1 /*
2  * Copyright 2012 Red Hat Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  *
22  * Authors: Ben Skeggs
23  *
24  */
25 
26 #include "util/u_inlines.h"
27 #include "nv30_context.h"
28 
29 void
nv40_verttex_validate(struct nv30_context * nv30)30 nv40_verttex_validate(struct nv30_context *nv30)
31 {
32    struct nouveau_pushbuf *push = nv30->base.pushbuf;
33    unsigned dirty = nv30->vertprog.dirty_samplers;
34 
35    while (dirty) {
36       unsigned unit = ffs(dirty) - 1;
37       struct nv30_sampler_view *sv = (void *)nv30->fragprog.textures[unit];
38       struct nv30_sampler_state *ss = nv30->fragprog.samplers[unit];
39 
40       if (ss && sv) {
41       } else {
42          BEGIN_NV04(push, NV40_3D(VTXTEX_ENABLE(unit)), 1);
43          PUSH_DATA (push, 0);
44       }
45    }
46 
47    nv30->vertprog.dirty_samplers = 0;
48 }
49 
50 static void
nv40_verttex_sampler_states_bind(struct pipe_context * pipe,unsigned nr,void ** hwcso)51 nv40_verttex_sampler_states_bind(struct pipe_context *pipe,
52                                  unsigned nr, void **hwcso)
53 {
54    struct nv30_context *nv30 = nv30_context(pipe);
55    unsigned i;
56 
57    for (i = 0; i < nr; i++) {
58       nv30->vertprog.samplers[i] = hwcso[i];
59       nv30->vertprog.dirty_samplers |= (1 << i);
60    }
61 
62    for (; i < nv30->vertprog.num_samplers; i++) {
63       nv30->vertprog.samplers[i] = NULL;
64       nv30->vertprog.dirty_samplers |= (1 << i);
65    }
66 
67    nv30->vertprog.num_samplers = nr;
68    nv30->dirty |= NV30_NEW_VERTTEX;
69 }
70 
71 
72 static void
nv40_verttex_set_sampler_views(struct pipe_context * pipe,unsigned nr,struct pipe_sampler_view ** views)73 nv40_verttex_set_sampler_views(struct pipe_context *pipe, unsigned nr,
74                                struct pipe_sampler_view **views)
75 {
76    struct nv30_context *nv30 = nv30_context(pipe);
77    unsigned i;
78 
79    for (i = 0; i < nr; i++) {
80       nouveau_bufctx_reset(nv30->bufctx, BUFCTX_VERTTEX(i));
81       pipe_sampler_view_reference(&nv30->vertprog.textures[i], views[i]);
82       nv30->vertprog.dirty_samplers |= (1 << i);
83    }
84 
85    for (; i < nv30->vertprog.num_textures; i++) {
86       nouveau_bufctx_reset(nv30->bufctx, BUFCTX_VERTTEX(i));
87       pipe_sampler_view_reference(&nv30->vertprog.textures[i], NULL);
88       nv30->vertprog.dirty_samplers |= (1 << i);
89    }
90 
91    nv30->vertprog.num_textures = nr;
92    nv30->dirty |= NV30_NEW_VERTTEX;
93 }
94 
95 void
nv40_verttex_init(struct pipe_context * pipe)96 nv40_verttex_init(struct pipe_context *pipe)
97 {
98    pipe->bind_vertex_sampler_states = nv40_verttex_sampler_states_bind;
99    pipe->set_vertex_sampler_views = nv40_verttex_set_sampler_views;
100 }
101