GL 3.1 promoted GL_RGBA to core, and added GL_R and GL_RG. It dropped A/I/L/LA formats. Our hardware doesn't support the A/I/L/LA formats, so if we want to support GL_ARB_texture_buffer_object on its own, we have to map them to RG and swizzle their data into place. --- src/mesa/drivers/dri/i965/brw_wm.c | 89 +++++++++++++++------ src/mesa/drivers/dri/i965/gen7_wm_surface_state.c | 36 ++++++++- 2 files changed, 99 insertions(+), 26 deletions(-)
diff --git a/src/mesa/drivers/dri/i965/brw_wm.c b/src/mesa/drivers/dri/i965/brw_wm.c index b358306..18a4bd4 100644 --- a/src/mesa/drivers/dri/i965/brw_wm.c +++ b/src/mesa/drivers/dri/i965/brw_wm.c @@ -328,22 +328,64 @@ brw_populate_sampler_prog_key_data(struct gl_context *ctx, { const struct gl_texture_unit *unit = &ctx->Texture.Unit[i]; - if (unit->_ReallyEnabled && unit->_Current->Target != GL_TEXTURE_BUFFER) { - const struct gl_texture_object *t = unit->_Current; - const struct gl_texture_image *img = t->Image[0][t->BaseLevel]; - struct gl_sampler_object *sampler = _mesa_get_samplerobj(ctx, i); - int swizzles[SWIZZLE_NIL + 1] = { - SWIZZLE_X, - SWIZZLE_Y, - SWIZZLE_Z, - SWIZZLE_W, - SWIZZLE_ZERO, - SWIZZLE_ONE, - SWIZZLE_NIL - }; - - if (img->_BaseFormat == GL_DEPTH_COMPONENT || - img->_BaseFormat == GL_DEPTH_STENCIL) { + if (!unit->_ReallyEnabled) { + key->swizzles[i] = SWIZZLE_NOOP; + return; + } + + const struct gl_texture_object *t = unit->_Current; + const struct gl_texture_image *img; + struct gl_sampler_object *sampler = _mesa_get_samplerobj(ctx, i); + int swizzles[SWIZZLE_NIL + 1] = { + SWIZZLE_X, + SWIZZLE_Y, + SWIZZLE_Z, + SWIZZLE_W, + SWIZZLE_ZERO, + SWIZZLE_ONE, + SWIZZLE_NIL + }; + + if (t->Target != GL_TEXTURE_BUFFER) + img = t->Image[0][t->BaseLevel]; + else + img = NULL; + + if (t->Target == GL_TEXTURE_BUFFER) { + /* The hardware doesn't have support for the deprecated integer formats, + * so we map them to R/RG in the surface, and swizzle the channels here. + */ + if (_mesa_is_format_integer_color(t->_BufferObjectFormat)) { + switch (_mesa_get_format_base_format(t->_BufferObjectFormat)) { + case GL_ALPHA: + swizzles[0] = SWIZZLE_ZERO; + swizzles[1] = SWIZZLE_ZERO; + swizzles[2] = SWIZZLE_ZERO; + swizzles[3] = SWIZZLE_X; + break; + case GL_LUMINANCE: + swizzles[0] = SWIZZLE_X; + swizzles[1] = SWIZZLE_X; + swizzles[2] = SWIZZLE_X; + swizzles[3] = SWIZZLE_ONE; + break; + case GL_LUMINANCE_ALPHA: + swizzles[0] = SWIZZLE_X; + swizzles[1] = SWIZZLE_X; + swizzles[2] = SWIZZLE_X; + swizzles[3] = SWIZZLE_Y; + break; + case GL_INTENSITY: + swizzles[0] = SWIZZLE_X; + swizzles[1] = SWIZZLE_X; + swizzles[2] = SWIZZLE_X; + swizzles[3] = SWIZZLE_X; + break; + } + } + } else { + if ((img->_BaseFormat == GL_DEPTH_COMPONENT || + img->_BaseFormat == GL_DEPTH_STENCIL)) { if (sampler->CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB) key->compare_funcs[i] = sampler->CompareFunc; @@ -385,12 +427,6 @@ brw_populate_sampler_prog_key_data(struct gl_context *ctx, key->yuvtex_swap_mask |= 1 << i; } - key->swizzles[i] = - MAKE_SWIZZLE4(swizzles[GET_SWZ(t->_Swizzle, 0)], - swizzles[GET_SWZ(t->_Swizzle, 1)], - swizzles[GET_SWZ(t->_Swizzle, 2)], - swizzles[GET_SWZ(t->_Swizzle, 3)]); - if (sampler->MinFilter != GL_NEAREST && sampler->MagFilter != GL_NEAREST) { if (sampler->WrapS == GL_CLAMP) @@ -401,9 +437,12 @@ brw_populate_sampler_prog_key_data(struct gl_context *ctx, key->gl_clamp_mask[2] |= 1 << i; } } - else { - key->swizzles[i] = SWIZZLE_NOOP; - } + + key->swizzles[i] = + MAKE_SWIZZLE4(swizzles[GET_SWZ(t->_Swizzle, 0)], + swizzles[GET_SWZ(t->_Swizzle, 1)], + swizzles[GET_SWZ(t->_Swizzle, 2)], + swizzles[GET_SWZ(t->_Swizzle, 3)]); } static void brw_wm_populate_key( struct brw_context *brw, diff --git a/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c b/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c index 1ebecc7..c093975 100644 --- a/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c +++ b/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c @@ -54,6 +54,36 @@ gen7_set_surface_tiling(struct gen7_surface_state *surf, uint32_t tiling) } } +const uint32_t buffer_format_overrides[MESA_FORMAT_COUNT] = { + [MESA_FORMAT_ALPHA_INT8] = BRW_SURFACEFORMAT_R8_SINT, + [MESA_FORMAT_ALPHA_INT16] = BRW_SURFACEFORMAT_R16_SINT, + [MESA_FORMAT_ALPHA_INT32] = BRW_SURFACEFORMAT_R32_SINT, + [MESA_FORMAT_ALPHA_UINT8] = BRW_SURFACEFORMAT_R8_UINT, + [MESA_FORMAT_ALPHA_UINT16] = BRW_SURFACEFORMAT_R16_UINT, + [MESA_FORMAT_ALPHA_UINT32] = BRW_SURFACEFORMAT_R32_UINT, + + [MESA_FORMAT_INTENSITY_INT8] = BRW_SURFACEFORMAT_R8_SINT, + [MESA_FORMAT_INTENSITY_INT16] = BRW_SURFACEFORMAT_R16_SINT, + [MESA_FORMAT_INTENSITY_INT32] = BRW_SURFACEFORMAT_R32_SINT, + [MESA_FORMAT_INTENSITY_UINT8] = BRW_SURFACEFORMAT_R8_UINT, + [MESA_FORMAT_INTENSITY_UINT16] = BRW_SURFACEFORMAT_R16_UINT, + [MESA_FORMAT_INTENSITY_UINT32] = BRW_SURFACEFORMAT_R32_UINT, + + [MESA_FORMAT_LUMINANCE_INT8] = BRW_SURFACEFORMAT_R8_SINT, + [MESA_FORMAT_LUMINANCE_INT16] = BRW_SURFACEFORMAT_R16_SINT, + [MESA_FORMAT_LUMINANCE_INT32] = BRW_SURFACEFORMAT_R32_SINT, + [MESA_FORMAT_LUMINANCE_UINT8] = BRW_SURFACEFORMAT_R8_UINT, + [MESA_FORMAT_LUMINANCE_UINT16] = BRW_SURFACEFORMAT_R16_UINT, + [MESA_FORMAT_LUMINANCE_UINT32] = BRW_SURFACEFORMAT_R32_UINT, + + [MESA_FORMAT_LUMINANCE_ALPHA_INT8] = BRW_SURFACEFORMAT_R8G8_SINT, + [MESA_FORMAT_LUMINANCE_ALPHA_INT16] = BRW_SURFACEFORMAT_R16G16_SINT, + [MESA_FORMAT_LUMINANCE_ALPHA_INT32] = BRW_SURFACEFORMAT_R32G32_SINT, + [MESA_FORMAT_LUMINANCE_ALPHA_UINT8] = BRW_SURFACEFORMAT_R8G8_UINT, + [MESA_FORMAT_LUMINANCE_ALPHA_UINT16] = BRW_SURFACEFORMAT_R16G16_UINT, + [MESA_FORMAT_LUMINANCE_ALPHA_UINT32] = BRW_SURFACEFORMAT_R32G32_UINT, +}; + static void gen7_update_buffer_texture_surface(struct gl_context *ctx, GLuint unit) { @@ -72,7 +102,11 @@ gen7_update_buffer_texture_surface(struct gl_context *ctx, GLuint unit) memset(surf, 0, sizeof(*surf)); surf->ss0.surface_type = BRW_SURFACE_BUFFER; - surf->ss0.surface_format = brw_format_for_mesa_format(format); + + if (buffer_format_overrides[format]) + surf->ss0.surface_format = buffer_format_overrides[format]; + else + surf->ss0.surface_format = brw_format_for_mesa_format(format); surf->ss0.render_cache_read_write = 1; -- 1.7.9.1 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev