Path: blob/21.2-virgl/src/gallium/drivers/swr/swr_context.h
4570 views
/****************************************************************************1* Copyright (C) 2015 Intel Corporation. All Rights Reserved.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21***************************************************************************/2223#ifndef SWR_CONTEXT_H24#define SWR_CONTEXT_H2526#include "common/os.h"2728#include "pipe/p_context.h"29#include "pipe/p_state.h"30#include "util/u_blitter.h"31#include "rasterizer/memory/SurfaceState.h"32#include "rasterizer/memory/InitMemory.h"33#include "jit_api.h"34#include "swr_state.h"35#include <unordered_map>3637#define SWR_NEW_BLEND (1 << 0)38#define SWR_NEW_RASTERIZER (1 << 1)39#define SWR_NEW_DEPTH_STENCIL_ALPHA (1 << 2)40#define SWR_NEW_SAMPLER (1 << 3)41#define SWR_NEW_SAMPLER_VIEW (1 << 4)42#define SWR_NEW_VS (1 << 5)43#define SWR_NEW_FS (1 << 6)44#define SWR_NEW_GS (1 << 7)45#define SWR_NEW_VSCONSTANTS (1 << 8)46#define SWR_NEW_FSCONSTANTS (1 << 9)47#define SWR_NEW_GSCONSTANTS (1 << 10)48#define SWR_NEW_VERTEX (1 << 11)49#define SWR_NEW_STIPPLE (1 << 12)50#define SWR_NEW_SCISSOR (1 << 13)51#define SWR_NEW_VIEWPORT (1 << 14)52#define SWR_NEW_FRAMEBUFFER (1 << 15)53#define SWR_NEW_CLIP (1 << 16)54#define SWR_NEW_SO (1 << 17)55#define SWR_BLOCK_CLIENT_DRAW ( 1 << 18) // Indicates client draw will block56#define SWR_NEW_TCS (1 << 19)57#define SWR_NEW_TES (1 << 20)58#define SWR_NEW_TS (1 << 21)59#define SWR_NEW_TCSCONSTANTS (1 << 22)60#define SWR_NEW_TESCONSTANTS (1 << 23)6162namespace std63{64template <> struct hash<BLEND_COMPILE_STATE> {65std::size_t operator()(const BLEND_COMPILE_STATE &k) const66{67return util_hash_crc32(&k, sizeof(k));68}69};70};7172struct swr_jit_texture {73uint32_t width; // same as number of elements74uint32_t height;75uint32_t depth; // doubles as array size76uint32_t first_level;77uint32_t last_level;78const uint8_t *base_ptr;79uint32_t num_samples;80uint32_t sample_stride;81uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS];82uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS];83uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS];84};8586struct swr_jit_sampler {87float min_lod;88float max_lod;89float lod_bias;90float border_color[4];91};9293struct swr_draw_context {94const float *constantVS[PIPE_MAX_CONSTANT_BUFFERS];95uint32_t num_constantsVS[PIPE_MAX_CONSTANT_BUFFERS];96const float *constantFS[PIPE_MAX_CONSTANT_BUFFERS];97uint32_t num_constantsFS[PIPE_MAX_CONSTANT_BUFFERS];98const float *constantGS[PIPE_MAX_CONSTANT_BUFFERS];99uint32_t num_constantsGS[PIPE_MAX_CONSTANT_BUFFERS];100const float *constantTCS[PIPE_MAX_CONSTANT_BUFFERS];101uint32_t num_constantsTCS[PIPE_MAX_CONSTANT_BUFFERS];102const float *constantTES[PIPE_MAX_CONSTANT_BUFFERS];103uint32_t num_constantsTES[PIPE_MAX_CONSTANT_BUFFERS];104105swr_jit_texture texturesVS[PIPE_MAX_SHADER_SAMPLER_VIEWS];106swr_jit_sampler samplersVS[PIPE_MAX_SAMPLERS];107swr_jit_texture texturesFS[PIPE_MAX_SHADER_SAMPLER_VIEWS];108swr_jit_sampler samplersFS[PIPE_MAX_SAMPLERS];109swr_jit_texture texturesGS[PIPE_MAX_SHADER_SAMPLER_VIEWS];110swr_jit_sampler samplersGS[PIPE_MAX_SAMPLERS];111swr_jit_texture texturesTCS[PIPE_MAX_SHADER_SAMPLER_VIEWS];112swr_jit_sampler samplersTCS[PIPE_MAX_SAMPLERS];113swr_jit_texture texturesTES[PIPE_MAX_SHADER_SAMPLER_VIEWS];114swr_jit_sampler samplersTES[PIPE_MAX_SAMPLERS];115116float userClipPlanes[PIPE_MAX_CLIP_PLANES][4];117118uint32_t polyStipple[32];119120SWR_SURFACE_STATE renderTargets[SWR_NUM_ATTACHMENTS];121struct swr_query_result *pStats; // @llvm_struct122SWR_INTERFACE *pAPI; // @llvm_struct - Needed for the swr_memory callbacks123SWR_TILE_INTERFACE *pTileAPI; // @llvm_struct - Needed for the swr_memory callbacks124125uint64_t* soPrims; //number of primitives written to StreamOut buffer126};127128/* gen_llvm_types FINI */129130struct swr_context {131struct pipe_context pipe; /**< base class */132133HANDLE swrContext;134135SWR_TS_STATE tsState;136137/** Constant state objects */138struct swr_blend_state *blend;139struct pipe_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];140struct pipe_depth_stencil_alpha_state *depth_stencil;141struct pipe_rasterizer_state *rasterizer;142143struct swr_vertex_shader *vs;144struct swr_fragment_shader *fs;145struct swr_geometry_shader *gs;146struct swr_tess_control_shader *tcs;147struct swr_tess_evaluation_shader *tes;148struct swr_vertex_element_state *velems;149150/** Other rendering state */151struct pipe_blend_color blend_color;152struct pipe_stencil_ref stencil_ref;153struct pipe_clip_state clip;154struct pipe_constant_buffer155constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];156struct pipe_framebuffer_state framebuffer;157struct swr_poly_stipple poly_stipple;158struct pipe_scissor_state scissors[KNOB_NUM_VIEWPORTS_SCISSORS];159SWR_RECT swr_scissors[KNOB_NUM_VIEWPORTS_SCISSORS];160struct pipe_sampler_view *161sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];162163struct pipe_viewport_state viewports[KNOB_NUM_VIEWPORTS_SCISSORS];164struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];165166struct blitter_context *blitter;167168/** Conditional query object and mode */169struct pipe_query *render_cond_query;170enum pipe_render_cond_flag render_cond_mode;171bool render_cond_cond;172unsigned active_queries;173174unsigned num_vertex_buffers;175unsigned num_samplers[PIPE_SHADER_TYPES];176unsigned num_sampler_views[PIPE_SHADER_TYPES];177178unsigned sample_mask;179180// streamout181pipe_stream_output_target *so_targets[MAX_SO_STREAMS];182uint32_t num_so_targets;183uint64_t so_primCounter; // number of primitives written to StreamOut buffer184185/* Temp storage for user_buffer constants */186struct swr_scratch_buffers *scratch;187188// blend jit functions189std::unordered_map<BLEND_COMPILE_STATE, PFN_BLEND_JIT_FUNC> *blendJIT;190191/* Derived SWR API DrawState */192struct swr_derived_state derived;193194/* SWR private state - draw context */195struct swr_draw_context swrDC;196197unsigned dirty; /**< Mask of SWR_NEW_x flags */198199SWR_INTERFACE api;200SWR_TILE_INTERFACE tileApi;201202uint32_t max_draws_in_flight;203};204205static INLINE struct swr_context *206swr_context(struct pipe_context *pipe)207{208return (struct swr_context *)pipe;209}210211static INLINE void212swr_update_draw_context(struct swr_context *ctx,213struct swr_query_result *pqr = nullptr)214{215swr_draw_context *pDC =216(swr_draw_context *)ctx->api.pfnSwrGetPrivateContextState(ctx->swrContext);217if (pqr)218ctx->swrDC.pStats = pqr;219memcpy(pDC, &ctx->swrDC, sizeof(swr_draw_context));220}221222struct pipe_context *swr_create_context(struct pipe_screen *, void *priv, unsigned flags);223224void swr_state_init(struct pipe_context *pipe);225226void swr_clear_init(struct pipe_context *pipe);227228void swr_draw_init(struct pipe_context *pipe);229230void swr_finish(struct pipe_context *pipe);231232void swr_do_msaa_resolve(struct pipe_resource *src_resource,233struct pipe_resource *dst_resource);234#endif235236237