Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vc4_state.c 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. /*
  2. * Copyright © 2014 Broadcom
  3. * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  22. * IN THE SOFTWARE.
  23. */
  24. #include "pipe/p_state.h"
  25. #include "util/u_inlines.h"
  26. #include "util/u_math.h"
  27. #include "util/u_memory.h"
  28. #include "util/u_helpers.h"
  29. #include "vc4_context.h"
  30. static void *
  31. vc4_generic_cso_state_create(const void *src, uint32_t size)
  32. {
  33. void *dst = calloc(1, size);
  34. if (!dst)
  35. return NULL;
  36. memcpy(dst, src, size);
  37. return dst;
  38. }
  39. static void
  40. vc4_generic_cso_state_delete(struct pipe_context *pctx, void *hwcso)
  41. {
  42. free(hwcso);
  43. }
  44. static void
  45. vc4_set_blend_color(struct pipe_context *pctx,
  46. const struct pipe_blend_color *blend_color)
  47. {
  48. struct vc4_context *vc4 = vc4_context(pctx);
  49. vc4->blend_color = *blend_color;
  50. vc4->dirty |= VC4_DIRTY_BLEND_COLOR;
  51. }
  52. static void
  53. vc4_set_stencil_ref(struct pipe_context *pctx,
  54. const struct pipe_stencil_ref *stencil_ref)
  55. {
  56. struct vc4_context *vc4 = vc4_context(pctx);
  57. vc4->stencil_ref =* stencil_ref;
  58. vc4->dirty |= VC4_DIRTY_STENCIL_REF;
  59. }
  60. static void
  61. vc4_set_clip_state(struct pipe_context *pctx,
  62. const struct pipe_clip_state *clip)
  63. {
  64. struct vc4_context *vc4 = vc4_context(pctx);
  65. vc4->clip = *clip;
  66. vc4->dirty |= VC4_DIRTY_CLIP;
  67. }
  68. static void
  69. vc4_set_sample_mask(struct pipe_context *pctx, unsigned sample_mask)
  70. {
  71. struct vc4_context *vc4 = vc4_context(pctx);
  72. vc4->sample_mask = (uint16_t)sample_mask;
  73. vc4->dirty |= VC4_DIRTY_SAMPLE_MASK;
  74. }
  75. static uint16_t
  76. float_to_187_half(float f)
  77. {
  78. return fui(f) >> 16;
  79. }
  80. static void *
  81. vc4_create_rasterizer_state(struct pipe_context *pctx,
  82. const struct pipe_rasterizer_state *cso)
  83. {
  84. struct vc4_rasterizer_state *so;
  85. so = CALLOC_STRUCT(vc4_rasterizer_state);
  86. if (!so)
  87. return NULL;
  88. so->base = *cso;
  89. if (!(cso->cull_face & PIPE_FACE_FRONT))
  90. so->config_bits[0] |= VC4_CONFIG_BITS_ENABLE_PRIM_FRONT;
  91. if (!(cso->cull_face & PIPE_FACE_BACK))
  92. so->config_bits[0] |= VC4_CONFIG_BITS_ENABLE_PRIM_BACK;
  93. /* Workaround: HW-2726 PTB does not handle zero-size points (BCM2835,
  94. * BCM21553).
  95. */
  96. so->point_size = MAX2(cso->point_size, .125);
  97. if (cso->front_ccw)
  98. so->config_bits[0] |= VC4_CONFIG_BITS_CW_PRIMITIVES;
  99. if (cso->offset_tri) {
  100. so->config_bits[0] |= VC4_CONFIG_BITS_ENABLE_DEPTH_OFFSET;
  101. so->offset_units = float_to_187_half(cso->offset_units);
  102. so->offset_factor = float_to_187_half(cso->offset_scale);
  103. }
  104. return so;
  105. }
  106. /* Blend state is baked into shaders. */
  107. static void *
  108. vc4_create_blend_state(struct pipe_context *pctx,
  109. const struct pipe_blend_state *cso)
  110. {
  111. return vc4_generic_cso_state_create(cso, sizeof(*cso));
  112. }
  113. /**
  114. * The TLB_STENCIL_SETUP data has a little bitfield for common writemask
  115. * values, so you don't have to do a separate writemask setup.
  116. */
  117. static uint8_t
  118. tlb_stencil_setup_writemask(uint8_t mask)
  119. {
  120. switch (mask) {
  121. case 0x1: return 0;
  122. case 0x3: return 1;
  123. case 0xf: return 2;
  124. case 0xff: return 3;
  125. default: return 0xff;
  126. }
  127. }
  128. static uint32_t
  129. tlb_stencil_setup_bits(const struct pipe_stencil_state *state,
  130. uint8_t writemask_bits)
  131. {
  132. static const uint8_t op_map[] = {
  133. [PIPE_STENCIL_OP_ZERO] = 0,
  134. [PIPE_STENCIL_OP_KEEP] = 1,
  135. [PIPE_STENCIL_OP_REPLACE] = 2,
  136. [PIPE_STENCIL_OP_INCR] = 3,
  137. [PIPE_STENCIL_OP_DECR] = 4,
  138. [PIPE_STENCIL_OP_INVERT] = 5,
  139. [PIPE_STENCIL_OP_INCR_WRAP] = 6,
  140. [PIPE_STENCIL_OP_DECR_WRAP] = 7,
  141. };
  142. uint32_t bits = 0;
  143. if (writemask_bits != 0xff)
  144. bits |= writemask_bits << 28;
  145. bits |= op_map[state->zfail_op] << 25;
  146. bits |= op_map[state->zpass_op] << 22;
  147. bits |= op_map[state->fail_op] << 19;
  148. bits |= state->func << 16;
  149. /* Ref is filled in at uniform upload time */
  150. bits |= state->valuemask << 0;
  151. return bits;
  152. }
  153. static void *
  154. vc4_create_depth_stencil_alpha_state(struct pipe_context *pctx,
  155. const struct pipe_depth_stencil_alpha_state *cso)
  156. {
  157. struct vc4_depth_stencil_alpha_state *so;
  158. so = CALLOC_STRUCT(vc4_depth_stencil_alpha_state);
  159. if (!so)
  160. return NULL;
  161. so->base = *cso;
  162. /* We always keep the early Z state correct, since a later state using
  163. * early Z may want it.
  164. */
  165. so->config_bits[2] |= VC4_CONFIG_BITS_EARLY_Z_UPDATE;
  166. if (cso->depth.enabled) {
  167. if (cso->depth.writemask) {
  168. so->config_bits[1] |= VC4_CONFIG_BITS_Z_UPDATE;
  169. }
  170. so->config_bits[1] |= (cso->depth.func <<
  171. VC4_CONFIG_BITS_DEPTH_FUNC_SHIFT);
  172. /* We only handle early Z in the < direction because otherwise
  173. * we'd have to runtime guess which direction to set in the
  174. * render config.
  175. */
  176. if ((cso->depth.func == PIPE_FUNC_LESS ||
  177. cso->depth.func == PIPE_FUNC_LEQUAL) &&
  178. (!cso->stencil[0].enabled ||
  179. (cso->stencil[0].zfail_op == PIPE_STENCIL_OP_KEEP &&
  180. (!cso->stencil[1].enabled ||
  181. cso->stencil[1].zfail_op == PIPE_STENCIL_OP_KEEP)))) {
  182. so->config_bits[2] |= VC4_CONFIG_BITS_EARLY_Z;
  183. }
  184. } else {
  185. so->config_bits[1] |= (PIPE_FUNC_ALWAYS <<
  186. VC4_CONFIG_BITS_DEPTH_FUNC_SHIFT);
  187. }
  188. if (cso->stencil[0].enabled) {
  189. const struct pipe_stencil_state *front = &cso->stencil[0];
  190. const struct pipe_stencil_state *back = &cso->stencil[1];
  191. uint8_t front_writemask_bits =
  192. tlb_stencil_setup_writemask(front->writemask);
  193. uint8_t back_writemask = front->writemask;
  194. uint8_t back_writemask_bits = front_writemask_bits;
  195. so->stencil_uniforms[0] =
  196. tlb_stencil_setup_bits(front, front_writemask_bits);
  197. if (back->enabled) {
  198. back_writemask = back->writemask;
  199. back_writemask_bits =
  200. tlb_stencil_setup_writemask(back->writemask);
  201. so->stencil_uniforms[0] |= (1 << 30);
  202. so->stencil_uniforms[1] =
  203. tlb_stencil_setup_bits(back, back_writemask_bits);
  204. so->stencil_uniforms[1] |= (2 << 30);
  205. } else {
  206. so->stencil_uniforms[0] |= (3 << 30);
  207. }
  208. if (front_writemask_bits == 0xff ||
  209. back_writemask_bits == 0xff) {
  210. so->stencil_uniforms[2] = (front->writemask |
  211. (back_writemask << 8));
  212. }
  213. }
  214. return so;
  215. }
  216. static void
  217. vc4_set_polygon_stipple(struct pipe_context *pctx,
  218. const struct pipe_poly_stipple *stipple)
  219. {
  220. struct vc4_context *vc4 = vc4_context(pctx);
  221. vc4->stipple = *stipple;
  222. vc4->dirty |= VC4_DIRTY_STIPPLE;
  223. }
  224. static void
  225. vc4_set_scissor_states(struct pipe_context *pctx,
  226. unsigned start_slot,
  227. unsigned num_scissors,
  228. const struct pipe_scissor_state *scissor)
  229. {
  230. struct vc4_context *vc4 = vc4_context(pctx);
  231. vc4->scissor = *scissor;
  232. vc4->dirty |= VC4_DIRTY_SCISSOR;
  233. }
  234. static void
  235. vc4_set_viewport_states(struct pipe_context *pctx,
  236. unsigned start_slot,
  237. unsigned num_viewports,
  238. const struct pipe_viewport_state *viewport)
  239. {
  240. struct vc4_context *vc4 = vc4_context(pctx);
  241. vc4->viewport = *viewport;
  242. vc4->dirty |= VC4_DIRTY_VIEWPORT;
  243. }
  244. static void
  245. vc4_set_vertex_buffers(struct pipe_context *pctx,
  246. unsigned start_slot, unsigned count,
  247. const struct pipe_vertex_buffer *vb)
  248. {
  249. struct vc4_context *vc4 = vc4_context(pctx);
  250. struct vc4_vertexbuf_stateobj *so = &vc4->vertexbuf;
  251. util_set_vertex_buffers_mask(so->vb, &so->enabled_mask, vb,
  252. start_slot, count);
  253. so->count = util_last_bit(so->enabled_mask);
  254. vc4->dirty |= VC4_DIRTY_VTXBUF;
  255. }
  256. static void
  257. vc4_set_index_buffer(struct pipe_context *pctx,
  258. const struct pipe_index_buffer *ib)
  259. {
  260. struct vc4_context *vc4 = vc4_context(pctx);
  261. if (ib) {
  262. assert(!ib->user_buffer);
  263. if (ib->index_size == 4) {
  264. struct pipe_resource tmpl = *ib->buffer;
  265. assert(tmpl.format == PIPE_FORMAT_R8_UNORM);
  266. assert(tmpl.height0 == 1);
  267. tmpl.width0 = (tmpl.width0 - ib->offset) / 2;
  268. struct pipe_resource *pshadow =
  269. vc4_resource_create(&vc4->screen->base, &tmpl);
  270. struct vc4_resource *shadow = vc4_resource(pshadow);
  271. pipe_resource_reference(&shadow->shadow_parent, ib->buffer);
  272. pipe_resource_reference(&vc4->indexbuf.buffer, NULL);
  273. vc4->indexbuf.buffer = pshadow;
  274. vc4->indexbuf.index_size = 2;
  275. } else {
  276. pipe_resource_reference(&vc4->indexbuf.buffer, ib->buffer);
  277. vc4->indexbuf.index_size = ib->index_size;
  278. }
  279. vc4->indexbuf.offset = ib->offset;
  280. } else {
  281. pipe_resource_reference(&vc4->indexbuf.buffer, NULL);
  282. }
  283. vc4->dirty |= VC4_DIRTY_INDEXBUF;
  284. }
  285. static void
  286. vc4_blend_state_bind(struct pipe_context *pctx, void *hwcso)
  287. {
  288. struct vc4_context *vc4 = vc4_context(pctx);
  289. vc4->blend = hwcso;
  290. vc4->dirty |= VC4_DIRTY_BLEND;
  291. }
  292. static void
  293. vc4_rasterizer_state_bind(struct pipe_context *pctx, void *hwcso)
  294. {
  295. struct vc4_context *vc4 = vc4_context(pctx);
  296. struct vc4_rasterizer_state *rast = hwcso;
  297. if (vc4->rasterizer && rast &&
  298. vc4->rasterizer->base.flatshade != rast->base.flatshade) {
  299. vc4->dirty |= VC4_DIRTY_FLAT_SHADE_FLAGS;
  300. }
  301. vc4->rasterizer = hwcso;
  302. vc4->dirty |= VC4_DIRTY_RASTERIZER;
  303. }
  304. static void
  305. vc4_zsa_state_bind(struct pipe_context *pctx, void *hwcso)
  306. {
  307. struct vc4_context *vc4 = vc4_context(pctx);
  308. vc4->zsa = hwcso;
  309. vc4->dirty |= VC4_DIRTY_ZSA;
  310. }
  311. static void *
  312. vc4_vertex_state_create(struct pipe_context *pctx, unsigned num_elements,
  313. const struct pipe_vertex_element *elements)
  314. {
  315. struct vc4_vertex_stateobj *so = CALLOC_STRUCT(vc4_vertex_stateobj);
  316. if (!so)
  317. return NULL;
  318. memcpy(so->pipe, elements, sizeof(*elements) * num_elements);
  319. so->num_elements = num_elements;
  320. return so;
  321. }
  322. static void
  323. vc4_vertex_state_bind(struct pipe_context *pctx, void *hwcso)
  324. {
  325. struct vc4_context *vc4 = vc4_context(pctx);
  326. vc4->vtx = hwcso;
  327. vc4->dirty |= VC4_DIRTY_VTXSTATE;
  328. }
  329. static void
  330. vc4_set_constant_buffer(struct pipe_context *pctx, uint shader, uint index,
  331. struct pipe_constant_buffer *cb)
  332. {
  333. struct vc4_context *vc4 = vc4_context(pctx);
  334. struct vc4_constbuf_stateobj *so = &vc4->constbuf[shader];
  335. assert(index == 0);
  336. /* Note that the state tracker can unbind constant buffers by
  337. * passing NULL here.
  338. */
  339. if (unlikely(!cb)) {
  340. so->enabled_mask &= ~(1 << index);
  341. so->dirty_mask &= ~(1 << index);
  342. return;
  343. }
  344. assert(!cb->buffer);
  345. so->cb[index].buffer_offset = cb->buffer_offset;
  346. so->cb[index].buffer_size = cb->buffer_size;
  347. so->cb[index].user_buffer = cb->user_buffer;
  348. so->enabled_mask |= 1 << index;
  349. so->dirty_mask |= 1 << index;
  350. vc4->dirty |= VC4_DIRTY_CONSTBUF;
  351. }
  352. static void
  353. vc4_set_framebuffer_state(struct pipe_context *pctx,
  354. const struct pipe_framebuffer_state *framebuffer)
  355. {
  356. struct vc4_context *vc4 = vc4_context(pctx);
  357. struct pipe_framebuffer_state *cso = &vc4->framebuffer;
  358. unsigned i;
  359. vc4_flush(pctx);
  360. for (i = 0; i < framebuffer->nr_cbufs; i++)
  361. pipe_surface_reference(&cso->cbufs[i], framebuffer->cbufs[i]);
  362. for (; i < vc4->framebuffer.nr_cbufs; i++)
  363. pipe_surface_reference(&cso->cbufs[i], NULL);
  364. cso->nr_cbufs = framebuffer->nr_cbufs;
  365. pipe_surface_reference(&cso->zsbuf, framebuffer->zsbuf);
  366. cso->width = framebuffer->width;
  367. cso->height = framebuffer->height;
  368. /* Nonzero texture mipmap levels are laid out as if they were in
  369. * power-of-two-sized spaces. The renderbuffer config infers its
  370. * stride from the width parameter, so we need to configure our
  371. * framebuffer. Note that if the z/color buffers were mismatched
  372. * sizes, we wouldn't be able to do this.
  373. */
  374. if (cso->cbufs[0] && cso->cbufs[0]->u.tex.level) {
  375. struct vc4_resource *rsc =
  376. vc4_resource(cso->cbufs[0]->texture);
  377. cso->width =
  378. (rsc->slices[cso->cbufs[0]->u.tex.level].stride /
  379. rsc->cpp);
  380. } else if (cso->zsbuf && cso->zsbuf->u.tex.level){
  381. struct vc4_resource *rsc =
  382. vc4_resource(cso->zsbuf->texture);
  383. cso->width =
  384. (rsc->slices[cso->zsbuf->u.tex.level].stride /
  385. rsc->cpp);
  386. }
  387. vc4->dirty |= VC4_DIRTY_FRAMEBUFFER;
  388. }
  389. static struct vc4_texture_stateobj *
  390. vc4_get_stage_tex(struct vc4_context *vc4, unsigned shader)
  391. {
  392. vc4->dirty |= VC4_DIRTY_TEXSTATE;
  393. switch (shader) {
  394. case PIPE_SHADER_FRAGMENT:
  395. vc4->dirty |= VC4_DIRTY_FRAGTEX;
  396. return &vc4->fragtex;
  397. break;
  398. case PIPE_SHADER_VERTEX:
  399. vc4->dirty |= VC4_DIRTY_VERTTEX;
  400. return &vc4->verttex;
  401. break;
  402. default:
  403. fprintf(stderr, "Unknown shader target %d\n", shader);
  404. abort();
  405. }
  406. }
  407. static void *
  408. vc4_create_sampler_state(struct pipe_context *pctx,
  409. const struct pipe_sampler_state *cso)
  410. {
  411. return vc4_generic_cso_state_create(cso, sizeof(*cso));
  412. }
  413. static void
  414. vc4_sampler_states_bind(struct pipe_context *pctx,
  415. unsigned shader, unsigned start,
  416. unsigned nr, void **hwcso)
  417. {
  418. struct vc4_context *vc4 = vc4_context(pctx);
  419. struct vc4_texture_stateobj *stage_tex = vc4_get_stage_tex(vc4, shader);
  420. assert(start == 0);
  421. unsigned i;
  422. unsigned new_nr = 0;
  423. for (i = 0; i < nr; i++) {
  424. if (hwcso[i])
  425. new_nr = i + 1;
  426. stage_tex->samplers[i] = hwcso[i];
  427. stage_tex->dirty_samplers |= (1 << i);
  428. }
  429. for (; i < stage_tex->num_samplers; i++) {
  430. stage_tex->samplers[i] = NULL;
  431. stage_tex->dirty_samplers |= (1 << i);
  432. }
  433. stage_tex->num_samplers = new_nr;
  434. }
  435. static struct pipe_sampler_view *
  436. vc4_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *prsc,
  437. const struct pipe_sampler_view *cso)
  438. {
  439. struct pipe_sampler_view *so = malloc(sizeof(*so));
  440. struct vc4_resource *rsc = vc4_resource(prsc);
  441. if (!so)
  442. return NULL;
  443. *so = *cso;
  444. pipe_reference(NULL, &prsc->reference);
  445. /* There is no hardware level clamping, and the start address of a
  446. * texture may be misaligned, so in that case we have to copy to a
  447. * temporary.
  448. *
  449. * Also, Raspberry Pi doesn't support sampling from raster textures,
  450. * so we also have to copy to a temporary then.
  451. */
  452. if (so->u.tex.first_level ||
  453. rsc->vc4_format == VC4_TEXTURE_TYPE_RGBA32R) {
  454. struct vc4_resource *shadow_parent = vc4_resource(prsc);
  455. struct pipe_resource tmpl = shadow_parent->base.b;
  456. struct vc4_resource *clone;
  457. tmpl.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET;
  458. tmpl.width0 = u_minify(tmpl.width0, so->u.tex.first_level);
  459. tmpl.height0 = u_minify(tmpl.height0, so->u.tex.first_level);
  460. tmpl.last_level = so->u.tex.last_level - so->u.tex.first_level;
  461. prsc = vc4_resource_create(pctx->screen, &tmpl);
  462. clone = vc4_resource(prsc);
  463. clone->shadow_parent = &shadow_parent->base.b;
  464. /* Flag it as needing update of the contents from the parent. */
  465. clone->writes = shadow_parent->writes - 1;
  466. assert(clone->vc4_format != VC4_TEXTURE_TYPE_RGBA32R);
  467. }
  468. so->texture = prsc;
  469. so->reference.count = 1;
  470. so->context = pctx;
  471. return so;
  472. }
  473. static void
  474. vc4_sampler_view_destroy(struct pipe_context *pctx,
  475. struct pipe_sampler_view *view)
  476. {
  477. pipe_resource_reference(&view->texture, NULL);
  478. free(view);
  479. }
  480. static void
  481. vc4_set_sampler_views(struct pipe_context *pctx, unsigned shader,
  482. unsigned start, unsigned nr,
  483. struct pipe_sampler_view **views)
  484. {
  485. struct vc4_context *vc4 = vc4_context(pctx);
  486. struct vc4_texture_stateobj *stage_tex = vc4_get_stage_tex(vc4, shader);
  487. unsigned i;
  488. unsigned new_nr = 0;
  489. assert(start == 0);
  490. vc4->dirty |= VC4_DIRTY_TEXSTATE;
  491. for (i = 0; i < nr; i++) {
  492. if (views[i])
  493. new_nr = i + 1;
  494. pipe_sampler_view_reference(&stage_tex->textures[i], views[i]);
  495. stage_tex->dirty_samplers |= (1 << i);
  496. }
  497. for (; i < stage_tex->num_textures; i++) {
  498. pipe_sampler_view_reference(&stage_tex->textures[i], NULL);
  499. stage_tex->dirty_samplers |= (1 << i);
  500. }
  501. stage_tex->num_textures = new_nr;
  502. }
  503. void
  504. vc4_state_init(struct pipe_context *pctx)
  505. {
  506. pctx->set_blend_color = vc4_set_blend_color;
  507. pctx->set_stencil_ref = vc4_set_stencil_ref;
  508. pctx->set_clip_state = vc4_set_clip_state;
  509. pctx->set_sample_mask = vc4_set_sample_mask;
  510. pctx->set_constant_buffer = vc4_set_constant_buffer;
  511. pctx->set_framebuffer_state = vc4_set_framebuffer_state;
  512. pctx->set_polygon_stipple = vc4_set_polygon_stipple;
  513. pctx->set_scissor_states = vc4_set_scissor_states;
  514. pctx->set_viewport_states = vc4_set_viewport_states;
  515. pctx->set_vertex_buffers = vc4_set_vertex_buffers;
  516. pctx->set_index_buffer = vc4_set_index_buffer;
  517. pctx->create_blend_state = vc4_create_blend_state;
  518. pctx->bind_blend_state = vc4_blend_state_bind;
  519. pctx->delete_blend_state = vc4_generic_cso_state_delete;
  520. pctx->create_rasterizer_state = vc4_create_rasterizer_state;
  521. pctx->bind_rasterizer_state = vc4_rasterizer_state_bind;
  522. pctx->delete_rasterizer_state = vc4_generic_cso_state_delete;
  523. pctx->create_depth_stencil_alpha_state = vc4_create_depth_stencil_alpha_state;
  524. pctx->bind_depth_stencil_alpha_state = vc4_zsa_state_bind;
  525. pctx->delete_depth_stencil_alpha_state = vc4_generic_cso_state_delete;
  526. pctx->create_vertex_elements_state = vc4_vertex_state_create;
  527. pctx->delete_vertex_elements_state = vc4_generic_cso_state_delete;
  528. pctx->bind_vertex_elements_state = vc4_vertex_state_bind;
  529. pctx->create_sampler_state = vc4_create_sampler_state;
  530. pctx->delete_sampler_state = vc4_generic_cso_state_delete;
  531. pctx->bind_sampler_states = vc4_sampler_states_bind;
  532. pctx->create_sampler_view = vc4_create_sampler_view;
  533. pctx->sampler_view_destroy = vc4_sampler_view_destroy;
  534. pctx->set_sampler_views = vc4_set_sampler_views;
  535. }