diff --git a/src/d3d11/d3d11_buffer.cpp b/src/d3d11/d3d11_buffer.cpp index 3bbdc308..755a72ce 100644 --- a/src/d3d11/d3d11_buffer.cpp +++ b/src/d3d11/d3d11_buffer.cpp @@ -58,6 +58,11 @@ namespace dxvk { } + DxvkBufferSlice D3D11Buffer::GetBufferSlice() const { + return DxvkBufferSlice(m_buffer, 0, m_desc.ByteWidth); + } + + HRESULT D3D11Buffer::Map( D3D11DeviceContext* pContext, D3D11_MAP MapType, @@ -117,22 +122,6 @@ namespace dxvk { } - void D3D11Buffer::Unmap( - D3D11DeviceContext* pContext) { - // Nothing to see here, folks - } - - - DxvkBufferSlice D3D11Buffer::GetCurrentBufferSlice() const { - return DxvkBufferSlice(m_buffer, 0, m_desc.ByteWidth); - } - - - DxvkBufferSlice D3D11Buffer::GetInitialBufferSlice() const { - return DxvkBufferSlice(m_buffer, 0, m_desc.ByteWidth); - } - - Rc D3D11Buffer::CreateBuffer( const D3D11_BUFFER_DESC* pDesc) const { // Gather usage information diff --git a/src/d3d11/d3d11_buffer.h b/src/d3d11/d3d11_buffer.h index 717ee0a8..727412f0 100644 --- a/src/d3d11/d3d11_buffer.h +++ b/src/d3d11/d3d11_buffer.h @@ -11,15 +11,6 @@ namespace dxvk { class D3D11DeviceContext; - class D3D11BufferStorage { - - public: - - private: - - }; - - class D3D11Buffer : public D3D11DeviceChild { static constexpr VkDeviceSize BufferSliceAlignment = 64; public: @@ -46,24 +37,38 @@ namespace dxvk { void STDMETHODCALLTYPE GetDesc( D3D11_BUFFER_DESC *pDesc) final; + /** + * \brief Retrieves current buffer slice + * + * When the buffer gets renamed, the slice that is + * used for rendering and copy operations changes. + * May only be called from the immediate context. + * \returns Current buffer slice + */ + DxvkBufferSlice GetBufferSlice() const; + + /** + * \brief Maps buffer + * + * Must only be called from the immediate context. + * \param [in] pContext The immediate context + * \param [in] MapType Map type + * \param [in] MapFlags Map flags + * \param [out] pMappedSubresource Map pointer + * \return \c S_OK on success + */ HRESULT Map( D3D11DeviceContext* pContext, D3D11_MAP MapType, UINT MapFlags, D3D11_MAPPED_SUBRESOURCE* pMappedSubresource); - void Unmap( - D3D11DeviceContext* pContext); - - DxvkBufferSlice GetCurrentBufferSlice() const; - DxvkBufferSlice GetInitialBufferSlice() const; - private: - const Com m_device; - const D3D11_BUFFER_DESC m_desc; + const Com m_device; + const D3D11_BUFFER_DESC m_desc; - Rc m_buffer; + Rc m_buffer; Rc CreateBuffer( const D3D11_BUFFER_DESC* pDesc) const; diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index 6d551b8b..15ff2bd7 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -8,7 +8,7 @@ namespace dxvk { D3D11DeviceContext::D3D11DeviceContext( - ID3D11Device* parent, + D3D11Device* parent, Rc device) : m_parent(parent), m_device(device) { @@ -190,15 +190,7 @@ namespace dxvk { void STDMETHODCALLTYPE D3D11DeviceContext::Unmap( ID3D11Resource* pResource, UINT Subresource) { - D3D11_RESOURCE_DIMENSION resourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN; - pResource->GetType(&resourceDim); - - if (resourceDim == D3D11_RESOURCE_DIMENSION_BUFFER) { - D3D11Buffer* resource = static_cast(pResource); - return resource->Unmap(this); - } else { - // We already displayed an error on Map() - } + // Nothing to do here, resources are persistently mapped } @@ -396,7 +388,7 @@ namespace dxvk { if (resourceType == D3D11_RESOURCE_DIMENSION_BUFFER) { const auto bufferResource = static_cast(pDstResource); - const auto bufferSlice = bufferResource->GetCurrentBufferSlice(); + const auto bufferSlice = bufferResource->GetBufferSlice(); VkDeviceSize offset = 0; VkDeviceSize size = bufferSlice.length(); @@ -621,33 +613,37 @@ namespace dxvk { // TODO check if any of these buffers // are bound as UAVs or stream outputs for (uint32_t i = 0; i < NumBuffers; i++) { - D3D11VertexBufferBinding binding; - binding.buffer = nullptr; - binding.offset = 0; - binding.stride = 0; - m_state.ia.vertexBuffers.at(StartSlot + i) = binding; + const D3D11VertexBufferBinding oldSlice + = m_state.ia.vertexBuffers.at(StartSlot + i); + + D3D11VertexBufferBinding newSlice; + newSlice.buffer = nullptr; + newSlice.offset = 0; + newSlice.stride = 0; if (ppVertexBuffers != nullptr) { - binding.buffer = static_cast(ppVertexBuffers[i]); - binding.offset = pOffsets[i]; - binding.stride = pStrides[i]; + newSlice.buffer = static_cast(ppVertexBuffers[i]); + newSlice.offset = pOffsets[i]; + newSlice.stride = pStrides[i]; } + m_state.ia.vertexBuffers.at(StartSlot + i) = newSlice; + DxvkBufferSlice bufferSlice; - if (binding.buffer != nullptr) { + if (newSlice.buffer != nullptr) { const DxvkBufferSlice baseSlice = - binding.buffer->GetCurrentBufferSlice(); + newSlice.buffer->GetBufferSlice(); bufferSlice = DxvkBufferSlice( baseSlice.buffer(), - baseSlice.offset() + binding.offset, - baseSlice.length() - binding.offset); + baseSlice.offset() + newSlice.offset, + baseSlice.length() - newSlice.offset); } m_context->bindVertexBuffer( StartSlot + i, bufferSlice, - binding.stride); + newSlice.stride); } } @@ -666,7 +662,7 @@ namespace dxvk { if (binding.buffer != nullptr) { const DxvkBufferSlice baseSlice = - binding.buffer->GetCurrentBufferSlice(); + binding.buffer->GetBufferSlice(); bufferSlice = DxvkBufferSlice( baseSlice.buffer(), @@ -1198,7 +1194,6 @@ namespace dxvk { m_state.om.depthStencilView = static_cast(pDepthStencilView); - // TODO unbind overlapping shader resource views Rc framebuffer = nullptr; @@ -1461,19 +1456,19 @@ namespace dxvk { UINT NumBuffers, ID3D11Buffer* const* ppConstantBuffers) { for (uint32_t i = 0; i < NumBuffers; i++) { - D3D11Buffer* buffer = nullptr; + D3D11Buffer* oldBuffer = pBindings->at(StartSlot + i).ptr(); + D3D11Buffer* newBuffer = nullptr; if (ppConstantBuffers != nullptr) - buffer = static_cast(ppConstantBuffers[i]); + newBuffer = static_cast(ppConstantBuffers[i]); - if (pBindings->at(StartSlot + i) != buffer) { - pBindings->at(StartSlot + i) = buffer; + if (oldBuffer != newBuffer) { + pBindings->at(StartSlot + i) = newBuffer; - // Figure out which part of the buffer to bind DxvkBufferSlice bufferSlice; - if (buffer != nullptr) - bufferSlice = buffer->GetCurrentBufferSlice(); + if (newBuffer != nullptr) + bufferSlice = newBuffer->GetBufferSlice(); // Bind buffer to the DXVK resource slot const VkPipelineBindPoint bindPoint diff --git a/src/d3d11/d3d11_context.h b/src/d3d11/d3d11_context.h index d31121fd..ef2fcadc 100644 --- a/src/d3d11/d3d11_context.h +++ b/src/d3d11/d3d11_context.h @@ -16,7 +16,7 @@ namespace dxvk { public: D3D11DeviceContext( - ID3D11Device* parent, + D3D11Device* parent, Rc device); ~D3D11DeviceContext(); @@ -549,7 +549,7 @@ namespace dxvk { private: - ID3D11Device* const m_parent; + D3D11Device* const m_parent; const D3D11_DEVICE_CONTEXT_TYPE m_type = D3D11_DEVICE_CONTEXT_IMMEDIATE; const UINT m_flags = 0; @@ -561,7 +561,7 @@ namespace dxvk { Com m_defaultDepthStencilState; Com m_defaultRasterizerState; - D3D11ContextState m_state; + D3D11ContextState m_state; void BindConstantBuffers( DxbcProgramType ShaderStage, diff --git a/src/d3d11/d3d11_device.cpp b/src/d3d11/d3d11_device.cpp index 49cc8629..4259e40b 100644 --- a/src/d3d11/d3d11_device.cpp +++ b/src/d3d11/d3d11_device.cpp @@ -1148,7 +1148,7 @@ namespace dxvk { D3D11Buffer* pBuffer, const D3D11_SUBRESOURCE_DATA* pInitialData) { const DxvkBufferSlice bufferSlice - = pBuffer->GetCurrentBufferSlice(); + = pBuffer->GetBufferSlice(); if (pInitialData != nullptr) { std::lock_guard lock(m_resourceInitMutex);; diff --git a/src/d3d11/d3d11_util.h b/src/d3d11/d3d11_util.h index deea098d..ef22e202 100644 --- a/src/d3d11/d3d11_util.h +++ b/src/d3d11/d3d11_util.h @@ -1,6 +1,8 @@ #pragma once -#include +#include "../dxvk/dxvk_device.h" + +#include "../dxbc/dxbc_util.h" #include "d3d11_include.h" diff --git a/src/dxvk/dxvk_buffer.h b/src/dxvk/dxvk_buffer.h index 9c477cb6..403a5fd1 100644 --- a/src/dxvk/dxvk_buffer.h +++ b/src/dxvk/dxvk_buffer.h @@ -194,6 +194,10 @@ namespace dxvk { return m_length; } + void* mapPtr(VkDeviceSize offset) const { + return m_buffer->mapPtr(m_offset + offset); + } + VkDescriptorBufferInfo descriptorInfo() const { VkDescriptorBufferInfo info; info.buffer = m_buffer->handle();