From d87bc015dc8b84257dc84e92cf4381c11a5086d3 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sun, 5 Dec 2010 13:32:59 -0700 Subject: [PATCH 001/164] gallium: added PIPE_CAP_INSTANCED_DRAWING --- src/gallium/docs/source/screen.rst | 1 + src/gallium/include/pipe/p_defines.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/gallium/docs/source/screen.rst b/src/gallium/docs/source/screen.rst index e3ef49c862c..a62520061ea 100644 --- a/src/gallium/docs/source/screen.rst +++ b/src/gallium/docs/source/screen.rst @@ -36,6 +36,7 @@ The integer capabilities: bound. * ``OCCLUSION_QUERY``: Whether occlusion queries are available. * ``TIMER_QUERY``: Whether timer queries are available. +* ``INSTANCED_DRAWING``: indicates support for instanced drawing. * ``TEXTURE_SHADOW_MAP``: indicates whether the fragment shader hardware can do the depth texture / Z comparison operation in TEX instructions for shadow testing. diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h index dacabed891a..9f2b081e33a 100644 --- a/src/gallium/include/pipe/p_defines.h +++ b/src/gallium/include/pipe/p_defines.h @@ -467,6 +467,7 @@ enum pipe_cap { PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER, PIPE_CAP_DEPTH_CLAMP, PIPE_CAP_SHADER_STENCIL_EXPORT, + PIPE_CAP_INSTANCED_DRAWING, }; /* Shader caps not specific to any single stage */ From 9cd277684db5a266b451a719a963556664838d6e Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sun, 5 Dec 2010 13:34:02 -0700 Subject: [PATCH 002/164] st/mesa: GL_ARB_draw_instanced depends on PIPE_CAP_INSTANCED_DRAWING --- src/mesa/state_tracker/st_extensions.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c index 930b60ade2d..37a0aa2bc9f 100644 --- a/src/mesa/state_tracker/st_extensions.c +++ b/src/mesa/state_tracker/st_extensions.c @@ -456,4 +456,8 @@ void st_init_extensions(struct st_context *st) if (screen->get_param(screen, PIPE_CAP_SHADER_STENCIL_EXPORT)) { ctx->Extensions.ARB_shader_stencil_export = GL_TRUE; } + + if (screen->get_param(screen, PIPE_CAP_INSTANCED_DRAWING)) { + ctx->Extensions.ARB_draw_instanced = GL_TRUE; + } } From 859f45a92197f310186924c47ef7b7d1c2bd7ec8 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 8 Dec 2010 18:19:14 -0700 Subject: [PATCH 003/164] tgsi: add support for system values to TGSI interpreter --- src/gallium/auxiliary/tgsi/tgsi_exec.c | 19 ++++++++++++++++--- src/gallium/auxiliary/tgsi/tgsi_exec.h | 7 +++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c b/src/gallium/auxiliary/tgsi/tgsi_exec.c index 7892a67f04c..35b27423513 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_exec.c +++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c @@ -1038,7 +1038,6 @@ fetch_src_file_channel(const struct tgsi_exec_machine *mach, break; case TGSI_FILE_INPUT: - case TGSI_FILE_SYSTEM_VALUE: for (i = 0; i < QUAD_SIZE; i++) { /* if (TGSI_PROCESSOR_GEOMETRY == mach->Processor) { @@ -1053,6 +1052,15 @@ fetch_src_file_channel(const struct tgsi_exec_machine *mach, } break; + case TGSI_FILE_SYSTEM_VALUE: + /* XXX no swizzling at this point. Will be needed if we put + * gl_FragCoord, for example, in a sys value register. + */ + for (i = 0; i < QUAD_SIZE; i++) { + chan->f[i] = mach->SystemValue[index->i[i]][0]; + } + break; + case TGSI_FILE_TEMPORARY: for (i = 0; i < QUAD_SIZE; i++) { assert(index->i[i] < TGSI_EXEC_NUM_TEMPS); @@ -1907,8 +1915,7 @@ exec_declaration(struct tgsi_exec_machine *mach, const struct tgsi_full_declaration *decl) { if (mach->Processor == TGSI_PROCESSOR_FRAGMENT) { - if (decl->Declaration.File == TGSI_FILE_INPUT || - decl->Declaration.File == TGSI_FILE_SYSTEM_VALUE) { + if (decl->Declaration.File == TGSI_FILE_INPUT) { uint first, last, mask; first = decl->Range.First; @@ -1921,6 +1928,7 @@ exec_declaration(struct tgsi_exec_machine *mach, * ureg code to emit the right UsageMask value (WRITEMASK_X). * Then, we could remove the tgsi_exec_machine::Face field. */ + /* XXX make FACE a system value */ if (decl->Semantic.Name == TGSI_SEMANTIC_FACE) { uint i; @@ -1962,8 +1970,13 @@ exec_declaration(struct tgsi_exec_machine *mach, } } } + + if (decl->Declaration.File == TGSI_FILE_SYSTEM_VALUE) { + mach->SysSemanticToIndex[decl->Declaration.Semantic] = decl->Range.First; + } } + typedef void (* micro_op)(union tgsi_exec_channel *dst); static void diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.h b/src/gallium/auxiliary/tgsi/tgsi_exec.h index b5ebbfbfaab..6c204c73714 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_exec.h +++ b/src/gallium/auxiliary/tgsi/tgsi_exec.h @@ -31,6 +31,7 @@ #include "pipe/p_compiler.h" #include "pipe/p_state.h" +#include "pipe/p_shader_tokens.h" #if defined __cplusplus extern "C" { @@ -181,6 +182,8 @@ struct tgsi_sampler /* The maximum total number of vertices */ #define TGSI_MAX_TOTAL_VERTICES (TGSI_MAX_PRIM_VERTICES * TGSI_MAX_PRIMITIVES * PIPE_MAX_ATTRIBS) +#define TGSI_MAX_MISC_INPUTS 8 + /** function call/activation record */ struct tgsi_call_record { @@ -228,6 +231,10 @@ struct tgsi_exec_machine struct tgsi_exec_vector Inputs[TGSI_MAX_PRIM_VERTICES * PIPE_MAX_ATTRIBS]; struct tgsi_exec_vector Outputs[TGSI_MAX_TOTAL_VERTICES]; + /* System values */ + unsigned SysSemanticToIndex[TGSI_SEMANTIC_COUNT]; + float SystemValue[TGSI_MAX_MISC_INPUTS][4]; + struct tgsi_exec_vector *Addrs; struct tgsi_exec_vector *Predicates; From b550d8d76b42ef5ba5e8293dcc24220d5b683369 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 8 Dec 2010 18:19:47 -0700 Subject: [PATCH 004/164] tgsi: new tgsi_shader_info fields for system values --- src/gallium/auxiliary/tgsi/tgsi_scan.c | 19 ++++++++++++++++++- src/gallium/auxiliary/tgsi/tgsi_scan.h | 4 ++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/gallium/auxiliary/tgsi/tgsi_scan.c b/src/gallium/auxiliary/tgsi/tgsi_scan.c index 6585da3e838..83c6ac75e54 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_scan.c +++ b/src/gallium/auxiliary/tgsi/tgsi_scan.c @@ -143,7 +143,7 @@ tgsi_scan_shader(const struct tgsi_token *tokens, info->file_count[file]++; info->file_max[file] = MAX2(info->file_max[file], (int)reg); - if (file == TGSI_FILE_INPUT || file == TGSI_FILE_SYSTEM_VALUE) { + if (file == TGSI_FILE_INPUT) { info->input_semantic_name[reg] = (ubyte)fulldecl->Semantic.Name; info->input_semantic_index[reg] = (ubyte)fulldecl->Semantic.Index; info->input_interpolate[reg] = (ubyte)fulldecl->Declaration.Interpolate; @@ -151,6 +151,23 @@ tgsi_scan_shader(const struct tgsi_token *tokens, info->input_cylindrical_wrap[reg] = (ubyte)fulldecl->Declaration.CylindricalWrap; info->num_inputs++; } + else if (file == TGSI_FILE_SYSTEM_VALUE) { + unsigned index = fulldecl->Range.First; + unsigned semName = fulldecl->Semantic.Name; + + info->system_value_semantic_name[index] = semName; + info->num_system_values = MAX2(info->num_system_values, + index + 1); + + /* + info->system_value_semantic_name[info->num_system_values++] = + fulldecl->Semantic.Name; + */ + + if (fulldecl->Semantic.Name == TGSI_SEMANTIC_INSTANCEID) { + info->uses_instanceid = TRUE; + } + } else if (file == TGSI_FILE_OUTPUT) { info->output_semantic_name[reg] = (ubyte)fulldecl->Semantic.Name; info->output_semantic_index[reg] = (ubyte)fulldecl->Semantic.Index; diff --git a/src/gallium/auxiliary/tgsi/tgsi_scan.h b/src/gallium/auxiliary/tgsi/tgsi_scan.h index 104097fbc03..53ab3d509dd 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_scan.h +++ b/src/gallium/auxiliary/tgsi/tgsi_scan.h @@ -51,6 +51,9 @@ struct tgsi_shader_info ubyte output_semantic_name[PIPE_MAX_SHADER_OUTPUTS]; /**< TGSI_SEMANTIC_x */ ubyte output_semantic_index[PIPE_MAX_SHADER_OUTPUTS]; + ubyte num_system_values; + ubyte system_value_semantic_name[PIPE_MAX_SHADER_INPUTS]; + uint file_mask[TGSI_FILE_COUNT]; /**< bitmask of declared registers */ uint file_count[TGSI_FILE_COUNT]; /**< number of declared registers */ int file_max[TGSI_FILE_COUNT]; /**< highest index of declared registers */ @@ -64,6 +67,7 @@ struct tgsi_shader_info boolean writes_stencil; /**< does fragment shader write stencil value? */ boolean writes_edgeflag; /**< vertex shader outputs edgeflag */ boolean uses_kill; /**< KIL or KILP instruction used? */ + boolean uses_instanceid; /** * Bitmask indicating which register files are accessed with From e8154eeae52c09783f537f5584e6fb57b3c5efb6 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 8 Dec 2010 18:20:05 -0700 Subject: [PATCH 005/164] tgsi/sse: add support for system values --- src/gallium/auxiliary/tgsi/tgsi_sse2.c | 54 ++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/src/gallium/auxiliary/tgsi/tgsi_sse2.c b/src/gallium/auxiliary/tgsi/tgsi_sse2.c index 086d983a73a..3f2cda860e0 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_sse2.c +++ b/src/gallium/auxiliary/tgsi/tgsi_sse2.c @@ -163,6 +163,14 @@ get_immediate_base( void ) reg_DX ); } +static struct x86_reg +get_system_value_base( void ) +{ + return x86_make_disp( + get_machine_base(), + Offset(struct tgsi_exec_machine, SystemValue) ); +} + /** * Data access helpers. @@ -228,6 +236,16 @@ get_temp( (vec * 4 + chan) * 16 ); } +static struct x86_reg +get_system_value( + unsigned vec, + unsigned chan ) +{ + return x86_make_disp( + get_system_value_base(), /* base */ + (vec * 4 + chan) * 4 ); /* byte offset from base */ +} + static struct x86_reg get_coef( unsigned vec, @@ -422,6 +440,30 @@ emit_tempf( get_temp( vec, chan ) ); } +/** + * Copy a system value to xmm register + * \param xmm the destination xmm register + * \param vec the source system value register + * \param chan src channel to fetch (X, Y, Z or W) + */ +static void +emit_system_value( + struct x86_function *func, + unsigned xmm, + unsigned vec, + unsigned chan ) +{ + sse_movss( + func, + make_xmm( xmm ), + get_system_value( vec, chan ) ); + sse_shufps( + func, + make_xmm( xmm ), + make_xmm( xmm ), + SHUF( 0, 0, 0, 0 ) ); +} + /** * Load an xmm register with an input attrib coefficient (a0, dadx or dady) * \param xmm the destination xmm register @@ -1281,8 +1323,15 @@ emit_fetch( swizzle ); break; - case TGSI_FILE_INPUT: case TGSI_FILE_SYSTEM_VALUE: + emit_system_value( + func, + xmm, + reg->Register.Index, + swizzle ); + break; + + case TGSI_FILE_INPUT: emit_inputf( func, xmm, @@ -2636,8 +2685,7 @@ emit_declaration( struct x86_function *func, struct tgsi_full_declaration *decl ) { - if( decl->Declaration.File == TGSI_FILE_INPUT || - decl->Declaration.File == TGSI_FILE_SYSTEM_VALUE ) { + if( decl->Declaration.File == TGSI_FILE_INPUT ) { unsigned first, last, mask; unsigned i, j; From 975418a654e72d8338a9cf288d2d1f9429c226ae Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 8 Dec 2010 18:20:44 -0700 Subject: [PATCH 006/164] tgsi/ppc: add case for system values and assert --- src/gallium/auxiliary/tgsi/tgsi_ppc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gallium/auxiliary/tgsi/tgsi_ppc.c b/src/gallium/auxiliary/tgsi/tgsi_ppc.c index 3521847b619..537a0f6c5e4 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_ppc.c +++ b/src/gallium/auxiliary/tgsi/tgsi_ppc.c @@ -294,7 +294,6 @@ emit_fetch(struct gen_context *gen, case TGSI_SWIZZLE_W: switch (reg->Register.File) { case TGSI_FILE_INPUT: - case TGSI_FILE_SYSTEM_VALUE: { int offset = (reg->Register.Index * 4 + swizzle) * 16; int offset_reg = emit_li_offset(gen, offset); @@ -302,6 +301,9 @@ emit_fetch(struct gen_context *gen, ppc_lvx(gen->f, dst_vec, gen->inputs_reg, offset_reg); } break; + case TGSI_FILE_SYSTEM_VALUE: + assert(!"unhandled system value in tgsi_ppc.c"); + break; case TGSI_FILE_TEMPORARY: if (is_ppc_vec_temporary(reg)) { /* use PPC vec register */ From c6d74bcbfcb54e0c03f4c3d7e82bc1267f36ffe4 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 8 Dec 2010 18:21:18 -0700 Subject: [PATCH 007/164] mesa: add PROGRAM_SYSTEM_VALUE and related tokens System values are shader inputs which don't necessarily change from vertex to vertex or fragment to fragment. gl_InstanceID and gl_FrontFacing are examples. --- src/mesa/main/mtypes.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 80c20e09d9a..417f8df8e34 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1747,11 +1747,24 @@ typedef enum PROGRAM_WRITE_ONLY, /**< A dummy, write-only register */ PROGRAM_ADDRESS, /**< machine->AddressReg */ PROGRAM_SAMPLER, /**< for shader samplers, compile-time only */ + PROGRAM_SYSTEM_VALUE,/**< InstanceId, PrimitiveID, etc. */ PROGRAM_UNDEFINED, /**< Invalid/TBD value */ PROGRAM_FILE_MAX } gl_register_file; +/** + * If the register file is PROGRAM_SYSTEM_VALUE, the register index will be + * one of these values. + */ +typedef enum +{ + SYSTEM_VALUE_FRONT_FACE, /**< Fragment shader only (not done yet) */ + SYSTEM_VALUE_INSTANCE_ID, /**< Vertex shader only */ + SYSTEM_VALUE_MAX /**< Number of values */ +} gl_system_value; + + /** Vertex and fragment instructions */ struct prog_instruction; struct gl_program_parameter_list; @@ -1774,6 +1787,7 @@ struct gl_program GLbitfield InputsRead; /**< Bitmask of which input regs are read */ GLbitfield64 OutputsWritten; /**< Bitmask of which output regs are written */ + GLbitfield SystemValuesRead; /**< Bitmask of SYSTEM_VALUE_x inputs used */ GLbitfield InputFlags[MAX_PROGRAM_INPUTS]; /**< PROG_PARAM_BIT_x flags */ GLbitfield OutputFlags[MAX_PROGRAM_OUTPUTS]; /**< PROG_PARAM_BIT_x flags */ GLbitfield TexturesUsed[MAX_TEXTURE_UNITS]; /**< TEXTURE_x_BIT bitmask */ From 379332f629153220614e651225b0521cd64c98b9 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 8 Dec 2010 18:24:48 -0700 Subject: [PATCH 008/164] mesa: program printing for PROGRAM_SYSTEM_VALUE --- src/mesa/program/prog_print.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/mesa/program/prog_print.c b/src/mesa/program/prog_print.c index abebf392c0a..484596af760 100644 --- a/src/mesa/program/prog_print.c +++ b/src/mesa/program/prog_print.c @@ -72,6 +72,8 @@ _mesa_register_file_name(gl_register_file f) return "ADDR"; case PROGRAM_SAMPLER: return "SAMPLER"; + case PROGRAM_SYSTEM_VALUE: + return "SYSVAL"; case PROGRAM_UNDEFINED: return "UNDEFINED"; default: @@ -310,6 +312,9 @@ reg_string(gl_register_file f, GLint index, gl_prog_print_mode mode, case PROGRAM_UNIFORM: /* extension */ sprintf(str, "uniform[%s%d]", addr, index); break; + case PROGRAM_SYSTEM_VALUE: + sprintf(str, "sysvalue[%s%d]", addr, index); + break; case PROGRAM_STATE_VAR: { struct gl_program_parameter *param From 7ce186358e881d1e30eda716a8dea73d2dab2ee9 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 8 Dec 2010 18:25:38 -0700 Subject: [PATCH 009/164] glsl: add support for system values and GL_ARB_draw_instanced --- src/glsl/glsl_parser_extras.cpp | 9 +++++++++ src/glsl/glsl_parser_extras.h | 2 ++ src/glsl/ir.h | 1 + src/glsl/ir_set_program_inouts.cpp | 9 +++++++-- src/glsl/ir_variable.cpp | 32 ++++++++++++++++++++++++++++++ src/glsl/main.cpp | 1 + 6 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp index 302cfbc5668..f7df3011eab 100644 --- a/src/glsl/glsl_parser_extras.cpp +++ b/src/glsl/glsl_parser_extras.cpp @@ -180,6 +180,15 @@ _mesa_glsl_process_extension(const char *name, YYLTYPE *name_locp, state->ARB_draw_buffers_enable = (ext_mode != extension_disable); state->ARB_draw_buffers_warn = (ext_mode == extension_warn); } + } else if (strcmp(name, "GL_ARB_draw_instanced") == 0) { + /* This extension is only supported in vertex shaders. + */ + if (state->target != vertex_shader) { + unsupported = true; + } else { + state->ARB_draw_instanced_enable = (ext_mode != extension_disable); + state->ARB_draw_instanced_warn = (ext_mode == extension_warn); + } } else if (strcmp(name, "GL_ARB_explicit_attrib_location") == 0) { state->ARB_explicit_attrib_location_enable = (ext_mode != extension_disable); diff --git a/src/glsl/glsl_parser_extras.h b/src/glsl/glsl_parser_extras.h index 98c4e70173d..9b5f38a2bf1 100644 --- a/src/glsl/glsl_parser_extras.h +++ b/src/glsl/glsl_parser_extras.h @@ -124,6 +124,8 @@ struct _mesa_glsl_parse_state { /*@{*/ unsigned ARB_draw_buffers_enable:1; unsigned ARB_draw_buffers_warn:1; + unsigned ARB_draw_instanced_enable:1; + unsigned ARB_draw_instanced_warn:1; unsigned ARB_explicit_attrib_location_enable:1; unsigned ARB_explicit_attrib_location_warn:1; unsigned ARB_fragment_coord_conventions_enable:1; diff --git a/src/glsl/ir.h b/src/glsl/ir.h index 850033b185f..8023a78dc27 100644 --- a/src/glsl/ir.h +++ b/src/glsl/ir.h @@ -224,6 +224,7 @@ enum ir_variable_mode { ir_var_in, ir_var_out, ir_var_inout, + ir_var_system_value, /**< Ex: front-face, instance-id, etc. */ ir_var_temporary /**< Temporary variable generated during compilation. */ }; diff --git a/src/glsl/ir_set_program_inouts.cpp b/src/glsl/ir_set_program_inouts.cpp index b3f1cc0d8b5..31a122c6bb9 100644 --- a/src/glsl/ir_set_program_inouts.cpp +++ b/src/glsl/ir_set_program_inouts.cpp @@ -90,7 +90,10 @@ mark(struct gl_program *prog, ir_variable *var, int index) index *= element_size; for (int i = 0; i < element_size; i++) { - if (var->mode == ir_var_in) + if (var->mode == ir_var_system_value) { + prog->SystemValuesRead |= (1 << (var->location + index + i)); + } + else if (var->mode == ir_var_in) prog->InputsRead |= BITFIELD64_BIT(var->location + index + i); else prog->OutputsWritten |= BITFIELD64_BIT(var->location + index + i); @@ -139,7 +142,8 @@ ir_visitor_status ir_set_program_inouts_visitor::visit(ir_variable *ir) { if (ir->mode == ir_var_in || - ir->mode == ir_var_out) { + ir->mode == ir_var_out || + ir->mode == ir_var_system_value) { hash_table_insert(this->ht, ir, ir); } @@ -163,5 +167,6 @@ do_set_program_inouts(exec_list *instructions, struct gl_program *prog) prog->InputsRead = 0; prog->OutputsWritten = 0; + prog->SystemValuesRead = 0; visit_list_elements(&v, instructions); } diff --git a/src/glsl/ir_variable.cpp b/src/glsl/ir_variable.cpp index 6b9b29458d0..4d105400dd9 100644 --- a/src/glsl/ir_variable.cpp +++ b/src/glsl/ir_variable.cpp @@ -30,6 +30,11 @@ static void generate_ARB_draw_buffers_variables(exec_list *, struct _mesa_glsl_parse_state *, bool, _mesa_glsl_parser_targets); +static void +generate_ARB_draw_instanced_variables(exec_list *, + struct _mesa_glsl_parse_state *, + bool, _mesa_glsl_parser_targets); + static ir_variable * add_variable(const char *name, enum ir_variable_mode mode, int slot, const glsl_type *type, exec_list *instructions, @@ -41,6 +46,7 @@ add_variable(const char *name, enum ir_variable_mode mode, int slot, case ir_var_auto: case ir_var_in: case ir_var_uniform: + case ir_var_system_value: var->read_only = true; break; case ir_var_inout: @@ -324,8 +330,13 @@ initialize_vs_variables(exec_list *instructions, generate_130_vs_variables(instructions, state); break; } + + if (state->ARB_draw_instanced_enable) + generate_ARB_draw_instanced_variables(instructions, state, false, + vertex_shader); } + /* This function should only be called for ES, not desktop GL. */ static void generate_100ES_fs_variables(exec_list *instructions, @@ -422,6 +433,27 @@ generate_ARB_draw_buffers_variables(exec_list *instructions, } } + +static void +generate_ARB_draw_instanced_variables(exec_list *instructions, + struct _mesa_glsl_parse_state *state, + bool warn, + _mesa_glsl_parser_targets target) +{ + /* gl_InstanceIDARB is only available in the vertex shader. + */ + if (target == vertex_shader) { + ir_variable *const inst = + add_variable("gl_InstanceIDARB", ir_var_system_value, + SYSTEM_VALUE_INSTANCE_ID, + glsl_type::int_type, instructions, state->symbols); + + if (warn) + inst->warn_extension = "GL_ARB_draw_instanced"; + } +} + + static void generate_ARB_shader_stencil_export_variables(exec_list *instructions, struct _mesa_glsl_parse_state *state, diff --git a/src/glsl/main.cpp b/src/glsl/main.cpp index 33028512644..36597d0bcd0 100644 --- a/src/glsl/main.cpp +++ b/src/glsl/main.cpp @@ -78,6 +78,7 @@ initialize_context(struct gl_context *ctx, gl_api api) ctx->API = api; ctx->Extensions.ARB_draw_buffers = GL_TRUE; + ctx->Extensions.ARB_draw_instanced = GL_TRUE; ctx->Extensions.ARB_fragment_coord_conventions = GL_TRUE; ctx->Extensions.EXT_texture_array = GL_TRUE; ctx->Extensions.NV_texture_rectangle = GL_TRUE; From 691048a22acf930e263711cf206e792a1b52f342 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 8 Dec 2010 18:25:58 -0700 Subject: [PATCH 010/164] mesa: ir_to_mesa support for system values --- src/mesa/program/ir_to_mesa.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp index 8f75c82c3eb..a5b17bb3284 100644 --- a/src/mesa/program/ir_to_mesa.cpp +++ b/src/mesa/program/ir_to_mesa.cpp @@ -1460,6 +1460,7 @@ ir_to_mesa_visitor::visit(ir_dereference_variable *ir) case ir_var_in: case ir_var_out: case ir_var_inout: + case ir_var_system_value: /* The linker assigns locations for varyings and attributes, * including deprecated builtins (like gl_Color), user-assign * generic attributes (glBindVertexLocation), and @@ -1482,6 +1483,10 @@ ir_to_mesa_visitor::visit(ir_dereference_variable *ir) ir->var->type->gl_type, ir->var->location - VERT_ATTRIB_GENERIC0); } + } else if (ir->var->mode == ir_var_system_value) { + entry = new(mem_ctx) variable_storage(ir->var, + PROGRAM_SYSTEM_VALUE, + ir->var->location); } else { entry = new(mem_ctx) variable_storage(ir->var, PROGRAM_OUTPUT, From 0be042cb4d256393750f7060d79bdaa2cd47d72e Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 8 Dec 2010 19:00:32 -0700 Subject: [PATCH 011/164] draw: setup instance ID for VS interpreter --- src/gallium/auxiliary/draw/draw_vs_exec.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/gallium/auxiliary/draw/draw_vs_exec.c b/src/gallium/auxiliary/draw/draw_vs_exec.c index dab3eb1ca8e..08608b480e0 100644 --- a/src/gallium/auxiliary/draw/draw_vs_exec.c +++ b/src/gallium/auxiliary/draw/draw_vs_exec.c @@ -99,6 +99,12 @@ vs_exec_run_linear( struct draw_vertex_shader *shader, tgsi_exec_set_constant_buffers(machine, PIPE_MAX_CONSTANT_BUFFERS, constants, const_size); + if (shader->info.uses_instanceid) { + unsigned i = machine->SysSemanticToIndex[TGSI_SEMANTIC_INSTANCEID]; + assert(i < Elements(machine->SystemValue)); + machine->SystemValue[i][0] = shader->draw->instance_id; + } + for (i = 0; i < count; i += MAX_TGSI_VERTICES) { unsigned int max_vertices = MIN2(MAX_TGSI_VERTICES, count - i); From 2d62fb6c3f7dd7261513253767cc63ff00fad9bb Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 8 Dec 2010 19:00:44 -0700 Subject: [PATCH 012/164] draw: setup instance ID for SSE generator --- src/gallium/auxiliary/draw/draw_vs_sse.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/gallium/auxiliary/draw/draw_vs_sse.c b/src/gallium/auxiliary/draw/draw_vs_sse.c index 0b0c6077c6f..672efe25cca 100644 --- a/src/gallium/auxiliary/draw/draw_vs_sse.c +++ b/src/gallium/auxiliary/draw/draw_vs_sse.c @@ -71,6 +71,12 @@ vs_sse_prepare( struct draw_vertex_shader *base, struct tgsi_exec_machine *machine = shader->machine; machine->Samplers = draw->vs.samplers; + + if (base->info.uses_instanceid) { + unsigned i = machine->SysSemanticToIndex[TGSI_SEMANTIC_INSTANCEID]; + assert(i < Elements(machine->SystemValue)); + machine->SystemValue[i][0] = base->draw->instance_id; + } } From 2b5e1e5287df5cae218b6f83d2638853d250aff9 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 8 Dec 2010 19:01:15 -0700 Subject: [PATCH 013/164] st/mesa: translate shader system inputs --- src/mesa/state_tracker/st_mesa_to_tgsi.c | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.c b/src/mesa/state_tracker/st_mesa_to_tgsi.c index c5c239b2c95..96c8aeb6e8d 100644 --- a/src/mesa/state_tracker/st_mesa_to_tgsi.c +++ b/src/mesa/state_tracker/st_mesa_to_tgsi.c @@ -72,6 +72,7 @@ struct st_translate { struct ureg_src inputs[PIPE_MAX_SHADER_INPUTS]; struct ureg_dst address[1]; struct ureg_src samplers[PIPE_MAX_SAMPLERS]; + struct ureg_src systemValues[SYSTEM_VALUE_MAX]; /* Extra info for handling point size clamping in vertex shader */ struct ureg_dst pointSizeResult; /**< Actual point size output register */ @@ -104,6 +105,13 @@ struct st_translate { }; +/** Map Mesa's SYSTEM_VALUE_x to TGSI_SEMANTIC_x */ +static unsigned mesa_sysval_to_semantic[SYSTEM_VALUE_MAX] = { + TGSI_SEMANTIC_FACE, + TGSI_SEMANTIC_INSTANCEID +}; + + /** * Make note of a branch to a label in the TGSI code. * After we've emitted all instructions, we'll go over the list @@ -245,6 +253,10 @@ src_register( struct st_translate *t, case PROGRAM_ADDRESS: return ureg_src(t->address[index]); + case PROGRAM_SYSTEM_VALUE: + assert(index < Elements(t->systemValues)); + return t->systemValues[index]; + default: debug_assert( 0 ); return ureg_src_undef(); @@ -1076,6 +1088,21 @@ st_translate_mesa_program( t->address[0] = ureg_DECL_address( ureg ); } + /* Declare misc input registers + */ + { + GLbitfield sysInputs = program->SystemValuesRead; + unsigned numSys = 0; + for (i = 0; sysInputs; i++) { + if (sysInputs & (1 << i)) { + unsigned semName = mesa_sysval_to_semantic[i]; + t->systemValues[i] = ureg_DECL_system_value(ureg, numSys, semName, 0); + numSys++; + sysInputs &= ~(1 << i); + } + } + } + if (program->IndirectRegisterFiles & (1 << PROGRAM_TEMPORARY)) { /* If temps are accessed with indirect addressing, declare temporaries * in sequential order. Else, we declare them on demand elsewhere. From 1d6f3543a063ab9e740fd0c149dcce26c282d773 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 8 Dec 2010 19:02:14 -0700 Subject: [PATCH 014/164] gallivm/llvmpipe: implement system values and instanceID --- src/gallium/auxiliary/draw/draw_llvm.c | 21 ++++-- src/gallium/auxiliary/gallivm/lp_bld_tgsi.h | 8 +++ .../auxiliary/gallivm/lp_bld_tgsi_soa.c | 71 +++++++++++++++++++ src/gallium/drivers/llvmpipe/lp_state_fs.c | 3 +- 4 files changed, 98 insertions(+), 5 deletions(-) diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c index 2b5f01cda74..eb162fb0f62 100644 --- a/src/gallium/auxiliary/draw/draw_llvm.c +++ b/src/gallium/auxiliary/draw/draw_llvm.c @@ -340,6 +340,7 @@ generate_vs(struct draw_llvm *llvm, LLVMBuilderRef builder, LLVMValueRef (*outputs)[NUM_CHANNELS], const LLVMValueRef (*inputs)[NUM_CHANNELS], + LLVMValueRef system_values_array, LLVMValueRef context_ptr, struct lp_build_sampler_soa *draw_sampler) { @@ -371,6 +372,7 @@ generate_vs(struct draw_llvm *llvm, vs_type, NULL /*struct lp_build_mask_context *mask*/, consts_ptr, + system_values_array, NULL /*pos*/, inputs, outputs, @@ -1011,7 +1013,9 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant) LLVMValueRef start, end, count, stride, step, io_itr; LLVMValueRef io_ptr, vbuffers_ptr, vb_ptr; LLVMValueRef instance_id; + LLVMValueRef system_values_array; struct draw_context *draw = llvm->draw; + const struct tgsi_shader_info *vs_info = &draw->vs.vertex_shader->info; unsigned i, j; struct lp_build_context bld; struct lp_build_loop_state lp_loop; @@ -1070,6 +1074,9 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant) lp_build_context_init(&bld, builder, lp_type_int(32)); + system_values_array = lp_build_system_values_array(builder, vs_info, + instance_id, NULL); + end = lp_build_add(&bld, start, count); step = LLVMConstInt(LLVMInt32Type(), max_vertices, 0); @@ -1126,6 +1133,7 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant) builder, outputs, ptr_aos, + system_values_array, context_ptr, sampler); @@ -1156,8 +1164,7 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant) /* store clipmask in vertex header and positions in data */ convert_to_aos(builder, io, outputs, clipmask, - draw->vs.vertex_shader->info.num_outputs, - max_vertices); + vs_info->num_outputs, max_vertices); } lp_build_loop_end_cond(builder, end, step, LLVMIntUGE, &lp_loop); @@ -1207,7 +1214,9 @@ draw_llvm_generate_elts(struct draw_llvm *llvm, struct draw_llvm_variant *varian LLVMValueRef fetch_elts, fetch_count, stride, step, io_itr; LLVMValueRef io_ptr, vbuffers_ptr, vb_ptr; LLVMValueRef instance_id; + LLVMValueRef system_values_array; struct draw_context *draw = llvm->draw; + const struct tgsi_shader_info *vs_info = &draw->vs.vertex_shader->info; unsigned i, j; struct lp_build_context bld; struct lp_build_loop_state lp_loop; @@ -1268,6 +1277,10 @@ draw_llvm_generate_elts(struct draw_llvm *llvm, struct draw_llvm_variant *varian lp_build_context_init(&bld, builder, lp_type_int(32)); + system_values_array = lp_build_system_values_array(builder, vs_info, + instance_id, NULL); + + step = LLVMConstInt(LLVMInt32Type(), max_vertices, 0); /* code generated texture sampling */ @@ -1332,6 +1345,7 @@ draw_llvm_generate_elts(struct draw_llvm *llvm, struct draw_llvm_variant *varian builder, outputs, ptr_aos, + system_values_array, context_ptr, sampler); @@ -1365,8 +1379,7 @@ draw_llvm_generate_elts(struct draw_llvm *llvm, struct draw_llvm_variant *varian * and transformed positions in data */ convert_to_aos(builder, io, outputs, clipmask, - draw->vs.vertex_shader->info.num_outputs, - max_vertices); + vs_info->num_outputs, max_vertices); } lp_build_loop_end_cond(builder, fetch_count, step, LLVMIntUGE, &lp_loop); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h index a4d3b750c3c..694818ccfb8 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h @@ -179,6 +179,7 @@ lp_build_tgsi_soa(LLVMBuilderRef builder, struct lp_type type, struct lp_build_mask_context *mask, LLVMValueRef consts_ptr, + LLVMValueRef system_values_array, const LLVMValueRef *pos, const LLVMValueRef (*inputs)[4], LLVMValueRef (*outputs)[4], @@ -198,4 +199,11 @@ lp_build_tgsi_aos(LLVMBuilderRef builder, const struct tgsi_shader_info *info); +LLVMValueRef +lp_build_system_values_array(LLVMBuilderRef builder, + const struct tgsi_shader_info *info, + LLVMValueRef instance_id, + LLVMValueRef facing); + + #endif /* LP_BLD_TGSI_H */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c index 7f0f058c222..3fdfac95a0a 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c @@ -156,6 +156,8 @@ struct lp_build_tgsi_soa_context */ LLVMValueRef inputs_array; + LLVMValueRef system_values_array; + const struct tgsi_shader_info *info; /** bitmask indicating which register files are accessed indirectly */ unsigned indirect_files; @@ -732,6 +734,22 @@ emit_fetch( } break; + case TGSI_FILE_SYSTEM_VALUE: + assert(!reg->Register.Indirect); + { + LLVMValueRef index; /* index into the system value array */ + LLVMValueRef scalar, scalar_ptr; + + index = lp_build_const_int32(reg->Register.Index * 4 + swizzle); + + scalar_ptr = LLVMBuildGEP(bld->base.builder, bld->system_values_array, + &index, 1, ""); + scalar = LLVMBuildLoad(bld->base.builder, scalar_ptr, ""); + + res = lp_build_broadcast_scalar(&bld->base, scalar); + } + break; + default: assert(0 && "invalid src register in emit_fetch()"); return bld->base.undef; @@ -2289,6 +2307,7 @@ lp_build_tgsi_soa(LLVMBuilderRef builder, struct lp_type type, struct lp_build_mask_context *mask, LLVMValueRef consts_ptr, + LLVMValueRef system_values_array, const LLVMValueRef *pos, const LLVMValueRef (*inputs)[NUM_CHANNELS], LLVMValueRef (*outputs)[NUM_CHANNELS], @@ -2375,6 +2394,8 @@ lp_build_tgsi_soa(LLVMBuilderRef builder, } } + bld.system_values_array = system_values_array; + tgsi_parse_init( &parse, tokens ); while( !tgsi_parse_end_of_tokens( &parse ) ) { @@ -2476,3 +2497,53 @@ lp_build_tgsi_soa(LLVMBuilderRef builder, FREE( bld.instructions ); } + +/** + * Build up the system values array out of individual values such as + * the instance ID, front-face, primitive ID, etc. The shader info is + * used to determine which system values are needed and where to put + * them in the system values array. + * + * XXX only instance ID is implemented at this time. + * + * The system values register file is similar to the constants buffer. + * Example declaration: + * DCL SV[0], INSTANCEID + * Example instruction: + * MOVE foo, SV[0].xxxx; + * + * \return LLVM float array (interpreted as float [][4]) + */ +LLVMValueRef +lp_build_system_values_array(LLVMBuilderRef builder, + const struct tgsi_shader_info *info, + LLVMValueRef instance_id, + LLVMValueRef facing) +{ + LLVMValueRef size = lp_build_const_int32(4 * info->num_system_values); + LLVMValueRef array = lp_build_array_alloca(builder, LLVMFloatType(), + size, "sysvals_array"); + unsigned i; + + for (i = 0; i < info->num_system_values; i++) { + LLVMValueRef index = lp_build_const_int32(i * 4); + LLVMValueRef ptr, value; + + switch (info->system_value_semantic_name[i]) { + case TGSI_SEMANTIC_INSTANCEID: + /* convert instance ID from int to float */ + value = LLVMBuildSIToFP(builder, instance_id, LLVMFloatType(), + "sysval_instanceid"); + break; + case TGSI_SEMANTIC_FACE: + /* fall-through */ + default: + assert(0 && "unexpected semantic in build_system_values_array()"); + } + + ptr = LLVMBuildGEP(builder, array, &index, 1, ""); + LLVMBuildStore(builder, value, ptr); + } + + return array; +} diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c index 48971510f21..cd67d488616 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@ -334,7 +334,8 @@ generate_fs(struct lp_fragment_shader *shader, /* Build the actual shader */ lp_build_tgsi_soa(builder, tokens, type, &mask, - consts_ptr, interp->pos, interp->inputs, + consts_ptr, NULL, /* sys values array */ + interp->pos, interp->inputs, outputs, sampler, &shader->info.base); From cf2184f05717deb860aaaa031fbac48c89865ddd Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 8 Dec 2010 19:02:43 -0700 Subject: [PATCH 015/164] softpipe: enable instanced drawing cap --- src/gallium/drivers/softpipe/sp_screen.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gallium/drivers/softpipe/sp_screen.c b/src/gallium/drivers/softpipe/sp_screen.c index 5f171d314a3..9b54babdfb7 100644 --- a/src/gallium/drivers/softpipe/sp_screen.c +++ b/src/gallium/drivers/softpipe/sp_screen.c @@ -123,6 +123,8 @@ softpipe_get_param(struct pipe_screen *screen, enum pipe_cap param) return 0; case PIPE_CAP_SHADER_STENCIL_EXPORT: return 1; + case PIPE_CAP_INSTANCED_DRAWING: + return 1; default: return 0; } From dcb48e7eb41efb2d2ae12da0f59710334cf36796 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 8 Dec 2010 19:06:22 -0700 Subject: [PATCH 016/164] llvmpipe: enable instanced drawing cap --- src/gallium/drivers/llvmpipe/lp_screen.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c b/src/gallium/drivers/llvmpipe/lp_screen.c index ad0ea75b3a3..43904343c3a 100644 --- a/src/gallium/drivers/llvmpipe/lp_screen.c +++ b/src/gallium/drivers/llvmpipe/lp_screen.c @@ -164,6 +164,8 @@ llvmpipe_get_param(struct pipe_screen *screen, enum pipe_cap param) return 1; case PIPE_CAP_DEPTH_CLAMP: return 0; + case PIPE_CAP_INSTANCED_DRAWING: + return 1; default: return 0; } From 6a0d3b7696260f449a1d0c5222814568764e8110 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 10 Dec 2010 09:29:00 -0700 Subject: [PATCH 017/164] mesa: implement system values in program interpreter --- src/mesa/program/prog_execute.c | 4 ++++ src/mesa/program/prog_execute.h | 1 + 2 files changed, 5 insertions(+) diff --git a/src/mesa/program/prog_execute.c b/src/mesa/program/prog_execute.c index 1d97a077f52..c20347fe678 100644 --- a/src/mesa/program/prog_execute.c +++ b/src/mesa/program/prog_execute.c @@ -159,6 +159,10 @@ get_src_register_pointer(const struct prog_src_register *source, return ZeroVec; return prog->Parameters->ParameterValues[reg]; + case PROGRAM_SYSTEM_VALUE: + assert(reg < Elements(machine->SystemValues)); + return machine->SystemValues[reg]; + default: _mesa_problem(NULL, "Invalid src register file %d in get_src_register_pointer()", diff --git a/src/mesa/program/prog_execute.h b/src/mesa/program/prog_execute.h index cefd468c36b..cdf37082a00 100644 --- a/src/mesa/program/prog_execute.h +++ b/src/mesa/program/prog_execute.h @@ -61,6 +61,7 @@ struct gl_program_machine GLfloat (*EnvParams)[4]; /**< Vertex or Fragment env parameters */ GLuint CondCodes[4]; /**< COND_* value for x/y/z/w */ GLint AddressReg[MAX_PROGRAM_ADDRESS_REGS][4]; + GLfloat SystemValues[SYSTEM_VALUE_MAX][4]; const GLubyte *Samplers; /** Array mapping sampler var to tex unit */ From a63486ac680acc0bfb895037aca130a457caa01a Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 10 Dec 2010 09:29:13 -0700 Subject: [PATCH 018/164] tnl: implement instanced drawing --- src/mesa/tnl/t_context.h | 2 ++ src/mesa/tnl/t_draw.c | 19 ++++++++++++------- src/mesa/tnl/t_vb_program.c | 7 +++++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/mesa/tnl/t_context.h b/src/mesa/tnl/t_context.h index bc01646247c..6a9444216c0 100644 --- a/src/mesa/tnl/t_context.h +++ b/src/mesa/tnl/t_context.h @@ -527,6 +527,8 @@ typedef struct GLubyte *block[VERT_ATTRIB_MAX]; GLuint nr_blocks; + GLuint CurInstance; + } TNLcontext; diff --git a/src/mesa/tnl/t_draw.c b/src/mesa/tnl/t_draw.c index 30f1bf323cb..bdb893eba22 100644 --- a/src/mesa/tnl/t_draw.c +++ b/src/mesa/tnl/t_draw.c @@ -453,6 +453,7 @@ void _tnl_draw_prims( struct gl_context *ctx, */ struct gl_buffer_object *bo[VERT_ATTRIB_MAX + 1]; GLuint nr_bo = 0; + GLuint inst; for (i = 0; i < nr_prims;) { GLuint this_nr_prims; @@ -470,15 +471,19 @@ void _tnl_draw_prims( struct gl_context *ctx, /* Binding inputs may imply mapping some vertex buffer objects. * They will need to be unmapped below. */ - bind_prims(ctx, &prim[i], this_nr_prims); - bind_inputs(ctx, arrays, max_index + prim[i].basevertex + 1, - bo, &nr_bo); - bind_indices(ctx, ib, bo, &nr_bo); + for (inst = 0; inst < prim[i].num_instances; inst++) { - TNL_CONTEXT(ctx)->Driver.RunPipeline(ctx); + bind_prims(ctx, &prim[i], this_nr_prims); + bind_inputs(ctx, arrays, max_index + prim[i].basevertex + 1, + bo, &nr_bo); + bind_indices(ctx, ib, bo, &nr_bo); - unmap_vbos(ctx, bo, nr_bo); - free_space(ctx); + tnl->CurInstance = inst; + TNL_CONTEXT(ctx)->Driver.RunPipeline(ctx); + + unmap_vbos(ctx, bo, nr_bo); + free_space(ctx); + } i += this_nr_prims; } diff --git a/src/mesa/tnl/t_vb_program.c b/src/mesa/tnl/t_vb_program.c index 76f8fde3f52..a1853689a43 100644 --- a/src/mesa/tnl/t_vb_program.c +++ b/src/mesa/tnl/t_vb_program.c @@ -218,7 +218,8 @@ _tnl_program_string(struct gl_context *ctx, GLenum target, struct gl_program *pr * Initialize virtual machine state prior to executing vertex program. */ static void -init_machine(struct gl_context *ctx, struct gl_program_machine *machine) +init_machine(struct gl_context *ctx, struct gl_program_machine *machine, + GLuint instID) { /* Input registers get initialized from the current vertex attribs */ memcpy(machine->VertAttribs, ctx->Current.Attrib, @@ -254,6 +255,8 @@ init_machine(struct gl_context *ctx, struct gl_program_machine *machine) machine->FetchTexelDeriv = NULL; /* not used by vertex programs */ machine->Samplers = ctx->VertexProgram._Current->Base.SamplerUnits; + + machine->SystemValues[SYSTEM_VALUE_INSTANCE_ID][0] = (GLfloat) instID; } @@ -339,7 +342,7 @@ run_vp( struct gl_context *ctx, struct tnl_pipeline_stage *stage ) for (i = 0; i < VB->Count; i++) { GLuint attr; - init_machine(ctx, &machine); + init_machine(ctx, &machine, tnl->CurInstance); #if 0 printf("Input %d: %f, %f, %f, %f\n", i, From b7c38734c9d85f9dad1796d97690be2d9c55c397 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 10 Dec 2010 09:29:41 -0700 Subject: [PATCH 019/164] mesa: enable GL_ARB_draw_instanced for software drivers --- src/mesa/main/extensions.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c index 3d5830c01cc..a7bdfcc0204 100644 --- a/src/mesa/main/extensions.c +++ b/src/mesa/main/extensions.c @@ -237,6 +237,7 @@ _mesa_enable_sw_extensions(struct gl_context *ctx) ctx->Extensions.ARB_depth_texture = GL_TRUE; /*ctx->Extensions.ARB_draw_buffers = GL_TRUE;*/ ctx->Extensions.ARB_draw_elements_base_vertex = GL_TRUE; + ctx->Extensions.ARB_draw_instanced = GL_TRUE; ctx->Extensions.ARB_explicit_attrib_location = GL_TRUE; ctx->Extensions.ARB_fragment_coord_conventions = GL_TRUE; #if FEATURE_ARB_fragment_program From 4eb7284ef98c24331761cbe683c5bd89058e3ad3 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 11 Jan 2011 15:13:49 -0800 Subject: [PATCH 020/164] i965: Tighten up the check for flow control interfering with coalescing. This greatly improves codegen for programs with flow control by allowing coalescing for all instructions at the top level, not just ones that follow the last flow control in the program. --- src/mesa/drivers/dri/i965/brw_fs.cpp | 38 +++++++++++++++++++--------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp index 22e6e2e7368..35bce0f397c 100644 --- a/src/mesa/drivers/dri/i965/brw_fs.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs.cpp @@ -2929,10 +2929,35 @@ bool fs_visitor::register_coalesce() { bool progress = false; + int if_depth = 0; + int loop_depth = 0; foreach_iter(exec_list_iterator, iter, this->instructions) { fs_inst *inst = (fs_inst *)iter.get(); + /* Make sure that we dominate the instructions we're going to + * scan for interfering with our coalescing, or we won't have + * scanned enough to see if anything interferes with our + * coalescing. We don't dominate the following instructions if + * we're in a loop or an if block. + */ + switch (inst->opcode) { + case BRW_OPCODE_DO: + loop_depth++; + break; + case BRW_OPCODE_WHILE: + loop_depth--; + break; + case BRW_OPCODE_IF: + if_depth++; + break; + case BRW_OPCODE_ENDIF: + if_depth--; + break; + } + if (loop_depth || if_depth) + continue; + if (inst->opcode != BRW_OPCODE_MOV || inst->predicated || inst->saturate || @@ -2950,14 +2975,6 @@ fs_visitor::register_coalesce() for (; scan_iter.has_next(); scan_iter.next()) { fs_inst *scan_inst = (fs_inst *)scan_iter.get(); - if (scan_inst->opcode == BRW_OPCODE_DO || - scan_inst->opcode == BRW_OPCODE_WHILE || - scan_inst->opcode == BRW_OPCODE_ENDIF) { - interfered = true; - iter = scan_iter; - break; - } - if (scan_inst->dst.file == GRF) { if (scan_inst->dst.reg == inst->dst.reg && (scan_inst->dst.reg_offset == inst->dst.reg_offset || @@ -2977,10 +2994,6 @@ fs_visitor::register_coalesce() continue; } - /* Update live interval so we don't have to recalculate. */ - this->virtual_grf_use[inst->src[0].reg] = MAX2(virtual_grf_use[inst->src[0].reg], - virtual_grf_use[inst->dst.reg]); - /* Rewrite the later usage to point at the source of the move to * be removed. */ @@ -3617,6 +3630,7 @@ brw_wm_fs_emit(struct brw_context *brw, struct brw_wm_compile *c) v.calculate_live_intervals(); progress = v.propagate_constants() || progress; progress = v.register_coalesce() || progress; + v.calculate_live_intervals(); progress = v.compute_to_mrf() || progress; progress = v.dead_code_eliminate() || progress; } while (progress); From 1412dea94953243b5cd3a452f676afd046101192 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Mon, 6 Dec 2010 16:00:24 -0800 Subject: [PATCH 021/164] glsl: Add type inference support for remaining expression opcodes. --- src/glsl/ir.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp index b8b0fed9d1c..742dd41b9f4 100644 --- a/src/glsl/ir.cpp +++ b/src/glsl/ir.cpp @@ -261,12 +261,38 @@ ir_expression::ir_expression(int op, ir_rvalue *op0) case ir_unop_floor: case ir_unop_fract: case ir_unop_round_even: + case ir_unop_sin: case ir_unop_cos: + case ir_unop_sin_reduced: + case ir_unop_cos_reduced: case ir_unop_dFdx: case ir_unop_dFdy: this->type = op0->type; break; + case ir_unop_f2i: + case ir_unop_b2i: + this->type = glsl_type::get_instance(GLSL_TYPE_INT, + op0->type->vector_elements, 1); + break; + + case ir_unop_b2f: + case ir_unop_i2f: + case ir_unop_u2f: + this->type = glsl_type::get_instance(GLSL_TYPE_FLOAT, + op0->type->vector_elements, 1); + break; + + case ir_unop_f2b: + case ir_unop_i2b: + this->type = glsl_type::get_instance(GLSL_TYPE_BOOL, + op0->type->vector_elements, 1); + break; + + case ir_unop_noise: + this->type = glsl_type::float_type; + break; + case ir_unop_any: this->type = glsl_type::bool_type; break; @@ -302,6 +328,8 @@ ir_expression::ir_expression(int op, ir_rvalue *op0, ir_rvalue *op1) case ir_binop_max: case ir_binop_pow: case ir_binop_mul: + case ir_binop_div: + case ir_binop_mod: if (op0->type->is_scalar()) { this->type = op1->type; } else if (op1->type->is_scalar()) { @@ -315,7 +343,11 @@ ir_expression::ir_expression(int op, ir_rvalue *op0, ir_rvalue *op1) break; case ir_binop_logic_and: + case ir_binop_logic_xor: case ir_binop_logic_or: + case ir_binop_bit_and: + case ir_binop_bit_xor: + case ir_binop_bit_or: if (op0->type->is_scalar()) { this->type = op1->type; } else if (op1->type->is_scalar()) { @@ -323,10 +355,26 @@ ir_expression::ir_expression(int op, ir_rvalue *op0, ir_rvalue *op1) } break; + case ir_binop_equal: + case ir_binop_nequal: + case ir_binop_lequal: + case ir_binop_gequal: + case ir_binop_less: + case ir_binop_greater: + assert(op0->type == op1->type); + this->type = glsl_type::get_instance(GLSL_TYPE_BOOL, + op0->type->vector_elements, 1); + break; + case ir_binop_dot: this->type = glsl_type::float_type; break; + case ir_binop_lshift: + case ir_binop_rshift: + this->type = op0->type; + break; + default: assert(!"not reached: missing automatic type setup for ir_expression"); this->type = glsl_type::float_type; From 49ed5bb28d501cd6751bd59dc25a60a4293bcd75 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Mon, 10 Jan 2011 12:39:46 +0800 Subject: [PATCH 022/164] targets/egl-static: New EGL target for scons. This target is based on and replaces egl-gdi. It is suitable for both windows and x11. --- src/egl/main/egldriver.c | 20 +- src/gallium/targets/egl-gdi/SConscript | 55 ----- .../egl-static.c => egl-static/egl.c} | 122 +++++----- src/gallium/targets/egl-static/egl_pipe.c | 216 ++++++++++++++++++ src/gallium/targets/egl-static/egl_pipe.h | 40 ++++ src/gallium/targets/egl-static/egl_st.c | 105 +++++++++ src/gallium/targets/egl-static/egl_st.h | 40 ++++ 7 files changed, 469 insertions(+), 129 deletions(-) delete mode 100644 src/gallium/targets/egl-gdi/SConscript rename src/gallium/targets/{egl-gdi/egl-static.c => egl-static/egl.c} (52%) create mode 100644 src/gallium/targets/egl-static/egl_pipe.c create mode 100644 src/gallium/targets/egl-static/egl_pipe.h create mode 100644 src/gallium/targets/egl-static/egl_st.c create mode 100644 src/gallium/targets/egl-static/egl_st.h diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c index 62c56955134..46876d00565 100644 --- a/src/egl/main/egldriver.c +++ b/src/egl/main/egldriver.c @@ -141,9 +141,6 @@ _eglOpenLibrary(const char *driverPath, lib_handle *handle) if (!lib) { _eglLog(_EGL_WARNING, "Could not open driver %s (%s)", driverPath, error); - if (!getenv("EGL_DRIVER")) - _eglLog(_EGL_WARNING, - "The driver can be overridden by setting EGL_DRIVER"); return NULL; } @@ -467,6 +464,19 @@ _eglAddUserDriver(void) } +/** + * Add egl_gallium to the module array. + */ +static void +_eglAddGalliumDriver(void) +{ +#ifndef _EGL_BUILT_IN_DRIVER_GALLIUM + void *external = (void *) "egl_gallium"; + _eglPreloadForEach(_eglGetSearchPath(), _eglLoaderFile, external); +#endif +} + + /** * Add built-in drivers to the module array. */ @@ -491,14 +501,12 @@ _eglAddBuiltInDrivers(void) static EGLBoolean _eglAddDrivers(void) { - void *external = (void *) "egl_gallium"; - if (_eglModules) return EGL_TRUE; /* the order here decides the priorities of the drivers */ _eglAddUserDriver(); - _eglPreloadForEach(_eglGetSearchPath(), _eglLoaderFile, external); + _eglAddGalliumDriver(); _eglAddBuiltInDrivers(); return (_eglModules != NULL); diff --git a/src/gallium/targets/egl-gdi/SConscript b/src/gallium/targets/egl-gdi/SConscript deleted file mode 100644 index d52eeb70fd5..00000000000 --- a/src/gallium/targets/egl-gdi/SConscript +++ /dev/null @@ -1,55 +0,0 @@ -####################################################################### -# SConscript for egl-gdi target - -Import('*') - -env = env.Clone() - -env.Append(CPPPATH = [ - '#/src/gallium/state_trackers/egl', - '#/src/gallium/state_trackers/vega', - '#/src/egl/main', - '#/src/mesa', -]) - -env.Append(CPPDEFINES = [ - 'FEATURE_VG=1', - 'GALLIUM_SOFTPIPE', - 'GALLIUM_RBUG', - 'GALLIUM_TRACE', -]) - -env.Append(LIBS = [ - 'gdi32', - 'user32', - 'kernel32', - 'ws2_32', -]) - -env.Prepend(LIBS = [ - st_egl_gdi, - ws_gdi, - identity, - trace, - rbug, - softpipe, - vgapi, - st_vega, - gallium, - egl, -]) - -if env['llvm']: - env.Append(CPPDEFINES = 'GALLIUM_LLVMPIPE') - env.Prepend(LIBS = [llvmpipe]) - -egl_gallium = env.SharedLibrary( - target ='egl_gallium', - source = 'egl-static.c', -) - -env['no_import_lib'] = 1 - -egl_gdi = env.InstallSharedLibrary(egl_gallium) - -env.Alias('egl-gdi', egl_gdi) diff --git a/src/gallium/targets/egl-gdi/egl-static.c b/src/gallium/targets/egl-static/egl.c similarity index 52% rename from src/gallium/targets/egl-gdi/egl-static.c rename to src/gallium/targets/egl-static/egl.c index da6e5ce3396..e617ff50208 100644 --- a/src/gallium/targets/egl-gdi/egl-static.c +++ b/src/gallium/targets/egl-static/egl.c @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 7.9 + * Version: 7.10 * - * Copyright (C) 2010 LunarG Inc. + * Copyright (C) 2010-2011 LunarG Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -27,41 +27,29 @@ */ #include "common/egl_g3d_loader.h" -#include "state_tracker/st_gl_api.h" -#include "vg_api.h" -#include "target-helpers/inline_sw_helper.h" -#include "target-helpers/inline_debug_helper.h" #include "egldriver.h" -static struct st_api *stapis[ST_API_COUNT]; +#include "egl_pipe.h" +#include "egl_st.h" + +static struct egl_g3d_loader egl_g3d_loader; + +static struct st_module { + boolean initialized; + struct st_api *stapi; +} st_modules[ST_API_COUNT]; static struct st_api * get_st_api(enum st_api_type api) { - struct st_api *stapi; + struct st_module *stmod = &st_modules[api]; - stapi = stapis[api]; - if (stapi) - return stapi; - - switch (api) { -#if FEATURE_GL || FEATURE_ES1 || FEATURE_ES2 - case ST_API_OPENGL: - stapi = st_gl_api_create(); - break; -#endif -#if FEATURE_VG - case ST_API_OPENVG: - stapi = (struct st_api *) vg_api_get(); - break; -#endif - default: - break; + if (!stmod->initialized) { + stmod->stapi = egl_st_create_api(api); + stmod->initialized = TRUE; } - stapis[api] = stapi; - - return stapi; + return stmod->stapi; } static struct st_api * @@ -73,71 +61,69 @@ guess_gl_api(enum st_profile_type profile) static struct pipe_screen * create_drm_screen(const char *name, int fd) { - return NULL; + return egl_pipe_create_drm_screen(name, fd); } static struct pipe_screen * create_sw_screen(struct sw_winsys *ws) { - struct pipe_screen *screen; + return egl_pipe_create_swrast_screen(ws); +} - screen = sw_screen_create(ws); - if (screen) - screen = debug_screen_wrap(screen); +static const struct egl_g3d_loader * +loader_init(void) +{ + int i; - return screen; + for (i = 0; i < ST_API_COUNT; i++) + egl_g3d_loader.profile_masks[i] = egl_st_get_profile_mask(i); + + egl_g3d_loader.get_st_api = get_st_api; + egl_g3d_loader.guess_gl_api = guess_gl_api; + egl_g3d_loader.create_drm_screen = create_drm_screen; + egl_g3d_loader.create_sw_screen = create_sw_screen; + + return &egl_g3d_loader; } static void -init_loader(struct egl_g3d_loader *loader) +loader_fini(void) { -#if FEATURE_GL - loader->profile_masks[ST_API_OPENGL] |= ST_PROFILE_DEFAULT_MASK; -#endif -#if FEATURE_ES1 - loader->profile_masks[ST_API_OPENGL] |= ST_PROFILE_OPENGL_ES1_MASK; -#endif -#if FEATURE_ES2 - loader->profile_masks[ST_API_OPENGL] |= ST_PROFILE_OPENGL_ES2_MASK; -#endif -#if FEATURE_VG - loader->profile_masks[ST_API_OPENVG] |= ST_PROFILE_DEFAULT_MASK; -#endif + int i; - loader->get_st_api = get_st_api; - loader->guess_gl_api = guess_gl_api; - loader->create_drm_screen = create_drm_screen; - loader->create_sw_screen = create_sw_screen; + for (i = 0; i < ST_API_COUNT; i++) { + struct st_module *stmod = &st_modules[i]; + + if (stmod->stapi) { + stmod->stapi->destroy(stmod->stapi); + stmod->stapi = NULL; + } + stmod->initialized = FALSE; + } } static void egl_g3d_unload(_EGLDriver *drv) { - int i; - egl_g3d_destroy_driver(drv); - - for (i = 0; i < ST_API_COUNT; i++) { - if (stapis[i]) { - stapis[i]->destroy(stapis[i]); - stapis[i] = NULL; - } - } + loader_fini(); } -static struct egl_g3d_loader loader; - _EGLDriver * -_eglMain(const char *args) +_EGL_MAIN(const char *args) { + const struct egl_g3d_loader *loader; _EGLDriver *drv; - init_loader(&loader); - drv = egl_g3d_create_driver(&loader); - if (drv) { - drv->Name = "Gallium"; - drv->Unload = egl_g3d_unload; + loader = loader_init(); + drv = egl_g3d_create_driver(loader); + if (!drv) { + loader_fini(); + return NULL; } + drv->Name = "Gallium"; + drv->Unload = egl_g3d_unload; + return drv; } diff --git a/src/gallium/targets/egl-static/egl_pipe.c b/src/gallium/targets/egl-static/egl_pipe.c new file mode 100644 index 00000000000..2684ede307f --- /dev/null +++ b/src/gallium/targets/egl-static/egl_pipe.c @@ -0,0 +1,216 @@ +/* + * Mesa 3-D graphics library + * Version: 7.10 + * + * Copyright (C) 2011 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ +#include "target-helpers/inline_debug_helper.h" +#include "target-helpers/inline_sw_helper.h" +#include "state_tracker/drm_driver.h" +#include "egl_pipe.h" + +/* for i915 */ +#include "i915/drm/i915_drm_public.h" +#include "i915/i915_public.h" +/* for i965 */ +#include "target-helpers/inline_wrapper_sw_helper.h" +#include "i965/drm/i965_drm_public.h" +#include "i965/brw_public.h" +/* for nouveau */ +#include "nouveau/drm/nouveau_drm_public.h" +/* for r300 */ +#include "radeon/drm/radeon_drm_public.h" +#include "r300/r300_public.h" +/* for r600 */ +#include "r600/drm/r600_drm_public.h" +#include "r600/r600_public.h" +/* for vmwgfx */ +#include "svga/drm/svga_drm_public.h" +#include "svga/svga_public.h" + +static struct pipe_screen * +pipe_i915_create_screen(int fd) +{ +#if _EGL_PIPE_I915 + struct i915_winsys *iws; + struct pipe_screen *screen; + + iws = i915_drm_winsys_create(fd); + if (!iws) + return NULL; + + screen = i915_screen_create(iws); + if (!screen) + return NULL; + + screen = debug_screen_wrap(screen); + + return screen; +#else + return NULL; +#endif +} + +static struct pipe_screen * +pipe_i965_create_screen(int fd) +{ +#if _EGL_PIPE_I965 + struct brw_winsys_screen *bws; + struct pipe_screen *screen; + + bws = i965_drm_winsys_screen_create(fd); + if (!bws) + return NULL; + + screen = brw_screen_create(bws); + if (!screen) + return NULL; + + screen = sw_screen_wrap(screen); + + screen = debug_screen_wrap(screen); + + return screen; +#else + return NULL; +#endif +} + +static struct pipe_screen * +pipe_nouveau_create_screen(int fd) +{ +#if _EGL_PIPE_NOUVEAU + struct pipe_screen *screen; + + screen = nouveau_drm_screen_create(fd); + if (!screen) + return NULL; + + screen = debug_screen_wrap(screen); + + return screen; +#else + return NULL; +#endif +} + +static struct pipe_screen * +pipe_r300_create_screen(int fd) +{ +#if _EGL_PIPE_R300 + struct r300_winsys_screen *sws; + struct pipe_screen *screen; + + sws = r300_drm_winsys_screen_create(fd); + if (!sws) + return NULL; + + screen = r300_screen_create(sws); + if (!screen) + return NULL; + + screen = debug_screen_wrap(screen); + + return screen; +#else + return NULL; +#endif +} + +static struct pipe_screen * +pipe_r600_create_screen(int fd) +{ +#if _EGL_PIPE_R600 + struct radeon *rw; + struct pipe_screen *screen; + + rw = r600_drm_winsys_create(fd); + if (!rw) + return NULL; + + screen = r600_screen_create(rw); + if (!screen) + return NULL; + + screen = debug_screen_wrap(screen); + + return screen; +#else + return NULL; +#endif +} + +static struct pipe_screen * +pipe_vmwgfx_create_screen(int fd) +{ +#if _EGL_PIPE_VMWGFX + struct svga_winsys_screen *sws; + struct pipe_screen *screen; + + sws = svga_drm_winsys_screen_create(fd); + if (!sws) + return NULL; + + screen = svga_screen_create(sws); + if (!screen) + return NULL; + + screen = debug_screen_wrap(screen); + + return screen; +#else + return NULL; +#endif +} + +struct pipe_screen * +egl_pipe_create_drm_screen(const char *name, int fd) +{ + if (strcmp(name, "i915") == 0) + return pipe_i915_create_screen(fd); + else if (strcmp(name, "i965") == 0) + return pipe_i965_create_screen(fd); + else if (strcmp(name, "nouveau") == 0) + return pipe_nouveau_create_screen(fd); + else if (strcmp(name, "r300") == 0) + return pipe_r300_create_screen(fd); + else if (strcmp(name, "r600") == 0) + return pipe_r600_create_screen(fd); + else if (strcmp(name, "vmwgfx") == 0) + return pipe_vmwgfx_create_screen(fd); + else + return NULL; +} + +struct pipe_screen * +egl_pipe_create_swrast_screen(struct sw_winsys *ws) +{ + struct pipe_screen *screen; + + screen = sw_screen_create(ws); + if (screen) + screen = debug_screen_wrap(screen); + + return screen; +} diff --git a/src/gallium/targets/egl-static/egl_pipe.h b/src/gallium/targets/egl-static/egl_pipe.h new file mode 100644 index 00000000000..569b2d067c4 --- /dev/null +++ b/src/gallium/targets/egl-static/egl_pipe.h @@ -0,0 +1,40 @@ +/* + * Mesa 3-D graphics library + * Version: 7.10 + * + * Copyright (C) 2011 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ +#ifndef _EGL_PIPE_H_ +#define _EGL_PIPE_H_ + +struct pipe_screen; +struct sw_winsys; + +struct pipe_screen * +egl_pipe_create_drm_screen(const char *name, int fd); + +struct pipe_screen * +egl_pipe_create_swrast_screen(struct sw_winsys *ws); + +#endif /* _EGL_PIPE_H_ */ diff --git a/src/gallium/targets/egl-static/egl_st.c b/src/gallium/targets/egl-static/egl_st.c new file mode 100644 index 00000000000..3db52621def --- /dev/null +++ b/src/gallium/targets/egl-static/egl_st.c @@ -0,0 +1,105 @@ +/* + * Mesa 3-D graphics library + * Version: 7.10 + * + * Copyright (C) 2011 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ +#include "util/u_debug.h" +#include "state_tracker/st_api.h" +#include "egl_st.h" + +/* for st/mesa */ +#include "state_tracker/st_gl_api.h" +/* for st/vega */ +#include "vg_api.h" + +static struct st_api * +st_GL_create_api(void) +{ +#if FEATURE_GL || FEATURE_ES1 || FEATURE_ES2 + return st_gl_api_create(); +#else + return NULL; +#endif +} + +static struct st_api * +st_OpenVG_create_api(void) +{ +#if FEATURE_VG + return (struct st_api *) vg_api_get(); +#else + return NULL; +#endif +} + +struct st_api * +egl_st_create_api(enum st_api_type api) +{ + struct st_api *stapi; + + switch (api) { + case ST_API_OPENGL: + stapi = st_GL_create_api(); + break; + case ST_API_OPENVG: + stapi = st_OpenVG_create_api(); + break; + default: + assert(!"Unknown API Type\n"); + stapi = NULL; + break; + } + + return stapi; +} + +uint +egl_st_get_profile_mask(enum st_api_type api) +{ + uint mask = 0x0; + + switch (api) { + case ST_API_OPENGL: +#if FEATURE_GL + mask |= ST_PROFILE_DEFAULT_MASK; +#endif +#if FEATURE_ES1 + mask |= ST_PROFILE_OPENGL_ES1_MASK; +#endif +#if FEATURE_ES2 + mask |= ST_PROFILE_OPENGL_ES2_MASK; +#endif + break; + case ST_API_OPENVG: +#if FEATURE_VG + mask |= ST_PROFILE_DEFAULT_MASK; +#endif + break; + default: + break; + } + + return mask; +} diff --git a/src/gallium/targets/egl-static/egl_st.h b/src/gallium/targets/egl-static/egl_st.h new file mode 100644 index 00000000000..ba82faf0b0e --- /dev/null +++ b/src/gallium/targets/egl-static/egl_st.h @@ -0,0 +1,40 @@ +/* + * Mesa 3-D graphics library + * Version: 7.10 + * + * Copyright (C) 2011 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ +#ifndef _EGL_ST_H_ +#define _EGL_ST_H_ + +#include "pipe/p_compiler.h" +#include "state_tracker/st_api.h" + +struct st_api * +egl_st_create_api(enum st_api_type api); + +uint +egl_st_get_profile_mask(enum st_api_type api); + +#endif /* _EGL_ST_H_ */ From a8b6b6555c7d6a02a3d095c72ebbdc218bc45cd3 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Sun, 9 Jan 2011 23:37:32 +0800 Subject: [PATCH 023/164] scons: Updates for targets/egl-static. Update SConscripts to re-enable or add support for EGL on windows and x11 platforms respectively. targets/egl-gdi is replaced by targets/egl-static, where "-static" means pipe drivers and state trackers are linked to statically by egl_gallium, and egl_gallium is a built-in driver of libEGL. There is no more egl_gallium.dll on Windows. --- src/SConscript | 6 +- src/egl/main/SConscript | 30 +++--- src/egl/main/egldriver.c | 3 + src/egl/main/egldriver.h | 4 + src/gallium/SConscript | 12 ++- src/gallium/state_trackers/egl/SConscript | 38 +++++-- src/gallium/targets/egl-static/SConscript | 122 ++++++++++++++++++++++ src/mapi/vgapi/SConscript | 5 +- 8 files changed, 187 insertions(+), 33 deletions(-) create mode 100644 src/gallium/targets/egl-static/SConscript diff --git a/src/SConscript b/src/SConscript index c42d9bff2d7..116c9b36e4e 100644 --- a/src/SConscript +++ b/src/SConscript @@ -1,16 +1,16 @@ Import('*') -SConscript('mapi/vgapi/SConscript') - if env['platform'] == 'windows': - SConscript('egl/main/SConscript') SConscript('talloc/SConscript') SConscript('glsl/SConscript') SConscript('mapi/glapi/SConscript') SConscript('mesa/SConscript') +SConscript('mapi/vgapi/SConscript') + if env['platform'] != 'embedded': + SConscript('egl/main/SConscript') SConscript('glut/glx/SConscript') SConscript('gallium/SConscript') diff --git a/src/egl/main/SConscript b/src/egl/main/SConscript index f001b81600f..8c57ceaf20f 100644 --- a/src/egl/main/SConscript +++ b/src/egl/main/SConscript @@ -7,13 +7,23 @@ Import('*') env = env.Clone() env.Append(CPPDEFINES = [ - '_EGL_NATIVE_PLATFORM=_EGL_PLATFORM_WINDOWS', + '_EGL_BUILT_IN_DRIVER_GALLIUM', '_EGL_DRIVER_SEARCH_DIR=\\"\\"', - '_EGL_OS_WINDOWS', - '_EGL_GET_CORE_ADDRESSES', - 'KHRONOS_DLL_EXPORTS', ]) +if env['platform'] == 'windows': + env.Append(CPPDEFINES = [ + '_EGL_NATIVE_PLATFORM=_EGL_PLATFORM_WINDOWS', + '_EGL_OS_WINDOWS', + '_EGL_GET_CORE_ADDRESSES', + 'KHRONOS_DLL_EXPORTS', + ]) +else: + env.Append(CPPDEFINES = [ + '_EGL_NATIVE_PLATFORM=_EGL_PLATFORM_X11', + '_EGL_OS_UNIX', + ]) + env.Append(CPPPATH = [ '#/include', ]) @@ -38,15 +48,9 @@ egl_sources = [ 'eglsync.c', ] -egl = env.SharedLibrary( - target = 'libEGL', - source = egl_sources + ['egl.def'], +egl = env.ConvenienceLibrary( + target = 'egl', + source = egl_sources, ) -installed_egl = env.InstallSharedLibrary(egl, version=(1, 4, 0)) - -env.Alias('egl', installed_egl) - -egl = [env.FindIxes(egl, 'LIBPREFIX', 'LIBSUFFIX')] - Export('egl') diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c index 46876d00565..b7c3de3e38e 100644 --- a/src/egl/main/egldriver.c +++ b/src/egl/main/egldriver.c @@ -37,6 +37,9 @@ const struct { const char *name; _EGLMain_t main; } _eglBuiltInDrivers[] = { +#ifdef _EGL_BUILT_IN_DRIVER_GALLIUM + { "egl_gallium", _eglBuiltInDriverGALLIUM }, +#endif #ifdef _EGL_BUILT_IN_DRIVER_DRI2 { "egl_dri2", _eglBuiltInDriverDRI2 }, #endif diff --git a/src/egl/main/egldriver.h b/src/egl/main/egldriver.h index 651788cb7ae..d6177579193 100644 --- a/src/egl/main/egldriver.h +++ b/src/egl/main/egldriver.h @@ -64,6 +64,10 @@ struct _egl_driver }; +extern _EGLDriver * +_eglBuiltInDriverGALLIUM(const char *args); + + extern _EGLDriver * _eglBuiltInDriverDRI2(const char *args); diff --git a/src/gallium/SConscript b/src/gallium/SConscript index 0efab834f66..2265f1de46c 100644 --- a/src/gallium/SConscript +++ b/src/gallium/SConscript @@ -55,6 +55,7 @@ SConscript('winsys/sw/null/SConscript') SConscript('state_trackers/python/SConscript') if env['platform'] != 'embedded': SConscript('state_trackers/vega/SConscript') + SConscript('state_trackers/egl/SConscript') if env['x11']: SConscript('state_trackers/glx/xlib/SConscript') @@ -66,10 +67,7 @@ if env['platform'] != 'embedded': SConscript('state_trackers/xorg/SConscript') if env['platform'] == 'windows': - SConscript([ - 'state_trackers/egl/SConscript', - 'state_trackers/wgl/SConscript', - ]) + SConscript('state_trackers/wgl/SConscript') # # Winsys @@ -85,6 +83,11 @@ SConscript([ 'targets/graw-null/SConscript', ]) +if env['platform'] != 'embedded': + SConscript([ + 'targets/egl-static/SConscript' + ]) + if env['x11']: SConscript([ 'targets/graw-xlib/SConscript', @@ -95,7 +98,6 @@ if env['platform'] == 'windows': SConscript([ 'targets/graw-gdi/SConscript', 'targets/libgl-gdi/SConscript', - #'egl-gdi/SConscript', ]) if env['dri']: diff --git a/src/gallium/state_trackers/egl/SConscript b/src/gallium/state_trackers/egl/SConscript index 50c76819954..9ade76ecbb2 100644 --- a/src/gallium/state_trackers/egl/SConscript +++ b/src/gallium/state_trackers/egl/SConscript @@ -10,11 +10,8 @@ env.Append(CPPPATH = [ '#/src/gallium/winsys/sw', '.', ]) -env.Append(CPPDEFINES = [ - 'HAVE_GDI_BACKEND', -]) -common_sources = [ +sources = [ 'common/egl_g3d.c', 'common/egl_g3d_api.c', 'common/egl_g3d_image.c', @@ -23,12 +20,31 @@ common_sources = [ 'common/native_helper.c', ] -gdi_sources = common_sources + [ - 'gdi/native_gdi.c', -] +if env['platform'] == 'windows': + env.Append(CPPDEFINES = ['HAVE_GDI_BACKEND']) + sources.append('gdi/native_gdi.c') +else: + if env['x11']: + env.Append(CPPDEFINES = ['HAVE_X11_BACKEND']) + env.Prepend(CPPPATH = [ + '#/src/glx', + '#/src/mapi', + ]) + sources.append([ + 'x11/native_x11.c', + 'x11/native_dri2.c', + 'x11/native_ximage.c', + 'x11/x11_screen.c', + 'x11/glxinit.c']) + if env['dri']: + env.Append(CPPDEFINES = ['GLX_DIRECT_RENDERING']) + sources.append(['#/src/glx/dri2.c']) + if env['drm']: + env.Append(CPPDEFINES = ['HAVE_DRM_BACKEND']) + sources.append(['drm/native_drm.c', 'drm/modeset.c']) -st_egl_gdi = env.ConvenienceLibrary( - target = 'st_egl_gdi', - source = gdi_sources, +st_egl = env.ConvenienceLibrary( + target = 'st_egl', + source = sources, ) -Export('st_egl_gdi') +Export('st_egl') diff --git a/src/gallium/targets/egl-static/SConscript b/src/gallium/targets/egl-static/SConscript new file mode 100644 index 00000000000..1fa40806319 --- /dev/null +++ b/src/gallium/targets/egl-static/SConscript @@ -0,0 +1,122 @@ +####################################################################### +# SConscript for egl-static target + +Import('*') + +env = env.Clone() + +env.Append(CPPPATH = [ + '#/include', + '#/src/egl/main', + '#/src/gallium/auxiliary', + '#/src/gallium/drivers', + '#/src/gallium/include', + '#/src/gallium/winsys', + '#/src/gallium/state_trackers/egl', + '#/src/gallium/state_trackers/vega', + '#/src/mesa', +]) + +env.Append(CPPDEFINES = [ + 'GALLIUM_SOFTPIPE', + 'GALLIUM_RBUG', + 'GALLIUM_TRACE', + 'GALLIUM_GALAHAD', + '_EGL_MAIN=_eglBuiltInDriverGALLIUM', +]) + +env.Prepend(LIBS = [ + softpipe, + rbug, + trace, + galahad, + gallium, + egl, +]) + +if env['llvm']: + env.Append(CPPDEFINES = ['GALLIUM_LLVMPIPE']) + env.Prepend(LIBS = [llvmpipe]) + +sources = [ + 'egl.c', + 'egl_pipe.c', + 'egl_st.c', +] + +if env['platform'] == 'windows': + sources.append('#src/egl/main/egl.def') + + env.Append(LIBS = [ + 'gdi32', + 'user32', + 'kernel32', + 'ws2_32', + ]) + + env.Prepend(LIBS = [ + st_egl, + ws_gdi, + ]) + + # OpenVG + env.Append(CPPDEFINES = ['FEATURE_VG=1']) + env.Prepend(LIBS = [vgapi, st_vega]) +else: + env.Prepend(LIBS = [ + st_egl, + ws_xlib, + ]) + + # OpenGL + env.Append(CPPDEFINES = ['FEATURE_GL=1']) + env.Prepend(LIBS = ['GL', 'talloc', glsl, mesa]) + + # OpenVG + env.Append(CPPDEFINES = ['FEATURE_VG=1']) + env.Prepend(LIBS = ['OpenVG', st_vega]) + + +if env['dri']: + env.ParseConfig('pkg-config --cflags --libs xfixes') + +# pipe drivers +if env['drm']: + env.ParseConfig('pkg-config --cflags --libs libdrm') + + if env['drm_intel']: + env.ParseConfig('pkg-config --cflags --libs libdrm_intel') + env.Append(CPPDEFINES = ['_EGL_PIPE_I915', '_EGL_PIPE_I965']) + env.Prepend(LIBS = [ + i915drm, + i915, + i965drm, + i965, + ]) + + if env['drm_radeon']: + env.ParseConfig('pkg-config --cflags --libs libdrm_radeon') + env.Append(CPPDEFINES = ['_EGL_PIPE_R300', '_EGL_PIPE_R600']) + env.Prepend(LIBS = [ + radeonwinsys, + r300, + r600winsys, + r600, + ]) + + env.Append(CPPDEFINES = ['_EGL_PIPE_VMWGFX']) + env.Prepend(LIBS = [ + svgadrm, + svga, + ]) + +egl_gallium = env.SharedLibrary( + target ='libEGL', + source = sources, +) + +env.Depends(egl_gallium, [vgapi]) + +egl_gallium = env.InstallSharedLibrary(egl_gallium, version=(1, 4, 0)) + +env.Alias('egl-gallium', egl_gallium) diff --git a/src/mapi/vgapi/SConscript b/src/mapi/vgapi/SConscript index 42d86b69eef..8d671597859 100644 --- a/src/mapi/vgapi/SConscript +++ b/src/mapi/vgapi/SConscript @@ -51,6 +51,9 @@ if env['platform'] != 'winddk': env.InstallSharedLibrary(openvg, version=(1, 0, 0)) - vgapi = [env.FindIxes(openvg, 'LIBPREFIX', 'LIBSUFFIX')] + if env['platform'] == 'windows': + vgapi = env.FindIxes(openvg, 'LIBPREFIX', 'LIBSUFFIX') + else: + vgapi = env.FindIxes(openvg, 'SHLIBPREFIX', 'SHLIBSUFFIX') Export(['vgapi']) From 39812c48dfb18e6c3b896db8a8395eeebef8cc1b Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Wed, 12 Jan 2011 18:06:47 +0800 Subject: [PATCH 024/164] egl_dri2: Fix eglGetProcAddress. The driver struct is zeroed after dri2_load. Oops. --- src/egl/drivers/dri2/egl_dri2.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index 8967969c924..458d18f4da5 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -2382,10 +2382,11 @@ _EGL_MAIN(const char *args) if (!dri2_drv) return NULL; + memset(dri2_drv, 0, sizeof *dri2_drv); + if (!dri2_load(&dri2_drv->base)) return NULL; - memset(dri2_drv, 0, sizeof *dri2_drv); _eglInitDriverFallbacks(&dri2_drv->base); dri2_drv->base.API.Initialize = dri2_initialize; dri2_drv->base.API.Terminate = dri2_terminate; From 4924cb9036cfe0f435a4a09db6f86d59a3a132d8 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Wed, 12 Jan 2011 18:09:12 +0800 Subject: [PATCH 025/164] egl: libEGL depends on LOCAL_LIBS. So that libEGL is rebuilt whenever LOCAL_LIBS changes. --- src/egl/main/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/egl/main/Makefile b/src/egl/main/Makefile index 0eb309c1969..c710631688c 100644 --- a/src/egl/main/Makefile +++ b/src/egl/main/Makefile @@ -93,7 +93,7 @@ default: depend library # EGL Library library: $(TOP)/$(LIB_DIR)/$(EGL_LIB_NAME) -$(TOP)/$(LIB_DIR)/$(EGL_LIB_NAME): $(OBJECTS) +$(TOP)/$(LIB_DIR)/$(EGL_LIB_NAME): $(OBJECTS) $(LOCAL_LIBS) $(MKLIB) -o $(EGL_LIB) -linker '$(CC)' -ldflags '$(LDFLAGS)' \ -major $(EGL_MAJOR) -minor $(EGL_MINOR) \ -install $(TOP)/$(LIB_DIR) $(MKLIB_OPTIONS) \ From 1e4f412242391000eea3fd28452865c3d27f987d Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Wed, 12 Jan 2011 17:49:43 +0800 Subject: [PATCH 026/164] egl: When EGL_DRIVER is set, do not add other drivers. Setting EGL_DRIVER forces the driver to be loaded, as documented. There should be no fallbacks. --- src/egl/main/egldriver.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c index b7c3de3e38e..0f2e40abf57 100644 --- a/src/egl/main/egldriver.c +++ b/src/egl/main/egldriver.c @@ -432,7 +432,7 @@ _eglGetSearchPath(void) * * The user driver is specified by EGL_DRIVER. */ -static void +static EGLBoolean _eglAddUserDriver(void) { const char *search_path = _eglGetSearchPath(); @@ -463,7 +463,11 @@ _eglAddUserDriver(void) mod->BuiltIn = _eglBuiltInDrivers[i].main; } } + + return EGL_TRUE; } + + return EGL_FALSE; } @@ -507,10 +511,14 @@ _eglAddDrivers(void) if (_eglModules) return EGL_TRUE; - /* the order here decides the priorities of the drivers */ - _eglAddUserDriver(); - _eglAddGalliumDriver(); - _eglAddBuiltInDrivers(); + if (!_eglAddUserDriver()) { + /* + * Add other drivers only when EGL_DRIVER is not set. The order here + * decides the priorities. + */ + _eglAddGalliumDriver(); + _eglAddBuiltInDrivers(); + } return (_eglModules != NULL); } @@ -535,6 +543,7 @@ _eglMatchDriver(_EGLDisplay *dpy, EGLBoolean use_probe) if (!_eglAddDrivers()) { _eglUnlockMutex(&_eglModuleMutex); + _eglLog(_EGL_WARNING, "failed to find any driver"); return EGL_FALSE; } From b07ad1d6bd08bfe3ab84b660587523d5711ea21f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fonseca?= Date: Wed, 12 Jan 2011 15:06:57 +0000 Subject: [PATCH 027/164] scons: Fix build on systems without libOpenVG.so --- src/gallium/targets/egl-static/SConscript | 3 ++- src/mapi/vgapi/SConscript | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/gallium/targets/egl-static/SConscript b/src/gallium/targets/egl-static/SConscript index 1fa40806319..4bb063b8215 100644 --- a/src/gallium/targets/egl-static/SConscript +++ b/src/gallium/targets/egl-static/SConscript @@ -74,6 +74,7 @@ else: # OpenVG env.Append(CPPDEFINES = ['FEATURE_VG=1']) + env.Prepend(LIBPATH = [openvg.dir]) env.Prepend(LIBS = ['OpenVG', st_vega]) @@ -115,7 +116,7 @@ egl_gallium = env.SharedLibrary( source = sources, ) -env.Depends(egl_gallium, [vgapi]) +env.Depends(egl_gallium, [openvg]) egl_gallium = env.InstallSharedLibrary(egl_gallium, version=(1, 4, 0)) diff --git a/src/mapi/vgapi/SConscript b/src/mapi/vgapi/SConscript index 8d671597859..c0c6c6c033a 100644 --- a/src/mapi/vgapi/SConscript +++ b/src/mapi/vgapi/SConscript @@ -45,15 +45,15 @@ if env['platform'] != 'winddk': env.Depends(vgapi_objects, vgapi_header) openvg = env.SharedLibrary( - target = 'libOpenVG', + target = 'OpenVG', source = vgapi_objects, ) env.InstallSharedLibrary(openvg, version=(1, 0, 0)) if env['platform'] == 'windows': - vgapi = env.FindIxes(openvg, 'LIBPREFIX', 'LIBSUFFIX') + openvg = env.FindIxes(openvg, 'LIBPREFIX', 'LIBSUFFIX') else: - vgapi = env.FindIxes(openvg, 'SHLIBPREFIX', 'SHLIBSUFFIX') + openvg = env.FindIxes(openvg, 'SHLIBPREFIX', 'SHLIBSUFFIX') - Export(['vgapi']) + Export(['openvg']) From 46662de68b72634c9059ad450e8f6c2edf36c092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fonseca?= Date: Wed, 12 Jan 2011 15:13:57 +0000 Subject: [PATCH 028/164] scons: Update windows build for vgapi->openvg rename. --- src/gallium/targets/egl-static/SConscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gallium/targets/egl-static/SConscript b/src/gallium/targets/egl-static/SConscript index 4bb063b8215..028fc095c04 100644 --- a/src/gallium/targets/egl-static/SConscript +++ b/src/gallium/targets/egl-static/SConscript @@ -61,7 +61,7 @@ if env['platform'] == 'windows': # OpenVG env.Append(CPPDEFINES = ['FEATURE_VG=1']) - env.Prepend(LIBS = [vgapi, st_vega]) + env.Prepend(LIBS = [openvg, st_vega]) else: env.Prepend(LIBS = [ st_egl, From 6d670f6c0f3b9383b8b4c8ed12beaeec56928266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fonseca?= Date: Wed, 12 Jan 2011 15:32:17 +0000 Subject: [PATCH 029/164] getopt: Import OpenBSD getopt implementation for MSVC. --- src/SConscript | 1 + src/getopt/SConscript | 13 + src/getopt/getopt.h | 78 ++++++ src/getopt/getopt_long.c | 511 +++++++++++++++++++++++++++++++++++++++ src/glsl/SConscript | 4 + 5 files changed, 607 insertions(+) create mode 100644 src/getopt/SConscript create mode 100644 src/getopt/getopt.h create mode 100644 src/getopt/getopt_long.c diff --git a/src/SConscript b/src/SConscript index 116c9b36e4e..38137ee9028 100644 --- a/src/SConscript +++ b/src/SConscript @@ -1,6 +1,7 @@ Import('*') if env['platform'] == 'windows': + SConscript('getopt/SConscript') SConscript('talloc/SConscript') SConscript('glsl/SConscript') diff --git a/src/getopt/SConscript b/src/getopt/SConscript new file mode 100644 index 00000000000..0fbaab4af9c --- /dev/null +++ b/src/getopt/SConscript @@ -0,0 +1,13 @@ +Import('*') + +if not env['msvc']: + Return() + +env = env.Clone() + +getopt = env.ConvenienceLibrary( + target = 'getopt', + source = ['getopt_long.c'], +) + +Export('getopt') diff --git a/src/getopt/getopt.h b/src/getopt/getopt.h new file mode 100644 index 00000000000..0311b078b71 --- /dev/null +++ b/src/getopt/getopt.h @@ -0,0 +1,78 @@ +/* $OpenBSD: getopt.h,v 1.2 2008/06/26 05:42:04 ray Exp $ */ +/* $NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Dieter Baron and Thomas Klausner. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _GETOPT_H_ +#define _GETOPT_H_ + +#include + +/* + * GNU-like getopt_long() and 4.4BSD getsubopt()/optreset extensions + */ +#define no_argument 0 +#define required_argument 1 +#define optional_argument 2 + +struct option { + /* name of long option */ + const char *name; + /* + * one of no_argument, required_argument, and optional_argument: + * whether option takes an argument + */ + int has_arg; + /* if not NULL, set *flag to val when option found */ + int *flag; + /* if flag not NULL, value to set *flag to; else return value */ + int val; +}; + +__BEGIN_DECLS +int getopt_long(int, char * const *, const char *, + const struct option *, int *); +int getopt_long_only(int, char * const *, const char *, + const struct option *, int *); +#ifndef _GETOPT_DEFINED_ +#define _GETOPT_DEFINED_ +int getopt(int, char * const *, const char *); +int getsubopt(char **, char * const *, char **); + +extern char *optarg; /* getopt(3) external variables */ +extern int opterr; +extern int optind; +extern int optopt; +extern int optreset; +extern char *suboptarg; /* getsubopt(3) external variable */ +#endif +__END_DECLS + +#endif /* !_GETOPT_H_ */ diff --git a/src/getopt/getopt_long.c b/src/getopt/getopt_long.c new file mode 100644 index 00000000000..eb1e3ef4be5 --- /dev/null +++ b/src/getopt/getopt_long.c @@ -0,0 +1,511 @@ +/* $OpenBSD: getopt_long.c,v 1.24 2010/07/22 19:31:53 blambert Exp $ */ +/* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */ + +/* + * Copyright (c) 2002 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Sponsored in part by the Defense Advanced Research Projects + * Agency (DARPA) and Air Force Research Laboratory, Air Force + * Materiel Command, USAF, under agreement number F39502-99-1-0512. + */ +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Dieter Baron and Thomas Klausner. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include + +int opterr = 1; /* if error message should be printed */ +int optind = 1; /* index into parent argv vector */ +int optopt = '?'; /* character checked for validity */ +int optreset; /* reset getopt */ +char *optarg; /* argument associated with option */ + +#define PRINT_ERROR ((opterr) && (*options != ':')) + +#define FLAG_PERMUTE 0x01 /* permute non-options to the end of argv */ +#define FLAG_ALLARGS 0x02 /* treat non-options as args to option "-1" */ +#define FLAG_LONGONLY 0x04 /* operate as getopt_long_only */ + +/* return values */ +#define BADCH (int)'?' +#define BADARG ((*options == ':') ? (int)':' : (int)'?') +#define INORDER (int)1 + +#define EMSG "" + +static int getopt_internal(int, char * const *, const char *, + const struct option *, int *, int); +static int parse_long_options(char * const *, const char *, + const struct option *, int *, int); +static int gcd(int, int); +static void permute_args(int, int, int, char * const *); + +static char *place = EMSG; /* option letter processing */ + +/* XXX: set optreset to 1 rather than these two */ +static int nonopt_start = -1; /* first non option argument (for permute) */ +static int nonopt_end = -1; /* first option after non options (for permute) */ + +/* Error messages */ +static const char recargchar[] = "option requires an argument -- %c"; +static const char recargstring[] = "option requires an argument -- %s"; +static const char ambig[] = "ambiguous option -- %.*s"; +static const char noarg[] = "option doesn't take an argument -- %.*s"; +static const char illoptchar[] = "unknown option -- %c"; +static const char illoptstring[] = "unknown option -- %s"; + +/* + * Compute the greatest common divisor of a and b. + */ +static int +gcd(int a, int b) +{ + int c; + + c = a % b; + while (c != 0) { + a = b; + b = c; + c = a % b; + } + + return (b); +} + +/* + * Exchange the block from nonopt_start to nonopt_end with the block + * from nonopt_end to opt_end (keeping the same order of arguments + * in each block). + */ +static void +permute_args(int panonopt_start, int panonopt_end, int opt_end, + char * const *nargv) +{ + int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos; + char *swap; + + /* + * compute lengths of blocks and number and size of cycles + */ + nnonopts = panonopt_end - panonopt_start; + nopts = opt_end - panonopt_end; + ncycle = gcd(nnonopts, nopts); + cyclelen = (opt_end - panonopt_start) / ncycle; + + for (i = 0; i < ncycle; i++) { + cstart = panonopt_end+i; + pos = cstart; + for (j = 0; j < cyclelen; j++) { + if (pos >= panonopt_end) + pos -= nnonopts; + else + pos += nopts; + swap = nargv[pos]; + /* LINTED const cast */ + ((char **) nargv)[pos] = nargv[cstart]; + /* LINTED const cast */ + ((char **)nargv)[cstart] = swap; + } + } +} + +/* + * parse_long_options -- + * Parse long options in argc/argv argument vector. + * Returns -1 if short_too is set and the option does not match long_options. + */ +static int +parse_long_options(char * const *nargv, const char *options, + const struct option *long_options, int *idx, int short_too) +{ + char *current_argv, *has_equal; + size_t current_argv_len; + int i, match; + + current_argv = place; + match = -1; + + optind++; + + if ((has_equal = strchr(current_argv, '=')) != NULL) { + /* argument found (--option=arg) */ + current_argv_len = has_equal - current_argv; + has_equal++; + } else + current_argv_len = strlen(current_argv); + + for (i = 0; long_options[i].name; i++) { + /* find matching long option */ + if (strncmp(current_argv, long_options[i].name, + current_argv_len)) + continue; + + if (strlen(long_options[i].name) == current_argv_len) { + /* exact match */ + match = i; + break; + } + /* + * If this is a known short option, don't allow + * a partial match of a single character. + */ + if (short_too && current_argv_len == 1) + continue; + + if (match == -1) /* partial match */ + match = i; + else { + /* ambiguous abbreviation */ + if (PRINT_ERROR) + warnx(ambig, (int)current_argv_len, + current_argv); + optopt = 0; + return (BADCH); + } + } + if (match != -1) { /* option found */ + if (long_options[match].has_arg == no_argument + && has_equal) { + if (PRINT_ERROR) + warnx(noarg, (int)current_argv_len, + current_argv); + /* + * XXX: GNU sets optopt to val regardless of flag + */ + if (long_options[match].flag == NULL) + optopt = long_options[match].val; + else + optopt = 0; + return (BADARG); + } + if (long_options[match].has_arg == required_argument || + long_options[match].has_arg == optional_argument) { + if (has_equal) + optarg = has_equal; + else if (long_options[match].has_arg == + required_argument) { + /* + * optional argument doesn't use next nargv + */ + optarg = nargv[optind++]; + } + } + if ((long_options[match].has_arg == required_argument) + && (optarg == NULL)) { + /* + * Missing argument; leading ':' indicates no error + * should be generated. + */ + if (PRINT_ERROR) + warnx(recargstring, + current_argv); + /* + * XXX: GNU sets optopt to val regardless of flag + */ + if (long_options[match].flag == NULL) + optopt = long_options[match].val; + else + optopt = 0; + --optind; + return (BADARG); + } + } else { /* unknown option */ + if (short_too) { + --optind; + return (-1); + } + if (PRINT_ERROR) + warnx(illoptstring, current_argv); + optopt = 0; + return (BADCH); + } + if (idx) + *idx = match; + if (long_options[match].flag) { + *long_options[match].flag = long_options[match].val; + return (0); + } else + return (long_options[match].val); +} + +/* + * getopt_internal -- + * Parse argc/argv argument vector. Called by user level routines. + */ +static int +getopt_internal(int nargc, char * const *nargv, const char *options, + const struct option *long_options, int *idx, int flags) +{ + char *oli; /* option letter list index */ + int optchar, short_too; + static int posixly_correct = -1; + + if (options == NULL) + return (-1); + + /* + * Disable GNU extensions if POSIXLY_CORRECT is set or options + * string begins with a '+'. + */ + if (posixly_correct == -1) + posixly_correct = (getenv("POSIXLY_CORRECT") != NULL); + if (posixly_correct || *options == '+') + flags &= ~FLAG_PERMUTE; + else if (*options == '-') + flags |= FLAG_ALLARGS; + if (*options == '+' || *options == '-') + options++; + + /* + * XXX Some GNU programs (like cvs) set optind to 0 instead of + * XXX using optreset. Work around this braindamage. + */ + if (optind == 0) + optind = optreset = 1; + + optarg = NULL; + if (optreset) + nonopt_start = nonopt_end = -1; +start: + if (optreset || !*place) { /* update scanning pointer */ + optreset = 0; + if (optind >= nargc) { /* end of argument vector */ + place = EMSG; + if (nonopt_end != -1) { + /* do permutation, if we have to */ + permute_args(nonopt_start, nonopt_end, + optind, nargv); + optind -= nonopt_end - nonopt_start; + } + else if (nonopt_start != -1) { + /* + * If we skipped non-options, set optind + * to the first of them. + */ + optind = nonopt_start; + } + nonopt_start = nonopt_end = -1; + return (-1); + } + if (*(place = nargv[optind]) != '-' || + (place[1] == '\0' && strchr(options, '-') == NULL)) { + place = EMSG; /* found non-option */ + if (flags & FLAG_ALLARGS) { + /* + * GNU extension: + * return non-option as argument to option 1 + */ + optarg = nargv[optind++]; + return (INORDER); + } + if (!(flags & FLAG_PERMUTE)) { + /* + * If no permutation wanted, stop parsing + * at first non-option. + */ + return (-1); + } + /* do permutation */ + if (nonopt_start == -1) + nonopt_start = optind; + else if (nonopt_end != -1) { + permute_args(nonopt_start, nonopt_end, + optind, nargv); + nonopt_start = optind - + (nonopt_end - nonopt_start); + nonopt_end = -1; + } + optind++; + /* process next argument */ + goto start; + } + if (nonopt_start != -1 && nonopt_end == -1) + nonopt_end = optind; + + /* + * If we have "-" do nothing, if "--" we are done. + */ + if (place[1] != '\0' && *++place == '-' && place[1] == '\0') { + optind++; + place = EMSG; + /* + * We found an option (--), so if we skipped + * non-options, we have to permute. + */ + if (nonopt_end != -1) { + permute_args(nonopt_start, nonopt_end, + optind, nargv); + optind -= nonopt_end - nonopt_start; + } + nonopt_start = nonopt_end = -1; + return (-1); + } + } + + /* + * Check long options if: + * 1) we were passed some + * 2) the arg is not just "-" + * 3) either the arg starts with -- we are getopt_long_only() + */ + if (long_options != NULL && place != nargv[optind] && + (*place == '-' || (flags & FLAG_LONGONLY))) { + short_too = 0; + if (*place == '-') + place++; /* --foo long option */ + else if (*place != ':' && strchr(options, *place) != NULL) + short_too = 1; /* could be short option too */ + + optchar = parse_long_options(nargv, options, long_options, + idx, short_too); + if (optchar != -1) { + place = EMSG; + return (optchar); + } + } + + if ((optchar = (int)*place++) == (int)':' || + (optchar == (int)'-' && *place != '\0') || + (oli = strchr(options, optchar)) == NULL) { + /* + * If the user specified "-" and '-' isn't listed in + * options, return -1 (non-option) as per POSIX. + * Otherwise, it is an unknown option character (or ':'). + */ + if (optchar == (int)'-' && *place == '\0') + return (-1); + if (!*place) + ++optind; + if (PRINT_ERROR) + warnx(illoptchar, optchar); + optopt = optchar; + return (BADCH); + } + if (long_options != NULL && optchar == 'W' && oli[1] == ';') { + /* -W long-option */ + if (*place) /* no space */ + /* NOTHING */; + else if (++optind >= nargc) { /* no arg */ + place = EMSG; + if (PRINT_ERROR) + warnx(recargchar, optchar); + optopt = optchar; + return (BADARG); + } else /* white space */ + place = nargv[optind]; + optchar = parse_long_options(nargv, options, long_options, + idx, 0); + place = EMSG; + return (optchar); + } + if (*++oli != ':') { /* doesn't take argument */ + if (!*place) + ++optind; + } else { /* takes (optional) argument */ + optarg = NULL; + if (*place) /* no white space */ + optarg = place; + else if (oli[1] != ':') { /* arg not optional */ + if (++optind >= nargc) { /* no arg */ + place = EMSG; + if (PRINT_ERROR) + warnx(recargchar, optchar); + optopt = optchar; + return (BADARG); + } else + optarg = nargv[optind]; + } + place = EMSG; + ++optind; + } + /* dump back option letter */ + return (optchar); +} + +/* + * getopt -- + * Parse argc/argv argument vector. + * + * [eventually this will replace the BSD getopt] + */ +int +getopt(int nargc, char * const *nargv, const char *options) +{ + + /* + * We don't pass FLAG_PERMUTE to getopt_internal() since + * the BSD getopt(3) (unlike GNU) has never done this. + * + * Furthermore, since many privileged programs call getopt() + * before dropping privileges it makes sense to keep things + * as simple (and bug-free) as possible. + */ + return (getopt_internal(nargc, nargv, options, NULL, NULL, 0)); +} + +/* + * getopt_long -- + * Parse argc/argv argument vector. + */ +int +getopt_long(int nargc, char * const *nargv, const char *options, + const struct option *long_options, int *idx) +{ + + return (getopt_internal(nargc, nargv, options, long_options, idx, + FLAG_PERMUTE)); +} + +/* + * getopt_long_only -- + * Parse argc/argv argument vector. + */ +int +getopt_long_only(int nargc, char * const *nargv, const char *options, + const struct option *long_options, int *idx) +{ + + return (getopt_internal(nargc, nargv, options, long_options, idx, + FLAG_PERMUTE|FLAG_LONGONLY)); +} diff --git a/src/glsl/SConscript b/src/glsl/SConscript index 1757605f7cb..577aedfe617 100644 --- a/src/glsl/SConscript +++ b/src/glsl/SConscript @@ -80,6 +80,10 @@ sources = [ 'strtod.c', ] +if env['msvc']: + env.Prepend(CPPPATH = ['#/src/getopt']) + env.PrependUnique(LIBS = [getopt]) + env.Prepend(LIBS = ['talloc']) env.Append(CPPPATH = ['#/src/glsl']) From f9bb5323eb96f47cfb4ab5f93165323df0a1fd61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fonseca?= Date: Wed, 12 Jan 2011 16:08:22 +0000 Subject: [PATCH 030/164] getopt: Make code more portable. --- src/getopt/SConscript | 2 ++ src/getopt/getopt.h | 12 ++++++++---- src/getopt/getopt_long.c | 16 ++++++++-------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/getopt/SConscript b/src/getopt/SConscript index 0fbaab4af9c..14cabed4e64 100644 --- a/src/getopt/SConscript +++ b/src/getopt/SConscript @@ -5,6 +5,8 @@ if not env['msvc']: env = env.Clone() +env.Prepend(CPPPATH = ['.']) + getopt = env.ConvenienceLibrary( target = 'getopt', source = ['getopt_long.c'], diff --git a/src/getopt/getopt.h b/src/getopt/getopt.h index 0311b078b71..117608f485e 100644 --- a/src/getopt/getopt.h +++ b/src/getopt/getopt.h @@ -33,8 +33,6 @@ #ifndef _GETOPT_H_ #define _GETOPT_H_ -#include - /* * GNU-like getopt_long() and 4.4BSD getsubopt()/optreset extensions */ @@ -42,6 +40,10 @@ #define required_argument 1 #define optional_argument 2 +#ifdef __cplusplus +extern "C" { +#endif + struct option { /* name of long option */ const char *name; @@ -56,7 +58,6 @@ struct option { int val; }; -__BEGIN_DECLS int getopt_long(int, char * const *, const char *, const struct option *, int *); int getopt_long_only(int, char * const *, const char *, @@ -73,6 +74,9 @@ extern int optopt; extern int optreset; extern char *suboptarg; /* getsubopt(3) external variable */ #endif -__END_DECLS + +#ifdef __cplusplus +} +#endif #endif /* !_GETOPT_H_ */ diff --git a/src/getopt/getopt_long.c b/src/getopt/getopt_long.c index eb1e3ef4be5..81268b83953 100644 --- a/src/getopt/getopt_long.c +++ b/src/getopt/getopt_long.c @@ -49,9 +49,9 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include #include #include +#include #include #include @@ -198,7 +198,7 @@ parse_long_options(char * const *nargv, const char *options, else { /* ambiguous abbreviation */ if (PRINT_ERROR) - warnx(ambig, (int)current_argv_len, + fprintf(stderr, ambig, (int)current_argv_len, current_argv); optopt = 0; return (BADCH); @@ -208,7 +208,7 @@ parse_long_options(char * const *nargv, const char *options, if (long_options[match].has_arg == no_argument && has_equal) { if (PRINT_ERROR) - warnx(noarg, (int)current_argv_len, + fprintf(stderr, noarg, (int)current_argv_len, current_argv); /* * XXX: GNU sets optopt to val regardless of flag @@ -238,7 +238,7 @@ parse_long_options(char * const *nargv, const char *options, * should be generated. */ if (PRINT_ERROR) - warnx(recargstring, + fprintf(stderr, recargstring, current_argv); /* * XXX: GNU sets optopt to val regardless of flag @@ -256,7 +256,7 @@ parse_long_options(char * const *nargv, const char *options, return (-1); } if (PRINT_ERROR) - warnx(illoptstring, current_argv); + fprintf(stderr, illoptstring, current_argv); optopt = 0; return (BADCH); } @@ -418,7 +418,7 @@ start: if (!*place) ++optind; if (PRINT_ERROR) - warnx(illoptchar, optchar); + fprintf(stderr, illoptchar, optchar); optopt = optchar; return (BADCH); } @@ -429,7 +429,7 @@ start: else if (++optind >= nargc) { /* no arg */ place = EMSG; if (PRINT_ERROR) - warnx(recargchar, optchar); + fprintf(stderr, recargchar, optchar); optopt = optchar; return (BADARG); } else /* white space */ @@ -450,7 +450,7 @@ start: if (++optind >= nargc) { /* no arg */ place = EMSG; if (PRINT_ERROR) - warnx(recargchar, optchar); + fprintf(stderr, recargchar, optchar); optopt = optchar; return (BADARG); } else From 0035d1d902f34a88ec745925284fe3b768fac261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fonseca?= Date: Wed, 12 Jan 2011 16:31:07 +0000 Subject: [PATCH 031/164] glsl: Make builtin_compiler portable for non-unices. --- src/glsl/main.cpp | 53 ++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/src/glsl/main.cpp b/src/glsl/main.cpp index c8fc2676253..847540ddd9f 100644 --- a/src/glsl/main.cpp +++ b/src/glsl/main.cpp @@ -24,11 +24,6 @@ #include #include -#include -#include -#include -#include - #include "ast.h" #include "glsl_parser_extras.h" #include "glsl_parser.h" @@ -110,38 +105,40 @@ static char * load_text_file(void *ctx, const char *file_name) { char *text = NULL; - struct stat st; - ssize_t total_read = 0; - int fd = open(file_name, O_RDONLY); + size_t size; + size_t total_read = 0; + FILE *fp = fopen(file_name, "rb"); - if (fd < 0) { + if (!fp) { return NULL; } - if (fstat(fd, & st) == 0) { - text = (char *) talloc_size(ctx, st.st_size + 1); - if (text != NULL) { - do { - ssize_t bytes = read(fd, text + total_read, - st.st_size - total_read); - if (bytes < 0) { - free(text); - text = NULL; - break; - } + fseek(fp, 0L, SEEK_END); + size = ftell(fp); + fseek(fp, 0L, SEEK_SET); - if (bytes == 0) { - break; - } + text = (char *) talloc_size(ctx, size + 1); + if (text != NULL) { + do { + size_t bytes = fread(text + total_read, + 1, size - total_read, fp); + if (bytes < size - total_read) { + free(text); + text = NULL; + break; + } - total_read += bytes; - } while (total_read < st.st_size); + if (bytes == 0) { + break; + } - text[total_read] = '\0'; - } + total_read += bytes; + } while (total_read < size); + + text[total_read] = '\0'; } - close(fd); + fclose(fp); return text; } From 416ca901389b049eaaf2edbce631396772dbeb20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fonseca?= Date: Wed, 12 Jan 2011 16:58:37 +0000 Subject: [PATCH 032/164] glsl: Make builtin_compiler build on Windows with MSVC. --- src/glsl/SConscript | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/glsl/SConscript b/src/glsl/SConscript index 577aedfe617..a22fceb75c7 100644 --- a/src/glsl/SConscript +++ b/src/glsl/SConscript @@ -84,7 +84,11 @@ if env['msvc']: env.Prepend(CPPPATH = ['#/src/getopt']) env.PrependUnique(LIBS = [getopt]) -env.Prepend(LIBS = ['talloc']) +if env['platform'] == 'windows': + env.Prepend(LIBS = [talloc]) +else: + env.Prepend(LIBS = ['talloc']) + env.Append(CPPPATH = ['#/src/glsl']) builtin_compiler = env.Program( @@ -103,6 +107,14 @@ env.CodeGenerate( env.Depends('builtin_function.cpp', ['builtins/tools/generate_builtins.py', 'builtins/tools/texture_builtins.py'] + Glob('builtins/ir/*')) +if env['msvc']: + # There is no LD_LIBRARY_PATH equivalent on Windows. We need to ensure + # talloc.dll is on the same dir as builtin_function. + talloc_dll_src = talloc.dir.File('talloc.dll') + talloc_dll_dst = builtin_compiler[0].dir.File('talloc.dll') + talloc_dll = env.Command(talloc_dll_dst, talloc_dll_src, Copy(talloc_dll_dst, talloc_dll_src)) + env.Depends('builtin_function.cpp', talloc_dll) + glsl = env.ConvenienceLibrary( target = 'glsl', source = sources + [ 'builtin_function.cpp' ], From ab56e3be9aae54602372427755305c354821e105 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 12 Jan 2011 09:37:07 -0800 Subject: [PATCH 033/164] i965/fs: When producing ir_unop_abs of an operand, strip negate. We were returning the negative absolute value, instead of the absolute value. Fixes glsl-fs-abs-neg. --- src/mesa/drivers/dri/i965/brw_fs.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp index 35bce0f397c..f4f93859574 100644 --- a/src/mesa/drivers/dri/i965/brw_fs.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs.cpp @@ -859,6 +859,7 @@ fs_visitor::visit(ir_expression *ir) break; case ir_unop_abs: op[0].abs = true; + op[0].negate = false; this->result = op[0]; break; case ir_unop_sign: From 9351ef7a4418f5c1bb95a8f2016af0a15fa97679 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 12 Jan 2011 09:40:05 -0800 Subject: [PATCH 034/164] i965/vs: When MOVing to produce ABS, strip negate of the operand. We were returning the negative absolute value, instead of the absolute value. Fixes glsl-vs-abs-neg. --- src/mesa/drivers/dri/i965/brw_vs_emit.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mesa/drivers/dri/i965/brw_vs_emit.c b/src/mesa/drivers/dri/i965/brw_vs_emit.c index fe9737d043a..0411ce0b36c 100644 --- a/src/mesa/drivers/dri/i965/brw_vs_emit.c +++ b/src/mesa/drivers/dri/i965/brw_vs_emit.c @@ -1942,6 +1942,7 @@ void brw_vs_emit(struct brw_vs_compile *c ) switch (inst->Opcode) { case OPCODE_ABS: + args[0].negate = false; brw_MOV(p, dst, brw_abs(args[0])); break; case OPCODE_ADD: From 47e7c6f57149975939b8519c45b793a30364dd79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 16 Dec 2010 22:05:33 +0100 Subject: [PATCH 035/164] r600g: improve r600_bc_dump --- src/gallium/drivers/r600/r600_asm.c | 159 +++++++++++++++++++++++----- 1 file changed, 131 insertions(+), 28 deletions(-) diff --git a/src/gallium/drivers/r600/r600_asm.c b/src/gallium/drivers/r600/r600_asm.c index 1c138513f6a..48007218152 100644 --- a/src/gallium/drivers/r600/r600_asm.c +++ b/src/gallium/drivers/r600/r600_asm.c @@ -1077,7 +1077,12 @@ void r600_bc_clear(struct r600_bc *bc) void r600_bc_dump(struct r600_bc *bc) { - unsigned i; + struct r600_bc_cf *cf; + struct r600_bc_alu *alu; + struct r600_bc_vtx *vtx; + struct r600_bc_tex *tex; + + unsigned i, id; char chip = '6'; switch (bc->chiprev) { @@ -1094,9 +1099,132 @@ void r600_bc_dump(struct r600_bc *bc) } fprintf(stderr, "bytecode %d dw -----------------------\n", bc->ndw); fprintf(stderr, " %c\n", chip); - for (i = 0; i < bc->ndw; i++) { - fprintf(stderr, "0x%08X\n", bc->bytecode[i]); + + LIST_FOR_EACH_ENTRY(cf, &bc->cf, list) { + id = cf->id; + + switch (cf->inst) { + case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU << 3): + case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER << 3): + case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER << 3): + case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE << 3): + fprintf(stderr, "%04d %08X ALU ", id, bc->bytecode[id]); + fprintf(stderr, "ADDR:%d ", cf->addr); + fprintf(stderr, "KCACHE_MODE0:%X ", cf->kcache[0].mode); + fprintf(stderr, "KCACHE_BANK0:%X ", cf->kcache[0].bank); + fprintf(stderr, "KCACHE_BANK1:%X\n", cf->kcache[1].bank); + id++; + fprintf(stderr, "%04d %08X ALU ", id, bc->bytecode[id]); + fprintf(stderr, "INST:%d ", cf->inst); + fprintf(stderr, "KCACHE_MODE1:%X ", cf->kcache[1].mode); + fprintf(stderr, "KCACHE_ADDR0:%X ", cf->kcache[0].addr); + fprintf(stderr, "KCACHE_ADDR1:%X ", cf->kcache[1].addr); + fprintf(stderr, "COUNT:%d\n", cf->ndw / 2); + break; + case V_SQ_CF_WORD1_SQ_CF_INST_TEX: + case V_SQ_CF_WORD1_SQ_CF_INST_VTX: + case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC: + fprintf(stderr, "%04d %08X TEX/VTX ", id, bc->bytecode[id]); + fprintf(stderr, "ADDR:%d\n", cf->addr); + id++; + fprintf(stderr, "%04d %08X TEX/VTX ", id, bc->bytecode[id]); + fprintf(stderr, "INST:%d ", cf->inst); + fprintf(stderr, "COUNT:%d\n", cf->ndw / 4); + break; + case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT: + case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE: + fprintf(stderr, "%04d %08X EXPORT ", id, bc->bytecode[id]); + fprintf(stderr, "GPR:%X ", cf->output.gpr); + fprintf(stderr, "ELEM_SIZE:%X ", cf->output.elem_size); + fprintf(stderr, "ARRAY_BASE:%X ", cf->output.array_base); + fprintf(stderr, "TYPE:%X\n", cf->output.type); + id++; + fprintf(stderr, "%04d %08X EXPORT ", id, bc->bytecode[id]); + fprintf(stderr, "SWIZ_X:%X ", cf->output.swizzle_x); + fprintf(stderr, "SWIZ_Y:%X ", cf->output.swizzle_y); + fprintf(stderr, "SWIZ_Z:%X ", cf->output.swizzle_z); + fprintf(stderr, "SWIZ_W:%X ", cf->output.swizzle_w); + fprintf(stderr, "SWIZ_W:%X ", cf->output.swizzle_w); + fprintf(stderr, "BARRIER:%X ", cf->output.barrier); + fprintf(stderr, "INST:%d ", cf->output.inst); + fprintf(stderr, "EOP:%X\n", cf->output.end_of_program); + break; + case V_SQ_CF_WORD1_SQ_CF_INST_JUMP: + case V_SQ_CF_WORD1_SQ_CF_INST_ELSE: + case V_SQ_CF_WORD1_SQ_CF_INST_POP: + case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL: + case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END: + case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE: + case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK: + case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS: + case V_SQ_CF_WORD1_SQ_CF_INST_RETURN: + fprintf(stderr, "%04d %08X CF ", id, bc->bytecode[id]); + fprintf(stderr, "ADDR:%d\n", cf->cf_addr); + id++; + fprintf(stderr, "%04d %08X CF ", id, bc->bytecode[id]); + fprintf(stderr, "INST:%d ", cf->inst); + fprintf(stderr, "COND:%X ", cf->cond); + fprintf(stderr, "POP_COUNT:%X\n", cf->pop_count); + break; + } + + LIST_FOR_EACH_ENTRY(alu, &cf->alu, list) { + id = cf->addr; + fprintf(stderr, "%04d %08X\t", id, bc->bytecode[id]); + fprintf(stderr, "SRC0(SEL:%d ", alu->src[0].sel); + fprintf(stderr, "REL:%d ", alu->src[0].rel); + fprintf(stderr, "CHAN:%d ", alu->src[0].chan); + fprintf(stderr, "NEG:%d) ", alu->src[0].neg); + fprintf(stderr, "SRC1(SEL:%d ", alu->src[1].sel); + fprintf(stderr, "REL:%d ", alu->src[1].rel); + fprintf(stderr, "CHAN:%d ", alu->src[1].chan); + fprintf(stderr, "NEG:%d) ", alu->src[1].neg); + fprintf(stderr, "LAST:%d)\n", alu->last); + id++; + if (alu->is_op3) { + fprintf(stderr, "%04d %08X\t", id, bc->bytecode[id]); + fprintf(stderr, "DST(SEL:%d ", alu->dst.sel); + fprintf(stderr, "CHAN:%d ", alu->dst.chan); + fprintf(stderr, "REL:%d ", alu->dst.rel); + fprintf(stderr, "CLAMP:%d) ", alu->dst.clamp); + fprintf(stderr, "SRC2(SEL:%d ", alu->src[2].sel); + fprintf(stderr, "REL:%d ", alu->src[2].rel); + fprintf(stderr, "CHAN:%d ", alu->src[2].chan); + fprintf(stderr, "NEG:%d) ", alu->src[2].neg); + fprintf(stderr, "INST:%d ", alu->inst); + fprintf(stderr, "BANK_SWIZZLE:%d\n", alu->bank_swizzle); + } else { + fprintf(stderr, "%04d %08X\t", id, bc->bytecode[id]); + fprintf(stderr, "DST(SEL:%d ", alu->dst.sel); + fprintf(stderr, "CHAN:%d ", alu->dst.chan); + fprintf(stderr, "REL:%d ", alu->dst.rel); + fprintf(stderr, "CLAMP:%d) ", alu->dst.clamp); + fprintf(stderr, "SRC0_ABS:%d ", alu->src[0].abs); + fprintf(stderr, "SRC1_ABS:%d ", alu->src[1].abs); + fprintf(stderr, "WRITE_MASK:%d ", alu->dst.write); + fprintf(stderr, "INST:%d ", alu->inst); + fprintf(stderr, "BANK_SWIZZLE:%d ", alu->bank_swizzle); + fprintf(stderr, "EXECUTE_MASK:%d ", alu->predicate); + fprintf(stderr, "UPDATE_PRED:%d\n", alu->predicate); + } + + if (alu->last) { + for (i = 0; i < alu->nliteral; i++) { + float *f = (float*)(bc->bytecode + id); + fprintf(stderr, "%04d %08X %f\n", id, bc->bytecode[id], *f); + } + } + } + + LIST_FOR_EACH_ENTRY(tex, &cf->tex, list) { + //TODO + } + + LIST_FOR_EACH_ENTRY(vtx, &cf->vtx, list) { + //TODO + } } + fprintf(stderr, "--------------------------------------\n"); } @@ -1308,31 +1436,6 @@ out_unknown: R600_ERR("unsupported vertex format %s\n", util_format_name(pformat)); } -static void r600_bc(unsigned ndw, unsigned chiprev, u32 *bytecode) -{ - unsigned i; - char chip = '6'; - - switch (chiprev) { - case 1: - chip = '7'; - break; - case 2: - chip = 'E'; - break; - case 0: - default: - chip = '6'; - break; - } - fprintf(stderr, "bytecode %d dw -----------------------\n", ndw); - fprintf(stderr, " %c\n", chip); - for (i = 0; i < ndw; i++) { - fprintf(stderr, "0x%08X\n", bytecode[i]); - } - fprintf(stderr, "--------------------------------------\n"); -} - int r600_vertex_elements_build_fetch_shader(struct r600_pipe_context *rctx, struct r600_vertex_element *ve) { unsigned ndw, i; From 95a2b265facfb8c6e50895326c90f7fd75d5c1d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 17 Dec 2010 22:57:36 +0100 Subject: [PATCH 036/164] r600g: fix alu dumping --- src/gallium/drivers/r600/r600_asm.c | 32 ++++++++++++----------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/gallium/drivers/r600/r600_asm.c b/src/gallium/drivers/r600/r600_asm.c index 48007218152..e911f977f75 100644 --- a/src/gallium/drivers/r600/r600_asm.c +++ b/src/gallium/drivers/r600/r600_asm.c @@ -1168,9 +1168,9 @@ void r600_bc_dump(struct r600_bc *bc) break; } + id = cf->addr; LIST_FOR_EACH_ENTRY(alu, &cf->alu, list) { - id = cf->addr; - fprintf(stderr, "%04d %08X\t", id, bc->bytecode[id]); + fprintf(stderr, "%04d %08X ", id, bc->bytecode[id]); fprintf(stderr, "SRC0(SEL:%d ", alu->src[0].sel); fprintf(stderr, "REL:%d ", alu->src[0].rel); fprintf(stderr, "CHAN:%d ", alu->src[0].chan); @@ -1181,37 +1181,31 @@ void r600_bc_dump(struct r600_bc *bc) fprintf(stderr, "NEG:%d) ", alu->src[1].neg); fprintf(stderr, "LAST:%d)\n", alu->last); id++; + fprintf(stderr, "%04d %08X %c ", id, bc->bytecode[id], alu->last ? '*' : ' '); + fprintf(stderr, "INST:%d ", alu->inst); + fprintf(stderr, "DST(SEL:%d ", alu->dst.sel); + fprintf(stderr, "CHAN:%d ", alu->dst.chan); + fprintf(stderr, "REL:%d ", alu->dst.rel); + fprintf(stderr, "CLAMP:%d) ", alu->dst.clamp); + fprintf(stderr, "BANK_SWIZZLE:%d ", alu->bank_swizzle); if (alu->is_op3) { - fprintf(stderr, "%04d %08X\t", id, bc->bytecode[id]); - fprintf(stderr, "DST(SEL:%d ", alu->dst.sel); - fprintf(stderr, "CHAN:%d ", alu->dst.chan); - fprintf(stderr, "REL:%d ", alu->dst.rel); - fprintf(stderr, "CLAMP:%d) ", alu->dst.clamp); fprintf(stderr, "SRC2(SEL:%d ", alu->src[2].sel); fprintf(stderr, "REL:%d ", alu->src[2].rel); fprintf(stderr, "CHAN:%d ", alu->src[2].chan); - fprintf(stderr, "NEG:%d) ", alu->src[2].neg); - fprintf(stderr, "INST:%d ", alu->inst); - fprintf(stderr, "BANK_SWIZZLE:%d\n", alu->bank_swizzle); + fprintf(stderr, "NEG:%d)\n", alu->src[2].neg); } else { - fprintf(stderr, "%04d %08X\t", id, bc->bytecode[id]); - fprintf(stderr, "DST(SEL:%d ", alu->dst.sel); - fprintf(stderr, "CHAN:%d ", alu->dst.chan); - fprintf(stderr, "REL:%d ", alu->dst.rel); - fprintf(stderr, "CLAMP:%d) ", alu->dst.clamp); fprintf(stderr, "SRC0_ABS:%d ", alu->src[0].abs); fprintf(stderr, "SRC1_ABS:%d ", alu->src[1].abs); fprintf(stderr, "WRITE_MASK:%d ", alu->dst.write); - fprintf(stderr, "INST:%d ", alu->inst); - fprintf(stderr, "BANK_SWIZZLE:%d ", alu->bank_swizzle); fprintf(stderr, "EXECUTE_MASK:%d ", alu->predicate); fprintf(stderr, "UPDATE_PRED:%d\n", alu->predicate); } + id++; if (alu->last) { - for (i = 0; i < alu->nliteral; i++) { + for (i = 0; i < alu->nliteral; i++, id++) { float *f = (float*)(bc->bytecode + id); - fprintf(stderr, "%04d %08X %f\n", id, bc->bytecode[id], *f); + fprintf(stderr, "%04d %08X\t%f\n", id, bc->bytecode[id], *f); } } } From 052b9e8fab2e7deddf7f287d63c45aa938e5ec67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 12 Jan 2011 19:02:03 +0100 Subject: [PATCH 037/164] r600g: make dumping of shaders an option --- src/gallium/drivers/r600/r600_shader.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/gallium/drivers/r600/r600_shader.c b/src/gallium/drivers/r600/r600_shader.c index 2bf116c90bc..9248eb33573 100644 --- a/src/gallium/drivers/r600/r600_shader.c +++ b/src/gallium/drivers/r600/r600_shader.c @@ -228,11 +228,19 @@ int r600_pipe_shader(struct pipe_context *ctx, struct r600_pipe_shader *shader) int r600_shader_from_tgsi(const struct tgsi_token *tokens, struct r600_shader *shader); int r600_pipe_shader_create(struct pipe_context *ctx, struct r600_pipe_shader *shader, const struct tgsi_token *tokens) { + static int dump_shaders = -1; struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; int r; -//fprintf(stderr, "--------------------------------------------------------------\n"); -//tgsi_dump(tokens, 0); + /* Would like some magic "get_bool_option_once" routine. + */ + if (dump_shaders == -1) + dump_shaders = debug_get_bool_option("R600_DUMP_SHADERS", FALSE); + + if (dump_shaders) { + fprintf(stderr, "--------------------------------------------------------------\n"); + tgsi_dump(tokens, 0); + } shader->shader.family = r600_get_family(rctx->radeon); r = r600_shader_from_tgsi(tokens, &shader->shader); if (r) { @@ -244,8 +252,10 @@ int r600_pipe_shader_create(struct pipe_context *ctx, struct r600_pipe_shader *s R600_ERR("building bytecode failed !\n"); return r; } -//r600_bc_dump(&shader->shader.bc); -//fprintf(stderr, "______________________________________________________________\n"); + if (dump_shaders) { + r600_bc_dump(&shader->shader.bc); + fprintf(stderr, "______________________________________________________________\n"); + } return r600_pipe_shader(ctx, shader); } From 8813842121d46d1be476807c98b0ba0b771f0c91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 14 Dec 2010 00:43:53 +0100 Subject: [PATCH 038/164] r600g: optimize away CF_INST_POP If last instruction is an CF_INST_ALU we don't need to emit an additional CF_INST_POP for stack clean up after an IF ELSE ENDIF. --- src/gallium/drivers/r600/eg_asm.c | 2 ++ src/gallium/drivers/r600/r600_asm.c | 8 ++++++++ src/gallium/drivers/r600/r600_shader.c | 22 +++++++++++++++++++--- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/gallium/drivers/r600/eg_asm.c b/src/gallium/drivers/r600/eg_asm.c index c44506c7eba..67d742b3760 100644 --- a/src/gallium/drivers/r600/eg_asm.c +++ b/src/gallium/drivers/r600/eg_asm.c @@ -35,6 +35,8 @@ int eg_bc_cf_build(struct r600_bc *bc, struct r600_bc_cf *cf) switch (cf->inst) { case (EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU << 3): + case (EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER << 3): + case (EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER << 3): case (EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE << 3): bc->bytecode[id++] = S_SQ_CF_ALU_WORD0_ADDR(cf->addr >> 1) | S_SQ_CF_ALU_WORD0_KCACHE_MODE0(cf->kcache[0].mode) | diff --git a/src/gallium/drivers/r600/r600_asm.c b/src/gallium/drivers/r600/r600_asm.c index e911f977f75..3ee54a2af15 100644 --- a/src/gallium/drivers/r600/r600_asm.c +++ b/src/gallium/drivers/r600/r600_asm.c @@ -631,6 +631,8 @@ int r600_bc_add_literal(struct r600_bc *bc, const u32 *value) } /* same on EG */ if (((bc->cf_last->inst != (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU << 3)) && + (bc->cf_last->inst != (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER << 3)) && + (bc->cf_last->inst != (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER << 3)) && (bc->cf_last->inst != (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE << 3))) || LIST_IS_EMPTY(&bc->cf_last->alu)) { R600_ERR("last CF is not ALU (%p)\n", bc->cf_last); @@ -853,6 +855,8 @@ static int r600_bc_cf_build(struct r600_bc *bc, struct r600_bc_cf *cf) switch (cf->inst) { case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU << 3): case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE << 3): + case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER << 3): + case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER << 3): bc->bytecode[id++] = S_SQ_CF_ALU_WORD0_ADDR(cf->addr >> 1) | S_SQ_CF_ALU_WORD0_KCACHE_MODE0(cf->kcache[0].mode) | S_SQ_CF_ALU_WORD0_KCACHE_BANK0(cf->kcache[0].bank) | @@ -932,6 +936,8 @@ int r600_bc_build(struct r600_bc *bc) LIST_FOR_EACH_ENTRY(cf, &bc->cf, list) { switch (cf->inst) { case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU << 3): + case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER << 3): + case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER << 3): case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE << 3): break; case V_SQ_CF_WORD1_SQ_CF_INST_TEX: @@ -978,6 +984,8 @@ int r600_bc_build(struct r600_bc *bc) return r; switch (cf->inst) { case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU << 3): + case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER << 3): + case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER << 3): case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE << 3): LIST_FOR_EACH_ENTRY(alu, &cf->alu, list) { switch(bc->chiprev) { diff --git a/src/gallium/drivers/r600/r600_shader.c b/src/gallium/drivers/r600/r600_shader.c index 9248eb33573..0f7213f977b 100644 --- a/src/gallium/drivers/r600/r600_shader.c +++ b/src/gallium/drivers/r600/r600_shader.c @@ -2703,9 +2703,25 @@ static int emit_logic_pred(struct r600_shader_ctx *ctx, int opcode) static int pops(struct r600_shader_ctx *ctx, int pops) { - r600_bc_add_cfinst(ctx->bc, CTX_INST(V_SQ_CF_WORD1_SQ_CF_INST_POP)); - ctx->bc->cf_last->pop_count = pops; - ctx->bc->cf_last->cf_addr = ctx->bc->cf_last->id + 2; + int alu_pop = 3; + if (ctx->bc->cf_last) { + if (ctx->bc->cf_last->inst == CTX_INST(V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU) << 3) + alu_pop = 0; + else if (ctx->bc->cf_last->inst == CTX_INST(V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER) << 3) + alu_pop = 1; + } + alu_pop += pops; + if (alu_pop == 1) { + ctx->bc->cf_last->inst = CTX_INST(V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER) << 3; + ctx->bc->force_add_cf = 1; + } else if (alu_pop == 2) { + ctx->bc->cf_last->inst = CTX_INST(V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER) << 3; + ctx->bc->force_add_cf = 1; + } else { + r600_bc_add_cfinst(ctx->bc, CTX_INST(V_SQ_CF_WORD1_SQ_CF_INST_POP)); + ctx->bc->cf_last->pop_count = pops; + ctx->bc->cf_last->cf_addr = ctx->bc->cf_last->id + 2; + } return 0; } From dffad730df17983cfaef0808555a8c26cad0aa15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 14 Dec 2010 20:49:31 +0100 Subject: [PATCH 039/164] r600g: optimize temp register handling for LRP --- src/gallium/drivers/r600/r600_shader.c | 72 ++++++++++++++------------ 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/src/gallium/drivers/r600/r600_shader.c b/src/gallium/drivers/r600/r600_shader.c index 0f7213f977b..0902f398f62 100644 --- a/src/gallium/drivers/r600/r600_shader.c +++ b/src/gallium/drivers/r600/r600_shader.c @@ -880,19 +880,25 @@ static int tgsi_split_literal_constant(struct r600_shader_ctx *ctx, struct r600_ return 0; } +static int tgsi_last_instruction(unsigned writemask) +{ + int i, lasti = 0; + + for (i = 0; i < 4; i++) { + if (writemask & (1 << i)) { + lasti = i; + } + } + return lasti; +} + static int tgsi_op2_s(struct r600_shader_ctx *ctx, int swap) { struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; struct r600_bc_alu_src r600_src[3]; struct r600_bc_alu alu; int i, j, r; - int lasti = 0; - - for (i = 0; i < 4; i++) { - if (inst->Dst[0].Register.WriteMask & (1 << i)) { - lasti = i; - } - } + int lasti = tgsi_last_instruction(inst->Dst[0].Register.WriteMask); r = tgsi_split_constant(ctx, r600_src); if (r) @@ -1066,7 +1072,7 @@ static int tgsi_trig(struct r600_shader_ctx *ctx) struct r600_bc_alu_src r600_src[3]; struct r600_bc_alu alu; int i, r; - int lasti = 0; + int lasti = tgsi_last_instruction(inst->Dst[0].Register.WriteMask); r = tgsi_setup_trig(ctx, r600_src); if (r) @@ -1086,10 +1092,6 @@ static int tgsi_trig(struct r600_shader_ctx *ctx) return r; /* replicate result */ - for (i = 0; i < 4; i++) { - if (inst->Dst[0].Register.WriteMask & (1 << i)) - lasti = i; - } for (i = 0; i < lasti + 1; i++) { if (!(inst->Dst[0].Register.WriteMask & (1 << i))) continue; @@ -1616,13 +1618,7 @@ static int tgsi_op3(struct r600_shader_ctx *ctx) struct r600_bc_alu_src r600_src[3]; struct r600_bc_alu alu; int i, j, r; - int lasti = 0; - - for (i = 0; i < 4; i++) { - if (inst->Dst[0].Register.WriteMask & (1 << i)) { - lasti = i; - } - } + int lasti = tgsi_last_instruction(inst->Dst[0].Register.WriteMask); r = tgsi_split_constant(ctx, r600_src); if (r) @@ -1966,6 +1962,7 @@ static int tgsi_lrp(struct r600_shader_ctx *ctx) struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; struct r600_bc_alu_src r600_src[3]; struct r600_bc_alu alu; + int lasti = tgsi_last_instruction(inst->Dst[0].Register.WriteMask); unsigned i; int r; @@ -1976,7 +1973,10 @@ static int tgsi_lrp(struct r600_shader_ctx *ctx) if (r) return r; /* 1 - src0 */ - for (i = 0; i < 4; i++) { + for (i = 0; i < lasti + 1; i++) { + if (!(inst->Dst[0].Register.WriteMask & (1 << i))) + continue; + memset(&alu, 0, sizeof(struct r600_bc_alu)); alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD); alu.src[0].sel = V_SQ_ALU_SRC_1; @@ -1986,7 +1986,7 @@ static int tgsi_lrp(struct r600_shader_ctx *ctx) alu.src[1].neg = 1; alu.dst.sel = ctx->temp_reg; alu.dst.chan = i; - if (i == 3) { + if (i == lasti) { alu.last = 1; } alu.dst.write = 1; @@ -1999,7 +1999,10 @@ static int tgsi_lrp(struct r600_shader_ctx *ctx) return r; /* (1 - src0) * src2 */ - for (i = 0; i < 4; i++) { + for (i = 0; i < lasti + 1; i++) { + if (!(inst->Dst[0].Register.WriteMask & (1 << i))) + continue; + memset(&alu, 0, sizeof(struct r600_bc_alu)); alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL); alu.src[0].sel = ctx->temp_reg; @@ -2008,7 +2011,7 @@ static int tgsi_lrp(struct r600_shader_ctx *ctx) alu.src[1].chan = tgsi_chan(&inst->Src[2], i); alu.dst.sel = ctx->temp_reg; alu.dst.chan = i; - if (i == 3) { + if (i == lasti) { alu.last = 1; } alu.dst.write = 1; @@ -2021,7 +2024,10 @@ static int tgsi_lrp(struct r600_shader_ctx *ctx) return r; /* src0 * src1 + (1 - src0) * src2 */ - for (i = 0; i < 4; i++) { + for (i = 0; i < lasti + 1; i++) { + if (!(inst->Dst[0].Register.WriteMask & (1 << i))) + continue; + memset(&alu, 0, sizeof(struct r600_bc_alu)); alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD); alu.is_op3 = 1; @@ -2031,16 +2037,20 @@ static int tgsi_lrp(struct r600_shader_ctx *ctx) alu.src[1].chan = tgsi_chan(&inst->Src[1], i); alu.src[2].sel = ctx->temp_reg; alu.src[2].chan = i; - alu.dst.sel = ctx->temp_reg; + + r = tgsi_dst(ctx, &inst->Dst[0], i, &alu.dst); + if (r) + return r; + alu.dst.chan = i; - if (i == 3) { + if (i == lasti) { alu.last = 1; } r = r600_bc_add_alu(ctx->bc, &alu); if (r) return r; } - return tgsi_helper_copy(ctx, inst); + return 0; } static int tgsi_cmp(struct r600_shader_ctx *ctx) @@ -2049,13 +2059,7 @@ static int tgsi_cmp(struct r600_shader_ctx *ctx) struct r600_bc_alu_src r600_src[3]; struct r600_bc_alu alu; int i, r; - int lasti = 0; - - for (i = 0; i < 4; i++) { - if (inst->Dst[0].Register.WriteMask & (1 << i)) { - lasti = i; - } - } + int lasti = tgsi_last_instruction(inst->Dst[0].Register.WriteMask); r = tgsi_split_constant(ctx, r600_src); if (r) From 7728bef29097c8406d35c6dd969544382abdf935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 14 Dec 2010 23:38:30 +0100 Subject: [PATCH 040/164] r600g: use special constants for 0, 1, -1, 1.0f, 0.5f etc --- src/gallium/drivers/r600/r600_shader.c | 56 ++++++++++++++++++++------ 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/src/gallium/drivers/r600/r600_shader.c b/src/gallium/drivers/r600/r600_shader.c index 0902f398f62..b853fd9dc88 100644 --- a/src/gallium/drivers/r600/r600_shader.c +++ b/src/gallium/drivers/r600/r600_shader.c @@ -556,7 +556,7 @@ int r600_shader_from_tgsi(const struct tgsi_token *tokens, struct r600_shader *s * kcache banks later. */ ctx.file_offset[TGSI_FILE_CONSTANT] = 512; - ctx.file_offset[TGSI_FILE_IMMEDIATE] = 253; + ctx.file_offset[TGSI_FILE_IMMEDIATE] = V_SQ_ALU_SRC_LITERAL; ctx.temp_reg = ctx.file_offset[TGSI_FILE_TEMPORARY] + ctx.info.file_count[TGSI_FILE_TEMPORARY]; @@ -746,22 +746,54 @@ static int tgsi_src(struct r600_shader_ctx *ctx, const struct tgsi_full_src_register *tgsi_src, struct r600_bc_alu_src *r600_src) { - int index; memset(r600_src, 0, sizeof(struct r600_bc_alu_src)); - r600_src->sel = tgsi_src->Register.Index; - if (tgsi_src->Register.File == TGSI_FILE_IMMEDIATE) { - r600_src->sel = 0; + r600_src->neg = tgsi_src->Register.Negate; + r600_src->abs = tgsi_src->Register.Absolute; + if (tgsi_src->Register.File == TGSI_FILE_IMMEDIATE) { + int index; + if((tgsi_src->Register.SwizzleX == tgsi_src->Register.SwizzleY) && + (tgsi_src->Register.SwizzleX == tgsi_src->Register.SwizzleZ) && + (tgsi_src->Register.SwizzleX == tgsi_src->Register.SwizzleW)) { + + index = tgsi_src->Register.Index * 4 + tgsi_src->Register.SwizzleX; + switch(ctx->literals[index]) { + case 0: + r600_src->sel = V_SQ_ALU_SRC_0; + return 0; + case 1: + r600_src->sel = V_SQ_ALU_SRC_1_INT; + return 0; + case -1: + r600_src->sel = V_SQ_ALU_SRC_M_1_INT; + return 0; + case 0x3F800000: // 1.0f + r600_src->sel = V_SQ_ALU_SRC_1; + return 0; + case 0x3F000000: // 0.5f + r600_src->sel = V_SQ_ALU_SRC_0_5; + return 0; + case 0xBF800000: // -1.0f + r600_src->sel = V_SQ_ALU_SRC_1; + r600_src->neg ^= 1; + return 0; + case 0xBF000000: // -0.5f + r600_src->sel = V_SQ_ALU_SRC_0_5; + r600_src->neg ^= 1; + return 0; + } + } index = tgsi_src->Register.Index; + r600_src->sel = V_SQ_ALU_SRC_LITERAL; ctx->value[0] = ctx->literals[index * 4 + 0]; ctx->value[1] = ctx->literals[index * 4 + 1]; ctx->value[2] = ctx->literals[index * 4 + 2]; ctx->value[3] = ctx->literals[index * 4 + 3]; + } else { + if (tgsi_src->Register.Indirect) + r600_src->rel = V_SQ_REL_RELATIVE; + r600_src->sel = tgsi_src->Register.Index; + r600_src->sel += ctx->file_offset[tgsi_src->Register.File]; } - if (tgsi_src->Register.Indirect) - r600_src->rel = V_SQ_REL_RELATIVE; - r600_src->neg = tgsi_src->Register.Negate; - r600_src->abs = tgsi_src->Register.Absolute; - r600_src->sel += ctx->file_offset[tgsi_src->Register.File]; return 0; } @@ -849,12 +881,12 @@ static int tgsi_split_literal_constant(struct r600_shader_ctx *ctx, struct r600_ int i, j, k, nliteral, r; for (i = 0, nliteral = 0; i < inst->Instruction.NumSrcRegs; i++) { - if (inst->Src[i].Register.File == TGSI_FILE_IMMEDIATE) { + if (r600_src[i].sel == V_SQ_ALU_SRC_LITERAL) { nliteral++; } } for (i = 0, j = nliteral - 1; i < inst->Instruction.NumSrcRegs; i++) { - if (j > 0 && inst->Src[i].Register.File == TGSI_FILE_IMMEDIATE) { + if (j > 0 && r600_src[i].sel == V_SQ_ALU_SRC_LITERAL) { int treg = r600_get_temp(ctx); for (k = 0; k < 4; k++) { memset(&alu, 0, sizeof(struct r600_bc_alu)); From c60cb25bfb15fc83e78d9f2c74646dcc5ad07792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 16 Dec 2010 16:42:14 +0100 Subject: [PATCH 041/164] r600g: implement output modifiers and use them to further optimize LRP --- src/gallium/drivers/r600/r600_asm.c | 2 ++ src/gallium/drivers/r600/r600_asm.h | 1 + src/gallium/drivers/r600/r600_shader.c | 29 ++++++++++++++++++++++++++ src/gallium/drivers/r600/r700_asm.c | 1 + 4 files changed, 33 insertions(+) diff --git a/src/gallium/drivers/r600/r600_asm.c b/src/gallium/drivers/r600/r600_asm.c index 3ee54a2af15..5be5e1823d2 100644 --- a/src/gallium/drivers/r600/r600_asm.c +++ b/src/gallium/drivers/r600/r600_asm.c @@ -831,6 +831,7 @@ static int r600_bc_alu_build(struct r600_bc *bc, struct r600_bc_alu *alu, unsign S_SQ_ALU_WORD1_OP2_SRC0_ABS(alu->src[0].abs) | S_SQ_ALU_WORD1_OP2_SRC1_ABS(alu->src[1].abs) | S_SQ_ALU_WORD1_OP2_WRITE_MASK(alu->dst.write) | + S_SQ_ALU_WORD1_OP2_OMOD(alu->omod) | S_SQ_ALU_WORD1_OP2_ALU_INST(alu->inst) | S_SQ_ALU_WORD1_BANK_SWIZZLE(alu->bank_swizzle) | S_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK(alu->predicate) | @@ -1205,6 +1206,7 @@ void r600_bc_dump(struct r600_bc *bc) fprintf(stderr, "SRC0_ABS:%d ", alu->src[0].abs); fprintf(stderr, "SRC1_ABS:%d ", alu->src[1].abs); fprintf(stderr, "WRITE_MASK:%d ", alu->dst.write); + fprintf(stderr, "OMOD:%d ", alu->omod); fprintf(stderr, "EXECUTE_MASK:%d ", alu->predicate); fprintf(stderr, "UPDATE_PRED:%d\n", alu->predicate); } diff --git a/src/gallium/drivers/r600/r600_asm.h b/src/gallium/drivers/r600/r600_asm.h index a5504ad39f4..4763ce03ec4 100644 --- a/src/gallium/drivers/r600/r600_asm.h +++ b/src/gallium/drivers/r600/r600_asm.h @@ -62,6 +62,7 @@ struct r600_bc_alu { unsigned bank_swizzle_force; u32 value[4]; int hw_gpr[NUM_OF_CYCLES][NUM_OF_COMPONENTS]; + unsigned omod; }; struct r600_bc_tex { diff --git a/src/gallium/drivers/r600/r600_shader.c b/src/gallium/drivers/r600/r600_shader.c index b853fd9dc88..78739bf89d8 100644 --- a/src/gallium/drivers/r600/r600_shader.c +++ b/src/gallium/drivers/r600/r600_shader.c @@ -2004,6 +2004,35 @@ static int tgsi_lrp(struct r600_shader_ctx *ctx) r = tgsi_split_literal_constant(ctx, r600_src); if (r) return r; + + /* optimize if it's just an equal balance */ + if(r600_src[0].sel == V_SQ_ALU_SRC_0_5) { + for (i = 0; i < lasti + 1; i++) { + if (!(inst->Dst[0].Register.WriteMask & (1 << i))) + continue; + + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD); + alu.src[0] = r600_src[1]; + alu.src[0].chan = tgsi_chan(&inst->Src[1], i); + alu.src[1] = r600_src[2]; + alu.src[1].chan = tgsi_chan(&inst->Src[2], i); + alu.omod = 3; + r = tgsi_dst(ctx, &inst->Dst[0], i, &alu.dst); + if (r) + return r; + + alu.dst.chan = i; + if (i == lasti) { + alu.last = 1; + } + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + } + return 0; + } + /* 1 - src0 */ for (i = 0; i < lasti + 1; i++) { if (!(inst->Dst[0].Register.WriteMask & (1 << i))) diff --git a/src/gallium/drivers/r600/r700_asm.c b/src/gallium/drivers/r600/r700_asm.c index 892dee86baf..3eb6fb50ca7 100644 --- a/src/gallium/drivers/r600/r700_asm.c +++ b/src/gallium/drivers/r600/r700_asm.c @@ -61,6 +61,7 @@ int r700_bc_alu_build(struct r600_bc *bc, struct r600_bc_alu *alu, unsigned id) S_SQ_ALU_WORD1_OP2_SRC0_ABS(alu->src[0].abs) | S_SQ_ALU_WORD1_OP2_SRC1_ABS(alu->src[1].abs) | S_SQ_ALU_WORD1_OP2_WRITE_MASK(alu->dst.write) | + S_SQ_ALU_WORD1_OP2_OMOD(alu->omod) | S_SQ_ALU_WORD1_OP2_ALU_INST(alu->inst) | S_SQ_ALU_WORD1_BANK_SWIZZLE(alu->bank_swizzle) | S_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK(alu->predicate) | From e880a57a71bbd5152ed26367dcc7051f21c20981 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 12 Jan 2011 10:10:01 -0800 Subject: [PATCH 042/164] i965: Clarify when we need to (re-)calculate live intervals. The ad-hoc placement of recalculation somewhere between when they got invalidated and when they were next needed was confusing. This should clarify what's going on here. --- src/mesa/drivers/dri/i965/brw_fs.cpp | 26 +++++++++++++++---- src/mesa/drivers/dri/i965/brw_fs.h | 2 ++ .../drivers/dri/i965/brw_fs_reg_allocate.cpp | 4 +++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp index f4f93859574..b618ee5b157 100644 --- a/src/mesa/drivers/dri/i965/brw_fs.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs.cpp @@ -2727,6 +2727,9 @@ fs_visitor::calculate_live_intervals() int loop_start = 0; int bb_header_ip = 0; + if (this->live_intervals_valid) + return; + for (int i = 0; i < num_vars; i++) { def[i] = 1 << 30; use[i] = -1; @@ -2806,6 +2809,8 @@ fs_visitor::calculate_live_intervals() talloc_free(this->virtual_grf_use); this->virtual_grf_def = def; this->virtual_grf_use = use; + + this->live_intervals_valid = true; } /** @@ -2821,6 +2826,8 @@ fs_visitor::propagate_constants() { bool progress = false; + calculate_live_intervals(); + foreach_iter(exec_list_iterator, iter, this->instructions) { fs_inst *inst = (fs_inst *)iter.get(); @@ -2878,6 +2885,7 @@ fs_visitor::propagate_constants() /* Fit this constant in by commuting the operands */ scan_inst->src[0] = scan_inst->src[1]; scan_inst->src[1] = inst->src[0]; + progress = true; } break; case BRW_OPCODE_CMP: @@ -2898,6 +2906,9 @@ fs_visitor::propagate_constants() } } + if (progress) + this->live_intervals_valid = false; + return progress; } /** @@ -2912,6 +2923,8 @@ fs_visitor::dead_code_eliminate() bool progress = false; int pc = 0; + calculate_live_intervals(); + foreach_iter(exec_list_iterator, iter, this->instructions) { fs_inst *inst = (fs_inst *)iter.get(); @@ -2923,6 +2936,9 @@ fs_visitor::dead_code_eliminate() pc++; } + if (progress) + live_intervals_valid = false; + return progress; } @@ -3019,6 +3035,9 @@ fs_visitor::register_coalesce() progress = true; } + if (progress) + live_intervals_valid = false; + return progress; } @@ -3029,6 +3048,8 @@ fs_visitor::compute_to_mrf() bool progress = false; int next_ip = 0; + calculate_live_intervals(); + foreach_iter(exec_list_iterator, iter, this->instructions) { fs_inst *inst = (fs_inst *)iter.get(); @@ -3628,10 +3649,8 @@ brw_wm_fs_emit(struct brw_context *brw, struct brw_wm_compile *c) progress = v.remove_duplicate_mrf_writes() || progress; - v.calculate_live_intervals(); progress = v.propagate_constants() || progress; progress = v.register_coalesce() || progress; - v.calculate_live_intervals(); progress = v.compute_to_mrf() || progress; progress = v.dead_code_eliminate() || progress; } while (progress); @@ -3642,7 +3661,6 @@ brw_wm_fs_emit(struct brw_context *brw, struct brw_wm_compile *c) for (int i = 1; i < virtual_grf_count; i++) { v.spill_reg(i); } - v.calculate_live_intervals(); } if (0) @@ -3651,8 +3669,6 @@ brw_wm_fs_emit(struct brw_context *brw, struct brw_wm_compile *c) while (!v.assign_regs()) { if (v.fail) break; - - v.calculate_live_intervals(); } } } diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h index 00a000855c5..d213c62dcb7 100644 --- a/src/mesa/drivers/dri/i965/brw_fs.h +++ b/src/mesa/drivers/dri/i965/brw_fs.h @@ -378,6 +378,7 @@ public: this->virtual_grf_array_size = 0; this->virtual_grf_def = NULL; this->virtual_grf_use = NULL; + this->live_intervals_valid = false; this->kill_emitted = false; } @@ -479,6 +480,7 @@ public: int virtual_grf_array_size; int *virtual_grf_def; int *virtual_grf_use; + bool live_intervals_valid; struct hash_table *variable_ht; ir_variable *frag_color, *frag_data, *frag_depth; diff --git a/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp b/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp index bbb210cd449..078a349abdf 100644 --- a/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp @@ -94,6 +94,8 @@ fs_visitor::assign_regs() int class_count = 0; int aligned_pair_class = -1; + calculate_live_intervals(); + /* Set up the register classes. * * The base registers store a scalar value. For texture samples, @@ -416,4 +418,6 @@ fs_visitor::spill_reg(int spill_reg) } } } + + this->live_intervals_valid = false; } From e1fb511570e9b2a4d015332b7d80f469bf334b2a Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 12 Jan 2011 10:12:00 -0800 Subject: [PATCH 043/164] meta: Actually use mipmapping when generating mipmaps. With the change to not reset baselevel, this GL_LINEAR filtering was resulting in generating mipmaps off of the base level instead of the next higher detail level. Fixes fbo-generatemipmap-filtering. Reported by: Neil Roberts --- src/mesa/drivers/common/meta.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c index 3e699912bb4..fd12e4d0a66 100644 --- a/src/mesa/drivers/common/meta.c +++ b/src/mesa/drivers/common/meta.c @@ -2319,7 +2319,7 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target, } _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, mipmap->FBO); - _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); _mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); _mesa_TexParameteri(target, GL_GENERATE_MIPMAP, GL_FALSE); _mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); From a42906f862cbdef251fbccb69787ba3710f0116a Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Wed, 12 Jan 2011 11:35:43 -0800 Subject: [PATCH 044/164] generate_builtins.py: Add missing import. Import sys for sys.exit. --- src/glsl/builtins/tools/generate_builtins.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/glsl/builtins/tools/generate_builtins.py b/src/glsl/builtins/tools/generate_builtins.py index 8b11338e8c7..1cf12a148c6 100755 --- a/src/glsl/builtins/tools/generate_builtins.py +++ b/src/glsl/builtins/tools/generate_builtins.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- import re +import sys from glob import glob from os import path from subprocess import Popen, PIPE From 6881262eff2154e4252359c104e8c90052537eb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 12 Jan 2011 20:39:40 +0100 Subject: [PATCH 045/164] r600g: also look at tex inst when for maximum gpu count --- src/gallium/drivers/r600/r600_asm.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/gallium/drivers/r600/r600_asm.c b/src/gallium/drivers/r600/r600_asm.c index 5be5e1823d2..6c216c4d5f8 100644 --- a/src/gallium/drivers/r600/r600_asm.c +++ b/src/gallium/drivers/r600/r600_asm.c @@ -699,6 +699,12 @@ int r600_bc_add_tex(struct r600_bc *bc, const struct r600_bc_tex *tex) } bc->cf_last->inst = V_SQ_CF_WORD1_SQ_CF_INST_TEX; } + if (ntex->src_gpr >= bc->ngpr) { + bc->ngpr = ntex->src_gpr + 1; + } + if (ntex->dst_gpr >= bc->ngpr) { + bc->ngpr = ntex->dst_gpr + 1; + } LIST_ADDTAIL(&ntex->list, &bc->cf_last->tex); /* each texture fetch use 4 dwords */ bc->cf_last->ndw += 4; @@ -1106,7 +1112,7 @@ void r600_bc_dump(struct r600_bc *bc) chip = '6'; break; } - fprintf(stderr, "bytecode %d dw -----------------------\n", bc->ndw); + fprintf(stderr, "bytecode %d dw -- %d gprs ---------------------\n", bc->ndw, bc->ngpr); fprintf(stderr, " %c\n", chip); LIST_FOR_EACH_ENTRY(cf, &bc->cf, list) { From c3f000b3926988124a44ce7e8cd6588e46063058 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 12 Jan 2011 12:52:16 -0800 Subject: [PATCH 046/164] i965/fs: Do flat shading when appropriate. We were trying to interpolate, which would end up doing unnecessary math, and doing so on undefined values. Fixes glsl-fs-flat-color. --- src/mesa/drivers/dri/i965/brw_fs.cpp | 63 ++++++++++++++++++---------- src/mesa/drivers/dri/i965/brw_fs.h | 1 + 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp index b618ee5b157..d2947eee1f8 100644 --- a/src/mesa/drivers/dri/i965/brw_fs.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs.cpp @@ -534,25 +534,40 @@ fs_visitor::emit_general_interpolation(ir_variable *ir) continue; } - for (unsigned int c = 0; c < type->vector_elements; c++) { - struct brw_reg interp = interp_reg(location, c); - emit(fs_inst(FS_OPCODE_LINTERP, - attr, - this->delta_x, - this->delta_y, - fs_reg(interp))); - attr.reg_offset++; - } - - if (intel->gen < 6) { - attr.reg_offset -= type->vector_elements; + if (c->key.flat_shade && (location == FRAG_ATTRIB_COL0 || + location == FRAG_ATTRIB_COL1)) { + /* Constant interpolation (flat shading) case. The SF has + * handed us defined values in only the constant offset + * field of the setup reg. + */ for (unsigned int c = 0; c < type->vector_elements; c++) { - emit(fs_inst(BRW_OPCODE_MUL, - attr, - attr, - this->pixel_w)); + struct brw_reg interp = interp_reg(location, c); + interp = suboffset(interp, 3); + emit(fs_inst(FS_OPCODE_CINTERP, attr, fs_reg(interp))); attr.reg_offset++; } + } else { + /* Perspective interpolation case. */ + for (unsigned int c = 0; c < type->vector_elements; c++) { + struct brw_reg interp = interp_reg(location, c); + emit(fs_inst(FS_OPCODE_LINTERP, + attr, + this->delta_x, + this->delta_y, + fs_reg(interp))); + attr.reg_offset++; + } + + if (intel->gen < 6) { + attr.reg_offset -= type->vector_elements; + for (unsigned int c = 0; c < type->vector_elements; c++) { + emit(fs_inst(BRW_OPCODE_MUL, + attr, + attr, + this->pixel_w)); + attr.reg_offset++; + } + } } location++; } @@ -2557,12 +2572,15 @@ fs_visitor::assign_urb_setup() foreach_iter(exec_list_iterator, iter, this->instructions) { fs_inst *inst = (fs_inst *)iter.get(); - if (inst->opcode != FS_OPCODE_LINTERP) - continue; + if (inst->opcode == FS_OPCODE_LINTERP) { + assert(inst->src[2].file == FIXED_HW_REG); + inst->src[2].fixed_hw_reg.nr += urb_start; + } - assert(inst->src[2].file == FIXED_HW_REG); - - inst->src[2].fixed_hw_reg.nr += urb_start; + if (inst->opcode == FS_OPCODE_CINTERP) { + assert(inst->src[0].file == FIXED_HW_REG); + inst->src[0].fixed_hw_reg.nr += urb_start; + } } this->first_non_payload_grf = urb_start + c->prog_data.urb_read_length; @@ -3501,6 +3519,9 @@ fs_visitor::generate_code() case FS_OPCODE_COS: generate_math(inst, dst, src); break; + case FS_OPCODE_CINTERP: + brw_MOV(p, dst, src[0]); + break; case FS_OPCODE_LINTERP: generate_linterp(inst, dst, src); break; diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h index d213c62dcb7..82d96f6ac02 100644 --- a/src/mesa/drivers/dri/i965/brw_fs.h +++ b/src/mesa/drivers/dri/i965/brw_fs.h @@ -68,6 +68,7 @@ enum fs_opcodes { FS_OPCODE_COS, FS_OPCODE_DDX, FS_OPCODE_DDY, + FS_OPCODE_CINTERP, FS_OPCODE_LINTERP, FS_OPCODE_TEX, FS_OPCODE_TXB, From bd33055ef4b6dd18d6247ff7d9e47496ff4acc51 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Fri, 7 Jan 2011 18:34:58 -0800 Subject: [PATCH 047/164] glsl: Track variable usage, use that to enforce semantics In particular, variables cannot be redeclared invariant after being used. Fixes piglit test invariant-05.vert and bugzilla #29164. NOTE: This is a candidate for the 7.9 and 7.10 branches. --- src/glsl/ast_to_hir.cpp | 18 ++++++++++++++++-- src/glsl/ir.cpp | 1 + src/glsl/ir.h | 9 +++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp index c4bd7e64e27..a833be18f31 100644 --- a/src/glsl/ast_to_hir.cpp +++ b/src/glsl/ast_to_hir.cpp @@ -1623,6 +1623,7 @@ ast_expression::hir(exec_list *instructions, result = new(ctx) ir_dereference_variable(var); if (var != NULL) { + var->used = true; type = result->type; } else { _mesa_glsl_error(& loc, state, "`%s' undeclared", @@ -1797,8 +1798,16 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual, struct _mesa_glsl_parse_state *state, YYLTYPE *loc) { - if (qual->flags.q.invariant) - var->invariant = 1; + if (qual->flags.q.invariant) { + if (var->used) { + _mesa_glsl_error(loc, state, + "variable `%s' may not be redeclared " + "`invariant' after being used", + var->name); + } else { + var->invariant = 1; + } + } /* FINISHME: Mark 'in' variables at global scope as read-only. */ if (qual->flags.q.constant || qual->flags.q.attribute @@ -2005,6 +2014,11 @@ ast_declarator_list::hir(exec_list *instructions, _mesa_glsl_error(& loc, state, "`%s' cannot be marked invariant, fragment shader " "inputs only\n", decl->identifier); + } else if (earlier->used) { + _mesa_glsl_error(& loc, state, + "variable `%s' may not be redeclared " + "`invariant' after being used", + earlier->name); } else { earlier->invariant = true; } diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp index 742dd41b9f4..460d43b02e1 100644 --- a/src/glsl/ir.cpp +++ b/src/glsl/ir.cpp @@ -1325,6 +1325,7 @@ ir_variable::ir_variable(const struct glsl_type *type, const char *name, this->constant_value = NULL; this->origin_upper_left = false; this->pixel_center_integer = false; + this->used = false; if (type && type->base_type == GLSL_TYPE_SAMPLER) this->read_only = true; diff --git a/src/glsl/ir.h b/src/glsl/ir.h index 9668c9439ad..57e89f0f6bf 100644 --- a/src/glsl/ir.h +++ b/src/glsl/ir.h @@ -294,6 +294,15 @@ public: unsigned centroid:1; unsigned invariant:1; + /** + * Has this variable been used for reading or writing? + * + * Several GLSL semantic checks require knowledge of whether or not a + * variable has been used. For example, it is an error to redeclare a + * variable as invariant after it has been used. + */ + unsigned used:1; + /** * Storage class of the variable. * From 9b260c377f5b437b7e03607fefa022459ef758ed Mon Sep 17 00:00:00 2001 From: Chad Versace Date: Sun, 9 Jan 2011 10:53:52 -0800 Subject: [PATCH 048/164] mesa: Refactor handling of extension strings Place GL, GLES1, and GLES2 extensions in a unified extension table. This allows one to enable, disable, and query the status of GLES1 and GLES2 extensions by name. When tested on Intel Ironlake, this patch did not alter the extension string [as given by glGetString(GL_EXTENSIONS)] for any API. Reviewed-by: Ian Romanick Reviewed-by: Brian Paul --- src/mesa/main/extensions.c | 919 +++++++++++++++++-------------------- src/mesa/main/mtypes.h | 3 + 2 files changed, 419 insertions(+), 503 deletions(-) diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c index 42626152e8e..ca03c09ffec 100644 --- a/src/mesa/main/extensions.c +++ b/src/mesa/main/extensions.c @@ -24,6 +24,12 @@ */ +/** + * \file + * \brief Extension handling + */ + + #include "glheader.h" #include "imports.h" #include "context.h" @@ -31,199 +37,331 @@ #include "mfeatures.h" #include "mtypes.h" - -#define F(x) offsetof(struct gl_extensions, x) -#define ON GL_TRUE -#define OFF GL_FALSE - - -/* - * Note: The GL_MESAX_* extensions are placeholders for future ARB extensions. - */ -static const struct { - GLboolean enabled; - const char *name; - int flag_offset; -} default_extensions[] = { - { OFF, "GL_ARB_blend_func_extended", F(ARB_blend_func_extended) }, - { ON, "GL_ARB_copy_buffer", F(ARB_copy_buffer) }, - { OFF, "GL_ARB_depth_buffer_float", F(ARB_depth_buffer_float) }, - { OFF, "GL_ARB_depth_clamp", F(ARB_depth_clamp) }, - { OFF, "GL_ARB_depth_texture", F(ARB_depth_texture) }, - { ON, "GL_ARB_draw_buffers", F(ARB_draw_buffers) }, - { OFF, "GL_ARB_draw_elements_base_vertex", F(ARB_draw_elements_base_vertex) }, - { OFF, "GL_ARB_draw_instanced", F(ARB_draw_instanced) }, - { OFF, "GL_ARB_explicit_attrib_location", F(ARB_explicit_attrib_location) }, - { OFF, "GL_ARB_fragment_coord_conventions", F(ARB_fragment_coord_conventions) }, - { OFF, "GL_ARB_fragment_program", F(ARB_fragment_program) }, - { OFF, "GL_ARB_fragment_program_shadow", F(ARB_fragment_program_shadow) }, - { OFF, "GL_ARB_fragment_shader", F(ARB_fragment_shader) }, - { OFF, "GL_ARB_framebuffer_object", F(ARB_framebuffer_object) }, - /* TODO: reenable this when the new GLSL compiler actually supports them */ - /* { OFF, "GL_ARB_geometry_shader4", F(ARB_geometry_shader4) }, */ - { OFF, "GL_ARB_half_float_pixel", F(ARB_half_float_pixel) }, - { OFF, "GL_ARB_half_float_vertex", F(ARB_half_float_vertex) }, - { OFF, "GL_ARB_instanced_arrays", F(ARB_instanced_arrays) }, - { OFF, "GL_ARB_map_buffer_range", F(ARB_map_buffer_range) }, - { ON, "GL_ARB_multisample", F(ARB_multisample) }, - { OFF, "GL_ARB_multitexture", F(ARB_multitexture) }, - { OFF, "GL_ARB_occlusion_query", F(ARB_occlusion_query) }, - { OFF, "GL_ARB_occlusion_query2", F(ARB_occlusion_query2) }, - { OFF, "GL_ARB_pixel_buffer_object", F(EXT_pixel_buffer_object) }, - { OFF, "GL_ARB_point_parameters", F(EXT_point_parameters) }, - { OFF, "GL_ARB_point_sprite", F(ARB_point_sprite) }, - { OFF, "GL_ARB_provoking_vertex", F(EXT_provoking_vertex) }, - { OFF, "GL_ARB_sampler_objects", F(ARB_sampler_objects) }, - { OFF, "GL_ARB_seamless_cube_map", F(ARB_seamless_cube_map) }, - { OFF, "GL_ARB_shader_objects", F(ARB_shader_objects) }, - { OFF, "GL_ARB_shader_stencil_export", F(ARB_shader_stencil_export) }, - { OFF, "GL_ARB_shading_language_100", F(ARB_shading_language_100) }, - { OFF, "GL_ARB_shadow", F(ARB_shadow) }, - { OFF, "GL_ARB_shadow_ambient", F(ARB_shadow_ambient) }, - { OFF, "GL_ARB_sync", F(ARB_sync) }, - { OFF, "GL_ARB_texture_border_clamp", F(ARB_texture_border_clamp) }, - { OFF, "GL_ARB_texture_buffer_object", F(ARB_texture_buffer_object) }, - { ON, "GL_ARB_texture_compression", F(ARB_texture_compression) }, - { OFF, "GL_ARB_texture_compression_rgtc", F(ARB_texture_compression_rgtc) }, - { OFF, "GL_ARB_texture_cube_map", F(ARB_texture_cube_map) }, - { OFF, "GL_ARB_texture_env_add", F(EXT_texture_env_add) }, - { OFF, "GL_ARB_texture_env_combine", F(ARB_texture_env_combine) }, - { OFF, "GL_ARB_texture_env_crossbar", F(ARB_texture_env_crossbar) }, - { OFF, "GL_ARB_texture_env_dot3", F(ARB_texture_env_dot3) }, - { OFF, "GL_MESAX_texture_float", F(ARB_texture_float) }, - { OFF, "GL_ARB_texture_mirrored_repeat", F(ARB_texture_mirrored_repeat)}, - { OFF, "GL_ARB_texture_multisample", F(ARB_texture_multisample) }, - { OFF, "GL_ARB_texture_non_power_of_two", F(ARB_texture_non_power_of_two)}, - { OFF, "GL_ARB_texture_rectangle", F(NV_texture_rectangle) }, - { OFF, "GL_ARB_texture_rg", F(ARB_texture_rg) }, - { OFF, "GL_ARB_texture_rgb10_a2ui", F(ARB_texture_rgb10_a2ui) }, - { OFF, "GL_ARB_texture_swizzle", F(EXT_texture_swizzle) }, - { ON, "GL_ARB_transpose_matrix", F(ARB_transpose_matrix) }, - { OFF, "GL_ARB_transform_feedback2", F(ARB_transform_feedback2) }, - { OFF, "GL_ARB_uniform_buffer_object", F(ARB_uniform_buffer_object) }, - { OFF, "GL_ARB_vertex_array_bgra", F(EXT_vertex_array_bgra) }, - { OFF, "GL_ARB_vertex_array_object", F(ARB_vertex_array_object) }, - { ON, "GL_ARB_vertex_buffer_object", F(ARB_vertex_buffer_object) }, - { OFF, "GL_ARB_vertex_program", F(ARB_vertex_program) }, - { OFF, "GL_ARB_vertex_shader", F(ARB_vertex_shader) }, - { OFF, "GL_ARB_vertex_type_2_10_10_10_rev", F(ARB_vertex_type_2_10_10_10_rev) }, - { ON, "GL_ARB_window_pos", F(ARB_window_pos) }, - { ON, "GL_EXT_abgr", F(EXT_abgr) }, - { ON, "GL_EXT_bgra", F(EXT_bgra) }, - { OFF, "GL_EXT_blend_color", F(EXT_blend_color) }, - { OFF, "GL_EXT_blend_equation_separate", F(EXT_blend_equation_separate) }, - { OFF, "GL_EXT_blend_func_separate", F(EXT_blend_func_separate) }, - { OFF, "GL_EXT_blend_logic_op", F(EXT_blend_logic_op) }, - { OFF, "GL_EXT_blend_minmax", F(EXT_blend_minmax) }, - { OFF, "GL_EXT_blend_subtract", F(EXT_blend_subtract) }, - { OFF, "GL_EXT_clip_volume_hint", F(EXT_clip_volume_hint) }, - { ON, "GL_EXT_compiled_vertex_array", F(EXT_compiled_vertex_array) }, - { ON, "GL_EXT_copy_texture", F(EXT_copy_texture) }, - { OFF, "GL_EXT_depth_bounds_test", F(EXT_depth_bounds_test) }, - { OFF, "GL_EXT_draw_buffers2", F(EXT_draw_buffers2) }, - { OFF, "GL_EXT_draw_instanced", F(ARB_draw_instanced) }, - { ON, "GL_EXT_draw_range_elements", F(EXT_draw_range_elements) }, - { OFF, "GL_EXT_framebuffer_blit", F(EXT_framebuffer_blit) }, - { OFF, "GL_EXT_framebuffer_multisample", F(EXT_framebuffer_multisample) }, - { OFF, "GL_EXT_framebuffer_object", F(EXT_framebuffer_object) }, - { OFF, "GL_EXT_framebuffer_sRGB", F(EXT_framebuffer_sRGB) }, - { OFF, "GL_EXT_fog_coord", F(EXT_fog_coord) }, - { OFF, "GL_EXT_gpu_program_parameters", F(EXT_gpu_program_parameters) }, - { OFF, "GL_EXT_gpu_shader4", F(EXT_gpu_shader4) }, - { ON, "GL_EXT_multi_draw_arrays", F(EXT_multi_draw_arrays) }, - { OFF, "GL_EXT_packed_depth_stencil", F(EXT_packed_depth_stencil) }, - { OFF, "GL_EXT_packed_float", F(EXT_packed_float) }, - { ON, "GL_EXT_packed_pixels", F(EXT_packed_pixels) }, - { OFF, "GL_EXT_paletted_texture", F(EXT_paletted_texture) }, - { OFF, "GL_EXT_pixel_buffer_object", F(EXT_pixel_buffer_object) }, - { OFF, "GL_EXT_point_parameters", F(EXT_point_parameters) }, - { ON, "GL_EXT_polygon_offset", F(EXT_polygon_offset) }, - { OFF, "GL_EXT_provoking_vertex", F(EXT_provoking_vertex) }, - { ON, "GL_EXT_rescale_normal", F(EXT_rescale_normal) }, - { OFF, "GL_EXT_secondary_color", F(EXT_secondary_color) }, - { OFF, "GL_EXT_separate_shader_objects", F(EXT_separate_shader_objects) }, - { ON, "GL_EXT_separate_specular_color", F(EXT_separate_specular_color) }, - { OFF, "GL_EXT_shadow_funcs", F(EXT_shadow_funcs) }, - { OFF, "GL_EXT_shared_texture_palette", F(EXT_shared_texture_palette) }, - { OFF, "GL_EXT_stencil_two_side", F(EXT_stencil_two_side) }, - { OFF, "GL_EXT_stencil_wrap", F(EXT_stencil_wrap) }, - { ON, "GL_EXT_subtexture", F(EXT_subtexture) }, - { ON, "GL_EXT_texture", F(EXT_texture) }, - { ON, "GL_EXT_texture3D", F(EXT_texture3D) }, - { OFF, "GL_EXT_texture_array", F(EXT_texture_array) }, - { OFF, "GL_EXT_texture_compression_s3tc", F(EXT_texture_compression_s3tc) }, - { OFF, "GL_EXT_texture_compression_rgtc", F(ARB_texture_compression_rgtc) }, - { OFF, "GL_EXT_texture_cube_map", F(ARB_texture_cube_map) }, - { ON, "GL_EXT_texture_edge_clamp", F(SGIS_texture_edge_clamp) }, - { OFF, "GL_EXT_texture_env_add", F(EXT_texture_env_add) }, - { OFF, "GL_EXT_texture_env_combine", F(EXT_texture_env_combine) }, - { OFF, "GL_EXT_texture_env_dot3", F(EXT_texture_env_dot3) }, - { OFF, "GL_EXT_texture_filter_anisotropic", F(EXT_texture_filter_anisotropic) }, - { OFF, "GL_EXT_texture_integer", F(EXT_texture_integer) }, - { OFF, "GL_EXT_texture_lod_bias", F(EXT_texture_lod_bias) }, - { OFF, "GL_EXT_texture_mirror_clamp", F(EXT_texture_mirror_clamp) }, - { ON, "GL_EXT_texture_object", F(EXT_texture_object) }, - { OFF, "GL_EXT_texture_rectangle", F(NV_texture_rectangle) }, - { OFF, "GL_EXT_texture_shared_exponent", F(EXT_texture_shared_exponent) }, - { OFF, "GL_EXT_texture_sRGB", F(EXT_texture_sRGB) }, - { OFF, "GL_EXT_texture_swizzle", F(EXT_texture_swizzle) }, - { OFF, "GL_EXT_timer_query", F(EXT_timer_query) }, - { OFF, "GL_EXT_transform_feedback", F(EXT_transform_feedback) }, - { ON, "GL_EXT_vertex_array", F(EXT_vertex_array) }, - { OFF, "GL_EXT_vertex_array_bgra", F(EXT_vertex_array_bgra) }, - { OFF, "GL_EXT_vertex_array_set", F(EXT_vertex_array_set) }, - { OFF, "GL_3DFX_texture_compression_FXT1", F(TDFX_texture_compression_FXT1) }, - { OFF, "GL_APPLE_client_storage", F(APPLE_client_storage) }, - { ON, "GL_APPLE_packed_pixels", F(APPLE_packed_pixels) }, - { OFF, "GL_APPLE_vertex_array_object", F(APPLE_vertex_array_object) }, - { OFF, "GL_APPLE_object_purgeable", F(APPLE_object_purgeable) }, - { OFF, "GL_ATI_blend_equation_separate", F(EXT_blend_equation_separate) }, - { OFF, "GL_ATI_envmap_bumpmap", F(ATI_envmap_bumpmap) }, - { OFF, "GL_ATI_texture_env_combine3", F(ATI_texture_env_combine3)}, - { OFF, "GL_ATI_texture_mirror_once", F(ATI_texture_mirror_once)}, - { OFF, "GL_ATI_fragment_shader", F(ATI_fragment_shader)}, - { OFF, "GL_ATI_separate_stencil", F(ATI_separate_stencil)}, - { ON, "GL_IBM_multimode_draw_arrays", F(IBM_multimode_draw_arrays) }, - { ON, "GL_IBM_rasterpos_clip", F(IBM_rasterpos_clip) }, - { OFF, "GL_IBM_texture_mirrored_repeat", F(ARB_texture_mirrored_repeat)}, - { OFF, "GL_INGR_blend_func_separate", F(EXT_blend_func_separate) }, - { OFF, "GL_MESA_pack_invert", F(MESA_pack_invert) }, - { OFF, "GL_MESA_resize_buffers", F(MESA_resize_buffers) }, - { OFF, "GL_MESA_texture_array", F(MESA_texture_array) }, - { OFF, "GL_MESA_texture_signed_rgba", F(MESA_texture_signed_rgba) }, - { OFF, "GL_MESA_ycbcr_texture", F(MESA_ycbcr_texture) }, - { ON, "GL_MESA_window_pos", F(ARB_window_pos) }, - { OFF, "GL_NV_blend_square", F(NV_blend_square) }, - { OFF, "GL_NV_conditional_render", F(NV_conditional_render) }, - { OFF, "GL_NV_depth_clamp", F(ARB_depth_clamp) }, - { OFF, "GL_NV_fragment_program", F(NV_fragment_program) }, - { OFF, "GL_NV_fragment_program_option", F(NV_fragment_program_option) }, - { ON, "GL_NV_light_max_exponent", F(NV_light_max_exponent) }, - { OFF, "GL_NV_packed_depth_stencil", F(EXT_packed_depth_stencil) }, - { OFF, "GL_NV_point_sprite", F(NV_point_sprite) }, - { OFF, "GL_NV_primitive_restart", F(NV_primitive_restart) }, - { ON, "GL_NV_texgen_reflection", F(NV_texgen_reflection) }, - { OFF, "GL_NV_texture_env_combine4", F(NV_texture_env_combine4) }, - { OFF, "GL_NV_texture_rectangle", F(NV_texture_rectangle) }, - { OFF, "GL_NV_vertex_program", F(NV_vertex_program) }, - { OFF, "GL_NV_vertex_program1_1", F(NV_vertex_program1_1) }, - { ON, "GL_OES_read_format", F(OES_read_format) }, - { OFF, "GL_SGI_texture_color_table", F(SGI_texture_color_table) }, - { ON, "GL_SGIS_generate_mipmap", F(SGIS_generate_mipmap) }, - { OFF, "GL_SGIS_texture_border_clamp", F(ARB_texture_border_clamp) }, - { ON, "GL_SGIS_texture_edge_clamp", F(SGIS_texture_edge_clamp) }, - { ON, "GL_SGIS_texture_lod", F(SGIS_texture_lod) }, - { ON, "GL_SUN_multi_draw_arrays", F(EXT_multi_draw_arrays) }, - { OFF, "GL_S3_s3tc", F(S3_s3tc) }, - { OFF, "GL_EXT_texture_format_BGRA8888", F(EXT_texture_format_BGRA8888) }, -#if FEATURE_OES_EGL_image - { OFF, "GL_OES_EGL_image", F(OES_EGL_image) }, -#endif -#if FEATURE_OES_draw_texture - { OFF, "GL_OES_draw_texture", F(OES_draw_texture) }, -#endif /* FEATURE_OES_draw_texture */ +enum { + DISABLE = 0, + GL = 1 << API_OPENGL, + ES1 = 1 << API_OPENGLES, + ES2 = 1 << API_OPENGLES2, }; +/** + * \brief An element of the \c extension_table. + */ +struct extension { + /** Name of extension, such as "GL_ARB_depth_clamp". */ + const char *name; + + /** Offset (in bytes) of the corresponding member in struct gl_extensions. */ + size_t offset; + + /** Set of API's in which the extension exists, as a bitset. */ + uint8_t api_set; +}; + + +/** + * Given a member \c x of struct gl_extensions, return offset of + * \c x in bytes. + */ +#define o(x) offsetof(struct gl_extensions, x) + + +/** + * \brief Table of supported OpenGL extensions for all API's. + * + * Note: The GL_MESAX_* extensions are placeholders for future ARB extensions. + */ +static const struct extension extension_table[] = { + /* ARB Extensions */ + { "GL_ARB_blend_func_extended", o(ARB_blend_func_extended), GL }, + { "GL_ARB_copy_buffer", o(ARB_copy_buffer), GL }, + { "GL_ARB_depth_buffer_float", o(ARB_depth_buffer_float), GL }, + { "GL_ARB_depth_clamp", o(ARB_depth_clamp), GL }, + { "GL_ARB_depth_texture", o(ARB_depth_texture), GL }, + { "GL_ARB_draw_buffers", o(ARB_draw_buffers), GL }, + { "GL_ARB_draw_elements_base_vertex", o(ARB_draw_elements_base_vertex), GL }, + { "GL_ARB_draw_instanced", o(ARB_draw_instanced), GL }, + { "GL_ARB_explicit_attrib_location", o(ARB_explicit_attrib_location), GL }, + { "GL_ARB_fragment_coord_conventions", o(ARB_fragment_coord_conventions), GL }, + { "GL_ARB_fragment_program", o(ARB_fragment_program), GL }, + { "GL_ARB_fragment_program_shadow", o(ARB_fragment_program_shadow), GL }, + { "GL_ARB_fragment_shader", o(ARB_fragment_shader), GL }, + { "GL_ARB_framebuffer_object", o(ARB_framebuffer_object), GL }, + { "GL_ARB_half_float_pixel", o(ARB_half_float_pixel), GL }, + { "GL_ARB_half_float_vertex", o(ARB_half_float_vertex), GL }, + { "GL_ARB_instanced_arrays", o(ARB_instanced_arrays), GL }, + { "GL_ARB_map_buffer_range", o(ARB_map_buffer_range), GL }, + { "GL_ARB_multisample", o(ARB_multisample), GL }, + { "GL_ARB_multitexture", o(ARB_multitexture), GL }, + { "GL_ARB_occlusion_query2", o(ARB_occlusion_query2), GL }, + { "GL_ARB_occlusion_query", o(ARB_occlusion_query), GL }, + { "GL_ARB_pixel_buffer_object", o(EXT_pixel_buffer_object), GL }, + { "GL_ARB_point_parameters", o(EXT_point_parameters), GL }, + { "GL_ARB_point_sprite", o(ARB_point_sprite), GL }, + { "GL_ARB_provoking_vertex", o(EXT_provoking_vertex), GL }, + { "GL_ARB_sampler_objects", o(ARB_sampler_objects), GL }, + { "GL_ARB_seamless_cube_map", o(ARB_seamless_cube_map), GL }, + { "GL_ARB_shader_objects", o(ARB_shader_objects), GL }, + { "GL_ARB_shader_stencil_export", o(ARB_shader_stencil_export), GL }, + { "GL_ARB_shading_language_100", o(ARB_shading_language_100), GL }, + { "GL_ARB_shadow_ambient", o(ARB_shadow_ambient), GL }, + { "GL_ARB_shadow", o(ARB_shadow), GL }, + { "GL_ARB_sync", o(ARB_sync), GL }, + { "GL_ARB_texture_border_clamp", o(ARB_texture_border_clamp), GL }, + { "GL_ARB_texture_buffer_object", o(ARB_texture_buffer_object), GL }, + { "GL_ARB_texture_compression", o(ARB_texture_compression), GL }, + { "GL_ARB_texture_compression_rgtc", o(ARB_texture_compression_rgtc), GL }, + { "GL_ARB_texture_cube_map", o(ARB_texture_cube_map), GL }, + { "GL_ARB_texture_env_add", o(EXT_texture_env_add), GL }, + { "GL_ARB_texture_env_combine", o(ARB_texture_env_combine), GL }, + { "GL_ARB_texture_env_crossbar", o(ARB_texture_env_crossbar), GL }, + { "GL_ARB_texture_env_dot3", o(ARB_texture_env_dot3), GL }, + { "GL_ARB_texture_mirrored_repeat", o(ARB_texture_mirrored_repeat), GL }, + { "GL_ARB_texture_multisample", o(ARB_texture_multisample), GL }, + { "GL_ARB_texture_non_power_of_two", o(ARB_texture_non_power_of_two), GL }, + { "GL_ARB_texture_rectangle", o(NV_texture_rectangle), GL }, + { "GL_ARB_texture_rgb10_a2ui", o(ARB_texture_rgb10_a2ui), GL }, + { "GL_ARB_texture_rg", o(ARB_texture_rg), GL }, + { "GL_ARB_texture_swizzle", o(EXT_texture_swizzle), GL }, + { "GL_ARB_transform_feedback2", o(ARB_transform_feedback2), GL }, + { "GL_ARB_transpose_matrix", o(ARB_transpose_matrix), GL }, + { "GL_ARB_uniform_buffer_object", o(ARB_uniform_buffer_object), GL }, + { "GL_ARB_vertex_array_bgra", o(EXT_vertex_array_bgra), GL }, + { "GL_ARB_vertex_array_object", o(ARB_vertex_array_object), GL }, + { "GL_ARB_vertex_buffer_object", o(ARB_vertex_buffer_object), GL }, + { "GL_ARB_vertex_program", o(ARB_vertex_program), GL }, + { "GL_ARB_vertex_shader", o(ARB_vertex_shader), GL }, + { "GL_ARB_vertex_type_2_10_10_10_rev", o(ARB_vertex_type_2_10_10_10_rev), GL }, + { "GL_ARB_window_pos", o(ARB_window_pos), GL }, + + /* EXT extensions */ + { "GL_EXT_abgr", o(EXT_abgr), GL }, + { "GL_EXT_bgra", o(EXT_bgra), GL }, + { "GL_EXT_blend_color", o(EXT_blend_color), GL }, + { "GL_EXT_blend_equation_separate", o(EXT_blend_equation_separate), GL }, + { "GL_EXT_blend_func_separate", o(EXT_blend_func_separate), GL }, + { "GL_EXT_blend_logic_op", o(EXT_blend_logic_op), GL }, + { "GL_EXT_blend_minmax", o(EXT_blend_minmax), GL | ES1 | ES2 }, + { "GL_EXT_blend_subtract", o(EXT_blend_subtract), GL }, + { "GL_EXT_clip_volume_hint", o(EXT_clip_volume_hint), GL }, + { "GL_EXT_compiled_vertex_array", o(EXT_compiled_vertex_array), GL }, + { "GL_EXT_copy_texture", o(EXT_copy_texture), GL }, + { "GL_EXT_depth_bounds_test", o(EXT_depth_bounds_test), GL }, + { "GL_EXT_draw_buffers2", o(EXT_draw_buffers2), GL }, + { "GL_EXT_draw_instanced", o(ARB_draw_instanced), GL }, + { "GL_EXT_draw_range_elements", o(EXT_draw_range_elements), GL }, + { "GL_EXT_fog_coord", o(EXT_fog_coord), GL }, + { "GL_EXT_framebuffer_blit", o(EXT_framebuffer_blit), GL }, + { "GL_EXT_framebuffer_multisample", o(EXT_framebuffer_multisample), GL }, + { "GL_EXT_framebuffer_object", o(EXT_framebuffer_object), GL }, + { "GL_EXT_framebuffer_sRGB", o(EXT_framebuffer_sRGB), GL }, + { "GL_EXT_gpu_program_parameters", o(EXT_gpu_program_parameters), GL }, + { "GL_EXT_gpu_shader4", o(EXT_gpu_shader4), GL }, + { "GL_EXT_multi_draw_arrays", o(EXT_multi_draw_arrays), GL | ES1 | ES2 }, + { "GL_EXT_packed_depth_stencil", o(EXT_packed_depth_stencil), GL }, + { "GL_EXT_packed_float", o(EXT_packed_float), GL }, + { "GL_EXT_packed_pixels", o(EXT_packed_pixels), GL }, + { "GL_EXT_paletted_texture", o(EXT_paletted_texture), GL }, + { "GL_EXT_pixel_buffer_object", o(EXT_pixel_buffer_object), GL }, + { "GL_EXT_point_parameters", o(EXT_point_parameters), GL }, + { "GL_EXT_polygon_offset", o(EXT_polygon_offset), GL }, + { "GL_EXT_provoking_vertex", o(EXT_provoking_vertex), GL }, + { "GL_EXT_rescale_normal", o(EXT_rescale_normal), GL }, + { "GL_EXT_secondary_color", o(EXT_secondary_color), GL }, + { "GL_EXT_separate_shader_objects", o(EXT_separate_shader_objects), GL }, + { "GL_EXT_separate_specular_color", o(EXT_separate_specular_color), GL }, + { "GL_EXT_shadow_funcs", o(EXT_shadow_funcs), GL }, + { "GL_EXT_shared_texture_palette", o(EXT_shared_texture_palette), GL }, + { "GL_EXT_stencil_two_side", o(EXT_stencil_two_side), GL }, + { "GL_EXT_stencil_wrap", o(EXT_stencil_wrap), GL }, + { "GL_EXT_subtexture", o(EXT_subtexture), GL }, + { "GL_EXT_texture3D", o(EXT_texture3D), GL }, + { "GL_EXT_texture_array", o(EXT_texture_array), GL }, + { "GL_EXT_texture_compression_dxt1", o(EXT_texture_compression_s3tc), GL | ES1 | ES2 }, + { "GL_EXT_texture_compression_rgtc", o(ARB_texture_compression_rgtc), GL }, + { "GL_EXT_texture_compression_s3tc", o(EXT_texture_compression_s3tc), GL }, + { "GL_EXT_texture_cube_map", o(ARB_texture_cube_map), GL }, + { "GL_EXT_texture_edge_clamp", o(SGIS_texture_edge_clamp), GL }, + { "GL_EXT_texture_env_add", o(EXT_texture_env_add), GL }, + { "GL_EXT_texture_env_combine", o(EXT_texture_env_combine), GL }, + { "GL_EXT_texture_env_dot3", o(EXT_texture_env_dot3), GL }, + { "GL_EXT_texture_filter_anisotropic", o(EXT_texture_filter_anisotropic), GL | ES1 | ES2 }, + { "GL_EXT_texture_format_BGRA8888", o(EXT_texture_format_BGRA8888), ES1 | ES2 }, + { "GL_EXT_texture_integer", o(EXT_texture_integer), GL }, + { "GL_EXT_texture_lod_bias", o(EXT_texture_lod_bias), GL | ES1 }, + { "GL_EXT_texture_mirror_clamp", o(EXT_texture_mirror_clamp), GL }, + { "GL_EXT_texture_object", o(EXT_texture_object), GL }, + { "GL_EXT_texture", o(EXT_texture), GL }, + { "GL_EXT_texture_rectangle", o(NV_texture_rectangle), GL }, + { "GL_EXT_texture_shared_exponent", o(EXT_texture_shared_exponent), GL }, + { "GL_EXT_texture_sRGB", o(EXT_texture_sRGB), GL }, + { "GL_EXT_texture_swizzle", o(EXT_texture_swizzle), GL }, + { "GL_EXT_texture_type_2_10_10_10_REV", o(dummy_true), ES2 }, + { "GL_EXT_timer_query", o(EXT_timer_query), GL }, + { "GL_EXT_transform_feedback", o(EXT_transform_feedback), GL }, + { "GL_EXT_vertex_array_bgra", o(EXT_vertex_array_bgra), GL }, + { "GL_EXT_vertex_array", o(EXT_vertex_array), GL }, + { "GL_EXT_vertex_array_set", o(EXT_vertex_array_set), GL }, + + /* OES extensions */ + { "GL_OES_blend_equation_separate", o(EXT_blend_equation_separate), ES1 }, + { "GL_OES_blend_func_separate", o(EXT_blend_func_separate), ES1 }, + { "GL_OES_blend_subtract", o(EXT_blend_subtract), ES1 }, + { "GL_OES_byte_coordinates", o(dummy_true), ES1 }, + { "GL_OES_compressed_paletted_texture", o(dummy_true), ES1 }, + { "GL_OES_depth24", o(ARB_framebuffer_object), ES1 | ES2 }, + { "GL_OES_depth32", o(ARB_framebuffer_object), ES1 | ES2 }, + { "GL_OES_depth_texture", o(ARB_depth_texture), ES2 }, +#if FEATURE_OES_draw_texture + { "GL_OES_draw_texture", o(OES_draw_texture), ES1 | ES2 }, +#endif +#if FEATURE_OES_EGL_image + /* FIXME: Mesa expects GL_OES_EGL_image to be available in OpenGL contexts. */ + { "GL_OES_EGL_image", o(OES_EGL_image), GL | ES1 | ES2 }, +#endif + { "GL_OES_element_index_uint", o(EXT_vertex_array), ES1 | ES2 }, + { "GL_OES_fbo_render_mipmap", o(ARB_framebuffer_object), ES1 | ES2 }, + { "GL_OES_fixed_point", o(dummy_true), ES1 }, + { "GL_OES_framebuffer_object", o(ARB_framebuffer_object), ES1 }, + { "GL_OES_mapbuffer", o(ARB_vertex_buffer_object), ES1 | ES2 }, + { "GL_OES_matrix_get", o(dummy_true), ES1 }, + { "GL_OES_packed_depth_stencil", o(EXT_packed_depth_stencil), ES1 | ES2 }, + { "GL_OES_point_size_array", o(dummy_true), ES1 }, + { "GL_OES_point_sprite", o(dummy_true), ES1 }, + { "GL_OES_query_matrix", o(dummy_true), ES1 }, + { "GL_OES_read_format", o(OES_read_format), GL | ES1 }, + { "GL_OES_rgb8_rgba8", o(ARB_framebuffer_object), ES1 | ES2 }, + { "GL_OES_single_precision", o(dummy_true), ES1 }, + { "GL_OES_standard_derivatives", o(ARB_fragment_shader), ES2 }, + { "GL_OES_stencil1", o(ARB_framebuffer_object), ES1 | ES2 }, + { "GL_OES_stencil4", o(ARB_framebuffer_object), ES1 | ES2 }, + { "GL_OES_stencil8", o(ARB_framebuffer_object), ES1 }, + { "GL_OES_stencil_wrap", o(EXT_stencil_wrap), ES1 }, + /* GL_OES_texture_3D is disabled due to missing GLSL support. */ + { "GL_OES_texture_3D", o(EXT_texture3D), DISABLE }, + { "GL_OES_texture_cube_map", o(ARB_texture_cube_map), ES1 }, + { "GL_OES_texture_env_crossbar", o(ARB_texture_env_crossbar), ES1 }, + { "GL_OES_texture_mirrored_repeat", o(ARB_texture_mirrored_repeat), ES1 }, + { "GL_OES_texture_npot", o(ARB_texture_non_power_of_two), ES2 }, + + /* Vendor extensions */ + { "GL_3DFX_texture_compression_FXT1", o(TDFX_texture_compression_FXT1), GL }, + { "GL_APPLE_client_storage", o(APPLE_client_storage), GL }, + { "GL_APPLE_object_purgeable", o(APPLE_object_purgeable), GL }, + { "GL_APPLE_packed_pixels", o(APPLE_packed_pixels), GL }, + { "GL_APPLE_vertex_array_object", o(APPLE_vertex_array_object), GL }, + { "GL_ATI_blend_equation_separate", o(EXT_blend_equation_separate), GL }, + { "GL_ATI_envmap_bumpmap", o(ATI_envmap_bumpmap), GL }, + { "GL_ATI_fragment_shader", o(ATI_fragment_shader), GL }, + { "GL_ATI_separate_stencil", o(ATI_separate_stencil), GL }, + { "GL_ATI_texture_env_combine3", o(ATI_texture_env_combine3), GL }, + { "GL_ATI_texture_mirror_once", o(ATI_texture_mirror_once), GL }, + { "GL_IBM_multimode_draw_arrays", o(IBM_multimode_draw_arrays), GL }, + { "GL_IBM_rasterpos_clip", o(IBM_rasterpos_clip), GL }, + { "GL_IBM_texture_mirrored_repeat", o(ARB_texture_mirrored_repeat), GL }, + { "GL_INGR_blend_func_separate", o(EXT_blend_func_separate), GL }, + { "GL_MESA_pack_invert", o(MESA_pack_invert), GL }, + { "GL_MESA_resize_buffers", o(MESA_resize_buffers), GL }, + { "GL_MESA_texture_array", o(MESA_texture_array), GL }, + { "GL_MESA_texture_signed_rgba", o(MESA_texture_signed_rgba), GL }, + { "GL_MESA_window_pos", o(ARB_window_pos), GL }, + { "GL_MESAX_texture_float", o(ARB_texture_float), GL }, + { "GL_MESA_ycbcr_texture", o(MESA_ycbcr_texture), GL }, + { "GL_NV_blend_square", o(NV_blend_square), GL }, + { "GL_NV_conditional_render", o(NV_conditional_render), GL }, + { "GL_NV_depth_clamp", o(ARB_depth_clamp), GL }, + { "GL_NV_fragment_program", o(NV_fragment_program), GL }, + { "GL_NV_fragment_program_option", o(NV_fragment_program_option), GL }, + { "GL_NV_light_max_exponent", o(NV_light_max_exponent), GL }, + { "GL_NV_packed_depth_stencil", o(EXT_packed_depth_stencil), GL }, + { "GL_NV_point_sprite", o(NV_point_sprite), GL }, + { "GL_NV_primitive_restart", o(NV_primitive_restart), GL }, + { "GL_NV_texgen_reflection", o(NV_texgen_reflection), GL }, + { "GL_NV_texture_env_combine4", o(NV_texture_env_combine4), GL }, + { "GL_NV_texture_rectangle", o(NV_texture_rectangle), GL }, + { "GL_NV_vertex_program1_1", o(NV_vertex_program1_1), GL }, + { "GL_NV_vertex_program", o(NV_vertex_program), GL }, + { "GL_S3_s3tc", o(S3_s3tc), GL }, + { "GL_SGIS_generate_mipmap", o(SGIS_generate_mipmap), GL }, + { "GL_SGIS_texture_border_clamp", o(ARB_texture_border_clamp), GL }, + { "GL_SGIS_texture_edge_clamp", o(SGIS_texture_edge_clamp), GL }, + { "GL_SGIS_texture_lod", o(SGIS_texture_lod), GL }, + { "GL_SGI_texture_color_table", o(SGI_texture_color_table), GL }, + { "GL_SUN_multi_draw_arrays", o(EXT_multi_draw_arrays), GL }, + + { 0, 0, 0 }, +}; + + +/** + * Given an extension name, lookup up the corresponding member of struct + * gl_extensions and return that member's offset (in bytes). If the name is + * not found in the \c extension_table, return 0. + * + * \param name Name of extension. + * \return Offset of member in struct gl_extensions. + */ +static size_t +name_to_offset(const char* name) +{ + if (name == 0) + return 0; + + for (const struct extension *i = extension_table; i->name != 0; ++i) { + if (strcmp(name, i->name) == 0) + return i->offset; + } + + return 0; +} + + +/** + * \brief Extensions enabled by default. + * + * These extensions are enabled by _mesa_init_extensions(). + * + * XXX: Should these defaults also apply to GLES? + */ +static const size_t default_extensions[] = { + o(ARB_copy_buffer), + o(ARB_draw_buffers), + o(ARB_multisample), + o(ARB_texture_compression), + o(ARB_transpose_matrix), + o(ARB_vertex_buffer_object), + o(ARB_window_pos), + + o(EXT_abgr), + o(EXT_bgra), + o(EXT_compiled_vertex_array), + o(EXT_copy_texture), + o(EXT_draw_range_elements), + o(EXT_multi_draw_arrays), + o(EXT_packed_pixels), + o(EXT_polygon_offset), + o(EXT_rescale_normal), + o(EXT_separate_specular_color), + o(EXT_subtexture), + o(EXT_texture), + o(EXT_texture3D), + o(EXT_texture_object), + o(EXT_vertex_array), + + o(OES_read_format), + + /* Vendor Extensions */ + o(APPLE_packed_pixels), + o(IBM_multimode_draw_arrays), + o(IBM_rasterpos_clip), + o(NV_light_max_exponent), + o(NV_texgen_reflection), + o(SGIS_generate_mipmap), + o(SGIS_texture_edge_clamp), + o(SGIS_texture_lod), + + 0, +}; /** @@ -513,25 +651,26 @@ _mesa_enable_2_1_extensions(struct gl_context *ctx) static GLboolean set_extension( struct gl_context *ctx, const char *name, GLboolean state ) { - GLboolean *base = (GLboolean *) &ctx->Extensions; - GLuint i; - if (ctx->Extensions.String) { /* The string was already queried - can't change it now! */ _mesa_problem(ctx, "Trying to enable/disable extension after glGetString(GL_EXTENSIONS): %s", name); return GL_FALSE; } - for (i = 0 ; i < Elements(default_extensions) ; i++) { - if (strcmp(default_extensions[i].name, name) == 0) { - if (default_extensions[i].flag_offset) { - GLboolean *enabled = base + default_extensions[i].flag_offset; - *enabled = state; - } - return GL_TRUE; - } + size_t offset = name_to_offset(name); + if (offset == 0) { + _mesa_problem(ctx, "Trying to enable/disable unknown extension %s", + name); + return GL_FALSE; + } else if (offset == o(dummy_true) && state == GL_FALSE) { + _mesa_problem(ctx, "Trying to disable a permanently enabled extension: " + "%s", name); + return GL_FALSE; + } else { + GLboolean *base = (GLboolean *) &ctx->Extensions; + base[offset] = state; + return GL_TRUE; } - return GL_FALSE; } @@ -559,37 +698,20 @@ _mesa_disable_extension( struct gl_context *ctx, const char *name ) } -/** - * Check if the i-th extension is enabled. - */ -static GLboolean -extension_enabled(struct gl_context *ctx, GLuint index) -{ - const GLboolean *base = (const GLboolean *) &ctx->Extensions; - if (!default_extensions[index].flag_offset || - *(base + default_extensions[index].flag_offset)) { - return GL_TRUE; - } - else { - return GL_FALSE; - } -} - - /** * Test if the named extension is enabled in this context. */ GLboolean _mesa_extension_is_enabled( struct gl_context *ctx, const char *name ) { - GLuint i; + if (name == 0) + return GL_FALSE; - for (i = 0 ; i < Elements(default_extensions) ; i++) { - if (strcmp(default_extensions[i].name, name) == 0) { - return extension_enabled(ctx, i); - } - } - return GL_FALSE; + size_t offset = name_to_offset(name); + if (offset == 0) + return GL_FALSE; + GLboolean *base = (GLboolean *) &ctx->Extensions; + return base[offset]; } @@ -620,8 +742,10 @@ append(const char *a, const char *b) * For extension names that are recognized, turn them on. For extension * names that are recognized and prefixed with '-', turn them off. * Return a string of the unknown/leftover names. + * + * Returnd string needs to be freed. */ -static const char * +static char * get_extension_override( struct gl_context *ctx ) { const char *envExt = _mesa_getenv("MESA_EXTENSION_OVERRIDE"); @@ -668,22 +792,25 @@ get_extension_override( struct gl_context *ctx ) /** - * Run through the default_extensions array above and set the - * ctx->Extensions.ARB/EXT_* flags accordingly. - * To be called during context initialization. + * \brief Initialize extension tables and enable default extensions. + * + * This should be called during context initialization. + * Note: Sets gl_extensions.dummy_true to true. */ void _mesa_init_extensions( struct gl_context *ctx ) { GLboolean *base = (GLboolean *) &ctx->Extensions; - GLuint i; + GLboolean *sentinel = base + o(extension_sentinel); - for (i = 0 ; i < Elements(default_extensions) ; i++) { - if (default_extensions[i].enabled && - default_extensions[i].flag_offset) { - *(base + default_extensions[i].flag_offset) = GL_TRUE; - } - } + /* First, turn all extensions off. */ + for (GLboolean *i = base; i != sentinel; ++i) + *i = GL_FALSE; + + /* Then, selectively turn default extensions on. */ + ctx->Extensions.dummy_true = GL_TRUE; + for (const size_t *i = default_extensions; *i != 0; ++i) + base[*i] = GL_TRUE; } @@ -691,256 +818,45 @@ _mesa_init_extensions( struct gl_context *ctx ) * Construct the GL_EXTENSIONS string. Called the first time that * glGetString(GL_EXTENSIONS) is called. */ -static GLubyte * -compute_extensions( struct gl_context *ctx ) -{ - const char *extraExt = get_extension_override(ctx); - GLuint extStrLen = 0; - char *s; - GLuint i; - - /* first, compute length of the extension string */ - for (i = 0 ; i < Elements(default_extensions) ; i++) { - if (extension_enabled(ctx, i)) { - extStrLen += (GLuint) strlen(default_extensions[i].name) + 1; - } - } - - if (extraExt) - extStrLen += strlen(extraExt) + 1; /* +1 for space */ - - /* allocate the extension string */ - s = (char *) malloc(extStrLen); - if (!s) - return NULL; - - /* second, build the extension string */ - extStrLen = 0; - for (i = 0 ; i < Elements(default_extensions) ; i++) { - if (extension_enabled(ctx, i)) { - GLuint len = (GLuint) strlen(default_extensions[i].name); - memcpy(s + extStrLen, default_extensions[i].name, len); - extStrLen += len; - s[extStrLen] = ' '; - extStrLen++; - } - } - ASSERT(extStrLen > 0); - - s[extStrLen - 1] = 0; /* -1 to overwrite trailing the ' ' */ - - if (extraExt) { - s = append(s, " "); - s = append(s, extraExt); - } - - return (GLubyte *) s; -} - -static size_t -append_extension(GLubyte **str, const char *ext) -{ - GLubyte *s = *str; - size_t len = strlen(ext); - - if (s) { - memcpy(s, ext, len); - s[len++] = ' '; - s[len] = '\0'; - - *str += len; - } - else { - len++; - } - - return len; -} - - -static size_t -make_extension_string_es1(const struct gl_context *ctx, GLubyte *str) -{ - size_t len = 0; - - /* Core additions */ - len += append_extension(&str, "GL_OES_byte_coordinates"); - len += append_extension(&str, "GL_OES_fixed_point"); - len += append_extension(&str, "GL_OES_single_precision"); - len += append_extension(&str, "GL_OES_matrix_get"); - - /* 1.1 required extensions */ - len += append_extension(&str, "GL_OES_read_format"); - len += append_extension(&str, "GL_OES_compressed_paletted_texture"); - len += append_extension(&str, "GL_OES_point_size_array"); - len += append_extension(&str, "GL_OES_point_sprite"); - - /* 1.1 deprecated extensions */ - len += append_extension(&str, "GL_OES_query_matrix"); - -#if FEATURE_OES_draw_texture - if (ctx->Extensions.OES_draw_texture) - len += append_extension(&str, "GL_OES_draw_texture"); -#endif - - if (ctx->Extensions.EXT_blend_equation_separate) - len += append_extension(&str, "GL_OES_blend_equation_separate"); - if (ctx->Extensions.EXT_blend_func_separate) - len += append_extension(&str, "GL_OES_blend_func_separate"); - if (ctx->Extensions.EXT_blend_subtract) - len += append_extension(&str, "GL_OES_blend_subtract"); - - if (ctx->Extensions.EXT_stencil_wrap) - len += append_extension(&str, "GL_OES_stencil_wrap"); - - if (ctx->Extensions.ARB_texture_cube_map) - len += append_extension(&str, "GL_OES_texture_cube_map"); - if (ctx->Extensions.ARB_texture_env_crossbar) - len += append_extension(&str, "GL_OES_texture_env_crossbar"); - if (ctx->Extensions.ARB_texture_mirrored_repeat) - len += append_extension(&str, "GL_OES_texture_mirrored_repeat"); - - if (ctx->Extensions.ARB_framebuffer_object) { - len += append_extension(&str, "GL_OES_framebuffer_object"); - len += append_extension(&str, "GL_OES_depth24"); - len += append_extension(&str, "GL_OES_depth32"); - len += append_extension(&str, "GL_OES_fbo_render_mipmap"); - len += append_extension(&str, "GL_OES_rgb8_rgba8"); - len += append_extension(&str, "GL_OES_stencil1"); - len += append_extension(&str, "GL_OES_stencil4"); - len += append_extension(&str, "GL_OES_stencil8"); - } - - if (ctx->Extensions.EXT_vertex_array) - len += append_extension(&str, "GL_OES_element_index_uint"); - if (ctx->Extensions.ARB_vertex_buffer_object) - len += append_extension(&str, "GL_OES_mapbuffer"); - if (ctx->Extensions.EXT_texture_filter_anisotropic) - len += append_extension(&str, "GL_EXT_texture_filter_anisotropic"); - - /* some applications check this for NPOT support */ - if (ctx->Extensions.ARB_texture_non_power_of_two) - len += append_extension(&str, "GL_ARB_texture_non_power_of_two"); - - if (ctx->Extensions.EXT_texture_compression_s3tc) - len += append_extension(&str, "GL_EXT_texture_compression_dxt1"); - if (ctx->Extensions.EXT_texture_lod_bias) - len += append_extension(&str, "GL_EXT_texture_lod_bias"); - if (ctx->Extensions.EXT_blend_minmax) - len += append_extension(&str, "GL_EXT_blend_minmax"); - if (ctx->Extensions.EXT_multi_draw_arrays) - len += append_extension(&str, "GL_EXT_multi_draw_arrays"); - -#if FEATURE_OES_EGL_image - if (ctx->Extensions.OES_EGL_image) - len += append_extension(&str, "GL_OES_EGL_image"); -#endif - - return len; -} - - -static GLubyte * -compute_extensions_es1(const struct gl_context *ctx) -{ - GLubyte *s; - unsigned int len; - - len = make_extension_string_es1(ctx, NULL); - s = malloc(len + 1); - if (!s) - return NULL; - make_extension_string_es1(ctx, s); - - return s; -} - -static size_t -make_extension_string_es2(const struct gl_context *ctx, GLubyte *str) -{ - size_t len = 0; - - if (ctx->Extensions.ARB_framebuffer_object) { - len += append_extension(&str, "GL_OES_depth24"); - len += append_extension(&str, "GL_OES_depth32"); - len += append_extension(&str, "GL_OES_fbo_render_mipmap"); - len += append_extension(&str, "GL_OES_rgb8_rgba8"); - len += append_extension(&str, "GL_OES_stencil1"); - len += append_extension(&str, "GL_OES_stencil4"); - } - - if (ctx->Extensions.EXT_vertex_array) - len += append_extension(&str, "GL_OES_element_index_uint"); - if (ctx->Extensions.ARB_vertex_buffer_object) - len += append_extension(&str, "GL_OES_mapbuffer"); - -#if 0 - /* disabled because of missing GLSL support */ - if (ctx->Extensions.EXT_texture3D) - len += append_extension(&str, "GL_OES_texture_3D"); -#endif - - if (ctx->Extensions.ARB_texture_non_power_of_two) - len += append_extension(&str, "GL_OES_texture_npot"); - if (ctx->Extensions.EXT_texture_filter_anisotropic) - len += append_extension(&str, "GL_EXT_texture_filter_anisotropic"); - - len += append_extension(&str, "GL_EXT_texture_type_2_10_10_10_REV"); - if (ctx->Extensions.ARB_depth_texture) - len += append_extension(&str, "GL_OES_depth_texture"); - if (ctx->Extensions.EXT_packed_depth_stencil) - len += append_extension(&str, "GL_OES_packed_depth_stencil"); - if (ctx->Extensions.ARB_fragment_shader) - len += append_extension(&str, "GL_OES_standard_derivatives"); - - if (ctx->Extensions.EXT_texture_compression_s3tc) - len += append_extension(&str, "GL_EXT_texture_compression_dxt1"); - if (ctx->Extensions.EXT_blend_minmax) - len += append_extension(&str, "GL_EXT_blend_minmax"); - if (ctx->Extensions.EXT_multi_draw_arrays) - len += append_extension(&str, "GL_EXT_multi_draw_arrays"); - -#if FEATURE_OES_EGL_image - if (ctx->Extensions.OES_EGL_image) - len += append_extension(&str, "GL_OES_EGL_image"); -#endif - - if (ctx->Extensions.EXT_texture_format_BGRA8888) - len += append_extension(&str, "GL_EXT_texture_format_BGRA8888"); - - return len; -} - -static GLubyte * -compute_extensions_es2(struct gl_context *ctx) -{ - GLubyte *s; - unsigned int len; - - len = make_extension_string_es2(ctx, NULL); - s = malloc(len + 1); - if (!s) - return NULL; - make_extension_string_es2(ctx, s); - - return s; -} - - -GLubyte * +GLubyte* _mesa_make_extension_string(struct gl_context *ctx) { - switch (ctx->API) { - case API_OPENGL: - return compute_extensions(ctx); - case API_OPENGLES2: - return compute_extensions_es2(ctx); - case API_OPENGLES: - return compute_extensions_es1(ctx); - default: - assert(0); + /* The extension string. */ + char *exts = 0; + /* Length of extension string. */ + size_t length = 0; + /* String of extra extensions. */ + char *extra_extensions = get_extension_override(ctx); + GLboolean *base = (GLboolean *) &ctx->Extensions; + + /* Compute length of the extension string. */ + for (const struct extension *i = extension_table; i->name != 0; ++i) { + if (base[i->offset] && (i->api_set & (1 << ctx->API))) { + length += strlen(i->name) + 1; /* +1 for space */ + } + } + if (extra_extensions != NULL) + length += 1 + strlen(extra_extensions); /* +1 for space */ + + exts = (char *) calloc(length + 1, sizeof(char)); + if (exts == NULL) { + free(extra_extensions); return NULL; } + + /* Build the extension string.*/ + for (const struct extension *i = extension_table; i->name != 0; ++i) { + if (base[i->offset] && (i->api_set & (1 << ctx->API))) { + strcat(exts, i->name); + strcat(exts, " "); + } + } + if (extra_extensions != 0) { + strcat(exts, extra_extensions); + free(extra_extensions); + } + + return (GLubyte *) exts; } /** @@ -949,38 +865,35 @@ _mesa_make_extension_string(struct gl_context *ctx) GLuint _mesa_get_extension_count(struct gl_context *ctx) { - GLuint i; - /* only count once */ - if (!ctx->Extensions.Count) { - for (i = 0; i < Elements(default_extensions); i++) { - if (extension_enabled(ctx, i)) { - ctx->Extensions.Count++; - } + if (ctx->Extensions.Count != 0) + return ctx->Extensions.Count; + + GLboolean *base = (GLboolean *) &ctx->Extensions; + for (const struct extension *i = extension_table; i->name != 0; ++i) { + if (base[i->offset]) { + ctx->Extensions.Count++; } } - - if (0) - _mesa_debug(ctx, "%u of %d extensions enabled\n", ctx->Extensions.Count, - (int) Elements(default_extensions)); - return ctx->Extensions.Count; } - /** * Return name of i-th enabled extension */ const GLubyte * _mesa_get_enabled_extension(struct gl_context *ctx, GLuint index) { - GLuint i; + if (index < 0) + return NULL; - for (i = 0; i < Elements(default_extensions); i++) { - if (extension_enabled(ctx, i)) { - if (index == 0) - return (const GLubyte *) default_extensions[i].name; - index--; + const GLboolean *base = (GLboolean*) &ctx->Extensions; + size_t n = 0; + for (const struct extension *i = extension_table; i->name != 0; ++i) { + if (n == index && base[i->offset]) { + return (GLubyte*) i->name; + } else if (base[i->offset]) { + ++n; } } diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 4fc25a4148f..3fc1facb4ca 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -2655,6 +2655,8 @@ struct gl_constants struct gl_extensions { GLboolean dummy; /* don't remove this! */ + GLboolean dummy_true; /* Set true by _mesa_init_extensions(). */ + GLboolean dummy_false; /* Set false by _mesa_init_extensions(). */ GLboolean ARB_blend_func_extended; GLboolean ARB_copy_buffer; GLboolean ARB_depth_buffer_float; @@ -2809,6 +2811,7 @@ struct gl_extensions GLboolean OES_EGL_image; GLboolean OES_draw_texture; GLboolean EXT_texture_format_BGRA8888; + GLboolean extension_sentinel; /** The extension string */ const GLubyte *String; /** Number of supported extensions */ From 19418e921af0efce198627d0ce6c92660797d011 Mon Sep 17 00:00:00 2001 From: Chad Versace Date: Sun, 9 Jan 2011 21:53:52 -0800 Subject: [PATCH 049/164] mesa: Add/remove extensions in extension string Add GL_OES_stencil8 to ES2. Remove the following: GL_OES_compressed_paletted_texture : ES1 GL_OES_depth32 : ES1, ES2 GL_OES_stencil1 : ES1, ES2 GL_OES_stencil4 : ES1, ES2 Mesa advertised these extensions, but did not actually support them. Reviewed-by: Ian Romanick --- src/mesa/main/extensions.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c index ca03c09ffec..851bf9ee59b 100644 --- a/src/mesa/main/extensions.c +++ b/src/mesa/main/extensions.c @@ -208,9 +208,9 @@ static const struct extension extension_table[] = { { "GL_OES_blend_func_separate", o(EXT_blend_func_separate), ES1 }, { "GL_OES_blend_subtract", o(EXT_blend_subtract), ES1 }, { "GL_OES_byte_coordinates", o(dummy_true), ES1 }, - { "GL_OES_compressed_paletted_texture", o(dummy_true), ES1 }, + { "GL_OES_compressed_paletted_texture", o(dummy_false), DISABLE }, { "GL_OES_depth24", o(ARB_framebuffer_object), ES1 | ES2 }, - { "GL_OES_depth32", o(ARB_framebuffer_object), ES1 | ES2 }, + { "GL_OES_depth32", o(dummy_false), DISABLE }, { "GL_OES_depth_texture", o(ARB_depth_texture), ES2 }, #if FEATURE_OES_draw_texture { "GL_OES_draw_texture", o(OES_draw_texture), ES1 | ES2 }, @@ -233,9 +233,9 @@ static const struct extension extension_table[] = { { "GL_OES_rgb8_rgba8", o(ARB_framebuffer_object), ES1 | ES2 }, { "GL_OES_single_precision", o(dummy_true), ES1 }, { "GL_OES_standard_derivatives", o(ARB_fragment_shader), ES2 }, - { "GL_OES_stencil1", o(ARB_framebuffer_object), ES1 | ES2 }, - { "GL_OES_stencil4", o(ARB_framebuffer_object), ES1 | ES2 }, - { "GL_OES_stencil8", o(ARB_framebuffer_object), ES1 }, + { "GL_OES_stencil1", o(dummy_false), DISABLE }, + { "GL_OES_stencil4", o(dummy_false), DISABLE }, + { "GL_OES_stencil8", o(ARB_framebuffer_object), ES1 | ES2 }, { "GL_OES_stencil_wrap", o(EXT_stencil_wrap), ES1 }, /* GL_OES_texture_3D is disabled due to missing GLSL support. */ { "GL_OES_texture_3D", o(EXT_texture3D), DISABLE }, From 039150169e99be28d8b172a95a07032a3c862585 Mon Sep 17 00:00:00 2001 From: Chad Versace Date: Tue, 11 Jan 2011 14:56:13 -0800 Subject: [PATCH 050/164] mesa: Change dependencies of some OES extension strings Change all OES extension strings that depend on ARB_framebuffer_object to instead depend on EXT_framebuffer_object. Reviewed-by: Ian Romanick --- src/mesa/main/extensions.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c index 851bf9ee59b..fff4c6ed759 100644 --- a/src/mesa/main/extensions.c +++ b/src/mesa/main/extensions.c @@ -209,7 +209,7 @@ static const struct extension extension_table[] = { { "GL_OES_blend_subtract", o(EXT_blend_subtract), ES1 }, { "GL_OES_byte_coordinates", o(dummy_true), ES1 }, { "GL_OES_compressed_paletted_texture", o(dummy_false), DISABLE }, - { "GL_OES_depth24", o(ARB_framebuffer_object), ES1 | ES2 }, + { "GL_OES_depth24", o(EXT_framebuffer_object), ES1 | ES2 }, { "GL_OES_depth32", o(dummy_false), DISABLE }, { "GL_OES_depth_texture", o(ARB_depth_texture), ES2 }, #if FEATURE_OES_draw_texture @@ -220,9 +220,9 @@ static const struct extension extension_table[] = { { "GL_OES_EGL_image", o(OES_EGL_image), GL | ES1 | ES2 }, #endif { "GL_OES_element_index_uint", o(EXT_vertex_array), ES1 | ES2 }, - { "GL_OES_fbo_render_mipmap", o(ARB_framebuffer_object), ES1 | ES2 }, + { "GL_OES_fbo_render_mipmap", o(EXT_framebuffer_object), ES1 | ES2 }, { "GL_OES_fixed_point", o(dummy_true), ES1 }, - { "GL_OES_framebuffer_object", o(ARB_framebuffer_object), ES1 }, + { "GL_OES_framebuffer_object", o(EXT_framebuffer_object), ES1 }, { "GL_OES_mapbuffer", o(ARB_vertex_buffer_object), ES1 | ES2 }, { "GL_OES_matrix_get", o(dummy_true), ES1 }, { "GL_OES_packed_depth_stencil", o(EXT_packed_depth_stencil), ES1 | ES2 }, @@ -230,12 +230,12 @@ static const struct extension extension_table[] = { { "GL_OES_point_sprite", o(dummy_true), ES1 }, { "GL_OES_query_matrix", o(dummy_true), ES1 }, { "GL_OES_read_format", o(OES_read_format), GL | ES1 }, - { "GL_OES_rgb8_rgba8", o(ARB_framebuffer_object), ES1 | ES2 }, + { "GL_OES_rgb8_rgba8", o(EXT_framebuffer_object), ES1 | ES2 }, { "GL_OES_single_precision", o(dummy_true), ES1 }, { "GL_OES_standard_derivatives", o(ARB_fragment_shader), ES2 }, { "GL_OES_stencil1", o(dummy_false), DISABLE }, { "GL_OES_stencil4", o(dummy_false), DISABLE }, - { "GL_OES_stencil8", o(ARB_framebuffer_object), ES1 | ES2 }, + { "GL_OES_stencil8", o(EXT_framebuffer_object), ES1 | ES2 }, { "GL_OES_stencil_wrap", o(EXT_stencil_wrap), ES1 }, /* GL_OES_texture_3D is disabled due to missing GLSL support. */ { "GL_OES_texture_3D", o(EXT_texture3D), DISABLE }, From a7b5664c05a7a0bdc999caedf2dea17fee6bb5c8 Mon Sep 17 00:00:00 2001 From: Chad Versace Date: Wed, 12 Jan 2011 15:21:23 -0800 Subject: [PATCH 051/164] mesa: Change OES_point_sprite to depend on ARB_point_sprite The extension string in GLES1 contexts always advertised GL_OES_point_sprite. Now advertisement depends on ARB_point_sprite being enabled. Reviewed-by: Ian Romanick --- src/mesa/main/extensions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c index fff4c6ed759..750b12f73cc 100644 --- a/src/mesa/main/extensions.c +++ b/src/mesa/main/extensions.c @@ -227,7 +227,7 @@ static const struct extension extension_table[] = { { "GL_OES_matrix_get", o(dummy_true), ES1 }, { "GL_OES_packed_depth_stencil", o(EXT_packed_depth_stencil), ES1 | ES2 }, { "GL_OES_point_size_array", o(dummy_true), ES1 }, - { "GL_OES_point_sprite", o(dummy_true), ES1 }, + { "GL_OES_point_sprite", o(ARB_point_sprite), ES1 }, { "GL_OES_query_matrix", o(dummy_true), ES1 }, { "GL_OES_read_format", o(OES_read_format), GL | ES1 }, { "GL_OES_rgb8_rgba8", o(EXT_framebuffer_object), ES1 | ES2 }, From 356e2e962f424215b41bcf67d7114b83471e8813 Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Wed, 12 Jan 2011 16:23:11 -0800 Subject: [PATCH 052/164] mesa: Move declaration before code in extensions.c. Fixes SCons build. --- src/mesa/main/extensions.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c index 750b12f73cc..c14b05a37a8 100644 --- a/src/mesa/main/extensions.c +++ b/src/mesa/main/extensions.c @@ -651,13 +651,15 @@ _mesa_enable_2_1_extensions(struct gl_context *ctx) static GLboolean set_extension( struct gl_context *ctx, const char *name, GLboolean state ) { + size_t offset; + if (ctx->Extensions.String) { /* The string was already queried - can't change it now! */ _mesa_problem(ctx, "Trying to enable/disable extension after glGetString(GL_EXTENSIONS): %s", name); return GL_FALSE; } - size_t offset = name_to_offset(name); + offset = name_to_offset(name); if (offset == 0) { _mesa_problem(ctx, "Trying to enable/disable unknown extension %s", name); @@ -704,13 +706,16 @@ _mesa_disable_extension( struct gl_context *ctx, const char *name ) GLboolean _mesa_extension_is_enabled( struct gl_context *ctx, const char *name ) { + size_t offset; + GLboolean *base; + if (name == 0) return GL_FALSE; - size_t offset = name_to_offset(name); + offset = name_to_offset(name); if (offset == 0) return GL_FALSE; - GLboolean *base = (GLboolean *) &ctx->Extensions; + base = (GLboolean *) &ctx->Extensions; return base[offset]; } @@ -865,11 +870,13 @@ _mesa_make_extension_string(struct gl_context *ctx) GLuint _mesa_get_extension_count(struct gl_context *ctx) { + GLboolean *base; + /* only count once */ if (ctx->Extensions.Count != 0) return ctx->Extensions.Count; - GLboolean *base = (GLboolean *) &ctx->Extensions; + base = (GLboolean *) &ctx->Extensions; for (const struct extension *i = extension_table; i->name != 0; ++i) { if (base[i->offset]) { ctx->Extensions.Count++; @@ -884,11 +891,14 @@ _mesa_get_extension_count(struct gl_context *ctx) const GLubyte * _mesa_get_enabled_extension(struct gl_context *ctx, GLuint index) { + const GLboolean *base; + size_t n; + if (index < 0) return NULL; - const GLboolean *base = (GLboolean*) &ctx->Extensions; - size_t n = 0; + base = (GLboolean*) &ctx->Extensions; + n = 0; for (const struct extension *i = extension_table; i->name != 0; ++i) { if (n == index && base[i->offset]) { return (GLubyte*) i->name; From b076551e3bf03b9710f4d795e3490ac7ccfd5a9a Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 12 Jan 2011 16:37:03 -0800 Subject: [PATCH 053/164] glsl/Makefile: Fix build with --as-needed. --- src/glsl/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/glsl/Makefile b/src/glsl/Makefile index 15f70298be3..c9525446633 100644 --- a/src/glsl/Makefile +++ b/src/glsl/Makefile @@ -174,7 +174,7 @@ glcpp/glcpp-parse.c: glcpp/glcpp-parse.y bison -v -o "$@" --defines=glcpp/glcpp-parse.h $< builtin_compiler: $(GLSL2_OBJECTS) $(OBJECTS) builtin_stubs.o - $(APP_CXX) $(INCLUDES) $(CFLAGS) $(LDFLAGS) $(TALLOC_LIBS) $(OBJECTS) $(GLSL2_OBJECTS) builtin_stubs.o -o builtin_compiler + $(APP_CXX) $(INCLUDES) $(CFLAGS) $(LDFLAGS) $(OBJECTS) $(GLSL2_OBJECTS) builtin_stubs.o $(TALLOC_LIBS) -o $@ builtin_function.cpp: builtins/profiles/* builtins/ir/* builtins/tools/generate_builtins.py builtins/tools/texture_builtins.py builtin_compiler @echo Regenerating builtin_function.cpp... From 4d96af933710c74b3ccf3f24ee7d62e57f330bba Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 12 Jan 2011 14:39:24 -0700 Subject: [PATCH 054/164] noop: change var type to silence warning --- src/gallium/drivers/noop/noop_pipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gallium/drivers/noop/noop_pipe.c b/src/gallium/drivers/noop/noop_pipe.c index 8c9efc2f536..3680f4622da 100644 --- a/src/gallium/drivers/noop/noop_pipe.c +++ b/src/gallium/drivers/noop/noop_pipe.c @@ -124,7 +124,7 @@ static struct pipe_resource *noop_resource_from_handle(struct pipe_screen *scree struct noop_pipe_screen *noop_screen = (struct noop_pipe_screen*)screen; struct pipe_screen *oscreen = noop_screen->oscreen; struct pipe_resource *result; - struct noop_resource *noop_resource; + struct pipe_resource *noop_resource; result = oscreen->resource_from_handle(oscreen, templ, handle); noop_resource = noop_resource_create(screen, result); From 1b173fb3bad3b53411a4b16a385556b23a247d93 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 12 Jan 2011 14:39:42 -0700 Subject: [PATCH 055/164] glsl: remove trailing comma to silence warning --- src/glsl/lower_jumps.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/glsl/lower_jumps.cpp b/src/glsl/lower_jumps.cpp index d99e0aa7398..dd2601d1aad 100644 --- a/src/glsl/lower_jumps.cpp +++ b/src/glsl/lower_jumps.cpp @@ -66,7 +66,7 @@ enum jump_strength strength_always_clears_execute_flag, strength_continue, strength_break, - strength_return, + strength_return }; struct block_record From 30616fdacfd3e2d8d3df64e4aa6b4cac405f3cf0 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 12 Jan 2011 14:50:41 -0700 Subject: [PATCH 056/164] st/mesa: add st_BeginQuery() case for GL_ANY_SAMPLES_PASSED Fixes piglit occlusion_query2 failure. --- src/mesa/state_tracker/st_cb_queryobj.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mesa/state_tracker/st_cb_queryobj.c b/src/mesa/state_tracker/st_cb_queryobj.c index 35036e72f90..d0ac253bcec 100644 --- a/src/mesa/state_tracker/st_cb_queryobj.c +++ b/src/mesa/state_tracker/st_cb_queryobj.c @@ -85,6 +85,8 @@ st_BeginQuery(struct gl_context *ctx, struct gl_query_object *q) /* convert GL query type to Gallium query type */ switch (q->Target) { + case GL_ANY_SAMPLES_PASSED: + /* fall-through */ case GL_SAMPLES_PASSED_ARB: type = PIPE_QUERY_OCCLUSION_COUNTER; break; From 2fa6012f6a0b02de6093cbccba3bf4432f072e57 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 12 Jan 2011 17:32:00 -0700 Subject: [PATCH 057/164] mesa: fix num_draw_buffers==0 in fixed-function fragment program generation This fixes a problem when glDrawBuffers(GL_NONE). The fragment program was writing to color output[0] but OutputsWritten was 0. That led to a failed assertion in the Mesa->TGSI translation code. NOTE: This is a candidate for the 7.9 and 7.10 branches. --- src/mesa/main/texenvprogram.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mesa/main/texenvprogram.c b/src/mesa/main/texenvprogram.c index a3fa3fe826c..c1380f2a645 100644 --- a/src/mesa/main/texenvprogram.c +++ b/src/mesa/main/texenvprogram.c @@ -1467,7 +1467,7 @@ create_new_program(struct gl_context *ctx, struct state_key *key, p.last_tex_stage = 0; release_temps(ctx, &p); - if (key->enabled_units) { + if (key->enabled_units && key->num_draw_buffers) { GLboolean needbumpstage = GL_FALSE; /* Zeroth pass - bump map textures first */ @@ -1560,7 +1560,7 @@ create_new_program(struct gl_context *ctx, struct state_key *key, _mesa_copy_instructions(p.program->Base.Instructions, instBuffer, p.program->Base.NumInstructions); - if (p.program->FogOption) { + if (key->num_draw_buffers && p.program->FogOption) { _mesa_append_fog_code(ctx, p.program); p.program->FogOption = GL_NONE; } From 67722ae403526d8b267e29ed2ac962b806001ce5 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 12 Jan 2011 18:12:46 -0700 Subject: [PATCH 058/164] mesa: don't assert in GetIntegerIndexed, etc We were getting an assertion upon invalid pname. NOTE: This is a candidate for the 7.9 and 7.10 branches. --- src/mesa/main/get.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c index 5d26f74bbc2..196ac5d1201 100644 --- a/src/mesa/main/get.c +++ b/src/mesa/main/get.c @@ -2311,8 +2311,10 @@ void GLAPIENTRY _mesa_GetBooleanIndexedv( GLenum pname, GLuint index, GLboolean *params ) { union value v; + enum value_type type = + find_value_indexed("glGetBooleanIndexedv", pname, index, &v); - switch (find_value_indexed("glGetBooleanIndexedv", pname, index, &v)) { + switch (type) { case TYPE_INT: params[0] = INT_TO_BOOLEAN(v.value_int); break; @@ -2326,7 +2328,7 @@ _mesa_GetBooleanIndexedv( GLenum pname, GLuint index, GLboolean *params ) params[0] = INT64_TO_BOOLEAN(v.value_int); break; default: - assert(0); + ; /* nothing - GL error was recorded */ } } @@ -2334,8 +2336,10 @@ void GLAPIENTRY _mesa_GetIntegerIndexedv( GLenum pname, GLuint index, GLint *params ) { union value v; + enum value_type type = + find_value_indexed("glGetIntegerIndexedv", pname, index, &v); - switch (find_value_indexed("glGetIntegerIndexedv", pname, index, &v)) { + switch (type) { case TYPE_INT: params[0] = v.value_int; break; @@ -2349,7 +2353,7 @@ _mesa_GetIntegerIndexedv( GLenum pname, GLuint index, GLint *params ) params[0] = INT64_TO_INT(v.value_int); break; default: - assert(0); + ; /* nothing - GL error was recorded */ } } @@ -2358,8 +2362,10 @@ void GLAPIENTRY _mesa_GetInteger64Indexedv( GLenum pname, GLuint index, GLint64 *params ) { union value v; + enum value_type type = + find_value_indexed("glGetIntegerIndexedv", pname, index, &v); - switch (find_value_indexed("glGetIntegerIndexedv", pname, index, &v)) { + switch (type) { case TYPE_INT: params[0] = v.value_int; break; @@ -2373,7 +2379,7 @@ _mesa_GetInteger64Indexedv( GLenum pname, GLuint index, GLint64 *params ) params[0] = v.value_int; break; default: - assert(0); + ; /* nothing - GL error was recorded */ } } #endif /* FEATURE_ARB_sync */ From dd973cd9e81abf1c0bc1880c7905f3277d4361a0 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 12 Jan 2011 18:14:14 -0700 Subject: [PATCH 059/164] mesa: check for dummy renderbuffer in _mesa_FramebufferRenderbufferEXT() Fixes a failed assertion when a renderbuffer ID that was gen'd but not previously bound was passed to glFramebufferRenderbuffer(). Generate the same error that NVIDIA does. NOTE: This is a candidate for the 7.9 and 7.10 branches. --- src/mesa/main/fbobject.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c index 3e7fd9cf0ec..e3aefe9b855 100644 --- a/src/mesa/main/fbobject.c +++ b/src/mesa/main/fbobject.c @@ -1924,6 +1924,13 @@ _mesa_FramebufferRenderbufferEXT(GLenum target, GLenum attachment, " renderbuffer %u)", renderbuffer); return; } + else if (rb == &DummyRenderbuffer) { + /* This is what NVIDIA does */ + _mesa_error(ctx, GL_INVALID_VALUE, + "glFramebufferRenderbufferEXT(renderbuffer %u)", + renderbuffer); + return; + } } else { /* remove renderbuffer attachment */ From 31b10516636043b8d92ce518acf6afb27d82a2d1 Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Wed, 12 Jan 2011 17:43:28 -0800 Subject: [PATCH 060/164] mesa: Move loop variable declarations outside for loop in extensions.c. Fixes MSVC build. --- src/mesa/main/extensions.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c index c14b05a37a8..015f89aa0ba 100644 --- a/src/mesa/main/extensions.c +++ b/src/mesa/main/extensions.c @@ -304,10 +304,12 @@ static const struct extension extension_table[] = { static size_t name_to_offset(const char* name) { + const struct extension *i; + if (name == 0) return 0; - for (const struct extension *i = extension_table; i->name != 0; ++i) { + for (i = extension_table; i->name != 0; ++i) { if (strcmp(name, i->name) == 0) return i->offset; } @@ -807,15 +809,17 @@ _mesa_init_extensions( struct gl_context *ctx ) { GLboolean *base = (GLboolean *) &ctx->Extensions; GLboolean *sentinel = base + o(extension_sentinel); + GLboolean *i; + const size_t *j; /* First, turn all extensions off. */ - for (GLboolean *i = base; i != sentinel; ++i) + for (i = base; i != sentinel; ++i) *i = GL_FALSE; /* Then, selectively turn default extensions on. */ ctx->Extensions.dummy_true = GL_TRUE; - for (const size_t *i = default_extensions; *i != 0; ++i) - base[*i] = GL_TRUE; + for (j = default_extensions; *j != 0; ++j) + base[*j] = GL_TRUE; } @@ -833,9 +837,10 @@ _mesa_make_extension_string(struct gl_context *ctx) /* String of extra extensions. */ char *extra_extensions = get_extension_override(ctx); GLboolean *base = (GLboolean *) &ctx->Extensions; + const struct extension *i; /* Compute length of the extension string. */ - for (const struct extension *i = extension_table; i->name != 0; ++i) { + for (i = extension_table; i->name != 0; ++i) { if (base[i->offset] && (i->api_set & (1 << ctx->API))) { length += strlen(i->name) + 1; /* +1 for space */ } @@ -850,7 +855,7 @@ _mesa_make_extension_string(struct gl_context *ctx) } /* Build the extension string.*/ - for (const struct extension *i = extension_table; i->name != 0; ++i) { + for (i = extension_table; i->name != 0; ++i) { if (base[i->offset] && (i->api_set & (1 << ctx->API))) { strcat(exts, i->name); strcat(exts, " "); @@ -871,13 +876,14 @@ GLuint _mesa_get_extension_count(struct gl_context *ctx) { GLboolean *base; + const struct extension *i; /* only count once */ if (ctx->Extensions.Count != 0) return ctx->Extensions.Count; base = (GLboolean *) &ctx->Extensions; - for (const struct extension *i = extension_table; i->name != 0; ++i) { + for (i = extension_table; i->name != 0; ++i) { if (base[i->offset]) { ctx->Extensions.Count++; } @@ -893,13 +899,14 @@ _mesa_get_enabled_extension(struct gl_context *ctx, GLuint index) { const GLboolean *base; size_t n; + const struct extension *i; if (index < 0) return NULL; base = (GLboolean*) &ctx->Extensions; n = 0; - for (const struct extension *i = extension_table; i->name != 0; ++i) { + for (i = extension_table; i->name != 0; ++i) { if (n == index && base[i->offset]) { return (GLubyte*) i->name; } else if (base[i->offset]) { From 0c1db2feb9c2f5c9a2ef486053b6e9dcd9860b3e Mon Sep 17 00:00:00 2001 From: Ben Skeggs Date: Thu, 13 Jan 2011 13:23:55 +1000 Subject: [PATCH 061/164] nvc0: fix mp_stack_bo relocation Fixes a PT_NOT_PRESENT error cause by: - allocating in VRAM - emitting GART relocs to 0x17bc/0x17c0, moving the buffer - telling the bufmgr that the buffer should be in VRAM when we use it, but not correcting the value sent to 0x17bc/0x17c0. Signed-off-by: Ben Skeggs --- src/gallium/drivers/nvc0/nvc0_screen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gallium/drivers/nvc0/nvc0_screen.c b/src/gallium/drivers/nvc0/nvc0_screen.c index c191790ab14..928ea7eac33 100644 --- a/src/gallium/drivers/nvc0/nvc0_screen.c +++ b/src/gallium/drivers/nvc0/nvc0_screen.c @@ -503,8 +503,8 @@ nvc0_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev) goto fail; BEGIN_RING(chan, RING_3D_(0x17bc), 3); - OUT_RELOCh(chan, screen->mp_stack_bo, 0, NOUVEAU_BO_GART | NOUVEAU_BO_RDWR); - OUT_RELOCl(chan, screen->mp_stack_bo, 0, NOUVEAU_BO_GART | NOUVEAU_BO_RDWR); + OUT_RELOCh(chan, screen->mp_stack_bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RDWR); + OUT_RELOCl(chan, screen->mp_stack_bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RDWR); OUT_RING (chan, 1); ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 17, 1 << 17, &screen->txc); From 8c8e26d66ae41e900cc88521da9c0dc02803d7d2 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 13 Jan 2011 15:16:11 +1000 Subject: [PATCH 062/164] mesa/fbo: prevent assert trigger on i965 with piglit fbo-srgb test. --- src/mesa/main/fbobject.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c index e3aefe9b855..fac63ac994d 100644 --- a/src/mesa/main/fbobject.c +++ b/src/mesa/main/fbobject.c @@ -999,6 +999,8 @@ _mesa_base_fbo_format(struct gl_context *ctx, GLenum internalFormat) case GL_RGBA12: case GL_RGBA16: case GL_RGBA16_SNORM: + case GL_SRGB8_ALPHA8_EXT: + case GL_SRGB8_EXT: return GL_RGBA; case GL_STENCIL_INDEX: case GL_STENCIL_INDEX1_EXT: From bd2b72359ed504434692d7464602c780a322c61e Mon Sep 17 00:00:00 2001 From: Ben Skeggs Date: Thu, 13 Jan 2011 15:25:37 +1000 Subject: [PATCH 063/164] nvc0: disable calling of sw methods we don't implement Left in the code as a marker of what NVIDIA do, just in case we need to do this some day. Signed-off-by: Ben Skeggs --- src/gallium/drivers/nvc0/nvc0_screen.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gallium/drivers/nvc0/nvc0_screen.c b/src/gallium/drivers/nvc0/nvc0_screen.c index 928ea7eac33..2300af52eda 100644 --- a/src/gallium/drivers/nvc0/nvc0_screen.c +++ b/src/gallium/drivers/nvc0/nvc0_screen.c @@ -292,8 +292,10 @@ nvc0_magic_3d_init(struct nouveau_channel *chan) BEGIN_RING(chan, RING_3D_(0x165c), 1); OUT_RING (chan, 0); +#if 0 /* software method */ BEGIN_RING(chan, RING_3D_(0x1528), 1); /* MP poke */ OUT_RING (chan, 0); +#endif BEGIN_RING(chan, RING_3D_(0x12ac), 1); OUT_RING (chan, 0); @@ -323,8 +325,10 @@ nvc0_magic_3d_init(struct nouveau_channel *chan) OUT_RING (chan, 0); BEGIN_RING(chan, RING_3D_(0x0300), 1); OUT_RING (chan, 3); +#if 0 /* software method */ BEGIN_RING(chan, RING_3D_(0x1280), 1); /* PGRAPH poke */ OUT_RING (chan, 0); +#endif BEGIN_RING(chan, RING_3D_(0x02d0), 1); OUT_RING (chan, 0x1f40); BEGIN_RING(chan, RING_3D_(0x00fdc), 1); From 71b889f904fcba4fbc5aafff4cb62a7201f38075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=B6glund?= Date: Thu, 6 Jan 2011 23:12:08 +0100 Subject: [PATCH 064/164] st/mesa: fix a regression from cae2bb76 stObj->pt is null when a TFP texture is passed to st_finalize_texture, and with the changes introduced in the above commit this resulted in a new texture being created and the existing image being copied into it. NOTE: This is a candidate for the 7.10 branch. Reviewed-by: Alex Deucher --- src/mesa/state_tracker/st_cb_texture.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 14d33f7b490..09a10ba5819 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -1858,9 +1858,8 @@ st_finalize_texture(struct gl_context *ctx, * will match. */ if (firstImage->pt && - stObj->pt && firstImage->pt != stObj->pt && - firstImage->pt->last_level >= stObj->pt->last_level) { + (!stObj->pt || firstImage->pt->last_level >= stObj->pt->last_level)) { pipe_resource_reference(&stObj->pt, firstImage->pt); pipe_sampler_view_reference(&stObj->sampler_view, NULL); } From 407184fe08ced99875c3abfac743a1d60857ccf2 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 13 Jan 2011 16:49:32 +1000 Subject: [PATCH 065/164] mesa/srgb: handle SARGB8 case in the sw fbo renderer. --- src/mesa/main/texrender.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/mesa/main/texrender.c b/src/mesa/main/texrender.c index d4def2e0fbe..968f9f139c5 100644 --- a/src/mesa/main/texrender.c +++ b/src/mesa/main/texrender.c @@ -595,6 +595,10 @@ update_wrapper(struct gl_context *ctx, const struct gl_renderbuffer_attachment * trb->Base.DataType = CHAN_TYPE; trb->Base._BaseFormat = GL_RGBA; break; + case MESA_FORMAT_SARGB8: + trb->Fetchf = _mesa_get_texel_fetch_func(MESA_FORMAT_ARGB8888, _mesa_get_texture_dimensions(att->Texture->Target)); + trb->Base.DataType = CHAN_TYPE; + trb->Base._BaseFormat = GL_RGBA; default: trb->Base.DataType = CHAN_TYPE; trb->Base._BaseFormat = GL_RGBA; From daeb0c646e0d652bfa16d326028753ecf092c0c9 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 3 Nov 2010 12:47:06 -0700 Subject: [PATCH 066/164] ir_reader: Add a pattern matching system and use it everywhere. Previously, the IR reader was riddled with code that: 1. Checked for the right number of list elements (via a linked list walk) 2. Retrieved references to each component (via ->next->next pointers) 3. Downcasted as necessary to make sure that each sub-component was the right type (i.e. symbol, int, list). 4. Checking that the tag (i.e. "declare") was correct. This was all very ad-hoc and a bit ugly. Error checking had to be done at both steps 1, 3, and 4. Most code didn't even check the tag, relying on the caller to do so. Not all callers did. The new pattern matching module performs the whole process in a single straightforward function call, resulting in shorter, more readable code. Unfortunately, MSVC does not support C99-style anonymous arrays, so the pattern must be declared outside of the match call. --- src/glsl/ir_reader.cpp | 524 ++++++++++++++++---------------------- src/glsl/s_expression.cpp | 46 ++++ src/glsl/s_expression.h | 38 +++ 3 files changed, 297 insertions(+), 311 deletions(-) diff --git a/src/glsl/ir_reader.cpp b/src/glsl/ir_reader.cpp index 5a718d3b756..00146d8c15e 100644 --- a/src/glsl/ir_reader.cpp +++ b/src/glsl/ir_reader.cpp @@ -21,8 +21,6 @@ * DEALINGS IN THE SOFTWARE. */ -#include - extern "C" { #include } @@ -43,7 +41,7 @@ static void scan_for_prototypes(_mesa_glsl_parse_state *, exec_list *, static ir_function *read_function(_mesa_glsl_parse_state *, s_list *, bool skip_body); static void read_function_sig(_mesa_glsl_parse_state *, ir_function *, - s_list *, bool skip_body); + s_expression *, bool skip_body); static void read_instructions(_mesa_glsl_parse_state *, exec_list *, s_expression *, ir_loop *); @@ -124,47 +122,23 @@ ir_read_error(_mesa_glsl_parse_state *state, s_expression *expr, static const glsl_type * read_type(_mesa_glsl_parse_state *st, s_expression *expr) { - s_list *list = SX_AS_LIST(expr); - if (list != NULL) { - s_symbol *type_sym = SX_AS_SYMBOL(list->subexpressions.get_head()); - if (type_sym == NULL) { - ir_read_error(st, expr, "expected type (array ...) or (struct ...)"); + s_expression *s_base_type; + s_int *s_size; + + s_pattern pat[] = { "array", s_base_type, s_size }; + if (MATCH(expr, pat)) { + const glsl_type *base_type = read_type(st, s_base_type); + if (base_type == NULL) { + ir_read_error(st, NULL, "when reading base type of array type"); return NULL; } - if (strcmp(type_sym->value(), "array") == 0) { - if (list->length() != 3) { - ir_read_error(st, expr, "expected type (array )"); - return NULL; - } - // Read base type - s_expression *base_expr = (s_expression*) type_sym->next; - const glsl_type *base_type = read_type(st, base_expr); - if (base_type == NULL) { - ir_read_error(st, NULL, "when reading base type of array"); - return NULL; - } - - // Read array size - s_int *size = SX_AS_INT(base_expr->next); - if (size == NULL) { - ir_read_error(st, expr, "found non-integer array size"); - return NULL; - } - - return glsl_type::get_array_instance(base_type, size->value()); - } else if (strcmp(type_sym->value(), "struct") == 0) { - assert(false); // FINISHME - } else { - ir_read_error(st, expr, "expected (array ...) or (struct ...); " - "found (%s ...)", type_sym->value()); - return NULL; - } + return glsl_type::get_array_instance(base_type, s_size->value()); } s_symbol *type_sym = SX_AS_SYMBOL(expr); if (type_sym == NULL) { - ir_read_error(st, expr, "expected (symbol or list)"); + ir_read_error(st, expr, "expected "); return NULL; } @@ -207,14 +181,11 @@ read_function(_mesa_glsl_parse_state *st, s_list *list, bool skip_body) { void *ctx = st; bool added = false; - if (list->length() < 3) { - ir_read_error(st, list, "Expected (function (signature ...) ...)"); - return NULL; - } + s_symbol *name; - s_symbol *name = SX_AS_SYMBOL(list->subexpressions.head->next); - if (name == NULL) { - ir_read_error(st, list, "Expected (function ...)"); + s_pattern pat[] = { "function", name }; + if (!PARTIAL_MATCH(list, pat)) { + ir_read_error(st, list, "Expected (function (signature ...) ...)"); return NULL; } @@ -229,46 +200,32 @@ read_function(_mesa_glsl_parse_state *st, s_list *list, bool skip_body) it.next(); // skip "function" tag it.next(); // skip function name for (/* nothing */; it.has_next(); it.next()) { - s_list *siglist = SX_AS_LIST(it.get()); - if (siglist == NULL) { - ir_read_error(st, list, "Expected (function (signature ...) ...)"); - return NULL; - } - - s_symbol *tag = SX_AS_SYMBOL(siglist->subexpressions.get_head()); - if (tag == NULL || strcmp(tag->value(), "signature") != 0) { - ir_read_error(st, siglist, "Expected (signature ...)"); - return NULL; - } - - read_function_sig(st, f, siglist, skip_body); + s_expression *s_sig = (s_expression *) it.get(); + read_function_sig(st, f, s_sig, skip_body); } return added ? f : NULL; } static void -read_function_sig(_mesa_glsl_parse_state *st, ir_function *f, s_list *list, - bool skip_body) +read_function_sig(_mesa_glsl_parse_state *st, ir_function *f, + s_expression *expr, bool skip_body) { void *ctx = st; - if (list->length() != 4) { - ir_read_error(st, list, "Expected (signature (parameters ...) " + s_expression *type_expr; + s_list *paramlist; + s_list *body_list; + + s_pattern pat[] = { "signature", type_expr, paramlist, body_list }; + if (!MATCH(expr, pat)) { + ir_read_error(st, expr, "Expected (signature (parameters ...) " "( ...))"); return; } - s_expression *type_expr = (s_expression*) list->subexpressions.head->next; const glsl_type *return_type = read_type(st, type_expr); if (return_type == NULL) return; - s_list *paramlist = SX_AS_LIST(type_expr->next); - s_list *body_list = SX_AS_LIST(type_expr->next->next); - if (paramlist == NULL || body_list == NULL) { - ir_read_error(st, list, "Expected (signature (parameters ...) " - "( ...))"); - return; - } s_symbol *paramtag = SX_AS_SYMBOL(paramlist->subexpressions.get_head()); if (paramtag == NULL || strcmp(paramtag->value(), "parameters") != 0) { ir_read_error(st, paramlist, "Expected (parameters ...)"); @@ -298,13 +255,13 @@ read_function_sig(_mesa_glsl_parse_state *st, ir_function *f, s_list *list, } else if (sig != NULL) { const char *badvar = sig->qualifiers_match(&hir_parameters); if (badvar != NULL) { - ir_read_error(st, list, "function `%s' parameter `%s' qualifiers " + ir_read_error(st, expr, "function `%s' parameter `%s' qualifiers " "don't match prototype", f->name, badvar); return; } if (sig->return_type != return_type) { - ir_read_error(st, list, "function `%s' return type doesn't " + ir_read_error(st, expr, "function `%s' return type doesn't " "match prototype", f->name); return; } @@ -319,7 +276,7 @@ read_function_sig(_mesa_glsl_parse_state *st, ir_function *f, s_list *list, if (!skip_body && !body_list->subexpressions.is_empty()) { if (sig->is_defined) { - ir_read_error(st, list, "function %s redefined", f->name); + ir_read_error(st, expr, "function %s redefined", f->name); return; } st->current_function = sig; @@ -406,42 +363,30 @@ read_instruction(_mesa_glsl_parse_state *st, s_expression *expr, return inst; } - static ir_variable * read_declaration(_mesa_glsl_parse_state *st, s_list *list) { - void *ctx = st; - if (list->length() != 4) { + s_list *s_quals; + s_expression *s_type; + s_symbol *s_name; + + s_pattern pat[] = { "declare", s_quals, s_type, s_name }; + if (!MATCH(list, pat)) { ir_read_error(st, list, "expected (declare () " ")"); return NULL; } - s_list *quals = SX_AS_LIST(list->subexpressions.head->next); - if (quals == NULL) { - ir_read_error(st, list, "expected a list of variable qualifiers"); - return NULL; - } - - s_expression *type_expr = (s_expression*) quals->next; - const glsl_type *type = read_type(st, type_expr); + const glsl_type *type = read_type(st, s_type); if (type == NULL) return NULL; - s_symbol *var_name = SX_AS_SYMBOL(type_expr->next); - if (var_name == NULL) { - ir_read_error(st, list, "expected variable name, found non-symbol"); - return NULL; - } + ir_variable *var = new(st) ir_variable(type, s_name->value(), ir_var_auto); - ir_variable *var = new(ctx) ir_variable(type, var_name->value(), - ir_var_auto); - - foreach_iter(exec_list_iterator, it, quals->subexpressions) { + foreach_iter(exec_list_iterator, it, s_quals->subexpressions) { s_symbol *qualifier = SX_AS_SYMBOL(it.get()); if (qualifier == NULL) { ir_read_error(st, list, "qualifier list must contain only symbols"); - delete var; return NULL; } @@ -468,7 +413,6 @@ read_declaration(_mesa_glsl_parse_state *st, s_list *list) var->interpolation = ir_var_noperspective; } else { ir_read_error(st, list, "unknown qualifier: %s", qualifier->value()); - delete var; return NULL; } } @@ -483,27 +427,27 @@ read_declaration(_mesa_glsl_parse_state *st, s_list *list) static ir_if * read_if(_mesa_glsl_parse_state *st, s_list *list, ir_loop *loop_ctx) { - void *ctx = st; - if (list->length() != 4) { + s_expression *s_cond; + s_expression *s_then; + s_expression *s_else; + + s_pattern pat[] = { "if", s_cond, s_then, s_else }; + if (!MATCH(list, pat)) { ir_read_error(st, list, "expected (if ( ...) " - "( ...))"); + "( ...))"); return NULL; } - s_expression *cond_expr = (s_expression*) list->subexpressions.head->next; - ir_rvalue *condition = read_rvalue(st, cond_expr); + ir_rvalue *condition = read_rvalue(st, s_cond); if (condition == NULL) { ir_read_error(st, NULL, "when reading condition of (if ...)"); return NULL; } - s_expression *then_expr = (s_expression*) cond_expr->next; - s_expression *else_expr = (s_expression*) then_expr->next; + ir_if *iff = new(st) ir_if(condition); - ir_if *iff = new(ctx) ir_if(condition); - - read_instructions(st, &iff->then_instructions, then_expr, loop_ctx); - read_instructions(st, &iff->else_instructions, else_expr, loop_ctx); + read_instructions(st, &iff->then_instructions, s_then, loop_ctx); + read_instructions(st, &iff->else_instructions, s_else, loop_ctx); if (st->error) { delete iff; iff = NULL; @@ -515,23 +459,19 @@ read_if(_mesa_glsl_parse_state *st, s_list *list, ir_loop *loop_ctx) static ir_loop * read_loop(_mesa_glsl_parse_state *st, s_list *list) { - void *ctx = st; - if (list->length() != 6) { + s_expression *s_counter, *s_from, *s_to, *s_inc, *s_body; + + s_pattern pat[] = { "loop", s_counter, s_from, s_to, s_inc, s_body }; + if (!MATCH(list, pat)) { ir_read_error(st, list, "expected (loop " " )"); return NULL; } - s_expression *count_expr = (s_expression*) list->subexpressions.head->next; - s_expression *from_expr = (s_expression*) count_expr->next; - s_expression *to_expr = (s_expression*) from_expr->next; - s_expression *inc_expr = (s_expression*) to_expr->next; - s_expression *body_expr = (s_expression*) inc_expr->next; - // FINISHME: actually read the count/from/to fields. - ir_loop *loop = new(ctx) ir_loop; - read_instructions(st, &loop->body_instructions, body_expr, loop); + ir_loop *loop = new(st) ir_loop; + read_instructions(st, &loop->body_instructions, s_body, loop); if (st->error) { delete loop; loop = NULL; @@ -543,21 +483,21 @@ read_loop(_mesa_glsl_parse_state *st, s_list *list) static ir_return * read_return(_mesa_glsl_parse_state *st, s_list *list) { - void *ctx = st; - if (list->length() != 2) { + s_expression *expr; + + s_pattern pat[] = { "return", expr }; + if (!MATCH(list, pat)) { ir_read_error(st, list, "expected (return )"); return NULL; } - s_expression *expr = (s_expression*) list->subexpressions.head->next; - ir_rvalue *retval = read_rvalue(st, expr); if (retval == NULL) { ir_read_error(st, NULL, "when reading return value"); return NULL; } - return new(ctx) ir_return(retval); + return new(st) ir_return(retval); } @@ -597,37 +537,27 @@ read_rvalue(_mesa_glsl_parse_state *st, s_expression *expr) static ir_assignment * read_assignment(_mesa_glsl_parse_state *st, s_list *list) { - void *ctx = st; - if (list->length() != 5) { + s_expression *cond_expr, *lhs_expr, *rhs_expr; + s_list *mask_list; + + s_pattern pat[] = { "assign", cond_expr, mask_list, lhs_expr, rhs_expr }; + if (!MATCH(list, pat)) { ir_read_error(st, list, "expected (assign () " " )"); return NULL; } - s_expression *cond_expr = (s_expression*) list->subexpressions.head->next; - s_list *mask_list = SX_AS_LIST(cond_expr->next); - s_expression *lhs_expr = (s_expression*) cond_expr->next->next; - s_expression *rhs_expr = (s_expression*) lhs_expr->next; - ir_rvalue *condition = read_rvalue(st, cond_expr); if (condition == NULL) { ir_read_error(st, NULL, "when reading condition of assignment"); return NULL; } - if (mask_list == NULL || mask_list->length() > 1) { - ir_read_error(st, mask_list, "expected () or ()"); - return NULL; - } - unsigned mask = 0; - if (mask_list->length() == 1) { - s_symbol *mask_symbol = SX_AS_SYMBOL(mask_list->subexpressions.head); - if (mask_symbol == NULL) { - ir_read_error(st, list, "expected a write mask; found non-symbol"); - return NULL; - } + s_symbol *mask_symbol; + s_pattern mask_pat[] = { mask_symbol }; + if (MATCH(mask_list, mask_pat)) { const char *mask_str = mask_symbol->value(); unsigned mask_length = strlen(mask_str); if (mask_length > 4) { @@ -645,6 +575,9 @@ read_assignment(_mesa_glsl_parse_state *st, s_list *list) } mask |= 1 << idx_map[mask_str[i] - 'w']; } + } else if (!mask_list->subexpressions.is_empty()) { + ir_read_error(st, mask_list, "expected () or ()"); + return NULL; } ir_dereference *lhs = read_dereference(st, lhs_expr); @@ -664,21 +597,18 @@ read_assignment(_mesa_glsl_parse_state *st, s_list *list) return NULL; } - return new(ctx) ir_assignment(lhs, rhs, condition, mask); + return new(st) ir_assignment(lhs, rhs, condition, mask); } static ir_call * read_call(_mesa_glsl_parse_state *st, s_list *list) { void *ctx = st; - if (list->length() != 3) { - ir_read_error(st, list, "expected (call ( ...))"); - return NULL; - } + s_symbol *name; + s_list *params; - s_symbol *name = SX_AS_SYMBOL(list->subexpressions.head->next); - s_list *params = SX_AS_LIST(list->subexpressions.head->next->next); - if (name == NULL || params == NULL) { + s_pattern pat[] = { "call", name, params }; + if (!MATCH(list, pat)) { ir_read_error(st, list, "expected (call ( ...))"); return NULL; } @@ -716,61 +646,54 @@ static ir_expression * read_expression(_mesa_glsl_parse_state *st, s_list *list) { void *ctx = st; - const unsigned list_length = list->length(); - if (list_length < 4) { + s_expression *s_type; + s_symbol *s_op; + s_expression *s_arg1; + + s_pattern pat[] = { "expression", s_type, s_op, s_arg1 }; + if (!PARTIAL_MATCH(list, pat)) { ir_read_error(st, list, "expected (expression " " [])"); return NULL; } + s_expression *s_arg2 = (s_expression *) s_arg1->next; // may be tail sentinel - s_expression *type_expr = (s_expression*) list->subexpressions.head->next; - const glsl_type *type = read_type(st, type_expr); + const glsl_type *type = read_type(st, s_type); if (type == NULL) return NULL; /* Read the operator */ - s_symbol *op_sym = SX_AS_SYMBOL(type_expr->next); - if (op_sym == NULL) { - ir_read_error(st, list, "expected operator, found non-symbol"); - return NULL; - } - - ir_expression_operation op = ir_expression::get_operator(op_sym->value()); + ir_expression_operation op = ir_expression::get_operator(s_op->value()); if (op == (ir_expression_operation) -1) { - ir_read_error(st, list, "invalid operator: %s", op_sym->value()); + ir_read_error(st, list, "invalid operator: %s", s_op->value()); return NULL; } - /* Now that we know the operator, check for the right number of operands */ - if (ir_expression::get_num_operands(op) == 2) { - if (list_length != 5) { - ir_read_error(st, list, "expected (expression %s " - " )", op_sym->value()); - return NULL; - } - } else { - if (list_length != 4) { - ir_read_error(st, list, "expected (expression %s )", - op_sym->value()); - return NULL; - } - } - - s_expression *exp1 = (s_expression*) (op_sym->next); - ir_rvalue *arg1 = read_rvalue(st, exp1); - if (arg1 == NULL) { - ir_read_error(st, NULL, "when reading first operand of %s", - op_sym->value()); + unsigned num_operands = ir_expression::get_num_operands(op); + if (num_operands == 1 && !s_arg1->next->is_tail_sentinel()) { + ir_read_error(st, list, "expected (expression %s )", + s_op->value()); return NULL; } + ir_rvalue *arg1 = read_rvalue(st, s_arg1); ir_rvalue *arg2 = NULL; - if (ir_expression::get_num_operands(op) == 2) { - s_expression *exp2 = (s_expression*) (exp1->next); - arg2 = read_rvalue(st, exp2); + if (arg1 == NULL) { + ir_read_error(st, NULL, "when reading first operand of %s", + s_op->value()); + return NULL; + } + + if (num_operands == 2) { + if (s_arg2->is_tail_sentinel() || !s_arg2->next->is_tail_sentinel()) { + ir_read_error(st, list, "expected (expression %s " + ")", s_op->value()); + return NULL; + } + arg2 = read_rvalue(st, s_arg2); if (arg2 == NULL) { ir_read_error(st, NULL, "when reading second operand of %s", - op_sym->value()); + s_op->value()); return NULL; } } @@ -781,14 +704,12 @@ read_expression(_mesa_glsl_parse_state *st, s_list *list) static ir_swizzle * read_swizzle(_mesa_glsl_parse_state *st, s_list *list) { - if (list->length() != 3) { - ir_read_error(st, list, "expected (swiz )"); - return NULL; - } + s_symbol *swiz; + s_expression *sub; - s_symbol *swiz = SX_AS_SYMBOL(list->subexpressions.head->next); - if (swiz == NULL) { - ir_read_error(st, list, "expected a valid swizzle; found non-symbol"); + s_pattern pat[] = { "swiz", swiz, sub }; + if (!MATCH(list, pat)) { + ir_read_error(st, list, "expected (swiz )"); return NULL; } @@ -798,7 +719,6 @@ read_swizzle(_mesa_glsl_parse_state *st, s_list *list) return NULL; } - s_expression *sub = (s_expression*) swiz->next; ir_rvalue *rvalue = read_rvalue(st, sub); if (rvalue == NULL) return NULL; @@ -815,17 +735,19 @@ static ir_constant * read_constant(_mesa_glsl_parse_state *st, s_list *list) { void *ctx = st; - if (list->length() != 3) { + s_expression *type_expr; + s_list *values; + + s_pattern pat[] = { "constant", type_expr, values }; + if (!MATCH(list, pat)) { ir_read_error(st, list, "expected (constant (...))"); return NULL; } - s_expression *type_expr = (s_expression*) list->subexpressions.head->next; const glsl_type *type = read_type(st, type_expr); if (type == NULL) return NULL; - s_list *values = SX_AS_LIST(type_expr->next); if (values == NULL) { ir_read_error(st, list, "expected (constant (...))"); return NULL; @@ -931,12 +853,10 @@ static ir_dereference_variable * read_var_ref(_mesa_glsl_parse_state *st, s_list *list) { void *ctx = st; - if (list->length() != 2) { - ir_read_error(st, list, "expected (var_ref )"); - return NULL; - } - s_symbol *var_name = SX_AS_SYMBOL(list->subexpressions.head->next); - if (var_name == NULL) { + s_symbol *var_name; + + s_pattern pat[] = { "var_ref", var_name }; + if (!MATCH(list, pat)) { ir_read_error(st, list, "expected (var_ref )"); return NULL; } @@ -954,19 +874,21 @@ static ir_dereference_array * read_array_ref(_mesa_glsl_parse_state *st, s_list *list) { void *ctx = st; - if (list->length() != 3) { + s_expression *subj_expr; + s_expression *idx_expr; + + s_pattern pat[] = { "array_ref", subj_expr, idx_expr }; + if (!MATCH(list, pat)) { ir_read_error(st, list, "expected (array_ref )"); return NULL; } - s_expression *subj_expr = (s_expression*) list->subexpressions.head->next; ir_rvalue *subject = read_rvalue(st, subj_expr); if (subject == NULL) { ir_read_error(st, NULL, "when reading the subject of an array_ref"); return NULL; } - s_expression *idx_expr = (s_expression*) subj_expr->next; ir_rvalue *idx = read_rvalue(st, idx_expr); return new(ctx) ir_dereference_array(subject, idx); } @@ -975,169 +897,149 @@ static ir_dereference_record * read_record_ref(_mesa_glsl_parse_state *st, s_list *list) { void *ctx = st; - if (list->length() != 3) { + s_expression *subj_expr; + s_symbol *field; + + s_pattern pat[] = { "record_ref", subj_expr, field }; + if (!MATCH(list, pat)) { ir_read_error(st, list, "expected (record_ref )"); return NULL; } - s_expression *subj_expr = (s_expression*) list->subexpressions.head->next; ir_rvalue *subject = read_rvalue(st, subj_expr); if (subject == NULL) { ir_read_error(st, NULL, "when reading the subject of a record_ref"); return NULL; } - - s_symbol *field = SX_AS_SYMBOL(subj_expr->next); - if (field == NULL) { - ir_read_error(st, list, "expected (record_ref ... )"); - return NULL; - } return new(ctx) ir_dereference_record(subject, field->value()); } -static bool -valid_texture_list_length(ir_texture_opcode op, s_list *list) -{ - unsigned required_length = 7; - if (op == ir_txf) - required_length = 5; - else if (op == ir_tex) - required_length = 6; - - return list->length() == required_length; -} - static ir_texture * read_texture(_mesa_glsl_parse_state *st, s_list *list) { - void *ctx = st; - s_symbol *tag = SX_AS_SYMBOL(list->subexpressions.head); - assert(tag != NULL); + s_symbol *tag = NULL; + s_expression *s_sampler = NULL; + s_expression *s_coord = NULL; + s_list *s_offset = NULL; + s_expression *s_proj = NULL; + s_list *s_shadow = NULL; + s_expression *s_lod = NULL; - ir_texture_opcode op = ir_texture::get_opcode(tag->value()); - if (op == (ir_texture_opcode) -1) - return NULL; + ir_texture_opcode op; - if (!valid_texture_list_length(op, list)) { - ir_read_error(st, NULL, "invalid list size in (%s ...)", tag->value()); - return NULL; + s_pattern tex_pattern[] = + { "tex", s_sampler, s_coord, s_offset, s_proj, s_shadow }; + s_pattern txf_pattern[] = + { "txf", s_sampler, s_coord, s_offset, s_lod }; + s_pattern other_pattern[] = + { tag, s_sampler, s_coord, s_offset, s_proj, s_shadow, s_lod }; + + if (MATCH(list, tex_pattern)) { + op = ir_tex; + } else if (MATCH(list, txf_pattern)) { + op = ir_txf; + } else if (MATCH(list, other_pattern)) { + op = ir_texture::get_opcode(tag->value()); + if (op == -1) + return NULL; } - ir_texture *tex = new(ctx) ir_texture(op); + ir_texture *tex = new(st) ir_texture(op); // Read sampler (must be a deref) - s_expression *sampler_expr = (s_expression *) tag->next; - ir_dereference *sampler = read_dereference(st, sampler_expr); + ir_dereference *sampler = read_dereference(st, s_sampler); if (sampler == NULL) { - ir_read_error(st, NULL, "when reading sampler in (%s ...)", tag->value()); + ir_read_error(st, NULL, "when reading sampler in (%s ...)", + tex->opcode_string()); return NULL; } tex->set_sampler(sampler); // Read coordinate (any rvalue) - s_expression *coordinate_expr = (s_expression *) sampler_expr->next; - tex->coordinate = read_rvalue(st, coordinate_expr); + tex->coordinate = read_rvalue(st, s_coord); if (tex->coordinate == NULL) { ir_read_error(st, NULL, "when reading coordinate in (%s ...)", - tag->value()); + tex->opcode_string()); return NULL; } // Read texel offset, i.e. (0 0 0) - s_list *offset_list = SX_AS_LIST(coordinate_expr->next); - if (offset_list == NULL || offset_list->length() != 3) { - ir_read_error(st, offset_list, "expected ( )"); - return NULL; - } - s_int *offset_x = SX_AS_INT(offset_list->subexpressions.head); - s_int *offset_y = SX_AS_INT(offset_list->subexpressions.head->next); - s_int *offset_z = SX_AS_INT(offset_list->subexpressions.head->next->next); - if (offset_x == NULL || offset_y == NULL || offset_z == NULL) { - ir_read_error(st, offset_list, "expected ( )"); + s_int *offset_x; + s_int *offset_y; + s_int *offset_z; + s_pattern offset_pat[] = { offset_x, offset_y, offset_z }; + if (!MATCH(s_offset, offset_pat)) { + ir_read_error(st, s_offset, "expected ( )"); return NULL; } tex->offsets[0] = offset_x->value(); tex->offsets[1] = offset_y->value(); tex->offsets[2] = offset_z->value(); - if (op == ir_txf) { - s_expression *lod_expr = (s_expression *) offset_list->next; - tex->lod_info.lod = read_rvalue(st, lod_expr); - if (tex->lod_info.lod == NULL) { - ir_read_error(st, NULL, "when reading LOD in (txf ...)"); - return NULL; - } - } else { - s_expression *proj_expr = (s_expression *) offset_list->next; - s_int *proj_as_int = SX_AS_INT(proj_expr); + if (op != ir_txf) { + s_int *proj_as_int = SX_AS_INT(s_proj); if (proj_as_int && proj_as_int->value() == 1) { tex->projector = NULL; } else { - tex->projector = read_rvalue(st, proj_expr); + tex->projector = read_rvalue(st, s_proj); if (tex->projector == NULL) { ir_read_error(st, NULL, "when reading projective divide in (%s ..)", - tag->value()); + tex->opcode_string()); return NULL; } } - s_list *shadow_list = SX_AS_LIST(proj_expr->next); - if (shadow_list == NULL) { - ir_read_error(st, NULL, "shadow comparitor must be a list"); - return NULL; - } - if (shadow_list->subexpressions.is_empty()) { - tex->shadow_comparitor= NULL; + if (s_shadow->subexpressions.is_empty()) { + tex->shadow_comparitor = NULL; } else { - tex->shadow_comparitor = read_rvalue(st, shadow_list); + tex->shadow_comparitor = read_rvalue(st, s_shadow); if (tex->shadow_comparitor == NULL) { ir_read_error(st, NULL, "when reading shadow comparitor in (%s ..)", - tag->value()); + tex->opcode_string()); return NULL; } } - s_expression *lod_expr = (s_expression *) shadow_list->next; - - switch (op) { - case ir_txb: - tex->lod_info.bias = read_rvalue(st, lod_expr); - if (tex->lod_info.bias == NULL) { - ir_read_error(st, NULL, "when reading LOD bias in (txb ...)"); - return NULL; - } - break; - case ir_txl: - tex->lod_info.lod = read_rvalue(st, lod_expr); - if (tex->lod_info.lod == NULL) { - ir_read_error(st, NULL, "when reading LOD in (txl ...)"); - return NULL; - } - break; - case ir_txd: { - s_list *lod_list = SX_AS_LIST(lod_expr); - if (lod_list->length() != 2) { - ir_read_error(st, lod_expr, "expected (dPdx dPdy) in (txd ...)"); - return NULL; - } - s_expression *dx_expr = (s_expression *) lod_list->subexpressions.head; - s_expression *dy_expr = (s_expression *) dx_expr->next; - - tex->lod_info.grad.dPdx = read_rvalue(st, dx_expr); - if (tex->lod_info.grad.dPdx == NULL) { - ir_read_error(st, NULL, "when reading dPdx in (txd ...)"); - return NULL; - } - tex->lod_info.grad.dPdy = read_rvalue(st, dy_expr); - if (tex->lod_info.grad.dPdy == NULL) { - ir_read_error(st, NULL, "when reading dPdy in (txd ...)"); - return NULL; - } - break; - } - default: - // tex doesn't have any extra parameters and txf was handled earlier. - break; - }; } + + switch (op) { + case ir_txb: + tex->lod_info.bias = read_rvalue(st, s_lod); + if (tex->lod_info.bias == NULL) { + ir_read_error(st, NULL, "when reading LOD bias in (txb ...)"); + return NULL; + } + break; + case ir_txl: + case ir_txf: + tex->lod_info.lod = read_rvalue(st, s_lod); + if (tex->lod_info.lod == NULL) { + ir_read_error(st, NULL, "when reading LOD in (%s ...)", + tex->opcode_string()); + return NULL; + } + break; + case ir_txd: { + s_expression *s_dx, *s_dy; + s_pattern dxdy_pat[] = { s_dx, s_dy }; + if (!MATCH(s_lod, dxdy_pat)) { + ir_read_error(st, s_lod, "expected (dPdx dPdy) in (txd ...)"); + return NULL; + } + tex->lod_info.grad.dPdx = read_rvalue(st, s_dx); + if (tex->lod_info.grad.dPdx == NULL) { + ir_read_error(st, NULL, "when reading dPdx in (txd ...)"); + return NULL; + } + tex->lod_info.grad.dPdy = read_rvalue(st, s_dy); + if (tex->lod_info.grad.dPdy == NULL) { + ir_read_error(st, NULL, "when reading dPdy in (txd ...)"); + return NULL; + } + break; + } + default: + // tex doesn't have any extra parameters. + break; + }; return tex; } diff --git a/src/glsl/s_expression.cpp b/src/glsl/s_expression.cpp index e420cd6e7ec..a00bfa73ed1 100644 --- a/src/glsl/s_expression.cpp +++ b/src/glsl/s_expression.cpp @@ -139,3 +139,49 @@ void s_list::print() printf(")"); } +// -------------------------------------------------- + +bool +s_pattern::match(s_expression *expr) +{ + switch (type) + { + case EXPR: *p_expr = expr; break; + case LIST: if (expr->is_list()) *p_list = (s_list *) expr; break; + case SYMBOL: if (expr->is_symbol()) *p_symbol = (s_symbol *) expr; break; + case NUMBER: if (expr->is_number()) *p_number = (s_number *) expr; break; + case INT: if (expr->is_int()) *p_int = (s_int *) expr; break; + case STRING: + s_symbol *sym = SX_AS_SYMBOL(expr); + if (sym != NULL && strcmp(sym->value(), literal) == 0) + return true; + return false; + }; + + return *p_expr == expr; +} + +bool +s_match(s_expression *top, unsigned n, s_pattern *pattern, bool partial) +{ + s_list *list = SX_AS_LIST(top); + if (list == NULL) + return false; + + unsigned i = 0; + foreach_iter(exec_list_iterator, it, list->subexpressions) { + if (i >= n) + return partial; /* More actual items than the pattern expected */ + + s_expression *expr = (s_expression *) it.get(); + if (expr == NULL || !pattern[i].match(expr)) + return false; + + i++; + } + + if (i < n) + return false; /* Less actual items than the pattern expected */ + + return true; +} diff --git a/src/glsl/s_expression.h b/src/glsl/s_expression.h index 29d800e394a..c444ba4338d 100644 --- a/src/glsl/s_expression.h +++ b/src/glsl/s_expression.h @@ -26,9 +26,11 @@ #ifndef S_EXPRESSION_H #define S_EXPRESSION_H +#include "main/core.h" /* for Elements */ #include "strtod.h" #include "list.h" +/* Type-safe downcasting macros (also safe to pass NULL) */ #define SX_AS_(t,x) ((x) && ((s_expression*) x)->is_##t()) ? ((s_##t*) (x)) \ : NULL #define SX_AS_LIST(x) SX_AS_(list, x) @@ -36,6 +38,10 @@ #define SX_AS_NUMBER(x) SX_AS_(number, x) #define SX_AS_INT(x) SX_AS_(int, x) +/* Pattern matching macros */ +#define MATCH(list, pat) s_match(list, Elements(pat), pat, false) +#define PARTIAL_MATCH(list, pat) s_match(list, Elements(pat), pat, true) + /* For our purposes, S-Expressions are: * - * - @@ -140,4 +146,36 @@ public: exec_list subexpressions; }; +// ------------------------------------------------------------ + +/** + * Part of a pattern to match - essentially a record holding a pointer to the + * storage for the component to match, along with the appropriate type. + */ +class s_pattern { +public: + s_pattern(s_expression *&s) : p_expr(&s), type(EXPR) { } + s_pattern(s_list *&s) : p_list(&s), type(LIST) { } + s_pattern(s_symbol *&s) : p_symbol(&s), type(SYMBOL) { } + s_pattern(s_number *&s) : p_number(&s), type(NUMBER) { } + s_pattern(s_int *&s) : p_int(&s), type(INT) { } + s_pattern(const char *str) : literal(str), type(STRING) { } + + bool match(s_expression *expr); + +private: + union { + s_expression **p_expr; + s_list **p_list; + s_symbol **p_symbol; + s_number **p_number; + s_int **p_int; + const char *literal; + }; + enum { EXPR, LIST, SYMBOL, NUMBER, INT, STRING } type; +}; + +bool +s_match(s_expression *top, unsigned n, s_pattern *pattern, bool partial); + #endif /* S_EXPRESSION_H */ From d7988152722cd5f3930064a139b567cbcb0e5f53 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Fri, 31 Dec 2010 01:48:02 -0800 Subject: [PATCH 067/164] ir_reader: Remove s_list::length() method. Most code now relies on the pattern matcher rather than this function, and for the only remaining case, not using this saves an iteration. --- src/glsl/ir_reader.cpp | 15 ++++++++------- src/glsl/s_expression.cpp | 10 ---------- src/glsl/s_expression.h | 1 - 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/glsl/ir_reader.cpp b/src/glsl/ir_reader.cpp index 00146d8c15e..98906c4ad73 100644 --- a/src/glsl/ir_reader.cpp +++ b/src/glsl/ir_reader.cpp @@ -754,13 +754,7 @@ read_constant(_mesa_glsl_parse_state *st, s_list *list) } if (type->is_array()) { - const unsigned elements_supplied = values->length(); - if (elements_supplied != type->length) { - ir_read_error(st, values, "expected exactly %u array elements, " - "given %u", type->length, elements_supplied); - return NULL; - } - + unsigned elements_supplied = 0; exec_list elements; foreach_iter(exec_list_iterator, it, values->subexpressions) { s_expression *expr = (s_expression *) it.get(); @@ -774,6 +768,13 @@ read_constant(_mesa_glsl_parse_state *st, s_list *list) if (ir_elt == NULL) return NULL; elements.push_tail(ir_elt); + elements_supplied++; + } + + if (elements_supplied != type->length) { + ir_read_error(st, values, "expected exactly %u array elements, " + "given %u", type->length, elements_supplied); + return NULL; } return new(ctx) ir_constant(type, &elements); } diff --git a/src/glsl/s_expression.cpp b/src/glsl/s_expression.cpp index a00bfa73ed1..852a049d43f 100644 --- a/src/glsl/s_expression.cpp +++ b/src/glsl/s_expression.cpp @@ -38,16 +38,6 @@ s_list::s_list() { } -unsigned -s_list::length() const -{ - unsigned i = 0; - foreach_iter(exec_list_iterator, it, this->subexpressions) { - i++; - } - return i; -} - static s_expression * read_atom(void *ctx, const char *& src) { diff --git a/src/glsl/s_expression.h b/src/glsl/s_expression.h index c444ba4338d..795f3fccea7 100644 --- a/src/glsl/s_expression.h +++ b/src/glsl/s_expression.h @@ -139,7 +139,6 @@ public: s_list(); virtual bool is_list() const { return true; } - unsigned length() const; void print(); From e486fca2d3b430065cbcb27c5d1b545642e11ab5 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Fri, 31 Dec 2010 02:03:21 -0800 Subject: [PATCH 068/164] ir_reader: Relax requirement that function arguments be s_lists. All of these functions used to take s_list pointers so they wouldn't all need SX_AS_LIST conversions and error checking. However, the new pattern matcher conveniently does this for us in one centralized place. So there's no need to insist on s_list. Switching to s_expression saves a bit of code and is somewhat cleaner. --- src/glsl/ir_reader.cpp | 163 ++++++++++++++++++++--------------------- 1 file changed, 78 insertions(+), 85 deletions(-) diff --git a/src/glsl/ir_reader.cpp b/src/glsl/ir_reader.cpp index 98906c4ad73..cfc1ac968b9 100644 --- a/src/glsl/ir_reader.cpp +++ b/src/glsl/ir_reader.cpp @@ -38,7 +38,7 @@ static const glsl_type *read_type(_mesa_glsl_parse_state *, s_expression *); static void scan_for_prototypes(_mesa_glsl_parse_state *, exec_list *, s_expression *); -static ir_function *read_function(_mesa_glsl_parse_state *, s_list *, +static ir_function *read_function(_mesa_glsl_parse_state *, s_expression *, bool skip_body); static void read_function_sig(_mesa_glsl_parse_state *, ir_function *, s_expression *, bool skip_body); @@ -47,27 +47,27 @@ static void read_instructions(_mesa_glsl_parse_state *, exec_list *, s_expression *, ir_loop *); static ir_instruction *read_instruction(_mesa_glsl_parse_state *, s_expression *, ir_loop *); -static ir_variable *read_declaration(_mesa_glsl_parse_state *, s_list *); -static ir_if *read_if(_mesa_glsl_parse_state *, s_list *, ir_loop *); -static ir_loop *read_loop(_mesa_glsl_parse_state *st, s_list *list); -static ir_return *read_return(_mesa_glsl_parse_state *, s_list *); +static ir_variable *read_declaration(_mesa_glsl_parse_state *, s_expression *); +static ir_if *read_if(_mesa_glsl_parse_state *, s_expression *, ir_loop *); +static ir_loop *read_loop(_mesa_glsl_parse_state *st, s_expression *); +static ir_return *read_return(_mesa_glsl_parse_state *, s_expression *); static ir_rvalue *read_rvalue(_mesa_glsl_parse_state *, s_expression *); -static ir_assignment *read_assignment(_mesa_glsl_parse_state *, s_list *); -static ir_expression *read_expression(_mesa_glsl_parse_state *, s_list *); -static ir_call *read_call(_mesa_glsl_parse_state *, s_list *); -static ir_swizzle *read_swizzle(_mesa_glsl_parse_state *, s_list *); -static ir_constant *read_constant(_mesa_glsl_parse_state *, s_list *); -static ir_texture *read_texture(_mesa_glsl_parse_state *, s_list *); +static ir_assignment *read_assignment(_mesa_glsl_parse_state *, s_expression *); +static ir_expression *read_expression(_mesa_glsl_parse_state *, s_expression *); +static ir_call *read_call(_mesa_glsl_parse_state *, s_expression *); +static ir_swizzle *read_swizzle(_mesa_glsl_parse_state *, s_expression *); +static ir_constant *read_constant(_mesa_glsl_parse_state *, s_expression *); +static ir_texture *read_texture(_mesa_glsl_parse_state *, s_expression *); static ir_dereference *read_dereference(_mesa_glsl_parse_state *, s_expression *); static ir_dereference_variable * -read_var_ref(_mesa_glsl_parse_state *, s_list *); +read_var_ref(_mesa_glsl_parse_state *, s_expression *); static ir_dereference_array * -read_array_ref(_mesa_glsl_parse_state *, s_list *); +read_array_ref(_mesa_glsl_parse_state *, s_expression *); static ir_dereference_record * -read_record_ref(_mesa_glsl_parse_state *, s_list *); +read_record_ref(_mesa_glsl_parse_state *, s_expression *); void _mesa_glsl_read_ir(_mesa_glsl_parse_state *state, exec_list *instructions, @@ -177,15 +177,15 @@ scan_for_prototypes(_mesa_glsl_parse_state *st, exec_list *instructions, } static ir_function * -read_function(_mesa_glsl_parse_state *st, s_list *list, bool skip_body) +read_function(_mesa_glsl_parse_state *st, s_expression *expr, bool skip_body) { void *ctx = st; bool added = false; s_symbol *name; s_pattern pat[] = { "function", name }; - if (!PARTIAL_MATCH(list, pat)) { - ir_read_error(st, list, "Expected (function (signature ...) ...)"); + if (!PARTIAL_MATCH(expr, pat)) { + ir_read_error(st, expr, "Expected (function (signature ...) ...)"); return NULL; } @@ -196,7 +196,7 @@ read_function(_mesa_glsl_parse_state *st, s_list *list, bool skip_body) assert(added); } - exec_list_iterator it = list->subexpressions.iterator(); + exec_list_iterator it = ((s_list *) expr)->subexpressions.iterator(); it.next(); // skip "function" tag it.next(); // skip function name for (/* nothing */; it.has_next(); it.next()) { @@ -238,8 +238,7 @@ read_function_sig(_mesa_glsl_parse_state *st, ir_function *f, exec_list_iterator it = paramlist->subexpressions.iterator(); for (it.next() /* skip "parameters" */; it.has_next(); it.next()) { - s_list *decl = SX_AS_LIST(it.get()); - ir_variable *var = read_declaration(st, decl); + ir_variable *var = read_declaration(st, (s_expression *) it.get()); if (var == NULL) return; @@ -364,15 +363,15 @@ read_instruction(_mesa_glsl_parse_state *st, s_expression *expr, } static ir_variable * -read_declaration(_mesa_glsl_parse_state *st, s_list *list) +read_declaration(_mesa_glsl_parse_state *st, s_expression *expr) { s_list *s_quals; s_expression *s_type; s_symbol *s_name; s_pattern pat[] = { "declare", s_quals, s_type, s_name }; - if (!MATCH(list, pat)) { - ir_read_error(st, list, "expected (declare () " + if (!MATCH(expr, pat)) { + ir_read_error(st, expr, "expected (declare () " ")"); return NULL; } @@ -386,7 +385,7 @@ read_declaration(_mesa_glsl_parse_state *st, s_list *list) foreach_iter(exec_list_iterator, it, s_quals->subexpressions) { s_symbol *qualifier = SX_AS_SYMBOL(it.get()); if (qualifier == NULL) { - ir_read_error(st, list, "qualifier list must contain only symbols"); + ir_read_error(st, expr, "qualifier list must contain only symbols"); return NULL; } @@ -412,7 +411,7 @@ read_declaration(_mesa_glsl_parse_state *st, s_list *list) } else if (strcmp(qualifier->value(), "noperspective") == 0) { var->interpolation = ir_var_noperspective; } else { - ir_read_error(st, list, "unknown qualifier: %s", qualifier->value()); + ir_read_error(st, expr, "unknown qualifier: %s", qualifier->value()); return NULL; } } @@ -425,15 +424,15 @@ read_declaration(_mesa_glsl_parse_state *st, s_list *list) static ir_if * -read_if(_mesa_glsl_parse_state *st, s_list *list, ir_loop *loop_ctx) +read_if(_mesa_glsl_parse_state *st, s_expression *expr, ir_loop *loop_ctx) { s_expression *s_cond; s_expression *s_then; s_expression *s_else; s_pattern pat[] = { "if", s_cond, s_then, s_else }; - if (!MATCH(list, pat)) { - ir_read_error(st, list, "expected (if ( ...) " + if (!MATCH(expr, pat)) { + ir_read_error(st, expr, "expected (if ( ...) " "( ...))"); return NULL; } @@ -457,13 +456,13 @@ read_if(_mesa_glsl_parse_state *st, s_list *list, ir_loop *loop_ctx) static ir_loop * -read_loop(_mesa_glsl_parse_state *st, s_list *list) +read_loop(_mesa_glsl_parse_state *st, s_expression *expr) { s_expression *s_counter, *s_from, *s_to, *s_inc, *s_body; s_pattern pat[] = { "loop", s_counter, s_from, s_to, s_inc, s_body }; - if (!MATCH(list, pat)) { - ir_read_error(st, list, "expected (loop " + if (!MATCH(expr, pat)) { + ir_read_error(st, expr, "expected (loop " " )"); return NULL; } @@ -481,17 +480,17 @@ read_loop(_mesa_glsl_parse_state *st, s_list *list) static ir_return * -read_return(_mesa_glsl_parse_state *st, s_list *list) +read_return(_mesa_glsl_parse_state *st, s_expression *expr) { - s_expression *expr; + s_expression *s_retval; - s_pattern pat[] = { "return", expr }; - if (!MATCH(list, pat)) { - ir_read_error(st, list, "expected (return )"); + s_pattern pat[] = { "return", s_retval}; + if (!MATCH(expr, pat)) { + ir_read_error(st, expr, "expected (return )"); return NULL; } - ir_rvalue *retval = read_rvalue(st, expr); + ir_rvalue *retval = read_rvalue(st, s_retval); if (retval == NULL) { ir_read_error(st, NULL, "when reading return value"); return NULL; @@ -535,14 +534,14 @@ read_rvalue(_mesa_glsl_parse_state *st, s_expression *expr) } static ir_assignment * -read_assignment(_mesa_glsl_parse_state *st, s_list *list) +read_assignment(_mesa_glsl_parse_state *st, s_expression *expr) { s_expression *cond_expr, *lhs_expr, *rhs_expr; s_list *mask_list; s_pattern pat[] = { "assign", cond_expr, mask_list, lhs_expr, rhs_expr }; - if (!MATCH(list, pat)) { - ir_read_error(st, list, "expected (assign () " + if (!MATCH(expr, pat)) { + ir_read_error(st, expr, "expected (assign () " " )"); return NULL; } @@ -561,7 +560,7 @@ read_assignment(_mesa_glsl_parse_state *st, s_list *list) const char *mask_str = mask_symbol->value(); unsigned mask_length = strlen(mask_str); if (mask_length > 4) { - ir_read_error(st, list, "invalid write mask: %s", mask_str); + ir_read_error(st, expr, "invalid write mask: %s", mask_str); return NULL; } @@ -569,7 +568,7 @@ read_assignment(_mesa_glsl_parse_state *st, s_list *list) for (unsigned i = 0; i < mask_length; i++) { if (mask_str[i] < 'w' || mask_str[i] > 'z') { - ir_read_error(st, list, "write mask contains invalid character: %c", + ir_read_error(st, expr, "write mask contains invalid character: %c", mask_str[i]); return NULL; } @@ -593,7 +592,7 @@ read_assignment(_mesa_glsl_parse_state *st, s_list *list) } if (mask == 0 && (lhs->type->is_vector() || lhs->type->is_scalar())) { - ir_read_error(st, list, "non-zero write mask required."); + ir_read_error(st, expr, "non-zero write mask required."); return NULL; } @@ -601,15 +600,15 @@ read_assignment(_mesa_glsl_parse_state *st, s_list *list) } static ir_call * -read_call(_mesa_glsl_parse_state *st, s_list *list) +read_call(_mesa_glsl_parse_state *st, s_expression *expr) { void *ctx = st; s_symbol *name; s_list *params; s_pattern pat[] = { "call", name, params }; - if (!MATCH(list, pat)) { - ir_read_error(st, list, "expected (call ( ...))"); + if (!MATCH(expr, pat)) { + ir_read_error(st, expr, "expected (call ( ...))"); return NULL; } @@ -619,7 +618,7 @@ read_call(_mesa_glsl_parse_state *st, s_list *list) s_expression *expr = (s_expression*) it.get(); ir_rvalue *param = read_rvalue(st, expr); if (param == NULL) { - ir_read_error(st, list, "when reading parameter to function call"); + ir_read_error(st, expr, "when reading parameter to function call"); return NULL; } parameters.push_tail(param); @@ -627,14 +626,14 @@ read_call(_mesa_glsl_parse_state *st, s_list *list) ir_function *f = st->symbols->get_function(name->value()); if (f == NULL) { - ir_read_error(st, list, "found call to undefined function %s", + ir_read_error(st, expr, "found call to undefined function %s", name->value()); return NULL; } ir_function_signature *callee = f->matching_signature(¶meters); if (callee == NULL) { - ir_read_error(st, list, "couldn't find matching signature for function " + ir_read_error(st, expr, "couldn't find matching signature for function " "%s", name->value()); return NULL; } @@ -643,7 +642,7 @@ read_call(_mesa_glsl_parse_state *st, s_list *list) } static ir_expression * -read_expression(_mesa_glsl_parse_state *st, s_list *list) +read_expression(_mesa_glsl_parse_state *st, s_expression *expr) { void *ctx = st; s_expression *s_type; @@ -651,8 +650,8 @@ read_expression(_mesa_glsl_parse_state *st, s_list *list) s_expression *s_arg1; s_pattern pat[] = { "expression", s_type, s_op, s_arg1 }; - if (!PARTIAL_MATCH(list, pat)) { - ir_read_error(st, list, "expected (expression " + if (!PARTIAL_MATCH(expr, pat)) { + ir_read_error(st, expr, "expected (expression " " [])"); return NULL; } @@ -665,13 +664,13 @@ read_expression(_mesa_glsl_parse_state *st, s_list *list) /* Read the operator */ ir_expression_operation op = ir_expression::get_operator(s_op->value()); if (op == (ir_expression_operation) -1) { - ir_read_error(st, list, "invalid operator: %s", s_op->value()); + ir_read_error(st, expr, "invalid operator: %s", s_op->value()); return NULL; } unsigned num_operands = ir_expression::get_num_operands(op); if (num_operands == 1 && !s_arg1->next->is_tail_sentinel()) { - ir_read_error(st, list, "expected (expression %s )", + ir_read_error(st, expr, "expected (expression %s )", s_op->value()); return NULL; } @@ -686,7 +685,7 @@ read_expression(_mesa_glsl_parse_state *st, s_list *list) if (num_operands == 2) { if (s_arg2->is_tail_sentinel() || !s_arg2->next->is_tail_sentinel()) { - ir_read_error(st, list, "expected (expression %s " + ir_read_error(st, expr, "expected (expression %s " ")", s_op->value()); return NULL; } @@ -702,19 +701,19 @@ read_expression(_mesa_glsl_parse_state *st, s_list *list) } static ir_swizzle * -read_swizzle(_mesa_glsl_parse_state *st, s_list *list) +read_swizzle(_mesa_glsl_parse_state *st, s_expression *expr) { s_symbol *swiz; s_expression *sub; s_pattern pat[] = { "swiz", swiz, sub }; - if (!MATCH(list, pat)) { - ir_read_error(st, list, "expected (swiz )"); + if (!MATCH(expr, pat)) { + ir_read_error(st, expr, "expected (swiz )"); return NULL; } if (strlen(swiz->value()) > 4) { - ir_read_error(st, list, "expected a valid swizzle; found %s", + ir_read_error(st, expr, "expected a valid swizzle; found %s", swiz->value()); return NULL; } @@ -726,21 +725,21 @@ read_swizzle(_mesa_glsl_parse_state *st, s_list *list) ir_swizzle *ir = ir_swizzle::create(rvalue, swiz->value(), rvalue->type->vector_elements); if (ir == NULL) - ir_read_error(st, list, "invalid swizzle"); + ir_read_error(st, expr, "invalid swizzle"); return ir; } static ir_constant * -read_constant(_mesa_glsl_parse_state *st, s_list *list) +read_constant(_mesa_glsl_parse_state *st, s_expression *expr) { void *ctx = st; s_expression *type_expr; s_list *values; s_pattern pat[] = { "constant", type_expr, values }; - if (!MATCH(list, pat)) { - ir_read_error(st, list, "expected (constant (...))"); + if (!MATCH(expr, pat)) { + ir_read_error(st, expr, "expected (constant (...))"); return NULL; } @@ -749,7 +748,7 @@ read_constant(_mesa_glsl_parse_state *st, s_list *list) return NULL; if (values == NULL) { - ir_read_error(st, list, "expected (constant (...))"); + ir_read_error(st, expr, "expected (constant (...))"); return NULL; } @@ -757,13 +756,7 @@ read_constant(_mesa_glsl_parse_state *st, s_list *list) unsigned elements_supplied = 0; exec_list elements; foreach_iter(exec_list_iterator, it, values->subexpressions) { - s_expression *expr = (s_expression *) it.get(); - s_list *elt = SX_AS_LIST(expr); - if (elt == NULL) { - ir_read_error(st, expr, "expected (constant ...) array element"); - return NULL; - } - + s_expression *elt = (s_expression *) it.get(); ir_constant *ir_elt = read_constant(st, elt); if (ir_elt == NULL) return NULL; @@ -851,20 +844,20 @@ read_dereference(_mesa_glsl_parse_state *st, s_expression *expr) } static ir_dereference_variable * -read_var_ref(_mesa_glsl_parse_state *st, s_list *list) +read_var_ref(_mesa_glsl_parse_state *st, s_expression *expr) { void *ctx = st; s_symbol *var_name; s_pattern pat[] = { "var_ref", var_name }; - if (!MATCH(list, pat)) { - ir_read_error(st, list, "expected (var_ref )"); + if (!MATCH(expr, pat)) { + ir_read_error(st, expr, "expected (var_ref )"); return NULL; } ir_variable *var = st->symbols->get_variable(var_name->value()); if (var == NULL) { - ir_read_error(st, list, "undeclared variable: %s", var_name->value()); + ir_read_error(st, expr, "undeclared variable: %s", var_name->value()); return NULL; } @@ -872,15 +865,15 @@ read_var_ref(_mesa_glsl_parse_state *st, s_list *list) } static ir_dereference_array * -read_array_ref(_mesa_glsl_parse_state *st, s_list *list) +read_array_ref(_mesa_glsl_parse_state *st, s_expression *expr) { void *ctx = st; s_expression *subj_expr; s_expression *idx_expr; s_pattern pat[] = { "array_ref", subj_expr, idx_expr }; - if (!MATCH(list, pat)) { - ir_read_error(st, list, "expected (array_ref )"); + if (!MATCH(expr, pat)) { + ir_read_error(st, expr, "expected (array_ref )"); return NULL; } @@ -895,15 +888,15 @@ read_array_ref(_mesa_glsl_parse_state *st, s_list *list) } static ir_dereference_record * -read_record_ref(_mesa_glsl_parse_state *st, s_list *list) +read_record_ref(_mesa_glsl_parse_state *st, s_expression *expr) { void *ctx = st; s_expression *subj_expr; s_symbol *field; s_pattern pat[] = { "record_ref", subj_expr, field }; - if (!MATCH(list, pat)) { - ir_read_error(st, list, "expected (record_ref )"); + if (!MATCH(expr, pat)) { + ir_read_error(st, expr, "expected (record_ref )"); return NULL; } @@ -916,7 +909,7 @@ read_record_ref(_mesa_glsl_parse_state *st, s_list *list) } static ir_texture * -read_texture(_mesa_glsl_parse_state *st, s_list *list) +read_texture(_mesa_glsl_parse_state *st, s_expression *expr) { s_symbol *tag = NULL; s_expression *s_sampler = NULL; @@ -935,11 +928,11 @@ read_texture(_mesa_glsl_parse_state *st, s_list *list) s_pattern other_pattern[] = { tag, s_sampler, s_coord, s_offset, s_proj, s_shadow, s_lod }; - if (MATCH(list, tex_pattern)) { + if (MATCH(expr, tex_pattern)) { op = ir_tex; - } else if (MATCH(list, txf_pattern)) { + } else if (MATCH(expr, txf_pattern)) { op = ir_txf; - } else if (MATCH(list, other_pattern)) { + } else if (MATCH(expr, other_pattern)) { op = ir_texture::get_opcode(tag->value()); if (op == -1) return NULL; From ec7e4f0ec5c9b718bbfa33a706149030be86d2d9 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Fri, 31 Dec 2010 02:17:58 -0800 Subject: [PATCH 069/164] ir_reader: Combine the three dereference reading functions into one. These used to be more complicated, but now are so simple there's no real point in keeping them separate. --- src/glsl/ir_reader.cpp | 117 ++++++++++++----------------------------- 1 file changed, 35 insertions(+), 82 deletions(-) diff --git a/src/glsl/ir_reader.cpp b/src/glsl/ir_reader.cpp index cfc1ac968b9..b1191a8988e 100644 --- a/src/glsl/ir_reader.cpp +++ b/src/glsl/ir_reader.cpp @@ -62,12 +62,6 @@ static ir_texture *read_texture(_mesa_glsl_parse_state *, s_expression *); static ir_dereference *read_dereference(_mesa_glsl_parse_state *, s_expression *); -static ir_dereference_variable * -read_var_ref(_mesa_glsl_parse_state *, s_expression *); -static ir_dereference_array * -read_array_ref(_mesa_glsl_parse_state *, s_expression *); -static ir_dereference_record * -read_record_ref(_mesa_glsl_parse_state *, s_expression *); void _mesa_glsl_read_ir(_mesa_glsl_parse_state *state, exec_list *instructions, @@ -827,87 +821,46 @@ read_constant(_mesa_glsl_parse_state *st, s_expression *expr) static ir_dereference * read_dereference(_mesa_glsl_parse_state *st, s_expression *expr) { - s_list *list = SX_AS_LIST(expr); - if (list == NULL || list->subexpressions.is_empty()) - return NULL; + s_symbol *s_var; + s_expression *s_subject; + s_expression *s_index; + s_symbol *s_field; - s_symbol *tag = SX_AS_SYMBOL(list->subexpressions.head); - assert(tag != NULL); + s_pattern var_pat[] = { "var_ref", s_var }; + s_pattern array_pat[] = { "array_ref", s_subject, s_index }; + s_pattern record_pat[] = { "record_ref", s_subject, s_field }; - if (strcmp(tag->value(), "var_ref") == 0) - return read_var_ref(st, list); - if (strcmp(tag->value(), "array_ref") == 0) - return read_array_ref(st, list); - if (strcmp(tag->value(), "record_ref") == 0) - return read_record_ref(st, list); + if (MATCH(expr, var_pat)) { + ir_variable *var = st->symbols->get_variable(s_var->value()); + if (var == NULL) { + ir_read_error(st, expr, "undeclared variable: %s", s_var->value()); + return NULL; + } + return new(st) ir_dereference_variable(var); + } else if (MATCH(expr, array_pat)) { + ir_rvalue *subject = read_rvalue(st, s_subject); + if (subject == NULL) { + ir_read_error(st, NULL, "when reading the subject of an array_ref"); + return NULL; + } + + ir_rvalue *idx = read_rvalue(st, s_index); + if (subject == NULL) { + ir_read_error(st, NULL, "when reading the index of an array_ref"); + return NULL; + } + return new(st) ir_dereference_array(subject, idx); + } else if (MATCH(expr, record_pat)) { + ir_rvalue *subject = read_rvalue(st, s_subject); + if (subject == NULL) { + ir_read_error(st, NULL, "when reading the subject of a record_ref"); + return NULL; + } + return new(st) ir_dereference_record(subject, s_field->value()); + } return NULL; } -static ir_dereference_variable * -read_var_ref(_mesa_glsl_parse_state *st, s_expression *expr) -{ - void *ctx = st; - s_symbol *var_name; - - s_pattern pat[] = { "var_ref", var_name }; - if (!MATCH(expr, pat)) { - ir_read_error(st, expr, "expected (var_ref )"); - return NULL; - } - - ir_variable *var = st->symbols->get_variable(var_name->value()); - if (var == NULL) { - ir_read_error(st, expr, "undeclared variable: %s", var_name->value()); - return NULL; - } - - return new(ctx) ir_dereference_variable(var); -} - -static ir_dereference_array * -read_array_ref(_mesa_glsl_parse_state *st, s_expression *expr) -{ - void *ctx = st; - s_expression *subj_expr; - s_expression *idx_expr; - - s_pattern pat[] = { "array_ref", subj_expr, idx_expr }; - if (!MATCH(expr, pat)) { - ir_read_error(st, expr, "expected (array_ref )"); - return NULL; - } - - ir_rvalue *subject = read_rvalue(st, subj_expr); - if (subject == NULL) { - ir_read_error(st, NULL, "when reading the subject of an array_ref"); - return NULL; - } - - ir_rvalue *idx = read_rvalue(st, idx_expr); - return new(ctx) ir_dereference_array(subject, idx); -} - -static ir_dereference_record * -read_record_ref(_mesa_glsl_parse_state *st, s_expression *expr) -{ - void *ctx = st; - s_expression *subj_expr; - s_symbol *field; - - s_pattern pat[] = { "record_ref", subj_expr, field }; - if (!MATCH(expr, pat)) { - ir_read_error(st, expr, "expected (record_ref )"); - return NULL; - } - - ir_rvalue *subject = read_rvalue(st, subj_expr); - if (subject == NULL) { - ir_read_error(st, NULL, "when reading the subject of a record_ref"); - return NULL; - } - return new(ctx) ir_dereference_record(subject, field->value()); -} - static ir_texture * read_texture(_mesa_glsl_parse_state *st, s_expression *expr) { From b74ff382a42bcb81bbf0dc6a85bb38404c46260d Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Sat, 1 Jan 2011 01:17:59 -0800 Subject: [PATCH 070/164] ir_reader: Convert to a class. This makes it unnecessary to pass _mesa_glsl_parse_state around everywhere, making at least the prototypes a lot easier to read. It's also more C++-ish than a pile of static C functions. --- src/glsl/ir_reader.cpp | 471 +++++++++++++++++++++-------------------- 1 file changed, 237 insertions(+), 234 deletions(-) diff --git a/src/glsl/ir_reader.cpp b/src/glsl/ir_reader.cpp index b1191a8988e..11a8cb7ac24 100644 --- a/src/glsl/ir_reader.cpp +++ b/src/glsl/ir_reader.cpp @@ -32,63 +32,78 @@ extern "C" { const static bool debug = false; -static void ir_read_error(_mesa_glsl_parse_state *, s_expression *, - const char *fmt, ...); -static const glsl_type *read_type(_mesa_glsl_parse_state *, s_expression *); +class ir_reader { +public: + ir_reader(_mesa_glsl_parse_state *); -static void scan_for_prototypes(_mesa_glsl_parse_state *, exec_list *, - s_expression *); -static ir_function *read_function(_mesa_glsl_parse_state *, s_expression *, - bool skip_body); -static void read_function_sig(_mesa_glsl_parse_state *, ir_function *, - s_expression *, bool skip_body); + void read(exec_list *instructions, const char *src, bool scan_for_protos); -static void read_instructions(_mesa_glsl_parse_state *, exec_list *, - s_expression *, ir_loop *); -static ir_instruction *read_instruction(_mesa_glsl_parse_state *, - s_expression *, ir_loop *); -static ir_variable *read_declaration(_mesa_glsl_parse_state *, s_expression *); -static ir_if *read_if(_mesa_glsl_parse_state *, s_expression *, ir_loop *); -static ir_loop *read_loop(_mesa_glsl_parse_state *st, s_expression *); -static ir_return *read_return(_mesa_glsl_parse_state *, s_expression *); +private: + void *mem_ctx; + _mesa_glsl_parse_state *state; -static ir_rvalue *read_rvalue(_mesa_glsl_parse_state *, s_expression *); -static ir_assignment *read_assignment(_mesa_glsl_parse_state *, s_expression *); -static ir_expression *read_expression(_mesa_glsl_parse_state *, s_expression *); -static ir_call *read_call(_mesa_glsl_parse_state *, s_expression *); -static ir_swizzle *read_swizzle(_mesa_glsl_parse_state *, s_expression *); -static ir_constant *read_constant(_mesa_glsl_parse_state *, s_expression *); -static ir_texture *read_texture(_mesa_glsl_parse_state *, s_expression *); + void ir_read_error(s_expression *, const char *fmt, ...); -static ir_dereference *read_dereference(_mesa_glsl_parse_state *, - s_expression *); + const glsl_type *read_type(s_expression *); + + void scan_for_prototypes(exec_list *, s_expression *); + ir_function *read_function(s_expression *, bool skip_body); + void read_function_sig(ir_function *, s_expression *, bool skip_body); + + void read_instructions(exec_list *, s_expression *, ir_loop *); + ir_instruction *read_instruction(s_expression *, ir_loop *); + ir_variable *read_declaration(s_expression *); + ir_if *read_if(s_expression *, ir_loop *); + ir_loop *read_loop(s_expression *); + ir_return *read_return(s_expression *); + ir_rvalue *read_rvalue(s_expression *); + ir_assignment *read_assignment(s_expression *); + ir_expression *read_expression(s_expression *); + ir_call *read_call(s_expression *); + ir_swizzle *read_swizzle(s_expression *); + ir_constant *read_constant(s_expression *); + ir_texture *read_texture(s_expression *); + + ir_dereference *read_dereference(s_expression *); +}; + +ir_reader::ir_reader(_mesa_glsl_parse_state *state) : state(state) +{ + this->mem_ctx = state; +} void _mesa_glsl_read_ir(_mesa_glsl_parse_state *state, exec_list *instructions, const char *src, bool scan_for_protos) { - s_expression *expr = s_expression::read_expression(state, src); + ir_reader r(state); + r.read(instructions, src, scan_for_protos); +} + +void +ir_reader::read(exec_list *instructions, const char *src, bool scan_for_protos) +{ + s_expression *expr = s_expression::read_expression(mem_ctx, src); if (expr == NULL) { - ir_read_error(state, NULL, "couldn't parse S-Expression."); + ir_read_error(NULL, "couldn't parse S-Expression."); return; } if (scan_for_protos) { - scan_for_prototypes(state, instructions, expr); + scan_for_prototypes(instructions, expr); if (state->error) return; } - read_instructions(state, instructions, expr, NULL); + read_instructions(instructions, expr, NULL); talloc_free(expr); if (debug) validate_ir_tree(instructions); } -static void -ir_read_error(_mesa_glsl_parse_state *state, s_expression *expr, - const char *fmt, ...) +void +ir_reader::ir_read_error(s_expression *expr, const char *fmt, ...) { va_list ap; @@ -113,17 +128,17 @@ ir_read_error(_mesa_glsl_parse_state *state, s_expression *expr, } } -static const glsl_type * -read_type(_mesa_glsl_parse_state *st, s_expression *expr) +const glsl_type * +ir_reader::read_type(s_expression *expr) { s_expression *s_base_type; s_int *s_size; s_pattern pat[] = { "array", s_base_type, s_size }; if (MATCH(expr, pat)) { - const glsl_type *base_type = read_type(st, s_base_type); + const glsl_type *base_type = read_type(s_base_type); if (base_type == NULL) { - ir_read_error(st, NULL, "when reading base type of array type"); + ir_read_error(NULL, "when reading base type of array type"); return NULL; } @@ -132,25 +147,24 @@ read_type(_mesa_glsl_parse_state *st, s_expression *expr) s_symbol *type_sym = SX_AS_SYMBOL(expr); if (type_sym == NULL) { - ir_read_error(st, expr, "expected "); + ir_read_error(expr, "expected "); return NULL; } - const glsl_type *type = st->symbols->get_type(type_sym->value()); + const glsl_type *type = state->symbols->get_type(type_sym->value()); if (type == NULL) - ir_read_error(st, expr, "invalid type: %s", type_sym->value()); + ir_read_error(expr, "invalid type: %s", type_sym->value()); return type; } -static void -scan_for_prototypes(_mesa_glsl_parse_state *st, exec_list *instructions, - s_expression *expr) +void +ir_reader::scan_for_prototypes(exec_list *instructions, s_expression *expr) { s_list *list = SX_AS_LIST(expr); if (list == NULL) { - ir_read_error(st, expr, "Expected ( ...); found an atom."); + ir_read_error(expr, "Expected ( ...); found an atom."); return; } @@ -163,30 +177,29 @@ scan_for_prototypes(_mesa_glsl_parse_state *st, exec_list *instructions, if (tag == NULL || strcmp(tag->value(), "function") != 0) continue; // not a (function ...); ignore it. - ir_function *f = read_function(st, sub, true); + ir_function *f = read_function(sub, true); if (f == NULL) return; instructions->push_tail(f); } } -static ir_function * -read_function(_mesa_glsl_parse_state *st, s_expression *expr, bool skip_body) +ir_function * +ir_reader::read_function(s_expression *expr, bool skip_body) { - void *ctx = st; bool added = false; s_symbol *name; s_pattern pat[] = { "function", name }; if (!PARTIAL_MATCH(expr, pat)) { - ir_read_error(st, expr, "Expected (function (signature ...) ...)"); + ir_read_error(expr, "Expected (function (signature ...) ...)"); return NULL; } - ir_function *f = st->symbols->get_function(name->value()); + ir_function *f = state->symbols->get_function(name->value()); if (f == NULL) { - f = new(ctx) ir_function(name->value()); - added = st->symbols->add_function(f); + f = new(mem_ctx) ir_function(name->value()); + added = state->symbols->add_function(f); assert(added); } @@ -195,44 +208,42 @@ read_function(_mesa_glsl_parse_state *st, s_expression *expr, bool skip_body) it.next(); // skip function name for (/* nothing */; it.has_next(); it.next()) { s_expression *s_sig = (s_expression *) it.get(); - read_function_sig(st, f, s_sig, skip_body); + read_function_sig(f, s_sig, skip_body); } return added ? f : NULL; } -static void -read_function_sig(_mesa_glsl_parse_state *st, ir_function *f, - s_expression *expr, bool skip_body) +void +ir_reader::read_function_sig(ir_function *f, s_expression *expr, bool skip_body) { - void *ctx = st; s_expression *type_expr; s_list *paramlist; s_list *body_list; s_pattern pat[] = { "signature", type_expr, paramlist, body_list }; if (!MATCH(expr, pat)) { - ir_read_error(st, expr, "Expected (signature (parameters ...) " - "( ...))"); + ir_read_error(expr, "Expected (signature (parameters ...) " + "( ...))"); return; } - const glsl_type *return_type = read_type(st, type_expr); + const glsl_type *return_type = read_type(type_expr); if (return_type == NULL) return; s_symbol *paramtag = SX_AS_SYMBOL(paramlist->subexpressions.get_head()); if (paramtag == NULL || strcmp(paramtag->value(), "parameters") != 0) { - ir_read_error(st, paramlist, "Expected (parameters ...)"); + ir_read_error(paramlist, "Expected (parameters ...)"); return; } // Read the parameters list into a temporary place. exec_list hir_parameters; - st->symbols->push_scope(); + state->symbols->push_scope(); exec_list_iterator it = paramlist->subexpressions.iterator(); for (it.next() /* skip "parameters" */; it.has_next(); it.next()) { - ir_variable *var = read_declaration(st, (s_expression *) it.get()); + ir_variable *var = read_declaration((s_expression *) it.get()); if (var == NULL) return; @@ -242,25 +253,25 @@ read_function_sig(_mesa_glsl_parse_state *st, ir_function *f, ir_function_signature *sig = f->exact_matching_signature(&hir_parameters); if (sig == NULL && skip_body) { /* If scanning for prototypes, generate a new signature. */ - sig = new(ctx) ir_function_signature(return_type); + sig = new(mem_ctx) ir_function_signature(return_type); sig->is_builtin = true; f->add_signature(sig); } else if (sig != NULL) { const char *badvar = sig->qualifiers_match(&hir_parameters); if (badvar != NULL) { - ir_read_error(st, expr, "function `%s' parameter `%s' qualifiers " + ir_read_error(expr, "function `%s' parameter `%s' qualifiers " "don't match prototype", f->name, badvar); return; } if (sig->return_type != return_type) { - ir_read_error(st, expr, "function `%s' return type doesn't " + ir_read_error(expr, "function `%s' return type doesn't " "match prototype", f->name); return; } } else { /* No prototype for this body exists - skip it. */ - st->symbols->pop_scope(); + state->symbols->pop_scope(); return; } assert(sig != NULL); @@ -269,39 +280,39 @@ read_function_sig(_mesa_glsl_parse_state *st, ir_function *f, if (!skip_body && !body_list->subexpressions.is_empty()) { if (sig->is_defined) { - ir_read_error(st, expr, "function %s redefined", f->name); + ir_read_error(expr, "function %s redefined", f->name); return; } - st->current_function = sig; - read_instructions(st, &sig->body, body_list, NULL); - st->current_function = NULL; + state->current_function = sig; + read_instructions(&sig->body, body_list, NULL); + state->current_function = NULL; sig->is_defined = true; } - st->symbols->pop_scope(); + state->symbols->pop_scope(); } -static void -read_instructions(_mesa_glsl_parse_state *st, exec_list *instructions, - s_expression *expr, ir_loop *loop_ctx) +void +ir_reader::read_instructions(exec_list *instructions, s_expression *expr, + ir_loop *loop_ctx) { // Read in a list of instructions s_list *list = SX_AS_LIST(expr); if (list == NULL) { - ir_read_error(st, expr, "Expected ( ...); found an atom."); + ir_read_error(expr, "Expected ( ...); found an atom."); return; } foreach_iter(exec_list_iterator, it, list->subexpressions) { s_expression *sub = (s_expression*) it.get(); - ir_instruction *ir = read_instruction(st, sub, loop_ctx); + ir_instruction *ir = read_instruction(sub, loop_ctx); if (ir != NULL) { /* Global variable declarations should be moved to the top, before * any functions that might use them. Functions are added to the * instruction stream when scanning for prototypes, so without this * hack, they always appear before variable declarations. */ - if (st->current_function == NULL && ir->as_variable() != NULL) + if (state->current_function == NULL && ir->as_variable() != NULL) instructions->push_head(ir); else instructions->push_tail(ir); @@ -310,54 +321,52 @@ read_instructions(_mesa_glsl_parse_state *st, exec_list *instructions, } -static ir_instruction * -read_instruction(_mesa_glsl_parse_state *st, s_expression *expr, - ir_loop *loop_ctx) +ir_instruction * +ir_reader::read_instruction(s_expression *expr, ir_loop *loop_ctx) { - void *ctx = st; s_symbol *symbol = SX_AS_SYMBOL(expr); if (symbol != NULL) { if (strcmp(symbol->value(), "break") == 0 && loop_ctx != NULL) - return new(ctx) ir_loop_jump(ir_loop_jump::jump_break); + return new(mem_ctx) ir_loop_jump(ir_loop_jump::jump_break); if (strcmp(symbol->value(), "continue") == 0 && loop_ctx != NULL) - return new(ctx) ir_loop_jump(ir_loop_jump::jump_continue); + return new(mem_ctx) ir_loop_jump(ir_loop_jump::jump_continue); } s_list *list = SX_AS_LIST(expr); if (list == NULL || list->subexpressions.is_empty()) { - ir_read_error(st, expr, "Invalid instruction.\n"); + ir_read_error(expr, "Invalid instruction.\n"); return NULL; } s_symbol *tag = SX_AS_SYMBOL(list->subexpressions.get_head()); if (tag == NULL) { - ir_read_error(st, expr, "expected instruction tag"); + ir_read_error(expr, "expected instruction tag"); return NULL; } ir_instruction *inst = NULL; if (strcmp(tag->value(), "declare") == 0) { - inst = read_declaration(st, list); + inst = read_declaration(list); } else if (strcmp(tag->value(), "assign") == 0) { - inst = read_assignment(st, list); + inst = read_assignment(list); } else if (strcmp(tag->value(), "if") == 0) { - inst = read_if(st, list, loop_ctx); + inst = read_if(list, loop_ctx); } else if (strcmp(tag->value(), "loop") == 0) { - inst = read_loop(st, list); + inst = read_loop(list); } else if (strcmp(tag->value(), "return") == 0) { - inst = read_return(st, list); + inst = read_return(list); } else if (strcmp(tag->value(), "function") == 0) { - inst = read_function(st, list, false); + inst = read_function(list, false); } else { - inst = read_rvalue(st, list); + inst = read_rvalue(list); if (inst == NULL) - ir_read_error(st, NULL, "when reading instruction"); + ir_read_error(NULL, "when reading instruction"); } return inst; } -static ir_variable * -read_declaration(_mesa_glsl_parse_state *st, s_expression *expr) +ir_variable * +ir_reader::read_declaration(s_expression *expr) { s_list *s_quals; s_expression *s_type; @@ -365,21 +374,21 @@ read_declaration(_mesa_glsl_parse_state *st, s_expression *expr) s_pattern pat[] = { "declare", s_quals, s_type, s_name }; if (!MATCH(expr, pat)) { - ir_read_error(st, expr, "expected (declare () " - ")"); + ir_read_error(expr, "expected (declare () )"); return NULL; } - const glsl_type *type = read_type(st, s_type); + const glsl_type *type = read_type(s_type); if (type == NULL) return NULL; - ir_variable *var = new(st) ir_variable(type, s_name->value(), ir_var_auto); + ir_variable *var = new(mem_ctx) ir_variable(type, s_name->value(), + ir_var_auto); foreach_iter(exec_list_iterator, it, s_quals->subexpressions) { s_symbol *qualifier = SX_AS_SYMBOL(it.get()); if (qualifier == NULL) { - ir_read_error(st, expr, "qualifier list must contain only symbols"); + ir_read_error(expr, "qualifier list must contain only symbols"); return NULL; } @@ -405,20 +414,20 @@ read_declaration(_mesa_glsl_parse_state *st, s_expression *expr) } else if (strcmp(qualifier->value(), "noperspective") == 0) { var->interpolation = ir_var_noperspective; } else { - ir_read_error(st, expr, "unknown qualifier: %s", qualifier->value()); + ir_read_error(expr, "unknown qualifier: %s", qualifier->value()); return NULL; } } // Add the variable to the symbol table - st->symbols->add_variable(var); + state->symbols->add_variable(var); return var; } -static ir_if * -read_if(_mesa_glsl_parse_state *st, s_expression *expr, ir_loop *loop_ctx) +ir_if * +ir_reader::read_if(s_expression *expr, ir_loop *loop_ctx) { s_expression *s_cond; s_expression *s_then; @@ -426,22 +435,21 @@ read_if(_mesa_glsl_parse_state *st, s_expression *expr, ir_loop *loop_ctx) s_pattern pat[] = { "if", s_cond, s_then, s_else }; if (!MATCH(expr, pat)) { - ir_read_error(st, expr, "expected (if ( ...) " - "( ...))"); + ir_read_error(expr, "expected (if (...) (...))"); return NULL; } - ir_rvalue *condition = read_rvalue(st, s_cond); + ir_rvalue *condition = read_rvalue(s_cond); if (condition == NULL) { - ir_read_error(st, NULL, "when reading condition of (if ...)"); + ir_read_error(NULL, "when reading condition of (if ...)"); return NULL; } - ir_if *iff = new(st) ir_if(condition); + ir_if *iff = new(mem_ctx) ir_if(condition); - read_instructions(st, &iff->then_instructions, s_then, loop_ctx); - read_instructions(st, &iff->else_instructions, s_else, loop_ctx); - if (st->error) { + read_instructions(&iff->then_instructions, s_then, loop_ctx); + read_instructions(&iff->else_instructions, s_else, loop_ctx); + if (state->error) { delete iff; iff = NULL; } @@ -449,23 +457,23 @@ read_if(_mesa_glsl_parse_state *st, s_expression *expr, ir_loop *loop_ctx) } -static ir_loop * -read_loop(_mesa_glsl_parse_state *st, s_expression *expr) +ir_loop * +ir_reader::read_loop(s_expression *expr) { s_expression *s_counter, *s_from, *s_to, *s_inc, *s_body; s_pattern pat[] = { "loop", s_counter, s_from, s_to, s_inc, s_body }; if (!MATCH(expr, pat)) { - ir_read_error(st, expr, "expected (loop " - " )"); + ir_read_error(expr, "expected (loop " + " )"); return NULL; } // FINISHME: actually read the count/from/to fields. - ir_loop *loop = new(st) ir_loop; - read_instructions(st, &loop->body_instructions, s_body, loop); - if (st->error) { + ir_loop *loop = new(mem_ctx) ir_loop; + read_instructions(&loop->body_instructions, s_body, loop); + if (state->error) { delete loop; loop = NULL; } @@ -473,29 +481,29 @@ read_loop(_mesa_glsl_parse_state *st, s_expression *expr) } -static ir_return * -read_return(_mesa_glsl_parse_state *st, s_expression *expr) +ir_return * +ir_reader::read_return(s_expression *expr) { s_expression *s_retval; s_pattern pat[] = { "return", s_retval}; if (!MATCH(expr, pat)) { - ir_read_error(st, expr, "expected (return )"); + ir_read_error(expr, "expected (return )"); return NULL; } - ir_rvalue *retval = read_rvalue(st, s_retval); + ir_rvalue *retval = read_rvalue(s_retval); if (retval == NULL) { - ir_read_error(st, NULL, "when reading return value"); + ir_read_error(NULL, "when reading return value"); return NULL; } - return new(st) ir_return(retval); + return new(mem_ctx) ir_return(retval); } -static ir_rvalue * -read_rvalue(_mesa_glsl_parse_state *st, s_expression *expr) +ir_rvalue * +ir_reader::read_rvalue(s_expression *expr) { s_list *list = SX_AS_LIST(expr); if (list == NULL || list->subexpressions.is_empty()) @@ -503,46 +511,46 @@ read_rvalue(_mesa_glsl_parse_state *st, s_expression *expr) s_symbol *tag = SX_AS_SYMBOL(list->subexpressions.get_head()); if (tag == NULL) { - ir_read_error(st, expr, "expected rvalue tag"); + ir_read_error(expr, "expected rvalue tag"); return NULL; } - ir_rvalue *rvalue = read_dereference(st, list); - if (rvalue != NULL || st->error) + ir_rvalue *rvalue = read_dereference(list); + if (rvalue != NULL || state->error) return rvalue; else if (strcmp(tag->value(), "swiz") == 0) { - rvalue = read_swizzle(st, list); + rvalue = read_swizzle(list); } else if (strcmp(tag->value(), "expression") == 0) { - rvalue = read_expression(st, list); + rvalue = read_expression(list); } else if (strcmp(tag->value(), "call") == 0) { - rvalue = read_call(st, list); + rvalue = read_call(list); } else if (strcmp(tag->value(), "constant") == 0) { - rvalue = read_constant(st, list); + rvalue = read_constant(list); } else { - rvalue = read_texture(st, list); - if (rvalue == NULL && !st->error) - ir_read_error(st, expr, "unrecognized rvalue tag: %s", tag->value()); + rvalue = read_texture(list); + if (rvalue == NULL && !state->error) + ir_read_error(expr, "unrecognized rvalue tag: %s", tag->value()); } return rvalue; } -static ir_assignment * -read_assignment(_mesa_glsl_parse_state *st, s_expression *expr) +ir_assignment * +ir_reader::read_assignment(s_expression *expr) { s_expression *cond_expr, *lhs_expr, *rhs_expr; s_list *mask_list; s_pattern pat[] = { "assign", cond_expr, mask_list, lhs_expr, rhs_expr }; if (!MATCH(expr, pat)) { - ir_read_error(st, expr, "expected (assign () " - " )"); + ir_read_error(expr, "expected (assign () " + " )"); return NULL; } - ir_rvalue *condition = read_rvalue(st, cond_expr); + ir_rvalue *condition = read_rvalue(cond_expr); if (condition == NULL) { - ir_read_error(st, NULL, "when reading condition of assignment"); + ir_read_error(NULL, "when reading condition of assignment"); return NULL; } @@ -554,7 +562,7 @@ read_assignment(_mesa_glsl_parse_state *st, s_expression *expr) const char *mask_str = mask_symbol->value(); unsigned mask_length = strlen(mask_str); if (mask_length > 4) { - ir_read_error(st, expr, "invalid write mask: %s", mask_str); + ir_read_error(expr, "invalid write mask: %s", mask_str); return NULL; } @@ -562,47 +570,46 @@ read_assignment(_mesa_glsl_parse_state *st, s_expression *expr) for (unsigned i = 0; i < mask_length; i++) { if (mask_str[i] < 'w' || mask_str[i] > 'z') { - ir_read_error(st, expr, "write mask contains invalid character: %c", + ir_read_error(expr, "write mask contains invalid character: %c", mask_str[i]); return NULL; } mask |= 1 << idx_map[mask_str[i] - 'w']; } } else if (!mask_list->subexpressions.is_empty()) { - ir_read_error(st, mask_list, "expected () or ()"); + ir_read_error(mask_list, "expected () or ()"); return NULL; } - ir_dereference *lhs = read_dereference(st, lhs_expr); + ir_dereference *lhs = read_dereference(lhs_expr); if (lhs == NULL) { - ir_read_error(st, NULL, "when reading left-hand side of assignment"); + ir_read_error(NULL, "when reading left-hand side of assignment"); return NULL; } - ir_rvalue *rhs = read_rvalue(st, rhs_expr); + ir_rvalue *rhs = read_rvalue(rhs_expr); if (rhs == NULL) { - ir_read_error(st, NULL, "when reading right-hand side of assignment"); + ir_read_error(NULL, "when reading right-hand side of assignment"); return NULL; } if (mask == 0 && (lhs->type->is_vector() || lhs->type->is_scalar())) { - ir_read_error(st, expr, "non-zero write mask required."); + ir_read_error(expr, "non-zero write mask required."); return NULL; } - return new(st) ir_assignment(lhs, rhs, condition, mask); + return new(mem_ctx) ir_assignment(lhs, rhs, condition, mask); } -static ir_call * -read_call(_mesa_glsl_parse_state *st, s_expression *expr) +ir_call * +ir_reader::read_call(s_expression *expr) { - void *ctx = st; s_symbol *name; s_list *params; s_pattern pat[] = { "call", name, params }; if (!MATCH(expr, pat)) { - ir_read_error(st, expr, "expected (call ( ...))"); + ir_read_error(expr, "expected (call ( ...))"); return NULL; } @@ -610,139 +617,135 @@ read_call(_mesa_glsl_parse_state *st, s_expression *expr) foreach_iter(exec_list_iterator, it, params->subexpressions) { s_expression *expr = (s_expression*) it.get(); - ir_rvalue *param = read_rvalue(st, expr); + ir_rvalue *param = read_rvalue(expr); if (param == NULL) { - ir_read_error(st, expr, "when reading parameter to function call"); + ir_read_error(expr, "when reading parameter to function call"); return NULL; } parameters.push_tail(param); } - ir_function *f = st->symbols->get_function(name->value()); + ir_function *f = state->symbols->get_function(name->value()); if (f == NULL) { - ir_read_error(st, expr, "found call to undefined function %s", + ir_read_error(expr, "found call to undefined function %s", name->value()); return NULL; } ir_function_signature *callee = f->matching_signature(¶meters); if (callee == NULL) { - ir_read_error(st, expr, "couldn't find matching signature for function " + ir_read_error(expr, "couldn't find matching signature for function " "%s", name->value()); return NULL; } - return new(ctx) ir_call(callee, ¶meters); + return new(mem_ctx) ir_call(callee, ¶meters); } -static ir_expression * -read_expression(_mesa_glsl_parse_state *st, s_expression *expr) +ir_expression * +ir_reader::read_expression(s_expression *expr) { - void *ctx = st; s_expression *s_type; s_symbol *s_op; s_expression *s_arg1; s_pattern pat[] = { "expression", s_type, s_op, s_arg1 }; if (!PARTIAL_MATCH(expr, pat)) { - ir_read_error(st, expr, "expected (expression " - " [])"); + ir_read_error(expr, "expected (expression " + " [])"); return NULL; } s_expression *s_arg2 = (s_expression *) s_arg1->next; // may be tail sentinel - const glsl_type *type = read_type(st, s_type); + const glsl_type *type = read_type(s_type); if (type == NULL) return NULL; /* Read the operator */ ir_expression_operation op = ir_expression::get_operator(s_op->value()); if (op == (ir_expression_operation) -1) { - ir_read_error(st, expr, "invalid operator: %s", s_op->value()); + ir_read_error(expr, "invalid operator: %s", s_op->value()); return NULL; } unsigned num_operands = ir_expression::get_num_operands(op); if (num_operands == 1 && !s_arg1->next->is_tail_sentinel()) { - ir_read_error(st, expr, "expected (expression %s )", + ir_read_error(expr, "expected (expression %s )", s_op->value()); return NULL; } - ir_rvalue *arg1 = read_rvalue(st, s_arg1); + ir_rvalue *arg1 = read_rvalue(s_arg1); ir_rvalue *arg2 = NULL; if (arg1 == NULL) { - ir_read_error(st, NULL, "when reading first operand of %s", - s_op->value()); + ir_read_error(NULL, "when reading first operand of %s", s_op->value()); return NULL; } if (num_operands == 2) { if (s_arg2->is_tail_sentinel() || !s_arg2->next->is_tail_sentinel()) { - ir_read_error(st, expr, "expected (expression %s " - ")", s_op->value()); + ir_read_error(expr, "expected (expression %s " + ")", s_op->value()); return NULL; } - arg2 = read_rvalue(st, s_arg2); + arg2 = read_rvalue(s_arg2); if (arg2 == NULL) { - ir_read_error(st, NULL, "when reading second operand of %s", + ir_read_error(NULL, "when reading second operand of %s", s_op->value()); return NULL; } } - return new(ctx) ir_expression(op, type, arg1, arg2); + return new(mem_ctx) ir_expression(op, type, arg1, arg2); } -static ir_swizzle * -read_swizzle(_mesa_glsl_parse_state *st, s_expression *expr) +ir_swizzle * +ir_reader::read_swizzle(s_expression *expr) { s_symbol *swiz; s_expression *sub; s_pattern pat[] = { "swiz", swiz, sub }; if (!MATCH(expr, pat)) { - ir_read_error(st, expr, "expected (swiz )"); + ir_read_error(expr, "expected (swiz )"); return NULL; } if (strlen(swiz->value()) > 4) { - ir_read_error(st, expr, "expected a valid swizzle; found %s", - swiz->value()); + ir_read_error(expr, "expected a valid swizzle; found %s", swiz->value()); return NULL; } - ir_rvalue *rvalue = read_rvalue(st, sub); + ir_rvalue *rvalue = read_rvalue(sub); if (rvalue == NULL) return NULL; ir_swizzle *ir = ir_swizzle::create(rvalue, swiz->value(), rvalue->type->vector_elements); if (ir == NULL) - ir_read_error(st, expr, "invalid swizzle"); + ir_read_error(expr, "invalid swizzle"); return ir; } -static ir_constant * -read_constant(_mesa_glsl_parse_state *st, s_expression *expr) +ir_constant * +ir_reader::read_constant(s_expression *expr) { - void *ctx = st; s_expression *type_expr; s_list *values; s_pattern pat[] = { "constant", type_expr, values }; if (!MATCH(expr, pat)) { - ir_read_error(st, expr, "expected (constant (...))"); + ir_read_error(expr, "expected (constant (...))"); return NULL; } - const glsl_type *type = read_type(st, type_expr); + const glsl_type *type = read_type(type_expr); if (type == NULL) return NULL; if (values == NULL) { - ir_read_error(st, expr, "expected (constant (...))"); + ir_read_error(expr, "expected (constant (...))"); return NULL; } @@ -751,7 +754,7 @@ read_constant(_mesa_glsl_parse_state *st, s_expression *expr) exec_list elements; foreach_iter(exec_list_iterator, it, values->subexpressions) { s_expression *elt = (s_expression *) it.get(); - ir_constant *ir_elt = read_constant(st, elt); + ir_constant *ir_elt = read_constant(elt); if (ir_elt == NULL) return NULL; elements.push_tail(ir_elt); @@ -759,11 +762,11 @@ read_constant(_mesa_glsl_parse_state *st, s_expression *expr) } if (elements_supplied != type->length) { - ir_read_error(st, values, "expected exactly %u array elements, " + ir_read_error(values, "expected exactly %u array elements, " "given %u", type->length, elements_supplied); return NULL; } - return new(ctx) ir_constant(type, &elements); + return new(mem_ctx) ir_constant(type, &elements); } const glsl_type *const base_type = type->get_base_type(); @@ -774,7 +777,7 @@ read_constant(_mesa_glsl_parse_state *st, s_expression *expr) int k = 0; foreach_iter(exec_list_iterator, it, values->subexpressions) { if (k >= 16) { - ir_read_error(st, values, "expected at most 16 numbers"); + ir_read_error(values, "expected at most 16 numbers"); return NULL; } @@ -783,14 +786,14 @@ read_constant(_mesa_glsl_parse_state *st, s_expression *expr) if (base_type->base_type == GLSL_TYPE_FLOAT) { s_number *value = SX_AS_NUMBER(expr); if (value == NULL) { - ir_read_error(st, values, "expected numbers"); + ir_read_error(values, "expected numbers"); return NULL; } data.f[k] = value->fvalue(); } else { s_int *value = SX_AS_INT(expr); if (value == NULL) { - ir_read_error(st, values, "expected integers"); + ir_read_error(values, "expected integers"); return NULL; } @@ -808,18 +811,18 @@ read_constant(_mesa_glsl_parse_state *st, s_expression *expr) break; } default: - ir_read_error(st, values, "unsupported constant type"); + ir_read_error(values, "unsupported constant type"); return NULL; } } ++k; } - return new(ctx) ir_constant(type, &data); + return new(mem_ctx) ir_constant(type, &data); } -static ir_dereference * -read_dereference(_mesa_glsl_parse_state *st, s_expression *expr) +ir_dereference * +ir_reader::read_dereference(s_expression *expr) { s_symbol *s_var; s_expression *s_subject; @@ -831,38 +834,38 @@ read_dereference(_mesa_glsl_parse_state *st, s_expression *expr) s_pattern record_pat[] = { "record_ref", s_subject, s_field }; if (MATCH(expr, var_pat)) { - ir_variable *var = st->symbols->get_variable(s_var->value()); + ir_variable *var = state->symbols->get_variable(s_var->value()); if (var == NULL) { - ir_read_error(st, expr, "undeclared variable: %s", s_var->value()); + ir_read_error(expr, "undeclared variable: %s", s_var->value()); return NULL; } - return new(st) ir_dereference_variable(var); + return new(mem_ctx) ir_dereference_variable(var); } else if (MATCH(expr, array_pat)) { - ir_rvalue *subject = read_rvalue(st, s_subject); + ir_rvalue *subject = read_rvalue(s_subject); if (subject == NULL) { - ir_read_error(st, NULL, "when reading the subject of an array_ref"); + ir_read_error(NULL, "when reading the subject of an array_ref"); return NULL; } - ir_rvalue *idx = read_rvalue(st, s_index); + ir_rvalue *idx = read_rvalue(s_index); if (subject == NULL) { - ir_read_error(st, NULL, "when reading the index of an array_ref"); + ir_read_error(NULL, "when reading the index of an array_ref"); return NULL; } - return new(st) ir_dereference_array(subject, idx); + return new(mem_ctx) ir_dereference_array(subject, idx); } else if (MATCH(expr, record_pat)) { - ir_rvalue *subject = read_rvalue(st, s_subject); + ir_rvalue *subject = read_rvalue(s_subject); if (subject == NULL) { - ir_read_error(st, NULL, "when reading the subject of a record_ref"); + ir_read_error(NULL, "when reading the subject of a record_ref"); return NULL; } - return new(st) ir_dereference_record(subject, s_field->value()); + return new(mem_ctx) ir_dereference_record(subject, s_field->value()); } return NULL; } -static ir_texture * -read_texture(_mesa_glsl_parse_state *st, s_expression *expr) +ir_texture * +ir_reader::read_texture(s_expression *expr) { s_symbol *tag = NULL; s_expression *s_sampler = NULL; @@ -891,21 +894,21 @@ read_texture(_mesa_glsl_parse_state *st, s_expression *expr) return NULL; } - ir_texture *tex = new(st) ir_texture(op); + ir_texture *tex = new(mem_ctx) ir_texture(op); // Read sampler (must be a deref) - ir_dereference *sampler = read_dereference(st, s_sampler); + ir_dereference *sampler = read_dereference(s_sampler); if (sampler == NULL) { - ir_read_error(st, NULL, "when reading sampler in (%s ...)", + ir_read_error(NULL, "when reading sampler in (%s ...)", tex->opcode_string()); return NULL; } tex->set_sampler(sampler); // Read coordinate (any rvalue) - tex->coordinate = read_rvalue(st, s_coord); + tex->coordinate = read_rvalue(s_coord); if (tex->coordinate == NULL) { - ir_read_error(st, NULL, "when reading coordinate in (%s ...)", + ir_read_error(NULL, "when reading coordinate in (%s ...)", tex->opcode_string()); return NULL; } @@ -916,7 +919,7 @@ read_texture(_mesa_glsl_parse_state *st, s_expression *expr) s_int *offset_z; s_pattern offset_pat[] = { offset_x, offset_y, offset_z }; if (!MATCH(s_offset, offset_pat)) { - ir_read_error(st, s_offset, "expected ( )"); + ir_read_error(s_offset, "expected ( )"); return NULL; } tex->offsets[0] = offset_x->value(); @@ -928,9 +931,9 @@ read_texture(_mesa_glsl_parse_state *st, s_expression *expr) if (proj_as_int && proj_as_int->value() == 1) { tex->projector = NULL; } else { - tex->projector = read_rvalue(st, s_proj); + tex->projector = read_rvalue(s_proj); if (tex->projector == NULL) { - ir_read_error(st, NULL, "when reading projective divide in (%s ..)", + ir_read_error(NULL, "when reading projective divide in (%s ..)", tex->opcode_string()); return NULL; } @@ -939,9 +942,9 @@ read_texture(_mesa_glsl_parse_state *st, s_expression *expr) if (s_shadow->subexpressions.is_empty()) { tex->shadow_comparitor = NULL; } else { - tex->shadow_comparitor = read_rvalue(st, s_shadow); + tex->shadow_comparitor = read_rvalue(s_shadow); if (tex->shadow_comparitor == NULL) { - ir_read_error(st, NULL, "when reading shadow comparitor in (%s ..)", + ir_read_error(NULL, "when reading shadow comparitor in (%s ..)", tex->opcode_string()); return NULL; } @@ -950,17 +953,17 @@ read_texture(_mesa_glsl_parse_state *st, s_expression *expr) switch (op) { case ir_txb: - tex->lod_info.bias = read_rvalue(st, s_lod); + tex->lod_info.bias = read_rvalue(s_lod); if (tex->lod_info.bias == NULL) { - ir_read_error(st, NULL, "when reading LOD bias in (txb ...)"); + ir_read_error(NULL, "when reading LOD bias in (txb ...)"); return NULL; } break; case ir_txl: case ir_txf: - tex->lod_info.lod = read_rvalue(st, s_lod); + tex->lod_info.lod = read_rvalue(s_lod); if (tex->lod_info.lod == NULL) { - ir_read_error(st, NULL, "when reading LOD in (%s ...)", + ir_read_error(NULL, "when reading LOD in (%s ...)", tex->opcode_string()); return NULL; } @@ -969,17 +972,17 @@ read_texture(_mesa_glsl_parse_state *st, s_expression *expr) s_expression *s_dx, *s_dy; s_pattern dxdy_pat[] = { s_dx, s_dy }; if (!MATCH(s_lod, dxdy_pat)) { - ir_read_error(st, s_lod, "expected (dPdx dPdy) in (txd ...)"); + ir_read_error(s_lod, "expected (dPdx dPdy) in (txd ...)"); return NULL; } - tex->lod_info.grad.dPdx = read_rvalue(st, s_dx); + tex->lod_info.grad.dPdx = read_rvalue(s_dx); if (tex->lod_info.grad.dPdx == NULL) { - ir_read_error(st, NULL, "when reading dPdx in (txd ...)"); + ir_read_error(NULL, "when reading dPdx in (txd ...)"); return NULL; } - tex->lod_info.grad.dPdy = read_rvalue(st, s_dy); + tex->lod_info.grad.dPdy = read_rvalue(s_dy); if (tex->lod_info.grad.dPdy == NULL) { - ir_read_error(st, NULL, "when reading dPdy in (txd ...)"); + ir_read_error(NULL, "when reading dPdy in (txd ...)"); return NULL; } break; From bbafd2b849629d3155fe0eef655bbc166a901925 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Sat, 1 Jan 2011 03:37:02 -0800 Subject: [PATCH 071/164] ir_reader: Make assignment conditions optional. You can now simply write (assign (xy) ) instead of the verbose (assign (constant bool (1)) (xy) ). --- src/glsl/ir_print_visitor.cpp | 3 --- src/glsl/ir_reader.cpp | 21 +++++++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/glsl/ir_print_visitor.cpp b/src/glsl/ir_print_visitor.cpp index 0aa0b0a5d32..c56bafd00c5 100644 --- a/src/glsl/ir_print_visitor.cpp +++ b/src/glsl/ir_print_visitor.cpp @@ -281,9 +281,6 @@ void ir_print_visitor::visit(ir_assignment *ir) if (ir->condition) ir->condition->accept(this); - else - printf("(constant bool (1))"); - char mask[5]; unsigned j = 0; diff --git a/src/glsl/ir_reader.cpp b/src/glsl/ir_reader.cpp index 11a8cb7ac24..40901dc6c92 100644 --- a/src/glsl/ir_reader.cpp +++ b/src/glsl/ir_reader.cpp @@ -538,20 +538,25 @@ ir_reader::read_rvalue(s_expression *expr) ir_assignment * ir_reader::read_assignment(s_expression *expr) { - s_expression *cond_expr, *lhs_expr, *rhs_expr; + s_expression *cond_expr = NULL; + s_expression *lhs_expr, *rhs_expr; s_list *mask_list; - s_pattern pat[] = { "assign", cond_expr, mask_list, lhs_expr, rhs_expr }; - if (!MATCH(expr, pat)) { - ir_read_error(expr, "expected (assign () " + s_pattern pat4[] = { "assign", mask_list, lhs_expr, rhs_expr }; + s_pattern pat5[] = { "assign", cond_expr, mask_list, lhs_expr, rhs_expr }; + if (!MATCH(expr, pat4) && !MATCH(expr, pat5)) { + ir_read_error(expr, "expected (assign [] () " " )"); return NULL; } - ir_rvalue *condition = read_rvalue(cond_expr); - if (condition == NULL) { - ir_read_error(NULL, "when reading condition of assignment"); - return NULL; + ir_rvalue *condition = NULL; + if (cond_expr != NULL) { + condition = read_rvalue(cond_expr); + if (condition == NULL) { + ir_read_error(NULL, "when reading condition of assignment"); + return NULL; + } } unsigned mask = 0; From 5bfb68cd0f1d2941645a1fe133ffe1c6a4f5786b Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Sat, 1 Jan 2011 03:43:07 -0800 Subject: [PATCH 072/164] glsl/builtins: Remove unnecessary (constant bool (1)) from assignments. This isn't strictly necessary, but is definitely nicer. --- src/glsl/builtins/ir/atan | 28 ++--- src/glsl/builtins/ir/distance | 6 +- src/glsl/builtins/ir/matrixCompMult | 54 +++++----- src/glsl/builtins/ir/modf | 20 ++-- src/glsl/builtins/ir/noise2 | 32 +++--- src/glsl/builtins/ir/noise3 | 48 ++++----- src/glsl/builtins/ir/noise4 | 72 ++++++------- src/glsl/builtins/ir/outerProduct | 54 +++++----- src/glsl/builtins/ir/refract | 8 +- src/glsl/builtins/ir/smoothstep | 14 +-- src/glsl/builtins/ir/step | 36 +++---- src/glsl/builtins/ir/transpose | 162 ++++++++++++++-------------- 12 files changed, 265 insertions(+), 269 deletions(-) diff --git a/src/glsl/builtins/ir/atan b/src/glsl/builtins/ir/atan index 3f97e0d46f1..cfecc1f1749 100644 --- a/src/glsl/builtins/ir/atan +++ b/src/glsl/builtins/ir/atan @@ -55,19 +55,19 @@ ( (declare () float r) (if (expression bool > (expression float abs (var_ref x)) (constant float (0.000100))) ( - (assign (constant bool (1)) (x) (var_ref r) (call atan ((expression float / (var_ref y) (var_ref x))))) + (assign (x) (var_ref r) (call atan ((expression float / (var_ref y) (var_ref x))))) (if (expression bool < (var_ref x) (constant float (0.000000)) ) ( (if (expression bool >= (var_ref y) (constant float (0.000000)) ) - ((assign (constant bool (1)) (x) (var_ref r) (expression float + (var_ref r) (constant float (3.141593))))) - ((assign (constant bool (1)) (x) (var_ref r) (expression float - (var_ref r) (constant float (3.141593)))))) + ((assign (x) (var_ref r) (expression float + (var_ref r) (constant float (3.141593))))) + ((assign (x) (var_ref r) (expression float - (var_ref r) (constant float (3.141593)))))) ) ( )) ) ( (declare () float sgn) - (assign (constant bool (1)) (x) (var_ref sgn) (expression float sign (var_ref y))) - (assign (constant bool (1)) (x) (var_ref r) (expression float * (var_ref sgn) (constant float (1.5707965)))) + (assign (x) (var_ref sgn) (expression float sign (var_ref y))) + (assign (x) (var_ref r) (expression float * (var_ref sgn) (constant float (1.5707965)))) )) (return (var_ref r) ) @@ -80,10 +80,10 @@ (declare (in) vec2 y) (declare (in) vec2 x)) ((declare () vec2 r) - (assign (constant bool (1)) (x) (var_ref r) + (assign (x) (var_ref r) (call atan ((swiz x (var_ref y)) (swiz x (var_ref x))))) - (assign (constant bool (1)) (y) (var_ref r) + (assign (y) (var_ref r) (call atan ((swiz y (var_ref y)) (swiz y (var_ref x))))) (return (var_ref r)))) @@ -93,13 +93,13 @@ (declare (in) vec3 y) (declare (in) vec3 x)) ((declare () vec3 r) - (assign (constant bool (1)) (x) (var_ref r) + (assign (x) (var_ref r) (call atan ((swiz x (var_ref y)) (swiz x (var_ref x))))) - (assign (constant bool (1)) (y) (var_ref r) + (assign (y) (var_ref r) (call atan ((swiz y (var_ref y)) (swiz y (var_ref x))))) - (assign (constant bool (1)) (z) (var_ref r) + (assign (z) (var_ref r) (call atan ((swiz z (var_ref y)) (swiz z (var_ref x))))) (return (var_ref r)))) @@ -109,16 +109,16 @@ (declare (in) vec4 y) (declare (in) vec4 x)) ((declare () vec4 r) - (assign (constant bool (1)) (x) (var_ref r) + (assign (x) (var_ref r) (call atan ((swiz x (var_ref y)) (swiz x (var_ref x))))) - (assign (constant bool (1)) (y) (var_ref r) + (assign (y) (var_ref r) (call atan ((swiz y (var_ref y)) (swiz y (var_ref x))))) - (assign (constant bool (1)) (z) (var_ref r) + (assign (z) (var_ref r) (call atan ((swiz z (var_ref y)) (swiz z (var_ref x))))) - (assign (constant bool (1)) (w) (var_ref r) + (assign (w) (var_ref r) (call atan ((swiz w (var_ref y)) (swiz w (var_ref x))))) (return (var_ref r))))) diff --git a/src/glsl/builtins/ir/distance b/src/glsl/builtins/ir/distance index 7789ca6314d..c249f8c9962 100644 --- a/src/glsl/builtins/ir/distance +++ b/src/glsl/builtins/ir/distance @@ -10,7 +10,7 @@ (declare (in) vec2 p0) (declare (in) vec2 p1)) ((declare () vec2 p) - (assign (constant bool (1)) (xy) (var_ref p) (expression vec2 - (var_ref p0) (var_ref p1))) + (assign (xy) (var_ref p) (expression vec2 - (var_ref p0) (var_ref p1))) (return (expression float sqrt (expression float dot (var_ref p) (var_ref p)))))) (signature float @@ -18,7 +18,7 @@ (declare (in) vec3 p0) (declare (in) vec3 p1)) ((declare () vec3 p) - (assign (constant bool (1)) (xyz) (var_ref p) (expression vec3 - (var_ref p0) (var_ref p1))) + (assign (xyz) (var_ref p) (expression vec3 - (var_ref p0) (var_ref p1))) (return (expression float sqrt (expression float dot (var_ref p) (var_ref p)))))) (signature float @@ -26,6 +26,6 @@ (declare (in) vec4 p0) (declare (in) vec4 p1)) ((declare () vec4 p) - (assign (constant bool (1)) (xyzw) (var_ref p) (expression vec4 - (var_ref p0) (var_ref p1))) + (assign (xyzw) (var_ref p) (expression vec4 - (var_ref p0) (var_ref p1))) (return (expression float sqrt (expression float dot (var_ref p) (var_ref p)))))) )) diff --git a/src/glsl/builtins/ir/matrixCompMult b/src/glsl/builtins/ir/matrixCompMult index 4be9b03e31e..2400f11afad 100644 --- a/src/glsl/builtins/ir/matrixCompMult +++ b/src/glsl/builtins/ir/matrixCompMult @@ -4,8 +4,8 @@ (declare (in) mat2 x) (declare (in) mat2 y)) ((declare () mat2 z) - (assign (constant bool (1)) (xy) (array_ref (var_ref z) (constant int (0))) (expression vec2 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) - (assign (constant bool (1)) (xy) (array_ref (var_ref z) (constant int (1))) (expression vec2 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) + (assign (xy) (array_ref (var_ref z) (constant int (0))) (expression vec2 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) + (assign (xy) (array_ref (var_ref z) (constant int (1))) (expression vec2 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) (return (var_ref z)))) (signature mat3 @@ -13,9 +13,9 @@ (declare (in) mat3 x) (declare (in) mat3 y)) ((declare () mat3 z) - (assign (constant bool (1)) (xyz) (array_ref (var_ref z) (constant int (0))) (expression vec3 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) - (assign (constant bool (1)) (xyz) (array_ref (var_ref z) (constant int (1))) (expression vec3 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) - (assign (constant bool (1)) (xyz) (array_ref (var_ref z) (constant int (2))) (expression vec3 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2))))) + (assign (xyz) (array_ref (var_ref z) (constant int (0))) (expression vec3 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) + (assign (xyz) (array_ref (var_ref z) (constant int (1))) (expression vec3 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) + (assign (xyz) (array_ref (var_ref z) (constant int (2))) (expression vec3 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2))))) (return (var_ref z)))) (signature mat4 @@ -23,10 +23,10 @@ (declare (in) mat4 x) (declare (in) mat4 y)) ((declare () mat4 z) - (assign (constant bool (1)) (xyzw) (array_ref (var_ref z) (constant int (0))) (expression vec4 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) - (assign (constant bool (1)) (xyzw) (array_ref (var_ref z) (constant int (1))) (expression vec4 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) - (assign (constant bool (1)) (xyzw) (array_ref (var_ref z) (constant int (2))) (expression vec4 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2))))) - (assign (constant bool (1)) (xyzw) (array_ref (var_ref z) (constant int (3))) (expression vec4 * (array_ref (var_ref x) (constant int (3))) (array_ref (var_ref y) (constant int (3))))) + (assign (xyzw) (array_ref (var_ref z) (constant int (0))) (expression vec4 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) + (assign (xyzw) (array_ref (var_ref z) (constant int (1))) (expression vec4 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) + (assign (xyzw) (array_ref (var_ref z) (constant int (2))) (expression vec4 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2))))) + (assign (xyzw) (array_ref (var_ref z) (constant int (3))) (expression vec4 * (array_ref (var_ref x) (constant int (3))) (array_ref (var_ref y) (constant int (3))))) (return (var_ref z)))) (signature mat2x3 @@ -34,8 +34,8 @@ (declare (in) mat2x3 x) (declare (in) mat2x3 y)) ((declare () mat2x3 z) - (assign (constant bool (1)) (xyz) (array_ref (var_ref z) (constant int (0))) (expression vec3 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) - (assign (constant bool (1)) (xyz) (array_ref (var_ref z) (constant int (1))) (expression vec3 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) + (assign (xyz) (array_ref (var_ref z) (constant int (0))) (expression vec3 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) + (assign (xyz) (array_ref (var_ref z) (constant int (1))) (expression vec3 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) (return (var_ref z)))) (signature mat3x2 @@ -43,9 +43,9 @@ (declare (in) mat3x2 x) (declare (in) mat3x2 y)) ((declare () mat3x2 z) - (assign (constant bool (1)) (xy) (array_ref (var_ref z) (constant int (0))) (expression vec2 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) - (assign (constant bool (1)) (xy) (array_ref (var_ref z) (constant int (1))) (expression vec2 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) - (assign (constant bool (1)) (xy) (array_ref (var_ref z) (constant int (2))) (expression vec2 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2))))) + (assign (xy) (array_ref (var_ref z) (constant int (0))) (expression vec2 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) + (assign (xy) (array_ref (var_ref z) (constant int (1))) (expression vec2 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) + (assign (xy) (array_ref (var_ref z) (constant int (2))) (expression vec2 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2))))) (return (var_ref z)))) (signature mat2x4 @@ -53,8 +53,8 @@ (declare (in) mat2x4 x) (declare (in) mat2x4 y)) ((declare () mat2x4 z) - (assign (constant bool (1)) (xyzw) (array_ref (var_ref z) (constant int (0))) (expression vec4 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) - (assign (constant bool (1)) (xyzw) (array_ref (var_ref z) (constant int (1))) (expression vec4 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) + (assign (xyzw) (array_ref (var_ref z) (constant int (0))) (expression vec4 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) + (assign (xyzw) (array_ref (var_ref z) (constant int (1))) (expression vec4 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) (return (var_ref z)))) (signature mat4x2 @@ -62,10 +62,10 @@ (declare (in) mat4x2 x) (declare (in) mat4x2 y)) ((declare () mat4x2 z) - (assign (constant bool (1)) (xy) (array_ref (var_ref z) (constant int (0))) (expression vec2 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) - (assign (constant bool (1)) (xy) (array_ref (var_ref z) (constant int (1))) (expression vec2 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) - (assign (constant bool (1)) (xy) (array_ref (var_ref z) (constant int (2))) (expression vec2 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2))))) - (assign (constant bool (1)) (xy) (array_ref (var_ref z) (constant int (3))) (expression vec2 * (array_ref (var_ref x) (constant int (3))) (array_ref (var_ref y) (constant int (3))))) + (assign (xy) (array_ref (var_ref z) (constant int (0))) (expression vec2 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) + (assign (xy) (array_ref (var_ref z) (constant int (1))) (expression vec2 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) + (assign (xy) (array_ref (var_ref z) (constant int (2))) (expression vec2 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2))))) + (assign (xy) (array_ref (var_ref z) (constant int (3))) (expression vec2 * (array_ref (var_ref x) (constant int (3))) (array_ref (var_ref y) (constant int (3))))) (return (var_ref z)))) (signature mat3x4 @@ -73,9 +73,9 @@ (declare (in) mat3x4 x) (declare (in) mat3x4 y)) ((declare () mat3x4 z) - (assign (constant bool (1)) (xyzw) (array_ref (var_ref z) (constant int (0))) (expression vec4 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) - (assign (constant bool (1)) (xyzw) (array_ref (var_ref z) (constant int (1))) (expression vec4 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) - (assign (constant bool (1)) (xyzw) (array_ref (var_ref z) (constant int (2))) (expression vec4 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2))))) + (assign (xyzw) (array_ref (var_ref z) (constant int (0))) (expression vec4 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) + (assign (xyzw) (array_ref (var_ref z) (constant int (1))) (expression vec4 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) + (assign (xyzw) (array_ref (var_ref z) (constant int (2))) (expression vec4 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2))))) (return (var_ref z)))) (signature mat4x3 @@ -83,9 +83,9 @@ (declare (in) mat4x3 x) (declare (in) mat4x3 y)) ((declare () mat4x3 z) - (assign (constant bool (1)) (xyz) (array_ref (var_ref z) (constant int (0))) (expression vec3 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) - (assign (constant bool (1)) (xyz) (array_ref (var_ref z) (constant int (1))) (expression vec3 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) - (assign (constant bool (1)) (xyz) (array_ref (var_ref z) (constant int (2))) (expression vec3 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2))))) - (assign (constant bool (1)) (xyz) (array_ref (var_ref z) (constant int (3))) (expression vec3 * (array_ref (var_ref x) (constant int (3))) (array_ref (var_ref y) (constant int (3))))) + (assign (xyz) (array_ref (var_ref z) (constant int (0))) (expression vec3 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) + (assign (xyz) (array_ref (var_ref z) (constant int (1))) (expression vec3 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) + (assign (xyz) (array_ref (var_ref z) (constant int (2))) (expression vec3 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2))))) + (assign (xyz) (array_ref (var_ref z) (constant int (3))) (expression vec3 * (array_ref (var_ref x) (constant int (3))) (array_ref (var_ref y) (constant int (3))))) (return (var_ref z)))) )) diff --git a/src/glsl/builtins/ir/modf b/src/glsl/builtins/ir/modf index 2b935a91a7c..f4f631567bd 100644 --- a/src/glsl/builtins/ir/modf +++ b/src/glsl/builtins/ir/modf @@ -4,9 +4,8 @@ (declare (in) float x) (declare (out) float i)) ((declare () float t) - (assign (constant bool (1)) (x) (var_ref t) - (expression float trunc (var_ref x))) - (assign (constant bool (1)) (x) (var_ref i) (var_ref t)) + (assign (x) (var_ref t) (expression float trunc (var_ref x))) + (assign (x) (var_ref i) (var_ref t)) (return (expression float - (var_ref x) (var_ref t))))) (signature vec2 @@ -14,9 +13,8 @@ (declare (in) vec2 x) (declare (out) vec2 i)) ((declare () vec2 t) - (assign (constant bool (1)) (xy) (var_ref t) - (expression vec2 trunc (var_ref x))) - (assign (constant bool (1)) (xy) (var_ref i) (var_ref t)) + (assign (xy) (var_ref t) (expression vec2 trunc (var_ref x))) + (assign (xy) (var_ref i) (var_ref t)) (return (expression vec2 - (var_ref x) (var_ref t))))) (signature vec3 @@ -24,9 +22,8 @@ (declare (in) vec3 x) (declare (out) vec3 i)) ((declare () vec3 t) - (assign (constant bool (1)) (xyz) (var_ref t) - (expression vec3 trunc (var_ref x))) - (assign (constant bool (1)) (xyz) (var_ref i) (var_ref t)) + (assign (xyz) (var_ref t) (expression vec3 trunc (var_ref x))) + (assign (xyz) (var_ref i) (var_ref t)) (return (expression vec3 - (var_ref x) (var_ref t))))) (signature vec4 @@ -34,8 +31,7 @@ (declare (in) vec4 x) (declare (out) vec4 i)) ((declare () vec4 t) - (assign (constant bool (1)) (xyzw) (var_ref t) - (expression vec4 trunc (var_ref x))) - (assign (constant bool (1)) (xyzw) (var_ref i) (var_ref t)) + (assign (xyzw) (var_ref t) (expression vec4 trunc (var_ref x))) + (assign (xyzw) (var_ref i) (var_ref t)) (return (expression vec4 - (var_ref x) (var_ref t))))) )) diff --git a/src/glsl/builtins/ir/noise2 b/src/glsl/builtins/ir/noise2 index 383fccfadfb..d3366145fed 100644 --- a/src/glsl/builtins/ir/noise2 +++ b/src/glsl/builtins/ir/noise2 @@ -6,10 +6,10 @@ (declare () float b) (declare () vec2 t) - (assign (constant bool (1)) (x) (var_ref a) (expression float noise (var_ref p))) - (assign (constant bool (1)) (x) (var_ref b) (expression float noise (expression vec4 + (var_ref p) (constant vec4 (601.0 313.0 29.0 277.0))))) - (assign (constant bool (1)) (x) (var_ref t) (var_ref a)) - (assign (constant bool (1)) (y) (var_ref t) (var_ref b)) + (assign (x) (var_ref a) (expression float noise (var_ref p))) + (assign (x) (var_ref b) (expression float noise (expression vec4 + (var_ref p) (constant vec4 (601.0 313.0 29.0 277.0))))) + (assign (x) (var_ref t) (var_ref a)) + (assign (y) (var_ref t) (var_ref b)) (return (var_ref t)) )) @@ -20,10 +20,10 @@ (declare () float b) (declare () vec2 t) - (assign (constant bool (1)) (x) (var_ref a) (expression float noise (var_ref p))) - (assign (constant bool (1)) (x) (var_ref b) (expression float noise (expression vec3 + (var_ref p) (constant vec3 (601.0 313.0 29.0))))) - (assign (constant bool (1)) (x) (var_ref t) (var_ref a)) - (assign (constant bool (1)) (y) (var_ref t) (var_ref b)) + (assign (x) (var_ref a) (expression float noise (var_ref p))) + (assign (x) (var_ref b) (expression float noise (expression vec3 + (var_ref p) (constant vec3 (601.0 313.0 29.0))))) + (assign (x) (var_ref t) (var_ref a)) + (assign (y) (var_ref t) (var_ref b)) (return (var_ref t)) )) @@ -36,10 +36,10 @@ (declare () float b) (declare () vec2 t) - (assign (constant bool (1)) (x) (var_ref a) (expression float noise (var_ref p))) - (assign (constant bool (1)) (x) (var_ref b) (expression float noise (expression vec2 + (var_ref p) (constant vec2 (601.0 313.0))))) - (assign (constant bool (1)) (x) (var_ref t) (var_ref a)) - (assign (constant bool (1)) (y) (var_ref t) (var_ref b)) + (assign (x) (var_ref a) (expression float noise (var_ref p))) + (assign (x) (var_ref b) (expression float noise (expression vec2 + (var_ref p) (constant vec2 (601.0 313.0))))) + (assign (x) (var_ref t) (var_ref a)) + (assign (y) (var_ref t) (var_ref b)) (return (var_ref t)) )) @@ -52,10 +52,10 @@ (declare () float b) (declare () vec2 t) - (assign (constant bool (1)) (x) (var_ref a) (expression float noise (var_ref p))) - (assign (constant bool (1)) (x) (var_ref b) (expression float noise (expression float + (var_ref p) (constant float (601.0))))) - (assign (constant bool (1)) (x) (var_ref t) (var_ref a)) - (assign (constant bool (1)) (y) (var_ref t) (var_ref b)) + (assign (x) (var_ref a) (expression float noise (var_ref p))) + (assign (x) (var_ref b) (expression float noise (expression float + (var_ref p) (constant float (601.0))))) + (assign (x) (var_ref t) (var_ref a)) + (assign (y) (var_ref t) (var_ref b)) (return (var_ref t)) )) )) diff --git a/src/glsl/builtins/ir/noise3 b/src/glsl/builtins/ir/noise3 index ed7ad5190f2..1d8aa3f30d0 100644 --- a/src/glsl/builtins/ir/noise3 +++ b/src/glsl/builtins/ir/noise3 @@ -7,13 +7,13 @@ (declare () float c) (declare () vec3 t) - (assign (constant bool (1)) (x) (var_ref a) (expression float noise (var_ref p))) - (assign (constant bool (1)) (x) (var_ref b) (expression float noise (expression vec4 + (var_ref p) (constant vec4 (601.0 313.0 29.0 277.0))))) - (assign (constant bool (1)) (x) (var_ref c) (expression float noise (expression vec4 + (var_ref p) (constant vec4 (1559.0 113.0 1861.0 797.0))))) + (assign (x) (var_ref a) (expression float noise (var_ref p))) + (assign (x) (var_ref b) (expression float noise (expression vec4 + (var_ref p) (constant vec4 (601.0 313.0 29.0 277.0))))) + (assign (x) (var_ref c) (expression float noise (expression vec4 + (var_ref p) (constant vec4 (1559.0 113.0 1861.0 797.0))))) - (assign (constant bool (1)) (x) (var_ref t) (var_ref a)) - (assign (constant bool (1)) (y) (var_ref t) (var_ref b)) - (assign (constant bool (1)) (z) (var_ref t) (var_ref c)) + (assign (x) (var_ref t) (var_ref a)) + (assign (y) (var_ref t) (var_ref b)) + (assign (z) (var_ref t) (var_ref c)) (return (var_ref t)) )) @@ -25,13 +25,13 @@ (declare () float c) (declare () vec3 t) - (assign (constant bool (1)) (x) (var_ref a) (expression float noise (var_ref p))) - (assign (constant bool (1)) (x) (var_ref b) (expression float noise (expression vec3 + (var_ref p) (constant vec3 (601.0 313.0 29.0))))) - (assign (constant bool (1)) (x) (var_ref c) (expression float noise (expression vec3 + (var_ref p) (constant vec3 (1559.0 113.0 1861.0))))) + (assign (x) (var_ref a) (expression float noise (var_ref p))) + (assign (x) (var_ref b) (expression float noise (expression vec3 + (var_ref p) (constant vec3 (601.0 313.0 29.0))))) + (assign (x) (var_ref c) (expression float noise (expression vec3 + (var_ref p) (constant vec3 (1559.0 113.0 1861.0))))) - (assign (constant bool (1)) (x) (var_ref t) (var_ref a)) - (assign (constant bool (1)) (y) (var_ref t) (var_ref b)) - (assign (constant bool (1)) (z) (var_ref t) (var_ref c)) + (assign (x) (var_ref t) (var_ref a)) + (assign (y) (var_ref t) (var_ref b)) + (assign (z) (var_ref t) (var_ref c)) (return (var_ref t)) )) @@ -43,13 +43,13 @@ (declare () float c) (declare () vec3 t) - (assign (constant bool (1)) (x) (var_ref a) (expression float noise (var_ref p))) - (assign (constant bool (1)) (x) (var_ref b) (expression float noise (expression vec2 + (var_ref p) (constant vec2 (601.0 313.0))))) - (assign (constant bool (1)) (x) (var_ref c) (expression float noise (expression vec2 + (var_ref p) (constant vec2 (1559.0 113.0))))) + (assign (x) (var_ref a) (expression float noise (var_ref p))) + (assign (x) (var_ref b) (expression float noise (expression vec2 + (var_ref p) (constant vec2 (601.0 313.0))))) + (assign (x) (var_ref c) (expression float noise (expression vec2 + (var_ref p) (constant vec2 (1559.0 113.0))))) - (assign (constant bool (1)) (x) (var_ref t) (var_ref a)) - (assign (constant bool (1)) (y) (var_ref t) (var_ref b)) - (assign (constant bool (1)) (z) (var_ref t) (var_ref c)) + (assign (x) (var_ref t) (var_ref a)) + (assign (y) (var_ref t) (var_ref b)) + (assign (z) (var_ref t) (var_ref c)) (return (var_ref t)) )) @@ -61,13 +61,13 @@ (declare () float c) (declare () vec3 t) - (assign (constant bool (1)) (x) (var_ref a) (expression float noise (var_ref p))) - (assign (constant bool (1)) (x) (var_ref b) (expression float noise (expression float + (var_ref p) (constant float (601.0))))) - (assign (constant bool (1)) (x) (var_ref c) (expression float noise (expression float + (var_ref p) (constant float (1559.0))))) + (assign (x) (var_ref a) (expression float noise (var_ref p))) + (assign (x) (var_ref b) (expression float noise (expression float + (var_ref p) (constant float (601.0))))) + (assign (x) (var_ref c) (expression float noise (expression float + (var_ref p) (constant float (1559.0))))) - (assign (constant bool (1)) (x) (var_ref t) (var_ref a)) - (assign (constant bool (1)) (y) (var_ref t) (var_ref b)) - (assign (constant bool (1)) (z) (var_ref t) (var_ref c)) + (assign (x) (var_ref t) (var_ref a)) + (assign (y) (var_ref t) (var_ref b)) + (assign (z) (var_ref t) (var_ref c)) (return (var_ref t)) )) )) diff --git a/src/glsl/builtins/ir/noise4 b/src/glsl/builtins/ir/noise4 index 77a2529a180..d0894fd5e3e 100644 --- a/src/glsl/builtins/ir/noise4 +++ b/src/glsl/builtins/ir/noise4 @@ -9,17 +9,17 @@ (declare () vec4 _r) (declare () vec4 _p) - (assign (constant bool (1)) (xyzw) (var_ref _p) (expression vec4 + (var_ref p) (constant vec4 (1559.0 113.0 1861.0 797.0))) ) + (assign (xyzw) (var_ref _p) (expression vec4 + (var_ref p) (constant vec4 (1559.0 113.0 1861.0 797.0))) ) - (assign (constant bool (1)) (x) (var_ref _x) (expression float noise(var_ref p))) - (assign (constant bool (1)) (x) (var_ref _y) (expression float noise(expression vec4 + (var_ref p) (constant vec4 (601.0 313.0 29.0 277.0))))) - (assign (constant bool (1)) (x) (var_ref _z) (expression float noise(var_ref _p))) - (assign (constant bool (1)) (x) (var_ref _w) (expression float noise(expression vec4 + (var_ref _p) (constant vec4 (601.0 313.0 29.0 277.0))))) + (assign (x) (var_ref _x) (expression float noise(var_ref p))) + (assign (x) (var_ref _y) (expression float noise(expression vec4 + (var_ref p) (constant vec4 (601.0 313.0 29.0 277.0))))) + (assign (x) (var_ref _z) (expression float noise(var_ref _p))) + (assign (x) (var_ref _w) (expression float noise(expression vec4 + (var_ref _p) (constant vec4 (601.0 313.0 29.0 277.0))))) - (assign (constant bool (1)) (x) (var_ref _r) (var_ref _x)) - (assign (constant bool (1)) (y) (var_ref _r) (var_ref _y)) - (assign (constant bool (1)) (z) (var_ref _r) (var_ref _z)) - (assign (constant bool (1)) (w) (var_ref _r) (var_ref _w)) + (assign (x) (var_ref _r) (var_ref _x)) + (assign (y) (var_ref _r) (var_ref _y)) + (assign (z) (var_ref _r) (var_ref _z)) + (assign (w) (var_ref _r) (var_ref _w)) (return (var_ref _r)) )) @@ -33,17 +33,17 @@ (declare () vec4 _r) (declare () vec3 _p) - (assign (constant bool (1)) (xyz) (var_ref _p) (expression vec3 + (var_ref p) (constant vec3 (1559.0 113.0 1861.0))) ) + (assign (xyz) (var_ref _p) (expression vec3 + (var_ref p) (constant vec3 (1559.0 113.0 1861.0))) ) - (assign (constant bool (1)) (x) (var_ref _x) (expression float noise(var_ref p))) - (assign (constant bool (1)) (x) (var_ref _y) (expression float noise(expression vec3 + (var_ref p) (constant vec3 (601.0 313.0 29.0))))) - (assign (constant bool (1)) (x) (var_ref _z) (expression float noise(var_ref _p))) - (assign (constant bool (1)) (x) (var_ref _w) (expression float noise(expression vec3 + (var_ref _p) (constant vec3 (601.0 313.0 29.0))))) + (assign (x) (var_ref _x) (expression float noise(var_ref p))) + (assign (x) (var_ref _y) (expression float noise(expression vec3 + (var_ref p) (constant vec3 (601.0 313.0 29.0))))) + (assign (x) (var_ref _z) (expression float noise(var_ref _p))) + (assign (x) (var_ref _w) (expression float noise(expression vec3 + (var_ref _p) (constant vec3 (601.0 313.0 29.0))))) - (assign (constant bool (1)) (x) (var_ref _r) (var_ref _x)) - (assign (constant bool (1)) (y) (var_ref _r) (var_ref _y)) - (assign (constant bool (1)) (z) (var_ref _r) (var_ref _z)) - (assign (constant bool (1)) (w) (var_ref _r) (var_ref _w)) + (assign (x) (var_ref _r) (var_ref _x)) + (assign (y) (var_ref _r) (var_ref _y)) + (assign (z) (var_ref _r) (var_ref _z)) + (assign (w) (var_ref _r) (var_ref _w)) (return (var_ref _r)) )) @@ -57,17 +57,17 @@ (declare () vec4 _r) (declare () vec2 _p) - (assign (constant bool (1)) (xy) (var_ref _p) (expression vec2 + (var_ref p) (constant vec2 (1559.0 113.0))) ) + (assign (xy) (var_ref _p) (expression vec2 + (var_ref p) (constant vec2 (1559.0 113.0))) ) - (assign (constant bool (1)) (x) (var_ref _x) (expression float noise(var_ref p))) - (assign (constant bool (1)) (x) (var_ref _y) (expression float noise(expression vec2 + (var_ref p) (constant vec2 (601.0 313.0))))) - (assign (constant bool (1)) (x) (var_ref _z) (expression float noise(var_ref _p))) - (assign (constant bool (1)) (x) (var_ref _w) (expression float noise(expression vec2 + (var_ref _p) (constant vec2 (601.0 313.0))))) + (assign (x) (var_ref _x) (expression float noise(var_ref p))) + (assign (x) (var_ref _y) (expression float noise(expression vec2 + (var_ref p) (constant vec2 (601.0 313.0))))) + (assign (x) (var_ref _z) (expression float noise(var_ref _p))) + (assign (x) (var_ref _w) (expression float noise(expression vec2 + (var_ref _p) (constant vec2 (601.0 313.0))))) - (assign (constant bool (1)) (x) (var_ref _r) (var_ref _x)) - (assign (constant bool (1)) (y) (var_ref _r) (var_ref _y)) - (assign (constant bool (1)) (z) (var_ref _r) (var_ref _z)) - (assign (constant bool (1)) (w) (var_ref _r) (var_ref _w)) + (assign (x) (var_ref _r) (var_ref _x)) + (assign (y) (var_ref _r) (var_ref _y)) + (assign (z) (var_ref _r) (var_ref _z)) + (assign (w) (var_ref _r) (var_ref _w)) (return (var_ref _r)) )) @@ -81,17 +81,17 @@ (declare () vec4 _r) (declare () float _p) - (assign (constant bool (1)) (x) (var_ref _p) (expression float + (var_ref p) (constant float (1559.0))) ) + (assign (x) (var_ref _p) (expression float + (var_ref p) (constant float (1559.0))) ) - (assign (constant bool (1)) (x) (var_ref _x) (expression float noise(var_ref p))) - (assign (constant bool (1)) (x) (var_ref _y) (expression float noise(expression float + (var_ref p) (constant float (601.0 313.0 29.0 277.0))))) - (assign (constant bool (1)) (x) (var_ref _z) (expression float noise(var_ref _p))) - (assign (constant bool (1)) (x) (var_ref _w) (expression float noise(expression float + (var_ref _p) (constant float (601.0 313.0 29.0 277.0))))) + (assign (x) (var_ref _x) (expression float noise(var_ref p))) + (assign (x) (var_ref _y) (expression float noise(expression float + (var_ref p) (constant float (601.0 313.0 29.0 277.0))))) + (assign (x) (var_ref _z) (expression float noise(var_ref _p))) + (assign (x) (var_ref _w) (expression float noise(expression float + (var_ref _p) (constant float (601.0 313.0 29.0 277.0))))) - (assign (constant bool (1)) (x) (var_ref _r) (var_ref _x)) - (assign (constant bool (1)) (y) (var_ref _r) (var_ref _y)) - (assign (constant bool (1)) (z) (var_ref _r) (var_ref _z)) - (assign (constant bool (1)) (w) (var_ref _r) (var_ref _w)) + (assign (x) (var_ref _r) (var_ref _x)) + (assign (y) (var_ref _r) (var_ref _y)) + (assign (z) (var_ref _r) (var_ref _z)) + (assign (w) (var_ref _r) (var_ref _w)) (return (var_ref _r)) )) )) diff --git a/src/glsl/builtins/ir/outerProduct b/src/glsl/builtins/ir/outerProduct index 61d46261548..0e3f375bbac 100644 --- a/src/glsl/builtins/ir/outerProduct +++ b/src/glsl/builtins/ir/outerProduct @@ -4,8 +4,8 @@ (declare (in) vec2 u) (declare (in) vec2 v)) ((declare () mat2 m) - (assign (constant bool (1)) (xy) (array_ref (var_ref m) (constant int (0))) (expression vec2 * (var_ref u) (swiz x (var_ref v)))) - (assign (constant bool (1)) (xy) (array_ref (var_ref m) (constant int (1))) (expression vec2 * (var_ref u) (swiz y (var_ref v)))) + (assign (xy) (array_ref (var_ref m) (constant int (0))) (expression vec2 * (var_ref u) (swiz x (var_ref v)))) + (assign (xy) (array_ref (var_ref m) (constant int (1))) (expression vec2 * (var_ref u) (swiz y (var_ref v)))) (return (var_ref m)))) (signature mat2x3 @@ -13,8 +13,8 @@ (declare (in) vec3 u) (declare (in) vec2 v)) ((declare () mat2x3 m) - (assign (constant bool (1)) (xyz) (array_ref (var_ref m) (constant int (0))) (expression vec3 * (var_ref u) (swiz x (var_ref v)))) - (assign (constant bool (1)) (xyz) (array_ref (var_ref m) (constant int (1))) (expression vec3 * (var_ref u) (swiz y (var_ref v)))) + (assign (xyz) (array_ref (var_ref m) (constant int (0))) (expression vec3 * (var_ref u) (swiz x (var_ref v)))) + (assign (xyz) (array_ref (var_ref m) (constant int (1))) (expression vec3 * (var_ref u) (swiz y (var_ref v)))) (return (var_ref m)))) (signature mat2x4 @@ -22,8 +22,8 @@ (declare (in) vec4 u) (declare (in) vec2 v)) ((declare () mat2x4 m) - (assign (constant bool (1)) (xyzw) (array_ref (var_ref m) (constant int (0))) (expression vec4 * (var_ref u) (swiz x (var_ref v)))) - (assign (constant bool (1)) (xyzw) (array_ref (var_ref m) (constant int (1))) (expression vec4 * (var_ref u) (swiz y (var_ref v)))) + (assign (xyzw) (array_ref (var_ref m) (constant int (0))) (expression vec4 * (var_ref u) (swiz x (var_ref v)))) + (assign (xyzw) (array_ref (var_ref m) (constant int (1))) (expression vec4 * (var_ref u) (swiz y (var_ref v)))) (return (var_ref m)))) (signature mat3x2 @@ -31,9 +31,9 @@ (declare (in) vec2 u) (declare (in) vec3 v)) ((declare () mat3x2 m) - (assign (constant bool (1)) (xy) (array_ref (var_ref m) (constant int (0))) (expression vec2 * (var_ref u) (swiz x (var_ref v)))) - (assign (constant bool (1)) (xy) (array_ref (var_ref m) (constant int (1))) (expression vec2 * (var_ref u) (swiz y (var_ref v)))) - (assign (constant bool (1)) (xy) (array_ref (var_ref m) (constant int (2))) (expression vec2 * (var_ref u) (swiz z (var_ref v)))) + (assign (xy) (array_ref (var_ref m) (constant int (0))) (expression vec2 * (var_ref u) (swiz x (var_ref v)))) + (assign (xy) (array_ref (var_ref m) (constant int (1))) (expression vec2 * (var_ref u) (swiz y (var_ref v)))) + (assign (xy) (array_ref (var_ref m) (constant int (2))) (expression vec2 * (var_ref u) (swiz z (var_ref v)))) (return (var_ref m)) )) @@ -42,9 +42,9 @@ (declare (in) vec3 u) (declare (in) vec3 v)) ((declare () mat3 m) - (assign (constant bool (1)) (xyz) (array_ref (var_ref m) (constant int (0))) (expression vec3 * (var_ref u) (swiz x (var_ref v)))) - (assign (constant bool (1)) (xyz) (array_ref (var_ref m) (constant int (1))) (expression vec3 * (var_ref u) (swiz y (var_ref v)))) - (assign (constant bool (1)) (xyz) (array_ref (var_ref m) (constant int (2))) (expression vec3 * (var_ref u) (swiz z (var_ref v)))) + (assign (xyz) (array_ref (var_ref m) (constant int (0))) (expression vec3 * (var_ref u) (swiz x (var_ref v)))) + (assign (xyz) (array_ref (var_ref m) (constant int (1))) (expression vec3 * (var_ref u) (swiz y (var_ref v)))) + (assign (xyz) (array_ref (var_ref m) (constant int (2))) (expression vec3 * (var_ref u) (swiz z (var_ref v)))) (return (var_ref m)))) (signature mat3x4 @@ -52,9 +52,9 @@ (declare (in) vec4 u) (declare (in) vec3 v)) ((declare () mat3x4 m) - (assign (constant bool (1)) (xyzw) (array_ref (var_ref m) (constant int (0))) (expression vec4 * (var_ref u) (swiz x (var_ref v)))) - (assign (constant bool (1)) (xyzw) (array_ref (var_ref m) (constant int (1))) (expression vec4 * (var_ref u) (swiz y (var_ref v)))) - (assign (constant bool (1)) (xyzw) (array_ref (var_ref m) (constant int (2))) (expression vec4 * (var_ref u) (swiz z (var_ref v)))) + (assign (xyzw) (array_ref (var_ref m) (constant int (0))) (expression vec4 * (var_ref u) (swiz x (var_ref v)))) + (assign (xyzw) (array_ref (var_ref m) (constant int (1))) (expression vec4 * (var_ref u) (swiz y (var_ref v)))) + (assign (xyzw) (array_ref (var_ref m) (constant int (2))) (expression vec4 * (var_ref u) (swiz z (var_ref v)))) (return (var_ref m)))) (signature mat4x2 @@ -62,10 +62,10 @@ (declare (in) vec2 u) (declare (in) vec4 v)) ((declare () mat4x2 m) - (assign (constant bool (1)) (xy) (array_ref (var_ref m) (constant int (0))) (expression vec2 * (var_ref u) (swiz x (var_ref v)))) - (assign (constant bool (1)) (xy) (array_ref (var_ref m) (constant int (1))) (expression vec2 * (var_ref u) (swiz y (var_ref v)))) - (assign (constant bool (1)) (xy) (array_ref (var_ref m) (constant int (2))) (expression vec2 * (var_ref u) (swiz z (var_ref v)))) - (assign (constant bool (1)) (xy) (array_ref (var_ref m) (constant int (3))) (expression vec2 * (var_ref u) (swiz w (var_ref v)))) + (assign (xy) (array_ref (var_ref m) (constant int (0))) (expression vec2 * (var_ref u) (swiz x (var_ref v)))) + (assign (xy) (array_ref (var_ref m) (constant int (1))) (expression vec2 * (var_ref u) (swiz y (var_ref v)))) + (assign (xy) (array_ref (var_ref m) (constant int (2))) (expression vec2 * (var_ref u) (swiz z (var_ref v)))) + (assign (xy) (array_ref (var_ref m) (constant int (3))) (expression vec2 * (var_ref u) (swiz w (var_ref v)))) (return (var_ref m)))) (signature mat4x3 @@ -73,10 +73,10 @@ (declare (in) vec3 u) (declare (in) vec4 v)) ((declare () mat4x3 m) - (assign (constant bool (1)) (xyz) (array_ref (var_ref m) (constant int (0))) (expression vec3 * (var_ref u) (swiz x (var_ref v)))) - (assign (constant bool (1)) (xyz) (array_ref (var_ref m) (constant int (1))) (expression vec3 * (var_ref u) (swiz y (var_ref v)))) - (assign (constant bool (1)) (xyz) (array_ref (var_ref m) (constant int (2))) (expression vec3 * (var_ref u) (swiz z (var_ref v)))) - (assign (constant bool (1)) (xyz) (array_ref (var_ref m) (constant int (3))) (expression vec3 * (var_ref u) (swiz w (var_ref v)))) + (assign (xyz) (array_ref (var_ref m) (constant int (0))) (expression vec3 * (var_ref u) (swiz x (var_ref v)))) + (assign (xyz) (array_ref (var_ref m) (constant int (1))) (expression vec3 * (var_ref u) (swiz y (var_ref v)))) + (assign (xyz) (array_ref (var_ref m) (constant int (2))) (expression vec3 * (var_ref u) (swiz z (var_ref v)))) + (assign (xyz) (array_ref (var_ref m) (constant int (3))) (expression vec3 * (var_ref u) (swiz w (var_ref v)))) (return (var_ref m)))) (signature mat4 @@ -84,9 +84,9 @@ (declare (in) vec4 u) (declare (in) vec4 v)) ((declare () mat4 m) - (assign (constant bool (1)) (xyzw) (array_ref (var_ref m) (constant int (0))) (expression vec4 * (var_ref u) (swiz x (var_ref v)))) - (assign (constant bool (1)) (xyzw) (array_ref (var_ref m) (constant int (1))) (expression vec4 * (var_ref u) (swiz y (var_ref v)))) - (assign (constant bool (1)) (xyzw) (array_ref (var_ref m) (constant int (2))) (expression vec4 * (var_ref u) (swiz z (var_ref v)))) - (assign (constant bool (1)) (xyzw) (array_ref (var_ref m) (constant int (3))) (expression vec4 * (var_ref u) (swiz w (var_ref v)))) + (assign (xyzw) (array_ref (var_ref m) (constant int (0))) (expression vec4 * (var_ref u) (swiz x (var_ref v)))) + (assign (xyzw) (array_ref (var_ref m) (constant int (1))) (expression vec4 * (var_ref u) (swiz y (var_ref v)))) + (assign (xyzw) (array_ref (var_ref m) (constant int (2))) (expression vec4 * (var_ref u) (swiz z (var_ref v)))) + (assign (xyzw) (array_ref (var_ref m) (constant int (3))) (expression vec4 * (var_ref u) (swiz w (var_ref v)))) (return (var_ref m)))) )) diff --git a/src/glsl/builtins/ir/refract b/src/glsl/builtins/ir/refract index f6319b0ed47..60899f01cec 100644 --- a/src/glsl/builtins/ir/refract +++ b/src/glsl/builtins/ir/refract @@ -5,7 +5,7 @@ (declare (in) float n) (declare (in) float eta)) ((declare () float k) - (assign (constant bool (1)) (x) (var_ref k) + (assign (x) (var_ref k) (expression float - (constant float (1.0)) (expression float * (var_ref eta) (expression float * (var_ref eta) @@ -30,7 +30,7 @@ (declare (in) vec2 n) (declare (in) float eta)) ((declare () float k) - (assign (constant bool (1)) (x) (var_ref k) + (assign (x) (var_ref k) (expression float - (constant float (1.0)) (expression float * (var_ref eta) (expression float * (var_ref eta) @@ -55,7 +55,7 @@ (declare (in) vec3 n) (declare (in) float eta)) ((declare () float k) - (assign (constant bool (1)) (x) (var_ref k) + (assign (x) (var_ref k) (expression float - (constant float (1.0)) (expression float * (var_ref eta) (expression float * (var_ref eta) @@ -80,7 +80,7 @@ (declare (in) vec4 n) (declare (in) float eta)) ((declare () float k) - (assign (constant bool (1)) (x) (var_ref k) + (assign (x) (var_ref k) (expression float - (constant float (1.0)) (expression float * (var_ref eta) (expression float * (var_ref eta) diff --git a/src/glsl/builtins/ir/smoothstep b/src/glsl/builtins/ir/smoothstep index b283f73d8d3..94c98b29e53 100644 --- a/src/glsl/builtins/ir/smoothstep +++ b/src/glsl/builtins/ir/smoothstep @@ -5,7 +5,7 @@ (declare (in) float edge1) (declare (in) float x)) ((declare () float t) - (assign (constant bool (1)) (x) (var_ref t) + (assign (x) (var_ref t) (expression float max (expression float min (expression float / (expression float - (var_ref x) (var_ref edge0)) (expression float - (var_ref edge1) (var_ref edge0))) @@ -18,7 +18,7 @@ (declare (in) float edge1) (declare (in) vec2 x)) ((declare () vec2 t) - (assign (constant bool (1)) (xy) (var_ref t) + (assign (xy) (var_ref t) (expression vec2 max (expression vec2 min (expression vec2 / (expression vec2 - (var_ref x) (var_ref edge0)) (expression float - (var_ref edge1) (var_ref edge0))) @@ -32,7 +32,7 @@ (declare (in) float edge1) (declare (in) vec3 x)) ((declare () vec3 t) - (assign (constant bool (1)) (xyz) (var_ref t) + (assign (xyz) (var_ref t) (expression vec3 max (expression vec3 min (expression vec3 / (expression vec3 - (var_ref x) (var_ref edge0)) (expression float - (var_ref edge1) (var_ref edge0))) @@ -47,7 +47,7 @@ (declare (in) float edge1) (declare (in) vec4 x)) ((declare () vec4 t) - (assign (constant bool (1)) (xyzw) (var_ref t) + (assign (xyzw) (var_ref t) (expression vec4 max (expression vec4 min (expression vec4 / (expression vec4 - (var_ref x) (var_ref edge0)) (expression float - (var_ref edge1) (var_ref edge0))) @@ -61,7 +61,7 @@ (declare (in) vec2 edge1) (declare (in) vec2 x)) ((declare () vec2 t) - (assign (constant bool (1)) (xy) (var_ref t) + (assign (xy) (var_ref t) (expression vec2 max (expression vec2 min (expression vec2 / (expression vec2 - (var_ref x) (var_ref edge0)) (expression vec2 - (var_ref edge1) (var_ref edge0))) @@ -75,7 +75,7 @@ (declare (in) vec3 edge1) (declare (in) vec3 x)) ((declare () vec3 t) - (assign (constant bool (1)) (xyz) (var_ref t) + (assign (xyz) (var_ref t) (expression vec3 max (expression vec3 min (expression vec3 / (expression vec3 - (var_ref x) (var_ref edge0)) (expression vec3 - (var_ref edge1) (var_ref edge0))) @@ -89,7 +89,7 @@ (declare (in) vec4 edge1) (declare (in) vec4 x)) ((declare () vec4 t) - (assign (constant bool (1)) (xyzw) (var_ref t) + (assign (xyzw) (var_ref t) (expression vec4 max (expression vec4 min (expression vec4 / (expression vec4 - (var_ref x) (var_ref edge0)) (expression vec4 - (var_ref edge1) (var_ref edge0))) diff --git a/src/glsl/builtins/ir/step b/src/glsl/builtins/ir/step index 7aec9d7a6cc..efcd7bc8023 100644 --- a/src/glsl/builtins/ir/step +++ b/src/glsl/builtins/ir/step @@ -10,8 +10,8 @@ (declare (in) float edge) (declare (in) vec2 x)) ((declare () vec2 t) - (assign (constant bool (1)) (x) (var_ref t) (expression float b2f (expression bool >= (swiz x (var_ref x))(var_ref edge)))) - (assign (constant bool (1)) (y) (var_ref t) (expression float b2f (expression bool >= (swiz y (var_ref x))(var_ref edge)))) + (assign (x) (var_ref t) (expression float b2f (expression bool >= (swiz x (var_ref x))(var_ref edge)))) + (assign (y) (var_ref t) (expression float b2f (expression bool >= (swiz y (var_ref x))(var_ref edge)))) (return (var_ref t)))) (signature vec3 @@ -19,9 +19,9 @@ (declare (in) float edge) (declare (in) vec3 x)) ((declare () vec3 t) - (assign (constant bool (1)) (x) (var_ref t) (expression float b2f (expression bool >= (swiz x (var_ref x))(var_ref edge)))) - (assign (constant bool (1)) (y) (var_ref t) (expression float b2f (expression bool >= (swiz y (var_ref x))(var_ref edge)))) - (assign (constant bool (1)) (z) (var_ref t) (expression float b2f (expression bool >= (swiz z (var_ref x))(var_ref edge)))) + (assign (x) (var_ref t) (expression float b2f (expression bool >= (swiz x (var_ref x))(var_ref edge)))) + (assign (y) (var_ref t) (expression float b2f (expression bool >= (swiz y (var_ref x))(var_ref edge)))) + (assign (z) (var_ref t) (expression float b2f (expression bool >= (swiz z (var_ref x))(var_ref edge)))) (return (var_ref t)))) (signature vec4 @@ -29,10 +29,10 @@ (declare (in) float edge) (declare (in) vec4 x)) ((declare () vec4 t) - (assign (constant bool (1)) (x) (var_ref t) (expression float b2f (expression bool >= (swiz x (var_ref x))(var_ref edge)))) - (assign (constant bool (1)) (y) (var_ref t) (expression float b2f (expression bool >= (swiz y (var_ref x))(var_ref edge)))) - (assign (constant bool (1)) (z) (var_ref t) (expression float b2f (expression bool >= (swiz z (var_ref x))(var_ref edge)))) - (assign (constant bool (1)) (w) (var_ref t) (expression float b2f (expression bool >= (swiz w (var_ref x))(var_ref edge)))) + (assign (x) (var_ref t) (expression float b2f (expression bool >= (swiz x (var_ref x))(var_ref edge)))) + (assign (y) (var_ref t) (expression float b2f (expression bool >= (swiz y (var_ref x))(var_ref edge)))) + (assign (z) (var_ref t) (expression float b2f (expression bool >= (swiz z (var_ref x))(var_ref edge)))) + (assign (w) (var_ref t) (expression float b2f (expression bool >= (swiz w (var_ref x))(var_ref edge)))) (return (var_ref t)))) (signature vec2 @@ -40,8 +40,8 @@ (declare (in) vec2 edge) (declare (in) vec2 x)) ((declare () vec2 t) - (assign (constant bool (1)) (x) (var_ref t) (expression float b2f (expression bool >= (swiz x (var_ref x))(swiz x (var_ref edge))))) - (assign (constant bool (1)) (y) (var_ref t) (expression float b2f (expression bool >= (swiz y (var_ref x))(swiz y (var_ref edge))))) + (assign (x) (var_ref t) (expression float b2f (expression bool >= (swiz x (var_ref x))(swiz x (var_ref edge))))) + (assign (y) (var_ref t) (expression float b2f (expression bool >= (swiz y (var_ref x))(swiz y (var_ref edge))))) (return (var_ref t)))) (signature vec3 @@ -49,9 +49,9 @@ (declare (in) vec3 edge) (declare (in) vec3 x)) ((declare () vec3 t) - (assign (constant bool (1)) (x) (var_ref t) (expression float b2f (expression bool >= (swiz x (var_ref x))(swiz x (var_ref edge))))) - (assign (constant bool (1)) (y) (var_ref t) (expression float b2f (expression bool >= (swiz y (var_ref x))(swiz y (var_ref edge))))) - (assign (constant bool (1)) (z) (var_ref t) (expression float b2f (expression bool >= (swiz z (var_ref x))(swiz z (var_ref edge))))) + (assign (x) (var_ref t) (expression float b2f (expression bool >= (swiz x (var_ref x))(swiz x (var_ref edge))))) + (assign (y) (var_ref t) (expression float b2f (expression bool >= (swiz y (var_ref x))(swiz y (var_ref edge))))) + (assign (z) (var_ref t) (expression float b2f (expression bool >= (swiz z (var_ref x))(swiz z (var_ref edge))))) (return (var_ref t)))) (signature vec4 @@ -59,10 +59,10 @@ (declare (in) vec4 edge) (declare (in) vec4 x)) ((declare () vec4 t) - (assign (constant bool (1)) (x) (var_ref t) (expression float b2f (expression bool >= (swiz x (var_ref x))(swiz x (var_ref edge))))) - (assign (constant bool (1)) (y) (var_ref t) (expression float b2f (expression bool >= (swiz y (var_ref x))(swiz y (var_ref edge))))) - (assign (constant bool (1)) (z) (var_ref t) (expression float b2f (expression bool >= (swiz z (var_ref x))(swiz z (var_ref edge))))) - (assign (constant bool (1)) (w) (var_ref t) (expression float b2f (expression bool >= (swiz w (var_ref x))(swiz w (var_ref edge))))) + (assign (x) (var_ref t) (expression float b2f (expression bool >= (swiz x (var_ref x))(swiz x (var_ref edge))))) + (assign (y) (var_ref t) (expression float b2f (expression bool >= (swiz y (var_ref x))(swiz y (var_ref edge))))) + (assign (z) (var_ref t) (expression float b2f (expression bool >= (swiz z (var_ref x))(swiz z (var_ref edge))))) + (assign (w) (var_ref t) (expression float b2f (expression bool >= (swiz w (var_ref x))(swiz w (var_ref edge))))) (return (var_ref t)))) )) diff --git a/src/glsl/builtins/ir/transpose b/src/glsl/builtins/ir/transpose index 4bed4489bf4..043327d235b 100644 --- a/src/glsl/builtins/ir/transpose +++ b/src/glsl/builtins/ir/transpose @@ -3,135 +3,135 @@ (parameters (declare (in) mat2 m)) ((declare () mat2 t) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1))))) + (assign (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0))))) + (assign (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0))))) + (assign (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1))))) + (assign (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1))))) (return (var_ref t)))) (signature mat3x2 (parameters (declare (in) mat2x3 m)) ((declare () mat3x2 t) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (1))))) + (assign (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0))))) + (assign (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0))))) + (assign (x) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (0))))) + (assign (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1))))) + (assign (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1))))) + (assign (y) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (1))))) (return (var_ref t)))) (signature mat4x2 (parameters (declare (in) mat2x4 m)) ((declare () mat4x2 t) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (1))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (1))))) + (assign (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0))))) + (assign (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0))))) + (assign (x) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (0))))) + (assign (x) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (0))))) + (assign (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1))))) + (assign (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1))))) + (assign (y) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (1))))) + (assign (y) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (1))))) (return (var_ref t)))) (signature mat2x3 (parameters (declare (in) mat3x2 m)) ((declare () mat2x3 t) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1))))) - (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (2))))) - (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (2))))) + (assign (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0))))) + (assign (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0))))) + (assign (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1))))) + (assign (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1))))) + (assign (z) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (2))))) + (assign (z) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (2))))) (return (var_ref t)))) (signature mat3 (parameters (declare (in) mat3 m)) ((declare () mat3 t) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (1))))) - (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (2))))) - (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (2))))) - (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (2))))) + (assign (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0))))) + (assign (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0))))) + (assign (x) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (0))))) + (assign (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1))))) + (assign (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1))))) + (assign (y) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (1))))) + (assign (z) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (2))))) + (assign (z) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (2))))) + (assign (z) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (2))))) (return (var_ref t)))) (signature mat4x3 (parameters (declare (in) mat3x4 m)) ((declare () mat4x3 t) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (1))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (1))))) - (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (2))))) - (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (2))))) - (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (2))))) - (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (2))))) + (assign (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0))))) + (assign (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0))))) + (assign (x) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (0))))) + (assign (x) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (0))))) + (assign (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1))))) + (assign (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1))))) + (assign (y) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (1))))) + (assign (y) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (1))))) + (assign (z) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (2))))) + (assign (z) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (2))))) + (assign (z) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (2))))) + (assign (z) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (2))))) (return (var_ref t)))) (signature mat2x4 (parameters (declare (in) mat4x2 m)) ((declare () mat2x4 t) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1))))) - (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (2))))) - (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (2))))) - (assign (constant bool (1)) (w) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (3))))) - (assign (constant bool (1)) (w) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (3))))) + (assign (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0))))) + (assign (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0))))) + (assign (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1))))) + (assign (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1))))) + (assign (z) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (2))))) + (assign (z) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (2))))) + (assign (w) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (3))))) + (assign (w) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (3))))) (return (var_ref t)))) (signature mat3x4 (parameters (declare (in) mat4x3 m)) ((declare () mat3x4 t) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (1))))) - (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (2))))) - (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (2))))) - (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (2))))) - (assign (constant bool (1)) (w) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (3))))) - (assign (constant bool (1)) (w) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (3))))) - (assign (constant bool (1)) (w) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (3))))) + (assign (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0))))) + (assign (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0))))) + (assign (x) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (0))))) + (assign (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1))))) + (assign (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1))))) + (assign (y) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (1))))) + (assign (z) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (2))))) + (assign (z) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (2))))) + (assign (z) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (2))))) + (assign (w) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (3))))) + (assign (w) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (3))))) + (assign (w) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (3))))) (return (var_ref t)))) (signature mat4 (parameters (declare (in) mat4 m)) ((declare () mat4 t) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (0))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (1))))) - (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (1))))) - (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (2))))) - (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (2))))) - (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (2))))) - (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (2))))) - (assign (constant bool (1)) (w) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (3))))) - (assign (constant bool (1)) (w) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (3))))) - (assign (constant bool (1)) (w) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (3))))) - (assign (constant bool (1)) (w) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (3))))) + (assign (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0))))) + (assign (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0))))) + (assign (x) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (0))))) + (assign (x) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (0))))) + (assign (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1))))) + (assign (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1))))) + (assign (y) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (1))))) + (assign (y) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (1))))) + (assign (z) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (2))))) + (assign (z) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (2))))) + (assign (z) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (2))))) + (assign (z) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (2))))) + (assign (w) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (3))))) + (assign (w) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (3))))) + (assign (w) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (3))))) + (assign (w) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (3))))) (return (var_ref t)))) ) From 47b2af2c62fec3ac0fb501a31e93fc8d00c18cb8 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Sat, 1 Jan 2011 12:43:03 -0800 Subject: [PATCH 073/164] glsl/s_expression: Read and ignore Scheme-style comments. A single-semicolon until the end of the line, i.e. ; this is a comment. --- src/glsl/s_expression.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/glsl/s_expression.cpp b/src/glsl/s_expression.cpp index 852a049d43f..6edbf62e488 100644 --- a/src/glsl/s_expression.cpp +++ b/src/glsl/s_expression.cpp @@ -38,15 +38,25 @@ s_list::s_list() { } +static void +skip_whitespace(const char *& src) +{ + src += strspn(src, " \v\t\r\n"); + /* Also skip Scheme-style comments: semi-colon 'til end of line */ + if (src[0] == ';') { + src += strcspn(src, "\n"); + skip_whitespace(src); + } +} + static s_expression * read_atom(void *ctx, const char *& src) { s_expression *expr = NULL; - // Skip leading spaces. - src += strspn(src, " \v\t\r\n"); + skip_whitespace(src); - size_t n = strcspn(src, "( \v\t\r\n)"); + size_t n = strcspn(src, "( \v\t\r\n);"); if (n == 0) return NULL; // no atom @@ -80,8 +90,7 @@ s_expression::read_expression(void *ctx, const char *&src) if (atom != NULL) return atom; - // Skip leading spaces. - src += strspn(src, " \v\t\r\n"); + skip_whitespace(src); if (src[0] == '(') { ++src; @@ -91,7 +100,7 @@ s_expression::read_expression(void *ctx, const char *&src) while ((expr = read_expression(ctx, src)) != NULL) { list->subexpressions.push_tail(expr); } - src += strspn(src, " \v\t\r\n"); + skip_whitespace(src); if (src[0] != ')') { printf("Unclosed expression (check your parenthesis).\n"); return NULL; From a4a38dcf61f141297a083ccac217200947d57b0d Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 13 Jan 2011 16:53:13 +0800 Subject: [PATCH 074/164] egl: Cleanup _EGLDisplay initialization. Reorder/rename and document the fields that should be set by the driver during initialization. Drop the major/minor arguments from drv->API.Initialize. --- src/egl/drivers/dri2/egl_dri2.c | 33 +++++++++---------- src/egl/drivers/glx/egl_glx.c | 9 +++-- src/egl/main/eglapi.c | 9 ++--- src/egl/main/eglapi.h | 2 +- src/egl/main/egldisplay.h | 28 ++++++++-------- src/egl/main/egldriver.c | 8 ++--- src/egl/main/eglmisc.c | 31 +++++++++-------- src/egl/main/eglstring.h | 1 + .../state_trackers/egl/common/egl_g3d.c | 17 +++++----- 9 files changed, 66 insertions(+), 72 deletions(-) diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index 458d18f4da5..f6bca4abf72 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -260,8 +260,8 @@ dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id, base.BindToTextureRGBA = bind_to_texture_rgba; } - base.RenderableType = disp->ClientAPIsMask; - base.Conformant = disp->ClientAPIsMask; + base.RenderableType = disp->ClientAPIs; + base.Conformant = disp->ClientAPIs; if (!_eglValidateConfig(&base, EGL_FALSE)) { _eglLog(_EGL_DEBUG, "DRI2: failed to validate config %d", id); @@ -752,13 +752,13 @@ dri2_create_screen(_EGLDisplay *disp) else api_mask = 1 << __DRI_API_OPENGL; - disp->ClientAPIsMask = 0; + disp->ClientAPIs = 0; if (api_mask & (1 <<__DRI_API_OPENGL)) - disp->ClientAPIsMask |= EGL_OPENGL_BIT; + disp->ClientAPIs |= EGL_OPENGL_BIT; if (api_mask & (1 <<__DRI_API_GLES)) - disp->ClientAPIsMask |= EGL_OPENGL_ES_BIT; + disp->ClientAPIs |= EGL_OPENGL_ES_BIT; if (api_mask & (1 << __DRI_API_GLES2)) - disp->ClientAPIsMask |= EGL_OPENGL_ES2_BIT; + disp->ClientAPIs |= EGL_OPENGL_ES2_BIT; if (dri2_dpy->dri2->base.version >= 2) { disp->Extensions.KHR_surfaceless_gles1 = EGL_TRUE; @@ -775,8 +775,7 @@ dri2_create_screen(_EGLDisplay *disp) } static EGLBoolean -dri2_initialize_x11(_EGLDriver *drv, _EGLDisplay *disp, - EGLint *major, EGLint *minor) +dri2_initialize_x11(_EGLDriver *drv, _EGLDisplay *disp) { struct dri2_egl_display *dri2_dpy; @@ -855,8 +854,8 @@ dri2_initialize_x11(_EGLDriver *drv, _EGLDisplay *disp, disp->Extensions.NOK_texture_from_pixmap = EGL_TRUE; /* we're supporting EGL 1.4 */ - *major = 1; - *minor = 4; + disp->VersionMajor = 1; + disp->VersionMinor = 4; return EGL_TRUE; @@ -1415,8 +1414,7 @@ dri2_get_driver_for_fd(int fd) } static EGLBoolean -dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp, - EGLint *major, EGLint *minor) +dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp) { struct dri2_egl_display *dri2_dpy; int i; @@ -1451,8 +1449,8 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp, disp->Extensions.KHR_gl_texture_2D_image = EGL_TRUE; /* we're supporting EGL 1.4 */ - *major = 1; - *minor = 4; + disp->VersionMajor = 1; + disp->VersionMinor = 4; return EGL_TRUE; @@ -1470,16 +1468,15 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp, * Called via eglInitialize(), GLX_drv->API.Initialize(). */ static EGLBoolean -dri2_initialize(_EGLDriver *drv, _EGLDisplay *disp, - EGLint *major, EGLint *minor) +dri2_initialize(_EGLDriver *drv, _EGLDisplay *disp) { switch (disp->Platform) { case _EGL_PLATFORM_X11: - return dri2_initialize_x11(drv, disp, major, minor); + return dri2_initialize_x11(drv, disp); #ifdef HAVE_LIBUDEV case _EGL_PLATFORM_DRM: - return dri2_initialize_drm(drv, disp, major, minor); + return dri2_initialize_drm(drv, disp); #endif default: diff --git a/src/egl/drivers/glx/egl_glx.c b/src/egl/drivers/glx/egl_glx.c index 5fce06d66df..84b04f7967e 100644 --- a/src/egl/drivers/glx/egl_glx.c +++ b/src/egl/drivers/glx/egl_glx.c @@ -581,8 +581,7 @@ check_quirks(struct GLX_egl_driver *GLX_drv, * Called via eglInitialize(), GLX_drv->API.Initialize(). */ static EGLBoolean -GLX_eglInitialize(_EGLDriver *drv, _EGLDisplay *disp, - EGLint *major, EGLint *minor) +GLX_eglInitialize(_EGLDriver *drv, _EGLDisplay *disp) { struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv); struct GLX_egl_display *GLX_dpy; @@ -614,7 +613,7 @@ GLX_eglInitialize(_EGLDriver *drv, _EGLDisplay *disp, } disp->DriverData = (void *) GLX_dpy; - disp->ClientAPIsMask = EGL_OPENGL_BIT; + disp->ClientAPIs = EGL_OPENGL_BIT; check_extensions(GLX_drv, GLX_dpy, DefaultScreen(GLX_dpy->dpy)); check_quirks(GLX_drv, GLX_dpy, DefaultScreen(GLX_dpy->dpy)); @@ -629,8 +628,8 @@ GLX_eglInitialize(_EGLDriver *drv, _EGLDisplay *disp, } /* we're supporting EGL 1.4 */ - *major = 1; - *minor = 4; + disp->VersionMajor = 1; + disp->VersionMinor = 4; return EGL_TRUE; } diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index efa9e97346b..4e64ce6f718 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -57,7 +57,6 @@ #include #include -#include "eglstring.h" #include "eglcontext.h" #include "egldisplay.h" #include "egltypedefs.h" @@ -294,16 +293,14 @@ eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) if (!_eglMatchDriver(disp, EGL_FALSE)) RETURN_EGL_ERROR(disp, EGL_NOT_INITIALIZED, EGL_FALSE); - _eglsnprintf(disp->Version, sizeof(disp->Version), "%d.%d (%s)", - disp->APImajor, disp->APIminor, disp->Driver->Name); /* limit to APIs supported by core */ - disp->ClientAPIsMask &= _EGL_API_ALL_BITS; + disp->ClientAPIs &= _EGL_API_ALL_BITS; } /* Update applications version of major and minor if not NULL */ if ((major != NULL) && (minor != NULL)) { - *major = disp->APImajor; - *minor = disp->APIminor; + *major = disp->VersionMajor; + *minor = disp->VersionMinor; } RETURN_EGL_SUCCESS(disp, EGL_TRUE); diff --git a/src/egl/main/eglapi.h b/src/egl/main/eglapi.h index 127becc9acd..01492082f66 100644 --- a/src/egl/main/eglapi.h +++ b/src/egl/main/eglapi.h @@ -12,7 +12,7 @@ typedef void (*_EGLProc)(void); */ /* driver funcs */ -typedef EGLBoolean (*Initialize_t)(_EGLDriver *, _EGLDisplay *dpy, EGLint *major, EGLint *minor); +typedef EGLBoolean (*Initialize_t)(_EGLDriver *, _EGLDisplay *dpy); typedef EGLBoolean (*Terminate_t)(_EGLDriver *, _EGLDisplay *dpy); /* config funcs */ diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index bcba05480a8..faeb2906478 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -74,8 +74,6 @@ struct _egl_extensions EGLBoolean NOK_swap_region; EGLBoolean NOK_texture_from_pixmap; - - char String[_EGL_MAX_EXTENSIONS_LEN]; }; @@ -86,21 +84,23 @@ struct _egl_display _EGLMutex Mutex; - _EGLPlatformType Platform; - void *PlatformDisplay; + _EGLPlatformType Platform; /**< The type of the platform display */ + void *PlatformDisplay; /**< A pointer to the platform display */ - EGLBoolean Initialized; /**< True if the display is initialized */ - _EGLDriver *Driver; - void *DriverData; /* private to driver */ + _EGLDriver *Driver; /**< Matched driver of the display */ + EGLBoolean Initialized; /**< True if the display is initialized */ - int APImajor, APIminor; /**< as returned by eglInitialize() */ - char Version[1000]; /**< initialized from APImajor/minor, DriverName */ + /* these fields are set by the driver during init */ + void *DriverData; /**< Driver private data */ + EGLint VersionMajor; /**< EGL major version */ + EGLint VersionMinor; /**< EGL minor version */ + EGLint ClientAPIs; /**< Bitmask of APIs supported (EGL_xxx_BIT) */ + _EGLExtensions Extensions; /**< Extensions supported */ - /** Bitmask of supported APIs (EGL_xx_BIT) set by the driver during init */ - EGLint ClientAPIsMask; - char ClientAPIs[1000]; /**< updated by eglQueryString */ - - _EGLExtensions Extensions; + /* these fields are derived from above */ + char VersionString[1000]; /**< EGL_VERSION */ + char ClientAPIsString[1000]; /**< EGL_CLIENT_APIS */ + char ExtensionsString[_EGL_MAX_EXTENSIONS_LEN]; /**< EGL_EXTENSIONS */ _EGLArray *Screens; _EGLArray *Configs; diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c index 0f2e40abf57..1ae030db448 100644 --- a/src/egl/main/egldriver.c +++ b/src/egl/main/egldriver.c @@ -537,7 +537,7 @@ _eglMatchDriver(_EGLDisplay *dpy, EGLBoolean use_probe) _EGLModule *mod; _EGLDriver *best_drv = NULL; EGLint best_score = 0; - EGLint major, minor, i; + EGLint i; _eglLockMutex(&_eglModuleMutex); @@ -562,7 +562,7 @@ _eglMatchDriver(_EGLDisplay *dpy, EGLBoolean use_probe) } } else { - if (mod->Driver->API.Initialize(mod->Driver, dpy, &major, &minor)) { + if (mod->Driver->API.Initialize(mod->Driver, dpy)) { best_drv = mod->Driver; best_score = 100; } @@ -591,7 +591,7 @@ _eglMatchDriver(_EGLDisplay *dpy, EGLBoolean use_probe) mod->Driver->Probe(mod->Driver, dpy) : 1; } else { - if (mod->Driver->API.Initialize(mod->Driver, dpy, &major, &minor)) + if (mod->Driver->API.Initialize(mod->Driver, dpy)) best_score = 100; } @@ -621,8 +621,6 @@ _eglMatchDriver(_EGLDisplay *dpy, EGLBoolean use_probe) if (!use_probe) { dpy->Driver = best_drv; dpy->Initialized = EGL_TRUE; - dpy->APImajor = major; - dpy->APIminor = minor; } } diff --git a/src/egl/main/eglmisc.c b/src/egl/main/eglmisc.c index bbb96a908e4..5a607dc080a 100644 --- a/src/egl/main/eglmisc.c +++ b/src/egl/main/eglmisc.c @@ -36,6 +36,8 @@ #include "eglcurrent.h" #include "eglmisc.h" #include "egldisplay.h" +#include "egldriver.h" +#include "eglstring.h" /** @@ -73,11 +75,11 @@ _eglUpdateExtensionsString(_EGLDisplay *dpy) do { \ if (dpy->Extensions.ext) { \ _eglAppendExtension(&exts, "EGL_" #ext); \ - assert(exts <= dpy->Extensions.String + _EGL_MAX_EXTENSIONS_LEN); \ + assert(exts <= dpy->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \ } \ } while (0) - char *exts = dpy->Extensions.String; + char *exts = dpy->ExtensionsString; if (exts[0]) return; @@ -114,21 +116,21 @@ _eglUpdateExtensionsString(_EGLDisplay *dpy) static void _eglUpdateAPIsString(_EGLDisplay *dpy) { - char *apis = dpy->ClientAPIs; + char *apis = dpy->ClientAPIsString; - if (apis[0] || !dpy->ClientAPIsMask) + if (apis[0] || !dpy->ClientAPIs) return; - if (dpy->ClientAPIsMask & EGL_OPENGL_BIT) + if (dpy->ClientAPIs & EGL_OPENGL_BIT) strcat(apis, "OpenGL "); - if (dpy->ClientAPIsMask & EGL_OPENGL_ES_BIT) + if (dpy->ClientAPIs & EGL_OPENGL_ES_BIT) strcat(apis, "OpenGL_ES "); - if (dpy->ClientAPIsMask & EGL_OPENGL_ES2_BIT) + if (dpy->ClientAPIs & EGL_OPENGL_ES2_BIT) strcat(apis, "OpenGL_ES2 "); - if (dpy->ClientAPIsMask & EGL_OPENVG_BIT) + if (dpy->ClientAPIs & EGL_OPENVG_BIT) strcat(apis, "OpenVG "); assert(strlen(apis) < sizeof(dpy->ClientAPIs)); @@ -139,20 +141,21 @@ const char * _eglQueryString(_EGLDriver *drv, _EGLDisplay *dpy, EGLint name) { (void) drv; - (void) dpy; + switch (name) { case EGL_VENDOR: return _EGL_VENDOR_STRING; case EGL_VERSION: - return dpy->Version; + _eglsnprintf(dpy->VersionString, sizeof(dpy->VersionString), + "%d.%d (%s)", dpy->VersionMajor, dpy->VersionMajor, + dpy->Driver->Name); + return dpy->VersionString; case EGL_EXTENSIONS: _eglUpdateExtensionsString(dpy); - return dpy->Extensions.String; -#ifdef EGL_VERSION_1_2 + return dpy->ExtensionsString; case EGL_CLIENT_APIS: _eglUpdateAPIsString(dpy); - return dpy->ClientAPIs; -#endif + return dpy->ClientAPIsString; default: _eglError(EGL_BAD_PARAMETER, "eglQueryString"); return NULL; diff --git a/src/egl/main/eglstring.h b/src/egl/main/eglstring.h index f1d559b24a2..8a8c43c1eff 100644 --- a/src/egl/main/eglstring.h +++ b/src/egl/main/eglstring.h @@ -4,6 +4,7 @@ #include #ifdef _EGL_OS_WINDOWS +#include #define _eglstrcasecmp _stricmp #define _eglsnprintf _snprintf #else diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.c b/src/gallium/state_trackers/egl/common/egl_g3d.c index f2b137a674a..90354705172 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d.c +++ b/src/gallium/state_trackers/egl/common/egl_g3d.c @@ -280,7 +280,7 @@ egl_g3d_init_config(_EGLDriver *drv, _EGLDisplay *dpy, ST_ATTACHMENT_BACK_LEFT : ST_ATTACHMENT_FRONT_LEFT; valid = init_config_attributes(&gconf->base, - nconf, dpy->ClientAPIsMask, depth_stencil_format, + nconf, dpy->ClientAPIs, depth_stencil_format, preserve_buffer, max_swap_interval); if (!valid) { _eglLog(_EGL_DEBUG, "skip invalid config 0x%x", nconf->native_visual_id); @@ -474,8 +474,7 @@ egl_g3d_terminate(_EGLDriver *drv, _EGLDisplay *dpy) } static EGLBoolean -egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy, - EGLint *major, EGLint *minor) +egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy) { struct egl_g3d_driver *gdrv = egl_g3d_driver(drv); struct egl_g3d_display *gdpy; @@ -502,13 +501,13 @@ egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy, } if (gdpy->loader->profile_masks[ST_API_OPENGL] & ST_PROFILE_DEFAULT_MASK) - dpy->ClientAPIsMask |= EGL_OPENGL_BIT; + dpy->ClientAPIs |= EGL_OPENGL_BIT; if (gdpy->loader->profile_masks[ST_API_OPENGL] & ST_PROFILE_OPENGL_ES1_MASK) - dpy->ClientAPIsMask |= EGL_OPENGL_ES_BIT; + dpy->ClientAPIs |= EGL_OPENGL_ES_BIT; if (gdpy->loader->profile_masks[ST_API_OPENGL] & ST_PROFILE_OPENGL_ES2_MASK) - dpy->ClientAPIsMask |= EGL_OPENGL_ES2_BIT; + dpy->ClientAPIs |= EGL_OPENGL_ES2_BIT; if (gdpy->loader->profile_masks[ST_API_OPENVG] & ST_PROFILE_DEFAULT_MASK) - dpy->ClientAPIsMask |= EGL_OPENVG_BIT; + dpy->ClientAPIs |= EGL_OPENVG_BIT; gdpy->smapi = egl_g3d_create_st_manager(dpy); if (!gdpy->smapi) { @@ -547,8 +546,8 @@ egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy, goto fail; } - *major = 1; - *minor = 4; + dpy->VersionMajor = 1; + dpy->VersionMinor = 4; return EGL_TRUE; From 655e4598927728a663f4cfcd6babdf7e5ad83f77 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 13 Jan 2011 00:27:45 +0800 Subject: [PATCH 075/164] egl: Simplify driver matching. Add initialization options that drv->API.Initialize should support. Replace drv->Probe by TestOnly initialization option and simplify _eglMatchDriver. --- src/egl/drivers/dri2/egl_dri2.c | 4 + src/egl/drivers/glx/egl_glx.c | 3 + src/egl/main/egldisplay.h | 5 + src/egl/main/egldriver.c | 141 +++++++----------- src/egl/main/egldriver.h | 12 +- .../state_trackers/egl/common/egl_g3d.c | 11 +- 6 files changed, 74 insertions(+), 102 deletions(-) diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index f6bca4abf72..2e827f4f3e5 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -1472,10 +1472,14 @@ dri2_initialize(_EGLDriver *drv, _EGLDisplay *disp) { switch (disp->Platform) { case _EGL_PLATFORM_X11: + if (disp->Options.TestOnly) + return EGL_TRUE; return dri2_initialize_x11(drv, disp); #ifdef HAVE_LIBUDEV case _EGL_PLATFORM_DRM: + if (disp->Options.TestOnly) + return EGL_TRUE; return dri2_initialize_drm(drv, disp); #endif diff --git a/src/egl/drivers/glx/egl_glx.c b/src/egl/drivers/glx/egl_glx.c index 84b04f7967e..aecebae40c2 100644 --- a/src/egl/drivers/glx/egl_glx.c +++ b/src/egl/drivers/glx/egl_glx.c @@ -589,6 +589,9 @@ GLX_eglInitialize(_EGLDriver *drv, _EGLDisplay *disp) if (disp->Platform != _EGL_PLATFORM_X11) return EGL_FALSE; + if (disp->Options.TestOnly) + return EGL_TRUE; + GLX_dpy = CALLOC_STRUCT(GLX_egl_display); if (!GLX_dpy) return _eglError(EGL_BAD_ALLOC, "eglInitialize"); diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index faeb2906478..b42760befab 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -90,6 +90,11 @@ struct _egl_display _EGLDriver *Driver; /**< Matched driver of the display */ EGLBoolean Initialized; /**< True if the display is initialized */ + /* options that affect how the driver initializes the display */ + struct { + EGLBoolean TestOnly; /**< Driver should not set fields when true */ + } Options; + /* these fields are set by the driver during init */ void *DriverData; /**< Driver private data */ EGLint VersionMajor; /**< EGL major version */ diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c index 1ae030db448..7baa24fbf86 100644 --- a/src/egl/main/egldriver.c +++ b/src/egl/main/egldriver.c @@ -525,100 +525,75 @@ _eglAddDrivers(void) /** - * Match a display to a driver. The display is initialized unless use_probe is - * true. - * - * The matching is done by finding the first driver that can initialize the - * display, or when use_probe is true, the driver with highest score. + * A helper function for _eglMatchDriver. It finds the first driver that can + * initialize the display and return. + */ +static _EGLDriver * +_eglMatchAndInitialize(_EGLDisplay *dpy) +{ + _EGLDriver *drv = NULL; + EGLint i = 0; + + if (!_eglAddDrivers()) { + _eglLog(_EGL_WARNING, "failed to find any driver"); + return NULL; + } + + if (dpy->Driver) { + drv = dpy->Driver; + /* no re-matching? */ + if (!drv->API.Initialize(drv, dpy)) + drv = NULL; + return drv; + } + + while (i < _eglModules->Size) { + _EGLModule *mod = (_EGLModule *) _eglModules->Elements[i]; + + if (!_eglLoadModule(mod)) { + /* remove invalid modules */ + _eglEraseArray(_eglModules, i, _eglFreeModule); + continue; + } + + if (mod->Driver->API.Initialize(mod->Driver, dpy)) { + drv = mod->Driver; + break; + } + else { + i++; + } + } + + return drv; +} + + +/** + * Match a display to a driver. The display is initialized unless test_only is + * true. The matching is done by finding the first driver that can initialize + * the display. */ _EGLDriver * -_eglMatchDriver(_EGLDisplay *dpy, EGLBoolean use_probe) +_eglMatchDriver(_EGLDisplay *dpy, EGLBoolean test_only) { - _EGLModule *mod; - _EGLDriver *best_drv = NULL; - EGLint best_score = 0; - EGLint i; + _EGLDriver *best_drv; + + assert(!dpy->Initialized); _eglLockMutex(&_eglModuleMutex); - if (!_eglAddDrivers()) { - _eglUnlockMutex(&_eglModuleMutex); - _eglLog(_EGL_WARNING, "failed to find any driver"); - return EGL_FALSE; - } + /* set options */ + dpy->Options.TestOnly = test_only; - /* match the loaded modules */ - for (i = 0; i < _eglModules->Size; i++) { - mod = (_EGLModule *) _eglModules->Elements[i]; - if (!mod->Driver) - break; - - if (use_probe) { - EGLint score = (mod->Driver->Probe) ? - mod->Driver->Probe(mod->Driver, dpy) : 1; - if (score > best_score) { - best_drv = mod->Driver; - best_score = score; - } - } - else { - if (mod->Driver->API.Initialize(mod->Driver, dpy)) { - best_drv = mod->Driver; - best_score = 100; - } - } - /* perfect match */ - if (best_score >= 100) - break; - } - - /* load more modules */ - if (!best_drv) { - EGLint first_unloaded = i; - - while (i < _eglModules->Size) { - mod = (_EGLModule *) _eglModules->Elements[i]; - assert(!mod->Driver); - - if (!_eglLoadModule(mod)) { - /* remove invalid modules */ - _eglEraseArray(_eglModules, i, _eglFreeModule); - continue; - } - - if (use_probe) { - best_score = (mod->Driver->Probe) ? - mod->Driver->Probe(mod->Driver, dpy) : 1; - } - else { - if (mod->Driver->API.Initialize(mod->Driver, dpy)) - best_score = 100; - } - - if (best_score > 0) { - best_drv = mod->Driver; - /* loaded modules come before unloaded ones */ - if (first_unloaded != i) { - void *tmp = _eglModules->Elements[i]; - _eglModules->Elements[i] = - _eglModules->Elements[first_unloaded]; - _eglModules->Elements[first_unloaded] = tmp; - } - break; - } - else { - _eglUnloadModule(mod); - i++; - } - } - } + best_drv = _eglMatchAndInitialize(dpy); _eglUnlockMutex(&_eglModuleMutex); if (best_drv) { - _eglLog(_EGL_DEBUG, "the best driver is %s (score %d)", - best_drv->Name, best_score); - if (!use_probe) { + _eglLog(_EGL_DEBUG, "the best driver is %s%s", + best_drv->Name, (test_only) ? " (test only) " : ""); + if (!test_only) { dpy->Driver = best_drv; dpy->Initialized = EGL_TRUE; } diff --git a/src/egl/main/egldriver.h b/src/egl/main/egldriver.h index d6177579193..3cde102d12d 100644 --- a/src/egl/main/egldriver.h +++ b/src/egl/main/egldriver.h @@ -43,16 +43,6 @@ struct _egl_driver { const char *Name; /**< name of this driver */ - /** - * Probe a display and return a score. - * - * Roughly, - * 50 means the driver supports the display; - * 90 means the driver can accelerate the display; - * 100 means a perfect match. - */ - EGLint (*Probe)(_EGLDriver *drv, _EGLDisplay *dpy); - /** * Release the driver resource. * @@ -81,7 +71,7 @@ _eglMain(const char *args); extern _EGLDriver * -_eglMatchDriver(_EGLDisplay *dpy, EGLBoolean probe_only); +_eglMatchDriver(_EGLDisplay *dpy, EGLBoolean test_only); extern __eglMustCastToProperFunctionPointerType diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.c b/src/gallium/state_trackers/egl/common/egl_g3d.c index 90354705172..bad32ac6e4c 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d.c +++ b/src/gallium/state_trackers/egl/common/egl_g3d.c @@ -484,6 +484,9 @@ egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy) if (!nplat) return EGL_FALSE; + if (dpy->Options.TestOnly) + return EGL_TRUE; + gdpy = CALLOC_STRUCT(egl_g3d_display); if (!gdpy) { _eglError(EGL_BAD_ALLOC, "eglInitialize"); @@ -572,12 +575,6 @@ egl_g3d_get_proc_address(_EGLDriver *drv, const char *procname) stapi->get_proc_address(stapi, procname) : NULL); } -static EGLint -egl_g3d_probe(_EGLDriver *drv, _EGLDisplay *dpy) -{ - return (egl_g3d_get_platform(drv, dpy->Platform)) ? 90 : 0; -} - _EGLDriver * egl_g3d_create_driver(const struct egl_g3d_loader *loader) { @@ -594,8 +591,6 @@ egl_g3d_create_driver(const struct egl_g3d_loader *loader) gdrv->base.API.Terminate = egl_g3d_terminate; gdrv->base.API.GetProcAddress = egl_g3d_get_proc_address; - gdrv->base.Probe = egl_g3d_probe; - /* to be filled by the caller */ gdrv->base.Name = NULL; gdrv->base.Unload = NULL; From a22a332fc7cc54d4d0973dcd21a90159cc51de1a Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 13 Jan 2011 04:40:38 +0800 Subject: [PATCH 076/164] egl: Improve driver selection. The idea is to be able to match a driver using the following order try egl_gallium with hw renderer try egl_dri2 try egl_gallium with sw renderer try egl_glx given the module list egl_gallium egl_dri2 egl_glx For that, UseFallback initialization option is added. The module list is matched twice: with the option unset and with the option set. In the first pass, egl_gallium skips its sw renderer and egl_glx rejects to initialize since UseFallback is not set. In the second pass, egl_gallium skips its hw renderer and egl_dri2 rejects to initialize since UseFallback is set. The process stops at the first driver that initializes the display. --- src/egl/drivers/dri2/egl_dri2.c | 4 + src/egl/drivers/glx/egl_glx.c | 4 + src/egl/main/egldisplay.h | 1 + src/egl/main/egldriver.c | 5 ++ .../state_trackers/egl/common/egl_g3d.c | 86 ++++++++++--------- .../state_trackers/egl/common/native.h | 3 +- .../state_trackers/egl/drm/native_drm.c | 14 ++- .../state_trackers/egl/fbdev/native_fbdev.c | 14 ++- .../state_trackers/egl/gdi/native_gdi.c | 16 +++- .../state_trackers/egl/x11/native_x11.c | 28 +++--- 10 files changed, 111 insertions(+), 64 deletions(-) diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index 2e827f4f3e5..6fc1e49e773 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -1470,6 +1470,10 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp) static EGLBoolean dri2_initialize(_EGLDriver *drv, _EGLDisplay *disp) { + /* not until swrast_dri is supported */ + if (disp->Options.UseFallback) + return EGL_FALSE; + switch (disp->Platform) { case _EGL_PLATFORM_X11: if (disp->Options.TestOnly) diff --git a/src/egl/drivers/glx/egl_glx.c b/src/egl/drivers/glx/egl_glx.c index aecebae40c2..c3c11c7b6eb 100644 --- a/src/egl/drivers/glx/egl_glx.c +++ b/src/egl/drivers/glx/egl_glx.c @@ -589,6 +589,10 @@ GLX_eglInitialize(_EGLDriver *drv, _EGLDisplay *disp) if (disp->Platform != _EGL_PLATFORM_X11) return EGL_FALSE; + /* this is a fallback driver */ + if (!disp->Options.UseFallback) + return EGL_FALSE; + if (disp->Options.TestOnly) return EGL_TRUE; diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index b42760befab..dbc5d32d910 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -93,6 +93,7 @@ struct _egl_display /* options that affect how the driver initializes the display */ struct { EGLBoolean TestOnly; /**< Driver should not set fields when true */ + EGLBoolean UseFallback; /**< Use fallback driver (sw or less features) */ } Options; /* these fields are set by the driver during init */ diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c index 7baa24fbf86..e133c220f5c 100644 --- a/src/egl/main/egldriver.c +++ b/src/egl/main/egldriver.c @@ -585,8 +585,13 @@ _eglMatchDriver(_EGLDisplay *dpy, EGLBoolean test_only) /* set options */ dpy->Options.TestOnly = test_only; + dpy->Options.UseFallback = EGL_FALSE; best_drv = _eglMatchAndInitialize(dpy); + if (!best_drv) { + dpy->Options.UseFallback = EGL_TRUE; + best_drv = _eglMatchAndInitialize(dpy); + } _eglUnlockMutex(&_eglModuleMutex); diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.c b/src/gallium/state_trackers/egl/common/egl_g3d.c index bad32ac6e4c..9024f945b8c 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d.c +++ b/src/gallium/state_trackers/egl/common/egl_g3d.c @@ -38,6 +38,46 @@ #include "egl_g3d_loader.h" #include "native.h" +static void +egl_g3d_invalid_surface(struct native_display *ndpy, + struct native_surface *nsurf, + unsigned int seq_num) +{ + /* XXX not thread safe? */ + struct egl_g3d_surface *gsurf = egl_g3d_surface(nsurf->user_data); + struct egl_g3d_context *gctx; + + /* + * Some functions such as egl_g3d_copy_buffers create a temporary native + * surface. There is no gsurf associated with it. + */ + gctx = (gsurf) ? egl_g3d_context(gsurf->base.CurrentContext) : NULL; + if (gctx) + gctx->stctxi->notify_invalid_framebuffer(gctx->stctxi, gsurf->stfbi); +} + +static struct pipe_screen * +egl_g3d_new_drm_screen(struct native_display *ndpy, const char *name, int fd) +{ + _EGLDisplay *dpy = (_EGLDisplay *) ndpy->user_data; + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + return gdpy->loader->create_drm_screen(name, fd); +} + +static struct pipe_screen * +egl_g3d_new_sw_screen(struct native_display *ndpy, struct sw_winsys *ws) +{ + _EGLDisplay *dpy = (_EGLDisplay *) ndpy->user_data; + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + return gdpy->loader->create_sw_screen(ws); +} + +static struct native_event_handler egl_g3d_native_event_handler = { + egl_g3d_invalid_surface, + egl_g3d_new_drm_screen, + egl_g3d_new_sw_screen +}; + /** * Get the native platform. */ @@ -79,7 +119,9 @@ egl_g3d_get_platform(_EGLDriver *drv, _EGLPlatformType plat) break; } - if (!nplat) + if (nplat) + nplat->set_event_handler(&egl_g3d_native_event_handler); + else _eglLog(_EGL_WARNING, "unsupported platform %s", plat_name); gdrv->platforms[plat] = nplat; @@ -383,46 +425,6 @@ egl_g3d_add_configs(_EGLDriver *drv, _EGLDisplay *dpy, EGLint id) return id; } -static void -egl_g3d_invalid_surface(struct native_display *ndpy, - struct native_surface *nsurf, - unsigned int seq_num) -{ - /* XXX not thread safe? */ - struct egl_g3d_surface *gsurf = egl_g3d_surface(nsurf->user_data); - struct egl_g3d_context *gctx; - - /* - * Some functions such as egl_g3d_copy_buffers create a temporary native - * surface. There is no gsurf associated with it. - */ - gctx = (gsurf) ? egl_g3d_context(gsurf->base.CurrentContext) : NULL; - if (gctx) - gctx->stctxi->notify_invalid_framebuffer(gctx->stctxi, gsurf->stfbi); -} - -static struct pipe_screen * -egl_g3d_new_drm_screen(struct native_display *ndpy, const char *name, int fd) -{ - _EGLDisplay *dpy = (_EGLDisplay *) ndpy->user_data; - struct egl_g3d_display *gdpy = egl_g3d_display(dpy); - return gdpy->loader->create_drm_screen(name, fd); -} - -static struct pipe_screen * -egl_g3d_new_sw_screen(struct native_display *ndpy, struct sw_winsys *ws) -{ - _EGLDisplay *dpy = (_EGLDisplay *) ndpy->user_data; - struct egl_g3d_display *gdpy = egl_g3d_display(dpy); - return gdpy->loader->create_sw_screen(ws); -} - -static struct native_event_handler egl_g3d_native_event_handler = { - egl_g3d_invalid_surface, - egl_g3d_new_drm_screen, - egl_g3d_new_sw_screen -}; - static void egl_g3d_free_config(void *conf) { @@ -497,7 +499,7 @@ egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy) _eglLog(_EGL_INFO, "use %s for display %p", nplat->name, dpy->PlatformDisplay); gdpy->native = nplat->create_display(dpy->PlatformDisplay, - &egl_g3d_native_event_handler, (void *) dpy); + dpy->Options.UseFallback, (void *) dpy); if (!gdpy->native) { _eglError(EGL_NOT_INITIALIZED, "eglInitialize(no usable display)"); goto fail; diff --git a/src/gallium/state_trackers/egl/common/native.h b/src/gallium/state_trackers/egl/common/native.h index 654f445fca6..6461b5edbdf 100644 --- a/src/gallium/state_trackers/egl/common/native.h +++ b/src/gallium/state_trackers/egl/common/native.h @@ -226,8 +226,9 @@ native_attachment_mask_test(uint mask, enum native_attachment att) struct native_platform { const char *name; + void (*set_event_handler)(struct native_event_handler *handler); struct native_display *(*create_display)(void *dpy, - struct native_event_handler *handler, + boolean use_sw, void *user_data); }; diff --git a/src/gallium/state_trackers/egl/drm/native_drm.c b/src/gallium/state_trackers/egl/drm/native_drm.c index 2441b43fd8e..14c134ea1ad 100644 --- a/src/gallium/state_trackers/egl/drm/native_drm.c +++ b/src/gallium/state_trackers/egl/drm/native_drm.c @@ -237,9 +237,16 @@ drm_create_display(int fd, struct native_event_handler *event_handler, return &drmdpy->base; } +static struct native_event_handler *drm_event_handler; + +static void +native_set_event_handler(struct native_event_handler *event_handler) +{ + drm_event_handler = event_handler; +} + static struct native_display * -native_create_display(void *dpy, struct native_event_handler *event_handler, - void *user_data) +native_create_display(void *dpy, boolean use_sw, void *user_data) { int fd; @@ -252,11 +259,12 @@ native_create_display(void *dpy, struct native_event_handler *event_handler, if (fd < 0) return NULL; - return drm_create_display(fd, event_handler, user_data); + return drm_create_display(fd, drm_event_handler, user_data); } static const struct native_platform drm_platform = { "DRM", /* name */ + native_set_event_handler, native_create_display }; diff --git a/src/gallium/state_trackers/egl/fbdev/native_fbdev.c b/src/gallium/state_trackers/egl/fbdev/native_fbdev.c index 1b5ea8bf9d5..a1e91ba701c 100644 --- a/src/gallium/state_trackers/egl/fbdev/native_fbdev.c +++ b/src/gallium/state_trackers/egl/fbdev/native_fbdev.c @@ -459,9 +459,16 @@ fbdev_display_create(int fd, struct native_event_handler *event_handler, return &fbdpy->base; } +static struct native_event_handler *fbdev_event_handler; + +static void +native_set_event_handler(struct native_event_handler *event_handler) +{ + fbdev_event_handler = event_handler; +} + static struct native_display * -native_create_display(void *dpy, struct native_event_handler *event_handler, - void *user_data) +native_create_display(void *dpy, boolean use_sw, void *user_data) { struct native_display *ndpy; int fd; @@ -476,7 +483,7 @@ native_create_display(void *dpy, struct native_event_handler *event_handler, if (fd < 0) return NULL; - ndpy = fbdev_display_create(fd, event_handler, user_data); + ndpy = fbdev_display_create(fd, fbdev_event_handler, user_data); if (!ndpy) close(fd); @@ -485,6 +492,7 @@ native_create_display(void *dpy, struct native_event_handler *event_handler, static const struct native_platform fbdev_platform = { "FBDEV", /* name */ + native_set_event_handler, native_create_display }; diff --git a/src/gallium/state_trackers/egl/gdi/native_gdi.c b/src/gallium/state_trackers/egl/gdi/native_gdi.c index 2d0450604c6..3cc4aefa937 100644 --- a/src/gallium/state_trackers/egl/gdi/native_gdi.c +++ b/src/gallium/state_trackers/egl/gdi/native_gdi.c @@ -406,15 +406,23 @@ gdi_create_display(HDC hDC, struct native_event_handler *event_handler, return &gdpy->base; } -static struct native_display * -native_create_display(void *dpy, struct native_event_handler *event_handler, - void *user_data) +static struct native_event_handler *gdi_event_handler; + +static void +native_set_event_handler(struct native_event_handler *event_handler) { - return gdi_create_display((HDC) dpy, event_handler, user_data); + gdi_event_handler = event_handler; +} + +static struct native_display * +native_create_display(void *dpy, boolean use_sw, void *user_data) +{ + return gdi_create_display((HDC) dpy, gdi_event_handler, user_data); } static const struct native_platform gdi_platform = { "GDI", /* name */ + native_set_event_handler, native_create_display }; diff --git a/src/gallium/state_trackers/egl/x11/native_x11.c b/src/gallium/state_trackers/egl/x11/native_x11.c index 37c8b01541f..a0bcad4c734 100644 --- a/src/gallium/state_trackers/egl/x11/native_x11.c +++ b/src/gallium/state_trackers/egl/x11/native_x11.c @@ -30,25 +30,30 @@ #include "native_x11.h" +static struct native_event_handler *x11_event_handler; + +static void +native_set_event_handler(struct native_event_handler *event_handler) +{ + x11_event_handler = event_handler; +} + static struct native_display * -native_create_display(void *dpy, struct native_event_handler *event_handler, - void *user_data) +native_create_display(void *dpy, boolean use_sw, void *user_data) { struct native_display *ndpy = NULL; boolean force_sw; force_sw = debug_get_bool_option("EGL_SOFTWARE", FALSE); - if (!force_sw) { - ndpy = x11_create_dri2_display((Display *) dpy, - event_handler, user_data); - } - if (!ndpy) { - EGLint level = (force_sw) ? _EGL_INFO : _EGL_WARNING; - - _eglLog(level, "use software fallback"); + if (force_sw || use_sw) { + _eglLog(_EGL_INFO, "use software fallback"); ndpy = x11_create_ximage_display((Display *) dpy, - event_handler, user_data); + x11_event_handler, user_data); + } + else { + ndpy = x11_create_dri2_display((Display *) dpy, + x11_event_handler, user_data); } return ndpy; @@ -56,6 +61,7 @@ native_create_display(void *dpy, struct native_event_handler *event_handler, static const struct native_platform x11_platform = { "X11", /* name */ + native_set_event_handler, native_create_display }; From fe2cfd9b19657274244b187310b706ff5aa09728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fonseca?= Date: Thu, 13 Jan 2011 11:44:16 +0000 Subject: [PATCH 077/164] util: Don't limit debug_printf message length on unices. --- src/gallium/auxiliary/util/u_debug.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c index 2ad2f95b13e..a19db3a6576 100644 --- a/src/gallium/auxiliary/util/u_debug.c +++ b/src/gallium/auxiliary/util/u_debug.c @@ -47,14 +47,19 @@ void _debug_vprintf(const char *format, va_list ap) { +#if defined(PIPE_OS_WINDOWS) || defined(PIPE_OS_EMBEDDED) /* We buffer until we find a newline. */ static char buf[4096] = {'\0'}; size_t len = strlen(buf); int ret = util_vsnprintf(buf + len, sizeof(buf) - len, format, ap); if(ret > (int)(sizeof(buf) - len - 1) || util_strchr(buf + len, '\n')) { - os_log_message(buf); + os_log_message(buf * h); buf[0] = '\0'; } +#else + /* Just print as-is to stderr */ + vfprintf(stderr, format, ap); +#endif } From 80f18876f689e250e286f8821e37389b414776bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fonseca?= Date: Thu, 13 Jan 2011 11:45:40 +0000 Subject: [PATCH 078/164] util: Undo spurious changes in last commit. --- src/gallium/auxiliary/util/u_debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c index a19db3a6576..f4ad545bee7 100644 --- a/src/gallium/auxiliary/util/u_debug.c +++ b/src/gallium/auxiliary/util/u_debug.c @@ -53,7 +53,7 @@ void _debug_vprintf(const char *format, va_list ap) size_t len = strlen(buf); int ret = util_vsnprintf(buf + len, sizeof(buf) - len, format, ap); if(ret > (int)(sizeof(buf) - len - 1) || util_strchr(buf + len, '\n')) { - os_log_message(buf * h); + os_log_message(buf); buf[0] = '\0'; } #else From 63528c4510e4891a13c255871b1dd5c2dafdb02c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fonseca?= Date: Thu, 13 Jan 2011 11:54:43 +0000 Subject: [PATCH 079/164] scons: Build libOpenVG.dll & libEGL.dll But without creating liblibOpenVG or liblibEGL elsewhere. Thanks Chia-I Wu for pointing this out. --- src/gallium/targets/egl-static/SConscript | 5 ++++- src/mapi/vgapi/SConscript | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/gallium/targets/egl-static/SConscript b/src/gallium/targets/egl-static/SConscript index 028fc095c04..3eba9e07f20 100644 --- a/src/gallium/targets/egl-static/SConscript +++ b/src/gallium/targets/egl-static/SConscript @@ -111,8 +111,11 @@ if env['drm']: svga, ]) +# libEGL.dll +env['SHLIBPREFIX'] = 'lib' + egl_gallium = env.SharedLibrary( - target ='libEGL', + target ='EGL', source = sources, ) diff --git a/src/mapi/vgapi/SConscript b/src/mapi/vgapi/SConscript index c0c6c6c033a..e970e4eff84 100644 --- a/src/mapi/vgapi/SConscript +++ b/src/mapi/vgapi/SConscript @@ -44,6 +44,9 @@ if env['platform'] != 'winddk': env.Depends(vgapi_objects, vgapi_header) + # libOpenVG.dll + env['SHLIBPREFIX'] = 'lib' + openvg = env.SharedLibrary( target = 'OpenVG', source = vgapi_objects, From 9277a62aa3c1b2073dcfafcf34265b4d7154f4da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fonseca?= Date: Thu, 13 Jan 2011 12:33:41 +0000 Subject: [PATCH 080/164] scons: Ensure the OpenVG/EGL import libs are also prefixed with 'lib'. --- src/gallium/targets/egl-static/SConscript | 1 + src/mapi/vgapi/SConscript | 1 + 2 files changed, 2 insertions(+) diff --git a/src/gallium/targets/egl-static/SConscript b/src/gallium/targets/egl-static/SConscript index 3eba9e07f20..25c49ea9d18 100644 --- a/src/gallium/targets/egl-static/SConscript +++ b/src/gallium/targets/egl-static/SConscript @@ -112,6 +112,7 @@ if env['drm']: ]) # libEGL.dll +env['LIBPREFIX'] = 'lib' env['SHLIBPREFIX'] = 'lib' egl_gallium = env.SharedLibrary( diff --git a/src/mapi/vgapi/SConscript b/src/mapi/vgapi/SConscript index e970e4eff84..ee6d9fb827c 100644 --- a/src/mapi/vgapi/SConscript +++ b/src/mapi/vgapi/SConscript @@ -45,6 +45,7 @@ if env['platform'] != 'winddk': env.Depends(vgapi_objects, vgapi_header) # libOpenVG.dll + env['LIBPREFIX'] = 'lib' env['SHLIBPREFIX'] = 'lib' openvg = env.SharedLibrary( From dad914f6b2e5862a5174133f11276e975867be04 Mon Sep 17 00:00:00 2001 From: Paulo Zanoni Date: Thu, 13 Jan 2011 04:59:12 -0800 Subject: [PATCH 081/164] dri_util: fail driCreateNewScreen if InitScreen is NULL Without this, X doesn't start with UMS on r300g. NOTE: This is a candidate for the 7.9 and 7.10 branches. Signed-off-by: Paulo Zanoni Signed-off-by: Brian Paul --- src/mesa/drivers/dri/common/dri_util.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/mesa/drivers/dri/common/dri_util.c b/src/mesa/drivers/dri/common/dri_util.c index a5b71bd40ad..bf8cf6eec07 100644 --- a/src/mesa/drivers/dri/common/dri_util.c +++ b/src/mesa/drivers/dri/common/dri_util.c @@ -790,6 +790,9 @@ driCreateNewScreen(int scrn, static const __DRIextension *emptyExtensionList[] = { NULL }; __DRIscreen *psp; + if (driDriverAPI.InitScreen == NULL) + return NULL; + psp = calloc(1, sizeof *psp); if (!psp) return NULL; From ca31c596e8acf64cbae86b052bb5634790a540ce Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 13 Jan 2011 09:25:55 -0700 Subject: [PATCH 082/164] egl: need stdio.h for non-Windows build too to avoid compiler warning --- src/egl/main/eglstring.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/egl/main/eglstring.h b/src/egl/main/eglstring.h index 8a8c43c1eff..d4c89541362 100644 --- a/src/egl/main/eglstring.h +++ b/src/egl/main/eglstring.h @@ -2,9 +2,9 @@ #define EGLSTRING_INCLUDED #include +#include #ifdef _EGL_OS_WINDOWS -#include #define _eglstrcasecmp _stricmp #define _eglsnprintf _snprintf #else From d76f1da7cb4a9c5666e2364f90eb09552e839b55 Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Thu, 13 Jan 2011 08:53:33 -0800 Subject: [PATCH 083/164] mesa: Add missing break statement in SARGB8 case. --- src/mesa/main/texrender.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mesa/main/texrender.c b/src/mesa/main/texrender.c index 968f9f139c5..8cec24c3e24 100644 --- a/src/mesa/main/texrender.c +++ b/src/mesa/main/texrender.c @@ -599,6 +599,7 @@ update_wrapper(struct gl_context *ctx, const struct gl_renderbuffer_attachment * trb->Fetchf = _mesa_get_texel_fetch_func(MESA_FORMAT_ARGB8888, _mesa_get_texture_dimensions(att->Texture->Target)); trb->Base.DataType = CHAN_TYPE; trb->Base._BaseFormat = GL_RGBA; + break; default: trb->Base.DataType = CHAN_TYPE; trb->Base._BaseFormat = GL_RGBA; From eb70e58caf773f9a89aa16109705b84f0aa2a6f7 Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Thu, 13 Jan 2011 09:07:19 -0800 Subject: [PATCH 084/164] r600g: Silence uninitialized variable warnings. --- src/gallium/drivers/r600/r600_asm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gallium/drivers/r600/r600_asm.c b/src/gallium/drivers/r600/r600_asm.c index 6c216c4d5f8..57acb87240d 100644 --- a/src/gallium/drivers/r600/r600_asm.c +++ b/src/gallium/drivers/r600/r600_asm.c @@ -1092,10 +1092,10 @@ void r600_bc_clear(struct r600_bc *bc) void r600_bc_dump(struct r600_bc *bc) { - struct r600_bc_cf *cf; - struct r600_bc_alu *alu; - struct r600_bc_vtx *vtx; - struct r600_bc_tex *tex; + struct r600_bc_cf *cf = NULL; + struct r600_bc_alu *alu = NULL; + struct r600_bc_vtx *vtx = NULL; + struct r600_bc_tex *tex = NULL; unsigned i, id; char chip = '6'; From d599df8a8c26bdaaf59cc650a5ca1b79230209ed Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Thu, 13 Jan 2011 09:16:25 -0800 Subject: [PATCH 085/164] targets/egl-static: Remove unnecessary header. --- src/gallium/targets/egl-static/egl_pipe.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/gallium/targets/egl-static/egl_pipe.c b/src/gallium/targets/egl-static/egl_pipe.c index 2684ede307f..a33d419e0aa 100644 --- a/src/gallium/targets/egl-static/egl_pipe.c +++ b/src/gallium/targets/egl-static/egl_pipe.c @@ -27,7 +27,6 @@ */ #include "target-helpers/inline_debug_helper.h" #include "target-helpers/inline_sw_helper.h" -#include "state_tracker/drm_driver.h" #include "egl_pipe.h" /* for i915 */ From 1f6693033256123ec5cf6f186e5cfb1679e523d3 Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Thu, 13 Jan 2011 09:28:47 -0800 Subject: [PATCH 086/164] i965: Remove unnecessary headers. --- src/mesa/drivers/dri/i965/brw_fallback.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/mesa/drivers/dri/i965/brw_fallback.c b/src/mesa/drivers/dri/i965/brw_fallback.c index 395f306f1b5..d0b0c22abf6 100644 --- a/src/mesa/drivers/dri/i965/brw_fallback.c +++ b/src/mesa/drivers/dri/i965/brw_fallback.c @@ -36,8 +36,6 @@ #include "swrast/swrast.h" #include "tnl/tnl.h" #include "brw_context.h" -#include "intel_fbo.h" -#include "intel_regions.h" #define FILE_DEBUG_FLAG DEBUG_FALLBACKS From abbb1c8f084c6739bc9d6f559caf26f3f71b2fab Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 14 Jan 2011 01:50:51 +0800 Subject: [PATCH 087/164] draw: Fix an off-by-one bug in a vsplit assertion. When use_spoken is true, istart (the first vertex of this segment) is replaced by i0 (the spoken vertex of the fan). There are still icount vertices. Thanks to Brian Paul for spotting this. --- src/gallium/auxiliary/draw/draw_pt_vsplit_tmp.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gallium/auxiliary/draw/draw_pt_vsplit_tmp.h b/src/gallium/auxiliary/draw/draw_pt_vsplit_tmp.h index 3f66f962e11..75dba8c39a5 100644 --- a/src/gallium/auxiliary/draw/draw_pt_vsplit_tmp.h +++ b/src/gallium/auxiliary/draw/draw_pt_vsplit_tmp.h @@ -258,9 +258,10 @@ vsplit_segment_fan_linear(struct vsplit_frontend *vsplit, unsigned flags, boolean use_spoken = ((flags & DRAW_SPLIT_BEFORE) != 0); unsigned nr = 0, i; - assert(icount + !!use_spoken <= vsplit->segment_size); + assert(icount <= vsplit->segment_size); if (use_spoken) { + /* replace istart by i0 */ vsplit->fetch_elts[nr++] = i0; for (i = 1 ; i < icount; i++) vsplit->fetch_elts[nr++] = istart + i; From 370ae0bd614fcbf9c4c0424fb5c41f2cfbc17b3e Mon Sep 17 00:00:00 2001 From: Christoph Bumiller Date: Thu, 13 Jan 2011 19:36:25 +0100 Subject: [PATCH 088/164] nvc0: identify POINT_RASTER_RULES, add POINT_SMOOTH state Point smoothing requires rasterization rules to be set to OGL. Sorry for the extra noise caused by the header update. --- src/gallium/drivers/nvc0/nvc0_3d.xml.h | 48 +++++++++++++++++------- src/gallium/drivers/nvc0/nvc0_screen.c | 10 ++--- src/gallium/drivers/nvc0/nvc0_state.c | 1 + src/gallium/drivers/nvc0/nvc0_stateobj.h | 2 +- 4 files changed, 42 insertions(+), 19 deletions(-) diff --git a/src/gallium/drivers/nvc0/nvc0_3d.xml.h b/src/gallium/drivers/nvc0/nvc0_3d.xml.h index 702e58b2e3c..31302949d5e 100644 --- a/src/gallium/drivers/nvc0/nvc0_3d.xml.h +++ b/src/gallium/drivers/nvc0/nvc0_3d.xml.h @@ -8,7 +8,7 @@ http://0x04.net/cgit/index.cgi/rules-ng-ng git clone git://0x04.net/rules-ng-ng The rules-ng-ng source files this header was generated from are: -- nvc0_3d.xml ( 30401 bytes, from 2011-01-08 18:09:11) +- nvc0_3d.xml ( 30827 bytes, from 2011-01-13 18:23:07) - copyright.xml ( 6452 bytes, from 2010-11-25 23:28:20) - nv_defs.xml ( 4437 bytes, from 2010-07-06 07:43:58) - nv_3ddefs.xml ( 16394 bytes, from 2010-12-17 15:10:40) @@ -449,6 +449,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define NVC0_3D_LINKED_TSC 0x00001234 +#define NVC0_3D_DRAW_TFB_BYTES 0x0000123c + #define NVC0_3D_FP_RESULT_COUNT 0x00001298 #define NVC0_3D_DEPTH_TEST_ENABLE 0x000012cc @@ -511,6 +513,10 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define NVC0_3D_ALPHA_TEST_FUNC_GEQUAL 0x00000206 #define NVC0_3D_ALPHA_TEST_FUNC_ALWAYS 0x00000207 +#define NVC0_3D_DRAW_TFB_STRIDE 0x00001318 +#define NVC0_3D_DRAW_TFB_STRIDE__MIN 0x00000001 +#define NVC0_3D_DRAW_TFB_STRIDE__MAX 0x00000fff + #define NVC0_3D_BLEND_COLOR(i0) (0x0000131c + 0x4*(i0)) #define NVC0_3D_BLEND_COLOR__ESIZE 0x00000004 #define NVC0_3D_BLEND_COLOR__LEN 0x00000004 @@ -603,6 +609,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define NVC0_3D_STENCIL_FRONT_FUNC_MASK 0x0000139c +#define NVC0_3D_DRAW_TFB_BASE 0x000013a4 + #define NVC0_3D_FRAG_COLOR_CLAMP_EN 0x000013a8 #define NVC0_3D_FRAG_COLOR_CLAMP_EN_0 0x00000001 #define NVC0_3D_FRAG_COLOR_CLAMP_EN_1 0x00000010 @@ -613,7 +621,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define NVC0_3D_FRAG_COLOR_CLAMP_EN_6 0x01000000 #define NVC0_3D_FRAG_COLOR_CLAMP_EN_7 0x10000000 -#define NVC0_3D_Y_ORIGIN_BOTTOM 0x000013ac +#define NVC0_3D_SCREEN_Y_CONTROL 0x000013ac +#define NVC0_3D_SCREEN_Y_CONTROL_Y_NEGATE 0x00000001 +#define NVC0_3D_SCREEN_Y_CONTROL_TRIANGLE_RAST_FLIP 0x00000010 #define NVC0_3D_LINE_WIDTH 0x000013b0 @@ -621,7 +631,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define NVC0_3D_GP_VERTEX_OUTPUT_COUNT__MIN 0x00000001 #define NVC0_3D_GP_VERTEX_OUTPUT_COUNT__MAX 0x00000400 -#define NVC0_3D_FENCE_UNK 0x0000142c +#define NVC0_3D_VERTEX_ARRAY_FLUSH 0x0000142c #define NVC0_3D_VB_ELEMENT_BASE 0x00001434 @@ -668,7 +678,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define NVC0_3D_COUNTER_RESET_UNK1E 0x0000001e #define NVC0_3D_COUNTER_RESET_GENERATED_PRIMITIVES 0x0000001f -#define NVC0_3D_MULTISAMPLE_ZETA_ENABLE 0x00001534 +#define NVC0_3D_MULTISAMPLE_ENABLE 0x00001534 #define NVC0_3D_ZETA_ENABLE 0x00001538 @@ -747,7 +757,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define NVC0_3D_STENCIL_BACK_FUNC_FUNC_GEQUAL 0x00000206 #define NVC0_3D_STENCIL_BACK_FUNC_FUNC_ALWAYS 0x00000207 -#define NVC0_3D_MULTISAMPLE_COLOR_ENABLE 0x000015b4 +#define NVC0_3D_CSAA_ENABLE 0x000015b4 #define NVC0_3D_FRAMEBUFFER_SRGB 0x000015b8 @@ -849,6 +859,10 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define NVC0_3D_POINT_SMOOTH_ENABLE 0x00001658 +#define NVC0_3D_POINT_RASTER_RULES 0x0000165c +#define NVC0_3D_POINT_RASTER_RULES_OGL 0x00000000 +#define NVC0_3D_POINT_RASTER_RULES_D3D 0x00000001 + #define NVC0_3D_POINT_SPRITE_CTRL 0x00001660 #define NVC0_3D_TEX_MISC 0x00001664 @@ -1028,6 +1042,14 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define NVC0_3D_VERTEX_ARRAY_FETCH_STRIDE__SHIFT 0 #define NVC0_3D_VERTEX_ARRAY_FETCH_ENABLE 0x00001000 +#define NVC0_3D_VERTEX_ARRAY_START_HIGH(i0) (0x00001c04 + 0x10*(i0)) +#define NVC0_3D_VERTEX_ARRAY_START_HIGH__ESIZE 0x00000010 +#define NVC0_3D_VERTEX_ARRAY_START_HIGH__LEN 0x00000020 + +#define NVC0_3D_VERTEX_ARRAY_START_LOW(i0) (0x00001c08 + 0x10*(i0)) +#define NVC0_3D_VERTEX_ARRAY_START_LOW__ESIZE 0x00000010 +#define NVC0_3D_VERTEX_ARRAY_START_LOW__LEN 0x00000020 + #define NVC0_3D_VERTEX_ARRAY_DIVISOR(i0) (0x00001c0c + 0x10*(i0)) #define NVC0_3D_VERTEX_ARRAY_DIVISOR__ESIZE 0x00000010 #define NVC0_3D_VERTEX_ARRAY_DIVISOR__LEN 0x00000020 @@ -1058,6 +1080,14 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define NVC0_3D_IBLEND_FUNC_DST_ALPHA(i0) (0x00001e18 + 0x20*(i0)) +#define NVC0_3D_VERTEX_ARRAY_LIMIT_HIGH(i0) (0x00001f00 + 0x8*(i0)) +#define NVC0_3D_VERTEX_ARRAY_LIMIT_HIGH__ESIZE 0x00000008 +#define NVC0_3D_VERTEX_ARRAY_LIMIT_HIGH__LEN 0x00000020 + +#define NVC0_3D_VERTEX_ARRAY_LIMIT_LOW(i0) (0x00001f04 + 0x8*(i0)) +#define NVC0_3D_VERTEX_ARRAY_LIMIT_LOW__ESIZE 0x00000008 +#define NVC0_3D_VERTEX_ARRAY_LIMIT_LOW__LEN 0x00000020 + #define NVC0_3D_SP(i0) (0x00002000 + 0x40*(i0)) #define NVC0_3D_SP__ESIZE 0x00000040 #define NVC0_3D_SP__LEN 0x00000006 @@ -1132,14 +1162,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define NVC0_3D_VERTEX_ARRAY_SELECT 0x00003820 -#define NVC0_3D_VERTEX_ARRAY_LIMIT_HIGH 0x00003824 - -#define NVC0_3D_VERTEX_ARRAY_LIMIT_LOW 0x00003828 - -#define NVC0_3D_VERTEX_ARRAY_START_HIGH 0x0000382c - -#define NVC0_3D_VERTEX_ARRAY_START_LOW 0x00003830 - #define NVC0_3D_BLEND_ENABLES 0x00003858 #define NVC0_3D_POLYGON_MODE_FRONT 0x00003868 diff --git a/src/gallium/drivers/nvc0/nvc0_screen.c b/src/gallium/drivers/nvc0/nvc0_screen.c index 2300af52eda..54eec660b2a 100644 --- a/src/gallium/drivers/nvc0/nvc0_screen.c +++ b/src/gallium/drivers/nvc0/nvc0_screen.c @@ -289,8 +289,6 @@ nvc0_magic_3d_init(struct nouveau_channel *chan) OUT_RING (chan, (2 << 16) | 2); BEGIN_RING(chan, RING_3D_(0x0de8), 1); OUT_RING (chan, 1); - BEGIN_RING(chan, RING_3D_(0x165c), 1); - OUT_RING (chan, 0); #if 0 /* software method */ BEGIN_RING(chan, RING_3D_(0x1528), 1); /* MP poke */ @@ -445,9 +443,9 @@ nvc0_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev) BEGIN_RING(chan, RING_3D(RT_CONTROL), 1); OUT_RING (chan, 1); - BEGIN_RING(chan, RING_3D(MULTISAMPLE_ZETA_ENABLE), 1); + BEGIN_RING(chan, RING_3D(CSAA_ENABLE), 1); OUT_RING (chan, 0); - BEGIN_RING(chan, RING_3D(MULTISAMPLE_COLOR_ENABLE), 1); + BEGIN_RING(chan, RING_3D(MULTISAMPLE_ENABLE), 1); OUT_RING (chan, 0); BEGIN_RING(chan, RING_3D(MULTISAMPLE_MODE), 1); OUT_RING (chan, NVC0_3D_MULTISAMPLE_MODE_1X); @@ -525,7 +523,7 @@ nvc0_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev) OUT_RELOCl(chan, screen->txc, 65536, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD); OUT_RING (chan, NVC0_TSC_MAX_ENTRIES - 1); - BEGIN_RING(chan, RING_3D(Y_ORIGIN_BOTTOM), 1); + BEGIN_RING(chan, RING_3D(SCREEN_Y_CONTROL), 1); OUT_RING (chan, 0); BEGIN_RING(chan, RING_3D(WINDOW_OFFSET_X), 2); OUT_RING (chan, 0); @@ -591,6 +589,8 @@ nvc0_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev) BEGIN_RING(chan, RING_3D(POINT_COORD_REPLACE), 1); OUT_RING (chan, 0); + BEGIN_RING(chan, RING_3D(POINT_RASTER_RULES), 1); + OUT_RING (chan, NVC0_3D_POINT_RASTER_RULES_OGL); BEGIN_RING(chan, RING_3D(FRAG_COLOR_CLAMP_EN), 1); OUT_RING (chan, 0x11111111); diff --git a/src/gallium/drivers/nvc0/nvc0_state.c b/src/gallium/drivers/nvc0/nvc0_state.c index 5a9b1c28509..c08f3693f5e 100644 --- a/src/gallium/drivers/nvc0/nvc0_state.c +++ b/src/gallium/drivers/nvc0/nvc0_state.c @@ -207,6 +207,7 @@ nvc0_rasterizer_state_create(struct pipe_context *pipe, SB_DATA (so, fui(cso->point_size)); } SB_IMMED_3D(so, POINT_SPRITE_ENABLE, cso->point_quad_rasterization); + SB_IMMED_3D(so, POINT_SMOOTH_ENABLE, cso->point_smooth); SB_BEGIN_3D(so, POLYGON_MODE_FRONT, 1); SB_DATA (so, nvgl_polygon_mode(cso->fill_front)); diff --git a/src/gallium/drivers/nvc0/nvc0_stateobj.h b/src/gallium/drivers/nvc0/nvc0_stateobj.h index e7cd94800de..ee788c5bb9c 100644 --- a/src/gallium/drivers/nvc0/nvc0_stateobj.h +++ b/src/gallium/drivers/nvc0/nvc0_stateobj.h @@ -48,7 +48,7 @@ nvc0_tic_entry(struct pipe_sampler_view *view) struct nvc0_rasterizer_stateobj { struct pipe_rasterizer_state pipe; int size; - uint32_t state[43]; + uint32_t state[36]; }; struct nvc0_zsa_stateobj { From 236e99fe05a8d301f81ca4330bf4ded80cf501a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 18 Dec 2010 00:45:59 +0100 Subject: [PATCH 089/164] r600g: optimize away CF ALU instructions even if type doesn't match --- src/gallium/drivers/r600/r600_asm.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/gallium/drivers/r600/r600_asm.c b/src/gallium/drivers/r600/r600_asm.c index 57acb87240d..53122e54b7d 100644 --- a/src/gallium/drivers/r600/r600_asm.c +++ b/src/gallium/drivers/r600/r600_asm.c @@ -539,16 +539,29 @@ int r600_bc_add_alu_type(struct r600_bc *bc, const struct r600_bc_alu *alu, int memcpy(nalu, alu, sizeof(struct r600_bc_alu)); nalu->nliteral = 0; + if (bc->cf_last != NULL && bc->cf_last->inst != (type << 3)) { + /* check if we could add it anyway */ + if (bc->cf_last->inst == (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU << 3) && + type == V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE) { + LIST_FOR_EACH_ENTRY(lalu, &bc->cf_last->alu, list) { + if (lalu->predicate) { + bc->force_add_cf = 1; + break; + } + } + } else + bc->force_add_cf = 1; + } + /* cf can contains only alu or only vtx or only tex */ - if (bc->cf_last == NULL || bc->cf_last->inst != (type << 3) || - bc->force_add_cf) { + if (bc->cf_last == NULL || bc->force_add_cf) { r = r600_bc_add_cf(bc); if (r) { free(nalu); return r; } - bc->cf_last->inst = (type << 3); } + bc->cf_last->inst = (type << 3); /* Setup the kcache for this ALU instruction. This will start a new * ALU clause if needed. */ From 89275c0b36f1104ac05f13e930f7fb99595607a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 18 Dec 2010 13:57:18 +0100 Subject: [PATCH 090/164] r600g: fix alu slot assignment --- src/gallium/drivers/r600/r600_asm.c | 182 +++++++++++++++++++++++++--- 1 file changed, 167 insertions(+), 15 deletions(-) diff --git a/src/gallium/drivers/r600/r600_asm.c b/src/gallium/drivers/r600/r600_asm.c index 53122e54b7d..b0567dd55de 100644 --- a/src/gallium/drivers/r600/r600_asm.c +++ b/src/gallium/drivers/r600/r600_asm.c @@ -195,6 +195,151 @@ int r600_bc_add_output(struct r600_bc *bc, const struct r600_bc_output *output) return 0; } +/* alu instructions that can ony exits once per group */ +static int is_alu_once_inst(struct r600_bc_alu *alu) +{ + return !alu->is_op3 && ( + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT_UINT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE_UINT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE_INT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT_INT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE_INT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE_INT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_UINT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_UINT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_INV || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_POP || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_CLR || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_RESTORE || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_PUSH || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_PUSH || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_PUSH || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_PUSH || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_INT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_INT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_INT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_INT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_PUSH_INT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_PUSH_INT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_PUSH_INT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_PUSH_INT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETLT_PUSH_INT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETLE_PUSH_INT); +} + +static int is_alu_reduction_inst(struct r600_bc_alu *alu) +{ + return !alu->is_op3 && ( + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4 || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4_IEEE || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX4); +} + +static int is_alu_mova_inst(struct r600_bc_alu *alu) +{ + return !alu->is_op3 && ( + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_FLOOR || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT); +} + +/* alu instructions that can only execute on the vector unit */ +static int is_alu_vec_unit_inst(struct r600_bc_alu *alu) +{ + return is_alu_reduction_inst(alu) || + is_alu_mova_inst(alu); +} + +/* alu instructions that can only execute on the trans unit */ +static int is_alu_trans_unit_inst(struct r600_bc_alu *alu) +{ + if(!alu->is_op3) + return alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ASHR_INT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INT_TO_FLT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHL_INT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHR_INT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_INT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_INT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_UINT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_INT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_UINT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_UINT_TO_FLT || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_CLAMPED || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_FF || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_CLAMPED || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_FF || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN || + alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SQRT_IEEE; + else + return alu->inst == V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT || + alu->inst == V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT_D2 || + alu->inst == V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT_M2 || + alu->inst == V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT_M4; +} + +/* alu instructions that can execute on any unit */ +static int is_alu_any_unit_inst(struct r600_bc_alu *alu) +{ + return !is_alu_vec_unit_inst(alu) && + !is_alu_trans_unit_inst(alu); +} + +static int assign_alu_units(struct r600_bc_alu *alu_first, struct r600_bc_alu *assignment[5]) +{ + struct r600_bc_alu *alu; + unsigned i, chan, trans; + + for (i = 0; i < 5; i++) + assignment[i] = NULL; + + for (alu = alu_first; alu; alu = container_of(alu->list.next, alu, list)) { + chan = alu->dst.chan; + if (is_alu_trans_unit_inst(alu)) + trans = 1; + else if (is_alu_vec_unit_inst(alu)) + trans = 0; + else if (assignment[chan]) + trans = 1; // assume ALU_INST_PREFER_VECTOR + else + trans = 0; + + if (trans) { + if (assignment[4]) { + assert(0); //ALU.Trans has already been allocated + return -1; + } + assignment[4] = alu; + } else { + if (assignment[chan]) { + assert(0); //ALU.chan has already been allocated + return -1; + } + assignment[chan] = alu; + } + + if (alu->last) + break; + } + return 0; +} + const unsigned bank_swizzle_vec[8] = {SQ_ALU_VEC_210, //000 SQ_ALU_VEC_120, //001 SQ_ALU_VEC_102, //010 @@ -392,25 +537,30 @@ static int check_vector(struct r600_bc *bc, struct r600_bc_alu *alu) static int check_and_set_bank_swizzle(struct r600_bc *bc, struct r600_bc_alu *alu_first) { - struct r600_bc_alu *alu = NULL; - int num_instr = 1; + struct r600_bc_alu *assignment[5]; + int i, r; - init_gpr(alu_first); + r = init_gpr(alu_first); + if (r) + return r; - LIST_FOR_EACH_ENTRY(alu, &alu_first->bs_list, bs_list) { - num_instr++; - } + r = assign_alu_units(alu_first, assignment); + if (r) + return r; - if (num_instr == 1) { - check_scalar(bc, alu_first); - - } else { -/* check_read_slots(bc, bc->cf_last->curr_bs_head);*/ - check_vector(bc, alu_first); - LIST_FOR_EACH_ENTRY(alu, &alu_first->bs_list, bs_list) { - check_vector(bc, alu); + for (i = 0; i < 4; i++) + if (assignment[i]) { + r = check_vector(bc, assignment[i]); + if (r) + return r; } + + if (assignment[4]) { + r = check_scalar(bc, assignment[4]); + if (r) + return r; } + return 0; } @@ -611,7 +761,9 @@ int r600_bc_add_alu_type(struct r600_bc *bc, const struct r600_bc_alu *alu, int /* process cur ALU instructions for bank swizzle */ if (nalu->last) { - check_and_set_bank_swizzle(bc, bc->cf_last->curr_bs_head); + r = check_and_set_bank_swizzle(bc, bc->cf_last->curr_bs_head); + if (r) + return r; bc->cf_last->curr_bs_head = NULL; } return 0; From a25b91c2c2118741389f418a66de7ca145b8600b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 18 Dec 2010 17:56:36 +0100 Subject: [PATCH 091/164] r600g: rework bank swizzle code --- src/gallium/drivers/r600/r600_asm.c | 377 ++++++++++++++-------------- src/gallium/drivers/r600/r600_asm.h | 4 - 2 files changed, 186 insertions(+), 195 deletions(-) diff --git a/src/gallium/drivers/r600/r600_asm.c b/src/gallium/drivers/r600/r600_asm.c index b0567dd55de..4ceb1d71a0a 100644 --- a/src/gallium/drivers/r600/r600_asm.c +++ b/src/gallium/drivers/r600/r600_asm.c @@ -32,6 +32,9 @@ #include "r600_formats.h" #include "r600d.h" +#define NUM_OF_CYCLES 3 +#define NUM_OF_COMPONENTS 4 + static inline unsigned int r600_bc_get_num_operands(struct r600_bc_alu *alu) { if(alu->is_op3) @@ -340,229 +343,221 @@ static int assign_alu_units(struct r600_bc_alu *alu_first, struct r600_bc_alu *a return 0; } -const unsigned bank_swizzle_vec[8] = {SQ_ALU_VEC_210, //000 - SQ_ALU_VEC_120, //001 - SQ_ALU_VEC_102, //010 +struct alu_bank_swizzle { + int hw_gpr[NUM_OF_CYCLES][NUM_OF_COMPONENTS]; + int hw_cfile_addr[4]; + int hw_cfile_elem[4]; +}; - SQ_ALU_VEC_201, //011 - SQ_ALU_VEC_012, //100 - SQ_ALU_VEC_021, //101 +const unsigned cycle_for_bank_swizzle_vec[][3] = { + [SQ_ALU_VEC_012] = { 0, 1, 2 }, + [SQ_ALU_VEC_021] = { 0, 2, 1 }, + [SQ_ALU_VEC_120] = { 1, 2, 0 }, + [SQ_ALU_VEC_102] = { 1, 0, 2 }, + [SQ_ALU_VEC_201] = { 2, 0, 1 }, + [SQ_ALU_VEC_210] = { 2, 1, 0 } +}; - SQ_ALU_VEC_012, //110 - SQ_ALU_VEC_012}; //111 +const unsigned cycle_for_bank_swizzle_scl[][3] = { + [SQ_ALU_SCL_210] = { 2, 1, 0 }, + [SQ_ALU_SCL_122] = { 1, 2, 2 }, + [SQ_ALU_SCL_212] = { 2, 1, 2 }, + [SQ_ALU_SCL_221] = { 2, 2, 1 } +}; -const unsigned bank_swizzle_scl[8] = {SQ_ALU_SCL_210, //000 - SQ_ALU_SCL_122, //001 - SQ_ALU_SCL_122, //010 - - SQ_ALU_SCL_221, //011 - SQ_ALU_SCL_212, //100 - SQ_ALU_SCL_122, //101 - - SQ_ALU_SCL_122, //110 - SQ_ALU_SCL_122}; //111 - -static int init_gpr(struct r600_bc_alu *alu) +static void init_bank_swizzle(struct alu_bank_swizzle *bs) { - int cycle, component; + int i, cycle, component; /* set up gpr use */ for (cycle = 0; cycle < NUM_OF_CYCLES; cycle++) for (component = 0; component < NUM_OF_COMPONENTS; component++) - alu->hw_gpr[cycle][component] = -1; - return 0; + bs->hw_gpr[cycle][component] = -1; + for (i = 0; i < 4; i++) + bs->hw_cfile_addr[i] = -1; + for (i = 0; i < 4; i++) + bs->hw_cfile_elem[i] = -1; } - -#if 0 -static int reserve_gpr(struct r600_bc_alu *alu, unsigned sel, unsigned chan, unsigned cycle) + +static int reserve_gpr(struct alu_bank_swizzle *bs, unsigned sel, unsigned chan, unsigned cycle) { - if (alu->hw_gpr[cycle][chan] < 0) - alu->hw_gpr[cycle][chan] = sel; - else if (alu->hw_gpr[cycle][chan] != (int)sel) { - R600_ERR("Another scalar operation has already used GPR read port for channel\n"); + if (bs->hw_gpr[cycle][chan] == -1) + bs->hw_gpr[cycle][chan] = sel; + else if (bs->hw_gpr[cycle][chan] != (int)sel) { + // Another scalar operation has already used GPR read port for channel return -1; } return 0; } - -static int cycle_for_scalar_bank_swizzle(const int swiz, const int sel, unsigned *p_cycle) + +static int reserve_cfile(struct alu_bank_swizzle *bs, unsigned sel, unsigned chan) { - int table[3]; - int ret = 0; - switch (swiz) { - case SQ_ALU_SCL_210: - table[0] = 2; table[1] = 1; table[2] = 0; - *p_cycle = table[sel]; - break; - case SQ_ALU_SCL_122: - table[0] = 1; table[1] = 2; table[2] = 2; - *p_cycle = table[sel]; - break; - case SQ_ALU_SCL_212: - table[0] = 2; table[1] = 1; table[2] = 2; - *p_cycle = table[sel]; - break; - case SQ_ALU_SCL_221: - table[0] = 2; table[1] = 2; table[2] = 1; - *p_cycle = table[sel]; - break; - break; - default: - R600_ERR("bad scalar bank swizzle value\n"); - ret = -1; - break; + int res, resmatch = -1, resempty = -1; + for (res = 3; res >= 0; --res) { + if (bs->hw_cfile_addr[res] == -1) + resempty = res; + else if (bs->hw_cfile_addr[res] == sel && + bs->hw_cfile_elem[res] == chan) + resmatch = res; } - return ret; -} - -static int cycle_for_vector_bank_swizzle(const int swiz, const int sel, unsigned *p_cycle) -{ - int table[3]; - int ret; - - switch (swiz) { - case SQ_ALU_VEC_012: - table[0] = 0; table[1] = 1; table[2] = 2; - *p_cycle = table[sel]; - break; - case SQ_ALU_VEC_021: - table[0] = 0; table[1] = 2; table[2] = 1; - *p_cycle = table[sel]; - break; - case SQ_ALU_VEC_120: - table[0] = 1; table[1] = 2; table[2] = 0; - *p_cycle = table[sel]; - break; - case SQ_ALU_VEC_102: - table[0] = 1; table[1] = 0; table[2] = 2; - *p_cycle = table[sel]; - break; - case SQ_ALU_VEC_201: - table[0] = 2; table[1] = 0; table[2] = 1; - *p_cycle = table[sel]; - break; - case SQ_ALU_VEC_210: - table[0] = 2; table[1] = 1; table[2] = 0; - *p_cycle = table[sel]; - break; - default: - R600_ERR("bad vector bank swizzle value\n"); - ret = -1; - break; - } - return ret; -} - - - -static void update_chan_counter(struct r600_bc_alu *alu, int *chan_counter) -{ - int num_src; - int i; - int channel_swizzle; - - num_src = r600_bc_get_num_operands(alu); - - for (i = 0; i < num_src; i++) { - channel_swizzle = alu->src[i].chan; - if ((alu->src[i].sel > 0 && alu->src[i].sel < 128) && channel_swizzle <= 3) - chan_counter[channel_swizzle]++; - } -} - -/* we need something like this I think - but this is bogus */ -int check_read_slots(struct r600_bc *bc, struct r600_bc_alu *alu_first) -{ - struct r600_bc_alu *alu; - int chan_counter[4] = { 0 }; - - update_chan_counter(alu_first, chan_counter); - - LIST_FOR_EACH_ENTRY(alu, &alu_first->bs_list, bs_list) { - update_chan_counter(alu, chan_counter); - } - - if (chan_counter[0] > 3 || - chan_counter[1] > 3 || - chan_counter[2] > 3 || - chan_counter[3] > 3) { - R600_ERR("needed to split instruction for input ran out of banks %x %d %d %d %d\n", - alu_first->inst, chan_counter[0], chan_counter[1], chan_counter[2], chan_counter[3]); + if (resmatch != -1) + return 0; // Read for this scalar element already reserved, nothing to do here. + else if (resempty != -1) { + bs->hw_cfile_addr[resempty] = sel; + bs->hw_cfile_elem[resempty] = chan; + } else { + // All cfile read ports are used, cannot reference vector element return -1; } - return 0; + return 0; +} + +static int is_gpr(unsigned sel) +{ + return (sel >= 0 && sel <= 127); } -#endif /* CB constants start at 512, and get translated to a kcache index when ALU * clauses are constructed. Note that we handle kcache constants the same way * as (the now gone) cfile constants, is that really required? */ +static int is_cfile(unsigned sel) +{ + return (sel > 255 && sel < 512) || + (sel > 511 && sel < 4607) || // Kcache before translate + (sel > 127 && sel < 192); // Kcache after translate +} + static int is_const(int sel) { - if (sel > 511 && sel < 4607) - return 1; - return 0; + return is_cfile(sel) || + (sel >= V_SQ_ALU_SRC_0 && + sel <= V_SQ_ALU_SRC_LITERAL); } - -static int check_scalar(struct r600_bc *bc, struct r600_bc_alu *alu) + +static int check_vector(struct r600_bc_alu *alu, struct alu_bank_swizzle *bs, int bank_swizzle) { - unsigned swizzle_key; - - if (alu->bank_swizzle_force) { - alu->bank_swizzle = alu->bank_swizzle_force; - return 0; - } - swizzle_key = (is_const(alu->src[0].sel) ? 4 : 0 ) + - (is_const(alu->src[1].sel) ? 2 : 0 ) + - (is_const(alu->src[2].sel) ? 1 : 0 ); - - alu->bank_swizzle = bank_swizzle_scl[swizzle_key]; - return 0; -} - -static int check_vector(struct r600_bc *bc, struct r600_bc_alu *alu) -{ - unsigned swizzle_key; - - if (alu->bank_swizzle_force) { - alu->bank_swizzle = alu->bank_swizzle_force; - return 0; - } - swizzle_key = (is_const(alu->src[0].sel) ? 4 : 0 ) + - (is_const(alu->src[1].sel) ? 2 : 0 ) + - (is_const(alu->src[2].sel) ? 1 : 0 ); - - alu->bank_swizzle = bank_swizzle_vec[swizzle_key]; - return 0; -} - -static int check_and_set_bank_swizzle(struct r600_bc *bc, struct r600_bc_alu *alu_first) -{ - struct r600_bc_alu *assignment[5]; - int i, r; - - r = init_gpr(alu_first); - if (r) - return r; - - r = assign_alu_units(alu_first, assignment); - if (r) - return r; - - for (i = 0; i < 4; i++) - if (assignment[i]) { - r = check_vector(bc, assignment[i]); + int r, src, num_src, sel, elem, cycle; + + num_src = r600_bc_get_num_operands(alu); + for (src = 0; src < num_src; src++) { + sel = alu->src[src].sel; + elem = alu->src[src].chan; + if (is_gpr(sel)) { + cycle = cycle_for_bank_swizzle_vec[bank_swizzle][src]; + if (src == 1 && sel == alu->src[0].sel && elem == alu->src[0].chan) + // Nothing to do; special-case optimization, + // second source uses first source’s reservation + continue; + else { + r = reserve_gpr(bs, sel, elem, cycle); + if (r) + return r; + } + } else if (is_cfile(sel)) { + r = reserve_cfile(bs, sel, elem); if (r) return r; } - - if (assignment[4]) { - r = check_scalar(bc, assignment[4]); - if (r) - return r; + // No restrictions on PV, PS, literal or special constants } - return 0; } + +static int check_scalar(struct r600_bc_alu *alu, struct alu_bank_swizzle *bs, int bank_swizzle) +{ + int r, src, num_src, const_count, sel, elem, cycle; + + num_src = r600_bc_get_num_operands(alu); + for (const_count = 0, src = 0; src < num_src; ++src) { + sel = alu->src[src].sel; + elem = alu->src[src].chan; + if (is_const(sel)) { // Any constant, including literal and inline constants + if (const_count >= 2) + // More than two references to a constant in + // transcendental operation. + return -1; + else + const_count++; + } + if (is_cfile(sel)) { + r = reserve_cfile(bs, sel, elem); + if (r) + return r; + } + } + for (src = 0; src < num_src; ++src) { + sel = alu->src[src].sel; + elem = alu->src[src].chan; + if (is_gpr(sel)) { + cycle = cycle_for_bank_swizzle_scl[bank_swizzle][src]; + if (cycle < const_count) + // Cycle for GPR load conflicts with + // constant load in transcendental operation. + return -1; + r = reserve_gpr(bs, sel, elem, cycle); + if (r) + return r; + } + // Constants already processed + // No restrictions on PV, PS + } + return 0; +} + +static int check_and_set_bank_swizzle(struct r600_bc *bc, struct r600_bc_alu *alu_first) +{ + struct r600_bc_alu *assignment[5]; + struct alu_bank_swizzle bs; + int bank_swizzle[5]; + int i, r; + + r = assign_alu_units(alu_first, assignment); + if (r) + return r; + + if(alu_first->bank_swizzle_force) { + for (i = 0; i < 5; i++) + if (assignment[i]) + assignment[i]->bank_swizzle = assignment[i]->bank_swizzle_force; + return 0; + } + + // just check every possible combination of bank swizzle + // not very efficent, but works on the first try in most of the cases + for (i = 0; i < 4; i++) + bank_swizzle[i] = SQ_ALU_VEC_012; + bank_swizzle[4] = SQ_ALU_SCL_210; + while(bank_swizzle[4] <= SQ_ALU_SCL_221) { + init_bank_swizzle(&bs); + for (i = 0; i < 4; i++) { + if (assignment[i]) { + r = check_vector(assignment[i], &bs, bank_swizzle[i]); + if (r) + break; + } + } + if (!r && assignment[4]) { + r = check_scalar(assignment[4], &bs, bank_swizzle[4]); + } + if (!r) { + for (i = 0; i < 5; i++) { + if (assignment[i]) + assignment[i]->bank_swizzle = bank_swizzle[i]; + } + return 0; + } + + for (i = 0; i < 5; i++) { + bank_swizzle[i]++; + if (bank_swizzle[i] <= SQ_ALU_VEC_210) + break; + else + bank_swizzle[i] = SQ_ALU_VEC_012; + } + } + + // couldn't find a working swizzle + return -1; +} /* This code handles kcache lines as single blocks of 32 constants. We could * probably do slightly better by recognizing that we actually have two diff --git a/src/gallium/drivers/r600/r600_asm.h b/src/gallium/drivers/r600/r600_asm.h index 4763ce03ec4..a9123299f1e 100644 --- a/src/gallium/drivers/r600/r600_asm.h +++ b/src/gallium/drivers/r600/r600_asm.h @@ -25,9 +25,6 @@ #include "util/u_double_list.h" -#define NUM_OF_CYCLES 3 -#define NUM_OF_COMPONENTS 4 - struct r600_vertex_element; struct r600_pipe_context; @@ -61,7 +58,6 @@ struct r600_bc_alu { unsigned bank_swizzle; unsigned bank_swizzle_force; u32 value[4]; - int hw_gpr[NUM_OF_CYCLES][NUM_OF_COMPONENTS]; unsigned omod; }; From 0448f73f06b92dfd04e553147cac0e240dbabbdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 13 Jan 2011 21:29:47 +0100 Subject: [PATCH 092/164] r600g: add missing RECIPSQRT_CLAMPED to r600_bc_get_num_operands --- src/gallium/drivers/r600/r600_asm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gallium/drivers/r600/r600_asm.c b/src/gallium/drivers/r600/r600_asm.c index 4ceb1d71a0a..9091317adac 100644 --- a/src/gallium/drivers/r600/r600_asm.c +++ b/src/gallium/drivers/r600/r600_asm.c @@ -73,6 +73,7 @@ static inline unsigned int r600_bc_get_num_operands(struct r600_bc_alu *alu) case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED: case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE: case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_CLAMPED: case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE: case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT: case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN: From e1bc68b0140fef465cda26b74602aeb1cbcfdafc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fonseca?= Date: Thu, 13 Jan 2011 20:52:01 +0000 Subject: [PATCH 093/164] scons: Fix cross-compilation. Hairy stuff. Don't know how to do it better though. --- SConstruct | 33 ++++++++++++++++++++++ common.py | 26 +++++++++-------- src/SConscript | 3 ++ src/glsl/SConscript | 69 +++++++++++++++++++++++++-------------------- 4 files changed, 89 insertions(+), 42 deletions(-) diff --git a/SConstruct b/SConstruct index 8880d851e64..368ad83edf3 100644 --- a/SConstruct +++ b/SConstruct @@ -118,6 +118,39 @@ if env['platform'] in ('posix', 'linux', 'freebsd', 'darwin'): Export('env') +####################################################################### +# Invoke host SConscripts +# +# For things that are meant to be run on the native host build machine, instead +# of the target machine. +# + +# Create host environent +if env['platform'] != common.host_platform: + host_env = Environment( + options = opts, + # no tool used + tools = [], + toolpath = ['#scons'], + ENV = os.environ, + ) + + # Override options + host_env['platform'] = common.host_platform + host_env['machine'] = common.host_machine + host_env['toolchain'] = 'default' + host_env['llvm'] = False + + host_env.Tool('gallium') + + SConscript( + 'src/glsl/SConscript', + variant_dir = host_env['build_dir'], + duplicate = 0, # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html + exports={'env':host_env}, + ) + + ####################################################################### # Invoke SConscripts diff --git a/common.py b/common.py index 78e2d0fb24f..76184d577a3 100644 --- a/common.py +++ b/common.py @@ -19,17 +19,17 @@ _platform_map = { 'win32': 'windows', } -default_platform = sys.platform -default_platform = _platform_map.get(default_platform, default_platform) +host_platform = sys.platform +host_platform = _platform_map.get(host_platform, host_platform) # Search sys.argv[] for a "platform=foo" argument since we don't have # an 'env' variable at this point. if 'platform' in SCons.Script.ARGUMENTS: - selected_platform = SCons.Script.ARGUMENTS['platform'] + target_platform = SCons.Script.ARGUMENTS['platform'] else: - selected_platform = default_platform + target_platform = host_platform -cross_compiling = selected_platform != default_platform +cross_compiling = target_platform != host_platform _machine_map = { 'x86': 'x86', @@ -42,15 +42,17 @@ _machine_map = { } -# find default_machine value +# find host_machine value if 'PROCESSOR_ARCHITECTURE' in os.environ: - default_machine = os.environ['PROCESSOR_ARCHITECTURE'] + host_machine = os.environ['PROCESSOR_ARCHITECTURE'] else: - default_machine = _platform.machine() -default_machine = _machine_map.get(default_machine, 'generic') + host_machine = _platform.machine() +host_machine = _machine_map.get(host_machine, 'generic') + +default_machine = host_machine default_toolchain = 'default' -if selected_platform == 'windows' and cross_compiling: +if target_platform == 'windows' and cross_compiling: default_machine = 'x86' default_toolchain = 'crossmingw' @@ -61,7 +63,7 @@ if 'LLVM' in os.environ: else: default_llvm = 'no' try: - if selected_platform != 'windows' and \ + if target_platform != 'windows' and \ subprocess.call(['llvm-config', '--version'], stdout=subprocess.PIPE) == 0: default_llvm = 'yes' except: @@ -85,7 +87,7 @@ def AddOptions(opts): opts.Add(BoolOption('quiet', 'quiet command lines', 'yes')) opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine, allowed_values=('generic', 'ppc', 'x86', 'x86_64'))) - opts.Add(EnumOption('platform', 'target platform', default_platform, + opts.Add(EnumOption('platform', 'target platform', host_platform, allowed_values=('linux', 'cell', 'windows', 'winddk', 'wince', 'darwin', 'embedded', 'cygwin', 'sunos5', 'freebsd8'))) opts.Add('toolchain', 'compiler toolchain', default_toolchain) opts.Add(BoolOption('llvm', 'use LLVM', default_llvm)) diff --git a/src/SConscript b/src/SConscript index 38137ee9028..201812c5ac3 100644 --- a/src/SConscript +++ b/src/SConscript @@ -3,6 +3,9 @@ Import('*') if env['platform'] == 'windows': SConscript('getopt/SConscript') SConscript('talloc/SConscript') +else: + talloc = 'talloc' + Export('talloc') SConscript('glsl/SConscript') SConscript('mapi/glapi/SConscript') diff --git a/src/glsl/SConscript b/src/glsl/SConscript index a22fceb75c7..88a83fdb6fa 100644 --- a/src/glsl/SConscript +++ b/src/glsl/SConscript @@ -9,6 +9,7 @@ env = env.Clone() env.Prepend(CPPPATH = [ '#src/mapi', '#src/mesa', + '#src/glsl', ]) if env['platform'] == 'windows': @@ -78,46 +79,54 @@ sources = [ 'opt_tree_grafting.cpp', 's_expression.cpp', 'strtod.c', -] +] -if env['msvc']: - env.Prepend(CPPPATH = ['#/src/getopt']) - env.PrependUnique(LIBS = [getopt]) -if env['platform'] == 'windows': - env.Prepend(LIBS = [talloc]) -else: - env.Prepend(LIBS = ['talloc']) +if env['platform'] == common.host_platform: + if env['msvc']: + env.Prepend(CPPPATH = ['#/src/getopt']) + env.PrependUnique(LIBS = [getopt]) -env.Append(CPPPATH = ['#/src/glsl']) + if env['platform'] == 'windows': + env.Prepend(CPPPATH = ['#src/talloc']) + env.Prepend(LIBS = [talloc]) + else: + env.Prepend(LIBS = ['talloc']) -builtin_compiler = env.Program( - target = 'builtin_compiler', - source = sources + ['main.cpp', 'builtin_stubs.cpp', - '#src/mesa/program/hash_table.c', - '#src/mesa/program/symbol_table.c'], -) + builtin_compiler = env.Program( + target = 'builtin_compiler', + source = sources + ['main.cpp', 'builtin_stubs.cpp', + '#src/mesa/program/hash_table.c', + '#src/mesa/program/symbol_table.c'], + ) -env.CodeGenerate( - target = 'builtin_function.cpp', - script = 'builtins/tools/generate_builtins.py', - source = builtin_compiler, - command = python_cmd + ' $SCRIPT $SOURCE > $TARGET' -) + builtin_glsl_function = env.CodeGenerate( + target = 'builtin_function.cpp', + script = 'builtins/tools/generate_builtins.py', + source = builtin_compiler, + command = python_cmd + ' $SCRIPT $SOURCE > $TARGET' + ) -env.Depends('builtin_function.cpp', ['builtins/tools/generate_builtins.py', 'builtins/tools/texture_builtins.py'] + Glob('builtins/ir/*')) + env.Depends(builtin_glsl_function, ['builtins/tools/generate_builtins.py', 'builtins/tools/texture_builtins.py'] + Glob('builtins/ir/*')) -if env['msvc']: - # There is no LD_LIBRARY_PATH equivalent on Windows. We need to ensure - # talloc.dll is on the same dir as builtin_function. - talloc_dll_src = talloc.dir.File('talloc.dll') - talloc_dll_dst = builtin_compiler[0].dir.File('talloc.dll') - talloc_dll = env.Command(talloc_dll_dst, talloc_dll_src, Copy(talloc_dll_dst, talloc_dll_src)) - env.Depends('builtin_function.cpp', talloc_dll) + if env['msvc']: + # There is no LD_LIBRARY_PATH equivalent on Windows. We need to ensure + # talloc.dll is on the same dir as builtin_function. + talloc_dll_src = talloc.dir.File('talloc.dll') + talloc_dll_dst = builtin_compiler[0].dir.File('talloc.dll') + talloc_dll = env.Command(talloc_dll_dst, talloc_dll_src, Copy(talloc_dll_dst, talloc_dll_src)) + env.Depends('builtin_function.cpp', talloc_dll) + + Export('builtin_glsl_function') + + if common.cross_compiling: + Return() + +sources += builtin_glsl_function glsl = env.ConvenienceLibrary( target = 'glsl', - source = sources + [ 'builtin_function.cpp' ], + source = sources, ) Export('glsl') From 82c4b4f88af97395a3d1b01e1998ec828cd5d305 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Fri, 7 Jan 2011 16:53:07 -0800 Subject: [PATCH 094/164] glsl: Allow 'in' and 'out' when 'layout' is also available All of the extensions that add the 'layout' keyword also enable (and required) the use of 'in' and 'out' with shader globals. This is related to (piglit) bugzilla #31804. NOTE: This is a candidate for the 7.9 and 7.10 branches. --- src/glsl/ast_to_hir.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp index a833be18f31..d70978c838b 100644 --- a/src/glsl/ast_to_hir.cpp +++ b/src/glsl/ast_to_hir.cpp @@ -2088,9 +2088,12 @@ ast_declarator_list::hir(exec_list *instructions, * * Local variables can only use the qualifier const." * - * This is relaxed in GLSL 1.30. + * This is relaxed in GLSL 1.30. It is also relaxed by any extension + * that adds the 'layout' keyword. */ - if (state->language_version < 130) { + if ((state->language_version < 130) + && !state->ARB_explicit_attrib_location_enable + && !state->ARB_fragment_coord_conventions_enable) { if (this->type->qualifier.flags.q.out) { _mesa_glsl_error(& loc, state, "`out' qualifier in declaration of `%s' " From 4bcff0c19091c7df2b2e0bafe58addb5bae28f1a Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Fri, 7 Jan 2011 16:53:59 -0800 Subject: [PATCH 095/164] glsl: Emit errors or warnings when 'layout' is used with 'attribute' or 'varying' The specs that add 'layout' require the use of 'in' or 'out'. However, a number of implementations, including Mesa, shipped several of these extensions allowing the use of 'varying' and 'attribute'. For these extensions only a warning is emitted. This differs from the behavior of Mesa 7.10. Mesa 7.10 would only accept 'attribute' with 'layout(location)'. This behavior was clearly wrong. Rather than carrying the broken behavior forward, we're just doing the correct thing. This is related to (piglit) bugzilla #31804. NOTE: This is a candidate for the 7.9 and 7.10 branches. --- src/glsl/ast_to_hir.cpp | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp index d70978c838b..365a6e2676f 100644 --- a/src/glsl/ast_to_hir.cpp +++ b/src/glsl/ast_to_hir.cpp @@ -1957,6 +1957,52 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual, } } + /* Does the declaration use the 'layout' keyword? + */ + const bool uses_layout = qual->flags.q.pixel_center_integer + || qual->flags.q.origin_upper_left + || qual->flags.q.explicit_location; + + /* Does the declaration use the deprecated 'attribute' or 'varying' + * keywords? + */ + const bool uses_deprecated_qualifier = qual->flags.q.attribute + || qual->flags.q.varying; + + /* Is the 'layout' keyword used with parameters that allow relaxed checking. + * Many implementations of GL_ARB_fragment_coord_conventions_enable and some + * implementations (only Mesa?) GL_ARB_explicit_attrib_location_enable + * allowed the layout qualifier to be used with 'varying' and 'attribute'. + * These extensions and all following extensions that add the 'layout' + * keyword have been modified to require the use of 'in' or 'out'. + * + * The following extension do not allow the deprecated keywords: + * + * GL_AMD_conservative_depth + * GL_ARB_gpu_shader5 + * GL_ARB_separate_shader_objects + * GL_ARB_tesselation_shader + * GL_ARB_transform_feedback3 + * GL_ARB_uniform_buffer_object + * + * It is unknown whether GL_EXT_shader_image_load_store or GL_NV_gpu_shader5 + * allow layout with the deprecated keywords. + */ + const bool relaxed_layout_qualifier_checking = + state->ARB_fragment_coord_conventions_enable; + + if (uses_layout && uses_deprecated_qualifier) { + if (relaxed_layout_qualifier_checking) { + _mesa_glsl_warning(loc, state, + "`layout' qualifier may not be used with " + "`attribute' or `varying'"); + } else { + _mesa_glsl_error(loc, state, + "`layout' qualifier may not be used with " + "`attribute' or `varying'"); + } + } + if (var->type->is_array() && state->language_version != 110) { var->array_lvalue = true; } From eea1d8199b376f37027c14669e0bdf991a22872d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 18 Dec 2010 21:32:16 +0100 Subject: [PATCH 096/164] r600g: implement replacing gpr with pv and ps --- src/gallium/drivers/r600/r600_asm.c | 64 +++++++++++++++++++++++++++-- src/gallium/drivers/r600/r600_asm.h | 2 +- src/gallium/drivers/r600/r600_sq.h | 2 + 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/src/gallium/drivers/r600/r600_asm.c b/src/gallium/drivers/r600/r600_asm.c index 9091317adac..e2d52c3a46b 100644 --- a/src/gallium/drivers/r600/r600_asm.c +++ b/src/gallium/drivers/r600/r600_asm.c @@ -108,7 +108,6 @@ static struct r600_bc_alu *r600_bc_alu(void) if (alu == NULL) return NULL; LIST_INITHEAD(&alu->list); - LIST_INITHEAD(&alu->bs_list); return alu; } @@ -560,6 +559,63 @@ static int check_and_set_bank_swizzle(struct r600_bc *bc, struct r600_bc_alu *al return -1; } +static int replace_gpr_with_pv_ps(struct r600_bc_alu *alu_first, struct r600_bc_alu *alu_prev) +{ + struct r600_bc_alu *slots[5]; + int gpr[5], chan[5]; + int i, j, r, src, num_src; + + r = assign_alu_units(alu_prev, slots); + if (r) + return r; + + for (i = 0; i < 5; ++i) { + if(slots[i] && slots[i]->dst.write && !slots[i]->dst.rel) { + gpr[i] = slots[i]->dst.sel; + if (is_alu_reduction_inst(slots[i])) + chan[i] = 0; + else + chan[i] = slots[i]->dst.chan; + } else + gpr[i] = -1; + + } + + r = assign_alu_units(alu_first, slots); + if (r) + return r; + + for (i = 0; i < 5; ++i) { + struct r600_bc_alu *alu = slots[i]; + if(!alu) + continue; + + num_src = r600_bc_get_num_operands(alu); + for (src = 0; src < num_src; ++src) { + if (!is_gpr(alu->src[src].sel) || alu->src[src].rel) + continue; + + if (alu->src[src].sel == gpr[4] && + alu->src[src].chan == chan[4]) { + alu->src[src].sel = V_SQ_ALU_SRC_PS; + alu->src[src].chan = 0; + continue; + } + + for (j = 0; j < 4; ++j) { + if (alu->src[src].sel == gpr[j] && + alu->src[src].chan == j) { + alu->src[src].sel = V_SQ_ALU_SRC_PV; + alu->src[src].chan = chan[j]; + break; + } + } + } + } + + return 0; +} + /* This code handles kcache lines as single blocks of 32 constants. We could * probably do slightly better by recognizing that we actually have two * consecutive lines of 16 constants, but the resulting code would also be @@ -718,9 +774,6 @@ int r600_bc_add_alu_type(struct r600_bc *bc, const struct r600_bc_alu *alu, int if (!bc->cf_last->curr_bs_head) { bc->cf_last->curr_bs_head = nalu; - LIST_INITHEAD(&nalu->bs_list); - } else { - LIST_ADDTAIL(&nalu->bs_list, &bc->cf_last->curr_bs_head->bs_list); } /* at most 128 slots, one add alu can add 4 slots + 4 constants(2 slots) * worst case */ @@ -757,9 +810,12 @@ int r600_bc_add_alu_type(struct r600_bc *bc, const struct r600_bc_alu *alu, int /* process cur ALU instructions for bank swizzle */ if (nalu->last) { + if (bc->cf_last->prev_bs_head) + replace_gpr_with_pv_ps(bc->cf_last->curr_bs_head, bc->cf_last->prev_bs_head); r = check_and_set_bank_swizzle(bc, bc->cf_last->curr_bs_head); if (r) return r; + bc->cf_last->prev_bs_head = bc->cf_last->curr_bs_head; bc->cf_last->curr_bs_head = NULL; } return 0; diff --git a/src/gallium/drivers/r600/r600_asm.h b/src/gallium/drivers/r600/r600_asm.h index a9123299f1e..2a046d1e88d 100644 --- a/src/gallium/drivers/r600/r600_asm.h +++ b/src/gallium/drivers/r600/r600_asm.h @@ -46,7 +46,6 @@ struct r600_bc_alu_dst { struct r600_bc_alu { struct list_head list; - struct list_head bs_list; /* bank swizzle list */ struct r600_bc_alu_src src[3]; struct r600_bc_alu_dst dst; unsigned inst; @@ -144,6 +143,7 @@ struct r600_bc_cf { struct list_head vtx; struct r600_bc_output output; struct r600_bc_alu *curr_bs_head; + struct r600_bc_alu *prev_bs_head; }; #define FC_NONE 0 diff --git a/src/gallium/drivers/r600/r600_sq.h b/src/gallium/drivers/r600/r600_sq.h index d812bfd1fed..56ed35e8b32 100644 --- a/src/gallium/drivers/r600/r600_sq.h +++ b/src/gallium/drivers/r600/r600_sq.h @@ -191,6 +191,8 @@ #define V_SQ_ALU_SRC_M_1_INT 0x000000FB #define V_SQ_ALU_SRC_0_5 0x000000FC #define V_SQ_ALU_SRC_LITERAL 0x000000FD +#define V_SQ_ALU_SRC_PV 0x000000FE +#define V_SQ_ALU_SRC_PS 0x000000FF #define V_SQ_ALU_SRC_PARAM_BASE 0x000001C0 #define S_SQ_ALU_WORD0_SRC0_REL(x) (((x) & 0x1) << 9) #define G_SQ_ALU_WORD0_SRC0_REL(x) (((x) >> 9) & 0x1) From d7342f6a81a0d13acb6486a24bffa8e5987d5410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 20 Dec 2010 22:09:09 +0100 Subject: [PATCH 097/164] r600g: merge alu groups --- src/gallium/drivers/r600/r600_asm.c | 186 ++++++++++++++++++++++------ src/gallium/drivers/r600/r600_asm.h | 1 + 2 files changed, 150 insertions(+), 37 deletions(-) diff --git a/src/gallium/drivers/r600/r600_asm.c b/src/gallium/drivers/r600/r600_asm.c index e2d52c3a46b..ca2bf93b0b8 100644 --- a/src/gallium/drivers/r600/r600_asm.c +++ b/src/gallium/drivers/r600/r600_asm.c @@ -312,7 +312,7 @@ static int assign_alu_units(struct r600_bc_alu *alu_first, struct r600_bc_alu *a for (i = 0; i < 5; i++) assignment[i] = NULL; - for (alu = alu_first; alu; alu = container_of(alu->list.next, alu, list)) { + for (alu = alu_first; alu; alu = LIST_ENTRY(struct r600_bc_alu, alu->list.next, list)) { chan = alu->dst.chan; if (is_alu_trans_unit_inst(alu)) trans = 1; @@ -502,24 +502,21 @@ static int check_scalar(struct r600_bc_alu *alu, struct alu_bank_swizzle *bs, in } return 0; } - -static int check_and_set_bank_swizzle(struct r600_bc *bc, struct r600_bc_alu *alu_first) + +static int check_and_set_bank_swizzle(struct r600_bc_alu *slots[5]) { - struct r600_bc_alu *assignment[5]; struct alu_bank_swizzle bs; int bank_swizzle[5]; - int i, r; + int i, r = 0, forced = 0; - r = assign_alu_units(alu_first, assignment); - if (r) - return r; - - if(alu_first->bank_swizzle_force) { - for (i = 0; i < 5; i++) - if (assignment[i]) - assignment[i]->bank_swizzle = assignment[i]->bank_swizzle_force; + for (i = 0; i < 5; i++) + if (slots[i] && slots[i]->bank_swizzle_force) { + slots[i]->bank_swizzle = slots[i]->bank_swizzle_force; + forced = 1; + } + + if (forced) return 0; - } // just check every possible combination of bank swizzle // not very efficent, but works on the first try in most of the cases @@ -529,19 +526,19 @@ static int check_and_set_bank_swizzle(struct r600_bc *bc, struct r600_bc_alu *al while(bank_swizzle[4] <= SQ_ALU_SCL_221) { init_bank_swizzle(&bs); for (i = 0; i < 4; i++) { - if (assignment[i]) { - r = check_vector(assignment[i], &bs, bank_swizzle[i]); + if (slots[i]) { + r = check_vector(slots[i], &bs, bank_swizzle[i]); if (r) break; } } - if (!r && assignment[4]) { - r = check_scalar(assignment[4], &bs, bank_swizzle[4]); + if (!r && slots[4]) { + r = check_scalar(slots[4], &bs, bank_swizzle[4]); } if (!r) { for (i = 0; i < 5; i++) { - if (assignment[i]) - assignment[i]->bank_swizzle = bank_swizzle[i]; + if (slots[i]) + slots[i]->bank_swizzle = bank_swizzle[i]; } return 0; } @@ -559,32 +556,27 @@ static int check_and_set_bank_swizzle(struct r600_bc *bc, struct r600_bc_alu *al return -1; } -static int replace_gpr_with_pv_ps(struct r600_bc_alu *alu_first, struct r600_bc_alu *alu_prev) +static int replace_gpr_with_pv_ps(struct r600_bc_alu *slots[5], struct r600_bc_alu *alu_prev) { - struct r600_bc_alu *slots[5]; + struct r600_bc_alu *prev[5]; int gpr[5], chan[5]; int i, j, r, src, num_src; - r = assign_alu_units(alu_prev, slots); + r = assign_alu_units(alu_prev, prev); if (r) return r; for (i = 0; i < 5; ++i) { - if(slots[i] && slots[i]->dst.write && !slots[i]->dst.rel) { - gpr[i] = slots[i]->dst.sel; - if (is_alu_reduction_inst(slots[i])) + if(prev[i] && prev[i]->dst.write && !prev[i]->dst.rel) { + gpr[i] = prev[i]->dst.sel; + if (is_alu_reduction_inst(prev[i])) chan[i] = 0; else - chan[i] = slots[i]->dst.chan; + chan[i] = prev[i]->dst.chan; } else - gpr[i] = -1; - + gpr[i] = -1; } - r = assign_alu_units(alu_first, slots); - if (r) - return r; - for (i = 0; i < 5; ++i) { struct r600_bc_alu *alu = slots[i]; if(!alu) @@ -616,6 +608,109 @@ static int replace_gpr_with_pv_ps(struct r600_bc_alu *alu_first, struct r600_bc_ return 0; } +static int merge_inst_groups(struct r600_bc *bc, struct r600_bc_alu *slots[5], struct r600_bc_alu *alu_prev) +{ + struct r600_bc_alu *prev[5]; + struct r600_bc_alu *result[5] = { NULL }; + int i, j, r, src, num_src; + int num_once_inst = 0; + + r = assign_alu_units(alu_prev, prev); + if (r) + return r; + + for (i = 0; i < 5; ++i) { + // TODO: we have literals? forget it! + if (prev[i] && prev[i]->nliteral) + return 0; + if (slots[i] && slots[i]->nliteral) + return 0; + + + // let's check used slots + if (prev[i] && !slots[i]) { + result[i] = prev[i]; + num_once_inst += is_alu_once_inst(prev[i]); + continue; + } else if (prev[i] && slots[i]) { + if (result[4] == NULL && prev[4] == NULL && slots[4] == NULL) { + // trans unit is still free try to use it + if (is_alu_any_unit_inst(slots[i])) { + result[i] = prev[i]; + result[4] = slots[i]; + } else if (is_alu_any_unit_inst(prev[i])) { + result[i] = slots[i]; + result[4] = prev[i]; + } else + return 0; + } else + return 0; + } else if(!slots[i]) { + continue; + } else + result[i] = slots[i]; + + // let's check source gprs + struct r600_bc_alu *alu = slots[i]; + num_once_inst += is_alu_once_inst(alu); + + num_src = r600_bc_get_num_operands(alu); + for (src = 0; src < num_src; ++src) { + // constants doesn't matter + if (!is_gpr(alu->src[src].sel)) + continue; + + for (j = 0; j < 5; ++j) { + if (!prev[j] || !prev[j]->dst.write) + continue; + + // if it's relative then we can't determin which gpr is really used + if (prev[j]->dst.chan == alu->src[src].chan && + (prev[j]->dst.sel == alu->src[src].sel || + prev[j]->dst.rel || alu->src[src].rel)) + return 0; + } + } + } + + /* more than one PRED_ or KILL_ ? */ + if (num_once_inst > 1) + return 0; + + /* check if the result can still be swizzlet */ + r = check_and_set_bank_swizzle(result); + if (r) + return 0; + + /* looks like everything worked out right, apply the changes */ + + /* sort instructions */ + for (i = 0; i < 5; ++i) { + slots[i] = result[i]; + if (result[i]) { + LIST_DEL(&result[i]->list); + result[i]->last = 0; + LIST_ADDTAIL(&result[i]->list, &bc->cf_last->alu); + } + } + + /* determine new last instruction */ + LIST_ENTRY(struct r600_bc_alu, bc->cf_last->alu.prev, list)->last = 1; + + /* determine new first instruction */ + for (i = 0; i < 5; ++i) { + if (result[i]) { + bc->cf_last->curr_bs_head = result[i]; + break; + } + } + + bc->cf_last->prev_bs_head = bc->cf_last->prev2_bs_head; + bc->cf_last->prev2_bs_head = NULL; + + return 0; +} + /* This code handles kcache lines as single blocks of 32 constants. We could * probably do slightly better by recognizing that we actually have two * consecutive lines of 16 constants, but the resulting code would also be @@ -775,7 +870,7 @@ int r600_bc_add_alu_type(struct r600_bc *bc, const struct r600_bc_alu *alu, int if (!bc->cf_last->curr_bs_head) { bc->cf_last->curr_bs_head = nalu; } - /* at most 128 slots, one add alu can add 4 slots + 4 constants(2 slots) + /* at most 128 slots, one add alu can add 5 slots + 4 constants(2 slots) * worst case */ if (nalu->last && (bc->cf_last->ndw >> 1) >= 120) { bc->force_add_cf = 1; @@ -810,11 +905,28 @@ int r600_bc_add_alu_type(struct r600_bc *bc, const struct r600_bc_alu *alu, int /* process cur ALU instructions for bank swizzle */ if (nalu->last) { - if (bc->cf_last->prev_bs_head) - replace_gpr_with_pv_ps(bc->cf_last->curr_bs_head, bc->cf_last->prev_bs_head); - r = check_and_set_bank_swizzle(bc, bc->cf_last->curr_bs_head); + struct r600_bc_alu *slots[5]; + r = assign_alu_units(bc->cf_last->curr_bs_head, slots); if (r) return r; + + if (bc->cf_last->prev_bs_head) { + r = merge_inst_groups(bc, slots, bc->cf_last->prev_bs_head); + if (r) + return r; + } + + if (bc->cf_last->prev_bs_head) { + r = replace_gpr_with_pv_ps(slots, bc->cf_last->prev_bs_head); + if (r) + return r; + } + + r = check_and_set_bank_swizzle(slots); + if (r) + return r; + + bc->cf_last->prev2_bs_head = bc->cf_last->prev_bs_head; bc->cf_last->prev_bs_head = bc->cf_last->curr_bs_head; bc->cf_last->curr_bs_head = NULL; } diff --git a/src/gallium/drivers/r600/r600_asm.h b/src/gallium/drivers/r600/r600_asm.h index 2a046d1e88d..570292e9fdc 100644 --- a/src/gallium/drivers/r600/r600_asm.h +++ b/src/gallium/drivers/r600/r600_asm.h @@ -144,6 +144,7 @@ struct r600_bc_cf { struct r600_bc_output output; struct r600_bc_alu *curr_bs_head; struct r600_bc_alu *prev_bs_head; + struct r600_bc_alu *prev2_bs_head; }; #define FC_NONE 0 From 96f8f8db7bcddec7ef0fce62cf0e23f1c2fb8c8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 22 Dec 2010 17:45:51 +0100 Subject: [PATCH 098/164] r600g: rework literal handling --- src/gallium/drivers/r600/r600_asm.c | 189 +++++++++++++-------- src/gallium/drivers/r600/r600_asm.h | 6 +- src/gallium/drivers/r600/r600_shader.c | 221 ++++--------------------- src/gallium/drivers/r600/r600_shader.h | 2 +- src/gallium/drivers/r600/r700_asm.c | 10 -- 5 files changed, 151 insertions(+), 277 deletions(-) diff --git a/src/gallium/drivers/r600/r600_asm.c b/src/gallium/drivers/r600/r600_asm.c index ca2bf93b0b8..e96236e06ee 100644 --- a/src/gallium/drivers/r600/r600_asm.c +++ b/src/gallium/drivers/r600/r600_asm.c @@ -608,10 +608,90 @@ static int replace_gpr_with_pv_ps(struct r600_bc_alu *slots[5], struct r600_bc_a return 0; } +void r600_bc_special_constants(u32 value, unsigned *sel, unsigned *neg) +{ + switch(value) { + case 0: + *sel = V_SQ_ALU_SRC_0; + break; + case 1: + *sel = V_SQ_ALU_SRC_1_INT; + break; + case -1: + *sel = V_SQ_ALU_SRC_M_1_INT; + break; + case 0x3F800000: // 1.0f + *sel = V_SQ_ALU_SRC_1; + break; + case 0x3F000000: // 0.5f + *sel = V_SQ_ALU_SRC_0_5; + break; + case 0xBF800000: // -1.0f + *sel = V_SQ_ALU_SRC_1; + *neg ^= 1; + break; + case 0xBF000000: // -0.5f + *sel = V_SQ_ALU_SRC_0_5; + *neg ^= 1; + break; + default: + *sel = V_SQ_ALU_SRC_LITERAL; + break; + } +} + +/* compute how many literal are needed */ +static int r600_bc_alu_nliterals(struct r600_bc_alu *alu, uint32_t literal[4], unsigned *nliteral) +{ + unsigned num_src = r600_bc_get_num_operands(alu); + unsigned i, j; + + for (i = 0; i < num_src; ++i) { + if (alu->src[i].sel == V_SQ_ALU_SRC_LITERAL) { + uint32_t value = alu->src[i].value[alu->src[i].chan]; + unsigned found = 0; + for (j = 0; j < *nliteral; ++j) { + if (literal[j] == value) { + found = 1; + break; + } + } + if (!found) { + if (*nliteral >= 4) + return -EINVAL; + literal[(*nliteral)++] = value; + } + } + } + return 0; +} + +static void r600_bc_alu_adjust_literals(struct r600_bc_alu *alu, uint32_t literal[4], unsigned nliteral) +{ + unsigned num_src = r600_bc_get_num_operands(alu); + unsigned i, j; + + for (i = 0; i < num_src; ++i) { + if (alu->src[i].sel == V_SQ_ALU_SRC_LITERAL) { + uint32_t value = alu->src[i].value[alu->src[i].chan]; + for (j = 0; j < nliteral; ++j) { + if (literal[j] == value) { + alu->src[i].chan = j; + break; + } + } + } + } +} + static int merge_inst_groups(struct r600_bc *bc, struct r600_bc_alu *slots[5], struct r600_bc_alu *alu_prev) { struct r600_bc_alu *prev[5]; struct r600_bc_alu *result[5] = { NULL }; + + uint32_t literal[4]; + unsigned nliteral = 0; + int i, j, r, src, num_src; int num_once_inst = 0; @@ -620,13 +700,12 @@ static int merge_inst_groups(struct r600_bc *bc, struct r600_bc_alu *slots[5], s return r; for (i = 0; i < 5; ++i) { - // TODO: we have literals? forget it! - if (prev[i] && prev[i]->nliteral) + /* check number of literals */ + if (prev[i] && r600_bc_alu_nliterals(prev[i], literal, &nliteral)) return 0; - if (slots[i] && slots[i]->nliteral) + if (slots[i] && r600_bc_alu_nliterals(slots[i], literal, &nliteral)) return 0; - // let's check used slots if (prev[i] && !slots[i]) { result[i] = prev[i]; @@ -834,7 +913,6 @@ int r600_bc_add_alu_type(struct r600_bc *bc, const struct r600_bc_alu *alu, int if (nalu == NULL) return -ENOMEM; memcpy(nalu, alu, sizeof(struct r600_bc_alu)); - nalu->nliteral = 0; if (bc->cf_last != NULL && bc->cf_last->inst != (type << 3)) { /* check if we could add it anyway */ @@ -880,20 +958,10 @@ int r600_bc_add_alu_type(struct r600_bc *bc, const struct r600_bc_alu *alu, int if (nalu->src[i].sel >= bc->ngpr && nalu->src[i].sel < 128) { bc->ngpr = nalu->src[i].sel + 1; } - /* compute how many literal are needed - * either 2 or 4 literals - */ - if (nalu->src[i].sel == 253) { - if (((nalu->src[i].chan + 2) & 0x6) > nalu->nliteral) { - nalu->nliteral = (nalu->src[i].chan + 2) & 0x6; - } - } - } - if (!LIST_IS_EMPTY(&bc->cf_last->alu)) { - lalu = LIST_ENTRY(struct r600_bc_alu, bc->cf_last->alu.prev, list); - if (!lalu->last && lalu->nliteral > nalu->nliteral) { - nalu->nliteral = lalu->nliteral; - } + if (nalu->src[i].sel == V_SQ_ALU_SRC_LITERAL) + r600_bc_special_constants( + nalu->src[i].value[nalu->src[i].chan], + &nalu->src[i].sel, &nalu->src[i].neg); } if (nalu->dst.sel >= bc->ngpr) { bc->ngpr = nalu->dst.sel + 1; @@ -938,46 +1006,6 @@ int r600_bc_add_alu(struct r600_bc *bc, const struct r600_bc_alu *alu) return r600_bc_add_alu_type(bc, alu, BC_INST(bc, V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU)); } -int r600_bc_add_literal(struct r600_bc *bc, const u32 *value) -{ - struct r600_bc_alu *alu; - - if (bc->cf_last == NULL) { - return 0; - } - if (bc->cf_last->inst == V_SQ_CF_WORD1_SQ_CF_INST_TEX) { - return 0; - } - /* all same on EG */ - if (bc->cf_last->inst == V_SQ_CF_WORD1_SQ_CF_INST_JUMP || - bc->cf_last->inst == V_SQ_CF_WORD1_SQ_CF_INST_ELSE || - bc->cf_last->inst == V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL || - bc->cf_last->inst == V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK || - bc->cf_last->inst == V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE || - bc->cf_last->inst == V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END || - bc->cf_last->inst == V_SQ_CF_WORD1_SQ_CF_INST_POP) { - return 0; - } - /* same on EG */ - if (((bc->cf_last->inst != (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU << 3)) && - (bc->cf_last->inst != (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER << 3)) && - (bc->cf_last->inst != (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER << 3)) && - (bc->cf_last->inst != (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE << 3))) || - LIST_IS_EMPTY(&bc->cf_last->alu)) { - R600_ERR("last CF is not ALU (%p)\n", bc->cf_last); - return -EINVAL; - } - alu = LIST_ENTRY(struct r600_bc_alu, bc->cf_last->alu.prev, list); - if (!alu->last || !alu->nliteral || alu->literal_added) { - return 0; - } - memcpy(alu->value, value, 4 * 4); - bc->cf_last->ndw += alu->nliteral; - bc->ndw += alu->nliteral; - alu->literal_added = 1; - return 0; -} - int r600_bc_add_vtx(struct r600_bc *bc, const struct r600_bc_vtx *vtx) { struct r600_bc_vtx *nvtx = r600_bc_vtx(); @@ -1134,8 +1162,6 @@ static int r600_bc_tex_build(struct r600_bc *bc, struct r600_bc_tex *tex, unsign /* r600 only, r700/eg bits in r700_asm.c */ static int r600_bc_alu_build(struct r600_bc *bc, struct r600_bc_alu *alu, unsigned id) { - unsigned i; - /* don't replace gpr by pv or ps for destination register */ bc->bytecode[id++] = S_SQ_ALU_WORD0_SRC0_SEL(alu->src[0].sel) | S_SQ_ALU_WORD0_SRC0_REL(alu->src[0].rel) | @@ -1172,14 +1198,6 @@ static int r600_bc_alu_build(struct r600_bc *bc, struct r600_bc_alu *alu, unsign S_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK(alu->predicate) | S_SQ_ALU_WORD1_OP2_UPDATE_PRED(alu->predicate); } - if (alu->last) { - if (alu->nliteral && !alu->literal_added) { - R600_ERR("Bug in ALU processing for instruction 0x%08x, literal not added correctly\n", alu->inst); - } - for (i = 0; i < alu->nliteral; i++) { - bc->bytecode[id++] = alu->value[i]; - } - } return 0; } @@ -1257,8 +1275,10 @@ int r600_bc_build(struct r600_bc *bc) struct r600_bc_alu *alu; struct r600_bc_vtx *vtx; struct r600_bc_tex *tex; + uint32_t literal[4]; + unsigned nliteral; unsigned addr; - int r; + int i, r; if (bc->callstack[0].max > 0) bc->nstack = ((bc->callstack[0].max + 3) >> 2) + 2; @@ -1275,6 +1295,16 @@ int r600_bc_build(struct r600_bc *bc) case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER << 3): case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER << 3): case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE << 3): + nliteral = 0; + LIST_FOR_EACH_ENTRY(alu, &cf->alu, list) { + r = r600_bc_alu_nliterals(alu, literal, &nliteral); + if (r) + return r; + if (alu->last) { + cf->ndw += align(nliteral, 2); + nliteral = 0; + } + } break; case V_SQ_CF_WORD1_SQ_CF_INST_TEX: case V_SQ_CF_WORD1_SQ_CF_INST_VTX: @@ -1323,7 +1353,12 @@ int r600_bc_build(struct r600_bc *bc) case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER << 3): case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER << 3): case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE << 3): + nliteral = 0; LIST_FOR_EACH_ENTRY(alu, &cf->alu, list) { + r = r600_bc_alu_nliterals(alu, literal, &nliteral); + if (r) + return r; + r600_bc_alu_adjust_literals(alu, literal, nliteral); switch(bc->chiprev) { case CHIPREV_R600: r = r600_bc_alu_build(bc, alu, addr); @@ -1340,7 +1375,10 @@ int r600_bc_build(struct r600_bc *bc) return r; addr += 2; if (alu->last) { - addr += alu->nliteral; + for (i = 0; i < align(nliteral, 2); ++i) { + bc->bytecode[addr++] = literal[i]; + } + nliteral = 0; } } break; @@ -1427,6 +1465,8 @@ void r600_bc_dump(struct r600_bc *bc) struct r600_bc_tex *tex = NULL; unsigned i, id; + uint32_t literal[4]; + unsigned nliteral; char chip = '6'; switch (bc->chiprev) { @@ -1513,7 +1553,10 @@ void r600_bc_dump(struct r600_bc *bc) } id = cf->addr; + nliteral = 0; LIST_FOR_EACH_ENTRY(alu, &cf->alu, list) { + r600_bc_alu_nliterals(alu, literal, &nliteral); + fprintf(stderr, "%04d %08X ", id, bc->bytecode[id]); fprintf(stderr, "SRC0(SEL:%d ", alu->src[0].sel); fprintf(stderr, "REL:%d ", alu->src[0].rel); @@ -1548,10 +1591,12 @@ void r600_bc_dump(struct r600_bc *bc) id++; if (alu->last) { - for (i = 0; i < alu->nliteral; i++, id++) { + for (i = 0; i < nliteral; i++, id++) { float *f = (float*)(bc->bytecode + id); fprintf(stderr, "%04d %08X\t%f\n", id, bc->bytecode[id], *f); } + id += nliteral & 1; + nliteral = 0; } } diff --git a/src/gallium/drivers/r600/r600_asm.h b/src/gallium/drivers/r600/r600_asm.h index 570292e9fdc..278b4466cb0 100644 --- a/src/gallium/drivers/r600/r600_asm.h +++ b/src/gallium/drivers/r600/r600_asm.h @@ -34,6 +34,7 @@ struct r600_bc_alu_src { unsigned neg; unsigned abs; unsigned rel; + u32 *value; }; struct r600_bc_alu_dst { @@ -52,11 +53,8 @@ struct r600_bc_alu { unsigned last; unsigned is_op3; unsigned predicate; - unsigned nliteral; - unsigned literal_added; unsigned bank_swizzle; unsigned bank_swizzle_force; - u32 value[4]; unsigned omod; }; @@ -196,13 +194,13 @@ void eg_cf_vtx(struct r600_vertex_element *ve, u32 *bytecode, unsigned count); int r600_bc_init(struct r600_bc *bc, enum radeon_family family); void r600_bc_clear(struct r600_bc *bc); int r600_bc_add_alu(struct r600_bc *bc, const struct r600_bc_alu *alu); -int r600_bc_add_literal(struct r600_bc *bc, const u32 *value); int r600_bc_add_vtx(struct r600_bc *bc, const struct r600_bc_vtx *vtx); int r600_bc_add_tex(struct r600_bc *bc, const struct r600_bc_tex *tex); int r600_bc_add_output(struct r600_bc *bc, const struct r600_bc_output *output); int r600_bc_build(struct r600_bc *bc); int r600_bc_add_cfinst(struct r600_bc *bc, int inst); int r600_bc_add_alu_type(struct r600_bc *bc, const struct r600_bc_alu *alu, int type); +void r600_bc_special_constants(u32 value, unsigned *sel, unsigned *neg); void r600_bc_dump(struct r600_bc *bc); void r600_cf_vtx(struct r600_vertex_element *ve, u32 *bytecode, unsigned count); void r600_cf_vtx_tc(struct r600_vertex_element *ve, u32 *bytecode, unsigned count); diff --git a/src/gallium/drivers/r600/r600_shader.c b/src/gallium/drivers/r600/r600_shader.c index 78739bf89d8..e85e829badd 100644 --- a/src/gallium/drivers/r600/r600_shader.c +++ b/src/gallium/drivers/r600/r600_shader.c @@ -225,11 +225,12 @@ int r600_pipe_shader(struct pipe_context *ctx, struct r600_pipe_shader *shader) return 0; } -int r600_shader_from_tgsi(const struct tgsi_token *tokens, struct r600_shader *shader); +int r600_shader_from_tgsi(const struct tgsi_token *tokens, struct r600_shader *shader, u32 **literals); int r600_pipe_shader_create(struct pipe_context *ctx, struct r600_pipe_shader *shader, const struct tgsi_token *tokens) { static int dump_shaders = -1; struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + u32 *literals; int r; /* Would like some magic "get_bool_option_once" routine. @@ -242,12 +243,13 @@ int r600_pipe_shader_create(struct pipe_context *ctx, struct r600_pipe_shader *s tgsi_dump(tokens, 0); } shader->shader.family = r600_get_family(rctx->radeon); - r = r600_shader_from_tgsi(tokens, &shader->shader); + r = r600_shader_from_tgsi(tokens, &shader->shader, &literals); if (r) { R600_ERR("translation from TGSI failed !\n"); return r; } r = r600_bc_build(&shader->shader.bc); + free(literals); if (r) { R600_ERR("building bytecode failed !\n"); return r; @@ -282,7 +284,6 @@ struct r600_shader_ctx { struct r600_shader_tgsi_instruction *inst_info; struct r600_bc *bc; struct r600_shader *shader; - u32 value[4]; u32 *literals; u32 nliterals; u32 max_driver_temp_used; @@ -491,7 +492,7 @@ static int evergreen_gpr_count(struct r600_shader_ctx *ctx) return ctx->num_interp_gpr; } -int r600_shader_from_tgsi(const struct tgsi_token *tokens, struct r600_shader *shader) +int r600_shader_from_tgsi(const struct tgsi_token *tokens, struct r600_shader *shader, u32 **literals) { struct tgsi_full_immediate *immediate; struct r600_shader_ctx ctx; @@ -597,9 +598,6 @@ int r600_shader_from_tgsi(const struct tgsi_token *tokens, struct r600_shader *s else ctx.inst_info = &r600_shader_tgsi_instruction[opcode]; r = ctx.inst_info->process(&ctx); - if (r) - goto out_err; - r = r600_bc_add_literal(ctx.bc, ctx.value); if (r) goto out_err; break; @@ -722,7 +720,7 @@ int r600_shader_from_tgsi(const struct tgsi_token *tokens, struct r600_shader *s if (r) goto out_err; } - free(ctx.literals); + *literals = ctx.literals; tgsi_parse_free(&ctx.parse); return 0; out_err: @@ -756,38 +754,13 @@ static int tgsi_src(struct r600_shader_ctx *ctx, (tgsi_src->Register.SwizzleX == tgsi_src->Register.SwizzleW)) { index = tgsi_src->Register.Index * 4 + tgsi_src->Register.SwizzleX; - switch(ctx->literals[index]) { - case 0: - r600_src->sel = V_SQ_ALU_SRC_0; + r600_bc_special_constants(ctx->literals[index], &r600_src->sel, &r600_src->neg); + if (r600_src->sel != V_SQ_ALU_SRC_LITERAL) return 0; - case 1: - r600_src->sel = V_SQ_ALU_SRC_1_INT; - return 0; - case -1: - r600_src->sel = V_SQ_ALU_SRC_M_1_INT; - return 0; - case 0x3F800000: // 1.0f - r600_src->sel = V_SQ_ALU_SRC_1; - return 0; - case 0x3F000000: // 0.5f - r600_src->sel = V_SQ_ALU_SRC_0_5; - return 0; - case 0xBF800000: // -1.0f - r600_src->sel = V_SQ_ALU_SRC_1; - r600_src->neg ^= 1; - return 0; - case 0xBF000000: // -0.5f - r600_src->sel = V_SQ_ALU_SRC_0_5; - r600_src->neg ^= 1; - return 0; - } } index = tgsi_src->Register.Index; r600_src->sel = V_SQ_ALU_SRC_LITERAL; - ctx->value[0] = ctx->literals[index * 4 + 0]; - ctx->value[1] = ctx->literals[index * 4 + 1]; - ctx->value[2] = ctx->literals[index * 4 + 2]; - ctx->value[3] = ctx->literals[index * 4 + 3]; + r600_src->value = ctx->literals + index * 4; } else { if (tgsi_src->Register.Indirect) r600_src->rel = V_SQ_REL_RELATIVE; @@ -893,6 +866,7 @@ static int tgsi_split_literal_constant(struct r600_shader_ctx *ctx, struct r600_ alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV); alu.src[0].sel = r600_src[i].sel; alu.src[0].chan = k; + alu.src[0].value = r600_src[i].value; alu.dst.sel = treg; alu.dst.chan = k; alu.dst.write = 1; @@ -902,9 +876,6 @@ static int tgsi_split_literal_constant(struct r600_shader_ctx *ctx, struct r600_ if (r) return r; } - r = r600_bc_add_literal(ctx->bc, &ctx->literals[inst->Src[i].Register.Index * 4]); - if (r) - return r; r600_src[i].sel = treg; j--; } @@ -999,12 +970,14 @@ static int tgsi_op2_swap(struct r600_shader_ctx *ctx) static int tgsi_setup_trig(struct r600_shader_ctx *ctx, struct r600_bc_alu_src r600_src[3]) { + static float half_inv_pi = 1.0 /(3.1415926535 * 2); + static float double_pi = 3.1415926535 * 2; + static float neg_pi = -3.1415926535; + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; - int r, src0_chan; - uint32_t lit_vals[4]; + int r; struct r600_bc_alu alu; - memset(lit_vals, 0, 4*4); r = tgsi_split_constant(ctx, r600_src); if (r) return r; @@ -1012,22 +985,6 @@ static int tgsi_setup_trig(struct r600_shader_ctx *ctx, if (r) return r; - src0_chan = tgsi_chan(&inst->Src[0], 0); - - /* We are going to feed two literals to the MAD below, - * which means that if the first operand is a literal as well, - * we need to copy its value manually. - */ - if (r600_src[0].sel == V_SQ_ALU_SRC_LITERAL) { - unsigned index = inst->Src[0].Register.Index; - - lit_vals[2] = ctx->literals[index * 4 + src0_chan]; - src0_chan = 2; - } - - lit_vals[0] = fui(1.0 /(3.1415926535 * 2)); - lit_vals[1] = fui(0.5f); - memset(&alu, 0, sizeof(struct r600_bc_alu)); alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD); alu.is_op3 = 1; @@ -1037,17 +994,15 @@ static int tgsi_setup_trig(struct r600_shader_ctx *ctx, alu.dst.write = 1; alu.src[0] = r600_src[0]; - alu.src[0].chan = src0_chan; + alu.src[0].chan = tgsi_chan(&inst->Src[0], 0); alu.src[1].sel = V_SQ_ALU_SRC_LITERAL; alu.src[1].chan = 0; - alu.src[2].sel = V_SQ_ALU_SRC_LITERAL; + alu.src[1].value = (uint32_t *)&half_inv_pi; + alu.src[2].sel = V_SQ_ALU_SRC_0_5; alu.src[2].chan = 1; alu.last = 1; r = r600_bc_add_alu(ctx->bc, &alu); - if (r) - return r; - r = r600_bc_add_literal(ctx->bc, lit_vals); if (r) return r; @@ -1065,14 +1020,6 @@ static int tgsi_setup_trig(struct r600_shader_ctx *ctx, if (r) return r; - if (ctx->bc->chiprev == CHIPREV_R600) { - lit_vals[0] = fui(3.1415926535897f * 2.0f); - lit_vals[1] = fui(-3.1415926535897f); - } else { - lit_vals[0] = fui(1.0f); - lit_vals[1] = fui(-0.5f); - } - memset(&alu, 0, sizeof(struct r600_bc_alu)); alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD); alu.is_op3 = 1; @@ -1088,11 +1035,18 @@ static int tgsi_setup_trig(struct r600_shader_ctx *ctx, alu.src[1].chan = 0; alu.src[2].sel = V_SQ_ALU_SRC_LITERAL; alu.src[2].chan = 1; + + if (ctx->bc->chiprev == CHIPREV_R600) { + alu.src[1].value = (uint32_t *)&double_pi; + alu.src[2].value = (uint32_t *)&neg_pi; + } else { + alu.src[1].sel = V_SQ_ALU_SRC_1; + alu.src[2].sel = V_SQ_ALU_SRC_0_5; + alu.src[2].neg = 1; + } + alu.last = 1; r = r600_bc_add_alu(ctx->bc, &alu); - if (r) - return r; - r = r600_bc_add_literal(ctx->bc, lit_vals); if (r) return r; return 0; @@ -1210,10 +1164,6 @@ static int tgsi_scs(struct r600_shader_ctx *ctx) r = r600_bc_add_alu(ctx->bc, &alu); if (r) return r; - - r = r600_bc_add_literal(ctx->bc, ctx->value); - if (r) - return r; } /* dst.w = 1.0; */ @@ -1234,10 +1184,6 @@ static int tgsi_scs(struct r600_shader_ctx *ctx) r = r600_bc_add_alu(ctx->bc, &alu); if (r) return r; - - r = r600_bc_add_literal(ctx->bc, ctx->value); - if (r) - return r; } return 0; @@ -1273,9 +1219,6 @@ static int tgsi_kill(struct r600_shader_ctx *ctx) if (r) return r; } - r = r600_bc_add_literal(ctx->bc, ctx->value); - if (r) - return r; /* kill must be last in ALU */ ctx->bc->force_add_cf = 1; @@ -1338,10 +1281,6 @@ static int tgsi_lit(struct r600_shader_ctx *ctx) if (r) return r; - r = r600_bc_add_literal(ctx->bc, ctx->value); - if (r) - return r; - if (inst->Dst[0].Register.WriteMask & (1 << 2)) { int chan; @@ -1360,10 +1299,6 @@ static int tgsi_lit(struct r600_shader_ctx *ctx) if (r) return r; - r = r600_bc_add_literal(ctx->bc, ctx->value); - if (r) - return r; - chan = alu.dst.chan; sel = alu.dst.sel; @@ -1386,9 +1321,6 @@ static int tgsi_lit(struct r600_shader_ctx *ctx) if (r) return r; - r = r600_bc_add_literal(ctx->bc, ctx->value); - if (r) - return r; /* dst.z = exp(tmp.x) */ memset(&alu, 0, sizeof(struct r600_bc_alu)); alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE); @@ -1430,9 +1362,6 @@ static int tgsi_rsq(struct r600_shader_ctx *ctx) alu.dst.write = 1; alu.last = 1; r = r600_bc_add_alu(ctx->bc, &alu); - if (r) - return r; - r = r600_bc_add_literal(ctx->bc, ctx->value); if (r) return r; /* replicate result */ @@ -1481,9 +1410,6 @@ static int tgsi_trans_srcx_replicate(struct r600_shader_ctx *ctx) alu.dst.write = 1; alu.last = 1; r = r600_bc_add_alu(ctx->bc, &alu); - if (r) - return r; - r = r600_bc_add_literal(ctx->bc, ctx->value); if (r) return r; /* replicate result */ @@ -1507,9 +1433,6 @@ static int tgsi_pow(struct r600_shader_ctx *ctx) alu.dst.write = 1; alu.last = 1; r = r600_bc_add_alu(ctx->bc, &alu); - if (r) - return r; - r = r600_bc_add_literal(ctx->bc,ctx->value); if (r) return r; /* b * LOG2(a) */ @@ -1524,9 +1447,6 @@ static int tgsi_pow(struct r600_shader_ctx *ctx) alu.dst.write = 1; alu.last = 1; r = r600_bc_add_alu(ctx->bc, &alu); - if (r) - return r; - r = r600_bc_add_literal(ctx->bc,ctx->value); if (r) return r; /* POW(a,b) = EXP2(b * LOG2(a))*/ @@ -1537,9 +1457,6 @@ static int tgsi_pow(struct r600_shader_ctx *ctx) alu.dst.write = 1; alu.last = 1; r = r600_bc_add_alu(ctx->bc, &alu); - if (r) - return r; - r = r600_bc_add_literal(ctx->bc,ctx->value); if (r) return r; return tgsi_helper_tempx_replicate(ctx); @@ -1581,9 +1498,6 @@ static int tgsi_ssg(struct r600_shader_ctx *ctx) if (r) return r; } - r = r600_bc_add_literal(ctx->bc, ctx->value); - if (r) - return r; /* dst = (-tmp > 0 ? -1 : tmp) */ for (i = 0; i < 4; i++) { @@ -1618,9 +1532,6 @@ static int tgsi_helper_copy(struct r600_shader_ctx *ctx, struct tgsi_full_instru struct r600_bc_alu alu; int i, r; - r = r600_bc_add_literal(ctx->bc, ctx->value); - if (r) - return r; for (i = 0; i < 4; i++) { memset(&alu, 0, sizeof(struct r600_bc_alu)); if (!(inst->Dst[0].Register.WriteMask & (1 << i))) { @@ -1749,6 +1660,7 @@ static int tgsi_dp(struct r600_shader_ctx *ctx) static int tgsi_tex(struct r600_shader_ctx *ctx) { + static float one_point_five = 1.5f; struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; struct r600_bc_tex tex; struct r600_bc_alu alu; @@ -1758,7 +1670,6 @@ static int tgsi_tex(struct r600_shader_ctx *ctx) boolean src_not_temp = inst->Src[0].Register.File != TGSI_FILE_TEMPORARY && inst->Src[0].Register.File != TGSI_FILE_INPUT; - uint32_t lit_vals[4]; src_gpr = ctx->file_offset[inst->Src[0].Register.File] + inst->Src[0].Register.Index; @@ -1887,6 +1798,7 @@ static int tgsi_tex(struct r600_shader_ctx *ctx) alu.src[2].sel = V_SQ_ALU_SRC_LITERAL; alu.src[2].chan = 0; + alu.src[2].value = (u32*)&one_point_five; alu.dst.sel = ctx->temp_reg; alu.dst.chan = 0; @@ -1907,6 +1819,7 @@ static int tgsi_tex(struct r600_shader_ctx *ctx) alu.src[2].sel = V_SQ_ALU_SRC_LITERAL; alu.src[2].chan = 0; + alu.src[2].value = (u32*)&one_point_five; alu.dst.sel = ctx->temp_reg; alu.dst.chan = 1; @@ -1917,11 +1830,6 @@ static int tgsi_tex(struct r600_shader_ctx *ctx) if (r) return r; - lit_vals[0] = fui(1.5f); - - r = r600_bc_add_literal(ctx->bc, lit_vals); - if (r) - return r; src_not_temp = FALSE; src_gpr = ctx->temp_reg; } @@ -2055,9 +1963,6 @@ static int tgsi_lrp(struct r600_shader_ctx *ctx) if (r) return r; } - r = r600_bc_add_literal(ctx->bc, ctx->value); - if (r) - return r; /* (1 - src0) * src2 */ for (i = 0; i < lasti + 1; i++) { @@ -2080,9 +1985,6 @@ static int tgsi_lrp(struct r600_shader_ctx *ctx) if (r) return r; } - r = r600_bc_add_literal(ctx->bc, ctx->value); - if (r) - return r; /* src0 * src1 + (1 - src0) * src2 */ for (i = 0; i < lasti + 1; i++) { @@ -2223,10 +2125,6 @@ static int tgsi_xpd(struct r600_shader_ctx *ctx) r = r600_bc_add_alu(ctx->bc, &alu); if (r) return r; - - r = r600_bc_add_literal(ctx->bc, ctx->value); - if (r) - return r; } for (i = 0; i < 4; i++) { @@ -2284,10 +2182,6 @@ static int tgsi_xpd(struct r600_shader_ctx *ctx) r = r600_bc_add_alu(ctx->bc, &alu); if (r) return r; - - r = r600_bc_add_literal(ctx->bc, ctx->value); - if (r) - return r; } if (use_temp) return tgsi_helper_copy(ctx, inst); @@ -2320,10 +2214,6 @@ static int tgsi_exp(struct r600_shader_ctx *ctx) if (r) return r; - r = r600_bc_add_literal(ctx->bc, ctx->value); - if (r) - return r; - alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE); alu.src[0].sel = ctx->temp_reg; alu.src[0].chan = 0; @@ -2335,10 +2225,6 @@ static int tgsi_exp(struct r600_shader_ctx *ctx) r = r600_bc_add_alu(ctx->bc, &alu); if (r) return r; - - r = r600_bc_add_literal(ctx->bc, ctx->value); - if (r) - return r; } /* result.y = tmp - floor(tmp); */ @@ -2364,9 +2250,6 @@ static int tgsi_exp(struct r600_shader_ctx *ctx) r = r600_bc_add_alu(ctx->bc, &alu); if (r) return r; - r = r600_bc_add_literal(ctx->bc, ctx->value); - if (r) - return r; } /* result.z = RoughApprox2ToX(tmp);*/ @@ -2387,9 +2270,6 @@ static int tgsi_exp(struct r600_shader_ctx *ctx) r = r600_bc_add_alu(ctx->bc, &alu); if (r) return r; - r = r600_bc_add_literal(ctx->bc, ctx->value); - if (r) - return r; } /* result.w = 1.0;*/ @@ -2407,9 +2287,6 @@ static int tgsi_exp(struct r600_shader_ctx *ctx) r = r600_bc_add_alu(ctx->bc, &alu); if (r) return r; - r = r600_bc_add_literal(ctx->bc, ctx->value); - if (r) - return r; } return tgsi_helper_copy(ctx, inst); } @@ -2439,10 +2316,6 @@ static int tgsi_log(struct r600_shader_ctx *ctx) if (r) return r; - r = r600_bc_add_literal(ctx->bc, ctx->value); - if (r) - return r; - alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR); alu.src[0].sel = ctx->temp_reg; alu.src[0].chan = 0; @@ -2455,10 +2328,6 @@ static int tgsi_log(struct r600_shader_ctx *ctx) r = r600_bc_add_alu(ctx->bc, &alu); if (r) return r; - - r = r600_bc_add_literal(ctx->bc, ctx->value); - if (r) - return r; } /* result.y = src.x / (2 ^ floor(log2(src.x))); */ @@ -2481,10 +2350,6 @@ static int tgsi_log(struct r600_shader_ctx *ctx) if (r) return r; - r = r600_bc_add_literal(ctx->bc, ctx->value); - if (r) - return r; - memset(&alu, 0, sizeof(struct r600_bc_alu)); alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR); @@ -2500,10 +2365,6 @@ static int tgsi_log(struct r600_shader_ctx *ctx) if (r) return r; - r = r600_bc_add_literal(ctx->bc, ctx->value); - if (r) - return r; - memset(&alu, 0, sizeof(struct r600_bc_alu)); alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE); @@ -2519,10 +2380,6 @@ static int tgsi_log(struct r600_shader_ctx *ctx) if (r) return r; - r = r600_bc_add_literal(ctx->bc, ctx->value); - if (r) - return r; - memset(&alu, 0, sizeof(struct r600_bc_alu)); alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE); @@ -2538,10 +2395,6 @@ static int tgsi_log(struct r600_shader_ctx *ctx) if (r) return r; - r = r600_bc_add_literal(ctx->bc, ctx->value); - if (r) - return r; - memset(&alu, 0, sizeof(struct r600_bc_alu)); alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL); @@ -2563,10 +2416,6 @@ static int tgsi_log(struct r600_shader_ctx *ctx) r = r600_bc_add_alu(ctx->bc, &alu); if (r) return r; - - r = r600_bc_add_literal(ctx->bc, ctx->value); - if (r) - return r; } /* result.z = log2(src);*/ @@ -2588,10 +2437,6 @@ static int tgsi_log(struct r600_shader_ctx *ctx) r = r600_bc_add_alu(ctx->bc, &alu); if (r) return r; - - r = r600_bc_add_literal(ctx->bc, ctx->value); - if (r) - return r; } /* result.w = 1.0; */ @@ -2610,10 +2455,6 @@ static int tgsi_log(struct r600_shader_ctx *ctx) r = r600_bc_add_alu(ctx->bc, &alu); if (r) return r; - - r = r600_bc_add_literal(ctx->bc, ctx->value); - if (r) - return r; } return tgsi_helper_copy(ctx, inst); diff --git a/src/gallium/drivers/r600/r600_shader.h b/src/gallium/drivers/r600/r600_shader.h index 35b0331525a..935dd6fe3ab 100644 --- a/src/gallium/drivers/r600/r600_shader.h +++ b/src/gallium/drivers/r600/r600_shader.h @@ -47,6 +47,6 @@ struct r600_shader { boolean uses_kill; }; -int r600_shader_from_tgsi(const struct tgsi_token *tokens, struct r600_shader *shader); +int r600_shader_from_tgsi(const struct tgsi_token *tokens, struct r600_shader *shader, u32 **literals); #endif diff --git a/src/gallium/drivers/r600/r700_asm.c b/src/gallium/drivers/r600/r700_asm.c index 3eb6fb50ca7..a7f2f54736e 100644 --- a/src/gallium/drivers/r600/r700_asm.c +++ b/src/gallium/drivers/r600/r700_asm.c @@ -29,8 +29,6 @@ int r700_bc_alu_build(struct r600_bc *bc, struct r600_bc_alu *alu, unsigned id) { - unsigned i; - bc->bytecode[id++] = S_SQ_ALU_WORD0_SRC0_SEL(alu->src[0].sel) | S_SQ_ALU_WORD0_SRC0_REL(alu->src[0].rel) | S_SQ_ALU_WORD0_SRC0_CHAN(alu->src[0].chan) | @@ -67,13 +65,5 @@ int r700_bc_alu_build(struct r600_bc *bc, struct r600_bc_alu *alu, unsigned id) S_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK(alu->predicate) | S_SQ_ALU_WORD1_OP2_UPDATE_PRED(alu->predicate); } - if (alu->last) { - if (alu->nliteral && !alu->literal_added) { - R600_ERR("Bug in ALU processing for instruction 0x%08x, literal not added correctly\n", alu->inst); - } - for (i = 0; i < alu->nliteral; i++) { - bc->bytecode[id++] = alu->value[i]; - } - } return 0; } From a2ab929ab2d7dd4fcbbc5f32c8feabf42cad4d34 Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Thu, 13 Jan 2011 14:17:01 -0800 Subject: [PATCH 099/164] r600g: Move declaration before code in r600_asm.c. Fixes SCons build. --- src/gallium/drivers/r600/r600_asm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gallium/drivers/r600/r600_asm.c b/src/gallium/drivers/r600/r600_asm.c index e96236e06ee..52dc0688d52 100644 --- a/src/gallium/drivers/r600/r600_asm.c +++ b/src/gallium/drivers/r600/r600_asm.c @@ -700,6 +700,8 @@ static int merge_inst_groups(struct r600_bc *bc, struct r600_bc_alu *slots[5], s return r; for (i = 0; i < 5; ++i) { + struct r600_bc_alu *alu; + /* check number of literals */ if (prev[i] && r600_bc_alu_nliterals(prev[i], literal, &nliteral)) return 0; @@ -730,7 +732,7 @@ static int merge_inst_groups(struct r600_bc *bc, struct r600_bc_alu *slots[5], s result[i] = slots[i]; // let's check source gprs - struct r600_bc_alu *alu = slots[i]; + alu = slots[i]; num_once_inst += is_alu_once_inst(alu); num_src = r600_bc_get_num_operands(alu); From 78838b2d1bd88f948030cd60479b832b661ccd3c Mon Sep 17 00:00:00 2001 From: Chad Versace Date: Wed, 12 Jan 2011 15:47:26 -0800 Subject: [PATCH 100/164] mesa: Change OES_standard_derivatives to be stand-alone extension Add a bit in struct gl_extensions for OES_standard_derivatives, and enable the bit by default. Advertise the extension only if the bit is enabled. Previously, OES_standard_derivatives was advertised in GLES2 contexts if ARB_framebuffer_object was enabled. --- src/mesa/main/extensions.c | 3 ++- src/mesa/main/mtypes.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c index 015f89aa0ba..39aabdb752c 100644 --- a/src/mesa/main/extensions.c +++ b/src/mesa/main/extensions.c @@ -232,7 +232,7 @@ static const struct extension extension_table[] = { { "GL_OES_read_format", o(OES_read_format), GL | ES1 }, { "GL_OES_rgb8_rgba8", o(EXT_framebuffer_object), ES1 | ES2 }, { "GL_OES_single_precision", o(dummy_true), ES1 }, - { "GL_OES_standard_derivatives", o(ARB_fragment_shader), ES2 }, + { "GL_OES_standard_derivatives", o(OES_standard_derivatives), ES2 }, { "GL_OES_stencil1", o(dummy_false), DISABLE }, { "GL_OES_stencil4", o(dummy_false), DISABLE }, { "GL_OES_stencil8", o(EXT_framebuffer_object), ES1 | ES2 }, @@ -351,6 +351,7 @@ static const size_t default_extensions[] = { o(EXT_vertex_array), o(OES_read_format), + o(OES_standard_derivatives), /* Vendor Extensions */ o(APPLE_packed_pixels), diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 3fc1facb4ca..8d2030e9ced 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -2772,6 +2772,7 @@ struct gl_extensions GLboolean EXT_vertex_array; GLboolean EXT_vertex_array_bgra; GLboolean EXT_vertex_array_set; + GLboolean OES_standard_derivatives; /* vendor extensions */ GLboolean APPLE_client_storage; GLboolean APPLE_packed_pixels; From 7b9dc40b0d984ca2da915224517d5ba9d633f32a Mon Sep 17 00:00:00 2001 From: Chad Versace Date: Wed, 12 Jan 2011 16:09:37 -0800 Subject: [PATCH 101/164] i915: Disable extension OES_standard_derivatives OES_standard_derivatives must be manually disabled for i915 because Mesa enables it by default. --- src/mesa/drivers/dri/intel/intel_extensions_es2.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/mesa/drivers/dri/intel/intel_extensions_es2.c b/src/mesa/drivers/dri/intel/intel_extensions_es2.c index 38b92d5b55b..5ef6b0561de 100644 --- a/src/mesa/drivers/dri/intel/intel_extensions_es2.c +++ b/src/mesa/drivers/dri/intel/intel_extensions_es2.c @@ -80,6 +80,17 @@ static const char *es2_extensions[] = { NULL, }; +/** + * \brief Extensions to disable. + * + * These extensions must be manually disabled because they may have been + * enabled by default. + */ +static const char* es2_extensions_disabled[] = { + "GL_OES_standard_derivatives", + NULL, +}; + /** * Initializes potential list of extensions if ctx == NULL, or actually enables * extensions for a context. @@ -94,4 +105,6 @@ intelInitExtensionsES2(struct gl_context *ctx) for (i = 0; es2_extensions[i]; i++) _mesa_enable_extension(ctx, es2_extensions[i]); + for (i = 0; es2_extensions_disabled[i]; i++) + _mesa_disable_extension(ctx, es2_extensions_disabled[i]); } From 7f652fc523b56a3c13a90b417f8d32e7a702ed3d Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 14 Jan 2011 14:57:54 +1000 Subject: [PATCH 102/164] srgb: fix fbo base format picking. Pointed out by Brian. --- src/mesa/main/fbobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c index fac63ac994d..ea9f803cb15 100644 --- a/src/mesa/main/fbobject.c +++ b/src/mesa/main/fbobject.c @@ -989,6 +989,7 @@ _mesa_base_fbo_format(struct gl_context *ctx, GLenum internalFormat) case GL_RGB10: case GL_RGB12: case GL_RGB16: + case GL_SRGB8_EXT: return GL_RGB; case GL_RGBA: case GL_RGBA2: @@ -1000,7 +1001,6 @@ _mesa_base_fbo_format(struct gl_context *ctx, GLenum internalFormat) case GL_RGBA16: case GL_RGBA16_SNORM: case GL_SRGB8_ALPHA8_EXT: - case GL_SRGB8_EXT: return GL_RGBA; case GL_STENCIL_INDEX: case GL_STENCIL_INDEX1_EXT: From 483de8ef2eb9d4861c746dee750379529ea0ce0c Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 13 Jan 2011 15:46:44 +1000 Subject: [PATCH 103/164] i965: fix fbo-srgb on i965. Until we get the EXT_framebuffer_sRGB extension we should bind the sRGB formats for FBO as linear. Signed-off-by: Dave Airlie --- src/mesa/drivers/dri/i965/brw_wm_surface_state.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c index e921d8a9a1d..233fe3b7310 100644 --- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c +++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c @@ -435,6 +435,11 @@ brw_update_renderbuffer_surface(struct brw_context *brw, */ surf.ss0.surface_format = BRW_SURFACEFORMAT_B8G8R8A8_UNORM; break; + case MESA_FORMAT_SARGB8: + /* without GL_EXT_framebuffer_sRGB we shouldn't bind sRGB + surfaces to the blend/update as sRGB */ + surf.ss0.surface_format = BRW_SURFACEFORMAT_B8G8R8A8_UNORM; + break; default: surf.ss0.surface_format = brw_format_for_mesa_format[irb->Base.Format]; assert(surf.ss0.surface_format != 0); From 36a59b29ef07b78378dcb3934131d262d42612cb Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 14 Jan 2011 14:11:35 +0800 Subject: [PATCH 104/164] egl: Fix an assertion in _eglUpdateAPIsString. dpy->ClientAPIs was renamed in a4a38dcf61f141297a083ccac217200947d57b0d. --- src/egl/main/eglmisc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/egl/main/eglmisc.c b/src/egl/main/eglmisc.c index 5a607dc080a..a595e3f4d91 100644 --- a/src/egl/main/eglmisc.c +++ b/src/egl/main/eglmisc.c @@ -133,7 +133,7 @@ _eglUpdateAPIsString(_EGLDisplay *dpy) if (dpy->ClientAPIs & EGL_OPENVG_BIT) strcat(apis, "OpenVG "); - assert(strlen(apis) < sizeof(dpy->ClientAPIs)); + assert(strlen(apis) < sizeof(dpy->ClientAPIsString)); } From e7d8f925704ddd635748fe72a42eaeec95eb89ee Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 14 Jan 2011 14:29:04 +0800 Subject: [PATCH 105/164] egl: Fix EGL_VERSION string. Fix a copy-and-paste error in a4a38dcf61f141297a083ccac217200947d57b0d. --- src/egl/main/eglmisc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/egl/main/eglmisc.c b/src/egl/main/eglmisc.c index a595e3f4d91..f8ba5f33eb9 100644 --- a/src/egl/main/eglmisc.c +++ b/src/egl/main/eglmisc.c @@ -147,7 +147,7 @@ _eglQueryString(_EGLDriver *drv, _EGLDisplay *dpy, EGLint name) return _EGL_VENDOR_STRING; case EGL_VERSION: _eglsnprintf(dpy->VersionString, sizeof(dpy->VersionString), - "%d.%d (%s)", dpy->VersionMajor, dpy->VersionMajor, + "%d.%d (%s)", dpy->VersionMajor, dpy->VersionMinor, dpy->Driver->Name); return dpy->VersionString; case EGL_EXTENSIONS: From 323ef3a1f07ba4333dadebab571ddcd49d95f45c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 14 Jan 2011 18:46:11 +0100 Subject: [PATCH 106/164] r600g: add more missing instructions to r600_bc_get_num_operands --- src/gallium/drivers/r600/r600_asm.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/gallium/drivers/r600/r600_asm.c b/src/gallium/drivers/r600/r600_asm.c index 52dc0688d52..2d0d2776544 100644 --- a/src/gallium/drivers/r600/r600_asm.c +++ b/src/gallium/drivers/r600/r600_asm.c @@ -64,18 +64,22 @@ static inline unsigned int r600_bc_get_num_operands(struct r600_bc_alu *alu) case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE: return 2; - case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA: case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_FLOOR: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT: case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT: case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR: case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_TRUNC: case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE: case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED: case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_CLAMPED: case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE: case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_CLAMPED: case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE: case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT_FLOOR: case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN: case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS: return 1; From 6e9b0f6807c7a22f096f483961ae71512f8d9f41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= Date: Fri, 14 Jan 2011 16:11:28 -0500 Subject: [PATCH 107/164] gles2: Also support GL_BGRA_EXT for glTexSubImage2d --- src/mesa/main/APIspec.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/mesa/main/APIspec.xml b/src/mesa/main/APIspec.xml index 16d0c9413d0..2a98c952e05 100644 --- a/src/mesa/main/APIspec.xml +++ b/src/mesa/main/APIspec.xml @@ -2004,6 +2004,14 @@ + + + + + + + +