diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2021-05-06 12:45:00 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-06 12:45:00 -0400 |
| commit | e510a287deb25f2542a68bf21382f2557740d70c (patch) | |
| tree | a2bc079431edeeb979d61fa4612858f6aa13c901 /tools/gfx | |
| parent | 85632e8db19916a2f348fe356a91119d2fde2929 (diff) | |
Half texture support (#1836)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Split out StringEscapeUtil.
* Added StringEscapeUtil.
* Fix typo in unix quoting type.
* Small comment improvements.
* Try to fix linux linking issue.
* Fix typo.
* Attempt to fix linux link issue.
* Update VS proj even though nothing really changed.
* Fix another typo issue.
* Fix for windows issue.
Fixed bug.
* Make separate Utils for escaping.
* Fix typo.
* Split out into StringEscapeHandler.
* Windows shell does handle removing quotes (so remove code to remove them).
* Handle unescaping if not initiating using the shell.
* Slight improvement around shell like decoding.
* Simplify command extraction.
* Add shared-library category type.
* Fix bug in command extraction.
* Typo in transcendental category.
* Enable unit-test on in smoke test category.
* Make parsing failing output as a failing test.
* Fixes for transcendental tests. Disable tests that do not work.
* Changed category parsing.
* Removed the TestResult parameter from _gatherTestsForFile.
Made testsList only output.
* Remove testing if all tests were disabled.
* Make args of CommandLine always unescaped.
* Add category.
* Don't need escaping on unix/linux.
* Remove some no longer used functions.
* Add requireSMVersion to CUDAExtensionTracker.
* half-calc.slang now works for CUDA.
* bit-cast-16-bit works on CUDA.
* WIP handling of CUDA vector<half> types.
* Half swizzle CUDA.
* Half vector test.
* Fix swizzle half bug.
* Fix compilation issue with narrowing to Index.
* Add unary ops.
* Add some vector scalar maths ops.
* Add half vector conversions for CUDA.
* Fix erroneous comment.
* Support for half comparisons.
* First pass test for half compare.
* Fix bug in CUDA specialized emit control.
Updated tests to have pre and post inc/dec.
* Removed unneeded parts of the cuda prelude.
* Half structured buffer works on CUDA.
* Added name lookup for Gfx::Format
* Support half texture type in test system.
* Test for half reading on CUDA.
* Add half formats to Vk and D3D utils.
* Fix getAt for CUDA - where there might not be a .x member in a vector.
Diffstat (limited to 'tools/gfx')
| -rw-r--r-- | tools/gfx/cpu/render-cpu.cpp | 73 | ||||
| -rw-r--r-- | tools/gfx/cuda/render-cuda.cpp | 16 | ||||
| -rw-r--r-- | tools/gfx/d3d/d3d-util.cpp | 4 | ||||
| -rw-r--r-- | tools/gfx/render.cpp | 75 | ||||
| -rw-r--r-- | tools/gfx/vulkan/vk-util.cpp | 5 |
5 files changed, 131 insertions, 42 deletions
diff --git a/tools/gfx/cpu/render-cpu.cpp b/tools/gfx/cpu/render-cpu.cpp index 2d7d858c4..0bdc06ad6 100644 --- a/tools/gfx/cpu/render-cpu.cpp +++ b/tools/gfx/cpu/render-cpu.cpp @@ -89,6 +89,18 @@ void _unpackFloatTexel(void const* texelData, void* outData, size_t outSize) memcpy(outData, temp, outSize); } +template<int N> +void _unpackFloat16Texel(void const* texelData, void* outData, size_t outSize) +{ + auto input = (int16_t const*)texelData; + + float temp[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; + for (int i = 0; i < N; ++i) + temp[i] = HalfToFloat(input[i]); + + memcpy(outData, temp, outSize); +} + static inline float _unpackUnorm8Value(uint8_t value) { return value / 255.0f; @@ -143,42 +155,45 @@ void _unpackUInt32Texel(void const* texelData, void* outData, size_t outSize) memcpy(outData, temp, outSize); } -#define TEXTURE_FORMAT_INFO(FORMAT) static const CPUTextureFormatInfo kCPUTextureFormatInfo_##FORMAT +struct CPUFormatInfoMap +{ + CPUFormatInfoMap() + { + memset(m_infos, 0, sizeof(m_infos)); -TEXTURE_FORMAT_INFO(RGBA_Float32) = { &_unpackFloatTexel<4> }; -TEXTURE_FORMAT_INFO(RGB_Float32) = { &_unpackFloatTexel<3> }; -TEXTURE_FORMAT_INFO(RG_Float32) = { &_unpackFloatTexel<2> }; -TEXTURE_FORMAT_INFO(R_Float32) = { &_unpackFloatTexel<1> }; -TEXTURE_FORMAT_INFO(RGBA_Unorm_UInt8) = { &_unpackUnorm8Texel<4> }; -TEXTURE_FORMAT_INFO(BGRA_Unorm_UInt8) = { &_unpackUnormBGRA8Texel }; -TEXTURE_FORMAT_INFO(R_UInt16) = { &_unpackUInt16Texel<1> }; -TEXTURE_FORMAT_INFO(R_UInt32) = { &_unpackUInt32Texel<1> }; -TEXTURE_FORMAT_INFO(D_Float32) = { &_unpackFloatTexel<1> }; + set(Format::RGBA_Float32, &_unpackFloatTexel<4>); + set(Format::RGB_Float32, &_unpackFloatTexel<3>); -#undef TEXTURE_FORMAT_INFO + set(Format::RG_Float32, &_unpackFloatTexel<2>); + set(Format::R_Float32, &_unpackFloatTexel<1>); -static CPUTextureFormatInfo const* _getFormatInfo(Format format) -{ - switch(format) + set(Format::RGBA_Float16, &_unpackFloat16Texel<4>); + set(Format::RG_Float16, &_unpackFloat16Texel<2>); + set(Format::R_Float16, &_unpackFloat16Texel<1>); + + set(Format::RGBA_Unorm_UInt8, &_unpackUnorm8Texel<4>); + set(Format::BGRA_Unorm_UInt8, &_unpackUnormBGRA8Texel); + set(Format::R_UInt16, &_unpackUInt16Texel<1>); + set(Format::R_UInt32, &_unpackUInt32Texel<1>); + set(Format::D_Float32, &_unpackFloatTexel<1>); + } + + void set(Format format, CPUTextureUnpackFunc func) { - case Format::D_Unorm24_S8: - default: - return nullptr; + auto& info = m_infos[Index(format)]; + info.unpackFunc = func; + } + SLANG_FORCE_INLINE const CPUTextureFormatInfo& get(Format format) const { return m_infos[Index(format)]; } + CPUTextureFormatInfo m_infos[Index(Format::CountOf)]; +}; -#define CASE(FORMAT) case Format::FORMAT: return &kCPUTextureFormatInfo_##FORMAT; - CASE(RGBA_Float32) - CASE(RGB_Float32) - CASE(RG_Float32) - CASE(R_Float32) - CASE(RGBA_Unorm_UInt8) - CASE(BGRA_Unorm_UInt8) - CASE(R_UInt16) - CASE(R_UInt32) - CASE(D_Float32) +static const CPUFormatInfoMap g_formatInfoMap; -#undef CASE - } +static CPUTextureFormatInfo const* _getFormatInfo(Format format) +{ + const CPUTextureFormatInfo& info = g_formatInfoMap.get(format); + return info.unpackFunc ? &info : nullptr; } class CPUTextureResource : public TextureResource diff --git a/tools/gfx/cuda/render-cuda.cpp b/tools/gfx/cuda/render-cuda.cpp index a6400789f..b919ac6b0 100644 --- a/tools/gfx/cuda/render-cuda.cpp +++ b/tools/gfx/cuda/render-cuda.cpp @@ -1432,14 +1432,28 @@ public: switch (desc.format) { + case Format::RGBA_Float32: + case Format::RGB_Float32: + case Format::RG_Float32: case Format::R_Float32: case Format::D_Float32: { + const FormatInfo info = gfxGetFormatInfo(desc.format); format = CU_AD_FORMAT_FLOAT; - numChannels = 1; + numChannels = info.channelCount; elementSize = sizeof(float); break; } + case Format::RGBA_Float16: + case Format::RG_Float16: + case Format::R_Float16: + { + const FormatInfo info = gfxGetFormatInfo(desc.format); + format = CU_AD_FORMAT_HALF; + numChannels = info.channelCount; + elementSize = sizeof(uint16_t); + break; + } case Format::RGBA_Unorm_UInt8: { format = CU_AD_FORMAT_UNSIGNED_INT8; diff --git a/tools/gfx/d3d/d3d-util.cpp b/tools/gfx/d3d/d3d-util.cpp index dfc19c927..651d61abf 100644 --- a/tools/gfx/d3d/d3d-util.cpp +++ b/tools/gfx/d3d/d3d-util.cpp @@ -115,6 +115,10 @@ D3D12_DEPTH_STENCILOP_DESC D3DUtil::translateStencilOpDesc(DepthStencilOpDesc de case Format::RGBA_Unorm_UInt8: return DXGI_FORMAT_R8G8B8A8_UNORM; case Format::BGRA_Unorm_UInt8: return DXGI_FORMAT_B8G8R8A8_UNORM; + case Format::RGBA_Float16: return DXGI_FORMAT_R16G16B16A16_FLOAT; + case Format::RG_Float16: return DXGI_FORMAT_R16G16_FLOAT; + case Format::R_Float16: return DXGI_FORMAT_R16_FLOAT; + case Format::R_UInt16: return DXGI_FORMAT_R16_UINT; case Format::R_UInt32: return DXGI_FORMAT_R32_UINT; diff --git a/tools/gfx/render.cpp b/tools/gfx/render.cpp index d14ce904a..cbf1c6d26 100644 --- a/tools/gfx/render.cpp +++ b/tools/gfx/render.cpp @@ -19,24 +19,70 @@ static bool debugLayerEnabled = false; /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Global Renderer Functions !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ -static const uint8_t s_formatSize[] = { - 0, // Unknown, +#define GFX_FORMAT_SIZE(name, size) uint8_t(size), - uint8_t(sizeof(float) * 4), // RGBA_Float32, - uint8_t(sizeof(float) * 3), // RGB_Float32, - uint8_t(sizeof(float) * 2), // RG_Float32, - uint8_t(sizeof(float) * 1), // R_Float32, +static const uint8_t s_formatSize[] = +{ + GFX_FORMAT(GFX_FORMAT_SIZE) +}; + +static bool _checkFormat() +{ + Index value = 0; + Index count = 0; + + // Check the values are in the same order +#define GFX_FORMAT_CHECK(name, size) count += Index(Index(Format::name) == value++); + GFX_FORMAT(GFX_FORMAT_CHECK) + + const bool r = (count == Index(Format::CountOf)); + SLANG_ASSERT(r); + return r; +} + +// We don't make static because we will get a warning that it's unused +static const bool _checkFormatResult = _checkFormat(); + +struct FormatInfoMap +{ + FormatInfoMap() + { + // Set all to nothing initially + for (auto& info : m_infos) + { + info.channelCount = 0; + info.channelType = SLANG_SCALAR_TYPE_NONE; + } + + set(Format::RGBA_Float16, SLANG_SCALAR_TYPE_FLOAT16, 4); + set(Format::RG_Float16, SLANG_SCALAR_TYPE_FLOAT16, 2); + set(Format::R_Float16, SLANG_SCALAR_TYPE_FLOAT16, 1); + + set(Format::RGBA_Float32, SLANG_SCALAR_TYPE_FLOAT32, 4); + set(Format::RGB_Float32, SLANG_SCALAR_TYPE_FLOAT32, 3); + set(Format::RG_Float32, SLANG_SCALAR_TYPE_FLOAT32, 2); + set(Format::R_Float32, SLANG_SCALAR_TYPE_FLOAT32, 1); + + set(Format::R_UInt16, SLANG_SCALAR_TYPE_UINT16, 1); + set(Format::R_UInt32, SLANG_SCALAR_TYPE_UINT32, 1); + + set(Format::D_Float32, SLANG_SCALAR_TYPE_FLOAT32, 1); + } - uint8_t(sizeof(uint32_t)), // RGBA_Unorm_UInt8, - uint8_t(sizeof(uint32_t)), // BGRA_Unorm_UInt8, + void set(Format format, SlangScalarType type, Index channelCount) + { + FormatInfo& info = m_infos[Index(format)]; + info.channelCount = uint8_t(channelCount); + info.channelType = uint8_t(type); + } - uint8_t(sizeof(uint16_t)), // R_UInt16, - uint8_t(sizeof(uint32_t)), // R_UInt32, + const FormatInfo& get(Format format) const { return m_infos[Index(format)]; } - uint8_t(sizeof(float)), // D_Float32, - uint8_t(sizeof(uint32_t)), // D_Unorm24_S8, + FormatInfo m_infos[Index(Format::CountOf)]; }; +static const FormatInfoMap s_formatInfoMap; + static void _compileTimeAsserts() { SLANG_COMPILE_TIME_ASSERT(SLANG_COUNT_OF(s_formatSize) == int(Format::CountOf)); @@ -49,6 +95,11 @@ extern "C" return s_formatSize[int(format)]; } + SLANG_GFX_API FormatInfo gfxGetFormatInfo(Format format) + { + return s_formatInfoMap.get(format); + } + SlangResult _createDevice(const IDevice::Desc* desc, IDevice** outDevice) { switch (desc->deviceType) diff --git a/tools/gfx/vulkan/vk-util.cpp b/tools/gfx/vulkan/vk-util.cpp index 135fe3732..5f7077753 100644 --- a/tools/gfx/vulkan/vk-util.cpp +++ b/tools/gfx/vulkan/vk-util.cpp @@ -14,6 +14,11 @@ namespace gfx { case Format::RGB_Float32: return VK_FORMAT_R32G32B32_SFLOAT; case Format::RG_Float32: return VK_FORMAT_R32G32_SFLOAT; case Format::R_Float32: return VK_FORMAT_R32_SFLOAT; + + case Format::RGBA_Float16: return VK_FORMAT_R16G16B16A16_SFLOAT; + case Format::RG_Float16: return VK_FORMAT_R16G16_SFLOAT; + case Format::R_Float16: return VK_FORMAT_R16_SFLOAT; + case Format::RGBA_Unorm_UInt8: return VK_FORMAT_R8G8B8A8_UNORM; case Format::BGRA_Unorm_UInt8: return VK_FORMAT_B8G8R8A8_UNORM; case Format::R_UInt32: return VK_FORMAT_R32_UINT; |
