st/mesa/glsl/i965: move ImageUnits and ImageAccess fields to gl_program
Having it here rather than in gl_linked_shader allows us to simplify the code. Also it is error prone to depend on the gl_linked_shader for programs in current use because a failed linking attempt will free infomation about the current program. In i965 we could be trying to recompile a shader variant but may have lost some required fields. We drop the memset on ImageUnits because gl_program is already created using rzalloc(). Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
This commit is contained in:
@@ -141,9 +141,10 @@ set_opaque_binding(void *mem_ctx, gl_shader_program *prog,
|
||||
storage->opaque[sh].active) {
|
||||
for (unsigned i = 0; i < elements; i++) {
|
||||
const unsigned index = storage->opaque[sh].index + i;
|
||||
if (index >= ARRAY_SIZE(shader->ImageUnits))
|
||||
if (index >= ARRAY_SIZE(shader->Program->sh.ImageUnits))
|
||||
break;
|
||||
shader->ImageUnits[index] = storage->storage[i].i;
|
||||
shader->Program->sh.ImageUnits[index] =
|
||||
storage->storage[i].i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -613,7 +613,7 @@ private:
|
||||
this->next_image += MAX2(1, uniform->array_elements);
|
||||
|
||||
for (unsigned i = first; i < MIN2(next_image, MAX_IMAGE_UNIFORMS); i++)
|
||||
prog->_LinkedShaders[shader_type]->ImageAccess[i] = access;
|
||||
prog->_LinkedShaders[shader_type]->Program->sh.ImageAccess[i] = access;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1308,7 +1308,6 @@ link_assign_uniform_locations(struct gl_shader_program *prog,
|
||||
* types cannot have initializers."
|
||||
*/
|
||||
memset(sh->SamplerUnits, 0, sizeof(sh->SamplerUnits));
|
||||
memset(sh->ImageUnits, 0, sizeof(sh->ImageUnits));
|
||||
|
||||
link_update_uniform_buffer_variables(sh, i);
|
||||
|
||||
|
@@ -280,7 +280,8 @@ intel_update_state(struct gl_context * ctx, GLuint new_state)
|
||||
|
||||
if (unlikely(shader && shader->Program->info.num_images)) {
|
||||
for (unsigned j = 0; j < shader->Program->info.num_images; j++) {
|
||||
struct gl_image_unit *u = &ctx->ImageUnits[shader->ImageUnits[j]];
|
||||
struct gl_image_unit *u =
|
||||
&ctx->ImageUnits[shader->Program->sh.ImageUnits[j]];
|
||||
tex_obj = intel_texture_object(u->TexObj);
|
||||
|
||||
if (tex_obj && tex_obj->mt) {
|
||||
|
@@ -1465,7 +1465,6 @@ void brw_upload_abo_surfaces(struct brw_context *brw,
|
||||
struct brw_stage_state *stage_state,
|
||||
struct brw_stage_prog_data *prog_data);
|
||||
void brw_upload_image_surfaces(struct brw_context *brw,
|
||||
struct gl_linked_shader *shader,
|
||||
const struct gl_program *prog,
|
||||
struct brw_stage_state *stage_state,
|
||||
struct brw_stage_prog_data *prog_data);
|
||||
|
@@ -122,16 +122,13 @@ const struct brw_tracked_state brw_gs_abo_surfaces = {
|
||||
static void
|
||||
brw_upload_gs_image_surfaces(struct brw_context *brw)
|
||||
{
|
||||
struct gl_context *ctx = &brw->ctx;
|
||||
/* BRW_NEW_GEOMETRY_PROGRAM */
|
||||
struct gl_shader_program *prog =
|
||||
ctx->_Shader->CurrentProgram[MESA_SHADER_GEOMETRY];
|
||||
const struct gl_program *gp = brw->geometry_program;
|
||||
|
||||
if (gp && prog) {
|
||||
if (gp) {
|
||||
/* BRW_NEW_GS_PROG_DATA, BRW_NEW_IMAGE_UNITS, _NEW_TEXTURE */
|
||||
brw_upload_image_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_GEOMETRY],
|
||||
gp, &brw->gs.base, brw->gs.base.prog_data);
|
||||
brw_upload_image_surfaces(brw, gp, &brw->gs.base,
|
||||
brw->gs.base.prog_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -123,16 +123,13 @@ const struct brw_tracked_state brw_tcs_abo_surfaces = {
|
||||
static void
|
||||
brw_upload_tcs_image_surfaces(struct brw_context *brw)
|
||||
{
|
||||
struct gl_context *ctx = &brw->ctx;
|
||||
/* BRW_NEW_TESS_PROGRAMS */
|
||||
struct gl_shader_program *prog =
|
||||
ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_CTRL];
|
||||
const struct gl_program *tcp = brw->tess_ctrl_program;
|
||||
|
||||
if (tcp && prog) {
|
||||
if (tcp) {
|
||||
/* BRW_NEW_TCS_PROG_DATA, BRW_NEW_IMAGE_UNITS */
|
||||
brw_upload_image_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_TESS_CTRL],
|
||||
tcp, &brw->tcs.base, brw->tcs.base.prog_data);
|
||||
brw_upload_image_surfaces(brw, tcp, &brw->tcs.base,
|
||||
brw->tcs.base.prog_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -123,16 +123,13 @@ const struct brw_tracked_state brw_tes_abo_surfaces = {
|
||||
static void
|
||||
brw_upload_tes_image_surfaces(struct brw_context *brw)
|
||||
{
|
||||
struct gl_context *ctx = &brw->ctx;
|
||||
/* BRW_NEW_TESS_PROGRAMS */
|
||||
struct gl_shader_program *prog =
|
||||
ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_EVAL];
|
||||
const struct gl_program *tep = brw->tess_eval_program;
|
||||
|
||||
if (tep && prog) {
|
||||
if (tep) {
|
||||
/* BRW_NEW_TES_PROG_DATA, BRW_NEW_IMAGE_UNITS */
|
||||
brw_upload_image_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_TESS_EVAL],
|
||||
tep, &brw->tes.base, brw->tes.base.prog_data);
|
||||
brw_upload_image_surfaces(brw, tep, &brw->tes.base,
|
||||
brw->tes.base.prog_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -188,16 +188,13 @@ const struct brw_tracked_state brw_vs_abo_surfaces = {
|
||||
static void
|
||||
brw_upload_vs_image_surfaces(struct brw_context *brw)
|
||||
{
|
||||
struct gl_context *ctx = &brw->ctx;
|
||||
/* BRW_NEW_VERTEX_PROGRAM */
|
||||
struct gl_shader_program *prog =
|
||||
ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX];
|
||||
const struct gl_program *vp = brw->vertex_program;
|
||||
|
||||
if (vp && prog) {
|
||||
if (vp) {
|
||||
/* BRW_NEW_VS_PROG_DATA, BRW_NEW_IMAGE_UNITS, _NEW_TEXTURE */
|
||||
brw_upload_image_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_VERTEX],
|
||||
vp, &brw->vs.base, brw->vs.base.prog_data);
|
||||
brw_upload_image_surfaces(brw, vp, &brw->vs.base,
|
||||
brw->vs.base.prog_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1564,16 +1564,13 @@ const struct brw_tracked_state brw_cs_abo_surfaces = {
|
||||
static void
|
||||
brw_upload_cs_image_surfaces(struct brw_context *brw)
|
||||
{
|
||||
struct gl_context *ctx = &brw->ctx;
|
||||
/* _NEW_PROGRAM */
|
||||
struct gl_shader_program *prog =
|
||||
ctx->_Shader->CurrentProgram[MESA_SHADER_COMPUTE];
|
||||
const struct gl_program *cp = brw->compute_program;
|
||||
|
||||
if (cp && prog) {
|
||||
if (cp) {
|
||||
/* BRW_NEW_CS_PROG_DATA, BRW_NEW_IMAGE_UNITS, _NEW_TEXTURE */
|
||||
brw_upload_image_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_COMPUTE],
|
||||
cp, &brw->cs.base, brw->cs.base.prog_data);
|
||||
brw_upload_image_surfaces(brw, cp, &brw->cs.base,
|
||||
brw->cs.base.prog_data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1780,7 +1777,6 @@ update_image_surface(struct brw_context *brw,
|
||||
|
||||
void
|
||||
brw_upload_image_surfaces(struct brw_context *brw,
|
||||
struct gl_linked_shader *shader,
|
||||
const struct gl_program *prog,
|
||||
struct brw_stage_state *stage_state,
|
||||
struct brw_stage_prog_data *prog_data)
|
||||
@@ -1788,12 +1784,12 @@ brw_upload_image_surfaces(struct brw_context *brw,
|
||||
assert(prog);
|
||||
struct gl_context *ctx = &brw->ctx;
|
||||
|
||||
if (prog->info.num_images && shader) {
|
||||
if (prog->info.num_images) {
|
||||
for (unsigned i = 0; i < prog->info.num_images; i++) {
|
||||
struct gl_image_unit *u = &ctx->ImageUnits[shader->ImageUnits[i]];
|
||||
struct gl_image_unit *u = &ctx->ImageUnits[prog->sh.ImageUnits[i]];
|
||||
const unsigned surf_idx = prog_data->binding_table.image_start + i;
|
||||
|
||||
update_image_surface(brw, u, shader->ImageAccess[i],
|
||||
update_image_surface(brw, u, prog->sh.ImageAccess[i],
|
||||
surf_idx,
|
||||
&stage_state->surf_offset[surf_idx],
|
||||
&prog_data->image_param[i]);
|
||||
@@ -1811,15 +1807,13 @@ brw_upload_image_surfaces(struct brw_context *brw,
|
||||
static void
|
||||
brw_upload_wm_image_surfaces(struct brw_context *brw)
|
||||
{
|
||||
struct gl_context *ctx = &brw->ctx;
|
||||
/* BRW_NEW_FRAGMENT_PROGRAM */
|
||||
struct gl_shader_program *prog = ctx->_Shader->_CurrentFragmentProgram;
|
||||
const struct gl_program *wm = brw->fragment_program;
|
||||
|
||||
if (wm && prog) {
|
||||
if (wm) {
|
||||
/* BRW_NEW_FS_PROG_DATA, BRW_NEW_IMAGE_UNITS, _NEW_TEXTURE */
|
||||
brw_upload_image_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_FRAGMENT],
|
||||
wm, &brw->wm.base, brw->wm.base.prog_data);
|
||||
brw_upload_image_surfaces(brw, wm, &brw->wm.base,
|
||||
brw->wm.base.prog_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1980,6 +1980,25 @@ struct gl_program
|
||||
GLuint MaxSubroutineFunctionIndex;
|
||||
struct gl_subroutine_function *SubroutineFunctions;
|
||||
|
||||
/**
|
||||
* Map from image uniform index to image unit (set by glUniform1i())
|
||||
*
|
||||
* An image uniform index is associated with each image uniform by
|
||||
* the linker. The image index associated with each uniform is
|
||||
* stored in the \c gl_uniform_storage::image field.
|
||||
*/
|
||||
GLubyte ImageUnits[MAX_IMAGE_UNIFORMS];
|
||||
|
||||
/**
|
||||
* Access qualifier specified in the shader for each image uniform
|
||||
* index. Either \c GL_READ_ONLY, \c GL_WRITE_ONLY or \c
|
||||
* GL_READ_WRITE.
|
||||
*
|
||||
* It may be different, though only more strict than the value of
|
||||
* \c gl_image_unit::Access for the corresponding image unit.
|
||||
*/
|
||||
GLenum ImageAccess[MAX_IMAGE_UNIFORMS];
|
||||
|
||||
union {
|
||||
struct {
|
||||
/**
|
||||
@@ -2374,29 +2393,10 @@ struct gl_linked_shader
|
||||
struct exec_list *fragdata_arrays;
|
||||
struct glsl_symbol_table *symbols;
|
||||
|
||||
/**
|
||||
* Map from image uniform index to image unit (set by glUniform1i())
|
||||
*
|
||||
* An image uniform index is associated with each image uniform by
|
||||
* the linker. The image index associated with each uniform is
|
||||
* stored in the \c gl_uniform_storage::image field.
|
||||
*/
|
||||
GLubyte ImageUnits[MAX_IMAGE_UNIFORMS];
|
||||
|
||||
/**
|
||||
* Access qualifier specified in the shader for each image uniform
|
||||
* index. Either \c GL_READ_ONLY, \c GL_WRITE_ONLY or \c
|
||||
* GL_READ_WRITE.
|
||||
*
|
||||
* It may be different, though only more strict than the value of
|
||||
* \c gl_image_unit::Access for the corresponding image unit.
|
||||
*/
|
||||
GLenum ImageAccess[MAX_IMAGE_UNIFORMS];
|
||||
|
||||
/**
|
||||
* Number of image uniforms defined in the shader. It specifies
|
||||
* the number of valid elements in the \c ImageUnits and \c
|
||||
* ImageAccess arrays above.
|
||||
* ImageAccess arrays.
|
||||
*/
|
||||
GLuint NumImages;
|
||||
|
||||
|
@@ -908,7 +908,7 @@ _mesa_uniform(struct gl_context *ctx, struct gl_shader_program *shProg,
|
||||
struct gl_linked_shader *sh = shProg->_LinkedShaders[i];
|
||||
|
||||
for (int j = 0; j < count; j++)
|
||||
sh->ImageUnits[uni->opaque[i].index + offset + j] =
|
||||
sh->Program->sh.ImageUnits[uni->opaque[i].index + offset + j] =
|
||||
((GLint *) values)[j];
|
||||
}
|
||||
}
|
||||
|
@@ -58,7 +58,8 @@ st_bind_images(struct st_context *st, struct gl_linked_shader *shader,
|
||||
c = &st->ctx->Const.Program[shader->Stage];
|
||||
|
||||
for (i = 0; i < shader->NumImages; i++) {
|
||||
struct gl_image_unit *u = &st->ctx->ImageUnits[shader->ImageUnits[i]];
|
||||
struct gl_image_unit *u =
|
||||
&st->ctx->ImageUnits[shader->Program->sh.ImageUnits[i]];
|
||||
struct st_texture_object *stObj = st_texture_object(u->TexObj);
|
||||
struct pipe_image_view *img = &images[i];
|
||||
|
||||
|
Reference in New Issue
Block a user