smourier / DirectN

Direct interop Code for .NET Framework, .NET Core and .NET 5+ : DXGI, WIC, DirectX 9 to 12, Direct2D, Direct Write, Direct Composition, Media Foundation, WASAPI, CodecAPI, GDI, Spatial Audio, DVD, Windows Media Player, UWP DXInterop, WinUI3, etc.
MIT License
295 stars 26 forks source link

Why I cannot use GSSetShader()? #47

Closed vmx17 closed 9 months ago

vmx17 commented 9 months ago

Hi! Today, I tried to figure out why I cannot use GSSetShader(). Yes, I want to set and unset (= set(null)) geometry shader. Though I've checked your extension code, they seems to have its definitions. Though I've attached following code to "Extensions\ID3D11DeviceContextExtensions.cs", there was no luck. As you mentioned #35, the m_device.Object seems to have original code (but I'm investigating other arguments). Now I'm using version 1.15.0.2 from nuget.org but compiled version number was backdated to 1.13.x.y. Could you help me to use it? What I'm trying to draw multiple kind of primitives and one of it use geometry shader (Texture2D) but others do not. So I set/unset in Render() method.

        public static void GSSetShader(this IComObject<ID3D11DeviceContext> context, IComObject<ID3D11GeometryShader> geometryShader, IComObject<ID3D11ClassInstance>[] 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));

            context.GSSetShader(geometryShader, classInstances, (classInstances?.Length).GetValueOrDefault());
        }
smourier commented 9 months ago

Hi,

someInterfaceRef.Object always has all methods.

Extensions method in Extensions folder were added for some interfaces, and for some methods. It's very far from being complete. You can always create your own if you're missing some.

Looking at history, I don't think there ever was a GSSetShader on ID3D11DeviceContextExtensions.cs in DirectN code?

vmx17 commented 9 months ago

Hi, thank you for rapid reply. There were no GSSetShader() on ID3D11DeviceContextExtensions.cs then I tried to add it with code copied from PSSetShader(). As far as I've checked other source files seem to have code for GS. Today I've add code below to the ID3D11DeviceContextExtensions.cs and got connection to the API (but I'm far from to confirm it works correctly). And about the "backdated version number(1.13.x)", was in a previously made *.nuget package name. In my local environment, newly added version number appeard in the filename. I'm sorry for my misunderstanding.

public static void GSSetShader(this IComObject<ID3D11DeviceContext> context, IComObject<ID3D11GeometryShader> geometryShader, IComObject<ID3D11ClassInstance>[] 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));

    context.GSSetShader(geometryShader, classInstances, (classInstances?.Length).GetValueOrDefault());
}

and

public static void GSSetShaderResource(this IComObject<ID3D11DeviceContext> context, int startSlot, IComObject<ID3D11ShaderResourceView> 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<ID3D11DeviceContext> context, int startSlot, IComObject<ID3D11ShaderResourceView>[] 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);
}
smourier commented 9 months ago

In the first line, you should pass classInstances?.ToArray() instead of classInstances.ToArray() to avoid null ref errors when you're passing a null list of instances. Other than that it seems fine.

vmx17 commented 9 months ago

Thanks. It's a difference between PS and GS. GS should be "nullable". In honet, I do not understand where and how DirectN calls/replaces original API. It might be a large work and should be maintained every SDK update. I'm trying to show Texture2D as string (so to speak font rendering) with and without GS.

smourier commented 9 months ago

I do not understand where and how DirectN calls/replaces original API

DirectN doesn't replace any API. Not sure I understand what you mean by that.

vmx17 commented 9 months ago

This is just my guessing. I think there are layers of methods in COMs supported by DirectN. So I think you're checking (searching Guids and move them to C# codes) all *.h files in SDK. Some methods of them may go to lower layer those require another Guids. This is one case what I regard your these work as a kind of replacing APIs (? no, *.h with *.cs). Of course, this must not be all of your work. There are folders named "Generated" and "Manual". I guess "Generated" folder contains output of some converters (you made?) but in "Manual", your manual output. I do not know depth of MS's library. I cannot imagine even how you divided .NetCore from .Net but I want to know how to maintain these codes in future. That is a junction point which way to take in large programs. (What I'm doing now is just a prototyping.) I keep annoying which language should I choose for base components. Everyone want to use C# (or JS?) but as for DirectX, I feel everything is exception.

Sorry, far from the title.