From 8ddeeb45515ef7cc5e4c66b50aed4084a3f0ffac Mon Sep 17 00:00:00 2001 From: Vladislav Sytchenko Date: Mon, 23 Mar 2020 14:11:25 -0400 Subject: [PATCH] Enable initial sRGB support Instead of using the sampler field force_degamma to perform sRGB->linear conversion during pixel sampling, we use an appropriate image format instead. The overhead of this is having to create an image view when creating a texture object from an array. Change-Id: I1ca368c312c1fd4b6f784a3a1b35b5eeb28070ff --- vdi/hip_conversions.hpp | 7 +++++-- vdi/hip_memory.cpp | 2 +- vdi/hip_texture.cpp | 15 ++++++--------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/vdi/hip_conversions.hpp b/vdi/hip_conversions.hpp index 3b43cae2b1..0b8557ee4d 100644 --- a/vdi/hip_conversions.hpp +++ b/vdi/hip_conversions.hpp @@ -76,14 +76,17 @@ cl_channel_type getCLChannelType(const hipArray_Format hipFormat, } inline -cl_channel_order getCLChannelOrder(const unsigned int hipNumChannels) { +cl_channel_order getCLChannelOrder(const unsigned int hipNumChannels, + const int sRGB) { switch (hipNumChannels) { case 1: return CL_R; case 2: return CL_RG; case 4: - return CL_RGBA; + return (sRGB == 1) ? CL_sRGBA : CL_RGBA; + default: + break; } ShouldNotReachHere(); diff --git a/vdi/hip_memory.cpp b/vdi/hip_memory.cpp index f197ba2bef..fdcfa78ebc 100644 --- a/vdi/hip_memory.cpp +++ b/vdi/hip_memory.cpp @@ -545,7 +545,7 @@ hipError_t ihipArrayCreate(hipArray** array, return hipErrorNotSupported; } - const cl_channel_order channelOrder = hip::getCLChannelOrder(pAllocateArray->NumChannels); + const cl_channel_order channelOrder = hip::getCLChannelOrder(pAllocateArray->NumChannels, 0); const cl_channel_type channelType = hip::getCLChannelType(pAllocateArray->Format, hipReadModeElementType); const cl_mem_object_type imageType = hip::getCLMemObjectType(pAllocateArray->Width, pAllocateArray->Height, diff --git a/vdi/hip_texture.cpp b/vdi/hip_texture.cpp index b2e58a7f69..6b2f151922 100644 --- a/vdi/hip_texture.cpp +++ b/vdi/hip_texture.cpp @@ -130,10 +130,6 @@ hipError_t ihipCreateTextureObject(hipTextureObject_t* pTexObject, if (pTexDesc->addressMode[0] == hipAddressModeBorder) { return hipErrorNotSupported; } - // We don't program the force_degamma/skip_degamma fields in the HW sampler SRD. - if (pTexDesc->sRGB == 1) { - return hipErrorNotSupported; - } // We don't program the max_ansio_ratio field in the the HW sampler SRD. if (pTexDesc->maxAnisotropy != 0) { return hipErrorNotSupported; @@ -221,10 +217,11 @@ hipError_t ihipCreateTextureObject(hipTextureObject_t* pTexObject, // We need to create an image view if the user requested to use normalized pixel values, // due to already having the image created with a different format. if ((pResViewDesc != nullptr) || - (readMode == hipReadModeNormalizedFloat)) { + (readMode == hipReadModeNormalizedFloat) || + (pTexDesc->sRGB == 1)) { // TODO VDI currently right now can only change the format of the image. - const cl_channel_order channelOrder = (pResViewDesc != nullptr) ? hip::getCLChannelOrder(hip::getNumChannels(pResViewDesc->format)) : - hip::getCLChannelOrder(pResDesc->res.array.array->NumChannels); + const cl_channel_order channelOrder = (pResViewDesc != nullptr) ? hip::getCLChannelOrder(hip::getNumChannels(pResViewDesc->format), pTexDesc->sRGB) : + hip::getCLChannelOrder(pResDesc->res.array.array->NumChannels, pTexDesc->sRGB); const cl_channel_type channelType = (pResViewDesc != nullptr) ? hip::getCLChannelType(hip::getArrayFormat(pResViewDesc->format), readMode) : hip::getCLChannelType(pResDesc->res.array.array->Format, readMode); const amd::Image::Format imageFormat(cl_image_format{channelOrder, channelType}); @@ -244,7 +241,7 @@ hipError_t ihipCreateTextureObject(hipTextureObject_t* pTexObject, break; } case hipResourceTypeLinear: { - const cl_channel_order channelOrder = hip::getCLChannelOrder(hip::getNumChannels(pResDesc->res.linear.desc)); + const cl_channel_order channelOrder = hip::getCLChannelOrder(hip::getNumChannels(pResDesc->res.linear.desc), pTexDesc->sRGB); const cl_channel_type channelType = hip::getCLChannelType(hip::getArrayFormat(pResDesc->res.linear.desc), pTexDesc->readMode); const amd::Image::Format imageFormat({channelOrder, channelType}); const cl_mem_object_type imageType = hip::getCLMemObjectType(pResDesc->resType); @@ -268,7 +265,7 @@ hipError_t ihipCreateTextureObject(hipTextureObject_t* pTexObject, break; } case hipResourceTypePitch2D: { - const cl_channel_order channelOrder = hip::getCLChannelOrder(hip::getNumChannels(pResDesc->res.pitch2D.desc)); + const cl_channel_order channelOrder = hip::getCLChannelOrder(hip::getNumChannels(pResDesc->res.pitch2D.desc), pTexDesc->sRGB); const cl_channel_type channelType = hip::getCLChannelType(hip::getArrayFormat(pResDesc->res.pitch2D.desc), pTexDesc->readMode); const cl_mem_object_type imageType = hip::getCLMemObjectType(pResDesc->resType); size_t offset = 0;