mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-05 23:44:31 +01:00
internal/graphicsdriver/directx: bug fix: wrong state transitions at screen images
This change fixes the following issues: * There should be two resource states for presenting targets, so an image for the screen must have two resource states, though it had only one in the current implementation. * At removeImage, the screen image was removed unexpectedly. Updates #2081 Closes #2151
This commit is contained in:
parent
b176867d07
commit
7a6cbcaea6
@ -582,8 +582,7 @@ func (g *Graphics) End(present bool) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// The screen image can be nil when resizing the window (#2081).
|
if present {
|
||||||
if present && g.screenImage != nil {
|
|
||||||
g.screenImage.transiteState(g.drawCommandList, _D3D12_RESOURCE_STATE_PRESENT)
|
g.screenImage.transiteState(g.drawCommandList, _D3D12_RESOURCE_STATE_PRESENT)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -839,7 +838,7 @@ func (g *Graphics) NewImage(width, height int) (graphicsdriver.Image, error) {
|
|||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
texture: t,
|
texture: t,
|
||||||
state: state,
|
states: [frameCount]_D3D12_RESOURCE_STATES{state},
|
||||||
layouts: layouts,
|
layouts: layouts,
|
||||||
numRows: numRows,
|
numRows: numRows,
|
||||||
totalBytes: totalBytes,
|
totalBytes: totalBytes,
|
||||||
@ -859,9 +858,10 @@ func (g *Graphics) NewScreenFramebufferImage(width, height int) (graphicsdriver.
|
|||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
screen: true,
|
screen: true,
|
||||||
state: _D3D12_RESOURCE_STATE_PRESENT,
|
states: [frameCount]_D3D12_RESOURCE_STATES{0, 0},
|
||||||
}
|
}
|
||||||
g.addImage(i)
|
g.addImage(i)
|
||||||
|
g.screenImage = i
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -873,17 +873,11 @@ func (g *Graphics) addImage(img *Image) {
|
|||||||
panic(fmt.Sprintf("directx: image ID %d was already registered", img.id))
|
panic(fmt.Sprintf("directx: image ID %d was already registered", img.id))
|
||||||
}
|
}
|
||||||
g.images[img.id] = img
|
g.images[img.id] = img
|
||||||
if img.screen {
|
|
||||||
g.screenImage = img
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Graphics) removeImage(img *Image) {
|
func (g *Graphics) removeImage(img *Image) {
|
||||||
delete(g.images, img.id)
|
delete(g.images, img.id)
|
||||||
g.disposedImages[g.frameIndex] = append(g.disposedImages[g.frameIndex], img)
|
g.disposedImages[g.frameIndex] = append(g.disposedImages[g.frameIndex], img)
|
||||||
if img.screen {
|
|
||||||
g.screenImage = nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Graphics) addShader(s *Shader) {
|
func (g *Graphics) addShader(s *Shader) {
|
||||||
@ -1201,7 +1195,7 @@ type Image struct {
|
|||||||
height int
|
height int
|
||||||
screen bool
|
screen bool
|
||||||
|
|
||||||
state _D3D12_RESOURCE_STATES
|
states [frameCount]_D3D12_RESOURCE_STATES
|
||||||
texture *iD3D12Resource1
|
texture *iD3D12Resource1
|
||||||
stencil *iD3D12Resource1
|
stencil *iD3D12Resource1
|
||||||
layouts _D3D12_PLACED_SUBRESOURCE_FOOTPRINT
|
layouts _D3D12_PLACED_SUBRESOURCE_FOOTPRINT
|
||||||
@ -1399,8 +1393,23 @@ func (i *Image) resource() *iD3D12Resource1 {
|
|||||||
return i.texture
|
return i.texture
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *Image) state() _D3D12_RESOURCE_STATES {
|
||||||
|
if i.screen {
|
||||||
|
return i.states[i.graphics.frameIndex]
|
||||||
|
}
|
||||||
|
return i.states[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *Image) setState(newState _D3D12_RESOURCE_STATES) {
|
||||||
|
if i.screen {
|
||||||
|
i.states[i.graphics.frameIndex] = newState
|
||||||
|
return
|
||||||
|
}
|
||||||
|
i.states[0] = newState
|
||||||
|
}
|
||||||
|
|
||||||
func (i *Image) transiteState(commandList *iD3D12GraphicsCommandList, newState _D3D12_RESOURCE_STATES) {
|
func (i *Image) transiteState(commandList *iD3D12GraphicsCommandList, newState _D3D12_RESOURCE_STATES) {
|
||||||
if i.state == newState {
|
if i.state() == newState {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1410,11 +1419,11 @@ func (i *Image) transiteState(commandList *iD3D12GraphicsCommandList, newState _
|
|||||||
Transition: _D3D12_RESOURCE_TRANSITION_BARRIER{
|
Transition: _D3D12_RESOURCE_TRANSITION_BARRIER{
|
||||||
pResource: i.resource(),
|
pResource: i.resource(),
|
||||||
Subresource: _D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES,
|
Subresource: _D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES,
|
||||||
StateBefore: i.state,
|
StateBefore: i.state(),
|
||||||
StateAfter: newState,
|
StateAfter: newState,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
i.state = newState
|
i.setState(newState)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) internalSize() (int, int) {
|
func (i *Image) internalSize() (int, int) {
|
||||||
|
Loading…
Reference in New Issue
Block a user