nouveau: update nouveau_class.h
[mesa.git] / src / gallium / drivers / nv50 / nv50_state.c
index b0e5552eff45957a838f7c47c2dfa4f2a25cc8af..88fee3630bef7145c4b2caad37f0846b200f9fb1 100644 (file)
@@ -48,6 +48,53 @@ nv50_colormask(unsigned mask)
        return cmask;
 }
 
+static INLINE uint32_t
+nv50_blend_func(unsigned factor)
+{
+       switch (factor) {
+       case PIPE_BLENDFACTOR_ZERO:
+               return NV50TCL_BLEND_FUNC_SRC_RGB_ZERO;
+       case PIPE_BLENDFACTOR_ONE:
+               return NV50TCL_BLEND_FUNC_SRC_RGB_ONE;
+       case PIPE_BLENDFACTOR_SRC_COLOR:
+               return NV50TCL_BLEND_FUNC_SRC_RGB_SRC_COLOR;
+       case PIPE_BLENDFACTOR_INV_SRC_COLOR:
+               return NV50TCL_BLEND_FUNC_SRC_RGB_ONE_MINUS_SRC_COLOR;
+       case PIPE_BLENDFACTOR_SRC_ALPHA:
+               return NV50TCL_BLEND_FUNC_SRC_RGB_SRC_ALPHA;
+       case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
+               return NV50TCL_BLEND_FUNC_SRC_RGB_ONE_MINUS_SRC_ALPHA;
+       case PIPE_BLENDFACTOR_DST_ALPHA:
+               return NV50TCL_BLEND_FUNC_SRC_RGB_DST_ALPHA;
+       case PIPE_BLENDFACTOR_INV_DST_ALPHA:
+               return NV50TCL_BLEND_FUNC_SRC_RGB_ONE_MINUS_DST_ALPHA;
+       case PIPE_BLENDFACTOR_DST_COLOR:
+               return NV50TCL_BLEND_FUNC_SRC_RGB_DST_COLOR;
+       case PIPE_BLENDFACTOR_INV_DST_COLOR:
+               return NV50TCL_BLEND_FUNC_SRC_RGB_ONE_MINUS_DST_COLOR;
+       case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
+               return NV50TCL_BLEND_FUNC_SRC_RGB_SRC_ALPHA_SATURATE;
+       case PIPE_BLENDFACTOR_CONST_COLOR:
+               return NV50TCL_BLEND_FUNC_SRC_RGB_CONSTANT_COLOR;
+       case PIPE_BLENDFACTOR_INV_CONST_COLOR:
+               return NV50TCL_BLEND_FUNC_SRC_RGB_ONE_MINUS_CONSTANT_COLOR;
+       case PIPE_BLENDFACTOR_CONST_ALPHA:
+               return NV50TCL_BLEND_FUNC_SRC_RGB_CONSTANT_ALPHA;
+       case PIPE_BLENDFACTOR_INV_CONST_ALPHA:
+               return NV50TCL_BLEND_FUNC_SRC_RGB_ONE_MINUS_CONSTANT_ALPHA;
+       case PIPE_BLENDFACTOR_SRC1_COLOR:
+               return NV50TCL_BLEND_FUNC_SRC_RGB_SRC1_COLOR;
+       case PIPE_BLENDFACTOR_INV_SRC1_COLOR:
+               return NV50TCL_BLEND_FUNC_SRC_RGB_ONE_MINUS_SRC1_COLOR;
+       case PIPE_BLENDFACTOR_SRC1_ALPHA:
+               return NV50TCL_BLEND_FUNC_SRC_RGB_SRC1_ALPHA;
+       case PIPE_BLENDFACTOR_INV_SRC1_ALPHA:
+               return NV50TCL_BLEND_FUNC_SRC_RGB_ONE_MINUS_SRC1_ALPHA;
+       default:
+               return NV50TCL_BLEND_FUNC_SRC_RGB_ZERO;
+       }
+}
+
 static void *
 nv50_blend_state_create(struct pipe_context *pipe,
                        const struct pipe_blend_state *cso)
@@ -80,12 +127,12 @@ nv50_blend_state_create(struct pipe_context *pipe,
        if (blend_enabled) {
                so_method(so, tesla, NV50TCL_BLEND_EQUATION_RGB, 5);
                so_data  (so, nvgl_blend_eqn(cso->rt[0].rgb_func));
-               so_data  (so, 0x4000 | nvgl_blend_func(cso->rt[0].rgb_src_factor));
-               so_data  (so, 0x4000 | nvgl_blend_func(cso->rt[0].rgb_dst_factor));
+               so_data  (so, nv50_blend_func(cso->rt[0].rgb_src_factor));
+               so_data  (so, nv50_blend_func(cso->rt[0].rgb_dst_factor));
                so_data  (so, nvgl_blend_eqn(cso->rt[0].alpha_func));
-               so_data  (so, 0x4000 | nvgl_blend_func(cso->rt[0].alpha_src_factor));
+               so_data  (so, nv50_blend_func(cso->rt[0].alpha_src_factor));
                so_method(so, tesla, NV50TCL_BLEND_FUNC_DST_ALPHA, 1);
-               so_data  (so, 0x4000 | nvgl_blend_func(cso->rt[0].alpha_dst_factor));
+               so_data  (so, nv50_blend_func(cso->rt[0].alpha_dst_factor));
        }
 
        if (cso->logicop_enable == 0 ) {
@@ -238,6 +285,9 @@ nv50_sampler_state_create(struct pipe_context *pipe,
        return (void *)sso;
 }
 
+/* type == 0 for VPs, 1 for GPs, 2 for FPs, which is how the
+ * relevant tesla methods are indexed (NV50TCL_BIND_TSC etc.)
+ */
 static INLINE void
 nv50_sampler_state_bind(struct pipe_context *pipe, unsigned type,
                        unsigned nr, void **sampler)
@@ -253,13 +303,13 @@ nv50_sampler_state_bind(struct pipe_context *pipe, unsigned type,
 static void
 nv50_vp_sampler_state_bind(struct pipe_context *pipe, unsigned nr, void **s)
 {
-       nv50_sampler_state_bind(pipe, PIPE_SHADER_VERTEX, nr, s);
+       nv50_sampler_state_bind(pipe, 0, nr, s);
 }
 
 static void
 nv50_fp_sampler_state_bind(struct pipe_context *pipe, unsigned nr, void **s)
 {
-       nv50_sampler_state_bind(pipe, PIPE_SHADER_FRAGMENT, nr, s);
+       nv50_sampler_state_bind(pipe, 2, nr, s);
 }
 
 static void
@@ -269,35 +319,69 @@ nv50_sampler_state_delete(struct pipe_context *pipe, void *hwcso)
 }
 
 static INLINE void
-nv50_set_sampler_texture(struct pipe_context *pipe, unsigned type,
-                        unsigned nr, struct pipe_texture **pt)
+nv50_set_sampler_views(struct pipe_context *pipe, unsigned p,
+                      unsigned nr,
+                      struct pipe_sampler_view **views)
 {
        struct nv50_context *nv50 = nv50_context(pipe);
        unsigned i;
 
        for (i = 0; i < nr; i++)
-               pipe_texture_reference((void *)&nv50->miptree[type][i], pt[i]);
-       for (i = nr; i < nv50->miptree_nr[type]; i++)
-               pipe_texture_reference((void *)&nv50->miptree[type][i], NULL);
+               pipe_sampler_view_reference(&nv50->sampler_views[p][i],
+                                           views[i]);
+
+       for (i = nr; i < nv50->sampler_view_nr[p]; i++)
+               pipe_sampler_view_reference(&nv50->sampler_views[p][i], NULL);
 
-       nv50->miptree_nr[type] = nr;
+       nv50->sampler_view_nr[p] = nr;
        nv50->dirty |= NV50_NEW_TEXTURE;
 }
 
 static void
-nv50_set_vp_sampler_textures(struct pipe_context *pipe,
-                            unsigned nr, struct pipe_texture **pt)
+nv50_set_vp_sampler_views(struct pipe_context *pipe,
+                         unsigned nr,
+                         struct pipe_sampler_view **views)
 {
-       nv50_set_sampler_texture(pipe, PIPE_SHADER_VERTEX, nr, pt);
+       nv50_set_sampler_views(pipe, 0, nr, views);
 }
 
 static void
-nv50_set_fp_sampler_textures(struct pipe_context *pipe,
-                            unsigned nr, struct pipe_texture **pt)
+nv50_set_fp_sampler_views(struct pipe_context *pipe,
+                         unsigned nr,
+                         struct pipe_sampler_view **views)
 {
-       nv50_set_sampler_texture(pipe, PIPE_SHADER_FRAGMENT, nr, pt);
+       nv50_set_sampler_views(pipe, 2, nr, views);
 }
 
+static void
+nv50_sampler_view_destroy(struct pipe_context *pipe,
+                         struct pipe_sampler_view *view)
+{
+       pipe_resource_reference(&view->texture, NULL);
+       FREE(nv50_sampler_view(view));
+}
+
+static struct pipe_sampler_view *
+nv50_create_sampler_view(struct pipe_context *pipe,
+                        struct pipe_resource *texture,
+                        const struct pipe_sampler_view *templ)
+{
+       struct nv50_sampler_view *view = CALLOC_STRUCT(nv50_sampler_view);
+
+       view->pipe = *templ;
+       view->pipe.reference.count = 1;
+       view->pipe.texture = NULL;
+       pipe_resource_reference(&view->pipe.texture, texture);
+       view->pipe.context = pipe;
+
+       if (!nv50_tex_construct(view)) {
+               nv50_sampler_view_destroy(pipe, &view->pipe);
+               return NULL;
+       }
+       return &view->pipe;
+}
+
+
 static void *
 nv50_rasterizer_state_create(struct pipe_context *pipe,
                             const struct pipe_rasterizer_state *cso)
@@ -308,7 +392,7 @@ nv50_rasterizer_state_create(struct pipe_context *pipe,
                CALLOC_STRUCT(nv50_rasterizer_stateobj);
 
        /*XXX: ignored
-        *      - light_twosize
+        *      - light_twoside
         *      - point_smooth
         *      - multisample
         *      - point_sprite / sprite_coord_mode
@@ -348,72 +432,44 @@ nv50_rasterizer_state_create(struct pipe_context *pipe,
        so_data  (so, cso->point_quad_rasterization ? 1 : 0);
 
        so_method(so, tesla, NV50TCL_POLYGON_MODE_FRONT, 3);
-       if (cso->front_winding == PIPE_WINDING_CCW) {
-               so_data(so, nvgl_polygon_mode(cso->fill_ccw));
-               so_data(so, nvgl_polygon_mode(cso->fill_cw));
-       } else {
-               so_data(so, nvgl_polygon_mode(cso->fill_cw));
-               so_data(so, nvgl_polygon_mode(cso->fill_ccw));
-       }
+        so_data(so, nvgl_polygon_mode(cso->fill_front));
+        so_data(so, nvgl_polygon_mode(cso->fill_back));
        so_data(so, cso->poly_smooth ? 1 : 0);
 
        so_method(so, tesla, NV50TCL_CULL_FACE_ENABLE, 3);
-       so_data  (so, cso->cull_mode != PIPE_WINDING_NONE);
-       if (cso->front_winding == PIPE_WINDING_CCW) {
+       so_data  (so, cso->cull_face != PIPE_FACE_NONE);
+       if (cso->front_ccw) {
                so_data(so, NV50TCL_FRONT_FACE_CCW);
-               switch (cso->cull_mode) {
-               case PIPE_WINDING_CCW:
-                       so_data(so, NV50TCL_CULL_FACE_FRONT);
-                       break;
-               case PIPE_WINDING_CW:
-                       so_data(so, NV50TCL_CULL_FACE_BACK);
-                       break;
-               case PIPE_WINDING_BOTH:
-                       so_data(so, NV50TCL_CULL_FACE_FRONT_AND_BACK);
-                       break;
-               default:
-                       so_data(so, NV50TCL_CULL_FACE_BACK);
-                       break;
-               }
-       } else {
+        }
+        else {
                so_data(so, NV50TCL_FRONT_FACE_CW);
-               switch (cso->cull_mode) {
-               case PIPE_WINDING_CCW:
-                       so_data(so, NV50TCL_CULL_FACE_BACK);
-                       break;
-               case PIPE_WINDING_CW:
-                       so_data(so, NV50TCL_CULL_FACE_FRONT);
-                       break;
-               case PIPE_WINDING_BOTH:
-                       so_data(so, NV50TCL_CULL_FACE_FRONT_AND_BACK);
-                       break;
-               default:
-                       so_data(so, NV50TCL_CULL_FACE_BACK);
-                       break;
-               }
+        }
+       switch (cso->cull_face) {
+       case PIPE_FACE_FRONT:
+               so_data(so, NV50TCL_CULL_FACE_FRONT);
+               break;
+       case PIPE_FACE_BACK:
+               so_data(so, NV50TCL_CULL_FACE_BACK);
+               break;
+       case PIPE_FACE_FRONT_AND_BACK:
+               so_data(so, NV50TCL_CULL_FACE_FRONT_AND_BACK);
+               break;
+       default:
+               so_data(so, NV50TCL_CULL_FACE_BACK);
+               break;
        }
 
        so_method(so, tesla, NV50TCL_POLYGON_STIPPLE_ENABLE, 1);
        so_data  (so, cso->poly_stipple_enable ? 1 : 0);
 
        so_method(so, tesla, NV50TCL_POLYGON_OFFSET_POINT_ENABLE, 3);
-       if ((cso->offset_cw && cso->fill_cw == PIPE_POLYGON_MODE_POINT) ||
-           (cso->offset_ccw && cso->fill_ccw == PIPE_POLYGON_MODE_POINT))
-               so_data(so, 1);
-       else
-               so_data(so, 0);
-       if ((cso->offset_cw && cso->fill_cw == PIPE_POLYGON_MODE_LINE) ||
-           (cso->offset_ccw && cso->fill_ccw == PIPE_POLYGON_MODE_LINE))
-               so_data(so, 1);
-       else
-               so_data(so, 0);
-       if ((cso->offset_cw && cso->fill_cw == PIPE_POLYGON_MODE_FILL) ||
-           (cso->offset_ccw && cso->fill_ccw == PIPE_POLYGON_MODE_FILL))
-               so_data(so, 1);
-       else
-               so_data(so, 0);
+        so_data(so, cso->offset_point);
+        so_data(so, cso->offset_line);
+        so_data(so, cso->offset_tri);
 
-       if (cso->offset_cw || cso->offset_ccw) {
+       if (cso->offset_point ||
+            cso->offset_line ||
+            cso->offset_tri) {
                so_method(so, tesla, NV50TCL_POLYGON_OFFSET_FACTOR, 1);
                so_data  (so, fui(cso->offset_scale));
                so_method(so, tesla, NV50TCL_POLYGON_OFFSET_UNITS, 1);
@@ -537,7 +593,6 @@ nv50_vp_state_create(struct pipe_context *pipe,
 
        p->pipe.tokens = tgsi_dup_tokens(cso->tokens);
        p->type = PIPE_SHADER_VERTEX;
-       tgsi_scan_shader(p->pipe.tokens, &p->info);
        return (void *)p;
 }
 
@@ -569,7 +624,6 @@ nv50_fp_state_create(struct pipe_context *pipe,
 
        p->pipe.tokens = tgsi_dup_tokens(cso->tokens);
        p->type = PIPE_SHADER_FRAGMENT;
-       tgsi_scan_shader(p->pipe.tokens, &p->info);
        return (void *)p;
 }
 
@@ -601,7 +655,6 @@ nv50_gp_state_create(struct pipe_context *pipe,
 
        p->pipe.tokens = tgsi_dup_tokens(cso->tokens);
        p->type = PIPE_SHADER_GEOMETRY;
-       tgsi_scan_shader(p->pipe.tokens, &p->info);
        return (void *)p;
 }
 
@@ -648,12 +701,22 @@ nv50_set_stencil_ref(struct pipe_context *pipe,
 static void
 nv50_set_clip_state(struct pipe_context *pipe,
                    const struct pipe_clip_state *clip)
+{
+       struct nv50_context *nv50 = nv50_context(pipe);
+
+       nv50->clip.depth_clamp = clip->depth_clamp;
+       nv50->dirty |= NV50_NEW_CLIP;
+}
+
+static void
+nv50_set_sample_mask(struct pipe_context *pipe,
+                    unsigned sample_mask)
 {
 }
 
 static void
 nv50_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index,
-                        struct pipe_buffer *buf )
+                        struct pipe_resource *buf )
 {
        struct nv50_context *nv50 = nv50_context(pipe);
 
@@ -765,8 +828,10 @@ nv50_init_state_functions(struct nv50_context *nv50)
        nv50->pipe.delete_sampler_state = nv50_sampler_state_delete;
        nv50->pipe.bind_fragment_sampler_states = nv50_fp_sampler_state_bind;
        nv50->pipe.bind_vertex_sampler_states   = nv50_vp_sampler_state_bind;
-       nv50->pipe.set_fragment_sampler_textures = nv50_set_fp_sampler_textures;
-       nv50->pipe.set_vertex_sampler_textures   = nv50_set_vp_sampler_textures;
+       nv50->pipe.set_fragment_sampler_views = nv50_set_fp_sampler_views;
+       nv50->pipe.set_vertex_sampler_views   = nv50_set_vp_sampler_views;
+       nv50->pipe.create_sampler_view = nv50_create_sampler_view;
+       nv50->pipe.sampler_view_destroy = nv50_sampler_view_destroy;
 
        nv50->pipe.create_rasterizer_state = nv50_rasterizer_state_create;
        nv50->pipe.bind_rasterizer_state = nv50_rasterizer_state_bind;
@@ -794,6 +859,7 @@ nv50_init_state_functions(struct nv50_context *nv50)
        nv50->pipe.set_blend_color = nv50_set_blend_color;
         nv50->pipe.set_stencil_ref = nv50_set_stencil_ref;
        nv50->pipe.set_clip_state = nv50_set_clip_state;
+       nv50->pipe.set_sample_mask = nv50_set_sample_mask;
        nv50->pipe.set_constant_buffer = nv50_set_constant_buffer;
        nv50->pipe.set_framebuffer_state = nv50_set_framebuffer_state;
        nv50->pipe.set_polygon_stipple = nv50_set_polygon_stipple;