[Mesa-dev] [PATCH] nv50: Dont illegally change format after surface_create() call

Edward O'Callaghan eocallaghan at alterapraxis.com
Sun Mar 27 02:59:31 UTC 2016


This was the wrong way to force a resource format, fix it in nv50.

NOTE: Needs testing from someone with nv hw.

Signed-off-by: Edward O'Callaghan <eocallaghan at alterapraxis.com>
---
 src/gallium/drivers/nouveau/nv50/nv50_surface.c | 67 ++++++++++++-------------
 1 file changed, 33 insertions(+), 34 deletions(-)

diff --git a/src/gallium/drivers/nouveau/nv50/nv50_surface.c b/src/gallium/drivers/nouveau/nv50/nv50_surface.c
index 68b0e18..c3e97cc 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_surface.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_surface.c
@@ -447,11 +447,43 @@ nv50_clear_texture(struct pipe_context *pipe,
                    const void *data)
 {
    struct pipe_surface tmpl = {{0}}, *sf;
+   union pipe_color_union color;
+
+   switch (util_format_get_blocksizebits(res->format)) {
+   case 128:
+      tmpl.format = PIPE_FORMAT_R32G32B32A32_UINT;
+      memcpy(&color.ui, data, 128 / 8);
+      break;
+   case 64:
+      tmpl.format = PIPE_FORMAT_R32G32_UINT;
+      memcpy(&color.ui, data, 64 / 8);
+      memset(&color.ui[2], 0, 64 / 8);
+      break;
+   case 32:
+      tmpl.format = PIPE_FORMAT_R32_UINT;
+      memcpy(&color.ui, data, 32 / 8);
+      memset(&color.ui[1], 0, 96 / 8);
+      break;
+   case 16:
+      tmpl.format = PIPE_FORMAT_R16_UINT;
+      color.ui[0] = util_cpu_to_le32(
+         util_le16_to_cpu(*(unsigned short *)data));
+      memset(&color.ui[1], 0, 96 / 8);
+      break;
+   case 8:
+      tmpl.format = PIPE_FORMAT_R8_UINT;
+      color.ui[0] = util_cpu_to_le32(*(unsigned char *)data);
+      memset(&color.ui[1], 0, 96 / 8);
+      break;
+   default:
+      assert(!"Unknown texel element size");
+      return;
+   }
 
-   tmpl.format = res->format;
    tmpl.u.tex.first_layer = box->z;
    tmpl.u.tex.last_layer = box->z + box->depth - 1;
    tmpl.u.tex.level = level;
+
    sf = pipe->create_surface(pipe, res, &tmpl);
    if (!sf)
       return;
@@ -474,39 +506,6 @@ nv50_clear_texture(struct pipe_context *pipe,
       pipe->clear_depth_stencil(pipe, sf, clear, depth, stencil,
                                 box->x, box->y, box->width, box->height);
    } else {
-      union pipe_color_union color;
-
-      switch (util_format_get_blocksizebits(res->format)) {
-      case 128:
-         sf->format = PIPE_FORMAT_R32G32B32A32_UINT;
-         memcpy(&color.ui, data, 128 / 8);
-         break;
-      case 64:
-         sf->format = PIPE_FORMAT_R32G32_UINT;
-         memcpy(&color.ui, data, 64 / 8);
-         memset(&color.ui[2], 0, 64 / 8);
-         break;
-      case 32:
-         sf->format = PIPE_FORMAT_R32_UINT;
-         memcpy(&color.ui, data, 32 / 8);
-         memset(&color.ui[1], 0, 96 / 8);
-         break;
-      case 16:
-         sf->format = PIPE_FORMAT_R16_UINT;
-         color.ui[0] = util_cpu_to_le32(
-            util_le16_to_cpu(*(unsigned short *)data));
-         memset(&color.ui[1], 0, 96 / 8);
-         break;
-      case 8:
-         sf->format = PIPE_FORMAT_R8_UINT;
-         color.ui[0] = util_cpu_to_le32(*(unsigned char *)data);
-         memset(&color.ui[1], 0, 96 / 8);
-         break;
-      default:
-         assert(!"Unknown texel element size");
-         return;
-      }
-
       pipe->clear_render_target(pipe, sf, &color,
                                 box->x, box->y, box->width, box->height);
    }
-- 
2.5.5



More information about the mesa-dev mailing list