diff --git a/internal/graphicsdriver/directx/graphics_windows.go b/internal/graphicsdriver/directx/graphics_windows.go index 94f4d26f0..f9cd23975 100644 --- a/internal/graphicsdriver/directx/graphics_windows.go +++ b/internal/graphicsdriver/directx/graphics_windows.go @@ -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 } diff --git a/internal/graphicsdriver/directx/pipeline_windows.go b/internal/graphicsdriver/directx/pipeline_windows.go index 6c16da894..fe110af33 100644 --- a/internal/graphicsdriver/directx/pipeline_windows.go +++ b/internal/graphicsdriver/directx/pipeline_windows.go @@ -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{