Deprecate properties. Use hinted cbuffers instead. This opens up to use a structured buffer in that way as well if you want instead.

This commit is contained in:
2025-09-17 12:31:37 +02:00
parent 7fefe0ecf6
commit 607a6a0bed
27 changed files with 518 additions and 629 deletions

View File

@@ -5,7 +5,6 @@
/////////////////////////////////////
//~ nbr: Codegen TODOs
//
// [ ] Prefix output of property values with __PROPERTIES so we don't get name clashes
Output_Language :: enum {
HLSL;
@@ -99,13 +98,6 @@ emit_field :: (state : *Codegen_State, node : *AST_Node, indentation : int) {
print_to_builder(*state.builder, "% ", hlsl_type_to_string(field));
if field.struct_field_parent {
parent_tv := from_handle(state.result.type_variables, field.struct_field_parent.type_variable);
if parent_tv.typename == "properties" {
append(*state.builder, "__PROPERTIES__");
}
}
print_to_builder(*state.builder, "%", node.name);
if field.type == .Sampler {
@@ -212,56 +204,6 @@ emit_call :: (state : *Codegen_State, node : *AST_Node, indentation : int) {
append(*state.builder, ")");
}
emit_properties :: (state : *Codegen_State, node : *AST_Node, indentation : int) {
find_result := find_symbol(state.result.scope_stack, ifx node.name.count > 0 then node.name else "properties", state.current_scope);
if !find_result {
message : Compiler_Message;
message.message_kind = .Internal_Error;
message.path = state.path;
message.message = "Attempting to generate undeclared properties buffer. This should never happen at this stage.";
array_add(*state.result.messages, message);
}
assert(find_result != null, "Attempting to generate undeclared properties buffer. This should never happen at this stage.");
variable := from_handle(state.result.type_variables, find_result.type_variable);
print_to_builder(*state.builder, "cbuffer __PROPERTIES : register(b%) \n{\n", variable.resource_index);
previous_scope := state.current_scope;
state.current_scope = variable.scope;
resources : Static_Array(*AST_Node, 8);
for child : node.children {
if child.kind == .FieldList {
for field : child.children {
tv := from_handle(state.result.type_variables, field.type_variable);
if tv.type == .Sampler || tv.type == .Texture2D {
array_add(*resources, field);
continue;
}
emit_node(state, field, 1);
append(*state.builder, ";\n");
}
}
}
append(*state.builder, "}\n\n");
for i : 0..resources.count - 1 {
resource := resources[i];
emit_node(state, resource, 0);
append(*state.builder, ";\n");
}
append(*state.builder, "\n");
state.current_scope = previous_scope;
}
emit_function :: (state : *Codegen_State, node : *AST_Node, indentation : int, emit_body := true) {
name := get_actual_function_name(node);
find_result := find_symbol(state.result.scope_stack, name, state.current_scope);
@@ -407,10 +349,7 @@ emit_node :: (state : *Codegen_State, node : *AST_Node, indentation : int) {
}
case .Float; {
print_to_builder(*state.builder, "%f", formatFloat(node.float_value, zero_removal=.ONE_ZERO_AFTER_DECIMAL));
}
case .Properties; {
}
}
case .Field; {
emit_field(state, node, indentation);
}
@@ -422,23 +361,11 @@ emit_node :: (state : *Codegen_State, node : *AST_Node, indentation : int) {
indent(*state.builder, indentation);
type_var := from_handle(state.result.type_variables, node.type_variable);
is_properties := type_var.typename == "properties";
if !is_properties {
if type_var.struct_field_parent {
parent_tv := from_handle(state.result.type_variables, type_var.struct_field_parent.type_variable);
if parent_tv.typename == "properties" {
append(*state.builder, "__PROPERTIES__");
}
}
print_to_builder(*state.builder, "%", node.name);
}
print_to_builder(*state.builder, "%", node.name);
if node.children.count > 0 {
if !is_properties {
append(*state.builder, ".");
}
append(*state.builder, ".");
emit_node(state, node.children[0], 0);
}
}
@@ -601,9 +528,6 @@ emit_declaration :: (state : *Codegen_State, node : *AST_Node) {
case .Function; {
emit_function(state, node, 0);
}
case .Properties; {
emit_properties(state, node, 0);
}
case .CBuffer; {
emit_cbuffer(state, node, 0);
}