diff --git a/examples/mrt/main.go b/examples/mrt/main.go index 2cdbce40275e..11c7d1b3e035 100644 --- a/examples/mrt/main.go +++ b/examples/mrt/main.go @@ -36,9 +36,9 @@ var ( ebiten.NewImage(dstSize, dstSize), ebiten.NewImage(dstSize, dstSize), ebiten.NewImage(dstSize, dstSize),*/ - nil,/*ebiten.NewImageWithOptions(image.Rect(0, 0, dstSize, dstSize), &ebiten.NewImageOptions{ + ebiten.NewImageWithOptions(image.Rect(0, 0, dstSize, dstSize), &ebiten.NewImageOptions{ Unmanaged: true, - }),*/ + }), ebiten.NewImageWithOptions(image.Rect(0, 0, dstSize, dstSize), &ebiten.NewImageOptions{ Unmanaged: true, }), @@ -101,7 +101,7 @@ func (g *Game) Draw(screen *ebiten.Image) { indices := []uint16{0, 1, 2, 1, 2, 3} ebiten.DrawTrianglesShaderMRT(dsts, vertices, indices, s, nil) // Dst 0 - //screen.DrawImage(dsts[0], nil) + screen.DrawImage(dsts[0], nil) // Dst 1 opts := &ebiten.DrawImageOptions{} opts.GeoM.Translate(dstSize, 0) diff --git a/internal/graphicsdriver/directx/graphics12_windows.go b/internal/graphicsdriver/directx/graphics12_windows.go index e2670cf529b5..2e12fc17400d 100644 --- a/internal/graphicsdriver/directx/graphics12_windows.go +++ b/internal/graphicsdriver/directx/graphics12_windows.go @@ -1231,7 +1231,6 @@ func (g *graphics12) DrawTriangles(dstIDs [graphics.ShaderDstImageCount]graphics targetCount = graphics.ShaderDstImageCount } - g.drawCommandList.RSSetViewports([]_D3D12_VIEWPORT{vp}) if err := g.setAsRenderTargets(dsts[:targetCount], fillRule != graphicsdriver.FillAll); err != nil { return err } @@ -1241,6 +1240,8 @@ func (g *graphics12) DrawTriangles(dstIDs [graphics.ShaderDstImageCount]graphics g.needFlushDrawCommandList = true + g.drawCommandList.RSSetViewports([]_D3D12_VIEWPORT{vp}) + g.drawCommandList.IASetPrimitiveTopology(_D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST) g.drawCommandList.IASetVertexBuffers(0, []_D3D12_VERTEX_BUFFER_VIEW{ { diff --git a/internal/graphicsdriver/directx/image12_windows.go b/internal/graphicsdriver/directx/image12_windows.go index aab796833218..6c3c1bdb8eed 100644 --- a/internal/graphicsdriver/directx/image12_windows.go +++ b/internal/graphicsdriver/directx/image12_windows.go @@ -70,7 +70,7 @@ func (i *image12) disposeImpl() { func (i *image12) ReadPixels(args []graphicsdriver.PixelsArgs) error { if i.screen { - return errors.New("directx: Pixels cannot be called on the screen") + return errors.New("directx: ReadPixels cannot be called on the screen") } if err := i.graphics.flushCommandList(i.graphics.drawCommandList); err != nil { diff --git a/internal/graphicsdriver/directx/pipeline12_windows.go b/internal/graphicsdriver/directx/pipeline12_windows.go index 7ede40675f46..eed7cff73444 100644 --- a/internal/graphicsdriver/directx/pipeline12_windows.go +++ b/internal/graphicsdriver/directx/pipeline12_windows.go @@ -484,6 +484,18 @@ func (p *pipelineStates) newPipelineState(device *_ID3D12Device, vsh, psh *_ID3D } // Create a pipeline state. + rtBlendDesc := _D3D12_RENDER_TARGET_BLEND_DESC{ + BlendEnable: 1, + LogicOpEnable: 0, + SrcBlend: blendFactorToBlend12(blend.BlendFactorSourceRGB, false), + DestBlend: blendFactorToBlend12(blend.BlendFactorDestinationRGB, false), + BlendOp: blendOperationToBlendOp12(blend.BlendOperationRGB), + SrcBlendAlpha: blendFactorToBlend12(blend.BlendFactorSourceAlpha, true), + DestBlendAlpha: blendFactorToBlend12(blend.BlendFactorDestinationAlpha, true), + BlendOpAlpha: blendOperationToBlendOp12(blend.BlendOperationAlpha), + LogicOp: _D3D12_LOGIC_OP_NOOP, + RenderTargetWriteMask: writeMask, + } psoDesc := _D3D12_GRAPHICS_PIPELINE_STATE_DESC{ pRootSignature: rootSignature, VS: _D3D12_SHADER_BYTECODE{ @@ -498,102 +510,7 @@ func (p *pipelineStates) newPipelineState(device *_ID3D12Device, vsh, psh *_ID3D AlphaToCoverageEnable: 0, IndependentBlendEnable: 0, RenderTarget: [8]_D3D12_RENDER_TARGET_BLEND_DESC{ - { - BlendEnable: 1, - LogicOpEnable: 0, - SrcBlend: blendFactorToBlend12(blend.BlendFactorSourceRGB, false), - DestBlend: blendFactorToBlend12(blend.BlendFactorDestinationRGB, false), - BlendOp: blendOperationToBlendOp12(blend.BlendOperationRGB), - SrcBlendAlpha: blendFactorToBlend12(blend.BlendFactorSourceAlpha, true), - DestBlendAlpha: blendFactorToBlend12(blend.BlendFactorDestinationAlpha, true), - BlendOpAlpha: blendOperationToBlendOp12(blend.BlendOperationAlpha), - LogicOp: _D3D12_LOGIC_OP_NOOP, - RenderTargetWriteMask: writeMask, - }, - { - BlendEnable: 1, - LogicOpEnable: 0, - SrcBlend: blendFactorToBlend12(blend.BlendFactorSourceRGB, false), - DestBlend: blendFactorToBlend12(blend.BlendFactorDestinationRGB, false), - BlendOp: blendOperationToBlendOp12(blend.BlendOperationRGB), - SrcBlendAlpha: blendFactorToBlend12(blend.BlendFactorSourceAlpha, true), - DestBlendAlpha: blendFactorToBlend12(blend.BlendFactorDestinationAlpha, true), - BlendOpAlpha: blendOperationToBlendOp12(blend.BlendOperationAlpha), - LogicOp: _D3D12_LOGIC_OP_NOOP, - RenderTargetWriteMask: writeMask, - }, - { - BlendEnable: 1, - LogicOpEnable: 0, - SrcBlend: blendFactorToBlend12(blend.BlendFactorSourceRGB, false), - DestBlend: blendFactorToBlend12(blend.BlendFactorDestinationRGB, false), - BlendOp: blendOperationToBlendOp12(blend.BlendOperationRGB), - SrcBlendAlpha: blendFactorToBlend12(blend.BlendFactorSourceAlpha, true), - DestBlendAlpha: blendFactorToBlend12(blend.BlendFactorDestinationAlpha, true), - BlendOpAlpha: blendOperationToBlendOp12(blend.BlendOperationAlpha), - LogicOp: _D3D12_LOGIC_OP_NOOP, - RenderTargetWriteMask: writeMask, - }, - { - BlendEnable: 1, - LogicOpEnable: 0, - SrcBlend: blendFactorToBlend12(blend.BlendFactorSourceRGB, false), - DestBlend: blendFactorToBlend12(blend.BlendFactorDestinationRGB, false), - BlendOp: blendOperationToBlendOp12(blend.BlendOperationRGB), - SrcBlendAlpha: blendFactorToBlend12(blend.BlendFactorSourceAlpha, true), - DestBlendAlpha: blendFactorToBlend12(blend.BlendFactorDestinationAlpha, true), - BlendOpAlpha: blendOperationToBlendOp12(blend.BlendOperationAlpha), - LogicOp: _D3D12_LOGIC_OP_NOOP, - RenderTargetWriteMask: writeMask, - }, - { - BlendEnable: 1, - LogicOpEnable: 0, - SrcBlend: blendFactorToBlend12(blend.BlendFactorSourceRGB, false), - DestBlend: blendFactorToBlend12(blend.BlendFactorDestinationRGB, false), - BlendOp: blendOperationToBlendOp12(blend.BlendOperationRGB), - SrcBlendAlpha: blendFactorToBlend12(blend.BlendFactorSourceAlpha, true), - DestBlendAlpha: blendFactorToBlend12(blend.BlendFactorDestinationAlpha, true), - BlendOpAlpha: blendOperationToBlendOp12(blend.BlendOperationAlpha), - LogicOp: _D3D12_LOGIC_OP_NOOP, - RenderTargetWriteMask: writeMask, - }, - { - BlendEnable: 1, - LogicOpEnable: 0, - SrcBlend: blendFactorToBlend12(blend.BlendFactorSourceRGB, false), - DestBlend: blendFactorToBlend12(blend.BlendFactorDestinationRGB, false), - BlendOp: blendOperationToBlendOp12(blend.BlendOperationRGB), - SrcBlendAlpha: blendFactorToBlend12(blend.BlendFactorSourceAlpha, true), - DestBlendAlpha: blendFactorToBlend12(blend.BlendFactorDestinationAlpha, true), - BlendOpAlpha: blendOperationToBlendOp12(blend.BlendOperationAlpha), - LogicOp: _D3D12_LOGIC_OP_NOOP, - RenderTargetWriteMask: writeMask, - }, - { - BlendEnable: 1, - LogicOpEnable: 0, - SrcBlend: blendFactorToBlend12(blend.BlendFactorSourceRGB, false), - DestBlend: blendFactorToBlend12(blend.BlendFactorDestinationRGB, false), - BlendOp: blendOperationToBlendOp12(blend.BlendOperationRGB), - SrcBlendAlpha: blendFactorToBlend12(blend.BlendFactorSourceAlpha, true), - DestBlendAlpha: blendFactorToBlend12(blend.BlendFactorDestinationAlpha, true), - BlendOpAlpha: blendOperationToBlendOp12(blend.BlendOperationAlpha), - LogicOp: _D3D12_LOGIC_OP_NOOP, - RenderTargetWriteMask: writeMask, - }, - { - BlendEnable: 1, - LogicOpEnable: 0, - SrcBlend: blendFactorToBlend12(blend.BlendFactorSourceRGB, false), - DestBlend: blendFactorToBlend12(blend.BlendFactorDestinationRGB, false), - BlendOp: blendOperationToBlendOp12(blend.BlendOperationRGB), - SrcBlendAlpha: blendFactorToBlend12(blend.BlendFactorSourceAlpha, true), - DestBlendAlpha: blendFactorToBlend12(blend.BlendFactorDestinationAlpha, true), - BlendOpAlpha: blendOperationToBlendOp12(blend.BlendOperationAlpha), - LogicOp: _D3D12_LOGIC_OP_NOOP, - RenderTargetWriteMask: writeMask, - }, + rtBlendDesc, // TODO: need to fill them all? }, }, SampleMask: math.MaxUint32, diff --git a/shader_test.go b/shader_test.go index fb52bf419576..b87fc7f19ef4 100644 --- a/shader_test.go +++ b/shader_test.go @@ -2623,16 +2623,6 @@ func Fragment(dstPos vec4, srcPos vec2, color vec4) (vec4, vec4, vec4, vec4, vec opts := &ebiten.NewImageOptions{ Unmanaged: true, } - imgs := [8]*ebiten.Image{ - ebiten.NewImageWithOptions(bounds, opts), - ebiten.NewImageWithOptions(bounds, opts), - ebiten.NewImageWithOptions(bounds, opts), - ebiten.NewImageWithOptions(bounds, opts), - ebiten.NewImageWithOptions(bounds, opts), - ebiten.NewImageWithOptions(bounds, opts), - ebiten.NewImageWithOptions(bounds, opts), - ebiten.NewImageWithOptions(bounds, opts), - } vertices := []ebiten.Vertex{ { DstX: 0, @@ -2653,6 +2643,16 @@ func Fragment(dstPos vec4, srcPos vec2, color vec4) (vec4, vec4, vec4, vec4, vec } indices := []uint16{0, 1, 2, 1, 2, 3} t.Run("8 locations", func(t *testing.T) { + imgs := [8]*ebiten.Image{ + ebiten.NewImageWithOptions(bounds, opts), + ebiten.NewImageWithOptions(bounds, opts), + ebiten.NewImageWithOptions(bounds, opts), + ebiten.NewImageWithOptions(bounds, opts), + ebiten.NewImageWithOptions(bounds, opts), + ebiten.NewImageWithOptions(bounds, opts), + ebiten.NewImageWithOptions(bounds, opts), + ebiten.NewImageWithOptions(bounds, opts), + } wantColors := [8]color.RGBA{ {R: 0xff, G: 0, B: 0, A: 0xff}, {R: 0, G: 0xff, B: 0, A: 0xff}, @@ -2677,11 +2677,17 @@ func Fragment(dstPos vec4, srcPos vec2, color vec4) (vec4, vec4, vec4, vec4, vec } }) - // Clear images - for _, img := range imgs { - img.Clear() - } t.Run("Empty locations", func(t *testing.T) { + imgs := [8]*ebiten.Image{ + ebiten.NewImageWithOptions(bounds, opts), + ebiten.NewImageWithOptions(bounds, opts), + ebiten.NewImageWithOptions(bounds, opts), + ebiten.NewImageWithOptions(bounds, opts), + ebiten.NewImageWithOptions(bounds, opts), + ebiten.NewImageWithOptions(bounds, opts), + ebiten.NewImageWithOptions(bounds, opts), + ebiten.NewImageWithOptions(bounds, opts), + } wantColors := [8]color.RGBA{ {}, {R: 0, G: 0xff, B: 0, A: 0xff}, @@ -2697,7 +2703,6 @@ func Fragment(dstPos vec4, srcPos vec2, color vec4) (vec4, vec4, vec4, vec4, vec } ebiten.DrawTrianglesShaderMRT(dsts, vertices, indices, s, nil) for k, dst := range imgs { - t.Log("image index:", k) for j := 0; j < h; j++ { for i := 0; i < w; i++ { got := dst.At(i, j).(color.RGBA) @@ -2710,11 +2715,17 @@ func Fragment(dstPos vec4, srcPos vec2, color vec4) (vec4, vec4, vec4, vec4, vec } }) - // Clear images - for _, img := range imgs { - img.Clear() - } t.Run("1 location (first slot)", func(t *testing.T) { + imgs := [8]*ebiten.Image{ + ebiten.NewImageWithOptions(bounds, opts), + ebiten.NewImageWithOptions(bounds, opts), + ebiten.NewImageWithOptions(bounds, opts), + ebiten.NewImageWithOptions(bounds, opts), + ebiten.NewImageWithOptions(bounds, opts), + ebiten.NewImageWithOptions(bounds, opts), + ebiten.NewImageWithOptions(bounds, opts), + ebiten.NewImageWithOptions(bounds, opts), + } wantColors := [8]color.RGBA{ {R: 0xff, G: 0, B: 0, A: 0xff}, {}, {}, {}, {}, {}, {}, {},