anv: Populate SURFACE_STATE more safely
authorChad Versace <chad.versace@intel.com>
Fri, 15 Jan 2016 18:54:05 +0000 (10:54 -0800)
committerChad Versace <chad.versace@intel.com>
Fri, 15 Jan 2016 19:00:22 +0000 (11:00 -0800)
genX_image_view_init allocates up to 3 separate SURFACE_STATE structures,
and populates each from a single template. Stop mutating the template
between each final SURFACE_STATE.

src/vulkan/gen7_state.c
src/vulkan/gen8_state.c

index 09c1332e450cb878807ac8f59766500ff25bcb19..b24e484262afc977b5c0394a74b1462b31b9af67 100644 (file)
@@ -173,7 +173,7 @@ genX(image_view_init)(struct anv_image_view *iview,
    const struct isl_extent3d image_align_sa =
       isl_surf_get_image_alignment_sa(&surface->isl);
 
-   struct GENX(RENDER_SURFACE_STATE) surface_state = {
+   const struct GENX(RENDER_SURFACE_STATE) template = {
       .SurfaceType = anv_surftype(image, pCreateInfo->viewType, false),
       .SurfaceArray = image->array_size > 1,
       .SurfaceFormat = iview->format,
@@ -227,6 +227,8 @@ genX(image_view_init)(struct anv_image_view *iview,
    };
 
    if (image->needs_nonrt_surface_state) {
+      struct GENX(RENDER_SURFACE_STATE) surface_state = template;
+
       iview->nonrt_surface_state = alloc_surface_state(device, cmd_buffer);
 
       surface_state.RenderCacheReadWriteMode = false;
@@ -248,6 +250,8 @@ genX(image_view_init)(struct anv_image_view *iview,
    }
 
    if (image->needs_color_rt_surface_state) {
+      struct GENX(RENDER_SURFACE_STATE) surface_state = template;
+
       iview->color_rt_surface_state = alloc_surface_state(device, cmd_buffer);
 
       surface_state.RenderCacheReadWriteMode = 0; /* Write only */
@@ -270,6 +274,8 @@ genX(image_view_init)(struct anv_image_view *iview,
    }
 
    if (image->needs_storage_surface_state) {
+      struct GENX(RENDER_SURFACE_STATE) surface_state = template;
+
       iview->storage_surface_state = alloc_surface_state(device, cmd_buffer);
 
       surface_state.SurfaceType =
index b6741e005d3967070f4b26184dfa4515decd0436..9fa2a0554b91015494430be03025812fb8b381e9 100644 (file)
@@ -187,7 +187,7 @@ genX(image_view_init)(struct anv_image_view *iview,
    uint32_t halign, valign;
    get_halign_valign(&surface->isl, &halign, &valign);
 
-   struct GENX(RENDER_SURFACE_STATE) surface_state = {
+   struct GENX(RENDER_SURFACE_STATE) template = {
       .SurfaceType = anv_surftype(image, pCreateInfo->viewType, false),
       .SurfaceArray = image->array_size > 1,
       .SurfaceFormat = iview->format,
@@ -237,10 +237,10 @@ genX(image_view_init)(struct anv_image_view *iview,
       .SurfaceBaseAddress = { NULL, iview->offset },
    };
 
-   switch (surface_state.SurfaceType) {
+   switch (template.SurfaceType) {
    case SURFTYPE_1D:
    case SURFTYPE_2D:
-      surface_state.MinimumArrayElement = range->baseArrayLayer;
+      template.MinimumArrayElement = range->baseArrayLayer;
 
       /* From the Broadwell PRM >> RENDER_SURFACE_STATE::Depth:
        *
@@ -251,37 +251,37 @@ genX(image_view_init)(struct anv_image_view *iview,
        *
        * In other words, 'Depth' is the number of array layers.
        */
-      surface_state.Depth = range->layerCount - 1;
+      template.Depth = range->layerCount - 1;
 
       /* From the Broadwell PRM >> RENDER_SURFACE_STATE::RenderTargetViewExtent:
        *
        *    For Render Target and Typed Dataport 1D and 2D Surfaces:
        *    This field must be set to the same value as the Depth field.
        */
-      surface_state.RenderTargetViewExtent = surface_state.Depth;
+      template.RenderTargetViewExtent = template.Depth;
       break;
    case SURFTYPE_CUBE:
       #if ANV_GENx10 >= 90
          /* Like SURFTYPE_2D, but divided by 6. */
-         surface_state.MinimumArrayElement = range->baseArrayLayer / 6;
-         surface_state.Depth = range->layerCount / 6 - 1;
-         surface_state.RenderTargetViewExtent = surface_state.Depth;
+         template.MinimumArrayElement = range->baseArrayLayer / 6;
+         template.Depth = range->layerCount / 6 - 1;
+         template.RenderTargetViewExtent = template.Depth;
       #else
          /* Same as SURFTYPE_2D */
-         surface_state.MinimumArrayElement = range->baseArrayLayer;
-         surface_state.Depth = range->layerCount - 1;
-         surface_state.RenderTargetViewExtent = surface_state.Depth;
+         template.MinimumArrayElement = range->baseArrayLayer;
+         template.Depth = range->layerCount - 1;
+         template.RenderTargetViewExtent = template.Depth;
       #endif
       break;
    case SURFTYPE_3D:
-      surface_state.MinimumArrayElement = range->baseArrayLayer;
+      template.MinimumArrayElement = range->baseArrayLayer;
 
       /* From the Broadwell PRM >> RENDER_SURFACE_STATE::Depth:
        *
        *    If the volume texture is MIP-mapped, this field specifies the
        *    depth of the base MIP level.
        */
-      surface_state.Depth = image->extent.depth - 1;
+      template.Depth = image->extent.depth - 1;
 
       /* From the Broadwell PRM >> RENDER_SURFACE_STATE::RenderTargetViewExtent:
        *
@@ -289,13 +289,15 @@ genX(image_view_init)(struct anv_image_view *iview,
        *    indicates the extent of the accessible 'R' coordinates minus 1 on
        *    the LOD currently being rendered to.
        */
-      surface_state.RenderTargetViewExtent = iview->extent.depth - 1;
+      template.RenderTargetViewExtent = iview->extent.depth - 1;
       break;
    default:
       unreachable(!"bad SurfaceType");
    }
 
    if (image->needs_nonrt_surface_state) {
+      struct GENX(RENDER_SURFACE_STATE) surface_state = template;
+
       iview->nonrt_surface_state =
          alloc_surface_state(device, cmd_buffer);
 
@@ -315,6 +317,8 @@ genX(image_view_init)(struct anv_image_view *iview,
    }
 
    if (image->needs_color_rt_surface_state) {
+      struct GENX(RENDER_SURFACE_STATE) surface_state = template;
+
       iview->color_rt_surface_state =
          alloc_surface_state(device, cmd_buffer);
 
@@ -336,6 +340,8 @@ genX(image_view_init)(struct anv_image_view *iview,
    }
 
    if (image->needs_storage_surface_state) {
+      struct GENX(RENDER_SURFACE_STATE) surface_state = template;
+
       iview->storage_surface_state =
          alloc_surface_state(device, cmd_buffer);