Fix RHI texture binding and add pure quad test

This commit is contained in:
2026-03-26 00:47:12 +08:00
parent 76c4c2ace2
commit 9adac63b4c
20 changed files with 711 additions and 53 deletions

View File

@@ -74,6 +74,8 @@ uint32_t GetFormatBytesPerPixel(Format format) {
return 8;
case Format::R32_Float:
return 4;
case Format::R32G32_Float:
return 8;
case Format::R32G32B32A32_Float:
return 16;
default:
@@ -390,6 +392,7 @@ RHITexture* D3D12Device::CreateTexture(const TextureDesc& desc, const void* init
uploadCommandList.Reset();
auto* texture = new D3D12Texture();
ComPtr<ID3D12Resource> uploadBuffer;
if (!texture->InitializeFromData(
m_device.Get(),
uploadCommandList.GetCommandList(),
@@ -397,7 +400,8 @@ RHITexture* D3D12Device::CreateTexture(const TextureDesc& desc, const void* init
desc.width,
desc.height,
ToD3D12(format),
resolvedRowPitch)) {
resolvedRowPitch,
&uploadBuffer)) {
delete texture;
uploadCommandList.Shutdown();
uploadAllocator.Shutdown();
@@ -411,6 +415,7 @@ RHITexture* D3D12Device::CreateTexture(const TextureDesc& desc, const void* init
ID3D12CommandList* commandLists[] = { uploadCommandList.GetCommandList() };
uploadQueue.ExecuteCommandListsInternal(1, commandLists);
uploadQueue.WaitForIdle();
uploadBuffer.Reset();
uploadCommandList.Shutdown();
uploadAllocator.Shutdown();
@@ -442,13 +447,13 @@ RHIShader* D3D12Device::CreateShader(const ShaderCompileDesc& desc) {
RHISampler* D3D12Device::CreateSampler(const SamplerDesc& desc) {
auto* sampler = new D3D12Sampler();
D3D12_SAMPLER_DESC d3d12Desc = {};
d3d12Desc.Filter = static_cast<D3D12_FILTER>(desc.filter);
d3d12Desc.AddressU = static_cast<D3D12_TEXTURE_ADDRESS_MODE>(desc.addressU);
d3d12Desc.AddressV = static_cast<D3D12_TEXTURE_ADDRESS_MODE>(desc.addressV);
d3d12Desc.AddressW = static_cast<D3D12_TEXTURE_ADDRESS_MODE>(desc.addressW);
d3d12Desc.Filter = ToD3D12(static_cast<FilterMode>(desc.filter));
d3d12Desc.AddressU = ToD3D12(static_cast<TextureAddressMode>(desc.addressU));
d3d12Desc.AddressV = ToD3D12(static_cast<TextureAddressMode>(desc.addressV));
d3d12Desc.AddressW = ToD3D12(static_cast<TextureAddressMode>(desc.addressW));
d3d12Desc.MipLODBias = desc.mipLodBias;
d3d12Desc.MaxAnisotropy = desc.maxAnisotropy;
d3d12Desc.ComparisonFunc = static_cast<D3D12_COMPARISON_FUNC>(desc.comparisonFunc);
d3d12Desc.ComparisonFunc = ToD3D12(static_cast<ComparisonFunc>(desc.comparisonFunc));
d3d12Desc.BorderColor[0] = desc.borderColorR;
d3d12Desc.BorderColor[1] = desc.borderColorG;
d3d12Desc.BorderColor[2] = desc.borderColorB;
@@ -735,7 +740,7 @@ RHIResourceView* D3D12Device::CreateShaderResourceView(RHITexture* texture, cons
srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
auto heap = std::make_unique<D3D12DescriptorHeap>();
if (!heap->Initialize(m_device.Get(), DescriptorHeapType::CBV_SRV_UAV, 1, true)) {
if (!heap->Initialize(m_device.Get(), DescriptorHeapType::CBV_SRV_UAV, 1, false)) {
delete view;
return nullptr;
}
@@ -756,7 +761,7 @@ RHIResourceView* D3D12Device::CreateUnorderedAccessView(RHITexture* texture, con
uavDesc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;
auto heap = std::make_unique<D3D12DescriptorHeap>();
if (!heap->Initialize(m_device.Get(), DescriptorHeapType::CBV_SRV_UAV, 1, true)) {
if (!heap->Initialize(m_device.Get(), DescriptorHeapType::CBV_SRV_UAV, 1, false)) {
delete view;
return nullptr;
}