@ -83,10 +83,11 @@ static void mat3_to_mat4(const float mat3[9], float mat4[4][4]) {
struct wlr_vk_descriptor_pool * vulkan_alloc_texture_ds (
struct wlr_vk_descriptor_pool * vulkan_alloc_texture_ds (
struct wlr_vk_renderer * renderer , VkDescriptorSet * ds ) {
struct wlr_vk_renderer * renderer , VkDescriptorSet * ds ) {
VkResult res ;
VkResult res ;
VkDescriptorSetAllocateInfo ds_info = { 0 } ;
VkDescriptorSetAllocateInfo ds_info = {
ds_info . sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO ;
. sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO ,
ds_info . descriptorSetCount = 1 ;
. descriptorSetCount = 1 ,
ds_info . pSetLayouts = & renderer - > ds_layout ;
. pSetLayouts = & renderer - > ds_layout ,
} ;
bool found = false ;
bool found = false ;
struct wlr_vk_descriptor_pool * pool ;
struct wlr_vk_descriptor_pool * pool ;
@ -110,16 +111,18 @@ struct wlr_vk_descriptor_pool *vulkan_alloc_texture_ds(
}
}
pool - > free = count ;
pool - > free = count ;
VkDescriptorPoolSize pool_size = { 0 } ;
VkDescriptorPoolSize pool_size = {
pool_size . descriptorCount = count ;
. descriptorCount = count ,
pool_size . type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER ;
. type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER ,
} ;
VkDescriptorPoolCreateInfo dpool_info = { 0 } ;
VkDescriptorPoolCreateInfo dpool_info = {
dpool_info . sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO ;
. sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO ,
dpool_info . maxSets = count ;
. maxSets = count ,
dpool_info . poolSizeCount = 1 ;
. poolSizeCount = 1 ,
dpool_info . pPoolSizes = & pool_size ;
. pPoolSizes = & pool_size ,
dpool_info . flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT ;
. flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT ,
} ;
res = vkCreateDescriptorPool ( renderer - > dev - > dev , & dpool_info , NULL ,
res = vkCreateDescriptorPool ( renderer - > dev - > dev , & dpool_info , NULL ,
& pool - > pool ) ;
& pool - > pool ) ;
@ -256,12 +259,13 @@ struct wlr_vk_buffer_span vulkan_get_stage_span(struct wlr_vk_renderer *r,
}
}
VkResult res ;
VkResult res ;
VkBufferCreateInfo buf_info = { 0 } ;
VkBufferCreateInfo buf_info = {
buf_info . sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO ;
. sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO ,
buf_info . size = bsize ;
. size = bsize ,
buf_info . usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT |
. usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT |
VK_BUFFER_USAGE_TRANSFER_SRC_BIT ;
VK_BUFFER_USAGE_TRANSFER_SRC_BIT ,
buf_info . sharingMode = VK_SHARING_MODE_EXCLUSIVE ;
. sharingMode = VK_SHARING_MODE_EXCLUSIVE ,
} ;
res = vkCreateBuffer ( r - > dev - > dev , & buf_info , NULL , & buf - > buffer ) ;
res = vkCreateBuffer ( r - > dev - > dev , & buf_info , NULL , & buf - > buffer ) ;
if ( res ! = VK_SUCCESS ) {
if ( res ! = VK_SUCCESS ) {
wlr_vk_error ( " vkCreateBuffer " , res ) ;
wlr_vk_error ( " vkCreateBuffer " , res ) ;
@ -279,10 +283,11 @@ struct wlr_vk_buffer_span vulkan_get_stage_span(struct wlr_vk_renderer *r,
goto error ;
goto error ;
}
}
VkMemoryAllocateInfo mem_info = { 0 } ;
VkMemoryAllocateInfo mem_info = {
mem_info . sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO ;
. sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO ,
mem_info . allocationSize = mem_reqs . size ;
. allocationSize = mem_reqs . size ,
mem_info . memoryTypeIndex = ( uint32_t ) mem_type_index ;
. memoryTypeIndex = ( uint32_t ) mem_type_index ,
} ;
res = vkAllocateMemory ( r - > dev - > dev , & mem_info , NULL , & buf - > memory ) ;
res = vkAllocateMemory ( r - > dev - > dev , & mem_info , NULL , & buf - > memory ) ;
if ( res ! = VK_SUCCESS ) {
if ( res ! = VK_SUCCESS ) {
wlr_vk_error ( " vkAllocatorMemory " , res ) ;
wlr_vk_error ( " vkAllocatorMemory " , res ) ;
@ -327,8 +332,9 @@ error_alloc:
VkCommandBuffer vulkan_record_stage_cb ( struct wlr_vk_renderer * renderer ) {
VkCommandBuffer vulkan_record_stage_cb ( struct wlr_vk_renderer * renderer ) {
if ( ! renderer - > stage . recording ) {
if ( ! renderer - > stage . recording ) {
VkCommandBufferBeginInfo begin_info = { 0 } ;
VkCommandBufferBeginInfo begin_info = {
begin_info . sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO ;
. sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO ,
} ;
vkBeginCommandBuffer ( renderer - > stage . cb , & begin_info ) ;
vkBeginCommandBuffer ( renderer - > stage . cb , & begin_info ) ;
renderer - > stage . recording = true ;
renderer - > stage . recording = true ;
}
}
@ -344,10 +350,11 @@ bool vulkan_submit_stage_wait(struct wlr_vk_renderer *renderer) {
vkEndCommandBuffer ( renderer - > stage . cb ) ;
vkEndCommandBuffer ( renderer - > stage . cb ) ;
renderer - > stage . recording = false ;
renderer - > stage . recording = false ;
VkSubmitInfo submit_info = { 0 } ;
VkSubmitInfo submit_info = {
submit_info . sType = VK_STRUCTURE_TYPE_SUBMIT_INFO ;
. sType = VK_STRUCTURE_TYPE_SUBMIT_INFO ,
submit_info . commandBufferCount = 1u ;
. commandBufferCount = 1u ,
submit_info . pCommandBuffers = & renderer - > stage . cb ;
. pCommandBuffers = & renderer - > stage . cb ,
} ;
VkResult res = vkQueueSubmit ( renderer - > dev - > queue , 1 ,
VkResult res = vkQueueSubmit ( renderer - > dev - > queue , 1 ,
& submit_info , renderer - > fence ) ;
& submit_info , renderer - > fence ) ;
if ( res ! = VK_SUCCESS ) {
if ( res ! = VK_SUCCESS ) {
@ -448,17 +455,22 @@ static struct wlr_vk_render_buffer *create_render_buffer(
goto error_buffer ;
goto error_buffer ;
}
}
VkImageViewCreateInfo view_info = { 0 } ;
VkImageViewCreateInfo view_info = {
view_info . sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO ;
. sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO ,
view_info . image = buffer - > image ;
. image = buffer - > image ,
view_info . viewType = VK_IMAGE_VIEW_TYPE_2D ;
. viewType = VK_IMAGE_VIEW_TYPE_2D ,
view_info . format = fmt - > format . vk_format ;
. format = fmt - > format . vk_format ,
view_info . components . r = VK_COMPONENT_SWIZZLE_IDENTITY ;
. components . r = VK_COMPONENT_SWIZZLE_IDENTITY ,
view_info . components . g = VK_COMPONENT_SWIZZLE_IDENTITY ;
. components . g = VK_COMPONENT_SWIZZLE_IDENTITY ,
view_info . components . b = VK_COMPONENT_SWIZZLE_IDENTITY ;
. components . b = VK_COMPONENT_SWIZZLE_IDENTITY ,
view_info . components . a = VK_COMPONENT_SWIZZLE_IDENTITY ;
. components . a = VK_COMPONENT_SWIZZLE_IDENTITY ,
view_info . subresourceRange = ( VkImageSubresourceRange ) {
. subresourceRange = ( VkImageSubresourceRange ) {
VK_IMAGE_ASPECT_COLOR_BIT , 0 , 1 , 0 , 1
. aspectMask = VK_IMAGE_ASPECT_COLOR_BIT ,
. baseMipLevel = 0 ,
. levelCount = 1 ,
. baseArrayLayer = 0 ,
. layerCount = 1 ,
} ,
} ;
} ;
res = vkCreateImageView ( dev , & view_info , NULL , & buffer - > image_view ) ;
res = vkCreateImageView ( dev , & view_info , NULL , & buffer - > image_view ) ;
@ -473,15 +485,16 @@ static struct wlr_vk_render_buffer *create_render_buffer(
goto error_view ;
goto error_view ;
}
}
VkFramebufferCreateInfo fb_info = { 0 } ;
VkFramebufferCreateInfo fb_info = {
fb_info . sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO ;
. sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO ,
fb_info . attachmentCount = 1u ;
. attachmentCount = 1u ,
fb_info . pAttachments = & buffer - > image_view ;
. pAttachments = & buffer - > image_view ,
fb_info . flags = 0u ;
. flags = 0u ,
fb_info . width = dmabuf . width ;
. width = dmabuf . width ,
fb_info . height = dmabuf . height ;
. height = dmabuf . height ,
fb_info . layers = 1u ;
. layers = 1u ,
fb_info . renderPass = buffer - > render_setup - > render_pass ;
. renderPass = buffer - > render_setup - > render_pass ,
} ;
res = vkCreateFramebuffer ( dev , & fb_info , NULL , & buffer - > framebuffer ) ;
res = vkCreateFramebuffer ( dev , & fb_info , NULL , & buffer - > framebuffer ) ;
if ( res ! = VK_SUCCESS ) {
if ( res ! = VK_SUCCESS ) {
@ -553,8 +566,9 @@ static void vulkan_begin(struct wlr_renderer *wlr_renderer,
assert ( renderer - > current_render_buffer ) ;
assert ( renderer - > current_render_buffer ) ;
VkCommandBuffer cb = renderer - > cb ;
VkCommandBuffer cb = renderer - > cb ;
VkCommandBufferBeginInfo begin_info = { 0 } ;
VkCommandBufferBeginInfo begin_info = {
begin_info . sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO ;
. sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO ,
} ;
vkBeginCommandBuffer ( cb , & begin_info ) ;
vkBeginCommandBuffer ( cb , & begin_info ) ;
// begin render pass
// begin render pass
@ -563,12 +577,13 @@ static void vulkan_begin(struct wlr_renderer *wlr_renderer,
VkRect2D rect = { { 0 , 0 } , { width , height } } ;
VkRect2D rect = { { 0 , 0 } , { width , height } } ;
renderer - > scissor = rect ;
renderer - > scissor = rect ;
VkRenderPassBeginInfo rp_info = { 0 } ;
VkRenderPassBeginInfo rp_info = {
rp_info . sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO ;
. sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO ,
rp_info . renderArea = rect ;
. renderArea = rect ,
rp_info . renderPass = renderer - > current_render_buffer - > render_setup - > render_pass ;
. renderPass = renderer - > current_render_buffer - > render_setup - > render_pass ,
rp_info . framebuffer = fb ;
. framebuffer = fb ,
rp_info . clearValueCount = 0 ;
. clearValueCount = 0 ,
} ;
vkCmdBeginRenderPass ( cb , & rp_info , VK_SUBPASS_CONTENTS_INLINE ) ;
vkCmdBeginRenderPass ( cb , & rp_info , VK_SUBPASS_CONTENTS_INLINE ) ;
VkViewport vp = { 0.f , 0.f , ( float ) width , ( float ) height , 0.f , 1.f } ;
VkViewport vp = { 0.f , 0.f , ( float ) width , ( float ) height , 0.f , 1.f } ;
@ -808,24 +823,27 @@ static void vulkan_clear(struct wlr_renderer *wlr_renderer,
struct wlr_vk_renderer * renderer = vulkan_get_renderer ( wlr_renderer ) ;
struct wlr_vk_renderer * renderer = vulkan_get_renderer ( wlr_renderer ) ;
VkCommandBuffer cb = renderer - > cb ;
VkCommandBuffer cb = renderer - > cb ;
VkClearAttachment att = { 0 } ;
VkClearAttachment att = {
att . aspectMask = VK_IMAGE_ASPECT_COLOR_BIT ;
. aspectMask = VK_IMAGE_ASPECT_COLOR_BIT ,
att . colorAttachment = 0u ;
. colorAttachment = 0u ,
// Input color values are given in srgb space, vulkan expects
// Input color values are given in srgb space, vulkan expects
// them in linear space. We explicitly import argb8 render buffers
// them in linear space. We explicitly import argb8 render buffers
// as srgb, vulkan will convert the input values we give here to
// as srgb, vulkan will convert the input values we give here to
// srgb first.
// srgb first.
// But in other parts of wlroots we just always assume
// But in other parts of wlroots we just always assume
// srgb so that's why we have to convert here.
// srgb so that's why we have to convert here.
att . clearValue . color . float32 [ 0 ] = color_to_linear ( color [ 0 ] ) ;
. clearValue . color . float32 = {
att . clearValue . color . float32 [ 1 ] = color_to_linear ( color [ 1 ] ) ;
color_to_linear ( color [ 0 ] ) ,
att . clearValue . color . float32 [ 2 ] = color_to_linear ( color [ 2 ] ) ;
color_to_linear ( color [ 1 ] ) ,
att . clearValue . color . float32 [ 3 ] = color [ 3 ] ; // no conversion for alpha
color_to_linear ( color [ 2 ] ) ,
color [ 3 ] , // no conversion for alpha
VkClearRect rect = { 0 } ;
} ,
rect . rect = renderer - > scissor ;
} ;
rect . layerCount = 1 ;
VkClearRect rect = {
. rect = renderer - > scissor ,
. layerCount = 1 ,
} ;
vkCmdClearAttachments ( cb , 1 , & att , 1 , & rect ) ;
vkCmdClearAttachments ( cb , 1 , & att , 1 , & rect ) ;
}
}
@ -1242,15 +1260,19 @@ static bool init_tex_layouts(struct wlr_vk_renderer *renderer,
// layouts
// layouts
// descriptor set
// descriptor set
VkDescriptorSetLayoutBinding ds_bindings [ 1 ] = { {
VkDescriptorSetLayoutBinding ds_binding = {
0 , VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER , 1 ,
. binding = 0 ,
VK_SHADER_STAGE_FRAGMENT_BIT , & tex_sampler ,
. descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER ,
} } ;
. descriptorCount = 1 ,
. stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT ,
. pImmutableSamplers = & tex_sampler ,
} ;
VkDescriptorSetLayoutCreateInfo ds_info = { 0 } ;
VkDescriptorSetLayoutCreateInfo ds_info = {
ds_info . sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO ;
. sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO ,
ds_info . bindingCount = 1 ;
. bindingCount = 1 ,
ds_info . pBindings = ds_bindings ;
. pBindings = & ds_binding ,
} ;
res = vkCreateDescriptorSetLayout ( dev , & ds_info , NULL , out_ds_layout ) ;
res = vkCreateDescriptorSetLayout ( dev , & ds_info , NULL , out_ds_layout ) ;
if ( res ! = VK_SUCCESS ) {
if ( res ! = VK_SUCCESS ) {
@ -1259,20 +1281,25 @@ static bool init_tex_layouts(struct wlr_vk_renderer *renderer,
}
}
// pipeline layout
// pipeline layout
VkPushConstantRange pc_ranges [ 2 ] = { 0 } ;
VkPushConstantRange pc_ranges [ 2 ] = {
pc_ranges [ 0 ] . size = sizeof ( struct vert_pcr_data ) ;
{
pc_ranges [ 0 ] . stageFlags = VK_SHADER_STAGE_VERTEX_BIT ;
. size = sizeof ( struct vert_pcr_data ) ,
. stageFlags = VK_SHADER_STAGE_VERTEX_BIT ,
pc_ranges [ 1 ] . offset = pc_ranges [ 0 ] . size ;
} ,
pc_ranges [ 1 ] . size = sizeof ( float ) * 4 ; // alpha or color
{
pc_ranges [ 1 ] . stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT ;
. offset = pc_ranges [ 0 ] . size ,
. size = sizeof ( float ) * 4 , // alpha or color
. stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT ,
} ,
} ;
VkPipelineLayoutCreateInfo pl_info = { 0 } ;
VkPipelineLayoutCreateInfo pl_info = {
pl_info . sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO ;
. sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO ,
pl_info . setLayoutCount = 1 ;
. setLayoutCount = 1 ,
pl_info . pSetLayouts = out_ds_layout ;
. pSetLayouts = out_ds_layout ,
pl_info . pushConstantRangeCount = 2 ;
. pushConstantRangeCount = 2 ,
pl_info . pPushConstantRanges = pc_ranges ;
. pPushConstantRanges = pc_ranges ,
} ;
res = vkCreatePipelineLayout ( dev , & pl_info , NULL , out_pipe_layout ) ;
res = vkCreatePipelineLayout ( dev , & pl_info , NULL , out_pipe_layout ) ;
if ( res ! = VK_SUCCESS ) {
if ( res ! = VK_SUCCESS ) {
@ -1304,73 +1331,82 @@ static bool init_tex_pipeline(struct wlr_vk_renderer *renderer,
} } ;
} } ;
// info
// info
VkPipelineInputAssemblyStateCreateInfo assembly = { 0 } ;
VkPipelineInputAssemblyStateCreateInfo assembly = {
assembly . sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO ;
. sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO ,
assembly . topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN ;
. topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN ,
} ;
VkPipelineRasterizationStateCreateInfo rasterization = { 0 } ;
rasterization . sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO ;
VkPipelineRasterizationStateCreateInfo rasterization = {
rasterization . polygonMode = VK_POLYGON_MODE_FILL ;
. sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO ,
rasterization . cullMode = VK_CULL_MODE_NONE ;
. polygonMode = VK_POLYGON_MODE_FILL ,
rasterization . frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE ;
. cullMode = VK_CULL_MODE_NONE ,
rasterization . lineWidth = 1.f ;
. frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE ,
. lineWidth = 1.f ,
VkPipelineColorBlendAttachmentState blend_attachment = { 0 } ;
} ;
blend_attachment . blendEnable = true ;
VkPipelineColorBlendAttachmentState blend_attachment = {
. blendEnable = true ,
// we generally work with pre-multiplied alpha
// we generally work with pre-multiplied alpha
blend_attachment . srcColorBlendFactor = VK_BLEND_FACTOR_ONE ;
. srcColorBlendFactor = VK_BLEND_FACTOR_ONE ,
blend_attachment . dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA ;
. dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA ,
blend_attachment . colorBlendOp = VK_BLEND_OP_ADD ;
. colorBlendOp = VK_BLEND_OP_ADD ,
blend_attachment . srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE ;
. srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE ,
blend_attachment . dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE ;
. dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE ,
blend_attachment . alphaBlendOp = VK_BLEND_OP_ADD ;
. alphaBlendOp = VK_BLEND_OP_ADD ,
blend_attachment . colorWriteMask =
. colorWriteMask =
VK_COLOR_COMPONENT_R_BIT |
VK_COLOR_COMPONENT_R_BIT |
VK_COLOR_COMPONENT_G_BIT |
VK_COLOR_COMPONENT_G_BIT |
VK_COLOR_COMPONENT_B_BIT |
VK_COLOR_COMPONENT_B_BIT |
VK_COLOR_COMPONENT_A_BIT ;
VK_COLOR_COMPONENT_A_BIT ,
} ;
VkPipelineColorBlendStateCreateInfo blend = { 0 } ;
VkPipelineColorBlendStateCreateInfo blend = {
blend . sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO ;
. sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO ,
blend . attachmentCount = 1 ;
. attachmentCount = 1 ,
blend . pAttachments = & blend_attachment ;
. pAttachments = & blend_attachment ,
} ;
VkPipelineMultisampleStateCreateInfo multisample = { 0 } ;
VkPipelineMultisampleStateCreateInfo multisample = {
multisample . sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO ;
. sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO ,
multisample . rasterizationSamples = VK_SAMPLE_COUNT_1_BIT ;
. rasterizationSamples = VK_SAMPLE_COUNT_1_BIT ,
} ;
VkPipelineViewportStateCreateInfo viewport = { 0 } ;
VkPipelineViewportStateCreateInfo viewport = {
viewport . sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO ;
. sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO ,
viewport . viewportCount = 1 ;
. viewportCount = 1 ,
viewport . scissorCount = 1 ;
. scissorCount = 1 ,
} ;
VkDynamicState dynStates [ 2 ] = {
VkDynamicState dynStates [ 2 ] = {
VK_DYNAMIC_STATE_VIEWPORT ,
VK_DYNAMIC_STATE_VIEWPORT ,
VK_DYNAMIC_STATE_SCISSOR ,
VK_DYNAMIC_STATE_SCISSOR ,
} ;
} ;
VkPipelineDynamicStateCreateInfo dynamic = { 0 } ;
VkPipelineDynamicStateCreateInfo dynamic = {
dynamic . sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO ;
. sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO ,
dynamic . pDynamicStates = dynStates ;
. pDynamicStates = dynStates ,
dynamic . dynamicStateCount = 2 ;
. dynamicStateCount = 2 ,
} ;
VkPipelineVertexInputStateCreateInfo vertex = { 0 } ;
vertex . sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO ;
VkPipelineVertexInputStateCreateInfo vertex = {
. sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO ,
VkGraphicsPipelineCreateInfo pinfo = { 0 } ;
} ;
pinfo . sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO ;
pinfo . layout = pipe_layout ;
VkGraphicsPipelineCreateInfo pinfo = {
pinfo . renderPass = rp ;
. sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO ,
pinfo . subpass = 0 ;
. layout = pipe_layout ,
pinfo . stageCount = 2 ;
. renderPass = rp ,
pinfo . pStages = tex_stages ;
. subpass = 0 ,
. stageCount = 2 ,
pinfo . pInputAssemblyState = & assembly ;
. pStages = tex_stages ,
pinfo . pRasterizationState = & rasterization ;
pinfo . pColorBlendState = & blend ;
. pInputAssemblyState = & assembly ,
pinfo . pMultisampleState = & multisample ;
. pRasterizationState = & rasterization ,
pinfo . pViewportState = & viewport ;
. pColorBlendState = & blend ,
pinfo . pDynamicState = & dynamic ;
. pMultisampleState = & multisample ,
pinfo . pVertexInputState = & vertex ;
. pViewportState = & viewport ,
. pDynamicState = & dynamic ,
. pVertexInputState = & vertex ,
} ;
// NOTE: use could use a cache here for faster loading
// NOTE: use could use a cache here for faster loading
// store it somewhere like $XDG_CACHE_HOME/wlroots/vk_pipe_cache
// store it somewhere like $XDG_CACHE_HOME/wlroots/vk_pipe_cache
@ -1392,18 +1428,19 @@ static bool init_static_render_data(struct wlr_vk_renderer *renderer) {
VkDevice dev = renderer - > dev - > dev ;
VkDevice dev = renderer - > dev - > dev ;
// default sampler (non ycbcr)
// default sampler (non ycbcr)
VkSamplerCreateInfo sampler_info = { 0 } ;
VkSamplerCreateInfo sampler_info = {
sampler_info . sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO ;
. sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO ,
sampler_info . magFilter = VK_FILTER_LINEAR ;
. magFilter = VK_FILTER_LINEAR ,
sampler_info . minFilter = VK_FILTER_LINEAR ;
. minFilter = VK_FILTER_LINEAR ,
sampler_info . mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST ;
. mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST ,
sampler_info . addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT ;
. addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT ,
sampler_info . addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT ;
. addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT ,
sampler_info . addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT ;
. addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT ,
sampler_info . maxAnisotropy = 1.f ;
. maxAnisotropy = 1.f ,
sampler_info . minLod = 0.f ;
. minLod = 0.f ,
sampler_info . maxLod = 0.25f ;
. maxLod = 0.25f ,
sampler_info . borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK ;
. borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK ,
} ;
res = vkCreateSampler ( dev , & sampler_info , NULL , & renderer - > sampler ) ;
res = vkCreateSampler ( dev , & sampler_info , NULL , & renderer - > sampler ) ;
if ( res ! = VK_SUCCESS ) {
if ( res ! = VK_SUCCESS ) {
@ -1418,10 +1455,11 @@ static bool init_static_render_data(struct wlr_vk_renderer *renderer) {
// load vert module and tex frag module since they are needed to
// load vert module and tex frag module since they are needed to
// initialize the tex pipeline
// initialize the tex pipeline
VkShaderModuleCreateInfo sinfo = { 0 } ;
VkShaderModuleCreateInfo sinfo = {
sinfo . sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO ;
. sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO ,
sinfo . codeSize = sizeof ( common_vert_data ) ;
. codeSize = sizeof ( common_vert_data ) ,
sinfo . pCode = common_vert_data ;
. pCode = common_vert_data ,
} ;
res = vkCreateShaderModule ( dev , & sinfo , NULL , & renderer - > vert_module ) ;
res = vkCreateShaderModule ( dev , & sinfo , NULL , & renderer - > vert_module ) ;
if ( res ! = VK_SUCCESS ) {
if ( res ! = VK_SUCCESS ) {
wlr_vk_error ( " Failed to create vertex shader module " , res ) ;
wlr_vk_error ( " Failed to create vertex shader module " , res ) ;
@ -1429,8 +1467,11 @@ static bool init_static_render_data(struct wlr_vk_renderer *renderer) {
}
}
// tex frag
// tex frag
sinfo . codeSize = sizeof ( texture_frag_data ) ;
sinfo = ( VkShaderModuleCreateInfo ) {
sinfo . pCode = texture_frag_data ;
. sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO ,
. codeSize = sizeof ( texture_frag_data ) ,
. pCode = texture_frag_data ,
} ;
res = vkCreateShaderModule ( dev , & sinfo , NULL , & renderer - > tex_frag_module ) ;
res = vkCreateShaderModule ( dev , & sinfo , NULL , & renderer - > tex_frag_module ) ;
if ( res ! = VK_SUCCESS ) {
if ( res ! = VK_SUCCESS ) {
wlr_vk_error ( " Failed to create tex fragment shader module " , res ) ;
wlr_vk_error ( " Failed to create tex fragment shader module " , res ) ;
@ -1438,8 +1479,11 @@ static bool init_static_render_data(struct wlr_vk_renderer *renderer) {
}
}
// quad frag
// quad frag
sinfo . codeSize = sizeof ( quad_frag_data ) ;
sinfo = ( VkShaderModuleCreateInfo ) {
sinfo . pCode = quad_frag_data ;
. sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO ,
. codeSize = sizeof ( quad_frag_data ) ,
. pCode = quad_frag_data ,
} ;
res = vkCreateShaderModule ( dev , & sinfo , NULL , & renderer - > quad_frag_module ) ;
res = vkCreateShaderModule ( dev , & sinfo , NULL , & renderer - > quad_frag_module ) ;
if ( res ! = VK_SUCCESS ) {
if ( res ! = VK_SUCCESS ) {
wlr_vk_error ( " Failed to create quad fragment shader module " , res ) ;
wlr_vk_error ( " Failed to create quad fragment shader module " , res ) ;
@ -1470,58 +1514,66 @@ static struct wlr_vk_render_format_setup *find_or_create_render_setup(
VkDevice dev = renderer - > dev - > dev ;
VkDevice dev = renderer - > dev - > dev ;
VkResult res ;
VkResult res ;
VkAttachmentDescription attachment = { 0 } ;
VkAttachmentDescription attachment = {
attachment . format = format ;
. format = format ,
attachment . samples = VK_SAMPLE_COUNT_1_BIT ;
. samples = VK_SAMPLE_COUNT_1_BIT ,
attachment . loadOp = VK_ATTACHMENT_LOAD_OP_LOAD ;
. loadOp = VK_ATTACHMENT_LOAD_OP_LOAD ,
attachment . storeOp = VK_ATTACHMENT_STORE_OP_STORE ;
. storeOp = VK_ATTACHMENT_STORE_OP_STORE ,
attachment . stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE ;
. stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE ,
attachment . stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE ;
. stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE ,
attachment . initialLayout = VK_IMAGE_LAYOUT_GENERAL ;
. initialLayout = VK_IMAGE_LAYOUT_GENERAL ,
attachment . finalLayout = VK_IMAGE_LAYOUT_GENERAL ;
. finalLayout = VK_IMAGE_LAYOUT_GENERAL ,
} ;
VkAttachmentReference color_ref = { 0 } ;
color_ref . attachment = 0u ;
VkAttachmentReference color_ref = {
color_ref . layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL ;
. attachment = 0u ,
. layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL ,
VkSubpassDescription subpass = { 0 } ;
} ;
subpass . pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS ;
subpass . colorAttachmentCount = 1 ;
VkSubpassDescription subpass = {
subpass . pColorAttachments = & color_ref ;
. pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS ,
. colorAttachmentCount = 1 ,
VkSubpassDependency deps [ 2 ] = { 0 } ;
. pColorAttachments = & color_ref ,
deps [ 0 ] . srcSubpass = VK_SUBPASS_EXTERNAL ;
} ;
deps [ 0 ] . srcStageMask = VK_PIPELINE_STAGE_HOST_BIT |
VkSubpassDependency deps [ 2 ] = {
{
. srcSubpass = VK_SUBPASS_EXTERNAL ,
. srcStageMask = VK_PIPELINE_STAGE_HOST_BIT |
VK_PIPELINE_STAGE_TRANSFER_BIT |
VK_PIPELINE_STAGE_TRANSFER_BIT |
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT |
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT |
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT ;
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT ,
deps [ 0 ] . srcAccessMask = VK_ACCESS_HOST_WRITE_BIT |
. srcAccessMask = VK_ACCESS_HOST_WRITE_BIT |
VK_ACCESS_TRANSFER_WRITE_BIT |
VK_ACCESS_TRANSFER_WRITE_BIT |
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT ;
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT ,
deps [ 0 ] . dstSubpass = 0 ;
. dstSubpass = 0 ,
deps [ 0 ] . dstStageMask = VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT ;
. dstStageMask = VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT ,
deps [ 0 ] . dstAccessMask = VK_ACCESS_UNIFORM_READ_BIT |
. dstAccessMask = VK_ACCESS_UNIFORM_READ_BIT |
VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT |
VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT |
VK_ACCESS_INDIRECT_COMMAND_READ_BIT |
VK_ACCESS_INDIRECT_COMMAND_READ_BIT |
VK_ACCESS_SHADER_READ_BIT ;
VK_ACCESS_SHADER_READ_BIT ,
} ,
deps [ 1 ] . srcSubpass = 0 ;
{
deps [ 1 ] . srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT ;
. srcSubpass = 0 ,
deps [ 1 ] . srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT ;
. srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT ,
deps [ 1 ] . dstSubpass = VK_SUBPASS_EXTERNAL ;
. srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT ,
deps [ 1 ] . dstStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT |
. dstSubpass = VK_SUBPASS_EXTERNAL ,
VK_PIPELINE_STAGE_HOST_BIT | VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT ;
. dstStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT |
deps [ 1 ] . dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT |
VK_PIPELINE_STAGE_HOST_BIT | VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT ,
VK_ACCESS_MEMORY_READ_BIT ;
. dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT |
VK_ACCESS_MEMORY_READ_BIT ,
VkRenderPassCreateInfo rp_info = { 0 } ;
} ,
rp_info . sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO ;
} ;
rp_info . attachmentCount = 1 ;
rp_info . pAttachments = & attachment ;
VkRenderPassCreateInfo rp_info = {
rp_info . subpassCount = 1 ;
. sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO ,
rp_info . pSubpasses = & subpass ;
. attachmentCount = 1 ,
rp_info . dependencyCount = 2u ;
. pAttachments = & attachment ,
rp_info . pDependencies = deps ;
. subpassCount = 1 ,
. pSubpasses = & subpass ,
. dependencyCount = 2u ,
. pDependencies = deps ,
} ;
res = vkCreateRenderPass ( dev , & rp_info , NULL , & setup - > render_pass ) ;
res = vkCreateRenderPass ( dev , & rp_info , NULL , & setup - > render_pass ) ;
if ( res ! = VK_SUCCESS ) {
if ( res ! = VK_SUCCESS ) {
@ -1535,85 +1587,97 @@ static struct wlr_vk_render_format_setup *find_or_create_render_setup(
goto error ;
goto error ;
}
}
VkPipelineShaderStageCreateInfo vert_stage = {
VkPipelineShaderStageCreateInfo quad_stages [ 2 ] = {
VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO ,
{
NULL , 0 , VK_SHADER_STAGE_VERTEX_BIT , renderer - > vert_module ,
. sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO ,
" main " , NULL
. stage = VK_SHADER_STAGE_VERTEX_BIT ,
. module = renderer - > vert_module ,
. pName = " main " ,
} ,
{
. sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO ,
. stage = VK_SHADER_STAGE_FRAGMENT_BIT ,
. module = renderer - > quad_frag_module ,
. pName = " main " ,
} ,
} ;
} ;
VkPipelineShaderStageCreateInfo quad_stages [ 2 ] = { vert_stage , {
VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO ,
NULL , 0 , VK_SHADER_STAGE_FRAGMENT_BIT ,
renderer - > quad_frag_module , " main " , NULL
} } ;
// info
// info
VkPipelineInputAssemblyStateCreateInfo assembly = { 0 } ;
VkPipelineInputAssemblyStateCreateInfo assembly = {
assembly . sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO ;
. sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO ,
assembly . topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN ;
. topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN ,
} ;
VkPipelineRasterizationStateCreateInfo rasterization = { 0 } ;
rasterization . sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO ;
VkPipelineRasterizationStateCreateInfo rasterization = {
rasterization . polygonMode = VK_POLYGON_MODE_FILL ;
. sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO ,
rasterization . cullMode = VK_CULL_MODE_NONE ;
. polygonMode = VK_POLYGON_MODE_FILL ,
rasterization . frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE ;
. cullMode = VK_CULL_MODE_NONE ,
rasterization . lineWidth = 1.f ;
. frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE ,
. lineWidth = 1.f ,
VkPipelineColorBlendAttachmentState blend_attachment = { 0 } ;
} ;
blend_attachment . blendEnable = true ;
blend_attachment . srcColorBlendFactor = VK_BLEND_FACTOR_ONE ;
VkPipelineColorBlendAttachmentState blend_attachment = {
blend_attachment . dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA ;
. blendEnable = true ,
blend_attachment . colorBlendOp = VK_BLEND_OP_ADD ;
. srcColorBlendFactor = VK_BLEND_FACTOR_ONE ,
blend_attachment . srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE ;
. dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA ,
blend_attachment . dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE ;
. colorBlendOp = VK_BLEND_OP_ADD ,
blend_attachment . alphaBlendOp = VK_BLEND_OP_ADD ;
. srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE ,
blend_attachment . colorWriteMask =
. dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE ,
. alphaBlendOp = VK_BLEND_OP_ADD ,
. colorWriteMask =
VK_COLOR_COMPONENT_R_BIT |
VK_COLOR_COMPONENT_R_BIT |
VK_COLOR_COMPONENT_G_BIT |
VK_COLOR_COMPONENT_G_BIT |
VK_COLOR_COMPONENT_B_BIT |
VK_COLOR_COMPONENT_B_BIT |
VK_COLOR_COMPONENT_A_BIT ;
VK_COLOR_COMPONENT_A_BIT ,
} ;
VkPipelineColorBlendStateCreateInfo blend = { 0 } ;
VkPipelineColorBlendStateCreateInfo blend = {
blend . sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO ;
. sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO ,
blend . attachmentCount = 1 ;
. attachmentCount = 1 ,
blend . pAttachments = & blend_attachment ;
. pAttachments = & blend_attachment ,
} ;
VkPipelineMultisampleStateCreateInfo multisample = { 0 } ;
VkPipelineMultisampleStateCreateInfo multisample = {
multisample . sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO ;
. sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO ,
multisample . rasterizationSamples = VK_SAMPLE_COUNT_1_BIT ;
. rasterizationSamples = VK_SAMPLE_COUNT_1_BIT ,
} ;
VkPipelineViewportStateCreateInfo viewport = { 0 } ;
VkPipelineViewportStateCreateInfo viewport = {
viewport . sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO ;
. sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO ,
viewport . viewportCount = 1 ;
. viewportCount = 1 ,
viewport . scissorCount = 1 ;
. scissorCount = 1 ,
} ;
VkDynamicState dynStates [ 2 ] = {
VkDynamicState dynStates [ 2 ] = {
VK_DYNAMIC_STATE_VIEWPORT ,
VK_DYNAMIC_STATE_VIEWPORT ,
VK_DYNAMIC_STATE_SCISSOR ,
VK_DYNAMIC_STATE_SCISSOR ,
} ;
} ;
VkPipelineDynamicStateCreateInfo dynamic = { 0 } ;
VkPipelineDynamicStateCreateInfo dynamic = {
dynamic . sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO ;
. sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO ,
dynamic . pDynamicStates = dynStates ;
. pDynamicStates = dynStates ,
dynamic . dynamicStateCount = 2 ;
. dynamicStateCount = 2 ,
} ;
VkPipelineVertexInputStateCreateInfo vertex = { 0 } ;
vertex . sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO ;
VkPipelineVertexInputStateCreateInfo vertex = {
. sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO ,
VkGraphicsPipelineCreateInfo pinfo = { 0 } ;
} ;
pinfo . sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO ;
pinfo . layout = renderer - > pipe_layout ;
VkGraphicsPipelineCreateInfo pinfo = {
pinfo . renderPass = setup - > render_pass ;
. sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO ,
pinfo . subpass = 0 ;
. layout = renderer - > pipe_layout ,
pinfo . stageCount = 2 ;
. renderPass = setup - > render_pass ,
pinfo . pStages = quad_stages ;
. subpass = 0 ,
. stageCount = 2 ,
pinfo . pInputAssemblyState = & assembly ;
. pStages = quad_stages ,
pinfo . pRasterizationState = & rasterization ;
pinfo . pColorBlendState = & blend ;
. pInputAssemblyState = & assembly ,
pinfo . pMultisampleState = & multisample ;
. pRasterizationState = & rasterization ,
pinfo . pViewportState = & viewport ;
. pColorBlendState = & blend ,
pinfo . pDynamicState = & dynamic ;
. pMultisampleState = & multisample ,
pinfo . pVertexInputState = & vertex ;
. pViewportState = & viewport ,
. pDynamicState = & dynamic ,
. pVertexInputState = & vertex ,
} ;
// NOTE: use could use a cache here for faster loading
// NOTE: use could use a cache here for faster loading
// store it somewhere like $XDG_CACHE_HOME/wlroots/vk_pipe_cache.bin
// store it somewhere like $XDG_CACHE_HOME/wlroots/vk_pipe_cache.bin
@ -1655,10 +1719,11 @@ struct wlr_renderer *vulkan_renderer_create_for_device(struct wlr_vk_device *dev
}
}
// command pool
// command pool
VkCommandPoolCreateInfo cpool_info = { 0 } ;
VkCommandPoolCreateInfo cpool_info = {
cpool_info . sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO ;
. sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO ,
cpool_info . flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT ;
. flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT ,
cpool_info . queueFamilyIndex = dev - > queue_family ;
. queueFamilyIndex = dev - > queue_family ,
} ;
res = vkCreateCommandPool ( dev - > dev , & cpool_info , NULL ,
res = vkCreateCommandPool ( dev - > dev , & cpool_info , NULL ,
& renderer - > command_pool ) ;
& renderer - > command_pool ) ;
if ( res ! = VK_SUCCESS ) {
if ( res ! = VK_SUCCESS ) {
@ -1666,19 +1731,21 @@ struct wlr_renderer *vulkan_renderer_create_for_device(struct wlr_vk_device *dev
goto error ;
goto error ;
}
}
VkCommandBufferAllocateInfo cbai = { 0 } ;
VkCommandBufferAllocateInfo cbai = {
cbai . sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO ;
. sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO ,
cbai . commandBufferCount = 1u ;
. commandBufferCount = 1u ,
cbai . commandPool = renderer - > command_pool ;
. commandPool = renderer - > command_pool ,
cbai . level = VK_COMMAND_BUFFER_LEVEL_PRIMARY ;
. level = VK_COMMAND_BUFFER_LEVEL_PRIMARY ,
} ;
res = vkAllocateCommandBuffers ( dev - > dev , & cbai , & renderer - > cb ) ;
res = vkAllocateCommandBuffers ( dev - > dev , & cbai , & renderer - > cb ) ;
if ( res ! = VK_SUCCESS ) {
if ( res ! = VK_SUCCESS ) {
wlr_vk_error ( " vkAllocateCommandBuffers " , res ) ;
wlr_vk_error ( " vkAllocateCommandBuffers " , res ) ;
goto error ;
goto error ;
}
}
VkFenceCreateInfo fence_info = { 0 } ;
VkFenceCreateInfo fence_info = {
fence_info . sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO ;
. sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO ,
} ;
res = vkCreateFence ( dev - > dev , & fence_info , NULL ,
res = vkCreateFence ( dev - > dev , & fence_info , NULL ,
& renderer - > fence ) ;
& renderer - > fence ) ;
if ( res ! = VK_SUCCESS ) {
if ( res ! = VK_SUCCESS ) {
@ -1687,11 +1754,12 @@ struct wlr_renderer *vulkan_renderer_create_for_device(struct wlr_vk_device *dev
}
}
// staging command buffer
// staging command buffer
VkCommandBufferAllocateInfo cmd_buf_info = { 0 } ;
VkCommandBufferAllocateInfo cmd_buf_info = {
cmd_buf_info . sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO ;
. sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO ,
cmd_buf_info . commandPool = renderer - > command_pool ;
. commandPool = renderer - > command_pool ,
cmd_buf_info . level = VK_COMMAND_BUFFER_LEVEL_PRIMARY ;
. level = VK_COMMAND_BUFFER_LEVEL_PRIMARY ,
cmd_buf_info . commandBufferCount = 1u ;
. commandBufferCount = 1u ,
} ;
res = vkAllocateCommandBuffers ( dev - > dev , & cmd_buf_info ,
res = vkAllocateCommandBuffers ( dev - > dev , & cmd_buf_info ,
& renderer - > stage . cb ) ;
& renderer - > stage . cb ) ;
if ( res ! = VK_SUCCESS ) {
if ( res ! = VK_SUCCESS ) {