From 8aa9f1402bed9140dba0997591009297cc2e2661 Mon Sep 17 00:00:00 2001 From: jacob Date: Wed, 28 May 2025 03:24:26 -0500 Subject: [PATCH] use float2x3 for xforms in shaders --- res/shaders/common.hlsl | 5 ----- res/shaders/grid.hlsl | 8 +++----- res/shaders/texture.hlsl | 8 +++----- src/common.h | 2 +- src/gpu_dx11.c | 6 ++++-- 5 files changed, 11 insertions(+), 18 deletions(-) diff --git a/res/shaders/common.hlsl b/res/shaders/common.hlsl index 769bba61..71d77684 100644 --- a/res/shaders/common.hlsl +++ b/res/shaders/common.hlsl @@ -23,8 +23,3 @@ float4 linear_from_srgb32(uint srgb32) res.a = ((srgb32 >> 24) & 0xFF) / 255.0; return linear_from_srgb(res); } - -float2 xform_mul(struct xform xf, float2 v) -{ - return xf.bx * v.x + xf.by * v.y + xf.og; -} \ No newline at end of file diff --git a/res/shaders/grid.hlsl b/res/shaders/grid.hlsl index c01e7509..1c7b6e7a 100644 --- a/res/shaders/grid.hlsl +++ b/res/shaders/grid.hlsl @@ -1,7 +1,7 @@ #include "shaders/common.hlsl" struct vs_instance { - struct xform xf; + float2x3 xf; float line_thickness; float line_spacing; float2 offset; @@ -51,12 +51,10 @@ ps_input vs_main(uint instance_id : SV_InstanceID, uint vertex_id : SV_VertexID) { vs_instance instance = G_instance_buffer[G_instance_offset + instance_id]; float2 vert = G_quad_verts[vertex_id]; - - float2 world_pos = xform_mul(instance.xf, vert); - float4 screen_pos = mul(G_projection, float4(world_pos, 0, 1)); + float2 world_pos = mul(instance.xf, float3(vert, 1)).xy; ps_input output; - output.screen_pos = screen_pos; + output.screen_pos = mul(G_projection, float4(world_pos, 0, 1)); output.line_thickness = instance.line_thickness; output.line_spacing = instance.line_spacing; output.offset = instance.offset; diff --git a/res/shaders/texture.hlsl b/res/shaders/texture.hlsl index 1a65e7a4..db910821 100644 --- a/res/shaders/texture.hlsl +++ b/res/shaders/texture.hlsl @@ -1,7 +1,7 @@ #include "shaders/common.hlsl" struct vs_instance { - struct xform xf; + float2x3 xf; float2 uv0; float2 uv1; uint tint_srgb; @@ -51,13 +51,11 @@ ps_input vs_main(uint instance_id : SV_InstanceID, uint vertex_id : SV_VertexID) { vs_instance instance = G_instance_buffer[G_instance_offset + instance_id]; float2 vert = G_quad_verts[vertex_id]; + float2 world_pos = mul(instance.xf, float3(vert, 1)).xy; float2 uv_factor = G_uv_factors[vertex_id]; - float2 world_pos = xform_mul(instance.xf, vert); - float4 screen_pos = mul(G_projection, float4(world_pos, 0, 1)); - ps_input output; - output.screen_pos = screen_pos; + output.screen_pos = mul(G_projection, float4(world_pos, 0, 1)); output.uv = instance.uv0 + uv_factor * (instance.uv1 - instance.uv0); output.tint_lin = linear_from_srgb32(instance.tint_srgb); diff --git a/src/common.h b/src/common.h index 2e6cbcc2..682130e5 100644 --- a/src/common.h +++ b/src/common.h @@ -655,7 +655,7 @@ INLINE void __prof_dx11_zone_cleanup_func(TracyCD3D11ZoneCtx *ctx) { ___tracy_d3 #define __profalloc(ptr, size) TracyCAlloc((ptr), (size)) #define __proffree(ptr) TracyCFree((ptr)) -#define __profmsg(txt, len, col) TracyCMessageC((txt), (len), (col)); +#define __profmsg(txt, len, col) TracyCMessageC((txt), (len), BGR(col)); #define __profframe(name) TracyCFrameMarkNamed((name)) #define __profthread(name) TracyCSetThreadName((name)) diff --git a/src/gpu_dx11.c b/src/gpu_dx11.c index 632c459b..9fb3fb27 100644 --- a/src/gpu_dx11.c +++ b/src/gpu_dx11.c @@ -731,7 +731,7 @@ INTERNAL struct string shader_alloc(struct arena *arena, struct dx11_shader *sha struct dx11_include_handler include_handler = dx11_include_handler_alloc(shader); - u32 flags = D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR; + u32 flags = 0; #if DX11_SHADER_DEBUG flags |= D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION | D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_WARNINGS_ARE_ERRORS; #else @@ -952,7 +952,6 @@ INTERNAL void dx11_buffer_release(struct dx11_buffer *buffer) INTERNAL void *dx11_buffer_push(struct dx11_buffer *buffer, u64 size) { - __prof; void *data = arena_push_array_no_zero(&buffer->cpu_buffer_arena, u8, size); return data; } @@ -1017,6 +1016,7 @@ INTERNAL void dx11_buffer_submit(struct dx11_buffer *buffer) struct gpu_cmd_store gpu_cmd_store_alloc(void) { + __prof; struct dx11_cmd_store *store = NULL; { struct arena cpu_cmds_arena = ZI; @@ -1107,12 +1107,14 @@ struct gpu_cmd_store gpu_cmd_store_alloc(void) void gpu_cmd_store_release(struct gpu_cmd_store gpu_cmd_store) { + __prof; /* TODO */ (UNUSED)gpu_cmd_store; } void gpu_push_cmd(struct gpu_cmd_store gpu_cmd_store, struct gpu_cmd_params params) { + __prof; struct dx11_cmd_store *store = (struct dx11_cmd_store *)gpu_cmd_store.handle; switch (params.kind) {