From ab878cc1eae7fba533e71db3d6d04c560bf7f832 Mon Sep 17 00:00:00 2001 From: Peyton Lee Date: Mon, 27 Apr 2026 15:38:14 +0800 Subject: [PATCH] amd/gmlib: add tm_generate_formatted_3DLut Adds a utility to format a 3D LUT into the required memory layout and write it into a given buffer. Signed-off-by: Peyton Lee Part-of: --- src/amd/gmlib/tonemap_adaptor.c | 40 +++++++++++++++++++++++++++++++-- src/amd/gmlib/tonemap_adaptor.h | 10 +++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/amd/gmlib/tonemap_adaptor.c b/src/amd/gmlib/tonemap_adaptor.c index 825c0363b94..2bdfbd126db 100644 --- a/src/amd/gmlib/tonemap_adaptor.c +++ b/src/amd/gmlib/tonemap_adaptor.c @@ -50,12 +50,12 @@ void tm_destroy(void** pp_tmGenerator) *pp_tmGenerator = NULL; } -int tm_generate3DLut(struct tonemap_param* pInparam, void* pformattedLutData) +int tm_generate3DLut(struct tonemap_param* pInparam, void* pLutData) { enum TMGReturnCode result; struct ToneMappingParameters tmParams; - tmParams.lutData = (uint16_t *)pformattedLutData; + tmParams.lutData = (uint16_t *)pLutData; ToneMapGenerator_SetInternalAllocators( (struct ToneMapGenerator*)pInparam->tm_handle, @@ -76,3 +76,39 @@ int tm_generate3DLut(struct tonemap_param* pInparam, void* pformattedLutData) return (int)result; } + +int tm_generate_formatted_3DLut( + uint16_t* pCpuLutData, + int cpuLutDim, + int gpuLutContainerDim, + const float bitDepthCpu, + const uint32_t bitDepthGpu, + void* pGpuLutData) +{ + int result = 1; + /* HardCode: use 256bits alignment */ + int AlignedLutContainerDim = ((gpuLutContainerDim + 32) >> 5) * 32; + + if ((NULL != pCpuLutData) && (NULL != pGpuLutData)) { + uint16_t* pGpuData = (uint16_t *)pGpuLutData; + int cpuSurfIndex = 0; + int gpuSurfIndex = 0; + int widthSize = AlignedLutContainerDim * 4; + int sliceSize = widthSize * gpuLutContainerDim; + int i, j, k; + + for (i = 0; i < cpuLutDim; i++) { + for (j = 0; j < cpuLutDim; j++) { + for (k = 0; k < cpuLutDim; k++) { + cpuSurfIndex = i * cpuLutDim * cpuLutDim * 3 + j * cpuLutDim * 3 + k * 3; + gpuSurfIndex = i * sliceSize + j * widthSize + k * 4; + *(pGpuData + gpuSurfIndex + 0) = (uint16_t)(((float)(pCpuLutData[cpuSurfIndex + 0]) / (float)bitDepthCpu) * bitDepthGpu); + *(pGpuData + gpuSurfIndex + 1) = (uint16_t)(((float)(pCpuLutData[cpuSurfIndex + 1]) / (float)bitDepthCpu) * bitDepthGpu); + *(pGpuData + gpuSurfIndex + 2) = (uint16_t)(((float)(pCpuLutData[cpuSurfIndex + 2]) / (float)bitDepthCpu) * bitDepthGpu); + } + } + } + result = 0; + } + return result; +} diff --git a/src/amd/gmlib/tonemap_adaptor.h b/src/amd/gmlib/tonemap_adaptor.h index 41777a24977..25887d34fd1 100644 --- a/src/amd/gmlib/tonemap_adaptor.h +++ b/src/amd/gmlib/tonemap_adaptor.h @@ -26,8 +26,14 @@ struct tonemap_param void* tm_create(void); void tm_destroy(void** pp_tmGenerator); -int tm_generate3DLut(struct tonemap_param* pInparam, void* pformattedLutData); +int tm_generate3DLut(struct tonemap_param* pInparam, void* pLutData); +int tm_generate_formatted_3DLut(uint16_t* pCpuLutData, + int cpuLutDim, + int gpuLutContainerDim, + const float bitDepthCpu, + const uint32_t bitDepthGpu, + void* pGpuLutData); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif