radv: Make fs key exemplars ordered to be a reverse fs_key lookup.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Sat, 11 Aug 2018 21:26:26 +0000 (23:26 +0200)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Tue, 14 Aug 2018 08:26:06 +0000 (10:26 +0200)
While at it, share the exemplars and account for a non-occurring
fs key.

Reviewed-by: Dave Airlie <airlied@redhat.com>
src/amd/vulkan/radv_meta_blit.c
src/amd/vulkan/radv_meta_blit2d.c
src/amd/vulkan/radv_meta_clear.c
src/amd/vulkan/radv_meta_resolve.c
src/amd/vulkan/radv_meta_resolve_fs.c
src/amd/vulkan/radv_pipeline.c
src/amd/vulkan/radv_private.h

index 67c26aabdb3507bf96b5d052ffaff287b817f2f5..f68496d32026221b9492a67da17584bbd774f9e9 100644 (file)
@@ -714,21 +714,6 @@ radv_device_finish_meta_blit_state(struct radv_device *device)
                                        state->blit.ds_layout, &state->alloc);
 }
 
-static VkFormat pipeline_formats[] = {
-   VK_FORMAT_R8G8B8A8_UNORM,
-   VK_FORMAT_R8G8B8A8_UINT,
-   VK_FORMAT_R8G8B8A8_SINT,
-   VK_FORMAT_A2R10G10B10_UINT_PACK32,
-   VK_FORMAT_A2R10G10B10_SINT_PACK32,
-   VK_FORMAT_R16G16B16A16_UNORM,
-   VK_FORMAT_R16G16B16A16_SNORM,
-   VK_FORMAT_R16G16B16A16_UINT,
-   VK_FORMAT_R16G16B16A16_SINT,
-   VK_FORMAT_R32_SFLOAT,
-   VK_FORMAT_R32G32_SFLOAT,
-   VK_FORMAT_R32G32B32A32_SFLOAT
-};
-
 static VkResult
 radv_device_init_meta_blit_color(struct radv_device *device,
                                 struct radv_shader_module *vs)
@@ -740,8 +725,8 @@ radv_device_init_meta_blit_color(struct radv_device *device,
        fs_2d.nir = build_nir_copy_fragment_shader(GLSL_SAMPLER_DIM_2D);
        fs_3d.nir = build_nir_copy_fragment_shader(GLSL_SAMPLER_DIM_3D);
 
-       for (unsigned i = 0; i < ARRAY_SIZE(pipeline_formats); ++i) {
-               unsigned key = radv_format_meta_fs_key(pipeline_formats[i]);
+       for (unsigned i = 0; i < NUM_META_FS_KEYS; ++i) {
+               unsigned key = radv_format_meta_fs_key(radv_fs_key_format_exemplars[i]);
                for(unsigned j = 0; j < RADV_META_DST_LAYOUT_COUNT; ++j) {
                        VkImageLayout layout = radv_meta_dst_layout_to_layout(j);
                        result = radv_CreateRenderPass(radv_device_to_handle(device),
@@ -749,7 +734,7 @@ radv_device_init_meta_blit_color(struct radv_device *device,
                                                        .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
                                                                .attachmentCount = 1,
                                                                .pAttachments = &(VkAttachmentDescription) {
-                                                               .format = pipeline_formats[i],
+                                                               .format = radv_fs_key_format_exemplars[i],
                                                                .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
                                                                .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
                                                                .initialLayout = layout,
index cac0a4dd55f32dfc04c6d3c8f8dddfdb6d8ca9c3..7965285694231b5a89e4ce0de776c70d694bd9eb 100644 (file)
@@ -1239,21 +1239,6 @@ blit2d_init_stencil_only_pipeline(struct radv_device *device,
        return result;
 }
 
-static VkFormat pipeline_formats[] = {
-   VK_FORMAT_R8G8B8A8_UNORM,
-   VK_FORMAT_R8G8B8A8_UINT,
-   VK_FORMAT_R8G8B8A8_SINT,
-   VK_FORMAT_A2R10G10B10_UINT_PACK32,
-   VK_FORMAT_A2R10G10B10_SINT_PACK32,
-   VK_FORMAT_R16G16B16A16_UNORM,
-   VK_FORMAT_R16G16B16A16_SNORM,
-   VK_FORMAT_R16G16B16A16_UINT,
-   VK_FORMAT_R16G16B16A16_SINT,
-   VK_FORMAT_R32_SFLOAT,
-   VK_FORMAT_R32G32_SFLOAT,
-   VK_FORMAT_R32G32B32A32_SFLOAT
-};
-
 static VkResult
 meta_blit2d_create_pipe_layout(struct radv_device *device,
                               int idx,
@@ -1320,8 +1305,8 @@ radv_device_init_meta_blit2d_state(struct radv_device *device)
                        if (result != VK_SUCCESS)
                                goto fail;
 
-                       for (unsigned j = 0; j < ARRAY_SIZE(pipeline_formats); ++j) {
-                               result = blit2d_init_color_pipeline(device, src, pipeline_formats[j], log2_samples);
+                       for (unsigned j = 0; j < NUM_META_FS_KEYS; ++j) {
+                               result = blit2d_init_color_pipeline(device, src, radv_fs_key_format_exemplars[j], log2_samples);
                                if (result != VK_SUCCESS)
                                        goto fail;
                        }
index d7c984973431b06707c9eb2199b231adb35d29d6..4f77e32b83fedc83d9e8f5bb352c983224a8c9d2 100644 (file)
@@ -757,21 +757,6 @@ fail:
        return false;
 }
 
-static VkFormat pipeline_formats[] = {
-       VK_FORMAT_R8G8B8A8_UNORM,
-       VK_FORMAT_R8G8B8A8_UINT,
-       VK_FORMAT_R8G8B8A8_SINT,
-       VK_FORMAT_A2R10G10B10_UINT_PACK32,
-       VK_FORMAT_A2R10G10B10_SINT_PACK32,
-       VK_FORMAT_R16G16B16A16_UNORM,
-       VK_FORMAT_R16G16B16A16_SNORM,
-       VK_FORMAT_R16G16B16A16_UINT,
-       VK_FORMAT_R16G16B16A16_SINT,
-       VK_FORMAT_R32_SFLOAT,
-       VK_FORMAT_R32G32_SFLOAT,
-       VK_FORMAT_R32G32B32A32_SFLOAT
-};
-
 VkResult
 radv_device_init_meta_clear_state(struct radv_device *device)
 {
@@ -808,8 +793,8 @@ radv_device_init_meta_clear_state(struct radv_device *device)
 
        for (uint32_t i = 0; i < ARRAY_SIZE(state->clear); ++i) {
                uint32_t samples = 1 << i;
-               for (uint32_t j = 0; j < ARRAY_SIZE(pipeline_formats); ++j) {
-                       VkFormat format = pipeline_formats[j];
+               for (uint32_t j = 0; j < NUM_META_FS_KEYS; ++j) {
+                       VkFormat format = radv_fs_key_format_exemplars[j];
                        unsigned fs_key = radv_format_meta_fs_key(format);
                        assert(!state->clear[i].color_pipelines[fs_key]);
 
index b049237ba658d48f7f028058e2245976519cc8c9..30fed97441478ceebfc597b429d39721a15e72c1 100644 (file)
@@ -251,21 +251,6 @@ radv_device_finish_meta_resolve_state(struct radv_device *device)
 
 }
 
-static VkFormat pipeline_formats[] = {
-       VK_FORMAT_R8G8B8A8_UNORM,
-       VK_FORMAT_R8G8B8A8_UINT,
-       VK_FORMAT_R8G8B8A8_SINT,
-       VK_FORMAT_A2R10G10B10_UINT_PACK32,
-       VK_FORMAT_A2R10G10B10_SINT_PACK32,
-       VK_FORMAT_R16G16B16A16_UNORM,
-       VK_FORMAT_R16G16B16A16_SNORM,
-       VK_FORMAT_R16G16B16A16_UINT,
-       VK_FORMAT_R16G16B16A16_SINT,
-       VK_FORMAT_R32_SFLOAT,
-       VK_FORMAT_R32G32_SFLOAT,
-       VK_FORMAT_R32G32B32A32_SFLOAT
-};
-
 VkResult
 radv_device_init_meta_resolve_state(struct radv_device *device)
 {
@@ -278,8 +263,8 @@ radv_device_init_meta_resolve_state(struct radv_device *device)
                goto fail;
        }
 
-       for (uint32_t i = 0; i < ARRAY_SIZE(pipeline_formats); ++i) {
-               VkFormat format = pipeline_formats[i];
+       for (uint32_t i = 0; i < NUM_META_FS_KEYS; ++i) {
+               VkFormat format = radv_fs_key_format_exemplars[i];
                unsigned fs_key = radv_format_meta_fs_key(format);
                res = create_pass(device, format, &state->resolve.pass[fs_key]);
                if (res != VK_SUCCESS)
index 76f00bfb5e39e04f768ff191ed9ec178625d7daa..6013503b837b9a9d3dabc8bf8cff97b7e6a0589f 100644 (file)
@@ -156,21 +156,6 @@ static const VkPipelineVertexInputStateCreateInfo normal_vi_create_info = {
        .vertexAttributeDescriptionCount = 0,
 };
 
-static VkFormat pipeline_formats[] = {
-   VK_FORMAT_R8G8B8A8_UNORM,
-   VK_FORMAT_R8G8B8A8_UINT,
-   VK_FORMAT_R8G8B8A8_SINT,
-   VK_FORMAT_A2R10G10B10_UINT_PACK32,
-   VK_FORMAT_A2R10G10B10_SINT_PACK32,
-   VK_FORMAT_R16G16B16A16_UNORM,
-   VK_FORMAT_R16G16B16A16_SNORM,
-   VK_FORMAT_R16G16B16A16_UINT,
-   VK_FORMAT_R16G16B16A16_SINT,
-   VK_FORMAT_R32_SFLOAT,
-   VK_FORMAT_R32G32_SFLOAT,
-   VK_FORMAT_R32G32B32A32_SFLOAT
-};
-
 static VkResult
 create_resolve_pipeline(struct radv_device *device,
                        int samples_log2,
@@ -335,8 +320,8 @@ radv_device_init_meta_resolve_fragment_state(struct radv_device *device)
                goto fail;
 
        for (uint32_t i = 0; i < MAX_SAMPLES_LOG2; ++i) {
-               for (unsigned j = 0; j < ARRAY_SIZE(pipeline_formats); ++j) {
-                       res = create_resolve_pipeline(device, i, pipeline_formats[j]);
+               for (unsigned j = 0; j < NUM_META_FS_KEYS; ++j) {
+                       res = create_resolve_pipeline(device, i, radv_fs_key_format_exemplars[j]);
                        if (res != VK_SUCCESS)
                                goto fail;
                }
index eb58e8a1c0ac81d333f3f9e2a5e1b34e5839aa36..e63c481d1e74454b6b7a591d82a0d837fd21e795 100644 (file)
@@ -565,9 +565,34 @@ format_is_int10(VkFormat format)
        return false;
 }
 
+/*
+ * Ordered so that for each i,
+ * radv_format_meta_fs_key(radv_fs_key_format_exemplars[i]) == i.
+ */
+const VkFormat radv_fs_key_format_exemplars[NUM_META_FS_KEYS] = {
+       VK_FORMAT_R32_SFLOAT,
+       VK_FORMAT_R32G32_SFLOAT,
+       VK_FORMAT_R8G8B8A8_UNORM,
+       VK_FORMAT_R16G16B16A16_UNORM,
+       VK_FORMAT_R16G16B16A16_SNORM,
+       VK_FORMAT_R16G16B16A16_UINT,
+       VK_FORMAT_R16G16B16A16_SINT,
+       VK_FORMAT_R32G32B32A32_SFLOAT,
+       VK_FORMAT_R8G8B8A8_UINT,
+       VK_FORMAT_R8G8B8A8_SINT,
+       VK_FORMAT_A2R10G10B10_UINT_PACK32,
+       VK_FORMAT_A2R10G10B10_SINT_PACK32,
+};
+
 unsigned radv_format_meta_fs_key(VkFormat format)
 {
-       unsigned col_format = si_choose_spi_color_format(format, false, false) - 1;
+       unsigned col_format = si_choose_spi_color_format(format, false, false);
+
+       assert(col_format != V_028714_SPI_SHADER_32_AR);
+       if (col_format >= V_028714_SPI_SHADER_32_AR)
+               --col_format; /* Skip V_028714_SPI_SHADER_32_AR  since there is no such VkFormat */
+
+       --col_format; /* Skip V_028714_SPI_SHADER_ZERO */
        bool is_int8 = format_is_int8(format);
        bool is_int10 = format_is_int10(format);
 
index a187f76be491a65c5cd534afa80ffb7308aaaa2e..9374b730b5256475dfc7dbdaa99dd2ae919ed5a5 100644 (file)
@@ -96,7 +96,7 @@ typedef uint32_t xcb_window_t;
 #define MAX_DYNAMIC_STORAGE_BUFFERS 8
 #define MAX_DYNAMIC_BUFFERS (MAX_DYNAMIC_UNIFORM_BUFFERS + MAX_DYNAMIC_STORAGE_BUFFERS)
 #define MAX_SAMPLES_LOG2 4
-#define NUM_META_FS_KEYS 13
+#define NUM_META_FS_KEYS 12
 #define RADV_MAX_DRM_DEVICES 8
 #define MAX_VIEWS        8
 
@@ -1242,6 +1242,7 @@ mesa_to_vk_shader_stage(gl_shader_stage mesa_stage)
             stage = __builtin_ffs(__tmp) - 1, __tmp;                   \
             __tmp &= ~(1 << (stage)))
 
+extern const VkFormat radv_fs_key_format_exemplars[NUM_META_FS_KEYS];
 unsigned radv_format_meta_fs_key(VkFormat format);
 
 struct radv_multisample_state {