diff --git a/Sources/backends/hlsl.c b/Sources/backends/hlsl.c index 69f3ad1..5acd9fe 100644 --- a/Sources/backends/hlsl.c +++ b/Sources/backends/hlsl.c @@ -507,6 +507,28 @@ static void write_root_signature(char *hlsl, size_t *offset) { *offset += sprintf(&hlsl[*offset], ")"); } + if (has_boundless) { + uint32_t boundless_space = 1; + for (size_t definition_index = 0; definition_index < set->definitions_count; ++definition_index) { + definition *def = &set->definitions[definition_index]; + + switch (def->kind) { + case DEFINITION_TEX2D: + case DEFINITION_TEX2DARRAY: + case DEFINITION_TEXCUBE: { + type *t = get_type(get_global(def->global)->type); + + if (t->kind == TYPE_ARRAY && t->array.array_size == -1) { + *offset += sprintf(&hlsl[*offset], "\\\n, DescriptorTable(SRV(t0, space = %i, numDescriptors = unbounded))", boundless_space); + boundless_space += 1; + } + + break; + } + } + } + } + if (has_sampler) { *offset += sprintf(&hlsl[*offset], "\\\n, DescriptorTable("); @@ -530,28 +552,6 @@ static void write_root_signature(char *hlsl, size_t *offset) { *offset += sprintf(&hlsl[*offset], ")"); } - - if (has_boundless) { - uint32_t boundless_space = 1; - for (size_t definition_index = 0; definition_index < set->definitions_count; ++definition_index) { - definition *def = &set->definitions[definition_index]; - - switch (def->kind) { - case DEFINITION_TEX2D: - case DEFINITION_TEX2DARRAY: - case DEFINITION_TEXCUBE: { - type *t = get_type(get_global(def->global)->type); - - if (t->kind == TYPE_ARRAY && t->array.array_size == -1) { - *offset += sprintf(&hlsl[*offset], "\\\n, DescriptorTable(SRV(t0, space = %i, numDescriptors = unbounded))", boundless_space); - boundless_space += 1; - } - - break; - } - } - } - } } *offset += sprintf(&hlsl[*offset], "\")]\n"); diff --git a/Sources/integrations/kope.c b/Sources/integrations/kope.c index f7d0fdb..c38fd7b 100644 --- a/Sources/integrations/kope.c +++ b/Sources/integrations/kope.c @@ -1019,6 +1019,7 @@ void kope_export(char *directory, api_kind api) { size_t other_count = 0; size_t sampler_count = 0; size_t dynamic_count = 0; + size_t bindless_count = 0; for (size_t descriptor_index = 0; descriptor_index < set->definitions_count; ++descriptor_index) { definition d = set->definitions[descriptor_index]; @@ -1032,17 +1033,24 @@ void kope_export(char *directory, api_kind api) { other_count += 1; } break; - CASE_TEXTURE: - other_count += 1; + CASE_TEXTURE: { + type *t = get_type(get_global(d.global)->type); + if (t->kind == TYPE_ARRAY && t->array.array_size == -1) { + bindless_count += 1; + } + else { + other_count += 1; + } break; + } case DEFINITION_SAMPLER: sampler_count += 1; break; } } - fprintf(output, "\tkope_d3d12_device_create_descriptor_set(device, %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", &set->set);\n", other_count, - dynamic_count, sampler_count); + fprintf(output, "\tkope_d3d12_device_create_descriptor_set(device, %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", &set->set);\n", other_count, + dynamic_count, bindless_count, sampler_count); size_t other_index = 0; size_t sampler_index = 0; @@ -1072,6 +1080,10 @@ void kope_export(char *directory, api_kind api) { get_name(get_global(d.global)->name)); fprintf(output, "\tassert(set->%s != NULL);\n", get_name(get_global(d.global)->name)); fprintf(output, "\tfor (size_t index = 0; index < parameters->textures_count; ++index) {\n"); + fprintf(output, + "\t\tkope_d3d12_descriptor_set_set_texture_view_srv(device, set->set.bindless_descriptor_allocation.offset + (uint32_t)index, " + "¶meters->%s[index]);\n", + get_name(get_global(d.global)->name)); fprintf(output, "\t\tset->%s[index] = parameters->%s[index];\n", get_name(get_global(d.global)->name), get_name(get_global(d.global)->name)); fprintf(output, "\t}\n"); @@ -1086,14 +1098,17 @@ void kope_export(char *directory, api_kind api) { get_name(get_global(d.global)->name), other_index); } else { - fprintf(output, "\tkope_d3d12_descriptor_set_set_texture_view_srv(device, &set->set, ¶meters->%s, %" PRIu64 ");\n", - get_name(get_global(d.global)->name), other_index); + fprintf(output, + "\tkope_d3d12_descriptor_set_set_texture_view_srv(device, set->set.descriptor_allocation.offset + %" PRIu64 + ", ¶meters->%s);\n", + other_index, get_name(get_global(d.global)->name)); } fprintf(output, "\tset->%s = parameters->%s;\n", get_name(get_global(d.global)->name), get_name(get_global(d.global)->name)); + + other_index += 1; } - other_index += 1; break; } case DEFINITION_TEX2DARRAY: {