mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-22 07:50:08 +01:00
Attempt at fixing Directx 12
This commit is contained in:
parent
483059184f
commit
9881530b46
@ -36,9 +36,9 @@ var (
|
|||||||
ebiten.NewImage(dstSize, dstSize),
|
ebiten.NewImage(dstSize, dstSize),
|
||||||
ebiten.NewImage(dstSize, dstSize),
|
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,
|
Unmanaged: true,
|
||||||
}),*/
|
}),
|
||||||
ebiten.NewImageWithOptions(image.Rect(0, 0, dstSize, dstSize), &ebiten.NewImageOptions{
|
ebiten.NewImageWithOptions(image.Rect(0, 0, dstSize, dstSize), &ebiten.NewImageOptions{
|
||||||
Unmanaged: true,
|
Unmanaged: true,
|
||||||
}),
|
}),
|
||||||
@ -101,7 +101,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
|||||||
indices := []uint16{0, 1, 2, 1, 2, 3}
|
indices := []uint16{0, 1, 2, 1, 2, 3}
|
||||||
ebiten.DrawTrianglesShaderMRT(dsts, vertices, indices, s, nil)
|
ebiten.DrawTrianglesShaderMRT(dsts, vertices, indices, s, nil)
|
||||||
// Dst 0
|
// Dst 0
|
||||||
//screen.DrawImage(dsts[0], nil)
|
screen.DrawImage(dsts[0], nil)
|
||||||
// Dst 1
|
// Dst 1
|
||||||
opts := &ebiten.DrawImageOptions{}
|
opts := &ebiten.DrawImageOptions{}
|
||||||
opts.GeoM.Translate(dstSize, 0)
|
opts.GeoM.Translate(dstSize, 0)
|
||||||
|
@ -1127,13 +1127,18 @@ func (g *graphics12) setAsRenderTargets(dsts []*image12, useStencil bool) error
|
|||||||
rtv := rtvBase
|
rtv := rtvBase
|
||||||
rtvs = append(rtvs, rtv)
|
rtvs = append(rtvs, rtv)
|
||||||
|
|
||||||
if !useStencil || dsv != nil {
|
if !useStencil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := img.ensureDepthStencilView(g.device); err != nil {
|
if err := img.ensureDepthStencilView(g.device); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dsv != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
sv, err := img.dsvDescriptorHeap.GetCPUDescriptorHandleForHeapStart()
|
sv, err := img.dsvDescriptorHeap.GetCPUDescriptorHandleForHeapStart()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -1231,7 +1236,6 @@ func (g *graphics12) DrawTriangles(dstIDs [graphics.ShaderDstImageCount]graphics
|
|||||||
targetCount = graphics.ShaderDstImageCount
|
targetCount = graphics.ShaderDstImageCount
|
||||||
}
|
}
|
||||||
|
|
||||||
g.drawCommandList.RSSetViewports([]_D3D12_VIEWPORT{vp})
|
|
||||||
if err := g.setAsRenderTargets(dsts[:targetCount], fillRule != graphicsdriver.FillAll); err != nil {
|
if err := g.setAsRenderTargets(dsts[:targetCount], fillRule != graphicsdriver.FillAll); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1241,6 +1245,8 @@ func (g *graphics12) DrawTriangles(dstIDs [graphics.ShaderDstImageCount]graphics
|
|||||||
|
|
||||||
g.needFlushDrawCommandList = true
|
g.needFlushDrawCommandList = true
|
||||||
|
|
||||||
|
g.drawCommandList.RSSetViewports([]_D3D12_VIEWPORT{vp})
|
||||||
|
|
||||||
g.drawCommandList.IASetPrimitiveTopology(_D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST)
|
g.drawCommandList.IASetPrimitiveTopology(_D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST)
|
||||||
g.drawCommandList.IASetVertexBuffers(0, []_D3D12_VERTEX_BUFFER_VIEW{
|
g.drawCommandList.IASetVertexBuffers(0, []_D3D12_VERTEX_BUFFER_VIEW{
|
||||||
{
|
{
|
||||||
|
@ -70,7 +70,7 @@ func (i *image12) disposeImpl() {
|
|||||||
|
|
||||||
func (i *image12) ReadPixels(args []graphicsdriver.PixelsArgs) error {
|
func (i *image12) ReadPixels(args []graphicsdriver.PixelsArgs) error {
|
||||||
if i.screen {
|
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 {
|
if err := i.graphics.flushCommandList(i.graphics.drawCommandList); err != nil {
|
||||||
|
@ -484,6 +484,18 @@ func (p *pipelineStates) newPipelineState(device *_ID3D12Device, vsh, psh *_ID3D
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a pipeline state.
|
// 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{
|
psoDesc := _D3D12_GRAPHICS_PIPELINE_STATE_DESC{
|
||||||
pRootSignature: rootSignature,
|
pRootSignature: rootSignature,
|
||||||
VS: _D3D12_SHADER_BYTECODE{
|
VS: _D3D12_SHADER_BYTECODE{
|
||||||
@ -498,102 +510,7 @@ func (p *pipelineStates) newPipelineState(device *_ID3D12Device, vsh, psh *_ID3D
|
|||||||
AlphaToCoverageEnable: 0,
|
AlphaToCoverageEnable: 0,
|
||||||
IndependentBlendEnable: 0,
|
IndependentBlendEnable: 0,
|
||||||
RenderTarget: [8]_D3D12_RENDER_TARGET_BLEND_DESC{
|
RenderTarget: [8]_D3D12_RENDER_TARGET_BLEND_DESC{
|
||||||
{
|
rtBlendDesc, // TODO: need to fill them all?
|
||||||
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,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
SampleMask: math.MaxUint32,
|
SampleMask: math.MaxUint32,
|
||||||
|
@ -2623,16 +2623,6 @@ func Fragment(dstPos vec4, srcPos vec2, color vec4) (vec4, vec4, vec4, vec4, vec
|
|||||||
opts := &ebiten.NewImageOptions{
|
opts := &ebiten.NewImageOptions{
|
||||||
Unmanaged: true,
|
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{
|
vertices := []ebiten.Vertex{
|
||||||
{
|
{
|
||||||
DstX: 0,
|
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}
|
indices := []uint16{0, 1, 2, 1, 2, 3}
|
||||||
t.Run("8 locations", func(t *testing.T) {
|
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{
|
wantColors := [8]color.RGBA{
|
||||||
{R: 0xff, G: 0, B: 0, A: 0xff},
|
{R: 0xff, G: 0, B: 0, A: 0xff},
|
||||||
{R: 0, G: 0xff, 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) {
|
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{
|
wantColors := [8]color.RGBA{
|
||||||
{},
|
{},
|
||||||
{R: 0, G: 0xff, B: 0, A: 0xff},
|
{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)
|
ebiten.DrawTrianglesShaderMRT(dsts, vertices, indices, s, nil)
|
||||||
for k, dst := range imgs {
|
for k, dst := range imgs {
|
||||||
t.Log("image index:", k)
|
|
||||||
for j := 0; j < h; j++ {
|
for j := 0; j < h; j++ {
|
||||||
for i := 0; i < w; i++ {
|
for i := 0; i < w; i++ {
|
||||||
got := dst.At(i, j).(color.RGBA)
|
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) {
|
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{
|
wantColors := [8]color.RGBA{
|
||||||
{R: 0xff, G: 0, B: 0, A: 0xff},
|
{R: 0xff, G: 0, B: 0, A: 0xff},
|
||||||
{}, {}, {}, {}, {}, {}, {},
|
{}, {}, {}, {}, {}, {}, {},
|
||||||
|
Loading…
Reference in New Issue
Block a user