radv: Update descriptor sets for multiple planes.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Sat, 30 Mar 2019 02:16:04 +0000 (03:16 +0100)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Thu, 25 Apr 2019 19:56:20 +0000 (19:56 +0000)
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
src/amd/vulkan/radv_descriptor_set.c
src/amd/vulkan/radv_nir_to_llvm.c
src/amd/vulkan/radv_private.h

index 7d5b05ad46464d526db69d8190c4d559f4715a3d..e1b5992d63571f746e3238218c4ee2ec9f176fea 100644 (file)
@@ -563,7 +563,7 @@ radv_descriptor_set_create(struct radv_device *device,
 
                        unsigned offset = layout->binding[i].offset / 4;
                        if (layout->binding[i].type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
-                               offset += 16;
+                               offset += radv_combined_image_descriptor_sampler_offset(layout->binding + i) / 4;
 
                        const uint32_t *samplers = (const uint32_t*)((const char*)layout + layout->binding[i].immutable_samplers_offset);
                        for (unsigned j = 0; j < layout->binding[i].array_size; ++j) {
@@ -882,7 +882,7 @@ static void write_dynamic_buffer_descriptor(struct radv_device *device,
 static void
 write_image_descriptor(struct radv_device *device,
                       struct radv_cmd_buffer *cmd_buffer,
-                      unsigned *dst,
+                      unsigned size, unsigned *dst,
                       struct radeon_winsys_bo **buffer_list,
                       VkDescriptorType descriptor_type,
                       const VkDescriptorImageInfo *image_info)
@@ -896,7 +896,7 @@ write_image_descriptor(struct radv_device *device,
                descriptor = &iview->descriptor;
        }
 
-       memcpy(dst, descriptor, 16 * 4);
+       memcpy(dst, descriptor, size);
 
        if (cmd_buffer)
                radv_cs_add_buffer(device->ws, cmd_buffer->cs, iview->bo);
@@ -907,6 +907,7 @@ write_image_descriptor(struct radv_device *device,
 static void
 write_combined_image_sampler_descriptor(struct radv_device *device,
                                        struct radv_cmd_buffer *cmd_buffer,
+                                       unsigned sampler_offset,
                                        unsigned *dst,
                                        struct radeon_winsys_bo **buffer_list,
                                        VkDescriptorType descriptor_type,
@@ -915,10 +916,12 @@ write_combined_image_sampler_descriptor(struct radv_device *device,
 {
        RADV_FROM_HANDLE(radv_sampler, sampler, image_info->sampler);
 
-       write_image_descriptor(device, cmd_buffer, dst, buffer_list, descriptor_type, image_info);
+       write_image_descriptor(device, cmd_buffer, sampler_offset, dst, buffer_list,
+                              descriptor_type, image_info);
        /* copy over sampler state */
-       if (has_sampler)
-               memcpy(dst + 16, sampler->state, 16);
+       if (has_sampler) {
+               memcpy(dst + sampler_offset / sizeof(*dst), sampler->state, 16);
+       }
 }
 
 static void
@@ -991,20 +994,23 @@ void radv_update_descriptor_sets(
                        case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
                        case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
                        case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
-                               write_image_descriptor(device, cmd_buffer, ptr, buffer_list,
+                               write_image_descriptor(device, cmd_buffer, 64, ptr, buffer_list,
                                                       writeset->descriptorType,
                                                       writeset->pImageInfo + j);
                                break;
-                       case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
-                               write_combined_image_sampler_descriptor(device, cmd_buffer, ptr, buffer_list,
+                       case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: {
+                               unsigned sampler_offset = radv_combined_image_descriptor_sampler_offset(binding_layout);
+                               write_combined_image_sampler_descriptor(device, cmd_buffer, sampler_offset,
+                                                                       ptr, buffer_list,
                                                                        writeset->descriptorType,
                                                                        writeset->pImageInfo + j,
                                                                        !binding_layout->immutable_samplers_offset);
                                if (copy_immutable_samplers) {
                                        const unsigned idx = writeset->dstArrayElement + j;
-                                       memcpy(ptr + 16, samplers + 4 * idx, 16);
+                                       memcpy((char*)ptr + sampler_offset, samplers + 4 * idx, 16);
                                }
                                break;
+                       }
                        case VK_DESCRIPTOR_TYPE_SAMPLER:
                                if (!binding_layout->immutable_samplers_offset) {
                                        write_sampler_descriptor(device, ptr,
@@ -1163,6 +1169,7 @@ VkResult radv_CreateDescriptorUpdateTemplate(VkDevice _device,
                        .dst_stride = dst_stride,
                        .buffer_offset = buffer_offset,
                        .has_sampler = !binding_layout->immutable_samplers_offset,
+                       .sampler_offset = radv_combined_image_descriptor_sampler_offset(binding_layout),
                        .immutable_samplers = immutable_samplers
                };
        }
@@ -1227,17 +1234,18 @@ void radv_update_descriptor_set_with_template(struct radv_device *device,
                        case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
                        case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
                        case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
-                               write_image_descriptor(device, cmd_buffer, pDst, buffer_list,
+                               write_image_descriptor(device, cmd_buffer, 64, pDst, buffer_list,
                                                       templ->entry[i].descriptor_type,
                                                       (struct VkDescriptorImageInfo *) pSrc);
                                break;
                        case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
-                               write_combined_image_sampler_descriptor(device, cmd_buffer, pDst, buffer_list,
-                                                                       templ->entry[i].descriptor_type,
+                               write_combined_image_sampler_descriptor(device, cmd_buffer, templ->entry[i].sampler_offset,
+                                                                       pDst, buffer_list, templ->entry[i].descriptor_type,
                                                                        (struct VkDescriptorImageInfo *) pSrc,
                                                                        templ->entry[i].has_sampler);
-                               if (templ->entry[i].immutable_samplers)
-                                       memcpy(pDst + 16, templ->entry[i].immutable_samplers + 4 * j, 16);
+                               if (templ->entry[i].immutable_samplers) {
+                                       memcpy((char*)pDst + templ->entry[i].sampler_offset, templ->entry[i].immutable_samplers + 4 * j, 16);
+                               }
                                break;
                        case VK_DESCRIPTOR_TYPE_SAMPLER:
                                if (templ->entry[i].has_sampler)
index 5bc88298ee6bc92979142255c36ce5ea7a0afc6e..adf158e30e15b44d5539d6f7fd4110be298b47c9 100644 (file)
@@ -1978,8 +1978,9 @@ static LLVMValueRef radv_get_sampler_desc(struct ac_shader_abi *abi,
                break;
        case AC_DESC_SAMPLER:
                type = ctx->ac.v4i32;
-               if (binding->type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
-                       offset += 64;
+               if (binding->type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) {
+                       offset += radv_combined_image_descriptor_sampler_offset(binding);
+               }
 
                type_size = 16;
                break;
@@ -1987,6 +1988,13 @@ static LLVMValueRef radv_get_sampler_desc(struct ac_shader_abi *abi,
                type = ctx->ac.v4i32;
                type_size = 16;
                break;
+       case AC_DESC_PLANE_0:
+       case AC_DESC_PLANE_1:
+       case AC_DESC_PLANE_2:
+               type = ctx->ac.v8i32;
+               type_size = 32;
+               offset += 32 * (desc_type - AC_DESC_PLANE_0);
+               break;
        default:
                unreachable("invalid desc_type\n");
        }
index ddd130773c1071f300d6e91c368569cacfd52a1c..352072f8ff3f176f4df93889c76083066fcb127e 100644 (file)
@@ -809,7 +809,8 @@ struct radv_descriptor_update_template_entry {
        uint32_t buffer_offset;
 
        /* Only valid for combined image samplers and samplers */
-       uint16_t has_sampler;
+       uint8_t has_sampler;
+       uint8_t sampler_offset;
 
        /* In bytes */
        size_t src_offset;