Re: [Mesa-dev] [PATCH 1/2] draw: use util_pstipple_create_fragment_shader
On 02/08/2016 07:59 AM, Nicolai Hähnle wrote: Ping? Looks good. For both: Reviewed-by: Brian PaulOn 22.01.2016 11:56, Nicolai Hähnle wrote: From: Nicolai Hähnle This reduces code duplication. It also adds support for drivers where the fragment position is a system value. Suggested-by: Jose Fonseca --- A basic polygon stippling test shows no regression on llvmpipe, but that's the extent of my testing. src/gallium/auxiliary/draw/draw_pipe_pstipple.c | 209 ++-- 1 file changed, 12 insertions(+), 197 deletions(-) diff --git a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c index cf52ca4..e468cc3 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c +++ b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c @@ -43,10 +43,10 @@ #include "util/u_format.h" #include "util/u_math.h" #include "util/u_memory.h" +#include "util/u_pstipple.h" #include "util/u_sampler.h" #include "tgsi/tgsi_transform.h" -#include "tgsi/tgsi_dump.h" #include "draw_context.h" #include "draw_pipe.h" @@ -114,178 +114,6 @@ struct pstip_stage }; - -/** - * Subclass of tgsi_transform_context, used for transforming the - * user's fragment shader to add the extra texture sample and fragment kill - * instructions. - */ -struct pstip_transform_context { - struct tgsi_transform_context base; - uint tempsUsed; /**< bitmask */ - int wincoordInput; - int maxInput; - uint samplersUsed; /**< bitfield of samplers used */ - bool hasSview; - int freeSampler; /** an available sampler for the pstipple */ - int texTemp; /**< temp registers */ - int numImmed; -}; - - -/** - * TGSI declaration transform callback. - * Look for a free sampler, a free input attrib, and two free temp regs. - */ -static void -pstip_transform_decl(struct tgsi_transform_context *ctx, - struct tgsi_full_declaration *decl) -{ - struct pstip_transform_context *pctx = (struct pstip_transform_context *) ctx; - - if (decl->Declaration.File == TGSI_FILE_SAMPLER) { - uint i; - for (i = decl->Range.First; - i <= decl->Range.Last; i++) { - pctx->samplersUsed |= 1 << i; - } - } - else if (decl->Declaration.File == TGSI_FILE_SAMPLER_VIEW) { - pctx->hasSview = true; - } - else if (decl->Declaration.File == TGSI_FILE_INPUT) { - pctx->maxInput = MAX2(pctx->maxInput, (int) decl->Range.Last); - if (decl->Semantic.Name == TGSI_SEMANTIC_POSITION) - pctx->wincoordInput = (int) decl->Range.First; - } - else if (decl->Declaration.File == TGSI_FILE_TEMPORARY) { - uint i; - for (i = decl->Range.First; - i <= decl->Range.Last; i++) { - pctx->tempsUsed |= (1 << i); - } - } - - ctx->emit_declaration(ctx, decl); -} - - -/** - * TGSI immediate declaration transform callback. - * We're just counting the number of immediates here. - */ -static void -pstip_transform_immed(struct tgsi_transform_context *ctx, - struct tgsi_full_immediate *immed) -{ - struct pstip_transform_context *pctx = (struct pstip_transform_context *) ctx; - ctx->emit_immediate(ctx, immed); /* emit to output shader */ - pctx->numImmed++; -} - - -/** - * Find the lowest zero bit in the given word, or -1 if bitfield is all ones. - */ -static int -free_bit(uint bitfield) -{ - return ffs(~bitfield) - 1; -} - - -/** - * TGSI transform prolog callback. - */ -static void -pstip_transform_prolog(struct tgsi_transform_context *ctx) -{ - struct pstip_transform_context *pctx = (struct pstip_transform_context *) ctx; - uint i; - int wincoordInput; - - /* find free sampler */ - pctx->freeSampler = free_bit(pctx->samplersUsed); - if (pctx->freeSampler >= PIPE_MAX_SAMPLERS) - pctx->freeSampler = PIPE_MAX_SAMPLERS - 1; - - if (pctx->wincoordInput < 0) - wincoordInput = pctx->maxInput + 1; - else - wincoordInput = pctx->wincoordInput; - - /* find one free temp reg */ - for (i = 0; i < 32; i++) { - if ((pctx->tempsUsed & (1 << i)) == 0) { - /* found a free temp */ - if (pctx->texTemp < 0) - pctx->texTemp = i; - else - break; - } - } - assert(pctx->texTemp >= 0); - - if (pctx->wincoordInput < 0) { - /* declare new position input reg */ - tgsi_transform_input_decl(ctx, wincoordInput, -TGSI_SEMANTIC_POSITION, 1, -TGSI_INTERPOLATE_LINEAR); - } - - /* declare new sampler */ - tgsi_transform_sampler_decl(ctx, pctx->freeSampler); - - /* if the src shader has SVIEW decl's for each SAMP decl, we -* need to continue the trend and ensure there is a matching -* SVIEW for the new SAMP we just created -*/ - if (pctx->hasSview) { - tgsi_transform_sampler_view_decl(ctx, - pctx->freeSampler, -
Re: [Mesa-dev] [PATCH 1/2] draw: use util_pstipple_create_fragment_shader
Ping? On 22.01.2016 11:56, Nicolai Hähnle wrote: From: Nicolai HähnleThis reduces code duplication. It also adds support for drivers where the fragment position is a system value. Suggested-by: Jose Fonseca --- A basic polygon stippling test shows no regression on llvmpipe, but that's the extent of my testing. src/gallium/auxiliary/draw/draw_pipe_pstipple.c | 209 ++-- 1 file changed, 12 insertions(+), 197 deletions(-) diff --git a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c index cf52ca4..e468cc3 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c +++ b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c @@ -43,10 +43,10 @@ #include "util/u_format.h" #include "util/u_math.h" #include "util/u_memory.h" +#include "util/u_pstipple.h" #include "util/u_sampler.h" #include "tgsi/tgsi_transform.h" -#include "tgsi/tgsi_dump.h" #include "draw_context.h" #include "draw_pipe.h" @@ -114,178 +114,6 @@ struct pstip_stage }; - -/** - * Subclass of tgsi_transform_context, used for transforming the - * user's fragment shader to add the extra texture sample and fragment kill - * instructions. - */ -struct pstip_transform_context { - struct tgsi_transform_context base; - uint tempsUsed; /**< bitmask */ - int wincoordInput; - int maxInput; - uint samplersUsed; /**< bitfield of samplers used */ - bool hasSview; - int freeSampler; /** an available sampler for the pstipple */ - int texTemp; /**< temp registers */ - int numImmed; -}; - - -/** - * TGSI declaration transform callback. - * Look for a free sampler, a free input attrib, and two free temp regs. - */ -static void -pstip_transform_decl(struct tgsi_transform_context *ctx, - struct tgsi_full_declaration *decl) -{ - struct pstip_transform_context *pctx = (struct pstip_transform_context *) ctx; - - if (decl->Declaration.File == TGSI_FILE_SAMPLER) { - uint i; - for (i = decl->Range.First; - i <= decl->Range.Last; i++) { - pctx->samplersUsed |= 1 << i; - } - } - else if (decl->Declaration.File == TGSI_FILE_SAMPLER_VIEW) { - pctx->hasSview = true; - } - else if (decl->Declaration.File == TGSI_FILE_INPUT) { - pctx->maxInput = MAX2(pctx->maxInput, (int) decl->Range.Last); - if (decl->Semantic.Name == TGSI_SEMANTIC_POSITION) - pctx->wincoordInput = (int) decl->Range.First; - } - else if (decl->Declaration.File == TGSI_FILE_TEMPORARY) { - uint i; - for (i = decl->Range.First; - i <= decl->Range.Last; i++) { - pctx->tempsUsed |= (1 << i); - } - } - - ctx->emit_declaration(ctx, decl); -} - - -/** - * TGSI immediate declaration transform callback. - * We're just counting the number of immediates here. - */ -static void -pstip_transform_immed(struct tgsi_transform_context *ctx, - struct tgsi_full_immediate *immed) -{ - struct pstip_transform_context *pctx = (struct pstip_transform_context *) ctx; - ctx->emit_immediate(ctx, immed); /* emit to output shader */ - pctx->numImmed++; -} - - -/** - * Find the lowest zero bit in the given word, or -1 if bitfield is all ones. - */ -static int -free_bit(uint bitfield) -{ - return ffs(~bitfield) - 1; -} - - -/** - * TGSI transform prolog callback. - */ -static void -pstip_transform_prolog(struct tgsi_transform_context *ctx) -{ - struct pstip_transform_context *pctx = (struct pstip_transform_context *) ctx; - uint i; - int wincoordInput; - - /* find free sampler */ - pctx->freeSampler = free_bit(pctx->samplersUsed); - if (pctx->freeSampler >= PIPE_MAX_SAMPLERS) - pctx->freeSampler = PIPE_MAX_SAMPLERS - 1; - - if (pctx->wincoordInput < 0) - wincoordInput = pctx->maxInput + 1; - else - wincoordInput = pctx->wincoordInput; - - /* find one free temp reg */ - for (i = 0; i < 32; i++) { - if ((pctx->tempsUsed & (1 << i)) == 0) { - /* found a free temp */ - if (pctx->texTemp < 0) - pctx->texTemp = i; - else - break; - } - } - assert(pctx->texTemp >= 0); - - if (pctx->wincoordInput < 0) { - /* declare new position input reg */ - tgsi_transform_input_decl(ctx, wincoordInput, -TGSI_SEMANTIC_POSITION, 1, -TGSI_INTERPOLATE_LINEAR); - } - - /* declare new sampler */ - tgsi_transform_sampler_decl(ctx, pctx->freeSampler); - - /* if the src shader has SVIEW decl's for each SAMP decl, we -* need to continue the trend and ensure there is a matching -* SVIEW for the new SAMP we just created -*/ - if (pctx->hasSview) { - tgsi_transform_sampler_view_decl(ctx, - pctx->freeSampler, - TGSI_TEXTURE_2D, - TGSI_RETURN_TYPE_FLOAT); - } - -
Re: [Mesa-dev] [PATCH 1/2] draw: use util_pstipple_create_fragment_shader
Thanks for this this. Series looks good to me. Reviewed-by: Jose FonsecaSorry for not replying sooner -- I missed it. (Unfortunately I haven't been able to keep up with mesa-dev traffic and if I'm not CC'ed the odds are I miss things.) Jose On 08/02/16 14:59, Nicolai Hähnle wrote: Ping? On 22.01.2016 11:56, Nicolai Hähnle wrote: From: Nicolai Hähnle This reduces code duplication. It also adds support for drivers where the fragment position is a system value. Suggested-by: Jose Fonseca --- A basic polygon stippling test shows no regression on llvmpipe, but that's the extent of my testing. src/gallium/auxiliary/draw/draw_pipe_pstipple.c | 209 ++-- 1 file changed, 12 insertions(+), 197 deletions(-) diff --git a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c index cf52ca4..e468cc3 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c +++ b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c @@ -43,10 +43,10 @@ #include "util/u_format.h" #include "util/u_math.h" #include "util/u_memory.h" +#include "util/u_pstipple.h" #include "util/u_sampler.h" #include "tgsi/tgsi_transform.h" -#include "tgsi/tgsi_dump.h" #include "draw_context.h" #include "draw_pipe.h" @@ -114,178 +114,6 @@ struct pstip_stage }; - -/** - * Subclass of tgsi_transform_context, used for transforming the - * user's fragment shader to add the extra texture sample and fragment kill - * instructions. - */ -struct pstip_transform_context { - struct tgsi_transform_context base; - uint tempsUsed; /**< bitmask */ - int wincoordInput; - int maxInput; - uint samplersUsed; /**< bitfield of samplers used */ - bool hasSview; - int freeSampler; /** an available sampler for the pstipple */ - int texTemp; /**< temp registers */ - int numImmed; -}; - - -/** - * TGSI declaration transform callback. - * Look for a free sampler, a free input attrib, and two free temp regs. - */ -static void -pstip_transform_decl(struct tgsi_transform_context *ctx, - struct tgsi_full_declaration *decl) -{ - struct pstip_transform_context *pctx = (struct pstip_transform_context *) ctx; - - if (decl->Declaration.File == TGSI_FILE_SAMPLER) { - uint i; - for (i = decl->Range.First; - i <= decl->Range.Last; i++) { - pctx->samplersUsed |= 1 << i; - } - } - else if (decl->Declaration.File == TGSI_FILE_SAMPLER_VIEW) { - pctx->hasSview = true; - } - else if (decl->Declaration.File == TGSI_FILE_INPUT) { - pctx->maxInput = MAX2(pctx->maxInput, (int) decl->Range.Last); - if (decl->Semantic.Name == TGSI_SEMANTIC_POSITION) - pctx->wincoordInput = (int) decl->Range.First; - } - else if (decl->Declaration.File == TGSI_FILE_TEMPORARY) { - uint i; - for (i = decl->Range.First; - i <= decl->Range.Last; i++) { - pctx->tempsUsed |= (1 << i); - } - } - - ctx->emit_declaration(ctx, decl); -} - - -/** - * TGSI immediate declaration transform callback. - * We're just counting the number of immediates here. - */ -static void -pstip_transform_immed(struct tgsi_transform_context *ctx, - struct tgsi_full_immediate *immed) -{ - struct pstip_transform_context *pctx = (struct pstip_transform_context *) ctx; - ctx->emit_immediate(ctx, immed); /* emit to output shader */ - pctx->numImmed++; -} - - -/** - * Find the lowest zero bit in the given word, or -1 if bitfield is all ones. - */ -static int -free_bit(uint bitfield) -{ - return ffs(~bitfield) - 1; -} - - -/** - * TGSI transform prolog callback. - */ -static void -pstip_transform_prolog(struct tgsi_transform_context *ctx) -{ - struct pstip_transform_context *pctx = (struct pstip_transform_context *) ctx; - uint i; - int wincoordInput; - - /* find free sampler */ - pctx->freeSampler = free_bit(pctx->samplersUsed); - if (pctx->freeSampler >= PIPE_MAX_SAMPLERS) - pctx->freeSampler = PIPE_MAX_SAMPLERS - 1; - - if (pctx->wincoordInput < 0) - wincoordInput = pctx->maxInput + 1; - else - wincoordInput = pctx->wincoordInput; - - /* find one free temp reg */ - for (i = 0; i < 32; i++) { - if ((pctx->tempsUsed & (1 << i)) == 0) { - /* found a free temp */ - if (pctx->texTemp < 0) - pctx->texTemp = i; - else - break; - } - } - assert(pctx->texTemp >= 0); - - if (pctx->wincoordInput < 0) { - /* declare new position input reg */ - tgsi_transform_input_decl(ctx, wincoordInput, -TGSI_SEMANTIC_POSITION, 1, -TGSI_INTERPOLATE_LINEAR); - } - - /* declare new sampler */ - tgsi_transform_sampler_decl(ctx, pctx->freeSampler); - - /* if the src shader has SVIEW decl's for each SAMP decl, we -* need to continue the trend and ensure there is a matching -*
[Mesa-dev] [PATCH 1/2] draw: use util_pstipple_create_fragment_shader
From: Nicolai HähnleThis reduces code duplication. It also adds support for drivers where the fragment position is a system value. Suggested-by: Jose Fonseca --- A basic polygon stippling test shows no regression on llvmpipe, but that's the extent of my testing. src/gallium/auxiliary/draw/draw_pipe_pstipple.c | 209 ++-- 1 file changed, 12 insertions(+), 197 deletions(-) diff --git a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c index cf52ca4..e468cc3 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c +++ b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c @@ -43,10 +43,10 @@ #include "util/u_format.h" #include "util/u_math.h" #include "util/u_memory.h" +#include "util/u_pstipple.h" #include "util/u_sampler.h" #include "tgsi/tgsi_transform.h" -#include "tgsi/tgsi_dump.h" #include "draw_context.h" #include "draw_pipe.h" @@ -114,178 +114,6 @@ struct pstip_stage }; - -/** - * Subclass of tgsi_transform_context, used for transforming the - * user's fragment shader to add the extra texture sample and fragment kill - * instructions. - */ -struct pstip_transform_context { - struct tgsi_transform_context base; - uint tempsUsed; /**< bitmask */ - int wincoordInput; - int maxInput; - uint samplersUsed; /**< bitfield of samplers used */ - bool hasSview; - int freeSampler; /** an available sampler for the pstipple */ - int texTemp; /**< temp registers */ - int numImmed; -}; - - -/** - * TGSI declaration transform callback. - * Look for a free sampler, a free input attrib, and two free temp regs. - */ -static void -pstip_transform_decl(struct tgsi_transform_context *ctx, - struct tgsi_full_declaration *decl) -{ - struct pstip_transform_context *pctx = (struct pstip_transform_context *) ctx; - - if (decl->Declaration.File == TGSI_FILE_SAMPLER) { - uint i; - for (i = decl->Range.First; - i <= decl->Range.Last; i++) { - pctx->samplersUsed |= 1 << i; - } - } - else if (decl->Declaration.File == TGSI_FILE_SAMPLER_VIEW) { - pctx->hasSview = true; - } - else if (decl->Declaration.File == TGSI_FILE_INPUT) { - pctx->maxInput = MAX2(pctx->maxInput, (int) decl->Range.Last); - if (decl->Semantic.Name == TGSI_SEMANTIC_POSITION) - pctx->wincoordInput = (int) decl->Range.First; - } - else if (decl->Declaration.File == TGSI_FILE_TEMPORARY) { - uint i; - for (i = decl->Range.First; - i <= decl->Range.Last; i++) { - pctx->tempsUsed |= (1 << i); - } - } - - ctx->emit_declaration(ctx, decl); -} - - -/** - * TGSI immediate declaration transform callback. - * We're just counting the number of immediates here. - */ -static void -pstip_transform_immed(struct tgsi_transform_context *ctx, - struct tgsi_full_immediate *immed) -{ - struct pstip_transform_context *pctx = (struct pstip_transform_context *) ctx; - ctx->emit_immediate(ctx, immed); /* emit to output shader */ - pctx->numImmed++; -} - - -/** - * Find the lowest zero bit in the given word, or -1 if bitfield is all ones. - */ -static int -free_bit(uint bitfield) -{ - return ffs(~bitfield) - 1; -} - - -/** - * TGSI transform prolog callback. - */ -static void -pstip_transform_prolog(struct tgsi_transform_context *ctx) -{ - struct pstip_transform_context *pctx = (struct pstip_transform_context *) ctx; - uint i; - int wincoordInput; - - /* find free sampler */ - pctx->freeSampler = free_bit(pctx->samplersUsed); - if (pctx->freeSampler >= PIPE_MAX_SAMPLERS) - pctx->freeSampler = PIPE_MAX_SAMPLERS - 1; - - if (pctx->wincoordInput < 0) - wincoordInput = pctx->maxInput + 1; - else - wincoordInput = pctx->wincoordInput; - - /* find one free temp reg */ - for (i = 0; i < 32; i++) { - if ((pctx->tempsUsed & (1 << i)) == 0) { - /* found a free temp */ - if (pctx->texTemp < 0) - pctx->texTemp = i; - else - break; - } - } - assert(pctx->texTemp >= 0); - - if (pctx->wincoordInput < 0) { - /* declare new position input reg */ - tgsi_transform_input_decl(ctx, wincoordInput, -TGSI_SEMANTIC_POSITION, 1, -TGSI_INTERPOLATE_LINEAR); - } - - /* declare new sampler */ - tgsi_transform_sampler_decl(ctx, pctx->freeSampler); - - /* if the src shader has SVIEW decl's for each SAMP decl, we -* need to continue the trend and ensure there is a matching -* SVIEW for the new SAMP we just created -*/ - if (pctx->hasSview) { - tgsi_transform_sampler_view_decl(ctx, - pctx->freeSampler, - TGSI_TEXTURE_2D, - TGSI_RETURN_TYPE_FLOAT); - } - - /* declare new temp regs */ -