internal/graphicsdriver/directx: bug fix: wrong offsets

* Wrong offsets were speicified when creating a constant buffer view and
  a shader resource view.
* Wrong root descriptor tables were speicified. For one draw command,
  one descriptor table for a constant buffer and textures should be used.

Updates #2198
Closes #2201
This commit is contained in:
Hajime Hoshi 2022-07-14 02:41:44 +09:00
parent ddaef29bc9
commit 4a17f6159a
2 changed files with 10 additions and 9 deletions

View File

@ -593,7 +593,7 @@ func (g *Graphics) End(present bool) error {
// Release vertices and indices buffers when too many ones were created.
// This is needed espciallly for testings, where present is always false.
if len(g.vertices[g.frameIndex]) >= 16 {
if len(g.vertices[g.frameIndex]) >= numDescriptorsPerFrame {
if err := g.waitForCommandQueue(); err != nil {
return err
}

View File

@ -23,7 +23,7 @@ import (
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
)
const numDescriptorsPerFrame = 256
const numDescriptorsPerFrame = 16
func operationToBlend(c graphicsdriver.Operation, alpha bool) _D3D12_BLEND {
switch c {
@ -389,7 +389,8 @@ func (p *pipelineStates) useGraphicsPipelineState(device *iD3D12Device, commandL
p.constantBuffers[frameIndex][idx] = cb
h := p.shaderDescriptorHeap.GetCPUDescriptorHandleForHeapStart()
h.Offset(int32(frameIndex*numDescriptorsPerFrame+numConstantBufferAndSourceTextures*idx), p.shaderDescriptorSize)
offset := int32(numConstantBufferAndSourceTextures * (frameIndex*numDescriptorsPerFrame + idx))
h.Offset(offset, p.shaderDescriptorSize)
device.CreateConstantBufferView(&_D3D12_CONSTANT_BUFFER_VIEW_DESC{
BufferLocation: cb.GetGPUVirtualAddress(),
SizeInBytes: bufferSize,
@ -397,7 +398,8 @@ func (p *pipelineStates) useGraphicsPipelineState(device *iD3D12Device, commandL
}
h := p.shaderDescriptorHeap.GetCPUDescriptorHandleForHeapStart()
h.Offset(int32(frameIndex*numDescriptorsPerFrame+numConstantBufferAndSourceTextures*idx), p.shaderDescriptorSize)
offset := int32(numConstantBufferAndSourceTextures * (frameIndex*numDescriptorsPerFrame + idx))
h.Offset(offset, p.shaderDescriptorSize)
for _, src := range srcs {
h.Offset(1, p.shaderDescriptorSize)
if src == nil {
@ -437,9 +439,8 @@ func (p *pipelineStates) useGraphicsPipelineState(device *iD3D12Device, commandL
// Match the indices with rootParams in graphicsPipelineState.
gh := p.shaderDescriptorHeap.GetGPUDescriptorHandleForHeapStart()
gh.Offset(int32(frameIndex*numDescriptorsPerFrame+numConstantBufferAndSourceTextures*idx), p.shaderDescriptorSize)
gh.Offset(offset, p.shaderDescriptorSize)
commandList.SetGraphicsRootDescriptorTable(0, gh)
gh.Offset(1, p.shaderDescriptorSize)
commandList.SetGraphicsRootDescriptorTable(1, gh)
commandList.SetGraphicsRootDescriptorTable(2, p.samplerDescriptorHeap.GetGPUDescriptorHandleForHeapStart())
@ -456,21 +457,21 @@ func (p *pipelineStates) ensureRootSignature(device *iD3D12Device) (rootSignatur
NumDescriptors: 1,
BaseShaderRegister: 0,
RegisterSpace: 0,
OffsetInDescriptorsFromTableStart: _D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND,
OffsetInDescriptorsFromTableStart: 0,
}
srv := _D3D12_DESCRIPTOR_RANGE{
RangeType: _D3D12_DESCRIPTOR_RANGE_TYPE_SRV, // t0
NumDescriptors: graphics.ShaderImageNum,
BaseShaderRegister: 0,
RegisterSpace: 0,
OffsetInDescriptorsFromTableStart: _D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND,
OffsetInDescriptorsFromTableStart: 1,
}
sampler := _D3D12_DESCRIPTOR_RANGE{
RangeType: _D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, // s0
NumDescriptors: 1,
BaseShaderRegister: 0,
RegisterSpace: 0,
OffsetInDescriptorsFromTableStart: _D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND,
OffsetInDescriptorsFromTableStart: 0,
}
rootParams := [...]_D3D12_ROOT_PARAMETER{