radv: Do not use extra descriptor space for the 3rd plane.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Wed, 8 May 2019 23:57:28 +0000 (01:57 +0200)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Sun, 12 May 2019 23:02:44 +0000 (23:02 +0000)
While ImageFormatProperties returns the number of internal descriptors,
it turns out that applications do not need to actually allocate more
descriptors in the descriptor pool.

So if we make descriptors with more planes larger we have to be
convervative and always allocate space for the larger descriptors
which is a waste given the low usage of this ext.

So let us make use of the fact that 3plane formats all have the
same formats & dimensions for the last two planes. This way we
only need the first half of the descriptor of the 3rd plane and
can share the second half of the second plane.

This allows us to use 16 bytes for the descriptor which nicely
fits into the 16 bytes that are unused right next to the sampler.

Fixes: 5564c38212a "radv: Update descriptor sets for multiple planes."
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
src/amd/vulkan/radv_descriptor_set.c
src/amd/vulkan/radv_descriptor_set.h
src/amd/vulkan/radv_nir_to_llvm.c

index 4e9c73c94d0ac70fb7a010281ea8e75a9b34dd66..bd00f68a3cb6ddbb3a6faba0005dc8c3fb1f2d0b 100644 (file)
@@ -200,7 +200,7 @@ VkResult radv_CreateDescriptorSetLayout(
                        break;
                case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
                        /* main descriptor + fmask descriptor + sampler */
-                       set_layout->binding[b].size = 32 + 32 * max_sampled_image_descriptors;
+                       set_layout->binding[b].size = 96;
                        binding_buffer_count = 1;
                        alignment = 32;
                        break;
@@ -247,7 +247,8 @@ VkResult radv_CreateDescriptorSetLayout(
 
                        /* Don't reserve space for the samplers if they're not accessed. */
                        if (set_layout->binding[b].immutable_samplers_equal) {
-                               if (binding->descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
+                               if (binding->descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER &&
+                                   max_sampled_image_descriptors <= 2)
                                        set_layout->binding[b].size -= 32;
                                else if (binding->descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER)
                                        set_layout->binding[b].size -= 16;
index 5fd19d94482fc077435ea3de95dd366ff527c68e..89be6e69068f2a72de64969638eeaadd51c42cf2 100644 (file)
@@ -104,7 +104,7 @@ radv_immutable_samplers(const struct radv_descriptor_set_layout *set,
 static inline unsigned
 radv_combined_image_descriptor_sampler_offset(const struct radv_descriptor_set_binding_layout *binding)
 {
-       return binding->size - ((!binding->immutable_samplers_equal) ? 32 : 0);
+       return binding->size - ((!binding->immutable_samplers_equal) ? 16 : 0);
 }
 
 static inline const struct radv_sampler_ycbcr_conversion *
index d83f0bd547f3d516f3b73b0563091ac991a78576..5a34a85d7b4fc9342d95a85ad6a33b060b492e2f 100644 (file)
@@ -2019,16 +2019,34 @@ static LLVMValueRef radv_get_sampler_desc(struct ac_shader_abi *abi,
 
        assert(stride % type_size == 0);
 
-       if (!index)
-               index = ctx->ac.i32_0;
+       LLVMValueRef adjusted_index = index;
+       if (!adjusted_index)
+               adjusted_index = ctx->ac.i32_0;
 
-       index = LLVMBuildMul(builder, index, LLVMConstInt(ctx->ac.i32, stride / type_size, 0), "");
+       adjusted_index = LLVMBuildMul(builder, adjusted_index, LLVMConstInt(ctx->ac.i32, stride / type_size, 0), "");
 
        list = ac_build_gep0(&ctx->ac, list, LLVMConstInt(ctx->ac.i32, offset, 0));
        list = LLVMBuildPointerCast(builder, list,
                                    ac_array_in_const32_addr_space(type), "");
 
-       return ac_build_load_to_sgpr(&ctx->ac, list, index);
+       LLVMValueRef descriptor = ac_build_load_to_sgpr(&ctx->ac, list, adjusted_index);
+
+       /* 3 plane formats always have same size and format for plane 1 & 2, so
+        * use the tail from plane 1 so that we can store only the first 16 bytes
+        * of the last plane. */
+       if (desc_type == AC_DESC_PLANE_2) {
+               LLVMValueRef descriptor2 = radv_get_sampler_desc(abi, descriptor_set, base_index, constant_index, index, AC_DESC_PLANE_1,image, write, bindless);
+
+               LLVMValueRef components[8];
+               for (unsigned i = 0; i < 4; ++i)
+                       components[i] = ac_llvm_extract_elem(&ctx->ac, descriptor, i);
+
+               for (unsigned i = 4; i < 8; ++i)
+                       components[i] = ac_llvm_extract_elem(&ctx->ac, descriptor2, i);
+               descriptor = ac_build_gather_values(&ctx->ac, components, 8);
+       }
+
+       return descriptor;
 }
 
 /* For 2_10_10_10 formats the alpha is handled as unsigned by pre-vega HW.