diff --git a/src/compiler/glsl/builtin_variables.cpp b/src/compiler/glsl/builtin_variables.cpp index d894e618ad4..42017905b11 100644 --- a/src/compiler/glsl/builtin_variables.cpp +++ b/src/compiler/glsl/builtin_variables.cpp @@ -177,19 +177,19 @@ static const struct gl_builtin_uniform_element gl_Fog_elements[] = { }; static const struct gl_builtin_uniform_element gl_NormalScale_elements[] = { - {NULL, {STATE_NORMAL_SCALE}, SWIZZLE_XXXX}, + {NULL, {STATE_NORMAL_SCALE_EYESPACE}, SWIZZLE_XXXX}, }; static const struct gl_builtin_uniform_element gl_FogParamsOptimizedMESA_elements[] = { - {NULL, {STATE_INTERNAL, STATE_FOG_PARAMS_OPTIMIZED}, SWIZZLE_XYZW}, + {NULL, {STATE_FOG_PARAMS_OPTIMIZED}, SWIZZLE_XYZW}, }; static const struct gl_builtin_uniform_element gl_CurrentAttribVertMESA_elements[] = { - {NULL, {STATE_INTERNAL, STATE_CURRENT_ATTRIB, 0}, SWIZZLE_XYZW}, + {NULL, {STATE_CURRENT_ATTRIB, 0}, SWIZZLE_XYZW}, }; static const struct gl_builtin_uniform_element gl_CurrentAttribFragMESA_elements[] = { - {NULL, {STATE_INTERNAL, STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED, 0}, SWIZZLE_XYZW}, + {NULL, {STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED, 0}, SWIZZLE_XYZW}, }; #define MATRIX(name, statevar) \ @@ -618,14 +618,8 @@ builtin_variable_generator::add_uniform(const glsl_type *type, &statevar->elements[j]; memcpy(slots->tokens, element->tokens, sizeof(element->tokens)); - if (type->is_array()) { - if (strcmp(name, "gl_CurrentAttribVertMESA") == 0 || - strcmp(name, "gl_CurrentAttribFragMESA") == 0) { - slots->tokens[2] = a; - } else { - slots->tokens[1] = a; - } - } + if (type->is_array()) + slots->tokens[1] = a; slots->swizzle = element->swizzle; slots++; diff --git a/src/compiler/glsl/lower_blend_equation_advanced.cpp b/src/compiler/glsl/lower_blend_equation_advanced.cpp index 76d4c8b7be4..5ea4222b592 100644 --- a/src/compiler/glsl/lower_blend_equation_advanced.cpp +++ b/src/compiler/glsl/lower_blend_equation_advanced.cpp @@ -489,9 +489,8 @@ lower_blend_equation_advanced(struct gl_linked_shader *sh, bool coherent) mode->allocate_state_slots(1); ir_state_slot *slot0 = &mode->get_state_slots()[0]; slot0->swizzle = SWIZZLE_XXXX; - slot0->tokens[0] = STATE_INTERNAL; - slot0->tokens[1] = STATE_ADVANCED_BLENDING_MODE; - for (int i = 2; i < STATE_LENGTH; i++) + slot0->tokens[0] = STATE_ADVANCED_BLENDING_MODE; + for (int i = 1; i < STATE_LENGTH; i++) slot0->tokens[i] = 0; sh->ir->push_head(fb); diff --git a/src/gallium/drivers/d3d12/d3d12_lower_point_sprite.c b/src/gallium/drivers/d3d12/d3d12_lower_point_sprite.c index 79fa759e2cb..4212d4169a5 100644 --- a/src/gallium/drivers/d3d12/d3d12_lower_point_sprite.c +++ b/src/gallium/drivers/d3d12/d3d12_lower_point_sprite.c @@ -231,8 +231,7 @@ d3d12_lower_point_sprite(nir_shader *shader, unsigned point_coord_enable, uint64_t next_inputs_read) { - const gl_state_index16 tokens[4] = { STATE_INTERNAL, - STATE_INTERNAL_DRIVER, + const gl_state_index16 tokens[4] = { STATE_INTERNAL_DRIVER, D3D12_STATE_VAR_PT_SPRITE }; struct lower_state state; bool progress = false; diff --git a/src/gallium/drivers/d3d12/d3d12_nir_passes.c b/src/gallium/drivers/d3d12/d3d12_nir_passes.c index 2686926eb97..4866e0eaaab 100644 --- a/src/gallium/drivers/d3d12/d3d12_nir_passes.c +++ b/src/gallium/drivers/d3d12/d3d12_nir_passes.c @@ -43,7 +43,7 @@ get_state_var(nir_builder *b, const struct glsl_type *var_type, nir_variable **out_var) { - const gl_state_index16 tokens[STATE_LENGTH] = { STATE_INTERNAL, STATE_INTERNAL_DRIVER, var_enum }; + const gl_state_index16 tokens[STATE_LENGTH] = { STATE_INTERNAL_DRIVER, var_enum }; if (*out_var == NULL) { nir_variable *var = nir_variable_create(b->shader, nir_var_uniform, @@ -432,10 +432,10 @@ lower_instr(nir_intrinsic_instr *instr, nir_builder *b, if (variable == NULL || variable->num_state_slots != 1 || - variable->state_slots[0].tokens[1] != STATE_INTERNAL_DRIVER) + variable->state_slots[0].tokens[0] != STATE_INTERNAL_DRIVER) return false; - enum d3d12_state_var var = variable->state_slots[0].tokens[2]; + enum d3d12_state_var var = variable->state_slots[0].tokens[1]; nir_ssa_def *ubo_idx = nir_imm_int(b, binding); nir_ssa_def *ubo_offset = nir_imm_int(b, get_state_var_offset(shader, var) * 4); nir_ssa_def *load = @@ -476,7 +476,7 @@ d3d12_lower_state_vars(nir_shader *nir, struct d3d12_shader *shader) nir_foreach_variable_with_modes_safe(var, nir, nir_var_uniform) { if (var->num_state_slots == 1 && - var->state_slots[0].tokens[1] == STATE_INTERNAL_DRIVER) { + var->state_slots[0].tokens[0] == STATE_INTERNAL_DRIVER) { if (var->data.mode == nir_var_mem_ubo) { binding = var->data.binding; } @@ -510,13 +510,13 @@ d3d12_lower_state_vars(nir_shader *nir, struct d3d12_shader *shader) /* Remove state variables */ nir_foreach_variable_with_modes_safe(var, nir, nir_var_uniform) { if (var->num_state_slots == 1 && - var->state_slots[0].tokens[1] == STATE_INTERNAL_DRIVER) { + var->state_slots[0].tokens[0] == STATE_INTERNAL_DRIVER) { exec_node_remove(&var->node); nir->num_uniforms--; } } - const gl_state_index16 tokens[STATE_LENGTH] = { STATE_INTERNAL, STATE_INTERNAL_DRIVER }; + const gl_state_index16 tokens[STATE_LENGTH] = { STATE_INTERNAL_DRIVER }; const struct glsl_type *type = glsl_array_type(glsl_vec4_type(), shader->state_vars_size / 4, 0); nir_variable *ubo = nir_variable_create(nir, nir_var_mem_ubo, type, diff --git a/src/mesa/drivers/dri/i965/brw_program.c b/src/mesa/drivers/dri/i965/brw_program.c index 71606b9f845..2c5d53d9d51 100644 --- a/src/mesa/drivers/dri/i965/brw_program.c +++ b/src/mesa/drivers/dri/i965/brw_program.c @@ -129,7 +129,7 @@ brw_create_nir(struct brw_context *brw, if (stage == MESA_SHADER_TESS_CTRL) { /* Lower gl_PatchVerticesIn from a sys. value to a uniform on Gen8+. */ static const gl_state_index16 tokens[STATE_LENGTH] = - { STATE_INTERNAL, STATE_TCS_PATCH_VERTICES_IN }; + { STATE_TCS_PATCH_VERTICES_IN }; nir_lower_patch_vertices(nir, 0, devinfo->gen >= 8 ? tokens : NULL); } @@ -142,13 +142,13 @@ brw_create_nir(struct brw_context *brw, uint32_t static_patch_vertices = tcs ? tcs->Program->nir->info.tess.tcs_vertices_out : 0; static const gl_state_index16 tokens[STATE_LENGTH] = - { STATE_INTERNAL, STATE_TES_PATCH_VERTICES_IN }; + { STATE_TES_PATCH_VERTICES_IN }; nir_lower_patch_vertices(nir, static_patch_vertices, tokens); } if (stage == MESA_SHADER_FRAGMENT) { static const struct nir_lower_wpos_ytransform_options wpos_options = { - .state_tokens = {STATE_INTERNAL, STATE_FB_WPOS_Y_TRANSFORM, 0, 0}, + .state_tokens = {STATE_FB_WPOS_Y_TRANSFORM, 0, 0}, .fs_coord_pixel_center_integer = 1, .fs_coord_origin_upper_left = 1, }; diff --git a/src/mesa/main/ffvertex_prog.c b/src/mesa/main/ffvertex_prog.c index 66fe688de3c..9158a3595e9 100644 --- a/src/mesa/main/ffvertex_prog.c +++ b/src/mesa/main/ffvertex_prog.c @@ -443,7 +443,7 @@ static struct ureg register_input( struct tnl_program *p, GLuint input ) return make_ureg(PROGRAM_INPUT, input); } else { - return register_param3( p, STATE_INTERNAL, STATE_CURRENT_ATTRIB, input ); + return register_param2(p, STATE_CURRENT_ATTRIB, input); } } @@ -797,8 +797,7 @@ static struct ureg get_transformed_normal( struct tnl_program *p ) else if (p->state->need_eye_coords == p->state->rescale_normals) { /* This is already adjusted for eye/non-eye rendering: */ - struct ureg rescale = register_param2(p, STATE_INTERNAL, - STATE_NORMAL_SCALE); + struct ureg rescale = register_param1(p, STATE_NORMAL_SCALE); emit_op2( p, OPCODE_MUL, transformed_normal, 0, normal, rescale ); normal = transformed_normal; @@ -947,8 +946,7 @@ static struct ureg calculate_light_attenuation( struct tnl_program *p, /* Calculate spot attenuation: */ if (!p->state->unit[i].light_spotcutoff_is_180) { - struct ureg spot_dir_norm = register_param3(p, STATE_INTERNAL, - STATE_LIGHT_SPOT_DIR_NORMALIZED, i); + struct ureg spot_dir_norm = register_param2(p, STATE_LIGHT_SPOT_DIR_NORMALIZED, i); struct ureg spot = get_temp(p); struct ureg slt = get_temp(p); @@ -1117,11 +1115,9 @@ static void build_lighting( struct tnl_program *p ) count++; if (p->state->unit[i].light_eyepos3_is_zero) { - VPpli = register_param3(p, STATE_INTERNAL, - STATE_LIGHT_POSITION_NORMALIZED, i); + VPpli = register_param2(p, STATE_LIGHT_POSITION_NORMALIZED, i); } else { - struct ureg Ppli = register_param3(p, STATE_INTERNAL, - STATE_LIGHT_POSITION, i); + struct ureg Ppli = register_param2(p, STATE_LIGHT_POSITION, i); struct ureg V = get_eye_position(p); VPpli = get_temp(p); @@ -1153,8 +1149,7 @@ static void build_lighting( struct tnl_program *p ) emit_op2(p, OPCODE_SUB, half, 0, VPpli, eye_hat); emit_normalize_vec3(p, half, half); } else if (p->state->unit[i].light_eyepos3_is_zero) { - half = register_param3(p, STATE_INTERNAL, - STATE_LIGHT_HALF_VECTOR, i); + half = register_param2(p, STATE_LIGHT_HALF_VECTOR, i); } else { struct ureg z_dir = swizzle(get_identity_param(p),X,Y,W,Z); half = get_temp(p); @@ -1521,7 +1516,7 @@ static void build_texture_transform( struct tnl_program *p ) static void build_atten_pointsize( struct tnl_program *p ) { struct ureg eye = get_eye_position_z(p); - struct ureg state_size = register_param2(p, STATE_INTERNAL, STATE_POINT_SIZE_CLAMPED); + struct ureg state_size = register_param1(p, STATE_POINT_SIZE_CLAMPED); struct ureg state_attenuation = register_param1(p, STATE_POINT_ATTENUATION); struct ureg out = register_output(p, VARYING_SLOT_PSIZ); struct ureg ut = get_temp(p); diff --git a/src/mesa/program/prog_statevars.c b/src/mesa/program/prog_statevars.c index 52514361494..790e79238a5 100644 --- a/src/mesa/program/prog_statevars.c +++ b/src/mesa/program/prog_statevars.c @@ -472,226 +472,217 @@ fetch_state(struct gl_context *ctx, const gl_state_index16 state[], } return; - case STATE_NORMAL_SCALE: + case STATE_NORMAL_SCALE_EYESPACE: ASSIGN_4V(value, ctx->_ModelViewInvScaleEyespace, 0, 0, 1); return; - case STATE_INTERNAL: - switch (state[1]) { - case STATE_CURRENT_ATTRIB: - { - const GLuint idx = (GLuint) state[2]; - COPY_4V(value, ctx->Current.Attrib[idx]); - } - return; - - case STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED: - { - const GLuint idx = (GLuint) state[2]; - if(ctx->Light._ClampVertexColor && - (idx == VERT_ATTRIB_COLOR0 || - idx == VERT_ATTRIB_COLOR1)) { - value[0] = SATURATE(ctx->Current.Attrib[idx][0]); - value[1] = SATURATE(ctx->Current.Attrib[idx][1]); - value[2] = SATURATE(ctx->Current.Attrib[idx][2]); - value[3] = SATURATE(ctx->Current.Attrib[idx][3]); - } - else - COPY_4V(value, ctx->Current.Attrib[idx]); - } - return; - - case STATE_NORMAL_SCALE: - ASSIGN_4V(value, - ctx->_ModelViewInvScale, - ctx->_ModelViewInvScale, - ctx->_ModelViewInvScale, - 1); - return; - - case STATE_FOG_PARAMS_OPTIMIZED: { - /* for simpler per-vertex/pixel fog calcs. POW (for EXP/EXP2 fog) - * might be more expensive than EX2 on some hw, plus it needs - * another constant (e) anyway. Linear fog can now be done with a - * single MAD. - * linear: fogcoord * -1/(end-start) + end/(end-start) - * exp: 2^-(density/ln(2) * fogcoord) - * exp2: 2^-((density/(sqrt(ln(2))) * fogcoord)^2) - */ - float val = (ctx->Fog.End == ctx->Fog.Start) - ? 1.0f : (GLfloat)(-1.0F / (ctx->Fog.End - ctx->Fog.Start)); - value[0] = val; - value[1] = ctx->Fog.End * -val; - value[2] = (GLfloat)(ctx->Fog.Density * M_LOG2E); /* M_LOG2E == 1/ln(2) */ - value[3] = (GLfloat)(ctx->Fog.Density * ONE_DIV_SQRT_LN2); - return; + case STATE_CURRENT_ATTRIB: + { + const GLuint idx = (GLuint) state[1]; + COPY_4V(value, ctx->Current.Attrib[idx]); } + return; - case STATE_POINT_SIZE_CLAMPED: - { - /* this includes implementation dependent limits, to avoid - * another potentially necessary clamp. - * Note: for sprites, point smooth (point AA) is ignored - * and we'll clamp to MinPointSizeAA and MaxPointSize, because we - * expect drivers will want to say their minimum for AA size is 0.0 - * but for non-AA it's 1.0 (because normal points with size below 1.0 - * need to get rounded up to 1.0, hence never disappear). GL does - * not specify max clamp size for sprites, other than it needs to be - * at least as large as max AA size, hence use non-AA size there. - */ - GLfloat minImplSize; - GLfloat maxImplSize; - if (ctx->Point.PointSprite) { - minImplSize = ctx->Const.MinPointSizeAA; - maxImplSize = ctx->Const.MaxPointSize; - } - else if (ctx->Point.SmoothFlag || _mesa_is_multisample_enabled(ctx)) { - minImplSize = ctx->Const.MinPointSizeAA; - maxImplSize = ctx->Const.MaxPointSizeAA; - } - else { - minImplSize = ctx->Const.MinPointSize; - maxImplSize = ctx->Const.MaxPointSize; - } - value[0] = ctx->Point.Size; - value[1] = ctx->Point.MinSize >= minImplSize ? ctx->Point.MinSize : minImplSize; - value[2] = ctx->Point.MaxSize <= maxImplSize ? ctx->Point.MaxSize : maxImplSize; - value[3] = ctx->Point.Threshold; + case STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED: + { + const GLuint idx = (GLuint) state[1]; + if(ctx->Light._ClampVertexColor && + (idx == VERT_ATTRIB_COLOR0 || + idx == VERT_ATTRIB_COLOR1)) { + value[0] = SATURATE(ctx->Current.Attrib[idx][0]); + value[1] = SATURATE(ctx->Current.Attrib[idx][1]); + value[2] = SATURATE(ctx->Current.Attrib[idx][2]); + value[3] = SATURATE(ctx->Current.Attrib[idx][3]); } - return; - case STATE_LIGHT_SPOT_DIR_NORMALIZED: - { - /* here, state[2] is the light number */ - /* pre-normalize spot dir */ - const GLuint ln = (GLuint) state[2]; - COPY_3V(value, ctx->Light.Light[ln]._NormSpotDirection); - value[3] = ctx->Light.LightSource[ln]._CosCutoff; + else + COPY_4V(value, ctx->Current.Attrib[idx]); + } + return; + + case STATE_NORMAL_SCALE: + ASSIGN_4V(value, + ctx->_ModelViewInvScale, + ctx->_ModelViewInvScale, + ctx->_ModelViewInvScale, + 1); + return; + + case STATE_FOG_PARAMS_OPTIMIZED: { + /* for simpler per-vertex/pixel fog calcs. POW (for EXP/EXP2 fog) + * might be more expensive than EX2 on some hw, plus it needs + * another constant (e) anyway. Linear fog can now be done with a + * single MAD. + * linear: fogcoord * -1/(end-start) + end/(end-start) + * exp: 2^-(density/ln(2) * fogcoord) + * exp2: 2^-((density/(sqrt(ln(2))) * fogcoord)^2) + */ + float val = (ctx->Fog.End == ctx->Fog.Start) + ? 1.0f : (GLfloat)(-1.0F / (ctx->Fog.End - ctx->Fog.Start)); + value[0] = val; + value[1] = ctx->Fog.End * -val; + value[2] = (GLfloat)(ctx->Fog.Density * M_LOG2E); /* M_LOG2E == 1/ln(2) */ + value[3] = (GLfloat)(ctx->Fog.Density * ONE_DIV_SQRT_LN2); + return; + } + + case STATE_POINT_SIZE_CLAMPED: + { + /* this includes implementation dependent limits, to avoid + * another potentially necessary clamp. + * Note: for sprites, point smooth (point AA) is ignored + * and we'll clamp to MinPointSizeAA and MaxPointSize, because we + * expect drivers will want to say their minimum for AA size is 0.0 + * but for non-AA it's 1.0 (because normal points with size below 1.0 + * need to get rounded up to 1.0, hence never disappear). GL does + * not specify max clamp size for sprites, other than it needs to be + * at least as large as max AA size, hence use non-AA size there. + */ + GLfloat minImplSize; + GLfloat maxImplSize; + if (ctx->Point.PointSprite) { + minImplSize = ctx->Const.MinPointSizeAA; + maxImplSize = ctx->Const.MaxPointSize; } - return; - - case STATE_LIGHT_POSITION: - { - const GLuint ln = (GLuint) state[2]; - COPY_4V(value, ctx->Light.Light[ln]._Position); + else if (ctx->Point.SmoothFlag || _mesa_is_multisample_enabled(ctx)) { + minImplSize = ctx->Const.MinPointSizeAA; + maxImplSize = ctx->Const.MaxPointSizeAA; } - return; - - case STATE_LIGHT_POSITION_NORMALIZED: - { - const GLuint ln = (GLuint) state[2]; - float p[4]; - COPY_4V(p, ctx->Light.Light[ln]._Position); - NORMALIZE_3FV(p); - COPY_4V(value, p); + else { + minImplSize = ctx->Const.MinPointSize; + maxImplSize = ctx->Const.MaxPointSize; } - return; + value[0] = ctx->Point.Size; + value[1] = ctx->Point.MinSize >= minImplSize ? ctx->Point.MinSize : minImplSize; + value[2] = ctx->Point.MaxSize <= maxImplSize ? ctx->Point.MaxSize : maxImplSize; + value[3] = ctx->Point.Threshold; + } + return; + case STATE_LIGHT_SPOT_DIR_NORMALIZED: + { + /* here, state[1] is the light number */ + /* pre-normalize spot dir */ + const GLuint ln = (GLuint) state[1]; + COPY_3V(value, ctx->Light.Light[ln]._NormSpotDirection); + value[3] = ctx->Light.LightSource[ln]._CosCutoff; + } + return; - case STATE_LIGHT_HALF_VECTOR: - { - const GLuint ln = (GLuint) state[2]; - GLfloat p[3]; - /* Compute infinite half angle vector: - * halfVector = normalize(normalize(lightPos) + (0, 0, 1)) - * light.EyePosition.w should be 0 for infinite lights. - */ - COPY_3V(p, ctx->Light.Light[ln]._Position); - NORMALIZE_3FV(p); - ADD_3V(p, p, ctx->_EyeZDir); - NORMALIZE_3FV(p); - COPY_3V(value, p); - value[3] = 1.0; - } - return; + case STATE_LIGHT_POSITION: + { + const GLuint ln = (GLuint) state[1]; + COPY_4V(value, ctx->Light.Light[ln]._Position); + } + return; - case STATE_PT_SCALE: - value[0] = ctx->Pixel.RedScale; - value[1] = ctx->Pixel.GreenScale; - value[2] = ctx->Pixel.BlueScale; - value[3] = ctx->Pixel.AlphaScale; - return; + case STATE_LIGHT_POSITION_NORMALIZED: + { + const GLuint ln = (GLuint) state[1]; + float p[4]; + COPY_4V(p, ctx->Light.Light[ln]._Position); + NORMALIZE_3FV(p); + COPY_4V(value, p); + } + return; - case STATE_PT_BIAS: - value[0] = ctx->Pixel.RedBias; - value[1] = ctx->Pixel.GreenBias; - value[2] = ctx->Pixel.BlueBias; - value[3] = ctx->Pixel.AlphaBias; - return; + case STATE_LIGHT_HALF_VECTOR: + { + const GLuint ln = (GLuint) state[1]; + GLfloat p[3]; + /* Compute infinite half angle vector: + * halfVector = normalize(normalize(lightPos) + (0, 0, 1)) + * light.EyePosition.w should be 0 for infinite lights. + */ + COPY_3V(p, ctx->Light.Light[ln]._Position); + NORMALIZE_3FV(p); + ADD_3V(p, p, ctx->_EyeZDir); + NORMALIZE_3FV(p); + COPY_3V(value, p); + value[3] = 1.0; + } + return; - case STATE_FB_SIZE: - value[0] = (GLfloat) (ctx->DrawBuffer->Width - 1); - value[1] = (GLfloat) (ctx->DrawBuffer->Height - 1); + case STATE_PT_SCALE: + value[0] = ctx->Pixel.RedScale; + value[1] = ctx->Pixel.GreenScale; + value[2] = ctx->Pixel.BlueScale; + value[3] = ctx->Pixel.AlphaScale; + return; + + case STATE_PT_BIAS: + value[0] = ctx->Pixel.RedBias; + value[1] = ctx->Pixel.GreenBias; + value[2] = ctx->Pixel.BlueBias; + value[3] = ctx->Pixel.AlphaBias; + return; + + case STATE_FB_SIZE: + value[0] = (GLfloat) (ctx->DrawBuffer->Width - 1); + value[1] = (GLfloat) (ctx->DrawBuffer->Height - 1); + value[2] = 0.0F; + value[3] = 0.0F; + return; + + case STATE_FB_WPOS_Y_TRANSFORM: + /* A driver may negate this conditional by using ZW swizzle + * instead of XY (based on e.g. some other state). */ + if (!ctx->DrawBuffer->FlipY) { + /* Identity (XY) followed by flipping Y upside down (ZW). */ + value[0] = 1.0F; + value[1] = 0.0F; + value[2] = -1.0F; + value[3] = _mesa_geometric_height(ctx->DrawBuffer); + } else { + /* Flipping Y upside down (XY) followed by identity (ZW). */ + value[0] = -1.0F; + value[1] = _mesa_geometric_height(ctx->DrawBuffer); + value[2] = 1.0F; + value[3] = 0.0F; + } + return; + + case STATE_FB_PNTC_Y_TRANSFORM: + { + bool flip_y = (ctx->Point.SpriteOrigin == GL_LOWER_LEFT) ^ + (ctx->DrawBuffer->FlipY); + + value[0] = flip_y ? -1.0F : 1.0F; + value[1] = flip_y ? 1.0F : 0.0F; value[2] = 0.0F; value[3] = 0.0F; - return; - - case STATE_FB_WPOS_Y_TRANSFORM: - /* A driver may negate this conditional by using ZW swizzle - * instead of XY (based on e.g. some other state). */ - if (!ctx->DrawBuffer->FlipY) { - /* Identity (XY) followed by flipping Y upside down (ZW). */ - value[0] = 1.0F; - value[1] = 0.0F; - value[2] = -1.0F; - value[3] = _mesa_geometric_height(ctx->DrawBuffer); - } else { - /* Flipping Y upside down (XY) followed by identity (ZW). */ - value[0] = -1.0F; - value[1] = _mesa_geometric_height(ctx->DrawBuffer); - value[2] = 1.0F; - value[3] = 0.0F; - } - return; - - case STATE_FB_PNTC_Y_TRANSFORM: - { - bool flip_y = (ctx->Point.SpriteOrigin == GL_LOWER_LEFT) ^ - (ctx->DrawBuffer->FlipY); - - value[0] = flip_y ? -1.0F : 1.0F; - value[1] = flip_y ? 1.0F : 0.0F; - value[2] = 0.0F; - value[3] = 0.0F; - } - return; - - case STATE_TCS_PATCH_VERTICES_IN: - val[0].i = ctx->TessCtrlProgram.patch_vertices; - return; - - case STATE_TES_PATCH_VERTICES_IN: - if (ctx->TessCtrlProgram._Current) - val[0].i = ctx->TessCtrlProgram._Current->info.tess.tcs_vertices_out; - else - val[0].i = ctx->TessCtrlProgram.patch_vertices; - return; - - case STATE_ADVANCED_BLENDING_MODE: - val[0].i = _mesa_get_advanced_blend_sh_constant( - ctx->Color.BlendEnabled, ctx->Color._AdvancedBlendMode); - return; - - case STATE_ALPHA_REF: - value[0] = ctx->Color.AlphaRefUnclamped; - return; - - case STATE_CLIP_INTERNAL: - { - const GLuint plane = (GLuint) state[2]; - COPY_4V(value, ctx->Transform._ClipUserPlane[plane]); - } - return; - - /* XXX: make sure new tokens added here are also handled in the - * _mesa_program_state_flags() switch, below. - */ - default: - /* Unknown state indexes are silently ignored here. - * Drivers may do something special. - */ - return; } return; + case STATE_TCS_PATCH_VERTICES_IN: + val[0].i = ctx->TessCtrlProgram.patch_vertices; + return; + + case STATE_TES_PATCH_VERTICES_IN: + if (ctx->TessCtrlProgram._Current) + val[0].i = ctx->TessCtrlProgram._Current->info.tess.tcs_vertices_out; + else + val[0].i = ctx->TessCtrlProgram.patch_vertices; + return; + + case STATE_ADVANCED_BLENDING_MODE: + val[0].i = _mesa_get_advanced_blend_sh_constant( + ctx->Color.BlendEnabled, ctx->Color._AdvancedBlendMode); + return; + + case STATE_ALPHA_REF: + value[0] = ctx->Color.AlphaRefUnclamped; + return; + + case STATE_CLIP_INTERNAL: + { + const GLuint plane = (GLuint) state[1]; + COPY_4V(value, ctx->Transform._ClipUserPlane[plane]); + } + return; + + case STATE_INTERNAL_DRIVER: + /* Internal driver state */ + return; + case STATE_NOT_STATE_VAR: /* Most likely PROGRAM_CONSTANT. This only happens in rare cases, e.g. * ARB_vp with ARL, which can't sort parameters by type. @@ -789,55 +780,49 @@ _mesa_program_state_flags(const gl_state_index16 state[STATE_LENGTH]) case STATE_VERTEX_PROGRAM: return _NEW_PROGRAM; + case STATE_NORMAL_SCALE_EYESPACE: + return _NEW_MODELVIEW; + + case STATE_CURRENT_ATTRIB: + return _NEW_CURRENT_ATTRIB; + case STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED: + return _NEW_CURRENT_ATTRIB | _NEW_LIGHT | _NEW_BUFFERS; + case STATE_NORMAL_SCALE: return _NEW_MODELVIEW; - case STATE_INTERNAL: - switch (state[1]) { - case STATE_CURRENT_ATTRIB: - return _NEW_CURRENT_ATTRIB; - case STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED: - return _NEW_CURRENT_ATTRIB | _NEW_LIGHT | _NEW_BUFFERS; + case STATE_FOG_PARAMS_OPTIMIZED: + return _NEW_FOG; + case STATE_POINT_SIZE_CLAMPED: + return _NEW_POINT | _NEW_MULTISAMPLE; + case STATE_LIGHT_SPOT_DIR_NORMALIZED: + case STATE_LIGHT_POSITION: + case STATE_LIGHT_POSITION_NORMALIZED: + case STATE_LIGHT_HALF_VECTOR: + return _NEW_LIGHT; - case STATE_NORMAL_SCALE: - return _NEW_MODELVIEW; + case STATE_PT_SCALE: + case STATE_PT_BIAS: + return _NEW_PIXEL; - case STATE_FOG_PARAMS_OPTIMIZED: - return _NEW_FOG; - case STATE_POINT_SIZE_CLAMPED: - return _NEW_POINT | _NEW_MULTISAMPLE; - case STATE_LIGHT_SPOT_DIR_NORMALIZED: - case STATE_LIGHT_POSITION: - case STATE_LIGHT_POSITION_NORMALIZED: - case STATE_LIGHT_HALF_VECTOR: - return _NEW_LIGHT; + case STATE_FB_SIZE: + case STATE_FB_WPOS_Y_TRANSFORM: + return _NEW_BUFFERS; - case STATE_PT_SCALE: - case STATE_PT_BIAS: - return _NEW_PIXEL; + case STATE_FB_PNTC_Y_TRANSFORM: + return _NEW_BUFFERS | _NEW_POINT; - case STATE_FB_SIZE: - case STATE_FB_WPOS_Y_TRANSFORM: - return _NEW_BUFFERS; + case STATE_ADVANCED_BLENDING_MODE: + return _NEW_COLOR; - case STATE_FB_PNTC_Y_TRANSFORM: - return _NEW_BUFFERS | _NEW_POINT; + case STATE_ALPHA_REF: + return _NEW_COLOR; - case STATE_ADVANCED_BLENDING_MODE: - return _NEW_COLOR; + case STATE_CLIP_INTERNAL: + return _NEW_TRANSFORM | _NEW_PROJECTION; - case STATE_ALPHA_REF: - return _NEW_COLOR; - - case STATE_CLIP_INTERNAL: - return _NEW_TRANSFORM | _NEW_PROJECTION; - - default: - /* unknown state indexes are silently ignored and - * no flag set, since it is handled by the driver. - */ - return 0; - } + case STATE_INTERNAL_DRIVER: + return 0; /* internal driver state */ case STATE_NOT_STATE_VAR: return 0; @@ -1035,16 +1020,15 @@ append_token(char *dst, gl_state_index k) case STATE_LOCAL: append(dst, "local"); break; - /* BEGIN internal state vars */ - case STATE_INTERNAL: - append(dst, "internal."); - break; case STATE_CURRENT_ATTRIB: append(dst, "current"); break; case STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED: append(dst, "currentAttribMaybeVPClamped"); break; + case STATE_NORMAL_SCALE_EYESPACE: + append(dst, "normalScaleEyeSpace"); + break; case STATE_NORMAL_SCALE: append(dst, "normalScale"); break; @@ -1226,14 +1210,29 @@ _mesa_program_state_string(const gl_state_index16 state[STATE_LENGTH]) append_token(str, state[1]); append_index(str, state[2], false); break; - case STATE_NORMAL_SCALE: + case STATE_NORMAL_SCALE_EYESPACE: + break; + case STATE_CURRENT_ATTRIB: + case STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED: + case STATE_LIGHT_SPOT_DIR_NORMALIZED: + case STATE_LIGHT_POSITION: + case STATE_LIGHT_POSITION_NORMALIZED: + case STATE_LIGHT_HALF_VECTOR: + case STATE_CLIP_INTERNAL: + append_index(str, state[1], false); + break; + case STATE_NORMAL_SCALE: + case STATE_FOG_PARAMS_OPTIMIZED: + case STATE_POINT_SIZE_CLAMPED: + case STATE_PT_SCALE: + case STATE_PT_BIAS: + case STATE_FB_SIZE: + case STATE_FB_WPOS_Y_TRANSFORM: + case STATE_TCS_PATCH_VERTICES_IN: + case STATE_TES_PATCH_VERTICES_IN: + case STATE_ADVANCED_BLENDING_MODE: + case STATE_ALPHA_REF: break; - case STATE_INTERNAL: - append_token(str, state[1]); - if (state[1] == STATE_CURRENT_ATTRIB || - state[1] == STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED) - append_index(str, state[2], false); - break; case STATE_NOT_STATE_VAR: append(str, "not_state"); break; diff --git a/src/mesa/program/prog_statevars.h b/src/mesa/program/prog_statevars.h index 4e45382d019..a490c8679ae 100644 --- a/src/mesa/program/prog_statevars.h +++ b/src/mesa/program/prog_statevars.h @@ -132,10 +132,10 @@ typedef enum gl_state_index_ { STATE_ENV, STATE_LOCAL, - STATE_INTERNAL, /* Mesa additions */ STATE_CURRENT_ATTRIB, /* ctx->Current vertex attrib value */ STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED, /* ctx->Current vertex attrib value after passthrough vertex processing */ STATE_NORMAL_SCALE, + STATE_NORMAL_SCALE_EYESPACE, STATE_FOG_PARAMS_OPTIMIZED, /* for faster fog calc */ STATE_POINT_SIZE_CLAMPED, /* includes implementation dependent size clamp */ STATE_LIGHT_SPOT_DIR_NORMALIZED, /* pre-normalized spot dir */ @@ -156,6 +156,7 @@ typedef enum gl_state_index_ { STATE_ADVANCED_BLENDING_MODE, STATE_ALPHA_REF, /* alpha-test reference value */ STATE_CLIP_INTERNAL, /* similar to STATE_CLIPPLANE, but in clip-space */ + STATE_INTERNAL_DRIVER /* first available state index for drivers (must be last) */ } gl_state_index; diff --git a/src/mesa/program/programopt.c b/src/mesa/program/programopt.c index 71d53eea65f..1429bd4f869 100644 --- a/src/mesa/program/programopt.c +++ b/src/mesa/program/programopt.c @@ -248,7 +248,7 @@ _mesa_append_fog_code(struct gl_context *ctx, struct gl_program *fprog, GLenum fog_mode, GLboolean saturate) { static const gl_state_index16 fogPStateOpt[STATE_LENGTH] - = { STATE_INTERNAL, STATE_FOG_PARAMS_OPTIMIZED, 0, 0 }; + = { STATE_FOG_PARAMS_OPTIMIZED, 0, 0 }; static const gl_state_index16 fogColorState[STATE_LENGTH] = { STATE_FOG_COLOR, 0, 0, 0 }; struct prog_instruction *newInst, *inst; diff --git a/src/mesa/state_tracker/st_atifs_to_nir.c b/src/mesa/state_tracker/st_atifs_to_nir.c index df33b1dc041..34431e6a58b 100644 --- a/src/mesa/state_tracker/st_atifs_to_nir.c +++ b/src/mesa/state_tracker/st_atifs_to_nir.c @@ -540,7 +540,7 @@ st_init_atifs_prog(struct gl_context *ctx, struct gl_program *prog) unsigned pass, i, r, optype, arg; static const gl_state_index16 fog_params_state[STATE_LENGTH] = - {STATE_INTERNAL, STATE_FOG_PARAMS_OPTIMIZED, 0, 0}; + {STATE_FOG_PARAMS_OPTIMIZED, 0, 0}; static const gl_state_index16 fog_color[STATE_LENGTH] = {STATE_FOG_COLOR, 0, 0, 0}; diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp index 82dede29167..ee31428a3d3 100644 --- a/src/mesa/state_tracker/st_glsl_to_nir.cpp +++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp @@ -668,7 +668,7 @@ st_nir_lower_wpos_ytransform(struct nir_shader *nir, return; static const gl_state_index16 wposTransformState[STATE_LENGTH] = { - STATE_INTERNAL, STATE_FB_WPOS_Y_TRANSFORM + STATE_FB_WPOS_Y_TRANSFORM }; nir_lower_wpos_ytransform_options wpos_options = { { 0 } }; @@ -693,7 +693,7 @@ st_nir_lower_wpos_ytransform(struct nir_shader *nir, } static const gl_state_index16 pntcTransformState[STATE_LENGTH] = { - STATE_INTERNAL, STATE_FB_PNTC_Y_TRANSFORM + STATE_FB_PNTC_Y_TRANSFORM }; if (nir_lower_pntc_ytransform(nir, &pntcTransformState)) { diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp index 9e9289b41cb..77534b14736 100644 --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp @@ -1623,7 +1623,7 @@ glsl_to_tgsi_visitor::visit_expression(ir_expression* ir, st_src_reg *op) * It is then multiplied with the source operand of DDY. */ static const gl_state_index16 transform_y_state[STATE_LENGTH] - = { STATE_INTERNAL, STATE_FB_WPOS_Y_TRANSFORM }; + = { STATE_FB_WPOS_Y_TRANSFORM }; unsigned transform_y_index = _mesa_add_state_reference(this->prog->Parameters, @@ -2235,7 +2235,7 @@ glsl_to_tgsi_visitor::visit_expression(ir_expression* ir, st_src_reg *op) case ir_binop_interpolate_at_offset: { /* The y coordinate needs to be flipped for the default fb */ static const gl_state_index16 transform_y_state[STATE_LENGTH] - = { STATE_INTERNAL, STATE_FB_WPOS_Y_TRANSFORM }; + = { STATE_FB_WPOS_Y_TRANSFORM }; unsigned transform_y_index = _mesa_add_state_reference(this->prog->Parameters, @@ -7234,7 +7234,7 @@ get_mesa_program_tgsi(struct gl_context *ctx, prog->info.system_values_read & (1ull << SYSTEM_VALUE_FRAG_COORD) || prog->info.system_values_read & (1ull << SYSTEM_VALUE_SAMPLE_POS))) { static const gl_state_index16 wposTransformState[STATE_LENGTH] = { - STATE_INTERNAL, STATE_FB_WPOS_Y_TRANSFORM + STATE_FB_WPOS_Y_TRANSFORM }; v->wpos_transform_const = _mesa_add_state_reference(prog->Parameters, diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index e85d0f58a61..2a8cf247378 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -716,9 +716,8 @@ lower_ucp(struct st_context *st, clipplane_state[i][0] = STATE_CLIPPLANE; clipplane_state[i][1] = i; } else { - clipplane_state[i][0] = STATE_INTERNAL; - clipplane_state[i][1] = STATE_CLIP_INTERNAL; - clipplane_state[i][2] = i; + clipplane_state[i][0] = STATE_CLIP_INTERNAL; + clipplane_state[i][1] = i; } _mesa_add_state_reference(params, clipplane_state[i]); } @@ -750,7 +749,7 @@ st_create_vp_variant(struct st_context *st, struct pipe_shader_state state = {0}; static const gl_state_index16 point_size_state[STATE_LENGTH] = - { STATE_INTERNAL, STATE_POINT_SIZE_CLAMPED, 0 }; + { STATE_POINT_SIZE_CLAMPED, 0 }; struct gl_program_parameter_list *params = stvp->Base.Parameters; vpv->key = *key; @@ -1229,13 +1228,13 @@ st_create_fp_variant(struct st_context *st, struct pipe_shader_state state = {0}; struct gl_program_parameter_list *params = stfp->Base.Parameters; static const gl_state_index16 texcoord_state[STATE_LENGTH] = - { STATE_INTERNAL, STATE_CURRENT_ATTRIB, VERT_ATTRIB_TEX0 }; + { STATE_CURRENT_ATTRIB, VERT_ATTRIB_TEX0 }; static const gl_state_index16 scale_state[STATE_LENGTH] = - { STATE_INTERNAL, STATE_PT_SCALE }; + { STATE_PT_SCALE }; static const gl_state_index16 bias_state[STATE_LENGTH] = - { STATE_INTERNAL, STATE_PT_BIAS }; + { STATE_PT_BIAS }; static const gl_state_index16 alpha_ref_state[STATE_LENGTH] = - { STATE_INTERNAL, STATE_ALPHA_REF }; + { STATE_ALPHA_REF }; if (!variant) return NULL; @@ -1748,7 +1747,7 @@ st_get_common_variant(struct st_context *st, if (key->lower_point_size) { static const gl_state_index16 point_size_state[STATE_LENGTH] = - { STATE_INTERNAL, STATE_POINT_SIZE_CLAMPED, 0 }; + { STATE_POINT_SIZE_CLAMPED, 0 }; _mesa_add_state_reference(params, point_size_state); NIR_PASS_V(state.ir.nir, nir_lower_point_size_mov, point_size_state);