14a49301eSmrg/************************************************************************** 24a49301eSmrg * 3af69d88dSmrg * Copyright 2003 VMware, Inc. 44a49301eSmrg * All Rights Reserved. 54a49301eSmrg * 64a49301eSmrg * Permission is hereby granted, free of charge, to any person obtaining a 74a49301eSmrg * copy of this software and associated documentation files (the 84a49301eSmrg * "Software"), to deal in the Software without restriction, including 94a49301eSmrg * without limitation the rights to use, copy, modify, merge, publish, 104a49301eSmrg * distribute, sub license, and/or sell copies of the Software, and to 114a49301eSmrg * permit persons to whom the Software is furnished to do so, subject to 124a49301eSmrg * the following conditions: 134a49301eSmrg * 144a49301eSmrg * The above copyright notice and this permission notice (including the 154a49301eSmrg * next paragraph) shall be included in all copies or substantial portions 164a49301eSmrg * of the Software. 174a49301eSmrg * 184a49301eSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 194a49301eSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 204a49301eSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21af69d88dSmrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 224a49301eSmrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 234a49301eSmrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 244a49301eSmrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 254a49301eSmrg * 264a49301eSmrg **************************************************************************/ 274a49301eSmrg 284a49301eSmrg#ifndef ST_CONTEXT_H 294a49301eSmrg#define ST_CONTEXT_H 304a49301eSmrg 31b9abf16eSmaya#include "main/arrayobj.h" 324a49301eSmrg#include "main/mtypes.h" 337ec681f3Smrg#include "frontend/api.h" 34af69d88dSmrg#include "main/fbobject.h" 3501e04c3fSmrg#include "state_tracker/st_atom.h" 3601e04c3fSmrg#include "util/u_helpers.h" 3701e04c3fSmrg#include "util/u_inlines.h" 3801e04c3fSmrg#include "util/list.h" 3901e04c3fSmrg#include "vbo/vbo.h" 40b9abf16eSmaya#include "util/list.h" 417ec681f3Smrg#include "cso_cache/cso_context.h" 4201e04c3fSmrg 4301e04c3fSmrg 4401e04c3fSmrg#ifdef __cplusplus 4501e04c3fSmrgextern "C" { 4601e04c3fSmrg#endif 4701e04c3fSmrg 484a49301eSmrg 493464ebd5Sriastradhstruct dd_function_table; 504a49301eSmrgstruct draw_context; 514a49301eSmrgstruct draw_stage; 524a49301eSmrgstruct gen_mipmap_state; 533464ebd5Sriastradhstruct st_context; 547ec681f3Smrgstruct st_program; 5501e04c3fSmrgstruct st_perf_monitor_group; 56af69d88dSmrgstruct u_upload_mgr; 574a49301eSmrg 587ec681f3Smrg#define ST_L3_PINNING_DISABLED 0xffffffff 594a49301eSmrg 6001e04c3fSmrgstruct st_bitmap_cache 6101e04c3fSmrg{ 6201e04c3fSmrg /** Window pos to render the cached image */ 6301e04c3fSmrg GLint xpos, ypos; 6401e04c3fSmrg /** Bounds of region used in window coords */ 6501e04c3fSmrg GLint xmin, ymin, xmax, ymax; 664a49301eSmrg 6701e04c3fSmrg GLfloat color[4]; 6801e04c3fSmrg 6901e04c3fSmrg /** Bitmap's Z position */ 7001e04c3fSmrg GLfloat zpos; 7101e04c3fSmrg 7201e04c3fSmrg struct pipe_resource *texture; 7301e04c3fSmrg struct pipe_transfer *trans; 7401e04c3fSmrg 7501e04c3fSmrg GLboolean empty; 7601e04c3fSmrg 7701e04c3fSmrg /** An I8 texture image: */ 7801e04c3fSmrg ubyte *buffer; 794a49301eSmrg}; 804a49301eSmrg 8101e04c3fSmrgstruct st_bound_handles 8201e04c3fSmrg{ 8301e04c3fSmrg unsigned num_handles; 8401e04c3fSmrg uint64_t *handles; 854a49301eSmrg}; 864a49301eSmrg 874a49301eSmrg 8801e04c3fSmrg#define NUM_DRAWPIX_CACHE_ENTRIES 4 8901e04c3fSmrg 9001e04c3fSmrgstruct drawpix_cache_entry 9101e04c3fSmrg{ 9201e04c3fSmrg GLsizei width, height; 9301e04c3fSmrg GLenum format, type; 9401e04c3fSmrg const void *user_pointer; /**< Last user 'pixels' pointer */ 9501e04c3fSmrg void *image; /**< Copy of the glDrawPixels image data */ 9601e04c3fSmrg struct pipe_resource *texture; 9701e04c3fSmrg unsigned age; 9801e04c3fSmrg}; 9901e04c3fSmrg 1004a49301eSmrg 101b9abf16eSmaya/* 102b9abf16eSmaya * Node for a linked list of dead sampler views. 103b9abf16eSmaya */ 104b9abf16eSmayastruct st_zombie_sampler_view_node 105b9abf16eSmaya{ 106b9abf16eSmaya struct pipe_sampler_view *view; 107b9abf16eSmaya struct list_head node; 108b9abf16eSmaya}; 109b9abf16eSmaya 110b9abf16eSmaya 111b9abf16eSmaya/* 112b9abf16eSmaya * Node for a linked list of dead shaders. 113b9abf16eSmaya */ 114b9abf16eSmayastruct st_zombie_shader_node 115b9abf16eSmaya{ 116b9abf16eSmaya void *shader; 117b9abf16eSmaya enum pipe_shader_type type; 118b9abf16eSmaya struct list_head node; 119b9abf16eSmaya}; 120b9abf16eSmaya 121b9abf16eSmaya 1224a49301eSmrgstruct st_context 1234a49301eSmrg{ 1243464ebd5Sriastradh struct st_context_iface iface; 1253464ebd5Sriastradh 1263464ebd5Sriastradh struct gl_context *ctx; 1277ec681f3Smrg struct pipe_screen *screen; 1284a49301eSmrg struct pipe_context *pipe; 1297ec681f3Smrg struct cso_context *cso_context; 1304a49301eSmrg 1314a49301eSmrg struct draw_context *draw; /**< For selection/feedback/rastpos only */ 1324a49301eSmrg struct draw_stage *feedback_stage; /**< For GL_FEEDBACK rendermode */ 1334a49301eSmrg struct draw_stage *selection_stage; /**< For GL_SELECT rendermode */ 1344a49301eSmrg struct draw_stage *rastpos_stage; /**< For glRasterPos */ 1357ec681f3Smrg 1367ec681f3Smrg unsigned pin_thread_counter; /* for L3 thread pinning on AMD Zen */ 1377ec681f3Smrg 138af69d88dSmrg GLboolean clamp_frag_color_in_shader; 139af69d88dSmrg GLboolean clamp_vert_color_in_shader; 1407ec681f3Smrg boolean clamp_frag_depth_in_shader; 141af69d88dSmrg boolean has_stencil_export; /**< can do shader stencil export? */ 142af69d88dSmrg boolean has_time_elapsed; 143af69d88dSmrg boolean has_etc1; 14401e04c3fSmrg boolean has_etc2; 1457ec681f3Smrg boolean transcode_etc; 1467ec681f3Smrg boolean transcode_astc; 14701e04c3fSmrg boolean has_astc_2d_ldr; 1487ec681f3Smrg boolean has_astc_5x5_ldr; 149af69d88dSmrg boolean prefer_blit_based_texture_transfer; 15001e04c3fSmrg boolean force_persample_in_shader; 15101e04c3fSmrg boolean has_shareable_shaders; 15201e04c3fSmrg boolean has_half_float_packing; 15301e04c3fSmrg boolean has_multi_draw_indirect; 154b9abf16eSmaya boolean has_single_pipe_stat; 155b9abf16eSmaya boolean has_indep_blend_func; 156b9abf16eSmaya boolean needs_rgb_dst_alpha_override; 15701e04c3fSmrg boolean can_bind_const_buffer_as_vertex; 1587ec681f3Smrg boolean lower_flatshade; 1597ec681f3Smrg boolean lower_alpha_test; 1607ec681f3Smrg boolean lower_point_size; 1617ec681f3Smrg boolean lower_two_sided_color; 1627ec681f3Smrg boolean lower_ucp; 1637ec681f3Smrg boolean prefer_real_buffer_in_constbuf0; 1647ec681f3Smrg boolean has_conditional_render; 1657ec681f3Smrg boolean lower_texcoord_replace; 1667ec681f3Smrg boolean lower_rect_tex; 1677ec681f3Smrg 1687ec681f3Smrg /* There are consequences for drivers wanting to call st_finalize_nir 1697ec681f3Smrg * twice, once before shader caching and once after lowering for shader 1707ec681f3Smrg * variants. If shader variants use lowering passes that are not ready 1717ec681f3Smrg * for that, things can blow up. 1727ec681f3Smrg * 1737ec681f3Smrg * If this is true, st_finalize_nir and pipe_screen::finalize_nir will be 1747ec681f3Smrg * called before the result is stored in the shader cache. If lowering for 1757ec681f3Smrg * shader variants is invoked, the functions will be called again. 1767ec681f3Smrg */ 1777ec681f3Smrg boolean allow_st_finalize_nir_twice; 17801e04c3fSmrg 17901e04c3fSmrg /** 18001e04c3fSmrg * If a shader can be created when we get its source. 18101e04c3fSmrg * This means it has only 1 variant, not counting glBitmap and 18201e04c3fSmrg * glDrawPixels. 18301e04c3fSmrg */ 18401e04c3fSmrg boolean shader_has_one_variant[MESA_SHADER_STAGES]; 1854a49301eSmrg 186af69d88dSmrg boolean needs_texcoord_semantic; 187af69d88dSmrg boolean apply_texture_swizzle_to_border_color; 1887ec681f3Smrg boolean emulate_gl_clamp; 1897ec681f3Smrg boolean texture_buffer_sampler; 1903464ebd5Sriastradh 1913464ebd5Sriastradh /* On old libGL's for linux we need to invalidate the drawables 1923464ebd5Sriastradh * on glViewpport calls, this is set via a option. 1933464ebd5Sriastradh */ 1943464ebd5Sriastradh boolean invalidate_on_gl_viewport; 19501e04c3fSmrg boolean draw_needs_minmax_index; 19601e04c3fSmrg boolean has_hw_atomics; 197af69d88dSmrg 1987ec681f3Smrg 1997ec681f3Smrg /* driver supports scissored clears */ 2007ec681f3Smrg boolean can_scissor_clear; 2017ec681f3Smrg 2024a49301eSmrg /* Some state is contained in constant objects. 2034a49301eSmrg * Other state is just parameter values. 2044a49301eSmrg */ 2054a49301eSmrg struct { 2064a49301eSmrg struct pipe_blend_state blend; 2074a49301eSmrg struct pipe_depth_stencil_alpha_state depth_stencil; 2084a49301eSmrg struct pipe_rasterizer_state rasterizer; 2097ec681f3Smrg struct pipe_sampler_state vert_samplers[PIPE_MAX_SAMPLERS]; 21001e04c3fSmrg struct pipe_sampler_state frag_samplers[PIPE_MAX_SAMPLERS]; 2117ec681f3Smrg GLuint num_vert_samplers; 21201e04c3fSmrg GLuint num_frag_samplers; 213af69d88dSmrg GLuint num_sampler_views[PIPE_SHADER_TYPES]; 2147ec681f3Smrg unsigned num_images[PIPE_SHADER_TYPES]; 2154a49301eSmrg struct pipe_clip_state clip; 2167ec681f3Smrg unsigned constbuf0_enabled_shader_mask; 21701e04c3fSmrg unsigned fb_width; 21801e04c3fSmrg unsigned fb_height; 21901e04c3fSmrg unsigned fb_num_samples; 22001e04c3fSmrg unsigned fb_num_layers; 22101e04c3fSmrg unsigned fb_num_cb; 22201e04c3fSmrg unsigned num_viewports; 223af69d88dSmrg struct pipe_scissor_state scissor[PIPE_MAX_VIEWPORTS]; 224af69d88dSmrg struct pipe_viewport_state viewport[PIPE_MAX_VIEWPORTS]; 22501e04c3fSmrg struct { 22601e04c3fSmrg unsigned num; 22701e04c3fSmrg boolean include; 22801e04c3fSmrg struct pipe_scissor_state rects[PIPE_MAX_WINDOW_RECTANGLES]; 22901e04c3fSmrg } window_rects; 2304a49301eSmrg 2314a49301eSmrg GLuint poly_stipple[32]; /**< In OpenGL's bottom-to-top order */ 232af69d88dSmrg 233af69d88dSmrg GLuint fb_orientation; 23401e04c3fSmrg 23501e04c3fSmrg bool enable_sample_locations; 23601e04c3fSmrg unsigned sample_locations_samples; 23701e04c3fSmrg uint8_t sample_locations[ 23801e04c3fSmrg PIPE_MAX_SAMPLE_LOCATION_GRID_SIZE * 23901e04c3fSmrg PIPE_MAX_SAMPLE_LOCATION_GRID_SIZE * 32]; 2404a49301eSmrg } state; 2414a49301eSmrg 24201e04c3fSmrg uint64_t dirty; /**< dirty states */ 24301e04c3fSmrg 24401e04c3fSmrg /** This masks out unused shader resources. Only valid in draw calls. */ 24501e04c3fSmrg uint64_t active_states; 2464a49301eSmrg 24701e04c3fSmrg /* If true, further analysis of states is required to know if something 24801e04c3fSmrg * has changed. Used mainly for shaders. 24901e04c3fSmrg */ 25001e04c3fSmrg bool gfx_shaders_may_be_dirty; 25101e04c3fSmrg bool compute_shader_may_be_dirty; 2524a49301eSmrg 253cdc920a0Smrg GLboolean vertdata_edgeflags; 254af69d88dSmrg GLboolean edgeflag_culls_prims; 2554a49301eSmrg 2567ec681f3Smrg /** 2577ec681f3Smrg * The number of currently active queries (excluding timer queries). 2587ec681f3Smrg * This is used to know if we need to pause any queries for meta ops. 2597ec681f3Smrg */ 2607ec681f3Smrg unsigned active_queries; 2614a49301eSmrg 2627ec681f3Smrg union { 2637ec681f3Smrg struct { 2647ec681f3Smrg struct st_program *vp; /**< Currently bound vertex program */ 2657ec681f3Smrg struct st_program *tcp; /**< Currently bound tess control program */ 2667ec681f3Smrg struct st_program *tep; /**< Currently bound tess eval program */ 2677ec681f3Smrg struct st_program *gp; /**< Currently bound geometry program */ 2687ec681f3Smrg struct st_program *fp; /**< Currently bound fragment program */ 2697ec681f3Smrg struct st_program *cp; /**< Currently bound compute program */ 2707ec681f3Smrg }; 2717ec681f3Smrg struct gl_program *current_program[MESA_SHADER_STAGES]; 2727ec681f3Smrg }; 2737ec681f3Smrg 2747ec681f3Smrg struct st_common_variant *vp_variant; 2754a49301eSmrg 2764a49301eSmrg struct { 2773464ebd5Sriastradh struct pipe_resource *pixelmap_texture; 2783464ebd5Sriastradh struct pipe_sampler_view *pixelmap_sampler_view; 2794a49301eSmrg } pixel_xfer; 2804a49301eSmrg 2814a49301eSmrg /** for glBitmap */ 2824a49301eSmrg struct { 2834a49301eSmrg struct pipe_rasterizer_state rasterizer; 28401e04c3fSmrg struct pipe_sampler_state sampler; 28501e04c3fSmrg struct pipe_sampler_state atlas_sampler; 2864a49301eSmrg enum pipe_format tex_format; 28701e04c3fSmrg struct st_bitmap_cache cache; 2884a49301eSmrg } bitmap; 2894a49301eSmrg 2904a49301eSmrg /** for glDraw/CopyPixels */ 2914a49301eSmrg struct { 2927ec681f3Smrg void *zs_shaders[6]; 2934a49301eSmrg } drawpix; 2944a49301eSmrg 29501e04c3fSmrg /** Cache of glDrawPixels images */ 29601e04c3fSmrg struct { 29701e04c3fSmrg struct drawpix_cache_entry entries[NUM_DRAWPIX_CACHE_ENTRIES]; 29801e04c3fSmrg unsigned age; 29901e04c3fSmrg } drawpix_cache; 30001e04c3fSmrg 30101e04c3fSmrg /** for glReadPixels */ 30201e04c3fSmrg struct { 30301e04c3fSmrg struct pipe_resource *src; 30401e04c3fSmrg struct pipe_resource *cache; 30501e04c3fSmrg enum pipe_format dst_format; 30601e04c3fSmrg unsigned level; 30701e04c3fSmrg unsigned layer; 30801e04c3fSmrg unsigned hits; 30901e04c3fSmrg } readpix_cache; 31001e04c3fSmrg 3114a49301eSmrg /** for glClear */ 3124a49301eSmrg struct { 3134a49301eSmrg struct pipe_rasterizer_state raster; 3144a49301eSmrg struct pipe_viewport_state viewport; 3154a49301eSmrg void *vs; 3164a49301eSmrg void *fs; 317af69d88dSmrg void *vs_layered; 318af69d88dSmrg void *gs_layered; 3194a49301eSmrg } clear; 3204a49301eSmrg 32101e04c3fSmrg /* For gl(Compressed)Tex(Sub)Image */ 32201e04c3fSmrg struct { 32301e04c3fSmrg struct pipe_rasterizer_state raster; 32401e04c3fSmrg struct pipe_blend_state upload_blend; 32501e04c3fSmrg void *vs; 32601e04c3fSmrg void *gs; 3277ec681f3Smrg void *upload_fs[5][2]; 3287ec681f3Smrg void *download_fs[5][PIPE_MAX_TEXTURE_TYPES][2]; 32901e04c3fSmrg bool upload_enabled; 33001e04c3fSmrg bool download_enabled; 33101e04c3fSmrg bool rgba_only; 33201e04c3fSmrg bool layers; 33301e04c3fSmrg bool use_gs; 33401e04c3fSmrg } pbo; 33501e04c3fSmrg 33601e04c3fSmrg /** for drawing with st_util_vertex */ 3377ec681f3Smrg struct cso_velems_state util_velems; 3383464ebd5Sriastradh 339b9abf16eSmaya /** passthrough vertex shader matching the util_velem attributes */ 340b9abf16eSmaya void *passthrough_vs; 3414a49301eSmrg 3423464ebd5Sriastradh enum pipe_texture_target internal_target; 3434a49301eSmrg 3443464ebd5Sriastradh void *winsys_drawable_handle; 3453464ebd5Sriastradh 346af69d88dSmrg /* The number of vertex buffers from the last call of validate_arrays. */ 347af69d88dSmrg unsigned last_num_vbuffers; 3483464ebd5Sriastradh 3497ec681f3Smrg unsigned last_used_atomic_bindings[PIPE_SHADER_TYPES]; 3507ec681f3Smrg unsigned last_num_ssbos[PIPE_SHADER_TYPES]; 3517ec681f3Smrg 352af69d88dSmrg int32_t draw_stamp; 353af69d88dSmrg int32_t read_stamp; 3543464ebd5Sriastradh 355af69d88dSmrg struct st_config_options options; 35601e04c3fSmrg 35701e04c3fSmrg struct st_perf_monitor_group *perfmon; 35801e04c3fSmrg 35901e04c3fSmrg enum pipe_reset_status reset_status; 36001e04c3fSmrg 36101e04c3fSmrg /* Array of bound texture/image handles which are resident in the context. 36201e04c3fSmrg */ 36301e04c3fSmrg struct st_bound_handles bound_texture_handles[PIPE_SHADER_TYPES]; 36401e04c3fSmrg struct st_bound_handles bound_image_handles[PIPE_SHADER_TYPES]; 36501e04c3fSmrg 36601e04c3fSmrg /* Winsys buffers */ 36701e04c3fSmrg struct list_head winsys_buffers; 36801e04c3fSmrg 36901e04c3fSmrg /* Throttling for texture uploads and similar operations to limit memory 37001e04c3fSmrg * usage by limiting the number of in-flight operations based on 37101e04c3fSmrg * the estimated allocated size needed to execute those operations. 37201e04c3fSmrg */ 37301e04c3fSmrg struct util_throttle throttle; 374b9abf16eSmaya 375b9abf16eSmaya struct { 376b9abf16eSmaya struct st_zombie_sampler_view_node list; 3777ec681f3Smrg simple_mtx_t mutex; 378b9abf16eSmaya } zombie_sampler_views; 379b9abf16eSmaya 380b9abf16eSmaya struct { 381b9abf16eSmaya struct st_zombie_shader_node list; 3827ec681f3Smrg simple_mtx_t mutex; 383b9abf16eSmaya } zombie_shaders; 3844a49301eSmrg}; 3854a49301eSmrg 3864a49301eSmrg 387b9abf16eSmaya/* 388b9abf16eSmaya * Get the state tracker context for the given Mesa context. 3894a49301eSmrg */ 390b9abf16eSmayastatic inline struct st_context * 391b9abf16eSmayast_context(struct gl_context *ctx) 3924a49301eSmrg{ 3934a49301eSmrg return ctx->st; 3944a49301eSmrg} 3954a49301eSmrg 3964a49301eSmrg 397b9abf16eSmayaextern struct st_context * 398b9abf16eSmayast_create_context(gl_api api, struct pipe_context *pipe, 399b9abf16eSmaya const struct gl_config *visual, 400b9abf16eSmaya struct st_context *share, 401b9abf16eSmaya const struct st_config_options *options, 4027ec681f3Smrg bool no_error, bool has_egl_image_validate); 403b9abf16eSmaya 404b9abf16eSmayaextern void 405b9abf16eSmayast_destroy_context(struct st_context *st); 406b9abf16eSmaya 407b9abf16eSmaya 408b9abf16eSmayaextern void 409b9abf16eSmayast_invalidate_buffers(struct st_context *st); 410b9abf16eSmaya 411b9abf16eSmaya 412b9abf16eSmayaextern void 413b9abf16eSmayast_save_zombie_sampler_view(struct st_context *st, 414b9abf16eSmaya struct pipe_sampler_view *view); 415b9abf16eSmaya 416b9abf16eSmayaextern void 417b9abf16eSmayast_save_zombie_shader(struct st_context *st, 418b9abf16eSmaya enum pipe_shader_type type, 419b9abf16eSmaya struct pipe_shader_state *shader); 420b9abf16eSmaya 421b9abf16eSmaya 422b9abf16eSmayavoid 423b9abf16eSmayast_context_free_zombie_objects(struct st_context *st); 424b9abf16eSmaya 4257ec681f3Smrgconst struct nir_shader_compiler_options * 4267ec681f3Smrgst_get_nir_compiler_options(struct st_context *st, gl_shader_stage stage); 427b9abf16eSmaya 428b9abf16eSmaya 4294a49301eSmrg/** 4303464ebd5Sriastradh * Wrapper for struct gl_framebuffer. 4314a49301eSmrg * This is an opaque type to the outside world. 4324a49301eSmrg */ 4334a49301eSmrgstruct st_framebuffer 4344a49301eSmrg{ 4353464ebd5Sriastradh struct gl_framebuffer Base; 4363464ebd5Sriastradh 4373464ebd5Sriastradh struct st_framebuffer_iface *iface; 4383464ebd5Sriastradh enum st_attachment_type statts[ST_ATTACHMENT_COUNT]; 4393464ebd5Sriastradh unsigned num_statts; 440af69d88dSmrg int32_t stamp; 441af69d88dSmrg int32_t iface_stamp; 44201e04c3fSmrg uint32_t iface_ID; 44301e04c3fSmrg 44401e04c3fSmrg /* list of framebuffer objects */ 44501e04c3fSmrg struct list_head head; 4464a49301eSmrg}; 4474a49301eSmrg 4484a49301eSmrg 44901e04c3fSmrg#ifdef __cplusplus 45001e04c3fSmrg} 45101e04c3fSmrg#endif 4524a49301eSmrg 4534a49301eSmrg#endif 454