refactor: RHI枚举改为独立编号,添加D3D12转换层
This commit is contained in:
@@ -14,8 +14,9 @@ target_compile_definitions(D3D12 PRIVATE
|
||||
)
|
||||
|
||||
target_include_directories(D3D12 PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/tests/D3D12
|
||||
${CMAKE_SOURCE_DIR}/tests/D3D12/stbi
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/stbi
|
||||
D:/Xuanchi/高斯泼溅/XCEngine/engine/include
|
||||
)
|
||||
|
||||
target_link_libraries(D3D12 PRIVATE
|
||||
|
||||
@@ -1,272 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
enum class ShaderType : uint8_t {
|
||||
Vertex,
|
||||
Hull,
|
||||
Domain,
|
||||
Geometry,
|
||||
Pixel,
|
||||
Compute,
|
||||
Amplification,
|
||||
Mesh,
|
||||
Library
|
||||
};
|
||||
|
||||
enum class CullMode : uint8_t {
|
||||
None = 1,
|
||||
Front = 2,
|
||||
Back = 3
|
||||
};
|
||||
|
||||
enum class FillMode : uint8_t {
|
||||
Wireframe = 2,
|
||||
Solid = 3
|
||||
};
|
||||
|
||||
enum class BlendOp : uint8_t {
|
||||
Add = 1,
|
||||
Subtract = 2,
|
||||
ReverseSubtract = 3,
|
||||
Min = 4,
|
||||
Max = 5
|
||||
};
|
||||
|
||||
enum class BlendFactor : uint8_t {
|
||||
Zero = 0,
|
||||
One = 1,
|
||||
SrcColor = 2,
|
||||
InvSrcColor = 3,
|
||||
SrcAlpha = 4,
|
||||
InvSrcAlpha = 5,
|
||||
DstAlpha = 6,
|
||||
InvDstAlpha = 7,
|
||||
DstColor = 8,
|
||||
InvDstColor = 9,
|
||||
SrcAlphaSat = 10,
|
||||
BlendFactor = 11,
|
||||
InvBlendFactor = 12,
|
||||
Src1Color = 13,
|
||||
InvSrc1Color = 14,
|
||||
Src1Alpha = 15,
|
||||
InvSrc1Alpha = 16
|
||||
};
|
||||
|
||||
enum class ComparisonFunc : uint8_t {
|
||||
Never = 1,
|
||||
Less = 2,
|
||||
Equal = 3,
|
||||
LessEqual = 4,
|
||||
Greater = 5,
|
||||
NotEqual = 6,
|
||||
GreaterEqual = 7,
|
||||
Always = 8
|
||||
};
|
||||
|
||||
enum class StencilOp : uint8_t {
|
||||
Keep = 1,
|
||||
Zero = 2,
|
||||
Replace = 3,
|
||||
IncrSat = 4,
|
||||
DecrSat = 5,
|
||||
Invert = 6,
|
||||
Incr = 7,
|
||||
Decr = 8
|
||||
};
|
||||
|
||||
enum class TextureType : uint8_t {
|
||||
Texture1D,
|
||||
Texture2D,
|
||||
Texture2DArray,
|
||||
Texture3D,
|
||||
TextureCube,
|
||||
TextureCubeArray
|
||||
};
|
||||
|
||||
enum class BufferType : uint8_t {
|
||||
Vertex,
|
||||
Index,
|
||||
Constant,
|
||||
ReadBack,
|
||||
Indirect,
|
||||
RaytracingAccelerationStructure,
|
||||
ShaderBindingTable
|
||||
};
|
||||
|
||||
enum class DescriptorType : uint8_t {
|
||||
CBV,
|
||||
SRV,
|
||||
UAV,
|
||||
Sampler,
|
||||
RTV,
|
||||
DSV
|
||||
};
|
||||
|
||||
enum class PipelineType : uint8_t {
|
||||
Graphics,
|
||||
Compute,
|
||||
Raytracing
|
||||
};
|
||||
|
||||
enum class CommandQueueType : uint8_t {
|
||||
Direct,
|
||||
Compute,
|
||||
Copy
|
||||
};
|
||||
|
||||
enum class LoadAction : uint8_t {
|
||||
Undefined = 0,
|
||||
Load = 1,
|
||||
Clear = 2
|
||||
};
|
||||
|
||||
enum class StoreAction : uint8_t {
|
||||
Undefined = 0,
|
||||
Store = 1,
|
||||
Resolve = 2,
|
||||
StoreAndResolve = 3,
|
||||
Discard = 4
|
||||
};
|
||||
|
||||
enum class PresentFlags : uint8_t {
|
||||
None = 0,
|
||||
AllowTearing = 1,
|
||||
StrictlyTimedFrame = 2,
|
||||
AllowDisplayLatencyWaitableObject = 4
|
||||
};
|
||||
|
||||
enum class PrimitiveTopology : uint8_t {
|
||||
Undefined = 0,
|
||||
PointList = 1,
|
||||
LineList = 2,
|
||||
LineStrip = 3,
|
||||
TriangleList = 4,
|
||||
TriangleStrip = 5,
|
||||
LineListAdj = 10,
|
||||
LineStripAdj = 11,
|
||||
TriangleListAdj = 12,
|
||||
TriangleStripAdj = 13,
|
||||
PatchList = 33
|
||||
};
|
||||
|
||||
enum class FilterMode : uint8_t {
|
||||
Point = 0,
|
||||
Linear = 1,
|
||||
Anisotropic = 2,
|
||||
ComparisonPoint = 3,
|
||||
ComparisonLinear = 4,
|
||||
ComparisonAnisotropic = 5,
|
||||
MinimumPoint = 7,
|
||||
MinimumLinear = 8,
|
||||
MinimumAnisotropic = 9,
|
||||
MaximumPoint = 11,
|
||||
MaximumLinear = 12,
|
||||
MaximumAnisotropic = 13
|
||||
};
|
||||
|
||||
enum class TextureAddressMode : uint8_t {
|
||||
Wrap = 1,
|
||||
Mirror = 2,
|
||||
Clamp = 3,
|
||||
Border = 4,
|
||||
MirrorOnce = 5
|
||||
};
|
||||
|
||||
enum class BorderColor : uint8_t {
|
||||
TransparentBlack = 0,
|
||||
OpaqueBlack = 1,
|
||||
OpaqueWhite = 2
|
||||
};
|
||||
|
||||
enum class LogicOp : uint8_t {
|
||||
Clear = 0,
|
||||
Set = 1,
|
||||
Copy = 2,
|
||||
CopyInverted = 3,
|
||||
Noop = 4,
|
||||
Invert = 5,
|
||||
And = 6,
|
||||
Nand = 7,
|
||||
Or = 8,
|
||||
Nor = 9,
|
||||
Xor = 10,
|
||||
Equiv = 11,
|
||||
AndReverse = 12,
|
||||
AndInverted = 13,
|
||||
OrReverse = 14,
|
||||
OrInverted = 15
|
||||
};
|
||||
|
||||
enum class ColorWriteMask : uint8_t {
|
||||
Red = 1,
|
||||
Green = 2,
|
||||
Blue = 4,
|
||||
Alpha = 8,
|
||||
All = 15
|
||||
};
|
||||
|
||||
inline ColorWriteMask operator|(ColorWriteMask a, ColorWriteMask b) {
|
||||
return static_cast<ColorWriteMask>(static_cast<uint8_t>(a) | static_cast<uint8_t>(b));
|
||||
}
|
||||
|
||||
enum class ShaderVisibility : uint8_t {
|
||||
All = 0,
|
||||
Vertex = 1,
|
||||
Hull = 2,
|
||||
Domain = 3,
|
||||
Geometry = 4,
|
||||
Pixel = 5,
|
||||
Amplification = 6,
|
||||
Mesh = 7
|
||||
};
|
||||
|
||||
enum class RootParameterType : uint8_t {
|
||||
DescriptorTable,
|
||||
Constants,
|
||||
CBV,
|
||||
SRV,
|
||||
UAV
|
||||
};
|
||||
|
||||
enum class DescriptorHeapType : uint8_t {
|
||||
CBV_SRV_UAV,
|
||||
Sampler,
|
||||
RTV,
|
||||
DSV
|
||||
};
|
||||
|
||||
enum class QueryType : uint8_t {
|
||||
Occlusion,
|
||||
Timestamp,
|
||||
PipelineStatistics
|
||||
};
|
||||
|
||||
enum class Format : uint32_t {
|
||||
Unknown = 0,
|
||||
R8_UNorm = 61,
|
||||
R8G8_UNorm = 49,
|
||||
R8G8B8A8_UNorm = 28,
|
||||
R16G16B16A16_Float = 10,
|
||||
R32G32B32A32_Float = 2,
|
||||
R16_Float = 54,
|
||||
R32_Float = 41,
|
||||
D16_UNorm = 55,
|
||||
D24_UNorm_S8_UInt = 45,
|
||||
D32_Float = 40,
|
||||
BC1_UNorm = 71,
|
||||
BC2_UNorm = 74,
|
||||
BC3_UNorm = 77,
|
||||
BC4_UNorm = 80,
|
||||
BC5_UNorm = 83,
|
||||
BC6H_UF16 = 95,
|
||||
BC7_UNorm = 98,
|
||||
R32G32B32A32_UInt = 23,
|
||||
R32_UInt = 39
|
||||
};
|
||||
|
||||
} // namespace RHI
|
||||
} // namespace XCEngine
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user