mesa/cs: Implement MAX_COMPUTE_WORK_GROUP_SIZE constant.

v2: Document that the 3-element array MaxComputeWorkGroupSize is
indexed by dimension.

Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
This commit is contained in:
Paul Berry 2014-01-06 13:31:58 -08:00
parent 47d480e3e4
commit 347dde82e6
8 changed files with 56 additions and 0 deletions

View file

@ -390,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);
@ -530,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()
{
@ -660,6 +680,13 @@ 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_MaxComputeWorkGroupSize",
state->Const.MaxComputeWorkGroupSize[0],
state->Const.MaxComputeWorkGroupSize[1],
state->Const.MaxComputeWorkGroupSize[2]);
}
}

View file

@ -123,6 +123,10 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *_ctx,
this->Const.MaxCombinedAtomicCounters = ctx->Const.MaxCombinedAtomicCounters;
this->Const.MaxAtomicBufferBindings = ctx->Const.MaxAtomicBufferBindings;
/* Compute shader constants */
for (unsigned i = 0; i < Elements(this->Const.MaxComputeWorkGroupSize); i++)
this->Const.MaxComputeWorkGroupSize[i] = ctx->Const.MaxComputeWorkGroupSize[i];
this->current_function = NULL;
this->toplevel_ir = NULL;
this->found_return = false;

View file

@ -250,6 +250,9 @@ struct _mesa_glsl_parse_state {
unsigned MaxFragmentAtomicCounters;
unsigned MaxCombinedAtomicCounters;
unsigned MaxAtomicBufferBindings;
/* ARB_compute_shader */
unsigned MaxComputeWorkGroupSize[3];
} Const;
/**

View file

@ -50,6 +50,9 @@ initialize_context(struct gl_context *ctx, gl_api api)
*/
ctx->Const.GLSLVersion = glsl_version;
ctx->Extensions.ARB_ES3_compatibility = true;
ctx->Const.MaxComputeWorkGroupSize[0] = 1024;
ctx->Const.MaxComputeWorkGroupSize[1] = 1024;
ctx->Const.MaxComputeWorkGroupSize[2] = 64;
ctx->Const.Program[MESA_SHADER_COMPUTE].MaxTextureImageUnits = 16;
ctx->Const.Program[MESA_SHADER_COMPUTE].MaxUniformComponents = 1024;
ctx->Const.Program[MESA_SHADER_COMPUTE].MaxInputComponents = 0; /* not used */

View file

@ -141,6 +141,9 @@ void initialize_context_to_defaults(struct gl_context *ctx, gl_api api)
ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxInputComponents = 32;
ctx->Const.MaxDrawBuffers = 1;
ctx->Const.MaxComputeWorkGroupSize[0] = 1024;
ctx->Const.MaxComputeWorkGroupSize[1] = 1024;
ctx->Const.MaxComputeWorkGroupSize[2] = 64;
ctx->Const.Program[MESA_SHADER_COMPUTE].MaxTextureImageUnits = 16;
ctx->Const.Program[MESA_SHADER_COMPUTE].MaxUniformComponents = 1024;
ctx->Const.Program[MESA_SHADER_COMPUTE].MaxInputComponents = 0; /* not used */

View file

@ -700,6 +700,11 @@ _mesa_init_constants(struct gl_context *ctx)
/* GL_ARB_vertex_attrib_binding */
ctx->Const.MaxVertexAttribRelativeOffset = 2047;
ctx->Const.MaxVertexAttribBindings = MAX_VERTEX_GENERIC_ATTRIBS;
/* GL_ARB_compute_shader */
ctx->Const.MaxComputeWorkGroupSize[0] = 1024;
ctx->Const.MaxComputeWorkGroupSize[1] = 1024;
ctx->Const.MaxComputeWorkGroupSize[2] = 64;
}

View file

@ -1927,6 +1927,14 @@ find_value_indexed(const char *func, GLenum pname, GLuint index, union value *v)
v->value_int = ctx->ImageUnits[index].Format;
return TYPE_INT;
case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
if (!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_compute_shader)
goto invalid_enum;
if (index >= 3)
goto invalid_value;
v->value_int = ctx->Const.MaxComputeWorkGroupSize[index];
return TYPE_INT;
}
invalid_enum:

View file

@ -3378,6 +3378,9 @@ struct gl_constants
GLuint MaxCombinedImageUnitsAndFragmentOutputs;
GLuint MaxImageSamples;
GLuint MaxCombinedImageUniforms;
/** GL_ARB_compute_shader */
GLuint MaxComputeWorkGroupSize[3]; /* Array of x, y, z dimensions */
};