mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2024-11-27 12:14:10 +08:00
mesa/st: Remove GL_ARB_depth_clamp emulation support.
This was useful for emulating GL 3.2 in virgl on a GLES3 host renderer, before GL_EXT_depth_clamp introduced the ability for hardware drivers to expose the feature on GLES. Now that we have that, the desktop-GL-capable HW that virgl cares about can expose desktop GL even on its GLES renderer on the host without this emulation. I don't think anyone particularly cares about hitting higher GL versions on actually-core-GLES hosts with virgl. Reviewed-by: Marek Olšák <marek.olsak@amd.com> Acked-by: Gert Wollny <gert.wollny@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13729>
This commit is contained in:
parent
c691149f3e
commit
9b2600da87
@ -73,9 +73,7 @@ The integer capabilities:
|
||||
* ``PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER``: Whether the TGSI
|
||||
property FS_COORD_PIXEL_CENTER with value INTEGER is supported.
|
||||
* ``PIPE_CAP_DEPTH_CLIP_DISABLE``: Whether the driver is capable of disabling
|
||||
depth clipping (=1) (through pipe_rasterizer_state) or supports lowering
|
||||
depth_clamp in the client shader code (=2), for this the driver must
|
||||
currently use TGSI.
|
||||
depth clipping (through pipe_rasterizer_state).
|
||||
* ``PIPE_CAP_DEPTH_CLIP_DISABLE_SEPARATE``: Whether the driver is capable of
|
||||
disabling depth clipping (through pipe_rasterizer_state) separately for
|
||||
the near and far plane. If not, depth_clip_near and depth_clip_far will be
|
||||
|
@ -127,8 +127,6 @@ virgl_get_param(struct pipe_screen *screen, enum pipe_cap param)
|
||||
case PIPE_CAP_DEPTH_CLIP_DISABLE:
|
||||
if (vscreen->caps.caps.v1.bset.depth_clip_disable)
|
||||
return 1;
|
||||
if (vscreen->caps.caps.v2.host_feature_check_version >= 3)
|
||||
return 2;
|
||||
return 0;
|
||||
case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS:
|
||||
return vscreen->caps.caps.v1.max_streamout_buffers;
|
||||
|
@ -457,8 +457,6 @@ files_libmesa = files(
|
||||
'state_tracker/st_shader_cache.h',
|
||||
'state_tracker/st_texture.c',
|
||||
'state_tracker/st_texture.h',
|
||||
'state_tracker/st_tgsi_lower_depth_clamp.c',
|
||||
'state_tracker/st_tgsi_lower_depth_clamp.h',
|
||||
'state_tracker/st_tgsi_lower_yuv.c',
|
||||
'state_tracker/st_tgsi_lower_yuv.h',
|
||||
'state_tracker/st_util.h',
|
||||
|
@ -296,10 +296,8 @@ st_update_rasterizer(struct st_context *st)
|
||||
}
|
||||
|
||||
/* _NEW_TRANSFORM */
|
||||
raster->depth_clip_near = st->clamp_frag_depth_in_shader ||
|
||||
!ctx->Transform.DepthClampNear;
|
||||
raster->depth_clip_far = st->clamp_frag_depth_in_shader ||
|
||||
!ctx->Transform.DepthClampFar;
|
||||
raster->depth_clip_near = !ctx->Transform.DepthClampNear;
|
||||
raster->depth_clip_far = !ctx->Transform.DepthClampFar;
|
||||
raster->depth_clamp = !raster->depth_clip_far;
|
||||
raster->clip_plane_enable = ctx->Transform.ClipPlanesEnabled;
|
||||
raster->clip_halfz = (ctx->Transform.ClipDepthMode == GL_ZERO_TO_ONE);
|
||||
|
@ -168,11 +168,6 @@ st_update_fp( struct st_context *st )
|
||||
st->ctx->Multisample.MinSampleShadingValue *
|
||||
_mesa_geometric_samples(st->ctx->DrawBuffer) > 1;
|
||||
|
||||
key.lower_depth_clamp =
|
||||
st->clamp_frag_depth_in_shader &&
|
||||
(st->ctx->Transform.DepthClampNear ||
|
||||
st->ctx->Transform.DepthClampFar);
|
||||
|
||||
if (stfp->ati_fs) {
|
||||
key.fog = st->ctx->Fog._PackedEnabledMode;
|
||||
|
||||
@ -237,16 +232,6 @@ st_update_vp( struct st_context *st )
|
||||
VARYING_SLOT_BFC0 |
|
||||
VARYING_SLOT_BFC1));
|
||||
|
||||
key.lower_depth_clamp =
|
||||
!st->gp && !st->tep &&
|
||||
st->clamp_frag_depth_in_shader &&
|
||||
(st->ctx->Transform.DepthClampNear ||
|
||||
st->ctx->Transform.DepthClampFar);
|
||||
|
||||
if (key.lower_depth_clamp)
|
||||
key.clip_negative_one_to_one =
|
||||
st->ctx->Transform.ClipDepthMode == GL_NEGATIVE_ONE_TO_ONE;
|
||||
|
||||
if (!st->ctx->GeometryProgram._Current &&
|
||||
!st->ctx->TessEvalProgram._Current) {
|
||||
/* _NEW_POINT */
|
||||
@ -310,16 +295,6 @@ st_update_common_program(struct st_context *st, struct gl_program *prog,
|
||||
VARYING_SLOT_BFC0 |
|
||||
VARYING_SLOT_BFC1));
|
||||
|
||||
key.lower_depth_clamp =
|
||||
(pipe_shader == PIPE_SHADER_GEOMETRY || !st->gp) &&
|
||||
st->clamp_frag_depth_in_shader &&
|
||||
(st->ctx->Transform.DepthClampNear ||
|
||||
st->ctx->Transform.DepthClampFar);
|
||||
|
||||
if (key.lower_depth_clamp)
|
||||
key.clip_negative_one_to_one =
|
||||
st->ctx->Transform.ClipDepthMode == GL_NEGATIVE_ONE_TO_ONE;
|
||||
|
||||
if (st->lower_ucp && st_user_clip_planes_enabled(st->ctx) &&
|
||||
pipe_shader == PIPE_SHADER_GEOMETRY)
|
||||
key.lower_ucp = st->ctx->Transform.ClipPlanesEnabled;
|
||||
|
@ -785,10 +785,8 @@ draw_textured_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
|
||||
ctx->Color._ClampFragmentColor;
|
||||
rasterizer.half_pixel_center = 1;
|
||||
rasterizer.bottom_edge_rule = 1;
|
||||
rasterizer.depth_clip_near = st->clamp_frag_depth_in_shader ||
|
||||
!ctx->Transform.DepthClampNear;
|
||||
rasterizer.depth_clip_far = st->clamp_frag_depth_in_shader ||
|
||||
!ctx->Transform.DepthClampFar;
|
||||
rasterizer.depth_clip_near = !ctx->Transform.DepthClampNear;
|
||||
rasterizer.depth_clip_far = !ctx->Transform.DepthClampFar;
|
||||
rasterizer.depth_clamp = !rasterizer.depth_clip_far;
|
||||
rasterizer.scissor = ctx->Scissor.EnableFlags;
|
||||
cso_set_rasterizer(cso, &rasterizer);
|
||||
@ -1275,34 +1273,6 @@ setup_sampler_swizzle(struct pipe_sampler_view *sv, GLenum format, GLenum type)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compute the effective raster z position. This performs depth-clamping
|
||||
* if needed.
|
||||
*/
|
||||
static float
|
||||
get_effective_raster_z(struct gl_context *ctx)
|
||||
{
|
||||
float z = ctx->Current.RasterPos[2];
|
||||
if (st_context(ctx)->clamp_frag_depth_in_shader) {
|
||||
GLfloat depth_near;
|
||||
GLfloat depth_far;
|
||||
if (ctx->ViewportArray[0].Near < ctx->ViewportArray[0].Far) {
|
||||
depth_near = ctx->ViewportArray[0].Near;
|
||||
depth_far = ctx->ViewportArray[0].Far;
|
||||
} else {
|
||||
depth_near = ctx->ViewportArray[0].Far;
|
||||
depth_far = ctx->ViewportArray[0].Near;
|
||||
}
|
||||
|
||||
if (ctx->Transform.DepthClampNear)
|
||||
z = MAX2(z, depth_near);
|
||||
if (ctx->Transform.DepthClampFar)
|
||||
z = MIN2(z, depth_far);
|
||||
}
|
||||
return z;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called via ctx->Driver.DrawPixels()
|
||||
*/
|
||||
@ -1429,7 +1399,7 @@ st_DrawPixels(struct gl_context *ctx, GLint x, GLint y,
|
||||
num_sampler_view++;
|
||||
}
|
||||
|
||||
draw_textured_quad(ctx, x, y, get_effective_raster_z(ctx),
|
||||
draw_textured_quad(ctx, x, y, ctx->Current.RasterPos[2],
|
||||
width, height,
|
||||
ctx->Pixel.ZoomX, ctx->Pixel.ZoomY,
|
||||
sv,
|
||||
@ -1965,7 +1935,7 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
|
||||
* textured quad with that texture.
|
||||
*/
|
||||
|
||||
draw_textured_quad(ctx, dstx, dsty, get_effective_raster_z(ctx),
|
||||
draw_textured_quad(ctx, dstx, dsty, ctx->Current.RasterPos[2],
|
||||
width, height, ctx->Pixel.ZoomX, ctx->Pixel.ZoomY,
|
||||
sv,
|
||||
num_sampler_view,
|
||||
|
@ -246,16 +246,6 @@ st_invalidate_state(struct gl_context *ctx)
|
||||
ctx->Array.NewVertexElements = true;
|
||||
}
|
||||
|
||||
if (st->clamp_frag_depth_in_shader && (new_state & _NEW_VIEWPORT)) {
|
||||
if (ctx->GeometryProgram._Current)
|
||||
st->dirty |= ST_NEW_GS_CONSTANTS;
|
||||
else if (ctx->TessEvalProgram._Current)
|
||||
st->dirty |= ST_NEW_TES_CONSTANTS;
|
||||
else
|
||||
st->dirty |= ST_NEW_VS_CONSTANTS;
|
||||
st->dirty |= ST_NEW_FS_CONSTANTS;
|
||||
}
|
||||
|
||||
/* Update the vertex shader if ctx->Light._ClampVertexColor was changed. */
|
||||
if (st->clamp_vert_color_in_shader && (new_state & _NEW_LIGHT_STATE)) {
|
||||
st->dirty |= ST_NEW_VS_STATE;
|
||||
@ -547,15 +537,7 @@ st_init_driver_flags(struct st_context *st)
|
||||
f->NewFragClamp = ST_NEW_RASTERIZER;
|
||||
}
|
||||
|
||||
if (st->clamp_frag_depth_in_shader) {
|
||||
f->NewClipControl |= ST_NEW_VS_STATE | ST_NEW_GS_STATE |
|
||||
ST_NEW_TES_STATE;
|
||||
|
||||
f->NewDepthClamp = ST_NEW_FS_STATE | ST_NEW_VS_STATE |
|
||||
ST_NEW_GS_STATE | ST_NEW_TES_STATE;
|
||||
} else {
|
||||
f->NewDepthClamp = ST_NEW_RASTERIZER;
|
||||
}
|
||||
f->NewDepthClamp = ST_NEW_RASTERIZER;
|
||||
|
||||
if (st->lower_ucp)
|
||||
f->NewClipPlaneEnable = ST_NEW_VS_STATE | ST_NEW_GS_STATE;
|
||||
@ -783,9 +765,6 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
|
||||
}
|
||||
}
|
||||
|
||||
if (screen->get_param(screen, PIPE_CAP_DEPTH_CLIP_DISABLE) == 2)
|
||||
st->clamp_frag_depth_in_shader = true;
|
||||
|
||||
/* called after _mesa_create_context/_mesa_init_point, fix default user
|
||||
* settable max point size up
|
||||
*/
|
||||
@ -818,7 +797,6 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
|
||||
/* Set which shader types can be compiled at link time. */
|
||||
st->shader_has_one_variant[MESA_SHADER_VERTEX] =
|
||||
st->has_shareable_shaders &&
|
||||
!st->clamp_frag_depth_in_shader &&
|
||||
!st->clamp_vert_color_in_shader &&
|
||||
!st->lower_point_size &&
|
||||
!st->lower_ucp;
|
||||
@ -828,7 +806,6 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
|
||||
!st->lower_flatshade &&
|
||||
!st->lower_alpha_test &&
|
||||
!st->clamp_frag_color_in_shader &&
|
||||
!st->clamp_frag_depth_in_shader &&
|
||||
!st->force_persample_in_shader &&
|
||||
!st->lower_two_sided_color &&
|
||||
!st->lower_texcoord_replace;
|
||||
@ -836,14 +813,12 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
|
||||
st->shader_has_one_variant[MESA_SHADER_TESS_CTRL] = st->has_shareable_shaders;
|
||||
st->shader_has_one_variant[MESA_SHADER_TESS_EVAL] =
|
||||
st->has_shareable_shaders &&
|
||||
!st->clamp_frag_depth_in_shader &&
|
||||
!st->clamp_vert_color_in_shader &&
|
||||
!st->lower_point_size &&
|
||||
!st->lower_ucp;
|
||||
|
||||
st->shader_has_one_variant[MESA_SHADER_GEOMETRY] =
|
||||
st->has_shareable_shaders &&
|
||||
!st->clamp_frag_depth_in_shader &&
|
||||
!st->clamp_vert_color_in_shader &&
|
||||
!st->lower_point_size &&
|
||||
!st->lower_ucp;
|
||||
|
@ -137,7 +137,6 @@ struct st_context
|
||||
|
||||
GLboolean clamp_frag_color_in_shader;
|
||||
GLboolean clamp_vert_color_in_shader;
|
||||
boolean clamp_frag_depth_in_shader;
|
||||
boolean has_stencil_export; /**< can do shader stencil export? */
|
||||
boolean has_time_elapsed;
|
||||
boolean has_etc1;
|
||||
|
@ -237,14 +237,7 @@ void st_init_limits(struct pipe_screen *screen,
|
||||
|
||||
if (!screen->get_param(screen, PIPE_CAP_POINT_SIZE_FIXED))
|
||||
pc->MaxUniformComponents -= 4;
|
||||
|
||||
if (screen->get_param(screen, PIPE_CAP_DEPTH_CLIP_DISABLE) == 2)
|
||||
pc->MaxUniformComponents -= 4;
|
||||
|
||||
} else if (sh == PIPE_SHADER_FRAGMENT) {
|
||||
if (screen->get_param(screen, PIPE_CAP_DEPTH_CLIP_DISABLE) == 2)
|
||||
pc->MaxUniformComponents -= 4;
|
||||
|
||||
if (!screen->get_param(screen, PIPE_CAP_ALPHA_TEST))
|
||||
pc->MaxUniformComponents -= 4;
|
||||
}
|
||||
|
@ -61,7 +61,6 @@
|
||||
#include "st_cb_bitmap.h"
|
||||
#include "st_cb_drawpixels.h"
|
||||
#include "st_context.h"
|
||||
#include "st_tgsi_lower_depth_clamp.h"
|
||||
#include "st_tgsi_lower_yuv.h"
|
||||
#include "st_program.h"
|
||||
#include "st_atifs_to_nir.h"
|
||||
@ -756,9 +755,6 @@ lower_ucp(struct st_context *st,
|
||||
}
|
||||
}
|
||||
|
||||
static const gl_state_index16 depth_range_state[STATE_LENGTH] =
|
||||
{ STATE_DEPTH_RANGE };
|
||||
|
||||
static struct st_common_variant *
|
||||
st_create_common_variant(struct st_context *st,
|
||||
struct st_program *stp,
|
||||
@ -881,18 +877,6 @@ st_create_common_variant(struct st_context *st,
|
||||
}
|
||||
}
|
||||
|
||||
if (key->lower_depth_clamp) {
|
||||
unsigned depth_range_const =
|
||||
_mesa_add_state_reference(params, depth_range_state);
|
||||
|
||||
const struct tgsi_token *tokens;
|
||||
tokens = st_tgsi_lower_depth_clamp(state.tokens, depth_range_const,
|
||||
key->clip_negative_one_to_one);
|
||||
if (tokens != state.tokens)
|
||||
tgsi_free_tokens(state.tokens);
|
||||
state.tokens = tokens;
|
||||
}
|
||||
|
||||
if (ST_DEBUG & DEBUG_PRINT_IR)
|
||||
tgsi_dump(state.tokens, 0);
|
||||
|
||||
@ -975,12 +959,10 @@ st_get_common_variant(struct st_context *st,
|
||||
if (!v) {
|
||||
if (stp->variants != NULL) {
|
||||
_mesa_perf_debug(st->ctx, MESA_DEBUG_SEVERITY_MEDIUM,
|
||||
"Compiling %s shader variant (%s%s%s%s%s%s%s%s)",
|
||||
"Compiling %s shader variant (%s%s%s%s%s%s)",
|
||||
_mesa_shader_stage_to_string(stp->Base.info.stage),
|
||||
key->passthrough_edgeflags ? "edgeflags," : "",
|
||||
key->clamp_color ? "clamp_color," : "",
|
||||
key->lower_depth_clamp ? "depth_clamp," : "",
|
||||
key->clip_negative_one_to_one ? "clip_negative_one," : "",
|
||||
key->export_point_size ? "point_size," : "",
|
||||
key->lower_ucp ? "ucp," : "",
|
||||
key->is_draw_shader ? "draw," : "",
|
||||
@ -1634,15 +1616,6 @@ st_create_fp_variant(struct st_context *st,
|
||||
}
|
||||
}
|
||||
|
||||
if (key->lower_depth_clamp) {
|
||||
unsigned depth_range_const = _mesa_add_state_reference(params, depth_range_state);
|
||||
|
||||
const struct tgsi_token *tokens;
|
||||
tokens = st_tgsi_lower_depth_clamp_fs(state.tokens, depth_range_const);
|
||||
if (state.tokens != stfp->state.tokens)
|
||||
tgsi_free_tokens(state.tokens);
|
||||
state.tokens = tokens;
|
||||
}
|
||||
|
||||
if (ST_DEBUG & DEBUG_PRINT_IR)
|
||||
tgsi_dump(state.tokens, 0);
|
||||
@ -1679,7 +1652,7 @@ st_get_fp_variant(struct st_context *st,
|
||||
|
||||
if (stfp->variants != NULL) {
|
||||
_mesa_perf_debug(st->ctx, MESA_DEBUG_SEVERITY_MEDIUM,
|
||||
"Compiling fragment shader variant (%s%s%s%s%s%s%s%s%s%s%s%s%s%s)",
|
||||
"Compiling fragment shader variant (%s%s%s%s%s%s%s%s%s%s%s%s%s)",
|
||||
key->bitmap ? "bitmap," : "",
|
||||
key->drawpixels ? "drawpixels," : "",
|
||||
key->scaleAndBias ? "scale_bias," : "",
|
||||
@ -1687,7 +1660,6 @@ st_get_fp_variant(struct st_context *st,
|
||||
key->clamp_color ? "clamp_color," : "",
|
||||
key->persample_shading ? "persample_shading," : "",
|
||||
key->fog ? "fog," : "",
|
||||
key->lower_depth_clamp ? "depth_clamp," : "",
|
||||
key->lower_two_sided_color ? "twoside," : "",
|
||||
key->lower_flatshade ? "flatshade," : "",
|
||||
key->lower_texcoord_replace ? "texcoord_replace," : "",
|
||||
|
@ -157,9 +157,6 @@ struct st_fp_variant_key
|
||||
/** needed for ATI_fragment_shader */
|
||||
GLuint fog:2;
|
||||
|
||||
/** for ARB_depth_clamp */
|
||||
GLuint lower_depth_clamp:1;
|
||||
|
||||
/** for OpenGL 1.0 on modern hardware */
|
||||
GLuint lower_two_sided_color:1;
|
||||
|
||||
@ -221,10 +218,6 @@ struct st_common_variant_key
|
||||
/** for ARB_color_buffer_float */
|
||||
bool clamp_color;
|
||||
|
||||
/** both for ARB_depth_clamp */
|
||||
bool lower_depth_clamp;
|
||||
bool clip_negative_one_to_one;
|
||||
|
||||
/** lower glPointSize to gl_PointSize */
|
||||
boolean export_point_size;
|
||||
|
||||
|
@ -1,409 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2018 Collabora Ltd
|
||||
*
|
||||
* 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, sublicense,
|
||||
* 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 NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS 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.
|
||||
*/
|
||||
|
||||
#include "st_tgsi_lower_depth_clamp.h"
|
||||
#include "tgsi/tgsi_transform.h"
|
||||
#include "tgsi/tgsi_scan.h"
|
||||
|
||||
struct tgsi_depth_clamp_transform {
|
||||
struct tgsi_transform_context base;
|
||||
|
||||
struct tgsi_shader_info info;
|
||||
|
||||
int depth_range_const;
|
||||
int next_generic;
|
||||
int imm;
|
||||
int depth_var;
|
||||
int pos_input;
|
||||
int pos_output;
|
||||
int pos_input_temp;
|
||||
int pos_output_temp;
|
||||
int depth_range_corrected;
|
||||
bool depth_clip_minus_one_to_one;
|
||||
};
|
||||
|
||||
static inline struct tgsi_depth_clamp_transform *
|
||||
tgsi_depth_clamp_transform(struct tgsi_transform_context *tctx)
|
||||
{
|
||||
return (struct tgsi_depth_clamp_transform *)tctx;
|
||||
}
|
||||
|
||||
static void
|
||||
transform_decl(struct tgsi_transform_context *tctx,
|
||||
struct tgsi_full_declaration *decl)
|
||||
{
|
||||
struct tgsi_depth_clamp_transform *ctx = tgsi_depth_clamp_transform(tctx);
|
||||
|
||||
/* find the next generic index usable for our inserted varying */
|
||||
if (ctx->info.processor == PIPE_SHADER_FRAGMENT) {
|
||||
if (decl->Declaration.File == TGSI_FILE_INPUT &&
|
||||
decl->Semantic.Name == TGSI_SEMANTIC_GENERIC)
|
||||
ctx->next_generic = MAX2(ctx->next_generic, decl->Semantic.Index + 1);
|
||||
} else {
|
||||
if (decl->Declaration.File == TGSI_FILE_OUTPUT &&
|
||||
decl->Semantic.Name == TGSI_SEMANTIC_GENERIC)
|
||||
ctx->next_generic = MAX2(ctx->next_generic, decl->Semantic.Index + 1);
|
||||
}
|
||||
|
||||
if (decl->Declaration.File == TGSI_FILE_OUTPUT &&
|
||||
decl->Semantic.Name == TGSI_SEMANTIC_POSITION) {
|
||||
assert(decl->Semantic.Index == 0);
|
||||
ctx->pos_output = decl->Range.First;
|
||||
} else if (decl->Declaration.File == TGSI_FILE_INPUT &&
|
||||
decl->Semantic.Name == TGSI_SEMANTIC_POSITION) {
|
||||
assert(decl->Semantic.Index == 0);
|
||||
if (ctx->info.processor == PIPE_SHADER_FRAGMENT)
|
||||
ctx->pos_input = decl->Range.First;
|
||||
}
|
||||
|
||||
tctx->emit_declaration(tctx, decl);
|
||||
}
|
||||
|
||||
static void
|
||||
prolog_common(struct tgsi_depth_clamp_transform *ctx)
|
||||
{
|
||||
assert(ctx->depth_range_const >= 0);
|
||||
if (ctx->info.const_file_max[0] < ctx->depth_range_const)
|
||||
tgsi_transform_const_decl(&ctx->base, ctx->depth_range_const,
|
||||
ctx->depth_range_const);
|
||||
|
||||
/* declare a temp for the position-output */
|
||||
ctx->pos_output_temp = ctx->info.file_max[TGSI_FILE_TEMPORARY] + 1;
|
||||
tgsi_transform_temp_decl(&ctx->base, ctx->pos_output_temp);
|
||||
}
|
||||
|
||||
static void
|
||||
prolog_last_vertex_stage(struct tgsi_transform_context *tctx)
|
||||
{
|
||||
struct tgsi_depth_clamp_transform *ctx = tgsi_depth_clamp_transform(tctx);
|
||||
|
||||
prolog_common(ctx);
|
||||
|
||||
ctx->imm = ctx->info.immediate_count;
|
||||
tgsi_transform_immediate_decl(tctx, 0.5, 0.0, 0.0, 0.0);
|
||||
|
||||
/* declare the output */
|
||||
ctx->depth_var = ctx->info.num_outputs;
|
||||
tgsi_transform_output_decl(tctx, ctx->depth_var,
|
||||
TGSI_SEMANTIC_GENERIC,
|
||||
ctx->next_generic,
|
||||
TGSI_INTERPOLATE_LINEAR);
|
||||
}
|
||||
|
||||
static void
|
||||
epilog_last_vertex_stage(struct tgsi_transform_context *tctx)
|
||||
{
|
||||
struct tgsi_depth_clamp_transform *ctx = tgsi_depth_clamp_transform(tctx);
|
||||
|
||||
int mad_dst_file = TGSI_FILE_TEMPORARY;
|
||||
int mad_dst_index = ctx->pos_output_temp;
|
||||
|
||||
if (!ctx->depth_clip_minus_one_to_one) {
|
||||
mad_dst_file = TGSI_FILE_OUTPUT;
|
||||
mad_dst_index = ctx->depth_var;
|
||||
}
|
||||
|
||||
/* move from temp-register to output */
|
||||
tgsi_transform_op1_inst(tctx, TGSI_OPCODE_MOV,
|
||||
TGSI_FILE_OUTPUT, ctx->pos_output,
|
||||
TGSI_WRITEMASK_XYZW,
|
||||
TGSI_FILE_TEMPORARY, ctx->pos_output_temp);
|
||||
|
||||
/* Set gl_position.z to 0.0 to avoid clipping */
|
||||
tgsi_transform_op1_swz_inst(tctx, TGSI_OPCODE_MOV,
|
||||
TGSI_FILE_OUTPUT, ctx->pos_output,
|
||||
TGSI_WRITEMASK_Z,
|
||||
TGSI_FILE_IMMEDIATE, ctx->imm,
|
||||
TGSI_SWIZZLE_Y);
|
||||
|
||||
/* Evaluate and pass true depth value in depthRange terms */
|
||||
/* z = gl_Position.z / gl_Position.w */
|
||||
|
||||
struct tgsi_full_instruction inst;
|
||||
|
||||
inst = tgsi_default_full_instruction();
|
||||
inst.Instruction.Opcode = TGSI_OPCODE_DIV;
|
||||
inst.Instruction.NumDstRegs = 1;
|
||||
inst.Dst[0].Register.File = TGSI_FILE_TEMPORARY;
|
||||
inst.Dst[0].Register.Index = ctx->pos_output_temp;
|
||||
inst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_X;
|
||||
inst.Instruction.NumSrcRegs = 2;
|
||||
tgsi_transform_src_reg_xyzw(&inst.Src[0], TGSI_FILE_TEMPORARY, ctx->pos_output_temp);
|
||||
tgsi_transform_src_reg_xyzw(&inst.Src[1], TGSI_FILE_TEMPORARY, ctx->pos_output_temp);
|
||||
inst.Src[0].Register.SwizzleX =
|
||||
inst.Src[0].Register.SwizzleY =
|
||||
inst.Src[0].Register.SwizzleZ =
|
||||
inst.Src[0].Register.SwizzleW = TGSI_SWIZZLE_Z;
|
||||
|
||||
inst.Src[1].Register.SwizzleX =
|
||||
inst.Src[1].Register.SwizzleY =
|
||||
inst.Src[1].Register.SwizzleZ =
|
||||
inst.Src[1].Register.SwizzleW = TGSI_SWIZZLE_W;
|
||||
|
||||
tctx->emit_instruction(tctx, &inst);
|
||||
|
||||
|
||||
/* OpenGL Core Profile 4.5 - 13.6.1
|
||||
* The vertex's windows z coordinate zw is given by zw = s * z + b.
|
||||
*
|
||||
* * With clip control depth mode ZERO_TO_ONE
|
||||
* s = f - n, b = n, and hence
|
||||
*
|
||||
* zw_0_1 = z * gl_DepthRange.diff + gl_DepthRange.near
|
||||
*/
|
||||
tgsi_transform_op3_swz_inst(tctx, TGSI_OPCODE_MAD,
|
||||
mad_dst_file, mad_dst_index,
|
||||
TGSI_WRITEMASK_X,
|
||||
TGSI_FILE_TEMPORARY, ctx->pos_output_temp,
|
||||
TGSI_SWIZZLE_X,
|
||||
false,
|
||||
TGSI_FILE_CONSTANT, ctx->depth_range_const,
|
||||
TGSI_SWIZZLE_Z,
|
||||
TGSI_FILE_CONSTANT, ctx->depth_range_const,
|
||||
TGSI_SWIZZLE_X);
|
||||
|
||||
/* If clip control depth mode is NEGATIVE_ONE_TO_ONE, then
|
||||
* s = 0.5 * (f - n), b = 0.5 * (n + f), and hence
|
||||
*
|
||||
* zw_m1_1 = 0.5 * (zw_01 + gl_DepthRange.far)
|
||||
*/
|
||||
if (ctx->depth_clip_minus_one_to_one) {
|
||||
/* z += gl_DepthRange.far */
|
||||
tgsi_transform_op2_swz_inst(tctx, TGSI_OPCODE_ADD,
|
||||
TGSI_FILE_TEMPORARY, ctx->pos_output_temp,
|
||||
TGSI_WRITEMASK_X,
|
||||
TGSI_FILE_TEMPORARY, ctx->pos_output_temp,
|
||||
TGSI_SWIZZLE_X,
|
||||
TGSI_FILE_CONSTANT, ctx->depth_range_const,
|
||||
TGSI_SWIZZLE_Y, false);
|
||||
/* z *= 0.5 */
|
||||
tgsi_transform_op2_swz_inst(tctx, TGSI_OPCODE_MUL,
|
||||
TGSI_FILE_OUTPUT, ctx->depth_var,
|
||||
TGSI_WRITEMASK_X,
|
||||
TGSI_FILE_TEMPORARY, ctx->pos_output_temp,
|
||||
TGSI_SWIZZLE_X,
|
||||
TGSI_FILE_IMMEDIATE, ctx->imm,
|
||||
TGSI_SWIZZLE_X, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
prolog_fs(struct tgsi_transform_context *tctx)
|
||||
{
|
||||
struct tgsi_depth_clamp_transform *ctx = tgsi_depth_clamp_transform(tctx);
|
||||
|
||||
prolog_common(ctx);
|
||||
|
||||
ctx->depth_range_corrected = ctx->info.file_max[TGSI_FILE_TEMPORARY] + 2;
|
||||
tgsi_transform_temp_decl(tctx, ctx->depth_range_corrected);
|
||||
|
||||
/* declare the input */
|
||||
ctx->depth_var = ctx->info.num_inputs;
|
||||
tgsi_transform_input_decl(tctx, ctx->depth_var,
|
||||
TGSI_SEMANTIC_GENERIC,
|
||||
ctx->next_generic,
|
||||
TGSI_INTERPOLATE_LINEAR);
|
||||
|
||||
/* declare the output */
|
||||
if (ctx->pos_output < 0) {
|
||||
ctx->pos_output = ctx->info.num_outputs;
|
||||
tgsi_transform_output_decl(tctx, ctx->pos_output,
|
||||
TGSI_SEMANTIC_POSITION,
|
||||
0,
|
||||
TGSI_INTERPOLATE_LINEAR);
|
||||
}
|
||||
|
||||
if (ctx->info.reads_z) {
|
||||
ctx->pos_input_temp = ctx->info.file_max[TGSI_FILE_TEMPORARY] + 3;
|
||||
tgsi_transform_temp_decl(tctx, ctx->pos_input_temp);
|
||||
|
||||
assert(ctx->pos_input_temp >= 0);
|
||||
/* copy normal position */
|
||||
tgsi_transform_op1_inst(tctx, TGSI_OPCODE_MOV,
|
||||
TGSI_FILE_TEMPORARY, ctx->pos_input_temp,
|
||||
TGSI_WRITEMASK_XYZW,
|
||||
TGSI_FILE_INPUT, ctx->pos_input);
|
||||
/* replace z-component with varying */
|
||||
tgsi_transform_op1_swz_inst(tctx, TGSI_OPCODE_MOV,
|
||||
TGSI_FILE_TEMPORARY, ctx->pos_input_temp,
|
||||
TGSI_WRITEMASK_Z,
|
||||
TGSI_FILE_INPUT, ctx->depth_var,
|
||||
TGSI_SWIZZLE_X);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
epilog_fs(struct tgsi_transform_context *tctx)
|
||||
{
|
||||
struct tgsi_depth_clamp_transform *ctx = tgsi_depth_clamp_transform(tctx);
|
||||
|
||||
unsigned src0_file = TGSI_FILE_INPUT;
|
||||
unsigned src0_index = ctx->depth_var;
|
||||
unsigned src0_swizzle = TGSI_SWIZZLE_X;
|
||||
|
||||
if (ctx->info.writes_z) {
|
||||
src0_file = TGSI_FILE_TEMPORARY;
|
||||
src0_index = ctx->pos_output_temp;
|
||||
src0_swizzle = TGSI_SWIZZLE_Z;
|
||||
}
|
||||
|
||||
/* it is possible to have gl_DepthRange.near > gl_DepthRange.far, so first
|
||||
* we have to sort the two */
|
||||
tgsi_transform_op2_swz_inst(tctx, TGSI_OPCODE_MIN,
|
||||
TGSI_FILE_TEMPORARY, ctx->depth_range_corrected,
|
||||
TGSI_WRITEMASK_X,
|
||||
TGSI_FILE_CONSTANT, ctx->depth_range_const,
|
||||
TGSI_SWIZZLE_X,
|
||||
TGSI_FILE_CONSTANT, ctx->depth_range_const,
|
||||
TGSI_SWIZZLE_Y,
|
||||
false);
|
||||
|
||||
tgsi_transform_op2_swz_inst(tctx, TGSI_OPCODE_MAX,
|
||||
TGSI_FILE_TEMPORARY, ctx->depth_range_corrected,
|
||||
TGSI_WRITEMASK_Y,
|
||||
TGSI_FILE_CONSTANT, ctx->depth_range_const,
|
||||
TGSI_SWIZZLE_X,
|
||||
TGSI_FILE_CONSTANT, ctx->depth_range_const,
|
||||
TGSI_SWIZZLE_Y,
|
||||
false);
|
||||
|
||||
/* gl_FragDepth = max(gl_FragDepth, min(gl_DepthRange.near, gl_DepthRange.far)) */
|
||||
tgsi_transform_op2_swz_inst(tctx, TGSI_OPCODE_MAX,
|
||||
TGSI_FILE_TEMPORARY, ctx->pos_output_temp,
|
||||
TGSI_WRITEMASK_X,
|
||||
src0_file, src0_index, src0_swizzle,
|
||||
TGSI_FILE_TEMPORARY, ctx->depth_range_corrected,
|
||||
TGSI_SWIZZLE_X, false);
|
||||
|
||||
/* gl_FragDepth = min(gl_FragDepth, max(gl_DepthRange.near, gl_DepthRange.far)) */
|
||||
tgsi_transform_op2_swz_inst(tctx, TGSI_OPCODE_MIN,
|
||||
TGSI_FILE_OUTPUT, ctx->pos_output,
|
||||
TGSI_WRITEMASK_Z,
|
||||
TGSI_FILE_TEMPORARY, ctx->pos_output_temp,
|
||||
TGSI_SWIZZLE_X,
|
||||
TGSI_FILE_TEMPORARY, ctx->depth_range_corrected,
|
||||
TGSI_SWIZZLE_Y, false);
|
||||
}
|
||||
|
||||
static void
|
||||
transform_instr(struct tgsi_transform_context *tctx,
|
||||
struct tgsi_full_instruction *inst)
|
||||
{
|
||||
struct tgsi_depth_clamp_transform *ctx = tgsi_depth_clamp_transform(tctx);
|
||||
|
||||
if (ctx->pos_output >= 0) {
|
||||
/* replace writes to gl_Position / gl_FragDepth with a temp-variable
|
||||
*/
|
||||
for (int i = 0; i < inst->Instruction.NumDstRegs; ++i) {
|
||||
if (inst->Dst[i].Register.File == TGSI_FILE_OUTPUT &&
|
||||
inst->Dst[i].Register.Index == ctx->pos_output) {
|
||||
inst->Dst[i].Register.File = TGSI_FILE_TEMPORARY;
|
||||
inst->Dst[i].Register.Index = ctx->pos_output_temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ctx->info.reads_z) {
|
||||
/* replace reads from gl_FragCoord with temp-variable
|
||||
*/
|
||||
assert(ctx->pos_input_temp >= 0);
|
||||
for (int i = 0; i < inst->Instruction.NumSrcRegs; ++i) {
|
||||
if (inst->Src[i].Register.File == TGSI_FILE_INPUT &&
|
||||
inst->Src[i].Register.Index == ctx->pos_input) {
|
||||
inst->Src[i].Register.File = TGSI_FILE_TEMPORARY;
|
||||
inst->Src[i].Register.Index = ctx->pos_input_temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* In a GS each we have to add the z-write opilog for each emit
|
||||
*/
|
||||
if (ctx->info.processor == PIPE_SHADER_GEOMETRY &&
|
||||
inst->Instruction.Opcode == TGSI_OPCODE_EMIT)
|
||||
epilog_last_vertex_stage(tctx);
|
||||
|
||||
tctx->emit_instruction(tctx, inst);
|
||||
}
|
||||
|
||||
const struct tgsi_token *
|
||||
st_tgsi_lower_depth_clamp(const struct tgsi_token *tokens,
|
||||
int depth_range_const,
|
||||
bool clip_negative_one_to_one)
|
||||
{
|
||||
struct tgsi_depth_clamp_transform ctx;
|
||||
struct tgsi_token *newtoks;
|
||||
int newlen;
|
||||
|
||||
memset(&ctx, 0, sizeof(ctx));
|
||||
tgsi_scan_shader(tokens, &ctx.info);
|
||||
|
||||
/* we only want to do this for the fragment shader, and the shader-stage
|
||||
* right before it, but in the first pass there might be no "next" shader
|
||||
*/
|
||||
if (ctx.info.processor != PIPE_SHADER_FRAGMENT &&
|
||||
ctx.info.processor != PIPE_SHADER_GEOMETRY &&
|
||||
ctx.info.processor != PIPE_SHADER_VERTEX &&
|
||||
ctx.info.processor != PIPE_SHADER_TESS_EVAL &&
|
||||
(ctx.info.properties[TGSI_PROPERTY_NEXT_SHADER] > PIPE_SHADER_VERTEX &&
|
||||
(ctx.info.properties[TGSI_PROPERTY_NEXT_SHADER] != PIPE_SHADER_FRAGMENT))) {
|
||||
return tokens;
|
||||
}
|
||||
|
||||
ctx.base.transform_declaration = transform_decl;
|
||||
ctx.base.transform_instruction = transform_instr;
|
||||
|
||||
if (ctx.info.processor == PIPE_SHADER_FRAGMENT) {
|
||||
ctx.base.prolog = prolog_fs;
|
||||
ctx.base.epilog = epilog_fs;
|
||||
} else {
|
||||
ctx.base.prolog = prolog_last_vertex_stage;
|
||||
ctx.base.epilog = epilog_last_vertex_stage;
|
||||
}
|
||||
|
||||
ctx.pos_output = ctx.pos_input = -1;
|
||||
ctx.depth_range_const = depth_range_const;
|
||||
ctx.depth_clip_minus_one_to_one = clip_negative_one_to_one;
|
||||
|
||||
/* We add approximately 30 tokens per Z write, so add this per vertex in
|
||||
* a GS and some additional tokes for VS and TES
|
||||
*/
|
||||
newlen = tgsi_num_tokens(tokens) +
|
||||
30 * ctx.info.properties[TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES] +
|
||||
120;
|
||||
|
||||
newtoks = tgsi_alloc_tokens(newlen);
|
||||
if (!newtoks)
|
||||
return tokens;
|
||||
|
||||
tgsi_transform_shader(tokens, newtoks, newlen, &ctx.base);
|
||||
|
||||
return newtoks;
|
||||
}
|
||||
|
||||
const struct tgsi_token *
|
||||
st_tgsi_lower_depth_clamp_fs(const struct tgsi_token *tokens,
|
||||
int depth_range_const)
|
||||
{
|
||||
return st_tgsi_lower_depth_clamp(tokens, depth_range_const, false);
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2018 Collabora Ltd
|
||||
*
|
||||
* 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, sublicense,
|
||||
* 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 NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS 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.
|
||||
*/
|
||||
|
||||
#ifndef ST_TGSI_LOWER_DEPTH_CLAMP_H
|
||||
#define ST_TGSI_LOWER_DEPTH_CLAMP_H
|
||||
|
||||
#include <stdbool.h>
|
||||
struct tgsi_token;
|
||||
|
||||
const struct tgsi_token *
|
||||
st_tgsi_lower_depth_clamp(const struct tgsi_token *tokens,
|
||||
int depth_range_const,
|
||||
bool clip_negative_one_to_one);
|
||||
|
||||
const struct tgsi_token *
|
||||
st_tgsi_lower_depth_clamp_fs(const struct tgsi_token *tokens,
|
||||
int depth_range_const);
|
||||
|
||||
#endif /* ST_TGSI_LOWER_DEPTH_CLAMP_H */
|
Loading…
Reference in New Issue
Block a user