mip levels at 0 means full mip chain

When a resource set the description MipLevels to 0, d3d generate a full
mip chain, we have to compute the count to allocate the proper amount
of subresource states.
This commit is contained in:
galop1n
2016-08-14 18:07:13 -07:00
committed by baldurk
parent f869d6d91b
commit 9c2a6ec77f
+61 -2
View File
@@ -45,6 +45,65 @@ enum D3D12ComponentMapping
{
};
UINT GetResourceNumMipLevels(const D3D12_RESOURCE_DESC *desc)
{
switch(desc->Dimension)
{
default:
case D3D12_RESOURCE_DIMENSION_UNKNOWN:
RDCERR("Unexpected resource dimension! %d", desc->Dimension);
break;
case D3D12_RESOURCE_DIMENSION_BUFFER: return 1;
case D3D12_RESOURCE_DIMENSION_TEXTURE1D:
{
if(desc->MipLevels)
return desc->MipLevels;
UINT w = RDCMAX(1U, UINT(desc->Width));
UINT count = 1;
while(w > 1)
{
++count;
w = RDCMAX(1U, w >> 1U);
}
return count;
}
case D3D12_RESOURCE_DIMENSION_TEXTURE2D:
{
if(desc->MipLevels)
return desc->MipLevels;
UINT w = RDCMAX(1U, UINT(desc->Width));
UINT h = RDCMAX(1U, desc->Height);
UINT count = 1;
while(w > 1 || h > 1)
{
++count;
w = RDCMAX(1U, w >> 1U);
h = RDCMAX(1U, h >> 1U);
}
return count;
}
case D3D12_RESOURCE_DIMENSION_TEXTURE3D:
{
if(desc->MipLevels)
return desc->MipLevels;
UINT w = RDCMAX(1U, UINT(desc->Width));
UINT h = RDCMAX(1U, desc->Height);
UINT d = RDCMAX(1U, UINT(desc->DepthOrArraySize));
UINT count = 1;
while(w > 1 || h > 1 || d > 1)
{
++count;
w = RDCMAX(1U, w >> 1U);
h = RDCMAX(1U, h >> 1U);
d = RDCMAX(1U, d >> 1U);
}
return count;
}
}
return 1;
}
UINT GetNumSubresources(const D3D12_RESOURCE_DESC *desc)
{
switch(desc->Dimension)
@@ -56,8 +115,8 @@ UINT GetNumSubresources(const D3D12_RESOURCE_DESC *desc)
case D3D12_RESOURCE_DIMENSION_BUFFER: return 1;
case D3D12_RESOURCE_DIMENSION_TEXTURE1D:
case D3D12_RESOURCE_DIMENSION_TEXTURE2D:
return RDCMAX((UINT16)1, desc->DepthOrArraySize) * RDCMAX((UINT16)1, desc->MipLevels);
case D3D12_RESOURCE_DIMENSION_TEXTURE3D: return RDCMAX((UINT16)1, desc->MipLevels);
return RDCMAX((UINT16)1, desc->DepthOrArraySize) * GetResourceNumMipLevels(desc);
case D3D12_RESOURCE_DIMENSION_TEXTURE3D: return GetResourceNumMipLevels(desc);
}
return 1;