Skip to content

Commit 8355881

Browse files
author
devsh
committed
Fix the BIN and shader loaders to compute content hashes when loading
1 parent c7e42ed commit 8355881

File tree

3 files changed

+47
-46
lines changed

3 files changed

+47
-46
lines changed

src/nbl/asset/interchange/CBufferLoaderBIN.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ asset::SAssetBundle CBufferLoaderBIN::loadAsset(system::IFile* _file, const asse
1919
if (!success)
2020
return {};
2121

22+
ctx.sourceCodeBuffer->setContentHash(ctx.sourceCodeBuffer->computeContentHash());
2223
return SAssetBundle(nullptr,{std::move(ctx.sourceCodeBuffer)});
2324
}
2425

src/nbl/asset/interchange/CHLSLLoader.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@ SAssetBundle CHLSLLoader::loadAsset(system::IFile* _file, const IAssetLoader::SA
1414
if (!_file)
1515
return {};
1616

17-
auto len = _file->getSize();
18-
void* source = _NBL_ALIGNED_MALLOC(len+1u,_NBL_SIMD_ALIGNMENT);
17+
const auto len = _file->getSize();
18+
auto source = core::make_smart_refctd_ptr<ICPUBuffer>(len+1);
1919

2020
system::IFile::success_t success;
21-
_file->read(success, source, 0, len);
21+
_file->read(success, source->getPointer(), 0, len);
2222
if (!success)
2323
return {};
24-
25-
reinterpret_cast<char*>(source)[len] = 0;
24+
// make sure put string end terminator
25+
reinterpret_cast<char*>(source->getPointer())[len] = 0;
2626

2727

2828
const auto filename = _file->getFileName();
2929
auto filenameEnding = filename.filename().string();
3030

31-
core::unordered_map<std::string,IShader::E_SHADER_STAGE> typeFromExt = {
31+
core::unordered_map<std::string,IShader::E_SHADER_STAGE> typeFromExt =
32+
{
3233
{".vert.hlsl",IShader::E_SHADER_STAGE::ESS_VERTEX},
3334
{".tesc.hlsl",IShader::E_SHADER_STAGE::ESS_TESSELLATION_CONTROL},
3435
{".tese.hlsl",IShader::E_SHADER_STAGE::ESS_TESSELLATION_EVALUATION},
@@ -39,7 +40,8 @@ SAssetBundle CHLSLLoader::loadAsset(system::IFile* _file, const IAssetLoader::SA
3940
{".task.hlsl",IShader::E_SHADER_STAGE::ESS_TASK},
4041
};
4142
auto shaderStage = IShader::E_SHADER_STAGE::ESS_UNKNOWN;
42-
for (auto& it : typeFromExt) {
43+
for (auto& it : typeFromExt)
44+
{
4345
if (filenameEnding.size() <= it.first.size()) continue;
4446
auto stringPart = filenameEnding.substr(filenameEnding.size() - it.first.size());
4547
if (stringPart == it.first)
@@ -49,9 +51,6 @@ SAssetBundle CHLSLLoader::loadAsset(system::IFile* _file, const IAssetLoader::SA
4951
}
5052
}
5153

52-
// TODO: allocate the source as an ICPUBuffer right away!
53-
auto shader = core::make_smart_refctd_ptr<ICPUShader>(reinterpret_cast<char*>(source), shaderStage, IShader::E_CONTENT_TYPE::ECT_HLSL, filename.string());
54-
_NBL_ALIGNED_FREE(source);
55-
56-
return SAssetBundle(nullptr,{std::move(shader)});
54+
source->setContentHash(source->computeContentHash());
55+
return SAssetBundle(nullptr,{core::make_smart_refctd_ptr<ICPUShader>(std::move(source), shaderStage, IShader::E_CONTENT_TYPE::ECT_HLSL, filename.string())});
5756
}

src/nbl/asset/interchange/CSPVLoader.cpp

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,40 @@ inline IShader::E_SHADER_STAGE getShaderStageFromSPIRVCrossExecutionModel(spv::E
2121
IShader::E_SHADER_STAGE shaderStage;
2222
switch (model)
2323
{
24-
case spv::ExecutionModelVertex:
25-
shaderStage = IShader::E_SHADER_STAGE::ESS_VERTEX; break;
26-
case spv::ExecutionModelTessellationControl:
27-
shaderStage = IShader::E_SHADER_STAGE::ESS_TESSELLATION_CONTROL; break;
28-
case spv::ExecutionModelTessellationEvaluation:
29-
shaderStage = IShader::E_SHADER_STAGE::ESS_TESSELLATION_EVALUATION; break;
30-
case spv::ExecutionModelGeometry:
31-
shaderStage = IShader::E_SHADER_STAGE::ESS_GEOMETRY; break;
32-
case spv::ExecutionModelFragment:
33-
shaderStage = IShader::E_SHADER_STAGE::ESS_FRAGMENT; break;
34-
case spv::ExecutionModelGLCompute:
35-
shaderStage = IShader::E_SHADER_STAGE::ESS_COMPUTE; break;
36-
case spv::ExecutionModelTaskNV:
37-
shaderStage = IShader::E_SHADER_STAGE::ESS_TASK; break;
38-
case spv::ExecutionModelMeshNV:
39-
shaderStage = IShader::E_SHADER_STAGE::ESS_MESH; break;
40-
case spv::ExecutionModelRayGenerationKHR:
41-
shaderStage = IShader::E_SHADER_STAGE::ESS_RAYGEN; break;
42-
case spv::ExecutionModelIntersectionKHR:
43-
shaderStage = IShader::E_SHADER_STAGE::ESS_INTERSECTION; break;
44-
case spv::ExecutionModelAnyHitKHR:
45-
shaderStage = IShader::E_SHADER_STAGE::ESS_ANY_HIT; break;
46-
case spv::ExecutionModelClosestHitKHR:
47-
shaderStage = IShader::E_SHADER_STAGE::ESS_MISS; break;
48-
case spv::ExecutionModelMissKHR:
49-
shaderStage = IShader::E_SHADER_STAGE::ESS_MISS; break;
50-
case spv::ExecutionModelCallableKHR:
51-
shaderStage = IShader::E_SHADER_STAGE::ESS_CALLABLE; break;
52-
case spv::ExecutionModelKernel:
53-
case spv::ExecutionModelMax:
54-
default:
55-
assert(!"Shader stage not supported!");
56-
shaderStage = IShader::E_SHADER_STAGE::ESS_UNKNOWN;
57-
break;
24+
case spv::ExecutionModelVertex:
25+
shaderStage = IShader::E_SHADER_STAGE::ESS_VERTEX; break;
26+
case spv::ExecutionModelTessellationControl:
27+
shaderStage = IShader::E_SHADER_STAGE::ESS_TESSELLATION_CONTROL; break;
28+
case spv::ExecutionModelTessellationEvaluation:
29+
shaderStage = IShader::E_SHADER_STAGE::ESS_TESSELLATION_EVALUATION; break;
30+
case spv::ExecutionModelGeometry:
31+
shaderStage = IShader::E_SHADER_STAGE::ESS_GEOMETRY; break;
32+
case spv::ExecutionModelFragment:
33+
shaderStage = IShader::E_SHADER_STAGE::ESS_FRAGMENT; break;
34+
case spv::ExecutionModelGLCompute:
35+
shaderStage = IShader::E_SHADER_STAGE::ESS_COMPUTE; break;
36+
case spv::ExecutionModelTaskNV:
37+
shaderStage = IShader::E_SHADER_STAGE::ESS_TASK; break;
38+
case spv::ExecutionModelMeshNV:
39+
shaderStage = IShader::E_SHADER_STAGE::ESS_MESH; break;
40+
case spv::ExecutionModelRayGenerationKHR:
41+
shaderStage = IShader::E_SHADER_STAGE::ESS_RAYGEN; break;
42+
case spv::ExecutionModelIntersectionKHR:
43+
shaderStage = IShader::E_SHADER_STAGE::ESS_INTERSECTION; break;
44+
case spv::ExecutionModelAnyHitKHR:
45+
shaderStage = IShader::E_SHADER_STAGE::ESS_ANY_HIT; break;
46+
case spv::ExecutionModelClosestHitKHR:
47+
shaderStage = IShader::E_SHADER_STAGE::ESS_MISS; break;
48+
case spv::ExecutionModelMissKHR:
49+
shaderStage = IShader::E_SHADER_STAGE::ESS_MISS; break;
50+
case spv::ExecutionModelCallableKHR:
51+
shaderStage = IShader::E_SHADER_STAGE::ESS_CALLABLE; break;
52+
case spv::ExecutionModelKernel:
53+
case spv::ExecutionModelMax:
54+
default:
55+
assert(!"Shader stage not supported!");
56+
shaderStage = IShader::E_SHADER_STAGE::ESS_UNKNOWN;
57+
break;
5858
}
5959
return shaderStage;
6060
}
@@ -80,5 +80,6 @@ SAssetBundle CSPVLoader::loadAsset(system::IFile* _file, const IAssetLoader::SAs
8080
const SPIRV_CROSS_NAMESPACE::ParsedIR& parsedIR = parser.get_parsed_ir();
8181
SPIRV_CROSS_NAMESPACE::SPIREntryPoint defaultEntryPoint = parsedIR.entry_points.at(parsedIR.default_entry_point);
8282

83+
buffer->setContentHash(buffer->computeContentHash());
8384
return SAssetBundle(nullptr,{core::make_smart_refctd_ptr<ICPUShader>(std::move(buffer), getShaderStageFromSPIRVCrossExecutionModel(defaultEntryPoint.model), asset::IShader::E_CONTENT_TYPE::ECT_SPIRV, _file->getFileName().string())});
8485
}

0 commit comments

Comments
 (0)