Add entry points for hipTexObject*() API
Even though the runtime and driver texture object API is one to one, the structs used by these APIs are not. See hipResourceDesc vs HIP_RESOURCE_DESC differences.
These differences are not trivial and most likely won't be able to handled by hipify, so we need new API entry points.
Change-Id: Id4bcb1ad0ae15378dbdb5a2ed07e5ea30f320082
[ROCm/hip commit: aea688b79c]
This commit is contained in:
@@ -654,4 +654,245 @@ HIP_MEMCPY3D getDrvMemcpy3DDesc(const hipMemcpy3DParms& desc) {
|
||||
|
||||
return descDrv;
|
||||
}
|
||||
|
||||
inline
|
||||
hipResourceType getResourceType(const HIPresourcetype resType) {
|
||||
// These two enums should be isomorphic.
|
||||
return static_cast<hipResourceType>(resType);
|
||||
}
|
||||
|
||||
inline
|
||||
HIPresourcetype getResourceType(const hipResourceType resType) {
|
||||
// These two enums should be isomorphic.
|
||||
return static_cast<HIPresourcetype>(resType);
|
||||
}
|
||||
|
||||
inline
|
||||
hipResourceDesc getResourceDesc(const HIP_RESOURCE_DESC& resDesc) {
|
||||
hipResourceDesc desc;
|
||||
|
||||
desc.resType = getResourceType(resDesc.resType);
|
||||
switch (resDesc.resType) {
|
||||
case hipResourceTypeArray:
|
||||
desc.res.array.array = resDesc.res.array.hArray;
|
||||
break;
|
||||
case hipResourceTypeMipmappedArray:
|
||||
desc.res.mipmap.mipmap = resDesc.res.mipmap.hMipmappedArray;
|
||||
break;
|
||||
case hipResourceTypeLinear:
|
||||
desc.res.linear.devPtr = resDesc.res.linear.devPtr;
|
||||
desc.res.linear.desc = getChannelFormatDesc(resDesc.res.linear.numChannels, resDesc.res.linear.format);
|
||||
desc.res.linear.sizeInBytes = resDesc.res.linear.sizeInBytes;
|
||||
break;
|
||||
case hipResourceTypePitch2D:
|
||||
desc.res.pitch2D.devPtr = resDesc.res.pitch2D.devPtr;
|
||||
desc.res.pitch2D.desc = getChannelFormatDesc(resDesc.res.pitch2D.numChannels, resDesc.res.pitch2D.format);
|
||||
desc.res.pitch2D.width = resDesc.res.pitch2D.width;
|
||||
desc.res.pitch2D.height = resDesc.res.pitch2D.height;
|
||||
desc.res.pitch2D.pitchInBytes = resDesc.res.pitch2D.pitchInBytes;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return desc;
|
||||
}
|
||||
|
||||
inline
|
||||
HIP_RESOURCE_DESC getResourceDesc(const hipResourceDesc& resDesc) {
|
||||
HIP_RESOURCE_DESC desc;
|
||||
|
||||
desc.resType = getResourceType(resDesc.resType);
|
||||
switch (resDesc.resType) {
|
||||
case HIP_RESOURCE_TYPE_ARRAY:
|
||||
desc.res.array.hArray = resDesc.res.array.array;
|
||||
break;
|
||||
case HIP_RESOURCE_TYPE_MIPMAPPED_ARRAY:
|
||||
desc.res.mipmap.hMipmappedArray = resDesc.res.mipmap.mipmap;
|
||||
break;
|
||||
case HIP_RESOURCE_TYPE_LINEAR:
|
||||
desc.res.linear.devPtr = resDesc.res.linear.devPtr;
|
||||
desc.res.linear.numChannels = getNumChannels(resDesc.res.linear.desc);
|
||||
desc.res.linear.format = getArrayFormat(resDesc.res.linear.desc);
|
||||
desc.res.linear.sizeInBytes = resDesc.res.linear.sizeInBytes;
|
||||
break;
|
||||
case HIP_RESOURCE_TYPE_PITCH2D:
|
||||
desc.res.pitch2D.devPtr = resDesc.res.pitch2D.devPtr;
|
||||
desc.res.pitch2D.numChannels = getNumChannels(resDesc.res.pitch2D.desc);
|
||||
desc.res.pitch2D.format = getArrayFormat(resDesc.res.pitch2D.desc);
|
||||
desc.res.pitch2D.width = resDesc.res.pitch2D.width;
|
||||
desc.res.pitch2D.height = resDesc.res.pitch2D.height;
|
||||
desc.res.pitch2D.pitchInBytes = resDesc.res.pitch2D.pitchInBytes;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return desc;
|
||||
}
|
||||
|
||||
inline
|
||||
hipTextureAddressMode getAddressMode(const HIPaddress_mode mode) {
|
||||
// These two enums should be isomorphic.
|
||||
return static_cast<hipTextureAddressMode>(mode);
|
||||
}
|
||||
|
||||
inline
|
||||
HIPaddress_mode getAddressMode(const hipTextureAddressMode mode) {
|
||||
// These two enums should be isomorphic.
|
||||
return static_cast<HIPaddress_mode>(mode);
|
||||
}
|
||||
|
||||
inline
|
||||
hipTextureFilterMode getFilterMode(const HIPfilter_mode mode) {
|
||||
// These two enums should be isomorphic.
|
||||
return static_cast<hipTextureFilterMode>(mode);
|
||||
}
|
||||
|
||||
inline
|
||||
HIPfilter_mode getFilterMode(const hipTextureFilterMode mode) {
|
||||
// These two enums should be isomorphic.
|
||||
return static_cast<HIPfilter_mode>(mode);
|
||||
}
|
||||
|
||||
inline
|
||||
hipTextureReadMode getReadMode(const unsigned int flags) {
|
||||
if (flags & HIP_TRSF_READ_AS_INTEGER) {
|
||||
return hipReadModeElementType;
|
||||
} else {
|
||||
return hipReadModeNormalizedFloat;
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
unsigned int getReadMode(const hipTextureReadMode mode) {
|
||||
if (mode == hipReadModeElementType) {
|
||||
return HIP_TRSF_READ_AS_INTEGER;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
int getsRGB(const unsigned int flags) {
|
||||
if (flags & HIP_TRSF_SRGB) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
unsigned int getsRGB(const int sRGB) {
|
||||
if (sRGB == 1) {
|
||||
return HIP_TRSF_SRGB;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
int getNormalizedCoords(const unsigned int flags) {
|
||||
if (flags & HIP_TRSF_NORMALIZED_COORDINATES) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
unsigned int getNormalizedCoords(const int normalizedCoords) {
|
||||
if (normalizedCoords == 1) {
|
||||
return HIP_TRSF_NORMALIZED_COORDINATES;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
hipTextureDesc getTextureDesc(const HIP_TEXTURE_DESC& texDesc) {
|
||||
hipTextureDesc desc;
|
||||
|
||||
desc.addressMode[0] = getAddressMode(texDesc.addressMode[0]);
|
||||
desc.addressMode[1] = getAddressMode(texDesc.addressMode[1]);
|
||||
desc.addressMode[2] = getAddressMode(texDesc.addressMode[2]);
|
||||
desc.filterMode = getFilterMode(texDesc.filterMode);
|
||||
desc.readMode = getReadMode(texDesc.flags);
|
||||
desc.sRGB = getsRGB(texDesc.flags);
|
||||
std::memcpy(desc.borderColor, texDesc.borderColor, sizeof(desc.borderColor));
|
||||
desc.normalizedCoords = getNormalizedCoords(texDesc.flags);
|
||||
desc.maxAnisotropy = texDesc.maxAnisotropy;
|
||||
desc.mipmapFilterMode = getFilterMode(texDesc.mipmapFilterMode);
|
||||
desc.mipmapLevelBias = texDesc.mipmapLevelBias;
|
||||
desc.minMipmapLevelClamp = texDesc.minMipmapLevelClamp;
|
||||
desc.maxMipmapLevelClamp = texDesc.maxMipmapLevelClamp;
|
||||
|
||||
return desc;
|
||||
}
|
||||
|
||||
inline
|
||||
HIP_TEXTURE_DESC getTextureDesc(const hipTextureDesc& texDesc) {
|
||||
HIP_TEXTURE_DESC desc;
|
||||
|
||||
desc.addressMode[0] = getAddressMode(texDesc.addressMode[0]);
|
||||
desc.addressMode[1] = getAddressMode(texDesc.addressMode[1]);
|
||||
desc.addressMode[2] = getAddressMode(texDesc.addressMode[2]);
|
||||
desc.filterMode = getFilterMode(texDesc.filterMode);
|
||||
desc.flags = 0;
|
||||
desc.flags |= getReadMode(texDesc.readMode);
|
||||
desc.flags |= getsRGB(texDesc.sRGB);
|
||||
desc.flags |= getNormalizedCoords(texDesc.normalizedCoords);
|
||||
desc.maxAnisotropy = texDesc.maxAnisotropy;
|
||||
desc.mipmapFilterMode = getFilterMode(texDesc.mipmapFilterMode);
|
||||
desc.mipmapLevelBias = texDesc.mipmapLevelBias;
|
||||
desc.minMipmapLevelClamp = texDesc.minMipmapLevelClamp;
|
||||
desc.maxMipmapLevelClamp = texDesc.maxMipmapLevelClamp;
|
||||
std::memcpy(desc.borderColor, texDesc.borderColor, sizeof(desc.borderColor));
|
||||
|
||||
return desc;
|
||||
}
|
||||
|
||||
inline
|
||||
hipResourceViewFormat getResourceViewFormat(const HIPresourceViewFormat format) {
|
||||
// These two enums should be isomorphic.
|
||||
return static_cast<hipResourceViewFormat>(format);
|
||||
}
|
||||
|
||||
inline
|
||||
HIPresourceViewFormat getResourceViewFormat(const hipResourceViewFormat format) {
|
||||
// These two enums should be isomorphic.
|
||||
return static_cast<HIPresourceViewFormat>(format);
|
||||
}
|
||||
|
||||
inline
|
||||
hipResourceViewDesc getResourceViewDesc(const HIP_RESOURCE_VIEW_DESC& resViewDesc) {
|
||||
hipResourceViewDesc desc;
|
||||
|
||||
desc.format = getResourceViewFormat(resViewDesc.format);
|
||||
desc.width = resViewDesc.width;
|
||||
desc.height = resViewDesc.height;
|
||||
desc.depth = resViewDesc.depth;
|
||||
desc.firstMipmapLevel = resViewDesc.firstMipmapLevel;
|
||||
desc.lastMipmapLevel = resViewDesc.lastMipmapLevel;
|
||||
desc.firstLayer = resViewDesc.firstLayer;
|
||||
desc.lastLayer = resViewDesc.lastLayer;
|
||||
|
||||
return desc;
|
||||
}
|
||||
|
||||
inline
|
||||
HIP_RESOURCE_VIEW_DESC getResourceViewDesc(const hipResourceViewDesc& resViewDesc) {
|
||||
HIP_RESOURCE_VIEW_DESC desc;
|
||||
|
||||
desc.format = getResourceViewFormat(resViewDesc.format);
|
||||
desc.width = resViewDesc.width;
|
||||
desc.height = resViewDesc.height;
|
||||
desc.depth = resViewDesc.depth;
|
||||
desc.firstMipmapLevel = resViewDesc.firstMipmapLevel;
|
||||
desc.lastMipmapLevel = resViewDesc.lastMipmapLevel;
|
||||
desc.firstLayer = resViewDesc.firstLayer;
|
||||
desc.lastLayer = resViewDesc.lastLayer;
|
||||
|
||||
return desc;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -238,3 +238,8 @@ hipFreeMipmappedArray
|
||||
hipMipmappedArrayGetLevel
|
||||
hipGetMipmappedArrayLevel
|
||||
hipMallocHost
|
||||
hipTexObjectCreate
|
||||
hipTexObjectDestroy
|
||||
hipTexObjectGetResourceDesc
|
||||
hipTexObjectGetResourceViewDesc
|
||||
hipTexObjectGetTextureDesc
|
||||
|
||||
@@ -232,6 +232,11 @@ global:
|
||||
hipMipmappedArrayGetLevel;
|
||||
hipGetMipmappedArrayLevel;
|
||||
hipMallocHost;
|
||||
hipTexObjectCreate;
|
||||
hipTexObjectDestroy;
|
||||
hipTexObjectGetResourceDesc;
|
||||
hipTexObjectGetResourceViewDesc;
|
||||
hipTexObjectGetTextureDesc;
|
||||
extern "C++" {
|
||||
hip_impl::hipLaunchKernelGGLImpl*;
|
||||
hip_impl::demangle*;
|
||||
|
||||
@@ -1134,4 +1134,74 @@ hipError_t hipTexRefSetMipmappedArray(textureReference* texRef,
|
||||
hipResourceViewDesc resViewDesc = hip::getResourceViewDesc(mipmappedArray, format);
|
||||
|
||||
HIP_RETURN(ihipCreateTextureObject(&texRef->textureObject, &resDesc, &texDesc, &resViewDesc));
|
||||
}
|
||||
}
|
||||
|
||||
hipError_t hipTexObjectCreate(hipTextureObject_t* pTexObject,
|
||||
const HIP_RESOURCE_DESC* pResDesc,
|
||||
const HIP_TEXTURE_DESC* pTexDesc,
|
||||
const HIP_RESOURCE_VIEW_DESC* pResViewDesc) {
|
||||
HIP_INIT_API(hipTexObjectCreate, pTexObject, pResDesc, pTexDesc, pResViewDesc);
|
||||
|
||||
if ((pTexObject == nullptr) ||
|
||||
(pResDesc == nullptr) || (pTexDesc == nullptr)) {
|
||||
HIP_RETURN(hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
hipResourceDesc resDesc = hip::getResourceDesc(*pResDesc);
|
||||
hipTextureDesc texDesc = hip::getTextureDesc(*pTexDesc);
|
||||
|
||||
if (pResViewDesc != nullptr) {
|
||||
hipResourceViewDesc resViewDesc = hip::getResourceViewDesc(*pResViewDesc);
|
||||
HIP_RETURN(ihipCreateTextureObject(pTexObject, &resDesc, &texDesc, &resViewDesc));
|
||||
} else {
|
||||
HIP_RETURN(ihipCreateTextureObject(pTexObject, &resDesc, &texDesc, nullptr));
|
||||
}
|
||||
}
|
||||
|
||||
hipError_t hipTexObjectDestroy(hipTextureObject_t texObject) {
|
||||
HIP_INIT_API(hipTexObjectDestroy, texObject);
|
||||
|
||||
HIP_RETURN(ihipDestroyTextureObject(texObject));
|
||||
}
|
||||
|
||||
hipError_t hipTexObjectGetResourceDesc(HIP_RESOURCE_DESC* pResDesc,
|
||||
hipTextureObject_t texObject) {
|
||||
HIP_INIT_API(hipTexObjectGetResourceDesc, pResDesc, texObject);
|
||||
|
||||
if ((pResDesc == nullptr) ||
|
||||
(texObject == nullptr)) {
|
||||
HIP_RETURN(hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
*pResDesc = hip::getResourceDesc(texObject->resDesc);
|
||||
|
||||
HIP_RETURN(hipSuccess);
|
||||
}
|
||||
|
||||
hipError_t hipTexObjectGetResourceViewDesc(HIP_RESOURCE_VIEW_DESC* pResViewDesc,
|
||||
hipTextureObject_t texObject) {
|
||||
HIP_INIT_API(hipTexObjectGetResourceViewDesc, pResViewDesc, texObject);
|
||||
|
||||
if ((pResViewDesc == nullptr) ||
|
||||
(texObject == nullptr)) {
|
||||
HIP_RETURN(hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
*pResViewDesc = hip::getResourceViewDesc(texObject->resViewDesc);
|
||||
|
||||
HIP_RETURN(hipSuccess);
|
||||
}
|
||||
|
||||
hipError_t hipTexObjectGetTextureDesc(HIP_TEXTURE_DESC* pTexDesc,
|
||||
hipTextureObject_t texObject) {
|
||||
HIP_INIT_API(hipTexObjectGetTextureDesc, pTexDesc, texObject);
|
||||
|
||||
if ((pTexDesc == nullptr) ||
|
||||
(texObject == nullptr)) {
|
||||
HIP_RETURN(hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
*pTexDesc = hip::getTextureDesc(texObject->texDesc);
|
||||
|
||||
HIP_RETURN(hipSuccess);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user