"Fossies" - the Fresh Open Source Software Archive

Member "mesa-20.1.8/src/gallium/drivers/swr/swr_context.h" (16 Sep 2020, 7953 Bytes) of package /linux/misc/mesa-20.1.8.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "swr_context.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 20.1.5_vs_20.2.0-rc1.

    1 /****************************************************************************
    2  * Copyright (C) 2015 Intel Corporation.   All Rights Reserved.
    3  *
    4  * Permission is hereby granted, free of charge, to any person obtaining a
    5  * copy of this software and associated documentation files (the "Software"),
    6  * to deal in the Software without restriction, including without limitation
    7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
    8  * and/or sell copies of the Software, and to permit persons to whom the
    9  * Software is furnished to do so, subject to the following conditions:
   10  *
   11  * The above copyright notice and this permission notice (including the next
   12  * paragraph) shall be included in all copies or substantial portions of the
   13  * Software.
   14  *
   15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
   18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
   20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
   21  * IN THE SOFTWARE.
   22  ***************************************************************************/
   23 
   24 #ifndef SWR_CONTEXT_H
   25 #define SWR_CONTEXT_H
   26 
   27 #include "common/os.h"
   28 
   29 #include "pipe/p_context.h"
   30 #include "pipe/p_state.h"
   31 #include "util/u_blitter.h"
   32 #include "rasterizer/memory/SurfaceState.h"
   33 #include "rasterizer/memory/InitMemory.h"
   34 #include "jit_api.h"
   35 #include "swr_state.h"
   36 #include <unordered_map>
   37 
   38 #define SWR_NEW_BLEND (1 << 0)
   39 #define SWR_NEW_RASTERIZER (1 << 1)
   40 #define SWR_NEW_DEPTH_STENCIL_ALPHA (1 << 2)
   41 #define SWR_NEW_SAMPLER (1 << 3)
   42 #define SWR_NEW_SAMPLER_VIEW (1 << 4)
   43 #define SWR_NEW_VS (1 << 5)
   44 #define SWR_NEW_FS (1 << 6)
   45 #define SWR_NEW_GS (1 << 7)
   46 #define SWR_NEW_VSCONSTANTS (1 << 8)
   47 #define SWR_NEW_FSCONSTANTS (1 << 9)
   48 #define SWR_NEW_GSCONSTANTS (1 << 10)
   49 #define SWR_NEW_VERTEX (1 << 11)
   50 #define SWR_NEW_STIPPLE (1 << 12)
   51 #define SWR_NEW_SCISSOR (1 << 13)
   52 #define SWR_NEW_VIEWPORT (1 << 14)
   53 #define SWR_NEW_FRAMEBUFFER (1 << 15)
   54 #define SWR_NEW_CLIP (1 << 16)
   55 #define SWR_NEW_SO (1 << 17)
   56 #define SWR_BLOCK_CLIENT_DRAW ( 1 << 18) // Indicates client draw will block
   57 #define SWR_NEW_TCS (1 << 19)
   58 #define SWR_NEW_TES (1 << 20)
   59 #define SWR_NEW_TS (1 << 21)
   60 #define SWR_NEW_TCSCONSTANTS (1 << 22)
   61 #define SWR_NEW_TESCONSTANTS (1 << 23)
   62 
   63 namespace std
   64 {
   65 template <> struct hash<BLEND_COMPILE_STATE> {
   66    std::size_t operator()(const BLEND_COMPILE_STATE &k) const
   67    {
   68       return util_hash_crc32(&k, sizeof(k));
   69    }
   70 };
   71 };
   72 
   73 struct swr_jit_texture {
   74    uint32_t width; // same as number of elements
   75    uint32_t height;
   76    uint32_t depth; // doubles as array size
   77    uint32_t first_level;
   78    uint32_t last_level;
   79    const uint8_t *base_ptr;
   80    uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS];
   81    uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS];
   82    uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS];
   83 };
   84 
   85 struct swr_jit_sampler {
   86    float min_lod;
   87    float max_lod;
   88    float lod_bias;
   89    float border_color[4];
   90 };
   91 
   92 struct swr_draw_context {
   93    const float *constantVS[PIPE_MAX_CONSTANT_BUFFERS];
   94    uint32_t num_constantsVS[PIPE_MAX_CONSTANT_BUFFERS];
   95    const float *constantFS[PIPE_MAX_CONSTANT_BUFFERS];
   96    uint32_t num_constantsFS[PIPE_MAX_CONSTANT_BUFFERS];
   97    const float *constantGS[PIPE_MAX_CONSTANT_BUFFERS];
   98    uint32_t num_constantsGS[PIPE_MAX_CONSTANT_BUFFERS];
   99    const float *constantTCS[PIPE_MAX_CONSTANT_BUFFERS];
  100    uint32_t num_constantsTCS[PIPE_MAX_CONSTANT_BUFFERS];
  101    const float *constantTES[PIPE_MAX_CONSTANT_BUFFERS];
  102    uint32_t num_constantsTES[PIPE_MAX_CONSTANT_BUFFERS];
  103 
  104    swr_jit_texture texturesVS[PIPE_MAX_SHADER_SAMPLER_VIEWS];
  105    swr_jit_sampler samplersVS[PIPE_MAX_SAMPLERS];
  106    swr_jit_texture texturesFS[PIPE_MAX_SHADER_SAMPLER_VIEWS];
  107    swr_jit_sampler samplersFS[PIPE_MAX_SAMPLERS];
  108    swr_jit_texture texturesGS[PIPE_MAX_SHADER_SAMPLER_VIEWS];
  109    swr_jit_sampler samplersGS[PIPE_MAX_SAMPLERS];
  110    swr_jit_texture texturesTCS[PIPE_MAX_SHADER_SAMPLER_VIEWS];
  111    swr_jit_sampler samplersTCS[PIPE_MAX_SAMPLERS];
  112    swr_jit_texture texturesTES[PIPE_MAX_SHADER_SAMPLER_VIEWS];
  113    swr_jit_sampler samplersTES[PIPE_MAX_SAMPLERS];
  114 
  115    float userClipPlanes[PIPE_MAX_CLIP_PLANES][4];
  116 
  117    uint32_t polyStipple[32];
  118 
  119    SWR_SURFACE_STATE renderTargets[SWR_NUM_ATTACHMENTS];
  120    struct swr_query_result *pStats; // @llvm_struct
  121    SWR_INTERFACE *pAPI; // @llvm_struct - Needed for the swr_memory callbacks
  122    SWR_TILE_INTERFACE *pTileAPI; // @llvm_struct - Needed for the swr_memory callbacks
  123 
  124    uint64_t* soPrims; //number of primitives written to StreamOut buffer
  125 };
  126 
  127 /* gen_llvm_types FINI */
  128 
  129 struct swr_context {
  130    struct pipe_context pipe; /**< base class */
  131 
  132    HANDLE swrContext;
  133 
  134    SWR_TS_STATE tsState;
  135 
  136    /** Constant state objects */
  137    struct swr_blend_state *blend;
  138    struct pipe_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
  139    struct pipe_depth_stencil_alpha_state *depth_stencil;
  140    struct pipe_rasterizer_state *rasterizer;
  141 
  142    struct swr_vertex_shader *vs;
  143    struct swr_fragment_shader *fs;
  144    struct swr_geometry_shader *gs;
  145    struct swr_tess_control_shader *tcs;
  146    struct swr_tess_evaluation_shader *tes;
  147    struct swr_vertex_element_state *velems;
  148 
  149    /** Other rendering state */
  150    struct pipe_blend_color blend_color;
  151    struct pipe_stencil_ref stencil_ref;
  152    struct pipe_clip_state clip;
  153    struct pipe_constant_buffer
  154       constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
  155    struct pipe_framebuffer_state framebuffer;
  156    struct swr_poly_stipple poly_stipple;
  157    struct pipe_scissor_state scissors[KNOB_NUM_VIEWPORTS_SCISSORS];
  158    SWR_RECT swr_scissors[KNOB_NUM_VIEWPORTS_SCISSORS];
  159    struct pipe_sampler_view *
  160       sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
  161 
  162    struct pipe_viewport_state viewports[KNOB_NUM_VIEWPORTS_SCISSORS];
  163    struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
  164 
  165    struct blitter_context *blitter;
  166 
  167    /** Conditional query object and mode */
  168    struct pipe_query *render_cond_query;
  169    enum pipe_render_cond_flag render_cond_mode;
  170    bool render_cond_cond;
  171    unsigned active_queries;
  172 
  173    unsigned num_vertex_buffers;
  174    unsigned num_samplers[PIPE_SHADER_TYPES];
  175    unsigned num_sampler_views[PIPE_SHADER_TYPES];
  176 
  177    unsigned sample_mask;
  178 
  179    // streamout
  180    pipe_stream_output_target *so_targets[MAX_SO_STREAMS];
  181    uint32_t num_so_targets;
  182    uint64_t so_primCounter; // number of primitives written to StreamOut buffer
  183 
  184    /* Temp storage for user_buffer constants */
  185    struct swr_scratch_buffers *scratch;
  186 
  187    // blend jit functions
  188    std::unordered_map<BLEND_COMPILE_STATE, PFN_BLEND_JIT_FUNC> *blendJIT;
  189 
  190    /* Derived SWR API DrawState */
  191    struct swr_derived_state derived;
  192 
  193    /* SWR private state - draw context */
  194    struct swr_draw_context swrDC;
  195 
  196    unsigned dirty; /**< Mask of SWR_NEW_x flags */
  197 
  198    SWR_INTERFACE api;
  199    SWR_TILE_INTERFACE tileApi;
  200 
  201    uint32_t max_draws_in_flight;
  202 };
  203 
  204 static INLINE struct swr_context *
  205 swr_context(struct pipe_context *pipe)
  206 {
  207    return (struct swr_context *)pipe;
  208 }
  209 
  210 static INLINE void
  211 swr_update_draw_context(struct swr_context *ctx,
  212       struct swr_query_result *pqr = nullptr)
  213 {
  214    swr_draw_context *pDC =
  215       (swr_draw_context *)ctx->api.pfnSwrGetPrivateContextState(ctx->swrContext);
  216    if (pqr)
  217       ctx->swrDC.pStats = pqr;
  218    memcpy(pDC, &ctx->swrDC, sizeof(swr_draw_context));
  219 }
  220 
  221 struct pipe_context *swr_create_context(struct pipe_screen *, void *priv, unsigned flags);
  222 
  223 void swr_state_init(struct pipe_context *pipe);
  224 
  225 void swr_clear_init(struct pipe_context *pipe);
  226 
  227 void swr_draw_init(struct pipe_context *pipe);
  228 
  229 void swr_finish(struct pipe_context *pipe);
  230 
  231 void swr_do_msaa_resolve(struct pipe_resource *src_resource,
  232                          struct pipe_resource *dst_resource);
  233 #endif