Re: [Mesa-dev] [PATCH 0/7] dma-buf: Add an API for exporting sync files (v11)

2021-06-10 Thread Chia-I Wu
On Tue, May 25, 2021 at 2:18 PM Jason Ekstrand  wrote:
> Modern userspace APIs like Vulkan are built on an explicit
> synchronization model.  This doesn't always play nicely with the
> implicit synchronization used in the kernel and assumed by X11 and
> Wayland.  The client -> compositor half of the synchronization isn't too
> bad, at least on intel, because we can control whether or not i915
> synchronizes on the buffer and whether or not it's considered written.
We might have an important use case for this half, for virtio-gpu and Chrome OS.

When the guest compositor acts as a proxy to connect guest apps to the
host compositor, implicit fencing requires the guest compositor to do
a wait before forwarding the buffer to the host compositor.  With this
patch, the guest compositor can extract the dma-fence from the buffer,
and if the fence is a virtio-gpu fence, forward both the fence and the
buffer to the host compositor.  It will allow us to convert a
guest-side wait into a host-side wait.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] Merging virtio-gpu vulkan driver

2021-04-05 Thread Chia-I Wu
On Mon, Apr 5, 2021 at 11:12 AM Dave Airlie  wrote:
>
> On Tue, 6 Apr 2021 at 03:22, Chia-I Wu  wrote:
> >
> > Hi list,
> >
> > We are looking to merge virtio-gpu vulkan driver
> >
> >   https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5800
> >
> > On the good side, the driver is conformant with Vulkan 1.2 (vtest) and
> > Vulkan 1.1 (virtio-gpu).  I only tried it on a handful of games (e.g.,
> > Dota 2, Hades on Proton with D3D and Vulkan backends, and some
> > others), but it appeared to work with reasonable framerates.  I was
> > told that it works with other games as well.
> >
> > I tried Basemark GPU a month ago on a Core i7-7820HQ.  The fps numbers were
> >
> >   quality highend: native 17.07, vtest 16.83, virtio-gpu 16.65
> >   quality medium: native 98.19, vtest 91.15, virtio-gpu 92.29
> >   quality simple: native 327.52, vtest 317.17, virtio-gpu 283.02
> >
> > On the bad side, the driver requires
> >
> >   VIRTIO_GPU_F_RESOURCE_BLOB (kernel 5.11 but not supported by qemu)
> >   VIRTIO_GPU_F_CONTEXT_INIT (to be upstreamed[1])
> >
> > As a result, it can only be tested with crosvm[2] or vtest[3].
> >
>
> I've no major objections to merging this in an experimental state, not
> having qemu support is of course an annoyance but at some point I
> suppose that bridge will have to be crossed.
>
> My main worry with no qemu support is locking in crosvm specific
> behaviours that we later can't get back out of.
Agreed.  I also want the driver to be available to the much wider
community that qemu has.  I myself use crosvm with archlinux
host+guest for developments, in addition to on chromebooks.  While it
works, it is not as versatile/mature as qemu is.

We have qemu support as a part of VIRTIO_GPU_F_RESOURCE_BLOB upstream
task, but there was no activity recently.  I can check the status and
get that going again.

>
> > We develop using anv as the host driver mostly.  Simple samples work
> > when the host driver is radv, but games hit a host KVM bug quickly.
> > The issue has been reported and we expect it to be fixed by upstream.
> >
> > The protocol for Vulkan command serialization is not finalized either.
> > The driver is still marked experimental and must be enabled with
> > -Dvulkan-drivers=virtio-experimental.  The plan is to mark the driver
> > stable after the kernel ABI and the protocol ABI are finalized.
>
> Sounds good.
>
> Is the virglrenderer side merged? or is it a case of both sides
> landing close to each other.

I want to land both sides close to each other.

Both sides have been reviewed.  virglrenderer side is ready to land

  https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/412

I plan to merge both sides in a day or two if the feedback on this
thread is positive :)

>
> Dave.
> >
> > [1] 
> > https://gitlab.freedesktop.org/virgl/drm-misc-next/-/commits/context-init/
> > [2] KVM-based VMM written in Rust
> > https://chromium.googlesource.com/chromiumos/platform/crosvm/
> > [3] vtest is a part of virglrenderer and is what I use for most of the
> > developments
> > ___
> > mesa-dev mailing list
> > mesa-dev@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/mesa-dev
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] Merging virtio-gpu vulkan driver

2021-04-05 Thread Chia-I Wu
Hi list,

We are looking to merge virtio-gpu vulkan driver

  https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5800

On the good side, the driver is conformant with Vulkan 1.2 (vtest) and
Vulkan 1.1 (virtio-gpu).  I only tried it on a handful of games (e.g.,
Dota 2, Hades on Proton with D3D and Vulkan backends, and some
others), but it appeared to work with reasonable framerates.  I was
told that it works with other games as well.

I tried Basemark GPU a month ago on a Core i7-7820HQ.  The fps numbers were

  quality highend: native 17.07, vtest 16.83, virtio-gpu 16.65
  quality medium: native 98.19, vtest 91.15, virtio-gpu 92.29
  quality simple: native 327.52, vtest 317.17, virtio-gpu 283.02

On the bad side, the driver requires

  VIRTIO_GPU_F_RESOURCE_BLOB (kernel 5.11 but not supported by qemu)
  VIRTIO_GPU_F_CONTEXT_INIT (to be upstreamed[1])

As a result, it can only be tested with crosvm[2] or vtest[3].

We develop using anv as the host driver mostly.  Simple samples work
when the host driver is radv, but games hit a host KVM bug quickly.
The issue has been reported and we expect it to be fixed by upstream.

The protocol for Vulkan command serialization is not finalized either.
The driver is still marked experimental and must be enabled with
-Dvulkan-drivers=virtio-experimental.  The plan is to mark the driver
stable after the kernel ABI and the protocol ABI are finalized.

[1] https://gitlab.freedesktop.org/virgl/drm-misc-next/-/commits/context-init/
[2] KVM-based VMM written in Rust
https://chromium.googlesource.com/chromiumos/platform/crosvm/
[3] vtest is a part of virglrenderer and is what I use for most of the
developments
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] Perfetto CPU/GPU tracing

2021-02-12 Thread Chia-I Wu
For virgl, where the biggest perf gaps often come from unnecessary CPU
waits or high latencies of fence signaling, being able to insert
userspace driver trace events and combine them with kernel ftrace
events are a big plus.  Admittedly, there is no HW counters and my
needs are simpler (inserting function begin/end and wait begin/end and
combining them with virtio-gpu and dma-fence ftrace events).

On Fri, Feb 12, 2021 at 2:13 PM Alyssa Rosenzweig
 wrote:
>
> My 2c for Mali/Panfrost --
>
> For us, capturing GPU perf counters is orthogonal to rendering. It's
> expected (e.g. with Arm's tools) to do this from a separate process.
> Neither Mesa nor the DDK should require custom instrumentation for the
> low-level data. Fahien's gfx-pps handles this correctly for Panfrost +
> Perfetto as it is. So for us I don't see the value in modifying Mesa for
> tracing.
>
> On Fri, Feb 12, 2021 at 01:34:51PM -0800, John Bates wrote:
> > (responding from correct address this time)
> >
> > On Fri, Feb 12, 2021 at 12:03 PM Mark Janes  wrote:
> >
> > > I've recently been using GPUVis to look at trace events.  On Intel
> > > platforms, GPUVis incorporates ftrace events from the i915 driver,
> > > performance metrics from igt-gpu-tools, and userspace ftrace markers
> > > that I locally hack up in Mesa.
> > >
> >
> > GPUVis is great. I would love to see that data combined with
> > userspace events without any need for local hacks. Perfetto provides
> > on-demand trace events with lower overhead compared to ftrace, so for
> > example it is acceptable to have production trace instrumentation that can
> > be captured without dev builds. To do that with ftrace it may require a way
> > to enable and disable the ftrace file writes to avoid the overhead when
> > tracing is not in use. This is what Android does with systrace/atrace, for
> > example, it uses Binder to notify processes about trace sessions. Perfetto
> > does that in a more portable way.
> >
> >
> > >
> > > It is very easy to compile the GPUVis UI.  Userspace instrumentation
> > > requires a single C/C++ header.  You don't have to access an external
> > > web service to analyze trace data (a big no-no for devs working on
> > > preproduction hardware).
> > >
> > > Is it possible to build and run the Perfetto UI locally?
> >
> >
> > Yes, local UI builds are possible
> > .
> > Also confirmed with the perfetto team  that
> > trace data is not uploaded unless you use the 'share' feature.
> >
> >
> > >   Can it display
> > > arbitrary trace events that are written to
> > > /sys/kernel/tracing/trace_marker ?
> >
> >
> > Yes, I believe it does support that via linux.ftrace data source
> > . We use that for
> > example to overlay CPU sched data to show what process is on each core
> > throughout the timeline. There are many ftrace event types
> > 
> > in
> > the perfetto protos.
> >
> >
> > > Can it be extended to show i915 and
> > > i915-perf-recorder events?
> > >
> >
> > It can be extended to consume custom data sources. One way this is done is
> > via a bridge daemon, such as traced_probes which is responsible for
> > capturing data from ftrace and /proc during a trace session and sending it
> > to traced. traced is the main perfetto tracing daemon that notifies all
> > trace data sources to start/stop tracing and communicates with user tracing
> > requests via the 'perfetto' command.
> >
> >
> >
> > >
> > > John Bates  writes:
> > >
> > > > I recently opened issue 4262
> > > >  to begin the
> > > > discussion on integrating perfetto into mesa.
> > > >
> > > > *Background*
> > > >
> > > > System-wide tracing is an invaluable tool for developers to find and fix
> > > > performance problems. The perfetto project enables a combined view of
> > > trace
> > > > data from kernel ftrace, GPU driver and various manually-instrumented
> > > > tracepoints throughout the application and system. This helps developers
> > > > quickly answer questions like:
> > > >
> > > >- How long are frames taking?
> > > >- What caused a particular frame drop?
> > > >- Is it CPU bound or GPU bound?
> > > >- Did a CPU core frequency drop cause something to go slower than
> > > usual?
> > > >- Is something else running that is stealing CPU or GPU time? Could I
> > > >fix that with better thread/context priorities?
> > > >- Are all CPU cores being used effectively? Do I need
> > > sched_setaffinity
> > > >to keep my thread on a big or little core?
> > > >- What’s the latency between CPU frame submit and GPU start?
> > > >
> > > > *What Does Mesa + Perfetto Provide?*
> > > >
> > > > Mesa is in a unique position to produce GPU trace data 

Re: [Mesa-dev] Static thread safety checking with clang

2020-11-10 Thread Chia-I Wu
On Tue, Nov 10, 2020 at 8:09 AM Kristian Høgsberg  wrote:
>
> Hi,
>
> I wanted to call attention to
>
>   https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7529
>
> which shows how we can use a new clang __attribute__ to statically
> check locking invariants. It's probably not perfect, but more like
> static type checking - there will always be cases where you can't
> statically determine if the code is right or wrong, but it will be
> useful and correct in most cases (like in the MR).  The attributes
> have a few quirks and I suspect that they were mostly designed and
> tested to work for C++ classes, but I found a way to make it work for
> C.
>
> For each type of lock, declare a lock capability:
>
>   extern lock_cap_t fd_screen_lock_cap;
>
> Functions that take and release that lock get annotated with:
>
>   static inline void
>   fd_screen_lock(struct fd_screen *screen)
> acquire_cap(fd_screen_lock_cap);
>
>   static inline void
>   fd_screen_unlock(struct fd_screen *screen)
> release_cap(fd_screen_lock_cap)
>
> where acquire_cap and release_cap are #defines for an __attribute__.
> One of the quirks is that the function doing the locking triggers a
> warning about how it doesn't actually take the lock, so I silenced
> that by adding a no_thread_safety_analysis in there.
>
> Now whenever we have a function that expects to be called with that
> lock held (we often call them foo_locked) we can add the requires_cap
> annotation:
>
>   static struct gmem_key *
>   gmem_key_init(struct fd_batch *batch, bool assume_zs, bool no_scis_opt)
> requires_cap(fd_screen_lock_cap)
>
> and calls to this function will warn or error if called from a point
> where it's not statically determinable that you've taken the lock:
>
> ../../master/src/gallium/drivers/freedreno/freedreno_gmem.c:532:25:
> error: calling function 'gmem_key_init' requires holding lock
> 'fd_screen_lock_cap' exclusively [-Werror,-Wthread-safety-analysis]
> struct gmem_key *key = gmem_key_init(batch, assume_zs, no_scis_opt);
>^
> 1 error generated.

fd_screen_lock_cap seems to be a placeholder here.  Is it one of the
quirks?  It would be nice if the error message reads "... requiring
hold lock '>lock' exclusively".

From https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h,
wrapping of the threading api is expected.  I wonder if we can
annotate simple_mtx_t (and other in-tree locking wrappers), and
perhaps kepp lock_cap_t only for code that uses mtx_t or
pthread_mutex_t directly.


>
> Many functions that assert a lock is taken are better off using the
> requires_cap annotation, which makes the check a compile failure
> instead. For cases where it's not possible to determine statically, we
> can still assert at runtime:
>
>   static inline void
>   fd_screen_assert_locked(struct fd_screen *screen)
> assert_cap(fd_screen_lock_cap)
>
> which tells the checker to assume the lock is taken.  Finally, it's
> possible to annotate struct members:
>
>   struct fd_gmem_cache gmem_cache guarded_by(fd_screen_lock_cap);
>
> such that any access to that field can only happen with the lock taken:
>
> ../../master/src/gallium/drivers/freedreno/freedreno_gmem.c:277:20:
> error: reading variable 'gmem_cache' requires holding lock
> 'fd_screen_lock_cap' [-Werror,-Wthread-safety-analysis]
> rzalloc(screen->gmem_cache.ht, struct 
> fd_gmem_stateobj);
> ^
> Having these annotations also helps human readers of the code by
> spelling out the conventions explicitly instead of relying on _locked
> suffix conventions or documentation that call out which parts of a
> struct are protected by which lock. All in all this seems really
> useful.
100% agreed.

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


Re: [Mesa-dev] [PATCH v3] egl/android: Update color_buffers querying for buffer age

2019-07-19 Thread Chia-I Wu
On Fri, Jul 19, 2019 at 11:03 AM Nataraj Deshpande
 wrote:
>
> color_buffers[] is currently hard coded to 3 for android which fails
> in droid_window_dequeue_buffer when ANativeWindow creates color_buffers
> >3 while querying buffer age during dEQP partial_update tests on chromeOS.
>
> The patch removes static color_buffers[], queries for MIN_UNDEQUEUED_BUFFERS,
> sets native window buffer count and allocates the correct number of
> color_buffers as per android.
>
> Fixes dEQP-EGL.functional.partial_update* tests on chromebooks with
> enabling EGL_KHR_partial_update.
>
> v2: update comment instead of removing (Eric Engestrom)
> v3: change static array to dynamic allocated color_buffers
> querying MIN_UNDEQUEUED_BUFFERS (Chia-I Wu o...@chromium.org)
>
> Fixes: 2acc69da8ce "EGL/Android: Add EGL_EXT_buffer_age extension"
> Signed-off-by: Nataraj Deshpande 
> Acked-by: Eric Engestrom 
Reviewed-by: Chia-I Wu 

> ---
>  src/egl/drivers/dri2/egl_dri2.h |  7 ---
>  src/egl/drivers/dri2/platform_android.c | 30 +++---
>  2 files changed, 31 insertions(+), 6 deletions(-)
>
> diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
> index fa04e3b..3206d00 100644
> --- a/src/egl/drivers/dri2/egl_dri2.h
> +++ b/src/egl/drivers/dri2/egl_dri2.h
> @@ -325,13 +325,14 @@ struct dri2_egl_surface
> __DRIimage *dri_image_front;
>
> /* Used to record all the buffers created by ANativeWindow and their ages.
> -* Usually Android uses at most triple buffers in ANativeWindow
> -* so hardcode the number of color_buffers to 3.
> +* Allocate number of color_buffers based on query to android bufferqueue
> +* and save color_buffers_count.
>  */
> +   int color_buffers_count;
> struct {
>struct ANativeWindowBuffer *buffer;
>int age;
> -   } color_buffers[3], *back;
> +   } *color_buffers, *back;
>  #endif
>
> /* surfaceless and device */
> diff --git a/src/egl/drivers/dri2/platform_android.c 
> b/src/egl/drivers/dri2/platform_android.c
> index d949ed4..d37f6b8 100644
> --- a/src/egl/drivers/dri2/platform_android.c
> +++ b/src/egl/drivers/dri2/platform_android.c
> @@ -237,7 +237,7 @@ droid_window_dequeue_buffer(struct dri2_egl_surface 
> *dri2_surf)
>  * for updating buffer's age in swap_buffers.
>  */
> EGLBoolean updated = EGL_FALSE;
> -   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
> +   for (int i = 0; i < dri2_surf->color_buffers_count; i++) {
>if (!dri2_surf->color_buffers[i].buffer) {
>   dri2_surf->color_buffers[i].buffer = dri2_surf->buffer;
>}
> @@ -252,7 +252,7 @@ droid_window_dequeue_buffer(struct dri2_egl_surface 
> *dri2_surf)
>/* In case of all the buffers were recreated by ANativeWindow, reset
> * the color_buffers
> */
> -  for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
> +  for (int i = 0; i < dri2_surf->color_buffers_count; i++) {
>   dri2_surf->color_buffers[i].buffer = NULL;
>   dri2_surf->color_buffers[i].age = 0;
>}
> @@ -367,6 +367,7 @@ droid_create_surface(_EGLDriver *drv, _EGLDisplay *disp, 
> EGLint type,
>
> if (type == EGL_WINDOW_BIT) {
>int format;
> +  int buffer_count;
>
>if (window->common.magic != ANDROID_NATIVE_WINDOW_MAGIC) {
>   _eglError(EGL_BAD_NATIVE_WINDOW, "droid_create_surface");
> @@ -377,6 +378,26 @@ droid_create_surface(_EGLDriver *drv, _EGLDisplay *disp, 
> EGLint type,
>   goto cleanup_surface;
>}
>
> +  /* Query ANativeWindow for MIN_UNDEQUEUED_BUFFER, set buffer count
> +   * and allocate color_buffers.
> +   */
> +  if (window->query(window, NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS,
> +_count)) {
> + _eglError(EGL_BAD_NATIVE_WINDOW, "droid_create_surface");
> + goto cleanup_surface;
> +  }
> +  if (native_window_set_buffer_count(window, buffer_count+1)) {
> + _eglError(EGL_BAD_NATIVE_WINDOW, "droid_create_surface");
> + goto cleanup_surface;
> +  }
> +  dri2_surf->color_buffers = calloc(buffer_count+1,
> +sizeof(*dri2_surf->color_buffers));
> +  if (!dri2_surf->color_buffers) {
> + _eglError(EGL_BAD_ALLOC, "droid_create_surface");
> + goto cleanup_surface;
> +  }
> +  dri2_surf->color_buffers_count = buffer_count+1;
> +
>if (format != dri2_conf->base.NativeVisualID) {
>   _eglLog(_EGL_WARNING, "Native 

Re: [Mesa-dev] [PATCH] virgl: Set meta data for textures from handle.

2019-07-17 Thread Chia-I Wu
On Wed, Jul 17, 2019 at 3:59 PM Lepton Wu  wrote:
>
> OK, actually struct winsys_handle is an obscure structure for virgl
> driver so we can't access whandle->stride here...
> So maybe just leave this CL as it is?
That is fair.  R-b'ed and pushed.
>
> On Wed, Jul 17, 2019 at 1:12 PM Chia-I Wu  wrote:
> >
> > On Wed, Jul 17, 2019 at 12:45 PM Lepton Wu  wrote:
> > > metadata->stride[0] is calculated from
> > > util_format_get_stride(pt->format, pt->width0);
> > > So basically you are asking to check if
> > > util_format_get_stride(pt->format, pt->width0) == whandle->stride
> > > Should this be something done by framework?
> > The framework does not know that is how virgl decides the stride for a
> > resource.  That is also not the case for most drivers.
> >
> > The framework asks virgl to import a buffer with the specified stride.
> > virgl should either accept it, or reject it if virgl does not want to
> > handle the unexpected stride.  Not that I believe that is going to
> > happen, but still...
> >
> > >
> > > On Wed, Jul 17, 2019 at 12:25 PM Chia-I Wu  wrote:
> > > >
> > > > On Wed, Jul 17, 2019 at 11:44 AM Lepton Wu  wrote:
> > > > >
> > > > > On Wed, Jul 17, 2019 at 11:26 AM Chia-I Wu  wrote:
> > > > > >
> > > > > > On Wed, Jul 17, 2019 at 10:14 AM Erik Faye-Lund
> > > > > >  wrote:
> > > > > > >
> > > > > > > On Wed, 2019-07-17 at 10:02 -0700, Lepton Wu wrote:
> > > > > > > > The set of meta data was removed by commit 8083464. It broke 
> > > > > > > > lots of
> > > > > > > > dEQP tests when running with pbuffer surface type.
> > > > > > > >
> > > > > > > > Fixes: 80834640137 ("virgl: remove dead code")
> > > > > > > > Signed-off-by: Lepton Wu 
> > > > > > > > ---
> > > > > > > >  src/gallium/drivers/virgl/virgl_resource.c | 1 +
> > > > > > > >  1 file changed, 1 insertion(+)
> > > > > > > >
> > > > > > > > diff --git a/src/gallium/drivers/virgl/virgl_resource.c
> > > > > > > > b/src/gallium/drivers/virgl/virgl_resource.c
> > > > > > > > index c22a78a4731..909deb774c7 100644
> > > > > > > > --- a/src/gallium/drivers/virgl/virgl_resource.c
> > > > > > > > +++ b/src/gallium/drivers/virgl/virgl_resource.c
> > > > > > > > @@ -515,6 +515,7 @@ static struct pipe_resource
> > > > > > > > *virgl_resource_from_handle(struct pipe_screen *scre
> > > > > > > > res->u.b = *templ;
> > > > > > > > res->u.b.screen = >base;
> > > > > > > > pipe_reference_init(>u.b.reference, 1);
> > > > > > > > +   virgl_resource_layout(>u.b, >metadata);
> > > > > > There was a similar MR for this
> > > > > >
> > > > > >   https://gitlab.freedesktop.org/mesa/mesa/merge_requests/965
> > > > > >
> > > > > > Can you add a check to make sure the stride is compatible?
> > > > > I think this kind of check should be in "framework" side instead of
> > > > > inside virgl driver.
> > > > > The check what you are said is basically to check if  stride info n
> > > > > whandle is comptabile
> > > > > with value in pipe_resource, I think if we need this check, we should
> > > > > put it in dri2_allocate_textures
> > > > > and dri2_create_image_from_winsys? and that should be another CL?
> > > > The framework does not know the stride of a pipe resource.
> > > >
> > > > > >
> > > > > >   if (res->metadata->stride[0] != whandle->stride) reject the 
> > > > > > whandle;
> > > > > >
> > > > > > > >
> > > > > > > > res->hw_res = vs->vws->resource_create_from_handle(vs->vws,
> > > > > > > > whandle);
> > > > > > > > if (!res->hw_res) {
> > > > > > >
> > > > > > > Whoops! Good catch, sorry for the mess!
> > > > > > >
> > > > > > > Reviewed-by: Erik Faye-Lund 
> > > > > > >
> > > > > > > ___
> > > > > > > mesa-dev mailing list
> > > > > > > mesa-dev@lists.freedesktop.org
> > > > > > > https://lists.freedesktop.org/mailman/listinfo/mesa-dev
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Re: [Mesa-dev] [PATCH] virgl: Set meta data for textures from handle.

2019-07-17 Thread Chia-I Wu
On Wed, Jul 17, 2019 at 12:45 PM Lepton Wu  wrote:
> metadata->stride[0] is calculated from
> util_format_get_stride(pt->format, pt->width0);
> So basically you are asking to check if
> util_format_get_stride(pt->format, pt->width0) == whandle->stride
> Should this be something done by framework?
The framework does not know that is how virgl decides the stride for a
resource.  That is also not the case for most drivers.

The framework asks virgl to import a buffer with the specified stride.
virgl should either accept it, or reject it if virgl does not want to
handle the unexpected stride.  Not that I believe that is going to
happen, but still...

>
> On Wed, Jul 17, 2019 at 12:25 PM Chia-I Wu  wrote:
> >
> > On Wed, Jul 17, 2019 at 11:44 AM Lepton Wu  wrote:
> > >
> > > On Wed, Jul 17, 2019 at 11:26 AM Chia-I Wu  wrote:
> > > >
> > > > On Wed, Jul 17, 2019 at 10:14 AM Erik Faye-Lund
> > > >  wrote:
> > > > >
> > > > > On Wed, 2019-07-17 at 10:02 -0700, Lepton Wu wrote:
> > > > > > The set of meta data was removed by commit 8083464. It broke lots of
> > > > > > dEQP tests when running with pbuffer surface type.
> > > > > >
> > > > > > Fixes: 80834640137 ("virgl: remove dead code")
> > > > > > Signed-off-by: Lepton Wu 
> > > > > > ---
> > > > > >  src/gallium/drivers/virgl/virgl_resource.c | 1 +
> > > > > >  1 file changed, 1 insertion(+)
> > > > > >
> > > > > > diff --git a/src/gallium/drivers/virgl/virgl_resource.c
> > > > > > b/src/gallium/drivers/virgl/virgl_resource.c
> > > > > > index c22a78a4731..909deb774c7 100644
> > > > > > --- a/src/gallium/drivers/virgl/virgl_resource.c
> > > > > > +++ b/src/gallium/drivers/virgl/virgl_resource.c
> > > > > > @@ -515,6 +515,7 @@ static struct pipe_resource
> > > > > > *virgl_resource_from_handle(struct pipe_screen *scre
> > > > > > res->u.b = *templ;
> > > > > > res->u.b.screen = >base;
> > > > > > pipe_reference_init(>u.b.reference, 1);
> > > > > > +   virgl_resource_layout(>u.b, >metadata);
> > > > There was a similar MR for this
> > > >
> > > >   https://gitlab.freedesktop.org/mesa/mesa/merge_requests/965
> > > >
> > > > Can you add a check to make sure the stride is compatible?
> > > I think this kind of check should be in "framework" side instead of
> > > inside virgl driver.
> > > The check what you are said is basically to check if  stride info n
> > > whandle is comptabile
> > > with value in pipe_resource, I think if we need this check, we should
> > > put it in dri2_allocate_textures
> > > and dri2_create_image_from_winsys? and that should be another CL?
> > The framework does not know the stride of a pipe resource.
> >
> > > >
> > > >   if (res->metadata->stride[0] != whandle->stride) reject the whandle;
> > > >
> > > > > >
> > > > > > res->hw_res = vs->vws->resource_create_from_handle(vs->vws,
> > > > > > whandle);
> > > > > > if (!res->hw_res) {
> > > > >
> > > > > Whoops! Good catch, sorry for the mess!
> > > > >
> > > > > Reviewed-by: Erik Faye-Lund 
> > > > >
> > > > > ___
> > > > > mesa-dev mailing list
> > > > > mesa-dev@lists.freedesktop.org
> > > > > https://lists.freedesktop.org/mailman/listinfo/mesa-dev
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Re: [Mesa-dev] [PATCH] virgl: Set meta data for textures from handle.

2019-07-17 Thread Chia-I Wu
On Wed, Jul 17, 2019 at 11:44 AM Lepton Wu  wrote:
>
> On Wed, Jul 17, 2019 at 11:26 AM Chia-I Wu  wrote:
> >
> > On Wed, Jul 17, 2019 at 10:14 AM Erik Faye-Lund
> >  wrote:
> > >
> > > On Wed, 2019-07-17 at 10:02 -0700, Lepton Wu wrote:
> > > > The set of meta data was removed by commit 8083464. It broke lots of
> > > > dEQP tests when running with pbuffer surface type.
> > > >
> > > > Fixes: 80834640137 ("virgl: remove dead code")
> > > > Signed-off-by: Lepton Wu 
> > > > ---
> > > >  src/gallium/drivers/virgl/virgl_resource.c | 1 +
> > > >  1 file changed, 1 insertion(+)
> > > >
> > > > diff --git a/src/gallium/drivers/virgl/virgl_resource.c
> > > > b/src/gallium/drivers/virgl/virgl_resource.c
> > > > index c22a78a4731..909deb774c7 100644
> > > > --- a/src/gallium/drivers/virgl/virgl_resource.c
> > > > +++ b/src/gallium/drivers/virgl/virgl_resource.c
> > > > @@ -515,6 +515,7 @@ static struct pipe_resource
> > > > *virgl_resource_from_handle(struct pipe_screen *scre
> > > > res->u.b = *templ;
> > > > res->u.b.screen = >base;
> > > > pipe_reference_init(>u.b.reference, 1);
> > > > +   virgl_resource_layout(>u.b, >metadata);
> > There was a similar MR for this
> >
> >   https://gitlab.freedesktop.org/mesa/mesa/merge_requests/965
> >
> > Can you add a check to make sure the stride is compatible?
> I think this kind of check should be in "framework" side instead of
> inside virgl driver.
> The check what you are said is basically to check if  stride info n
> whandle is comptabile
> with value in pipe_resource, I think if we need this check, we should
> put it in dri2_allocate_textures
> and dri2_create_image_from_winsys? and that should be another CL?
The framework does not know the stride of a pipe resource.

> >
> >   if (res->metadata->stride[0] != whandle->stride) reject the whandle;
> >
> > > >
> > > > res->hw_res = vs->vws->resource_create_from_handle(vs->vws,
> > > > whandle);
> > > > if (!res->hw_res) {
> > >
> > > Whoops! Good catch, sorry for the mess!
> > >
> > > Reviewed-by: Erik Faye-Lund 
> > >
> > > ___
> > > mesa-dev mailing list
> > > mesa-dev@lists.freedesktop.org
> > > https://lists.freedesktop.org/mailman/listinfo/mesa-dev
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Re: [Mesa-dev] [PATCH] virgl: Set meta data for textures from handle.

2019-07-17 Thread Chia-I Wu
On Wed, Jul 17, 2019 at 10:14 AM Erik Faye-Lund
 wrote:
>
> On Wed, 2019-07-17 at 10:02 -0700, Lepton Wu wrote:
> > The set of meta data was removed by commit 8083464. It broke lots of
> > dEQP tests when running with pbuffer surface type.
> >
> > Fixes: 80834640137 ("virgl: remove dead code")
> > Signed-off-by: Lepton Wu 
> > ---
> >  src/gallium/drivers/virgl/virgl_resource.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/src/gallium/drivers/virgl/virgl_resource.c
> > b/src/gallium/drivers/virgl/virgl_resource.c
> > index c22a78a4731..909deb774c7 100644
> > --- a/src/gallium/drivers/virgl/virgl_resource.c
> > +++ b/src/gallium/drivers/virgl/virgl_resource.c
> > @@ -515,6 +515,7 @@ static struct pipe_resource
> > *virgl_resource_from_handle(struct pipe_screen *scre
> > res->u.b = *templ;
> > res->u.b.screen = >base;
> > pipe_reference_init(>u.b.reference, 1);
> > +   virgl_resource_layout(>u.b, >metadata);
There was a similar MR for this

  https://gitlab.freedesktop.org/mesa/mesa/merge_requests/965

Can you add a check to make sure the stride is compatible?

  if (res->metadata->stride[0] != whandle->stride) reject the whandle;

> >
> > res->hw_res = vs->vws->resource_create_from_handle(vs->vws,
> > whandle);
> > if (!res->hw_res) {
>
> Whoops! Good catch, sorry for the mess!
>
> Reviewed-by: Erik Faye-Lund 
>
> ___
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Re: [Mesa-dev] [PATCH] turnip: drop dead close(master_fd)

2019-04-19 Thread Chia-I Wu
On Fri, Apr 19, 2019 at 8:01 AM Emil Velikov  wrote:
>
> From: Emil Velikov 
>
> The fd is -1, thus the block of if (fd != -1) close(fd) is dead code.
>
> Cc: Chad Versace 
> Cc: Chia-I Wu 
> Signed-off-by: Emil Velikov 
Reviewed-by: Chia-I Wu 
> ---
>  src/freedreno/vulkan/tu_device.c | 2 --
>  1 file changed, 2 deletions(-)
>
> diff --git a/src/freedreno/vulkan/tu_device.c 
> b/src/freedreno/vulkan/tu_device.c
> index c7f4d0b26eb..1268624bd8d 100644
> --- a/src/freedreno/vulkan/tu_device.c
> +++ b/src/freedreno/vulkan/tu_device.c
> @@ -198,8 +198,6 @@ tu_physical_device_init(struct tu_physical_device *device,
>
> if (strcmp(version->name, "msm")) {
>drmFreeVersion(version);
> -  if (master_fd != -1)
> - close(master_fd);
>close(fd);
>return vk_errorf(instance, VK_ERROR_INCOMPATIBLE_DRIVER,
> "device %s does not use the msm kernel driver", path);
> --
> 2.21.0
>
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Re: [Mesa-dev] [PATCH v2] virgl: Use right key to insert resource to hash.

2019-04-08 Thread Chia-I Wu
On Mon, Apr 8, 2019 at 11:24 AM Lepton Wu  wrote:

> On Mon, Apr 8, 2019 at 11:10 AM Chia-I Wu  wrote:
> >
> >
> >
> > On Mon, Apr 8, 2019 at 9:34 AM Lepton Wu  wrote:
> >>
> >> The old code could use gem name as key when inserting it to bo_handles
> >> hash table while trying to remove it from hash table with bo_handle as
> >> key in virgl_hw_res_destroy and then it fail to remove it from
> bo_handles
> >> hash table. This triggers use after free. Also, we should insert
> resource
> >> to bo_names hash table when handle type is SHARED.
> >>
> >> Signed-off-by: Lepton Wu 
> >> ---
> >>  .../winsys/virgl/drm/virgl_drm_winsys.c   | 24 +--
> >>  1 file changed, 17 insertions(+), 7 deletions(-)
> >>
> >> diff --git a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
> b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
> >> index 2cf8b4ba076..af92b6a98fc 100644
> >> --- a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
> >> +++ b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
> >> @@ -406,6 +406,12 @@ virgl_drm_winsys_resource_create_handle(struct
> virgl_winsys *qws,
> >>return NULL;
> >> }
> >>
> >> +   if (whandle->type != WINSYS_HANDLE_TYPE_FD &&
> >> +   whandle->type != WINSYS_HANDLE_TYPE_SHARED) {
> >> +  fprintf(stderr, "Unexpected handle type: %d\n", whandle->type);
> >> +  return NULL;
> >> +   }
> >> +
> >> mtx_lock(>bo_handles_mutex);
> >>
> >> if (whandle->type == WINSYS_HANDLE_TYPE_SHARED) {
> >> @@ -424,13 +430,13 @@ virgl_drm_winsys_resource_create_handle(struct
> virgl_winsys *qws,
> >>   res = NULL;
> >>   goto done;
> >>}
> >> -   }
> >>
> >> -   res = util_hash_table_get(qdws->bo_handles,
> (void*)(uintptr_t)handle);
> >> -   if (res) {
> >> -  struct virgl_hw_res *r = NULL;
> >> -  virgl_drm_resource_reference(qdws, , res);
> >> -  goto done;
> >> +  res = util_hash_table_get(qdws->bo_handles,
> (void*)(uintptr_t)handle);
> >> +  if (res) {
> >> + struct virgl_hw_res *r = NULL;
> >> + virgl_drm_resource_reference(qdws, , res);
> >> + goto done;
> >> +  }
> >> }
> >>
> > You can still run into troubles when asked to import a buffer by both
> its prime fd and its flink name.
> But it seems there is no way to fix it at user space, right? Every
> time we got a flink name for
> the first time, kernel will give a new handle and no way to  reuse any
> res from hash table.
>
Yeah, I think you are right... but that appears to be a kernel bug.  Once
kernel is fixed to return the same handle for the same flink name / prime
fd, we should be ready for that.  Let's see what Dave thinks.

>
> >> res = CALLOC_STRUCT(virgl_hw_res);
> >> @@ -448,6 +454,8 @@ virgl_drm_winsys_resource_create_handle(struct
> virgl_winsys *qws,
> >>   goto done;
> >>}
> >>res->bo_handle = open_arg.handle;
> >> +  res->flinked = true;
> >> +  res->flink = whandle->handle;
> >> }
> >> res->name = handle;
> >
> > res->name has no user.  Remove it.
> >
> > It is also less confusing to make sure `handle' means GEM handle at this
> point, by calling either GEM_OPEN or drmPrimeFDToHandle depending on the
> handle type.
> >
> >>
> >> @@ -469,7 +477,9 @@ virgl_drm_winsys_resource_create_handle(struct
> virgl_winsys *qws,
> >> res->num_cs_references = 0;
> >> res->fence_fd = -1;
> >>
> >> -   util_hash_table_set(qdws->bo_handles, (void *)(uintptr_t)handle,
> res);
> >> +   util_hash_table_set(qdws->bo_handles, (void
> *)(uintptr_t)res->bo_handle, res);
> >> +   if (whandle->type == WINSYS_HANDLE_TYPE_SHARED)
> >> +  util_hash_table_set(qdws->bo_names, (void
> *)(uintptr_t)res->flink, res);
> >>
> >>  done:
> >> mtx_unlock(>bo_handles_mutex);
> >> --
> >> 2.21.0.392.gf8f6787159e-goog
> >>
>
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Re: [Mesa-dev] [PATCH] virgl: Use right key to insert resource to hash.

2019-04-08 Thread Chia-I Wu
On Wed, Apr 3, 2019 at 8:17 PM Dave Airlie  wrote:

> On Thu, 4 Apr 2019 at 06:54, Chia-I Wu  wrote:
> >
> > You could end up having two virgl_hw_res with two different GEM handles
> pointing to the same kernel GEM object.  That might break some assumptions
> about dependency tracking.
> >
> > For example, when the cmdbuf being built uses a buffer and you want to
> transfer some more data into the buffer, you normally need to submit the
> cmdbuf first before starting the transfer.  The current code detects that
> with virgl_drm_res_is_ref, which assumes each kernel GEM object has a
> unique virgl_hw_res.
> >
> > On Mon, Apr 1, 2019 at 12:37 PM Lepton Wu  wrote:
> >>
> >>
> >>
> >>
> >> On Wed, Mar 20, 2019 at 3:03 PM Chia-I Wu  wrote:
> >>>
> >>> On Mon, Mar 18, 2019 at 2:22 PM Lepton Wu  wrote:
> >>>>
> >>>> The old code could use gem name as key when inserting it to bo_handles
> >>>> hash table while trying to remove it from hash table with bo_handle as
> >>>> key in virgl_hw_res_destroy. This triggers use after free. Also, we
> >>>> should only reuse resource from bo_handle hash when the handle type is
> >>>> FD.
> >>>
> >>> Reuse is not very accurate.  Opening a shared handle (flink name)
> twice gives two GEM handles.  Importing an fd handle (prime fd) twice gives
> the same GEM handle.  In all cases, within a virgl_winsys, we want only one
> GEM handle and only one virgl_resource for each kernel GEM object.
> >>>
> >>> I think the logic should go like:
> >>>
> >>>   if (HANDLE_TYPE_SHARED) {
> >>> if (bo_names.has(flink_name))
> >>>   return bo_names[flink_name];
> >>> gem_handle = gem_open(flink_name);
> >>>   } else {
> >>> gem_handle = drmPrimeFDToHandle(prime_fd);
> >>>   }
> >>>
> >>>
> >>>   if (bo_handles.has(gem_handle))
> >>> return bo_handles[gem_handle];
> >>>   bo_handles[gem_handle] = create_new_resource();
> >>>
> >> Hi, the current patch did most of what you said with only one
> difference:  it didn't insert to bo_handles[]   hash when the type is
> HANDLE_TYPE_SHARED.
> >> I think this is reasonable since opening a shared handle always get a
> new gem handle very time and I think it doesn't worth to insert it to
> bo_handles[] hash.
> >> What do you think?
>
> Just to reinforce this, we can only have one GEM handle for a kernel
> object, validation will go wrong and deadlock if we submit two handles
> pointing at the same bo.
>
> Opening a shared handle should not get a new gem handle, if should
> return any gem handle that already exists.
>
I just tried and that is not the case.  Sounds like a kernel bug?


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

Re: [Mesa-dev] [PATCH v2] virgl: Use right key to insert resource to hash.

2019-04-08 Thread Chia-I Wu
On Mon, Apr 8, 2019 at 9:34 AM Lepton Wu  wrote:

> The old code could use gem name as key when inserting it to bo_handles
> hash table while trying to remove it from hash table with bo_handle as
> key in virgl_hw_res_destroy and then it fail to remove it from bo_handles
> hash table. This triggers use after free. Also, we should insert resource
> to bo_names hash table when handle type is SHARED.
>
> Signed-off-by: Lepton Wu 
> ---
>  .../winsys/virgl/drm/virgl_drm_winsys.c   | 24 +--
>  1 file changed, 17 insertions(+), 7 deletions(-)
>
> diff --git a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
> b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
> index 2cf8b4ba076..af92b6a98fc 100644
> --- a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
> +++ b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
> @@ -406,6 +406,12 @@ virgl_drm_winsys_resource_create_handle(struct
> virgl_winsys *qws,
>return NULL;
> }
>
> +   if (whandle->type != WINSYS_HANDLE_TYPE_FD &&
> +   whandle->type != WINSYS_HANDLE_TYPE_SHARED) {
> +  fprintf(stderr, "Unexpected handle type: %d\n", whandle->type);
> +  return NULL;
> +   }
> +
> mtx_lock(>bo_handles_mutex);
>
> if (whandle->type == WINSYS_HANDLE_TYPE_SHARED) {
> @@ -424,13 +430,13 @@ virgl_drm_winsys_resource_create_handle(struct
> virgl_winsys *qws,
>   res = NULL;
>   goto done;
>}
> -   }
>
> -   res = util_hash_table_get(qdws->bo_handles, (void*)(uintptr_t)handle);
> -   if (res) {
> -  struct virgl_hw_res *r = NULL;
> -  virgl_drm_resource_reference(qdws, , res);
> -  goto done;
> +  res = util_hash_table_get(qdws->bo_handles,
> (void*)(uintptr_t)handle);
> +  if (res) {
> + struct virgl_hw_res *r = NULL;
> + virgl_drm_resource_reference(qdws, , res);
> + goto done;
> +  }
> }
>
> You can still run into troubles when asked to import a buffer by both its
prime fd and its flink name.

res = CALLOC_STRUCT(virgl_hw_res);
> @@ -448,6 +454,8 @@ virgl_drm_winsys_resource_create_handle(struct
> virgl_winsys *qws,
>   goto done;
>}
>res->bo_handle = open_arg.handle;
> +  res->flinked = true;
> +  res->flink = whandle->handle;
> }
> res->name = handle;
>
res->name has no user.  Remove it.

It is also less confusing to make sure `handle' means GEM handle at this
point, by calling either GEM_OPEN or drmPrimeFDToHandle depending on the
handle type.


> @@ -469,7 +477,9 @@ virgl_drm_winsys_resource_create_handle(struct
> virgl_winsys *qws,
> res->num_cs_references = 0;
> res->fence_fd = -1;
>
> -   util_hash_table_set(qdws->bo_handles, (void *)(uintptr_t)handle, res);
> +   util_hash_table_set(qdws->bo_handles, (void
> *)(uintptr_t)res->bo_handle, res);
> +   if (whandle->type == WINSYS_HANDLE_TYPE_SHARED)
> +  util_hash_table_set(qdws->bo_names, (void *)(uintptr_t)res->flink,
> res);
>
>  done:
> mtx_unlock(>bo_handles_mutex);
> --
> 2.21.0.392.gf8f6787159e-goog
>
>
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Re: [Mesa-dev] [PATCH] virgl: Use right key to insert resource to hash.

2019-04-03 Thread Chia-I Wu
You could end up having two virgl_hw_res with two different GEM handles
pointing to the same kernel GEM object.  That might break some assumptions
about dependency tracking.

For example, when the cmdbuf being built uses a buffer and you want to
transfer some more data into the buffer, you normally need to submit the
cmdbuf first before starting the transfer.  The current code detects that
with virgl_drm_res_is_ref, which assumes each kernel GEM object has a
unique virgl_hw_res.

On Mon, Apr 1, 2019 at 12:37 PM Lepton Wu  wrote:

>
>
>
> On Wed, Mar 20, 2019 at 3:03 PM Chia-I Wu  wrote:
>
>> On Mon, Mar 18, 2019 at 2:22 PM Lepton Wu  wrote:
>>
>>> The old code could use gem name as key when inserting it to bo_handles
>>> hash table while trying to remove it from hash table with bo_handle as
>>> key in virgl_hw_res_destroy. This triggers use after free. Also, we
>>> should only reuse resource from bo_handle hash when the handle type is
>>> FD.
>>>
>> Reuse is not very accurate.  Opening a shared handle (flink name) twice
>> gives two GEM handles.  Importing an fd handle (prime fd) twice gives the
>> same GEM handle.  In all cases, within a virgl_winsys, we want only one GEM
>> handle and only one virgl_resource for each kernel GEM object.
>>
>> I think the logic should go like:
>>
>>   if (HANDLE_TYPE_SHARED) {
>> if (bo_names.has(flink_name))
>>   return bo_names[flink_name];
>> gem_handle = gem_open(flink_name);
>>   } else {
>> gem_handle = drmPrimeFDToHandle(prime_fd);
>>   }
>>
>>
>   if (bo_handles.has(gem_handle))
>> return bo_handles[gem_handle];
>>   bo_handles[gem_handle] = create_new_resource();
>>
>> Hi, the current patch did most of what you said with only one
> difference:  it didn't insert to bo_handles[]   hash when the type
> is  HANDLE_TYPE_SHARED.
> I think this is reasonable since opening a shared handle always get a new
> gem handle very time and I think it doesn't worth to insert it to
> bo_handles[] hash.
> What do you think?
>
>>
>>> Signed-off-by: Lepton Wu 
>>> ---
>>>  src/gallium/winsys/virgl/drm/virgl_drm_winsys.c | 15 ---
>>>  1 file changed, 8 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
>>> b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
>>> index 120e8eda2cd..01811a0e997 100644
>>> --- a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
>>> +++ b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
>>> @@ -424,13 +424,13 @@ virgl_drm_winsys_resource_create_handle(struct
>>> virgl_winsys *qws,
>>>   res = NULL;
>>>   goto done;
>>>}
>>> -   }
>>>
>>> -   res = util_hash_table_get(qdws->bo_handles,
>>> (void*)(uintptr_t)handle);
>>> -   if (res) {
>>> -  struct virgl_hw_res *r = NULL;
>>> -  virgl_drm_resource_reference(qdws, , res);
>>> -  goto done;
>>> +  res = util_hash_table_get(qdws->bo_handles,
>>> (void*)(uintptr_t)handle);
>>> +  if (res) {
>>> +struct virgl_hw_res *r = NULL;
>>> +virgl_drm_resource_reference(qdws, , res);
>>> +goto done;
>>> +  }
>>> }
>>>
>>> res = CALLOC_STRUCT(virgl_hw_res);
>>> @@ -469,7 +469,8 @@ virgl_drm_winsys_resource_create_handle(struct
>>> virgl_winsys *qws,
>>> res->num_cs_references = 0;
>>> res->fence_fd = -1;
>>>
>>> -   util_hash_table_set(qdws->bo_handles, (void *)(uintptr_t)handle,
>>> res);
>>> +   util_hash_table_set(qdws->bo_handles, (void
>>> *)(uintptr_t)res->bo_handle,
>>> +   res);
>>>
>>>  done:
>>> mtx_unlock(>bo_handles_mutex);
>>> --
>>> 2.21.0.225.g810b269d1ac-goog
>>>
>>> ___
>>> mesa-dev mailing list
>>> mesa-dev@lists.freedesktop.org
>>> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>>
>>
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Re: [Mesa-dev] [PATCH] virgl: Use right key to insert resource to hash.

2019-03-20 Thread Chia-I Wu
On Mon, Mar 18, 2019 at 2:22 PM Lepton Wu  wrote:

> The old code could use gem name as key when inserting it to bo_handles
> hash table while trying to remove it from hash table with bo_handle as
> key in virgl_hw_res_destroy. This triggers use after free. Also, we
> should only reuse resource from bo_handle hash when the handle type is
> FD.
>
Reuse is not very accurate.  Opening a shared handle (flink name) twice
gives two GEM handles.  Importing an fd handle (prime fd) twice gives the
same GEM handle.  In all cases, within a virgl_winsys, we want only one GEM
handle and only one virgl_resource for each kernel GEM object.

I think the logic should go like:

  if (HANDLE_TYPE_SHARED) {
if (bo_names.has(flink_name))
  return bo_names[flink_name];
gem_handle = gem_open(flink_name);
  } else {
gem_handle = drmPrimeFDToHandle(prime_fd);
  }

  if (bo_handles.has(gem_handle))
return bo_handles[gem_handle];
  bo_handles[gem_handle] = create_new_resource();


> Signed-off-by: Lepton Wu 
> ---
>  src/gallium/winsys/virgl/drm/virgl_drm_winsys.c | 15 ---
>  1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
> b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
> index 120e8eda2cd..01811a0e997 100644
> --- a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
> +++ b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
> @@ -424,13 +424,13 @@ virgl_drm_winsys_resource_create_handle(struct
> virgl_winsys *qws,
>   res = NULL;
>   goto done;
>}
> -   }
>
> -   res = util_hash_table_get(qdws->bo_handles, (void*)(uintptr_t)handle);
> -   if (res) {
> -  struct virgl_hw_res *r = NULL;
> -  virgl_drm_resource_reference(qdws, , res);
> -  goto done;
> +  res = util_hash_table_get(qdws->bo_handles,
> (void*)(uintptr_t)handle);
> +  if (res) {
> +struct virgl_hw_res *r = NULL;
> +virgl_drm_resource_reference(qdws, , res);
> +goto done;
> +  }
> }
>
> res = CALLOC_STRUCT(virgl_hw_res);
> @@ -469,7 +469,8 @@ virgl_drm_winsys_resource_create_handle(struct
> virgl_winsys *qws,
> res->num_cs_references = 0;
> res->fence_fd = -1;
>
> -   util_hash_table_set(qdws->bo_handles, (void *)(uintptr_t)handle, res);
> +   util_hash_table_set(qdws->bo_handles, (void
> *)(uintptr_t)res->bo_handle,
> +   res);
>
>  done:
> mtx_unlock(>bo_handles_mutex);
> --
> 2.21.0.225.g810b269d1ac-goog
>
> ___
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Re: [Mesa-dev] [PATCH] virgl: close drm fd when destroying virgl screen.

2019-03-20 Thread Chia-I Wu
Reviewed-by: Chia-I Wu 

On Mon, Mar 18, 2019 at 4:40 PM Lepton Wu  wrote:

> This fd was create in virgl_drm_screen_create and should be closed
> in virgl_drm_screen_destroy.
>
> Signed-off-by: Lepton Wu 
> ---
>  src/gallium/winsys/virgl/drm/virgl_drm_winsys.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
> b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
> index 01811a0e997..5501fe3ed48 100644
> --- a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
> +++ b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
> @@ -973,6 +973,7 @@ virgl_drm_screen_destroy(struct pipe_screen *pscreen)
> if (destroy) {
>int fd = virgl_drm_winsys(screen->vws)->fd;
>util_hash_table_remove(fd_tab, intptr_to_pointer(fd));
> +  close(fd);
> }
> mtx_unlock(_screen_mutex);
>
> --
> 2.21.0.225.g810b269d1ac-goog
>
> ___
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

[Mesa-dev] [PATCH] freedreno/drm: sync uapi again

2019-01-07 Thread Chia-I Wu
"pad" was missing in Mesa's msm_drm.h.  sizeof(drm_msm_gem_info)
remains the same, but now the compiler initializes the field to
zero.

Buffer allocation results in EINVAL without this for me.

Cc: Rob Clark 
Cc: Kristian Høgsberg 
Signed-off-by: Chia-I Wu 
---
 src/freedreno/drm/msm_drm.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/freedreno/drm/msm_drm.h b/src/freedreno/drm/msm_drm.h
index 09f16fd7be..91a16b333c 100644
--- a/src/freedreno/drm/msm_drm.h
+++ b/src/freedreno/drm/msm_drm.h
@@ -122,6 +122,7 @@ struct drm_msm_gem_info {
__u32 info;   /* in - one of MSM_INFO_* */
__u64 value;  /* in or out */
__u32 len;/* in or out */
+   __u32 pad;
 };
 
 #define MSM_PREP_READ0x01
-- 
2.20.1.97.g81188d93c3-goog

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


[Mesa-dev] [PATCH] meson: fix EGL/X11 build without GLX

2019-01-07 Thread Chia-I Wu
dep_xcb and others were not set under this configuration.

Signed-off-by: Chia-I Wu 
---
 meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index 709f77a9c7..601085e055 100644
--- a/meson.build
+++ b/meson.build
@@ -1361,7 +1361,7 @@ if with_platform_x11
 dep_xfixes = dependency('xfixes')
 dep_xcb_glx = dependency('xcb-glx', version : '>= 1.8.1')
   endif
-  if (with_any_vk or with_glx == 'dri' or
+  if (with_any_vk or with_glx == 'dri' or with_egl or
(with_gallium_vdpau or with_gallium_xvmc or with_gallium_va or
 with_gallium_omx != 'disabled'))
 dep_xcb = dependency('xcb')
-- 
2.20.1.97.g81188d93c3-goog

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


Re: [Mesa-dev] [PATCH 1/3] ilo: EOL unplumb unmaintained gallium drv from winsys

2017-02-02 Thread Chia-I Wu
All three are

Acked-by:Chia-I Wu 

On Thu, Feb 2, 2017 at 12:15 AM, Edward O'Callaghan
 wrote:
> This is no longer actively maintained and is just
> accumulating bitrot.
>
> Signed-off-by: Edward O'Callaghan 
> ---
>  .../auxiliary/pipe-loader/pipe_loader_drm.c|  5 ---
>  src/gallium/auxiliary/target-helpers/drm_helper.h  | 29 -
>  src/gallium/targets/dri/target.c   |  3 --
>  src/gallium/targets/pipe-loader/pipe_i965.c| 47 
> --
>  src/gallium/winsys/intel/drm/intel_drm_winsys.c|  1 -
>  5 files changed, 85 deletions(-)
>  delete mode 100644 src/gallium/targets/pipe-loader/pipe_i965.c
>
> diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c 
> b/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
> index 6c89fe5..09549e5 100644
> --- a/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
> +++ b/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
> @@ -105,11 +105,6 @@ static const struct drm_driver_descriptor 
> driver_descriptors[] = {
>  },
>  #endif
>  {
> -.driver_name = "i965",
> -.create_screen = pipe_ilo_create_screen,
> -.configuration = configuration_query,
> -},
> -{
>  .driver_name = "nouveau",
>  .create_screen = pipe_nouveau_create_screen,
>  .configuration = configuration_query,
> diff --git a/src/gallium/auxiliary/target-helpers/drm_helper.h 
> b/src/gallium/auxiliary/target-helpers/drm_helper.h
> index f847b17..3159df6 100644
> --- a/src/gallium/auxiliary/target-helpers/drm_helper.h
> +++ b/src/gallium/auxiliary/target-helpers/drm_helper.h
> @@ -34,35 +34,6 @@ pipe_i915_create_screen(int fd)
>
>  #endif
>
> -#ifdef GALLIUM_ILO
> -#include "intel/drm/intel_drm_public.h"
> -#include "ilo/ilo_public.h"
> -
> -struct pipe_screen *
> -pipe_ilo_create_screen(int fd)
> -{
> -   struct intel_winsys *iws;
> -   struct pipe_screen *screen;
> -
> -   iws = intel_winsys_create_for_fd(fd);
> -   if (!iws)
> -  return NULL;
> -
> -   screen = ilo_screen_create(iws);
> -   return screen ? debug_screen_wrap(screen) : NULL;
> -}
> -
> -#else
> -
> -struct pipe_screen *
> -pipe_ilo_create_screen(int fd)
> -{
> -   fprintf(stderr, "ilo: driver missing\n");
> -   return NULL;
> -}
> -
> -#endif
> -
>  #ifdef GALLIUM_NOUVEAU
>  #include "nouveau/drm/nouveau_drm_public.h"
>
> diff --git a/src/gallium/targets/dri/target.c 
> b/src/gallium/targets/dri/target.c
> index 441a27f..dba18cc 100644
> --- a/src/gallium/targets/dri/target.c
> +++ b/src/gallium/targets/dri/target.c
> @@ -151,9 +151,6 @@ const __DRIextension 
> **__driDriverGetExtensions_i965(void);
>   * i965 driver so that you can just make a directory with a link from
>   * i965_dri.so to the built vc4_dri.so, and point LIBGL_DRIVERS_PATH to that
>   * on your i965-using host to run the driver under simulation.
> - *
> - * This is, of course, incompatible with building with the ilo driver, but 
> you
> - * shouldn't be building that anyway.
>   */
>  PUBLIC const __DRIextension **__driDriverGetExtensions_i965(void)
>  {
> diff --git a/src/gallium/targets/pipe-loader/pipe_i965.c 
> b/src/gallium/targets/pipe-loader/pipe_i965.c
> deleted file mode 100644
> index a2d8deb..000
> --- a/src/gallium/targets/pipe-loader/pipe_i965.c
> +++ /dev/null
> @@ -1,47 +0,0 @@
> -#include "target-helpers/inline_debug_helper.h"
> -#include "state_tracker/drm_driver.h"
> -#include "intel/drm/intel_drm_public.h"
> -#include "ilo/ilo_public.h"
> -
> -static struct pipe_screen *
> -create_screen(int fd)
> -{
> -   struct intel_winsys *iws;
> -   struct pipe_screen *screen;
> -
> -   iws = intel_winsys_create_for_fd(fd);
> -   if (!iws)
> -  return NULL;
> -
> -   screen = ilo_screen_create(iws);
> -   if (!screen)
> -  return NULL;
> -
> -   screen = debug_screen_wrap(screen);
> -
> -   return screen;
> -}
> -static const struct drm_conf_ret throttle_ret = {
> -   .type = DRM_CONF_INT,
> -   .val.val_int = 2,
> -};
> -
> -static const struct drm_conf_ret share_fd_ret = {
> -   .type = DRM_CONF_BOOL,
> -   .val.val_int = true,
> -};
> -
> -static const struct drm_conf_ret *drm_configuration(enum drm_conf conf)
> -{
> -   switch (conf) {
> -   case DRM_CONF_THROTTLE:
> -  return _ret;
> -   case DRM_CONF_SHARE_FD:
> -  return _fd_ret;
> -   default:
> -  break;
> -   }
> -   return NULL;
> -}
> -PUBLIC
> -DRM_DRIVER_DESCRIPTOR("i965", create_screen, drm_configuration)
> diff --git a/src/gallium/winsys/intel/drm/intel_drm_winsys.c 
> b/src/gallium/winsys/intel/drm/intel_drm_winsys.c
> index d3bc430..63c5c8b 100644
> --- a/src/gallium/winsys/intel/drm/intel_drm_winsys.c
> +++ b/src/gallium/winsys/intel/drm/intel_drm_winsys.c
> @@ -41,7 +41,6 @@
>  #include "util/u_inlines.h"
>  #include "util/u_memory.h"
>  #include "util/u_debug.h"
> -#include "ilo/core/intel_winsys.h"
>  #include "intel_drm_public.h"
>
>  struct intel_winsys {
> --
> 

Re: [Mesa-dev] Potentially EOL ilo gallium driver

2016-12-07 Thread Chia-I Wu
Hi all,

Sorry for the slow response.  I think it is fine to drop the driver :(

Not because the driver is currently unmaintained, which is very true
and is a very good reason, but that there is now a Intel Vulkan
driver.  Vulkan is somewhat as low-level as Gallium is (or even
lower-level).  The driver has most things I like to see as well (low
CPU overhead, minimal/predictable heap allocation, generated register
descriptions, etc.).  Sorry for the confusions and burdens it bring to
others, and thanks to the few individuals/groups who find it useful
for their needs at various times.


On Thu, Dec 8, 2016 at 8:33 AM, Edward O'Callaghan
<funfunc...@folklore1984.net> wrote:
>
>
> On 12/08/2016 11:28 AM, Roland Scheidegger wrote:
>> I haven't seen the driver author's opinion on this yet, so it's probably
>> fair to give him some more time to answer. It's not like this is really
>> urgent...
>
> Absolutely!
>
>>
>> Roland
>>
>> Am 08.12.2016 um 01:11 schrieb Edward O'Callaghan:
>>> Hi all,
>>>
>>> So I'll get right to the crux of this; In summary the consensus would
>>> then be to drop ilo?
>>>
>>> If so, I am not sure of this communities procedure? However, if it helps
>>> the patch is here:
>>> https://cgit.freedesktop.org/~funfunctor/mesa/log/?h=eol-ilo
>>>
>>> Kind Regards,
>>> Edward.
>>>
>>> On 12/07/2016 07:08 AM, Ilia Mirkin wrote:
>>>> On Tue, Dec 6, 2016 at 3:00 PM, Rob Clark <robdcl...@gmail.com> wrote:
>>>>> On Tue, Dec 6, 2016 at 2:11 PM, Jason Ekstrand <ja...@jlekstrand.net> 
>>>>> wrote:
>>>>>> On Tue, Dec 6, 2016 at 8:39 AM, Rob Clark <robdcl...@gmail.com> wrote:
>>>>>>>
>>>>>>> On Tue, Dec 6, 2016 at 8:42 AM, Emil Velikov <emil.l.veli...@gmail.com>
>>>>>>> wrote:
>>>>>>>> On 6 December 2016 at 03:16, Edward O'Callaghan
>>>>>>>> <funfunc...@folklore1984.net> wrote:
>>>>>>>>> This patch is to potentially remove ourself from the maintaince
>>>>>>>>> burden of the ilo driver that appears to now be essentially
>>>>>>>>> unmaintained?
>>>>>>>>>
>>>>>>>>> I am not sure of our policy here or if there are too many
>>>>>>>>> users so this patch is really only to gauge a response of
>>>>>>>>> how folks feel?
>>>>>>>>>
>>>>>>>> Surely you want to CC the core/sole developer of the driver when
>>>>>>>> considering its removal.
>>>>>>>> Maybe mailman was "nice" and hid his email in the header ;-)
>>>>>>>>
>>>>>>>> Either way adding Chia-I Wu to the list.
>>>>>>>>
>>>>>>>> -Emil
>>>>>>>> P.S. Not sure/sold how much of an actual burden the driver is, yet I
>>>>>>>> don't make serious gallium infra changes.
>>>>>>>
>>>>>>> really hasn't been a problem for me..
>>>>>>>
>>>>>>> That said, it would be nice if someday someone wired this up to use
>>>>>>> glsl_to_nir path in gallium and re-used i965's nir backend.  I think
>>>>>>> that would make ilo somewhat more interesting..
>>>>>>
>>>>>>
>>>>>> We had a bit of a chat about this on IRC and what I told Ilia there was 
>>>>>> that
>>>>>> the more interesting thing to do, if someone really wanted to do Intel on
>>>>>> gallium, would probably be to build a new driver based on ISL, blorp, the
>>>>>> i965 compiler, NIR, and genxml.  We've made a pretty good driver-building
>>>>>> toolbox.  Having an almost unmaintained driver that has it's own 
>>>>>> hand-rolled
>>>>>> and inferrior compiler, surface layout, etc. isn't doing much good.
>>>>>>
>>>>>
>>>>> yeah, reusing the other bits would be nice too, and hopefully would be
>>>>> the long term goal if someone where to spend time on this.. I guess
>>>>> I'd prefer a more incremental approach of converting parts one by one
>>>>> if I were doing it myself.  It's kind of a moot point either way until
>>>>> someone has time/motivation to spend on it.
>>>>>
>>>>> But I've no real objection to dropping ilo until then if others feel
>>>>> strongly.. it's still there in git history so it can be resurrected if
>>>>> someone wants to convert to reuse other i965 bits incrementally rather
>>>>> than starting from scratch.
>>>>
>>>> As mentioned on IRC, I think the real use-case that ilo could cover
>>>> that i965/anv can't (easily) handle is acting as a gallium-nine
>>>> backend. (I know someone's working on DX9 over vulkan, but that's
>>>> hardly ready, and will never be available on gen6.)
>>>>
>>>> However at this time, it's not sufficiently functional to handle
>>>> gallium-nine, so I don't see any serious downside to dropping it.
>>>>
>>>>   -ilia
>>>>
>>>
>>>
>>>
>>> ___
>>> mesa-dev mailing list
>>> mesa-dev@lists.freedesktop.org
>>> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>>>
>>
>
>
> ___
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 1/3] ilo: add PIPE_QUERY_OCCLUSION_PREDICATE support

2016-02-04 Thread Chia-I Wu
On Fri, Feb 5, 2016 at 2:36 AM, Ilia Mirkin <imir...@alum.mit.edu> wrote:
> [+Chia-I Wu]
>
> I'd appreciate it if you could have a look and see if this looks
> reasonable. Not sure if you're still maintaining the driver or not.
> The story is that I want to use this query type for GL_ANY_SAMPLES*
> queries.
The change looks good, thanks.

I do still have interests in the driver, but I recently changed to a
full time job and could not find much time between job and family :(

>
> Cheers,
>
>   -ilia
>
> On Thu, Feb 4, 2016 at 12:52 PM, Ilia Mirkin <imir...@alum.mit.edu> wrote:
>> Signed-off-by: Ilia Mirkin <imir...@alum.mit.edu>
>> ---
>>  src/gallium/drivers/ilo/ilo_draw.c   | 2 ++
>>  src/gallium/drivers/ilo/ilo_query.c  | 9 -
>>  src/gallium/drivers/ilo/ilo_render.c | 2 ++
>>  3 files changed, 12 insertions(+), 1 deletion(-)
>>
>> diff --git a/src/gallium/drivers/ilo/ilo_draw.c 
>> b/src/gallium/drivers/ilo/ilo_draw.c
>> index 69f36ae..6831d2c 100644
>> --- a/src/gallium/drivers/ilo/ilo_draw.c
>> +++ b/src/gallium/drivers/ilo/ilo_draw.c
>> @@ -71,6 +71,7 @@ query_process_bo(const struct ilo_context *ilo, struct 
>> ilo_query *q)
>>
>> switch (q->type) {
>> case PIPE_QUERY_OCCLUSION_COUNTER:
>> +   case PIPE_QUERY_OCCLUSION_PREDICATE:
>> case PIPE_QUERY_TIME_ELAPSED:
>> case PIPE_QUERY_PRIMITIVES_GENERATED:
>> case PIPE_QUERY_PRIMITIVES_EMITTED:
>> @@ -157,6 +158,7 @@ ilo_init_draw_query(struct ilo_context *ilo, struct 
>> ilo_query *q)
>>
>> switch (q->type) {
>> case PIPE_QUERY_OCCLUSION_COUNTER:
>> +   case PIPE_QUERY_OCCLUSION_PREDICATE:
>> case PIPE_QUERY_TIME_ELAPSED:
>> case PIPE_QUERY_PRIMITIVES_GENERATED:
>> case PIPE_QUERY_PRIMITIVES_EMITTED:
>> diff --git a/src/gallium/drivers/ilo/ilo_query.c 
>> b/src/gallium/drivers/ilo/ilo_query.c
>> index 27d0812..106bd42 100644
>> --- a/src/gallium/drivers/ilo/ilo_query.c
>> +++ b/src/gallium/drivers/ilo/ilo_query.c
>> @@ -47,7 +47,7 @@ static const struct {
>>  #define INFOX(prefix) { NULL, NULL, NULL, NULL, }
>>
>> [PIPE_QUERY_OCCLUSION_COUNTER]  = INFO(draw),
>> -   [PIPE_QUERY_OCCLUSION_PREDICATE]= INFOX(draw),
>> +   [PIPE_QUERY_OCCLUSION_PREDICATE]= INFO(draw),
>> [PIPE_QUERY_TIMESTAMP]  = INFO(draw),
>> [PIPE_QUERY_TIMESTAMP_DISJOINT] = INFOX(draw),
>> [PIPE_QUERY_TIME_ELAPSED]   = INFO(draw),
>> @@ -75,6 +75,7 @@ ilo_create_query(struct pipe_context *pipe, unsigned 
>> query_type, unsigned index)
>>
>> switch (query_type) {
>> case PIPE_QUERY_OCCLUSION_COUNTER:
>> +   case PIPE_QUERY_OCCLUSION_PREDICATE:
>> case PIPE_QUERY_TIMESTAMP:
>> case PIPE_QUERY_TIME_ELAPSED:
>> case PIPE_QUERY_PRIMITIVES_GENERATED:
>> @@ -163,6 +164,12 @@ query_serialize(const struct ilo_query *q, void *buf)
>>   dst[0] = q->result.u64;
>>}
>>break;
>> +   case PIPE_QUERY_OCCLUSION_PREDICATE:
>> +  {
>> + uint64_t *dst = buf;
>> + dst[0] = !!q->result.u64;
>> +  }
>> +  break;
>> case PIPE_QUERY_PIPELINE_STATISTICS:
>>{
>>   const struct pipe_query_data_pipeline_statistics *stats =
>> diff --git a/src/gallium/drivers/ilo/ilo_render.c 
>> b/src/gallium/drivers/ilo/ilo_render.c
>> index 8bc04df..9a47ca8 100644
>> --- a/src/gallium/drivers/ilo/ilo_render.c
>> +++ b/src/gallium/drivers/ilo/ilo_render.c
>> @@ -202,6 +202,7 @@ ilo_render_get_query_len(const struct ilo_render *render,
>>
>> switch (query_type) {
>> case PIPE_QUERY_OCCLUSION_COUNTER:
>> +   case PIPE_QUERY_OCCLUSION_PREDICATE:
>> case PIPE_QUERY_TIMESTAMP:
>> case PIPE_QUERY_TIME_ELAPSED:
>>/* no reg */
>> @@ -268,6 +269,7 @@ ilo_render_emit_query(struct ilo_render *render,
>>
>> switch (q->type) {
>> case PIPE_QUERY_OCCLUSION_COUNTER:
>> +   case PIPE_QUERY_OCCLUSION_PREDICATE:
>>pipe_control_dw1 = GEN6_PIPE_CONTROL_DEPTH_STALL |
>>   GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT;
>>break;
>> --
>> 2.4.10
>>
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 3/4] ilo: unref old fence

2015-07-09 Thread Chia-I Wu
On Thu, Jul 9, 2015 at 8:46 AM, Rob Clark robdcl...@gmail.com wrote:
 From: Rob Clark robcl...@freedesktop.org

 Some, but not all, state trackers will explicitly unref (and set to
 NULL) the previous *fence before calling pipe-flush().  So driver
 should use fence_ref() which will unref the old fence if not NULL.
Looks good.  Thanks.

 Signed-off-by: Rob Clark robcl...@freedesktop.org
 ---
  src/gallium/drivers/ilo/ilo_context.c | 2 ++
  1 file changed, 2 insertions(+)

 diff --git a/src/gallium/drivers/ilo/ilo_context.c 
 b/src/gallium/drivers/ilo/ilo_context.c
 index 3d5c7b6..b9a16aa 100644
 --- a/src/gallium/drivers/ilo/ilo_context.c
 +++ b/src/gallium/drivers/ilo/ilo_context.c
 @@ -62,6 +62,8 @@ ilo_flush(struct pipe_context *pipe,
   (flags  PIPE_FLUSH_END_OF_FRAME) ? frame end : user request);

 if (f) {
 +  struct pipe_screen *screen = pipe-screen;
 +  screen-fence_reference(screen, f, NULL);
*f = ilo_screen_fence_create(pipe-screen, ilo-cp-last_submitted_bo);
 }
  }
 --
 2.4.3




-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 01/18] winsys/radeon: move radeon_winsys.h up one directory

2015-04-28 Thread Chia-I Wu
On Tue, Apr 28, 2015 at 2:19 PM, Emil Velikov emil.l.veli...@gmail.com wrote:
 On 28 April 2015 at 03:30, Michel Dänzer mic...@daenzer.net wrote:
 On 28.04.2015 03:57, Marek Olšák wrote:
 Can you elaborate on what amdgpu/sw would be good for? Frankly I don't
 see a point, therefore we don't need the drm subdirectory.

 I think Emil's main point (which I agree with) is that radeon_winsys.h
 should live somewhere under src/gallium/drivers/, probably
 src/gallium/drivers/radeon/, because the winsys interface is defined by
 the drivers, not the winsys. All other drivers have their *_winsys.h
 headers there.

 Maybe amdgpu/sw wasn't a good example, but at some point there might be
 e.g. amdgpu/haiku. ;)

 Well said Michel - this is exactly what I meant.
ilo moved its intel_winsys.h to src/gallium/drivers/ilo because Emil
wouldn't let me put it in src/gallium/winsys/intel, which is exactly
what this patch tries to do for radeon :)


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



-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 0/2] Disable the EGL state tracker for Linux/DRI builds

2014-11-05 Thread Chia-I Wu
On Thu, Nov 6, 2014 at 5:11 AM, Jose Fonseca jfons...@vmware.com wrote:
 How many people/companies use EGL for Windows/fbdev, how about OpenVG on
 any platform ?

 I already said this privately to Marek when he was RFC'ing on this change: 
 I'm fine if Linux-specific drivers abandon st/egl to focus solely on st/dri, 
 but removing st/egl altogether seems unnecessary and short-sighted: EGL is a 
 cross-platform API, Mesa is a cross-platform implementation of OpenGL and 
 friends, so sooner or later people will want to have Mesa's EGL support on 
 platforms others than Linux.

 This is not hypothetical:
 - See https://bugs.freedesktop.org/show_bug.cgi?id=40920 for an example of a 
 bug reported from an user using llvmpipe + egl + opengv on windows.
 - VMware doesn't currently ship or support EGL on Windows, but I suspect we 
 eventually we'll want to support EGL on non-linux platforms.

 Even if OpenVG is loosing popularity, but maybe Khronos will come up with 
 another cross-platform graphics API (maybe OpenGL NG) that's tied to EGL.

 So a cross-platform implementation of EGL is bound to be useful.


 I don't test, but I build egl-static and OpenVG on Windows nightly w/ 
 llvmpipe.  It's like a superset of OSMesa, and it seems more useful, as it 
 gives one more APIs than OSMesa, and through a standard API to create/bind 
 contexts .
EGL/OpenVG worked with softpipe at one point on Windows.  I am not
sure about the status now.


 In short, stop caring about st/egl on Linux, maybe even remove DRI support 
 out st/egl if you must, but please don't go out of your way to break EGL on 
 non-linux platforms.


 Jose

 
 From: mesa-dev mesa-dev-boun...@lists.freedesktop.org on behalf of Emil 
 Velikov emil.l.veli...@gmail.com
 Sent: 05 November 2014 00:46
 To: Marek Olšák; mesa-dev@lists.freedesktop.org
 Cc: emil.l.veli...@gmail.com
 Subject: Re: [Mesa-dev] [PATCH 0/2] Disable the EGL state tracker for 
 Linux/DRI builds

 On 04/11/14 22:42, Marek Olšák wrote:
 Hi everybody,

 I'm about to address this long-standing issue: The EGL state tracker is
 redundant. It duplicates what st/dri does and it also duplicates what
 the common loader egl_dri2 does, which is used by all classic drivers
 and even works better with gallium drivers.

 Let's compare EGL extensions for both backends:

 st/egl:
 EGL version string: 1.4 (Gallium)
 EGL client APIs: OpenGL OpenGL_ES OpenGL_ES2 OpenVG
 EGL extensions string:
 EGL_WL_bind_wayland_display EGL_KHR_image_base EGL_KHR_image_pixmap
 EGL_KHR_image EGL_KHR_reusable_sync EGL_KHR_fence_sync
 EGL_KHR_surfaceless_context EGL_NOK_swap_region
 EGL_NV_post_sub_buffer

 egl_dri2:
 EGL version string: 1.4 (DRI2)
 EGL client APIs: OpenGL OpenGL_ES OpenGL_ES2 OpenGL_ES3
 EGL extensions string:
 EGL_MESA_drm_image EGL_MESA_configless_context EGL_KHR_image_base
 EGL_KHR_image_pixmap EGL_KHR_image EGL_KHR_gl_texture_2D_image
 EGL_KHR_gl_texture_cubemap_image EGL_KHR_gl_renderbuffer_image
 EGL_KHR_surfaceless_context EGL_KHR_create_context
 EGL_NOK_swap_region EGL_NOK_texture_from_pixmap
 EGL_CHROMIUM_sync_control EGL_EXT_image_dma_buf_import
 EGL_NV_post_sub_buffer

 egl_dri2 also supports MSAA on the window framebuffer (through st/dri).
 It's really obvious which one is better.

 I'm aware of 2 features that we will lose:
 - swrast on Wayland - I'm not sure about this. Perhaps kms-swrast has
 addressed this already.
 - OpenVG - It has never taken off. If people want this on Linux, it should
 use egl_dri2 and st/dri, like OpenGL does.

 This series removes st/egl and st/gbm support from the autoconf build
 (the latter depends on the former and is probably just as redundant).
 The next step is to remove all Linux-specific backends from st/egl.
 Windows, Android, and other platform backends will be kept intact,
 therefore st/egl won't be removed completely.

 Please comment.

 A few thoughts:
  - Iirc Eric is using st/egl as the dri2 backend seems to be causing
 problems :(
  - Android supports dri modules, but st/dri/Android.mk is missing.
 Should be trivial to add.
  - Windows - might be a pain in the a** to get it working. Then again
 does Windows have EGL ?
  - fbdev, OpenVG - the etnaviv project was using the former, currently
 moving to full-blown drm :)

 If one is to nuking the three st we can remove
  - the libEGL symbol export mayhem
  - gallium's st_api, and flatten things a bit
  - a bit of duplication :)

 In summary:
 With a bit of work we can remove Linux and Android from the equation.
 How many people/companies use EGL for Windows/fbdev, how about OpenVG on
 any platform ?

 Cheers,
 Emil

 Thanks,

 Marek
 ___
 mesa-dev mailing list
 mesa-dev@lists.freedesktop.org
 

Re: [Mesa-dev] [PATCH 0/2] Disable the EGL state tracker for Linux/DRI builds

2014-11-05 Thread Chia-I Wu
On Wed, Nov 5, 2014 at 6:42 AM, Marek Olšák mar...@gmail.com wrote:
 Hi everybody,

 I'm about to address this long-standing issue: The EGL state tracker is
 redundant. It duplicates what st/dri does and it also duplicates what
 the common loader egl_dri2 does, which is used by all classic drivers
 and even works better with gallium drivers.

 Let's compare EGL extensions for both backends:

 st/egl:
 EGL version string: 1.4 (Gallium)
 EGL client APIs: OpenGL OpenGL_ES OpenGL_ES2 OpenVG
 EGL extensions string:
 EGL_WL_bind_wayland_display EGL_KHR_image_base EGL_KHR_image_pixmap
 EGL_KHR_image EGL_KHR_reusable_sync EGL_KHR_fence_sync
 EGL_KHR_surfaceless_context EGL_NOK_swap_region
 EGL_NV_post_sub_buffer

 egl_dri2:
 EGL version string: 1.4 (DRI2)
 EGL client APIs: OpenGL OpenGL_ES OpenGL_ES2 OpenGL_ES3
 EGL extensions string:
 EGL_MESA_drm_image EGL_MESA_configless_context EGL_KHR_image_base
 EGL_KHR_image_pixmap EGL_KHR_image EGL_KHR_gl_texture_2D_image
 EGL_KHR_gl_texture_cubemap_image EGL_KHR_gl_renderbuffer_image
 EGL_KHR_surfaceless_context EGL_KHR_create_context
 EGL_NOK_swap_region EGL_NOK_texture_from_pixmap
 EGL_CHROMIUM_sync_control EGL_EXT_image_dma_buf_import
 EGL_NV_post_sub_buffer

 egl_dri2 also supports MSAA on the window framebuffer (through st/dri).
 It's really obvious which one is better.

 I'm aware of 2 features that we will lose:
 - swrast on Wayland - I'm not sure about this. Perhaps kms-swrast has
 addressed this already.
 - OpenVG - It has never taken off. If people want this on Linux, it should
 use egl_dri2 and st/dri, like OpenGL does.

 This series removes st/egl and st/gbm support from the autoconf build
 (the latter depends on the former and is probably just as redundant).
 The next step is to remove all Linux-specific backends from st/egl.
 Windows, Android, and other platform backends will be kept intact,
 therefore st/egl won't be removed completely.
While I think Pekka and Jose have valid arguments, I am not sure if
anyone is taking care of st/egl bug reports and patch reviews.  If no
one is, it might be better for st/egl to go than to stay IMHO.



 Please comment.

 Thanks,

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


-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 01/27] winsys/intel: drop intel_winsys.h from makefile.sources

2014-08-29 Thread Chia-I Wu
On Sat, Aug 30, 2014 at 7:44 AM, Emil Velikov emil.l.veli...@gmail.com wrote:
 With the last revisions of commit 664c2d76947(gallium/ilo: cleanup
 intel_winsys.h) we moved the header from winsys to drivers, but we
 forgot to update the makefile.sources to reflect this.
This and patch 14 looks good to me.  Thanks.

 Cc: Chia-I Wu olva...@gmail.com
 Signed-off-by: Emil Velikov emil.l.veli...@gmail.com
 ---
  src/gallium/winsys/intel/drm/Makefile.sources | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)

 diff --git a/src/gallium/winsys/intel/drm/Makefile.sources 
 b/src/gallium/winsys/intel/drm/Makefile.sources
 index 18b2513..0085d5a 100644
 --- a/src/gallium/winsys/intel/drm/Makefile.sources
 +++ b/src/gallium/winsys/intel/drm/Makefile.sources
 @@ -1,4 +1,3 @@
  C_SOURCES := \
 intel_drm_public.h \
 -   intel_drm_winsys.c \
 -   intel_winsys.h
 +   intel_drm_winsys.c
 --
 2.0.2




-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCHv3 07/16] glsl: protect anonymous struct id with a mutex

2014-08-20 Thread Chia-I Wu
There may be two contexts compiling shaders at the same time, and we want the
anonymous struct id to be globally unique.

Signed-off-by: Chia-I Wu o...@lunarg.com
Reviewed-by: Brian Paul bri...@vmware.com
Reviewed-by: Ian Romanick ian.d.roman...@intel.com
---
 src/glsl/glsl_parser_extras.cpp | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index 490c3c8..b17cdb1 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -1350,9 +1350,15 @@ ast_struct_specifier::ast_struct_specifier(const char 
*identifier,
   ast_declarator_list *declarator_list)
 {
if (identifier == NULL) {
+  static mtx_t mutex = _MTX_INITIALIZER_NP;
   static unsigned anon_count = 1;
-  identifier = ralloc_asprintf(this, #anon_struct_%04x, anon_count);
-  anon_count++;
+  unsigned count;
+
+  mtx_lock(mutex);
+  count = anon_count++;
+  mtx_unlock(mutex);
+
+  identifier = ralloc_asprintf(this, #anon_struct_%04x, count);
}
name = identifier;
this-declarations.push_degenerate_list_at_head(declarator_list-link);
-- 
2.0.0.rc2

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


[Mesa-dev] [PATCHv3 03/16] util: initialize locale_t with a static object

2014-08-20 Thread Chia-I Wu
_mesa_strtod and _mesa_strtof may be called from multiple threads.  They need
to be thread-safe.

Signed-off-by: Chia-I Wu o...@lunarg.com
Reviewed-by: Brian Paul bri...@vmware.com
Reviewed-by: Ian Romanick ian.d.roman...@intel.com

v2: platform checks are now done in configure.ac
---
 src/util/strtod.cpp | 18 --
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/src/util/strtod.cpp b/src/util/strtod.cpp
index 2a3e8eb..2b4dd98 100644
--- a/src/util/strtod.cpp
+++ b/src/util/strtod.cpp
@@ -36,6 +36,12 @@
 #include strtod.h
 
 
+#if defined(_GNU_SOURCE)  defined(HAVE_XLOCALE_H)
+static struct locale_initializer {
+   locale_initializer() { loc = newlocale(LC_CTYPE_MASK, C, NULL); }
+   locale_t loc;
+} loc_init;
+#endif
 
 /**
  * Wrapper around strtod which uses the C locale so the decimal
@@ -45,11 +51,7 @@ double
 _mesa_strtod(const char *s, char **end)
 {
 #if defined(_GNU_SOURCE)  defined(HAVE_XLOCALE_H)
-   static locale_t loc = NULL;
-   if (!loc) {
-  loc = newlocale(LC_CTYPE_MASK, C, NULL);
-   }
-   return strtod_l(s, end, loc);
+   return strtod_l(s, end, loc_init.loc);
 #else
return strtod(s, end);
 #endif
@@ -64,11 +66,7 @@ float
 _mesa_strtof(const char *s, char **end)
 {
 #if defined(_GNU_SOURCE)  defined(HAVE_XLOCALE_H)
-   static locale_t loc = NULL;
-   if (!loc) {
-  loc = newlocale(LC_CTYPE_MASK, C, NULL);
-   }
-   return strtof_l(s, end, loc);
+   return strtof_l(s, end, loc_init.loc);
 #elif defined(HAVE_STRTOF)
return strtof(s, end);
 #else
-- 
2.0.0.rc2

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


[Mesa-dev] [PATCHv3 11/16] mesa: add infrastructure for threaded shader compilation

2014-08-20 Thread Chia-I Wu
Add _mesa_enable_glsl_threadpool to enable the thread pool for a context, and
add ctx-Const.DeferCompileShader and ctx-Const.DeferLinkProgram to
fine-control what gets threaded.

Setting DeferCompileShader to true will make _mesa_glsl_compile_shader be
executed in a worker thread.  The function is thread-safe so there is no
restriction on DeferCompileShader.

Setting DeferLinkProgram to true will make _mesa_glsl_link_shader be executed
in a worker thread.  The function is thread-safe only when certain driver
functions (as documented in struct gl_constants) are thread-safe.  It is
drivers' responsibility to fix those driver functions before setting
DeferLinkProgram.

When DeferLinkProgram is set, drivers are not supposed to inspect the context
in their LinkShader callbacks.  Instead, NotifyLinkShader is added.  Drivers
should inspect the context in NotifyLinkShader and save what they need for
LinkShader in gl_shader_program.

As a final note, most applications will not benefit from threaded shader
compilation because they check GL_COMPILE_STATUS/GL_LINK_STATUS immediately,
giving the worker threads no time to do their jobs.  A possible improvement is
to split LinkShader into two parts: the first part links and error checks
while the second part optimizes and generates the machine code.  With the
split, we can always defer the second part to the thread pool.

Signed-off-by: Chia-I Wu o...@lunarg.com
Reviewed-by: Brian Paul bri...@vmware.com
Reviewed-by: Ian Romanick ian.d.roman...@intel.com

v2:

 - replace void *TaskData by struct gl_context *TaskContext
 - use bool instead of GLboolean internally
 - add more comments to the newly added functions
---
 src/mesa/main/context.c |  29 +++
 src/mesa/main/context.h |   3 ++
 src/mesa/main/dd.h  |   8 +++
 src/mesa/main/mtypes.h  |  34 
 src/mesa/main/pipelineobj.c |  18 +++
 src/mesa/main/shaderapi.c   | 124 +++-
 src/mesa/main/shaderobj.c   |  84 +++---
 src/mesa/main/shaderobj.h   |  55 ++--
 8 files changed, 332 insertions(+), 23 deletions(-)

diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 7a1b6f6..54d1248 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -112,6 +112,7 @@
 #include points.h
 #include polygon.h
 #include queryobj.h
+#include shaderapi.h
 #include syncobj.h
 #include rastpos.h
 #include remap.h
@@ -133,6 +134,7 @@
 #include math/m_matrix.h
 #include main/dispatch.h /* for _gloffset_COUNT */
 #include util/simple_list.h
+#include util/threadpool.h
 
 #ifdef USE_SPARC_ASM
 #include sparc/sparc.h
@@ -1187,6 +1189,27 @@ _mesa_create_context(gl_api api,
}
 }
 
+void
+_mesa_enable_glsl_threadpool(struct gl_context *ctx, int max_threads)
+{
+   if (!ctx-ThreadPool)
+  ctx-ThreadPool = _mesa_threadpool_get_singleton(max_threads);
+}
+
+static void
+wait_shader_object_cb(GLuint id, void *data, void *userData)
+{
+   struct gl_context *ctx = (struct gl_context *) userData;
+   struct gl_shader *sh = (struct gl_shader *) data;
+
+   if (_mesa_validate_shader_target(ctx, sh-Type)) {
+  _mesa_wait_shaders(ctx, sh, 1);
+   }
+   else {
+  struct gl_shader_program *shProg = (struct gl_shader_program *) data;
+  _mesa_wait_shader_program(ctx, shProg);
+   }
+}
 
 /**
  * Free the data associated with the given context.
@@ -1205,6 +1228,12 @@ _mesa_free_context_data( struct gl_context *ctx )
   _mesa_make_current(ctx, NULL, NULL);
}
 
+   if (ctx-ThreadPool) {
+  _mesa_HashWalk(ctx-Shared-ShaderObjects, wait_shader_object_cb, ctx);
+  _mesa_threadpool_unref(ctx-ThreadPool);
+  ctx-ThreadPool = NULL;
+   }
+
/* unreference WinSysDraw/Read buffers */
_mesa_reference_framebuffer(ctx-WinSysDrawBuffer, NULL);
_mesa_reference_framebuffer(ctx-WinSysReadBuffer, NULL);
diff --git a/src/mesa/main/context.h b/src/mesa/main/context.h
index d902ea7..e81d4f7 100644
--- a/src/mesa/main/context.h
+++ b/src/mesa/main/context.h
@@ -118,6 +118,9 @@ _mesa_create_context(gl_api api,
  const struct dd_function_table *driverFunctions);
 
 extern void
+_mesa_enable_glsl_threadpool(struct gl_context *ctx, int max_threads);
+
+extern void
 _mesa_free_context_data( struct gl_context *ctx );
 
 extern void
diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
index c130b14..9310002 100644
--- a/src/mesa/main/dd.h
+++ b/src/mesa/main/dd.h
@@ -477,6 +477,14 @@ struct dd_function_table {
 */
/*@{*/
/**
+* Called when a shader program is to be linked.
+*
+* This is optional and gives drivers an opportunity to inspect the context
+* and prepare for LinkShader, which may be deferred to another thread.
+*/
+   void (*NotifyLinkShader)(struct gl_context *ctx,
+struct gl_shader_program *shader);
+   /**
 * Called when a shader program is linked.
 *
 * This gives drivers an opportunity to clone

[Mesa-dev] [PATCHv3 05/16] util: add a generic thread pool data structure

2014-08-20 Thread Chia-I Wu
It can be used to implement, for example, threaded glCompileShader and
glLinkProgram.  Two basic tests are included to verify the basic functions,
and to give us some confidence about its thread-safety.

v2: allow tasks to complete other tasks

Signed-off-by: Chia-I Wu o...@lunarg.com
Reviewed-by: Brian Paul bri...@vmware.com

v3: move to src/util/ and mention the tests
---
 configure.ac  |   3 +-
 src/util/Makefile.am  |   5 +-
 src/util/Makefile.sources |   3 +-
 src/util/tests/threadpool/Makefile.am |  36 ++
 src/util/tests/threadpool/threadpool_test.cpp | 137 
 src/util/threadpool.c | 476 ++
 src/util/threadpool.h |  67 
 7 files changed, 724 insertions(+), 3 deletions(-)
 create mode 100644 src/util/tests/threadpool/Makefile.am
 create mode 100644 src/util/tests/threadpool/threadpool_test.cpp
 create mode 100644 src/util/threadpool.c
 create mode 100644 src/util/threadpool.h

diff --git a/configure.ac b/configure.ac
index 57e9f7d..2f7268f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2261,7 +2261,8 @@ AC_CONFIG_FILES([Makefile
src/mesa/drivers/x11/Makefile
src/mesa/main/tests/Makefile
src/util/Makefile
-   src/util/tests/hash_table/Makefile])
+   src/util/tests/hash_table/Makefile
+   src/util/tests/threadpool/Makefile])
 
 dnl Sort the dirs alphabetically
 GALLIUM_TARGET_DIRS=`echo $GALLIUM_TARGET_DIRS|tr   \n|sort -u|tr \n  `
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index 4733a1a..da6815e 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -19,7 +19,7 @@
 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 # IN THE SOFTWARE.
 
-SUBDIRS = . tests/hash_table
+SUBDIRS = . tests/hash_table tests/threadpool
 
 include Makefile.sources
 
@@ -34,6 +34,9 @@ libmesautil_la_SOURCES = \
$(MESA_UTIL_FILES) \
$(MESA_UTIL_GENERATED_FILES)
 
+libmesautil_la_LIBADD = \
+   $(PTHREAD_LIBS)
+
 BUILT_SOURCES = $(MESA_UTIL_GENERATED_FILES)
 CLEANFILES = $(BUILT_SOURCES)
 
diff --git a/src/util/Makefile.sources b/src/util/Makefile.sources
index 86466dc..65f98f7 100644
--- a/src/util/Makefile.sources
+++ b/src/util/Makefile.sources
@@ -1,7 +1,8 @@
 MESA_UTIL_FILES := \
hash_table.c\
ralloc.c \
-   strtod.cpp
+   strtod.cpp \
+   threadpool.c
 
 MESA_UTIL_GENERATED_FILES = \
format_srgb.c
diff --git a/src/util/tests/threadpool/Makefile.am 
b/src/util/tests/threadpool/Makefile.am
new file mode 100644
index 000..2aa010c
--- /dev/null
+++ b/src/util/tests/threadpool/Makefile.am
@@ -0,0 +1,36 @@
+# Copyright © 2009 Intel Corporation
+#
+#  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
+#  on the rights to use, copy, modify, merge, publish, distribute, sub
+#  license, 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 NON-INFRINGEMENT.  IN NO EVENT SHALL
+#  ADAM JACKSON 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.
+
+AM_CPPFLAGS = \
+   -I$(top_srcdir)/include \
+   -I$(top_srcdir)/src/gtest/include \
+   -I$(top_srcdir)/src/util \
+   $(DEFINES)
+
+TESTS = threadpool-test
+
+check_PROGRAMS = threadpool-test
+
+threadpool_test_SOURCES = threadpool_test.cpp
+threadpool_test_CFLAGS = $(PTHREAD_CFLAGS)
+threadpool_test_LDADD =\
+   $(top_builddir)/src/util/libmesautil.la \
+   $(top_builddir)/src/gtest/libgtest.la   \
+   $(PTHREAD_LIBS)
diff --git a/src/util/tests/threadpool/threadpool_test.cpp 
b/src/util/tests/threadpool/threadpool_test.cpp
new file mode 100644
index 000..63f55c5
--- /dev/null
+++ b/src/util/tests/threadpool/threadpool_test.cpp
@@ -0,0 +1,137 @@
+/*
+ * Copyright © 2014 LunarG, Inc.
+ *
+ * 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

[Mesa-dev] [PATCHv3 02/16] configure: check for xlocale.h and strtof

2014-08-20 Thread Chia-I Wu
With the assumptions that xlocale.h implies newlocale and strtof_l.  SCons is
updated to define HAVE_XLOCALE_H on linux and darwin.

Signed-off-by: Chia-I Wu o...@lunarg.com
---
 configure.ac|  3 +++
 scons/gallium.py|  4 
 src/util/strtod.cpp | 12 
 3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/configure.ac b/configure.ac
index be6898f..57e9f7d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -494,6 +494,9 @@ if test x$enable_asm = xyes; then
 esac
 fi
 
+AC_CHECK_HEADER([xlocale.h], [DEFINES=$DEFINES -DHAVE_XLOCALE_H])
+AC_CHECK_FUNC([strtof], [DEFINES=$DEFINES -DHAVE_STRTOF])
+
 dnl Check to see if dlopen is in default libraries (like Solaris, which
 dnl has it in libc), or if libdl is needed to get it.
 AC_CHECK_FUNC([dlopen], [DEFINES=$DEFINES -DHAVE_DLOPEN],
diff --git a/scons/gallium.py b/scons/gallium.py
index e915319..70b40f6 100755
--- a/scons/gallium.py
+++ b/scons/gallium.py
@@ -301,6 +301,10 @@ def generate(env):
 cppdefines += ['HAVE_ALIAS']
 else:
 cppdefines += ['GLX_ALIAS_UNSUPPORTED']
+
+if env['platform'] in ('linux', 'darwin'):
+cppdefines += ['HAVE_XLOCALE_H']
+
 if env['platform'] == 'haiku':
 cppdefines += [
 'HAVE_PTHREAD',
diff --git a/src/util/strtod.cpp b/src/util/strtod.cpp
index 2f1d229..2a3e8eb 100644
--- a/src/util/strtod.cpp
+++ b/src/util/strtod.cpp
@@ -28,7 +28,7 @@
 
 #ifdef _GNU_SOURCE
 #include locale.h
-#ifdef __APPLE__
+#ifdef HAVE_XLOCALE_H
 #include xlocale.h
 #endif
 #endif
@@ -44,9 +44,7 @@
 double
 _mesa_strtod(const char *s, char **end)
 {
-#if defined(_GNU_SOURCE)  !defined(__CYGWIN__)  !defined(__FreeBSD__)  \
-   !defined(ANDROID)  !defined(__HAIKU__)  !defined(__UCLIBC__)  \
-   !defined(__NetBSD__)
+#if defined(_GNU_SOURCE)  defined(HAVE_XLOCALE_H)
static locale_t loc = NULL;
if (!loc) {
   loc = newlocale(LC_CTYPE_MASK, C, NULL);
@@ -65,15 +63,13 @@ _mesa_strtod(const char *s, char **end)
 float
 _mesa_strtof(const char *s, char **end)
 {
-#if defined(_GNU_SOURCE)  !defined(__CYGWIN__)  !defined(__FreeBSD__)  \
-   !defined(ANDROID)  !defined(__HAIKU__)  !defined(__UCLIBC__)  \
-   !defined(__NetBSD__)
+#if defined(_GNU_SOURCE)  defined(HAVE_XLOCALE_H)
static locale_t loc = NULL;
if (!loc) {
   loc = newlocale(LC_CTYPE_MASK, C, NULL);
}
return strtof_l(s, end, loc);
-#elif defined(_ISOC99_SOURCE) || (defined(_XOPEN_SOURCE)  _XOPEN_SOURCE = 
600)
+#elif defined(HAVE_STRTOF)
return strtof(s, end);
 #else
return (float) strtod(s, end);
-- 
2.0.0.rc2

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


[Mesa-dev] [PATCHv3 10/16] mesa: protect the debug state with a mutex

2014-08-20 Thread Chia-I Wu
We are about to change mesa to spawn threads for deferred glCompileShader and
glLinkProgram, and we need to make sure those threads can send compiler
warnings/errors to the debug output safely.

Signed-off-by: Chia-I Wu o...@lunarg.com
Reviewed-by: Brian Paul bri...@vmware.com
Reviewed-by: Ian Romanick ian.d.roman...@intel.com
---
 src/mesa/main/errors.c | 172 +++--
 src/mesa/main/mtypes.h |   1 +
 2 files changed, 126 insertions(+), 47 deletions(-)

diff --git a/src/mesa/main/errors.c b/src/mesa/main/errors.c
index 6b55a1d..218b4ee 100644
--- a/src/mesa/main/errors.c
+++ b/src/mesa/main/errors.c
@@ -677,22 +677,41 @@ debug_pop_group(struct gl_debug_state *debug)
 
 
 /**
- * Return debug state for the context.  The debug state will be allocated
- * and initialized upon the first call.
+ * Lock and return debug state for the context.  The debug state will be
+ * allocated and initialized upon the first call.  When NULL is returned, the
+ * debug state is not locked.
  */
 static struct gl_debug_state *
-_mesa_get_debug_state(struct gl_context *ctx)
+_mesa_lock_debug_state(struct gl_context *ctx)
 {
+   mtx_lock(ctx-DebugMutex);
+
if (!ctx-Debug) {
   ctx-Debug = debug_create();
   if (!ctx-Debug) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, allocating debug state);
+ GET_CURRENT_CONTEXT(cur);
+ mtx_unlock(ctx-DebugMutex);
+
+ /*
+  * This function may be called from other threads.  When that is the
+  * case, we cannot record this OOM error.
+  */
+ if (ctx == cur)
+_mesa_error(ctx, GL_OUT_OF_MEMORY, allocating debug state);
+
+ return NULL;
   }
}
 
return ctx-Debug;
 }
 
+static void
+_mesa_unlock_debug_state(struct gl_context *ctx)
+{
+   mtx_unlock(ctx-DebugMutex);
+}
+
 /**
  * Set the integer debug state specified by \p pname.  This can be called from
  * _mesa_set_enable for example.
@@ -700,7 +719,7 @@ _mesa_get_debug_state(struct gl_context *ctx)
 bool
 _mesa_set_debug_state_int(struct gl_context *ctx, GLenum pname, GLint val)
 {
-   struct gl_debug_state *debug = _mesa_get_debug_state(ctx);
+   struct gl_debug_state *debug = _mesa_lock_debug_state(ctx);
 
if (!debug)
   return false;
@@ -717,6 +736,8 @@ _mesa_set_debug_state_int(struct gl_context *ctx, GLenum 
pname, GLint val)
   break;
}
 
+   _mesa_unlock_debug_state(ctx);
+
return true;
 }
 
@@ -730,9 +751,12 @@ _mesa_get_debug_state_int(struct gl_context *ctx, GLenum 
pname)
struct gl_debug_state *debug;
GLint val;
 
+   mtx_lock(ctx-DebugMutex);
debug = ctx-Debug;
-   if (!debug)
+   if (!debug) {
+  mtx_unlock(ctx-DebugMutex);
   return 0;
+   }
 
switch (pname) {
case GL_DEBUG_OUTPUT:
@@ -757,6 +781,8 @@ _mesa_get_debug_state_int(struct gl_context *ctx, GLenum 
pname)
   break;
}
 
+   mtx_unlock(ctx-DebugMutex);
+
return val;
 }
 
@@ -770,9 +796,12 @@ _mesa_get_debug_state_ptr(struct gl_context *ctx, GLenum 
pname)
struct gl_debug_state *debug;
void *val;
 
+   mtx_lock(ctx-DebugMutex);
debug = ctx-Debug;
-   if (!debug)
+   if (!debug) {
+  mtx_unlock(ctx-DebugMutex);
   return NULL;
+   }
 
switch (pname) {
case GL_DEBUG_CALLBACK_FUNCTION_ARB:
@@ -787,9 +816,49 @@ _mesa_get_debug_state_ptr(struct gl_context *ctx, GLenum 
pname)
   break;
}
 
+   mtx_unlock(ctx-DebugMutex);
+
return val;
 }
 
+/**
+ * Insert a debug message.  The mutex is assumed to be locked, and will be
+ * unlocked by this call.
+ */
+static void
+log_msg_locked_and_unlock(struct gl_context *ctx,
+  enum mesa_debug_source source,
+  enum mesa_debug_type type, GLuint id,
+  enum mesa_debug_severity severity,
+  GLint len, const char *buf)
+{
+   struct gl_debug_state *debug = ctx-Debug;
+
+   if (!debug_is_message_enabled(debug, source, type, id, severity)) {
+  _mesa_unlock_debug_state(ctx);
+  return;
+   }
+
+   if (ctx-Debug-Callback) {
+  GLenum gl_source = debug_source_enums[source];
+  GLenum gl_type = debug_type_enums[type];
+  GLenum gl_severity = debug_severity_enums[severity];
+  GLDEBUGPROC callback = ctx-Debug-Callback;
+  const void *data = ctx-Debug-CallbackData;
+
+  /*
+   * When ctx-Debug-SyncOutput is GL_FALSE, the client is prepared for
+   * unsynchronous calls.  When it is GL_TRUE, we will not spawn threads.
+   * In either case, we can call the callback unlocked.
+   */
+  _mesa_unlock_debug_state(ctx);
+  callback(gl_source, gl_type, id, gl_severity, len, buf, data);
+   }
+   else {
+  debug_log_message(ctx-Debug, source, type, id, severity, len, buf);
+  _mesa_unlock_debug_state(ctx);
+   }
+}
 
 /**
  * Log a client or driver debug message.
@@ -799,24 +868,12 @@ log_msg(struct gl_context *ctx, enum mesa_debug_source 
source,
 enum

[Mesa-dev] [PATCHv3 16/16] i965: enable threaded precompile

2014-08-20 Thread Chia-I Wu
Inherit gl_shader_program and add save/restore functions to save precompile
results in the shader programs.  When DeferLinkProgram is set, we will save
the precompile results instead of uploading them immediately because we may be
on a different thread.

A few other modifications are also needed.  brw_shader_program_precompile_key
is introduced and initialized in NofityLinkShader for we cannot inspect the
context during precompiling.

Signed-off-by: Chia-I Wu o...@lunarg.com
Acked-by: Ian Romanick ian.d.roman...@intel.com
---
 src/mesa/drivers/dri/i965/brw_context.c  |   4 +-
 src/mesa/drivers/dri/i965/brw_fs.cpp |  33 --
 src/mesa/drivers/dri/i965/brw_program.c  |   1 +
 src/mesa/drivers/dri/i965/brw_shader.cpp | 177 ++-
 src/mesa/drivers/dri/i965/brw_shader.h   |  44 
 src/mesa/drivers/dri/i965/brw_vec4_gs.c  |  37 +--
 src/mesa/drivers/dri/i965/brw_vs.c   |  36 +--
 src/mesa/drivers/dri/i965/brw_wm.c   |  23 ++--
 src/mesa/drivers/dri/i965/brw_wm.h   |   5 +-
 9 files changed, 310 insertions(+), 50 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_context.c 
b/src/mesa/drivers/dri/i965/brw_context.c
index b02128c..70e61f7 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -839,8 +839,8 @@ brwCreateContext(gl_api api,
if (INTEL_DEBUG  DEBUG_SHADER_TIME)
   brw_init_shader_time(brw);
 
-   /* brw_shader_precompile is not thread-safe */
-   if (brw-precompile)
+   /* brw_shader_precompile is not thread-safe when debug flags are set */
+   if (brw-precompile  (INTEL_DEBUG || brw-perf_debug))
   ctx-Const.DeferLinkProgram = GL_FALSE;
 
_mesa_compute_version(ctx);
diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp 
b/src/mesa/drivers/dri/i965/brw_fs.cpp
index 5c70f50..393a262 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -3452,6 +3452,8 @@ bool
 brw_fs_precompile(struct gl_context *ctx, struct gl_shader_program *prog)
 {
struct brw_context *brw = brw_context(ctx);
+   const struct brw_shader_program_precompile_key *pre_key =
+  brw_shader_program_get_precompile_key(prog);
struct brw_wm_prog_key key;
 
if (!prog-_LinkedShaders[MESA_SHADER_FRAGMENT])
@@ -3493,7 +3495,7 @@ brw_fs_precompile(struct gl_context *ctx, struct 
gl_shader_program *prog)
}
 
if (fp-Base.InputsRead  VARYING_BIT_POS) {
-  key.drawable_height = ctx-DrawBuffer-Height;
+  key.drawable_height = pre_key-fbo_height;
}
 
key.nr_color_regions = _mesa_bitcount_64(fp-Base.OutputsWritten 
@@ -3501,7 +3503,7 @@ brw_fs_precompile(struct gl_context *ctx, struct 
gl_shader_program *prog)
  BITFIELD64_BIT(FRAG_RESULT_SAMPLE_MASK)));
 
if ((fp-Base.InputsRead  VARYING_BIT_POS) || program_uses_dfdy) {
-  key.render_to_fbo = _mesa_is_user_fbo(ctx-DrawBuffer) ||
+  key.render_to_fbo = pre_key-is_user_fbo ||
   key.nr_color_regions  1;
}
 
@@ -3513,13 +3515,28 @@ brw_fs_precompile(struct gl_context *ctx, struct 
gl_shader_program *prog)
 
key.program_string_id = bfp-id;
 
-   uint32_t old_prog_offset = brw-wm.base.prog_offset;
-   struct brw_wm_prog_data *old_prog_data = brw-wm.prog_data;
+   struct brw_wm_compile c;
 
-   bool success = do_wm_prog(brw, prog, bfp, key);
+   brw_wm_init_compile(brw, prog, bfp, key, c);
+   if (!brw_wm_do_compile(brw, c)) {
+  brw_wm_clear_compile(brw, c);
+  return false;
+   }
+
+   if (brw-ctx.Const.DeferLinkProgram) {
+  brw_shader_program_save_wm_compile(prog, c);
+   }
+   else {
+  uint32_t old_prog_offset = brw-wm.base.prog_offset;
+  struct brw_wm_prog_data *old_prog_data = brw-wm.prog_data;
 
-   brw-wm.base.prog_offset = old_prog_offset;
-   brw-wm.prog_data = old_prog_data;
+  brw_wm_upload_compile(brw, c);
 
-   return success;
+  brw-wm.base.prog_offset = old_prog_offset;
+  brw-wm.prog_data = old_prog_data;
+   }
+
+   brw_wm_clear_compile(brw, c);
+
+   return true;
 }
diff --git a/src/mesa/drivers/dri/i965/brw_program.c 
b/src/mesa/drivers/dri/i965/brw_program.c
index d782b4f..35fd69a 100644
--- a/src/mesa/drivers/dri/i965/brw_program.c
+++ b/src/mesa/drivers/dri/i965/brw_program.c
@@ -259,6 +259,7 @@ void brwInitFragProgFuncs( struct dd_function_table 
*functions )
functions-NewShader = brw_new_shader;
functions-NewShaderProgram = brw_new_shader_program;
functions-LinkShader = brw_link_shader;
+   functions-NotifyLinkShader = brw_notify_link_shader;
 }
 
 void
diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp 
b/src/mesa/drivers/dri/i965/brw_shader.cpp
index 28db29a..29f4a19 100644
--- a/src/mesa/drivers/dri/i965/brw_shader.cpp
+++ b/src/mesa/drivers/dri/i965/brw_shader.cpp
@@ -25,14 +25,52 @@ extern C {
 #include main/macros.h
 #include brw_context.h
 }
+#include brw_shader.h
 #include brw_vs.h
 #include brw_vec4_gs.h
+#include brw_vec4_gs_visitor.h
 #include brw_fs.h
 #include brw_cfg.h

[Mesa-dev] [PATCHv3 04/16] util: move simple_list.h from core to util

2014-08-20 Thread Chia-I Wu
It belongs to util, and we will need it from within util.

Signed-off-by: Chia-I Wu o...@lunarg.com
---
 src/mesa/drivers/dri/i915/i830_texblend.c  |   2 +-
 src/mesa/drivers/dri/i915/intel_syncobj.c  |   2 +-
 src/mesa/drivers/dri/r200/r200_cmdbuf.c|   2 +-
 src/mesa/drivers/dri/r200/r200_context.c   |   3 +-
 src/mesa/drivers/dri/r200/r200_ioctl.h |   2 +-
 src/mesa/drivers/dri/r200/r200_swtcl.c |   2 +-
 src/mesa/drivers/dri/r200/r200_tex.c   |   2 +-
 .../drivers/dri/radeon/radeon_common_context.c |   2 +-
 src/mesa/drivers/dri/radeon/radeon_context.c   |   3 +-
 src/mesa/drivers/dri/radeon/radeon_dma.c   |   2 +-
 src/mesa/drivers/dri/radeon/radeon_ioctl.c |   2 +-
 src/mesa/drivers/dri/radeon/radeon_ioctl.h |   2 +-
 src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c   |   2 +-
 src/mesa/drivers/dri/radeon/radeon_queryobj.c  |   2 +-
 src/mesa/drivers/dri/radeon/radeon_queryobj.h  |   2 +-
 src/mesa/drivers/dri/radeon/radeon_state.c |   2 +-
 src/mesa/drivers/dri/radeon/radeon_swtcl.c |   3 +-
 src/mesa/drivers/dri/radeon/radeon_tex.c   |   2 +-
 src/mesa/main/context.c|   2 +-
 src/mesa/main/enable.c |   2 +-
 src/mesa/main/errors.c |   1 +
 src/mesa/main/light.c  |   2 +-
 src/mesa/main/mtypes.h |   1 -
 src/mesa/main/simple_list.h| 210 -
 src/mesa/program/prog_hash_table.c |   2 +-
 src/mesa/tnl/t_context.c   |   1 +
 src/mesa/tnl/t_rasterpos.c |   2 +-
 src/mesa/tnl/t_vb_light.c  |   2 +-
 src/mesa/tnl/t_vertex_generic.c|   2 +-
 src/mesa/tnl/t_vertex_sse.c|   2 +-
 src/util/simple_list.h | 210 +
 31 files changed, 241 insertions(+), 237 deletions(-)
 delete mode 100644 src/mesa/main/simple_list.h
 create mode 100644 src/util/simple_list.h

diff --git a/src/mesa/drivers/dri/i915/i830_texblend.c 
b/src/mesa/drivers/dri/i915/i830_texblend.c
index 236be59..f55d941 100644
--- a/src/mesa/drivers/dri/i915/i830_texblend.c
+++ b/src/mesa/drivers/dri/i915/i830_texblend.c
@@ -28,9 +28,9 @@
 #include main/glheader.h
 #include main/macros.h
 #include main/mtypes.h
-#include main/simple_list.h
 #include main/enums.h
 #include main/mm.h
+#include util/simple_list.h
 
 #include intel_screen.h
 #include intel_tex.h
diff --git a/src/mesa/drivers/dri/i915/intel_syncobj.c 
b/src/mesa/drivers/dri/i915/intel_syncobj.c
index 9657d9a..95d0b16 100644
--- a/src/mesa/drivers/dri/i915/intel_syncobj.c
+++ b/src/mesa/drivers/dri/i915/intel_syncobj.c
@@ -38,8 +38,8 @@
  * performance bottleneck, though.
  */
 
-#include main/simple_list.h
 #include main/imports.h
+#include util/simple_list.h
 
 #include intel_context.h
 #include intel_batchbuffer.h
diff --git a/src/mesa/drivers/dri/r200/r200_cmdbuf.c 
b/src/mesa/drivers/dri/r200/r200_cmdbuf.c
index 1e6c0d8..13ac5af 100644
--- a/src/mesa/drivers/dri/r200/r200_cmdbuf.c
+++ b/src/mesa/drivers/dri/r200/r200_cmdbuf.c
@@ -35,7 +35,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
SOFTWARE.
 #include main/imports.h
 #include main/macros.h
 #include main/context.h
-#include main/simple_list.h
+#include util/simple_list.h
 
 #include radeon_common.h
 #include r200_context.h
diff --git a/src/mesa/drivers/dri/r200/r200_context.c 
b/src/mesa/drivers/dri/r200/r200_context.c
index 7815c4e..41040a6 100644
--- a/src/mesa/drivers/dri/r200/r200_context.c
+++ b/src/mesa/drivers/dri/r200/r200_context.c
@@ -37,7 +37,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
SOFTWARE.
 #include main/api_arrayelt.h
 #include main/api_exec.h
 #include main/context.h
-#include main/simple_list.h
 #include main/imports.h
 #include main/extensions.h
 #include main/version.h
@@ -50,6 +49,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
SOFTWARE.
 #include tnl/tnl.h
 #include tnl/t_pipeline.h
 
+#include util/simple_list.h
+
 #include drivers/common/driverfuncs.h
 
 #include r200_context.h
diff --git a/src/mesa/drivers/dri/r200/r200_ioctl.h 
b/src/mesa/drivers/dri/r200/r200_ioctl.h
index ab5f822..384787c 100644
--- a/src/mesa/drivers/dri/r200/r200_ioctl.h
+++ b/src/mesa/drivers/dri/r200/r200_ioctl.h
@@ -35,7 +35,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
SOFTWARE.
 #ifndef __R200_IOCTL_H__
 #define __R200_IOCTL_H__
 
-#include main/simple_list.h
+#include util/simple_list.h
 #include radeon_dri.h
 
 #include radeon_bo_gem.h
diff --git a/src/mesa/drivers/dri/r200/r200_swtcl.c 
b/src/mesa/drivers/dri/r200/r200_swtcl.c
index 07c64f8..c324d53 100644
--- a/src/mesa/drivers/dri/r200/r200_swtcl.c
+++ b/src/mesa/drivers/dri/r200/r200_swtcl.c
@@ -39,7 +39,6 @@ WITH THE SOFTWARE

[Mesa-dev] [PATCHv3 08/16] glsl: protect glsl_type with a mutex

2014-08-20 Thread Chia-I Wu
glsl_type has several static hash tables and a static ralloc context.  They
need to be protected by a mutex as they are not thread-safe.

Signed-off-by: Chia-I Wu o...@lunarg.com
Reviewed-by: Brian Paul bri...@vmware.com
Reviewed-by: Ian Romanick ian.d.roman...@intel.com
---
 src/glsl/glsl_types.cpp | 57 +++--
 src/glsl/glsl_types.h   | 15 +
 2 files changed, 62 insertions(+), 10 deletions(-)

diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
index 66e9b13..74ec40f 100644
--- a/src/glsl/glsl_types.cpp
+++ b/src/glsl/glsl_types.cpp
@@ -29,6 +29,7 @@ extern C {
 #include program/hash_table.h
 }
 
+mtx_t glsl_type::mutex = _MTX_INITIALIZER_NP;
 hash_table *glsl_type::array_types = NULL;
 hash_table *glsl_type::record_types = NULL;
 hash_table *glsl_type::interface_types = NULL;
@@ -53,9 +54,14 @@ glsl_type::glsl_type(GLenum gl_type,
vector_elements(vector_elements), matrix_columns(matrix_columns),
length(0)
 {
+   mtx_lock(glsl_type::mutex);
+
init_ralloc_type_ctx();
assert(name != NULL);
this-name = ralloc_strdup(this-mem_ctx, name);
+
+   mtx_unlock(glsl_type::mutex);
+
/* Neither dimension is zero or both dimensions are zero.
 */
assert((vector_elements == 0) == (matrix_columns == 0));
@@ -71,9 +77,14 @@ glsl_type::glsl_type(GLenum gl_type, glsl_base_type 
base_type,
sampler_array(array), sampler_type(type), interface_packing(0),
length(0)
 {
+   mtx_lock(glsl_type::mutex);
+
init_ralloc_type_ctx();
assert(name != NULL);
this-name = ralloc_strdup(this-mem_ctx, name);
+
+   mtx_unlock(glsl_type::mutex);
+
memset( fields, 0, sizeof(fields));
 
if (base_type == GLSL_TYPE_SAMPLER) {
@@ -95,11 +106,14 @@ glsl_type::glsl_type(const glsl_struct_field *fields, 
unsigned num_fields,
 {
unsigned int i;
 
+   mtx_lock(glsl_type::mutex);
+
init_ralloc_type_ctx();
assert(name != NULL);
this-name = ralloc_strdup(this-mem_ctx, name);
this-fields.structure = ralloc_array(this-mem_ctx,
 glsl_struct_field, length);
+
for (i = 0; i  length; i++) {
   this-fields.structure[i].type = fields[i].type;
   this-fields.structure[i].name = ralloc_strdup(this-fields.structure,
@@ -110,6 +124,8 @@ glsl_type::glsl_type(const glsl_struct_field *fields, 
unsigned num_fields,
   this-fields.structure[i].sample = fields[i].sample;
   this-fields.structure[i].matrix_layout = fields[i].matrix_layout;
}
+
+   mtx_unlock(glsl_type::mutex);
 }
 
 glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields,
@@ -123,6 +139,8 @@ glsl_type::glsl_type(const glsl_struct_field *fields, 
unsigned num_fields,
 {
unsigned int i;
 
+   mtx_lock(glsl_type::mutex);
+
init_ralloc_type_ctx();
assert(name != NULL);
this-name = ralloc_strdup(this-mem_ctx, name);
@@ -138,6 +156,8 @@ glsl_type::glsl_type(const glsl_struct_field *fields, 
unsigned num_fields,
   this-fields.structure[i].sample = fields[i].sample;
   this-fields.structure[i].matrix_layout = fields[i].matrix_layout;
}
+
+   mtx_unlock(glsl_type::mutex);
 }
 
 
@@ -285,6 +305,8 @@ const glsl_type *glsl_type::get_scalar_type() const
 void
 _mesa_glsl_release_types(void)
 {
+   mtx_lock(glsl_type::mutex);
+
if (glsl_type::array_types != NULL) {
   hash_table_dtor(glsl_type::array_types);
   glsl_type::array_types = NULL;
@@ -294,6 +316,8 @@ _mesa_glsl_release_types(void)
   hash_table_dtor(glsl_type::record_types);
   glsl_type::record_types = NULL;
}
+
+   mtx_unlock(glsl_type::mutex);
 }
 
 
@@ -316,7 +340,10 @@ glsl_type::glsl_type(const glsl_type *array, unsigned 
length) :
 * NUL.
 */
const unsigned name_length = strlen(array-name) + 10 + 3;
+
+   mtx_lock(glsl_type::mutex);
char *const n = (char *) ralloc_size(this-mem_ctx, name_length);
+   mtx_unlock(glsl_type::mutex);
 
if (length == 0)
   snprintf(n, name_length, %s[], array-name);
@@ -452,12 +479,6 @@ glsl_type::get_instance(unsigned base_type, unsigned rows, 
unsigned columns)
 const glsl_type *
 glsl_type::get_array_instance(const glsl_type *base, unsigned array_size)
 {
-
-   if (array_types == NULL) {
-  array_types = hash_table_ctor(64, hash_table_string_hash,
-   hash_table_string_compare);
-   }
-
/* Generate a name using the base type pointer in the key.  This is
 * done because the name of the base type may not be unique across
 * shaders.  For example, two shaders may have different record types
@@ -466,9 +487,19 @@ glsl_type::get_array_instance(const glsl_type *base, 
unsigned array_size)
char key[128];
snprintf(key, sizeof(key), %p[%u], (void *) base, array_size);
 
+   mtx_lock(glsl_type::mutex);
+
+   if (array_types == NULL) {
+  array_types = hash_table_ctor(64, hash_table_string_hash,
+   hash_table_string_compare);
+   }
+
const

[Mesa-dev] [PATCHv3 12/16] i965: add drirc option multithread_glsl_compiler

2014-08-20 Thread Chia-I Wu
Setting it to a non-zero value N will cause shader compilation to be deferred
to a thread pool.  When N is greater than 1, it indicates the maximum number
of threads in the pool.  When N is 1, the number of threads is up to the
driver (two for i965).

Signed-off-by: Chia-I Wu o...@lunarg.com
Reviewed-by: Ian Romanick ian.d.roman...@intel.com
---
 src/mesa/drivers/dri/common/xmlpool/t_options.h |  4 
 src/mesa/drivers/dri/i965/brw_context.c | 15 +++
 src/mesa/drivers/dri/i965/intel_screen.c|  2 ++
 3 files changed, 21 insertions(+)

diff --git a/src/mesa/drivers/dri/common/xmlpool/t_options.h 
b/src/mesa/drivers/dri/common/xmlpool/t_options.h
index b73a662..7ac0298 100644
--- a/src/mesa/drivers/dri/common/xmlpool/t_options.h
+++ b/src/mesa/drivers/dri/common/xmlpool/t_options.h
@@ -298,6 +298,10 @@ DRI_CONF_OPT_BEGIN_V(texture_heaps,enum,def,0:2) \
DRI_CONF_DESC_END \
 DRI_CONF_OPT_END
 
+#define DRI_CONF_MULTITHREAD_GLSL_COMPILER(def) \
+DRI_CONF_OPT_BEGIN(multithread_glsl_compiler, int, def) \
+DRI_CONF_DESC(en,gettext(Enable multithreading in the GLSL 
compiler)) \
+DRI_CONF_OPT_END
 
 
 /**
diff --git a/src/mesa/drivers/dri/i965/brw_context.c 
b/src/mesa/drivers/dri/i965/brw_context.c
index 216b788..b02128c 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -624,6 +624,17 @@ brw_process_driconf_options(struct brw_context *brw)
 
ctx-Const.AllowGLSLExtensionDirectiveMidShader =
   driQueryOptionb(options, allow_glsl_extension_directive_midshader);
+
+   const int multithread_glsl_compiler =
+  driQueryOptioni(options, multithread_glsl_compiler);
+   if (multithread_glsl_compiler  0) {
+  const int max_threads = (multithread_glsl_compiler  1) ?
+ multithread_glsl_compiler : 2;
+
+  _mesa_enable_glsl_threadpool(ctx, max_threads);
+  ctx-Const.DeferCompileShader = GL_TRUE;
+  ctx-Const.DeferLinkProgram = GL_TRUE;
+   }
 }
 
 GLboolean
@@ -828,6 +839,10 @@ brwCreateContext(gl_api api,
if (INTEL_DEBUG  DEBUG_SHADER_TIME)
   brw_init_shader_time(brw);
 
+   /* brw_shader_precompile is not thread-safe */
+   if (brw-precompile)
+  ctx-Const.DeferLinkProgram = GL_FALSE;
+
_mesa_compute_version(ctx);
 
_mesa_initialize_dispatch_tables(ctx);
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 9e743ee..95850c1 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -48,6 +48,8 @@ static const __DRIconfigOptionsExtension brw_config_options = 
{
 DRI_CONF_BEGIN
DRI_CONF_SECTION_PERFORMANCE
   DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC)
+  DRI_CONF_MULTITHREAD_GLSL_COMPILER(0)
+
   /* Options correspond to DRI_CONF_BO_REUSE_DISABLED,
* DRI_CONF_BO_REUSE_ALL
*/
-- 
2.0.0.rc2

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


[Mesa-dev] [PATCHv3 14/16] i965: refactor do_gs_prog

2014-08-20 Thread Chia-I Wu
Split do_gs_prog into

  brw_gs_init_compile
  brw_gs_do_compile
  brw_gs_upload_compile
  brw_gs_clear_complile

Signed-off-by: Chia-I Wu o...@lunarg.com
Acked-by: Ian Romanick ian.d.roman...@intel.com
---
 src/mesa/drivers/dri/i965/brw_vec4_gs.c | 161 
 1 file changed, 102 insertions(+), 59 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_vec4_gs.c 
b/src/mesa/drivers/dri/i965/brw_vec4_gs.c
index 5b2ed51..04407b8 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_gs.c
+++ b/src/mesa/drivers/dri/i965/brw_vec4_gs.c
@@ -33,22 +33,29 @@
 #include brw_state.h
 
 
-static bool
-do_gs_prog(struct brw_context *brw,
-   struct gl_shader_program *prog,
-   struct brw_geometry_program *gp,
-   struct brw_gs_prog_key *key)
+static void
+brw_gs_init_compile(struct brw_context *brw,
+struct gl_shader_program *prog,
+struct brw_geometry_program *gp,
+const struct brw_gs_prog_key *key,
+struct brw_gs_compile *c)
 {
-   struct brw_stage_state *stage_state = brw-gs.base;
-   struct brw_gs_compile c;
-   memset(c, 0, sizeof(c));
-   c.key = *key;
-   c.gp = gp;
+   memset(c, 0, sizeof(*c));
 
-   c.prog_data.include_primitive_id =
-  (gp-program.Base.InputsRead  VARYING_BIT_PRIMITIVE_ID) != 0;
+   c-key = *key;
+   c-gp = gp;
+   c-base.shader_prog = prog;
+   c-base.mem_ctx = ralloc_context(NULL);
+}
 
-   c.prog_data.invocations = gp-program.Invocations;
+static bool
+brw_gs_do_compile(struct brw_context *brw,
+  struct brw_gs_compile *c)
+{
+   c-prog_data.include_primitive_id =
+  (c-gp-program.Base.InputsRead  VARYING_BIT_PRIMITIVE_ID) != 0;
+
+   c-prog_data.invocations = c-gp-program.Invocations;
 
/* Allocate the references to the uniforms that will end up in the
 * prog_data associated with the compiled program, and which will be freed
@@ -58,34 +65,37 @@ do_gs_prog(struct brw_context *brw,
 * padding around uniform values below vec4 size, so the worst case is that
 * every uniform is a float which gets padded to the size of a vec4.
 */
-   struct gl_shader *gs = prog-_LinkedShaders[MESA_SHADER_GEOMETRY];
+   struct gl_shader *gs =
+  c-base.shader_prog-_LinkedShaders[MESA_SHADER_GEOMETRY];
int param_count = gs-num_uniform_components * 4;
 
/* We also upload clip plane data as uniforms */
param_count += MAX_CLIP_PLANES * 4;
 
-   c.prog_data.base.base.param =
+   c-prog_data.base.base.param =
   rzalloc_array(NULL, const gl_constant_value *, param_count);
-   c.prog_data.base.base.pull_param =
+   c-prog_data.base.base.pull_param =
   rzalloc_array(NULL, const gl_constant_value *, param_count);
/* Setting nr_params here NOT to the size of the param and pull_param
 * arrays, but to the number of uniform components vec4_visitor
 * needs. vec4_visitor::setup_uniforms() will set it back to a proper value.
 */
-   c.prog_data.base.base.nr_params = ALIGN(param_count, 4) / 4 + 
gs-num_samplers;
+   c-prog_data.base.base.nr_params =
+  ALIGN(param_count, 4) / 4 + gs-num_samplers;
 
-   if (gp-program.OutputType == GL_POINTS) {
+   if (c-gp-program.OutputType == GL_POINTS) {
   /* When the output type is points, the geometry shader may output data
* to multiple streams, and EndPrimitive() has no effect.  So we
* configure the hardware to interpret the control data as stream ID.
*/
-  c.prog_data.control_data_format = GEN7_GS_CONTROL_DATA_FORMAT_GSCTL_SID;
+  c-prog_data.control_data_format =
+ GEN7_GS_CONTROL_DATA_FORMAT_GSCTL_SID;
 
   /* We only have to emit control bits if we are using streams */
-  if (prog-Geom.UsesStreams)
- c.control_data_bits_per_vertex = 2;
+  if (c-base.shader_prog-Geom.UsesStreams)
+ c-control_data_bits_per_vertex = 2;
   else
- c.control_data_bits_per_vertex = 0;
+ c-control_data_bits_per_vertex = 0;
} else {
   /* When the output type is triangle_strip or line_strip, EndPrimitive()
* may be used to terminate the current strip and start a new one
@@ -93,32 +103,34 @@ do_gs_prog(struct brw_context *brw,
* streams is not supported.  So we configure the hardware to interpret
* the control data as EndPrimitive information (a.k.a. cut bits).
*/
-  c.prog_data.control_data_format = GEN7_GS_CONTROL_DATA_FORMAT_GSCTL_CUT;
+  c-prog_data.control_data_format =
+ GEN7_GS_CONTROL_DATA_FORMAT_GSCTL_CUT;
 
   /* We only need to output control data if the shader actually calls
* EndPrimitive().
*/
-  c.control_data_bits_per_vertex = gp-program.UsesEndPrimitive ? 1 : 0;
+  c-control_data_bits_per_vertex =
+ c-gp-program.UsesEndPrimitive ? 1 : 0;
}
-   c.control_data_header_size_bits =
-  gp-program.VerticesOut * c.control_data_bits_per_vertex;
+   c-control_data_header_size_bits =
+  c-gp

[Mesa-dev] [PATCHv3 15/16] i965: refactor do_wm_prog

2014-08-20 Thread Chia-I Wu
Split do_wm_prog into

  brw_wm_init_compile
  brw_wm_do_compile
  brw_wm_upload_compile
  brw_wm_clear_complile

Add struct brw_wm_compile to be passed around them.

Signed-off-by: Chia-I Wu o...@lunarg.com
Acked-by: Ian Romanick ian.d.roman...@intel.com
---
 src/mesa/drivers/dri/i965/brw_wm.c | 116 -
 src/mesa/drivers/dri/i965/brw_wm.h |  30 ++
 2 files changed, 106 insertions(+), 40 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_wm.c 
b/src/mesa/drivers/dri/i965/brw_wm.c
index 2e3cd4b..329e82c 100644
--- a/src/mesa/drivers/dri/i965/brw_wm.c
+++ b/src/mesa/drivers/dri/i965/brw_wm.c
@@ -135,27 +135,30 @@ brw_wm_prog_data_compare(const void *in_a, const void 
*in_b)
return true;
 }
 
-/**
- * All Mesa program - GPU code generation goes through this function.
- * Depending on the instructions used (i.e. flow control instructions)
- * we'll use one of two code generators.
- */
-bool do_wm_prog(struct brw_context *brw,
-   struct gl_shader_program *prog,
-   struct brw_fragment_program *fp,
-   struct brw_wm_prog_key *key)
+void
+brw_wm_init_compile(struct brw_context *brw,
+struct gl_shader_program *prog,
+struct brw_fragment_program *fp,
+const struct brw_wm_prog_key *key,
+struct brw_wm_compile *c)
+{
+   memset(c, 0, sizeof(*c));
+
+   c-shader_prog = prog;
+   c-fp = fp;
+   c-key = key;
+   c-mem_ctx = ralloc_context(NULL);
+}
+
+bool
+brw_wm_do_compile(struct brw_context *brw,
+  struct brw_wm_compile *c)
 {
struct gl_context *ctx = brw-ctx;
-   void *mem_ctx = ralloc_context(NULL);
-   struct brw_wm_prog_data prog_data;
-   const GLuint *program;
struct gl_shader *fs = NULL;
-   GLuint program_size;
 
-   if (prog)
-  fs = prog-_LinkedShaders[MESA_SHADER_FRAGMENT];
-
-   memset(prog_data, 0, sizeof(prog_data));
+   if (c-shader_prog)
+  fs = c-shader_prog-_LinkedShaders[MESA_SHADER_FRAGMENT];
 
/* Allocate the references to the uniforms that will end up in the
 * prog_data associated with the compiled program, and which will be freed
@@ -165,43 +168,76 @@ bool do_wm_prog(struct brw_context *brw,
if (fs) {
   param_count = fs-num_uniform_components;
} else {
-  param_count = fp-program.Base.Parameters-NumParameters * 4;
+  param_count = c-fp-program.Base.Parameters-NumParameters * 4;
}
/* The backend also sometimes adds params for texture size. */
param_count += 2 * 
ctx-Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits;
-   prog_data.base.param =
+   c-prog_data.base.param =
   rzalloc_array(NULL, const gl_constant_value *, param_count);
-   prog_data.base.pull_param =
+   c-prog_data.base.pull_param =
   rzalloc_array(NULL, const gl_constant_value *, param_count);
-   prog_data.base.nr_params = param_count;
+   c-prog_data.base.nr_params = param_count;
 
-   prog_data.barycentric_interp_modes =
-  brw_compute_barycentric_interp_modes(brw, key-flat_shade,
-   key-persample_shading,
-   fp-program);
+   c-prog_data.barycentric_interp_modes =
+  brw_compute_barycentric_interp_modes(brw, c-key-flat_shade,
+   c-key-persample_shading,
+   c-fp-program);
 
-   program = brw_wm_fs_emit(brw, mem_ctx, key, prog_data,
-fp-program, prog, program_size);
-   if (program == NULL) {
-  ralloc_free(mem_ctx);
+   c-program = brw_wm_fs_emit(brw, c-mem_ctx, c-key, c-prog_data,
+   c-fp-program, c-shader_prog,
+   c-program_size);
+   if (c-program == NULL)
   return false;
-   }
-
-   if (prog_data.total_scratch) {
-  brw_get_scratch_bo(brw, brw-wm.base.scratch_bo,
-prog_data.total_scratch * brw-max_wm_threads);
-   }
 
if (unlikely(INTEL_DEBUG  DEBUG_WM))
   fprintf(stderr, \n);
 
+   return true;
+}
+
+void
+brw_wm_upload_compile(struct brw_context *brw,
+  const struct brw_wm_compile *c)
+{
+   if (c-prog_data.total_scratch) {
+  brw_get_scratch_bo(brw, brw-wm.base.scratch_bo,
+ c-prog_data.total_scratch * brw-max_wm_threads);
+   }
+
brw_upload_cache(brw-cache, BRW_WM_PROG,
-   key, sizeof(struct brw_wm_prog_key),
-   program, program_size,
-   prog_data, sizeof(prog_data),
-   brw-wm.base.prog_offset, brw-wm.prog_data);
+c-key, sizeof(struct brw_wm_prog_key),
+c-program, c-program_size,
+c-prog_data, sizeof(c-prog_data),
+brw-wm.base.prog_offset, brw-wm.prog_data);
+}
+
+void
+brw_wm_clear_compile(struct brw_context *brw,
+ struct brw_wm_compile *c

[Mesa-dev] [PATCHv3 09/16] glsl: integrate with the singleton thread pool

2014-08-20 Thread Chia-I Wu
The singleton thread pool will be used by contexts to queue compilation tasks.
We need to control its lieftime from the compiler.

Signed-off-by: Chia-I Wu o...@lunarg.com
---
 src/glsl/glsl_parser_extras.cpp | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index b17cdb1..9342908 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -32,6 +32,7 @@ extern C {
 }
 
 #include util/ralloc.h
+#include util/threadpool.h
 #include ast.h
 #include glsl_parser_extras.h
 #include glsl_parser.h
@@ -1626,6 +1627,8 @@ extern C {
 void
 _mesa_destroy_shader_compiler(void)
 {
+   _mesa_threadpool_destroy_singleton();
+
_mesa_destroy_shader_compiler_caches();
 
_mesa_glsl_release_types();
@@ -1639,6 +1642,7 @@ _mesa_destroy_shader_compiler(void)
 void
 _mesa_destroy_shader_compiler_caches(void)
 {
+   _mesa_threadpool_wait_singleton();
_mesa_glsl_release_builtin_functions();
 }
 
-- 
2.0.0.rc2

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


[Mesa-dev] [PATCHv3 01/16] util: add _mesa_strtod and _mesa_strtof

2014-08-20 Thread Chia-I Wu
Both core mesa and glsl have their own wrappers for strtof_l.  Merge and move
them to util/.  They are compiled with a C++ compiler so that we can make them
thread-safe in a following commit.

Signed-off-by: Chia-I Wu o...@lunarg.com
---
 src/glsl/Makefile.sources|  3 +-
 src/glsl/glsl_lexer.ll   | 12 +++---
 src/glsl/s_expression.cpp|  2 +-
 src/glsl/s_expression.h  |  2 +-
 src/glsl/strtod.c| 79 ---
 src/glsl/strtod.h| 46 ---
 src/mesa/main/imports.c  | 19 --
 src/mesa/main/imports.h  |  3 --
 src/mesa/program/program_lexer.l |  1 +
 src/util/Makefile.sources|  3 +-
 src/util/strtod.cpp  | 81 
 src/util/strtod.h| 46 +++
 12 files changed, 139 insertions(+), 158 deletions(-)
 delete mode 100644 src/glsl/strtod.c
 delete mode 100644 src/glsl/strtod.h
 create mode 100644 src/util/strtod.cpp
 create mode 100644 src/util/strtod.h

diff --git a/src/glsl/Makefile.sources b/src/glsl/Makefile.sources
index 2131dda..472ad89 100644
--- a/src/glsl/Makefile.sources
+++ b/src/glsl/Makefile.sources
@@ -101,8 +101,7 @@ LIBGLSL_FILES = \
$(GLSL_SRCDIR)/opt_swizzle_swizzle.cpp \
$(GLSL_SRCDIR)/opt_tree_grafting.cpp \
$(GLSL_SRCDIR)/opt_vectorize.cpp \
-   $(GLSL_SRCDIR)/s_expression.cpp \
-   $(GLSL_SRCDIR)/strtod.c
+   $(GLSL_SRCDIR)/s_expression.cpp
 
 # glsl_compiler
 
diff --git a/src/glsl/glsl_lexer.ll b/src/glsl/glsl_lexer.ll
index b7c4aad..ed2f26d 100644
--- a/src/glsl/glsl_lexer.ll
+++ b/src/glsl/glsl_lexer.ll
@@ -23,7 +23,7 @@
  */
 #include ctype.h
 #include limits.h
-#include strtod.h
+#include util/strtod.h
 #include ast.h
 #include glsl_parser_extras.h
 #include glsl_parser.h
@@ -448,23 +448,23 @@ layout{
}
 
 [0-9]+\.[0-9]+([eE][+-]?[0-9]+)?[fF]?  {
-   yylval-real = glsl_strtof(yytext, NULL);
+   yylval-real = _mesa_strtof(yytext, NULL);
return FLOATCONSTANT;
}
 \.[0-9]+([eE][+-]?[0-9]+)?[fF]?{
-   yylval-real = glsl_strtof(yytext, NULL);
+   yylval-real = _mesa_strtof(yytext, NULL);
return FLOATCONSTANT;
}
 [0-9]+\.([eE][+-]?[0-9]+)?[fF]?{
-   yylval-real = glsl_strtof(yytext, NULL);
+   yylval-real = _mesa_strtof(yytext, NULL);
return FLOATCONSTANT;
}
 [0-9]+[eE][+-]?[0-9]+[fF]? {
-   yylval-real = glsl_strtof(yytext, NULL);
+   yylval-real = _mesa_strtof(yytext, NULL);
return FLOATCONSTANT;
}
 [0-9]+[fF] {
-   yylval-real = glsl_strtof(yytext, NULL);
+   yylval-real = _mesa_strtof(yytext, NULL);
return FLOATCONSTANT;
}
 
diff --git a/src/glsl/s_expression.cpp b/src/glsl/s_expression.cpp
index 1a28e1d..2928a4d 100644
--- a/src/glsl/s_expression.cpp
+++ b/src/glsl/s_expression.cpp
@@ -73,7 +73,7 @@ read_atom(void *ctx, const char *src, char *symbol_buffer)
} else {
   // Check if the atom is a number.
   char *float_end = NULL;
-  float f = glsl_strtof(src, float_end);
+  float f = _mesa_strtof(src, float_end);
   if (float_end != src) {
  char *int_end = NULL;
  int i = strtol(src, int_end, 10);
diff --git a/src/glsl/s_expression.h b/src/glsl/s_expression.h
index 642af19..1d47535 100644
--- a/src/glsl/s_expression.h
+++ b/src/glsl/s_expression.h
@@ -27,7 +27,7 @@
 #define S_EXPRESSION_H
 
 #include main/core.h /* for Elements */
-#include strtod.h
+#include util/strtod.h
 #include list.h
 
 /* Type-safe downcasting macros (also safe to pass NULL) */
diff --git a/src/glsl/strtod.c b/src/glsl/strtod.c
deleted file mode 100644
index 5d4346b..000
--- a/src/glsl/strtod.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright 2010 VMware, Inc.
- * All Rights Reserved.
- *
- * 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, sub license, 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

[Mesa-dev] [PATCHv3 00/16] multithread shader compiler

2014-08-20 Thread Chia-I Wu
Hi,

This is v3 of the series.  It should have all the changes I promised to fix.
There are some new or splitted patches because _mesa_strtof, simple_list, and
thread pool are now moved to src/util/.  To summarize,

Patch 1-3 merge mesa and glsl strtof wrappers and moves them to src/util/.
They go on to clean up the #ifdef hell and make the wrappers thread-safe.

Patch 4-6 add a generic thread pool to src/util/.  Patch 4 moves simple_list.h
from core to util because the thread pool needs it.

Patch 7-11 fixe thread safety issues in the frontend compiler and add the
infrastructure for multithread compilation to the core.

Patch 12-16 fix i965 and add the drirc option to enable multithread compiler.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCHv3 06/16] util: allow the thread pool to be used as a singleton

2014-08-20 Thread Chia-I Wu
To have a real control over the number of driver threads, we almost never want
more than a single thread pool.

Signed-off-by: Chia-I Wu o...@lunarg.com
Reviewed-by: Brian Paul bri...@vmware.com
Reviewed-by: Ian Romanick ian.d.roman...@intel.com

v2: split glsl changes to another commit
---
 src/util/threadpool.c | 72 +++
 src/util/threadpool.h |  9 +++
 2 files changed, 81 insertions(+)

diff --git a/src/util/threadpool.c b/src/util/threadpool.c
index 224f411..9dc91f9 100644
--- a/src/util/threadpool.c
+++ b/src/util/threadpool.c
@@ -55,6 +55,7 @@ struct _mesa_threadpool_task {
 struct _mesa_threadpool {
mtx_t mutex;
int refcnt;
+   bool shutdown;
 
enum _mesa_threadpool_control thread_control;
thrd_t *threads;
@@ -168,6 +169,12 @@ _mesa_threadpool_queue_task(struct _mesa_threadpool *pool,
 
mtx_lock(pool-mutex);
 
+   if (unlikely(pool-shutdown)) {
+  mtx_unlock(pool-mutex);
+  free(task);
+  return NULL;
+   }
+
/* someone is joining with the threads */
while (unlikely(pool-thread_control != MESA_THREADPOOL_NORMAL))
   cnd_wait(pool-thread_joined, pool-mutex);
@@ -379,6 +386,17 @@ _mesa_threadpool_join(struct _mesa_threadpool *pool, bool 
graceful)
 }
 
 /**
+ * After this call, no task can be queued.
+ */
+static void
+_mesa_threadpool_set_shutdown(struct _mesa_threadpool *pool)
+{
+   mtx_lock(pool-mutex);
+   pool-shutdown = true;
+   mtx_unlock(pool-mutex);
+}
+
+/**
  * Decrease the reference count.  Destroy \p pool when the reference count
  * reaches zero.
  */
@@ -474,3 +492,57 @@ _mesa_threadpool_create(int max_threads)
 
return pool;
 }
+
+static mtx_t threadpool_lock = _MTX_INITIALIZER_NP;
+static struct _mesa_threadpool *threadpool;
+
+/**
+ * Get the singleton thread pool.  \p max_threads is honored only by the first
+ * call to this function.
+ */
+struct _mesa_threadpool *
+_mesa_threadpool_get_singleton(int max_threads)
+{
+   mtx_lock(threadpool_lock);
+   if (!threadpool)
+  threadpool = _mesa_threadpool_create(max_threads);
+   if (threadpool)
+  _mesa_threadpool_ref(threadpool);
+   mtx_unlock(threadpool_lock);
+
+   return threadpool;
+}
+
+/**
+ * Wait until all tasks are completed and threads are joined.
+ */
+void
+_mesa_threadpool_wait_singleton(void)
+{
+   mtx_lock(threadpool_lock);
+   if (threadpool)
+  _mesa_threadpool_join(threadpool, true);
+   mtx_unlock(threadpool_lock);
+}
+
+/**
+ * Destroy the singleton thread pool.
+ */
+void
+_mesa_threadpool_destroy_singleton(void)
+{
+   mtx_lock(threadpool_lock);
+   if (threadpool) {
+  /*
+   * No new task is allowed since this point.  But whoever owns references
+   * to the pool can still complete tasks that have been queued (which
+   * will simply destroy the tasks as all tasks are marked cancelled).
+   */
+  _mesa_threadpool_set_shutdown(threadpool);
+
+  _mesa_threadpool_join(threadpool, false);
+  _mesa_threadpool_unref(threadpool);
+  threadpool = NULL;
+   }
+   mtx_unlock(threadpool_lock);
+}
diff --git a/src/util/threadpool.h b/src/util/threadpool.h
index 48e4a47..aeda9d3 100644
--- a/src/util/threadpool.h
+++ b/src/util/threadpool.h
@@ -60,6 +60,15 @@ bool
 _mesa_threadpool_complete_task(struct _mesa_threadpool *pool,
struct _mesa_threadpool_task *task);
 
+struct _mesa_threadpool *
+_mesa_threadpool_get_singleton(int max_threads);
+
+void
+_mesa_threadpool_wait_singleton(void);
+
+void
+_mesa_threadpool_destroy_singleton(void);
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.0.0.rc2

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


[Mesa-dev] [PATCHv3 13/16] i965: refactor do_vs_prog

2014-08-20 Thread Chia-I Wu
Split do_vs_prog into

  brw_vs_init_compile
  brw_vs_do_compile
  brw_vs_upload_compile
  brw_vs_clear_complile

Signed-off-by: Chia-I Wu o...@lunarg.com
Acked-by: Ian Romanick ian.d.roman...@intel.com
---
 src/mesa/drivers/dri/i965/brw_vec4.h |   6 ++
 src/mesa/drivers/dri/i965/brw_vs.c   | 121 ++-
 src/mesa/drivers/dri/i965/brw_vs.h   |   1 +
 3 files changed, 83 insertions(+), 45 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_vec4.h 
b/src/mesa/drivers/dri/i965/brw_vec4.h
index f0239cb..f0e9f10 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4.h
+++ b/src/mesa/drivers/dri/i965/brw_vec4.h
@@ -47,6 +47,12 @@ extern C {
 
 struct brw_vec4_compile {
GLuint last_scratch; /** measured in 32-byte (register size) units */
+
+   struct gl_shader_program *shader_prog;
+
+   void *mem_ctx;
+   const unsigned *program;
+   unsigned program_size;
 };
 
 
diff --git a/src/mesa/drivers/dri/i965/brw_vs.c 
b/src/mesa/drivers/dri/i965/brw_vs.c
index 4574c3e..8e3dcf4 100644
--- a/src/mesa/drivers/dri/i965/brw_vs.c
+++ b/src/mesa/drivers/dri/i965/brw_vs.c
@@ -187,31 +187,31 @@ brw_vs_prog_data_compare(const void *in_a, const void 
*in_b)
return true;
 }
 
-static bool
-do_vs_prog(struct brw_context *brw,
-  struct gl_shader_program *prog,
-  struct brw_vertex_program *vp,
-  struct brw_vs_prog_key *key)
+static void
+brw_vs_init_compile(struct brw_context *brw,
+struct gl_shader_program *prog,
+struct brw_vertex_program *vp,
+const struct brw_vs_prog_key *key,
+struct brw_vs_compile *c)
 {
-   GLuint program_size;
-   const GLuint *program;
-   struct brw_vs_compile c;
-   struct brw_vs_prog_data prog_data;
-   struct brw_stage_prog_data *stage_prog_data = prog_data.base.base;
-   void *mem_ctx;
-   int i;
-   struct gl_shader *vs = NULL;
-
-   if (prog)
-  vs = prog-_LinkedShaders[MESA_SHADER_VERTEX];
+   memset(c, 0, sizeof(*c));
 
-   memset(c, 0, sizeof(c));
-   memcpy(c.key, key, sizeof(*key));
-   memset(prog_data, 0, sizeof(prog_data));
+   memcpy(c-key, key, sizeof(*key));
+   c-vp = vp;
+   c-base.shader_prog = prog;
+   c-base.mem_ctx = ralloc_context(NULL);
+}
 
-   mem_ctx = ralloc_context(NULL);
+static bool
+brw_vs_do_compile(struct brw_context *brw,
+  struct brw_vs_compile *c)
+{
+   struct brw_stage_prog_data *stage_prog_data = c-prog_data.base.base;
+   struct gl_shader *vs = NULL;
+   int i;
 
-   c.vp = vp;
+   if (c-base.shader_prog)
+  vs = c-base.shader_prog-_LinkedShaders[MESA_SHADER_VERTEX];
 
/* Allocate the references to the uniforms that will end up in the
 * prog_data associated with the compiled program, and which will be freed
@@ -226,12 +226,12 @@ do_vs_prog(struct brw_context *brw,
   param_count = vs-num_uniform_components * 4;
 
} else {
-  param_count = vp-program.Base.Parameters-NumParameters * 4;
+  param_count = c-vp-program.Base.Parameters-NumParameters * 4;
}
/* vec4_visitor::setup_uniform_clipplane_values() also uploads user clip
 * planes as uniforms.
 */
-   param_count += c.key.base.nr_userclip_plane_consts * 4;
+   param_count += c-key.base.nr_userclip_plane_consts * 4;
 
stage_prog_data-param =
   rzalloc_array(NULL, const gl_constant_value *, param_count);
@@ -247,12 +247,12 @@ do_vs_prog(struct brw_context *brw,
   stage_prog_data-nr_params += vs-num_samplers;
}
 
-   GLbitfield64 outputs_written = vp-program.Base.OutputsWritten;
-   prog_data.inputs_read = vp-program.Base.InputsRead;
+   GLbitfield64 outputs_written = c-vp-program.Base.OutputsWritten;
+   c-prog_data.inputs_read = c-vp-program.Base.InputsRead;
 
-   if (c.key.copy_edgeflag) {
+   if (c-key.copy_edgeflag) {
   outputs_written |= BITFIELD64_BIT(VARYING_SLOT_EDGE);
-  prog_data.inputs_read |= VERT_BIT_EDGEFLAG;
+  c-prog_data.inputs_read |= VERT_BIT_EDGEFLAG;
}
 
if (brw-gen  6) {
@@ -263,7 +263,7 @@ do_vs_prog(struct brw_context *brw,
* coords, which would be a pain to handle.
*/
   for (i = 0; i  8; i++) {
- if (c.key.point_coord_replace  (1  i))
+ if (c-key.point_coord_replace  (1  i))
 outputs_written |= BITFIELD64_BIT(VARYING_SLOT_TEX0 + i);
   }
 
@@ -278,45 +278,76 @@ do_vs_prog(struct brw_context *brw,
 * distance varying slots whenever clipping is enabled, even if the vertex
 * shader doesn't write to gl_ClipDistance.
 */
-   if (c.key.base.userclip_active) {
+   if (c-key.base.userclip_active) {
   outputs_written |= BITFIELD64_BIT(VARYING_SLOT_CLIP_DIST0);
   outputs_written |= BITFIELD64_BIT(VARYING_SLOT_CLIP_DIST1);
}
 
-   brw_compute_vue_map(brw, prog_data.base.vue_map, outputs_written);
+   brw_compute_vue_map(brw, c-prog_data.base.vue_map, outputs_written);
 
if (0) {
-  _mesa_fprint_program_opt(stderr, c.vp-program.Base, PROG_PRINT_DEBUG

Re: [Mesa-dev] [PATCHv3 11/16] mesa: add infrastructure for threaded shader compilation

2014-08-20 Thread Chia-I Wu
On Thu, Aug 21, 2014 at 12:40 AM, Fredrik Höglund fred...@kde.org wrote:
 On Wednesday 20 August 2014, Chia-I Wu wrote:
 Add _mesa_enable_glsl_threadpool to enable the thread pool for a context, and
 add ctx-Const.DeferCompileShader and ctx-Const.DeferLinkProgram to
 fine-control what gets threaded.

 Setting DeferCompileShader to true will make _mesa_glsl_compile_shader be
 executed in a worker thread.  The function is thread-safe so there is no
 restriction on DeferCompileShader.

 Setting DeferLinkProgram to true will make _mesa_glsl_link_shader be executed
 in a worker thread.  The function is thread-safe only when certain driver
 functions (as documented in struct gl_constants) are thread-safe.  It is
 drivers' responsibility to fix those driver functions before setting
 DeferLinkProgram.

 When DeferLinkProgram is set, drivers are not supposed to inspect the context
 in their LinkShader callbacks.  Instead, NotifyLinkShader is added.  Drivers
 should inspect the context in NotifyLinkShader and save what they need for
 LinkShader in gl_shader_program.

 As a final note, most applications will not benefit from threaded shader
 compilation because they check GL_COMPILE_STATUS/GL_LINK_STATUS immediately,
 giving the worker threads no time to do their jobs.  A possible improvement 
 is
 to split LinkShader into two parts: the first part links and error checks
 while the second part optimizes and generates the machine code.  With the
 split, we can always defer the second part to the thread pool.

 It looks like _mesa_create_shader_program() needs a bit of work since
 it also checks the compile status immediately after compiling the shader.
It is left out in this series because I have no real-world app to
measure the time difference.  I also want to keep this series simple.

To support it, it should be possible to have a deferred function that
combines deferred_compile_shader and deferred_link_program, and delete
the shader afterward.



 Fredrik




-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCHv3 05/16] util: add a generic thread pool data structure

2014-08-20 Thread Chia-I Wu
On Thu, Aug 21, 2014 at 9:31 AM, Matt Turner matts...@gmail.com wrote:
 On Tue, Aug 19, 2014 at 11:40 PM, Chia-I Wu olva...@gmail.com wrote:
 It can be used to implement, for example, threaded glCompileShader and
 glLinkProgram.  Two basic tests are included to verify the basic functions,
 and to give us some confidence about its thread-safety.

 v2: allow tasks to complete other tasks

 Signed-off-by: Chia-I Wu o...@lunarg.com
 Reviewed-by: Brian Paul bri...@vmware.com

 v3: move to src/util/ and mention the tests
 ---
  configure.ac  |   3 +-
  src/util/Makefile.am  |   5 +-
  src/util/Makefile.sources |   3 +-
  src/util/tests/threadpool/Makefile.am |  36 ++
  src/util/tests/threadpool/threadpool_test.cpp | 137 
  src/util/threadpool.c | 476 
 ++
  src/util/threadpool.h |  67 
  7 files changed, 724 insertions(+), 3 deletions(-)
  create mode 100644 src/util/tests/threadpool/Makefile.am
  create mode 100644 src/util/tests/threadpool/threadpool_test.cpp
  create mode 100644 src/util/threadpool.c
  create mode 100644 src/util/threadpool.h

 diff --git a/configure.ac b/configure.ac
 index 57e9f7d..2f7268f 100644
 --- a/configure.ac
 +++ b/configure.ac
 @@ -2261,7 +2261,8 @@ AC_CONFIG_FILES([Makefile
 src/mesa/drivers/x11/Makefile
 src/mesa/main/tests/Makefile
 src/util/Makefile
 -   src/util/tests/hash_table/Makefile])
 +   src/util/tests/hash_table/Makefile
 +   src/util/tests/threadpool/Makefile])

  dnl Sort the dirs alphabetically
  GALLIUM_TARGET_DIRS=`echo $GALLIUM_TARGET_DIRS|tr   \n|sort -u|tr \n 
  `
 diff --git a/src/util/Makefile.am b/src/util/Makefile.am
 index 4733a1a..da6815e 100644
 --- a/src/util/Makefile.am
 +++ b/src/util/Makefile.am
 @@ -19,7 +19,7 @@
  # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 DEALINGS
  # IN THE SOFTWARE.

 -SUBDIRS = . tests/hash_table
 +SUBDIRS = . tests/hash_table tests/threadpool

  include Makefile.sources

 @@ -34,6 +34,9 @@ libmesautil_la_SOURCES = \
 $(MESA_UTIL_FILES) \
 $(MESA_UTIL_GENERATED_FILES)

 +libmesautil_la_LIBADD = \
 +   $(PTHREAD_LIBS)

 You want to link the test programs with pthreads, not the convenience
 library. Add PTHREAD_CFLAGS to the target's CFLAGS, and likewise for
 PTHREAD_LIBS (which it looks like you're doing below, so throw this
 hunk out?)
I think it can be thrown out.  I added $(PTHREAD_LIBS) to the
convenience library so that all targets would be automatically linked
with pthread.  But since this is a base utility library, and only
those use thread pool would need pthread, I can add pthread to all GL
targets (which should already be the case).


 +
  BUILT_SOURCES = $(MESA_UTIL_GENERATED_FILES)
  CLEANFILES = $(BUILT_SOURCES)

 diff --git a/src/util/Makefile.sources b/src/util/Makefile.sources
 index 86466dc..65f98f7 100644
 --- a/src/util/Makefile.sources
 +++ b/src/util/Makefile.sources
 @@ -1,7 +1,8 @@
  MESA_UTIL_FILES := \
 hash_table.c\
 ralloc.c \
 -   strtod.cpp
 +   strtod.cpp \
 +   threadpool.c

  MESA_UTIL_GENERATED_FILES = \
 format_srgb.c
 diff --git a/src/util/tests/threadpool/Makefile.am 
 b/src/util/tests/threadpool/Makefile.am
 new file mode 100644
 index 000..2aa010c
 --- /dev/null
 +++ b/src/util/tests/threadpool/Makefile.am
 @@ -0,0 +1,36 @@
 +# Copyright © 2009 Intel Corporation

 Seems wrong.

 +#
 +#  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
 +#  on the rights to use, copy, modify, merge, publish, distribute, sub
 +#  license, 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 NON-INFRINGEMENT.  IN NO EVENT SHALL
 +#  ADAM JACKSON BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER

 Adam Jackson?
That was copied from src/util/tests/hash_table/Makefile.am.  I will
update the copyright header.


 Otherwise, the build system stuff looks okay. Just fix this stuff
 before you commit.

-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCHv2 03/13] glsl: initialize locale_t with a static object

2014-08-19 Thread Chia-I Wu
On Thu, Aug 14, 2014 at 3:00 AM, Ian Romanick i...@freedesktop.org wrote:
 On 07/09/2014 12:47 AM, Chia-I Wu wrote:
 The compiler may be used by multiple contexts simultaneously and needs to be
 thread-safe.

 Signed-off-by: Chia-I Wu o...@lunarg.com
 ---
  src/glsl/strtod.cpp | 29 +++--
  1 file changed, 15 insertions(+), 14 deletions(-)

 diff --git a/src/glsl/strtod.cpp b/src/glsl/strtod.cpp
 index 5d4346b..1ac29ec 100644
 --- a/src/glsl/strtod.cpp
 +++ b/src/glsl/strtod.cpp
 @@ -35,6 +35,17 @@

  #include strtod.h

 +#if defined(_GNU_SOURCE)  !defined(__CYGWIN__)  !defined(__FreeBSD__) 
  \
 +   !defined(__HAIKU__)  !defined(__UCLIBC__)
 +#define GLSL_HAVE_LOCALE_T
 +#endif

 Could we just do this in configure.ac (or whatever the scons analog is)
 instead?
I can add AC_CHECK_FUNCs to configure.ac.  It looks like there is also
_mesa_strtof defined in main/imports.c.  I will add a unified version
to  src/util/.


 +
 +#ifdef GLSL_HAVE_LOCALE_T
 +static struct locale_initializer {
 +   locale_initializer() { loc = newlocale(LC_CTYPE_MASK, C, NULL); }
 +   locale_t loc;
 +} loc_init;
 +#endif


  /**
 @@ -44,13 +55,8 @@
  double
  glsl_strtod(const char *s, char **end)
  {
 -#if defined(_GNU_SOURCE)  !defined(__CYGWIN__)  !defined(__FreeBSD__) 
  \
 -   !defined(__HAIKU__)  !defined(__UCLIBC__)
 -   static locale_t loc = NULL;
 -   if (!loc) {
 -  loc = newlocale(LC_CTYPE_MASK, C, NULL);
 -   }
 -   return strtod_l(s, end, loc);
 +#ifdef GLSL_HAVE_LOCALE_T
 +   return strtod_l(s, end, loc_init.loc);
  #else
 return strtod(s, end);
  #endif
 @@ -64,13 +70,8 @@ glsl_strtod(const char *s, char **end)
  float
  glsl_strtof(const char *s, char **end)
  {
 -#if defined(_GNU_SOURCE)  !defined(__CYGWIN__)  !defined(__FreeBSD__) 
  \
 -   !defined(__HAIKU__)  !defined(__UCLIBC__)
 -   static locale_t loc = NULL;
 -   if (!loc) {
 -  loc = newlocale(LC_CTYPE_MASK, C, NULL);
 -   }
 -   return strtof_l(s, end, loc);
 +#ifdef GLSL_HAVE_LOCALE_T
 +   return strtof_l(s, end, loc_init.loc);
  #elif _XOPEN_SOURCE = 600 || _ISOC99_SOURCE
 return strtof(s, end);
  #else





-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCHv2 04/13] glsl: protect anonymous struct id with a mutex

2014-08-19 Thread Chia-I Wu
On Thu, Aug 14, 2014 at 3:03 AM, Ian Romanick i...@freedesktop.org wrote:
 On 07/09/2014 12:47 AM, Chia-I Wu wrote:
 There may be two contexts compiling shaders at the same time, and we want the
 anonymous struct id to be globally unique.

 Signed-off-by: Chia-I Wu o...@lunarg.com
 ---
  src/glsl/glsl_parser_extras.cpp | 10 --
  1 file changed, 8 insertions(+), 2 deletions(-)

 diff --git a/src/glsl/glsl_parser_extras.cpp 
 b/src/glsl/glsl_parser_extras.cpp
 index b327c2b..ad31469 100644
 --- a/src/glsl/glsl_parser_extras.cpp
 +++ b/src/glsl/glsl_parser_extras.cpp
 @@ -1347,9 +1347,15 @@ ast_struct_specifier::ast_struct_specifier(const char 
 *identifier,
  ast_declarator_list 
 *declarator_list)
  {
 if (identifier == NULL) {
 +  static mtx_t mutex = _MTX_INITIALIZER_NP;
static unsigned anon_count = 1;
 -  identifier = ralloc_asprintf(this, #anon_struct_%04x, anon_count);
 -  anon_count++;
 +  unsigned count;
 +
 +  mtx_lock(mutex);
 +  count = anon_count++;
 +  mtx_unlock(mutex);

 My previous feedback on this was to try and use some sort of atomic
 counter when available.  I'm not excited about the performance hit of
 taking a lock here.  Although, this probably isn't hit too much.  After
 this lands, can you submit an enhancement bug for this issue?
Sure.  I responded to that feedback without getting any ACK or NACK.

 +
 +  identifier = ralloc_asprintf(this, #anon_struct_%04x, count);
 }
 name = identifier;
 this-declarations.push_degenerate_list_at_head(declarator_list-link);





-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCHv2 08/13] mesa: add infrastructure for threaded shader compilation

2014-08-19 Thread Chia-I Wu
On Thu, Aug 14, 2014 at 4:35 AM, Ian Romanick i...@freedesktop.org wrote:
 On 07/09/2014 12:47 AM, Chia-I Wu wrote:
 Add _mesa_enable_glsl_threadpool to enable the thread pool for a context, and
 add ctx-Const.DeferCompileShader and ctx-Const.DeferLinkProgram to
 fine-control what gets threaded.

 Setting DeferCompileShader to true will make _mesa_glsl_compile_shader be
 executed in a worker thread.  The function is thread-safe so there is no
 restriction on DeferCompileShader.

 Setting DeferLinkProgram to true will make _mesa_glsl_link_shader be executed
 in a worker thread.  The function is thread-safe only when certain driver
 functions (as documented in struct gl_constants) are thread-safe.  It is
 drivers' responsibility to fix those driver functions before setting
 DeferLinkProgram.

 When DeferLinkProgram is set, drivers are not supposed to inspect the context
 in their LinkShader callbacks.  Instead, NotifyLinkShader is added.  Drivers
 should inspect the context in NotifyLinkShader and save what they need for
 LinkShader in gl_shader_program.

 As a final note, most applications will not benefit from threaded shader
 compilation because they check GL_COMPILE_STATUS/GL_LINK_STATUS immediately,
 giving the worker threads no time to do their jobs.  A possible improvement 
 is
 to split LinkShader into two parts: the first part links and error checks
 while the second part optimizes and generates the machine code.  With the
 split, we can always defer the second part to the thread pool.

 Signed-off-by: Chia-I Wu o...@lunarg.com
 ---
  src/mesa/main/context.c |  29 +++
  src/mesa/main/context.h |   3 ++
  src/mesa/main/dd.h  |   8 +++
  src/mesa/main/mtypes.h  |  34 
  src/mesa/main/pipelineobj.c |  18 +++
  src/mesa/main/shaderapi.c   | 122 
 +++-
  src/mesa/main/shaderobj.c   |  74 +--
  src/mesa/main/shaderobj.h   |  55 ++--
  8 files changed, 322 insertions(+), 21 deletions(-)

 diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
 index b082159..e27450c 100644
 --- a/src/mesa/main/context.c
 +++ b/src/mesa/main/context.c
 @@ -112,6 +112,7 @@
  #include points.h
  #include polygon.h
  #include queryobj.h
 +#include shaderapi.h
  #include syncobj.h
  #include rastpos.h
  #include remap.h
 @@ -139,6 +140,7 @@
  #endif

  #include glsl_parser_extras.h
 +#include threadpool.h
  #include stdbool.h


 @@ -1187,6 +1189,27 @@ _mesa_create_context(gl_api api,
 }
  }

 +void
 +_mesa_enable_glsl_threadpool(struct gl_context *ctx, int max_threads)
 +{
 +   if (!ctx-ThreadPool)
 +  ctx-ThreadPool = _mesa_glsl_get_threadpool(max_threads);
 +}
 +
 +static void
 +wait_shader_object_cb(GLuint id, void *data, void *userData)
 +{
 +   struct gl_context *ctx = (struct gl_context *) userData;
 +   struct gl_shader *sh = (struct gl_shader *) data;
 +
 +   if (_mesa_validate_shader_target(ctx, sh-Type)) {
 +  _mesa_wait_shaders(ctx, sh, 1);
 +   }
 +   else {
 +  struct gl_shader_program *shProg = (struct gl_shader_program *) data;
 +  _mesa_wait_shader_program(ctx, shProg);
 +   }
 +}

  /**
   * Free the data associated with the given context.
 @@ -1205,6 +1228,12 @@ _mesa_free_context_data( struct gl_context *ctx )
_mesa_make_current(ctx, NULL, NULL);
 }

 +   if (ctx-ThreadPool) {
 +  _mesa_HashWalk(ctx-Shared-ShaderObjects, wait_shader_object_cb, 
 ctx);
 +  _mesa_threadpool_unref(ctx-ThreadPool);
 +  ctx-ThreadPool = NULL;
 +   }
 +
 /* unreference WinSysDraw/Read buffers */
 _mesa_reference_framebuffer(ctx-WinSysDrawBuffer, NULL);
 _mesa_reference_framebuffer(ctx-WinSysReadBuffer, NULL);
 diff --git a/src/mesa/main/context.h b/src/mesa/main/context.h
 index 792ab4c..b23f9fa 100644
 --- a/src/mesa/main/context.h
 +++ b/src/mesa/main/context.h
 @@ -118,6 +118,9 @@ _mesa_create_context(gl_api api,
   const struct dd_function_table *driverFunctions);

  extern void
 +_mesa_enable_glsl_threadpool(struct gl_context *ctx, int max_threads);
 +
 +extern void
  _mesa_free_context_data( struct gl_context *ctx );

  extern void
 diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
 index 633ea2c..38f8c68 100644
 --- a/src/mesa/main/dd.h
 +++ b/src/mesa/main/dd.h
 @@ -447,6 +447,14 @@ struct dd_function_table {
  */
 /*@{*/
 /**
 +* Called when a shader program is to be linked.
 +*
 +* This is optional and gives drivers an opportunity to inspect the 
 context
 +* and prepare for LinkShader, which may be deferred to another thread.
 +*/
 +   void (*NotifyLinkShader)(struct gl_context *ctx,
 +struct gl_shader_program *shader);
 +   /**
  * Called when a shader program is linked.
  *
  * This gives drivers an opportunity to clone the IR and make their
 diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
 index 5964576..316da23 100644

Re: [Mesa-dev] [PATCHv2 08/13] mesa: add infrastructure for threaded shader compilation

2014-08-19 Thread Chia-I Wu
On Thu, Aug 14, 2014 at 4:41 AM, Ian Romanick i...@freedesktop.org wrote:
 On 07/09/2014 12:47 AM, Chia-I Wu wrote:
 @@ -3489,6 +3508,18 @@ struct gl_constants
 GLfloat MaxFragmentInterpolationOffset;

 GLboolean FakeSWMSAA;
 +
 +   /*
 +* Defer certain operations to a thread pool.
 +*
 +* When DeferLinkProgram is set, these functions must be thread-safe
 +*
 +*   ctx-Driver.NewShader
 +*   ctx-Driver.DeleteShader
 +*   ctx-Driver.LinkShader
 +*/
 +   GLboolean DeferCompileShader;
 +   GLboolean DeferLinkProgram;

 We're trying to make non-API facing things use bool instead.
Will do.

  };






-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCHv2 13/13] i965: enable threaded precompile

2014-08-19 Thread Chia-I Wu
On Thu, Aug 14, 2014 at 4:44 AM, Ian Romanick i...@freedesktop.org wrote:
 On 07/09/2014 12:47 AM, Chia-I Wu wrote:
 Inherit gl_shader_program and add save/restore functions to save precompile
 results in the shader programs.  When DeferLinkProgram is set, we will save
 the precompile results instead of uploading them immediately because we may 
 be
 on a different thread.

 A few other modifications are also needed.  brw_shader_program_precompile_key
 is introduced and initialized in NofityLinkShader for we cannot inspect the
 context during precompiling.

 Signed-off-by: Chia-I Wu o...@lunarg.com
 ---
  src/mesa/drivers/dri/i965/brw_context.c  |   4 +-
  src/mesa/drivers/dri/i965/brw_fs.cpp |  33 --
  src/mesa/drivers/dri/i965/brw_program.c  |   1 +
  src/mesa/drivers/dri/i965/brw_shader.cpp | 177 
 ++-
  src/mesa/drivers/dri/i965/brw_shader.h   |  44 
  src/mesa/drivers/dri/i965/brw_vec4_gs.c  |  37 +--
  src/mesa/drivers/dri/i965/brw_vs.c   |  36 +--
  src/mesa/drivers/dri/i965/brw_wm.c   |  23 ++--
  src/mesa/drivers/dri/i965/brw_wm.h   |   5 +-
  9 files changed, 310 insertions(+), 50 deletions(-)

 diff --git a/src/mesa/drivers/dri/i965/brw_context.c 
 b/src/mesa/drivers/dri/i965/brw_context.c
 index bd13ebf..4a28766 100644
 --- a/src/mesa/drivers/dri/i965/brw_context.c
 +++ b/src/mesa/drivers/dri/i965/brw_context.c
 @@ -784,8 +784,8 @@ brwCreateContext(gl_api api,
 if (INTEL_DEBUG  DEBUG_SHADER_TIME)
brw_init_shader_time(brw);

 -   /* brw_shader_precompile is not thread-safe */
 -   if (brw-precompile)
 +   /* brw_shader_precompile is not thread-safe when debug flags are set */
 +   if (brw-precompile  (INTEL_DEBUG || brw-perf_debug))
ctx-Const.DeferLinkProgram = GL_FALSE;

 But it is safe now without debug flags?
That is what this patch is about.  Before this patch, brw_link_shader
can only be called in another thread when brw_shader_precompile does
nothing (precompile disabled).  This patch is an attempt to make it
safe to call brw_shader_precompile from another thread.

But as mentioned in the summary, this last patch is more an RFC.  A
complete audit of the various backend visitors and generators hasn't
been done yet.



 _mesa_compute_version(ctx);
 diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp 
 b/src/mesa/drivers/dri/i965/brw_fs.cpp
 index a3ad375..61a0dff 100644
 --- a/src/mesa/drivers/dri/i965/brw_fs.cpp
 +++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
 @@ -3288,6 +3288,8 @@ bool
  brw_fs_precompile(struct gl_context *ctx, struct gl_shader_program *prog)
  {
 struct brw_context *brw = brw_context(ctx);
 +   const struct brw_shader_program_precompile_key *pre_key =
 +  brw_shader_program_get_precompile_key(prog);
 struct brw_wm_prog_key key;

 if (!prog-_LinkedShaders[MESA_SHADER_FRAGMENT])
 @@ -3329,7 +3331,7 @@ brw_fs_precompile(struct gl_context *ctx, struct 
 gl_shader_program *prog)
 }

 if (fp-Base.InputsRead  VARYING_BIT_POS) {
 -  key.drawable_height = ctx-DrawBuffer-Height;
 +  key.drawable_height = pre_key-fbo_height;
 }

 key.nr_color_regions = _mesa_bitcount_64(fp-Base.OutputsWritten 
 @@ -3337,7 +3339,7 @@ brw_fs_precompile(struct gl_context *ctx, struct 
 gl_shader_program *prog)
   BITFIELD64_BIT(FRAG_RESULT_SAMPLE_MASK)));

 if ((fp-Base.InputsRead  VARYING_BIT_POS) || program_uses_dfdy) {
 -  key.render_to_fbo = _mesa_is_user_fbo(ctx-DrawBuffer) ||
 +  key.render_to_fbo = pre_key-is_user_fbo ||
key.nr_color_regions  1;
 }

 @@ -3349,13 +3351,28 @@ brw_fs_precompile(struct gl_context *ctx, struct 
 gl_shader_program *prog)

 key.program_string_id = bfp-id;

 -   uint32_t old_prog_offset = brw-wm.base.prog_offset;
 -   struct brw_wm_prog_data *old_prog_data = brw-wm.prog_data;
 +   struct brw_wm_compile c;

 -   bool success = do_wm_prog(brw, prog, bfp, key);
 +   brw_wm_init_compile(brw, prog, bfp, key, c);
 +   if (!brw_wm_do_compile(brw, c)) {
 +  brw_wm_clear_compile(brw, c);
 +  return false;
 +   }
 +
 +   if (brw-ctx.Const.DeferLinkProgram) {
 +  brw_shader_program_save_wm_compile(prog, c);
 +   }
 +   else {
 +  uint32_t old_prog_offset = brw-wm.base.prog_offset;
 +  struct brw_wm_prog_data *old_prog_data = brw-wm.prog_data;

 -   brw-wm.base.prog_offset = old_prog_offset;
 -   brw-wm.prog_data = old_prog_data;
 +  brw_wm_upload_compile(brw, c);

 -   return success;
 +  brw-wm.base.prog_offset = old_prog_offset;
 +  brw-wm.prog_data = old_prog_data;
 +   }
 +
 +   brw_wm_clear_compile(brw, c);
 +
 +   return true;
  }
 diff --git a/src/mesa/drivers/dri/i965/brw_program.c 
 b/src/mesa/drivers/dri/i965/brw_program.c
 index cff1188..2194640 100644
 --- a/src/mesa/drivers/dri/i965/brw_program.c
 +++ b/src/mesa/drivers/dri/i965/brw_program.c
 @@ -259,6 +259,7 @@ void brwInitFragProgFuncs( struct dd_function_table 
 *functions )
 functions-NewShader

Re: [Mesa-dev] [PATCHv2 06/13] glsl: add a generic thread pool data structure

2014-08-19 Thread Chia-I Wu
On Thu, Aug 14, 2014 at 8:38 AM, Ian Romanick i...@freedesktop.org wrote:
 On 07/09/2014 12:47 AM, Chia-I Wu wrote:
 It can be used to implement, for example, threaded glCompileShader and
 glLinkProgram.

 v2: allow tasks to complete other tasks

 Signed-off-by: Chia-I Wu o...@lunarg.com
 ---
  src/glsl/Makefile.am   |  12 +-
  src/glsl/Makefile.sources  |   3 +-
  src/glsl/tests/threadpool_test.cpp | 137 +++

 Some description of what the tests are doing would be good.
Sure.

  src/glsl/threadpool.c  | 476 
 +
  src/glsl/threadpool.h  |  67 ++
  5 files changed, 693 insertions(+), 2 deletions(-)
  create mode 100644 src/glsl/tests/threadpool_test.cpp
  create mode 100644 src/glsl/threadpool.c
  create mode 100644 src/glsl/threadpool.h

 diff --git a/src/glsl/Makefile.am b/src/glsl/Makefile.am
 index 00261fd..3d07af3 100644
 --- a/src/glsl/Makefile.am
 +++ b/src/glsl/Makefile.am
 @@ -35,6 +35,7 @@ TESTS = glcpp/tests/glcpp-test 
  \
   tests/general-ir-test   \
   tests/optimization-test \
   tests/ralloc-test   \
 + tests/threadpool-test   \
   tests/sampler-types-test\
   tests/uniform-initializer-test

 @@ -48,6 +49,7 @@ check_PROGRAMS =\
   glsl_test   \
   tests/general-ir-test   \
   tests/ralloc-test   \
 + tests/threadpool-test   \
   tests/sampler-types-test\
   tests/uniform-initializer-test

 @@ -95,6 +97,14 @@ tests_ralloc_test_LDADD =  \
   $(top_builddir)/src/gtest/libgtest.la   \
   $(PTHREAD_LIBS)

 +tests_threadpool_test_SOURCES =  \
 + tests/threadpool_test.cpp   \
 + $(top_builddir)/src/glsl/threadpool.c
 +tests_threadpool_test_CFLAGS = $(PTHREAD_CFLAGS)
 +tests_threadpool_test_LDADD =\
 + $(top_builddir)/src/gtest/libgtest.la   \
 + $(PTHREAD_LIBS)
 +
  tests_sampler_types_test_SOURCES =   \
   $(top_srcdir)/src/mesa/program/prog_hash_table.c\
   $(top_srcdir)/src/mesa/program/symbol_table.c   \
 @@ -120,7 +130,7 @@ glcpp_glcpp_LDADD =  
  \
   libglcpp.la \
   -lm

 -libglsl_la_LIBADD = libglcpp.la
 +libglsl_la_LIBADD = libglcpp.la $(PTHREAD_LIBS)
  libglsl_la_SOURCES = \
   glsl_lexer.cpp  \
   glsl_parser.cpp \
 diff --git a/src/glsl/Makefile.sources b/src/glsl/Makefile.sources
 index 6fc94d6..bab2358 100644
 --- a/src/glsl/Makefile.sources
 +++ b/src/glsl/Makefile.sources
 @@ -103,7 +103,8 @@ LIBGLSL_FILES = \
   $(GLSL_SRCDIR)/opt_tree_grafting.cpp \
   $(GLSL_SRCDIR)/opt_vectorize.cpp \
   $(GLSL_SRCDIR)/s_expression.cpp \
 - $(GLSL_SRCDIR)/strtod.cpp
 + $(GLSL_SRCDIR)/strtod.cpp \
 + $(GLSL_SRCDIR)/threadpool.c

  # glsl_compiler

 diff --git a/src/glsl/tests/threadpool_test.cpp 
 b/src/glsl/tests/threadpool_test.cpp
 new file mode 100644
 index 000..63f55c5
 --- /dev/null
 +++ b/src/glsl/tests/threadpool_test.cpp
 @@ -0,0 +1,137 @@
 +/*
 + * Copyright © 2014 LunarG, Inc.
 + *
 + * 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 gtest/gtest.h
 +#include string.h
 +#include stdbool.h
 +#include stdlib.h
 +#include time.h
 +#include unistd.h
 +#include c11/threads.h
 +
 +#include threadpool.h
 +
 +#define NUM_THREADS 10
 +#define OPS_PER_THREAD 100
 +#define

Re: [Mesa-dev] [PATCHv2 01/13] mesa: protect the debug state with a mutex

2014-08-19 Thread Chia-I Wu
Hi Ian,

Thanks for the reviews.

On Thu, Aug 14, 2014 at 8:45 AM, Ian Romanick i...@freedesktop.org wrote:
 Patches 7, 8, and 9 are

 Reviewed-by: Ian Romanick ian.d.roman...@intel.com

 I made a few minor comments on 7, but they should be trivial to resolve.

 Patches 10 through 13 are

 Acked-by: Ian Romanick ian.d.roman...@intel.com

 I'd like to see some feed back on those last four from Ken and / or
 Matt.  I'd also like, if possible, for this to land this week.
Sorry that I wasn't quite available until now.  Our two-year-old was
in and out of the hopsital for the last ten days or so...

When do you plan to branch off 10.3?  I should be able to send out v3
late evening Tuesday, and be responsive.



 On 07/09/2014 12:47 AM, Chia-I Wu wrote:
 We are about to change mesa to spawn threads for deferred glCompileShader and
 glLinkProgram, and we need to make sure those threads can send compiler
 warnings/errors to the debug output safely.

 Signed-off-by: Chia-I Wu o...@lunarg.com
 ---
  src/mesa/main/errors.c | 172 
 +++--
  src/mesa/main/mtypes.h |   1 +
  2 files changed, 126 insertions(+), 47 deletions(-)

 diff --git a/src/mesa/main/errors.c b/src/mesa/main/errors.c
 index aa0ff50..156eb0d 100644
 --- a/src/mesa/main/errors.c
 +++ b/src/mesa/main/errors.c
 @@ -676,22 +676,41 @@ debug_pop_group(struct gl_debug_state *debug)


  /**
 - * Return debug state for the context.  The debug state will be allocated
 - * and initialized upon the first call.
 + * Lock and return debug state for the context.  The debug state will be
 + * allocated and initialized upon the first call.  When NULL is returned, 
 the
 + * debug state is not locked.
   */
  static struct gl_debug_state *
 -_mesa_get_debug_state(struct gl_context *ctx)
 +_mesa_lock_debug_state(struct gl_context *ctx)
  {
 +   mtx_lock(ctx-DebugMutex);
 +
 if (!ctx-Debug) {
ctx-Debug = debug_create();
if (!ctx-Debug) {
 - _mesa_error(ctx, GL_OUT_OF_MEMORY, allocating debug state);
 + GET_CURRENT_CONTEXT(cur);
 + mtx_unlock(ctx-DebugMutex);
 +
 + /*
 +  * This function may be called from other threads.  When that is 
 the
 +  * case, we cannot record this OOM error.
 +  */
 + if (ctx == cur)
 +_mesa_error(ctx, GL_OUT_OF_MEMORY, allocating debug state);
 +
 + return NULL;
}
 }

 return ctx-Debug;
  }

 +static void
 +_mesa_unlock_debug_state(struct gl_context *ctx)
 +{
 +   mtx_unlock(ctx-DebugMutex);
 +}
 +
  /**
   * Set the integer debug state specified by \p pname.  This can be called 
 from
   * _mesa_set_enable for example.
 @@ -699,7 +718,7 @@ _mesa_get_debug_state(struct gl_context *ctx)
  bool
  _mesa_set_debug_state_int(struct gl_context *ctx, GLenum pname, GLint val)
  {
 -   struct gl_debug_state *debug = _mesa_get_debug_state(ctx);
 +   struct gl_debug_state *debug = _mesa_lock_debug_state(ctx);

 if (!debug)
return false;
 @@ -716,6 +735,8 @@ _mesa_set_debug_state_int(struct gl_context *ctx, GLenum 
 pname, GLint val)
break;
 }

 +   _mesa_unlock_debug_state(ctx);
 +
 return true;
  }

 @@ -729,9 +750,12 @@ _mesa_get_debug_state_int(struct gl_context *ctx, 
 GLenum pname)
 struct gl_debug_state *debug;
 GLint val;

 +   mtx_lock(ctx-DebugMutex);
 debug = ctx-Debug;
 -   if (!debug)
 +   if (!debug) {
 +  mtx_unlock(ctx-DebugMutex);
return 0;
 +   }

 switch (pname) {
 case GL_DEBUG_OUTPUT:
 @@ -756,6 +780,8 @@ _mesa_get_debug_state_int(struct gl_context *ctx, GLenum 
 pname)
break;
 }

 +   mtx_unlock(ctx-DebugMutex);
 +
 return val;
  }

 @@ -769,9 +795,12 @@ _mesa_get_debug_state_ptr(struct gl_context *ctx, 
 GLenum pname)
 struct gl_debug_state *debug;
 void *val;

 +   mtx_lock(ctx-DebugMutex);
 debug = ctx-Debug;
 -   if (!debug)
 +   if (!debug) {
 +  mtx_unlock(ctx-DebugMutex);
return NULL;
 +   }

 switch (pname) {
 case GL_DEBUG_CALLBACK_FUNCTION_ARB:
 @@ -786,9 +815,49 @@ _mesa_get_debug_state_ptr(struct gl_context *ctx, 
 GLenum pname)
break;
 }

 +   mtx_unlock(ctx-DebugMutex);
 +
 return val;
  }

 +/**
 + * Insert a debug message.  The mutex is assumed to be locked, and will be
 + * unlocked by this call.
 + */
 +static void
 +log_msg_locked_and_unlock(struct gl_context *ctx,
 +  enum mesa_debug_source source,
 +  enum mesa_debug_type type, GLuint id,
 +  enum mesa_debug_severity severity,
 +  GLint len, const char *buf)
 +{
 +   struct gl_debug_state *debug = ctx-Debug;
 +
 +   if (!debug_is_message_enabled(debug, source, type, id, severity)) {
 +  _mesa_unlock_debug_state(ctx);
 +  return;
 +   }
 +
 +   if (ctx-Debug-Callback) {
 +  GLenum gl_source = debug_source_enums[source];
 +  GLenum gl_type = debug_type_enums[type

Re: [Mesa-dev] [PATCH 01/22] gallium/ilo: cleanup intel_winsys.h

2014-08-19 Thread Chia-I Wu
On Tue, Aug 19, 2014 at 7:20 AM, Emil Velikov emil.l.veli...@gmail.com wrote:
 Make the header location, inclusion and contents more common with
 its i915,r* and nouveau counterparts:

  - Move the header within intel/drm.
  - Separate out intel_winsys_create_for_fd into 'drm_public' header.
  - Cleanup the compiler includes.
The latter two sound fine to me, but do you have a real need to move
intel_winsys.h into drm/?  It is supposed to be OS-neutral so that the
pipe driver stays OS-neutral, not being tied to DRM.



 Cc: Chia-I Wu olva...@gmail.com
 Signed-off-by: Emil Velikov emil.l.veli...@gmail.com
 ---
  .../auxiliary/target-helpers/inline_drm_helper.h   |   2 +-
  src/gallium/drivers/ilo/Android.mk |   3 +-
  src/gallium/drivers/ilo/Makefile.am|   1 -
  src/gallium/drivers/ilo/ilo_3d.c   |   2 +-
  src/gallium/drivers/ilo/ilo_3d_pipeline.c  |   2 +-
  src/gallium/drivers/ilo/ilo_3d_pipeline_dump.c |   2 +-
  src/gallium/drivers/ilo/ilo_cp.c   |   2 +-
  src/gallium/drivers/ilo/ilo_cp.h   |   2 +-
  src/gallium/drivers/ilo/ilo_gpe_gen6.h |   2 +-
  src/gallium/drivers/ilo/ilo_gpe_gen7.h |   2 +-
  src/gallium/drivers/ilo/ilo_query.c|   2 +-
  src/gallium/drivers/ilo/ilo_resource.h |   2 +-
  src/gallium/drivers/ilo/ilo_screen.c   |   2 +-
  src/gallium/drivers/ilo/ilo_shader.c   |   2 +-
  src/gallium/winsys/intel/drm/intel_drm_public.h|   8 +
  src/gallium/winsys/intel/drm/intel_drm_winsys.c|   3 +-
  src/gallium/winsys/intel/drm/intel_winsys.h| 317 
  src/gallium/winsys/intel/intel_winsys.h| 320 
 -
  18 files changed, 340 insertions(+), 336 deletions(-)
  create mode 100644 src/gallium/winsys/intel/drm/intel_drm_public.h
  create mode 100644 src/gallium/winsys/intel/drm/intel_winsys.h
  delete mode 100644 src/gallium/winsys/intel/intel_winsys.h

 diff --git a/src/gallium/auxiliary/target-helpers/inline_drm_helper.h 
 b/src/gallium/auxiliary/target-helpers/inline_drm_helper.h
 index 4ef94de..dd55a71 100644
 --- a/src/gallium/auxiliary/target-helpers/inline_drm_helper.h
 +++ b/src/gallium/auxiliary/target-helpers/inline_drm_helper.h
 @@ -19,7 +19,7 @@
  #endif

  #if GALLIUM_ILO
 -#include intel/intel_winsys.h
 +#include intel/drm/intel_drm_public.h
  #include ilo/ilo_public.h
  #endif

 diff --git a/src/gallium/drivers/ilo/Android.mk 
 b/src/gallium/drivers/ilo/Android.mk
 index 2b06663..39de3a6 100644
 --- a/src/gallium/drivers/ilo/Android.mk
 +++ b/src/gallium/drivers/ilo/Android.mk
 @@ -28,8 +28,7 @@ include $(LOCAL_PATH)/Makefile.sources
  include $(CLEAR_VARS)

  LOCAL_C_INCLUDES := \
 -   $(LOCAL_PATH)/include \
 -   $(GALLIUM_TOP)/winsys/intel
 +   $(LOCAL_PATH)/include

  LOCAL_SRC_FILES := $(C_SOURCES)

 diff --git a/src/gallium/drivers/ilo/Makefile.am 
 b/src/gallium/drivers/ilo/Makefile.am
 index 04d4da8..75213d4 100644
 --- a/src/gallium/drivers/ilo/Makefile.am
 +++ b/src/gallium/drivers/ilo/Makefile.am
 @@ -27,7 +27,6 @@ include Makefile.sources
  include $(top_srcdir)/src/gallium/Automake.inc

  AM_CPPFLAGS = \
 -   -I$(top_srcdir)/src/gallium/winsys/intel \
 $(GALLIUM_DRIVER_CFLAGS)

  noinst_LTLIBRARIES = libilo.la
 diff --git a/src/gallium/drivers/ilo/ilo_3d.c 
 b/src/gallium/drivers/ilo/ilo_3d.c
 index 9006376..daedf59 100644
 --- a/src/gallium/drivers/ilo/ilo_3d.c
 +++ b/src/gallium/drivers/ilo/ilo_3d.c
 @@ -26,7 +26,7 @@
   */

  #include util/u_prim.h
 -#include intel_winsys.h
 +#include intel/drm/intel_winsys.h

  #include ilo_3d_pipeline.h
  #include ilo_blit.h
 diff --git a/src/gallium/drivers/ilo/ilo_3d_pipeline.c 
 b/src/gallium/drivers/ilo/ilo_3d_pipeline.c
 index 1f18bbb..ee43372 100644
 --- a/src/gallium/drivers/ilo/ilo_3d_pipeline.c
 +++ b/src/gallium/drivers/ilo/ilo_3d_pipeline.c
 @@ -26,7 +26,7 @@
   */

  #include util/u_prim.h
 -#include intel_winsys.h
 +#include intel/drm/intel_winsys.h

  #include ilo_blitter.h
  #include ilo_context.h
 diff --git a/src/gallium/drivers/ilo/ilo_3d_pipeline_dump.c 
 b/src/gallium/drivers/ilo/ilo_3d_pipeline_dump.c
 index de47e8d..3d9065c 100644
 --- a/src/gallium/drivers/ilo/ilo_3d_pipeline_dump.c
 +++ b/src/gallium/drivers/ilo/ilo_3d_pipeline_dump.c
 @@ -26,7 +26,7 @@
   *Chia-I Wu o...@lunarg.com
   */

 -#include intel_winsys.h
 +#include intel/drm/intel_winsys.h

  #include ilo_cp.h
  #include ilo_3d_pipeline.h
 diff --git a/src/gallium/drivers/ilo/ilo_cp.c 
 b/src/gallium/drivers/ilo/ilo_cp.c
 index ec99e0f..0a1996c 100644
 --- a/src/gallium/drivers/ilo/ilo_cp.c
 +++ b/src/gallium/drivers/ilo/ilo_cp.c
 @@ -26,7 +26,7 @@
   */

  #include genhw/genhw.h
 -#include intel_winsys.h
 +#include intel/drm/intel_winsys.h

  #include ilo_cp.h

 diff --git a/src/gallium/drivers/ilo/ilo_cp.h 
 b/src/gallium/drivers/ilo/ilo_cp.h
 index 15b6604..83eee34 100644
 --- a/src/gallium

Re: [Mesa-dev] [PATCH 13/19] gallium/ilo: handle query_renderer caps

2014-08-19 Thread Chia-I Wu
On Fri, Aug 15, 2014 at 6:18 AM, Emil Velikov emil.l.veli...@gmail.com wrote:
 Implementation based on the classic driver with the following
 changes:
  - Use auxiliarry function os_get_total_physical_memory to get the
 total amount of memory.
  - Move the libdrm_intel specific get_aperture_size to the winsys.
Please call drm_intel_get_aperture_sizes() in probe_winsys() and
report the values in bytes in struct intel_winsys_info.  There is no
need to export the function.


 Cc: Chia-I Wu olva...@gmail.com
 Signed-off-by: Emil Velikov emil.l.veli...@gmail.com
 ---
  src/gallium/drivers/i915/i915_screen.c  |  2 +-
i915g?

  src/gallium/drivers/ilo/ilo_screen.c| 24 
  src/gallium/winsys/intel/drm/intel_drm_winsys.c | 10 ++
  src/gallium/winsys/intel/intel_winsys.h |  3 +++
  4 files changed, 38 insertions(+), 1 deletion(-)

 diff --git a/src/gallium/drivers/i915/i915_screen.c 
 b/src/gallium/drivers/i915/i915_screen.c
 index f3b89b5..022d56a 100644
 --- a/src/gallium/drivers/i915/i915_screen.c
 +++ b/src/gallium/drivers/i915/i915_screen.c
 @@ -300,7 +300,7 @@ i915_get_param(struct pipe_screen *screen, enum pipe_cap 
 cap)
if (!os_get_total_physical_memory(system_memory))
   return 0;

 -  return MIN2(gpu_mappable_megabytes, (int) (system_memory  20));
 +  return MIN2(gpu_mappable_megabytes, (int)(system_memory  20));
 }
 case PIPE_CAP_UMA:
return 1;
 diff --git a/src/gallium/drivers/ilo/ilo_screen.c 
 b/src/gallium/drivers/ilo/ilo_screen.c
 index bd6d8dd..af341dc 100644
 --- a/src/gallium/drivers/ilo/ilo_screen.c
 +++ b/src/gallium/drivers/ilo/ilo_screen.c
 @@ -25,6 +25,7 @@
   *Chia-I Wu o...@lunarg.com
   */

 +#include os/os_misc.h
  #include util/u_format_s3tc.h
  #include vl/vl_decoder.h
  #include vl/vl_video_buffer.h
 @@ -435,6 +436,29 @@ ilo_get_param(struct pipe_screen *screen, enum pipe_cap 
 param)
 case PIPE_CAP_DRAW_INDIRECT:
return 0;

 +   case PIPE_CAP_VENDOR_ID:
 +  return 0x8086;
 +   case PIPE_CAP_DEVICE_ID:
 +  return is-dev.devid;
 +   case PIPE_CAP_ACCELERATED:
 +  return true;
 +   case PIPE_CAP_VIDEO_MEMORY: {
 +  /* Once a batch uses more than 75% of the maximum mappable size, we
 +   * assume that there's some fragmentation, and we start doing extra
 +   * flushing, etc.  That's the big cliff apps will care about.
 +   */
 +  const int gpu_mappable_megabytes =
 + intel_winsys_get_aperture_size(is-winsys) * 3 / 4;
 +  uint64_t system_memory;
 +
 +  if (!os_get_total_physical_memory(system_memory))
 + return 0;
 +
 +  return MIN2(gpu_mappable_megabytes, (int)(system_memory  20));
 +   }
 +   case PIPE_CAP_UMA:
 +  return true;
 +
 default:
return 0;
 }
 diff --git a/src/gallium/winsys/intel/drm/intel_drm_winsys.c 
 b/src/gallium/winsys/intel/drm/intel_drm_winsys.c
 index b7a2c4e..b394e5f 100644
 --- a/src/gallium/winsys/intel/drm/intel_drm_winsys.c
 +++ b/src/gallium/winsys/intel/drm/intel_drm_winsys.c
 @@ -223,6 +223,16 @@ intel_winsys_get_info(const struct intel_winsys *winsys)
 return winsys-info;
  }

 +int
 +intel_winsys_get_aperture_size(const struct intel_winsys *winsys)
 +{
 +   size_t aper_size, mappable_size;
 +
 +   drm_intel_get_aperture_sizes(winsys-fd, mappable_size, aper_size);
 +
 +   return aper_size  20;
 +}
 +
  struct intel_context *
  intel_winsys_create_context(struct intel_winsys *winsys)
  {
 diff --git a/src/gallium/winsys/intel/intel_winsys.h 
 b/src/gallium/winsys/intel/intel_winsys.h
 index 197eae8..4bf9a16 100644
 --- a/src/gallium/winsys/intel/intel_winsys.h
 +++ b/src/gallium/winsys/intel/intel_winsys.h
 @@ -91,6 +91,9 @@ intel_winsys_destroy(struct intel_winsys *winsys);
  const struct intel_winsys_info *
  intel_winsys_get_info(const struct intel_winsys *winsys);

 +int
 +intel_winsys_get_aperture_size(const struct intel_winsys *winsys);
 +
  /**
   * Create a logical context for use with the render ring.
   */
 --
 2.0.2




-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 01/22] gallium/ilo: cleanup intel_winsys.h

2014-08-19 Thread Chia-I Wu
On Tue, Aug 19, 2014 at 4:26 PM, Emil Velikov emil.l.veli...@gmail.com wrote:
 On 19/08/14 09:07, Chia-I Wu wrote:
 On Tue, Aug 19, 2014 at 7:20 AM, Emil Velikov emil.l.veli...@gmail.com 
 wrote:
 Make the header location, inclusion and contents more common with
 its i915,r* and nouveau counterparts:

  - Move the header within intel/drm.
  - Separate out intel_winsys_create_for_fd into 'drm_public' header.
  - Cleanup the compiler includes.
 The latter two sound fine to me, but do you have a real need to move
 intel_winsys.h into drm/?  It is supposed to be OS-neutral so that the
 pipe driver stays OS-neutral, not being tied to DRM.

 No real need just the following ideas
  - Ease 'make dist' - see patch 07/22 from this series.
  - Gets things more obvious by prefixing the winsys header inclusions with
 $(hw)/drm or sw/$(platform).
  - This is how the cool kids do it (radeon) :P

 One could argue that ilo's approach is correct, and everyone else is
 encouraged to follow, yet I'm taking the route of least resistance :)
How about splitting intel_winsys_create_for_fd() out to the public
header, and move intel_winsys.h to drivers/ilo/?  Other cool kids
appear to do it that way.



 -Emil



 Cc: Chia-I Wu olva...@gmail.com
 Signed-off-by: Emil Velikov emil.l.veli...@gmail.com
 ---
  .../auxiliary/target-helpers/inline_drm_helper.h   |   2 +-
  src/gallium/drivers/ilo/Android.mk |   3 +-
  src/gallium/drivers/ilo/Makefile.am|   1 -
  src/gallium/drivers/ilo/ilo_3d.c   |   2 +-
  src/gallium/drivers/ilo/ilo_3d_pipeline.c  |   2 +-
  src/gallium/drivers/ilo/ilo_3d_pipeline_dump.c |   2 +-
  src/gallium/drivers/ilo/ilo_cp.c   |   2 +-
  src/gallium/drivers/ilo/ilo_cp.h   |   2 +-
  src/gallium/drivers/ilo/ilo_gpe_gen6.h |   2 +-
  src/gallium/drivers/ilo/ilo_gpe_gen7.h |   2 +-
  src/gallium/drivers/ilo/ilo_query.c|   2 +-
  src/gallium/drivers/ilo/ilo_resource.h |   2 +-
  src/gallium/drivers/ilo/ilo_screen.c   |   2 +-
  src/gallium/drivers/ilo/ilo_shader.c   |   2 +-
  src/gallium/winsys/intel/drm/intel_drm_public.h|   8 +
  src/gallium/winsys/intel/drm/intel_drm_winsys.c|   3 +-
  src/gallium/winsys/intel/drm/intel_winsys.h| 317 
 
  src/gallium/winsys/intel/intel_winsys.h| 320 
 -
  18 files changed, 340 insertions(+), 336 deletions(-)
  create mode 100644 src/gallium/winsys/intel/drm/intel_drm_public.h
  create mode 100644 src/gallium/winsys/intel/drm/intel_winsys.h
  delete mode 100644 src/gallium/winsys/intel/intel_winsys.h

 diff --git a/src/gallium/auxiliary/target-helpers/inline_drm_helper.h 
 b/src/gallium/auxiliary/target-helpers/inline_drm_helper.h
 index 4ef94de..dd55a71 100644
 --- a/src/gallium/auxiliary/target-helpers/inline_drm_helper.h
 +++ b/src/gallium/auxiliary/target-helpers/inline_drm_helper.h
 @@ -19,7 +19,7 @@
  #endif

  #if GALLIUM_ILO
 -#include intel/intel_winsys.h
 +#include intel/drm/intel_drm_public.h
  #include ilo/ilo_public.h
  #endif

 diff --git a/src/gallium/drivers/ilo/Android.mk 
 b/src/gallium/drivers/ilo/Android.mk
 index 2b06663..39de3a6 100644
 --- a/src/gallium/drivers/ilo/Android.mk
 +++ b/src/gallium/drivers/ilo/Android.mk
 @@ -28,8 +28,7 @@ include $(LOCAL_PATH)/Makefile.sources
  include $(CLEAR_VARS)

  LOCAL_C_INCLUDES := \
 -   $(LOCAL_PATH)/include \
 -   $(GALLIUM_TOP)/winsys/intel
 +   $(LOCAL_PATH)/include

  LOCAL_SRC_FILES := $(C_SOURCES)

 diff --git a/src/gallium/drivers/ilo/Makefile.am 
 b/src/gallium/drivers/ilo/Makefile.am
 index 04d4da8..75213d4 100644
 --- a/src/gallium/drivers/ilo/Makefile.am
 +++ b/src/gallium/drivers/ilo/Makefile.am
 @@ -27,7 +27,6 @@ include Makefile.sources
  include $(top_srcdir)/src/gallium/Automake.inc

  AM_CPPFLAGS = \
 -   -I$(top_srcdir)/src/gallium/winsys/intel \
 $(GALLIUM_DRIVER_CFLAGS)

  noinst_LTLIBRARIES = libilo.la
 diff --git a/src/gallium/drivers/ilo/ilo_3d.c 
 b/src/gallium/drivers/ilo/ilo_3d.c
 index 9006376..daedf59 100644
 --- a/src/gallium/drivers/ilo/ilo_3d.c
 +++ b/src/gallium/drivers/ilo/ilo_3d.c
 @@ -26,7 +26,7 @@
   */

  #include util/u_prim.h
 -#include intel_winsys.h
 +#include intel/drm/intel_winsys.h

  #include ilo_3d_pipeline.h
  #include ilo_blit.h
 diff --git a/src/gallium/drivers/ilo/ilo_3d_pipeline.c 
 b/src/gallium/drivers/ilo/ilo_3d_pipeline.c
 index 1f18bbb..ee43372 100644
 --- a/src/gallium/drivers/ilo/ilo_3d_pipeline.c
 +++ b/src/gallium/drivers/ilo/ilo_3d_pipeline.c
 @@ -26,7 +26,7 @@
   */

  #include util/u_prim.h
 -#include intel_winsys.h
 +#include intel/drm/intel_winsys.h

  #include ilo_blitter.h
  #include ilo_context.h
 diff --git a/src/gallium/drivers/ilo/ilo_3d_pipeline_dump.c 
 b/src/gallium/drivers/ilo/ilo_3d_pipeline_dump.c
 index de47e8d..3d9065c 100644
 --- a/src/gallium/drivers/ilo/ilo_3d_pipeline_dump.c
 +++ b

Re: [Mesa-dev] [PATCH] ilo: fold drm_intel_get_aperture_sizes() within probe_winsys()

2014-08-19 Thread Chia-I Wu
On Tue, Aug 19, 2014 at 5:02 PM, Emil Velikov emil.l.veli...@gmail.com wrote:
 ... and store the value in intel_winsys_info/ilo_dev_info.
One nitpick: use size_t and report in bytes.  I will make the change
and commit.  Thanks.  I wasn't aware the patch has gone in (kind of
catching up mails today).




 Suggested-by: Chia-I Wu olva...@gmail.com
 Signed-off-by: Emil Velikov emil.l.veli...@gmail.com
 ---

 Hello Chia-I

 Hope I've understood you correctly this time :)
 -Emil

  src/gallium/drivers/ilo/ilo_common.h|  1 +
  src/gallium/drivers/ilo/ilo_screen.c|  4 ++--
  src/gallium/winsys/intel/drm/intel_drm_winsys.c | 14 --
  src/gallium/winsys/intel/intel_winsys.h |  6 +++---
  4 files changed, 10 insertions(+), 15 deletions(-)

 diff --git a/src/gallium/drivers/ilo/ilo_common.h 
 b/src/gallium/drivers/ilo/ilo_common.h
 index dd31f74..11bd0c9 100644
 --- a/src/gallium/drivers/ilo/ilo_common.h
 +++ b/src/gallium/drivers/ilo/ilo_common.h
 @@ -75,6 +75,7 @@ struct ilo_dev_info {
 bool has_ppgtt;
 bool has_timestamp;
 bool has_gen7_sol_reset;
 +   int aperture_size;

 int gen;
 int gt;
 diff --git a/src/gallium/drivers/ilo/ilo_screen.c 
 b/src/gallium/drivers/ilo/ilo_screen.c
 index ad59d6d..8c67e6a 100644
 --- a/src/gallium/drivers/ilo/ilo_screen.c
 +++ b/src/gallium/drivers/ilo/ilo_screen.c
 @@ -448,8 +448,7 @@ ilo_get_param(struct pipe_screen *screen, enum pipe_cap 
 param)
 * assume that there's some fragmentation, and we start doing extra
 * flushing, etc.  That's the big cliff apps will care about.
 */
 -  const int gpu_mappable_megabytes =
 - intel_winsys_get_aperture_size(is-winsys) * 3 / 4;
 +  const int gpu_mappable_megabytes = is-dev.aperture_size * 3 / 4;
uint64_t system_memory;

if (!os_get_total_physical_memory(system_memory))
 @@ -645,6 +644,7 @@ init_dev(struct ilo_dev_info *dev, const struct 
 intel_winsys_info *info)
 dev-has_ppgtt = info-has_ppgtt;
 dev-has_timestamp = info-has_timestamp;
 dev-has_gen7_sol_reset = info-has_gen7_sol_reset;
 +   dev-aperture_size = info-aperture_size;

 if (!dev-has_logical_context) {
ilo_err(missing hardware logical context support\n);
 diff --git a/src/gallium/winsys/intel/drm/intel_drm_winsys.c 
 b/src/gallium/winsys/intel/drm/intel_drm_winsys.c
 index b394e5f..d7fdeb2 100644
 --- a/src/gallium/winsys/intel/drm/intel_drm_winsys.c
 +++ b/src/gallium/winsys/intel/drm/intel_drm_winsys.c
 @@ -115,6 +115,7 @@ static bool
  probe_winsys(struct intel_winsys *winsys)
  {
 struct intel_winsys_info *info = winsys-info;
 +   size_t aper_size, mappable_size;
 int val;

 /*
 @@ -157,6 +158,9 @@ probe_winsys(struct intel_winsys *winsys)
 get_param(winsys, I915_PARAM_HAS_GEN7_SOL_RESET, val);
 info-has_gen7_sol_reset = val;

 +   drm_intel_get_aperture_sizes(winsys-fd, mappable_size, aper_size);
 +   info-aperture_size = aper_size  20;
 +
 return true;
  }

 @@ -223,16 +227,6 @@ intel_winsys_get_info(const struct intel_winsys *winsys)
 return winsys-info;
  }

 -int
 -intel_winsys_get_aperture_size(const struct intel_winsys *winsys)
 -{
 -   size_t aper_size, mappable_size;
 -
 -   drm_intel_get_aperture_sizes(winsys-fd, mappable_size, aper_size);
 -
 -   return aper_size  20;
 -}
 -
  struct intel_context *
  intel_winsys_create_context(struct intel_winsys *winsys)
  {
 diff --git a/src/gallium/winsys/intel/intel_winsys.h 
 b/src/gallium/winsys/intel/intel_winsys.h
 index 4bf9a16..9058ab2 100644
 --- a/src/gallium/winsys/intel/intel_winsys.h
 +++ b/src/gallium/winsys/intel/intel_winsys.h
 @@ -80,6 +80,9 @@ struct intel_winsys_info {

 /* valid flags for intel_winsys_submit_bo() */
 bool has_gen7_sol_reset;
 +
 +   /* the size of the aperture in MiB */
 +   int aperture_size;
  };

  struct intel_winsys *
 @@ -91,9 +94,6 @@ intel_winsys_destroy(struct intel_winsys *winsys);
  const struct intel_winsys_info *
  intel_winsys_get_info(const struct intel_winsys *winsys);

 -int
 -intel_winsys_get_aperture_size(const struct intel_winsys *winsys);
 -
  /**
   * Create a logical context for use with the render ring.
   */
 --
 2.0.2

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



-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCHv2 01/22] gallium/ilo: cleanup intel_winsys.h

2014-08-19 Thread Chia-I Wu
On Tue, Aug 19, 2014 at 5:32 PM, Emil Velikov emil.l.veli...@gmail.com wrote:
 Make the header location, inclusion and contents more common with
 its i915,r* and nouveau counterparts:

  - Move the header within drivers/ilo.
  - Separate out intel_winsys_create_for_fd into 'drm_public' header.
  - Cleanup the compiler includes.

 v2: Move the header to drivers/ilo. Suggested by Chia-I.

 Cc: Chia-I Wu olva...@gmail.com
 Signed-off-by: Emil Velikov emil.l.veli...@gmail.com
 ---

 The patch is generated with -M, and likely won't apply as is.
 It makes it alot easier to read though ;)

 -Emil

  src/gallium/auxiliary/target-helpers/inline_drm_helper.h | 2 +-
  src/gallium/drivers/ilo/Android.mk   | 3 +--
  src/gallium/drivers/ilo/Makefile.am  | 1 -
  src/gallium/winsys/intel/drm/Makefile.am | 1 +
  src/gallium/winsys/intel/drm/intel_drm_public.h  | 8 
  src/gallium/winsys/intel/drm/intel_drm_winsys.c  | 3 ++-
  src/gallium/winsys/intel/{ = drm}/intel_winsys.h| 3 ---
  7 files changed, 13 insertions(+), 8 deletions(-)
  create mode 100644 src/gallium/winsys/intel/drm/intel_drm_public.h
  rename src/gallium/winsys/intel/{ = drm}/intel_winsys.h (99%)

 diff --git a/src/gallium/auxiliary/target-helpers/inline_drm_helper.h 
 b/src/gallium/auxiliary/target-helpers/inline_drm_helper.h
 index 4ef94de..dd55a71 100644
 --- a/src/gallium/auxiliary/target-helpers/inline_drm_helper.h
 +++ b/src/gallium/auxiliary/target-helpers/inline_drm_helper.h
 @@ -19,7 +19,7 @@
  #endif

  #if GALLIUM_ILO
 -#include intel/intel_winsys.h
 +#include intel/drm/intel_drm_public.h
  #include ilo/ilo_public.h
  #endif

 diff --git a/src/gallium/drivers/ilo/Android.mk 
 b/src/gallium/drivers/ilo/Android.mk
 index 2b06663..39de3a6 100644
 --- a/src/gallium/drivers/ilo/Android.mk
 +++ b/src/gallium/drivers/ilo/Android.mk
 @@ -28,8 +28,7 @@ include $(LOCAL_PATH)/Makefile.sources
  include $(CLEAR_VARS)

  LOCAL_C_INCLUDES := \
 -   $(LOCAL_PATH)/include \
 -   $(GALLIUM_TOP)/winsys/intel
 +   $(LOCAL_PATH)/include

  LOCAL_SRC_FILES := $(C_SOURCES)

 diff --git a/src/gallium/drivers/ilo/Makefile.am 
 b/src/gallium/drivers/ilo/Makefile.am
 index 04d4da8..75213d4 100644
 --- a/src/gallium/drivers/ilo/Makefile.am
 +++ b/src/gallium/drivers/ilo/Makefile.am
 @@ -27,7 +27,6 @@ include Makefile.sources
  include $(top_srcdir)/src/gallium/Automake.inc

  AM_CPPFLAGS = \
 -   -I$(top_srcdir)/src/gallium/winsys/intel \
 $(GALLIUM_DRIVER_CFLAGS)

  noinst_LTLIBRARIES = libilo.la
 diff --git a/src/gallium/winsys/intel/drm/Makefile.am 
 b/src/gallium/winsys/intel/drm/Makefile.am
 index 30f4486..fbe1cea 100644
 --- a/src/gallium/winsys/intel/drm/Makefile.am
 +++ b/src/gallium/winsys/intel/drm/Makefile.am
 @@ -25,6 +25,7 @@ include Makefile.sources
  include $(top_srcdir)/src/gallium/Automake.inc

  AM_CFLAGS = \
 +   -I$(top_srcdir)/src/gallium/drivers \
 $(GALLIUM_WINSYS_CFLAGS) \
 $(INTEL_CFLAGS)

 diff --git a/src/gallium/winsys/intel/drm/intel_drm_public.h 
 b/src/gallium/winsys/intel/drm/intel_drm_public.h
 new file mode 100644
 index 000..0e39dfb
 --- /dev/null
 +++ b/src/gallium/winsys/intel/drm/intel_drm_public.h
 @@ -0,0 +1,8 @@
 +#ifndef INTEL_DRM_PUBLIC_H
 +#define INTEL_DRM_PUBLIC_H
 +
 +struct intel_winsys;
 +
 +struct intel_winsys *intel_winsys_create_for_fd(int fd);
 +
 +#endif
 diff --git a/src/gallium/winsys/intel/drm/intel_drm_winsys.c 
 b/src/gallium/winsys/intel/drm/intel_drm_winsys.c
 index b394e5f..2c8f7b2 100644
 --- a/src/gallium/winsys/intel/drm/intel_drm_winsys.c
 +++ b/src/gallium/winsys/intel/drm/intel_drm_winsys.c
 @@ -41,7 +41,8 @@
  #include util/u_inlines.h
  #include util/u_memory.h
  #include util/u_debug.h
 -#include ../intel_winsys.h
 +#include intel_drm_public.h
 +#include intel/intel_winsys.h
Should be ilo/intel_winsys.h?  Otherwise, looks good to me.


  #define BATCH_SZ (8192 * sizeof(uint32_t))

 diff --git a/src/gallium/winsys/intel/intel_winsys.h 
 b/src/gallium/winsys/intel/drm/intel_winsys.h
 similarity index 99%
 rename from src/gallium/winsys/intel/intel_winsys.h
 rename to src/gallium/winsys/intel/drm/intel_winsys.h
 index 4bf9a16..932ffb5 100644
 --- a/src/gallium/winsys/intel/intel_winsys.h
 +++ b/src/gallium/winsys/intel/drm/intel_winsys.h
 @@ -82,9 +82,6 @@ struct intel_winsys_info {
 bool has_gen7_sol_reset;
  };

 -struct intel_winsys *
 -intel_winsys_create_for_fd(int fd);
 -
  void
  intel_winsys_destroy(struct intel_winsys *winsys);

 --
 2.0.2




-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCHv2 00/13] multithread GLSL compiler

2014-07-09 Thread Chia-I Wu
Hi list,

This is my second try to add multithread support for the GLSL compiler.
Changes since v1 are

 - glLinkProgram can now be threaded
 - added ctx-Const.DeferCompileShader and ctx-Const.DeferLinkProgram to
   allow drivers to control what get threaded
 - minimal changes to i965 to enable DeferLinkProgram

The most interesting patch should be patch 8, which makes the necessary
changes to core mesa.  Patch 13 touches i965 and is more a RFC patch.

v2 still requires applications to Do the Right Thing to benefit from
multithread compiler.  But that can be changed as noted in patch 8.  I am open
to suggestions.

A summary of the patches:

Patch 1 makes our GL_KRH_debug implementation thread-safe.

Patch 2~5 make the GLSL compiler thread-safe.  These are mostly the same as v1,
except for how locale_t is initialized.

Patch 6~7 add a singleton thread pool to the compiler.

Patch 8 adds the infrastructure to core mesa to enable multithread
compiling/linkg, and patch 9 adds a dri option to enable DeferCompileShader
for i965.

Patch 10~12 refactor some code in i965 and patch 13 adds the necessary changes
to enable DeferLinkProgram.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCHv2 07/13] glsl: add a singleton GLSL thread pool

2014-07-09 Thread Chia-I Wu
This thread pool will be used by contexts to queue compilation tasks.

Signed-off-by: Chia-I Wu o...@lunarg.com
---
 src/glsl/glsl_parser_extras.cpp |  4 +++
 src/glsl/threadpool.c   | 72 +
 src/glsl/threadpool.h   |  9 ++
 3 files changed, 85 insertions(+)

diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index ad31469..cb7d59e 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -37,6 +37,7 @@ extern C {
 #include glsl_parser.h
 #include ir_optimization.h
 #include loop_analysis.h
+#include threadpool.h
 
 /**
  * Format a short human-readable description of the given GLSL version.
@@ -1599,6 +1600,8 @@ extern C {
 void
 _mesa_destroy_shader_compiler(void)
 {
+   _mesa_glsl_destroy_threadpool();
+
_mesa_destroy_shader_compiler_caches();
 
_mesa_glsl_release_types();
@@ -1612,6 +1615,7 @@ _mesa_destroy_shader_compiler(void)
 void
 _mesa_destroy_shader_compiler_caches(void)
 {
+   _mesa_glsl_wait_threadpool();
_mesa_glsl_release_builtin_functions();
 }
 
diff --git a/src/glsl/threadpool.c b/src/glsl/threadpool.c
index c069fd3..d6ed8c1 100644
--- a/src/glsl/threadpool.c
+++ b/src/glsl/threadpool.c
@@ -55,6 +55,7 @@ struct _mesa_threadpool_task {
 struct _mesa_threadpool {
mtx_t mutex;
int refcnt;
+   bool shutdown;
 
enum _mesa_threadpool_control thread_control;
thrd_t *threads;
@@ -168,6 +169,12 @@ _mesa_threadpool_queue_task(struct _mesa_threadpool *pool,
 
mtx_lock(pool-mutex);
 
+   if (unlikely(pool-shutdown)) {
+  mtx_unlock(pool-mutex);
+  free(task);
+  return NULL;
+   }
+
/* someone is joining with the threads */
while (unlikely(pool-thread_control != MESA_THREADPOOL_NORMAL))
   cnd_wait(pool-thread_joined, pool-mutex);
@@ -379,6 +386,17 @@ _mesa_threadpool_join(struct _mesa_threadpool *pool, bool 
graceful)
 }
 
 /**
+ * After this call, no task can be queued.
+ */
+static void
+_mesa_threadpool_set_shutdown(struct _mesa_threadpool *pool)
+{
+   mtx_lock(pool-mutex);
+   pool-shutdown = true;
+   mtx_unlock(pool-mutex);
+}
+
+/**
  * Decrease the reference count.  Destroy \p pool when the reference count
  * reaches zero.
  */
@@ -474,3 +492,57 @@ _mesa_threadpool_create(int max_threads)
 
return pool;
 }
+
+static mtx_t threadpool_lock = _MTX_INITIALIZER_NP;
+static struct _mesa_threadpool *threadpool;
+
+/**
+ * Get the singleton GLSL thread pool.  \p max_threads is honored only by the
+ * first call to this function.
+ */
+struct _mesa_threadpool *
+_mesa_glsl_get_threadpool(int max_threads)
+{
+   mtx_lock(threadpool_lock);
+   if (!threadpool)
+  threadpool = _mesa_threadpool_create(max_threads);
+   if (threadpool)
+  _mesa_threadpool_ref(threadpool);
+   mtx_unlock(threadpool_lock);
+
+   return threadpool;
+}
+
+/**
+ * Wait until all tasks are completed and threads are joined.
+ */
+void
+_mesa_glsl_wait_threadpool(void)
+{
+   mtx_lock(threadpool_lock);
+   if (threadpool)
+  _mesa_threadpool_join(threadpool, true);
+   mtx_unlock(threadpool_lock);
+}
+
+/**
+ * Destroy the GLSL thread pool.
+ */
+void
+_mesa_glsl_destroy_threadpool(void)
+{
+   mtx_lock(threadpool_lock);
+   if (threadpool) {
+  /*
+   * This is called from _mesa_destroy_shader_compiler().  No new task is
+   * allowed since this point.  But contexts, who also own references to
+   * the pool, can still complete tasks that have been queued.
+   */
+  _mesa_threadpool_set_shutdown(threadpool);
+
+  _mesa_threadpool_join(threadpool, false);
+  _mesa_threadpool_unref(threadpool);
+  threadpool = NULL;
+   }
+   mtx_unlock(threadpool_lock);
+}
diff --git a/src/glsl/threadpool.h b/src/glsl/threadpool.h
index 48e4a47..b1a8ea8 100644
--- a/src/glsl/threadpool.h
+++ b/src/glsl/threadpool.h
@@ -60,6 +60,15 @@ bool
 _mesa_threadpool_complete_task(struct _mesa_threadpool *pool,
struct _mesa_threadpool_task *task);
 
+struct _mesa_threadpool *
+_mesa_glsl_get_threadpool(int max_threads);
+
+void
+_mesa_glsl_wait_threadpool(void);
+
+void
+_mesa_glsl_destroy_threadpool(void);
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.0.0.rc2

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


[Mesa-dev] [PATCHv2 10/13] i965: refactor do_vs_prog

2014-07-09 Thread Chia-I Wu
Split do_vs_prog into

  brw_vs_init_compile
  brw_vs_do_compile
  brw_vs_upload_compile
  brw_vs_clear_complile

Signed-off-by: Chia-I Wu o...@lunarg.com
---
 src/mesa/drivers/dri/i965/brw_vec4.h |   6 ++
 src/mesa/drivers/dri/i965/brw_vs.c   | 117 ++-
 src/mesa/drivers/dri/i965/brw_vs.h   |   1 +
 3 files changed, 81 insertions(+), 43 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_vec4.h 
b/src/mesa/drivers/dri/i965/brw_vec4.h
index 87247ea..dd66b6c 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4.h
+++ b/src/mesa/drivers/dri/i965/brw_vec4.h
@@ -48,6 +48,12 @@ extern C {
 
 struct brw_vec4_compile {
GLuint last_scratch; /** measured in 32-byte (register size) units */
+
+   struct gl_shader_program *shader_prog;
+
+   void *mem_ctx;
+   const unsigned *program;
+   unsigned program_size;
 };
 
 
diff --git a/src/mesa/drivers/dri/i965/brw_vs.c 
b/src/mesa/drivers/dri/i965/brw_vs.c
index e0f32b3..22bc473 100644
--- a/src/mesa/drivers/dri/i965/brw_vs.c
+++ b/src/mesa/drivers/dri/i965/brw_vs.c
@@ -187,31 +187,31 @@ brw_vs_prog_data_compare(const void *in_a, const void 
*in_b)
return true;
 }
 
-static bool
-do_vs_prog(struct brw_context *brw,
-  struct gl_shader_program *prog,
-  struct brw_vertex_program *vp,
-  struct brw_vs_prog_key *key)
+static void
+brw_vs_init_compile(struct brw_context *brw,
+   struct gl_shader_program *prog,
+   struct brw_vertex_program *vp,
+   const struct brw_vs_prog_key *key,
+   struct brw_vs_compile *c)
 {
-   GLuint program_size;
-   const GLuint *program;
-   struct brw_vs_compile c;
-   struct brw_vs_prog_data prog_data;
-   struct brw_stage_prog_data *stage_prog_data = prog_data.base.base;
-   void *mem_ctx;
-   int i;
-   struct gl_shader *vs = NULL;
-
-   if (prog)
-  vs = prog-_LinkedShaders[MESA_SHADER_VERTEX];
+   memset(c, 0, sizeof(*c));
 
-   memset(c, 0, sizeof(c));
-   memcpy(c.key, key, sizeof(*key));
-   memset(prog_data, 0, sizeof(prog_data));
+   memcpy(c-key, key, sizeof(*key));
+   c-vp = vp;
+   c-base.shader_prog = prog;
+   c-base.mem_ctx = ralloc_context(NULL);
+}
 
-   mem_ctx = ralloc_context(NULL);
+static bool
+brw_vs_do_compile(struct brw_context *brw,
+ struct brw_vs_compile *c)
+{
+   struct brw_stage_prog_data *stage_prog_data = c-prog_data.base.base;
+   struct gl_shader *vs = NULL;
+   int i;
 
-   c.vp = vp;
+   if (c-base.shader_prog)
+  vs = c-base.shader_prog-_LinkedShaders[MESA_SHADER_VERTEX];
 
/* Allocate the references to the uniforms that will end up in the
 * prog_data associated with the compiled program, and which will be freed
@@ -226,12 +226,12 @@ do_vs_prog(struct brw_context *brw,
   param_count = vs-num_uniform_components * 4;
 
} else {
-  param_count = vp-program.Base.Parameters-NumParameters * 4;
+  param_count = c-vp-program.Base.Parameters-NumParameters * 4;
}
/* vec4_visitor::setup_uniform_clipplane_values() also uploads user clip
 * planes as uniforms.
 */
-   param_count += c.key.base.nr_userclip_plane_consts * 4;
+   param_count += c-key.base.nr_userclip_plane_consts * 4;
 
stage_prog_data-param = rzalloc_array(NULL, const float *, param_count);
stage_prog_data-pull_param = rzalloc_array(NULL, const float *, 
param_count);
@@ -245,12 +245,12 @@ do_vs_prog(struct brw_context *brw,
   stage_prog_data-nr_params += vs-num_samplers;
}
 
-   GLbitfield64 outputs_written = vp-program.Base.OutputsWritten;
-   prog_data.inputs_read = vp-program.Base.InputsRead;
+   GLbitfield64 outputs_written = c-vp-program.Base.OutputsWritten;
+   c-prog_data.inputs_read = c-vp-program.Base.InputsRead;
 
-   if (c.key.copy_edgeflag) {
+   if (c-key.copy_edgeflag) {
   outputs_written |= BITFIELD64_BIT(VARYING_SLOT_EDGE);
-  prog_data.inputs_read |= VERT_BIT_EDGEFLAG;
+  c-prog_data.inputs_read |= VERT_BIT_EDGEFLAG;
}
 
if (brw-gen  6) {
@@ -261,7 +261,7 @@ do_vs_prog(struct brw_context *brw,
* coords, which would be a pain to handle.
*/
   for (i = 0; i  8; i++) {
- if (c.key.point_coord_replace  (1  i))
+ if (c-key.point_coord_replace  (1  i))
 outputs_written |= BITFIELD64_BIT(VARYING_SLOT_TEX0 + i);
   }
 
@@ -276,45 +276,76 @@ do_vs_prog(struct brw_context *brw,
 * distance varying slots whenever clipping is enabled, even if the vertex
 * shader doesn't write to gl_ClipDistance.
 */
-   if (c.key.base.userclip_active) {
+   if (c-key.base.userclip_active) {
   outputs_written |= BITFIELD64_BIT(VARYING_SLOT_CLIP_DIST0);
   outputs_written |= BITFIELD64_BIT(VARYING_SLOT_CLIP_DIST1);
}
 
-   brw_compute_vue_map(brw, prog_data.base.vue_map, outputs_written);
+   brw_compute_vue_map(brw, c-prog_data.base.vue_map, outputs_written);
 
if (0) {
-  _mesa_fprint_program_opt(stderr, c.vp-program.Base, PROG_PRINT_DEBUG

[Mesa-dev] [PATCHv2 06/13] glsl: add a generic thread pool data structure

2014-07-09 Thread Chia-I Wu
It can be used to implement, for example, threaded glCompileShader and
glLinkProgram.

v2: allow tasks to complete other tasks

Signed-off-by: Chia-I Wu o...@lunarg.com
---
 src/glsl/Makefile.am   |  12 +-
 src/glsl/Makefile.sources  |   3 +-
 src/glsl/tests/threadpool_test.cpp | 137 +++
 src/glsl/threadpool.c  | 476 +
 src/glsl/threadpool.h  |  67 ++
 5 files changed, 693 insertions(+), 2 deletions(-)
 create mode 100644 src/glsl/tests/threadpool_test.cpp
 create mode 100644 src/glsl/threadpool.c
 create mode 100644 src/glsl/threadpool.h

diff --git a/src/glsl/Makefile.am b/src/glsl/Makefile.am
index 00261fd..3d07af3 100644
--- a/src/glsl/Makefile.am
+++ b/src/glsl/Makefile.am
@@ -35,6 +35,7 @@ TESTS = glcpp/tests/glcpp-test
\
tests/general-ir-test   \
tests/optimization-test \
tests/ralloc-test   \
+   tests/threadpool-test   \
tests/sampler-types-test\
tests/uniform-initializer-test
 
@@ -48,6 +49,7 @@ check_PROGRAMS =  \
glsl_test   \
tests/general-ir-test   \
tests/ralloc-test   \
+   tests/threadpool-test   \
tests/sampler-types-test\
tests/uniform-initializer-test
 
@@ -95,6 +97,14 @@ tests_ralloc_test_LDADD =\
$(top_builddir)/src/gtest/libgtest.la   \
$(PTHREAD_LIBS)
 
+tests_threadpool_test_SOURCES =\
+   tests/threadpool_test.cpp   \
+   $(top_builddir)/src/glsl/threadpool.c
+tests_threadpool_test_CFLAGS = $(PTHREAD_CFLAGS)
+tests_threadpool_test_LDADD =  \
+   $(top_builddir)/src/gtest/libgtest.la   \
+   $(PTHREAD_LIBS)
+
 tests_sampler_types_test_SOURCES = \
$(top_srcdir)/src/mesa/program/prog_hash_table.c\
$(top_srcdir)/src/mesa/program/symbol_table.c   \
@@ -120,7 +130,7 @@ glcpp_glcpp_LDADD = \
libglcpp.la \
-lm
 
-libglsl_la_LIBADD = libglcpp.la
+libglsl_la_LIBADD = libglcpp.la $(PTHREAD_LIBS)
 libglsl_la_SOURCES =   \
glsl_lexer.cpp  \
glsl_parser.cpp \
diff --git a/src/glsl/Makefile.sources b/src/glsl/Makefile.sources
index 6fc94d6..bab2358 100644
--- a/src/glsl/Makefile.sources
+++ b/src/glsl/Makefile.sources
@@ -103,7 +103,8 @@ LIBGLSL_FILES = \
$(GLSL_SRCDIR)/opt_tree_grafting.cpp \
$(GLSL_SRCDIR)/opt_vectorize.cpp \
$(GLSL_SRCDIR)/s_expression.cpp \
-   $(GLSL_SRCDIR)/strtod.cpp
+   $(GLSL_SRCDIR)/strtod.cpp \
+   $(GLSL_SRCDIR)/threadpool.c
 
 # glsl_compiler
 
diff --git a/src/glsl/tests/threadpool_test.cpp 
b/src/glsl/tests/threadpool_test.cpp
new file mode 100644
index 000..63f55c5
--- /dev/null
+++ b/src/glsl/tests/threadpool_test.cpp
@@ -0,0 +1,137 @@
+/*
+ * Copyright © 2014 LunarG, Inc.
+ *
+ * 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 gtest/gtest.h
+#include string.h
+#include stdbool.h
+#include stdlib.h
+#include time.h
+#include unistd.h
+#include c11/threads.h
+
+#include threadpool.h
+
+#define NUM_THREADS 10
+#define OPS_PER_THREAD 100
+#define MAX_TASKS 10
+
+static void
+race_cb(void *data)
+{
+   usleep(1000 * 5);
+}
+
+static int
+race_random_op(void *data)
+{
+   struct _mesa_threadpool *pool = (struct _mesa_threadpool *) data;
+   struct _mesa_threadpool_task *tasks[MAX_TASKS

[Mesa-dev] [PATCHv2 02/13] glsl: rename strtod.c to strtod.cpp

2014-07-09 Thread Chia-I Wu
We want to add a static object to initialize locale_t in the following commit.

Signed-off-by: Chia-I Wu o...@lunarg.com
---
 src/glsl/Makefile.sources |  2 +-
 src/glsl/strtod.c | 79 ---
 src/glsl/strtod.cpp   | 79 +++
 3 files changed, 80 insertions(+), 80 deletions(-)
 delete mode 100644 src/glsl/strtod.c
 create mode 100644 src/glsl/strtod.cpp

diff --git a/src/glsl/Makefile.sources b/src/glsl/Makefile.sources
index b54eae7..6fc94d6 100644
--- a/src/glsl/Makefile.sources
+++ b/src/glsl/Makefile.sources
@@ -103,7 +103,7 @@ LIBGLSL_FILES = \
$(GLSL_SRCDIR)/opt_tree_grafting.cpp \
$(GLSL_SRCDIR)/opt_vectorize.cpp \
$(GLSL_SRCDIR)/s_expression.cpp \
-   $(GLSL_SRCDIR)/strtod.c
+   $(GLSL_SRCDIR)/strtod.cpp
 
 # glsl_compiler
 
diff --git a/src/glsl/strtod.c b/src/glsl/strtod.c
deleted file mode 100644
index 5d4346b..000
--- a/src/glsl/strtod.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright 2010 VMware, Inc.
- * All Rights Reserved.
- *
- * 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, sub license, 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 NON-INFRINGEMENT.
- * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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 stdlib.h
-
-#ifdef _GNU_SOURCE
-#include locale.h
-#ifdef __APPLE__
-#include xlocale.h
-#endif
-#endif
-
-#include strtod.h
-
-
-
-/**
- * Wrapper around strtod which uses the C locale so the decimal
- * point is always '.'
- */
-double
-glsl_strtod(const char *s, char **end)
-{
-#if defined(_GNU_SOURCE)  !defined(__CYGWIN__)  !defined(__FreeBSD__)  \
-   !defined(__HAIKU__)  !defined(__UCLIBC__)
-   static locale_t loc = NULL;
-   if (!loc) {
-  loc = newlocale(LC_CTYPE_MASK, C, NULL);
-   }
-   return strtod_l(s, end, loc);
-#else
-   return strtod(s, end);
-#endif
-}
-
-
-/**
- * Wrapper around strtof which uses the C locale so the decimal
- * point is always '.'
- */
-float
-glsl_strtof(const char *s, char **end)
-{
-#if defined(_GNU_SOURCE)  !defined(__CYGWIN__)  !defined(__FreeBSD__)  \
-   !defined(__HAIKU__)  !defined(__UCLIBC__)
-   static locale_t loc = NULL;
-   if (!loc) {
-  loc = newlocale(LC_CTYPE_MASK, C, NULL);
-   }
-   return strtof_l(s, end, loc);
-#elif _XOPEN_SOURCE = 600 || _ISOC99_SOURCE
-   return strtof(s, end);
-#else
-   return (float) strtod(s, end);
-#endif
-}
diff --git a/src/glsl/strtod.cpp b/src/glsl/strtod.cpp
new file mode 100644
index 000..5d4346b
--- /dev/null
+++ b/src/glsl/strtod.cpp
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2010 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * 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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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 stdlib.h
+
+#ifdef _GNU_SOURCE
+#include locale.h
+#ifdef __APPLE__
+#include xlocale.h
+#endif
+#endif
+
+#include strtod.h
+
+
+
+/**
+ * Wrapper around strtod which uses the C locale so the decimal
+ * point is always '.'
+ */
+double
+glsl_strtod(const char *s, char **end)
+{
+#if defined

[Mesa-dev] [PATCHv2 03/13] glsl: initialize locale_t with a static object

2014-07-09 Thread Chia-I Wu
The compiler may be used by multiple contexts simultaneously and needs to be
thread-safe.

Signed-off-by: Chia-I Wu o...@lunarg.com
---
 src/glsl/strtod.cpp | 29 +++--
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/src/glsl/strtod.cpp b/src/glsl/strtod.cpp
index 5d4346b..1ac29ec 100644
--- a/src/glsl/strtod.cpp
+++ b/src/glsl/strtod.cpp
@@ -35,6 +35,17 @@
 
 #include strtod.h
 
+#if defined(_GNU_SOURCE)  !defined(__CYGWIN__)  !defined(__FreeBSD__)  \
+   !defined(__HAIKU__)  !defined(__UCLIBC__)
+#define GLSL_HAVE_LOCALE_T
+#endif
+
+#ifdef GLSL_HAVE_LOCALE_T
+static struct locale_initializer {
+   locale_initializer() { loc = newlocale(LC_CTYPE_MASK, C, NULL); }
+   locale_t loc;
+} loc_init;
+#endif
 
 
 /**
@@ -44,13 +55,8 @@
 double
 glsl_strtod(const char *s, char **end)
 {
-#if defined(_GNU_SOURCE)  !defined(__CYGWIN__)  !defined(__FreeBSD__)  \
-   !defined(__HAIKU__)  !defined(__UCLIBC__)
-   static locale_t loc = NULL;
-   if (!loc) {
-  loc = newlocale(LC_CTYPE_MASK, C, NULL);
-   }
-   return strtod_l(s, end, loc);
+#ifdef GLSL_HAVE_LOCALE_T
+   return strtod_l(s, end, loc_init.loc);
 #else
return strtod(s, end);
 #endif
@@ -64,13 +70,8 @@ glsl_strtod(const char *s, char **end)
 float
 glsl_strtof(const char *s, char **end)
 {
-#if defined(_GNU_SOURCE)  !defined(__CYGWIN__)  !defined(__FreeBSD__)  \
-   !defined(__HAIKU__)  !defined(__UCLIBC__)
-   static locale_t loc = NULL;
-   if (!loc) {
-  loc = newlocale(LC_CTYPE_MASK, C, NULL);
-   }
-   return strtof_l(s, end, loc);
+#ifdef GLSL_HAVE_LOCALE_T
+   return strtof_l(s, end, loc_init.loc);
 #elif _XOPEN_SOURCE = 600 || _ISOC99_SOURCE
return strtof(s, end);
 #else
-- 
2.0.0.rc2

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


[Mesa-dev] [PATCHv2 01/13] mesa: protect the debug state with a mutex

2014-07-09 Thread Chia-I Wu
We are about to change mesa to spawn threads for deferred glCompileShader and
glLinkProgram, and we need to make sure those threads can send compiler
warnings/errors to the debug output safely.

Signed-off-by: Chia-I Wu o...@lunarg.com
---
 src/mesa/main/errors.c | 172 +++--
 src/mesa/main/mtypes.h |   1 +
 2 files changed, 126 insertions(+), 47 deletions(-)

diff --git a/src/mesa/main/errors.c b/src/mesa/main/errors.c
index aa0ff50..156eb0d 100644
--- a/src/mesa/main/errors.c
+++ b/src/mesa/main/errors.c
@@ -676,22 +676,41 @@ debug_pop_group(struct gl_debug_state *debug)
 
 
 /**
- * Return debug state for the context.  The debug state will be allocated
- * and initialized upon the first call.
+ * Lock and return debug state for the context.  The debug state will be
+ * allocated and initialized upon the first call.  When NULL is returned, the
+ * debug state is not locked.
  */
 static struct gl_debug_state *
-_mesa_get_debug_state(struct gl_context *ctx)
+_mesa_lock_debug_state(struct gl_context *ctx)
 {
+   mtx_lock(ctx-DebugMutex);
+
if (!ctx-Debug) {
   ctx-Debug = debug_create();
   if (!ctx-Debug) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, allocating debug state);
+ GET_CURRENT_CONTEXT(cur);
+ mtx_unlock(ctx-DebugMutex);
+
+ /*
+  * This function may be called from other threads.  When that is the
+  * case, we cannot record this OOM error.
+  */
+ if (ctx == cur)
+_mesa_error(ctx, GL_OUT_OF_MEMORY, allocating debug state);
+
+ return NULL;
   }
}
 
return ctx-Debug;
 }
 
+static void
+_mesa_unlock_debug_state(struct gl_context *ctx)
+{
+   mtx_unlock(ctx-DebugMutex);
+}
+
 /**
  * Set the integer debug state specified by \p pname.  This can be called from
  * _mesa_set_enable for example.
@@ -699,7 +718,7 @@ _mesa_get_debug_state(struct gl_context *ctx)
 bool
 _mesa_set_debug_state_int(struct gl_context *ctx, GLenum pname, GLint val)
 {
-   struct gl_debug_state *debug = _mesa_get_debug_state(ctx);
+   struct gl_debug_state *debug = _mesa_lock_debug_state(ctx);
 
if (!debug)
   return false;
@@ -716,6 +735,8 @@ _mesa_set_debug_state_int(struct gl_context *ctx, GLenum 
pname, GLint val)
   break;
}
 
+   _mesa_unlock_debug_state(ctx);
+
return true;
 }
 
@@ -729,9 +750,12 @@ _mesa_get_debug_state_int(struct gl_context *ctx, GLenum 
pname)
struct gl_debug_state *debug;
GLint val;
 
+   mtx_lock(ctx-DebugMutex);
debug = ctx-Debug;
-   if (!debug)
+   if (!debug) {
+  mtx_unlock(ctx-DebugMutex);
   return 0;
+   }
 
switch (pname) {
case GL_DEBUG_OUTPUT:
@@ -756,6 +780,8 @@ _mesa_get_debug_state_int(struct gl_context *ctx, GLenum 
pname)
   break;
}
 
+   mtx_unlock(ctx-DebugMutex);
+
return val;
 }
 
@@ -769,9 +795,12 @@ _mesa_get_debug_state_ptr(struct gl_context *ctx, GLenum 
pname)
struct gl_debug_state *debug;
void *val;
 
+   mtx_lock(ctx-DebugMutex);
debug = ctx-Debug;
-   if (!debug)
+   if (!debug) {
+  mtx_unlock(ctx-DebugMutex);
   return NULL;
+   }
 
switch (pname) {
case GL_DEBUG_CALLBACK_FUNCTION_ARB:
@@ -786,9 +815,49 @@ _mesa_get_debug_state_ptr(struct gl_context *ctx, GLenum 
pname)
   break;
}
 
+   mtx_unlock(ctx-DebugMutex);
+
return val;
 }
 
+/**
+ * Insert a debug message.  The mutex is assumed to be locked, and will be
+ * unlocked by this call.
+ */
+static void
+log_msg_locked_and_unlock(struct gl_context *ctx,
+  enum mesa_debug_source source,
+  enum mesa_debug_type type, GLuint id,
+  enum mesa_debug_severity severity,
+  GLint len, const char *buf)
+{
+   struct gl_debug_state *debug = ctx-Debug;
+
+   if (!debug_is_message_enabled(debug, source, type, id, severity)) {
+  _mesa_unlock_debug_state(ctx);
+  return;
+   }
+
+   if (ctx-Debug-Callback) {
+  GLenum gl_source = debug_source_enums[source];
+  GLenum gl_type = debug_type_enums[type];
+  GLenum gl_severity = debug_severity_enums[severity];
+  GLDEBUGPROC callback = ctx-Debug-Callback;
+  const void *data = ctx-Debug-CallbackData;
+
+  /*
+   * When ctx-Debug-SyncOutput is GL_FALSE, the client is prepared for
+   * unsynchronous calls.  When it is GL_TRUE, we will not spawn threads.
+   * In either case, we can call the callback unlocked.
+   */
+  _mesa_unlock_debug_state(ctx);
+  callback(gl_source, gl_type, id, gl_severity, len, buf, data);
+   }
+   else {
+  debug_log_message(ctx-Debug, source, type, id, severity, len, buf);
+  _mesa_unlock_debug_state(ctx);
+   }
+}
 
 /**
  * Log a client or driver debug message.
@@ -798,24 +867,12 @@ log_msg(struct gl_context *ctx, enum mesa_debug_source 
source,
 enum mesa_debug_type type, GLuint id,
 enum mesa_debug_severity severity, GLint len, const

[Mesa-dev] [PATCHv2 11/13] i965: refactor do_gs_prog

2014-07-09 Thread Chia-I Wu
Split do_gs_prog into

  brw_gs_init_compile
  brw_gs_do_compile
  brw_gs_upload_compile
  brw_gs_clear_complile

Signed-off-by: Chia-I Wu o...@lunarg.com
---
 src/mesa/drivers/dri/i965/brw_vec4_gs.c | 153 
 1 file changed, 96 insertions(+), 57 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_vec4_gs.c 
b/src/mesa/drivers/dri/i965/brw_vec4_gs.c
index 6428291..39ee507 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_gs.c
+++ b/src/mesa/drivers/dri/i965/brw_vec4_gs.c
@@ -33,22 +33,29 @@
 #include brw_state.h
 
 
-static bool
-do_gs_prog(struct brw_context *brw,
-   struct gl_shader_program *prog,
-   struct brw_geometry_program *gp,
-   struct brw_gs_prog_key *key)
+static void
+brw_gs_init_compile(struct brw_context *brw,
+struct gl_shader_program *prog,
+struct brw_geometry_program *gp,
+const struct brw_gs_prog_key *key,
+struct brw_gs_compile *c)
 {
-   struct brw_stage_state *stage_state = brw-gs.base;
-   struct brw_gs_compile c;
-   memset(c, 0, sizeof(c));
-   c.key = *key;
-   c.gp = gp;
+   memset(c, 0, sizeof(*c));
 
-   c.prog_data.include_primitive_id =
-  (gp-program.Base.InputsRead  VARYING_BIT_PRIMITIVE_ID) != 0;
+   c-key = *key;
+   c-gp = gp;
+   c-base.shader_prog = prog;
+   c-base.mem_ctx = ralloc_context(NULL);
+}
 
-   c.prog_data.invocations = gp-program.Invocations;
+static bool
+brw_gs_do_compile(struct brw_context *brw,
+  struct brw_gs_compile *c)
+{
+   c-prog_data.include_primitive_id =
+  (c-gp-program.Base.InputsRead  VARYING_BIT_PRIMITIVE_ID) != 0;
+
+   c-prog_data.invocations = c-gp-program.Invocations;
 
/* Allocate the references to the uniforms that will end up in the
 * prog_data associated with the compiled program, and which will be freed
@@ -58,34 +65,35 @@ do_gs_prog(struct brw_context *brw,
 * padding around uniform values below vec4 size, so the worst case is that
 * every uniform is a float which gets padded to the size of a vec4.
 */
-   struct gl_shader *gs = prog-_LinkedShaders[MESA_SHADER_GEOMETRY];
+   struct gl_shader *gs =
+  c-base.shader_prog-_LinkedShaders[MESA_SHADER_GEOMETRY];
int param_count = gs-num_uniform_components * 4;
 
/* We also upload clip plane data as uniforms */
param_count += MAX_CLIP_PLANES * 4;
 
-   c.prog_data.base.base.param =
+   c-prog_data.base.base.param =
   rzalloc_array(NULL, const float *, param_count);
-   c.prog_data.base.base.pull_param =
+   c-prog_data.base.base.pull_param =
   rzalloc_array(NULL, const float *, param_count);
/* Setting nr_params here NOT to the size of the param and pull_param
 * arrays, but to the number of uniform components vec4_visitor
 * needs. vec4_visitor::setup_uniforms() will set it back to a proper value.
 */
-   c.prog_data.base.base.nr_params = ALIGN(param_count, 4) / 4 + 
gs-num_samplers;
+   c-prog_data.base.base.nr_params = ALIGN(param_count, 4) / 4 + 
gs-num_samplers;
 
-   if (gp-program.OutputType == GL_POINTS) {
+   if (c-gp-program.OutputType == GL_POINTS) {
   /* When the output type is points, the geometry shader may output data
* to multiple streams, and EndPrimitive() has no effect.  So we
* configure the hardware to interpret the control data as stream ID.
*/
-  c.prog_data.control_data_format = GEN7_GS_CONTROL_DATA_FORMAT_GSCTL_SID;
+  c-prog_data.control_data_format = GEN7_GS_CONTROL_DATA_FORMAT_GSCTL_SID;
 
   /* We only have to emit control bits if we are using streams */
-  if (prog-Geom.UsesStreams)
- c.control_data_bits_per_vertex = 2;
+  if (c-base.shader_prog-Geom.UsesStreams)
+ c-control_data_bits_per_vertex = 2;
   else
- c.control_data_bits_per_vertex = 0;
+ c-control_data_bits_per_vertex = 0;
} else {
   /* When the output type is triangle_strip or line_strip, EndPrimitive()
* may be used to terminate the current strip and start a new one
@@ -93,32 +101,33 @@ do_gs_prog(struct brw_context *brw,
* streams is not supported.  So we configure the hardware to interpret
* the control data as EndPrimitive information (a.k.a. cut bits).
*/
-  c.prog_data.control_data_format = GEN7_GS_CONTROL_DATA_FORMAT_GSCTL_CUT;
+  c-prog_data.control_data_format = GEN7_GS_CONTROL_DATA_FORMAT_GSCTL_CUT;
 
   /* We only need to output control data if the shader actually calls
* EndPrimitive().
*/
-  c.control_data_bits_per_vertex = gp-program.UsesEndPrimitive ? 1 : 0;
+  c-control_data_bits_per_vertex =
+ c-gp-program.UsesEndPrimitive ? 1 : 0;
}
-   c.control_data_header_size_bits =
-  gp-program.VerticesOut * c.control_data_bits_per_vertex;
+   c-control_data_header_size_bits =
+  c-gp-program.VerticesOut * c-control_data_bits_per_vertex;
 
/* 1 HWORD = 32 bytes = 256 bits

[Mesa-dev] [PATCHv2 08/13] mesa: add infrastructure for threaded shader compilation

2014-07-09 Thread Chia-I Wu
Add _mesa_enable_glsl_threadpool to enable the thread pool for a context, and
add ctx-Const.DeferCompileShader and ctx-Const.DeferLinkProgram to
fine-control what gets threaded.

Setting DeferCompileShader to true will make _mesa_glsl_compile_shader be
executed in a worker thread.  The function is thread-safe so there is no
restriction on DeferCompileShader.

Setting DeferLinkProgram to true will make _mesa_glsl_link_shader be executed
in a worker thread.  The function is thread-safe only when certain driver
functions (as documented in struct gl_constants) are thread-safe.  It is
drivers' responsibility to fix those driver functions before setting
DeferLinkProgram.

When DeferLinkProgram is set, drivers are not supposed to inspect the context
in their LinkShader callbacks.  Instead, NotifyLinkShader is added.  Drivers
should inspect the context in NotifyLinkShader and save what they need for
LinkShader in gl_shader_program.

As a final note, most applications will not benefit from threaded shader
compilation because they check GL_COMPILE_STATUS/GL_LINK_STATUS immediately,
giving the worker threads no time to do their jobs.  A possible improvement is
to split LinkShader into two parts: the first part links and error checks
while the second part optimizes and generates the machine code.  With the
split, we can always defer the second part to the thread pool.

Signed-off-by: Chia-I Wu o...@lunarg.com
---
 src/mesa/main/context.c |  29 +++
 src/mesa/main/context.h |   3 ++
 src/mesa/main/dd.h  |   8 +++
 src/mesa/main/mtypes.h  |  34 
 src/mesa/main/pipelineobj.c |  18 +++
 src/mesa/main/shaderapi.c   | 122 +++-
 src/mesa/main/shaderobj.c   |  74 +--
 src/mesa/main/shaderobj.h   |  55 ++--
 8 files changed, 322 insertions(+), 21 deletions(-)

diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index b082159..e27450c 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -112,6 +112,7 @@
 #include points.h
 #include polygon.h
 #include queryobj.h
+#include shaderapi.h
 #include syncobj.h
 #include rastpos.h
 #include remap.h
@@ -139,6 +140,7 @@
 #endif
 
 #include glsl_parser_extras.h
+#include threadpool.h
 #include stdbool.h
 
 
@@ -1187,6 +1189,27 @@ _mesa_create_context(gl_api api,
}
 }
 
+void
+_mesa_enable_glsl_threadpool(struct gl_context *ctx, int max_threads)
+{
+   if (!ctx-ThreadPool)
+  ctx-ThreadPool = _mesa_glsl_get_threadpool(max_threads);
+}
+
+static void
+wait_shader_object_cb(GLuint id, void *data, void *userData)
+{
+   struct gl_context *ctx = (struct gl_context *) userData;
+   struct gl_shader *sh = (struct gl_shader *) data;
+
+   if (_mesa_validate_shader_target(ctx, sh-Type)) {
+  _mesa_wait_shaders(ctx, sh, 1);
+   }
+   else {
+  struct gl_shader_program *shProg = (struct gl_shader_program *) data;
+  _mesa_wait_shader_program(ctx, shProg);
+   }
+}
 
 /**
  * Free the data associated with the given context.
@@ -1205,6 +1228,12 @@ _mesa_free_context_data( struct gl_context *ctx )
   _mesa_make_current(ctx, NULL, NULL);
}
 
+   if (ctx-ThreadPool) {
+  _mesa_HashWalk(ctx-Shared-ShaderObjects, wait_shader_object_cb, ctx);
+  _mesa_threadpool_unref(ctx-ThreadPool);
+  ctx-ThreadPool = NULL;
+   }
+
/* unreference WinSysDraw/Read buffers */
_mesa_reference_framebuffer(ctx-WinSysDrawBuffer, NULL);
_mesa_reference_framebuffer(ctx-WinSysReadBuffer, NULL);
diff --git a/src/mesa/main/context.h b/src/mesa/main/context.h
index 792ab4c..b23f9fa 100644
--- a/src/mesa/main/context.h
+++ b/src/mesa/main/context.h
@@ -118,6 +118,9 @@ _mesa_create_context(gl_api api,
  const struct dd_function_table *driverFunctions);
 
 extern void
+_mesa_enable_glsl_threadpool(struct gl_context *ctx, int max_threads);
+
+extern void
 _mesa_free_context_data( struct gl_context *ctx );
 
 extern void
diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
index 633ea2c..38f8c68 100644
--- a/src/mesa/main/dd.h
+++ b/src/mesa/main/dd.h
@@ -447,6 +447,14 @@ struct dd_function_table {
 */
/*@{*/
/**
+* Called when a shader program is to be linked.
+*
+* This is optional and gives drivers an opportunity to inspect the context
+* and prepare for LinkShader, which may be deferred to another thread.
+*/
+   void (*NotifyLinkShader)(struct gl_context *ctx,
+struct gl_shader_program *shader);
+   /**
 * Called when a shader program is linked.
 *
 * This gives drivers an opportunity to clone the IR and make their
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 5964576..316da23 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -71,6 +71,8 @@ typedef GLuint64 GLbitfield64;
  */
 /*@{*/
 struct _mesa_HashTable;
+struct _mesa_threadpool;
+struct _mesa_threadpool_task;
 struct gl_attrib_node;
 struct

[Mesa-dev] [PATCHv2 13/13] i965: enable threaded precompile

2014-07-09 Thread Chia-I Wu
Inherit gl_shader_program and add save/restore functions to save precompile
results in the shader programs.  When DeferLinkProgram is set, we will save
the precompile results instead of uploading them immediately because we may be
on a different thread.

A few other modifications are also needed.  brw_shader_program_precompile_key
is introduced and initialized in NofityLinkShader for we cannot inspect the
context during precompiling.

Signed-off-by: Chia-I Wu o...@lunarg.com
---
 src/mesa/drivers/dri/i965/brw_context.c  |   4 +-
 src/mesa/drivers/dri/i965/brw_fs.cpp |  33 --
 src/mesa/drivers/dri/i965/brw_program.c  |   1 +
 src/mesa/drivers/dri/i965/brw_shader.cpp | 177 ++-
 src/mesa/drivers/dri/i965/brw_shader.h   |  44 
 src/mesa/drivers/dri/i965/brw_vec4_gs.c  |  37 +--
 src/mesa/drivers/dri/i965/brw_vs.c   |  36 +--
 src/mesa/drivers/dri/i965/brw_wm.c   |  23 ++--
 src/mesa/drivers/dri/i965/brw_wm.h   |   5 +-
 9 files changed, 310 insertions(+), 50 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_context.c 
b/src/mesa/drivers/dri/i965/brw_context.c
index bd13ebf..4a28766 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -784,8 +784,8 @@ brwCreateContext(gl_api api,
if (INTEL_DEBUG  DEBUG_SHADER_TIME)
   brw_init_shader_time(brw);
 
-   /* brw_shader_precompile is not thread-safe */
-   if (brw-precompile)
+   /* brw_shader_precompile is not thread-safe when debug flags are set */
+   if (brw-precompile  (INTEL_DEBUG || brw-perf_debug))
   ctx-Const.DeferLinkProgram = GL_FALSE;
 
_mesa_compute_version(ctx);
diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp 
b/src/mesa/drivers/dri/i965/brw_fs.cpp
index a3ad375..61a0dff 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -3288,6 +3288,8 @@ bool
 brw_fs_precompile(struct gl_context *ctx, struct gl_shader_program *prog)
 {
struct brw_context *brw = brw_context(ctx);
+   const struct brw_shader_program_precompile_key *pre_key =
+  brw_shader_program_get_precompile_key(prog);
struct brw_wm_prog_key key;
 
if (!prog-_LinkedShaders[MESA_SHADER_FRAGMENT])
@@ -3329,7 +3331,7 @@ brw_fs_precompile(struct gl_context *ctx, struct 
gl_shader_program *prog)
}
 
if (fp-Base.InputsRead  VARYING_BIT_POS) {
-  key.drawable_height = ctx-DrawBuffer-Height;
+  key.drawable_height = pre_key-fbo_height;
}
 
key.nr_color_regions = _mesa_bitcount_64(fp-Base.OutputsWritten 
@@ -3337,7 +3339,7 @@ brw_fs_precompile(struct gl_context *ctx, struct 
gl_shader_program *prog)
  BITFIELD64_BIT(FRAG_RESULT_SAMPLE_MASK)));
 
if ((fp-Base.InputsRead  VARYING_BIT_POS) || program_uses_dfdy) {
-  key.render_to_fbo = _mesa_is_user_fbo(ctx-DrawBuffer) ||
+  key.render_to_fbo = pre_key-is_user_fbo ||
   key.nr_color_regions  1;
}
 
@@ -3349,13 +3351,28 @@ brw_fs_precompile(struct gl_context *ctx, struct 
gl_shader_program *prog)
 
key.program_string_id = bfp-id;
 
-   uint32_t old_prog_offset = brw-wm.base.prog_offset;
-   struct brw_wm_prog_data *old_prog_data = brw-wm.prog_data;
+   struct brw_wm_compile c;
 
-   bool success = do_wm_prog(brw, prog, bfp, key);
+   brw_wm_init_compile(brw, prog, bfp, key, c);
+   if (!brw_wm_do_compile(brw, c)) {
+  brw_wm_clear_compile(brw, c);
+  return false;
+   }
+
+   if (brw-ctx.Const.DeferLinkProgram) {
+  brw_shader_program_save_wm_compile(prog, c);
+   }
+   else {
+  uint32_t old_prog_offset = brw-wm.base.prog_offset;
+  struct brw_wm_prog_data *old_prog_data = brw-wm.prog_data;
 
-   brw-wm.base.prog_offset = old_prog_offset;
-   brw-wm.prog_data = old_prog_data;
+  brw_wm_upload_compile(brw, c);
 
-   return success;
+  brw-wm.base.prog_offset = old_prog_offset;
+  brw-wm.prog_data = old_prog_data;
+   }
+
+   brw_wm_clear_compile(brw, c);
+
+   return true;
 }
diff --git a/src/mesa/drivers/dri/i965/brw_program.c 
b/src/mesa/drivers/dri/i965/brw_program.c
index cff1188..2194640 100644
--- a/src/mesa/drivers/dri/i965/brw_program.c
+++ b/src/mesa/drivers/dri/i965/brw_program.c
@@ -259,6 +259,7 @@ void brwInitFragProgFuncs( struct dd_function_table 
*functions )
functions-NewShader = brw_new_shader;
functions-NewShaderProgram = brw_new_shader_program;
functions-LinkShader = brw_link_shader;
+   functions-NotifyLinkShader = brw_notify_link_shader;
 }
 
 void
diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp 
b/src/mesa/drivers/dri/i965/brw_shader.cpp
index 318802b..3cf1f15 100644
--- a/src/mesa/drivers/dri/i965/brw_shader.cpp
+++ b/src/mesa/drivers/dri/i965/brw_shader.cpp
@@ -25,14 +25,52 @@ extern C {
 #include main/macros.h
 #include brw_context.h
 }
+#include brw_shader.h
 #include brw_vs.h
 #include brw_vec4_gs.h
+#include brw_vec4_gs_visitor.h
 #include brw_fs.h
 #include brw_cfg.h
 #include glsl/ir_optimization.h
 #include glsl

[Mesa-dev] [PATCHv2 09/13] i965: add drirc option multithread_glsl_compiler

2014-07-09 Thread Chia-I Wu
Setting it to a non-zero value N will cause shader compilation to be deferred
to a thread pool.  When N is greater than 1, it indicates the maximum number
of threads in the pool.  When N is 1, the number of threads is up to the
driver (two for i965).

Signed-off-by: Chia-I Wu o...@lunarg.com
---
 src/mesa/drivers/dri/common/xmlpool/t_options.h |  4 
 src/mesa/drivers/dri/i965/brw_context.c | 15 +++
 src/mesa/drivers/dri/i965/intel_screen.c|  2 ++
 3 files changed, 21 insertions(+)

diff --git a/src/mesa/drivers/dri/common/xmlpool/t_options.h 
b/src/mesa/drivers/dri/common/xmlpool/t_options.h
index fc9e104..80abaf9 100644
--- a/src/mesa/drivers/dri/common/xmlpool/t_options.h
+++ b/src/mesa/drivers/dri/common/xmlpool/t_options.h
@@ -293,6 +293,10 @@ DRI_CONF_OPT_BEGIN_V(texture_heaps,enum,def,0:2) \
DRI_CONF_DESC_END \
 DRI_CONF_OPT_END
 
+#define DRI_CONF_MULTITHREAD_GLSL_COMPILER(def) \
+DRI_CONF_OPT_BEGIN(multithread_glsl_compiler, int, def) \
+DRI_CONF_DESC(en,gettext(Enable multithreading in the GLSL 
compiler)) \
+DRI_CONF_OPT_END
 
 
 /**
diff --git a/src/mesa/drivers/dri/i965/brw_context.c 
b/src/mesa/drivers/dri/i965/brw_context.c
index c47ad36..bd13ebf 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -570,6 +570,17 @@ brw_process_driconf_options(struct brw_context *brw)
 
ctx-Const.DisableGLSLLineContinuations =
   driQueryOptionb(options, disable_glsl_line_continuations);
+
+   const int multithread_glsl_compiler =
+  driQueryOptioni(options, multithread_glsl_compiler);
+   if (multithread_glsl_compiler  0) {
+  const int max_threads = (multithread_glsl_compiler  1) ?
+ multithread_glsl_compiler : 2;
+
+  _mesa_enable_glsl_threadpool(ctx, max_threads);
+  ctx-Const.DeferCompileShader = GL_TRUE;
+  ctx-Const.DeferLinkProgram = GL_TRUE;
+   }
 }
 
 GLboolean
@@ -773,6 +784,10 @@ brwCreateContext(gl_api api,
if (INTEL_DEBUG  DEBUG_SHADER_TIME)
   brw_init_shader_time(brw);
 
+   /* brw_shader_precompile is not thread-safe */
+   if (brw-precompile)
+  ctx-Const.DeferLinkProgram = GL_FALSE;
+
_mesa_compute_version(ctx);
 
_mesa_initialize_dispatch_tables(ctx);
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 5b0cbf3..b91d1b1 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -48,6 +48,8 @@ static const __DRIconfigOptionsExtension brw_config_options = 
{
 DRI_CONF_BEGIN
DRI_CONF_SECTION_PERFORMANCE
   DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC)
+  DRI_CONF_MULTITHREAD_GLSL_COMPILER(0)
+
   /* Options correspond to DRI_CONF_BO_REUSE_DISABLED,
* DRI_CONF_BO_REUSE_ALL
*/
-- 
2.0.0.rc2

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


[Mesa-dev] [PATCHv2 05/13] glsl: protect glsl_type with a mutex

2014-07-09 Thread Chia-I Wu
glsl_type has several static hash tables and a static ralloc context.  They
need to be protected by a mutex as they are not thread-safe.

Signed-off-by: Chia-I Wu o...@lunarg.com
---
 src/glsl/glsl_types.cpp | 57 +++--
 src/glsl/glsl_types.h   | 15 +
 2 files changed, 62 insertions(+), 10 deletions(-)

diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
index f9cd258..a9261e4 100644
--- a/src/glsl/glsl_types.cpp
+++ b/src/glsl/glsl_types.cpp
@@ -29,6 +29,7 @@ extern C {
 #include program/hash_table.h
 }
 
+mtx_t glsl_type::mutex = _MTX_INITIALIZER_NP;
 hash_table *glsl_type::array_types = NULL;
 hash_table *glsl_type::record_types = NULL;
 hash_table *glsl_type::interface_types = NULL;
@@ -53,9 +54,14 @@ glsl_type::glsl_type(GLenum gl_type,
vector_elements(vector_elements), matrix_columns(matrix_columns),
length(0)
 {
+   mtx_lock(glsl_type::mutex);
+
init_ralloc_type_ctx();
assert(name != NULL);
this-name = ralloc_strdup(this-mem_ctx, name);
+
+   mtx_unlock(glsl_type::mutex);
+
/* Neither dimension is zero or both dimensions are zero.
 */
assert((vector_elements == 0) == (matrix_columns == 0));
@@ -71,9 +77,14 @@ glsl_type::glsl_type(GLenum gl_type, glsl_base_type 
base_type,
sampler_array(array), sampler_type(type), interface_packing(0),
length(0)
 {
+   mtx_lock(glsl_type::mutex);
+
init_ralloc_type_ctx();
assert(name != NULL);
this-name = ralloc_strdup(this-mem_ctx, name);
+
+   mtx_unlock(glsl_type::mutex);
+
memset( fields, 0, sizeof(fields));
 
if (base_type == GLSL_TYPE_SAMPLER) {
@@ -95,11 +106,14 @@ glsl_type::glsl_type(const glsl_struct_field *fields, 
unsigned num_fields,
 {
unsigned int i;
 
+   mtx_lock(glsl_type::mutex);
+
init_ralloc_type_ctx();
assert(name != NULL);
this-name = ralloc_strdup(this-mem_ctx, name);
this-fields.structure = ralloc_array(this-mem_ctx,
 glsl_struct_field, length);
+
for (i = 0; i  length; i++) {
   this-fields.structure[i].type = fields[i].type;
   this-fields.structure[i].name = ralloc_strdup(this-fields.structure,
@@ -110,6 +124,8 @@ glsl_type::glsl_type(const glsl_struct_field *fields, 
unsigned num_fields,
   this-fields.structure[i].sample = fields[i].sample;
   this-fields.structure[i].row_major = fields[i].row_major;
}
+
+   mtx_unlock(glsl_type::mutex);
 }
 
 glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields,
@@ -123,6 +139,8 @@ glsl_type::glsl_type(const glsl_struct_field *fields, 
unsigned num_fields,
 {
unsigned int i;
 
+   mtx_lock(glsl_type::mutex);
+
init_ralloc_type_ctx();
assert(name != NULL);
this-name = ralloc_strdup(this-mem_ctx, name);
@@ -138,6 +156,8 @@ glsl_type::glsl_type(const glsl_struct_field *fields, 
unsigned num_fields,
   this-fields.structure[i].sample = fields[i].sample;
   this-fields.structure[i].row_major = fields[i].row_major;
}
+
+   mtx_unlock(glsl_type::mutex);
 }
 
 
@@ -285,6 +305,8 @@ const glsl_type *glsl_type::get_scalar_type() const
 void
 _mesa_glsl_release_types(void)
 {
+   mtx_lock(glsl_type::mutex);
+
if (glsl_type::array_types != NULL) {
   hash_table_dtor(glsl_type::array_types);
   glsl_type::array_types = NULL;
@@ -294,6 +316,8 @@ _mesa_glsl_release_types(void)
   hash_table_dtor(glsl_type::record_types);
   glsl_type::record_types = NULL;
}
+
+   mtx_unlock(glsl_type::mutex);
 }
 
 
@@ -316,7 +340,10 @@ glsl_type::glsl_type(const glsl_type *array, unsigned 
length) :
 * NUL.
 */
const unsigned name_length = strlen(array-name) + 10 + 3;
+
+   mtx_lock(glsl_type::mutex);
char *const n = (char *) ralloc_size(this-mem_ctx, name_length);
+   mtx_unlock(glsl_type::mutex);
 
if (length == 0)
   snprintf(n, name_length, %s[], array-name);
@@ -452,12 +479,6 @@ glsl_type::get_instance(unsigned base_type, unsigned rows, 
unsigned columns)
 const glsl_type *
 glsl_type::get_array_instance(const glsl_type *base, unsigned array_size)
 {
-
-   if (array_types == NULL) {
-  array_types = hash_table_ctor(64, hash_table_string_hash,
-   hash_table_string_compare);
-   }
-
/* Generate a name using the base type pointer in the key.  This is
 * done because the name of the base type may not be unique across
 * shaders.  For example, two shaders may have different record types
@@ -466,9 +487,19 @@ glsl_type::get_array_instance(const glsl_type *base, 
unsigned array_size)
char key[128];
snprintf(key, sizeof(key), %p[%u], (void *) base, array_size);
 
+   mtx_lock(glsl_type::mutex);
+
+   if (array_types == NULL) {
+  array_types = hash_table_ctor(64, hash_table_string_hash,
+   hash_table_string_compare);
+   }
+
const glsl_type *t = (glsl_type *) hash_table_find(array_types, key);
+
if (t == NULL) {
+  mtx_unlock

[Mesa-dev] [PATCHv2 12/13] i965: refactor do_wm_prog

2014-07-09 Thread Chia-I Wu
Split do_wm_prog into

  brw_wm_init_compile
  brw_wm_do_compile
  brw_wm_upload_compile
  brw_wm_clear_complile

Add struct brw_wm_compile to be passed around them.

Signed-off-by: Chia-I Wu o...@lunarg.com
---
 src/mesa/drivers/dri/i965/brw_wm.c | 119 -
 src/mesa/drivers/dri/i965/brw_wm.h |  30 ++
 2 files changed, 107 insertions(+), 42 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_wm.c 
b/src/mesa/drivers/dri/i965/brw_wm.c
index d716e6f..6849963 100644
--- a/src/mesa/drivers/dri/i965/brw_wm.c
+++ b/src/mesa/drivers/dri/i965/brw_wm.c
@@ -135,27 +135,30 @@ brw_wm_prog_data_compare(const void *in_a, const void 
*in_b)
return true;
 }
 
-/**
- * All Mesa program - GPU code generation goes through this function.
- * Depending on the instructions used (i.e. flow control instructions)
- * we'll use one of two code generators.
- */
-bool do_wm_prog(struct brw_context *brw,
-   struct gl_shader_program *prog,
-   struct brw_fragment_program *fp,
-   struct brw_wm_prog_key *key)
+void
+brw_wm_init_compile(struct brw_context *brw,
+   struct gl_shader_program *prog,
+   struct brw_fragment_program *fp,
+   const struct brw_wm_prog_key *key,
+   struct brw_wm_compile *c)
+{
+   memset(c, 0, sizeof(*c));
+
+   c-shader_prog = prog;
+   c-fp = fp;
+   c-key = key;
+   c-mem_ctx = ralloc_context(NULL);
+}
+
+bool
+brw_wm_do_compile(struct brw_context *brw,
+  struct brw_wm_compile *c)
 {
struct gl_context *ctx = brw-ctx;
-   void *mem_ctx = ralloc_context(NULL);
-   struct brw_wm_prog_data prog_data;
-   const GLuint *program;
struct gl_shader *fs = NULL;
-   GLuint program_size;
 
-   if (prog)
-  fs = prog-_LinkedShaders[MESA_SHADER_FRAGMENT];
-
-   memset(prog_data, 0, sizeof(prog_data));
+   if (c-shader_prog)
+  fs = c-shader_prog-_LinkedShaders[MESA_SHADER_FRAGMENT];
 
/* Allocate the references to the uniforms that will end up in the
 * prog_data associated with the compiled program, and which will be freed
@@ -165,42 +168,74 @@ bool do_wm_prog(struct brw_context *brw,
if (fs) {
   param_count = fs-num_uniform_components;
} else {
-  param_count = fp-program.Base.Parameters-NumParameters * 4;
+  param_count = c-fp-program.Base.Parameters-NumParameters * 4;
}
/* The backend also sometimes adds params for texture size. */
param_count += 2 * 
ctx-Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits;
-   prog_data.base.param = rzalloc_array(NULL, const float *, param_count);
-   prog_data.base.pull_param =
-   rzalloc_array(NULL, const float *, param_count);
-   prog_data.base.nr_params = param_count;
-
-   prog_data.barycentric_interp_modes =
-  brw_compute_barycentric_interp_modes(brw, key-flat_shade,
-   key-persample_shading,
-   fp-program);
-
-   program = brw_wm_fs_emit(brw, mem_ctx, key, prog_data,
-fp-program, prog, program_size);
-   if (program == NULL) {
-  ralloc_free(mem_ctx);
+   c-prog_data.base.param = rzalloc_array(NULL, const float *, param_count);
+   c-prog_data.base.pull_param =
+  rzalloc_array(NULL, const float *, param_count);
+   c-prog_data.base.nr_params = param_count;
+
+   c-prog_data.barycentric_interp_modes =
+  brw_compute_barycentric_interp_modes(brw, c-key-flat_shade,
+   c-key-persample_shading,
+   c-fp-program);
+
+   c-program = brw_wm_fs_emit(brw, c-mem_ctx, c-key, c-prog_data,
+ c-fp-program, c-shader_prog, c-program_size);
+   if (c-program == NULL)
   return false;
-   }
-
-   if (prog_data.total_scratch) {
-  brw_get_scratch_bo(brw, brw-wm.base.scratch_bo,
-prog_data.total_scratch * brw-max_wm_threads);
-   }
 
if (unlikely(INTEL_DEBUG  DEBUG_WM))
   fprintf(stderr, \n);
 
+   return true;
+}
+
+void
+brw_wm_upload_compile(struct brw_context *brw,
+  const struct brw_wm_compile *c)
+{
+   if (c-prog_data.total_scratch) {
+  brw_get_scratch_bo(brw, brw-wm.base.scratch_bo,
+c-prog_data.total_scratch * brw-max_wm_threads);
+   }
+
brw_upload_cache(brw-cache, BRW_WM_PROG,
-   key, sizeof(struct brw_wm_prog_key),
-   program, program_size,
-   prog_data, sizeof(prog_data),
+   c-key, sizeof(struct brw_wm_prog_key),
+   c-program, c-program_size,
+   c-prog_data, sizeof(c-prog_data),
brw-wm.base.prog_offset, brw-wm.prog_data);
+}
+
+void
+brw_wm_clear_compile(struct brw_context *brw,
+ struct brw_wm_compile *c)
+{
+   ralloc_free(c-mem_ctx);
+}
+
+/**
+ * All Mesa program - GPU code generation goes through

[Mesa-dev] [PATCHv2 04/13] glsl: protect anonymous struct id with a mutex

2014-07-09 Thread Chia-I Wu
There may be two contexts compiling shaders at the same time, and we want the
anonymous struct id to be globally unique.

Signed-off-by: Chia-I Wu o...@lunarg.com
---
 src/glsl/glsl_parser_extras.cpp | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index b327c2b..ad31469 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -1347,9 +1347,15 @@ ast_struct_specifier::ast_struct_specifier(const char 
*identifier,
   ast_declarator_list *declarator_list)
 {
if (identifier == NULL) {
+  static mtx_t mutex = _MTX_INITIALIZER_NP;
   static unsigned anon_count = 1;
-  identifier = ralloc_asprintf(this, #anon_struct_%04x, anon_count);
-  anon_count++;
+  unsigned count;
+
+  mtx_lock(mutex);
+  count = anon_count++;
+  mtx_unlock(mutex);
+
+  identifier = ralloc_asprintf(this, #anon_struct_%04x, count);
}
name = identifier;
this-declarations.push_degenerate_list_at_head(declarator_list-link);
-- 
2.0.0.rc2

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


Re: [Mesa-dev] [PATCHv2 06/13] glsl: add a generic thread pool data structure

2014-07-09 Thread Chia-I Wu
On Wed, Jul 9, 2014 at 10:42 PM, Brian Paul bri...@vmware.com wrote:
 On 07/09/2014 01:47 AM, Chia-I Wu wrote:

 It can be used to implement, for example, threaded glCompileShader and
 glLinkProgram.

 v2: allow tasks to complete other tasks

 Signed-off-by: Chia-I Wu o...@lunarg.com
 ---
   src/glsl/Makefile.am   |  12 +-
   src/glsl/Makefile.sources  |   3 +-
   src/glsl/tests/threadpool_test.cpp | 137 +++
   src/glsl/threadpool.c  | 476
 +
   src/glsl/threadpool.h  |  67 ++


 Does the threadpool code have anything GLSL-specific in it?  If not, maybe
 these files should go in src/mesa/main/
No, there is no GLSL-specific code here.  The following commit (patch
7) adds the singleton of the pool to GLSL.  The code is here because
the singleton is the only user of it, and it does not make much sense
to have more than a pool.

I do not have a preference where these files should reside.  I will
move them if you or others have a preference.







   5 files changed, 693 insertions(+), 2 deletions(-)
   create mode 100644 src/glsl/tests/threadpool_test.cpp
   create mode 100644 src/glsl/threadpool.c
   create mode 100644 src/glsl/threadpool.h

 diff --git a/src/glsl/Makefile.am b/src/glsl/Makefile.am
 index 00261fd..3d07af3 100644
 --- a/src/glsl/Makefile.am
 +++ b/src/glsl/Makefile.am
 @@ -35,6 +35,7 @@ TESTS = glcpp/tests/glcpp-test
 \
 tests/general-ir-test   \
 tests/optimization-test \
 tests/ralloc-test   \
 +   tests/threadpool-test   \
 tests/sampler-types-test\
 tests/uniform-initializer-test

 @@ -48,6 +49,7 @@ check_PROGRAMS =  \
 glsl_test   \
 tests/general-ir-test   \
 tests/ralloc-test   \
 +   tests/threadpool-test   \
 tests/sampler-types-test\
 tests/uniform-initializer-test

 @@ -95,6 +97,14 @@ tests_ralloc_test_LDADD =\
 $(top_builddir)/src/gtest/libgtest.la   \
 $(PTHREAD_LIBS)

 +tests_threadpool_test_SOURCES =\
 +   tests/threadpool_test.cpp   \
 +   $(top_builddir)/src/glsl/threadpool.c
 +tests_threadpool_test_CFLAGS = $(PTHREAD_CFLAGS)
 +tests_threadpool_test_LDADD =  \
 +   $(top_builddir)/src/gtest/libgtest.la   \
 +   $(PTHREAD_LIBS)
 +
   tests_sampler_types_test_SOURCES =\
 $(top_srcdir)/src/mesa/program/prog_hash_table.c\
 $(top_srcdir)/src/mesa/program/symbol_table.c   \
 @@ -120,7 +130,7 @@ glcpp_glcpp_LDADD = \
 libglcpp.la \
 -lm

 -libglsl_la_LIBADD = libglcpp.la
 +libglsl_la_LIBADD = libglcpp.la $(PTHREAD_LIBS)
   libglsl_la_SOURCES =  \
 glsl_lexer.cpp  \
 glsl_parser.cpp \
 diff --git a/src/glsl/Makefile.sources b/src/glsl/Makefile.sources
 index 6fc94d6..bab2358 100644
 --- a/src/glsl/Makefile.sources
 +++ b/src/glsl/Makefile.sources
 @@ -103,7 +103,8 @@ LIBGLSL_FILES = \
 $(GLSL_SRCDIR)/opt_tree_grafting.cpp \
 $(GLSL_SRCDIR)/opt_vectorize.cpp \
 $(GLSL_SRCDIR)/s_expression.cpp \
 -   $(GLSL_SRCDIR)/strtod.cpp
 +   $(GLSL_SRCDIR)/strtod.cpp \
 +   $(GLSL_SRCDIR)/threadpool.c

   # glsl_compiler

 diff --git a/src/glsl/tests/threadpool_test.cpp
 b/src/glsl/tests/threadpool_test.cpp
 new file mode 100644
 index 000..63f55c5
 --- /dev/null
 +++ b/src/glsl/tests/threadpool_test.cpp
 @@ -0,0 +1,137 @@
 +/*
 + * Copyright © 2014 LunarG, Inc.
 + *
 + * 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

Re: [Mesa-dev] [PATCHv2 08/13] mesa: add infrastructure for threaded shader compilation

2014-07-09 Thread Chia-I Wu
On Wed, Jul 9, 2014 at 10:42 PM, Brian Paul bri...@vmware.com wrote:
 On 07/09/2014 01:47 AM, Chia-I Wu wrote:

 Add _mesa_enable_glsl_threadpool to enable the thread pool for a context,
 and
 add ctx-Const.DeferCompileShader and ctx-Const.DeferLinkProgram to
 fine-control what gets threaded.

 Setting DeferCompileShader to true will make _mesa_glsl_compile_shader be
 executed in a worker thread.  The function is thread-safe so there is no
 restriction on DeferCompileShader.

 Setting DeferLinkProgram to true will make _mesa_glsl_link_shader be
 executed
 in a worker thread.  The function is thread-safe only when certain driver
 functions (as documented in struct gl_constants) are thread-safe.  It is
 drivers' responsibility to fix those driver functions before setting
 DeferLinkProgram.

 When DeferLinkProgram is set, drivers are not supposed to inspect the
 context
 in their LinkShader callbacks.  Instead, NotifyLinkShader is added.
 Drivers
 should inspect the context in NotifyLinkShader and save what they need for
 LinkShader in gl_shader_program.

 As a final note, most applications will not benefit from threaded shader
 compilation because they check GL_COMPILE_STATUS/GL_LINK_STATUS
 immediately,
 giving the worker threads no time to do their jobs.  A possible
 improvement is
 to split LinkShader into two parts: the first part links and error checks
 while the second part optimizes and generates the machine code.  With the
 split, we can always defer the second part to the thread pool.

 Signed-off-by: Chia-I Wu o...@lunarg.com
 ---
   src/mesa/main/context.c |  29 +++
   src/mesa/main/context.h |   3 ++
   src/mesa/main/dd.h  |   8 +++
   src/mesa/main/mtypes.h  |  34 
   src/mesa/main/pipelineobj.c |  18 +++
   src/mesa/main/shaderapi.c   | 122
 +++-
   src/mesa/main/shaderobj.c   |  74 +--
   src/mesa/main/shaderobj.h   |  55 ++--
   8 files changed, 322 insertions(+), 21 deletions(-)

 diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
 index b082159..e27450c 100644
 --- a/src/mesa/main/context.c
 +++ b/src/mesa/main/context.c
 @@ -112,6 +112,7 @@
   #include points.h
   #include polygon.h
   #include queryobj.h
 +#include shaderapi.h
   #include syncobj.h
   #include rastpos.h
   #include remap.h
 @@ -139,6 +140,7 @@
   #endif

   #include glsl_parser_extras.h
 +#include threadpool.h
   #include stdbool.h


 @@ -1187,6 +1189,27 @@ _mesa_create_context(gl_api api,
  }
   }

 +void
 +_mesa_enable_glsl_threadpool(struct gl_context *ctx, int max_threads)
 +{
 +   if (!ctx-ThreadPool)
 +  ctx-ThreadPool = _mesa_glsl_get_threadpool(max_threads);
 +}
 +
 +static void
 +wait_shader_object_cb(GLuint id, void *data, void *userData)
 +{
 +   struct gl_context *ctx = (struct gl_context *) userData;
 +   struct gl_shader *sh = (struct gl_shader *) data;
 +
 +   if (_mesa_validate_shader_target(ctx, sh-Type)) {
 +  _mesa_wait_shaders(ctx, sh, 1);
 +   }
 +   else {
 +  struct gl_shader_program *shProg = (struct gl_shader_program *)
 data;
 +  _mesa_wait_shader_program(ctx, shProg);
 +   }
 +}

   /**
* Free the data associated with the given context.
 @@ -1205,6 +1228,12 @@ _mesa_free_context_data( struct gl_context *ctx )
 _mesa_make_current(ctx, NULL, NULL);
  }

 +   if (ctx-ThreadPool) {
 +  _mesa_HashWalk(ctx-Shared-ShaderObjects, wait_shader_object_cb,
 ctx);
 +  _mesa_threadpool_unref(ctx-ThreadPool);
 +  ctx-ThreadPool = NULL;
 +   }
 +
  /* unreference WinSysDraw/Read buffers */
  _mesa_reference_framebuffer(ctx-WinSysDrawBuffer, NULL);
  _mesa_reference_framebuffer(ctx-WinSysReadBuffer, NULL);
 diff --git a/src/mesa/main/context.h b/src/mesa/main/context.h
 index 792ab4c..b23f9fa 100644
 --- a/src/mesa/main/context.h
 +++ b/src/mesa/main/context.h
 @@ -118,6 +118,9 @@ _mesa_create_context(gl_api api,
const struct dd_function_table *driverFunctions);

   extern void
 +_mesa_enable_glsl_threadpool(struct gl_context *ctx, int max_threads);
 +
 +extern void
   _mesa_free_context_data( struct gl_context *ctx );

   extern void
 diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
 index 633ea2c..38f8c68 100644
 --- a/src/mesa/main/dd.h
 +++ b/src/mesa/main/dd.h
 @@ -447,6 +447,14 @@ struct dd_function_table {
   */
  /*@{*/
  /**
 +* Called when a shader program is to be linked.
 +*
 +* This is optional and gives drivers an opportunity to inspect the
 context
 +* and prepare for LinkShader, which may be deferred to another
 thread.
 +*/
 +   void (*NotifyLinkShader)(struct gl_context *ctx,
 +struct gl_shader_program *shader);
 +   /**
   * Called when a shader program is linked.
   *
   * This gives drivers an opportunity to clone the IR and make their
 diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h

Re: [Mesa-dev] Static/shared pipe-drivers (was megadriver/pipe-loader-to-all)

2014-06-18 Thread Chia-I Wu
Hi Emil,

On Fri, Jun 13, 2014 at 3:56 AM, Emil Velikov emil.l.veli...@gmail.com wrote:
 Hi all,

 These patches add support for building (grouping) the various targets per
 API, meaning that only one library will be created  for e.g. vdpau
 (libvdpau_gallium) with individual ones (libvdpau_r600) being a hardlink
 to it.

 This allows us to have substantial space savings as the API(state-tracker)
 is available only once. Additionally it adds support for shared
 pipe-drivers via a _unstable_ interface, which saves us the duplication
 across X APIs.

 The former method has been used by the egl-static while the latter by
 opencl and gbm targets since they were introduced.

 By default we build with static pipe-drivers.

 Some numbers + extra info [1]

 [Static]
 dri:(r600|radeonsi|nouveau)_dri.so   - 6.5 MiB
 vdpau:  libvdpau_(r600|radeonsi|nouveau).so  - 3.5 MiB

 Total: 10MiB

 [Shared]
 Libraries:
 dri:(r600|radeonsi|nouveau)_dri.so   - 3.9 MiB
 vdpau:  libvdpau_(r600|radeonsi|nouveau).so  - 633 KiB
 gallium-pipe:   pipe_(r600|radeonsi|nouveau).so  - 5.3 MiB

 Total: 9.8MiB

 [Current]
 dri:(r600|radeonsi|nouveau)_dri.so   - 5.0+4.5+5.3 = 14.8 MiB
 vdpau:  libvdpau_(r600|radeonsi|nouveau).so  - 1.9+1.2+2.3 = 5.4 MiB

 Total: 20.2MiB


 The previous series can be found here [2]
 Changes since then
  - Convert targets individually.
  - OMX targets now work, and the final library is now libomx-mesa.so
  - Dropped the DRI targets for now
  - A handfull of typos thinkos and bugs fixed.


 My plan is to have these pushed in ~4 stages, with two stages per week.
 This way I will be able to crack on with the remaining bits and have all
 of it tested well before we branch the next release.

 Series is availabe at
 https://github.com/evelikov/Mesa/tree/static-or-shared-pipe-drivers

 As always comments and suggestions are greatly appreciated.
Thanks for working on this.  This is a tough issue to tackle.  I have
a few questions/comments, which I am fine to see them resolved either
before or after landing your series.

I see this work as to define an internal API to manage pipe drivers.
The lack of such API previously led us to targets, where each target
knows how to load a specific driver.  With your changes, state
trackers that need to work with pipe drivers have a way to do so.  As
a result, files such as

  dri/target.c,
  xa/target.c,
  xvmc/target.c,
  vdpau/target.c, and
  omx/target.c

become quite dummy and redundant.  Do you see a way to get rid of
targets entirely?

In the same view, and noticing that all users of the API have this snippet

#if GALLIUM_STATIC_TARGETS
   scrn-base.pscreen = dd_create_screen(fd);
#else
   if (pipe_loader_drm_probe_fd(scrn-base.dev, fd, true))
  scrn-base.pscreen = pipe_loader_create_screen(scrn-base.dev,
PIPE_SEARCH_DIR);
#endif // GALLIUM_STATIC_TARGETS

I think it makes sense hide this difference behind the API.  Another
thing I noted is that the non-static path allows the user to auth the
fd while the static path doesn't.  It is not clear to me how come the
static path works.

On the other hand, the implementation of the API extends itself a bit
when DRI_TARGET is defined.  That is ugly from the API's point of
view.  Could that be abstracted somehow so that it can be used
elsewhere or at least looks nicer?

Finally, the API is limited to C API (i.e., inline_{drm,sw}_helper.h).
At the build system level, we also like a way to easily manage a pipe
driver.  For example, we can see this snippet in many of the
Makefile.am

if HAVE_GALLIUM_RADEONSI
STATIC_TARGET_CPPFLAGS += -DGALLIUM_RADEONSI
STATIC_TARGET_LIB_DEPS += \
$(top_builddir)/src/gallium/drivers/radeonsi/libradeonsi.la \
$(RADEON_LIBS)
endif

If pipe drivers can be accompanies by some Makefile rules specifying
how it should be built, in addition to how it can be loaded, we can
get rid of those duplicated rules.



 Cheers,
 -Emil

 [1] http://lists.freedesktop.org/archives/mesa-dev/2014-May/059806.html
 [2] http://lists.freedesktop.org/archives/mesa-dev/2014-May/059628.html


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



-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] Static/shared pipe-drivers (was megadriver/pipe-loader-to-all)

2014-06-18 Thread Chia-I Wu
On Wed, Jun 18, 2014 at 8:14 PM, Emil Velikov emil.l.veli...@gmail.com wrote:
 On 18 June 2014 08:21, Chia-I Wu olva...@gmail.com wrote:
 Hi Emil,

 On Fri, Jun 13, 2014 at 3:56 AM, Emil Velikov emil.l.veli...@gmail.com 
 wrote:
 Hi all,

 These patches add support for building (grouping) the various targets per
 API, meaning that only one library will be created  for e.g. vdpau
 (libvdpau_gallium) with individual ones (libvdpau_r600) being a hardlink
 to it.

 This allows us to have substantial space savings as the API(state-tracker)
 is available only once. Additionally it adds support for shared
 pipe-drivers via a _unstable_ interface, which saves us the duplication
 across X APIs.

 The former method has been used by the egl-static while the latter by
 opencl and gbm targets since they were introduced.

 By default we build with static pipe-drivers.

 Some numbers + extra info [1]

 [Static]
 dri:(r600|radeonsi|nouveau)_dri.so   - 6.5 MiB
 vdpau:  libvdpau_(r600|radeonsi|nouveau).so  - 3.5 MiB

 Total: 10MiB

 [Shared]
 Libraries:
 dri:(r600|radeonsi|nouveau)_dri.so   - 3.9 MiB
 vdpau:  libvdpau_(r600|radeonsi|nouveau).so  - 633 KiB
 gallium-pipe:   pipe_(r600|radeonsi|nouveau).so  - 5.3 MiB

 Total: 9.8MiB

 [Current]
 dri:(r600|radeonsi|nouveau)_dri.so   - 5.0+4.5+5.3 = 14.8 
 MiB
 vdpau:  libvdpau_(r600|radeonsi|nouveau).so  - 1.9+1.2+2.3 = 5.4 
 MiB

 Total: 20.2MiB


 The previous series can be found here [2]
 Changes since then
  - Convert targets individually.
  - OMX targets now work, and the final library is now libomx-mesa.so
  - Dropped the DRI targets for now
  - A handfull of typos thinkos and bugs fixed.


 My plan is to have these pushed in ~4 stages, with two stages per week.
 This way I will be able to crack on with the remaining bits and have all
 of it tested well before we branch the next release.

 Series is availabe at
 https://github.com/evelikov/Mesa/tree/static-or-shared-pipe-drivers

 As always comments and suggestions are greatly appreciated.
 Thanks for working on this.  This is a tough issue to tackle.  I have
 a few questions/comments, which I am fine to see them resolved either
 before or after landing your series.

 I see this work as to define an internal API to manage pipe drivers.
 Interesting, I do not see this as an attempt to define an API, but to
 cleanup all the mayhem that our targets currently are:
  * Cleanup the build system - drop symlinks, including the same source
 files from different locations.
  * Make targets less error prone by using static pipe-drivers by
 default. Shared ones we lack versioning and ... are a big can of
 worms.
  * Minimize all the target.c duplication across each target. Makefiles
 are in similar boat.
The reason that the state trackers can manage statically linked pipe
drivers, or the duplications in target.c can be killed is because of
the introduction of an API (inline_drm_helper.h), or if you prefer,
helper functions.

Either way, a set of functions are defined to help manage statically
linked pipe drivers.  State trackers tend to do

#ifdef GALLIUM_STATIC_TARGETS
/* use inline_drm_helper.h */
...
#else
/* use pipe_loader.h */
...
#endif

IMHO, we should be able to define a single API, or a single set of
helper functions, to manage pipe drivers, no matter they are
statically linked or dynamically loaded.  Note that
inline_drm_helper.h is not stateless: dd_create_screen must be called
first to initialize a static variable.  It may even be possible to
extend pipe loader for the statically linked case.

  * Allow people to use the unstable pipe-drivers if they are really
 short on size and know what they are doing.

 The lack of such API previously led us to targets, where each target
 knows how to load a specific driver.  With your changes, state
 trackers that need to work with pipe drivers have a way to do so.  As
 a result, files such as

   dri/target.c,
   xa/target.c,
   xvmc/target.c,
   vdpau/target.c, and
   omx/target.c

 become quite dummy and redundant.  Do you see a way to get rid of
 targets entirely?

 Indeed if/when an API comes around these targets may become redundant.
Well, with inline_drm_helper.h and the like, there is already
basically nothing in those target.c.  I do not even get why we need
those #include's in them :)  As things are right now, for most state
trackers (dri, gbm, omx, vdpau, xa, and xvmc), there is a matching
target, and the only things in the target are rules to build it.

I am not suggesting you should update the series to kill the targets.
As I said, I believe it takes a lot of time to get things to where
they are now, and I am fine to see any of this resolved later.

 In the same view, and noticing that all users of the API have this snippet

 #if GALLIUM_STATIC_TARGETS
scrn-base.pscreen = dd_create_screen(fd);
 #else
if (pipe_loader_drm_probe_fd(scrn-base.dev, fd, true))
   scrn-base.pscreen

Re: [Mesa-dev] [PATCH] egl/dri2: do not leak dri2_dpy-driver_name

2014-06-02 Thread Chia-I Wu
On Sun, Jun 1, 2014 at 11:53 PM, Emil Velikov emil.l.veli...@gmail.com wrote:
 Originally all hardware drivers duplicate the driver_name string
 from an external source, while for the software rasterizer we set
 it to swrast. Follow the example set by hw drivers this way
 we can free the string at dri2_terminate().
Sounds fine to me.  But from a quick look, platform_drm gets the
driver name from gbm, without strdup() on it.  Does that need a
similar treatment too?

Maybe every platform should switch to use libloader at some point.



 v2: Use strdup over strndup. Suggested by Ilia Mirkin.

 Cc: Chia-I Wu o...@lunarg.com
 Signed-off-by: Emil Velikov emil.l.veli...@gmail.com
 ---

 Normally I prefer strn* functions, although in this case looks ugly.

 Thanks for the suggestion Ilia.
 -Emil

  src/egl/drivers/dri2/egl_dri2.c | 7 ++-
  1 file changed, 6 insertions(+), 1 deletion(-)

 diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
 index c1497b8..f10afed 100644
 --- a/src/egl/drivers/dri2/egl_dri2.c
 +++ b/src/egl/drivers/dri2/egl_dri2.c
 @@ -469,7 +469,11 @@ dri2_load_driver_swrast(_EGLDisplay *disp)
 struct dri2_egl_display *dri2_dpy = disp-DriverData;
 const __DRIextension **extensions;

 -   dri2_dpy-driver_name = swrast;
 +   /*
 +* Every hardware driver_name is set using strndup. Doing the same in
 +* here will allow is to simply free the memory at dri2_terminate().
 +*/
 +   dri2_dpy-driver_name = strdup(swrast);
 extensions = dri2_open_driver(disp);

 if (!extensions)
 @@ -673,6 +677,7 @@ dri2_terminate(_EGLDriver *drv, _EGLDisplay *disp)
 if (dri2_dpy-driver)
dlclose(dri2_dpy-driver);
 free(dri2_dpy-device_name);
 +   free(dri2_dpy-driver_name);

 switch (disp-Platform) {
  #ifdef HAVE_X11_PLATFORM
 --
 1.9.3




-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 2/2] egl-static: resolve library linking

2014-05-28 Thread Chia-I Wu
On Wed, May 28, 2014 at 10:58 PM, Emil Velikov emil.l.veli...@gmail.com wrote:
 With DRM_PLATFORM libloader.la in linked into libEGL pleading
 to multiple defition of the loader* symbols. For every other
 platform we need to explicitly link against it.
I would prefer to see libloader.la removed from st/egl, and added to
egl_gallium_la_LIBADD here when HAVE_EGL_PLATFORM_DRM.  The idea is
that we don't usually do LIBADD for state trackers, but rely on
targets to do the right thing.


 Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=79263
 Cc: José Fonseca jfons...@vmware.com
 Cc: Chia-I Wu o...@lunarg.com
 Signed-off-by: Emil Velikov emil.l.veli...@gmail.com
 ---
  src/gallium/targets/egl-static/Makefile.am | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

 diff --git a/src/gallium/targets/egl-static/Makefile.am 
 b/src/gallium/targets/egl-static/Makefile.am
 index f4990ad..224ed95 100644
 --- a/src/gallium/targets/egl-static/Makefile.am
 +++ b/src/gallium/targets/egl-static/Makefile.am
 @@ -66,7 +66,6 @@ egl_gallium_la_SOURCES = \
 egl_st.c

  egl_gallium_la_LIBADD = \
 -   $(top_builddir)/src/loader/libloader.la \
 $(top_builddir)/src/gallium/auxiliary/libgallium.la \
 $(top_builddir)/src/gallium/drivers/identity/libidentity.la \
 $(top_builddir)/src/gallium/drivers/trace/libtrace.la \
 @@ -100,6 +99,9 @@ AM_CPPFLAGS += $(LIBDRM_CFLAGS)
  egl_gallium_la_LIBADD += \
 $(top_builddir)/src/gbm/libgbm.la \
 $(LIBDRM_LIBS)
 +else
 +egl_gallium_la_LIBADD += \
 +   $(top_builddir)/src/loader/libloader.la
  endif

  if HAVE_EGL_PLATFORM_FBDEV
 --
 1.9.3




-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH] st/egl: do not link against libloader

2014-05-28 Thread Chia-I Wu
On Thu, May 29, 2014 at 10:43 AM, Emil Velikov emil.l.veli...@gmail.com wrote:
 Move the link to the final targets, like any other place in
 mesa/gallium. This allows better visibilty and will prevent
 us from including the library archive twice.

 Resolves multiple definition of `loader_get_pci_id_for_fd'
Thanks for working on this.  This patch is

Reviewed-by: Chia-I Wu o...@lunarg.com

 Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=79263
 Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=79382
 Cc: Chia-I Wu o...@lunarg.com
 Signed-off-by: Emil Velikov emil.l.veli...@gmail.com
 ---

 Strange... I could swear I did remove that one a while back.
 Either way, perhaps I should pay closer attention to the
 messages the build throws at us next time.

 -Emil

  src/gallium/state_trackers/egl/Makefile.am | 1 -
  1 file changed, 1 deletion(-)

 diff --git a/src/gallium/state_trackers/egl/Makefile.am 
 b/src/gallium/state_trackers/egl/Makefile.am
 index 26266ed..b7dcdab 100644
 --- a/src/gallium/state_trackers/egl/Makefile.am
 +++ b/src/gallium/state_trackers/egl/Makefile.am
 @@ -65,7 +65,6 @@ endif

  if HAVE_EGL_PLATFORM_DRM
  libegl_la_SOURCES += $(drm_FILES)
 -libegl_la_LIBADD = $(top_builddir)/src/loader/libloader.la
  AM_CFLAGS += \
 $(LIBDRM_CFLAGS)
  AM_CPPFLAGS += \
 --
 1.9.3




-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 2/3] gallium/egl: st_profiles are build time decision, treat them as such

2014-05-18 Thread Chia-I Wu
On Tue, May 13, 2014 at 10:35 AM, Emil Velikov emil.l.veli...@gmail.com wrote:
 On 13/05/14 02:57, Chia-I Wu wrote:
 On Sat, May 10, 2014 at 10:41 AM, Emil Velikov emil.l.veli...@gmail.com 
 wrote:
 The profiles are present depending on the defines at build time.
 Drop the extra functions and feed the defines directly into the
 state-tracker at build time.
 Do you have other changes planned that require this one?  The current
 code deals with st/vega and st/mesa entirely in targets/egl-static,
 which is good separation IMHO, but can also be viewed as unnecessary
 as this patch demonstrates.

 Yes I have actually, although the different variations of sw winsys are
 causing some annoyance.
I am fine with the change then.
 The plan is to have two build modes - shared pipe-drivers(loaded via
 pipe-loader) and static (megadriver style) for most(all) targets. With static
 one as the default.

 With that done one will be able to cleanup all the targetst screen_create
 vtables. On a related note: I was wondering if we can squash the egl_gallium
 into libEGL like other platform do. The idea will help us cleanup the exported
 functions namespace which exposes a few internal callbacks + close a bug or
 two that they cause. How does that sound ?
This sounds nice too.

 -Emil


 Cc: Chia-I Wu olva...@gmail.com
 Signed-off-by: Emil Velikov emil.l.veli...@gmail.com
 ---
  src/gallium/state_trackers/egl/Android.mk  |  5 +++-
  src/gallium/state_trackers/egl/SConscript  | 12 +
  src/gallium/state_trackers/egl/common/egl_g3d.c| 20 +--
  .../state_trackers/egl/common/egl_g3d_loader.h |  1 -
  src/gallium/targets/egl-static/Android.mk  |  2 --
  src/gallium/targets/egl-static/SConscript  |  6 -
  src/gallium/targets/egl-static/egl.c   |  3 ---
  src/gallium/targets/egl-static/egl_st.c| 29 
 --
  src/gallium/targets/egl-static/egl_st.h|  3 ---
  9 files changed, 28 insertions(+), 53 deletions(-)

 diff --git a/src/gallium/state_trackers/egl/Android.mk 
 b/src/gallium/state_trackers/egl/Android.mk
 index b27e14b..7c4c936 100644
 --- a/src/gallium/state_trackers/egl/Android.mk
 +++ b/src/gallium/state_trackers/egl/Android.mk
 @@ -32,7 +32,10 @@ LOCAL_SRC_FILES := \
 $(common_FILES) \
 $(android_FILES)

 -LOCAL_CFLAGS := -DHAVE_ANDROID_BACKEND
 +LOCAL_CFLAGS := \
 +   -DFEATURE_ES1=1 \
 +   -DFEATURE_ES2=1 \
 +   -DHAVE_ANDROID_BACKEND

  LOCAL_C_INCLUDES := \
 $(GALLIUM_TOP)/state_trackers/egl \
 diff --git a/src/gallium/state_trackers/egl/SConscript 
 b/src/gallium/state_trackers/egl/SConscript
 index 3ddf0bc..3727fb2 100644
 --- a/src/gallium/state_trackers/egl/SConscript
 +++ b/src/gallium/state_trackers/egl/SConscript
 @@ -14,6 +14,18 @@ env.Append(CPPPATH = [

  sources = env.ParseSourceList('Makefile.sources', 'common_FILES')

 +# OpenGL ES and OpenGL
 +if env['gles']:
 +env.Append(CPPDEFINES = [
 +'FEATURE_GL=1',
 +'FEATURE_ES1=1',
 +'FEATURE_ES2=1'
 +])
 +
 +# OpenVG
 +if True:
 +env.Append(CPPDEFINES = ['FEATURE_VG=1'])
 +
  if env['platform'] == 'windows':
  env.Append(CPPDEFINES = ['HAVE_GDI_BACKEND'])
  sources.append(env.ParseSourceList('Makefile.sources', 'gdi_FILES'))
 diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.c 
 b/src/gallium/state_trackers/egl/common/egl_g3d.c
 index 7cc4e8f..d3f5e92 100644
 --- a/src/gallium/state_trackers/egl/common/egl_g3d.c
 +++ b/src/gallium/state_trackers/egl/common/egl_g3d.c
 @@ -548,14 +548,18 @@ egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy)
goto fail;
 }

 -   if (gdpy-loader-profile_masks[ST_API_OPENGL]  
 ST_PROFILE_DEFAULT_MASK)
 -  dpy-ClientAPIs |= EGL_OPENGL_BIT;
 -   if (gdpy-loader-profile_masks[ST_API_OPENGL]  
 ST_PROFILE_OPENGL_ES1_MASK)
 -  dpy-ClientAPIs |= EGL_OPENGL_ES_BIT;
 -   if (gdpy-loader-profile_masks[ST_API_OPENGL]  
 ST_PROFILE_OPENGL_ES2_MASK)
 -  dpy-ClientAPIs |= EGL_OPENGL_ES2_BIT;
 -   if (gdpy-loader-profile_masks[ST_API_OPENVG]  
 ST_PROFILE_DEFAULT_MASK)
 -  dpy-ClientAPIs |= EGL_OPENVG_BIT;
 +#if FEATURE_GL
 +   dpy-ClientAPIs |= EGL_OPENGL_BIT;
 +#endif
 +#if FEATURE_ES1
 +   dpy-ClientAPIs |= EGL_OPENGL_ES_BIT;
 +#endif
 +#if FEATURE_ES2
 +   dpy-ClientAPIs |= EGL_OPENGL_ES2_BIT;
 +#endif
 +#if FEATURE_VG
 +   dpy-ClientAPIs |= EGL_OPENVG_BIT;
 +#endif

 gdpy-smapi = egl_g3d_create_st_manager(dpy);
 if (!gdpy-smapi) {
 diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_loader.h 
 b/src/gallium/state_trackers/egl/common/egl_g3d_loader.h
 index 51b4d19..03db153 100644
 --- a/src/gallium/state_trackers/egl/common/egl_g3d_loader.h
 +++ b/src/gallium/state_trackers/egl/common/egl_g3d_loader.h
 @@ -36,7 +36,6 @@ struct pipe_screen;
  struct sw_winsys;

  struct egl_g3d_loader {
 -   uint profile_masks[ST_API_COUNT];
 struct st_api *(*get_st_api)(enum st_api_type api);

 struct

Re: [Mesa-dev] [PATCH 2/3] gallium/egl: st_profiles are build time decision, treat them as such

2014-05-12 Thread Chia-I Wu
On Sat, May 10, 2014 at 10:41 AM, Emil Velikov emil.l.veli...@gmail.com wrote:
 The profiles are present depending on the defines at build time.
 Drop the extra functions and feed the defines directly into the
 state-tracker at build time.
Do you have other changes planned that require this one?  The current
code deals with st/vega and st/mesa entirely in targets/egl-static,
which is good separation IMHO, but can also be viewed as unnecessary
as this patch demonstrates.


 Cc: Chia-I Wu olva...@gmail.com
 Signed-off-by: Emil Velikov emil.l.veli...@gmail.com
 ---
  src/gallium/state_trackers/egl/Android.mk  |  5 +++-
  src/gallium/state_trackers/egl/SConscript  | 12 +
  src/gallium/state_trackers/egl/common/egl_g3d.c| 20 +--
  .../state_trackers/egl/common/egl_g3d_loader.h |  1 -
  src/gallium/targets/egl-static/Android.mk  |  2 --
  src/gallium/targets/egl-static/SConscript  |  6 -
  src/gallium/targets/egl-static/egl.c   |  3 ---
  src/gallium/targets/egl-static/egl_st.c| 29 
 --
  src/gallium/targets/egl-static/egl_st.h|  3 ---
  9 files changed, 28 insertions(+), 53 deletions(-)

 diff --git a/src/gallium/state_trackers/egl/Android.mk 
 b/src/gallium/state_trackers/egl/Android.mk
 index b27e14b..7c4c936 100644
 --- a/src/gallium/state_trackers/egl/Android.mk
 +++ b/src/gallium/state_trackers/egl/Android.mk
 @@ -32,7 +32,10 @@ LOCAL_SRC_FILES := \
 $(common_FILES) \
 $(android_FILES)

 -LOCAL_CFLAGS := -DHAVE_ANDROID_BACKEND
 +LOCAL_CFLAGS := \
 +   -DFEATURE_ES1=1 \
 +   -DFEATURE_ES2=1 \
 +   -DHAVE_ANDROID_BACKEND

  LOCAL_C_INCLUDES := \
 $(GALLIUM_TOP)/state_trackers/egl \
 diff --git a/src/gallium/state_trackers/egl/SConscript 
 b/src/gallium/state_trackers/egl/SConscript
 index 3ddf0bc..3727fb2 100644
 --- a/src/gallium/state_trackers/egl/SConscript
 +++ b/src/gallium/state_trackers/egl/SConscript
 @@ -14,6 +14,18 @@ env.Append(CPPPATH = [

  sources = env.ParseSourceList('Makefile.sources', 'common_FILES')

 +# OpenGL ES and OpenGL
 +if env['gles']:
 +env.Append(CPPDEFINES = [
 +'FEATURE_GL=1',
 +'FEATURE_ES1=1',
 +'FEATURE_ES2=1'
 +])
 +
 +# OpenVG
 +if True:
 +env.Append(CPPDEFINES = ['FEATURE_VG=1'])
 +
  if env['platform'] == 'windows':
  env.Append(CPPDEFINES = ['HAVE_GDI_BACKEND'])
  sources.append(env.ParseSourceList('Makefile.sources', 'gdi_FILES'))
 diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.c 
 b/src/gallium/state_trackers/egl/common/egl_g3d.c
 index 7cc4e8f..d3f5e92 100644
 --- a/src/gallium/state_trackers/egl/common/egl_g3d.c
 +++ b/src/gallium/state_trackers/egl/common/egl_g3d.c
 @@ -548,14 +548,18 @@ egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy)
goto fail;
 }

 -   if (gdpy-loader-profile_masks[ST_API_OPENGL]  ST_PROFILE_DEFAULT_MASK)
 -  dpy-ClientAPIs |= EGL_OPENGL_BIT;
 -   if (gdpy-loader-profile_masks[ST_API_OPENGL]  
 ST_PROFILE_OPENGL_ES1_MASK)
 -  dpy-ClientAPIs |= EGL_OPENGL_ES_BIT;
 -   if (gdpy-loader-profile_masks[ST_API_OPENGL]  
 ST_PROFILE_OPENGL_ES2_MASK)
 -  dpy-ClientAPIs |= EGL_OPENGL_ES2_BIT;
 -   if (gdpy-loader-profile_masks[ST_API_OPENVG]  ST_PROFILE_DEFAULT_MASK)
 -  dpy-ClientAPIs |= EGL_OPENVG_BIT;
 +#if FEATURE_GL
 +   dpy-ClientAPIs |= EGL_OPENGL_BIT;
 +#endif
 +#if FEATURE_ES1
 +   dpy-ClientAPIs |= EGL_OPENGL_ES_BIT;
 +#endif
 +#if FEATURE_ES2
 +   dpy-ClientAPIs |= EGL_OPENGL_ES2_BIT;
 +#endif
 +#if FEATURE_VG
 +   dpy-ClientAPIs |= EGL_OPENVG_BIT;
 +#endif

 gdpy-smapi = egl_g3d_create_st_manager(dpy);
 if (!gdpy-smapi) {
 diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_loader.h 
 b/src/gallium/state_trackers/egl/common/egl_g3d_loader.h
 index 51b4d19..03db153 100644
 --- a/src/gallium/state_trackers/egl/common/egl_g3d_loader.h
 +++ b/src/gallium/state_trackers/egl/common/egl_g3d_loader.h
 @@ -36,7 +36,6 @@ struct pipe_screen;
  struct sw_winsys;

  struct egl_g3d_loader {
 -   uint profile_masks[ST_API_COUNT];
 struct st_api *(*get_st_api)(enum st_api_type api);

 struct pipe_screen *(*create_drm_screen)(const char *name, int fd);
 diff --git a/src/gallium/targets/egl-static/Android.mk 
 b/src/gallium/targets/egl-static/Android.mk
 index 37244b5..01408a7 100644
 --- a/src/gallium/targets/egl-static/Android.mk
 +++ b/src/gallium/targets/egl-static/Android.mk
 @@ -31,8 +31,6 @@ LOCAL_SRC_FILES := \
 egl_st.c

  LOCAL_CFLAGS := \
 -   -DFEATURE_ES1=1 \
 -   -DFEATURE_ES2=1 \
 -D_EGL_MAIN=_eglBuiltInDriverGALLIUM

  LOCAL_C_INCLUDES := \
 diff --git a/src/gallium/targets/egl-static/SConscript 
 b/src/gallium/targets/egl-static/SConscript
 index 83937fe..f879cc3 100644
 --- a/src/gallium/targets/egl-static/SConscript
 +++ b/src/gallium/targets/egl-static/SConscript
 @@ -63,11 +63,6 @@ if env['platform'] == 'windows':

  # OpenGL ES and OpenGL
  if env['gles

Re: [Mesa-dev] [PATCH 3/3] egl-static: include libradeonwinsys.la only once

2014-05-12 Thread Chia-I Wu
On Tue, May 13, 2014 at 7:15 AM, Emil Velikov emil.l.veli...@gmail.com wrote:
 With this and the previous patch, we no longer have multiple
 definitions in the final egl_gallium.so.
Looks good to me.

 Cc: Chia-I Wu o...@lunarg.com
 Signed-off-by: Emil Velikov emil.l.veli...@gmail.com
 ---
  src/gallium/targets/egl-static/Makefile.am | 12 +---
  1 file changed, 5 insertions(+), 7 deletions(-)

 diff --git a/src/gallium/targets/egl-static/Makefile.am 
 b/src/gallium/targets/egl-static/Makefile.am
 index 332b38d..4378fa3 100644
 --- a/src/gallium/targets/egl-static/Makefile.am
 +++ b/src/gallium/targets/egl-static/Makefile.am
 @@ -75,10 +75,6 @@ if HAVE_MESA_LLVM
  AM_LDFLAGS += $(LLVM_LDFLAGS)
  endif

 -egl_gallium_la_LDFLAGS = \
 -   $(AM_LDFLAGS) \
 -   -Wl,--allow-multiple-definition
 -
  if HAVE_EGL_PLATFORM_X11
  AM_CPPFLAGS += $(LIBDRM_CFLAGS)
  egl_gallium_la_LIBADD += \
 @@ -183,6 +179,11 @@ egl_gallium_la_LIBADD += \
 $(NOUVEAU_LIBS)
  endif

 +if NEED_RADEON_DRM_WINSYS
 +egl_gallium_la_LIBADD += \
 +   $(top_builddir)/src/gallium/winsys/radeon/drm/libradeonwinsys.la
 +endif
 +
  if HAVE_GALLIUM_RADEON_COMMON
  egl_gallium_la_LIBADD += \
 $(top_builddir)/src/gallium/drivers/radeon/libradeon.la
 @@ -191,7 +192,6 @@ endif
  if HAVE_GALLIUM_R300
  AM_CPPFLAGS += -D_EGL_PIPE_R300=1
  egl_gallium_la_LIBADD += \
 -   $(top_builddir)/src/gallium/winsys/radeon/drm/libradeonwinsys.la \
 $(top_builddir)/src/gallium/drivers/r300/libr300.la \
 $(RADEON_LIBS)
  endif
 @@ -199,7 +199,6 @@ endif
  if HAVE_GALLIUM_R600
  AM_CPPFLAGS += -D_EGL_PIPE_R600=1
  egl_gallium_la_LIBADD += \
 -   $(top_builddir)/src/gallium/winsys/radeon/drm/libradeonwinsys.la \
 $(top_builddir)/src/gallium/drivers/r600/libr600.la \
 $(RADEON_LIBS)
  endif
 @@ -207,7 +206,6 @@ endif
  if HAVE_GALLIUM_RADEONSI
  AM_CPPFLAGS += -D_EGL_PIPE_RADEONSI=1
  egl_gallium_la_LIBADD += \
 -   $(top_builddir)/src/gallium/winsys/radeon/drm/libradeonwinsys.la \
 $(top_builddir)/src/gallium/drivers/radeonsi/libradeonsi.la \
 $(RADEON_LIBS)
  endif
 --
 1.9.2




-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [Mesa-stable] A candidate branch for the next stable release

2014-05-12 Thread Chia-I Wu
Hi Carl,

On Fri, May 2, 2014 at 1:44 AM, Carl Worth cwo...@cworth.org wrote:
 I've recently pushed an update to the 10.1 branch. I anticipate making a
 release from this branch tomorrow. The state of this branch is
 summarized here:


 http://cworth.org/~cworth/mesa-stable-queue/

 As always, please let me know if I have missed something that should be
 picked over to the stable branch.
I'd like to nominate this commit on master for 10.1.4

commit 9245206cbfaaa4e18c1f3715eebb5f281070d772
Author: Eric Anholt e...@anholt.net
Date:   Fri Feb 14 16:06:31 2014 -0800

i965/vs: Use samplers for UBOs in the VS like we do for non-UBO pulls.

Improves performance of a dolphin emulator trace I had laying around by
3.60131% +/- 0.995887% (n=128).

Reviewed-by: Kenneth Graunke kenn...@whitecape.org

It makes a really huge performance improvement for one application
that I am looking into, and the change is logically simple.  Should I
generate a patch and send it to mesa-stable to get it reviewed and
included?


 The code on this branch includes 32 commits since 10.1.1 and introduces
 no regressions as tested with piglit on my Haswell laptop. I would, of
 course, welcome any additional testing reports from users of other
 drivers.

 There are a couple of points of concern which, if addressed, could lead
 to some changes between now and the release:

   * There are 23 patches that have been sent to the mesa-stable mailing
 list, but have not yet been merged to master. The oldest of these is
 from February 20 (10 weeks ago!).

 Presumably, we could use some help reviewing these patches. Please
 see the list of Nominated, awaiting review patches at the URL
 above.

   * I rejected one patch, (i965: Add glBlitFramebuffer to commands
 affected by conditional rendering), based on a piglit regression it
 caused. The relevant bug report:

 https://bugs.freedesktop.org/show_bug.cgi?id=77702

 suggests that the test itself is at fault here. If that's correct,
 and the test can be updated, then this patch can be merged before
 the release.

 Thanks everyone,

 -Carl

 --
 carl.d.wo...@intel.com

 ___
 mesa-stable mailing list
 mesa-sta...@lists.freedesktop.org
 http://lists.freedesktop.org/mailman/listinfo/mesa-stable




-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH] ilo: destroy the mutex, if winsys creation fails

2014-05-08 Thread Chia-I Wu
On Fri, May 9, 2014 at 2:09 AM, Emil Velikov emil.l.veli...@gmail.com wrote:
 Cc: Chia-I Wu olva...@gmail.com
 Signed-off-by: Emil Velikov emil.l.veli...@gmail.com
Reviewed-by: Chia-I Wu olva...@gmail.com

 ---
  src/gallium/winsys/intel/drm/intel_drm_winsys.c | 1 +
  1 file changed, 1 insertion(+)

 diff --git a/src/gallium/winsys/intel/drm/intel_drm_winsys.c 
 b/src/gallium/winsys/intel/drm/intel_drm_winsys.c
 index d34246a..00c4a46 100644
 --- a/src/gallium/winsys/intel/drm/intel_drm_winsys.c
 +++ b/src/gallium/winsys/intel/drm/intel_drm_winsys.c
 @@ -181,6 +181,7 @@ intel_winsys_create_for_fd(int fd)
 pipe_mutex_init(winsys-mutex);

 if (!probe_winsys(winsys)) {
 +  pipe_mutex_destroy(winsys-mutex);
drm_intel_bufmgr_destroy(winsys-bufmgr);
FREE(winsys);
return NULL;
 --
 1.9.2




-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 00/21] deferred and threaded glCompileShader

2014-05-06 Thread Chia-I Wu
On Tue, May 6, 2014 at 5:27 AM, Fredrik Höglund fred...@kde.org wrote:
 On Tuesday 22 April 2014, Chia-I Wu wrote:
 Hi list,

 This series adds a thread pool to the GLSL compiler, and a drirc option to
 defer glCompileShader calls to the pool.  The goal is to reduce the start-up
 time of applications that are aware of this feature.  That is, applications
 that compile shaders first and check the compile status later.

 I do not have numbers from real applications yet.  But trying to compiling a
 set of 2882 shaders extracted from some trace file, with everything else
 idled, the time it takes is

   8 threads: 17.8s
   4 threads: 20.3s
   2 threads: 31.2s
   1 threads: 58.0s
   no thread pool: 54.5

 on a quad core system.

 Patches 1-4 fix potential races in the GLSL compiler.  As the compiler is
 already shared by all contexts, these patches could be desirable even without
 the thread pool that I am going to add.

 Patches 5-18 adds true GL_DEBUG_OUTPUT_SYNCHRONOUS support to the KHR_debug
 code.  All except patch 18 are clean-ups.  Patch 18 adds a mutex to protect
 gl_debug_state.

 Patch 19 defines a simple API to create and work with thread pools, as well 
 as
 a test for the API.

 Patch 20 adds the singleton GLSL thread pool and allows glCompileShader to be
 deferred to the pool.  This feature needs to be explicitly enabled with
 _mesa_enable_glsl_threadpool.

 Patch 21 adds a drirc option to enable the thread pool.  The idea is that 
 only
 applications that can benefit from it will enable it.

 If applications are supposed to enable this behavior themselves I think
 it would be better to add an extension that lets them do:

 glEnable(GL_DEFERRED_SHADER_COMPILATION_EXT);
glHint might be better.  But it is hard to define the behavior of
deferred shader compilation without restricting what an implementation
may do.  And for a driver that is able to determine GL_COMPILE_STATUS
quickly and defer only the optimization passes, threaded compile may
be always on.



 The drirc option can still be useful for overriding the default though.

 Fredrik




-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 02/21] glsl: protect locale_t with a mutex

2014-05-06 Thread Chia-I Wu
On Tue, May 6, 2014 at 6:04 AM, Kenneth Graunke kenn...@whitecape.org wrote:
 On 05/05/2014 10:01 AM, Ian Romanick wrote:
 On 05/04/2014 02:14 PM, Chia-I Wu wrote:
 On Sat, May 3, 2014 at 1:52 AM, Ian Romanick i...@freedesktop.org wrote:
 On 04/22/2014 01:58 AM, Chia-I Wu wrote:
 There may be two contexts compiling shaders at the same time.  locale_t 
 needs
 to be protected.

 Rather than calling glsl_initialize_strtod from other places in the
 compiler, it seems better to use call_once from the strtof and strtod
 functions.
 How about having a static object to call newlocale()/freelocale() in
 its constructor/destructor?  It will impose no overead on
 glsl_strtod(), at the expense of little wasted memory when the
 applications do not compile shaders.

 The problem I see with that is we don't know what order constructors on
 global objects will occur.  Are we sure the contructor will be invoked
 before we need the locale now and in the future?

 These functions are used during lexing to read floating point
 literals...without breaking on locales where the decimal point is a comma.

 All constructors have definitely been run by that point, and I can't
 imagine we'll ever need to call locale-independent strtof/strtod from
 other constructors.
They are also used by the IR reader.  But the IR reader is no longer
used to parse built-in functions or so.  We should be good as you
said.

Not that we need this, and I am not saying this with 100% confidence,
from my research on stackoverflow (instead of the standard, sorry), it
is the initialization order of static objects from different
translation units that are undefined.  If this locale_t_initializer
was defined statically in strtod.cpp, other static constructors
calling glsl_strtod() would actually work because, by the time
glsl_strtod() is called, locale_t_initializer is guaranteed to be
initialized.

Anyway, I should add some assert() just in case.


 --Ken




-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 7/8] i965/vs: Enable SPF when the shader contains no control flow.

2014-05-06 Thread Chia-I Wu
On Wed, May 7, 2014 at 9:38 AM, Matt Turner matts...@gmail.com wrote:
 ---
  src/mesa/drivers/dri/i965/gen6_vs_state.c | 3 ++-
  src/mesa/drivers/dri/i965/gen7_vs_state.c | 3 ++-
  src/mesa/drivers/dri/i965/gen8_vs_state.c | 3 ++-
  3 files changed, 6 insertions(+), 3 deletions(-)

 diff --git a/src/mesa/drivers/dri/i965/gen6_vs_state.c 
 b/src/mesa/drivers/dri/i965/gen6_vs_state.c
 index 0af87d1..bdfb9b5 100644
 --- a/src/mesa/drivers/dri/i965/gen6_vs_state.c
 +++ b/src/mesa/drivers/dri/i965/gen6_vs_state.c
 @@ -167,7 +167,8 @@ upload_vs_state(struct brw_context *brw)
 OUT_BATCH(floating_point_mode |
  ((ALIGN(stage_state-sampler_count, 4)/4)  
 GEN6_VS_SAMPLER_COUNT_SHIFT) |
   ((brw-vs.prog_data-base.base.binding_table.size_bytes / 4) 
 -  GEN6_VS_BINDING_TABLE_ENTRY_COUNT_SHIFT));
 +  GEN6_VS_BINDING_TABLE_ENTRY_COUNT_SHIFT) |
 + (!brw-vs.prog_data-base.has_control_flow ? GEN6_VS_SPF_MODE : 
 0));
The doc says bit 31 is Single Vertex Dispatch.  When this bit is
set, I vaguely remember VS_INVOCATION_COUNT does get doubled for the
same workload, and the performance is hurt.


 if (brw-vs.prog_data-base.total_scratch) {
OUT_RELOC(stage_state-scratch_bo,
 diff --git a/src/mesa/drivers/dri/i965/gen7_vs_state.c 
 b/src/mesa/drivers/dri/i965/gen7_vs_state.c
 index b5fc871..f9c9abc 100644
 --- a/src/mesa/drivers/dri/i965/gen7_vs_state.c
 +++ b/src/mesa/drivers/dri/i965/gen7_vs_state.c
 @@ -97,7 +97,8 @@ upload_vs_state(struct brw_context *brw)
  ((ALIGN(stage_state-sampler_count, 4)/4) 
GEN6_VS_SAMPLER_COUNT_SHIFT) |
   ((brw-vs.prog_data-base.base.binding_table.size_bytes / 4) 
 -  GEN6_VS_BINDING_TABLE_ENTRY_COUNT_SHIFT));
 +  GEN6_VS_BINDING_TABLE_ENTRY_COUNT_SHIFT) |
 + (!brw-vs.prog_data-base.has_control_flow ? GEN6_VS_SPF_MODE : 
 0));

 if (brw-vs.prog_data-base.total_scratch) {
OUT_RELOC(stage_state-scratch_bo,
 diff --git a/src/mesa/drivers/dri/i965/gen8_vs_state.c 
 b/src/mesa/drivers/dri/i965/gen8_vs_state.c
 index 373cfe4..a83d78b 100644
 --- a/src/mesa/drivers/dri/i965/gen8_vs_state.c
 +++ b/src/mesa/drivers/dri/i965/gen8_vs_state.c
 @@ -85,7 +85,8 @@ upload_vs_state(struct brw_context *brw)
   ((ALIGN(stage_state-sampler_count, 4) / 4) 
 GEN6_VS_SAMPLER_COUNT_SHIFT) |
   ((prog_data-base.binding_table.size_bytes / 4) 
 -   GEN6_VS_BINDING_TABLE_ENTRY_COUNT_SHIFT));
 +   GEN6_VS_BINDING_TABLE_ENTRY_COUNT_SHIFT) |
 + (!brw-vs.prog_data-base.has_control_flow ? GEN6_VS_SPF_MODE : 
 0));

 if (prog_data-total_scratch) {
OUT_RELOC64(stage_state-scratch_bo,
 --
 1.8.3.2

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



-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 20/21] mesa: add support for threaded glCompileShader

2014-05-06 Thread Chia-I Wu
On Mon, May 5, 2014 at 5:37 AM, Chia-I Wu olva...@gmail.com wrote:
 On Sat, May 3, 2014 at 1:59 AM, Ian Romanick i...@freedesktop.org wrote:
 On 04/22/2014 01:58 AM, Chia-I Wu wrote:
 From: Chia-I Wu o...@lunarg.com

 Threaded glCompileShader can be enabled for a context by calling
 _mesa_enable_glsl_threadpool.  It will initialize the singleton GLSL thread
 pool and defer glCompileShader calls to the thread pool.

 For applications to benefit from threaded glCompileShader, they have to
 compile shaders in this fashion

  for (i = 0; i  num_shaders; i++)
glCompileShader(shaders[i]);
  for (i = 0; i  num_shaders; i++)
glGetShaderiv(shaders[i], GL_COMPILE_STATUS, val);

 I think when you try this series on some real applications, you will be
 disappointed.  Eric had a pretty similar branch
 (http://cgit.freedesktop.org/~anholt/mesa/log/?h=compiler-threads), but
 it saw no benefit on any applications... because everybody does

 for (i = 0; i  num_shaders; i++) {
 glCompileShader(shaders[i]);
 glGetShaderiv(shaders[i], GL_COMPILE_STATUS, val);
 }

 or

 for (i = 0; i  num_shaders; i++) {
 glCompileShader(shaders[i]);
 glAttachShader(prog, shaders[i]);
 }

 glLinkProgram(prog);
 Yeah, I am aware of the situation with real-world applications.  Only
 applications that are modified to not immediately check compilation results
 will get the speed up in compile times.  That is why this feature needs to be
 enabled through drirc.  We, at LunarG, are working with major game engines
 vendors to ensure this performance benefit is realized.

 I'm also curious about your test case... did you link the shaders?  As
 far as I'm aware, the bulk of time spent in the compiler happens during
 linking (final optimizations and register allocation).  Eric's data
 (http://lists.freedesktop.org/archives/mesa-dev/2014-April/057494.html)
 says we spend more than 2x time in linking than in compiling.
 No, I did not.  In my other experiment with Unigine Tropics, the
 distribution of time was more like

 glCompileShader: 50%
 glLinkProgram FE: 25%
 glLinkProgram BE: 25%
I've rerun the test (source attached).  The numbers from compiling and
linking Unigine Tropics shaders are

  _mesa_CompileShader: 54.8%
  link_shaders: 17.1%
  brw_link_shaders: 27.9%

The numbers from running on another set of shaders (took about 100 seconds) are

  _mesa_CompileShader: 50.4%
  link_shaders: 5.6%
  brw_link_shaders: 43.8%


-- 
o...@lunarg.com
#include stdio.h
#include string.h
#include sys/types.h
#include sys/time.h
#include dirent.h
#include GL/glew.h
#include GL/glut.h
#include GL/freeglut_ext.h

#define MAX_PROGRAMS 4100
struct {
	GLuint prog;
	long long prog_time;
	long long shader_times[2];
} progs[MAX_PROGRAMS];

static GLuint create_shader(int id, GLenum type)
{
	char filename[32];
	size_t size;
	FILE *fp;
	char *buf;
	GLuint sh;

	switch (type) {
	case GL_VERTEX_SHADER:
		snprintf(filename, sizeof(filename), %d.vert, id);
		break;
	case GL_FRAGMENT_SHADER:
		snprintf(filename, sizeof(filename), %d.frag, id);
		break;
	default:
		return 0;
		break;
	}

	fp = fopen(filename, rb);
	if (!fp)
		return 0;

	fseek(fp, 0, SEEK_END);
	size = ftell(fp);
	if (!size) {
		fclose(fp);
		return 0;
	}

	fseek(fp, 0, SEEK_SET);
	buf = malloc(size + 1);
	if (!buf) {
		fclose(fp);
		return 0;
	}

	if (fread(buf, 1, size, fp) != size) {
		printf(error reading %s\n, filename);
		fclose(fp);
		return 0;
	}

	buf[size] = '\0';
	fclose(fp);

	sh = glCreateShader(type);
	glShaderSource(sh, 1, (void*)buf, NULL);

	return sh;
}

static void compile_all_shaders(void)
{
	struct timeval start, end;
	GLint val;
	int i;

	for (i = 0; i  MAX_PROGRAMS; i++) {
		GLuint prog;
		int num_shaders, j;

		prog = glCreateProgram();

		num_shaders = 0;
		for (j = 0; j  2; j++) {
			GLenum type = (j == 0) ? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER;
			GLuint sh;

			sh = create_shader(i, type);
			if (!sh)
continue;

			num_shaders++;
			gettimeofday(start, NULL);
			glCompileShader(sh);
			gettimeofday(end, NULL);

			glGetShaderiv(sh, GL_COMPILE_STATUS, val);
			if (!val) {
char buf[1024];
GLsizei len;
glGetShaderInfoLog(sh, sizeof(buf), len, buf);
printf(%d.%d: %*s\n, i, j, len, buf);
			}

			progs[i].shader_times[j] = 100ll * (end.tv_sec - start.tv_sec) +
((long long) end.tv_usec - start.tv_usec);

			glAttachShader(prog, sh);
			glDeleteShader(sh);
		}

		if (num_shaders  j) {
			if (num_shaders) {
;//glProgramParameteri(prog, GL_PROGRAM_SEPARABLE, GL_TRUE);
			}
			else {
glDeleteProgram(prog);
continue;
			}
		}

		gettimeofday(start, NULL);
		glLinkProgram(prog);
		gettimeofday(end, NULL);

		glGetProgramiv(prog, GL_LINK_STATUS, val);
		if (!val) {
			char buf[1024];
			GLsizei len;
			glGetProgramInfoLog(prog, sizeof(buf), len, buf);
			printf(%d: %*s\n, i, len, buf);
		}

		progs[i].prog = prog;
		progs[i].prog_time = 100ll * (end.tv_sec - start.tv_sec) +
			((long long

Re: [Mesa-dev] [PATCH 02/21] glsl: protect locale_t with a mutex

2014-05-04 Thread Chia-I Wu
On Sat, May 3, 2014 at 1:52 AM, Ian Romanick i...@freedesktop.org wrote:
 On 04/22/2014 01:58 AM, Chia-I Wu wrote:
 There may be two contexts compiling shaders at the same time.  locale_t needs
 to be protected.

 Rather than calling glsl_initialize_strtod from other places in the
 compiler, it seems better to use call_once from the strtof and strtod
 functions.
How about having a static object to call newlocale()/freelocale() in
its constructor/destructor?  It will impose no overead on
glsl_strtod(), at the expense of little wasted memory when the
applications do not compile shaders.

-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 03/21] glsl: protect anonymous struct id with a mutex

2014-05-04 Thread Chia-I Wu
On Sat, May 3, 2014 at 1:33 AM, Ian Romanick i...@freedesktop.org wrote:
 On 04/22/2014 01:58 AM, Chia-I Wu wrote:
 There may be two contexts compiling shaders at the same time, and we want the
 anonymous struct id to be globally unique.

 I am not very excited about this.

 Is there any chance of getting stdatomic.h for the MSVC compilers that
 people care about?  I'd much rather have this code be...

if (identifier == NULL) {
   static volatile atomic_uint_t anon_count = ATOMIC_VAR_INIT(1);
   unsigned count;

   count = atomic_fetch_add(anon_count, 1);
   identifier = ralloc_asprintf(this, #anon_struct_%04x, count);
}
I could not find any portable stdatomic.h implementation from a quick
search.  One thing we may
do is to have

$ cat $mesa/include/c11/stdatomic.h
#if __STDC_VERSION__ = 201112L  !defined(__STDC_NO_ATOMICS__)
#include stdatomic.h
#else

/* a implementation that is good enough for us */
#include threads.h

#define ATOMIC_VAR_INIT(val) { _MTX_INITIALIZER_NP, (val) }

typedef struct atomic_uint_t {
   mtx_t mutex;
   unsigned int val;
} atomic_uint_t;

static inline unsigned int
atomic_fetch_add(volatile atomic_uint_t *a)
{
unsigned int val;

mtx_lock(a-mutex);
val = a-val++;
mtx_unlock(a-mutex);

return val;
}
#endif

Whoever needs more than reference counting with unsigned int will need
to extend it a bit on systems where there is no stdatomic.h.  And
maybe we are better off without naming it stdatomic.h.  Ideas?


 Signed-off-by: Chia-I Wu o...@lunarg.com
 ---
  src/glsl/glsl_parser_extras.cpp | 10 --
  1 file changed, 8 insertions(+), 2 deletions(-)

 diff --git a/src/glsl/glsl_parser_extras.cpp 
 b/src/glsl/glsl_parser_extras.cpp
 index 91c9285..30e284b 100644
 --- a/src/glsl/glsl_parser_extras.cpp
 +++ b/src/glsl/glsl_parser_extras.cpp
 @@ -1332,9 +1332,15 @@ ast_struct_specifier::ast_struct_specifier(const char 
 *identifier,
  ast_declarator_list 
 *declarator_list)
  {
 if (identifier == NULL) {
 +  static mtx_t mutex = _MTX_INITIALIZER_NP;
static unsigned anon_count = 1;
 -  identifier = ralloc_asprintf(this, #anon_struct_%04x, anon_count);
 -  anon_count++;
 +  unsigned count;
 +
 +  mtx_lock(mutex);
 +  count = anon_count++;
 +  mtx_unlock(mutex);
 +
 +  identifier = ralloc_asprintf(this, #anon_struct_%04x, count);
 }
 name = identifier;
 this-declarations.push_degenerate_list_at_head(declarator_list-link);





-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 20/21] mesa: add support for threaded glCompileShader

2014-05-04 Thread Chia-I Wu
On Sat, May 3, 2014 at 1:59 AM, Ian Romanick i...@freedesktop.org wrote:
 On 04/22/2014 01:58 AM, Chia-I Wu wrote:
 From: Chia-I Wu o...@lunarg.com

 Threaded glCompileShader can be enabled for a context by calling
 _mesa_enable_glsl_threadpool.  It will initialize the singleton GLSL thread
 pool and defer glCompileShader calls to the thread pool.

 For applications to benefit from threaded glCompileShader, they have to
 compile shaders in this fashion

  for (i = 0; i  num_shaders; i++)
glCompileShader(shaders[i]);
  for (i = 0; i  num_shaders; i++)
glGetShaderiv(shaders[i], GL_COMPILE_STATUS, val);

 I think when you try this series on some real applications, you will be
 disappointed.  Eric had a pretty similar branch
 (http://cgit.freedesktop.org/~anholt/mesa/log/?h=compiler-threads), but
 it saw no benefit on any applications... because everybody does

 for (i = 0; i  num_shaders; i++) {
 glCompileShader(shaders[i]);
 glGetShaderiv(shaders[i], GL_COMPILE_STATUS, val);
 }

 or

 for (i = 0; i  num_shaders; i++) {
 glCompileShader(shaders[i]);
 glAttachShader(prog, shaders[i]);
 }

 glLinkProgram(prog);
Yeah, I am aware of the situation with real-world applications.  Only
applications that are modified to not immediately check compilation results
will get the speed up in compile times.  That is why this feature needs to be
enabled through drirc.  We, at LunarG, are working with major game engines
vendors to ensure this performance benefit is realized.

 I'm also curious about your test case... did you link the shaders?  As
 far as I'm aware, the bulk of time spent in the compiler happens during
 linking (final optimizations and register allocation).  Eric's data
 (http://lists.freedesktop.org/archives/mesa-dev/2014-April/057494.html)
 says we spend more than 2x time in linking than in compiling.
No, I did not.  In my other experiment with Unigine Tropics, the
distribution of time was more like

glCompileShader: 50%
glLinkProgram FE: 25%
glLinkProgram BE: 25%

But, yeah, I will modify my test case to collect more numbers.  Given
Pierre-Loup's numbers on DOTA2, we could expect much more reduction of
shader compiling/linking time if Eric's data are correct.

Despite all that, if this series is to be accepted after concerns are resolved,
what I plan to do based on it are

 * defer FE work in glLinkProgram to the thread pool
 * defer glCreateShaderProgramv
 * defer BE work in glLinkProgram to the thread pool

The priorities will be driven by where CPU time is spent.

I am sorry I wasn't aware of the mail thread you pointed out.  I would
have responded to it if I knew.  I am still on the road and away from
my desktop.  I will read the thread carefully when I get to sit down
and work.

 As each glGetShaderiv call will force mesa to wait for the deferred
 glCompileShader to complete, compiling shaders in the traditional way will
 defeat this feature.  This is also why the feature needs to be explicitly
 enabled with _mesa_enable_glsl_threadpool.

 Signed-off-by: Chia-I Wu o...@lunarg.com
 ---
  src/glsl/glsl_parser_extras.cpp |  4 +++
  src/glsl/threadpool.c   | 72 
 +
  src/glsl/threadpool.h   |  9 ++
  src/mesa/main/context.c | 25 ++
  src/mesa/main/context.h |  3 ++
  src/mesa/main/mtypes.h  | 13 
  src/mesa/main/shaderapi.c   | 48 +--
  src/mesa/main/shaderobj.c   | 20 
  src/mesa/main/shaderobj.h   |  2 ++
  9 files changed, 194 insertions(+), 2 deletions(-)

 diff --git a/src/glsl/glsl_parser_extras.cpp 
 b/src/glsl/glsl_parser_extras.cpp
 index 30e284b..c035474 100644
 --- a/src/glsl/glsl_parser_extras.cpp
 +++ b/src/glsl/glsl_parser_extras.cpp
 @@ -37,6 +37,7 @@ extern C {
  #include glsl_parser.h
  #include ir_optimization.h
  #include loop_analysis.h
 +#include threadpool.h

  /**
   * Format a short human-readable description of the given GLSL version.
 @@ -1567,6 +1568,8 @@ extern C {
  void
  _mesa_destroy_shader_compiler(void)
  {
 +   _mesa_glsl_destroy_threadpool();
 +
 _mesa_destroy_shader_compiler_caches();

 _mesa_glsl_release_types();
 @@ -1580,6 +1583,7 @@ _mesa_destroy_shader_compiler(void)
  void
  _mesa_destroy_shader_compiler_caches(void)
  {
 +   _mesa_glsl_wait_threadpool();
 _mesa_glsl_release_builtin_functions();
  }

 diff --git a/src/glsl/threadpool.c b/src/glsl/threadpool.c
 index 0aaac3a..3d54ec0 100644
 --- a/src/glsl/threadpool.c
 +++ b/src/glsl/threadpool.c
 @@ -55,6 +55,7 @@ struct _mesa_threadpool_task {
  struct _mesa_threadpool {
 mtx_t mutex;
 int refcnt;
 +   bool shutdown;

 enum _mesa_threadpool_control thread_control;
 thrd_t *threads;
 @@ -158,6 +159,12 @@ _mesa_threadpool_queue_task(struct _mesa_threadpool 
 *pool,

 mtx_lock(pool-mutex);

 +   if (unlikely(pool-shutdown)) {
 +  mtx_unlock(pool-mutex);
 +  free(task

Re: [Mesa-dev] [PATCH] st/egl: Flush resources before presentation (android - bug 77966)

2014-05-04 Thread Chia-I Wu
On Sun, May 4, 2014 at 7:02 PM, Marek Olšák mar...@gmail.com wrote:
 Reviewed-by: Marek Olšák marek.ol...@amd.com
Looks good to me too, except please use your real name.
 Marek

 On Fri, May 2, 2014 at 5:00 PM, pstglia pstg...@gmail.com wrote:
 ---
  src/gallium/state_trackers/egl/android/native_android.cpp | 7 +++
  1 file changed, 7 insertions(+)

 diff --git a/src/gallium/state_trackers/egl/android/native_android.cpp 
 b/src/gallium/state_trackers/egl/android/native_android.cpp
 index e73d031..8620ed8 100644
 --- a/src/gallium/state_trackers/egl/android/native_android.cpp
 +++ b/src/gallium/state_trackers/egl/android/native_android.cpp
 @@ -396,6 +396,13 @@ android_surface_swap_buffers(struct native_surface 
 *nsurf)
 struct android_surface *asurf = android_surface(nsurf);
 struct android_display *adpy = asurf-adpy;

 +   struct native_display *ndpy = adpy-base;
 +   struct pipe_context *pipe = ndpy_get_copy_context(ndpy);
 +
 +   /* flush buffer */
 +   pipe-flush_resource(pipe, asurf-buf_res);
 +   pipe-flush(pipe, NULL, 0);
 +
 android_surface_enqueue_buffer(asurf-base);

 asurf-stamp++;
 --
 1.7.12.1

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



-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH] st/egl: Flush resources before presentation (android - bug 77966)

2014-05-04 Thread Chia-I Wu
On Mon, May 5, 2014 at 6:12 AM, Paulo Sergio pstg...@gmail.com wrote:
 Ok. Name is Paulo Sergio Travaglia. Shall I resend the patch?
I've committed it.  Thanks.
 Thanks

 Em 04/05/2014 18:40, Chia-I Wu olva...@gmail.com escreveu:

 On Sun, May 4, 2014 at 7:02 PM, Marek Olšák mar...@gmail.com wrote:
  Reviewed-by: Marek Olšák marek.ol...@amd.com
 Looks good to me too, except please use your real name.
  Marek
 
  On Fri, May 2, 2014 at 5:00 PM, pstglia pstg...@gmail.com wrote:
  ---
   src/gallium/state_trackers/egl/android/native_android.cpp | 7 +++
   1 file changed, 7 insertions(+)
 
  diff --git a/src/gallium/state_trackers/egl/android/native_android.cpp
  b/src/gallium/state_trackers/egl/android/native_android.cpp
  index e73d031..8620ed8 100644
  --- a/src/gallium/state_trackers/egl/android/native_android.cpp
  +++ b/src/gallium/state_trackers/egl/android/native_android.cpp
  @@ -396,6 +396,13 @@ android_surface_swap_buffers(struct native_surface
  *nsurf)
  struct android_surface *asurf = android_surface(nsurf);
  struct android_display *adpy = asurf-adpy;
 
  +   struct native_display *ndpy = adpy-base;
  +   struct pipe_context *pipe = ndpy_get_copy_context(ndpy);
  +
  +   /* flush buffer */
  +   pipe-flush_resource(pipe, asurf-buf_res);
  +   pipe-flush(pipe, NULL, 0);
  +
  android_surface_enqueue_buffer(asurf-base);
 
  asurf-stamp++;
  --
  1.7.12.1
 
  ___
  mesa-dev mailing list
  mesa-dev@lists.freedesktop.org
  http://lists.freedesktop.org/mailman/listinfo/mesa-dev
  ___
  mesa-dev mailing list
  mesa-dev@lists.freedesktop.org
  http://lists.freedesktop.org/mailman/listinfo/mesa-dev



 --
 o...@lunarg.com



-- 
o...@lunarg.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 05/21 v3] meta: Fix saving the program pipeline state

2014-05-01 Thread Chia-I Wu
On Fri, May 2, 2014 at 7:38 AM, Ian Romanick i...@freedesktop.org wrote:
 From: Ian Romanick ian.d.roman...@intel.com

 This code was broken in some odd ways before.  Too much state was being
 saved, it was being restored in the wrong order, and in the wrong way.
 The biggest problem was that the pipeline object was restored before
 restoring the programs attached to the default pipeline.

 Fixes a regression in the glean texgen test.

 v3: Fairly significant re-write.  I think it's much cleaner now, and it
 avoids a bug with some meta ops that use shaders (reported by Chia-I).
Thanks, it fixes the bug.  The patch looks good to me.  A few minor
comments/questions below.

 Signed-off-by: Ian Romanick ian.d.roman...@intel.com
 Cc: Chia-I Wu olva...@gmail.com
 ---
  src/mesa/drivers/common/meta.c | 86 
 ++
  src/mesa/drivers/common/meta.h |  1 -
  2 files changed, 53 insertions(+), 34 deletions(-)

 diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
 index ab86f9c..42b67ec 100644
 --- a/src/mesa/drivers/common/meta.c
 +++ b/src/mesa/drivers/common/meta.c
 @@ -577,19 +577,21 @@ _mesa_meta_begin(struct gl_context *ctx, GLbitfield 
 state)
}

if (ctx-Extensions.ARB_separate_shader_objects) {
 - /* Warning it must be done before _mesa_UseProgram call */
 - _mesa_reference_pipeline_object(ctx, save-_Shader, ctx-_Shader);
 - _mesa_reference_pipeline_object(ctx, save-Pipeline,
 - ctx-Pipeline.Current);
 - _mesa_BindProgramPipeline(0);
 + if (ctx-Pipeline.Current != ctx-Pipeline.Default) {
It seems ctx-Pipeline.Current is never equal to
ctx-Pipeline.Default.  You may check against NULL instead.

 +_mesa_reference_pipeline_object(ctx, save-Pipeline,
 +ctx-Pipeline.Current);
 +_mesa_BindProgramPipeline(0);
}

 -  for (i = 0; i  MESA_SHADER_STAGES; i++) {
 +  /* Save the shader state from ctx-Shader (instead of ctx-_Shader) so
 +   * that we don't have to worry about the current pipeline state.
 +   */
 +  for (i = 0; i = MESA_SHADER_FRAGMENT; i++) {
I am not familiar with MESA_SHADER_COMPUTE.  If this will not give us
headaches in the future, I am fine with it.

   _mesa_reference_shader_program(ctx, save-Shader[i],
 - ctx-_Shader-CurrentProgram[i]);
 +ctx-Shader.CurrentProgram[i]);
}
_mesa_reference_shader_program(ctx, save-ActiveShader,
 - ctx-_Shader-ActiveProgram);
 + ctx-Shader.ActiveProgram);

_mesa_UseProgram(0);
 }
 @@ -908,6 +910,14 @@ _mesa_meta_end(struct gl_context *ctx)
 }

 if (state  MESA_META_SHADER) {
 +  static const GLenum targets[] = {
 + GL_VERTEX_SHADER,
 + GL_GEOMETRY_SHADER,
 + GL_FRAGMENT_SHADER,
 +  };
 +
 +  bool any_shader;
 +
if (ctx-Extensions.ARB_vertex_program) {
   _mesa_set_enable(ctx, GL_VERTEX_PROGRAM_ARB,
save-VertexProgramEnabled);
 @@ -929,37 +939,47 @@ _mesa_meta_end(struct gl_context *ctx)
save-ATIFragmentShaderEnabled);
}

 -  /* Warning it must be done before _mesa_use_shader_program call */
 -  if (ctx-Extensions.ARB_separate_shader_objects) {
 - _mesa_reference_pipeline_object(ctx, ctx-_Shader, save-_Shader);
 - _mesa_reference_pipeline_object(ctx, ctx-Pipeline.Current,
 - save-Pipeline);
 - _mesa_reference_pipeline_object(ctx, save-Pipeline, NULL);
 -  }
 +  any_shader = false;
 +  for (i = 0; i = MESA_SHADER_FRAGMENT; i++) {
 + /* It is safe to call _mesa_use_shader_program even if the extension
 +  * necessary for that program state is not supported.  In that case,
 +  * the saved program object must be NULL and the currently bound
 +  * program object must be NULL.  _mesa_use_shader_program is a no-op
 +  * in that case.
 +  */
 + _mesa_use_shader_program(ctx, targets[i],
 +  save-Shader[i],
 +  ctx-Shader);
 +
 + /* Do this *before* killing the reference. :)
 +  */
 + if (save-Shader[i] != NULL)
 +any_shader = true;

 -  if (ctx-Extensions.ARB_vertex_shader) {
 -_mesa_use_shader_program(ctx, GL_VERTEX_SHADER,
 -  save-Shader[MESA_SHADER_VERTEX],
 -  ctx-_Shader);
 + _mesa_reference_shader_program(ctx, save-Shader[i], NULL);
}

 -  if (_mesa_has_geometry_shaders(ctx))
 -_mesa_use_shader_program(ctx, GL_GEOMETRY_SHADER_ARB,
 -  save-Shader

Re: [Mesa-dev] [PATCH 05/21] meta: Fix saving the program pipeline state

2014-04-30 Thread Chia-I Wu
On Thu, May 1, 2014 at 12:11 AM, Ian Romanick i...@freedesktop.org wrote:
 On 04/29/2014 08:43 PM, Chia-I Wu wrote:
 On Wed, Apr 30, 2014 at 8:52 AM, Ian Romanick i...@freedesktop.org wrote:
 From: Ian Romanick ian.d.roman...@intel.com

 This code was broken in some odd ways before.  Too much state was being
 saved, it was being restored in the wrong order, and in the wrong way.
 The biggest problem was that the pipeline object was restored before
 restoring the programs attached to the default pipeline.

 Fixes a regression in the glean texgen test.

 Signed-off-by: Ian Romanick ian.d.roman...@intel.com
 Reviewed-by: Kenneth Graunke kenn...@whitecape.org
 Reviewed-by: Eric Anholt e...@anholt.net
 ---
  src/mesa/drivers/common/meta.c | 34 --
  src/mesa/drivers/common/meta.h |  1 -
  2 files changed, 20 insertions(+), 15 deletions(-)

 diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
 index ac27abb..92bc185 100644
 --- a/src/mesa/drivers/common/meta.c
 +++ b/src/mesa/drivers/common/meta.c
 @@ -577,11 +577,15 @@ _mesa_meta_begin(struct gl_context *ctx, GLbitfield 
 state)
}

if (ctx-Extensions.ARB_separate_shader_objects) {
 - /* Warning it must be done before _mesa_UseProgram call */
 - _mesa_reference_pipeline_object(ctx, save-_Shader, 
 ctx-_Shader);
 - _mesa_reference_pipeline_object(ctx, save-Pipeline,
 - ctx-Pipeline.Current);
 - _mesa_BindProgramPipeline(0);
 + /* Warning: This must be done before saving the current programs.
 +  * Otherwise the programs attached to the pipeline will be saved
 +  * instead of the programs attached to the default pipeline.
 +  */
 + if (ctx-Pipeline.Current != ctx-Pipeline.Default) {
 +_mesa_reference_pipeline_object(ctx, save-Pipeline,
 +ctx-Pipeline.Current);
 +_mesa_BindProgramPipeline(0);
 + }
}

for (i = 0; i  MESA_SHADER_STAGES; i++) {
 @@ -929,14 +933,6 @@ _mesa_meta_end(struct gl_context *ctx)
save-ATIFragmentShaderEnabled);
}

 -  /* Warning it must be done before _mesa_use_shader_program call */
 -  if (ctx-Extensions.ARB_separate_shader_objects) {
 - _mesa_reference_pipeline_object(ctx, ctx-_Shader, 
 save-_Shader);
 - _mesa_reference_pipeline_object(ctx, ctx-Pipeline.Current,
 - save-Pipeline);
 - _mesa_reference_pipeline_object(ctx, save-Pipeline, NULL);
 -  }
 -
if (ctx-Extensions.ARB_vertex_shader) {
  _mesa_use_shader_program(ctx, GL_VERTEX_SHADER,
save-Shader[MESA_SHADER_VERTEX],
 @@ -956,10 +952,20 @@ _mesa_meta_end(struct gl_context *ctx)
_mesa_reference_shader_program(ctx, ctx-_Shader-ActiveProgram,
  save-ActiveShader);

 +  /* Warning: This must be done after _mesa_use_shader_program call.
 +   * Otherwise the programs will be restored to the pipeline object
 +   * instead of to the default pipeline.
 +   */
 +  if (save-Pipeline) {
 + assert(ctx-Extensions.ARB_separate_shader_objects);
 + _mesa_bind_pipeline(ctx, save-Pipeline);
 This issue does not appear to be fixed

   http://lists.freedesktop.org/archives/mesa-dev/2014-April/057999.html

 The attached change to piglit triggers it.

 What should the result have been with that patch?  I tried that with my
 current sso6 branch, and
 arb_separate_shader_objects-rendezvous_by_location passes with or
 without this patch.
The patch should not affect the result, but I got this error after applying it

$ ./bin/arb_separate_shader_object-rendezvous_by_location -auto
Probe color at (0,0)
  Expected: 0.00 1.00 0.00 1.00
  Observed: 1.00 1.00 1.00 1.00
PIGLIT: {'result': 'fail' }

I am also on sso6 (except that I merged it to master).


 +
 + _mesa_reference_pipeline_object(ctx, save-Pipeline, NULL);
 +  }
 +
for (i = 0; i  MESA_SHADER_STAGES; i++)
   _mesa_reference_shader_program(ctx, save-Shader[i], NULL);
_mesa_reference_shader_program(ctx, save-ActiveShader, NULL);
 -  _mesa_reference_pipeline_object(ctx, save-_Shader, NULL);
 }

 if (state  MESA_META_STENCIL_TEST) {
 diff --git a/src/mesa/drivers/common/meta.h b/src/mesa/drivers/common/meta.h
 index fde4f9a..0a34792 100644
 --- a/src/mesa/drivers/common/meta.h
 +++ b/src/mesa/drivers/common/meta.h
 @@ -121,7 +121,6 @@ struct save_state
 GLboolean ATIFragmentShaderEnabled;
 struct gl_shader_program *Shader[MESA_SHADER_STAGES];
 struct gl_shader_program *ActiveShader;
 -   struct gl_pipeline_object   *_Shader;
 struct gl_pipeline_object   *Pipeline;

 /** MESA_META_STENCIL_TEST */
 --
 1.8.1.4

[Mesa-dev] [PATCH 04/18] mesa: refactor debug out log_msg

2014-04-25 Thread Chia-I Wu
Move message logging to debug_log_message.  Replace store_message_details by
debug_message_store.  No functional change.

Signed-off-by: Chia-I Wu o...@lunarg.com
---
 src/mesa/main/errors.c | 134 +++--
 1 file changed, 75 insertions(+), 59 deletions(-)

diff --git a/src/mesa/main/errors.c b/src/mesa/main/errors.c
index d2d072f..d9bff7b 100644
--- a/src/mesa/main/errors.c
+++ b/src/mesa/main/errors.c
@@ -181,6 +181,39 @@ enum {
ENABLED = ENABLED_BIT | FOUND_BIT
 };
 
+static void
+debug_message_store(struct gl_debug_msg *msg,
+enum mesa_debug_source source,
+enum mesa_debug_type type, GLuint id,
+enum mesa_debug_severity severity,
+GLsizei len, const char *buf)
+{
+   assert(!msg-message  !msg-length);
+
+   msg-message = malloc(len+1);
+   if (msg-message) {
+  (void) strncpy(msg-message, buf, (size_t)len);
+  msg-message[len] = '\0';
+
+  msg-length = len+1;
+  msg-source = source;
+  msg-type = type;
+  msg-id = id;
+  msg-severity = severity;
+   } else {
+  static GLuint oom_msg_id = 0;
+  debug_get_id(oom_msg_id);
+
+  /* malloc failed! */
+  msg-message = out_of_memory;
+  msg-length = strlen(out_of_memory)+1;
+  msg-source = MESA_DEBUG_SOURCE_OTHER;
+  msg-type = MESA_DEBUG_TYPE_ERROR;
+  msg-id = oom_msg_id;
+  msg-severity = MESA_DEBUG_SEVERITY_HIGH;
+   }
+}
+
 /**
  * Allocate and initialize context debug state.
  */
@@ -311,6 +344,40 @@ out:
return (state  ENABLED_BIT);
 }
 
+/**
+ * 'buf' is not necessarily a null-terminated string. When logging, copy
+ * 'len' characters from it, store them in a new, null-terminated string,
+ * and remember the number of bytes used by that string, *including*
+ * the null terminator this time.
+ */
+static void
+debug_log_message(struct gl_debug_state *debug,
+  enum mesa_debug_source source,
+  enum mesa_debug_type type, GLuint id,
+  enum mesa_debug_severity severity,
+  GLsizei len, const char *buf)
+{
+   GLint nextEmpty;
+   struct gl_debug_msg *emptySlot;
+
+   assert(len = 0  len  MAX_DEBUG_MESSAGE_LENGTH);
+
+   if (debug-NumMessages == MAX_DEBUG_LOGGED_MESSAGES)
+  return;
+
+   nextEmpty = (debug-NextMsg + debug-NumMessages)
+  % MAX_DEBUG_LOGGED_MESSAGES;
+   emptySlot = debug-Log[nextEmpty];
+
+   debug_message_store(emptySlot, source, type,
+   id, severity, len, buf);
+
+   if (debug-NumMessages == 0)
+  debug-NextMsgLength = debug-Log[debug-NextMsg].length;
+
+   debug-NumMessages++;
+}
+
 
 /**
  * Return debug state for the context.  The debug state will be allocated
@@ -366,45 +433,9 @@ set_message_state(struct gl_context *ctx,
 }
 
 
-static void
-store_message_details(struct gl_debug_msg *emptySlot,
-  enum mesa_debug_source source,
-  enum mesa_debug_type type, GLuint id,
-  enum mesa_debug_severity severity, GLint len,
-  const char *buf)
-{
-   assert(!emptySlot-message  !emptySlot-length);
-
-   emptySlot-message = malloc(len+1);
-   if (emptySlot-message) {
-  (void) strncpy(emptySlot-message, buf, (size_t)len);
-  emptySlot-message[len] = '\0';
-
-  emptySlot-length = len+1;
-  emptySlot-source = source;
-  emptySlot-type = type;
-  emptySlot-id = id;
-  emptySlot-severity = severity;
-   } else {
-  static GLuint oom_msg_id = 0;
-  debug_get_id(oom_msg_id);
-
-  /* malloc failed! */
-  emptySlot-message = out_of_memory;
-  emptySlot-length = strlen(out_of_memory)+1;
-  emptySlot-source = MESA_DEBUG_SOURCE_OTHER;
-  emptySlot-type = MESA_DEBUG_TYPE_ERROR;
-  emptySlot-id = oom_msg_id;
-  emptySlot-severity = MESA_DEBUG_SEVERITY_HIGH;
-   }
-}
-
 
 /**
- * 'buf' is not necessarily a null-terminated string. When logging, copy
- * 'len' characters from it, store them in a new, null-terminated string,
- * and remember the number of bytes used by that string, *including*
- * the null terminator this time.
+ * Log a client or driver debug message.
  */
 static void
 log_msg(struct gl_context *ctx, enum mesa_debug_source source,
@@ -412,14 +443,10 @@ log_msg(struct gl_context *ctx, enum mesa_debug_source 
source,
 enum mesa_debug_severity severity, GLint len, const char *buf)
 {
struct gl_debug_state *debug = _mesa_get_debug_state(ctx);
-   GLint nextEmpty;
-   struct gl_debug_msg *emptySlot;
 
if (!debug)
   return;
 
-   assert(len = 0  len  MAX_DEBUG_MESSAGE_LENGTH);
-
if (!should_log(ctx, source, type, id, severity))
   return;
 
@@ -432,19 +459,7 @@ log_msg(struct gl_context *ctx, enum mesa_debug_source 
source,
   return;
}
 
-   if (debug-NumMessages == MAX_DEBUG_LOGGED_MESSAGES)
-  return;
-
-   nextEmpty = (debug-NextMsg + debug-NumMessages

[Mesa-dev] [PATCH 03/21] glsl: protect anonymous struct id with a mutex

2014-04-22 Thread Chia-I Wu
There may be two contexts compiling shaders at the same time, and we want the
anonymous struct id to be globally unique.

Signed-off-by: Chia-I Wu o...@lunarg.com
---
 src/glsl/glsl_parser_extras.cpp | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index 91c9285..30e284b 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -1332,9 +1332,15 @@ ast_struct_specifier::ast_struct_specifier(const char 
*identifier,
   ast_declarator_list *declarator_list)
 {
if (identifier == NULL) {
+  static mtx_t mutex = _MTX_INITIALIZER_NP;
   static unsigned anon_count = 1;
-  identifier = ralloc_asprintf(this, #anon_struct_%04x, anon_count);
-  anon_count++;
+  unsigned count;
+
+  mtx_lock(mutex);
+  count = anon_count++;
+  mtx_unlock(mutex);
+
+  identifier = ralloc_asprintf(this, #anon_struct_%04x, count);
}
name = identifier;
this-declarations.push_degenerate_list_at_head(declarator_list-link);
-- 
1.8.5.3

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


[Mesa-dev] [PATCH 07/21] mesa: refactor debug output set_message_state

2014-04-22 Thread Chia-I Wu
Move message state update to debug_set_message_filter.

Signed-off-by: Chia-I Wu o...@lunarg.com
---
 src/mesa/main/errors.c | 70 --
 1 file changed, 39 insertions(+), 31 deletions(-)

diff --git a/src/mesa/main/errors.c b/src/mesa/main/errors.c
index 66896c4..c478aac 100644
--- a/src/mesa/main/errors.c
+++ b/src/mesa/main/errors.c
@@ -217,6 +217,43 @@ debug_create(void)
return debug;
 }
 
+/*
+ * Sets the state of the given message source/type/ID tuple.
+ */
+static void
+debug_set_message_filter(struct gl_debug_state *debug,
+ enum mesa_debug_source source,
+ enum mesa_debug_type type,
+ GLuint id, GLboolean enabled)
+{
+   GLint gstack = debug-GroupStackDepth;
+   struct gl_debug_namespace *nspace =
+  debug-Namespaces[gstack][source][type];
+   uintptr_t state;
+
+   /* In addition to not being able to store zero as a value, HashTable also
+* can't use zero as a key.
+*/
+   if (id)
+  state = (uintptr_t)_mesa_HashLookup(nspace-IDs, id);
+   else
+  state = nspace-ZeroID;
+
+   if (state == NOT_FOUND)
+  state = enabled ? ENABLED : DISABLED;
+   else {
+  if (enabled)
+ state |= ENABLED_BIT;
+  else
+ state = ~ENABLED_BIT;
+   }
+
+   if (id)
+  _mesa_HashInsert(nspace-IDs, id, (void*)state);
+   else
+  nspace-ZeroID = state;
+}
+
 /**
  * Returns if the given message source/type/ID tuple is filtered.
  */
@@ -316,9 +353,6 @@ should_log(struct gl_context *ctx,
 }
 
 
-/**
- * Sets the state of the given message source/type/ID tuple.
- */
 static void
 set_message_state(struct gl_context *ctx,
   enum mesa_debug_source source,
@@ -327,34 +361,8 @@ set_message_state(struct gl_context *ctx,
 {
struct gl_debug_state *debug = _mesa_get_debug_state(ctx);
 
-   if (debug) {
-  GLint gstack = debug-GroupStackDepth;
-  struct gl_debug_namespace *nspace =
- debug-Namespaces[gstack][source][type];
-  uintptr_t state;
-
-  /* In addition to not being able to store zero as a value, HashTable also
-   * can't use zero as a key.
-   */
-  if (id)
- state = (uintptr_t)_mesa_HashLookup(nspace-IDs, id);
-  else
- state = nspace-ZeroID;
-
-  if (state == NOT_FOUND)
- state = enabled ? ENABLED : DISABLED;
-  else {
- if (enabled)
-state |= ENABLED_BIT;
- else
-state = ~ENABLED_BIT;
-  }
-
-  if (id)
- _mesa_HashInsert(nspace-IDs, id, (void*)state);
-  else
- nspace-ZeroID = state;
-   }
+   if (debug)
+  debug_set_message_filter(debug, source, type, id, enabled);
 }
 
 
-- 
1.8.5.3

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


[Mesa-dev] [PATCH 09/21] mesa: refactor debug output get_msg

2014-04-22 Thread Chia-I Wu
Move message fetching to debug_fetch_message and message deletion to
debug_delete_messages.

Signed-off-by: Chia-I Wu o...@lunarg.com
---
 src/mesa/main/errors.c | 61 +-
 1 file changed, 50 insertions(+), 11 deletions(-)

diff --git a/src/mesa/main/errors.c b/src/mesa/main/errors.c
index 930e801..0d26285 100644
--- a/src/mesa/main/errors.c
+++ b/src/mesa/main/errors.c
@@ -346,6 +346,18 @@ debug_store_message(struct gl_debug_state *debug,
}
 }
 
+static void
+debug_clear_message(struct gl_debug_state *debug,
+struct gl_debug_msg *msg)
+{
+   (void) debug;
+
+   if (msg-message != (char*)out_of_memory)
+  free(msg-message);
+   msg-message = NULL;
+   msg-length = 0;
+}
+
 /**
  * 'buf' is not necessarily a null-terminated string. When logging, copy
  * 'len' characters from it, store them in a new, null-terminated string,
@@ -380,6 +392,37 @@ debug_log_message(struct gl_debug_state *debug,
debug-NumMessages++;
 }
 
+/**
+ * Return the oldest debug message out of the log.
+ */
+static const struct gl_debug_msg *
+debug_fetch_message(const struct gl_debug_state *debug)
+{
+   return (debug-NumMessages) ? debug-Log[debug-NextMsg] : NULL;
+}
+
+/**
+ * Delete the oldest debug messages out of the log.
+ */
+static void
+debug_delete_messages(struct gl_debug_state *debug, unsigned count)
+{
+   if (count  debug-NumMessages)
+  count = debug-NumMessages;
+
+   while (count--) {
+  struct gl_debug_msg *msg = debug-Log[debug-NextMsg];
+
+  assert(msg-length  0  msg-length == debug-NextMsgLength);
+  debug_clear_message(debug, msg);
+
+  debug-NumMessages--;
+  debug-NextMsg++;
+  debug-NextMsg %= MAX_DEBUG_LOGGED_MESSAGES;
+  debug-NextMsgLength = debug-Log[debug-NextMsg].length;
+   }
+}
+
 
 /**
  * Return debug state for the context.  The debug state will be allocated
@@ -480,10 +523,14 @@ get_msg(struct gl_context *ctx, GLenum *source, GLenum 
*type,
 GLuint *id, GLenum *severity, GLsizei bufSize, char *buf)
 {
struct gl_debug_state *debug = _mesa_get_debug_state(ctx);
-   struct gl_debug_msg *msg;
+   const struct gl_debug_msg *msg;
GLsizei length;
 
-   if (!debug || debug-NumMessages == 0)
+   if (!debug)
+  return 0;
+
+   msg = debug_fetch_message(debug);
+   if (!msg)
   return 0;
 
msg = debug-Log[debug-NextMsg];
@@ -515,15 +562,7 @@ get_msg(struct gl_context *ctx, GLenum *source, GLenum 
*type,
   (void) strncpy(buf, msg-message, (size_t)length);
}
 
-   if (msg-message != (char*)out_of_memory)
-  free(msg-message);
-   msg-message = NULL;
-   msg-length = 0;
-
-   debug-NumMessages--;
-   debug-NextMsg++;
-   debug-NextMsg %= MAX_DEBUG_LOGGED_MESSAGES;
-   debug-NextMsgLength = debug-Log[debug-NextMsg].length;
+   debug_delete_messages(debug, 1);
 
return length;
 }
-- 
1.8.5.3

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


[Mesa-dev] [PATCH 04/21] glsl: protect glsl_type with a mutex

2014-04-22 Thread Chia-I Wu
glsl_type has several static hash tables and a static ralloc context.  They
need to be protected by a mutex as they are not thread-safe.

Signed-off-by: Chia-I Wu o...@lunarg.com
---
 src/glsl/glsl_types.cpp | 57 +++--
 src/glsl/glsl_types.h   | 15 +
 2 files changed, 62 insertions(+), 10 deletions(-)

diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
index 849a79a..562cf00 100644
--- a/src/glsl/glsl_types.cpp
+++ b/src/glsl/glsl_types.cpp
@@ -31,6 +31,7 @@ extern C {
 #include program/hash_table.h
 }
 
+mtx_t glsl_type::mutex = _MTX_INITIALIZER_NP;
 hash_table *glsl_type::array_types = NULL;
 hash_table *glsl_type::record_types = NULL;
 hash_table *glsl_type::interface_types = NULL;
@@ -55,9 +56,14 @@ glsl_type::glsl_type(GLenum gl_type,
vector_elements(vector_elements), matrix_columns(matrix_columns),
length(0)
 {
+   mtx_lock(glsl_type::mutex);
+
init_ralloc_type_ctx();
assert(name != NULL);
this-name = ralloc_strdup(this-mem_ctx, name);
+
+   mtx_unlock(glsl_type::mutex);
+
/* Neither dimension is zero or both dimensions are zero.
 */
assert((vector_elements == 0) == (matrix_columns == 0));
@@ -73,9 +79,14 @@ glsl_type::glsl_type(GLenum gl_type, glsl_base_type 
base_type,
sampler_array(array), sampler_type(type), interface_packing(0),
length(0)
 {
+   mtx_lock(glsl_type::mutex);
+
init_ralloc_type_ctx();
assert(name != NULL);
this-name = ralloc_strdup(this-mem_ctx, name);
+
+   mtx_unlock(glsl_type::mutex);
+
memset( fields, 0, sizeof(fields));
 
if (base_type == GLSL_TYPE_SAMPLER) {
@@ -97,11 +108,14 @@ glsl_type::glsl_type(const glsl_struct_field *fields, 
unsigned num_fields,
 {
unsigned int i;
 
+   mtx_lock(glsl_type::mutex);
+
init_ralloc_type_ctx();
assert(name != NULL);
this-name = ralloc_strdup(this-mem_ctx, name);
this-fields.structure = ralloc_array(this-mem_ctx,
 glsl_struct_field, length);
+
for (i = 0; i  length; i++) {
   this-fields.structure[i].type = fields[i].type;
   this-fields.structure[i].name = ralloc_strdup(this-fields.structure,
@@ -112,6 +126,8 @@ glsl_type::glsl_type(const glsl_struct_field *fields, 
unsigned num_fields,
   this-fields.structure[i].sample = fields[i].sample;
   this-fields.structure[i].row_major = fields[i].row_major;
}
+
+   mtx_unlock(glsl_type::mutex);
 }
 
 glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields,
@@ -125,6 +141,8 @@ glsl_type::glsl_type(const glsl_struct_field *fields, 
unsigned num_fields,
 {
unsigned int i;
 
+   mtx_lock(glsl_type::mutex);
+
init_ralloc_type_ctx();
assert(name != NULL);
this-name = ralloc_strdup(this-mem_ctx, name);
@@ -140,6 +158,8 @@ glsl_type::glsl_type(const glsl_struct_field *fields, 
unsigned num_fields,
   this-fields.structure[i].sample = fields[i].sample;
   this-fields.structure[i].row_major = fields[i].row_major;
}
+
+   mtx_unlock(glsl_type::mutex);
 }
 
 
@@ -287,6 +307,8 @@ const glsl_type *glsl_type::get_scalar_type() const
 void
 _mesa_glsl_release_types(void)
 {
+   mtx_lock(glsl_type::mutex);
+
if (glsl_type::array_types != NULL) {
   hash_table_dtor(glsl_type::array_types);
   glsl_type::array_types = NULL;
@@ -296,6 +318,8 @@ _mesa_glsl_release_types(void)
   hash_table_dtor(glsl_type::record_types);
   glsl_type::record_types = NULL;
}
+
+   mtx_unlock(glsl_type::mutex);
 }
 
 
@@ -318,7 +342,10 @@ glsl_type::glsl_type(const glsl_type *array, unsigned 
length) :
 * NUL.
 */
const unsigned name_length = strlen(array-name) + 10 + 3;
+
+   mtx_lock(glsl_type::mutex);
char *const n = (char *) ralloc_size(this-mem_ctx, name_length);
+   mtx_unlock(glsl_type::mutex);
 
if (length == 0)
   snprintf(n, name_length, %s[], array-name);
@@ -454,12 +481,6 @@ glsl_type::get_instance(unsigned base_type, unsigned rows, 
unsigned columns)
 const glsl_type *
 glsl_type::get_array_instance(const glsl_type *base, unsigned array_size)
 {
-
-   if (array_types == NULL) {
-  array_types = hash_table_ctor(64, hash_table_string_hash,
-   hash_table_string_compare);
-   }
-
/* Generate a name using the base type pointer in the key.  This is
 * done because the name of the base type may not be unique across
 * shaders.  For example, two shaders may have different record types
@@ -468,9 +489,19 @@ glsl_type::get_array_instance(const glsl_type *base, 
unsigned array_size)
char key[128];
snprintf(key, sizeof(key), %p[%u], (void *) base, array_size);
 
+   mtx_lock(glsl_type::mutex);
+
+   if (array_types == NULL) {
+  array_types = hash_table_ctor(64, hash_table_string_hash,
+   hash_table_string_compare);
+   }
+
const glsl_type *t = (glsl_type *) hash_table_find(array_types, key);
+
if (t == NULL) {
+  mtx_unlock

  1   2   3   4   5   6   7   >