Replace hip::TextureObject with __hip_texture

This avoids the use of extra casts when obtaining a texture object handle.

Change-Id: I42df22bdad0ab9ac6c33cb8b282dee65fe7cfd6e


[ROCm/clr commit: 6cfbe19160]
Этот коммит содержится в:
Vladislav Sytchenko committed 2020-03-26 14:45:20 -04:00
1 родитель df2f07ce18
Коммит cf49aaa7fc
1 file changed
+34 -40
+34 -40
Просмотреть файл
@@ -24,36 +24,34 @@
#include "hip_conversions.hpp" #include "hip_conversions.hpp"
#include "platform/sampler.hpp" #include "platform/sampler.hpp"
namespace hip { struct __hip_texture {
struct TextureObject { uint32_t imageSRD[HIP_IMAGE_OBJECT_SIZE_DWORD];
uint32_t imageSRD[HIP_IMAGE_OBJECT_SIZE_DWORD]; uint32_t samplerSRD[HIP_SAMPLER_OBJECT_SIZE_DWORD];
uint32_t samplerSRD[HIP_SAMPLER_OBJECT_SIZE_DWORD]; amd::Image* image;
amd::Image* image; amd::Sampler* sampler;
amd::Sampler* sampler; hipResourceDesc resDesc;
hipResourceDesc resDesc; hipTextureDesc texDesc;
hipTextureDesc texDesc; hipResourceViewDesc resViewDesc;
hipResourceViewDesc resViewDesc;
TextureObject(amd::Image* image_, __hip_texture(amd::Image* image_,
amd::Sampler* sampler_, amd::Sampler* sampler_,
const hipResourceDesc& resDesc_, const hipResourceDesc& resDesc_,
const hipTextureDesc& texDesc_, const hipTextureDesc& texDesc_,
const hipResourceViewDesc& resViewDesc_) : const hipResourceViewDesc& resViewDesc_) :
image(image_), image(image_),
sampler(sampler_), sampler(sampler_),
resDesc(resDesc_), resDesc(resDesc_),
texDesc(texDesc_), texDesc(texDesc_),
resViewDesc(resViewDesc_) { resViewDesc(resViewDesc_) {
amd::Context& context = *hip::getCurrentDevice()->asContext(); amd::Context& context = *hip::getCurrentDevice()->asContext();
amd::Device& device = *context.devices()[0]; amd::Device& device = *context.devices()[0];
device::Memory* imageMem = image->getDeviceMemory(device); device::Memory* imageMem = image->getDeviceMemory(device);
std::memcpy(imageSRD, imageMem->cpuSrd(), sizeof(imageSRD)); std::memcpy(imageSRD, imageMem->cpuSrd(), sizeof(imageSRD));
device::Sampler* samplerMem = sampler->getDeviceSampler(device); device::Sampler* samplerMem = sampler->getDeviceSampler(device);
std::memcpy(samplerSRD, samplerMem->hwState(), sizeof(samplerSRD)); std::memcpy(samplerSRD, samplerMem->hwState(), sizeof(samplerSRD));
} }
};
}; };
amd::Image* ihipImageCreate(const cl_channel_order channelOrder, amd::Image* ihipImageCreate(const cl_channel_order channelOrder,
@@ -290,11 +288,11 @@ hipError_t ihipCreateTextureObject(hipTextureObject_t* pTexObject,
} }
void *texObjectBuffer = nullptr; void *texObjectBuffer = nullptr;
ihipMalloc(&texObjectBuffer, sizeof(hip::TextureObject), CL_MEM_SVM_FINE_GRAIN_BUFFER); ihipMalloc(&texObjectBuffer, sizeof(__hip_texture), CL_MEM_SVM_FINE_GRAIN_BUFFER);
if (texObjectBuffer == nullptr) { if (texObjectBuffer == nullptr) {
return hipErrorOutOfMemory; return hipErrorOutOfMemory;
} }
*pTexObject = reinterpret_cast<hipTextureObject_t>(new (texObjectBuffer) hip::TextureObject{image, sampler, *pResDesc, *pTexDesc, (pResViewDesc != nullptr) ? *pResViewDesc : hipResourceViewDesc{}}); *pTexObject = new (texObjectBuffer) __hip_texture{image, sampler, *pResDesc, *pTexDesc, (pResViewDesc != nullptr) ? *pResViewDesc : hipResourceViewDesc{}};
return hipSuccess; return hipSuccess;
} }
@@ -314,17 +312,16 @@ hipError_t ihipDestroyTextureObject(hipTextureObject_t texObject) {
return hipErrorInvalidValue; return hipErrorInvalidValue;
} }
hip::TextureObject* hipTexObject = reinterpret_cast<hip::TextureObject*>(texObject); const hipResourceType type = texObject->resDesc.resType;
const hipResourceType type = hipTexObject->resDesc.resType;
const bool isImageFromBuffer = (type == hipResourceTypeLinear) || (type == hipResourceTypePitch2D); const bool isImageFromBuffer = (type == hipResourceTypeLinear) || (type == hipResourceTypePitch2D);
const bool isImageView = ((type == hipResourceTypeArray) || (type == hipResourceTypeMipmappedArray)) && const bool isImageView = ((type == hipResourceTypeArray) || (type == hipResourceTypeMipmappedArray)) &&
!hipTexObject->image->isParent(); !texObject->image->isParent();
if (isImageFromBuffer || isImageView) { if (isImageFromBuffer || isImageView) {
hipTexObject->image->release(); texObject->image->release();
} }
// TODO Should call ihipFree() to not polute the api trace. // TODO Should call ihipFree() to not polute the api trace.
return hipFree(hipTexObject); return hipFree(texObject);
} }
hipError_t hipDestroyTextureObject(hipTextureObject_t texObject) { hipError_t hipDestroyTextureObject(hipTextureObject_t texObject) {
@@ -343,8 +340,7 @@ hipError_t hipGetTextureObjectResourceDesc(hipResourceDesc* pResDesc,
HIP_RETURN(hipErrorInvalidValue); HIP_RETURN(hipErrorInvalidValue);
} }
hip::TextureObject* hipTexObject = reinterpret_cast<hip::TextureObject*>(texObject); *pResDesc = texObject->resDesc;
*pResDesc = hipTexObject->resDesc;
HIP_RETURN(hipSuccess); HIP_RETURN(hipSuccess);
} }
@@ -358,8 +354,7 @@ hipError_t hipGetTextureObjectResourceViewDesc(hipResourceViewDesc* pResViewDesc
HIP_RETURN(hipErrorInvalidValue); HIP_RETURN(hipErrorInvalidValue);
} }
hip::TextureObject* hipTexObject = reinterpret_cast<hip::TextureObject*>(texObject); *pResViewDesc = texObject->resViewDesc;
*pResViewDesc = hipTexObject->resViewDesc;
HIP_RETURN(hipSuccess); HIP_RETURN(hipSuccess);
} }
@@ -373,8 +368,7 @@ hipError_t hipGetTextureObjectTextureDesc(hipTextureDesc* pTexDesc,
HIP_RETURN(hipErrorInvalidValue); HIP_RETURN(hipErrorInvalidValue);
} }
hip::TextureObject* hipTexObject = reinterpret_cast<hip::TextureObject*>(texObject); *pTexDesc = texObject->texDesc;
*pTexDesc = hipTexObject->texDesc;
HIP_RETURN(hipSuccess); HIP_RETURN(hipSuccess);
} }