diff options
Diffstat (limited to 'mesalib/src/mesa')
25 files changed, 312 insertions, 129 deletions
diff --git a/mesalib/src/mesa/Android.libmesa_glsl_utils.mk b/mesalib/src/mesa/Android.libmesa_glsl_utils.mk index 9c5f3493c..47f2e151b 100644 --- a/mesalib/src/mesa/Android.libmesa_glsl_utils.mk +++ b/mesalib/src/mesa/Android.libmesa_glsl_utils.mk @@ -35,10 +35,13 @@ include $(CLEAR_VARS) LOCAL_MODULE := libmesa_glsl_utils -LOCAL_C_INCLUDES := $(MESA_TOP)/src/glsl +LOCAL_C_INCLUDES := \ + $(MESA_TOP)/src/glsl \ + $(MESA_TOP)/src/mapi LOCAL_SRC_FILES := \ main/hash_table.c \ + main/imports.c \ program/prog_hash_table.c \ program/symbol_table.c @@ -54,10 +57,13 @@ include $(CLEAR_VARS) LOCAL_MODULE := libmesa_glsl_utils LOCAL_IS_HOST_MODULE := true -LOCAL_C_INCLUDES := $(MESA_TOP)/src/glsl +LOCAL_C_INCLUDES := \ + $(MESA_TOP)/src/glsl \ + $(MESA_TOP)/src/mapi LOCAL_SRC_FILES := \ main/hash_table.c \ + main/imports.c \ program/prog_hash_table.c \ program/symbol_table.c diff --git a/mesalib/src/mesa/main/extensions.c b/mesalib/src/mesa/main/extensions.c index 5d01ac8ea..7ae07fb5a 100644 --- a/mesalib/src/mesa/main/extensions.c +++ b/mesalib/src/mesa/main/extensions.c @@ -125,6 +125,7 @@ static const struct extension extension_table[] = { { "GL_ARB_shader_stencil_export", o(ARB_shader_stencil_export), GL, 2009 }, { "GL_ARB_shader_texture_lod", o(ARB_shader_texture_lod), GL, 2009 }, { "GL_ARB_shading_language_100", o(ARB_shading_language_100), GLL, 2003 }, + { "GL_ARB_shading_language_packing", o(ARB_shading_language_packing), GL, 2011 }, { "GL_ARB_shadow", o(ARB_shadow), GLL, 2001 }, { "GL_ARB_sync", o(ARB_sync), GL, 2003 }, { "GL_ARB_texture_border_clamp", o(ARB_texture_border_clamp), GLL, 2000 }, diff --git a/mesalib/src/mesa/main/getstring.c b/mesalib/src/mesa/main/getstring.c index 1f23cc0a4..aa3a528fd 100644 --- a/mesalib/src/mesa/main/getstring.c +++ b/mesalib/src/mesa/main/getstring.c @@ -74,7 +74,9 @@ shading_language_version(struct gl_context *ctx) break; case API_OPENGLES2: - return (const GLubyte *) "OpenGL ES GLSL ES 1.0.16"; + return (ctx->Version < 30) + ? (const GLubyte *) "OpenGL ES GLSL ES 1.0.16" + : (const GLubyte *) "OpenGL ES GLSL ES 3.0"; case API_OPENGLES: /* fall-through */ diff --git a/mesalib/src/mesa/main/imports.c b/mesalib/src/mesa/main/imports.c index 76f835e0e..e6f754254 100644 --- a/mesalib/src/mesa/main/imports.c +++ b/mesalib/src/mesa/main/imports.c @@ -314,10 +314,43 @@ _mesa_bitcount_64(uint64_t n) #endif +/* Using C99 rounding functions for roundToEven() implementation is + * difficult, because round(), rint, and nearbyint() are affected by + * fesetenv(), which the application may have done for its own + * purposes. Mesa's IROUND macro is close to what we want, but it + * rounds away from 0 on n + 0.5. + */ +int +_mesa_round_to_even(float val) +{ + int rounded = IROUND(val); + + if (val - floor(val) == 0.5) { + if (rounded % 2 != 0) + rounded += val > 0 ? -1 : 1; + } + + return rounded; +} + + /** * Convert a 4-byte float to a 2-byte half float. - * Based on code from: - * http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/008786.html + * + * Not all float32 values can be represented exactly as a float16 value. We + * round such intermediate float32 values to the nearest float16. When the + * float32 lies exactly between to float16 values, we round to the one with + * an even mantissa. + * + * This rounding behavior has several benefits: + * - It has no sign bias. + * + * - It reproduces the behavior of real hardware: opcode F32TO16 in Intel's + * GPU ISA. + * + * - By reproducing the behavior of the GPU (at least on Intel hardware), + * compile-time evaluation of constant packHalf2x16 GLSL expressions will + * result in the same value as if the expression were executed on the GPU. */ GLhalfARB _mesa_float_to_half(float val) @@ -356,32 +389,13 @@ _mesa_float_to_half(float val) else { /* regular number */ const int new_exp = flt_e - 127; - if (new_exp < -24) { - /* this maps to 0 */ - /* m = 0; - already set */ - e = 0; - } - else if (new_exp < -14) { - /* this maps to a denorm */ - unsigned int exp_val = (unsigned int) (-14 - new_exp); /* 2^-exp_val*/ + if (new_exp < -14) { + /* The float32 lies in the range (0.0, min_normal16) and is rounded + * to a nearby float16 value. The result will be either zero, subnormal, + * or normal. + */ e = 0; - switch (exp_val) { - case 0: - _mesa_warning(NULL, - "float_to_half: logical error in denorm creation!\n"); - /* m = 0; - already set */ - break; - case 1: m = 512 + (flt_m >> 14); break; - case 2: m = 256 + (flt_m >> 15); break; - case 3: m = 128 + (flt_m >> 16); break; - case 4: m = 64 + (flt_m >> 17); break; - case 5: m = 32 + (flt_m >> 18); break; - case 6: m = 16 + (flt_m >> 19); break; - case 7: m = 8 + (flt_m >> 20); break; - case 8: m = 4 + (flt_m >> 21); break; - case 9: m = 2 + (flt_m >> 22); break; - case 10: m = 1; break; - } + m = _mesa_round_to_even((1 << 24) * fabsf(fi.f)); } else if (new_exp > 15) { /* map this value to infinity */ @@ -389,12 +403,26 @@ _mesa_float_to_half(float val) e = 31; } else { - /* regular */ + /* The float32 lies in the range + * [min_normal16, max_normal16 + max_step16) + * and is rounded to a nearby float16 value. The result will be + * either normal or infinite. + */ e = new_exp + 15; - m = flt_m >> 13; + m = _mesa_round_to_even(flt_m / (float) (1 << 13)); } } + assert(0 <= m && m <= 1024); + if (m == 1024) { + /* The float32 was rounded upwards into the range of the next exponent, + * so bump the exponent. This correctly handles the case where f32 + * should be rounded up to float16 infinity. + */ + ++e; + m = 0; + } + result = (s << 15) | (e << 10) | m; return result; } diff --git a/mesalib/src/mesa/main/imports.h b/mesalib/src/mesa/main/imports.h index 8446ea2a3..4b783818b 100644 --- a/mesalib/src/mesa/main/imports.h +++ b/mesalib/src/mesa/main/imports.h @@ -548,6 +548,9 @@ _mesa_fls(unsigned int n) #endif } +extern int +_mesa_round_to_even(float val); + extern GLhalfARB _mesa_float_to_half(float f); diff --git a/mesalib/src/mesa/main/mtypes.h b/mesalib/src/mesa/main/mtypes.h index d37e6c4c0..3369623f7 100644 --- a/mesalib/src/mesa/main/mtypes.h +++ b/mesalib/src/mesa/main/mtypes.h @@ -2273,11 +2273,30 @@ typedef enum struct gl_uniform_buffer_variable { char *Name; + + /** + * Name of the uniform as seen by glGetUniformIndices. + * + * glGetUniformIndices requires that the block instance index \b not be + * present in the name of queried uniforms. + * + * \note + * \c gl_uniform_buffer_variable::IndexName and + * \c gl_uniform_buffer_variable::Name may point to identical storage. + */ + char *IndexName; + const struct glsl_type *Type; unsigned int Offset; GLboolean RowMajor; }; +enum gl_uniform_block_packing { + ubo_packing_std140, + ubo_packing_shared, + ubo_packing_packed +}; + struct gl_uniform_block { /** Declared name of the uniform block */ @@ -2299,6 +2318,14 @@ struct gl_uniform_block * (GL_UNIFORM_BLOCK_DATA_SIZE). */ GLuint UniformBufferSize; + + /** + * Layout specified in the shader + * + * This isn't accessible through the API, but it is used while + * cross-validating uniform blocks. + */ + enum gl_uniform_block_packing _Packing; }; /** @@ -3042,6 +3069,7 @@ struct gl_extensions GLboolean ARB_shader_stencil_export; GLboolean ARB_shader_texture_lod; GLboolean ARB_shading_language_100; + GLboolean ARB_shading_language_packing; GLboolean ARB_shadow; GLboolean ARB_sync; GLboolean ARB_texture_border_clamp; diff --git a/mesalib/src/mesa/main/remap.c b/mesalib/src/mesa/main/remap.c index c89fba453..a09870561 100644 --- a/mesalib/src/mesa/main/remap.c +++ b/mesalib/src/mesa/main/remap.c @@ -208,8 +208,10 @@ _mesa_do_init_remap_table(const char *pool, offset = _mesa_map_function_spec(spec); /* store the dispatch offset in the remap table */ driDispatchRemapTable[i] = offset; - if (offset < 0) - _mesa_warning(NULL, "failed to remap index %d", i); + if (offset < 0) { + const char *name = spec + strlen(spec) + 1; + _mesa_warning(NULL, "failed to remap %s", name); + } } } diff --git a/mesalib/src/mesa/main/shader_query.cpp b/mesalib/src/mesa/main/shader_query.cpp index 27b1b8f56..3014a9778 100644 --- a/mesalib/src/mesa/main/shader_query.cpp +++ b/mesalib/src/mesa/main/shader_query.cpp @@ -106,7 +106,7 @@ _mesa_GetActiveAttrib(GLhandleARB program, GLuint desired_index, const ir_variable *const var = ((ir_instruction *) node)->as_variable(); if (var == NULL - || var->mode != ir_var_in + || var->mode != ir_var_shader_in || var->location == -1) continue; @@ -169,7 +169,7 @@ _mesa_GetAttribLocation(GLhandleARB program, const GLcharARB * name) * attribute, or if an error occurs, -1 will be returned." */ if (var == NULL - || var->mode != ir_var_in + || var->mode != ir_var_shader_in || var->location == -1 || var->location < VERT_ATTRIB_GENERIC0) continue; @@ -197,7 +197,7 @@ _mesa_count_active_attribs(struct gl_shader_program *shProg) const ir_variable *const var = ((ir_instruction *) node)->as_variable(); if (var == NULL - || var->mode != ir_var_in + || var->mode != ir_var_shader_in || var->location == -1) continue; @@ -223,7 +223,7 @@ _mesa_longest_attribute_name_length(struct gl_shader_program *shProg) const ir_variable *const var = ((ir_instruction *) node)->as_variable(); if (var == NULL - || var->mode != ir_var_in + || var->mode != ir_var_shader_in || var->location == -1) continue; @@ -333,7 +333,7 @@ _mesa_GetFragDataIndex(GLuint program, const GLchar *name) * attribute, or if an error occurs, -1 will be returned." */ if (var == NULL - || var->mode != ir_var_out + || var->mode != ir_var_shader_out || var->location == -1 || var->location < FRAG_RESULT_DATA0) continue; @@ -389,7 +389,7 @@ _mesa_GetFragDataLocation(GLuint program, const GLchar *name) * attribute, or if an error occurs, -1 will be returned." */ if (var == NULL - || var->mode != ir_var_out + || var->mode != ir_var_shader_out || var->location == -1 || var->location < FRAG_RESULT_DATA0) continue; diff --git a/mesalib/src/mesa/main/texparam.c b/mesalib/src/mesa/main/texparam.c index 8d0ae16fb..52ede13c0 100644 --- a/mesalib/src/mesa/main/texparam.c +++ b/mesalib/src/mesa/main/texparam.c @@ -1388,10 +1388,10 @@ _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params ) if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture) goto invalid_pname; - params[0] = obj->CropRect[0]; - params[1] = obj->CropRect[1]; - params[2] = obj->CropRect[2]; - params[3] = obj->CropRect[3]; + params[0] = (GLfloat) obj->CropRect[0]; + params[1] = (GLfloat) obj->CropRect[1]; + params[2] = (GLfloat) obj->CropRect[2]; + params[3] = (GLfloat) obj->CropRect[3]; break; case GL_TEXTURE_SWIZZLE_R_EXT: diff --git a/mesalib/src/mesa/main/uniforms.c b/mesalib/src/mesa/main/uniforms.c index 62c85b3c0..d902407a0 100644 --- a/mesalib/src/mesa/main/uniforms.c +++ b/mesalib/src/mesa/main/uniforms.c @@ -695,7 +695,7 @@ _mesa_GetActiveUniformBlockiv(GLuint program, for (i = 0; i < block->NumUniforms; i++) { unsigned offset; params[i] = _mesa_get_uniform_location(ctx, shProg, - block->Uniforms[i].Name, + block->Uniforms[i].IndexName, &offset); } return; diff --git a/mesalib/src/mesa/main/version.c b/mesalib/src/mesa/main/version.c index 4373d7b91..e944a5518 100644 --- a/mesalib/src/mesa/main/version.c +++ b/mesalib/src/mesa/main/version.c @@ -323,7 +323,30 @@ compute_version_es2(struct gl_context *ctx) ctx->Extensions.ARB_fragment_shader && ctx->Extensions.ARB_texture_non_power_of_two && ctx->Extensions.EXT_blend_equation_separate); - if (ver_2_0) { + /* FINISHME: This list isn't quite right. */ + const GLboolean ver_3_0 = (ctx->Extensions.ARB_half_float_vertex && + ctx->Extensions.ARB_internalformat_query && + ctx->Extensions.ARB_map_buffer_range && + ctx->Extensions.ARB_shader_texture_lod && + ctx->Extensions.ARB_texture_float && + ctx->Extensions.ARB_texture_rg && + ctx->Extensions.ARB_texture_compression_rgtc && + ctx->Extensions.EXT_draw_buffers2 && + /* ctx->Extensions.ARB_framebuffer_object && */ + ctx->Extensions.EXT_framebuffer_sRGB && + ctx->Extensions.EXT_packed_float && + ctx->Extensions.EXT_texture_array && + ctx->Extensions.EXT_texture_shared_exponent && + ctx->Extensions.EXT_transform_feedback && + ctx->Extensions.NV_conditional_render && + ctx->Extensions.ARB_draw_instanced && + ctx->Extensions.ARB_uniform_buffer_object && + ctx->Extensions.EXT_texture_snorm && + ctx->Extensions.NV_primitive_restart && + ctx->Extensions.OES_depth_texture_cube_map); + if (ver_3_0) { + ctx->Version = 30; + } else if (ver_2_0) { ctx->Version = 20; } else { _mesa_problem(ctx, "Incomplete OpenGL ES 2.0 support."); diff --git a/mesalib/src/mesa/program/ir_to_mesa.cpp b/mesalib/src/mesa/program/ir_to_mesa.cpp index 0f7439b3b..cd89171da 100644 --- a/mesalib/src/mesa/program/ir_to_mesa.cpp +++ b/mesalib/src/mesa/program/ir_to_mesa.cpp @@ -623,10 +623,14 @@ type_size(const struct glsl_type *type) * at link time. */ return 1; - default: - assert(0); - return 0; + case GLSL_TYPE_VOID: + case GLSL_TYPE_ERROR: + case GLSL_TYPE_INTERFACE: + assert(!"Invalid type in type_size"); + break; } + + return 0; } /** @@ -1427,7 +1431,21 @@ ir_to_mesa_visitor::visit(ir_expression *ir) case ir_unop_fract: emit(ir, OPCODE_FRC, result_dst, op[0]); break; - + case ir_unop_pack_snorm_2x16: + case ir_unop_pack_snorm_4x8: + case ir_unop_pack_unorm_2x16: + case ir_unop_pack_unorm_4x8: + case ir_unop_pack_half_2x16: + case ir_unop_unpack_snorm_2x16: + case ir_unop_unpack_snorm_4x8: + case ir_unop_unpack_unorm_2x16: + case ir_unop_unpack_unorm_4x8: + case ir_unop_unpack_half_2x16: + case ir_unop_unpack_half_2x16_split_x: + case ir_unop_unpack_half_2x16_split_y: + case ir_binop_pack_half_2x16_split: + assert(!"not supported"); + break; case ir_binop_min: emit(ir, OPCODE_MIN, result_dst, op[0], op[1]); break; @@ -1529,21 +1547,18 @@ ir_to_mesa_visitor::visit(ir_dereference_variable *ir) var->location); this->variables.push_tail(entry); break; - case ir_var_in: - case ir_var_inout: + case ir_var_shader_in: /* The linker assigns locations for varyings and attributes, * including deprecated builtins (like gl_Color), * user-assigned generic attributes (glBindVertexLocation), * and user-defined varyings. - * - * FINISHME: We would hit this path for function arguments. Fix! */ assert(var->location != -1); entry = new(mem_ctx) variable_storage(var, PROGRAM_INPUT, var->location); break; - case ir_var_out: + case ir_var_shader_out: assert(var->location != -1); entry = new(mem_ctx) variable_storage(var, PROGRAM_OUTPUT, @@ -2378,7 +2393,8 @@ public: } private: - virtual void visit_field(const glsl_type *type, const char *name); + virtual void visit_field(const glsl_type *type, const char *name, + bool row_major); struct gl_shader_program *shader_program; struct gl_program_parameter_list *params; @@ -2386,10 +2402,13 @@ private: }; void -add_uniform_to_shader::visit_field(const glsl_type *type, const char *name) +add_uniform_to_shader::visit_field(const glsl_type *type, const char *name, + bool row_major) { unsigned int size; + (void) row_major; + if (type->is_vector() || type->is_scalar()) { size = type->vector_elements; } else { @@ -2459,7 +2478,7 @@ _mesa_generate_parameters_list_for_uniforms(struct gl_shader_program ir_variable *var = ((ir_instruction *) node)->as_variable(); if ((var == NULL) || (var->mode != ir_var_uniform) - || var->uniform_block != -1 || (strncmp(var->name, "gl_", 3) == 0)) + || var->is_in_uniform_block() || (strncmp(var->name, "gl_", 3) == 0)) continue; add.process(var); @@ -2522,7 +2541,11 @@ _mesa_associate_uniform_storage(struct gl_context *ctx, format = uniform_native; columns = 1; break; - default: + case GLSL_TYPE_ARRAY: + case GLSL_TYPE_VOID: + case GLSL_TYPE_STRUCT: + case GLSL_TYPE_ERROR: + case GLSL_TYPE_INTERFACE: assert(!"Should not get here."); break; } diff --git a/mesalib/src/mesa/program/program.c b/mesalib/src/mesa/program/program.c index 993803dd5..fb0aeb7ed 100644 --- a/mesalib/src/mesa/program/program.c +++ b/mesalib/src/mesa/program/program.c @@ -696,7 +696,7 @@ _mesa_combine_programs(struct gl_context *ctx, const GLuint newLength = lenA + lenB; GLboolean usedTemps[MAX_PROGRAM_TEMPS]; GLuint firstTemp = 0; - GLbitfield inputsB; + GLbitfield64 inputsB; GLuint i; ASSERT(progA->Target == progB->Target); @@ -724,7 +724,7 @@ _mesa_combine_programs(struct gl_context *ctx, if (newProg->Target == GL_FRAGMENT_PROGRAM_ARB) { const struct gl_fragment_program *fprogA, *fprogB; struct gl_fragment_program *newFprog; - GLbitfield progB_inputsRead = progB->InputsRead; + GLbitfield64 progB_inputsRead = progB->InputsRead; GLint progB_colorFile, progB_colorIndex; fprogA = gl_fragment_program_const(progA); @@ -840,8 +840,8 @@ _mesa_find_used_registers(const struct gl_program *prog, for (j = 0; j < n; j++) { if (inst->SrcReg[j].File == file) { - ASSERT(inst->SrcReg[j].Index < usedSize); - if(inst->SrcReg[j].Index < usedSize) + ASSERT(inst->SrcReg[j].Index < (GLint) usedSize); + if (inst->SrcReg[j].Index < (GLint) usedSize) used[inst->SrcReg[j].Index] = GL_TRUE; } } @@ -908,23 +908,23 @@ _mesa_valid_register_index(const struct gl_context *ctx, return GL_TRUE; /* XXX or maybe false? */ case PROGRAM_TEMPORARY: - return index >= 0 && index < c->MaxTemps; + return index >= 0 && index < (GLint) c->MaxTemps; case PROGRAM_ENV_PARAM: - return index >= 0 && index < c->MaxEnvParams; + return index >= 0 && index < (GLint) c->MaxEnvParams; case PROGRAM_LOCAL_PARAM: - return index >= 0 && index < c->MaxLocalParams; + return index >= 0 && index < (GLint) c->MaxLocalParams; case PROGRAM_UNIFORM: case PROGRAM_STATE_VAR: /* aka constant buffer */ - return index >= 0 && index < c->MaxUniformComponents / 4; + return index >= 0 && index < (GLint) c->MaxUniformComponents / 4; case PROGRAM_CONSTANT: /* constant buffer w/ possible relative negative addressing */ return (index > (int) c->MaxUniformComponents / -4 && - index < c->MaxUniformComponents / 4); + index < (int) c->MaxUniformComponents / 4); case PROGRAM_INPUT: if (index < 0) @@ -932,11 +932,11 @@ _mesa_valid_register_index(const struct gl_context *ctx, switch (shaderType) { case MESA_SHADER_VERTEX: - return index < VERT_ATTRIB_GENERIC0 + c->MaxAttribs; + return index < VERT_ATTRIB_GENERIC0 + (GLint) c->MaxAttribs; case MESA_SHADER_FRAGMENT: - return index < FRAG_ATTRIB_VAR0 + ctx->Const.MaxVarying; + return index < FRAG_ATTRIB_VAR0 + (GLint) ctx->Const.MaxVarying; case MESA_SHADER_GEOMETRY: - return index < GEOM_ATTRIB_VAR0 + ctx->Const.MaxVarying; + return index < GEOM_ATTRIB_VAR0 + (GLint) ctx->Const.MaxVarying; default: return GL_FALSE; } @@ -947,17 +947,17 @@ _mesa_valid_register_index(const struct gl_context *ctx, switch (shaderType) { case MESA_SHADER_VERTEX: - return index < VERT_RESULT_VAR0 + ctx->Const.MaxVarying; + return index < VERT_RESULT_VAR0 + (GLint) ctx->Const.MaxVarying; case MESA_SHADER_FRAGMENT: - return index < FRAG_RESULT_DATA0 + ctx->Const.MaxDrawBuffers; + return index < FRAG_RESULT_DATA0 + (GLint) ctx->Const.MaxDrawBuffers; case MESA_SHADER_GEOMETRY: - return index < GEOM_RESULT_VAR0 + ctx->Const.MaxVarying; + return index < GEOM_RESULT_VAR0 + (GLint) ctx->Const.MaxVarying; default: return GL_FALSE; } case PROGRAM_ADDRESS: - return index >= 0 && index < c->MaxAddressRegs; + return index >= 0 && index < (GLint) c->MaxAddressRegs; default: _mesa_problem(ctx, diff --git a/mesalib/src/mesa/state_tracker/st_cb_bitmap.c b/mesalib/src/mesa/state_tracker/st_cb_bitmap.c index 843dc5be3..63dbdb29b 100644 --- a/mesalib/src/mesa/state_tracker/st_cb_bitmap.c +++ b/mesalib/src/mesa/state_tracker/st_cb_bitmap.c @@ -350,9 +350,8 @@ setup_bitmap_vertex_data(struct st_context *st, bool normalized, tBot = (GLfloat) height; } - u_upload_alloc(st->uploader, 0, 4 * sizeof(vertices[0]), vbuf_offset, vbuf, - (void**)&vertices); - if (!vbuf) { + if (u_upload_alloc(st->uploader, 0, 4 * sizeof(vertices[0]), + vbuf_offset, vbuf, (void **) &vertices) != PIPE_OK) { return; } diff --git a/mesalib/src/mesa/state_tracker/st_cb_clear.c b/mesalib/src/mesa/state_tracker/st_cb_clear.c index d01236e28..a5aa8f496 100644 --- a/mesalib/src/mesa/state_tracker/st_cb_clear.c +++ b/mesalib/src/mesa/state_tracker/st_cb_clear.c @@ -141,9 +141,8 @@ draw_quad(struct st_context *st, GLuint i, offset; float (*vertices)[2][4]; /**< vertex pos + color */ - u_upload_alloc(st->uploader, 0, 4 * sizeof(vertices[0]), &offset, &vbuf, - (void**)&vertices); - if (!vbuf) { + if (u_upload_alloc(st->uploader, 0, 4 * sizeof(vertices[0]), + &offset, &vbuf, (void **) &vertices) != PIPE_OK) { return; } diff --git a/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c b/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c index ff8a9dc43..c944b81f6 100644 --- a/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c @@ -568,9 +568,8 @@ draw_quad(struct gl_context *ctx, GLfloat x0, GLfloat y0, GLfloat z, struct pipe_resource *buf = NULL; unsigned offset; - u_upload_alloc(st->uploader, 0, 4 * sizeof(verts[0]), &offset, &buf, - (void**)&verts); - if (!buf) { + if (u_upload_alloc(st->uploader, 0, 4 * sizeof(verts[0]), &offset, + &buf, (void **) &verts) != PIPE_OK) { return; } @@ -795,7 +794,7 @@ draw_textured_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z, y1 = y + height * ctx->Pixel.ZoomY; /* convert Z from [0,1] to [-1,-1] to match viewport Z scale/bias */ - z = z * 2.0 - 1.0; + z = z * 2.0f - 1.0f; draw_quad(ctx, x0, y0, z, x1, y1, color, invertTex, normalized ? ((GLfloat) width / sv[0]->texture->width0) : (GLfloat)width, @@ -1063,7 +1062,7 @@ static void clamp_size(struct pipe_context *pipe, GLsizei *width, GLsizei *height, struct gl_pixelstore_attrib *unpack) { - const unsigned maxSize = + const int maxSize = 1 << (pipe->screen->get_param(pipe->screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS) - 1); diff --git a/mesalib/src/mesa/state_tracker/st_cb_drawtex.c b/mesalib/src/mesa/state_tracker/st_cb_drawtex.c index 269068da2..5ca097004 100644 --- a/mesalib/src/mesa/state_tracker/st_cb_drawtex.c +++ b/mesalib/src/mesa/state_tracker/st_cb_drawtex.c @@ -148,10 +148,9 @@ st_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z, GLfloat *vbuf = NULL; GLuint attr; - u_upload_alloc(st->uploader, 0, - numAttribs * 4 * 4 * sizeof(GLfloat), - &offset, &vbuffer, (void**)&vbuf); - if (!vbuffer) { + if (u_upload_alloc(st->uploader, 0, + numAttribs * 4 * 4 * sizeof(GLfloat), + &offset, &vbuffer, (void **) &vbuf) != PIPE_OK) { return; } diff --git a/mesalib/src/mesa/state_tracker/st_cb_texture.c b/mesalib/src/mesa/state_tracker/st_cb_texture.c index 7f07b741e..3cea2df07 100644 --- a/mesalib/src/mesa/state_tracker/st_cb_texture.c +++ b/mesalib/src/mesa/state_tracker/st_cb_texture.c @@ -1555,6 +1555,7 @@ void st_init_texture_functions(struct dd_function_table *functions) { functions->ChooseTextureFormat = st_ChooseTextureFormat; + functions->QuerySamplesForFormat = st_QuerySamplesForFormat; functions->TexImage = st_TexImage; functions->TexSubImage = _mesa_store_texsubimage; functions->CompressedTexSubImage = _mesa_store_compressed_texsubimage; diff --git a/mesalib/src/mesa/state_tracker/st_draw.c b/mesalib/src/mesa/state_tracker/st_draw.c index de539ca5a..de62264a1 100644 --- a/mesalib/src/mesa/state_tracker/st_draw.c +++ b/mesalib/src/mesa/state_tracker/st_draw.c @@ -84,7 +84,12 @@ all_varyings_in_vbos(const struct gl_client_array *arrays[]) } -static void +/** + * Basically, translate Mesa's index buffer information into + * a pipe_index_buffer object. + * \return TRUE or FALSE for success/failure + */ +static boolean setup_index_buffer(struct st_context *st, const struct _mesa_index_buffer *ib, struct pipe_index_buffer *ibuffer) @@ -100,8 +105,12 @@ setup_index_buffer(struct st_context *st, ibuffer->offset = pointer_to_offset(ib->ptr); } else if (st->indexbuf_uploader) { - u_upload_data(st->indexbuf_uploader, 0, ib->count * ibuffer->index_size, - ib->ptr, &ibuffer->offset, &ibuffer->buffer); + if (u_upload_data(st->indexbuf_uploader, 0, + ib->count * ibuffer->index_size, ib->ptr, + &ibuffer->offset, &ibuffer->buffer) != PIPE_OK) { + /* out of memory */ + return FALSE; + } u_upload_unmap(st->indexbuf_uploader); } else { @@ -110,6 +119,7 @@ setup_index_buffer(struct st_context *st, } cso_set_index_buffer(st->cso_context, ibuffer); + return TRUE; } @@ -220,7 +230,10 @@ st_draw_vbo(struct gl_context *ctx, vbo_get_minmax_indices(ctx, prims, ib, &min_index, &max_index, nr_prims); - setup_index_buffer(st, ib, &ibuffer); + if (!setup_index_buffer(st, ib, &ibuffer)) { + /* out of memory */ + return; + } info.indexed = TRUE; if (min_index != ~0 && max_index != ~0) { diff --git a/mesalib/src/mesa/state_tracker/st_extensions.c b/mesalib/src/mesa/state_tracker/st_extensions.c index 18d89815d..af54cf7c8 100644 --- a/mesalib/src/mesa/state_tracker/st_extensions.c +++ b/mesalib/src/mesa/state_tracker/st_extensions.c @@ -516,6 +516,7 @@ void st_init_extensions(struct st_context *st) ctx->Extensions.ARB_fragment_shader = GL_TRUE; ctx->Extensions.ARB_half_float_pixel = GL_TRUE; ctx->Extensions.ARB_half_float_vertex = GL_TRUE; + ctx->Extensions.ARB_internalformat_query = GL_TRUE; ctx->Extensions.ARB_map_buffer_range = GL_TRUE; ctx->Extensions.ARB_shader_objects = GL_TRUE; ctx->Extensions.ARB_shading_language_100 = GL_TRUE; @@ -594,9 +595,10 @@ void st_init_extensions(struct st_context *st) ctx->Const.NativeIntegers = GL_TRUE; ctx->Const.MaxClipPlanes = 8; - /* Extensions that only depend on GLSL 1.3. */ + /* Extensions that either depend on GLSL 1.30 or are a subset thereof. */ ctx->Extensions.ARB_conservative_depth = GL_TRUE; ctx->Extensions.ARB_shader_bit_encoding = GL_TRUE; + ctx->Extensions.OES_depth_texture_cube_map = GL_TRUE; } else { /* Optional integer support for GLSL 1.2. */ if (screen->get_shader_param(screen, PIPE_SHADER_VERTEX, diff --git a/mesalib/src/mesa/state_tracker/st_format.c b/mesalib/src/mesa/state_tracker/st_format.c index af81f732d..7ef063953 100644 --- a/mesalib/src/mesa/state_tracker/st_format.c +++ b/mesalib/src/mesa/state_tracker/st_format.c @@ -1642,6 +1642,40 @@ st_ChooseTextureFormat(struct gl_context *ctx, GLenum target, } +/** + * Called via ctx->Driver.ChooseTextureFormat(). + */ +size_t +st_QuerySamplesForFormat(struct gl_context *ctx, GLenum internalFormat, + int samples[16]) +{ + struct pipe_screen *screen = st_context(ctx)->pipe->screen; + enum pipe_format format; + unsigned i, bind, num_sample_counts = 0; + + if (_mesa_is_depth_or_stencil_format(internalFormat)) + bind = PIPE_BIND_DEPTH_STENCIL; + else + bind = PIPE_BIND_RENDER_TARGET; + + /* Set sample counts in descending order. */ + for (i = 16; i > 1; i--) { + format = st_choose_format(screen, internalFormat, GL_NONE, GL_NONE, + PIPE_TEXTURE_2D, i, bind); + + if (format != PIPE_FORMAT_NONE) { + samples[num_sample_counts++] = i; + } + } + + if (!num_sample_counts) { + samples[num_sample_counts++] = 1; + } + + return num_sample_counts; +} + + GLboolean st_sampler_compat_formats(enum pipe_format format1, enum pipe_format format2) { diff --git a/mesalib/src/mesa/state_tracker/st_format.h b/mesalib/src/mesa/state_tracker/st_format.h index 39397b17a..cb6e5bc96 100644 --- a/mesalib/src/mesa/state_tracker/st_format.h +++ b/mesalib/src/mesa/state_tracker/st_format.h @@ -67,6 +67,9 @@ st_ChooseTextureFormat(struct gl_context * ctx, GLenum target, GLint internalFormat, GLenum format, GLenum type); +size_t +st_QuerySamplesForFormat(struct gl_context *ctx, GLenum internalFormat, + int samples[16]); /* can we use a sampler view to translate these formats only used to make TFP so far */ diff --git a/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp index 1d96e905c..c6ac634a2 100644 --- a/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp +++ b/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp @@ -984,10 +984,13 @@ type_size(const struct glsl_type *type) * at link time. */ return 1; - default: - assert(0); - return 0; + case GLSL_TYPE_INTERFACE: + case GLSL_TYPE_VOID: + case GLSL_TYPE_ERROR: + assert(!"Invalid type in type_size"); + break; } + return 0; } /** @@ -1932,10 +1935,23 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir) } break; } + case ir_unop_pack_snorm_2x16: + case ir_unop_pack_unorm_2x16: + case ir_unop_pack_half_2x16: + case ir_unop_pack_snorm_4x8: + case ir_unop_pack_unorm_4x8: + case ir_unop_unpack_snorm_2x16: + case ir_unop_unpack_unorm_2x16: + case ir_unop_unpack_half_2x16: + case ir_unop_unpack_half_2x16_split_x: + case ir_unop_unpack_half_2x16_split_y: + case ir_unop_unpack_snorm_4x8: + case ir_unop_unpack_unorm_4x8: + case ir_binop_pack_half_2x16_split: case ir_quadop_vector: - /* This operation should have already been handled. + /* This operation is not supported, or should have already been handled. */ - assert(!"Should not get here."); + assert(!"Invalid ir opcode in glsl_to_tgsi_visitor::visit()"); break; } @@ -2001,21 +2017,18 @@ glsl_to_tgsi_visitor::visit(ir_dereference_variable *ir) var->location); this->variables.push_tail(entry); break; - case ir_var_in: - case ir_var_inout: + case ir_var_shader_in: /* The linker assigns locations for varyings and attributes, * including deprecated builtins (like gl_Color), user-assign * generic attributes (glBindVertexLocation), and * user-defined varyings. - * - * FINISHME: We would hit this path for function arguments. Fix! */ assert(var->location != -1); entry = new(mem_ctx) variable_storage(var, PROGRAM_INPUT, var->location); break; - case ir_var_out: + case ir_var_shader_out: assert(var->location != -1); entry = new(mem_ctx) variable_storage(var, PROGRAM_OUTPUT, @@ -2304,7 +2317,7 @@ glsl_to_tgsi_visitor::visit(ir_assignment *ir) assert(!ir->lhs->type->is_scalar() && !ir->lhs->type->is_vector()); l.writemask = WRITEMASK_XYZW; } else if (ir->lhs->type->is_scalar() && - ir->lhs->variable_referenced()->mode == ir_var_out) { + ir->lhs->variable_referenced()->mode == ir_var_shader_out) { /* FINISHME: This hack makes writing to gl_FragDepth, which lives in the * FINISHME: W component of fragment shader output zero, work correctly. */ @@ -2581,8 +2594,8 @@ glsl_to_tgsi_visitor::visit(ir_call *ir) ir_rvalue *param_rval = (ir_rvalue *)iter.get(); ir_variable *param = (ir_variable *)sig_iter.get(); - if (param->mode == ir_var_in || - param->mode == ir_var_inout) { + if (param->mode == ir_var_function_in || + param->mode == ir_var_function_inout) { variable_storage *storage = find_variable_storage(param); assert(storage); @@ -2617,8 +2630,8 @@ glsl_to_tgsi_visitor::visit(ir_call *ir) ir_rvalue *param_rval = (ir_rvalue *)iter.get(); ir_variable *param = (ir_variable *)sig_iter.get(); - if (param->mode == ir_var_out || - param->mode == ir_var_inout) { + if (param->mode == ir_var_function_out || + param->mode == ir_var_function_inout) { variable_storage *storage = find_variable_storage(param); assert(storage); diff --git a/mesalib/src/mesa/swrast/s_texfilter.c b/mesalib/src/mesa/swrast/s_texfilter.c index 0a91cca06..953300f65 100644 --- a/mesalib/src/mesa/swrast/s_texfilter.c +++ b/mesalib/src/mesa/swrast/s_texfilter.c @@ -1647,14 +1647,14 @@ sample_2d_ewa(struct gl_context *ctx, GLfloat rgba[]) { GLint level = lod > 0 ? lod : 0; - GLfloat scaling = 1.0 / (1 << level); + GLfloat scaling = 1.0f / (1 << level); const struct gl_texture_image *img = tObj->Image[0][level]; const struct gl_texture_image *mostDetailedImage = tObj->Image[0][tObj->BaseLevel]; const struct swrast_texture_image *swImg = swrast_texture_image_const(mostDetailedImage); - GLfloat tex_u=-0.5 + texcoord[0] * swImg->WidthScale * scaling; - GLfloat tex_v=-0.5 + texcoord[1] * swImg->HeightScale * scaling; + GLfloat tex_u = -0.5f + texcoord[0] * swImg->WidthScale * scaling; + GLfloat tex_v = -0.5f + texcoord[1] * swImg->HeightScale * scaling; GLfloat ux = dudx * scaling; GLfloat vx = dvdx * scaling; @@ -1667,20 +1667,20 @@ sample_2d_ewa(struct gl_context *ctx, GLfloat A = vx*vx+vy*vy+1; GLfloat B = -2*(ux*vx+uy*vy); GLfloat C = ux*ux+uy*uy+1; - GLfloat F = A*C-B*B/4.0; + GLfloat F = A*C-B*B/4.0f; /* check if it is an ellipse */ /* ASSERT(F > 0.0); */ /* Compute the ellipse's (u,v) bounding box in texture space */ - GLfloat d = -B*B+4.0*C*A; - GLfloat box_u = 2.0 / d * sqrt(d*C*F); /* box_u -> half of bbox with */ - GLfloat box_v = 2.0 / d * sqrt(A*d*F); /* box_v -> half of bbox height */ + GLfloat d = -B*B+4.0f*C*A; + GLfloat box_u = 2.0f / d * sqrtf(d*C*F); /* box_u -> half of bbox with */ + GLfloat box_v = 2.0f / d * sqrtf(A*d*F); /* box_v -> half of bbox height */ - GLint u0 = floor(tex_u - box_u); - GLint u1 = ceil (tex_u + box_u); - GLint v0 = floor(tex_v - box_v); - GLint v1 = ceil (tex_v + box_v); + GLint u0 = (GLint) floorf(tex_u - box_u); + GLint u1 = (GLint) ceilf (tex_u + box_u); + GLint v0 = (GLint) floorf(tex_v - box_v); + GLint v1 = (GLint) ceilf (tex_v + box_v); GLfloat num[4] = {0.0F, 0.0F, 0.0F, 0.0F}; GLfloat newCoord[2]; @@ -1692,7 +1692,7 @@ sample_2d_ewa(struct gl_context *ctx, /* Scale ellipse formula to directly index the Filter Lookup Table. * i.e. scale so that F = WEIGHT_LUT_SIZE-1 */ - double formScale = (double) (WEIGHT_LUT_SIZE - 1) / F; + GLfloat formScale = (GLfloat) (WEIGHT_LUT_SIZE - 1) / F; A *= formScale; B *= formScale; C *= formScale; @@ -1715,7 +1715,7 @@ sample_2d_ewa(struct gl_context *ctx, /* as a LUT is used, q must never be negative; * should not happen, though */ - const GLint qClamped = q >= 0.0F ? q : 0; + const GLint qClamped = q >= 0.0F ? (GLint) q : 0; GLfloat weight = weightLut[qClamped]; newCoord[0] = u / ((GLfloat) img->Width2); @@ -1795,19 +1795,19 @@ sample_2d_footprint(struct gl_context *ctx, /* Calculate the per anisotropic sample offsets in s,t space. */ if (Px2 > Py2) { - numSamples = ceil(sqrtf(Px2)); + numSamples = (GLint) ceilf(sqrtf(Px2)); ds = ux / ((GLfloat) img->Width2); dt = vx / ((GLfloat) img->Height2); } else { - numSamples = ceil(sqrtf(Py2)); + numSamples = (GLint) ceilf(sqrtf(Py2)); ds = uy / ((GLfloat) img->Width2); dt = vy / ((GLfloat) img->Height2); } for (s = 0; s<numSamples; s++) { - newCoord[0] = texcoord[0] + ds * ((GLfloat)(s+1) / (numSamples+1) -0.5); - newCoord[1] = texcoord[1] + dt * ((GLfloat)(s+1) / (numSamples+1) -0.5); + newCoord[0] = texcoord[0] + ds * ((GLfloat)(s+1) / (numSamples+1) -0.5f); + newCoord[1] = texcoord[1] + dt * ((GLfloat)(s+1) / (numSamples+1) -0.5f); sample_2d_linear(ctx, samp, img, newCoord, rgba); num[0] += rgba[0]; @@ -1956,7 +1956,7 @@ sample_lambda_2d_aniso(struct gl_context *ctx, /* note: we need to have Pmin=sqrt(Pmin2) here, but we can avoid * this since 0.5*log(x) = log(sqrt(x)) */ - lod = 0.5 * LOG2(Pmin2); + lod = 0.5f * LOG2(Pmin2); if (adjustLOD) { /* from swrast/s_texcombine.c _swrast_texture_span */ @@ -1988,7 +1988,7 @@ sample_lambda_2d_aniso(struct gl_context *ctx, * seem to be worth the extra running time. */ sample_2d_ewa(ctx, samp, tObj, texcoords[i], - dudx, dvdx, dudy, dvdy, floor(lod), rgba[i]); + dudx, dvdx, dudy, dvdy, (GLint) floorf(lod), rgba[i]); /* unused: */ (void) sample_2d_footprint; diff --git a/mesalib/src/mesa/vbo/vbo_exec_api.c b/mesalib/src/mesa/vbo/vbo_exec_api.c index 985f2209c..353f8cfde 100644 --- a/mesalib/src/mesa/vbo/vbo_exec_api.c +++ b/mesalib/src/mesa/vbo/vbo_exec_api.c @@ -124,6 +124,11 @@ void vbo_exec_vtx_wrap( struct vbo_exec_context *exec ) */ vbo_exec_wrap_buffers( exec ); + if (!exec->vtx.buffer_ptr) { + /* probably ran out of memory earlier when allocating the VBO */ + return; + } + /* Copy stored stored vertices to start of new list. */ assert(exec->vtx.max_vert - exec->vtx.vert_count > exec->vtx.copied.nr); |