Skip to content

Commit c6c0cc4

Browse files
committed
[D3D] Fixed default UAV of 3D textures.
The default UAV for RWTexture3D resources must use the texture depth, not the array size. This adds `GetDepthOrArraySize()` to both D3D11Texture and D3D12Texture classes to pick the right parameter for 3D textures and all other texture types.
1 parent f2ea13b commit c6c0cc4

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

sources/Renderer/Direct3D11/Texture/D3D11Texture.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ void D3D11Texture::CreateDefaultUAV(ID3D11Device* device)
10501050
if (hasTypelessFormat || hasDepthStencilFormat)
10511051
{
10521052
/* Create UAV with parameters for entire texture resource */
1053-
CreateSubresourceUAV(device, uav_.ReleaseAndGetAddressOf(), GetType(), DXTypes::ToDXGIFormat(GetFormat()), 0, 0, GetNumArrayLayers());
1053+
CreateSubresourceUAV(device, uav_.ReleaseAndGetAddressOf(), GetType(), DXTypes::ToDXGIFormat(GetFormat()), 0, 0, GetDepthOrArraySize());
10541054
}
10551055
else
10561056
{
@@ -1067,6 +1067,11 @@ void D3D11Texture::SetResourceParams(DXGI_FORMAT format, const Extent3D& extent,
10671067
numArrayLayers_ = arraySize;
10681068
}
10691069

1070+
UINT D3D11Texture::GetDepthOrArraySize() const
1071+
{
1072+
return (GetType() == TextureType::Texture3D ? GetMipExtent(0).depth : numArrayLayers_);
1073+
}
1074+
10701075

10711076
} // /namespace LLGL
10721077

sources/Renderer/Direct3D11/Texture/D3D11Texture.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ class D3D11Texture final : public Texture
185185

186186
void SetResourceParams(DXGI_FORMAT format, const Extent3D& extent, UINT mipLevels, UINT arraySize);
187187

188+
UINT GetDepthOrArraySize() const;
189+
188190
private:
189191

190192
ComPtr<ID3D11Resource> native_;

sources/Renderer/Direct3D12/Texture/D3D12Texture.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ void D3D12Texture::CreateUnorderedAccessView(ID3D12Device* device, D3D12_CPU_DES
549549
device,
550550
D3D12Types::MapUavDimension(GetType()),
551551
format_,
552-
TextureSubresource{ 0, numArrayLayers_, 0, 1 },
552+
TextureSubresource{ 0, GetDepthOrArraySize(), 0, 1 },
553553
cpuDescHandle
554554
);
555555
}
@@ -904,6 +904,11 @@ void D3D12Texture::CreateMipDescHeap(ID3D12Device* device)
904904
}
905905
}
906906

907+
UINT D3D12Texture::GetDepthOrArraySize() const
908+
{
909+
return (GetType() == TextureType::Texture3D ? extent_.depth : numArrayLayers_);
910+
}
911+
907912

908913
} // /namespace LLGL
909914

sources/Renderer/Direct3D12/Texture/D3D12Texture.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ class D3D12Texture final : public Texture
173173

174174
void CreateMipDescHeap(ID3D12Device* device);
175175

176+
UINT GetDepthOrArraySize() const;
177+
176178
private:
177179

178180
D3D12Resource resource_;

0 commit comments

Comments
 (0)