summaryrefslogtreecommitdiffstats
path: root/tools/gfx/d3d12/render-d3d12.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/gfx/d3d12/render-d3d12.cpp')
-rw-r--r--tools/gfx/d3d12/render-d3d12.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/tools/gfx/d3d12/render-d3d12.cpp b/tools/gfx/d3d12/render-d3d12.cpp
index 8029826a3..aa945fd85 100644
--- a/tools/gfx/d3d12/render-d3d12.cpp
+++ b/tools/gfx/d3d12/render-d3d12.cpp
@@ -4711,7 +4711,12 @@ Result D3D12Device::createTextureResource(const ITextureResource::Desc& descIn,
const D3D12_PLACED_SUBRESOURCE_FOOTPRINT& layout = layouts[j];
const D3D12_SUBRESOURCE_FOOTPRINT& footprint = layout.Footprint;
- const TextureResource::Size mipSize = calcMipSize(srcDesc.size, j);
+ TextureResource::Size mipSize = calcMipSize(srcDesc.size, j);
+ if (gfxIsCompressedFormat(descIn.format))
+ {
+ mipSize.width = int(D3DUtil::calcAligned(mipSize.width, 4));
+ mipSize.height = int(D3DUtil::calcAligned(mipSize.height, 4));
+ }
assert(footprint.Width == mipSize.width && footprint.Height == mipSize.height && footprint.Depth == mipSize.depth);
@@ -4733,7 +4738,8 @@ Result D3D12Device::createTextureResource(const ITextureResource::Desc& descIn,
//
const uint8_t* srcRow = srcLayer;
uint8_t* dstRow = dstLayer;
- for (int k = 0; k < mipSize.height; ++k)
+ int j = gfxIsCompressedFormat(descIn.format) ? 4 : 1; // BC compressed formats are organized into 4x4 blocks
+ for (int k = 0; k < mipSize.height; k += j)
{
::memcpy(dstRow, srcRow, (size_t)mipRowSize);
@@ -5022,7 +5028,8 @@ Result D3D12Device::createTextureView(ITextureResource* texture, IResourceView::
// Need to construct the D3D12_SHADER_RESOURCE_VIEW_DESC because otherwise TextureCube is not accessed
// appropriately (rather than just passing nullptr to CreateShaderResourceView)
const D3D12_RESOURCE_DESC resourceDesc = resourceImpl->m_resource.getResource()->GetDesc();
- const DXGI_FORMAT pixelFormat = resourceDesc.Format;
+ const DXGI_FORMAT pixelFormat =
+ gfxIsTypelessFormat(texture->getDesc()->format) ? D3DUtil::getMapFormat(desc.format) : resourceDesc.Format;
D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc;
_initSrvDesc(resourceImpl->getType(), *resourceImpl->getDesc(), resourceDesc, pixelFormat, srvDesc);
@@ -5070,7 +5077,9 @@ Result D3D12Device::createBufferView(IBufferResource* buffer, IResourceView::Des
}
else
{
- uavDesc.Buffer.NumElements = UINT(resourceDesc.sizeInBytes / gfxGetFormatSize(desc.format));
+ FormatInfo sizeInfo;
+ gfxGetFormatInfo(desc.format, &sizeInfo);
+ uavDesc.Buffer.NumElements = UINT(resourceDesc.sizeInBytes / (sizeInfo.blockSizeInBytes / sizeInfo.pixelsPerBlock));
}
@@ -5104,7 +5113,9 @@ Result D3D12Device::createBufferView(IBufferResource* buffer, IResourceView::Des
}
else
{
- srvDesc.Buffer.NumElements = UINT(resourceDesc.sizeInBytes / gfxGetFormatSize(desc.format));
+ FormatInfo sizeInfo;
+ gfxGetFormatInfo(desc.format, &sizeInfo);
+ srvDesc.Buffer.NumElements = UINT(resourceDesc.sizeInBytes / (sizeInfo.blockSizeInBytes / sizeInfo.pixelsPerBlock));
}
SLANG_RETURN_ON_FAIL(m_cpuViewHeap->allocate(&viewImpl->m_descriptor));