st/mesa: add st_context parameter to st_mesa_format_to_pipe_format

This will be used by the next commit.

Reviewed-by: Glenn Kennard <glenn.kennard@gmail.com>
This commit is contained in:
Marek Olšák
2014-08-02 21:00:41 +02:00
parent 3d56732c1f
commit 547e2880bc
9 changed files with 32 additions and 29 deletions

View File

@@ -338,7 +338,7 @@ update_single_texture(struct st_context *st,
/* Determine the format of the texture sampler view */ /* Determine the format of the texture sampler view */
if (texObj->Target == GL_TEXTURE_BUFFER) { if (texObj->Target == GL_TEXTURE_BUFFER) {
view_format = view_format =
st_mesa_format_to_pipe_format(stObj->base._BufferObjectFormat); st_mesa_format_to_pipe_format(st, stObj->base._BufferObjectFormat);
} }
else { else {
view_format = view_format =

View File

@@ -491,7 +491,7 @@ make_texture(struct st_context *st,
/* Choose a pixel format for the temp texture which will hold the /* Choose a pixel format for the temp texture which will hold the
* image to draw. * image to draw.
*/ */
pipeFormat = st_choose_matching_format(pipe->screen, PIPE_BIND_SAMPLER_VIEW, pipeFormat = st_choose_matching_format(st, PIPE_BIND_SAMPLER_VIEW,
format, type, unpack->SwapBytes); format, type, unpack->SwapBytes);
if (pipeFormat == PIPE_FORMAT_NONE) { if (pipeFormat == PIPE_FORMAT_NONE) {

View File

@@ -588,7 +588,7 @@ st_validate_attachment(struct gl_context *ctx,
if (!ctx->Extensions.EXT_framebuffer_sRGB && if (!ctx->Extensions.EXT_framebuffer_sRGB &&
_mesa_get_format_color_encoding(texFormat) == GL_SRGB) { _mesa_get_format_color_encoding(texFormat) == GL_SRGB) {
const mesa_format linearFormat = _mesa_get_srgb_format_linear(texFormat); const mesa_format linearFormat = _mesa_get_srgb_format_linear(texFormat);
format = st_mesa_format_to_pipe_format(linearFormat); format = st_mesa_format_to_pipe_format(st_context(ctx), linearFormat);
} }
valid = screen->is_format_supported(screen, format, valid = screen->is_format_supported(screen, format,

View File

@@ -143,7 +143,7 @@ st_readpixels(struct gl_context *ctx, GLint x, GLint y,
/* Choose the destination format by finding the best match /* Choose the destination format by finding the best match
* for the format+type combo. */ * for the format+type combo. */
dst_format = st_choose_matching_format(screen, bind, format, type, dst_format = st_choose_matching_format(st, bind, format, type,
pack->SwapBytes); pack->SwapBytes);
if (dst_format == PIPE_FORMAT_NONE) { if (dst_format == PIPE_FORMAT_NONE) {
goto fallback; goto fallback;

View File

@@ -442,7 +442,7 @@ guess_and_alloc_texture(struct st_context *st,
stObj->height0 = height; stObj->height0 = height;
stObj->depth0 = depth; stObj->depth0 = depth;
fmt = st_mesa_format_to_pipe_format(stImage->base.TexFormat); fmt = st_mesa_format_to_pipe_format(st, stImage->base.TexFormat);
bindings = default_bindings(st, fmt); bindings = default_bindings(st, fmt);
@@ -493,7 +493,7 @@ st_AllocTextureImageBuffer(struct gl_context *ctx,
/* Look if the parent texture object has space for this image */ /* Look if the parent texture object has space for this image */
if (stObj->pt && if (stObj->pt &&
level <= stObj->pt->last_level && level <= stObj->pt->last_level &&
st_texture_match_image(stObj->pt, texImage)) { st_texture_match_image(st, stObj->pt, texImage)) {
/* this image will fit in the existing texture object's memory */ /* this image will fit in the existing texture object's memory */
pipe_resource_reference(&stImage->pt, stObj->pt); pipe_resource_reference(&stImage->pt, stObj->pt);
return GL_TRUE; return GL_TRUE;
@@ -516,7 +516,7 @@ st_AllocTextureImageBuffer(struct gl_context *ctx,
} }
if (stObj->pt && if (stObj->pt &&
st_texture_match_image(stObj->pt, texImage)) { st_texture_match_image(st, stObj->pt, texImage)) {
/* The image will live in the object's mipmap memory */ /* The image will live in the object's mipmap memory */
pipe_resource_reference(&stImage->pt, stObj->pt); pipe_resource_reference(&stImage->pt, stObj->pt);
assert(stImage->pt); assert(stImage->pt);
@@ -530,7 +530,7 @@ st_AllocTextureImageBuffer(struct gl_context *ctx,
* level. * level.
*/ */
enum pipe_format format = enum pipe_format format =
st_mesa_format_to_pipe_format(texImage->TexFormat); st_mesa_format_to_pipe_format(st, texImage->TexFormat);
GLuint bindings = default_bindings(st, format); GLuint bindings = default_bindings(st, format);
GLuint ptWidth, ptHeight, ptDepth, ptLayers; GLuint ptWidth, ptHeight, ptDepth, ptLayers;
@@ -706,7 +706,7 @@ st_TexSubImage(struct gl_context *ctx, GLuint dims,
} }
/* Choose the source format. */ /* Choose the source format. */
src_format = st_choose_matching_format(screen, PIPE_BIND_SAMPLER_VIEW, src_format = st_choose_matching_format(st, PIPE_BIND_SAMPLER_VIEW,
format, type, unpack->SwapBytes); format, type, unpack->SwapBytes);
if (!src_format) { if (!src_format) {
goto fallback; goto fallback;
@@ -982,7 +982,7 @@ st_GetTexImage(struct gl_context * ctx,
/* Choose the destination format by finding the best match /* Choose the destination format by finding the best match
* for the format+type combo. */ * for the format+type combo. */
dst_format = st_choose_matching_format(screen, bind, format, type, dst_format = st_choose_matching_format(st, bind, format, type,
ctx->Pack.SwapBytes); ctx->Pack.SwapBytes);
if (dst_format == PIPE_FORMAT_NONE) { if (dst_format == PIPE_FORMAT_NONE) {
@@ -1581,7 +1581,8 @@ st_finalize_texture(struct gl_context *ctx,
} }
/* Find gallium format for the Mesa texture */ /* Find gallium format for the Mesa texture */
firstImageFormat = st_mesa_format_to_pipe_format(firstImage->base.TexFormat); firstImageFormat =
st_mesa_format_to_pipe_format(st, firstImage->base.TexFormat);
/* Find size of level=0 Gallium mipmap image, plus number of texture layers */ /* Find size of level=0 Gallium mipmap image, plus number of texture layers */
{ {
@@ -1699,7 +1700,7 @@ st_AllocTextureStorage(struct gl_context *ctx,
stObj->depth0 = depth; stObj->depth0 = depth;
stObj->lastLevel = levels - 1; stObj->lastLevel = levels - 1;
fmt = st_mesa_format_to_pipe_format(texImage->TexFormat); fmt = st_mesa_format_to_pipe_format(st, texImage->TexFormat);
bindings = default_bindings(st, fmt); bindings = default_bindings(st, fmt);
@@ -1778,7 +1779,7 @@ st_TestProxyTexImage(struct gl_context *ctx, GLenum target,
memset(&pt, 0, sizeof(pt)); memset(&pt, 0, sizeof(pt));
pt.target = gl_target_to_pipe(target); pt.target = gl_target_to_pipe(target);
pt.format = st_mesa_format_to_pipe_format(format); pt.format = st_mesa_format_to_pipe_format(st, format);
st_gl_texture_dims_to_pipe_dims(target, st_gl_texture_dims_to_pipe_dims(target,
width, height, depth, width, height, depth,

View File

@@ -54,7 +54,7 @@
* Translate Mesa format to Gallium format. * Translate Mesa format to Gallium format.
*/ */
enum pipe_format enum pipe_format
st_mesa_format_to_pipe_format(mesa_format mesaFormat) st_mesa_format_to_pipe_format(struct st_context *st, mesa_format mesaFormat)
{ {
switch (mesaFormat) { switch (mesaFormat) {
case MESA_FORMAT_A8B8G8R8_UNORM: case MESA_FORMAT_A8B8G8R8_UNORM:
@@ -795,7 +795,7 @@ st_pipe_format_to_mesa_format(enum pipe_format format)
* Mesa formats to Gallium formats and back again. * Mesa formats to Gallium formats and back again.
*/ */
static void static void
test_format_conversion(void) test_format_conversion(struct st_context *st)
{ {
GLuint i; GLuint i;
@@ -805,7 +805,7 @@ test_format_conversion(void)
if (_mesa_is_format_etc2(i)) if (_mesa_is_format_etc2(i))
continue; continue;
enum pipe_format pf = st_mesa_format_to_pipe_format(i); enum pipe_format pf = st_mesa_format_to_pipe_format(st, i);
if (pf != PIPE_FORMAT_NONE) { if (pf != PIPE_FORMAT_NONE) {
mesa_format mf = st_pipe_format_to_mesa_format(pf); mesa_format mf = st_pipe_format_to_mesa_format(pf);
assert(mf == i); assert(mf == i);
@@ -816,7 +816,7 @@ test_format_conversion(void)
for (i = 1; i < PIPE_FORMAT_COUNT; i++) { for (i = 1; i < PIPE_FORMAT_COUNT; i++) {
mesa_format mf = st_pipe_format_to_mesa_format(i); mesa_format mf = st_pipe_format_to_mesa_format(i);
if (mf != MESA_FORMAT_NONE) { if (mf != MESA_FORMAT_NONE) {
enum pipe_format pf = st_mesa_format_to_pipe_format(mf); enum pipe_format pf = st_mesa_format_to_pipe_format(st, mf);
assert(pf == i); assert(pf == i);
} }
} }
@@ -1704,7 +1704,7 @@ st_choose_format(struct st_context *st, GLenum internalFormat,
{ {
static boolean firstCall = TRUE; static boolean firstCall = TRUE;
if (firstCall) { if (firstCall) {
test_format_conversion(); test_format_conversion(st);
firstCall = FALSE; firstCall = FALSE;
} }
} }
@@ -1770,9 +1770,10 @@ st_choose_renderbuffer_format(struct st_context *st,
* If no format is supported, return PIPE_FORMAT_NONE. * If no format is supported, return PIPE_FORMAT_NONE.
*/ */
enum pipe_format enum pipe_format
st_choose_matching_format(struct pipe_screen *screen, unsigned bind, st_choose_matching_format(struct st_context *st, unsigned bind,
GLenum format, GLenum type, GLboolean swapBytes) GLenum format, GLenum type, GLboolean swapBytes)
{ {
struct pipe_screen *screen = st->pipe->screen;
mesa_format mesa_format; mesa_format mesa_format;
for (mesa_format = 1; mesa_format < MESA_FORMAT_COUNT; mesa_format++) { for (mesa_format = 1; mesa_format < MESA_FORMAT_COUNT; mesa_format++) {
@@ -1788,7 +1789,8 @@ st_choose_matching_format(struct pipe_screen *screen, unsigned bind,
if (_mesa_format_matches_format_and_type(mesa_format, format, type, if (_mesa_format_matches_format_and_type(mesa_format, format, type,
swapBytes)) { swapBytes)) {
enum pipe_format format = st_mesa_format_to_pipe_format(mesa_format); enum pipe_format format =
st_mesa_format_to_pipe_format(st, mesa_format);
if (format && if (format &&
screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, 0, screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, 0,
@@ -1858,16 +1860,14 @@ st_ChooseTextureFormat(struct gl_context *ctx, GLenum target,
* with the "format". * with the "format".
*/ */
if (iformat == baseFormat && iformat == basePackFormat) { if (iformat == baseFormat && iformat == basePackFormat) {
pFormat = st_choose_matching_format(st->pipe->screen, bindings, pFormat = st_choose_matching_format(st, bindings, format, type,
format, type,
ctx->Unpack.SwapBytes); ctx->Unpack.SwapBytes);
if (pFormat != PIPE_FORMAT_NONE) if (pFormat != PIPE_FORMAT_NONE)
return st_pipe_format_to_mesa_format(pFormat); return st_pipe_format_to_mesa_format(pFormat);
/* try choosing format again, this time without render target bindings */ /* try choosing format again, this time without render target bindings */
pFormat = st_choose_matching_format(st->pipe->screen, pFormat = st_choose_matching_format(st, PIPE_BIND_SAMPLER_VIEW,
PIPE_BIND_SAMPLER_VIEW,
format, type, format, type,
ctx->Unpack.SwapBytes); ctx->Unpack.SwapBytes);
if (pFormat != PIPE_FORMAT_NONE) if (pFormat != PIPE_FORMAT_NONE)

View File

@@ -41,7 +41,7 @@ struct pipe_screen;
extern enum pipe_format extern enum pipe_format
st_mesa_format_to_pipe_format(mesa_format mesaFormat); st_mesa_format_to_pipe_format(struct st_context *st, mesa_format mesaFormat);
extern mesa_format extern mesa_format
st_pipe_format_to_mesa_format(enum pipe_format pipeFormat); st_pipe_format_to_mesa_format(enum pipe_format pipeFormat);
@@ -58,7 +58,7 @@ st_choose_renderbuffer_format(struct st_context *st,
GLenum internalFormat, unsigned sample_count); GLenum internalFormat, unsigned sample_count);
extern enum pipe_format extern enum pipe_format
st_choose_matching_format(struct pipe_screen *screen, unsigned bind, st_choose_matching_format(struct st_context *st, unsigned bind,
GLenum format, GLenum type, GLboolean swapBytes); GLenum format, GLenum type, GLboolean swapBytes);
extern mesa_format extern mesa_format

View File

@@ -197,7 +197,8 @@ st_gl_texture_dims_to_pipe_dims(GLenum texture,
* Check if a texture image can be pulled into a unified mipmap texture. * Check if a texture image can be pulled into a unified mipmap texture.
*/ */
GLboolean GLboolean
st_texture_match_image(const struct pipe_resource *pt, st_texture_match_image(struct st_context *st,
const struct pipe_resource *pt,
const struct gl_texture_image *image) const struct gl_texture_image *image)
{ {
GLuint ptWidth, ptHeight, ptDepth, ptLayers; GLuint ptWidth, ptHeight, ptDepth, ptLayers;
@@ -209,7 +210,7 @@ st_texture_match_image(const struct pipe_resource *pt,
/* Check if this image's format matches the established texture's format. /* Check if this image's format matches the established texture's format.
*/ */
if (st_mesa_format_to_pipe_format(image->TexFormat) != pt->format) if (st_mesa_format_to_pipe_format(st, image->TexFormat) != pt->format)
return GL_FALSE; return GL_FALSE;
st_gl_texture_dims_to_pipe_dims(image->TexObject->Target, st_gl_texture_dims_to_pipe_dims(image->TexObject->Target,

View File

@@ -199,7 +199,8 @@ st_gl_texture_dims_to_pipe_dims(GLenum texture,
/* Check if an image fits into an existing texture object. /* Check if an image fits into an existing texture object.
*/ */
extern GLboolean extern GLboolean
st_texture_match_image(const struct pipe_resource *pt, st_texture_match_image(struct st_context *st,
const struct pipe_resource *pt,
const struct gl_texture_image *image); const struct gl_texture_image *image);
/* Return a pointer to an image within a texture. Return image stride as /* Return a pointer to an image within a texture. Return image stride as