X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fauxiliary%2Fdraw%2Fdraw_pipe_aaline.c;h=9f956715a228135df0459358ef0ff8242cf789e3;hb=d2f6d6ce49699d35d6b6a234fe17a27d99f4b267;hp=6dc20f2c90a95412cfeb1d4eceefa992a8703fde;hpb=d2ec02f44026244130b4e6f9d87eac6a03a9c6c1;p=mesa.git diff --git a/src/gallium/auxiliary/draw/draw_pipe_aaline.c b/src/gallium/auxiliary/draw/draw_pipe_aaline.c index 6dc20f2c90a..9f956715a22 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_aaline.c +++ b/src/gallium/auxiliary/draw/draw_pipe_aaline.c @@ -32,14 +32,14 @@ */ -#include "pipe/p_util.h" -#include "pipe/p_inlines.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_shader_tokens.h" +#include "util/u_math.h" +#include "util/u_memory.h" -#include "tgsi/util/tgsi_transform.h" -#include "tgsi/util/tgsi_dump.h" +#include "tgsi/tgsi_transform.h" +#include "tgsi/tgsi_dump.h" #include "draw_context.h" #include "draw_private.h" @@ -60,8 +60,6 @@ struct aaline_fragment_shader struct pipe_shader_state state; void *driver_fs; void *aaline_fs; - void *aapoint_fs; /* not yet */ - void *sprite_fs; /* not yet */ uint sampler_unit; int generic_attrib; /**< texcoord/generic used for texture */ }; @@ -78,6 +76,8 @@ struct aaline_stage /** For AA lines, this is the vertex attrib slot for the new texcoords */ uint tex_slot; + /** position, not necessarily output zero */ + uint pos_slot; void *sampler_cso; struct pipe_texture *texture; @@ -141,18 +141,18 @@ aa_transform_decl(struct tgsi_transform_context *ctx, if (decl->Declaration.File == TGSI_FILE_OUTPUT && decl->Semantic.SemanticName == TGSI_SEMANTIC_COLOR && decl->Semantic.SemanticIndex == 0) { - aactx->colorOutput = decl->u.DeclarationRange.First; + aactx->colorOutput = decl->DeclarationRange.First; } else if (decl->Declaration.File == TGSI_FILE_SAMPLER) { uint i; - for (i = decl->u.DeclarationRange.First; - i <= decl->u.DeclarationRange.Last; i++) { + for (i = decl->DeclarationRange.First; + i <= decl->DeclarationRange.Last; i++) { aactx->samplersUsed |= 1 << i; } } else if (decl->Declaration.File == TGSI_FILE_INPUT) { - if ((int) decl->u.DeclarationRange.Last > aactx->maxInput) - aactx->maxInput = decl->u.DeclarationRange.Last; + if ((int) decl->DeclarationRange.Last > aactx->maxInput) + aactx->maxInput = decl->DeclarationRange.Last; if (decl->Semantic.SemanticName == TGSI_SEMANTIC_GENERIC && (int) decl->Semantic.SemanticIndex > aactx->maxGeneric) { aactx->maxGeneric = decl->Semantic.SemanticIndex; @@ -160,8 +160,8 @@ aa_transform_decl(struct tgsi_transform_context *ctx, } else if (decl->Declaration.File == TGSI_FILE_TEMPORARY) { uint i; - for (i = decl->u.DeclarationRange.First; - i <= decl->u.DeclarationRange.Last; i++) { + for (i = decl->DeclarationRange.First; + i <= decl->DeclarationRange.Last; i++) { aactx->tempsUsed |= (1 << i); } } @@ -225,34 +225,33 @@ aa_transform_inst(struct tgsi_transform_context *ctx, /* declare new generic input/texcoord */ decl = tgsi_default_full_declaration(); decl.Declaration.File = TGSI_FILE_INPUT; + /* XXX this could be linear... */ + decl.Declaration.Interpolate = TGSI_INTERPOLATE_PERSPECTIVE; decl.Declaration.Semantic = 1; decl.Semantic.SemanticName = TGSI_SEMANTIC_GENERIC; decl.Semantic.SemanticIndex = aactx->maxGeneric + 1; - decl.Declaration.Interpolate = 1; - /* XXX this could be linear... */ - decl.Interpolation.Interpolate = TGSI_INTERPOLATE_PERSPECTIVE; - decl.u.DeclarationRange.First = - decl.u.DeclarationRange.Last = aactx->maxInput + 1; + decl.DeclarationRange.First = + decl.DeclarationRange.Last = aactx->maxInput + 1; ctx->emit_declaration(ctx, &decl); /* declare new sampler */ decl = tgsi_default_full_declaration(); decl.Declaration.File = TGSI_FILE_SAMPLER; - decl.u.DeclarationRange.First = - decl.u.DeclarationRange.Last = aactx->freeSampler; + decl.DeclarationRange.First = + decl.DeclarationRange.Last = aactx->freeSampler; ctx->emit_declaration(ctx, &decl); /* declare new temp regs */ decl = tgsi_default_full_declaration(); decl.Declaration.File = TGSI_FILE_TEMPORARY; - decl.u.DeclarationRange.First = - decl.u.DeclarationRange.Last = aactx->texTemp; + decl.DeclarationRange.First = + decl.DeclarationRange.Last = aactx->texTemp; ctx->emit_declaration(ctx, &decl); decl = tgsi_default_full_declaration(); decl.Declaration.File = TGSI_FILE_TEMPORARY; - decl.u.DeclarationRange.First = - decl.u.DeclarationRange.Last = aactx->colorTemp; + decl.DeclarationRange.First = + decl.DeclarationRange.Last = aactx->colorTemp; ctx->emit_declaration(ctx, &decl); aactx->firstInstruction = FALSE; @@ -372,10 +371,15 @@ generate_aaline_fs(struct aaline_stage *aaline) aaline->fs->aaline_fs = aaline->driver_create_fs_state(aaline->pipe, &aaline_fs); if (aaline->fs->aaline_fs == NULL) - return FALSE; + goto fail; aaline->fs->generic_attrib = transform.maxGeneric + 1; + FREE((void *)aaline_fs.tokens); return TRUE; + +fail: + FREE((void *)aaline_fs.tokens); + return FALSE; } @@ -397,7 +401,7 @@ aaline_create_texture(struct aaline_stage *aaline) texTemp.width[0] = 1 << MAX_TEXTURE_LEVEL; texTemp.height[0] = 1 << MAX_TEXTURE_LEVEL; texTemp.depth[0] = 1; - texTemp.cpp = 1; + pf_get_block(texTemp.format, &texTemp.block); aaline->texture = screen->texture_create(screen, &texTemp); if (!aaline->texture) @@ -408,7 +412,7 @@ aaline_create_texture(struct aaline_stage *aaline) * texels which are zero. Special case the 1x1 and 2x2 levels. */ for (level = 0; level <= MAX_TEXTURE_LEVEL; level++) { - struct pipe_surface *surface; + struct pipe_transfer *transfer; const uint size = aaline->texture->width[level]; ubyte *data; uint i, j; @@ -417,9 +421,9 @@ aaline_create_texture(struct aaline_stage *aaline) /* This texture is new, no need to flush. */ - surface = screen->get_tex_surface(screen, aaline->texture, 0, level, 0, - PIPE_BUFFER_USAGE_CPU_WRITE); - data = screen->surface_map(screen, surface, PIPE_BUFFER_USAGE_CPU_WRITE); + transfer = screen->get_tex_transfer(screen, aaline->texture, 0, level, 0, + PIPE_TRANSFER_WRITE, 0, 0, size, size); + data = screen->transfer_map(screen, transfer); if (data == NULL) return FALSE; @@ -438,13 +442,13 @@ aaline_create_texture(struct aaline_stage *aaline) else { d = 255; } - data[i * surface->pitch + j] = d; + data[i * transfer->stride + j] = d; } } /* unmap */ - screen->surface_unmap(screen, surface); - screen->tex_surface_release(screen, &surface); + screen->transfer_unmap(screen, transfer); + screen->tex_transfer_destroy(transfer); } return TRUE; } @@ -521,9 +525,10 @@ aaline_line(struct draw_stage *stage, struct prim_header *header) struct prim_header tri; struct vertex_header *v[8]; uint texPos = aaline->tex_slot; + uint posPos = aaline->pos_slot; float *pos, *tex; - float dx = header->v[1]->data[0][0] - header->v[0]->data[0][0]; - float dy = header->v[1]->data[0][1] - header->v[0]->data[0][1]; + float dx = header->v[1]->data[posPos][0] - header->v[0]->data[posPos][0]; + float dy = header->v[1]->data[posPos][1] - header->v[0]->data[posPos][1]; double a = atan2(dy, dx); float c_a = (float) cos(a), s_a = (float) sin(a); uint i; @@ -550,35 +555,35 @@ aaline_line(struct draw_stage *stage, struct prim_header *header) */ /* new verts */ - pos = v[0]->data[0]; + pos = v[0]->data[posPos]; pos[0] += (-dx * c_a - dy * s_a); pos[1] += (-dx * s_a + dy * c_a); - pos = v[1]->data[0]; + pos = v[1]->data[posPos]; pos[0] += (-dx * c_a - -dy * s_a); pos[1] += (-dx * s_a + -dy * c_a); - pos = v[2]->data[0]; + pos = v[2]->data[posPos]; pos[0] += ( dx * c_a - dy * s_a); pos[1] += ( dx * s_a + dy * c_a); - pos = v[3]->data[0]; + pos = v[3]->data[posPos]; pos[0] += ( dx * c_a - -dy * s_a); pos[1] += ( dx * s_a + -dy * c_a); - pos = v[4]->data[0]; + pos = v[4]->data[posPos]; pos[0] += (-dx * c_a - dy * s_a); pos[1] += (-dx * s_a + dy * c_a); - pos = v[5]->data[0]; + pos = v[5]->data[posPos]; pos[0] += (-dx * c_a - -dy * s_a); pos[1] += (-dx * s_a + -dy * c_a); - pos = v[6]->data[0]; + pos = v[6]->data[posPos]; pos[0] += ( dx * c_a - dy * s_a); pos[1] += ( dx * s_a + dy * c_a); - pos = v[7]->data[0]; + pos = v[7]->data[posPos]; pos[0] += ( dx * c_a - -dy * s_a); pos[1] += ( dx * s_a + -dy * c_a); @@ -653,8 +658,8 @@ aaline_first_line(struct draw_stage *stage, struct prim_header *header) } /* update vertex attrib info */ - aaline->tex_slot = draw->num_vs_outputs; - assert(aaline->tex_slot > 0); /* output[0] is vertex pos */ + aaline->tex_slot = draw->vs.num_vs_outputs; + aaline->pos_slot = draw->vs.position_output; /* advertise the extra post-transformed vertex attribute */ draw->extra_vp_outputs.semantic_name = TGSI_SEMANTIC_GENERIC; @@ -715,12 +720,17 @@ static void aaline_destroy(struct draw_stage *stage) { struct aaline_stage *aaline = aaline_stage(stage); + uint i; + + for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { + pipe_texture_reference(&aaline->state.texture[i], NULL); + } if (aaline->sampler_cso) aaline->pipe->delete_sampler_state(aaline->pipe, aaline->sampler_cso); if (aaline->texture) - pipe_texture_release(&aaline->texture); + pipe_texture_reference(&aaline->texture, NULL); draw_free_temp_verts( stage ); @@ -739,6 +749,7 @@ draw_aaline_stage(struct draw_context *draw) goto fail; aaline->stage.draw = draw; + aaline->stage.name = "aaline"; aaline->stage.next = NULL; aaline->stage.point = draw_pipe_passthrough_point; aaline->stage.line = aaline_first_line; @@ -808,6 +819,10 @@ aaline_delete_fs_state(struct pipe_context *pipe, void *fs) struct aaline_fragment_shader *aafs = (struct aaline_fragment_shader *) fs; /* pass-through */ aaline->driver_delete_fs_state(aaline->pipe, aafs->driver_fs); + + if (aafs->aaline_fs) + aaline->driver_delete_fs_state(aaline->pipe, aafs->aaline_fs); + FREE(aafs); } @@ -838,6 +853,9 @@ aaline_set_sampler_textures(struct pipe_context *pipe, for (i = 0; i < num; i++) { pipe_texture_reference(&aaline->state.texture[i], texture[i]); } + for ( ; i < PIPE_MAX_SAMPLERS; i++) { + pipe_texture_reference(&aaline->state.texture[i], NULL); + } aaline->num_textures = num; /* pass-through */