shader: emit readonly-images

OpenGL ES 3.1 only supports writing to a few formats, while it can
read from all of them. So let's make sure we emit readonly, so the
OpenGL driver knows we'll only read.

This avoids a shader-compiler error on OpenGL ES 3.1.

Signed-off-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Signed-off-by: Dave Airlie <airlied@redhat.com>
macos/master
Erik Faye-Lund 6 years ago committed by Dave Airlie
parent f97bec1799
commit ba349a176e
  1. 11
      src/vrend_shader.c

@ -4284,12 +4284,17 @@ static void *emit_image_decl(const struct dump_ctx *ctx, char *glsl_hdr,
const char *sname, *stc, *formatstr; const char *sname, *stc, *formatstr;
enum tgsi_return_type itype; enum tgsi_return_type itype;
const char *volatile_str = image->vflag ? "volatile " : ""; const char *volatile_str = image->vflag ? "volatile " : "";
const char *writeonly = image->decl.Format ? "" : "writeonly "; const char *access = "";
formatstr = get_internalformat_string(image->decl.Format, &itype); formatstr = get_internalformat_string(image->decl.Format, &itype);
ptc = vrend_shader_samplerreturnconv(itype); ptc = vrend_shader_samplerreturnconv(itype);
sname = tgsi_proc_to_prefix(ctx->prog_type); sname = tgsi_proc_to_prefix(ctx->prog_type);
stc = vrend_shader_samplertypeconv(image->decl.Resource, &is_shad); stc = vrend_shader_samplertypeconv(image->decl.Resource, &is_shad);
if (!image->decl.Writable)
access = "readonly ";
else if (!image->decl.Format)
access = "writeonly ";
if (ctx->cfg->use_gles) { /* TODO: enable on OpenGL 4.2 and up also */ if (ctx->cfg->use_gles) { /* TODO: enable on OpenGL 4.2 and up also */
snprintf(buf, 255, "layout(binding=%d%s%s) ", snprintf(buf, 255, "layout(binding=%d%s%s) ",
i, formatstr[0] != '\0' ? ", " : "", formatstr); i, formatstr[0] != '\0' ? ", " : "", formatstr);
@ -4301,10 +4306,10 @@ static void *emit_image_decl(const struct dump_ctx *ctx, char *glsl_hdr,
if (range) if (range)
snprintf(buf, 255, "%s%suniform %cimage%s %simg%d[%d];\n", snprintf(buf, 255, "%s%suniform %cimage%s %simg%d[%d];\n",
writeonly, volatile_str, ptc, stc, sname, i, range); access, volatile_str, ptc, stc, sname, i, range);
else else
snprintf(buf, 255, "%s%suniform %cimage%s %simg%d;\n", snprintf(buf, 255, "%s%suniform %cimage%s %simg%d;\n",
writeonly, volatile_str, ptc, stc, sname, i); access, volatile_str, ptc, stc, sname, i);
STRCAT_WITH_RET(glsl_hdr, buf); STRCAT_WITH_RET(glsl_hdr, buf);
return glsl_hdr; return glsl_hdr;

Loading…
Cancel
Save