diff --git a/src/imagination/vulkan/pvr_formats.c b/src/imagination/vulkan/pvr_formats.c index 28ac0c2be55..3edc258fdd0 100644 --- a/src/imagination/vulkan/pvr_formats.c +++ b/src/imagination/vulkan/pvr_formats.c @@ -48,12 +48,6 @@ #include "vk_log.h" #include "vk_util.h" -#define PVR_BIND_VERTEX_BUFFER BITFIELD_BIT(0) -#define PVR_BIND_SAMPLER_VIEW BITFIELD_BIT(1) -#define PVR_BIND_RENDER_TARGET BITFIELD_BIT(2) -#define PVR_BIND_DEPTH_STENCIL BITFIELD_BIT(3) -#define PVR_BIND_STORAGE_IMAGE BITFIELD_BIT(4) - /* Convenience */ #define _V PVR_BIND_VERTEX_BUFFER @@ -95,13 +89,6 @@ .bind = FLAGS__T_Z, \ } -struct pvr_format { - uint32_t tex_format; - uint32_t depth_tex_format; - uint32_t stencil_tex_format; - uint32_t bind; -}; - /* clang-format off */ static const struct pvr_format pvr_format_table[] = { FORMAT(B4G4R4A4_UNORM_PACK16, A4R4G4B4, VTR_), @@ -284,6 +271,13 @@ static const struct pvr_pbe_format pvr_pbe_format_table[] = { #undef FORMAT #undef FORMAT_DEPTH_STENCIL +const struct pvr_format *pvr_get_format_table(unsigned *num_formats) +{ + assert(num_formats != NULL); + *num_formats = ARRAY_SIZE(pvr_format_table); + return pvr_format_table; +} + static inline const struct pvr_format *pvr_get_format(VkFormat vk_format) { if (vk_format < ARRAY_SIZE(pvr_format_table) && @@ -298,6 +292,16 @@ static inline const struct pvr_format *pvr_get_format(VkFormat vk_format) return NULL; } +static inline const struct pvr_format * +pvr_get_pdevice_format(struct pvr_physical_device *pdevice, VkFormat vk_format) +{ + if (vk_format >= pdevice->num_formats || + pvr_format_table[vk_format].bind == 0) + return NULL; + + return &pdevice->formats[vk_format]; +} + static inline const struct pvr_pbe_format * pvr_get_pbe_format(VkFormat vk_format) { @@ -517,11 +521,14 @@ void pvr_get_hw_clear_color( #undef f32_to_f16 static VkFormatFeatureFlags2 -pvr_get_image_format_features2(VkFormat vk_format, VkImageTiling vk_tiling) +pvr_get_image_format_features2(struct pvr_physical_device *pdevice, + VkFormat vk_format, + VkImageTiling vk_tiling) { VkFormatFeatureFlags2 flags = 0; - const struct pvr_format *pvr_format = pvr_get_format(vk_format); + const struct pvr_format *pvr_format = + pvr_get_pdevice_format(pdevice, vk_format); if (!pvr_format) return 0; @@ -624,12 +631,15 @@ pvr_get_format_swizzle_for_tpu(const struct util_format_description *desc) return desc->swizzle; } -static VkFormatFeatureFlags2 pvr_get_buffer_format_features2(VkFormat vk_format) +static VkFormatFeatureFlags2 +pvr_get_buffer_format_features2(struct pvr_physical_device *pdevice, + VkFormat vk_format) { const struct util_format_description *desc; VkFormatFeatureFlags2 flags = 0; - const struct pvr_format *pvr_format = pvr_get_format(vk_format); + const struct pvr_format *pvr_format = + pvr_get_pdevice_format(pdevice, vk_format); if (!pvr_format) return 0; @@ -712,11 +722,14 @@ void pvr_GetPhysicalDeviceFormatProperties2( VkFormat format, VkFormatProperties2 *pFormatProperties) { + VK_FROM_HANDLE(pvr_physical_device, pdevice, physicalDevice); VkFormatFeatureFlags2 linear2, optimal2, buffer2; - linear2 = pvr_get_image_format_features2(format, VK_IMAGE_TILING_LINEAR); - optimal2 = pvr_get_image_format_features2(format, VK_IMAGE_TILING_OPTIMAL); - buffer2 = pvr_get_buffer_format_features2(format); + linear2 = + pvr_get_image_format_features2(pdevice, format, VK_IMAGE_TILING_LINEAR); + optimal2 = + pvr_get_image_format_features2(pdevice, format, VK_IMAGE_TILING_OPTIMAL); + buffer2 = pvr_get_buffer_format_features2(pdevice, format); pFormatProperties->formatProperties = (VkFormatProperties){ .linearTilingFeatures = vk_format_features2_to_features(linear2), @@ -772,7 +785,7 @@ pvr_get_image_format_properties(struct pvr_physical_device *pdevice, } tiling_features2 = - pvr_get_image_format_features2(info->format, info->tiling); + pvr_get_image_format_features2(pdevice, info->format, info->tiling); if (tiling_features2 == 0) { result = vk_error(pdevice, VK_ERROR_FORMAT_NOT_SUPPORTED); goto err_unsupported_format; diff --git a/src/imagination/vulkan/pvr_formats.h b/src/imagination/vulkan/pvr_formats.h index b0a751f2dc9..bf23c3ea30b 100644 --- a/src/imagination/vulkan/pvr_formats.h +++ b/src/imagination/vulkan/pvr_formats.h @@ -210,6 +210,21 @@ enum pvr_transfer_pbe_pixel_src { PVR_TRANSFER_PBE_PIXEL_SRC_NUM = 54, }; +#define PVR_BIND_VERTEX_BUFFER BITFIELD_BIT(0) +#define PVR_BIND_SAMPLER_VIEW BITFIELD_BIT(1) +#define PVR_BIND_RENDER_TARGET BITFIELD_BIT(2) +#define PVR_BIND_DEPTH_STENCIL BITFIELD_BIT(3) +#define PVR_BIND_STORAGE_IMAGE BITFIELD_BIT(4) + +struct pvr_format { + uint32_t tex_format; + uint32_t depth_tex_format; + uint32_t stencil_tex_format; + uint32_t bind; +}; + +const struct pvr_format *pvr_get_format_table(unsigned *num_formats); + struct util_format_description; const uint8_t * pvr_get_format_swizzle_for_tpu(const struct util_format_description *desc); diff --git a/src/imagination/vulkan/pvr_physical_device.c b/src/imagination/vulkan/pvr_physical_device.c index 0ff813a3604..5ed4b834e2d 100644 --- a/src/imagination/vulkan/pvr_physical_device.c +++ b/src/imagination/vulkan/pvr_physical_device.c @@ -893,6 +893,12 @@ pvr_get_cache_uuid(const struct pvr_physical_device *const pdevice, _mesa_sha1_final(&sha1_ctx, uuid_out); } +static void +pvr_physical_device_setup_formats(struct pvr_physical_device *const pdevice) +{ + pdevice->formats = pvr_get_format_table(&pdevice->num_formats); +} + static void pvr_physical_device_setup_uuids(struct pvr_physical_device *const pdevice) { @@ -1086,6 +1092,8 @@ VkResult pvr_physical_device_init(struct pvr_physical_device *pdevice, if (result != VK_SUCCESS) goto err_pvr_winsys_destroy; + pvr_physical_device_setup_formats(pdevice); + pvr_physical_device_setup_uuids(pdevice); if (!pvr_physical_device_setup_pipeline_cache(pdevice)) { diff --git a/src/imagination/vulkan/pvr_physical_device.h b/src/imagination/vulkan/pvr_physical_device.h index ea421ac5c25..34068e08beb 100644 --- a/src/imagination/vulkan/pvr_physical_device.h +++ b/src/imagination/vulkan/pvr_physical_device.h @@ -32,6 +32,7 @@ # define PVR_USE_WSI_PLATFORM false #endif +struct pvr_format; struct pvr_instance; typedef struct _pco_ctx pco_ctx; @@ -59,6 +60,9 @@ struct pvr_physical_device { pco_ctx *pco_ctx; + const struct pvr_format *formats; + unsigned num_formats; + uint8_t device_uuid[SHA1_DIGEST_LENGTH]; uint8_t cache_uuid[SHA1_DIGEST_LENGTH]; };