Skip to content

Commit

Permalink
Move dynamic buffers into a separate descriptor table
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Oct 5, 2024
1 parent b917239 commit 87f08b0
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions Sources/backends/hlsl.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,20 @@ static void write_root_signature(char *hlsl, size_t *offset) {

bool has_sampler = false;
bool has_other = false;
bool has_dynamic = false;

for (size_t definition_index = 0; definition_index < set->definitions_count; ++definition_index) {
definition *def = &set->definitions[definition_index];

switch (def->kind) {
case DEFINITION_CONST_CUSTOM:
if (has_attribute(&get_global(def->global)->attributes, add_name("indexed"))) {
has_dynamic = true;
}
else {
has_other = true;
}
break;
case DEFINITION_TEX2D:
case DEFINITION_TEX2DARRAY:
case DEFINITION_TEXCUBE:
Expand All @@ -415,14 +423,16 @@ static void write_root_signature(char *hlsl, size_t *offset) {

switch (def->kind) {
case DEFINITION_CONST_CUSTOM:
if (first) {
first = false;
}
else {
*offset += sprintf(&hlsl[*offset], ", ");
if (!has_attribute(&get_global(def->global)->attributes, add_name("indexed"))) {
if (first) {
first = false;
}
else {
*offset += sprintf(&hlsl[*offset], ", ");
}
*offset += sprintf(&hlsl[*offset], "CBV(b%i)", cbv_index);
cbv_index += 1;
}
*offset += sprintf(&hlsl[*offset], "CBV(b%i)", cbv_index);
cbv_index += 1;
break;
case DEFINITION_TEX2D:
case DEFINITION_TEX2DARRAY:
Expand Down Expand Up @@ -451,6 +461,32 @@ static void write_root_signature(char *hlsl, size_t *offset) {
*offset += sprintf(&hlsl[*offset], ")");
}

if (has_dynamic) {
*offset += sprintf(&hlsl[*offset], "\\\n, DescriptorTable(");

bool first = true;
for (size_t definition_index = 0; definition_index < set->definitions_count; ++definition_index) {
definition *def = &set->definitions[definition_index];

switch (def->kind) {
case DEFINITION_CONST_CUSTOM:
if (has_attribute(&get_global(def->global)->attributes, add_name("indexed"))) {
if (first) {
first = false;
}
else {
*offset += sprintf(&hlsl[*offset], ", ");
}
*offset += sprintf(&hlsl[*offset], "CBV(b%i)", cbv_index);
cbv_index += 1;
}
break;
}
}

*offset += sprintf(&hlsl[*offset], ")");
}

if (has_sampler) {
*offset += sprintf(&hlsl[*offset], "\\\n, DescriptorTable(");

Expand Down

0 comments on commit 87f08b0

Please sign in to comment.