From ee9ec10f7bc17cd6e0522be2e24b932748d6b06b Mon Sep 17 00:00:00 2001 From: luboslenco Date: Fri, 18 Apr 2025 09:28:41 +0200 Subject: [PATCH] kong + metal test --- armorpaint/shaders/dilate_pass.kong | 12 ++++----- armorpaint/shaders/layer_invert.kong | 10 ++++---- armorpaint/shaders/layer_merge.kong | 14 +++++----- armorpaint/shaders/layer_view.kong | 12 ++++----- armorpaint/shaders/mask_merge.kong | 12 ++++----- base/shaders/bloom_downsample_pass.kong | 12 ++++----- base/shaders/bloom_upsample_pass.kong | 12 ++++----- base/shaders/compositor_pass.kong | 12 ++++----- base/shaders/deferred_light.kong | 34 ++++++++++++------------- base/shaders/layer_copy.kong | 10 ++++---- base/shaders/layer_copy_bgra.kong | 10 ++++---- base/shaders/prefilter_envmap.kong | 10 ++++---- base/shaders/ssao_blur_pass.kong | 10 ++++---- base/shaders/ssao_pass.kong | 16 ++++++------ base/shaders/supersample_resolve.kong | 10 ++++---- base/shaders/taa_pass.kong | 10 ++++---- base/sources/backends/metal_gpu.m | 2 +- base/sources/ts/node_shader.ts | 16 ++++++------ 18 files changed, 112 insertions(+), 112 deletions(-) diff --git a/armorpaint/shaders/dilate_pass.kong b/armorpaint/shaders/dilate_pass.kong index e1e52769..6c6b8d8c 100644 --- a/armorpaint/shaders/dilate_pass.kong +++ b/armorpaint/shaders/dilate_pass.kong @@ -1,4 +1,10 @@ +#[set(everything)] +const constants: { + dilate_radius: float; + tex_size: float2; +}; + #[set(everything)] const tex: tex2d; @@ -11,12 +17,6 @@ const texdilate: tex2d; #[set(everything)] const texdilate_sampler: sampler; -#[set(everything)] -const constants: { - dilate_radius: float; - tex_size: float2; -}; - // const offsets: float2[8] = { // float2(-1.0, 0.0), float2( 1.0, 0.0), float2( 0.0, 1.0), float2( 0.0, -1.0), // float2(-1.0, 1.0), float2( 1.0, 1.0), float2( 1.0, -1.0), float2(-1.0, -1.0) diff --git a/armorpaint/shaders/layer_invert.kong b/armorpaint/shaders/layer_invert.kong index d77aa8b4..92acb1bc 100644 --- a/armorpaint/shaders/layer_invert.kong +++ b/armorpaint/shaders/layer_invert.kong @@ -1,15 +1,15 @@ +#[set(everything)] +const constants: { + P: float4x4; +}; + #[set(everything)] const tex: tex2d; #[set(everything)] const tex_sampler: sampler; -#[set(everything)] -const constants: { - P: float4x4; -}; - struct vert_in { pos: float3; tex: float2; diff --git a/armorpaint/shaders/layer_merge.kong b/armorpaint/shaders/layer_merge.kong index b2e7878d..d4e24244 100644 --- a/armorpaint/shaders/layer_merge.kong +++ b/armorpaint/shaders/layer_merge.kong @@ -1,4 +1,11 @@ +#[set(everything)] +const constants: { + opac: float; + blending: int; + tex1w: float; +}; + #[set(everything)] const tex0: tex2d; @@ -23,13 +30,6 @@ const texa: tex2d; #[set(everything)] const texa_sampler: sampler; -#[set(everything)] -const constants: { - opac: float; - blending: int; - tex1w: float; -}; - struct vert_in { pos: float2; } diff --git a/armorpaint/shaders/layer_view.kong b/armorpaint/shaders/layer_view.kong index 888db991..f58a7975 100644 --- a/armorpaint/shaders/layer_view.kong +++ b/armorpaint/shaders/layer_view.kong @@ -1,16 +1,16 @@ -#[set(everything)] -const tex: tex2d; - -#[set(everything)] -const tex_sampler: sampler; - #[set(everything)] const constants: { P: float4x4; channel: int; }; +#[set(everything)] +const tex: tex2d; + +#[set(everything)] +const tex_sampler: sampler; + struct vert_in { pos: float3; tex: float2; diff --git a/armorpaint/shaders/mask_merge.kong b/armorpaint/shaders/mask_merge.kong index 612e9a77..51af5870 100644 --- a/armorpaint/shaders/mask_merge.kong +++ b/armorpaint/shaders/mask_merge.kong @@ -1,4 +1,10 @@ +#[set(everything)] +const constants: { + opac: float; + blending: int; +}; + #[set(everything)] const tex0: tex2d; @@ -11,12 +17,6 @@ const texa: tex2d; #[set(everything)] const texa_sampler: sampler; -#[set(everything)] -const constants: { - opac: float; - blending: int; -}; - struct vert_in { pos: float2; } diff --git a/base/shaders/bloom_downsample_pass.kong b/base/shaders/bloom_downsample_pass.kong index 57d47d72..445c5698 100644 --- a/base/shaders/bloom_downsample_pass.kong +++ b/base/shaders/bloom_downsample_pass.kong @@ -1,16 +1,16 @@ -#[set(everything)] -const tex: tex2d; - -#[set(everything)] -const tex_sampler: sampler; - #[set(everything)] const constants: { screen_size_inv: float2; current_mip_level: int; }; +#[set(everything)] +const tex: tex2d; + +#[set(everything)] +const tex_sampler: sampler; + struct vert_in { pos: float2; } diff --git a/base/shaders/bloom_upsample_pass.kong b/base/shaders/bloom_upsample_pass.kong index 47789618..431025e7 100644 --- a/base/shaders/bloom_upsample_pass.kong +++ b/base/shaders/bloom_upsample_pass.kong @@ -1,10 +1,4 @@ -#[set(everything)] -const tex: tex2d; - -#[set(everything)] -const tex_sampler: sampler; - #[set(everything)] const constants: { screen_size_inv: float2; @@ -12,6 +6,12 @@ const constants: { sample_scale: float; }; +#[set(everything)] +const tex: tex2d; + +#[set(everything)] +const tex_sampler: sampler; + struct vert_in { pos: float2; } diff --git a/base/shaders/compositor_pass.kong b/base/shaders/compositor_pass.kong index bd5e2706..a7c4bb0d 100644 --- a/base/shaders/compositor_pass.kong +++ b/base/shaders/compositor_pass.kong @@ -1,4 +1,10 @@ +#[set(everything)] +const constants: { + vignette_strength: float; + grain_strength: float; +}; + #[set(everything)] const tex: tex2d; @@ -11,12 +17,6 @@ const tex_sampler: sampler; // #[set(everything)] // const histogram_sampler: sampler; -#[set(everything)] -const constants: { - vignette_strength: float; - grain_strength: float; -}; - struct vert_in { pos: float2; } diff --git a/base/shaders/deferred_light.kong b/base/shaders/deferred_light.kong index 92166987..4506f43e 100644 --- a/base/shaders/deferred_light.kong +++ b/base/shaders/deferred_light.kong @@ -1,4 +1,21 @@ +#[set(everything)] +const constants: { + invVP: float4x4; + eye: float3; + envmap_data: float4; // angle, sin(angle), cos(angle), strength + envmap_num_mipmaps: int; + camera_proj: float2; + eye_look: float3; + shirr0: float4; + shirr1: float4; + shirr2: float4; + shirr3: float4; + shirr4: float4; + shirr5: float4; + shirr6: float4; +}; + #[set(everything)] const gbufferD: tex2d; @@ -35,23 +52,6 @@ const ssaotex: tex2d; #[set(everything)] const ssaotex_sampler: sampler; -#[set(everything)] -const constants: { - invVP: float4x4; - eye: float3; - envmap_data: float4; // angle, sin(angle), cos(angle), strength - envmap_num_mipmaps: int; - camera_proj: float2; - eye_look: float3; - shirr0: float4; - shirr1: float4; - shirr2: float4; - shirr3: float4; - shirr4: float4; - shirr5: float4; - shirr6: float4; -}; - const PI: float = 3.14159265358979; const PI2: float = 6.28318530718; diff --git a/base/shaders/layer_copy.kong b/base/shaders/layer_copy.kong index 622dc8b1..4b2c0747 100644 --- a/base/shaders/layer_copy.kong +++ b/base/shaders/layer_copy.kong @@ -1,15 +1,15 @@ +#[set(everything)] +const constants: { + P: float4x4; +}; + #[set(everything)] const tex: tex2d; #[set(everything)] const tex_sampler: sampler; -#[set(everything)] -const constants: { - P: float4x4; -}; - struct vert_in { pos: float3; tex: float2; diff --git a/base/shaders/layer_copy_bgra.kong b/base/shaders/layer_copy_bgra.kong index 14d0afd3..bcb337b1 100644 --- a/base/shaders/layer_copy_bgra.kong +++ b/base/shaders/layer_copy_bgra.kong @@ -1,15 +1,15 @@ +#[set(everything)] +const constants: { + P: float4x4; +}; + #[set(everything)] const tex: tex2d; #[set(everything)] const tex_sampler: sampler; -#[set(everything)] -const constants: { - P: float4x4; -}; - struct vert_in { pos: float3; tex: float2; diff --git a/base/shaders/prefilter_envmap.kong b/base/shaders/prefilter_envmap.kong index 47907f9a..e04c64ba 100644 --- a/base/shaders/prefilter_envmap.kong +++ b/base/shaders/prefilter_envmap.kong @@ -1,15 +1,15 @@ +#[set(everything)] +const constants: { + params: float4; +}; + #[set(everything)] const radiance: tex2d; #[set(everything)] const radiance_sampler: sampler; -#[set(everything)] -const constants: { - params: float4; -}; - const PI: float = 3.14159265358979; const PI2: float = 6.28318530718; // #ifdef METAL diff --git a/base/shaders/ssao_blur_pass.kong b/base/shaders/ssao_blur_pass.kong index d6ee2d83..06960bfe 100644 --- a/base/shaders/ssao_blur_pass.kong +++ b/base/shaders/ssao_blur_pass.kong @@ -1,4 +1,9 @@ +#[set(everything)] +const constants: { + dir_inv: float2; +}; + #[set(everything)] const tex: tex2d; @@ -11,11 +16,6 @@ const gbuffer0: tex2d; #[set(everything)] const gbuffer0_sampler: sampler; -#[set(everything)] -const constants: { - dir_inv: float2; -}; - // const blur_weights: float[] = { // 0.132572, 0.125472, 0.106373, 0.08078, 0.05495, 0.033482, 0.018275, 0.008934, 0.003912, 0.001535 // }; diff --git a/base/shaders/ssao_pass.kong b/base/shaders/ssao_pass.kong index ddfd738e..034e9043 100644 --- a/base/shaders/ssao_pass.kong +++ b/base/shaders/ssao_pass.kong @@ -1,4 +1,12 @@ +#[set(everything)] +const constants: { + invP: float4x4; + P: float4x4; + V3: float3x3; + camera_proj: float2; +}; + #[set(everything)] const gbufferD: tex2d; @@ -11,14 +19,6 @@ const gbuffer0: tex2d; #[set(everything)] const gbuffer0_sampler: sampler; -#[set(everything)] -const constants: { - invP: float4x4; - P: float4x4; - V3: float3x3; - camera_proj: float2; -}; - const max_steps: float = 32; const ray_step: float = 0.001; diff --git a/base/shaders/supersample_resolve.kong b/base/shaders/supersample_resolve.kong index 7a2d55c8..8166a8b2 100644 --- a/base/shaders/supersample_resolve.kong +++ b/base/shaders/supersample_resolve.kong @@ -1,15 +1,15 @@ +#[set(everything)] +const constants: { + screen_size_inv: float2; +}; + #[set(everything)] const tex: tex2d; #[set(everything)] const tex_sampler: sampler; -#[set(everything)] -const constants: { - screen_size_inv: float2; -}; - struct vert_in { pos: float2; } diff --git a/base/shaders/taa_pass.kong b/base/shaders/taa_pass.kong index 954e874c..554974c1 100644 --- a/base/shaders/taa_pass.kong +++ b/base/shaders/taa_pass.kong @@ -1,4 +1,9 @@ +#[set(everything)] +const constants: { + taa_blend: float; +}; + #[set(everything)] const tex: tex2d; @@ -11,11 +16,6 @@ const tex2: tex2d; #[set(everything)] const tex2_sampler: sampler; -#[set(everything)] -const constants: { - taa_blend: float; -}; - struct vert_in { pos: float2; } diff --git a/base/sources/backends/metal_gpu.m b/base/sources/backends/metal_gpu.m index efb30f57..39a1a8ad 100644 --- a/base/sources/backends/metal_gpu.m +++ b/base/sources/backends/metal_gpu.m @@ -464,7 +464,7 @@ void iron_gpu_command_list_set_vertex_constant_buffer(iron_gpu_command_list_t *l void iron_gpu_command_list_set_fragment_constant_buffer(iron_gpu_command_list_t *list, struct iron_gpu_buffer *buffer, int offset, size_t size) { id buf = (__bridge id)buffer->impl._buffer; id encoder = getMetalEncoder(); - [encoder setFragmentBuffer:buf offset:offset atIndex:0]; + [encoder setFragmentBuffer:buf offset:offset atIndex:1]; } void iron_gpu_command_list_render_target_to_texture_barrier(iron_gpu_command_list_t *list, struct iron_gpu_texture *renderTarget) { diff --git a/base/sources/ts/node_shader.ts b/base/sources/ts/node_shader.ts index 6d7e00c9..085a45de 100644 --- a/base/sources/ts/node_shader.ts +++ b/base/sources/ts/node_shader.ts @@ -195,14 +195,6 @@ function node_shader_get(raw: node_shader_t): string { } s += "}\n\n"; - for (let i: i32 = 0; i < raw.textures.length; ++i) { - let a: string = raw.textures[i]; - s += "#[set(everything)]\n"; - s += "const " + a + ": tex2d;\n"; - s += "#[set(everything)]\n"; - s += "const " + a + "_sampler: sampler;\n\n"; - } - if (raw.constants.length > 0) { s += "#[set(everything)]\n"; s += "const constants: {\n"; @@ -213,6 +205,14 @@ function node_shader_get(raw: node_shader_t): string { s += "};\n\n"; } + for (let i: i32 = 0; i < raw.textures.length; ++i) { + let a: string = raw.textures[i]; + s += "#[set(everything)]\n"; + s += "const " + a + ": tex2d;\n"; + s += "#[set(everything)]\n"; + s += "const " + a + "_sampler: sampler;\n\n"; + } + for (let i: i32 = 0; i < raw.shared_samplers.length; ++i) { let a: string = raw.shared_samplers[i]; s += "#[set(everything)]\n";