refactor: 添加RHI Enums.h并在D3D12测试中替换部分D3D12枚举

This commit is contained in:
2026-03-15 02:05:28 +08:00
parent f427eb2588
commit 3e89489078
4 changed files with 353 additions and 139 deletions

View File

@@ -11,6 +11,9 @@
#include <string>
#include <cstring>
#include "stbi/stb_image.h"
#include "RHI/Enums.h"
using namespace XCEngine::RHI;
#pragma comment(lib,"d3d12.lib")
#pragma comment(lib,"dxgi.lib")
@@ -205,13 +208,13 @@ D3D12_RESOURCE_BARRIER InitResourceBarrier(
ID3D12RootSignature* InitRootSignature() {
D3D12_ROOT_PARAMETER rootParameters[4];
rootParameters[1].ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
rootParameters[1].ShaderVisibility = D3D12_SHADER_VISIBILITY_VERTEX;
rootParameters[1].ShaderVisibility = static_cast<D3D12_SHADER_VISIBILITY>(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 = D3D12_SHADER_VISIBILITY_ALL;
rootParameters[0].ShaderVisibility = static_cast<D3D12_SHADER_VISIBILITY>(ShaderVisibility::All);
rootParameters[0].Descriptor.RegisterSpace = 0;
rootParameters[0].Descriptor.ShaderRegister = 1;
@@ -223,26 +226,26 @@ ID3D12RootSignature* InitRootSignature() {
descriptorRange[0].OffsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;
rootParameters[2].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
rootParameters[2].ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
rootParameters[2].ShaderVisibility = static_cast<D3D12_SHADER_VISIBILITY>(ShaderVisibility::Pixel);
rootParameters[2].DescriptorTable.pDescriptorRanges = descriptorRange;
rootParameters[2].DescriptorTable.NumDescriptorRanges = _countof(descriptorRange);
rootParameters[3].ParameterType = D3D12_ROOT_PARAMETER_TYPE_SRV;
rootParameters[3].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
rootParameters[3].ShaderVisibility = static_cast<D3D12_SHADER_VISIBILITY>(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 = D3D12_FILTER_MIN_MAG_MIP_LINEAR;
samplerDesc[0].AddressU = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
samplerDesc[0].AddressV = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
samplerDesc[0].AddressW = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
samplerDesc[0].BorderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_BLACK;
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].MaxLOD = D3D12_FLOAT32_MAX;
samplerDesc[0].RegisterSpace = 0;
samplerDesc[0].ShaderRegister = 0;
samplerDesc[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
samplerDesc[0].ShaderVisibility = static_cast<D3D12_SHADER_VISIBILITY>(ShaderVisibility::Pixel);
D3D12_ROOT_SIGNATURE_DESC rootSignatureDesc = {};
rootSignatureDesc.NumParameters = _countof(rootParameters);
@@ -512,21 +515,21 @@ ID3D12PipelineState* CreatePSO(ID3D12RootSignature* inID3D12RootSignature,
psoDesc.InputLayout = vertexDataLayoutDesc;
psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
psoDesc.RasterizerState.FillMode = D3D12_FILL_MODE_SOLID;
psoDesc.RasterizerState.CullMode = D3D12_CULL_MODE_BACK;
psoDesc.RasterizerState.FillMode = static_cast<D3D12_FILL_MODE>(FillMode::Solid);
psoDesc.RasterizerState.CullMode = static_cast<D3D12_CULL_MODE>(CullMode::Back);
psoDesc.RasterizerState.DepthClipEnable = TRUE;
psoDesc.DepthStencilState.DepthEnable = true;
psoDesc.DepthStencilState.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
psoDesc.DepthStencilState.DepthFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL;
psoDesc.DepthStencilState.DepthFunc = static_cast<D3D12_COMPARISON_FUNC>(ComparisonFunc::LessEqual);
psoDesc.BlendState = { 0 };
D3D12_RENDER_TARGET_BLEND_DESC rtBlendDesc = {
FALSE,FALSE,
D3D12_BLEND_SRC_ALPHA,D3D12_BLEND_INV_SRC_ALPHA,D3D12_BLEND_OP_ADD,
D3D12_BLEND_SRC_ALPHA,D3D12_BLEND_INV_SRC_ALPHA,D3D12_BLEND_OP_ADD,
D3D12_LOGIC_OP_NOOP,
D3D12_COLOR_WRITE_ENABLE_ALL,
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),
static_cast<UINT8>(ColorWriteMask::All),
};
for (int i = 0; i < D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
psoDesc.BlendState.RenderTarget[i] = rtBlendDesc;