]> git.tdb.fi Git - libs/gl.git/blob - source/backends/vulkan/pipelinestate_backend.cpp
4eba2895e4925cd9282672a22d207f248ca4d2a4
[libs/gl.git] / source / backends / vulkan / pipelinestate_backend.cpp
1 #include <msp/core/algorithm.h>
2 #include <msp/core/hash.h>
3 #include "batch.h"
4 #include "blend.h"
5 #include "buffer.h"
6 #include "depthtest.h"
7 #include "device.h"
8 #include "framebuffer.h"
9 #include "pipelinestate.h"
10 #include "pipelinestate_backend.h"
11 #include "program.h"
12 #include "rect.h"
13 #include "sampler.h"
14 #include "stenciltest.h"
15 #include "structurebuilder.h"
16 #include "texture.h"
17 #include "uniformblock.h"
18 #include "vertexsetup.h"
19 #include "vulkan.h"
20
21 using namespace std;
22
23 namespace Msp {
24 namespace GL {
25
26 VulkanPipelineState::VulkanPipelineState():
27         device(Device::get_current())
28 { }
29
30 VulkanPipelineState::VulkanPipelineState(VulkanPipelineState &&other):
31         device(other.device),
32         handle(other.handle)
33 { }
34
35 void VulkanPipelineState::update() const
36 {
37         const PipelineState &self = *static_cast<const PipelineState *>(this);
38
39         unapplied |= changes&(PipelineState::VIEWPORT|PipelineState::SCISSOR|PipelineState::VERTEX_SETUP);
40
41         if(changes&PipelineState::VERTEX_SETUP)
42                 self.vertex_setup->refresh();
43
44         constexpr unsigned pipeline_mask = PipelineState::SHPROG|PipelineState::VERTEX_SETUP|PipelineState::FACE_CULL|
45                 PipelineState::DEPTH_TEST|PipelineState::STENCIL_TEST|PipelineState::BLEND|PipelineState::PRIMITIVE_TYPE;
46         if(changes&pipeline_mask)
47         {
48                 handle = device.get_pipeline_cache().get_pipeline(self);
49                 unapplied |= PipelineState::SHPROG;
50         }
51
52         if(changes&(PipelineState::SHPROG|PipelineState::UNIFORMS|PipelineState::TEXTURES))
53         {
54                 unsigned changed_sets = (changes&PipelineState::SHPROG ? ~0U : 0U);
55                 for(const PipelineState::BoundUniformBlock &u: self.uniform_blocks)
56                         if(u.changed || changed_sets==~0U)
57                         {
58                                 if(u.block)
59                                         u.used = self.shprog->uses_uniform_block_binding(u.binding);
60                                 if(u.binding>=0)
61                                         changed_sets |= 1<<(u.binding>>20);
62                                 u.changed = false;
63                         }
64                 for(const PipelineState::BoundTexture &t: self.textures)
65                         if(t.changed || changed_sets==~0U)
66                         {
67                                 if(t.texture && t.sampler)
68                                         t.used = self.shprog->uses_texture_binding(t.binding);
69                                 changed_sets |= 1<<(t.binding>>20);
70                                 if(t.texture && t.level>=0)
71                                         t.texture->refresh_mip_views();
72                                 if(t.sampler)
73                                         t.sampler->refresh();
74                                 t.changed = false;
75                         }
76
77                 if(changed_sets)
78                 {
79                         descriptor_set_slots.resize(self.shprog->get_n_descriptor_sets());
80                         first_changed_desc_set = descriptor_set_slots.size();
81                         for(unsigned i=0; i<descriptor_set_slots.size(); ++i)
82                                 if(changed_sets&(1<<i))
83                                 {
84                                         descriptor_set_slots[i] = device.get_descriptor_pool().get_descriptor_set_slot(self, i);
85                                         first_changed_desc_set = min(first_changed_desc_set, i);
86                                 }
87
88                         unapplied |= PipelineState::UNIFORMS;
89                 }
90         }
91
92         changes = 0;
93 }
94
95 uint64_t VulkanPipelineState::compute_hash() const
96 {
97         const PipelineState &self = *static_cast<const PipelineState *>(this);
98         const FrameFormat &format = self.framebuffer->get_format();
99
100         uint64_t result = hash<64>(self.shprog);
101         result = hash_update<64>(result, self.vertex_setup->compute_hash());
102         result = hash_round<64>(result, self.primitive_type);
103
104         if(self.front_face!=NON_MANIFOLD && self.face_cull!=NO_CULL)
105         {
106                 result = hash_round<64>(result, self.front_face);
107                 result = hash_round<64>(result, self.face_cull);
108         }
109
110         result = hash_round<64>(result, format.get_samples());
111
112         if(self.depth_test.enabled)
113         {
114                 result = hash_round<64>(result, self.depth_test.compare);
115                 result = hash_update<64>(result, self.depth_test.write);
116         }
117
118         if(self.stencil_test.enabled)
119         {
120                 result = hash_round<64>(result, self.stencil_test.compare);
121                 result = hash_round<64>(result, self.stencil_test.stencil_fail_op);
122                 result = hash_round<64>(result, self.stencil_test.depth_fail_op);
123                 result = hash_round<64>(result, self.stencil_test.depth_pass_op);
124                 result = hash_update<64>(result, self.stencil_test.reference);
125         }
126
127         if(self.blend.enabled)
128         {
129                 result = hash_round<64>(result, self.blend.equation);
130                 result = hash_round<64>(result, self.blend.src_factor);
131                 result = hash_round<64>(result, self.blend.dst_factor);
132                 result = hash_round<64>(result, self.blend.write_mask);
133         }
134
135         for(FrameAttachment a: format)
136                 result = hash_update<64>(result, a);
137
138         return result;
139 }
140
141 void VulkanPipelineState::fill_creation_info(vector<char> &buffer) const
142 {
143         const PipelineState &self = *static_cast<const PipelineState *>(this);
144
145         const FrameFormat &format = self.framebuffer->get_format();
146         VkRenderPass render_pass = device.get_pipeline_cache().get_render_pass(format, false, false, false);
147
148         unsigned n_color_attachments = 0;
149         for(FrameAttachment a: format)
150         {
151                 unsigned attach_pt = get_attach_point(a);
152                 if(attach_pt!=get_attach_point(DEPTH_ATTACHMENT) && attach_pt!=get_attach_point(STENCIL_ATTACHMENT))
153                         ++n_color_attachments;
154         }
155
156         StructureBuilder sb(buffer, 10);
157         VkGraphicsPipelineCreateInfo *&pipeline_info = sb.add<VkGraphicsPipelineCreateInfo>();
158         VkPipelineInputAssemblyStateCreateInfo *&input_assembly_info = sb.add<VkPipelineInputAssemblyStateCreateInfo>();
159         VkPipelineViewportStateCreateInfo *&viewport_info = sb.add<VkPipelineViewportStateCreateInfo>();
160         VkPipelineRasterizationStateCreateInfo *&raster_info = sb.add<VkPipelineRasterizationStateCreateInfo>();
161         VkPipelineMultisampleStateCreateInfo *&multisample_info = sb.add<VkPipelineMultisampleStateCreateInfo>();
162         VkPipelineDepthStencilStateCreateInfo *&depth_stencil_info = sb.add<VkPipelineDepthStencilStateCreateInfo>();
163         VkPipelineColorBlendStateCreateInfo *&blend_info = sb.add<VkPipelineColorBlendStateCreateInfo>();
164         VkPipelineColorBlendAttachmentState *&blend_attachments = sb.add<VkPipelineColorBlendAttachmentState>(n_color_attachments);
165         VkPipelineDynamicStateCreateInfo *&dynamic_info = sb.add<VkPipelineDynamicStateCreateInfo>();
166         VkDynamicState *&dynamic_states = sb.add<VkDynamicState>(2);
167
168         input_assembly_info->sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
169         input_assembly_info->topology = static_cast<VkPrimitiveTopology>(get_vulkan_primitive_type(self.primitive_type));
170         input_assembly_info->primitiveRestartEnable = true;
171
172         viewport_info->sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
173         viewport_info->viewportCount = 1;
174         viewport_info->pViewports = 0;
175         viewport_info->scissorCount = 1;
176         viewport_info->pScissors = 0;
177
178         raster_info->sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
179         raster_info->depthClampEnable = VK_FALSE;
180         raster_info->rasterizerDiscardEnable = VK_FALSE;
181         raster_info->polygonMode = VK_POLYGON_MODE_FILL;
182         raster_info->frontFace = (self.front_face==CLOCKWISE ? VK_FRONT_FACE_COUNTER_CLOCKWISE : VK_FRONT_FACE_CLOCKWISE);
183         if(self.face_cull==NO_CULL || self.front_face==NON_MANIFOLD)
184                 raster_info->cullMode = VK_CULL_MODE_NONE;
185         else
186                 raster_info->cullMode = (self.face_cull==CULL_FRONT ? VK_CULL_MODE_FRONT_BIT : VK_CULL_MODE_BACK_BIT);
187         raster_info->depthBiasEnable = VK_FALSE;
188         raster_info->depthBiasConstantFactor = 0.0f;
189         raster_info->depthBiasClamp = 0.0f;
190         raster_info->depthBiasSlopeFactor = 0.0f;
191         raster_info->lineWidth = 1.0f;
192
193         multisample_info->sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
194         multisample_info->rasterizationSamples = static_cast<VkSampleCountFlagBits>(get_vulkan_samples(format.get_samples()));
195         multisample_info->sampleShadingEnable = VK_FALSE;
196         multisample_info->minSampleShading = 1.0f;
197         multisample_info->pSampleMask = 0;
198         multisample_info->alphaToCoverageEnable = VK_FALSE;
199         multisample_info->alphaToOneEnable = VK_FALSE;
200
201         depth_stencil_info->sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
202         depth_stencil_info->depthTestEnable = self.depth_test.enabled;
203         depth_stencil_info->depthWriteEnable = self.depth_test.write;
204         depth_stencil_info->depthCompareOp = static_cast<VkCompareOp>(get_vulkan_predicate(self.depth_test.compare));
205         depth_stencil_info->depthBoundsTestEnable = VK_FALSE;
206
207         depth_stencil_info->stencilTestEnable = self.stencil_test.enabled;
208         depth_stencil_info->front.failOp = static_cast<VkStencilOp>(get_vulkan_stencil_op(self.stencil_test.stencil_fail_op));
209         depth_stencil_info->front.passOp = static_cast<VkStencilOp>(get_vulkan_stencil_op(self.stencil_test.depth_pass_op));
210         depth_stencil_info->front.depthFailOp = static_cast<VkStencilOp>(get_vulkan_stencil_op(self.stencil_test.depth_fail_op));
211         depth_stencil_info->front.compareOp = static_cast<VkCompareOp>(get_vulkan_predicate(self.stencil_test.compare));
212         depth_stencil_info->front.compareMask = 0xFFFFFFFFU;
213         depth_stencil_info->front.writeMask = 0xFFFFFFFFU;
214         depth_stencil_info->front.reference = self.stencil_test.reference;
215         depth_stencil_info->back = depth_stencil_info->front;
216
217         for(unsigned i=0; i<n_color_attachments; ++i)
218         {
219                 blend_attachments[i].blendEnable = self.blend.enabled;
220                 blend_attachments[i].srcColorBlendFactor = static_cast<VkBlendFactor>(get_vulkan_blend_factor(self.blend.src_factor));
221                 blend_attachments[i].dstColorBlendFactor = static_cast<VkBlendFactor>(get_vulkan_blend_factor(self.blend.dst_factor));
222                 blend_attachments[i].colorBlendOp = static_cast<VkBlendOp>(get_vulkan_blend_equation(self.blend.equation));
223                 blend_attachments[i].srcAlphaBlendFactor = blend_attachments[i].srcColorBlendFactor;
224                 blend_attachments[i].dstAlphaBlendFactor = blend_attachments[i].dstColorBlendFactor;
225                 blend_attachments[i].alphaBlendOp = blend_attachments[i].colorBlendOp;
226                 blend_attachments[i].colorWriteMask = get_vulkan_color_mask(self.blend.write_mask);
227         }
228
229         blend_info->sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
230         blend_info->attachmentCount = n_color_attachments;
231         blend_info->pAttachments = blend_attachments;
232
233         dynamic_states[0] = VK_DYNAMIC_STATE_VIEWPORT;
234         dynamic_states[1] = VK_DYNAMIC_STATE_SCISSOR;
235
236         dynamic_info->sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
237         dynamic_info->dynamicStateCount = 2;
238         dynamic_info->pDynamicStates = dynamic_states;
239
240         pipeline_info->sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
241
242         pipeline_info->pInputAssemblyState = input_assembly_info;
243         pipeline_info->pTessellationState = 0;
244         pipeline_info->pViewportState = viewport_info;
245         pipeline_info->pRasterizationState = raster_info;
246         pipeline_info->pMultisampleState = multisample_info;
247         pipeline_info->pDepthStencilState = depth_stencil_info;
248         pipeline_info->pColorBlendState = blend_info;
249         pipeline_info->pDynamicState = dynamic_info;
250         pipeline_info->renderPass = handle_cast<::VkRenderPass>(render_pass);
251         pipeline_info->subpass = 0;
252
253         if(self.shprog)
254         {
255                 pipeline_info->stageCount = self.shprog->n_stages;
256                 pipeline_info->pStages = reinterpret_cast<const VkPipelineShaderStageCreateInfo *>(self.shprog->creation_info.data());
257                 pipeline_info->layout = handle_cast<::VkPipelineLayout>(self.shprog->layout_handle);
258         }
259
260         if(self.vertex_setup)
261                 pipeline_info->pVertexInputState = reinterpret_cast<const VkPipelineVertexInputStateCreateInfo *>(self.vertex_setup->creation_info.data());
262 }
263
264 uint64_t VulkanPipelineState::compute_descriptor_set_hash(unsigned index) const
265 {
266         const PipelineState &self = *static_cast<const PipelineState *>(this);
267
268         uint64_t result = hash<64>(0, 0);
269         bool empty = true;
270
271         auto i = lower_bound_member(self.uniform_blocks, static_cast<int>(index)<<20, &PipelineState::BoundUniformBlock::binding);
272         for(; (i!=self.uniform_blocks.end() && static_cast<unsigned>(i->binding)>>20==index); ++i)
273                 if(i->used)
274                 {
275                         result = hash_update<64>(result, i->binding);
276                         result = hash_update<64>(result, reinterpret_cast<uintptr_t>(i->block));
277                         result = hash_update<64>(result, reinterpret_cast<uintptr_t>(i->buffer->handle));
278                         empty = false;
279                 }
280
281         auto j = lower_bound_member(self.textures, index<<20, &PipelineState::BoundTexture::binding);
282         for(; (j!=self.textures.end() && j->binding>>20==index); ++j)
283                 if(j->used)
284                 {
285                         result = hash_update<64>(result, j->binding);
286                         result = hash_update<64>(result, reinterpret_cast<uintptr_t>(j->texture->handle));
287                         result = hash_update<64>(result, reinterpret_cast<uintptr_t>(j->sampler->handle));
288                         result = hash_update<64>(result, j->level);
289                         empty = false;
290                 }
291
292         if(!empty)
293                 result = hash_update<64>(result, self.shprog->stage_flags);
294
295         return result;
296 }
297
298 bool VulkanPipelineState::is_descriptor_set_dynamic(unsigned index) const
299 {
300         const PipelineState &self = *static_cast<const PipelineState *>(this);
301
302         auto i = lower_bound_member(self.uniform_blocks, static_cast<int>(index)<<20, &PipelineState::BoundUniformBlock::binding);
303         for(; (i!=self.uniform_blocks.end() && static_cast<unsigned>(i->binding)>>20==index); ++i)
304                 if(i->used && i->buffer && i->buffer->get_usage()==STREAMING)
305                         return true;
306
307         return false;
308 }
309
310 VkDescriptorSetLayout VulkanPipelineState::get_descriptor_set_layout(unsigned index) const
311 {
312         return static_cast<const PipelineState *>(this)->shprog->desc_set_layout_handles[index];
313 }
314
315 unsigned VulkanPipelineState::fill_descriptor_writes(unsigned index, unsigned frame, vector<char> &buffer) const
316 {
317         const PipelineState &self = *static_cast<const PipelineState *>(this);
318
319         auto u_begin = lower_bound_member(self.uniform_blocks, static_cast<int>(index)<<20, &PipelineState::BoundUniformBlock::binding);
320         auto t_begin = lower_bound_member(self.textures, index<<20, &PipelineState::BoundTexture::binding);
321
322         unsigned n_buffers = 0;
323         for(auto i=u_begin; (i!=self.uniform_blocks.end() && static_cast<unsigned>(i->binding)>>20==index); ++i)
324                 if(i->used)
325                         ++n_buffers;
326         unsigned n_images = 0;
327         for(auto i=t_begin; (i!=self.textures.end() && i->binding>>20==index); ++i)
328                 if(i->used)
329                         ++n_images;
330         unsigned n_writes = n_buffers+n_images;
331
332         StructureBuilder sb(buffer, 3);
333         VkWriteDescriptorSet *&writes = sb.add<VkWriteDescriptorSet>(n_writes);
334         VkDescriptorBufferInfo *&buffers = sb.add<VkDescriptorBufferInfo>(n_buffers);
335         VkDescriptorImageInfo *&images = sb.add<VkDescriptorImageInfo>(n_images);
336
337         VkWriteDescriptorSet *write_ptr = writes;
338         VkDescriptorBufferInfo *buffer_ptr = buffers;
339         VkDescriptorImageInfo *image_ptr = images;
340
341         for(auto i=u_begin; (i!=self.uniform_blocks.end() && static_cast<unsigned>(i->binding)>>20==index); ++i)
342                 if(i->used)
343                 {
344                         buffer_ptr->buffer = handle_cast<::VkBuffer>(i->buffer->handle);
345                         buffer_ptr->offset = i->block->get_offset();
346                         if(i->buffer->get_usage()==STREAMING)
347                                 buffer_ptr->offset += frame*i->buffer->get_size();
348                         buffer_ptr->range = i->block->get_data_size();
349
350                         write_ptr->sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
351                         write_ptr->dstBinding = i->binding&0xFFFFF;
352                         write_ptr->descriptorCount = 1;
353                         write_ptr->descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
354                         write_ptr->pBufferInfo = buffer_ptr;
355
356                         ++buffer_ptr;
357                         ++write_ptr;
358                 }
359
360         for(auto i=t_begin; (i!=self.textures.end() && i->binding>>20==index); ++i)
361                 if(i->used)
362                 {
363                         image_ptr->sampler = handle_cast<::VkSampler>(i->sampler->handle);
364                         if(i->level<0)
365                                 image_ptr->imageView = handle_cast<::VkImageView>(i->texture->view_handle);
366                         else
367                                 image_ptr->imageView = handle_cast<::VkImageView>(i->texture->mip_view_handles[i->level]);
368                         image_ptr->imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
369
370                         write_ptr->sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
371                         write_ptr->dstBinding = i->binding&0xFFFFF;
372                         write_ptr->descriptorCount = 1;
373                         write_ptr->descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
374                         write_ptr->pImageInfo = image_ptr;
375
376                         ++image_ptr;
377                         ++write_ptr;
378                 }
379
380         return n_writes;
381 }
382
383 void VulkanPipelineState::apply(VkCommandBuffer command_buffer, const VulkanPipelineState *last, unsigned frame, bool negative_viewport) const
384 {
385         const PipelineState &self = *static_cast<const PipelineState *>(this);
386         const VulkanFunctions &vk = device.get_functions();
387
388         if(!last)
389         {
390                 unapplied = ~0U;
391                 first_changed_desc_set = 0;
392         }
393         else if(last!=this)
394         {
395                 const PipelineState &last_ps = *static_cast<const PipelineState *>(last);
396                 if(handle!=last->handle)
397                 {
398                         unapplied |= PipelineState::SHPROG;
399                         if(self.shprog->stage_flags!=last_ps.shprog->stage_flags)
400                         {
401                                 unapplied |= PipelineState::UNIFORMS;
402                                 first_changed_desc_set = 0;
403                         }
404                 }
405                 if(self.vertex_setup!=last_ps.vertex_setup)
406                         unapplied |= PipelineState::VERTEX_SETUP;
407                 for(unsigned i=0; i<descriptor_set_slots.size(); ++i)
408                         if(i>=last->descriptor_set_slots.size() || descriptor_set_slots[i]!=last->descriptor_set_slots[i])
409                         {
410                                 unapplied |= PipelineState::UNIFORMS;
411                                 first_changed_desc_set = min(first_changed_desc_set, i);
412                                 break;
413                         }
414                 if(self.viewport!=last_ps.viewport)
415                         unapplied |= PipelineState::VIEWPORT;
416                 if(self.scissor!=last_ps.scissor)
417                         unapplied |= PipelineState::SCISSOR;
418         }
419
420         if(unapplied&PipelineState::SHPROG)
421                 vk.CmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, handle);
422
423         if(unapplied&PipelineState::VERTEX_SETUP)
424                 if(const VertexSetup *vs = self.vertex_setup)
425                 {
426                         vk.CmdBindVertexBuffers(command_buffer, 0, vs->n_bindings, vs->buffers, vs->offsets);
427                         VkIndexType index_type = static_cast<VkIndexType>(get_vulkan_index_type(vs->get_index_type()));
428                         vk.CmdBindIndexBuffer(command_buffer, vs->get_index_buffer()->handle, 0, index_type);
429                 }
430
431         if(!self.uniform_blocks.empty())
432         {
433                 const PipelineState::BoundUniformBlock &first_block = self.uniform_blocks.front();
434                 if(first_block.used && first_block.binding==ReflectData::PUSH_CONSTANT)
435                 {
436                         const UniformBlock &pc_block = *first_block.block;
437                         vk.CmdPushConstants(command_buffer, self.shprog->layout_handle, self.shprog->stage_flags,
438                                 pc_block.get_offset(), pc_block.get_data_size(), pc_block.get_data_pointer());
439                 }
440         }
441
442         if((unapplied&PipelineState::UNIFORMS) && !descriptor_set_slots.empty())
443         {
444                 vector<VkDescriptorSet> descriptor_set_handles;
445                 descriptor_set_handles.reserve(descriptor_set_slots.size()-first_changed_desc_set);
446                 for(unsigned i=first_changed_desc_set; i<descriptor_set_slots.size(); ++i)
447                         descriptor_set_handles.push_back(device.get_descriptor_pool().get_descriptor_set(
448                                 self.descriptor_set_slots[i], self, i, frame));
449
450                 vk.CmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, self.shprog->layout_handle,
451                         first_changed_desc_set, descriptor_set_handles.size(), descriptor_set_handles.data(), 0, 0);
452         }
453
454         if(unapplied&(PipelineState::VIEWPORT|PipelineState::SCISSOR))
455         {
456                 Rect fb_rect = self.framebuffer->get_rect();
457
458                 if(unapplied&PipelineState::VIEWPORT)
459                 {
460                         Rect viewport_rect = fb_rect.intersect(self.viewport);
461                         VkViewport viewport = { };
462                         viewport.x = viewport_rect.left;
463                         viewport.y = viewport_rect.bottom;
464                         viewport.width = viewport_rect.width;
465                         viewport.height = viewport_rect.height;
466                         if(negative_viewport)
467                         {
468                                 viewport.y += viewport.height;
469                                 viewport.height = -viewport.height;
470                         }
471                         viewport.minDepth = 0.0f;
472                         viewport.maxDepth = 1.0f;
473                         vk.CmdSetViewport(command_buffer, 0, 1, &viewport);
474                 }
475
476                 if(unapplied&PipelineState::SCISSOR)
477                 {
478                         Rect scissor_rect = fb_rect.intersect(self.scissor);
479                         VkRect2D scissor = { };
480                         scissor.offset.x = scissor_rect.left;
481                         scissor.offset.y = scissor_rect.bottom;
482                         scissor.extent.width = scissor_rect.width;
483                         scissor.extent.height = scissor_rect.height;
484                         vk.CmdSetScissor(command_buffer, 0, 1, &scissor);
485                 }
486         }
487
488         unapplied = 0;
489         first_changed_desc_set = descriptor_set_slots.size();
490 }
491
492 } // namespace GL
493 } // namespace Msp