From ba1e7824aed9c51af98e7eda2772c542ddb971fb Mon Sep 17 00:00:00 2001 From: Robert Konrad Date: Tue, 10 Sep 2024 10:22:09 +0200 Subject: [PATCH] Support more Kope descriptor types --- Sources/integrations/kope.c | 50 ++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/Sources/integrations/kope.c b/Sources/integrations/kope.c index 8a2a91f..0912367 100644 --- a/Sources/integrations/kope.c +++ b/Sources/integrations/kope.c @@ -281,6 +281,7 @@ void kope_export(char *directory, api_kind api) { fprintf(output, "#define KONG_INTEGRATION_HEADER\n\n"); fprintf(output, "#include \n"); + fprintf(output, "#include \n"); fprintf(output, "#include \n"); fprintf(output, "#include \n"); fprintf(output, "#include \n"); @@ -358,7 +359,7 @@ void kope_export(char *directory, api_kind api) { fprintf(output, "\tkope_g5_texture *%s;\n", get_name(get_global(d.global)->name)); break; case DEFINITION_SAMPLER: - fprintf(output, "\tkope_g5_texture *%s;\n", get_name(get_global(d.global)->name)); + fprintf(output, "\tkope_g5_sampler *%s;\n", get_name(get_global(d.global)->name)); break; default: { debug_context context = {0}; @@ -573,10 +574,51 @@ void kope_export(char *directory, api_kind api) { fprintf(output, "void kong_create_%s_set(kope_g5_device *device, const %s_parameters *parameters, %s_set *set) {\n", get_name(set->name), get_name(set->name), get_name(set->name)); - fprintf(output, "\tkope_d3d12_device_create_descriptor_set(device, %" PRIu64 ", &set->set);\n", set->definitions_count); + + size_t other_count = 0; + size_t sampler_count = 0; + + for (size_t descriptor_index = 0; descriptor_index < set->definitions_count; ++descriptor_index) { + definition d = set->definitions[descriptor_index]; + + switch (d.kind) { + case DEFINITION_CONST_CUSTOM: + other_count += 1; + break; + case DEFINITION_TEX2D: + other_count += 1; + break; + case DEFINITION_SAMPLER: + sampler_count += 1; + break; + } + } + + fprintf(output, "\tkope_d3d12_device_create_descriptor_set(device, %" PRIu64 ", %" PRIu64 ", &set->set);\n", other_count, sampler_count); + + size_t other_index = 0; + size_t sampler_index = 0; + for (size_t descriptor_index = 0; descriptor_index < set->definitions_count; ++descriptor_index) { - fprintf(output, "\tkope_d3d12_descriptor_set_set_buffer_view_cbv(device, &set->set, parameters->%s, %" PRIu64 ");\n", - get_name(get_global(set->definitions[descriptor_index].global)->name), descriptor_index); + definition d = set->definitions[descriptor_index]; + + switch (d.kind) { + case DEFINITION_CONST_CUSTOM: + fprintf(output, "\tkope_d3d12_descriptor_set_set_buffer_view_cbv(device, &set->set, parameters->%s, %" PRIu64 ");\n", + get_name(get_global(d.global)->name), other_index); + other_index += 1; + break; + case DEFINITION_TEX2D: + fprintf(output, "\tkope_d3d12_descriptor_set_set_texture_view_srv(device, &set->set, parameters->%s, %" PRIu64 ");\n", + get_name(get_global(d.global)->name), other_index); + other_index += 1; + break; + case DEFINITION_SAMPLER: + fprintf(output, "\tkope_d3d12_descriptor_set_set_sampler(device, &set->set, parameters->%s, %" PRIu64 ");\n", + get_name(get_global(d.global)->name), sampler_index); + sampler_index += 1; + break; + } } fprintf(output, "}\n\n");