浏览代码

D3D1x: Fixed update surface size when texture is transcoded.

Branimir Karadžić 4 年之前
父节点
当前提交
67d1cce8f8
共有 2 个文件被更改,包括 16 次插入10 次删除
  1. 5 1
      src/renderer_d3d11.cpp
  2. 11 9
      src/renderer_d3d12.cpp

+ 5 - 1
src/renderer_d3d11.cpp

@@ -4751,9 +4751,10 @@ namespace bgfx { namespace d3d11
 		uint32_t rectpitch  = _rect.m_width*bpp/8;
 		uint32_t rectpitch  = _rect.m_width*bpp/8;
 		if (bimg::isCompressed(bimg::TextureFormat::Enum(m_textureFormat)))
 		if (bimg::isCompressed(bimg::TextureFormat::Enum(m_textureFormat)))
 		{
 		{
-			const bimg::ImageBlockInfo& blockInfo = bimg::getBlockInfo(bimg::TextureFormat::Enum(m_textureFormat));
+			const bimg::ImageBlockInfo& blockInfo = bimg::getBlockInfo(bimg::TextureFormat::Enum(m_textureFormat) );
 			rectpitch = (_rect.m_width / blockInfo.blockWidth)*blockInfo.blockSize;
 			rectpitch = (_rect.m_width / blockInfo.blockWidth)*blockInfo.blockSize;
 		}
 		}
+
 		const uint32_t srcpitch   = UINT16_MAX == _pitch ? rectpitch : _pitch;
 		const uint32_t srcpitch   = UINT16_MAX == _pitch ? rectpitch : _pitch;
 		const uint32_t slicepitch = rectpitch*_rect.m_height;
 		const uint32_t slicepitch = rectpitch*_rect.m_height;
 
 
@@ -4767,6 +4768,9 @@ namespace bgfx { namespace d3d11
 			temp = (uint8_t*)BX_ALLOC(g_allocator, slicepitch);
 			temp = (uint8_t*)BX_ALLOC(g_allocator, slicepitch);
 			bimg::imageDecodeToBgra8(g_allocator, temp, data, _rect.m_width, _rect.m_height, srcpitch, bimg::TextureFormat::Enum(m_requestedFormat) );
 			bimg::imageDecodeToBgra8(g_allocator, temp, data, _rect.m_width, _rect.m_height, srcpitch, bimg::TextureFormat::Enum(m_requestedFormat) );
 			data = temp;
 			data = temp;
+
+			box.right  = bx::max(1u, m_width  >> _mip);
+			box.bottom = bx::max(1u, m_height >> _mip);
 		}
 		}
 
 
 		deviceCtx->UpdateSubresource(
 		deviceCtx->UpdateSubresource(

+ 11 - 9
src/renderer_d3d12.cpp

@@ -5105,6 +5105,14 @@ namespace bgfx { namespace d3d12
 
 
 		const bool convert = m_textureFormat != m_requestedFormat;
 		const bool convert = m_textureFormat != m_requestedFormat;
 
 
+		D3D12_BOX box;
+		box.left   = 0;
+		box.top    = 0;
+		box.right  = box.left + _rect.m_width;
+		box.bottom = box.top  + _rect.m_height;
+		box.front  = _z;
+		box.back   = _z + _depth;
+
 		uint8_t* srcData = _mem->data;
 		uint8_t* srcData = _mem->data;
 		uint8_t* temp = NULL;
 		uint8_t* temp = NULL;
 
 
@@ -5113,8 +5121,10 @@ namespace bgfx { namespace d3d12
 			temp = (uint8_t*)BX_ALLOC(g_allocator, slicepitch);
 			temp = (uint8_t*)BX_ALLOC(g_allocator, slicepitch);
 			bimg::imageDecodeToBgra8(g_allocator, temp, srcData, _rect.m_width, _rect.m_height, srcpitch, bimg::TextureFormat::Enum(m_requestedFormat));
 			bimg::imageDecodeToBgra8(g_allocator, temp, srcData, _rect.m_width, _rect.m_height, srcpitch, bimg::TextureFormat::Enum(m_requestedFormat));
 			srcData = temp;
 			srcData = temp;
-		}
 
 
+			box.right = bx::max(1u, m_width >> _mip);
+			box.bottom = bx::max(1u, m_height >> _mip);
+		}
 
 
 		D3D12_RESOURCE_DESC desc = getResourceDesc(m_ptr);
 		D3D12_RESOURCE_DESC desc = getResourceDesc(m_ptr);
 
 
@@ -5155,14 +5165,6 @@ namespace bgfx { namespace d3d12
 		D3D12_RANGE writeRange = { 0, numRows*rowPitch };
 		D3D12_RANGE writeRange = { 0, numRows*rowPitch };
 		staging->Unmap(0, &writeRange);
 		staging->Unmap(0, &writeRange);
 
 
-		D3D12_BOX box;
-		box.left   = 0;
-		box.top    = 0;
-		box.right  = box.left + _rect.m_width;
-		box.bottom = box.top  + _rect.m_height;
-		box.front  = _z;
-		box.back   = _z+_depth;
-
 		D3D12_TEXTURE_COPY_LOCATION dst = { m_ptr,   D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, {        } };
 		D3D12_TEXTURE_COPY_LOCATION dst = { m_ptr,   D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, {        } };
 		dst.SubresourceIndex = subres;
 		dst.SubresourceIndex = subres;
 		D3D12_TEXTURE_COPY_LOCATION src = { staging, D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT,  { layout } };
 		D3D12_TEXTURE_COPY_LOCATION src = { staging, D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT,  { layout } };