Skip to content

Commit cfd8226

Browse files
workarounds for missing extensions
1 parent 237ddb5 commit cfd8226

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

tools/nsc/main.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ class ShaderCompiler final : public system::IApplicationFramework
8888
}
8989
#endif
9090

91-
const ICPUShader* shader = open_shader_file(file_to_compile);
91+
auto shader = open_shader_file(file_to_compile);
9292
if (shader->getContentType() != IShader::E_CONTENT_TYPE::ECT_HLSL)
9393
{
9494
m_logger->log("Error. Loaded shader file content is not HLSL.", ILogger::ELL_ERROR);
9595
return false;
9696
}
97-
auto compilation_result = compile_shader(shader, file_to_compile);
97+
auto compilation_result = compile_shader(shader.get(), file_to_compile);
9898

9999
// writie compiled shader to file as bytes
100100
if (compilation_result && !output_filepath.empty()) {
@@ -132,7 +132,7 @@ class ShaderCompiler final : public system::IApplicationFramework
132132
}
133133

134134

135-
const ICPUShader* open_shader_file(std::string& filepath) {
135+
core::smart_refctd_ptr<const ICPUShader> open_shader_file(std::string filepath) {
136136

137137
m_assetMgr = make_smart_refctd_ptr<asset::IAssetManager>(smart_refctd_ptr(m_system));
138138

@@ -146,9 +146,19 @@ class ShaderCompiler final : public system::IApplicationFramework
146146
return nullptr;
147147
}
148148
assert(assets.size() == 1);
149+
150+
// could happen when the file is missing an extension and we can't deduce its a shader
151+
if (assets[0]->getAssetType()==IAsset::ET_BUFFER)
152+
{
153+
auto buf = IAsset::castDown<ICPUBuffer>(assets[0]);
154+
std::string source; source.resize(buf->getSize()+1);
155+
memcpy(source.data(),buf->getPointer(),buf->getSize());
156+
return core::make_smart_refctd_ptr<ICPUShader>(source.data(), IShader::ESS_UNKNOWN, IShader::E_CONTENT_TYPE::ECT_HLSL, std::move(filepath));
157+
}
158+
149159
smart_refctd_ptr<ICPUSpecializedShader> source = IAsset::castDown<ICPUSpecializedShader>(assets[0]);
150160

151-
return source->getUnspecialized();
161+
return core::smart_refctd_ptr<const ICPUShader>(source->getUnspecialized());
152162
}
153163

154164

0 commit comments

Comments
 (0)