diff options
Diffstat (limited to 'mesalib/src/glsl/builtin_variables.cpp')
-rw-r--r-- | mesalib/src/glsl/builtin_variables.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/mesalib/src/glsl/builtin_variables.cpp b/mesalib/src/glsl/builtin_variables.cpp index d6bc3c073..cc423383d 100644 --- a/mesalib/src/glsl/builtin_variables.cpp +++ b/mesalib/src/glsl/builtin_variables.cpp @@ -356,6 +356,7 @@ public: void generate_vs_special_vars(); void generate_gs_special_vars(); void generate_fs_special_vars(); + void generate_cs_special_vars(); void generate_varyings(); private: @@ -389,6 +390,7 @@ private: enum ir_variable_mode mode, int slot); ir_variable *add_uniform(const glsl_type *type, const char *name); ir_variable *add_const(const char *name, int value); + ir_variable *add_const_ivec3(const char *name, int x, int y, int z); void add_varying(int slot, const glsl_type *type, const char *name, const char *name_as_gs_input); @@ -529,6 +531,25 @@ builtin_variable_generator::add_const(const char *name, int value) } +ir_variable * +builtin_variable_generator::add_const_ivec3(const char *name, int x, int y, + int z) +{ + ir_variable *const var = add_variable(name, glsl_type::ivec3_type, + ir_var_auto, -1); + ir_constant_data data; + memset(&data, 0, sizeof(data)); + data.i[0] = x; + data.i[1] = y; + data.i[2] = z; + var->constant_value = new(var) ir_constant(glsl_type::ivec3_type, &data); + var->constant_initializer = + new(var) ir_constant(glsl_type::ivec3_type, &data); + var->data.has_initializer = true; + return var; +} + + void builtin_variable_generator::generate_constants() { @@ -659,6 +680,37 @@ builtin_variable_generator::generate_constants() add_const("gl_MaxTessControlAtomicCounters", 0); add_const("gl_MaxTessEvaluationAtomicCounters", 0); } + + if (state->is_version(430, 0) || state->ARB_compute_shader_enable) { + add_const_ivec3("gl_MaxComputeWorkGroupCount", + state->Const.MaxComputeWorkGroupCount[0], + state->Const.MaxComputeWorkGroupCount[1], + state->Const.MaxComputeWorkGroupCount[2]); + add_const_ivec3("gl_MaxComputeWorkGroupSize", + state->Const.MaxComputeWorkGroupSize[0], + state->Const.MaxComputeWorkGroupSize[1], + state->Const.MaxComputeWorkGroupSize[2]); + + /* From the GLSL 4.40 spec, section 7.1 (Built-In Language Variables): + * + * The built-in constant gl_WorkGroupSize is a compute-shader + * constant containing the local work-group size of the shader. The + * size of the work group in the X, Y, and Z dimensions is stored in + * the x, y, and z components. The constants values in + * gl_WorkGroupSize will match those specified in the required + * local_size_x, local_size_y, and local_size_z layout qualifiers + * for the current shader. This is a constant so that it can be + * used to size arrays of memory that can be shared within the local + * work group. It is a compile-time error to use gl_WorkGroupSize + * in a shader that does not declare a fixed local group size, or + * before that shader has declared a fixed local group size, using + * local_size_x, local_size_y, and local_size_z. + * + * To prevent the shader from trying to refer to gl_WorkGroupSize before + * the layout declaration, we don't define it here. Intead we define it + * in ast_cs_input_layout::hir(). + */ + } } @@ -868,6 +920,16 @@ builtin_variable_generator::generate_fs_special_vars() /** + * Generate variables which only exist in compute shaders. + */ +void +builtin_variable_generator::generate_cs_special_vars() +{ + /* TODO: finish this. */ +} + + +/** * Add a single "varying" variable. The variable's type and direction (input * or output) are adjusted as appropriate for the type of shader being * compiled. For geometry shaders using {ARB,EXT}_geometry_shader4, @@ -888,6 +950,9 @@ builtin_variable_generator::add_varying(int slot, const glsl_type *type, case MESA_SHADER_FRAGMENT: add_input(slot, type, name); break; + case MESA_SHADER_COMPUTE: + /* Compute shaders don't have varyings. */ + break; } } @@ -975,5 +1040,8 @@ _mesa_glsl_initialize_variables(exec_list *instructions, case MESA_SHADER_FRAGMENT: gen.generate_fs_special_vars(); break; + case MESA_SHADER_COMPUTE: + gen.generate_cs_special_vars(); + break; } } |