Merge branch '7.8'
[mesa.git] / src / gallium / drivers / nv50 / nv50_surface.c
index b266324f58d7d40b30278c6acd625e0ad41d4ef3..6467c48a32a55f80340dc8b7f11d61bdc00a3bdd 100644 (file)
 #include "nouveau/nouveau_pushbuf.h"
 #include "nv50_context.h"
 #include "pipe/p_defines.h"
-#include "pipe/internal/p_winsys_screen.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
 
 #include "util/u_tile.h"
+#include "util/u_format.h"
 
 static INLINE int
 nv50_format(enum pipe_format format)
 {
        switch (format) {
-       case PIPE_FORMAT_A8R8G8B8_UNORM:
+       case PIPE_FORMAT_B8G8R8A8_UNORM:
                return NV50_2D_DST_FORMAT_A8R8G8B8_UNORM;
-       case PIPE_FORMAT_X8R8G8B8_UNORM:
+       case PIPE_FORMAT_B8G8R8X8_UNORM:
                return NV50_2D_DST_FORMAT_X8R8G8B8_UNORM;
-       case PIPE_FORMAT_R5G6B5_UNORM:
+       case PIPE_FORMAT_B8G8R8A8_SRGB:
+               return NV50_2D_DST_FORMAT_A8R8G8B8_SRGB;
+       case PIPE_FORMAT_B8G8R8X8_SRGB:
+               return NV50_2D_DST_FORMAT_X8R8G8B8_SRGB;
+       case PIPE_FORMAT_B5G6R5_UNORM:
                return NV50_2D_DST_FORMAT_R5G6B5_UNORM;
+       case PIPE_FORMAT_B5G5R5A1_UNORM:
+               return NV50_2D_DST_FORMAT_A1R5G5B5_UNORM;
        case PIPE_FORMAT_A8_UNORM:
+       case PIPE_FORMAT_I8_UNORM:
+       case PIPE_FORMAT_L8_UNORM:
                return NV50_2D_DST_FORMAT_R8_UNORM;
+       case PIPE_FORMAT_R32G32B32A32_FLOAT:
+               return NV50_2D_DST_FORMAT_R32G32B32A32_FLOAT;
+       case PIPE_FORMAT_R32G32B32_FLOAT:
+               return NV50_2D_DST_FORMAT_R32G32B32X32_FLOAT;
+       case PIPE_FORMAT_Z32_FLOAT:
+               return NV50_2D_DST_FORMAT_R32_FLOAT;
+
+       /* only because we require src format == dst format: */
+       case PIPE_FORMAT_R16G16_SNORM:
+       case PIPE_FORMAT_R16G16_UNORM:
+       case PIPE_FORMAT_S8Z24_UNORM:
+       case PIPE_FORMAT_Z24S8_UNORM:
+               return NV50_2D_DST_FORMAT_A8R8G8B8_UNORM;
+       case PIPE_FORMAT_L8A8_UNORM:
+       case PIPE_FORMAT_B4G4R4A4_UNORM:
+               return NV50_2D_DST_FORMAT_R16_UNORM;
+
        default:
                return -1;
        }
@@ -58,24 +83,29 @@ nv50_surface_set(struct nv50_screen *screen, struct pipe_surface *ps, int dst)
        int flags = NOUVEAU_BO_VRAM | (dst ? NOUVEAU_BO_WR : NOUVEAU_BO_RD);
 
        format = nv50_format(ps->format);
-       if (format < 0)
+       if (format < 0) {
+               NOUVEAU_ERR("invalid/unsupported surface format: %s\n",
+                           util_format_name(ps->format));
                return 1;
-  
+       }
+
        if (!bo->tile_flags) {
+               MARK_RING (chan, 9, 2); /* flush on lack of space or relocs */
                BEGIN_RING(chan, eng2d, mthd, 2);
                OUT_RING  (chan, format);
                OUT_RING  (chan, 1);
                BEGIN_RING(chan, eng2d, mthd + 0x14, 5);
-               OUT_RING  (chan, mt->level[0].pitch);
+               OUT_RING  (chan, mt->level[ps->level].pitch);
                OUT_RING  (chan, ps->width);
                OUT_RING  (chan, ps->height);
                OUT_RELOCh(chan, bo, ps->offset, flags);
                OUT_RELOCl(chan, bo, ps->offset, flags);
        } else {
+               MARK_RING (chan, 11, 2); /* flush on lack of space or relocs */
                BEGIN_RING(chan, eng2d, mthd, 5);
                OUT_RING  (chan, format);
                OUT_RING  (chan, 0);
-               OUT_RING  (chan, bo->tile_mode << 4);
+               OUT_RING  (chan, mt->level[ps->level].tile_mode << 4);
                OUT_RING  (chan, 1);
                OUT_RING  (chan, 0);
                BEGIN_RING(chan, eng2d, mthd + 0x18, 4);
@@ -174,11 +204,11 @@ nv50_surface_fill(struct pipe_context *pipe, struct pipe_surface *dest,
        if (ret)
                return;
 
-       BEGIN_RING(chan, eng2d, 0x0580, 3);
-       OUT_RING  (chan, 4);
+       BEGIN_RING(chan, eng2d, NV50_2D_DRAW_SHAPE, 3);
+       OUT_RING  (chan, NV50_2D_DRAW_SHAPE_RECTANGLES);
        OUT_RING  (chan, format);
        OUT_RING  (chan, value);
-       BEGIN_RING(chan, eng2d, NV50_2D_RECT_X1, 4);
+       BEGIN_RING(chan, eng2d, NV50_2D_DRAW_POINT32_X(0), 4);
        OUT_RING  (chan, destx);
        OUT_RING  (chan, desty);
        OUT_RING  (chan, width);