2017-12-10 15:57:51 +01:00
|
|
|
#include <cstring>
|
|
|
|
|
2017-10-14 23:52:47 +02:00
|
|
|
#include "dxvk_device.h"
|
2017-10-10 23:32:13 +02:00
|
|
|
#include "dxvk_context.h"
|
|
|
|
#include "dxvk_main.h"
|
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
2018-03-29 12:32:20 +02:00
|
|
|
DxvkContext::DxvkContext(
|
2018-05-25 17:45:41 +02:00
|
|
|
const Rc<DxvkDevice>& device,
|
|
|
|
const Rc<DxvkPipelineManager>& pipelineManager,
|
|
|
|
const Rc<DxvkMetaClearObjects>& metaClearObjects,
|
2018-06-23 13:07:11 +02:00
|
|
|
const Rc<DxvkMetaMipGenObjects>& metaMipGenObjects,
|
|
|
|
const Rc<DxvkMetaResolveObjects>& metaResolveObjects)
|
|
|
|
: m_device (device),
|
|
|
|
m_pipeMgr (pipelineManager),
|
|
|
|
m_metaClear (metaClearObjects),
|
|
|
|
m_metaMipGen (metaMipGenObjects),
|
2018-08-31 15:34:53 +02:00
|
|
|
m_metaResolve (metaResolveObjects),
|
|
|
|
m_queries (device->vkd()) { }
|
2017-10-10 23:32:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
DxvkContext::~DxvkContext() {
|
2017-11-26 14:01:41 +01:00
|
|
|
|
2017-10-10 23:32:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-01 09:50:47 +01:00
|
|
|
void DxvkContext::beginRecording(const Rc<DxvkCommandList>& cmdList) {
|
|
|
|
m_cmd = cmdList;
|
2017-10-14 14:28:31 +02:00
|
|
|
m_cmd->beginRecording();
|
2017-10-13 03:19:23 +02:00
|
|
|
|
2017-11-17 19:49:44 +01:00
|
|
|
// The current state of the internal command buffer is
|
|
|
|
// undefined, so we have to bind and set up everything
|
|
|
|
// before any draw or dispatch command is recorded.
|
2017-12-01 10:27:33 +01:00
|
|
|
m_flags.clr(
|
2018-04-30 17:04:13 +02:00
|
|
|
DxvkContextFlag::GpRenderPassBound,
|
|
|
|
DxvkContextFlag::GpClearRenderTargets);
|
2017-10-13 03:19:23 +02:00
|
|
|
|
2017-12-01 10:27:33 +01:00
|
|
|
m_flags.set(
|
2017-11-17 19:49:44 +01:00
|
|
|
DxvkContextFlag::GpDirtyPipeline,
|
2017-12-09 14:41:37 +01:00
|
|
|
DxvkContextFlag::GpDirtyPipelineState,
|
2017-11-17 19:49:44 +01:00
|
|
|
DxvkContextFlag::GpDirtyResources,
|
|
|
|
DxvkContextFlag::GpDirtyVertexBuffers,
|
2018-01-12 12:51:39 +01:00
|
|
|
DxvkContextFlag::GpDirtyIndexBuffer,
|
2017-11-17 19:49:44 +01:00
|
|
|
DxvkContextFlag::CpDirtyPipeline,
|
2018-01-12 12:51:39 +01:00
|
|
|
DxvkContextFlag::CpDirtyPipelineState,
|
2017-11-17 19:49:44 +01:00
|
|
|
DxvkContextFlag::CpDirtyResources);
|
2017-10-10 23:32:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-01 10:08:49 +01:00
|
|
|
Rc<DxvkCommandList> DxvkContext::endRecording() {
|
2018-04-23 11:11:40 +02:00
|
|
|
this->spillRenderPass();
|
2017-10-11 23:29:05 +02:00
|
|
|
|
2018-08-31 15:34:53 +02:00
|
|
|
m_queries.trackQueryPools(m_cmd);
|
|
|
|
|
2018-06-16 11:53:06 +02:00
|
|
|
m_barriers.recordCommands(m_cmd);
|
|
|
|
|
2017-10-14 14:28:31 +02:00
|
|
|
m_cmd->endRecording();
|
2017-12-01 10:08:49 +01:00
|
|
|
return std::exchange(m_cmd, nullptr);
|
2017-10-10 23:32:13 +02:00
|
|
|
}
|
2017-10-11 23:29:05 +02:00
|
|
|
|
|
|
|
|
2018-02-13 13:43:27 +01:00
|
|
|
void DxvkContext::beginQuery(const DxvkQueryRevision& query) {
|
2018-05-12 19:46:08 +02:00
|
|
|
query.query->beginRecording(query.revision);
|
2018-08-31 15:34:53 +02:00
|
|
|
m_queries.enableQuery(m_cmd, query);
|
2018-02-12 16:36:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-13 13:43:27 +01:00
|
|
|
void DxvkContext::endQuery(const DxvkQueryRevision& query) {
|
2018-08-31 15:34:53 +02:00
|
|
|
m_queries.disableQuery(m_cmd, query);
|
2018-02-13 13:43:27 +01:00
|
|
|
query.query->endRecording(query.revision);
|
2018-02-12 16:36:42 +01:00
|
|
|
}
|
|
|
|
|
2018-04-15 01:09:53 +02:00
|
|
|
|
2018-06-15 20:49:24 +02:00
|
|
|
void DxvkContext::bindRenderTargets(
|
|
|
|
const DxvkRenderTargets& targets,
|
|
|
|
bool spill) {
|
2018-04-26 18:43:19 +02:00
|
|
|
m_state.om.renderTargets = targets;
|
|
|
|
|
2018-04-30 17:04:13 +02:00
|
|
|
// If necessary, perform clears on the active render targets
|
|
|
|
if (m_flags.test(DxvkContextFlag::GpClearRenderTargets))
|
|
|
|
this->startRenderPass();
|
2018-04-30 13:12:28 +02:00
|
|
|
|
|
|
|
// Set up default render pass ops
|
|
|
|
this->resetRenderPassOps(
|
|
|
|
m_state.om.renderTargets,
|
|
|
|
m_state.om.renderPassOps);
|
|
|
|
|
|
|
|
if (m_state.om.framebuffer == nullptr || !m_state.om.framebuffer->hasTargets(targets)) {
|
2018-04-26 18:43:19 +02:00
|
|
|
// Create a new framebuffer object next
|
|
|
|
// time we start rendering something
|
2018-04-26 14:47:55 +02:00
|
|
|
m_flags.set(DxvkContextFlag::GpDirtyFramebuffer);
|
2018-04-26 15:30:18 +02:00
|
|
|
} else {
|
|
|
|
// Don't redundantly spill the render pass if
|
|
|
|
// the same render targets are bound again
|
|
|
|
m_flags.clr(DxvkContextFlag::GpDirtyFramebuffer);
|
2017-10-15 17:56:06 +02:00
|
|
|
}
|
2018-06-15 20:49:24 +02:00
|
|
|
|
|
|
|
if (spill)
|
|
|
|
this->spillRenderPass();
|
2017-10-15 17:56:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-20 13:21:27 +01:00
|
|
|
void DxvkContext::bindIndexBuffer(
|
2017-12-14 15:24:43 +01:00
|
|
|
const DxvkBufferSlice& buffer,
|
2017-12-07 14:01:17 +01:00
|
|
|
VkIndexType indexType) {
|
2018-01-18 18:50:44 +01:00
|
|
|
if (!m_state.vi.indexBuffer.matches(buffer)
|
|
|
|
|| (m_state.vi.indexType != indexType)) {
|
2017-11-20 13:21:27 +01:00
|
|
|
m_state.vi.indexBuffer = buffer;
|
2017-12-07 14:01:17 +01:00
|
|
|
m_state.vi.indexType = indexType;
|
|
|
|
|
2017-12-01 10:27:33 +01:00
|
|
|
m_flags.set(DxvkContextFlag::GpDirtyIndexBuffer);
|
2017-11-20 13:21:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-03 20:23:26 +01:00
|
|
|
void DxvkContext::bindResourceBuffer(
|
|
|
|
uint32_t slot,
|
2017-12-14 15:24:43 +01:00
|
|
|
const DxvkBufferSlice& buffer) {
|
2018-01-18 18:50:44 +01:00
|
|
|
if (!m_rc[slot].bufferSlice.matches(buffer)) {
|
2018-02-05 08:58:15 +01:00
|
|
|
m_rc[slot].sampler = nullptr;
|
|
|
|
m_rc[slot].imageView = nullptr;
|
|
|
|
m_rc[slot].bufferView = nullptr;
|
2017-12-20 12:13:08 +01:00
|
|
|
m_rc[slot].bufferSlice = buffer;
|
2017-12-23 15:11:23 +01:00
|
|
|
|
|
|
|
m_flags.set(
|
|
|
|
DxvkContextFlag::CpDirtyResources,
|
|
|
|
DxvkContextFlag::GpDirtyResources);
|
2017-12-03 20:23:26 +01:00
|
|
|
}
|
2017-12-03 00:40:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-10 11:16:52 +01:00
|
|
|
void DxvkContext::bindResourceView(
|
2017-12-03 20:23:26 +01:00
|
|
|
uint32_t slot,
|
2018-03-10 11:16:52 +01:00
|
|
|
const Rc<DxvkImageView>& imageView,
|
2017-12-03 20:23:26 +01:00
|
|
|
const Rc<DxvkBufferView>& bufferView) {
|
2018-03-10 11:16:52 +01:00
|
|
|
if (m_rc[slot].imageView != imageView
|
|
|
|
|| m_rc[slot].bufferView != bufferView) {
|
2018-02-05 08:58:15 +01:00
|
|
|
m_rc[slot].sampler = nullptr;
|
2018-03-10 11:16:52 +01:00
|
|
|
m_rc[slot].imageView = imageView;
|
2018-02-05 08:58:15 +01:00
|
|
|
m_rc[slot].bufferView = bufferView;
|
|
|
|
m_rc[slot].bufferSlice = DxvkBufferSlice();
|
2017-12-23 15:11:23 +01:00
|
|
|
|
|
|
|
m_flags.set(
|
|
|
|
DxvkContextFlag::CpDirtyResources,
|
|
|
|
DxvkContextFlag::GpDirtyResources);
|
2017-12-03 20:23:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DxvkContext::bindResourceSampler(
|
|
|
|
uint32_t slot,
|
|
|
|
const Rc<DxvkSampler>& sampler) {
|
2017-12-20 12:13:08 +01:00
|
|
|
if (m_rc[slot].sampler != sampler) {
|
2018-02-05 08:58:15 +01:00
|
|
|
m_rc[slot].sampler = sampler;
|
|
|
|
m_rc[slot].imageView = nullptr;
|
|
|
|
m_rc[slot].bufferView = nullptr;
|
|
|
|
m_rc[slot].bufferSlice = DxvkBufferSlice();
|
2017-12-23 15:11:23 +01:00
|
|
|
|
|
|
|
m_flags.set(
|
|
|
|
DxvkContextFlag::CpDirtyResources,
|
|
|
|
DxvkContextFlag::GpDirtyResources);
|
2017-12-03 20:23:26 +01:00
|
|
|
}
|
2017-10-15 17:56:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-07 09:38:31 +01:00
|
|
|
void DxvkContext::bindShader(
|
|
|
|
VkShaderStageFlagBits stage,
|
|
|
|
const Rc<DxvkShader>& shader) {
|
|
|
|
DxvkShaderStage* shaderStage = nullptr;
|
|
|
|
|
|
|
|
switch (stage) {
|
|
|
|
case VK_SHADER_STAGE_VERTEX_BIT: shaderStage = &m_state.gp.vs; break;
|
|
|
|
case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT: shaderStage = &m_state.gp.tcs; break;
|
|
|
|
case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT: shaderStage = &m_state.gp.tes; break;
|
|
|
|
case VK_SHADER_STAGE_GEOMETRY_BIT: shaderStage = &m_state.gp.gs; break;
|
|
|
|
case VK_SHADER_STAGE_FRAGMENT_BIT: shaderStage = &m_state.gp.fs; break;
|
|
|
|
case VK_SHADER_STAGE_COMPUTE_BIT: shaderStage = &m_state.cp.cs; break;
|
|
|
|
default: return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shaderStage->shader != shader) {
|
|
|
|
shaderStage->shader = shader;
|
|
|
|
|
2017-12-18 16:16:21 +01:00
|
|
|
if (stage == VK_SHADER_STAGE_COMPUTE_BIT) {
|
|
|
|
m_flags.set(
|
|
|
|
DxvkContextFlag::CpDirtyPipeline,
|
2018-01-10 12:13:46 +01:00
|
|
|
DxvkContextFlag::CpDirtyPipelineState,
|
2017-12-18 16:16:21 +01:00
|
|
|
DxvkContextFlag::CpDirtyResources);
|
|
|
|
} else {
|
|
|
|
m_flags.set(
|
|
|
|
DxvkContextFlag::GpDirtyPipeline,
|
2018-01-10 12:13:46 +01:00
|
|
|
DxvkContextFlag::GpDirtyPipelineState,
|
2017-12-18 16:16:21 +01:00
|
|
|
DxvkContextFlag::GpDirtyResources);
|
|
|
|
}
|
2017-12-07 09:38:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-20 13:21:27 +01:00
|
|
|
void DxvkContext::bindVertexBuffer(
|
|
|
|
uint32_t binding,
|
2017-12-14 15:24:43 +01:00
|
|
|
const DxvkBufferSlice& buffer,
|
2017-12-07 21:47:38 +01:00
|
|
|
uint32_t stride) {
|
2018-01-18 18:50:44 +01:00
|
|
|
if (!m_state.vi.vertexBuffers[binding].matches(buffer)) {
|
2017-12-20 12:13:08 +01:00
|
|
|
m_state.vi.vertexBuffers[binding] = buffer;
|
2017-12-01 10:27:33 +01:00
|
|
|
m_flags.set(DxvkContextFlag::GpDirtyVertexBuffers);
|
2017-11-20 13:21:27 +01:00
|
|
|
}
|
2017-12-07 21:47:38 +01:00
|
|
|
|
2017-12-20 12:13:08 +01:00
|
|
|
if (m_state.vi.vertexStrides[binding] != stride) {
|
|
|
|
m_state.vi.vertexStrides[binding] = stride;
|
2017-12-07 21:47:38 +01:00
|
|
|
m_flags.set(DxvkContextFlag::GpDirtyPipelineState);
|
|
|
|
}
|
2017-11-20 13:21:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-01 14:26:38 +01:00
|
|
|
void DxvkContext::clearBuffer(
|
|
|
|
const Rc<DxvkBuffer>& buffer,
|
|
|
|
VkDeviceSize offset,
|
|
|
|
VkDeviceSize length,
|
|
|
|
uint32_t value) {
|
2018-04-23 11:11:40 +02:00
|
|
|
this->spillRenderPass();
|
2018-02-01 14:26:38 +01:00
|
|
|
|
2018-05-25 21:02:15 +02:00
|
|
|
if (length == buffer->info().size)
|
|
|
|
length = align(length, 4);
|
|
|
|
|
2018-02-01 14:26:38 +01:00
|
|
|
auto slice = buffer->subSlice(offset, length);
|
2018-06-16 11:53:06 +02:00
|
|
|
|
|
|
|
if (m_barriers.isBufferDirty(slice, DxvkAccess::Write))
|
|
|
|
m_barriers.recordCommands(m_cmd);
|
2018-02-01 14:26:38 +01:00
|
|
|
|
|
|
|
m_cmd->cmdFillBuffer(
|
|
|
|
slice.handle(),
|
|
|
|
slice.offset(),
|
|
|
|
slice.length(),
|
|
|
|
value);
|
|
|
|
|
|
|
|
m_barriers.accessBuffer(slice,
|
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_WRITE_BIT,
|
|
|
|
buffer->info().stages,
|
|
|
|
buffer->info().access);
|
|
|
|
|
|
|
|
m_cmd->trackResource(slice.resource());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-11 17:05:12 +02:00
|
|
|
void DxvkContext::clearBufferView(
|
|
|
|
const Rc<DxvkBufferView>& bufferView,
|
|
|
|
VkDeviceSize offset,
|
|
|
|
VkDeviceSize length,
|
|
|
|
VkClearColorValue value) {
|
2018-04-23 11:11:40 +02:00
|
|
|
this->spillRenderPass();
|
2018-04-11 23:13:34 +02:00
|
|
|
this->unbindComputePipeline();
|
2018-06-16 11:53:06 +02:00
|
|
|
|
|
|
|
auto bufferSlice = bufferView->physicalSlice();
|
|
|
|
|
|
|
|
if (m_barriers.isBufferDirty(bufferSlice, DxvkAccess::Write))
|
|
|
|
m_barriers.recordCommands(m_cmd);
|
2018-04-11 23:13:34 +02:00
|
|
|
|
|
|
|
// Query pipeline objects to use for this clear operation
|
|
|
|
DxvkMetaClearPipeline pipeInfo = m_metaClear->getClearBufferPipeline(
|
|
|
|
imageFormatInfo(bufferView->info().format)->flags);
|
|
|
|
|
|
|
|
// Create a descriptor set pointing to the view
|
|
|
|
VkBufferView viewObject = bufferView->handle();
|
|
|
|
|
|
|
|
VkDescriptorSet descriptorSet =
|
|
|
|
m_cmd->allocateDescriptorSet(pipeInfo.dsetLayout);
|
|
|
|
|
|
|
|
VkWriteDescriptorSet descriptorWrite;
|
|
|
|
descriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
|
|
|
descriptorWrite.pNext = nullptr;
|
|
|
|
descriptorWrite.dstSet = descriptorSet;
|
|
|
|
descriptorWrite.dstBinding = 0;
|
|
|
|
descriptorWrite.dstArrayElement = 0;
|
|
|
|
descriptorWrite.descriptorCount = 1;
|
|
|
|
descriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
|
|
|
|
descriptorWrite.pImageInfo = nullptr;
|
|
|
|
descriptorWrite.pBufferInfo = nullptr;
|
|
|
|
descriptorWrite.pTexelBufferView = &viewObject;
|
|
|
|
m_cmd->updateDescriptorSets(1, &descriptorWrite);
|
|
|
|
|
|
|
|
// Prepare shader arguments
|
|
|
|
DxvkMetaClearArgs pushArgs;
|
|
|
|
pushArgs.clearValue = value;
|
|
|
|
pushArgs.offset = VkOffset3D { int32_t(offset), 0, 0 };
|
|
|
|
pushArgs.extent = VkExtent3D { uint32_t(length), 1, 1 };
|
|
|
|
|
|
|
|
VkExtent3D workgroups = util::computeBlockCount(
|
|
|
|
pushArgs.extent, pipeInfo.workgroupSize);
|
|
|
|
|
|
|
|
m_cmd->cmdBindPipeline(
|
|
|
|
VK_PIPELINE_BIND_POINT_COMPUTE,
|
|
|
|
pipeInfo.pipeline);
|
|
|
|
m_cmd->cmdBindDescriptorSet(
|
|
|
|
VK_PIPELINE_BIND_POINT_COMPUTE,
|
2018-06-22 00:33:06 +02:00
|
|
|
pipeInfo.pipeLayout, descriptorSet,
|
|
|
|
0, nullptr);
|
2018-04-11 23:13:34 +02:00
|
|
|
m_cmd->cmdPushConstants(
|
|
|
|
pipeInfo.pipeLayout,
|
|
|
|
VK_SHADER_STAGE_COMPUTE_BIT,
|
|
|
|
0, sizeof(pushArgs), &pushArgs);
|
|
|
|
m_cmd->cmdDispatch(
|
|
|
|
workgroups.width,
|
|
|
|
workgroups.height,
|
|
|
|
workgroups.depth);
|
2018-04-11 17:05:12 +02:00
|
|
|
|
2018-04-11 23:13:34 +02:00
|
|
|
m_barriers.accessBuffer(
|
2018-06-16 11:53:06 +02:00
|
|
|
bufferSlice,
|
2018-04-11 23:13:34 +02:00
|
|
|
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
|
|
|
VK_ACCESS_SHADER_WRITE_BIT,
|
|
|
|
bufferView->bufferInfo().stages,
|
|
|
|
bufferView->bufferInfo().access);
|
|
|
|
|
|
|
|
m_cmd->trackResource(bufferView->viewResource());
|
|
|
|
m_cmd->trackResource(bufferView->bufferResource());
|
2018-04-11 17:05:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-01 00:52:13 +01:00
|
|
|
void DxvkContext::clearColorImage(
|
|
|
|
const Rc<DxvkImage>& image,
|
|
|
|
const VkClearColorValue& value,
|
|
|
|
const VkImageSubresourceRange& subresources) {
|
2018-04-23 11:11:40 +02:00
|
|
|
this->spillRenderPass();
|
2018-06-18 14:35:11 +02:00
|
|
|
|
|
|
|
m_barriers.recordCommands(m_cmd);
|
2017-12-01 00:52:13 +01:00
|
|
|
|
2018-06-28 12:44:57 +02:00
|
|
|
VkImageLayout imageLayoutClear = image->pickLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
|
|
|
|
2018-01-23 19:00:48 +01:00
|
|
|
m_barriers.accessImage(image, subresources,
|
|
|
|
VK_IMAGE_LAYOUT_UNDEFINED,
|
|
|
|
image->info().stages,
|
|
|
|
image->info().access,
|
2018-06-28 12:44:57 +02:00
|
|
|
imageLayoutClear,
|
2018-01-23 19:00:48 +01:00
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_WRITE_BIT);
|
2018-06-18 14:35:11 +02:00
|
|
|
|
2018-01-23 19:00:48 +01:00
|
|
|
m_barriers.recordCommands(m_cmd);
|
2017-12-05 13:00:06 +01:00
|
|
|
|
|
|
|
m_cmd->cmdClearColorImage(image->handle(),
|
2018-06-28 12:44:57 +02:00
|
|
|
imageLayoutClear, &value, 1, &subresources);
|
2017-12-01 00:52:13 +01:00
|
|
|
|
2017-12-05 13:00:06 +01:00
|
|
|
m_barriers.accessImage(image, subresources,
|
2018-06-28 12:44:57 +02:00
|
|
|
imageLayoutClear,
|
2017-12-05 13:00:06 +01:00
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_WRITE_BIT,
|
|
|
|
image->info().layout,
|
|
|
|
image->info().stages,
|
|
|
|
image->info().access);
|
2017-12-01 00:52:13 +01:00
|
|
|
|
|
|
|
m_cmd->trackResource(image);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-09 03:53:42 +01:00
|
|
|
void DxvkContext::clearDepthStencilImage(
|
|
|
|
const Rc<DxvkImage>& image,
|
|
|
|
const VkClearDepthStencilValue& value,
|
|
|
|
const VkImageSubresourceRange& subresources) {
|
2018-04-23 11:11:40 +02:00
|
|
|
this->spillRenderPass();
|
2017-12-09 03:53:42 +01:00
|
|
|
|
2018-06-18 14:35:11 +02:00
|
|
|
m_barriers.recordCommands(m_cmd);
|
|
|
|
|
2018-06-28 12:44:57 +02:00
|
|
|
VkImageLayout imageLayoutInitial = image->info().layout;
|
|
|
|
VkImageLayout imageLayoutClear = image->pickLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
|
|
|
|
|
|
|
if (subresources.aspectMask == image->formatInfo()->aspectMask)
|
|
|
|
imageLayoutInitial = VK_IMAGE_LAYOUT_UNDEFINED;
|
|
|
|
|
2018-01-30 15:44:18 +01:00
|
|
|
m_barriers.accessImage(
|
|
|
|
image, subresources,
|
2018-06-28 12:44:57 +02:00
|
|
|
imageLayoutInitial,
|
2018-01-23 19:00:48 +01:00
|
|
|
image->info().stages,
|
|
|
|
image->info().access,
|
2018-06-28 12:44:57 +02:00
|
|
|
imageLayoutClear,
|
2018-01-23 19:00:48 +01:00
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_WRITE_BIT);
|
2018-06-18 14:35:11 +02:00
|
|
|
|
2018-01-23 19:00:48 +01:00
|
|
|
m_barriers.recordCommands(m_cmd);
|
2017-12-09 03:53:42 +01:00
|
|
|
|
|
|
|
m_cmd->cmdClearDepthStencilImage(image->handle(),
|
2018-06-28 12:44:57 +02:00
|
|
|
imageLayoutClear, &value, 1, &subresources);
|
2017-12-09 03:53:42 +01:00
|
|
|
|
2018-01-30 15:44:18 +01:00
|
|
|
m_barriers.accessImage(
|
|
|
|
image, subresources,
|
2018-06-28 12:44:57 +02:00
|
|
|
imageLayoutClear,
|
2017-12-09 03:53:42 +01:00
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_WRITE_BIT,
|
|
|
|
image->info().layout,
|
|
|
|
image->info().stages,
|
|
|
|
image->info().access);
|
|
|
|
|
|
|
|
m_cmd->trackResource(image);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-11 23:29:05 +02:00
|
|
|
void DxvkContext::clearRenderTarget(
|
2018-03-17 17:59:43 +01:00
|
|
|
const Rc<DxvkImageView>& imageView,
|
|
|
|
VkImageAspectFlags clearAspects,
|
|
|
|
const VkClearValue& clearValue) {
|
2018-09-13 21:39:56 +02:00
|
|
|
this->updateFramebuffer();
|
2018-07-06 15:23:59 +02:00
|
|
|
|
2018-04-30 21:42:16 +02:00
|
|
|
// Prepare attachment ops
|
|
|
|
DxvkColorAttachmentOps colorOp;
|
|
|
|
colorOp.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
|
|
|
|
colorOp.loadLayout = imageView->imageInfo().layout;
|
|
|
|
colorOp.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
|
|
|
colorOp.storeLayout = imageView->imageInfo().layout;
|
|
|
|
|
|
|
|
DxvkDepthAttachmentOps depthOp;
|
|
|
|
depthOp.loadOpD = VK_ATTACHMENT_LOAD_OP_LOAD;
|
|
|
|
depthOp.loadOpS = VK_ATTACHMENT_LOAD_OP_LOAD;
|
|
|
|
depthOp.loadLayout = imageView->imageInfo().layout;
|
|
|
|
depthOp.storeOpD = VK_ATTACHMENT_STORE_OP_STORE;
|
|
|
|
depthOp.storeOpS = VK_ATTACHMENT_STORE_OP_STORE;
|
|
|
|
depthOp.storeLayout = imageView->imageInfo().layout;
|
|
|
|
|
|
|
|
if (clearAspects & VK_IMAGE_ASPECT_COLOR_BIT)
|
|
|
|
colorOp.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
|
|
|
|
|
|
|
if (clearAspects & VK_IMAGE_ASPECT_DEPTH_BIT)
|
|
|
|
depthOp.loadOpD = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
|
|
|
|
|
|
|
if (clearAspects & VK_IMAGE_ASPECT_STENCIL_BIT)
|
|
|
|
depthOp.loadOpS = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
|
|
|
|
|
|
|
if (clearAspects == imageView->info().aspect) {
|
|
|
|
colorOp.loadLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
|
|
|
depthOp.loadLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
2018-03-17 17:59:43 +01:00
|
|
|
// Check whether the render target view is an attachment
|
|
|
|
// of the current framebuffer. If not, we need to create
|
|
|
|
// a temporary framebuffer.
|
2018-04-30 13:12:28 +02:00
|
|
|
int32_t attachmentIndex = -1;
|
2018-03-17 17:59:43 +01:00
|
|
|
|
|
|
|
if (m_state.om.framebuffer != nullptr)
|
|
|
|
attachmentIndex = m_state.om.framebuffer->findAttachment(imageView);
|
|
|
|
|
2018-04-30 13:12:28 +02:00
|
|
|
if (attachmentIndex < 0) {
|
2018-04-23 11:11:40 +02:00
|
|
|
this->spillRenderPass();
|
2018-03-17 17:59:43 +01:00
|
|
|
|
|
|
|
// Set up and bind a temporary framebuffer
|
|
|
|
DxvkRenderTargets attachments;
|
2018-04-30 13:12:28 +02:00
|
|
|
DxvkRenderPassOps ops;
|
2018-03-17 17:59:43 +01:00
|
|
|
|
|
|
|
if (clearAspects & VK_IMAGE_ASPECT_COLOR_BIT) {
|
2018-04-30 13:12:28 +02:00
|
|
|
attachments.color[0].view = imageView;
|
|
|
|
attachments.color[0].layout = imageView->pickLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
|
2018-04-30 21:42:16 +02:00
|
|
|
ops.colorOps[0] = colorOp;
|
2018-03-17 17:59:43 +01:00
|
|
|
} else {
|
2018-04-30 13:12:28 +02:00
|
|
|
attachments.depth.view = imageView;
|
|
|
|
attachments.depth.layout = imageView->pickLayout(VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
2018-04-30 21:42:16 +02:00
|
|
|
ops.depthOps = depthOp;
|
2018-03-17 17:59:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this->renderPassBindFramebuffer(
|
2018-04-30 17:04:13 +02:00
|
|
|
m_device->createFramebuffer(attachments),
|
|
|
|
ops, 1, &clearValue);
|
|
|
|
this->renderPassUnbindFramebuffer();
|
|
|
|
} else if (m_flags.test(DxvkContextFlag::GpRenderPassBound)) {
|
|
|
|
// Clear the attachment in quesion. For color images,
|
|
|
|
// the attachment index for the current subpass is
|
|
|
|
// equal to the render pass attachment index.
|
|
|
|
VkClearAttachment clearInfo;
|
|
|
|
clearInfo.aspectMask = clearAspects;
|
|
|
|
clearInfo.colorAttachment = attachmentIndex;
|
|
|
|
clearInfo.clearValue = clearValue;
|
|
|
|
|
2018-07-06 15:01:37 +02:00
|
|
|
VkClearRect clearRect;
|
|
|
|
clearRect.rect.offset.x = 0;
|
|
|
|
clearRect.rect.offset.y = 0;
|
|
|
|
clearRect.rect.extent.width = imageView->mipLevelExtent(0).width;
|
|
|
|
clearRect.rect.extent.height = imageView->mipLevelExtent(0).height;
|
|
|
|
clearRect.baseArrayLayer = 0;
|
|
|
|
clearRect.layerCount = imageView->info().numLayers;
|
|
|
|
|
2018-07-06 15:23:59 +02:00
|
|
|
m_cmd->cmdClearAttachments(1, &clearInfo, 1, &clearRect);
|
2018-03-17 17:59:43 +01:00
|
|
|
} else {
|
2018-04-30 17:04:13 +02:00
|
|
|
// Perform the clear when starting the render pass
|
2018-07-06 15:23:59 +02:00
|
|
|
if (clearAspects & VK_IMAGE_ASPECT_COLOR_BIT) {
|
2018-04-30 21:42:16 +02:00
|
|
|
m_state.om.renderPassOps.colorOps[attachmentIndex] = colorOp;
|
2018-07-06 15:23:59 +02:00
|
|
|
m_state.om.clearValues[attachmentIndex].color = clearValue.color;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clearAspects & VK_IMAGE_ASPECT_DEPTH_BIT) {
|
|
|
|
m_state.om.renderPassOps.depthOps.loadOpD = depthOp.loadOpD;
|
|
|
|
m_state.om.renderPassOps.depthOps.storeOpD = depthOp.storeOpD;
|
|
|
|
m_state.om.clearValues[attachmentIndex].depthStencil.depth = clearValue.depthStencil.depth;
|
|
|
|
}
|
2018-04-30 21:42:16 +02:00
|
|
|
|
2018-07-06 15:23:59 +02:00
|
|
|
if (clearAspects & VK_IMAGE_ASPECT_STENCIL_BIT) {
|
|
|
|
m_state.om.renderPassOps.depthOps.loadOpS = depthOp.loadOpS;
|
|
|
|
m_state.om.renderPassOps.depthOps.storeOpS = depthOp.storeOpS;
|
|
|
|
m_state.om.clearValues[attachmentIndex].depthStencil.stencil = clearValue.depthStencil.stencil;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clearAspects & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
|
|
|
|
m_state.om.renderPassOps.depthOps.loadLayout = depthOp.loadLayout;
|
|
|
|
m_state.om.renderPassOps.depthOps.storeLayout = depthOp.storeLayout;
|
|
|
|
|
|
|
|
if (m_state.om.renderPassOps.depthOps.loadOpD == VK_ATTACHMENT_LOAD_OP_CLEAR
|
|
|
|
&& m_state.om.renderPassOps.depthOps.loadOpS == VK_ATTACHMENT_LOAD_OP_CLEAR)
|
|
|
|
m_state.om.renderPassOps.depthOps.loadLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
|
|
|
}
|
2018-04-30 17:04:13 +02:00
|
|
|
|
|
|
|
m_flags.set(DxvkContextFlag::GpClearRenderTargets);
|
2018-03-17 17:59:43 +01:00
|
|
|
}
|
2017-10-11 23:29:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-11 17:05:12 +02:00
|
|
|
void DxvkContext::clearImageView(
|
2018-04-11 23:13:34 +02:00
|
|
|
const Rc<DxvkImageView>& imageView,
|
2018-04-11 17:05:12 +02:00
|
|
|
VkOffset3D offset,
|
|
|
|
VkExtent3D extent,
|
2018-08-15 18:06:52 +02:00
|
|
|
VkClearValue value) {
|
2018-08-15 19:00:29 +02:00
|
|
|
const VkImageUsageFlags viewUsage = imageView->info().usage;
|
|
|
|
|
|
|
|
if (viewUsage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT))
|
|
|
|
this->clearImageViewFb(imageView, offset, extent, value);
|
|
|
|
else if (viewUsage & VK_IMAGE_USAGE_STORAGE_BIT)
|
|
|
|
this->clearImageViewCs(imageView, offset, extent, value);
|
2018-04-11 17:05:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-26 13:24:01 +01:00
|
|
|
void DxvkContext::copyBuffer(
|
|
|
|
const Rc<DxvkBuffer>& dstBuffer,
|
|
|
|
VkDeviceSize dstOffset,
|
|
|
|
const Rc<DxvkBuffer>& srcBuffer,
|
|
|
|
VkDeviceSize srcOffset,
|
|
|
|
VkDeviceSize numBytes) {
|
2018-01-20 19:49:41 -08:00
|
|
|
if (numBytes == 0)
|
|
|
|
return;
|
2018-03-17 09:20:06 +01:00
|
|
|
|
2018-04-23 11:11:40 +02:00
|
|
|
this->spillRenderPass();
|
2018-03-17 09:20:06 +01:00
|
|
|
|
2018-01-20 19:49:41 -08:00
|
|
|
auto dstSlice = dstBuffer->subSlice(dstOffset, numBytes);
|
|
|
|
auto srcSlice = srcBuffer->subSlice(srcOffset, numBytes);
|
|
|
|
|
2018-06-16 11:53:06 +02:00
|
|
|
if (m_barriers.isBufferDirty(srcSlice, DxvkAccess::Read)
|
|
|
|
|| m_barriers.isBufferDirty(dstSlice, DxvkAccess::Write))
|
|
|
|
m_barriers.recordCommands(m_cmd);
|
|
|
|
|
2018-01-20 19:49:41 -08:00
|
|
|
VkBufferCopy bufferRegion;
|
|
|
|
bufferRegion.srcOffset = srcSlice.offset();
|
|
|
|
bufferRegion.dstOffset = dstSlice.offset();
|
|
|
|
bufferRegion.size = dstSlice.length();
|
|
|
|
|
|
|
|
m_cmd->cmdCopyBuffer(
|
|
|
|
srcSlice.handle(),
|
|
|
|
dstSlice.handle(),
|
|
|
|
1, &bufferRegion);
|
|
|
|
|
|
|
|
m_barriers.accessBuffer(srcSlice,
|
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_READ_BIT,
|
|
|
|
srcBuffer->info().stages,
|
|
|
|
srcBuffer->info().access);
|
|
|
|
|
|
|
|
m_barriers.accessBuffer(dstSlice,
|
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_WRITE_BIT,
|
|
|
|
dstBuffer->info().stages,
|
|
|
|
dstBuffer->info().access);
|
|
|
|
|
|
|
|
m_cmd->trackResource(dstBuffer->resource());
|
|
|
|
m_cmd->trackResource(srcBuffer->resource());
|
2017-11-26 13:24:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-18 16:20:57 +02:00
|
|
|
void DxvkContext::copyBufferRegion(
|
|
|
|
const Rc<DxvkBuffer>& dstBuffer,
|
|
|
|
VkDeviceSize dstOffset,
|
|
|
|
VkDeviceSize srcOffset,
|
|
|
|
VkDeviceSize numBytes) {
|
|
|
|
VkDeviceSize loOvl = std::max(dstOffset, srcOffset);
|
|
|
|
VkDeviceSize hiOvl = std::min(dstOffset, srcOffset) + numBytes;
|
|
|
|
|
|
|
|
if (hiOvl > loOvl) {
|
|
|
|
DxvkBufferCreateInfo bufInfo;
|
|
|
|
bufInfo.size = numBytes;
|
|
|
|
bufInfo.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT
|
|
|
|
| VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
|
|
|
|
bufInfo.stages = VK_PIPELINE_STAGE_TRANSFER_BIT;
|
|
|
|
bufInfo.access = VK_ACCESS_TRANSFER_WRITE_BIT
|
|
|
|
| VK_ACCESS_TRANSFER_READ_BIT;
|
|
|
|
|
|
|
|
auto tmpBuffer = m_device->createBuffer(
|
|
|
|
bufInfo, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
|
|
|
|
|
|
|
VkDeviceSize tmpOffset = 0;
|
|
|
|
|
|
|
|
this->copyBuffer(tmpBuffer, tmpOffset, dstBuffer, srcOffset, numBytes);
|
|
|
|
this->copyBuffer(dstBuffer, dstOffset, tmpBuffer, tmpOffset, numBytes);
|
|
|
|
} else {
|
|
|
|
this->copyBuffer(dstBuffer, dstOffset, dstBuffer, srcOffset, numBytes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-05 03:01:19 +01:00
|
|
|
void DxvkContext::copyBufferToImage(
|
|
|
|
const Rc<DxvkImage>& dstImage,
|
|
|
|
VkImageSubresourceLayers dstSubresource,
|
|
|
|
VkOffset3D dstOffset,
|
|
|
|
VkExtent3D dstExtent,
|
|
|
|
const Rc<DxvkBuffer>& srcBuffer,
|
|
|
|
VkDeviceSize srcOffset,
|
|
|
|
VkExtent2D srcExtent) {
|
2018-04-23 11:11:40 +02:00
|
|
|
this->spillRenderPass();
|
2018-06-28 12:44:57 +02:00
|
|
|
|
2018-01-18 18:33:13 +01:00
|
|
|
auto srcSlice = srcBuffer->subSlice(srcOffset, 0);
|
2018-06-16 11:53:06 +02:00
|
|
|
|
2018-06-28 12:44:57 +02:00
|
|
|
// We may copy to only one aspect of a depth-stencil image,
|
|
|
|
// but pipeline barriers need to have all aspect bits set
|
|
|
|
auto dstFormatInfo = dstImage->formatInfo();
|
|
|
|
|
2018-01-30 15:44:18 +01:00
|
|
|
VkImageSubresourceRange dstSubresourceRange = {
|
2018-06-28 12:44:57 +02:00
|
|
|
dstFormatInfo->aspectMask,
|
2018-01-05 03:01:19 +01:00
|
|
|
dstSubresource.mipLevel, 1,
|
|
|
|
dstSubresource.baseArrayLayer,
|
|
|
|
dstSubresource.layerCount };
|
|
|
|
|
2018-06-28 13:00:03 +02:00
|
|
|
if (m_barriers.isImageDirty(dstImage, dstSubresourceRange, DxvkAccess::Write)
|
|
|
|
|| m_barriers.isBufferDirty(srcSlice, DxvkAccess::Read))
|
|
|
|
m_barriers.recordCommands(m_cmd);
|
2018-06-18 14:35:11 +02:00
|
|
|
|
2018-06-28 12:44:57 +02:00
|
|
|
// Initialize the image if the entire subresource is covered
|
|
|
|
VkImageLayout dstImageLayoutInitial = dstImage->info().layout;
|
|
|
|
VkImageLayout dstImageLayoutTransfer = dstImage->pickLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
|
|
|
|
|
|
|
if (dstImage->isFullSubresource(dstSubresource, dstExtent))
|
|
|
|
dstImageLayoutInitial = VK_IMAGE_LAYOUT_UNDEFINED;
|
|
|
|
|
2018-06-28 13:00:03 +02:00
|
|
|
m_transitions.accessImage(
|
2018-01-05 03:01:19 +01:00
|
|
|
dstImage, dstSubresourceRange,
|
2018-06-28 13:00:03 +02:00
|
|
|
dstImageLayoutInitial, 0, 0,
|
2018-06-28 12:44:57 +02:00
|
|
|
dstImageLayoutTransfer,
|
2018-01-05 03:01:19 +01:00
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_WRITE_BIT);
|
2018-06-16 11:53:06 +02:00
|
|
|
|
2018-06-28 13:00:03 +02:00
|
|
|
m_transitions.recordCommands(m_cmd);
|
2018-01-05 03:01:19 +01:00
|
|
|
|
|
|
|
VkBufferImageCopy copyRegion;
|
2018-01-18 19:09:21 +01:00
|
|
|
copyRegion.bufferOffset = srcSlice.offset();
|
2018-01-05 03:01:19 +01:00
|
|
|
copyRegion.bufferRowLength = srcExtent.width;
|
|
|
|
copyRegion.bufferImageHeight = srcExtent.height;
|
|
|
|
copyRegion.imageSubresource = dstSubresource;
|
|
|
|
copyRegion.imageOffset = dstOffset;
|
|
|
|
copyRegion.imageExtent = dstExtent;
|
|
|
|
|
|
|
|
m_cmd->cmdCopyBufferToImage(
|
2018-01-18 18:33:13 +01:00
|
|
|
srcSlice.handle(),
|
2018-01-05 03:01:19 +01:00
|
|
|
dstImage->handle(),
|
2018-06-28 12:44:57 +02:00
|
|
|
dstImageLayoutTransfer,
|
2018-01-05 03:01:19 +01:00
|
|
|
1, ©Region);
|
|
|
|
|
|
|
|
m_barriers.accessImage(
|
|
|
|
dstImage, dstSubresourceRange,
|
2018-06-28 12:44:57 +02:00
|
|
|
dstImageLayoutTransfer,
|
2018-01-05 03:01:19 +01:00
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_WRITE_BIT,
|
|
|
|
dstImage->info().layout,
|
|
|
|
dstImage->info().stages,
|
|
|
|
dstImage->info().access);
|
2018-06-16 11:53:06 +02:00
|
|
|
|
2018-01-19 18:09:49 +01:00
|
|
|
m_barriers.accessBuffer(srcSlice,
|
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_READ_BIT,
|
|
|
|
srcBuffer->info().stages,
|
|
|
|
srcBuffer->info().access);
|
2018-01-05 03:01:19 +01:00
|
|
|
|
|
|
|
m_cmd->trackResource(dstImage);
|
2018-01-18 18:33:13 +01:00
|
|
|
m_cmd->trackResource(srcSlice.resource());
|
2018-01-05 03:01:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-30 19:10:45 +01:00
|
|
|
void DxvkContext::copyImage(
|
|
|
|
const Rc<DxvkImage>& dstImage,
|
|
|
|
VkImageSubresourceLayers dstSubresource,
|
|
|
|
VkOffset3D dstOffset,
|
|
|
|
const Rc<DxvkImage>& srcImage,
|
|
|
|
VkImageSubresourceLayers srcSubresource,
|
|
|
|
VkOffset3D srcOffset,
|
|
|
|
VkExtent3D extent) {
|
2018-04-23 11:11:40 +02:00
|
|
|
this->spillRenderPass();
|
2017-12-30 19:10:45 +01:00
|
|
|
|
2018-01-30 15:44:18 +01:00
|
|
|
VkImageSubresourceRange dstSubresourceRange = {
|
2018-01-05 03:01:19 +01:00
|
|
|
dstSubresource.aspectMask,
|
|
|
|
dstSubresource.mipLevel, 1,
|
|
|
|
dstSubresource.baseArrayLayer,
|
|
|
|
dstSubresource.layerCount };
|
2017-12-30 19:10:45 +01:00
|
|
|
|
2018-01-30 15:44:18 +01:00
|
|
|
VkImageSubresourceRange srcSubresourceRange = {
|
2018-01-05 03:01:19 +01:00
|
|
|
srcSubresource.aspectMask,
|
|
|
|
srcSubresource.mipLevel, 1,
|
|
|
|
srcSubresource.baseArrayLayer,
|
|
|
|
srcSubresource.layerCount };
|
2017-12-30 19:10:45 +01:00
|
|
|
|
2018-06-18 22:30:00 +02:00
|
|
|
if (m_barriers.isImageDirty(dstImage, dstSubresourceRange, DxvkAccess::Write)
|
|
|
|
|| m_barriers.isImageDirty(srcImage, srcSubresourceRange, DxvkAccess::Write))
|
|
|
|
m_barriers.recordCommands(m_cmd);
|
2018-06-16 11:53:06 +02:00
|
|
|
|
2018-06-18 22:30:00 +02:00
|
|
|
VkImageLayout dstImageLayout = dstImage->pickLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
|
|
|
VkImageLayout srcImageLayout = srcImage->pickLayout(VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
|
|
|
|
2018-06-28 13:00:03 +02:00
|
|
|
VkImageLayout dstInitImageLayout = dstImage->info().layout;
|
2018-06-18 22:30:00 +02:00
|
|
|
|
2018-06-28 13:00:03 +02:00
|
|
|
if (dstImage->isFullSubresource(dstSubresource, extent))
|
|
|
|
dstInitImageLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
2018-06-18 22:30:00 +02:00
|
|
|
|
2018-06-28 13:00:03 +02:00
|
|
|
m_transitions.accessImage(
|
|
|
|
dstImage, dstSubresourceRange,
|
|
|
|
dstInitImageLayout, 0, 0,
|
|
|
|
dstImageLayout,
|
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_WRITE_BIT);
|
2018-06-18 22:30:00 +02:00
|
|
|
|
2018-06-28 13:00:03 +02:00
|
|
|
m_transitions.accessImage(
|
|
|
|
srcImage, srcSubresourceRange,
|
|
|
|
srcImage->info().layout, 0, 0,
|
|
|
|
srcImageLayout,
|
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_READ_BIT);
|
2018-06-16 11:53:06 +02:00
|
|
|
|
2018-06-28 13:00:03 +02:00
|
|
|
m_transitions.recordCommands(m_cmd);
|
2018-02-20 13:08:50 +01:00
|
|
|
|
|
|
|
if (dstSubresource.aspectMask == srcSubresource.aspectMask) {
|
|
|
|
VkImageCopy imageRegion;
|
|
|
|
imageRegion.srcSubresource = srcSubresource;
|
|
|
|
imageRegion.srcOffset = srcOffset;
|
|
|
|
imageRegion.dstSubresource = dstSubresource;
|
|
|
|
imageRegion.dstOffset = dstOffset;
|
|
|
|
imageRegion.extent = extent;
|
|
|
|
|
|
|
|
m_cmd->cmdCopyImage(
|
2018-06-18 22:30:00 +02:00
|
|
|
srcImage->handle(), srcImageLayout,
|
|
|
|
dstImage->handle(), dstImageLayout,
|
2018-02-20 13:08:50 +01:00
|
|
|
1, &imageRegion);
|
|
|
|
} else {
|
|
|
|
const VkDeviceSize transferBufferSize = std::max(
|
|
|
|
util::computeImageDataSize(dstImage->info().format, extent),
|
|
|
|
util::computeImageDataSize(srcImage->info().format, extent));
|
|
|
|
|
|
|
|
// TODO optimize away buffer creation
|
|
|
|
DxvkBufferCreateInfo tmpBufferInfo;
|
|
|
|
tmpBufferInfo.size = transferBufferSize;
|
|
|
|
tmpBufferInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT
|
|
|
|
| VK_BUFFER_USAGE_TRANSFER_DST_BIT;
|
|
|
|
tmpBufferInfo.stages = VK_PIPELINE_STAGE_TRANSFER_BIT;
|
|
|
|
tmpBufferInfo.access = VK_ACCESS_TRANSFER_READ_BIT
|
|
|
|
| VK_ACCESS_TRANSFER_WRITE_BIT;
|
|
|
|
|
|
|
|
Rc<DxvkBuffer> tmpBuffer = m_device->createBuffer(
|
|
|
|
tmpBufferInfo, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
|
|
|
|
|
|
|
DxvkPhysicalBufferSlice tmpSlice = tmpBuffer->slice();
|
|
|
|
|
|
|
|
VkBufferImageCopy bufferImageCopy;
|
|
|
|
bufferImageCopy.bufferOffset = tmpSlice.offset();
|
|
|
|
bufferImageCopy.bufferRowLength = 0;
|
|
|
|
bufferImageCopy.bufferImageHeight = 0;
|
|
|
|
bufferImageCopy.imageSubresource = srcSubresource;
|
|
|
|
bufferImageCopy.imageOffset = srcOffset;
|
|
|
|
bufferImageCopy.imageExtent = extent;
|
|
|
|
|
|
|
|
m_cmd->cmdCopyImageToBuffer(
|
2018-06-18 22:30:00 +02:00
|
|
|
srcImage->handle(), srcImageLayout,
|
2018-02-20 13:08:50 +01:00
|
|
|
tmpSlice.handle(), 1, &bufferImageCopy);
|
|
|
|
|
|
|
|
m_barriers.accessBuffer(tmpSlice,
|
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_WRITE_BIT,
|
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_READ_BIT);
|
2018-06-16 11:53:06 +02:00
|
|
|
|
2018-02-20 13:08:50 +01:00
|
|
|
m_barriers.recordCommands(m_cmd);
|
|
|
|
|
|
|
|
bufferImageCopy.imageSubresource = dstSubresource;
|
|
|
|
bufferImageCopy.imageOffset = dstOffset;
|
|
|
|
|
2018-06-18 22:30:00 +02:00
|
|
|
m_cmd->cmdCopyBufferToImage(
|
|
|
|
tmpSlice.handle(), dstImage->handle(),
|
|
|
|
dstImageLayout, 1, &bufferImageCopy);
|
2018-02-20 13:08:50 +01:00
|
|
|
|
|
|
|
m_barriers.accessBuffer(tmpSlice,
|
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_READ_BIT,
|
|
|
|
tmpBuffer->info().stages,
|
|
|
|
tmpBuffer->info().access);
|
|
|
|
|
|
|
|
m_cmd->trackResource(tmpSlice.resource());
|
|
|
|
}
|
|
|
|
|
2017-12-30 19:10:45 +01:00
|
|
|
m_barriers.accessImage(
|
|
|
|
dstImage, dstSubresourceRange,
|
2018-06-18 22:30:00 +02:00
|
|
|
dstImageLayout,
|
2017-12-30 19:10:45 +01:00
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_WRITE_BIT,
|
|
|
|
dstImage->info().layout,
|
|
|
|
dstImage->info().stages,
|
|
|
|
dstImage->info().access);
|
2018-06-16 11:53:06 +02:00
|
|
|
|
2017-12-30 19:10:45 +01:00
|
|
|
m_barriers.accessImage(
|
|
|
|
srcImage, srcSubresourceRange,
|
2018-06-18 22:30:00 +02:00
|
|
|
srcImageLayout,
|
2017-12-30 19:10:45 +01:00
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_READ_BIT,
|
|
|
|
srcImage->info().layout,
|
|
|
|
srcImage->info().stages,
|
|
|
|
srcImage->info().access);
|
|
|
|
|
|
|
|
m_cmd->trackResource(dstImage);
|
|
|
|
m_cmd->trackResource(srcImage);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-18 16:20:57 +02:00
|
|
|
void DxvkContext::copyImageRegion(
|
|
|
|
const Rc<DxvkImage>& dstImage,
|
|
|
|
VkImageSubresourceLayers dstSubresource,
|
|
|
|
VkOffset3D dstOffset,
|
|
|
|
VkOffset3D srcOffset,
|
|
|
|
VkExtent3D extent) {
|
|
|
|
VkOffset3D loOvl = {
|
|
|
|
std::max(dstOffset.x, srcOffset.x),
|
|
|
|
std::max(dstOffset.y, srcOffset.y),
|
|
|
|
std::max(dstOffset.z, srcOffset.z) };
|
|
|
|
|
|
|
|
VkOffset3D hiOvl = {
|
|
|
|
std::min(dstOffset.x, srcOffset.x) + int32_t(extent.width),
|
|
|
|
std::min(dstOffset.y, srcOffset.y) + int32_t(extent.height),
|
|
|
|
std::min(dstOffset.z, srcOffset.z) + int32_t(extent.depth) };
|
|
|
|
|
|
|
|
bool overlap = hiOvl.x > loOvl.x
|
|
|
|
&& hiOvl.y > loOvl.y
|
|
|
|
&& hiOvl.z > loOvl.z;
|
|
|
|
|
|
|
|
if (overlap) {
|
|
|
|
DxvkImageCreateInfo imgInfo;
|
|
|
|
imgInfo.type = dstImage->info().type;
|
|
|
|
imgInfo.format = dstImage->info().format;
|
|
|
|
imgInfo.flags = 0;
|
|
|
|
imgInfo.sampleCount = dstImage->info().sampleCount;
|
|
|
|
imgInfo.extent = extent;
|
|
|
|
imgInfo.numLayers = dstSubresource.layerCount;
|
|
|
|
imgInfo.mipLevels = 1;
|
|
|
|
imgInfo.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT
|
|
|
|
| VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
|
|
|
|
imgInfo.stages = VK_PIPELINE_STAGE_TRANSFER_BIT;
|
|
|
|
imgInfo.access = VK_ACCESS_TRANSFER_WRITE_BIT
|
|
|
|
| VK_ACCESS_TRANSFER_READ_BIT;
|
|
|
|
imgInfo.tiling = dstImage->info().tiling;
|
|
|
|
imgInfo.layout = VK_IMAGE_LAYOUT_GENERAL;
|
|
|
|
|
|
|
|
auto tmpImage = m_device->createImage(
|
|
|
|
imgInfo, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
|
|
|
|
|
|
|
VkImageSubresourceLayers tmpSubresource;
|
|
|
|
tmpSubresource.aspectMask = dstSubresource.aspectMask;
|
|
|
|
tmpSubresource.mipLevel = 0;
|
|
|
|
tmpSubresource.baseArrayLayer = 0;
|
|
|
|
tmpSubresource.layerCount = dstSubresource.layerCount;
|
|
|
|
|
|
|
|
VkOffset3D tmpOffset = { 0, 0, 0 };
|
|
|
|
|
|
|
|
this->copyImage(
|
|
|
|
tmpImage, tmpSubresource, tmpOffset,
|
|
|
|
dstImage, dstSubresource, srcOffset,
|
|
|
|
extent);
|
|
|
|
|
|
|
|
this->copyImage(
|
|
|
|
dstImage, dstSubresource, dstOffset,
|
|
|
|
tmpImage, tmpSubresource, tmpOffset,
|
|
|
|
extent);
|
|
|
|
} else {
|
|
|
|
this->copyImage(
|
|
|
|
dstImage, dstSubresource, dstOffset,
|
|
|
|
dstImage, dstSubresource, srcOffset,
|
|
|
|
extent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-19 18:09:49 +01:00
|
|
|
void DxvkContext::copyImageToBuffer(
|
|
|
|
const Rc<DxvkBuffer>& dstBuffer,
|
|
|
|
VkDeviceSize dstOffset,
|
|
|
|
VkExtent2D dstExtent,
|
|
|
|
const Rc<DxvkImage>& srcImage,
|
|
|
|
VkImageSubresourceLayers srcSubresource,
|
|
|
|
VkOffset3D srcOffset,
|
|
|
|
VkExtent3D srcExtent) {
|
2018-04-23 11:11:40 +02:00
|
|
|
this->spillRenderPass();
|
2018-01-19 18:09:49 +01:00
|
|
|
|
|
|
|
auto dstSlice = dstBuffer->subSlice(dstOffset, 0);
|
2018-06-16 11:53:06 +02:00
|
|
|
|
2018-06-28 12:44:57 +02:00
|
|
|
// We may copy to only one aspect of a depth-stencil image,
|
|
|
|
// but pipeline barriers need to have all aspect bits set
|
|
|
|
auto srcFormatInfo = srcImage->formatInfo();
|
|
|
|
|
2018-01-30 15:44:18 +01:00
|
|
|
VkImageSubresourceRange srcSubresourceRange = {
|
2018-06-28 12:44:57 +02:00
|
|
|
srcFormatInfo->aspectMask,
|
2018-01-19 18:09:49 +01:00
|
|
|
srcSubresource.mipLevel, 1,
|
|
|
|
srcSubresource.baseArrayLayer,
|
|
|
|
srcSubresource.layerCount };
|
|
|
|
|
2018-06-28 13:00:03 +02:00
|
|
|
if (m_barriers.isImageDirty(srcImage, srcSubresourceRange, DxvkAccess::Write)
|
|
|
|
|| m_barriers.isBufferDirty(dstSlice, DxvkAccess::Write))
|
|
|
|
m_barriers.recordCommands(m_cmd);
|
2018-06-28 12:44:57 +02:00
|
|
|
|
|
|
|
// Select a suitable image layout for the transfer op
|
|
|
|
VkImageLayout srcImageLayoutTransfer = srcImage->pickLayout(VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
2018-06-18 14:35:11 +02:00
|
|
|
|
2018-06-28 13:00:03 +02:00
|
|
|
m_transitions.accessImage(
|
2018-01-19 18:09:49 +01:00
|
|
|
srcImage, srcSubresourceRange,
|
2018-06-28 13:00:03 +02:00
|
|
|
srcImage->info().layout, 0, 0,
|
2018-06-28 12:44:57 +02:00
|
|
|
srcImageLayoutTransfer,
|
2018-01-19 18:09:49 +01:00
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_READ_BIT);
|
2018-06-18 14:35:11 +02:00
|
|
|
|
2018-06-28 13:00:03 +02:00
|
|
|
m_transitions.recordCommands(m_cmd);
|
2018-01-19 18:09:49 +01:00
|
|
|
|
|
|
|
VkBufferImageCopy copyRegion;
|
|
|
|
copyRegion.bufferOffset = dstSlice.offset();
|
|
|
|
copyRegion.bufferRowLength = dstExtent.width;
|
|
|
|
copyRegion.bufferImageHeight = dstExtent.height;
|
|
|
|
copyRegion.imageSubresource = srcSubresource;
|
|
|
|
copyRegion.imageOffset = srcOffset;
|
|
|
|
copyRegion.imageExtent = srcExtent;
|
|
|
|
|
|
|
|
m_cmd->cmdCopyImageToBuffer(
|
|
|
|
srcImage->handle(),
|
2018-06-28 12:44:57 +02:00
|
|
|
srcImageLayoutTransfer,
|
2018-01-19 18:09:49 +01:00
|
|
|
dstSlice.handle(),
|
|
|
|
1, ©Region);
|
|
|
|
|
|
|
|
m_barriers.accessImage(
|
|
|
|
srcImage, srcSubresourceRange,
|
2018-06-28 12:44:57 +02:00
|
|
|
srcImageLayoutTransfer,
|
2018-01-19 18:09:49 +01:00
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_READ_BIT,
|
|
|
|
srcImage->info().layout,
|
|
|
|
srcImage->info().stages,
|
|
|
|
srcImage->info().access);
|
2018-06-16 11:53:06 +02:00
|
|
|
|
2018-01-19 18:09:49 +01:00
|
|
|
m_barriers.accessBuffer(dstSlice,
|
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_WRITE_BIT,
|
|
|
|
dstBuffer->info().stages,
|
|
|
|
dstBuffer->info().access);
|
|
|
|
|
|
|
|
m_cmd->trackResource(srcImage);
|
|
|
|
m_cmd->trackResource(dstSlice.resource());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-03 11:28:00 +02:00
|
|
|
void DxvkContext::discardBuffer(
|
|
|
|
const Rc<DxvkBuffer>& buffer) {
|
2018-08-27 14:50:47 +02:00
|
|
|
if (m_barriers.isBufferDirty(buffer->slice(), DxvkAccess::Write))
|
2018-08-03 11:28:00 +02:00
|
|
|
this->invalidateBuffer(buffer, buffer->allocPhysicalSlice());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-23 14:24:00 +01:00
|
|
|
void DxvkContext::dispatch(
|
|
|
|
uint32_t x,
|
|
|
|
uint32_t y,
|
|
|
|
uint32_t z) {
|
2017-11-26 14:01:41 +01:00
|
|
|
this->commitComputeState();
|
2017-11-23 14:24:00 +01:00
|
|
|
|
2018-02-24 23:56:12 +01:00
|
|
|
if (this->validateComputeState()) {
|
2018-06-18 14:35:11 +02:00
|
|
|
this->commitComputeInitBarriers();
|
|
|
|
|
2018-08-31 16:24:03 +02:00
|
|
|
m_queries.beginQueries(m_cmd,
|
|
|
|
VK_QUERY_TYPE_PIPELINE_STATISTICS);
|
|
|
|
|
2018-01-25 12:57:43 +01:00
|
|
|
m_cmd->cmdDispatch(x, y, z);
|
|
|
|
|
2018-08-31 16:24:03 +02:00
|
|
|
m_queries.endQueries(m_cmd,
|
|
|
|
VK_QUERY_TYPE_PIPELINE_STATISTICS);
|
|
|
|
|
2018-06-18 14:35:11 +02:00
|
|
|
this->commitComputePostBarriers();
|
2018-01-25 12:57:43 +01:00
|
|
|
}
|
2018-04-03 11:56:12 +02:00
|
|
|
|
|
|
|
m_cmd->addStatCtr(DxvkStatCounter::CmdDispatchCalls, 1);
|
2017-11-23 14:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-31 01:31:08 +01:00
|
|
|
void DxvkContext::dispatchIndirect(
|
|
|
|
const DxvkBufferSlice& buffer) {
|
|
|
|
this->commitComputeState();
|
|
|
|
|
2018-01-18 18:01:47 +01:00
|
|
|
auto physicalSlice = buffer.physicalSlice();
|
2018-06-18 14:35:11 +02:00
|
|
|
|
|
|
|
if (m_barriers.isBufferDirty(buffer.physicalSlice(), DxvkAccess::Read))
|
|
|
|
m_barriers.recordCommands(m_cmd);
|
2018-01-18 18:01:47 +01:00
|
|
|
|
2018-02-24 23:56:12 +01:00
|
|
|
if (this->validateComputeState()) {
|
2018-06-18 14:35:11 +02:00
|
|
|
this->commitComputeInitBarriers();
|
|
|
|
|
2018-08-31 16:24:03 +02:00
|
|
|
m_queries.beginQueries(m_cmd,
|
|
|
|
VK_QUERY_TYPE_PIPELINE_STATISTICS);
|
|
|
|
|
2018-01-25 12:57:43 +01:00
|
|
|
m_cmd->cmdDispatchIndirect(
|
|
|
|
physicalSlice.handle(),
|
|
|
|
physicalSlice.offset());
|
|
|
|
|
2018-08-31 16:24:03 +02:00
|
|
|
m_queries.endQueries(m_cmd,
|
|
|
|
VK_QUERY_TYPE_PIPELINE_STATISTICS);
|
|
|
|
|
2018-06-18 14:35:11 +02:00
|
|
|
this->commitComputePostBarriers();
|
2018-01-25 12:57:43 +01:00
|
|
|
}
|
2018-04-03 11:56:12 +02:00
|
|
|
|
|
|
|
m_cmd->addStatCtr(DxvkStatCounter::CmdDispatchCalls, 1);
|
2017-12-31 01:31:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-11 23:29:05 +02:00
|
|
|
void DxvkContext::draw(
|
|
|
|
uint32_t vertexCount,
|
|
|
|
uint32_t instanceCount,
|
|
|
|
uint32_t firstVertex,
|
|
|
|
uint32_t firstInstance) {
|
2017-11-20 14:11:09 +01:00
|
|
|
this->commitGraphicsState();
|
2017-11-20 15:35:29 +01:00
|
|
|
|
2018-02-24 23:56:12 +01:00
|
|
|
if (this->validateGraphicsState()) {
|
2018-02-03 10:36:17 +01:00
|
|
|
m_cmd->cmdDraw(
|
|
|
|
vertexCount, instanceCount,
|
|
|
|
firstVertex, firstInstance);
|
2018-01-12 14:25:26 +01:00
|
|
|
}
|
2018-04-03 11:56:12 +02:00
|
|
|
|
|
|
|
m_cmd->addStatCtr(DxvkStatCounter::CmdDrawCalls, 1);
|
2017-10-11 23:29:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-31 01:31:08 +01:00
|
|
|
void DxvkContext::drawIndirect(
|
|
|
|
const DxvkBufferSlice& buffer,
|
|
|
|
uint32_t count,
|
|
|
|
uint32_t stride) {
|
|
|
|
this->commitGraphicsState();
|
|
|
|
|
2018-02-24 23:56:12 +01:00
|
|
|
if (this->validateGraphicsState()) {
|
2018-01-18 18:01:47 +01:00
|
|
|
auto physicalSlice = buffer.physicalSlice();
|
|
|
|
|
2018-02-03 10:36:17 +01:00
|
|
|
m_cmd->cmdDrawIndirect(
|
|
|
|
physicalSlice.handle(),
|
|
|
|
physicalSlice.offset(),
|
|
|
|
count, stride);
|
2018-01-12 14:25:26 +01:00
|
|
|
}
|
2018-04-03 11:56:12 +02:00
|
|
|
|
|
|
|
m_cmd->addStatCtr(DxvkStatCounter::CmdDrawCalls, 1);
|
2017-12-31 01:31:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-11 23:29:05 +02:00
|
|
|
void DxvkContext::drawIndexed(
|
|
|
|
uint32_t indexCount,
|
|
|
|
uint32_t instanceCount,
|
|
|
|
uint32_t firstIndex,
|
|
|
|
uint32_t vertexOffset,
|
|
|
|
uint32_t firstInstance) {
|
2017-11-20 14:11:09 +01:00
|
|
|
this->commitGraphicsState();
|
2017-11-20 15:35:29 +01:00
|
|
|
|
2018-02-24 23:56:12 +01:00
|
|
|
if (this->validateGraphicsState()) {
|
2018-01-12 14:25:26 +01:00
|
|
|
m_cmd->cmdDrawIndexed(
|
|
|
|
indexCount, instanceCount,
|
|
|
|
firstIndex, vertexOffset,
|
|
|
|
firstInstance);
|
|
|
|
}
|
2018-04-03 11:56:12 +02:00
|
|
|
|
|
|
|
m_cmd->addStatCtr(DxvkStatCounter::CmdDrawCalls, 1);
|
2017-11-20 15:35:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-31 01:31:08 +01:00
|
|
|
void DxvkContext::drawIndexedIndirect(
|
|
|
|
const DxvkBufferSlice& buffer,
|
|
|
|
uint32_t count,
|
|
|
|
uint32_t stride) {
|
|
|
|
this->commitGraphicsState();
|
|
|
|
|
2018-02-24 23:56:12 +01:00
|
|
|
if (this->validateGraphicsState()) {
|
2018-01-18 18:01:47 +01:00
|
|
|
auto physicalSlice = buffer.physicalSlice();
|
|
|
|
|
2018-01-12 14:25:26 +01:00
|
|
|
m_cmd->cmdDrawIndexedIndirect(
|
2018-01-18 18:01:47 +01:00
|
|
|
physicalSlice.handle(),
|
|
|
|
physicalSlice.offset(),
|
2018-01-12 14:25:26 +01:00
|
|
|
count, stride);
|
|
|
|
}
|
2018-04-03 11:56:12 +02:00
|
|
|
|
|
|
|
m_cmd->addStatCtr(DxvkStatCounter::CmdDrawCalls, 1);
|
2017-12-31 01:31:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-01 17:52:05 +01:00
|
|
|
void DxvkContext::initImage(
|
2017-12-05 13:00:06 +01:00
|
|
|
const Rc<DxvkImage>& image,
|
|
|
|
const VkImageSubresourceRange& subresources) {
|
|
|
|
m_barriers.accessImage(image, subresources,
|
2018-06-28 13:00:03 +02:00
|
|
|
VK_IMAGE_LAYOUT_UNDEFINED, 0, 0,
|
2017-12-05 13:00:06 +01:00
|
|
|
image->info().layout,
|
|
|
|
image->info().stages,
|
|
|
|
image->info().access);
|
2018-03-07 10:37:27 +01:00
|
|
|
|
|
|
|
m_cmd->trackResource(image);
|
2017-12-01 17:52:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-20 09:46:54 +01:00
|
|
|
void DxvkContext::generateMipmaps(
|
2018-05-25 17:45:41 +02:00
|
|
|
const Rc<DxvkImageView>& imageView) {
|
|
|
|
if (imageView->info().numLevels <= 1)
|
2018-01-20 09:46:54 +01:00
|
|
|
return;
|
|
|
|
|
2018-04-23 11:11:40 +02:00
|
|
|
this->spillRenderPass();
|
2018-05-25 17:45:41 +02:00
|
|
|
this->unbindGraphicsPipeline();
|
2018-06-18 14:35:11 +02:00
|
|
|
|
|
|
|
m_barriers.recordCommands(m_cmd);
|
2018-01-20 09:46:54 +01:00
|
|
|
|
2018-05-25 17:45:41 +02:00
|
|
|
// Create the a set of framebuffers and image views
|
|
|
|
const Rc<DxvkMetaMipGenRenderPass> mipGenerator
|
|
|
|
= new DxvkMetaMipGenRenderPass(m_device->vkd(), imageView);
|
2018-01-20 09:46:54 +01:00
|
|
|
|
2018-05-25 17:45:41 +02:00
|
|
|
// Common descriptor set properties that we use to
|
|
|
|
// bind the source image view to the fragment shader
|
|
|
|
VkDescriptorImageInfo descriptorImage;
|
|
|
|
descriptorImage.sampler = VK_NULL_HANDLE;
|
|
|
|
descriptorImage.imageView = VK_NULL_HANDLE;
|
|
|
|
descriptorImage.imageLayout = imageView->imageInfo().layout;
|
|
|
|
|
|
|
|
VkWriteDescriptorSet descriptorWrite;
|
|
|
|
descriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
|
|
|
descriptorWrite.pNext = nullptr;
|
|
|
|
descriptorWrite.dstSet = VK_NULL_HANDLE;
|
|
|
|
descriptorWrite.dstBinding = 0;
|
|
|
|
descriptorWrite.dstArrayElement = 0;
|
|
|
|
descriptorWrite.descriptorCount = 1;
|
|
|
|
descriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
|
|
|
descriptorWrite.pImageInfo = &descriptorImage;
|
|
|
|
descriptorWrite.pBufferInfo = nullptr;
|
|
|
|
descriptorWrite.pTexelBufferView = nullptr;
|
2018-01-20 09:46:54 +01:00
|
|
|
|
2018-05-25 17:45:41 +02:00
|
|
|
// Common render pass info
|
|
|
|
VkRenderPassBeginInfo passInfo;
|
|
|
|
passInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
|
|
|
passInfo.pNext = nullptr;
|
|
|
|
passInfo.renderPass = mipGenerator->renderPass();
|
|
|
|
passInfo.framebuffer = VK_NULL_HANDLE;
|
|
|
|
passInfo.renderArea = VkRect2D { };
|
|
|
|
passInfo.clearValueCount = 0;
|
|
|
|
passInfo.pClearValues = nullptr;
|
|
|
|
|
|
|
|
// Retrieve a compatible pipeline to use for rendering
|
|
|
|
DxvkMetaMipGenPipeline pipeInfo = m_metaMipGen->getPipeline(
|
|
|
|
mipGenerator->viewType(), imageView->info().format);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < mipGenerator->passCount(); i++) {
|
|
|
|
DxvkMetaMipGenPass pass = mipGenerator->pass(i);
|
2018-01-20 09:46:54 +01:00
|
|
|
|
2018-05-25 17:45:41 +02:00
|
|
|
// Width, height and layer count for the current pass
|
|
|
|
VkExtent3D passExtent = mipGenerator->passExtent(i);
|
2018-01-20 09:46:54 +01:00
|
|
|
|
2018-05-25 17:45:41 +02:00
|
|
|
// Create descriptor set with the current source view
|
|
|
|
descriptorImage.imageView = pass.srcView;
|
|
|
|
descriptorWrite.dstSet = m_cmd->allocateDescriptorSet(pipeInfo.dsetLayout);
|
|
|
|
m_cmd->updateDescriptorSets(1, &descriptorWrite);
|
2018-01-20 09:46:54 +01:00
|
|
|
|
2018-05-25 17:45:41 +02:00
|
|
|
// Set up viewport and scissor rect
|
|
|
|
VkViewport viewport;
|
|
|
|
viewport.x = 0.0f;
|
|
|
|
viewport.y = 0.0f;
|
|
|
|
viewport.width = float(passExtent.width);
|
|
|
|
viewport.height = float(passExtent.height);
|
|
|
|
viewport.minDepth = 0.0f;
|
|
|
|
viewport.maxDepth = 1.0f;
|
2018-01-20 09:46:54 +01:00
|
|
|
|
2018-05-25 17:45:41 +02:00
|
|
|
VkRect2D scissor;
|
|
|
|
scissor.offset = { 0, 0 };
|
|
|
|
scissor.extent = { passExtent.width, passExtent.height };
|
2018-01-20 09:46:54 +01:00
|
|
|
|
2018-05-25 17:45:41 +02:00
|
|
|
// Set up render pass info
|
|
|
|
passInfo.framebuffer = pass.framebuffer;
|
|
|
|
passInfo.renderArea = scissor;
|
|
|
|
|
|
|
|
// Set up push constants
|
|
|
|
DxvkMetaMipGenPushConstants pushConstants;
|
|
|
|
pushConstants.layerCount = passExtent.depth;
|
|
|
|
|
|
|
|
m_cmd->cmdBeginRenderPass(&passInfo, VK_SUBPASS_CONTENTS_INLINE);
|
|
|
|
m_cmd->cmdBindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, pipeInfo.pipeHandle);
|
|
|
|
m_cmd->cmdBindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS,
|
2018-06-22 00:33:06 +02:00
|
|
|
pipeInfo.pipeLayout, descriptorWrite.dstSet, 0, nullptr);
|
2018-05-25 17:45:41 +02:00
|
|
|
|
|
|
|
m_cmd->cmdSetViewport(0, 1, &viewport);
|
|
|
|
m_cmd->cmdSetScissor (0, 1, &scissor);
|
|
|
|
|
|
|
|
m_cmd->cmdPushConstants(
|
|
|
|
pipeInfo.pipeLayout,
|
|
|
|
VK_SHADER_STAGE_FRAGMENT_BIT,
|
|
|
|
0, sizeof(pushConstants),
|
|
|
|
&pushConstants);
|
|
|
|
|
|
|
|
m_cmd->cmdDraw(1, passExtent.depth, 0, 0);
|
|
|
|
m_cmd->cmdEndRenderPass();
|
2018-01-20 09:46:54 +01:00
|
|
|
}
|
|
|
|
|
2018-05-25 17:45:41 +02:00
|
|
|
m_cmd->trackResource(mipGenerator);
|
2018-05-25 19:15:14 +02:00
|
|
|
m_cmd->trackResource(imageView->image());
|
2018-01-20 09:46:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-20 21:42:11 +01:00
|
|
|
void DxvkContext::invalidateBuffer(
|
|
|
|
const Rc<DxvkBuffer>& buffer,
|
|
|
|
const DxvkPhysicalBufferSlice& slice) {
|
2017-12-16 13:21:11 +01:00
|
|
|
// Allocate new backing resource
|
2018-03-19 02:18:44 +01:00
|
|
|
DxvkPhysicalBufferSlice prevSlice = buffer->rename(slice);
|
|
|
|
m_cmd->freePhysicalBufferSlice(buffer, prevSlice);
|
2017-12-16 13:21:11 +01:00
|
|
|
|
|
|
|
// We also need to update all bindings that the buffer
|
|
|
|
// may be bound to either directly or through views.
|
|
|
|
const VkBufferUsageFlags usage = buffer->info().usage;
|
|
|
|
|
|
|
|
if (usage & VK_BUFFER_USAGE_INDEX_BUFFER_BIT)
|
|
|
|
m_flags.set(DxvkContextFlag::GpDirtyIndexBuffer);
|
|
|
|
|
|
|
|
if (usage & VK_BUFFER_USAGE_VERTEX_BUFFER_BIT)
|
|
|
|
m_flags.set(DxvkContextFlag::GpDirtyVertexBuffers);
|
|
|
|
|
2018-06-22 00:33:06 +02:00
|
|
|
if (usage & (VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT
|
|
|
|
| VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT)) {
|
2017-12-16 13:21:11 +01:00
|
|
|
m_flags.set(DxvkContextFlag::GpDirtyResources,
|
|
|
|
DxvkContextFlag::CpDirtyResources);
|
2018-06-22 00:33:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (usage & (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
|
|
|
|
| VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
|
|
|
|
if (prevSlice.handle() != slice.handle()) {
|
|
|
|
m_flags.set(DxvkContextFlag::GpDirtyResources,
|
|
|
|
DxvkContextFlag::CpDirtyResources);
|
|
|
|
} else {
|
|
|
|
m_flags.set(DxvkContextFlag::GpDirtyDescriptorOffsets,
|
|
|
|
DxvkContextFlag::CpDirtyDescriptorOffsets);
|
|
|
|
}
|
|
|
|
}
|
2017-12-16 13:21:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 00:27:49 +01:00
|
|
|
void DxvkContext::resolveImage(
|
|
|
|
const Rc<DxvkImage>& dstImage,
|
|
|
|
const VkImageSubresourceLayers& dstSubresources,
|
|
|
|
const Rc<DxvkImage>& srcImage,
|
2018-02-20 22:26:23 +01:00
|
|
|
const VkImageSubresourceLayers& srcSubresources,
|
|
|
|
VkFormat format) {
|
2018-04-23 11:11:40 +02:00
|
|
|
this->spillRenderPass();
|
2018-06-23 13:07:11 +02:00
|
|
|
this->unbindGraphicsPipeline();
|
2018-02-20 22:26:23 +01:00
|
|
|
|
2018-06-18 14:35:11 +02:00
|
|
|
m_barriers.recordCommands(m_cmd);
|
|
|
|
|
2018-02-20 22:26:23 +01:00
|
|
|
if (format == VK_FORMAT_UNDEFINED)
|
|
|
|
format = srcImage->info().format;
|
|
|
|
|
2018-02-21 01:04:28 +01:00
|
|
|
if (dstImage->info().format == format
|
|
|
|
&& srcImage->info().format == format) {
|
|
|
|
VkImageSubresourceRange dstSubresourceRange = {
|
|
|
|
dstSubresources.aspectMask,
|
|
|
|
dstSubresources.mipLevel, 1,
|
|
|
|
dstSubresources.baseArrayLayer,
|
|
|
|
dstSubresources.layerCount };
|
|
|
|
|
|
|
|
VkImageSubresourceRange srcSubresourceRange = {
|
|
|
|
srcSubresources.aspectMask,
|
|
|
|
srcSubresources.mipLevel, 1,
|
|
|
|
srcSubresources.baseArrayLayer,
|
|
|
|
srcSubresources.layerCount };
|
|
|
|
|
|
|
|
// We only support resolving to the entire image
|
|
|
|
// area, so we might as well discard its contents
|
|
|
|
m_barriers.accessImage(
|
|
|
|
dstImage, dstSubresourceRange,
|
|
|
|
VK_IMAGE_LAYOUT_UNDEFINED,
|
|
|
|
dstImage->info().stages,
|
|
|
|
dstImage->info().access,
|
2018-04-29 15:28:50 +02:00
|
|
|
dstImage->pickLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL),
|
2018-02-21 01:04:28 +01:00
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_WRITE_BIT);
|
2018-06-18 14:35:11 +02:00
|
|
|
|
2018-02-21 01:04:28 +01:00
|
|
|
m_barriers.accessImage(
|
|
|
|
srcImage, srcSubresourceRange,
|
|
|
|
srcImage->info().layout,
|
|
|
|
srcImage->info().stages,
|
|
|
|
srcImage->info().access,
|
2018-04-29 15:28:50 +02:00
|
|
|
srcImage->pickLayout(VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL),
|
2018-02-21 01:04:28 +01:00
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_READ_BIT);
|
2018-06-18 14:35:11 +02:00
|
|
|
|
2018-02-21 01:04:28 +01:00
|
|
|
m_barriers.recordCommands(m_cmd);
|
|
|
|
|
2018-02-20 22:26:23 +01:00
|
|
|
VkImageResolve imageRegion;
|
|
|
|
imageRegion.srcSubresource = srcSubresources;
|
|
|
|
imageRegion.srcOffset = VkOffset3D { 0, 0, 0 };
|
|
|
|
imageRegion.dstSubresource = dstSubresources;
|
|
|
|
imageRegion.dstOffset = VkOffset3D { 0, 0, 0 };
|
|
|
|
imageRegion.extent = srcImage->mipLevelExtent(srcSubresources.mipLevel);
|
|
|
|
|
|
|
|
m_cmd->cmdResolveImage(
|
2018-04-29 15:28:50 +02:00
|
|
|
srcImage->handle(), srcImage->pickLayout(VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL),
|
|
|
|
dstImage->handle(), dstImage->pickLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL),
|
2018-02-20 22:26:23 +01:00
|
|
|
1, &imageRegion);
|
2018-02-21 01:04:28 +01:00
|
|
|
|
|
|
|
m_barriers.accessImage(
|
|
|
|
dstImage, dstSubresourceRange,
|
2018-04-29 15:28:50 +02:00
|
|
|
dstImage->pickLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL),
|
2018-02-21 01:04:28 +01:00
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_WRITE_BIT,
|
|
|
|
dstImage->info().layout,
|
|
|
|
dstImage->info().stages,
|
|
|
|
dstImage->info().access);
|
2018-06-18 14:35:11 +02:00
|
|
|
|
2018-02-21 01:04:28 +01:00
|
|
|
m_barriers.accessImage(
|
|
|
|
srcImage, srcSubresourceRange,
|
2018-04-29 15:28:50 +02:00
|
|
|
srcImage->pickLayout(VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL),
|
2018-02-21 01:04:28 +01:00
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_READ_BIT,
|
|
|
|
srcImage->info().layout,
|
|
|
|
srcImage->info().stages,
|
|
|
|
srcImage->info().access);
|
2018-02-20 22:26:23 +01:00
|
|
|
} else {
|
2018-06-23 13:07:11 +02:00
|
|
|
// Create image views covering the requested subresourcs
|
|
|
|
DxvkImageViewCreateInfo dstViewInfo;
|
|
|
|
dstViewInfo.type = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
|
|
|
|
dstViewInfo.format = format;
|
2018-07-21 09:40:07 +02:00
|
|
|
dstViewInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
2018-06-23 13:07:11 +02:00
|
|
|
dstViewInfo.aspect = dstSubresources.aspectMask;
|
|
|
|
dstViewInfo.minLevel = dstSubresources.mipLevel;
|
|
|
|
dstViewInfo.numLevels = 1;
|
|
|
|
dstViewInfo.minLayer = dstSubresources.baseArrayLayer;
|
|
|
|
dstViewInfo.numLayers = dstSubresources.layerCount;
|
|
|
|
|
|
|
|
DxvkImageViewCreateInfo srcViewInfo;
|
|
|
|
srcViewInfo.type = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
|
|
|
|
srcViewInfo.format = format;
|
2018-07-21 09:40:07 +02:00
|
|
|
srcViewInfo.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
|
2018-06-23 13:07:11 +02:00
|
|
|
srcViewInfo.aspect = srcSubresources.aspectMask;
|
|
|
|
srcViewInfo.minLevel = srcSubresources.mipLevel;
|
|
|
|
srcViewInfo.numLevels = 1;
|
|
|
|
srcViewInfo.minLayer = srcSubresources.baseArrayLayer;
|
|
|
|
srcViewInfo.numLayers = srcSubresources.layerCount;
|
|
|
|
|
|
|
|
Rc<DxvkImageView> dstImageView = m_device->createImageView(dstImage, dstViewInfo);
|
|
|
|
Rc<DxvkImageView> srcImageView = m_device->createImageView(srcImage, srcViewInfo);
|
|
|
|
|
|
|
|
// Create a framebuffer and pipeline for the resolve op
|
|
|
|
DxvkMetaResolvePipeline pipeInfo = m_metaResolve->getPipeline(format);
|
|
|
|
|
|
|
|
Rc<DxvkMetaResolveRenderPass> fb = new DxvkMetaResolveRenderPass(
|
|
|
|
m_device->vkd(), dstImageView, srcImageView);
|
|
|
|
|
|
|
|
// Create descriptor set pointing to the source image
|
|
|
|
VkDescriptorImageInfo descriptorImage;
|
|
|
|
descriptorImage.sampler = VK_NULL_HANDLE;
|
|
|
|
descriptorImage.imageView = srcImageView->handle();
|
|
|
|
descriptorImage.imageLayout = srcImageView->imageInfo().layout;
|
|
|
|
|
|
|
|
VkWriteDescriptorSet descriptorWrite;
|
|
|
|
descriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
|
|
|
descriptorWrite.pNext = nullptr;
|
|
|
|
descriptorWrite.dstBinding = 0;
|
|
|
|
descriptorWrite.dstArrayElement = 0;
|
|
|
|
descriptorWrite.descriptorCount = 1;
|
|
|
|
descriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
|
|
|
descriptorWrite.pImageInfo = &descriptorImage;
|
|
|
|
descriptorWrite.pBufferInfo = nullptr;
|
|
|
|
descriptorWrite.pTexelBufferView = nullptr;
|
|
|
|
|
|
|
|
descriptorWrite.dstSet = m_cmd->allocateDescriptorSet(pipeInfo.dsetLayout);
|
|
|
|
m_cmd->updateDescriptorSets(1, &descriptorWrite);
|
|
|
|
|
|
|
|
// Set up viewport and scissor rect
|
|
|
|
VkExtent3D passExtent = dstImageView->mipLevelExtent(0);
|
|
|
|
passExtent.depth = dstSubresources.layerCount;
|
|
|
|
|
|
|
|
VkViewport viewport;
|
|
|
|
viewport.x = 0.0f;
|
|
|
|
viewport.y = 0.0f;
|
|
|
|
viewport.width = float(passExtent.width);
|
|
|
|
viewport.height = float(passExtent.height);
|
|
|
|
viewport.minDepth = 0.0f;
|
|
|
|
viewport.maxDepth = 1.0f;
|
2018-02-21 01:04:28 +01:00
|
|
|
|
2018-06-23 13:07:11 +02:00
|
|
|
VkRect2D scissor;
|
|
|
|
scissor.offset = { 0, 0 };
|
|
|
|
scissor.extent = { passExtent.width, passExtent.height };
|
|
|
|
|
|
|
|
// Render pass info
|
2018-02-21 01:04:28 +01:00
|
|
|
VkRenderPassBeginInfo info;
|
2018-06-23 13:07:11 +02:00
|
|
|
info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
|
|
|
info.pNext = nullptr;
|
|
|
|
info.renderPass = fb->renderPass();
|
|
|
|
info.framebuffer = fb->framebuffer();
|
|
|
|
info.renderArea.offset = { 0, 0 };
|
|
|
|
info.renderArea.extent = { passExtent.width, passExtent.height };
|
|
|
|
info.clearValueCount = 0;
|
|
|
|
info.pClearValues = nullptr;
|
2018-02-21 01:04:28 +01:00
|
|
|
|
2018-06-23 13:07:11 +02:00
|
|
|
// Perform the actual resolve operation
|
2018-02-21 01:04:28 +01:00
|
|
|
m_cmd->cmdBeginRenderPass(&info, VK_SUBPASS_CONTENTS_INLINE);
|
2018-06-23 13:07:11 +02:00
|
|
|
m_cmd->cmdBindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, pipeInfo.pipeHandle);
|
|
|
|
m_cmd->cmdBindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS,
|
|
|
|
pipeInfo.pipeLayout, descriptorWrite.dstSet, 0, nullptr);
|
|
|
|
|
|
|
|
m_cmd->cmdSetViewport(0, 1, &viewport);
|
|
|
|
m_cmd->cmdSetScissor (0, 1, &scissor);
|
2018-02-21 01:04:28 +01:00
|
|
|
|
2018-06-23 13:07:11 +02:00
|
|
|
m_cmd->cmdDraw(1, passExtent.depth, 0, 0);
|
|
|
|
m_cmd->cmdEndRenderPass();
|
|
|
|
|
2018-02-21 01:04:28 +01:00
|
|
|
m_cmd->trackResource(fb);
|
2018-02-20 22:26:23 +01:00
|
|
|
}
|
2018-03-07 10:37:27 +01:00
|
|
|
|
|
|
|
m_cmd->trackResource(srcImage);
|
|
|
|
m_cmd->trackResource(dstImage);
|
2017-12-12 00:27:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-20 00:19:03 +02:00
|
|
|
void DxvkContext::transformImage(
|
|
|
|
const Rc<DxvkImage>& dstImage,
|
|
|
|
const VkImageSubresourceRange& dstSubresources,
|
|
|
|
VkImageLayout srcLayout,
|
|
|
|
VkImageLayout dstLayout) {
|
2018-05-01 23:29:58 +02:00
|
|
|
this->spillRenderPass();
|
2018-04-20 00:19:03 +02:00
|
|
|
|
2018-05-01 23:29:58 +02:00
|
|
|
if (srcLayout != dstLayout) {
|
2018-06-18 14:35:11 +02:00
|
|
|
m_barriers.recordCommands(m_cmd);
|
|
|
|
|
2018-05-01 23:29:58 +02:00
|
|
|
m_barriers.accessImage(
|
|
|
|
dstImage, dstSubresources,
|
|
|
|
srcLayout,
|
|
|
|
dstImage->info().stages,
|
|
|
|
dstImage->info().access,
|
|
|
|
dstLayout,
|
|
|
|
dstImage->info().stages,
|
|
|
|
dstImage->info().access);
|
|
|
|
|
|
|
|
m_cmd->trackResource(dstImage);
|
|
|
|
}
|
2018-04-20 00:19:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-07 18:51:41 +01:00
|
|
|
void DxvkContext::updateBuffer(
|
|
|
|
const Rc<DxvkBuffer>& buffer,
|
|
|
|
VkDeviceSize offset,
|
|
|
|
VkDeviceSize size,
|
|
|
|
const void* data) {
|
2018-04-23 11:11:40 +02:00
|
|
|
this->spillRenderPass();
|
2018-01-30 15:44:18 +01:00
|
|
|
|
2018-01-20 19:49:41 -08:00
|
|
|
// Vulkan specifies that small amounts of data (up to 64kB) can
|
|
|
|
// be copied to a buffer directly if the size is a multiple of
|
|
|
|
// four. Anything else must be copied through a staging buffer.
|
|
|
|
// We'll limit the size to 4kB in order to keep command buffers
|
|
|
|
// reasonably small, we do not know how much data apps may upload.
|
2018-01-30 15:44:18 +01:00
|
|
|
auto physicalSlice = buffer->subSlice(offset, size);
|
2018-06-16 11:53:06 +02:00
|
|
|
|
|
|
|
if (m_barriers.isBufferDirty(physicalSlice, DxvkAccess::Write))
|
|
|
|
m_barriers.recordCommands(m_cmd);
|
2018-01-30 15:44:18 +01:00
|
|
|
|
2018-01-20 19:49:41 -08:00
|
|
|
if ((size <= 4096) && ((size & 0x3) == 0) && ((offset & 0x3) == 0)) {
|
|
|
|
m_cmd->cmdUpdateBuffer(
|
|
|
|
physicalSlice.handle(),
|
|
|
|
physicalSlice.offset(),
|
|
|
|
physicalSlice.length(),
|
|
|
|
data);
|
|
|
|
} else {
|
|
|
|
auto slice = m_cmd->stagedAlloc(size);
|
|
|
|
std::memcpy(slice.mapPtr, data, size);
|
|
|
|
|
|
|
|
m_cmd->stagedBufferCopy(
|
|
|
|
physicalSlice.handle(),
|
|
|
|
physicalSlice.offset(),
|
|
|
|
physicalSlice.length(),
|
|
|
|
slice);
|
2017-12-10 15:57:51 +01:00
|
|
|
}
|
2018-01-20 19:49:41 -08:00
|
|
|
|
|
|
|
m_barriers.accessBuffer(
|
|
|
|
physicalSlice,
|
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_WRITE_BIT,
|
|
|
|
buffer->info().stages,
|
|
|
|
buffer->info().access);
|
|
|
|
|
|
|
|
m_cmd->trackResource(buffer->resource());
|
2017-12-10 15:57:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DxvkContext::updateImage(
|
|
|
|
const Rc<DxvkImage>& image,
|
|
|
|
const VkImageSubresourceLayers& subresources,
|
|
|
|
VkOffset3D imageOffset,
|
|
|
|
VkExtent3D imageExtent,
|
|
|
|
const void* data,
|
|
|
|
VkDeviceSize pitchPerRow,
|
|
|
|
VkDeviceSize pitchPerLayer) {
|
2018-04-23 11:11:40 +02:00
|
|
|
this->spillRenderPass();
|
2017-12-10 15:57:51 +01:00
|
|
|
|
2017-12-10 18:14:28 +01:00
|
|
|
// Upload data through a staging buffer. Special care needs to
|
|
|
|
// be taken when dealing with compressed image formats: Rather
|
|
|
|
// than copying pixels, we'll be copying blocks of pixels.
|
2018-01-30 15:44:18 +01:00
|
|
|
const DxvkFormatInfo* formatInfo = image->formatInfo();
|
2017-12-10 15:57:51 +01:00
|
|
|
|
2018-01-09 19:08:23 +01:00
|
|
|
// Align image extent to a full block. This is necessary in
|
|
|
|
// case the image size is not a multiple of the block size.
|
2018-01-20 21:42:11 +01:00
|
|
|
VkExtent3D elementCount = util::computeBlockCount(
|
|
|
|
imageExtent, formatInfo->blockSize);
|
|
|
|
elementCount.depth *= subresources.layerCount;
|
2017-12-10 18:14:28 +01:00
|
|
|
|
|
|
|
// Allocate staging buffer memory for the image data. The
|
|
|
|
// pixels or blocks will be tightly packed within the buffer.
|
2018-01-20 21:42:11 +01:00
|
|
|
const DxvkStagingBufferSlice slice = m_cmd->stagedAlloc(
|
|
|
|
formatInfo->elementSize * util::flattenImageExtent(elementCount));
|
2017-12-10 15:57:51 +01:00
|
|
|
|
|
|
|
auto dstData = reinterpret_cast<char*>(slice.mapPtr);
|
|
|
|
auto srcData = reinterpret_cast<const char*>(data);
|
|
|
|
|
2018-01-20 21:42:11 +01:00
|
|
|
util::packImageData(dstData, srcData,
|
|
|
|
elementCount, formatInfo->elementSize,
|
|
|
|
pitchPerRow, pitchPerLayer);
|
2017-12-10 15:57:51 +01:00
|
|
|
|
2017-12-10 18:14:28 +01:00
|
|
|
// Prepare the image layout. If the given extent covers
|
|
|
|
// the entire image, we may discard its previous contents.
|
|
|
|
VkImageSubresourceRange subresourceRange;
|
2018-06-28 13:00:03 +02:00
|
|
|
subresourceRange.aspectMask = formatInfo->aspectMask;
|
2017-12-10 18:14:28 +01:00
|
|
|
subresourceRange.baseMipLevel = subresources.mipLevel;
|
|
|
|
subresourceRange.levelCount = 1;
|
|
|
|
subresourceRange.baseArrayLayer = subresources.baseArrayLayer;
|
|
|
|
subresourceRange.layerCount = subresources.layerCount;
|
2018-06-18 14:35:11 +02:00
|
|
|
|
2018-06-28 13:00:03 +02:00
|
|
|
if (m_barriers.isImageDirty(image, subresourceRange, DxvkAccess::Write))
|
|
|
|
m_barriers.recordCommands(m_cmd);
|
2018-06-28 12:44:57 +02:00
|
|
|
|
|
|
|
// Initialize the image if the entire subresource is covered
|
|
|
|
VkImageLayout imageLayoutInitial = image->info().layout;
|
|
|
|
VkImageLayout imageLayoutTransfer = image->pickLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
|
|
|
|
|
|
|
if (image->isFullSubresource(subresources, imageExtent))
|
|
|
|
imageLayoutInitial = VK_IMAGE_LAYOUT_UNDEFINED;
|
|
|
|
|
2018-06-28 13:00:03 +02:00
|
|
|
m_transitions.accessImage(
|
2017-12-10 18:14:28 +01:00
|
|
|
image, subresourceRange,
|
2018-06-28 13:00:03 +02:00
|
|
|
imageLayoutInitial, 0, 0,
|
2018-06-28 12:44:57 +02:00
|
|
|
imageLayoutTransfer,
|
2017-12-10 18:14:28 +01:00
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_WRITE_BIT);
|
2018-06-18 14:35:11 +02:00
|
|
|
|
2018-06-28 13:00:03 +02:00
|
|
|
m_transitions.recordCommands(m_cmd);
|
2017-12-10 18:14:28 +01:00
|
|
|
|
|
|
|
// Copy contents of the staging buffer into the image.
|
|
|
|
// Since our source data is tightly packed, we do not
|
|
|
|
// need to specify any strides.
|
2017-12-10 15:57:51 +01:00
|
|
|
VkBufferImageCopy region;
|
|
|
|
region.bufferOffset = slice.offset;
|
|
|
|
region.bufferRowLength = 0;
|
|
|
|
region.bufferImageHeight = 0;
|
|
|
|
region.imageSubresource = subresources;
|
|
|
|
region.imageOffset = imageOffset;
|
|
|
|
region.imageExtent = imageExtent;
|
|
|
|
|
|
|
|
m_cmd->stagedBufferImageCopy(image->handle(),
|
2018-06-28 12:44:57 +02:00
|
|
|
imageLayoutTransfer, region, slice);
|
2017-12-10 15:57:51 +01:00
|
|
|
|
2017-12-10 18:14:28 +01:00
|
|
|
// Transition image back into its optimal layout
|
2017-12-10 15:57:51 +01:00
|
|
|
m_barriers.accessImage(
|
|
|
|
image, subresourceRange,
|
2018-06-28 12:44:57 +02:00
|
|
|
imageLayoutTransfer,
|
2017-12-10 15:57:51 +01:00
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_WRITE_BIT,
|
|
|
|
image->info().layout,
|
|
|
|
image->info().stages,
|
|
|
|
image->info().access);
|
|
|
|
|
|
|
|
m_cmd->trackResource(image);
|
2017-12-07 18:51:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-20 15:35:29 +01:00
|
|
|
void DxvkContext::setViewports(
|
|
|
|
uint32_t viewportCount,
|
|
|
|
const VkViewport* viewports,
|
|
|
|
const VkRect2D* scissorRects) {
|
2018-01-10 20:40:10 +01:00
|
|
|
if (m_state.gp.state.rsViewportCount != viewportCount) {
|
|
|
|
m_state.gp.state.rsViewportCount = viewportCount;
|
2017-12-07 09:44:45 +01:00
|
|
|
m_flags.set(DxvkContextFlag::GpDirtyPipelineState);
|
2017-11-20 15:35:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < viewportCount; i++) {
|
2017-12-20 12:13:08 +01:00
|
|
|
m_state.vp.viewports[i] = viewports[i];
|
|
|
|
m_state.vp.scissorRects[i] = scissorRects[i];
|
2018-03-12 13:14:27 +01:00
|
|
|
|
|
|
|
// Vulkan viewports are not allowed to have a width or
|
|
|
|
// height of zero, so we fall back to a dummy viewport.
|
|
|
|
if (viewports[i].width == 0.0f || viewports[i].height == 0.0f) {
|
|
|
|
m_state.vp.viewports[i] = VkViewport {
|
|
|
|
0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f };
|
|
|
|
}
|
2017-11-20 15:35:29 +01:00
|
|
|
}
|
|
|
|
|
2018-05-29 05:03:27 +02:00
|
|
|
m_flags.set(DxvkContextFlag::GpDirtyViewport);
|
2017-10-11 23:29:05 +02:00
|
|
|
}
|
|
|
|
|
2017-10-10 23:32:13 +02:00
|
|
|
|
2017-12-11 14:11:18 +01:00
|
|
|
void DxvkContext::setBlendConstants(
|
2018-01-20 15:41:06 +01:00
|
|
|
const DxvkBlendConstants& blendConstants) {
|
2018-01-29 20:01:49 +01:00
|
|
|
m_state.om.blendConstants = blendConstants;
|
2018-05-29 05:03:27 +02:00
|
|
|
m_flags.set(DxvkContextFlag::GpDirtyBlendConstants);
|
2017-12-11 14:11:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DxvkContext::setStencilReference(
|
|
|
|
const uint32_t reference) {
|
|
|
|
m_state.om.stencilReference = reference;
|
2018-05-29 05:03:27 +02:00
|
|
|
m_flags.set(DxvkContextFlag::GpDirtyStencilRef);
|
2017-12-11 14:11:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-10 20:40:10 +01:00
|
|
|
void DxvkContext::setInputAssemblyState(const DxvkInputAssemblyState& ia) {
|
|
|
|
m_state.gp.state.iaPrimitiveTopology = ia.primitiveTopology;
|
|
|
|
m_state.gp.state.iaPrimitiveRestart = ia.primitiveRestart;
|
2018-01-29 11:31:00 +01:00
|
|
|
m_state.gp.state.iaPatchVertexCount = ia.patchVertexCount;
|
2018-01-10 20:40:10 +01:00
|
|
|
|
2017-12-08 00:02:43 +01:00
|
|
|
m_flags.set(DxvkContextFlag::GpDirtyPipelineState);
|
2017-11-20 13:38:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DxvkContext::setInputLayout(
|
2017-12-08 00:44:58 +01:00
|
|
|
uint32_t attributeCount,
|
|
|
|
const DxvkVertexAttribute* attributes,
|
|
|
|
uint32_t bindingCount,
|
|
|
|
const DxvkVertexBinding* bindings) {
|
2018-01-08 20:23:21 +01:00
|
|
|
m_flags.set(
|
|
|
|
DxvkContextFlag::GpDirtyPipelineState,
|
|
|
|
DxvkContextFlag::GpDirtyVertexBuffers);
|
2017-12-08 00:44:58 +01:00
|
|
|
|
2018-01-10 20:40:10 +01:00
|
|
|
for (uint32_t i = 0; i < attributeCount; i++) {
|
|
|
|
m_state.gp.state.ilAttributes[i].location = attributes[i].location;
|
|
|
|
m_state.gp.state.ilAttributes[i].binding = attributes[i].binding;
|
|
|
|
m_state.gp.state.ilAttributes[i].format = attributes[i].format;
|
|
|
|
m_state.gp.state.ilAttributes[i].offset = attributes[i].offset;
|
|
|
|
}
|
|
|
|
|
2018-01-28 19:37:22 +01:00
|
|
|
for (uint32_t i = attributeCount; i < m_state.gp.state.ilAttributeCount; i++)
|
|
|
|
m_state.gp.state.ilAttributes[i] = VkVertexInputAttributeDescription();
|
2018-01-10 20:40:10 +01:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < bindingCount; i++) {
|
|
|
|
m_state.gp.state.ilBindings[i].binding = bindings[i].binding;
|
|
|
|
m_state.gp.state.ilBindings[i].inputRate = bindings[i].inputRate;
|
2018-04-17 17:24:16 +02:00
|
|
|
m_state.gp.state.ilDivisors[i] = bindings[i].fetchRate;
|
2018-01-10 20:40:10 +01:00
|
|
|
}
|
2017-12-08 00:44:58 +01:00
|
|
|
|
2018-01-28 19:37:22 +01:00
|
|
|
for (uint32_t i = bindingCount; i < m_state.gp.state.ilBindingCount; i++)
|
|
|
|
m_state.gp.state.ilBindings[i] = VkVertexInputBindingDescription();
|
|
|
|
|
|
|
|
m_state.gp.state.ilAttributeCount = attributeCount;
|
|
|
|
m_state.gp.state.ilBindingCount = bindingCount;
|
2017-11-20 13:38:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-10 20:40:10 +01:00
|
|
|
void DxvkContext::setRasterizerState(const DxvkRasterizerState& rs) {
|
2018-06-25 16:56:52 +02:00
|
|
|
m_state.gp.state.rsDepthClampEnable = rs.depthClampEnable;
|
|
|
|
m_state.gp.state.rsDepthBiasEnable = rs.depthBiasEnable;
|
2018-01-10 20:40:10 +01:00
|
|
|
m_state.gp.state.rsPolygonMode = rs.polygonMode;
|
|
|
|
m_state.gp.state.rsCullMode = rs.cullMode;
|
|
|
|
m_state.gp.state.rsFrontFace = rs.frontFace;
|
2018-09-18 13:21:58 +02:00
|
|
|
m_state.gp.state.rsSampleCount = rs.sampleCount;
|
2018-06-06 12:45:45 +02:00
|
|
|
|
|
|
|
m_state.ds.depthBiasConstant = rs.depthBiasConstant;
|
|
|
|
m_state.ds.depthBiasClamp = rs.depthBiasClamp;
|
|
|
|
m_state.ds.depthBiasSlope = rs.depthBiasSlope;
|
|
|
|
|
|
|
|
m_flags.set(
|
|
|
|
DxvkContextFlag::GpDirtyPipelineState,
|
|
|
|
DxvkContextFlag::GpDirtyDepthBias);
|
2017-11-20 13:38:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-10 20:40:10 +01:00
|
|
|
void DxvkContext::setMultisampleState(const DxvkMultisampleState& ms) {
|
|
|
|
m_state.gp.state.msSampleMask = ms.sampleMask;
|
|
|
|
m_state.gp.state.msEnableAlphaToCoverage = ms.enableAlphaToCoverage;
|
|
|
|
m_state.gp.state.msEnableAlphaToOne = ms.enableAlphaToOne;
|
|
|
|
|
2017-12-08 00:02:43 +01:00
|
|
|
m_flags.set(DxvkContextFlag::GpDirtyPipelineState);
|
2017-11-20 13:38:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-10 20:40:10 +01:00
|
|
|
void DxvkContext::setDepthStencilState(const DxvkDepthStencilState& ds) {
|
|
|
|
m_state.gp.state.dsEnableDepthTest = ds.enableDepthTest;
|
|
|
|
m_state.gp.state.dsEnableDepthWrite = ds.enableDepthWrite;
|
|
|
|
m_state.gp.state.dsEnableStencilTest = ds.enableStencilTest;
|
|
|
|
m_state.gp.state.dsDepthCompareOp = ds.depthCompareOp;
|
|
|
|
m_state.gp.state.dsStencilOpFront = ds.stencilOpFront;
|
|
|
|
m_state.gp.state.dsStencilOpBack = ds.stencilOpBack;
|
|
|
|
|
2017-12-08 00:02:43 +01:00
|
|
|
m_flags.set(DxvkContextFlag::GpDirtyPipelineState);
|
2017-11-20 13:38:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-10 20:40:10 +01:00
|
|
|
void DxvkContext::setLogicOpState(const DxvkLogicOpState& lo) {
|
|
|
|
m_state.gp.state.omEnableLogicOp = lo.enableLogicOp;
|
|
|
|
m_state.gp.state.omLogicOp = lo.logicOp;
|
|
|
|
|
2017-12-08 00:51:10 +01:00
|
|
|
m_flags.set(DxvkContextFlag::GpDirtyPipelineState);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DxvkContext::setBlendMode(
|
|
|
|
uint32_t attachment,
|
|
|
|
const DxvkBlendMode& blendMode) {
|
2018-01-10 20:40:10 +01:00
|
|
|
m_state.gp.state.omBlendAttachments[attachment].blendEnable = blendMode.enableBlending;
|
|
|
|
m_state.gp.state.omBlendAttachments[attachment].srcColorBlendFactor = blendMode.colorSrcFactor;
|
|
|
|
m_state.gp.state.omBlendAttachments[attachment].dstColorBlendFactor = blendMode.colorDstFactor;
|
|
|
|
m_state.gp.state.omBlendAttachments[attachment].colorBlendOp = blendMode.colorBlendOp;
|
|
|
|
m_state.gp.state.omBlendAttachments[attachment].srcAlphaBlendFactor = blendMode.alphaSrcFactor;
|
|
|
|
m_state.gp.state.omBlendAttachments[attachment].dstAlphaBlendFactor = blendMode.alphaDstFactor;
|
|
|
|
m_state.gp.state.omBlendAttachments[attachment].alphaBlendOp = blendMode.alphaBlendOp;
|
|
|
|
m_state.gp.state.omBlendAttachments[attachment].colorWriteMask = blendMode.writeMask;
|
|
|
|
|
2017-12-08 00:51:10 +01:00
|
|
|
m_flags.set(DxvkContextFlag::GpDirtyPipelineState);
|
2017-11-20 13:38:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-18 22:57:45 +01:00
|
|
|
void DxvkContext::signalEvent(const DxvkEventRevision& event) {
|
|
|
|
m_cmd->trackEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-15 13:25:18 +01:00
|
|
|
void DxvkContext::writeTimestamp(const DxvkQueryRevision& query) {
|
2018-08-31 15:34:53 +02:00
|
|
|
DxvkQueryHandle handle = m_queries.allocQuery(m_cmd, query);
|
2018-02-15 13:25:18 +01:00
|
|
|
|
|
|
|
m_cmd->cmdWriteTimestamp(
|
|
|
|
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
|
|
|
|
handle.queryPool, handle.queryId);
|
|
|
|
|
|
|
|
query.query->endRecording(query.revision);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-15 19:00:29 +02:00
|
|
|
void DxvkContext::clearImageViewFb(
|
|
|
|
const Rc<DxvkImageView>& imageView,
|
|
|
|
VkOffset3D offset,
|
|
|
|
VkExtent3D extent,
|
|
|
|
VkClearValue value) {
|
2018-09-13 21:39:56 +02:00
|
|
|
this->updateFramebuffer();
|
2018-08-15 19:00:29 +02:00
|
|
|
|
|
|
|
// Find out if the render target view is currently bound,
|
|
|
|
// so that we can avoid spilling the render pass if it is.
|
|
|
|
int32_t attachmentIndex = -1;
|
|
|
|
|
|
|
|
if (m_state.om.framebuffer != nullptr)
|
|
|
|
attachmentIndex = m_state.om.framebuffer->findAttachment(imageView);
|
|
|
|
|
|
|
|
if (attachmentIndex < 0) {
|
|
|
|
this->spillRenderPass();
|
|
|
|
|
|
|
|
// Set up a temporary framebuffer
|
|
|
|
DxvkRenderTargets attachments;
|
|
|
|
DxvkRenderPassOps ops;
|
|
|
|
|
|
|
|
if (imageView->info().aspect & VK_IMAGE_ASPECT_COLOR_BIT) {
|
|
|
|
attachments.color[0].view = imageView;
|
|
|
|
attachments.color[0].layout = imageView->pickLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
|
|
|
|
} else {
|
|
|
|
attachments.depth.view = imageView;
|
|
|
|
attachments.depth.layout = imageView->pickLayout(VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We cannot leverage render pass clears
|
|
|
|
// because we clear only part of the view
|
|
|
|
this->renderPassBindFramebuffer(
|
|
|
|
m_device->createFramebuffer(attachments),
|
|
|
|
ops, 0, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Perform the actual clear operation
|
|
|
|
VkClearAttachment clearInfo;
|
|
|
|
clearInfo.aspectMask = imageView->info().aspect;
|
|
|
|
clearInfo.colorAttachment = attachmentIndex;
|
|
|
|
clearInfo.clearValue = value;
|
|
|
|
|
|
|
|
if (attachmentIndex < 0)
|
|
|
|
clearInfo.colorAttachment = 0;
|
|
|
|
|
|
|
|
VkClearRect clearRect;
|
|
|
|
clearRect.rect.offset.x = offset.x;
|
|
|
|
clearRect.rect.offset.y = offset.y;
|
|
|
|
clearRect.rect.extent.width = extent.width;
|
|
|
|
clearRect.rect.extent.height = extent.height;
|
|
|
|
clearRect.baseArrayLayer = 0;
|
|
|
|
clearRect.layerCount = imageView->info().numLayers;
|
|
|
|
|
|
|
|
m_cmd->cmdClearAttachments(1, &clearInfo, 1, &clearRect);
|
|
|
|
|
|
|
|
// Unbind temporary framebuffer
|
|
|
|
if (attachmentIndex < 0)
|
|
|
|
this->renderPassUnbindFramebuffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DxvkContext::clearImageViewCs(
|
|
|
|
const Rc<DxvkImageView>& imageView,
|
|
|
|
VkOffset3D offset,
|
|
|
|
VkExtent3D extent,
|
|
|
|
VkClearValue value) {
|
|
|
|
this->spillRenderPass();
|
|
|
|
this->unbindComputePipeline();
|
|
|
|
|
|
|
|
m_barriers.recordCommands(m_cmd);
|
|
|
|
|
|
|
|
// Query pipeline objects to use for this clear operation
|
|
|
|
DxvkMetaClearPipeline pipeInfo = m_metaClear->getClearImagePipeline(
|
|
|
|
imageView->type(), imageFormatInfo(imageView->info().format)->flags);
|
|
|
|
|
|
|
|
// Create a descriptor set pointing to the view
|
|
|
|
VkDescriptorSet descriptorSet =
|
|
|
|
m_cmd->allocateDescriptorSet(pipeInfo.dsetLayout);
|
|
|
|
|
|
|
|
VkDescriptorImageInfo viewInfo;
|
|
|
|
viewInfo.sampler = VK_NULL_HANDLE;
|
|
|
|
viewInfo.imageView = imageView->handle();
|
|
|
|
viewInfo.imageLayout = imageView->imageInfo().layout;
|
|
|
|
|
|
|
|
VkWriteDescriptorSet descriptorWrite;
|
|
|
|
descriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
|
|
|
descriptorWrite.pNext = nullptr;
|
|
|
|
descriptorWrite.dstSet = descriptorSet;
|
|
|
|
descriptorWrite.dstBinding = 0;
|
|
|
|
descriptorWrite.dstArrayElement = 0;
|
|
|
|
descriptorWrite.descriptorCount = 1;
|
|
|
|
descriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
|
|
|
|
descriptorWrite.pImageInfo = &viewInfo;
|
|
|
|
descriptorWrite.pBufferInfo = nullptr;
|
|
|
|
descriptorWrite.pTexelBufferView = nullptr;
|
|
|
|
m_cmd->updateDescriptorSets(1, &descriptorWrite);
|
|
|
|
|
|
|
|
// Prepare shader arguments
|
|
|
|
DxvkMetaClearArgs pushArgs;
|
|
|
|
pushArgs.clearValue = value.color;
|
|
|
|
pushArgs.offset = offset;
|
|
|
|
pushArgs.extent = extent;
|
|
|
|
|
|
|
|
VkExtent3D workgroups = util::computeBlockCount(
|
|
|
|
pushArgs.extent, pipeInfo.workgroupSize);
|
|
|
|
|
|
|
|
if (imageView->type() == VK_IMAGE_VIEW_TYPE_1D_ARRAY)
|
|
|
|
workgroups.height = imageView->subresources().layerCount;
|
|
|
|
else if (imageView->type() == VK_IMAGE_VIEW_TYPE_2D_ARRAY)
|
|
|
|
workgroups.depth = imageView->subresources().layerCount;
|
|
|
|
|
|
|
|
m_cmd->cmdBindPipeline(
|
|
|
|
VK_PIPELINE_BIND_POINT_COMPUTE,
|
|
|
|
pipeInfo.pipeline);
|
|
|
|
m_cmd->cmdBindDescriptorSet(
|
|
|
|
VK_PIPELINE_BIND_POINT_COMPUTE,
|
|
|
|
pipeInfo.pipeLayout, descriptorSet,
|
|
|
|
0, nullptr);
|
|
|
|
m_cmd->cmdPushConstants(
|
|
|
|
pipeInfo.pipeLayout,
|
|
|
|
VK_SHADER_STAGE_COMPUTE_BIT,
|
|
|
|
0, sizeof(pushArgs), &pushArgs);
|
|
|
|
m_cmd->cmdDispatch(
|
|
|
|
workgroups.width,
|
|
|
|
workgroups.height,
|
|
|
|
workgroups.depth);
|
|
|
|
|
|
|
|
m_barriers.accessImage(
|
|
|
|
imageView->image(),
|
|
|
|
imageView->subresources(),
|
|
|
|
imageView->imageInfo().layout,
|
|
|
|
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
|
|
|
VK_ACCESS_SHADER_WRITE_BIT,
|
|
|
|
imageView->imageInfo().layout,
|
|
|
|
imageView->imageInfo().stages,
|
|
|
|
imageView->imageInfo().access);
|
|
|
|
|
|
|
|
m_cmd->trackResource(imageView);
|
|
|
|
m_cmd->trackResource(imageView->image());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-23 11:11:40 +02:00
|
|
|
void DxvkContext::startRenderPass() {
|
2017-12-01 10:27:33 +01:00
|
|
|
if (!m_flags.test(DxvkContextFlag::GpRenderPassBound)
|
2017-11-17 19:49:44 +01:00
|
|
|
&& (m_state.om.framebuffer != nullptr)) {
|
2017-12-01 10:27:33 +01:00
|
|
|
m_flags.set(DxvkContextFlag::GpRenderPassBound);
|
2018-04-30 17:04:13 +02:00
|
|
|
m_flags.clr(DxvkContextFlag::GpClearRenderTargets);
|
2018-06-16 11:53:06 +02:00
|
|
|
|
|
|
|
m_barriers.recordCommands(m_cmd);
|
2018-07-06 15:01:37 +02:00
|
|
|
|
2018-04-30 13:12:28 +02:00
|
|
|
this->renderPassBindFramebuffer(
|
|
|
|
m_state.om.framebuffer,
|
2018-04-30 17:04:13 +02:00
|
|
|
m_state.om.renderPassOps,
|
|
|
|
m_state.om.clearValues.size(),
|
|
|
|
m_state.om.clearValues.data());
|
2018-04-30 13:12:28 +02:00
|
|
|
|
|
|
|
// Don't discard image contents if we have
|
|
|
|
// to spill the current render pass
|
|
|
|
this->resetRenderPassOps(
|
|
|
|
m_state.om.renderTargets,
|
|
|
|
m_state.om.renderPassOps);
|
2018-05-12 19:46:08 +02:00
|
|
|
|
2018-08-31 15:34:53 +02:00
|
|
|
// Begin occlusion queries
|
2018-09-11 12:35:53 +02:00
|
|
|
m_queries.beginQueries(m_cmd, VK_QUERY_TYPE_OCCLUSION);
|
|
|
|
m_queries.beginQueries(m_cmd, VK_QUERY_TYPE_PIPELINE_STATISTICS);
|
2017-10-15 19:23:10 +02:00
|
|
|
}
|
2017-10-11 23:29:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-23 11:11:40 +02:00
|
|
|
void DxvkContext::spillRenderPass() {
|
2018-04-30 17:04:13 +02:00
|
|
|
if (m_flags.test(DxvkContextFlag::GpClearRenderTargets))
|
|
|
|
this->startRenderPass();
|
2018-04-30 13:12:28 +02:00
|
|
|
|
2017-12-01 10:27:33 +01:00
|
|
|
if (m_flags.test(DxvkContextFlag::GpRenderPassBound)) {
|
|
|
|
m_flags.clr(DxvkContextFlag::GpRenderPassBound);
|
2018-08-31 15:34:53 +02:00
|
|
|
|
2018-09-11 12:35:53 +02:00
|
|
|
m_queries.endQueries(m_cmd, VK_QUERY_TYPE_OCCLUSION);
|
|
|
|
m_queries.endQueries(m_cmd, VK_QUERY_TYPE_PIPELINE_STATISTICS);
|
2018-08-31 15:34:53 +02:00
|
|
|
|
2018-03-17 17:59:43 +01:00
|
|
|
this->renderPassUnbindFramebuffer();
|
2017-11-17 19:49:44 +01:00
|
|
|
}
|
2017-10-11 23:29:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-30 13:12:28 +02:00
|
|
|
void DxvkContext::renderPassBindFramebuffer(
|
|
|
|
const Rc<DxvkFramebuffer>& framebuffer,
|
2018-04-30 17:04:13 +02:00
|
|
|
const DxvkRenderPassOps& ops,
|
|
|
|
uint32_t clearValueCount,
|
|
|
|
const VkClearValue* clearValues) {
|
2018-03-17 17:59:43 +01:00
|
|
|
const DxvkFramebufferSize fbSize = framebuffer->size();
|
|
|
|
|
|
|
|
VkRect2D renderArea;
|
|
|
|
renderArea.offset = VkOffset2D { 0, 0 };
|
|
|
|
renderArea.extent = VkExtent2D { fbSize.width, fbSize.height };
|
|
|
|
|
|
|
|
VkRenderPassBeginInfo info;
|
|
|
|
info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
|
|
|
info.pNext = nullptr;
|
2018-04-30 13:12:28 +02:00
|
|
|
info.renderPass = framebuffer->getRenderPassHandle(ops);
|
2018-03-17 17:59:43 +01:00
|
|
|
info.framebuffer = framebuffer->handle();
|
|
|
|
info.renderArea = renderArea;
|
2018-04-30 17:04:13 +02:00
|
|
|
info.clearValueCount = clearValueCount;
|
|
|
|
info.pClearValues = clearValues;
|
2018-03-17 17:59:43 +01:00
|
|
|
|
|
|
|
m_cmd->cmdBeginRenderPass(&info,
|
|
|
|
VK_SUBPASS_CONTENTS_INLINE);
|
2018-07-10 04:47:50 +02:00
|
|
|
|
2018-03-17 17:59:43 +01:00
|
|
|
m_cmd->trackResource(framebuffer);
|
2018-07-10 04:47:50 +02:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < framebuffer->numAttachments(); i++) {
|
|
|
|
m_cmd->trackResource(framebuffer->getAttachment(i).view);
|
|
|
|
m_cmd->trackResource(framebuffer->getAttachment(i).view->image());
|
|
|
|
}
|
|
|
|
|
2018-04-03 11:56:12 +02:00
|
|
|
m_cmd->addStatCtr(DxvkStatCounter::CmdRenderPassCount, 1);
|
2018-03-17 17:59:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DxvkContext::renderPassUnbindFramebuffer() {
|
|
|
|
m_cmd->cmdEndRenderPass();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-30 13:12:28 +02:00
|
|
|
void DxvkContext::resetRenderPassOps(
|
|
|
|
const DxvkRenderTargets& renderTargets,
|
|
|
|
DxvkRenderPassOps& renderPassOps) {
|
|
|
|
renderPassOps.depthOps = renderTargets.depth.view != nullptr
|
2018-04-30 21:42:16 +02:00
|
|
|
? DxvkDepthAttachmentOps {
|
|
|
|
VK_ATTACHMENT_LOAD_OP_LOAD,
|
|
|
|
VK_ATTACHMENT_LOAD_OP_LOAD,
|
|
|
|
renderTargets.depth.view->imageInfo().layout,
|
|
|
|
VK_ATTACHMENT_STORE_OP_STORE,
|
|
|
|
VK_ATTACHMENT_STORE_OP_STORE,
|
|
|
|
renderTargets.depth.view->imageInfo().layout }
|
|
|
|
: DxvkDepthAttachmentOps { };
|
2018-04-30 13:12:28 +02:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < MaxNumRenderTargets; i++) {
|
|
|
|
renderPassOps.colorOps[i] = renderTargets.color[i].view != nullptr
|
2018-04-30 21:42:16 +02:00
|
|
|
? DxvkColorAttachmentOps {
|
|
|
|
VK_ATTACHMENT_LOAD_OP_LOAD,
|
|
|
|
renderTargets.color[i].view->imageInfo().layout,
|
|
|
|
VK_ATTACHMENT_STORE_OP_STORE,
|
|
|
|
renderTargets.color[i].view->imageInfo().layout }
|
|
|
|
: DxvkColorAttachmentOps { };
|
2018-04-30 13:12:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO provide a sane alternative for this
|
|
|
|
if (renderPassOps.colorOps[0].loadLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
|
|
|
|
renderPassOps.colorOps[0].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
|
|
|
renderPassOps.colorOps[0].loadLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-11 23:13:34 +02:00
|
|
|
void DxvkContext::unbindComputePipeline() {
|
|
|
|
m_flags.set(
|
|
|
|
DxvkContextFlag::CpDirtyPipeline,
|
|
|
|
DxvkContextFlag::CpDirtyPipelineState,
|
|
|
|
DxvkContextFlag::CpDirtyResources);
|
|
|
|
|
|
|
|
m_cpActivePipeline = VK_NULL_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-03 20:23:26 +01:00
|
|
|
void DxvkContext::updateComputePipeline() {
|
|
|
|
if (m_flags.test(DxvkContextFlag::CpDirtyPipeline)) {
|
|
|
|
m_flags.clr(DxvkContextFlag::CpDirtyPipeline);
|
|
|
|
|
2018-09-17 10:40:57 +02:00
|
|
|
m_state.cp.state.bsBindingMask.clear();
|
2018-05-09 14:26:45 +02:00
|
|
|
m_state.cp.pipeline = m_pipeMgr->createComputePipeline(m_state.cp.cs.shader);
|
2017-12-07 09:38:31 +01:00
|
|
|
|
2018-01-25 12:57:43 +01:00
|
|
|
if (m_state.cp.pipeline != nullptr)
|
|
|
|
m_cmd->trackResource(m_state.cp.pipeline);
|
2018-02-14 17:54:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DxvkContext::updateComputePipelineState() {
|
|
|
|
if (m_flags.test(DxvkContextFlag::CpDirtyPipelineState)) {
|
|
|
|
m_flags.clr(DxvkContextFlag::CpDirtyPipelineState);
|
|
|
|
|
|
|
|
m_cpActivePipeline = m_state.cp.pipeline != nullptr
|
2018-04-03 15:52:39 +02:00
|
|
|
? m_state.cp.pipeline->getPipelineHandle(m_state.cp.state, m_cmd->statCounters())
|
2018-02-14 17:54:35 +01:00
|
|
|
: VK_NULL_HANDLE;
|
2018-01-25 12:57:43 +01:00
|
|
|
|
|
|
|
if (m_cpActivePipeline != VK_NULL_HANDLE) {
|
|
|
|
m_cmd->cmdBindPipeline(
|
|
|
|
VK_PIPELINE_BIND_POINT_COMPUTE,
|
|
|
|
m_cpActivePipeline);
|
|
|
|
}
|
2017-12-03 20:23:26 +01:00
|
|
|
}
|
2017-11-23 14:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-25 17:45:41 +02:00
|
|
|
void DxvkContext::unbindGraphicsPipeline() {
|
|
|
|
m_flags.set(
|
|
|
|
DxvkContextFlag::GpDirtyPipeline,
|
|
|
|
DxvkContextFlag::GpDirtyPipelineState,
|
|
|
|
DxvkContextFlag::GpDirtyResources,
|
|
|
|
DxvkContextFlag::GpDirtyVertexBuffers,
|
|
|
|
DxvkContextFlag::GpDirtyIndexBuffer);
|
|
|
|
|
|
|
|
m_gpActivePipeline = VK_NULL_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-03 20:23:26 +01:00
|
|
|
void DxvkContext::updateGraphicsPipeline() {
|
2018-01-10 12:13:46 +01:00
|
|
|
if (m_flags.test(DxvkContextFlag::GpDirtyPipeline)) {
|
|
|
|
m_flags.clr(DxvkContextFlag::GpDirtyPipeline);
|
2017-12-07 09:44:45 +01:00
|
|
|
|
2018-09-17 10:40:57 +02:00
|
|
|
m_state.gp.state.bsBindingMask.clear();
|
2018-03-29 12:32:20 +02:00
|
|
|
m_state.gp.pipeline = m_pipeMgr->createGraphicsPipeline(
|
2018-05-09 14:26:45 +02:00
|
|
|
m_state.gp.vs.shader,
|
2018-03-29 12:32:20 +02:00
|
|
|
m_state.gp.tcs.shader, m_state.gp.tes.shader,
|
2018-01-10 12:13:46 +01:00
|
|
|
m_state.gp.gs.shader, m_state.gp.fs.shader);
|
|
|
|
|
2018-01-25 12:57:43 +01:00
|
|
|
if (m_state.gp.pipeline != nullptr)
|
|
|
|
m_cmd->trackResource(m_state.gp.pipeline);
|
2018-01-10 12:13:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DxvkContext::updateGraphicsPipelineState() {
|
|
|
|
if (m_flags.test(DxvkContextFlag::GpDirtyPipelineState)) {
|
|
|
|
m_flags.clr(DxvkContextFlag::GpDirtyPipelineState);
|
2017-12-07 09:38:31 +01:00
|
|
|
|
2018-01-10 21:53:13 +01:00
|
|
|
for (uint32_t i = 0; i < m_state.gp.state.ilBindingCount; i++) {
|
2018-02-01 13:29:57 +01:00
|
|
|
const uint32_t binding = m_state.gp.state.ilBindings[i].binding;
|
|
|
|
|
2018-01-10 21:53:13 +01:00
|
|
|
m_state.gp.state.ilBindings[i].stride
|
2018-02-01 13:29:57 +01:00
|
|
|
= (m_state.vi.bindingMask & (1u << binding)) != 0
|
|
|
|
? m_state.vi.vertexStrides[binding]
|
|
|
|
: 0;
|
2018-01-10 21:53:13 +01:00
|
|
|
}
|
2017-12-07 21:47:38 +01:00
|
|
|
|
2018-01-10 20:40:10 +01:00
|
|
|
for (uint32_t i = m_state.gp.state.ilBindingCount; i < MaxNumVertexBindings; i++)
|
|
|
|
m_state.gp.state.ilBindings[i].stride = 0;
|
2017-11-17 19:49:44 +01:00
|
|
|
|
2018-05-03 19:33:41 +02:00
|
|
|
m_gpActivePipeline = m_state.gp.pipeline != nullptr && m_state.om.framebuffer != nullptr
|
|
|
|
? m_state.gp.pipeline->getPipelineHandle(m_state.gp.state,
|
2018-09-13 21:39:56 +02:00
|
|
|
m_state.om.framebuffer->getRenderPass(), m_cmd->statCounters())
|
2018-01-25 12:57:43 +01:00
|
|
|
: VK_NULL_HANDLE;
|
2018-01-12 14:25:26 +01:00
|
|
|
|
|
|
|
if (m_gpActivePipeline != VK_NULL_HANDLE) {
|
|
|
|
m_cmd->cmdBindPipeline(
|
|
|
|
VK_PIPELINE_BIND_POINT_GRAPHICS,
|
|
|
|
m_gpActivePipeline);
|
|
|
|
}
|
2018-05-29 05:03:27 +02:00
|
|
|
|
|
|
|
m_flags.set(
|
|
|
|
DxvkContextFlag::GpDirtyBlendConstants,
|
|
|
|
DxvkContextFlag::GpDirtyStencilRef,
|
2018-06-06 12:45:45 +02:00
|
|
|
DxvkContextFlag::GpDirtyViewport,
|
|
|
|
DxvkContextFlag::GpDirtyDepthBias);
|
2017-12-03 20:23:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DxvkContext::updateComputeShaderResources() {
|
2018-06-22 00:33:06 +02:00
|
|
|
if (m_state.cp.pipeline == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((m_flags.test(DxvkContextFlag::CpDirtyResources))
|
|
|
|
|| (m_flags.test(DxvkContextFlag::CpDirtyDescriptorOffsets)
|
|
|
|
&& m_state.cp.pipeline->layout()->hasStaticBufferBindings())) {
|
|
|
|
m_flags.clr(DxvkContextFlag::CpDirtyResources);
|
|
|
|
|
|
|
|
this->updateShaderResources(
|
|
|
|
VK_PIPELINE_BIND_POINT_COMPUTE,
|
2018-09-17 10:40:57 +02:00
|
|
|
m_state.cp.state.bsBindingMask,
|
2018-06-22 00:33:06 +02:00
|
|
|
m_state.cp.pipeline->layout());
|
|
|
|
|
|
|
|
m_flags.set(
|
|
|
|
DxvkContextFlag::CpDirtyDescriptorSet,
|
|
|
|
DxvkContextFlag::CpDirtyDescriptorOffsets);
|
2018-01-10 12:13:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DxvkContext::updateComputeShaderDescriptors() {
|
2018-06-22 00:33:06 +02:00
|
|
|
if (m_state.cp.pipeline == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (m_flags.test(DxvkContextFlag::CpDirtyDescriptorSet)) {
|
|
|
|
m_cpSet = this->updateShaderDescriptors(
|
|
|
|
VK_PIPELINE_BIND_POINT_COMPUTE,
|
|
|
|
m_state.cp.pipeline->layout());
|
2017-12-03 20:23:26 +01:00
|
|
|
}
|
2018-06-22 00:33:06 +02:00
|
|
|
|
|
|
|
if (m_flags.test(DxvkContextFlag::CpDirtyDescriptorOffsets)) {
|
|
|
|
this->updateShaderDescriptorSetBinding(
|
|
|
|
VK_PIPELINE_BIND_POINT_COMPUTE, m_cpSet,
|
|
|
|
m_state.cp.pipeline->layout());
|
|
|
|
}
|
|
|
|
|
|
|
|
m_flags.clr(
|
|
|
|
DxvkContextFlag::CpDirtyDescriptorOffsets,
|
|
|
|
DxvkContextFlag::CpDirtyDescriptorSet);
|
2017-12-03 20:23:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DxvkContext::updateGraphicsShaderResources() {
|
2018-06-22 00:33:06 +02:00
|
|
|
if (m_state.gp.pipeline == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((m_flags.test(DxvkContextFlag::GpDirtyResources))
|
|
|
|
|| (m_flags.test(DxvkContextFlag::GpDirtyDescriptorOffsets)
|
|
|
|
&& m_state.gp.pipeline->layout()->hasStaticBufferBindings())) {
|
|
|
|
m_flags.clr(DxvkContextFlag::GpDirtyResources);
|
|
|
|
|
|
|
|
this->updateShaderResources(
|
|
|
|
VK_PIPELINE_BIND_POINT_GRAPHICS,
|
2018-09-17 10:40:57 +02:00
|
|
|
m_state.gp.state.bsBindingMask,
|
2018-06-22 00:33:06 +02:00
|
|
|
m_state.gp.pipeline->layout());
|
|
|
|
|
|
|
|
m_flags.set(
|
|
|
|
DxvkContextFlag::GpDirtyDescriptorSet,
|
|
|
|
DxvkContextFlag::GpDirtyDescriptorOffsets);
|
2018-01-10 12:13:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DxvkContext::updateGraphicsShaderDescriptors() {
|
2018-06-22 00:33:06 +02:00
|
|
|
if (m_state.gp.pipeline == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (m_flags.test(DxvkContextFlag::GpDirtyDescriptorSet)) {
|
|
|
|
m_gpSet = this->updateShaderDescriptors(
|
|
|
|
VK_PIPELINE_BIND_POINT_GRAPHICS,
|
|
|
|
m_state.gp.pipeline->layout());
|
2017-12-23 15:11:23 +01:00
|
|
|
}
|
2018-06-22 00:33:06 +02:00
|
|
|
|
|
|
|
if (m_flags.test(DxvkContextFlag::GpDirtyDescriptorOffsets)) {
|
|
|
|
this->updateShaderDescriptorSetBinding(
|
|
|
|
VK_PIPELINE_BIND_POINT_GRAPHICS, m_gpSet,
|
|
|
|
m_state.gp.pipeline->layout());
|
|
|
|
}
|
|
|
|
|
|
|
|
m_flags.clr(
|
|
|
|
DxvkContextFlag::GpDirtyDescriptorOffsets,
|
|
|
|
DxvkContextFlag::GpDirtyDescriptorSet);
|
2017-12-23 15:11:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DxvkContext::updateShaderResources(
|
|
|
|
VkPipelineBindPoint bindPoint,
|
2018-09-17 10:40:57 +02:00
|
|
|
DxvkBindingMask& bindMask,
|
2018-06-22 00:33:06 +02:00
|
|
|
const DxvkPipelineLayout* layout) {
|
2018-01-10 11:44:40 +01:00
|
|
|
bool updatePipelineState = false;
|
|
|
|
|
2018-03-09 12:30:39 +01:00
|
|
|
DxvkAttachment depthAttachment;
|
|
|
|
|
|
|
|
if (bindPoint == VK_PIPELINE_BIND_POINT_GRAPHICS && m_state.om.framebuffer != nullptr)
|
2018-04-30 13:12:28 +02:00
|
|
|
depthAttachment = m_state.om.framebuffer->getDepthTarget();
|
2018-03-09 12:30:39 +01:00
|
|
|
|
2017-12-23 15:11:23 +01:00
|
|
|
for (uint32_t i = 0; i < layout->bindingCount(); i++) {
|
2017-12-29 15:06:33 +01:00
|
|
|
const auto& binding = layout->binding(i);
|
|
|
|
const auto& res = m_rc[binding.slot];
|
|
|
|
|
|
|
|
switch (binding.type) {
|
|
|
|
case VK_DESCRIPTOR_TYPE_SAMPLER:
|
2018-01-08 20:23:21 +01:00
|
|
|
if (res.sampler != nullptr) {
|
2018-09-17 10:40:57 +02:00
|
|
|
updatePipelineState |= bindMask.setBound(i);
|
2018-01-10 11:44:40 +01:00
|
|
|
|
2018-02-04 23:59:34 +01:00
|
|
|
m_descInfos[i].image.sampler = res.sampler->handle();
|
|
|
|
m_descInfos[i].image.imageView = VK_NULL_HANDLE;
|
|
|
|
m_descInfos[i].image.imageLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
2018-01-08 20:23:21 +01:00
|
|
|
|
|
|
|
m_cmd->trackResource(res.sampler);
|
|
|
|
} else {
|
2018-09-17 10:40:57 +02:00
|
|
|
updatePipelineState |= bindMask.setUnbound(i);
|
2018-02-04 23:59:34 +01:00
|
|
|
m_descInfos[i].image = m_device->dummySamplerDescriptor();
|
2018-01-08 20:23:21 +01:00
|
|
|
} break;
|
2017-12-19 01:08:48 +01:00
|
|
|
|
2017-12-29 15:06:33 +01:00
|
|
|
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
|
2018-05-24 11:44:04 +02:00
|
|
|
if (res.imageView != nullptr && res.imageView->handle(binding.view) != VK_NULL_HANDLE) {
|
2018-09-17 10:40:57 +02:00
|
|
|
updatePipelineState |= bindMask.setBound(i);
|
2018-01-10 11:44:40 +01:00
|
|
|
|
2018-02-04 23:59:34 +01:00
|
|
|
m_descInfos[i].image.sampler = VK_NULL_HANDLE;
|
2018-05-24 11:44:04 +02:00
|
|
|
m_descInfos[i].image.imageView = res.imageView->handle(binding.view);
|
2018-02-04 23:59:34 +01:00
|
|
|
m_descInfos[i].image.imageLayout = res.imageView->imageInfo().layout;
|
2018-01-08 20:23:21 +01:00
|
|
|
|
2018-03-09 12:30:39 +01:00
|
|
|
if (depthAttachment.view != nullptr
|
|
|
|
&& depthAttachment.view->image() == res.imageView->image())
|
|
|
|
m_descInfos[i].image.imageLayout = depthAttachment.layout;
|
2018-02-06 17:31:23 +01:00
|
|
|
|
2018-01-08 20:23:21 +01:00
|
|
|
m_cmd->trackResource(res.imageView);
|
|
|
|
m_cmd->trackResource(res.imageView->image());
|
|
|
|
} else {
|
2018-09-17 10:40:57 +02:00
|
|
|
updatePipelineState |= bindMask.setUnbound(i);
|
2018-02-04 23:59:34 +01:00
|
|
|
m_descInfos[i].image = m_device->dummyImageViewDescriptor(binding.view);
|
2018-01-08 20:23:21 +01:00
|
|
|
} break;
|
2017-12-29 15:06:33 +01:00
|
|
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
|
2018-01-08 20:23:21 +01:00
|
|
|
if (res.bufferView != nullptr) {
|
2018-09-17 10:40:57 +02:00
|
|
|
updatePipelineState |= bindMask.setBound(i);
|
2018-01-10 11:44:40 +01:00
|
|
|
|
2018-03-07 13:54:28 +01:00
|
|
|
res.bufferView->updateView();
|
2018-02-04 23:59:34 +01:00
|
|
|
m_descInfos[i].texelBuffer = res.bufferView->handle();
|
2018-01-08 20:23:21 +01:00
|
|
|
|
2018-03-07 13:54:28 +01:00
|
|
|
m_cmd->trackResource(res.bufferView->viewResource());
|
|
|
|
m_cmd->trackResource(res.bufferView->bufferResource());
|
2018-01-08 20:23:21 +01:00
|
|
|
} else {
|
2018-09-17 10:40:57 +02:00
|
|
|
updatePipelineState |= bindMask.setUnbound(i);
|
2018-02-04 23:59:34 +01:00
|
|
|
m_descInfos[i].texelBuffer = m_device->dummyBufferViewDescriptor();
|
2018-01-08 20:23:21 +01:00
|
|
|
} break;
|
2017-12-23 15:11:23 +01:00
|
|
|
|
2017-12-29 15:06:33 +01:00
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
|
2018-01-18 18:01:47 +01:00
|
|
|
if (res.bufferSlice.defined()) {
|
2018-09-17 10:40:57 +02:00
|
|
|
updatePipelineState |= bindMask.setBound(i);
|
2018-09-20 12:10:43 +02:00
|
|
|
m_descInfos[i] = res.bufferSlice.getDescriptor(true);
|
2018-01-10 11:44:40 +01:00
|
|
|
|
2018-09-20 12:10:43 +02:00
|
|
|
m_cmd->trackResource(res.bufferSlice.resource());
|
2018-01-08 20:23:21 +01:00
|
|
|
} else {
|
2018-09-17 10:40:57 +02:00
|
|
|
updatePipelineState |= bindMask.setUnbound(i);
|
2018-02-04 23:59:34 +01:00
|
|
|
m_descInfos[i].buffer = m_device->dummyBufferDescriptor();
|
2018-01-08 20:23:21 +01:00
|
|
|
} break;
|
2017-12-23 15:11:23 +01:00
|
|
|
|
2018-06-22 00:33:06 +02:00
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
|
|
|
|
if (res.bufferSlice.defined()) {
|
2018-09-17 10:40:57 +02:00
|
|
|
updatePipelineState |= bindMask.setBound(i);
|
2018-09-20 12:10:43 +02:00
|
|
|
m_descInfos[i] = res.bufferSlice.getDescriptor(false);
|
2018-06-22 00:33:06 +02:00
|
|
|
|
2018-09-20 12:10:43 +02:00
|
|
|
m_cmd->trackResource(res.bufferSlice.resource());
|
2018-06-22 00:33:06 +02:00
|
|
|
} else {
|
2018-09-17 10:40:57 +02:00
|
|
|
updatePipelineState |= bindMask.setUnbound(i);
|
2018-06-22 00:33:06 +02:00
|
|
|
m_descInfos[i].buffer = m_device->dummyBufferDescriptor();
|
|
|
|
} break;
|
|
|
|
|
2017-12-29 15:06:33 +01:00
|
|
|
default:
|
|
|
|
Logger::err(str::format("DxvkContext: Unhandled descriptor type: ", binding.type));
|
2017-12-19 01:08:48 +01:00
|
|
|
}
|
2017-10-15 17:56:06 +02:00
|
|
|
}
|
2018-06-22 00:33:06 +02:00
|
|
|
|
2018-01-10 12:13:46 +01:00
|
|
|
if (updatePipelineState) {
|
|
|
|
m_flags.set(bindPoint == VK_PIPELINE_BIND_POINT_GRAPHICS
|
|
|
|
? DxvkContextFlag::GpDirtyPipelineState
|
|
|
|
: DxvkContextFlag::CpDirtyPipelineState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-22 00:33:06 +02:00
|
|
|
VkDescriptorSet DxvkContext::updateShaderDescriptors(
|
2018-01-10 12:13:46 +01:00
|
|
|
VkPipelineBindPoint bindPoint,
|
2018-06-22 00:33:06 +02:00
|
|
|
const DxvkPipelineLayout* layout) {
|
|
|
|
VkDescriptorSet descriptorSet = VK_NULL_HANDLE;
|
|
|
|
|
2018-03-26 23:13:33 +02:00
|
|
|
if (layout->bindingCount() != 0) {
|
2018-06-22 00:33:06 +02:00
|
|
|
descriptorSet = m_cmd->allocateDescriptorSet(
|
|
|
|
layout->descriptorSetLayout());
|
2018-03-26 23:13:33 +02:00
|
|
|
|
|
|
|
m_cmd->updateDescriptorSetWithTemplate(
|
2018-06-22 00:33:06 +02:00
|
|
|
descriptorSet, layout->descriptorTemplate(),
|
2018-03-26 23:13:33 +02:00
|
|
|
m_descInfos.data());
|
2018-06-22 00:33:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return descriptorSet;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DxvkContext::updateShaderDescriptorSetBinding(
|
|
|
|
VkPipelineBindPoint bindPoint,
|
|
|
|
VkDescriptorSet set,
|
|
|
|
const DxvkPipelineLayout* layout) {
|
|
|
|
if (set != VK_NULL_HANDLE) {
|
|
|
|
for (uint32_t i = 0; i < layout->dynamicBindingCount(); i++) {
|
|
|
|
const auto& binding = layout->dynamicBinding(i);
|
|
|
|
const auto& res = m_rc[binding.slot];
|
|
|
|
|
|
|
|
m_descOffsets[i] = res.bufferSlice.defined()
|
|
|
|
? res.bufferSlice.physicalSlice().offset()
|
|
|
|
: 0;
|
|
|
|
}
|
2018-03-26 23:13:33 +02:00
|
|
|
|
|
|
|
m_cmd->cmdBindDescriptorSet(bindPoint,
|
2018-06-22 00:33:06 +02:00
|
|
|
layout->pipelineLayout(), set,
|
|
|
|
layout->dynamicBindingCount(),
|
|
|
|
m_descOffsets.data());
|
2018-03-26 23:13:33 +02:00
|
|
|
}
|
2017-10-15 17:56:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-13 21:39:56 +02:00
|
|
|
void DxvkContext::updateFramebuffer() {
|
2018-04-26 14:47:55 +02:00
|
|
|
if (m_flags.test(DxvkContextFlag::GpDirtyFramebuffer)) {
|
|
|
|
m_flags.clr(DxvkContextFlag::GpDirtyFramebuffer);
|
|
|
|
|
|
|
|
this->spillRenderPass();
|
|
|
|
|
|
|
|
auto fb = m_device->createFramebuffer(m_state.om.renderTargets);
|
|
|
|
|
2018-04-30 13:12:28 +02:00
|
|
|
m_state.gp.state.msSampleCount = fb->getSampleCount();
|
2018-04-26 14:47:55 +02:00
|
|
|
m_state.om.framebuffer = fb;
|
2018-09-01 16:49:24 +02:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < MaxNumRenderTargets; i++) {
|
|
|
|
Rc<DxvkImageView> attachment = fb->getColorTarget(i).view;
|
|
|
|
|
|
|
|
m_state.gp.state.omComponentMapping[i] = attachment != nullptr
|
|
|
|
? util::invertComponentMapping(attachment->info().swizzle)
|
|
|
|
: VkComponentMapping();
|
|
|
|
}
|
2018-09-10 18:22:09 +02:00
|
|
|
|
2018-04-26 14:47:55 +02:00
|
|
|
m_flags.set(DxvkContextFlag::GpDirtyPipelineState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-21 19:50:57 +01:00
|
|
|
void DxvkContext::updateIndexBufferBinding() {
|
2017-12-01 10:27:33 +01:00
|
|
|
if (m_flags.test(DxvkContextFlag::GpDirtyIndexBuffer)) {
|
|
|
|
m_flags.clr(DxvkContextFlag::GpDirtyIndexBuffer);
|
2017-11-20 13:21:27 +01:00
|
|
|
|
2018-01-18 18:01:47 +01:00
|
|
|
if (m_state.vi.indexBuffer.defined()) {
|
|
|
|
auto physicalSlice = m_state.vi.indexBuffer.physicalSlice();
|
|
|
|
|
2017-11-20 15:35:29 +01:00
|
|
|
m_cmd->cmdBindIndexBuffer(
|
2018-01-18 18:01:47 +01:00
|
|
|
physicalSlice.handle(),
|
|
|
|
physicalSlice.offset(),
|
2017-12-07 14:01:17 +01:00
|
|
|
m_state.vi.indexType);
|
2017-11-20 15:35:29 +01:00
|
|
|
m_cmd->trackResource(
|
2018-01-18 18:01:47 +01:00
|
|
|
physicalSlice.resource());
|
2018-02-01 13:29:57 +01:00
|
|
|
} else {
|
|
|
|
m_cmd->cmdBindIndexBuffer(
|
|
|
|
m_device->dummyBufferHandle(),
|
|
|
|
0, VK_INDEX_TYPE_UINT32);
|
2017-11-20 15:35:29 +01:00
|
|
|
}
|
2017-11-20 13:21:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-21 19:50:57 +01:00
|
|
|
void DxvkContext::updateVertexBufferBindings() {
|
2017-12-01 10:27:33 +01:00
|
|
|
if (m_flags.test(DxvkContextFlag::GpDirtyVertexBuffers)) {
|
|
|
|
m_flags.clr(DxvkContextFlag::GpDirtyVertexBuffers);
|
2017-11-20 13:21:27 +01:00
|
|
|
|
2018-05-09 13:01:52 +02:00
|
|
|
std::array<VkBuffer, MaxNumVertexBindings> buffers;
|
|
|
|
std::array<VkDeviceSize, MaxNumVertexBindings> offsets;
|
|
|
|
|
|
|
|
// Set buffer handles and offsets for active bindings
|
|
|
|
uint32_t bindingCount = 0;
|
|
|
|
uint32_t bindingMask = 0;
|
2018-02-01 13:29:57 +01:00
|
|
|
|
2018-01-10 20:40:10 +01:00
|
|
|
for (uint32_t i = 0; i < m_state.gp.state.ilBindingCount; i++) {
|
2018-01-10 21:53:13 +01:00
|
|
|
const uint32_t binding = m_state.gp.state.ilBindings[i].binding;
|
2018-05-09 13:01:52 +02:00
|
|
|
bindingCount = std::max(bindingCount, binding + 1);
|
2018-01-10 21:53:13 +01:00
|
|
|
|
2018-01-18 18:01:47 +01:00
|
|
|
if (m_state.vi.vertexBuffers[binding].defined()) {
|
|
|
|
auto vbo = m_state.vi.vertexBuffers[binding].physicalSlice();
|
|
|
|
|
2018-05-09 13:01:52 +02:00
|
|
|
buffers[binding] = vbo.handle();
|
|
|
|
offsets[binding] = vbo.offset();
|
2018-02-01 13:29:57 +01:00
|
|
|
|
|
|
|
bindingMask |= 1u << binding;
|
|
|
|
|
2018-05-09 13:01:52 +02:00
|
|
|
m_cmd->trackResource(vbo.resource());
|
2017-11-21 19:50:57 +01:00
|
|
|
}
|
|
|
|
}
|
2018-02-01 13:29:57 +01:00
|
|
|
|
2018-05-09 13:01:52 +02:00
|
|
|
// Bind a dummy buffer to the remaining bindings
|
|
|
|
uint32_t bindingsUsed = (1u << bindingCount) - 1u;
|
|
|
|
uint32_t bindingsSet = bindingMask;
|
|
|
|
|
|
|
|
while (bindingsSet != bindingsUsed) {
|
2018-05-09 20:09:09 +02:00
|
|
|
uint32_t binding = bit::tzcnt(~bindingsSet);
|
2018-05-09 13:01:52 +02:00
|
|
|
|
|
|
|
buffers[binding] = m_device->dummyBufferHandle();
|
|
|
|
offsets[binding] = 0;
|
|
|
|
|
|
|
|
bindingsSet |= 1u << binding;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bind all vertex buffers at once
|
|
|
|
if (bindingCount != 0) {
|
|
|
|
m_cmd->cmdBindVertexBuffers(0, bindingCount,
|
|
|
|
buffers.data(), offsets.data());
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the set of active bindings has changed, we'll
|
|
|
|
// need to adjust the strides of the inactive ones
|
|
|
|
// and compile a new pipeline
|
2018-02-01 13:29:57 +01:00
|
|
|
if (m_state.vi.bindingMask != bindingMask) {
|
|
|
|
m_flags.set(DxvkContextFlag::GpDirtyPipelineState);
|
|
|
|
m_state.vi.bindingMask = bindingMask;
|
|
|
|
}
|
2017-11-20 13:21:27 +01:00
|
|
|
}
|
|
|
|
}
|
2018-05-29 05:03:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
void DxvkContext::updateDynamicState() {
|
|
|
|
if (m_gpActivePipeline == VK_NULL_HANDLE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (m_flags.test(DxvkContextFlag::GpDirtyViewport)) {
|
|
|
|
uint32_t viewportCount = m_state.gp.state.rsViewportCount;
|
|
|
|
m_cmd->cmdSetViewport(0, viewportCount, m_state.vp.viewports.data());
|
|
|
|
m_cmd->cmdSetScissor (0, viewportCount, m_state.vp.scissorRects.data());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_flags.test(DxvkContextFlag::GpDirtyBlendConstants))
|
|
|
|
m_cmd->cmdSetBlendConstants(&m_state.om.blendConstants.r);
|
|
|
|
|
|
|
|
if (m_flags.test(DxvkContextFlag::GpDirtyStencilRef))
|
|
|
|
m_cmd->cmdSetStencilReference(VK_STENCIL_FRONT_AND_BACK, m_state.om.stencilReference);
|
|
|
|
|
2018-06-06 12:45:45 +02:00
|
|
|
if (m_flags.test(DxvkContextFlag::GpDirtyDepthBias)) {
|
|
|
|
m_cmd->cmdSetDepthBias(
|
|
|
|
m_state.ds.depthBiasConstant,
|
|
|
|
m_state.ds.depthBiasClamp,
|
|
|
|
m_state.ds.depthBiasSlope);
|
|
|
|
}
|
|
|
|
|
2018-05-29 05:03:27 +02:00
|
|
|
m_flags.clr(
|
|
|
|
DxvkContextFlag::GpDirtyBlendConstants,
|
|
|
|
DxvkContextFlag::GpDirtyStencilRef,
|
2018-06-06 12:45:45 +02:00
|
|
|
DxvkContextFlag::GpDirtyViewport,
|
|
|
|
DxvkContextFlag::GpDirtyDepthBias);
|
2018-05-29 05:03:27 +02:00
|
|
|
}
|
2017-11-20 13:21:27 +01:00
|
|
|
|
|
|
|
|
2018-02-24 23:56:12 +01:00
|
|
|
bool DxvkContext::validateComputeState() {
|
2018-02-25 00:18:30 +01:00
|
|
|
return m_cpActivePipeline != VK_NULL_HANDLE;
|
2018-02-24 23:56:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DxvkContext::validateGraphicsState() {
|
2018-02-25 00:18:30 +01:00
|
|
|
if (m_gpActivePipeline == VK_NULL_HANDLE)
|
2018-02-24 23:56:12 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!m_flags.test(DxvkContextFlag::GpRenderPassBound))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-23 14:24:00 +01:00
|
|
|
void DxvkContext::commitComputeState() {
|
2018-04-23 11:11:40 +02:00
|
|
|
this->spillRenderPass();
|
2017-12-03 20:23:26 +01:00
|
|
|
this->updateComputePipeline();
|
|
|
|
this->updateComputeShaderResources();
|
2018-02-14 17:54:35 +01:00
|
|
|
this->updateComputePipelineState();
|
2018-01-10 12:13:46 +01:00
|
|
|
this->updateComputeShaderDescriptors();
|
2017-11-23 14:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-20 14:11:09 +01:00
|
|
|
void DxvkContext::commitGraphicsState() {
|
2018-09-13 21:39:56 +02:00
|
|
|
this->updateFramebuffer();
|
2018-04-23 11:11:40 +02:00
|
|
|
this->startRenderPass();
|
2017-12-03 20:23:26 +01:00
|
|
|
this->updateGraphicsPipeline();
|
2017-11-21 19:50:57 +01:00
|
|
|
this->updateIndexBufferBinding();
|
|
|
|
this->updateVertexBufferBindings();
|
2017-12-03 20:23:26 +01:00
|
|
|
this->updateGraphicsShaderResources();
|
2018-01-10 12:13:46 +01:00
|
|
|
this->updateGraphicsPipelineState();
|
|
|
|
this->updateGraphicsShaderDescriptors();
|
2018-05-29 05:03:27 +02:00
|
|
|
this->updateDynamicState();
|
2017-12-03 20:23:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-18 14:35:11 +02:00
|
|
|
void DxvkContext::commitComputeInitBarriers() {
|
|
|
|
auto layout = m_state.cp.pipeline->layout();
|
|
|
|
|
|
|
|
bool requiresBarrier = false;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < layout->bindingCount() && !requiresBarrier; i++) {
|
2018-09-17 10:40:57 +02:00
|
|
|
if (m_state.cp.state.bsBindingMask.isBound(i)) {
|
2018-06-18 14:35:11 +02:00
|
|
|
const DxvkDescriptorSlot binding = layout->binding(i);
|
|
|
|
const DxvkShaderResourceSlot& slot = m_rc[binding.slot];
|
|
|
|
|
|
|
|
DxvkAccessFlags access = DxvkAccess::Read;
|
|
|
|
|
|
|
|
switch (binding.type) {
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
|
2018-06-22 00:33:06 +02:00
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
|
2018-06-18 14:35:11 +02:00
|
|
|
access.set(DxvkAccess::Write);
|
|
|
|
/* fall through */
|
|
|
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
|
2018-06-22 00:33:06 +02:00
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
|
2018-06-18 14:35:11 +02:00
|
|
|
requiresBarrier = m_barriers.isBufferDirty(
|
|
|
|
slot.bufferSlice.physicalSlice(), access);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
|
|
|
|
access.set(DxvkAccess::Write);
|
|
|
|
/* fall through */
|
|
|
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
|
|
|
|
requiresBarrier = m_barriers.isBufferDirty(
|
|
|
|
slot.bufferView->physicalSlice(), access);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
|
|
|
|
access.set(DxvkAccess::Write);
|
|
|
|
/* fall through */
|
|
|
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
|
|
|
|
requiresBarrier = m_barriers.isImageDirty(
|
|
|
|
slot.imageView->image(),
|
|
|
|
slot.imageView->subresources(),
|
|
|
|
access);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* nothing to do */;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (requiresBarrier)
|
|
|
|
m_barriers.recordCommands(m_cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DxvkContext::commitComputePostBarriers() {
|
2017-12-29 01:09:54 +01:00
|
|
|
auto layout = m_state.cp.pipeline->layout();
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < layout->bindingCount(); i++) {
|
2018-09-17 10:40:57 +02:00
|
|
|
if (m_state.cp.state.bsBindingMask.isBound(i)) {
|
2018-02-14 16:18:18 +01:00
|
|
|
const DxvkDescriptorSlot binding = layout->binding(i);
|
|
|
|
const DxvkShaderResourceSlot& slot = m_rc[binding.slot];
|
2018-06-18 14:35:11 +02:00
|
|
|
|
|
|
|
VkPipelineStageFlags stages = VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
|
|
|
|
VkAccessFlags access = VK_ACCESS_SHADER_READ_BIT;
|
|
|
|
|
|
|
|
switch (binding.type) {
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
|
2018-06-22 00:33:06 +02:00
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
|
2018-06-18 14:35:11 +02:00
|
|
|
access |= VK_ACCESS_SHADER_WRITE_BIT;
|
|
|
|
/* fall through */
|
|
|
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
|
2018-06-22 00:33:06 +02:00
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
|
2018-06-18 14:35:11 +02:00
|
|
|
m_barriers.accessBuffer(
|
|
|
|
slot.bufferSlice.physicalSlice(),
|
|
|
|
stages, access,
|
|
|
|
slot.bufferSlice.bufferInfo().stages,
|
|
|
|
slot.bufferSlice.bufferInfo().access);
|
|
|
|
break;
|
2018-02-14 16:18:18 +01:00
|
|
|
|
2018-06-18 14:35:11 +02:00
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
|
|
|
|
access |= VK_ACCESS_SHADER_WRITE_BIT;
|
|
|
|
/* fall through */
|
|
|
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
|
|
|
|
m_barriers.accessBuffer(
|
|
|
|
slot.bufferView->physicalSlice(),
|
|
|
|
stages, access,
|
|
|
|
slot.bufferView->bufferInfo().stages,
|
|
|
|
slot.bufferView->bufferInfo().access);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
|
|
|
|
access |= VK_ACCESS_SHADER_WRITE_BIT;
|
|
|
|
/* fall through */
|
|
|
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
|
|
|
|
m_barriers.accessImage(
|
|
|
|
slot.imageView->image(),
|
|
|
|
slot.imageView->subresources(),
|
|
|
|
slot.imageView->imageInfo().layout,
|
|
|
|
stages, access,
|
|
|
|
slot.imageView->imageInfo().layout,
|
|
|
|
slot.imageView->imageInfo().stages,
|
|
|
|
slot.imageView->imageInfo().access);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* nothing to do */;
|
2018-02-14 16:18:18 +01:00
|
|
|
}
|
2017-12-29 01:09:54 +01:00
|
|
|
}
|
|
|
|
}
|
2017-12-03 20:23:26 +01:00
|
|
|
}
|
|
|
|
|
2017-10-10 23:32:13 +02:00
|
|
|
}
|