refactor: RHI枚举改为独立编号,添加D3D12转换层

This commit is contained in:
2026-03-15 02:24:56 +08:00
parent 3e89489078
commit be6abd7bf6
5 changed files with 286 additions and 421 deletions

View File

@@ -11,7 +11,8 @@
#include <string>
#include <cstring>
#include "stbi/stb_image.h"
#include "RHI/Enums.h"
#include "XCEngine/RHI/Enums.h"
#include "XCEngine/RHI/D3D12/D3D12Enum.h"
using namespace XCEngine::RHI;
@@ -208,13 +209,13 @@ D3D12_RESOURCE_BARRIER InitResourceBarrier(
ID3D12RootSignature* InitRootSignature() {
D3D12_ROOT_PARAMETER rootParameters[4];
rootParameters[1].ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
rootParameters[1].ShaderVisibility = static_cast<D3D12_SHADER_VISIBILITY>(ShaderVisibility::Vertex);
rootParameters[1].ShaderVisibility = ToD3D12(ShaderVisibility::Vertex);
rootParameters[1].Constants.RegisterSpace = 0;
rootParameters[1].Constants.ShaderRegister = 0;
rootParameters[1].Constants.Num32BitValues = 4;
rootParameters[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
rootParameters[0].ShaderVisibility = static_cast<D3D12_SHADER_VISIBILITY>(ShaderVisibility::All);
rootParameters[0].ShaderVisibility = ToD3D12(ShaderVisibility::All);
rootParameters[0].Descriptor.RegisterSpace = 0;
rootParameters[0].Descriptor.ShaderRegister = 1;
@@ -226,26 +227,26 @@ ID3D12RootSignature* InitRootSignature() {
descriptorRange[0].OffsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;
rootParameters[2].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
rootParameters[2].ShaderVisibility = static_cast<D3D12_SHADER_VISIBILITY>(ShaderVisibility::Pixel);
rootParameters[2].ShaderVisibility = ToD3D12(ShaderVisibility::Pixel);
rootParameters[2].DescriptorTable.pDescriptorRanges = descriptorRange;
rootParameters[2].DescriptorTable.NumDescriptorRanges = _countof(descriptorRange);
rootParameters[3].ParameterType = D3D12_ROOT_PARAMETER_TYPE_SRV;
rootParameters[3].ShaderVisibility = static_cast<D3D12_SHADER_VISIBILITY>(ShaderVisibility::All);
rootParameters[3].ShaderVisibility = ToD3D12(ShaderVisibility::All);
rootParameters[3].Descriptor.RegisterSpace = 1;
rootParameters[3].Descriptor.ShaderRegister = 0;
D3D12_STATIC_SAMPLER_DESC samplerDesc[1];
memset(samplerDesc, 0, sizeof(D3D12_STATIC_SAMPLER_DESC) * _countof(samplerDesc));
samplerDesc[0].Filter = static_cast<D3D12_FILTER>(FilterMode::Linear);
samplerDesc[0].AddressU = static_cast<D3D12_TEXTURE_ADDRESS_MODE>(TextureAddressMode::Clamp);
samplerDesc[0].AddressV = static_cast<D3D12_TEXTURE_ADDRESS_MODE>(TextureAddressMode::Clamp);
samplerDesc[0].AddressW = static_cast<D3D12_TEXTURE_ADDRESS_MODE>(TextureAddressMode::Clamp);
samplerDesc[0].BorderColor = static_cast<D3D12_STATIC_BORDER_COLOR>(BorderColor::OpaqueBlack);
samplerDesc[0].Filter = ToD3D12(FilterMode::Linear);
samplerDesc[0].AddressU = ToD3D12(TextureAddressMode::Clamp);
samplerDesc[0].AddressV = ToD3D12(TextureAddressMode::Clamp);
samplerDesc[0].AddressW = ToD3D12(TextureAddressMode::Clamp);
samplerDesc[0].BorderColor = ToD3D12(BorderColor::OpaqueBlack);
samplerDesc[0].MaxLOD = D3D12_FLOAT32_MAX;
samplerDesc[0].RegisterSpace = 0;
samplerDesc[0].ShaderRegister = 0;
samplerDesc[0].ShaderVisibility = static_cast<D3D12_SHADER_VISIBILITY>(ShaderVisibility::Pixel);
samplerDesc[0].ShaderVisibility = ToD3D12(ShaderVisibility::Pixel);
D3D12_ROOT_SIGNATURE_DESC rootSignatureDesc = {};
rootSignatureDesc.NumParameters = _countof(rootParameters);
@@ -515,20 +516,20 @@ ID3D12PipelineState* CreatePSO(ID3D12RootSignature* inID3D12RootSignature,
psoDesc.InputLayout = vertexDataLayoutDesc;
psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
psoDesc.RasterizerState.FillMode = static_cast<D3D12_FILL_MODE>(FillMode::Solid);
psoDesc.RasterizerState.CullMode = static_cast<D3D12_CULL_MODE>(CullMode::Back);
psoDesc.RasterizerState.FillMode = ToD3D12(FillMode::Solid);
psoDesc.RasterizerState.CullMode = ToD3D12(CullMode::Back);
psoDesc.RasterizerState.DepthClipEnable = TRUE;
psoDesc.DepthStencilState.DepthEnable = true;
psoDesc.DepthStencilState.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
psoDesc.DepthStencilState.DepthFunc = static_cast<D3D12_COMPARISON_FUNC>(ComparisonFunc::LessEqual);
psoDesc.DepthStencilState.DepthFunc = ToD3D12(ComparisonFunc::LessEqual);
psoDesc.BlendState = { 0 };
D3D12_RENDER_TARGET_BLEND_DESC rtBlendDesc = {
FALSE,FALSE,
static_cast<D3D12_BLEND>(BlendFactor::SrcAlpha),static_cast<D3D12_BLEND>(BlendFactor::InvSrcAlpha),static_cast<D3D12_BLEND_OP>(BlendOp::Add),
static_cast<D3D12_BLEND>(BlendFactor::SrcAlpha),static_cast<D3D12_BLEND>(BlendFactor::InvSrcAlpha),static_cast<D3D12_BLEND_OP>(BlendOp::Add),
static_cast<D3D12_LOGIC_OP>(LogicOp::Noop),
ToD3D12(BlendFactor::SrcAlpha),ToD3D12(BlendFactor::InvSrcAlpha),ToD3D12(BlendOp::Add),
ToD3D12(BlendFactor::SrcAlpha),ToD3D12(BlendFactor::InvSrcAlpha),ToD3D12(BlendOp::Add),
ToD3D12(LogicOp::Noop),
static_cast<UINT8>(ColorWriteMask::All),
};
for (int i = 0; i < D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)