Squashed commit of the following:
[mesa.git] / src / gallium / drivers / nv50 / nv50_state.c
index da8dc933b030f03f30b07144744ae12cf9ba83ba..e885a2b719686087e9df50c296cf24a16d973a2d 100644 (file)
@@ -22,7 +22,7 @@
 
 #include "pipe/p_state.h"
 #include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
 
 #include "tgsi/tgsi_parse.h"
 
@@ -202,18 +202,18 @@ nv50_sampler_state_create(struct pipe_context *pipe,
                break;
        }
 
-       if (cso->max_anisotropy >= 16.0)
+       if (cso->max_anisotropy >= 16)
                tsc[0] |= (7 << 20);
        else
-       if (cso->max_anisotropy >= 12.0)
+       if (cso->max_anisotropy >= 12)
                tsc[0] |= (6 << 20);
        else {
-               tsc[0] |= (int)(cso->max_anisotropy * 0.5f) << 20;
+               tsc[0] |= (cso->max_anisotropy >> 1) << 20;
 
-               if (cso->max_anisotropy >= 4.0)
+               if (cso->max_anisotropy >= 4)
                        tsc[1] |= NV50TSC_1_1_UNKN_ANISO_35;
                else
-               if (cso->max_anisotropy >= 2.0)
+               if (cso->max_anisotropy >= 2)
                        tsc[1] |= NV50TSC_1_1_UNKN_ANISO_15;
        }
 
@@ -238,6 +238,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 +256,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,40 +272,74 @@ 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)
 {
-       struct nouveau_stateobj *so = so_new(15, 21, 0);
+       struct nouveau_stateobj *so = so_new(16, 22, 0);
        struct nouveau_grobj *tesla = nv50_context(pipe)->screen->tesla;
        struct nv50_rasterizer_stateobj *rso =
                CALLOC_STRUCT(nv50_rasterizer_stateobj);
@@ -314,6 +351,9 @@ nv50_rasterizer_state_create(struct pipe_context *pipe,
         *      - point_sprite / sprite_coord_mode
         */
 
+       so_method(so, tesla, NV50TCL_SCISSOR_ENABLE(0), 1);
+       so_data  (so, cso->scissor);
+
        so_method(so, tesla, NV50TCL_SHADE_MODEL, 1);
        so_data  (so, cso->flatshade ? NV50TCL_SHADE_MODEL_FLAT :
                                       NV50TCL_SHADE_MODEL_SMOOTH);
@@ -342,7 +382,7 @@ nv50_rasterizer_state_create(struct pipe_context *pipe,
        so_data  (so, fui(cso->point_size));
 
        so_method(so, tesla, NV50TCL_POINT_SPRITE_ENABLE, 1);
-       so_data  (so, cso->point_sprite);
+       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) {
@@ -447,7 +487,7 @@ nv50_depth_stencil_alpha_state_create(struct pipe_context *pipe,
 {
        struct nouveau_grobj *tesla = nv50_context(pipe)->screen->tesla;
        struct nv50_zsa_stateobj *zsa = CALLOC_STRUCT(nv50_zsa_stateobj);
-       struct nouveau_stateobj *so = so_new(8, 22, 0);
+       struct nouveau_stateobj *so = so_new(9, 21, 0);
 
        so_method(so, tesla, NV50TCL_DEPTH_WRITE_ENABLE, 1);
        so_data  (so, cso->depth.writemask ? 1 : 0);
@@ -462,13 +502,13 @@ nv50_depth_stencil_alpha_state_create(struct pipe_context *pipe,
        }
 
        if (cso->stencil[0].enabled) {
-               so_method(so, tesla, NV50TCL_STENCIL_FRONT_ENABLE, 8);
+               so_method(so, tesla, NV50TCL_STENCIL_FRONT_ENABLE, 5);
                so_data  (so, 1);
                so_data  (so, nvgl_stencil_op(cso->stencil[0].fail_op));
                so_data  (so, nvgl_stencil_op(cso->stencil[0].zfail_op));
                so_data  (so, nvgl_stencil_op(cso->stencil[0].zpass_op));
                so_data  (so, nvgl_comparison_op(cso->stencil[0].func));
-               so_data  (so, cso->stencil[0].ref_value);
+               so_method(so, tesla, NV50TCL_STENCIL_FRONT_MASK, 2);
                so_data  (so, cso->stencil[0].writemask);
                so_data  (so, cso->stencil[0].valuemask);
        } else {
@@ -483,8 +523,7 @@ nv50_depth_stencil_alpha_state_create(struct pipe_context *pipe,
                so_data  (so, nvgl_stencil_op(cso->stencil[1].zfail_op));
                so_data  (so, nvgl_stencil_op(cso->stencil[1].zpass_op));
                so_data  (so, nvgl_comparison_op(cso->stencil[1].func));
-               so_method(so, tesla, NV50TCL_STENCIL_BACK_FUNC_REF, 3);
-               so_data  (so, cso->stencil[1].ref_value);
+               so_method(so, tesla, NV50TCL_STENCIL_BACK_MASK, 2);
                so_data  (so, cso->stencil[1].writemask);
                so_data  (so, cso->stencil[1].valuemask);
        } else {
@@ -633,6 +672,16 @@ nv50_set_blend_color(struct pipe_context *pipe,
        nv50->dirty |= NV50_NEW_BLEND_COLOUR;
 }
 
+ static void
+nv50_set_stencil_ref(struct pipe_context *pipe,
+                    const struct pipe_stencil_ref *sr)
+{
+       struct nv50_context *nv50 = nv50_context(pipe);
+
+       nv50->stencil_ref = *sr;
+       nv50->dirty |= NV50_NEW_STENCIL_REF;
+}
+
 static void
 nv50_set_clip_state(struct pipe_context *pipe,
                    const struct pipe_clip_state *clip)
@@ -641,7 +690,7 @@ nv50_set_clip_state(struct pipe_context *pipe,
 
 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);
 
@@ -711,15 +760,34 @@ nv50_set_vertex_buffers(struct pipe_context *pipe, unsigned count,
        nv50->dirty |= NV50_NEW_ARRAYS;
 }
 
+static void *
+nv50_vtxelts_state_create(struct pipe_context *pipe,
+                         unsigned num_elements,
+                         const struct pipe_vertex_element *elements)
+{
+       struct nv50_vtxelt_stateobj *cso = CALLOC_STRUCT(nv50_vtxelt_stateobj);
+
+       assert(num_elements < 16); /* not doing fallbacks yet */
+       cso->num_elements = num_elements;
+       memcpy(cso->pipe, elements, num_elements * sizeof(*elements));
+
+       nv50_vtxelt_construct(cso);
+
+       return (void *)cso;
+}
+
 static void
-nv50_set_vertex_elements(struct pipe_context *pipe, unsigned count,
-                        const struct pipe_vertex_element *ve)
+nv50_vtxelts_state_delete(struct pipe_context *pipe, void *hwcso)
 {
-       struct nv50_context *nv50 = nv50_context(pipe);
+       FREE(hwcso);
+}
 
-       memcpy(nv50->vtxelt, ve, sizeof(*ve) * count);
-       nv50->vtxelt_nr = count;
+static void
+nv50_vtxelts_state_bind(struct pipe_context *pipe, void *hwcso)
+{
+       struct nv50_context *nv50 = nv50_context(pipe);
 
+       nv50->vtxelt = hwcso;
        nv50->dirty |= NV50_NEW_ARRAYS;
 }
 
@@ -734,8 +802,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;
@@ -761,6 +831,7 @@ nv50_init_state_functions(struct nv50_context *nv50)
        nv50->pipe.delete_gs_state = nv50_gp_state_delete;
 
        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_constant_buffer = nv50_set_constant_buffer;
        nv50->pipe.set_framebuffer_state = nv50_set_framebuffer_state;
@@ -768,7 +839,10 @@ nv50_init_state_functions(struct nv50_context *nv50)
        nv50->pipe.set_scissor_state = nv50_set_scissor_state;
        nv50->pipe.set_viewport_state = nv50_set_viewport_state;
 
+       nv50->pipe.create_vertex_elements_state = nv50_vtxelts_state_create;
+       nv50->pipe.delete_vertex_elements_state = nv50_vtxelts_state_delete;
+       nv50->pipe.bind_vertex_elements_state = nv50_vtxelts_state_bind;
+
        nv50->pipe.set_vertex_buffers = nv50_set_vertex_buffers;
-       nv50->pipe.set_vertex_elements = nv50_set_vertex_elements;
 }