From 95b182ae1e38748c77387902455e0316b97fac55 Mon Sep 17 00:00:00 2001 From: jacob Date: Tue, 24 Feb 2026 12:09:38 -0600 Subject: [PATCH] formatting --- src/base/base_shader.gh | 6 +-- src/gpu/gpu_dx12/gpu_dx12_core.c | 2 - src/pp/pp_vis/pp_vis_gpu.g | 17 ++++----- src/pp/pp_vis/pp_vis_shared.cg | 63 +++++++------------------------- src/pp/pp_vis/pp_vis_shared.cgh | 36 +++++++++--------- 5 files changed, 43 insertions(+), 81 deletions(-) diff --git a/src/base/base_shader.gh b/src/base/base_shader.gh index 1993dd2e..fc615bf4 100644 --- a/src/base/base_shader.gh +++ b/src/base/base_shader.gh @@ -47,9 +47,9 @@ u32 countof(T arr[N]) //~ C -> HLSL interoperability stubs //- Constructors -#define CompVec2(x, y) { (x), (y) } -#define CompVec3(x, y, z) { (x), (y), (z) } -#define CompVec4(x, y, z, w) { (x), (y), (z), (w) } +#define CompVec2(...) Vec2(__VA_ARGS__) +#define CompVec3(...) Vec3(__VA_ARGS__) +#define CompVec4(...) Vec4(__VA_ARGS__) #define VEC2(...) Vec2(__VA_ARGS__) #define VEC3(...) Vec3(__VA_ARGS__) #define VEC4(...) Vec4(__VA_ARGS__) diff --git a/src/gpu/gpu_dx12/gpu_dx12_core.c b/src/gpu/gpu_dx12/gpu_dx12_core.c index 78de8af0..93a4de6c 100644 --- a/src/gpu/gpu_dx12/gpu_dx12_core.c +++ b/src/gpu/gpu_dx12/gpu_dx12_core.c @@ -1657,8 +1657,6 @@ u32 G_PushRef(G_ArenaHandle arena_handle, G_ResourceHandle resource_handle, G_Re b32 is_raw = kind == G_RefKind_ByteAddressBuffer; b32 is_writable = resource->flags & G_ResourceFlag_AllowShaderReadWrite; - b32 ok = 1; - G_D12_Descriptor *descriptor = 0; if (is_buffer || is_texture) { diff --git a/src/pp/pp_vis/pp_vis_gpu.g b/src/pp/pp_vis/pp_vis_gpu.g index af8e9712..001e25d8 100644 --- a/src/pp/pp_vis/pp_vis_gpu.g +++ b/src/pp/pp_vis/pp_vis_gpu.g @@ -195,7 +195,6 @@ ImplComputeShader2D(V_BackdropDownCS) } RWTexture2D bd_down = G_DereferenceRW(frame.backdrop_mips[mip_idx]); - Vec2 down_dims = countof(bd_down); Vec2 bd_pos = SV_DispatchThreadID + 0.5; @@ -400,7 +399,7 @@ ImplComputeShader(V_SimParticlesCS) V_SharedFrame frame = G_Dereference(V_GpuConst_Frame)[0]; Texture2D tiles = G_Dereference(frame.tiles); RWStructuredBuffer particles = G_DereferenceRW(frame.particles); - RWTexture2D occluders = G_DereferenceRW(frame.occluders); + Texture2D occluders = G_Dereference(frame.occluders); u32 particle_idx = SV_DispatchThreadID; if (particle_idx < V_ParticlesCap) @@ -679,7 +678,7 @@ ImplComputeShader2D(V_ShadeCS) Texture2D tiles = G_Dereference(frame.tiles); Texture2D albedo_tex = G_Dereference(frame.albedo); RWTexture2D shade_tex = G_DereferenceRW(frame.shade); - RWTexture2D drynesses = G_DereferenceRW(frame.drynesses); + Texture2D drynesses = G_Dereference(frame.drynesses); Vec2 shade_pos = SV_DispatchThreadID + 0.5; Vec2 world_pos = mul(frame.af.shade_to_world, Vec3(shade_pos, 1)); @@ -716,12 +715,12 @@ ImplComputeShader2D(V_CompositeCS) SamplerState bilinear_sampler = G_Dereference(frame.basic_samplers[G_BasicSamplerKind_BilinearClamp]); Texture2D albedo_tex = G_Dereference(frame.albedo); RWTexture2D screen_tex = G_DereferenceRW(frame.screen); - RWTexture2D stains = G_DereferenceRW(frame.stains); - RWTexture2D dry_stains = G_DereferenceRW(frame.dry_stains); - RWTexture2D drynesses = G_DereferenceRW(frame.drynesses); + Texture2D stains = G_Dereference(frame.stains); + Texture2D dry_stains = G_Dereference(frame.dry_stains); + Texture2D drynesses = G_Dereference(frame.drynesses); Texture2D tiles = G_Dereference(frame.tiles); Texture2D backdrop = G_Dereference(frame.backdrop_mips[0]); - RWStructuredBuffer particles = G_DereferenceRW(frame.particles); + StructuredBuffer particles = G_Dereference(frame.particles); Vec2 screen_pos = SV_DispatchThreadID.xy + 0.5; Vec2 world_pos = mul(frame.af.screen_to_world, Vec3(screen_pos, 1)); @@ -858,8 +857,8 @@ ImplComputeShader2D(V_CompositeCS) for (V_ParticleLayer layer = (V_ParticleLayer)0; layer < V_ParticleLayer_COUNT; layer += (V_ParticleLayer)1) { - RWTexture2D cells = G_DereferenceRW(frame.particle_cells[layer]); - RWTexture2D densities = G_DereferenceRW(frame.particle_densities[layer]); + Texture2D cells = G_Dereference(frame.particle_cells[layer]); + Texture2D densities = G_Dereference(frame.particle_densities[layer]); u32 packed = cells[cell_pos]; V_ParticleKind particle_kind = (V_ParticleKind)((packed >> 24) & 0x7F); if (particle_kind != V_ParticleKind_None) diff --git a/src/pp/pp_vis/pp_vis_shared.cg b/src/pp/pp_vis/pp_vis_shared.cg index 72f6ae8d..dacf8697 100644 --- a/src/pp/pp_vis/pp_vis_shared.cg +++ b/src/pp/pp_vis/pp_vis_shared.cg @@ -1,6 +1,3 @@ -//////////////////////////////////////////////////////////// -//~ Helpers - V_ParticleDesc V_DescFromParticleKind(V_ParticleKind kind) { if (kind < 0 || kind >= V_ParticleKind_COUNT) @@ -10,55 +7,23 @@ V_ParticleDesc V_DescFromParticleKind(V_ParticleKind kind) V_ParticleDesc result; { - PERSIST Readonly V_ParticleFlag flags[V_ParticleKind_COUNT] = { - #define X(name, flags, layer, stain_rate, pen_rate, lifetime, prune_speed_threshold, base_color, dry_factor) flags, + V_ParticleDesc descs[V_ParticleKind_COUNT] = { + #define X(name, flags, layer, stain_rate, pen_rate, lifetime, prune_speed_threshold, base_color, dry_factor) \ + { \ + V_ParticleKind_##name, \ + flags, \ + layer, \ + stain_rate, \ + pen_rate, \ + lifetime, \ + prune_speed_threshold, \ + LinearFromSrgb(base_color), \ + LinearFromSrgb(dry_factor) \ + }, V_ParticlesXList(X) #undef X }; - PERSIST Readonly V_ParticleLayer layers[V_ParticleKind_COUNT] = { - #define X(name, flags, layer, stain_rate, pen_rate, lifetime, prune_speed_threshold, base_color, dry_factor) layer, - V_ParticlesXList(X) - #undef X - }; - PERSIST Readonly f32 stain_rates[V_ParticleKind_COUNT] = { - #define X(name, flags, layer, stain_rate, pen_rate, lifetime, prune_speed_threshold, base_color, dry_factor) stain_rate, - V_ParticlesXList(X) - #undef X - }; - PERSIST Readonly f32 pen_rates[V_ParticleKind_COUNT] = { - #define X(name, flags, layer, stain_rate, pen_rate, lifetime, prune_speed_threshold, base_color, dry_factor) pen_rate, - V_ParticlesXList(X) - #undef X - }; - PERSIST Readonly f32 lifetimes[V_ParticleKind_COUNT] = { - #define X(name, flags, layer, stain_rate, pen_rate, lifetime, prune_speed_threshold, base_color, dry_factor) lifetime, - V_ParticlesXList(X) - #undef X - }; - PERSIST Readonly f32 prune_speed_thresholds[V_ParticleKind_COUNT] = { - #define X(name, flags, layer, stain_rate, pen_rate, lifetime, prune_speed_threshold, base_color, dry_factor) prune_speed_threshold, - V_ParticlesXList(X) - #undef X - }; - PERSIST Readonly Vec4 base_colors[V_ParticleKind_COUNT] = { - #define X(name, flags, layer, stain_rate, pen_rate, lifetime, prune_speed_threshold, base_color, dry_factor) base_color, - V_ParticlesXList(X) - #undef X - }; - PERSIST Readonly Vec4 dry_factor[V_ParticleKind_COUNT] = { - #define X(name, flags, layer, stain_rate, pen_rate, lifetime, prune_speed_threshold, base_color, dry_factor) dry_factor, - V_ParticlesXList(X) - #undef X - }; - result.kind = kind; - result.flags = flags[kind]; - result.layer = layers[kind]; - result.stain_rate = stain_rates[kind]; - result.pen_rate = pen_rates[kind]; - result.lifetime = lifetimes[kind]; - result.prune_speed_threshold = prune_speed_thresholds[kind]; - result.base_color = LinearFromSrgb(base_colors[kind]); - result.dry_factor = LinearFromSrgb(dry_factor[kind]); + result = descs[kind]; } return result; } diff --git a/src/pp/pp_vis/pp_vis_shared.cgh b/src/pp/pp_vis/pp_vis_shared.cgh index 092bbfcb..9e1b4587 100644 --- a/src/pp/pp_vis/pp_vis_shared.cgh +++ b/src/pp/pp_vis/pp_vis_shared.cgh @@ -52,8 +52,8 @@ Enum(V_ParticleLayer) /* Stain rate, pen chance */ 30, 0, \ /* Lifetime */ Inf, \ /* Prune speed threshold */ 0.01, \ - /* Base color */ CompVec4(0, 0, 0, 0), \ - /* Dry color factor */ CompVec4(1, 1, 1, 1) \ + /* Base color */ VEC4(0, 0, 0, 0), \ + /* Dry color factor */ VEC4(1, 1, 1, 1) \ ) \ \ /* Ground particles */ \ @@ -64,8 +64,8 @@ Enum(V_ParticleLayer) /* Stain rate, pen chance */ 100, 0.25, \ /* Lifetime */ Inf, \ /* Prune speed threshold */ 0.5, \ - /* Base color */ CompVec4(0.6, 0.1, 0.1, 0.05), \ - /* Dry color factor */ CompVec4(0.4, 0.4, 0.4, 1) \ + /* Base color */ VEC4(0.6, 0.1, 0.1, 0.05), \ + /* Dry color factor */ VEC4(0.4, 0.4, 0.4, 1) \ ) \ X( \ /* Name */ BloodDebris, \ @@ -74,8 +74,8 @@ Enum(V_ParticleLayer) /* Stain rate, pen chance */ 30, 0, \ /* Lifetime */ Inf, \ /* Prune speed threshold */ 0.01, \ - /* Base color */ CompVec4(0.5, 0.1, 0.1, 0.8), \ - /* Dry color factor */ CompVec4(1, 1, 1, 1) \ + /* Base color */ VEC4(0.5, 0.1, 0.1, 0.8), \ + /* Dry color factor */ VEC4(1, 1, 1, 1) \ ) \ X( \ /* Name */ Debris, \ @@ -84,8 +84,8 @@ Enum(V_ParticleLayer) /* Stain rate, pen chance */ 0, 0, \ /* Lifetime */ Inf, \ /* Prune speed threshold */ 0.01, \ - /* Base color */ CompVec4(0.4, 0.3, 0.2, 1), \ - /* Dry color factor */ CompVec4(1, 1, 1, 1) \ + /* Base color */ VEC4(0.4, 0.3, 0.2, 1), \ + /* Dry color factor */ VEC4(1, 1, 1, 1) \ ) \ X( \ /* Name */ Fire, \ @@ -94,8 +94,8 @@ Enum(V_ParticleLayer) /* Stain rate, pen chance */ 0, 0, \ /* Lifetime */ Inf, \ /* Prune speed threshold */ 0.1, \ - /* Base color */ CompVec4(2, 0.5, 0, 1), \ - /* Dry color factor */ CompVec4(0.2, 0.1, 0.0, 1) \ + /* Base color */ VEC4(2, 0.5, 0, 1), \ + /* Dry color factor */ VEC4(0.2, 0.1, 0.0, 1) \ ) \ \ /* Air particles */ \ @@ -106,8 +106,8 @@ Enum(V_ParticleLayer) /* Stain rate, pen chance */ 0, 0, \ /* Lifetime */ 0.075, \ /* Prune speed threshold */ 0.01, \ - /* Base color */ CompVec4(0.8, 0.6, 0.2, 0.25), \ - /* Dry color factor */ CompVec4(1, 1, 1, 1) \ + /* Base color */ VEC4(0.8, 0.6, 0.2, 0.25), \ + /* Dry color factor */ VEC4(1, 1, 1, 1) \ ) \ X( \ /* Name */ Smoke, \ @@ -116,8 +116,8 @@ Enum(V_ParticleLayer) /* Stain rate, pen chance */ 0, 0, \ /* Lifetime */ Inf, \ /* Prune speed threshold */ 0.01, \ - /* Base color */ CompVec4(0.25, 0.25, 0.25, 0.75), \ - /* Dry color factor */ CompVec4(1, 1, 1, 1) \ + /* Base color */ VEC4(0.25, 0.25, 0.25, 0.75), \ + /* Dry color factor */ VEC4(1, 1, 1, 1) \ ) \ \ /* Test particles */ \ @@ -128,8 +128,8 @@ Enum(V_ParticleLayer) /* Stain rate, pen chance */ 0, 0, \ /* Lifetime */ Inf, \ /* Prune speed threshold */ 0.01, \ - /* Base color */ CompVec4(1, 1, 0, 1), \ - /* Dry color factor */ CompVec4(1, 1, 1, 1) \ + /* Base color */ VEC4(1, 1, 0, 1), \ + /* Dry color factor */ VEC4(1, 1, 1, 1) \ ) \ /* ----------------------------------------------------------------------------------------------------------------------------------- */ @@ -156,9 +156,9 @@ Struct(V_Emitter) // TODO: Pack this efficiently Struct(V_Particle) { - i32 kind; // If >= 0, then map to V_ParticleKind. Otherwize initialize particle using emitter at index [abs(kind) - 1] + i32 kind; // If >= 0, then this maps to V_ParticleKind. Otherwise it represent a particle to be initialized using emitter at index [abs(kind) - 1] u32 origin_occluder; - u32 prev_occluder; // TODO: Remove this + u32 prev_occluder; // TODO: Remove this f32 life; f32 stain_accum; u32 cells_count;