1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright (c) 2012-2015 Etnaviv Project
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sub license,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
12bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
13bf215546Sopenharmony_ci * of the Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21bf215546Sopenharmony_ci * DEALINGS IN THE SOFTWARE.
22bf215546Sopenharmony_ci *
23bf215546Sopenharmony_ci * Authors:
24bf215546Sopenharmony_ci *    Wladimir J. van der Laan <laanwj@gmail.com>
25bf215546Sopenharmony_ci */
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci#include "etnaviv_texture_state.h"
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci#include "hw/common.xml.h"
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ci#include "etnaviv_clear_blit.h"
32bf215546Sopenharmony_ci#include "etnaviv_context.h"
33bf215546Sopenharmony_ci#include "etnaviv_emit.h"
34bf215546Sopenharmony_ci#include "etnaviv_format.h"
35bf215546Sopenharmony_ci#include "etnaviv_texture.h"
36bf215546Sopenharmony_ci#include "etnaviv_translate.h"
37bf215546Sopenharmony_ci#include "util/u_inlines.h"
38bf215546Sopenharmony_ci#include "util/u_memory.h"
39bf215546Sopenharmony_ci
40bf215546Sopenharmony_ci#include "drm-uapi/drm_fourcc.h"
41bf215546Sopenharmony_ci
42bf215546Sopenharmony_cistruct etna_sampler_state {
43bf215546Sopenharmony_ci   struct pipe_sampler_state base;
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_ci   /* sampler offset +4*sampler, interleave when committing state */
46bf215546Sopenharmony_ci   uint32_t config0;
47bf215546Sopenharmony_ci   uint32_t config1;
48bf215546Sopenharmony_ci   uint32_t config_lod;
49bf215546Sopenharmony_ci   uint32_t config_3d;
50bf215546Sopenharmony_ci   uint32_t baselod;
51bf215546Sopenharmony_ci   unsigned min_lod, max_lod, max_lod_min;
52bf215546Sopenharmony_ci};
53bf215546Sopenharmony_ci
54bf215546Sopenharmony_cistatic inline struct etna_sampler_state *
55bf215546Sopenharmony_cietna_sampler_state(struct pipe_sampler_state *samp)
56bf215546Sopenharmony_ci{
57bf215546Sopenharmony_ci   return (struct etna_sampler_state *)samp;
58bf215546Sopenharmony_ci}
59bf215546Sopenharmony_ci
60bf215546Sopenharmony_cistruct etna_sampler_view {
61bf215546Sopenharmony_ci   struct pipe_sampler_view base;
62bf215546Sopenharmony_ci
63bf215546Sopenharmony_ci   /* sampler offset +4*sampler, interleave when committing state */
64bf215546Sopenharmony_ci   uint32_t config0;
65bf215546Sopenharmony_ci   uint32_t config0_mask;
66bf215546Sopenharmony_ci   uint32_t config1;
67bf215546Sopenharmony_ci   uint32_t config_3d;
68bf215546Sopenharmony_ci   uint32_t size;
69bf215546Sopenharmony_ci   uint32_t log_size;
70bf215546Sopenharmony_ci   uint32_t astc0;
71bf215546Sopenharmony_ci   uint32_t linear_stride;  /* only LOD0 */
72bf215546Sopenharmony_ci   struct etna_reloc lod_addr[VIVS_TE_SAMPLER_LOD_ADDR__LEN];
73bf215546Sopenharmony_ci   unsigned min_lod, max_lod; /* 5.5 fixp */
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_ci   struct etna_sampler_ts ts;
76bf215546Sopenharmony_ci};
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_cistatic inline struct etna_sampler_view *
79bf215546Sopenharmony_cietna_sampler_view(struct pipe_sampler_view *view)
80bf215546Sopenharmony_ci{
81bf215546Sopenharmony_ci   return (struct etna_sampler_view *)view;
82bf215546Sopenharmony_ci}
83bf215546Sopenharmony_ci
84bf215546Sopenharmony_cistatic void *
85bf215546Sopenharmony_cietna_create_sampler_state_state(struct pipe_context *pipe,
86bf215546Sopenharmony_ci                          const struct pipe_sampler_state *ss)
87bf215546Sopenharmony_ci{
88bf215546Sopenharmony_ci   struct etna_sampler_state *cs = CALLOC_STRUCT(etna_sampler_state);
89bf215546Sopenharmony_ci   struct etna_context *ctx = etna_context(pipe);
90bf215546Sopenharmony_ci   struct etna_screen *screen = ctx->screen;
91bf215546Sopenharmony_ci   const bool ansio = ss->max_anisotropy > 1;
92bf215546Sopenharmony_ci   const bool mipmap = ss->min_mip_filter != PIPE_TEX_MIPFILTER_NONE;
93bf215546Sopenharmony_ci
94bf215546Sopenharmony_ci   if (!cs)
95bf215546Sopenharmony_ci      return NULL;
96bf215546Sopenharmony_ci
97bf215546Sopenharmony_ci   cs->base = *ss;
98bf215546Sopenharmony_ci
99bf215546Sopenharmony_ci   cs->config0 =
100bf215546Sopenharmony_ci      VIVS_TE_SAMPLER_CONFIG0_UWRAP(translate_texture_wrapmode(ss->wrap_s)) |
101bf215546Sopenharmony_ci      VIVS_TE_SAMPLER_CONFIG0_VWRAP(translate_texture_wrapmode(ss->wrap_t)) |
102bf215546Sopenharmony_ci      VIVS_TE_SAMPLER_CONFIG0_MIN(translate_texture_filter(ss->min_img_filter)) |
103bf215546Sopenharmony_ci      VIVS_TE_SAMPLER_CONFIG0_MIP(translate_texture_mipfilter(ss->min_mip_filter)) |
104bf215546Sopenharmony_ci      VIVS_TE_SAMPLER_CONFIG0_MAG(translate_texture_filter(ss->mag_img_filter)) |
105bf215546Sopenharmony_ci      VIVS_TE_SAMPLER_CONFIG0_ANISOTROPY(COND(ansio, etna_log2_fixp55(ss->max_anisotropy)));
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_ci   /* ROUND_UV improves precision - but not compatible with NEAREST filter */
108bf215546Sopenharmony_ci   if (ss->min_img_filter != PIPE_TEX_FILTER_NEAREST &&
109bf215546Sopenharmony_ci       ss->mag_img_filter != PIPE_TEX_FILTER_NEAREST) {
110bf215546Sopenharmony_ci      cs->config0 |= VIVS_TE_SAMPLER_CONFIG0_ROUND_UV;
111bf215546Sopenharmony_ci   }
112bf215546Sopenharmony_ci
113bf215546Sopenharmony_ci   cs->config1 = screen->specs.seamless_cube_map ?
114bf215546Sopenharmony_ci      COND(ss->seamless_cube_map, VIVS_TE_SAMPLER_CONFIG1_SEAMLESS_CUBE_MAP) : 0;
115bf215546Sopenharmony_ci
116bf215546Sopenharmony_ci   cs->config_lod =
117bf215546Sopenharmony_ci      COND(ss->lod_bias != 0.0 && mipmap, VIVS_TE_SAMPLER_LOD_CONFIG_BIAS_ENABLE) |
118bf215546Sopenharmony_ci      VIVS_TE_SAMPLER_LOD_CONFIG_BIAS(etna_float_to_fixp55(ss->lod_bias));
119bf215546Sopenharmony_ci
120bf215546Sopenharmony_ci   cs->config_3d =
121bf215546Sopenharmony_ci      VIVS_TE_SAMPLER_3D_CONFIG_WRAP(translate_texture_wrapmode(ss->wrap_r));
122bf215546Sopenharmony_ci
123bf215546Sopenharmony_ci   if (mipmap) {
124bf215546Sopenharmony_ci      cs->min_lod = etna_float_to_fixp55(ss->min_lod);
125bf215546Sopenharmony_ci      cs->max_lod = etna_float_to_fixp55(ss->max_lod);
126bf215546Sopenharmony_ci   } else {
127bf215546Sopenharmony_ci      /* when not mipmapping, we need to set max/min lod so that always
128bf215546Sopenharmony_ci       * lowest LOD is selected */
129bf215546Sopenharmony_ci      cs->min_lod = cs->max_lod = etna_float_to_fixp55(0.0f);
130bf215546Sopenharmony_ci   }
131bf215546Sopenharmony_ci
132bf215546Sopenharmony_ci   /* if max_lod is 0, MIN filter will never be used (GC3000)
133bf215546Sopenharmony_ci    * when min filter is different from mag filter, we need HW to compute LOD
134bf215546Sopenharmony_ci    * the workaround is to set max_lod to at least 1
135bf215546Sopenharmony_ci    */
136bf215546Sopenharmony_ci   cs->max_lod_min = (ss->min_img_filter != ss->mag_img_filter) ? 1 : 0;
137bf215546Sopenharmony_ci
138bf215546Sopenharmony_ci   cs->baselod =
139bf215546Sopenharmony_ci      COND(ss->compare_mode, VIVS_NTE_SAMPLER_BASELOD_COMPARE_ENABLE) |
140bf215546Sopenharmony_ci      VIVS_NTE_SAMPLER_BASELOD_COMPARE_FUNC(translate_texture_compare(ss->compare_func));
141bf215546Sopenharmony_ci
142bf215546Sopenharmony_ci   /* force nearest filting for nir_lower_sample_tex_compare(..) */
143bf215546Sopenharmony_ci   if ((ctx->screen->specs.halti < 2) && ss->compare_mode) {
144bf215546Sopenharmony_ci      cs->config0 &= ~VIVS_TE_SAMPLER_CONFIG0_MIN__MASK;
145bf215546Sopenharmony_ci      cs->config0 &= ~VIVS_TE_SAMPLER_CONFIG0_MAG__MASK;
146bf215546Sopenharmony_ci
147bf215546Sopenharmony_ci      cs->config0 |=
148bf215546Sopenharmony_ci         VIVS_TE_SAMPLER_CONFIG0_MIN(TEXTURE_FILTER_NEAREST) |
149bf215546Sopenharmony_ci         VIVS_TE_SAMPLER_CONFIG0_MAG(TEXTURE_FILTER_NEAREST);
150bf215546Sopenharmony_ci   }
151bf215546Sopenharmony_ci
152bf215546Sopenharmony_ci   return cs;
153bf215546Sopenharmony_ci}
154bf215546Sopenharmony_ci
155bf215546Sopenharmony_cistatic void
156bf215546Sopenharmony_cietna_delete_sampler_state_state(struct pipe_context *pctx, void *ss)
157bf215546Sopenharmony_ci{
158bf215546Sopenharmony_ci   FREE(ss);
159bf215546Sopenharmony_ci}
160bf215546Sopenharmony_ci
161bf215546Sopenharmony_cistatic struct pipe_sampler_view *
162bf215546Sopenharmony_cietna_create_sampler_view_state(struct pipe_context *pctx, struct pipe_resource *prsc,
163bf215546Sopenharmony_ci                         const struct pipe_sampler_view *so)
164bf215546Sopenharmony_ci{
165bf215546Sopenharmony_ci   struct etna_sampler_view *sv = CALLOC_STRUCT(etna_sampler_view);
166bf215546Sopenharmony_ci   struct etna_context *ctx = etna_context(pctx);
167bf215546Sopenharmony_ci   struct etna_screen *screen = ctx->screen;
168bf215546Sopenharmony_ci   const uint32_t format = translate_texture_format(so->format);
169bf215546Sopenharmony_ci   const bool ext = !!(format & EXT_FORMAT);
170bf215546Sopenharmony_ci   const bool astc = !!(format & ASTC_FORMAT);
171bf215546Sopenharmony_ci   const bool srgb = util_format_is_srgb(so->format);
172bf215546Sopenharmony_ci   const uint32_t swiz = get_texture_swiz(so->format, so->swizzle_r,
173bf215546Sopenharmony_ci                                          so->swizzle_g, so->swizzle_b,
174bf215546Sopenharmony_ci                                          so->swizzle_a);
175bf215546Sopenharmony_ci
176bf215546Sopenharmony_ci   if (!sv)
177bf215546Sopenharmony_ci      return NULL;
178bf215546Sopenharmony_ci
179bf215546Sopenharmony_ci   struct etna_resource *res = etna_texture_handle_incompatible(pctx, prsc);
180bf215546Sopenharmony_ci   if (!res) {
181bf215546Sopenharmony_ci      free(sv);
182bf215546Sopenharmony_ci      return NULL;
183bf215546Sopenharmony_ci   }
184bf215546Sopenharmony_ci
185bf215546Sopenharmony_ci   sv->base = *so;
186bf215546Sopenharmony_ci   pipe_reference_init(&sv->base.reference, 1);
187bf215546Sopenharmony_ci   sv->base.texture = NULL;
188bf215546Sopenharmony_ci   pipe_resource_reference(&sv->base.texture, prsc);
189bf215546Sopenharmony_ci   sv->base.context = pctx;
190bf215546Sopenharmony_ci
191bf215546Sopenharmony_ci   /* merged with sampler state */
192bf215546Sopenharmony_ci   sv->config0 =
193bf215546Sopenharmony_ci      VIVS_TE_SAMPLER_CONFIG0_TYPE(translate_texture_target(sv->base.target)) |
194bf215546Sopenharmony_ci      COND(!ext && !astc, VIVS_TE_SAMPLER_CONFIG0_FORMAT(format));
195bf215546Sopenharmony_ci   sv->config0_mask = 0xffffffff;
196bf215546Sopenharmony_ci
197bf215546Sopenharmony_ci   uint32_t base_height = res->base.height0;
198bf215546Sopenharmony_ci   uint32_t base_depth = res->base.depth0;
199bf215546Sopenharmony_ci   bool is_array = false;
200bf215546Sopenharmony_ci
201bf215546Sopenharmony_ci   switch (sv->base.target) {
202bf215546Sopenharmony_ci   case PIPE_TEXTURE_1D:
203bf215546Sopenharmony_ci      /* use 2D texture with T wrap to repeat for 1D texture
204bf215546Sopenharmony_ci       * TODO: check if old HW supports 1D texture
205bf215546Sopenharmony_ci       */
206bf215546Sopenharmony_ci      sv->config0_mask = ~VIVS_TE_SAMPLER_CONFIG0_VWRAP__MASK;
207bf215546Sopenharmony_ci      sv->config0 &= ~VIVS_TE_SAMPLER_CONFIG0_TYPE__MASK;
208bf215546Sopenharmony_ci      sv->config0 |=
209bf215546Sopenharmony_ci         VIVS_TE_SAMPLER_CONFIG0_TYPE(TEXTURE_TYPE_2D) |
210bf215546Sopenharmony_ci         VIVS_TE_SAMPLER_CONFIG0_VWRAP(TEXTURE_WRAPMODE_REPEAT);
211bf215546Sopenharmony_ci      break;
212bf215546Sopenharmony_ci   case PIPE_TEXTURE_1D_ARRAY:
213bf215546Sopenharmony_ci      is_array = true;
214bf215546Sopenharmony_ci      base_height = res->base.array_size;
215bf215546Sopenharmony_ci      break;
216bf215546Sopenharmony_ci   case PIPE_TEXTURE_2D_ARRAY:
217bf215546Sopenharmony_ci      is_array = true;
218bf215546Sopenharmony_ci      base_depth = res->base.array_size;
219bf215546Sopenharmony_ci      break;
220bf215546Sopenharmony_ci   default:
221bf215546Sopenharmony_ci      break;
222bf215546Sopenharmony_ci   }
223bf215546Sopenharmony_ci
224bf215546Sopenharmony_ci   if (res->layout == ETNA_LAYOUT_LINEAR && !util_format_is_compressed(so->format)) {
225bf215546Sopenharmony_ci      sv->config0 |= VIVS_TE_SAMPLER_CONFIG0_ADDRESSING_MODE(TEXTURE_ADDRESSING_MODE_LINEAR);
226bf215546Sopenharmony_ci
227bf215546Sopenharmony_ci      assert(res->base.last_level == 0);
228bf215546Sopenharmony_ci      sv->linear_stride = res->levels[0].stride;
229bf215546Sopenharmony_ci   } else {
230bf215546Sopenharmony_ci      sv->config0 |= VIVS_TE_SAMPLER_CONFIG0_ADDRESSING_MODE(TEXTURE_ADDRESSING_MODE_TILED);
231bf215546Sopenharmony_ci      sv->linear_stride = 0;
232bf215546Sopenharmony_ci   }
233bf215546Sopenharmony_ci
234bf215546Sopenharmony_ci   sv->config1 |= COND(ext, VIVS_TE_SAMPLER_CONFIG1_FORMAT_EXT(format)) |
235bf215546Sopenharmony_ci                  COND(astc, VIVS_TE_SAMPLER_CONFIG1_FORMAT_EXT(TEXTURE_FORMAT_EXT_ASTC)) |
236bf215546Sopenharmony_ci                  COND(is_array, VIVS_TE_SAMPLER_CONFIG1_TEXTURE_ARRAY) |
237bf215546Sopenharmony_ci                  VIVS_TE_SAMPLER_CONFIG1_HALIGN(res->halign) | swiz;
238bf215546Sopenharmony_ci   sv->astc0 = COND(astc, VIVS_NTE_SAMPLER_ASTC0_ASTC_FORMAT(format)) |
239bf215546Sopenharmony_ci               COND(astc && srgb, VIVS_NTE_SAMPLER_ASTC0_ASTC_SRGB) |
240bf215546Sopenharmony_ci               VIVS_NTE_SAMPLER_ASTC0_UNK8(0xc) |
241bf215546Sopenharmony_ci               VIVS_NTE_SAMPLER_ASTC0_UNK16(0xc) |
242bf215546Sopenharmony_ci               VIVS_NTE_SAMPLER_ASTC0_UNK24(0xc);
243bf215546Sopenharmony_ci   sv->size = VIVS_TE_SAMPLER_SIZE_WIDTH(res->base.width0) |
244bf215546Sopenharmony_ci              VIVS_TE_SAMPLER_SIZE_HEIGHT(base_height);
245bf215546Sopenharmony_ci   sv->log_size =
246bf215546Sopenharmony_ci      VIVS_TE_SAMPLER_LOG_SIZE_WIDTH(etna_log2_fixp55(res->base.width0)) |
247bf215546Sopenharmony_ci      VIVS_TE_SAMPLER_LOG_SIZE_HEIGHT(etna_log2_fixp55(base_height)) |
248bf215546Sopenharmony_ci      COND(util_format_is_srgb(so->format) && !astc, VIVS_TE_SAMPLER_LOG_SIZE_SRGB) |
249bf215546Sopenharmony_ci      COND(astc, VIVS_TE_SAMPLER_LOG_SIZE_ASTC);
250bf215546Sopenharmony_ci   sv->config_3d =
251bf215546Sopenharmony_ci      VIVS_TE_SAMPLER_3D_CONFIG_DEPTH(base_depth) |
252bf215546Sopenharmony_ci      VIVS_TE_SAMPLER_3D_CONFIG_LOG_DEPTH(etna_log2_fixp55(base_depth));
253bf215546Sopenharmony_ci
254bf215546Sopenharmony_ci   /* Set up levels-of-detail */
255bf215546Sopenharmony_ci   for (int lod = 0; lod <= res->base.last_level; ++lod) {
256bf215546Sopenharmony_ci      sv->lod_addr[lod].bo = res->bo;
257bf215546Sopenharmony_ci      sv->lod_addr[lod].offset = res->levels[lod].offset;
258bf215546Sopenharmony_ci      sv->lod_addr[lod].flags = ETNA_RELOC_READ;
259bf215546Sopenharmony_ci   }
260bf215546Sopenharmony_ci   sv->min_lod = sv->base.u.tex.first_level << 5;
261bf215546Sopenharmony_ci   sv->max_lod = MIN2(sv->base.u.tex.last_level, res->base.last_level) << 5;
262bf215546Sopenharmony_ci
263bf215546Sopenharmony_ci   /* Workaround for npot textures -- it appears that only CLAMP_TO_EDGE is
264bf215546Sopenharmony_ci    * supported when the appropriate capability is not set. */
265bf215546Sopenharmony_ci   if (!screen->specs.npot_tex_any_wrap &&
266bf215546Sopenharmony_ci       (!util_is_power_of_two_or_zero(res->base.width0) ||
267bf215546Sopenharmony_ci        !util_is_power_of_two_or_zero(res->base.height0))) {
268bf215546Sopenharmony_ci      sv->config0_mask = ~(VIVS_TE_SAMPLER_CONFIG0_UWRAP__MASK |
269bf215546Sopenharmony_ci                           VIVS_TE_SAMPLER_CONFIG0_VWRAP__MASK);
270bf215546Sopenharmony_ci      sv->config0 |=
271bf215546Sopenharmony_ci         VIVS_TE_SAMPLER_CONFIG0_UWRAP(TEXTURE_WRAPMODE_CLAMP_TO_EDGE) |
272bf215546Sopenharmony_ci         VIVS_TE_SAMPLER_CONFIG0_VWRAP(TEXTURE_WRAPMODE_CLAMP_TO_EDGE);
273bf215546Sopenharmony_ci   }
274bf215546Sopenharmony_ci
275bf215546Sopenharmony_ci   return &sv->base;
276bf215546Sopenharmony_ci}
277bf215546Sopenharmony_ci
278bf215546Sopenharmony_cistatic void
279bf215546Sopenharmony_cietna_sampler_view_state_destroy(struct pipe_context *pctx,
280bf215546Sopenharmony_ci                          struct pipe_sampler_view *view)
281bf215546Sopenharmony_ci{
282bf215546Sopenharmony_ci   pipe_resource_reference(&view->texture, NULL);
283bf215546Sopenharmony_ci   FREE(view);
284bf215546Sopenharmony_ci}
285bf215546Sopenharmony_ci
286bf215546Sopenharmony_ci#define EMIT_STATE(state_name, src_value) \
287bf215546Sopenharmony_ci   etna_coalsence_emit(stream, &coalesce, VIVS_##state_name, src_value)
288bf215546Sopenharmony_ci
289bf215546Sopenharmony_ci#define EMIT_STATE_FIXP(state_name, src_value) \
290bf215546Sopenharmony_ci   etna_coalsence_emit_fixp(stream, &coalesce, VIVS_##state_name, src_value)
291bf215546Sopenharmony_ci
292bf215546Sopenharmony_ci#define EMIT_STATE_RELOC(state_name, src_value) \
293bf215546Sopenharmony_ci   etna_coalsence_emit_reloc(stream, &coalesce, VIVS_##state_name, src_value)
294bf215546Sopenharmony_ci
295bf215546Sopenharmony_cistatic void
296bf215546Sopenharmony_cietna_emit_ts_state(struct etna_context *ctx)
297bf215546Sopenharmony_ci{
298bf215546Sopenharmony_ci   struct etna_cmd_stream *stream = ctx->stream;
299bf215546Sopenharmony_ci   uint32_t active_samplers = active_samplers_bits(ctx);
300bf215546Sopenharmony_ci   uint32_t dirty = ctx->dirty;
301bf215546Sopenharmony_ci   struct etna_coalesce coalesce;
302bf215546Sopenharmony_ci
303bf215546Sopenharmony_ci   etna_coalesce_start(stream, &coalesce);
304bf215546Sopenharmony_ci
305bf215546Sopenharmony_ci   if (unlikely(dirty & ETNA_DIRTY_SAMPLER_VIEWS)) {
306bf215546Sopenharmony_ci      for (int x = 0; x < VIVS_TS_SAMPLER__LEN; ++x) {
307bf215546Sopenharmony_ci         if ((1 << x) & active_samplers) {
308bf215546Sopenharmony_ci            struct etna_sampler_view *sv = etna_sampler_view(ctx->sampler_view[x]);
309bf215546Sopenharmony_ci            /*01720*/ EMIT_STATE(TS_SAMPLER_CONFIG(x), sv->ts.TS_SAMPLER_CONFIG);
310bf215546Sopenharmony_ci         }
311bf215546Sopenharmony_ci      }
312bf215546Sopenharmony_ci      for (int x = 0; x < VIVS_TS_SAMPLER__LEN; ++x) {
313bf215546Sopenharmony_ci         if ((1 << x) & active_samplers) {
314bf215546Sopenharmony_ci            struct etna_sampler_view *sv = etna_sampler_view(ctx->sampler_view[x]);
315bf215546Sopenharmony_ci            /*01740*/ EMIT_STATE_RELOC(TS_SAMPLER_STATUS_BASE(x), &sv->ts.TS_SAMPLER_STATUS_BASE);
316bf215546Sopenharmony_ci         }
317bf215546Sopenharmony_ci      }
318bf215546Sopenharmony_ci      for (int x = 0; x < VIVS_TS_SAMPLER__LEN; ++x) {
319bf215546Sopenharmony_ci         if ((1 << x) & active_samplers) {
320bf215546Sopenharmony_ci            struct etna_sampler_view *sv = etna_sampler_view(ctx->sampler_view[x]);
321bf215546Sopenharmony_ci            /*01760*/ EMIT_STATE(TS_SAMPLER_CLEAR_VALUE(x), sv->ts.TS_SAMPLER_CLEAR_VALUE);
322bf215546Sopenharmony_ci         }
323bf215546Sopenharmony_ci      }
324bf215546Sopenharmony_ci      for (int x = 0; x < VIVS_TS_SAMPLER__LEN; ++x) {
325bf215546Sopenharmony_ci         if ((1 << x) & active_samplers) {
326bf215546Sopenharmony_ci            struct etna_sampler_view *sv = etna_sampler_view(ctx->sampler_view[x]);
327bf215546Sopenharmony_ci            /*01780*/ EMIT_STATE(TS_SAMPLER_CLEAR_VALUE2(x), sv->ts.TS_SAMPLER_CLEAR_VALUE2);
328bf215546Sopenharmony_ci         }
329bf215546Sopenharmony_ci      }
330bf215546Sopenharmony_ci   }
331bf215546Sopenharmony_ci
332bf215546Sopenharmony_ci   etna_coalesce_end(stream, &coalesce);
333bf215546Sopenharmony_ci}
334bf215546Sopenharmony_ci
335bf215546Sopenharmony_cistatic void
336bf215546Sopenharmony_cietna_emit_new_texture_state(struct etna_context *ctx)
337bf215546Sopenharmony_ci{
338bf215546Sopenharmony_ci   struct etna_cmd_stream *stream = ctx->stream;
339bf215546Sopenharmony_ci   struct etna_screen *screen = ctx->screen;
340bf215546Sopenharmony_ci   uint32_t active_samplers = active_samplers_bits(ctx);
341bf215546Sopenharmony_ci   uint32_t dirty = ctx->dirty;
342bf215546Sopenharmony_ci   struct etna_coalesce coalesce;
343bf215546Sopenharmony_ci
344bf215546Sopenharmony_ci   etna_emit_ts_state(ctx);
345bf215546Sopenharmony_ci
346bf215546Sopenharmony_ci   etna_coalesce_start(stream, &coalesce);
347bf215546Sopenharmony_ci
348bf215546Sopenharmony_ci   if (unlikely(dirty & (ETNA_DIRTY_SAMPLER_VIEWS | ETNA_DIRTY_SAMPLERS))) {
349bf215546Sopenharmony_ci      for (int x = 0; x < VIVS_NTE_SAMPLER__LEN; ++x) {
350bf215546Sopenharmony_ci         uint32_t val = 0; /* 0 == sampler inactive */
351bf215546Sopenharmony_ci
352bf215546Sopenharmony_ci         /* set active samplers to their configuration value (determined by both
353bf215546Sopenharmony_ci          * the sampler state and sampler view) */
354bf215546Sopenharmony_ci         if ((1 << x) & active_samplers) {
355bf215546Sopenharmony_ci            struct etna_sampler_state *ss = etna_sampler_state(ctx->sampler[x]);
356bf215546Sopenharmony_ci            struct etna_sampler_view *sv = etna_sampler_view(ctx->sampler_view[x]);
357bf215546Sopenharmony_ci
358bf215546Sopenharmony_ci            val = (ss->config0 & sv->config0_mask) | sv->config0;
359bf215546Sopenharmony_ci         }
360bf215546Sopenharmony_ci
361bf215546Sopenharmony_ci         /*10000*/ EMIT_STATE(NTE_SAMPLER_CONFIG0(x), val);
362bf215546Sopenharmony_ci      }
363bf215546Sopenharmony_ci   }
364bf215546Sopenharmony_ci   if (unlikely(dirty & (ETNA_DIRTY_SAMPLER_VIEWS))) {
365bf215546Sopenharmony_ci      struct etna_sampler_state *ss;
366bf215546Sopenharmony_ci      struct etna_sampler_view *sv;
367bf215546Sopenharmony_ci
368bf215546Sopenharmony_ci      for (int x = 0; x < VIVS_NTE_SAMPLER__LEN; ++x) {
369bf215546Sopenharmony_ci         if ((1 << x) & active_samplers) {
370bf215546Sopenharmony_ci            sv = etna_sampler_view(ctx->sampler_view[x]);
371bf215546Sopenharmony_ci            /*10080*/ EMIT_STATE(NTE_SAMPLER_SIZE(x), sv->size);
372bf215546Sopenharmony_ci         }
373bf215546Sopenharmony_ci      }
374bf215546Sopenharmony_ci      for (int x = 0; x < VIVS_NTE_SAMPLER__LEN; ++x) {
375bf215546Sopenharmony_ci         if ((1 << x) & active_samplers) {
376bf215546Sopenharmony_ci            ss = etna_sampler_state(ctx->sampler[x]);
377bf215546Sopenharmony_ci            sv = etna_sampler_view(ctx->sampler_view[x]);
378bf215546Sopenharmony_ci            uint32_t log_size = sv->log_size;
379bf215546Sopenharmony_ci
380bf215546Sopenharmony_ci            if (texture_use_int_filter(&sv->base, &ss->base, false))
381bf215546Sopenharmony_ci               log_size |= VIVS_TE_SAMPLER_LOG_SIZE_INT_FILTER;
382bf215546Sopenharmony_ci
383bf215546Sopenharmony_ci            /*10100*/ EMIT_STATE(NTE_SAMPLER_LOG_SIZE(x), log_size);
384bf215546Sopenharmony_ci         }
385bf215546Sopenharmony_ci      }
386bf215546Sopenharmony_ci   }
387bf215546Sopenharmony_ci   if (unlikely(dirty & (ETNA_DIRTY_SAMPLER_VIEWS | ETNA_DIRTY_SAMPLERS))) {
388bf215546Sopenharmony_ci      struct etna_sampler_state *ss;
389bf215546Sopenharmony_ci      struct etna_sampler_view *sv;
390bf215546Sopenharmony_ci
391bf215546Sopenharmony_ci      for (int x = 0; x < VIVS_NTE_SAMPLER__LEN; ++x) {
392bf215546Sopenharmony_ci         if ((1 << x) & active_samplers) {
393bf215546Sopenharmony_ci            ss = etna_sampler_state(ctx->sampler[x]);
394bf215546Sopenharmony_ci            sv = etna_sampler_view(ctx->sampler_view[x]);
395bf215546Sopenharmony_ci
396bf215546Sopenharmony_ci            unsigned max_lod = MAX2(MIN2(ss->max_lod + sv->min_lod, sv->max_lod), ss->max_lod_min);
397bf215546Sopenharmony_ci            unsigned min_lod = MIN2(MAX2(ss->min_lod + sv->min_lod, sv->min_lod), max_lod);
398bf215546Sopenharmony_ci
399bf215546Sopenharmony_ci            /* min and max lod is determined both by the sampler and the view */
400bf215546Sopenharmony_ci            /*10180*/ EMIT_STATE(NTE_SAMPLER_LOD_CONFIG(x),
401bf215546Sopenharmony_ci                                 ss->config_lod |
402bf215546Sopenharmony_ci                                 VIVS_TE_SAMPLER_LOD_CONFIG_MAX(max_lod) |
403bf215546Sopenharmony_ci                                 VIVS_TE_SAMPLER_LOD_CONFIG_MIN(min_lod));
404bf215546Sopenharmony_ci         }
405bf215546Sopenharmony_ci      }
406bf215546Sopenharmony_ci   if (unlikely(dirty & (ETNA_DIRTY_SAMPLER_VIEWS))) {
407bf215546Sopenharmony_ci      /* only LOD0 is valid for this register */
408bf215546Sopenharmony_ci      for (int x = 0; x < VIVS_NTE_SAMPLER__LEN; ++x) {
409bf215546Sopenharmony_ci         if ((1 << x) & active_samplers) {
410bf215546Sopenharmony_ci            struct etna_sampler_view *sv = etna_sampler_view(ctx->sampler_view[x]);
411bf215546Sopenharmony_ci            /*10280*/ EMIT_STATE(NTE_SAMPLER_LINEAR_STRIDE(0, x), sv->linear_stride);
412bf215546Sopenharmony_ci         }
413bf215546Sopenharmony_ci      }
414bf215546Sopenharmony_ci   }
415bf215546Sopenharmony_ci      for (int x = 0; x < VIVS_NTE_SAMPLER__LEN; ++x) {
416bf215546Sopenharmony_ci         if ((1 << x) & active_samplers) {
417bf215546Sopenharmony_ci            ss = etna_sampler_state(ctx->sampler[x]);
418bf215546Sopenharmony_ci            sv = etna_sampler_view(ctx->sampler_view[x]);
419bf215546Sopenharmony_ci
420bf215546Sopenharmony_ci            /*10300*/ EMIT_STATE(NTE_SAMPLER_3D_CONFIG(x), ss->config_3d |
421bf215546Sopenharmony_ci                                                           sv->config_3d);
422bf215546Sopenharmony_ci         }
423bf215546Sopenharmony_ci      }
424bf215546Sopenharmony_ci      for (int x = 0; x < VIVS_NTE_SAMPLER__LEN; ++x) {
425bf215546Sopenharmony_ci         if ((1 << x) & active_samplers) {
426bf215546Sopenharmony_ci            ss = etna_sampler_state(ctx->sampler[x]);
427bf215546Sopenharmony_ci            sv = etna_sampler_view(ctx->sampler_view[x]);
428bf215546Sopenharmony_ci
429bf215546Sopenharmony_ci            /*10380*/ EMIT_STATE(NTE_SAMPLER_CONFIG1(x), ss->config1 |
430bf215546Sopenharmony_ci                                                         sv->config1 |
431bf215546Sopenharmony_ci                                                         COND(sv->ts.enable, VIVS_TE_SAMPLER_CONFIG1_USE_TS));
432bf215546Sopenharmony_ci         }
433bf215546Sopenharmony_ci      }
434bf215546Sopenharmony_ci   }
435bf215546Sopenharmony_ci   if (unlikely(screen->specs.tex_astc && (dirty & (ETNA_DIRTY_SAMPLER_VIEWS)))) {
436bf215546Sopenharmony_ci      for (int x = 0; x < VIVS_NTE_SAMPLER__LEN; ++x) {
437bf215546Sopenharmony_ci         if ((1 << x) & active_samplers) {
438bf215546Sopenharmony_ci            struct etna_sampler_view *sv = etna_sampler_view(ctx->sampler_view[x]);
439bf215546Sopenharmony_ci            /*10500*/ EMIT_STATE(NTE_SAMPLER_ASTC0(x), sv->astc0);
440bf215546Sopenharmony_ci         }
441bf215546Sopenharmony_ci      }
442bf215546Sopenharmony_ci   }
443bf215546Sopenharmony_ci   if (unlikely(dirty & (ETNA_DIRTY_SAMPLERS))) {
444bf215546Sopenharmony_ci      for (int x = 0; x < VIVS_NTE_SAMPLER__LEN; ++x) {
445bf215546Sopenharmony_ci         if ((1 << x) & active_samplers) {
446bf215546Sopenharmony_ci            struct etna_sampler_state *ss = etna_sampler_state(ctx->sampler[x]);
447bf215546Sopenharmony_ci            /*10700*/ EMIT_STATE(NTE_SAMPLER_BASELOD(x), ss->baselod);
448bf215546Sopenharmony_ci         }
449bf215546Sopenharmony_ci      }
450bf215546Sopenharmony_ci   }
451bf215546Sopenharmony_ci
452bf215546Sopenharmony_ci   if (unlikely(dirty & (ETNA_DIRTY_SAMPLER_VIEWS))) {
453bf215546Sopenharmony_ci      for (int x = 0; x < VIVS_NTE_SAMPLER__LEN; ++x) {
454bf215546Sopenharmony_ci         if ((1 << x) & active_samplers) {
455bf215546Sopenharmony_ci            for (int y = 0; y < VIVS_NTE_SAMPLER_ADDR_LOD__LEN; ++y) {
456bf215546Sopenharmony_ci               struct etna_sampler_view *sv = etna_sampler_view(ctx->sampler_view[x]);
457bf215546Sopenharmony_ci               /*10800*/ EMIT_STATE_RELOC(NTE_SAMPLER_ADDR_LOD(x, y), &sv->lod_addr[y]);
458bf215546Sopenharmony_ci            }
459bf215546Sopenharmony_ci         }
460bf215546Sopenharmony_ci      }
461bf215546Sopenharmony_ci   }
462bf215546Sopenharmony_ci
463bf215546Sopenharmony_ci   etna_coalesce_end(stream, &coalesce);
464bf215546Sopenharmony_ci}
465bf215546Sopenharmony_ci
466bf215546Sopenharmony_ci/* Emit plain (non-descriptor) texture state */
467bf215546Sopenharmony_cistatic void
468bf215546Sopenharmony_cietna_emit_texture_state(struct etna_context *ctx)
469bf215546Sopenharmony_ci{
470bf215546Sopenharmony_ci   struct etna_cmd_stream *stream = ctx->stream;
471bf215546Sopenharmony_ci   struct etna_screen *screen = ctx->screen;
472bf215546Sopenharmony_ci   uint32_t active_samplers = active_samplers_bits(ctx);
473bf215546Sopenharmony_ci   uint32_t dirty = ctx->dirty;
474bf215546Sopenharmony_ci   struct etna_coalesce coalesce;
475bf215546Sopenharmony_ci
476bf215546Sopenharmony_ci   etna_emit_ts_state(ctx);
477bf215546Sopenharmony_ci
478bf215546Sopenharmony_ci   etna_coalesce_start(stream, &coalesce);
479bf215546Sopenharmony_ci
480bf215546Sopenharmony_ci   if (unlikely(dirty & (ETNA_DIRTY_SAMPLER_VIEWS | ETNA_DIRTY_SAMPLERS))) {
481bf215546Sopenharmony_ci      for (int x = 0; x < VIVS_TE_SAMPLER__LEN; ++x) {
482bf215546Sopenharmony_ci         uint32_t val = 0; /* 0 == sampler inactive */
483bf215546Sopenharmony_ci
484bf215546Sopenharmony_ci         /* set active samplers to their configuration value (determined by both
485bf215546Sopenharmony_ci          * the sampler state and sampler view) */
486bf215546Sopenharmony_ci         if ((1 << x) & active_samplers) {
487bf215546Sopenharmony_ci            struct etna_sampler_state *ss = etna_sampler_state(ctx->sampler[x]);
488bf215546Sopenharmony_ci            struct etna_sampler_view *sv = etna_sampler_view(ctx->sampler_view[x]);
489bf215546Sopenharmony_ci
490bf215546Sopenharmony_ci            val = (ss->config0 & sv->config0_mask) | sv->config0;
491bf215546Sopenharmony_ci         }
492bf215546Sopenharmony_ci
493bf215546Sopenharmony_ci         /*02000*/ EMIT_STATE(TE_SAMPLER_CONFIG0(x), val);
494bf215546Sopenharmony_ci      }
495bf215546Sopenharmony_ci   }
496bf215546Sopenharmony_ci   if (unlikely(dirty & (ETNA_DIRTY_SAMPLER_VIEWS))) {
497bf215546Sopenharmony_ci      struct etna_sampler_state *ss;
498bf215546Sopenharmony_ci      struct etna_sampler_view *sv;
499bf215546Sopenharmony_ci
500bf215546Sopenharmony_ci      for (int x = 0; x < VIVS_TE_SAMPLER__LEN; ++x) {
501bf215546Sopenharmony_ci         if ((1 << x) & active_samplers) {
502bf215546Sopenharmony_ci            sv = etna_sampler_view(ctx->sampler_view[x]);
503bf215546Sopenharmony_ci            /*02040*/ EMIT_STATE(TE_SAMPLER_SIZE(x), sv->size);
504bf215546Sopenharmony_ci         }
505bf215546Sopenharmony_ci      }
506bf215546Sopenharmony_ci      for (int x = 0; x < VIVS_TE_SAMPLER__LEN; ++x) {
507bf215546Sopenharmony_ci         if ((1 << x) & active_samplers) {
508bf215546Sopenharmony_ci            ss = etna_sampler_state(ctx->sampler[x]);
509bf215546Sopenharmony_ci            sv = etna_sampler_view(ctx->sampler_view[x]);
510bf215546Sopenharmony_ci            uint32_t log_size = sv->log_size;
511bf215546Sopenharmony_ci
512bf215546Sopenharmony_ci            if (texture_use_int_filter(&sv->base, &ss->base, false))
513bf215546Sopenharmony_ci               log_size |= VIVS_TE_SAMPLER_LOG_SIZE_INT_FILTER;
514bf215546Sopenharmony_ci
515bf215546Sopenharmony_ci            /*02080*/ EMIT_STATE(TE_SAMPLER_LOG_SIZE(x), log_size);
516bf215546Sopenharmony_ci         }
517bf215546Sopenharmony_ci      }
518bf215546Sopenharmony_ci   }
519bf215546Sopenharmony_ci   if (unlikely(dirty & (ETNA_DIRTY_SAMPLER_VIEWS | ETNA_DIRTY_SAMPLERS))) {
520bf215546Sopenharmony_ci      struct etna_sampler_state *ss;
521bf215546Sopenharmony_ci      struct etna_sampler_view *sv;
522bf215546Sopenharmony_ci
523bf215546Sopenharmony_ci      for (int x = 0; x < VIVS_TE_SAMPLER__LEN; ++x) {
524bf215546Sopenharmony_ci         if ((1 << x) & active_samplers) {
525bf215546Sopenharmony_ci            ss = etna_sampler_state(ctx->sampler[x]);
526bf215546Sopenharmony_ci            sv = etna_sampler_view(ctx->sampler_view[x]);
527bf215546Sopenharmony_ci
528bf215546Sopenharmony_ci            unsigned max_lod = MAX2(MIN2(ss->max_lod + sv->min_lod, sv->max_lod), ss->max_lod_min);
529bf215546Sopenharmony_ci            unsigned min_lod = MIN2(MAX2(ss->min_lod + sv->min_lod, sv->min_lod), max_lod);
530bf215546Sopenharmony_ci
531bf215546Sopenharmony_ci            /* min and max lod is determined both by the sampler and the view */
532bf215546Sopenharmony_ci            /*020C0*/ EMIT_STATE(TE_SAMPLER_LOD_CONFIG(x),
533bf215546Sopenharmony_ci                                 ss->config_lod |
534bf215546Sopenharmony_ci                                 VIVS_TE_SAMPLER_LOD_CONFIG_MAX(max_lod) |
535bf215546Sopenharmony_ci                                 VIVS_TE_SAMPLER_LOD_CONFIG_MIN(min_lod));
536bf215546Sopenharmony_ci         }
537bf215546Sopenharmony_ci      }
538bf215546Sopenharmony_ci      for (int x = 0; x < VIVS_TE_SAMPLER__LEN; ++x) {
539bf215546Sopenharmony_ci         if ((1 << x) & active_samplers) {
540bf215546Sopenharmony_ci            ss = etna_sampler_state(ctx->sampler[x]);
541bf215546Sopenharmony_ci            sv = etna_sampler_view(ctx->sampler_view[x]);
542bf215546Sopenharmony_ci
543bf215546Sopenharmony_ci            /*02180*/ EMIT_STATE(TE_SAMPLER_3D_CONFIG(x), ss->config_3d |
544bf215546Sopenharmony_ci                                                          sv->config_3d);
545bf215546Sopenharmony_ci         }
546bf215546Sopenharmony_ci      }
547bf215546Sopenharmony_ci      for (int x = 0; x < VIVS_TE_SAMPLER__LEN; ++x) {
548bf215546Sopenharmony_ci         if ((1 << x) & active_samplers) {
549bf215546Sopenharmony_ci            ss = etna_sampler_state(ctx->sampler[x]);
550bf215546Sopenharmony_ci            sv = etna_sampler_view(ctx->sampler_view[x]);
551bf215546Sopenharmony_ci
552bf215546Sopenharmony_ci            /*021C0*/ EMIT_STATE(TE_SAMPLER_CONFIG1(x), ss->config1 |
553bf215546Sopenharmony_ci                                                        sv->config1 |
554bf215546Sopenharmony_ci                                                        COND(sv->ts.enable, VIVS_TE_SAMPLER_CONFIG1_USE_TS));
555bf215546Sopenharmony_ci         }
556bf215546Sopenharmony_ci      }
557bf215546Sopenharmony_ci   }
558bf215546Sopenharmony_ci   if (unlikely(dirty & (ETNA_DIRTY_SAMPLER_VIEWS))) {
559bf215546Sopenharmony_ci      for (int y = 0; y < VIVS_TE_SAMPLER_LOD_ADDR__LEN; ++y) {
560bf215546Sopenharmony_ci         for (int x = 0; x < VIVS_TE_SAMPLER__LEN; ++x) {
561bf215546Sopenharmony_ci            if ((1 << x) & active_samplers) {
562bf215546Sopenharmony_ci               struct etna_sampler_view *sv = etna_sampler_view(ctx->sampler_view[x]);
563bf215546Sopenharmony_ci               /*02400*/ EMIT_STATE_RELOC(TE_SAMPLER_LOD_ADDR(x, y), &sv->lod_addr[y]);
564bf215546Sopenharmony_ci            }
565bf215546Sopenharmony_ci         }
566bf215546Sopenharmony_ci      }
567bf215546Sopenharmony_ci   }
568bf215546Sopenharmony_ci   if (unlikely(dirty & (ETNA_DIRTY_SAMPLER_VIEWS))) {
569bf215546Sopenharmony_ci      /* only LOD0 is valid for this register */
570bf215546Sopenharmony_ci      for (int x = 0; x < VIVS_TE_SAMPLER__LEN; ++x) {
571bf215546Sopenharmony_ci         if ((1 << x) & active_samplers) {
572bf215546Sopenharmony_ci            struct etna_sampler_view *sv = etna_sampler_view(ctx->sampler_view[x]);
573bf215546Sopenharmony_ci            /*02C00*/ EMIT_STATE(TE_SAMPLER_LINEAR_STRIDE(0, x), sv->linear_stride);
574bf215546Sopenharmony_ci         }
575bf215546Sopenharmony_ci      }
576bf215546Sopenharmony_ci   }
577bf215546Sopenharmony_ci   if (unlikely(screen->specs.tex_astc && (dirty & (ETNA_DIRTY_SAMPLER_VIEWS)))) {
578bf215546Sopenharmony_ci      for (int x = 0; x < VIVS_TE_SAMPLER__LEN; ++x) {
579bf215546Sopenharmony_ci         if ((1 << x) & active_samplers) {
580bf215546Sopenharmony_ci            struct etna_sampler_view *sv = etna_sampler_view(ctx->sampler_view[x]);
581bf215546Sopenharmony_ci            /*10500*/ EMIT_STATE(NTE_SAMPLER_ASTC0(x), sv->astc0);
582bf215546Sopenharmony_ci         }
583bf215546Sopenharmony_ci      }
584bf215546Sopenharmony_ci   }
585bf215546Sopenharmony_ci
586bf215546Sopenharmony_ci   etna_coalesce_end(stream, &coalesce);
587bf215546Sopenharmony_ci}
588bf215546Sopenharmony_ci
589bf215546Sopenharmony_ci#undef EMIT_STATE
590bf215546Sopenharmony_ci#undef EMIT_STATE_FIXP
591bf215546Sopenharmony_ci#undef EMIT_STATE_RELOC
592bf215546Sopenharmony_ci
593bf215546Sopenharmony_cistatic struct etna_sampler_ts*
594bf215546Sopenharmony_cietna_ts_for_sampler_view_state(struct pipe_sampler_view *pview)
595bf215546Sopenharmony_ci{
596bf215546Sopenharmony_ci   struct etna_sampler_view *sv = etna_sampler_view(pview);
597bf215546Sopenharmony_ci   return &sv->ts;
598bf215546Sopenharmony_ci}
599bf215546Sopenharmony_ci
600bf215546Sopenharmony_civoid
601bf215546Sopenharmony_cietna_texture_state_init(struct pipe_context *pctx)
602bf215546Sopenharmony_ci{
603bf215546Sopenharmony_ci   struct etna_context *ctx = etna_context(pctx);
604bf215546Sopenharmony_ci   DBG("etnaviv: Using state-based texturing");
605bf215546Sopenharmony_ci   ctx->base.create_sampler_state = etna_create_sampler_state_state;
606bf215546Sopenharmony_ci   ctx->base.delete_sampler_state = etna_delete_sampler_state_state;
607bf215546Sopenharmony_ci   ctx->base.create_sampler_view = etna_create_sampler_view_state;
608bf215546Sopenharmony_ci   ctx->base.sampler_view_destroy = etna_sampler_view_state_destroy;
609bf215546Sopenharmony_ci   ctx->ts_for_sampler_view = etna_ts_for_sampler_view_state;
610bf215546Sopenharmony_ci
611bf215546Sopenharmony_ci   STATIC_ASSERT(VIVS_TE_SAMPLER_LOD_ADDR__LEN == VIVS_NTE_SAMPLER_ADDR_LOD__LEN);
612bf215546Sopenharmony_ci
613bf215546Sopenharmony_ci   if (ctx->screen->specs.halti >= 1)
614bf215546Sopenharmony_ci      ctx->emit_texture_state = etna_emit_new_texture_state;
615bf215546Sopenharmony_ci   else
616bf215546Sopenharmony_ci      ctx->emit_texture_state = etna_emit_texture_state;
617bf215546Sopenharmony_ci}
618