2026-03-15 18:41:27 +08:00
|
|
|
#include "XCEngine/RHI/D3D12/D3D12PipelineState.h"
|
|
|
|
|
|
|
|
|
|
namespace XCEngine {
|
|
|
|
|
namespace RHI {
|
|
|
|
|
|
|
|
|
|
D3D12PipelineState::D3D12PipelineState() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
D3D12PipelineState::~D3D12PipelineState() {
|
|
|
|
|
Shutdown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool D3D12PipelineState::Initialize(ID3D12Device* device, const D3D12_GRAPHICS_PIPELINE_STATE_DESC& desc) {
|
|
|
|
|
HRESULT hResult = device->CreateGraphicsPipelineState(&desc, IID_PPV_ARGS(&m_pipelineState));
|
|
|
|
|
if (FAILED(hResult)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void D3D12PipelineState::Shutdown() {
|
|
|
|
|
m_pipelineState.Reset();
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-17 00:57:35 +08:00
|
|
|
D3D12_GRAPHICS_PIPELINE_STATE_DESC D3D12PipelineState::CreateDesc(
|
|
|
|
|
ID3D12RootSignature* rootSignature,
|
|
|
|
|
const D3D12_SHADER_BYTECODE& vs,
|
|
|
|
|
const D3D12_SHADER_BYTECODE& ps,
|
|
|
|
|
const D3D12_SHADER_BYTECODE& gs,
|
|
|
|
|
uint32_t inputElementCount,
|
|
|
|
|
const D3D12_INPUT_ELEMENT_DESC* inputElements) {
|
|
|
|
|
D3D12_GRAPHICS_PIPELINE_STATE_DESC desc = {};
|
|
|
|
|
desc.pRootSignature = rootSignature;
|
|
|
|
|
desc.VS = vs;
|
|
|
|
|
desc.PS = ps;
|
|
|
|
|
desc.GS = gs;
|
|
|
|
|
desc.InputLayout.NumElements = inputElementCount;
|
|
|
|
|
desc.InputLayout.pInputElementDescs = inputElements;
|
|
|
|
|
desc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
|
|
|
desc.DSVFormat = DXGI_FORMAT_D24_UNORM_S8_UINT;
|
|
|
|
|
desc.SampleDesc.Count = 1;
|
|
|
|
|
desc.SampleDesc.Quality = 0;
|
|
|
|
|
desc.SampleMask = 0xffffffff;
|
|
|
|
|
desc.NumRenderTargets = 1;
|
|
|
|
|
desc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
|
|
|
|
|
desc.RasterizerState.FillMode = D3D12_FILL_MODE_SOLID;
|
|
|
|
|
desc.RasterizerState.CullMode = D3D12_CULL_MODE_BACK;
|
|
|
|
|
desc.RasterizerState.DepthClipEnable = TRUE;
|
|
|
|
|
desc.DepthStencilState.DepthEnable = TRUE;
|
|
|
|
|
desc.DepthStencilState.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
|
|
|
|
|
desc.DepthStencilState.DepthFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL;
|
|
|
|
|
return desc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
D3D12_INPUT_ELEMENT_DESC D3D12PipelineState::CreateInputElement(
|
|
|
|
|
const char* semanticName,
|
|
|
|
|
uint32_t semanticIndex,
|
|
|
|
|
Format format,
|
|
|
|
|
uint32_t inputSlot,
|
|
|
|
|
uint32_t alignedByteOffset) {
|
|
|
|
|
D3D12_INPUT_ELEMENT_DESC element = {};
|
|
|
|
|
element.SemanticName = semanticName;
|
|
|
|
|
element.SemanticIndex = semanticIndex;
|
|
|
|
|
element.Format = ToD3D12(format);
|
|
|
|
|
element.InputSlot = inputSlot;
|
|
|
|
|
element.AlignedByteOffset = alignedByteOffset;
|
|
|
|
|
element.InputSlotClass = D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA;
|
|
|
|
|
element.InstanceDataStepRate = 0;
|
|
|
|
|
return element;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
D3D12_INPUT_ELEMENT_DESC D3D12PipelineState::CreateInputElement(
|
|
|
|
|
const char* semanticName,
|
|
|
|
|
uint32_t semanticIndex,
|
|
|
|
|
Format format,
|
|
|
|
|
uint32_t inputSlot) {
|
|
|
|
|
return CreateInputElement(semanticName, semanticIndex, format, inputSlot, D3D12_APPEND_ALIGNED_ELEMENT);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-15 18:41:27 +08:00
|
|
|
} // namespace RHI
|
|
|
|
|
} // namespace XCEngine
|