Re: [Mesa-dev] [PATCH 0/2] egl/android: A few trivial cleanups

2017-05-28 Thread Tapani Pälli

Reviewed-by: Tapani Pälli 

On 05/27/2017 01:09 AM, Chad Versace wrote:

Chad Versace (2):
   egl/android: Align channel masks in HAL_PIXEL_FORMAT table
   egl/android: Drop unused 'format' param in get_back_bo()

  src/egl/drivers/dri2/platform_android.c | 12 ++--
  1 file changed, 6 insertions(+), 6 deletions(-)


___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] soft fp64 on evergreen

2017-05-28 Thread Dave Airlie
>>> I also notice some really large times in the GLSL->TGSI pass copy
>>> propogation on mul/div tests with matrices, tests take a fair while to
>>> complete.
>>>
>>
>> Unrelated to this I have noticed on some profiles when using nvc0
>> that the GLSL->TGSI passes are quite painful on compile times.
>> Especially copy propagation shows up as a big one.
>> Not sure if there is some easy gains to be had here as I haven't
>> looked at the pass at all.
> The GLSL->TGSI passes is probably slow too but I'm quite sure that my
> code doesn't help...

Okay, the main problem with the tgsi passes is the sheer number of temporaries
overwhelms it.

For start st_src/dest_reg has a int16_t for index, on

/home/airlied/devel/piglit/tests/spec/arb_gpu_shader_fp64/execution/vs-increment-dvec.shader_test
we enter this code wantined to use over 32000 temps, if I fix the
int16->int32, the final code seems
to only use about 20 temps.

Dave.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] soft fp64 on evergreen

2017-05-28 Thread Dave Airlie
On 26 May 2017 at 20:43, tournier.elie  wrote:
> Hi,
>
> First of all sorry for the mess in my repo. ;)
>
> On 26 May 2017 at 11:16, Thomas Helland  wrote:
>> 2017-05-26 8:13 GMT+02:00 Dave Airlie :
>>> Hi Elie,
>>>
>>> Thanks for the fp64 work.
>>>
>>> I've pulled the latest branch from your repo and start running piglit
>>> on a BARTS (r600g) GPU.
>>>
>>> I've noticed a few asserts with a debug build in ir_validate, do you
>>> test with --enable-debug?
> I run the test on my laptop using softpipe. But aboll sent me the test
> he run on an r600g.

I've done a first round of fixups,

https://cgit.freedesktop.org/~airlied/mesa/log/?h=glsl_arb_gpu_shader_fp64

has 3 patches on yours, this fixes asserts I was getting here just trying to run
generated_tests/spec/arb_gpu_shader_fp64/execution/built-in-functions/fs-abs-double.shader_test

This test now passes on my evergreen with that branch.

I'll see how piglit goes and pushed anything else I find there.

Dave.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [Bug 101223] Mesa fails to build with clang

2017-05-28 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=101223

Bug ID: 101223
   Summary: Mesa fails to build with clang
   Product: Mesa
   Version: git
  Hardware: Other
OS: All
Status: NEW
  Severity: normal
  Priority: medium
 Component: Mesa core
  Assignee: mesa-dev@lists.freedesktop.org
  Reporter: m...@fireburn.co.uk
QA Contact: mesa-dev@lists.freedesktop.org

Created attachment 131560
  --> https://bugs.freedesktop.org/attachment.cgi?id=131560=edit
Build log

I get the following errors:

glsl/.libs/libstandalone.a(libmesautil_la-disk_cache.o):/var/tmp/portage/media-libs/mesa-/work/mesa-/src/util/disk_cache.c:function
disk_cache_remove: error: undefined reference to '__atomic_fetch_add_8'
glsl/.libs/libstandalone.a(libmesautil_la-disk_cache.o):/var/tmp/portage/media-libs/mesa-/work/mesa-/src/util/disk_cache.c:function
cache_put: error: undefined reference to '__atomic_fetch_add_8'
glsl/.libs/libstandalone.a(libmesautil_la-disk_cache.o):/var/tmp/portage/media-libs/mesa-/work/mesa-/src/util/disk_cache.c:function
cache_put: error: undefined reference to '__atomic_fetch_add_8'

I'm attaching the complete log

-- 
You are receiving this mail because:
You are the assignee for the bug.
You are the QA Contact for the bug.___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH] svga: fix git_sha1.h include path in Android.mk

2017-05-28 Thread Mauro Rossi
2017-05-28 21:02 GMT+02:00 Rob Herring :

> On Sun, May 28, 2017 at 1:31 PM, Mauro Rossi 
> wrote:
> >
> >
> > 2017-05-28 16:46 GMT+02:00 Rob Herring :
> >>
> >> On Fri, May 26, 2017 at 10:15 AM, Mauro Rossi 
> >> wrote:
> >> > Fixes the following building error:
> >> >
> >> > external/mesa/src/gallium/drivers/svga/svga_screen.c:26:10:
> >> > fatal error: 'git_sha1.h' file not found
> >> >  ^
> >> > 1 error generated.
> >> > ---
> >> >  src/gallium/drivers/svga/Android.mk | 4 +++-
> >> >  1 file changed, 3 insertions(+), 1 deletion(-)
> >> >
> >> > diff --git a/src/gallium/drivers/svga/Android.mk
> >> > b/src/gallium/drivers/svga/Android.mk
> >> > index c50743d509..d19bd59bfe 100644
> >> > --- a/src/gallium/drivers/svga/Android.mk
> >> > +++ b/src/gallium/drivers/svga/Android.mk
> >> > @@ -30,7 +30,9 @@ include $(CLEAR_VARS)
> >> >
> >> >  LOCAL_SRC_FILES := $(C_SOURCES)
> >> >
> >> > -LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
> >> > +LOCAL_C_INCLUDES := \
> >> > +   $(LOCAL_PATH)/include \
> >> > +   $(call
> >> > generated-sources-dir-for,STATIC_LIBRARIES,libmesa_dricore,,)/main
> >>
> >> Add this path to LOCAL_EXPORT_C_INCLUDE_DIRS in libmesa_dricore and
> >> add libmesa_dricore as a static lib here instead.
> >>
> >> Rob
> >
> >
> > Hi Rob,
> > just a few questions,
> >
> > why should we export the header which is artificially associated to
> > libmesa_dricore
> > and why treat this as a 'fake dependency'? The LOCAL_C_INCLUDE should
> > suffice
> >
> > What is benefit in doing this? What is the drawback in using the android
> > macro created for this purpose?
>
> I can think of several reasons:
>
> LOCAL_* variables are more simple and less likely to change than
> generated-sources-dir-for. Doesn't matter so much when there's only
> one dependency, but if several drivers needed this, then it becomes
> more important. Also, I don't know how to do the equivalent of
> generated-sources-dir-for in blueprint files, but exporting includes
> is easy.
>
> It keeps any details of the structure of libmesa_dri_core within it.
> For example, look at the mess libelf was with include paths changing.
>
> There are now "header libraries" which would be more what we want here
> as we don't need to link it. However, those are new and won't work in
> prior android versions, but eventually we'll want to move to that.
>
> Maybe the header should be it's own module if it's really not related
> to the rest of libmesa_dri_core. The other option is create a variable
> with the path in libmesa_dri_core and then use it here (in
> LOCAL_C_INCLUDE). I think there's a few examples of doing that.
>
> Rob
>

Thanks for the hint
I'll try with the variable as it is the same mechanism used for NIR and
GLSL generated headers
and we can avoid declaring a fake static dependency.

Mauro
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH] svga: fix git_sha1.h include path in Android.mk

2017-05-28 Thread Mauro Rossi
2017-05-28 21:02 GMT+02:00 Rob Herring :

> On Sun, May 28, 2017 at 1:31 PM, Mauro Rossi 
> wrote:
> >
> >
> > 2017-05-28 16:46 GMT+02:00 Rob Herring :
> >>
> >> On Fri, May 26, 2017 at 10:15 AM, Mauro Rossi 
> >> wrote:
> >> > Fixes the following building error:
> >> >
> >> > external/mesa/src/gallium/drivers/svga/svga_screen.c:26:10:
> >> > fatal error: 'git_sha1.h' file not found
> >> >  ^
> >> > 1 error generated.
> >> > ---
> >> >  src/gallium/drivers/svga/Android.mk | 4 +++-
> >> >  1 file changed, 3 insertions(+), 1 deletion(-)
> >> >
> >> > diff --git a/src/gallium/drivers/svga/Android.mk
> >> > b/src/gallium/drivers/svga/Android.mk
> >> > index c50743d509..d19bd59bfe 100644
> >> > --- a/src/gallium/drivers/svga/Android.mk
> >> > +++ b/src/gallium/drivers/svga/Android.mk
> >> > @@ -30,7 +30,9 @@ include $(CLEAR_VARS)
> >> >
> >> >  LOCAL_SRC_FILES := $(C_SOURCES)
> >> >
> >> > -LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
> >> > +LOCAL_C_INCLUDES := \
> >> > +   $(LOCAL_PATH)/include \
> >> > +   $(call
> >> > generated-sources-dir-for,STATIC_LIBRARIES,libmesa_dricore,,)/main
> >>
> >> Add this path to LOCAL_EXPORT_C_INCLUDE_DIRS in libmesa_dricore and
> >> add libmesa_dricore as a static lib here instead.
> >>
> >> Rob
> >
> >
> > Hi Rob,
> > just a few questions,
> >
> > why should we export the header which is artificially associated to
> > libmesa_dricore
> > and why treat this as a 'fake dependency'? The LOCAL_C_INCLUDE should
> > suffice
> >
> > What is benefit in doing this? What is the drawback in using the android
> > macro created for this purpose?
>
> I can think of several reasons:
>
> LOCAL_* variables are more simple and less likely to change than
> generated-sources-dir-for. Doesn't matter so much when there's only
> one dependency, but if several drivers needed this, then it becomes
> more important. Also, I don't know how to do the equivalent of
> generated-sources-dir-for in blueprint files, but exporting includes
> is easy.
>
> It keeps any details of the structure of libmesa_dri_core within it.
> For example, look at the mess libelf was with include paths changing.
>
> There are now "header libraries" which would be more what we want here
> as we don't need to link it. However, those are new and won't work in
> prior android versions, but eventually we'll want to move to that.
>
> Maybe the header should be it's own module if it's really not related
> to the rest of libmesa_dri_core. The other option is create a variable
> with the path in libmesa_dri_core and then use it here (in
> LOCAL_C_INCLUDE). I think there's a few examples of doing that.
>
> Rob
>

Thanks

The generation rules for git_sha1.h are now in  src/mesa/Android.gen.mk
which is included by two android makefiles hereby reported in their order:

src/mesa/Android.libmesa_dricore.mk
src/mesa/Android.libmesa_st_mesa.mk

Which is better to use to do the  LOCAL_EXPORT_C_INCLUDE_DIRS or is it the
same?
M.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] radv: Reserve space for descriptor and push constant user SGPR setting.

2017-05-28 Thread Bas Nieuwenhuizen
flush_compute_state doesn't reserve a large chunk, so these need their own 
reservation.

Signed-off-by: Bas Nieuwenhuizen 
Fixes: f4e499ec791 "radv: add initial non-conformant radv vulkan driver"
---
 src/amd/vulkan/radv_cmd_buffer.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/src/amd/vulkan/radv_cmd_buffer.c b/src/amd/vulkan/radv_cmd_buffer.c
index eff0fd68c9f..66610e5233f 100644
--- a/src/amd/vulkan/radv_cmd_buffer.c
+++ b/src/amd/vulkan/radv_cmd_buffer.c
@@ -1364,6 +1364,10 @@ radv_flush_descriptors(struct radv_cmd_buffer 
*cmd_buffer,
radv_flush_indirect_descriptor_sets(cmd_buffer, pipeline);
}
 
+   MAYBE_UNUSED unsigned cdw_max = 
radeon_check_space(cmd_buffer->device->ws,
+  cmd_buffer->cs,
+  MAX_SETS * 
MESA_SHADER_STAGES * 4);
+
for (i = 0; i < MAX_SETS; i++) {
if (!(cmd_buffer->state.descriptors_dirty & (1u << i)))
continue;
@@ -1375,6 +1379,7 @@ radv_flush_descriptors(struct radv_cmd_buffer *cmd_buffer,
}
cmd_buffer->state.descriptors_dirty = 0;
cmd_buffer->state.push_descriptors_dirty = false;
+   assert(cmd_buffer->cs->cdw <= cdw_max);
 }
 
 static void
@@ -1403,6 +1408,8 @@ radv_flush_constants(struct radv_cmd_buffer *cmd_buffer,
va = 
cmd_buffer->device->ws->buffer_get_va(cmd_buffer->upload.upload_bo);
va += offset;
 
+   MAYBE_UNUSED unsigned cdw_max = 
radeon_check_space(cmd_buffer->device->ws,
+  cmd_buffer->cs, 
MESA_SHADER_STAGES * 4);
if (stages & VK_SHADER_STAGE_VERTEX_BIT)
radv_emit_userdata_address(cmd_buffer, pipeline, 
MESA_SHADER_VERTEX,
   AC_UD_PUSH_CONSTANTS, va);
@@ -1428,6 +1435,7 @@ radv_flush_constants(struct radv_cmd_buffer *cmd_buffer,
   AC_UD_PUSH_CONSTANTS, va);
 
cmd_buffer->push_constant_stages &= ~stages;
+   assert(cmd_buffer->cs->cdw <= cdw_max);
 }
 
 static void radv_emit_primitive_reset_state(struct radv_cmd_buffer *cmd_buffer,
-- 
2.13.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH] svga: fix git_sha1.h include path in Android.mk

2017-05-28 Thread Rob Herring
On Sun, May 28, 2017 at 1:31 PM, Mauro Rossi  wrote:
>
>
> 2017-05-28 16:46 GMT+02:00 Rob Herring :
>>
>> On Fri, May 26, 2017 at 10:15 AM, Mauro Rossi 
>> wrote:
>> > Fixes the following building error:
>> >
>> > external/mesa/src/gallium/drivers/svga/svga_screen.c:26:10:
>> > fatal error: 'git_sha1.h' file not found
>> >  ^
>> > 1 error generated.
>> > ---
>> >  src/gallium/drivers/svga/Android.mk | 4 +++-
>> >  1 file changed, 3 insertions(+), 1 deletion(-)
>> >
>> > diff --git a/src/gallium/drivers/svga/Android.mk
>> > b/src/gallium/drivers/svga/Android.mk
>> > index c50743d509..d19bd59bfe 100644
>> > --- a/src/gallium/drivers/svga/Android.mk
>> > +++ b/src/gallium/drivers/svga/Android.mk
>> > @@ -30,7 +30,9 @@ include $(CLEAR_VARS)
>> >
>> >  LOCAL_SRC_FILES := $(C_SOURCES)
>> >
>> > -LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
>> > +LOCAL_C_INCLUDES := \
>> > +   $(LOCAL_PATH)/include \
>> > +   $(call
>> > generated-sources-dir-for,STATIC_LIBRARIES,libmesa_dricore,,)/main
>>
>> Add this path to LOCAL_EXPORT_C_INCLUDE_DIRS in libmesa_dricore and
>> add libmesa_dricore as a static lib here instead.
>>
>> Rob
>
>
> Hi Rob,
> just a few questions,
>
> why should we export the header which is artificially associated to
> libmesa_dricore
> and why treat this as a 'fake dependency'? The LOCAL_C_INCLUDE should
> suffice
>
> What is benefit in doing this? What is the drawback in using the android
> macro created for this purpose?

I can think of several reasons:

LOCAL_* variables are more simple and less likely to change than
generated-sources-dir-for. Doesn't matter so much when there's only
one dependency, but if several drivers needed this, then it becomes
more important. Also, I don't know how to do the equivalent of
generated-sources-dir-for in blueprint files, but exporting includes
is easy.

It keeps any details of the structure of libmesa_dri_core within it.
For example, look at the mess libelf was with include paths changing.

There are now "header libraries" which would be more what we want here
as we don't need to link it. However, those are new and won't work in
prior android versions, but eventually we'll want to move to that.

Maybe the header should be it's own module if it's really not related
to the rest of libmesa_dri_core. The other option is create a variable
with the path in libmesa_dri_core and then use it here (in
LOCAL_C_INCLUDE). I think there's a few examples of doing that.

Rob
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH] svga: fix git_sha1.h include path in Android.mk

2017-05-28 Thread Mauro Rossi
2017-05-28 16:46 GMT+02:00 Rob Herring :

> On Fri, May 26, 2017 at 10:15 AM, Mauro Rossi 
> wrote:
> > Fixes the following building error:
> >
> > external/mesa/src/gallium/drivers/svga/svga_screen.c:26:10:
> > fatal error: 'git_sha1.h' file not found
> >  ^
> > 1 error generated.
> > ---
> >  src/gallium/drivers/svga/Android.mk | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/src/gallium/drivers/svga/Android.mk
> b/src/gallium/drivers/svga/Android.mk
> > index c50743d509..d19bd59bfe 100644
> > --- a/src/gallium/drivers/svga/Android.mk
> > +++ b/src/gallium/drivers/svga/Android.mk
> > @@ -30,7 +30,9 @@ include $(CLEAR_VARS)
> >
> >  LOCAL_SRC_FILES := $(C_SOURCES)
> >
> > -LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
> > +LOCAL_C_INCLUDES := \
> > +   $(LOCAL_PATH)/include \
> > +   $(call generated-sources-dir-for,STATIC_LIBRARIES,libmesa_
> dricore,,)/main
>
> Add this path to LOCAL_EXPORT_C_INCLUDE_DIRS in libmesa_dricore and
> add libmesa_dricore as a static lib here instead.
>
> Rob
>

Hi Rob,
just a few questions,

why should we export the header which is artificially associated to
libmesa_dricore
and why treat this as a 'fake dependency'? The LOCAL_C_INCLUDE should
suffice

What is benefit in doing this? What is the drawback in using the android
macro created for this purpose?
Thanks

Mauro
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] glsl: Change the parser to use the string buffer

2017-05-28 Thread Thomas Helland
V2: Pointed out by Timothy running the CI
   - Fix pp.c reralloc size issue and comment

V3 - Use vprintf instead of printf where we should
   - Fixes failing make-check tests
---
 src/compiler/glsl/glcpp/glcpp-parse.y | 85 ++-
 src/compiler/glsl/glcpp/glcpp.h   |  8 ++--
 src/compiler/glsl/glcpp/pp.c  | 39 +++-
 3 files changed, 64 insertions(+), 68 deletions(-)

diff --git a/src/compiler/glsl/glcpp/glcpp-parse.y 
b/src/compiler/glsl/glcpp/glcpp-parse.y
index fe211a0f0b..e84b6fb055 100644
--- a/src/compiler/glsl/glcpp/glcpp-parse.y
+++ b/src/compiler/glsl/glcpp/glcpp-parse.y
@@ -209,7 +209,7 @@ line:
 |  SPACE control_line
 |  text_line {
_glcpp_parser_print_expanded_token_list (parser, $1);
-   ralloc_asprintf_rewrite_tail (>output, 
>output_length, "\n");
+   _mesa_string_buffer_append_char(parser->output, '\n');
}
 |  expanded_line
 ;
@@ -228,20 +228,16 @@ expanded_line:
 |  LINE_EXPANDED integer_constant NEWLINE {
parser->has_new_line_number = 1;
parser->new_line_number = $2;
-   ralloc_asprintf_rewrite_tail (>output,
- >output_length,
- "#line %" PRIiMAX "\n",
- $2);
+   _mesa_string_buffer_printf(parser->output, "#line %" PRIiMAX 
"\n", $2);
}
 |  LINE_EXPANDED integer_constant integer_constant NEWLINE {
parser->has_new_line_number = 1;
parser->new_line_number = $2;
parser->has_new_source_number = 1;
parser->new_source_number = $3;
-   ralloc_asprintf_rewrite_tail (>output,
- >output_length,
- "#line %" PRIiMAX " %" PRIiMAX 
"\n",
- $2, $3);
+   _mesa_string_buffer_printf(parser->output,
+  "#line %" PRIiMAX " %" PRIiMAX "\n",
+   $2, $3);
}
 ;
 
@@ -259,7 +255,7 @@ define:
 
 control_line:
control_line_success {
-   ralloc_asprintf_rewrite_tail (>output, 
>output_length, "\n");
+   _mesa_string_buffer_append_char(parser->output, '\n');
}
 |  control_line_error
 |  HASH_TOKEN LINE pp_tokens NEWLINE {
@@ -432,7 +428,7 @@ control_line_success:
glcpp_parser_resolve_implicit_version(parser);
}
 |  HASH_TOKEN PRAGMA NEWLINE {
-   ralloc_asprintf_rewrite_tail (>output, 
>output_length, "#%s", $2);
+   _mesa_string_buffer_printf(parser->output, "#%s", $2);
}
 ;
 
@@ -1110,60 +1106,60 @@ _token_list_equal_ignoring_space(token_list_t *a, 
token_list_t *b)
 }
 
 static void
-_token_print(char **out, size_t *len, token_t *token)
+_token_print(struct _mesa_string_buffer *out, token_t *token)
 {
if (token->type < 256) {
-  ralloc_asprintf_rewrite_tail (out, len, "%c", token->type);
+  _mesa_string_buffer_printf(out,"%c", token->type);
   return;
}
 
switch (token->type) {
case INTEGER:
-  ralloc_asprintf_rewrite_tail (out, len, "%" PRIiMAX, token->value.ival);
+  _mesa_string_buffer_printf(out, "%" PRIiMAX, token->value.ival);
   break;
case IDENTIFIER:
case INTEGER_STRING:
case OTHER:
-  ralloc_asprintf_rewrite_tail (out, len, "%s", token->value.str);
+  _mesa_string_buffer_append(out, token->value.str);
   break;
case SPACE:
-  ralloc_asprintf_rewrite_tail (out, len, " ");
+  _mesa_string_buffer_append(out, " ");
   break;
case LEFT_SHIFT:
-  ralloc_asprintf_rewrite_tail (out, len, "<<");
+  _mesa_string_buffer_append(out, "<<");
   break;
case RIGHT_SHIFT:
-  ralloc_asprintf_rewrite_tail (out, len, ">>");
+  _mesa_string_buffer_append(out, ">>");
   break;
case LESS_OR_EQUAL:
-  ralloc_asprintf_rewrite_tail (out, len, "<=");
+  _mesa_string_buffer_append(out, "<=");
   break;
case GREATER_OR_EQUAL:
-  ralloc_asprintf_rewrite_tail (out, len, ">=");
+  _mesa_string_buffer_append(out, ">=");
   break;
case EQUAL:
-  ralloc_asprintf_rewrite_tail (out, len, "==");
+  _mesa_string_buffer_append(out, "==");
   break;
case NOT_EQUAL:
-  ralloc_asprintf_rewrite_tail (out, len, "!=");
+  _mesa_string_buffer_append(out, "!=");
   break;
case AND:
-  ralloc_asprintf_rewrite_tail (out, len, "&&");
+  _mesa_string_buffer_append(out, "&&");
   break;
case OR:
-  ralloc_asprintf_rewrite_tail (out, len, "||");
+  _mesa_string_buffer_append(out, "||");
   break;
case PASTE:
-  ralloc_asprintf_rewrite_tail (out, len, "##");
+  _mesa_string_buffer_append(out, "##");
   break;
case 

Re: [Mesa-dev] [PATCH] glsl: Change the parser to use the string buffer

2017-05-28 Thread Thomas Helland
2017-05-28 15:19 GMT+02:00 Thomas Helland :
> V2: Failure found by Timothy running it through CI
>- Fix pp.c reralloc size issue and comment

There is still something here that doesn't work as intended.
Some tests are failing  I'll report once I find the cause.

> ---
>  src/compiler/glsl/glcpp/glcpp-parse.y | 85 
> ++-
>  src/compiler/glsl/glcpp/glcpp.h   |  8 ++--
>  src/compiler/glsl/glcpp/pp.c  | 39 +++-
>  3 files changed, 64 insertions(+), 68 deletions(-)
>
> diff --git a/src/compiler/glsl/glcpp/glcpp-parse.y 
> b/src/compiler/glsl/glcpp/glcpp-parse.y
> index fe211a0f0b..e84b6fb055 100644
> --- a/src/compiler/glsl/glcpp/glcpp-parse.y
> +++ b/src/compiler/glsl/glcpp/glcpp-parse.y
> @@ -209,7 +209,7 @@ line:
>  |  SPACE control_line
>  |  text_line {
> _glcpp_parser_print_expanded_token_list (parser, $1);
> -   ralloc_asprintf_rewrite_tail (>output, 
> >output_length, "\n");
> +   _mesa_string_buffer_append_char(parser->output, '\n');
> }
>  |  expanded_line
>  ;
> @@ -228,20 +228,16 @@ expanded_line:
>  |  LINE_EXPANDED integer_constant NEWLINE {
> parser->has_new_line_number = 1;
> parser->new_line_number = $2;
> -   ralloc_asprintf_rewrite_tail (>output,
> - >output_length,
> - "#line %" PRIiMAX "\n",
> - $2);
> +   _mesa_string_buffer_printf(parser->output, "#line %" PRIiMAX 
> "\n", $2);
> }
>  |  LINE_EXPANDED integer_constant integer_constant NEWLINE {
> parser->has_new_line_number = 1;
> parser->new_line_number = $2;
> parser->has_new_source_number = 1;
> parser->new_source_number = $3;
> -   ralloc_asprintf_rewrite_tail (>output,
> - >output_length,
> - "#line %" PRIiMAX " %" PRIiMAX 
> "\n",
> - $2, $3);
> +   _mesa_string_buffer_printf(parser->output,
> +  "#line %" PRIiMAX " %" PRIiMAX 
> "\n",
> +   $2, $3);
> }
>  ;
>
> @@ -259,7 +255,7 @@ define:
>
>  control_line:
> control_line_success {
> -   ralloc_asprintf_rewrite_tail (>output, 
> >output_length, "\n");
> +   _mesa_string_buffer_append_char(parser->output, '\n');
> }
>  |  control_line_error
>  |  HASH_TOKEN LINE pp_tokens NEWLINE {
> @@ -432,7 +428,7 @@ control_line_success:
> glcpp_parser_resolve_implicit_version(parser);
> }
>  |  HASH_TOKEN PRAGMA NEWLINE {
> -   ralloc_asprintf_rewrite_tail (>output, 
> >output_length, "#%s", $2);
> +   _mesa_string_buffer_printf(parser->output, "#%s", $2);
> }
>  ;
>
> @@ -1110,60 +1106,60 @@ _token_list_equal_ignoring_space(token_list_t *a, 
> token_list_t *b)
>  }
>
>  static void
> -_token_print(char **out, size_t *len, token_t *token)
> +_token_print(struct _mesa_string_buffer *out, token_t *token)
>  {
> if (token->type < 256) {
> -  ralloc_asprintf_rewrite_tail (out, len, "%c", token->type);
> +  _mesa_string_buffer_printf(out,"%c", token->type);
>return;
> }
>
> switch (token->type) {
> case INTEGER:
> -  ralloc_asprintf_rewrite_tail (out, len, "%" PRIiMAX, 
> token->value.ival);
> +  _mesa_string_buffer_printf(out, "%" PRIiMAX, token->value.ival);
>break;
> case IDENTIFIER:
> case INTEGER_STRING:
> case OTHER:
> -  ralloc_asprintf_rewrite_tail (out, len, "%s", token->value.str);
> +  _mesa_string_buffer_append(out, token->value.str);
>break;
> case SPACE:
> -  ralloc_asprintf_rewrite_tail (out, len, " ");
> +  _mesa_string_buffer_append(out, " ");
>break;
> case LEFT_SHIFT:
> -  ralloc_asprintf_rewrite_tail (out, len, "<<");
> +  _mesa_string_buffer_append(out, "<<");
>break;
> case RIGHT_SHIFT:
> -  ralloc_asprintf_rewrite_tail (out, len, ">>");
> +  _mesa_string_buffer_append(out, ">>");
>break;
> case LESS_OR_EQUAL:
> -  ralloc_asprintf_rewrite_tail (out, len, "<=");
> +  _mesa_string_buffer_append(out, "<=");
>break;
> case GREATER_OR_EQUAL:
> -  ralloc_asprintf_rewrite_tail (out, len, ">=");
> +  _mesa_string_buffer_append(out, ">=");
>break;
> case EQUAL:
> -  ralloc_asprintf_rewrite_tail (out, len, "==");
> +  _mesa_string_buffer_append(out, "==");
>break;
> case NOT_EQUAL:
> -  ralloc_asprintf_rewrite_tail (out, len, "!=");
> +  _mesa_string_buffer_append(out, "!=");
>break;
> case AND:
> -  

[Mesa-dev] [Bug 101199] nouveau_screen.c: undefined reference to `nouveau_drm_del'

2017-05-28 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=101199

--- Comment #5 from Ilia Mirkin  ---
(In reply to Andrey from comment #4)
> This is an issue with the Mesa build system. The configure script should
> choose right libdrm from PKG_CONFIG_PATH specified.

The configure script does pick the right libdrm. (Otherwise it wouldn't let you
build with 2.4.60.)

You're probably going to have to do the debugging yourself to figure out why or
how the wrong file is being picked up.

-- 
You are receiving this mail because:
You are the QA Contact for the bug.
You are the assignee for the bug.___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH V3] util: Add a string buffer implementation

2017-05-28 Thread Thomas Helland
Based on Vladislav Egorovs work on the preprocessor, but split
out to a util functionality that should be universal. Setup, teardown,
memory handling and general layout is modeled around the hash_table
and the set, to make it familiar for everyone.

A notable change is that this implementation is always null terminated.
The rationale is that it will be less error-prone, as one might
access the buffer directly, thereby reading a non-terminated string.
Also, vsnprintf and friends prints the null-terminator.

V2: Address review feedback from Timothy and Grazvydas
   - Fix MINGW preprocessor check
   - Changed len from uint to int
   - Make string argument const in append function
   - Move to header and inline append function
   - Add crimp_to_fit function for resizing buffer

V3: Move include of ralloc to string_buffer.h
---
 src/util/Makefile.sources |   2 +
 src/util/string_buffer.c  | 172 ++
 src/util/string_buffer.h  |  86 +++
 3 files changed, 260 insertions(+)
 create mode 100644 src/util/string_buffer.c
 create mode 100644 src/util/string_buffer.h

diff --git a/src/util/Makefile.sources b/src/util/Makefile.sources
index e9057343dc..cb46639c87 100644
--- a/src/util/Makefile.sources
+++ b/src/util/Makefile.sources
@@ -37,6 +37,8 @@ MESA_UTIL_FILES := \
simple_list.h \
slab.c \
slab.h \
+   string_buffer.c \
+   string_buffer.h \
string_to_uint_map.cpp \
string_to_uint_map.h \
strndup.h \
diff --git a/src/util/string_buffer.c b/src/util/string_buffer.c
new file mode 100644
index 00..488766aa61
--- /dev/null
+++ b/src/util/string_buffer.c
@@ -0,0 +1,172 @@
+/*
+ * Copyright © 2017 Thomas Helland
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+#include "string_buffer.h"
+
+static bool
+ensure_capacity(struct _mesa_string_buffer *str, uint32_t needed_capacity)
+{
+   if (needed_capacity <= str->capacity)
+  return true;
+
+   /* Too small, we have to resize our buffer.
+* Double until we can fit the new string.
+*/
+   uint32_t new_capacity = str->capacity * 2;
+   while (needed_capacity > new_capacity)
+  new_capacity *= 2;
+
+   str->buf = reralloc_array_size(str, str->buf, sizeof(char), new_capacity);
+   if (str->buf == NULL)
+  return false;
+
+   str->capacity = new_capacity;
+   return true;
+}
+
+struct _mesa_string_buffer *
+_mesa_string_buffer_create(void *mem_ctx, uint32_t initial_capacity)
+{
+   struct _mesa_string_buffer *str;
+   str = ralloc(mem_ctx, struct _mesa_string_buffer);
+
+   if (str == NULL)
+  return NULL;
+
+   /* If no initial capacity is set then set it to something */
+   str->capacity = initial_capacity ? initial_capacity : 8;
+   str->buf = ralloc_array(str, char, str->capacity);
+   str->length = 0;
+   str->buf[str->length] = '\0';
+   return str;
+}
+
+void
+_mesa_string_buffer_destroy(struct _mesa_string_buffer *str)
+{
+   ralloc_free(str);
+}
+
+bool
+_mesa_string_buffer_append_all(struct _mesa_string_buffer *str,
+   uint32_t num_args, ...)
+{
+   int i;
+   char* s;
+   va_list args;
+   va_start(args, num_args);
+   for (i = 0; i < num_args; i++) {
+  s = va_arg(args, char*);
+  if (!_mesa_string_buffer_append_len(str, s, strlen(s)))
+ return false;
+   }
+   va_end(args);
+   return true;
+}
+
+bool
+_mesa_string_buffer_append_len(struct _mesa_string_buffer *str,
+   const char *c, uint32_t len)
+{
+   uint32_t needed_length = str->length + len + 1;
+   if (!ensure_capacity(str, needed_length))
+  return false;
+
+   memcpy(str->buf + str->length, c, len);
+   str->length += len;
+   str->buf[str->length] = '\0';
+   return true;
+}
+
+void
+_mesa_string_buffer_clear(struct _mesa_string_buffer *str)
+{
+   str->length = 0;
+   str->buf[str->length] = '\0';
+}
+
+uint32_t

Re: [Mesa-dev] [PATCH] svga: fix git_sha1.h include path in Android.mk

2017-05-28 Thread Rob Herring
On Fri, May 26, 2017 at 10:15 AM, Mauro Rossi  wrote:
> Fixes the following building error:
>
> external/mesa/src/gallium/drivers/svga/svga_screen.c:26:10:
> fatal error: 'git_sha1.h' file not found
>  ^
> 1 error generated.
> ---
>  src/gallium/drivers/svga/Android.mk | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/src/gallium/drivers/svga/Android.mk 
> b/src/gallium/drivers/svga/Android.mk
> index c50743d509..d19bd59bfe 100644
> --- a/src/gallium/drivers/svga/Android.mk
> +++ b/src/gallium/drivers/svga/Android.mk
> @@ -30,7 +30,9 @@ include $(CLEAR_VARS)
>
>  LOCAL_SRC_FILES := $(C_SOURCES)
>
> -LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
> +LOCAL_C_INCLUDES := \
> +   $(LOCAL_PATH)/include \
> +   $(call 
> generated-sources-dir-for,STATIC_LIBRARIES,libmesa_dricore,,)/main

Add this path to LOCAL_EXPORT_C_INCLUDE_DIRS in libmesa_dricore and
add libmesa_dricore as a static lib here instead.

Rob
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [Bug 101214] xdriinfo and libglvnd Screen 0: not direct rendering capable

2017-05-28 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=101214

LoneVVolf  changed:

   What|Removed |Added

 CC||emil.l.veli...@gmail.com

-- 
You are receiving this mail because:
You are the assignee for the bug.___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [Bug 101214] xdriinfo and libglvnd Screen 0: not direct rendering capable

2017-05-28 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=101214

LoneVVolf  changed:

   What|Removed |Added

 CC||jwrdego...@fedoraproject.or
   ||g

-- 
You are receiving this mail because:
You are the assignee for the bug.___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 3/5] r600: remove libamd_common dependency

2017-05-28 Thread Rob Herring
On Fri, May 26, 2017 at 10:32 AM, Emil Velikov  wrote:
> From: Emil Velikov 
>
> Seemingly nothing in r600 depends on it any more.
>
> This is the second step to unwrapping the amdgpu dependency out of r600.
>
> Reported-by: udovdh on #dri-devel
> Cc: Nicolai Hähnle 
> Cc: Marek Olšák 
> Signed-off-by: Emil Velikov 
> ---
>  configure.ac  | 3 +--
>  src/gallium/drivers/r600/Android.mk   | 5 -
>  src/gallium/drivers/r600/Automake.inc | 5 -
>  3 files changed, 1 insertion(+), 12 deletions(-)
>
> diff --git a/configure.ac b/configure.ac
> index b57be07e24a..6969af1d8d7 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -2635,8 +2635,7 @@ AM_CONDITIONAL(HAVE_SWRAST_DRI, test x$HAVE_SWRAST_DRI 
> = xyes)
>  AM_CONDITIONAL(HAVE_RADEON_VULKAN, test "x$HAVE_RADEON_VULKAN" = xyes)
>  AM_CONDITIONAL(HAVE_INTEL_VULKAN, test "x$HAVE_INTEL_VULKAN" = xyes)
>
> -AM_CONDITIONAL(HAVE_AMD_DRIVERS, test "x$HAVE_GALLIUM_R600" = xyes -o \
> -  "x$HAVE_GALLIUM_RADEONSI" = xyes -o \
> +AM_CONDITIONAL(HAVE_AMD_DRIVERS, test "x$HAVE_GALLIUM_RADEONSI" = xyes -o \
>"x$HAVE_RADEON_VULKAN" = xyes)
>
>  AM_CONDITIONAL(HAVE_INTEL_DRIVERS, test "x$HAVE_INTEL_VULKAN" = xyes -o \
> diff --git a/src/gallium/drivers/r600/Android.mk 
> b/src/gallium/drivers/r600/Android.mk
> index 87f433dbaeb..18c5bb63442 100644
> --- a/src/gallium/drivers/r600/Android.mk
> +++ b/src/gallium/drivers/r600/Android.mk
> @@ -30,11 +30,7 @@ include $(CLEAR_VARS)
>
>  LOCAL_SRC_FILES := $(C_SOURCES) $(CXX_SOURCES)
>
> -ifeq ($(MESA_ENABLE_LLVM),true)
> -LOCAL_STATIC_LIBRARIES := libmesa_amd_common
> -else
>  LOCAL_C_INCLUDES += $(MESA_TOP)/src/amd/common
> -endif

With OpenCL gone, I think you can remove the include too.

Rob
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 0/9][RFC] GLSL preprocessor/parser improvements

2017-05-28 Thread Thomas Helland
2017-05-22 20:02 GMT+02:00 Thomas Helland :
> 2017-05-22 3:41 GMT+02:00 Timothy Arceri :
>> I suspect you forgot to test with a debug build, there is issues with the
>> string buffer  changes somewhere.
>>
>> ralloc.c:203: reralloc_size: Assertion `ralloc_parent(ptr) == ctx' failed.
>>
>> #0  0x770eb91f in raise () from /lib64/libc.so.6
>> #1  0x770ed51a in abort () from /lib64/libc.so.6
>> #2  0x770e3da7 in __assert_fail_base () from /lib64/libc.so.6
>> #3  0x770e3e52 in __assert_fail () from /lib64/libc.so.6
>> #4  0x7442c73c in reralloc_size (ctx=ctx@entry=0x7fffd40cb910,
>> ptr=, size=) at ralloc.c:203
>> #5  0x744b519e in glcpp_preprocess
>> (ralloc_ctx=ralloc_ctx@entry=0x7fffd40c9da0,
>> shader=shader@entry=0x7fffea7cfcc8, info_log=info_log@entry=0x7fffd40ca058,
>> extensions=extensions@entry=0x743ff070
>> > const*, int), glcpp_parser*, unsigned int, bool)>,
>> state=state@entry=0x7fffd40c9da0,
>> gl_ctx=gl_ctx@entry=0x7fffe85c7010) at glsl/glcpp/pp.c:246
>> #6  0x74402665 in _mesa_glsl_compile_shader
>> (ctx=ctx@entry=0x7fffe85c7010, shader=shader@entry=0x7fffd40c8cc0,
>> dump_ast=dump_ast@entry=false, dump_hir=dump_hir@entry=false,
>> force_recompile=force_recompile@entry=false)
>> at glsl/glsl_parser_extras.cpp:2065
>>
>>
>
> Your suspicion is of course correct. Switching back and forth between
> profiling and coding and I forgot to switch debug back on. I'll look into
> this, plus addressing all of the nice feedback. Thanks for taking a look.
>

I've tracked down the issue and sent some updates to the list.
The issue was related to trying to realloc with the wrong
ralloc context in pp.c when resizing the buffer to reduce footprint.
I've added a "crimp_to_fit" function that does exactly that.
This is used instead of handrolling it in pp.c like was initially done.

I've also worked on porting the tests to gtest. It compiles nicely,
I just have to figure out how to run the gtest tests... It shouldn't
be to far out though, so expect them on the list the coming week or so.

Some performance numbers when running shader-db with
GALLIUM_NOOP set on a nouveau gallium driver:
Runtime drops from 48 to 45 seconds.
8% reduction in executed instruction, 6-7% drop in cycles.
So we are seeing that stalled cycles due to cache misses
are a primary limiting factor that's holding us back.
In other words, nothing new under the sun.

>>
>> On 22/05/17 06:49, Thomas Helland wrote:
>>>
>>> This patch series contains some of the work done by Vladislav
>>> in the beginning of March, that seems to have been forgotten.
>>>
>>> For reference, that series, with review comments, can be found here:
>>> https://lists.freedesktop.org/archives/mesa-dev/2017-January/139892.html
>>>
>>> I've adressed some of the review comments, most notably redoing the
>>> string buffer implementation quite a bit, and adding tests.
>>> The major change is that it is now decoupled from the parser
>>> and instead lives in /src/util/ as a utility for easier reuse.
>>> I've also closely followed the structure of our hash table and set
>>> so that it should be quite familiar for everyone. My implementation
>>> is also null terminated, while Vladislav's implementation was not.
>>> My reasoning behind this was that it's less fragile if someone where
>>> to access the contents of the buffer directly. I've also expanded
>>> with some different functions that allow us to do more stuff.
>>> Obviously this could be expanded upon further if need be.
>>>
>>> I've included some of Vladislav's less involved patches that
>>> I think we should get in as soon as possible. I've added Ian's
>>> r-b on the ones that he reviewed (I hope that's OK). The one
>>> patch that is missing from this series is the hand-written
>>> custom parser. While this was the thing that gave the biggest
>>> speed-up, unfortunately it's also a bit harder to review,
>>> so I've left that as a future exercise.
>>>
>>> I've run it through my complete shader-db and there's no changes
>>> or breakages, so that's encouraging. It amounts to about a 3%
>>> reduction in runtime and executed instructions on the shader-db run.
>>> It should be noted that the i965 backend is the primary bottleneck
>>> when running shader-db on my computer, so the numbers don't look all
>>> that impressive due to this. I'll see if I can come up with some
>>> numbers using the gallium noop driver.
>>>
>>> I have not done a very thorough job on testing that the output
>>> of the preprocessor/parser is the same after this series.
>>> However, there's no changes here that I believe should cause
>>> any issues, so I feel quite confident that this series should
>>> not cause any trouble. The original series did have some issues
>>> discovered by running a fuzzer over it, however I expect that
>>> was caused by the introduced 

[Mesa-dev] [PATCH] glsl: Change the parser to use the string buffer

2017-05-28 Thread Thomas Helland
V2: Failure found by Timothy running it through CI
   - Fix pp.c reralloc size issue and comment
---
 src/compiler/glsl/glcpp/glcpp-parse.y | 85 ++-
 src/compiler/glsl/glcpp/glcpp.h   |  8 ++--
 src/compiler/glsl/glcpp/pp.c  | 39 +++-
 3 files changed, 64 insertions(+), 68 deletions(-)

diff --git a/src/compiler/glsl/glcpp/glcpp-parse.y 
b/src/compiler/glsl/glcpp/glcpp-parse.y
index fe211a0f0b..e84b6fb055 100644
--- a/src/compiler/glsl/glcpp/glcpp-parse.y
+++ b/src/compiler/glsl/glcpp/glcpp-parse.y
@@ -209,7 +209,7 @@ line:
 |  SPACE control_line
 |  text_line {
_glcpp_parser_print_expanded_token_list (parser, $1);
-   ralloc_asprintf_rewrite_tail (>output, 
>output_length, "\n");
+   _mesa_string_buffer_append_char(parser->output, '\n');
}
 |  expanded_line
 ;
@@ -228,20 +228,16 @@ expanded_line:
 |  LINE_EXPANDED integer_constant NEWLINE {
parser->has_new_line_number = 1;
parser->new_line_number = $2;
-   ralloc_asprintf_rewrite_tail (>output,
- >output_length,
- "#line %" PRIiMAX "\n",
- $2);
+   _mesa_string_buffer_printf(parser->output, "#line %" PRIiMAX 
"\n", $2);
}
 |  LINE_EXPANDED integer_constant integer_constant NEWLINE {
parser->has_new_line_number = 1;
parser->new_line_number = $2;
parser->has_new_source_number = 1;
parser->new_source_number = $3;
-   ralloc_asprintf_rewrite_tail (>output,
- >output_length,
- "#line %" PRIiMAX " %" PRIiMAX 
"\n",
- $2, $3);
+   _mesa_string_buffer_printf(parser->output,
+  "#line %" PRIiMAX " %" PRIiMAX "\n",
+   $2, $3);
}
 ;
 
@@ -259,7 +255,7 @@ define:
 
 control_line:
control_line_success {
-   ralloc_asprintf_rewrite_tail (>output, 
>output_length, "\n");
+   _mesa_string_buffer_append_char(parser->output, '\n');
}
 |  control_line_error
 |  HASH_TOKEN LINE pp_tokens NEWLINE {
@@ -432,7 +428,7 @@ control_line_success:
glcpp_parser_resolve_implicit_version(parser);
}
 |  HASH_TOKEN PRAGMA NEWLINE {
-   ralloc_asprintf_rewrite_tail (>output, 
>output_length, "#%s", $2);
+   _mesa_string_buffer_printf(parser->output, "#%s", $2);
}
 ;
 
@@ -1110,60 +1106,60 @@ _token_list_equal_ignoring_space(token_list_t *a, 
token_list_t *b)
 }
 
 static void
-_token_print(char **out, size_t *len, token_t *token)
+_token_print(struct _mesa_string_buffer *out, token_t *token)
 {
if (token->type < 256) {
-  ralloc_asprintf_rewrite_tail (out, len, "%c", token->type);
+  _mesa_string_buffer_printf(out,"%c", token->type);
   return;
}
 
switch (token->type) {
case INTEGER:
-  ralloc_asprintf_rewrite_tail (out, len, "%" PRIiMAX, token->value.ival);
+  _mesa_string_buffer_printf(out, "%" PRIiMAX, token->value.ival);
   break;
case IDENTIFIER:
case INTEGER_STRING:
case OTHER:
-  ralloc_asprintf_rewrite_tail (out, len, "%s", token->value.str);
+  _mesa_string_buffer_append(out, token->value.str);
   break;
case SPACE:
-  ralloc_asprintf_rewrite_tail (out, len, " ");
+  _mesa_string_buffer_append(out, " ");
   break;
case LEFT_SHIFT:
-  ralloc_asprintf_rewrite_tail (out, len, "<<");
+  _mesa_string_buffer_append(out, "<<");
   break;
case RIGHT_SHIFT:
-  ralloc_asprintf_rewrite_tail (out, len, ">>");
+  _mesa_string_buffer_append(out, ">>");
   break;
case LESS_OR_EQUAL:
-  ralloc_asprintf_rewrite_tail (out, len, "<=");
+  _mesa_string_buffer_append(out, "<=");
   break;
case GREATER_OR_EQUAL:
-  ralloc_asprintf_rewrite_tail (out, len, ">=");
+  _mesa_string_buffer_append(out, ">=");
   break;
case EQUAL:
-  ralloc_asprintf_rewrite_tail (out, len, "==");
+  _mesa_string_buffer_append(out, "==");
   break;
case NOT_EQUAL:
-  ralloc_asprintf_rewrite_tail (out, len, "!=");
+  _mesa_string_buffer_append(out, "!=");
   break;
case AND:
-  ralloc_asprintf_rewrite_tail (out, len, "&&");
+  _mesa_string_buffer_append(out, "&&");
   break;
case OR:
-  ralloc_asprintf_rewrite_tail (out, len, "||");
+  _mesa_string_buffer_append(out, "||");
   break;
case PASTE:
-  ralloc_asprintf_rewrite_tail (out, len, "##");
+  _mesa_string_buffer_append(out, "##");
   break;
case PLUS_PLUS:
-  ralloc_asprintf_rewrite_tail (out, len, "++");
+  

[Mesa-dev] [PATCH] util: Add a string buffer implementation

2017-05-28 Thread Thomas Helland
Based on Vladislav Egorovs work on the preprocessor, but split
out to a util functionality that should be universal. Setup, teardown,
memory handling and general layout is modeled around the hash_table
and the set, to make it familiar for everyone.

A notable change is that this implementation is always null terminated.
The rationale is that it will be less error-prone, as one might
access the buffer directly, thereby reading a non-terminated string.
Also, vsnprintf and friends prints the null-terminator.

V2: Address review feedback from Timothy and Grazvydas
   - Fix MINGW preprocessor check
   - Changed len from uint to int
   - Make string argument const in append function
   - Move to header and inline append function
   - Add crimp_to_fit function for resizing buffer
---
 src/util/Makefile.sources |   2 +
 src/util/string_buffer.c  | 173 ++
 src/util/string_buffer.h  |  85 +++
 3 files changed, 260 insertions(+)
 create mode 100644 src/util/string_buffer.c
 create mode 100644 src/util/string_buffer.h

diff --git a/src/util/Makefile.sources b/src/util/Makefile.sources
index e9057343dc..cb46639c87 100644
--- a/src/util/Makefile.sources
+++ b/src/util/Makefile.sources
@@ -37,6 +37,8 @@ MESA_UTIL_FILES := \
simple_list.h \
slab.c \
slab.h \
+   string_buffer.c \
+   string_buffer.h \
string_to_uint_map.cpp \
string_to_uint_map.h \
strndup.h \
diff --git a/src/util/string_buffer.c b/src/util/string_buffer.c
new file mode 100644
index 00..8e0b3eb706
--- /dev/null
+++ b/src/util/string_buffer.c
@@ -0,0 +1,173 @@
+/*
+ * Copyright © 2017 Thomas Helland
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+#include "ralloc.h"
+#include "string_buffer.h"
+
+static bool
+ensure_capacity(struct _mesa_string_buffer *str, uint32_t needed_capacity)
+{
+   if (needed_capacity <= str->capacity)
+  return true;
+
+   /* Too small, we have to resize our buffer.
+* Double until we can fit the new string.
+*/
+   uint32_t new_capacity = str->capacity * 2;
+   while (needed_capacity > new_capacity)
+  new_capacity *= 2;
+
+   str->buf = reralloc_array_size(str, str->buf, sizeof(char), new_capacity);
+   if (str->buf == NULL)
+  return false;
+
+   str->capacity = new_capacity;
+   return true;
+}
+
+struct _mesa_string_buffer *
+_mesa_string_buffer_create(void *mem_ctx, uint32_t initial_capacity)
+{
+   struct _mesa_string_buffer *str;
+   str = ralloc(mem_ctx, struct _mesa_string_buffer);
+
+   if (str == NULL)
+  return NULL;
+
+   /* If no initial capacity is set then set it to something */
+   str->capacity = initial_capacity ? initial_capacity : 8;
+   str->buf = ralloc_array(str, char, str->capacity);
+   str->length = 0;
+   str->buf[str->length] = '\0';
+   return str;
+}
+
+void
+_mesa_string_buffer_destroy(struct _mesa_string_buffer *str)
+{
+   ralloc_free(str);
+}
+
+bool
+_mesa_string_buffer_append_all(struct _mesa_string_buffer *str,
+   uint32_t num_args, ...)
+{
+   int i;
+   char* s;
+   va_list args;
+   va_start(args, num_args);
+   for (i = 0; i < num_args; i++) {
+  s = va_arg(args, char*);
+  if (!_mesa_string_buffer_append_len(str, s, strlen(s)))
+ return false;
+   }
+   va_end(args);
+   return true;
+}
+
+bool
+_mesa_string_buffer_append_len(struct _mesa_string_buffer *str,
+   const char *c, uint32_t len)
+{
+   uint32_t needed_length = str->length + len + 1;
+   if (!ensure_capacity(str, needed_length))
+  return false;
+
+   memcpy(str->buf + str->length, c, len);
+   str->length += len;
+   str->buf[str->length] = '\0';
+   return true;
+}
+
+void
+_mesa_string_buffer_clear(struct _mesa_string_buffer *str)
+{
+   str->length = 0;
+   str->buf[str->length] = '\0';
+}
+
+uint32_t