Path: blob/21.2-virgl/src/gallium/drivers/llvmpipe/lp_rast_priv.h
4570 views
/**************************************************************************1*2* Copyright 2009 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627#ifndef LP_RAST_PRIV_H28#define LP_RAST_PRIV_H2930#include "util/format/u_format.h"31#include "util/u_thread.h"32#include "gallivm/lp_bld_debug.h"33#include "lp_memory.h"34#include "lp_rast.h"35#include "lp_scene.h"36#include "lp_state.h"37#include "lp_texture.h"38#include "lp_limits.h"394041#define TILE_VECTOR_HEIGHT 442#define TILE_VECTOR_WIDTH 44344/* If we crash in a jitted function, we can examine jit_line and jit_state45* to get some info. This is not thread-safe, however.46*/47#ifdef DEBUG4849struct lp_rasterizer_task;50extern int jit_line;51extern const struct lp_rast_state *jit_state;52extern const struct lp_rasterizer_task *jit_task;5354#define BEGIN_JIT_CALL(state, task) \55do { \56jit_line = __LINE__; \57jit_state = state; \58jit_task = task; \59} while (0)6061#define END_JIT_CALL() \62do { \63jit_line = 0; \64jit_state = NULL; \65} while (0)6667#else6869#define BEGIN_JIT_CALL(X, Y)70#define END_JIT_CALL()7172#endif737475struct lp_rasterizer;76struct cmd_bin;7778/**79* Per-thread rasterization state80*/81struct lp_rasterizer_task82{83const struct cmd_bin *bin;84const struct lp_rast_state *state;8586struct lp_scene *scene;87unsigned x, y; /**< Pos of this tile in framebuffer, in pixels */88unsigned width, height; /**< width, height of current tile, in pixels */8990uint8_t *color_tiles[PIPE_MAX_COLOR_BUFS];91uint8_t *depth_tile;9293/** "back" pointer */94struct lp_rasterizer *rast;9596/** "my" index */97unsigned thread_index;9899/** Non-interpolated passthru state and occlude counter for visible pixels */100struct lp_jit_thread_data thread_data;101102pipe_semaphore work_ready;103pipe_semaphore work_done;104};105106107/**108* This is the state required while rasterizing tiles.109* Note that this contains per-thread information too.110* The tile size is TILE_SIZE x TILE_SIZE pixels.111*/112struct lp_rasterizer113{114boolean exit_flag;115boolean no_rast; /**< For debugging/profiling */116117/** The incoming queue of scenes ready to rasterize */118struct lp_scene_queue *full_scenes;119120/** The scene currently being rasterized by the threads */121struct lp_scene *curr_scene;122123/** A task object for each rasterization thread */124struct lp_rasterizer_task tasks[LP_MAX_THREADS];125126unsigned num_threads;127thrd_t threads[LP_MAX_THREADS];128129/** For synchronizing the rasterization threads */130util_barrier barrier;131};132133void134lp_rast_shade_quads_mask_sample(struct lp_rasterizer_task *task,135const struct lp_rast_shader_inputs *inputs,136unsigned x, unsigned y,137uint64_t mask);138void139lp_rast_shade_quads_mask(struct lp_rasterizer_task *task,140const struct lp_rast_shader_inputs *inputs,141unsigned x, unsigned y,142unsigned mask);143144145/**146* Get the pointer to a 4x4 color block (within a 64x64 tile).147* \param x, y location of 4x4 block in window coords148*/149static inline uint8_t *150lp_rast_get_color_block_pointer(struct lp_rasterizer_task *task,151unsigned buf, unsigned x, unsigned y,152unsigned layer)153{154unsigned px, py, pixel_offset;155uint8_t *color;156157assert(x < task->scene->tiles_x * TILE_SIZE);158assert(y < task->scene->tiles_y * TILE_SIZE);159assert((x % TILE_VECTOR_WIDTH) == 0);160assert((y % TILE_VECTOR_HEIGHT) == 0);161assert(buf < task->scene->fb.nr_cbufs);162163assert(task->color_tiles[buf]);164165/*166* We don't actually benefit from having per tile cbuf/zsbuf pointers,167* it's just extra work - the mul/add would be exactly the same anyway.168* Fortunately the extra work (modulo) here is very cheap at least...169*/170px = x % TILE_SIZE;171py = y % TILE_SIZE;172173pixel_offset = px * task->scene->cbufs[buf].format_bytes +174py * task->scene->cbufs[buf].stride;175color = task->color_tiles[buf] + pixel_offset;176177if (layer) {178color += layer * task->scene->cbufs[buf].layer_stride;179}180181assert(lp_check_alignment(color, llvmpipe_get_format_alignment(task->scene->fb.cbufs[buf]->format)));182return color;183}184185186/**187* Get the pointer to a 4x4 depth block (within a 64x64 tile).188* \param x, y location of 4x4 block in window coords189*/190static inline uint8_t *191lp_rast_get_depth_block_pointer(struct lp_rasterizer_task *task,192unsigned x, unsigned y, unsigned layer)193{194unsigned px, py, pixel_offset;195uint8_t *depth;196197assert(x < task->scene->tiles_x * TILE_SIZE);198assert(y < task->scene->tiles_y * TILE_SIZE);199assert((x % TILE_VECTOR_WIDTH) == 0);200assert((y % TILE_VECTOR_HEIGHT) == 0);201202assert(task->depth_tile);203204px = x % TILE_SIZE;205py = y % TILE_SIZE;206207pixel_offset = px * task->scene->zsbuf.format_bytes +208py * task->scene->zsbuf.stride;209depth = task->depth_tile + pixel_offset;210211if (layer) {212depth += layer * task->scene->zsbuf.layer_stride;213}214215assert(lp_check_alignment(depth, llvmpipe_get_format_alignment(task->scene->fb.zsbuf->format)));216return depth;217}218219220221/**222* Shade all pixels in a 4x4 block. The fragment code omits the223* triangle in/out tests.224* \param x, y location of 4x4 block in window coords225*/226static inline void227lp_rast_shade_quads_all( struct lp_rasterizer_task *task,228const struct lp_rast_shader_inputs *inputs,229unsigned x, unsigned y )230{231const struct lp_scene *scene = task->scene;232const struct lp_rast_state *state = task->state;233struct lp_fragment_shader_variant *variant = state->variant;234uint8_t *color[PIPE_MAX_COLOR_BUFS];235unsigned stride[PIPE_MAX_COLOR_BUFS];236unsigned sample_stride[PIPE_MAX_COLOR_BUFS];237uint8_t *depth = NULL;238unsigned depth_stride = 0;239unsigned depth_sample_stride = 0;240unsigned i;241242/* color buffer */243for (i = 0; i < scene->fb.nr_cbufs; i++) {244if (scene->fb.cbufs[i]) {245stride[i] = scene->cbufs[i].stride;246sample_stride[i] = scene->cbufs[i].sample_stride;247color[i] = lp_rast_get_color_block_pointer(task, i, x, y,248inputs->layer + inputs->view_index);249}250else {251stride[i] = 0;252sample_stride[i] = 0;253color[i] = NULL;254}255}256257if (scene->zsbuf.map) {258depth = lp_rast_get_depth_block_pointer(task, x, y, inputs->layer + inputs->view_index);259depth_sample_stride = scene->zsbuf.sample_stride;260depth_stride = scene->zsbuf.stride;261}262263uint64_t mask = 0;264for (unsigned i = 0; i < scene->fb_max_samples; i++)265mask |= (uint64_t)0xffff << (16 * i);266267/*268* The rasterizer may produce fragments outside our269* allocated 4x4 blocks hence need to filter them out here.270*/271if ((x % TILE_SIZE) < task->width && (y % TILE_SIZE) < task->height) {272/* Propagate non-interpolated raster state. */273task->thread_data.raster_state.viewport_index = inputs->viewport_index;274task->thread_data.raster_state.view_index = inputs->view_index;275276/* run shader on 4x4 block */277BEGIN_JIT_CALL(state, task);278variant->jit_function[RAST_WHOLE]( &state->jit_context,279x, y,280inputs->frontfacing,281GET_A0(inputs),282GET_DADX(inputs),283GET_DADY(inputs),284color,285depth,286mask,287&task->thread_data,288stride,289depth_stride,290sample_stride,291depth_sample_stride);292END_JIT_CALL();293}294}295296void lp_rast_triangle_1( struct lp_rasterizer_task *,297const union lp_rast_cmd_arg );298void lp_rast_triangle_2( struct lp_rasterizer_task *,299const union lp_rast_cmd_arg );300void lp_rast_triangle_3( struct lp_rasterizer_task *,301const union lp_rast_cmd_arg );302void lp_rast_triangle_4( struct lp_rasterizer_task *,303const union lp_rast_cmd_arg );304void lp_rast_triangle_5( struct lp_rasterizer_task *,305const union lp_rast_cmd_arg );306void lp_rast_triangle_6( struct lp_rasterizer_task *,307const union lp_rast_cmd_arg );308void lp_rast_triangle_7( struct lp_rasterizer_task *,309const union lp_rast_cmd_arg );310void lp_rast_triangle_8( struct lp_rasterizer_task *,311const union lp_rast_cmd_arg );312313void lp_rast_triangle_3_4(struct lp_rasterizer_task *,314const union lp_rast_cmd_arg );315316void lp_rast_triangle_3_16( struct lp_rasterizer_task *,317const union lp_rast_cmd_arg );318319void lp_rast_triangle_4_16( struct lp_rasterizer_task *,320const union lp_rast_cmd_arg );321322323void lp_rast_triangle_32_1( struct lp_rasterizer_task *,324const union lp_rast_cmd_arg );325void lp_rast_triangle_32_2( struct lp_rasterizer_task *,326const union lp_rast_cmd_arg );327void lp_rast_triangle_32_3( struct lp_rasterizer_task *,328const union lp_rast_cmd_arg );329void lp_rast_triangle_32_4( struct lp_rasterizer_task *,330const union lp_rast_cmd_arg );331void lp_rast_triangle_32_5( struct lp_rasterizer_task *,332const union lp_rast_cmd_arg );333void lp_rast_triangle_32_6( struct lp_rasterizer_task *,334const union lp_rast_cmd_arg );335void lp_rast_triangle_32_7( struct lp_rasterizer_task *,336const union lp_rast_cmd_arg );337void lp_rast_triangle_32_8( struct lp_rasterizer_task *,338const union lp_rast_cmd_arg );339340void lp_rast_triangle_32_3_4(struct lp_rasterizer_task *,341const union lp_rast_cmd_arg );342343void lp_rast_triangle_32_3_16( struct lp_rasterizer_task *,344const union lp_rast_cmd_arg );345346void lp_rast_triangle_32_4_16( struct lp_rasterizer_task *,347const union lp_rast_cmd_arg );348349void lp_rast_triangle_ms_1( struct lp_rasterizer_task *,350const union lp_rast_cmd_arg );351void lp_rast_triangle_ms_2( struct lp_rasterizer_task *,352const union lp_rast_cmd_arg );353void lp_rast_triangle_ms_3( struct lp_rasterizer_task *,354const union lp_rast_cmd_arg );355void lp_rast_triangle_ms_4( struct lp_rasterizer_task *,356const union lp_rast_cmd_arg );357void lp_rast_triangle_ms_5( struct lp_rasterizer_task *,358const union lp_rast_cmd_arg );359void lp_rast_triangle_ms_6( struct lp_rasterizer_task *,360const union lp_rast_cmd_arg );361void lp_rast_triangle_ms_7( struct lp_rasterizer_task *,362const union lp_rast_cmd_arg );363void lp_rast_triangle_ms_8( struct lp_rasterizer_task *,364const union lp_rast_cmd_arg );365366void lp_rast_triangle_ms_3_4(struct lp_rasterizer_task *,367const union lp_rast_cmd_arg );368369void lp_rast_triangle_ms_3_16( struct lp_rasterizer_task *,370const union lp_rast_cmd_arg );371372void lp_rast_triangle_ms_4_16( struct lp_rasterizer_task *,373const union lp_rast_cmd_arg );374375void lp_rast_triangle_ms_32_1( struct lp_rasterizer_task *,376const union lp_rast_cmd_arg );377void lp_rast_triangle_ms_32_2( struct lp_rasterizer_task *,378const union lp_rast_cmd_arg );379void lp_rast_triangle_ms_32_3( struct lp_rasterizer_task *,380const union lp_rast_cmd_arg );381void lp_rast_triangle_ms_32_4( struct lp_rasterizer_task *,382const union lp_rast_cmd_arg );383void lp_rast_triangle_ms_32_5( struct lp_rasterizer_task *,384const union lp_rast_cmd_arg );385void lp_rast_triangle_ms_32_6( struct lp_rasterizer_task *,386const union lp_rast_cmd_arg );387void lp_rast_triangle_ms_32_7( struct lp_rasterizer_task *,388const union lp_rast_cmd_arg );389void lp_rast_triangle_ms_32_8( struct lp_rasterizer_task *,390const union lp_rast_cmd_arg );391392void lp_rast_triangle_ms_32_3_4(struct lp_rasterizer_task *,393const union lp_rast_cmd_arg );394395void lp_rast_triangle_ms_32_3_16( struct lp_rasterizer_task *,396const union lp_rast_cmd_arg );397398void lp_rast_triangle_ms_32_4_16( struct lp_rasterizer_task *,399const union lp_rast_cmd_arg );400401void402lp_rast_set_state(struct lp_rasterizer_task *task,403const union lp_rast_cmd_arg arg);404405void406lp_debug_bin( const struct cmd_bin *bin, int x, int y );407408#endif409410411