[Vulkan] Basic draw call architecture + [D3D12] Some cleanup
This commit is contained in:
@@ -46,15 +46,65 @@ void DeferredCommandBuffer::Execute(VkCommandBuffer command_buffer) {
|
||||
stream_remaining -= kCommandHeaderSizeElements;
|
||||
|
||||
switch (header.command) {
|
||||
case Command::kVkBeginRenderPass: {
|
||||
auto& args = *reinterpret_cast<const ArgsVkBeginRenderPass*>(stream);
|
||||
size_t offset_bytes = sizeof(ArgsVkBeginRenderPass);
|
||||
VkRenderPassBeginInfo render_pass_begin_info;
|
||||
render_pass_begin_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
||||
render_pass_begin_info.pNext = nullptr;
|
||||
render_pass_begin_info.renderPass = args.render_pass;
|
||||
render_pass_begin_info.framebuffer = args.framebuffer;
|
||||
render_pass_begin_info.renderArea = args.render_area;
|
||||
render_pass_begin_info.clearValueCount = args.clear_value_count;
|
||||
if (render_pass_begin_info.clearValueCount) {
|
||||
offset_bytes = xe::align(offset_bytes, alignof(VkClearValue));
|
||||
render_pass_begin_info.pClearValues =
|
||||
reinterpret_cast<const VkClearValue*>(
|
||||
reinterpret_cast<const uint8_t*>(stream) + offset_bytes);
|
||||
offset_bytes +=
|
||||
sizeof(VkClearValue) * render_pass_begin_info.clearValueCount;
|
||||
} else {
|
||||
render_pass_begin_info.pClearValues = nullptr;
|
||||
}
|
||||
dfn.vkCmdBeginRenderPass(command_buffer, &render_pass_begin_info,
|
||||
args.contents);
|
||||
} break;
|
||||
|
||||
case Command::kVkBindDescriptorSets: {
|
||||
auto& args = *reinterpret_cast<const ArgsVkBindDescriptorSets*>(stream);
|
||||
size_t offset_bytes = xe::align(sizeof(ArgsVkBindDescriptorSets),
|
||||
alignof(VkDescriptorSet));
|
||||
const VkDescriptorSet* descriptor_sets =
|
||||
reinterpret_cast<const VkDescriptorSet*>(
|
||||
reinterpret_cast<const uint8_t*>(stream) + offset_bytes);
|
||||
offset_bytes += sizeof(VkDescriptorSet) * args.descriptor_set_count;
|
||||
const uint32_t* dynamic_offsets = nullptr;
|
||||
if (args.dynamic_offset_count) {
|
||||
offset_bytes = xe::align(offset_bytes, alignof(uint32_t));
|
||||
dynamic_offsets = reinterpret_cast<const uint32_t*>(
|
||||
reinterpret_cast<const uint8_t*>(stream) + offset_bytes);
|
||||
offset_bytes += sizeof(uint32_t) * args.dynamic_offset_count;
|
||||
}
|
||||
dfn.vkCmdBindDescriptorSets(command_buffer, args.pipeline_bind_point,
|
||||
args.layout, args.first_set,
|
||||
args.descriptor_set_count, descriptor_sets,
|
||||
args.dynamic_offset_count, dynamic_offsets);
|
||||
} break;
|
||||
|
||||
case Command::kVkBindIndexBuffer: {
|
||||
auto& args = *reinterpret_cast<const ArgsVkBindIndexBuffer*>(stream);
|
||||
dfn.vkCmdBindIndexBuffer(command_buffer, args.buffer, args.offset,
|
||||
args.index_type);
|
||||
} break;
|
||||
|
||||
case Command::kVkBindPipeline: {
|
||||
auto& args = *reinterpret_cast<const ArgsVkBindPipeline*>(stream);
|
||||
dfn.vkCmdBindPipeline(command_buffer, args.pipeline_bind_point,
|
||||
args.pipeline);
|
||||
} break;
|
||||
|
||||
case Command::kVkCopyBuffer: {
|
||||
auto& args = *reinterpret_cast<const ArgsVkCopyBuffer*>(stream);
|
||||
static_assert(alignof(VkBufferCopy) <= alignof(uintmax_t));
|
||||
dfn.vkCmdCopyBuffer(
|
||||
command_buffer, args.src_buffer, args.dst_buffer, args.region_count,
|
||||
reinterpret_cast<const VkBufferCopy*>(
|
||||
@@ -62,26 +112,37 @@ void DeferredCommandBuffer::Execute(VkCommandBuffer command_buffer) {
|
||||
xe::align(sizeof(ArgsVkCopyBuffer), alignof(VkBufferCopy))));
|
||||
} break;
|
||||
|
||||
case Command::kVkDraw: {
|
||||
auto& args = *reinterpret_cast<const ArgsVkDraw*>(stream);
|
||||
dfn.vkCmdDraw(command_buffer, args.vertex_count, args.instance_count,
|
||||
args.first_vertex, args.first_instance);
|
||||
} break;
|
||||
|
||||
case Command::kVkDrawIndexed: {
|
||||
auto& args = *reinterpret_cast<const ArgsVkDrawIndexed*>(stream);
|
||||
dfn.vkCmdDrawIndexed(command_buffer, args.index_count,
|
||||
args.instance_count, args.first_index,
|
||||
args.vertex_offset, args.first_instance);
|
||||
} break;
|
||||
|
||||
case Command::kVkEndRenderPass:
|
||||
dfn.vkCmdEndRenderPass(command_buffer);
|
||||
break;
|
||||
|
||||
case Command::kVkPipelineBarrier: {
|
||||
auto& args = *reinterpret_cast<const ArgsVkPipelineBarrier*>(stream);
|
||||
size_t barrier_offset_bytes = sizeof(ArgsVkPipelineBarrier);
|
||||
|
||||
const VkMemoryBarrier* memory_barriers;
|
||||
const VkMemoryBarrier* memory_barriers = nullptr;
|
||||
if (args.memory_barrier_count) {
|
||||
static_assert(alignof(VkMemoryBarrier) <= alignof(uintmax_t));
|
||||
barrier_offset_bytes =
|
||||
xe::align(barrier_offset_bytes, alignof(VkMemoryBarrier));
|
||||
memory_barriers = reinterpret_cast<const VkMemoryBarrier*>(
|
||||
reinterpret_cast<const uint8_t*>(stream) + barrier_offset_bytes);
|
||||
barrier_offset_bytes +=
|
||||
sizeof(VkMemoryBarrier) * args.memory_barrier_count;
|
||||
} else {
|
||||
memory_barriers = nullptr;
|
||||
}
|
||||
|
||||
const VkBufferMemoryBarrier* buffer_memory_barriers;
|
||||
const VkBufferMemoryBarrier* buffer_memory_barriers = nullptr;
|
||||
if (args.buffer_memory_barrier_count) {
|
||||
static_assert(alignof(VkBufferMemoryBarrier) <= alignof(uintmax_t));
|
||||
barrier_offset_bytes =
|
||||
xe::align(barrier_offset_bytes, alignof(VkBufferMemoryBarrier));
|
||||
buffer_memory_barriers =
|
||||
@@ -90,23 +151,16 @@ void DeferredCommandBuffer::Execute(VkCommandBuffer command_buffer) {
|
||||
barrier_offset_bytes);
|
||||
barrier_offset_bytes +=
|
||||
sizeof(VkBufferMemoryBarrier) * args.buffer_memory_barrier_count;
|
||||
} else {
|
||||
buffer_memory_barriers = nullptr;
|
||||
}
|
||||
|
||||
const VkImageMemoryBarrier* image_memory_barriers;
|
||||
const VkImageMemoryBarrier* image_memory_barriers = nullptr;
|
||||
if (args.image_memory_barrier_count) {
|
||||
static_assert(alignof(VkImageMemoryBarrier) <= alignof(uintmax_t));
|
||||
barrier_offset_bytes =
|
||||
xe::align(barrier_offset_bytes, alignof(VkImageMemoryBarrier));
|
||||
image_memory_barriers = reinterpret_cast<const VkImageMemoryBarrier*>(
|
||||
reinterpret_cast<const uint8_t*>(stream) + barrier_offset_bytes);
|
||||
barrier_offset_bytes +=
|
||||
sizeof(VkImageMemoryBarrier) * args.image_memory_barrier_count;
|
||||
} else {
|
||||
image_memory_barriers = nullptr;
|
||||
}
|
||||
|
||||
dfn.vkCmdPipelineBarrier(
|
||||
command_buffer, args.src_stage_mask, args.dst_stage_mask,
|
||||
args.dependency_flags, args.memory_barrier_count, memory_barriers,
|
||||
@@ -114,6 +168,24 @@ void DeferredCommandBuffer::Execute(VkCommandBuffer command_buffer) {
|
||||
args.image_memory_barrier_count, image_memory_barriers);
|
||||
} break;
|
||||
|
||||
case Command::kVkSetScissor: {
|
||||
auto& args = *reinterpret_cast<const ArgsVkSetScissor*>(stream);
|
||||
dfn.vkCmdSetScissor(
|
||||
command_buffer, args.first_scissor, args.scissor_count,
|
||||
reinterpret_cast<const VkRect2D*>(
|
||||
reinterpret_cast<const uint8_t*>(stream) +
|
||||
xe::align(sizeof(ArgsVkSetScissor), alignof(VkRect2D))));
|
||||
} break;
|
||||
|
||||
case Command::kVkSetViewport: {
|
||||
auto& args = *reinterpret_cast<const ArgsVkSetViewport*>(stream);
|
||||
dfn.vkCmdSetViewport(
|
||||
command_buffer, args.first_viewport, args.viewport_count,
|
||||
reinterpret_cast<const VkViewport*>(
|
||||
reinterpret_cast<const uint8_t*>(stream) +
|
||||
xe::align(sizeof(ArgsVkSetViewport), alignof(VkViewport))));
|
||||
} break;
|
||||
|
||||
default:
|
||||
assert_unhandled_case(header.command);
|
||||
break;
|
||||
@@ -133,38 +205,25 @@ void DeferredCommandBuffer::CmdVkPipelineBarrier(
|
||||
uint32_t image_memory_barrier_count,
|
||||
const VkImageMemoryBarrier* image_memory_barriers) {
|
||||
size_t arguments_size = sizeof(ArgsVkPipelineBarrier);
|
||||
|
||||
size_t memory_barriers_offset;
|
||||
size_t memory_barriers_offset = 0;
|
||||
if (memory_barrier_count) {
|
||||
static_assert(alignof(VkMemoryBarrier) <= alignof(uintmax_t));
|
||||
arguments_size = xe::align(arguments_size, alignof(VkMemoryBarrier));
|
||||
memory_barriers_offset = arguments_size;
|
||||
arguments_size += sizeof(VkMemoryBarrier) * memory_barrier_count;
|
||||
} else {
|
||||
memory_barriers_offset = 0;
|
||||
}
|
||||
|
||||
size_t buffer_memory_barriers_offset;
|
||||
size_t buffer_memory_barriers_offset = 0;
|
||||
if (buffer_memory_barrier_count) {
|
||||
static_assert(alignof(VkBufferMemoryBarrier) <= alignof(uintmax_t));
|
||||
arguments_size = xe::align(arguments_size, alignof(VkBufferMemoryBarrier));
|
||||
buffer_memory_barriers_offset = arguments_size;
|
||||
arguments_size +=
|
||||
sizeof(VkBufferMemoryBarrier) * buffer_memory_barrier_count;
|
||||
} else {
|
||||
buffer_memory_barriers_offset = 0;
|
||||
}
|
||||
|
||||
size_t image_memory_barriers_offset;
|
||||
size_t image_memory_barriers_offset = 0;
|
||||
if (image_memory_barrier_count) {
|
||||
static_assert(alignof(VkImageMemoryBarrier) <= alignof(uintmax_t));
|
||||
arguments_size = xe::align(arguments_size, alignof(VkImageMemoryBarrier));
|
||||
image_memory_barriers_offset = arguments_size;
|
||||
arguments_size += sizeof(VkImageMemoryBarrier) * image_memory_barrier_count;
|
||||
} else {
|
||||
image_memory_barriers_offset = 0;
|
||||
}
|
||||
|
||||
uint8_t* args_ptr = reinterpret_cast<uint8_t*>(
|
||||
WriteCommand(Command::kVkPipelineBarrier, arguments_size));
|
||||
auto& args = *reinterpret_cast<ArgsVkPipelineBarrier*>(args_ptr);
|
||||
|
||||
Reference in New Issue
Block a user