Update readme
This commit is contained in:
80
README.md
80
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
|
- Vector types: float2, float3, float4, int2, int3, int4
|
||||||
- Matrices: float4x4
|
- Matrices: float4x4
|
||||||
All of the above can be constructed with their namesake constructors i.e. `float4(x, y, z, w);`.
|
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
|
If you want to declare and use variables you can do it as follows
|
||||||
```hlsl
|
```hlsl
|
||||||
x : float = 2.0; // no 'f' suffix required or even supported (it gives an error)
|
x : float = 2.0; // no 'f' suffix required or even supported (it gives an error)
|
||||||
y : float = 4.0;
|
y : float = 4.0;
|
||||||
v : float2 = float2(x, y);
|
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
|
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.
|
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
|
```hlsl
|
||||||
properties {
|
properties {
|
||||||
projection : float4x4;
|
projection : float4x4;
|
||||||
@@ -53,13 +54,14 @@ which will be exposed in the compiled result. `properties` can be renamed to a c
|
|||||||
```
|
```
|
||||||
p :: properties {
|
p :: properties {
|
||||||
...
|
...
|
||||||
}
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also define constant buffers
|
You can also define constant buffers
|
||||||
|
|
||||||
```
|
```
|
||||||
camera :: Constant_Buffer {
|
camera :: constant_buffer {
|
||||||
projection : float4x4;
|
projection : float4x4;
|
||||||
view : 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
|
To compile a shader and use the result, you can do the following in jai
|
||||||
```jai
|
```jai
|
||||||
|
|
||||||
parse_shader :: (path : string, allocator : Allocator) -> Compilation_Result {
|
// In the future, you can pass environment defines to the compiler.
|
||||||
// In the future, you can pass environment defines to the compiler.
|
ctx : Compiler_Context;
|
||||||
compiler : Shader_Compiler;
|
compile_file(*compiler, "shader.shd", allocator);
|
||||||
|
|
||||||
return compile_file(*compiler, path,, allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
result := parse_shader("shader.shd", allocator);
|
if ctx.had_error {
|
||||||
if result.had_error {
|
log_error("%\n", report_messages(ctx.messages),, temp);
|
||||||
log_error("%\n", report_messages(result.messages),, temp);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
collection := result.collection;
|
// The ctx now contains all the needed information like the source text, entry points, constant buffers etc.
|
||||||
variant := collection.variants[0];
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
When parsing a shader you get the following struct as a result
|
When parsing a shader you get the following struct as a result
|
||||||
```
|
```
|
||||||
Compilation_Result :: struct {
|
Compiler_Context :: struct {
|
||||||
messages : [..]Compiler_Message;
|
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
|
constant_buffers : Static_Array(Type_Variable_Handle, 16);
|
||||||
```
|
|
||||||
Shader_Variant_Collection :: struct {
|
|
||||||
properties : Properties;
|
|
||||||
|
|
||||||
max_constant_buffers :: 16;
|
scope_stack : Scope_Stack;
|
||||||
cbuffers : Static_Array(Constant_Buffer, max_constant_buffers);
|
type_variables : [..]Type_Variable;
|
||||||
|
|
||||||
variants : [..]Shader_Variant;
|
property_name : string;
|
||||||
}
|
|
||||||
|
|
||||||
Shader_Variant :: struct {
|
|
||||||
text : string;
|
|
||||||
|
|
||||||
vertex_entry_point : struct {
|
vertex_entry_point : struct {
|
||||||
|
node : *AST_Node;
|
||||||
name : string;
|
name : string;
|
||||||
|
|
||||||
input : [..]Field;
|
input : [..]Field;
|
||||||
}
|
}
|
||||||
|
|
||||||
pixel_entry_point : struct {
|
pixel_entry_point : struct {
|
||||||
|
node : *AST_Node;
|
||||||
name : string;
|
name : string;
|
||||||
|
|
||||||
return_value : Field;
|
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 {
|
Constant_Buffer :: struct {
|
||||||
register : int;
|
|
||||||
|
|
||||||
name : string;
|
name : string;
|
||||||
|
|
||||||
fields : Static_Array(Property_Field, 16);
|
fields : Static_Array(Property_Field, 16);
|
||||||
|
|
||||||
|
// hints : Field_Hint; // optional hint...
|
||||||
|
hints : [..]Field_Hint;
|
||||||
|
|
||||||
buffer_index : u32;
|
buffer_index : u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,11 +193,10 @@ Hint_Kind :: enum {
|
|||||||
|
|
||||||
## Notable missing features
|
## Notable missing features
|
||||||
|
|
||||||
- Control flow: if/else, for, while, switch etc.
|
- While
|
||||||
- Arrays
|
- Arrays
|
||||||
- Textures and samplers
|
|
||||||
- Multiple render targets
|
- Multiple render targets
|
||||||
- Custom buffers/structured buffers
|
- Custom buffers/structured buffers
|
||||||
- Interpolation specifiers
|
- Interpolation specifiers
|
||||||
- Proper variant handling with environment defines
|
- Proper variant handling with environment defines
|
||||||
- Include/importing files such as shared utils etc.
|
- Importing files such as shared utils etc. with something other than textual `#load`
|
||||||
20
module.jai
20
module.jai
@@ -81,22 +81,6 @@ Entry_Point :: struct {
|
|||||||
return_value : Field;
|
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 {
|
Property_Field :: struct {
|
||||||
base_field : Field;
|
base_field : Field;
|
||||||
|
|
||||||
@@ -111,8 +95,6 @@ Properties :: struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Constant_Buffer :: struct {
|
Constant_Buffer :: struct {
|
||||||
register : int;
|
|
||||||
|
|
||||||
name : string;
|
name : string;
|
||||||
|
|
||||||
fields : Static_Array(Property_Field, 16);
|
fields : Static_Array(Property_Field, 16);
|
||||||
@@ -167,7 +149,7 @@ Compiler_Context :: struct {
|
|||||||
return_value : Field;
|
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;
|
max_constant_buffers :: 16;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user