diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-10-07 20:05:34 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-10-07 20:05:34 +0000 |
| commit | 01a6742a3ccd45c8f8cd74f84c9b093c398450fc (patch) | |
| tree | 2014633aca9baae701912aca1d01549dc5cd5e99 /Graphics | |
| parent | Removed D3D11 debug names for Depth-stencil, Rasterizer, Blend states and sam... (diff) | |
| download | DiligentCore-01a6742a3ccd45c8f8cd74f84c9b093c398450fc.tar.gz DiligentCore-01a6742a3ccd45c8f8cd74f84c9b093c398450fc.zip | |
Added TextureFormatInfoExt::SampleCounts. Reworked texture format support queries in D3D11 and D3D12
Diffstat (limited to 'Graphics')
6 files changed, 57 insertions, 238 deletions
diff --git a/Graphics/GraphicsEngine/interface/GraphicsTypes.h b/Graphics/GraphicsEngine/interface/GraphicsTypes.h index 169a0793..2c37c0d5 100644 --- a/Graphics/GraphicsEngine/interface/GraphicsTypes.h +++ b/Graphics/GraphicsEngine/interface/GraphicsTypes.h @@ -1575,7 +1575,8 @@ namespace Diligent /// Indicates if the format can be used to create a cube texture bool TexCubeFmt = false; - /// Indicates if the format can be used to create a multisampled 2D texture - bool SupportsMS = false; + /// A bitmask specifying all the supported sample counts for this texture format. + /// If the format supports n samples, then (SampleCounts & n) != 0 + Uint32 SampleCounts = 0; }; } diff --git a/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp index 27b226e9..d9dd3901 100644 --- a/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp @@ -70,144 +70,37 @@ RenderDeviceD3D11Impl :: RenderDeviceD3D11Impl(IReferenceCounters* pRefCou m_DeviceCaps.bMultithreadedResourceCreationSupported = True; } - -bool CreateTestTexture1D(ID3D11Device* pDevice, const D3D11_TEXTURE1D_DESC& TexDesc) -{ - // Set the texture pointer address to nullptr to validate input parameters - // without creating the texture - // https://msdn.microsoft.com/en-us/library/windows/desktop/ff476520(v=vs.85).aspx - HRESULT hr = pDevice->CreateTexture1D( &TexDesc, nullptr, nullptr ); - return hr == S_FALSE; // S_FALSE means that input parameters passed validation -} - -bool CreateTestTexture2D(ID3D11Device* pDevice, const D3D11_TEXTURE2D_DESC &TexDesc) -{ - // Set the texture pointer address to nullptr to validate input parameters - // without creating the texture - // https://msdn.microsoft.com/en-us/library/windows/desktop/ff476521(v=vs.85).aspx - HRESULT hr = pDevice->CreateTexture2D( &TexDesc, nullptr, nullptr ); - return hr == S_FALSE; // S_FALSE means that input parameters passed validation -} - -bool CreateTestTexture3D(ID3D11Device* pDevice, const D3D11_TEXTURE3D_DESC& TexDesc) -{ - // Set the texture pointer address to nullptr to validate input parameters - // without creating the texture - // https://msdn.microsoft.com/en-us/library/windows/desktop/ff476522(v=vs.85).aspx - HRESULT hr = pDevice->CreateTexture3D( &TexDesc, nullptr, nullptr ); - return hr == S_FALSE; // S_FALSE means that input parameters passed validation -} - void RenderDeviceD3D11Impl::TestTextureFormat( TEXTURE_FORMAT TexFormat ) { auto &TexFormatInfo = m_TextureFormatsInfo[TexFormat]; VERIFY( TexFormatInfo.Supported, "Texture format is not supported" ); auto DXGIFormat = TexFormatToDXGI_Format(TexFormat); - UINT DefaultBind = 0; - if( TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH || - TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH_STENCIL ) - DefaultBind = D3D11_BIND_DEPTH_STENCIL; - else - DefaultBind = D3D11_BIND_SHADER_RESOURCE; - - const int TestTextureDim = 32; - const int TestTextureDepth = 8; - - // Create test texture 1D - TexFormatInfo.Tex1DFmt = false; - if( TexFormatInfo.ComponentType != COMPONENT_TYPE_COMPRESSED ) - { - D3D11_TEXTURE1D_DESC Tex1DDesc = - { - TestTextureDim, // UINT Width; - 1, // UINT MipLevels; - 1, // UINT ArraySize; - DXGIFormat, // DXGI_FORMAT Format; - D3D11_USAGE_DEFAULT, // D3D11_USAGE Usage; - DefaultBind, // UINT BindFlags; - 0, // UINT CPUAccessFlags; - 0 // UINT MiscFlags; - }; - TexFormatInfo.Tex1DFmt = CreateTestTexture1D(m_pd3d11Device, Tex1DDesc ); - } - - // Create test texture 2D - TexFormatInfo.Tex2DFmt = false; - TexFormatInfo.TexCubeFmt = false; - TexFormatInfo.ColorRenderable = false; - TexFormatInfo.DepthRenderable = false; - TexFormatInfo.SupportsMS = false; + + UINT FormatSupport = 0; + auto hr = m_pd3d11Device->CheckFormatSupport(DXGIFormat, &FormatSupport); + if (FAILED(hr)) { - D3D11_TEXTURE2D_DESC Tex2DDesc = - { - TestTextureDim, // UINT Width; - TestTextureDim, // UINT Height; - 1, // UINT MipLevels; - 1, // UINT ArraySize; - DXGIFormat, // DXGI_FORMAT Format; - { 1, 0 }, // DXGI_SAMPLE_DESC SampleDesc; - D3D11_USAGE_DEFAULT, // D3D11_USAGE Usage; - DefaultBind, // UINT BindFlags; - 0, // UINT CPUAccessFlags; - 0, // UINT MiscFlags; - }; - TexFormatInfo.Tex2DFmt = CreateTestTexture2D( m_pd3d11Device, Tex2DDesc ); - - if( TexFormatInfo.Tex2DFmt ) - { - { - D3D11_TEXTURE2D_DESC CubeTexDesc = Tex2DDesc; - CubeTexDesc.ArraySize = 6; - CubeTexDesc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE; - TexFormatInfo.TexCubeFmt = CreateTestTexture2D( m_pd3d11Device, CubeTexDesc ); - } - - if( TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH || - TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH_STENCIL ) - { - Tex2DDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; - TexFormatInfo.DepthRenderable = CreateTestTexture2D( m_pd3d11Device, Tex2DDesc ); - - if( TexFormatInfo.DepthRenderable ) - { - Tex2DDesc.SampleDesc.Count = 4; - TexFormatInfo.SupportsMS = CreateTestTexture2D( m_pd3d11Device, Tex2DDesc ); - } - } - else if( TexFormatInfo.ComponentType != COMPONENT_TYPE_COMPRESSED && - TexFormatInfo.Format != DXGI_FORMAT_R9G9B9E5_SHAREDEXP) - { - Tex2DDesc.BindFlags = D3D11_BIND_RENDER_TARGET; - TexFormatInfo.ColorRenderable = CreateTestTexture2D( m_pd3d11Device, Tex2DDesc ); - if( TexFormatInfo.ColorRenderable ) - { - Tex2DDesc.SampleDesc.Count = 4; - TexFormatInfo.SupportsMS = CreateTestTexture2D( m_pd3d11Device, Tex2DDesc ); - } - } - } + LOG_ERROR_MESSAGE("CheckFormatSupport() failed for format ", DXGIFormat); + return; } - // Create test texture 3D - TexFormatInfo.Tex3DFmt = false; - // 3D textures do not support depth formats - if( !(TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH || - TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH_STENCIL) ) + TexFormatInfo.Filterable = ((FormatSupport & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE) != 0) || + ((FormatSupport & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON) != 0); + TexFormatInfo.ColorRenderable = (FormatSupport & D3D11_FORMAT_SUPPORT_RENDER_TARGET) != 0; + TexFormatInfo.DepthRenderable = (FormatSupport & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL) != 0; + TexFormatInfo.Tex1DFmt = (FormatSupport & D3D11_FORMAT_SUPPORT_TEXTURE1D) != 0; + TexFormatInfo.Tex2DFmt = (FormatSupport & D3D11_FORMAT_SUPPORT_TEXTURE2D) != 0; + TexFormatInfo.Tex3DFmt = (FormatSupport & D3D11_FORMAT_SUPPORT_TEXTURE3D) != 0; + TexFormatInfo.TexCubeFmt = (FormatSupport & D3D11_FORMAT_SUPPORT_TEXTURECUBE) != 0; + + TexFormatInfo.SampleCounts = 0x0; + for(Uint32 SampleCount = 1; SampleCount <= D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT; SampleCount *= 2) { - D3D11_TEXTURE3D_DESC Tex3DDesc = - { - TestTextureDim, // UINT Width; - TestTextureDim, // UINT Height; - TestTextureDepth, // UINT Depth; - 1, // UINT MipLevels; - DXGIFormat, // DXGI_FORMAT Format; - D3D11_USAGE_DEFAULT,// D3D11_USAGE Usage; - DefaultBind, // UINT BindFlags; - 0, // UINT CPUAccessFlags; - 0 // UINT MiscFlags; - }; - TexFormatInfo.Tex3DFmt = CreateTestTexture3D( m_pd3d11Device, Tex3DDesc ); + UINT QualityLevels = 0; + hr = m_pd3d11Device->CheckMultisampleQualityLevels(DXGIFormat, SampleCount, &QualityLevels); + if(SUCCEEDED(hr) && QualityLevels > 0) + TexFormatInfo.SampleCounts |= SampleCount; } } diff --git a/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp index 1bb2267d..fe7550ff 100644 --- a/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp @@ -62,7 +62,7 @@ void SwapChainD3D11Impl::CreateRTVandDSV() "Failed to get back buffer from swap chain" ); static const char BackBufferName[] = "Main back buffer"; auto hr = pd3dBackBuffer->SetPrivateData(WKPDID_D3DDebugObjectName, _countof(BackBufferName)-1, BackBufferName); - VERIFY(SUCCEEDED(hr)); + DEV_CHECK_ERR(SUCCEEDED(hr), "Failed to set back buffer name"); RefCntAutoPtr<ITexture> pBackBuffer; pRenderDeviceD3D11Impl->CreateTextureFromD3DResource(pd3dBackBuffer, &pBackBuffer); diff --git a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp index cfe7e24c..f441fde0 100644 --- a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp @@ -239,22 +239,6 @@ RenderDeviceD3D12Impl::PooledCommandContext RenderDeviceD3D12Impl::AllocateComma return PooledCommandContext(pCtx, CmdCtxAllocator); } -bool CreateTestResource(ID3D12Device* pDevice, const D3D12_RESOURCE_DESC& ResDesc) -{ - // Set the texture pointer address to nullptr to validate input parameters - // without creating the texture - // https://msdn.microsoft.com/en-us/library/windows/desktop/dn899178(v=vs.85).aspx - - D3D12_HEAP_PROPERTIES HeapProps; - HeapProps.Type = D3D12_HEAP_TYPE_DEFAULT; - HeapProps.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN; - HeapProps.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN; - HeapProps.CreationNodeMask = 1; - HeapProps.VisibleNodeMask = 1; - - auto hr = pDevice->CreateCommittedResource( &HeapProps, D3D12_HEAP_FLAG_NONE, &ResDesc, D3D12_RESOURCE_STATE_COMMON, nullptr, __uuidof(ID3D12Resource), nullptr ); - return hr == S_FALSE; // S_FALSE means that input parameters passed validation -} void RenderDeviceD3D12Impl::TestTextureFormat( TEXTURE_FORMAT TexFormat ) { @@ -262,95 +246,31 @@ void RenderDeviceD3D12Impl::TestTextureFormat( TEXTURE_FORMAT TexFormat ) VERIFY( TexFormatInfo.Supported, "Texture format is not supported" ); auto DXGIFormat = TexFormatToDXGI_Format(TexFormat); - D3D12_RESOURCE_FLAGS DefaultResourceFlags = D3D12_RESOURCE_FLAG_NONE; - if( TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH || - TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH_STENCIL ) - DefaultResourceFlags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL; - - const int TestTextureDim = 32; - const int TestTextureDepth = 8; - - D3D12_RESOURCE_DESC ResDesc = - { - D3D12_RESOURCE_DIMENSION_TEXTURE1D, - 0, // Alignment - TestTextureDim, - 1, // Height - 1, // DepthOrArraySize - 1, // MipLevels - DXGIFormat, - {1, 0}, - D3D12_TEXTURE_LAYOUT_UNKNOWN, - DefaultResourceFlags - }; - - // Create test texture 1D - TexFormatInfo.Tex1DFmt = false; - if( TexFormatInfo.ComponentType != COMPONENT_TYPE_COMPRESSED ) - { - TexFormatInfo.Tex1DFmt = CreateTestResource(m_pd3d12Device, ResDesc ); - } - // Create test texture 2D - TexFormatInfo.Tex2DFmt = false; - TexFormatInfo.TexCubeFmt = false; - TexFormatInfo.ColorRenderable = false; - TexFormatInfo.DepthRenderable = false; - TexFormatInfo.SupportsMS = false; + D3D12_FEATURE_DATA_FORMAT_SUPPORT FormatSupport = {DXGIFormat}; + auto hr = m_pd3d12Device->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &FormatSupport, sizeof(FormatSupport)); + if (FAILED(hr)) { - ResDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; - ResDesc.Height = TestTextureDim; - TexFormatInfo.Tex2DFmt = CreateTestResource( m_pd3d12Device, ResDesc ); - - if( TexFormatInfo.Tex2DFmt ) - { - { - // D3D12_TEXTURE2D_DESC CubeTexDesc = Tex2DDesc; - ResDesc.DepthOrArraySize = 6; - // CubeTexDesc.MiscFlags = D3D12_RESOURCE_MISC_TEXTURECUBE; - TexFormatInfo.TexCubeFmt = CreateTestResource( m_pd3d12Device, ResDesc ); - ResDesc.DepthOrArraySize = 1; - } - - if( TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH || - TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH_STENCIL ) - { - ResDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL; - ResDesc.SampleDesc.Count = 1; - TexFormatInfo.DepthRenderable = CreateTestResource( m_pd3d12Device, ResDesc ); - - if( TexFormatInfo.DepthRenderable ) - { - ResDesc.SampleDesc.Count = 4; - TexFormatInfo.SupportsMS = CreateTestResource( m_pd3d12Device, ResDesc ); - } - } - else if( TexFormatInfo.ComponentType != COMPONENT_TYPE_COMPRESSED && - TexFormatInfo.Format != DXGI_FORMAT_R9G9B9E5_SHAREDEXP ) - { - ResDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET; - ResDesc.SampleDesc.Count = 1; - TexFormatInfo.ColorRenderable = CreateTestResource( m_pd3d12Device, ResDesc ); - if( TexFormatInfo.ColorRenderable ) - { - ResDesc.SampleDesc.Count = 4; - TexFormatInfo.SupportsMS = CreateTestResource( m_pd3d12Device, ResDesc ); - } - } - } + LOG_ERROR_MESSAGE("CheckFormatSupport() failed for format ", DXGIFormat); + return; } - // Create test texture 3D - TexFormatInfo.Tex3DFmt = false; - // 3D textures do not support depth formats - if( !(TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH || - TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH_STENCIL) ) + TexFormatInfo.Filterable = ((FormatSupport.Support1 & D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE) != 0) || + ((FormatSupport.Support1 & D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE_COMPARISON) != 0); + TexFormatInfo.ColorRenderable = (FormatSupport.Support1 & D3D12_FORMAT_SUPPORT1_RENDER_TARGET) != 0; + TexFormatInfo.DepthRenderable = (FormatSupport.Support1 & D3D12_FORMAT_SUPPORT1_DEPTH_STENCIL) != 0; + TexFormatInfo.Tex1DFmt = (FormatSupport.Support1 & D3D12_FORMAT_SUPPORT1_TEXTURE1D) != 0; + TexFormatInfo.Tex2DFmt = (FormatSupport.Support1 & D3D12_FORMAT_SUPPORT1_TEXTURE2D) != 0; + TexFormatInfo.Tex3DFmt = (FormatSupport.Support1 & D3D12_FORMAT_SUPPORT1_TEXTURE3D) != 0; + TexFormatInfo.TexCubeFmt = (FormatSupport.Support1 & D3D12_FORMAT_SUPPORT1_TEXTURECUBE) != 0; + + TexFormatInfo.SampleCounts = 0x0; + for(Uint32 SampleCount = 1; SampleCount <= D3D12_MAX_MULTISAMPLE_SAMPLE_COUNT; SampleCount *= 2) { - ResDesc.SampleDesc.Count = 1; - ResDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE3D; - ResDesc.Flags = DefaultResourceFlags; - ResDesc.DepthOrArraySize = TestTextureDepth; - TexFormatInfo.Tex3DFmt = CreateTestResource( m_pd3d12Device, ResDesc ); + D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS QualityLevels = {DXGIFormat, SampleCount}; + hr = m_pd3d12Device->CheckFeatureSupport(D3D12_FEATURE_MULTISAMPLE_QUALITY_LEVELS, &QualityLevels, sizeof(QualityLevels)); + if(SUCCEEDED(hr) && QualityLevels.NumQualityLevels > 0) + TexFormatInfo.SampleCounts |= SampleCount; } } diff --git a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp index 9524554e..f10a4277 100644 --- a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp @@ -646,16 +646,21 @@ void RenderDeviceGLImpl::TestTextureFormat( TEXTURE_FORMAT TexFormat ) } } - TexFormatInfo.SupportsMS = false; + TexFormatInfo.SampleCounts = 0x01; if( TexFormatInfo.ComponentType != COMPONENT_TYPE_COMPRESSED && m_DeviceCaps.TexCaps.bTexture2DMSSupported ) { #if GL_ARB_texture_storage_multisample - GLObjectWrappers::GLTextureObj TestGLTex( true ); - TexFormatInfo.SupportsMS = CreateTestGLTexture( ContextState, GL_TEXTURE_2D_MULTISAMPLE, TestGLTex, [&]() + for (GLsizei SampleCount = 2; SampleCount <= 8; SampleCount *= 2) { - glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GLFmt, TestTextureDim, TestTextureDim, GL_TRUE); - } ); + GLObjectWrappers::GLTextureObj TestGLTex( true ); + auto SampleCountSupported = CreateTestGLTexture( ContextState, GL_TEXTURE_2D_MULTISAMPLE, TestGLTex, [&]() + { + glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, SampleCount, GLFmt, TestTextureDim, TestTextureDim, GL_TRUE); + } ); + if (SampleCountSupported) + TexFormatInfo.SampleCounts |= SampleCount; + } #endif } diff --git a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp index 62772d92..cc82f4b2 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp @@ -397,7 +397,7 @@ void RenderDeviceVkImpl::TestTextureFormat( TEXTURE_FORMAT TexFormat ) TexFormatInfo.ColorRenderable = err == VK_SUCCESS; if (TexFormatInfo.ColorRenderable) { - TexFormatInfo.SupportsMS = ImgFmtProps.sampleCounts > VK_SAMPLE_COUNT_1_BIT; + TexFormatInfo.SampleCounts = ImgFmtProps.sampleCounts; } } } @@ -415,7 +415,7 @@ void RenderDeviceVkImpl::TestTextureFormat( TEXTURE_FORMAT TexFormat ) TexFormatInfo.DepthRenderable = err == VK_SUCCESS; if (TexFormatInfo.DepthRenderable) { - TexFormatInfo.SupportsMS = ImgFmtProps.sampleCounts > VK_SAMPLE_COUNT_1_BIT; + TexFormatInfo.SampleCounts = ImgFmtProps.sampleCounts; } } } |
