Skip to content

Commit 574ff45

Browse files
committed
Added verification that shader content type is HLSL
1 parent 841ff91 commit 574ff45

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

tools/nsc/main.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,13 @@ class ShaderCompiler final : public system::IApplicationFramework
8181
}
8282
#endif
8383

84-
//TODO unfuck this
85-
const ICPUShader* shader_code = open_shader_file(file_to_compile);
86-
auto compilation_result = compile_shader(shader_code, file_to_compile);
84+
const ICPUShader* shader = open_shader_file(file_to_compile);
85+
if (shader->getContentType() != IShader::E_CONTENT_TYPE::ECT_HLSL)
86+
{
87+
m_logger->log("Error. Loaded shader file content is not HLSL.", ILogger::ELL_ERROR);
88+
return false;
89+
}
90+
auto compilation_result = compile_shader(shader, file_to_compile);
8791

8892
// writie compiled shader to file as bytes
8993
if (compilation_result && !output_filepath.empty()) {
@@ -105,23 +109,23 @@ class ShaderCompiler final : public system::IApplicationFramework
105109

106110
private:
107111

108-
core::smart_refctd_ptr<ICPUShader> compile_shader(const ICPUShader* shader_code, std::string_view sourceIdentifier) {
112+
core::smart_refctd_ptr<ICPUShader> compile_shader(const ICPUShader* shader, std::string_view sourceIdentifier) {
109113
constexpr uint32_t WorkgroupSize = 256;
110114
constexpr uint32_t WorkgroupCount = 2048;
111115
const string WorkgroupSizeAsStr = std::to_string(WorkgroupSize);
112116

113117
smart_refctd_ptr<CHLSLCompiler> hlslcompiler = make_smart_refctd_ptr<CHLSLCompiler>(smart_refctd_ptr(m_system));
114118

115119
CHLSLCompiler::SOptions options = {};
116-
options.stage = shader_code->getStage();
120+
options.stage = shader->getStage();
117121
//options.debugInfoFlags = IShaderCompiler::E_DEBUG_INFO_FLAGS::EDIF_LINE_BIT;
118122
options.preprocessorOptions.sourceIdentifier = sourceIdentifier;
119123
options.preprocessorOptions.logger = m_logger.get();
120124
options.dxcOptions = std::span<std::string>(m_arguments);
121125
auto includeFinder = make_smart_refctd_ptr<IShaderCompiler::CIncludeFinder>(smart_refctd_ptr(m_system));
122126
options.preprocessorOptions.includeFinder = includeFinder.get();
123127

124-
return hlslcompiler->compileToSPIRV((const char*)shader_code->getContent()->getPointer(), options);
128+
return hlslcompiler->compileToSPIRV((const char*)shader->getContent()->getPointer(), options);
125129
}
126130

127131

0 commit comments

Comments
 (0)