mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-05 01:24:14 +01:00
[d3d11] Bind UAV counter buffers as views
This commit is contained in:
parent
82f500250f
commit
6f194b0e7b
@ -329,13 +329,14 @@ namespace dxvk {
|
|||||||
if (!buf || !uav)
|
if (!buf || !uav)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto counterSlice = uav->GetCounterSlice();
|
auto counterView = uav->GetCounterView();
|
||||||
if (!counterSlice.defined())
|
|
||||||
|
if (counterView == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
EmitCs([
|
EmitCs([
|
||||||
cDstSlice = buf->GetBufferSlice(DstAlignedByteOffset),
|
cDstSlice = buf->GetBufferSlice(DstAlignedByteOffset),
|
||||||
cSrcSlice = std::move(counterSlice)
|
cSrcSlice = counterView->slice()
|
||||||
] (DxvkContext* ctx) {
|
] (DxvkContext* ctx) {
|
||||||
ctx->copyBuffer(
|
ctx->copyBuffer(
|
||||||
cDstSlice.buffer(),
|
cDstSlice.buffer(),
|
||||||
@ -3702,25 +3703,27 @@ namespace dxvk {
|
|||||||
cUavSlotId = UavSlot,
|
cUavSlotId = UavSlot,
|
||||||
cCtrSlotId = CtrSlot,
|
cCtrSlotId = CtrSlot,
|
||||||
cBufferView = pUav->GetBufferView(),
|
cBufferView = pUav->GetBufferView(),
|
||||||
cCounterSlice = pUav->GetCounterSlice(),
|
cCounterView = pUav->GetCounterView(),
|
||||||
cCounterValue = Counter
|
cCounterValue = Counter
|
||||||
] (DxvkContext* ctx) mutable {
|
] (DxvkContext* ctx) mutable {
|
||||||
VkShaderStageFlags stages = ShaderStage == DxbcProgramType::ComputeShader
|
VkShaderStageFlags stages = ShaderStage == DxbcProgramType::ComputeShader
|
||||||
? VK_SHADER_STAGE_COMPUTE_BIT
|
? VK_SHADER_STAGE_COMPUTE_BIT
|
||||||
: VK_SHADER_STAGE_ALL_GRAPHICS;
|
: VK_SHADER_STAGE_ALL_GRAPHICS;
|
||||||
|
|
||||||
if (cCounterSlice.defined() && cCounterValue != ~0u) {
|
if (cCounterView != nullptr && cCounterValue != ~0u) {
|
||||||
|
auto counterSlice = cCounterView->slice();
|
||||||
|
|
||||||
ctx->updateBuffer(
|
ctx->updateBuffer(
|
||||||
cCounterSlice.buffer(),
|
counterSlice.buffer(),
|
||||||
cCounterSlice.offset(),
|
counterSlice.offset(),
|
||||||
sizeof(uint32_t),
|
sizeof(uint32_t),
|
||||||
&cCounterValue);
|
&cCounterValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->bindResourceBufferView(stages, cUavSlotId,
|
ctx->bindResourceBufferView(stages, cUavSlotId,
|
||||||
Forwarder::move(cBufferView));
|
Forwarder::move(cBufferView));
|
||||||
ctx->bindResourceBuffer(stages, cCtrSlotId,
|
ctx->bindResourceBufferView(stages, cCtrSlotId,
|
||||||
Forwarder::move(cCounterSlice));
|
Forwarder::move(cCounterView));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
EmitCs([
|
EmitCs([
|
||||||
@ -3734,7 +3737,7 @@ namespace dxvk {
|
|||||||
|
|
||||||
ctx->bindResourceImageView(stages, cUavSlotId,
|
ctx->bindResourceImageView(stages, cUavSlotId,
|
||||||
Forwarder::move(cImageView));
|
Forwarder::move(cImageView));
|
||||||
ctx->bindResourceBuffer(stages, cCtrSlotId, DxvkBufferSlice());
|
ctx->bindResourceBufferView(stages, cCtrSlotId, nullptr);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -3747,7 +3750,7 @@ namespace dxvk {
|
|||||||
: VK_SHADER_STAGE_ALL_GRAPHICS;
|
: VK_SHADER_STAGE_ALL_GRAPHICS;
|
||||||
|
|
||||||
ctx->bindResourceImageView(stages, cUavSlotId, nullptr);
|
ctx->bindResourceImageView(stages, cUavSlotId, nullptr);
|
||||||
ctx->bindResourceBuffer(stages, cCtrSlotId, DxvkBufferSlice());
|
ctx->bindResourceBufferView(stages, cCtrSlotId, nullptr);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4416,7 +4419,7 @@ namespace dxvk {
|
|||||||
|
|
||||||
for (uint32_t j = 0; j < cUsedBindings.stages[i].uavCount; j++) {
|
for (uint32_t j = 0; j < cUsedBindings.stages[i].uavCount; j++) {
|
||||||
ctx->bindResourceImageView(stages, uavSlotId, nullptr);
|
ctx->bindResourceImageView(stages, uavSlotId, nullptr);
|
||||||
ctx->bindResourceBuffer(stages, ctrSlotId, DxvkBufferSlice());
|
ctx->bindResourceBufferView(stages, ctrSlotId, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,18 +54,21 @@ namespace dxvk {
|
|||||||
|
|
||||||
void D3D11Initializer::InitUavCounter(
|
void D3D11Initializer::InitUavCounter(
|
||||||
D3D11UnorderedAccessView* pUav) {
|
D3D11UnorderedAccessView* pUav) {
|
||||||
auto counterBuffer = pUav->GetCounterSlice();
|
auto counterView = pUav->GetCounterView();
|
||||||
|
|
||||||
if (!counterBuffer.defined())
|
if (counterView == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
auto counterSlice = counterView->slice();
|
||||||
|
|
||||||
std::lock_guard<dxvk::mutex> lock(m_mutex);
|
std::lock_guard<dxvk::mutex> lock(m_mutex);
|
||||||
m_transferCommands += 1;
|
m_transferCommands += 1;
|
||||||
|
|
||||||
const uint32_t zero = 0;
|
const uint32_t zero = 0;
|
||||||
m_context->updateBuffer(
|
m_context->updateBuffer(
|
||||||
counterBuffer.buffer(),
|
counterSlice.buffer(),
|
||||||
0, sizeof(zero), &zero);
|
counterSlice.offset(),
|
||||||
|
sizeof(zero), &zero);
|
||||||
|
|
||||||
FlushImplicit();
|
FlushImplicit();
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ namespace dxvk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pDesc->Buffer.Flags & (D3D11_BUFFER_UAV_FLAG_APPEND | D3D11_BUFFER_UAV_FLAG_COUNTER))
|
if (pDesc->Buffer.Flags & (D3D11_BUFFER_UAV_FLAG_APPEND | D3D11_BUFFER_UAV_FLAG_COUNTER))
|
||||||
m_counterBuffer = CreateCounterBuffer();
|
m_counterView = CreateCounterBufferView();
|
||||||
|
|
||||||
// Populate view info struct
|
// Populate view info struct
|
||||||
m_info.Buffer.Offset = viewInfo.rangeOffset;
|
m_info.Buffer.Offset = viewInfo.rangeOffset;
|
||||||
@ -429,7 +429,7 @@ namespace dxvk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Rc<DxvkBuffer> D3D11UnorderedAccessView::CreateCounterBuffer() {
|
Rc<DxvkBufferView> D3D11UnorderedAccessView::CreateCounterBufferView() {
|
||||||
Rc<DxvkDevice> device = m_parent->GetDXVKDevice();
|
Rc<DxvkDevice> device = m_parent->GetDXVKDevice();
|
||||||
|
|
||||||
DxvkBufferCreateInfo info;
|
DxvkBufferCreateInfo info;
|
||||||
@ -443,7 +443,15 @@ namespace dxvk {
|
|||||||
| VK_ACCESS_TRANSFER_READ_BIT
|
| VK_ACCESS_TRANSFER_READ_BIT
|
||||||
| VK_ACCESS_SHADER_WRITE_BIT
|
| VK_ACCESS_SHADER_WRITE_BIT
|
||||||
| VK_ACCESS_SHADER_READ_BIT;
|
| VK_ACCESS_SHADER_READ_BIT;
|
||||||
return device->createBuffer(info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
|
||||||
|
Rc<DxvkBuffer> buffer = device->createBuffer(info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
||||||
|
|
||||||
|
DxvkBufferViewCreateInfo viewInfo;
|
||||||
|
viewInfo.format = VK_FORMAT_UNDEFINED;
|
||||||
|
viewInfo.rangeOffset = 0;
|
||||||
|
viewInfo.rangeLength = sizeof(uint32_t);
|
||||||
|
|
||||||
|
return device->createBufferView(buffer, viewInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -57,10 +57,8 @@ namespace dxvk {
|
|||||||
return m_imageView;
|
return m_imageView;
|
||||||
}
|
}
|
||||||
|
|
||||||
DxvkBufferSlice GetCounterSlice() const {
|
Rc<DxvkBufferView> GetCounterView() const {
|
||||||
return m_counterBuffer != nullptr
|
return m_counterView;
|
||||||
? DxvkBufferSlice(m_counterBuffer)
|
|
||||||
: DxvkBufferSlice();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT GetDescFromResource(
|
static HRESULT GetDescFromResource(
|
||||||
@ -85,9 +83,9 @@ namespace dxvk {
|
|||||||
D3D11_VK_VIEW_INFO m_info;
|
D3D11_VK_VIEW_INFO m_info;
|
||||||
Rc<DxvkBufferView> m_bufferView;
|
Rc<DxvkBufferView> m_bufferView;
|
||||||
Rc<DxvkImageView> m_imageView;
|
Rc<DxvkImageView> m_imageView;
|
||||||
Rc<DxvkBuffer> m_counterBuffer;
|
Rc<DxvkBufferView> m_counterView;
|
||||||
|
|
||||||
Rc<DxvkBuffer> CreateCounterBuffer();
|
Rc<DxvkBufferView> CreateCounterBufferView();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user