From dcc2b854a64b3e4e890215ff21cf4b219724f524 Mon Sep 17 00:00:00 2001 From: lucy96chen <47800040+lucy96chen@users.noreply.github.com> Date: Tue, 26 Oct 2021 16:30:59 -0700 Subject: Expanded gfx::Format to include additional formats (#1982) * Format list updated with additional formats supported by both D3D and Vulkan; D3DUtil::getMapFormat() and VkUtil::getVkFormat() updated to include additional formats; GFX_FORMAT() updated with all additional formats (BC compression unfinished) * Finished updating GFX_FORMAT with newly added formats and sizes; Pixel size is now tracked using the FormatPixelSize struct containing the values for bytes per block and pixels per block to accomodate BC formats; Updated gfxGetFormatSize and associated sub-calls to return FormatPixelSize instead of uint8_t; Most calls to gfxGetFormatSize() updated to reflect changes, a couple calls still unupdated * Changes to accommodate new formats finished, debugging slang-literal unit test * First format unit test working * One test added for BC1Unorm and RGBA8Unorm_SRGB, both passing * Refactored format testing code to merge BC1Unorm and RGBA8Unorm SRGB into a single file * All unit tests added for BC and Srgb formats * Most tests added and working; Added five additional formats (still need tests) and made the appropriate changes to support these; createTextureView() modified for D3D11, D3D12, and Vulkan to take into account the format specified in the texture view desc when the texture's format is typeless * Format enums renamed to more closely match their D3D counterparts; Added a universal float and uint buffer and buffer view for use across all Format tests * Remaining tests added; D3D12 tests pass, but Vulkan crashes in BC1_UNORM and D3D11 spits out a bunch of D3D11 Errors (but supposedly passes) * re-run premake * Added Sint versions of test shaders; Vulkan and D3D11 tests also pass * Size struct for format unit tests no longer use initializer lists * Fixed a Size struct missed in the previous pass * Fixed minor bugs causing tests to fail * Added documentation detailing all currently unsupported formats * Skip tests causing unsupported format warnings due to swiftshader * updated several test using old Format enum names * Revert change to compareComputeResult() that was added for debugging purposes * DEBUGGING: Added prints to identify which formats are failing on CI * Reverted attempted debugging changes; Fixed texture2d-gather.hlsl to use updated Format enums * Fixed incorrect array sizes in d3d11 _initSrvDesc() * Commented out further tests that produce unexpected results when tested for Vulkan with swiftshader * Revert "Merge branch 'expanded-format-support' of https://github.com/lucy96chen/slang into expanded-format-support" This reverts commit 20008f0d3ecc3b1405ecac8c138edaa3cd37ed6b, reversing changes made to 6081e95827315fee50e18409394d5abd62fac787. * Added a fuzzy comparison function for use with floats * submodule update * Revert messed up changes caused by previous revert after automatically merging on github --- tools/gfx/cpu/render-cpu.cpp | 32 ++++---- tools/gfx/cuda/render-cuda.cpp | 26 +++--- tools/gfx/d3d/d3d-util.cpp | 116 +++++++++++++++++++++----- tools/gfx/d3d11/render-d3d11.cpp | 82 +++++++++++++++++-- tools/gfx/d3d12/render-d3d12.cpp | 21 +++-- tools/gfx/debug-layer.cpp | 22 ++--- tools/gfx/open-gl/render-gl.cpp | 21 +++-- tools/gfx/render.cpp | 173 ++++++++++++++++++++++++++++++++++----- tools/gfx/vulkan/render-vk.cpp | 35 ++++---- tools/gfx/vulkan/vk-util.cpp | 111 +++++++++++++++++++++---- 10 files changed, 502 insertions(+), 137 deletions(-) (limited to 'tools/gfx') diff --git a/tools/gfx/cpu/render-cpu.cpp b/tools/gfx/cpu/render-cpu.cpp index c6662b851..ccc7a4abd 100644 --- a/tools/gfx/cpu/render-cpu.cpp +++ b/tools/gfx/cpu/render-cpu.cpp @@ -169,21 +169,21 @@ struct CPUFormatInfoMap { memset(m_infos, 0, sizeof(m_infos)); - set(Format::RGBA_Float32, &_unpackFloatTexel<4>); - set(Format::RGB_Float32, &_unpackFloatTexel<3>); + set(Format::R32G32B32A32_FLOAT, &_unpackFloatTexel<4>); + set(Format::R32G32B32_FLOAT, &_unpackFloatTexel<3>); - set(Format::RG_Float32, &_unpackFloatTexel<2>); - set(Format::R_Float32, &_unpackFloatTexel<1>); + set(Format::R32G32_FLOAT, &_unpackFloatTexel<2>); + set(Format::R32_FLOAT, &_unpackFloatTexel<1>); - set(Format::RGBA_Float16, &_unpackFloat16Texel<4>); - set(Format::RG_Float16, &_unpackFloat16Texel<2>); - set(Format::R_Float16, &_unpackFloat16Texel<1>); + set(Format::R16G16B16A16_FLOAT, &_unpackFloat16Texel<4>); + set(Format::R16G16_FLOAT, &_unpackFloat16Texel<2>); + set(Format::R16_FLOAT, &_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>); + set(Format::R8G8B8A8_UNORM, &_unpackUnorm8Texel<4>); + set(Format::B8G8R8A8_UNORM, &_unpackUnormBGRA8Texel); + set(Format::R16_UINT, &_unpackUInt16Texel<1>); + set(Format::R32_UINT, &_unpackUInt32Texel<1>); + set(Format::D32_FLOAT, &_unpackFloatTexel<1>); } void set(Format format, CPUTextureUnpackFunc func) @@ -233,8 +233,10 @@ public: // the block extents would be 1 along each axis. // auto format = desc.format; - auto texelSize = gfxGetFormatSize(format); - m_texelSize = (int32_t) texelSize; + FormatInfo texelInfo; + gfxGetFormatInfo(format, &texelInfo); + uint32_t texelSize = uint32_t(texelInfo.blockSizeInBytes / texelInfo.pixelsPerBlock); + m_texelSize = texelSize; int32_t formatBlockSize[kMaxRank] = { 1, 1, 1 }; @@ -353,7 +355,7 @@ public: CPUTextureBaseShapeInfo const* m_baseShape; CPUTextureFormatInfo const* m_formatInfo; int32_t m_effectiveArrayElementCount = 0; - int32_t m_texelSize = 0; + uint32_t m_texelSize = 0; struct MipLevel { diff --git a/tools/gfx/cuda/render-cuda.cpp b/tools/gfx/cuda/render-cuda.cpp index ed22495cb..47c309d34 100644 --- a/tools/gfx/cuda/render-cuda.cpp +++ b/tools/gfx/cuda/render-cuda.cpp @@ -1362,29 +1362,31 @@ public: switch (desc.format) { - case Format::RGBA_Float32: - case Format::RGB_Float32: - case Format::RG_Float32: - case Format::R_Float32: - case Format::D_Float32: + case Format::R32G32B32A32_FLOAT: + case Format::R32G32B32_FLOAT: + case Format::R32G32_FLOAT: + case Format::R32_FLOAT: + case Format::D32_FLOAT: { - const FormatInfo info = gfxGetFormatInfo(desc.format); + FormatInfo info; + gfxGetFormatInfo(desc.format, &info); format = CU_AD_FORMAT_FLOAT; numChannels = info.channelCount; elementSize = sizeof(float) * numChannels; break; } - case Format::RGBA_Float16: - case Format::RG_Float16: - case Format::R_Float16: + case Format::R16G16B16A16_FLOAT: + case Format::R16G16_FLOAT: + case Format::R16_FLOAT: { - const FormatInfo info = gfxGetFormatInfo(desc.format); + FormatInfo info; + gfxGetFormatInfo(desc.format, &info); format = CU_AD_FORMAT_HALF; numChannels = info.channelCount; elementSize = sizeof(uint16_t) * numChannels; break; } - case Format::RGBA_Unorm_UInt8: + case Format::R8G8B8A8_UNORM: { format = CU_AD_FORMAT_UNSIGNED_INT8; numChannels = 4; @@ -1393,7 +1395,7 @@ public: } default: { - SLANG_ASSERT(!"Only support R_Float32/RGBA_Unorm_UInt8 formats for now"); + SLANG_ASSERT(!"Only support R32_FLOAT/R8G8B8A8_UNORM formats for now"); return SLANG_FAIL; } } diff --git a/tools/gfx/d3d/d3d-util.cpp b/tools/gfx/d3d/d3d-util.cpp index 1f8e5bf7b..d73b3f519 100644 --- a/tools/gfx/d3d/d3d-util.cpp +++ b/tools/gfx/d3d/d3d-util.cpp @@ -108,26 +108,102 @@ D3D12_DEPTH_STENCILOP_DESC D3DUtil::translateStencilOpDesc(DepthStencilOpDesc de { switch (format) { - case Format::RGBA_Float32: return DXGI_FORMAT_R32G32B32A32_FLOAT; - case Format::RGB_Float32: return DXGI_FORMAT_R32G32B32_FLOAT; - case Format::RG_Float32: return DXGI_FORMAT_R32G32_FLOAT; - case Format::R_Float32: return DXGI_FORMAT_R32_FLOAT; - case Format::RGBA_Unorm_UInt8: return DXGI_FORMAT_R8G8B8A8_UNORM; - case Format::BGRA_Unorm_UInt8: return DXGI_FORMAT_B8G8R8A8_UNORM; - case Format::RGBA_Snorm_UInt16: return DXGI_FORMAT_R16G16B16A16_SNORM; - case Format::RG_Snorm_UInt16: return DXGI_FORMAT_R16G16_SNORM; - - 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; - - case Format::D_Float32: return DXGI_FORMAT_D32_FLOAT; - case Format::D_Unorm24_S8: return DXGI_FORMAT_D24_UNORM_S8_UINT; - - default: return DXGI_FORMAT_UNKNOWN; + case Format::R32G32B32A32_TYPELESS: return DXGI_FORMAT_R32G32B32A32_TYPELESS; + case Format::R32G32B32_TYPELESS: return DXGI_FORMAT_R32G32B32_TYPELESS; + case Format::R32G32_TYPELESS: return DXGI_FORMAT_R32G32_TYPELESS; + case Format::R32_TYPELESS: return DXGI_FORMAT_R32_TYPELESS; + + case Format::R16G16B16A16_TYPELESS: return DXGI_FORMAT_R16G16B16A16_TYPELESS; + case Format::R16G16_TYPELESS: return DXGI_FORMAT_R16G16_TYPELESS; + case Format::R16_TYPELESS: return DXGI_FORMAT_R16_TYPELESS; + + case Format::R8G8B8A8_TYPELESS: return DXGI_FORMAT_R8G8B8A8_TYPELESS; + case Format::R8G8_TYPELESS: return DXGI_FORMAT_R8G8_TYPELESS; + case Format::R8_TYPELESS: return DXGI_FORMAT_R8_TYPELESS; + case Format::B8G8R8A8_TYPELESS: return DXGI_FORMAT_B8G8R8A8_TYPELESS; + + case Format::R32G32B32A32_FLOAT: return DXGI_FORMAT_R32G32B32A32_FLOAT; + case Format::R32G32B32_FLOAT: return DXGI_FORMAT_R32G32B32_FLOAT; + case Format::R32G32_FLOAT: return DXGI_FORMAT_R32G32_FLOAT; + case Format::R32_FLOAT: return DXGI_FORMAT_R32_FLOAT; + + case Format::R16G16B16A16_FLOAT: return DXGI_FORMAT_R16G16B16A16_FLOAT; + case Format::R16G16_FLOAT: return DXGI_FORMAT_R16G16_FLOAT; + case Format::R16_FLOAT: return DXGI_FORMAT_R16_FLOAT; + + case Format::R32G32B32A32_UINT: return DXGI_FORMAT_R32G32B32A32_UINT; + case Format::R32G32B32_UINT: return DXGI_FORMAT_R32G32B32_UINT; + case Format::R32G32_UINT: return DXGI_FORMAT_R32G32_UINT; + case Format::R32_UINT: return DXGI_FORMAT_R32_UINT; + + case Format::R16G16B16A16_UINT: return DXGI_FORMAT_R16G16B16A16_UINT; + case Format::R16G16_UINT: return DXGI_FORMAT_R16G16_UINT; + case Format::R16_UINT: return DXGI_FORMAT_R16_UINT; + + case Format::R8G8B8A8_UINT: return DXGI_FORMAT_R8G8B8A8_UINT; + case Format::R8G8_UINT: return DXGI_FORMAT_R8G8_UINT; + case Format::R8_UINT: return DXGI_FORMAT_R8_UINT; + + case Format::R32G32B32A32_SINT: return DXGI_FORMAT_R32G32B32A32_SINT; + case Format::R32G32B32_SINT: return DXGI_FORMAT_R32G32B32_SINT; + case Format::R32G32_SINT: return DXGI_FORMAT_R32G32_SINT; + case Format::R32_SINT: return DXGI_FORMAT_R32_SINT; + + case Format::R16G16B16A16_SINT: return DXGI_FORMAT_R16G16B16A16_SINT; + case Format::R16G16_SINT: return DXGI_FORMAT_R16G16_SINT; + case Format::R16_SINT: return DXGI_FORMAT_R16_SINT; + + case Format::R8G8B8A8_SINT: return DXGI_FORMAT_R8G8B8A8_SINT; + case Format::R8G8_SINT: return DXGI_FORMAT_R8G8_SINT; + case Format::R8_SINT: return DXGI_FORMAT_R8_SINT; + + case Format::R16G16B16A16_UNORM: return DXGI_FORMAT_R16G16B16A16_UNORM; + case Format::R16G16_UNORM: return DXGI_FORMAT_R16G16_UNORM; + case Format::R16_UNORM: return DXGI_FORMAT_R16_UNORM; + + case Format::R8G8B8A8_UNORM: return DXGI_FORMAT_R8G8B8A8_UNORM; + case Format::R8G8B8A8_UNORM_SRGB: return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; + case Format::R8G8_UNORM: return DXGI_FORMAT_R8G8_UNORM; + case Format::R8_UNORM: return DXGI_FORMAT_R8_UNORM; + case Format::B8G8R8A8_UNORM: return DXGI_FORMAT_B8G8R8A8_UNORM; + + case Format::R16G16B16A16_SNORM: return DXGI_FORMAT_R16G16B16A16_SNORM; + case Format::R16G16_SNORM: return DXGI_FORMAT_R16G16_SNORM; + case Format::R16_SNORM: return DXGI_FORMAT_R16_SNORM; + + case Format::R8G8B8A8_SNORM: return DXGI_FORMAT_R8G8B8A8_SNORM; + case Format::R8G8_SNORM: return DXGI_FORMAT_R8G8_SNORM; + case Format::R8_SNORM: return DXGI_FORMAT_R8_SNORM; + + case Format::D32_FLOAT: return DXGI_FORMAT_D32_FLOAT; + case Format::D16_UNORM: return DXGI_FORMAT_D16_UNORM; + + case Format::B4G4R4A4_UNORM: return DXGI_FORMAT_B4G4R4A4_UNORM; + case Format::B5G6R5_UNORM: return DXGI_FORMAT_B5G6R5_UNORM; + case Format::B5G5R5A1_UNORM: return DXGI_FORMAT_B5G5R5A1_UNORM; + + case Format::R9G9B9E5_SHAREDEXP: return DXGI_FORMAT_R9G9B9E5_SHAREDEXP; + case Format::R10G10B10A2_TYPELESS: return DXGI_FORMAT_R10G10B10A2_TYPELESS; + case Format::R10G10B10A2_UINT: return DXGI_FORMAT_R10G10B10A2_UINT; + case Format::R10G10B10A2_UNORM: return DXGI_FORMAT_R10G10B10A2_UNORM; + case Format::R11G11B10_FLOAT: return DXGI_FORMAT_R11G11B10_FLOAT; + + case Format::BC1_UNORM: return DXGI_FORMAT_BC1_UNORM; + case Format::BC1_UNORM_SRGB: return DXGI_FORMAT_BC1_UNORM_SRGB; + case Format::BC2_UNORM: return DXGI_FORMAT_BC2_UNORM; + case Format::BC2_UNORM_SRGB: return DXGI_FORMAT_BC2_UNORM_SRGB; + case Format::BC3_UNORM: return DXGI_FORMAT_BC3_UNORM; + case Format::BC3_UNORM_SRGB: return DXGI_FORMAT_BC3_UNORM_SRGB; + case Format::BC4_UNORM: return DXGI_FORMAT_BC4_UNORM; + case Format::BC4_SNORM: return DXGI_FORMAT_BC4_SNORM; + case Format::BC5_UNORM: return DXGI_FORMAT_BC5_UNORM; + case Format::BC5_SNORM: return DXGI_FORMAT_BC5_SNORM; + case Format::BC6H_UF16: return DXGI_FORMAT_BC6H_UF16; + case Format::BC6H_SF16: return DXGI_FORMAT_BC6H_SF16; + case Format::BC7_UNORM: return DXGI_FORMAT_BC7_UNORM; + case Format::BC7_UNORM_SRGB: return DXGI_FORMAT_BC7_UNORM_SRGB; + + default: return DXGI_FORMAT_UNKNOWN; } } diff --git a/tools/gfx/d3d11/render-d3d11.cpp b/tools/gfx/d3d11/render-d3d11.cpp index ec89c0879..b2bd042e6 100644 --- a/tools/gfx/d3d11/render-d3d11.cpp +++ b/tools/gfx/d3d11/render-d3d11.cpp @@ -2024,6 +2024,65 @@ SlangResult SLANG_MCALL createD3D11Device(const IDevice::Desc* desc, IDevice** o return SLANG_OK; } +static void _initSrvDesc(IResource::Type resourceType, const ITextureResource::Desc& textureDesc, DXGI_FORMAT pixelFormat, D3D11_SHADER_RESOURCE_VIEW_DESC& descOut) +{ + // create SRV + descOut = D3D11_SHADER_RESOURCE_VIEW_DESC(); + + descOut.Format = (pixelFormat == DXGI_FORMAT_UNKNOWN) ? D3DUtil::calcFormat(D3DUtil::USAGE_SRV, D3DUtil::getMapFormat(textureDesc.format)) : pixelFormat; + const int arraySize = calcEffectiveArraySize(textureDesc); + if (arraySize <= 1) + { + switch (textureDesc.type) + { + case IResource::Type::Texture1D: descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D; break; + case IResource::Type::Texture2D: descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; break; + case IResource::Type::Texture3D: descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D; break; + default: assert(!"Unknown dimension"); + } + + descOut.Texture2D.MipLevels = textureDesc.numMipLevels; + descOut.Texture2D.MostDetailedMip = 0; + } + else if (resourceType == IResource::Type::TextureCube) + { + if (textureDesc.arraySize > 1) + { + descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBEARRAY; + + descOut.TextureCubeArray.NumCubes = textureDesc.arraySize; + descOut.TextureCubeArray.First2DArrayFace = 0; + descOut.TextureCubeArray.MipLevels = textureDesc.numMipLevels; + descOut.TextureCubeArray.MostDetailedMip = 0; + } + else + { + descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE; + + descOut.TextureCube.MipLevels = textureDesc.numMipLevels; + descOut.TextureCube.MostDetailedMip = 0; + } + } + else + { + assert(textureDesc.size.depth > 1 || arraySize > 1); + + switch (textureDesc.type) + { + case IResource::Type::Texture1D: descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1DARRAY; break; + case IResource::Type::Texture2D: descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY; break; + case IResource::Type::Texture3D: descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D; break; + + default: assert(!"Unknown dimension"); + } + + descOut.Texture2DArray.ArraySize = max(textureDesc.size.depth, arraySize); + descOut.Texture2DArray.MostDetailedMip = 0; + descOut.Texture2DArray.MipLevels = textureDesc.numMipLevels; + descOut.Texture2DArray.FirstArraySlice = 0; + } +} + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!ScopeNVAPI !!!!!!!!!!!!!!!!!!!!!!!!!!!!! SlangResult D3D11Device::ScopeNVAPI::init(D3D11Device* device, Index regIndex) @@ -2884,8 +2943,11 @@ Result D3D11Device::createTextureView(ITextureResource* texture, IResourceView:: case IResourceView::Type::ShaderResource: { + D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; + _initSrvDesc(resourceImpl->getType(), *resourceImpl->getDesc(), D3DUtil::getMapFormat(desc.format), srvDesc); + ComPtr srv; - SLANG_RETURN_ON_FAIL(m_device->CreateShaderResourceView(resourceImpl->m_resource, nullptr, srv.writeRef())); + SLANG_RETURN_ON_FAIL(m_device->CreateShaderResourceView(resourceImpl->m_resource, &srvDesc, srv.writeRef())); RefPtr viewImpl = new ShaderResourceViewImpl(); viewImpl->m_type = ResourceViewImpl::Type::SRV; @@ -2928,7 +2990,9 @@ Result D3D11Device::createBufferView(IBufferResource* buffer, IResourceView::Des } else { - uavDesc.Buffer.NumElements = UINT(resourceDesc.sizeInBytes / gfxGetFormatSize(desc.format)); + FormatInfo sizeInfo; + gfxGetFormatInfo(desc.format, &sizeInfo); + uavDesc.Buffer.NumElements = UINT(resourceDesc.sizeInBytes / (sizeInfo.blockSizeInBytes / sizeInfo.pixelsPerBlock)); } ComPtr uav; @@ -2975,7 +3039,9 @@ Result D3D11Device::createBufferView(IBufferResource* buffer, IResourceView::Des } else { - srvDesc.Buffer.NumElements = UINT(resourceDesc.sizeInBytes / gfxGetFormatSize(desc.format)); + FormatInfo sizeInfo; + gfxGetFormatInfo(desc.format, &sizeInfo); + srvDesc.Buffer.NumElements = UINT(resourceDesc.sizeInBytes / (sizeInfo.blockSizeInBytes / sizeInfo.pixelsPerBlock)); } ComPtr srv; @@ -3019,17 +3085,17 @@ Result D3D11Device::createInputLayout(const InputElementDesc* inputElementsIn, U char const* typeName = "Unknown"; switch (inputElementsIn[ii].format) { - case Format::RGBA_Float32: - case Format::RGBA_Unorm_UInt8: + case Format::R32G32B32A32_FLOAT: + case Format::R8G8B8A8_UNORM: typeName = "float4"; break; - case Format::RGB_Float32: + case Format::R32G32B32_FLOAT: typeName = "float3"; break; - case Format::RG_Float32: + case Format::R32G32_FLOAT: typeName = "float2"; break; - case Format::R_Float32: + case Format::R32_FLOAT: typeName = "float"; break; default: diff --git a/tools/gfx/d3d12/render-d3d12.cpp b/tools/gfx/d3d12/render-d3d12.cpp index 8029826a3..aa945fd85 100644 --- a/tools/gfx/d3d12/render-d3d12.cpp +++ b/tools/gfx/d3d12/render-d3d12.cpp @@ -4711,7 +4711,12 @@ Result D3D12Device::createTextureResource(const ITextureResource::Desc& descIn, const D3D12_PLACED_SUBRESOURCE_FOOTPRINT& layout = layouts[j]; const D3D12_SUBRESOURCE_FOOTPRINT& footprint = layout.Footprint; - const TextureResource::Size mipSize = calcMipSize(srcDesc.size, j); + TextureResource::Size mipSize = calcMipSize(srcDesc.size, j); + if (gfxIsCompressedFormat(descIn.format)) + { + mipSize.width = int(D3DUtil::calcAligned(mipSize.width, 4)); + mipSize.height = int(D3DUtil::calcAligned(mipSize.height, 4)); + } assert(footprint.Width == mipSize.width && footprint.Height == mipSize.height && footprint.Depth == mipSize.depth); @@ -4733,7 +4738,8 @@ Result D3D12Device::createTextureResource(const ITextureResource::Desc& descIn, // const uint8_t* srcRow = srcLayer; uint8_t* dstRow = dstLayer; - for (int k = 0; k < mipSize.height; ++k) + int j = gfxIsCompressedFormat(descIn.format) ? 4 : 1; // BC compressed formats are organized into 4x4 blocks + for (int k = 0; k < mipSize.height; k += j) { ::memcpy(dstRow, srcRow, (size_t)mipRowSize); @@ -5022,7 +5028,8 @@ Result D3D12Device::createTextureView(ITextureResource* texture, IResourceView:: // Need to construct the D3D12_SHADER_RESOURCE_VIEW_DESC because otherwise TextureCube is not accessed // appropriately (rather than just passing nullptr to CreateShaderResourceView) const D3D12_RESOURCE_DESC resourceDesc = resourceImpl->m_resource.getResource()->GetDesc(); - const DXGI_FORMAT pixelFormat = resourceDesc.Format; + const DXGI_FORMAT pixelFormat = + gfxIsTypelessFormat(texture->getDesc()->format) ? D3DUtil::getMapFormat(desc.format) : resourceDesc.Format; D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc; _initSrvDesc(resourceImpl->getType(), *resourceImpl->getDesc(), resourceDesc, pixelFormat, srvDesc); @@ -5070,7 +5077,9 @@ Result D3D12Device::createBufferView(IBufferResource* buffer, IResourceView::Des } else { - uavDesc.Buffer.NumElements = UINT(resourceDesc.sizeInBytes / gfxGetFormatSize(desc.format)); + FormatInfo sizeInfo; + gfxGetFormatInfo(desc.format, &sizeInfo); + uavDesc.Buffer.NumElements = UINT(resourceDesc.sizeInBytes / (sizeInfo.blockSizeInBytes / sizeInfo.pixelsPerBlock)); } @@ -5104,7 +5113,9 @@ Result D3D12Device::createBufferView(IBufferResource* buffer, IResourceView::Des } else { - srvDesc.Buffer.NumElements = UINT(resourceDesc.sizeInBytes / gfxGetFormatSize(desc.format)); + FormatInfo sizeInfo; + gfxGetFormatInfo(desc.format, &sizeInfo); + srvDesc.Buffer.NumElements = UINT(resourceDesc.sizeInBytes / (sizeInfo.blockSizeInBytes / sizeInfo.pixelsPerBlock)); } SLANG_RETURN_ON_FAIL(m_cpuViewHeap->allocate(&viewImpl->m_descriptor)); diff --git a/tools/gfx/debug-layer.cpp b/tools/gfx/debug-layer.cpp index 5f5b0505e..daf86b60d 100644 --- a/tools/gfx/debug-layer.cpp +++ b/tools/gfx/debug-layer.cpp @@ -205,30 +205,30 @@ void validateAccelerationStructureBuildInputs( case IAccelerationStructure::GeometryType::Triangles: switch (buildInputs.geometryDescs[i].content.triangles.vertexFormat) { - case Format::RGB_Float32: - case Format::RG_Float32: - case Format::RGBA_Float16: - case Format::RG_Float16: - case Format::RGBA_Snorm_UInt16: - case Format::RG_Snorm_UInt16: + case Format::R32G32B32_FLOAT: + case Format::R32G32_FLOAT: + case Format::R16G16B16A16_FLOAT: + case Format::R16G16_FLOAT: + case Format::R16G16B16A16_SNORM: + case Format::R16G16_SNORM: break; default: GFX_DIAGNOSE_ERROR( "Unsupported IAccelerationStructure::TriangleDesc::vertexFormat. Valid " - "values are RGB_Float32, RG_Float32, RGBA_Float16, RG_Float16, " - "RGBA_Snorm_UInt16 or RG_Snorm_UInt16."); + "values are R32G32B32_FLOAT, R32G32_FLOAT, R16G16B16A16_FLOAT, R16G16_FLOAT, " + "R16G16B16A16_SNORM or R16G16_SNORM."); } if (buildInputs.geometryDescs[i].content.triangles.indexCount) { switch (buildInputs.geometryDescs[i].content.triangles.indexFormat) { - case Format::R_UInt32: - case Format::R_UInt16: + case Format::R32_UINT: + case Format::R16_UINT: break; default: GFX_DIAGNOSE_ERROR( "Unsupported IAccelerationStructure::TriangleDesc::indexFormat. Valid " - "values are Unknown, R_UInt32 or R_UInt16."); + "values are Unknown, R32_UINT or R16_UINT."); } if (!buildInputs.geometryDescs[i].content.triangles.indexData) { diff --git a/tools/gfx/open-gl/render-gl.cpp b/tools/gfx/open-gl/render-gl.cpp index a5d5ae368..afcb8c781 100644 --- a/tools/gfx/open-gl/render-gl.cpp +++ b/tools/gfx/open-gl/render-gl.cpp @@ -1532,8 +1532,8 @@ public: enum class GlPixelFormat { Unknown, - RGBA_Unorm_UInt8, - D_Float32, + R8G8B8A8_UNORM, + D32_FLOAT, D_Unorm24_S8, CountOf, }; @@ -1600,9 +1600,8 @@ public: { switch (format) { - case Format::RGBA_Unorm_UInt8: return GlPixelFormat::RGBA_Unorm_UInt8; - case Format::D_Float32: return GlPixelFormat::D_Float32; - case Format::D_Unorm24_S8: return GlPixelFormat::D_Unorm24_S8; + case Format::R8G8B8A8_UNORM: return GlPixelFormat::R8G8B8A8_UNORM; + case Format::D32_FLOAT: return GlPixelFormat::D32_FLOAT; default: return GlPixelFormat::Unknown; } @@ -1612,8 +1611,8 @@ public: { // internalType, format, formatType { 0, 0, 0}, // GlPixelFormat::Unknown - { GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE }, // GlPixelFormat::RGBA_Unorm_UInt8 - { GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE}, // GlPixelFormat::D_Float32 + { GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE }, // GlPixelFormat::R8G8B8A8_UNORM + { GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE}, // GlPixelFormat::D32_FLOAT { GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_BYTE}, // GlPixelFormat::D_Unorm24_S8 }; @@ -1651,10 +1650,10 @@ void GLDevice::debugCallback(GLenum source, GLenum type, GLuint id, GLenum sever #define CASE(NAME, COUNT, TYPE, NORMALIZED) \ case Format::NAME: do { VertexAttributeFormat result = {COUNT, TYPE, NORMALIZED}; return result; } while (0) - CASE(RGBA_Float32, 4, GL_FLOAT, GL_FALSE); - CASE(RGB_Float32, 3, GL_FLOAT, GL_FALSE); - CASE(RG_Float32, 2, GL_FLOAT, GL_FALSE); - CASE(R_Float32, 1, GL_FLOAT, GL_FALSE); + CASE(R32G32B32A32_FLOAT, 4, GL_FLOAT, GL_FALSE); + CASE(R32G32B32_FLOAT, 3, GL_FLOAT, GL_FALSE); + CASE(R32G32_FLOAT, 2, GL_FLOAT, GL_FALSE); + CASE(R32_FLOAT, 1, GL_FLOAT, GL_FALSE); #undef CASE } } diff --git a/tools/gfx/render.cpp b/tools/gfx/render.cpp index cbf1c6d26..6fef96f0b 100644 --- a/tools/gfx/render.cpp +++ b/tools/gfx/render.cpp @@ -19,9 +19,9 @@ static bool debugLayerEnabled = false; /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Global Renderer Functions !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ -#define GFX_FORMAT_SIZE(name, size) uint8_t(size), +#define GFX_FORMAT_SIZE(name, blockSizeInBytes, pixelsPerBlock) {blockSizeInBytes, pixelsPerBlock}, -static const uint8_t s_formatSize[] = +static const uint32_t s_formatSizeInfo[][2] = { GFX_FORMAT(GFX_FORMAT_SIZE) }; @@ -32,7 +32,7 @@ static bool _checkFormat() Index count = 0; // Check the values are in the same order -#define GFX_FORMAT_CHECK(name, size) count += Index(Index(Format::name) == value++); +#define GFX_FORMAT_CHECK(name, blockSizeInBytes, pixelsPerblock) count += Index(Index(Format::name) == value++); GFX_FORMAT(GFX_FORMAT_CHECK) const bool r = (count == Index(Format::CountOf)); @@ -54,26 +54,113 @@ struct FormatInfoMap 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); + set(Format::R32G32B32A32_TYPELESS, SLANG_SCALAR_TYPE_UINT32, 4); + set(Format::R32G32B32_TYPELESS, SLANG_SCALAR_TYPE_UINT32, 3); + set(Format::R32G32_TYPELESS, SLANG_SCALAR_TYPE_UINT32, 2); + set(Format::R32_TYPELESS, SLANG_SCALAR_TYPE_UINT32, 1); + + set(Format::R16G16B16A16_TYPELESS, SLANG_SCALAR_TYPE_UINT16, 4); + set(Format::R16G16_TYPELESS, SLANG_SCALAR_TYPE_UINT16, 2); + set(Format::R16_TYPELESS, SLANG_SCALAR_TYPE_UINT16, 1); + + set(Format::R8G8B8A8_TYPELESS, SLANG_SCALAR_TYPE_UINT8, 4); + set(Format::R8G8_TYPELESS, SLANG_SCALAR_TYPE_UINT8, 2); + set(Format::R8_TYPELESS, SLANG_SCALAR_TYPE_UINT8, 1); + set(Format::B8G8R8A8_TYPELESS, SLANG_SCALAR_TYPE_UINT8, 4); + + set(Format::R32G32B32A32_FLOAT, SLANG_SCALAR_TYPE_FLOAT32, 4); + set(Format::R32G32B32_FLOAT, SLANG_SCALAR_TYPE_FLOAT32, 3); + set(Format::R32G32_FLOAT, SLANG_SCALAR_TYPE_FLOAT32, 2); + set(Format::R32_FLOAT, SLANG_SCALAR_TYPE_FLOAT32, 1); + + set(Format::R16G16B16A16_FLOAT, SLANG_SCALAR_TYPE_FLOAT16, 4); + set(Format::R16G16_FLOAT, SLANG_SCALAR_TYPE_FLOAT16, 2); + set(Format::R16_FLOAT, SLANG_SCALAR_TYPE_FLOAT16, 1); + + set(Format::R32G32B32A32_UINT, SLANG_SCALAR_TYPE_UINT32, 4); + set(Format::R32G32B32_UINT, SLANG_SCALAR_TYPE_UINT32, 3); + set(Format::R32G32_UINT, SLANG_SCALAR_TYPE_UINT32, 2); + set(Format::R32_UINT, SLANG_SCALAR_TYPE_UINT32, 1); + + set(Format::R16G16B16A16_UINT, SLANG_SCALAR_TYPE_UINT16, 4); + set(Format::R16G16_UINT, SLANG_SCALAR_TYPE_UINT16, 2); + set(Format::R16_UINT, SLANG_SCALAR_TYPE_UINT16, 1); + + set(Format::R8G8B8A8_UINT, SLANG_SCALAR_TYPE_UINT8, 4); + set(Format::R8G8_UINT, SLANG_SCALAR_TYPE_UINT8, 2); + set(Format::R8_UINT, SLANG_SCALAR_TYPE_UINT8, 1); + + set(Format::R32G32B32A32_SINT, SLANG_SCALAR_TYPE_INT32, 4); + set(Format::R32G32B32_SINT, SLANG_SCALAR_TYPE_INT32, 3); + set(Format::R32G32_SINT, SLANG_SCALAR_TYPE_INT32, 2); + set(Format::R32_SINT, SLANG_SCALAR_TYPE_INT32, 1); + + set(Format::R16G16B16A16_SINT, SLANG_SCALAR_TYPE_INT16, 4); + set(Format::R16G16_SINT, SLANG_SCALAR_TYPE_INT16, 2); + set(Format::R16_SINT, SLANG_SCALAR_TYPE_INT16, 1); + + set(Format::R8G8B8A8_SINT, SLANG_SCALAR_TYPE_INT8, 4); + set(Format::R8G8_SINT, SLANG_SCALAR_TYPE_INT8, 2); + set(Format::R8_SINT, SLANG_SCALAR_TYPE_INT8, 1); + + set(Format::R16G16B16A16_UNORM, SLANG_SCALAR_TYPE_FLOAT32, 4); + set(Format::R16G16_UNORM, SLANG_SCALAR_TYPE_FLOAT32, 2); + set(Format::R16_UNORM, SLANG_SCALAR_TYPE_FLOAT32, 1); + + set(Format::R8G8B8A8_UNORM, SLANG_SCALAR_TYPE_FLOAT32, 4); + set(Format::R8G8B8A8_UNORM_SRGB, SLANG_SCALAR_TYPE_FLOAT32, 4); + set(Format::R8G8_UNORM, SLANG_SCALAR_TYPE_FLOAT32, 2); + set(Format::R8_UNORM, SLANG_SCALAR_TYPE_FLOAT32, 1); + set(Format::B8G8R8A8_UNORM, SLANG_SCALAR_TYPE_FLOAT32, 4); + + set(Format::R16G16B16A16_SNORM, SLANG_SCALAR_TYPE_FLOAT32, 4); + set(Format::R16G16_SNORM, SLANG_SCALAR_TYPE_FLOAT32, 2); + set(Format::R16_SNORM, SLANG_SCALAR_TYPE_FLOAT32, 1); + + set(Format::R8G8B8A8_SNORM, SLANG_SCALAR_TYPE_FLOAT32, 4); + set(Format::R8G8_SNORM, SLANG_SCALAR_TYPE_FLOAT32, 2); + set(Format::R8_SNORM, SLANG_SCALAR_TYPE_FLOAT32, 1); + + set(Format::D32_FLOAT, SLANG_SCALAR_TYPE_FLOAT32, 1); + set(Format::D16_UNORM, SLANG_SCALAR_TYPE_FLOAT32, 1); + + set(Format::B4G4R4A4_UNORM, SLANG_SCALAR_TYPE_FLOAT32, 4); + set(Format::B5G6R5_UNORM, SLANG_SCALAR_TYPE_FLOAT32, 3); + set(Format::B5G5R5A1_UNORM, SLANG_SCALAR_TYPE_FLOAT32, 4); + + set(Format::R9G9B9E5_SHAREDEXP, SLANG_SCALAR_TYPE_FLOAT32, 3); + set(Format::R10G10B10A2_TYPELESS, SLANG_SCALAR_TYPE_FLOAT32, 4); + set(Format::R10G10B10A2_UNORM, SLANG_SCALAR_TYPE_FLOAT32, 4); + set(Format::R10G10B10A2_UINT, SLANG_SCALAR_TYPE_UINT32, 4); + set(Format::R11G11B10_FLOAT, SLANG_SCALAR_TYPE_FLOAT32, 3); + + set(Format::BC1_UNORM, SLANG_SCALAR_TYPE_FLOAT32, 4, 4, 4); + set(Format::BC1_UNORM_SRGB, SLANG_SCALAR_TYPE_FLOAT32, 4, 4, 4); + set(Format::BC2_UNORM, SLANG_SCALAR_TYPE_FLOAT32, 4, 4, 4); + set(Format::BC2_UNORM_SRGB, SLANG_SCALAR_TYPE_FLOAT32, 4, 4, 4); + set(Format::BC3_UNORM, SLANG_SCALAR_TYPE_FLOAT32, 4, 4, 4); + set(Format::BC3_UNORM_SRGB, SLANG_SCALAR_TYPE_FLOAT32, 4, 4, 4); + set(Format::BC4_UNORM, SLANG_SCALAR_TYPE_FLOAT32, 1, 4, 4); + set(Format::BC4_SNORM, SLANG_SCALAR_TYPE_FLOAT32, 1, 4, 4); + set(Format::BC5_UNORM, SLANG_SCALAR_TYPE_FLOAT32, 2, 4, 4); + set(Format::BC5_SNORM, SLANG_SCALAR_TYPE_FLOAT32, 2, 4, 4); + set(Format::BC6H_UF16, SLANG_SCALAR_TYPE_FLOAT32, 3, 4, 4); + set(Format::BC6H_SF16, SLANG_SCALAR_TYPE_FLOAT32, 3, 4, 4); + set(Format::BC7_UNORM, SLANG_SCALAR_TYPE_FLOAT32, 4, 4, 4); + set(Format::BC7_UNORM_SRGB, SLANG_SCALAR_TYPE_FLOAT32, 4, 4, 4); } - void set(Format format, SlangScalarType type, Index channelCount) + void set(Format format, SlangScalarType type, Index channelCount, uint32_t blockWidth = 1, uint32_t blockHeight = 1) { FormatInfo& info = m_infos[Index(format)]; info.channelCount = uint8_t(channelCount); info.channelType = uint8_t(type); + + auto sizeInfo = s_formatSizeInfo[Index(format)]; + info.blockSizeInBytes = sizeInfo[0]; + info.pixelsPerBlock = sizeInfo[1]; + info.blockWidth = blockWidth; + info.blockHeight = blockHeight; } const FormatInfo& get(Format format) const { return m_infos[Index(format)]; } @@ -85,19 +172,61 @@ static const FormatInfoMap s_formatInfoMap; static void _compileTimeAsserts() { - SLANG_COMPILE_TIME_ASSERT(SLANG_COUNT_OF(s_formatSize) == int(Format::CountOf)); + SLANG_COMPILE_TIME_ASSERT(SLANG_COUNT_OF(s_formatSizeInfo) == int(Format::CountOf)); } extern "C" { - size_t SLANG_MCALL gfxGetFormatSize(Format format) + SLANG_GFX_API bool gfxIsCompressedFormat(Format format) + { + switch (format) + { + case Format::BC1_UNORM: + case Format::BC1_UNORM_SRGB: + case Format::BC2_UNORM: + case Format::BC2_UNORM_SRGB: + case Format::BC3_UNORM: + case Format::BC3_UNORM_SRGB: + case Format::BC4_UNORM: + case Format::BC4_SNORM: + case Format::BC5_UNORM: + case Format::BC5_SNORM: + case Format::BC6H_UF16: + case Format::BC6H_SF16: + case Format::BC7_UNORM: + case Format::BC7_UNORM_SRGB: + return true; + default: + return false; + } + } + + SLANG_GFX_API bool gfxIsTypelessFormat(Format format) { - return s_formatSize[int(format)]; + switch (format) + { + case Format::R32G32B32A32_TYPELESS: + case Format::R32G32B32_TYPELESS: + case Format::R32G32_TYPELESS: + case Format::R32_TYPELESS: + case Format::R16G16B16A16_TYPELESS: + case Format::R16G16_TYPELESS: + case Format::R16_TYPELESS: + case Format::R8G8B8A8_TYPELESS: + case Format::R8G8_TYPELESS: + case Format::R8_TYPELESS: + case Format::B8G8R8A8_TYPELESS: + case Format::R10G10B10A2_TYPELESS: + return true; + default: + return false; + } } - SLANG_GFX_API FormatInfo gfxGetFormatInfo(Format format) + SLANG_GFX_API SlangResult gfxGetFormatInfo(Format format, FormatInfo* outInfo) { - return s_formatInfoMap.get(format); + *outInfo = s_formatInfoMap.get(format); + return SLANG_OK; } SlangResult _createDevice(const IDevice::Desc* desc, IDevice** outDevice) diff --git a/tools/gfx/vulkan/render-vk.cpp b/tools/gfx/vulkan/render-vk.cpp index 03f193ca6..3a1557a3c 100644 --- a/tools/gfx/vulkan/render-vk.cpp +++ b/tools/gfx/vulkan/render-vk.cpp @@ -3800,10 +3800,10 @@ public: { switch (indexFormat) { - case Format::R_UInt16: + case Format::R16_UINT: m_boundIndexFormat = VK_INDEX_TYPE_UINT16; break; - case Format::R_UInt32: + case Format::R32_UINT: m_boundIndexFormat = VK_INDEX_TYPE_UINT32; break; default: @@ -5026,7 +5026,7 @@ public: List formats; formats.add(VulkanUtil::getVkFormat(desc.format)); // HACK! To check for a different format if couldn't be found - if (desc.format == Format::RGBA_Unorm_UInt8) + if (desc.format == Format::R8G8B8A8_UNORM) { formats.add(VK_FORMAT_B8G8R8A8_UNORM); } @@ -5047,10 +5047,10 @@ public: // Save the desc m_desc = desc; - if (m_desc.format == Format::RGBA_Unorm_UInt8 && + if (m_desc.format == Format::R8G8B8A8_UNORM && m_vkformat == VK_FORMAT_B8G8R8A8_UNORM) { - m_desc.format = Format::BGRA_Unorm_UInt8; + m_desc.format = Format::B8G8R8A8_UNORM; } SLANG_RETURN_ON_FAIL(createSwapchainAndImages()); @@ -5763,7 +5763,6 @@ Result VKDevice::initVulkanInstanceAndDevice(const NativeHandle handles, bool us deviceExtensions.add(VK_KHR_SHADER_SUBGROUP_EXTENDED_TYPES_EXTENSION_NAME); m_features.add("shader-subgroup-extended-types"); } - if (extendedFeatures.accelerationStructureFeatures.accelerationStructure) { extendedFeatures.accelerationStructureFeatures.pNext = (void*)deviceCreateInfo.pNext; @@ -5781,7 +5780,6 @@ Result VKDevice::initVulkanInstanceAndDevice(const NativeHandle handles, bool us m_features.add("ray-query"); m_features.add("ray-tracing"); } - if (extendedFeatures.bufferDeviceAddressFeatures.bufferDeviceAddress) { extendedFeatures.bufferDeviceAddressFeatures.pNext = (void*)deviceCreateInfo.pNext; @@ -6373,17 +6371,16 @@ void VKDevice::_transitionImageLayout(VkImage image, VkFormat format, const Text size_t calcRowSize(Format format, int width) { - size_t pixelSize = gfxGetFormatSize(format); - if (pixelSize == 0) - { - return 0; - } - return size_t(pixelSize * width); + FormatInfo sizeInfo; + gfxGetFormatInfo(format, &sizeInfo); + return size_t((width + sizeInfo.blockWidth - 1) / sizeInfo.blockWidth * sizeInfo.blockSizeInBytes); } size_t calcNumRows(Format format, int height) { - return (size_t)height; + FormatInfo sizeInfo; + gfxGetFormatInfo(format, &sizeInfo); + return (size_t)(height + sizeInfo.blockHeight - 1) / sizeInfo.blockHeight; } Result VKDevice::createTextureResource(const ITextureResource::Desc& descIn, const ITextureResource::SubresourceData* initData, ITextureResource** outResource) @@ -6516,6 +6513,8 @@ Result VKDevice::createTextureResource(const ITextureResource::Desc& descIn, con uint8_t* dstData; m_api.vkMapMemory(m_device, uploadBuffer.m_memory, 0, bufferSize, 0, (void**)&dstData); + uint8_t* dstDataStart; + dstDataStart = dstData; size_t dstSubresourceOffset = 0; for (int i = 0; i < arraySize; ++i) @@ -6822,6 +6821,8 @@ Result VKDevice::createSamplerState(ISamplerState::Desc const& desc, ISamplerSta samplerInfo.compareEnable = desc.reductionOp == TextureReductionOp::Comparison; samplerInfo.compareOp = translateComparisonFunc(desc.comparisonFunc); samplerInfo.mipmapMode = translateMipFilterMode(desc.mipFilter); + samplerInfo.minLod = Math::Max(0.0f, desc.minLOD); + samplerInfo.maxLod = Math::Clamp(desc.maxLOD, samplerInfo.minLod, VK_LOD_CLAMP_NONE); VkSampler sampler; SLANG_VK_RETURN_ON_FAIL(m_api.vkCreateSampler(m_device, &samplerInfo, nullptr, &sampler)); @@ -6840,7 +6841,7 @@ Result VKDevice::createTextureView(ITextureResource* texture, IResourceView::Des VkImageViewCreateInfo createInfo = {}; createInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; createInfo.flags = 0; - createInfo.format = resourceImpl->m_vkformat; + createInfo.format = gfxIsTypelessFormat(texture->getDesc()->format) ? VulkanUtil::getVkFormat(desc.format) : resourceImpl->m_vkformat; createInfo.image = resourceImpl->m_image; createInfo.components = VkComponentMapping{ VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G,VK_COMPONENT_SWIZZLE_B,VK_COMPONENT_SWIZZLE_A }; bool isArray = resourceImpl->getDesc()->arraySize != 0; @@ -7013,7 +7014,9 @@ Result VKDevice::createInputLayout(const InputElementDesc* elements, UInt numEle dstDesc.offset = uint32_t(srcDesc.offset); - const size_t elementSize = gfxGetFormatSize(srcDesc.format); + FormatInfo sizeInfo; + gfxGetFormatInfo(srcDesc.format, &sizeInfo); + const size_t elementSize = sizeInfo.blockSizeInBytes / sizeInfo.pixelsPerBlock; assert(elementSize > 0); const size_t endElement = srcDesc.offset + elementSize; diff --git a/tools/gfx/vulkan/vk-util.cpp b/tools/gfx/vulkan/vk-util.cpp index 56664d9e4..3a40152a4 100644 --- a/tools/gfx/vulkan/vk-util.cpp +++ b/tools/gfx/vulkan/vk-util.cpp @@ -11,25 +11,102 @@ namespace gfx { { switch (format) { - case Format::RGBA_Float32: return VK_FORMAT_R32G32B32A32_SFLOAT; - 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::R32G32B32A32_TYPELESS: return VK_FORMAT_R32G32B32A32_SFLOAT; + case Format::R32G32B32_TYPELESS: return VK_FORMAT_R32G32B32_SFLOAT; + case Format::R32G32_TYPELESS: return VK_FORMAT_R32G32_SFLOAT; + case Format::R32_TYPELESS: 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::R16G16B16A16_TYPELESS: return VK_FORMAT_R16G16B16A16_SFLOAT; + case Format::R16G16_TYPELESS: return VK_FORMAT_R16G16_SFLOAT; + case Format::R16_TYPELESS: 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::RGBA_Snorm_UInt16: return VK_FORMAT_R16G16B16A16_SNORM; - case Format::RG_Snorm_UInt16: return VK_FORMAT_R16G16_SNORM; - case Format::R_UInt32: return VK_FORMAT_R32_UINT; + case Format::R8G8B8A8_TYPELESS: return VK_FORMAT_R8G8B8A8_UNORM; + case Format::R8G8_TYPELESS: return VK_FORMAT_R8G8_UNORM; + case Format::R8_TYPELESS: return VK_FORMAT_R8_UNORM; + case Format::B8G8R8A8_TYPELESS: return VK_FORMAT_B8G8R8A8_UNORM; - case Format::D_Float32: return VK_FORMAT_D32_SFLOAT; - case Format::D_Unorm24_S8: return VK_FORMAT_D24_UNORM_S8_UINT; + case Format::R32G32B32A32_FLOAT: return VK_FORMAT_R32G32B32A32_SFLOAT; + case Format::R32G32B32_FLOAT: return VK_FORMAT_R32G32B32_SFLOAT; + case Format::R32G32_FLOAT: return VK_FORMAT_R32G32_SFLOAT; + case Format::R32_FLOAT: return VK_FORMAT_R32_SFLOAT; - default: return VK_FORMAT_UNDEFINED; + case Format::R16G16B16A16_FLOAT: return VK_FORMAT_R16G16B16A16_SFLOAT; + case Format::R16G16_FLOAT: return VK_FORMAT_R16G16_SFLOAT; + case Format::R16_FLOAT: return VK_FORMAT_R16_SFLOAT; + + case Format::R32G32B32A32_UINT: return VK_FORMAT_R32G32B32A32_UINT; + case Format::R32G32B32_UINT: return VK_FORMAT_R32G32B32_UINT; + case Format::R32G32_UINT: return VK_FORMAT_R32G32_UINT; + case Format::R32_UINT: return VK_FORMAT_R32_UINT; + + case Format::R16G16B16A16_UINT: return VK_FORMAT_R16G16B16A16_UINT; + case Format::R16G16_UINT: return VK_FORMAT_R16G16_UINT; + case Format::R16_UINT: return VK_FORMAT_R16_UINT; + + case Format::R8G8B8A8_UINT: return VK_FORMAT_R8G8B8A8_UINT; + case Format::R8G8_UINT: return VK_FORMAT_R8G8_UINT; + case Format::R8_UINT: return VK_FORMAT_R8_UINT; + + case Format::R32G32B32A32_SINT: return VK_FORMAT_R32G32B32A32_SINT; + case Format::R32G32B32_SINT: return VK_FORMAT_R32G32B32_SINT; + case Format::R32G32_SINT: return VK_FORMAT_R32G32_SINT; + case Format::R32_SINT: return VK_FORMAT_R32_SINT; + + case Format::R16G16B16A16_SINT: return VK_FORMAT_R16G16B16A16_SINT; + case Format::R16G16_SINT: return VK_FORMAT_R16G16_SINT; + case Format::R16_SINT: return VK_FORMAT_R16_SINT; + + case Format::R8G8B8A8_SINT: return VK_FORMAT_R8G8B8A8_SINT; + case Format::R8G8_SINT: return VK_FORMAT_R8G8_SINT; + case Format::R8_SINT: return VK_FORMAT_R8_SINT; + + case Format::R16G16B16A16_UNORM: return VK_FORMAT_R16G16B16A16_UNORM; + case Format::R16G16_UNORM: return VK_FORMAT_R16G16_UNORM; + case Format::R16_UNORM: return VK_FORMAT_R16_UNORM; + + case Format::R8G8B8A8_UNORM: return VK_FORMAT_R8G8B8A8_UNORM; + case Format::R8G8B8A8_UNORM_SRGB: return VK_FORMAT_R8G8B8A8_SRGB; + case Format::R8G8_UNORM: return VK_FORMAT_R8G8_UNORM; + case Format::R8_UNORM: return VK_FORMAT_R8_UNORM; + case Format::B8G8R8A8_UNORM: return VK_FORMAT_B8G8R8A8_UNORM; + + case Format::R16G16B16A16_SNORM: return VK_FORMAT_R16G16B16A16_SNORM; + case Format::R16G16_SNORM: return VK_FORMAT_R16G16_SNORM; + case Format::R16_SNORM: return VK_FORMAT_R16_SNORM; + + case Format::R8G8B8A8_SNORM: return VK_FORMAT_R8G8B8A8_SNORM; + case Format::R8G8_SNORM: return VK_FORMAT_R8G8_SNORM; + case Format::R8_SNORM: return VK_FORMAT_R8_SNORM; + + case Format::D32_FLOAT: return VK_FORMAT_D32_SFLOAT; + case Format::D16_UNORM: return VK_FORMAT_D16_UNORM; + + case Format::B4G4R4A4_UNORM: return VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT; + case Format::B5G6R5_UNORM: return VK_FORMAT_R5G6B5_UNORM_PACK16; + case Format::B5G5R5A1_UNORM: return VK_FORMAT_A1R5G5B5_UNORM_PACK16; + + case Format::R9G9B9E5_SHAREDEXP: return VK_FORMAT_E5B9G9R9_UFLOAT_PACK32; + case Format::R10G10B10A2_TYPELESS: return VK_FORMAT_A2B10G10R10_UINT_PACK32; + case Format::R10G10B10A2_UINT: return VK_FORMAT_A2B10G10R10_UINT_PACK32; + case Format::R10G10B10A2_UNORM: return VK_FORMAT_A2B10G10R10_UNORM_PACK32; + case Format::R11G11B10_FLOAT: return VK_FORMAT_B10G11R11_UFLOAT_PACK32; + + case Format::BC1_UNORM: return VK_FORMAT_BC1_RGBA_UNORM_BLOCK; + case Format::BC1_UNORM_SRGB: return VK_FORMAT_BC1_RGBA_SRGB_BLOCK; + case Format::BC2_UNORM: return VK_FORMAT_BC2_UNORM_BLOCK; + case Format::BC2_UNORM_SRGB: return VK_FORMAT_BC2_SRGB_BLOCK; + case Format::BC3_UNORM: return VK_FORMAT_BC3_UNORM_BLOCK; + case Format::BC3_UNORM_SRGB: return VK_FORMAT_BC3_SRGB_BLOCK; + case Format::BC4_UNORM: return VK_FORMAT_BC4_UNORM_BLOCK; + case Format::BC4_SNORM: return VK_FORMAT_BC4_SNORM_BLOCK; + case Format::BC5_UNORM: return VK_FORMAT_BC5_UNORM_BLOCK; + case Format::BC5_SNORM: return VK_FORMAT_BC5_SNORM_BLOCK; + case Format::BC6H_UF16: return VK_FORMAT_BC6H_UFLOAT_BLOCK; + case Format::BC6H_SF16: return VK_FORMAT_BC6H_SFLOAT_BLOCK; + case Format::BC7_UNORM: return VK_FORMAT_BC7_UNORM_BLOCK; + case Format::BC7_UNORM_SRGB: return VK_FORMAT_BC7_SRGB_BLOCK; + + default: return VK_FORMAT_UNDEFINED; } } @@ -256,10 +333,10 @@ Result AccelerationStructureBuildGeometryInfoBuilder::build( vkGeomData.triangles.maxVertex = geomDesc.content.triangles.vertexCount - 1; switch (geomDesc.content.triangles.indexFormat) { - case Format::R_UInt32: + case Format::R32_UINT: vkGeomData.triangles.indexType = VK_INDEX_TYPE_UINT32; break; - case Format::R_UInt16: + case Format::R16_UINT: vkGeomData.triangles.indexType = VK_INDEX_TYPE_UINT16; break; case Format::Unknown: -- cgit v1.2.3