diff options
| author | lucy96chen <47800040+lucy96chen@users.noreply.github.com> | 2021-10-26 16:30:59 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-26 16:30:59 -0700 |
| commit | dcc2b854a64b3e4e890215ff21cf4b219724f524 (patch) | |
| tree | fe958a184f46f4a1bbf10f6c7174d31283df76dc /tools/gfx/d3d11/render-d3d11.cpp | |
| parent | fe6d5f1cf8865567e08cf210a2639ffde2886fc3 (diff) | |
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
Diffstat (limited to 'tools/gfx/d3d11/render-d3d11.cpp')
| -rw-r--r-- | tools/gfx/d3d11/render-d3d11.cpp | 82 |
1 files changed, 74 insertions, 8 deletions
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<ID3D11ShaderResourceView> 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<ShaderResourceViewImpl> 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<ID3D11UnorderedAccessView> 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<ID3D11ShaderResourceView> 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: |
