Skip to content

Commit

Permalink
fix set order mess up
Browse files Browse the repository at this point in the history
  • Loading branch information
martty committed Dec 31, 2024
1 parent 233a7c0 commit da5b220
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 40 deletions.
1 change: 1 addition & 0 deletions include/vuk/runtime/vk/Program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ namespace vuk {

private:
void flatten_bindings();
Descriptors& ensure_set(size_t set_index);
};

struct ShaderModule {
Expand Down
66 changes: 26 additions & 40 deletions src/runtime/vk/Program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,16 @@ namespace vuk {
}
}

Program::Descriptors& Program::ensure_set(size_t set) {
if (set >= sets.size()) {
sets.resize(set + 1, std::nullopt);
}
if (!sets[set]) {
sets[set] = Descriptors{};
}
return *sets[set];
}

VkShaderStageFlagBits Program::introspect(const uint32_t* ir, size_t word_count) {
spirv_cross::Compiler refl(ir, word_count);
auto resources = refl.get_shader_resources();
Expand Down Expand Up @@ -249,11 +259,8 @@ namespace vuk {
reflect_members(refl, refl.get_type(ub.type_id), un.members);
}
un.size = refl.get_declared_struct_size(type);
if (set >= sets.size()) {
sets.resize(set + 1, std::nullopt);
sets[set] = Descriptors{};
}
sets[set]->bindings.push_back(un);

ensure_set(set).bindings.push_back(un);
}

for (auto& sb : resources.storage_buffers) {
Expand All @@ -275,11 +282,8 @@ namespace vuk {
un.is_hlsl_counter_buffer = refl.buffer_is_hlsl_counter_buffer(sb.id);
un.non_writable = refl.get_decoration(sb.id, spv::DecorationNonWritable);
un.non_readable = refl.get_decoration(sb.id, spv::DecorationNonReadable);
if (set >= sets.size()) {
sets.resize(set + 1, std::nullopt);
sets[set] = Descriptors{};
}
sets[set]->bindings.push_back(un);

ensure_set(set).bindings.push_back(un);
}

for (auto& si : resources.sampled_images) {
Expand All @@ -293,11 +297,8 @@ namespace vuk {
// maybe spirv cross bug?
t.array_size = type.array.size() == 1 ? (type.array[0] == 1 ? 0 : type.array[0]) : -1;
t.shadow = type.image.depth;
if (set >= sets.size()) {
sets.resize(set + 1, std::nullopt);
sets[set] = Descriptors{};
}
sets[set]->bindings.push_back(t);

ensure_set(set).bindings.push_back(t);
}

for (auto& sa : resources.separate_samplers) {
Expand All @@ -311,11 +312,8 @@ namespace vuk {
// maybe spirv cross bug?
t.array_size = type.array.size() == 1 ? (type.array[0] == 1 ? 0 : type.array[0]) : -1;
t.shadow = type.image.depth;
if (set >= sets.size()) {
sets.resize(set + 1, std::nullopt);
sets[set] = Descriptors{};
}
sets[set]->bindings.push_back(t);

ensure_set(set).bindings.push_back(t);
}

for (auto& si : resources.separate_images) {
Expand All @@ -328,11 +326,8 @@ namespace vuk {
t.stage = stage;
// maybe spirv cross bug?
t.array_size = type.array.size() == 1 ? (type.array[0] == 1 ? 0 : type.array[0]) : -1;
if (set >= sets.size()) {
sets.resize(set + 1, std::nullopt);
sets[set] = Descriptors{};
}
sets[set]->bindings.push_back(t);

ensure_set(set).bindings.push_back(t);
}

for (auto& sb : resources.storage_images) {
Expand All @@ -347,11 +342,8 @@ namespace vuk {
un.non_readable = refl.get_decoration(sb.id, spv::DecorationNonReadable);
// maybe spirv cross bug?
un.array_size = type.array.size() == 1 ? (type.array[0] == 1 ? 0 : type.array[0]) : -1;
if (set >= sets.size()) {
sets.resize(set + 1, std::nullopt);
sets[set] = Descriptors{};
}
sets[set]->bindings.push_back(un);

ensure_set(set).bindings.push_back(un);
}

// subpass inputs
Expand All @@ -363,11 +355,8 @@ namespace vuk {
s.name = std::string(si.name.c_str());
s.binding = binding;
s.stage = stage;
if (set >= sets.size()) {
sets.resize(set + 1, std::nullopt);
sets[set] = Descriptors{};
}
sets[set]->bindings.push_back(s);

ensure_set(set).bindings.push_back(s);
}

// ASs
Expand All @@ -380,11 +369,8 @@ namespace vuk {
s.binding = binding;
s.stage = stage;
s.array_size = type.array.size() == 1 ? (type.array[0] == 1 ? 0 : type.array[0]) : -1;
if (set >= sets.size()) {
sets.resize(set + 1, std::nullopt);
sets[set] = Descriptors{};
}
sets[set]->bindings.push_back(s);

ensure_set(set).bindings.push_back(s);
}

for (auto& sc : refl.get_specialization_constants()) {
Expand Down

0 comments on commit da5b220

Please sign in to comment.