forked from ShuriZma/suyu
1
0
Fork 0

vk_rasterizer: Make use of designated initializers where applicable

This commit is contained in:
Lioncash 2020-07-16 18:49:42 -04:00
parent c07b0ffe47
commit 01f297f2e0
1 changed files with 48 additions and 42 deletions

View File

@ -64,20 +64,22 @@ VkViewport GetViewportState(const VKDevice& device, const Maxwell& regs, std::si
const auto& src = regs.viewport_transform[index]; const auto& src = regs.viewport_transform[index];
const float width = src.scale_x * 2.0f; const float width = src.scale_x * 2.0f;
const float height = src.scale_y * 2.0f; const float height = src.scale_y * 2.0f;
VkViewport viewport;
viewport.x = src.translate_x - src.scale_x;
viewport.y = src.translate_y - src.scale_y;
viewport.width = width != 0.0f ? width : 1.0f;
viewport.height = height != 0.0f ? height : 1.0f;
const float reduce_z = regs.depth_mode == Maxwell::DepthMode::MinusOneToOne ? 1.0f : 0.0f; const float reduce_z = regs.depth_mode == Maxwell::DepthMode::MinusOneToOne ? 1.0f : 0.0f;
viewport.minDepth = src.translate_z - src.scale_z * reduce_z;
viewport.maxDepth = src.translate_z + src.scale_z; VkViewport viewport{
.x = src.translate_x - src.scale_x,
.y = src.translate_y - src.scale_y,
.width = width != 0.0f ? width : 1.0f,
.height = height != 0.0f ? height : 1.0f,
.minDepth = src.translate_z - src.scale_z * reduce_z,
.maxDepth = src.translate_z + src.scale_z,
};
if (!device.IsExtDepthRangeUnrestrictedSupported()) { if (!device.IsExtDepthRangeUnrestrictedSupported()) {
viewport.minDepth = std::clamp(viewport.minDepth, 0.0f, 1.0f); viewport.minDepth = std::clamp(viewport.minDepth, 0.0f, 1.0f);
viewport.maxDepth = std::clamp(viewport.maxDepth, 0.0f, 1.0f); viewport.maxDepth = std::clamp(viewport.maxDepth, 0.0f, 1.0f);
} }
return viewport; return viewport;
} }
@ -508,10 +510,11 @@ void RasterizerVulkan::Clear() {
const u32 color_attachment = regs.clear_buffers.RT; const u32 color_attachment = regs.clear_buffers.RT;
scheduler.Record([color_attachment, clear_value, clear_rect](vk::CommandBuffer cmdbuf) { scheduler.Record([color_attachment, clear_value, clear_rect](vk::CommandBuffer cmdbuf) {
VkClearAttachment attachment; const VkClearAttachment attachment{
attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
attachment.colorAttachment = color_attachment; .colorAttachment = color_attachment,
attachment.clearValue = clear_value; .clearValue = clear_value,
};
cmdbuf.ClearAttachments(attachment, clear_rect); cmdbuf.ClearAttachments(attachment, clear_rect);
}); });
} }
@ -551,13 +554,16 @@ void RasterizerVulkan::DispatchCompute(GPUVAddr code_addr) {
query_cache.UpdateCounters(); query_cache.UpdateCounters();
const auto& launch_desc = system.GPU().KeplerCompute().launch_description; const auto& launch_desc = system.GPU().KeplerCompute().launch_description;
ComputePipelineCacheKey key; auto& pipeline = pipeline_cache.GetComputePipeline({
key.shader = code_addr; .shader = code_addr,
key.shared_memory_size = launch_desc.shared_alloc; .shared_memory_size = launch_desc.shared_alloc,
key.workgroup_size = {launch_desc.block_dim_x, launch_desc.block_dim_y, .workgroup_size =
launch_desc.block_dim_z}; {
launch_desc.block_dim_x,
auto& pipeline = pipeline_cache.GetComputePipeline(key); launch_desc.block_dim_y,
launch_desc.block_dim_z,
},
});
// Compute dispatches can't be executed inside a renderpass // Compute dispatches can't be executed inside a renderpass
scheduler.RequestOutsideRenderPassOperationContext(); scheduler.RequestOutsideRenderPassOperationContext();
@ -841,17 +847,17 @@ std::tuple<VkFramebuffer, VkExtent2D> RasterizerVulkan::ConfigureFramebuffers(
const auto [fbentry, is_cache_miss] = framebuffer_cache.try_emplace(key); const auto [fbentry, is_cache_miss] = framebuffer_cache.try_emplace(key);
auto& framebuffer = fbentry->second; auto& framebuffer = fbentry->second;
if (is_cache_miss) { if (is_cache_miss) {
VkFramebufferCreateInfo framebuffer_ci; framebuffer = device.GetLogical().CreateFramebuffer({
framebuffer_ci.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; .sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
framebuffer_ci.pNext = nullptr; .pNext = nullptr,
framebuffer_ci.flags = 0; .flags = 0,
framebuffer_ci.renderPass = key.renderpass; .renderPass = key.renderpass,
framebuffer_ci.attachmentCount = static_cast<u32>(key.views.size()); .attachmentCount = static_cast<u32>(key.views.size()),
framebuffer_ci.pAttachments = key.views.data(); .pAttachments = key.views.data(),
framebuffer_ci.width = key.width; .width = key.width,
framebuffer_ci.height = key.height; .height = key.height,
framebuffer_ci.layers = key.layers; .layers = key.layers,
framebuffer = device.GetLogical().CreateFramebuffer(framebuffer_ci); });
} }
return {*framebuffer, VkExtent2D{key.width, key.height}}; return {*framebuffer, VkExtent2D{key.width, key.height}};
@ -1553,17 +1559,17 @@ VkBuffer RasterizerVulkan::DefaultBuffer() {
return *default_buffer; return *default_buffer;
} }
VkBufferCreateInfo ci; default_buffer = device.GetLogical().CreateBuffer({
ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
ci.pNext = nullptr; .pNext = nullptr,
ci.flags = 0; .flags = 0,
ci.size = DEFAULT_BUFFER_SIZE; .size = DEFAULT_BUFFER_SIZE,
ci.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | .usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT |
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
ci.queueFamilyIndexCount = 0; .queueFamilyIndexCount = 0,
ci.pQueueFamilyIndices = nullptr; .pQueueFamilyIndices = nullptr,
default_buffer = device.GetLogical().CreateBuffer(ci); });
default_buffer_commit = memory_manager.Commit(default_buffer, false); default_buffer_commit = memory_manager.Commit(default_buffer, false);
scheduler.RequestOutsideRenderPassOperationContext(); scheduler.RequestOutsideRenderPassOperationContext();