diff --git a/src/ComputeSharp.Dynamic/Shaders/Interop/ReflectionServices.cs b/src/ComputeSharp.Dynamic/Shaders/Interop/ReflectionServices.cs
index f9cbd999..394b55f3 100644
--- a/src/ComputeSharp.Dynamic/Shaders/Interop/ReflectionServices.cs
+++ b/src/ComputeSharp.Dynamic/Shaders/Interop/ReflectionServices.cs
@@ -25,16 +25,16 @@ public static class ReflectionServices
///
///
/// The type of compute shader to retrieve info for.
- /// The resulting instance.
+ /// The resulting instance.
///
/// The thread group sizes will always be set to (1, 1, 1) in the returned shader. This is done to
/// avoid having to compiler multiple shaders just to get reflection info for them. When using any of
/// the APIs to dispatch a shader, the thread sizes would actually be set to a proper value insead.
///
- public static void GetShaderInfo(out ShaderInfo shaderInfo)
+ public static ShaderInfo GetShaderInfo()
where T : struct, IComputeShader
{
- GetNonGenericShaderInfo(default(T), out shaderInfo);
+ return GetNonGenericShaderInfo(default(T));
}
///
@@ -42,16 +42,16 @@ public static class ReflectionServices
///
/// The type of compute shader to retrieve info for.
/// The input compute shader to retrieve info for.
- /// The resulting instance.
+ /// The resulting instance.
///
/// The thread group sizes will always be set to (1, 1, 1) in the returned shader. This is done to
/// avoid having to compiler multiple shaders just to get reflection info for them. When using any of
/// the APIs to dispatch a shader, the thread sizes would actually be set to a proper value insead.
///
- public static unsafe void GetShaderInfo(in T shader, out ShaderInfo shaderInfo)
+ public static unsafe ShaderInfo GetShaderInfo(in T shader)
where T : struct, IComputeShader
{
- GetNonGenericShaderInfo(in shader, out shaderInfo);
+ return GetNonGenericShaderInfo(in shader);
}
///
@@ -63,17 +63,17 @@ public static class ReflectionServices
///
/// The type of pixel shader to retrieve info for.
/// The type of pixels being processed by the shader.
- /// The resulting instance.
+ /// The resulting instance.
///
/// The thread group sizes will always be set to (1, 1, 1) in the returned shader. This is done to
/// avoid having to compiler multiple shaders just to get reflection info for them. When using any of
/// the APIs to dispatch a shader, the thread sizes would actually be set to a proper value insead.
///
- public static void GetShaderInfo(out ShaderInfo shaderInfo)
+ public static ShaderInfo GetShaderInfo()
where T : struct, IPixelShader
where TPixel : unmanaged
{
- GetNonGenericShaderInfo(default(T), out shaderInfo);
+ return GetNonGenericShaderInfo(default(T));
}
///
@@ -82,17 +82,17 @@ public static class ReflectionServices
/// The type of pixel shader to retrieve info for.
/// The type of pixels being processed by the shader.
/// The input pixel shader to retrieve info for.
- /// The resulting instance.
+ /// The resulting instance.
///
/// The thread group sizes will always be set to (1, 1, 1) in the returned shader. This is done to
/// avoid having to compiler multiple shaders just to get reflection info for them. When using any of
/// the APIs to dispatch a shader, the thread sizes would actually be set to a proper value insead.
///
- public static unsafe void GetShaderInfo(in T shader, out ShaderInfo shaderInfo)
+ public static unsafe ShaderInfo GetShaderInfo(in T shader)
where T : struct, IPixelShader
where TPixel : unmanaged
{
- GetNonGenericShaderInfo(in shader, out shaderInfo);
+ return GetNonGenericShaderInfo(in shader);
}
///
@@ -100,8 +100,8 @@ public static class ReflectionServices
///
/// The type of shader to retrieve info for.
/// The input shader to retrieve info for.
- /// The resulting instance.
- private static unsafe void GetNonGenericShaderInfo(in T shader, out ShaderInfo shaderInfo)
+ /// The resulting instance.
+ private static unsafe ShaderInfo GetNonGenericShaderInfo(in T shader)
where T : struct, IShader
{
Unsafe.AsRef(in shader).BuildHlslString(out ArrayPoolStringBuilder shaderSource, 1, 1, 1);
@@ -132,31 +132,31 @@ public static class ReflectionServices
d3D12ShaderReflection.Get()->GetDesc(&d3D12ShaderDescription).Assert();
- shaderInfo = default;
- Unsafe.AsRef(shaderInfo.CompilerVersion) = new string(d3D12ShaderDescription.Creator);
- Unsafe.AsRef(shaderInfo.HlslSource) = shaderSource.WrittenSpan.ToString();
- Unsafe.AsRef(shaderInfo.ConstantBufferCount) = d3D12ShaderDescription.ConstantBuffers;
- Unsafe.AsRef(shaderInfo.BoundResourceCount) = d3D12ShaderDescription.BoundResources;
- Unsafe.AsRef(shaderInfo.InstructionCount) = d3D12ShaderDescription.InstructionCount;
- Unsafe.AsRef(shaderInfo.TemporaryRegisterCount) = d3D12ShaderDescription.TempRegisterCount;
- Unsafe.AsRef(shaderInfo.TemporaryArrayCount) = d3D12ShaderDescription.TempArrayCount;
- Unsafe.AsRef(shaderInfo.ConstantDefineCount) = d3D12ShaderDescription.DefCount;
- Unsafe.AsRef(shaderInfo.DeclarationCount) = d3D12ShaderDescription.DclCount;
- Unsafe.AsRef(shaderInfo.TextureNormalInstructions) = d3D12ShaderDescription.TextureNormalInstructions;
- Unsafe.AsRef(shaderInfo.TextureLoadInstructionCount) = d3D12ShaderDescription.TextureLoadInstructions;
- Unsafe.AsRef(shaderInfo.TextureStoreInstructionCount) = d3D12ShaderDescription.cTextureStoreInstructions;
- Unsafe.AsRef(shaderInfo.FloatInstructionCount) = d3D12ShaderDescription.FloatInstructionCount;
- Unsafe.AsRef(shaderInfo.IntInstructionCount) = d3D12ShaderDescription.IntInstructionCount;
- Unsafe.AsRef(shaderInfo.UIntInstructionCount) = d3D12ShaderDescription.UintInstructionCount;
- Unsafe.AsRef(shaderInfo.StaticFlowControlInstructionCount) = d3D12ShaderDescription.StaticFlowControlCount;
- Unsafe.AsRef(shaderInfo.DynamicFlowControlInstructionCount) = d3D12ShaderDescription.DynamicFlowControlCount;
- Unsafe.AsRef(shaderInfo.EmitInstructionCount) = d3D12ShaderDescription.EmitInstructionCount;
- Unsafe.AsRef(shaderInfo.BarrierInstructionCount) = d3D12ShaderDescription.cBarrierInstructions;
- Unsafe.AsRef(shaderInfo.InterlockedInstructionCount) = d3D12ShaderDescription.cInterlockedInstructions;
- Unsafe.AsRef(shaderInfo.BitwiseInstructionCount) = d3D12ShaderReflection.Get()->GetBitwiseInstructionCount();
- Unsafe.AsRef(shaderInfo.MovcInstructionCount) = d3D12ShaderReflection.Get()->GetMovcInstructionCount();
- Unsafe.AsRef(shaderInfo.MovInstructionCount) = d3D12ShaderReflection.Get()->GetMovInstructionCount();
- Unsafe.AsRef(shaderInfo.InterfaceSlotCount) = d3D12ShaderReflection.Get()->GetNumInterfaceSlots();
- Unsafe.AsRef(shaderInfo.RequiresDoublePrecisionSupport) = (d3D12ShaderReflection.Get()->GetRequiresFlags() & (D3D.D3D_SHADER_REQUIRES_DOUBLES | D3D.D3D_SHADER_REQUIRES_11_1_DOUBLE_EXTENSIONS)) != 0;
+ return new(
+ CompilerVersion: new string(d3D12ShaderDescription.Creator),
+ HlslSource: shaderSource.WrittenSpan.ToString(),
+ ConstantBufferCount: d3D12ShaderDescription.ConstantBuffers,
+ BoundResourceCount: d3D12ShaderDescription.BoundResources,
+ InstructionCount: d3D12ShaderDescription.InstructionCount,
+ TemporaryRegisterCount: d3D12ShaderDescription.TempRegisterCount,
+ TemporaryArrayCount: d3D12ShaderDescription.TempArrayCount,
+ ConstantDefineCount: d3D12ShaderDescription.DefCount,
+ DeclarationCount: d3D12ShaderDescription.DclCount,
+ TextureNormalInstructions: d3D12ShaderDescription.TextureNormalInstructions,
+ TextureLoadInstructionCount: d3D12ShaderDescription.TextureLoadInstructions,
+ TextureStoreInstructionCount: d3D12ShaderDescription.cTextureStoreInstructions,
+ FloatInstructionCount: d3D12ShaderDescription.FloatInstructionCount,
+ IntInstructionCount: d3D12ShaderDescription.IntInstructionCount,
+ UIntInstructionCount: d3D12ShaderDescription.UintInstructionCount,
+ StaticFlowControlInstructionCount: d3D12ShaderDescription.StaticFlowControlCount,
+ DynamicFlowControlInstructionCount: d3D12ShaderDescription.DynamicFlowControlCount,
+ EmitInstructionCount: d3D12ShaderDescription.EmitInstructionCount,
+ BarrierInstructionCount: d3D12ShaderDescription.cBarrierInstructions,
+ InterlockedInstructionCount: d3D12ShaderDescription.cInterlockedInstructions,
+ BitwiseInstructionCount: d3D12ShaderReflection.Get()->GetBitwiseInstructionCount(),
+ MovcInstructionCount: d3D12ShaderReflection.Get()->GetMovcInstructionCount(),
+ MovInstructionCount: d3D12ShaderReflection.Get()->GetMovInstructionCount(),
+ InterfaceSlotCount: d3D12ShaderReflection.Get()->GetNumInterfaceSlots(),
+ RequiresDoublePrecisionSupport: (d3D12ShaderReflection.Get()->GetRequiresFlags() & (D3D.D3D_SHADER_REQUIRES_DOUBLES | D3D.D3D_SHADER_REQUIRES_11_1_DOUBLE_EXTENSIONS)) != 0);
}
}
diff --git a/src/ComputeSharp.Dynamic/Shaders/Interop/ShaderInfo.cs b/src/ComputeSharp.Dynamic/Shaders/Interop/ShaderInfo.cs
index 3403f74b..f69667e5 100644
--- a/src/ComputeSharp.Dynamic/Shaders/Interop/ShaderInfo.cs
+++ b/src/ComputeSharp.Dynamic/Shaders/Interop/ShaderInfo.cs
@@ -3,130 +3,54 @@
///
/// A model representing reflection info for a given compute shader.
///
-public readonly struct ShaderInfo
-{
- ///
- /// The compiler version used to build the shader.
- ///
- public readonly string CompilerVersion;
-
- ///
- /// The HLSL source code the shader was built from.
- ///
- public readonly string HlslSource;
-
- ///
- /// The number of shader constant buffers.
- ///
- public readonly uint ConstantBufferCount;
-
- ///
- /// The number of resource (textures and buffers) bound to a shader.
- ///
- public readonly uint BoundResourceCount;
-
- ///
- /// The number of intermediate-language instructions in the compiled shader.
- ///
- public readonly uint InstructionCount;
-
- ///
- /// The number of temporary registers in the compiled shader.
- ///
- public readonly uint TemporaryRegisterCount;
-
- ///
- /// The number of temporary arrays used.
- ///
- public readonly uint TemporaryArrayCount;
-
- ///
- /// The number of constant defines.
- ///
- public readonly uint ConstantDefineCount;
-
- ///
- /// The number of declarations (input + output).
- ///
- public readonly uint DeclarationCount;
-
- ///
- /// The number of non-categorized texture instructions.
- ///
- public readonly uint TextureNormalInstructions;
-
- ///
- /// The number of texture load instructions.
- ///
- public readonly uint TextureLoadInstructionCount;
-
- ///
- /// The number of texture write instructions.
- ///
- public readonly uint TextureStoreInstructionCount;
-
- ///
- /// The number of floating point arithmetic instructions used.
- ///
- public readonly uint FloatInstructionCount;
-
- ///
- /// The number of signed integer arithmetic instructions used.
- ///
- public readonly uint IntInstructionCount;
-
- ///
- /// The number of unsigned integer arithmetic instructions used.
- ///
- public readonly uint UIntInstructionCount;
-
- ///
- /// The number of static flow control instructions used.
- ///
- public readonly uint StaticFlowControlInstructionCount;
-
- ///
- /// The number of dynamic flow control instructions used.
- ///
- public readonly uint DynamicFlowControlInstructionCount;
-
- ///
- /// The number of emit instructions used.
- ///
- public readonly uint EmitInstructionCount;
-
- ///
- /// The number of barrier instructions used.
- ///
- public readonly uint BarrierInstructionCount;
-
- ///
- /// The number of interlocked instructions used.
- ///
- public readonly uint InterlockedInstructionCount;
-
- ///
- /// The number of bitwise instructions used.
- ///
- public readonly uint BitwiseInstructionCount;
-
- ///
- /// The number of movc instructions used.
- ///
- public readonly uint MovcInstructionCount;
-
- ///
- /// The number of mov instructions used.
- ///
- public readonly uint MovInstructionCount;
-
- ///
- /// The number of interface slots used.
- ///
- public readonly uint InterfaceSlotCount;
-
- ///
- /// Indicates whether support for double precision floating point numbers is required.
- ///
- public readonly bool RequiresDoublePrecisionSupport;
-}
+/// The compiler version used to build the shader.
+/// The HLSL source code the shader was built from.
+/// The number of shader constant buffers.
+/// The number of resource (textures and buffers) bound to a shader.
+/// The number of intermediate-language instructions in the compiled shader.
+/// The number of temporary registers in the compiled shader.
+/// The number of temporary arrays used.
+/// The number of constant defines.
+/// The number of declarations (input + output).
+/// The number of non-categorized texture instructions.
+/// The number of texture load instructions.
+/// The number of texture write instructions.
+/// The number of floating point arithmetic instructions used.
+/// The number of signed integer arithmetic instructions used.
+/// The number of unsigned integer arithmetic instructions used.
+/// The number of static flow control instructions used.
+/// The number of dynamic flow control instructions used.
+/// The number of emit instructions used.
+/// The number of barrier instructions used.
+/// The number of interlocked instructions used.
+/// The number of bitwise instructions used.
+/// The number of movc instructions used.
+/// The number of mov instructions used.
+/// The number of interface slots used.
+/// Indicates whether support for double precision floating point numbers is required.
+public sealed record ShaderInfo(
+ string CompilerVersion,
+ string HlslSource,
+ uint ConstantBufferCount,
+ uint BoundResourceCount,
+ uint InstructionCount,
+ uint TemporaryRegisterCount,
+ uint TemporaryArrayCount,
+ uint ConstantDefineCount,
+ uint DeclarationCount,
+ uint TextureNormalInstructions,
+ uint TextureLoadInstructionCount,
+ uint TextureStoreInstructionCount,
+ uint FloatInstructionCount,
+ uint IntInstructionCount,
+ uint UIntInstructionCount,
+ uint StaticFlowControlInstructionCount,
+ uint DynamicFlowControlInstructionCount,
+ uint EmitInstructionCount,
+ uint BarrierInstructionCount,
+ uint InterlockedInstructionCount,
+ uint BitwiseInstructionCount,
+ uint MovcInstructionCount,
+ uint MovInstructionCount,
+ uint InterfaceSlotCount,
+ bool RequiresDoublePrecisionSupport);
diff --git a/tests/ComputeSharp.Tests/DispatchTests.cs b/tests/ComputeSharp.Tests/DispatchTests.cs
index b4078328..e6a674fd 100644
--- a/tests/ComputeSharp.Tests/DispatchTests.cs
+++ b/tests/ComputeSharp.Tests/DispatchTests.cs
@@ -237,7 +237,7 @@ public partial class DispatchTests
device.Get().For(11, 22, 3, new DispatchSizeShader(buffer));
- ReflectionServices.GetShaderInfo(out var info);
+ ShaderInfo info = ReflectionServices.GetShaderInfo();
int[] data = buffer.ToArray();
diff --git a/tests/ComputeSharp.Tests/ShaderCompilerTests.cs b/tests/ComputeSharp.Tests/ShaderCompilerTests.cs
index 22493747..9996ffb9 100644
--- a/tests/ComputeSharp.Tests/ShaderCompilerTests.cs
+++ b/tests/ComputeSharp.Tests/ShaderCompilerTests.cs
@@ -12,7 +12,7 @@ namespace ComputeSharp.Tests
[TestMethod]
public void ReservedKeywords()
{
- ReflectionServices.GetShaderInfo(out _);
+ _ = ReflectionServices.GetShaderInfo();
}
[AutoConstructor]
@@ -33,7 +33,7 @@ namespace ComputeSharp.Tests
[TestMethod]
public void SpecialTypeAsReturnType()
{
- ReflectionServices.GetShaderInfo(out _);
+ _ = ReflectionServices.GetShaderInfo();
}
[AutoConstructor]
@@ -54,7 +54,7 @@ namespace ComputeSharp.Tests
[TestMethod]
public void LocalFunctionInExternalMethods()
{
- ReflectionServices.GetShaderInfo(out _);
+ _ = ReflectionServices.GetShaderInfo();
}
[AutoConstructor]
@@ -78,7 +78,7 @@ namespace ComputeSharp.Tests
[TestMethod]
public void CapturedNestedStructType()
{
- ReflectionServices.GetShaderInfo(out _);
+ _ = ReflectionServices.GetShaderInfo();
}
[AutoConstructor]
@@ -104,7 +104,7 @@ namespace ComputeSharp.Tests
[TestMethod]
public void ExternalStructType_Ok()
{
- ReflectionServices.GetShaderInfo(out var info);
+ _ = ReflectionServices.GetShaderInfo();
}
[AutoConstructor]
@@ -125,7 +125,7 @@ namespace ComputeSharp.Tests
[TestMethod]
public void OutOfOrderMethods()
{
- ReflectionServices.GetShaderInfo(out var info);
+ _ = ReflectionServices.GetShaderInfo();
}
[AutoConstructor]
@@ -158,7 +158,7 @@ namespace ComputeSharp.Tests
[TestMethod]
public void PixelShader()
{
- ReflectionServices.GetShaderInfo(out var info);
+ ShaderInfo info = ReflectionServices.GetShaderInfo();
Assert.AreEqual(info.TextureStoreInstructionCount, 1u);
Assert.AreEqual(info.BoundResourceCount, 2u);
@@ -191,13 +191,13 @@ namespace ComputeSharp.Tests
[TestMethod]
public void LoopWithVarCounter()
{
- ReflectionServices.GetShaderInfo(out var info);
+ _ = ReflectionServices.GetShaderInfo();
}
[TestMethod]
public void DoublePrecisionSupport()
{
- ReflectionServices.GetShaderInfo(out var info);
+ ShaderInfo info = ReflectionServices.GetShaderInfo();
Assert.IsTrue(info.RequiresDoublePrecisionSupport);
}
@@ -241,7 +241,7 @@ namespace ExternalNamespace
[TestMethod]
public void UserDefinedType()
{
- ReflectionServices.GetShaderInfo(out var info);
+ _ = ReflectionServices.GetShaderInfo();
}
}
}
diff --git a/tests/ComputeSharp.Tests/ShadersTests.cs b/tests/ComputeSharp.Tests/ShadersTests.cs
index 580d610f..31a9b1e0 100644
--- a/tests/ComputeSharp.Tests/ShadersTests.cs
+++ b/tests/ComputeSharp.Tests/ShadersTests.cs
@@ -95,7 +95,7 @@ public class ShadersTests
[Data(typeof(SwapChain.Shaders.Compute.ExtrudedTruchetPattern))]
public void ExtrudedTruchetPattern(Device device, Type shaderType)
{
- ReflectionServices.GetShaderInfo(out var info);
+ ShaderInfo info = ReflectionServices.GetShaderInfo();
Assert.IsFalse(info.RequiresDoublePrecisionSupport);
@@ -161,7 +161,7 @@ public class ShadersTests
static void RunComputeShader(ReadWriteTexture2D texture)
where T : struct, IComputeShader
{
- ReflectionServices.GetShaderInfo(out var info);
+ ShaderInfo info = ReflectionServices.GetShaderInfo();
Assert.IsFalse(info.RequiresDoublePrecisionSupport);
@@ -230,7 +230,7 @@ public class ShadersTests
{
if (typeof(IComputeShader).IsAssignableFrom(shaderType))
{
- ReflectionServices.GetShaderInfo(out var info);
+ ShaderInfo info = ReflectionServices.GetShaderInfo();
Assert.IsFalse(info.RequiresDoublePrecisionSupport);