2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * 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 * GFX queue: Compute shader implementation of image->buffer copy
29 * Compute queue: implementation also of buffer->image, image->image, and image clear.
32 /* GFX9 needs to use a 3D sampler to access 3D resources, so the shader has the options
36 build_nir_itob_compute_shader(struct radv_device
*dev
, bool is_3d
)
39 enum glsl_sampler_dim dim
= is_3d
? GLSL_SAMPLER_DIM_3D
: GLSL_SAMPLER_DIM_2D
;
40 const struct glsl_type
*sampler_type
= glsl_sampler_type(dim
,
44 const struct glsl_type
*img_type
= glsl_sampler_type(GLSL_SAMPLER_DIM_BUF
,
48 nir_builder_init_simple_shader(&b
, NULL
, MESA_SHADER_COMPUTE
, NULL
);
49 b
.shader
->info
.name
= ralloc_strdup(b
.shader
, is_3d
? "meta_itob_cs_3d" : "meta_itob_cs");
50 b
.shader
->info
.cs
.local_size
[0] = 16;
51 b
.shader
->info
.cs
.local_size
[1] = 16;
52 b
.shader
->info
.cs
.local_size
[2] = 1;
53 nir_variable
*input_img
= nir_variable_create(b
.shader
, nir_var_uniform
,
54 sampler_type
, "s_tex");
55 input_img
->data
.descriptor_set
= 0;
56 input_img
->data
.binding
= 0;
58 nir_variable
*output_img
= nir_variable_create(b
.shader
, nir_var_uniform
,
60 output_img
->data
.descriptor_set
= 0;
61 output_img
->data
.binding
= 1;
63 nir_ssa_def
*invoc_id
= nir_load_system_value(&b
, nir_intrinsic_load_local_invocation_id
, 0);
64 nir_ssa_def
*wg_id
= nir_load_system_value(&b
, nir_intrinsic_load_work_group_id
, 0);
65 nir_ssa_def
*block_size
= nir_imm_ivec4(&b
,
66 b
.shader
->info
.cs
.local_size
[0],
67 b
.shader
->info
.cs
.local_size
[1],
68 b
.shader
->info
.cs
.local_size
[2], 0);
70 nir_ssa_def
*global_id
= nir_iadd(&b
, nir_imul(&b
, wg_id
, block_size
), invoc_id
);
74 nir_intrinsic_instr
*offset
= nir_intrinsic_instr_create(b
.shader
, nir_intrinsic_load_push_constant
);
75 nir_intrinsic_set_base(offset
, 0);
76 nir_intrinsic_set_range(offset
, 16);
77 offset
->src
[0] = nir_src_for_ssa(nir_imm_int(&b
, 0));
78 offset
->num_components
= is_3d
? 3 : 2;
79 nir_ssa_dest_init(&offset
->instr
, &offset
->dest
, is_3d
? 3 : 2, 32, "offset");
80 nir_builder_instr_insert(&b
, &offset
->instr
);
82 nir_intrinsic_instr
*stride
= nir_intrinsic_instr_create(b
.shader
, nir_intrinsic_load_push_constant
);
83 nir_intrinsic_set_base(stride
, 0);
84 nir_intrinsic_set_range(stride
, 16);
85 stride
->src
[0] = nir_src_for_ssa(nir_imm_int(&b
, 12));
86 stride
->num_components
= 1;
87 nir_ssa_dest_init(&stride
->instr
, &stride
->dest
, 1, 32, "stride");
88 nir_builder_instr_insert(&b
, &stride
->instr
);
90 nir_ssa_def
*img_coord
= nir_iadd(&b
, global_id
, &offset
->dest
.ssa
);
91 nir_tex_instr
*tex
= nir_tex_instr_create(b
.shader
, 2);
92 tex
->sampler_dim
= dim
;
93 tex
->op
= nir_texop_txf
;
94 tex
->src
[0].src_type
= nir_tex_src_coord
;
95 tex
->src
[0].src
= nir_src_for_ssa(nir_channels(&b
, img_coord
, is_3d
? 0x7 : 0x3));
96 tex
->src
[1].src_type
= nir_tex_src_lod
;
97 tex
->src
[1].src
= nir_src_for_ssa(nir_imm_int(&b
, 0));
98 tex
->dest_type
= nir_type_float
;
99 tex
->is_array
= false;
100 tex
->coord_components
= is_3d
? 3 : 2;
101 tex
->texture
= nir_deref_var_create(tex
, input_img
);
104 nir_ssa_dest_init(&tex
->instr
, &tex
->dest
, 4, 32, "tex");
105 nir_builder_instr_insert(&b
, &tex
->instr
);
107 nir_ssa_def
*pos_x
= nir_channel(&b
, global_id
, 0);
108 nir_ssa_def
*pos_y
= nir_channel(&b
, global_id
, 1);
110 nir_ssa_def
*tmp
= nir_imul(&b
, pos_y
, &stride
->dest
.ssa
);
111 tmp
= nir_iadd(&b
, tmp
, pos_x
);
113 nir_ssa_def
*coord
= nir_vec4(&b
, tmp
, tmp
, tmp
, tmp
);
115 nir_ssa_def
*outval
= &tex
->dest
.ssa
;
116 nir_intrinsic_instr
*store
= nir_intrinsic_instr_create(b
.shader
, nir_intrinsic_image_store
);
117 store
->src
[0] = nir_src_for_ssa(coord
);
118 store
->src
[1] = nir_src_for_ssa(nir_ssa_undef(&b
, 1, 32));
119 store
->src
[2] = nir_src_for_ssa(outval
);
120 store
->variables
[0] = nir_deref_var_create(store
, output_img
);
122 nir_builder_instr_insert(&b
, &store
->instr
);
126 /* Image to buffer - don't write use image accessors */
128 radv_device_init_meta_itob_state(struct radv_device
*device
)
131 struct radv_shader_module cs
= { .nir
= NULL
};
132 struct radv_shader_module cs_3d
= { .nir
= NULL
};
134 cs
.nir
= build_nir_itob_compute_shader(device
, false);
135 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
)
136 cs_3d
.nir
= build_nir_itob_compute_shader(device
, true);
139 * two descriptors one for the image being sampled
140 * one for the buffer being written.
142 VkDescriptorSetLayoutCreateInfo ds_create_info
= {
143 .sType
= VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
,
144 .flags
= VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
,
146 .pBindings
= (VkDescriptorSetLayoutBinding
[]) {
149 .descriptorType
= VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
,
150 .descriptorCount
= 1,
151 .stageFlags
= VK_SHADER_STAGE_COMPUTE_BIT
,
152 .pImmutableSamplers
= NULL
156 .descriptorType
= VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
,
157 .descriptorCount
= 1,
158 .stageFlags
= VK_SHADER_STAGE_COMPUTE_BIT
,
159 .pImmutableSamplers
= NULL
164 result
= radv_CreateDescriptorSetLayout(radv_device_to_handle(device
),
166 &device
->meta_state
.alloc
,
167 &device
->meta_state
.itob
.img_ds_layout
);
168 if (result
!= VK_SUCCESS
)
172 VkPipelineLayoutCreateInfo pl_create_info
= {
173 .sType
= VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
,
175 .pSetLayouts
= &device
->meta_state
.itob
.img_ds_layout
,
176 .pushConstantRangeCount
= 1,
177 .pPushConstantRanges
= &(VkPushConstantRange
){VK_SHADER_STAGE_COMPUTE_BIT
, 0, 16},
180 result
= radv_CreatePipelineLayout(radv_device_to_handle(device
),
182 &device
->meta_state
.alloc
,
183 &device
->meta_state
.itob
.img_p_layout
);
184 if (result
!= VK_SUCCESS
)
189 VkPipelineShaderStageCreateInfo pipeline_shader_stage
= {
190 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
191 .stage
= VK_SHADER_STAGE_COMPUTE_BIT
,
192 .module
= radv_shader_module_to_handle(&cs
),
194 .pSpecializationInfo
= NULL
,
197 VkComputePipelineCreateInfo vk_pipeline_info
= {
198 .sType
= VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO
,
199 .stage
= pipeline_shader_stage
,
201 .layout
= device
->meta_state
.itob
.img_p_layout
,
204 result
= radv_CreateComputePipelines(radv_device_to_handle(device
),
205 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
206 1, &vk_pipeline_info
, NULL
,
207 &device
->meta_state
.itob
.pipeline
);
208 if (result
!= VK_SUCCESS
)
211 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
212 VkPipelineShaderStageCreateInfo pipeline_shader_stage_3d
= {
213 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
214 .stage
= VK_SHADER_STAGE_COMPUTE_BIT
,
215 .module
= radv_shader_module_to_handle(&cs_3d
),
217 .pSpecializationInfo
= NULL
,
220 VkComputePipelineCreateInfo vk_pipeline_info_3d
= {
221 .sType
= VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO
,
222 .stage
= pipeline_shader_stage_3d
,
224 .layout
= device
->meta_state
.itob
.img_p_layout
,
227 result
= radv_CreateComputePipelines(radv_device_to_handle(device
),
228 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
229 1, &vk_pipeline_info_3d
, NULL
,
230 &device
->meta_state
.itob
.pipeline_3d
);
231 if (result
!= VK_SUCCESS
)
233 ralloc_free(cs_3d
.nir
);
240 ralloc_free(cs_3d
.nir
);
245 radv_device_finish_meta_itob_state(struct radv_device
*device
)
247 struct radv_meta_state
*state
= &device
->meta_state
;
249 radv_DestroyPipelineLayout(radv_device_to_handle(device
),
250 state
->itob
.img_p_layout
, &state
->alloc
);
251 radv_DestroyDescriptorSetLayout(radv_device_to_handle(device
),
252 state
->itob
.img_ds_layout
,
254 radv_DestroyPipeline(radv_device_to_handle(device
),
255 state
->itob
.pipeline
, &state
->alloc
);
256 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
)
257 radv_DestroyPipeline(radv_device_to_handle(device
),
258 state
->itob
.pipeline_3d
, &state
->alloc
);
262 build_nir_btoi_compute_shader(struct radv_device
*dev
)
265 const struct glsl_type
*buf_type
= glsl_sampler_type(GLSL_SAMPLER_DIM_BUF
,
269 const struct glsl_type
*img_type
= glsl_sampler_type(GLSL_SAMPLER_DIM_2D
,
273 nir_builder_init_simple_shader(&b
, NULL
, MESA_SHADER_COMPUTE
, NULL
);
274 b
.shader
->info
.name
= ralloc_strdup(b
.shader
, "meta_btoi_cs");
275 b
.shader
->info
.cs
.local_size
[0] = 16;
276 b
.shader
->info
.cs
.local_size
[1] = 16;
277 b
.shader
->info
.cs
.local_size
[2] = 1;
278 nir_variable
*input_img
= nir_variable_create(b
.shader
, nir_var_uniform
,
280 input_img
->data
.descriptor_set
= 0;
281 input_img
->data
.binding
= 0;
283 nir_variable
*output_img
= nir_variable_create(b
.shader
, nir_var_uniform
,
284 img_type
, "out_img");
285 output_img
->data
.descriptor_set
= 0;
286 output_img
->data
.binding
= 1;
288 nir_ssa_def
*invoc_id
= nir_load_system_value(&b
, nir_intrinsic_load_local_invocation_id
, 0);
289 nir_ssa_def
*wg_id
= nir_load_system_value(&b
, nir_intrinsic_load_work_group_id
, 0);
290 nir_ssa_def
*block_size
= nir_imm_ivec4(&b
,
291 b
.shader
->info
.cs
.local_size
[0],
292 b
.shader
->info
.cs
.local_size
[1],
293 b
.shader
->info
.cs
.local_size
[2], 0);
295 nir_ssa_def
*global_id
= nir_iadd(&b
, nir_imul(&b
, wg_id
, block_size
), invoc_id
);
297 nir_intrinsic_instr
*offset
= nir_intrinsic_instr_create(b
.shader
, nir_intrinsic_load_push_constant
);
298 nir_intrinsic_set_base(offset
, 0);
299 nir_intrinsic_set_range(offset
, 12);
300 offset
->src
[0] = nir_src_for_ssa(nir_imm_int(&b
, 0));
301 offset
->num_components
= 2;
302 nir_ssa_dest_init(&offset
->instr
, &offset
->dest
, 2, 32, "offset");
303 nir_builder_instr_insert(&b
, &offset
->instr
);
305 nir_intrinsic_instr
*stride
= nir_intrinsic_instr_create(b
.shader
, nir_intrinsic_load_push_constant
);
306 nir_intrinsic_set_base(stride
, 0);
307 nir_intrinsic_set_range(stride
, 12);
308 stride
->src
[0] = nir_src_for_ssa(nir_imm_int(&b
, 8));
309 stride
->num_components
= 1;
310 nir_ssa_dest_init(&stride
->instr
, &stride
->dest
, 1, 32, "stride");
311 nir_builder_instr_insert(&b
, &stride
->instr
);
313 nir_ssa_def
*pos_x
= nir_channel(&b
, global_id
, 0);
314 nir_ssa_def
*pos_y
= nir_channel(&b
, global_id
, 1);
316 nir_ssa_def
*tmp
= nir_imul(&b
, pos_y
, &stride
->dest
.ssa
);
317 tmp
= nir_iadd(&b
, tmp
, pos_x
);
319 nir_ssa_def
*buf_coord
= nir_vec4(&b
, tmp
, tmp
, tmp
, tmp
);
321 nir_ssa_def
*img_coord
= nir_iadd(&b
, global_id
, &offset
->dest
.ssa
);
323 nir_tex_instr
*tex
= nir_tex_instr_create(b
.shader
, 2);
324 tex
->sampler_dim
= GLSL_SAMPLER_DIM_BUF
;
325 tex
->op
= nir_texop_txf
;
326 tex
->src
[0].src_type
= nir_tex_src_coord
;
327 tex
->src
[0].src
= nir_src_for_ssa(nir_channels(&b
, buf_coord
, 1));
328 tex
->src
[1].src_type
= nir_tex_src_lod
;
329 tex
->src
[1].src
= nir_src_for_ssa(nir_imm_int(&b
, 0));
330 tex
->dest_type
= nir_type_float
;
331 tex
->is_array
= false;
332 tex
->coord_components
= 1;
333 tex
->texture
= nir_deref_var_create(tex
, input_img
);
336 nir_ssa_dest_init(&tex
->instr
, &tex
->dest
, 4, 32, "tex");
337 nir_builder_instr_insert(&b
, &tex
->instr
);
339 nir_ssa_def
*outval
= &tex
->dest
.ssa
;
340 nir_intrinsic_instr
*store
= nir_intrinsic_instr_create(b
.shader
, nir_intrinsic_image_store
);
341 store
->src
[0] = nir_src_for_ssa(img_coord
);
342 store
->src
[1] = nir_src_for_ssa(nir_ssa_undef(&b
, 1, 32));
343 store
->src
[2] = nir_src_for_ssa(outval
);
344 store
->variables
[0] = nir_deref_var_create(store
, output_img
);
346 nir_builder_instr_insert(&b
, &store
->instr
);
350 /* Buffer to image - don't write use image accessors */
352 radv_device_init_meta_btoi_state(struct radv_device
*device
)
355 struct radv_shader_module cs
= { .nir
= NULL
};
357 cs
.nir
= build_nir_btoi_compute_shader(device
);
360 * two descriptors one for the image being sampled
361 * one for the buffer being written.
363 VkDescriptorSetLayoutCreateInfo ds_create_info
= {
364 .sType
= VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
,
365 .flags
= VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
,
367 .pBindings
= (VkDescriptorSetLayoutBinding
[]) {
370 .descriptorType
= VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
,
371 .descriptorCount
= 1,
372 .stageFlags
= VK_SHADER_STAGE_COMPUTE_BIT
,
373 .pImmutableSamplers
= NULL
377 .descriptorType
= VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
,
378 .descriptorCount
= 1,
379 .stageFlags
= VK_SHADER_STAGE_COMPUTE_BIT
,
380 .pImmutableSamplers
= NULL
385 result
= radv_CreateDescriptorSetLayout(radv_device_to_handle(device
),
387 &device
->meta_state
.alloc
,
388 &device
->meta_state
.btoi
.img_ds_layout
);
389 if (result
!= VK_SUCCESS
)
393 VkPipelineLayoutCreateInfo pl_create_info
= {
394 .sType
= VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
,
396 .pSetLayouts
= &device
->meta_state
.btoi
.img_ds_layout
,
397 .pushConstantRangeCount
= 1,
398 .pPushConstantRanges
= &(VkPushConstantRange
){VK_SHADER_STAGE_COMPUTE_BIT
, 0, 12},
401 result
= radv_CreatePipelineLayout(radv_device_to_handle(device
),
403 &device
->meta_state
.alloc
,
404 &device
->meta_state
.btoi
.img_p_layout
);
405 if (result
!= VK_SUCCESS
)
410 VkPipelineShaderStageCreateInfo pipeline_shader_stage
= {
411 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
412 .stage
= VK_SHADER_STAGE_COMPUTE_BIT
,
413 .module
= radv_shader_module_to_handle(&cs
),
415 .pSpecializationInfo
= NULL
,
418 VkComputePipelineCreateInfo vk_pipeline_info
= {
419 .sType
= VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO
,
420 .stage
= pipeline_shader_stage
,
422 .layout
= device
->meta_state
.btoi
.img_p_layout
,
425 result
= radv_CreateComputePipelines(radv_device_to_handle(device
),
426 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
427 1, &vk_pipeline_info
, NULL
,
428 &device
->meta_state
.btoi
.pipeline
);
429 if (result
!= VK_SUCCESS
)
440 radv_device_finish_meta_btoi_state(struct radv_device
*device
)
442 struct radv_meta_state
*state
= &device
->meta_state
;
444 radv_DestroyPipelineLayout(radv_device_to_handle(device
),
445 state
->btoi
.img_p_layout
, &state
->alloc
);
446 radv_DestroyDescriptorSetLayout(radv_device_to_handle(device
),
447 state
->btoi
.img_ds_layout
,
449 radv_DestroyPipeline(radv_device_to_handle(device
),
450 state
->btoi
.pipeline
, &state
->alloc
);
454 build_nir_itoi_compute_shader(struct radv_device
*dev
, bool is_3d
)
457 enum glsl_sampler_dim dim
= is_3d
? GLSL_SAMPLER_DIM_3D
: GLSL_SAMPLER_DIM_2D
;
458 const struct glsl_type
*buf_type
= glsl_sampler_type(dim
,
462 const struct glsl_type
*img_type
= glsl_sampler_type(dim
,
466 nir_builder_init_simple_shader(&b
, NULL
, MESA_SHADER_COMPUTE
, NULL
);
467 b
.shader
->info
.name
= ralloc_strdup(b
.shader
, is_3d
? "meta_itoi_cs_3d" : "meta_itoi_cs");
468 b
.shader
->info
.cs
.local_size
[0] = 16;
469 b
.shader
->info
.cs
.local_size
[1] = 16;
470 b
.shader
->info
.cs
.local_size
[2] = 1;
471 nir_variable
*input_img
= nir_variable_create(b
.shader
, nir_var_uniform
,
473 input_img
->data
.descriptor_set
= 0;
474 input_img
->data
.binding
= 0;
476 nir_variable
*output_img
= nir_variable_create(b
.shader
, nir_var_uniform
,
477 img_type
, "out_img");
478 output_img
->data
.descriptor_set
= 0;
479 output_img
->data
.binding
= 1;
481 nir_ssa_def
*invoc_id
= nir_load_system_value(&b
, nir_intrinsic_load_local_invocation_id
, 0);
482 nir_ssa_def
*wg_id
= nir_load_system_value(&b
, nir_intrinsic_load_work_group_id
, 0);
483 nir_ssa_def
*block_size
= nir_imm_ivec4(&b
,
484 b
.shader
->info
.cs
.local_size
[0],
485 b
.shader
->info
.cs
.local_size
[1],
486 b
.shader
->info
.cs
.local_size
[2], 0);
488 nir_ssa_def
*global_id
= nir_iadd(&b
, nir_imul(&b
, wg_id
, block_size
), invoc_id
);
490 nir_intrinsic_instr
*src_offset
= nir_intrinsic_instr_create(b
.shader
, nir_intrinsic_load_push_constant
);
491 nir_intrinsic_set_base(src_offset
, 0);
492 nir_intrinsic_set_range(src_offset
, 24);
493 src_offset
->src
[0] = nir_src_for_ssa(nir_imm_int(&b
, 0));
494 src_offset
->num_components
= is_3d
? 3 : 2;
495 nir_ssa_dest_init(&src_offset
->instr
, &src_offset
->dest
, is_3d
? 3 : 2, 32, "src_offset");
496 nir_builder_instr_insert(&b
, &src_offset
->instr
);
498 nir_intrinsic_instr
*dst_offset
= nir_intrinsic_instr_create(b
.shader
, nir_intrinsic_load_push_constant
);
499 nir_intrinsic_set_base(dst_offset
, 0);
500 nir_intrinsic_set_range(dst_offset
, 24);
501 dst_offset
->src
[0] = nir_src_for_ssa(nir_imm_int(&b
, 12));
502 dst_offset
->num_components
= is_3d
? 3 : 2;
503 nir_ssa_dest_init(&dst_offset
->instr
, &dst_offset
->dest
, is_3d
? 3 : 2, 32, "dst_offset");
504 nir_builder_instr_insert(&b
, &dst_offset
->instr
);
506 nir_ssa_def
*src_coord
= nir_iadd(&b
, global_id
, &src_offset
->dest
.ssa
);
508 nir_ssa_def
*dst_coord
= nir_iadd(&b
, global_id
, &dst_offset
->dest
.ssa
);
510 nir_tex_instr
*tex
= nir_tex_instr_create(b
.shader
, 2);
511 tex
->sampler_dim
= dim
;
512 tex
->op
= nir_texop_txf
;
513 tex
->src
[0].src_type
= nir_tex_src_coord
;
514 tex
->src
[0].src
= nir_src_for_ssa(nir_channels(&b
, src_coord
, is_3d
? 0x7 : 0x3));
515 tex
->src
[1].src_type
= nir_tex_src_lod
;
516 tex
->src
[1].src
= nir_src_for_ssa(nir_imm_int(&b
, 0));
517 tex
->dest_type
= nir_type_float
;
518 tex
->is_array
= false;
519 tex
->coord_components
= is_3d
? 3 : 2;
520 tex
->texture
= nir_deref_var_create(tex
, input_img
);
523 nir_ssa_dest_init(&tex
->instr
, &tex
->dest
, 4, 32, "tex");
524 nir_builder_instr_insert(&b
, &tex
->instr
);
526 nir_ssa_def
*outval
= &tex
->dest
.ssa
;
527 nir_intrinsic_instr
*store
= nir_intrinsic_instr_create(b
.shader
, nir_intrinsic_image_store
);
528 store
->src
[0] = nir_src_for_ssa(dst_coord
);
529 store
->src
[1] = nir_src_for_ssa(nir_ssa_undef(&b
, 1, 32));
530 store
->src
[2] = nir_src_for_ssa(outval
);
531 store
->variables
[0] = nir_deref_var_create(store
, output_img
);
533 nir_builder_instr_insert(&b
, &store
->instr
);
537 /* image to image - don't write use image accessors */
539 radv_device_init_meta_itoi_state(struct radv_device
*device
)
542 struct radv_shader_module cs
= { .nir
= NULL
};
543 struct radv_shader_module cs_3d
= { .nir
= NULL
};
544 cs
.nir
= build_nir_itoi_compute_shader(device
, false);
545 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
)
546 cs_3d
.nir
= build_nir_itoi_compute_shader(device
, true);
548 * two descriptors one for the image being sampled
549 * one for the buffer being written.
551 VkDescriptorSetLayoutCreateInfo ds_create_info
= {
552 .sType
= VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
,
553 .flags
= VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
,
555 .pBindings
= (VkDescriptorSetLayoutBinding
[]) {
558 .descriptorType
= VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
,
559 .descriptorCount
= 1,
560 .stageFlags
= VK_SHADER_STAGE_COMPUTE_BIT
,
561 .pImmutableSamplers
= NULL
565 .descriptorType
= VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
,
566 .descriptorCount
= 1,
567 .stageFlags
= VK_SHADER_STAGE_COMPUTE_BIT
,
568 .pImmutableSamplers
= NULL
573 result
= radv_CreateDescriptorSetLayout(radv_device_to_handle(device
),
575 &device
->meta_state
.alloc
,
576 &device
->meta_state
.itoi
.img_ds_layout
);
577 if (result
!= VK_SUCCESS
)
581 VkPipelineLayoutCreateInfo pl_create_info
= {
582 .sType
= VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
,
584 .pSetLayouts
= &device
->meta_state
.itoi
.img_ds_layout
,
585 .pushConstantRangeCount
= 1,
586 .pPushConstantRanges
= &(VkPushConstantRange
){VK_SHADER_STAGE_COMPUTE_BIT
, 0, 24},
589 result
= radv_CreatePipelineLayout(radv_device_to_handle(device
),
591 &device
->meta_state
.alloc
,
592 &device
->meta_state
.itoi
.img_p_layout
);
593 if (result
!= VK_SUCCESS
)
598 VkPipelineShaderStageCreateInfo pipeline_shader_stage
= {
599 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
600 .stage
= VK_SHADER_STAGE_COMPUTE_BIT
,
601 .module
= radv_shader_module_to_handle(&cs
),
603 .pSpecializationInfo
= NULL
,
606 VkComputePipelineCreateInfo vk_pipeline_info
= {
607 .sType
= VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO
,
608 .stage
= pipeline_shader_stage
,
610 .layout
= device
->meta_state
.itoi
.img_p_layout
,
613 result
= radv_CreateComputePipelines(radv_device_to_handle(device
),
614 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
615 1, &vk_pipeline_info
, NULL
,
616 &device
->meta_state
.itoi
.pipeline
);
617 if (result
!= VK_SUCCESS
)
620 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
621 VkPipelineShaderStageCreateInfo pipeline_shader_stage_3d
= {
622 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
623 .stage
= VK_SHADER_STAGE_COMPUTE_BIT
,
624 .module
= radv_shader_module_to_handle(&cs_3d
),
626 .pSpecializationInfo
= NULL
,
629 VkComputePipelineCreateInfo vk_pipeline_info_3d
= {
630 .sType
= VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO
,
631 .stage
= pipeline_shader_stage_3d
,
633 .layout
= device
->meta_state
.itoi
.img_p_layout
,
636 result
= radv_CreateComputePipelines(radv_device_to_handle(device
),
637 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
638 1, &vk_pipeline_info_3d
, NULL
,
639 &device
->meta_state
.itoi
.pipeline_3d
);
641 ralloc_free(cs_3d
.nir
);
648 ralloc_free(cs_3d
.nir
);
653 radv_device_finish_meta_itoi_state(struct radv_device
*device
)
655 struct radv_meta_state
*state
= &device
->meta_state
;
657 radv_DestroyPipelineLayout(radv_device_to_handle(device
),
658 state
->itoi
.img_p_layout
, &state
->alloc
);
659 radv_DestroyDescriptorSetLayout(radv_device_to_handle(device
),
660 state
->itoi
.img_ds_layout
,
662 radv_DestroyPipeline(radv_device_to_handle(device
),
663 state
->itoi
.pipeline
, &state
->alloc
);
664 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
)
665 radv_DestroyPipeline(radv_device_to_handle(device
),
666 state
->itoi
.pipeline_3d
, &state
->alloc
);
670 build_nir_cleari_compute_shader(struct radv_device
*dev
, bool is_3d
)
673 enum glsl_sampler_dim dim
= is_3d
? GLSL_SAMPLER_DIM_3D
: GLSL_SAMPLER_DIM_2D
;
674 const struct glsl_type
*img_type
= glsl_sampler_type(dim
,
678 nir_builder_init_simple_shader(&b
, NULL
, MESA_SHADER_COMPUTE
, NULL
);
679 b
.shader
->info
.name
= ralloc_strdup(b
.shader
, is_3d
? "meta_cleari_cs_3d" : "meta_cleari_cs");
680 b
.shader
->info
.cs
.local_size
[0] = 16;
681 b
.shader
->info
.cs
.local_size
[1] = 16;
682 b
.shader
->info
.cs
.local_size
[2] = 1;
684 nir_variable
*output_img
= nir_variable_create(b
.shader
, nir_var_uniform
,
685 img_type
, "out_img");
686 output_img
->data
.descriptor_set
= 0;
687 output_img
->data
.binding
= 0;
689 nir_ssa_def
*invoc_id
= nir_load_system_value(&b
, nir_intrinsic_load_local_invocation_id
, 0);
690 nir_ssa_def
*wg_id
= nir_load_system_value(&b
, nir_intrinsic_load_work_group_id
, 0);
691 nir_ssa_def
*block_size
= nir_imm_ivec4(&b
,
692 b
.shader
->info
.cs
.local_size
[0],
693 b
.shader
->info
.cs
.local_size
[1],
694 b
.shader
->info
.cs
.local_size
[2], 0);
696 nir_ssa_def
*global_id
= nir_iadd(&b
, nir_imul(&b
, wg_id
, block_size
), invoc_id
);
698 nir_intrinsic_instr
*clear_val
= nir_intrinsic_instr_create(b
.shader
, nir_intrinsic_load_push_constant
);
699 nir_intrinsic_set_base(clear_val
, 0);
700 nir_intrinsic_set_range(clear_val
, 20);
701 clear_val
->src
[0] = nir_src_for_ssa(nir_imm_int(&b
, 0));
702 clear_val
->num_components
= 4;
703 nir_ssa_dest_init(&clear_val
->instr
, &clear_val
->dest
, 4, 32, "clear_value");
704 nir_builder_instr_insert(&b
, &clear_val
->instr
);
706 nir_intrinsic_instr
*layer
= nir_intrinsic_instr_create(b
.shader
, nir_intrinsic_load_push_constant
);
707 nir_intrinsic_set_base(layer
, 0);
708 nir_intrinsic_set_range(layer
, 20);
709 layer
->src
[0] = nir_src_for_ssa(nir_imm_int(&b
, 16));
710 layer
->num_components
= 1;
711 nir_ssa_dest_init(&layer
->instr
, &layer
->dest
, 1, 32, "layer");
712 nir_builder_instr_insert(&b
, &layer
->instr
);
714 nir_ssa_def
*global_z
= nir_iadd(&b
, nir_channel(&b
, global_id
, 2), &layer
->dest
.ssa
);
716 nir_ssa_def
*comps
[4];
717 comps
[0] = nir_channel(&b
, global_id
, 0);
718 comps
[1] = nir_channel(&b
, global_id
, 1);
720 comps
[3] = nir_imm_int(&b
, 0);
721 global_id
= nir_vec(&b
, comps
, 4);
723 nir_intrinsic_instr
*store
= nir_intrinsic_instr_create(b
.shader
, nir_intrinsic_image_store
);
724 store
->src
[0] = nir_src_for_ssa(global_id
);
725 store
->src
[1] = nir_src_for_ssa(nir_ssa_undef(&b
, 1, 32));
726 store
->src
[2] = nir_src_for_ssa(&clear_val
->dest
.ssa
);
727 store
->variables
[0] = nir_deref_var_create(store
, output_img
);
729 nir_builder_instr_insert(&b
, &store
->instr
);
734 radv_device_init_meta_cleari_state(struct radv_device
*device
)
737 struct radv_shader_module cs
= { .nir
= NULL
};
738 struct radv_shader_module cs_3d
= { .nir
= NULL
};
739 cs
.nir
= build_nir_cleari_compute_shader(device
, false);
740 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
)
741 cs_3d
.nir
= build_nir_cleari_compute_shader(device
, true);
744 * two descriptors one for the image being sampled
745 * one for the buffer being written.
747 VkDescriptorSetLayoutCreateInfo ds_create_info
= {
748 .sType
= VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
,
749 .flags
= VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
,
751 .pBindings
= (VkDescriptorSetLayoutBinding
[]) {
754 .descriptorType
= VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
,
755 .descriptorCount
= 1,
756 .stageFlags
= VK_SHADER_STAGE_COMPUTE_BIT
,
757 .pImmutableSamplers
= NULL
762 result
= radv_CreateDescriptorSetLayout(radv_device_to_handle(device
),
764 &device
->meta_state
.alloc
,
765 &device
->meta_state
.cleari
.img_ds_layout
);
766 if (result
!= VK_SUCCESS
)
770 VkPipelineLayoutCreateInfo pl_create_info
= {
771 .sType
= VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
,
773 .pSetLayouts
= &device
->meta_state
.cleari
.img_ds_layout
,
774 .pushConstantRangeCount
= 1,
775 .pPushConstantRanges
= &(VkPushConstantRange
){VK_SHADER_STAGE_COMPUTE_BIT
, 0, 20},
778 result
= radv_CreatePipelineLayout(radv_device_to_handle(device
),
780 &device
->meta_state
.alloc
,
781 &device
->meta_state
.cleari
.img_p_layout
);
782 if (result
!= VK_SUCCESS
)
787 VkPipelineShaderStageCreateInfo pipeline_shader_stage
= {
788 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
789 .stage
= VK_SHADER_STAGE_COMPUTE_BIT
,
790 .module
= radv_shader_module_to_handle(&cs
),
792 .pSpecializationInfo
= NULL
,
795 VkComputePipelineCreateInfo vk_pipeline_info
= {
796 .sType
= VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO
,
797 .stage
= pipeline_shader_stage
,
799 .layout
= device
->meta_state
.cleari
.img_p_layout
,
802 result
= radv_CreateComputePipelines(radv_device_to_handle(device
),
803 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
804 1, &vk_pipeline_info
, NULL
,
805 &device
->meta_state
.cleari
.pipeline
);
806 if (result
!= VK_SUCCESS
)
810 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
812 VkPipelineShaderStageCreateInfo pipeline_shader_stage_3d
= {
813 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
814 .stage
= VK_SHADER_STAGE_COMPUTE_BIT
,
815 .module
= radv_shader_module_to_handle(&cs_3d
),
817 .pSpecializationInfo
= NULL
,
820 VkComputePipelineCreateInfo vk_pipeline_info_3d
= {
821 .sType
= VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO
,
822 .stage
= pipeline_shader_stage_3d
,
824 .layout
= device
->meta_state
.cleari
.img_p_layout
,
827 result
= radv_CreateComputePipelines(radv_device_to_handle(device
),
828 radv_pipeline_cache_to_handle(&device
->meta_state
.cache
),
829 1, &vk_pipeline_info_3d
, NULL
,
830 &device
->meta_state
.cleari
.pipeline_3d
);
831 if (result
!= VK_SUCCESS
)
834 ralloc_free(cs_3d
.nir
);
840 ralloc_free(cs_3d
.nir
);
845 radv_device_finish_meta_cleari_state(struct radv_device
*device
)
847 struct radv_meta_state
*state
= &device
->meta_state
;
849 radv_DestroyPipelineLayout(radv_device_to_handle(device
),
850 state
->cleari
.img_p_layout
, &state
->alloc
);
851 radv_DestroyDescriptorSetLayout(radv_device_to_handle(device
),
852 state
->cleari
.img_ds_layout
,
854 radv_DestroyPipeline(radv_device_to_handle(device
),
855 state
->cleari
.pipeline
, &state
->alloc
);
856 radv_DestroyPipeline(radv_device_to_handle(device
),
857 state
->cleari
.pipeline_3d
, &state
->alloc
);
861 radv_device_finish_meta_bufimage_state(struct radv_device
*device
)
863 radv_device_finish_meta_itob_state(device
);
864 radv_device_finish_meta_btoi_state(device
);
865 radv_device_finish_meta_itoi_state(device
);
866 radv_device_finish_meta_cleari_state(device
);
870 radv_device_init_meta_bufimage_state(struct radv_device
*device
)
874 result
= radv_device_init_meta_itob_state(device
);
875 if (result
!= VK_SUCCESS
)
878 result
= radv_device_init_meta_btoi_state(device
);
879 if (result
!= VK_SUCCESS
)
882 result
= radv_device_init_meta_itoi_state(device
);
883 if (result
!= VK_SUCCESS
)
886 result
= radv_device_init_meta_cleari_state(device
);
887 if (result
!= VK_SUCCESS
)
892 radv_device_finish_meta_itoi_state(device
);
894 radv_device_finish_meta_btoi_state(device
);
896 radv_device_finish_meta_itob_state(device
);
901 create_iview(struct radv_cmd_buffer
*cmd_buffer
,
902 struct radv_meta_blit2d_surf
*surf
,
903 struct radv_image_view
*iview
)
905 VkImageViewType view_type
= cmd_buffer
->device
->physical_device
->rad_info
.chip_class
< GFX9
? VK_IMAGE_VIEW_TYPE_2D
:
906 radv_meta_get_view_type(surf
->image
);
907 radv_image_view_init(iview
, cmd_buffer
->device
,
908 &(VkImageViewCreateInfo
) {
909 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
910 .image
= radv_image_to_handle(surf
->image
),
911 .viewType
= view_type
,
912 .format
= surf
->format
,
913 .subresourceRange
= {
914 .aspectMask
= surf
->aspect_mask
,
915 .baseMipLevel
= surf
->level
,
917 .baseArrayLayer
= surf
->layer
,
924 create_bview(struct radv_cmd_buffer
*cmd_buffer
,
925 struct radv_buffer
*buffer
,
928 struct radv_buffer_view
*bview
)
930 radv_buffer_view_init(bview
, cmd_buffer
->device
,
931 &(VkBufferViewCreateInfo
) {
932 .sType
= VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO
,
934 .buffer
= radv_buffer_to_handle(buffer
),
937 .range
= VK_WHOLE_SIZE
,
943 itob_bind_descriptors(struct radv_cmd_buffer
*cmd_buffer
,
944 struct radv_image_view
*src
,
945 struct radv_buffer_view
*dst
)
947 struct radv_device
*device
= cmd_buffer
->device
;
949 radv_meta_push_descriptor_set(cmd_buffer
,
950 VK_PIPELINE_BIND_POINT_COMPUTE
,
951 device
->meta_state
.itob
.img_p_layout
,
953 2, /* descriptorWriteCount */
954 (VkWriteDescriptorSet
[]) {
956 .sType
= VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET
,
958 .dstArrayElement
= 0,
959 .descriptorCount
= 1,
960 .descriptorType
= VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
,
961 .pImageInfo
= (VkDescriptorImageInfo
[]) {
963 .sampler
= VK_NULL_HANDLE
,
964 .imageView
= radv_image_view_to_handle(src
),
965 .imageLayout
= VK_IMAGE_LAYOUT_GENERAL
,
970 .sType
= VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET
,
972 .dstArrayElement
= 0,
973 .descriptorCount
= 1,
974 .descriptorType
= VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
,
975 .pTexelBufferView
= (VkBufferView
[]) { radv_buffer_view_to_handle(dst
) },
981 radv_meta_image_to_buffer(struct radv_cmd_buffer
*cmd_buffer
,
982 struct radv_meta_blit2d_surf
*src
,
983 struct radv_meta_blit2d_buffer
*dst
,
985 struct radv_meta_blit2d_rect
*rects
)
987 VkPipeline pipeline
= cmd_buffer
->device
->meta_state
.itob
.pipeline
;
988 struct radv_device
*device
= cmd_buffer
->device
;
989 struct radv_image_view src_view
;
990 struct radv_buffer_view dst_view
;
992 create_iview(cmd_buffer
, src
, &src_view
);
993 create_bview(cmd_buffer
, dst
->buffer
, dst
->offset
, dst
->format
, &dst_view
);
994 itob_bind_descriptors(cmd_buffer
, &src_view
, &dst_view
);
996 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
997 src
->image
->type
== VK_IMAGE_TYPE_3D
)
998 pipeline
= cmd_buffer
->device
->meta_state
.itob
.pipeline_3d
;
1000 radv_CmdBindPipeline(radv_cmd_buffer_to_handle(cmd_buffer
),
1001 VK_PIPELINE_BIND_POINT_COMPUTE
, pipeline
);
1003 for (unsigned r
= 0; r
< num_rects
; ++r
) {
1004 unsigned push_constants
[4] = {
1010 radv_CmdPushConstants(radv_cmd_buffer_to_handle(cmd_buffer
),
1011 device
->meta_state
.itob
.img_p_layout
,
1012 VK_SHADER_STAGE_COMPUTE_BIT
, 0, 16,
1015 radv_unaligned_dispatch(cmd_buffer
, rects
[r
].width
, rects
[r
].height
, 1);
1020 btoi_bind_descriptors(struct radv_cmd_buffer
*cmd_buffer
,
1021 struct radv_buffer_view
*src
,
1022 struct radv_image_view
*dst
)
1024 struct radv_device
*device
= cmd_buffer
->device
;
1026 radv_meta_push_descriptor_set(cmd_buffer
,
1027 VK_PIPELINE_BIND_POINT_COMPUTE
,
1028 device
->meta_state
.btoi
.img_p_layout
,
1030 2, /* descriptorWriteCount */
1031 (VkWriteDescriptorSet
[]) {
1033 .sType
= VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET
,
1035 .dstArrayElement
= 0,
1036 .descriptorCount
= 1,
1037 .descriptorType
= VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
,
1038 .pTexelBufferView
= (VkBufferView
[]) { radv_buffer_view_to_handle(src
) },
1041 .sType
= VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET
,
1043 .dstArrayElement
= 0,
1044 .descriptorCount
= 1,
1045 .descriptorType
= VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
,
1046 .pImageInfo
= (VkDescriptorImageInfo
[]) {
1048 .sampler
= VK_NULL_HANDLE
,
1049 .imageView
= radv_image_view_to_handle(dst
),
1050 .imageLayout
= VK_IMAGE_LAYOUT_GENERAL
,
1058 radv_meta_buffer_to_image_cs(struct radv_cmd_buffer
*cmd_buffer
,
1059 struct radv_meta_blit2d_buffer
*src
,
1060 struct radv_meta_blit2d_surf
*dst
,
1062 struct radv_meta_blit2d_rect
*rects
)
1064 VkPipeline pipeline
= cmd_buffer
->device
->meta_state
.btoi
.pipeline
;
1065 struct radv_device
*device
= cmd_buffer
->device
;
1066 struct radv_buffer_view src_view
;
1067 struct radv_image_view dst_view
;
1069 create_bview(cmd_buffer
, src
->buffer
, src
->offset
, src
->format
, &src_view
);
1070 create_iview(cmd_buffer
, dst
, &dst_view
);
1071 btoi_bind_descriptors(cmd_buffer
, &src_view
, &dst_view
);
1073 radv_CmdBindPipeline(radv_cmd_buffer_to_handle(cmd_buffer
),
1074 VK_PIPELINE_BIND_POINT_COMPUTE
, pipeline
);
1076 for (unsigned r
= 0; r
< num_rects
; ++r
) {
1077 unsigned push_constants
[3] = {
1082 radv_CmdPushConstants(radv_cmd_buffer_to_handle(cmd_buffer
),
1083 device
->meta_state
.btoi
.img_p_layout
,
1084 VK_SHADER_STAGE_COMPUTE_BIT
, 0, 12,
1087 radv_unaligned_dispatch(cmd_buffer
, rects
[r
].width
, rects
[r
].height
, 1);
1092 itoi_bind_descriptors(struct radv_cmd_buffer
*cmd_buffer
,
1093 struct radv_image_view
*src
,
1094 struct radv_image_view
*dst
)
1096 struct radv_device
*device
= cmd_buffer
->device
;
1098 radv_meta_push_descriptor_set(cmd_buffer
,
1099 VK_PIPELINE_BIND_POINT_COMPUTE
,
1100 device
->meta_state
.itoi
.img_p_layout
,
1102 2, /* descriptorWriteCount */
1103 (VkWriteDescriptorSet
[]) {
1105 .sType
= VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET
,
1107 .dstArrayElement
= 0,
1108 .descriptorCount
= 1,
1109 .descriptorType
= VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
,
1110 .pImageInfo
= (VkDescriptorImageInfo
[]) {
1112 .sampler
= VK_NULL_HANDLE
,
1113 .imageView
= radv_image_view_to_handle(src
),
1114 .imageLayout
= VK_IMAGE_LAYOUT_GENERAL
,
1119 .sType
= VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET
,
1121 .dstArrayElement
= 0,
1122 .descriptorCount
= 1,
1123 .descriptorType
= VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
,
1124 .pImageInfo
= (VkDescriptorImageInfo
[]) {
1126 .sampler
= VK_NULL_HANDLE
,
1127 .imageView
= radv_image_view_to_handle(dst
),
1128 .imageLayout
= VK_IMAGE_LAYOUT_GENERAL
,
1136 radv_meta_image_to_image_cs(struct radv_cmd_buffer
*cmd_buffer
,
1137 struct radv_meta_blit2d_surf
*src
,
1138 struct radv_meta_blit2d_surf
*dst
,
1140 struct radv_meta_blit2d_rect
*rects
)
1142 VkPipeline pipeline
= cmd_buffer
->device
->meta_state
.itoi
.pipeline
;
1143 struct radv_device
*device
= cmd_buffer
->device
;
1144 struct radv_image_view src_view
, dst_view
;
1146 create_iview(cmd_buffer
, src
, &src_view
);
1147 create_iview(cmd_buffer
, dst
, &dst_view
);
1149 itoi_bind_descriptors(cmd_buffer
, &src_view
, &dst_view
);
1151 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
1152 src
->image
->type
== VK_IMAGE_TYPE_3D
)
1153 pipeline
= cmd_buffer
->device
->meta_state
.itoi
.pipeline_3d
;
1154 radv_CmdBindPipeline(radv_cmd_buffer_to_handle(cmd_buffer
),
1155 VK_PIPELINE_BIND_POINT_COMPUTE
, pipeline
);
1157 for (unsigned r
= 0; r
< num_rects
; ++r
) {
1158 unsigned push_constants
[6] = {
1166 radv_CmdPushConstants(radv_cmd_buffer_to_handle(cmd_buffer
),
1167 device
->meta_state
.itoi
.img_p_layout
,
1168 VK_SHADER_STAGE_COMPUTE_BIT
, 0, 24,
1171 radv_unaligned_dispatch(cmd_buffer
, rects
[r
].width
, rects
[r
].height
, 1);
1176 cleari_bind_descriptors(struct radv_cmd_buffer
*cmd_buffer
,
1177 struct radv_image_view
*dst_iview
)
1179 struct radv_device
*device
= cmd_buffer
->device
;
1181 radv_meta_push_descriptor_set(cmd_buffer
,
1182 VK_PIPELINE_BIND_POINT_COMPUTE
,
1183 device
->meta_state
.cleari
.img_p_layout
,
1185 1, /* descriptorWriteCount */
1186 (VkWriteDescriptorSet
[]) {
1188 .sType
= VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET
,
1190 .dstArrayElement
= 0,
1191 .descriptorCount
= 1,
1192 .descriptorType
= VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
,
1193 .pImageInfo
= (VkDescriptorImageInfo
[]) {
1195 .sampler
= VK_NULL_HANDLE
,
1196 .imageView
= radv_image_view_to_handle(dst_iview
),
1197 .imageLayout
= VK_IMAGE_LAYOUT_GENERAL
,
1205 radv_meta_clear_image_cs(struct radv_cmd_buffer
*cmd_buffer
,
1206 struct radv_meta_blit2d_surf
*dst
,
1207 const VkClearColorValue
*clear_color
)
1209 VkPipeline pipeline
= cmd_buffer
->device
->meta_state
.cleari
.pipeline
;
1210 struct radv_device
*device
= cmd_buffer
->device
;
1211 struct radv_image_view dst_iview
;
1213 create_iview(cmd_buffer
, dst
, &dst_iview
);
1214 cleari_bind_descriptors(cmd_buffer
, &dst_iview
);
1216 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
1217 dst
->image
->type
== VK_IMAGE_TYPE_3D
)
1218 pipeline
= cmd_buffer
->device
->meta_state
.cleari
.pipeline_3d
;
1220 radv_CmdBindPipeline(radv_cmd_buffer_to_handle(cmd_buffer
),
1221 VK_PIPELINE_BIND_POINT_COMPUTE
, pipeline
);
1223 unsigned push_constants
[5] = {
1224 clear_color
->uint32
[0],
1225 clear_color
->uint32
[1],
1226 clear_color
->uint32
[2],
1227 clear_color
->uint32
[3],
1231 radv_CmdPushConstants(radv_cmd_buffer_to_handle(cmd_buffer
),
1232 device
->meta_state
.cleari
.img_p_layout
,
1233 VK_SHADER_STAGE_COMPUTE_BIT
, 0, 20,
1236 radv_unaligned_dispatch(cmd_buffer
, dst
->image
->info
.width
, dst
->image
->info
.height
, 1);