1ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca/**************************************************************************
2ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca *
3ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca * Copyright 2009 VMware, Inc.
4ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca * All Rights Reserved.
5ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca *
6ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca * Permission is hereby granted, free of charge, to any person obtaining a
7ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca * copy of this software and associated documentation files (the
8ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca * "Software"), to deal in the Software without restriction, including
9ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca * without limitation the rights to use, copy, modify, merge, publish,
10ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca * distribute, sub license, and/or sell copies of the Software, and to
11ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca * permit persons to whom the Software is furnished to do so, subject to
12ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca * the following conditions:
13ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca *
14ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca * The above copyright notice and this permission notice (including the
15ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca * next paragraph) shall be included in all copies or substantial portions
16ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca * of the Software.
17ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca *
18ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca *
26ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca **************************************************************************/
27ee3383bc5ab81ff12d9faa675c1c38683300ce68José Fonseca
28e529170c11d3cb5812aabeff0a6ee2d7a2ea66f2Keith Whitwell#ifndef LP_RAST_PRIV_H
29e529170c11d3cb5812aabeff0a6ee2d7a2ea66f2Keith Whitwell#define LP_RAST_PRIV_H
30e529170c11d3cb5812aabeff0a6ee2d7a2ea66f2Keith Whitwell
31a1af8eec66c5f7ec421e8011b41c1a7c36319f9fJosé Fonseca#include "os/os_thread.h"
325e6a9005100ec2636ce9734a5e4535216494cf60José Fonseca#include "util/u_format.h"
335e6a9005100ec2636ce9734a5e4535216494cf60José Fonseca#include "gallivm/lp_bld_debug.h"
342b3e1ad731d2bd095a680d3120619972a7eb0242Brian Paul#include "lp_memory.h"
35e529170c11d3cb5812aabeff0a6ee2d7a2ea66f2Keith Whitwell#include "lp_rast.h"
360639765b2850739af1678f10fc0c5706d5827776Brian Paul#include "lp_scene.h"
374c4f98c6fcabc4a2c9ede3647de390a4585cf58aJosé Fonseca#include "lp_state.h"
380639765b2850739af1678f10fc0c5706d5827776Brian Paul#include "lp_texture.h"
392797f2bf57562c95a601a67edca3089641215cc4Brian Paul#include "lp_tile_soa.h"
4039be50dcdebe6bcbb48cb6aa8ac151eee811acb1José Fonseca#include "lp_limits.h"
413a06c113c76355fc9622adfe7565c18d9787e9a8Brian Paul
423a06c113c76355fc9622adfe7565c18d9787e9a8Brian Paul
436c1625cc405f0d77523c122cedf3e8003f2aa7bfBrian Paul/* If we crash in a jitted function, we can examine jit_line and jit_state
446c1625cc405f0d77523c122cedf3e8003f2aa7bfBrian Paul * to get some info.  This is not thread-safe, however.
456c1625cc405f0d77523c122cedf3e8003f2aa7bfBrian Paul */
466c1625cc405f0d77523c122cedf3e8003f2aa7bfBrian Paul#ifdef DEBUG
476c1625cc405f0d77523c122cedf3e8003f2aa7bfBrian Paul
48efc82aef35a2aac5d2ed9774f6d28f2626796416Brian Paulstruct lp_rasterizer_task;
496c1625cc405f0d77523c122cedf3e8003f2aa7bfBrian Paulextern int jit_line;
506c1625cc405f0d77523c122cedf3e8003f2aa7bfBrian Paulextern const struct lp_rast_state *jit_state;
51efc82aef35a2aac5d2ed9774f6d28f2626796416Brian Paulextern const struct lp_rasterizer_task *jit_task;
526c1625cc405f0d77523c122cedf3e8003f2aa7bfBrian Paul
53efc82aef35a2aac5d2ed9774f6d28f2626796416Brian Paul#define BEGIN_JIT_CALL(state, task)                  \
546c1625cc405f0d77523c122cedf3e8003f2aa7bfBrian Paul   do { \
556c1625cc405f0d77523c122cedf3e8003f2aa7bfBrian Paul      jit_line = __LINE__; \
566c1625cc405f0d77523c122cedf3e8003f2aa7bfBrian Paul      jit_state = state; \
57efc82aef35a2aac5d2ed9774f6d28f2626796416Brian Paul      jit_task = task; \
586c1625cc405f0d77523c122cedf3e8003f2aa7bfBrian Paul   } while (0)
596c1625cc405f0d77523c122cedf3e8003f2aa7bfBrian Paul
606c1625cc405f0d77523c122cedf3e8003f2aa7bfBrian Paul#define END_JIT_CALL() \
616c1625cc405f0d77523c122cedf3e8003f2aa7bfBrian Paul   do { \
626c1625cc405f0d77523c122cedf3e8003f2aa7bfBrian Paul      jit_line = 0; \
636c1625cc405f0d77523c122cedf3e8003f2aa7bfBrian Paul      jit_state = NULL; \
646c1625cc405f0d77523c122cedf3e8003f2aa7bfBrian Paul   } while (0)
656c1625cc405f0d77523c122cedf3e8003f2aa7bfBrian Paul
666c1625cc405f0d77523c122cedf3e8003f2aa7bfBrian Paul#else
676c1625cc405f0d77523c122cedf3e8003f2aa7bfBrian Paul
68efc82aef35a2aac5d2ed9774f6d28f2626796416Brian Paul#define BEGIN_JIT_CALL(X, Y)
69e75da1a8d668aa2a245a7c2690b42ae7a6038f48Brian Paul#define END_JIT_CALL()
706c1625cc405f0d77523c122cedf3e8003f2aa7bfBrian Paul
716c1625cc405f0d77523c122cedf3e8003f2aa7bfBrian Paul#endif
726c1625cc405f0d77523c122cedf3e8003f2aa7bfBrian Paul
736c1625cc405f0d77523c122cedf3e8003f2aa7bfBrian Paul
74aab1ceceecbd6449eebce7f5f5b356b1a51552e7Brian Paulstruct lp_rasterizer;
759f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwellstruct cmd_bin;
76a9be9cd8be0fac4be5d65430749666d2204b79a4Brian Paul
77a9be9cd8be0fac4be5d65430749666d2204b79a4Brian Paul/**
783a06c113c76355fc9622adfe7565c18d9787e9a8Brian Paul * Per-thread rasterization state
79a9be9cd8be0fac4be5d65430749666d2204b79a4Brian Paul */
803a06c113c76355fc9622adfe7565c18d9787e9a8Brian Paulstruct lp_rasterizer_task
81a9be9cd8be0fac4be5d65430749666d2204b79a4Brian Paul{
829f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwell   const struct cmd_bin *bin;
834195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell   const struct lp_rast_state *state;
849f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwell
859f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwell   struct lp_scene *scene;
86a9be9cd8be0fac4be5d65430749666d2204b79a4Brian Paul   unsigned x, y;          /**< Pos of this tile in framebuffer, in pixels */
873a06c113c76355fc9622adfe7565c18d9787e9a8Brian Paul
880639765b2850739af1678f10fc0c5706d5827776Brian Paul   uint8_t *color_tiles[PIPE_MAX_COLOR_BUFS];
890639765b2850739af1678f10fc0c5706d5827776Brian Paul   uint8_t *depth_tile;
900639765b2850739af1678f10fc0c5706d5827776Brian Paul
91aab1ceceecbd6449eebce7f5f5b356b1a51552e7Brian Paul   /** "back" pointer */
92aab1ceceecbd6449eebce7f5f5b356b1a51552e7Brian Paul   struct lp_rasterizer *rast;
93aab1ceceecbd6449eebce7f5f5b356b1a51552e7Brian Paul
94aab1ceceecbd6449eebce7f5f5b356b1a51552e7Brian Paul   /** "my" index */
95aab1ceceecbd6449eebce7f5f5b356b1a51552e7Brian Paul   unsigned thread_index;
96aab1ceceecbd6449eebce7f5f5b356b1a51552e7Brian Paul
9786afe8250edaa2e6129c937a62a695f616c48d70Qicheng Christopher Li   /* occlude counter for visiable pixels */
9886afe8250edaa2e6129c937a62a695f616c48d70Qicheng Christopher Li   uint32_t vis_counter;
9918452c1e87f79327fbd5f27478028b481ee72a5dKeith Whitwell   struct llvmpipe_query *query;
10086afe8250edaa2e6129c937a62a695f616c48d70Qicheng Christopher Li
101aab1ceceecbd6449eebce7f5f5b356b1a51552e7Brian Paul   pipe_semaphore work_ready;
102aab1ceceecbd6449eebce7f5f5b356b1a51552e7Brian Paul   pipe_semaphore work_done;
1033a06c113c76355fc9622adfe7565c18d9787e9a8Brian Paul};
1043a06c113c76355fc9622adfe7565c18d9787e9a8Brian Paul
1053a06c113c76355fc9622adfe7565c18d9787e9a8Brian Paul
1063a06c113c76355fc9622adfe7565c18d9787e9a8Brian Paul/**
1073a06c113c76355fc9622adfe7565c18d9787e9a8Brian Paul * This is the state required while rasterizing tiles.
1083a06c113c76355fc9622adfe7565c18d9787e9a8Brian Paul * Note that this contains per-thread information too.
1093a06c113c76355fc9622adfe7565c18d9787e9a8Brian Paul * The tile size is TILE_SIZE x TILE_SIZE pixels.
1103a06c113c76355fc9622adfe7565c18d9787e9a8Brian Paul */
1113a06c113c76355fc9622adfe7565c18d9787e9a8Brian Paulstruct lp_rasterizer
1123a06c113c76355fc9622adfe7565c18d9787e9a8Brian Paul{
113bc04ae21c10bedcc75d3483784d3eaf7bf090f55Brian Paul   boolean exit_flag;
11445df3eb1db7147aca31134723972e1de4f6a7a16Brian Paul   boolean no_rast;  /**< For debugging/profiling */
115e0e2008f1dcd73a59a184e0ef4c1dd77ac2a1cbfKeith Whitwell
116663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell   /** The incoming queue of scenes ready to rasterize */
117663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell   struct lp_scene_queue *full_scenes;
1185fe2ce28b6e9fba181c13c6f49b57b3dd68fe88eKeith Whitwell
119663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell   /** The scene currently being rasterized by the threads */
120663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell   struct lp_scene *curr_scene;
1212bce5c195f94e2cce8f67c6a8066b0ae408487ceBrian Paul
1223a06c113c76355fc9622adfe7565c18d9787e9a8Brian Paul   /** A task object for each rasterization thread */
12339be50dcdebe6bcbb48cb6aa8ac151eee811acb1José Fonseca   struct lp_rasterizer_task tasks[LP_MAX_THREADS];
124aab1ceceecbd6449eebce7f5f5b356b1a51552e7Brian Paul
125aab1ceceecbd6449eebce7f5f5b356b1a51552e7Brian Paul   unsigned num_threads;
12639be50dcdebe6bcbb48cb6aa8ac151eee811acb1José Fonseca   pipe_thread threads[LP_MAX_THREADS];
127aab1ceceecbd6449eebce7f5f5b356b1a51552e7Brian Paul
1282bce5c195f94e2cce8f67c6a8066b0ae408487ceBrian Paul   /** For synchronizing the rasterization threads */
1292bce5c195f94e2cce8f67c6a8066b0ae408487ceBrian Paul   pipe_barrier barrier;
130e529170c11d3cb5812aabeff0a6ee2d7a2ea66f2Keith Whitwell};
131e529170c11d3cb5812aabeff0a6ee2d7a2ea66f2Keith Whitwell
132ab76b2a8b896edc1e972de108d044b70310b4324José Fonseca
133d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwellvoid
134d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwelllp_rast_shade_quads_mask(struct lp_rasterizer_task *task,
135d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell                         const struct lp_rast_shader_inputs *inputs,
136d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell                         unsigned x, unsigned y,
137d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell                         unsigned mask);
138d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell
139ab76b2a8b896edc1e972de108d044b70310b4324José Fonseca
1402797f2bf57562c95a601a67edca3089641215cc4Brian Paul
1412797f2bf57562c95a601a67edca3089641215cc4Brian Paul/**
1420639765b2850739af1678f10fc0c5706d5827776Brian Paul * Get the pointer to a 4x4 depth/stencil block.
1430639765b2850739af1678f10fc0c5706d5827776Brian Paul * We'll map the z/stencil buffer on demand here.
1440639765b2850739af1678f10fc0c5706d5827776Brian Paul * Note that this may be called even when there's no z/stencil buffer - return
1450639765b2850739af1678f10fc0c5706d5827776Brian Paul * NULL in that case.
1465e6a9005100ec2636ce9734a5e4535216494cf60José Fonseca * \param x, y location of 4x4 block in window coords
1475e6a9005100ec2636ce9734a5e4535216494cf60José Fonseca */
1485e6a9005100ec2636ce9734a5e4535216494cf60José Fonsecastatic INLINE void *
1492b3e1ad731d2bd095a680d3120619972a7eb0242Brian Paullp_rast_get_depth_block_pointer(struct lp_rasterizer_task *task,
1500639765b2850739af1678f10fc0c5706d5827776Brian Paul                                unsigned x, unsigned y)
1515e6a9005100ec2636ce9734a5e4535216494cf60José Fonseca{
1529f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwell   const struct lp_scene *scene = task->scene;
1530639765b2850739af1678f10fc0c5706d5827776Brian Paul   void *depth;
1545fe2ce28b6e9fba181c13c6f49b57b3dd68fe88eKeith Whitwell
155c620087432b2055aa9301f19f8b6444080698c90José Fonseca   assert(x < scene->tiles_x * TILE_SIZE);
156c620087432b2055aa9301f19f8b6444080698c90José Fonseca   assert(y < scene->tiles_y * TILE_SIZE);
1575e6a9005100ec2636ce9734a5e4535216494cf60José Fonseca   assert((x % TILE_VECTOR_WIDTH) == 0);
1585e6a9005100ec2636ce9734a5e4535216494cf60José Fonseca   assert((y % TILE_VECTOR_HEIGHT) == 0);
1595fe2ce28b6e9fba181c13c6f49b57b3dd68fe88eKeith Whitwell
1609f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwell   if (!scene->zsbuf.map) {
161e21e7ab4da859198dfa9845b4a7207c49db54771Keith Whitwell      /* Either out of memory or no zsbuf.  Can't tell without access
162e21e7ab4da859198dfa9845b4a7207c49db54771Keith Whitwell       * to the state.  Just use dummy tile memory, but don't print
163e21e7ab4da859198dfa9845b4a7207c49db54771Keith Whitwell       * the oom warning as this most likely because there is no
164e21e7ab4da859198dfa9845b4a7207c49db54771Keith Whitwell       * zsbuf.
165e21e7ab4da859198dfa9845b4a7207c49db54771Keith Whitwell       */
1662f6d47a7c8d6e69e5154de44115aab9ba35a41d2Keith Whitwell      return lp_dummy_tile;
1672b3e1ad731d2bd095a680d3120619972a7eb0242Brian Paul   }
1685fe2ce28b6e9fba181c13c6f49b57b3dd68fe88eKeith Whitwell
1699f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwell   depth = (scene->zsbuf.map +
1709f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwell            scene->zsbuf.stride * y +
1719f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwell            scene->zsbuf.blocksize * x * TILE_VECTOR_HEIGHT);
1725fe2ce28b6e9fba181c13c6f49b57b3dd68fe88eKeith Whitwell
1735e6a9005100ec2636ce9734a5e4535216494cf60José Fonseca   assert(lp_check_alignment(depth, 16));
1745e6a9005100ec2636ce9734a5e4535216494cf60José Fonseca   return depth;
1755e6a9005100ec2636ce9734a5e4535216494cf60José Fonseca}
1765e6a9005100ec2636ce9734a5e4535216494cf60José Fonseca
1775e6a9005100ec2636ce9734a5e4535216494cf60José Fonseca
1780639765b2850739af1678f10fc0c5706d5827776Brian Paul/**
179d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell * Get pointer to the swizzled color tile
180d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell */
181d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwellstatic INLINE uint8_t *
182d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwelllp_rast_get_color_tile_pointer(struct lp_rasterizer_task *task,
183d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell                               unsigned buf, enum lp_texture_usage usage)
184d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell{
1859f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwell   const struct lp_scene *scene = task->scene;
186d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell
187c620087432b2055aa9301f19f8b6444080698c90José Fonseca   assert(task->x < scene->tiles_x * TILE_SIZE);
188c620087432b2055aa9301f19f8b6444080698c90José Fonseca   assert(task->y < scene->tiles_y * TILE_SIZE);
189d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell   assert(task->x % TILE_SIZE == 0);
190d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell   assert(task->y % TILE_SIZE == 0);
1919f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwell   assert(buf < scene->fb.nr_cbufs);
192d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell
193d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell   if (!task->color_tiles[buf]) {
1949f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwell      struct pipe_surface *cbuf = scene->fb.cbufs[buf];
195d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell      struct llvmpipe_resource *lpt;
196d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell      assert(cbuf);
197d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell      lpt = llvmpipe_resource(cbuf->texture);
1982f6d47a7c8d6e69e5154de44115aab9ba35a41d2Keith Whitwell      task->color_tiles[buf] = lp_swizzled_cbuf[task->thread_index][buf];
1992f6d47a7c8d6e69e5154de44115aab9ba35a41d2Keith Whitwell
2002f6d47a7c8d6e69e5154de44115aab9ba35a41d2Keith Whitwell      if (usage != LP_TEX_USAGE_WRITE_ALL) {
2012f6d47a7c8d6e69e5154de44115aab9ba35a41d2Keith Whitwell         llvmpipe_swizzle_cbuf_tile(lpt,
2024c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger                                    cbuf->u.tex.first_layer,
2034c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger                                    cbuf->u.tex.level,
2042f6d47a7c8d6e69e5154de44115aab9ba35a41d2Keith Whitwell                                    task->x, task->y,
2052f6d47a7c8d6e69e5154de44115aab9ba35a41d2Keith Whitwell                                    task->color_tiles[buf]);
206d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell      }
207d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell   }
208d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell
209d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell   return task->color_tiles[buf];
210d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell}
211d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell
212d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell
213d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell/**
2140639765b2850739af1678f10fc0c5706d5827776Brian Paul * Get the pointer to a 4x4 color block (within a 64x64 tile).
2150639765b2850739af1678f10fc0c5706d5827776Brian Paul * We'll map the color buffer on demand here.
2160639765b2850739af1678f10fc0c5706d5827776Brian Paul * Note that this may be called even when there's no color buffers - return
2170639765b2850739af1678f10fc0c5706d5827776Brian Paul * NULL in that case.
2180639765b2850739af1678f10fc0c5706d5827776Brian Paul * \param x, y location of 4x4 block in window coords
2190639765b2850739af1678f10fc0c5706d5827776Brian Paul */
2200639765b2850739af1678f10fc0c5706d5827776Brian Paulstatic INLINE uint8_t *
2210639765b2850739af1678f10fc0c5706d5827776Brian Paullp_rast_get_color_block_pointer(struct lp_rasterizer_task *task,
2220639765b2850739af1678f10fc0c5706d5827776Brian Paul                                unsigned buf, unsigned x, unsigned y)
2230639765b2850739af1678f10fc0c5706d5827776Brian Paul{
2240639765b2850739af1678f10fc0c5706d5827776Brian Paul   unsigned px, py, pixel_offset;
2250639765b2850739af1678f10fc0c5706d5827776Brian Paul   uint8_t *color;
2260639765b2850739af1678f10fc0c5706d5827776Brian Paul
227c620087432b2055aa9301f19f8b6444080698c90José Fonseca   assert(x < task->scene->tiles_x * TILE_SIZE);
228c620087432b2055aa9301f19f8b6444080698c90José Fonseca   assert(y < task->scene->tiles_y * TILE_SIZE);
2290639765b2850739af1678f10fc0c5706d5827776Brian Paul   assert((x % TILE_VECTOR_WIDTH) == 0);
2300639765b2850739af1678f10fc0c5706d5827776Brian Paul   assert((y % TILE_VECTOR_HEIGHT) == 0);
2310639765b2850739af1678f10fc0c5706d5827776Brian Paul
232d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell   color = lp_rast_get_color_tile_pointer(task, buf, LP_TEX_USAGE_READ_WRITE);
2332f6d47a7c8d6e69e5154de44115aab9ba35a41d2Keith Whitwell   assert(color);
2340639765b2850739af1678f10fc0c5706d5827776Brian Paul
2350639765b2850739af1678f10fc0c5706d5827776Brian Paul   px = x % TILE_SIZE;
2360639765b2850739af1678f10fc0c5706d5827776Brian Paul   py = y % TILE_SIZE;
2370639765b2850739af1678f10fc0c5706d5827776Brian Paul   pixel_offset = tile_pixel_offset(px, py, 0);
2380639765b2850739af1678f10fc0c5706d5827776Brian Paul
2390639765b2850739af1678f10fc0c5706d5827776Brian Paul   color = color + pixel_offset;
2400639765b2850739af1678f10fc0c5706d5827776Brian Paul
2410639765b2850739af1678f10fc0c5706d5827776Brian Paul   assert(lp_check_alignment(color, 16));
2420639765b2850739af1678f10fc0c5706d5827776Brian Paul   return color;
2430639765b2850739af1678f10fc0c5706d5827776Brian Paul}
2440639765b2850739af1678f10fc0c5706d5827776Brian Paul
2450639765b2850739af1678f10fc0c5706d5827776Brian Paul
2465e6a9005100ec2636ce9734a5e4535216494cf60José Fonseca
2475e6a9005100ec2636ce9734a5e4535216494cf60José Fonseca/**
2482797f2bf57562c95a601a67edca3089641215cc4Brian Paul * Shade all pixels in a 4x4 block.  The fragment code omits the
2492797f2bf57562c95a601a67edca3089641215cc4Brian Paul * triangle in/out tests.
2502797f2bf57562c95a601a67edca3089641215cc4Brian Paul * \param x, y location of 4x4 block in window coords
2512797f2bf57562c95a601a67edca3089641215cc4Brian Paul */
2522797f2bf57562c95a601a67edca3089641215cc4Brian Paulstatic INLINE void
2531c9db3c57f1538e21b839df0989b958be3465a36Brian Paullp_rast_shade_quads_all( struct lp_rasterizer_task *task,
2542797f2bf57562c95a601a67edca3089641215cc4Brian Paul                         const struct lp_rast_shader_inputs *inputs,
2552797f2bf57562c95a601a67edca3089641215cc4Brian Paul                         unsigned x, unsigned y )
2562797f2bf57562c95a601a67edca3089641215cc4Brian Paul{
2579f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwell   const struct lp_scene *scene = task->scene;
2584195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell   const struct lp_rast_state *state = task->state;
25918fb9ff6d8f58a08e559070cf29f26ed0caa567fJosé Fonseca   struct lp_fragment_shader_variant *variant = state->variant;
2602797f2bf57562c95a601a67edca3089641215cc4Brian Paul   uint8_t *color[PIPE_MAX_COLOR_BUFS];
2612797f2bf57562c95a601a67edca3089641215cc4Brian Paul   void *depth;
2620639765b2850739af1678f10fc0c5706d5827776Brian Paul   unsigned i;
2632797f2bf57562c95a601a67edca3089641215cc4Brian Paul
2642797f2bf57562c95a601a67edca3089641215cc4Brian Paul   /* color buffer */
2659f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwell   for (i = 0; i < scene->fb.nr_cbufs; i++)
2660639765b2850739af1678f10fc0c5706d5827776Brian Paul      color[i] = lp_rast_get_color_block_pointer(task, i, x, y);
2670639765b2850739af1678f10fc0c5706d5827776Brian Paul
2682b3e1ad731d2bd095a680d3120619972a7eb0242Brian Paul   depth = lp_rast_get_depth_block_pointer(task, x, y);
2690639765b2850739af1678f10fc0c5706d5827776Brian Paul
2700639765b2850739af1678f10fc0c5706d5827776Brian Paul   /* run shader on 4x4 block */
271efc82aef35a2aac5d2ed9774f6d28f2626796416Brian Paul   BEGIN_JIT_CALL(state, task);
27218fb9ff6d8f58a08e559070cf29f26ed0caa567fJosé Fonseca   variant->jit_function[RAST_WHOLE]( &state->jit_context,
273d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell                                      x, y,
2740a1c9001037a13b69b157994e7983aa3dee158d3Keith Whitwell                                      inputs->frontfacing,
2759bf8a55c4b29d55320fc2e7875ecf0e9ca164ee8Keith Whitwell                                      GET_A0(inputs),
2769bf8a55c4b29d55320fc2e7875ecf0e9ca164ee8Keith Whitwell                                      GET_DADX(inputs),
2779bf8a55c4b29d55320fc2e7875ecf0e9ca164ee8Keith Whitwell                                      GET_DADY(inputs),
278d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell                                      color,
279d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell                                      depth,
280d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell                                      0xffff,
281d4b64167b56f780d0dea73193c345622888fbc16Keith Whitwell                                      &task->vis_counter );
2826c1625cc405f0d77523c122cedf3e8003f2aa7bfBrian Paul   END_JIT_CALL();
2832797f2bf57562c95a601a67edca3089641215cc4Brian Paul}
2842797f2bf57562c95a601a67edca3089641215cc4Brian Paul
2859f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwellvoid lp_rast_triangle_1( struct lp_rasterizer_task *,
2869f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwell                         const union lp_rast_cmd_arg );
2879f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwellvoid lp_rast_triangle_2( struct lp_rasterizer_task *,
2889f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwell                         const union lp_rast_cmd_arg );
2899f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwellvoid lp_rast_triangle_3( struct lp_rasterizer_task *,
2909f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwell                         const union lp_rast_cmd_arg );
2919f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwellvoid lp_rast_triangle_4( struct lp_rasterizer_task *,
2929f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwell                         const union lp_rast_cmd_arg );
2939f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwellvoid lp_rast_triangle_5( struct lp_rasterizer_task *,
2949f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwell                         const union lp_rast_cmd_arg );
2959f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwellvoid lp_rast_triangle_6( struct lp_rasterizer_task *,
2969f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwell                         const union lp_rast_cmd_arg );
2979f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwellvoid lp_rast_triangle_7( struct lp_rasterizer_task *,
2989f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwell                         const union lp_rast_cmd_arg );
2999f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwellvoid lp_rast_triangle_8( struct lp_rasterizer_task *,
3009f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwell                         const union lp_rast_cmd_arg );
3019f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwell
302c4046d4fda2fe838659bff99bfa17f57f895a943Keith Whitwellvoid lp_rast_triangle_3_4(struct lp_rasterizer_task *,
303c4046d4fda2fe838659bff99bfa17f57f895a943Keith Whitwell			  const union lp_rast_cmd_arg );
304c4046d4fda2fe838659bff99bfa17f57f895a943Keith Whitwell
3059f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwellvoid lp_rast_triangle_3_16( struct lp_rasterizer_task *,
3069f6e8e1d6b8696a3ee96cba01b2466ba7a1a8ef6Keith Whitwell                            const union lp_rast_cmd_arg );
3070ff132e5a633170afaed0aea54d01438c895b8abKeith Whitwell
3080ff132e5a633170afaed0aea54d01438c895b8abKeith Whitwellvoid lp_rast_triangle_4_16( struct lp_rasterizer_task *,
3090ff132e5a633170afaed0aea54d01438c895b8abKeith Whitwell                            const union lp_rast_cmd_arg );
3100ff132e5a633170afaed0aea54d01438c895b8abKeith Whitwell
311f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwellvoid
3124195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwelllp_rast_set_state(struct lp_rasterizer_task *task,
3134195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell                  const union lp_rast_cmd_arg arg);
3144195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwell
3154195febeecd2d2f5571afdb90cbb185a4759f50aKeith Whitwellvoid
316f25836d7b2c21e046a725cf13c8649d3981693b7Keith Whitwelllp_debug_bin( const struct cmd_bin *bin );
3172797f2bf57562c95a601a67edca3089641215cc4Brian Paul
318e529170c11d3cb5812aabeff0a6ee2d7a2ea66f2Keith Whitwell#endif
319