From 70ad9aac0e1ac2793c37d50a2788efd206b0381c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Fri, 23 Oct 2015 14:21:54 -0700 Subject: [PATCH] Split texture format test. --- include/bgfx/bgfxdefines.h | 16 ++++++++++----- src/bgfx.cpp | 40 +++++++++++++++++++++++++++----------- src/renderer_d3d11.cpp | 30 ++++++++++++++++++++++++++-- src/renderer_d3d12.cpp | 32 ++++++++++++++++++++++++++---- src/renderer_d3d9.cpp | 32 ++++++++++++++++++++++++++++++ src/renderer_gl.cpp | 4 ++++ 6 files changed, 132 insertions(+), 22 deletions(-) diff --git a/include/bgfx/bgfxdefines.h b/include/bgfx/bgfxdefines.h index 3d05fcd6..5ca5e7d0 100644 --- a/include/bgfx/bgfxdefines.h +++ b/include/bgfx/bgfxdefines.h @@ -376,11 +376,17 @@ #define BGFX_CAPS_FORMAT_TEXTURE_2D UINT16_C(0x0001) //!< Texture format is supported. #define BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB UINT16_C(0x0002) //!< Texture as sRGB format is supported. #define BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED UINT16_C(0x0004) //!< Texture format is emulated. -#define BGFX_CAPS_FORMAT_TEXTURE_VERTEX UINT16_C(0x0008) //!< Texture format can be used from vertex shader. -#define BGFX_CAPS_FORMAT_TEXTURE_IMAGE UINT16_C(0x0010) //!< Texture format can be used as image from compute shader. -#define BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER UINT16_C(0x0020) //!< Texture format can be used as frame buffer. -#define BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA UINT16_C(0x0040) //!< Texture format can be used as MSAA frame buffer. -#define BGFX_CAPS_FORMAT_TEXTURE_MSAA UINT16_C(0x0080) //!< Texture can be sampled as MSAA. +#define BGFX_CAPS_FORMAT_TEXTURE_3D UINT16_C(0x0008) //!< Texture format is supported. +#define BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB UINT16_C(0x0010) //!< Texture as sRGB format is supported. +#define BGFX_CAPS_FORMAT_TEXTURE_3D_EMULATED UINT16_C(0x0020) //!< Texture format is emulated. +#define BGFX_CAPS_FORMAT_TEXTURE_CUBE UINT16_C(0x0040) //!< Texture format is supported. +#define BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB UINT16_C(0x0080) //!< Texture as sRGB format is supported. +#define BGFX_CAPS_FORMAT_TEXTURE_CUBE_EMULATED UINT16_C(0x0100) //!< Texture format is emulated. +#define BGFX_CAPS_FORMAT_TEXTURE_VERTEX UINT16_C(0x0200) //!< Texture format can be used from vertex shader. +#define BGFX_CAPS_FORMAT_TEXTURE_IMAGE UINT16_C(0x0400) //!< Texture format can be used as image from compute shader. +#define BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER UINT16_C(0x0800) //!< Texture format can be used as frame buffer. +#define BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA UINT16_C(0x1000) //!< Texture format can be used as MSAA frame buffer. +#define BGFX_CAPS_FORMAT_TEXTURE_MSAA UINT16_C(0x2000) //!< Texture can be sampled as MSAA. /// #define BGFX_VIEW_NONE UINT8_C(0x00) //!< diff --git a/src/bgfx.cpp b/src/bgfx.cpp index a7eceb0d..1c34fef1 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -998,23 +998,31 @@ namespace bgfx } BX_TRACE("Supported texture formats:"); - BX_TRACE("\t +----------- x = supported / * = emulated"); - BX_TRACE("\t |+---------- sRGB format"); - BX_TRACE("\t ||+--------- vertex format"); - BX_TRACE("\t |||+-------- image"); - BX_TRACE("\t ||||+------- framebuffer"); - BX_TRACE("\t |||||+------ MSAA framebuffer"); - BX_TRACE("\t ||||||+----- MSAA texture"); - BX_TRACE("\t ||||||| +-- name"); + BX_TRACE("\t +--------------- 2D: x = supported / * = emulated"); + BX_TRACE("\t |+-------------- 2D: sRGB format"); + BX_TRACE("\t ||+------------- 3D: x = supported / * = emulated"); + BX_TRACE("\t |||+------------ 3D: sRGB format"); + BX_TRACE("\t ||||+----------- Cube: x = supported / * = emulated"); + BX_TRACE("\t |||||+---------- Cube: sRGB format"); + BX_TRACE("\t ||||||+--------- vertex format"); + BX_TRACE("\t |||||||+-------- image"); + BX_TRACE("\t ||||||||+------- framebuffer"); + BX_TRACE("\t |||||||||+------ MSAA framebuffer"); + BX_TRACE("\t ||||||||||+----- MSAA texture"); + BX_TRACE("\t ||||||||||| +-- name"); for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii) { if (TextureFormat::Unknown != ii && TextureFormat::UnknownDepth != ii) { uint16_t flags = g_caps.formats[ii]; - BX_TRACE("\t[%c%c%c%c%c%c%c] %s" - , flags&BGFX_CAPS_FORMAT_TEXTURE_2D ? 'x' : flags&BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED ? '*' : ' ' - , flags&BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB ? 'l' : ' ' + BX_TRACE("\t[%c%c%c%c%c%c%c%c%c%c%c] %s" + , flags&BGFX_CAPS_FORMAT_TEXTURE_2D ? 'x' : flags&BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED ? '*' : ' ' + , flags&BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB ? 'l' : ' ' + , flags&BGFX_CAPS_FORMAT_TEXTURE_3D ? 'x' : flags&BGFX_CAPS_FORMAT_TEXTURE_3D_EMULATED ? '*' : ' ' + , flags&BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB ? 'l' : ' ' + , flags&BGFX_CAPS_FORMAT_TEXTURE_CUBE ? 'x' : flags&BGFX_CAPS_FORMAT_TEXTURE_CUBE_EMULATED ? '*' : ' ' + , flags&BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB ? 'l' : ' ' , flags&BGFX_CAPS_FORMAT_TEXTURE_VERTEX ? 'v' : ' ' , flags&BGFX_CAPS_FORMAT_TEXTURE_IMAGE ? 'i' : ' ' , flags&BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER ? 'f' : ' ' @@ -1139,6 +1147,16 @@ namespace bgfx { g_caps.formats[s_emulatedFormats[ii] ] |= BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED; } + + if (0 == (g_caps.formats[s_emulatedFormats[ii] ] & BGFX_CAPS_FORMAT_TEXTURE_3D) ) + { + g_caps.formats[s_emulatedFormats[ii] ] |= BGFX_CAPS_FORMAT_TEXTURE_3D_EMULATED; + } + + if (0 == (g_caps.formats[s_emulatedFormats[ii] ] & BGFX_CAPS_FORMAT_TEXTURE_CUBE) ) + { + g_caps.formats[s_emulatedFormats[ii] ] |= BGFX_CAPS_FORMAT_TEXTURE_CUBE_EMULATED; + } } g_caps.rendererType = m_renderCtx->getRendererType(); diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index feef3559..e2ec495a 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -1281,6 +1281,20 @@ BX_PRAGMA_DIAGNOSTIC_POP(); : BGFX_CAPS_FORMAT_TEXTURE_NONE ; + support |= 0 != (data.OutFormatSupport & (0 + | D3D11_FORMAT_SUPPORT_TEXTURE3D + ) ) + ? BGFX_CAPS_FORMAT_TEXTURE_3D + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + + support |= 0 != (data.OutFormatSupport & (0 + | D3D11_FORMAT_SUPPORT_TEXTURECUBE + ) ) + ? BGFX_CAPS_FORMAT_TEXTURE_CUBE + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + support |= 0 != (data.OutFormatSupport & (0 | D3D11_FORMAT_SUPPORT_BUFFER | D3D11_FORMAT_SUPPORT_IA_VERTEX_BUFFER @@ -1359,12 +1373,24 @@ BX_PRAGMA_DIAGNOSTIC_POP(); { support |= 0 != (data.OutFormatSupport & (0 | D3D11_FORMAT_SUPPORT_TEXTURE2D - | D3D11_FORMAT_SUPPORT_TEXTURE3D - | D3D11_FORMAT_SUPPORT_TEXTURECUBE ) ) ? BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB : BGFX_CAPS_FORMAT_TEXTURE_NONE ; + + support |= 0 != (data.OutFormatSupport & (0 + | D3D11_FORMAT_SUPPORT_TEXTURE3D + ) ) + ? BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + + support |= 0 != (data.OutFormatSupport & (0 + | D3D11_FORMAT_SUPPORT_TEXTURECUBE + ) ) + ? BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; } else { diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index b87f20c6..a7151e68 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -907,13 +907,25 @@ namespace bgfx { namespace d3d12 { support |= 0 != (data.Support1 & (0 | D3D12_FORMAT_SUPPORT1_TEXTURE2D - | D3D12_FORMAT_SUPPORT1_TEXTURE3D - | D3D12_FORMAT_SUPPORT1_TEXTURECUBE ) ) ? BGFX_CAPS_FORMAT_TEXTURE_2D : BGFX_CAPS_FORMAT_TEXTURE_NONE ; + support |= 0 != (data.Support1 & (0 + | D3D12_FORMAT_SUPPORT1_TEXTURE3D + ) ) + ? BGFX_CAPS_FORMAT_TEXTURE_3D + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + + support |= 0 != (data.Support1 & (0 + | D3D12_FORMAT_SUPPORT1_TEXTURECUBE + ) ) + ? BGFX_CAPS_FORMAT_TEXTURE_CUBE + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + support |= 0 != (data.Support1 & (0 | D3D12_FORMAT_SUPPORT1_BUFFER | D3D12_FORMAT_SUPPORT1_IA_VERTEX_BUFFER @@ -992,12 +1004,24 @@ namespace bgfx { namespace d3d12 { support |= 0 != (data.Support1 & (0 | D3D12_FORMAT_SUPPORT1_TEXTURE2D - | D3D12_FORMAT_SUPPORT1_TEXTURE3D - | D3D12_FORMAT_SUPPORT1_TEXTURECUBE ) ) ? BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB : BGFX_CAPS_FORMAT_TEXTURE_NONE ; + + support |= 0 != (data.Support1 & (0 + | D3D12_FORMAT_SUPPORT1_TEXTURE3D + ) ) + ? BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + + support |= 0 != (data.Support1 & (0 + | D3D12_FORMAT_SUPPORT1_TEXTURECUBE + ) ) + ? BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; } else { diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index d883afaf..10fe0367 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -599,6 +599,38 @@ namespace bgfx { namespace d3d9 , s_textureFormat[ii].m_fmt ) ) ? BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB : BGFX_CAPS_FORMAT_TEXTURE_NONE; + support |= SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter + , m_deviceType + , adapterFormat + , 0 + , D3DRTYPE_VOLUMETEXTURE + , s_textureFormat[ii].m_fmt + ) ) ? BGFX_CAPS_FORMAT_TEXTURE_3D : BGFX_CAPS_FORMAT_TEXTURE_NONE; + + support |= SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter + , m_deviceType + , adapterFormat + , D3DUSAGE_QUERY_SRGBREAD + , D3DRTYPE_VOLUMETEXTURE + , s_textureFormat[ii].m_fmt + ) ) ? BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB : BGFX_CAPS_FORMAT_TEXTURE_NONE; + + support |= SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter + , m_deviceType + , adapterFormat + , 0 + , D3DRTYPE_CUBETEXTURE + , s_textureFormat[ii].m_fmt + ) ) ? BGFX_CAPS_FORMAT_TEXTURE_CUBE : BGFX_CAPS_FORMAT_TEXTURE_NONE; + + support |= SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter + , m_deviceType + , adapterFormat + , D3DUSAGE_QUERY_SRGBREAD + , D3DRTYPE_CUBETEXTURE + , s_textureFormat[ii].m_fmt + ) ) ? BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB : BGFX_CAPS_FORMAT_TEXTURE_NONE; + support |= SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter , m_deviceType , adapterFormat diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 3d161412..0a684f57 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -1595,11 +1595,15 @@ namespace bgfx { namespace gl uint8_t supported = 0; supported |= s_textureFormat[ii].m_supported ? BGFX_CAPS_FORMAT_TEXTURE_2D + | BGFX_CAPS_FORMAT_TEXTURE_3D + | BGFX_CAPS_FORMAT_TEXTURE_CUBE : BGFX_CAPS_FORMAT_TEXTURE_NONE ; supported |= isTextureFormatValid(TextureFormat::Enum(ii), true) ? BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB + | BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB + | BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB : BGFX_CAPS_FORMAT_TEXTURE_NONE ;