glsl: add EXT_clip_cull_distance support based on ARB_cull_distance

Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Reviewed-by: Dave Airlie <airlied@redhat.com>
This commit is contained in:
Ilia Mirkin
2016-05-23 21:38:38 -04:00
parent f236f1f506
commit 979bcb9f42
5 changed files with 34 additions and 21 deletions

View File

@@ -674,11 +674,14 @@ builtin_variable_generator::generate_constants()
state->Const.MaxProgramTexelOffset); state->Const.MaxProgramTexelOffset);
} }
if (state->is_version(130, 0)) { if (state->is_version(130, 0) || state->EXT_clip_cull_distance_enable) {
add_const("gl_MaxClipDistances", state->Const.MaxClipPlanes); add_const("gl_MaxClipDistances", state->Const.MaxClipPlanes);
}
if (state->is_version(130, 0)) {
add_const("gl_MaxVaryingComponents", state->ctx->Const.MaxVarying * 4); add_const("gl_MaxVaryingComponents", state->ctx->Const.MaxVarying * 4);
} }
if (state->is_version(450, 0) || state->ARB_cull_distance_enable) { if (state->is_version(450, 0) || state->ARB_cull_distance_enable ||
state->EXT_clip_cull_distance_enable) {
add_const("gl_MaxCullDistances", state->Const.MaxClipPlanes); add_const("gl_MaxCullDistances", state->Const.MaxClipPlanes);
add_const("gl_MaxCombinedClipAndCullDistances", add_const("gl_MaxCombinedClipAndCullDistances",
state->Const.MaxClipPlanes); state->Const.MaxClipPlanes);
@@ -1250,11 +1253,12 @@ builtin_variable_generator::generate_varyings()
} }
} }
if (state->is_version(130, 0)) { if (state->is_version(130, 0) || state->EXT_clip_cull_distance_enable) {
add_varying(VARYING_SLOT_CLIP_DIST0, array(float_t, 0), add_varying(VARYING_SLOT_CLIP_DIST0, array(float_t, 0),
"gl_ClipDistance"); "gl_ClipDistance");
} }
if (state->is_version(450, 0) || state->ARB_cull_distance_enable) { if (state->is_version(450, 0) || state->ARB_cull_distance_enable ||
state->EXT_clip_cull_distance_enable) {
add_varying(VARYING_SLOT_CULL_DIST0, array(float_t, 0), add_varying(VARYING_SLOT_CULL_DIST0, array(float_t, 0),
"gl_CullDistance"); "gl_CullDistance");
} }

View File

@@ -641,6 +641,7 @@ static const _mesa_glsl_extension _mesa_glsl_supported_extensions[] = {
EXT(AMD_vertex_shader_viewport_index, true, false, AMD_vertex_shader_viewport_index), EXT(AMD_vertex_shader_viewport_index, true, false, AMD_vertex_shader_viewport_index),
EXT(EXT_blend_func_extended, false, true, ARB_blend_func_extended), EXT(EXT_blend_func_extended, false, true, ARB_blend_func_extended),
EXT(EXT_draw_buffers, false, true, dummy_true), EXT(EXT_draw_buffers, false, true, dummy_true),
EXT(EXT_clip_cull_distance, false, true, ARB_cull_distance),
EXT(EXT_gpu_shader5, false, true, ARB_gpu_shader5), EXT(EXT_gpu_shader5, false, true, ARB_gpu_shader5),
EXT(EXT_separate_shader_objects, false, true, dummy_true), EXT(EXT_separate_shader_objects, false, true, dummy_true),
EXT(EXT_shader_integer_mix, true, true, EXT_shader_integer_mix), EXT(EXT_shader_integer_mix, true, true, EXT_shader_integer_mix),

View File

@@ -639,6 +639,8 @@ struct _mesa_glsl_parse_state {
bool AMD_vertex_shader_viewport_index_warn; bool AMD_vertex_shader_viewport_index_warn;
bool EXT_blend_func_extended_enable; bool EXT_blend_func_extended_enable;
bool EXT_blend_func_extended_warn; bool EXT_blend_func_extended_warn;
bool EXT_clip_cull_distance_enable;
bool EXT_clip_cull_distance_warn;
bool EXT_draw_buffers_enable; bool EXT_draw_buffers_enable;
bool EXT_draw_buffers_warn; bool EXT_draw_buffers_warn;
bool EXT_gpu_shader5_enable; bool EXT_gpu_shader5_enable;

View File

@@ -661,7 +661,7 @@ analyze_clip_cull_usage(struct gl_shader_program *prog,
*clip_distance_array_size = 0; *clip_distance_array_size = 0;
*cull_distance_array_size = 0; *cull_distance_array_size = 0;
if (!prog->IsES && prog->Version >= 130) { if (prog->Version >= (prog->IsES ? 300 : 130)) {
/* From section 7.1 (Vertex Shader Special Variables) of the /* From section 7.1 (Vertex Shader Special Variables) of the
* GLSL 1.30 spec: * GLSL 1.30 spec:
* *
@@ -669,13 +669,12 @@ analyze_clip_cull_usage(struct gl_shader_program *prog,
* gl_ClipVertex and gl_ClipDistance." * gl_ClipVertex and gl_ClipDistance."
* *
* This does not apply to GLSL ES shaders, since GLSL ES defines neither * This does not apply to GLSL ES shaders, since GLSL ES defines neither
* gl_ClipVertex nor gl_ClipDistance. * gl_ClipVertex nor gl_ClipDistance. However with
* GL_EXT_clip_cull_distance, this functionality is exposed in ES 3.0.
*/ */
find_assignment_visitor clip_vertex("gl_ClipVertex");
find_assignment_visitor clip_distance("gl_ClipDistance"); find_assignment_visitor clip_distance("gl_ClipDistance");
find_assignment_visitor cull_distance("gl_CullDistance"); find_assignment_visitor cull_distance("gl_CullDistance");
clip_vertex.run(shader->ir);
clip_distance.run(shader->ir); clip_distance.run(shader->ir);
cull_distance.run(shader->ir); cull_distance.run(shader->ir);
@@ -685,20 +684,26 @@ analyze_clip_cull_usage(struct gl_shader_program *prog,
* a program to statically read or write both gl_ClipVertex and either * a program to statically read or write both gl_ClipVertex and either
* gl_ClipDistance or gl_CullDistance. * gl_ClipDistance or gl_CullDistance.
* *
* This does not apply to GLSL ES shaders, since GLSL ES defines neither * This does not apply to GLSL ES shaders, since GLSL ES doesn't define
* gl_ClipVertex, gl_ClipDistance or gl_CullDistance. * gl_ClipVertex.
*/ */
if (clip_vertex.variable_found() && clip_distance.variable_found()) { if (!prog->IsES) {
linker_error(prog, "%s shader writes to both `gl_ClipVertex' " find_assignment_visitor clip_vertex("gl_ClipVertex");
"and `gl_ClipDistance'\n",
_mesa_shader_stage_to_string(shader->Stage)); clip_vertex.run(shader->ir);
return;
} if (clip_vertex.variable_found() && clip_distance.variable_found()) {
if (clip_vertex.variable_found() && cull_distance.variable_found()) { linker_error(prog, "%s shader writes to both `gl_ClipVertex' "
linker_error(prog, "%s shader writes to both `gl_ClipVertex' " "and `gl_ClipDistance'\n",
"and `gl_CullDistance'\n", _mesa_shader_stage_to_string(shader->Stage));
_mesa_shader_stage_to_string(shader->Stage)); return;
return; }
if (clip_vertex.variable_found() && cull_distance.variable_found()) {
linker_error(prog, "%s shader writes to both `gl_ClipVertex' "
"and `gl_CullDistance'\n",
_mesa_shader_stage_to_string(shader->Stage));
return;
}
} }
if (clip_distance.variable_found()) { if (clip_distance.variable_found()) {

View File

@@ -189,6 +189,7 @@ EXT(EXT_blend_func_separate , EXT_blend_func_separate
EXT(EXT_blend_minmax , EXT_blend_minmax , GLL, x , ES1, ES2, 1995) EXT(EXT_blend_minmax , EXT_blend_minmax , GLL, x , ES1, ES2, 1995)
EXT(EXT_blend_subtract , dummy_true , GLL, x , x , x , 1995) EXT(EXT_blend_subtract , dummy_true , GLL, x , x , x , 1995)
EXT(EXT_buffer_storage , ARB_buffer_storage , x , x , x , 31, 2015) EXT(EXT_buffer_storage , ARB_buffer_storage , x , x , x , 31, 2015)
EXT(EXT_clip_cull_distance , ARB_cull_distance , x , x , x , 30, 2016)
EXT(EXT_color_buffer_float , dummy_true , x , x , ES1, 30, 2013) EXT(EXT_color_buffer_float , dummy_true , x , x , ES1, 30, 2013)
EXT(EXT_compiled_vertex_array , dummy_true , GLL, x , x , x , 1996) EXT(EXT_compiled_vertex_array , dummy_true , GLL, x , x , x , 1996)
EXT(EXT_copy_image , OES_copy_image , x , x , x , 30, 2014) EXT(EXT_copy_image , OES_copy_image , x , x , x , 30, 2014)