Move D3D12 cpp files to src/RHI/D3D12/ subdirectory

This commit is contained in:
2026-03-15 20:50:06 +08:00
parent 4af4326767
commit dfbd218435
21 changed files with 20 additions and 20 deletions

View File

@@ -0,0 +1,70 @@
#include "XCEngine/RHI/D3D12/D3D12Shader.h"
#include <d3dcompiler.h>
namespace XCEngine {
namespace RHI {
D3D12Shader::D3D12Shader()
: m_type(ShaderType::Vertex) {
}
D3D12Shader::~D3D12Shader() {
Shutdown();
}
bool D3D12Shader::CompileFromFile(const wchar_t* filePath, const char* entryPoint, const char* target) {
HRESULT hResult = D3DCompileFromFile(filePath, nullptr, nullptr, entryPoint, target,
D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION, 0, &m_bytecode, &m_error);
if (FAILED(hResult)) {
if (m_error) {
const char* errorMsg = static_cast<const char*>(m_error->GetBufferPointer());
OutputDebugStringA(errorMsg);
}
return false;
}
if (strstr(target, "vs_")) {
m_type = ShaderType::Vertex;
} else if (strstr(target, "ps_")) {
m_type = ShaderType::Pixel;
} else if (strstr(target, "gs_")) {
m_type = ShaderType::Geometry;
} else if (strstr(target, "cs_")) {
m_type = ShaderType::Compute;
}
return true;
}
bool D3D12Shader::Compile(const void* sourceData, size_t sourceSize, const char* entryPoint, const char* target) {
HRESULT hResult = D3DCompile(sourceData, sourceSize, nullptr, nullptr, nullptr, entryPoint, target,
D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION, 0, &m_bytecode, &m_error);
if (FAILED(hResult)) {
if (m_error) {
const char* errorMsg = static_cast<const char*>(m_error->GetBufferPointer());
OutputDebugStringA(errorMsg);
}
return false;
}
return true;
}
void D3D12Shader::Shutdown() {
m_bytecode.Reset();
m_error.Reset();
}
const D3D12_SHADER_BYTECODE D3D12Shader::GetBytecode() const {
D3D12_SHADER_BYTECODE bytecode = {};
if (m_bytecode) {
bytecode.pShaderBytecode = m_bytecode->GetBufferPointer();
bytecode.BytecodeLength = m_bytecode->GetBufferSize();
}
return bytecode;
}
} // namespace RHI
} // namespace XCEngine