]> git.nega.tv - josh/narcissus/commitdiff
shark-shaders: Migrate composite pipeline to slang
authorJoshua Simmons <josh@nega.tv>
Sun, 12 Oct 2025 10:30:29 +0000 (12:30 +0200)
committerJoshua Simmons <josh@nega.tv>
Sun, 12 Oct 2025 10:32:31 +0000 (12:32 +0200)
title/shark-shaders/build.rs
title/shark-shaders/shaders/composite.comp [deleted file]
title/shark-shaders/shaders/composite.slang [new file with mode: 0644]
title/shark-shaders/src/pipelines.rs

index a62676132ec0f9921f48772ddcba2d022e418dbe..74112484af0d22b14dd37bad908e0e906dc080dd 100644 (file)
@@ -79,6 +79,7 @@ struct SlangShader {
 const SLANG_SHADERS: &[SlangShader] = &[
     SlangShader { name: "basic" },
     SlangShader { name: "draw_2d" },
+    SlangShader { name: "composite" },
 ];
 
 const SHADERS: &[Shader] = &[
@@ -90,10 +91,6 @@ const SHADERS: &[Shader] = &[
         stage: "comp",
         name: "radix_sort_1_downsweep",
     },
-    Shader {
-        stage: "comp",
-        name: "composite",
-    },
 ];
 
 fn main() {
diff --git a/title/shark-shaders/shaders/composite.comp b/title/shark-shaders/shaders/composite.comp
deleted file mode 100644 (file)
index a9d019d..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-#version 460
-
-#extension GL_GOOGLE_include_directive : require
-
-#extension GL_EXT_buffer_reference : require
-#extension GL_EXT_buffer_reference2 : require
-#extension GL_EXT_scalar_block_layout : require
-#extension GL_EXT_shader_image_load_formatted : require
-
-#include "bindings_compute.h"
-
-// TODO: Remove this
-const uint TILE_SIZE = 32;
-
-struct Tile {
-    uint index_min;
-    uint index_max;
-};
-
-layout(buffer_reference, std430, buffer_reference_align = 4) readonly buffer TileReadRef {
-    Tile values[];
-};
-
-float srgb_oetf(float a) {
-    return (.0031308f >= a) ? 12.92f * a : 1.055f * pow(a, .4166666666666667f) - .055f;
-}
-
-vec3 srgb_oetf(vec3 a) {
-       return vec3(srgb_oetf(a.r), srgb_oetf(a.g), srgb_oetf(a.b));
-}
-
-vec3 tony_mc_mapface(vec3 stimulus) {
-    const vec3 encoded = stimulus / (stimulus + 1.0);
-    const float LUT_DIMS = 48.0;
-    const vec3 uv = (encoded * ((LUT_DIMS - 1.0) / LUT_DIMS) + 0.5 / LUT_DIMS);
-    return textureLod(sampler3D(tony_mc_mapface_lut, samplers[SAMPLER_BILINEAR]), uv, 0.0).rgb;
-}
-
-struct CompositeConstants {
-    uvec2 tile_resolution;
-    TileReadRef tile_buffer;
-};
-
-layout(std430, push_constant) uniform CompositeConstantsBlock {
-    CompositeConstants constants;
-};
-
-layout (local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
-
-void main() {
-    const uvec2 tile_coord = gl_WorkGroupID.xy / (TILE_SIZE / gl_WorkGroupSize.xy);
-    const uint tile_index = tile_coord.y * constants.tile_resolution.x + tile_coord.x;
-
-    const uint lo = constants.tile_buffer.values[tile_index].index_min;
-    const uint hi = constants.tile_buffer.values[tile_index].index_max;
-
-    // Display transform
-    const vec3 stimulus = imageLoad(color_layer, ivec2(gl_GlobalInvocationID.xy)).rgb;
-    const vec3 transformed = tony_mc_mapface(stimulus);
-    vec3 composited = srgb_oetf(transformed);
-
-    // UI Composite
-    if (lo != hi) {
-        const vec4 ui = imageLoad(ui_layer_read, ivec2(gl_GlobalInvocationID.xy)).rgba;
-        composited = ui.rgb + (composited * (1.0 - ui.a));
-    }
-
-    imageStore(composited_output, ivec2(gl_GlobalInvocationID.xy), vec4(composited, 1.0));
-}
diff --git a/title/shark-shaders/shaders/composite.slang b/title/shark-shaders/shaders/composite.slang
new file mode 100644 (file)
index 0000000..f02ace9
--- /dev/null
@@ -0,0 +1,48 @@
+
+import bindings_samplers;
+import bindings_compute;
+
+import draw_2d;
+
+float srgb_oetf(float a) {
+    return (.0031308f >= a) ? 12.92f * a : 1.055f * pow(a, .4166666666666667f) - .055f;
+}
+
+float3 srgb_oetf(float3 a) {
+    return float3(srgb_oetf(a.r), srgb_oetf(a.g), srgb_oetf(a.b));
+}
+
+float3 tony_mc_mapface(float3 stimulus) {
+    const float3 encoded = stimulus / (stimulus + 1.0);
+    const float LUT_DIMS = 48.0;
+    const float3 uv = (encoded * ((LUT_DIMS - 1.0) / LUT_DIMS) + 0.5 / LUT_DIMS);
+    return tony_mc_mapface_lut.SampleLevel(samplers[Sampler::Bilinear], uv, 0.0).rgb;
+}
+
+struct CompositeConstants {
+    uint2 tile_resolution;
+    Draw2d::Tile *tile_buffer;
+}
+
+[shader("compute")]
+[numthreads(8, 8, 1)]
+void main(uniform CompositeConstants constants, uint3 thread_id: SV_DispatchThreadID, uint3 group_id: SV_GroupID) {
+    let tile_coord = group_id.xy * WorkgroupSize().xy / Draw2d::TILE_SIZE;
+    let tile_index = tile_coord.y * constants.tile_resolution.x + tile_coord.x;
+
+    let lo = constants.tile_buffer[tile_index].index_min;
+    let hi = constants.tile_buffer[tile_index].index_max;
+
+    // Display transform
+    let stimulus = color_layer.Load(thread_id.xy).rgb;
+    let transformed = tony_mc_mapface(stimulus);
+    var composited = srgb_oetf(transformed);
+
+    // UI composite
+    if (lo != hi) {
+        let ui = ui_layer.Load(thread_id.xy).rgba;
+        composited = ui.rgb + (composited * (1.0 - ui.a));
+    }
+
+    composited_output.Store(thread_id.xy, float4(composited, 1.0));
+}
index 9c3734dd550a0b188fa1741bf98a95c53a7966e0..19abe02259d913f86db0b0fe386fbd89f2264b87 100644 (file)
@@ -481,7 +481,7 @@ impl Pipelines {
         );
 
         let composite_pipeline = create_compute_pipeline(
-            crate::COMPOSITE_COMP_SPV,
+            crate::COMPOSITE_SPV,
             "composite",
             0,
             false,