r600g: fix SSG and op3 neg writing
[mesa.git] / src / gallium / drivers / nvfx / nvfx_draw.c
index 5379b29efd11db676089b6b54a385fb3c5f40d4e..2601d5b8e2ecc7edcd97a0bb83cded1cd432111e 100644 (file)
@@ -9,8 +9,7 @@
 #include "draw/draw_pipe.h"
 
 #include "nvfx_context.h"
-#include "nv30_vertprog.h"
-#include "nv40_vertprog.h"
+#include "nvfx_resource.h"
 
 /* Simple, but crappy, swtnl path, hopefully we wont need to hit this very
  * often at all.  Uses "quadro style" vertex submission + a fixed vertex
@@ -41,30 +40,21 @@ nvfx_render_vertex(struct nvfx_context *nvfx, const struct vertex_header *v)
                unsigned idx = nvfx->swtnl.draw[i];
                unsigned hw = nvfx->swtnl.hw[i];
 
+               WAIT_RING(chan, 5);
                switch (nvfx->swtnl.emit[i]) {
                case EMIT_OMIT:
                        break;
                case EMIT_1F:
-                       BEGIN_RING(chan, eng3d, NV34TCL_VTX_ATTR_1F(hw), 1);
-                       OUT_RING  (chan, fui(v->data[idx][0]));
+                       nvfx_emit_vtx_attr(chan, hw, v->data[idx], 1);
                        break;
                case EMIT_2F:
-                       BEGIN_RING(chan, eng3d, NV34TCL_VTX_ATTR_2F_X(hw), 2);
-                       OUT_RING  (chan, fui(v->data[idx][0]));
-                       OUT_RING  (chan, fui(v->data[idx][1]));
+                       nvfx_emit_vtx_attr(chan, hw, v->data[idx], 2);
                        break;
                case EMIT_3F:
-                       BEGIN_RING(chan, eng3d, NV34TCL_VTX_ATTR_3F_X(hw), 3);
-                       OUT_RING  (chan, fui(v->data[idx][0]));
-                       OUT_RING  (chan, fui(v->data[idx][1]));
-                       OUT_RING  (chan, fui(v->data[idx][2]));
+                       nvfx_emit_vtx_attr(chan, hw, v->data[idx], 3);
                        break;
                case EMIT_4F:
-                       BEGIN_RING(chan, eng3d, NV34TCL_VTX_ATTR_4F_X(hw), 4);
-                       OUT_RING  (chan, fui(v->data[idx][0]));
-                       OUT_RING  (chan, fui(v->data[idx][1]));
-                       OUT_RING  (chan, fui(v->data[idx][2]));
-                       OUT_RING  (chan, fui(v->data[idx][3]));
+                       nvfx_emit_vtx_attr(chan, hw, v->data[idx], 4);
                        break;
                case 0xff:
                        BEGIN_RING(chan, eng3d, NV34TCL_VTX_ATTR_4F_X(hw), 4);
@@ -79,6 +69,12 @@ nvfx_render_vertex(struct nvfx_context *nvfx, const struct vertex_header *v)
                                            float_to_ubyte(v->data[idx][1]),
                                            float_to_ubyte(v->data[idx][2]),
                                            float_to_ubyte(v->data[idx][3])));
+               case EMIT_4UB_BGRA:
+                       BEGIN_RING(chan, eng3d, NV34TCL_VTX_ATTR_4UB(hw), 1);
+                       OUT_RING  (chan, pack_ub4(float_to_ubyte(v->data[idx][2]),
+                                           float_to_ubyte(v->data[idx][1]),
+                                           float_to_ubyte(v->data[idx][0]),
+                                           float_to_ubyte(v->data[idx][3])));
                        break;
                default:
                        assert(0);
@@ -227,57 +223,38 @@ nvfx_draw_render_stage(struct nvfx_context *nvfx)
 }
 
 void
-nvfx_draw_elements_swtnl(struct pipe_context *pipe,
-                        struct pipe_buffer *idxbuf, unsigned idxbuf_size,
-                        unsigned mode, unsigned start, unsigned count)
+nvfx_draw_vbo_swtnl(struct pipe_context *pipe, const struct pipe_draw_info* info)
 {
        struct nvfx_context *nvfx = nvfx_context(pipe);
-       struct pipe_screen *pscreen = pipe->screen;
        unsigned i;
        void *map;
 
        if (!nvfx_state_validate_swtnl(nvfx))
                return;
-       nvfx->state.dirty &= ~(1ULL << NVFX_STATE_VTXBUF);
        nvfx_state_emit(nvfx);
 
+       /* these must be passed without adding the offsets */
        for (i = 0; i < nvfx->vtxbuf_nr; i++) {
-               map = pipe_buffer_map(pscreen, nvfx->vtxbuf[i].buffer,
-                                      PIPE_BUFFER_USAGE_CPU_READ);
+               map = nvfx_buffer(nvfx->vtxbuf[i].buffer)->data;
                draw_set_mapped_vertex_buffer(nvfx->draw, i, map);
        }
 
-       if (idxbuf) {
-               map = pipe_buffer_map(pscreen, idxbuf,
-                                     PIPE_BUFFER_USAGE_CPU_READ);
-               draw_set_mapped_element_buffer(nvfx->draw, idxbuf_size, map);
-       } else {
-               draw_set_mapped_element_buffer(nvfx->draw, 0, NULL);
-       }
+       map = NULL;
+       if (info->indexed && nvfx->idxbuf.buffer)
+               map = nvfx_buffer(nvfx->idxbuf.buffer)->data;
+       draw_set_mapped_index_buffer(nvfx->draw, map);
 
        if (nvfx->constbuf[PIPE_SHADER_VERTEX]) {
                const unsigned nr = nvfx->constbuf_nr[PIPE_SHADER_VERTEX];
 
-               map = pipe_buffer_map(pscreen,
-                                     nvfx->constbuf[PIPE_SHADER_VERTEX],
-                                     PIPE_BUFFER_USAGE_CPU_READ);
+               map = nvfx_buffer(nvfx->constbuf[PIPE_SHADER_VERTEX])->data;
                draw_set_mapped_constant_buffer(nvfx->draw, PIPE_SHADER_VERTEX, 0,
                                                 map, nr);
        }
 
-       draw_arrays(nvfx->draw, mode, start, count);
-
-       for (i = 0; i < nvfx->vtxbuf_nr; i++)
-               pipe_buffer_unmap(pscreen, nvfx->vtxbuf[i].buffer);
-
-       if (idxbuf)
-               pipe_buffer_unmap(pscreen, idxbuf);
-
-       if (nvfx->constbuf[PIPE_SHADER_VERTEX])
-               pipe_buffer_unmap(pscreen, nvfx->constbuf[PIPE_SHADER_VERTEX]);
+       draw_vbo(nvfx->draw, info);
 
        draw_flush(nvfx->draw);
-       pipe->flush(pipe, 0, NULL);
 }
 
 static INLINE void
@@ -292,22 +269,22 @@ emit_attrib(struct nvfx_context *nvfx, unsigned hw, unsigned emit,
        nvfx->swtnl.draw[a] = draw_out;
 }
 
-static boolean
-nvfx_state_vtxfmt_validate(struct nvfx_context *nvfx)
+void
+nvfx_vtxfmt_validate(struct nvfx_context *nvfx)
 {
-       struct nvfx_fragment_program *fp = nvfx->fragprog;
+       struct nvfx_pipe_fragment_program *pfp = nvfx->fragprog;
        unsigned colour = 0, texcoords = 0, fog = 0, i;
 
        /* Determine needed fragprog inputs */
-       for (i = 0; i < fp->info.num_inputs; i++) {
-               switch (fp->info.input_semantic_name[i]) {
+       for (i = 0; i < pfp->info.num_inputs; i++) {
+               switch (pfp->info.input_semantic_name[i]) {
                case TGSI_SEMANTIC_POSITION:
                        break;
                case TGSI_SEMANTIC_COLOR:
-                       colour |= (1 << fp->info.input_semantic_index[i]);
+                       colour |= (1 << pfp->info.input_semantic_index[i]);
                        break;
                case TGSI_SEMANTIC_GENERIC:
-                       texcoords |= (1 << fp->info.input_semantic_index[i]);
+                       texcoords |= (1 << pfp->info.input_semantic_index[i]);
                        break;
                case TGSI_SEMANTIC_FOG:
                        fog = 1;
@@ -337,14 +314,4 @@ nvfx_state_vtxfmt_validate(struct nvfx_context *nvfx)
        }
 
        emit_attrib(nvfx, 0, 0xff, TGSI_SEMANTIC_POSITION, 0);
-
-       return FALSE;
 }
-
-struct nvfx_state_entry nvfx_state_vtxfmt = {
-       .validate = nvfx_state_vtxfmt_validate,
-       .dirty = {
-               .pipe = NVFX_NEW_ARRAYS | NVFX_NEW_FRAGPROG,
-               .hw = 0
-       }
-};