Fix RHI D3D12 RTV creation and GetFormat bug
1. Add ALLOW_RENDER_TARGET flag for color textures in CreateTexture - This was the root cause of 5 failing RTV-related tests - Without this flag, creating RTV caused device removal 2. Add FromD3D12() reverse conversion for Format enum - GetFormat() was incorrectly casting DXGI_FORMAT to Format - DXGI_FORMAT_R8G8B8A8_UNORM=28 but Format::R8G8B8A8_UNorm=3 - Added FromD3D12() to properly convert back 3. Update RHITestFixture to pre-create CommandQueue and Fence - Prevents potential timing issues with GPU synchronization 4. Update RHITestFixture tests to pass correct format in ResourceViewDesc - Previously passed empty desc.format=0 which caused issues All 234 RHI unit tests now pass (117 D3D12 + 117 OpenGL)
This commit is contained in:
@@ -158,6 +158,32 @@ inline DXGI_FORMAT ToD3D12(Format format) {
|
||||
return DXGI_FORMAT_UNKNOWN;
|
||||
}
|
||||
|
||||
inline Format FromD3D12(DXGI_FORMAT format) {
|
||||
switch (format) {
|
||||
case DXGI_FORMAT_UNKNOWN: return Format::Unknown;
|
||||
case DXGI_FORMAT_R8_UNORM: return Format::R8_UNorm;
|
||||
case DXGI_FORMAT_R8G8_UNORM: return Format::R8G8_UNorm;
|
||||
case DXGI_FORMAT_R8G8B8A8_UNORM: return Format::R8G8B8A8_UNorm;
|
||||
case DXGI_FORMAT_R16G16B16A16_FLOAT: return Format::R16G16B16A16_Float;
|
||||
case DXGI_FORMAT_R32G32B32A32_FLOAT: return Format::R32G32B32A32_Float;
|
||||
case DXGI_FORMAT_R16_FLOAT: return Format::R16_Float;
|
||||
case DXGI_FORMAT_R32_FLOAT: return Format::R32_Float;
|
||||
case DXGI_FORMAT_D16_UNORM: return Format::D16_UNorm;
|
||||
case DXGI_FORMAT_D24_UNORM_S8_UINT: return Format::D24_UNorm_S8_UInt;
|
||||
case DXGI_FORMAT_D32_FLOAT: return Format::D32_Float;
|
||||
case DXGI_FORMAT_BC1_UNORM: return Format::BC1_UNorm;
|
||||
case DXGI_FORMAT_BC2_UNORM: return Format::BC2_UNorm;
|
||||
case DXGI_FORMAT_BC3_UNORM: return Format::BC3_UNorm;
|
||||
case DXGI_FORMAT_BC4_UNORM: return Format::BC4_UNorm;
|
||||
case DXGI_FORMAT_BC5_UNORM: return Format::BC5_UNorm;
|
||||
case DXGI_FORMAT_BC6H_UF16: return Format::BC6H_UF16;
|
||||
case DXGI_FORMAT_BC7_UNORM: return Format::BC7_UNorm;
|
||||
case DXGI_FORMAT_R32G32B32A32_UINT: return Format::R32G32B32A32_UInt;
|
||||
case DXGI_FORMAT_R32_UINT: return Format::R32_UInt;
|
||||
}
|
||||
return Format::Unknown;
|
||||
}
|
||||
|
||||
inline D3D12_RESOURCE_STATES ToD3D12(ResourceStates state) {
|
||||
switch (state) {
|
||||
case ResourceStates::Common: return D3D12_RESOURCE_STATE_COMMON;
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
void SetName(const std::string& name) override { m_name = name; }
|
||||
|
||||
uint32_t GetArraySize() const { return GetDesc().DepthOrArraySize; }
|
||||
Format GetFormat() const override { return static_cast<Format>(GetDesc().Format); }
|
||||
Format GetFormat() const override { return FromD3D12(GetDesc().Format); }
|
||||
TextureType GetTextureType() const override {
|
||||
switch (GetDesc().Dimension) {
|
||||
case D3D12_RESOURCE_DIMENSION_TEXTURE1D: return TextureType::Texture1D;
|
||||
|
||||
@@ -297,12 +297,14 @@ RHITexture* D3D12Device::CreateTexture(const TextureDesc& desc) {
|
||||
if (format == Format::D24_UNorm_S8_UInt || format == Format::D32_Float ||
|
||||
format == Format::D16_UNorm) {
|
||||
d3d12Desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
|
||||
} else if (d3d12Desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE2D && desc.width > 0 && desc.height > 0) {
|
||||
d3d12Desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
|
||||
}
|
||||
|
||||
d3d12Desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
|
||||
{
|
||||
FILE* f = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
|
||||
if (f) { fprintf(f, "[CreateTexture] Calling Initialize, device=%p, format=%d\n", m_device.Get(), (int)d3d12Desc.Format); fclose(f); }
|
||||
if (f) { fprintf(f, "[CreateTexture] Calling Initialize, device=%p, format=%d, flags=0x%X\n", m_device.Get(), (int)d3d12Desc.Format, d3d12Desc.Flags); fclose(f); }
|
||||
}
|
||||
if (texture->Initialize(m_device.Get(), d3d12Desc)) {
|
||||
FILE* f = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
|
||||
|
||||
Reference in New Issue
Block a user