2017-07-17 15:16:12 -04:00
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "hsa/hsa.h"
|
|
|
|
|
#include "hsa/hsa_ext_amd.h"
|
|
|
|
|
|
|
|
|
|
#include "hip/hip_runtime.h"
|
|
|
|
|
#include "hip_hcc_internal.h"
|
|
|
|
|
#include "trace_helper.h"
|
|
|
|
|
|
|
|
|
|
#include "hip_texture.h"
|
|
|
|
|
|
|
|
|
|
static std::map<hipTextureObject_t, hipTexture*> textureHash;
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
void saveTextureInfo(const hipTexture* pTexture, const hipResourceDesc* pResDesc,
|
|
|
|
|
const hipTextureDesc* pTexDesc, const hipResourceViewDesc* pResViewDesc) {
|
2017-07-17 15:16:12 -04:00
|
|
|
if (pResDesc != nullptr) {
|
|
|
|
|
memcpy((void*)&(pTexture->resDesc), (void*)pResDesc, sizeof(hipResourceDesc));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pTexDesc != nullptr) {
|
|
|
|
|
memcpy((void*)&(pTexture->texDesc), (void*)pTexDesc, sizeof(hipTextureDesc));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pResViewDesc != nullptr) {
|
|
|
|
|
memcpy((void*)&(pTexture->resViewDesc), (void*)pResViewDesc, sizeof(hipResourceViewDesc));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
void getDrvChannelOrderAndType(const enum hipArray_Format Format, unsigned int NumChannels,
|
|
|
|
|
hsa_ext_image_channel_order_t* channelOrder,
|
|
|
|
|
hsa_ext_image_channel_type_t* channelType) {
|
|
|
|
|
switch (Format) {
|
2017-11-21 21:19:06 +05:30
|
|
|
case HIP_AD_FORMAT_UNSIGNED_INT8:
|
|
|
|
|
*channelType = HSA_EXT_IMAGE_CHANNEL_TYPE_UNSIGNED_INT8;
|
|
|
|
|
break;
|
|
|
|
|
case HIP_AD_FORMAT_UNSIGNED_INT16:
|
|
|
|
|
*channelType = HSA_EXT_IMAGE_CHANNEL_TYPE_UNSIGNED_INT16;
|
|
|
|
|
break;
|
|
|
|
|
case HIP_AD_FORMAT_UNSIGNED_INT32:
|
|
|
|
|
*channelType = HSA_EXT_IMAGE_CHANNEL_TYPE_UNSIGNED_INT32;
|
|
|
|
|
break;
|
|
|
|
|
case HIP_AD_FORMAT_SIGNED_INT8:
|
|
|
|
|
*channelType = HSA_EXT_IMAGE_CHANNEL_TYPE_SIGNED_INT8;
|
|
|
|
|
break;
|
|
|
|
|
case HIP_AD_FORMAT_SIGNED_INT16:
|
|
|
|
|
*channelType = HSA_EXT_IMAGE_CHANNEL_TYPE_SIGNED_INT16;
|
|
|
|
|
break;
|
|
|
|
|
case HIP_AD_FORMAT_SIGNED_INT32:
|
|
|
|
|
*channelType = HSA_EXT_IMAGE_CHANNEL_TYPE_SIGNED_INT32;
|
|
|
|
|
break;
|
|
|
|
|
case HIP_AD_FORMAT_HALF:
|
|
|
|
|
*channelType = HSA_EXT_IMAGE_CHANNEL_TYPE_HALF_FLOAT;
|
|
|
|
|
break;
|
|
|
|
|
case HIP_AD_FORMAT_FLOAT:
|
|
|
|
|
*channelType = HSA_EXT_IMAGE_CHANNEL_TYPE_FLOAT;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (NumChannels == 4) {
|
|
|
|
|
*channelOrder = HSA_EXT_IMAGE_CHANNEL_ORDER_RGBA;
|
|
|
|
|
} else if (NumChannels == 2) {
|
|
|
|
|
*channelOrder = HSA_EXT_IMAGE_CHANNEL_ORDER_RG;
|
|
|
|
|
} else if (NumChannels == 1) {
|
|
|
|
|
*channelOrder = HSA_EXT_IMAGE_CHANNEL_ORDER_R;
|
|
|
|
|
}
|
2017-11-09 22:10:55 +05:30
|
|
|
}
|
2018-03-12 11:29:03 +05:30
|
|
|
void getChannelOrderAndType(const hipChannelFormatDesc& desc, enum hipTextureReadMode readMode,
|
2017-11-21 21:19:06 +05:30
|
|
|
hsa_ext_image_channel_order_t* channelOrder,
|
2018-03-12 11:29:03 +05:30
|
|
|
hsa_ext_image_channel_type_t* channelType) {
|
2017-07-17 15:16:12 -04:00
|
|
|
if (desc.x != 0 && desc.y != 0 && desc.z != 0 && desc.w != 0) {
|
2017-11-21 21:19:06 +05:30
|
|
|
*channelOrder = HSA_EXT_IMAGE_CHANNEL_ORDER_RGBA;
|
2017-07-17 15:16:12 -04:00
|
|
|
} else if (desc.x != 0 && desc.y != 0 && desc.z != 0 && desc.w == 0) {
|
2017-11-21 21:19:06 +05:30
|
|
|
*channelOrder = HSA_EXT_IMAGE_CHANNEL_ORDER_RGB;
|
2017-07-17 15:16:12 -04:00
|
|
|
} else if (desc.x != 0 && desc.y != 0 && desc.z == 0 && desc.w == 0) {
|
2017-11-21 21:19:06 +05:30
|
|
|
*channelOrder = HSA_EXT_IMAGE_CHANNEL_ORDER_RG;
|
2017-07-17 15:16:12 -04:00
|
|
|
} else if (desc.x != 0 && desc.y == 0 && desc.z == 0 && desc.w == 0) {
|
2017-11-21 21:19:06 +05:30
|
|
|
*channelOrder = HSA_EXT_IMAGE_CHANNEL_ORDER_R;
|
2017-07-17 15:16:12 -04:00
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (desc.f) {
|
2018-03-12 11:29:03 +05:30
|
|
|
case hipChannelFormatKindUnsigned:
|
|
|
|
|
switch (desc.x) {
|
|
|
|
|
case 32:
|
|
|
|
|
*channelType = HSA_EXT_IMAGE_CHANNEL_TYPE_UNSIGNED_INT32;
|
|
|
|
|
break;
|
|
|
|
|
case 16:
|
|
|
|
|
*channelType = readMode == hipReadModeNormalizedFloat
|
|
|
|
|
? HSA_EXT_IMAGE_CHANNEL_TYPE_UNORM_INT16
|
|
|
|
|
: HSA_EXT_IMAGE_CHANNEL_TYPE_UNSIGNED_INT16;
|
|
|
|
|
break;
|
|
|
|
|
case 8:
|
|
|
|
|
*channelType = readMode == hipReadModeNormalizedFloat
|
|
|
|
|
? HSA_EXT_IMAGE_CHANNEL_TYPE_UNORM_INT8
|
|
|
|
|
: HSA_EXT_IMAGE_CHANNEL_TYPE_UNSIGNED_INT8;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
*channelType = HSA_EXT_IMAGE_CHANNEL_TYPE_UNSIGNED_INT32;
|
|
|
|
|
}
|
2017-07-17 15:16:12 -04:00
|
|
|
break;
|
2018-03-12 11:29:03 +05:30
|
|
|
case hipChannelFormatKindSigned:
|
|
|
|
|
switch (desc.x) {
|
|
|
|
|
case 32:
|
|
|
|
|
*channelType = HSA_EXT_IMAGE_CHANNEL_TYPE_SIGNED_INT32;
|
|
|
|
|
break;
|
|
|
|
|
case 16:
|
|
|
|
|
*channelType = readMode == hipReadModeNormalizedFloat
|
|
|
|
|
? HSA_EXT_IMAGE_CHANNEL_TYPE_SNORM_INT16
|
|
|
|
|
: HSA_EXT_IMAGE_CHANNEL_TYPE_SIGNED_INT16;
|
|
|
|
|
break;
|
|
|
|
|
case 8:
|
|
|
|
|
*channelType = readMode == hipReadModeNormalizedFloat
|
|
|
|
|
? HSA_EXT_IMAGE_CHANNEL_TYPE_SNORM_INT8
|
|
|
|
|
: HSA_EXT_IMAGE_CHANNEL_TYPE_SIGNED_INT8;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
*channelType = HSA_EXT_IMAGE_CHANNEL_TYPE_SIGNED_INT32;
|
|
|
|
|
}
|
2017-07-17 15:16:12 -04:00
|
|
|
break;
|
2018-03-12 11:29:03 +05:30
|
|
|
case hipChannelFormatKindFloat:
|
|
|
|
|
switch (desc.x) {
|
|
|
|
|
case 32:
|
|
|
|
|
*channelType = HSA_EXT_IMAGE_CHANNEL_TYPE_FLOAT;
|
|
|
|
|
break;
|
|
|
|
|
case 16:
|
|
|
|
|
*channelType = HSA_EXT_IMAGE_CHANNEL_TYPE_HALF_FLOAT;
|
|
|
|
|
break;
|
|
|
|
|
case 8:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
*channelType = HSA_EXT_IMAGE_CHANNEL_TYPE_FLOAT;
|
|
|
|
|
}
|
2017-07-17 15:16:12 -04:00
|
|
|
break;
|
2018-03-12 11:29:03 +05:30
|
|
|
case hipChannelFormatKindNone:
|
2017-07-17 15:16:12 -04:00
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void fillSamplerDescriptor(hsa_ext_sampler_descriptor_t& samplerDescriptor,
|
|
|
|
|
enum hipTextureAddressMode addressMode,
|
2018-03-12 11:29:03 +05:30
|
|
|
enum hipTextureFilterMode filterMode, int normalizedCoords) {
|
2017-07-17 15:16:12 -04:00
|
|
|
if (normalizedCoords) {
|
|
|
|
|
samplerDescriptor.coordinate_mode = HSA_EXT_SAMPLER_COORDINATE_MODE_NORMALIZED;
|
|
|
|
|
} else {
|
|
|
|
|
samplerDescriptor.coordinate_mode = HSA_EXT_SAMPLER_COORDINATE_MODE_UNNORMALIZED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (filterMode) {
|
2018-03-12 11:29:03 +05:30
|
|
|
case hipFilterModePoint:
|
|
|
|
|
samplerDescriptor.filter_mode = HSA_EXT_SAMPLER_FILTER_MODE_NEAREST;
|
|
|
|
|
break;
|
|
|
|
|
case hipFilterModeLinear:
|
|
|
|
|
samplerDescriptor.filter_mode = HSA_EXT_SAMPLER_FILTER_MODE_LINEAR;
|
|
|
|
|
break;
|
2017-07-17 15:16:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (addressMode) {
|
2018-03-12 11:29:03 +05:30
|
|
|
case hipAddressModeWrap:
|
|
|
|
|
samplerDescriptor.address_mode = HSA_EXT_SAMPLER_ADDRESSING_MODE_REPEAT;
|
|
|
|
|
break;
|
|
|
|
|
case hipAddressModeClamp:
|
|
|
|
|
samplerDescriptor.address_mode = HSA_EXT_SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE;
|
|
|
|
|
break;
|
|
|
|
|
case hipAddressModeMirror:
|
|
|
|
|
samplerDescriptor.address_mode = HSA_EXT_SAMPLER_ADDRESSING_MODE_MIRRORED_REPEAT;
|
|
|
|
|
break;
|
|
|
|
|
case hipAddressModeBorder:
|
|
|
|
|
samplerDescriptor.address_mode = HSA_EXT_SAMPLER_ADDRESSING_MODE_CLAMP_TO_BORDER;
|
|
|
|
|
break;
|
2017-07-17 15:16:12 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
bool getHipTextureObject(hipTextureObject_t* pTexObject, hsa_ext_image_t& image,
|
|
|
|
|
hsa_ext_sampler_t sampler) {
|
2017-07-17 15:16:12 -04:00
|
|
|
unsigned int* texSRD;
|
2018-03-12 11:29:03 +05:30
|
|
|
hipMalloc((void**)&texSRD, HIP_TEXTURE_OBJECT_SIZE_DWORD * 4);
|
|
|
|
|
hipMemcpy(texSRD, (void*)image.handle, HIP_IMAGE_OBJECT_SIZE_DWORD * 4,
|
|
|
|
|
hipMemcpyDeviceToDevice);
|
|
|
|
|
hipMemcpy(texSRD + HIP_SAMPLER_OBJECT_OFFSET_DWORD, (void*)sampler.handle,
|
|
|
|
|
HIP_SAMPLER_OBJECT_SIZE_DWORD * 4, hipMemcpyDeviceToDevice);
|
|
|
|
|
*pTexObject = (hipTextureObject_t)texSRD;
|
2017-07-17 15:16:12 -04:00
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2018-03-12 11:29:03 +05:30
|
|
|
unsigned int* srd = (unsigned int*)malloc(HIP_TEXTURE_OBJECT_SIZE_DWORD * 4);
|
2017-07-17 15:16:12 -04:00
|
|
|
hipMemcpy(srd, texSRD, HIP_TEXTURE_OBJECT_SIZE_DWORD * 4, hipMemcpyDeviceToHost);
|
|
|
|
|
printf("New SRD: \n");
|
|
|
|
|
for (int i = 0; i < HIP_TEXTURE_OBJECT_SIZE_DWORD; i++) {
|
|
|
|
|
printf("SRD[%d]: %x\n", i, srd[i]);
|
|
|
|
|
}
|
|
|
|
|
printf("\n");
|
|
|
|
|
#endif
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Texture Object APIs
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hipCreateTextureObject(hipTextureObject_t* pTexObject, const hipResourceDesc* pResDesc,
|
2017-07-17 15:16:12 -04:00
|
|
|
const hipTextureDesc* pTexDesc,
|
2018-03-12 11:29:03 +05:30
|
|
|
const hipResourceViewDesc* pResViewDesc) {
|
2018-11-08 08:36:50 -06:00
|
|
|
HIP_INIT_API(hipCreateTextureObject, pTexObject, pResDesc, pTexDesc, pResViewDesc);
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hip_status = hipSuccess;
|
2017-07-17 15:16:12 -04:00
|
|
|
|
|
|
|
|
auto ctx = ihipGetTlsDefaultCtx();
|
|
|
|
|
if (ctx) {
|
|
|
|
|
hc::accelerator acc = ctx->getDevice()->_acc;
|
|
|
|
|
auto device = ctx->getWriteableDevice();
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hsa_agent_t* agent = static_cast<hsa_agent_t*>(acc.get_hsa_agent());
|
2017-07-17 15:16:12 -04:00
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipTexture* pTexture = (hipTexture*)malloc(sizeof(hipTexture));
|
2017-07-17 15:16:12 -04:00
|
|
|
if (pTexture != nullptr) {
|
|
|
|
|
memset(pTexture, 0, sizeof(hipTexture));
|
|
|
|
|
saveTextureInfo(pTexture, pResDesc, pTexDesc, pResViewDesc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hsa_ext_image_descriptor_t imageDescriptor;
|
|
|
|
|
hsa_ext_image_channel_order_t channelOrder;
|
|
|
|
|
hsa_ext_image_channel_type_t channelType;
|
|
|
|
|
void* devPtr = nullptr;
|
|
|
|
|
|
|
|
|
|
switch (pResDesc->resType) {
|
2018-03-12 11:29:03 +05:30
|
|
|
case hipResourceTypeArray:
|
|
|
|
|
devPtr = pResDesc->res.array.array->data;
|
|
|
|
|
imageDescriptor.width = pResDesc->res.array.array->width;
|
|
|
|
|
imageDescriptor.height = pResDesc->res.array.array->height;
|
|
|
|
|
switch (pResDesc->res.array.array->type) {
|
|
|
|
|
case hipArrayLayered:
|
|
|
|
|
imageDescriptor.geometry = HSA_EXT_IMAGE_GEOMETRY_2DA;
|
|
|
|
|
imageDescriptor.depth = 0;
|
|
|
|
|
imageDescriptor.array_size = pResDesc->res.array.array->depth;
|
|
|
|
|
break;
|
|
|
|
|
case hipArrayCubemap:
|
|
|
|
|
imageDescriptor.geometry = HSA_EXT_IMAGE_GEOMETRY_3D;
|
|
|
|
|
imageDescriptor.depth = pResDesc->res.array.array->depth;
|
|
|
|
|
imageDescriptor.array_size = 0;
|
|
|
|
|
break;
|
|
|
|
|
case hipArraySurfaceLoadStore:
|
|
|
|
|
case hipArrayTextureGather:
|
|
|
|
|
case hipArrayDefault:
|
|
|
|
|
default:
|
|
|
|
|
imageDescriptor.geometry = HSA_EXT_IMAGE_GEOMETRY_2D;
|
|
|
|
|
imageDescriptor.depth = 0;
|
|
|
|
|
imageDescriptor.array_size = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
getChannelOrderAndType(pResDesc->res.array.array->desc, pTexDesc->readMode,
|
|
|
|
|
&channelOrder, &channelType);
|
2017-07-17 15:16:12 -04:00
|
|
|
break;
|
2018-03-12 11:29:03 +05:30
|
|
|
case hipResourceTypeMipmappedArray:
|
|
|
|
|
devPtr = pResDesc->res.mipmap.mipmap->data;
|
|
|
|
|
imageDescriptor.width = pResDesc->res.mipmap.mipmap->width;
|
|
|
|
|
imageDescriptor.height = pResDesc->res.mipmap.mipmap->height;
|
|
|
|
|
imageDescriptor.depth = pResDesc->res.mipmap.mipmap->depth;
|
2017-07-17 15:16:12 -04:00
|
|
|
imageDescriptor.array_size = 0;
|
|
|
|
|
imageDescriptor.geometry = HSA_EXT_IMAGE_GEOMETRY_2D;
|
2018-03-12 11:29:03 +05:30
|
|
|
getChannelOrderAndType(pResDesc->res.mipmap.mipmap->desc, pTexDesc->readMode,
|
|
|
|
|
&channelOrder, &channelType);
|
|
|
|
|
break;
|
|
|
|
|
case hipResourceTypeLinear:
|
|
|
|
|
devPtr = pResDesc->res.linear.devPtr;
|
2018-10-03 12:07:38 +05:30
|
|
|
imageDescriptor.width = pResDesc->res.linear.sizeInBytes/((pResDesc->res.linear.desc.x + pResDesc->res.linear.desc.y + pResDesc->res.linear.desc.z + pResDesc->res.linear.desc.w)/8);
|
2018-03-12 11:29:03 +05:30
|
|
|
imageDescriptor.height = 1;
|
2017-07-17 15:16:12 -04:00
|
|
|
imageDescriptor.depth = 0;
|
|
|
|
|
imageDescriptor.array_size = 0;
|
2018-03-12 11:29:03 +05:30
|
|
|
imageDescriptor.geometry =
|
|
|
|
|
HSA_EXT_IMAGE_GEOMETRY_1D; // ? HSA_EXT_IMAGE_DATA_LAYOUT_LINEAR
|
|
|
|
|
getChannelOrderAndType(pResDesc->res.linear.desc, pTexDesc->readMode, &channelOrder,
|
|
|
|
|
&channelType);
|
|
|
|
|
break;
|
|
|
|
|
case hipResourceTypePitch2D:
|
|
|
|
|
devPtr = pResDesc->res.pitch2D.devPtr;
|
|
|
|
|
imageDescriptor.width = pResDesc->res.pitch2D.width;
|
|
|
|
|
imageDescriptor.height = pResDesc->res.pitch2D.height;
|
|
|
|
|
imageDescriptor.depth = 0;
|
|
|
|
|
imageDescriptor.array_size = 0;
|
|
|
|
|
imageDescriptor.geometry = HSA_EXT_IMAGE_GEOMETRY_2D;
|
|
|
|
|
getChannelOrderAndType(pResDesc->res.pitch2D.desc, pTexDesc->readMode,
|
|
|
|
|
&channelOrder, &channelType);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2017-07-17 15:16:12 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
imageDescriptor.format.channel_order = channelOrder;
|
|
|
|
|
imageDescriptor.format.channel_type = channelType;
|
|
|
|
|
|
|
|
|
|
hsa_ext_sampler_descriptor_t samplerDescriptor;
|
2018-03-12 11:29:03 +05:30
|
|
|
fillSamplerDescriptor(samplerDescriptor, pTexDesc->addressMode[0], pTexDesc->filterMode,
|
|
|
|
|
pTexDesc->normalizedCoords);
|
2017-07-17 15:16:12 -04:00
|
|
|
|
|
|
|
|
hsa_access_permission_t permission = HSA_ACCESS_PERMISSION_RW;
|
2018-03-12 11:29:03 +05:30
|
|
|
if (HSA_STATUS_SUCCESS != hsa_ext_image_create_with_layout(
|
|
|
|
|
*agent, &imageDescriptor, devPtr, permission,
|
|
|
|
|
HSA_EXT_IMAGE_DATA_LAYOUT_LINEAR, 0, 0, &(pTexture->image)) ||
|
|
|
|
|
HSA_STATUS_SUCCESS !=
|
|
|
|
|
hsa_ext_sampler_create(*agent, &samplerDescriptor, &(pTexture->sampler))) {
|
2017-07-17 15:16:12 -04:00
|
|
|
return ihipLogStatus(hipErrorRuntimeOther);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getHipTextureObject(pTexObject, pTexture->image, pTexture->sampler);
|
|
|
|
|
|
|
|
|
|
textureHash[*pTexObject] = pTexture;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ihipLogStatus(hip_status);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hipDestroyTextureObject(hipTextureObject_t textureObject) {
|
2018-11-08 08:36:50 -06:00
|
|
|
HIP_INIT_API(hipDestroyTextureObject, textureObject);
|
2017-07-17 15:16:12 -04:00
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hip_status = hipSuccess;
|
2017-07-17 15:16:12 -04:00
|
|
|
|
|
|
|
|
auto ctx = ihipGetTlsDefaultCtx();
|
|
|
|
|
if (ctx) {
|
|
|
|
|
hc::accelerator acc = ctx->getDevice()->_acc;
|
|
|
|
|
auto device = ctx->getWriteableDevice();
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hsa_agent_t* agent = static_cast<hsa_agent_t*>(acc.get_hsa_agent());
|
2017-07-17 15:16:12 -04:00
|
|
|
|
|
|
|
|
hipTexture* pTexture = textureHash[textureObject];
|
|
|
|
|
if (pTexture != nullptr) {
|
|
|
|
|
hsa_ext_image_destroy(*agent, pTexture->image);
|
|
|
|
|
hsa_ext_sampler_destroy(*agent, pTexture->sampler);
|
|
|
|
|
free(pTexture);
|
|
|
|
|
textureHash.erase(textureObject);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ihipLogStatus(hip_status);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hipGetTextureObjectResourceDesc(hipResourceDesc* pResDesc,
|
|
|
|
|
hipTextureObject_t textureObject) {
|
2018-11-08 08:36:50 -06:00
|
|
|
HIP_INIT_API(hipGetTextureObjectResourceDesc, pResDesc, textureObject);
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hip_status = hipSuccess;
|
2017-07-17 15:16:12 -04:00
|
|
|
|
|
|
|
|
auto ctx = ihipGetTlsDefaultCtx();
|
|
|
|
|
if (ctx) {
|
|
|
|
|
hipTexture* pTexture = textureHash[textureObject];
|
|
|
|
|
if (pTexture != nullptr && pResDesc != nullptr) {
|
|
|
|
|
memcpy((void*)pResDesc, (void*)&(pTexture->resDesc), sizeof(hipResourceDesc));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ihipLogStatus(hip_status);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hipGetTextureObjectResourceViewDesc(hipResourceViewDesc* pResViewDesc,
|
|
|
|
|
hipTextureObject_t textureObject) {
|
2018-11-08 08:36:50 -06:00
|
|
|
HIP_INIT_API(hipGetTextureObjectResourceViewDesc, pResViewDesc, textureObject);
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hip_status = hipSuccess;
|
2017-07-17 15:16:12 -04:00
|
|
|
|
|
|
|
|
auto ctx = ihipGetTlsDefaultCtx();
|
|
|
|
|
if (ctx) {
|
|
|
|
|
hipTexture* pTexture = textureHash[textureObject];
|
|
|
|
|
if (pTexture != nullptr && pResViewDesc != nullptr) {
|
2018-03-12 11:29:03 +05:30
|
|
|
memcpy((void*)pResViewDesc, (void*)&(pTexture->resViewDesc),
|
|
|
|
|
sizeof(hipResourceViewDesc));
|
2017-07-17 15:16:12 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ihipLogStatus(hip_status);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hipGetTextureObjectTextureDesc(hipTextureDesc* pTexDesc,
|
|
|
|
|
hipTextureObject_t textureObject) {
|
2018-11-08 08:36:50 -06:00
|
|
|
HIP_INIT_API(hipGetTextureObjectTextureDesc, pTexDesc, textureObject);
|
2017-07-17 15:16:12 -04:00
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hip_status = hipSuccess;
|
2017-07-17 15:16:12 -04:00
|
|
|
|
|
|
|
|
auto ctx = ihipGetTlsDefaultCtx();
|
|
|
|
|
if (ctx) {
|
|
|
|
|
hipTexture* pTexture = textureHash[textureObject];
|
|
|
|
|
if (pTexture != nullptr && pTexDesc != nullptr) {
|
|
|
|
|
memcpy((void*)pTexDesc, (void*)&(pTexture->texDesc), sizeof(hipTextureDesc));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ihipLogStatus(hip_status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Texture Reference APIs
|
2019-08-05 02:51:02 -07:00
|
|
|
hipError_t ihipBindTextureImpl(TlsData *tls_, int dim, enum hipTextureReadMode readMode, size_t* offset,
|
2018-03-12 11:29:03 +05:30
|
|
|
const void* devPtr, const struct hipChannelFormatDesc* desc,
|
|
|
|
|
size_t size, textureReference* tex) {
|
2019-08-05 02:51:02 -07:00
|
|
|
TlsData *tls = (tls_ == nullptr) ? tls_get_ptr() : tls_;
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hip_status = hipSuccess;
|
2017-11-14 11:09:35 +05:30
|
|
|
enum hipTextureAddressMode addressMode = tex->addressMode[0];
|
|
|
|
|
enum hipTextureFilterMode filterMode = tex->filterMode;
|
|
|
|
|
int normalizedCoords = tex->normalized;
|
|
|
|
|
hipTextureObject_t& textureObject = tex->textureObject;
|
2018-07-03 08:54:17 +05:30
|
|
|
if(offset != nullptr)
|
|
|
|
|
*offset = 0;
|
2017-07-17 15:16:12 -04:00
|
|
|
auto ctx = ihipGetTlsDefaultCtx();
|
|
|
|
|
if (ctx) {
|
|
|
|
|
hc::accelerator acc = ctx->getDevice()->_acc;
|
|
|
|
|
auto device = ctx->getWriteableDevice();
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hsa_agent_t* agent = static_cast<hsa_agent_t*>(acc.get_hsa_agent());
|
2017-07-17 15:16:12 -04:00
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipTexture* pTexture = (hipTexture*)malloc(sizeof(hipTexture));
|
2017-07-17 15:16:12 -04:00
|
|
|
if (pTexture != nullptr) {
|
|
|
|
|
memset(pTexture, 0, sizeof(hipTexture));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hsa_ext_image_descriptor_t imageDescriptor;
|
|
|
|
|
|
|
|
|
|
assert(dim == hipTextureType1D);
|
|
|
|
|
|
|
|
|
|
imageDescriptor.geometry = HSA_EXT_IMAGE_GEOMETRY_1D;
|
|
|
|
|
imageDescriptor.width = size;
|
|
|
|
|
imageDescriptor.height = 1;
|
|
|
|
|
imageDescriptor.depth = 1;
|
|
|
|
|
imageDescriptor.array_size = 0;
|
|
|
|
|
|
|
|
|
|
hsa_ext_image_channel_order_t channelOrder;
|
|
|
|
|
hsa_ext_image_channel_type_t channelType;
|
2018-03-12 11:29:03 +05:30
|
|
|
if (NULL == desc) {
|
|
|
|
|
getDrvChannelOrderAndType(tex->format, tex->numChannels, &channelOrder, &channelType);
|
|
|
|
|
} else {
|
|
|
|
|
getChannelOrderAndType(*desc, readMode, &channelOrder, &channelType);
|
|
|
|
|
}
|
2017-07-17 15:16:12 -04:00
|
|
|
imageDescriptor.format.channel_order = channelOrder;
|
|
|
|
|
imageDescriptor.format.channel_type = channelType;
|
|
|
|
|
|
|
|
|
|
hsa_ext_sampler_descriptor_t samplerDescriptor;
|
|
|
|
|
fillSamplerDescriptor(samplerDescriptor, addressMode, filterMode, normalizedCoords);
|
|
|
|
|
|
|
|
|
|
hsa_access_permission_t permission = HSA_ACCESS_PERMISSION_RW;
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
if (HSA_STATUS_SUCCESS != hsa_ext_image_create_with_layout(
|
|
|
|
|
*agent, &imageDescriptor, devPtr, permission,
|
|
|
|
|
HSA_EXT_IMAGE_DATA_LAYOUT_LINEAR, 0, 0, &(pTexture->image)) ||
|
|
|
|
|
HSA_STATUS_SUCCESS !=
|
|
|
|
|
hsa_ext_sampler_create(*agent, &samplerDescriptor, &(pTexture->sampler))) {
|
2017-11-14 11:09:35 +05:30
|
|
|
return hipErrorRuntimeOther;
|
2017-07-17 15:16:12 -04:00
|
|
|
}
|
|
|
|
|
getHipTextureObject(&textureObject, pTexture->image, pTexture->sampler);
|
2019-10-04 01:08:45 -07:00
|
|
|
pTexture->devPtr = (void*) devPtr;
|
2017-07-17 15:16:12 -04:00
|
|
|
textureHash[textureObject] = pTexture;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-14 11:09:35 +05:30
|
|
|
return hip_status;
|
2017-07-17 15:16:12 -04:00
|
|
|
}
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hipBindTexture(size_t* offset, textureReference* tex, const void* devPtr,
|
|
|
|
|
const hipChannelFormatDesc* desc, size_t size) {
|
2018-11-08 08:36:50 -06:00
|
|
|
HIP_INIT_API(hipBindTexture, offset, tex, devPtr, desc, size);
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hip_status = hipSuccess;
|
2017-07-17 15:16:12 -04:00
|
|
|
// TODO: hipReadModeElementType is default.
|
2019-08-05 02:51:02 -07:00
|
|
|
hip_status = ihipBindTextureImpl(tls, hipTextureType1D, hipReadModeElementType, offset, devPtr, desc,
|
2018-03-12 11:29:03 +05:30
|
|
|
size, tex);
|
2017-11-14 11:09:35 +05:30
|
|
|
return ihipLogStatus(hip_status);
|
2017-07-17 15:16:12 -04:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 02:51:02 -07:00
|
|
|
hipError_t ihipBindTexture2DImpl(TlsData *tls, int dim, enum hipTextureReadMode readMode, size_t* offset,
|
2018-03-12 11:29:03 +05:30
|
|
|
const void* devPtr, const struct hipChannelFormatDesc* desc,
|
|
|
|
|
size_t width, size_t height, textureReference* tex) {
|
|
|
|
|
hipError_t hip_status = hipSuccess;
|
2017-11-14 11:09:35 +05:30
|
|
|
enum hipTextureAddressMode addressMode = tex->addressMode[0];
|
2018-03-12 11:29:03 +05:30
|
|
|
enum hipTextureFilterMode filterMode = tex->filterMode;
|
|
|
|
|
int normalizedCoords = tex->normalized;
|
2017-11-14 11:09:35 +05:30
|
|
|
hipTextureObject_t& textureObject = tex->textureObject;
|
2018-07-03 08:54:17 +05:30
|
|
|
if(offset != nullptr)
|
|
|
|
|
*offset = 0;
|
2017-07-17 15:16:12 -04:00
|
|
|
auto ctx = ihipGetTlsDefaultCtx();
|
|
|
|
|
if (ctx) {
|
|
|
|
|
hc::accelerator acc = ctx->getDevice()->_acc;
|
|
|
|
|
auto device = ctx->getWriteableDevice();
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hsa_agent_t* agent = static_cast<hsa_agent_t*>(acc.get_hsa_agent());
|
2017-07-17 15:16:12 -04:00
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipTexture* pTexture = (hipTexture*)malloc(sizeof(hipTexture));
|
2017-07-17 15:16:12 -04:00
|
|
|
if (pTexture != nullptr) {
|
|
|
|
|
memset(pTexture, 0, sizeof(hipTexture));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hsa_ext_image_descriptor_t imageDescriptor;
|
|
|
|
|
|
|
|
|
|
assert(dim == hipTextureType2D);
|
|
|
|
|
|
|
|
|
|
imageDescriptor.geometry = HSA_EXT_IMAGE_GEOMETRY_2D;
|
|
|
|
|
imageDescriptor.width = width;
|
|
|
|
|
imageDescriptor.height = height;
|
|
|
|
|
imageDescriptor.depth = 1;
|
|
|
|
|
imageDescriptor.array_size = 0;
|
|
|
|
|
|
|
|
|
|
hsa_ext_image_channel_order_t channelOrder;
|
|
|
|
|
hsa_ext_image_channel_type_t channelType;
|
2017-11-15 18:23:28 +05:30
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
if (NULL == desc) {
|
|
|
|
|
getDrvChannelOrderAndType(tex->format, tex->numChannels, &channelOrder, &channelType);
|
|
|
|
|
} else {
|
|
|
|
|
getChannelOrderAndType(*desc, readMode, &channelOrder, &channelType);
|
|
|
|
|
}
|
2017-07-17 15:16:12 -04:00
|
|
|
imageDescriptor.format.channel_order = channelOrder;
|
|
|
|
|
imageDescriptor.format.channel_type = channelType;
|
|
|
|
|
|
|
|
|
|
hsa_ext_sampler_descriptor_t samplerDescriptor;
|
|
|
|
|
fillSamplerDescriptor(samplerDescriptor, addressMode, filterMode, normalizedCoords);
|
|
|
|
|
|
|
|
|
|
hsa_access_permission_t permission = HSA_ACCESS_PERMISSION_RW;
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
if (HSA_STATUS_SUCCESS != hsa_ext_image_create_with_layout(
|
|
|
|
|
*agent, &imageDescriptor, devPtr, permission,
|
|
|
|
|
HSA_EXT_IMAGE_DATA_LAYOUT_LINEAR, 0, 0, &(pTexture->image)) ||
|
|
|
|
|
HSA_STATUS_SUCCESS !=
|
|
|
|
|
hsa_ext_sampler_create(*agent, &samplerDescriptor, &(pTexture->sampler))) {
|
2017-11-14 11:09:35 +05:30
|
|
|
return hipErrorRuntimeOther;
|
2017-07-17 15:16:12 -04:00
|
|
|
}
|
|
|
|
|
getHipTextureObject(&textureObject, pTexture->image, pTexture->sampler);
|
2019-10-04 01:08:45 -07:00
|
|
|
pTexture->devPtr = (void*) devPtr;
|
2017-07-17 15:16:12 -04:00
|
|
|
textureHash[textureObject] = pTexture;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-14 11:09:35 +05:30
|
|
|
return hip_status;
|
2017-07-17 15:16:12 -04:00
|
|
|
}
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hipBindTexture2D(size_t* offset, textureReference* tex, const void* devPtr,
|
|
|
|
|
const hipChannelFormatDesc* desc, size_t width, size_t height,
|
|
|
|
|
size_t pitch) {
|
2018-11-08 08:36:50 -06:00
|
|
|
HIP_INIT_API(hipBindTexture2D, offset, tex, devPtr, desc, width, height, pitch);
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hip_status = hipSuccess;
|
2019-08-05 02:51:02 -07:00
|
|
|
hip_status = ihipBindTexture2DImpl(tls, hipTextureType2D, hipReadModeElementType, offset, devPtr,
|
2018-03-12 11:29:03 +05:30
|
|
|
desc, width, height, tex);
|
2017-11-14 11:09:35 +05:30
|
|
|
return ihipLogStatus(hip_status);
|
2017-07-17 15:16:12 -04:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 02:51:02 -07:00
|
|
|
hipError_t ihipBindTextureToArrayImpl(TlsData *tls_, int dim, enum hipTextureReadMode readMode,
|
2017-07-17 15:16:12 -04:00
|
|
|
hipArray_const_t array,
|
|
|
|
|
const struct hipChannelFormatDesc& desc,
|
2018-03-12 11:29:03 +05:30
|
|
|
textureReference* tex) {
|
2019-08-05 02:51:02 -07:00
|
|
|
TlsData *tls = (tls_ == nullptr) ? tls_get_ptr() : tls_;
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hip_status = hipSuccess;
|
2017-11-14 11:09:35 +05:30
|
|
|
enum hipTextureAddressMode addressMode = tex->addressMode[0];
|
2018-03-12 11:29:03 +05:30
|
|
|
enum hipTextureFilterMode filterMode = tex->filterMode;
|
2017-11-14 11:09:35 +05:30
|
|
|
int normalizedCoords = tex->normalized;
|
|
|
|
|
hipTextureObject_t& textureObject = tex->textureObject;
|
2017-07-17 15:16:12 -04:00
|
|
|
auto ctx = ihipGetTlsDefaultCtx();
|
|
|
|
|
if (ctx) {
|
|
|
|
|
hc::accelerator acc = ctx->getDevice()->_acc;
|
|
|
|
|
auto device = ctx->getWriteableDevice();
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hsa_agent_t* agent = static_cast<hsa_agent_t*>(acc.get_hsa_agent());
|
2017-07-17 15:16:12 -04:00
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipTexture* pTexture = (hipTexture*)malloc(sizeof(hipTexture));
|
2017-07-17 15:16:12 -04:00
|
|
|
if (pTexture != nullptr) {
|
|
|
|
|
memset(pTexture, 0, sizeof(hipTexture));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hsa_ext_image_descriptor_t imageDescriptor;
|
|
|
|
|
|
|
|
|
|
imageDescriptor.width = array->width;
|
|
|
|
|
imageDescriptor.height = array->height;
|
|
|
|
|
imageDescriptor.depth = array->depth;
|
|
|
|
|
imageDescriptor.array_size = 0;
|
|
|
|
|
|
|
|
|
|
switch (dim) {
|
2018-03-12 11:29:03 +05:30
|
|
|
case hipTextureType1D:
|
|
|
|
|
imageDescriptor.geometry = HSA_EXT_IMAGE_GEOMETRY_1D;
|
|
|
|
|
imageDescriptor.height = 1;
|
|
|
|
|
imageDescriptor.depth = 1;
|
|
|
|
|
break;
|
|
|
|
|
case hipTextureType2D:
|
|
|
|
|
imageDescriptor.geometry = HSA_EXT_IMAGE_GEOMETRY_2D;
|
|
|
|
|
imageDescriptor.depth = 1;
|
|
|
|
|
break;
|
|
|
|
|
case hipTextureType3D:
|
|
|
|
|
case hipTextureTypeCubemap:
|
|
|
|
|
imageDescriptor.geometry = HSA_EXT_IMAGE_GEOMETRY_3D;
|
|
|
|
|
break;
|
|
|
|
|
case hipTextureType1DLayered:
|
|
|
|
|
imageDescriptor.geometry = HSA_EXT_IMAGE_GEOMETRY_1DA;
|
|
|
|
|
imageDescriptor.height = 1;
|
|
|
|
|
imageDescriptor.array_size = array->height;
|
|
|
|
|
break;
|
|
|
|
|
case hipTextureType2DLayered:
|
|
|
|
|
imageDescriptor.geometry = HSA_EXT_IMAGE_GEOMETRY_2DA;
|
|
|
|
|
imageDescriptor.depth = 1;
|
|
|
|
|
imageDescriptor.array_size = array->depth;
|
|
|
|
|
break;
|
|
|
|
|
case hipTextureTypeCubemapLayered:
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2017-07-17 15:16:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hsa_ext_image_channel_order_t channelOrder;
|
|
|
|
|
hsa_ext_image_channel_type_t channelType;
|
2018-03-12 11:29:03 +05:30
|
|
|
if (array->isDrv) {
|
2019-07-11 14:58:16 +03:00
|
|
|
getDrvChannelOrderAndType(array->Format, array->NumChannels,
|
2018-03-12 11:29:03 +05:30
|
|
|
&channelOrder, &channelType);
|
|
|
|
|
} else {
|
2017-11-21 21:19:06 +05:30
|
|
|
getChannelOrderAndType(desc, readMode, &channelOrder, &channelType);
|
2018-03-12 11:29:03 +05:30
|
|
|
}
|
2017-07-17 15:16:12 -04:00
|
|
|
imageDescriptor.format.channel_order = channelOrder;
|
|
|
|
|
imageDescriptor.format.channel_type = channelType;
|
|
|
|
|
|
|
|
|
|
hsa_ext_sampler_descriptor_t samplerDescriptor;
|
|
|
|
|
fillSamplerDescriptor(samplerDescriptor, addressMode, filterMode, normalizedCoords);
|
|
|
|
|
|
|
|
|
|
hsa_access_permission_t permission = HSA_ACCESS_PERMISSION_RW;
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
if (HSA_STATUS_SUCCESS != hsa_ext_image_create_with_layout(
|
|
|
|
|
*agent, &imageDescriptor, array->data, permission,
|
|
|
|
|
HSA_EXT_IMAGE_DATA_LAYOUT_LINEAR, 0, 0, &(pTexture->image)) ||
|
|
|
|
|
HSA_STATUS_SUCCESS !=
|
|
|
|
|
hsa_ext_sampler_create(*agent, &samplerDescriptor, &(pTexture->sampler))) {
|
2017-11-14 11:09:35 +05:30
|
|
|
return hipErrorRuntimeOther;
|
2017-07-17 15:16:12 -04:00
|
|
|
}
|
|
|
|
|
getHipTextureObject(&textureObject, pTexture->image, pTexture->sampler);
|
2019-10-04 01:08:45 -07:00
|
|
|
pTexture->devPtr = (void*) array;
|
2017-07-17 15:16:12 -04:00
|
|
|
textureHash[textureObject] = pTexture;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-14 11:09:35 +05:30
|
|
|
return hip_status;
|
2017-07-17 15:16:12 -04:00
|
|
|
}
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hipBindTextureToArray(textureReference* tex, hipArray_const_t array,
|
|
|
|
|
const hipChannelFormatDesc* desc) {
|
2018-11-08 08:36:50 -06:00
|
|
|
HIP_INIT_API(hipBindTextureToArray, tex, array, desc);
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hip_status = hipSuccess;
|
2017-07-17 15:16:12 -04:00
|
|
|
// TODO: hipReadModeElementType is default.
|
2018-03-12 11:29:03 +05:30
|
|
|
hip_status =
|
2019-08-05 02:51:02 -07:00
|
|
|
ihipBindTextureToArrayImpl(tls, array->textureType, hipReadModeElementType, array, *desc, tex);
|
2017-11-14 11:09:35 +05:30
|
|
|
return ihipLogStatus(hip_status);
|
2017-07-17 15:16:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipBindTextureToMipmappedArray(textureReference* tex,
|
|
|
|
|
hipMipmappedArray_const_t mipmappedArray,
|
2018-03-12 11:29:03 +05:30
|
|
|
const hipChannelFormatDesc* desc) {
|
2018-11-08 08:36:50 -06:00
|
|
|
HIP_INIT_API(hipBindTextureToMipmappedArray, tex, mipmappedArray, desc);
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hip_status = hipSuccess;
|
|
|
|
|
return ihipLogStatus(hip_status);
|
2017-07-17 15:16:12 -04:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 02:51:02 -07:00
|
|
|
hipError_t ihipUnbindTextureImpl(TlsData *tls, const hipTextureObject_t& textureObject) {
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hip_status = hipSuccess;
|
2017-07-17 15:16:12 -04:00
|
|
|
|
|
|
|
|
auto ctx = ihipGetTlsDefaultCtx();
|
|
|
|
|
if (ctx) {
|
|
|
|
|
hc::accelerator acc = ctx->getDevice()->_acc;
|
|
|
|
|
auto device = ctx->getWriteableDevice();
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hsa_agent_t* agent = static_cast<hsa_agent_t*>(acc.get_hsa_agent());
|
2017-07-17 15:16:12 -04:00
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipTexture* pTexture = textureHash[textureObject];
|
2017-07-17 15:16:12 -04:00
|
|
|
if (pTexture != nullptr) {
|
|
|
|
|
hsa_ext_image_destroy(*agent, pTexture->image);
|
|
|
|
|
hsa_ext_sampler_destroy(*agent, pTexture->sampler);
|
|
|
|
|
free(pTexture);
|
|
|
|
|
textureHash.erase(textureObject);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-14 11:09:35 +05:30
|
|
|
return hip_status;
|
2017-07-17 15:16:12 -04:00
|
|
|
}
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hipUnbindTexture(const textureReference* tex) {
|
2018-11-08 08:36:50 -06:00
|
|
|
HIP_INIT_API(hipUnbindTexture, tex);
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hip_status = hipSuccess;
|
2019-08-05 02:51:02 -07:00
|
|
|
hip_status = ihipUnbindTextureImpl(tls, tex->textureObject);
|
2017-11-14 11:09:35 +05:30
|
|
|
return ihipLogStatus(hip_status);
|
2017-07-17 15:16:12 -04:00
|
|
|
}
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hipGetChannelDesc(hipChannelFormatDesc* desc, hipArray_const_t array) {
|
2018-11-08 08:36:50 -06:00
|
|
|
HIP_INIT_API(hipGetChannelDesc, desc, array);
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hip_status = hipSuccess;
|
2017-07-17 15:16:12 -04:00
|
|
|
|
|
|
|
|
auto ctx = ihipGetTlsDefaultCtx();
|
|
|
|
|
if (ctx) {
|
|
|
|
|
*desc = array->desc;
|
|
|
|
|
}
|
|
|
|
|
return ihipLogStatus(hip_status);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hipGetTextureAlignmentOffset(size_t* offset, const textureReference* tex) {
|
2018-11-08 08:36:50 -06:00
|
|
|
HIP_INIT_API(hipGetTextureAlignmentOffset, offset, tex);
|
2017-07-17 15:16:12 -04:00
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hip_status = hipSuccess;
|
2017-07-17 15:16:12 -04:00
|
|
|
|
|
|
|
|
auto ctx = ihipGetTlsDefaultCtx();
|
|
|
|
|
if (ctx) {
|
2018-07-24 12:25:40 +05:30
|
|
|
if(offset != nullptr)
|
|
|
|
|
*offset = 0;
|
2017-07-17 15:16:12 -04:00
|
|
|
}
|
|
|
|
|
return ihipLogStatus(hip_status);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hipGetTextureReference(const textureReference** tex, const void* symbol) {
|
2018-11-08 08:36:50 -06:00
|
|
|
HIP_INIT_API(hipGetTextureReference, tex, symbol);
|
2017-07-17 15:16:12 -04:00
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hip_status = hipSuccess;
|
2017-07-17 15:16:12 -04:00
|
|
|
|
|
|
|
|
auto ctx = ihipGetTlsDefaultCtx();
|
|
|
|
|
if (ctx) {
|
|
|
|
|
}
|
|
|
|
|
return ihipLogStatus(hip_status);
|
|
|
|
|
}
|
2017-11-09 22:10:55 +05:30
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hipTexRefSetFormat(textureReference* tex, hipArray_Format fmt, int NumPackedComponents) {
|
2018-11-08 08:36:50 -06:00
|
|
|
HIP_INIT_API(hipTexRefSetFormat, tex, fmt, NumPackedComponents);
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hip_status = hipSuccess;
|
|
|
|
|
tex->format = fmt;
|
|
|
|
|
tex->numChannels = NumPackedComponents;
|
2017-11-09 22:10:55 +05:30
|
|
|
return ihipLogStatus(hip_status);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hipTexRefSetFlags(textureReference* tex, unsigned int flags) {
|
2018-11-08 08:36:50 -06:00
|
|
|
HIP_INIT_API(hipTexRefSetFlags, tex, flags);
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hip_status = hipSuccess;
|
|
|
|
|
tex->normalized = flags;
|
2017-11-09 22:10:55 +05:30
|
|
|
return ihipLogStatus(hip_status);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hipTexRefSetFilterMode(textureReference* tex, hipTextureFilterMode fm) {
|
2018-11-08 08:36:50 -06:00
|
|
|
HIP_INIT_API(hipTexRefSetFilterMode, tex, fm);
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hip_status = hipSuccess;
|
2017-11-09 22:10:55 +05:30
|
|
|
tex->filterMode = fm;
|
|
|
|
|
return ihipLogStatus(hip_status);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hipTexRefSetAddressMode(textureReference* tex, int dim, hipTextureAddressMode am) {
|
2018-11-08 08:36:50 -06:00
|
|
|
HIP_INIT_API(hipTexRefSetAddressMode, tex, dim, am);
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hip_status = hipSuccess;
|
|
|
|
|
tex->addressMode[dim] = am;
|
2017-11-09 22:10:55 +05:30
|
|
|
return ihipLogStatus(hip_status);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-04 01:08:45 -07:00
|
|
|
hipError_t hipTexRefGetAddressMode(hipTextureAddressMode* am, textureReference tex, int dim) {
|
|
|
|
|
HIP_INIT_API(hipTexRefGetAddressMode,am, &tex, dim);
|
|
|
|
|
|
|
|
|
|
if ((am == nullptr) || (dim >= 3))
|
|
|
|
|
return ihipLogStatus(hipErrorInvalidValue);
|
|
|
|
|
|
|
|
|
|
*am = tex.addressMode[dim];
|
|
|
|
|
|
|
|
|
|
return ihipLogStatus(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hipTexRefSetArray(textureReference* tex, hipArray_const_t array, unsigned int flags) {
|
2018-11-08 08:36:50 -06:00
|
|
|
HIP_INIT_API(hipTexRefSetArray, tex, array, flags);
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hip_status = hipSuccess;
|
2017-11-09 22:10:55 +05:30
|
|
|
|
2019-08-05 02:51:02 -07:00
|
|
|
hip_status = ihipBindTextureToArrayImpl(tls, array->textureType, hipReadModeElementType, array,
|
2018-03-12 11:29:03 +05:30
|
|
|
array->desc, tex);
|
2017-11-14 11:09:35 +05:30
|
|
|
return ihipLogStatus(hip_status);
|
|
|
|
|
}
|
2017-11-15 18:23:28 +05:30
|
|
|
|
2019-10-04 01:08:45 -07:00
|
|
|
hipError_t hipTexRefGetArray(hipArray_t* array, textureReference tex) {
|
|
|
|
|
HIP_INIT_API(hipTexRefGetArray, array, &tex);
|
|
|
|
|
|
|
|
|
|
if (array == nullptr)
|
|
|
|
|
return ihipLogStatus(hipErrorInvalidValue);
|
|
|
|
|
|
|
|
|
|
hipTexture* pTexture = textureHash[tex.textureObject];
|
|
|
|
|
if((pTexture == nullptr) || (hipResourceTypeArray != pTexture->resDesc.resType))
|
|
|
|
|
return ihipLogStatus(hipErrorInvalidImage);
|
|
|
|
|
|
|
|
|
|
if (pTexture->devPtr == nullptr)
|
|
|
|
|
return ihipLogStatus(hipErrorUnknown);
|
|
|
|
|
|
|
|
|
|
*array = reinterpret_cast<hipArray_t>(pTexture->devPtr);
|
|
|
|
|
|
|
|
|
|
return ihipLogStatus(hipSuccess);
|
|
|
|
|
}
|
2017-11-15 18:23:28 +05:30
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hipTexRefSetAddress(size_t* offset, textureReference* tex, hipDeviceptr_t devPtr,
|
|
|
|
|
size_t size) {
|
2018-11-08 08:36:50 -06:00
|
|
|
HIP_INIT_API(hipTexRefSetAddress, offset, tex, devPtr, size);
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hip_status = hipSuccess;
|
2017-11-15 18:23:28 +05:30
|
|
|
// TODO: hipReadModeElementType is default.
|
2019-08-05 02:51:02 -07:00
|
|
|
hip_status = ihipBindTextureImpl(tls, hipTextureType1D, hipReadModeElementType, offset, devPtr, NULL,
|
2018-03-12 11:29:03 +05:30
|
|
|
size, tex);
|
2017-11-15 18:23:28 +05:30
|
|
|
return ihipLogStatus(hip_status);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-04 01:08:45 -07:00
|
|
|
hipError_t hipTexRefGetAddress(hipDeviceptr_t* dev_ptr, textureReference tex) {
|
|
|
|
|
HIP_INIT_API(hipTexRefGetAddress,dev_ptr, &tex);
|
|
|
|
|
|
|
|
|
|
if (dev_ptr == nullptr)
|
|
|
|
|
return ihipLogStatus(hipErrorInvalidValue);
|
|
|
|
|
|
|
|
|
|
hipTexture* pTexture = textureHash[tex.textureObject];
|
|
|
|
|
if (pTexture == nullptr)
|
|
|
|
|
return ihipLogStatus(hipErrorInvalidImage);
|
|
|
|
|
|
|
|
|
|
if (pTexture->devPtr == nullptr)
|
|
|
|
|
return ihipLogStatus(hipErrorUnknown);
|
|
|
|
|
|
|
|
|
|
*dev_ptr = reinterpret_cast<hipDeviceptr_t>(pTexture->devPtr);
|
|
|
|
|
return ihipLogStatus(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipError_t hipTexRefSetAddress2D(textureReference* tex, const HIP_ARRAY_DESCRIPTOR* desc,
|
|
|
|
|
hipDeviceptr_t devPtr, size_t pitch) {
|
2018-11-08 08:36:50 -06:00
|
|
|
HIP_INIT_API(hipTexRefSetAddress2D, tex, desc, devPtr, pitch);
|
2018-03-12 11:29:03 +05:30
|
|
|
size_t offset;
|
|
|
|
|
hipError_t hip_status = hipSuccess;
|
2017-11-15 18:23:28 +05:30
|
|
|
// TODO: hipReadModeElementType is default.
|
2019-08-05 02:51:02 -07:00
|
|
|
hip_status = ihipBindTexture2DImpl(tls, hipTextureType2D, hipReadModeElementType, &offset, devPtr,
|
2019-07-11 14:58:16 +03:00
|
|
|
NULL, desc->Width, desc->Height, tex);
|
2017-11-15 18:23:28 +05:30
|
|
|
return ihipLogStatus(hip_status);
|
|
|
|
|
}
|