X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fstate_tracker%2Fst_atom_pixeltransfer.c;h=b612f784630e46a8eca1cb87e4d89993fc9e5988;hb=9785ae0973cc206afc36dbc7d5b9553f92d06b47;hp=e8e67f80305d57245a884809eebcb6cc6ca8940c;hpb=8f3bdeaad610d7d5a5c6e73e1e9c721219595754;p=mesa.git diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c index e8e67f80305..b612f784630 100644 --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -27,7 +27,7 @@ /* * Generate fragment programs to implement pixel transfer ops, such as - * scale/bias, colormatrix, colortable, convolution... + * scale/bias, colortable, convolution... * * Authors: * Brian Paul @@ -36,26 +36,25 @@ #include "main/imports.h" #include "main/image.h" #include "main/macros.h" -#include "shader/program.h" -#include "shader/prog_instruction.h" -#include "shader/prog_parameter.h" -#include "shader/prog_print.h" +#include "program/program.h" +#include "program/prog_cache.h" +#include "program/prog_instruction.h" +#include "program/prog_parameter.h" +#include "program/prog_print.h" #include "st_context.h" #include "st_format.h" #include "st_texture.h" -#include "st_inlines.h" #include "pipe/p_screen.h" #include "pipe/p_context.h" +#include "util/u_inlines.h" #include "util/u_pack_color.h" struct state_key { GLuint scaleAndBias:1; - GLuint colorMatrix:1; - GLuint colorMatrixPostScaleBias:1; GLuint pixelMaps:1; #if 0 @@ -69,27 +68,9 @@ struct state_key #endif }; - -static GLboolean -is_identity(const GLfloat m[16]) -{ - GLuint i; - for (i = 0; i < 16; i++) { - const int row = i % 4, col = i / 4; - const float val = (GLfloat)(row == col); - if (m[i] != val) - return GL_FALSE; - } - return GL_TRUE; -} - - static void -make_state_key(GLcontext *ctx, struct state_key *key) +make_state_key(struct gl_context *ctx, struct state_key *key) { - static const GLfloat zero[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; - static const GLfloat one[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; - memset(key, 0, sizeof(*key)); if (ctx->Pixel.RedBias != 0.0 || ctx->Pixel.RedScale != 1.0 || @@ -99,45 +80,18 @@ make_state_key(GLcontext *ctx, struct state_key *key) key->scaleAndBias = 1; } - if (!is_identity(ctx->ColorMatrixStack.Top->m)) { - key->colorMatrix = 1; - } - - if (!TEST_EQ_4V(ctx->Pixel.PostColorMatrixScale, one) || - !TEST_EQ_4V(ctx->Pixel.PostColorMatrixBias, zero)) { - key->colorMatrixPostScaleBias = 1; - } - key->pixelMaps = ctx->Pixel.MapColorFlag; } -static struct pipe_resource * -create_color_map_texture(GLcontext *ctx) -{ - struct pipe_context *pipe = ctx->st->pipe; - struct pipe_resource *pt; - enum pipe_format format; - const uint texSize = 256; /* simple, and usually perfect */ - - /* find an RGBA texture format */ - format = st_choose_format(pipe->screen, GL_RGBA, - PIPE_TEXTURE_2D, PIPE_BIND_SAMPLER_VIEW); - - /* create texture for color map/table */ - pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, format, 0, - texSize, texSize, 1, PIPE_BIND_SAMPLER_VIEW); - return pt; -} - - /** * Update the pixelmap texture with the contents of the R/G/B/A pixel maps. */ static void -load_color_map_texture(GLcontext *ctx, struct pipe_resource *pt) +load_color_map_texture(struct gl_context *ctx, struct pipe_resource *pt) { - struct pipe_context *pipe = ctx->st->pipe; + struct st_context *st = st_context(ctx); + struct pipe_context *pipe = st->pipe; struct pipe_transfer *transfer; const GLuint rSize = ctx->PixelMaps.RtoR.Size; const GLuint gSize = ctx->PixelMaps.GtoG.Size; @@ -147,10 +101,9 @@ load_color_map_texture(GLcontext *ctx, struct pipe_resource *pt) uint *dest; uint i, j; - transfer = st_cond_flush_get_tex_transfer(st_context(ctx), - pt, 0, 0, 0, PIPE_TRANSFER_WRITE, - 0, 0, texSize, texSize); - dest = (uint *) pipe_transfer_map(pipe, transfer); + dest = (uint *) pipe_transfer_map(pipe, + pt, 0, 0, PIPE_TRANSFER_WRITE, + 0, 0, texSize, texSize, &transfer); /* Pack four 1D maps into a 2D texture: * R map is placed horizontally, indexed by S, in channel 0 @@ -162,17 +115,17 @@ load_color_map_texture(GLcontext *ctx, struct pipe_resource *pt) for (j = 0; j < texSize; j++) { union util_color uc; int k = (i * texSize + j); - ubyte r = ctx->PixelMaps.RtoR.Map8[j * rSize / texSize]; - ubyte g = ctx->PixelMaps.GtoG.Map8[i * gSize / texSize]; - ubyte b = ctx->PixelMaps.BtoB.Map8[j * bSize / texSize]; - ubyte a = ctx->PixelMaps.AtoA.Map8[i * aSize / texSize]; - util_pack_color_ub(r, g, b, a, pt->format, &uc); + float rgba[4]; + rgba[0] = ctx->PixelMaps.RtoR.Map[j * rSize / texSize]; + rgba[1] = ctx->PixelMaps.GtoG.Map[i * gSize / texSize]; + rgba[2] = ctx->PixelMaps.BtoB.Map[j * bSize / texSize]; + rgba[3] = ctx->PixelMaps.AtoA.Map[i * aSize / texSize]; + util_pack_color(rgba, pt->format, &uc); *(dest + k) = uc.ui; } } pipe_transfer_unmap(pipe, transfer); - pipe->transfer_destroy(pipe, transfer); } @@ -183,9 +136,9 @@ load_color_map_texture(GLcontext *ctx, struct pipe_resource *pt) * Returns a fragment program which implements the current pixel transfer ops. */ static struct gl_fragment_program * -get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) +get_pixel_transfer_program(struct gl_context *ctx, const struct state_key *key) { - struct st_context *st = ctx->st; + struct st_context *st = st_context(ctx); struct prog_instruction inst[MAX_INST]; struct gl_program_parameter_list *params; struct gl_fragment_program *fp; @@ -212,8 +165,8 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) inst[ic].TexSrcUnit = 0; inst[ic].TexSrcTarget = TEXTURE_2D_INDEX; ic++; - fp->Base.InputsRead = (1 << FRAG_ATTRIB_TEX0); - fp->Base.OutputsWritten = (1 << FRAG_RESULT_COLOR); + fp->Base.InputsRead = BITFIELD64_BIT(FRAG_ATTRIB_TEX0); + fp->Base.OutputsWritten = BITFIELD64_BIT(FRAG_RESULT_COLOR); fp->Base.SamplersUsed = 0x1; /* sampler 0 (bit 0) is used */ if (key->scaleAndBias) { @@ -221,18 +174,8 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) { STATE_INTERNAL, STATE_PT_SCALE, 0, 0, 0 }; static const gl_state_index bias_state[STATE_LENGTH] = { STATE_INTERNAL, STATE_PT_BIAS, 0, 0, 0 }; - GLfloat scale[4], bias[4]; GLint scale_p, bias_p; - scale[0] = ctx->Pixel.RedScale; - scale[1] = ctx->Pixel.GreenScale; - scale[2] = ctx->Pixel.BlueScale; - scale[3] = ctx->Pixel.AlphaScale; - bias[0] = ctx->Pixel.RedBias; - bias[1] = ctx->Pixel.GreenBias; - bias[2] = ctx->Pixel.BlueBias; - bias[3] = ctx->Pixel.AlphaBias; - scale_p = _mesa_add_state_reference(params, scale_state); bias_p = _mesa_add_state_reference(params, bias_state); @@ -255,9 +198,10 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) /* create the colormap/texture now if not already done */ if (!st->pixel_xfer.pixelmap_texture) { - st->pixel_xfer.pixelmap_texture = create_color_map_texture(ctx); - st->pixel_xfer.pixelmap_sampler_view = st_create_texture_sampler_view(ctx->st->pipe, - st->pixel_xfer.pixelmap_texture); + st->pixel_xfer.pixelmap_texture = st_create_color_map_texture(ctx); + st->pixel_xfer.pixelmap_sampler_view = + st_create_texture_sampler_view(st->pipe, + st->pixel_xfer.pixelmap_texture); } /* with a little effort, we can do four pixel map look-ups with @@ -302,103 +246,6 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) fp->Base.SamplersUsed |= (1 << 1); /* sampler 1 is used */ } - if (key->colorMatrix) { - static const gl_state_index row0_state[STATE_LENGTH] = - { STATE_COLOR_MATRIX, 0, 0, 0, 0 }; - static const gl_state_index row1_state[STATE_LENGTH] = - { STATE_COLOR_MATRIX, 0, 1, 1, 0 }; - static const gl_state_index row2_state[STATE_LENGTH] = - { STATE_COLOR_MATRIX, 0, 2, 2, 0 }; - static const gl_state_index row3_state[STATE_LENGTH] = - { STATE_COLOR_MATRIX, 0, 3, 3, 0 }; - - GLint row0_p = _mesa_add_state_reference(params, row0_state); - GLint row1_p = _mesa_add_state_reference(params, row1_state); - GLint row2_p = _mesa_add_state_reference(params, row2_state); - GLint row3_p = _mesa_add_state_reference(params, row3_state); - const GLuint temp = 1; - - /* DP4 temp.x, colorTemp, matrow0; */ - _mesa_init_instructions(inst + ic, 1); - inst[ic].Opcode = OPCODE_DP4; - inst[ic].DstReg.File = PROGRAM_TEMPORARY; - inst[ic].DstReg.Index = temp; - inst[ic].DstReg.WriteMask = WRITEMASK_X; - inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; - inst[ic].SrcReg[0].Index = colorTemp; - inst[ic].SrcReg[1].File = PROGRAM_STATE_VAR; - inst[ic].SrcReg[1].Index = row0_p; - ic++; - - /* DP4 temp.y, colorTemp, matrow1; */ - _mesa_init_instructions(inst + ic, 1); - inst[ic].Opcode = OPCODE_DP4; - inst[ic].DstReg.File = PROGRAM_TEMPORARY; - inst[ic].DstReg.Index = temp; - inst[ic].DstReg.WriteMask = WRITEMASK_Y; - inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; - inst[ic].SrcReg[0].Index = colorTemp; - inst[ic].SrcReg[1].File = PROGRAM_STATE_VAR; - inst[ic].SrcReg[1].Index = row1_p; - ic++; - - /* DP4 temp.z, colorTemp, matrow2; */ - _mesa_init_instructions(inst + ic, 1); - inst[ic].Opcode = OPCODE_DP4; - inst[ic].DstReg.File = PROGRAM_TEMPORARY; - inst[ic].DstReg.Index = temp; - inst[ic].DstReg.WriteMask = WRITEMASK_Z; - inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; - inst[ic].SrcReg[0].Index = colorTemp; - inst[ic].SrcReg[1].File = PROGRAM_STATE_VAR; - inst[ic].SrcReg[1].Index = row2_p; - ic++; - - /* DP4 temp.w, colorTemp, matrow3; */ - _mesa_init_instructions(inst + ic, 1); - inst[ic].Opcode = OPCODE_DP4; - inst[ic].DstReg.File = PROGRAM_TEMPORARY; - inst[ic].DstReg.Index = temp; - inst[ic].DstReg.WriteMask = WRITEMASK_W; - inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; - inst[ic].SrcReg[0].Index = colorTemp; - inst[ic].SrcReg[1].File = PROGRAM_STATE_VAR; - inst[ic].SrcReg[1].Index = row3_p; - ic++; - - /* MOV colorTemp, temp; */ - _mesa_init_instructions(inst + ic, 1); - inst[ic].Opcode = OPCODE_MOV; - inst[ic].DstReg.File = PROGRAM_TEMPORARY; - inst[ic].DstReg.Index = colorTemp; - inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; - inst[ic].SrcReg[0].Index = temp; - ic++; - } - - if (key->colorMatrixPostScaleBias) { - static const gl_state_index scale_state[STATE_LENGTH] = - { STATE_INTERNAL, STATE_PT_SCALE, 0, 0, 0 }; - static const gl_state_index bias_state[STATE_LENGTH] = - { STATE_INTERNAL, STATE_PT_BIAS, 0, 0, 0 }; - GLint scale_param, bias_param; - - scale_param = _mesa_add_state_reference(params, scale_state); - bias_param = _mesa_add_state_reference(params, bias_state); - - _mesa_init_instructions(inst + ic, 1); - inst[ic].Opcode = OPCODE_MAD; - inst[ic].DstReg.File = PROGRAM_TEMPORARY; - inst[ic].DstReg.Index = colorTemp; - inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; - inst[ic].SrcReg[0].Index = colorTemp; - inst[ic].SrcReg[1].File = PROGRAM_STATE_VAR; - inst[ic].SrcReg[1].Index = scale_param; - inst[ic].SrcReg[2].File = PROGRAM_STATE_VAR; - inst[ic].SrcReg[2].Index = bias_param; - ic++; - } - /* Modify last instruction's dst reg to write to result.color */ { struct prog_instruction *last = &inst[ic - 1]; @@ -418,6 +265,7 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) if (!fp->Base.Instructions) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "generating pixel transfer program"); + _mesa_free_parameter_list(params); return NULL; } @@ -442,7 +290,7 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) static void update_pixel_transfer(struct st_context *st) { - GLcontext *ctx = st->ctx; + struct gl_context *ctx = st->ctx; struct state_key key; struct gl_fragment_program *fp; @@ -469,7 +317,7 @@ update_pixel_transfer(struct st_context *st) const struct st_tracked_state st_update_pixel_transfer = { "st_update_pixel_transfer", /* name */ { /* dirty */ - _NEW_PIXEL | _NEW_COLOR_MATRIX, /* mesa */ + _NEW_PIXEL, /* mesa */ 0, /* st */ }, update_pixel_transfer /* update */