Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4358 | Serge | 1 | /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */ |
2 | |||
3 | /* |
||
4 | * Copyright (C) 2012 Rob Clark |
||
5 | * |
||
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
7 | * copy of this software and associated documentation files (the "Software"), |
||
8 | * to deal in the Software without restriction, including without limitation |
||
9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||
10 | * and/or sell copies of the Software, and to permit persons to whom the |
||
11 | * Software is furnished to do so, subject to the following conditions: |
||
12 | * |
||
13 | * The above copyright notice and this permission notice (including the next |
||
14 | * paragraph) shall be included in all copies or substantial portions of the |
||
15 | * Software. |
||
16 | * |
||
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||
20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||
23 | * SOFTWARE. |
||
24 | * |
||
25 | * Authors: |
||
26 | * Rob Clark |
||
27 | */ |
||
28 | |||
29 | #include "pipe/p_state.h" |
||
30 | #include "util/u_string.h" |
||
31 | #include "util/u_memory.h" |
||
32 | #include "util/u_inlines.h" |
||
33 | |||
34 | #include "freedreno_texture.h" |
||
35 | #include "freedreno_context.h" |
||
36 | #include "freedreno_util.h" |
||
37 | |||
38 | static void |
||
39 | fd_sampler_state_delete(struct pipe_context *pctx, void *hwcso) |
||
40 | { |
||
41 | FREE(hwcso); |
||
42 | } |
||
43 | |||
44 | static void |
||
45 | fd_sampler_view_destroy(struct pipe_context *pctx, |
||
46 | struct pipe_sampler_view *view) |
||
47 | { |
||
48 | pipe_resource_reference(&view->texture, NULL); |
||
49 | FREE(view); |
||
50 | } |
||
51 | |||
52 | static void bind_sampler_states(struct fd_texture_stateobj *prog, |
||
53 | unsigned nr, void **hwcso) |
||
54 | { |
||
55 | unsigned i; |
||
56 | unsigned new_nr = 0; |
||
57 | |||
58 | for (i = 0; i < nr; i++) { |
||
59 | if (hwcso[i]) |
||
60 | new_nr++; |
||
61 | prog->samplers[i] = hwcso[i]; |
||
62 | prog->dirty_samplers |= (1 << i); |
||
63 | } |
||
64 | |||
65 | for (; i < prog->num_samplers; i++) { |
||
66 | prog->samplers[i] = NULL; |
||
67 | prog->dirty_samplers |= (1 << i); |
||
68 | } |
||
69 | |||
70 | prog->num_samplers = new_nr; |
||
71 | } |
||
72 | |||
73 | static void set_sampler_views(struct fd_texture_stateobj *prog, |
||
74 | unsigned nr, struct pipe_sampler_view **views) |
||
75 | { |
||
76 | unsigned i; |
||
77 | unsigned new_nr = 0; |
||
78 | |||
79 | for (i = 0; i < nr; i++) { |
||
80 | if (views[i]) |
||
81 | new_nr++; |
||
82 | pipe_sampler_view_reference(&prog->textures[i], views[i]); |
||
83 | prog->dirty_samplers |= (1 << i); |
||
84 | } |
||
85 | |||
86 | for (; i < prog->num_textures; i++) { |
||
87 | pipe_sampler_view_reference(&prog->textures[i], NULL); |
||
88 | prog->dirty_samplers |= (1 << i); |
||
89 | } |
||
90 | |||
91 | prog->num_textures = new_nr; |
||
92 | } |
||
93 | |||
94 | static void |
||
95 | fd_fragtex_sampler_states_bind(struct pipe_context *pctx, |
||
96 | unsigned nr, void **hwcso) |
||
97 | { |
||
98 | struct fd_context *ctx = fd_context(pctx); |
||
99 | |||
100 | /* on a2xx, since there is a flat address space for textures/samplers, |
||
101 | * a change in # of fragment textures/samplers will trigger patching and |
||
102 | * re-emitting the vertex shader: |
||
103 | */ |
||
104 | if (nr != ctx->fragtex.num_samplers) |
||
105 | ctx->dirty |= FD_DIRTY_TEXSTATE; |
||
106 | |||
107 | bind_sampler_states(&ctx->fragtex, nr, hwcso); |
||
108 | ctx->dirty |= FD_DIRTY_FRAGTEX; |
||
109 | } |
||
110 | |||
111 | |||
112 | static void |
||
113 | fd_fragtex_set_sampler_views(struct pipe_context *pctx, unsigned nr, |
||
114 | struct pipe_sampler_view **views) |
||
115 | { |
||
116 | struct fd_context *ctx = fd_context(pctx); |
||
117 | |||
118 | /* on a2xx, since there is a flat address space for textures/samplers, |
||
119 | * a change in # of fragment textures/samplers will trigger patching and |
||
120 | * re-emitting the vertex shader: |
||
121 | */ |
||
122 | if (nr != ctx->fragtex.num_textures) |
||
123 | ctx->dirty |= FD_DIRTY_TEXSTATE; |
||
124 | |||
125 | set_sampler_views(&ctx->fragtex, nr, views); |
||
126 | ctx->dirty |= FD_DIRTY_FRAGTEX; |
||
127 | } |
||
128 | |||
129 | static void |
||
130 | fd_verttex_sampler_states_bind(struct pipe_context *pctx, |
||
131 | unsigned nr, void **hwcso) |
||
132 | { |
||
133 | struct fd_context *ctx = fd_context(pctx); |
||
134 | bind_sampler_states(&ctx->verttex, nr, hwcso); |
||
135 | ctx->dirty |= FD_DIRTY_VERTTEX; |
||
136 | } |
||
137 | |||
138 | |||
139 | static void |
||
140 | fd_verttex_set_sampler_views(struct pipe_context *pctx, unsigned nr, |
||
141 | struct pipe_sampler_view **views) |
||
142 | { |
||
143 | struct fd_context *ctx = fd_context(pctx); |
||
144 | set_sampler_views(&ctx->verttex, nr, views); |
||
145 | ctx->dirty |= FD_DIRTY_VERTTEX; |
||
146 | } |
||
147 | |||
148 | void |
||
149 | fd_texture_init(struct pipe_context *pctx) |
||
150 | { |
||
151 | pctx->delete_sampler_state = fd_sampler_state_delete; |
||
152 | |||
153 | pctx->sampler_view_destroy = fd_sampler_view_destroy; |
||
154 | |||
155 | pctx->bind_fragment_sampler_states = fd_fragtex_sampler_states_bind; |
||
156 | pctx->set_fragment_sampler_views = fd_fragtex_set_sampler_views; |
||
157 | |||
158 | pctx->bind_vertex_sampler_states = fd_verttex_sampler_states_bind; |
||
159 | pctx->set_vertex_sampler_views = fd_verttex_set_sampler_views; |
||
160 | }><>>><>>><>>><>> |