radv: Properly handle all sizes of specialization constants
authorJason Ekstrand <jason@jlekstrand.net>
Wed, 22 Apr 2020 18:42:12 +0000 (13:42 -0500)
committerMarge Bot <eric+marge@anholt.net>
Fri, 24 Apr 2020 09:23:59 +0000 (09:23 +0000)
cc: mesa-stable@lists.freedesktop.org

Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Acked-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4675>

src/amd/vulkan/radv_shader.c

index 61923b432ee44a3ba0db099c93904b06fffebf7a..7d8e8a290118335dba31eba79de4f48e71c4bb18 100644 (file)
@@ -327,10 +327,23 @@ radv_shader_compile_to_nir(struct radv_device *device,
                                assert(data + entry.size <= spec_info->pData + spec_info->dataSize);
 
                                spec_entries[i].id = spec_info->pMapEntries[i].constantID;
-                               if (spec_info->dataSize == 8)
+                               switch (entry.size) {
+                               case 8:
                                        spec_entries[i].data64 = *(const uint64_t *)data;
-                               else
+                                       break;
+                               case 4:
                                        spec_entries[i].data32 = *(const uint32_t *)data;
+                                       break;
+                               case 2:
+                                       spec_entries[i].data32 = *(const uint16_t *)data;
+                                       break;
+                               case 1:
+                                       spec_entries[i].data32 = *(const uint8_t *)data;
+                                       break;
+                               default:
+                                       assert(!"Invalid spec constant size");
+                                       break;
+                               }
                        }
                }
                const struct spirv_to_nir_options spirv_options = {