Add forward shadow receiving support

This commit is contained in:
2026-04-04 23:01:34 +08:00
parent 353d129613
commit 96a44da2cb
22 changed files with 889 additions and 89 deletions

View File

@@ -196,6 +196,51 @@ D3D12_RTV_DIMENSION ResolveRTVDimension(const ResourceViewDesc& desc, TextureTyp
}
}
bool IsDepthFormat(Format format) {
return format == Format::D16_UNorm ||
format == Format::D24_UNorm_S8_UInt ||
format == Format::D32_Float;
}
DXGI_FORMAT ResolveD3D12ResourceFormat(Format format) {
switch (format) {
case Format::D16_UNorm:
return DXGI_FORMAT_R16_TYPELESS;
case Format::D24_UNorm_S8_UInt:
return DXGI_FORMAT_R24G8_TYPELESS;
case Format::D32_Float:
return DXGI_FORMAT_R32_TYPELESS;
default:
return ToD3D12(format);
}
}
DXGI_FORMAT ResolveD3D12DepthStencilViewFormat(Format format) {
switch (format) {
case Format::D16_UNorm:
return DXGI_FORMAT_D16_UNORM;
case Format::D24_UNorm_S8_UInt:
return DXGI_FORMAT_D24_UNORM_S8_UINT;
case Format::D32_Float:
return DXGI_FORMAT_D32_FLOAT;
default:
return ToD3D12(format);
}
}
DXGI_FORMAT ResolveD3D12ShaderResourceViewFormat(Format format) {
switch (format) {
case Format::D16_UNorm:
return DXGI_FORMAT_R16_UNORM;
case Format::D24_UNorm_S8_UInt:
return DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
case Format::D32_Float:
return DXGI_FORMAT_R32_FLOAT;
default:
return ToD3D12(format);
}
}
} // namespace
D3D12Device::D3D12Device()
@@ -595,16 +640,14 @@ RHITexture* D3D12Device::CreateTexture(const TextureDesc& desc) {
const TextureType textureType = ResolveTextureType(desc.textureType);
const Format format = static_cast<Format>(desc.format);
const bool isDepthFormat = format == Format::D24_UNorm_S8_UInt ||
format == Format::D32_Float ||
format == Format::D16_UNorm;
const bool isDepthFormat = IsDepthFormat(format);
d3d12Desc.Dimension = ToD3D12(textureType);
d3d12Desc.Width = desc.width;
d3d12Desc.Height = desc.height;
d3d12Desc.DepthOrArraySize = ResolveDepthOrArraySize(desc, textureType);
d3d12Desc.MipLevels = desc.mipLevels > 0 ? desc.mipLevels : 1;
d3d12Desc.Format = ToD3D12(format);
d3d12Desc.Format = ResolveD3D12ResourceFormat(format);
d3d12Desc.SampleDesc.Count = desc.sampleCount > 0 ? desc.sampleCount : 1;
d3d12Desc.SampleDesc.Quality = desc.sampleQuality;
d3d12Desc.Flags = static_cast<D3D12_RESOURCE_FLAGS>(desc.flags);
@@ -1009,7 +1052,8 @@ RHIResourceView* D3D12Device::CreateDepthStencilView(RHITexture* texture, const
ID3D12Resource* resource = d3d12Texture->GetResource();
D3D12_DEPTH_STENCIL_VIEW_DESC dsvDesc = {};
dsvDesc.Format = ToD3D12(static_cast<Format>(desc.format));
const Format format = desc.format != 0 ? static_cast<Format>(desc.format) : texture->GetFormat();
dsvDesc.Format = ResolveD3D12DepthStencilViewFormat(format);
dsvDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D;
auto heap = std::make_unique<D3D12DescriptorHeap>();
@@ -1029,10 +1073,11 @@ RHIResourceView* D3D12Device::CreateShaderResourceView(RHITexture* texture, cons
ID3D12Resource* resource = d3d12Texture->GetResource();
D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
srvDesc.Format = ToD3D12(static_cast<Format>(desc.format));
const Format format = desc.format != 0 ? static_cast<Format>(desc.format) : texture->GetFormat();
srvDesc.Format = ResolveD3D12ShaderResourceViewFormat(format);
srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MipLevels = desc.mipLevel > 0 ? desc.mipLevel : 1;
srvDesc.Texture2D.MostDetailedMip = 0;
srvDesc.Texture2D.MostDetailedMip = desc.mipLevel;
srvDesc.Texture2D.MipLevels = 1;
srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
auto heap = std::make_unique<D3D12DescriptorHeap>();