diff --git a/internal/graphicsdriver/directx/graphics_windows.go b/internal/graphicsdriver/directx/graphics_windows.go index bdefaa365..900ff7be5 100644 --- a/internal/graphicsdriver/directx/graphics_windows.go +++ b/internal/graphicsdriver/directx/graphics_windows.go @@ -1262,42 +1262,10 @@ func (g *Graphics) DrawTriangles(dstID graphicsdriver.ImageID, srcs [graphics.Sh Format: _DXGI_FORMAT_R16_UINT, }) - if evenOdd { - s, err := shader.pipelineState(blend, prepareStencil, dst.screen) - if err != nil { - return err - } - if err := g.drawTriangles(s, srcImages, flattenUniforms, indexLen, indexOffset); err != nil { - return err - } - - s, err = shader.pipelineState(blend, drawWithStencil, dst.screen) - if err != nil { - return err - } - if err := g.drawTriangles(s, srcImages, flattenUniforms, indexLen, indexOffset); err != nil { - return err - } - } else { - s, err := shader.pipelineState(blend, noStencil, dst.screen) - if err != nil { - return err - } - if err := g.drawTriangles(s, srcImages, flattenUniforms, indexLen, indexOffset); err != nil { - return err - } - } - - return nil -} - -func (g *Graphics) drawTriangles(pipelineState *_ID3D12PipelineState, srcs [graphics.ShaderImageCount]*Image, flattenUniforms []float32, indexLen int, indexOffset int) error { - if err := g.pipelineStates.useGraphicsPipelineState(g.device, g.drawCommandList, g.frameIndex, pipelineState, srcs, flattenUniforms); err != nil { + if err := g.pipelineStates.drawTriangles(g.device, g.drawCommandList, g.frameIndex, dst.screen, srcImages, shader, flattenUniforms, blend, indexLen, indexOffset, evenOdd); err != nil { return err } - g.drawCommandList.DrawIndexedInstanced(uint32(indexLen), 1, uint32(indexOffset), 0, 0) - return nil } diff --git a/internal/graphicsdriver/directx/pipeline_windows.go b/internal/graphicsdriver/directx/pipeline_windows.go index 28c882dd6..849449ef9 100644 --- a/internal/graphicsdriver/directx/pipeline_windows.go +++ b/internal/graphicsdriver/directx/pipeline_windows.go @@ -146,7 +146,7 @@ func (p *pipelineStates) initialize(device *_ID3D12Device) (ferr error) { return nil } -func (p *pipelineStates) useGraphicsPipelineState(device *_ID3D12Device, commandList *_ID3D12GraphicsCommandList, frameIndex int, pipelineState *_ID3D12PipelineState, srcs [graphics.ShaderImageCount]*Image, uniforms []float32) error { +func (p *pipelineStates) drawTriangles(device *_ID3D12Device, commandList *_ID3D12GraphicsCommandList, frameIndex int, screen bool, srcs [graphics.ShaderImageCount]*Image, shader *Shader, uniforms []float32, blend graphicsdriver.Blend, indexLen int, indexOffset int, evenOdd bool) error { idx := len(p.constantBuffers[frameIndex]) if idx >= numDescriptorsPerFrame { return fmt.Errorf("directx: too many constant buffers") @@ -230,8 +230,6 @@ func (p *pipelineStates) useGraphicsPipelineState(device *_ID3D12Device, command // Update the constant buffer. copy(unsafe.Slice((*float32)(unsafe.Pointer(m)), len(uniforms)), uniforms) - commandList.SetPipelineState(pipelineState) - rs, err := p.ensureRootSignature(device) if err != nil { return err @@ -257,6 +255,29 @@ func (p *pipelineStates) useGraphicsPipelineState(device *_ID3D12Device, command } commandList.SetGraphicsRootDescriptorTable(2, sh) + if evenOdd { + s, err := shader.pipelineState(blend, prepareStencil, screen) + if err != nil { + return err + } + commandList.SetPipelineState(s) + commandList.DrawIndexedInstanced(uint32(indexLen), 1, uint32(indexOffset), 0, 0) + + s, err = shader.pipelineState(blend, drawWithStencil, screen) + if err != nil { + return err + } + commandList.SetPipelineState(s) + commandList.DrawIndexedInstanced(uint32(indexLen), 1, uint32(indexOffset), 0, 0) + } else { + s, err := shader.pipelineState(blend, noStencil, screen) + if err != nil { + return err + } + commandList.SetPipelineState(s) + commandList.DrawIndexedInstanced(uint32(indexLen), 1, uint32(indexOffset), 0, 0) + } + return nil }