From 06799bf22303c3fcdee848fd03ccb3589b24677b Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 28 Dec 2018 11:23:00 +1000 Subject: [PATCH] shader: move header emission to use the error state. This should avoid all the unnecessary return overheads, at the expense of some extra runtime overheads in the unwanted error case. Reviewed-by: Erik Faye-Lund Signed-off-by: Dave Airlie --- src/vrend_shader.c | 230 +++++++++++++++++++++------------------------ 1 file changed, 106 insertions(+), 124 deletions(-) diff --git a/src/vrend_shader.c b/src/vrend_shader.c index 60c7a38..b92e346 100644 --- a/src/vrend_shader.c +++ b/src/vrend_shader.c @@ -517,22 +517,16 @@ static void outdent_buf(struct dump_ctx *ctx) if (!_ret) return false; \ } while(0) -static bool add_str_to_glsl_hdr(struct dump_ctx *ctx, const char *buf) +static void emit_hdr(struct dump_ctx *ctx, const char *buf) { strbuf_append(&ctx->glsl_hdr, buf); - return !strbuf_get_error(&ctx->glsl_hdr); } -static bool emit_hdr(struct dump_ctx *ctx, const char *buf) +static void set_hdr_error(struct dump_ctx *ctx) { - return add_str_to_glsl_hdr(ctx, buf); + strbuf_set_error(&ctx->glsl_hdr); } -#define EMIT_HDR_WITH_RET(ctx, buf) do { \ - bool _ret = emit_hdr((ctx), (buf)); \ - if (!_ret) return false; \ - } while(0) - static bool allocate_temp_range(struct dump_ctx *ctx, int first, int last, int array_id) { @@ -4036,16 +4030,16 @@ prolog(struct tgsi_iterate_context *iter) /* reserve space for: "#extension GL_ARB_gpu_shader5 : require\n" */ #define PAD_GPU_SHADER5(ctx) \ - EMIT_HDR_WITH_RET(ctx, " \n") + emit_hdr(ctx, " \n") #define PAD_GPU_MSINTERPOL(ctx) \ - EMIT_HDR_WITH_RET(ctx, " \n") + emit_hdr(ctx, " \n") -static bool emit_header(struct dump_ctx *ctx) +static void emit_header(struct dump_ctx *ctx) { if (ctx->cfg->use_gles) { char buf[32]; snprintf(buf, sizeof(buf), "#version %d es\n", ctx->cfg->glsl_version); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); if (ctx->cfg->glsl_version < 320 && (ctx->prog_type == TGSI_PROCESSOR_VERTEX || @@ -4056,60 +4050,60 @@ static bool emit_header(struct dump_ctx *ctx) } if (ctx->shader_req_bits & SHADER_REQ_SAMPLER_MS) - EMIT_HDR_WITH_RET(ctx, "#extension GL_OES_texture_storage_multisample_2d_array : require\n"); + emit_hdr(ctx, "#extension GL_OES_texture_storage_multisample_2d_array : require\n"); if (ctx->prog_type == TGSI_PROCESSOR_FRAGMENT) { if (ctx->shader_req_bits & SHADER_REQ_FBFETCH) - EMIT_HDR_WITH_RET(ctx, "#extension GL_EXT_shader_framebuffer_fetch : require\n"); + emit_hdr(ctx, "#extension GL_EXT_shader_framebuffer_fetch : require\n"); } if (ctx->prog_type == TGSI_PROCESSOR_GEOMETRY) { - EMIT_HDR_WITH_RET(ctx, "#extension GL_EXT_geometry_shader : require\n"); + emit_hdr(ctx, "#extension GL_EXT_geometry_shader : require\n"); if (ctx->shader_req_bits & SHADER_REQ_PSIZE) - EMIT_HDR_WITH_RET(ctx, "#extension GL_OES_geometry_point_size : enable\n"); + emit_hdr(ctx, "#extension GL_OES_geometry_point_size : enable\n"); } if ((ctx->prog_type == TGSI_PROCESSOR_TESS_CTRL || ctx->prog_type == TGSI_PROCESSOR_TESS_EVAL)) { if (ctx->cfg->glsl_version < 320) - EMIT_HDR_WITH_RET(ctx, "#extension GL_OES_tessellation_shader : require\n"); - EMIT_HDR_WITH_RET(ctx, "#extension GL_OES_tessellation_point_size : enable\n"); + emit_hdr(ctx, "#extension GL_OES_tessellation_shader : require\n"); + emit_hdr(ctx, "#extension GL_OES_tessellation_point_size : enable\n"); } if (ctx->cfg->glsl_version < 320) { if (ctx->shader_req_bits & SHADER_REQ_SAMPLE_SHADING) - EMIT_HDR_WITH_RET(ctx, "#extension GL_OES_sample_variables : require\n"); + emit_hdr(ctx, "#extension GL_OES_sample_variables : require\n"); if (ctx->shader_req_bits & SHADER_REQ_GPU_SHADER5) { - EMIT_HDR_WITH_RET(ctx, "#extension GL_OES_gpu_shader5 : require\n"); - EMIT_HDR_WITH_RET(ctx, "#extension GL_OES_shader_multisample_interpolation : require\n"); + emit_hdr(ctx, "#extension GL_OES_gpu_shader5 : require\n"); + emit_hdr(ctx, "#extension GL_OES_shader_multisample_interpolation : require\n"); } if (ctx->shader_req_bits & SHADER_REQ_CUBE_ARRAY) - EMIT_HDR_WITH_RET(ctx, "#extension GL_OES_texture_cube_map_array : require\n"); + emit_hdr(ctx, "#extension GL_OES_texture_cube_map_array : require\n"); if (ctx->shader_req_bits & SHADER_REQ_LAYER) - EMIT_HDR_WITH_RET(ctx, "#extension GL_EXT_geometry_shader : require\n"); + emit_hdr(ctx, "#extension GL_EXT_geometry_shader : require\n"); if (ctx->shader_req_bits & SHADER_REQ_IMAGE_ATOMIC) - EMIT_HDR_WITH_RET(ctx, "#extension GL_OES_shader_image_atomic : require\n"); + emit_hdr(ctx, "#extension GL_OES_shader_image_atomic : require\n"); } PAD_GPU_SHADER5(ctx); - EMIT_HDR_WITH_RET(ctx, "precision highp float;\n"); - EMIT_HDR_WITH_RET(ctx, "precision highp int;\n"); + emit_hdr(ctx, "precision highp float;\n"); + emit_hdr(ctx, "precision highp int;\n"); } else { char buf[128]; if (ctx->prog_type == TGSI_PROCESSOR_COMPUTE) { - EMIT_HDR_WITH_RET(ctx, "#version 330\n"); - EMIT_HDR_WITH_RET(ctx, "#extension GL_ARB_compute_shader : require\n"); + emit_hdr(ctx, "#version 330\n"); + emit_hdr(ctx, "#extension GL_ARB_compute_shader : require\n"); } else { if (ctx->prog_type == TGSI_PROCESSOR_GEOMETRY || ctx->prog_type == TGSI_PROCESSOR_TESS_EVAL || ctx->prog_type == TGSI_PROCESSOR_TESS_CTRL || ctx->glsl_ver_required == 150) - EMIT_HDR_WITH_RET(ctx, "#version 150\n"); + emit_hdr(ctx, "#version 150\n"); else if (ctx->glsl_ver_required == 140) - EMIT_HDR_WITH_RET(ctx, "#version 140\n"); + emit_hdr(ctx, "#version 140\n"); else - EMIT_HDR_WITH_RET(ctx, "#version 130\n"); + emit_hdr(ctx, "#version 130\n"); if (ctx->prog_type == TGSI_PROCESSOR_VERTEX || ctx->prog_type == TGSI_PROCESSOR_GEOMETRY || ctx->prog_type == TGSI_PROCESSOR_TESS_EVAL) @@ -4118,24 +4112,24 @@ static bool emit_header(struct dump_ctx *ctx) if (ctx->prog_type == TGSI_PROCESSOR_TESS_CTRL || ctx->prog_type == TGSI_PROCESSOR_TESS_EVAL) - EMIT_HDR_WITH_RET(ctx, "#extension GL_ARB_tessellation_shader : require\n"); + emit_hdr(ctx, "#extension GL_ARB_tessellation_shader : require\n"); if (ctx->prog_type == TGSI_PROCESSOR_VERTEX && ctx->cfg->use_explicit_locations) - EMIT_HDR_WITH_RET(ctx, "#extension GL_ARB_explicit_attrib_location : require\n"); + emit_hdr(ctx, "#extension GL_ARB_explicit_attrib_location : require\n"); if (ctx->prog_type == TGSI_PROCESSOR_FRAGMENT && fs_emit_layout(ctx)) - EMIT_HDR_WITH_RET(ctx, "#extension GL_ARB_fragment_coord_conventions : require\n"); + emit_hdr(ctx, "#extension GL_ARB_fragment_coord_conventions : require\n"); if (ctx->num_ubo) - EMIT_HDR_WITH_RET(ctx, "#extension GL_ARB_uniform_buffer_object : require\n"); + emit_hdr(ctx, "#extension GL_ARB_uniform_buffer_object : require\n"); if (ctx->num_cull_dist_prop || ctx->key->prev_stage_num_cull_out) - EMIT_HDR_WITH_RET(ctx, "#extension GL_ARB_cull_distance : require\n"); + emit_hdr(ctx, "#extension GL_ARB_cull_distance : require\n"); if (ctx->ssbo_used_mask) - EMIT_HDR_WITH_RET(ctx, "#extension GL_ARB_shader_storage_buffer_object : require\n"); + emit_hdr(ctx, "#extension GL_ARB_shader_storage_buffer_object : require\n"); if (ctx->num_abo) { - EMIT_HDR_WITH_RET(ctx, "#extension GL_ARB_shader_atomic_counters : require\n"); - EMIT_HDR_WITH_RET(ctx, "#extension GL_ARB_shader_atomic_counter_ops : require\n"); + emit_hdr(ctx, "#extension GL_ARB_shader_atomic_counters : require\n"); + emit_hdr(ctx, "#extension GL_ARB_shader_atomic_counter_ops : require\n"); } for (uint32_t i = 0; i < ARRAY_SIZE(shader_req_table); i++) { @@ -4144,12 +4138,10 @@ static bool emit_header(struct dump_ctx *ctx) if (ctx->shader_req_bits & shader_req_table[i].key) { snprintf(buf, 128, "#extension GL_%s : require\n", shader_req_table[i].string); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } } } - - return true; } char vrend_shader_samplerreturnconv(enum tgsi_return_type type) @@ -4239,7 +4231,7 @@ static const char *get_aux_string(unsigned location) } } -static bool emit_sampler_decl(struct dump_ctx *ctx, +static void emit_sampler_decl(struct dump_ctx *ctx, uint32_t i, uint32_t range, const struct vrend_shader_sampler *sampler) { @@ -4262,16 +4254,14 @@ static bool emit_sampler_decl(struct dump_ctx *ctx, else snprintf(buf, 255, "uniform %s%csampler%s %ssamp%d;\n", precision, ptc, stc, sname, i); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); if (is_shad) { snprintf(buf, 255, "uniform %svec4 %sshadmask%d;\n", precision, sname, i); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); snprintf(buf, 255, "uniform %svec4 %sshadadd%d;\n", precision, sname, i); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); ctx->shadow_samp_mask |= (1 << i); } - - return true; } const char *get_internalformat_string(int virgl_format, enum tgsi_return_type *stype) @@ -4404,7 +4394,7 @@ const char *get_internalformat_string(int virgl_format, enum tgsi_return_type *s } } -static bool emit_image_decl(struct dump_ctx *ctx, +static void emit_image_decl(struct dump_ctx *ctx, uint32_t i, uint32_t range, const struct vrend_shader_image *image) { @@ -4432,10 +4422,10 @@ static bool emit_image_decl(struct dump_ctx *ctx, if (ctx->cfg->use_gles) { /* TODO: enable on OpenGL 4.2 and up also */ snprintf(buf, 255, "layout(binding=%d%s%s) ", i, formatstr[0] != '\0' ? ", " : "", formatstr); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } else if (formatstr[0] != '\0') { snprintf(buf, 255, "layout(%s) ", formatstr); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } if (range) @@ -4445,11 +4435,10 @@ static bool emit_image_decl(struct dump_ctx *ctx, snprintf(buf, 255, "%s%suniform %s%cimage%s %simg%d;\n", access, volatile_str, precision, ptc, stc, sname, i); - EMIT_HDR_WITH_RET(ctx, buf); - return true; + emit_hdr(ctx, buf); } -static bool emit_ios(struct dump_ctx *ctx) +static void emit_ios(struct dump_ctx *ctx) { uint32_t i; char buf[255]; @@ -4462,7 +4451,8 @@ static bool emit_ios(struct dump_ctx *ctx) if (ctx->so && ctx->so->num_outputs >= PIPE_MAX_SO_OUTPUTS) { fprintf(stderr, "Num outputs exceeded, max is %u\n", PIPE_MAX_SO_OUTPUTS); - return false; + set_hdr_error(ctx); + return; } if (ctx->key->color_two_side) { @@ -4478,22 +4468,22 @@ static bool emit_ios(struct dump_ctx *ctx) upper_left ? "origin_upper_left" : "", comma, ctx->fs_pixel_center ? "pixel_center_integer" : ""); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } if (ctx->early_depth_stencil) { - EMIT_HDR_WITH_RET(ctx, "layout(early_fragment_tests) in;\n"); + emit_hdr(ctx, "layout(early_fragment_tests) in;\n"); } } if (ctx->prog_type == TGSI_PROCESSOR_COMPUTE) { snprintf(buf, 255, "layout (local_size_x = %d, local_size_y = %d, local_size_z = %d) in;\n", ctx->local_cs_block_size[0], ctx->local_cs_block_size[1], ctx->local_cs_block_size[2]); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); if (ctx->req_local_mem) { enum vrend_type_qualifier type = ctx->integer_memory ? INT : UINT; snprintf(buf, 255, "shared %s values[%d];\n", get_string(type), ctx->req_local_mem / 4); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } } @@ -4505,9 +4495,9 @@ static bool emit_ios(struct dump_ctx *ctx) snprintf(buf, 255, "layout(%s%s) in;\n", prim_to_name(ctx->gs_in_prim), ctx->gs_num_invocations > 1 ? invocbuf : ""); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); snprintf(buf, 255, "layout(%s, max_vertices = %d) out;\n", prim_to_name(ctx->gs_out_prim), ctx->gs_max_out_verts); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } if (ctx_indirect_inputs(ctx)) { @@ -4518,7 +4508,7 @@ static bool emit_ios(struct dump_ctx *ctx) if (size < ctx->key->num_indirect_patch_inputs) size = ctx->key->num_indirect_patch_inputs; snprintf(buf, 255, "patch in vec4 %sp%d[%d];\n", name_prefix, ctx->patch_input_range.first, size); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } } @@ -4529,7 +4519,7 @@ static bool emit_ios(struct dump_ctx *ctx) if (size < ctx->key->num_indirect_generic_inputs) size = ctx->key->num_indirect_generic_inputs; snprintf(buf, 255, "in block { vec4 %s%d[%d]; } blk[];\n", name_prefix, ctx->generic_input_range.first, size); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } } } @@ -4537,7 +4527,7 @@ static bool emit_ios(struct dump_ctx *ctx) if (!ctx->inputs[i].glsl_predefined_no_emit) { if (ctx->prog_type == TGSI_PROCESSOR_VERTEX && ctx->cfg->use_explicit_locations) { snprintf(buf, 255, "layout(location=%d) ", ctx->inputs[i].first); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } prefix = ""; auxprefix = ""; @@ -4562,19 +4552,19 @@ static bool emit_ios(struct dump_ctx *ctx) } else postfix[0] = 0; snprintf(buf, 255, "%s%sin vec4 %s%s;\n", prefix, auxprefix, ctx->inputs[i].glsl_name, postfix); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } if (ctx->prog_type == TGSI_PROCESSOR_FRAGMENT && ctx->cfg->use_gles && !ctx->key->winsys_adjust_y_emitted && (ctx->key->coord_replace & (1 << ctx->inputs[i].sid))) { ctx->key->winsys_adjust_y_emitted = true; - EMIT_HDR_WITH_RET(ctx, "uniform float winsys_adjust_y;\n"); + emit_hdr(ctx, "uniform float winsys_adjust_y;\n"); } } if (ctx->prog_type == TGSI_PROCESSOR_TESS_CTRL) { snprintf(buf, 255, "layout(vertices = %d) out;\n", ctx->tcs_vertices_out); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } if (ctx->prog_type == TGSI_PROCESSOR_TESS_EVAL) { snprintf(buf, 255, "layout(%s, %s, %s%s) in;\n", @@ -4582,7 +4572,7 @@ static bool emit_ios(struct dump_ctx *ctx) get_spacing_string(ctx->tes_spacing), ctx->tes_vertex_order ? "cw" : "ccw", ctx->tes_point_mode ? ", point_mode" : ""); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } if (ctx_indirect_outputs(ctx)) { @@ -4590,17 +4580,17 @@ static bool emit_ios(struct dump_ctx *ctx) if (ctx->prog_type == TGSI_PROCESSOR_VERTEX) { if (ctx->generic_output_range.used) { snprintf(buf, 255, "out block { vec4 %s%d[%d]; } oblk;\n", name_prefix, ctx->generic_output_range.first, ctx->generic_output_range.last - ctx->generic_output_range.first + 1); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } } if (ctx->prog_type == TGSI_PROCESSOR_TESS_CTRL) { if (ctx->generic_output_range.used) { snprintf(buf, 255, "out block { vec4 %s%d[%d]; } oblk[];\n", name_prefix, ctx->generic_output_range.first, ctx->generic_output_range.last - ctx->generic_output_range.first + 1); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } if (ctx->patch_output_range.used) { snprintf(buf, 255, "patch out vec4 %sp%d[%d];\n", name_prefix, ctx->patch_output_range.first, ctx->patch_output_range.last - ctx->patch_output_range.first + 1); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } } } @@ -4611,7 +4601,7 @@ static bool emit_ios(struct dump_ctx *ctx) snprintf(buf, 255, "layout (location=%d) out vec4 fsout_c%d;\n", i, i); else snprintf(buf, 255, "out vec4 fsout_c%d;\n", i); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } } else { for (i = 0; i < ctx->num_outputs; i++) { @@ -4650,13 +4640,13 @@ static bool emit_ios(struct dump_ctx *ctx) ctx->outputs[i].invariant ? "invariant " : "", ctx->outputs[i].fbfetch_used ? "inout" : "out", ctx->outputs[i].glsl_name); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } else if (ctx->outputs[i].invariant || ctx->outputs[i].precise) { snprintf(buf, 255, "%s%s;\n", ctx->outputs[i].precise ? "precise " : (ctx->outputs[i].invariant ? "invariant " : ""), ctx->outputs[i].glsl_name); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } } } @@ -4665,11 +4655,11 @@ static bool emit_ios(struct dump_ctx *ctx) for (i = 0; i < 2; i++) { if (fcolor_emitted[i] && !bcolor_emitted[i]) { snprintf(buf, 255, "%sout vec4 ex_bc%d;\n", INTERP_PREFIX, i); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } if (bcolor_emitted[i] && !fcolor_emitted[i]) { snprintf(buf, 255, "%sout vec4 ex_c%d;\n", INTERP_PREFIX, i); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } } } @@ -4677,13 +4667,13 @@ static bool emit_ios(struct dump_ctx *ctx) if (ctx->prog_type == TGSI_PROCESSOR_VERTEX || ctx->prog_type == TGSI_PROCESSOR_GEOMETRY || ctx->prog_type == TGSI_PROCESSOR_TESS_EVAL) { - EMIT_HDR_WITH_RET(ctx, "uniform float winsys_adjust_y;\n"); + emit_hdr(ctx, "uniform float winsys_adjust_y;\n"); } if (ctx->prog_type == TGSI_PROCESSOR_VERTEX) { if (ctx->has_clipvertex) { snprintf(buf, 255, "%svec4 clipv_tmp;\n", ctx->has_clipvertex_so ? "out " : ""); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } if (ctx->num_clip_dist || ctx->key->clip_plane_enable) { bool has_prop = (ctx->num_clip_dist_prop + ctx->num_cull_dist_prop) > 0; @@ -4701,17 +4691,17 @@ static bool emit_ios(struct dump_ctx *ctx) } else snprintf(clip_buf, 64, "out float gl_ClipDistance[%d];\n", num_clip_dists); if (ctx->key->clip_plane_enable) { - EMIT_HDR_WITH_RET(ctx, "uniform vec4 clipp[8];\n"); + emit_hdr(ctx, "uniform vec4 clipp[8];\n"); } if (ctx->key->gs_present || ctx->key->tes_present) { ctx->vs_has_pervertex = true; snprintf(buf, 255, "out gl_PerVertex {\n vec4 gl_Position;\n float gl_PointSize;\n%s%s};\n", clip_buf, cull_buf); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } else { snprintf(buf, 255, "%s%s", clip_buf, cull_buf); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } - EMIT_HDR_WITH_RET(ctx, "vec4 clip_dist_temp[2];\n"); + emit_hdr(ctx, "vec4 clip_dist_temp[2];\n"); } } @@ -4729,7 +4719,7 @@ static bool emit_ios(struct dump_ctx *ctx) snprintf(cull_var, 64, "float gl_CullDistance[%d];\n", cull_dist); snprintf(buf, 255, "in gl_PerVertex {\n vec4 gl_Position;\n float gl_PointSize; \n %s%s\n} gl_in[];\n", clip_var, cull_var); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } if (ctx->num_clip_dist) { bool has_prop = (ctx->num_clip_dist_prop + ctx->num_cull_dist_prop) > 0; @@ -4747,20 +4737,20 @@ static bool emit_ios(struct dump_ctx *ctx) } else snprintf(clip_buf, 64, "out float gl_ClipDistance[%d];\n", num_clip_dists); snprintf(buf, 255, "%s%s\n", clip_buf, cull_buf); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); snprintf(buf, 255, "vec4 clip_dist_temp[2];\n"); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } } if (ctx->prog_type == TGSI_PROCESSOR_FRAGMENT && ctx->num_in_clip_dist) { if (ctx->key->prev_stage_num_clip_out) { snprintf(buf, 255, "in float gl_ClipDistance[%d];\n", ctx->key->prev_stage_num_clip_out); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } if (ctx->key->prev_stage_num_cull_out) { snprintf(buf, 255, "in float gl_CullDistance[%d];\n", ctx->key->prev_stage_num_cull_out); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } } @@ -4778,13 +4768,13 @@ static bool emit_ios(struct dump_ctx *ctx) snprintf(cull_var, 64, "float gl_CullDistance[%d];\n", cull_dist); snprintf(buf, 255, "in gl_PerVertex {\n vec4 gl_Position;\n float gl_PointSize; \n %s%s} gl_in[];\n", clip_var, cull_var); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } if (ctx->num_clip_dist) { snprintf(buf, 255, "out gl_PerVertex {\n vec4 gl_Position;\n float gl_PointSize;\n float gl_ClipDistance[%d];\n} gl_out[];\n", ctx->num_clip_dist ? ctx->num_clip_dist : 8); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); snprintf(buf, 255, "vec4 clip_dist_temp[2];\n"); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } } @@ -4803,48 +4793,48 @@ static bool emit_ios(struct dump_ctx *ctx) snprintf(buf, 255, "layout (stream=%d) out %s tfout%d;\n", ctx->so->output[i].stream, outtype, i); else snprintf(buf, 255, "out %s tfout%d;\n", outtype, i); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } } for (i = 0; i < ctx->num_temp_ranges; i++) { snprintf(buf, 255, "vec4 temp%d[%d];\n", ctx->temp_ranges[i].first, ctx->temp_ranges[i].last - ctx->temp_ranges[i].first + 1); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } if (ctx->write_mul_utemp) { - EMIT_HDR_WITH_RET(ctx, "uvec4 mul_utemp;\n"); - EMIT_HDR_WITH_RET(ctx, "uvec4 umul_temp;\n"); + emit_hdr(ctx, "uvec4 mul_utemp;\n"); + emit_hdr(ctx, "uvec4 umul_temp;\n"); } if (ctx->write_mul_itemp) { - EMIT_HDR_WITH_RET(ctx, "ivec4 mul_itemp;\n"); - EMIT_HDR_WITH_RET(ctx, "ivec4 imul_temp;\n"); + emit_hdr(ctx, "ivec4 mul_itemp;\n"); + emit_hdr(ctx, "ivec4 imul_temp;\n"); } if (ctx->ssbo_used_mask || ctx->has_file_memory) { - EMIT_HDR_WITH_RET(ctx, "uint ssbo_addr_temp;\n"); + emit_hdr(ctx, "uint ssbo_addr_temp;\n"); } if (ctx->shader_req_bits & SHADER_REQ_FP64) { - EMIT_HDR_WITH_RET(ctx, "dvec2 fp64_dst[3];\n"); - EMIT_HDR_WITH_RET(ctx, "dvec2 fp64_src[4];\n"); + emit_hdr(ctx, "dvec2 fp64_dst[3];\n"); + emit_hdr(ctx, "dvec2 fp64_src[4];\n"); } for (i = 0; i < ctx->num_address; i++) { snprintf(buf, 255, "int addr%d;\n", i); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } if (ctx->num_consts) { const char *cname = tgsi_proc_to_prefix(ctx->prog_type); snprintf(buf, 255, "uniform uvec4 %sconst0[%d];\n", cname, ctx->num_consts); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } if (ctx->key->color_two_side) { if (ctx->color_in_mask & 1) - EMIT_HDR_WITH_RET(ctx, "vec4 realcolor0;\n"); + emit_hdr(ctx, "vec4 realcolor0;\n"); if (ctx->color_in_mask & 2) - EMIT_HDR_WITH_RET(ctx, "vec4 realcolor1;\n"); + emit_hdr(ctx, "vec4 realcolor1;\n"); } if (ctx->num_ubo) { const char *cname = tgsi_proc_to_prefix(ctx->prog_type); @@ -4852,11 +4842,11 @@ static bool emit_ios(struct dump_ctx *ctx) if (ctx->info.dimension_indirect_files & (1 << TGSI_FILE_CONSTANT)) { require_glsl_ver(ctx, 150); snprintf(buf, 255, "uniform %subo { vec4 ubocontents[%d]; } %suboarr[%d];\n", cname, ctx->ubo_sizes[0], cname, ctx->num_ubo); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } else { for (i = 0; i < ctx->num_ubo; i++) { snprintf(buf, 255, "uniform %subo%d { vec4 %subo%dcontents[%d]; };\n", cname, ctx->ubo_idx[i], cname, ctx->ubo_idx[i], ctx->ubo_sizes[i]); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } } } @@ -4865,8 +4855,7 @@ static bool emit_ios(struct dump_ctx *ctx) for (i = 0; i < ctx->num_sampler_arrays; i++) { uint32_t first = ctx->sampler_arrays[i].first; uint32_t range = ctx->sampler_arrays[i].array_size; - if (!emit_sampler_decl(ctx, first, range, ctx->samplers + first)) - return false; + emit_sampler_decl(ctx, first, range, ctx->samplers + first); } } else { nsamp = util_last_bit(ctx->samplers_used); @@ -4875,8 +4864,7 @@ static bool emit_ios(struct dump_ctx *ctx) if ((ctx->samplers_used & (1 << i)) == 0) continue; - if (!emit_sampler_decl(ctx, i, 0, ctx->samplers + i)) - return false; + emit_sampler_decl(ctx, i, 0, ctx->samplers + i); } } @@ -4884,15 +4872,13 @@ static bool emit_ios(struct dump_ctx *ctx) for (i = 0; i < ctx->num_image_arrays; i++) { uint32_t first = ctx->image_arrays[i].first; uint32_t range = ctx->image_arrays[i].array_size; - if (!emit_image_decl(ctx, first, range, ctx->images + first)) - return false; + emit_image_decl(ctx, first, range, ctx->images + first); } } else { uint32_t mask = ctx->images_used_mask; while (mask) { i = u_bit_scan(&mask); - if (!emit_image_decl(ctx, i, 0, ctx->images + i)) - return false; + emit_image_decl(ctx, i, 0, ctx->images + i); } } @@ -4901,7 +4887,7 @@ static bool emit_ios(struct dump_ctx *ctx) snprintf(buf, 255, "layout (binding = %d, offset = %d) uniform atomic_uint ac%d[%d];\n", ctx->abo_idx[i], ctx->abo_offsets[i] * 4, i, ctx->abo_sizes[i]); else snprintf(buf, 255, "layout (binding = %d, offset = %d) uniform atomic_uint ac%d;\n", ctx->abo_idx[i], ctx->abo_offsets[i] * 4, i); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } if (ctx->info.indirect_files & (1 << TGSI_FILE_BUFFER)) { @@ -4911,7 +4897,7 @@ static bool emit_ios(struct dump_ctx *ctx) u_bit_scan_consecutive_range(&mask, &start, &count); const char *atomic = (ctx->ssbo_atomic_mask & (1 << start)) ? "atomic" : ""; snprintf(buf, 255, "layout (binding = %d, std430) buffer %sssbo%d { uint %sssbocontents%d[]; } %sssboarr%s[%d];\n", start, sname, start, sname, start, sname, atomic, count); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } } else { uint32_t mask = ctx->ssbo_used_mask; @@ -4921,15 +4907,14 @@ static bool emit_ios(struct dump_ctx *ctx) enum vrend_type_qualifier type = (ctx->ssbo_integer_mask & (1 << id)) ? INT : UINT; snprintf(buf, 255, "layout (binding = %d, std430) buffer %sssbo%d { %s %sssbocontents%d[]; };\n", id, sname, id, get_string(type), sname, id); - EMIT_HDR_WITH_RET(ctx, buf); + emit_hdr(ctx, buf); } } if (ctx->prog_type == TGSI_PROCESSOR_FRAGMENT && ctx->key->pstipple_tex == true) { - EMIT_HDR_WITH_RET(ctx, "uniform sampler2D pstipple_sampler;\nfloat stip_temp;\n"); + emit_hdr(ctx, "uniform sampler2D pstipple_sampler;\nfloat stip_temp;\n"); } - return true; } static boolean fill_fragment_interpolants(struct dump_ctx *ctx, struct vrend_shader_info *sinfo) @@ -5070,11 +5055,8 @@ char *vrend_convert_shader(struct vrend_context *rctx, if (!strbuf_alloc(&ctx.glsl_hdr, 1024)) goto fail; - if (!emit_header(&ctx)) - goto fail; - - if (!emit_ios(&ctx)) - goto fail; + emit_header(&ctx); + emit_ios(&ctx); if (strbuf_get_error(&ctx.glsl_hdr)) goto fail;