diff options
Diffstat (limited to 'mesalib/src/mesa/state_tracker')
-rw-r--r-- | mesalib/src/mesa/state_tracker/st_atom_texture.c | 35 | ||||
-rw-r--r-- | mesalib/src/mesa/state_tracker/st_cb_drawpixels.c | 24 | ||||
-rw-r--r-- | mesalib/src/mesa/state_tracker/st_cb_texture.c | 2 | ||||
-rw-r--r-- | mesalib/src/mesa/state_tracker/st_format.c | 84 | ||||
-rw-r--r-- | mesalib/src/mesa/state_tracker/st_format.h | 6 | ||||
-rw-r--r-- | mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 28 | ||||
-rw-r--r-- | mesalib/src/mesa/state_tracker/st_texture.c | 3 |
7 files changed, 88 insertions, 94 deletions
diff --git a/mesalib/src/mesa/state_tracker/st_atom_texture.c b/mesalib/src/mesa/state_tracker/st_atom_texture.c index 4b43b2a7d..28327bc14 100644 --- a/mesalib/src/mesa/state_tracker/st_atom_texture.c +++ b/mesalib/src/mesa/state_tracker/st_atom_texture.c @@ -214,7 +214,7 @@ update_single_texture(struct st_context *st, const struct gl_sampler_object *samp; struct gl_texture_object *texObj; struct st_texture_object *stObj; - enum pipe_format st_view_format; + enum pipe_format view_format; GLboolean retval; samp = _mesa_get_samplerobj(ctx, texUnit); @@ -234,32 +234,11 @@ update_single_texture(struct st_context *st, } /* Determine the format of the texture sampler view */ - st_view_format = stObj->pt->format; - - { - gl_format texFormat; - enum pipe_format firstImageFormat; - - if (texObj->Target == GL_TEXTURE_BUFFER) { - texFormat = stObj->base._BufferObjectFormat; - } else { - const struct st_texture_image *firstImage = - st_texture_image(stObj->base.Image[0][stObj->base.BaseLevel]); - texFormat = firstImage->base.TexFormat; - } - firstImageFormat = st_mesa_format_to_pipe_format(texFormat); - if ((samp->sRGBDecode == GL_SKIP_DECODE_EXT) && - (_mesa_get_format_color_encoding(texFormat) == GL_SRGB)) { - /* Don't do sRGB->RGB conversion. Interpret the texture data as - * linear values. - */ - const gl_format linearFormat = - _mesa_get_srgb_format_linear(texFormat); - firstImageFormat = st_mesa_format_to_pipe_format(linearFormat); - } + view_format = stObj->pt->format; - if (firstImageFormat != stObj->pt->format) - st_view_format = firstImageFormat; + /* If sRGB decoding is off, use the linear format */ + if (samp->sRGBDecode == GL_SKIP_DECODE_EXT) { + view_format = util_format_linear(view_format); } /* if sampler view has changed dereference it */ @@ -267,7 +246,7 @@ update_single_texture(struct st_context *st, if (check_sampler_swizzle(stObj->sampler_view, stObj->base._Swizzle, stObj->base.DepthMode) || - (st_view_format != stObj->sampler_view->format) || + (view_format != stObj->sampler_view->format) || stObj->base.BaseLevel != stObj->sampler_view->u.tex.first_level) { pipe_sampler_view_reference(&stObj->sampler_view, NULL); } @@ -275,7 +254,7 @@ update_single_texture(struct st_context *st, *sampler_view = st_get_texture_sampler_view_from_stobj(stObj, pipe, samp, - st_view_format); + view_format); return GL_TRUE; } diff --git a/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c b/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c index c944b81f6..26d1923b5 100644 --- a/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c @@ -489,12 +489,14 @@ make_texture(struct st_context *st, intFormat = internal_format(ctx, format, type); baseInternalFormat = _mesa_base_tex_format(ctx, intFormat); - mformat = st_ChooseTextureFormat_renderable(ctx, intFormat, - format, type, GL_FALSE); - assert(mformat); - - pipeFormat = st_mesa_format_to_pipe_format(mformat); - assert(pipeFormat); + /* Choose a pixel format for the temp texture which will hold the + * image to draw. + */ + pipeFormat = st_choose_format(pipe->screen, intFormat, format, type, + PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW, + FALSE); + assert(pipeFormat != PIPE_FORMAT_NONE); + mformat = st_pipe_format_to_mesa_format(pipeFormat); pixels = _mesa_map_pbo_source(ctx, unpack, pixels); if (!pixels) @@ -1462,8 +1464,8 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy, driver_vp = make_passthrough_vertex_shader(st, GL_FALSE); if (st->pixel_xfer.pixelmap_enabled) { - sv[1] = st->pixel_xfer.pixelmap_sampler_view; - num_sampler_view++; + sv[1] = st->pixel_xfer.pixelmap_sampler_view; + num_sampler_view++; } } else { @@ -1499,14 +1501,16 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy, if (type == GL_DEPTH) { texFormat = st_choose_format(screen, GL_DEPTH_COMPONENT, GL_NONE, GL_NONE, st->internal_target, - sample_count, PIPE_BIND_DEPTH_STENCIL); + sample_count, PIPE_BIND_DEPTH_STENCIL, + FALSE); assert(texFormat != PIPE_FORMAT_NONE); } else { /* default color format */ texFormat = st_choose_format(screen, GL_RGBA, GL_NONE, GL_NONE, st->internal_target, - sample_count, PIPE_BIND_SAMPLER_VIEW); + sample_count, PIPE_BIND_SAMPLER_VIEW, + FALSE); assert(texFormat != PIPE_FORMAT_NONE); } } diff --git a/mesalib/src/mesa/state_tracker/st_cb_texture.c b/mesalib/src/mesa/state_tracker/st_cb_texture.c index 3cea2df07..80a440d18 100644 --- a/mesalib/src/mesa/state_tracker/st_cb_texture.c +++ b/mesalib/src/mesa/state_tracker/st_cb_texture.c @@ -597,7 +597,7 @@ decompress_with_blit(struct gl_context * ctx, /* Find the best match for the format+type combo. */ pipe_format = st_choose_format(pipe->screen, GL_RGBA8, format, type, - pipe_target, 0, bind); + pipe_target, 0, bind, FALSE); if (pipe_format == PIPE_FORMAT_NONE) { /* unable to get an rgba format!?! */ _mesa_problem(ctx, "%s: cannot find a supported format", __func__); diff --git a/mesalib/src/mesa/state_tracker/st_format.c b/mesalib/src/mesa/state_tracker/st_format.c index 7ef063953..2169bed89 100644 --- a/mesalib/src/mesa/state_tracker/st_format.c +++ b/mesalib/src/mesa/state_tracker/st_format.c @@ -1398,18 +1398,25 @@ static const struct format_mapping format_map[] = { /** * Return first supported format from the given list. + * \param allow_dxt indicates whether it's OK to return a DXT format. */ static enum pipe_format find_supported_format(struct pipe_screen *screen, const enum pipe_format formats[], enum pipe_texture_target target, unsigned sample_count, - unsigned tex_usage) + unsigned tex_usage, + boolean allow_dxt) { uint i; for (i = 0; formats[i]; i++) { if (screen->is_format_supported(screen, formats[i], target, sample_count, tex_usage)) { + if (!allow_dxt && util_format_is_s3tc(formats[i])) { + /* we can't return a dxt format, continue searching */ + continue; + } + return formats[i]; } } @@ -1514,12 +1521,16 @@ find_exact_format(GLint internalFormat, GLenum format, GLenum type) * \param internalFormat the user value passed to glTexImage2D * \param target one of PIPE_TEXTURE_x * \param bindings bitmask of PIPE_BIND_x flags. + * \param allow_dxt indicates whether it's OK to return a DXT format. This + * only matters when internalFormat names a generic or + * specific compressed format. And that should only happen + * when we're getting called from gl[Copy]TexImage(). */ enum pipe_format st_choose_format(struct pipe_screen *screen, GLenum internalFormat, GLenum format, GLenum type, enum pipe_texture_target target, unsigned sample_count, - unsigned bindings) + unsigned bindings, boolean allow_dxt) { GET_CURRENT_CONTEXT(ctx); /* XXX this should be a function parameter */ int i, j; @@ -1547,7 +1558,8 @@ st_choose_format(struct pipe_screen *screen, GLenum internalFormat, * which is supported by the driver. */ return find_supported_format(screen, mapping->pipeFormats, - target, sample_count, bindings); + target, sample_count, bindings, + allow_dxt); } } } @@ -1569,27 +1581,42 @@ st_choose_renderbuffer_format(struct pipe_screen *screen, usage = PIPE_BIND_DEPTH_STENCIL; else usage = PIPE_BIND_RENDER_TARGET; - return st_choose_format(screen, internalFormat, GL_NONE, GL_NONE, PIPE_TEXTURE_2D, - sample_count, usage); + return st_choose_format(screen, internalFormat, GL_NONE, GL_NONE, + PIPE_TEXTURE_2D, sample_count, usage, FALSE); } +/** + * Called via ctx->Driver.ChooseTextureFormat(). + */ gl_format -st_ChooseTextureFormat_renderable(struct gl_context *ctx, GLint internalFormat, - GLenum format, GLenum type, GLboolean renderable) +st_ChooseTextureFormat(struct gl_context *ctx, GLenum target, + GLint internalFormat, + GLenum format, GLenum type) { + const boolean want_renderable = + internalFormat == 3 || internalFormat == 4 || + internalFormat == GL_RGB || internalFormat == GL_RGBA || + internalFormat == GL_RGB8 || internalFormat == GL_RGBA8 || + internalFormat == GL_BGRA; struct pipe_screen *screen = st_context(ctx)->pipe->screen; enum pipe_format pFormat; - uint bindings; + unsigned bindings; - (void) format; - (void) type; + if (target == GL_TEXTURE_1D || target == GL_TEXTURE_1D_ARRAY) { + /* We don't do compression for these texture targets because of + * difficulty with sub-texture updates on non-block boundaries, etc. + * So change the internal format request to an uncompressed format. + */ + internalFormat = + _mesa_generic_compressed_format_to_uncompressed_format(internalFormat); + } /* GL textures may wind up being render targets, but we don't know * that in advance. Specify potential render target flags now. */ bindings = PIPE_BIND_SAMPLER_VIEW; - if (renderable) { + if (want_renderable) { if (_mesa_is_depth_or_stencil_format(internalFormat)) bindings |= PIPE_BIND_DEPTH_STENCIL; else @@ -1597,12 +1624,13 @@ st_ChooseTextureFormat_renderable(struct gl_context *ctx, GLint internalFormat, } pFormat = st_choose_format(screen, internalFormat, format, type, - PIPE_TEXTURE_2D, 0, bindings); + PIPE_TEXTURE_2D, 0, bindings, ctx->Mesa_DXTn); if (pFormat == PIPE_FORMAT_NONE) { /* try choosing format again, this time without render target bindings */ pFormat = st_choose_format(screen, internalFormat, format, type, - PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW); + PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW, + ctx->Mesa_DXTn); } if (pFormat == PIPE_FORMAT_NONE) { @@ -1617,34 +1645,6 @@ st_ChooseTextureFormat_renderable(struct gl_context *ctx, GLint internalFormat, /** * Called via ctx->Driver.ChooseTextureFormat(). */ -gl_format -st_ChooseTextureFormat(struct gl_context *ctx, GLenum target, - GLint internalFormat, - GLenum format, GLenum type) -{ - boolean want_renderable = - internalFormat == 3 || internalFormat == 4 || - internalFormat == GL_RGB || internalFormat == GL_RGBA || - internalFormat == GL_RGB8 || internalFormat == GL_RGBA8 || - internalFormat == GL_BGRA; - - if (target == GL_TEXTURE_1D || target == GL_TEXTURE_1D_ARRAY) { - /* We don't do compression for these texture targets because of - * difficulty with sub-texture updates on non-block boundaries, etc. - * So change the internal format request to an uncompressed format. - */ - internalFormat = - _mesa_generic_compressed_format_to_uncompressed_format(internalFormat); - } - - return st_ChooseTextureFormat_renderable(ctx, internalFormat, - format, type, want_renderable); -} - - -/** - * Called via ctx->Driver.ChooseTextureFormat(). - */ size_t st_QuerySamplesForFormat(struct gl_context *ctx, GLenum internalFormat, int samples[16]) @@ -1661,7 +1661,7 @@ st_QuerySamplesForFormat(struct gl_context *ctx, GLenum internalFormat, /* 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); + PIPE_TEXTURE_2D, i, bind, FALSE); if (format != PIPE_FORMAT_NONE) { samples[num_sample_counts++] = i; diff --git a/mesalib/src/mesa/state_tracker/st_format.h b/mesalib/src/mesa/state_tracker/st_format.h index cb6e5bc96..50588d8d4 100644 --- a/mesalib/src/mesa/state_tracker/st_format.h +++ b/mesalib/src/mesa/state_tracker/st_format.h @@ -51,17 +51,13 @@ extern enum pipe_format st_choose_format(struct pipe_screen *screen, GLenum internalFormat, GLenum format, GLenum type, enum pipe_texture_target target, unsigned sample_count, - unsigned bindings); + unsigned bindings, boolean allow_dxt); extern enum pipe_format st_choose_renderbuffer_format(struct pipe_screen *screen, GLenum internalFormat, unsigned sample_count); -gl_format -st_ChooseTextureFormat_renderable(struct gl_context *ctx, GLint internalFormat, - GLenum format, GLenum type, GLboolean renderable); - extern gl_format st_ChooseTextureFormat(struct gl_context * ctx, GLenum target, GLint internalFormat, 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 c6ac634a2..b3da2016d 100644 --- a/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp +++ b/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp @@ -322,6 +322,7 @@ public: int glsl_version; bool native_integers; + bool have_sqrt; variable_storage *find_variable_storage(ir_variable *var); @@ -1761,13 +1762,18 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir) break; case ir_unop_sqrt: - /* sqrt(x) = x * rsq(x). */ - emit_scalar(ir, TGSI_OPCODE_RSQ, result_dst, op[0]); - emit(ir, TGSI_OPCODE_MUL, result_dst, result_src, op[0]); - /* For incoming channels <= 0, set the result to 0. */ - op[0].negate = ~op[0].negate; - emit(ir, TGSI_OPCODE_CMP, result_dst, - op[0], result_src, st_src_reg_for_float(0.0)); + if (have_sqrt) { + emit_scalar(ir, TGSI_OPCODE_SQRT, result_dst, op[0]); + } + else { + /* sqrt(x) = x * rsq(x). */ + emit_scalar(ir, TGSI_OPCODE_RSQ, result_dst, op[0]); + emit(ir, TGSI_OPCODE_MUL, result_dst, result_src, op[0]); + /* For incoming channels <= 0, set the result to 0. */ + op[0].negate = ~op[0].negate; + emit(ir, TGSI_OPCODE_CMP, result_dst, + op[0], result_src, st_src_reg_for_float(0.0)); + } break; case ir_unop_rsq: emit_scalar(ir, TGSI_OPCODE_RSQ, result_dst, op[0]); @@ -4956,18 +4962,23 @@ get_mesa_program(struct gl_context *ctx, bool progress; struct gl_shader_compiler_options *options = &ctx->ShaderCompilerOptions[_mesa_shader_type_to_index(shader->Type)]; + struct pipe_screen *pscreen = ctx->st->pipe->screen; + unsigned ptarget; switch (shader->Type) { case GL_VERTEX_SHADER: target = GL_VERTEX_PROGRAM_ARB; + ptarget = PIPE_SHADER_VERTEX; target_string = "vertex"; break; case GL_FRAGMENT_SHADER: target = GL_FRAGMENT_PROGRAM_ARB; + ptarget = PIPE_SHADER_FRAGMENT; target_string = "fragment"; break; case GL_GEOMETRY_SHADER: target = GL_GEOMETRY_PROGRAM_NV; + ptarget = PIPE_SHADER_GEOMETRY; target_string = "geometry"; break; default: @@ -4989,6 +5000,9 @@ get_mesa_program(struct gl_context *ctx, v->glsl_version = ctx->Const.GLSLVersion; v->native_integers = ctx->Const.NativeIntegers; + v->have_sqrt = pscreen->get_shader_param(pscreen, ptarget, + PIPE_SHADER_CAP_TGSI_SQRT_SUPPORTED); + _mesa_generate_parameters_list_for_uniforms(shader_program, shader, prog->Parameters); diff --git a/mesalib/src/mesa/state_tracker/st_texture.c b/mesalib/src/mesa/state_tracker/st_texture.c index ee4d7622d..584eaa981 100644 --- a/mesalib/src/mesa/state_tracker/st_texture.c +++ b/mesalib/src/mesa/state_tracker/st_texture.c @@ -398,7 +398,8 @@ st_create_color_map_texture(struct gl_context *ctx) /* find an RGBA texture format */ format = st_choose_format(pipe->screen, GL_RGBA, GL_NONE, GL_NONE, - PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW); + PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW, + FALSE); /* create texture for color map/table */ pt = st_texture_create(st, PIPE_TEXTURE_2D, format, 0, |