diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index e09caf9bd..3692ab91f 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -801,7 +801,7 @@ namespace bgfx { namespace d3d11 if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) { // D3D11_1.h has ID3DUserDefinedAnnotation - // http://msdn.microsoft.com/en-us/library/windows/desktop/hh446881%28v=vs.85%29.aspx + // https://web.archive.org/web/20190207230424/https://docs.microsoft.com/en-us/windows/desktop/api/d3d11_1/nn-d3d11_1-id3duserdefinedannotation m_d3d9Dll = bx::dlopen("d3d9.dll"); if (NULL != m_d3d9Dll) { @@ -3045,16 +3045,16 @@ namespace bgfx { namespace d3d11 switch (texture.m_type) { case TextureD3D11::Texture2D: - if (1 < texture.m_depth) + if (1 < texture.m_numLayers) { desc.ViewDimension = msaaSample ? D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY : D3D11_SRV_DIMENSION_TEXTURE2DARRAY ; desc.Texture2DArray.MostDetailedMip = _mip; - desc.Texture2DArray.MipLevels = 1; + desc.Texture2DArray.MipLevels = 1; desc.Texture2DArray.FirstArraySlice = 0; - desc.Texture2DArray.ArraySize = texture.m_depth; + desc.Texture2DArray.ArraySize = texture.m_numLayers; } else { @@ -3063,7 +3063,7 @@ namespace bgfx { namespace d3d11 : D3D11_SRV_DIMENSION_TEXTURE2D ; desc.Texture2D.MostDetailedMip = _mip; - desc.Texture2D.MipLevels = 1; + desc.Texture2D.MipLevels = 1; } break; @@ -3354,6 +3354,7 @@ namespace bgfx { namespace d3d11 _clear.m_index[2]*1.0f/255.0f, _clear.m_index[3]*1.0f/255.0f, }; + for (uint32_t ii = 0; ii < numMrt; ++ii) { bx::memCopy(mrtClearColor[ii], rgba, 16); @@ -4088,10 +4089,11 @@ namespace bgfx { namespace d3d11 ); ti.numMips = bx::min(imageContainer.m_numMips-startLod, ti.numMips); - m_flags = _flags; - m_width = ti.width; - m_height = ti.height; - m_depth = ti.depth; + m_flags = _flags; + m_width = ti.width; + m_height = ti.height; + m_depth = ti.depth; + m_numLayers = ti.numLayers; m_requestedFormat = uint8_t(imageContainer.m_format); m_textureFormat = uint8_t(getViableTextureFormat(imageContainer) ); @@ -4758,11 +4760,11 @@ namespace bgfx { namespace d3d11 case TextureD3D11::Texture2D: if (1 < msaa.Count) { - if (1 < texture.m_depth) + if (1 < texture.m_numLayers) { desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY; desc.Texture2DMSArray.FirstArraySlice = at.layer; - desc.Texture2DMSArray.ArraySize = 1; + desc.Texture2DMSArray.ArraySize = 1; } else { @@ -4771,12 +4773,12 @@ namespace bgfx { namespace d3d11 } else { - if (1 < texture.m_depth) + if (1 < texture.m_numLayers) { desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY; desc.Texture2DArray.FirstArraySlice = at.layer; - desc.Texture2DArray.ArraySize = 1; - desc.Texture2DArray.MipSlice = at.mip; + desc.Texture2DArray.ArraySize = 1; + desc.Texture2DArray.MipSlice = at.mip; } else { @@ -4806,6 +4808,7 @@ namespace bgfx { namespace d3d11 desc.Texture2DArray.FirstArraySlice = at.layer; desc.Texture2DArray.MipSlice = at.mip; } + DX_CHECK(s_renderD3D11->m_device->CreateRenderTargetView(texture.m_ptr, &desc, &m_rtv[m_num]) ); break; @@ -4814,6 +4817,7 @@ namespace bgfx { namespace d3d11 desc.Texture3D.MipSlice = at.mip; desc.Texture3D.WSize = 1; desc.Texture3D.FirstWSlice = at.layer; + DX_CHECK(s_renderD3D11->m_device->CreateRenderTargetView(texture.m_ptr, &desc, &m_rtv[m_num]) ); break; } diff --git a/src/renderer_d3d11.h b/src/renderer_d3d11.h index df694c5a6..4ea6c047d 100644 --- a/src/renderer_d3d11.h +++ b/src/renderer_d3d11.h @@ -294,6 +294,7 @@ namespace bgfx { namespace d3d11 uint32_t m_width; uint32_t m_height; uint32_t m_depth; + uint32_t m_numLayers; uint8_t m_type; uint8_t m_requestedFormat; uint8_t m_textureFormat; diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index 863b8025e..deaf2a8dc 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -4594,10 +4594,11 @@ namespace bgfx { namespace d3d12 ); ti.numMips = bx::min(imageContainer.m_numMips-startLod, ti.numMips); - m_flags = _flags; - m_width = ti.width; - m_height = ti.height; - m_depth = ti.depth; + m_flags = _flags; + m_width = ti.width; + m_height = ti.height; + m_depth = ti.depth; + m_numLayers = ti.numLayers; m_requestedFormat = uint8_t(imageContainer.m_format); m_textureFormat = uint8_t(getViableTextureFormat(imageContainer) ); const bool convert = m_textureFormat != m_requestedFormat; @@ -4798,49 +4799,31 @@ namespace bgfx { namespace d3d12 switch (m_type) { case Texture2D: - case TextureCube: resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; - if (imageContainer.m_cubeMap) + + if (1 < ti.numLayers) { - if (1 < ti.numLayers) - { - m_srvd.ViewDimension = D3D12_SRV_DIMENSION_TEXTURECUBEARRAY; - m_srvd.TextureCubeArray.MostDetailedMip = 0; - m_srvd.TextureCubeArray.MipLevels = ti.numMips; - m_srvd.TextureCubeArray.ResourceMinLODClamp = 0.0f; - m_srvd.TextureCubeArray.NumCubes = ti.numLayers; - } - else - { - m_srvd.ViewDimension = D3D12_SRV_DIMENSION_TEXTURECUBE; - m_srvd.TextureCube.MostDetailedMip = 0; - m_srvd.TextureCube.MipLevels = ti.numMips; - m_srvd.TextureCube.ResourceMinLODClamp = 0.0f; - } + m_srvd.ViewDimension = 1 < msaa.Count + ? D3D12_SRV_DIMENSION_TEXTURE2DMSARRAY + : D3D12_SRV_DIMENSION_TEXTURE2DARRAY + ; + m_srvd.Texture2DArray.MostDetailedMip = 0; + m_srvd.Texture2DArray.MipLevels = ti.numMips; + m_srvd.Texture2DArray.FirstArraySlice = 0; + m_srvd.Texture2DArray.ArraySize = ti.numLayers; + m_srvd.Texture2DArray.PlaneSlice = 0; + m_srvd.Texture2DArray.ResourceMinLODClamp = 0.0f; } else { - if (1 < ti.numLayers) - { - m_srvd.ViewDimension = 1 < msaa.Count - ? D3D12_SRV_DIMENSION_TEXTURE2DMSARRAY - : D3D12_SRV_DIMENSION_TEXTURE2DARRAY - ; - m_srvd.Texture2DArray.MostDetailedMip = 0; - m_srvd.Texture2DArray.MipLevels = ti.numMips; - m_srvd.Texture2DArray.ResourceMinLODClamp = 0.0f; - m_srvd.Texture2DArray.ArraySize = ti.numLayers; - } - else - { - m_srvd.ViewDimension = 1 < msaa.Count - ? D3D12_SRV_DIMENSION_TEXTURE2DMS - : D3D12_SRV_DIMENSION_TEXTURE2D - ; - m_srvd.Texture2D.MostDetailedMip = 0; - m_srvd.Texture2D.MipLevels = ti.numMips; - m_srvd.Texture2D.ResourceMinLODClamp = 0.0f; - } + m_srvd.ViewDimension = 1 < msaa.Count + ? D3D12_SRV_DIMENSION_TEXTURE2DMS + : D3D12_SRV_DIMENSION_TEXTURE2D + ; + m_srvd.Texture2D.MostDetailedMip = 0; + m_srvd.Texture2D.MipLevels = ti.numMips; + m_srvd.Texture2D.PlaneSlice = 0; + m_srvd.Texture2D.ResourceMinLODClamp = 0.0f; } if (1 < ti.numLayers) @@ -4848,8 +4831,8 @@ namespace bgfx { namespace d3d12 m_uavd.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2DARRAY; m_uavd.Texture2DArray.MipSlice = 0; m_uavd.Texture2DArray.FirstArraySlice = 0; - m_uavd.Texture2DArray.PlaneSlice = 0; m_uavd.Texture2DArray.ArraySize = ti.numLayers; + m_uavd.Texture2DArray.PlaneSlice = 0; } else { @@ -4857,14 +4840,6 @@ namespace bgfx { namespace d3d12 m_uavd.Texture2D.MipSlice = 0; m_uavd.Texture2D.PlaneSlice = 0; } - - if (TextureCube == m_type) - { - m_uavd.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2DARRAY; - m_uavd.Texture2DArray.MipSlice = 0; - m_uavd.Texture2DArray.ArraySize = 6; - } - break; case Texture3D: @@ -4880,8 +4855,37 @@ namespace bgfx { namespace d3d12 m_uavd.Texture3D.FirstWSlice = 0; m_uavd.Texture3D.WSize = m_depth; break; + + case TextureCube: + resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; + + if (1 < ti.numLayers) + { + m_srvd.ViewDimension = D3D12_SRV_DIMENSION_TEXTURECUBEARRAY; + m_srvd.TextureCubeArray.MostDetailedMip = 0; + m_srvd.TextureCubeArray.MipLevels = ti.numMips; + m_srvd.TextureCubeArray.ResourceMinLODClamp = 0.0f; + m_srvd.TextureCubeArray.NumCubes = ti.numLayers; + } + else + { + m_srvd.ViewDimension = D3D12_SRV_DIMENSION_TEXTURECUBE; + m_srvd.TextureCube.MostDetailedMip = 0; + m_srvd.TextureCube.MipLevels = ti.numMips; + m_srvd.TextureCube.ResourceMinLODClamp = 0.0f; + } + + m_uavd.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2DARRAY; + m_uavd.Texture2DArray.MipSlice = 0; + m_uavd.Texture2DArray.FirstArraySlice = 0; + m_uavd.Texture2DArray.ArraySize = 6; + m_uavd.Texture2DArray.PlaneSlice = 0; + break; } +{HRESULT hr = device->GetDeviceRemovedReason(); + BX_CHECK(SUCCEEDED(hr), "%x %x", hr, DXGI_ERROR_INVALID_CALL);} + m_ptr = createCommittedResource(device, HeapProperty::Texture, &resourceDesc, clearValue, renderTarget); if (directAccess) @@ -4918,6 +4922,9 @@ namespace bgfx { namespace d3d12 setState(commandList, state); } +{HRESULT hr = device->GetDeviceRemovedReason(); + BX_CHECK(SUCCEEDED(hr), "%x %x", hr, DXGI_ERROR_INVALID_CALL);} + if (0 != kk) { kk = 0; @@ -5206,9 +5213,19 @@ namespace bgfx { namespace d3d12 // } // else { - desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D; - desc.Texture2D.MipSlice = at.mip; - desc.Texture2D.PlaneSlice = 0; + if (1 < texture.m_numLayers) + { + desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DARRAY; + desc.Texture2DArray.FirstArraySlice = at.layer; + desc.Texture2DArray.ArraySize = 1; + desc.Texture2DArray.MipSlice = at.mip; + } + else + { + desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D; + desc.Texture2D.MipSlice = at.mip; + desc.Texture2D.PlaneSlice = 0; + } } break; diff --git a/src/renderer_d3d12.h b/src/renderer_d3d12.h index a05fe21d6..dbd04d167 100644 --- a/src/renderer_d3d12.h +++ b/src/renderer_d3d12.h @@ -326,6 +326,7 @@ namespace bgfx { namespace d3d12 uint32_t m_width; uint32_t m_height; uint32_t m_depth; + uint32_t m_numLayers; uint16_t m_samplerIdx; uint8_t m_type; uint8_t m_requestedFormat; diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index 816ad7fa1..6b3b5b83e 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -373,11 +373,12 @@ namespace bgfx { namespace d3d9 ; } - static inline bool useD3D9Pitch(bimg::TextureFormat::Enum _format) + inline bool useD3D9Pitch(bimg::TextureFormat::Enum _format) { - // For BC4 and B5 in DX9 LockRect returns wrong number of - // bytes. If actual mip size is used it causes memory corruption. - // http://www.aras-p.info/texts/D3D9GPUHacks.html#3dc + // Reference(s): + // - For BC4 and B5 in DX9 LockRect returns wrong number of + // bytes. If actual mip size is used it causes memory corruption. + // https://web.archive.org/web/20190207230133/http://www.aras-p.info/texts/D3D9GPUHacks.html return true && _format != bimg::TextureFormat::BC4 && _format != bimg::TextureFormat::BC5 @@ -448,7 +449,8 @@ namespace bgfx { namespace d3d9 D3DFORMAT adapterFormat = D3DFMT_X8R8G8B8; - // http://msdn.microsoft.com/en-us/library/windows/desktop/bb172588%28v=vs.85%29.aspx + // Reference(s): + // - https://web.archive.org/web/20190207230309/https://docs.microsoft.com/en-us/windows/desktop/direct3d9/d3dpresent-parameters bx::memSet(&m_params, 0, sizeof(m_params) ); m_params.BackBufferWidth = _init.resolution.width; m_params.BackBufferHeight = _init.resolution.height; diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 71ec3ab62..4224403fa 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -4770,6 +4770,8 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); return; } + m_numLayers = ti.numLayers; + target = isCubeMap() ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : m_target @@ -5945,7 +5947,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); } else if (Access::Write == at.access) { - if (1 < texture.m_depth + if (1 < texture.m_numLayers && !texture.isCubeMap()) { GL_CHECK(glFramebufferTextureLayer(GL_FRAMEBUFFER diff --git a/src/renderer_gl.h b/src/renderer_gl.h index 8dca8e895..455e6a343 100644 --- a/src/renderer_gl.h +++ b/src/renderer_gl.h @@ -635,7 +635,7 @@ typedef uint64_t GLuint64; # define GL_RENDERBUFFER_FREE_MEMORY_ATI 0x87FD #endif // GL_RENDERBUFFER_FREE_MEMORY_ATI -// http://developer.download.nvidia.com/opengl/specs/GL_NVX_gpu_memory_info.txt +// https://web.archive.org/web/20190207230448/http://developer.download.nvidia.com/opengl/specs/GL_NVX_gpu_memory_info.txt #ifndef GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX # define GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX 0x9047 #endif // GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX @@ -1273,6 +1273,7 @@ namespace bgfx { namespace gl uint32_t m_width; uint32_t m_height; uint32_t m_depth; + uint32_t m_numLayers; uint8_t m_numMips; uint8_t m_requestedFormat; uint8_t m_textureFormat;