3#include <d3dcompiler.h>
11 assert(m_device !=
nullptr);
18 std::string dx12Path = shaderPath;
19 auto hlslPos = dx12Path.rfind(
".hlsl");
20 if (hlslPos != std::string::npos) {
21 dx12Path = dx12Path.substr(0, hlslPos);
23 dx12Path +=
"_dx12.hlsl";
26 if (!compileShader(dx12Path,
"VS_Main",
"vs_5_0", m_vertexShaderBlob)) {
31 if (!compileShader(dx12Path,
"PS_Main",
"ps_5_0", m_pixelShaderBlob)) {
40 const std::string& fragPath) {
42 if (!compileShader(vertPath,
"Main",
"vs_5_0", m_vertexShaderBlob)) {
47 if (!compileShader(fragPath,
"Main",
"ps_5_0", m_pixelShaderBlob)) {
56 if (m_pipelineState && m_commandList) {
57 m_commandList->SetPipelineState(m_pipelineState.Get());
62 return m_vertexShaderBlob.Get();
66 return m_pixelShaderBlob.Get();
70 m_pipelineState = pso;
74 return m_pipelineState.Get();
78 m_commandList = cmdList;
81bool DirectX12Shader::compileShader(
const std::string& filePath,
82 const std::string& entryPoint,
83 const std::string& profile,
84 Microsoft::WRL::ComPtr<ID3DBlob>& blob) {
85 Microsoft::WRL::ComPtr<ID3DBlob> errorBlob;
86 HRESULT hr = D3DCompileFromFile(
87 std::wstring(filePath.begin(), filePath.end()).c_str(),
89 D3D_COMPILE_STANDARD_FILE_INCLUDE,
92 D3DCOMPILE_ENABLE_STRICTNESS,
99 SLEAK_ERROR(
"Shader error: {}", (
char*)errorBlob->GetBufferPointer());
void bind() override
Binds the shader's cached PSO to the current command list.
void SetCommandList(ID3D12GraphicsCommandList *cmdList)
ID3DBlob * getVertexShaderBlob() const
ID3DBlob * getPixelShaderBlob() const
void SetPipelineState(Microsoft::WRL::ComPtr< ID3D12PipelineState > pso)
~DirectX12Shader() override
ID3D12PipelineState * GetPipelineState() const
DirectX12Shader(ID3D12Device *device)
bool compile(const std::string &shaderPath) override
Compiles the combined-path convention (vs_main/ps_main entry points) from a single HLSL file.
Backend-facing rendering layer shared by the four graphics backends.
Root namespace for everything the engine exposes.