Fix lvalue/rvalue binaries. Fix structured buffer output.

This commit is contained in:
2025-09-29 22:22:00 +02:00
parent 2e23b37405
commit 0c0e31db38
23 changed files with 244 additions and 103 deletions

View File

@@ -128,7 +128,13 @@ Entry_Point :: struct {
return_value : Field;
}
Constant_Buffer :: struct {
Buffer_Kind :: enum {
Constant;
Structured;
}
Buffer :: struct {
kind : Buffer_Kind;
name : string;
fields : Static_Array(Field, 16);
@@ -154,8 +160,8 @@ Compiler_Context :: struct {
codegen_result_text : string;
constant_buffers : Static_Array(Type_Variable_Handle, 16);
buffers : Static_Array(Type_Variable_Handle, 16);
typed_buffers : Static_Array(Type_Variable_Handle, 32);
// structured_buffers : Static_Array(Type_Variable_Handle, 16);
scope_stack : Scope_Stack;
type_variables : [..]Type_Variable;
@@ -172,9 +178,9 @@ Compiler_Context :: struct {
return_value : Field;
}
max_constant_buffers :: 16;
max_buffers :: 32;
cbuffers : Static_Array(Constant_Buffer, max_constant_buffers);
buffers : Static_Array(Buffer, max_buffers);
had_error : bool;
messages : [..]Compiler_Message;
@@ -403,6 +409,37 @@ type_variable_to_field :: (ctx : *Compiler_Context, variable : Type_Variable_Han
return type_variable_to_field(ctx, from_handle(ctx.type_variables, variable));
}
generate_buffer :: (ctx : *Compiler_Context, type_handle : Type_Variable_Handle, buffers : *Static_Array) {
variable := from_handle(ctx.type_variables, type_handle);
buffer := array_add(buffers);
if variable.type == {
case .CBuffer; {
buffer.kind = .Constant;
}
case .Buffer; {
buffer.kind = .Structured;
}
}
buffer.name = variable.name;
for i : 0..variable.children.count - 1 {
child := variable.children[i];
field : Field = type_variable_to_field(ctx, from_handle(ctx.type_variables, child));
array_add(*buffer.fields, field);
}
buffer.buffer_index = variable.resource_index;
for hint : variable.source_node.hint_tokens {
field_hint : Field_Hint;
field_hint.custom_hint_name = hint.ident_value;
field_hint.kind = .Custom;
array_add(*buffer.hints, field_hint);
}
}
generate_output_data :: (ctx : *Compiler_Context) {
if ctx.had_error {
return;
@@ -427,26 +464,8 @@ generate_output_data :: (ctx : *Compiler_Context) {
}
}
for buffer_variable : ctx.constant_buffers {
variable := from_handle(ctx.type_variables, buffer_variable);
cb := array_add(*ctx.cbuffers);
cb.name = variable.name;
for i : 0..variable.children.count - 1 {
child := variable.children[i];
field : Field = type_variable_to_field(ctx, from_handle(ctx.type_variables, child));
array_add(*cb.fields, field);
}
cb.buffer_index = variable.resource_index;
for hint : variable.source_node.hint_tokens {
field_hint : Field_Hint;
field_hint.custom_hint_name = hint.ident_value;
field_hint.kind = .Custom;
array_add(*cb.hints, field_hint);
}
for buffer_variable : ctx.typed_buffers {
generate_buffer(ctx, buffer_variable, *ctx.buffers);
}
if ctx.pixel_entry_point.node {