shader,feat: Add support for TGSI_PROPERTY_FS_DEPTH_LAYOUT

GL 4.2 supports depth layouts that make it possible to optimize by
enabling early depth tests and still being able to write a new
z value in the fragment shader under specific circumstances.

Fixes #106

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
macos/master
Gert Wollny 5 years ago
parent a07a3f6f96
commit 52703a2ded
  1. 3
      src/vrend_renderer.c
  2. 33
      src/vrend_shader.c
  3. 1
      src/vrend_shader.h

@ -99,6 +99,7 @@ enum features_id
feat_compute_shader,
feat_copy_image,
feat_conditional_render_inverted,
feat_conservative_depth,
feat_cube_map_array,
feat_debug_cb,
feat_depth_clamp,
@ -184,6 +185,7 @@ static const struct {
FEAT(compute_shader, 43, 31, "GL_ARB_compute_shader" ),
FEAT(copy_image, 43, 32, "GL_ARB_copy_image", "GL_EXT_copy_image", "GL_OES_copy_image" ),
FEAT(conditional_render_inverted, 45, UNAVAIL, "GL_ARB_conditional_render_inverted" ),
FEAT(conservative_depth, 42, UNAVAIL, "GL_ARB_conservative_depth", "GL_EXT_conservative_depth" ),
FEAT(cube_map_array, 40, 32, "GL_ARB_texture_cube_map_array", "GL_EXT_texture_cube_map_array", "GL_OES_texture_cube_map_array" ),
FEAT(debug_cb, UNAVAIL, UNAVAIL, NULL), /* special case */
FEAT(draw_instance, 31, 30, "GL_ARB_draw_instanced" ),
@ -5811,6 +5813,7 @@ struct vrend_context *vrend_create_context(int id, uint32_t nlen, const char *de
grctx->shader_cfg.has_arrays_of_arrays = has_feature(feat_arrays_of_arrays);
grctx->shader_cfg.has_gpu_shader5 = has_feature(feat_gpu_shader5);
grctx->shader_cfg.has_es31_compat = has_feature(feat_gles31_compatibility);
grctx->shader_cfg.has_conservative_depth = has_feature(feat_conservative_depth);
vrend_renderer_create_sub_ctx(grctx, 0);
vrend_renderer_set_sub_ctx(grctx, 0);

@ -72,6 +72,7 @@
#define SHADER_REQ_SHADER_INTEGER_FUNC (1 << 27)
#define SHADER_REQ_SHADER_ATOMIC_FLOAT (1 << 28)
#define SHADER_REQ_NV_IMAGE_FORMATS (1 << 29)
#define SHADER_REQ_CONSERVATIVE_DEPTH (1 << 30)
struct vrend_shader_io {
unsigned name;
@ -219,6 +220,7 @@ struct dump_ctx {
uint32_t shadow_samp_mask;
int fs_coord_origin, fs_pixel_center;
int fs_depth_layout;
int gs_in_prim, gs_out_prim, gs_max_out_verts;
int gs_num_invocations;
@ -275,6 +277,7 @@ static const struct vrend_shader_table shader_req_table[] = {
{ SHADER_REQ_SHADER_CLOCK, "ARB_shader_clock" },
{ SHADER_REQ_SHADER_INTEGER_FUNC, "MESA_shader_integer_functions" },
{ SHADER_REQ_SHADER_ATOMIC_FLOAT, "NV_shader_atomic_float"},
{ SHADER_REQ_CONSERVATIVE_DEPTH, "ARB_conservative_depth"},
};
enum vrend_type_qualifier {
@ -1530,6 +1533,14 @@ iter_property(struct tgsi_iterate_context *iter,
case TGSI_PROPERTY_FS_COORD_PIXEL_CENTER:
ctx->fs_pixel_center = prop->u[0].Data;
break;
case TGSI_PROPERTY_FS_DEPTH_LAYOUT:
/* If the host doesn't support this, then we can savely ignore this,
* we only lost an opportunity to optimize */
if (ctx->cfg->has_conservative_depth) {
ctx->shader_req_bits |= SHADER_REQ_CONSERVATIVE_DEPTH;
ctx->fs_depth_layout = prop->u[0].Data;
}
break;
case TGSI_PROPERTY_GS_INPUT_PRIM:
ctx->gs_in_prim = prop->u[0].Data;
break;
@ -5200,6 +5211,9 @@ static void emit_header(struct dump_ctx *ctx)
if (ctx->shader_req_bits & SHADER_REQ_SAMPLER_MS)
emit_ext(ctx, "OES_texture_storage_multisample_2d_array", "require");
if (ctx->shader_req_bits & SHADER_REQ_CONSERVATIVE_DEPTH)
emit_ext(ctx, "EXT_conservative_depth", "require");
if (ctx->prog_type == TGSI_PROCESSOR_FRAGMENT) {
if (ctx->shader_req_bits & SHADER_REQ_FBFETCH)
emit_ext(ctx, "EXT_shader_framebuffer_fetch", "require");
@ -6007,6 +6021,19 @@ static void emit_ios_vs(struct dump_ctx *ctx)
}
}
static const char *get_depth_layout(int depth_layout)
{
const char *dl[4] = {
"depth_any",
"depth_greater",
"depth_less",
"depth_unchanged"
};
if (depth_layout < 1 || depth_layout > TGSI_FS_DEPTH_LAYOUT_UNCHANGED)
return NULL;
return dl[depth_layout -1];
}
static void emit_ios_fs(struct dump_ctx *ctx)
{
@ -6093,6 +6120,12 @@ static void emit_ios_fs(struct dump_ctx *ctx)
}
}
if (ctx->fs_depth_layout) {
const char *depth_layout = get_depth_layout(ctx->fs_depth_layout);
if (depth_layout)
emit_hdrf(ctx, "layout (%s) out float gl_FragDepth;\n", depth_layout);
}
if (ctx->num_in_clip_dist) {
if (ctx->key->prev_stage_num_clip_out) {
emit_hdrf(ctx, "in float gl_ClipDistance[%d];\n", ctx->key->prev_stage_num_clip_out);

@ -135,6 +135,7 @@ struct vrend_shader_cfg {
bool has_arrays_of_arrays;
bool has_gpu_shader5;
bool has_es31_compat;
bool has_conservative_depth;
};
struct vrend_context;

Loading…
Cancel
Save