From b44189e046438a2a1a3d7f1819e72e2e94606825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Wed, 12 Aug 2015 22:50:17 -0700 Subject: [PATCH] Cleanup. --- src/renderer_d3d12.cpp | 43 ++++++++++++++++++++++++++++++++---------- src/renderer_d3d12.h | 4 +++- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index 67639737..65d0386a 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -1413,7 +1413,7 @@ namespace bgfx { namespace d3d12 VertexBufferD3D12& vb = m_vertexBuffers[_blitter.m_vb->handle.idx]; const VertexDecl& vertexDecl = m_vertexDecls[_blitter.m_vb->decl.idx]; D3D12_VERTEX_BUFFER_VIEW viewDesc; - viewDesc.BufferLocation = vb.m_ptr->GetGPUVirtualAddress(); + viewDesc.BufferLocation = vb.m_gpuVA; viewDesc.StrideInBytes = vertexDecl.m_stride; viewDesc.SizeInBytes = vb.m_size; m_commandList->IASetVertexBuffers(0, 1, &viewDesc); @@ -1421,7 +1421,7 @@ namespace bgfx { namespace d3d12 const BufferD3D12& ib = m_indexBuffers[_blitter.m_ib->handle.idx]; D3D12_INDEX_BUFFER_VIEW ibv; ibv.Format = DXGI_FORMAT_R16_UINT; - ibv.BufferLocation = ib.m_ptr->GetGPUVirtualAddress(); + ibv.BufferLocation = ib.m_gpuVA; ibv.SizeInBytes = ib.m_size; m_commandList->IASetIndexBuffer(&ibv); @@ -2518,6 +2518,7 @@ data.NumQualityLevels = 0; ) ); m_upload = createCommittedResource(device, HeapProperty::Upload, desc.NumDescriptors * 1024); + m_gpuVA = m_upload->GetGPUVirtualAddress(); m_upload->Map(0, NULL, (void**)&m_data); reset(m_gpuHandle); @@ -2541,7 +2542,7 @@ data.NumQualityLevels = 0; void* ScratchBufferD3D12::alloc(D3D12_GPU_VIRTUAL_ADDRESS& _gpuAddress, uint32_t _size) { - _gpuAddress = m_upload->GetGPUVirtualAddress() + m_pos; + _gpuAddress = m_gpuVA + m_pos; D3D12_CONSTANT_BUFFER_VIEW_DESC desc; desc.BufferLocation = _gpuAddress; desc.SizeInBytes = _size; @@ -2573,12 +2574,33 @@ data.NumQualityLevels = 0; m_gpuHandle.ptr += m_incrementSize; } - void ScratchBufferD3D12::allocUav(D3D12_GPU_DESCRIPTOR_HANDLE& gpuHandle, TextureD3D12& _texture) + void ScratchBufferD3D12::allocUav(D3D12_GPU_DESCRIPTOR_HANDLE& gpuHandle, TextureD3D12& _texture, uint8_t _mip) { ID3D12Device* device = s_renderD3D12->m_device; + + D3D12_UNORDERED_ACCESS_VIEW_DESC tmpUavd; + D3D12_UNORDERED_ACCESS_VIEW_DESC* uavd = &_texture.m_uavd; + if (0 != _mip) + { + memcpy(&tmpUavd, uavd, sizeof(tmpUavd) ); + switch (_texture.m_uavd.ViewDimension) + { + default: + case D3D12_UAV_DIMENSION_TEXTURE2D: + uavd->Texture2D.MipSlice = _mip; + break; + + case D3D12_UAV_DIMENSION_TEXTURE3D: + uavd->Texture3D.MipSlice = _mip; + break; + } + + uavd = &tmpUavd; + } + device->CreateUnorderedAccessView(_texture.m_ptr , NULL - , &_texture.m_uavd + , uavd , m_cpuHandle ); m_cpuHandle.ptr += m_incrementSize; @@ -2811,7 +2833,8 @@ data.NumQualityLevels = 0; ID3D12Device* device = s_renderD3D12->m_device; ID3D12GraphicsCommandList* commandList = s_renderD3D12->m_commandList; - m_ptr = createCommittedResource(device, HeapProperty::Default, _size, flags); + m_ptr = createCommittedResource(device, HeapProperty::Default, _size, flags); + m_gpuVA = m_ptr->GetGPUVirtualAddress(); setState(commandList, D3D12_RESOURCE_STATE_GENERIC_READ); if (!m_dynamic) @@ -3820,7 +3843,7 @@ data.NumQualityLevels = 0; if (Access::Read != bind.m_un.m_compute.m_access) { - scratchBuffer.allocUav(srvHandle[ii], texture); + scratchBuffer.allocUav(srvHandle[ii], texture, bind.m_un.m_compute.m_mip); } else { @@ -4109,14 +4132,14 @@ data.NumQualityLevels = 0; D3D12_VERTEX_BUFFER_VIEW vbView[2]; uint32_t numVertexBuffers = 1; - vbView[0].BufferLocation = vb.m_ptr->GetGPUVirtualAddress(); + vbView[0].BufferLocation = vb.m_gpuVA; vbView[0].StrideInBytes = vertexDecl.m_stride; vbView[0].SizeInBytes = vb.m_size; if (isValid(draw.m_instanceDataBuffer) ) { const VertexBufferD3D12& inst = m_vertexBuffers[draw.m_instanceDataBuffer.idx]; - vbView[1].BufferLocation = inst.m_ptr->GetGPUVirtualAddress() + draw.m_instanceDataOffset; + vbView[1].BufferLocation = inst.m_gpuVA + draw.m_instanceDataOffset; vbView[1].StrideInBytes = draw.m_instanceDataStride; vbView[1].SizeInBytes = draw.m_numInstances * draw.m_instanceDataStride; ++numVertexBuffers; @@ -4144,7 +4167,7 @@ data.NumQualityLevels = 0; ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT ; - ibv.BufferLocation = ib.m_ptr->GetGPUVirtualAddress(); + ibv.BufferLocation = ib.m_gpuVA; ibv.SizeInBytes = ib.m_size; m_commandList->IASetIndexBuffer(&ibv); } diff --git a/src/renderer_d3d12.h b/src/renderer_d3d12.h index da30362a..954588ab 100644 --- a/src/renderer_d3d12.h +++ b/src/renderer_d3d12.h @@ -47,7 +47,7 @@ namespace bgfx { namespace d3d12 void reset(D3D12_GPU_DESCRIPTOR_HANDLE& gpuHandle); void* alloc(D3D12_GPU_VIRTUAL_ADDRESS& gpuAddress, uint32_t _size); void alloc(D3D12_GPU_DESCRIPTOR_HANDLE& gpuHandle, struct TextureD3D12& _texture); - void allocUav(D3D12_GPU_DESCRIPTOR_HANDLE& gpuHandle, struct TextureD3D12& _texture); + void allocUav(D3D12_GPU_DESCRIPTOR_HANDLE& gpuHandle, struct TextureD3D12& _texture, uint8_t _mip); void alloc(D3D12_GPU_DESCRIPTOR_HANDLE& gpuHandle, struct BufferD3D12& _buffer); void allocUav(D3D12_GPU_DESCRIPTOR_HANDLE& gpuHandle, struct BufferD3D12& _buffer); @@ -60,6 +60,7 @@ namespace bgfx { namespace d3d12 private: ID3D12DescriptorHeap* m_heap; ID3D12Resource* m_upload; + D3D12_GPU_VIRTUAL_ADDRESS m_gpuVA; D3D12_CPU_DESCRIPTOR_HANDLE m_cpuHandle; D3D12_GPU_DESCRIPTOR_HANDLE m_gpuHandle; uint32_t m_incrementSize; @@ -132,6 +133,7 @@ namespace bgfx { namespace d3d12 D3D12_SHADER_RESOURCE_VIEW_DESC m_srvd; D3D12_UNORDERED_ACCESS_VIEW_DESC m_uavd; ID3D12Resource* m_ptr; + D3D12_GPU_VIRTUAL_ADDRESS m_gpuVA; D3D12_RESOURCE_STATES m_state; uint32_t m_size; uint16_t m_flags;