rendering: unify builtin forward and depth-style shaders
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include <stdio.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#ifdef _DEBUG
|
||||
#include <dxgidebug.h>
|
||||
@@ -51,7 +52,36 @@ bool CompileD3D12Shader(const ShaderCompileDesc& desc, D3D12Shader& shader) {
|
||||
const char* profilePtr = profile.empty() ? nullptr : profile.c_str();
|
||||
|
||||
if (!desc.source.empty()) {
|
||||
return shader.Compile(desc.source.data(), desc.source.size(), entryPointPtr, profilePtr);
|
||||
std::vector<std::string> macroNames;
|
||||
std::vector<std::string> macroDefinitions;
|
||||
std::vector<D3D_SHADER_MACRO> macroTable;
|
||||
if (!desc.macros.empty()) {
|
||||
macroNames.reserve(desc.macros.size());
|
||||
macroDefinitions.reserve(desc.macros.size());
|
||||
macroTable.reserve(desc.macros.size() + 1u);
|
||||
for (const ShaderCompileMacro& macro : desc.macros) {
|
||||
macroNames.push_back(NarrowAscii(macro.name));
|
||||
macroDefinitions.push_back(NarrowAscii(macro.definition));
|
||||
}
|
||||
|
||||
for (size_t macroIndex = 0; macroIndex < desc.macros.size(); ++macroIndex) {
|
||||
D3D_SHADER_MACRO d3dMacro = {};
|
||||
d3dMacro.Name = macroNames[macroIndex].c_str();
|
||||
d3dMacro.Definition = macroDefinitions[macroIndex].empty()
|
||||
? "1"
|
||||
: macroDefinitions[macroIndex].c_str();
|
||||
macroTable.push_back(d3dMacro);
|
||||
}
|
||||
macroTable.push_back({ nullptr, nullptr });
|
||||
}
|
||||
|
||||
const D3D_SHADER_MACRO* macroPtr = macroTable.empty() ? nullptr : macroTable.data();
|
||||
return shader.Compile(
|
||||
desc.source.data(),
|
||||
desc.source.size(),
|
||||
macroPtr,
|
||||
entryPointPtr,
|
||||
profilePtr);
|
||||
}
|
||||
|
||||
if (!desc.fileName.empty()) {
|
||||
|
||||
Reference in New Issue
Block a user