mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-02-20 19:54:19 +01:00
[d3d11] Minor restructuring
This commit is contained in:
parent
c0a963ae5b
commit
d9f38a7f42
@ -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<DxvkBuffer> D3D11Buffer::CreateBuffer(
|
||||
const D3D11_BUFFER_DESC* pDesc) const {
|
||||
// Gather usage information
|
||||
|
@ -11,15 +11,6 @@ namespace dxvk {
|
||||
class D3D11DeviceContext;
|
||||
|
||||
|
||||
class D3D11BufferStorage {
|
||||
|
||||
public:
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
class D3D11Buffer : public D3D11DeviceChild<ID3D11Buffer> {
|
||||
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<D3D11Device> m_device;
|
||||
const D3D11_BUFFER_DESC m_desc;
|
||||
const Com<D3D11Device> m_device;
|
||||
const D3D11_BUFFER_DESC m_desc;
|
||||
|
||||
Rc<DxvkBuffer> m_buffer;
|
||||
Rc<DxvkBuffer> m_buffer;
|
||||
|
||||
Rc<DxvkBuffer> CreateBuffer(
|
||||
const D3D11_BUFFER_DESC* pDesc) const;
|
||||
|
@ -8,7 +8,7 @@
|
||||
namespace dxvk {
|
||||
|
||||
D3D11DeviceContext::D3D11DeviceContext(
|
||||
ID3D11Device* parent,
|
||||
D3D11Device* parent,
|
||||
Rc<DxvkDevice> 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<D3D11Buffer*>(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<D3D11Buffer*>(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<D3D11Buffer*>(ppVertexBuffers[i]);
|
||||
binding.offset = pOffsets[i];
|
||||
binding.stride = pStrides[i];
|
||||
newSlice.buffer = static_cast<D3D11Buffer*>(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<D3D11DepthStencilView*>(pDepthStencilView);
|
||||
|
||||
|
||||
// TODO unbind overlapping shader resource views
|
||||
|
||||
Rc<DxvkFramebuffer> 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<D3D11Buffer*>(ppConstantBuffers[i]);
|
||||
newBuffer = static_cast<D3D11Buffer*>(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
|
||||
|
@ -16,7 +16,7 @@ namespace dxvk {
|
||||
public:
|
||||
|
||||
D3D11DeviceContext(
|
||||
ID3D11Device* parent,
|
||||
D3D11Device* parent,
|
||||
Rc<DxvkDevice> 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<D3D11DepthStencilState> m_defaultDepthStencilState;
|
||||
Com<D3D11RasterizerState> m_defaultRasterizerState;
|
||||
|
||||
D3D11ContextState m_state;
|
||||
D3D11ContextState m_state;
|
||||
|
||||
void BindConstantBuffers(
|
||||
DxbcProgramType ShaderStage,
|
||||
|
@ -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<std::mutex> lock(m_resourceInitMutex);;
|
||||
|
@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <dxvk_device.h>
|
||||
#include "../dxvk/dxvk_device.h"
|
||||
|
||||
#include "../dxbc/dxbc_util.h"
|
||||
|
||||
#include "d3d11_include.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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user