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
, 16, 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
);
271 struct blit2d_dst_temps dst_temps
;
272 blit2d_bind_dst(cmd_buffer
, dst
, rects
[r
].dst_x
+ rects
[r
].width
,
273 rects
[r
].dst_y
+ rects
[r
].height
, depth_format
, &dst_temps
);
275 float vertex_push_constants
[4] = {
278 rects
[r
].src_x
+ rects
[r
].width
,
279 rects
[r
].src_y
+ rects
[r
].height
,
282 radv_CmdPushConstants(radv_cmd_buffer_to_handle(cmd_buffer
),
283 device
->meta_state
.blit2d
.p_layouts
[src_type
],
284 VK_SHADER_STAGE_VERTEX_BIT
, 0, 16,
285 vertex_push_constants
);
287 if (dst
->aspect_mask
== VK_IMAGE_ASPECT_COLOR_BIT
) {
288 unsigned fs_key
= radv_format_meta_fs_key(dst_temps
.iview
.vk_format
);
290 radv_CmdBeginRenderPass(radv_cmd_buffer_to_handle(cmd_buffer
),
291 &(VkRenderPassBeginInfo
) {
292 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO
,
293 .renderPass
= device
->meta_state
.blit2d
.render_passes
[fs_key
],
294 .framebuffer
= dst_temps
.fb
,
296 .offset
= { rects
[r
].dst_x
, rects
[r
].dst_y
, },
297 .extent
= { rects
[r
].width
, rects
[r
].height
},
299 .clearValueCount
= 0,
300 .pClearValues
= NULL
,
301 }, VK_SUBPASS_CONTENTS_INLINE
);
304 bind_pipeline(cmd_buffer
, src_type
, fs_key
);
305 } else if (dst
->aspect_mask
== VK_IMAGE_ASPECT_DEPTH_BIT
) {
306 radv_CmdBeginRenderPass(radv_cmd_buffer_to_handle(cmd_buffer
),
307 &(VkRenderPassBeginInfo
) {
308 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO
,
309 .renderPass
= device
->meta_state
.blit2d
.depth_only_rp
,
310 .framebuffer
= dst_temps
.fb
,
312 .offset
= { rects
[r
].dst_x
, rects
[r
].dst_y
, },
313 .extent
= { rects
[r
].width
, rects
[r
].height
},
315 .clearValueCount
= 0,
316 .pClearValues
= NULL
,
317 }, VK_SUBPASS_CONTENTS_INLINE
);
320 bind_depth_pipeline(cmd_buffer
, src_type
);
322 } else if (dst
->aspect_mask
== VK_IMAGE_ASPECT_STENCIL_BIT
) {
323 radv_CmdBeginRenderPass(radv_cmd_buffer_to_handle(cmd_buffer
),
324 &(VkRenderPassBeginInfo
) {
325 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO
,
326 .renderPass
= device
->meta_state
.blit2d
.stencil_only_rp
,
327 .framebuffer
= dst_temps
.fb
,
329 .offset
= { rects
[r
].dst_x
, rects
[r
].dst_y
, },
330 .extent
= { rects
[r
].width
, rects
[r
].height
},
332 .clearValueCount
= 0,
333 .pClearValues
= NULL
,
334 }, VK_SUBPASS_CONTENTS_INLINE
);
337 bind_stencil_pipeline(cmd_buffer
, src_type
);
340 radv_CmdSetViewport(radv_cmd_buffer_to_handle(cmd_buffer
), 0, 1, &(VkViewport
) {
343 .width
= rects
[r
].width
,
344 .height
= rects
[r
].height
,
349 radv_CmdSetScissor(radv_cmd_buffer_to_handle(cmd_buffer
), 0, 1, &(VkRect2D
) {
350 .offset
= (VkOffset2D
) { rects
[r
].dst_x
, rects
[r
].dst_y
},
351 .extent
= (VkExtent2D
) { rects
[r
].width
, rects
[r
].height
},
356 radv_CmdDraw(radv_cmd_buffer_to_handle(cmd_buffer
), 3, 1, 0, 0);
357 radv_CmdEndRenderPass(radv_cmd_buffer_to_handle(cmd_buffer
));
359 /* At the point where we emit the draw call, all data from the
360 * descriptor sets, etc. has been used. We are free to delete it.
362 blit2d_unbind_dst(cmd_buffer
, &dst_temps
);
367 radv_meta_blit2d(struct radv_cmd_buffer
*cmd_buffer
,
368 struct radv_meta_blit2d_surf
*src_img
,
369 struct radv_meta_blit2d_buffer
*src_buf
,
370 struct radv_meta_blit2d_surf
*dst
,
372 struct radv_meta_blit2d_rect
*rects
)
374 enum blit2d_src_type src_type
= src_buf
? BLIT2D_SRC_TYPE_BUFFER
:
375 BLIT2D_SRC_TYPE_IMAGE
;
376 radv_meta_blit2d_normal_dst(cmd_buffer
, src_img
, src_buf
, dst
,
377 num_rects
, rects
, src_type
);
381 build_nir_vertex_shader(void)
383 const struct glsl_type
*vec4
= glsl_vec4_type();
384 const struct glsl_type
*vec2
= glsl_vector_type(GLSL_TYPE_FLOAT
, 2);
387 nir_builder_init_simple_shader(&b
, NULL
, MESA_SHADER_VERTEX
, NULL
);
388 b
.shader
->info
->name
= ralloc_strdup(b
.shader
, "meta_blit2d_vs");
390 nir_variable
*pos_out
= nir_variable_create(b
.shader
, nir_var_shader_out
,
391 vec4
, "gl_Position");
392 pos_out
->data
.location
= VARYING_SLOT_POS
;
394 nir_variable
*tex_pos_out
= nir_variable_create(b
.shader
, nir_var_shader_out
,
396 tex_pos_out
->data
.location
= VARYING_SLOT_VAR0
;
397 tex_pos_out
->data
.interpolation
= INTERP_MODE_SMOOTH
;
399 nir_ssa_def
*outvec
= radv_meta_gen_rect_vertices(&b
);
400 nir_store_var(&b
, pos_out
, outvec
, 0xf);
402 nir_intrinsic_instr
*src_box
= nir_intrinsic_instr_create(b
.shader
, nir_intrinsic_load_push_constant
);
403 src_box
->src
[0] = nir_src_for_ssa(nir_imm_int(&b
, 0));
404 nir_intrinsic_set_base(src_box
, 0);
405 nir_intrinsic_set_range(src_box
, 16);
406 src_box
->num_components
= 4;
407 nir_ssa_dest_init(&src_box
->instr
, &src_box
->dest
, 4, 32, "src_box");
408 nir_builder_instr_insert(&b
, &src_box
->instr
);
410 nir_intrinsic_instr
*vertex_id
= nir_intrinsic_instr_create(b
.shader
, nir_intrinsic_load_vertex_id_zero_base
);
411 nir_ssa_dest_init(&vertex_id
->instr
, &vertex_id
->dest
, 1, 32, "vertexid");
412 nir_builder_instr_insert(&b
, &vertex_id
->instr
);
414 /* vertex 0 - src_x, src_y */
415 /* vertex 1 - src_x, src_y+h */
416 /* vertex 2 - src_x+w, src_y */
417 /* so channel 0 is vertex_id != 2 ? src_x : src_x + w
418 channel 1 is vertex id != 1 ? src_y : src_y + w */
420 nir_ssa_def
*c0cmp
= nir_ine(&b
, &vertex_id
->dest
.ssa
,
422 nir_ssa_def
*c1cmp
= nir_ine(&b
, &vertex_id
->dest
.ssa
,
425 nir_ssa_def
*comp
[2];
426 comp
[0] = nir_bcsel(&b
, c0cmp
,
427 nir_channel(&b
, &src_box
->dest
.ssa
, 0),
428 nir_channel(&b
, &src_box
->dest
.ssa
, 2));
430 comp
[1] = nir_bcsel(&b
, c1cmp
,
431 nir_channel(&b
, &src_box
->dest
.ssa
, 1),
432 nir_channel(&b
, &src_box
->dest
.ssa
, 3));
433 nir_ssa_def
*out_tex_vec
= nir_vec(&b
, comp
, 2);
434 nir_store_var(&b
, tex_pos_out
, out_tex_vec
, 0x3);
438 typedef nir_ssa_def
* (*texel_fetch_build_func
)(struct nir_builder
*,
439 struct radv_device
*,
443 build_nir_texel_fetch(struct nir_builder
*b
, struct radv_device
*device
,
444 nir_ssa_def
*tex_pos
)
446 const struct glsl_type
*sampler_type
=
447 glsl_sampler_type(GLSL_SAMPLER_DIM_2D
, false, false, GLSL_TYPE_UINT
);
448 nir_variable
*sampler
= nir_variable_create(b
->shader
, nir_var_uniform
,
449 sampler_type
, "s_tex");
450 sampler
->data
.descriptor_set
= 0;
451 sampler
->data
.binding
= 0;
453 nir_tex_instr
*tex
= nir_tex_instr_create(b
->shader
, 2);
454 tex
->sampler_dim
= GLSL_SAMPLER_DIM_2D
;
455 tex
->op
= nir_texop_txf
;
456 tex
->src
[0].src_type
= nir_tex_src_coord
;
457 tex
->src
[0].src
= nir_src_for_ssa(tex_pos
);
458 tex
->src
[1].src_type
= nir_tex_src_lod
;
459 tex
->src
[1].src
= nir_src_for_ssa(nir_imm_int(b
, 0));
460 tex
->dest_type
= nir_type_uint
;
461 tex
->is_array
= false;
462 tex
->coord_components
= 2;
463 tex
->texture
= nir_deref_var_create(tex
, sampler
);
466 nir_ssa_dest_init(&tex
->instr
, &tex
->dest
, 4, 32, "tex");
467 nir_builder_instr_insert(b
, &tex
->instr
);
469 return &tex
->dest
.ssa
;
474 build_nir_buffer_fetch(struct nir_builder
*b
, struct radv_device
*device
,
475 nir_ssa_def
*tex_pos
)
477 const struct glsl_type
*sampler_type
=
478 glsl_sampler_type(GLSL_SAMPLER_DIM_BUF
, false, false, GLSL_TYPE_UINT
);
479 nir_variable
*sampler
= nir_variable_create(b
->shader
, nir_var_uniform
,
480 sampler_type
, "s_tex");
481 sampler
->data
.descriptor_set
= 0;
482 sampler
->data
.binding
= 0;
484 nir_intrinsic_instr
*width
= nir_intrinsic_instr_create(b
->shader
, nir_intrinsic_load_push_constant
);
485 nir_intrinsic_set_base(width
, 16);
486 nir_intrinsic_set_range(width
, 4);
487 width
->src
[0] = nir_src_for_ssa(nir_imm_int(b
, 0));
488 width
->num_components
= 1;
489 nir_ssa_dest_init(&width
->instr
, &width
->dest
, 1, 32, "width");
490 nir_builder_instr_insert(b
, &width
->instr
);
492 nir_ssa_def
*pos_x
= nir_channel(b
, tex_pos
, 0);
493 nir_ssa_def
*pos_y
= nir_channel(b
, tex_pos
, 1);
494 pos_y
= nir_imul(b
, pos_y
, &width
->dest
.ssa
);
495 pos_x
= nir_iadd(b
, pos_x
, pos_y
);
496 //pos_x = nir_iadd(b, pos_x, nir_imm_int(b, 100000));
498 nir_tex_instr
*tex
= nir_tex_instr_create(b
->shader
, 1);
499 tex
->sampler_dim
= GLSL_SAMPLER_DIM_BUF
;
500 tex
->op
= nir_texop_txf
;
501 tex
->src
[0].src_type
= nir_tex_src_coord
;
502 tex
->src
[0].src
= nir_src_for_ssa(pos_x
);
503 tex
->dest_type
= nir_type_uint
;
504 tex
->is_array
= false;
505 tex
->coord_components
= 1;
506 tex
->texture
= nir_deref_var_create(tex
, sampler
);
509 nir_ssa_dest_init(&tex
->instr
, &tex
->dest
, 4, 32, "tex");
510 nir_builder_instr_insert(b
, &tex
->instr
);
512 return &tex
->dest
.ssa
;
515 static const VkPipelineVertexInputStateCreateInfo normal_vi_create_info
= {
516 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO
,
517 .vertexBindingDescriptionCount
= 0,
518 .vertexAttributeDescriptionCount
= 0,
522 build_nir_copy_fragment_shader(struct radv_device
*device
,
523 texel_fetch_build_func txf_func
, const char* name
)
525 const struct glsl_type
*vec4
= glsl_vec4_type();
526 const struct glsl_type
*vec2
= glsl_vector_type(GLSL_TYPE_FLOAT
, 2);
529 nir_builder_init_simple_shader(&b
, NULL
, MESA_SHADER_FRAGMENT
, NULL
);
530 b
.shader
->info
->name
= ralloc_strdup(b
.shader
, name
);
532 nir_variable
*tex_pos_in
= nir_variable_create(b
.shader
, nir_var_shader_in
,
534 tex_pos_in
->data
.location
= VARYING_SLOT_VAR0
;
536 nir_variable
*color_out
= nir_variable_create(b
.shader
, nir_var_shader_out
,
538 color_out
->data
.location
= FRAG_RESULT_DATA0
;
540 nir_ssa_def
*pos_int
= nir_f2i32(&b
, nir_load_var(&b
, tex_pos_in
));
541 unsigned swiz
[4] = { 0, 1 };
542 nir_ssa_def
*tex_pos
= nir_swizzle(&b
, pos_int
, swiz
, 2, false);
544 nir_ssa_def
*color
= txf_func(&b
, device
, tex_pos
);
545 nir_store_var(&b
, color_out
, color
, 0xf);
551 build_nir_copy_fragment_shader_depth(struct radv_device
*device
,
552 texel_fetch_build_func txf_func
, const char* name
)
554 const struct glsl_type
*vec4
= glsl_vec4_type();
555 const struct glsl_type
*vec2
= glsl_vector_type(GLSL_TYPE_FLOAT
, 2);
558 nir_builder_init_simple_shader(&b
, NULL
, MESA_SHADER_FRAGMENT
, NULL
);
559 b
.shader
->info
->name
= ralloc_strdup(b
.shader
, name
);
561 nir_variable
*tex_pos_in
= nir_variable_create(b
.shader
, nir_var_shader_in
,
563 tex_pos_in
->data
.location
= VARYING_SLOT_VAR0
;
565 nir_variable
*color_out
= nir_variable_create(b
.shader
, nir_var_shader_out
,
567 color_out
->data
.location
= FRAG_RESULT_DEPTH
;
569 nir_ssa_def
*pos_int
= nir_f2i32(&b
, nir_load_var(&b
, tex_pos_in
));
570 unsigned swiz
[4] = { 0, 1 };
571 nir_ssa_def
*tex_pos
= nir_swizzle(&b
, pos_int
, swiz
, 2, false);
573 nir_ssa_def
*color
= txf_func(&b
, device
, tex_pos
);
574 nir_store_var(&b
, color_out
, color
, 0x1);
580 build_nir_copy_fragment_shader_stencil(struct radv_device
*device
,
581 texel_fetch_build_func txf_func
, const char* name
)
583 const struct glsl_type
*vec4
= glsl_vec4_type();
584 const struct glsl_type
*vec2
= glsl_vector_type(GLSL_TYPE_FLOAT
, 2);
587 nir_builder_init_simple_shader(&b
, NULL
, MESA_SHADER_FRAGMENT
, NULL
);
588 b
.shader
->info
->name
= ralloc_strdup(b
.shader
, name
);
590 nir_variable
*tex_pos_in
= nir_variable_create(b
.shader
, nir_var_shader_in
,
592 tex_pos_in
->data
.location
= VARYING_SLOT_VAR0
;
594 nir_variable
*color_out
= nir_variable_create(b
.shader
, nir_var_shader_out
,
596 color_out
->data
.location
= FRAG_RESULT_STENCIL
;
598 nir_ssa_def
*pos_int
= nir_f2i32(&b
, nir_load_var(&b
, tex_pos_in
));
599 unsigned swiz
[4] = { 0, 1 };
600 nir_ssa_def
*tex_pos
= nir_swizzle(&b
, pos_int
, swiz
, 2, false);
602 nir_ssa_def
*color
= txf_func(&b
, device
, tex_pos
);
603 nir_store_var(&b
, color_out
, color
, 0x1);
609 radv_device_finish_meta_blit2d_state(struct radv_device
*device
)
611 for(unsigned j
= 0; j
< NUM_META_FS_KEYS
; ++j
) {
612 if (device
->meta_state
.blit2d
.render_passes
[j
]) {
613 radv_DestroyRenderPass(radv_device_to_handle(device
),
614 device
->meta_state
.blit2d
.render_passes
[j
],
615 &device
->meta_state
.alloc
);
619 radv_DestroyRenderPass(radv_device_to_handle(device
),
620 device
->meta_state
.blit2d
.depth_only_rp
,
621 &device
->meta_state
.alloc
);
622 radv_DestroyRenderPass(radv_device_to_handle(device
),
623 device
->meta_state
.blit2d
.stencil_only_rp
,
624 &device
->meta_state
.alloc
);
626 for (unsigned src
= 0; src
< BLIT2D_NUM_SRC_TYPES
; src
++) {
627 if (device
->meta_state
.blit2d
.p_layouts
[src
]) {
628 radv_DestroyPipelineLayout(radv_device_to_handle(device
),
629 device
->meta_state
.blit2d
.p_layouts
[src
],
630 &device
->meta_state
.alloc
);
633 if (device
->meta_state
.blit2d
.ds_layouts
[src
]) {
634 radv_DestroyDescriptorSetLayout(radv_device_to_handle(device
),
635 device
->meta_state
.blit2d
.ds_layouts
[src
],
636 &device
->meta_state
.alloc
);
639 for (unsigned j
= 0; j
< NUM_META_FS_KEYS
; ++j
) {
640 if (device
->meta_state
.blit2d
.pipelines
[src
][j
]) {
641 radv_DestroyPipeline(radv_device_to_handle(device
),
642 device
->meta_state
.blit2d
.pipelines
[src
][j
],
643 &device
->meta_state
.alloc
);
647 radv_DestroyPipeline(radv_device_to_handle(device
),
648 device
->meta_state
.blit2d
.depth_only_pipeline
[src
],
649 &device
->meta_state
.alloc
);
650 radv_DestroyPipeline(radv_device_to_handle(device
),
651 device
->meta_state
.blit2d
.stencil_only_pipeline
[src
],
652 &device
->meta_state
.alloc
);
657 blit2d_init_color_pipeline(struct radv_device
*device
,
658 enum blit2d_src_type src_type
,
662 unsigned fs_key
= radv_format_meta_fs_key(format
);
665 texel_fetch_build_func src_func
;
667 case BLIT2D_SRC_TYPE_IMAGE
:
668 src_func
= build_nir_texel_fetch
;
669 name
= "meta_blit2d_image_fs";
671 case BLIT2D_SRC_TYPE_BUFFER
:
672 src_func
= build_nir_buffer_fetch
;
673 name
= "meta_blit2d_buffer_fs";
676 unreachable("unknown blit src type\n");
680 const VkPipelineVertexInputStateCreateInfo
*vi_create_info
;
681 struct radv_shader_module fs
= { .nir
= NULL
};
684 fs
.nir
= build_nir_copy_fragment_shader(device
, src_func
, name
);
685 vi_create_info
= &normal_vi_create_info
;
687 struct radv_shader_module vs
= {
688 .nir
= build_nir_vertex_shader(),
691 VkPipelineShaderStageCreateInfo pipeline_shader_stages
[] = {
693 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
694 .stage
= VK_SHADER_STAGE_VERTEX_BIT
,
695 .module
= radv_shader_module_to_handle(&vs
),
697 .pSpecializationInfo
= NULL
699 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
700 .stage
= VK_SHADER_STAGE_FRAGMENT_BIT
,
701 .module
= radv_shader_module_to_handle(&fs
),
703 .pSpecializationInfo
= NULL
707 if (!device
->meta_state
.blit2d
.render_passes
[fs_key
]) {
708 result
= radv_CreateRenderPass(radv_device_to_handle(device
),
709 &(VkRenderPassCreateInfo
) {
710 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
,
711 .attachmentCount
= 1,
712 .pAttachments
= &(VkAttachmentDescription
) {
714 .loadOp
= VK_ATTACHMENT_LOAD_OP_LOAD
,
715 .storeOp
= VK_ATTACHMENT_STORE_OP_STORE
,
716 .initialLayout
= VK_IMAGE_LAYOUT_GENERAL
,
717 .finalLayout
= VK_IMAGE_LAYOUT_GENERAL
,
720 .pSubpasses
= &(VkSubpassDescription
) {
721 .pipelineBindPoint
= VK_PIPELINE_BIND_POINT_GRAPHICS
,
722 .inputAttachmentCount
= 0,
723 .colorAttachmentCount
= 1,
724 .pColorAttachments
= &(VkAttachmentReference
) {
726 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
728 .pResolveAttachments
= NULL
,
729 .pDepthStencilAttachment
= &(VkAttachmentReference
) {
730 .attachment
= VK_ATTACHMENT_UNUSED
,
731 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
733 .preserveAttachmentCount
= 1,
734 .pPreserveAttachments
= (uint32_t[]) { 0 },
736 .dependencyCount
= 0,
737 }, &device
->meta_state
.alloc
, &device
->meta_state
.blit2d
.render_passes
[fs_key
]);
740 const VkGraphicsPipelineCreateInfo vk_pipeline_info
= {
741 .sType
= VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
,
742 .stageCount
= ARRAY_SIZE(pipeline_shader_stages
),
743 .pStages
= pipeline_shader_stages
,
744 .pVertexInputState
= vi_create_info
,
745 .pInputAssemblyState
= &(VkPipelineInputAssemblyStateCreateInfo
) {
746 .sType
= VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO
,
747 .topology
= VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
,
748 .primitiveRestartEnable
= false,
750 .pViewportState
= &(VkPipelineViewportStateCreateInfo
) {
751 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO
,
755 .pRasterizationState
= &(VkPipelineRasterizationStateCreateInfo
) {
756 .sType
= VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO
,
757 .rasterizerDiscardEnable
= false,
758 .polygonMode
= VK_POLYGON_MODE_FILL
,
759 .cullMode
= VK_CULL_MODE_NONE
,
760 .frontFace
= VK_FRONT_FACE_COUNTER_CLOCKWISE
762 .pMultisampleState
= &(VkPipelineMultisampleStateCreateInfo
) {
763 .sType
= VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO
,
764 .rasterizationSamples
= 1,
765 .sampleShadingEnable
= false,
766 .pSampleMask
= (VkSampleMask
[]) { UINT32_MAX
},
768 .pColorBlendState
= &(VkPipelineColorBlendStateCreateInfo
) {
769 .sType
= VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO
,
770 .attachmentCount
= 1,
771 .pAttachments
= (VkPipelineColorBlendAttachmentState
[]) {
773 VK_COLOR_COMPONENT_A_BIT
|
774 VK_COLOR_COMPONENT_R_BIT
|
775 VK_COLOR_COMPONENT_G_BIT
|
776 VK_COLOR_COMPONENT_B_BIT
},
779 .pDynamicState
= &(VkPipelineDynamicStateCreateInfo
) {
780 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO
,
781 .dynamicStateCount
= 9,
782 .pDynamicStates
= (VkDynamicState
[]) {
783 VK_DYNAMIC_STATE_VIEWPORT
,
784 VK_DYNAMIC_STATE_SCISSOR
,
785 VK_DYNAMIC_STATE_LINE_WIDTH
,
786 VK_DYNAMIC_STATE_DEPTH_BIAS
,
787 VK_DYNAMIC_STATE_BLEND_CONSTANTS
,
788 VK_DYNAMIC_STATE_DEPTH_BOUNDS
,
789 VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK
,
790 VK_DYNAMIC_STATE_STENCIL_WRITE_MASK
,
791 VK_DYNAMIC_STATE_STENCIL_REFERENCE
,
795 .layout
= device
->meta_state
.blit2d
.p_layouts
[src_type
],
796 .renderPass
= device
->meta_state
.blit2d
.render_passes
[fs_key
],
800 const struct radv_graphics_pipeline_create_info radv_pipeline_info
= {
804 result
= radv_graphics_pipeline_create(radv_device_to_handle(device
),
805 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
806 &vk_pipeline_info
, &radv_pipeline_info
,
807 &device
->meta_state
.alloc
,
808 &device
->meta_state
.blit2d
.pipelines
[src_type
][fs_key
]);
818 blit2d_init_depth_only_pipeline(struct radv_device
*device
,
819 enum blit2d_src_type src_type
)
824 texel_fetch_build_func src_func
;
826 case BLIT2D_SRC_TYPE_IMAGE
:
827 src_func
= build_nir_texel_fetch
;
828 name
= "meta_blit2d_depth_image_fs";
830 case BLIT2D_SRC_TYPE_BUFFER
:
831 src_func
= build_nir_buffer_fetch
;
832 name
= "meta_blit2d_depth_buffer_fs";
835 unreachable("unknown blit src type\n");
839 const VkPipelineVertexInputStateCreateInfo
*vi_create_info
;
840 struct radv_shader_module fs
= { .nir
= NULL
};
842 fs
.nir
= build_nir_copy_fragment_shader_depth(device
, src_func
, name
);
843 vi_create_info
= &normal_vi_create_info
;
845 struct radv_shader_module vs
= {
846 .nir
= build_nir_vertex_shader(),
849 VkPipelineShaderStageCreateInfo pipeline_shader_stages
[] = {
851 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
852 .stage
= VK_SHADER_STAGE_VERTEX_BIT
,
853 .module
= radv_shader_module_to_handle(&vs
),
855 .pSpecializationInfo
= NULL
857 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
858 .stage
= VK_SHADER_STAGE_FRAGMENT_BIT
,
859 .module
= radv_shader_module_to_handle(&fs
),
861 .pSpecializationInfo
= NULL
865 if (!device
->meta_state
.blit2d
.depth_only_rp
) {
866 result
= radv_CreateRenderPass(radv_device_to_handle(device
),
867 &(VkRenderPassCreateInfo
) {
868 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
,
869 .attachmentCount
= 1,
870 .pAttachments
= &(VkAttachmentDescription
) {
872 .loadOp
= VK_ATTACHMENT_LOAD_OP_LOAD
,
873 .storeOp
= VK_ATTACHMENT_STORE_OP_STORE
,
874 .initialLayout
= VK_IMAGE_LAYOUT_GENERAL
,
875 .finalLayout
= VK_IMAGE_LAYOUT_GENERAL
,
878 .pSubpasses
= &(VkSubpassDescription
) {
879 .pipelineBindPoint
= VK_PIPELINE_BIND_POINT_GRAPHICS
,
880 .inputAttachmentCount
= 0,
881 .colorAttachmentCount
= 0,
882 .pColorAttachments
= NULL
,
883 .pResolveAttachments
= NULL
,
884 .pDepthStencilAttachment
= &(VkAttachmentReference
) {
886 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
888 .preserveAttachmentCount
= 1,
889 .pPreserveAttachments
= (uint32_t[]) { 0 },
891 .dependencyCount
= 0,
892 }, &device
->meta_state
.alloc
, &device
->meta_state
.blit2d
.depth_only_rp
);
895 const VkGraphicsPipelineCreateInfo vk_pipeline_info
= {
896 .sType
= VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
,
897 .stageCount
= ARRAY_SIZE(pipeline_shader_stages
),
898 .pStages
= pipeline_shader_stages
,
899 .pVertexInputState
= vi_create_info
,
900 .pInputAssemblyState
= &(VkPipelineInputAssemblyStateCreateInfo
) {
901 .sType
= VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO
,
902 .topology
= VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
,
903 .primitiveRestartEnable
= false,
905 .pViewportState
= &(VkPipelineViewportStateCreateInfo
) {
906 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO
,
910 .pRasterizationState
= &(VkPipelineRasterizationStateCreateInfo
) {
911 .sType
= VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO
,
912 .rasterizerDiscardEnable
= false,
913 .polygonMode
= VK_POLYGON_MODE_FILL
,
914 .cullMode
= VK_CULL_MODE_NONE
,
915 .frontFace
= VK_FRONT_FACE_COUNTER_CLOCKWISE
917 .pMultisampleState
= &(VkPipelineMultisampleStateCreateInfo
) {
918 .sType
= VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO
,
919 .rasterizationSamples
= 1,
920 .sampleShadingEnable
= false,
921 .pSampleMask
= (VkSampleMask
[]) { UINT32_MAX
},
923 .pColorBlendState
= &(VkPipelineColorBlendStateCreateInfo
) {
924 .sType
= VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO
,
925 .attachmentCount
= 0,
926 .pAttachments
= NULL
,
928 .pDepthStencilState
= &(VkPipelineDepthStencilStateCreateInfo
) {
929 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO
,
930 .depthTestEnable
= true,
931 .depthWriteEnable
= true,
932 .depthCompareOp
= VK_COMPARE_OP_ALWAYS
,
934 .pDynamicState
= &(VkPipelineDynamicStateCreateInfo
) {
935 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO
,
936 .dynamicStateCount
= 9,
937 .pDynamicStates
= (VkDynamicState
[]) {
938 VK_DYNAMIC_STATE_VIEWPORT
,
939 VK_DYNAMIC_STATE_SCISSOR
,
940 VK_DYNAMIC_STATE_LINE_WIDTH
,
941 VK_DYNAMIC_STATE_DEPTH_BIAS
,
942 VK_DYNAMIC_STATE_BLEND_CONSTANTS
,
943 VK_DYNAMIC_STATE_DEPTH_BOUNDS
,
944 VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK
,
945 VK_DYNAMIC_STATE_STENCIL_WRITE_MASK
,
946 VK_DYNAMIC_STATE_STENCIL_REFERENCE
,
950 .layout
= device
->meta_state
.blit2d
.p_layouts
[src_type
],
951 .renderPass
= device
->meta_state
.blit2d
.depth_only_rp
,
955 const struct radv_graphics_pipeline_create_info radv_pipeline_info
= {
959 result
= radv_graphics_pipeline_create(radv_device_to_handle(device
),
960 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
961 &vk_pipeline_info
, &radv_pipeline_info
,
962 &device
->meta_state
.alloc
,
963 &device
->meta_state
.blit2d
.depth_only_pipeline
[src_type
]);
973 blit2d_init_stencil_only_pipeline(struct radv_device
*device
,
974 enum blit2d_src_type src_type
)
979 texel_fetch_build_func src_func
;
981 case BLIT2D_SRC_TYPE_IMAGE
:
982 src_func
= build_nir_texel_fetch
;
983 name
= "meta_blit2d_stencil_image_fs";
985 case BLIT2D_SRC_TYPE_BUFFER
:
986 src_func
= build_nir_buffer_fetch
;
987 name
= "meta_blit2d_stencil_buffer_fs";
990 unreachable("unknown blit src type\n");
994 const VkPipelineVertexInputStateCreateInfo
*vi_create_info
;
995 struct radv_shader_module fs
= { .nir
= NULL
};
997 fs
.nir
= build_nir_copy_fragment_shader_stencil(device
, src_func
, name
);
998 vi_create_info
= &normal_vi_create_info
;
1000 struct radv_shader_module vs
= {
1001 .nir
= build_nir_vertex_shader(),
1004 VkPipelineShaderStageCreateInfo pipeline_shader_stages
[] = {
1006 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
1007 .stage
= VK_SHADER_STAGE_VERTEX_BIT
,
1008 .module
= radv_shader_module_to_handle(&vs
),
1010 .pSpecializationInfo
= NULL
1012 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
1013 .stage
= VK_SHADER_STAGE_FRAGMENT_BIT
,
1014 .module
= radv_shader_module_to_handle(&fs
),
1016 .pSpecializationInfo
= NULL
1020 if (!device
->meta_state
.blit2d
.stencil_only_rp
) {
1021 result
= radv_CreateRenderPass(radv_device_to_handle(device
),
1022 &(VkRenderPassCreateInfo
) {
1023 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
,
1024 .attachmentCount
= 1,
1025 .pAttachments
= &(VkAttachmentDescription
) {
1027 .loadOp
= VK_ATTACHMENT_LOAD_OP_LOAD
,
1028 .storeOp
= VK_ATTACHMENT_STORE_OP_STORE
,
1029 .initialLayout
= VK_IMAGE_LAYOUT_GENERAL
,
1030 .finalLayout
= VK_IMAGE_LAYOUT_GENERAL
,
1033 .pSubpasses
= &(VkSubpassDescription
) {
1034 .pipelineBindPoint
= VK_PIPELINE_BIND_POINT_GRAPHICS
,
1035 .inputAttachmentCount
= 0,
1036 .colorAttachmentCount
= 0,
1037 .pColorAttachments
= NULL
,
1038 .pResolveAttachments
= NULL
,
1039 .pDepthStencilAttachment
= &(VkAttachmentReference
) {
1041 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
1043 .preserveAttachmentCount
= 1,
1044 .pPreserveAttachments
= (uint32_t[]) { 0 },
1046 .dependencyCount
= 0,
1047 }, &device
->meta_state
.alloc
, &device
->meta_state
.blit2d
.stencil_only_rp
);
1050 const VkGraphicsPipelineCreateInfo vk_pipeline_info
= {
1051 .sType
= VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
,
1052 .stageCount
= ARRAY_SIZE(pipeline_shader_stages
),
1053 .pStages
= pipeline_shader_stages
,
1054 .pVertexInputState
= vi_create_info
,
1055 .pInputAssemblyState
= &(VkPipelineInputAssemblyStateCreateInfo
) {
1056 .sType
= VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO
,
1057 .topology
= VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
,
1058 .primitiveRestartEnable
= false,
1060 .pViewportState
= &(VkPipelineViewportStateCreateInfo
) {
1061 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO
,
1065 .pRasterizationState
= &(VkPipelineRasterizationStateCreateInfo
) {
1066 .sType
= VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO
,
1067 .rasterizerDiscardEnable
= false,
1068 .polygonMode
= VK_POLYGON_MODE_FILL
,
1069 .cullMode
= VK_CULL_MODE_NONE
,
1070 .frontFace
= VK_FRONT_FACE_COUNTER_CLOCKWISE
1072 .pMultisampleState
= &(VkPipelineMultisampleStateCreateInfo
) {
1073 .sType
= VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO
,
1074 .rasterizationSamples
= 1,
1075 .sampleShadingEnable
= false,
1076 .pSampleMask
= (VkSampleMask
[]) { UINT32_MAX
},
1078 .pColorBlendState
= &(VkPipelineColorBlendStateCreateInfo
) {
1079 .sType
= VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO
,
1080 .attachmentCount
= 0,
1081 .pAttachments
= NULL
,
1083 .pDepthStencilState
= &(VkPipelineDepthStencilStateCreateInfo
) {
1084 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO
,
1085 .depthTestEnable
= false,
1086 .depthWriteEnable
= false,
1087 .stencilTestEnable
= true,
1089 .failOp
= VK_STENCIL_OP_REPLACE
,
1090 .passOp
= VK_STENCIL_OP_REPLACE
,
1091 .depthFailOp
= VK_STENCIL_OP_REPLACE
,
1092 .compareOp
= VK_COMPARE_OP_ALWAYS
,
1093 .compareMask
= 0xff,
1098 .failOp
= VK_STENCIL_OP_REPLACE
,
1099 .passOp
= VK_STENCIL_OP_REPLACE
,
1100 .depthFailOp
= VK_STENCIL_OP_REPLACE
,
1101 .compareOp
= VK_COMPARE_OP_ALWAYS
,
1102 .compareMask
= 0xff,
1106 .depthCompareOp
= VK_COMPARE_OP_ALWAYS
,
1108 .pDynamicState
= &(VkPipelineDynamicStateCreateInfo
) {
1109 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO
,
1110 .dynamicStateCount
= 6,
1111 .pDynamicStates
= (VkDynamicState
[]) {
1112 VK_DYNAMIC_STATE_VIEWPORT
,
1113 VK_DYNAMIC_STATE_SCISSOR
,
1114 VK_DYNAMIC_STATE_LINE_WIDTH
,
1115 VK_DYNAMIC_STATE_DEPTH_BIAS
,
1116 VK_DYNAMIC_STATE_BLEND_CONSTANTS
,
1117 VK_DYNAMIC_STATE_DEPTH_BOUNDS
,
1121 .layout
= device
->meta_state
.blit2d
.p_layouts
[src_type
],
1122 .renderPass
= device
->meta_state
.blit2d
.stencil_only_rp
,
1126 const struct radv_graphics_pipeline_create_info radv_pipeline_info
= {
1127 .use_rectlist
= true
1130 result
= radv_graphics_pipeline_create(radv_device_to_handle(device
),
1131 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
1132 &vk_pipeline_info
, &radv_pipeline_info
,
1133 &device
->meta_state
.alloc
,
1134 &device
->meta_state
.blit2d
.stencil_only_pipeline
[src_type
]);
1137 ralloc_free(vs
.nir
);
1138 ralloc_free(fs
.nir
);
1143 static VkFormat pipeline_formats
[] = {
1144 VK_FORMAT_R8G8B8A8_UNORM
,
1145 VK_FORMAT_R8G8B8A8_UINT
,
1146 VK_FORMAT_R8G8B8A8_SINT
,
1147 VK_FORMAT_R16G16B16A16_UNORM
,
1148 VK_FORMAT_R16G16B16A16_SNORM
,
1149 VK_FORMAT_R16G16B16A16_UINT
,
1150 VK_FORMAT_R16G16B16A16_SINT
,
1151 VK_FORMAT_R32_SFLOAT
,
1152 VK_FORMAT_R32G32_SFLOAT
,
1153 VK_FORMAT_R32G32B32A32_SFLOAT
1157 radv_device_init_meta_blit2d_state(struct radv_device
*device
)
1161 zero(device
->meta_state
.blit2d
);
1163 const VkPushConstantRange push_constant_ranges
[] = {
1164 {VK_SHADER_STAGE_VERTEX_BIT
, 0, 16},
1165 {VK_SHADER_STAGE_FRAGMENT_BIT
, 16, 4},
1167 result
= radv_CreateDescriptorSetLayout(radv_device_to_handle(device
),
1168 &(VkDescriptorSetLayoutCreateInfo
) {
1169 .sType
= VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
,
1170 .flags
= VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
,
1172 .pBindings
= (VkDescriptorSetLayoutBinding
[]) {
1175 .descriptorType
= VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
,
1176 .descriptorCount
= 1,
1177 .stageFlags
= VK_SHADER_STAGE_FRAGMENT_BIT
,
1178 .pImmutableSamplers
= NULL
1181 }, &device
->meta_state
.alloc
, &device
->meta_state
.blit2d
.ds_layouts
[BLIT2D_SRC_TYPE_IMAGE
]);
1182 if (result
!= VK_SUCCESS
)
1185 result
= radv_CreatePipelineLayout(radv_device_to_handle(device
),
1186 &(VkPipelineLayoutCreateInfo
) {
1187 .sType
= VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
,
1188 .setLayoutCount
= 1,
1189 .pSetLayouts
= &device
->meta_state
.blit2d
.ds_layouts
[BLIT2D_SRC_TYPE_IMAGE
],
1190 .pushConstantRangeCount
= 1,
1191 .pPushConstantRanges
= push_constant_ranges
,
1193 &device
->meta_state
.alloc
, &device
->meta_state
.blit2d
.p_layouts
[BLIT2D_SRC_TYPE_IMAGE
]);
1194 if (result
!= VK_SUCCESS
)
1197 result
= radv_CreateDescriptorSetLayout(radv_device_to_handle(device
),
1198 &(VkDescriptorSetLayoutCreateInfo
) {
1199 .sType
= VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
,
1200 .flags
= VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
,
1202 .pBindings
= (VkDescriptorSetLayoutBinding
[]) {
1205 .descriptorType
= VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
,
1206 .descriptorCount
= 1,
1207 .stageFlags
= VK_SHADER_STAGE_FRAGMENT_BIT
,
1208 .pImmutableSamplers
= NULL
1211 }, &device
->meta_state
.alloc
, &device
->meta_state
.blit2d
.ds_layouts
[BLIT2D_SRC_TYPE_BUFFER
]);
1212 if (result
!= VK_SUCCESS
)
1216 result
= radv_CreatePipelineLayout(radv_device_to_handle(device
),
1217 &(VkPipelineLayoutCreateInfo
) {
1218 .sType
= VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
,
1219 .setLayoutCount
= 1,
1220 .pSetLayouts
= &device
->meta_state
.blit2d
.ds_layouts
[BLIT2D_SRC_TYPE_BUFFER
],
1221 .pushConstantRangeCount
= 2,
1222 .pPushConstantRanges
= push_constant_ranges
,
1224 &device
->meta_state
.alloc
, &device
->meta_state
.blit2d
.p_layouts
[BLIT2D_SRC_TYPE_BUFFER
]);
1225 if (result
!= VK_SUCCESS
)
1228 for (unsigned src
= 0; src
< BLIT2D_NUM_SRC_TYPES
; src
++) {
1229 for (unsigned j
= 0; j
< ARRAY_SIZE(pipeline_formats
); ++j
) {
1230 result
= blit2d_init_color_pipeline(device
, src
, pipeline_formats
[j
]);
1231 if (result
!= VK_SUCCESS
)
1235 result
= blit2d_init_depth_only_pipeline(device
, src
);
1236 if (result
!= VK_SUCCESS
)
1239 result
= blit2d_init_stencil_only_pipeline(device
, src
);
1240 if (result
!= VK_SUCCESS
)
1247 radv_device_finish_meta_blit2d_state(device
);