summaryrefslogtreecommitdiffstats
path: root/third_party/rust/gfx-backend-metal/shaders
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/gfx-backend-metal/shaders')
-rw-r--r--third_party/rust/gfx-backend-metal/shaders/blit.metal110
-rw-r--r--third_party/rust/gfx-backend-metal/shaders/clear.metal79
-rw-r--r--third_party/rust/gfx-backend-metal/shaders/fill.metal33
-rw-r--r--third_party/rust/gfx-backend-metal/shaders/gfx-shaders-ios-simulator.metallibbin0 -> 98746 bytes
-rw-r--r--third_party/rust/gfx-backend-metal/shaders/gfx-shaders-ios.metallibbin0 -> 92304 bytes
-rw-r--r--third_party/rust/gfx-backend-metal/shaders/gfx-shaders-macos.metallibbin0 -> 90314 bytes
-rw-r--r--third_party/rust/gfx-backend-metal/shaders/macros.h5
7 files changed, 227 insertions, 0 deletions
diff --git a/third_party/rust/gfx-backend-metal/shaders/blit.metal b/third_party/rust/gfx-backend-metal/shaders/blit.metal
new file mode 100644
index 0000000000..9fcaf1c2b0
--- /dev/null
+++ b/third_party/rust/gfx-backend-metal/shaders/blit.metal
@@ -0,0 +1,110 @@
+#include "macros.h"
+#include <metal_stdlib>
+using namespace metal;
+
+typedef struct {
+ float4 src_coords [[attribute(0)]];
+ float4 dst_coords [[attribute(1)]];
+} BlitAttributes;
+
+typedef struct {
+ float4 position [[position]];
+ float4 uv;
+ uint layer GFX_RENDER_TARGET_ARRAY_INDEX;
+} BlitVertexData;
+
+typedef struct {
+ float depth [[depth(any)]];
+} BlitDepthFragment;
+
+
+vertex BlitVertexData vs_blit(BlitAttributes in [[stage_in]]) {
+ float4 pos = { 0.0, 0.0, in.dst_coords.z, 1.0f };
+ pos.xy = in.dst_coords.xy * 2.0 - 1.0;
+ return BlitVertexData { pos, in.src_coords, uint(in.dst_coords.w) };
+}
+
+fragment float4 ps_blit_1d_float(
+ BlitVertexData in [[stage_in]],
+ texture1d<float> tex1D [[ texture(0) ]],
+ sampler sampler2D [[ sampler(0) ]]
+) {
+ return tex1D.sample(sampler2D, in.uv.x);
+}
+
+
+fragment float4 ps_blit_1d_array_float(
+ BlitVertexData in [[stage_in]],
+ texture1d_array<float> tex1DArray [[ texture(0) ]],
+ sampler sampler2D [[ sampler(0) ]]
+) {
+ return tex1DArray.sample(sampler2D, in.uv.x, uint(in.uv.z));
+}
+
+
+fragment float4 ps_blit_2d_float(
+ BlitVertexData in [[stage_in]],
+ texture2d<float> tex2D [[ texture(0) ]],
+ sampler sampler2D [[ sampler(0) ]]
+) {
+ return tex2D.sample(sampler2D, in.uv.xy, level(in.uv.w));
+}
+
+fragment uint4 ps_blit_2d_uint(
+ BlitVertexData in [[stage_in]],
+ texture2d<uint> tex2D [[ texture(0) ]],
+ sampler sampler2D [[ sampler(0) ]]
+) {
+ return tex2D.sample(sampler2D, in.uv.xy, level(in.uv.w));
+}
+
+fragment int4 ps_blit_2d_int(
+ BlitVertexData in [[stage_in]],
+ texture2d<int> tex2D [[ texture(0) ]],
+ sampler sampler2D [[ sampler(0) ]]
+) {
+ return tex2D.sample(sampler2D, in.uv.xy, level(in.uv.w));
+}
+
+fragment BlitDepthFragment ps_blit_2d_depth(
+ BlitVertexData in [[stage_in]],
+ depth2d<float> tex2D [[ texture(0) ]],
+ sampler sampler2D [[ sampler(0) ]]
+) {
+ float depth = tex2D.sample(sampler2D, in.uv.xy, level(in.uv.w));
+ return BlitDepthFragment { depth };
+}
+
+
+fragment float4 ps_blit_2d_array_float(
+ BlitVertexData in [[stage_in]],
+ texture2d_array<float> tex2DArray [[ texture(0) ]],
+ sampler sampler2D [[ sampler(0) ]]
+) {
+ return tex2DArray.sample(sampler2D, in.uv.xy, uint(in.uv.z), level(in.uv.w));
+}
+
+fragment uint4 ps_blit_2d_array_uint(
+ BlitVertexData in [[stage_in]],
+ texture2d_array<uint> tex2DArray [[ texture(0) ]],
+ sampler sampler2D [[ sampler(0) ]]
+) {
+ return tex2DArray.sample(sampler2D, in.uv.xy, uint(in.uv.z), level(in.uv.w));
+}
+
+fragment int4 ps_blit_2d_array_int(
+ BlitVertexData in [[stage_in]],
+ texture2d_array<int> tex2DArray [[ texture(0) ]],
+ sampler sampler2D [[ sampler(0) ]]
+) {
+ return tex2DArray.sample(sampler2D, in.uv.xy, uint(in.uv.z), level(in.uv.w));
+}
+
+
+fragment float4 ps_blit_3d_float(
+ BlitVertexData in [[stage_in]],
+ texture3d<float> tex3D [[ texture(0) ]],
+ sampler sampler2D [[ sampler(0) ]]
+) {
+ return tex3D.sample(sampler2D, in.uv.xyz, level(in.uv.w));
+}
diff --git a/third_party/rust/gfx-backend-metal/shaders/clear.metal b/third_party/rust/gfx-backend-metal/shaders/clear.metal
new file mode 100644
index 0000000000..4adbdd3b56
--- /dev/null
+++ b/third_party/rust/gfx-backend-metal/shaders/clear.metal
@@ -0,0 +1,79 @@
+#include "macros.h"
+#include <metal_stdlib>
+using namespace metal;
+
+//TODO: simplified code path for Metal 2.0?
+//> Starting in Metal 2.0, the [[color(n)]] and [[raster_order_group(index)]] indices can
+//> also be a function constant. The function constant specified as indices for color and
+//> raster order group attributes must be a scalar integer type.
+
+typedef struct {
+ float4 coords [[attribute(0)]];
+} ClearAttributes;
+
+typedef struct {
+ float4 position [[position]];
+ uint layer GFX_RENDER_TARGET_ARRAY_INDEX;
+} ClearVertexData;
+
+vertex ClearVertexData vs_clear(ClearAttributes in [[stage_in]]) {
+ float4 pos = { 0.0, 0.0, in.coords.z, 1.0f };
+ pos.xy = in.coords.xy * 2.0 - 1.0;
+ return ClearVertexData { pos, uint(in.coords.w) };
+}
+
+
+fragment float4 ps_clear0_float(
+ ClearVertexData in [[stage_in]],
+ constant float4 &value [[ buffer(0) ]]
+) {
+ return value;
+}
+
+fragment int4 ps_clear0_int(
+ ClearVertexData in [[stage_in]],
+ constant int4 &value [[ buffer(0) ]]
+) {
+ return value;
+}
+
+fragment uint4 ps_clear0_uint(
+ ClearVertexData in [[stage_in]],
+ constant uint4 &value [[ buffer(0) ]]
+) {
+ return value;
+}
+
+
+typedef struct {
+ float4 color [[color(1)]];
+} Clear1FloatFragment;
+
+fragment Clear1FloatFragment ps_clear1_float(
+ ClearVertexData in [[stage_in]],
+ constant float4 &value [[ buffer(0) ]]
+) {
+ return Clear1FloatFragment { value };
+}
+
+typedef struct {
+ int4 color [[color(1)]];
+} Clear1IntFragment;
+
+fragment Clear1IntFragment ps_clear1_int(
+ ClearVertexData in [[stage_in]],
+ constant int4 &value [[ buffer(0) ]]
+) {
+ return Clear1IntFragment { value };
+}
+
+typedef struct {
+ uint4 color [[color(1)]];
+} Clear1UintFragment;
+
+fragment Clear1UintFragment ps_clear1_uint(
+ ClearVertexData in [[stage_in]],
+ constant uint4 &value [[ buffer(0) ]]
+) {
+ return Clear1UintFragment { value };
+}
diff --git a/third_party/rust/gfx-backend-metal/shaders/fill.metal b/third_party/rust/gfx-backend-metal/shaders/fill.metal
new file mode 100644
index 0000000000..fffe9b4a07
--- /dev/null
+++ b/third_party/rust/gfx-backend-metal/shaders/fill.metal
@@ -0,0 +1,33 @@
+#include <metal_stdlib>
+using namespace metal;
+
+typedef struct {
+ uint value;
+ uint length;
+} FillBufferValue;
+
+kernel void cs_fill_buffer(
+ device uint *buffer [[ buffer(0) ]],
+ constant FillBufferValue &fill [[ buffer(1) ]],
+ uint index [[ thread_position_in_grid ]]
+) {
+ if (index < fill.length) {
+ buffer[index] = fill.value;
+ }
+}
+
+typedef struct {
+ uint size;
+ uint offsets;
+} CopyBufferRange;
+
+kernel void cs_copy_buffer(
+ device uchar *dest [[ buffer(0) ]],
+ device uchar *source [[ buffer(1) ]],
+ constant CopyBufferRange &range [[ buffer(2) ]],
+ uint index [[ thread_position_in_grid ]]
+) {
+ if (index < range.size) {
+ dest[(range.offsets>>16) + index] = source[(range.offsets & 0xFFFF) + index];
+ }
+}
diff --git a/third_party/rust/gfx-backend-metal/shaders/gfx-shaders-ios-simulator.metallib b/third_party/rust/gfx-backend-metal/shaders/gfx-shaders-ios-simulator.metallib
new file mode 100644
index 0000000000..8bd51deb32
--- /dev/null
+++ b/third_party/rust/gfx-backend-metal/shaders/gfx-shaders-ios-simulator.metallib
Binary files differ
diff --git a/third_party/rust/gfx-backend-metal/shaders/gfx-shaders-ios.metallib b/third_party/rust/gfx-backend-metal/shaders/gfx-shaders-ios.metallib
new file mode 100644
index 0000000000..ab7ac50469
--- /dev/null
+++ b/third_party/rust/gfx-backend-metal/shaders/gfx-shaders-ios.metallib
Binary files differ
diff --git a/third_party/rust/gfx-backend-metal/shaders/gfx-shaders-macos.metallib b/third_party/rust/gfx-backend-metal/shaders/gfx-shaders-macos.metallib
new file mode 100644
index 0000000000..48553fff4f
--- /dev/null
+++ b/third_party/rust/gfx-backend-metal/shaders/gfx-shaders-macos.metallib
Binary files differ
diff --git a/third_party/rust/gfx-backend-metal/shaders/macros.h b/third_party/rust/gfx-backend-metal/shaders/macros.h
new file mode 100644
index 0000000000..b731190479
--- /dev/null
+++ b/third_party/rust/gfx-backend-metal/shaders/macros.h
@@ -0,0 +1,5 @@
+#ifdef __METAL_MACOS__
+# define GFX_RENDER_TARGET_ARRAY_INDEX [[render_target_array_index]]
+#else
+# define GFX_RENDER_TARGET_ARRAY_INDEX
+#endif