mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-02-21 22:54:16 +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(
|
HRESULT D3D11Buffer::Map(
|
||||||
D3D11DeviceContext* pContext,
|
D3D11DeviceContext* pContext,
|
||||||
D3D11_MAP MapType,
|
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(
|
Rc<DxvkBuffer> D3D11Buffer::CreateBuffer(
|
||||||
const D3D11_BUFFER_DESC* pDesc) const {
|
const D3D11_BUFFER_DESC* pDesc) const {
|
||||||
// Gather usage information
|
// Gather usage information
|
||||||
|
@ -11,15 +11,6 @@ namespace dxvk {
|
|||||||
class D3D11DeviceContext;
|
class D3D11DeviceContext;
|
||||||
|
|
||||||
|
|
||||||
class D3D11BufferStorage {
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class D3D11Buffer : public D3D11DeviceChild<ID3D11Buffer> {
|
class D3D11Buffer : public D3D11DeviceChild<ID3D11Buffer> {
|
||||||
static constexpr VkDeviceSize BufferSliceAlignment = 64;
|
static constexpr VkDeviceSize BufferSliceAlignment = 64;
|
||||||
public:
|
public:
|
||||||
@ -46,24 +37,38 @@ namespace dxvk {
|
|||||||
void STDMETHODCALLTYPE GetDesc(
|
void STDMETHODCALLTYPE GetDesc(
|
||||||
D3D11_BUFFER_DESC *pDesc) final;
|
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(
|
HRESULT Map(
|
||||||
D3D11DeviceContext* pContext,
|
D3D11DeviceContext* pContext,
|
||||||
D3D11_MAP MapType,
|
D3D11_MAP MapType,
|
||||||
UINT MapFlags,
|
UINT MapFlags,
|
||||||
D3D11_MAPPED_SUBRESOURCE* pMappedSubresource);
|
D3D11_MAPPED_SUBRESOURCE* pMappedSubresource);
|
||||||
|
|
||||||
void Unmap(
|
|
||||||
D3D11DeviceContext* pContext);
|
|
||||||
|
|
||||||
DxvkBufferSlice GetCurrentBufferSlice() const;
|
|
||||||
DxvkBufferSlice GetInitialBufferSlice() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
const Com<D3D11Device> m_device;
|
const Com<D3D11Device> m_device;
|
||||||
const D3D11_BUFFER_DESC m_desc;
|
const D3D11_BUFFER_DESC m_desc;
|
||||||
|
|
||||||
Rc<DxvkBuffer> m_buffer;
|
Rc<DxvkBuffer> m_buffer;
|
||||||
|
|
||||||
Rc<DxvkBuffer> CreateBuffer(
|
Rc<DxvkBuffer> CreateBuffer(
|
||||||
const D3D11_BUFFER_DESC* pDesc) const;
|
const D3D11_BUFFER_DESC* pDesc) const;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
namespace dxvk {
|
namespace dxvk {
|
||||||
|
|
||||||
D3D11DeviceContext::D3D11DeviceContext(
|
D3D11DeviceContext::D3D11DeviceContext(
|
||||||
ID3D11Device* parent,
|
D3D11Device* parent,
|
||||||
Rc<DxvkDevice> device)
|
Rc<DxvkDevice> device)
|
||||||
: m_parent(parent),
|
: m_parent(parent),
|
||||||
m_device(device) {
|
m_device(device) {
|
||||||
@ -190,15 +190,7 @@ namespace dxvk {
|
|||||||
void STDMETHODCALLTYPE D3D11DeviceContext::Unmap(
|
void STDMETHODCALLTYPE D3D11DeviceContext::Unmap(
|
||||||
ID3D11Resource* pResource,
|
ID3D11Resource* pResource,
|
||||||
UINT Subresource) {
|
UINT Subresource) {
|
||||||
D3D11_RESOURCE_DIMENSION resourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;
|
// Nothing to do here, resources are persistently mapped
|
||||||
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()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -396,7 +388,7 @@ namespace dxvk {
|
|||||||
|
|
||||||
if (resourceType == D3D11_RESOURCE_DIMENSION_BUFFER) {
|
if (resourceType == D3D11_RESOURCE_DIMENSION_BUFFER) {
|
||||||
const auto bufferResource = static_cast<D3D11Buffer*>(pDstResource);
|
const auto bufferResource = static_cast<D3D11Buffer*>(pDstResource);
|
||||||
const auto bufferSlice = bufferResource->GetCurrentBufferSlice();
|
const auto bufferSlice = bufferResource->GetBufferSlice();
|
||||||
|
|
||||||
VkDeviceSize offset = 0;
|
VkDeviceSize offset = 0;
|
||||||
VkDeviceSize size = bufferSlice.length();
|
VkDeviceSize size = bufferSlice.length();
|
||||||
@ -621,33 +613,37 @@ namespace dxvk {
|
|||||||
// TODO check if any of these buffers
|
// TODO check if any of these buffers
|
||||||
// are bound as UAVs or stream outputs
|
// are bound as UAVs or stream outputs
|
||||||
for (uint32_t i = 0; i < NumBuffers; i++) {
|
for (uint32_t i = 0; i < NumBuffers; i++) {
|
||||||
D3D11VertexBufferBinding binding;
|
const D3D11VertexBufferBinding oldSlice
|
||||||
binding.buffer = nullptr;
|
= m_state.ia.vertexBuffers.at(StartSlot + i);
|
||||||
binding.offset = 0;
|
|
||||||
binding.stride = 0;
|
D3D11VertexBufferBinding newSlice;
|
||||||
m_state.ia.vertexBuffers.at(StartSlot + i) = binding;
|
newSlice.buffer = nullptr;
|
||||||
|
newSlice.offset = 0;
|
||||||
|
newSlice.stride = 0;
|
||||||
|
|
||||||
if (ppVertexBuffers != nullptr) {
|
if (ppVertexBuffers != nullptr) {
|
||||||
binding.buffer = static_cast<D3D11Buffer*>(ppVertexBuffers[i]);
|
newSlice.buffer = static_cast<D3D11Buffer*>(ppVertexBuffers[i]);
|
||||||
binding.offset = pOffsets[i];
|
newSlice.offset = pOffsets[i];
|
||||||
binding.stride = pStrides[i];
|
newSlice.stride = pStrides[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_state.ia.vertexBuffers.at(StartSlot + i) = newSlice;
|
||||||
|
|
||||||
DxvkBufferSlice bufferSlice;
|
DxvkBufferSlice bufferSlice;
|
||||||
|
|
||||||
if (binding.buffer != nullptr) {
|
if (newSlice.buffer != nullptr) {
|
||||||
const DxvkBufferSlice baseSlice =
|
const DxvkBufferSlice baseSlice =
|
||||||
binding.buffer->GetCurrentBufferSlice();
|
newSlice.buffer->GetBufferSlice();
|
||||||
|
|
||||||
bufferSlice = DxvkBufferSlice(
|
bufferSlice = DxvkBufferSlice(
|
||||||
baseSlice.buffer(),
|
baseSlice.buffer(),
|
||||||
baseSlice.offset() + binding.offset,
|
baseSlice.offset() + newSlice.offset,
|
||||||
baseSlice.length() - binding.offset);
|
baseSlice.length() - newSlice.offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_context->bindVertexBuffer(
|
m_context->bindVertexBuffer(
|
||||||
StartSlot + i, bufferSlice,
|
StartSlot + i, bufferSlice,
|
||||||
binding.stride);
|
newSlice.stride);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -666,7 +662,7 @@ namespace dxvk {
|
|||||||
|
|
||||||
if (binding.buffer != nullptr) {
|
if (binding.buffer != nullptr) {
|
||||||
const DxvkBufferSlice baseSlice =
|
const DxvkBufferSlice baseSlice =
|
||||||
binding.buffer->GetCurrentBufferSlice();
|
binding.buffer->GetBufferSlice();
|
||||||
|
|
||||||
bufferSlice = DxvkBufferSlice(
|
bufferSlice = DxvkBufferSlice(
|
||||||
baseSlice.buffer(),
|
baseSlice.buffer(),
|
||||||
@ -1198,7 +1194,6 @@ namespace dxvk {
|
|||||||
|
|
||||||
m_state.om.depthStencilView = static_cast<D3D11DepthStencilView*>(pDepthStencilView);
|
m_state.om.depthStencilView = static_cast<D3D11DepthStencilView*>(pDepthStencilView);
|
||||||
|
|
||||||
|
|
||||||
// TODO unbind overlapping shader resource views
|
// TODO unbind overlapping shader resource views
|
||||||
|
|
||||||
Rc<DxvkFramebuffer> framebuffer = nullptr;
|
Rc<DxvkFramebuffer> framebuffer = nullptr;
|
||||||
@ -1461,19 +1456,19 @@ namespace dxvk {
|
|||||||
UINT NumBuffers,
|
UINT NumBuffers,
|
||||||
ID3D11Buffer* const* ppConstantBuffers) {
|
ID3D11Buffer* const* ppConstantBuffers) {
|
||||||
for (uint32_t i = 0; i < NumBuffers; i++) {
|
for (uint32_t i = 0; i < NumBuffers; i++) {
|
||||||
D3D11Buffer* buffer = nullptr;
|
D3D11Buffer* oldBuffer = pBindings->at(StartSlot + i).ptr();
|
||||||
|
D3D11Buffer* newBuffer = nullptr;
|
||||||
|
|
||||||
if (ppConstantBuffers != nullptr)
|
if (ppConstantBuffers != nullptr)
|
||||||
buffer = static_cast<D3D11Buffer*>(ppConstantBuffers[i]);
|
newBuffer = static_cast<D3D11Buffer*>(ppConstantBuffers[i]);
|
||||||
|
|
||||||
if (pBindings->at(StartSlot + i) != buffer) {
|
if (oldBuffer != newBuffer) {
|
||||||
pBindings->at(StartSlot + i) = buffer;
|
pBindings->at(StartSlot + i) = newBuffer;
|
||||||
|
|
||||||
// Figure out which part of the buffer to bind
|
|
||||||
DxvkBufferSlice bufferSlice;
|
DxvkBufferSlice bufferSlice;
|
||||||
|
|
||||||
if (buffer != nullptr)
|
if (newBuffer != nullptr)
|
||||||
bufferSlice = buffer->GetCurrentBufferSlice();
|
bufferSlice = newBuffer->GetBufferSlice();
|
||||||
|
|
||||||
// Bind buffer to the DXVK resource slot
|
// Bind buffer to the DXVK resource slot
|
||||||
const VkPipelineBindPoint bindPoint
|
const VkPipelineBindPoint bindPoint
|
||||||
|
@ -16,7 +16,7 @@ namespace dxvk {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
D3D11DeviceContext(
|
D3D11DeviceContext(
|
||||||
ID3D11Device* parent,
|
D3D11Device* parent,
|
||||||
Rc<DxvkDevice> device);
|
Rc<DxvkDevice> device);
|
||||||
~D3D11DeviceContext();
|
~D3D11DeviceContext();
|
||||||
|
|
||||||
@ -549,7 +549,7 @@ namespace dxvk {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
ID3D11Device* const m_parent;
|
D3D11Device* const m_parent;
|
||||||
|
|
||||||
const D3D11_DEVICE_CONTEXT_TYPE m_type = D3D11_DEVICE_CONTEXT_IMMEDIATE;
|
const D3D11_DEVICE_CONTEXT_TYPE m_type = D3D11_DEVICE_CONTEXT_IMMEDIATE;
|
||||||
const UINT m_flags = 0;
|
const UINT m_flags = 0;
|
||||||
@ -561,7 +561,7 @@ namespace dxvk {
|
|||||||
Com<D3D11DepthStencilState> m_defaultDepthStencilState;
|
Com<D3D11DepthStencilState> m_defaultDepthStencilState;
|
||||||
Com<D3D11RasterizerState> m_defaultRasterizerState;
|
Com<D3D11RasterizerState> m_defaultRasterizerState;
|
||||||
|
|
||||||
D3D11ContextState m_state;
|
D3D11ContextState m_state;
|
||||||
|
|
||||||
void BindConstantBuffers(
|
void BindConstantBuffers(
|
||||||
DxbcProgramType ShaderStage,
|
DxbcProgramType ShaderStage,
|
||||||
|
@ -1148,7 +1148,7 @@ namespace dxvk {
|
|||||||
D3D11Buffer* pBuffer,
|
D3D11Buffer* pBuffer,
|
||||||
const D3D11_SUBRESOURCE_DATA* pInitialData) {
|
const D3D11_SUBRESOURCE_DATA* pInitialData) {
|
||||||
const DxvkBufferSlice bufferSlice
|
const DxvkBufferSlice bufferSlice
|
||||||
= pBuffer->GetCurrentBufferSlice();
|
= pBuffer->GetBufferSlice();
|
||||||
|
|
||||||
if (pInitialData != nullptr) {
|
if (pInitialData != nullptr) {
|
||||||
std::lock_guard<std::mutex> lock(m_resourceInitMutex);;
|
std::lock_guard<std::mutex> lock(m_resourceInitMutex);;
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <dxvk_device.h>
|
#include "../dxvk/dxvk_device.h"
|
||||||
|
|
||||||
|
#include "../dxbc/dxbc_util.h"
|
||||||
|
|
||||||
#include "d3d11_include.h"
|
#include "d3d11_include.h"
|
||||||
|
|
||||||
|
@ -194,6 +194,10 @@ namespace dxvk {
|
|||||||
return m_length;
|
return m_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* mapPtr(VkDeviceSize offset) const {
|
||||||
|
return m_buffer->mapPtr(m_offset + offset);
|
||||||
|
}
|
||||||
|
|
||||||
VkDescriptorBufferInfo descriptorInfo() const {
|
VkDescriptorBufferInfo descriptorInfo() const {
|
||||||
VkDescriptorBufferInfo info;
|
VkDescriptorBufferInfo info;
|
||||||
info.buffer = m_buffer->handle();
|
info.buffer = m_buffer->handle();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user