diff --git a/Directory.Build.props b/Directory.Build.props index 3459912..32b44f4 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -14,7 +14,7 @@ true $(MSBuildThisFileDirectory)NuGet.config - 1.9.4 + 1.9.5 true diff --git a/src/Vortice.Win32.Graphics.Direct3D11/ID3D11Device.cs b/src/Vortice.Win32.Graphics.Direct3D11/ID3D11Device.cs index bd61fa4..5868d0b 100644 --- a/src/Vortice.Win32.Graphics.Direct3D11/ID3D11Device.cs +++ b/src/Vortice.Win32.Graphics.Direct3D11/ID3D11Device.cs @@ -7,7 +7,7 @@ namespace Win32.Graphics.Direct3D11; public static unsafe class ID3D11DeviceExtension { - public static ComPtr CheckFeatureSupport(ref this ID3D11Device self, BufferDescription* description, SubresourceData* initialData = default) + public static ComPtr CheckFeatureSupport(ref this TD3D11Device self, BufferDescription* description, SubresourceData* initialData = default) where TD3D11Device : unmanaged, ID3D11Device.Interface { using ComPtr buffer = default; @@ -15,8 +15,9 @@ public static unsafe class ID3D11DeviceExtension return buffer.Move(); } + public static ComPtr CreateBuffer( - ref this ID3D11Device self, + ref this TD3D11Device self, in T data, BufferDescription description) where TD3D11Device : unmanaged, ID3D11Device.Interface @@ -38,20 +39,11 @@ public static unsafe class ID3D11DeviceExtension } } - public static ComPtr CreateDeferredContext(ref this ID3D11Device self) + public static ComPtr CreateBuffer( + ref this TD3D11Device self, + ReadOnlySpan data, BufferDescription description) where TD3D11Device : unmanaged, ID3D11Device.Interface - { - using ComPtr deferredContext = default; - ThrowIfFailed(self.CreateDeferredContext(0u, deferredContext.GetAddressOf())); - return deferredContext.Move(); - } -} - - -public unsafe partial struct ID3D11Device -{ - - public ComPtr CreateBuffer(ReadOnlySpan data, BufferDescription description) where T : unmanaged + where T : unmanaged { if (description.ByteWidth == 0) description.ByteWidth = (uint)(sizeof(T) * data.Length); @@ -64,7 +56,7 @@ public unsafe partial struct ID3D11Device }; using ComPtr buffer = default; - ThrowIfFailed(CreateBuffer(&description, &subresourceData, buffer.GetAddressOf())); + ThrowIfFailed(self.CreateBuffer(&description, &subresourceData, buffer.GetAddressOf())); return buffer.Move(); } } @@ -72,7 +64,9 @@ public unsafe partial struct ID3D11Device /// /// Creates a new instance of the class. /// + /// ID3D11Device type /// Type of the data to upload + /// The instace type of . /// Flags specifying how the buffer will be bound to the pipeline. /// Initial data used to initialize the buffer. /// The size, in bytes, of the buffer. If 0 is specified, sizeof(T) * data.Length is used. @@ -81,14 +75,17 @@ public unsafe partial struct ID3D11Device /// Miscellaneous resource options. /// The size (in bytes) of the structure element for structured buffers. /// An initialized buffer - public ComPtr CreateBuffer( + public static ComPtr CreateBuffer( + ref this TD3D11Device self, ReadOnlySpan data, BindFlags bindFlags, Usage usage = Usage.Default, CpuAccessFlags accessFlags = CpuAccessFlags.None, ResourceMiscFlags miscFlags = ResourceMiscFlags.None, uint sizeInBytes = 0, - uint structureByteStride = 0) where T : unmanaged + uint structureByteStride = 0) + where TD3D11Device : unmanaged, ID3D11Device.Interface + where T : unmanaged { BufferDescription description = new() { @@ -108,160 +105,255 @@ public unsafe partial struct ID3D11Device }; using ComPtr buffer = default; - ThrowIfFailed(CreateBuffer(&description, &subresourceData, buffer.GetAddressOf())); + ThrowIfFailed(self.CreateBuffer(&description, &subresourceData, buffer.GetAddressOf())); return buffer.Move(); } } - public ComPtr CreateRenderTargetView( + + public static ComPtr CreateDeferredContext(ref this ID3D11Device self) + where TD3D11Device : unmanaged, ID3D11Device.Interface + { + using ComPtr deferredContext = default; + ThrowIfFailed(self.CreateDeferredContext(0u, deferredContext.GetAddressOf())); + return deferredContext.Move(); + } + + public static ComPtr CreateRenderTargetView(ref this ID3D11Device self, ID3D11Resource* resource, RenderTargetViewDescription* description) + where TD3D11Device : unmanaged, ID3D11Device.Interface { using ComPtr view = default; - ThrowIfFailed(CreateRenderTargetView(resource, description, view.GetAddressOf())); - + ThrowIfFailed(self.CreateRenderTargetView(resource, description, view.GetAddressOf())); return view.Move(); } - public ComPtr CreateDepthStencilView( + public static ComPtr CreateDepthStencilView(ref this ID3D11Device self, ID3D11Resource* resource, DepthStencilViewDescription* description) + where TD3D11Device : unmanaged, ID3D11Device.Interface { using ComPtr view = default; - ThrowIfFailed(CreateDepthStencilView(resource, description, view.GetAddressOf())); + ThrowIfFailed(self.CreateDepthStencilView(resource, description, view.GetAddressOf())); return view.Move(); } - public ComPtr CreateShaderResourceView( + public static ComPtr CreateShaderResourceView(ref this ID3D11Device self, ID3D11Resource* resource, ShaderResourceViewDescription* description) + where TD3D11Device : unmanaged, ID3D11Device.Interface { using ComPtr view = default; - ThrowIfFailed(CreateShaderResourceView(resource, description, view.GetAddressOf())); + ThrowIfFailed(self.CreateShaderResourceView(resource, description, view.GetAddressOf())); return view.Move(); } - public ComPtr CreateUnorderedAccessView( + public static ComPtr CreateUnorderedAccessView(ref this ID3D11Device self, ID3D11Resource* resource, UnorderedAccessViewDescription* description) + where TD3D11Device : unmanaged, ID3D11Device.Interface { using ComPtr view = default; - ThrowIfFailed(CreateUnorderedAccessView(resource, description, view.GetAddressOf())); + ThrowIfFailed(self.CreateUnorderedAccessView(resource, description, view.GetAddressOf())); return view.Move(); } - public ComPtr CreateBlendState(BlendDescription* description) + public static ComPtr CreateBlendState(ref this ID3D11Device self, BlendDescription* description) + where TD3D11Device : unmanaged, ID3D11Device.Interface { using ComPtr state = default; - ThrowIfFailed(CreateBlendState(description, state.GetAddressOf())); + ThrowIfFailed(self.CreateBlendState(description, state.GetAddressOf())); return state.Move(); } - public ComPtr CreateBlendState(BlendDescription description) + public static ComPtr CreateBlendState(ref this ID3D11Device self, BlendDescription description) + where TD3D11Device : unmanaged, ID3D11Device.Interface { using ComPtr state = default; - ThrowIfFailed(CreateBlendState(&description, state.GetAddressOf())); + ThrowIfFailed(self.CreateBlendState(&description, state.GetAddressOf())); return state.Move(); } - public ComPtr CreateDepthStencilState(DepthStencilDescription* description) + public static ComPtr CreateDepthStencilState(ref this ID3D11Device self, DepthStencilDescription* description) + where TD3D11Device : unmanaged, ID3D11Device.Interface { using ComPtr state = default; - ThrowIfFailed(CreateDepthStencilState(description, state.GetAddressOf())); + ThrowIfFailed(self.CreateDepthStencilState(description, state.GetAddressOf())); return state.Move(); } - public ComPtr CreateDepthStencilState(DepthStencilDescription description) + public static ComPtr CreateDepthStencilState(ref this ID3D11Device self, DepthStencilDescription description) + where TD3D11Device : unmanaged, ID3D11Device.Interface { using ComPtr state = default; - ThrowIfFailed(CreateDepthStencilState(&description, state.GetAddressOf())); + ThrowIfFailed(self.CreateDepthStencilState(&description, state.GetAddressOf())); return state.Move(); } - public ComPtr CreateRasterizerState(RasterizerDescription* description) + public static ComPtr CreateRasterizerState(ref this ID3D11Device self, RasterizerDescription* description) + where TD3D11Device : unmanaged, ID3D11Device.Interface { using ComPtr state = default; - ThrowIfFailed(CreateRasterizerState(description, state.GetAddressOf())); + ThrowIfFailed(self.CreateRasterizerState(description, state.GetAddressOf())); return state.Move(); } - public ComPtr CreateRasterizerState(RasterizerDescription description) + public static ComPtr CreateRasterizerState(ref this ID3D11Device self, RasterizerDescription description) + where TD3D11Device : unmanaged, ID3D11Device.Interface { using ComPtr state = default; - ThrowIfFailed(CreateRasterizerState(&description, state.GetAddressOf())); + ThrowIfFailed(self.CreateRasterizerState(&description, state.GetAddressOf())); return state.Move(); } - public ComPtr CreateSamplerState(SamplerDescription* description) + public static ComPtr CreateSamplerState(ref this ID3D11Device self, SamplerDescription* description) + where TD3D11Device : unmanaged, ID3D11Device.Interface { using ComPtr state = default; - ThrowIfFailed(CreateSamplerState(description, state.GetAddressOf())); + ThrowIfFailed(self.CreateSamplerState(description, state.GetAddressOf())); return state.Move(); } - public ComPtr CreateSamplerState(SamplerDescription description) + public static ComPtr CreateSamplerState(ref this ID3D11Device self, SamplerDescription description) + where TD3D11Device : unmanaged, ID3D11Device.Interface { using ComPtr state = default; - ThrowIfFailed(CreateSamplerState(&description, state.GetAddressOf())); + ThrowIfFailed(self.CreateSamplerState(&description, state.GetAddressOf())); return state.Move(); } - public ComPtr CreateTexture1D(Texture1DDescription* description, SubresourceData* initialData = default) + public static ComPtr CreateTexture1D(ref this TD3D11Device self, Texture1DDescription* description, SubresourceData* initialData = default) + where TD3D11Device : unmanaged, ID3D11Device.Interface { using ComPtr texture = default; - ThrowIfFailed(CreateTexture1D(description, initialData, texture.GetAddressOf())); + ThrowIfFailed(self.CreateTexture1D(description, initialData, texture.GetAddressOf())); return texture.Move(); } - public ComPtr CreateTexture1D(Texture1DDescription description, SubresourceData* initialData = default) + public static ComPtr CreateTexture1D(ref this TD3D11Device self, Texture1DDescription description, SubresourceData* initialData = default) + where TD3D11Device : unmanaged, ID3D11Device.Interface { using ComPtr texture = default; - ThrowIfFailed(CreateTexture1D(&description, initialData, texture.GetAddressOf())); + ThrowIfFailed(self.CreateTexture1D(&description, initialData, texture.GetAddressOf())); return texture.Move(); } - public ComPtr CreateTexture2D(Texture2DDescription* description, SubresourceData* initialData = default) + public static ComPtr CreateTexture2D(ref this TD3D11Device self, Texture2DDescription* description, SubresourceData* initialData = default) + where TD3D11Device : unmanaged, ID3D11Device.Interface { using ComPtr texture = default; - ThrowIfFailed(CreateTexture2D(description, initialData, texture.GetAddressOf())); + ThrowIfFailed(self.CreateTexture2D(description, initialData, texture.GetAddressOf())); return texture.Move(); } - public ComPtr CreateTexture2D(Texture2DDescription description, SubresourceData* initialData = default) + public static ComPtr CreateTexture2D(ref this TD3D11Device self, Texture2DDescription description, SubresourceData* initialData = default) + where TD3D11Device : unmanaged, ID3D11Device.Interface { using ComPtr texture = default; - ThrowIfFailed(CreateTexture2D(&description, initialData, texture.GetAddressOf())); + ThrowIfFailed(self.CreateTexture2D(&description, initialData, texture.GetAddressOf())); return texture.Move(); } - public ComPtr CreateTexture3D(Texture3DDescription* description, SubresourceData* initialData = default) + public static ComPtr CreateTexture3D(ref this TD3D11Device self, Texture3DDescription* description, SubresourceData* initialData = default) + where TD3D11Device : unmanaged, ID3D11Device.Interface { using ComPtr texture = default; - ThrowIfFailed(CreateTexture3D(description, initialData, texture.GetAddressOf())); + ThrowIfFailed(self.CreateTexture3D(description, initialData, texture.GetAddressOf())); return texture.Move(); } - public ComPtr CreateTexture3D(Texture3DDescription description, SubresourceData* initialData = default) + public static ComPtr CreateTexture3D(ref this TD3D11Device self, Texture3DDescription description, SubresourceData* initialData = default) + where TD3D11Device : unmanaged, ID3D11Device.Interface { using ComPtr texture = default; - ThrowIfFailed(CreateTexture3D(&description, initialData, texture.GetAddressOf())); + ThrowIfFailed(self.CreateTexture3D(&description, initialData, texture.GetAddressOf())); return texture.Move(); } + + public static HResult CreateVertexShader(ref this TD3D11Device self, ReadOnlySpan shaderBytecode, ID3D11ClassLinkage* pClassLinkage, ID3D11VertexShader** ppVertexShader) + where TD3D11Device : unmanaged, ID3D11Device.Interface + { + fixed (byte* pShaderBytecode = shaderBytecode) + { + return self.CreateVertexShader(pShaderBytecode, (nuint)shaderBytecode.Length, pClassLinkage, ppVertexShader); + } + } + + public static ComPtr CreateVertexShader(ref this TD3D11Device self, + ReadOnlySpan shaderBytecode, + ID3D11ClassLinkage* classLinkage = default) + where TD3D11Device : unmanaged, ID3D11Device.Interface + { + using ComPtr shader = default; + fixed (byte* pShaderBytecode = shaderBytecode) + { + ThrowIfFailed(self.CreateVertexShader(pShaderBytecode, (nuint)shaderBytecode.Length, classLinkage, shader.GetAddressOf())); + } + + return shader.Move(); + } + + public static HResult CreatePixelShader(ref this TD3D11Device self, ReadOnlySpan shaderBytecode, ID3D11ClassLinkage* pClassLinkage, ID3D11PixelShader** ppPixelShader) + where TD3D11Device : unmanaged, ID3D11Device.Interface + { + fixed (byte* pShaderBytecode = shaderBytecode) + { + return self.CreatePixelShader(pShaderBytecode, (nuint)shaderBytecode.Length, pClassLinkage, ppPixelShader); + } + } + + public static ComPtr CreatePixelShader(ref this TD3D11Device self, + ReadOnlySpan shaderBytecode, + ID3D11ClassLinkage* classLinkage = default) + where TD3D11Device : unmanaged, ID3D11Device.Interface + { + using ComPtr shader = default; + fixed (byte* pShaderBytecode = shaderBytecode) + { + ThrowIfFailed(self.CreatePixelShader(pShaderBytecode, (nuint)shaderBytecode.Length, classLinkage, shader.GetAddressOf())); + } + + return shader.Move(); + } + + public static HResult CreateComputeShader(ref this TD3D11Device self, ReadOnlySpan shaderBytecode, ID3D11ClassLinkage* pClassLinkage, ID3D11ComputeShader** ppComputeShader) + where TD3D11Device : unmanaged, ID3D11Device.Interface + { + fixed (byte* pShaderBytecode = shaderBytecode) + { + return self.CreateComputeShader(pShaderBytecode, (nuint)shaderBytecode.Length, pClassLinkage, ppComputeShader); + } + } + + public static ComPtr CreateComputeShader(ref this TD3D11Device self, + ReadOnlySpan shaderBytecode, + ID3D11ClassLinkage* classLinkage = default) + where TD3D11Device : unmanaged, ID3D11Device.Interface + { + using ComPtr shader = default; + fixed (byte* pShaderBytecode = shaderBytecode) + { + ThrowIfFailed(self.CreateComputeShader(pShaderBytecode, (nuint)shaderBytecode.Length, classLinkage, shader.GetAddressOf())); + } + + return shader.Move(); + } }