2 * Copyright © 2015 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 #include "radv_meta.h"
25 #include "nir/nir_builder.h"
28 VkOffset3D src_offset
;
29 VkExtent3D src_extent
;
30 VkOffset3D dest_offset
;
31 VkExtent3D dest_extent
;
35 build_nir_vertex_shader(void)
37 const struct glsl_type
*vec4
= glsl_vec4_type();
40 nir_builder_init_simple_shader(&b
, NULL
, MESA_SHADER_VERTEX
, NULL
);
41 b
.shader
->info
->name
= ralloc_strdup(b
.shader
, "meta_blit_vs");
43 nir_variable
*pos_out
= nir_variable_create(b
.shader
, nir_var_shader_out
,
45 pos_out
->data
.location
= VARYING_SLOT_POS
;
47 nir_variable
*tex_pos_in
= nir_variable_create(b
.shader
, nir_var_shader_in
,
49 tex_pos_in
->data
.location
= VERT_ATTRIB_GENERIC0
;
50 nir_variable
*tex_pos_out
= nir_variable_create(b
.shader
, nir_var_shader_out
,
52 tex_pos_out
->data
.location
= VARYING_SLOT_VAR0
;
53 tex_pos_out
->data
.interpolation
= INTERP_MODE_SMOOTH
;
54 nir_copy_var(&b
, tex_pos_out
, tex_pos_in
);
56 nir_ssa_def
*outvec
= radv_meta_gen_rect_vertices(&b
);
58 nir_store_var(&b
, pos_out
, outvec
, 0xf);
63 build_nir_copy_fragment_shader(enum glsl_sampler_dim tex_dim
)
66 const struct glsl_type
*vec4
= glsl_vec4_type();
69 nir_builder_init_simple_shader(&b
, NULL
, MESA_SHADER_FRAGMENT
, NULL
);
71 sprintf(shader_name
, "meta_blit_fs.%d", tex_dim
);
72 b
.shader
->info
->name
= ralloc_strdup(b
.shader
, shader_name
);
74 nir_variable
*tex_pos_in
= nir_variable_create(b
.shader
, nir_var_shader_in
,
76 tex_pos_in
->data
.location
= VARYING_SLOT_VAR0
;
78 /* Swizzle the array index which comes in as Z coordinate into the right
81 unsigned swz
[] = { 0, (tex_dim
== GLSL_SAMPLER_DIM_1D
? 2 : 1), 2 };
82 nir_ssa_def
*const tex_pos
=
83 nir_swizzle(&b
, nir_load_var(&b
, tex_pos_in
), swz
,
84 (tex_dim
== GLSL_SAMPLER_DIM_1D
? 2 : 3), false);
86 const struct glsl_type
*sampler_type
=
87 glsl_sampler_type(tex_dim
, false, tex_dim
!= GLSL_SAMPLER_DIM_3D
,
88 glsl_get_base_type(vec4
));
89 nir_variable
*sampler
= nir_variable_create(b
.shader
, nir_var_uniform
,
90 sampler_type
, "s_tex");
91 sampler
->data
.descriptor_set
= 0;
92 sampler
->data
.binding
= 0;
94 nir_tex_instr
*tex
= nir_tex_instr_create(b
.shader
, 1);
95 tex
->sampler_dim
= tex_dim
;
96 tex
->op
= nir_texop_tex
;
97 tex
->src
[0].src_type
= nir_tex_src_coord
;
98 tex
->src
[0].src
= nir_src_for_ssa(tex_pos
);
99 tex
->dest_type
= nir_type_float
; /* TODO */
100 tex
->is_array
= glsl_sampler_type_is_array(sampler_type
);
101 tex
->coord_components
= tex_pos
->num_components
;
102 tex
->texture
= nir_deref_var_create(tex
, sampler
);
103 tex
->sampler
= nir_deref_var_create(tex
, sampler
);
105 nir_ssa_dest_init(&tex
->instr
, &tex
->dest
, 4, 32, "tex");
106 nir_builder_instr_insert(&b
, &tex
->instr
);
108 nir_variable
*color_out
= nir_variable_create(b
.shader
, nir_var_shader_out
,
110 color_out
->data
.location
= FRAG_RESULT_DATA0
;
111 nir_store_var(&b
, color_out
, &tex
->dest
.ssa
, 0xf);
117 build_nir_copy_fragment_shader_depth(enum glsl_sampler_dim tex_dim
)
119 char shader_name
[64];
120 const struct glsl_type
*vec4
= glsl_vec4_type();
123 nir_builder_init_simple_shader(&b
, NULL
, MESA_SHADER_FRAGMENT
, NULL
);
125 sprintf(shader_name
, "meta_blit_depth_fs.%d", tex_dim
);
126 b
.shader
->info
->name
= ralloc_strdup(b
.shader
, shader_name
);
128 nir_variable
*tex_pos_in
= nir_variable_create(b
.shader
, nir_var_shader_in
,
130 tex_pos_in
->data
.location
= VARYING_SLOT_VAR0
;
132 /* Swizzle the array index which comes in as Z coordinate into the right
135 unsigned swz
[] = { 0, (tex_dim
== GLSL_SAMPLER_DIM_1D
? 2 : 1), 2 };
136 nir_ssa_def
*const tex_pos
=
137 nir_swizzle(&b
, nir_load_var(&b
, tex_pos_in
), swz
,
138 (tex_dim
== GLSL_SAMPLER_DIM_1D
? 2 : 3), false);
140 const struct glsl_type
*sampler_type
=
141 glsl_sampler_type(tex_dim
, false, tex_dim
!= GLSL_SAMPLER_DIM_3D
,
142 glsl_get_base_type(vec4
));
143 nir_variable
*sampler
= nir_variable_create(b
.shader
, nir_var_uniform
,
144 sampler_type
, "s_tex");
145 sampler
->data
.descriptor_set
= 0;
146 sampler
->data
.binding
= 0;
148 nir_tex_instr
*tex
= nir_tex_instr_create(b
.shader
, 1);
149 tex
->sampler_dim
= tex_dim
;
150 tex
->op
= nir_texop_tex
;
151 tex
->src
[0].src_type
= nir_tex_src_coord
;
152 tex
->src
[0].src
= nir_src_for_ssa(tex_pos
);
153 tex
->dest_type
= nir_type_float
; /* TODO */
154 tex
->is_array
= glsl_sampler_type_is_array(sampler_type
);
155 tex
->coord_components
= tex_pos
->num_components
;
156 tex
->texture
= nir_deref_var_create(tex
, sampler
);
157 tex
->sampler
= nir_deref_var_create(tex
, sampler
);
159 nir_ssa_dest_init(&tex
->instr
, &tex
->dest
, 4, 32, "tex");
160 nir_builder_instr_insert(&b
, &tex
->instr
);
162 nir_variable
*color_out
= nir_variable_create(b
.shader
, nir_var_shader_out
,
164 color_out
->data
.location
= FRAG_RESULT_DEPTH
;
165 nir_store_var(&b
, color_out
, &tex
->dest
.ssa
, 0x1);
171 build_nir_copy_fragment_shader_stencil(enum glsl_sampler_dim tex_dim
)
173 char shader_name
[64];
174 const struct glsl_type
*vec4
= glsl_vec4_type();
177 nir_builder_init_simple_shader(&b
, NULL
, MESA_SHADER_FRAGMENT
, NULL
);
179 sprintf(shader_name
, "meta_blit_stencil_fs.%d", tex_dim
);
180 b
.shader
->info
->name
= ralloc_strdup(b
.shader
, shader_name
);
182 nir_variable
*tex_pos_in
= nir_variable_create(b
.shader
, nir_var_shader_in
,
184 tex_pos_in
->data
.location
= VARYING_SLOT_VAR0
;
186 /* Swizzle the array index which comes in as Z coordinate into the right
189 unsigned swz
[] = { 0, (tex_dim
== GLSL_SAMPLER_DIM_1D
? 2 : 1), 2 };
190 nir_ssa_def
*const tex_pos
=
191 nir_swizzle(&b
, nir_load_var(&b
, tex_pos_in
), swz
,
192 (tex_dim
== GLSL_SAMPLER_DIM_1D
? 2 : 3), false);
194 const struct glsl_type
*sampler_type
=
195 glsl_sampler_type(tex_dim
, false, tex_dim
!= GLSL_SAMPLER_DIM_3D
,
196 glsl_get_base_type(vec4
));
197 nir_variable
*sampler
= nir_variable_create(b
.shader
, nir_var_uniform
,
198 sampler_type
, "s_tex");
199 sampler
->data
.descriptor_set
= 0;
200 sampler
->data
.binding
= 0;
202 nir_tex_instr
*tex
= nir_tex_instr_create(b
.shader
, 1);
203 tex
->sampler_dim
= tex_dim
;
204 tex
->op
= nir_texop_tex
;
205 tex
->src
[0].src_type
= nir_tex_src_coord
;
206 tex
->src
[0].src
= nir_src_for_ssa(tex_pos
);
207 tex
->dest_type
= nir_type_float
; /* TODO */
208 tex
->is_array
= glsl_sampler_type_is_array(sampler_type
);
209 tex
->coord_components
= tex_pos
->num_components
;
210 tex
->texture
= nir_deref_var_create(tex
, sampler
);
211 tex
->sampler
= nir_deref_var_create(tex
, sampler
);
213 nir_ssa_dest_init(&tex
->instr
, &tex
->dest
, 4, 32, "tex");
214 nir_builder_instr_insert(&b
, &tex
->instr
);
216 nir_variable
*color_out
= nir_variable_create(b
.shader
, nir_var_shader_out
,
218 color_out
->data
.location
= FRAG_RESULT_STENCIL
;
219 nir_store_var(&b
, color_out
, &tex
->dest
.ssa
, 0x1);
225 meta_emit_blit(struct radv_cmd_buffer
*cmd_buffer
,
226 struct radv_image
*src_image
,
227 struct radv_image_view
*src_iview
,
228 VkOffset3D src_offset_0
,
229 VkOffset3D src_offset_1
,
230 struct radv_image
*dest_image
,
231 struct radv_image_view
*dest_iview
,
232 VkOffset3D dest_offset_0
,
233 VkOffset3D dest_offset_1
,
235 VkFilter blit_filter
)
237 struct radv_device
*device
= cmd_buffer
->device
;
239 struct blit_vb_data
{
243 assert(src_image
->info
.samples
== dest_image
->info
.samples
);
244 unsigned vb_size
= 3 * sizeof(*vb_data
);
245 vb_data
[0] = (struct blit_vb_data
) {
247 (float)src_offset_0
.x
/ (float)src_iview
->extent
.width
,
248 (float)src_offset_0
.y
/ (float)src_iview
->extent
.height
,
249 (float)src_offset_0
.z
/ (float)src_iview
->extent
.depth
,
253 vb_data
[1] = (struct blit_vb_data
) {
255 (float)src_offset_0
.x
/ (float)src_iview
->extent
.width
,
256 (float)src_offset_1
.y
/ (float)src_iview
->extent
.height
,
257 (float)src_offset_0
.z
/ (float)src_iview
->extent
.depth
,
261 vb_data
[2] = (struct blit_vb_data
) {
263 (float)src_offset_1
.x
/ (float)src_iview
->extent
.width
,
264 (float)src_offset_0
.y
/ (float)src_iview
->extent
.height
,
265 (float)src_offset_0
.z
/ (float)src_iview
->extent
.depth
,
268 radv_cmd_buffer_upload_data(cmd_buffer
, vb_size
, 16, vb_data
, &offset
);
270 struct radv_buffer vertex_buffer
= {
273 .bo
= cmd_buffer
->upload
.upload_bo
,
277 radv_CmdBindVertexBuffers(radv_cmd_buffer_to_handle(cmd_buffer
), 0, 1,
279 radv_buffer_to_handle(&vertex_buffer
)
286 radv_CreateSampler(radv_device_to_handle(device
),
287 &(VkSamplerCreateInfo
) {
288 .sType
= VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
,
289 .magFilter
= blit_filter
,
290 .minFilter
= blit_filter
,
291 .addressModeU
= VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
,
292 .addressModeV
= VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
,
293 .addressModeW
= VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
,
294 }, &cmd_buffer
->pool
->alloc
, &sampler
);
297 radv_CreateFramebuffer(radv_device_to_handle(device
),
298 &(VkFramebufferCreateInfo
) {
299 .sType
= VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
,
300 .attachmentCount
= 1,
301 .pAttachments
= (VkImageView
[]) {
302 radv_image_view_to_handle(dest_iview
),
304 .width
= dest_iview
->extent
.width
,
305 .height
= dest_iview
->extent
.height
,
307 }, &cmd_buffer
->pool
->alloc
, &fb
);
309 switch (src_iview
->aspect_mask
) {
310 case VK_IMAGE_ASPECT_COLOR_BIT
: {
311 unsigned fs_key
= radv_format_meta_fs_key(dest_image
->vk_format
);
313 radv_CmdBeginRenderPass(radv_cmd_buffer_to_handle(cmd_buffer
),
314 &(VkRenderPassBeginInfo
) {
315 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO
,
316 .renderPass
= device
->meta_state
.blit
.render_pass
[fs_key
],
319 .offset
= { dest_box
.offset
.x
, dest_box
.offset
.y
},
320 .extent
= { dest_box
.extent
.width
, dest_box
.extent
.height
},
322 .clearValueCount
= 0,
323 .pClearValues
= NULL
,
324 }, VK_SUBPASS_CONTENTS_INLINE
);
325 switch (src_image
->type
) {
326 case VK_IMAGE_TYPE_1D
:
327 pipeline
= device
->meta_state
.blit
.pipeline_1d_src
[fs_key
];
329 case VK_IMAGE_TYPE_2D
:
330 pipeline
= device
->meta_state
.blit
.pipeline_2d_src
[fs_key
];
332 case VK_IMAGE_TYPE_3D
:
333 pipeline
= device
->meta_state
.blit
.pipeline_3d_src
[fs_key
];
336 unreachable(!"bad VkImageType");
340 case 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
.blit
.depth_only_rp
,
347 .offset
= { dest_box
.offset
.x
, dest_box
.offset
.y
},
348 .extent
= { dest_box
.extent
.width
, dest_box
.extent
.height
},
350 .clearValueCount
= 0,
351 .pClearValues
= NULL
,
352 }, VK_SUBPASS_CONTENTS_INLINE
);
353 switch (src_image
->type
) {
354 case VK_IMAGE_TYPE_1D
:
355 pipeline
= device
->meta_state
.blit
.depth_only_1d_pipeline
;
357 case VK_IMAGE_TYPE_2D
:
358 pipeline
= device
->meta_state
.blit
.depth_only_2d_pipeline
;
360 case VK_IMAGE_TYPE_3D
:
361 pipeline
= device
->meta_state
.blit
.depth_only_3d_pipeline
;
364 unreachable(!"bad VkImageType");
367 case VK_IMAGE_ASPECT_STENCIL_BIT
:
368 radv_CmdBeginRenderPass(radv_cmd_buffer_to_handle(cmd_buffer
),
369 &(VkRenderPassBeginInfo
) {
370 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO
,
371 .renderPass
= device
->meta_state
.blit
.stencil_only_rp
,
374 .offset
= { dest_box
.offset
.x
, dest_box
.offset
.y
},
375 .extent
= { dest_box
.extent
.width
, dest_box
.extent
.height
},
377 .clearValueCount
= 0,
378 .pClearValues
= NULL
,
379 }, VK_SUBPASS_CONTENTS_INLINE
);
380 switch (src_image
->type
) {
381 case VK_IMAGE_TYPE_1D
:
382 pipeline
= device
->meta_state
.blit
.stencil_only_1d_pipeline
;
384 case VK_IMAGE_TYPE_2D
:
385 pipeline
= device
->meta_state
.blit
.stencil_only_2d_pipeline
;
387 case VK_IMAGE_TYPE_3D
:
388 pipeline
= device
->meta_state
.blit
.stencil_only_3d_pipeline
;
391 unreachable(!"bad VkImageType");
395 unreachable(!"bad VkImageType");
398 if (cmd_buffer
->state
.pipeline
!= radv_pipeline_from_handle(pipeline
)) {
399 radv_CmdBindPipeline(radv_cmd_buffer_to_handle(cmd_buffer
),
400 VK_PIPELINE_BIND_POINT_GRAPHICS
, pipeline
);
403 radv_meta_push_descriptor_set(cmd_buffer
, VK_PIPELINE_BIND_POINT_GRAPHICS
,
404 device
->meta_state
.blit
.pipeline_layout
,
406 1, /* descriptorWriteCount */
407 (VkWriteDescriptorSet
[]) {
409 .sType
= VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET
,
411 .dstArrayElement
= 0,
412 .descriptorCount
= 1,
413 .descriptorType
= VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
,
414 .pImageInfo
= (VkDescriptorImageInfo
[]) {
417 .imageView
= radv_image_view_to_handle(src_iview
),
418 .imageLayout
= VK_IMAGE_LAYOUT_GENERAL
,
424 radv_CmdSetViewport(radv_cmd_buffer_to_handle(cmd_buffer
), 0, 1, &(VkViewport
) {
425 .x
= dest_offset_0
.x
,
426 .y
= dest_offset_0
.y
,
427 .width
= dest_offset_1
.x
- dest_offset_0
.x
,
428 .height
= dest_offset_1
.y
- dest_offset_0
.y
,
433 radv_CmdSetScissor(radv_cmd_buffer_to_handle(cmd_buffer
), 0, 1, &(VkRect2D
) {
434 .offset
= (VkOffset2D
) { MIN2(dest_offset_0
.x
, dest_offset_1
.x
), MIN2(dest_offset_0
.y
, dest_offset_1
.y
) },
435 .extent
= (VkExtent2D
) {
436 abs(dest_offset_1
.x
- dest_offset_0
.x
),
437 abs(dest_offset_1
.y
- dest_offset_0
.y
)
441 radv_CmdDraw(radv_cmd_buffer_to_handle(cmd_buffer
), 3, 1, 0, 0);
443 radv_CmdEndRenderPass(radv_cmd_buffer_to_handle(cmd_buffer
));
445 /* At the point where we emit the draw call, all data from the
446 * descriptor sets, etc. has been used. We are free to delete it.
448 /* TODO: above comment is not valid for at least descriptor sets/pools,
449 * as we may not free them till after execution finishes. Check others. */
451 radv_DestroySampler(radv_device_to_handle(device
), sampler
,
452 &cmd_buffer
->pool
->alloc
);
453 radv_DestroyFramebuffer(radv_device_to_handle(device
), fb
,
454 &cmd_buffer
->pool
->alloc
);
458 flip_coords(unsigned *src0
, unsigned *src1
, unsigned *dst0
, unsigned *dst1
)
462 unsigned tmp
= *src0
;
469 unsigned tmp
= *dst0
;
477 void radv_CmdBlitImage(
478 VkCommandBuffer commandBuffer
,
480 VkImageLayout srcImageLayout
,
482 VkImageLayout destImageLayout
,
483 uint32_t regionCount
,
484 const VkImageBlit
* pRegions
,
488 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
, commandBuffer
);
489 RADV_FROM_HANDLE(radv_image
, src_image
, srcImage
);
490 RADV_FROM_HANDLE(radv_image
, dest_image
, destImage
);
491 struct radv_meta_saved_state saved_state
;
493 /* From the Vulkan 1.0 spec:
495 * vkCmdBlitImage must not be used for multisampled source or
496 * destination images. Use vkCmdResolveImage for this purpose.
498 assert(src_image
->info
.samples
== 1);
499 assert(dest_image
->info
.samples
== 1);
501 radv_meta_save_graphics_reset_vport_scissor(&saved_state
, cmd_buffer
);
503 for (unsigned r
= 0; r
< regionCount
; r
++) {
504 const VkImageSubresourceLayers
*src_res
= &pRegions
[r
].srcSubresource
;
505 const VkImageSubresourceLayers
*dst_res
= &pRegions
[r
].dstSubresource
;
506 struct radv_image_view src_iview
;
507 radv_image_view_init(&src_iview
, cmd_buffer
->device
,
508 &(VkImageViewCreateInfo
) {
509 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
511 .viewType
= radv_meta_get_view_type(src_image
),
512 .format
= src_image
->vk_format
,
513 .subresourceRange
= {
514 .aspectMask
= src_res
->aspectMask
,
515 .baseMipLevel
= src_res
->mipLevel
,
517 .baseArrayLayer
= src_res
->baseArrayLayer
,
521 cmd_buffer
, VK_IMAGE_USAGE_SAMPLED_BIT
);
523 unsigned dst_start
, dst_end
;
524 if (dest_image
->type
== VK_IMAGE_TYPE_3D
) {
525 assert(dst_res
->baseArrayLayer
== 0);
526 dst_start
= pRegions
[r
].dstOffsets
[0].z
;
527 dst_end
= pRegions
[r
].dstOffsets
[1].z
;
529 dst_start
= dst_res
->baseArrayLayer
;
530 dst_end
= dst_start
+ dst_res
->layerCount
;
533 unsigned src_start
, src_end
;
534 if (src_image
->type
== VK_IMAGE_TYPE_3D
) {
535 assert(src_res
->baseArrayLayer
== 0);
536 src_start
= pRegions
[r
].srcOffsets
[0].z
;
537 src_end
= pRegions
[r
].srcOffsets
[1].z
;
539 src_start
= src_res
->baseArrayLayer
;
540 src_end
= src_start
+ src_res
->layerCount
;
543 bool flip_z
= flip_coords(&src_start
, &src_end
, &dst_start
, &dst_end
);
544 float src_z_step
= (float)(src_end
+ 1 - src_start
) /
545 (float)(dst_end
+ 1 - dst_start
);
552 unsigned src_x0
= pRegions
[r
].srcOffsets
[0].x
;
553 unsigned src_x1
= pRegions
[r
].srcOffsets
[1].x
;
554 unsigned dst_x0
= pRegions
[r
].dstOffsets
[0].x
;
555 unsigned dst_x1
= pRegions
[r
].dstOffsets
[1].x
;
557 unsigned src_y0
= pRegions
[r
].srcOffsets
[0].y
;
558 unsigned src_y1
= pRegions
[r
].srcOffsets
[1].y
;
559 unsigned dst_y0
= pRegions
[r
].dstOffsets
[0].y
;
560 unsigned dst_y1
= pRegions
[r
].dstOffsets
[1].y
;
563 dest_box
.offset
.x
= MIN2(dst_x0
, dst_x1
);
564 dest_box
.offset
.y
= MIN2(dst_y0
, dst_y1
);
565 dest_box
.extent
.width
= abs(dst_x1
- dst_x0
);
566 dest_box
.extent
.height
= abs(dst_y1
- dst_y0
);
568 struct radv_image_view dest_iview
;
570 if (dst_res
->aspectMask
== VK_IMAGE_ASPECT_COLOR_BIT
)
571 usage
= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
;
573 usage
= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
;
575 const unsigned num_layers
= dst_end
- dst_start
;
576 for (unsigned i
= 0; i
< num_layers
; i
++) {
577 const VkOffset3D dest_offset_0
= {
582 const VkOffset3D dest_offset_1
= {
587 VkOffset3D src_offset_0
= {
590 .z
= src_start
+ i
* src_z_step
,
592 VkOffset3D src_offset_1
= {
595 .z
= src_start
+ i
* src_z_step
,
597 const uint32_t dest_array_slice
=
598 radv_meta_get_iview_layer(dest_image
, dst_res
,
601 radv_image_view_init(&dest_iview
, cmd_buffer
->device
,
602 &(VkImageViewCreateInfo
) {
603 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
605 .viewType
= radv_meta_get_view_type(dest_image
),
606 .format
= dest_image
->vk_format
,
607 .subresourceRange
= {
608 .aspectMask
= dst_res
->aspectMask
,
609 .baseMipLevel
= dst_res
->mipLevel
,
611 .baseArrayLayer
= dest_array_slice
,
616 meta_emit_blit(cmd_buffer
,
617 src_image
, &src_iview
,
618 src_offset_0
, src_offset_1
,
619 dest_image
, &dest_iview
,
620 dest_offset_0
, dest_offset_1
,
626 radv_meta_restore(&saved_state
, cmd_buffer
);
630 radv_device_finish_meta_blit_state(struct radv_device
*device
)
632 for (unsigned i
= 0; i
< NUM_META_FS_KEYS
; ++i
) {
633 if (device
->meta_state
.blit
.render_pass
[i
])
634 radv_DestroyRenderPass(radv_device_to_handle(device
),
635 device
->meta_state
.blit
.render_pass
[i
],
636 &device
->meta_state
.alloc
);
637 if (device
->meta_state
.blit
.pipeline_1d_src
[i
])
638 radv_DestroyPipeline(radv_device_to_handle(device
),
639 device
->meta_state
.blit
.pipeline_1d_src
[i
],
640 &device
->meta_state
.alloc
);
641 if (device
->meta_state
.blit
.pipeline_2d_src
[i
])
642 radv_DestroyPipeline(radv_device_to_handle(device
),
643 device
->meta_state
.blit
.pipeline_2d_src
[i
],
644 &device
->meta_state
.alloc
);
645 if (device
->meta_state
.blit
.pipeline_3d_src
[i
])
646 radv_DestroyPipeline(radv_device_to_handle(device
),
647 device
->meta_state
.blit
.pipeline_3d_src
[i
],
648 &device
->meta_state
.alloc
);
651 if (device
->meta_state
.blit
.depth_only_rp
)
652 radv_DestroyRenderPass(radv_device_to_handle(device
),
653 device
->meta_state
.blit
.depth_only_rp
,
654 &device
->meta_state
.alloc
);
655 if (device
->meta_state
.blit
.depth_only_1d_pipeline
)
656 radv_DestroyPipeline(radv_device_to_handle(device
),
657 device
->meta_state
.blit
.depth_only_1d_pipeline
,
658 &device
->meta_state
.alloc
);
659 if (device
->meta_state
.blit
.depth_only_2d_pipeline
)
660 radv_DestroyPipeline(radv_device_to_handle(device
),
661 device
->meta_state
.blit
.depth_only_2d_pipeline
,
662 &device
->meta_state
.alloc
);
663 if (device
->meta_state
.blit
.depth_only_3d_pipeline
)
664 radv_DestroyPipeline(radv_device_to_handle(device
),
665 device
->meta_state
.blit
.depth_only_3d_pipeline
,
666 &device
->meta_state
.alloc
);
667 if (device
->meta_state
.blit
.stencil_only_rp
)
668 radv_DestroyRenderPass(radv_device_to_handle(device
),
669 device
->meta_state
.blit
.stencil_only_rp
,
670 &device
->meta_state
.alloc
);
671 if (device
->meta_state
.blit
.stencil_only_1d_pipeline
)
672 radv_DestroyPipeline(radv_device_to_handle(device
),
673 device
->meta_state
.blit
.stencil_only_1d_pipeline
,
674 &device
->meta_state
.alloc
);
675 if (device
->meta_state
.blit
.stencil_only_2d_pipeline
)
676 radv_DestroyPipeline(radv_device_to_handle(device
),
677 device
->meta_state
.blit
.stencil_only_2d_pipeline
,
678 &device
->meta_state
.alloc
);
679 if (device
->meta_state
.blit
.stencil_only_3d_pipeline
)
680 radv_DestroyPipeline(radv_device_to_handle(device
),
681 device
->meta_state
.blit
.stencil_only_3d_pipeline
,
682 &device
->meta_state
.alloc
);
683 if (device
->meta_state
.blit
.pipeline_layout
)
684 radv_DestroyPipelineLayout(radv_device_to_handle(device
),
685 device
->meta_state
.blit
.pipeline_layout
,
686 &device
->meta_state
.alloc
);
687 if (device
->meta_state
.blit
.ds_layout
)
688 radv_DestroyDescriptorSetLayout(radv_device_to_handle(device
),
689 device
->meta_state
.blit
.ds_layout
,
690 &device
->meta_state
.alloc
);
693 static VkFormat pipeline_formats
[] = {
694 VK_FORMAT_R8G8B8A8_UNORM
,
695 VK_FORMAT_R8G8B8A8_UINT
,
696 VK_FORMAT_R8G8B8A8_SINT
,
697 VK_FORMAT_R16G16B16A16_UNORM
,
698 VK_FORMAT_R16G16B16A16_SNORM
,
699 VK_FORMAT_R16G16B16A16_UINT
,
700 VK_FORMAT_R16G16B16A16_SINT
,
701 VK_FORMAT_R32_SFLOAT
,
702 VK_FORMAT_R32G32_SFLOAT
,
703 VK_FORMAT_R32G32B32A32_SFLOAT
707 radv_device_init_meta_blit_color(struct radv_device
*device
,
708 struct radv_shader_module
*vs
)
710 struct radv_shader_module fs_1d
= {0}, fs_2d
= {0}, fs_3d
= {0};
713 fs_1d
.nir
= build_nir_copy_fragment_shader(GLSL_SAMPLER_DIM_1D
);
714 fs_2d
.nir
= build_nir_copy_fragment_shader(GLSL_SAMPLER_DIM_2D
);
715 fs_3d
.nir
= build_nir_copy_fragment_shader(GLSL_SAMPLER_DIM_3D
);
717 for (unsigned i
= 0; i
< ARRAY_SIZE(pipeline_formats
); ++i
) {
718 unsigned key
= radv_format_meta_fs_key(pipeline_formats
[i
]);
719 result
= radv_CreateRenderPass(radv_device_to_handle(device
),
720 &(VkRenderPassCreateInfo
) {
721 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
,
722 .attachmentCount
= 1,
723 .pAttachments
= &(VkAttachmentDescription
) {
724 .format
= pipeline_formats
[i
],
725 .loadOp
= VK_ATTACHMENT_LOAD_OP_LOAD
,
726 .storeOp
= VK_ATTACHMENT_STORE_OP_STORE
,
727 .initialLayout
= VK_IMAGE_LAYOUT_GENERAL
,
728 .finalLayout
= VK_IMAGE_LAYOUT_GENERAL
,
731 .pSubpasses
= &(VkSubpassDescription
) {
732 .pipelineBindPoint
= VK_PIPELINE_BIND_POINT_GRAPHICS
,
733 .inputAttachmentCount
= 0,
734 .colorAttachmentCount
= 1,
735 .pColorAttachments
= &(VkAttachmentReference
) {
737 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
739 .pResolveAttachments
= NULL
,
740 .pDepthStencilAttachment
= &(VkAttachmentReference
) {
741 .attachment
= VK_ATTACHMENT_UNUSED
,
742 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
744 .preserveAttachmentCount
= 1,
745 .pPreserveAttachments
= (uint32_t[]) { 0 },
747 .dependencyCount
= 0,
748 }, &device
->meta_state
.alloc
, &device
->meta_state
.blit
.render_pass
[key
]);
749 if (result
!= VK_SUCCESS
)
752 VkPipelineVertexInputStateCreateInfo vi_create_info
= {
753 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO
,
754 .vertexBindingDescriptionCount
= 1,
755 .pVertexBindingDescriptions
= (VkVertexInputBindingDescription
[]) {
758 .stride
= 3 * sizeof(float),
759 .inputRate
= VK_VERTEX_INPUT_RATE_VERTEX
762 .vertexAttributeDescriptionCount
= 1,
763 .pVertexAttributeDescriptions
= (VkVertexInputAttributeDescription
[]) {
765 /* Texture Coordinate */
768 .format
= VK_FORMAT_R32G32B32_SFLOAT
,
774 VkPipelineShaderStageCreateInfo pipeline_shader_stages
[] = {
776 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
777 .stage
= VK_SHADER_STAGE_VERTEX_BIT
,
778 .module
= radv_shader_module_to_handle(vs
),
780 .pSpecializationInfo
= NULL
782 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
783 .stage
= VK_SHADER_STAGE_FRAGMENT_BIT
,
784 .module
= VK_NULL_HANDLE
, /* TEMPLATE VALUE! FILL ME IN! */
786 .pSpecializationInfo
= NULL
790 const VkGraphicsPipelineCreateInfo vk_pipeline_info
= {
791 .sType
= VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
,
792 .stageCount
= ARRAY_SIZE(pipeline_shader_stages
),
793 .pStages
= pipeline_shader_stages
,
794 .pVertexInputState
= &vi_create_info
,
795 .pInputAssemblyState
= &(VkPipelineInputAssemblyStateCreateInfo
) {
796 .sType
= VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO
,
797 .topology
= VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
,
798 .primitiveRestartEnable
= false,
800 .pViewportState
= &(VkPipelineViewportStateCreateInfo
) {
801 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO
,
805 .pRasterizationState
= &(VkPipelineRasterizationStateCreateInfo
) {
806 .sType
= VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO
,
807 .rasterizerDiscardEnable
= false,
808 .polygonMode
= VK_POLYGON_MODE_FILL
,
809 .cullMode
= VK_CULL_MODE_NONE
,
810 .frontFace
= VK_FRONT_FACE_COUNTER_CLOCKWISE
812 .pMultisampleState
= &(VkPipelineMultisampleStateCreateInfo
) {
813 .sType
= VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO
,
814 .rasterizationSamples
= 1,
815 .sampleShadingEnable
= false,
816 .pSampleMask
= (VkSampleMask
[]) { UINT32_MAX
},
818 .pColorBlendState
= &(VkPipelineColorBlendStateCreateInfo
) {
819 .sType
= VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO
,
820 .attachmentCount
= 1,
821 .pAttachments
= (VkPipelineColorBlendAttachmentState
[]) {
823 VK_COLOR_COMPONENT_A_BIT
|
824 VK_COLOR_COMPONENT_R_BIT
|
825 VK_COLOR_COMPONENT_G_BIT
|
826 VK_COLOR_COMPONENT_B_BIT
},
829 .pDynamicState
= &(VkPipelineDynamicStateCreateInfo
) {
830 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO
,
831 .dynamicStateCount
= 4,
832 .pDynamicStates
= (VkDynamicState
[]) {
833 VK_DYNAMIC_STATE_VIEWPORT
,
834 VK_DYNAMIC_STATE_SCISSOR
,
835 VK_DYNAMIC_STATE_LINE_WIDTH
,
836 VK_DYNAMIC_STATE_BLEND_CONSTANTS
,
840 .layout
= device
->meta_state
.blit
.pipeline_layout
,
841 .renderPass
= device
->meta_state
.blit
.render_pass
[key
],
845 const struct radv_graphics_pipeline_create_info radv_pipeline_info
= {
849 pipeline_shader_stages
[1].module
= radv_shader_module_to_handle(&fs_1d
);
850 result
= radv_graphics_pipeline_create(radv_device_to_handle(device
),
851 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
852 &vk_pipeline_info
, &radv_pipeline_info
,
853 &device
->meta_state
.alloc
, &device
->meta_state
.blit
.pipeline_1d_src
[key
]);
854 if (result
!= VK_SUCCESS
)
857 pipeline_shader_stages
[1].module
= radv_shader_module_to_handle(&fs_2d
);
858 result
= radv_graphics_pipeline_create(radv_device_to_handle(device
),
859 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
860 &vk_pipeline_info
, &radv_pipeline_info
,
861 &device
->meta_state
.alloc
, &device
->meta_state
.blit
.pipeline_2d_src
[key
]);
862 if (result
!= VK_SUCCESS
)
865 pipeline_shader_stages
[1].module
= radv_shader_module_to_handle(&fs_3d
);
866 result
= radv_graphics_pipeline_create(radv_device_to_handle(device
),
867 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
868 &vk_pipeline_info
, &radv_pipeline_info
,
869 &device
->meta_state
.alloc
, &device
->meta_state
.blit
.pipeline_3d_src
[key
]);
870 if (result
!= VK_SUCCESS
)
877 ralloc_free(fs_1d
.nir
);
878 ralloc_free(fs_2d
.nir
);
879 ralloc_free(fs_3d
.nir
);
884 radv_device_init_meta_blit_depth(struct radv_device
*device
,
885 struct radv_shader_module
*vs
)
887 struct radv_shader_module fs_1d
= {0}, fs_2d
= {0}, fs_3d
= {0};
890 fs_1d
.nir
= build_nir_copy_fragment_shader_depth(GLSL_SAMPLER_DIM_1D
);
891 fs_2d
.nir
= build_nir_copy_fragment_shader_depth(GLSL_SAMPLER_DIM_2D
);
892 fs_3d
.nir
= build_nir_copy_fragment_shader_depth(GLSL_SAMPLER_DIM_3D
);
894 result
= radv_CreateRenderPass(radv_device_to_handle(device
),
895 &(VkRenderPassCreateInfo
) {
896 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
,
897 .attachmentCount
= 1,
898 .pAttachments
= &(VkAttachmentDescription
) {
900 .loadOp
= VK_ATTACHMENT_LOAD_OP_LOAD
,
901 .storeOp
= VK_ATTACHMENT_STORE_OP_STORE
,
902 .initialLayout
= VK_IMAGE_LAYOUT_GENERAL
,
903 .finalLayout
= VK_IMAGE_LAYOUT_GENERAL
,
906 .pSubpasses
= &(VkSubpassDescription
) {
907 .pipelineBindPoint
= VK_PIPELINE_BIND_POINT_GRAPHICS
,
908 .inputAttachmentCount
= 0,
909 .colorAttachmentCount
= 0,
910 .pColorAttachments
= NULL
,
911 .pResolveAttachments
= NULL
,
912 .pDepthStencilAttachment
= &(VkAttachmentReference
) {
914 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
916 .preserveAttachmentCount
= 1,
917 .pPreserveAttachments
= (uint32_t[]) { 0 },
919 .dependencyCount
= 0,
920 }, &device
->meta_state
.alloc
, &device
->meta_state
.blit
.depth_only_rp
);
921 if (result
!= VK_SUCCESS
)
924 VkPipelineVertexInputStateCreateInfo vi_create_info
= {
925 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO
,
926 .vertexBindingDescriptionCount
= 1,
927 .pVertexBindingDescriptions
= (VkVertexInputBindingDescription
[]) {
930 .stride
= 3 * sizeof(float),
931 .inputRate
= VK_VERTEX_INPUT_RATE_VERTEX
934 .vertexAttributeDescriptionCount
= 1,
935 .pVertexAttributeDescriptions
= (VkVertexInputAttributeDescription
[]) {
937 /* Texture Coordinate */
940 .format
= VK_FORMAT_R32G32B32_SFLOAT
,
946 VkPipelineShaderStageCreateInfo pipeline_shader_stages
[] = {
948 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
949 .stage
= VK_SHADER_STAGE_VERTEX_BIT
,
950 .module
= radv_shader_module_to_handle(vs
),
952 .pSpecializationInfo
= NULL
954 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
955 .stage
= VK_SHADER_STAGE_FRAGMENT_BIT
,
956 .module
= VK_NULL_HANDLE
, /* TEMPLATE VALUE! FILL ME IN! */
958 .pSpecializationInfo
= NULL
962 const VkGraphicsPipelineCreateInfo vk_pipeline_info
= {
963 .sType
= VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
,
964 .stageCount
= ARRAY_SIZE(pipeline_shader_stages
),
965 .pStages
= pipeline_shader_stages
,
966 .pVertexInputState
= &vi_create_info
,
967 .pInputAssemblyState
= &(VkPipelineInputAssemblyStateCreateInfo
) {
968 .sType
= VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO
,
969 .topology
= VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
,
970 .primitiveRestartEnable
= false,
972 .pViewportState
= &(VkPipelineViewportStateCreateInfo
) {
973 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO
,
977 .pRasterizationState
= &(VkPipelineRasterizationStateCreateInfo
) {
978 .sType
= VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO
,
979 .rasterizerDiscardEnable
= false,
980 .polygonMode
= VK_POLYGON_MODE_FILL
,
981 .cullMode
= VK_CULL_MODE_NONE
,
982 .frontFace
= VK_FRONT_FACE_COUNTER_CLOCKWISE
984 .pMultisampleState
= &(VkPipelineMultisampleStateCreateInfo
) {
985 .sType
= VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO
,
986 .rasterizationSamples
= 1,
987 .sampleShadingEnable
= false,
988 .pSampleMask
= (VkSampleMask
[]) { UINT32_MAX
},
990 .pColorBlendState
= &(VkPipelineColorBlendStateCreateInfo
) {
991 .sType
= VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO
,
992 .attachmentCount
= 0,
993 .pAttachments
= NULL
,
995 .pDepthStencilState
= &(VkPipelineDepthStencilStateCreateInfo
) {
996 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO
,
997 .depthTestEnable
= true,
998 .depthWriteEnable
= true,
999 .depthCompareOp
= VK_COMPARE_OP_ALWAYS
,
1001 .pDynamicState
= &(VkPipelineDynamicStateCreateInfo
) {
1002 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO
,
1003 .dynamicStateCount
= 9,
1004 .pDynamicStates
= (VkDynamicState
[]) {
1005 VK_DYNAMIC_STATE_VIEWPORT
,
1006 VK_DYNAMIC_STATE_SCISSOR
,
1007 VK_DYNAMIC_STATE_LINE_WIDTH
,
1008 VK_DYNAMIC_STATE_DEPTH_BIAS
,
1009 VK_DYNAMIC_STATE_BLEND_CONSTANTS
,
1010 VK_DYNAMIC_STATE_DEPTH_BOUNDS
,
1011 VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK
,
1012 VK_DYNAMIC_STATE_STENCIL_WRITE_MASK
,
1013 VK_DYNAMIC_STATE_STENCIL_REFERENCE
,
1017 .layout
= device
->meta_state
.blit
.pipeline_layout
,
1018 .renderPass
= device
->meta_state
.blit
.depth_only_rp
,
1022 const struct radv_graphics_pipeline_create_info radv_pipeline_info
= {
1023 .use_rectlist
= true
1026 pipeline_shader_stages
[1].module
= radv_shader_module_to_handle(&fs_1d
);
1027 result
= radv_graphics_pipeline_create(radv_device_to_handle(device
),
1028 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
1029 &vk_pipeline_info
, &radv_pipeline_info
,
1030 &device
->meta_state
.alloc
, &device
->meta_state
.blit
.depth_only_1d_pipeline
);
1031 if (result
!= VK_SUCCESS
)
1034 pipeline_shader_stages
[1].module
= radv_shader_module_to_handle(&fs_2d
);
1035 result
= radv_graphics_pipeline_create(radv_device_to_handle(device
),
1036 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
1037 &vk_pipeline_info
, &radv_pipeline_info
,
1038 &device
->meta_state
.alloc
, &device
->meta_state
.blit
.depth_only_2d_pipeline
);
1039 if (result
!= VK_SUCCESS
)
1042 pipeline_shader_stages
[1].module
= radv_shader_module_to_handle(&fs_3d
);
1043 result
= radv_graphics_pipeline_create(radv_device_to_handle(device
),
1044 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
1045 &vk_pipeline_info
, &radv_pipeline_info
,
1046 &device
->meta_state
.alloc
, &device
->meta_state
.blit
.depth_only_3d_pipeline
);
1047 if (result
!= VK_SUCCESS
)
1051 ralloc_free(fs_1d
.nir
);
1052 ralloc_free(fs_2d
.nir
);
1053 ralloc_free(fs_3d
.nir
);
1058 radv_device_init_meta_blit_stencil(struct radv_device
*device
,
1059 struct radv_shader_module
*vs
)
1061 struct radv_shader_module fs_1d
= {0}, fs_2d
= {0}, fs_3d
= {0};
1064 fs_1d
.nir
= build_nir_copy_fragment_shader_stencil(GLSL_SAMPLER_DIM_1D
);
1065 fs_2d
.nir
= build_nir_copy_fragment_shader_stencil(GLSL_SAMPLER_DIM_2D
);
1066 fs_3d
.nir
= build_nir_copy_fragment_shader_stencil(GLSL_SAMPLER_DIM_3D
);
1068 result
= radv_CreateRenderPass(radv_device_to_handle(device
),
1069 &(VkRenderPassCreateInfo
) {
1070 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
,
1071 .attachmentCount
= 1,
1072 .pAttachments
= &(VkAttachmentDescription
) {
1074 .loadOp
= VK_ATTACHMENT_LOAD_OP_LOAD
,
1075 .storeOp
= VK_ATTACHMENT_STORE_OP_STORE
,
1076 .initialLayout
= VK_IMAGE_LAYOUT_GENERAL
,
1077 .finalLayout
= VK_IMAGE_LAYOUT_GENERAL
,
1080 .pSubpasses
= &(VkSubpassDescription
) {
1081 .pipelineBindPoint
= VK_PIPELINE_BIND_POINT_GRAPHICS
,
1082 .inputAttachmentCount
= 0,
1083 .colorAttachmentCount
= 0,
1084 .pColorAttachments
= NULL
,
1085 .pResolveAttachments
= NULL
,
1086 .pDepthStencilAttachment
= &(VkAttachmentReference
) {
1088 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
1090 .preserveAttachmentCount
= 1,
1091 .pPreserveAttachments
= (uint32_t[]) { 0 },
1093 .dependencyCount
= 0,
1094 }, &device
->meta_state
.alloc
, &device
->meta_state
.blit
.stencil_only_rp
);
1095 if (result
!= VK_SUCCESS
)
1098 VkPipelineVertexInputStateCreateInfo vi_create_info
= {
1099 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO
,
1100 .vertexBindingDescriptionCount
= 1,
1101 .pVertexBindingDescriptions
= (VkVertexInputBindingDescription
[]) {
1104 .stride
= 3 * sizeof(float),
1105 .inputRate
= VK_VERTEX_INPUT_RATE_VERTEX
1108 .vertexAttributeDescriptionCount
= 1,
1109 .pVertexAttributeDescriptions
= (VkVertexInputAttributeDescription
[]) {
1111 /* Texture Coordinate */
1114 .format
= VK_FORMAT_R32G32B32_SFLOAT
,
1120 VkPipelineShaderStageCreateInfo pipeline_shader_stages
[] = {
1122 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
1123 .stage
= VK_SHADER_STAGE_VERTEX_BIT
,
1124 .module
= radv_shader_module_to_handle(vs
),
1126 .pSpecializationInfo
= NULL
1128 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
1129 .stage
= VK_SHADER_STAGE_FRAGMENT_BIT
,
1130 .module
= VK_NULL_HANDLE
, /* TEMPLATE VALUE! FILL ME IN! */
1132 .pSpecializationInfo
= NULL
1136 const VkGraphicsPipelineCreateInfo vk_pipeline_info
= {
1137 .sType
= VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
,
1138 .stageCount
= ARRAY_SIZE(pipeline_shader_stages
),
1139 .pStages
= pipeline_shader_stages
,
1140 .pVertexInputState
= &vi_create_info
,
1141 .pInputAssemblyState
= &(VkPipelineInputAssemblyStateCreateInfo
) {
1142 .sType
= VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO
,
1143 .topology
= VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
,
1144 .primitiveRestartEnable
= false,
1146 .pViewportState
= &(VkPipelineViewportStateCreateInfo
) {
1147 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO
,
1151 .pRasterizationState
= &(VkPipelineRasterizationStateCreateInfo
) {
1152 .sType
= VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO
,
1153 .rasterizerDiscardEnable
= false,
1154 .polygonMode
= VK_POLYGON_MODE_FILL
,
1155 .cullMode
= VK_CULL_MODE_NONE
,
1156 .frontFace
= VK_FRONT_FACE_COUNTER_CLOCKWISE
1158 .pMultisampleState
= &(VkPipelineMultisampleStateCreateInfo
) {
1159 .sType
= VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO
,
1160 .rasterizationSamples
= 1,
1161 .sampleShadingEnable
= false,
1162 .pSampleMask
= (VkSampleMask
[]) { UINT32_MAX
},
1164 .pColorBlendState
= &(VkPipelineColorBlendStateCreateInfo
) {
1165 .sType
= VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO
,
1166 .attachmentCount
= 0,
1167 .pAttachments
= NULL
,
1169 .pDepthStencilState
= &(VkPipelineDepthStencilStateCreateInfo
) {
1170 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO
,
1171 .depthTestEnable
= false,
1172 .depthWriteEnable
= false,
1173 .stencilTestEnable
= true,
1175 .failOp
= VK_STENCIL_OP_REPLACE
,
1176 .passOp
= VK_STENCIL_OP_REPLACE
,
1177 .depthFailOp
= VK_STENCIL_OP_REPLACE
,
1178 .compareOp
= VK_COMPARE_OP_ALWAYS
,
1179 .compareMask
= 0xff,
1184 .failOp
= VK_STENCIL_OP_REPLACE
,
1185 .passOp
= VK_STENCIL_OP_REPLACE
,
1186 .depthFailOp
= VK_STENCIL_OP_REPLACE
,
1187 .compareOp
= VK_COMPARE_OP_ALWAYS
,
1188 .compareMask
= 0xff,
1192 .depthCompareOp
= VK_COMPARE_OP_ALWAYS
,
1195 .pDynamicState
= &(VkPipelineDynamicStateCreateInfo
) {
1196 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO
,
1197 .dynamicStateCount
= 6,
1198 .pDynamicStates
= (VkDynamicState
[]) {
1199 VK_DYNAMIC_STATE_VIEWPORT
,
1200 VK_DYNAMIC_STATE_SCISSOR
,
1201 VK_DYNAMIC_STATE_LINE_WIDTH
,
1202 VK_DYNAMIC_STATE_DEPTH_BIAS
,
1203 VK_DYNAMIC_STATE_BLEND_CONSTANTS
,
1204 VK_DYNAMIC_STATE_DEPTH_BOUNDS
,
1208 .layout
= device
->meta_state
.blit
.pipeline_layout
,
1209 .renderPass
= device
->meta_state
.blit
.stencil_only_rp
,
1213 const struct radv_graphics_pipeline_create_info radv_pipeline_info
= {
1214 .use_rectlist
= true
1217 pipeline_shader_stages
[1].module
= radv_shader_module_to_handle(&fs_1d
);
1218 result
= radv_graphics_pipeline_create(radv_device_to_handle(device
),
1219 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
1220 &vk_pipeline_info
, &radv_pipeline_info
,
1221 &device
->meta_state
.alloc
, &device
->meta_state
.blit
.stencil_only_1d_pipeline
);
1222 if (result
!= VK_SUCCESS
)
1225 pipeline_shader_stages
[1].module
= radv_shader_module_to_handle(&fs_2d
);
1226 result
= radv_graphics_pipeline_create(radv_device_to_handle(device
),
1227 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
1228 &vk_pipeline_info
, &radv_pipeline_info
,
1229 &device
->meta_state
.alloc
, &device
->meta_state
.blit
.stencil_only_2d_pipeline
);
1230 if (result
!= VK_SUCCESS
)
1233 pipeline_shader_stages
[1].module
= radv_shader_module_to_handle(&fs_3d
);
1234 result
= radv_graphics_pipeline_create(radv_device_to_handle(device
),
1235 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
1236 &vk_pipeline_info
, &radv_pipeline_info
,
1237 &device
->meta_state
.alloc
, &device
->meta_state
.blit
.stencil_only_3d_pipeline
);
1238 if (result
!= VK_SUCCESS
)
1242 ralloc_free(fs_1d
.nir
);
1243 ralloc_free(fs_2d
.nir
);
1244 ralloc_free(fs_3d
.nir
);
1249 radv_device_init_meta_blit_state(struct radv_device
*device
)
1252 struct radv_shader_module vs
= {0};
1253 zero(device
->meta_state
.blit
);
1255 VkDescriptorSetLayoutCreateInfo ds_layout_info
= {
1256 .sType
= VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
,
1257 .flags
= VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
,
1259 .pBindings
= (VkDescriptorSetLayoutBinding
[]) {
1262 .descriptorType
= VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
,
1263 .descriptorCount
= 1,
1264 .stageFlags
= VK_SHADER_STAGE_FRAGMENT_BIT
,
1265 .pImmutableSamplers
= NULL
1269 result
= radv_CreateDescriptorSetLayout(radv_device_to_handle(device
),
1271 &device
->meta_state
.alloc
,
1272 &device
->meta_state
.blit
.ds_layout
);
1273 if (result
!= VK_SUCCESS
)
1276 result
= radv_CreatePipelineLayout(radv_device_to_handle(device
),
1277 &(VkPipelineLayoutCreateInfo
) {
1278 .sType
= VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
,
1279 .setLayoutCount
= 1,
1280 .pSetLayouts
= &device
->meta_state
.blit
.ds_layout
,
1282 &device
->meta_state
.alloc
, &device
->meta_state
.blit
.pipeline_layout
);
1283 if (result
!= VK_SUCCESS
)
1286 vs
.nir
= build_nir_vertex_shader();
1288 result
= radv_device_init_meta_blit_color(device
, &vs
);
1289 if (result
!= VK_SUCCESS
)
1292 result
= radv_device_init_meta_blit_depth(device
, &vs
);
1293 if (result
!= VK_SUCCESS
)
1296 result
= radv_device_init_meta_blit_stencil(device
, &vs
);
1297 if (result
!= VK_SUCCESS
)
1302 ralloc_free(vs
.nir
);
1303 radv_device_finish_meta_blit_state(device
);