st/mesa: move utility functions, macros into new st_util.h file
To de-clutter st_context.h. Clean up remaining function prototypes in st_context.h. The st_vp_uses_current_values() helper is only used in st_context.c so move it there. The st_get_active_states() function is only used in st_context.c so remove its prototype in st_context.h Reviewed-by: Neha Bhende <bhenden@vmware.com>
This commit is contained in:
@@ -556,6 +556,7 @@ STATETRACKER_FILES = \
|
||||
state_tracker/st_texture.h \
|
||||
state_tracker/st_tgsi_lower_yuv.c \
|
||||
state_tracker/st_tgsi_lower_yuv.h \
|
||||
state_tracker/st_util.h \
|
||||
state_tracker/st_vdpau.c \
|
||||
state_tracker/st_vdpau.h
|
||||
|
||||
|
@@ -600,6 +600,7 @@ files_libmesa_gallium = files(
|
||||
'state_tracker/st_texture.h',
|
||||
'state_tracker/st_tgsi_lower_yuv.c',
|
||||
'state_tracker/st_tgsi_lower_yuv.h',
|
||||
'state_tracker/st_util.h',
|
||||
'state_tracker/st_vdpau.c',
|
||||
'state_tracker/st_vdpau.h',
|
||||
)
|
||||
|
@@ -36,6 +36,8 @@
|
||||
#include "st_atom.h"
|
||||
#include "st_program.h"
|
||||
#include "st_manager.h"
|
||||
#include "st_util.h"
|
||||
|
||||
|
||||
typedef void (*update_func_t)(struct st_context *st);
|
||||
|
||||
|
@@ -38,6 +38,7 @@
|
||||
#include "st_cb_bitmap.h"
|
||||
#include "st_cb_fbo.h"
|
||||
#include "st_texture.h"
|
||||
#include "st_util.h"
|
||||
#include "pipe/p_context.h"
|
||||
#include "cso_cache/cso_context.h"
|
||||
#include "util/u_math.h"
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#include "pipe/p_context.h"
|
||||
#include "st_atom.h"
|
||||
#include "st_program.h"
|
||||
#include "st_util.h"
|
||||
|
||||
#include "cso_cache/cso_context.h"
|
||||
#include "util/u_framebuffer.h"
|
||||
|
@@ -37,6 +37,7 @@
|
||||
#include "st_atom.h"
|
||||
#include "st_debug.h"
|
||||
#include "st_program.h"
|
||||
#include "st_util.h"
|
||||
#include "pipe/p_context.h"
|
||||
#include "pipe/p_defines.h"
|
||||
#include "cso_cache/cso_context.h"
|
||||
|
@@ -36,6 +36,7 @@
|
||||
#include "st_context.h"
|
||||
#include "pipe/p_context.h"
|
||||
#include "st_atom.h"
|
||||
#include "st_util.h"
|
||||
|
||||
|
||||
/**
|
||||
|
@@ -30,6 +30,7 @@
|
||||
#include "main/viewport.h"
|
||||
#include "st_context.h"
|
||||
#include "st_atom.h"
|
||||
#include "st_util.h"
|
||||
#include "pipe/p_context.h"
|
||||
#include "cso_cache/cso_context.h"
|
||||
|
||||
|
@@ -49,6 +49,7 @@
|
||||
#include "st_cb_drawpixels.h"
|
||||
#include "st_sampler_view.h"
|
||||
#include "st_texture.h"
|
||||
#include "st_util.h"
|
||||
|
||||
#include "pipe/p_context.h"
|
||||
#include "pipe/p_defines.h"
|
||||
|
@@ -41,6 +41,7 @@
|
||||
#include "st_cb_fbo.h"
|
||||
#include "st_manager.h"
|
||||
#include "st_scissor.h"
|
||||
#include "st_util.h"
|
||||
|
||||
#include "util/u_format.h"
|
||||
|
||||
|
@@ -43,6 +43,7 @@
|
||||
#include "st_cb_bufferobjects.h"
|
||||
#include "st_cb_memoryobjects.h"
|
||||
#include "st_debug.h"
|
||||
#include "st_util.h"
|
||||
|
||||
#include "pipe/p_context.h"
|
||||
#include "pipe/p_defines.h"
|
||||
|
@@ -50,6 +50,7 @@
|
||||
#include "st_format.h"
|
||||
#include "st_nir.h"
|
||||
#include "st_program.h"
|
||||
#include "st_util.h"
|
||||
|
||||
#include "pipe/p_context.h"
|
||||
#include "pipe/p_shader_tokens.h"
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#include "st_cb_bitmap.h"
|
||||
#include "st_cb_bufferobjects.h"
|
||||
#include "st_cb_compute.h"
|
||||
#include "st_util.h"
|
||||
|
||||
#include "pipe/p_context.h"
|
||||
|
||||
|
@@ -27,6 +27,7 @@
|
||||
#include "state_tracker/st_cb_copyimage.h"
|
||||
#include "state_tracker/st_cb_fbo.h"
|
||||
#include "state_tracker/st_texture.h"
|
||||
#include "state_tracker/st_util.h"
|
||||
|
||||
#include "util/u_box.h"
|
||||
#include "util/u_format.h"
|
||||
|
@@ -65,6 +65,7 @@
|
||||
#include "st_sampler_view.h"
|
||||
#include "st_scissor.h"
|
||||
#include "st_texture.h"
|
||||
#include "st_util.h"
|
||||
#include "st_nir.h"
|
||||
|
||||
#include "pipe/p_context.h"
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#include "st_cb_bitmap.h"
|
||||
#include "st_cb_drawtex.h"
|
||||
#include "st_nir.h"
|
||||
#include "st_util.h"
|
||||
|
||||
#include "pipe/p_context.h"
|
||||
#include "pipe/p_defines.h"
|
||||
|
@@ -53,6 +53,7 @@
|
||||
#include "st_cb_texture.h"
|
||||
#include "st_format.h"
|
||||
#include "st_texture.h"
|
||||
#include "st_util.h"
|
||||
#include "st_manager.h"
|
||||
|
||||
#include "util/u_format.h"
|
||||
|
@@ -48,6 +48,7 @@
|
||||
#include "st_draw.h"
|
||||
#include "st_cb_feedback.h"
|
||||
#include "st_program.h"
|
||||
#include "st_util.h"
|
||||
|
||||
#include "pipe/p_context.h"
|
||||
#include "pipe/p_defines.h"
|
||||
|
@@ -29,6 +29,7 @@
|
||||
|
||||
#include "st_context.h"
|
||||
#include "st_cb_memoryobjects.h"
|
||||
#include "st_util.h"
|
||||
|
||||
#include "state_tracker/drm_driver.h"
|
||||
#include "pipe/p_context.h"
|
||||
|
@@ -29,6 +29,7 @@
|
||||
#include "st_context.h"
|
||||
#include "st_cb_bitmap.h"
|
||||
#include "st_cb_perfmon.h"
|
||||
#include "st_util.h"
|
||||
|
||||
#include "util/bitset.h"
|
||||
|
||||
|
@@ -47,6 +47,7 @@
|
||||
#include "st_cb_program.h"
|
||||
#include "st_glsl_to_ir.h"
|
||||
#include "st_atifs_to_tgsi.h"
|
||||
#include "st_util.h"
|
||||
|
||||
|
||||
/**
|
||||
|
@@ -45,6 +45,7 @@
|
||||
#include "st_cb_queryobj.h"
|
||||
#include "st_cb_bitmap.h"
|
||||
#include "st_cb_bufferobjects.h"
|
||||
#include "st_util.h"
|
||||
|
||||
|
||||
static struct gl_query_object *
|
||||
|
@@ -49,6 +49,7 @@
|
||||
#include "st_draw.h"
|
||||
#include "st_program.h"
|
||||
#include "st_cb_rasterpos.h"
|
||||
#include "st_util.h"
|
||||
#include "draw/draw_context.h"
|
||||
#include "draw/draw_pipe.h"
|
||||
#include "vbo/vbo.h"
|
||||
|
@@ -46,6 +46,8 @@
|
||||
#include "state_tracker/st_format.h"
|
||||
#include "state_tracker/st_pbo.h"
|
||||
#include "state_tracker/st_texture.h"
|
||||
#include "state_tracker/st_util.h"
|
||||
|
||||
|
||||
/* The readpixels cache caches a blitted staging texture so that back-to-back
|
||||
* calls to glReadPixels with user pointers require less CPU-GPU synchronization.
|
||||
|
@@ -29,6 +29,7 @@
|
||||
|
||||
#include "st_context.h"
|
||||
#include "st_texture.h"
|
||||
#include "st_util.h"
|
||||
#include "st_cb_bitmap.h"
|
||||
#include "st_cb_bufferobjects.h"
|
||||
#include "st_cb_semaphoreobjects.h"
|
||||
|
@@ -62,6 +62,7 @@
|
||||
#include "state_tracker/st_gen_mipmap.h"
|
||||
#include "state_tracker/st_atom.h"
|
||||
#include "state_tracker/st_sampler_view.h"
|
||||
#include "state_tracker/st_util.h"
|
||||
|
||||
#include "pipe/p_context.h"
|
||||
#include "pipe/p_defines.h"
|
||||
|
@@ -78,6 +78,7 @@
|
||||
#include "st_shader_cache.h"
|
||||
#include "st_vdpau.h"
|
||||
#include "st_texture.h"
|
||||
#include "st_util.h"
|
||||
#include "pipe/p_context.h"
|
||||
#include "util/u_cpu_detect.h"
|
||||
#include "util/u_inlines.h"
|
||||
@@ -132,7 +133,7 @@ st_query_memory_info(struct gl_context *ctx, struct gl_memory_info *out)
|
||||
}
|
||||
|
||||
|
||||
uint64_t
|
||||
static uint64_t
|
||||
st_get_active_states(struct gl_context *ctx)
|
||||
{
|
||||
struct st_vertex_program *vp =
|
||||
@@ -184,6 +185,14 @@ st_invalidate_buffers(struct st_context *st)
|
||||
}
|
||||
|
||||
|
||||
static inline bool
|
||||
st_vp_uses_current_values(const struct gl_context *ctx)
|
||||
{
|
||||
const uint64_t inputs = ctx->VertexProgram._Current->info.inputs_read;
|
||||
return _mesa_draw_current_bits(ctx) & inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called via ctx->Driver.UpdateState()
|
||||
*/
|
||||
|
@@ -54,14 +54,6 @@ struct st_perf_monitor_group;
|
||||
struct u_upload_mgr;
|
||||
|
||||
|
||||
/** For drawing quads for glClear, glDraw/CopyPixels, glBitmap, etc. */
|
||||
struct st_util_vertex
|
||||
{
|
||||
float x, y, z;
|
||||
float r, g, b, a;
|
||||
float s, t;
|
||||
};
|
||||
|
||||
struct st_bitmap_cache
|
||||
{
|
||||
/** Window pos to render the cached image */
|
||||
@@ -317,14 +309,40 @@ struct st_context
|
||||
};
|
||||
|
||||
|
||||
/* Need this so that we can implement Mesa callbacks in this module.
|
||||
/*
|
||||
* Get the state tracker context for the given Mesa context.
|
||||
*/
|
||||
static inline struct st_context *st_context(struct gl_context *ctx)
|
||||
static inline struct st_context *
|
||||
st_context(struct gl_context *ctx)
|
||||
{
|
||||
return ctx->st;
|
||||
}
|
||||
|
||||
|
||||
extern struct st_context *
|
||||
st_create_context(gl_api api, struct pipe_context *pipe,
|
||||
const struct gl_config *visual,
|
||||
struct st_context *share,
|
||||
const struct st_config_options *options,
|
||||
bool no_error);
|
||||
|
||||
extern void
|
||||
st_destroy_context(struct st_context *st);
|
||||
|
||||
|
||||
extern void
|
||||
st_init_driver_functions(struct pipe_screen *screen,
|
||||
struct dd_function_table *functions);
|
||||
|
||||
|
||||
extern void
|
||||
st_invalidate_buffers(struct st_context *st);
|
||||
|
||||
|
||||
extern uint64_t
|
||||
st_get_active_states(struct gl_context *ctx);
|
||||
|
||||
|
||||
/**
|
||||
* Wrapper for struct gl_framebuffer.
|
||||
* This is an opaque type to the outside world.
|
||||
@@ -345,86 +363,6 @@ struct st_framebuffer
|
||||
};
|
||||
|
||||
|
||||
extern void st_init_driver_functions(struct pipe_screen *screen,
|
||||
struct dd_function_table *functions);
|
||||
|
||||
void
|
||||
st_invalidate_buffers(struct st_context *st);
|
||||
|
||||
/* Invalidate the readpixels cache to ensure we don't read stale data.
|
||||
*/
|
||||
static inline void
|
||||
st_invalidate_readpix_cache(struct st_context *st)
|
||||
{
|
||||
if (unlikely(st->readpix_cache.src)) {
|
||||
pipe_resource_reference(&st->readpix_cache.src, NULL);
|
||||
pipe_resource_reference(&st->readpix_cache.cache, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define Y_0_TOP 1
|
||||
#define Y_0_BOTTOM 2
|
||||
|
||||
static inline GLuint
|
||||
st_fb_orientation(const struct gl_framebuffer *fb)
|
||||
{
|
||||
if (fb && _mesa_is_winsys_fbo(fb)) {
|
||||
/* Drawing into a window (on-screen buffer).
|
||||
*
|
||||
* Negate Y scale to flip image vertically.
|
||||
* The NDC Y coords prior to viewport transformation are in the range
|
||||
* [y=-1=bottom, y=1=top]
|
||||
* Hardware window coords are in the range [y=0=top, y=H-1=bottom] where
|
||||
* H is the window height.
|
||||
* Use the viewport transformation to invert Y.
|
||||
*/
|
||||
return Y_0_TOP;
|
||||
}
|
||||
else {
|
||||
/* Drawing into user-created FBO (very likely a texture).
|
||||
*
|
||||
* For textures, T=0=Bottom, so by extension Y=0=Bottom for rendering.
|
||||
*/
|
||||
return Y_0_BOTTOM;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static inline bool
|
||||
st_user_clip_planes_enabled(struct gl_context *ctx)
|
||||
{
|
||||
return (ctx->API == API_OPENGL_COMPAT ||
|
||||
ctx->API == API_OPENGLES) && /* only ES 1.x */
|
||||
ctx->Transform.ClipPlanesEnabled;
|
||||
}
|
||||
|
||||
|
||||
static inline bool
|
||||
st_vp_uses_current_values(const struct gl_context *ctx)
|
||||
{
|
||||
const uint64_t inputs = ctx->VertexProgram._Current->info.inputs_read;
|
||||
return _mesa_draw_current_bits(ctx) & inputs;
|
||||
}
|
||||
|
||||
/** clear-alloc a struct-sized object, with casting */
|
||||
#define ST_CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T))
|
||||
|
||||
|
||||
extern struct st_context *
|
||||
st_create_context(gl_api api, struct pipe_context *pipe,
|
||||
const struct gl_config *visual,
|
||||
struct st_context *share,
|
||||
const struct st_config_options *options,
|
||||
bool no_error);
|
||||
|
||||
extern void
|
||||
st_destroy_context(struct st_context *st);
|
||||
|
||||
uint64_t
|
||||
st_get_active_states(struct gl_context *ctx);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -55,6 +55,7 @@
|
||||
#include "st_debug.h"
|
||||
#include "st_draw.h"
|
||||
#include "st_program.h"
|
||||
#include "st_util.h"
|
||||
|
||||
#include "pipe/p_context.h"
|
||||
#include "pipe/p_defines.h"
|
||||
|
@@ -39,6 +39,7 @@
|
||||
#include "st_cb_bufferobjects.h"
|
||||
#include "st_draw.h"
|
||||
#include "st_program.h"
|
||||
#include "st_util.h"
|
||||
|
||||
#include "pipe/p_context.h"
|
||||
#include "pipe/p_defines.h"
|
||||
|
@@ -40,6 +40,7 @@
|
||||
#include "st_debug.h"
|
||||
#include "st_context.h"
|
||||
#include "st_texture.h"
|
||||
#include "st_util.h"
|
||||
#include "st_gen_mipmap.h"
|
||||
#include "st_cb_bitmap.h"
|
||||
#include "st_cb_texture.h"
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#include "st_debug.h"
|
||||
#include "st_program.h"
|
||||
#include "st_shader_cache.h"
|
||||
#include "st_util.h"
|
||||
#include "compiler/glsl/program.h"
|
||||
#include "compiler/nir/nir.h"
|
||||
#include "compiler/nir/nir_serialize.h"
|
||||
|
114
src/mesa/state_tracker/st_util.h
Normal file
114
src/mesa/state_tracker/st_util.h
Normal file
@@ -0,0 +1,114 @@
|
||||
/**************************************************************************
|
||||
*
|
||||
* Copyright 2019 VMware, Inc.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sub license, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the
|
||||
* next paragraph) shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
|
||||
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/*
|
||||
* Miscellantous state tracker utility functions, macros.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ST_UTIL
|
||||
#define ST_UTIL
|
||||
|
||||
|
||||
#include "state_tracker/st_context.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/** For drawing quads for glClear, glDraw/CopyPixels, glBitmap, etc. */
|
||||
struct st_util_vertex
|
||||
{
|
||||
float x, y, z;
|
||||
float r, g, b, a;
|
||||
float s, t;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* Invalidate the readpixels cache to ensure we don't read stale data.
|
||||
*/
|
||||
static inline void
|
||||
st_invalidate_readpix_cache(struct st_context *st)
|
||||
{
|
||||
if (unlikely(st->readpix_cache.src)) {
|
||||
pipe_resource_reference(&st->readpix_cache.src, NULL);
|
||||
pipe_resource_reference(&st->readpix_cache.cache, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define Y_0_TOP 1
|
||||
#define Y_0_BOTTOM 2
|
||||
|
||||
static inline GLuint
|
||||
st_fb_orientation(const struct gl_framebuffer *fb)
|
||||
{
|
||||
if (fb && _mesa_is_winsys_fbo(fb)) {
|
||||
/* Drawing into a window (on-screen buffer).
|
||||
*
|
||||
* Negate Y scale to flip image vertically.
|
||||
* The NDC Y coords prior to viewport transformation are in the range
|
||||
* [y=-1=bottom, y=1=top]
|
||||
* Hardware window coords are in the range [y=0=top, y=H-1=bottom] where
|
||||
* H is the window height.
|
||||
* Use the viewport transformation to invert Y.
|
||||
*/
|
||||
return Y_0_TOP;
|
||||
}
|
||||
else {
|
||||
/* Drawing into user-created FBO (very likely a texture).
|
||||
*
|
||||
* For textures, T=0=Bottom, so by extension Y=0=Bottom for rendering.
|
||||
*/
|
||||
return Y_0_BOTTOM;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static inline bool
|
||||
st_user_clip_planes_enabled(struct gl_context *ctx)
|
||||
{
|
||||
return (ctx->API == API_OPENGL_COMPAT ||
|
||||
ctx->API == API_OPENGLES) && /* only ES 1.x */
|
||||
ctx->Transform.ClipPlanesEnabled;
|
||||
}
|
||||
|
||||
|
||||
/** clear-alloc a struct-sized object, with casting */
|
||||
#define ST_CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T))
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* ST_UTIL */
|
Reference in New Issue
Block a user