Compare commits

..

2 Commits

Author SHA1 Message Date
Bertrand Jung
bde384b707
Merge ec592390e7 into 9cd7b34a77 2024-04-14 16:39:09 +00:00
Zyko
ec592390e7 nth attempt at fixing directx 12 2024-04-14 18:39:01 +02:00
2 changed files with 44 additions and 14 deletions

View File

@ -44,7 +44,9 @@ type graphics12 struct {
device *_ID3D12Device device *_ID3D12Device
commandQueue *_ID3D12CommandQueue commandQueue *_ID3D12CommandQueue
rtvDescriptorHeap *_ID3D12DescriptorHeap rtvDescriptorHeap *_ID3D12DescriptorHeap
rtvEmptyDescriptorHeap *_ID3D12DescriptorHeap
rtvDescriptorSize uint32 rtvDescriptorSize uint32
emptyRenderTarget *_ID3D12Resource
renderTargets [frameCount]*_ID3D12Resource renderTargets [frameCount]*_ID3D12Resource
framePipelineToken _D3D12XBOX_FRAME_PIPELINE_TOKEN framePipelineToken _D3D12XBOX_FRAME_PIPELINE_TOKEN
@ -418,6 +420,34 @@ func (g *graphics12) initializeMembers(frameIndex int) (ferr error) {
g.rtvDescriptorHeap = nil g.rtvDescriptorHeap = nil
} }
}() }()
// Create a descriptor heap for empty RTV in case of MRT with empty locations.
h, err = g.device.CreateDescriptorHeap(&_D3D12_DESCRIPTOR_HEAP_DESC{
Type: _D3D12_DESCRIPTOR_HEAP_TYPE_RTV,
NumDescriptors: frameCount,
Flags: _D3D12_DESCRIPTOR_HEAP_FLAG_NONE,
NodeMask: 0,
})
if err != nil {
return err
}
g.rtvEmptyDescriptorHeap = h
defer func() {
if ferr != nil {
g.rtvEmptyDescriptorHeap.Release()
g.rtvEmptyDescriptorHeap = nil
}
}()
hnd, err := g.rtvEmptyDescriptorHeap.GetCPUDescriptorHandleForHeapStart()
if err != nil {
return err
}
// Create an empty render target for empty destinations at DrawTriangles
g.device.CreateRenderTargetView(nil, &_D3D12_RENDER_TARGET_VIEW_DESC{
Format: _DXGI_FORMAT_R8G8B8A8_UNORM,
ViewDimension: _D3D12_RTV_DIMENSION_TEXTURE2D,
}, hnd)
g.rtvDescriptorSize = g.device.GetDescriptorHandleIncrementSize(_D3D12_DESCRIPTOR_HEAP_TYPE_RTV) g.rtvDescriptorSize = g.device.GetDescriptorHandleIncrementSize(_D3D12_DESCRIPTOR_HEAP_TYPE_RTV)
if err := g.pipelineStates.initialize(g.device); err != nil { if err := g.pipelineStates.initialize(g.device); err != nil {
@ -1090,20 +1120,15 @@ func (g *graphics12) setAsRenderTargets(dsts []*image12, useStencil bool) error
// Ignore a nil image in case of MRT // Ignore a nil image in case of MRT
if img == nil { if img == nil {
_ = i _ = i
rtvBase, err := g.rtvDescriptorHeap.GetCPUDescriptorHandleForHeapStart() rtv, err := g.rtvEmptyDescriptorHeap.GetCPUDescriptorHandleForHeapStart()
if err != nil { if err != nil {
return err return err
} }
rtv := rtvBase
rtv.Offset(int32(g.frameIndex), g.rtvDescriptorSize) rtv.Offset(int32(g.frameIndex), g.rtvDescriptorSize)
rtvs = append(rtvs, rtv) rtvs = append(rtvs, rtv)
continue continue
} }
if err := img.ensureRenderTargetView(g.device); err != nil {
return err
}
if img.screen { if img.screen {
if useStencil { if useStencil {
return fmt.Errorf("directx: stencils are not available on the screen framebuffer") return fmt.Errorf("directx: stencils are not available on the screen framebuffer")
@ -1119,6 +1144,10 @@ func (g *graphics12) setAsRenderTargets(dsts []*image12, useStencil bool) error
continue continue
} }
if err := img.ensureRenderTargetView(g.device); err != nil {
return err
}
rtvBase, err := img.rtvDescriptorHeap.GetCPUDescriptorHandleForHeapStart() rtvBase, err := img.rtvDescriptorHeap.GetCPUDescriptorHandleForHeapStart()
if err != nil { if err != nil {
return err return err

View File

@ -510,7 +510,8 @@ 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? rtBlendDesc, rtBlendDesc, rtBlendDesc, rtBlendDesc,
rtBlendDesc, rtBlendDesc, rtBlendDesc, rtBlendDesc, // TODO: need to fill them all?
}, },
}, },
SampleMask: math.MaxUint32, SampleMask: math.MaxUint32,