aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGurchetan Singh <gurchetansingh@google.com>2024-01-02 15:00:06 -0800
committerGurchetan Singh <gurchetansingh@google.com>2024-03-05 18:20:46 -0800
commitb394b814823c40b343ddcc6cb8671a4680bbecaf (patch)
tree9e4db5dd9ca9121382c1999f9e748fd7a525ce03
parent27704e08b8189805162d83482394e717e5b4bc2e (diff)
downloadmesa3d-b394b814823c40b343ddcc6cb8671a4680bbecaf.tar.gz
ANDROID: vulkan/util: introduce vk_util_compiler files
This is essentially code movement into separate files. Bug: 327408955 Test: compile Change-Id: Id60be8cd1b3ff7de14b8f6d90f830a83850afda1
-rw-r--r--src/vulkan/util/meson.build2
-rw-r--r--src/vulkan/util/vk_util.c62
-rw-r--r--src/vulkan/util/vk_util.h23
-rw-r--r--src/vulkan/util/vk_util_compiler.c67
-rw-r--r--src/vulkan/util/vk_util_compiler.h32
5 files changed, 102 insertions, 84 deletions
diff --git a/src/vulkan/util/meson.build b/src/vulkan/util/meson.build
index 90ebfd6fb71..9dbe9dddfa7 100644
--- a/src/vulkan/util/meson.build
+++ b/src/vulkan/util/meson.build
@@ -71,6 +71,8 @@ files_vulkan_util = files(
'vk_format.c',
'vk_util.c',
'vk_util.h',
+ 'vk_util_compiler.c',
+ 'vk_util_compiler.h',
)
vk_dispatch_table = custom_target(
diff --git a/src/vulkan/util/vk_util.c b/src/vulkan/util/vk_util.c
index 841212034ec..e172ccea27d 100644
--- a/src/vulkan/util/vk_util.c
+++ b/src/vulkan/util/vk_util.c
@@ -29,8 +29,6 @@
#include "vk_util.h"
#include "util/u_debug.h"
-#include "compiler/spirv/nir_spirv.h"
-
uint32_t vk_get_driver_version(void)
{
const char *minor_string = strchr(PACKAGE_VERSION, '.');
@@ -81,63 +79,3 @@ vk_warn_non_conformant_implementation(const char *driver_name)
fprintf(stderr, "WARNING: %s is not a conformant Vulkan implementation, "
"testing use only.\n", driver_name);
}
-
-struct nir_spirv_specialization*
-vk_spec_info_to_nir_spirv(const VkSpecializationInfo *spec_info,
- uint32_t *out_num_spec_entries)
-{
- if (spec_info == NULL || spec_info->mapEntryCount == 0)
- return NULL;
-
- uint32_t num_spec_entries = spec_info->mapEntryCount;
- struct nir_spirv_specialization *spec_entries =
- calloc(num_spec_entries, sizeof(*spec_entries));
-
- for (uint32_t i = 0; i < num_spec_entries; i++) {
- VkSpecializationMapEntry entry = spec_info->pMapEntries[i];
- const void *data = (uint8_t *)spec_info->pData + entry.offset;
- assert((uint8_t *)data + entry.size <=
- (uint8_t *)spec_info->pData + spec_info->dataSize);
-
- spec_entries[i].id = spec_info->pMapEntries[i].constantID;
- switch (entry.size) {
- case 8:
- spec_entries[i].value.u64 = *(const uint64_t *)data;
- break;
- case 4:
- spec_entries[i].value.u32 = *(const uint32_t *)data;
- break;
- case 2:
- spec_entries[i].value.u16 = *(const uint16_t *)data;
- break;
- case 1:
- spec_entries[i].value.u8 = *(const uint8_t *)data;
- break;
- case 0:
- default:
- /* The Vulkan spec says:
- *
- * "For a constantID specialization constant declared in a
- * shader, size must match the byte size of the constantID. If
- * the specialization constant is of type boolean, size must be
- * the byte size of VkBool32."
- *
- * Therefore, since only scalars can be decorated as
- * specialization constants, we can assume that if it doesn't have
- * a size of 1, 2, 4, or 8, any use in a shader would be invalid
- * usage. The spec further says:
- *
- * "If a constantID value is not a specialization constant ID
- * used in the shader, that map entry does not affect the
- * behavior of the pipeline."
- *
- * so we should ignore any invalid specialization constants rather
- * than crash or error out when we see one.
- */
- break;
- }
- }
-
- *out_num_spec_entries = num_spec_entries;
- return spec_entries;
-}
diff --git a/src/vulkan/util/vk_util.h b/src/vulkan/util/vk_util.h
index 85807f410fa..e691acb8609 100644
--- a/src/vulkan/util/vk_util.h
+++ b/src/vulkan/util/vk_util.h
@@ -23,12 +23,11 @@
#ifndef VK_UTIL_H
#define VK_UTIL_H
-#include "util/bitscan.h"
#include "util/macros.h"
-#include "compiler/shader_enums.h"
#include <stdlib.h>
#include <string.h>
+#include "vk_util_compiler.h"
#include "vk_struct_type_cast.h"
#ifdef __cplusplus
@@ -316,19 +315,6 @@ struct vk_pipeline_cache_header {
memcpy((dest), (src), (count) * sizeof(*(src))); \
} while (0)
-static inline gl_shader_stage
-vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage)
-{
- assert(util_bitcount((uint32_t) vk_stage) == 1);
- return (gl_shader_stage) (ffs((uint32_t) vk_stage) - 1);
-}
-
-static inline VkShaderStageFlagBits
-mesa_to_vk_shader_stage(gl_shader_stage mesa_stage)
-{
- return (VkShaderStageFlagBits) (1 << ((uint32_t) mesa_stage));
-}
-
/* iterate over a sequence of indexed multidraws for VK_EXT_multi_draw extension */
/* 'i' must be explicitly declared */
#define vk_foreach_multi_draw_indexed(_draw, _i, _pDrawInfo, _num_draws, _stride) \
@@ -343,13 +329,6 @@ mesa_to_vk_shader_stage(gl_shader_stage mesa_stage)
(_i) < (_num_draws); \
(_i)++, (_draw) = (const VkMultiDrawInfoEXT*)((const uint8_t*)(_draw) + (_stride)))
-
-struct nir_spirv_specialization;
-
-struct nir_spirv_specialization*
-vk_spec_info_to_nir_spirv(const VkSpecializationInfo *spec_info,
- uint32_t *out_num_spec_entries);
-
#define STACK_ARRAY_SIZE 8
#ifdef __cplusplus
diff --git a/src/vulkan/util/vk_util_compiler.c b/src/vulkan/util/vk_util_compiler.c
new file mode 100644
index 00000000000..619644ca830
--- /dev/null
+++ b/src/vulkan/util/vk_util_compiler.c
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2024 Google LLC
+ * SPDX-License-Identifier: MIT
+ */
+
+#include "vk_util_compiler.h"
+#include "compiler/spirv/nir_spirv.h"
+
+struct nir_spirv_specialization*
+vk_spec_info_to_nir_spirv(const VkSpecializationInfo *spec_info,
+ uint32_t *out_num_spec_entries)
+{
+ if (spec_info == NULL || spec_info->mapEntryCount == 0)
+ return NULL;
+
+ uint32_t num_spec_entries = spec_info->mapEntryCount;
+ struct nir_spirv_specialization *spec_entries =
+ calloc(num_spec_entries, sizeof(*spec_entries));
+
+ for (uint32_t i = 0; i < num_spec_entries; i++) {
+ VkSpecializationMapEntry entry = spec_info->pMapEntries[i];
+ const void *data = (uint8_t *)spec_info->pData + entry.offset;
+ assert((uint8_t *)data + entry.size <=
+ (uint8_t *)spec_info->pData + spec_info->dataSize);
+
+ spec_entries[i].id = spec_info->pMapEntries[i].constantID;
+ switch (entry.size) {
+ case 8:
+ spec_entries[i].value.u64 = *(const uint64_t *)data;
+ break;
+ case 4:
+ spec_entries[i].value.u32 = *(const uint32_t *)data;
+ break;
+ case 2:
+ spec_entries[i].value.u16 = *(const uint16_t *)data;
+ break;
+ case 1:
+ spec_entries[i].value.u8 = *(const uint8_t *)data;
+ break;
+ case 0:
+ default:
+ /* The Vulkan spec says:
+ *
+ * "For a constantID specialization constant declared in a
+ * shader, size must match the byte size of the constantID. If
+ * the specialization constant is of type boolean, size must be
+ * the byte size of VkBool32."
+ *
+ * Therefore, since only scalars can be decorated as
+ * specialization constants, we can assume that if it doesn't have
+ * a size of 1, 2, 4, or 8, any use in a shader would be invalid
+ * usage. The spec further says:
+ *
+ * "If a constantID value is not a specialization constant ID
+ * used in the shader, that map entry does not affect the
+ * behavior of the pipeline."
+ *
+ * so we should ignore any invalid specialization constants rather
+ * than crash or error out when we see one.
+ */
+ break;
+ }
+ }
+
+ *out_num_spec_entries = num_spec_entries;
+ return spec_entries;
+}
diff --git a/src/vulkan/util/vk_util_compiler.h b/src/vulkan/util/vk_util_compiler.h
new file mode 100644
index 00000000000..bf75e54df8e
--- /dev/null
+++ b/src/vulkan/util/vk_util_compiler.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2024 Google LLC
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef VK_UTIL_COMPILER_H
+#define VK_UTIL_COMPILER_H
+
+#include <vulkan/vulkan_core.h>
+
+#include "compiler/shader_enums.h"
+#include "util/bitscan.h"
+
+static inline gl_shader_stage
+vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage)
+{
+ assert(util_bitcount((uint32_t) vk_stage) == 1);
+ return (gl_shader_stage) (ffs((uint32_t) vk_stage) - 1);
+}
+
+static inline VkShaderStageFlagBits
+mesa_to_vk_shader_stage(gl_shader_stage mesa_stage)
+{
+ return (VkShaderStageFlagBits) (1 << ((uint32_t) mesa_stage));
+}
+
+struct nir_spirv_specialization;
+
+struct nir_spirv_specialization*
+vk_spec_info_to_nir_spirv(const VkSpecializationInfo *spec_info,
+ uint32_t *out_num_spec_entries);
+#endif