summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_vulkan/vk_blit_screen.cpp718
1 files changed, 384 insertions, 334 deletions
diff --git a/src/video_core/renderer_vulkan/vk_blit_screen.cpp b/src/video_core/renderer_vulkan/vk_blit_screen.cpp
index fbd406f2b..866813465 100644
--- a/src/video_core/renderer_vulkan/vk_blit_screen.cpp
+++ b/src/video_core/renderer_vulkan/vk_blit_screen.cpp
@@ -141,24 +141,28 @@ struct ScreenRectVertex {
141 std::array<f32, 2> tex_coord; 141 std::array<f32, 2> tex_coord;
142 142
143 static VkVertexInputBindingDescription GetDescription() { 143 static VkVertexInputBindingDescription GetDescription() {
144 VkVertexInputBindingDescription description; 144 return {
145 description.binding = 0; 145 .binding = 0,
146 description.stride = sizeof(ScreenRectVertex); 146 .stride = sizeof(ScreenRectVertex),
147 description.inputRate = VK_VERTEX_INPUT_RATE_VERTEX; 147 .inputRate = VK_VERTEX_INPUT_RATE_VERTEX,
148 return description; 148 };
149 } 149 }
150 150
151 static std::array<VkVertexInputAttributeDescription, 2> GetAttributes() { 151 static std::array<VkVertexInputAttributeDescription, 2> GetAttributes() {
152 std::array<VkVertexInputAttributeDescription, 2> attributes; 152 return {{
153 attributes[0].location = 0; 153 {
154 attributes[0].binding = 0; 154 .location = 0,
155 attributes[0].format = VK_FORMAT_R32G32_SFLOAT; 155 .binding = 0,
156 attributes[0].offset = offsetof(ScreenRectVertex, position); 156 .format = VK_FORMAT_R32G32_SFLOAT,
157 attributes[1].location = 1; 157 .offset = offsetof(ScreenRectVertex, position),
158 attributes[1].binding = 0; 158 },
159 attributes[1].format = VK_FORMAT_R32G32_SFLOAT; 159 {
160 attributes[1].offset = offsetof(ScreenRectVertex, tex_coord); 160 .location = 1,
161 return attributes; 161 .binding = 0,
162 .format = VK_FORMAT_R32G32_SFLOAT,
163 .offset = offsetof(ScreenRectVertex, tex_coord),
164 },
165 }};
162 } 166 }
163}; 167};
164 168
@@ -267,20 +271,25 @@ std::tuple<VKFence&, VkSemaphore> VKBlitScreen::Draw(const Tegra::FramebufferCon
267 blit_image->Transition(0, 1, 0, 1, VK_PIPELINE_STAGE_TRANSFER_BIT, 271 blit_image->Transition(0, 1, 0, 1, VK_PIPELINE_STAGE_TRANSFER_BIT,
268 VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); 272 VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
269 273
270 VkBufferImageCopy copy; 274 const VkBufferImageCopy copy{
271 copy.bufferOffset = image_offset; 275 .bufferOffset = image_offset,
272 copy.bufferRowLength = 0; 276 .bufferRowLength = 0,
273 copy.bufferImageHeight = 0; 277 .bufferImageHeight = 0,
274 copy.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; 278 .imageSubresource =
275 copy.imageSubresource.mipLevel = 0; 279 {
276 copy.imageSubresource.baseArrayLayer = 0; 280 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
277 copy.imageSubresource.layerCount = 1; 281 .mipLevel = 0,
278 copy.imageOffset.x = 0; 282 .baseArrayLayer = 0,
279 copy.imageOffset.y = 0; 283 .layerCount = 1,
280 copy.imageOffset.z = 0; 284 },
281 copy.imageExtent.width = framebuffer.width; 285 .imageOffset = {.x = 0, .y = 0, .z = 0},
282 copy.imageExtent.height = framebuffer.height; 286 .imageExtent =
283 copy.imageExtent.depth = 1; 287 {
288 .width = framebuffer.width,
289 .height = framebuffer.height,
290 .depth = 1,
291 },
292 };
284 scheduler.Record( 293 scheduler.Record(
285 [buffer = *buffer, image = *blit_image->GetHandle(), copy](vk::CommandBuffer cmdbuf) { 294 [buffer = *buffer, image = *blit_image->GetHandle(), copy](vk::CommandBuffer cmdbuf) {
286 cmdbuf.CopyBufferToImage(buffer, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, copy); 295 cmdbuf.CopyBufferToImage(buffer, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, copy);
@@ -295,11 +304,9 @@ std::tuple<VKFence&, VkSemaphore> VKBlitScreen::Draw(const Tegra::FramebufferCon
295 descriptor_set = descriptor_sets[image_index], buffer = *buffer, 304 descriptor_set = descriptor_sets[image_index], buffer = *buffer,
296 size = swapchain.GetSize(), pipeline = *pipeline, 305 size = swapchain.GetSize(), pipeline = *pipeline,
297 layout = *pipeline_layout](vk::CommandBuffer cmdbuf) { 306 layout = *pipeline_layout](vk::CommandBuffer cmdbuf) {
298 VkClearValue clear_color; 307 const VkClearValue clear_color{
299 clear_color.color.float32[0] = 0.0f; 308 .color = {.float32 = {0.0f, 0.0f, 0.0f, 0.0f}},
300 clear_color.color.float32[1] = 0.0f; 309 };
301 clear_color.color.float32[2] = 0.0f;
302 clear_color.color.float32[3] = 0.0f;
303 310
304 VkRenderPassBeginInfo renderpass_bi; 311 VkRenderPassBeginInfo renderpass_bi;
305 renderpass_bi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; 312 renderpass_bi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
@@ -379,93 +386,109 @@ void VKBlitScreen::CreateSemaphores() {
379} 386}
380 387
381void VKBlitScreen::CreateDescriptorPool() { 388void VKBlitScreen::CreateDescriptorPool() {
382 std::array<VkDescriptorPoolSize, 2> pool_sizes; 389 const std::array<VkDescriptorPoolSize, 2> pool_sizes{{
383 pool_sizes[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; 390 {
384 pool_sizes[0].descriptorCount = static_cast<u32>(image_count); 391 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
385 pool_sizes[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; 392 .descriptorCount = static_cast<u32>(image_count),
386 pool_sizes[1].descriptorCount = static_cast<u32>(image_count); 393 },
387 394 {
388 VkDescriptorPoolCreateInfo ci; 395 .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
389 ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; 396 .descriptorCount = static_cast<u32>(image_count),
390 ci.pNext = nullptr; 397 },
391 ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT; 398 }};
392 ci.maxSets = static_cast<u32>(image_count); 399
393 ci.poolSizeCount = static_cast<u32>(pool_sizes.size()); 400 const VkDescriptorPoolCreateInfo ci{
394 ci.pPoolSizes = pool_sizes.data(); 401 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
402 .pNext = nullptr,
403 .flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT,
404 .maxSets = static_cast<u32>(image_count),
405 .poolSizeCount = static_cast<u32>(pool_sizes.size()),
406 .pPoolSizes = pool_sizes.data(),
407 };
395 descriptor_pool = device.GetLogical().CreateDescriptorPool(ci); 408 descriptor_pool = device.GetLogical().CreateDescriptorPool(ci);
396} 409}
397 410
398void VKBlitScreen::CreateRenderPass() { 411void VKBlitScreen::CreateRenderPass() {
399 VkAttachmentDescription color_attachment; 412 const VkAttachmentDescription color_attachment{
400 color_attachment.flags = 0; 413 .flags = 0,
401 color_attachment.format = swapchain.GetImageFormat(); 414 .format = swapchain.GetImageFormat(),
402 color_attachment.samples = VK_SAMPLE_COUNT_1_BIT; 415 .samples = VK_SAMPLE_COUNT_1_BIT,
403 color_attachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; 416 .loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
404 color_attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE; 417 .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
405 color_attachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; 418 .stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE,
406 color_attachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; 419 .stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE,
407 color_attachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; 420 .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
408 color_attachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; 421 .finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
409 422 };
410 VkAttachmentReference color_attachment_ref; 423
411 color_attachment_ref.attachment = 0; 424 const VkAttachmentReference color_attachment_ref{
412 color_attachment_ref.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; 425 .attachment = 0,
413 426 .layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
414 VkSubpassDescription subpass_description; 427 };
415 subpass_description.flags = 0; 428
416 subpass_description.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; 429 const VkSubpassDescription subpass_description{
417 subpass_description.inputAttachmentCount = 0; 430 .flags = 0,
418 subpass_description.pInputAttachments = nullptr; 431 .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
419 subpass_description.colorAttachmentCount = 1; 432 .inputAttachmentCount = 0,
420 subpass_description.pColorAttachments = &color_attachment_ref; 433 .pInputAttachments = nullptr,
421 subpass_description.pResolveAttachments = nullptr; 434 .colorAttachmentCount = 1,
422 subpass_description.pDepthStencilAttachment = nullptr; 435 .pColorAttachments = &color_attachment_ref,
423 subpass_description.preserveAttachmentCount = 0; 436 .pResolveAttachments = nullptr,
424 subpass_description.pPreserveAttachments = nullptr; 437 .pDepthStencilAttachment = nullptr,
425 438 .preserveAttachmentCount = 0,
426 VkSubpassDependency dependency; 439 .pPreserveAttachments = nullptr,
427 dependency.srcSubpass = VK_SUBPASS_EXTERNAL; 440 };
428 dependency.dstSubpass = 0; 441
429 dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; 442 const VkSubpassDependency dependency{
430 dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; 443 .srcSubpass = VK_SUBPASS_EXTERNAL,
431 dependency.srcAccessMask = 0; 444 .dstSubpass = 0,
432 dependency.dstAccessMask = 445 .srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
433 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; 446 .dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
434 dependency.dependencyFlags = 0; 447 .srcAccessMask = 0,
435 448 .dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
436 VkRenderPassCreateInfo renderpass_ci; 449 .dependencyFlags = 0,
437 renderpass_ci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; 450 };
438 renderpass_ci.pNext = nullptr; 451
439 renderpass_ci.flags = 0; 452 const VkRenderPassCreateInfo renderpass_ci{
440 renderpass_ci.attachmentCount = 1; 453 .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
441 renderpass_ci.pAttachments = &color_attachment; 454 .pNext = nullptr,
442 renderpass_ci.subpassCount = 1; 455 .flags = 0,
443 renderpass_ci.pSubpasses = &subpass_description; 456 .attachmentCount = 1,
444 renderpass_ci.dependencyCount = 1; 457 .pAttachments = &color_attachment,
445 renderpass_ci.pDependencies = &dependency; 458 .subpassCount = 1,
459 .pSubpasses = &subpass_description,
460 .dependencyCount = 1,
461 .pDependencies = &dependency,
462 };
446 463
447 renderpass = device.GetLogical().CreateRenderPass(renderpass_ci); 464 renderpass = device.GetLogical().CreateRenderPass(renderpass_ci);
448} 465}
449 466
450void VKBlitScreen::CreateDescriptorSetLayout() { 467void VKBlitScreen::CreateDescriptorSetLayout() {
451 std::array<VkDescriptorSetLayoutBinding, 2> layout_bindings; 468 const std::array<VkDescriptorSetLayoutBinding, 2> layout_bindings{{
452 layout_bindings[0].binding = 0; 469 {
453 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; 470 .binding = 0,
454 layout_bindings[0].descriptorCount = 1; 471 .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
455 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; 472 .descriptorCount = 1,
456 layout_bindings[0].pImmutableSamplers = nullptr; 473 .stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
457 layout_bindings[1].binding = 1; 474 .pImmutableSamplers = nullptr,
458 layout_bindings[1].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; 475 },
459 layout_bindings[1].descriptorCount = 1; 476 {
460 layout_bindings[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; 477 .binding = 1,
461 layout_bindings[1].pImmutableSamplers = nullptr; 478 .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
462 479 .descriptorCount = 1,
463 VkDescriptorSetLayoutCreateInfo ci; 480 .stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT,
464 ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; 481 .pImmutableSamplers = nullptr,
465 ci.pNext = nullptr; 482 },
466 ci.flags = 0; 483 }};
467 ci.bindingCount = static_cast<u32>(layout_bindings.size()); 484
468 ci.pBindings = layout_bindings.data(); 485 const VkDescriptorSetLayoutCreateInfo ci{
486 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
487 .pNext = nullptr,
488 .flags = 0,
489 .bindingCount = static_cast<u32>(layout_bindings.size()),
490 .pBindings = layout_bindings.data(),
491 };
469 492
470 descriptor_set_layout = device.GetLogical().CreateDescriptorSetLayout(ci); 493 descriptor_set_layout = device.GetLogical().CreateDescriptorSetLayout(ci);
471} 494}
@@ -473,175 +496,192 @@ void VKBlitScreen::CreateDescriptorSetLayout() {
473void VKBlitScreen::CreateDescriptorSets() { 496void VKBlitScreen::CreateDescriptorSets() {
474 const std::vector layouts(image_count, *descriptor_set_layout); 497 const std::vector layouts(image_count, *descriptor_set_layout);
475 498
476 VkDescriptorSetAllocateInfo ai; 499 const VkDescriptorSetAllocateInfo ai{
477 ai.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; 500 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
478 ai.pNext = nullptr; 501 .pNext = nullptr,
479 ai.descriptorPool = *descriptor_pool; 502 .descriptorPool = *descriptor_pool,
480 ai.descriptorSetCount = static_cast<u32>(image_count); 503 .descriptorSetCount = static_cast<u32>(image_count),
481 ai.pSetLayouts = layouts.data(); 504 .pSetLayouts = layouts.data(),
505 };
506
482 descriptor_sets = descriptor_pool.Allocate(ai); 507 descriptor_sets = descriptor_pool.Allocate(ai);
483} 508}
484 509
485void VKBlitScreen::CreatePipelineLayout() { 510void VKBlitScreen::CreatePipelineLayout() {
486 VkPipelineLayoutCreateInfo ci; 511 const VkPipelineLayoutCreateInfo ci{
487 ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; 512 .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
488 ci.pNext = nullptr; 513 .pNext = nullptr,
489 ci.flags = 0; 514 .flags = 0,
490 ci.setLayoutCount = 1; 515 .setLayoutCount = 1,
491 ci.pSetLayouts = descriptor_set_layout.address(); 516 .pSetLayouts = descriptor_set_layout.address(),
492 ci.pushConstantRangeCount = 0; 517 .pushConstantRangeCount = 0,
493 ci.pPushConstantRanges = nullptr; 518 .pPushConstantRanges = nullptr,
519 };
494 pipeline_layout = device.GetLogical().CreatePipelineLayout(ci); 520 pipeline_layout = device.GetLogical().CreatePipelineLayout(ci);
495} 521}
496 522
497void VKBlitScreen::CreateGraphicsPipeline() { 523void VKBlitScreen::CreateGraphicsPipeline() {
498 std::array<VkPipelineShaderStageCreateInfo, 2> shader_stages; 524 const std::array<VkPipelineShaderStageCreateInfo, 2> shader_stages{{
499 shader_stages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; 525 {
500 shader_stages[0].pNext = nullptr; 526 .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
501 shader_stages[0].flags = 0; 527 .pNext = nullptr,
502 shader_stages[0].stage = VK_SHADER_STAGE_VERTEX_BIT; 528 .flags = 0,
503 shader_stages[0].module = *vertex_shader; 529 .stage = VK_SHADER_STAGE_VERTEX_BIT,
504 shader_stages[0].pName = "main"; 530 .module = *vertex_shader,
505 shader_stages[0].pSpecializationInfo = nullptr; 531 .pName = "main",
506 shader_stages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; 532 .pSpecializationInfo = nullptr,
507 shader_stages[1].pNext = nullptr; 533 },
508 shader_stages[1].flags = 0; 534 {
509 shader_stages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; 535 .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
510 shader_stages[1].module = *fragment_shader; 536 .pNext = nullptr,
511 shader_stages[1].pName = "main"; 537 .flags = 0,
512 shader_stages[1].pSpecializationInfo = nullptr; 538 .stage = VK_SHADER_STAGE_FRAGMENT_BIT,
539 .module = *fragment_shader,
540 .pName = "main",
541 .pSpecializationInfo = nullptr,
542 },
543 }};
513 544
514 const auto vertex_binding_description = ScreenRectVertex::GetDescription(); 545 const auto vertex_binding_description = ScreenRectVertex::GetDescription();
515 const auto vertex_attrs_description = ScreenRectVertex::GetAttributes(); 546 const auto vertex_attrs_description = ScreenRectVertex::GetAttributes();
516 547
517 VkPipelineVertexInputStateCreateInfo vertex_input_ci; 548 const VkPipelineVertexInputStateCreateInfo vertex_input_ci{
518 vertex_input_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; 549 .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
519 vertex_input_ci.pNext = nullptr; 550 .pNext = nullptr,
520 vertex_input_ci.flags = 0; 551 .flags = 0,
521 vertex_input_ci.vertexBindingDescriptionCount = 1; 552 .vertexBindingDescriptionCount = 1,
522 vertex_input_ci.pVertexBindingDescriptions = &vertex_binding_description; 553 .pVertexBindingDescriptions = &vertex_binding_description,
523 vertex_input_ci.vertexAttributeDescriptionCount = u32{vertex_attrs_description.size()}; 554 .vertexAttributeDescriptionCount = u32{vertex_attrs_description.size()},
524 vertex_input_ci.pVertexAttributeDescriptions = vertex_attrs_description.data(); 555 .pVertexAttributeDescriptions = vertex_attrs_description.data(),
525 556 };
526 VkPipelineInputAssemblyStateCreateInfo input_assembly_ci; 557
527 input_assembly_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; 558 const VkPipelineInputAssemblyStateCreateInfo input_assembly_ci{
528 input_assembly_ci.pNext = nullptr; 559 .sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
529 input_assembly_ci.flags = 0; 560 .pNext = nullptr,
530 input_assembly_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; 561 .flags = 0,
531 input_assembly_ci.primitiveRestartEnable = VK_FALSE; 562 .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,
532 563 .primitiveRestartEnable = VK_FALSE,
533 VkPipelineViewportStateCreateInfo viewport_state_ci; 564 };
534 viewport_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; 565
535 viewport_state_ci.pNext = nullptr; 566 const VkPipelineViewportStateCreateInfo viewport_state_ci{
536 viewport_state_ci.flags = 0; 567 .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
537 viewport_state_ci.viewportCount = 1; 568 .pNext = nullptr,
538 viewport_state_ci.pViewports = nullptr; 569 .flags = 0,
539 viewport_state_ci.scissorCount = 1; 570 .viewportCount = 1,
540 viewport_state_ci.pScissors = nullptr; 571 .pViewports = nullptr,
541 572 .scissorCount = 1,
542 VkPipelineRasterizationStateCreateInfo rasterization_ci; 573 .pScissors = nullptr,
543 rasterization_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; 574 };
544 rasterization_ci.pNext = nullptr; 575
545 rasterization_ci.flags = 0; 576 const VkPipelineRasterizationStateCreateInfo rasterization_ci{
546 rasterization_ci.depthClampEnable = VK_FALSE; 577 .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
547 rasterization_ci.rasterizerDiscardEnable = VK_FALSE; 578 .pNext = nullptr,
548 rasterization_ci.polygonMode = VK_POLYGON_MODE_FILL; 579 .flags = 0,
549 rasterization_ci.cullMode = VK_CULL_MODE_NONE; 580 .depthClampEnable = VK_FALSE,
550 rasterization_ci.frontFace = VK_FRONT_FACE_CLOCKWISE; 581 .rasterizerDiscardEnable = VK_FALSE,
551 rasterization_ci.depthBiasEnable = VK_FALSE; 582 .polygonMode = VK_POLYGON_MODE_FILL,
552 rasterization_ci.depthBiasConstantFactor = 0.0f; 583 .cullMode = VK_CULL_MODE_NONE,
553 rasterization_ci.depthBiasClamp = 0.0f; 584 .frontFace = VK_FRONT_FACE_CLOCKWISE,
554 rasterization_ci.depthBiasSlopeFactor = 0.0f; 585 .depthBiasEnable = VK_FALSE,
555 rasterization_ci.lineWidth = 1.0f; 586 .depthBiasConstantFactor = 0.0f,
556 587 .depthBiasClamp = 0.0f,
557 VkPipelineMultisampleStateCreateInfo multisampling_ci; 588 .depthBiasSlopeFactor = 0.0f,
558 multisampling_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; 589 .lineWidth = 1.0f,
559 multisampling_ci.pNext = nullptr; 590 };
560 multisampling_ci.flags = 0; 591
561 multisampling_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; 592 const VkPipelineMultisampleStateCreateInfo multisampling_ci{
562 multisampling_ci.sampleShadingEnable = VK_FALSE; 593 .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
563 multisampling_ci.minSampleShading = 0.0f; 594 .pNext = nullptr,
564 multisampling_ci.pSampleMask = nullptr; 595 .flags = 0,
565 multisampling_ci.alphaToCoverageEnable = VK_FALSE; 596 .rasterizationSamples = VK_SAMPLE_COUNT_1_BIT,
566 multisampling_ci.alphaToOneEnable = VK_FALSE; 597 .sampleShadingEnable = VK_FALSE,
567 598 .minSampleShading = 0.0f,
568 VkPipelineColorBlendAttachmentState color_blend_attachment; 599 .pSampleMask = nullptr,
569 color_blend_attachment.blendEnable = VK_FALSE; 600 .alphaToCoverageEnable = VK_FALSE,
570 color_blend_attachment.srcColorBlendFactor = VK_BLEND_FACTOR_ZERO; 601 .alphaToOneEnable = VK_FALSE,
571 color_blend_attachment.dstColorBlendFactor = VK_BLEND_FACTOR_ZERO; 602 };
572 color_blend_attachment.colorBlendOp = VK_BLEND_OP_ADD; 603
573 color_blend_attachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; 604 const VkPipelineColorBlendAttachmentState color_blend_attachment{
574 color_blend_attachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; 605 .blendEnable = VK_FALSE,
575 color_blend_attachment.alphaBlendOp = VK_BLEND_OP_ADD; 606 .srcColorBlendFactor = VK_BLEND_FACTOR_ZERO,
576 color_blend_attachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | 607 .dstColorBlendFactor = VK_BLEND_FACTOR_ZERO,
577 VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; 608 .colorBlendOp = VK_BLEND_OP_ADD,
578 609 .srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO,
579 VkPipelineColorBlendStateCreateInfo color_blend_ci; 610 .dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO,
580 color_blend_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; 611 .alphaBlendOp = VK_BLEND_OP_ADD,
581 color_blend_ci.flags = 0; 612 .colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT |
582 color_blend_ci.pNext = nullptr; 613 VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT,
583 color_blend_ci.logicOpEnable = VK_FALSE; 614 };
584 color_blend_ci.logicOp = VK_LOGIC_OP_COPY; 615
585 color_blend_ci.attachmentCount = 1; 616 const VkPipelineColorBlendStateCreateInfo color_blend_ci{
586 color_blend_ci.pAttachments = &color_blend_attachment; 617 .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
587 color_blend_ci.blendConstants[0] = 0.0f; 618 .pNext = nullptr,
588 color_blend_ci.blendConstants[1] = 0.0f; 619 .flags = 0,
589 color_blend_ci.blendConstants[2] = 0.0f; 620 .logicOpEnable = VK_FALSE,
590 color_blend_ci.blendConstants[3] = 0.0f; 621 .logicOp = VK_LOGIC_OP_COPY,
591 622 .attachmentCount = 1,
592 static constexpr std::array dynamic_states = {VK_DYNAMIC_STATE_VIEWPORT, 623 .pAttachments = &color_blend_attachment,
593 VK_DYNAMIC_STATE_SCISSOR}; 624 .blendConstants = {0.0f, 0.0f, 0.0f, 0.0f},
594 VkPipelineDynamicStateCreateInfo dynamic_state_ci; 625 };
595 dynamic_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; 626
596 dynamic_state_ci.pNext = nullptr; 627 static constexpr std::array dynamic_states{
597 dynamic_state_ci.flags = 0; 628 VK_DYNAMIC_STATE_VIEWPORT,
598 dynamic_state_ci.dynamicStateCount = static_cast<u32>(dynamic_states.size()); 629 VK_DYNAMIC_STATE_SCISSOR,
599 dynamic_state_ci.pDynamicStates = dynamic_states.data(); 630 };
600 631 const VkPipelineDynamicStateCreateInfo dynamic_state_ci{
601 VkGraphicsPipelineCreateInfo pipeline_ci; 632 .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
602 pipeline_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; 633 .pNext = nullptr,
603 pipeline_ci.pNext = nullptr; 634 .flags = 0,
604 pipeline_ci.flags = 0; 635 .dynamicStateCount = static_cast<u32>(dynamic_states.size()),
605 pipeline_ci.stageCount = static_cast<u32>(shader_stages.size()); 636 .pDynamicStates = dynamic_states.data(),
606 pipeline_ci.pStages = shader_stages.data(); 637 };
607 pipeline_ci.pVertexInputState = &vertex_input_ci; 638
608 pipeline_ci.pInputAssemblyState = &input_assembly_ci; 639 const VkGraphicsPipelineCreateInfo pipeline_ci{
609 pipeline_ci.pTessellationState = nullptr; 640 .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
610 pipeline_ci.pViewportState = &viewport_state_ci; 641 .pNext = nullptr,
611 pipeline_ci.pRasterizationState = &rasterization_ci; 642 .flags = 0,
612 pipeline_ci.pMultisampleState = &multisampling_ci; 643 .stageCount = static_cast<u32>(shader_stages.size()),
613 pipeline_ci.pDepthStencilState = nullptr; 644 .pStages = shader_stages.data(),
614 pipeline_ci.pColorBlendState = &color_blend_ci; 645 .pVertexInputState = &vertex_input_ci,
615 pipeline_ci.pDynamicState = &dynamic_state_ci; 646 .pInputAssemblyState = &input_assembly_ci,
616 pipeline_ci.layout = *pipeline_layout; 647 .pTessellationState = nullptr,
617 pipeline_ci.renderPass = *renderpass; 648 .pViewportState = &viewport_state_ci,
618 pipeline_ci.subpass = 0; 649 .pRasterizationState = &rasterization_ci,
619 pipeline_ci.basePipelineHandle = 0; 650 .pMultisampleState = &multisampling_ci,
620 pipeline_ci.basePipelineIndex = 0; 651 .pDepthStencilState = nullptr,
652 .pColorBlendState = &color_blend_ci,
653 .pDynamicState = &dynamic_state_ci,
654 .layout = *pipeline_layout,
655 .renderPass = *renderpass,
656 .subpass = 0,
657 .basePipelineHandle = 0,
658 .basePipelineIndex = 0,
659 };
621 660
622 pipeline = device.GetLogical().CreateGraphicsPipeline(pipeline_ci); 661 pipeline = device.GetLogical().CreateGraphicsPipeline(pipeline_ci);
623} 662}
624 663
625void VKBlitScreen::CreateSampler() { 664void VKBlitScreen::CreateSampler() {
626 VkSamplerCreateInfo ci; 665 const VkSamplerCreateInfo ci{
627 ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; 666 .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
628 ci.pNext = nullptr; 667 .pNext = nullptr,
629 ci.flags = 0; 668 .flags = 0,
630 ci.magFilter = VK_FILTER_LINEAR; 669 .magFilter = VK_FILTER_LINEAR,
631 ci.minFilter = VK_FILTER_NEAREST; 670 .minFilter = VK_FILTER_NEAREST,
632 ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; 671 .mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR,
633 ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; 672 .addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
634 ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; 673 .addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
635 ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; 674 .addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
636 ci.mipLodBias = 0.0f; 675 .mipLodBias = 0.0f,
637 ci.anisotropyEnable = VK_FALSE; 676 .anisotropyEnable = VK_FALSE,
638 ci.maxAnisotropy = 0.0f; 677 .maxAnisotropy = 0.0f,
639 ci.compareEnable = VK_FALSE; 678 .compareEnable = VK_FALSE,
640 ci.compareOp = VK_COMPARE_OP_NEVER; 679 .compareOp = VK_COMPARE_OP_NEVER,
641 ci.minLod = 0.0f; 680 .minLod = 0.0f,
642 ci.maxLod = 0.0f; 681 .maxLod = 0.0f,
643 ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK; 682 .borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK,
644 ci.unnormalizedCoordinates = VK_FALSE; 683 .unnormalizedCoordinates = VK_FALSE,
684 };
645 685
646 sampler = device.GetLogical().CreateSampler(ci); 686 sampler = device.GetLogical().CreateSampler(ci);
647} 687}
@@ -650,15 +690,16 @@ void VKBlitScreen::CreateFramebuffers() {
650 const VkExtent2D size{swapchain.GetSize()}; 690 const VkExtent2D size{swapchain.GetSize()};
651 framebuffers.resize(image_count); 691 framebuffers.resize(image_count);
652 692
653 VkFramebufferCreateInfo ci; 693 VkFramebufferCreateInfo ci{
654 ci.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; 694 .sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
655 ci.pNext = nullptr; 695 .pNext = nullptr,
656 ci.flags = 0; 696 .flags = 0,
657 ci.renderPass = *renderpass; 697 .renderPass = *renderpass,
658 ci.attachmentCount = 1; 698 .attachmentCount = 1,
659 ci.width = size.width; 699 .width = size.width,
660 ci.height = size.height; 700 .height = size.height,
661 ci.layers = 1; 701 .layers = 1,
702 };
662 703
663 for (std::size_t i = 0; i < image_count; ++i) { 704 for (std::size_t i = 0; i < image_count; ++i) {
664 const VkImageView image_view{swapchain.GetImageViewIndex(i)}; 705 const VkImageView image_view{swapchain.GetImageViewIndex(i)};
@@ -678,16 +719,17 @@ void VKBlitScreen::ReleaseRawImages() {
678} 719}
679 720
680void VKBlitScreen::CreateStagingBuffer(const Tegra::FramebufferConfig& framebuffer) { 721void VKBlitScreen::CreateStagingBuffer(const Tegra::FramebufferConfig& framebuffer) {
681 VkBufferCreateInfo ci; 722 const VkBufferCreateInfo ci{
682 ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; 723 .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
683 ci.pNext = nullptr; 724 .pNext = nullptr,
684 ci.flags = 0; 725 .flags = 0,
685 ci.size = CalculateBufferSize(framebuffer); 726 .size = CalculateBufferSize(framebuffer),
686 ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | 727 .usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT |
687 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; 728 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
688 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; 729 .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
689 ci.queueFamilyIndexCount = 0; 730 .queueFamilyIndexCount = 0,
690 ci.pQueueFamilyIndices = nullptr; 731 .pQueueFamilyIndices = nullptr,
732 };
691 733
692 buffer = device.GetLogical().CreateBuffer(ci); 734 buffer = device.GetLogical().CreateBuffer(ci);
693 buffer_commit = memory_manager.Commit(buffer, true); 735 buffer_commit = memory_manager.Commit(buffer, true);
@@ -697,24 +739,28 @@ void VKBlitScreen::CreateRawImages(const Tegra::FramebufferConfig& framebuffer)
697 raw_images.resize(image_count); 739 raw_images.resize(image_count);
698 raw_buffer_commits.resize(image_count); 740 raw_buffer_commits.resize(image_count);
699 741
700 VkImageCreateInfo ci; 742 const VkImageCreateInfo ci{
701 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; 743 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
702 ci.pNext = nullptr; 744 .pNext = nullptr,
703 ci.flags = 0; 745 .flags = 0,
704 ci.imageType = VK_IMAGE_TYPE_2D; 746 .imageType = VK_IMAGE_TYPE_2D,
705 ci.format = GetFormat(framebuffer); 747 .format = GetFormat(framebuffer),
706 ci.extent.width = framebuffer.width; 748 .extent =
707 ci.extent.height = framebuffer.height; 749 {
708 ci.extent.depth = 1; 750 .width = framebuffer.width,
709 ci.mipLevels = 1; 751 .height = framebuffer.height,
710 ci.arrayLayers = 1; 752 .depth = 1,
711 ci.samples = VK_SAMPLE_COUNT_1_BIT; 753 },
712 ci.tiling = VK_IMAGE_TILING_LINEAR; 754 .mipLevels = 1,
713 ci.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT; 755 .arrayLayers = 1,
714 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; 756 .samples = VK_SAMPLE_COUNT_1_BIT,
715 ci.queueFamilyIndexCount = 0; 757 .tiling = VK_IMAGE_TILING_LINEAR,
716 ci.pQueueFamilyIndices = nullptr; 758 .usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
717 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; 759 .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
760 .queueFamilyIndexCount = 0,
761 .pQueueFamilyIndices = nullptr,
762 .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
763 };
718 764
719 for (std::size_t i = 0; i < image_count; ++i) { 765 for (std::size_t i = 0; i < image_count; ++i) {
720 raw_images[i] = std::make_unique<VKImage>(device, scheduler, ci, VK_IMAGE_ASPECT_COLOR_BIT); 766 raw_images[i] = std::make_unique<VKImage>(device, scheduler, ci, VK_IMAGE_ASPECT_COLOR_BIT);
@@ -723,39 +769,43 @@ void VKBlitScreen::CreateRawImages(const Tegra::FramebufferConfig& framebuffer)
723} 769}
724 770
725void VKBlitScreen::UpdateDescriptorSet(std::size_t image_index, VkImageView image_view) const { 771void VKBlitScreen::UpdateDescriptorSet(std::size_t image_index, VkImageView image_view) const {
726 VkDescriptorBufferInfo buffer_info; 772 const VkDescriptorBufferInfo buffer_info{
727 buffer_info.buffer = *buffer; 773 .buffer = *buffer,
728 buffer_info.offset = offsetof(BufferData, uniform); 774 .offset = offsetof(BufferData, uniform),
729 buffer_info.range = sizeof(BufferData::uniform); 775 .range = sizeof(BufferData::uniform),
730 776 };
731 VkWriteDescriptorSet ubo_write; 777
732 ubo_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; 778 const VkWriteDescriptorSet ubo_write{
733 ubo_write.pNext = nullptr; 779 .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
734 ubo_write.dstSet = descriptor_sets[image_index]; 780 .pNext = nullptr,
735 ubo_write.dstBinding = 0; 781 .dstSet = descriptor_sets[image_index],
736 ubo_write.dstArrayElement = 0; 782 .dstBinding = 0,
737 ubo_write.descriptorCount = 1; 783 .dstArrayElement = 0,
738 ubo_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; 784 .descriptorCount = 1,
739 ubo_write.pImageInfo = nullptr; 785 .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
740 ubo_write.pBufferInfo = &buffer_info; 786 .pImageInfo = nullptr,
741 ubo_write.pTexelBufferView = nullptr; 787 .pBufferInfo = &buffer_info,
742 788 .pTexelBufferView = nullptr,
743 VkDescriptorImageInfo image_info; 789 };
744 image_info.sampler = *sampler; 790
745 image_info.imageView = image_view; 791 const VkDescriptorImageInfo image_info{
746 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; 792 .sampler = *sampler,
747 793 .imageView = image_view,
748 VkWriteDescriptorSet sampler_write; 794 .imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
749 sampler_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; 795 };
750 sampler_write.pNext = nullptr; 796
751 sampler_write.dstSet = descriptor_sets[image_index]; 797 const VkWriteDescriptorSet sampler_write{
752 sampler_write.dstBinding = 1; 798 .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
753 sampler_write.dstArrayElement = 0; 799 .pNext = nullptr,
754 sampler_write.descriptorCount = 1; 800 .dstSet = descriptor_sets[image_index],
755 sampler_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; 801 .dstBinding = 1,
756 sampler_write.pImageInfo = &image_info; 802 .dstArrayElement = 0,
757 sampler_write.pBufferInfo = nullptr; 803 .descriptorCount = 1,
758 sampler_write.pTexelBufferView = nullptr; 804 .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
805 .pImageInfo = &image_info,
806 .pBufferInfo = nullptr,
807 .pTexelBufferView = nullptr,
808 };
759 809
760 device.GetLogical().UpdateDescriptorSets(std::array{ubo_write, sampler_write}, {}); 810 device.GetLogical().UpdateDescriptorSets(std::array{ubo_write, sampler_write}, {});
761} 811}