2 * Copyright © 2016 Red Hat
5 * Copyright © 2016 Intel Corporation
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27 #include "radv_meta.h"
28 #include "nir/nir_builder.h"
29 #include "vk_format.h"
31 enum blit2d_dst_type
{
32 /* We can bind this destination as a "normal" render target and render
33 * to it just like you would anywhere else.
35 BLIT2D_DST_TYPE_NORMAL
,
37 /* The destination has a 3-channel RGB format. Since we can't render to
38 * non-power-of-two textures, we have to bind it as a red texture and
39 * select the correct component for the given red pixel in the shader.
47 enum blit2d_src_type
{
48 BLIT2D_SRC_TYPE_IMAGE
,
49 BLIT2D_SRC_TYPE_BUFFER
,
54 create_iview(struct radv_cmd_buffer
*cmd_buffer
,
55 struct radv_meta_blit2d_surf
*surf
,
56 VkImageUsageFlags usage
,
57 struct radv_image_view
*iview
, VkFormat depth_format
)
62 format
= depth_format
;
64 format
= surf
->format
;
66 radv_image_view_init(iview
, cmd_buffer
->device
,
67 &(VkImageViewCreateInfo
) {
68 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
69 .image
= radv_image_to_handle(surf
->image
),
70 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
73 .aspectMask
= surf
->aspect_mask
,
74 .baseMipLevel
= surf
->level
,
76 .baseArrayLayer
= surf
->layer
,
79 }, cmd_buffer
, usage
);
83 create_bview(struct radv_cmd_buffer
*cmd_buffer
,
84 struct radv_meta_blit2d_buffer
*src
,
85 struct radv_buffer_view
*bview
, VkFormat depth_format
)
90 format
= depth_format
;
93 radv_buffer_view_init(bview
, cmd_buffer
->device
,
94 &(VkBufferViewCreateInfo
) {
95 .sType
= VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO
,
97 .buffer
= radv_buffer_to_handle(src
->buffer
),
99 .offset
= src
->offset
,
100 .range
= VK_WHOLE_SIZE
,
105 struct blit2d_src_temps
{
106 struct radv_image_view iview
;
107 struct radv_buffer_view bview
;
111 blit2d_bind_src(struct radv_cmd_buffer
*cmd_buffer
,
112 struct radv_meta_blit2d_surf
*src_img
,
113 struct radv_meta_blit2d_buffer
*src_buf
,
114 struct blit2d_src_temps
*tmp
,
115 enum blit2d_src_type src_type
, VkFormat depth_format
)
117 struct radv_device
*device
= cmd_buffer
->device
;
119 if (src_type
== BLIT2D_SRC_TYPE_BUFFER
) {
120 create_bview(cmd_buffer
, src_buf
, &tmp
->bview
, depth_format
);
122 radv_meta_push_descriptor_set(cmd_buffer
, VK_PIPELINE_BIND_POINT_GRAPHICS
,
123 device
->meta_state
.blit2d
.p_layouts
[src_type
],
125 1, /* descriptorWriteCount */
126 (VkWriteDescriptorSet
[]) {
128 .sType
= VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET
,
130 .dstArrayElement
= 0,
131 .descriptorCount
= 1,
132 .descriptorType
= VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
,
133 .pTexelBufferView
= (VkBufferView
[]) { radv_buffer_view_to_handle(&tmp
->bview
) }
137 radv_CmdPushConstants(radv_cmd_buffer_to_handle(cmd_buffer
),
138 device
->meta_state
.blit2d
.p_layouts
[src_type
],
139 VK_SHADER_STAGE_FRAGMENT_BIT
, 0, 4,
142 create_iview(cmd_buffer
, src_img
, VK_IMAGE_USAGE_SAMPLED_BIT
, &tmp
->iview
,
145 radv_meta_push_descriptor_set(cmd_buffer
, VK_PIPELINE_BIND_POINT_GRAPHICS
,
146 device
->meta_state
.blit2d
.p_layouts
[src_type
],
148 1, /* descriptorWriteCount */
149 (VkWriteDescriptorSet
[]) {
151 .sType
= VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET
,
153 .dstArrayElement
= 0,
154 .descriptorCount
= 1,
155 .descriptorType
= VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
,
156 .pImageInfo
= (VkDescriptorImageInfo
[]) {
158 .sampler
= VK_NULL_HANDLE
,
159 .imageView
= radv_image_view_to_handle(&tmp
->iview
),
160 .imageLayout
= VK_IMAGE_LAYOUT_GENERAL
,
168 struct blit2d_dst_temps
{
170 struct radv_image_view iview
;
175 blit2d_bind_dst(struct radv_cmd_buffer
*cmd_buffer
,
176 struct radv_meta_blit2d_surf
*dst
,
179 VkFormat depth_format
,
180 struct blit2d_dst_temps
*tmp
)
182 VkImageUsageFlagBits bits
;
184 if (dst
->aspect_mask
== VK_IMAGE_ASPECT_COLOR_BIT
)
185 bits
= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
;
187 bits
= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
;
189 create_iview(cmd_buffer
, dst
, bits
,
190 &tmp
->iview
, depth_format
);
192 radv_CreateFramebuffer(radv_device_to_handle(cmd_buffer
->device
),
193 &(VkFramebufferCreateInfo
) {
194 .sType
= VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
,
195 .attachmentCount
= 1,
196 .pAttachments
= (VkImageView
[]) {
197 radv_image_view_to_handle(&tmp
->iview
),
202 }, &cmd_buffer
->pool
->alloc
, &tmp
->fb
);
206 blit2d_unbind_dst(struct radv_cmd_buffer
*cmd_buffer
,
207 struct blit2d_dst_temps
*tmp
)
209 VkDevice vk_device
= radv_device_to_handle(cmd_buffer
->device
);
210 radv_DestroyFramebuffer(vk_device
, tmp
->fb
, &cmd_buffer
->pool
->alloc
);
214 bind_pipeline(struct radv_cmd_buffer
*cmd_buffer
,
215 enum blit2d_src_type src_type
, unsigned fs_key
)
217 VkPipeline pipeline
=
218 cmd_buffer
->device
->meta_state
.blit2d
.pipelines
[src_type
][fs_key
];
220 if (cmd_buffer
->state
.pipeline
!= radv_pipeline_from_handle(pipeline
)) {
221 radv_CmdBindPipeline(radv_cmd_buffer_to_handle(cmd_buffer
),
222 VK_PIPELINE_BIND_POINT_GRAPHICS
, pipeline
);
227 bind_depth_pipeline(struct radv_cmd_buffer
*cmd_buffer
,
228 enum blit2d_src_type src_type
)
230 VkPipeline pipeline
=
231 cmd_buffer
->device
->meta_state
.blit2d
.depth_only_pipeline
[src_type
];
233 if (cmd_buffer
->state
.pipeline
!= radv_pipeline_from_handle(pipeline
)) {
234 radv_CmdBindPipeline(radv_cmd_buffer_to_handle(cmd_buffer
),
235 VK_PIPELINE_BIND_POINT_GRAPHICS
, pipeline
);
240 bind_stencil_pipeline(struct radv_cmd_buffer
*cmd_buffer
,
241 enum blit2d_src_type src_type
)
243 VkPipeline pipeline
=
244 cmd_buffer
->device
->meta_state
.blit2d
.stencil_only_pipeline
[src_type
];
246 if (cmd_buffer
->state
.pipeline
!= radv_pipeline_from_handle(pipeline
)) {
247 radv_CmdBindPipeline(radv_cmd_buffer_to_handle(cmd_buffer
),
248 VK_PIPELINE_BIND_POINT_GRAPHICS
, pipeline
);
253 radv_meta_blit2d_normal_dst(struct radv_cmd_buffer
*cmd_buffer
,
254 struct radv_meta_blit2d_surf
*src_img
,
255 struct radv_meta_blit2d_buffer
*src_buf
,
256 struct radv_meta_blit2d_surf
*dst
,
258 struct radv_meta_blit2d_rect
*rects
, enum blit2d_src_type src_type
)
260 struct radv_device
*device
= cmd_buffer
->device
;
262 for (unsigned r
= 0; r
< num_rects
; ++r
) {
263 VkFormat depth_format
= 0;
264 if (dst
->aspect_mask
== VK_IMAGE_ASPECT_STENCIL_BIT
)
265 depth_format
= vk_format_stencil_only(dst
->image
->vk_format
);
266 else if (dst
->aspect_mask
== VK_IMAGE_ASPECT_DEPTH_BIT
)
267 depth_format
= vk_format_depth_only(dst
->image
->vk_format
);
268 struct blit2d_src_temps src_temps
;
269 blit2d_bind_src(cmd_buffer
, src_img
, src_buf
, &src_temps
, src_type
, depth_format
);
272 struct blit2d_dst_temps dst_temps
;
273 blit2d_bind_dst(cmd_buffer
, dst
, rects
[r
].dst_x
+ rects
[r
].width
,
274 rects
[r
].dst_y
+ rects
[r
].height
, depth_format
, &dst_temps
);
276 struct blit_vb_data
{
280 unsigned vb_size
= 3 * sizeof(*vb_data
);
282 vb_data
[0] = (struct blit_vb_data
) {
289 vb_data
[1] = (struct blit_vb_data
) {
292 rects
[r
].src_y
+ rects
[r
].height
,
296 vb_data
[2] = (struct blit_vb_data
) {
298 rects
[r
].src_x
+ rects
[r
].width
,
304 radv_cmd_buffer_upload_data(cmd_buffer
, vb_size
, 16, vb_data
, &offset
);
306 struct radv_buffer vertex_buffer
= {
309 .bo
= cmd_buffer
->upload
.upload_bo
,
313 radv_CmdBindVertexBuffers(radv_cmd_buffer_to_handle(cmd_buffer
), 0, 1,
315 radv_buffer_to_handle(&vertex_buffer
),
322 if (dst
->aspect_mask
== VK_IMAGE_ASPECT_COLOR_BIT
) {
323 unsigned fs_key
= radv_format_meta_fs_key(dst_temps
.iview
.vk_format
);
325 radv_CmdBeginRenderPass(radv_cmd_buffer_to_handle(cmd_buffer
),
326 &(VkRenderPassBeginInfo
) {
327 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO
,
328 .renderPass
= device
->meta_state
.blit2d
.render_passes
[fs_key
],
329 .framebuffer
= dst_temps
.fb
,
331 .offset
= { rects
[r
].dst_x
, rects
[r
].dst_y
, },
332 .extent
= { rects
[r
].width
, rects
[r
].height
},
334 .clearValueCount
= 0,
335 .pClearValues
= NULL
,
336 }, VK_SUBPASS_CONTENTS_INLINE
);
339 bind_pipeline(cmd_buffer
, src_type
, fs_key
);
340 } else if (dst
->aspect_mask
== VK_IMAGE_ASPECT_DEPTH_BIT
) {
341 radv_CmdBeginRenderPass(radv_cmd_buffer_to_handle(cmd_buffer
),
342 &(VkRenderPassBeginInfo
) {
343 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO
,
344 .renderPass
= device
->meta_state
.blit2d
.depth_only_rp
,
345 .framebuffer
= dst_temps
.fb
,
347 .offset
= { rects
[r
].dst_x
, rects
[r
].dst_y
, },
348 .extent
= { rects
[r
].width
, rects
[r
].height
},
350 .clearValueCount
= 0,
351 .pClearValues
= NULL
,
352 }, VK_SUBPASS_CONTENTS_INLINE
);
355 bind_depth_pipeline(cmd_buffer
, src_type
);
357 } else if (dst
->aspect_mask
== VK_IMAGE_ASPECT_STENCIL_BIT
) {
358 radv_CmdBeginRenderPass(radv_cmd_buffer_to_handle(cmd_buffer
),
359 &(VkRenderPassBeginInfo
) {
360 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO
,
361 .renderPass
= device
->meta_state
.blit2d
.stencil_only_rp
,
362 .framebuffer
= dst_temps
.fb
,
364 .offset
= { rects
[r
].dst_x
, rects
[r
].dst_y
, },
365 .extent
= { rects
[r
].width
, rects
[r
].height
},
367 .clearValueCount
= 0,
368 .pClearValues
= NULL
,
369 }, VK_SUBPASS_CONTENTS_INLINE
);
372 bind_stencil_pipeline(cmd_buffer
, src_type
);
375 radv_CmdSetViewport(radv_cmd_buffer_to_handle(cmd_buffer
), 0, 1, &(VkViewport
) {
378 .width
= rects
[r
].width
,
379 .height
= rects
[r
].height
,
384 radv_CmdSetScissor(radv_cmd_buffer_to_handle(cmd_buffer
), 0, 1, &(VkRect2D
) {
385 .offset
= (VkOffset2D
) { rects
[r
].dst_x
, rects
[r
].dst_y
},
386 .extent
= (VkExtent2D
) { rects
[r
].width
, rects
[r
].height
},
391 radv_CmdDraw(radv_cmd_buffer_to_handle(cmd_buffer
), 3, 1, 0, 0);
392 radv_CmdEndRenderPass(radv_cmd_buffer_to_handle(cmd_buffer
));
394 /* At the point where we emit the draw call, all data from the
395 * descriptor sets, etc. has been used. We are free to delete it.
397 blit2d_unbind_dst(cmd_buffer
, &dst_temps
);
402 radv_meta_blit2d(struct radv_cmd_buffer
*cmd_buffer
,
403 struct radv_meta_blit2d_surf
*src_img
,
404 struct radv_meta_blit2d_buffer
*src_buf
,
405 struct radv_meta_blit2d_surf
*dst
,
407 struct radv_meta_blit2d_rect
*rects
)
409 enum blit2d_src_type src_type
= src_buf
? BLIT2D_SRC_TYPE_BUFFER
:
410 BLIT2D_SRC_TYPE_IMAGE
;
411 radv_meta_blit2d_normal_dst(cmd_buffer
, src_img
, src_buf
, dst
,
412 num_rects
, rects
, src_type
);
416 build_nir_vertex_shader(void)
418 const struct glsl_type
*vec4
= glsl_vec4_type();
419 const struct glsl_type
*vec2
= glsl_vector_type(GLSL_TYPE_FLOAT
, 2);
422 nir_builder_init_simple_shader(&b
, NULL
, MESA_SHADER_VERTEX
, NULL
);
423 b
.shader
->info
->name
= ralloc_strdup(b
.shader
, "meta_blit_vs");
425 nir_variable
*pos_out
= nir_variable_create(b
.shader
, nir_var_shader_out
,
426 vec4
, "gl_Position");
427 pos_out
->data
.location
= VARYING_SLOT_POS
;
429 nir_variable
*tex_pos_in
= nir_variable_create(b
.shader
, nir_var_shader_in
,
431 tex_pos_in
->data
.location
= VERT_ATTRIB_GENERIC0
;
432 nir_variable
*tex_pos_out
= nir_variable_create(b
.shader
, nir_var_shader_out
,
434 tex_pos_out
->data
.location
= VARYING_SLOT_VAR0
;
435 tex_pos_out
->data
.interpolation
= INTERP_MODE_SMOOTH
;
436 nir_copy_var(&b
, tex_pos_out
, tex_pos_in
);
438 nir_ssa_def
*outvec
= radv_meta_gen_rect_vertices(&b
);
440 nir_store_var(&b
, pos_out
, outvec
, 0xf);
444 typedef nir_ssa_def
* (*texel_fetch_build_func
)(struct nir_builder
*,
445 struct radv_device
*,
449 build_nir_texel_fetch(struct nir_builder
*b
, struct radv_device
*device
,
450 nir_ssa_def
*tex_pos
)
452 const struct glsl_type
*sampler_type
=
453 glsl_sampler_type(GLSL_SAMPLER_DIM_2D
, false, false, GLSL_TYPE_UINT
);
454 nir_variable
*sampler
= nir_variable_create(b
->shader
, nir_var_uniform
,
455 sampler_type
, "s_tex");
456 sampler
->data
.descriptor_set
= 0;
457 sampler
->data
.binding
= 0;
459 nir_tex_instr
*tex
= nir_tex_instr_create(b
->shader
, 2);
460 tex
->sampler_dim
= GLSL_SAMPLER_DIM_2D
;
461 tex
->op
= nir_texop_txf
;
462 tex
->src
[0].src_type
= nir_tex_src_coord
;
463 tex
->src
[0].src
= nir_src_for_ssa(tex_pos
);
464 tex
->src
[1].src_type
= nir_tex_src_lod
;
465 tex
->src
[1].src
= nir_src_for_ssa(nir_imm_int(b
, 0));
466 tex
->dest_type
= nir_type_uint
;
467 tex
->is_array
= false;
468 tex
->coord_components
= 2;
469 tex
->texture
= nir_deref_var_create(tex
, sampler
);
472 nir_ssa_dest_init(&tex
->instr
, &tex
->dest
, 4, 32, "tex");
473 nir_builder_instr_insert(b
, &tex
->instr
);
475 return &tex
->dest
.ssa
;
480 build_nir_buffer_fetch(struct nir_builder
*b
, struct radv_device
*device
,
481 nir_ssa_def
*tex_pos
)
483 const struct glsl_type
*sampler_type
=
484 glsl_sampler_type(GLSL_SAMPLER_DIM_BUF
, false, false, GLSL_TYPE_UINT
);
485 nir_variable
*sampler
= nir_variable_create(b
->shader
, nir_var_uniform
,
486 sampler_type
, "s_tex");
487 sampler
->data
.descriptor_set
= 0;
488 sampler
->data
.binding
= 0;
490 nir_intrinsic_instr
*width
= nir_intrinsic_instr_create(b
->shader
, nir_intrinsic_load_push_constant
);
491 nir_intrinsic_set_base(width
, 0);
492 nir_intrinsic_set_range(width
, 4);
493 width
->src
[0] = nir_src_for_ssa(nir_imm_int(b
, 0));
494 width
->num_components
= 1;
495 nir_ssa_dest_init(&width
->instr
, &width
->dest
, 1, 32, "width");
496 nir_builder_instr_insert(b
, &width
->instr
);
498 nir_ssa_def
*pos_x
= nir_channel(b
, tex_pos
, 0);
499 nir_ssa_def
*pos_y
= nir_channel(b
, tex_pos
, 1);
500 pos_y
= nir_imul(b
, pos_y
, &width
->dest
.ssa
);
501 pos_x
= nir_iadd(b
, pos_x
, pos_y
);
502 //pos_x = nir_iadd(b, pos_x, nir_imm_int(b, 100000));
504 nir_tex_instr
*tex
= nir_tex_instr_create(b
->shader
, 1);
505 tex
->sampler_dim
= GLSL_SAMPLER_DIM_BUF
;
506 tex
->op
= nir_texop_txf
;
507 tex
->src
[0].src_type
= nir_tex_src_coord
;
508 tex
->src
[0].src
= nir_src_for_ssa(pos_x
);
509 tex
->dest_type
= nir_type_uint
;
510 tex
->is_array
= false;
511 tex
->coord_components
= 1;
512 tex
->texture
= nir_deref_var_create(tex
, sampler
);
515 nir_ssa_dest_init(&tex
->instr
, &tex
->dest
, 4, 32, "tex");
516 nir_builder_instr_insert(b
, &tex
->instr
);
518 return &tex
->dest
.ssa
;
521 static const VkPipelineVertexInputStateCreateInfo normal_vi_create_info
= {
522 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO
,
523 .vertexBindingDescriptionCount
= 1,
524 .pVertexBindingDescriptions
= (VkVertexInputBindingDescription
[]) {
527 .stride
= 2 * sizeof(float),
528 .inputRate
= VK_VERTEX_INPUT_RATE_VERTEX
531 .vertexAttributeDescriptionCount
= 1,
532 .pVertexAttributeDescriptions
= (VkVertexInputAttributeDescription
[]) {
534 /* Texture Coordinate */
537 .format
= VK_FORMAT_R32G32_SFLOAT
,
544 build_nir_copy_fragment_shader(struct radv_device
*device
,
545 texel_fetch_build_func txf_func
, const char* name
)
547 const struct glsl_type
*vec4
= glsl_vec4_type();
548 const struct glsl_type
*vec2
= glsl_vector_type(GLSL_TYPE_FLOAT
, 2);
551 nir_builder_init_simple_shader(&b
, NULL
, MESA_SHADER_FRAGMENT
, NULL
);
552 b
.shader
->info
->name
= ralloc_strdup(b
.shader
, name
);
554 nir_variable
*tex_pos_in
= nir_variable_create(b
.shader
, nir_var_shader_in
,
556 tex_pos_in
->data
.location
= VARYING_SLOT_VAR0
;
558 nir_variable
*color_out
= nir_variable_create(b
.shader
, nir_var_shader_out
,
560 color_out
->data
.location
= FRAG_RESULT_DATA0
;
562 nir_ssa_def
*pos_int
= nir_f2i32(&b
, nir_load_var(&b
, tex_pos_in
));
563 unsigned swiz
[4] = { 0, 1 };
564 nir_ssa_def
*tex_pos
= nir_swizzle(&b
, pos_int
, swiz
, 2, false);
566 nir_ssa_def
*color
= txf_func(&b
, device
, tex_pos
);
567 nir_store_var(&b
, color_out
, color
, 0xf);
573 build_nir_copy_fragment_shader_depth(struct radv_device
*device
,
574 texel_fetch_build_func txf_func
, const char* name
)
576 const struct glsl_type
*vec4
= glsl_vec4_type();
577 const struct glsl_type
*vec2
= glsl_vector_type(GLSL_TYPE_FLOAT
, 2);
580 nir_builder_init_simple_shader(&b
, NULL
, MESA_SHADER_FRAGMENT
, NULL
);
581 b
.shader
->info
->name
= ralloc_strdup(b
.shader
, name
);
583 nir_variable
*tex_pos_in
= nir_variable_create(b
.shader
, nir_var_shader_in
,
585 tex_pos_in
->data
.location
= VARYING_SLOT_VAR0
;
587 nir_variable
*color_out
= nir_variable_create(b
.shader
, nir_var_shader_out
,
589 color_out
->data
.location
= FRAG_RESULT_DEPTH
;
591 nir_ssa_def
*pos_int
= nir_f2i32(&b
, nir_load_var(&b
, tex_pos_in
));
592 unsigned swiz
[4] = { 0, 1 };
593 nir_ssa_def
*tex_pos
= nir_swizzle(&b
, pos_int
, swiz
, 2, false);
595 nir_ssa_def
*color
= txf_func(&b
, device
, tex_pos
);
596 nir_store_var(&b
, color_out
, color
, 0x1);
602 build_nir_copy_fragment_shader_stencil(struct radv_device
*device
,
603 texel_fetch_build_func txf_func
, const char* name
)
605 const struct glsl_type
*vec4
= glsl_vec4_type();
606 const struct glsl_type
*vec2
= glsl_vector_type(GLSL_TYPE_FLOAT
, 2);
609 nir_builder_init_simple_shader(&b
, NULL
, MESA_SHADER_FRAGMENT
, NULL
);
610 b
.shader
->info
->name
= ralloc_strdup(b
.shader
, name
);
612 nir_variable
*tex_pos_in
= nir_variable_create(b
.shader
, nir_var_shader_in
,
614 tex_pos_in
->data
.location
= VARYING_SLOT_VAR0
;
616 nir_variable
*color_out
= nir_variable_create(b
.shader
, nir_var_shader_out
,
618 color_out
->data
.location
= FRAG_RESULT_STENCIL
;
620 nir_ssa_def
*pos_int
= nir_f2i32(&b
, nir_load_var(&b
, tex_pos_in
));
621 unsigned swiz
[4] = { 0, 1 };
622 nir_ssa_def
*tex_pos
= nir_swizzle(&b
, pos_int
, swiz
, 2, false);
624 nir_ssa_def
*color
= txf_func(&b
, device
, tex_pos
);
625 nir_store_var(&b
, color_out
, color
, 0x1);
631 radv_device_finish_meta_blit2d_state(struct radv_device
*device
)
633 for(unsigned j
= 0; j
< NUM_META_FS_KEYS
; ++j
) {
634 if (device
->meta_state
.blit2d
.render_passes
[j
]) {
635 radv_DestroyRenderPass(radv_device_to_handle(device
),
636 device
->meta_state
.blit2d
.render_passes
[j
],
637 &device
->meta_state
.alloc
);
641 radv_DestroyRenderPass(radv_device_to_handle(device
),
642 device
->meta_state
.blit2d
.depth_only_rp
,
643 &device
->meta_state
.alloc
);
644 radv_DestroyRenderPass(radv_device_to_handle(device
),
645 device
->meta_state
.blit2d
.stencil_only_rp
,
646 &device
->meta_state
.alloc
);
648 for (unsigned src
= 0; src
< BLIT2D_NUM_SRC_TYPES
; src
++) {
649 if (device
->meta_state
.blit2d
.p_layouts
[src
]) {
650 radv_DestroyPipelineLayout(radv_device_to_handle(device
),
651 device
->meta_state
.blit2d
.p_layouts
[src
],
652 &device
->meta_state
.alloc
);
655 if (device
->meta_state
.blit2d
.ds_layouts
[src
]) {
656 radv_DestroyDescriptorSetLayout(radv_device_to_handle(device
),
657 device
->meta_state
.blit2d
.ds_layouts
[src
],
658 &device
->meta_state
.alloc
);
661 for (unsigned j
= 0; j
< NUM_META_FS_KEYS
; ++j
) {
662 if (device
->meta_state
.blit2d
.pipelines
[src
][j
]) {
663 radv_DestroyPipeline(radv_device_to_handle(device
),
664 device
->meta_state
.blit2d
.pipelines
[src
][j
],
665 &device
->meta_state
.alloc
);
669 radv_DestroyPipeline(radv_device_to_handle(device
),
670 device
->meta_state
.blit2d
.depth_only_pipeline
[src
],
671 &device
->meta_state
.alloc
);
672 radv_DestroyPipeline(radv_device_to_handle(device
),
673 device
->meta_state
.blit2d
.stencil_only_pipeline
[src
],
674 &device
->meta_state
.alloc
);
679 blit2d_init_color_pipeline(struct radv_device
*device
,
680 enum blit2d_src_type src_type
,
684 unsigned fs_key
= radv_format_meta_fs_key(format
);
687 texel_fetch_build_func src_func
;
689 case BLIT2D_SRC_TYPE_IMAGE
:
690 src_func
= build_nir_texel_fetch
;
691 name
= "meta_blit2d_image_fs";
693 case BLIT2D_SRC_TYPE_BUFFER
:
694 src_func
= build_nir_buffer_fetch
;
695 name
= "meta_blit2d_buffer_fs";
698 unreachable("unknown blit src type\n");
702 const VkPipelineVertexInputStateCreateInfo
*vi_create_info
;
703 struct radv_shader_module fs
= { .nir
= NULL
};
706 fs
.nir
= build_nir_copy_fragment_shader(device
, src_func
, name
);
707 vi_create_info
= &normal_vi_create_info
;
709 struct radv_shader_module vs
= {
710 .nir
= build_nir_vertex_shader(),
713 VkPipelineShaderStageCreateInfo pipeline_shader_stages
[] = {
715 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
716 .stage
= VK_SHADER_STAGE_VERTEX_BIT
,
717 .module
= radv_shader_module_to_handle(&vs
),
719 .pSpecializationInfo
= NULL
721 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
722 .stage
= VK_SHADER_STAGE_FRAGMENT_BIT
,
723 .module
= radv_shader_module_to_handle(&fs
),
725 .pSpecializationInfo
= NULL
729 if (!device
->meta_state
.blit2d
.render_passes
[fs_key
]) {
730 result
= radv_CreateRenderPass(radv_device_to_handle(device
),
731 &(VkRenderPassCreateInfo
) {
732 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
,
733 .attachmentCount
= 1,
734 .pAttachments
= &(VkAttachmentDescription
) {
736 .loadOp
= VK_ATTACHMENT_LOAD_OP_LOAD
,
737 .storeOp
= VK_ATTACHMENT_STORE_OP_STORE
,
738 .initialLayout
= VK_IMAGE_LAYOUT_GENERAL
,
739 .finalLayout
= VK_IMAGE_LAYOUT_GENERAL
,
742 .pSubpasses
= &(VkSubpassDescription
) {
743 .pipelineBindPoint
= VK_PIPELINE_BIND_POINT_GRAPHICS
,
744 .inputAttachmentCount
= 0,
745 .colorAttachmentCount
= 1,
746 .pColorAttachments
= &(VkAttachmentReference
) {
748 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
750 .pResolveAttachments
= NULL
,
751 .pDepthStencilAttachment
= &(VkAttachmentReference
) {
752 .attachment
= VK_ATTACHMENT_UNUSED
,
753 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
755 .preserveAttachmentCount
= 1,
756 .pPreserveAttachments
= (uint32_t[]) { 0 },
758 .dependencyCount
= 0,
759 }, &device
->meta_state
.alloc
, &device
->meta_state
.blit2d
.render_passes
[fs_key
]);
762 const VkGraphicsPipelineCreateInfo vk_pipeline_info
= {
763 .sType
= VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
,
764 .stageCount
= ARRAY_SIZE(pipeline_shader_stages
),
765 .pStages
= pipeline_shader_stages
,
766 .pVertexInputState
= vi_create_info
,
767 .pInputAssemblyState
= &(VkPipelineInputAssemblyStateCreateInfo
) {
768 .sType
= VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO
,
769 .topology
= VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
,
770 .primitiveRestartEnable
= false,
772 .pViewportState
= &(VkPipelineViewportStateCreateInfo
) {
773 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO
,
777 .pRasterizationState
= &(VkPipelineRasterizationStateCreateInfo
) {
778 .sType
= VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO
,
779 .rasterizerDiscardEnable
= false,
780 .polygonMode
= VK_POLYGON_MODE_FILL
,
781 .cullMode
= VK_CULL_MODE_NONE
,
782 .frontFace
= VK_FRONT_FACE_COUNTER_CLOCKWISE
784 .pMultisampleState
= &(VkPipelineMultisampleStateCreateInfo
) {
785 .sType
= VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO
,
786 .rasterizationSamples
= 1,
787 .sampleShadingEnable
= false,
788 .pSampleMask
= (VkSampleMask
[]) { UINT32_MAX
},
790 .pColorBlendState
= &(VkPipelineColorBlendStateCreateInfo
) {
791 .sType
= VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO
,
792 .attachmentCount
= 1,
793 .pAttachments
= (VkPipelineColorBlendAttachmentState
[]) {
795 VK_COLOR_COMPONENT_A_BIT
|
796 VK_COLOR_COMPONENT_R_BIT
|
797 VK_COLOR_COMPONENT_G_BIT
|
798 VK_COLOR_COMPONENT_B_BIT
},
801 .pDynamicState
= &(VkPipelineDynamicStateCreateInfo
) {
802 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO
,
803 .dynamicStateCount
= 9,
804 .pDynamicStates
= (VkDynamicState
[]) {
805 VK_DYNAMIC_STATE_VIEWPORT
,
806 VK_DYNAMIC_STATE_SCISSOR
,
807 VK_DYNAMIC_STATE_LINE_WIDTH
,
808 VK_DYNAMIC_STATE_DEPTH_BIAS
,
809 VK_DYNAMIC_STATE_BLEND_CONSTANTS
,
810 VK_DYNAMIC_STATE_DEPTH_BOUNDS
,
811 VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK
,
812 VK_DYNAMIC_STATE_STENCIL_WRITE_MASK
,
813 VK_DYNAMIC_STATE_STENCIL_REFERENCE
,
817 .layout
= device
->meta_state
.blit2d
.p_layouts
[src_type
],
818 .renderPass
= device
->meta_state
.blit2d
.render_passes
[fs_key
],
822 const struct radv_graphics_pipeline_create_info radv_pipeline_info
= {
826 result
= radv_graphics_pipeline_create(radv_device_to_handle(device
),
827 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
828 &vk_pipeline_info
, &radv_pipeline_info
,
829 &device
->meta_state
.alloc
,
830 &device
->meta_state
.blit2d
.pipelines
[src_type
][fs_key
]);
840 blit2d_init_depth_only_pipeline(struct radv_device
*device
,
841 enum blit2d_src_type src_type
)
846 texel_fetch_build_func src_func
;
848 case BLIT2D_SRC_TYPE_IMAGE
:
849 src_func
= build_nir_texel_fetch
;
850 name
= "meta_blit2d_depth_image_fs";
852 case BLIT2D_SRC_TYPE_BUFFER
:
853 src_func
= build_nir_buffer_fetch
;
854 name
= "meta_blit2d_depth_buffer_fs";
857 unreachable("unknown blit src type\n");
861 const VkPipelineVertexInputStateCreateInfo
*vi_create_info
;
862 struct radv_shader_module fs
= { .nir
= NULL
};
864 fs
.nir
= build_nir_copy_fragment_shader_depth(device
, src_func
, name
);
865 vi_create_info
= &normal_vi_create_info
;
867 struct radv_shader_module vs
= {
868 .nir
= build_nir_vertex_shader(),
871 VkPipelineShaderStageCreateInfo pipeline_shader_stages
[] = {
873 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
874 .stage
= VK_SHADER_STAGE_VERTEX_BIT
,
875 .module
= radv_shader_module_to_handle(&vs
),
877 .pSpecializationInfo
= NULL
879 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
880 .stage
= VK_SHADER_STAGE_FRAGMENT_BIT
,
881 .module
= radv_shader_module_to_handle(&fs
),
883 .pSpecializationInfo
= NULL
887 if (!device
->meta_state
.blit2d
.depth_only_rp
) {
888 result
= radv_CreateRenderPass(radv_device_to_handle(device
),
889 &(VkRenderPassCreateInfo
) {
890 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
,
891 .attachmentCount
= 1,
892 .pAttachments
= &(VkAttachmentDescription
) {
894 .loadOp
= VK_ATTACHMENT_LOAD_OP_LOAD
,
895 .storeOp
= VK_ATTACHMENT_STORE_OP_STORE
,
896 .initialLayout
= VK_IMAGE_LAYOUT_GENERAL
,
897 .finalLayout
= VK_IMAGE_LAYOUT_GENERAL
,
900 .pSubpasses
= &(VkSubpassDescription
) {
901 .pipelineBindPoint
= VK_PIPELINE_BIND_POINT_GRAPHICS
,
902 .inputAttachmentCount
= 0,
903 .colorAttachmentCount
= 0,
904 .pColorAttachments
= NULL
,
905 .pResolveAttachments
= NULL
,
906 .pDepthStencilAttachment
= &(VkAttachmentReference
) {
908 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
910 .preserveAttachmentCount
= 1,
911 .pPreserveAttachments
= (uint32_t[]) { 0 },
913 .dependencyCount
= 0,
914 }, &device
->meta_state
.alloc
, &device
->meta_state
.blit2d
.depth_only_rp
);
917 const VkGraphicsPipelineCreateInfo vk_pipeline_info
= {
918 .sType
= VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
,
919 .stageCount
= ARRAY_SIZE(pipeline_shader_stages
),
920 .pStages
= pipeline_shader_stages
,
921 .pVertexInputState
= vi_create_info
,
922 .pInputAssemblyState
= &(VkPipelineInputAssemblyStateCreateInfo
) {
923 .sType
= VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO
,
924 .topology
= VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
,
925 .primitiveRestartEnable
= false,
927 .pViewportState
= &(VkPipelineViewportStateCreateInfo
) {
928 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO
,
932 .pRasterizationState
= &(VkPipelineRasterizationStateCreateInfo
) {
933 .sType
= VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO
,
934 .rasterizerDiscardEnable
= false,
935 .polygonMode
= VK_POLYGON_MODE_FILL
,
936 .cullMode
= VK_CULL_MODE_NONE
,
937 .frontFace
= VK_FRONT_FACE_COUNTER_CLOCKWISE
939 .pMultisampleState
= &(VkPipelineMultisampleStateCreateInfo
) {
940 .sType
= VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO
,
941 .rasterizationSamples
= 1,
942 .sampleShadingEnable
= false,
943 .pSampleMask
= (VkSampleMask
[]) { UINT32_MAX
},
945 .pColorBlendState
= &(VkPipelineColorBlendStateCreateInfo
) {
946 .sType
= VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO
,
947 .attachmentCount
= 0,
948 .pAttachments
= NULL
,
950 .pDepthStencilState
= &(VkPipelineDepthStencilStateCreateInfo
) {
951 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO
,
952 .depthTestEnable
= true,
953 .depthWriteEnable
= true,
954 .depthCompareOp
= VK_COMPARE_OP_ALWAYS
,
956 .pDynamicState
= &(VkPipelineDynamicStateCreateInfo
) {
957 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO
,
958 .dynamicStateCount
= 9,
959 .pDynamicStates
= (VkDynamicState
[]) {
960 VK_DYNAMIC_STATE_VIEWPORT
,
961 VK_DYNAMIC_STATE_SCISSOR
,
962 VK_DYNAMIC_STATE_LINE_WIDTH
,
963 VK_DYNAMIC_STATE_DEPTH_BIAS
,
964 VK_DYNAMIC_STATE_BLEND_CONSTANTS
,
965 VK_DYNAMIC_STATE_DEPTH_BOUNDS
,
966 VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK
,
967 VK_DYNAMIC_STATE_STENCIL_WRITE_MASK
,
968 VK_DYNAMIC_STATE_STENCIL_REFERENCE
,
972 .layout
= device
->meta_state
.blit2d
.p_layouts
[src_type
],
973 .renderPass
= device
->meta_state
.blit2d
.depth_only_rp
,
977 const struct radv_graphics_pipeline_create_info radv_pipeline_info
= {
981 result
= radv_graphics_pipeline_create(radv_device_to_handle(device
),
982 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
983 &vk_pipeline_info
, &radv_pipeline_info
,
984 &device
->meta_state
.alloc
,
985 &device
->meta_state
.blit2d
.depth_only_pipeline
[src_type
]);
995 blit2d_init_stencil_only_pipeline(struct radv_device
*device
,
996 enum blit2d_src_type src_type
)
1001 texel_fetch_build_func src_func
;
1003 case BLIT2D_SRC_TYPE_IMAGE
:
1004 src_func
= build_nir_texel_fetch
;
1005 name
= "meta_blit2d_stencil_image_fs";
1007 case BLIT2D_SRC_TYPE_BUFFER
:
1008 src_func
= build_nir_buffer_fetch
;
1009 name
= "meta_blit2d_stencil_buffer_fs";
1012 unreachable("unknown blit src type\n");
1016 const VkPipelineVertexInputStateCreateInfo
*vi_create_info
;
1017 struct radv_shader_module fs
= { .nir
= NULL
};
1019 fs
.nir
= build_nir_copy_fragment_shader_stencil(device
, src_func
, name
);
1020 vi_create_info
= &normal_vi_create_info
;
1022 struct radv_shader_module vs
= {
1023 .nir
= build_nir_vertex_shader(),
1026 VkPipelineShaderStageCreateInfo pipeline_shader_stages
[] = {
1028 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
1029 .stage
= VK_SHADER_STAGE_VERTEX_BIT
,
1030 .module
= radv_shader_module_to_handle(&vs
),
1032 .pSpecializationInfo
= NULL
1034 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
1035 .stage
= VK_SHADER_STAGE_FRAGMENT_BIT
,
1036 .module
= radv_shader_module_to_handle(&fs
),
1038 .pSpecializationInfo
= NULL
1042 if (!device
->meta_state
.blit2d
.stencil_only_rp
) {
1043 result
= radv_CreateRenderPass(radv_device_to_handle(device
),
1044 &(VkRenderPassCreateInfo
) {
1045 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
,
1046 .attachmentCount
= 1,
1047 .pAttachments
= &(VkAttachmentDescription
) {
1049 .loadOp
= VK_ATTACHMENT_LOAD_OP_LOAD
,
1050 .storeOp
= VK_ATTACHMENT_STORE_OP_STORE
,
1051 .initialLayout
= VK_IMAGE_LAYOUT_GENERAL
,
1052 .finalLayout
= VK_IMAGE_LAYOUT_GENERAL
,
1055 .pSubpasses
= &(VkSubpassDescription
) {
1056 .pipelineBindPoint
= VK_PIPELINE_BIND_POINT_GRAPHICS
,
1057 .inputAttachmentCount
= 0,
1058 .colorAttachmentCount
= 0,
1059 .pColorAttachments
= NULL
,
1060 .pResolveAttachments
= NULL
,
1061 .pDepthStencilAttachment
= &(VkAttachmentReference
) {
1063 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
1065 .preserveAttachmentCount
= 1,
1066 .pPreserveAttachments
= (uint32_t[]) { 0 },
1068 .dependencyCount
= 0,
1069 }, &device
->meta_state
.alloc
, &device
->meta_state
.blit2d
.stencil_only_rp
);
1072 const VkGraphicsPipelineCreateInfo vk_pipeline_info
= {
1073 .sType
= VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
,
1074 .stageCount
= ARRAY_SIZE(pipeline_shader_stages
),
1075 .pStages
= pipeline_shader_stages
,
1076 .pVertexInputState
= vi_create_info
,
1077 .pInputAssemblyState
= &(VkPipelineInputAssemblyStateCreateInfo
) {
1078 .sType
= VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO
,
1079 .topology
= VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
,
1080 .primitiveRestartEnable
= false,
1082 .pViewportState
= &(VkPipelineViewportStateCreateInfo
) {
1083 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO
,
1087 .pRasterizationState
= &(VkPipelineRasterizationStateCreateInfo
) {
1088 .sType
= VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO
,
1089 .rasterizerDiscardEnable
= false,
1090 .polygonMode
= VK_POLYGON_MODE_FILL
,
1091 .cullMode
= VK_CULL_MODE_NONE
,
1092 .frontFace
= VK_FRONT_FACE_COUNTER_CLOCKWISE
1094 .pMultisampleState
= &(VkPipelineMultisampleStateCreateInfo
) {
1095 .sType
= VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO
,
1096 .rasterizationSamples
= 1,
1097 .sampleShadingEnable
= false,
1098 .pSampleMask
= (VkSampleMask
[]) { UINT32_MAX
},
1100 .pColorBlendState
= &(VkPipelineColorBlendStateCreateInfo
) {
1101 .sType
= VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO
,
1102 .attachmentCount
= 0,
1103 .pAttachments
= NULL
,
1105 .pDepthStencilState
= &(VkPipelineDepthStencilStateCreateInfo
) {
1106 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO
,
1107 .depthTestEnable
= false,
1108 .depthWriteEnable
= false,
1109 .stencilTestEnable
= true,
1111 .failOp
= VK_STENCIL_OP_REPLACE
,
1112 .passOp
= VK_STENCIL_OP_REPLACE
,
1113 .depthFailOp
= VK_STENCIL_OP_REPLACE
,
1114 .compareOp
= VK_COMPARE_OP_ALWAYS
,
1115 .compareMask
= 0xff,
1120 .failOp
= VK_STENCIL_OP_REPLACE
,
1121 .passOp
= VK_STENCIL_OP_REPLACE
,
1122 .depthFailOp
= VK_STENCIL_OP_REPLACE
,
1123 .compareOp
= VK_COMPARE_OP_ALWAYS
,
1124 .compareMask
= 0xff,
1128 .depthCompareOp
= VK_COMPARE_OP_ALWAYS
,
1130 .pDynamicState
= &(VkPipelineDynamicStateCreateInfo
) {
1131 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO
,
1132 .dynamicStateCount
= 6,
1133 .pDynamicStates
= (VkDynamicState
[]) {
1134 VK_DYNAMIC_STATE_VIEWPORT
,
1135 VK_DYNAMIC_STATE_SCISSOR
,
1136 VK_DYNAMIC_STATE_LINE_WIDTH
,
1137 VK_DYNAMIC_STATE_DEPTH_BIAS
,
1138 VK_DYNAMIC_STATE_BLEND_CONSTANTS
,
1139 VK_DYNAMIC_STATE_DEPTH_BOUNDS
,
1143 .layout
= device
->meta_state
.blit2d
.p_layouts
[src_type
],
1144 .renderPass
= device
->meta_state
.blit2d
.stencil_only_rp
,
1148 const struct radv_graphics_pipeline_create_info radv_pipeline_info
= {
1149 .use_rectlist
= true
1152 result
= radv_graphics_pipeline_create(radv_device_to_handle(device
),
1153 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
1154 &vk_pipeline_info
, &radv_pipeline_info
,
1155 &device
->meta_state
.alloc
,
1156 &device
->meta_state
.blit2d
.stencil_only_pipeline
[src_type
]);
1159 ralloc_free(vs
.nir
);
1160 ralloc_free(fs
.nir
);
1165 static VkFormat pipeline_formats
[] = {
1166 VK_FORMAT_R8G8B8A8_UNORM
,
1167 VK_FORMAT_R8G8B8A8_UINT
,
1168 VK_FORMAT_R8G8B8A8_SINT
,
1169 VK_FORMAT_R16G16B16A16_UNORM
,
1170 VK_FORMAT_R16G16B16A16_SNORM
,
1171 VK_FORMAT_R16G16B16A16_UINT
,
1172 VK_FORMAT_R16G16B16A16_SINT
,
1173 VK_FORMAT_R32_SFLOAT
,
1174 VK_FORMAT_R32G32_SFLOAT
,
1175 VK_FORMAT_R32G32B32A32_SFLOAT
1179 radv_device_init_meta_blit2d_state(struct radv_device
*device
)
1183 zero(device
->meta_state
.blit2d
);
1185 result
= radv_CreateDescriptorSetLayout(radv_device_to_handle(device
),
1186 &(VkDescriptorSetLayoutCreateInfo
) {
1187 .sType
= VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
,
1188 .flags
= VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
,
1190 .pBindings
= (VkDescriptorSetLayoutBinding
[]) {
1193 .descriptorType
= VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
,
1194 .descriptorCount
= 1,
1195 .stageFlags
= VK_SHADER_STAGE_FRAGMENT_BIT
,
1196 .pImmutableSamplers
= NULL
1199 }, &device
->meta_state
.alloc
, &device
->meta_state
.blit2d
.ds_layouts
[BLIT2D_SRC_TYPE_IMAGE
]);
1200 if (result
!= VK_SUCCESS
)
1203 result
= radv_CreatePipelineLayout(radv_device_to_handle(device
),
1204 &(VkPipelineLayoutCreateInfo
) {
1205 .sType
= VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
,
1206 .setLayoutCount
= 1,
1207 .pSetLayouts
= &device
->meta_state
.blit2d
.ds_layouts
[BLIT2D_SRC_TYPE_IMAGE
],
1209 &device
->meta_state
.alloc
, &device
->meta_state
.blit2d
.p_layouts
[BLIT2D_SRC_TYPE_IMAGE
]);
1210 if (result
!= VK_SUCCESS
)
1213 result
= radv_CreateDescriptorSetLayout(radv_device_to_handle(device
),
1214 &(VkDescriptorSetLayoutCreateInfo
) {
1215 .sType
= VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
,
1216 .flags
= VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
,
1218 .pBindings
= (VkDescriptorSetLayoutBinding
[]) {
1221 .descriptorType
= VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
,
1222 .descriptorCount
= 1,
1223 .stageFlags
= VK_SHADER_STAGE_FRAGMENT_BIT
,
1224 .pImmutableSamplers
= NULL
1227 }, &device
->meta_state
.alloc
, &device
->meta_state
.blit2d
.ds_layouts
[BLIT2D_SRC_TYPE_BUFFER
]);
1228 if (result
!= VK_SUCCESS
)
1231 const VkPushConstantRange push_constant_range
= {VK_SHADER_STAGE_FRAGMENT_BIT
, 0, 4};
1232 result
= radv_CreatePipelineLayout(radv_device_to_handle(device
),
1233 &(VkPipelineLayoutCreateInfo
) {
1234 .sType
= VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
,
1235 .setLayoutCount
= 1,
1236 .pSetLayouts
= &device
->meta_state
.blit2d
.ds_layouts
[BLIT2D_SRC_TYPE_BUFFER
],
1237 .pushConstantRangeCount
= 1,
1238 .pPushConstantRanges
= &push_constant_range
,
1240 &device
->meta_state
.alloc
, &device
->meta_state
.blit2d
.p_layouts
[BLIT2D_SRC_TYPE_BUFFER
]);
1241 if (result
!= VK_SUCCESS
)
1244 for (unsigned src
= 0; src
< BLIT2D_NUM_SRC_TYPES
; src
++) {
1245 for (unsigned j
= 0; j
< ARRAY_SIZE(pipeline_formats
); ++j
) {
1246 result
= blit2d_init_color_pipeline(device
, src
, pipeline_formats
[j
]);
1247 if (result
!= VK_SUCCESS
)
1251 result
= blit2d_init_depth_only_pipeline(device
, src
);
1252 if (result
!= VK_SUCCESS
)
1255 result
= blit2d_init_stencil_only_pipeline(device
, src
);
1256 if (result
!= VK_SUCCESS
)
1263 radv_device_finish_meta_blit2d_state(device
);