internal/graphicsdriver/directx: reduce rendering paths for even-odd rendering

This commit is contained in:
Hajime Hoshi 2022-11-04 17:20:33 +09:00
parent 7bf822bdb1
commit 1ce29e2afa
2 changed files with 25 additions and 36 deletions

View File

@ -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
}

View File

@ -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
}