[Mesa-dev] [PATCH 2/8] ureg: add buffer support to ureg
Ilia Mirkin
imirkin at alum.mit.edu
Mon Jan 4 12:26:10 PST 2016
RES is split into two -- BUFFER and IMAGE.
On Mon, Jan 4, 2016 at 3:22 PM, Samuel Pitoiset
<samuel.pitoiset at gmail.com> wrote:
> I assume this is going to replace the old RES stuff?
>
>
> On 01/03/2016 05:37 AM, Ilia Mirkin wrote:
>>
>> Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu>
>> ---
>> src/gallium/auxiliary/tgsi/tgsi_dump.c | 5 +++
>> src/gallium/auxiliary/tgsi/tgsi_strings.c | 1 +
>> src/gallium/auxiliary/tgsi/tgsi_text.c | 5 +++
>> src/gallium/auxiliary/tgsi/tgsi_ureg.c | 52
>> ++++++++++++++++++++++++++++++
>> src/gallium/auxiliary/tgsi/tgsi_ureg.h | 3 ++
>> src/gallium/include/pipe/p_shader_tokens.h | 4 ++-
>> 6 files changed, 69 insertions(+), 1 deletion(-)
>>
>> diff --git a/src/gallium/auxiliary/tgsi/tgsi_dump.c
>> b/src/gallium/auxiliary/tgsi/tgsi_dump.c
>> index dad3839..de3aae5 100644
>> --- a/src/gallium/auxiliary/tgsi/tgsi_dump.c
>> +++ b/src/gallium/auxiliary/tgsi/tgsi_dump.c
>> @@ -359,6 +359,11 @@ iter_declaration(
>> TXT(", RAW");
>> }
>>
>> + if (decl->Declaration.File == TGSI_FILE_BUFFER) {
>> + if (decl->Declaration.Atomic)
>> + TXT(", ATOMIC");
>> + }
>> +
>> if (decl->Declaration.File == TGSI_FILE_SAMPLER_VIEW) {
>> TXT(", ");
>> ENM(decl->SamplerView.Resource, tgsi_texture_names);
>> diff --git a/src/gallium/auxiliary/tgsi/tgsi_strings.c
>> b/src/gallium/auxiliary/tgsi/tgsi_strings.c
>> index ae30399..c0dd044 100644
>> --- a/src/gallium/auxiliary/tgsi/tgsi_strings.c
>> +++ b/src/gallium/auxiliary/tgsi/tgsi_strings.c
>> @@ -56,6 +56,7 @@ static const char *tgsi_file_names[] =
>> "SV",
>> "IMAGE",
>> "SVIEW",
>> + "BUFFER",
>> };
>>
>> const char *tgsi_semantic_names[TGSI_SEMANTIC_COUNT] =
>> diff --git a/src/gallium/auxiliary/tgsi/tgsi_text.c
>> b/src/gallium/auxiliary/tgsi/tgsi_text.c
>> index a45ab90..d72d843 100644
>> --- a/src/gallium/auxiliary/tgsi/tgsi_text.c
>> +++ b/src/gallium/auxiliary/tgsi/tgsi_text.c
>> @@ -1350,6 +1350,11 @@ static boolean parse_declaration( struct
>> translate_ctx *ctx )
>> decl.SamplerView.ReturnTypeX;
>> }
>> ctx->cur = cur;
>> + } else if (file == TGSI_FILE_BUFFER) {
>> + if (str_match_nocase_whole(&cur, "ATOMIC")) {
>> + decl.Declaration.Atomic = 1;
>> + ctx->cur = cur;
>> + }
>> } else {
>> if (str_match_nocase_whole(&cur, "LOCAL")) {
>> decl.Declaration.Local = 1;
>> diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.c
>> b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
>> index ee23df9..6d5092b 100644
>> --- a/src/gallium/auxiliary/tgsi/tgsi_ureg.c
>> +++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
>> @@ -165,6 +165,12 @@ struct ureg_program
>> } image[PIPE_MAX_SHADER_IMAGES];
>> unsigned nr_images;
>>
>> + struct {
>> + unsigned index;
>> + bool atomic;
>> + } buffer[PIPE_MAX_SHADER_BUFFERS];
>> + unsigned nr_buffers;
>> +
>> struct util_bitmask *free_temps;
>> struct util_bitmask *local_temps;
>> struct util_bitmask *decl_temps;
>> @@ -689,6 +695,29 @@ ureg_DECL_image(struct ureg_program *ureg,
>> return reg;
>> }
>>
>> +/* Allocate a new buffer.
>> + */
>> +struct ureg_src ureg_DECL_buffer(struct ureg_program *ureg, unsigned nr,
>> + bool atomic)
>> +{
>> + struct ureg_src reg = ureg_src_register(TGSI_FILE_BUFFER, nr);
>> + unsigned i;
>> +
>> + for (i = 0; i < ureg->nr_buffers; i++)
>> + if (ureg->buffer[i].index == nr)
>> + return reg;
>> +
>> + if (i < PIPE_MAX_SHADER_BUFFERS) {
>> + ureg->buffer[i].index = nr;
>> + ureg->buffer[i].atomic = atomic;
>> + ureg->nr_buffers++;
>> + return reg;
>> + }
>> +
>> + assert(0);
>> + return reg;
>> +}
>> +
>> static int
>> match_or_expand_immediate64( const unsigned *v,
>> int type,
>> @@ -1546,6 +1575,25 @@ emit_decl_image(struct ureg_program *ureg,
>> }
>>
>> static void
>> +emit_decl_buffer(struct ureg_program *ureg,
>> + unsigned index,
>> + bool atomic)
>> +{
>> + union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 2);
>> +
>> + out[0].value = 0;
>> + out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION;
>> + out[0].decl.NrTokens = 2;
>> + out[0].decl.File = TGSI_FILE_BUFFER;
>> + out[0].decl.UsageMask = 0xf;
>> + out[0].decl.Atomic = atomic;
>> +
>> + out[1].value = 0;
>> + out[1].decl_range.First = index;
>> + out[1].decl_range.Last = index;
>> +}
>> +
>> +static void
>> emit_immediate( struct ureg_program *ureg,
>> const unsigned *v,
>> unsigned type )
>> @@ -1713,6 +1761,10 @@ static void emit_decls( struct ureg_program *ureg )
>> ureg->image[i].raw);
>> }
>>
>> + for (i = 0; i < ureg->nr_buffers; i++) {
>> + emit_decl_buffer(ureg, ureg->buffer[i].index,
>> ureg->buffer[i].atomic);
>> + }
>> +
>> if (ureg->const_decls.nr_constant_ranges) {
>> for (i = 0; i < ureg->const_decls.nr_constant_ranges; i++) {
>> emit_decl_range(ureg,
>> diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.h
>> b/src/gallium/auxiliary/tgsi/tgsi_ureg.h
>> index bba2afb..e25c961 100644
>> --- a/src/gallium/auxiliary/tgsi/tgsi_ureg.h
>> +++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.h
>> @@ -335,6 +335,9 @@ ureg_DECL_image(struct ureg_program *ureg,
>> boolean wr,
>> boolean raw);
>>
>> +struct ureg_src
>> +ureg_DECL_buffer(struct ureg_program *ureg, unsigned nr, bool atomic);
>> +
>> static inline struct ureg_src
>> ureg_imm4f( struct ureg_program *ureg,
>> float a, float b,
>> diff --git a/src/gallium/include/pipe/p_shader_tokens.h
>> b/src/gallium/include/pipe/p_shader_tokens.h
>> index d182962..815aff1 100644
>> --- a/src/gallium/include/pipe/p_shader_tokens.h
>> +++ b/src/gallium/include/pipe/p_shader_tokens.h
>> @@ -78,6 +78,7 @@ enum tgsi_file_type {
>> TGSI_FILE_SYSTEM_VALUE =9,
>> TGSI_FILE_IMAGE =10,
>> TGSI_FILE_SAMPLER_VIEW =11,
>> + TGSI_FILE_BUFFER =12,
>> TGSI_FILE_COUNT /**< how many TGSI_FILE_ types */
>> };
>>
>> @@ -127,7 +128,8 @@ struct tgsi_declaration
>> unsigned Invariant : 1; /**< invariant optimization? */
>> unsigned Local : 1; /**< optimize as subroutine local
>> variable? */
>> unsigned Array : 1; /**< extra array info? */
>> - unsigned Padding : 6;
>> + unsigned Atomic : 1; /**< atomic only? for TGSI_FILE_BUFFER */
>> + unsigned Padding : 5;
>> };
>>
>> struct tgsi_declaration_range
>>
>
More information about the mesa-dev
mailing list