tu: Implement extendedDynamicState3SampleLocationsEnable
authorConnor Abbott <cwabbott0@gmail.com>
Fri, 30 Sep 2022 14:21:11 +0000 (16:21 +0200)
committerMarge Bot <emma+marge@anholt.net>
Thu, 3 Nov 2022 21:59:42 +0000 (21:59 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18912>

src/freedreno/vulkan/tu_cmd_buffer.c
src/freedreno/vulkan/tu_device.c
src/freedreno/vulkan/tu_pipeline.c
src/freedreno/vulkan/tu_pipeline.h

index 70e19f34cc9f3b31e5c1140fdd8f5126511cfd9d..2b2fcd602437c4624035d88d91eaa7ba4f281527 100644 (file)
@@ -2874,13 +2874,24 @@ tu_CmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,
                             const VkSampleLocationsInfoEXT* pSampleLocationsInfo)
 {
    TU_FROM_HANDLE(tu_cmd_buffer, cmd, commandBuffer);
-   struct tu_cs cs = tu_cmd_dynamic_state(cmd, TU_DYNAMIC_STATE_SAMPLE_LOCATIONS, 9);
+   struct tu_cs cs = tu_cmd_dynamic_state(cmd, TU_DYNAMIC_STATE_SAMPLE_LOCATIONS, 6);
 
    assert(pSampleLocationsInfo);
 
    tu6_emit_sample_locations(&cs, pSampleLocationsInfo);
 }
 
+VKAPI_ATTR void VKAPI_CALL
+tu_CmdSetSampleLocationsEnableEXT(VkCommandBuffer commandBuffer,
+                                  VkBool32 sampleLocationsEnable)
+{
+   TU_FROM_HANDLE(tu_cmd_buffer, cmd, commandBuffer);
+
+   struct tu_cs cs = tu_cmd_dynamic_state(cmd, TU_DYNAMIC_STATE_SAMPLE_LOCATIONS_ENABLE, 6);
+
+   tu6_emit_sample_locations_enable(&cs, sampleLocationsEnable);
+}
+
 VKAPI_ATTR void VKAPI_CALL
 tu_CmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode)
 {
index 4739b0389c7f33c135bd1ab7f795e76030e5e0f0..dffd9f8173a79d0cf762b042715b0ac2ab4233e1 100644 (file)
@@ -777,7 +777,7 @@ tu_GetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice,
          features->extendedDynamicState3LineRasterizationMode = true;
          features->extendedDynamicState3LineStippleEnable = false;
          features->extendedDynamicState3ProvokingVertexMode = true;
-         features->extendedDynamicState3SampleLocationsEnable = false;
+         features->extendedDynamicState3SampleLocationsEnable = true;
          features->extendedDynamicState3ColorBlendEnable = false;
          features->extendedDynamicState3ColorBlendEquation = false;
          features->extendedDynamicState3ColorWriteMask = false;
index bcd0470e3347b6908e3a9feba49a39d30fa68bdc..236850cb1bfcb9724fd49b401542dc96d33d6e89 100644 (file)
@@ -2139,26 +2139,28 @@ tu6_emit_scissor(struct tu_cs *cs, const VkRect2D *scissors, uint32_t scissor_co
 }
 
 void
-tu6_emit_sample_locations(struct tu_cs *cs, const VkSampleLocationsInfoEXT *samp_loc)
+tu6_emit_sample_locations_enable(struct tu_cs *cs, bool enable)
 {
-   if (!samp_loc) {
-      tu_cs_emit_pkt4(cs, REG_A6XX_GRAS_SAMPLE_CONFIG, 1);
-      tu_cs_emit(cs, 0);
+   uint32_t sample_config =
+      COND(enable, A6XX_RB_SAMPLE_CONFIG_LOCATION_ENABLE);
 
-      tu_cs_emit_pkt4(cs, REG_A6XX_RB_SAMPLE_CONFIG, 1);
-      tu_cs_emit(cs, 0);
+   tu_cs_emit_pkt4(cs, REG_A6XX_GRAS_SAMPLE_CONFIG, 1);
+   tu_cs_emit(cs, sample_config);
 
-      tu_cs_emit_pkt4(cs, REG_A6XX_SP_TP_SAMPLE_CONFIG, 1);
-      tu_cs_emit(cs, 0);
-      return;
-   }
+   tu_cs_emit_pkt4(cs, REG_A6XX_RB_SAMPLE_CONFIG, 1);
+   tu_cs_emit(cs, sample_config);
+
+   tu_cs_emit_pkt4(cs, REG_A6XX_SP_TP_SAMPLE_CONFIG, 1);
+   tu_cs_emit(cs, sample_config);
+}
 
+void
+tu6_emit_sample_locations(struct tu_cs *cs, const VkSampleLocationsInfoEXT *samp_loc)
+{
    assert(samp_loc->sampleLocationsPerPixel == samp_loc->sampleLocationsCount);
    assert(samp_loc->sampleLocationGridSize.width == 1);
    assert(samp_loc->sampleLocationGridSize.height == 1);
 
-   uint32_t sample_config =
-      A6XX_RB_SAMPLE_CONFIG_LOCATION_ENABLE;
    uint32_t sample_locations = 0;
    for (uint32_t i = 0; i < samp_loc->sampleLocationsCount; i++) {
       /* From VkSampleLocationEXT:
@@ -2178,16 +2180,13 @@ tu6_emit_sample_locations(struct tu_cs *cs, const VkSampleLocationsInfoEXT *samp
           A6XX_RB_SAMPLE_LOCATION_0_SAMPLE_0_Y(y)) << i*8;
    }
 
-   tu_cs_emit_pkt4(cs, REG_A6XX_GRAS_SAMPLE_CONFIG, 2);
-   tu_cs_emit(cs, sample_config);
+   tu_cs_emit_pkt4(cs, REG_A6XX_GRAS_SAMPLE_LOCATION_0, 1);
    tu_cs_emit(cs, sample_locations);
 
-   tu_cs_emit_pkt4(cs, REG_A6XX_RB_SAMPLE_CONFIG, 2);
-   tu_cs_emit(cs, sample_config);
+   tu_cs_emit_pkt4(cs, REG_A6XX_RB_SAMPLE_LOCATION_0, 1);
    tu_cs_emit(cs, sample_locations);
 
-   tu_cs_emit_pkt4(cs, REG_A6XX_SP_TP_SAMPLE_CONFIG, 2);
-   tu_cs_emit(cs, sample_config);
+   tu_cs_emit_pkt4(cs, REG_A6XX_SP_TP_SAMPLE_LOCATION_0, 1);
    tu_cs_emit(cs, sample_locations);
 }
 
@@ -3625,6 +3624,9 @@ tu_pipeline_builder_parse_dynamic(struct tu_pipeline_builder *builder,
       case VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT:
          pipeline->dynamic_state_mask |= BIT(TU_DYNAMIC_STATE_SAMPLE_LOCATIONS);
          break;
+      case VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_ENABLE_EXT:
+         pipeline->dynamic_state_mask |= BIT(TU_DYNAMIC_STATE_SAMPLE_LOCATIONS_ENABLE);
+         break;
       case VK_DYNAMIC_STATE_CULL_MODE:
          pipeline->rast.gras_su_cntl_mask &=
             ~(A6XX_GRAS_SU_CNTL_CULL_BACK | A6XX_GRAS_SU_CNTL_CULL_FRONT);
@@ -3900,6 +3902,7 @@ tu_pipeline_builder_parse_libraries(struct tu_pipeline_builder *builder,
          library_dynamic_state |=
             BIT(VK_DYNAMIC_STATE_BLEND_CONSTANTS) |
             BIT(TU_DYNAMIC_STATE_SAMPLE_LOCATIONS) |
+            BIT(TU_DYNAMIC_STATE_SAMPLE_LOCATIONS_ENABLE) |
             BIT(TU_DYNAMIC_STATE_BLEND) |
             BIT(TU_DYNAMIC_STATE_LOGIC_OP) |
             BIT(TU_DYNAMIC_STATE_LOGIC_OP_ENABLE) |
@@ -4608,13 +4611,23 @@ tu_pipeline_builder_parse_multisample_and_color_blend(
       vk_find_struct_const(msaa_info->pNext, PIPELINE_SAMPLE_LOCATIONS_STATE_CREATE_INFO_EXT);
    const VkSampleLocationsInfoEXT *samp_loc = NULL;
 
-   if (sample_locations && sample_locations->sampleLocationsEnable)
+   if (sample_locations)
       samp_loc = &sample_locations->sampleLocationsInfo;
 
-    if (tu_pipeline_static_state(pipeline, &cs, TU_DYNAMIC_STATE_SAMPLE_LOCATIONS,
-                                 samp_loc ? 9 : 6)) {
+    bool samp_loc_enable = sample_locations &&
+       sample_locations->sampleLocationsEnable;
+
+    if (samp_loc &&
+        ((pipeline->dynamic_state_mask & BIT(TU_DYNAMIC_STATE_SAMPLE_LOCATIONS_ENABLE)) ||
+         samp_loc_enable) &&
+        tu_pipeline_static_state(pipeline, &cs, TU_DYNAMIC_STATE_SAMPLE_LOCATIONS, 6)) {
       tu6_emit_sample_locations(&cs, samp_loc);
     }
+
+    if (tu_pipeline_static_state(pipeline, &cs,
+                                 TU_DYNAMIC_STATE_SAMPLE_LOCATIONS_ENABLE, 6)) {
+       tu6_emit_sample_locations_enable(&cs, samp_loc_enable);
+    }
 }
 
 static void
index 699f7c073292e3c042ad88731d0ff39ee9e930d1..df09186e3eeedc297495bdbc26ada9e9cba89bc3 100644 (file)
@@ -21,6 +21,7 @@ enum tu_dynamic_state
 {
    /* re-use VK_DYNAMIC_STATE_ enums for non-extended dynamic states */
    TU_DYNAMIC_STATE_SAMPLE_LOCATIONS = VK_DYNAMIC_STATE_STENCIL_REFERENCE + 1,
+   TU_DYNAMIC_STATE_SAMPLE_LOCATIONS_ENABLE,
    TU_DYNAMIC_STATE_RB_DEPTH_CNTL,
    TU_DYNAMIC_STATE_RB_STENCIL_CNTL,
    TU_DYNAMIC_STATE_VB_STRIDE,
@@ -295,6 +296,9 @@ tu6_emit_scissor(struct tu_cs *cs, const VkRect2D *scs, uint32_t scissor_count);
 void
 tu6_emit_sample_locations(struct tu_cs *cs, const VkSampleLocationsInfoEXT *samp_loc);
 
+void
+tu6_emit_sample_locations_enable(struct tu_cs *cs, bool enable);
+
 void
 tu6_emit_depth_bias(struct tu_cs *cs,
                     float constant_factor,