vulkan: Zero initialize as much structure info as possible.

This fixes a crash with nvidia driver in present call (likely because of
some uninitialized member)
This commit is contained in:
Vincent Lejeune 2016-03-12 22:22:28 +01:00
parent c8cc681591
commit 70a80b84d7
5 changed files with 49 additions and 124 deletions

View file

@ -176,20 +176,11 @@ VKGSRender::VKGSRender() : GSRender(frame_type::Vulkan)
m_command_buffer_pool.create((*m_device)); m_command_buffer_pool.create((*m_device));
m_command_buffer.create(m_command_buffer_pool); m_command_buffer.create(m_command_buffer_pool);
VkCommandBufferInheritanceInfo inheritance_info; VkCommandBufferInheritanceInfo inheritance_info = {};
inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
inheritance_info.pNext = nullptr;
inheritance_info.renderPass = VK_NULL_HANDLE;
inheritance_info.subpass = 0;
inheritance_info.framebuffer = VK_NULL_HANDLE;
inheritance_info.occlusionQueryEnable = VK_FALSE;
inheritance_info.queryFlags = 0;
inheritance_info.pipelineStatistics = 0;
VkCommandBufferBeginInfo begin_infos; VkCommandBufferBeginInfo begin_infos = {};
begin_infos.flags = 0;
begin_infos.pInheritanceInfo = &inheritance_info; begin_infos.pInheritanceInfo = &inheritance_info;
begin_infos.pNext = nullptr;
begin_infos.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; begin_infos.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
CHECK_RESULT(vkBeginCommandBuffer(m_command_buffer, &begin_infos)); CHECK_RESULT(vkBeginCommandBuffer(m_command_buffer, &begin_infos));
@ -375,17 +366,14 @@ namespace
void VKGSRender::end() void VKGSRender::end()
{ {
VkRenderPassBeginInfo rp_begin; VkRenderPassBeginInfo rp_begin = {};
rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
rp_begin.pNext = NULL;
rp_begin.renderPass = m_render_pass; rp_begin.renderPass = m_render_pass;
rp_begin.framebuffer = m_framebuffer; rp_begin.framebuffer = m_framebuffer;
rp_begin.renderArea.offset.x = 0; rp_begin.renderArea.offset.x = 0;
rp_begin.renderArea.offset.y = 0; rp_begin.renderArea.offset.y = 0;
rp_begin.renderArea.extent.width = m_frame->client_size().width; rp_begin.renderArea.extent.width = m_frame->client_size().width;
rp_begin.renderArea.extent.height = m_frame->client_size().height; rp_begin.renderArea.extent.height = m_frame->client_size().height;
rp_begin.clearValueCount = 0;
rp_begin.pClearValues = nullptr;
vkCmdBeginRenderPass(m_command_buffer, &rp_begin, VK_SUBPASS_CONTENTS_INLINE); vkCmdBeginRenderPass(m_command_buffer, &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
@ -452,7 +440,7 @@ void VKGSRender::set_viewport()
// u32 shader_window = rsx::method_registers[NV4097_SET_SHADER_WINDOW]; // u32 shader_window = rsx::method_registers[NV4097_SET_SHADER_WINDOW];
// rsx::window_origin shader_window_origin = rsx::to_window_origin((shader_window >> 12) & 0xf); // rsx::window_origin shader_window_origin = rsx::to_window_origin((shader_window >> 12) & 0xf);
VkViewport viewport; VkViewport viewport = {};
viewport.x = viewport_x; viewport.x = viewport_x;
viewport.y = viewport_y; viewport.y = viewport_y;
viewport.width = viewport_w; viewport.width = viewport_w;
@ -462,7 +450,7 @@ void VKGSRender::set_viewport()
vkCmdSetViewport(m_command_buffer, 0, 1, &viewport); vkCmdSetViewport(m_command_buffer, 0, 1, &viewport);
VkRect2D scissor; VkRect2D scissor = {};
scissor.extent.height = scissor_h; scissor.extent.height = scissor_h;
scissor.extent.width = scissor_w; scissor.extent.width = scissor_w;
scissor.offset.x = scissor_x; scissor.offset.x = scissor_x;
@ -607,8 +595,7 @@ void VKGSRender::init_render_pass(VkFormat surface_format, VkFormat depth_format
{ {
//TODO: Create buffers as requested by the game. Render to swapchain for now.. //TODO: Create buffers as requested by the game. Render to swapchain for now..
/* Describe a render pass and framebuffer attachments */ /* Describe a render pass and framebuffer attachments */
VkAttachmentDescription attachments[2]; std::array<VkAttachmentDescription, 2> attachments;
memset(&attachments, 0, sizeof attachments);
attachments[0].format = surface_format; attachments[0].format = surface_format;
attachments[0].samples = VK_SAMPLE_COUNT_1_BIT; attachments[0].samples = VK_SAMPLE_COUNT_1_BIT;
@ -628,17 +615,17 @@ void VKGSRender::init_render_pass(VkFormat surface_format, VkFormat depth_format
attachments[1].initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; attachments[1].initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
attachments[1].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; attachments[1].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
VkAttachmentReference template_color_reference; VkAttachmentReference template_color_reference = {};
template_color_reference.attachment = VK_ATTACHMENT_UNUSED; template_color_reference.attachment = VK_ATTACHMENT_UNUSED;
template_color_reference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; template_color_reference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
VkAttachmentReference depth_reference; VkAttachmentReference depth_reference = {};
depth_reference.attachment = num_draw_buffers; depth_reference.attachment = num_draw_buffers;
depth_reference.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; depth_reference.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
//Fill in draw_buffers information... //Fill in draw_buffers information...
VkAttachmentDescription real_attachments[4]; std::array<VkAttachmentDescription, 4> real_attachments;
VkAttachmentReference color_references[4]; std::array<VkAttachmentReference, 4> color_references;
for (int i = 0; i < num_draw_buffers; ++i) for (int i = 0; i < num_draw_buffers; ++i)
{ {
@ -650,28 +637,18 @@ void VKGSRender::init_render_pass(VkFormat surface_format, VkFormat depth_format
real_attachments[num_draw_buffers] = attachments[1]; real_attachments[num_draw_buffers] = attachments[1];
VkSubpassDescription subpass; VkSubpassDescription subpass = {};
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpass.flags = 0;
subpass.inputAttachmentCount = 0;
subpass.pInputAttachments = nullptr;
subpass.colorAttachmentCount = num_draw_buffers; subpass.colorAttachmentCount = num_draw_buffers;
subpass.pColorAttachments = num_draw_buffers? color_references: nullptr; subpass.pColorAttachments = num_draw_buffers? color_references.data() : nullptr;
subpass.pResolveAttachments = nullptr;
subpass.pDepthStencilAttachment = &depth_reference; subpass.pDepthStencilAttachment = &depth_reference;
subpass.preserveAttachmentCount = 0;
subpass.pPreserveAttachments = nullptr;
VkRenderPassCreateInfo rp_info; VkRenderPassCreateInfo rp_info = {};
rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
rp_info.pNext = NULL; rp_info.attachmentCount = num_draw_buffers + 1;
rp_info.attachmentCount = num_draw_buffers+1; rp_info.pAttachments = real_attachments.data();
rp_info.pAttachments = real_attachments;
rp_info.subpassCount = 1; rp_info.subpassCount = 1;
rp_info.pSubpasses = &subpass; rp_info.pSubpasses = &subpass;
rp_info.dependencyCount = 0;
rp_info.pDependencies = NULL;
rp_info.flags = 0;
CHECK_RESULT(vkCreateRenderPass((*m_device), &rp_info, NULL, &m_render_pass)); CHECK_RESULT(vkCreateRenderPass((*m_device), &rp_info, NULL, &m_render_pass));
} }
@ -775,9 +752,7 @@ void VKGSRender::init_buffers(bool skip_reading)
if (dirty_frame) if (dirty_frame)
{ {
//Prepare surface for new frame //Prepare surface for new frame
VkSemaphoreCreateInfo semaphore_info; VkSemaphoreCreateInfo semaphore_info = {};
semaphore_info.flags = 0;
semaphore_info.pNext = nullptr;
semaphore_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; semaphore_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
vkCreateSemaphore((*m_device), &semaphore_info, nullptr, &m_present_semaphore); vkCreateSemaphore((*m_device), &semaphore_info, nullptr, &m_present_semaphore);
@ -808,20 +783,11 @@ void VKGSRender::write_buffers()
void VKGSRender::begin_command_buffer_recording() void VKGSRender::begin_command_buffer_recording()
{ {
VkCommandBufferInheritanceInfo inheritance_info; VkCommandBufferInheritanceInfo inheritance_info = {};
inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
inheritance_info.pNext = nullptr;
inheritance_info.renderPass = VK_NULL_HANDLE;
inheritance_info.subpass = 0;
inheritance_info.framebuffer = VK_NULL_HANDLE;
inheritance_info.occlusionQueryEnable = VK_FALSE;
inheritance_info.queryFlags = 0;
inheritance_info.pipelineStatistics = 0;
VkCommandBufferBeginInfo begin_infos; VkCommandBufferBeginInfo begin_infos = {};
begin_infos.flags = 0;
begin_infos.pInheritanceInfo = &inheritance_info; begin_infos.pInheritanceInfo = &inheritance_info;
begin_infos.pNext = nullptr;
begin_infos.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; begin_infos.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
if (m_submit_fence) if (m_submit_fence)
@ -922,25 +888,18 @@ void VKGSRender::execute_command_buffer(bool wait)
if (m_submit_fence) if (m_submit_fence)
throw EXCEPTION("Synchronization deadlock!"); throw EXCEPTION("Synchronization deadlock!");
VkFenceCreateInfo fence_info; VkFenceCreateInfo fence_info = {};
fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
fence_info.flags = 0;
fence_info.pNext = nullptr;
CHECK_RESULT(vkCreateFence(*m_device, &fence_info, nullptr, &m_submit_fence)); CHECK_RESULT(vkCreateFence(*m_device, &fence_info, nullptr, &m_submit_fence));
VkPipelineStageFlags pipe_stage_flags = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT; VkPipelineStageFlags pipe_stage_flags = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
VkCommandBuffer cmd = m_command_buffer; VkCommandBuffer cmd = m_command_buffer;
VkSubmitInfo infos; VkSubmitInfo infos = {};
infos.commandBufferCount = 1; infos.commandBufferCount = 1;
infos.pCommandBuffers = &cmd; infos.pCommandBuffers = &cmd;
infos.pNext = nullptr;
infos.pSignalSemaphores = nullptr;
infos.pWaitDstStageMask = &pipe_stage_flags; infos.pWaitDstStageMask = &pipe_stage_flags;
infos.signalSemaphoreCount = 0;
infos.waitSemaphoreCount = 0;
infos.pWaitSemaphores = nullptr;
infos.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; infos.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
CHECK_RESULT(vkQueueSubmit(m_swap_chain->get_present_queue(), 1, &infos, m_submit_fence)); CHECK_RESULT(vkQueueSubmit(m_swap_chain->get_present_queue(), 1, &infos, m_submit_fence));
@ -989,7 +948,7 @@ void VKGSRender::flip(int buffer)
VkSwapchainKHR swap_chain = (VkSwapchainKHR)(*m_swap_chain); VkSwapchainKHR swap_chain = (VkSwapchainKHR)(*m_swap_chain);
uint32_t next_image_temp = 0; uint32_t next_image_temp = 0;
VkPresentInfoKHR present; VkPresentInfoKHR present = {};
present.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; present.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
present.pNext = nullptr; present.pNext = nullptr;
present.swapchainCount = 1; present.swapchainCount = 1;

View file

@ -136,8 +136,7 @@ namespace vk
if (g_null_sampler) if (g_null_sampler)
return g_null_sampler; return g_null_sampler;
VkSamplerCreateInfo sampler_info; VkSamplerCreateInfo sampler_info = {};
memset(&sampler_info, 0, sizeof(sampler_info));
sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
@ -146,7 +145,6 @@ namespace vk
sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
sampler_info.anisotropyEnable = VK_FALSE; sampler_info.anisotropyEnable = VK_FALSE;
sampler_info.compareEnable = VK_FALSE; sampler_info.compareEnable = VK_FALSE;
sampler_info.pNext = nullptr;
sampler_info.unnormalizedCoordinates = VK_FALSE; sampler_info.unnormalizedCoordinates = VK_FALSE;
sampler_info.mipLodBias = 0; sampler_info.mipLodBias = 0;
sampler_info.maxAnisotropy = 0; sampler_info.maxAnisotropy = 0;
@ -216,9 +214,8 @@ namespace vk
VkImageSubresourceRange range = default_image_subresource_range(); VkImageSubresourceRange range = default_image_subresource_range();
range.aspectMask = aspect_flags; range.aspectMask = aspect_flags;
VkImageMemoryBarrier barrier; VkImageMemoryBarrier barrier = {};
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
barrier.pNext = nullptr;
barrier.newLayout = new_layout; barrier.newLayout = new_layout;
barrier.oldLayout = current_layout; barrier.oldLayout = current_layout;
barrier.image = image; barrier.image = image;

View file

@ -384,15 +384,12 @@ namespace vk
owner = &dev; owner = &dev;
VkBufferCreateInfo infos; VkBufferCreateInfo infos = {};
infos.pNext = nullptr;
infos.size = size; infos.size = size;
infos.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; infos.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
infos.sharingMode = VK_SHARING_MODE_EXCLUSIVE; infos.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
infos.flags = flags; infos.flags = flags;
infos.usage = usage; infos.usage = usage;
infos.pQueueFamilyIndices = nullptr;
infos.queueFamilyIndexCount = 0;
CHECK_RESULT(vkCreateBuffer(dev, &infos, nullptr, &m_buffer)); CHECK_RESULT(vkCreateBuffer(dev, &infos, nullptr, &m_buffer));
@ -503,12 +500,9 @@ namespace vk
if (!(format_properties.bufferFeatures & VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT)) if (!(format_properties.bufferFeatures & VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT))
throw EXCEPTION("Can't map view to requested format"); throw EXCEPTION("Can't map view to requested format");
VkBufferViewCreateInfo view_info; VkBufferViewCreateInfo view_info = {};
view_info.buffer = m_buffer; view_info.buffer = m_buffer;
view_info.flags = 0;
view_info.format = format; view_info.format = format;
view_info.offset = 0;
view_info.pNext = nullptr;
view_info.range = m_size; view_info.range = m_size;
view_info.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; view_info.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
@ -552,12 +546,10 @@ namespace vk
void create(vk::render_device &dev, VkRenderPass pass, VkImageView *attachments, u32 nb_attachments, u32 width, u32 height) void create(vk::render_device &dev, VkRenderPass pass, VkImageView *attachments, u32 nb_attachments, u32 width, u32 height)
{ {
VkFramebufferCreateInfo infos; VkFramebufferCreateInfo infos = {};
infos.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; infos.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
infos.flags = 0;
infos.width = width; infos.width = width;
infos.height = height; infos.height = height;
infos.pNext = nullptr;
infos.attachmentCount = nb_attachments; infos.attachmentCount = nb_attachments;
infos.pAttachments = attachments; infos.pAttachments = attachments;
infos.renderPass = pass; infos.renderPass = pass;
@ -593,10 +585,9 @@ namespace vk
void create(vk::render_device &dev, VkImage &swap_image, VkFormat format) void create(vk::render_device &dev, VkImage &swap_image, VkFormat format)
{ {
VkImageViewCreateInfo color_image_view; VkImageViewCreateInfo color_image_view = {};
color_image_view.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; color_image_view.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
color_image_view.pNext = nullptr;
color_image_view.format = format; color_image_view.format = format;
color_image_view.components.r = VK_COMPONENT_SWIZZLE_R; color_image_view.components.r = VK_COMPONENT_SWIZZLE_R;
@ -611,7 +602,6 @@ namespace vk
color_image_view.subresourceRange.layerCount = 1; color_image_view.subresourceRange.layerCount = 1;
color_image_view.viewType = VK_IMAGE_VIEW_TYPE_2D; color_image_view.viewType = VK_IMAGE_VIEW_TYPE_2D;
color_image_view.flags = 0;
color_image_view.image = swap_image; color_image_view.image = swap_image;
vkCreateImageView(dev, &color_image_view, nullptr, &view); vkCreateImageView(dev, &color_image_view, nullptr, &view);
@ -774,9 +764,8 @@ namespace vk
if (surface_descriptors.supportedTransforms & VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR) if (surface_descriptors.supportedTransforms & VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR)
pre_transform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; pre_transform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
VkSwapchainCreateInfoKHR swap_info; VkSwapchainCreateInfoKHR swap_info = {};
swap_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; swap_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
swap_info.pNext = nullptr;
swap_info.surface = m_surface; swap_info.surface = m_surface;
swap_info.minImageCount = nb_swap_images; swap_info.minImageCount = nb_swap_images;
swap_info.imageFormat = m_surface_format; swap_info.imageFormat = m_surface_format;
@ -787,8 +776,6 @@ namespace vk
swap_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; swap_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
swap_info.imageArrayLayers = 1; swap_info.imageArrayLayers = 1;
swap_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; swap_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
swap_info.queueFamilyIndexCount = 0;
swap_info.pQueueFamilyIndices = nullptr;
swap_info.presentMode = swapchain_present_mode; swap_info.presentMode = swapchain_present_mode;
swap_info.oldSwapchain = old_swapchain; swap_info.oldSwapchain = old_swapchain;
swap_info.clipped = true; swap_info.clipped = true;
@ -860,10 +847,8 @@ namespace vk
void create(vk::render_device &dev) void create(vk::render_device &dev)
{ {
owner = &dev; owner = &dev;
VkCommandPoolCreateInfo infos; VkCommandPoolCreateInfo infos = {};
infos.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; infos.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
infos.pNext = nullptr;
infos.queueFamilyIndex = 0;
infos.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; infos.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
CHECK_RESULT(vkCreateCommandPool(dev, &infos, nullptr, &pool)); CHECK_RESULT(vkCreateCommandPool(dev, &infos, nullptr, &pool));
@ -900,12 +885,11 @@ namespace vk
void create(vk::command_pool &cmd_pool) void create(vk::command_pool &cmd_pool)
{ {
VkCommandBufferAllocateInfo infos; VkCommandBufferAllocateInfo infos = {};
infos.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; infos.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
infos.commandBufferCount = 1; infos.commandBufferCount = 1;
infos.commandPool = (VkCommandPool)cmd_pool; infos.commandPool = (VkCommandPool)cmd_pool;
infos.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; infos.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
infos.pNext = nullptr;
CHECK_RESULT(vkAllocateCommandBuffers(cmd_pool.get_owner(), &infos, &commands)); CHECK_RESULT(vkAllocateCommandBuffers(cmd_pool.get_owner(), &infos, &commands));
pool = &cmd_pool; pool = &cmd_pool;
@ -973,11 +957,9 @@ namespace vk
createDebugReportCallback = (PFN_vkCreateDebugReportCallbackEXT)vkGetInstanceProcAddr(m_instance, "vkCreateDebugReportCallbackEXT"); createDebugReportCallback = (PFN_vkCreateDebugReportCallbackEXT)vkGetInstanceProcAddr(m_instance, "vkCreateDebugReportCallbackEXT");
destroyDebugReportCallback = (PFN_vkDestroyDebugReportCallbackEXT)vkGetInstanceProcAddr(m_instance, "vkDestroyDebugReportCallbackEXT"); destroyDebugReportCallback = (PFN_vkDestroyDebugReportCallbackEXT)vkGetInstanceProcAddr(m_instance, "vkDestroyDebugReportCallbackEXT");
VkDebugReportCallbackCreateInfoEXT dbgCreateInfo; VkDebugReportCallbackCreateInfoEXT dbgCreateInfo = {};
dbgCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT; dbgCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
dbgCreateInfo.pNext = NULL;
dbgCreateInfo.pfnCallback = callback; dbgCreateInfo.pfnCallback = callback;
dbgCreateInfo.pUserData = NULL;
dbgCreateInfo.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT; dbgCreateInfo.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT;
CHECK_RESULT(createDebugReportCallback(m_instance, &dbgCreateInfo, NULL, &m_debugger)); CHECK_RESULT(createDebugReportCallback(m_instance, &dbgCreateInfo, NULL, &m_debugger));
@ -986,10 +968,9 @@ namespace vk
uint32_t createInstance(const char *app_name) uint32_t createInstance(const char *app_name)
{ {
//Initialize a vulkan instance //Initialize a vulkan instance
VkApplicationInfo app; VkApplicationInfo app = {};
app.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; app.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
app.pNext = nullptr;
app.pApplicationName = app_name; app.pApplicationName = app_name;
app.applicationVersion = 0; app.applicationVersion = 0;
app.pEngineName = app_name; app.pEngineName = app_name;
@ -1009,9 +990,8 @@ namespace vk
if (rpcs3::config.rsx.d3d12.debug_output.value()) if (rpcs3::config.rsx.d3d12.debug_output.value())
layers.push_back("VK_LAYER_LUNARG_standard_validation"); layers.push_back("VK_LAYER_LUNARG_standard_validation");
VkInstanceCreateInfo instance_info; VkInstanceCreateInfo instance_info = {};
instance_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; instance_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
instance_info.pNext = nullptr;
instance_info.pApplicationInfo = &app; instance_info.pApplicationInfo = &app;
instance_info.enabledLayerCount = layers.size(); instance_info.enabledLayerCount = layers.size();
instance_info.ppEnabledLayerNames = layers.data(); instance_info.ppEnabledLayerNames = layers.data();
@ -1078,10 +1058,8 @@ namespace vk
#ifdef _WIN32 #ifdef _WIN32
vk::swap_chain* createSwapChain(HINSTANCE hInstance, HWND hWnd, vk::physical_device &dev) vk::swap_chain* createSwapChain(HINSTANCE hInstance, HWND hWnd, vk::physical_device &dev)
{ {
VkWin32SurfaceCreateInfoKHR createInfo; VkWin32SurfaceCreateInfoKHR createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR; createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
createInfo.pNext = NULL;
createInfo.flags = 0;
createInfo.hinstance = hInstance; createInfo.hinstance = hInstance;
createInfo.hwnd = hWnd; createInfo.hwnd = hWnd;
@ -1180,10 +1158,9 @@ namespace vk
void create(vk::render_device &dev, VkDescriptorPoolSize *sizes, u32 size_descriptors_count) void create(vk::render_device &dev, VkDescriptorPoolSize *sizes, u32 size_descriptors_count)
{ {
VkDescriptorPoolCreateInfo infos; VkDescriptorPoolCreateInfo infos = {};
infos.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT; infos.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
infos.maxSets = 2; infos.maxSets = 2;
infos.pNext = nullptr;
infos.poolSizeCount = size_descriptors_count; infos.poolSizeCount = size_descriptors_count;
infos.pPoolSizes = sizes; infos.pPoolSizes = sizes;
infos.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; infos.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;

View file

@ -47,8 +47,8 @@ namespace rsx
rtt.change_layout(*cmd, VK_IMAGE_LAYOUT_GENERAL); rtt.change_layout(*cmd, VK_IMAGE_LAYOUT_GENERAL);
//Clear new surface.. //Clear new surface..
VkClearDepthStencilValue clear_depth; VkClearDepthStencilValue clear_depth = {};
VkImageSubresourceRange range; VkImageSubresourceRange range = {};
range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
range.baseArrayLayer = 0; range.baseArrayLayer = 0;
range.baseMipLevel = 0; range.baseMipLevel = 0;

View file

@ -10,7 +10,7 @@ namespace vk
{ {
VkComponentMapping default_component_map() VkComponentMapping default_component_map()
{ {
VkComponentMapping result; VkComponentMapping result = {};
result.a = VK_COMPONENT_SWIZZLE_A; result.a = VK_COMPONENT_SWIZZLE_A;
result.r = VK_COMPONENT_SWIZZLE_R; result.r = VK_COMPONENT_SWIZZLE_R;
result.g = VK_COMPONENT_SWIZZLE_G; result.g = VK_COMPONENT_SWIZZLE_G;
@ -21,7 +21,7 @@ namespace vk
VkImageSubresource default_image_subresource() VkImageSubresource default_image_subresource()
{ {
VkImageSubresource subres; VkImageSubresource subres = {};
subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
subres.mipLevel = 0; subres.mipLevel = 0;
subres.arrayLayer = 0; subres.arrayLayer = 0;
@ -31,7 +31,7 @@ namespace vk
VkImageSubresourceRange default_image_subresource_range() VkImageSubresourceRange default_image_subresource_range()
{ {
VkImageSubresourceRange subres; VkImageSubresourceRange subres = {};
subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
subres.baseArrayLayer = 0; subres.baseArrayLayer = 0;
subres.baseMipLevel = 0; subres.baseMipLevel = 0;
@ -43,7 +43,7 @@ namespace vk
void copy_image(VkCommandBuffer cmd, VkImage &src, VkImage &dst, VkImageLayout srcLayout, VkImageLayout dstLayout, u32 width, u32 height, u32 mipmaps, VkImageAspectFlagBits aspect) void copy_image(VkCommandBuffer cmd, VkImage &src, VkImage &dst, VkImageLayout srcLayout, VkImageLayout dstLayout, u32 width, u32 height, u32 mipmaps, VkImageAspectFlagBits aspect)
{ {
VkImageSubresourceLayers a_src, a_dst; VkImageSubresourceLayers a_src = {}, a_dst = {};
a_src.aspectMask = aspect; a_src.aspectMask = aspect;
a_src.baseArrayLayer = 0; a_src.baseArrayLayer = 0;
a_src.layerCount = 1; a_src.layerCount = 1;
@ -51,7 +51,7 @@ namespace vk
a_dst = a_src; a_dst = a_src;
VkImageCopy rgn; VkImageCopy rgn = {};
rgn.extent.depth = 1; rgn.extent.depth = 1;
rgn.extent.width = width; rgn.extent.width = width;
rgn.extent.height = height; rgn.extent.height = height;
@ -83,7 +83,7 @@ namespace vk
void copy_scaled_image(VkCommandBuffer cmd, VkImage & src, VkImage & dst, VkImageLayout srcLayout, VkImageLayout dstLayout, u32 src_width, u32 src_height, u32 dst_width, u32 dst_height, u32 mipmaps, VkImageAspectFlagBits aspect) void copy_scaled_image(VkCommandBuffer cmd, VkImage & src, VkImage & dst, VkImageLayout srcLayout, VkImageLayout dstLayout, u32 src_width, u32 src_height, u32 dst_width, u32 dst_height, u32 mipmaps, VkImageAspectFlagBits aspect)
{ {
VkImageSubresourceLayers a_src, a_dst; VkImageSubresourceLayers a_src = {}, a_dst = {};
a_src.aspectMask = aspect; a_src.aspectMask = aspect;
a_src.baseArrayLayer = 0; a_src.baseArrayLayer = 0;
a_src.layerCount = 1; a_src.layerCount = 1;
@ -91,7 +91,7 @@ namespace vk
a_dst = a_src; a_dst = a_src;
VkImageBlit rgn; VkImageBlit rgn = {};
rgn.srcOffsets[0] = { 0, 0, 0 }; rgn.srcOffsets[0] = { 0, 0, 0 };
rgn.srcOffsets[1] = { (int32_t)src_width, (int32_t)src_height, 1 }; rgn.srcOffsets[1] = { (int32_t)src_width, (int32_t)src_height, 1 };
rgn.dstOffsets[0] = { 0, 0, 0 }; rgn.dstOffsets[0] = { 0, 0, 0 };
@ -143,11 +143,9 @@ namespace vk
owner = &device; owner = &device;
//First create the image //First create the image
VkImageCreateInfo image_info; VkImageCreateInfo image_info = {};
memset(&image_info, 0, sizeof(image_info));
image_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; image_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
image_info.pNext = nullptr;
image_info.imageType = image_type; image_info.imageType = image_type;
image_info.format = format; image_info.format = format;
image_info.extent = { width, height, 1 }; image_info.extent = { width, height, 1 };
@ -166,15 +164,13 @@ namespace vk
CHECK_RESULT(vkBindImageMemory(device, m_image_contents, vram_allocation, 0)); CHECK_RESULT(vkBindImageMemory(device, m_image_contents, vram_allocation, 0));
VkImageViewCreateInfo view_info; VkImageViewCreateInfo view_info = {};
view_info.format = format; view_info.format = format;
view_info.image = m_image_contents; view_info.image = m_image_contents;
view_info.pNext = nullptr;
view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
view_info.viewType = view_type; view_info.viewType = view_type;
view_info.components = swizzle; view_info.components = swizzle;
view_info.subresourceRange = default_image_subresource_range(); view_info.subresourceRange = default_image_subresource_range();
view_info.flags = 0;
if (usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) if (usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
{ {
@ -200,18 +196,16 @@ namespace vk
VkSamplerAddressMode clamp_t = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; VkSamplerAddressMode clamp_t = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
VkSamplerAddressMode clamp_r = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; VkSamplerAddressMode clamp_r = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
VkSamplerCreateInfo sampler_info; VkSamplerCreateInfo sampler_info = {};
sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
sampler_info.addressModeU = clamp_s; sampler_info.addressModeU = clamp_s;
sampler_info.addressModeV = clamp_t; sampler_info.addressModeV = clamp_t;
sampler_info.addressModeW = clamp_r; sampler_info.addressModeW = clamp_r;
sampler_info.anisotropyEnable = VK_FALSE; sampler_info.anisotropyEnable = VK_FALSE;
sampler_info.compareEnable = VK_FALSE; sampler_info.compareEnable = VK_FALSE;
sampler_info.pNext = nullptr;
sampler_info.unnormalizedCoordinates = VK_FALSE; sampler_info.unnormalizedCoordinates = VK_FALSE;
sampler_info.mipLodBias = 0; sampler_info.mipLodBias = 0;
sampler_info.maxAnisotropy = 0; sampler_info.maxAnisotropy = 0;
sampler_info.flags = 0;
sampler_info.magFilter = VK_FILTER_LINEAR; sampler_info.magFilter = VK_FILTER_LINEAR;
sampler_info.minFilter = VK_FILTER_LINEAR; sampler_info.minFilter = VK_FILTER_LINEAR;
sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
@ -325,18 +319,16 @@ namespace vk
VkSamplerAddressMode clamp_t = vk_wrap_mode(tex.wrap_t()); VkSamplerAddressMode clamp_t = vk_wrap_mode(tex.wrap_t());
VkSamplerAddressMode clamp_r = vk_wrap_mode(tex.wrap_r()); VkSamplerAddressMode clamp_r = vk_wrap_mode(tex.wrap_r());
VkSamplerCreateInfo sampler_info; VkSamplerCreateInfo sampler_info = {};
sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
sampler_info.addressModeU = clamp_s; sampler_info.addressModeU = clamp_s;
sampler_info.addressModeV = clamp_t; sampler_info.addressModeV = clamp_t;
sampler_info.addressModeW = clamp_r; sampler_info.addressModeW = clamp_r;
sampler_info.anisotropyEnable = VK_TRUE; sampler_info.anisotropyEnable = VK_TRUE;
sampler_info.compareEnable = VK_FALSE; sampler_info.compareEnable = VK_FALSE;
sampler_info.pNext = nullptr;
sampler_info.unnormalizedCoordinates = !!(tex.format() & CELL_GCM_TEXTURE_UN); sampler_info.unnormalizedCoordinates = !!(tex.format() & CELL_GCM_TEXTURE_UN);
sampler_info.mipLodBias = tex.bias(); sampler_info.mipLodBias = tex.bias();
sampler_info.maxAnisotropy = max_aniso(tex.max_aniso()); sampler_info.maxAnisotropy = max_aniso(tex.max_aniso());
sampler_info.flags = 0;
sampler_info.maxLod = tex.max_lod(); sampler_info.maxLod = tex.max_lod();
sampler_info.minLod = tex.min_lod(); sampler_info.minLod = tex.min_lod();
sampler_info.magFilter = VK_FILTER_LINEAR; sampler_info.magFilter = VK_FILTER_LINEAR;
@ -379,7 +371,7 @@ namespace vk
if (!m_sampler) if (!m_sampler)
sampler_setup(tex, best_type, default_component_map()); sampler_setup(tex, best_type, default_component_map());
VkImageSubresource subres; VkImageSubresource subres = {};
subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
subres.mipLevel = 0; subres.mipLevel = 0;
subres.arrayLayer = 0; subres.arrayLayer = 0;