Rev 4358 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4358 | Rev 4401 | ||
---|---|---|---|
1 | /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */ |
1 | /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */ |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * Copyright (C) 2013 Rob Clark |
4 | * Copyright (C) 2013 Rob Clark |
5 | * |
5 | * |
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
7 | * copy of this software and associated documentation files (the "Software"), |
7 | * copy of this software and associated documentation files (the "Software"), |
8 | * to deal in the Software without restriction, including without limitation |
8 | * to deal in the Software without restriction, including without limitation |
9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
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 |
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: |
11 | * Software is furnished to do so, subject to the following conditions: |
12 | * |
12 | * |
13 | * The above copyright notice and this permission notice (including the next |
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 |
14 | * paragraph) shall be included in all copies or substantial portions of the |
15 | * Software. |
15 | * Software. |
16 | * |
16 | * |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
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, |
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
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 |
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, |
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 |
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
23 | * SOFTWARE. |
23 | * SOFTWARE. |
24 | * |
24 | * |
25 | * Authors: |
25 | * Authors: |
26 | * Rob Clark |
26 | * Rob Clark |
27 | */ |
27 | */ |
28 | 28 | ||
29 | #include "pipe/p_state.h" |
29 | #include "pipe/p_state.h" |
30 | #include "util/u_string.h" |
30 | #include "util/u_string.h" |
31 | #include "util/u_memory.h" |
31 | #include "util/u_memory.h" |
32 | #include "util/u_inlines.h" |
32 | #include "util/u_inlines.h" |
33 | 33 | ||
34 | #include "fd3_texture.h" |
34 | #include "fd3_texture.h" |
35 | #include "fd3_util.h" |
35 | #include "fd3_util.h" |
36 | 36 | ||
37 | static enum a3xx_tex_clamp |
37 | static enum a3xx_tex_clamp |
38 | tex_clamp(unsigned wrap) |
38 | tex_clamp(unsigned wrap) |
39 | { |
39 | { |
40 | /* hardware probably supports more, but we can't coax all the |
40 | /* hardware probably supports more, but we can't coax all the |
41 | * wrap/clamp modes out of the GLESv2 blob driver. |
41 | * wrap/clamp modes out of the GLESv2 blob driver. |
42 | * |
42 | * |
43 | * TODO once we have basics working, go back and just try |
43 | * TODO once we have basics working, go back and just try |
44 | * different values and see what happens |
44 | * different values and see what happens |
45 | */ |
45 | */ |
46 | switch (wrap) { |
46 | switch (wrap) { |
47 | case PIPE_TEX_WRAP_REPEAT: |
47 | case PIPE_TEX_WRAP_REPEAT: |
48 | return A3XX_TEX_REPEAT; |
48 | return A3XX_TEX_REPEAT; |
49 | case PIPE_TEX_WRAP_CLAMP: |
49 | case PIPE_TEX_WRAP_CLAMP: |
50 | case PIPE_TEX_WRAP_CLAMP_TO_BORDER: |
50 | case PIPE_TEX_WRAP_CLAMP_TO_BORDER: |
51 | case PIPE_TEX_WRAP_CLAMP_TO_EDGE: |
51 | case PIPE_TEX_WRAP_CLAMP_TO_EDGE: |
52 | return A3XX_TEX_CLAMP_TO_EDGE; |
52 | return A3XX_TEX_CLAMP_TO_EDGE; |
53 | case PIPE_TEX_WRAP_MIRROR_CLAMP: |
53 | case PIPE_TEX_WRAP_MIRROR_CLAMP: |
54 | case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: |
54 | case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: |
55 | case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: |
55 | case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: |
56 | case PIPE_TEX_WRAP_MIRROR_REPEAT: |
56 | case PIPE_TEX_WRAP_MIRROR_REPEAT: |
57 | return A3XX_TEX_MIRROR_REPEAT; |
57 | return A3XX_TEX_MIRROR_REPEAT; |
58 | default: |
58 | default: |
59 | DBG("invalid wrap: %u", wrap); |
59 | DBG("invalid wrap: %u", wrap); |
60 | return 0; |
60 | return 0; |
61 | } |
61 | } |
62 | } |
62 | } |
63 | 63 | ||
64 | static enum a3xx_tex_filter |
64 | static enum a3xx_tex_filter |
65 | tex_filter(unsigned filter) |
65 | tex_filter(unsigned filter) |
66 | { |
66 | { |
67 | switch (filter) { |
67 | switch (filter) { |
68 | case PIPE_TEX_FILTER_NEAREST: |
68 | case PIPE_TEX_FILTER_NEAREST: |
69 | return A3XX_TEX_NEAREST; |
69 | return A3XX_TEX_NEAREST; |
70 | case PIPE_TEX_FILTER_LINEAR: |
70 | case PIPE_TEX_FILTER_LINEAR: |
71 | return A3XX_TEX_LINEAR; |
71 | return A3XX_TEX_LINEAR; |
72 | default: |
72 | default: |
73 | DBG("invalid filter: %u", filter); |
73 | DBG("invalid filter: %u", filter); |
74 | return 0; |
74 | return 0; |
75 | } |
75 | } |
76 | } |
76 | } |
77 | 77 | ||
78 | static void * |
78 | static void * |
79 | fd3_sampler_state_create(struct pipe_context *pctx, |
79 | fd3_sampler_state_create(struct pipe_context *pctx, |
80 | const struct pipe_sampler_state *cso) |
80 | const struct pipe_sampler_state *cso) |
81 | { |
81 | { |
82 | struct fd3_sampler_stateobj *so = CALLOC_STRUCT(fd3_sampler_stateobj); |
82 | struct fd3_sampler_stateobj *so = CALLOC_STRUCT(fd3_sampler_stateobj); |
83 | 83 | ||
84 | if (!so) |
84 | if (!so) |
85 | return NULL; |
85 | return NULL; |
86 | 86 | ||
87 | so->base = *cso; |
87 | so->base = *cso; |
88 | 88 | ||
89 | so->texsamp0 = |
89 | so->texsamp0 = |
- | 90 | COND(!cso->normalized_coords, A3XX_TEX_SAMP_0_UNNORM_COORDS) | |
|
90 | A3XX_TEX_SAMP_0_XY_MAG(tex_filter(cso->mag_img_filter)) | |
91 | A3XX_TEX_SAMP_0_XY_MAG(tex_filter(cso->mag_img_filter)) | |
91 | A3XX_TEX_SAMP_0_XY_MIN(tex_filter(cso->min_img_filter)) | |
92 | A3XX_TEX_SAMP_0_XY_MIN(tex_filter(cso->min_img_filter)) | |
92 | A3XX_TEX_SAMP_0_WRAP_S(tex_clamp(cso->wrap_s)) | |
93 | A3XX_TEX_SAMP_0_WRAP_S(tex_clamp(cso->wrap_s)) | |
93 | A3XX_TEX_SAMP_0_WRAP_T(tex_clamp(cso->wrap_t)) | |
94 | A3XX_TEX_SAMP_0_WRAP_T(tex_clamp(cso->wrap_t)) | |
94 | A3XX_TEX_SAMP_0_WRAP_R(tex_clamp(cso->wrap_r)); |
95 | A3XX_TEX_SAMP_0_WRAP_R(tex_clamp(cso->wrap_r)); |
95 | so->texsamp1 = 0x00000000; /* ??? */ |
96 | so->texsamp1 = 0x00000000; /* ??? */ |
96 | 97 | ||
97 | return so; |
98 | return so; |
98 | } |
99 | } |
- | 100 | ||
- | 101 | static enum a3xx_tex_type |
|
- | 102 | tex_type(unsigned target) |
|
- | 103 | { |
|
- | 104 | switch (target) { |
|
- | 105 | default: |
|
- | 106 | assert(0); |
|
- | 107 | case PIPE_BUFFER: |
|
- | 108 | case PIPE_TEXTURE_1D: |
|
- | 109 | case PIPE_TEXTURE_1D_ARRAY: |
|
- | 110 | return A3XX_TEX_1D; |
|
- | 111 | case PIPE_TEXTURE_RECT: |
|
- | 112 | case PIPE_TEXTURE_2D: |
|
- | 113 | case PIPE_TEXTURE_2D_ARRAY: |
|
- | 114 | return A3XX_TEX_2D; |
|
- | 115 | case PIPE_TEXTURE_3D: |
|
- | 116 | return A3XX_TEX_3D; |
|
- | 117 | case PIPE_TEXTURE_CUBE: |
|
- | 118 | case PIPE_TEXTURE_CUBE_ARRAY: |
|
- | 119 | return A3XX_TEX_CUBE; |
|
- | 120 | } |
|
- | 121 | } |
|
99 | 122 | ||
100 | static struct pipe_sampler_view * |
123 | static struct pipe_sampler_view * |
101 | fd3_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc, |
124 | fd3_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc, |
102 | const struct pipe_sampler_view *cso) |
125 | const struct pipe_sampler_view *cso) |
103 | { |
126 | { |
104 | struct fd3_pipe_sampler_view *so = CALLOC_STRUCT(fd3_pipe_sampler_view); |
127 | struct fd3_pipe_sampler_view *so = CALLOC_STRUCT(fd3_pipe_sampler_view); |
105 | struct fd_resource *rsc = fd_resource(prsc); |
128 | struct fd_resource *rsc = fd_resource(prsc); |
106 | 129 | ||
107 | if (!so) |
130 | if (!so) |
108 | return NULL; |
131 | return NULL; |
109 | 132 | ||
110 | so->base = *cso; |
133 | so->base = *cso; |
111 | pipe_reference(NULL, &prsc->reference); |
134 | pipe_reference(NULL, &prsc->reference); |
112 | so->base.texture = prsc; |
135 | so->base.texture = prsc; |
113 | so->base.reference.count = 1; |
136 | so->base.reference.count = 1; |
114 | so->base.context = pctx; |
137 | so->base.context = pctx; |
115 | 138 | ||
116 | so->tex_resource = rsc; |
139 | so->tex_resource = rsc; |
117 | 140 | ||
118 | so->texconst0 = |
141 | so->texconst0 = |
119 | 0x40000000 | /* ??? */ |
142 | A3XX_TEX_CONST_0_TYPE(tex_type(prsc->target)) | |
120 | A3XX_TEX_CONST_0_FMT(fd3_pipe2tex(cso->format)) | |
143 | A3XX_TEX_CONST_0_FMT(fd3_pipe2tex(cso->format)) | |
121 | fd3_tex_swiz(cso->format, cso->swizzle_r, cso->swizzle_g, |
144 | fd3_tex_swiz(cso->format, cso->swizzle_r, cso->swizzle_g, |
122 | cso->swizzle_b, cso->swizzle_a); |
145 | cso->swizzle_b, cso->swizzle_a); |
123 | so->texconst1 = |
146 | so->texconst1 = |
124 | A3XX_TEX_CONST_1_FETCHSIZE(fd3_pipe2fetchsize(cso->format)) | |
147 | A3XX_TEX_CONST_1_FETCHSIZE(fd3_pipe2fetchsize(cso->format)) | |
125 | A3XX_TEX_CONST_1_WIDTH(prsc->width0) | |
148 | A3XX_TEX_CONST_1_WIDTH(prsc->width0) | |
126 | A3XX_TEX_CONST_1_HEIGHT(prsc->height0); |
149 | A3XX_TEX_CONST_1_HEIGHT(prsc->height0); |
127 | /* when emitted, A3XX_TEX_CONST_2_INDX() must be OR'd in: */ |
150 | /* when emitted, A3XX_TEX_CONST_2_INDX() must be OR'd in: */ |
128 | so->texconst2 = |
151 | so->texconst2 = |
129 | A3XX_TEX_CONST_2_PITCH(rsc->pitch * rsc->cpp); |
152 | A3XX_TEX_CONST_2_PITCH(rsc->pitch * rsc->cpp); |
130 | so->texconst3 = 0x00000000; /* ??? */ |
153 | so->texconst3 = 0x00000000; /* ??? */ |
131 | 154 | ||
132 | return &so->base; |
155 | return &so->base; |
133 | } |
156 | } |
134 | 157 | ||
135 | void |
158 | void |
136 | fd3_texture_init(struct pipe_context *pctx) |
159 | fd3_texture_init(struct pipe_context *pctx) |
137 | { |
160 | { |
138 | pctx->create_sampler_state = fd3_sampler_state_create; |
161 | pctx->create_sampler_state = fd3_sampler_state_create; |
139 | pctx->create_sampler_view = fd3_sampler_view_create; |
162 | pctx->create_sampler_view = fd3_sampler_view_create; |
140 | } |
163 | } |