From 7423257f57bf125273b37413c8d6fe76d1283e2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sun, 17 Apr 2016 23:00:36 -0700 Subject: [PATCH] Added BGFX_TEXTURE_MSAA_SAMPLE flag. --- include/bgfx/bgfxdefines.h | 3 ++- src/renderer_d3d11.cpp | 27 +++++++++++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/include/bgfx/bgfxdefines.h b/include/bgfx/bgfxdefines.h index 6dff557b5..69fcea60a 100644 --- a/include/bgfx/bgfxdefines.h +++ b/include/bgfx/bgfxdefines.h @@ -6,7 +6,7 @@ #ifndef BGFX_DEFINES_H_HEADER_GUARD #define BGFX_DEFINES_H_HEADER_GUARD -#define BGFX_API_VERSION UINT32_C(13) +#define BGFX_API_VERSION UINT32_C(14) /// #define BGFX_STATE_RGB_WRITE UINT64_C(0x0000000000000001) //!< Enable RGB write. @@ -296,6 +296,7 @@ #define BGFX_TEXTURE_MIP_POINT UINT32_C(0x00000400) //!< #define BGFX_TEXTURE_MIP_SHIFT 10 //!< #define BGFX_TEXTURE_MIP_MASK UINT32_C(0x00000400) //!< +#define BGFX_TEXTURE_MSAA_SAMPLE UINT32_C(0x00000800) //!< #define BGFX_TEXTURE_RT UINT32_C(0x00001000) //!< #define BGFX_TEXTURE_RT_MSAA_X2 UINT32_C(0x00002000) //!< #define BGFX_TEXTURE_RT_MSAA_X4 UINT32_C(0x00003000) //!< diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index c08631c7e..ef136f500 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -2410,7 +2410,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); } #if !BX_PLATFORM_WINDOWS - HRESULT hr; + HRESULT hr = S_OK; if (g_platformData.ndt == 0) { hr = m_factory->CreateSwapChainForCoreWindow(m_device @@ -3078,14 +3078,20 @@ BX_PRAGMA_DIAGNOSTIC_POP(); ID3D11ShaderResourceView* srv; if (NULL == ptr) { - TextureD3D11& texture = m_textures[_handle.idx]; + const TextureD3D11& texture = m_textures[_handle.idx]; + const bool msaaSample = 0 != (texture.m_flags&BGFX_TEXTURE_MSAA_SAMPLE); + const uint32_t msaaQuality = bx::uint32_satsub( (texture.m_flags&BGFX_TEXTURE_RT_MSAA_MASK)>>BGFX_TEXTURE_RT_MSAA_SHIFT, 1); + const DXGI_SAMPLE_DESC& msaa = s_msaa[msaaQuality]; D3D11_SHADER_RESOURCE_VIEW_DESC desc; desc.Format = s_textureFormat[texture.m_textureFormat].m_fmtSrv; switch (texture.m_type) { case TextureD3D11::Texture2D: - desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + desc.ViewDimension = 1 < msaa.Count && msaaSample + ? D3D11_SRV_DIMENSION_TEXTURE2DMS + : D3D11_SRV_DIMENSION_TEXTURE2D + ; desc.Texture2D.MostDetailedMip = _mip; desc.Texture2D.MipLevels = 1; break; @@ -4327,6 +4333,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); const bool srgb = 0 != (m_flags&BGFX_TEXTURE_SRGB) || imageContainer.m_srgb; const bool blit = 0 != (m_flags&BGFX_TEXTURE_BLIT_DST); const bool readBack = 0 != (m_flags&BGFX_TEXTURE_READ_BACK); + const bool msaaSample = 0 != (m_flags&BGFX_TEXTURE_MSAA_SAMPLE); const uint32_t msaaQuality = bx::uint32_satsub( (m_flags&BGFX_TEXTURE_RT_MSAA_MASK)>>BGFX_TEXTURE_RT_MSAA_SHIFT, 1); const DXGI_SAMPLE_DESC& msaa = s_msaa[msaaQuality]; @@ -4403,8 +4410,16 @@ BX_PRAGMA_DIAGNOSTIC_POP(); { desc.ArraySize = 1; desc.MiscFlags = 0; - srvd.ViewDimension = 1 < msaa.Count ? D3D11_SRV_DIMENSION_TEXTURE2DMS : D3D11_SRV_DIMENSION_TEXTURE2D; - srvd.Texture2D.MipLevels = numMips; + if (1 < msaa.Count + && msaaSample) + { + srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMS; + } + else + { + srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + srvd.Texture2D.MipLevels = numMips; + } } DX_CHECK(s_renderD3D11->m_device->CreateTexture2D(&desc, kk == 0 ? NULL : srd, &m_texture2d) ); @@ -4678,7 +4693,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); } } - const uint32_t msaaQuality = bx::uint32_satsub( (texture.m_flags&BGFX_TEXTURE_RT_MSAA_MASK)>>BGFX_TEXTURE_RT_MSAA_SHIFT, 1); + const uint32_t msaaQuality = bx::uint32_satsub( (texture.m_flags&BGFX_TEXTURE_RT_MSAA_MASK)>>BGFX_TEXTURE_RT_MSAA_SHIFT, 1); const DXGI_SAMPLE_DESC& msaa = s_msaa[msaaQuality]; if (isDepth( (TextureFormat::Enum)texture.m_textureFormat) )