From 0bca5d1e623ef764aef0b4291e6a4d3c0cf0d8d5 Mon Sep 17 00:00:00 2001 From: 355yamada Date: Thu, 21 Mar 2024 10:13:30 +0900 Subject: [PATCH 1/2] Update ID3D11DeviceContextExtensions.cs Add geometry shader API, `GSSetShader()`, `GSSetShaderResouce()` and `GSSetShaderResouces()`. --- .../ID3D11DeviceContextExtensions.cs | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/DirectN/DirectN/Extensions/ID3D11DeviceContextExtensions.cs b/DirectN/DirectN/Extensions/ID3D11DeviceContextExtensions.cs index 575d04e73..089721808 100644 --- a/DirectN/DirectN/Extensions/ID3D11DeviceContextExtensions.cs +++ b/DirectN/DirectN/Extensions/ID3D11DeviceContextExtensions.cs @@ -354,8 +354,15 @@ public static void VSSetShader(this ID3D11DeviceContext context, ID3D11VertexSha context.VSSetShader(vertexShader, classInstances, (classInstances?.Length).GetValueOrDefault()); } + public static void GSSetShader(this IComObject context, IComObject geometryShader, IComObject[] classInstances = null) => GSSetShader(context?.Object, geometryShader?.Object, classInstances.ToArray()); + public static void GSSetShader(this ID3D11DeviceContext context, ID3D11GeometryShader geometryShader, ID3D11ClassInstance[] classInstances = null) + { + if (context == null) + throw new ArgumentNullException(nameof(context)); - public static void PSSetShader(this IComObject context, IComObject pixelShader, IComObject[] classInstances = null) => PSSetShader(context?.Object, pixelShader?.Object, classInstances.ToArray()); + context.GSSetShader(geometryShader, classInstances, (classInstances?.Length).GetValueOrDefault()); + } + public static void PSSetShader(this IComObject context, IComObject pixelShader, IComObject[] classInstances = null) => PSSetShader(context?.Object, pixelShader?.Object, classInstances?.ToArray()); public static void PSSetShader(this ID3D11DeviceContext context, ID3D11PixelShader pixelShader, ID3D11ClassInstance[] classInstances = null) { if (context == null) @@ -407,7 +414,31 @@ public static void VSSetShaderResources(this ID3D11DeviceContext context, int st context.VSSetShaderResources((uint)startSlot, (shaderResourceViews?.Length).GetValueOrDefault(), shaderResourceViews); } + public static void GSSetShaderResource(this IComObject context, int startSlot, IComObject shaderResourceView) + { + if (context == null) + throw new ArgumentNullException(nameof(context)); + + if (context.Object == null) + throw new ArgumentException(null, nameof(context)); + if (shaderResourceView == null) + throw new ArgumentNullException(nameof(shaderResourceView)); + + if (shaderResourceView.Object == null) + throw new ArgumentException(null, nameof(shaderResourceView)); + + context.Object.GSSetShaderResources((uint)startSlot, 1, new[] { shaderResourceView.Object }); + } + + public static void GSSetShaderResources(this IComObject context, int startSlot, IComObject[] shaderResourceViews) => GSSetShaderResources(context?.Object, startSlot, shaderResourceViews?.ToArray()); + public static void GSSetShaderResources(this ID3D11DeviceContext context, int startSlot, ID3D11ShaderResourceView[] shaderResourceViews) + { + if (context == null) + throw new ArgumentNullException(nameof(context)); + + context.GSSetShaderResources((uint)startSlot, (shaderResourceViews?.Length).GetValueOrDefault(), shaderResourceViews); + } public static void PSSetSampler(this IComObject context, int startSlot, IComObject samplerState) { if (context == null) From 85382e743253f803c00c53ec3dd368ad3edd346e Mon Sep 17 00:00:00 2001 From: Simon Mourier Date: Thu, 21 Mar 2024 07:49:44 +0100 Subject: [PATCH 2/2] Update ID3D11DeviceContextExtensions.cs - removed the ? on ToArray calls It's just not needed (one was left before) --- DirectN/DirectN/Extensions/ID3D11DeviceContextExtensions.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DirectN/DirectN/Extensions/ID3D11DeviceContextExtensions.cs b/DirectN/DirectN/Extensions/ID3D11DeviceContextExtensions.cs index 089721808..cbd87015d 100644 --- a/DirectN/DirectN/Extensions/ID3D11DeviceContextExtensions.cs +++ b/DirectN/DirectN/Extensions/ID3D11DeviceContextExtensions.cs @@ -362,7 +362,7 @@ public static void GSSetShader(this ID3D11DeviceContext context, ID3D11GeometryS context.GSSetShader(geometryShader, classInstances, (classInstances?.Length).GetValueOrDefault()); } - public static void PSSetShader(this IComObject context, IComObject pixelShader, IComObject[] classInstances = null) => PSSetShader(context?.Object, pixelShader?.Object, classInstances?.ToArray()); + public static void PSSetShader(this IComObject context, IComObject pixelShader, IComObject[] classInstances = null) => PSSetShader(context?.Object, pixelShader?.Object, classInstances.ToArray()); public static void PSSetShader(this ID3D11DeviceContext context, ID3D11PixelShader pixelShader, ID3D11ClassInstance[] classInstances = null) { if (context == null) @@ -431,7 +431,7 @@ public static void GSSetShaderResource(this IComObject cont context.Object.GSSetShaderResources((uint)startSlot, 1, new[] { shaderResourceView.Object }); } - public static void GSSetShaderResources(this IComObject context, int startSlot, IComObject[] shaderResourceViews) => GSSetShaderResources(context?.Object, startSlot, shaderResourceViews?.ToArray()); + public static void GSSetShaderResources(this IComObject context, int startSlot, IComObject[] shaderResourceViews) => GSSetShaderResources(context?.Object, startSlot, shaderResourceViews.ToArray()); public static void GSSetShaderResources(this ID3D11DeviceContext context, int startSlot, ID3D11ShaderResourceView[] shaderResourceViews) { if (context == null) @@ -482,7 +482,7 @@ public static void PSSetShaderResource(this IComObject cont context.Object.PSSetShaderResources((uint)startSlot, 1, new[] { shaderResourceView.Object }); } - public static void PSSetShaderResources(this IComObject context, int startSlot, IComObject[] shaderResourceViews) => PSSetShaderResources(context?.Object, startSlot, shaderResourceViews?.ToArray()); + public static void PSSetShaderResources(this IComObject context, int startSlot, IComObject[] shaderResourceViews) => PSSetShaderResources(context?.Object, startSlot, shaderResourceViews.ToArray()); public static void PSSetShaderResources(this ID3D11DeviceContext context, int startSlot, ID3D11ShaderResourceView[] shaderResourceViews) { if (context == null)