isl: make format layout channels accessible by index
[mesa.git] / src / intel / isl / isl_surface_state.c
index 1620c93cef107e22edaf45e5bd6f6da10a7945cd..bfb27fa4a44f758ad2b5835f18b7f489988ddf8b 100644 (file)
@@ -26,7 +26,7 @@
 #define __gen_address_type uint64_t
 #define __gen_user_data void
 
-static inline uint64_t
+static uint64_t
 __gen_combine_address(void *data, void *loc, uint64_t addr, uint32_t delta)
 {
    return addr + delta;
@@ -37,10 +37,6 @@ __gen_combine_address(void *data, void *loc, uint64_t addr, uint32_t delta)
 
 #include "isl_priv.h"
 
-#define __PASTE2(x, y) x ## y
-#define __PASTE(x, y) __PASTE2(x, y)
-#define isl_genX(x) __PASTE(isl_, genX(x))
-
 #if GEN_GEN >= 8
 static const uint8_t isl_to_gen_halign[] = {
     [4] = HALIGN4,
@@ -134,7 +130,7 @@ get_surftype(enum isl_surf_dim dim, isl_surf_usage_flags_t usage)
  * hardware.  Note that this does NOT give you the actual hardware enum values
  * but an index into the isl_to_gen_[hv]align arrays above.
  */
-static inline struct isl_extent3d
+UNUSED static struct isl_extent3d
 get_image_alignment(const struct isl_surf *surf)
 {
    if (GEN_GEN >= 9) {
@@ -254,7 +250,25 @@ isl_genX(surf_fill_state_s)(const struct isl_device *dev, void *state,
    if (info->surf->dim == ISL_SURF_DIM_1D)
       assert(!isl_format_is_compressed(info->view->format));
 
-   s.SurfaceFormat = info->view->format;
+   if (isl_format_is_compressed(info->surf->format)) {
+      /* You're not allowed to make a view of a compressed format with any
+       * format other than the surface format.  None of the userspace APIs
+       * allow for this directly and doing so would mess up a number of
+       * surface parameters such as Width, Height, and alignments.  Ideally,
+       * we'd like to assert that the two formats match.  However, we have an
+       * S3TC workaround that requires us to do reinterpretation.  So assert
+       * that they're at least the same bpb and block size.
+       */
+      MAYBE_UNUSED const struct isl_format_layout *surf_fmtl =
+         isl_format_get_layout(info->surf->format);
+      MAYBE_UNUSED const struct isl_format_layout *view_fmtl =
+         isl_format_get_layout(info->surf->format);
+      assert(surf_fmtl->bpb == view_fmtl->bpb);
+      assert(surf_fmtl->bw == view_fmtl->bw);
+      assert(surf_fmtl->bh == view_fmtl->bh);
+   }
+
+   s.SurfaceFormat = (enum GENX(SURFACE_FORMAT)) info->view->format;
 
 #if GEN_GEN <= 5
    s.ColorBufferComponentWriteDisables = info->write_disables;
@@ -263,7 +277,8 @@ isl_genX(surf_fill_state_s)(const struct isl_device *dev, void *state,
 #endif
 
 #if GEN_IS_HASWELL
-   s.IntegerSurfaceFormat = isl_format_has_int_channel(s.SurfaceFormat);
+   s.IntegerSurfaceFormat =
+      isl_format_has_int_channel((enum isl_format) s.SurfaceFormat);
 #endif
 
    assert(info->surf->logical_level0_px.width > 0 &&
@@ -437,18 +452,12 @@ isl_genX(surf_fill_state_s)(const struct isl_device *dev, void *state,
    s.RenderCacheReadWriteMode = 0;
 #endif
 
-   if (info->view->usage & ISL_SURF_USAGE_CUBE_BIT) {
-#if GEN_GEN >= 8
-      s.CubeFaceEnablePositiveZ = 1;
-      s.CubeFaceEnableNegativeZ = 1;
-      s.CubeFaceEnablePositiveY = 1;
-      s.CubeFaceEnableNegativeY = 1;
-      s.CubeFaceEnablePositiveX = 1;
-      s.CubeFaceEnableNegativeX = 1;
-#else
-      s.CubeFaceEnables = 0x3f;
-#endif
-   }
+   s.CubeFaceEnablePositiveZ = 1;
+   s.CubeFaceEnableNegativeZ = 1;
+   s.CubeFaceEnablePositiveY = 1;
+   s.CubeFaceEnableNegativeY = 1;
+   s.CubeFaceEnablePositiveX = 1;
+   s.CubeFaceEnableNegativeX = 1;
 
 #if GEN_GEN >= 6
    s.NumberofMultisamples = ffs(info->surf->samples) - 1;
@@ -491,10 +500,10 @@ isl_genX(surf_fill_state_s)(const struct isl_device *dev, void *state,
        */
       assert(info->view->swizzle.a == ISL_CHANNEL_SELECT_ALPHA);
    }
-   s.ShaderChannelSelectRed = info->view->swizzle.r;
-   s.ShaderChannelSelectGreen = info->view->swizzle.g;
-   s.ShaderChannelSelectBlue = info->view->swizzle.b;
-   s.ShaderChannelSelectAlpha = info->view->swizzle.a;
+   s.ShaderChannelSelectRed = (enum GENX(ShaderChannelSelect)) info->view->swizzle.r;
+   s.ShaderChannelSelectGreen = (enum GENX(ShaderChannelSelect)) info->view->swizzle.g;
+   s.ShaderChannelSelectBlue = (enum GENX(ShaderChannelSelect)) info->view->swizzle.b;
+   s.ShaderChannelSelectAlpha = (enum GENX(ShaderChannelSelect)) info->view->swizzle.a;
 #endif
 
    s.SurfaceBaseAddress = info->address;
@@ -687,7 +696,7 @@ isl_genX(buffer_fill_state_s)(void *state,
    struct GENX(RENDER_SURFACE_STATE) s = { 0, };
 
    s.SurfaceType = SURFTYPE_BUFFER;
-   s.SurfaceFormat = info->format;
+   s.SurfaceFormat = (enum GENX(SURFACE_FORMAT)) info->format;
 
 #if GEN_GEN >= 6
    s.SurfaceVerticalAlignment = isl_to_gen_valign[4];
@@ -739,3 +748,29 @@ isl_genX(buffer_fill_state_s)(void *state,
 
    GENX(RENDER_SURFACE_STATE_pack)(NULL, state, &s);
 }
+
+void
+isl_genX(null_fill_state)(void *state, struct isl_extent3d size)
+{
+   struct GENX(RENDER_SURFACE_STATE) s = {
+      .SurfaceType = SURFTYPE_NULL,
+      .SurfaceFormat = (enum GENX(SURFACE_FORMAT)) ISL_FORMAT_B8G8R8A8_UNORM,
+#if GEN_GEN >= 7
+      .SurfaceArray = size.depth > 0,
+#endif
+#if GEN_GEN >= 8
+      .TileMode = YMAJOR,
+#else
+      .TiledSurface = true,
+      .TileWalk = TILEWALK_YMAJOR,
+#endif
+      .Width = size.width - 1,
+      .Height = size.height - 1,
+      .Depth = size.depth - 1,
+      .RenderTargetViewExtent = size.depth - 1,
+#if GEN_GEN <= 5
+      .ColorBufferComponentWriteDisables = 0xf,
+#endif
+   };
+   GENX(RENDER_SURFACE_STATE_pack)(NULL, state, &s);
+}