diff --git a/src/ComputeSharp/Shaders/Loading/PipelineDataLoader{T}.cs b/src/ComputeSharp/Shaders/Loading/PipelineDataLoader{T}.cs index b9883cf6..aa24d6ff 100644 --- a/src/ComputeSharp/Shaders/Loading/PipelineDataLoader{T}.cs +++ b/src/ComputeSharp/Shaders/Loading/PipelineDataLoader{T}.cs @@ -44,21 +44,12 @@ internal static unsafe class PipelineDataLoader PipelineData pipelineData; using (ComPtr d3D12RootSignature = default) + using (ComPtr d3D12PipelineState = default) { CreateD3D12RootSignature(device.D3D12Device, d3D12RootSignature.GetAddressOf()); + CreateD3D12PipelineState(device.D3D12Device, d3D12RootSignature.Get(), d3D12PipelineState.GetAddressOf()); - Unsafe.SkipInit(out T shader); - - ReadOnlyMemory hlslBytecode = shader.HlslBytecode; - - fixed (byte* hlslBytecodePtr = hlslBytecode.Span) - { - D3D12_SHADER_BYTECODE d3D12ShaderBytecode = new(hlslBytecodePtr, (nuint)hlslBytecode.Length); - - using ComPtr d3D12PipelineState = device.D3D12Device->CreateComputePipelineState(d3D12RootSignature.Get(), d3D12ShaderBytecode); - - pipelineData = new PipelineData(d3D12RootSignature.Get(), d3D12PipelineState.Get()); - } + pipelineData = new PipelineData(d3D12RootSignature.Get(), d3D12PipelineState.Get()); } // Add the pipeline to the cache for this type @@ -117,4 +108,22 @@ internal static unsafe class PipelineDataLoader ArrayPool.Shared.Return(d3D12DescriptorRangesArray); } } + + /// + /// Creates a D3D12 pipeline state for the current shader type. + /// + /// The target to use to create the root signature. + /// The input value to use. + /// The resulting instance. + private static void CreateD3D12PipelineState(ID3D12Device* d3D12Device, ID3D12RootSignature* d3D12RootSignature, ID3D12PipelineState** d3D12PipelineState) + { + Unsafe.SkipInit(out T shader); + + fixed (byte* hlslBytecodePtr = shader.HlslBytecode.Span) + { + D3D12_SHADER_BYTECODE d3D12ShaderBytecode = new(hlslBytecodePtr, (nuint)shader.HlslBytecode.Length); + + *d3D12PipelineState = d3D12Device->CreateComputePipelineState(d3D12RootSignature, d3D12ShaderBytecode); + } + } } \ No newline at end of file