-
-
Notifications
You must be signed in to change notification settings - Fork 39
Open
Description
Currently if you write a shader and then comment out one of the textures, the slot bindings will be mismatched/counted by CF's implementation. For example:
layout(set = 2, binding = 1) uniform sampler2D tex1;
layout(set = 2, binding = 2) uniform sampler2D tex2;
layout(set = 2, binding = 3) uniform sampler2D tex3;
And then comment one out:
layout(set = 2, binding = 1) uniform sampler2D tex1;
//layout(set = 2, binding = 2) uniform sampler2D tex2;
layout(set = 2, binding = 3) uniform sampler2D tex3;
The third texture will get "missed" by CF's implementation. A proper solution would probably require a refactor of CF_ShaderInternal
and potentially the glslang shader reflection to pull out shader slot bindings and store them in our own reflection structs.
This chunk of code can then use the new slot index instead of j
index for assignments:
// Bind images to all their respective slots.
int sampler_count = shader->image_names.count();
SDL_GPUTextureSamplerBinding* sampler_bindings = SDL_stack_alloc(SDL_GPUTextureSamplerBinding, sampler_count);
int found_image_count = 0;
for (int i = 0; found_image_count < sampler_count && i < material->fs.textures.count(); ++i) {
const char* image_name = material->fs.textures[i].name;
for (int j = 0; j < shader->image_names.size(); ++j) {
if (shader->image_names[j] == image_name) {
sampler_bindings[j].sampler = ((CF_TextureInternal*)material->fs.textures[i].handle.id)->sampler;
sampler_bindings[j].texture = ((CF_TextureInternal*)material->fs.textures[i].handle.id)->tex;
found_image_count++;
}
}
}
CF_ASSERT(found_image_count == sampler_count);
SDL_BindGPUFragmentSamplers(pass, 0, sampler_bindings, (Uint32)found_image_count);
Metadata
Metadata
Assignees
Labels
No labels