2007-08-02 13:59:31 +01:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
s/Tungsten Graphics/VMware/
Tungsten Graphics Inc. was acquired by VMware Inc. in 2008. Leaving the
old copyright name is creating unnecessary confusion, hence this change.
This was the sed script I used:
$ cat tg2vmw.sed
# Run as:
#
# git reset --hard HEAD && find include scons src -type f -not -name 'sed*' -print0 | xargs -0 sed -i -f tg2vmw.sed
#
# Rename copyrights
s/Tungsten Gra\(ph\|hp\)ics,\? [iI]nc\.\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./g
/Copyright/s/Tungsten Graphics\(,\? [iI]nc\.\)\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./
s/TUNGSTEN GRAPHICS/VMWARE/g
# Rename emails
s/alanh@tungstengraphics.com/alanh@vmware.com/
s/jens@tungstengraphics.com/jowen@vmware.com/g
s/jrfonseca-at-tungstengraphics-dot-com/jfonseca-at-vmware-dot-com/
s/jrfonseca\?@tungstengraphics.com/jfonseca@vmware.com/g
s/keithw\?@tungstengraphics.com/keithw@vmware.com/g
s/michel@tungstengraphics.com/daenzer@vmware.com/g
s/thomas-at-tungstengraphics-dot-com/thellstom-at-vmware-dot-com/
s/zack@tungstengraphics.com/zackr@vmware.com/
# Remove dead links
s@Tungsten Graphics (http://www.tungstengraphics.com)@Tungsten Graphics@g
# C string src/gallium/state_trackers/vega/api_misc.c
s/"Tungsten Graphics, Inc"/"VMware, Inc"/
Reviewed-by: Brian Paul <brianp@vmware.com>
2014-01-17 16:27:50 +00:00
|
|
|
* Copyright 2007 VMware, Inc.
|
2007-08-02 13:59:31 +01:00
|
|
|
* All Rights Reserved.
|
2009-04-04 19:01:51 +02:00
|
|
|
* Copyright 2009 VMware, Inc. All Rights Reserved.
|
2007-08-02 13:59:31 +01:00
|
|
|
*
|
|
|
|
* 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.
|
s/Tungsten Graphics/VMware/
Tungsten Graphics Inc. was acquired by VMware Inc. in 2008. Leaving the
old copyright name is creating unnecessary confusion, hence this change.
This was the sed script I used:
$ cat tg2vmw.sed
# Run as:
#
# git reset --hard HEAD && find include scons src -type f -not -name 'sed*' -print0 | xargs -0 sed -i -f tg2vmw.sed
#
# Rename copyrights
s/Tungsten Gra\(ph\|hp\)ics,\? [iI]nc\.\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./g
/Copyright/s/Tungsten Graphics\(,\? [iI]nc\.\)\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./
s/TUNGSTEN GRAPHICS/VMWARE/g
# Rename emails
s/alanh@tungstengraphics.com/alanh@vmware.com/
s/jens@tungstengraphics.com/jowen@vmware.com/g
s/jrfonseca-at-tungstengraphics-dot-com/jfonseca-at-vmware-dot-com/
s/jrfonseca\?@tungstengraphics.com/jfonseca@vmware.com/g
s/keithw\?@tungstengraphics.com/keithw@vmware.com/g
s/michel@tungstengraphics.com/daenzer@vmware.com/g
s/thomas-at-tungstengraphics-dot-com/thellstom-at-vmware-dot-com/
s/zack@tungstengraphics.com/zackr@vmware.com/
# Remove dead links
s@Tungsten Graphics (http://www.tungstengraphics.com)@Tungsten Graphics@g
# C string src/gallium/state_trackers/vega/api_misc.c
s/"Tungsten Graphics, Inc"/"VMware, Inc"/
Reviewed-by: Brian Paul <brianp@vmware.com>
2014-01-17 16:27:50 +00:00
|
|
|
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
|
2007-08-02 13:59:31 +01:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Authors:
|
s/Tungsten Graphics/VMware/
Tungsten Graphics Inc. was acquired by VMware Inc. in 2008. Leaving the
old copyright name is creating unnecessary confusion, hence this change.
This was the sed script I used:
$ cat tg2vmw.sed
# Run as:
#
# git reset --hard HEAD && find include scons src -type f -not -name 'sed*' -print0 | xargs -0 sed -i -f tg2vmw.sed
#
# Rename copyrights
s/Tungsten Gra\(ph\|hp\)ics,\? [iI]nc\.\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./g
/Copyright/s/Tungsten Graphics\(,\? [iI]nc\.\)\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./
s/TUNGSTEN GRAPHICS/VMWARE/g
# Rename emails
s/alanh@tungstengraphics.com/alanh@vmware.com/
s/jens@tungstengraphics.com/jowen@vmware.com/g
s/jrfonseca-at-tungstengraphics-dot-com/jfonseca-at-vmware-dot-com/
s/jrfonseca\?@tungstengraphics.com/jfonseca@vmware.com/g
s/keithw\?@tungstengraphics.com/keithw@vmware.com/g
s/michel@tungstengraphics.com/daenzer@vmware.com/g
s/thomas-at-tungstengraphics-dot-com/thellstom-at-vmware-dot-com/
s/zack@tungstengraphics.com/zackr@vmware.com/
# Remove dead links
s@Tungsten Graphics (http://www.tungstengraphics.com)@Tungsten Graphics@g
# C string src/gallium/state_trackers/vega/api_misc.c
s/"Tungsten Graphics, Inc"/"VMware, Inc"/
Reviewed-by: Brian Paul <brianp@vmware.com>
2014-01-17 16:27:50 +00:00
|
|
|
* Keith Whitwell <keithw@vmware.com>
|
2007-08-02 13:59:31 +01:00
|
|
|
* Brian Paul
|
2009-04-04 19:01:51 +02:00
|
|
|
* Michel Dänzer
|
2007-08-02 13:59:31 +01:00
|
|
|
*/
|
|
|
|
|
2018-04-08 13:13:08 -04:00
|
|
|
#include "main/errors.h"
|
2022-11-02 22:43:19 +08:00
|
|
|
#include "util/glheader.h"
|
2011-12-03 10:04:18 -07:00
|
|
|
#include "main/accum.h"
|
2009-10-08 20:27:27 -06:00
|
|
|
#include "main/formats.h"
|
2017-06-09 22:19:33 +02:00
|
|
|
#include "main/framebuffer.h"
|
2007-08-08 16:08:45 -06:00
|
|
|
#include "main/macros.h"
|
2012-10-15 03:55:23 +02:00
|
|
|
#include "main/glformats.h"
|
2010-06-10 23:02:41 -06:00
|
|
|
#include "program/prog_instruction.h"
|
2007-08-02 10:29:42 -06:00
|
|
|
#include "st_context.h"
|
2008-05-02 10:08:03 +00:00
|
|
|
#include "st_atom.h"
|
2016-01-05 18:28:57 -07:00
|
|
|
#include "st_cb_bitmap.h"
|
2007-08-02 10:29:42 -06:00
|
|
|
#include "st_cb_clear.h"
|
2016-02-16 10:22:32 -07:00
|
|
|
#include "st_draw.h"
|
2011-02-21 16:54:23 -07:00
|
|
|
#include "st_format.h"
|
2018-11-02 02:24:00 -07:00
|
|
|
#include "st_nir.h"
|
2007-08-08 16:08:45 -06:00
|
|
|
#include "st_program.h"
|
2019-03-07 09:21:53 -07:00
|
|
|
#include "st_util.h"
|
2007-08-20 16:21:08 -06:00
|
|
|
|
2007-08-02 13:59:31 +01:00
|
|
|
#include "pipe/p_context.h"
|
2010-08-05 18:21:09 -07:00
|
|
|
#include "pipe/p_shader_tokens.h"
|
2007-08-20 16:21:08 -06:00
|
|
|
#include "pipe/p_state.h"
|
2007-08-02 10:29:42 -06:00
|
|
|
#include "pipe/p_defines.h"
|
2019-06-27 15:05:31 -07:00
|
|
|
#include "util/format/u_format.h"
|
2010-03-24 08:25:24 -06:00
|
|
|
#include "util/u_inlines.h"
|
2008-03-20 09:13:51 -06:00
|
|
|
#include "util/u_simple_shaders.h"
|
2007-08-20 16:21:08 -06:00
|
|
|
|
2008-03-11 18:54:31 -06:00
|
|
|
#include "cso_cache/cso_context.h"
|
|
|
|
|
2007-08-20 16:21:08 -06:00
|
|
|
|
2010-03-24 08:25:24 -06:00
|
|
|
/**
|
|
|
|
* Do per-context initialization for glClear.
|
|
|
|
*/
|
2008-04-03 12:54:32 -06:00
|
|
|
void
|
|
|
|
st_init_clear(struct st_context *st)
|
|
|
|
{
|
2010-02-24 16:41:18 +01:00
|
|
|
memset(&st->clear, 0, sizeof(st->clear));
|
|
|
|
|
2013-04-23 19:40:05 +01:00
|
|
|
st->clear.raster.half_pixel_center = 1;
|
|
|
|
st->clear.raster.bottom_edge_rule = 1;
|
2018-08-21 21:59:23 -04:00
|
|
|
st->clear.raster.depth_clip_near = 1;
|
|
|
|
st->clear.raster.depth_clip_far = 1;
|
2008-04-03 12:54:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-24 08:25:24 -06:00
|
|
|
/**
|
|
|
|
* Free per-context state for glClear.
|
|
|
|
*/
|
2008-03-20 09:13:51 -06:00
|
|
|
void
|
|
|
|
st_destroy_clear(struct st_context *st)
|
|
|
|
{
|
|
|
|
if (st->clear.fs) {
|
2020-03-05 15:09:28 -05:00
|
|
|
st->pipe->delete_fs_state(st->pipe, st->clear.fs);
|
2008-03-20 09:13:51 -06:00
|
|
|
st->clear.fs = NULL;
|
|
|
|
}
|
|
|
|
if (st->clear.vs) {
|
2020-03-05 15:09:28 -05:00
|
|
|
st->pipe->delete_vs_state(st->pipe, st->clear.vs);
|
2008-03-20 09:13:51 -06:00
|
|
|
st->clear.vs = NULL;
|
|
|
|
}
|
2014-11-15 13:29:25 -05:00
|
|
|
if (st->clear.vs_layered) {
|
2020-03-05 15:09:28 -05:00
|
|
|
st->pipe->delete_vs_state(st->pipe, st->clear.vs_layered);
|
2014-11-15 13:29:25 -05:00
|
|
|
st->clear.vs_layered = NULL;
|
|
|
|
}
|
|
|
|
if (st->clear.gs_layered) {
|
2020-03-05 15:09:28 -05:00
|
|
|
st->pipe->delete_gs_state(st->pipe, st->clear.gs_layered);
|
2014-11-15 13:29:25 -05:00
|
|
|
st->clear.gs_layered = NULL;
|
|
|
|
}
|
2008-03-20 09:13:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-05 13:27:00 +01:00
|
|
|
/**
|
2022-05-13 17:04:15 +05:30
|
|
|
* Helper function to set the clear color fragment shader.
|
2011-03-05 13:27:00 +01:00
|
|
|
*/
|
2022-05-13 17:04:15 +05:30
|
|
|
static void
|
|
|
|
set_clearcolor_fs(struct st_context *st, union pipe_color_union *color)
|
2011-03-05 13:27:00 +01:00
|
|
|
{
|
2022-05-13 17:04:15 +05:30
|
|
|
struct pipe_constant_buffer cb = {
|
|
|
|
.user_buffer = color->f,
|
|
|
|
.buffer_size = 4 * sizeof(float),
|
|
|
|
};
|
|
|
|
st->pipe->set_constant_buffer(st->pipe, PIPE_SHADER_FRAGMENT, 0,
|
|
|
|
false, &cb);
|
2018-11-02 02:24:00 -07:00
|
|
|
|
|
|
|
if (!st->clear.fs) {
|
2023-05-18 12:58:48 -07:00
|
|
|
st->clear.fs = st_nir_make_clearcolor_shader(st);
|
2018-11-02 02:24:00 -07:00
|
|
|
}
|
2011-03-05 13:27:00 +01:00
|
|
|
|
|
|
|
cso_set_fragment_shader_handle(st->cso_context, st->clear.fs);
|
|
|
|
}
|
|
|
|
|
2018-11-02 02:24:00 -07:00
|
|
|
static void *
|
|
|
|
make_nir_clear_vertex_shader(struct st_context *st, bool layered)
|
|
|
|
{
|
|
|
|
const char *shader_name = layered ? "layered clear VS" : "clear VS";
|
|
|
|
unsigned inputs[] = {
|
|
|
|
VERT_ATTRIB_POS,
|
|
|
|
SYSTEM_VALUE_INSTANCE_ID,
|
|
|
|
};
|
2023-05-18 13:36:47 -07:00
|
|
|
gl_varying_slot outputs[] = {
|
2018-11-02 02:24:00 -07:00
|
|
|
VARYING_SLOT_POS,
|
|
|
|
VARYING_SLOT_LAYER
|
|
|
|
};
|
|
|
|
|
2024-12-24 12:47:48 -05:00
|
|
|
return st_nir_make_passthrough_vs(st, shader_name, layered ? 2 : 1, inputs,
|
|
|
|
outputs, (1 << 1));
|
2018-11-02 02:24:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-05 13:27:00 +01:00
|
|
|
/**
|
|
|
|
* Helper function to set the vertex shader.
|
|
|
|
*/
|
2015-02-26 10:03:22 -07:00
|
|
|
static inline void
|
2011-03-05 13:27:00 +01:00
|
|
|
set_vertex_shader(struct st_context *st)
|
|
|
|
{
|
|
|
|
/* vertex shader - still required to provide the linkage between
|
|
|
|
* fragment shader input semantics and vertex_element/buffers.
|
|
|
|
*/
|
|
|
|
if (!st->clear.vs)
|
2023-05-18 12:58:48 -07:00
|
|
|
st->clear.vs = make_nir_clear_vertex_shader(st, false);
|
2011-03-05 13:27:00 +01:00
|
|
|
|
|
|
|
cso_set_vertex_shader_handle(st->cso_context, st->clear.vs);
|
2014-11-15 13:29:25 -05:00
|
|
|
cso_set_geometry_shader_handle(st->cso_context, NULL);
|
2011-03-05 13:27:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-21 15:50:31 +01:00
|
|
|
static void
|
|
|
|
set_vertex_shader_layered(struct st_context *st)
|
|
|
|
{
|
|
|
|
struct pipe_context *pipe = st->pipe;
|
|
|
|
|
2022-03-08 11:13:19 +01:00
|
|
|
if (!st->screen->get_param(st->screen, PIPE_CAP_VS_INSTANCEID)) {
|
2014-11-15 13:29:25 -05:00
|
|
|
assert(!"Got layered clear, but VS instancing is unsupported");
|
2013-11-21 15:50:31 +01:00
|
|
|
set_vertex_shader(st);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!st->clear.vs_layered) {
|
2014-11-15 13:29:25 -05:00
|
|
|
bool vs_layer =
|
2022-03-08 17:25:46 +01:00
|
|
|
st->screen->get_param(st->screen, PIPE_CAP_VS_LAYER_VIEWPORT);
|
2014-11-15 13:29:25 -05:00
|
|
|
if (vs_layer) {
|
2023-05-18 12:58:48 -07:00
|
|
|
st->clear.vs_layered = make_nir_clear_vertex_shader(st, true);
|
2014-11-15 13:29:25 -05:00
|
|
|
} else {
|
|
|
|
st->clear.vs_layered = util_make_layered_clear_helper_vertex_shader(pipe);
|
|
|
|
st->clear.gs_layered = util_make_layered_clear_geometry_shader(pipe);
|
|
|
|
}
|
2013-11-21 15:50:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cso_set_vertex_shader_handle(st->cso_context, st->clear.vs_layered);
|
2014-11-15 13:29:25 -05:00
|
|
|
cso_set_geometry_shader_handle(st->cso_context, st->clear.gs_layered);
|
2013-11-21 15:50:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-02 10:29:42 -06:00
|
|
|
/**
|
|
|
|
* Do glClear by drawing a quadrilateral.
|
2007-08-10 16:25:21 -06:00
|
|
|
* The vertices of the quad will be computed from the
|
|
|
|
* ctx->DrawBuffer->_X/Ymin/max fields.
|
2007-08-02 10:29:42 -06:00
|
|
|
*/
|
|
|
|
static void
|
2013-12-04 01:24:37 +01:00
|
|
|
clear_with_quad(struct gl_context *ctx, unsigned clear_buffers)
|
2007-08-02 10:29:42 -06:00
|
|
|
{
|
2010-04-23 14:00:50 -06:00
|
|
|
struct st_context *st = st_context(ctx);
|
2016-02-16 10:22:32 -07:00
|
|
|
struct cso_context *cso = st->cso_context;
|
2010-02-22 21:36:22 +01:00
|
|
|
const struct gl_framebuffer *fb = ctx->DrawBuffer;
|
|
|
|
const GLfloat fb_width = (GLfloat) fb->Width;
|
|
|
|
const GLfloat fb_height = (GLfloat) fb->Height;
|
2017-06-09 22:19:33 +02:00
|
|
|
|
|
|
|
_mesa_update_draw_buffer_bounds(ctx, ctx->DrawBuffer);
|
|
|
|
|
2010-02-22 21:36:22 +01:00
|
|
|
const GLfloat x0 = (GLfloat) ctx->DrawBuffer->_Xmin / fb_width * 2.0f - 1.0f;
|
|
|
|
const GLfloat x1 = (GLfloat) ctx->DrawBuffer->_Xmax / fb_width * 2.0f - 1.0f;
|
|
|
|
const GLfloat y0 = (GLfloat) ctx->DrawBuffer->_Ymin / fb_height * 2.0f - 1.0f;
|
|
|
|
const GLfloat y1 = (GLfloat) ctx->DrawBuffer->_Ymax / fb_height * 2.0f - 1.0f;
|
2017-06-05 01:22:45 +02:00
|
|
|
unsigned num_layers = st->state.fb_num_layers;
|
2007-08-02 13:48:02 -06:00
|
|
|
|
2008-02-14 16:53:51 +00:00
|
|
|
/*
|
2015-04-07 22:04:38 +03:00
|
|
|
printf("%s %s%s%s %f,%f %f,%f\n", __func__,
|
2008-02-14 16:53:51 +00:00
|
|
|
color ? "color, " : "",
|
|
|
|
depth ? "depth, " : "",
|
|
|
|
stencil ? "stencil" : "",
|
|
|
|
x0, y0,
|
|
|
|
x1, y1);
|
|
|
|
*/
|
2007-08-02 13:48:02 -06:00
|
|
|
|
2016-02-16 10:22:32 -07:00
|
|
|
cso_save_state(cso, (CSO_BIT_BLEND |
|
|
|
|
CSO_BIT_STENCIL_REF |
|
|
|
|
CSO_BIT_DEPTH_STENCIL_ALPHA |
|
|
|
|
CSO_BIT_RASTERIZER |
|
|
|
|
CSO_BIT_SAMPLE_MASK |
|
|
|
|
CSO_BIT_MIN_SAMPLES |
|
|
|
|
CSO_BIT_VIEWPORT |
|
|
|
|
CSO_BIT_STREAM_OUTPUTS |
|
|
|
|
CSO_BIT_VERTEX_ELEMENTS |
|
2019-09-09 15:36:16 -07:00
|
|
|
(st->active_queries ? CSO_BIT_PAUSE_QUERIES : 0) |
|
2016-02-16 10:22:32 -07:00
|
|
|
CSO_BITS_ALL_SHADERS));
|
2008-03-19 11:12:48 -06:00
|
|
|
|
2007-08-02 13:48:02 -06:00
|
|
|
/* blend state: RGBA masking */
|
2007-08-10 16:25:21 -06:00
|
|
|
{
|
|
|
|
struct pipe_blend_state blend;
|
|
|
|
memset(&blend, 0, sizeof(blend));
|
2013-12-04 01:24:37 +01:00
|
|
|
if (clear_buffers & PIPE_CLEAR_COLOR) {
|
2013-01-14 07:18:00 +01:00
|
|
|
int num_buffers = ctx->Extensions.EXT_draw_buffers2 ?
|
|
|
|
ctx->DrawBuffer->_NumColorDrawBuffers : 1;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
blend.independent_blend_enable = num_buffers > 1;
|
2020-04-16 10:53:03 -07:00
|
|
|
blend.max_rt = num_buffers - 1;
|
2013-01-14 07:18:00 +01:00
|
|
|
|
|
|
|
for (i = 0; i < num_buffers; i++) {
|
2013-12-04 01:24:37 +01:00
|
|
|
if (!(clear_buffers & (PIPE_CLEAR_COLOR0 << i)))
|
|
|
|
continue;
|
|
|
|
|
2018-01-31 03:03:25 +01:00
|
|
|
blend.rt[i].colormask = GET_COLORMASK(ctx->Color.ColorMask, i);
|
2013-01-14 07:18:00 +01:00
|
|
|
}
|
|
|
|
|
2016-02-16 10:22:32 -07:00
|
|
|
if (ctx->Color.DitherFlag)
|
2007-08-10 16:25:21 -06:00
|
|
|
blend.dither = 1;
|
|
|
|
}
|
2016-02-16 10:22:32 -07:00
|
|
|
cso_set_blend(cso, &blend);
|
2007-08-02 13:48:02 -06:00
|
|
|
}
|
2007-08-02 10:29:42 -06:00
|
|
|
|
2007-09-17 11:55:18 -04:00
|
|
|
/* depth_stencil state: always pass/set to ref value */
|
2007-08-10 16:25:21 -06:00
|
|
|
{
|
2007-12-17 16:14:29 +00:00
|
|
|
struct pipe_depth_stencil_alpha_state depth_stencil;
|
2007-09-17 11:55:18 -04:00
|
|
|
memset(&depth_stencil, 0, sizeof(depth_stencil));
|
2013-12-04 01:24:37 +01:00
|
|
|
if (clear_buffers & PIPE_CLEAR_DEPTH) {
|
2020-12-04 08:37:14 -05:00
|
|
|
depth_stencil.depth_enabled = 1;
|
|
|
|
depth_stencil.depth_writemask = 1;
|
|
|
|
depth_stencil.depth_func = PIPE_FUNC_ALWAYS;
|
2007-08-10 16:25:21 -06:00
|
|
|
}
|
2007-09-17 11:55:18 -04:00
|
|
|
|
2013-12-04 01:24:37 +01:00
|
|
|
if (clear_buffers & PIPE_CLEAR_STENCIL) {
|
2010-02-11 04:06:01 +01:00
|
|
|
struct pipe_stencil_ref stencil_ref;
|
|
|
|
memset(&stencil_ref, 0, sizeof(stencil_ref));
|
2007-12-17 16:14:29 +00:00
|
|
|
depth_stencil.stencil[0].enabled = 1;
|
|
|
|
depth_stencil.stencil[0].func = PIPE_FUNC_ALWAYS;
|
|
|
|
depth_stencil.stencil[0].fail_op = PIPE_STENCIL_OP_REPLACE;
|
|
|
|
depth_stencil.stencil[0].zpass_op = PIPE_STENCIL_OP_REPLACE;
|
|
|
|
depth_stencil.stencil[0].zfail_op = PIPE_STENCIL_OP_REPLACE;
|
2009-01-26 14:37:21 -05:00
|
|
|
depth_stencil.stencil[0].valuemask = 0xff;
|
|
|
|
depth_stencil.stencil[0].writemask = ctx->Stencil.WriteMask[0] & 0xff;
|
2010-02-10 21:14:18 +01:00
|
|
|
stencil_ref.ref_value[0] = ctx->Stencil.Clear;
|
2020-12-03 11:36:53 -05:00
|
|
|
cso_set_stencil_ref(cso, stencil_ref);
|
2007-09-17 11:55:18 -04:00
|
|
|
}
|
2008-03-11 18:54:31 -06:00
|
|
|
|
2016-02-16 10:22:32 -07:00
|
|
|
cso_set_depth_stencil_alpha(cso, &depth_stencil);
|
2007-08-02 10:29:42 -06:00
|
|
|
}
|
|
|
|
|
2022-05-13 17:04:15 +05:30
|
|
|
st->util_velems.count = 1;
|
2020-01-20 22:59:49 -05:00
|
|
|
cso_set_vertex_elements(cso, &st->util_velems);
|
|
|
|
|
2024-12-17 01:33:07 -05:00
|
|
|
cso_set_stream_outputs(cso, 0, NULL, NULL, 0);
|
2016-02-16 10:22:32 -07:00
|
|
|
cso_set_sample_mask(cso, ~0);
|
|
|
|
cso_set_min_samples(cso, 1);
|
2019-10-29 19:45:48 +01:00
|
|
|
st->clear.raster.multisample = st->state.fb_num_samples > 1;
|
2016-02-16 10:22:32 -07:00
|
|
|
cso_set_rasterizer(cso, &st->clear.raster);
|
2007-08-02 13:48:02 -06:00
|
|
|
|
2010-02-22 21:36:22 +01:00
|
|
|
/* viewport state: viewport matching window dims */
|
2016-02-16 10:22:32 -07:00
|
|
|
cso_set_viewport_dims(st->cso_context, fb_width, fb_height,
|
2021-12-23 06:17:16 +10:00
|
|
|
_mesa_fb_orientation(fb) == Y_0_TOP);
|
2010-02-22 21:36:22 +01:00
|
|
|
|
2022-05-13 17:04:15 +05:30
|
|
|
/* Set constant buffer */
|
|
|
|
set_clearcolor_fs(st, (union pipe_color_union*)&ctx->Color.ClearColor);
|
2016-02-16 10:22:32 -07:00
|
|
|
cso_set_tessctrl_shader_handle(cso, NULL);
|
|
|
|
cso_set_tesseval_shader_handle(cso, NULL);
|
2007-08-20 21:45:14 +01:00
|
|
|
|
2013-11-21 15:50:31 +01:00
|
|
|
if (num_layers > 1)
|
|
|
|
set_vertex_shader_layered(st);
|
|
|
|
else
|
|
|
|
set_vertex_shader(st);
|
|
|
|
|
2016-02-16 10:22:32 -07:00
|
|
|
/* draw quad matching scissor rect.
|
|
|
|
*
|
|
|
|
* Note: if we're only clearing depth/stencil we still setup vertices
|
|
|
|
* with color, but they'll be ignored.
|
|
|
|
*
|
|
|
|
* We can't translate the clear color to the colorbuffer format,
|
2013-12-04 00:39:52 +01:00
|
|
|
* because different colorbuffers may have different formats.
|
|
|
|
*/
|
2016-02-16 10:22:32 -07:00
|
|
|
if (!st_draw_quad(st, x0, y0, x1, y1,
|
|
|
|
ctx->Depth.Clear * 2.0f - 1.0f,
|
|
|
|
0.0f, 0.0f, 0.0f, 0.0f,
|
|
|
|
(const float *) &ctx->Color.ClearColor.f,
|
|
|
|
num_layers)) {
|
|
|
|
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glClear");
|
|
|
|
}
|
2007-08-02 13:59:31 +01:00
|
|
|
|
2007-08-02 16:08:18 -06:00
|
|
|
/* Restore pipe state */
|
2021-06-07 10:20:38 -04:00
|
|
|
cso_restore_state(cso, 0);
|
2021-10-24 03:57:14 -04:00
|
|
|
ctx->Array.NewVertexElements = true;
|
2022-11-21 07:37:45 -05:00
|
|
|
ctx->NewDriverState |= ST_NEW_VERTEX_ARRAYS |
|
|
|
|
ST_NEW_FS_CONSTANTS;
|
2007-08-02 10:29:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-24 19:36:23 -06:00
|
|
|
/**
|
2013-01-14 06:57:28 +01:00
|
|
|
* Return if the scissor must be enabled during the clear.
|
2007-08-24 19:36:23 -06:00
|
|
|
*/
|
2015-02-26 10:03:22 -07:00
|
|
|
static inline GLboolean
|
2013-01-14 06:57:28 +01:00
|
|
|
is_scissor_enabled(struct gl_context *ctx, struct gl_renderbuffer *rb)
|
2008-02-14 16:53:51 +00:00
|
|
|
{
|
2016-09-11 13:37:30 -04:00
|
|
|
const struct gl_scissor_rect *scissor = &ctx->Scissor.ScissorArray[0];
|
|
|
|
|
2013-11-13 14:02:12 -07:00
|
|
|
return (ctx->Scissor.EnableFlags & 1) &&
|
2016-09-11 13:37:30 -04:00
|
|
|
(scissor->X > 0 ||
|
|
|
|
scissor->Y > 0 ||
|
2016-10-14 15:15:13 -07:00
|
|
|
scissor->X + scissor->Width < (int)rb->Width ||
|
|
|
|
scissor->Y + scissor->Height < (int)rb->Height);
|
2007-08-24 19:36:23 -06:00
|
|
|
}
|
|
|
|
|
2016-06-11 16:52:17 -04:00
|
|
|
/**
|
|
|
|
* Return if window rectangles must be enabled during the clear.
|
|
|
|
*/
|
|
|
|
static inline bool
|
|
|
|
is_window_rectangle_enabled(struct gl_context *ctx)
|
|
|
|
{
|
|
|
|
if (ctx->DrawBuffer == ctx->WinSysDrawBuffer)
|
|
|
|
return false;
|
|
|
|
return ctx->Scissor.NumWindowRects > 0 ||
|
|
|
|
ctx->Scissor.WindowRectMode == GL_INCLUSIVE_EXT;
|
|
|
|
}
|
|
|
|
|
2007-08-24 19:36:23 -06:00
|
|
|
|
2013-12-27 19:10:03 +01:00
|
|
|
/**
|
|
|
|
* Return if all of the stencil bits are masked.
|
|
|
|
*/
|
2015-02-26 10:03:22 -07:00
|
|
|
static inline GLboolean
|
2013-12-27 19:10:03 +01:00
|
|
|
is_stencil_disabled(struct gl_context *ctx, struct gl_renderbuffer *rb)
|
|
|
|
{
|
|
|
|
const GLuint stencilMax = 0xff;
|
|
|
|
|
|
|
|
assert(_mesa_get_format_bits(rb->Format, GL_STENCIL_BITS) > 0);
|
|
|
|
return (ctx->Stencil.WriteMask[0] & stencilMax) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-24 19:36:23 -06:00
|
|
|
/**
|
2013-01-14 06:57:28 +01:00
|
|
|
* Return if any of the stencil bits are masked.
|
2007-08-24 19:36:23 -06:00
|
|
|
*/
|
2015-02-26 10:03:22 -07:00
|
|
|
static inline GLboolean
|
2013-01-14 06:57:28 +01:00
|
|
|
is_stencil_masked(struct gl_context *ctx, struct gl_renderbuffer *rb)
|
2007-08-24 19:36:23 -06:00
|
|
|
{
|
2009-10-08 20:27:27 -06:00
|
|
|
const GLuint stencilMax = 0xff;
|
2008-02-14 16:53:51 +00:00
|
|
|
|
2012-02-12 16:17:53 -07:00
|
|
|
assert(_mesa_get_format_bits(rb->Format, GL_STENCIL_BITS) > 0);
|
2013-01-14 06:57:28 +01:00
|
|
|
return (ctx->Stencil.WriteMask[0] & stencilMax) != stencilMax;
|
2007-08-24 19:36:23 -06:00
|
|
|
}
|
|
|
|
|
2021-12-07 10:54:42 +10:00
|
|
|
void
|
2010-10-12 12:26:10 -04:00
|
|
|
st_Clear(struct gl_context *ctx, GLbitfield mask)
|
2007-08-02 13:59:31 +01:00
|
|
|
{
|
2010-04-23 14:00:50 -06:00
|
|
|
struct st_context *st = st_context(ctx);
|
2007-08-02 16:08:18 -06:00
|
|
|
struct gl_renderbuffer *depthRb
|
|
|
|
= ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
|
|
|
|
struct gl_renderbuffer *stencilRb
|
|
|
|
= ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
|
2010-03-24 08:25:24 -06:00
|
|
|
GLbitfield quad_buffers = 0x0;
|
|
|
|
GLbitfield clear_buffers = 0x0;
|
2020-03-24 12:02:51 -04:00
|
|
|
bool have_scissor_buffers = false;
|
2009-04-04 19:01:51 +02:00
|
|
|
GLuint i;
|
2007-08-02 13:59:31 +01:00
|
|
|
|
2016-01-05 18:28:57 -07:00
|
|
|
st_flush_bitmap_cache(st);
|
2016-06-09 12:16:26 +02:00
|
|
|
st_invalidate_readpix_cache(st);
|
2016-01-05 18:28:57 -07:00
|
|
|
|
2009-04-04 19:01:51 +02:00
|
|
|
/* This makes sure the pipe has the latest scissor, etc values */
|
2022-11-21 07:47:59 -05:00
|
|
|
st_validate_state(st, ST_PIPELINE_CLEAR_STATE_MASK);
|
2007-08-02 13:59:31 +01:00
|
|
|
|
2009-04-04 19:01:51 +02:00
|
|
|
if (mask & BUFFER_BITS_COLOR) {
|
|
|
|
for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++) {
|
2017-11-08 22:18:40 -07:00
|
|
|
gl_buffer_index b = ctx->DrawBuffer->_ColorDrawBufferIndexes[i];
|
2007-08-02 16:08:18 -06:00
|
|
|
|
2017-11-08 22:18:40 -07:00
|
|
|
if (b != BUFFER_NONE && mask & (1 << b)) {
|
2007-08-13 16:16:42 -06:00
|
|
|
struct gl_renderbuffer *rb
|
|
|
|
= ctx->DrawBuffer->Attachment[b].Renderbuffer;
|
2013-01-14 07:18:00 +01:00
|
|
|
int colormask_index = ctx->Extensions.EXT_draw_buffers2 ? i : 0;
|
2009-04-04 19:01:51 +02:00
|
|
|
|
2021-12-10 09:35:23 +10:00
|
|
|
if (!rb || !rb->surface)
|
2009-04-04 19:01:51 +02:00
|
|
|
continue;
|
|
|
|
|
2018-11-13 14:19:38 -05:00
|
|
|
unsigned colormask =
|
|
|
|
GET_COLORMASK(ctx->Color.ColorMask, colormask_index);
|
|
|
|
|
|
|
|
if (!colormask)
|
2013-12-04 01:24:37 +01:00
|
|
|
continue;
|
|
|
|
|
2018-11-13 14:19:38 -05:00
|
|
|
unsigned surf_colormask =
|
2021-12-10 09:35:23 +10:00
|
|
|
util_format_colormask(util_format_description(rb->surface->format));
|
2018-11-13 14:19:38 -05:00
|
|
|
|
2020-03-24 12:02:51 -04:00
|
|
|
bool scissor = is_scissor_enabled(ctx, rb);
|
|
|
|
if ((scissor && !st->can_scissor_clear) ||
|
2016-06-11 16:52:17 -04:00
|
|
|
is_window_rectangle_enabled(ctx) ||
|
2018-11-13 14:19:38 -05:00
|
|
|
((colormask & surf_colormask) != surf_colormask))
|
2013-12-04 01:24:37 +01:00
|
|
|
quad_buffers |= PIPE_CLEAR_COLOR0 << i;
|
2009-04-04 19:01:51 +02:00
|
|
|
else
|
2013-12-04 01:24:37 +01:00
|
|
|
clear_buffers |= PIPE_CLEAR_COLOR0 << i;
|
2020-03-24 12:02:51 -04:00
|
|
|
have_scissor_buffers |= scissor && st->can_scissor_clear;
|
2007-08-02 16:08:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-08-02 18:25:10 +01:00
|
|
|
|
2013-01-14 08:16:18 +01:00
|
|
|
if (mask & BUFFER_BIT_DEPTH) {
|
2021-12-10 09:35:23 +10:00
|
|
|
if (depthRb->surface && ctx->Depth.Mask) {
|
2021-02-07 15:17:00 -05:00
|
|
|
bool scissor = is_scissor_enabled(ctx, depthRb);
|
|
|
|
if ((scissor && !st->can_scissor_clear) ||
|
2016-06-11 16:52:17 -04:00
|
|
|
is_window_rectangle_enabled(ctx))
|
2013-01-14 08:16:18 +01:00
|
|
|
quad_buffers |= PIPE_CLEAR_DEPTH;
|
2009-04-04 19:01:51 +02:00
|
|
|
else
|
2013-01-14 08:16:18 +01:00
|
|
|
clear_buffers |= PIPE_CLEAR_DEPTH;
|
2021-02-07 15:17:00 -05:00
|
|
|
have_scissor_buffers |= scissor && st->can_scissor_clear;
|
2009-04-04 19:01:51 +02:00
|
|
|
}
|
2007-08-02 13:59:31 +01:00
|
|
|
}
|
2013-01-14 08:16:18 +01:00
|
|
|
if (mask & BUFFER_BIT_STENCIL) {
|
2021-12-10 09:35:23 +10:00
|
|
|
if (stencilRb->surface && !is_stencil_disabled(ctx, stencilRb)) {
|
2021-02-07 15:17:00 -05:00
|
|
|
bool scissor = is_scissor_enabled(ctx, stencilRb);
|
|
|
|
if ((scissor && !st->can_scissor_clear) ||
|
2016-06-11 16:52:17 -04:00
|
|
|
is_window_rectangle_enabled(ctx) ||
|
2013-01-14 08:16:18 +01:00
|
|
|
is_stencil_masked(ctx, stencilRb))
|
|
|
|
quad_buffers |= PIPE_CLEAR_STENCIL;
|
|
|
|
else
|
|
|
|
clear_buffers |= PIPE_CLEAR_STENCIL;
|
2021-02-07 15:17:00 -05:00
|
|
|
have_scissor_buffers |= scissor && st->can_scissor_clear;
|
2007-08-02 16:08:18 -06:00
|
|
|
}
|
2007-08-02 13:59:31 +01:00
|
|
|
}
|
2009-04-04 19:01:51 +02:00
|
|
|
|
2013-12-06 18:58:52 +01:00
|
|
|
/* Always clear depth and stencil together.
|
|
|
|
* This can only happen when the stencil writemask is not a full mask.
|
|
|
|
*/
|
|
|
|
if (quad_buffers & PIPE_CLEAR_DEPTHSTENCIL &&
|
|
|
|
clear_buffers & PIPE_CLEAR_DEPTHSTENCIL) {
|
|
|
|
quad_buffers |= clear_buffers & PIPE_CLEAR_DEPTHSTENCIL;
|
|
|
|
clear_buffers &= ~PIPE_CLEAR_DEPTHSTENCIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only use quad-based clearing for the renderbuffers which cannot
|
|
|
|
* use pipe->clear. We want to always use pipe->clear for the other
|
|
|
|
* renderbuffers, because it's likely to be faster.
|
2009-04-04 19:01:51 +02:00
|
|
|
*/
|
2013-12-06 18:58:52 +01:00
|
|
|
if (clear_buffers) {
|
2020-03-24 12:02:51 -04:00
|
|
|
const struct gl_scissor_rect *scissor = &ctx->Scissor.ScissorArray[0];
|
|
|
|
struct pipe_scissor_state scissor_state = {
|
|
|
|
.minx = MAX2(scissor->X, 0),
|
|
|
|
.miny = MAX2(scissor->Y, 0),
|
|
|
|
.maxx = MAX2(scissor->X + scissor->Width, 0),
|
|
|
|
.maxy = MAX2(scissor->Y + scissor->Height, 0),
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Now invert Y if needed.
|
|
|
|
* Gallium drivers use the convention Y=0=top for surfaces.
|
|
|
|
*/
|
|
|
|
if (st->state.fb_orientation == Y_0_TOP) {
|
|
|
|
const struct gl_framebuffer *fb = ctx->DrawBuffer;
|
|
|
|
/* use intermediate variables to avoid uint underflow */
|
|
|
|
GLint miny, maxy;
|
|
|
|
miny = fb->Height - scissor_state.maxy;
|
|
|
|
maxy = fb->Height - scissor_state.miny;
|
|
|
|
scissor_state.miny = MAX2(miny, 0);
|
|
|
|
scissor_state.maxy = MAX2(maxy, 0);
|
|
|
|
}
|
2021-03-01 14:52:25 -05:00
|
|
|
if (have_scissor_buffers) {
|
|
|
|
const struct gl_framebuffer *fb = ctx->DrawBuffer;
|
|
|
|
scissor_state.maxx = MIN2(scissor_state.maxx, fb->Width);
|
|
|
|
scissor_state.maxy = MIN2(scissor_state.maxy, fb->Height);
|
2021-03-01 16:57:35 -05:00
|
|
|
if (scissor_state.minx >= scissor_state.maxx ||
|
|
|
|
scissor_state.miny >= scissor_state.maxy)
|
2021-03-01 14:53:50 -05:00
|
|
|
return;
|
2021-03-01 14:52:25 -05:00
|
|
|
}
|
2013-12-04 00:39:52 +01:00
|
|
|
/* We can't translate the clear color to the colorbuffer format,
|
|
|
|
* because different colorbuffers may have different formats.
|
|
|
|
*/
|
2020-03-24 12:02:51 -04:00
|
|
|
st->pipe->clear(st->pipe, clear_buffers, have_scissor_buffers ? &scissor_state : NULL,
|
2013-12-04 00:39:52 +01:00
|
|
|
(union pipe_color_union*)&ctx->Color.ClearColor,
|
2010-04-23 14:00:50 -06:00
|
|
|
ctx->Depth.Clear, ctx->Stencil.Clear);
|
2010-05-29 00:04:14 +02:00
|
|
|
}
|
2018-11-13 13:40:58 -05:00
|
|
|
if (quad_buffers) {
|
|
|
|
clear_with_quad(ctx, quad_buffers);
|
|
|
|
}
|
2009-04-04 19:01:51 +02:00
|
|
|
if (mask & BUFFER_BIT_ACCUM)
|
2011-12-03 10:04:18 -07:00
|
|
|
_mesa_clear_accum_buffer(ctx);
|
2007-08-02 13:59:31 +01:00
|
|
|
}
|
|
|
|
|