From 639ae6520ad65609fcdaf5cfcf85415f10623f14 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 11 Aug 2019 14:42:35 +0200 Subject: [PATCH] ThreadIds struct refactored --- src/DirectX12ComputeShaderSample/Gpu.cs | 2 +- src/DirectX12ComputeShaderSample/Program.cs | 2 +- .../Numerics/ThreadIds.cs | 23 +++++++++++++++++++ .../Numerics/UInt2.cs | 9 -------- .../Numerics/UInt3.cs | 13 ----------- .../ShaderGenerator.cs | 13 +++++------ 6 files changed, 31 insertions(+), 31 deletions(-) create mode 100644 src/DirectX12GameEngine.Shaders/Numerics/ThreadIds.cs delete mode 100644 src/DirectX12GameEngine.Shaders/Numerics/UInt2.cs delete mode 100644 src/DirectX12GameEngine.Shaders/Numerics/UInt3.cs diff --git a/src/DirectX12ComputeShaderSample/Gpu.cs b/src/DirectX12ComputeShaderSample/Gpu.cs index 7e122ace..1667f05b 100644 --- a/src/DirectX12ComputeShaderSample/Gpu.cs +++ b/src/DirectX12ComputeShaderSample/Gpu.cs @@ -19,7 +19,7 @@ namespace DirectX12ComputeShaderSample public static class GraphicsDeviceExtensions { - public static void For(this GraphicsDevice device, int n, Action shader) + public static void For(this GraphicsDevice device, int n, Action shader) { // Generate the compute shadr ShaderGenerator shaderGenerator = new ShaderGenerator(shader); diff --git a/src/DirectX12ComputeShaderSample/Program.cs b/src/DirectX12ComputeShaderSample/Program.cs index 33ffa741..f962f141 100644 --- a/src/DirectX12ComputeShaderSample/Program.cs +++ b/src/DirectX12ComputeShaderSample/Program.cs @@ -27,7 +27,7 @@ namespace DirectX12ComputeShaderSample var data = gpuBuffer.GetGpuResource(); // Shader body - Action action = id => + Action action = id => { data[id.X + id.Y * size] *= 2; }; diff --git a/src/DirectX12GameEngine.Shaders/Numerics/ThreadIds.cs b/src/DirectX12GameEngine.Shaders/Numerics/ThreadIds.cs new file mode 100644 index 00000000..8acc868a --- /dev/null +++ b/src/DirectX12GameEngine.Shaders/Numerics/ThreadIds.cs @@ -0,0 +1,23 @@ +namespace DirectX12GameEngine.Shaders.Numerics +{ + /// + /// A that indicates the ids of a given GPU thread running a compute shader + /// + public readonly struct ThreadIds + { + /// + /// The X id of the current thread + /// + public readonly uint X; + + /// + /// The Y id of the current thread + /// + public readonly uint Y; + + /// + /// The Z id of the current thread + /// + public readonly uint Z; + } +} diff --git a/src/DirectX12GameEngine.Shaders/Numerics/UInt2.cs b/src/DirectX12GameEngine.Shaders/Numerics/UInt2.cs deleted file mode 100644 index 719c2b8a..00000000 --- a/src/DirectX12GameEngine.Shaders/Numerics/UInt2.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace DirectX12GameEngine.Shaders.Numerics -{ - public struct UInt2 - { - public uint X; - - public uint Y; - } -} diff --git a/src/DirectX12GameEngine.Shaders/Numerics/UInt3.cs b/src/DirectX12GameEngine.Shaders/Numerics/UInt3.cs deleted file mode 100644 index 8cd63223..00000000 --- a/src/DirectX12GameEngine.Shaders/Numerics/UInt3.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace DirectX12GameEngine.Shaders.Numerics -{ - public struct UInt3 - { - public uint X; - - public uint Y; - - public uint Z; - - public UInt2 XY => new UInt2 { X = X, Y = Y }; - } -} diff --git a/src/DirectX12GameEngine.Shaders/ShaderGenerator.cs b/src/DirectX12GameEngine.Shaders/ShaderGenerator.cs index fd2fa6e9..8b4a9dfe 100644 --- a/src/DirectX12GameEngine.Shaders/ShaderGenerator.cs +++ b/src/DirectX12GameEngine.Shaders/ShaderGenerator.cs @@ -102,7 +102,7 @@ namespace DirectX12GameEngine.Shaders { if (result != null) return result; - if (!(shader is Action action)) throw new InvalidOperationException("Missing lambda shader"); + if (!(shader is Action action)) throw new InvalidOperationException("Missing lambda shader"); Type shaderType = action.Method.DeclaringType; object shaderInstance = action.Target; @@ -498,9 +498,8 @@ namespace DirectX12GameEngine.Shaders { typeof(Vector2).FullName, "float2" }, { typeof(Vector3).FullName, "float3" }, { typeof(Vector4).FullName, "float4" }, - { typeof(Numerics.UInt2).FullName, "uint2" }, - { typeof(Numerics.UInt3).FullName, "uint3" }, { typeof(Matrix4x4).FullName, "float4x4" }, + { typeof(ThreadIds).FullName, "uint3" }, { typeof(RWBufferResource<>).FullName, "RWBuffer" }, }; @@ -562,10 +561,10 @@ namespace DirectX12GameEngine.Shaders { "DirectX12GameEngine.Shaders.Numerics.UInt2.X", ".x" }, { "DirectX12GameEngine.Shaders.Numerics.UInt2.Y", ".y" }, - { "DirectX12GameEngine.Shaders.Numerics.UInt3.X", ".x" }, - { "DirectX12GameEngine.Shaders.Numerics.UInt3.Y", ".y" }, - { "DirectX12GameEngine.Shaders.Numerics.UInt3.Z", ".z" }, - { "DirectX12GameEngine.Shaders.Numerics.UInt3.XY", ".xy" }, + { "DirectX12GameEngine.Shaders.Numerics.ThreadIds.X", ".x" }, + { "DirectX12GameEngine.Shaders.Numerics.ThreadIds.Y", ".y" }, + { "DirectX12GameEngine.Shaders.Numerics.ThreadIds.Z", ".z" }, + { "DirectX12GameEngine.Shaders.Numerics.ThreadIds.XY", ".xy" }, { "System.Numerics.Vector3.X", ".x" }, { "System.Numerics.Vector3.Y", ".y" },