internal/graphicsdriver/directx: refactoring

This commit is contained in:
Hajime Hoshi 2022-06-13 17:25:27 +09:00
parent 348435f769
commit 4adf46c2b0
4 changed files with 49 additions and 41 deletions

View File

@ -76,8 +76,8 @@ func _ID3D12GraphicsCommandList_IASetPrimitiveTopology(i *_ID3D12GraphicsCommand
C.Ebitengine_ID3D12GraphicsCommandList_IASetPrimitiveTopology(unsafe.Pointer(i), C.int32_t(primitiveTopology))
}
func _ID3D12GraphicsCommandList_IASetVertexBuffers(i *_ID3D12GraphicsCommandList, startSlot uint32, numViews uint32, pViews *_D3D12_VERTEX_BUFFER_VIEW) {
C.Ebitengine_ID3D12GraphicsCommandList_IASetVertexBuffers(unsafe.Pointer(i), C.uint32_t(startSlot), C.uint32_t(numViews), unsafe.Pointer(pViews))
func _ID3D12GraphicsCommandList_IASetVertexBuffers(i *_ID3D12GraphicsCommandList, startSlot uint32, pViews []_D3D12_VERTEX_BUFFER_VIEW) {
C.Ebitengine_ID3D12GraphicsCommandList_IASetVertexBuffers(unsafe.Pointer(i), C.uint32_t(startSlot), C.uint32_t(len(pViews)), unsafe.Pointer(&pViews[0]))
}
func _ID3D12GraphicsCommandList_OMSetStencilRef(i *_ID3D12GraphicsCommandList, stencilRef uint32) {

View File

@ -29,7 +29,7 @@ func _ID3D12GraphicsCommandList_IASetPrimitiveTopology(i *_ID3D12GraphicsCommand
panic("not implemented")
}
func _ID3D12GraphicsCommandList_IASetVertexBuffers(i *_ID3D12GraphicsCommandList, startSlot uint32, numViews uint32, pViews *_D3D12_VERTEX_BUFFER_VIEW) {
func _ID3D12GraphicsCommandList_IASetVertexBuffers(i *_ID3D12GraphicsCommandList, startSlot uint32, pViews []_D3D12_VERTEX_BUFFER_VIEW) {
panic("not implemented")
}

View File

@ -1750,17 +1750,17 @@ type _ID3D12GraphicsCommandList_Vtbl struct {
_ uintptr
}
func (i *_ID3D12GraphicsCommandList) ClearDepthStencilView(depthStencilView _D3D12_CPU_DESCRIPTOR_HANDLE, clearFlags _D3D12_CLEAR_FLAGS, depth float32, stencil uint8, numRects uint32, pRects *_D3D12_RECT) {
func (i *_ID3D12GraphicsCommandList) ClearDepthStencilView(depthStencilView _D3D12_CPU_DESCRIPTOR_HANDLE, clearFlags _D3D12_CLEAR_FLAGS, depth float32, stencil uint8, pRects []_D3D12_RECT) {
syscall.Syscall9(i.vtbl.ClearDepthStencilView, 7, uintptr(unsafe.Pointer(i)),
depthStencilView.ptr, uintptr(clearFlags), uintptr(math.Float32bits(depth)),
uintptr(stencil), uintptr(numRects), uintptr(unsafe.Pointer(pRects)),
uintptr(stencil), uintptr(len(pRects)), uintptr(unsafe.Pointer(&pRects[0])),
0, 0)
runtime.KeepAlive(pRects)
}
func (i *_ID3D12GraphicsCommandList) ClearRenderTargetView(pRenderTargetView _D3D12_CPU_DESCRIPTOR_HANDLE, colorRGBA [4]float32, numRects uint32, pRects *_D3D12_RECT) {
func (i *_ID3D12GraphicsCommandList) ClearRenderTargetView(pRenderTargetView _D3D12_CPU_DESCRIPTOR_HANDLE, colorRGBA [4]float32, pRects []_D3D12_RECT) {
syscall.Syscall6(i.vtbl.ClearRenderTargetView, 5, uintptr(unsafe.Pointer(i)),
pRenderTargetView.ptr, uintptr(unsafe.Pointer(&colorRGBA[0])), uintptr(numRects), uintptr(unsafe.Pointer(pRects)),
pRenderTargetView.ptr, uintptr(unsafe.Pointer(&colorRGBA[0])), uintptr(len(pRects)), uintptr(unsafe.Pointer(&pRects[0])),
0)
runtime.KeepAlive(pRenderTargetView)
}
@ -1835,13 +1835,13 @@ func (i *_ID3D12GraphicsCommandList) IASetPrimitiveTopology(primitiveTopology _D
uintptr(primitiveTopology), 0)
}
func (i *_ID3D12GraphicsCommandList) IASetVertexBuffers(startSlot uint32, numViews uint32, pViews *_D3D12_VERTEX_BUFFER_VIEW) {
func (i *_ID3D12GraphicsCommandList) IASetVertexBuffers(startSlot uint32, pViews []_D3D12_VERTEX_BUFFER_VIEW) {
if microsoftgdk.IsXbox() {
_ID3D12GraphicsCommandList_IASetVertexBuffers(i, startSlot, numViews, pViews)
_ID3D12GraphicsCommandList_IASetVertexBuffers(i, startSlot, pViews)
return
}
syscall.Syscall6(i.vtbl.IASetVertexBuffers, 4, uintptr(unsafe.Pointer(i)),
uintptr(startSlot), uintptr(numViews), uintptr(unsafe.Pointer(pViews)),
uintptr(startSlot), uintptr(len(pViews)), uintptr(unsafe.Pointer(&pViews[0])),
0, 0)
runtime.KeepAlive(pViews)
}
@ -1877,21 +1877,21 @@ func (i *_ID3D12GraphicsCommandList) Reset(pAllocator *_ID3D12CommandAllocator,
return nil
}
func (i *_ID3D12GraphicsCommandList) ResourceBarrier(numBarriers uint32, pBarriers *_D3D12_RESOURCE_BARRIER_Transition) {
func (i *_ID3D12GraphicsCommandList) ResourceBarrier(pBarriers []_D3D12_RESOURCE_BARRIER_Transition) {
syscall.Syscall(i.vtbl.ResourceBarrier, 3, uintptr(unsafe.Pointer(i)),
uintptr(numBarriers), uintptr(unsafe.Pointer(pBarriers)))
uintptr(len(pBarriers)), uintptr(unsafe.Pointer(&pBarriers[0])))
runtime.KeepAlive(pBarriers)
}
func (i *_ID3D12GraphicsCommandList) RSSetViewports(numViewports uint32, pViewports *_D3D12_VIEWPORT) {
func (i *_ID3D12GraphicsCommandList) RSSetViewports(pViewports []_D3D12_VIEWPORT) {
syscall.Syscall(i.vtbl.RSSetViewports, 3, uintptr(unsafe.Pointer(i)),
uintptr(numViewports), uintptr(unsafe.Pointer(pViewports)))
uintptr(len(pViewports)), uintptr(unsafe.Pointer(&pViewports[0])))
runtime.KeepAlive(pViewports)
}
func (i *_ID3D12GraphicsCommandList) RSSetScissorRects(numRects uint32, pRects *_D3D12_RECT) {
func (i *_ID3D12GraphicsCommandList) RSSetScissorRects(pRects []_D3D12_RECT) {
syscall.Syscall(i.vtbl.RSSetScissorRects, 3, uintptr(unsafe.Pointer(i)),
uintptr(numRects), uintptr(unsafe.Pointer(pRects)))
uintptr(len(pRects)), uintptr(unsafe.Pointer(&pRects[0])))
runtime.KeepAlive(pRects)
}

View File

@ -1115,26 +1115,32 @@ func (g *Graphics) DrawTriangles(dstID graphicsdriver.ImageID, srcs [graphics.Sh
}
w, h := dst.internalSize()
g.drawCommandList.RSSetViewports(1, &_D3D12_VIEWPORT{
TopLeftX: 0,
TopLeftY: 0,
Width: float32(w),
Height: float32(h),
MinDepth: _D3D12_MIN_DEPTH,
MaxDepth: _D3D12_MAX_DEPTH,
g.drawCommandList.RSSetViewports([]_D3D12_VIEWPORT{
{
TopLeftX: 0,
TopLeftY: 0,
Width: float32(w),
Height: float32(h),
MinDepth: _D3D12_MIN_DEPTH,
MaxDepth: _D3D12_MAX_DEPTH,
},
})
g.drawCommandList.RSSetScissorRects(1, &_D3D12_RECT{
left: int32(dstRegion.X),
top: int32(dstRegion.Y),
right: int32(dstRegion.X + dstRegion.Width),
bottom: int32(dstRegion.Y + dstRegion.Height),
g.drawCommandList.RSSetScissorRects([]_D3D12_RECT{
{
left: int32(dstRegion.X),
top: int32(dstRegion.Y),
right: int32(dstRegion.X + dstRegion.Width),
bottom: int32(dstRegion.Y + dstRegion.Height),
},
})
g.drawCommandList.IASetPrimitiveTopology(_D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST)
g.drawCommandList.IASetVertexBuffers(0, 1, &_D3D12_VERTEX_BUFFER_VIEW{
BufferLocation: g.vertices[g.frameIndex][len(g.vertices[g.frameIndex])-1].GetGPUVirtualAddress(),
SizeInBytes: graphics.IndicesNum * graphics.VertexFloatNum * uint32(unsafe.Sizeof(float32(0))),
StrideInBytes: graphics.VertexFloatNum * uint32(unsafe.Sizeof(float32(0))),
g.drawCommandList.IASetVertexBuffers(0, []_D3D12_VERTEX_BUFFER_VIEW{
{
BufferLocation: g.vertices[g.frameIndex][len(g.vertices[g.frameIndex])-1].GetGPUVirtualAddress(),
SizeInBytes: graphics.IndicesNum * graphics.VertexFloatNum * uint32(unsafe.Sizeof(float32(0))),
StrideInBytes: graphics.VertexFloatNum * uint32(unsafe.Sizeof(float32(0))),
},
})
g.drawCommandList.IASetIndexBuffer(&_D3D12_INDEX_BUFFER_VIEW{
BufferLocation: g.indices[g.frameIndex][len(g.indices[g.frameIndex])-1].GetGPUVirtualAddress(),
@ -1449,14 +1455,16 @@ func (i *Image) transiteState(commandList *_ID3D12GraphicsCommandList, newState
return
}
commandList.ResourceBarrier(1, &_D3D12_RESOURCE_BARRIER_Transition{
Type: _D3D12_RESOURCE_BARRIER_TYPE_TRANSITION,
Flags: _D3D12_RESOURCE_BARRIER_FLAG_NONE,
Transition: _D3D12_RESOURCE_TRANSITION_BARRIER{
pResource: i.resource(),
Subresource: _D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES,
StateBefore: i.state,
StateAfter: newState,
commandList.ResourceBarrier([]_D3D12_RESOURCE_BARRIER_Transition{
{
Type: _D3D12_RESOURCE_BARRIER_TYPE_TRANSITION,
Flags: _D3D12_RESOURCE_BARRIER_FLAG_NONE,
Transition: _D3D12_RESOURCE_TRANSITION_BARRIER{
pResource: i.resource(),
Subresource: _D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES,
StateBefore: i.state,
StateAfter: newState,
},
},
})
i.state = newState
@ -1501,7 +1509,7 @@ func (i *Image) setAsRenderTarget(device *_ID3D12Device, useStencil bool) error
}
dsv = &v
i.graphics.drawCommandList.ClearDepthStencilView(v, _D3D12_CLEAR_FLAG_STENCIL, 0, 0, 0, nil)
i.graphics.drawCommandList.ClearDepthStencilView(v, _D3D12_CLEAR_FLAG_STENCIL, 0, 0, nil)
i.graphics.drawCommandList.OMSetStencilRef(0)
}
i.graphics.drawCommandList.OMSetRenderTargets(1, &rtv, false, dsv) // TODO: Pass depth-stencil here!