Finalize struct gen for structured buffers. Rename buffer builtins.

This commit is contained in:
2025-09-29 20:55:27 +02:00
parent 63a68b70b4
commit 2e23b37405
12 changed files with 25 additions and 20 deletions

View File

@@ -1094,16 +1094,16 @@ declare_buffer :: (checker : *Checker, node : *AST_Node) -> Type_Variable_Handle
return 0; return 0;
} }
buffer_struct_name := sprint("%_buffer_substruct___%", random_get(), node.name); buffer_struct_name := sprint("__buffer_substruct__%_%", random_get(), node.name);
variable.element_type = declare_struct(checker, node, buffer_struct_name); // Won't work entirely like this. At least we're going to need some access changes variable.element_type = declare_struct(checker, node, buffer_struct_name);
variable.resource_index = checker.current_buffer_index; variable.resource_index = checker.current_texture_index;
element := from_handle(checker, variable.element_type); element := from_handle(checker, variable.element_type);
scope := get_scope(checker, element.scope); scope := get_scope(checker, element.scope);
scope.builtin = true; scope.builtin = true;
variable.scope = element.scope; variable.scope = element.scope;
checker.current_buffer_index += 1; checker.current_texture_index += 1;
node.type_variable = handle; node.type_variable = handle;

View File

@@ -526,8 +526,13 @@ emit_field_list :: (state : *Codegen_State, field_list : *AST_Node, indentation
} }
} }
emit_struct :: (state : *Codegen_State, node : *AST_Node, indentation : int) { emit_struct :: (state : *Codegen_State, node : *AST_Node, indentation : int, name : string = "") {
print_to_builder(*state.builder, "struct %", node.name); if name.count > 0 {
print_to_builder(*state.builder, "struct %", name);
} else {
print_to_builder(*state.builder, "struct %", node.name);
}
current_scope := state.current_scope; current_scope := state.current_scope;
state.current_scope = from_handle(state.ctx.type_variables, node.type_variable).scope; state.current_scope = from_handle(state.ctx.type_variables, node.type_variable).scope;
@@ -571,10 +576,10 @@ emit_buffer :: (state : *Codegen_State, node : *AST_Node, indentation : int) {
variable := from_handle(state.ctx.type_variables, node.type_variable); variable := from_handle(state.ctx.type_variables, node.type_variable);
element := from_handle(state.ctx.type_variables, variable.element_type); element := from_handle(state.ctx.type_variables, variable.element_type);
emit_struct(state, node, indentation); emit_struct(state, node, indentation, element.typename);
// print_to_builder(*state.builder, "struct %\n", element.name); // print_to_builder(*state.builder, "struct %\n", element.name);
print_to_builder(*state.builder, "StructuredBuffer<%> %;\n\n", element.typename, variable.name); print_to_builder(*state.builder, "StructuredBuffer<%> % : register(t%);\n\n", element.typename, variable.name, variable.resource_index);
} }

View File

@@ -217,11 +217,11 @@ identifier_kind :: (using lexer : *Lexer) -> Token_Kind {
identifier.count = length; identifier.count = length;
if identifier == "bool" return .TOKEN_BOOL; if identifier == "bool" return .TOKEN_BOOL;
if identifier == "buffer" return .TOKEN_BUFFER; if identifier == "Buffer" return .TOKEN_BUFFER;
if identifier == "case" return .TOKEN_CASE; if identifier == "case" return .TOKEN_CASE;
if identifier == "columnmajor" return .TOKEN_COLUMNMAJOR; if identifier == "columnmajor" return .TOKEN_COLUMNMAJOR;
if identifier == "const" return .TOKEN_CONST; if identifier == "const" return .TOKEN_CONST;
if identifier == "constant_buffer" return .TOKEN_CONSTANT_BUFFER; if identifier == "Constant_Buffer" return .TOKEN_CONSTANT_BUFFER;
if identifier == "continue" return .TOKEN_CONTINUE; if identifier == "continue" return .TOKEN_CONTINUE;
if identifier == "default" return .TOKEN_DEFAULT; if identifier == "default" return .TOKEN_DEFAULT;
if identifier == "directive" return .TOKEN_DIRECTIVE; if identifier == "directive" return .TOKEN_DIRECTIVE;

View File

@@ -1,4 +1,4 @@
properties :: constant_buffer @properties { properties :: Constant_Buffer @properties {
color : float4; color : float4;
} }

View File

@@ -1,8 +1,8 @@
property_buffer :: buffer { property_buffer :: Buffer {
color : float4; color : float4;
} }
const_buffer :: constant_buffer { const_buffer :: Constant_Buffer {
color : float4; color : float4;
} }

View File

@@ -1,4 +1,4 @@
camera :: constant_buffer { camera :: Constant_Buffer {
projection : float4x4; projection : float4x4;
view : float4x4; view : float4x4;
} }

View File

@@ -1,4 +1,4 @@
p :: constant_buffer { p :: Constant_Buffer {
v : float2; v : float2;
} }

View File

@@ -1,4 +1,4 @@
p :: constant_buffer @properties { p :: Constant_Buffer @properties {
color : float4; color : float4;
rect_position : float2; rect_position : float2;
rect_scale : float2; rect_scale : float2;

View File

@@ -1,6 +1,6 @@
{kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 10 line = 1 ; column = 0 ; value ='properties'; } {kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 10 line = 1 ; column = 0 ; value ='properties'; }
{kind = TOKEN_DOUBLECOLON; ; index = 11 ; length = 2 line = 1 ; column = 11 ; value ='::'; } {kind = TOKEN_DOUBLECOLON; ; index = 11 ; length = 2 line = 1 ; column = 11 ; value ='::'; }
{kind = TOKEN_CONSTANT_BUFFER; ; index = 14 ; length = 15 line = 1 ; column = 14 ; value ='constant_buffer'; } {kind = TOKEN_CONSTANT_BUFFER; ; index = 14 ; length = 15 line = 1 ; column = 14 ; value ='Constant_Buffer'; }
{kind = TOKEN_AT; ; index = 30 ; length = 1 line = 1 ; column = 30 ; value ='@'; } {kind = TOKEN_AT; ; index = 30 ; length = 1 line = 1 ; column = 30 ; value ='@'; }
{kind = TOKEN_IDENTIFIER; ; index = 31 ; length = 10 line = 1 ; column = 31 ; value ='properties'; } {kind = TOKEN_IDENTIFIER; ; index = 31 ; length = 10 line = 1 ; column = 31 ; value ='properties'; }
{kind = TOKEN_LEFTBRACE; ; index = 42 ; length = 1 line = 1 ; column = 42 ; value ='{'; } {kind = TOKEN_LEFTBRACE; ; index = 42 ; length = 1 line = 1 ; column = 42 ; value ='{'; }

View File

@@ -1,6 +1,6 @@
{kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 6 line = 1 ; column = 0 ; value ='camera'; } {kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 6 line = 1 ; column = 0 ; value ='camera'; }
{kind = TOKEN_DOUBLECOLON; ; index = 7 ; length = 2 line = 1 ; column = 7 ; value ='::'; } {kind = TOKEN_DOUBLECOLON; ; index = 7 ; length = 2 line = 1 ; column = 7 ; value ='::'; }
{kind = TOKEN_CONSTANT_BUFFER; ; index = 10 ; length = 15 line = 1 ; column = 10 ; value ='constant_buffer'; } {kind = TOKEN_CONSTANT_BUFFER; ; index = 10 ; length = 15 line = 1 ; column = 10 ; value ='Constant_Buffer'; }
{kind = TOKEN_LEFTBRACE; ; index = 26 ; length = 1 line = 1 ; column = 26 ; value ='{'; } {kind = TOKEN_LEFTBRACE; ; index = 26 ; length = 1 line = 1 ; column = 26 ; value ='{'; }
{kind = TOKEN_IDENTIFIER; ; index = 30 ; length = 10 line = 2 ; column = 0 ; value ='projection'; } {kind = TOKEN_IDENTIFIER; ; index = 30 ; length = 10 line = 2 ; column = 0 ; value ='projection'; }
{kind = TOKEN_COLON; ; index = 41 ; length = 1 line = 2 ; column = 11 ; value =':'; } {kind = TOKEN_COLON; ; index = 41 ; length = 1 line = 2 ; column = 11 ; value =':'; }

View File

@@ -1,6 +1,6 @@
{kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 1 line = 1 ; column = 0 ; value ='p'; } {kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 1 line = 1 ; column = 0 ; value ='p'; }
{kind = TOKEN_DOUBLECOLON; ; index = 2 ; length = 2 line = 1 ; column = 2 ; value ='::'; } {kind = TOKEN_DOUBLECOLON; ; index = 2 ; length = 2 line = 1 ; column = 2 ; value ='::'; }
{kind = TOKEN_CONSTANT_BUFFER; ; index = 5 ; length = 15 line = 1 ; column = 5 ; value ='constant_buffer'; } {kind = TOKEN_IDENTIFIER; ; index = 5 ; length = 15 line = 1 ; column = 5 ; value ='constant_buffer'; }
{kind = TOKEN_LEFTBRACE; ; index = 21 ; length = 1 line = 1 ; column = 21 ; value ='{'; } {kind = TOKEN_LEFTBRACE; ; index = 21 ; length = 1 line = 1 ; column = 21 ; value ='{'; }
{kind = TOKEN_IDENTIFIER; ; index = 25 ; length = 1 line = 2 ; column = 0 ; value ='v'; } {kind = TOKEN_IDENTIFIER; ; index = 25 ; length = 1 line = 2 ; column = 0 ; value ='v'; }
{kind = TOKEN_COLON; ; index = 27 ; length = 1 line = 2 ; column = 2 ; value =':'; } {kind = TOKEN_COLON; ; index = 27 ; length = 1 line = 2 ; column = 2 ; value =':'; }

View File

@@ -1,6 +1,6 @@
{kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 1 line = 1 ; column = 0 ; value ='p'; } {kind = TOKEN_IDENTIFIER; ; index = 0 ; length = 1 line = 1 ; column = 0 ; value ='p'; }
{kind = TOKEN_DOUBLECOLON; ; index = 2 ; length = 2 line = 1 ; column = 2 ; value ='::'; } {kind = TOKEN_DOUBLECOLON; ; index = 2 ; length = 2 line = 1 ; column = 2 ; value ='::'; }
{kind = TOKEN_CONSTANT_BUFFER; ; index = 5 ; length = 15 line = 1 ; column = 5 ; value ='constant_buffer'; } {kind = TOKEN_IDENTIFIER; ; index = 5 ; length = 15 line = 1 ; column = 5 ; value ='constant_buffer'; }
{kind = TOKEN_AT; ; index = 21 ; length = 1 line = 1 ; column = 21 ; value ='@'; } {kind = TOKEN_AT; ; index = 21 ; length = 1 line = 1 ; column = 21 ; value ='@'; }
{kind = TOKEN_IDENTIFIER; ; index = 22 ; length = 10 line = 1 ; column = 22 ; value ='properties'; } {kind = TOKEN_IDENTIFIER; ; index = 22 ; length = 10 line = 1 ; column = 22 ; value ='properties'; }
{kind = TOKEN_LEFTBRACE; ; index = 33 ; length = 1 line = 1 ; column = 33 ; value ='{'; } {kind = TOKEN_LEFTBRACE; ; index = 33 ; length = 1 line = 1 ; column = 33 ; value ='{'; }