diff --git a/README.md b/README.md index 51e5624..61c7c18 100644 --- a/README.md +++ b/README.md @@ -20,15 +20,15 @@ There is basic support for most HLSL built-in math functions for the following t - Vector types: float2, float3, float4, int2, int3, int4 - Matrices: float4x4 All of the above can be constructed with their namesake constructors i.e. `float4(x, y, z, w);`. -We don't yet support textures and samplers. +We also support Samplers and Texture2D If you want to declare and use variables you can do it as follows ```hlsl x : float = 2.0; // no 'f' suffix required or even supported (it gives an error) y : float = 4.0; v : float2 = float2(x, y); +v2 := float2(x, y); ``` -For now it is required to specify the type of the variable (no type inference). You can also do arithmetic as you would expect ``` @@ -43,6 +43,7 @@ Camera_Data :: struct { } ``` And there is a special struct called `properties`, which is used for custom data you want to pass in. +#### ** Note: Properties will likely be deprecated, since the language now supports `@` hints to easily mark buffers and values with metadata.** ```hlsl properties { projection : float4x4; @@ -53,13 +54,14 @@ which will be exposed in the compiled result. `properties` can be renamed to a c ``` p :: properties { ... -} + + ``` You can also define constant buffers ``` -camera :: Constant_Buffer { +camera :: constant_buffer { projection : float4x4; view : float4x4; } @@ -70,69 +72,68 @@ camera :: Constant_Buffer { To compile a shader and use the result, you can do the following in jai ```jai -parse_shader :: (path : string, allocator : Allocator) -> Compilation_Result { - // In the future, you can pass environment defines to the compiler. - compiler : Shader_Compiler; - - return compile_file(*compiler, path,, allocator); -} +// In the future, you can pass environment defines to the compiler. +ctx : Compiler_Context; +compile_file(*compiler, "shader.shd", allocator); -result := parse_shader("shader.shd", allocator); -if result.had_error { - log_error("%\n", report_messages(result.messages),, temp); +if ctx.had_error { + log_error("%\n", report_messages(ctx.messages),, temp); return; } -collection := result.collection; -variant := collection.variants[0]; -} +// The ctx now contains all the needed information like the source text, entry points, constant buffers etc. ``` When parsing a shader you get the following struct as a result ``` -Compilation_Result :: struct { - messages : [..]Compiler_Message; +Compiler_Context :: struct { + file : Input_File; - had_error : bool; + environment : Environment; + + tokens : [..]Token;; + root : *AST_Node; + nodes : [..]AST_Node; - collection : Shader_Variant_Collection; -} -``` + codegen_result_text : string; -A `Shader_Variant_Collection` looks as follows -``` -Shader_Variant_Collection :: struct { - properties : Properties; + constant_buffers : Static_Array(Type_Variable_Handle, 16); - max_constant_buffers :: 16; - cbuffers : Static_Array(Constant_Buffer, max_constant_buffers); + scope_stack : Scope_Stack; + type_variables : [..]Type_Variable; - variants : [..]Shader_Variant; -} - -Shader_Variant :: struct { - text : string; + property_name : string; vertex_entry_point : struct { + node : *AST_Node; name : string; - input : [..]Field; } pixel_entry_point : struct { + node : *AST_Node; name : string; - return_value : Field; } + + properties : Properties; + + max_constant_buffers :: 16; + + cbuffers : Static_Array(Constant_Buffer, max_constant_buffers); + + had_error : bool; + messages : [..]Compiler_Message; } Constant_Buffer :: struct { - register : int; - name : string; fields : Static_Array(Property_Field, 16); + // hints : Field_Hint; // optional hint... + hints : [..]Field_Hint; + buffer_index : u32; } @@ -192,11 +193,10 @@ Hint_Kind :: enum { ## Notable missing features -- Control flow: if/else, for, while, switch etc. +- While - Arrays -- Textures and samplers - Multiple render targets - Custom buffers/structured buffers - Interpolation specifiers - Proper variant handling with environment defines -- Include/importing files such as shared utils etc. \ No newline at end of file +- Importing files such as shared utils etc. with something other than textual `#load` \ No newline at end of file diff --git a/module.jai b/module.jai index bc3aa0f..89d69fd 100644 --- a/module.jai +++ b/module.jai @@ -81,22 +81,6 @@ Entry_Point :: struct { return_value : Field; } -Shader_Variant :: struct { - text : string; - - vertex_entry_point : struct { - name : string; - - input : [..]Field; - } - - pixel_entry_point : struct { - name : string; - - return_value : Field; - } -} - Property_Field :: struct { base_field : Field; @@ -111,8 +95,6 @@ Properties :: struct { } Constant_Buffer :: struct { - register : int; - name : string; fields : Static_Array(Property_Field, 16); @@ -167,7 +149,7 @@ Compiler_Context :: struct { return_value : Field; } - properties : Properties; + properties : Properties; //@Note(niels): We'll deprecate this in favor of just marking a constant buffer how you'd want to use it max_constant_buffers :: 16;