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)
|
||||
return;
|
||||
|
||||
auto counterSlice = uav->GetCounterSlice();
|
||||
if (!counterSlice.defined())
|
||||
auto counterView = uav->GetCounterView();
|
||||
|
||||
if (counterView == nullptr)
|
||||
return;
|
||||
|
||||
EmitCs([
|
||||
cDstSlice = buf->GetBufferSlice(DstAlignedByteOffset),
|
||||
cSrcSlice = std::move(counterSlice)
|
||||
cSrcSlice = counterView->slice()
|
||||
] (DxvkContext* ctx) {
|
||||
ctx->copyBuffer(
|
||||
cDstSlice.buffer(),
|
||||
@ -3702,25 +3703,27 @@ namespace dxvk {
|
||||
cUavSlotId = UavSlot,
|
||||
cCtrSlotId = CtrSlot,
|
||||
cBufferView = pUav->GetBufferView(),
|
||||
cCounterSlice = pUav->GetCounterSlice(),
|
||||
cCounterView = pUav->GetCounterView(),
|
||||
cCounterValue = Counter
|
||||
] (DxvkContext* ctx) mutable {
|
||||
VkShaderStageFlags stages = ShaderStage == DxbcProgramType::ComputeShader
|
||||
? VK_SHADER_STAGE_COMPUTE_BIT
|
||||
: VK_SHADER_STAGE_ALL_GRAPHICS;
|
||||
|
||||
if (cCounterSlice.defined() && cCounterValue != ~0u) {
|
||||
if (cCounterView != nullptr && cCounterValue != ~0u) {
|
||||
auto counterSlice = cCounterView->slice();
|
||||
|
||||
ctx->updateBuffer(
|
||||
cCounterSlice.buffer(),
|
||||
cCounterSlice.offset(),
|
||||
counterSlice.buffer(),
|
||||
counterSlice.offset(),
|
||||
sizeof(uint32_t),
|
||||
&cCounterValue);
|
||||
}
|
||||
|
||||
ctx->bindResourceBufferView(stages, cUavSlotId,
|
||||
Forwarder::move(cBufferView));
|
||||
ctx->bindResourceBuffer(stages, cCtrSlotId,
|
||||
Forwarder::move(cCounterSlice));
|
||||
ctx->bindResourceBufferView(stages, cCtrSlotId,
|
||||
Forwarder::move(cCounterView));
|
||||
});
|
||||
} else {
|
||||
EmitCs([
|
||||
@ -3734,7 +3737,7 @@ namespace dxvk {
|
||||
|
||||
ctx->bindResourceImageView(stages, cUavSlotId,
|
||||
Forwarder::move(cImageView));
|
||||
ctx->bindResourceBuffer(stages, cCtrSlotId, DxvkBufferSlice());
|
||||
ctx->bindResourceBufferView(stages, cCtrSlotId, nullptr);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
@ -3747,7 +3750,7 @@ namespace dxvk {
|
||||
: VK_SHADER_STAGE_ALL_GRAPHICS;
|
||||
|
||||
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++) {
|
||||
ctx->bindResourceImageView(stages, uavSlotId, nullptr);
|
||||
ctx->bindResourceBuffer(stages, ctrSlotId, DxvkBufferSlice());
|
||||
ctx->bindResourceBufferView(stages, ctrSlotId, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -54,18 +54,21 @@ namespace dxvk {
|
||||
|
||||
void D3D11Initializer::InitUavCounter(
|
||||
D3D11UnorderedAccessView* pUav) {
|
||||
auto counterBuffer = pUav->GetCounterSlice();
|
||||
auto counterView = pUav->GetCounterView();
|
||||
|
||||
if (!counterBuffer.defined())
|
||||
if (counterView == nullptr)
|
||||
return;
|
||||
|
||||
auto counterSlice = counterView->slice();
|
||||
|
||||
std::lock_guard<dxvk::mutex> lock(m_mutex);
|
||||
m_transferCommands += 1;
|
||||
|
||||
const uint32_t zero = 0;
|
||||
m_context->updateBuffer(
|
||||
counterBuffer.buffer(),
|
||||
0, sizeof(zero), &zero);
|
||||
counterSlice.buffer(),
|
||||
counterSlice.offset(),
|
||||
sizeof(zero), &zero);
|
||||
|
||||
FlushImplicit();
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ namespace dxvk {
|
||||
}
|
||||
|
||||
if (pDesc->Buffer.Flags & (D3D11_BUFFER_UAV_FLAG_APPEND | D3D11_BUFFER_UAV_FLAG_COUNTER))
|
||||
m_counterBuffer = CreateCounterBuffer();
|
||||
m_counterView = CreateCounterBufferView();
|
||||
|
||||
// Populate view info struct
|
||||
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();
|
||||
|
||||
DxvkBufferCreateInfo info;
|
||||
@ -443,7 +443,15 @@ namespace dxvk {
|
||||
| VK_ACCESS_TRANSFER_READ_BIT
|
||||
| VK_ACCESS_SHADER_WRITE_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;
|
||||
}
|
||||
|
||||
DxvkBufferSlice GetCounterSlice() const {
|
||||
return m_counterBuffer != nullptr
|
||||
? DxvkBufferSlice(m_counterBuffer)
|
||||
: DxvkBufferSlice();
|
||||
Rc<DxvkBufferView> GetCounterView() const {
|
||||
return m_counterView;
|
||||
}
|
||||
|
||||
static HRESULT GetDescFromResource(
|
||||
@ -85,9 +83,9 @@ namespace dxvk {
|
||||
D3D11_VK_VIEW_INFO m_info;
|
||||
Rc<DxvkBufferView> m_bufferView;
|
||||
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