enum blit2d_src_type {
BLIT2D_SRC_TYPE_IMAGE,
+ BLIT2D_SRC_TYPE_IMAGE_3D,
BLIT2D_SRC_TYPE_BUFFER,
BLIT2D_NUM_SRC_TYPES,
};
VkImageAspectFlagBits aspects)
{
VkFormat format;
+ VkImageViewType view_type = cmd_buffer->device->physical_device->rad_info.chip_class < GFX9 ? VK_IMAGE_VIEW_TYPE_2D :
+ radv_meta_get_view_type(surf->image);
if (depth_format)
format = depth_format;
&(VkImageViewCreateInfo) {
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
.image = radv_image_to_handle(surf->image),
- .viewType = VK_IMAGE_VIEW_TYPE_2D,
+ .viewType = view_type,
.format = format,
.subresourceRange = {
.aspectMask = aspects,
} else {
create_iview(cmd_buffer, src_img, &tmp->iview, depth_format, aspects);
+ if (src_type == BLIT2D_SRC_TYPE_IMAGE_3D)
+ radv_CmdPushConstants(radv_cmd_buffer_to_handle(cmd_buffer),
+ device->meta_state.blit2d.p_layouts[src_type],
+ VK_SHADER_STAGE_FRAGMENT_BIT, 16, 4,
+ &src_img->layer);
+
radv_meta_push_descriptor_set(cmd_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
device->meta_state.blit2d.p_layouts[src_type],
0, /* set */
unsigned num_rects,
struct radv_meta_blit2d_rect *rects)
{
+ bool use_3d = cmd_buffer->device->physical_device->rad_info.chip_class >= GFX9 &&
+ (src_img && src_img->image->type == VK_IMAGE_TYPE_3D);
enum blit2d_src_type src_type = src_buf ? BLIT2D_SRC_TYPE_BUFFER :
- BLIT2D_SRC_TYPE_IMAGE;
+ use_3d ? BLIT2D_SRC_TYPE_IMAGE_3D : BLIT2D_SRC_TYPE_IMAGE;
radv_meta_blit2d_normal_dst(cmd_buffer, src_img, src_buf, dst,
num_rects, rects, src_type);
}
typedef nir_ssa_def* (*texel_fetch_build_func)(struct nir_builder *,
struct radv_device *,
- nir_ssa_def *);
+ nir_ssa_def *, bool);
static nir_ssa_def *
build_nir_texel_fetch(struct nir_builder *b, struct radv_device *device,
- nir_ssa_def *tex_pos)
+ nir_ssa_def *tex_pos, bool is_3d)
{
+ enum glsl_sampler_dim dim = is_3d ? GLSL_SAMPLER_DIM_3D : GLSL_SAMPLER_DIM_2D;
const struct glsl_type *sampler_type =
- glsl_sampler_type(GLSL_SAMPLER_DIM_2D, false, false, GLSL_TYPE_UINT);
+ glsl_sampler_type(dim, false, false, GLSL_TYPE_UINT);
nir_variable *sampler = nir_variable_create(b->shader, nir_var_uniform,
sampler_type, "s_tex");
sampler->data.descriptor_set = 0;
sampler->data.binding = 0;
+ nir_ssa_def *tex_pos_3d = NULL;
+ if (is_3d) {
+ nir_intrinsic_instr *layer = nir_intrinsic_instr_create(b->shader, nir_intrinsic_load_push_constant);
+ nir_intrinsic_set_base(layer, 16);
+ nir_intrinsic_set_range(layer, 4);
+ layer->src[0] = nir_src_for_ssa(nir_imm_int(b, 0));
+ layer->num_components = 1;
+ nir_ssa_dest_init(&layer->instr, &layer->dest, 1, 32, "layer");
+ nir_builder_instr_insert(b, &layer->instr);
+
+ nir_ssa_def *chans[3];
+ chans[0] = nir_channel(b, tex_pos, 0);
+ chans[1] = nir_channel(b, tex_pos, 1);
+ chans[2] = &layer->dest.ssa;
+ tex_pos_3d = nir_vec(b, chans, 3);
+ }
nir_tex_instr *tex = nir_tex_instr_create(b->shader, 2);
- tex->sampler_dim = GLSL_SAMPLER_DIM_2D;
+ tex->sampler_dim = dim;
tex->op = nir_texop_txf;
tex->src[0].src_type = nir_tex_src_coord;
- tex->src[0].src = nir_src_for_ssa(tex_pos);
+ tex->src[0].src = nir_src_for_ssa(is_3d ? tex_pos_3d : tex_pos);
tex->src[1].src_type = nir_tex_src_lod;
tex->src[1].src = nir_src_for_ssa(nir_imm_int(b, 0));
tex->dest_type = nir_type_uint;
tex->is_array = false;
- tex->coord_components = 2;
+ tex->coord_components = is_3d ? 3 : 2;
tex->texture = nir_deref_var_create(tex, sampler);
tex->sampler = NULL;
static nir_ssa_def *
build_nir_buffer_fetch(struct nir_builder *b, struct radv_device *device,
- nir_ssa_def *tex_pos)
+ nir_ssa_def *tex_pos, bool is_3d)
{
const struct glsl_type *sampler_type =
glsl_sampler_type(GLSL_SAMPLER_DIM_BUF, false, false, GLSL_TYPE_UINT);
static nir_shader *
build_nir_copy_fragment_shader(struct radv_device *device,
- texel_fetch_build_func txf_func, const char* name)
+ texel_fetch_build_func txf_func, const char* name, bool is_3d)
{
const struct glsl_type *vec4 = glsl_vec4_type();
const struct glsl_type *vec2 = glsl_vector_type(GLSL_TYPE_FLOAT, 2);
unsigned swiz[4] = { 0, 1 };
nir_ssa_def *tex_pos = nir_swizzle(&b, pos_int, swiz, 2, false);
- nir_ssa_def *color = txf_func(&b, device, tex_pos);
+ nir_ssa_def *color = txf_func(&b, device, tex_pos, is_3d);
nir_store_var(&b, color_out, color, 0xf);
return b.shader;
static nir_shader *
build_nir_copy_fragment_shader_depth(struct radv_device *device,
- texel_fetch_build_func txf_func, const char* name)
+ texel_fetch_build_func txf_func, const char* name, bool is_3d)
{
const struct glsl_type *vec4 = glsl_vec4_type();
const struct glsl_type *vec2 = glsl_vector_type(GLSL_TYPE_FLOAT, 2);
unsigned swiz[4] = { 0, 1 };
nir_ssa_def *tex_pos = nir_swizzle(&b, pos_int, swiz, 2, false);
- nir_ssa_def *color = txf_func(&b, device, tex_pos);
+ nir_ssa_def *color = txf_func(&b, device, tex_pos, is_3d);
nir_store_var(&b, color_out, color, 0x1);
return b.shader;
static nir_shader *
build_nir_copy_fragment_shader_stencil(struct radv_device *device,
- texel_fetch_build_func txf_func, const char* name)
+ texel_fetch_build_func txf_func, const char* name, bool is_3d)
{
const struct glsl_type *vec4 = glsl_vec4_type();
const struct glsl_type *vec2 = glsl_vector_type(GLSL_TYPE_FLOAT, 2);
unsigned swiz[4] = { 0, 1 };
nir_ssa_def *tex_pos = nir_swizzle(&b, pos_int, swiz, 2, false);
- nir_ssa_def *color = txf_func(&b, device, tex_pos);
+ nir_ssa_def *color = txf_func(&b, device, tex_pos, is_3d);
nir_store_var(&b, color_out, color, 0x1);
return b.shader;
src_func = build_nir_texel_fetch;
name = "meta_blit2d_image_fs";
break;
+ case BLIT2D_SRC_TYPE_IMAGE_3D:
+ src_func = build_nir_texel_fetch;
+ name = "meta_blit3d_image_fs";
+ break;
case BLIT2D_SRC_TYPE_BUFFER:
src_func = build_nir_buffer_fetch;
name = "meta_blit2d_buffer_fs";
struct radv_shader_module fs = { .nir = NULL };
- fs.nir = build_nir_copy_fragment_shader(device, src_func, name);
+ fs.nir = build_nir_copy_fragment_shader(device, src_func, name, src_type == BLIT2D_SRC_TYPE_IMAGE_3D);
vi_create_info = &normal_vi_create_info;
struct radv_shader_module vs = {
src_func = build_nir_texel_fetch;
name = "meta_blit2d_depth_image_fs";
break;
+ case BLIT2D_SRC_TYPE_IMAGE_3D:
+ src_func = build_nir_texel_fetch;
+ name = "meta_blit3d_depth_image_fs";
+ break;
case BLIT2D_SRC_TYPE_BUFFER:
src_func = build_nir_buffer_fetch;
name = "meta_blit2d_depth_buffer_fs";
const VkPipelineVertexInputStateCreateInfo *vi_create_info;
struct radv_shader_module fs = { .nir = NULL };
- fs.nir = build_nir_copy_fragment_shader_depth(device, src_func, name);
+ fs.nir = build_nir_copy_fragment_shader_depth(device, src_func, name, src_type == BLIT2D_SRC_TYPE_IMAGE_3D);
vi_create_info = &normal_vi_create_info;
struct radv_shader_module vs = {
src_func = build_nir_texel_fetch;
name = "meta_blit2d_stencil_image_fs";
break;
+ case BLIT2D_SRC_TYPE_IMAGE_3D:
+ src_func = build_nir_texel_fetch;
+ name = "meta_blit3d_stencil_image_fs";
+ break;
case BLIT2D_SRC_TYPE_BUFFER:
src_func = build_nir_buffer_fetch;
name = "meta_blit2d_stencil_buffer_fs";
const VkPipelineVertexInputStateCreateInfo *vi_create_info;
struct radv_shader_module fs = { .nir = NULL };
- fs.nir = build_nir_copy_fragment_shader_stencil(device, src_func, name);
+ fs.nir = build_nir_copy_fragment_shader_stencil(device, src_func, name, src_type == BLIT2D_SRC_TYPE_IMAGE_3D);
vi_create_info = &normal_vi_create_info;
struct radv_shader_module vs = {
radv_device_init_meta_blit2d_state(struct radv_device *device)
{
VkResult result;
+ bool create_3d = device->physical_device->rad_info.chip_class >= GFX9;
const VkPushConstantRange push_constant_ranges[] = {
{VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
if (result != VK_SUCCESS)
goto fail;
+ if (create_3d) {
+ result = radv_CreateDescriptorSetLayout(radv_device_to_handle(device),
+ &(VkDescriptorSetLayoutCreateInfo) {
+ .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
+ .flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR,
+ .bindingCount = 1,
+ .pBindings = (VkDescriptorSetLayoutBinding[]) {
+ {
+ .binding = 0,
+ .descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
+ .descriptorCount = 1,
+ .stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT,
+ .pImmutableSamplers = NULL
+ },
+ }
+ }, &device->meta_state.alloc, &device->meta_state.blit2d.ds_layouts[BLIT2D_SRC_TYPE_IMAGE_3D]);
+ if (result != VK_SUCCESS)
+ goto fail;
+ result = radv_CreatePipelineLayout(radv_device_to_handle(device),
+ &(VkPipelineLayoutCreateInfo) {
+ .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
+ .setLayoutCount = 1,
+ .pSetLayouts = &device->meta_state.blit2d.ds_layouts[BLIT2D_SRC_TYPE_IMAGE_3D],
+ .pushConstantRangeCount = 2,
+ .pPushConstantRanges = push_constant_ranges,
+ },
+ &device->meta_state.alloc, &device->meta_state.blit2d.p_layouts[BLIT2D_SRC_TYPE_IMAGE_3D]);
+ if (result != VK_SUCCESS)
+ goto fail;
+ }
+
result = radv_CreateDescriptorSetLayout(radv_device_to_handle(device),
&(VkDescriptorSetLayoutCreateInfo) {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
goto fail;
for (unsigned src = 0; src < BLIT2D_NUM_SRC_TYPES; src++) {
+ if (src == BLIT2D_SRC_TYPE_IMAGE_3D && !create_3d)
+ continue;
for (unsigned j = 0; j < ARRAY_SIZE(pipeline_formats); ++j) {
result = blit2d_init_color_pipeline(device, src, pipeline_formats[j]);
if (result != VK_SUCCESS)