On Fri, Jan 24, 2020 at 04:45:07PM +1100, Jonathan Gray wrote:
> On Thu, Jan 23, 2020 at 12:39:29PM +1100, Jonathan Gray wrote:
> > On Wed, Dec 18, 2019 at 03:28:48PM -0600, Brad DeMorrow wrote:
> > > This is a rather large patch that moves my previously submitted
> > > VA-API ports into xenocara. For your convenience, I've inlined
> > > a diff that shows you all of the changes I made to existing files
> > > that you can easily read in your MUA.  The attached patch also
> > > contains these changes and should be the only xenocara patch
> > > you need to apply.
> > > 
> > > Summary of Changes:
> > >  - libva added to xenocara/lib/libva
> > >  - vainfo added to xenocara/app/vainfo
> > >  - intel-vaapi-driver added to xenocara/driver/intel-vaapi-driver
> > >  - Mesa Makefile.bsd-wrapper updated to build with --enable-va flag
> > >  - 3RDPARTY file updated to include libva, libva-utils, and 
> > > intel-vaapi-driver
> > >  - BSD.x11.dist updated to include /usr/X11R6/include/va/ (separate patch)
> > 
> > It is difficult to see where you have made changes, can you send patches
> > against source from particular tarballs?
> 
> I built libva-2.6.1 but it does not work with non-intel drivers at
> runtime due to a Mesa bug:
> 
> https://bugs.freedesktop.org/show_bug.cgi?id=109929
> 
> libva info: VA-API version 1.6.0
> libva info: Trying to open /usr/X11R6/lib/dri/radeonsi_drv_video.so
> vainfo:/usr/X11R6/lib/dri/radeonsi_drv_video.so: undefined symbol 
> 'gl_nir_lower_samplers_as_deref'
> vainfo:/usr/X11R6/lib/dri/radeonsi_drv_video.so: undefined symbol 
> 'gl_nir_lower_samplers'
> libva error: dlopen of /usr/X11R6/lib/dri/radeonsi_drv_video.so failed: 
> Cannot load specified object
> libva info: va_openDriver() returns -1
> vaInitialize failed with error code -1 (unknown libva error),exit

If I backport the following commits to 19.2 vainfo no longer errors on
amdgpu.

libva info: VA-API version 1.6.0
libva info: Trying to open /usr/X11R6/lib/dri/radeonsi_drv_video.so
libva info: Found init function __vaDriverInit_1_6
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.6 (libva 2.6.1)
vainfo: Driver version: Mesa Gallium driver 19.2.8 for AMD RAVEN (DRM 3.27.0, 
6.6, LLVM 8.0.1)
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileVC1Simple              : VAEntrypointVLD
      VAProfileVC1Main                : VAEntrypointVLD
      VAProfileVC1Advanced            : VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointEncSlice
      VAProfileH264High               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointEncSlice
      VAProfileHEVCMain               : VAEntrypointVLD
      VAProfileHEVCMain               : VAEntrypointEncSlice
      VAProfileHEVCMain10             : VAEntrypointVLD
      VAProfileJPEGBaseline           : VAEntrypointVLD
      VAProfileVP9Profile0            : VAEntrypointVLD
      VAProfileVP9Profile2            : VAEntrypointVLD
      VAProfileNone                   : VAEntrypointVideoProc

commit 3debd0ef157ed614522d20c1735c38af42fcce30
Author:     Timur Kristóf <timur.kris...@gmail.com>
AuthorDate: Wed Sep 4 16:56:09 2019 +0300
Commit:     Timur Kristóf <timur.kris...@gmail.com>
CommitDate: Fri Sep 6 12:20:53 2019 +0300

    tgsi_to_nir: Remove dependency on libglsl.
    
    This commit removes the GLSL dependency in TTN by manually recording
    the textures used and calling nir_lower_samplers
    instead of its GL counterpart.
    
    Signed-off-by: Timur Kristóf <timur.kris...@gmail.com>
    Reviewed-by: Connor Abbott <cwabbo...@gmail.com>

commit 610cc3089ccf1bce3ad025f308b6f408e8e90920
Author:     Timur Kristóf <timur.kris...@gmail.com>
AuthorDate: Wed Aug 28 22:34:14 2019 +0200
Commit:     Timur Kristóf <timur.kris...@gmail.com>
CommitDate: Fri Sep 6 12:20:20 2019 +0300

    nir: Carve out nir_lower_samplers from GLSL code.
    
    Lowering samplers is needed to produce NIR that can actually be
    consumed by some gallium drivers, so it doesn't make sense to
    to keep it only in the GLSL code.
    
    This commit introduces nir_lower_samplers to compiler/nir,
    while maintains the GL-specific function too.
    
    Signed-off-by: Timur Kristóf <timur.kris...@gmail.com>
    Reviewed-by: Connor Abbott <cwabbo...@gmail.com>

Index: Makefile.bsd-wrapper
===================================================================
RCS file: /cvs/xenocara/lib/mesa/Makefile.bsd-wrapper,v
retrieving revision 1.29
diff -u -p -r1.29 Makefile.bsd-wrapper
--- Makefile.bsd-wrapper        22 Jan 2020 02:49:17 -0000      1.29
+++ Makefile.bsd-wrapper        25 Jan 2020 02:29:19 -0000
@@ -44,6 +44,7 @@ CONFIGURE_ARGS=               --with-dri-drivers=${DR
                        --enable-gbm \
                        --enable-texture-float \
                        --enable-autotools \
+                       --enable-va \
                        --with-platforms="x11,drm" \
                        --prefix=${X11BASE} \
                        --with-dri-driverdir=${X11BASE}/lib/modules/dri \
Index: Makefile.in
===================================================================
RCS file: /cvs/xenocara/lib/mesa/Makefile.in,v
retrieving revision 1.17
diff -u -p -r1.17 Makefile.in
--- Makefile.in 22 Jan 2020 03:02:59 -0000      1.17
+++ Makefile.in 25 Jan 2020 02:29:19 -0000
@@ -83,8 +83,8 @@ DIST_COMMON = $(am__configure_deps) $(no
        $(top_srcdir)/src/gbm/main/gbm.pc.in \
        $(top_srcdir)/src/mapi/es1api/glesv1_cm.pc.in \
        $(top_srcdir)/src/mapi/es2api/glesv2.pc.in bin/ar-lib \
-       bin/compile bin/config.guess bin/config.sub bin/install-sh \
-       bin/ltmain.sh bin/missing
+       bin/compile bin/config.guess bin/config.sub bin/depcomp \
+       bin/install-sh bin/ltmain.sh bin/missing
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_compile_flag.m4 \
        $(top_srcdir)/m4/ax_check_gnu_make.m4 \
Index: src/compiler/Makefile.in
===================================================================
RCS file: /cvs/xenocara/lib/mesa/src/compiler/Makefile.in,v
retrieving revision 1.18
diff -u -p -r1.18 Makefile.in
--- src/compiler/Makefile.in    22 Jan 2020 03:03:00 -0000      1.18
+++ src/compiler/Makefile.in    25 Jan 2020 02:29:20 -0000
@@ -311,9 +311,10 @@ am__objects_7 = nir/nir.lo nir/nir_built
        nir/nir_lower_passthrough_edgeflags.lo \
        nir/nir_lower_patch_vertices.lo \
        nir/nir_lower_phis_to_scalar.lo nir/nir_lower_regs_to_ssa.lo \
-       nir/nir_lower_returns.lo nir/nir_lower_scratch.lo \
-       nir/nir_lower_subgroups.lo nir/nir_lower_system_values.lo \
-       nir/nir_lower_tex.lo nir/nir_lower_to_source_mods.lo \
+       nir/nir_lower_returns.lo nir/nir_lower_samplers.lo \
+       nir/nir_lower_scratch.lo nir/nir_lower_subgroups.lo \
+       nir/nir_lower_system_values.lo nir/nir_lower_tex.lo \
+       nir/nir_lower_to_source_mods.lo \
        nir/nir_lower_two_sided_color.lo \
        nir/nir_lower_uniforms_to_ubo.lo nir/nir_lower_vars_to_ssa.lo \
        nir/nir_lower_var_copies.lo nir/nir_lower_vec_to_movs.lo \
@@ -1112,6 +1113,7 @@ NIR_FILES = \
        nir/nir_lower_phis_to_scalar.c \
        nir/nir_lower_regs_to_ssa.c \
        nir/nir_lower_returns.c \
+       nir/nir_lower_samplers.c \
        nir/nir_lower_scratch.c \
        nir/nir_lower_subgroups.c \
        nir/nir_lower_system_values.c \
@@ -1888,6 +1890,8 @@ nir/nir_lower_regs_to_ssa.lo: nir/$(am__
        nir/$(DEPDIR)/$(am__dirstamp)
 nir/nir_lower_returns.lo: nir/$(am__dirstamp) \
        nir/$(DEPDIR)/$(am__dirstamp)
+nir/nir_lower_samplers.lo: nir/$(am__dirstamp) \
+       nir/$(DEPDIR)/$(am__dirstamp)
 nir/nir_lower_scratch.lo: nir/$(am__dirstamp) \
        nir/$(DEPDIR)/$(am__dirstamp)
 nir/nir_lower_subgroups.lo: nir/$(am__dirstamp) \
@@ -2358,6 +2362,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ 
@am__quote@nir/$(DEPDIR)/nir_lower_phis_to_scalar.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ 
@am__quote@nir/$(DEPDIR)/nir_lower_regs_to_ssa.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ 
@am__quote@nir/$(DEPDIR)/nir_lower_returns.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ 
@am__quote@nir/$(DEPDIR)/nir_lower_samplers.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ 
@am__quote@nir/$(DEPDIR)/nir_lower_scratch.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ 
@am__quote@nir/$(DEPDIR)/nir_lower_subgroups.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ 
@am__quote@nir/$(DEPDIR)/nir_lower_system_values.Plo@am__quote@
Index: src/compiler/Makefile.sources
===================================================================
RCS file: /cvs/xenocara/lib/mesa/src/compiler/Makefile.sources,v
retrieving revision 1.8
diff -u -p -r1.8 Makefile.sources
--- src/compiler/Makefile.sources       22 Jan 2020 02:49:22 -0000      1.8
+++ src/compiler/Makefile.sources       25 Jan 2020 02:29:20 -0000
@@ -273,6 +273,7 @@ NIR_FILES = \
        nir/nir_lower_phis_to_scalar.c \
        nir/nir_lower_regs_to_ssa.c \
        nir/nir_lower_returns.c \
+       nir/nir_lower_samplers.c \
        nir/nir_lower_scratch.c \
        nir/nir_lower_subgroups.c \
        nir/nir_lower_system_values.c \
Index: src/compiler/glsl/gl_nir_lower_samplers.c
===================================================================
RCS file: /cvs/xenocara/lib/mesa/src/compiler/glsl/gl_nir_lower_samplers.c,v
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.2 gl_nir_lower_samplers.c
--- src/compiler/glsl/gl_nir_lower_samplers.c   23 May 2019 04:39:33 -0000      
1.1.1.2
+++ src/compiler/glsl/gl_nir_lower_samplers.c   25 Jan 2020 02:29:20 -0000
@@ -24,142 +24,16 @@
  */
 
 #include "compiler/nir/nir.h"
-#include "compiler/nir/nir_builder.h"
 #include "gl_nir.h"
-#include "ir_uniform.h"
-
-#include "main/compiler.h"
-#include "main/mtypes.h"
-
-static void
-lower_tex_src_to_offset(nir_builder *b,
-                        nir_tex_instr *instr, unsigned src_idx)
-{
-   nir_ssa_def *index = NULL;
-   unsigned base_index = 0;
-   unsigned array_elements = 1;
-   nir_tex_src *src = &instr->src[src_idx];
-   bool is_sampler = src->src_type == nir_tex_src_sampler_deref;
-
-   /* We compute first the offsets */
-   nir_deref_instr *deref = nir_instr_as_deref(src->src.ssa->parent_instr);
-   while (deref->deref_type != nir_deref_type_var) {
-      assert(deref->parent.is_ssa);
-      nir_deref_instr *parent =
-         nir_instr_as_deref(deref->parent.ssa->parent_instr);
-
-      assert(deref->deref_type == nir_deref_type_array);
-
-      if (nir_src_is_const(deref->arr.index) && index == NULL) {
-         /* We're still building a direct index */
-         base_index += nir_src_as_uint(deref->arr.index) * array_elements;
-      } else {
-         if (index == NULL) {
-            /* We used to be direct but not anymore */
-            index = nir_imm_int(b, base_index);
-            base_index = 0;
-         }
-
-         index = nir_iadd(b, index,
-                          nir_imul(b, nir_imm_int(b, array_elements),
-                                   nir_ssa_for_src(b, deref->arr.index, 1)));
-      }
-
-      array_elements *= glsl_get_length(parent->type);
-
-      deref = parent;
-   }
-
-   if (index)
-      index = nir_umin(b, index, nir_imm_int(b, array_elements - 1));
-
-   /* We hit the deref_var.  This is the end of the line */
-   assert(deref->deref_type == nir_deref_type_var);
-
-   base_index += deref->var->data.binding;
-
-   /* We have the offsets, we apply them, rewriting the source or removing
-    * instr if needed
-    */
-   if (index) {
-      nir_instr_rewrite_src(&instr->instr, &src->src,
-                            nir_src_for_ssa(index));
-
-      src->src_type = is_sampler ?
-         nir_tex_src_sampler_offset :
-         nir_tex_src_texture_offset;
-
-      instr->texture_array_size = array_elements;
-   } else {
-      nir_tex_instr_remove_src(instr, src_idx);
-   }
-
-   if (is_sampler) {
-      instr->sampler_index = base_index;
-   } else {
-      instr->texture_index = base_index;
-      instr->texture_array_size = array_elements;
-   }
-}
-
-static bool
-lower_sampler(nir_builder *b, nir_tex_instr *instr)
-{
-   int texture_idx =
-      nir_tex_instr_src_index(instr, nir_tex_src_texture_deref);
-
-   if (texture_idx >= 0) {
-      b->cursor = nir_before_instr(&instr->instr);
-
-      lower_tex_src_to_offset(b, instr, texture_idx);
-   }
-
-   int sampler_idx =
-      nir_tex_instr_src_index(instr, nir_tex_src_sampler_deref);
-
-   if (sampler_idx >= 0) {
-      lower_tex_src_to_offset(b, instr, sampler_idx);
-   }
-
-   if (texture_idx < 0 && sampler_idx < 0)
-      return false;
-
-   return true;
-}
-
-static bool
-lower_impl(nir_function_impl *impl)
-{
-   nir_builder b;
-   nir_builder_init(&b, impl);
-   bool progress = false;
-
-   nir_foreach_block(block, impl) {
-      nir_foreach_instr(instr, block) {
-         if (instr->type == nir_instr_type_tex)
-            progress |= lower_sampler(&b, nir_instr_as_tex(instr));
-      }
-   }
-
-   return progress;
-}
 
 bool
 gl_nir_lower_samplers(nir_shader *shader,
                       const struct gl_shader_program *shader_program)
 {
-   bool progress = false;
-
    /* First, use gl_nir_lower_samplers_as_derefs to set var->data.binding
     * based on the uniforms, and split structures to simplify derefs.
     */
    gl_nir_lower_samplers_as_deref(shader, shader_program);
 
-   /* Next, lower derefs to offsets. */
-   nir_foreach_function(function, shader) {
-      if (function->impl)
-         progress |= lower_impl(function->impl);
-   }
-
-   return progress;
+   return nir_lower_samplers(shader);
 }
Index: src/compiler/nir/meson.build
===================================================================
RCS file: /cvs/xenocara/lib/mesa/src/compiler/nir/meson.build,v
retrieving revision 1.1.1.3
diff -u -p -r1.1.1.3 meson.build
--- src/compiler/nir/meson.build        22 Jan 2020 02:08:11 -0000      1.1.1.3
+++ src/compiler/nir/meson.build        25 Jan 2020 02:29:20 -0000
@@ -152,6 +152,7 @@ files_libnir = files(
   'nir_lower_point_size.c',
   'nir_lower_regs_to_ssa.c',
   'nir_lower_returns.c',
+  'nir_lower_samplers.c',
   'nir_lower_scratch.c',
   'nir_lower_subgroups.c',
   'nir_lower_system_values.c',
Index: src/compiler/nir/nir.h
===================================================================
RCS file: /cvs/xenocara/lib/mesa/src/compiler/nir/nir.h,v
retrieving revision 1.8
diff -u -p -r1.8 nir.h
--- src/compiler/nir/nir.h      22 Jan 2020 02:49:23 -0000      1.8
+++ src/compiler/nir/nir.h      25 Jan 2020 02:29:20 -0000
@@ -3944,6 +3944,8 @@ bool nir_lower_phis_to_regs_block(nir_bl
 bool nir_lower_ssa_defs_to_regs_block(nir_block *block);
 bool nir_rematerialize_derefs_in_use_blocks_impl(nir_function_impl *impl);
 
+bool nir_lower_samplers(nir_shader *shader);
+
 /* This is here for unit tests. */
 bool nir_opt_comparison_pre_impl(nir_function_impl *impl);
 
Index: src/gallium/auxiliary/meson.build
===================================================================
RCS file: /cvs/xenocara/lib/mesa/src/gallium/auxiliary/meson.build,v
retrieving revision 1.1.1.3
diff -u -p -r1.1.1.3 meson.build
--- src/gallium/auxiliary/meson.build   22 Jan 2020 02:08:27 -0000      1.1.1.3
+++ src/gallium/auxiliary/meson.build   25 Jan 2020 02:29:20 -0000
@@ -525,12 +525,9 @@ libgallium = static_library(
   cpp_args : [cpp_vis_args, cpp_msvc_compat_args],
   dependencies : [
     dep_libdrm, dep_llvm, dep_unwind, dep_dl, dep_m, dep_thread, dep_lmsensors,
-    idep_nir_headers,
+    idep_nir, idep_nir_headers, idep_mesautil,
   ],
-  build_by_default : false,
-  link_with: [
-    libglsl
-  ]
+  build_by_default : false
 )
 
 libgalliumvl_stub = static_library(
Index: src/gallium/auxiliary/nir/tgsi_to_nir.c
===================================================================
RCS file: /cvs/xenocara/lib/mesa/src/gallium/auxiliary/nir/tgsi_to_nir.c,v
retrieving revision 1.8
diff -u -p -r1.8 tgsi_to_nir.c
--- src/gallium/auxiliary/nir/tgsi_to_nir.c     22 Jan 2020 02:49:26 -0000      
1.8
+++ src/gallium/auxiliary/nir/tgsi_to_nir.c     25 Jan 2020 02:29:20 -0000
@@ -28,8 +28,6 @@
 #include "compiler/nir/nir.h"
 #include "compiler/nir/nir_control_flow.h"
 #include "compiler/nir/nir_builder.h"
-#include "compiler/glsl/gl_nir.h"
-#include "compiler/glsl/list.h"
 #include "compiler/shader_enums.h"
 
 #include "tgsi_to_nir.h"
@@ -1307,7 +1305,8 @@ get_sampler_var(struct ttn_compile *c, i
                 enum glsl_sampler_dim dim,
                 bool is_shadow,
                 bool is_array,
-                enum glsl_base_type base_type)
+                enum glsl_base_type base_type,
+                nir_texop op)
 {
    nir_variable *var = c->samplers[binding];
    if (!var) {
@@ -1318,6 +1317,14 @@ get_sampler_var(struct ttn_compile *c, i
       var->data.binding = binding;
       var->data.explicit_binding = true;
       c->samplers[binding] = var;
+
+      /* Record textures used */
+      unsigned mask = 1 << binding;
+      c->build.shader->info.textures_used |= mask;
+      if (op == nir_texop_txf ||
+          op == nir_texop_txf_ms ||
+          op == nir_texop_txf_ms_mcs)
+         c->build.shader->info.textures_used_by_txf |= mask;
    }
 
    return var;
@@ -1502,7 +1509,8 @@ ttn_tex(struct ttn_compile *c, nir_alu_d
       get_sampler_var(c, sview, instr->sampler_dim,
                       instr->is_shadow,
                       instr->is_array,
-                      base_type_for_alu_type(instr->dest_type));
+                      base_type_for_alu_type(instr->dest_type),
+                      op);
 
    nir_deref_instr *deref = nir_build_deref_var(b, var);
 
@@ -1666,7 +1674,8 @@ ttn_txq(struct ttn_compile *c, nir_alu_d
       get_sampler_var(c, tex_index, txs->sampler_dim,
                       txs->is_shadow,
                       txs->is_array,
-                      base_type_for_alu_type(txs->dest_type));
+                      base_type_for_alu_type(txs->dest_type),
+                      nir_texop_txs);
 
    nir_deref_instr *deref = nir_build_deref_var(b, var);
 
@@ -2614,10 +2623,8 @@ ttn_finalize_nir(struct ttn_compile *c)
    if (c->cap_packed_uniforms)
       NIR_PASS_V(nir, nir_lower_uniforms_to_ubo, 16);
 
-   if (c->cap_samplers_as_deref)
-      NIR_PASS_V(nir, gl_nir_lower_samplers_as_deref, NULL);
-   else
-      NIR_PASS_V(nir, gl_nir_lower_samplers, NULL);
+   if (!c->cap_samplers_as_deref)
+      NIR_PASS_V(nir, nir_lower_samplers);
 
    ttn_optimize_nir(nir, c->cap_scalar);
    nir_shader_gather_info(nir, c->build.impl);

Reply via email to