diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index ba96bf0c..58452913 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -82,23 +82,9 @@ add_library(XCEngine STATIC src/Debug/Profiler.cpp # RHI - include/XCEngine/RHI/RHIDefines.h - include/XCEngine/RHI/IRHIResources.h - include/XCEngine/RHI/ICommandList.h - include/XCEngine/RHI/IRHIDevice.h - include/XCEngine/RHI/IResourceViews.h - include/XCEngine/RHI/RHISystem.h - - # Rendering - include/XCEngine/Rendering/Resources.h - include/XCEngine/Rendering/RenderTarget.h - include/XCEngine/Rendering/Shader.h - include/XCEngine/Rendering/RenderContext.h - include/XCEngine/Rendering/StaticMeshComponent.h + include/XCEngine/RHI/Enums.h ) -add_subdirectory(src/RHI/D3D12) - target_include_directories(XCEngine PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine diff --git a/engine/include/XCEngine/RHI/Enums.h b/engine/include/XCEngine/RHI/Enums.h new file mode 100644 index 00000000..b38c9c78 --- /dev/null +++ b/engine/include/XCEngine/RHI/Enums.h @@ -0,0 +1,272 @@ +#pragma once + +#include + +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(static_cast(a) | static_cast(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 diff --git a/tests/D3D12/RHI/Enums.h b/tests/D3D12/RHI/Enums.h index c27976a6..b38c9c78 100644 --- a/tests/D3D12/RHI/Enums.h +++ b/tests/D3D12/RHI/Enums.h @@ -33,23 +33,7 @@ enum class BlendOp : uint8_t { Subtract = 2, ReverseSubtract = 3, Min = 4, - Max = 5, - LogicalClear = 8, - LogicalSet = 9, - LogicalCopy = 10, - LogicalCopyInverted = 11, - LogicalNoop = 12, - LogicalInvert = 13, - LogicalAnd = 14, - LogicalNand = 15, - LogicalOr = 16, - LogicalNor = 17, - LogicalXor = 18, - LogicalEquiv = 19, - LogicalAndReverse = 20, - LogicalAndInverted = 21, - LogicalOrReverse = 22, - LogicalOrInverted = 23 + Max = 5 }; enum class BlendFactor : uint8_t { @@ -155,44 +139,18 @@ enum class PresentFlags : uint8_t { AllowDisplayLatencyWaitableObject = 4 }; -enum class IndirectDrawArguments : uint32_t { - VertexCountPerInstance = 0, - InstanceCount = 4, - StartVertexLocation = 8, - StartInstanceLocation = 12 -}; - -enum class IndirectDispatchArguments : uint32_t { - ThreadGroupCountX = 0, - ThreadGroupCountY = 4, - ThreadGroupCountZ = 8 -}; - -enum class StencilOpDesc : uint8_t { - StencilFailOp, - StencilDepthFailOp, - StencilPassOp, - StencilFunc -}; - -enum class BlendStateFlag : uint8_t { - None = 0, - IndependentBlendEnable = 1, - IndependentBlendEnable_8Targets = 2 -}; - -enum class DepthStencilStateFlag : uint8_t { - None = 0, - DepthWrite = 1, - StencilWrite = 2 -}; - -enum class TextureAddressMode : uint8_t { - Wrap = 1, - Mirror = 2, - Clamp = 3, - Border = 4, - MirrorOnce = 5 +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 { @@ -210,6 +168,14 @@ enum class FilterMode : uint8_t { 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, @@ -247,10 +213,15 @@ inline ColorWriteMask operator|(ColorWriteMask a, ColorWriteMask b) { return static_cast(static_cast(a) | static_cast(b)); } -enum class ResourceBarrierType : uint8_t { - Transition, - Aliasing, - UAV +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 { @@ -261,58 +232,40 @@ enum class RootParameterType : uint8_t { UAV }; -enum class ShaderRegisterType : uint8_t { - CBV, - SRV, - UAV, - Sampler +enum class DescriptorHeapType : uint8_t { + CBV_SRV_UAV, + Sampler, + RTV, + DSV }; -enum class RootSignatureVersion : uint8_t { - Version1, - Version1_0 = Version1, - Version1_1 +enum class QueryType : uint8_t { + Occlusion, + Timestamp, + PipelineStatistics }; -enum class ClearDepthStencilFlags : uint8_t { - Depth = 1, - Stencil = 2, - DepthAndStencil = 3 -}; - -enum class QueryHeapFlags : uint8_t { - None = 0, - Precision = 1 -}; - -enum class PipelineStateFlags : uint8_t { - None = 0, - DebugName = 1 -}; - -enum class BufferUAVFlags : uint8_t { - None = 0, - Raw = 1, - Append = 2, - Counter = 4 -}; - -enum class TextureLayout : uint8_t { - Unknown, - RowMajor, - _64KB_UNDEFINED_SWIZZLE, - Standard64KB -}; - -enum class CommandListFlags : uint8_t { - None = 0, - DisallowSetName = 1 -}; - -enum class FenceFlags : uint8_t { - None = 0, - Signal = 1, - Wait = 2 +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 diff --git a/tests/D3D12/main.cpp b/tests/D3D12/main.cpp index f129f517..c9e0faf7 100644 --- a/tests/D3D12/main.cpp +++ b/tests/D3D12/main.cpp @@ -11,6 +11,9 @@ #include #include #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(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(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(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(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(FilterMode::Linear); + samplerDesc[0].AddressU = static_cast(TextureAddressMode::Clamp); + samplerDesc[0].AddressV = static_cast(TextureAddressMode::Clamp); + samplerDesc[0].AddressW = static_cast(TextureAddressMode::Clamp); + samplerDesc[0].BorderColor = static_cast(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(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(FillMode::Solid); + psoDesc.RasterizerState.CullMode = static_cast(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(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(BlendFactor::SrcAlpha),static_cast(BlendFactor::InvSrcAlpha),static_cast(BlendOp::Add), + static_cast(BlendFactor::SrcAlpha),static_cast(BlendFactor::InvSrcAlpha),static_cast(BlendOp::Add), + static_cast(LogicOp::Noop), + static_cast(ColorWriteMask::All), }; for (int i = 0; i < D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i) psoDesc.BlendState.RenderTarget[i] = rtBlendDesc;