nvfx: rework state_fb code to get rid of render temps
[mesa.git] / src / gallium / drivers / nvfx / nvfx_surface.c
index 6fd6c47081bf18e101c13bf1060602b87ea3fbca..73a5260ac0f34dedddad628fb5331dea9086015e 100644 (file)
@@ -33,6 +33,7 @@
 #include "util/u_memory.h"
 #include "util/u_pack_color.h"
 #include "util/u_blitter.h"
+#include "util/u_surface.h"
 
 #include "nouveau/nouveau_winsys.h"
 #include "nouveau/nouveau_screen.h"
@@ -83,7 +84,7 @@ nvfx_region_set_format(struct nv04_region* rgn, enum pipe_format format)
 }
 
 static INLINE void
-nvfx_region_init_for_surface(struct nv04_region* rgn, struct nvfx_surface* surf, unsigned x, unsigned y, bool for_write)
+nvfx_region_init_for_surface(struct nv04_region* rgn, struct nvfx_surface* surf, unsigned x, unsigned y, boolean for_write)
 {
        rgn->x = x;
        rgn->y = y;
@@ -101,7 +102,7 @@ nvfx_region_init_for_surface(struct nv04_region* rgn, struct nvfx_surface* surf,
                rgn->bo = ((struct nvfx_resource*)surf->base.base.texture)->bo;
                rgn->offset = surf->offset;
 
-               if(surf->base.base.texture->flags & NVFX_RESOURCE_FLAG_LINEAR)
+               if(surf->base.base.texture->flags & NOUVEAU_RESOURCE_FLAG_LINEAR)
                        rgn->pitch = surf->pitch;
                else
                {
@@ -119,7 +120,7 @@ nvfx_region_init_for_surface(struct nv04_region* rgn, struct nvfx_surface* surf,
 }
 
 static INLINE void
-nvfx_region_init_for_subresource(struct nv04_region* rgn, struct pipe_resource* pt, unsigned level, unsigned x, unsigned y, unsigned z, bool for_write)
+nvfx_region_init_for_subresource(struct nv04_region* rgn, struct pipe_resource* pt, unsigned level, unsigned x, unsigned y, unsigned z, boolean for_write)
 {
        if(pt->target != PIPE_BUFFER)
        {
@@ -136,7 +137,7 @@ nvfx_region_init_for_subresource(struct nv04_region* rgn, struct pipe_resource*
        rgn->x = x;
        rgn->y = y;
 
-       if(pt->flags & NVFX_RESOURCE_FLAG_LINEAR)
+       if(pt->flags & NOUVEAU_RESOURCE_FLAG_LINEAR)
        {
                rgn->pitch = nvfx_subresource_pitch(pt, level);
                rgn->z = 0;
@@ -168,8 +169,8 @@ nvfx_get_blitter(struct pipe_context* pipe, int copy)
        if(nvfx->query && !nvfx->blitters_in_use)
        {
                struct nouveau_channel* chan = nvfx->screen->base.channel;
-               WAIT_RING(chan, 2);
-               OUT_RING(chan, RING_3D(NV30_3D_QUERY_ENABLE, 1));
+               struct nouveau_grobj *eng3d = nvfx->screen->eng3d;
+               BEGIN_RING(chan, eng3d, NV30_3D_QUERY_ENABLE, 1);
                OUT_RING(chan, 0);
        }
 
@@ -186,7 +187,6 @@ nvfx_get_blitter(struct pipe_context* pipe, int copy)
        util_blitter_save_vertex_shader(blitter, nvfx->vertprog);
        util_blitter_save_viewport(blitter, &nvfx->viewport);
        util_blitter_save_framebuffer(blitter, &nvfx->framebuffer);
-       util_blitter_save_clip(blitter, &nvfx->clip);
        util_blitter_save_vertex_elements(blitter, nvfx->vtxelt);
        util_blitter_save_vertex_buffers(blitter, nvfx->vtxbuf_nr, nvfx->vtxbuf);
 
@@ -209,8 +209,8 @@ nvfx_put_blitter(struct pipe_context* pipe, struct blitter_context* blitter)
        if(nvfx->query && !nvfx->blitters_in_use)
        {
                struct nouveau_channel* chan = nvfx->screen->base.channel;
-               WAIT_RING(chan, 2);
-               OUT_RING(chan, RING_3D(NV30_3D_QUERY_ENABLE, 1));
+               struct nouveau_grobj *eng3d = nvfx->screen->eng3d;
+               BEGIN_RING(chan, eng3d, NV30_3D_QUERY_ENABLE, 1);
                OUT_RING(chan, 1);
        }
 }
@@ -252,6 +252,13 @@ nvfx_resource_copy_region(struct pipe_context *pipe,
        if(!w || !h)
                return;
 
+        /* Fallback for buffers. */
+        if (dstr->target == PIPE_BUFFER && srcr->target == PIPE_BUFFER) {
+                util_resource_copy_region(pipe, dstr, dst_level, dstx, dsty, dstz,
+                                          srcr, src_level, src_box);
+                return;
+        }
+
        if(copy_threshold < 0)
                copy_threshold = debug_get_num_option("NOUVEAU_COPY_THRESHOLD", 4);
 
@@ -280,7 +287,7 @@ nvfx_resource_copy_region(struct pipe_context *pipe,
                 * TODO: perhaps support reinterpreting the formats
                 */
                struct blitter_context* blitter = nvfx_get_blitter(pipe, 1);
-               util_blitter_copy_region(blitter, dstr, dst_level, dstx, dsty, dstz, srcr, src_level, src_box, TRUE);
+               util_blitter_copy_texture(blitter, dstr, dst_level, dstx, dsty, dstz, srcr, src_level, src_box, TRUE);
                nvfx_put_blitter(pipe, blitter);
        }
        else
@@ -421,6 +428,8 @@ nvfx_surface_copy_temp(struct pipe_context* pipe, struct pipe_surface* surf, int
 void
 nvfx_surface_create_temp(struct pipe_context* pipe, struct pipe_surface* surf)
 {
+       assert (0);
+
        struct nvfx_surface* ns = (struct nvfx_surface*)surf;
        struct pipe_resource template;
        memset(&template, 0, sizeof(struct pipe_resource));
@@ -430,7 +439,7 @@ nvfx_surface_create_temp(struct pipe_context* pipe, struct pipe_surface* surf)
        template.height0 = surf->height;
        template.depth0 = 1;
        template.nr_samples = surf->texture->nr_samples;
-       template.flags = NVFX_RESOURCE_FLAG_LINEAR;
+       template.flags = NOUVEAU_RESOURCE_FLAG_LINEAR;
 
        assert(!ns->temp && !util_dirty_surface_is_dirty(&ns->base));
 
@@ -470,19 +479,19 @@ nvfx_surface_flush(struct pipe_context* pipe, struct pipe_surface* surf)
 static void
 nvfx_clear_render_target(struct pipe_context *pipe,
                         struct pipe_surface *dst,
-                        const float *rgba,
+                        const union pipe_color_union *color,
                         unsigned dstx, unsigned dsty,
                         unsigned width, unsigned height)
 {
        union util_color uc;
-       util_pack_color(rgba, dst->format, &uc);
+       util_pack_color(color->f, dst->format, &uc);
 
        if(util_format_get_blocksizebits(dst->format) > 32
                || nvfx_surface_fill(pipe, dst, dstx, dsty, width, height, uc.ui))
        {
                // TODO: probably should use hardware clear here instead if possible
                struct blitter_context* blitter = nvfx_get_blitter(pipe, 0);
-               util_blitter_clear_render_target(blitter, dst, rgba, dstx, dsty, width, height);
+               util_blitter_clear_render_target(blitter, dst, color, dstx, dsty, width, height);
                nvfx_put_blitter(pipe, blitter);
        }
 }