Re: [Mesa-dev] [PATCH] gbm: add gbm_{bo, surface}_create_with_modifiers2

2019-06-26 Thread Ben Widawsky
On 19-06-25 10:02:55, Daniel Stone wrote:
> Hi,
> 
> On Tue, 25 Jun 2019 at 07:26, Simon Ser  wrote:
> > > I noticed that original patch (v1) for gbm_bo_create_with_modifiers did
> > > have usage at first but it was removed during the review. I'm having
> > > trouble digging what was the reason for this?
> >
> > I'm not sure either. Daniel said it was a mistake.
> >
> > Adding the 63bd2ae7452d4 folks to the discussion. Ben, do you remember
> > the details?
> 
> We decided to remove it since we decided that modifiers were a good
> enough proxy for usage; no need to pass SCANOUT or TEXTURE anymore,
> because we already get the scanout modifiers from KMS and the texture
> modifiers from EGL.
> 
> In hindsight, I think this was a mistake since it only handles buffer
> layout, and not buffer placement or cache configuration.
> 
> Cheers,
> Daniel

Yeah... leaving an optional usage would have been ideal, however, I think the
way I peddled it, it was required - so we were all wrong :-)

-- 
Ben Widawsky, Intel Open Source Technology Center
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Re: [Mesa-dev] [PATCH] RFC: Externd IMG_context_priority with NV_context_priority_realtime

2018-04-06 Thread Ben Widawsky

On 18-03-31 12:00:16, Chris Wilson wrote:

Quoting Kenneth Graunke (2018-03-30 19:20:57)

On Friday, March 30, 2018 7:40:13 AM PDT Chris Wilson wrote:
> For i915, we are proposing to use a quality-of-service parameter in
> addition to that of just a priority that usurps everyone. Due to our HW,
> preemption may not be immediate and will be forced to wait until an
> uncooperative process hits an arbitration point. To prevent that unduly
> impacting the privileged RealTime context, we back up the preemption
> request with a timeout to reset the GPU and forcibly evict the GPU hog
> in order to execute the new context.

I am strongly against exposing this in general.  Performing a GPU reset
in the middle of a batch can completely screw up whatever application
was running.  If the application is using robustness extensions, we may
be forced to return GL_DEVICE_LOST, causing the application to have to
recreate their entire GL context and start over.  If not, we may try to
let them limp on(*) - and hope they didn't get too badly damaged by some
of their commands not executing, or executing twice (if the kernel tries
to resubmit it).  But it may very well cause the app to misrender, or
even crash.


Yes, I think the revulsion has been universal. However, as a
quality-of-service guarantee, I can understand the appeal. The
difference is that instead of allowing a DoS for 6s or so as we
currently allow, we allow that to be specified by the context. As it
does allow one context to impact another, I want it locked down to
privileged processes. I have been using CAP_SYS_ADMIN as the potential
to do harm is even greater than exploiting the weak scheduler by
changing priority.



I'm not terribly worried about this on our hardware for 3d. Today, there is
exactly one case I think where this would happen, if you have a sufficiently
long running shader on a sufficiently large triangle.

The concern I have is about compute where I think we don't do preemption nearly
as well.


This seems like a crazy plan to me.  Scheduling has never been allowed
to just kill random processes.


That's not strictly true, as processes have their limits which if they
exceed they will be killed. On the CPU preemption is much better, the
issue of unyielding processes is pretty much limited to the kernel, where
we can run the NMI watchdog to kill broken code.


If you ever hit that case, then your
customers will see random application crashes, glitches, GPU hangs,
and be pretty unhappy with the result.  And not because something was
broken, but because somebody was impatient and an app was a bit slow.


Yes, that is their decision. Kill random apps so that their
uber-critical interface updates the clock.


If you have work that is so mission critical, maybe you shouldn't run it
on the same machine as one that runs applications which you care so
little about that you're willing to watch them crash and burn.  Don't
run the entertainment system on the flight computer, so to speak.


You are not the first to say that ;)
-Chris



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


Re: [Mesa-dev] [PATCH] intel/gen9+: Enable object level preemption.

2018-02-20 Thread Ben Widawsky

On 18-02-20 09:15:01, Antognolli, Rafael wrote:

On Tue, Feb 20, 2018 at 08:11:14AM -0800, Rafael Antognolli wrote:

On Fri, Feb 16, 2018 at 06:37:55PM -0800, Ben Widawsky wrote:
> On 18-02-16 13:44:00, Antognolli, Rafael wrote:
> > "This field controls the granularity of the replay mechanism when
> > coming back into a previously preempted context."
> >
> > The kernel disables this bit but whitelists the register, and it's a
> > context register. So enable it and take advantage of finer granularity
> > when preemption is available.
> >
>
> Does the kernel actually disable it? I thought the kernel just doesn't touch 
it
> (I don't think it's whitelisted by the kernel either, it's just writable).

I'm seeing it being disabled at WaDisable3DMidCmdPreemption, seems to be
in effect since commit 5152defe4a53ad15e6d96c422440152302c8abd7.

And it's whitelisted by WaEnablePreemptionGranularityControlByUMD.

> > Signed-off-by: Rafael Antognolli 
> > Cc: Ben Widawsky 
> > ---
> >
> > This patch still needs more testing (only ran it through CI and also did
> > some basic tests on my machine to make sure it's not breaking anything).
> >
> > src/intel/genxml/gen10.xml   |  8 
> > src/intel/genxml/gen11.xml   |  8 
> > src/intel/genxml/gen9.xml|  8 
> > src/intel/vulkan/genX_state.c| 18 ++
> > src/mesa/drivers/dri/i965/brw_defines.h  |  5 +
> > src/mesa/drivers/dri/i965/brw_state_upload.c | 10 ++
> > 6 files changed, 57 insertions(+)
> >
> > diff --git a/src/intel/genxml/gen10.xml b/src/intel/genxml/gen10.xml
> > index 47c679a3fa9..42ac6e82696 100644
> > --- a/src/intel/genxml/gen10.xml
> > +++ b/src/intel/genxml/gen10.xml
> > @@ -3692,6 +3692,14 @@
> > 
> >   
> >
> > +  
> > +
> > +  
> > +  
> > +
> > +
> > +  
> > +
> >   
> > 
> >   
> > diff --git a/src/intel/genxml/gen11.xml b/src/intel/genxml/gen11.xml
> > index 9a8a2fe21e3..e6ce42b2bfb 100644
> > --- a/src/intel/genxml/gen11.xml
> > +++ b/src/intel/genxml/gen11.xml
> > @@ -3688,6 +3688,14 @@
> > 
> >   
> >
> > +  
> > +
> > +  
> > +  
> > +
> > +
> > +  
> > +
> >   
> > 
> >   
> > diff --git a/src/intel/genxml/gen9.xml b/src/intel/genxml/gen9.xml
> > index 7eef4bee013..45e1fddeb50 100644
> > --- a/src/intel/genxml/gen9.xml
> > +++ b/src/intel/genxml/gen9.xml
> > @@ -3638,6 +3638,14 @@
> > 
> >   
> >
> > +  
> > +
> > +  
> > +  
> > +
> > +
> > +  
> > +
> >   
> > 
> >   
> > diff --git a/src/intel/vulkan/genX_state.c b/src/intel/vulkan/genX_state.c
> > index 54fb8634fdc..83b6c6387f3 100644
> > --- a/src/intel/vulkan/genX_state.c
> > +++ b/src/intel/vulkan/genX_state.c
> > @@ -169,6 +169,24 @@ genX(init_device_state)(struct anv_device *device)
> >gen10_emit_wa_lri_to_cache_mode_zero(&batch);
> > #endif
> >
> > +#if GEN_GEN >= 9
> > +   /* A fixed function pipe flush is required before modifying this field 
*/
> > +   anv_batch_emit(&batch, GENX(PIPE_CONTROL), pipe) {
> > +  pipe.PipeControlFlushEnable = true;
> > +   }
> > +
> > +   /* enable object level preemption */
> > +   uint32_t csc1;
> > +
> > +   anv_pack_struct(&csc1, GENX(CS_CHICKEN1),
> > +   .ReplayMode = ObjectLevelPreemption,
> > +   .ReplayModeMask = 1);
> > +   anv_batch_emit(&batch, GENX(MI_LOAD_REGISTER_IMM), lri) {
> > +  lri.RegisterOffset   = GENX(CS_CHICKEN1_num);
> > +  lri.DataDWord= csc1;
> > +   }
> > +#endif
> > +
> >anv_batch_emit(&batch, GENX(MI_BATCH_BUFFER_END), bbe);
> >
> >assert(batch.next <= batch.end);
> > diff --git a/src/mesa/drivers/dri/i965/brw_defines.h 
b/src/mesa/drivers/dri/i965/brw_defines.h
> > index 8bf6f68b67c..f0994d3b139 100644
> > --- a/src/mesa/drivers/dri/i965/brw_defines.h
> > +++ b/src/mesa/drivers/dri/i965/brw_defines.h
> > @@ -1661,4 +1661,9 @@ enum brw_pixel_shader_coverage_mask_mode {
> > # define GLK_SCEC_BARRIER_MODE_3D_HULL (1 << 7)
> > # define GLK_SCEC_BARRIER_MODE_MASKREG_MASK(1 << 7)
> >
> > +#define CS_CHICKEN10x2580 /* Gen9+ */
>

Re: [Mesa-dev] [PATCH] intel/gen9+: Enable object level preemption.

2018-02-16 Thread Ben Widawsky

On 18-02-16 13:44:00, Antognolli, Rafael wrote:

"This field controls the granularity of the replay mechanism when
coming back into a previously preempted context."

The kernel disables this bit but whitelists the register, and it's a
context register. So enable it and take advantage of finer granularity
when preemption is available.



Does the kernel actually disable it? I thought the kernel just doesn't touch it
(I don't think it's whitelisted by the kernel either, it's just writable).


Signed-off-by: Rafael Antognolli 
Cc: Ben Widawsky 
---

This patch still needs more testing (only ran it through CI and also did
some basic tests on my machine to make sure it's not breaking anything).

src/intel/genxml/gen10.xml   |  8 
src/intel/genxml/gen11.xml   |  8 
src/intel/genxml/gen9.xml|  8 
src/intel/vulkan/genX_state.c| 18 ++
src/mesa/drivers/dri/i965/brw_defines.h  |  5 +
src/mesa/drivers/dri/i965/brw_state_upload.c | 10 ++
6 files changed, 57 insertions(+)

diff --git a/src/intel/genxml/gen10.xml b/src/intel/genxml/gen10.xml
index 47c679a3fa9..42ac6e82696 100644
--- a/src/intel/genxml/gen10.xml
+++ b/src/intel/genxml/gen10.xml
@@ -3692,6 +3692,14 @@

  

+  
+
+  
+  
+
+
+  
+
  

  
diff --git a/src/intel/genxml/gen11.xml b/src/intel/genxml/gen11.xml
index 9a8a2fe21e3..e6ce42b2bfb 100644
--- a/src/intel/genxml/gen11.xml
+++ b/src/intel/genxml/gen11.xml
@@ -3688,6 +3688,14 @@

  

+  
+
+  
+  
+
+
+  
+
  

  
diff --git a/src/intel/genxml/gen9.xml b/src/intel/genxml/gen9.xml
index 7eef4bee013..45e1fddeb50 100644
--- a/src/intel/genxml/gen9.xml
+++ b/src/intel/genxml/gen9.xml
@@ -3638,6 +3638,14 @@

  

+  
+
+  
+  
+
+
+  
+
  

  
diff --git a/src/intel/vulkan/genX_state.c b/src/intel/vulkan/genX_state.c
index 54fb8634fdc..83b6c6387f3 100644
--- a/src/intel/vulkan/genX_state.c
+++ b/src/intel/vulkan/genX_state.c
@@ -169,6 +169,24 @@ genX(init_device_state)(struct anv_device *device)
   gen10_emit_wa_lri_to_cache_mode_zero(&batch);
#endif

+#if GEN_GEN >= 9
+   /* A fixed function pipe flush is required before modifying this field */
+   anv_batch_emit(&batch, GENX(PIPE_CONTROL), pipe) {
+  pipe.PipeControlFlushEnable = true;
+   }
+
+   /* enable object level preemption */
+   uint32_t csc1;
+
+   anv_pack_struct(&csc1, GENX(CS_CHICKEN1),
+   .ReplayMode = ObjectLevelPreemption,
+   .ReplayModeMask = 1);
+   anv_batch_emit(&batch, GENX(MI_LOAD_REGISTER_IMM), lri) {
+  lri.RegisterOffset   = GENX(CS_CHICKEN1_num);
+  lri.DataDWord= csc1;
+   }
+#endif
+
   anv_batch_emit(&batch, GENX(MI_BATCH_BUFFER_END), bbe);

   assert(batch.next <= batch.end);
diff --git a/src/mesa/drivers/dri/i965/brw_defines.h 
b/src/mesa/drivers/dri/i965/brw_defines.h
index 8bf6f68b67c..f0994d3b139 100644
--- a/src/mesa/drivers/dri/i965/brw_defines.h
+++ b/src/mesa/drivers/dri/i965/brw_defines.h
@@ -1661,4 +1661,9 @@ enum brw_pixel_shader_coverage_mask_mode {
# define GLK_SCEC_BARRIER_MODE_3D_HULL (1 << 7)
# define GLK_SCEC_BARRIER_MODE_MASKREG_MASK(1 << 7)

+#define CS_CHICKEN10x2580 /* Gen9+ */
+# define GEN9_REPLAY_MODE_MIDBUFFER (0 << 0)
+# define GEN9_REPLAY_MODE_MIDOBJECT (1 << 0)
+# define GEN9_REPLAY_MODE_MASK  REG_MASK(1 << 0)
+
#endif
diff --git a/src/mesa/drivers/dri/i965/brw_state_upload.c 
b/src/mesa/drivers/dri/i965/brw_state_upload.c
index 86c12e4d357..a90dc01d87b 100644
--- a/src/mesa/drivers/dri/i965/brw_state_upload.c
+++ b/src/mesa/drivers/dri/i965/brw_state_upload.c
@@ -115,6 +115,16 @@ brw_upload_initial_gpu_state(struct brw_context *brw)
  OUT_BATCH(0);
  ADVANCE_BATCH();
   }
+
+   if (devinfo->gen >= 9) {
+  /* A fixed function pipe flush is required before modifying this field */
+  brw_emit_pipe_control_flush(brw, PIPE_CONTROL_FLUSH_ENABLE);
+
+  /* enable object level preemption */
+  brw_load_register_imm32(brw, CS_CHICKEN1,
+  GEN9_REPLAY_MODE_MIDOBJECT |
+  GEN9_REPLAY_MODE_MASK);
+   }


One other option BTW is a context parameter in i915 driver. Note sure if you
discussed this with the i915 folks, but it could make some sense.



}

static inline const struct brw_tracked_state *


Everything looks in order to me.

Reviewed-by: Ben Widawsky 


--
2.14.3


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


Re: [Mesa-dev] [PATCH] intel/compiler/gen10: Disable push constants.

2017-12-18 Thread Ben Widawsky

On 17-12-18 15:23:11, Antognolli, Rafael wrote:

We still have gpu hangs on Cannonlake when using push constants, so
disable them for now until we have a proper fix for these hangs.

v2: Add warning message when creating context too.

Signed-off-by: Rafael Antognolli 
Cc: Ben Widawsky 
Cc: Kenneth Graunke 


Since this improves the current situation by enabling more workloads to be run
by folks with these platforms, and we don't regress any of the conformance
suites, this is:

Reviewed-by: Ben Widawsky 

I'd go as far as to suggest this for stable, but I know there's a lot of
heartburn around that.


---
src/intel/compiler/brw_fs.cpp   | 9 +
src/mesa/drivers/dri/i965/brw_context.c | 7 +++
2 files changed, 16 insertions(+)

diff --git a/src/intel/compiler/brw_fs.cpp b/src/intel/compiler/brw_fs.cpp
index 3717c50e32a..6d9f0eccb29 100644
--- a/src/intel/compiler/brw_fs.cpp
+++ b/src/intel/compiler/brw_fs.cpp
@@ -2096,6 +2096,15 @@ fs_visitor::assign_constant_locations()
   if (subgroup_id_index >= 0)
  max_push_components--; /* Save a slot for the thread ID */

+   /* FIXME: We currently have some GPU hangs that happen apparently when using
+* push constants. Since we have no solution for such hangs yet, just
+* go ahead and use pull constants for now.
+*/
+   if (devinfo->gen == 10 && compiler->supports_pull_constants) {
+  compiler->shader_perf_log(log_data, "Disabling push constants.");
+  max_push_components = 0;
+   }
+
   /* We push small arrays, but no bigger than 16 floats.  This is big enough
* for a vec4 but hopefully not large enough to push out other stuff.  We
* should probably use a better heuristic at some point.
diff --git a/src/mesa/drivers/dri/i965/brw_context.c 
b/src/mesa/drivers/dri/i965/brw_context.c
index 126c187f629..b555f7bfdf1 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -1022,6 +1022,13 @@ brwCreateContext(gl_api api,
  return false;
   }

+   if (devinfo->gen == 10) {
+  fprintf(stderr,
+  "WARNING: i965 does not fully support Gen10 yet.\n"
+  "Instability or lower performance might occur.\n");
+
+   }
+
   brw_init_state(brw);

   intelInitExtensions(ctx);
--
2.14.3


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


Re: [Mesa-dev] [PATCH] i965: add 2xMSAA and 16xMSAA to DRI configs for Gen9.

2017-08-24 Thread Ben Widawsky

On 17-08-24 14:16:39, kevin.rogo...@intel.com wrote:

From: Kevin Rogovin 

Special thanks to Eero Tamminen for reporting rasterizer
numbers being twice what it should be for 2xMSAA under
a benchmark.

Signed-off-by: Kevin Rogovin 
---
src/mesa/drivers/dri/i965/intel_screen.c | 14 +++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 579554f..67eb776 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -1882,7 +1882,7 @@ intel_screen_make_configs(__DRIscreen *dri_screen)
   };

   static const uint8_t singlesample_samples[1] = {0};
-   static const uint8_t multisample_samples[2]  = {4, 8};
+   static const uint8_t multisample_samples_2_4_8_16[]  = {2, 4, 8, 16};

   struct intel_screen *screen = dri_screen->driverPrivate;
   const struct gen_device_info *devinfo = &screen->devinfo;
@@ -1959,6 +1959,7 @@ intel_screen_make_configs(__DRIscreen *dri_screen)
* supported.  Singlebuffer configs are not supported because no one wants
* them.
*/
+


No unnecessary whitespace changes, please.


   for (unsigned i = 0; i < ARRAY_SIZE(formats); i++) {
  if (devinfo->gen < 6)
 break;
@@ -1966,6 +1967,7 @@ intel_screen_make_configs(__DRIscreen *dri_screen)
  __DRIconfig **new_configs;
  const int num_depth_stencil_bits = 2;
  int num_msaa_modes = 0;
+  const uint8_t *multisample_samples = NULL;

  depth_bits[0] = 0;
  stencil_bits[0] = 0;
@@ -1978,10 +1980,16 @@ intel_screen_make_configs(__DRIscreen *dri_screen)
 stencil_bits[1] = 8;
  }

-  if (devinfo->gen >= 7)
+  if (devinfo->gen >= 9) {
+ multisample_samples = multisample_samples_2_4_8_16;
+ num_msaa_modes = 4;
+  } else if (devinfo->gen >= 7) {
+ multisample_samples = multisample_samples_2_4_8_16 + 1;
 num_msaa_modes = 2;
-  else if (devinfo->gen == 6)
+  } else if (devinfo->gen == 6) {
+ multisample_samples = multisample_samples_2_4_8_16 + 1;
 num_msaa_modes = 1;
+  }


I think it'd be a little cleaner to just make GEN specific arrays. Easier to
read, and you can just USE ARRAY_SIZE but I honestly don't care much.

if (devinfo->gen >= 9) {
  multisample_samples = multisample_samples_gen9;
  num_msaa_modes = ARRAY_SIZE(multisample_samples_gen9);
}



  new_configs = driCreateConfigs(formats[i],
 depth_bits,


Kind of shocking to me that we missed this previously for both when we added 2x
MSAA and later 16x. Indeed looking at glxinfo, I see no 2x or 16x visuals.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH mesa] i965: add missing `const` in function signature

2017-08-24 Thread Ben Widawsky

On 17-08-24 11:01:34, Matt Turner wrote:

Reviewed-by: Matt Turner 


I'm blaming this one on someone else's rebase ;-)
Reviewed-by: Ben Widawsky 


___
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 v2 4/5] intel/screen: Report the correct number of image planes

2017-08-16 Thread Ben Widawsky

On 17-08-16 13:26:00, Jason Ekstrand wrote:

For non-CCS images, we were reporting just one plane even though they
may have multiple in the case of YUV.

Cc: 


This has been wrong since it's initial implementation in 2014, ie. not stable
material IMO..

Reviewed-by: Ben Widawsky 


---
src/mesa/drivers/dri/i965/intel_screen.c | 9 -
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 9e65273..d454eeb 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -799,7 +799,14 @@ intel_query_image(__DRIimage *image, int attrib, int 
*value)
   case __DRI_IMAGE_ATTRIB_FOURCC:
  return intel_lookup_fourcc(image->dri_format, value);
   case __DRI_IMAGE_ATTRIB_NUM_PLANES:
-  *value = isl_drm_modifier_has_aux(image->modifier) ? 2 : 1;
+  if (isl_drm_modifier_has_aux(image->modifier)) {
+ assert(!image->planar_format || image->planar_format->nplanes == 1);
+ *value = 2;
+  } else if (image->planar_format) {
+ *value = image->planar_format->nplanes;
+  } else {
+ *value = 1;
+  }
  return true;
   case __DRI_IMAGE_ATTRIB_OFFSET:
  *value = image->offset;
--
2.5.0.400.gff86faf

___
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 2/2] i965/screen: Stop redefining DRM_FORMAT_MOD_(INVALID|LINEAR)

2017-08-14 Thread Ben Widawsky

On 17-08-14 10:13:23, Jason Ekstrand wrote:

---
src/mesa/drivers/dri/i965/intel_screen.c | 8 
1 file changed, 8 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 452f0d1..a22d63e 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -43,14 +43,6 @@
#include "utils.h"
#include "util/xmlpool.h"

-#ifndef DRM_FORMAT_MOD_INVALID
-#define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
-#endif
-
-#ifndef DRM_FORMAT_MOD_LINEAR
-#define DRM_FORMAT_MOD_LINEAR 0
-#endif
-
static const __DRIconfigOptionsExtension brw_config_options = {
   .base = { __DRI_CONFIG_OPTIONS, 1 },
   .xml =



Both are:
Reviewed-by: Ben Widawsky 

--
Ben Widawsky, Intel Open Source Technology Center
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [Intel-gfx] [PATCH 3/3] intel: Make driver aware of MOCS table version

2017-07-20 Thread Ben Widawsky

On 17-07-07 09:28:08, Jason Ekstrand wrote:

On Thu, Jul 6, 2017 at 4:27 PM, Ben Widawsky  wrote:


We don't yet have optimal MOCS settings, but we have enough to know how
to at least determine when we might have non-optimal settings within our
driver.

Signed-off-by: Ben Widawsky 
---
 src/intel/vulkan/anv_device.c | 12 
 src/intel/vulkan/anv_private.h|  2 ++
 src/mesa/drivers/dri/i915/intel_context.c |  7 ++-
 src/mesa/drivers/dri/i965/intel_screen.c  | 14 ++
 src/mesa/drivers/dri/i965/intel_screen.h  |  2 ++
 5 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 3dc55dbb8d..8e180dbf18 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -368,6 +368,18 @@ anv_physical_device_init(struct anv_physical_device
*device,
  device->info.max_cs_threads = max_cs_threads;
}

+   if (device->info.gen >= 9) {
+  device->mocs_version = anv_gem_get_param(fd,
+
 I915_PARAM_MOCS_TABLE_VERSION);
+  switch (device->mocs_version) {
+  default:
+ anv_perf_warn("Kernel exposes newer MOCS table\n");



A perf_warn here seems reasonable though it makes more sense to me to make
it

if (device->mocs_version > ANV_MAX_KNOWN_MOCS_VERSION)
  anv_perf_warn("...");




One thing to keep in mind: the max MOCS version can vary by platform (hopefully
it doesn't).


+  case 1:
+  case 0:
+ device->mocs_version = MOCS_TABLE_VERSION;



Why are we stomping device->mocs_version to MOCS_TABLE_VERSION?  Are you
just trying to avoid the version 0?  If so, why not just have

/* If the MOCS_TABLE_VERSION query fails, assume version 1 */
if (device->mocs_version == 0)
  device->mocs_version = 1;



I think the switch looks better, especially as the versions increase.


I don't think we want to have it dependent on a #define in an external
header file.  What if someone updates it for i965 and doesn't update anv or
vice-versa?




Yeah, I am removing that external define as mentioned in the other thread. I
think it was a bad idea that I jammed in at the last minute.


+  }
+   }
+
brw_process_intel_debug_variable();

device->compiler = brw_compiler_create(NULL, &device->info);
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_
private.h
index 573778dad5..b8241a9b22 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -684,6 +684,8 @@ struct anv_physical_device {
 uint32_teu_total;
 uint32_tsubslice_total;

+uint8_t mocs_version;
+
 struct {
   uint32_t  type_count;
   struct anv_memory_type
types[VK_MAX_MEMORY_TYPES];
diff --git a/src/mesa/drivers/dri/i915/intel_context.c
b/src/mesa/drivers/dri/i915/intel_context.c
index e0766a0e3f..9169ea650e 100644
--- a/src/mesa/drivers/dri/i915/intel_context.c
+++ b/src/mesa/drivers/dri/i915/intel_context.c
@@ -521,8 +521,13 @@ intelInitContext(struct intel_context *intel,
INTEL_DEBUG = parse_debug_string(getenv("INTEL_DEBUG"),
debug_control);
if (INTEL_DEBUG & DEBUG_BUFMGR)
   dri_bufmgr_set_debug(intel->bufmgr, true);
-   if (INTEL_DEBUG & DEBUG_PERF)
+   if (INTEL_DEBUG & DEBUG_PERF) {
   intel->perf_debug = true;
+  if (screen->mocs_version > MOCS_TABLE_VERSION) {
+ fprintf(stderr, "Kernel exposes newer MOCS table\n");
+ screen->mocs_version = MOCS_TABLE_VERSION;
+  }
+   }

if (INTEL_DEBUG & DEBUG_AUB)
   drm_intel_bufmgr_gem_set_aub_dump(intel->bufmgr, true);
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c
b/src/mesa/drivers/dri/i965/intel_screen.c
index c75f2125d4..c53f133d49 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -2301,6 +2301,20 @@ __DRIconfig **intelInitScreen2(__DRIscreen
*dri_screen)
  (ret != -1 || errno != EINVAL);
}

+   if (devinfo->gen >= 9) {
+  screen->mocs_version = intel_get_integer(screen,
+
 I915_PARAM_MOCS_TABLE_VERSION);
+  switch (screen->mocs_version) {
+  case 1:
+  case 0:
+ screen->mocs_version = MOCS_TABLE_VERSION;



Same comments apply here.



+ break;
+  default:
+ /* We want to perf debug, but we can't yet */
+ break;
+  }
+   }
+
dri_screen->extensions = !screen->has_context_reset_notification
   ? screenExtensions : intelRobustScreenExtensions;

diff --git a/src/mesa/drivers/dri/i965/intel_screen.h
b/src/mesa/drivers/dri/i965/intel_screen.h
index f78b3e8f74..eb801f8155 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.h
+++ b/src/mesa/drivers/dri/i965/intel_screen.h
@@ -112,6 +

Re: [Mesa-dev] [Intel-gfx] [PATCH 1/1] drm/i915: Version the MOCS settings

2017-07-07 Thread Ben Widawsky

On 17-07-07 09:23:26, Jason Ekstrand wrote:

On Fri, Jul 7, 2017 at 3:34 AM, Chris Wilson 
wrote:


Quoting Ben Widawsky (2017-07-07 00:27:01)
>  drivers/gpu/drm/i915/i915_drv.c |  3 +++
>  drivers/gpu/drm/i915/i915_drv.h |  2 ++
  drivers/gpu/drm/i915/i915_pci.c | 13 +
>  include/uapi/drm/i915_drm.h |  8 
>  4 files changed, 22 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_drv.c
b/drivers/gpu/drm/i915/i915_drv.c
> index 9167a73f3c69..26c27b6ae814 100644
> --- a/drivers/gpu/drm/i915/i915_drv.c
> +++ b/drivers/gpu/drm/i915/i915_drv.c
> @@ -401,6 +401,9 @@ static int i915_getparam(struct drm_device *dev,
void *data,
> if (!value)
> return -ENODEV;
> break;
> +   case I915_PARAM_MOCS_TABLE_VERSION:
> +   value = INTEL_INFO(dev_priv)->mocs_version;

If we use intel_mocs_get_table_version() we can put this magic number
in intel_mocs.c next to the tables, where we can keep its history and
hopefully be able to remember to update it.

> +/* What version of the MOCS table we have. For GEN9 GPUs, the PRM
defined
> + * non-optimal settings for the MOCS table. As a result, we were
required to use a
> + * small subset, and later add new settings. This param allows
userspace to
> + * determine which settings are there.
> + */
> +#define MOCS_TABLE_VERSION   1 /* Build time MOCS table
version */

How are you planing to share this? When we update we bump this number,
and then mesa copies it across and uses it after verifying it as 0,1 on
an old kernel.



Agreed.  I don't see how having a #define for compile-time mocs version is
useful.  The compile-time version doesn't really matter and we wouldn't
want to use that in i965/anv anyway (more on that in the other patch).




I think we're all agreed here.


I don't think you want to expose the updated constant here, but symbolic
names for each version? (What would be the point?)

Next question, why a version number and not just the number of entries
defined? Each index is defined by ABI once assigned, so the number of
entries still operates as a version number and allows easy checking.

if (advanced_cacheing_idx < kernel_max_mocs)
return advanced_cacheing_idx;
if (default_cacheing_idx < kernel_max_mocs)
return default_cacheing_idx;

return follow_pte_idx;

give or take the smarts to choose the preferred indices for any
particular scenario.



I'll have to think about it a bit more but this sounds like a fairly good
idea.  I see two major benefits:

1. The kernel can return ARRAY_SIZE(mocs_table_for_your_gen) and we will
never forget to update it.
2. It makes the "does this MOCS value exist" check much easier.  I imagine
future userspace code which chooses mocs values having some sort of "try
and fall back" approach to making MOCS choices and this would be convenient.

That said, having it be a version may have it's advantages, I just don't
know what they are yet.

--Jason


Please direct comments to my response to Chris if you have more. To me it's 6
one way, half dozen the other - and I believe version has a more direct meaning
(and the ability to potentially, albeit a terrible idea, rewrite entries).

If people are going to block a review based on this, I will change it, but I'd
rather not.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [Intel-gfx] [PATCH 1/1] drm/i915: Version the MOCS settings

2017-07-07 Thread Ben Widawsky

On 17-07-07 11:34:48, Chris Wilson wrote:

Quoting Ben Widawsky (2017-07-07 00:27:01)

 drivers/gpu/drm/i915/i915_drv.c |  3 +++
 drivers/gpu/drm/i915/i915_drv.h |  2 ++
 drivers/gpu/drm/i915/i915_pci.c | 13 +
 include/uapi/drm/i915_drm.h |  8 
 4 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 9167a73f3c69..26c27b6ae814 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -401,6 +401,9 @@ static int i915_getparam(struct drm_device *dev, void *data,
if (!value)
return -ENODEV;
break;
+   case I915_PARAM_MOCS_TABLE_VERSION:
+   value = INTEL_INFO(dev_priv)->mocs_version;


If we use intel_mocs_get_table_version() we can put this magic number
in intel_mocs.c next to the tables, where we can keep its history and
hopefully be able to remember to update it.



Yeah, that seems like an improvement to me as well.


+/* What version of the MOCS table we have. For GEN9 GPUs, the PRM defined
+ * non-optimal settings for the MOCS table. As a result, we were required to 
use a
+ * small subset, and later add new settings. This param allows userspace to
+ * determine which settings are there.
+ */
+#define MOCS_TABLE_VERSION   1 /* Build time MOCS table version */


How are you planing to share this? When we update we bump this number,
and then mesa copies it across and uses it after verifying it as 0,1 on
an old kernel.

I don't think you want to expose the updated constant here, but symbolic
names for each version? (What would be the point?)



At least one thing wrong here is we would need per GEN constants, which is maybe
what you meant and I misunderstood. Assuming you had per GEN constants, which I
don't like, I believe everything works out fine. So, I'll remove this compile
time MOCS versioning.


Next question, why a version number and not just the number of entries
defined? Each index is defined by ABI once assigned, so the number of
entries still operates as a version number and allows easy checking.

if (advanced_cacheing_idx < kernel_max_mocs)
return advanced_cacheing_idx;
if (default_cacheing_idx < kernel_max_mocs)
return default_cacheing_idx;

return follow_pte_idx;

give or take the smarts to choose the preferred indices for any
particular scenario.

In the future, if we finally get user defined mocs, the table_size will
then give the start of the user modifiable indices (presming they want
to keep the predefined entries for compatibility?))
-Chris


Yes, I considered this as well. I see no difference really as to one versus the
other. In fact, if you're to support multiple table versions, I think it's
actually easier with a pure version:

switch (kernel_mocs_version) {
case 3:
return new_best_cacheing_index;
case 2:
return old_best_cacheing_index;
case 1:
return naive_best_index;
}
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 0/3] MOCS versioning

2017-07-06 Thread Ben Widawsky
Copying the kernel commit message:

Starting with GEN9, Memory Object Control State (MOCS) becomes an index
into a table as opposed to the direct programming within the command.
The table has 62 usable entries (ie 6 bits can represent all settings),
and each buffer type may use one of these 62 entries to describe
cacheability type, and age (and some other less useful fields).

Because we hadn't dealt with MOCS settings like this, we didn't think
ahead too well and have ended up with a mess for GEN9 (and soon GEN10)
platform. The plan for for future platforms is that the ideal MOCS
settings will be determined, defined, and written in the public PRMs.
After this point, the i915.ko will absorb these settings and sometime
afterwards flip the alpha switch. All driver releases without the final
MOCS table must be considered alpha. Here on, userspace can assume the
MOCS table is definitively done. There will be some reserved entries for
'oh shit' scenarios. This avoids versioning the MOCS table which leaves
somewhat of a mess in userspace trying to handle arbitrarily many MOCS
versions.

But we do have a mess on GEN9. In the beginning, the MOCS table entries
were pre-populated by the hardware based on estimations made prior to
tapeout and we could just use that. Subsequently much performance tuning
was done to determine optimal settings that the i915 driver should load
on top of the hardware defaults. That was posted last as v6 of the
original per-engine MOCS settings:
https://patchwork.freedesktop.org/patch/53237/. Since the MOCS table is
not context saved/restored, it isn't feasible to let userspace upload
its own MOCS table. After a good amount of debate, it was decided that
we'd utilize only the minimal set of entires in mesa anyway, and so we
took only those entries for our MOCS entries.

Now we've come to the realization that indeed there are other MOCS
entries which are more optimal for various buffer types and workloads.
The problem is that the meaning of the indices is ABI (we assume index 0
is the uncached entry, and that there are only 3 entries total).

What this patch [simply] aims to do is expose a parameter to inform
userspace which "version" of the table was loaded by i915. Upon
sufficient data, new entries can be added, and the version can be
bumped. For example, from my original mesa mocs branch:

commit c9b0481bce24af032386701de0266eb5bc24e988
Author: Ben Widawsky 
Date:   Fri Apr 8 10:21:16 2016 -0700

    i965: Use PTE mocs

Signed-off-by: Ben Widawsky 

diff --git a/src/mesa/drivers/dri/i965/brw_mocs.c 
b/src/mesa/drivers/dri/i965/brw_mocs.c
index 5df154eb86..b7bfdab671 100644
--- a/src/mesa/drivers/dri/i965/brw_mocs.c
+++ b/src/mesa/drivers/dri/i965/brw_mocs.c
@@ -14,6 +14,9 @@
 /* Skylake: MOCS is now an index into an array of 62 different caching
  * configurations programmed by the kernel.
  */
+
+/* TC=PTE, LeCC=PTE, LRUM=3, L3CC=WB */
+#define SKL_MOCS_PTE_PTE (3 << 1)
 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */
 #define SKL_MOCS_WB  (2 << 1)
 /* TC=LLC/eLLC, LeCC=PTE, LRUM=3, L3CC=WB */
@@ -26,6 +29,9 @@ brw_mocs_get_control_state(const struct brw_context *brw,
switch (brw->gen) {
default:
case 9:
+  if (brw->intelScreen->mocs_version > 1)
+ return SKL_MOCS_PTE_PTE;
+
   return type == INTEL_MOCS_PTE ? SKL_MOCS_PTE : SKL_MOCS_WB;
case 8:
   return type == INTEL_MOCS_PTE ? BDW_MOCS_PTE : BDW_MOCS_WB;

tl;dr: A versioned MOCS table will allow userspace to be aware of new
and potentially interesting cacheability settings. Next GEN platforms
will not be considered production worthy until the MOCS table is
finalized.

Ben Widawsky (1):
  drm/i915: Version the MOCS settings

 drivers/gpu/drm/i915/i915_drv.c |  3 +++
 drivers/gpu/drm/i915/i915_drv.h |  2 ++
 drivers/gpu/drm/i915/i915_pci.c | 13 +
 include/uapi/drm/i915_drm.h     |  8 
 4 files changed, 22 insertions(+), 4 deletions(-)

Ben Widawsky (2):
  intel: Merge latest i915 uapi
  intel: Make driver aware of MOCS table version

 src/intel/drm/i915_drm.h  |  8 
 src/intel/vulkan/anv_device.c | 12 
 src/intel/vulkan/anv_private.h|  2 ++
 src/mesa/drivers/dri/i915/intel_context.c |  7 ++-
 src/mesa/drivers/dri/i965/intel_screen.c  | 14 ++
 src/mesa/drivers/dri/i965/intel_screen.h  |  2 ++
 6 files changed, 44 insertions(+), 1 deletion(-)

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


[Mesa-dev] [PATCH 2/3] intel: Merge latest i915 uapi

2017-07-06 Thread Ben Widawsky
Signed-off-by: Ben Widawsky 
---
 src/intel/drm/i915_drm.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/src/intel/drm/i915_drm.h b/src/intel/drm/i915_drm.h
index c26bf7c125..69e38ce89f 100644
--- a/src/intel/drm/i915_drm.h
+++ b/src/intel/drm/i915_drm.h
@@ -431,6 +431,14 @@ typedef struct drm_i915_irq_wait {
  */
 #define I915_PARAM_HAS_EXEC_BATCH_FIRST 48
 
+/* What version of the MOCS table we have. For GEN9 GPUs, the PRM defined
+ * non-optimal settings for the MOCS table. As a result, we were required to 
use a
+ * small subset, and later add new settings. This param allows userspace to
+ * determine which settings are there.
+ */
+#define MOCS_TABLE_VERSION   1 /* Build time MOCS table version */
+#define I915_PARAM_MOCS_TABLE_VERSION   49
+
 typedef struct drm_i915_getparam {
__s32 param;
/*
-- 
2.13.2

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


[Mesa-dev] [PATCH 3/3] intel: Make driver aware of MOCS table version

2017-07-06 Thread Ben Widawsky
We don't yet have optimal MOCS settings, but we have enough to know how
to at least determine when we might have non-optimal settings within our
driver.

Signed-off-by: Ben Widawsky 
---
 src/intel/vulkan/anv_device.c | 12 
 src/intel/vulkan/anv_private.h|  2 ++
 src/mesa/drivers/dri/i915/intel_context.c |  7 ++-
 src/mesa/drivers/dri/i965/intel_screen.c  | 14 ++
 src/mesa/drivers/dri/i965/intel_screen.h  |  2 ++
 5 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 3dc55dbb8d..8e180dbf18 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -368,6 +368,18 @@ anv_physical_device_init(struct anv_physical_device 
*device,
  device->info.max_cs_threads = max_cs_threads;
}
 
+   if (device->info.gen >= 9) {
+  device->mocs_version = anv_gem_get_param(fd,
+   I915_PARAM_MOCS_TABLE_VERSION);
+  switch (device->mocs_version) {
+  default:
+ anv_perf_warn("Kernel exposes newer MOCS table\n");
+  case 1:
+  case 0:
+ device->mocs_version = MOCS_TABLE_VERSION;
+  }
+   }
+
brw_process_intel_debug_variable();
 
device->compiler = brw_compiler_create(NULL, &device->info);
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index 573778dad5..b8241a9b22 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -684,6 +684,8 @@ struct anv_physical_device {
 uint32_teu_total;
 uint32_tsubslice_total;
 
+uint8_t mocs_version;
+
 struct {
   uint32_t  type_count;
   struct anv_memory_typetypes[VK_MAX_MEMORY_TYPES];
diff --git a/src/mesa/drivers/dri/i915/intel_context.c 
b/src/mesa/drivers/dri/i915/intel_context.c
index e0766a0e3f..9169ea650e 100644
--- a/src/mesa/drivers/dri/i915/intel_context.c
+++ b/src/mesa/drivers/dri/i915/intel_context.c
@@ -521,8 +521,13 @@ intelInitContext(struct intel_context *intel,
INTEL_DEBUG = parse_debug_string(getenv("INTEL_DEBUG"), debug_control);
if (INTEL_DEBUG & DEBUG_BUFMGR)
   dri_bufmgr_set_debug(intel->bufmgr, true);
-   if (INTEL_DEBUG & DEBUG_PERF)
+   if (INTEL_DEBUG & DEBUG_PERF) {
   intel->perf_debug = true;
+  if (screen->mocs_version > MOCS_TABLE_VERSION) {
+ fprintf(stderr, "Kernel exposes newer MOCS table\n");
+ screen->mocs_version = MOCS_TABLE_VERSION;
+  }
+   }
 
if (INTEL_DEBUG & DEBUG_AUB)
   drm_intel_bufmgr_gem_set_aub_dump(intel->bufmgr, true);
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index c75f2125d4..c53f133d49 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -2301,6 +2301,20 @@ __DRIconfig **intelInitScreen2(__DRIscreen *dri_screen)
  (ret != -1 || errno != EINVAL);
}
 
+   if (devinfo->gen >= 9) {
+  screen->mocs_version = intel_get_integer(screen,
+   I915_PARAM_MOCS_TABLE_VERSION);
+  switch (screen->mocs_version) {
+  case 1:
+  case 0:
+ screen->mocs_version = MOCS_TABLE_VERSION;
+ break;
+  default:
+ /* We want to perf debug, but we can't yet */
+ break;
+  }
+   }
+
dri_screen->extensions = !screen->has_context_reset_notification
   ? screenExtensions : intelRobustScreenExtensions;
 
diff --git a/src/mesa/drivers/dri/i965/intel_screen.h 
b/src/mesa/drivers/dri/i965/intel_screen.h
index f78b3e8f74..eb801f8155 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.h
+++ b/src/mesa/drivers/dri/i965/intel_screen.h
@@ -112,6 +112,8 @@ struct intel_screen
bool mesa_format_supports_texture[MESA_FORMAT_COUNT];
bool mesa_format_supports_render[MESA_FORMAT_COUNT];
enum isl_format mesa_to_isl_render_format[MESA_FORMAT_COUNT];
+
+   unsigned mocs_version;
 };
 
 extern void intelDestroyContext(__DRIcontext * driContextPriv);
-- 
2.13.2

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


[Mesa-dev] [PATCH 1/1] drm/i915: Version the MOCS settings

2017-07-06 Thread Ben Widawsky
From: Ben Widawsky 

Starting with GEN9, Memory Object Control State (MOCS) becomes an index
into a table as opposed to the direct programming within the command.
The table has 62 usable entries (ie 6 bits can represent all settings),
and each buffer type may use one of these 62 entries to describe
cacheability type, and age (and some other less useful fields).

Because we hadn't dealt with MOCS settings like this, we didn't think
ahead too well and have ended up with a mess for GEN9 (and soon GEN10)
platform. The plan for for future platforms is that the ideal MOCS
settings will be determined, defined, and written in the public PRMs.
After this point, the i915.ko will absorb these settings and sometime
afterwards flip the alpha switch. All driver releases without the final
MOCS table must be considered alpha. Here on, userspace can assume the
MOCS table is definitively done. There will be some reserved entries for
'oh shit' scenarios. This avoids versioning the MOCS table which leaves
somewhat of a mess in userspace trying to handle arbitrarily many MOCS
versions.

But we do have a mess on GEN9. In the beginning, the MOCS table entries
were pre-populated by the hardware based on estimations made prior to
tapeout and we could just use that. Subsequently much performance tuning
was done to determine optimal settings that the i915 driver should load
on top of the hardware defaults. That was posted last as v6 of the
original per-engine MOCS settings:
https://patchwork.freedesktop.org/patch/53237/. Since the MOCS table is
not context saved/restored, it isn't feasible to let userspace upload
its own MOCS table. After a good amount of debate, it was decided that
we'd utilize only the minimal set of entires in mesa anyway, and so we
took only those entries for our MOCS entries.

Now we've come to the realization that indeed there are other MOCS
entries which are more optimal for various buffer types and workloads.
The problem is that the meaning of the indices is ABI (we assume index 0
is the uncached entry, and that there are only 3 entries total).

What this patch [simply] aims to do is expose a parameter to inform
userspace which "version" of the table was loaded by i915. Upon
sufficient data, new entries can be added, and the version can be
bumped. For example, from my original mesa mocs branch:

commit c9b0481bce24af032386701de0266eb5bc24e988
Author: Ben Widawsky 
Date:   Fri Apr 8 10:21:16 2016 -0700

    i965: Use PTE mocs

Signed-off-by: Ben Widawsky 

diff --git a/src/mesa/drivers/dri/i965/brw_mocs.c 
b/src/mesa/drivers/dri/i965/brw_mocs.c
index 5df154eb86..b7bfdab671 100644
--- a/src/mesa/drivers/dri/i965/brw_mocs.c
+++ b/src/mesa/drivers/dri/i965/brw_mocs.c
@@ -14,6 +14,9 @@
 /* Skylake: MOCS is now an index into an array of 62 different caching
  * configurations programmed by the kernel.
  */
+
+/* TC=PTE, LeCC=PTE, LRUM=3, L3CC=WB */
+#define SKL_MOCS_PTE_PTE (3 << 1)
 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */
 #define SKL_MOCS_WB  (2 << 1)
 /* TC=LLC/eLLC, LeCC=PTE, LRUM=3, L3CC=WB */
@@ -26,6 +29,9 @@ brw_mocs_get_control_state(const struct brw_context *brw,
switch (brw->gen) {
default:
case 9:
+  if (brw->intelScreen->mocs_version > 1)
+ return SKL_MOCS_PTE_PTE;
+
   return type == INTEL_MOCS_PTE ? SKL_MOCS_PTE : SKL_MOCS_WB;
case 8:
   return type == INTEL_MOCS_PTE ? BDW_MOCS_PTE : BDW_MOCS_WB;

tl;dr: A versioned MOCS table will allow userspace to be aware of new
and potentially interesting cacheability settings. Next GEN platforms
will not be considered production worthy until the MOCS table is
finalized.

v2: Update 1.5 year old patch. Add comments. Update commit message.

Signed-off-by: Ben Widawsky 
---
 drivers/gpu/drm/i915/i915_drv.c |  3 +++
 drivers/gpu/drm/i915/i915_drv.h |  2 ++
 drivers/gpu/drm/i915/i915_pci.c | 13 +
 include/uapi/drm/i915_drm.h |  8 
 4 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 9167a73f3c69..26c27b6ae814 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -401,6 +401,9 @@ static int i915_getparam(struct drm_device *dev, void *data,
if (!value)
return -ENODEV;
break;
+   case I915_PARAM_MOCS_TABLE_VERSION:
+   value = INTEL_INFO(dev_priv)->mocs_version;
+   break;
default:
DRM_DEBUG("Unknown parameter %d\n", param->param);
return -EINVAL;
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index effbe4f72a64..9b30f6e6ef9b 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -859,6 +859,8 @@ struct intel_device_info {
u16 degamma_lut_size;
u16 gamma_lut_size;
} color;
+
+

Re: [Mesa-dev] [PATCH] i965: Naive implementation of gbm_bo_map

2017-06-12 Thread Ben Widawsky

Lost track of this. People interested?

On 17-04-24 12:09:49, Emil Velikov wrote:

On 24 April 2017 at 11:56, Tapani Pälli  wrote:



On 04/24/2017 01:52 PM, Emil Velikov wrote:


Hi Ben,

Just realised that the CrOS team might be interested in this as well -
adding Tomasz.

On 21 April 2017 at 18:17, Ben Widawsky  wrote:


Could do smarter stuff with the mappings. I decided not to.

Tested with kmscube. No current clients seem to use non-zero x0, y0, so
that's untested.

Cc: Tapani Pälli  (AndroidIA?)


Tomasz, Tapani,

With this in place you should be able to drop the [patched] 3.3Kloc
drm_gralloc in favour of the 0.6Kloc gbm_gralloc [1].
Latter is what the cool kids are using ;-)



Android-IA has switched to use minigbm as allocator at one point. BTW which
project uses gbm_gralloc?


Android-x86, which is used as a base by RobH, Robert Foss and a
handful of others devs, I believe.

-Emil

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


Re: [Mesa-dev] [PATCH v3 02/15] dri: Add an image creation with modifiers

2017-05-11 Thread Ben Widawsky

On 17-05-10 23:15:29, Varad Gautam wrote:

From: Ben Widawsky 

Modifiers will be obtained or guessed by the client and passed in during
image creation/import.

As of this patch, the modifiers aren't plumbed all the way down, this
patch simply makes sure the interface level stuff is correct and keeps
interface versioning consistent.

v2: Don't allow usage + modifiers
v3: Make NAND actually NAND. Bug introduced in v2. (Jason)
v4: Bump DRIimage version. (Varad)

Cc: Kristian Høgsberg 
Cc: Jason Ekstrand 
Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom  (v1)
Acked-by: Daniel Stone 
Signed-off-by: Varad Gautam 
---
src/gallium/state_trackers/dri/dri2.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index 0c5783c..d561fe8 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -1417,7 +1417,7 @@ dri2_get_capabilities(__DRIscreen *_screen)

/* The extension is modified during runtime if DRI_PRIME is detected */
static __DRIimageExtension dri2ImageExtension = {
-.base = { __DRI_IMAGE, 12 },
+.base = { __DRI_IMAGE, 14 },

.createImageFromName  = dri2_create_image_from_name,
.createImageFromRenderbuffer  = dri2_create_image_from_renderbuffer,
@@ -1435,6 +1435,7 @@ static __DRIimageExtension dri2ImageExtension = {
.getCapabilities  = dri2_get_capabilities,
.mapImage = dri2_map_image,
.unmapImage   = dri2_unmap_image,
+.createImageWithModifiers = NULL,
};





I think we can discard this patch, it seems to be some leftover garbage. If
someone wants to plumb a gallium driver to do this, they are welcome, but I am
not doing it.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 11/12] i965/cnl: Properly handle l3 configuration

2017-05-11 Thread Ben Widawsky

On 17-05-02 11:51:28, Francisco Jerez wrote:

Anuj Phogat  writes:


On Mon, Apr 24, 2017 at 9:15 PM, Ben Widawsky  wrote:


On 17-04-18 18:18:39, Francisco Jerez wrote:

Most, if not all of the unrelated changes that snuck in were due to rebase.
Anuj, would you mind fixing those? I tried my best to address the rest,
but I'm
admittedly stumbling my way through some of the l3 programming.

Anuj Phogat  writes:


From: Ben Widawsky 


V2: Squash the changes in one patch and rebased on master (Anuj).

Signed-off-by: Ben Widawsky 
Signed-off-by: Anuj Phogat 
---
 src/intel/common/gen_l3_config.c | 43 ++
--
 1 file changed, 37 insertions(+), 6 deletions(-)

diff --git a/src/intel/common/gen_l3_config.c
b/src/intel/common/gen_l3_config.c
index 4fe3503..f3e8793 100644
--- a/src/intel/common/gen_l3_config.c
+++ b/src/intel/common/gen_l3_config.c
@@ -102,6 +102,26 @@ static const struct gen_l3_config chv_l3_configs[]
= {
 };

 /**
+ * On CNL, RO clients are merged and shared with read/write space. As a
result
+ * we have fewer allocation parameters.



The two sentences above make it sound like RO clients haven't been part
of the same partition until CNL.  They have.  I'd drop this.



So the difference I was trying to spell out is that the previous "IS" "C"
and
"T" fields do not exist in a programmable way.

Also, programming does not require any

+ * back scaling. Programming simply works in 2k increments and is
scaled by the
+ * hardware.



That's basically the case (up to the specific scale factor) on all
hardware, I'd drop this too.



I personally think the existing code isn't as self-documenting to me as it
is to
you, and so I was trying to spell it out. I was trying to document, not
show
differentiation. In either event, I don't care if we keep this or leave it.

+ */

+static const struct gen_l3_config cnl_l3_configs[] = {
+   /* SLM URB Rest  DC  RO */



s/Rest/ALL/ (these are L3 partition enum labels), and align to the
column boundaries below.



Sure.


+   {{  0, 64, 64,  0,  0 }},

+   {{  0, 64,  0, 16, 48 }},
+   {{  0, 48,  0, 16, 64 }},
+   {{  0, 32,  0,  0, 96 }},
+   {{  0, 32, 96,  0,  0 }},
+   {{  0, 32,  0, 16, 80 }},
+   {{ 32, 16, 80,  0,  0 }},
+   {{ 32, 16,  0, 64, 16 }},
+   {{ 32,  0, 96,  0,  0 }},
+   {{ 0 }}
+};
+
+/**
  * Return a zero-terminated array of validated L3 configurations for the
  * specified device.
  */
@@ -116,9 +136,11 @@ get_l3_configs(const struct gen_device_info
*devinfo)
   return (devinfo->is_cherryview ? chv_l3_configs : bdw_l3_configs);

case 9:
-   case 10:
   return chv_l3_configs;

+   case 10:
+  return cnl_l3_configs;
+
default:
   unreachable("Not implemented");
}
@@ -258,13 +280,19 @@ get_l3_way_size(const struct gen_device_info
*devinfo)
if (devinfo->is_baytrail)
   return 2;

-   else if (devinfo->gt == 1 ||
-devinfo->is_cherryview ||
-devinfo->is_broxton)



Unrelated change sneaked in.



See above reply (not sure how this got in other than rebase).

+   /* Way size is actually 6 * num_slices, because it's 2k per bank, and

+* normally 3 banks per slice. However, on CNL+ this information
isn't
+* needed to setup the URB/l3 configuration. We fudge the answer here
+* and then use the scaling to fix it up later.
+*/



The comment makes it sound like you're lying to the caller and returning
a bogus way size you're going to fix up later.  That's not the case
though, the value you're returning below is accurate for all CNL
configs.  6 * num_slices OTOH *would* be inaccurate.  I'd drop the
comment.



Anuj, would you mind doing what Curro asks?

+   if (devinfo->gen >= 10)

+  return 2 * devinfo->l3_banks;
+



It would be nice if we could use the 'l3_banks' devinfo field you just
added on previous gens too in order to simplify things.  I'm okay if you
don't feel like doing the clean up right away but maybe add a short
FINISHME comment next to its definition in gen_device_info.h so we don't
forget about this (hopefully temporary) inconsistency.

+   /* XXX: Cherryview and Broxton are always gt1 */

+   if (devinfo->gt == 1)



Unrelated change.

   return 4;


-   else
-  return 8 * devinfo->num_slices;
+   return 8 * devinfo->num_slices;



Unrelated change.



I think here too it must have been a rebase change.

 }


 /**
@@ -274,6 +302,9 @@ get_l3_way_size(const struct gen_device_info
*devinfo)
 static unsigned
 get_urb_size_scale(const struct gen_device_info *devinfo)
 {
+   if (devinfo->gen == 10)
+  return devinfo->l3_banks;
+



This seems bogus, AFAICT URB programming is done in size per slice units
(just like it was the case on previous gens), not in size per L3 bank
units.



We have parts which have different l3 banks per slice, and those se

Re: [Mesa-dev] [PATCH kmscube 1/2] common: use %llx to print modifier

2017-04-28 Thread Ben Widawsky

Fix kmscube -A on i915 :P

On 17-04-28 14:17:34, Rob Clark wrote:

I guess this applies on top of one of Ben's in-flight patches?
Perhaps it can be squashed into that?  (Otherwise remind me about this
when the modifiers patchset is merged)

BR,
-R

On Fri, Apr 28, 2017 at 12:18 PM, Lucas Stach  wrote:

Use long long format when printing the format modifier, as a simple
long is only 4 bytes on 32bit systems.

Signed-off-by: Lucas Stach 
---
 drm-common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drm-common.c b/drm-common.c
index 2f2c918596a4..fb4ec7f4389e 100644
--- a/drm-common.c
+++ b/drm-common.c
@@ -73,7 +73,7 @@ struct drm_fb * drm_fb_get_from_bo(struct gbm_bo *bo)

if (modifiers[0]) {
flags = DRM_MODE_FB_MODIFIERS;
-   printf("Using modifier %lx\n", modifiers[0]);
+   printf("Using modifier %llx\n", modifiers[0]);
}

ret = drmModeAddFB2WithModifiers(drm_fd, width, height,
--
2.11.0

___
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 07/12] i965/cnl: Restore lossless compression for sRGB formats

2017-04-25 Thread Ben Widawsky

On 17-04-25 14:53:46, Anuj Phogat wrote:

On Mon, Apr 24, 2017 at 10:57 PM, Ben Widawsky  wrote:


On 17-04-15 18:27:33, Jason Ekstrand wrote:


On April 14, 2017 5:37:55 PM Anuj Phogat  wrote:

From: Ben Widawsky 


This support was removed on gen9 (it worked before then) and was brought
back
for gen10.

Signed-off-by: Ben Widawsky 
---
src/mesa/drivers/dri/i965/intel_mipmap_tree.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
index 467ada5..c8014b9 100644
--- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
@@ -207,7 +207,7 @@ intel_miptree_supports_non_msrt_fast_clear(struct
brw_context *brw,
   if (!brw->format_supported_as_render_target[mt->format])
  return false;

-   if (brw->gen >= 9) {
+   if (brw->gen == 9) {
  mesa_format linear_format = _mesa_get_srgb_format_linear(m
t->format);
  const uint32_t brw_format = brw_isl_format_for_mesa_format
(linear_format);
  return isl_format_supports_ccs_e(&brw->screen->devinfo,
brw_format);



I thought sRGB was supported for CCS_E on CNL.  If so, we should update
the table in isl_format_supports_ccs_e().  Also, I believe sRGB is
supported for CCS_D even on sky lake, you just can't sample from it.



The patch predates ISL... yes, we should. Anuj, would you mind doing this?


​I'll update the table in v2. As sRGB now supports lossless compression,
don't we
also need to stop resolving single sampled color render buffers for sRGB
formats
in Gen 10? See i965/brw_context.c:329
[snip]
  /* If FRAMEBUFFER_SRGB is used on Gen9+ then we need to resolve any of
the
   * single-sampled color renderbuffers because the CCS buffer isn't
   * supported for SRGB formats. This only matters if FRAMEBUFFER_SRGB is
   * enabled because otherwise the surface state will be programmed with
the
   * linear equivalent format anyway.
   */
  if (brw->gen >= 9 && ctx->Color.sRGBEnabled) {
 struct gl_framebuffer *fb = ctx->DrawBuffer;
 for (int i = 0; i < fb->_NumColorDrawBuffers; i++) {


​


Yes, it looks like it. Not sure how I missed that before.






--

2.9.3

___
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 07/12] i965/cnl: Restore lossless compression for sRGB formats

2017-04-24 Thread Ben Widawsky

On 17-04-15 18:27:33, Jason Ekstrand wrote:

On April 14, 2017 5:37:55 PM Anuj Phogat  wrote:


From: Ben Widawsky 

This support was removed on gen9 (it worked before then) and was brought back
for gen10.

Signed-off-by: Ben Widawsky 
---
src/mesa/drivers/dri/i965/intel_mipmap_tree.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c 
b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c

index 467ada5..c8014b9 100644
--- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
@@ -207,7 +207,7 @@ 
intel_miptree_supports_non_msrt_fast_clear(struct brw_context *brw,

   if (!brw->format_supported_as_render_target[mt->format])
  return false;

-   if (brw->gen >= 9) {
+   if (brw->gen == 9) {
  mesa_format linear_format = _mesa_get_srgb_format_linear(mt->format);
  const uint32_t brw_format = brw_isl_format_for_mesa_format(linear_format);
  return isl_format_supports_ccs_e(&brw->screen->devinfo, brw_format);


I thought sRGB was supported for CCS_E on CNL.  If so, we should 
update the table in isl_format_supports_ccs_e().  Also, I believe sRGB 
is supported for CCS_D even on sky lake, you just can't sample from 
it.




The patch predates ISL... yes, we should. Anuj, would you mind doing this?


--
2.9.3

___
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 11/12] i965/cnl: Properly handle l3 configuration

2017-04-24 Thread Ben Widawsky

On 17-04-18 18:18:39, Francisco Jerez wrote:

Most, if not all of the unrelated changes that snuck in were due to rebase.
Anuj, would you mind fixing those? I tried my best to address the rest, but I'm
admittedly stumbling my way through some of the l3 programming.


Anuj Phogat  writes:


From: Ben Widawsky 

V2: Squash the changes in one patch and rebased on master (Anuj).

Signed-off-by: Ben Widawsky 
Signed-off-by: Anuj Phogat 
---
 src/intel/common/gen_l3_config.c | 43 ++--
 1 file changed, 37 insertions(+), 6 deletions(-)

diff --git a/src/intel/common/gen_l3_config.c b/src/intel/common/gen_l3_config.c
index 4fe3503..f3e8793 100644
--- a/src/intel/common/gen_l3_config.c
+++ b/src/intel/common/gen_l3_config.c
@@ -102,6 +102,26 @@ static const struct gen_l3_config chv_l3_configs[] = {
 };

 /**
+ * On CNL, RO clients are merged and shared with read/write space. As a result
+ * we have fewer allocation parameters.


The two sentences above make it sound like RO clients haven't been part
of the same partition until CNL.  They have.  I'd drop this.



So the difference I was trying to spell out is that the previous "IS" "C" and
"T" fields do not exist in a programmable way.


Also, programming does not require any
+ * back scaling. Programming simply works in 2k increments and is scaled by the
+ * hardware.


That's basically the case (up to the specific scale factor) on all
hardware, I'd drop this too.



I personally think the existing code isn't as self-documenting to me as it is to
you, and so I was trying to spell it out. I was trying to document, not show
differentiation. In either event, I don't care if we keep this or leave it.


+ */
+static const struct gen_l3_config cnl_l3_configs[] = {
+   /* SLM URB Rest  DC  RO */


s/Rest/ALL/ (these are L3 partition enum labels), and align to the
column boundaries below.



Sure.


+   {{  0, 64, 64,  0,  0 }},
+   {{  0, 64,  0, 16, 48 }},
+   {{  0, 48,  0, 16, 64 }},
+   {{  0, 32,  0,  0, 96 }},
+   {{  0, 32, 96,  0,  0 }},
+   {{  0, 32,  0, 16, 80 }},
+   {{ 32, 16, 80,  0,  0 }},
+   {{ 32, 16,  0, 64, 16 }},
+   {{ 32,  0, 96,  0,  0 }},
+   {{ 0 }}
+};
+
+/**
  * Return a zero-terminated array of validated L3 configurations for the
  * specified device.
  */
@@ -116,9 +136,11 @@ get_l3_configs(const struct gen_device_info *devinfo)
   return (devinfo->is_cherryview ? chv_l3_configs : bdw_l3_configs);

case 9:
-   case 10:
   return chv_l3_configs;

+   case 10:
+  return cnl_l3_configs;
+
default:
   unreachable("Not implemented");
}
@@ -258,13 +280,19 @@ get_l3_way_size(const struct gen_device_info *devinfo)
if (devinfo->is_baytrail)
   return 2;

-   else if (devinfo->gt == 1 ||
-devinfo->is_cherryview ||
-devinfo->is_broxton)


Unrelated change sneaked in.



See above reply (not sure how this got in other than rebase).


+   /* Way size is actually 6 * num_slices, because it's 2k per bank, and
+* normally 3 banks per slice. However, on CNL+ this information isn't
+* needed to setup the URB/l3 configuration. We fudge the answer here
+* and then use the scaling to fix it up later.
+*/


The comment makes it sound like you're lying to the caller and returning
a bogus way size you're going to fix up later.  That's not the case
though, the value you're returning below is accurate for all CNL
configs.  6 * num_slices OTOH *would* be inaccurate.  I'd drop the
comment.



Anuj, would you mind doing what Curro asks?


+   if (devinfo->gen >= 10)
+  return 2 * devinfo->l3_banks;
+


It would be nice if we could use the 'l3_banks' devinfo field you just
added on previous gens too in order to simplify things.  I'm okay if you
don't feel like doing the clean up right away but maybe add a short
FINISHME comment next to its definition in gen_device_info.h so we don't
forget about this (hopefully temporary) inconsistency.


+   /* XXX: Cherryview and Broxton are always gt1 */
+   if (devinfo->gt == 1)


Unrelated change.


   return 4;

-   else
-  return 8 * devinfo->num_slices;
+   return 8 * devinfo->num_slices;


Unrelated change.



I think here too it must have been a rebase change.


 }

 /**
@@ -274,6 +302,9 @@ get_l3_way_size(const struct gen_device_info *devinfo)
 static unsigned
 get_urb_size_scale(const struct gen_device_info *devinfo)
 {
+   if (devinfo->gen == 10)
+  return devinfo->l3_banks;
+


This seems bogus, AFAICT URB programming is done in size per slice units
(just like it was the case on previous gens), not in size per L3 bank
units.



We have parts which have different l3 banks per slice, and those seemed to need
to be programmed differently which is how I got to this. Tell us what you'd
recommend instead, and Anuj can try t

Re: [Mesa-dev] [PATCH] autogen.sh: set default sendemail.to

2017-04-24 Thread Ben Widawsky

On 17-04-24 21:29:32, Jason Ekstrand wrote:
This seems like something that would be more appropriate to put on a 
"getting started" page than autogen.sh.  The very last thing I (as a 
user of it) would expect autogen.sh to do is monkey with my git 
config; local or otherwise.




"Otherwise" is certainly not okay, but I like this. Feel free to nak of course.

Acked-by: Ben Widawsky 



On April 24, 2017 6:16:14 PM Emil Velikov  wrote:


From: Emil Velikov 

To ease patch submission process a tiny bit.

Cc: Ben Widawsky 
Suggested-by: Ben Widawsky 
Signed-off-by: Emil Velikov 
---
autogen.sh | 3 +++
1 file changed, 3 insertions(+)

diff --git a/autogen.sh b/autogen.sh
index c8960971d24..d178880b407 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -6,6 +6,9 @@ test -z "$srcdir" && srcdir=.
ORIGDIR=`pwd`
cd "$srcdir"

+git config --local --get sendemail.to >/dev/null ||
+git config --local sendemail.to 
"mesa-dev@lists.freedesktop.org" 2>/dev/null

+
autoreconf --force --verbose --install || exit 1
cd "$ORIGDIR" || exit $?

--
2.12.2

___
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] i965: Naive implementation of gbm_bo_map

2017-04-21 Thread Ben Widawsky
Could do smarter stuff with the mappings. I decided not to.

Tested with kmscube. No current clients seem to use non-zero x0, y0, so
that's untested.

Cc: Tapani Pälli  (AndroidIA?)
Cc: Emil Velikov 
Signed-off-by: Ben Widawsky 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 39 ++--
 1 file changed, 37 insertions(+), 2 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 34a5f18af2..f89de3c9d4 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -926,6 +926,41 @@ intel_from_planar(__DRIimage *parent, int plane, void 
*loaderPrivate)
 return image;
 }
 
+static void *
+intel_map_image(__DRIcontext *context, __DRIimage *image,
+ int x0, int y0, int width, int height,
+ unsigned int flags, int *stride, void **data)
+{
+   if (!image || !data || *data)
+  return NULL;
+
+   /* FIXME: add width/height check */
+
+   brw_bo_reference(image->bo);
+
+   uintptr_t offset =
+  y0 * image->pitch + x0 * _mesa_get_format_bytes(image->format);
+   void *bo_map = brw_bo_map__wc(image->bo);
+
+   if (bo_map) {
+  *data = image->bo;
+  *stride = image->pitch;
+   } else {
+  *data = NULL;
+  *stride = 0;
+  brw_bo_unreference(image->bo);
+   }
+
+   return bo_map + offset;
+}
+
+
+static void
+intel_unmap_image(__DRIcontext *context, __DRIimage *image, void *data)
+{
+   brw_bo_unreference(data);
+}
+
 static const __DRIimageExtension intelImageExtension = {
 .base = { __DRI_IMAGE, 14 },
 
@@ -943,8 +978,8 @@ static const __DRIimageExtension intelImageExtension = {
 .createImageFromDmaBufs = intel_create_image_from_dma_bufs,
 .blitImage  = NULL,
 .getCapabilities= NULL,
-.mapImage   = NULL,
-.unmapImage = NULL,
+.mapImage   = intel_map_image,
+.unmapImage = intel_unmap_image,
 .createImageWithModifiers   = intel_create_image_with_modifiers,
 };
 
-- 
2.12.2

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


[Mesa-dev] [PATCH kmscube 2/6] configure: Check for the GBM modifiers

2017-04-13 Thread Ben Widawsky
---
 configure.ac | 16 
 1 file changed, 16 insertions(+)

diff --git a/configure.ac b/configure.ac
index aa0ef36..33167e4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -49,5 +49,21 @@ if test "x$HAVE_GST" = "xyes"; then
 fi
 AM_CONDITIONAL(ENABLE_GST, [test "x$HAVE_GST" = "xyes"])
 
+AC_CHECK_LIB([gbm], [gbm_bo_get_modifier], [gbm_modifiers=yes], [])
+
+AC_ARG_ENABLE([gbm-modifiers],
+ [AS_HELP_STRING([--enable-gbm-modifiers],
+ [enable using GBM modifiers @<:@default=auto@:>@])],
+ [enable_gbm_modifiers="$enableval"],
+ [enable_gbm_modifiers=auto])
+
+if test "x$enable_gbm_modifiers" = xyes -a "x$gbm_modifiers" != xyes; then
+   AC_MSG_ERROR([Cannot find gbm modifier supported mesa])
+fi
+
+if test "x$gbm_modifiers" = xyes; then
+   AC_DEFINE(HAVE_GBM_MODIFIERS, 1, [Define if you can use GBM 
properties.])
+fi
+
 AC_CONFIG_FILES([Makefile])
 AC_OUTPUT
-- 
2.12.2

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


[Mesa-dev] [PATCH kmscube 5/6] common: Use libdrm AddFB with modifiers

2017-04-13 Thread Ben Widawsky
Note: nothing happens here yet since LINEAR == 0.
---
 configure.ac |  2 +-
 drm-common.c | 37 +
 2 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/configure.ac b/configure.ac
index 33167e4..f564ef3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -35,7 +35,7 @@ AC_PROG_CC
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 
 # Obtain compiler/linker options for depedencies
-PKG_CHECK_MODULES(DRM, libdrm)
+PKG_CHECK_MODULES(DRM, [libdrm >= 2.4.71])
 PKG_CHECK_MODULES(GBM, gbm >= 13.0)
 PKG_CHECK_MODULES(EGL, egl)
 PKG_CHECK_MODULES(GLES2, glesv2)
diff --git a/drm-common.c b/drm-common.c
index b69ed70..eb460df 100644
--- a/drm-common.c
+++ b/drm-common.c
@@ -46,7 +46,7 @@ struct drm_fb * drm_fb_get_from_bo(struct gbm_bo *bo)
 {
int drm_fd = gbm_device_get_fd(gbm_bo_get_device(bo));
struct drm_fb *fb = gbm_bo_get_user_data(bo);
-   uint32_t width, height, stride, handle;
+   uint32_t width, height, strides[4]={0}, handles[4] = {0}, offsets[4] = 
{0}, flags = 0;
int ret;
 
if (fb)
@@ -57,10 +57,39 @@ struct drm_fb * drm_fb_get_from_bo(struct gbm_bo *bo)
 
width = gbm_bo_get_width(bo);
height = gbm_bo_get_height(bo);
-   stride = gbm_bo_get_stride(bo);
-   handle = gbm_bo_get_handle(bo).u32;
 
-   ret = drmModeAddFB(drm_fd, width, height, 24, 32, stride, handle, 
&fb->fb_id);
+#ifndef HAVE_GBM_MODIFIERS
+   strides[0] = gbm_bo_get_stride(bo);
+   handles[0] = gbm_bo_get_handle(bo).u32;
+   ret = -1;
+#else
+   uint64_t modifiers[4] = {0};
+   modifiers[0] = gbm_bo_get_modifier(bo);
+   const int num_planes = gbm_bo_get_plane_count(bo);
+   for (int i = 0; i < num_planes; i++) {
+   strides[i] = gbm_bo_get_stride_for_plane(bo, i);
+   handles[i] = gbm_bo_get_handle(bo).u32;
+   offsets[i] = gbm_bo_get_offset(bo, i);
+   modifiers[i] = modifiers[0];
+   }
+
+   if (modifiers[0]) {
+   flags = DRM_MODE_FB_MODIFIERS;
+   printf("Using modifier %lx\n", modifiers[0]);
+   }
+
+   ret = drmModeAddFB2WithModifiers(drm_fd, width, height,
+   DRM_FORMAT_XRGB, handles, strides, offsets,
+   modifiers, &fb->fb_id, flags);
+#endif
+   if (ret) {
+   if (flags)
+   fprintf(stderr, "Modifiers failed!\n");
+   flags = 0;
+   ret = drmModeAddFB2(drm_fd, width, height, DRM_FORMAT_XRGB,
+   handles, strides, offsets, &fb->fb_id, 0);
+   }
+
if (ret) {
printf("failed to create fb: %s\n", strerror(errno));
free(fb);
-- 
2.12.2

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


[Mesa-dev] [PATCH kmscube 4/6] common: Use the create with modifiers interface

2017-04-13 Thread Ben Widawsky
---
 common.c | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/common.c b/common.c
index 4bf3c5a..e63bb39 100644
--- a/common.c
+++ b/common.c
@@ -31,10 +31,23 @@
 
 static struct gbm gbm;
 
+#ifndef DRM_FORMAT_MOD_LINEAR
+#define DRM_FORMAT_MOD_LINEAR 0
+#endif
+static int
+get_modifiers(uint64_t **mods)
+{
+   /* Assumed LINEAR is supported everywhere */
+   static uint64_t modifiers[] = {DRM_FORMAT_MOD_LINEAR};
+   *mods = modifiers;
+   return 1;
+}
+
 const struct gbm * init_gbm(int drm_fd, int w, int h)
 {
gbm.dev = gbm_create_device(drm_fd);
 
+#ifndef HAVE_GBM_MODIFIERS
gbm.surface = gbm_surface_create(gbm.dev, w, h,
GBM_FORMAT_XRGB,
GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
@@ -42,6 +55,12 @@ const struct gbm * init_gbm(int drm_fd, int w, int h)
printf("failed to create gbm surface\n");
return NULL;
}
+#else
+   uint64_t *mods;
+   int count = get_modifiers(&mods);
+   gbm.surface = gbm_surface_create_with_modifiers(gbm.dev, w, h,
+   GBM_FORMAT_XRGB, mods, count);
+#endif
 
gbm.width = w;
gbm.height = h;
-- 
2.12.2

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


[Mesa-dev] [PATCH kmscube 6/6] common: Give cmdline parameter for forcing modifiers

2017-04-13 Thread Ben Widawsky
---
 common.c  | 13 -
 common.h  | 11 ++-
 kmscube.c | 14 +++---
 3 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/common.c b/common.c
index e63bb39..eaaa9a4 100644
--- a/common.c
+++ b/common.c
@@ -31,9 +31,6 @@
 
 static struct gbm gbm;
 
-#ifndef DRM_FORMAT_MOD_LINEAR
-#define DRM_FORMAT_MOD_LINEAR 0
-#endif
 static int
 get_modifiers(uint64_t **mods)
 {
@@ -43,7 +40,7 @@ get_modifiers(uint64_t **mods)
return 1;
 }
 
-const struct gbm * init_gbm(int drm_fd, int w, int h)
+const struct gbm * init_gbm(int drm_fd, int w, int h, uint64_t modifier)
 {
gbm.dev = gbm_create_device(drm_fd);
 
@@ -57,7 +54,13 @@ const struct gbm * init_gbm(int drm_fd, int w, int h)
}
 #else
uint64_t *mods;
-   int count = get_modifiers(&mods);
+   int count;
+   if (modifier != DRM_FORMAT_MOD_INVALID) {
+   count = 1;
+   mods = &modifier;
+   } else {
+   count = get_modifiers(&mods);
+   }
gbm.surface = gbm_surface_create_with_modifiers(gbm.dev, w, h,
GBM_FORMAT_XRGB, mods, count);
 #endif
diff --git a/common.h b/common.h
index f3d9d32..03634cc 100644
--- a/common.h
+++ b/common.h
@@ -36,6 +36,14 @@
   #include "config.h"
 #endif
 
+#ifndef DRM_FORMAT_MOD_LINEAR
+#define DRM_FORMAT_MOD_LINEAR 0
+#endif
+
+#ifndef DRM_FORMAT_MOD_INVALID
+#define DRM_FORMAT_MOD_INVALID __u64)0) << 56) | ((1ULL << 56) - 1))
+#endif
+
 #ifndef EGL_KHR_platform_gbm
 #define EGL_KHR_platform_gbm 1
 #define EGL_PLATFORM_GBM_KHR  0x31D7
@@ -57,9 +65,10 @@ struct gbm {
struct gbm_device *dev;
struct gbm_surface *surface;
int width, height;
+   uint64_t forced_modifier;
 };
 
-const struct gbm * init_gbm(int drm_fd, int w, int h);
+const struct gbm * init_gbm(int drm_fd, int w, int h, uint64_t modifier);
 
 
 struct egl {
diff --git a/kmscube.c b/kmscube.c
index 63a133b..6dcfd2f 100644
--- a/kmscube.c
+++ b/kmscube.c
@@ -26,6 +26,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 #include "common.h"
@@ -41,19 +42,20 @@ static const struct egl *egl;
 static const struct gbm *gbm;
 static const struct drm *drm;
 
-static const char *shortopts = "AD:M:V:";
+static const char *shortopts = "AD:M:m:V:";
 
 static const struct option longopts[] = {
{"atomic", no_argument,   0, 'A'},
{"device", required_argument, 0, 'D'},
{"mode",   required_argument, 0, 'M'},
+   {"modifier", required_argument, 0, 'm'},
{"video",  required_argument, 0, 'V'},
{0, 0, 0, 0}
 };
 
 static void usage(const char *name)
 {
-   printf("Usage: %s [-ADMV]\n"
+   printf("Usage: %s [-ADMmV]\n"
"\n"
"options:\n"
"-A, --atomic use atomic modesetting 
and fencing\n"
@@ -63,6 +65,7 @@ static void usage(const char *name)
"rgba  -  rgba textured cube\n"
"nv12-2img -  yuv textured (color conversion in 
shader)\n"
"nv12-1img -  yuv textured (single nv12 
texture)\n"
+   "-m, --modifier=MODIFIER  hardcode the selected 
modifier\n"
"-V, --video=FILE video textured cube\n",
name);
 }
@@ -72,6 +75,7 @@ int main(int argc, char *argv[])
const char *device = "/dev/dri/card0";
const char *video = NULL;
enum mode mode = SMOOTH;
+   uint64_t modifier = DRM_FORMAT_MOD_INVALID;
int atomic = 0;
int opt;
 
@@ -102,6 +106,9 @@ int main(int argc, char *argv[])
return -1;
}
break;
+   case 'm':
+   modifier = strtoull(optarg, NULL, 0);
+   break;
case 'V':
mode = VIDEO;
video = optarg;
@@ -121,7 +128,8 @@ int main(int argc, char *argv[])
return -1;
}
 
-   gbm = init_gbm(drm->fd, drm->mode->hdisplay, drm->mode->vdisplay);
+   gbm = init_gbm(drm->fd, drm->mode->hdisplay, drm->mode->vdisplay,
+   modifier);
if (!gbm) {
printf("failed to initialize GBM\n");
return -1;
-- 
2.12.2

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


[Mesa-dev] [PATCH kmscube 3/6] common: include config.h

2017-04-13 Thread Ben Widawsky
---
 common.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/common.h b/common.h
index 2eceac7..f3d9d32 100644
--- a/common.h
+++ b/common.h
@@ -32,6 +32,10 @@
 #include 
 #include 
 
+#ifdef HAVE_CONFIG_H
+  #include "config.h"
+#endif
+
 #ifndef EGL_KHR_platform_gbm
 #define EGL_KHR_platform_gbm 1
 #define EGL_PLATFORM_GBM_KHR  0x31D7
-- 
2.12.2

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


[Mesa-dev] [PATCH kmscube 1/6] drm: Provide a failure path when getting the fb

2017-04-13 Thread Ben Widawsky
This is helpful for debugging as you will bail early with an error
message instead of a random SIGSEGV (or something more obscure).
---
 drm-atomic.c | 9 +
 drm-legacy.c | 8 
 2 files changed, 17 insertions(+)

diff --git a/drm-atomic.c b/drm-atomic.c
index 27c6b1e..c06e52f 100644
--- a/drm-atomic.c
+++ b/drm-atomic.c
@@ -187,6 +187,11 @@ static int atomic_run(const struct gbm *gbm, const struct 
egl *egl)
eglSwapBuffers(egl->display, egl->surface);
bo = gbm_surface_lock_front_buffer(gbm->surface);
fb = drm_fb_get_from_bo(bo);
+   if (!fb) {
+   printf("Failed to get a new framebuffer BO\n");
+   return -1;
+   }
+
 
drm.kms_in_fence_fd = -1;
 
@@ -235,6 +240,10 @@ static int atomic_run(const struct gbm *gbm, const struct 
egl *egl)
 
next_bo = gbm_surface_lock_front_buffer(gbm->surface);
fb = drm_fb_get_from_bo(next_bo);
+   if (!fb) {
+   printf("Failed to get a new framebuffer BO\n");
+   return -1;
+   }
 
/*
 * Here you could also update drm plane layers if you want
diff --git a/drm-legacy.c b/drm-legacy.c
index 3b407f8..a0b419a 100644
--- a/drm-legacy.c
+++ b/drm-legacy.c
@@ -60,6 +60,10 @@ static int legacy_run(const struct gbm *gbm, const struct 
egl *egl)
eglSwapBuffers(egl->display, egl->surface);
bo = gbm_surface_lock_front_buffer(gbm->surface);
fb = drm_fb_get_from_bo(bo);
+   if (!fb) {
+   fprintf(stderr, "Failed to get a new framebuffer BO\n");
+   return -1;
+   }
 
/* set mode: */
ret = drmModeSetCrtc(drm.fd, drm.crtc_id, fb->fb_id, 0, 0,
@@ -78,6 +82,10 @@ static int legacy_run(const struct gbm *gbm, const struct 
egl *egl)
eglSwapBuffers(egl->display, egl->surface);
next_bo = gbm_surface_lock_front_buffer(gbm->surface);
fb = drm_fb_get_from_bo(next_bo);
+   if (!fb) {
+   fprintf(stderr, "Failed to get a new framebuffer BO\n");
+   return -1;
+   }
 
/*
 * Here you could also update drm plane layers if you want
-- 
2.12.2

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


Re: [Mesa-dev] [PATCH v2 2/4] egl, dri: Propagate context priority hint to driver->CreateContext

2017-04-11 Thread Ben Widawsky
urrent( __DRIcontext *driContextPriv,
diff --git a/src/mesa/drivers/dri/radeon/radeon_context.c 
b/src/mesa/drivers/dri/radeon/radeon_context.c
index 5e15b46fb3..885510f213 100644
--- a/src/mesa/drivers/dri/radeon/radeon_context.c
+++ b/src/mesa/drivers/dri/radeon/radeon_context.c
@@ -144,6 +144,7 @@ r100CreateContext( gl_api api,
   unsigned minor_version,
   uint32_t flags,
   bool notify_reset,
+  unsigned priority,
   unsigned *error,
   void *sharedContextPrivate)
{
diff --git a/src/mesa/drivers/dri/radeon/radeon_context.h 
b/src/mesa/drivers/dri/radeon/radeon_context.h
index 88a295386c..4124f50db5 100644
--- a/src/mesa/drivers/dri/radeon/radeon_context.h
+++ b/src/mesa/drivers/dri/radeon/radeon_context.h
@@ -456,6 +456,7 @@ extern GLboolean r100CreateContext( gl_api api,
unsigned minor_version,
uint32_t flags,
bool notify_reset,
+unsigned priority,
unsigned *error,
void *sharedContextPrivate);

diff --git a/src/mesa/drivers/dri/swrast/swrast.c 
b/src/mesa/drivers/dri/swrast/swrast.c
index f43ac608cf..8416616388 100644
--- a/src/mesa/drivers/dri/swrast/swrast.c
+++ b/src/mesa/drivers/dri/swrast/swrast.c
@@ -752,6 +752,7 @@ dri_create_context(gl_api api,
   unsigned minor_version,
   uint32_t flags,
   bool notify_reset,
+  unsigned priority,
       unsigned *error,
   void *sharedContextPrivate)
{


LGTM on i965 (i915) and dri bits.
Acked-by: Ben Widawsky 

--
Ben Widawsky, Intel Open Source Technology Center
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH v2 1/4] egl: Support IMG_context_priority

2017-04-11 Thread Ben Widawsky
break;
+case EGL_CONTEXT_PRIORITY_LOW_IMG:
+   bit = __EGL_CONTEXT_PRIORITY_LOW_BIT;
+   break;
+default:
+   bit = -1;
+   break;
+    }


unreachable()?

Either way:
Reviewed-by: Ben Widawsky 


+
+if (bit < 0 ||
+!(dpy->Extensions.IMG_context_priority & (1 << bit)) ){
+   err = EGL_BAD_ATTRIBUTE;
+   break;
+}
+
+ctx->ContextPriority = val;
+ }
+ break;
+
  default:
 err = EGL_BAD_ATTRIBUTE;
 break;
@@ -505,6 +544,7 @@ _eglInitContext(_EGLContext *ctx, _EGLDisplay *dpy, 
_EGLConfig *conf,
   ctx->Flags = 0;
   ctx->Profile = EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR;
   ctx->ResetNotificationStrategy = EGL_NO_RESET_NOTIFICATION_KHR;
+   ctx->ContextPriority = EGL_CONTEXT_PRIORITY_MEDIUM_IMG;

   err = _eglParseContextAttribList(ctx, dpy, attrib_list);
   if (err == EGL_SUCCESS && ctx->Config) {
@@ -570,6 +610,9 @@ _eglQueryContext(_EGLDriver *drv, _EGLDisplay *dpy, 
_EGLContext *c,
   case EGL_RENDER_BUFFER:
  *value = _eglQueryContextRenderBuffer(c);
  break;
+   case EGL_CONTEXT_PRIORITY_LEVEL_IMG:
+  *value = c->ContextPriority;
+  break;
   default:
  return _eglError(EGL_BAD_ATTRIBUTE, "eglQueryContext");
   }
diff --git a/src/egl/main/eglcontext.h b/src/egl/main/eglcontext.h
index f2fe806626..e8c2d7d4f3 100644
--- a/src/egl/main/eglcontext.h
+++ b/src/egl/main/eglcontext.h
@@ -62,6 +62,7 @@ struct _egl_context
   EGLint Flags;
   EGLint Profile;
   EGLint ResetNotificationStrategy;
+   EGLint ContextPriority;

   /* The real render buffer when a window surface is bound */
   EGLint WindowRenderBuffer;
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index 6c1049d23c..449ddb7b48 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -104,6 +104,11 @@ struct _egl_extensions
   EGLBoolean EXT_image_dma_buf_import;
   EGLBoolean EXT_swap_buffers_with_damage;

+   unsigned int IMG_context_priority;
+#define  __EGL_CONTEXT_PRIORITY_LOW_BIT0
+#define  __EGL_CONTEXT_PRIORITY_MEDIUM_BIT 1
+#define  __EGL_CONTEXT_PRIORITY_HIGH_BIT   2
+
   EGLBoolean KHR_cl_event2;
   EGLBoolean KHR_config_attribs;
   EGLBoolean KHR_create_context;
--
2.11.0



--
Ben Widawsky, Intel Open Source Technology Center
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] gbm: Assert modifiers and count are copacetic

2017-04-06 Thread Ben Widawsky
The API/entry point in mesa already checks the correct behavior,
however, it's possible to be handled by another implementation and those
implementations should not be able to abuse a weird combination of count
and pointer.

This fixes CID 1403193

Cc: Mark Janes 
Signed-off-by: Ben Widawsky 
---
 src/gbm/backends/dri/gbm_dri.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index 8df6a6b64d..71590d7110 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -1266,6 +1266,9 @@ gbm_dri_surface_create(struct gbm_device *gbm,
   return NULL;
}
 
+   if (count)
+  assert(modifiers);
+
/* It's acceptable to create an image with INVALID modifier in the list,
 * but it cannot be on the only modifier (since it will certainly fail
 * later). While we could easily catch this after modifier creation, doing
-- 
2.12.2

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


Re: [Mesa-dev] [PATCH 1/2] egl: Support IMG_context_priority

2017-04-06 Thread Ben Widawsky

On 17-04-06 20:12:35, Chris Wilson wrote:

IMG_context_priority
https://www.khronos.org/registry/egl/extensions/IMG/EGL_IMG_context_priority.txt

   "This extension allows an EGLContext to be created with a priority
   hint. It is possible that an implementation will not honour the
   hint, especially if there are constraints on the number of high
   priority contexts available in the system, or system policy limits
   access to high priority contexts to appropriate system privilege
   level. A query is provided to find the real priority level assigned
   to the context after creation."

The extension adds a new eglCreateContext attribute for choosing a
priority hint. This stub parses the attribute and copies into the base
struct _egl_context, and hooks up the query similarly.

Since the attribute is purely a hint, I have no qualms about the lack of
implementation before reporting back the value the user gave!

Signed-off-by: Chris Wilson 
Reviewed-by: Tapani Pälli 
Cc: Rob Clark 
---
src/egl/drivers/dri2/egl_dri2.c |  1 +
src/egl/main/eglapi.c   |  2 ++
src/egl/main/eglcontext.c   | 30 ++
src/egl/main/eglcontext.h   |  1 +
src/egl/main/egldisplay.h   |  2 ++
5 files changed, 36 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 2cab7d00c1..60e1472ac1 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -662,6 +662,7 @@ dri2_setup_screen(_EGLDisplay *disp)
   assert(dri2_dpy->image_driver || dri2_dpy->dri2 || dri2_dpy->swrast);
   disp->Extensions.KHR_no_config_context = EGL_TRUE;
   disp->Extensions.KHR_surfaceless_context = EGL_TRUE;
+   disp->Extensions.IMG_context_priority = EGL_TRUE; /* only a hint */

   if (dri2_renderer_query_integer(dri2_dpy,
   __DRI2_RENDERER_HAS_FRAMEBUFFER_SRGB))
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 5694b5a4ca..9ed65b1bba 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -490,6 +490,8 @@ _eglCreateExtensionsString(_EGLDisplay *dpy)
   _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import);
   _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage);

+   _EGL_CHECK_EXTENSION(IMG_context_priority);
+
   _EGL_CHECK_EXTENSION(KHR_cl_event2);
   _EGL_CHECK_EXTENSION(KHR_config_attribs);
   _EGL_CHECK_EXTENSION(KHR_create_context);
diff --git a/src/egl/main/eglcontext.c b/src/egl/main/eglcontext.c
index 05cc523c8d..54151d6b24 100644
--- a/src/egl/main/eglcontext.c
+++ b/src/egl/main/eglcontext.c
@@ -312,6 +312,33 @@ _eglParseContextAttribList(_EGLContext *ctx, _EGLDisplay 
*dpy,
ctx->Flags |= EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR;
 break;

+  case EGL_CONTEXT_PRIORITY_LEVEL_IMG:
+ /* The  EGL_IMG_context_priority spec says:
+  *
+  * "EGL_CONTEXT_PRIORITY_LEVEL_IMG determines the priority level of
+  * the context to be created. This attribute is a hint, as an
+  * implementation may not support multiple contexts at some
+  * priority levels and system policy may limit access to high
+  * priority contexts to appropriate system privilege level. The
+  * default value for EGL_CONTEXT_PRIORITY_LEVEL_IMG is
+  * EGL_CONTEXT_PRIORITY_MEDIUM_IMG."
+  */
+ if (!dpy->Extensions.IMG_context_priority) {
+err = EGL_BAD_ATTRIBUTE;
+break;
+ }
+ switch (val) {
+ case EGL_CONTEXT_PRIORITY_HIGH_IMG:
+ case EGL_CONTEXT_PRIORITY_MEDIUM_IMG:
+ case EGL_CONTEXT_PRIORITY_LOW_IMG:
+ctx->ContextPriority = val;
+break;
+ default:
+err = EGL_BAD_ATTRIBUTE;
+break;
+ }
+ break;
+
  default:
 err = EGL_BAD_ATTRIBUTE;
 break;
@@ -570,6 +597,9 @@ _eglQueryContext(_EGLDriver *drv, _EGLDisplay *dpy, 
_EGLContext *c,
   case EGL_RENDER_BUFFER:
  *value = _eglQueryContextRenderBuffer(c);
  break;
+   case EGL_CONTEXT_PRIORITY_LEVEL_IMG:
+  *value = c->ContextPriority;
+  break;
   default:
  return _eglError(EGL_BAD_ATTRIBUTE, "eglQueryContext");
   }
diff --git a/src/egl/main/eglcontext.h b/src/egl/main/eglcontext.h
index f2fe806626..e8c2d7d4f3 100644
--- a/src/egl/main/eglcontext.h
+++ b/src/egl/main/eglcontext.h
@@ -62,6 +62,7 @@ struct _egl_context
   EGLint Flags;
   EGLint Profile;
   EGLint ResetNotificationStrategy;
+   EGLint ContextPriority;


Should this be initialized to EGL_CONTEXT_PRIORITY_MEDIUM_IMG? Quick glance
through the spec doesn't make this immediately obvious, but it seems like yes to
me.



   /* The real render buffer when a window surface is bound */
   EGLint WindowRenderBuffer;
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index 6c1049d23c..84899ddcd0 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -104,6 +104,8 @@ struct _egl_extensions
   EGLBoolean EXT_ima

Re: [Mesa-dev] [PATCH 26/34] i965: Pretend that CCS modified images are two planes

2017-03-27 Thread Ben Widawsky

On 17-03-23 14:02:13, Daniel Stone wrote:

Hi Ben,

On 24 January 2017 at 06:21, Ben Widawsky  wrote:

@@ -1018,9 +1018,18 @@ intel_from_planar(__DRIimage *parent, int plane, void 
*loaderPrivate)
 int width, height, offset, stride, dri_format, index;
 struct intel_image_format *f;
 __DRIimage *image;
-
-if (parent == NULL || parent->planar_format == NULL)
-return NULL;
+bool is_aux = parent->aux_offset && plane == 1;
+
+if (parent == NULL || parent->planar_format == NULL) {
+   if (is_aux) {
+  offset = parent->aux_offset;
+  stride = ALIGN(parent->pitch / 32, 128);
+  height = ALIGN(DIV_ROUND_UP(parent->height, 16), 32);
+  dri_format = parent->dri_format;
+  goto done;


The non-goto version in modifiersv9 now throws a warning for 'width'
being uninitialised. I assume this should just be ALIGN(parent->width
/ 32, 32), or ... ?

Cheers,
Daniel


It should be:
width = ALIGN(DIV_ROUND_UP(parent->width, 32), 128);

I'm reworking as much of this as possible to use ISL. modv12 should have that.

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


[Mesa-dev] [PATCH 5/8] [v4] i965/dri: Handle the linear fb modifier

2017-03-21 Thread Ben Widawsky
At image creation create a path for dealing with the linear modifier.
This works exactly like the old usage flags where __DRI_IMAGE_USE_LINEAR
was specified.

During development of this patch series, it was decided that a lack of
modifier was an insufficient way to express the required modifiers. As a
result, 0 was repurposed to mean a modifier for a LINEAR layout.

NOTE: This patch was added for v3 of the patch series.

v2: Rework the algorithm for modifier selection to go from a bitmask
based selection to this priority value.

v3: Make DRM_FORMAT_MOD_INVALID allowed at selection as a way of
identifying no modifiers found (because 0 is LINEAR) (Jason)

v4: Remove the logic to prune unknown modifiers (like those from other
vendors) and simply handle is in select_best_modifier (Jason)

Requested-by: Jason Ekstrand 
Signed-off-by: Ben Widawsky 
Reviewed-by: Jason Ekstrand 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 55 +---
 1 file changed, 44 insertions(+), 11 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 26ab5a8e19..a430964f02 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -45,6 +45,10 @@
 #define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
 #endif
 
+#ifndef DRM_FORMAT_MOD_LINEAR
+#define DRM_FORMAT_MOD_LINEAR 0
+#endif
+
 static const __DRIconfigOptionsExtension brw_config_options = {
.base = { __DRI_CONFIG_OPTIONS, 1 },
.xml =
@@ -511,13 +515,36 @@ intel_destroy_image(__DRIimage *image)
free(image);
 }
 
+enum modifier_priority {
+   MODIFIER_PRIORITY_INVALID = 0,
+   MODIFIER_PRIORITY_LINEAR,
+};
+
+const uint64_t priority_to_modifier[] = {
+   [MODIFIER_PRIORITY_INVALID] = DRM_FORMAT_MOD_INVALID,
+   [MODIFIER_PRIORITY_LINEAR] = DRM_FORMAT_MOD_LINEAR,
+};
+
 static uint64_t
 select_best_modifier(struct gen_device_info *devinfo,
  const uint64_t *modifiers,
  const unsigned count)
 {
-   /* Modifiers are not supported by this DRI driver */
-   return DRM_FORMAT_MOD_INVALID;
+
+   enum modifier_priority prio = MODIFIER_PRIORITY_INVALID;
+
+   for (int i = 0; i < count; i++) {
+  switch (modifiers[i]) {
+  case DRM_FORMAT_MOD_LINEAR:
+ prio = MAX2(prio, MODIFIER_PRIORITY_LINEAR);
+ break;
+  case DRM_FORMAT_MOD_INVALID:
+  default:
+ break;
+  }
+   }
+
+   return priority_to_modifier[prio];
 }
 
 static __DRIimage *
@@ -530,7 +557,10 @@ intel_create_image_common(__DRIscreen *dri_screen,
 {
__DRIimage *image;
struct intel_screen *screen = dri_screen->driverPrivate;
-   uint32_t tiling;
+   /* Historically, X-tiled was the default, and so lack of modifier means
+* X-tiled.
+*/
+   uint32_t tiling = I915_TILING_X;
int cpp;
unsigned long pitch;
 
@@ -541,15 +571,17 @@ intel_create_image_common(__DRIscreen *dri_screen,
assert(!(use && count));
 
uint64_t modifier = select_best_modifier(&screen->devinfo, modifiers, 
count);
-   assert(modifier == DRM_FORMAT_MOD_INVALID);
-
-   if (modifier == DRM_FORMAT_MOD_INVALID && modifiers)
-  return NULL;
+   switch (modifier) {
+   case DRM_FORMAT_MOD_LINEAR:
+  tiling = I915_TILING_NONE;
+  break;
+   case DRM_FORMAT_MOD_INVALID:
+  if (modifiers)
+ return NULL;
+   default:
+ break;
+   }
 
-   /* Historically, X-tiled was the default, and so lack of modifier means
-* X-tiled.
-*/
-   tiling = I915_TILING_X;
if (use & __DRI_IMAGE_USE_CURSOR) {
   if (width != 64 || height != 64)
 return NULL;
@@ -574,6 +606,7 @@ intel_create_image_common(__DRIscreen *dri_screen,
image->width = width;
image->height = height;
image->pitch = pitch;
+   image->modifier = modifier;
 
return image;
 }
-- 
2.12.0

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


Re: [Mesa-dev] [PATCH] i965/dri: Handle the linear fb modifier

2017-03-21 Thread Ben Widawsky

On 17-03-21 14:15:05, Jason Ekstrand wrote:

On Tue, Mar 21, 2017 at 2:09 PM, Ben Widawsky  wrote:


At image creation create a path for dealing with the linear modifier.
This works exactly like the old usage flags where __DRI_IMAGE_USE_LINEAR
was specified.

During development of this patch series, it was decided that a lack of
modifier was an insufficient way to express the required modifiers. As a
result, 0 was repurposed to mean a modifier for a LINEAR layout.

NOTE: This patch was added for v3 of the patch series.

v2: Rework the algorithm for modifier selection to go from a bitmask
based selection to this priority value.

v3: Make DRM_FORMAT_MOD_INVALID allowed at selection as a way of
identifying no modifiers found (because 0 is LINEAR) (Jason)

Requested-by: Jason Ekstrand 
Signed-off-by: Ben Widawsky 
Reviewed-by: Jason Ekstrand 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 56
+---
 1 file changed, 45 insertions(+), 11 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c
b/src/mesa/drivers/dri/i965/intel_screen.c
index 26ab5a8e19..6c1fee586b 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -45,6 +45,10 @@
 #define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
 #endif

+#ifndef DRM_FORMAT_MOD_LINEAR
+#define DRM_FORMAT_MOD_LINEAR 0
+#endif
+
 static const __DRIconfigOptionsExtension brw_config_options = {
.base = { __DRI_CONFIG_OPTIONS, 1 },
.xml =
@@ -511,13 +515,37 @@ intel_destroy_image(__DRIimage *image)
free(image);
 }

+enum modifier_priority {
+   MODIFIER_PRIORITY_INVALID = 0,
+   MODIFIER_PRIORITY_LINEAR,
+};
+
+const uint64_t priority_to_modifier[] = {
+   [MODIFIER_PRIORITY_INVALID] = DRM_FORMAT_MOD_INVALID,
+   [MODIFIER_PRIORITY_LINEAR] = DRM_FORMAT_MOD_LINEAR,
+};
+
 static uint64_t
 select_best_modifier(struct gen_device_info *devinfo,
  const uint64_t *modifiers,
  const unsigned count)
 {
-   /* Modifiers are not supported by this DRI driver */
-   return DRM_FORMAT_MOD_INVALID;
+
+   enum modifier_priority prio = MODIFIER_PRIORITY_INVALID;
+
+   for (int i = 0; i < count; i++) {
+  switch (modifiers[i]) {
+  case DRM_FORMAT_MOD_LINEAR:
+ prio = MAX2(prio, MODIFIER_PRIORITY_LINEAR);
+ break;
+  case DRM_FORMAT_MOD_INVALID:
+ break;
+  default:
+ unreachable("Invalid modifiers specified\n");



I think we want them to both break don't we?




Oh yes. After removing the code to prune other modifiers, we do.


+  }
+   }
+
+   return priority_to_modifier[prio];
 }

 static __DRIimage *
@@ -530,7 +558,10 @@ intel_create_image_common(__DRIscreen *dri_screen,
 {
__DRIimage *image;
struct intel_screen *screen = dri_screen->driverPrivate;
-   uint32_t tiling;
+   /* Historically, X-tiled was the default, and so lack of modifier means
+* X-tiled.
+*/
+   uint32_t tiling = I915_TILING_X;
int cpp;
unsigned long pitch;

@@ -541,15 +572,17 @@ intel_create_image_common(__DRIscreen *dri_screen,
assert(!(use && count));

uint64_t modifier = select_best_modifier(&screen->devinfo, modifiers,
count);
-   assert(modifier == DRM_FORMAT_MOD_INVALID);
-
-   if (modifier == DRM_FORMAT_MOD_INVALID && modifiers)
-  return NULL;
+   switch (modifier) {
+   case DRM_FORMAT_MOD_LINEAR:
+  tiling = I915_TILING_NONE;
+  break;
+   case DRM_FORMAT_MOD_INVALID:
+  if (modifiers)
+ return NULL;
+   default:
+ break;
+   }

-   /* Historically, X-tiled was the default, and so lack of modifier means
-* X-tiled.
-*/
-   tiling = I915_TILING_X;
if (use & __DRI_IMAGE_USE_CURSOR) {
   if (width != 64 || height != 64)
 return NULL;
@@ -574,6 +607,7 @@ intel_create_image_common(__DRIscreen *dri_screen,
image->width = width;
image->height = height;
image->pitch = pitch;
+   image->modifier = modifier;

return image;
 }
--
2.12.0



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


[Mesa-dev] [PATCH] i965/dri: Handle Y-tiled modifier

2017-03-21 Thread Ben Widawsky
This patch begins introducing how we'll actually handle the potentially
many modifiers coming in from the API, how we'll store them, and the
structure in the code to support it.

Prior to this patch, the Y-tiled modifier would be entirely ignored. It
shouldn't actually be used until this point because we've not bumped the
DRIimage extension version (which is a requirement to use modifiers).

Measuring later in the series with kmscube:
Linear:
Read bandwidth: 1048.44 MiB/s
Write bandwidth: 1483.17 MiB/s

Y-tiled:
Read bandwidth: 471.13 MiB/s
Write bandwidth: 589.10 MiB/s

Similar functionality was introduced and then reverted here:

commit 6a0d036483caf87d43ebe2edd1905873446c9589
Author: Ben Widawsky 
Date:   Thu Apr 21 20:14:58 2016 -0700

i965: Always use Y-tiled buffers on SKL+

v2: Use last set bit instead of first set bit in modifiers to address
bug found by Daniel Stone.

v3: Use the new priority modifier selection thing. This nullifies the
bug fixed by v2 also.

v4: Get rid of modifier compaction which originally served another
purpose and now serves none (Jason)

Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom 
Acked-by: Daniel Stone 
Reviewed-by: Jason Ekstrand 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 18 ++
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 6c1fee586b..6c22636ad9 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -23,6 +23,7 @@
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -518,11 +519,13 @@ intel_destroy_image(__DRIimage *image)
 enum modifier_priority {
MODIFIER_PRIORITY_INVALID = 0,
MODIFIER_PRIORITY_LINEAR,
+   MODIFIER_PRIORITY_Y,
 };
 
 const uint64_t priority_to_modifier[] = {
[MODIFIER_PRIORITY_INVALID] = DRM_FORMAT_MOD_INVALID,
[MODIFIER_PRIORITY_LINEAR] = DRM_FORMAT_MOD_LINEAR,
+   [MODIFIER_PRIORITY_Y] = I915_FORMAT_MOD_Y_TILED,
 };
 
 static uint64_t
@@ -530,11 +533,13 @@ select_best_modifier(struct gen_device_info *devinfo,
  const uint64_t *modifiers,
  const unsigned count)
 {
-
enum modifier_priority prio = MODIFIER_PRIORITY_INVALID;
 
for (int i = 0; i < count; i++) {
   switch (modifiers[i]) {
+  case I915_FORMAT_MOD_Y_TILED:
+ prio = MAX2(prio, MODIFIER_PRIORITY_Y);
+ break;
   case DRM_FORMAT_MOD_LINEAR:
  prio = MAX2(prio, MODIFIER_PRIORITY_LINEAR);
  break;
@@ -576,6 +581,9 @@ intel_create_image_common(__DRIscreen *dri_screen,
case DRM_FORMAT_MOD_LINEAR:
   tiling = I915_TILING_NONE;
   break;
+   case I915_FORMAT_MOD_Y_TILED:
+  tiling = I915_TILING_Y;
+  break;
case DRM_FORMAT_MOD_INVALID:
   if (modifiers)
  return NULL;
@@ -629,8 +637,8 @@ intel_create_image_with_modifiers(__DRIscreen *dri_screen,
   const unsigned count,
   void *loaderPrivate)
 {
-   return intel_create_image_common(dri_screen, width, height, format, 0, NULL,
-0, loaderPrivate);
+   return intel_create_image_common(dri_screen, width, height, format, 0,
+modifiers, count, loaderPrivate);
 }
 
 static GLboolean
@@ -2000,7 +2008,9 @@ intelAllocateBuffer(__DRIscreen *dri_screen,
if (intelBuffer == NULL)
   return NULL;
 
-   /* The front and back buffers are color buffers, which are X tiled. */
+   /* The front and back buffers are color buffers, which are X tiled. GEN9+
+* supports Y tiled and compressed buffers, but there is no way to plumb 
that
+* through to here. */
uint32_t tiling = I915_TILING_X;
unsigned long pitch;
int cpp = format / 8;
-- 
2.12.0

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


[Mesa-dev] [PATCH] i965/dri: Handle the linear fb modifier

2017-03-21 Thread Ben Widawsky
At image creation create a path for dealing with the linear modifier.
This works exactly like the old usage flags where __DRI_IMAGE_USE_LINEAR
was specified.

During development of this patch series, it was decided that a lack of
modifier was an insufficient way to express the required modifiers. As a
result, 0 was repurposed to mean a modifier for a LINEAR layout.

NOTE: This patch was added for v3 of the patch series.

v2: Rework the algorithm for modifier selection to go from a bitmask
based selection to this priority value.

v3: Make DRM_FORMAT_MOD_INVALID allowed at selection as a way of
identifying no modifiers found (because 0 is LINEAR) (Jason)

Requested-by: Jason Ekstrand 
Signed-off-by: Ben Widawsky 
Reviewed-by: Jason Ekstrand 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 56 +---
 1 file changed, 45 insertions(+), 11 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 26ab5a8e19..6c1fee586b 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -45,6 +45,10 @@
 #define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
 #endif
 
+#ifndef DRM_FORMAT_MOD_LINEAR
+#define DRM_FORMAT_MOD_LINEAR 0
+#endif
+
 static const __DRIconfigOptionsExtension brw_config_options = {
.base = { __DRI_CONFIG_OPTIONS, 1 },
.xml =
@@ -511,13 +515,37 @@ intel_destroy_image(__DRIimage *image)
free(image);
 }
 
+enum modifier_priority {
+   MODIFIER_PRIORITY_INVALID = 0,
+   MODIFIER_PRIORITY_LINEAR,
+};
+
+const uint64_t priority_to_modifier[] = {
+   [MODIFIER_PRIORITY_INVALID] = DRM_FORMAT_MOD_INVALID,
+   [MODIFIER_PRIORITY_LINEAR] = DRM_FORMAT_MOD_LINEAR,
+};
+
 static uint64_t
 select_best_modifier(struct gen_device_info *devinfo,
  const uint64_t *modifiers,
  const unsigned count)
 {
-   /* Modifiers are not supported by this DRI driver */
-   return DRM_FORMAT_MOD_INVALID;
+
+   enum modifier_priority prio = MODIFIER_PRIORITY_INVALID;
+
+   for (int i = 0; i < count; i++) {
+  switch (modifiers[i]) {
+  case DRM_FORMAT_MOD_LINEAR:
+ prio = MAX2(prio, MODIFIER_PRIORITY_LINEAR);
+ break;
+  case DRM_FORMAT_MOD_INVALID:
+ break;
+  default:
+ unreachable("Invalid modifiers specified\n");
+  }
+   }
+
+   return priority_to_modifier[prio];
 }
 
 static __DRIimage *
@@ -530,7 +558,10 @@ intel_create_image_common(__DRIscreen *dri_screen,
 {
__DRIimage *image;
struct intel_screen *screen = dri_screen->driverPrivate;
-   uint32_t tiling;
+   /* Historically, X-tiled was the default, and so lack of modifier means
+* X-tiled.
+*/
+   uint32_t tiling = I915_TILING_X;
int cpp;
unsigned long pitch;
 
@@ -541,15 +572,17 @@ intel_create_image_common(__DRIscreen *dri_screen,
assert(!(use && count));
 
uint64_t modifier = select_best_modifier(&screen->devinfo, modifiers, 
count);
-   assert(modifier == DRM_FORMAT_MOD_INVALID);
-
-   if (modifier == DRM_FORMAT_MOD_INVALID && modifiers)
-  return NULL;
+   switch (modifier) {
+   case DRM_FORMAT_MOD_LINEAR:
+  tiling = I915_TILING_NONE;
+  break;
+   case DRM_FORMAT_MOD_INVALID:
+  if (modifiers)
+ return NULL;
+   default:
+ break;
+   }
 
-   /* Historically, X-tiled was the default, and so lack of modifier means
-* X-tiled.
-*/
-   tiling = I915_TILING_X;
if (use & __DRI_IMAGE_USE_CURSOR) {
   if (width != 64 || height != 64)
 return NULL;
@@ -574,6 +607,7 @@ intel_create_image_common(__DRIscreen *dri_screen,
image->width = width;
image->height = height;
image->pitch = pitch;
+   image->modifier = modifier;
 
return image;
 }
-- 
2.12.0

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


Re: [Mesa-dev] [PATCH 6/8] i965/dri: Handle Y-tiled modifier

2017-03-21 Thread Ben Widawsky

On 17-03-21 13:52:12, Jason Ekstrand wrote:

On Tue, Mar 21, 2017 at 1:45 PM, Ben Widawsky  wrote:


This patch begins introducing how we'll actually handle the potentially
many modifiers coming in from the API, how we'll store them, and the
structure in the code to support it.

Prior to this patch, the Y-tiled modifier would be entirely ignored. It
shouldn't actually be used until this point because we've not bumped the
DRIimage extension version (which is a requirement to use modifiers).

Measuring later in the series with kmscube:
Linear:
Read bandwidth: 1048.44 MiB/s
Write bandwidth: 1483.17 MiB/s

Y-tiled:
Read bandwidth: 471.13 MiB/s
Write bandwidth: 589.10 MiB/s

Similar functionality was introduced and then reverted here:

commit 6a0d036483caf87d43ebe2edd1905873446c9589
Author: Ben Widawsky 
Date:   Thu Apr 21 20:14:58 2016 -0700

i965: Always use Y-tiled buffers on SKL+

v2: Use last set bit instead of first set bit in modifiers to address
bug found by Daniel Stone.

v3: Use the new priority modifier selection thing. This nullifies the
bug fixed by v2 also.

Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom 
Acked-by: Daniel Stone 
Reviewed-by: Jason Ekstrand 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 36

 1 file changed, 32 insertions(+), 4 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c
b/src/mesa/drivers/dri/i965/intel_screen.c
index 8ba90f0a0c..8bb3aca946 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -23,6 +23,7 @@
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */

+#include 
 #include 
 #include 
 #include 
@@ -518,11 +519,13 @@ intel_destroy_image(__DRIimage *image)
 enum modifier_priority {
MODIFIER_PRIORITY_INVALID = 0,
MODIFIER_PRIORITY_LINEAR,
+   MODIFIER_PRIORITY_Y,
 };

 const uint64_t priority_to_modifier[] = {
[MODIFIER_PRIORITY_INVALID] = DRM_FORMAT_MOD_INVALID,
[MODIFIER_PRIORITY_LINEAR] = DRM_FORMAT_MOD_LINEAR,
+   [MODIFIER_PRIORITY_Y] = I915_FORMAT_MOD_Y_TILED,
 };

 static uint64_t
@@ -530,11 +533,13 @@ select_best_modifier(struct gen_device_info *devinfo,
  const uint64_t *modifiers,
  const unsigned count)
 {
-
enum modifier_priority prio = MODIFIER_PRIORITY_INVALID;

for (int i = 0; i < count; i++) {
   switch (modifiers[i]) {
+  case I915_FORMAT_MOD_Y_TILED:
+ prio = MAX2(prio, MODIFIER_PRIORITY_Y);
+ break;
   case DRM_FORMAT_MOD_LINEAR:
  prio = MAX2(prio, MODIFIER_PRIORITY_LINEAR);
  break;
@@ -575,6 +580,9 @@ intel_create_image_common(__DRIscreen *dri_screen,
case DRM_FORMAT_MOD_LINEAR:
   tiling = I915_TILING_NONE;
   break;
+   case I915_FORMAT_MOD_Y_TILED:
+  tiling = I915_TILING_Y;
+  break;
case DRM_FORMAT_MOD_INVALID:
   if (modifiers)
  return NULL;
@@ -628,8 +636,26 @@ intel_create_image_with_modifiers(__DRIscreen
*dri_screen,
   const unsigned count,
   void *loaderPrivate)
 {
-   return intel_create_image_common(dri_screen, width, height, format,
0, NULL,
-0, loaderPrivate);
+   uint64_t local_mods[count];
+   int local_count = 0;
+
+   /* This compacts the actual modifiers to the ones we know how to
handle */
+   for (int i = 0; i < count; i++) {
+  switch (modifiers[i]) {
+  case I915_FORMAT_MOD_Y_TILED:
+  case DRM_FORMAT_MOD_LINEAR:
+ local_mods[local_count++] = modifiers[i];
+ break;
+  case DRM_FORMAT_MOD_INVALID:
+ unreachable("Invalid modifiers specified\n");



I don't think you want unreachable here.  The higher layers only check
modifier zero.  They don't walk the entire list.




Yeah, same problem as before.


+  default:
+ /* Modifiers from other vendors would land here. */
+ break;
+  }
+   }



Also, what's the benifit of the local modifiers thing?  The
select_best_modifier can handle an arbitrarily long list so I don't see
what this is gaining us.




It's a relic from the original patches which actually stored a list of potential
modifiers (so it was calloc'd here). That required getting a count.  It can be
removed now because intel_create_image_common() doesn't do anything on
unrecognized modifies (again, it used to).


+
+   return intel_create_image_common(dri_screen, width, height, format, 0,
+local_mods, local_count,
loaderPrivate);
 }

 static GLboolean
@@ -1999,7 +2025,9 @@ intelAllocateBuffer(__DRIscreen *dri_screen,
if (intelBuffer == NULL)
   return NULL;

-   /* The front and back buffers are color buffers, which are X tiled. */
+   /* The front and back buffers are color buffers, which are X tiled.
GEN9+
+* supports Y tiled and compressed buffers, but there

Re: [Mesa-dev] [PATCH 5/8] i965/dri: Handle the linear fb modifier

2017-03-21 Thread Ben Widawsky

On 17-03-21 13:48:13, Jason Ekstrand wrote:

On Tue, Mar 21, 2017 at 1:45 PM, Ben Widawsky  wrote:


At image creation create a path for dealing with the linear modifier.
This works exactly like the old usage flags where __DRI_IMAGE_USE_LINEAR
was specified.

During development of this patch series, it was decided that a lack of
modifier was an insufficient way to express the required modifiers. As a
result, 0 was repurposed to mean a modifier for a LINEAR layout.

NOTE: This patch was added for v3 of the patch series.

v2: Rework the algorithm for modifier selection to go from a bitmask
based selection to this priority value.

Requested-by: Jason Ekstrand 
Signed-off-by: Ben Widawsky 
Reviewed-by: Jason Ekstrand 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 55
+---
 1 file changed, 44 insertions(+), 11 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c
b/src/mesa/drivers/dri/i965/intel_screen.c
index 26ab5a8e19..8ba90f0a0c 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -45,6 +45,10 @@
 #define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
 #endif

+#ifndef DRM_FORMAT_MOD_LINEAR
+#define DRM_FORMAT_MOD_LINEAR 0
+#endif
+
 static const __DRIconfigOptionsExtension brw_config_options = {
.base = { __DRI_CONFIG_OPTIONS, 1 },
.xml =
@@ -511,13 +515,36 @@ intel_destroy_image(__DRIimage *image)
free(image);
 }

+enum modifier_priority {
+   MODIFIER_PRIORITY_INVALID = 0,
+   MODIFIER_PRIORITY_LINEAR,
+};
+
+const uint64_t priority_to_modifier[] = {
+   [MODIFIER_PRIORITY_INVALID] = DRM_FORMAT_MOD_INVALID,
+   [MODIFIER_PRIORITY_LINEAR] = DRM_FORMAT_MOD_LINEAR,
+};
+
 static uint64_t
 select_best_modifier(struct gen_device_info *devinfo,
  const uint64_t *modifiers,
  const unsigned count)
 {
-   /* Modifiers are not supported by this DRI driver */
-   return DRM_FORMAT_MOD_INVALID;
+
+   enum modifier_priority prio = MODIFIER_PRIORITY_INVALID;
+
+   for (int i = 0; i < count; i++) {
+  switch (modifiers[i]) {
+  case DRM_FORMAT_MOD_LINEAR:
+ prio = MAX2(prio, MODIFIER_PRIORITY_LINEAR);
+ break;
+  case DRM_FORMAT_MOD_INVALID:
+  default:
+ unreachable("Invalid modifiers specified\n");



How'd this sneak back in?  I think you want to just fall through and
continue on to the next loop iteration in this case.




Yep. Sorry about that.


+  }
+   }
+
+   return priority_to_modifier[prio];
 }

 static __DRIimage *
@@ -530,7 +557,10 @@ intel_create_image_common(__DRIscreen *dri_screen,
 {
__DRIimage *image;
struct intel_screen *screen = dri_screen->driverPrivate;
-   uint32_t tiling;
+   /* Historically, X-tiled was the default, and so lack of modifier means
+* X-tiled.
+*/
+   uint32_t tiling = I915_TILING_X;
int cpp;
unsigned long pitch;

@@ -541,15 +571,17 @@ intel_create_image_common(__DRIscreen *dri_screen,
assert(!(use && count));

uint64_t modifier = select_best_modifier(&screen->devinfo, modifiers,
count);
-   assert(modifier == DRM_FORMAT_MOD_INVALID);
-
-   if (modifier == DRM_FORMAT_MOD_INVALID && modifiers)
-  return NULL;
+   switch (modifier) {
+   case DRM_FORMAT_MOD_LINEAR:
+  tiling = I915_TILING_NONE;
+  break;
+   case DRM_FORMAT_MOD_INVALID:
+  if (modifiers)
+ return NULL;
+   default:
+ break;
+   }

-   /* Historically, X-tiled was the default, and so lack of modifier means
-* X-tiled.
-*/
-   tiling = I915_TILING_X;
if (use & __DRI_IMAGE_USE_CURSOR) {
   if (width != 64 || height != 64)
 return NULL;
@@ -574,6 +606,7 @@ intel_create_image_common(__DRIscreen *dri_screen,
image->width = width;
image->height = height;
image->pitch = pitch;
+   image->modifier = modifier;

return image;
 }
--
2.12.0



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


[Mesa-dev] [PATCH 6/8] i965/dri: Handle Y-tiled modifier

2017-03-21 Thread Ben Widawsky
This patch begins introducing how we'll actually handle the potentially
many modifiers coming in from the API, how we'll store them, and the
structure in the code to support it.

Prior to this patch, the Y-tiled modifier would be entirely ignored. It
shouldn't actually be used until this point because we've not bumped the
DRIimage extension version (which is a requirement to use modifiers).

Measuring later in the series with kmscube:
Linear:
Read bandwidth: 1048.44 MiB/s
Write bandwidth: 1483.17 MiB/s

Y-tiled:
Read bandwidth: 471.13 MiB/s
Write bandwidth: 589.10 MiB/s

Similar functionality was introduced and then reverted here:

commit 6a0d036483caf87d43ebe2edd1905873446c9589
Author: Ben Widawsky 
Date:   Thu Apr 21 20:14:58 2016 -0700

i965: Always use Y-tiled buffers on SKL+

v2: Use last set bit instead of first set bit in modifiers to address
bug found by Daniel Stone.

v3: Use the new priority modifier selection thing. This nullifies the
bug fixed by v2 also.

Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom 
Acked-by: Daniel Stone 
Reviewed-by: Jason Ekstrand 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 36 
 1 file changed, 32 insertions(+), 4 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 8ba90f0a0c..8bb3aca946 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -23,6 +23,7 @@
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -518,11 +519,13 @@ intel_destroy_image(__DRIimage *image)
 enum modifier_priority {
MODIFIER_PRIORITY_INVALID = 0,
MODIFIER_PRIORITY_LINEAR,
+   MODIFIER_PRIORITY_Y,
 };
 
 const uint64_t priority_to_modifier[] = {
[MODIFIER_PRIORITY_INVALID] = DRM_FORMAT_MOD_INVALID,
[MODIFIER_PRIORITY_LINEAR] = DRM_FORMAT_MOD_LINEAR,
+   [MODIFIER_PRIORITY_Y] = I915_FORMAT_MOD_Y_TILED,
 };
 
 static uint64_t
@@ -530,11 +533,13 @@ select_best_modifier(struct gen_device_info *devinfo,
  const uint64_t *modifiers,
  const unsigned count)
 {
-
enum modifier_priority prio = MODIFIER_PRIORITY_INVALID;
 
for (int i = 0; i < count; i++) {
   switch (modifiers[i]) {
+  case I915_FORMAT_MOD_Y_TILED:
+ prio = MAX2(prio, MODIFIER_PRIORITY_Y);
+ break;
   case DRM_FORMAT_MOD_LINEAR:
  prio = MAX2(prio, MODIFIER_PRIORITY_LINEAR);
  break;
@@ -575,6 +580,9 @@ intel_create_image_common(__DRIscreen *dri_screen,
case DRM_FORMAT_MOD_LINEAR:
   tiling = I915_TILING_NONE;
   break;
+   case I915_FORMAT_MOD_Y_TILED:
+  tiling = I915_TILING_Y;
+  break;
case DRM_FORMAT_MOD_INVALID:
   if (modifiers)
  return NULL;
@@ -628,8 +636,26 @@ intel_create_image_with_modifiers(__DRIscreen *dri_screen,
   const unsigned count,
   void *loaderPrivate)
 {
-   return intel_create_image_common(dri_screen, width, height, format, 0, NULL,
-0, loaderPrivate);
+   uint64_t local_mods[count];
+   int local_count = 0;
+
+   /* This compacts the actual modifiers to the ones we know how to handle */
+   for (int i = 0; i < count; i++) {
+  switch (modifiers[i]) {
+  case I915_FORMAT_MOD_Y_TILED:
+  case DRM_FORMAT_MOD_LINEAR:
+ local_mods[local_count++] = modifiers[i];
+ break;
+  case DRM_FORMAT_MOD_INVALID:
+ unreachable("Invalid modifiers specified\n");
+  default:
+ /* Modifiers from other vendors would land here. */
+ break;
+  }
+   }
+
+   return intel_create_image_common(dri_screen, width, height, format, 0,
+local_mods, local_count, loaderPrivate);
 }
 
 static GLboolean
@@ -1999,7 +2025,9 @@ intelAllocateBuffer(__DRIscreen *dri_screen,
if (intelBuffer == NULL)
   return NULL;
 
-   /* The front and back buffers are color buffers, which are X tiled. */
+   /* The front and back buffers are color buffers, which are X tiled. GEN9+
+* supports Y tiled and compressed buffers, but there is no way to plumb 
that
+* through to here. */
uint32_t tiling = I915_TILING_X;
unsigned long pitch;
int cpp = format / 8;
-- 
2.12.0

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


[Mesa-dev] [PATCH 7/8] i965/dri: Handle X-tiled modifier

2017-03-21 Thread Ben Widawsky
This doesn't really "do" anything because the default tiling for the
winsys buffer is X tiled. We do however want the X tiled modifier to
work correctly from the API perspective, which would imply that if you
set this modifier, and later do a get_modifier, you get back at least X
tiled.

Running with a modified kmscube, here are the bandwidth measurements.

Linear:
Read bandwidth: 1039.31 MiB/s
Write bandwidth: 1453.56 MiB/s

Y-tiled:
Read bandwidth: 458.29 MiB/s
Write bandwidth: 542.12 MiB/s

X-tiled:
Read bandwidth: 575.01 MiB/s
Write bandwidth: 606.25 MiB/s

Cc: Kristian Høgsberg 
Signed-off-by: Ben Widawsky 
Acked-by: Daniel Stone 
Reviewed-by: Jason Ekstrand 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 8bb3aca946..b51b9c859a 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -519,12 +519,14 @@ intel_destroy_image(__DRIimage *image)
 enum modifier_priority {
MODIFIER_PRIORITY_INVALID = 0,
MODIFIER_PRIORITY_LINEAR,
+   MODIFIER_PRIORITY_X,
MODIFIER_PRIORITY_Y,
 };
 
 const uint64_t priority_to_modifier[] = {
[MODIFIER_PRIORITY_INVALID] = DRM_FORMAT_MOD_INVALID,
[MODIFIER_PRIORITY_LINEAR] = DRM_FORMAT_MOD_LINEAR,
+   [MODIFIER_PRIORITY_X] = I915_FORMAT_MOD_X_TILED,
[MODIFIER_PRIORITY_Y] = I915_FORMAT_MOD_Y_TILED,
 };
 
@@ -540,6 +542,9 @@ select_best_modifier(struct gen_device_info *devinfo,
   case I915_FORMAT_MOD_Y_TILED:
  prio = MAX2(prio, MODIFIER_PRIORITY_Y);
  break;
+  case I915_FORMAT_MOD_X_TILED:
+ prio = MAX2(prio, MODIFIER_PRIORITY_X);
+ break;
   case DRM_FORMAT_MOD_LINEAR:
  prio = MAX2(prio, MODIFIER_PRIORITY_LINEAR);
  break;
@@ -577,6 +582,9 @@ intel_create_image_common(__DRIscreen *dri_screen,
 
uint64_t modifier = select_best_modifier(&screen->devinfo, modifiers, 
count);
switch (modifier) {
+   case I915_FORMAT_MOD_X_TILED:
+  assert(tiling == I915_TILING_X);
+  break;
case DRM_FORMAT_MOD_LINEAR:
   tiling = I915_TILING_NONE;
   break;
@@ -643,6 +651,7 @@ intel_create_image_with_modifiers(__DRIscreen *dri_screen,
for (int i = 0; i < count; i++) {
   switch (modifiers[i]) {
   case I915_FORMAT_MOD_Y_TILED:
+  case I915_FORMAT_MOD_X_TILED:
   case DRM_FORMAT_MOD_LINEAR:
  local_mods[local_count++] = modifiers[i];
  break;
-- 
2.12.0

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


[Mesa-dev] [PATCH 8/8] i965/dri: Turn on support for image modifiers

2017-03-21 Thread Ben Widawsky
All the plumbing is in place so the extension just needs to be
advertised.

Signed-off-by: Ben Widawsky 
Reviewed-by: Jason Ekstrand 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index b51b9c859a..d3f6a50b9f 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -947,7 +947,7 @@ intel_from_planar(__DRIimage *parent, int plane, void 
*loaderPrivate)
 }
 
 static const __DRIimageExtension intelImageExtension = {
-.base = { __DRI_IMAGE, 13 },
+.base = { __DRI_IMAGE, 14 },
 
 .createImageFromName= intel_create_image_from_name,
 .createImageFromRenderbuffer= intel_create_image_from_renderbuffer,
-- 
2.12.0

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


[Mesa-dev] [PATCH 5/8] i965/dri: Handle the linear fb modifier

2017-03-21 Thread Ben Widawsky
At image creation create a path for dealing with the linear modifier.
This works exactly like the old usage flags where __DRI_IMAGE_USE_LINEAR
was specified.

During development of this patch series, it was decided that a lack of
modifier was an insufficient way to express the required modifiers. As a
result, 0 was repurposed to mean a modifier for a LINEAR layout.

NOTE: This patch was added for v3 of the patch series.

v2: Rework the algorithm for modifier selection to go from a bitmask
based selection to this priority value.

Requested-by: Jason Ekstrand 
Signed-off-by: Ben Widawsky 
Reviewed-by: Jason Ekstrand 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 55 +---
 1 file changed, 44 insertions(+), 11 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 26ab5a8e19..8ba90f0a0c 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -45,6 +45,10 @@
 #define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
 #endif
 
+#ifndef DRM_FORMAT_MOD_LINEAR
+#define DRM_FORMAT_MOD_LINEAR 0
+#endif
+
 static const __DRIconfigOptionsExtension brw_config_options = {
.base = { __DRI_CONFIG_OPTIONS, 1 },
.xml =
@@ -511,13 +515,36 @@ intel_destroy_image(__DRIimage *image)
free(image);
 }
 
+enum modifier_priority {
+   MODIFIER_PRIORITY_INVALID = 0,
+   MODIFIER_PRIORITY_LINEAR,
+};
+
+const uint64_t priority_to_modifier[] = {
+   [MODIFIER_PRIORITY_INVALID] = DRM_FORMAT_MOD_INVALID,
+   [MODIFIER_PRIORITY_LINEAR] = DRM_FORMAT_MOD_LINEAR,
+};
+
 static uint64_t
 select_best_modifier(struct gen_device_info *devinfo,
  const uint64_t *modifiers,
  const unsigned count)
 {
-   /* Modifiers are not supported by this DRI driver */
-   return DRM_FORMAT_MOD_INVALID;
+
+   enum modifier_priority prio = MODIFIER_PRIORITY_INVALID;
+
+   for (int i = 0; i < count; i++) {
+  switch (modifiers[i]) {
+  case DRM_FORMAT_MOD_LINEAR:
+ prio = MAX2(prio, MODIFIER_PRIORITY_LINEAR);
+ break;
+  case DRM_FORMAT_MOD_INVALID:
+  default:
+ unreachable("Invalid modifiers specified\n");
+  }
+   }
+
+   return priority_to_modifier[prio];
 }
 
 static __DRIimage *
@@ -530,7 +557,10 @@ intel_create_image_common(__DRIscreen *dri_screen,
 {
__DRIimage *image;
struct intel_screen *screen = dri_screen->driverPrivate;
-   uint32_t tiling;
+   /* Historically, X-tiled was the default, and so lack of modifier means
+* X-tiled.
+*/
+   uint32_t tiling = I915_TILING_X;
int cpp;
unsigned long pitch;
 
@@ -541,15 +571,17 @@ intel_create_image_common(__DRIscreen *dri_screen,
assert(!(use && count));
 
uint64_t modifier = select_best_modifier(&screen->devinfo, modifiers, 
count);
-   assert(modifier == DRM_FORMAT_MOD_INVALID);
-
-   if (modifier == DRM_FORMAT_MOD_INVALID && modifiers)
-  return NULL;
+   switch (modifier) {
+   case DRM_FORMAT_MOD_LINEAR:
+  tiling = I915_TILING_NONE;
+  break;
+   case DRM_FORMAT_MOD_INVALID:
+  if (modifiers)
+ return NULL;
+   default:
+ break;
+   }
 
-   /* Historically, X-tiled was the default, and so lack of modifier means
-* X-tiled.
-*/
-   tiling = I915_TILING_X;
if (use & __DRI_IMAGE_USE_CURSOR) {
   if (width != 64 || height != 64)
 return NULL;
@@ -574,6 +606,7 @@ intel_create_image_common(__DRIscreen *dri_screen,
image->width = width;
image->height = height;
image->pitch = pitch;
+   image->modifier = modifier;
 
return image;
 }
-- 
2.12.0

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


[Mesa-dev] [PATCH 4/8] i965/dri: Enable modifier queries

2017-03-21 Thread Ben Widawsky
New to the patch series after reordering things for landing smaller
chunks.

This will essentially enable modifiers from clients that were just
enabled in previous patches. A client could use the modifiers by
setting all of them at create, but had no way to actually query them
after creating the surface (ie. stupid clients could be broken before
this patch, but in more ways than this).

Obviously, there are no modifiers being actually stored yet - so this
patch shouldn't do anything other than allow the API to get back 0 (or
the LINEAR modifier).

Signed-off-by: Ben Widawsky 
Reviewed-by: Jason Ekstrand 
---
 src/mesa/drivers/dri/i965/intel_image.h  | 1 +
 src/mesa/drivers/dri/i965/intel_screen.c | 6 ++
 2 files changed, 7 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/intel_image.h 
b/src/mesa/drivers/dri/i965/intel_image.h
index fd63919b2d..a362c76689 100644
--- a/src/mesa/drivers/dri/i965/intel_image.h
+++ b/src/mesa/drivers/dri/i965/intel_image.h
@@ -71,6 +71,7 @@ struct __DRIimageRec {
GLenum internal_format;
uint32_t dri_format;
GLuint format;
+   uint64_t modifier; /**< fb modifier (fourcc) */
uint32_t offset;
 
/*
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 90223bab2b..26ab5a8e19 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -635,6 +635,12 @@ intel_query_image(__DRIimage *image, int attrib, int 
*value)
case __DRI_IMAGE_ATTRIB_OFFSET:
   *value = image->offset;
   return true;
+   case __DRI_IMAGE_ATTRIB_MODIFIER_LOWER:
+  *value = (image->modifier & 0x);
+  return true;
+   case __DRI_IMAGE_ATTRIB_MODIFIER_UPPER:
+  *value = ((image->modifier >> 32) & 0x);
+  return true;
 
   default:
   return false;
-- 
2.12.0

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


[Mesa-dev] [PATCH 3/8] i965/dri: Store the screen associated with the image

2017-03-21 Thread Ben Widawsky
I intend to need to get to the devinfo structure, and storing the screen
is an easy way to do that.

It seems to be the consensus that you cannot share an image between
multiple screens.

Scape-goat: Rob Clark 
Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom 
Acked-by: Daniel Stone 
Reviewed-by: Jason Ekstrand 
---
 src/mesa/drivers/dri/i965/intel_image.h  |  1 +
 src/mesa/drivers/dri/i965/intel_screen.c | 16 ++--
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_image.h 
b/src/mesa/drivers/dri/i965/intel_image.h
index 9b3816efd1..fd63919b2d 100644
--- a/src/mesa/drivers/dri/i965/intel_image.h
+++ b/src/mesa/drivers/dri/i965/intel_image.h
@@ -65,6 +65,7 @@ struct intel_image_format {
 };
 
 struct __DRIimageRec {
+   struct intel_screen *screen;
drm_intel_bo *bo;
uint32_t pitch; /**< in bytes */
GLenum internal_format;
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index b77933e100..90223bab2b 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -323,7 +323,8 @@ static boolean intel_lookup_fourcc(int dri_format, int 
*fourcc)
 }
 
 static __DRIimage *
-intel_allocate_image(int dri_format, void *loaderPrivate)
+intel_allocate_image(struct intel_screen *screen, int dri_format,
+ void *loaderPrivate)
 {
 __DRIimage *image;
 
@@ -331,6 +332,7 @@ intel_allocate_image(int dri_format, void *loaderPrivate)
 if (image == NULL)
return NULL;
 
+image->screen = screen;
 image->dri_format = dri_format;
 image->offset = 0;
 
@@ -381,7 +383,7 @@ intel_create_image_from_name(__DRIscreen *dri_screen,
 __DRIimage *image;
 int cpp;
 
-image = intel_allocate_image(format, loaderPrivate);
+image = intel_allocate_image(screen, format, loaderPrivate);
 if (image == NULL)
return NULL;
 
@@ -557,7 +559,7 @@ intel_create_image_common(__DRIscreen *dri_screen,
if (use & __DRI_IMAGE_USE_LINEAR)
   tiling = I915_TILING_NONE;
 
-   image = intel_allocate_image(format, loaderPrivate);
+   image = intel_allocate_image(screen, format, loaderPrivate);
if (image == NULL)
   return NULL;
 
@@ -740,9 +742,11 @@ intel_create_image_from_fds(__DRIscreen *dri_screen,
   return NULL;
 
if (f->nplanes == 1)
-  image = intel_allocate_image(f->planes[0].dri_format, loaderPrivate);
+  image = intel_allocate_image(screen, f->planes[0].dri_format,
+   loaderPrivate);
else
-  image = intel_allocate_image(__DRI_IMAGE_FORMAT_NONE, loaderPrivate);
+  image = intel_allocate_image(screen, __DRI_IMAGE_FORMAT_NONE,
+   loaderPrivate);
 
if (image == NULL)
   return NULL;
@@ -845,7 +849,7 @@ intel_from_planar(__DRIimage *parent, int plane, void 
*loaderPrivate)
 offset = parent->offsets[index];
 stride = parent->strides[index];
 
-image = intel_allocate_image(dri_format, loaderPrivate);
+image = intel_allocate_image(parent->screen, dri_format, loaderPrivate);
 if (image == NULL)
return NULL;
 
-- 
2.12.0

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


[Mesa-dev] [PATCH 1/8] i965/dri: Disallow image with INVALID modifier

2017-03-21 Thread Ben Widawsky
Signed-off-by: Ben Widawsky 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index af9c9a45f3..b77933e100 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -541,6 +541,9 @@ intel_create_image_common(__DRIscreen *dri_screen,
uint64_t modifier = select_best_modifier(&screen->devinfo, modifiers, 
count);
assert(modifier == DRM_FORMAT_MOD_INVALID);
 
+   if (modifier == DRM_FORMAT_MOD_INVALID && modifiers)
+  return NULL;
+
/* Historically, X-tiled was the default, and so lack of modifier means
 * X-tiled.
 */
-- 
2.12.0

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


[Mesa-dev] [PATCH 2/8] gbm: Disallow INVALID modifiers returned upon image creation

2017-03-21 Thread Ben Widawsky
Signed-off-by: Ben Widawsky 
---
 src/gbm/backends/dri/gbm_dri.c | 28 
 1 file changed, 28 insertions(+)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index a7ac149365..283a73454e 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -1143,12 +1143,29 @@ gbm_dri_bo_create(struct gbm_device *gbm,
  goto failed;
   }
 
+  /* It's acceptable to create an image with INVALID modifier in the list,
+   * but it cannot be on the only modifier (since it will certainly fail
+   * later). While we could easily catch this after modifier creation, 
doing
+   * the check here is a convenient debug check likely pointing at whatever
+   * interface the client is using to build its modifier list.
+   */
+  if (count == 1 && modifiers[0] == DRM_FORMAT_MOD_INVALID) {
+ fprintf(stderr, "Only invalid modifier specified\n");
+ errno = EINVAL;
+ goto failed;
+  }
+
   bo->image =
  dri->image->createImageWithModifiers(dri->screen,
   width, height,
   dri_format,
   modifiers, count,
   bo);
+
+  if (bo->image) {
+ /* The client passed in a list of invalid modifiers */
+ assert(gbm_dri_bo_get_modifier(&bo->base.base) != 
DRM_FORMAT_MOD_INVALID);
+  }
} else {
   bo->image = dri->image->createImage(dri->screen, width, height,
   dri_format, dri_use, bo);
@@ -1240,6 +1257,17 @@ gbm_dri_surface_create(struct gbm_device *gbm,
   return NULL;
}
 
+   /* It's acceptable to create an image with INVALID modifier in the list,
+* but it cannot be on the only modifier (since it will certainly fail
+* later). While we could easily catch this after modifier creation, doing
+* the check here is a convenient debug check likely pointing at whatever
+* interface the client is using to build its modifier list.
+*/
+   if (count == 1 && modifiers[0] == DRM_FORMAT_MOD_INVALID) {
+  fprintf(stderr, "Only invalid modifier specified\n");
+  errno = EINVAL;
+   }
+
surf = calloc(1, sizeof *surf);
if (surf == NULL) {
   errno = ENOMEM;
-- 
2.12.0

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


[Mesa-dev] [PATCH 0/8] [v2] i965 tiling modifiers

2017-03-21 Thread Ben Widawsky
v2 of the third chunk of Renderbuffer Decompression support. The big change over
the previous version is that now the INVALID modifier is explcitly disallowed in
the GBM layer (and the equivalent i965 functionality).

The other big change is the priority selection algorithm for modifiers.

As before, Y-tiled (as well as X, and linear) modifier can be used for DRI
images at the end of this patch series in i965.

Jason has reviewed most of this already, but since I added a few patches I
thought it was necessary to resend the whole thing.

Ben Widawsky (8):
  i965/dri: Disallow image with INVALID modifier
  gbm: Disallow INVALID modifiers returned upon image creation
  i965/dri: Store the screen associated with the image
  i965/dri: Enable modifier queries
  i965/dri: Handle the linear fb modifier
  i965/dri: Handle Y-tiled modifier
  i965/dri: Handle X-tiled modifier
  i965/dri: Turn on support for image modifiers

 src/gbm/backends/dri/gbm_dri.c   |  28 
 src/mesa/drivers/dri/i965/intel_image.h  |   2 +
 src/mesa/drivers/dri/i965/intel_screen.c | 119 ++-
 3 files changed, 131 insertions(+), 18 deletions(-)

-- 
2.12.0

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


Re: [Mesa-dev] [PATCH 4/6] [v2] i965: Handle Y-tiled modifier

2017-03-21 Thread Ben Widawsky

On 17-03-21 08:07:22, Jason Ekstrand wrote:

On Tue, Mar 21, 2017 at 8:04 AM, Jason Ekstrand 
wrote:


On Mon, Mar 20, 2017 at 8:35 PM, Ben Widawsky  wrote:


This patch begins introducing how we'll actually handle the potentially
many modifiers coming in from the API, how we'll store them, and the
structure in the code to support it.

Prior to this patch, the Y-tiled modifier would be entirely ignored. It
shouldn't actually be used until this point because we've not bumped the
DRIimage extension version (which is a requirement to use modifiers).

Measuring later in the series with kmscbe:
Linear:
Read bandwidth: 1048.44 MiB/s
Write bandwidth: 1483.17 MiB/s

Y-tiled:
Read bandwidth: 471.13 MiB/s
Write bandwidth: 589.10 MiB/s

Similar functionality was introduced and then reverted here:

commit 6a0d036483caf87d43ebe2edd1905873446c9589
Author: Ben Widawsky 
Date:   Thu Apr 21 20:14:58 2016 -0700

i965: Always use Y-tiled buffers on SKL+

v2: Use last set bit instead of first set bit in modifiers to address
bug found by Daniel Stone.

v3: Use the new priority modifier selection thing. This nullifies the
bug fixed by v2 also.

Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom 
Acked-by: Daniel Stone 
---
 src/gbm/backends/dri/gbm_dri.c   | 18 
 src/mesa/drivers/dri/i965/intel_screen.c | 36

 2 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/src/gbm/backends/dri/gbm_dri.c
b/src/gbm/backends/dri/gbm_dri.c
index a7ac149365..a78ea89fca 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -1143,6 +1143,15 @@ gbm_dri_bo_create(struct gbm_device *gbm,
  goto failed;
   }

+  if (modifiers) {
+ for (int i = 0; i < count; i++)
+if (modifiers[i] == DRM_FORMAT_MOD_INVALID) {
+   fprintf(stderr, "Invalid modifier passed in
DRM_FORMAT_MOD_INVALID");
+   errno = EINVAL;
+   goto failed;
+}
+  }
+
   bo->image =
  dri->image->createImageWithModifiers(dri->screen,
   width, height,
@@ -1240,6 +1249,15 @@ gbm_dri_surface_create(struct gbm_device *gbm,
   return NULL;
}

+   if (modifiers) {
+  for (int i = 0; i < count; i++)
+ if (modifiers[i] == DRM_FORMAT_MOD_INVALID) {
+fprintf(stderr, "Invalid modifier passed in
DRM_FORMAT_MOD_INVALID");
+errno = EINVAL;
+return NULL;
+ }
+   }



This could be its own patch but I don't care too much.



Also, you don't need this anymore now that MOD_INVALID just falls through
and doesn't assert below.  Feel free to drop it, pull it into its own
patch, or leave it here.  (I have a mild preference for dropping it and
just ignoring MOD_INVALID but don't care too much).  With that, series is

Reviewed-by: Jason Ekstrand 




intel_create_image_with_modifiers() (which will be called by this) will assert
if INVALID modifier slips through - which is what I wanted. I don't want any dri
implementation to have to deal with INVALID modifiers. So I think it needs to be
here. Did I misunderstand you?


+

surf = calloc(1, sizeof *surf);
if (surf == NULL) {
   errno = ENOMEM;
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c
b/src/mesa/drivers/dri/i965/intel_screen.c
index 14e60ef1a1..e4f858ed33 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -23,6 +23,7 @@
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */

+#include 
 #include 
 #include 
 #include 
@@ -518,11 +519,13 @@ intel_destroy_image(__DRIimage *image)
 enum modifier_priority {
MODIFIER_PRIORITY_INVALID = 0,
MODIFIER_PRIORITY_LINEAR,
+   MODIFIER_PRIORITY_Y,
 };

 const uint64_t priority_to_modifier[] = {
[MODIFIER_PRIORITY_INVALID] = DRM_FORMAT_MOD_INVALID,
[MODIFIER_PRIORITY_LINEAR] = DRM_FORMAT_MOD_LINEAR,
+   [MODIFIER_PRIORITY_Y] = I915_FORMAT_MOD_Y_TILED,
 };

 static uint64_t
@@ -530,11 +533,13 @@ select_best_modifier(struct gen_device_info
*devinfo,
  const uint64_t *modifiers,
  const unsigned count)
 {
-
enum modifier_priority prio = MODIFIER_PRIORITY_INVALID;

for (int i = 0; i < count; i++) {
   switch (modifiers[i]) {
+  case I915_FORMAT_MOD_Y_TILED:
+ prio = MAX2(prio, MODIFIER_PRIORITY_Y);
+ break;
   case DRM_FORMAT_MOD_LINEAR:
  prio = MAX2(prio, MODIFIER_PRIORITY_LINEAR);
  break;
@@ -575,6 +580,9 @@ intel_create_image_common(__DRIscreen *dri_screen,
case DRM_FORMAT_MOD_LINEAR:
   tiling = I915_TILING_NONE;
   break;
+   case I915_FORMAT_MOD_Y_TILED:
+  tiling = I915_TILING_Y;
+  break;
case DRM_FORMAT_MOD_INVALID:
default:
  break;
@@ -626,8 +634,26 @@ intel_create_image_with_modi

[Mesa-dev] [PATCH 5/6] [v2] i965: Handle X-tiled modifier

2017-03-20 Thread Ben Widawsky
This doesn't really "do" anything because the default tiling for the
winsys buffer is X tiled. We do however want the X tiled modifier to
work correctly from the API perspective, which would imply that if you
set this modifier, and later do a get_modifier, you get back at least X
tiled.

Cc: Kristian Høgsberg 
Signed-off-by: Ben Widawsky 
Acked-by: Daniel Stone 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index e4f858ed33..9d458c707a 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -519,12 +519,14 @@ intel_destroy_image(__DRIimage *image)
 enum modifier_priority {
MODIFIER_PRIORITY_INVALID = 0,
MODIFIER_PRIORITY_LINEAR,
+   MODIFIER_PRIORITY_X,
MODIFIER_PRIORITY_Y,
 };
 
 const uint64_t priority_to_modifier[] = {
[MODIFIER_PRIORITY_INVALID] = DRM_FORMAT_MOD_INVALID,
[MODIFIER_PRIORITY_LINEAR] = DRM_FORMAT_MOD_LINEAR,
+   [MODIFIER_PRIORITY_X] = I915_FORMAT_MOD_X_TILED,
[MODIFIER_PRIORITY_Y] = I915_FORMAT_MOD_Y_TILED,
 };
 
@@ -540,6 +542,9 @@ select_best_modifier(struct gen_device_info *devinfo,
   case I915_FORMAT_MOD_Y_TILED:
  prio = MAX2(prio, MODIFIER_PRIORITY_Y);
  break;
+  case I915_FORMAT_MOD_X_TILED:
+ prio = MAX2(prio, MODIFIER_PRIORITY_X);
+ break;
   case DRM_FORMAT_MOD_LINEAR:
  prio = MAX2(prio, MODIFIER_PRIORITY_LINEAR);
  break;
@@ -577,6 +582,9 @@ intel_create_image_common(__DRIscreen *dri_screen,
 
uint64_t modifier = select_best_modifier(&screen->devinfo, modifiers, 
count);
switch (modifier) {
+   case I915_FORMAT_MOD_X_TILED:
+  assert(tiling == I915_TILING_X);
+  break;
case DRM_FORMAT_MOD_LINEAR:
   tiling = I915_TILING_NONE;
   break;
@@ -641,6 +649,7 @@ intel_create_image_with_modifiers(__DRIscreen *dri_screen,
for (int i = 0; i < count; i++) {
   switch (modifiers[i]) {
   case I915_FORMAT_MOD_Y_TILED:
+  case I915_FORMAT_MOD_X_TILED:
   case DRM_FORMAT_MOD_LINEAR:
  local_mods[local_count++] = modifiers[i];
  break;
-- 
2.12.0

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


[Mesa-dev] [PATCH 4/6] [v2] i965: Handle Y-tiled modifier

2017-03-20 Thread Ben Widawsky
This patch begins introducing how we'll actually handle the potentially
many modifiers coming in from the API, how we'll store them, and the
structure in the code to support it.

Prior to this patch, the Y-tiled modifier would be entirely ignored. It
shouldn't actually be used until this point because we've not bumped the
DRIimage extension version (which is a requirement to use modifiers).

Measuring later in the series with kmscbe:
Linear:
Read bandwidth: 1048.44 MiB/s
Write bandwidth: 1483.17 MiB/s

Y-tiled:
Read bandwidth: 471.13 MiB/s
Write bandwidth: 589.10 MiB/s

Similar functionality was introduced and then reverted here:

commit 6a0d036483caf87d43ebe2edd1905873446c9589
Author: Ben Widawsky 
Date:   Thu Apr 21 20:14:58 2016 -0700

i965: Always use Y-tiled buffers on SKL+

v2: Use last set bit instead of first set bit in modifiers to address
bug found by Daniel Stone.

v3: Use the new priority modifier selection thing. This nullifies the
bug fixed by v2 also.

Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom 
Acked-by: Daniel Stone 
---
 src/gbm/backends/dri/gbm_dri.c   | 18 
 src/mesa/drivers/dri/i965/intel_screen.c | 36 
 2 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index a7ac149365..a78ea89fca 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -1143,6 +1143,15 @@ gbm_dri_bo_create(struct gbm_device *gbm,
  goto failed;
   }
 
+  if (modifiers) {
+ for (int i = 0; i < count; i++)
+if (modifiers[i] == DRM_FORMAT_MOD_INVALID) {
+   fprintf(stderr, "Invalid modifier passed in 
DRM_FORMAT_MOD_INVALID");
+   errno = EINVAL;
+   goto failed;
+}
+  }
+
   bo->image =
  dri->image->createImageWithModifiers(dri->screen,
   width, height,
@@ -1240,6 +1249,15 @@ gbm_dri_surface_create(struct gbm_device *gbm,
   return NULL;
}
 
+   if (modifiers) {
+  for (int i = 0; i < count; i++)
+ if (modifiers[i] == DRM_FORMAT_MOD_INVALID) {
+fprintf(stderr, "Invalid modifier passed in 
DRM_FORMAT_MOD_INVALID");
+errno = EINVAL;
+return NULL;
+ }
+   }
+
surf = calloc(1, sizeof *surf);
if (surf == NULL) {
   errno = ENOMEM;
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 14e60ef1a1..e4f858ed33 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -23,6 +23,7 @@
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -518,11 +519,13 @@ intel_destroy_image(__DRIimage *image)
 enum modifier_priority {
MODIFIER_PRIORITY_INVALID = 0,
MODIFIER_PRIORITY_LINEAR,
+   MODIFIER_PRIORITY_Y,
 };
 
 const uint64_t priority_to_modifier[] = {
[MODIFIER_PRIORITY_INVALID] = DRM_FORMAT_MOD_INVALID,
[MODIFIER_PRIORITY_LINEAR] = DRM_FORMAT_MOD_LINEAR,
+   [MODIFIER_PRIORITY_Y] = I915_FORMAT_MOD_Y_TILED,
 };
 
 static uint64_t
@@ -530,11 +533,13 @@ select_best_modifier(struct gen_device_info *devinfo,
  const uint64_t *modifiers,
  const unsigned count)
 {
-
enum modifier_priority prio = MODIFIER_PRIORITY_INVALID;
 
for (int i = 0; i < count; i++) {
   switch (modifiers[i]) {
+  case I915_FORMAT_MOD_Y_TILED:
+ prio = MAX2(prio, MODIFIER_PRIORITY_Y);
+ break;
   case DRM_FORMAT_MOD_LINEAR:
  prio = MAX2(prio, MODIFIER_PRIORITY_LINEAR);
  break;
@@ -575,6 +580,9 @@ intel_create_image_common(__DRIscreen *dri_screen,
case DRM_FORMAT_MOD_LINEAR:
   tiling = I915_TILING_NONE;
   break;
+   case I915_FORMAT_MOD_Y_TILED:
+  tiling = I915_TILING_Y;
+  break;
case DRM_FORMAT_MOD_INVALID:
default:
  break;
@@ -626,8 +634,26 @@ intel_create_image_with_modifiers(__DRIscreen *dri_screen,
   const unsigned count,
   void *loaderPrivate)
 {
-   return intel_create_image_common(dri_screen, width, height, format, 0, NULL,
-0, loaderPrivate);
+   uint64_t local_mods[count];
+   int local_count = 0;
+
+   /* This compacts the actual modifiers to the ones we know how to handle */
+   for (int i = 0; i < count; i++) {
+  switch (modifiers[i]) {
+  case I915_FORMAT_MOD_Y_TILED:
+  case DRM_FORMAT_MOD_LINEAR:
+ local_mods[local_count++] = modifiers[i];
+ break;
+  case DRM_FORMAT_MOD_INVALID:
+ unreachable("Invalid modifiers specified\n");
+  default:
+ /* Modifiers from other vendors would land here. */
+ break;
+  }
+   }
+

[Mesa-dev] [PATCH 2/6] [v2] i965: Enable modifier queries

2017-03-20 Thread Ben Widawsky
New to the patch series after reordering things for landing smaller
chunks.

This will essentially enable modifiers from clients that were just
enabled in previous patches. A client could use the modifiers by
setting all of them at create, but had no way to actually query them
after creating the surface (ie. stupid clients could be broken before
this patch, but in more ways than this).

Obviously, there are no modifiers being actually stored yet - so this
patch shouldn't do anything other than allow the API to get back 0 (or
the LINEAR modifier).

Signed-off-by: Ben Widawsky 
---
 src/mesa/drivers/dri/i965/intel_image.h  | 1 +
 src/mesa/drivers/dri/i965/intel_screen.c | 6 ++
 2 files changed, 7 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/intel_image.h 
b/src/mesa/drivers/dri/i965/intel_image.h
index fd63919b2d..a362c76689 100644
--- a/src/mesa/drivers/dri/i965/intel_image.h
+++ b/src/mesa/drivers/dri/i965/intel_image.h
@@ -71,6 +71,7 @@ struct __DRIimageRec {
GLenum internal_format;
uint32_t dri_format;
GLuint format;
+   uint64_t modifier; /**< fb modifier (fourcc) */
uint32_t offset;
 
/*
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 1525b4c560..2455649032 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -632,6 +632,12 @@ intel_query_image(__DRIimage *image, int attrib, int 
*value)
case __DRI_IMAGE_ATTRIB_OFFSET:
   *value = image->offset;
   return true;
+   case __DRI_IMAGE_ATTRIB_MODIFIER_LOWER:
+  *value = (image->modifier & 0x);
+  return true;
+   case __DRI_IMAGE_ATTRIB_MODIFIER_UPPER:
+  *value = ((image->modifier >> 32) & 0x);
+  return true;
 
   default:
   return false;
-- 
2.12.0

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


[Mesa-dev] [PATCH 3/6] [v2] i965: Handle the linear fb modifier

2017-03-20 Thread Ben Widawsky
At image creation create a path for dealing with the linear modifier.
This works exactly like the old usage flags where __DRI_IMAGE_USE_LINEAR
was specified.

During development of this patch series, it was decided that a lack of
modifier was an insufficient way to express the required modifiers. As a
result, 0 was repurposed to mean a modifier for a LINEAR layout.

NOTE: This patch was added for v3 of the patch series.

v2: Rework the algorithm for modifier selection to go from a bitmask
based selection to this priority value.

Requested-by: Jason Ekstrand 
Signed-off-by: Ben Widawsky 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 50 +++-
 1 file changed, 42 insertions(+), 8 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 2455649032..14e60ef1a1 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -45,6 +45,10 @@
 #define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
 #endif
 
+#ifndef DRM_FORMAT_MOD_LINEAR
+#define DRM_FORMAT_MOD_LINEAR 0
+#endif
+
 static const __DRIconfigOptionsExtension brw_config_options = {
.base = { __DRI_CONFIG_OPTIONS, 1 },
.xml =
@@ -511,13 +515,36 @@ intel_destroy_image(__DRIimage *image)
free(image);
 }
 
+enum modifier_priority {
+   MODIFIER_PRIORITY_INVALID = 0,
+   MODIFIER_PRIORITY_LINEAR,
+};
+
+const uint64_t priority_to_modifier[] = {
+   [MODIFIER_PRIORITY_INVALID] = DRM_FORMAT_MOD_INVALID,
+   [MODIFIER_PRIORITY_LINEAR] = DRM_FORMAT_MOD_LINEAR,
+};
+
 static uint64_t
 select_best_modifier(struct gen_device_info *devinfo,
  const uint64_t *modifiers,
  const unsigned count)
 {
-   /* Modifiers are not supported by this DRI driver */
-   return DRM_FORMAT_MOD_INVALID;
+
+   enum modifier_priority prio = MODIFIER_PRIORITY_INVALID;
+
+   for (int i = 0; i < count; i++) {
+  switch (modifiers[i]) {
+  case DRM_FORMAT_MOD_LINEAR:
+ prio = MAX2(prio, MODIFIER_PRIORITY_LINEAR);
+ break;
+  case DRM_FORMAT_MOD_INVALID:
+  default:
+ unreachable("Invalid modifiers specified\n");
+  }
+   }
+
+   return priority_to_modifier[prio];
 }
 
 static __DRIimage *
@@ -530,7 +557,10 @@ intel_create_image_common(__DRIscreen *dri_screen,
 {
__DRIimage *image;
struct intel_screen *screen = dri_screen->driverPrivate;
-   uint32_t tiling;
+   /* Historically, X-tiled was the default, and so lack of modifier means
+* X-tiled.
+*/
+   uint32_t tiling = I915_TILING_X;
int cpp;
unsigned long pitch;
 
@@ -541,12 +571,15 @@ intel_create_image_common(__DRIscreen *dri_screen,
assert(!(use && count));
 
uint64_t modifier = select_best_modifier(&screen->devinfo, modifiers, 
count);
-   assert(modifier == DRM_FORMAT_MOD_INVALID);
+   switch (modifier) {
+   case DRM_FORMAT_MOD_LINEAR:
+  tiling = I915_TILING_NONE;
+  break;
+   case DRM_FORMAT_MOD_INVALID:
+   default:
+ break;
+   }
 
-   /* Historically, X-tiled was the default, and so lack of modifier means
-* X-tiled.
-*/
-   tiling = I915_TILING_X;
if (use & __DRI_IMAGE_USE_CURSOR) {
   if (width != 64 || height != 64)
 return NULL;
@@ -571,6 +604,7 @@ intel_create_image_common(__DRIscreen *dri_screen,
image->width = width;
image->height = height;
image->pitch = pitch;
+   image->modifier = modifier;
 
return image;
 }
-- 
2.12.0

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


[Mesa-dev] [PATCH 2/6] [v2] i965: Enable modifier queries

2017-03-20 Thread Ben Widawsky
New to the patch series after reordering things for landing smaller
chunks.

This will essentially enable modifiers from clients that were just
enabled in previous patches. A client could use the modifiers by
setting all of them at create, but had no way to actually query them
after creating the surface (ie. stupid clients could be broken before
this patch, but in more ways than this).

Obviously, there are no modifiers being actually stored yet - so this
patch shouldn't do anything other than allow the API to get back 0 (or
the LINEAR modifier).

Signed-off-by: Ben Widawsky 
---
 src/mesa/drivers/dri/i965/intel_image.h  | 1 +
 src/mesa/drivers/dri/i965/intel_screen.c | 6 ++
 2 files changed, 7 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/intel_image.h 
b/src/mesa/drivers/dri/i965/intel_image.h
index fd63919b2d..a362c76689 100644
--- a/src/mesa/drivers/dri/i965/intel_image.h
+++ b/src/mesa/drivers/dri/i965/intel_image.h
@@ -71,6 +71,7 @@ struct __DRIimageRec {
GLenum internal_format;
uint32_t dri_format;
GLuint format;
+   uint64_t modifier; /**< fb modifier (fourcc) */
uint32_t offset;
 
/*
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 1525b4c560..2455649032 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -632,6 +632,12 @@ intel_query_image(__DRIimage *image, int attrib, int 
*value)
case __DRI_IMAGE_ATTRIB_OFFSET:
   *value = image->offset;
   return true;
+   case __DRI_IMAGE_ATTRIB_MODIFIER_LOWER:
+  *value = (image->modifier & 0x);
+  return true;
+   case __DRI_IMAGE_ATTRIB_MODIFIER_UPPER:
+  *value = ((image->modifier >> 32) & 0x);
+  return true;
 
   default:
   return false;
-- 
2.12.0

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


Re: [Mesa-dev] [PATCH 6/5] i965: Turn on support for image modifiers

2017-03-20 Thread Ben Widawsky

On 17-03-20 16:21:53, Jason Ekstrand wrote:

On Mon, Mar 20, 2017 at 4:15 PM, Ben Widawsky  wrote:


On 17-03-20 12:03:24, Jason Ekstrand wrote:


My only question here is whether or not we want to add a "supported
modifiers" query to DRIimage before we bump the version number.  It's
probably not super-important because we can always bump the version number
again.  Meh.



Remind me what the reasoning is for support modifiers? I thought we agreed
to
just use GET_PLANE2? Supported modifiers is difficult because mesa has no
idea
of per plane constraints.



They're for completely different cases.  If you want to scan out, use
GET_PLANE2, end of story.  If, however, you're not trying to scan out and
your window is always going to get composited (think not full-screen) then
you may have a much larger set of modifiers available to you and that set
of modifiers is not determined by GET_PLANE2 but by the GL or whatever is
being used for compositing.




Oh, yeah. Is there a consumer today of this? If we don't really have one readily
available, I'd say don't worry about it until we need it.



On Sat, Mar 18, 2017 at 1:00 PM, Ben Widawsky  wrote:


All the plumbing is in place so the extension just needs to be

advertised.

Signed-off-by: Ben Widawsky 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c
b/src/mesa/drivers/dri/i965/intel_screen.c
index ca725d9202..1ff18b30e4 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -948,7 +948,7 @@ intel_from_planar(__DRIimage *parent, int plane, void
*loaderPrivate)
 }

 static const __DRIimageExtension intelImageExtension = {
-.base = { __DRI_IMAGE, 13 },
+.base = { __DRI_IMAGE, 14 },

 .createImageFromName= intel_create_image_from_name,
 .createImageFromRenderbuffer= intel_create_image_from_
renderbuffer,
--
2.12.0

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



--
Ben Widawsky, Intel Open Source Technology Center


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


Re: [Mesa-dev] [PATCH 6/5] i965: Turn on support for image modifiers

2017-03-20 Thread Ben Widawsky

On 17-03-20 12:03:24, Jason Ekstrand wrote:

My only question here is whether or not we want to add a "supported
modifiers" query to DRIimage before we bump the version number.  It's
probably not super-important because we can always bump the version number
again.  Meh.



Remind me what the reasoning is for support modifiers? I thought we agreed to
just use GET_PLANE2? Supported modifiers is difficult because mesa has no idea
of per plane constraints.


On Sat, Mar 18, 2017 at 1:00 PM, Ben Widawsky  wrote:


All the plumbing is in place so the extension just needs to be
advertised.

Signed-off-by: Ben Widawsky 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c
b/src/mesa/drivers/dri/i965/intel_screen.c
index ca725d9202..1ff18b30e4 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -948,7 +948,7 @@ intel_from_planar(__DRIimage *parent, int plane, void
*loaderPrivate)
 }

 static const __DRIimageExtension intelImageExtension = {
-.base = { __DRI_IMAGE, 13 },
+.base = { __DRI_IMAGE, 14 },

 .createImageFromName= intel_create_image_from_name,
 .createImageFromRenderbuffer= intel_create_image_from_
renderbuffer,
--
2.12.0

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



--
Ben Widawsky, Intel Open Source Technology Center
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 4/5] i965: Handle Y-tiled modifier

2017-03-20 Thread Ben Widawsky

On 17-03-20 15:36:37, Jason Ekstrand wrote:

On Mon, Mar 20, 2017 at 3:25 PM, Ben Widawsky  wrote:


On 17-03-20 12:00:44, Jason Ekstrand wrote:


On Fri, Mar 17, 2017 at 5:34 PM, Ben Widawsky  wrote:

This patch begins introducing how we'll actually handle the potentially

many modifiers coming in from the API, how we'll store them, and the
structure in the code to support it.

Prior to this patch, the Y-tiled modifier would be entirely ignored. It
shouldn't actually be used until this point because we've not bumped the
DRIimage extension version (which is a requirement to use modifiers).

With X-tiling:
Writes:  6,583.58 MiB
Reads:   6,540.93 MiB

With Y-tiling:
Writes:  5,361.78 MiB
Reads6,052.45 MiB

Savings per frame
Writes:  2 MiB
Reads:  .8 MiB

Similar functionality was introduced and then reverted here:

commit 6a0d036483caf87d43ebe2edd1905873446c9589
Author: Ben Widawsky 
Date:   Thu Apr 21 20:14:58 2016 -0700

i965: Always use Y-tiled buffers on SKL+

v2: Use last set bit instead of first set bit in modifiers to address
bug found by Daniel Stone.

Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom 
Acked-by: Daniel Stone 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 55

 1 file changed, 49 insertions(+), 6 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c
b/src/mesa/drivers/dri/i965/intel_screen.c
index 22ab3a30b6..1954757d1e 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -23,6 +23,7 @@
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */

+#include 
 #include 
 #include 
 #include 
@@ -520,16 +521,35 @@ select_best_modifier(struct gen_device_info
*devinfo,
  const uint64_t *modifiers,
  const unsigned count)
 {
-   uint64_t modifier = DRM_FORMAT_MOD_INVALID;
+#define YTILE  (1 << 1)
+#define LINEAR (1 << 0)
+
+   const uint64_t prio_modifiers[] = { I915_FORMAT_MOD_Y_TILED,
DRM_FORMAT_MOD_LINEAR };
+   uint32_t modifier_bitmask = 0; /* API only allows 32 */



The bitfield thing is still confusing to me.  Here's an idea on how we
could maybe make it better.

enum modifier_priority {
  MODIFIER_PRIORITY_LINEAR,
  MODIFIER_PRIORITY_X,
  MODIFIER_PRIORITY_Y,
  MODIFIER_PRIORITY_Y_CCS,
};

uint32_t priority_to_modifier[] = {
  [MODIFIER_PRIORITY_LINEAR] = DRM_FORMAT_MOD_LINEAR,
  [MODIFIER_PRIORITY_X] = I915_FORMAT_MOD_X_TILED,
  [MODIFIER_PRIORITY_Y] = I915_FORMAT_MOD_Y_TILED,
  [MODIFIER_PRIORITY_Y_CCS] = I915_FORMAT_MOD_Y_TILED_CCS,
}

enum modier_priority prio = 0;
for (int i = 0; i < count; i++) {
  switch (modifiers[i]) {
  case DRM_FORMAT_MOD_LINEAR:
 prio = MAX2(prio, MODIFIER_PRIORITY_LINEAR);
 break;

  case DRM_FORMAT_MOD_X_TILED:
 prio = MAX2(prio, MODIFIER_PRIORITY_X);
 break;

  case DRM_FORMAT_MOD_Y_TILED:
 prio = MAX2(prio, MODIFIER_PRIORITY_Y);
 break;

  case DRM_FORMAT_MOD_Y_TILIED_CCS:
 prio = MAX2(prio, MODIFIER_PRIORITY_Y_CCS);
 break;
}

return priority_to_modifier[prio];

How does this strike your fancy?  I'm ok with the bit set approach if you
really prefer it but I find it hard to reason about.



I don't really prefer. This looks pretty good. Seems no less complex to
me, but
I wrote the first one, so perhaps I'm partial.

Originally, I had some code in the equivalent function (before select_best
was
separate) which would try fallbacks, ie. if Y tiled allocation failed,
it'd go
down to the next modifier just walking down the bits, but logic is now
gone, so
there isn't really a point in the bitmask.

Will respin with this and the fixes meant below.





for (int i = 0; i < count; i++) {
   switch (modifiers[i]) {
   case DRM_FORMAT_MOD_LINEAR:
- return modifiers[i];
+ modifier_bitmask |= LINEAR;
+ break;
+  case I915_FORMAT_MOD_Y_TILED:
+ if (devinfo->gen < 9) {
+_mesa_warning(NULL, "Invalid Y-tiling parameter\n");
+continue;



This isn't invalid.  It's just invalid for scanout.  If you wanted to
create an image to share between two GL implementations, Y-tiling works
fine on everything.




As a general function to support modifiers, you are correct, however since
this
is only called for image creation, I believe the existing warning is
correct.



But what if I want to create an image to share between two userspace
processes with no scanout involved?  While the GBM portion of the API is
mostly intended for scanout, the EGL extension will be something that can
and will be used for GL <-> GL.  I guess we can always flip it on when we
add support for the EGL extension but I see no reason why it shouldn't work
through GBM.

Part of the problem may be that I really don't understand why GBM exists.
It's like a linux-specific half-of-EGL thing. :-/




Yeah, l

Re: [Mesa-dev] [PATCH 4/5] i965: Handle Y-tiled modifier

2017-03-20 Thread Ben Widawsky

On 17-03-20 12:00:44, Jason Ekstrand wrote:

On Fri, Mar 17, 2017 at 5:34 PM, Ben Widawsky  wrote:


This patch begins introducing how we'll actually handle the potentially
many modifiers coming in from the API, how we'll store them, and the
structure in the code to support it.

Prior to this patch, the Y-tiled modifier would be entirely ignored. It
shouldn't actually be used until this point because we've not bumped the
DRIimage extension version (which is a requirement to use modifiers).

With X-tiling:
Writes:  6,583.58 MiB
Reads:   6,540.93 MiB

With Y-tiling:
Writes:  5,361.78 MiB
Reads6,052.45 MiB

Savings per frame
Writes:  2 MiB
Reads:  .8 MiB

Similar functionality was introduced and then reverted here:

commit 6a0d036483caf87d43ebe2edd1905873446c9589
Author: Ben Widawsky 
Date:   Thu Apr 21 20:14:58 2016 -0700

i965: Always use Y-tiled buffers on SKL+

v2: Use last set bit instead of first set bit in modifiers to address
bug found by Daniel Stone.

Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom 
Acked-by: Daniel Stone 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 55

 1 file changed, 49 insertions(+), 6 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c
b/src/mesa/drivers/dri/i965/intel_screen.c
index 22ab3a30b6..1954757d1e 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -23,6 +23,7 @@
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */

+#include 
 #include 
 #include 
 #include 
@@ -520,16 +521,35 @@ select_best_modifier(struct gen_device_info *devinfo,
  const uint64_t *modifiers,
  const unsigned count)
 {
-   uint64_t modifier = DRM_FORMAT_MOD_INVALID;
+#define YTILE  (1 << 1)
+#define LINEAR (1 << 0)
+
+   const uint64_t prio_modifiers[] = { I915_FORMAT_MOD_Y_TILED,
DRM_FORMAT_MOD_LINEAR };
+   uint32_t modifier_bitmask = 0; /* API only allows 32 */



The bitfield thing is still confusing to me.  Here's an idea on how we
could maybe make it better.

enum modifier_priority {
  MODIFIER_PRIORITY_LINEAR,
  MODIFIER_PRIORITY_X,
  MODIFIER_PRIORITY_Y,
  MODIFIER_PRIORITY_Y_CCS,
};

uint32_t priority_to_modifier[] = {
  [MODIFIER_PRIORITY_LINEAR] = DRM_FORMAT_MOD_LINEAR,
  [MODIFIER_PRIORITY_X] = I915_FORMAT_MOD_X_TILED,
  [MODIFIER_PRIORITY_Y] = I915_FORMAT_MOD_Y_TILED,
  [MODIFIER_PRIORITY_Y_CCS] = I915_FORMAT_MOD_Y_TILED_CCS,
}

enum modier_priority prio = 0;
for (int i = 0; i < count; i++) {
  switch (modifiers[i]) {
  case DRM_FORMAT_MOD_LINEAR:
 prio = MAX2(prio, MODIFIER_PRIORITY_LINEAR);
 break;

  case DRM_FORMAT_MOD_X_TILED:
 prio = MAX2(prio, MODIFIER_PRIORITY_X);
 break;

  case DRM_FORMAT_MOD_Y_TILED:
 prio = MAX2(prio, MODIFIER_PRIORITY_Y);
 break;

  case DRM_FORMAT_MOD_Y_TILIED_CCS:
 prio = MAX2(prio, MODIFIER_PRIORITY_Y_CCS);
 break;
}

return priority_to_modifier[prio];

How does this strike your fancy?  I'm ok with the bit set approach if you
really prefer it but I find it hard to reason about.



I don't really prefer. This looks pretty good. Seems no less complex to me, but
I wrote the first one, so perhaps I'm partial.

Originally, I had some code in the equivalent function (before select_best was
separate) which would try fallbacks, ie. if Y tiled allocation failed, it'd go
down to the next modifier just walking down the bits, but logic is now gone, so
there isn't really a point in the bitmask.

Will respin with this and the fixes meant below.





for (int i = 0; i < count; i++) {
   switch (modifiers[i]) {
   case DRM_FORMAT_MOD_LINEAR:
- return modifiers[i];
+ modifier_bitmask |= LINEAR;
+ break;
+  case I915_FORMAT_MOD_Y_TILED:
+ if (devinfo->gen < 9) {
+_mesa_warning(NULL, "Invalid Y-tiling parameter\n");
+continue;



This isn't invalid.  It's just invalid for scanout.  If you wanted to
create an image to share between two GL implementations, Y-tiling works
fine on everything.




As a general function to support modifiers, you are correct, however since this
is only called for image creation, I believe the existing warning is correct.


+ }
+
+ modifier_bitmask |= YTILE;
+ break;
   }
}

-   return modifier;
+   if (modifier_bitmask)
+  return prio_modifiers[util_last_bit64(modifier_bitmask)-1];
+
+   return DRM_FORMAT_MOD_INVALID;
+
+#undef LINEAR
+#undef YTILE
 }

 static __DRIimage *
@@ -560,6 +580,9 @@ intel_create_image_common(__DRIscreen *dri_screen,
case DRM_FORMAT_MOD_LINEAR:
   tiling = I915_TILING_NONE;
   break;
+   case I915_FORMAT_MOD_Y_TILED:
+  tiling = I915_TILING_Y;
+  break;
case DRM_FORMAT_MOD_INVALID:
default:
  break;
@@ -611,8 +634,26 @@ intel_create_image_w

[Mesa-dev] [PATCH 6/5] i965: Turn on support for image modifiers

2017-03-18 Thread Ben Widawsky
All the plumbing is in place so the extension just needs to be
advertised.

Signed-off-by: Ben Widawsky 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index ca725d9202..1ff18b30e4 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -948,7 +948,7 @@ intel_from_planar(__DRIimage *parent, int plane, void 
*loaderPrivate)
 }
 
 static const __DRIimageExtension intelImageExtension = {
-.base = { __DRI_IMAGE, 13 },
+.base = { __DRI_IMAGE, 14 },
 
 .createImageFromName= intel_create_image_from_name,
 .createImageFromRenderbuffer= intel_create_image_from_renderbuffer,
-- 
2.12.0

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


[Mesa-dev] [PATCH 1/5] i965/dri: Store the screen associated with the image

2017-03-17 Thread Ben Widawsky
I intend to need to get to the devinfo structure, and storing the screen
is an easy way to do that.

It seems to be the consensus that you cannot share an image between
multiple screens.

Scape-goat: Rob Clark 
Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom 
Acked-by: Daniel Stone 
---
 src/mesa/drivers/dri/i965/intel_image.h  |  1 +
 src/mesa/drivers/dri/i965/intel_screen.c | 16 ++--
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_image.h 
b/src/mesa/drivers/dri/i965/intel_image.h
index 9b3816efd1..fd63919b2d 100644
--- a/src/mesa/drivers/dri/i965/intel_image.h
+++ b/src/mesa/drivers/dri/i965/intel_image.h
@@ -65,6 +65,7 @@ struct intel_image_format {
 };
 
 struct __DRIimageRec {
+   struct intel_screen *screen;
drm_intel_bo *bo;
uint32_t pitch; /**< in bytes */
GLenum internal_format;
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 81cb0deabb..742a272b7b 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -323,7 +323,8 @@ static boolean intel_lookup_fourcc(int dri_format, int 
*fourcc)
 }
 
 static __DRIimage *
-intel_allocate_image(int dri_format, void *loaderPrivate)
+intel_allocate_image(struct intel_screen *screen, int dri_format,
+ void *loaderPrivate)
 {
 __DRIimage *image;
 
@@ -331,6 +332,7 @@ intel_allocate_image(int dri_format, void *loaderPrivate)
 if (image == NULL)
return NULL;
 
+image->screen = screen;
 image->dri_format = dri_format;
 image->offset = 0;
 
@@ -381,7 +383,7 @@ intel_create_image_from_name(__DRIscreen *dri_screen,
 __DRIimage *image;
 int cpp;
 
-image = intel_allocate_image(format, loaderPrivate);
+image = intel_allocate_image(screen, format, loaderPrivate);
 if (image == NULL)
return NULL;
 
@@ -554,7 +556,7 @@ intel_create_image_common(__DRIscreen *dri_screen,
if (use & __DRI_IMAGE_USE_LINEAR)
   tiling = I915_TILING_NONE;
 
-   image = intel_allocate_image(format, loaderPrivate);
+   image = intel_allocate_image(screen, format, loaderPrivate);
if (image == NULL)
   return NULL;
 
@@ -737,9 +739,11 @@ intel_create_image_from_fds(__DRIscreen *dri_screen,
   return NULL;
 
if (f->nplanes == 1)
-  image = intel_allocate_image(f->planes[0].dri_format, loaderPrivate);
+  image = intel_allocate_image(screen, f->planes[0].dri_format,
+   loaderPrivate);
else
-  image = intel_allocate_image(__DRI_IMAGE_FORMAT_NONE, loaderPrivate);
+  image = intel_allocate_image(screen, __DRI_IMAGE_FORMAT_NONE,
+   loaderPrivate);
 
if (image == NULL)
   return NULL;
@@ -842,7 +846,7 @@ intel_from_planar(__DRIimage *parent, int plane, void 
*loaderPrivate)
 offset = parent->offsets[index];
 stride = parent->strides[index];
 
-image = intel_allocate_image(dri_format, loaderPrivate);
+image = intel_allocate_image(parent->screen, dri_format, loaderPrivate);
 if (image == NULL)
return NULL;
 
-- 
2.12.0

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


[Mesa-dev] [PATCH 5/5] i965: Handle X-tiled modifier

2017-03-17 Thread Ben Widawsky
This doesn't really "do" anything because the default tiling for the
winsys buffer is X tiled. We do however want the X tiled modifier to
work correctly from the API perspective, which would imply that if you
set this modifier, and later do a get_modifier, you get back at least X
tiled.

v2: priority lits was in reverse order.

Cc: Kristian Høgsberg 
Signed-off-by: Ben Widawsky 
Acked-by: Daniel Stone 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 16 ++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 1954757d1e..ca725d9202 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -521,10 +521,14 @@ select_best_modifier(struct gen_device_info *devinfo,
  const uint64_t *modifiers,
  const unsigned count)
 {
-#define YTILE  (1 << 1)
+#define YTILE  (1 << 2)
+#define XTILE  (1 << 1)
 #define LINEAR (1 << 0)
 
-   const uint64_t prio_modifiers[] = { I915_FORMAT_MOD_Y_TILED, 
DRM_FORMAT_MOD_LINEAR };
+   const uint64_t prio_modifiers[] = {
+  DRM_FORMAT_MOD_LINEAR,
+  I915_FORMAT_MOD_X_TILED,
+  I915_FORMAT_MOD_Y_TILED};
uint32_t modifier_bitmask = 0; /* API only allows 32 */
 
for (int i = 0; i < count; i++) {
@@ -532,6 +536,9 @@ select_best_modifier(struct gen_device_info *devinfo,
   case DRM_FORMAT_MOD_LINEAR:
  modifier_bitmask |= LINEAR;
  break;
+  case I915_FORMAT_MOD_X_TILED:
+ modifier_bitmask |= XTILE;
+ break;
   case I915_FORMAT_MOD_Y_TILED:
  if (devinfo->gen < 9) {
 _mesa_warning(NULL, "Invalid Y-tiling parameter\n");
@@ -549,6 +556,7 @@ select_best_modifier(struct gen_device_info *devinfo,
return DRM_FORMAT_MOD_INVALID;
 
 #undef LINEAR
+#undef XTILE
 #undef YTILE
 }
 
@@ -577,6 +585,9 @@ intel_create_image_common(__DRIscreen *dri_screen,
 
uint64_t modifier = select_best_modifier(&screen->devinfo, modifiers, 
count);
switch (modifier) {
+   case I915_FORMAT_MOD_X_TILED:
+  assert(tiling == I915_TILING_X);
+  break;
case DRM_FORMAT_MOD_LINEAR:
   tiling = I915_TILING_NONE;
   break;
@@ -641,6 +652,7 @@ intel_create_image_with_modifiers(__DRIscreen *dri_screen,
for (int i = 0; i < count; i++) {
   switch (modifiers[i]) {
   case I915_FORMAT_MOD_Y_TILED:
+  case I915_FORMAT_MOD_X_TILED:
   case DRM_FORMAT_MOD_LINEAR:
  local_mods[local_count++] = modifiers[i];
  break;
-- 
2.12.0

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


[Mesa-dev] [PATCH 3/5] i965: Handle the linear fb modifier

2017-03-17 Thread Ben Widawsky
At image creation create a path for dealing with the linear modifier.
This works exactly like the old usage flags where __DRI_IMAGE_USE_LINEAR
was specified.

During development of this patch series, it was decided that a lack of
modifier was an insufficient way to express the required modifiers. As a
result, 0 was repurposed to mean a modifier for a LINEAR layout.

NOTE: This patch was added for v3 of the patch series.

References: https://patchwork.kernel.org/patch/9419157/
Signed-off-by: Ben Widawsky 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 35 
 1 file changed, 27 insertions(+), 8 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 7429603e86..22ab3a30b6 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -45,6 +45,10 @@
 #define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
 #endif
 
+#ifndef DRM_FORMAT_MOD_LINEAR
+#define DRM_FORMAT_MOD_LINEAR 0
+#endif
+
 static const __DRIconfigOptionsExtension brw_config_options = {
.base = { __DRI_CONFIG_OPTIONS, 1 },
.xml =
@@ -516,8 +520,16 @@ select_best_modifier(struct gen_device_info *devinfo,
  const uint64_t *modifiers,
  const unsigned count)
 {
-   /* Modifiers are not supported by this DRI driver */
-   return DRM_FORMAT_MOD_INVALID;
+   uint64_t modifier = DRM_FORMAT_MOD_INVALID;
+
+   for (int i = 0; i < count; i++) {
+  switch (modifiers[i]) {
+  case DRM_FORMAT_MOD_LINEAR:
+ return modifiers[i];
+  }
+   }
+
+   return modifier;
 }
 
 static __DRIimage *
@@ -530,7 +542,10 @@ intel_create_image_common(__DRIscreen *dri_screen,
 {
__DRIimage *image;
struct intel_screen *screen = dri_screen->driverPrivate;
-   uint32_t tiling;
+   /* Historically, X-tiled was the default, and so lack of modifier means
+* X-tiled.
+*/
+   uint32_t tiling = I915_TILING_X;
int cpp;
unsigned long pitch;
 
@@ -541,12 +556,15 @@ intel_create_image_common(__DRIscreen *dri_screen,
assert(!(use && count));
 
uint64_t modifier = select_best_modifier(&screen->devinfo, modifiers, 
count);
-   assert(modifier == DRM_FORMAT_MOD_INVALID);
+   switch (modifier) {
+   case DRM_FORMAT_MOD_LINEAR:
+  tiling = I915_TILING_NONE;
+  break;
+   case DRM_FORMAT_MOD_INVALID:
+   default:
+ break;
+   }
 
-   /* Historically, X-tiled was the default, and so lack of modifier means
-* X-tiled.
-*/
-   tiling = I915_TILING_X;
if (use & __DRI_IMAGE_USE_CURSOR) {
   if (width != 64 || height != 64)
 return NULL;
@@ -571,6 +589,7 @@ intel_create_image_common(__DRIscreen *dri_screen,
image->width = width;
image->height = height;
image->pitch = pitch;
+   image->modifier = modifier;
 
return image;
 }
-- 
2.12.0

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


[Mesa-dev] [PATCH 4/5] i965: Handle Y-tiled modifier

2017-03-17 Thread Ben Widawsky
This patch begins introducing how we'll actually handle the potentially
many modifiers coming in from the API, how we'll store them, and the
structure in the code to support it.

Prior to this patch, the Y-tiled modifier would be entirely ignored. It
shouldn't actually be used until this point because we've not bumped the
DRIimage extension version (which is a requirement to use modifiers).

With X-tiling:
Writes:  6,583.58 MiB
Reads:   6,540.93 MiB

With Y-tiling:
Writes:  5,361.78 MiB
Reads6,052.45 MiB

Savings per frame
Writes:  2 MiB
Reads:  .8 MiB

Similar functionality was introduced and then reverted here:

commit 6a0d036483caf87d43ebe2edd1905873446c9589
Author: Ben Widawsky 
Date:   Thu Apr 21 20:14:58 2016 -0700

i965: Always use Y-tiled buffers on SKL+

v2: Use last set bit instead of first set bit in modifiers to address
bug found by Daniel Stone.

Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom 
Acked-by: Daniel Stone 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 55 
 1 file changed, 49 insertions(+), 6 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 22ab3a30b6..1954757d1e 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -23,6 +23,7 @@
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -520,16 +521,35 @@ select_best_modifier(struct gen_device_info *devinfo,
  const uint64_t *modifiers,
  const unsigned count)
 {
-   uint64_t modifier = DRM_FORMAT_MOD_INVALID;
+#define YTILE  (1 << 1)
+#define LINEAR (1 << 0)
+
+   const uint64_t prio_modifiers[] = { I915_FORMAT_MOD_Y_TILED, 
DRM_FORMAT_MOD_LINEAR };
+   uint32_t modifier_bitmask = 0; /* API only allows 32 */
 
for (int i = 0; i < count; i++) {
   switch (modifiers[i]) {
   case DRM_FORMAT_MOD_LINEAR:
- return modifiers[i];
+ modifier_bitmask |= LINEAR;
+ break;
+  case I915_FORMAT_MOD_Y_TILED:
+ if (devinfo->gen < 9) {
+_mesa_warning(NULL, "Invalid Y-tiling parameter\n");
+continue;
+ }
+
+ modifier_bitmask |= YTILE;
+ break;
   }
}
 
-   return modifier;
+   if (modifier_bitmask)
+  return prio_modifiers[util_last_bit64(modifier_bitmask)-1];
+
+   return DRM_FORMAT_MOD_INVALID;
+
+#undef LINEAR
+#undef YTILE
 }
 
 static __DRIimage *
@@ -560,6 +580,9 @@ intel_create_image_common(__DRIscreen *dri_screen,
case DRM_FORMAT_MOD_LINEAR:
   tiling = I915_TILING_NONE;
   break;
+   case I915_FORMAT_MOD_Y_TILED:
+  tiling = I915_TILING_Y;
+  break;
case DRM_FORMAT_MOD_INVALID:
default:
  break;
@@ -611,8 +634,26 @@ intel_create_image_with_modifiers(__DRIscreen *dri_screen,
   const unsigned count,
   void *loaderPrivate)
 {
-   return intel_create_image_common(dri_screen, width, height, format, 0, NULL,
-0, loaderPrivate);
+   uint64_t local_mods[count];
+   int local_count = 0;
+
+   /* This compacts the actual modifiers to the ones we know how to handle */
+   for (int i = 0; i < count; i++) {
+  switch (modifiers[i]) {
+  case I915_FORMAT_MOD_Y_TILED:
+  case DRM_FORMAT_MOD_LINEAR:
+ local_mods[local_count++] = modifiers[i];
+ break;
+  case DRM_FORMAT_MOD_INVALID:
+ unreachable("Invalid modifiers specified\n");
+  default:
+ /* Modifiers from other vendors would land here. */
+ break;
+  }
+   }
+
+   return intel_create_image_common(dri_screen, width, height, format, 0,
+local_mods, local_count, loaderPrivate);
 }
 
 static GLboolean
@@ -1867,7 +1908,9 @@ intelAllocateBuffer(__DRIscreen *dri_screen,
if (intelBuffer == NULL)
   return NULL;
 
-   /* The front and back buffers are color buffers, which are X tiled. */
+   /* The front and back buffers are color buffers, which are X tiled. GEN9+
+* supports Y tiled and compressed buffers, but there is no way to plumb 
that
+* through to here. */
uint32_t tiling = I915_TILING_X;
unsigned long pitch;
int cpp = format / 8;
-- 
2.12.0

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


[Mesa-dev] [PATCH 0/5] i965 tiling modifiers

2017-03-17 Thread Ben Widawsky
This was the third chunk of the Renderbuffer Decompression series (aka GBM
modifiers). Splitting this up to make merging easier. These patches are plumbing
through the existing modifiers (up to the new CCS ones).

After this series we should support Y-tiled modifiers properly, thus allowing
the modesetting driver, and Weston (and other GBM clients) to use Y tiled
scanout buffers on gen9+.

Ben Widawsky (5):
  i965/dri: Store the screen associated with the image
  i965: Enable modifier queries
  i965: Handle the linear fb modifier
  i965: Handle Y-tiled modifier
  i965: Handle X-tiled modifier

 src/mesa/drivers/dri/i965/intel_image.h  |   2 +
 src/mesa/drivers/dri/i965/intel_screen.c | 116 ++-
 2 files changed, 102 insertions(+), 16 deletions(-)

-- 
2.12.0

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


[Mesa-dev] [PATCH 2/5] i965: Enable modifier queries

2017-03-17 Thread Ben Widawsky
New to the patch series after reordering things for landing smaller
chunks.

This will essentially enable modifiers from clients that were just
enabled in previous patches. A client could use the modifiers by
setting all of them at create, but had no way to actually query them
after creating the surface (ie. stupid clients could be broken before
this patch, but in more ways than this).

Obviously, there are no modifiers being actually stored yet - so this
patch shouldn't do anything other than allow the API to get back 0 (or
the LINEAR modifier).

Signed-off-by: Ben Widawsky 
---
 src/mesa/drivers/dri/i965/intel_image.h  | 1 +
 src/mesa/drivers/dri/i965/intel_screen.c | 6 ++
 2 files changed, 7 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/intel_image.h 
b/src/mesa/drivers/dri/i965/intel_image.h
index fd63919b2d..a362c76689 100644
--- a/src/mesa/drivers/dri/i965/intel_image.h
+++ b/src/mesa/drivers/dri/i965/intel_image.h
@@ -71,6 +71,7 @@ struct __DRIimageRec {
GLenum internal_format;
uint32_t dri_format;
GLuint format;
+   uint64_t modifier; /**< fb modifier (fourcc) */
uint32_t offset;
 
/*
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 742a272b7b..7429603e86 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -632,6 +632,12 @@ intel_query_image(__DRIimage *image, int attrib, int 
*value)
case __DRI_IMAGE_ATTRIB_OFFSET:
   *value = image->offset;
   return true;
+   case __DRI_IMAGE_ATTRIB_MODIFIER_LOWER:
+  *value = (image->modifier & 0x);
+  return true;
+   case __DRI_IMAGE_ATTRIB_MODIFIER_UPPER:
+  *value = ((image->modifier >> 32) & 0x);
+  return true;
 
   default:
   return false;
-- 
2.12.0

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


[Mesa-dev] [PATCH 3/6] [v6] gbm: Introduce modifiers into surface/bo creation

2017-03-14 Thread Ben Widawsky
The idea behind modifiers like this is that the user of GBM will have
some mechanism to query what properties the hardware supports for its BO
or surface. This information is directly passed in (and stored) so that
the DRI implementation can create an image with the appropriate
attributes.

A getter() will be added later so that the user GBM will be able to
query what modifier should be used.

Only in surface creation, the modifiers are stored until the BO is
actually allocated. In regular buffer allocation, the correct modifier
can (will be, in future patches be chosen at creation time.

v2: Make sure to check if count is non-zero in addition to testing if
calloc fails. (Daniel)

v3: Remove "usage" and "flags" from modifier creation. Requested by
Kristian.

v4: Take advantage of the "INVALID" modifier added by the GET_PLANE2
series.

v5: Don't bother with storing modifiers for gbm_bo_create because that's
a synchronous operation and we can actually select the correct modifier
at create time (done in a later patch) (Jason)

v6: Make modifier condition outside the check so that dri_use will work
properly (Jason)

Cc: Kristian Høgsberg 
References (v4): 
https://lists.freedesktop.org/archives/intel-gfx/2017-January/116636.html
Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom  (v1)
Reviewed-by: Jason Ekstrand 
Acked-by: Daniel Stone 
---
 src/gbm/backends/dri/gbm_dri.c | 63 --
 src/gbm/gbm-symbols-check  |  2 ++
 src/gbm/main/gbm.c | 39 --
 src/gbm/main/gbm.h | 12 
 src/gbm/main/gbmint.h  | 12 ++--
 5 files changed, 116 insertions(+), 12 deletions(-)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index 7106dc1229..cb3bfe1c2f 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -1023,13 +1023,20 @@ free_bo:
 static struct gbm_bo *
 gbm_dri_bo_create(struct gbm_device *gbm,
   uint32_t width, uint32_t height,
-  uint32_t format, uint32_t usage)
+  uint32_t format, uint32_t usage,
+  const uint64_t *modifiers,
+  const unsigned int count)
 {
struct gbm_dri_device *dri = gbm_dri_device(gbm);
struct gbm_dri_bo *bo;
int dri_format;
unsigned dri_use = 0;
 
+   /* Callers of this may specify a modifier, or a dri usage, but not both. The
+* newer modifier interface deprecates the older usage flags.
+*/
+   assert(!(usage && count));
+
if (usage & GBM_BO_USE_WRITE || dri->image == NULL)
   return create_dumb(gbm, width, height, format, usage);
 
@@ -1087,11 +1094,25 @@ gbm_dri_bo_create(struct gbm_device *gbm,
/* Gallium drivers requires shared in order to get the handle/stride */
dri_use |= __DRI_IMAGE_USE_SHARE;
 
-   bo->image =
-  dri->image->createImage(dri->screen,
-  width, height,
-  dri_format, dri_use,
-  bo);
+   if (modifiers) {
+  if (!dri->image || dri->image->base.version < 14 ||
+  !dri->image->createImageWithModifiers) {
+ fprintf(stderr, "Modifiers specified, but DRI is too old\n");
+ errno = ENOSYS;
+ goto failed;
+  }
+
+  bo->image =
+ dri->image->createImageWithModifiers(dri->screen,
+  width, height,
+  dri_format,
+  modifiers, count,
+  bo);
+   } else {
+  bo->image = dri->image->createImage(dri->screen, width, height,
+  dri_format, dri_use, bo);
+   }
+
if (bo->image == NULL)
   goto failed;
 
@@ -1165,19 +1186,44 @@ gbm_dri_bo_unmap(struct gbm_bo *_bo, void *map_data)
 static struct gbm_surface *
 gbm_dri_surface_create(struct gbm_device *gbm,
uint32_t width, uint32_t height,
-  uint32_t format, uint32_t flags)
+  uint32_t format, uint32_t flags,
+   const uint64_t *modifiers, const unsigned count)
 {
+   struct gbm_dri_device *dri = gbm_dri_device(gbm);
struct gbm_dri_surface *surf;
 
+   if (modifiers &&
+   (!dri->image || dri->image->base.version < 14 ||
+!dri->image->createImageWithModifiers)) {
+  errno = ENOSYS;
+  return NULL;
+   }
+
surf = calloc(1, sizeof *surf);
-   if (surf == NULL)
+   if (surf == NULL) {
+  errno = ENOMEM;
   return NULL;
+   }
 
surf->base.gbm = gbm;
surf->base.width = width;
surf->base.height = height;
surf->base.format = format;
surf->base.flags = flags;
+   if (!modifiers) {
+  assert(!count

Re: [Mesa-dev] [PATCH 3/6] gbm: Introduce modifiers into surface/bo creation

2017-03-14 Thread Ben Widawsky

On 17-03-14 13:31:01, Ben Widawsky wrote:

On 17-03-14 08:53:45, Jason Ekstrand wrote:

On Mon, Mar 13, 2017 at 10:24 PM, Ben Widawsky  wrote:


The idea behind modifiers like this is that the user of GBM will have
some mechanism to query what properties the hardware supports for its BO
or surface. This information is directly passed in (and stored) so that
the DRI implementation can create an image with the appropriate
attributes.

A getter() will be added later so that the user GBM will be able to
query what modifier should be used.

Only in surface creation, the modifiers are stored until the BO is
actually allocated. In regular buffer allocation, the correct modifier
can (will be, in future patches be chosen at creation time.

v2: Make sure to check if count is non-zero in addition to testing if
calloc fails. (Daniel)

v3: Remove "usage" and "flags" from modifier creation. Requested by
Kristian.

v4: Take advantage of the "INVALID" modifier added by the GET_PLANE2
series.

v5: Don't bother with storing modifiers for gbm_bo_create because that's
a synchronous operation and we can actually select the correct modifier
at create time (done in a later patch) (Jason)

Cc: Kristian Høgsberg 
Cc: Jason Ekstrand 
References (v4): https://lists.freedesktop.org/archives/intel-gfx/2017-
January/116636.html
Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom  (v1)
Acked-by: Daniel Stone 
---
src/gbm/backends/dri/gbm_dri.c | 62 ++
++--
src/gbm/gbm-symbols-check  |  2 ++
src/gbm/main/gbm.c | 39 --
src/gbm/main/gbm.h | 12 
src/gbm/main/gbmint.h  | 12 ++--
5 files changed, 115 insertions(+), 12 deletions(-)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_
dri.c
index 7106dc1229..1224ce4476 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -1023,13 +1023,20 @@ free_bo:
static struct gbm_bo *
gbm_dri_bo_create(struct gbm_device *gbm,
  uint32_t width, uint32_t height,
-  uint32_t format, uint32_t usage)
+  uint32_t format, uint32_t usage,
+  const uint64_t *modifiers,
+  const unsigned int count)
{
   struct gbm_dri_device *dri = gbm_dri_device(gbm);
   struct gbm_dri_bo *bo;
   int dri_format;
   unsigned dri_use = 0;

+   /* Callers of this may specify a modifier, or a dri usage, but not
both. The
+* newer modifier interface deprecates the older usage flags.
+*/
+   assert(!(usage && count));
+
   if (usage & GBM_BO_USE_WRITE || dri->image == NULL)
  return create_dumb(gbm, width, height, format, usage);

@@ -1087,11 +1094,24 @@ gbm_dri_bo_create(struct gbm_device *gbm,
   /* Gallium drivers requires shared in order to get the handle/stride */
   dri_use |= __DRI_IMAGE_USE_SHARE;

-   bo->image =
-  dri->image->createImage(dri->screen,
-  width, height,
-  dri_format, dri_use,
-  bo);
+   if (!dri->image || dri->image->base.version < 14 ||
+   !dri->image->createImageWithModifiers) {
+  if (modifiers) {



This logic still isn't correct.  As written, it will always call
createImageWithModifiers if it's available even if no modifiers are
provided.  I think you want the "if (modifiers)" to be the outside bit of
control-flow




I don't see a problem here. Calling createImageWithModifiers without modifiers
(provided count is correct) is a perfectly acceptable thing to do.



Oh dri_use is probably going to get missed. NVM me. I'll fix this.


+ fprintf(stderr, "Modifiers specified, but DRI is too old\n");
+ errno = ENOSYS;
+ goto failed;
+  }
+
+  bo->image = dri->image->createImage(dri->screen, width, height,
+  dri_format, dri_use, bo);
+   } else {
+  bo->image =
+ dri->image->createImageWithModifiers(dri->screen,
+  width, height,
+  dri_format,
+  modifiers, count,
+  bo);
+   }
   if (bo->image == NULL)
  goto failed;

@@ -1165,19 +1185,44 @@ gbm_dri_bo_unmap(struct gbm_bo *_bo, void
*map_data)
static struct gbm_surface *
gbm_dri_surface_create(struct gbm_device *gbm,
   uint32_t width, uint32_t height,
-  uint32_t format, uint32_t flags)
+  uint32_t format, uint32_t flags,
+   const uint64_t *modifiers, const unsigned count)
{
+   struct gbm_dri_device *dri = gbm_dri_device(gbm);
   struct gbm_dri_surface *surf;

+   if (modifiers &&
+   (!dri->image || dri-

Re: [Mesa-dev] [PATCH 3/6] gbm: Introduce modifiers into surface/bo creation

2017-03-14 Thread Ben Widawsky

On 17-03-14 08:53:45, Jason Ekstrand wrote:

On Mon, Mar 13, 2017 at 10:24 PM, Ben Widawsky  wrote:


The idea behind modifiers like this is that the user of GBM will have
some mechanism to query what properties the hardware supports for its BO
or surface. This information is directly passed in (and stored) so that
the DRI implementation can create an image with the appropriate
attributes.

A getter() will be added later so that the user GBM will be able to
query what modifier should be used.

Only in surface creation, the modifiers are stored until the BO is
actually allocated. In regular buffer allocation, the correct modifier
can (will be, in future patches be chosen at creation time.

v2: Make sure to check if count is non-zero in addition to testing if
calloc fails. (Daniel)

v3: Remove "usage" and "flags" from modifier creation. Requested by
Kristian.

v4: Take advantage of the "INVALID" modifier added by the GET_PLANE2
series.

v5: Don't bother with storing modifiers for gbm_bo_create because that's
a synchronous operation and we can actually select the correct modifier
at create time (done in a later patch) (Jason)

Cc: Kristian Høgsberg 
Cc: Jason Ekstrand 
References (v4): https://lists.freedesktop.org/archives/intel-gfx/2017-
January/116636.html
Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom  (v1)
Acked-by: Daniel Stone 
---
 src/gbm/backends/dri/gbm_dri.c | 62 ++
++--
 src/gbm/gbm-symbols-check  |  2 ++
 src/gbm/main/gbm.c | 39 --
 src/gbm/main/gbm.h | 12 
 src/gbm/main/gbmint.h  | 12 ++--
 5 files changed, 115 insertions(+), 12 deletions(-)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_
dri.c
index 7106dc1229..1224ce4476 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -1023,13 +1023,20 @@ free_bo:
 static struct gbm_bo *
 gbm_dri_bo_create(struct gbm_device *gbm,
   uint32_t width, uint32_t height,
-  uint32_t format, uint32_t usage)
+  uint32_t format, uint32_t usage,
+  const uint64_t *modifiers,
+  const unsigned int count)
 {
struct gbm_dri_device *dri = gbm_dri_device(gbm);
struct gbm_dri_bo *bo;
int dri_format;
unsigned dri_use = 0;

+   /* Callers of this may specify a modifier, or a dri usage, but not
both. The
+* newer modifier interface deprecates the older usage flags.
+*/
+   assert(!(usage && count));
+
if (usage & GBM_BO_USE_WRITE || dri->image == NULL)
   return create_dumb(gbm, width, height, format, usage);

@@ -1087,11 +1094,24 @@ gbm_dri_bo_create(struct gbm_device *gbm,
/* Gallium drivers requires shared in order to get the handle/stride */
dri_use |= __DRI_IMAGE_USE_SHARE;

-   bo->image =
-  dri->image->createImage(dri->screen,
-  width, height,
-  dri_format, dri_use,
-  bo);
+   if (!dri->image || dri->image->base.version < 14 ||
+   !dri->image->createImageWithModifiers) {
+  if (modifiers) {



This logic still isn't correct.  As written, it will always call
createImageWithModifiers if it's available even if no modifiers are
provided.  I think you want the "if (modifiers)" to be the outside bit of
control-flow




I don't see a problem here. Calling createImageWithModifiers without modifiers
(provided count is correct) is a perfectly acceptable thing to do.


+ fprintf(stderr, "Modifiers specified, but DRI is too old\n");
+ errno = ENOSYS;
+ goto failed;
+  }
+
+  bo->image = dri->image->createImage(dri->screen, width, height,
+  dri_format, dri_use, bo);
+   } else {
+  bo->image =
+ dri->image->createImageWithModifiers(dri->screen,
+  width, height,
+  dri_format,
+  modifiers, count,
+  bo);
+   }
if (bo->image == NULL)
   goto failed;

@@ -1165,19 +1185,44 @@ gbm_dri_bo_unmap(struct gbm_bo *_bo, void
*map_data)
 static struct gbm_surface *
 gbm_dri_surface_create(struct gbm_device *gbm,
uint32_t width, uint32_t height,
-  uint32_t format, uint32_t flags)
+  uint32_t format, uint32_t flags,
+   const uint64_t *modifiers, const unsigned count)
 {
+   struct gbm_dri_device *dri = gbm_dri_device(gbm);
struct gbm_dri_surface *surf;

+   if (modifiers &&
+   (!dri->image || dri->image->base.version < 14 ||
+!dri->image->createImageWithModifiers)

[Mesa-dev] [PATCH 4/6] egl/drm: Use modifiers for backbuffer creation

2017-03-13 Thread Ben Widawsky
Split into a separate patch from the previous patch as requested by
Emil.

Requeted-by: Emil Velikov 
Signed-off-by: Ben Widawsky 
---
 src/egl/drivers/dri2/platform_drm.c | 19 +++
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_drm.c 
b/src/egl/drivers/dri2/platform_drm.c
index e5e8c60596..cf35ce8a1f 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -230,10 +230,21 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
 
if (dri2_surf->back == NULL)
   return -1;
-   if (dri2_surf->back->bo == NULL)
-  dri2_surf->back->bo = gbm_bo_create(&dri2_dpy->gbm_dri->base.base,
- surf->base.width, surf->base.height,
- surf->base.format, surf->base.flags);
+   if (dri2_surf->back->bo == NULL) {
+  if (surf->base.modifiers)
+ dri2_surf->back->bo = 
gbm_bo_create_with_modifiers(&dri2_dpy->gbm_dri->base.base,
+surf->base.width, 
surf->base.height,
+surf->base.format,
+
surf->base.modifiers,
+surf->base.count);
+  else
+ dri2_surf->back->bo = gbm_bo_create(&dri2_dpy->gbm_dri->base.base,
+ surf->base.width,
+ surf->base.height,
+ surf->base.format,
+ surf->base.flags);
+
+   }
if (dri2_surf->back->bo == NULL)
   return -1;
 
-- 
2.12.0

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


[Mesa-dev] [PATCH 1/6] dri: Add an image creation with modifiers

2017-03-13 Thread Ben Widawsky
Modifiers will be obtained or guessed by the client and passed in during
image creation/import. In guessing, a client might decide to simply pass
along all known modifiers

This requires bumping the DRIimage version.

As of this patch, the modifiers aren't plumbed all the way down, this
patch simply makes sure the interface level stuff is correct.

v2: Don't allow usage + modifiers

v3: Make NAND actually NAND. Bug introduced in v2. (Jason)

v4:
- s/obtains/obtained (Jason)
- Pull out i965 imlemnentation into a later patch (Emil)

Cc: Jason Ekstrand 
Cc: Emil Velikov 
Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom  (v1)
Acked-by: Daniel Stone 
---
 include/GL/internal/dri_interface.h | 27 ++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index 598d111f33..53fac6fc3c 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1136,7 +1136,7 @@ struct __DRIdri2ExtensionRec {
  * extensions.
  */
 #define __DRI_IMAGE "DRI_IMAGE"
-#define __DRI_IMAGE_VERSION 13
+#define __DRI_IMAGE_VERSION 14
 
 /**
  * These formats correspond to the similarly named MESA_FORMAT_*
@@ -1257,6 +1257,8 @@ struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_ATTRIB_NUM_PLANES   0x2009 /* available in versions 11 */
 
 #define __DRI_IMAGE_ATTRIB_OFFSET 0x200A /* available in versions 13 */
+#define __DRI_IMAGE_ATTRIB_MODIFIER_LOWER 0x200B /* available in versions 14 */
+#define __DRI_IMAGE_ATTRIB_MODIFIER_UPPER 0x200C /* available in versions 14 */
 
 enum __DRIYUVColorSpace {
__DRI_YUV_COLOR_SPACE_UNDEFINED = 0,
@@ -1468,6 +1470,29 @@ struct __DRIimageExtensionRec {
 */
void (*unmapImage)(__DRIcontext *context, __DRIimage *image, void *data);
 
+
+   /**
+* Creates an image with implementation's favorite modifiers.
+*
+* This acts like createImage except there is a list of modifiers passed in
+* which the implementation may selectively use to create the DRIimage. The
+* result should be the implementation selects one modifier (perhaps it 
would
+* hold on to a few and later pick).
+*
+* The created image should be destroyed with destroyImage().
+*
+* Returns the new DRIimage. The chosen modifier can be obtained later on
+* and passed back to things like the kernel's AddFB2 interface.
+*
+* \sa __DRIimageRec::createImage
+*
+* \since 14
+*/
+   __DRIimage *(*createImageWithModifiers)(__DRIscreen *screen,
+   int width, int height, int format,
+   const uint64_t *modifiers,
+   const unsigned int modifier_count,
+   void *loaderPrivate);
 };
 
 
-- 
2.12.0

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


[Mesa-dev] [PATCH 2/6] i965: Implement basic modifier image creation

2017-03-13 Thread Ben Widawsky
This is just a stub for now and will be filled in later.

This was split out of an earlier patch

Requested-by: Emil Velikov 
Signed-off-by: Ben Widawsky 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 38 
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 21786eb54a..39289967cd 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -510,10 +510,12 @@ intel_destroy_image(__DRIimage *image)
 }
 
 static __DRIimage *
-intel_create_image(__DRIscreen *dri_screen,
-  int width, int height, int format,
-  unsigned int use,
-  void *loaderPrivate)
+intel_create_image_common(__DRIscreen *dri_screen,
+  int width, int height, int format,
+  unsigned int use,
+  const uint64_t *modifiers,
+  unsigned count,
+  void *loaderPrivate)
 {
__DRIimage *image;
struct intel_screen *screen = dri_screen->driverPrivate;
@@ -521,6 +523,12 @@ intel_create_image(__DRIscreen *dri_screen,
int cpp;
unsigned long pitch;
 
+   /* Callers of this may specify a modifier, or a dri usage, but not both. The
+* newer modifier interface deprecates the older usage flags newer modifier
+* interface deprecates the older usage flags.
+*/
+   assert(!(use && count));
+
tiling = I915_TILING_X;
if (use & __DRI_IMAGE_USE_CURSOR) {
   if (width != 64 || height != 64)
@@ -550,6 +558,27 @@ intel_create_image(__DRIscreen *dri_screen,
return image;
 }
 
+static __DRIimage *
+intel_create_image(__DRIscreen *dri_screen,
+  int width, int height, int format,
+  unsigned int use,
+  void *loaderPrivate)
+{
+   return intel_create_image_common(dri_screen, width, height, format, use, 
NULL, 0,
+   loaderPrivate);
+}
+
+static __DRIimage *
+intel_create_image_with_modifiers(__DRIscreen *dri_screen,
+  int width, int height, int format,
+  const uint64_t *modifiers,
+  const unsigned count,
+  void *loaderPrivate)
+{
+   return intel_create_image_common(dri_screen, width, height, format, 0, NULL,
+0, loaderPrivate);
+}
+
 static GLboolean
 intel_query_image(__DRIimage *image, int attrib, int *value)
 {
@@ -840,6 +869,7 @@ static const __DRIimageExtension intelImageExtension = {
 .getCapabilities= NULL,
 .mapImage   = NULL,
 .unmapImage = NULL,
+.createImageWithModifiers   = intel_create_image_with_modifiers,
 };
 
 static int
-- 
2.12.0

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


[Mesa-dev] [PATCH 3/6] gbm: Introduce modifiers into surface/bo creation

2017-03-13 Thread Ben Widawsky
The idea behind modifiers like this is that the user of GBM will have
some mechanism to query what properties the hardware supports for its BO
or surface. This information is directly passed in (and stored) so that
the DRI implementation can create an image with the appropriate
attributes.

A getter() will be added later so that the user GBM will be able to
query what modifier should be used.

Only in surface creation, the modifiers are stored until the BO is
actually allocated. In regular buffer allocation, the correct modifier
can (will be, in future patches be chosen at creation time.

v2: Make sure to check if count is non-zero in addition to testing if
calloc fails. (Daniel)

v3: Remove "usage" and "flags" from modifier creation. Requested by
Kristian.

v4: Take advantage of the "INVALID" modifier added by the GET_PLANE2
series.

v5: Don't bother with storing modifiers for gbm_bo_create because that's
a synchronous operation and we can actually select the correct modifier
at create time (done in a later patch) (Jason)

Cc: Kristian Høgsberg 
Cc: Jason Ekstrand 
References (v4): 
https://lists.freedesktop.org/archives/intel-gfx/2017-January/116636.html
Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom  (v1)
Acked-by: Daniel Stone 
---
 src/gbm/backends/dri/gbm_dri.c | 62 --
 src/gbm/gbm-symbols-check  |  2 ++
 src/gbm/main/gbm.c | 39 --
 src/gbm/main/gbm.h | 12 
 src/gbm/main/gbmint.h  | 12 ++--
 5 files changed, 115 insertions(+), 12 deletions(-)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index 7106dc1229..1224ce4476 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -1023,13 +1023,20 @@ free_bo:
 static struct gbm_bo *
 gbm_dri_bo_create(struct gbm_device *gbm,
   uint32_t width, uint32_t height,
-  uint32_t format, uint32_t usage)
+  uint32_t format, uint32_t usage,
+  const uint64_t *modifiers,
+  const unsigned int count)
 {
struct gbm_dri_device *dri = gbm_dri_device(gbm);
struct gbm_dri_bo *bo;
int dri_format;
unsigned dri_use = 0;
 
+   /* Callers of this may specify a modifier, or a dri usage, but not both. The
+* newer modifier interface deprecates the older usage flags.
+*/
+   assert(!(usage && count));
+
if (usage & GBM_BO_USE_WRITE || dri->image == NULL)
   return create_dumb(gbm, width, height, format, usage);
 
@@ -1087,11 +1094,24 @@ gbm_dri_bo_create(struct gbm_device *gbm,
/* Gallium drivers requires shared in order to get the handle/stride */
dri_use |= __DRI_IMAGE_USE_SHARE;
 
-   bo->image =
-  dri->image->createImage(dri->screen,
-  width, height,
-  dri_format, dri_use,
-  bo);
+   if (!dri->image || dri->image->base.version < 14 ||
+   !dri->image->createImageWithModifiers) {
+  if (modifiers) {
+ fprintf(stderr, "Modifiers specified, but DRI is too old\n");
+ errno = ENOSYS;
+ goto failed;
+  }
+
+  bo->image = dri->image->createImage(dri->screen, width, height,
+  dri_format, dri_use, bo);
+   } else {
+  bo->image =
+ dri->image->createImageWithModifiers(dri->screen,
+  width, height,
+  dri_format,
+  modifiers, count,
+  bo);
+   }
if (bo->image == NULL)
   goto failed;
 
@@ -1165,19 +1185,44 @@ gbm_dri_bo_unmap(struct gbm_bo *_bo, void *map_data)
 static struct gbm_surface *
 gbm_dri_surface_create(struct gbm_device *gbm,
uint32_t width, uint32_t height,
-  uint32_t format, uint32_t flags)
+  uint32_t format, uint32_t flags,
+   const uint64_t *modifiers, const unsigned count)
 {
+   struct gbm_dri_device *dri = gbm_dri_device(gbm);
struct gbm_dri_surface *surf;
 
+   if (modifiers &&
+   (!dri->image || dri->image->base.version < 14 ||
+!dri->image->createImageWithModifiers)) {
+  errno = ENOSYS;
+  return NULL;
+   }
+
surf = calloc(1, sizeof *surf);
-   if (surf == NULL)
+   if (surf == NULL) {
+  errno = ENOMEM;
   return NULL;
+   }
 
surf->base.gbm = gbm;
surf->base.width = width;
surf->base.height = height;
surf->base.format = format;
surf->base.flags = flags;
+   if (!modifiers) {
+  assert(!count);
+  return &surf->base;
+   }
+
+   surf->base.modifiers = calloc(count, sizeo

[Mesa-dev] [PATCH 6/6] gbm: Export a get modifiers

2017-03-13 Thread Ben Widawsky
This patch originally had i965 specific code and was named:
commit 61cd3c52b868cf8cb90b06e53a382a921eb42754
Author: Ben Widawsky 
Date:   Thu Oct 20 18:21:24 2016 -0700

gbm: Get modifiers from DRI

To accomplish this, two new query tokens are added to the extension:
__DRI_IMAGE_ATTRIB_MODIFIER_UPPER
__DRI_IMAGE_ATTRIB_MODIFIER_LOWER

The query extension only supported 32b queries, and modifiers are 64b,
so we needed two of them.

NOTE: The extension version is still set to 13, so none of this will
actually be called.

v2: Error handling of queryImage (Emil)

Signed-off-by: Ben Widawsky 
Reviewed-by: Jason Ekstrand 
Reviewed-by: Emil Velikov 
---
 src/gbm/backends/dri/gbm_dri.c | 42 ++
 src/gbm/gbm-symbols-check  |  1 +
 src/gbm/main/gbm.c | 19 +++
 src/gbm/main/gbm.h |  3 +++
 src/gbm/main/gbmint.h  |  1 +
 5 files changed, 66 insertions(+)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index 1224ce4476..dbeb3ad907 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -39,6 +39,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include  /* dri_interface needs GL types */
 #include 
@@ -53,6 +54,14 @@
 #include "../../../egl/wayland/wayland-drm/wayland-drm.h"
 #endif
 
+#ifndef DRM_FORMAT_MOD_INVALID
+#define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
+#endif
+
+#ifndef DRM_FORMAT_MOD_LINEAR
+#define DRM_FORMAT_MOD_LINEAR 0
+#endif
+
 static __DRIimage *
 dri_lookup_egl_image(__DRIscreen *screen, void *image, void *data)
 {
@@ -735,6 +744,38 @@ gbm_dri_bo_get_offset(struct gbm_bo *_bo, int plane)
return (uint32_t)offset;
 }
 
+static uint64_t
+gbm_dri_bo_get_modifier(struct gbm_bo *_bo)
+{
+   struct gbm_dri_device *dri = gbm_dri_device(_bo->gbm);
+   struct gbm_dri_bo *bo = gbm_dri_bo(_bo);
+
+   if (!dri->image || dri->image->base.version < 14) {
+  errno = ENOSYS;
+  return DRM_FORMAT_MOD_INVALID;
+   }
+
+   /* Dumb buffers have no modifiers */
+   if (!bo->image)
+  return DRM_FORMAT_MOD_LINEAR;
+
+   uint64_t ret = 0;
+   int mod;
+   if (!dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_MODIFIER_UPPER,
+   &mod))
+  return DRM_FORMAT_MOD_INVALID;
+
+   ret = (uint64_t)mod << 32;
+
+   if (!dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_MODIFIER_LOWER,
+   &mod))
+  return DRM_FORMAT_MOD_INVALID;
+
+   ret |= mod;
+
+   return ret;
+}
+
 static void
 gbm_dri_bo_destroy(struct gbm_bo *_bo)
 {
@@ -1277,6 +1318,7 @@ dri_device_create(int fd)
dri->base.base.bo_get_handle = gbm_dri_bo_get_handle_for_plane;
dri->base.base.bo_get_stride = gbm_dri_bo_get_stride;
dri->base.base.bo_get_offset = gbm_dri_bo_get_offset;
+   dri->base.base.bo_get_modifier = gbm_dri_bo_get_modifier;
dri->base.base.bo_destroy = gbm_dri_bo_destroy;
dri->base.base.destroy = dri_destroy;
dri->base.base.surface_create = gbm_dri_surface_create;
diff --git a/src/gbm/gbm-symbols-check b/src/gbm/gbm-symbols-check
index 0550baddc4..6a9af0c59d 100755
--- a/src/gbm/gbm-symbols-check
+++ b/src/gbm/gbm-symbols-check
@@ -23,6 +23,7 @@ gbm_bo_get_handle
 gbm_bo_get_fd
 gbm_bo_get_plane_count
 gbm_bo_get_handle_for_plane
+gbm_bo_get_modifier
 gbm_bo_write
 gbm_bo_set_user_data
 gbm_bo_get_user_data
diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c
index 7bacd8b86a..19dc5db901 100644
--- a/src/gbm/main/gbm.c
+++ b/src/gbm/main/gbm.c
@@ -280,6 +280,25 @@ gbm_bo_get_handle_for_plane(struct gbm_bo *bo, int plane)
return bo->gbm->bo_get_handle(bo, plane);
 }
 
+/**
+ * Get the chosen modifier for the buffer object
+ *
+ * This function returns the modifier that was chosen for the object. These
+ * properties may be generic, or platform/implementation dependent.
+ *
+ * \param bo The buffer object
+ * \return Returns the selected modifier (chosen by the implementation) for the
+ * BO.
+ * \sa gbm_bo_create_with_modifiers() where possible modifiers are set
+ * \sa gbm_surface_create_with_modifiers() where possible modifiers are set
+ * \sa define DRM_FORMAT_MOD_* in drm_fourcc.h for possible modifiers
+ */
+GBM_EXPORT uint64_t
+gbm_bo_get_modifier(struct gbm_bo *bo)
+{
+   return bo->gbm->bo_get_modifier(bo);
+}
+
 /** Write data into the buffer object
  *
  * If the buffer object was created with the GBM_BO_USE_WRITE flag,
diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h
index 5f588dab58..a774b50951 100644
--- a/src/gbm/main/gbm.h
+++ b/src/gbm/main/gbm.h
@@ -327,6 +327,9 @@ gbm_bo_get_handle(struct gbm_bo *bo);
 int
 gbm_bo_get_fd(struct gbm_bo *bo);
 
+uint64_t
+gbm_bo_get_modifier(struct gbm_bo *bo);
+
 int
 gbm_bo_get_plane_count(struct gbm_bo *bo);
 
diff --git a/src/gbm/main/gbmint.h b/src/gbm/main/gbmint.h
index d8c9f6e5d7..5ad85cc80f 100644
--- a/src/gbm/main

[Mesa-dev] [PATCH 5/6] i965: introduce modifier selection.

2017-03-13 Thread Ben Widawsky
Nothing special here other than a brief introduction to modifier
selection. Originally this was part of another patch but was split out
from
gbm: Introduce modifiers into surface/bo creation by request of Emil.

Requested-by: Emil Velikov 
Signed-off-by: Ben Widawsky 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 39289967cd..cc695d383b 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -41,6 +41,10 @@
 #include "utils.h"
 #include "xmlpool.h"
 
+#ifndef DRM_FORMAT_MOD_INVALID
+#define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
+#endif
+
 static const __DRIconfigOptionsExtension brw_config_options = {
.base = { __DRI_CONFIG_OPTIONS, 1 },
.xml =
@@ -509,6 +513,15 @@ intel_destroy_image(__DRIimage *image)
free(image);
 }
 
+static uint64_t
+select_best_modifier(struct gen_device_info *devinfo,
+ const uint64_t *modifiers,
+ const unsigned count)
+{
+   /* Modifiers are not supported by this DRI driver */
+   return DRM_FORMAT_MOD_INVALID;
+}
+
 static __DRIimage *
 intel_create_image_common(__DRIscreen *dri_screen,
   int width, int height, int format,
@@ -529,6 +542,12 @@ intel_create_image_common(__DRIscreen *dri_screen,
 */
assert(!(use && count));
 
+   uint64_t modifier = select_best_modifier(&screen->devinfo, modifiers, 
count);
+   assert(modifier == DRM_FORMAT_MOD_INVALID);
+
+   /* Historically, X-tiled was the default, and so lack of modifier means
+* X-tiled.
+*/
tiling = I915_TILING_X;
if (use & __DRI_IMAGE_USE_CURSOR) {
   if (width != 64 || height != 64)
-- 
2.12.0

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


Re: [Mesa-dev] [PATCH 2/3] gbm: Introduce modifiers into surface/bo creation

2017-03-13 Thread Ben Widawsky

On 17-03-10 11:32:35, Emil Velikov wrote:

On 10 March 2017 at 01:48, Ben Widawsky  wrote:

The idea behind modifiers like this is that the user of GBM will have
some mechanism to query what properties the hardware supports for its BO
or surface. This information is directly passed in (and stored) so that
the DRI implementation can create an image with the appropriate
attributes.

A getter() will be added later so that the user GBM will be able to
query what modifier should be used.

Only in surface creation, the modifiers are stored until the BO is
actually allocated. In regular buffer allocation, the correct modifier
can (will be, in future patches be chosen at creation time.

v2: Make sure to check if count is non-zero in addition to testing if
calloc fails. (Daniel)

v3: Remove "usage" and "flags" from modifier creation. Requested by
Kristian.

v4: Take advantage of the "INVALID" modifier added by the GET_PLANE2
series.

v5: Don't bother with storing modifiers for gbm_bo_create because that's
a synchronous operation and we can actually select the correct modifier
at create time (done in a later patch) (Jason)

Cc: Kristian Høgsberg 
Cc: Jason Ekstrand 
References (v4): 
https://lists.freedesktop.org/archives/intel-gfx/2017-January/116636.html
Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom  (v1)
Acked-by: Daniel Stone 



---
 src/egl/drivers/dri2/platform_drm.c  | 19 ---

Worth splitting the patches - patch N+1


 src/gbm/backends/dri/gbm_dri.c   | 42 ++--
 src/gbm/gbm-symbols-check|  2 ++
 src/gbm/main/gbm.c   | 29 --
 src/gbm/main/gbm.h   | 12 +
 src/gbm/main/gbmint.h| 12 +++--

Patch N


 src/mesa/drivers/dri/i965/intel_screen.c | 18 ++

Patch N+Y


--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -1023,13 +1023,20 @@ free_bo:
 static struct gbm_bo *
 gbm_dri_bo_create(struct gbm_device *gbm,
   uint32_t width, uint32_t height,
-  uint32_t format, uint32_t usage)
+  uint32_t format, uint32_t usage,
+  const uint64_t *modifiers,
+  const unsigned int count)
 {
struct gbm_dri_device *dri = gbm_dri_device(gbm);
struct gbm_dri_bo *bo;
int dri_format;
unsigned dri_use = 0;

+   /* Callers of this may specify a modifier, or a dri usage, but not both. The
+* newer modifier interface deprecates the older usage flags.
+*/
+   assert(!(usage && count));
+

Similar to last patch - XOR ?



I don't believe so, I still think NAND is right, but I guess I can't say
indisputably that dri_use == 0 is valid.


if (usage & GBM_BO_USE_WRITE || dri->image == NULL)
   return create_dumb(gbm, width, height, format, usage);

@@ -1087,11 +1094,21 @@ gbm_dri_bo_create(struct gbm_device *gbm,
/* Gallium drivers requires shared in order to get the handle/stride */
dri_use |= __DRI_IMAGE_USE_SHARE;

-   bo->image =
-  dri->image->createImage(dri->screen,
-  width, height,
-  dri_format, dri_use,
-  bo);
+   if (!dri->image || dri->image->base.version < 14 ||
+   !dri->image->createImageWithModifiers) {
+  if (modifiers)
+ fprintf(stderr, "Modifiers specified, but DRI is too old\n");
+
+  bo->image = dri->image->createImage(dri->screen, width, height,
+  dri_format, dri_use, bo);

With the "modifiers or use" above how do we get sane value for dri_use
in this fall-back ?
Seems like things we'll miss/ignore the scanout/curson/linear flags.

Perhaps it's worth simply bailing out ?



Yes, I think you're right. Jason said basically the same thing, but the way
you've presented it, it's more obvious to me that baling out is the right thing
to do.

So I've changed this locally.

Same thing basically for gbm_dri_surface_create()




--- a/src/gbm/gbm-symbols-check
+++ b/src/gbm/gbm-symbols-check



+gbm_bo_create_with_modifiers



+gbm_surface_create_with_modifiers

Thank you :-)



+GBM_EXPORT struct gbm_bo *
+gbm_bo_create_with_modifiers(struct gbm_device *gbm,
+ uint32_t width, uint32_t height,
+ uint32_t format,
+ const uint64_t *modifiers,
+ const unsigned int count)
+{
+   if (width == 0 || height == 0) {
+  errno = EINVAL;
+  return NULL;
+   }
+

Should we validate modifiers and/or count at this level as well ?




Yeah, I suppose that makes sense. I got this change locally.

I honestly think almost no validation should be done at this level so that the
implementation can do whate

Re: [Mesa-dev] [PATCH 2/3] gbm: Introduce modifiers into surface/bo creation

2017-03-13 Thread Ben Widawsky

On 17-03-09 18:52:52, Jason Ekstrand wrote:

On Thu, Mar 9, 2017 at 5:48 PM, Ben Widawsky  wrote:


The idea behind modifiers like this is that the user of GBM will have
some mechanism to query what properties the hardware supports for its BO
or surface. This information is directly passed in (and stored) so that
the DRI implementation can create an image with the appropriate
attributes.

A getter() will be added later so that the user GBM will be able to
query what modifier should be used.

Only in surface creation, the modifiers are stored until the BO is
actually allocated. In regular buffer allocation, the correct modifier
can (will be, in future patches be chosen at creation time.

v2: Make sure to check if count is non-zero in addition to testing if
calloc fails. (Daniel)

v3: Remove "usage" and "flags" from modifier creation. Requested by
Kristian.

v4: Take advantage of the "INVALID" modifier added by the GET_PLANE2
series.

v5: Don't bother with storing modifiers for gbm_bo_create because that's
a synchronous operation and we can actually select the correct modifier
at create time (done in a later patch) (Jason)

Cc: Kristian Høgsberg 
Cc: Jason Ekstrand 
References (v4): https://lists.freedesktop.org/
archives/intel-gfx/2017-January/116636.html
Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom  (v1)
Acked-by: Daniel Stone 
---
 src/egl/drivers/dri2/platform_drm.c  | 19 ---
 src/gbm/backends/dri/gbm_dri.c   | 42
++--
 src/gbm/gbm-symbols-check|  2 ++
 src/gbm/main/gbm.c   | 29 --
 src/gbm/main/gbm.h   | 12 +
 src/gbm/main/gbmint.h| 12 +++--
 src/mesa/drivers/dri/i965/intel_screen.c | 18 ++
 7 files changed, 119 insertions(+), 15 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_drm.c
b/src/egl/drivers/dri2/platform_drm.c
index e5e8c60596..cf35ce8a1f 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -230,10 +230,21 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)

if (dri2_surf->back == NULL)
   return -1;
-   if (dri2_surf->back->bo == NULL)
-  dri2_surf->back->bo = gbm_bo_create(&dri2_dpy->gbm_dri->base.base,
- surf->base.width,
surf->base.height,
- surf->base.format,
surf->base.flags);
+   if (dri2_surf->back->bo == NULL) {
+  if (surf->base.modifiers)
+ dri2_surf->back->bo = gbm_bo_create_with_modifiers(&
dri2_dpy->gbm_dri->base.base,
+
surf->base.width, surf->base.height,
+
surf->base.format,
+
surf->base.modifiers,
+
surf->base.count);
+  else
+ dri2_surf->back->bo = gbm_bo_create(&dri2_dpy->gbm_d
ri->base.base,
+ surf->base.width,
+ surf->base.height,
+ surf->base.format,
+ surf->base.flags);
+
+   }
if (dri2_surf->back->bo == NULL)
   return -1;

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri
.c
index 7106dc1229..d45ba94080 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -1023,13 +1023,20 @@ free_bo:
 static struct gbm_bo *
 gbm_dri_bo_create(struct gbm_device *gbm,
   uint32_t width, uint32_t height,
-  uint32_t format, uint32_t usage)
+  uint32_t format, uint32_t usage,
+  const uint64_t *modifiers,
+  const unsigned int count)
 {
struct gbm_dri_device *dri = gbm_dri_device(gbm);
struct gbm_dri_bo *bo;
int dri_format;
unsigned dri_use = 0;

+   /* Callers of this may specify a modifier, or a dri usage, but not
both. The
+* newer modifier interface deprecates the older usage flags.
+*/
+   assert(!(usage && count));
+
if (usage & GBM_BO_USE_WRITE || dri->image == NULL)
   return create_dumb(gbm, width, height, format, usage);

@@ -1087,11 +1094,21 @@ gbm_dri_bo_create(struct gbm_device *gbm,
/* Gallium drivers requires shared in order to get the handle/stride */
dri_use |= __DRI_IMAGE_USE_SHARE;

-   bo->image =
-  dri->image->createImage(dri->screen,
-  width, height,
-  dri_format, dri_use,
-  bo);
+   if (!dri->image || dri->image->base.version < 14 ||
+   !dri->image->createImageWithModifiers) {
+  if (modifiers)
+ fprintf(stderr, "Modifiers specified, but DRI is too old\n");



This seems a bit on the sketchy side.  Do we want to fail, set errno to
ENOSYS, and return NULL in t

Re: [Mesa-dev] [PATCH 2/3] gbm: Introduce modifiers into surface/bo creation

2017-03-13 Thread Ben Widawsky

On 17-03-10 11:34:19, Jason Ekstrand wrote:

On Thu, Mar 9, 2017 at 6:52 PM, Jason Ekstrand  wrote:


On Thu, Mar 9, 2017 at 5:48 PM, Ben Widawsky  wrote:


The idea behind modifiers like this is that the user of GBM will have
some mechanism to query what properties the hardware supports for its BO
or surface. This information is directly passed in (and stored) so that
the DRI implementation can create an image with the appropriate
attributes.

A getter() will be added later so that the user GBM will be able to
query what modifier should be used.

Only in surface creation, the modifiers are stored until the BO is
actually allocated. In regular buffer allocation, the correct modifier
can (will be, in future patches be chosen at creation time.

v2: Make sure to check if count is non-zero in addition to testing if
calloc fails. (Daniel)

v3: Remove "usage" and "flags" from modifier creation. Requested by
Kristian.

v4: Take advantage of the "INVALID" modifier added by the GET_PLANE2
series.

v5: Don't bother with storing modifiers for gbm_bo_create because that's
a synchronous operation and we can actually select the correct modifier
at create time (done in a later patch) (Jason)

Cc: Kristian Høgsberg 
Cc: Jason Ekstrand 
References (v4): https://lists.freedesktop.org/
archives/intel-gfx/2017-January/116636.html
Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom  (v1)
Acked-by: Daniel Stone 
---
 src/egl/drivers/dri2/platform_drm.c  | 19 ---
 src/gbm/backends/dri/gbm_dri.c   | 42
++--
 src/gbm/gbm-symbols-check|  2 ++
 src/gbm/main/gbm.c   | 29 --
 src/gbm/main/gbm.h   | 12 +
 src/gbm/main/gbmint.h| 12 +++--
 src/mesa/drivers/dri/i965/intel_screen.c | 18 ++
 7 files changed, 119 insertions(+), 15 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_drm.c
b/src/egl/drivers/dri2/platform_drm.c
index e5e8c60596..cf35ce8a1f 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -230,10 +230,21 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)

if (dri2_surf->back == NULL)
   return -1;
-   if (dri2_surf->back->bo == NULL)
-  dri2_surf->back->bo = gbm_bo_create(&dri2_dpy->gbm_dri->base.base,
- surf->base.width,
surf->base.height,
- surf->base.format,
surf->base.flags);
+   if (dri2_surf->back->bo == NULL) {
+  if (surf->base.modifiers)
+ dri2_surf->back->bo = gbm_bo_create_with_modifiers(&
dri2_dpy->gbm_dri->base.base,
+
surf->base.width, surf->base.height,
+
surf->base.format,
+
surf->base.modifiers,
+
surf->base.count);
+  else
+ dri2_surf->back->bo = gbm_bo_create(&dri2_dpy->gbm_d
ri->base.base,
+ surf->base.width,
+ surf->base.height,
+ surf->base.format,
+ surf->base.flags);
+
+   }
if (dri2_surf->back->bo == NULL)
   return -1;

diff --git a/src/gbm/backends/dri/gbm_dri.c
b/src/gbm/backends/dri/gbm_dri.c
index 7106dc1229..d45ba94080 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -1023,13 +1023,20 @@ free_bo:
 static struct gbm_bo *
 gbm_dri_bo_create(struct gbm_device *gbm,
   uint32_t width, uint32_t height,
-  uint32_t format, uint32_t usage)
+  uint32_t format, uint32_t usage,
+  const uint64_t *modifiers,
+  const unsigned int count)
 {
struct gbm_dri_device *dri = gbm_dri_device(gbm);
struct gbm_dri_bo *bo;
int dri_format;
unsigned dri_use = 0;

+   /* Callers of this may specify a modifier, or a dri usage, but not
both. The
+* newer modifier interface deprecates the older usage flags.
+*/
+   assert(!(usage && count));
+
if (usage & GBM_BO_USE_WRITE || dri->image == NULL)
   return create_dumb(gbm, width, height, format, usage);

@@ -1087,11 +1094,21 @@ gbm_dri_bo_create(struct gbm_device *gbm,
/* Gallium drivers requires shared in order to get the handle/stride
*/
dri_use |= __DRI_IMAGE_USE_SHARE;

-   bo->image =
-  dri->image->createImage(dri->screen,
-  width, height,
-  dri_format, dri_use,
-  bo);
+   if (!dri->image || dri->image->base.version < 14 ||
+   !dri->image->createImageWithModifiers) {
+  if (modifiers)
+ fprintf(stderr, "Modifiers specified, but DRI is too old\n");



This seems a bit on the sketchy si

Re: [Mesa-dev] [PATCH 1/3] dri: Add an image creation with modifiers

2017-03-13 Thread Ben Widawsky

On 17-03-10 10:28:42, Emil Velikov wrote:

Hi Ben,

Mostly pointing out a few things that look strange, pardon if some
seem too pedantic.

On 10 March 2017 at 01:48, Ben Widawsky  wrote:


---
 include/GL/internal/dri_interface.h  | 27 ++-

Split the Infra from the i965 implementation ?



Sure. Doesn't matter to me.


 src/gallium/state_trackers/dri/dri2.c|  1 +

Not needed.



Yeah, whoops.


 src/mesa/drivers/dri/i965/intel_screen.c | 32 +++-

Patch should come as/after __DRI_IMAGE_ATTRIB_MODIFIER_* are honoured.
Or modifiers and modifiers count in general.



Assuming this also means split the infra from implementation, sure.


--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -1413,6 +1413,7 @@ static __DRIimageExtension dri2ImageExtension = {
 .getCapabilities  = dri2_get_capabilities,
 .mapImage = dri2_map_image,
 .unmapImage   = dri2_unmap_image,
+.createImageWithModifiers = NULL,
 };


Not needed - drop ?




Gone.


diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 21786eb54a..3452572874 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -510,9 +510,11 @@ intel_destroy_image(__DRIimage *image)
 }

 static __DRIimage *
-intel_create_image(__DRIscreen *dri_screen,
+__intel_create_image(__DRIscreen *dri_screen,

Don't think there's (m)any functions that start with __ in 965.
Perhaps append "_common" ?




Sure.


int cpp;
unsigned long pitch;

+   /* Callers of this may specify a modifier, or a dri usage, but not both. The
+* newer modifier interface deprecates the older usage flags newer modifier
+* interface deprecates the older usage flags.
+*/
+   assert(!(use && count));
+

What would happen if we don't have either old (use) or new (modifiers) ?
Shouldn't this be XOR ?



Not having either is fine. It's like the previous case of supporting use flags
but passing in none, which is allowed.




@@ -840,6 +869,7 @@ static const __DRIimageExtension intelImageExtension = {

Afaict, nothing in this series bumps the version to 14.
So you either missed a patch or we have a bug somewhere ?



Well, it bumps the version in dri_interface.h. Formerly, before splitting things
up, this patch had the i965 version bumped too, but that's gone now. I'm happy
to reword this however you'd like.


-Emil

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


Re: [Mesa-dev] [PATCH 1/3] dri: Add an image creation with modifiers

2017-03-13 Thread Ben Widawsky

On 17-03-09 18:38:15, Jason Ekstrand wrote:

On Thu, Mar 9, 2017 at 5:48 PM, Ben Widawsky  wrote:


Modifiers will be obtains or guessed by the client and passed in during



"obtained"




Got it.


image creation/import.

This requires bumping the DRIimage version.

As of this patch, the modifiers aren't plumbed all the way down, this
patch simply makes sure the interface level stuff is correct.

v2: Don't allow usage + modifiers

v3: Make NAND actually NAND. Bug introduced in v2. (Jason)

Cc: Kristian Høgsberg 
Cc: Jason Ekstrand 
Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom  (v1)
Acked-by: Daniel Stone 
---
 include/GL/internal/dri_interface.h  | 27 ++-
 src/gallium/state_trackers/dri/dri2.c|  1 +
 src/mesa/drivers/dri/i965/intel_screen.c | 32
+++-
 3 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/include/GL/internal/dri_interface.h
b/include/GL/internal/dri_interface.h
index 598d111f33..53fac6fc3c 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1136,7 +1136,7 @@ struct __DRIdri2ExtensionRec {
  * extensions.
  */
 #define __DRI_IMAGE "DRI_IMAGE"
-#define __DRI_IMAGE_VERSION 13
+#define __DRI_IMAGE_VERSION 14

 /**
  * These formats correspond to the similarly named MESA_FORMAT_*
@@ -1257,6 +1257,8 @@ struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_ATTRIB_NUM_PLANES   0x2009 /* available in versions
11 */

 #define __DRI_IMAGE_ATTRIB_OFFSET 0x200A /* available in versions 13 */
+#define __DRI_IMAGE_ATTRIB_MODIFIER_LOWER 0x200B /* available in
versions 14 */
+#define __DRI_IMAGE_ATTRIB_MODIFIER_UPPER 0x200C /* available in
versions 14 */

 enum __DRIYUVColorSpace {
__DRI_YUV_COLOR_SPACE_UNDEFINED = 0,
@@ -1468,6 +1470,29 @@ struct __DRIimageExtensionRec {
 */
void (*unmapImage)(__DRIcontext *context, __DRIimage *image, void
*data);

+
+   /**
+* Creates an image with implementation's favorite modifiers.
+*
+* This acts like createImage except there is a list of modifiers
passed in
+* which the implementation may selectively use to create the
DRIimage. The
+* result should be the implementation selects one modifier (perhaps
it would
+* hold on to a few and later pick).
+*
+* The created image should be destroyed with destroyImage().
+*
+* Returns the new DRIimage. The chosen modifier can be obtained later
on
+* and passed back to things like the kernel's AddFB2 interface.
+*
+* \sa __DRIimageRec::createImage
+*
+* \since 14
+*/
+   __DRIimage *(*createImageWithModifiers)(__DRIscreen *screen,
+   int width, int height, int
format,
+   const uint64_t *modifiers,
+   const unsigned int
modifier_count,
+   void *loaderPrivate);
 };


diff --git a/src/gallium/state_trackers/dri/dri2.c
b/src/gallium/state_trackers/dri/dri2.c
index b50e096443..12e466c6f1 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -1413,6 +1413,7 @@ static __DRIimageExtension dri2ImageExtension = {
 .getCapabilities  = dri2_get_capabilities,
 .mapImage = dri2_map_image,
 .unmapImage   = dri2_unmap_image,
+.createImageWithModifiers = NULL,
 };


diff --git a/src/mesa/drivers/dri/i965/intel_screen.c
b/src/mesa/drivers/dri/i965/intel_screen.c
index 21786eb54a..3452572874 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -510,9 +510,11 @@ intel_destroy_image(__DRIimage *image)
 }

 static __DRIimage *
-intel_create_image(__DRIscreen *dri_screen,
+__intel_create_image(__DRIscreen *dri_screen,
   int width, int height, int format,
   unsigned int use,
+   const uint64_t *modifiers,
+   unsigned count,
   void *loaderPrivate)
 {
__DRIimage *image;
@@ -521,6 +523,12 @@ intel_create_image(__DRIscreen *dri_screen,
int cpp;
unsigned long pitch;

+   /* Callers of this may specify a modifier, or a dri usage, but not
both. The
+* newer modifier interface deprecates the older usage flags newer
modifier
+* interface deprecates the older usage flags.
+*/
+   assert(!(use && count));
+
tiling = I915_TILING_X;
if (use & __DRI_IMAGE_USE_CURSOR) {
   if (width != 64 || height != 64)
@@ -550,6 +558,27 @@ intel_create_image(__DRIscreen *dri_screen,
return image;
 }

+static __DRIimage *
+intel_create_image(__DRIscreen *dri_screen,
+  int width, int height, int format,
+  unsigned int use,
+  void *loaderPrivate)
+{
+   return __intel_create_image(dri_screen, width, height, format, use,
NULL, 0,
+   

[Mesa-dev] [PATCH 1/3] dri: Add an image creation with modifiers

2017-03-09 Thread Ben Widawsky
Modifiers will be obtains or guessed by the client and passed in during
image creation/import.

This requires bumping the DRIimage version.

As of this patch, the modifiers aren't plumbed all the way down, this
patch simply makes sure the interface level stuff is correct.

v2: Don't allow usage + modifiers

v3: Make NAND actually NAND. Bug introduced in v2. (Jason)

Cc: Kristian Høgsberg 
Cc: Jason Ekstrand 
Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom  (v1)
Acked-by: Daniel Stone 
---
 include/GL/internal/dri_interface.h  | 27 ++-
 src/gallium/state_trackers/dri/dri2.c|  1 +
 src/mesa/drivers/dri/i965/intel_screen.c | 32 +++-
 3 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index 598d111f33..53fac6fc3c 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1136,7 +1136,7 @@ struct __DRIdri2ExtensionRec {
  * extensions.
  */
 #define __DRI_IMAGE "DRI_IMAGE"
-#define __DRI_IMAGE_VERSION 13
+#define __DRI_IMAGE_VERSION 14
 
 /**
  * These formats correspond to the similarly named MESA_FORMAT_*
@@ -1257,6 +1257,8 @@ struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_ATTRIB_NUM_PLANES   0x2009 /* available in versions 11 */
 
 #define __DRI_IMAGE_ATTRIB_OFFSET 0x200A /* available in versions 13 */
+#define __DRI_IMAGE_ATTRIB_MODIFIER_LOWER 0x200B /* available in versions 14 */
+#define __DRI_IMAGE_ATTRIB_MODIFIER_UPPER 0x200C /* available in versions 14 */
 
 enum __DRIYUVColorSpace {
__DRI_YUV_COLOR_SPACE_UNDEFINED = 0,
@@ -1468,6 +1470,29 @@ struct __DRIimageExtensionRec {
 */
void (*unmapImage)(__DRIcontext *context, __DRIimage *image, void *data);
 
+
+   /**
+* Creates an image with implementation's favorite modifiers.
+*
+* This acts like createImage except there is a list of modifiers passed in
+* which the implementation may selectively use to create the DRIimage. The
+* result should be the implementation selects one modifier (perhaps it 
would
+* hold on to a few and later pick).
+*
+* The created image should be destroyed with destroyImage().
+*
+* Returns the new DRIimage. The chosen modifier can be obtained later on
+* and passed back to things like the kernel's AddFB2 interface.
+*
+* \sa __DRIimageRec::createImage
+*
+* \since 14
+*/
+   __DRIimage *(*createImageWithModifiers)(__DRIscreen *screen,
+   int width, int height, int format,
+   const uint64_t *modifiers,
+   const unsigned int modifier_count,
+   void *loaderPrivate);
 };
 
 
diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index b50e096443..12e466c6f1 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -1413,6 +1413,7 @@ static __DRIimageExtension dri2ImageExtension = {
 .getCapabilities  = dri2_get_capabilities,
 .mapImage = dri2_map_image,
 .unmapImage   = dri2_unmap_image,
+.createImageWithModifiers = NULL,
 };
 
 
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 21786eb54a..3452572874 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -510,9 +510,11 @@ intel_destroy_image(__DRIimage *image)
 }
 
 static __DRIimage *
-intel_create_image(__DRIscreen *dri_screen,
+__intel_create_image(__DRIscreen *dri_screen,
   int width, int height, int format,
   unsigned int use,
+   const uint64_t *modifiers,
+   unsigned count,
   void *loaderPrivate)
 {
__DRIimage *image;
@@ -521,6 +523,12 @@ intel_create_image(__DRIscreen *dri_screen,
int cpp;
unsigned long pitch;
 
+   /* Callers of this may specify a modifier, or a dri usage, but not both. The
+* newer modifier interface deprecates the older usage flags newer modifier
+* interface deprecates the older usage flags.
+*/
+   assert(!(use && count));
+
tiling = I915_TILING_X;
if (use & __DRI_IMAGE_USE_CURSOR) {
   if (width != 64 || height != 64)
@@ -550,6 +558,27 @@ intel_create_image(__DRIscreen *dri_screen,
return image;
 }
 
+static __DRIimage *
+intel_create_image(__DRIscreen *dri_screen,
+  int width, int height, int format,
+  unsigned int use,
+  void *loaderPrivate)
+{
+   return __intel_create_image(dri_screen, width, height, format, use, NULL, 0,
+   loaderPrivate);
+}
+
+static __DRIimage *
+intel_create_image_with_modifiers(__DRIscreen *dri_screen,
+ 

[Mesa-dev] [PATCH 0/3] GBM modifier plumbing

2017-03-09 Thread Ben Widawsky
This is essential the creation and getter for GBM modifiers (via DRI images).

This was the second chunk of the Renderbuffer Decompression series (aka GBM
modifiers). Splitting this up to make merging easier. These patches are simple
plumbing for getting modifiers through the various GBM functions as well as
exposing the new entry points.

Ben Widawsky (3):
  dri: Add an image creation with modifiers
  gbm: Introduce modifiers into surface/bo creation
  gbm: Export a get modifiers

 include/GL/internal/dri_interface.h  | 27 ++-
 src/egl/drivers/dri2/platform_drm.c  | 19 ++--
 src/gallium/state_trackers/dri/dri2.c|  1 +
 src/gbm/backends/dri/gbm_dri.c   | 78 +---
 src/gbm/gbm-symbols-check|  3 ++
 src/gbm/main/gbm.c   | 48 +++-
 src/gbm/main/gbm.h   | 15 ++
 src/gbm/main/gbmint.h| 13 +-
 src/mesa/drivers/dri/i965/intel_screen.c | 50 +++-
 9 files changed, 237 insertions(+), 17 deletions(-)

-- 
2.12.0

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


[Mesa-dev] [PATCH 3/3] gbm: Export a get modifiers

2017-03-09 Thread Ben Widawsky
This patch originally had i965 specific code and was named:
commit 61cd3c52b868cf8cb90b06e53a382a921eb42754
Author: Ben Widawsky 
Date:   Thu Oct 20 18:21:24 2016 -0700

gbm: Get modifiers from DRI

To accomplish this, two new query tokens are added to the extension:
__DRI_IMAGE_ATTRIB_MODIFIER_UPPER
__DRI_IMAGE_ATTRIB_MODIFIER_LOWER

The query extension only supported 32b queries, and modifiers are 64b,
so we needed two of them.

NOTE: The extension version is still set to 13, so none of this will
actually be called.

Signed-off-by: Ben Widawsky 
---
 src/gbm/backends/dri/gbm_dri.c | 36 
 src/gbm/gbm-symbols-check  |  1 +
 src/gbm/main/gbm.c | 19 +++
 src/gbm/main/gbm.h |  3 +++
 src/gbm/main/gbmint.h  |  1 +
 5 files changed, 60 insertions(+)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index d45ba94080..2c467127c2 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -39,6 +39,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include  /* dri_interface needs GL types */
 #include 
@@ -53,6 +54,14 @@
 #include "../../../egl/wayland/wayland-drm/wayland-drm.h"
 #endif
 
+#ifndef DRM_FORMAT_MOD_INVALID
+#define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
+#endif
+
+#ifndef DRM_FORMAT_MOD_LINEAR
+#define DRM_FORMAT_MOD_LINEAR 0
+#endif
+
 static __DRIimage *
 dri_lookup_egl_image(__DRIscreen *screen, void *image, void *data)
 {
@@ -735,6 +744,32 @@ gbm_dri_bo_get_offset(struct gbm_bo *_bo, int plane)
return (uint32_t)offset;
 }
 
+static uint64_t
+gbm_dri_bo_get_modifier(struct gbm_bo *_bo)
+{
+   struct gbm_dri_device *dri = gbm_dri_device(_bo->gbm);
+   struct gbm_dri_bo *bo = gbm_dri_bo(_bo);
+
+   if (!dri->image || dri->image->base.version < 14) {
+  errno = ENOSYS;
+  return DRM_FORMAT_MOD_INVALID;
+   }
+
+   /* Dumb buffers have no modifiers */
+   if (!bo->image)
+  return DRM_FORMAT_MOD_LINEAR;
+
+   uint64_t ret = 0;
+   int mod;
+   dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_MODIFIER_UPPER, &mod);
+   ret = (uint64_t)mod << 32;
+
+   dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_MODIFIER_LOWER, &mod);
+   ret |= mod;
+
+   return ret;
+}
+
 static void
 gbm_dri_bo_destroy(struct gbm_bo *_bo)
 {
@@ -1259,6 +1294,7 @@ dri_device_create(int fd)
dri->base.base.bo_get_handle = gbm_dri_bo_get_handle_for_plane;
dri->base.base.bo_get_stride = gbm_dri_bo_get_stride;
dri->base.base.bo_get_offset = gbm_dri_bo_get_offset;
+   dri->base.base.bo_get_modifier = gbm_dri_bo_get_modifier;
dri->base.base.bo_destroy = gbm_dri_bo_destroy;
dri->base.base.destroy = dri_destroy;
dri->base.base.surface_create = gbm_dri_surface_create;
diff --git a/src/gbm/gbm-symbols-check b/src/gbm/gbm-symbols-check
index c137c6cd93..c72fb66b03 100755
--- a/src/gbm/gbm-symbols-check
+++ b/src/gbm/gbm-symbols-check
@@ -23,6 +23,7 @@ gbm_bo_get_handle
 gbm_bo_get_fd
 gbm_bo_get_plane_count
 gbm_bo_get_handle_for_plane
+gbm_bo_get_modifier
 gbm_bo_write
 gbm_bo_set_user_data
 gbm_bo_get_user_data
diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c
index 0fb62657ed..7ceaccdc21 100644
--- a/src/gbm/main/gbm.c
+++ b/src/gbm/main/gbm.c
@@ -280,6 +280,25 @@ gbm_bo_get_handle_for_plane(struct gbm_bo *bo, int plane)
return bo->gbm->bo_get_handle(bo, plane);
 }
 
+/**
+ * Get the chosen modifier for the buffer object
+ *
+ * This function returns the modifier that was chosen for the object. These
+ * properties may be generic, or platform/implementation dependent.
+ *
+ * \param bo The buffer object
+ * \return Returns the selected modifier (chosen by the implementation) for the
+ * BO.
+ * \sa gbm_bo_create_with_modifiers() where possible modifiers are set
+ * \sa gbm_surface_create_with_modifiers() where possible modifiers are set
+ * \sa define DRM_FORMAT_MOD_* in drm_fourcc.h for possible modifiers
+ */
+GBM_EXPORT uint64_t
+gbm_bo_get_modifier(struct gbm_bo *bo)
+{
+   return bo->gbm->bo_get_modifier(bo);
+}
+
 /** Write data into the buffer object
  *
  * If the buffer object was created with the GBM_BO_USE_WRITE flag,
diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h
index 5f588dab58..a774b50951 100644
--- a/src/gbm/main/gbm.h
+++ b/src/gbm/main/gbm.h
@@ -327,6 +327,9 @@ gbm_bo_get_handle(struct gbm_bo *bo);
 int
 gbm_bo_get_fd(struct gbm_bo *bo);
 
+uint64_t
+gbm_bo_get_modifier(struct gbm_bo *bo);
+
 int
 gbm_bo_get_plane_count(struct gbm_bo *bo);
 
diff --git a/src/gbm/main/gbmint.h b/src/gbm/main/gbmint.h
index d8c9f6e5d7..5ad85cc80f 100644
--- a/src/gbm/main/gbmint.h
+++ b/src/gbm/main/gbmint.h
@@ -82,6 +82,7 @@ struct gbm_device {
union gbm_bo_handle (*bo_get_handle)(struct gbm_bo *bo, int plane);
uint32_t (*bo_get_stride)(struct gbm_bo *bo, int plane);
int64_t (*bo_get_offset)(struct gbm_bo *bo, int p

[Mesa-dev] [PATCH 2/3] gbm: Introduce modifiers into surface/bo creation

2017-03-09 Thread Ben Widawsky
The idea behind modifiers like this is that the user of GBM will have
some mechanism to query what properties the hardware supports for its BO
or surface. This information is directly passed in (and stored) so that
the DRI implementation can create an image with the appropriate
attributes.

A getter() will be added later so that the user GBM will be able to
query what modifier should be used.

Only in surface creation, the modifiers are stored until the BO is
actually allocated. In regular buffer allocation, the correct modifier
can (will be, in future patches be chosen at creation time.

v2: Make sure to check if count is non-zero in addition to testing if
calloc fails. (Daniel)

v3: Remove "usage" and "flags" from modifier creation. Requested by
Kristian.

v4: Take advantage of the "INVALID" modifier added by the GET_PLANE2
series.

v5: Don't bother with storing modifiers for gbm_bo_create because that's
a synchronous operation and we can actually select the correct modifier
at create time (done in a later patch) (Jason)

Cc: Kristian Høgsberg 
Cc: Jason Ekstrand 
References (v4): 
https://lists.freedesktop.org/archives/intel-gfx/2017-January/116636.html
Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom  (v1)
Acked-by: Daniel Stone 
---
 src/egl/drivers/dri2/platform_drm.c  | 19 ---
 src/gbm/backends/dri/gbm_dri.c   | 42 ++--
 src/gbm/gbm-symbols-check|  2 ++
 src/gbm/main/gbm.c   | 29 --
 src/gbm/main/gbm.h   | 12 +
 src/gbm/main/gbmint.h| 12 +++--
 src/mesa/drivers/dri/i965/intel_screen.c | 18 ++
 7 files changed, 119 insertions(+), 15 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_drm.c 
b/src/egl/drivers/dri2/platform_drm.c
index e5e8c60596..cf35ce8a1f 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -230,10 +230,21 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
 
if (dri2_surf->back == NULL)
   return -1;
-   if (dri2_surf->back->bo == NULL)
-  dri2_surf->back->bo = gbm_bo_create(&dri2_dpy->gbm_dri->base.base,
- surf->base.width, surf->base.height,
- surf->base.format, surf->base.flags);
+   if (dri2_surf->back->bo == NULL) {
+  if (surf->base.modifiers)
+ dri2_surf->back->bo = 
gbm_bo_create_with_modifiers(&dri2_dpy->gbm_dri->base.base,
+surf->base.width, 
surf->base.height,
+surf->base.format,
+
surf->base.modifiers,
+surf->base.count);
+  else
+ dri2_surf->back->bo = gbm_bo_create(&dri2_dpy->gbm_dri->base.base,
+ surf->base.width,
+ surf->base.height,
+ surf->base.format,
+ surf->base.flags);
+
+   }
if (dri2_surf->back->bo == NULL)
   return -1;
 
diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index 7106dc1229..d45ba94080 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -1023,13 +1023,20 @@ free_bo:
 static struct gbm_bo *
 gbm_dri_bo_create(struct gbm_device *gbm,
   uint32_t width, uint32_t height,
-  uint32_t format, uint32_t usage)
+  uint32_t format, uint32_t usage,
+  const uint64_t *modifiers,
+  const unsigned int count)
 {
struct gbm_dri_device *dri = gbm_dri_device(gbm);
struct gbm_dri_bo *bo;
int dri_format;
unsigned dri_use = 0;
 
+   /* Callers of this may specify a modifier, or a dri usage, but not both. The
+* newer modifier interface deprecates the older usage flags.
+*/
+   assert(!(usage && count));
+
if (usage & GBM_BO_USE_WRITE || dri->image == NULL)
   return create_dumb(gbm, width, height, format, usage);
 
@@ -1087,11 +1094,21 @@ gbm_dri_bo_create(struct gbm_device *gbm,
/* Gallium drivers requires shared in order to get the handle/stride */
dri_use |= __DRI_IMAGE_USE_SHARE;
 
-   bo->image =
-  dri->image->createImage(dri->screen,
-  width, height,
-  dri_format, dri_use,
-  bo);
+   if (!dri->image || dri->image->base.version < 14 ||
+   !dri->image->createImageWithModifiers) {
+  if (modifiers)
+ fprintf(stderr, "Modifier

[Mesa-dev] [PATCH 0/3] GBM modifier plumbing

2017-03-09 Thread Ben Widawsky
This is essential the creation and getter for GBM modifiers (via DRI images).

This was the second chunk of the Renderbuffer Decompression series (aka GBM
modifiers). Splitting this up to make merging easier. These patches are simple
plumbing for getting modifiers through the various GBM functions as well as
exposing the new entry points.

Ben Widawsky (3):
  dri: Add an image creation with modifiers
  gbm: Introduce modifiers into surface/bo creation
  gbm: Export a get modifiers

 include/GL/internal/dri_interface.h  | 27 ++-
 src/egl/drivers/dri2/platform_drm.c  | 19 ++--
 src/gallium/state_trackers/dri/dri2.c|  1 +
 src/gbm/backends/dri/gbm_dri.c   | 78 +---
 src/gbm/gbm-symbols-check|  3 ++
 src/gbm/main/gbm.c   | 48 +++-
 src/gbm/main/gbm.h   | 15 ++
 src/gbm/main/gbmint.h| 13 +-
 src/mesa/drivers/dri/i965/intel_screen.c | 50 +++-
 9 files changed, 237 insertions(+), 17 deletions(-)

-- 
2.12.0

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


[Mesa-dev] [PATCH 5/5] [v2] gbm: Export a per plane getter for offset

2017-03-07 Thread Ben Widawsky
Unlike stride, there was no previous offset getter, so it can be right
on the first try.

v2: Return EINVAL when plane is greater than total planes to make it
match the similar APIs.
Avoid leak after fromPlanar (Daniel)
Make sure when getting offsets we consider dumb images (Daniel)

v3: Use Jason's recommendation for handling the non-planar case.

v4: Return int64_t so we can get real errors

Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom 
Acked-by: Daniel Stone 
---
 src/gbm/backends/dri/gbm_dri.c | 33 +
 src/gbm/gbm-symbols-check  |  1 +
 src/gbm/main/gbm.c | 15 +++
 src/gbm/main/gbm.h |  3 +++
 src/gbm/main/gbmint.h  |  1 +
 5 files changed, 53 insertions(+)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index 56a976fe78..b53f52f8df 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -699,6 +699,38 @@ gbm_dri_bo_get_stride(struct gbm_bo *_bo, int plane)
return (uint32_t)stride;
 }
 
+static int64_t
+gbm_dri_bo_get_offset(struct gbm_bo *_bo, int plane)
+{
+   struct gbm_dri_device *dri = gbm_dri_device(_bo->gbm);
+   struct gbm_dri_bo *bo = gbm_dri_bo(_bo);
+   int offset = 0;
+
+   if (!dri->image || dri->image->base.version < 13 || 
!dri->image->fromPlanar) {
+  errno = ENOSYS;
+  return -1;
+   }
+
+   if (plane >= get_number_planes(dri, bo->image)) {
+  errno = EINVAL;
+  return -2;
+   }
+
+/* Dumb images have no offset */
+   if (!bo->image)
+  return 0;
+
+   __DRIimage *image = dri->image->fromPlanar(bo->image, plane, NULL);
+   if (image) {
+  dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_OFFSET, &offset);
+  dri->image->destroyImage(image);
+   } else {
+  dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_OFFSET, &offset);
+   }
+
+   return (uint32_t)offset;
+}
+
 static void
 gbm_dri_bo_destroy(struct gbm_bo *_bo)
 {
@@ -1194,6 +1226,7 @@ dri_device_create(int fd)
dri->base.base.bo_get_planes = gbm_dri_bo_get_planes;
dri->base.base.bo_get_handle = gbm_dri_bo_get_handle_for_plane;
dri->base.base.bo_get_stride = gbm_dri_bo_get_stride;
+   dri->base.base.bo_get_offset = gbm_dri_bo_get_offset;
dri->base.base.bo_destroy = gbm_dri_bo_destroy;
dri->base.base.destroy = dri_destroy;
dri->base.base.surface_create = gbm_dri_surface_create;
diff --git a/src/gbm/gbm-symbols-check b/src/gbm/gbm-symbols-check
index 459006a63f..7ff78ab400 100755
--- a/src/gbm/gbm-symbols-check
+++ b/src/gbm/gbm-symbols-check
@@ -16,6 +16,7 @@ gbm_bo_get_height
 gbm_bo_get_stride
 gbm_bo_get_stride_for_plane
 gbm_bo_get_format
+gbm_bo_get_offset
 gbm_bo_get_device
 gbm_bo_get_handle
 gbm_bo_get_fd
diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c
index 0a9f0bef7e..afcca63da3 100644
--- a/src/gbm/main/gbm.c
+++ b/src/gbm/main/gbm.c
@@ -194,6 +194,21 @@ gbm_bo_get_format(struct gbm_bo *bo)
return bo->format;
 }
 
+/** Get the offset for the data of the specified plane
+ *
+ * Extra planes, and even the first plane, may have an offset from the start of
+ * the buffer object. This function will provide the offset for the given plane
+ * to be used in various KMS APIs.
+ *
+ * \param bo The buffer object
+ * \return The offset
+ */
+GBM_EXPORT int64_t
+gbm_bo_get_offset(struct gbm_bo *bo, int plane)
+{
+   return bo->gbm->bo_get_offset(bo, plane);
+}
+
 /** Get the gbm device used to create the buffer object
  *
  * \param bo The buffer object
diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h
index 1719c5312a..e3e5d34d97 100644
--- a/src/gbm/main/gbm.h
+++ b/src/gbm/main/gbm.h
@@ -309,6 +309,9 @@ gbm_bo_get_stride_for_plane(struct gbm_bo *bo, int plane);
 uint32_t
 gbm_bo_get_format(struct gbm_bo *bo);
 
+int64_t
+gbm_bo_get_offset(struct gbm_bo *bo, int plane);
+
 struct gbm_device *
 gbm_bo_get_device(struct gbm_bo *bo);
 
diff --git a/src/gbm/main/gbmint.h b/src/gbm/main/gbmint.h
index 26d18bab6b..a6541d91c5 100644
--- a/src/gbm/main/gbmint.h
+++ b/src/gbm/main/gbmint.h
@@ -79,6 +79,7 @@ struct gbm_device {
int (*bo_get_planes)(struct gbm_bo *bo);
union gbm_bo_handle (*bo_get_handle)(struct gbm_bo *bo, int plane);
uint32_t (*bo_get_stride)(struct gbm_bo *bo, int plane);
+   int64_t (*bo_get_offset)(struct gbm_bo *bo, int plane);
void (*bo_destroy)(struct gbm_bo *bo);
 
struct gbm_surface *(*surface_create)(struct gbm_device *gbm,
-- 
2.12.0

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


[Mesa-dev] [PATCH 4/5] gbm: Export a per plane getter for stride

2017-03-07 Thread Ben Widawsky
v2: Preserve legacy behavior when plane is 0 (Jason Ekstrand)
EINVAL when input plane is greater than total planes (Jason Ekstrand)
Don't leak the image after fromPlanar (Daniel)
Move bo->image check below plane count preventing bad index succeeding (Daniel)

v3: Fix DRIimage leak (using Jason's recommended change)
Make plane 0 return planar stride. This might break legacy behavior (Jason)

v4: Move bogus hunk for get_handle_for_plane to the right patch (Jason)
Fix error handling path to be cleaner (Jason)

Cc: Jason Ekstrand 
Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom  (v1)
Acked-by: Daniel Stone 
---
 src/gbm/backends/dri/gbm_dri.c | 33 -
 src/gbm/gbm-symbols-check  |  1 +
 src/gbm/main/gbm.c | 15 ++-
 src/gbm/main/gbm.h |  3 +++
 4 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index 6a834182b5..56a976fe78 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -665,7 +665,38 @@ gbm_dri_bo_get_handle_for_plane(struct gbm_bo *_bo, int 
plane)
 static uint32_t
 gbm_dri_bo_get_stride(struct gbm_bo *_bo, int plane)
 {
-   return _bo->stride;
+   struct gbm_dri_device *dri = gbm_dri_device(_bo->gbm);
+   struct gbm_dri_bo *bo = gbm_dri_bo(_bo);
+   __DRIimage *image;
+   int stride = 0;
+
+   if (!dri->image || dri->image->base.version < 11 || 
!dri->image->fromPlanar) {
+  /* Preserve legacy behavior if plane is 0 */
+  if (plane == 0)
+ return _bo->stride;
+
+  errno = ENOSYS;
+  return 0;
+   }
+
+   if (plane >= get_number_planes(dri, bo->image)) {
+  errno = EINVAL;
+  return 0;
+   }
+
+   if (bo->image == NULL)
+  return _bo->stride;
+
+   image = dri->image->fromPlanar(bo->image, plane, NULL);
+   if (image) {
+  dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_STRIDE, &stride);
+  dri->image->destroyImage(image);
+   } else {
+  assert(plane == 0);
+  dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_STRIDE, &stride);
+   }
+
+   return (uint32_t)stride;
 }
 
 static void
diff --git a/src/gbm/gbm-symbols-check b/src/gbm/gbm-symbols-check
index 1e6dd4d3ec..459006a63f 100755
--- a/src/gbm/gbm-symbols-check
+++ b/src/gbm/gbm-symbols-check
@@ -14,6 +14,7 @@ gbm_bo_unmap
 gbm_bo_get_width
 gbm_bo_get_height
 gbm_bo_get_stride
+gbm_bo_get_stride_for_plane
 gbm_bo_get_format
 gbm_bo_get_device
 gbm_bo_get_handle
diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c
index 7462e90c4c..0a9f0bef7e 100644
--- a/src/gbm/main/gbm.c
+++ b/src/gbm/main/gbm.c
@@ -165,7 +165,20 @@ gbm_bo_get_height(struct gbm_bo *bo)
 GBM_EXPORT uint32_t
 gbm_bo_get_stride(struct gbm_bo *bo)
 {
-   return bo->gbm->bo_get_stride(bo, 0);
+   return gbm_bo_get_stride_for_plane(bo, 0);
+}
+
+/** Get the stride for the given plane
+ *
+ * \param bo The buffer object
+ * \param plane for which you want the stride
+ *
+ * \sa gbm_bo_get_stride()
+ */
+GBM_EXPORT uint32_t
+gbm_bo_get_stride_for_plane(struct gbm_bo *bo, int plane)
+{
+   return bo->gbm->bo_get_stride(bo, plane);
 }
 
 /** Get the format of the buffer object
diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h
index 67548206c4..1719c5312a 100644
--- a/src/gbm/main/gbm.h
+++ b/src/gbm/main/gbm.h
@@ -304,6 +304,9 @@ uint32_t
 gbm_bo_get_stride(struct gbm_bo *bo);
 
 uint32_t
+gbm_bo_get_stride_for_plane(struct gbm_bo *bo, int plane);
+
+uint32_t
 gbm_bo_get_format(struct gbm_bo *bo);
 
 struct gbm_device *
-- 
2.12.0

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


[Mesa-dev] [PATCH 2/5] [v2] gbm: Export a getter for per plane handles

2017-03-07 Thread Ben Widawsky
v2: Make the error return be -1 instead of 0 because I think 0 is
actually valid.

v3: Set errno to EINVAL when the specified plane is above the total
planes. (Jason Ekstrand)
Return the bo's handle if there is no image ie. for dumb images like cursor 
(Daniel)

v4:
- Add assertions about plane == 0 (Jason)
- Add a comment about new restriction on planar dumb bo which is not an
earlier patch in the series.
- Correctly refactor from v2 in this patch; it ended up rebased into the
wrong patch.

Cc: Jason Ekstrand 
Signed-off-by: Ben Widawsky 
Acked-by: Daniel Stone 
---
 src/gbm/backends/dri/gbm_dri.c | 38 ++
 src/gbm/gbm-symbols-check  |  1 +
 src/gbm/main/gbm.c | 18 ++
 src/gbm/main/gbm.h |  3 +++
 src/gbm/main/gbmint.h  |  1 +
 5 files changed, 61 insertions(+)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index 9bd647fa19..e058361e4d 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -625,6 +625,43 @@ gbm_dri_bo_get_planes(struct gbm_bo *_bo)
return get_number_planes(dri, bo->image);
 }
 
+static union gbm_bo_handle
+gbm_dri_bo_get_handle_for_plane(struct gbm_bo *_bo, int plane)
+{
+   struct gbm_dri_device *dri = gbm_dri_device(_bo->gbm);
+   struct gbm_dri_bo *bo = gbm_dri_bo(_bo);
+   union gbm_bo_handle ret;
+   ret.s32 = -1;
+
+   if (!dri->image || dri->image->base.version < 13 || 
!dri->image->fromPlanar) {
+  errno = ENOSYS;
+  return ret;
+   }
+
+   if (plane >= get_number_planes(dri, bo->image)) {
+  errno = EINVAL;
+  return ret;
+   }
+
+   /* dumb BOs can only utilize non-planar formats */
+   if (!bo->image) {
+  assert(plane == 0);
+  ret.s32 = bo->handle;
+  return ret;
+   }
+
+   __DRIimage *image = dri->image->fromPlanar(bo->image, plane, NULL);
+   if (image) {
+  dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_HANDLE, &ret.s32);
+  dri->image->destroyImage(image);
+   } else {
+  assert(plane == 0);
+  dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_HANDLE, &ret.s32);
+   }
+
+   return ret;
+}
+
 static void
 gbm_dri_bo_destroy(struct gbm_bo *_bo)
 {
@@ -1118,6 +1155,7 @@ dri_device_create(int fd)
dri->base.base.bo_write = gbm_dri_bo_write;
dri->base.base.bo_get_fd = gbm_dri_bo_get_fd;
dri->base.base.bo_get_planes = gbm_dri_bo_get_planes;
+   dri->base.base.bo_get_handle = gbm_dri_bo_get_handle_for_plane;
dri->base.base.bo_destroy = gbm_dri_bo_destroy;
dri->base.base.destroy = dri_destroy;
dri->base.base.surface_create = gbm_dri_surface_create;
diff --git a/src/gbm/gbm-symbols-check b/src/gbm/gbm-symbols-check
index 8c4da1b7ea..1e6dd4d3ec 100755
--- a/src/gbm/gbm-symbols-check
+++ b/src/gbm/gbm-symbols-check
@@ -19,6 +19,7 @@ gbm_bo_get_device
 gbm_bo_get_handle
 gbm_bo_get_fd
 gbm_bo_get_plane_count
+gbm_bo_get_handle_for_plane
 gbm_bo_write
 gbm_bo_set_user_data
 gbm_bo_get_user_data
diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c
index 3779517564..066ceffc0a 100644
--- a/src/gbm/main/gbm.c
+++ b/src/gbm/main/gbm.c
@@ -234,6 +234,24 @@ gbm_bo_get_plane_count(struct gbm_bo *bo)
return bo->gbm->bo_get_planes(bo);
 }
 
+/** Get the handle for the specified plane of the buffer object
+ *
+ * This function gets the handle for any plane associated with the BO. When
+ * dealing with multi-planar formats, or formats which might have implicit
+ * planes based on different underlying hardware it is necessary for the client
+ * to be able to get this information to pass to the DRM.
+ *
+ * \param bo The buffer object
+ * \param plane the plane to get a handle for
+ *
+ * \sa gbm_bo_get_handle()
+ */
+GBM_EXPORT union gbm_bo_handle
+gbm_bo_get_handle_for_plane(struct gbm_bo *bo, int plane)
+{
+   return bo->gbm->bo_get_handle(bo, plane);
+}
+
 /** Write data into the buffer object
  *
  * If the buffer object was created with the GBM_BO_USE_WRITE flag,
diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h
index 203a236357..67548206c4 100644
--- a/src/gbm/main/gbm.h
+++ b/src/gbm/main/gbm.h
@@ -318,6 +318,9 @@ gbm_bo_get_fd(struct gbm_bo *bo);
 int
 gbm_bo_get_plane_count(struct gbm_bo *bo);
 
+union gbm_bo_handle
+gbm_bo_get_handle_for_plane(struct gbm_bo *bo, int plane);
+
 int
 gbm_bo_write(struct gbm_bo *bo, const void *buf, size_t count);
 
diff --git a/src/gbm/main/gbmint.h b/src/gbm/main/gbmint.h
index c6a6701464..0ec531d099 100644
--- a/src/gbm/main/gbmint.h
+++ b/src/gbm/main/gbmint.h
@@ -77,6 +77,7 @@ struct gbm_device {
int (*bo_write)(struct gbm_bo *bo, const void *buf, size_t data);
int (*bo_get_fd)(struct gbm_bo *bo);
int (*bo_get_planes)(struct gbm_bo *bo);
+   union gbm_bo_handle (*bo_get_handle)(struct gbm_bo *bo, int plane);
void (*bo_destroy)(struct gbm_bo *bo);
 
struct gbm_surface *(*surface_create)(st

Re: [Mesa-dev] [PATCH 4/5] gbm: Export a per plane getter for stride

2017-03-07 Thread Ben Widawsky

On 17-03-07 08:33:32, Jason Ekstrand wrote:

On Mon, Mar 6, 2017 at 6:37 PM, Ben Widawsky  wrote:


v2: Preserve legacy behavior when plane is 0 (Jason Ekstrand)
EINVAL when input plane is greater than total planes (Jason Ekstrand)
Don't leak the image after fromPlanar (Daniel)
Move bo->image check below plane count preventing bad index succeeding
(Daniel)

v3: Fix DRIimage leak (using Jason's recommended change)
Make plane 0 return planar stride. This might break legacy behavior (Jason)

Cc: Jason Ekstrand 
Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom  (v1)
Acked-by: Daniel Stone 
---
 src/gbm/backends/dri/gbm_dri.c | 45 ++
++--
 src/gbm/gbm-symbols-check  |  1 +
 src/gbm/main/gbm.c | 15 +-
 src/gbm/main/gbm.h |  3 +++
 4 files changed, 57 insertions(+), 7 deletions(-)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_
dri.c
index 3d9c540d95..ecba3ead5a 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -648,20 +648,53 @@ gbm_dri_bo_get_handle_for_plane(struct gbm_bo *_bo,
int plane)
}

__DRIimage *image = dri->image->fromPlanar(bo->image, plane, NULL);
-   if (!image) {
-  /* Use the parent's handle */
-  image = bo->image;
+   if (image) {
+  dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_HANDLE, &ret.s32);
+  dri->image->destroyImage(image);
+   } else {
+  dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_HANDLE,
&ret.s32);
}

-   dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_HANDLE, &ret.s32);
-



Should this hunk go in the previous patch?




Yeah, this was a bad squash... two previous.


return ret;
 }

 static uint32_t
 gbm_dri_bo_get_stride(struct gbm_bo *_bo, int plane)
 {
-   return _bo->stride;
+   struct gbm_dri_device *dri = gbm_dri_device(_bo->gbm);
+   struct gbm_dri_bo *bo = gbm_dri_bo(_bo);
+   __DRIimage *image;
+   int stride = 0;
+
+   if (!dri->image || dri->image->base.version < 11 ||
!dri->image->fromPlanar) {
+  /* Preserve legacy behavior if plane is 0 */
+  if (plane == 0)
+ return _bo->stride;
+
+  errno = ENOSYS;
+  return 0;
+   }
+
+   if (plane >= get_number_planes(dri, bo->image)) {
+  errno = EINVAL;
+  return 0;
+   }
+
+   if (bo->image == NULL)
+  return _bo->stride;



Is this possible?




Yes, dumb BOs.


+
+   image = dri->image->fromPlanar(bo->image, plane, NULL);
+   if (!image) {
+  /* Use the parent stride */
+  image = bo->image;
+   }
+
+   dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_STRIDE, &stride);
+
+   if (image != bo->image)
+  dri->image->destroyImage(image);



Let's make the same tweaks to this clean-up path if you don't mind.




Sure. I think this existed somewhere and I sent the wrong patch.


+
+   return (uint32_t)stride;
 }

 static void
diff --git a/src/gbm/gbm-symbols-check b/src/gbm/gbm-symbols-check
index 1e6dd4d3ec..459006a63f 100755
--- a/src/gbm/gbm-symbols-check
+++ b/src/gbm/gbm-symbols-check
@@ -14,6 +14,7 @@ gbm_bo_unmap
 gbm_bo_get_width
 gbm_bo_get_height
 gbm_bo_get_stride
+gbm_bo_get_stride_for_plane
 gbm_bo_get_format
 gbm_bo_get_device
 gbm_bo_get_handle
diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c
index 7462e90c4c..0a9f0bef7e 100644
--- a/src/gbm/main/gbm.c
+++ b/src/gbm/main/gbm.c
@@ -165,7 +165,20 @@ gbm_bo_get_height(struct gbm_bo *bo)
 GBM_EXPORT uint32_t
 gbm_bo_get_stride(struct gbm_bo *bo)
 {
-   return bo->gbm->bo_get_stride(bo, 0);
+   return gbm_bo_get_stride_for_plane(bo, 0);
+}
+
+/** Get the stride for the given plane
+ *
+ * \param bo The buffer object
+ * \param plane for which you want the stride
+ *
+ * \sa gbm_bo_get_stride()
+ */
+GBM_EXPORT uint32_t
+gbm_bo_get_stride_for_plane(struct gbm_bo *bo, int plane)
+{
+   return bo->gbm->bo_get_stride(bo, plane);
 }

 /** Get the format of the buffer object
diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h
index 67548206c4..1719c5312a 100644
--- a/src/gbm/main/gbm.h
+++ b/src/gbm/main/gbm.h
@@ -304,6 +304,9 @@ uint32_t
 gbm_bo_get_stride(struct gbm_bo *bo);

 uint32_t
+gbm_bo_get_stride_for_plane(struct gbm_bo *bo, int plane);
+
+uint32_t
 gbm_bo_get_format(struct gbm_bo *bo);

 struct gbm_device *
--
2.12.0



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


[Mesa-dev] [PATCH] [v2] gbm: Explicitly disallow a planar dumb BO

2017-03-07 Thread Ben Widawsky
As more GBM functionality support planes is being evaluated, it becomes
clear that a dumb bo can never actually be planar. It's questionable
whether it was ever feasible to do this, and later functionality will
implicitly assume a dumb BO is non-planar.

v2: Include stdbool.h

Cc: Jason Ekstrand 
Cc: Daniel Stone 
Cc: Kristian H. Kristensen 
Signed-off-by: Ben Widawsky 
---
 src/gbm/backends/dri/gbm_dri.c | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index ac7ede87b6..3faa19e3f1 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -29,6 +29,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -795,6 +796,31 @@ gbm_dri_bo_import(struct gbm_device *gbm,
return &bo->base.base;
 }
 
+static bool
+is_planar_format(uint32_t format)
+{
+   switch (format) {
+   case GBM_FORMAT_NV12:
+   case GBM_FORMAT_NV21:
+   case GBM_FORMAT_NV16:
+   case GBM_FORMAT_NV61:
+   case GBM_FORMAT_YUV410:
+   case GBM_FORMAT_YVU410:
+   case GBM_FORMAT_YUV411:
+   case GBM_FORMAT_YVU411:
+   case GBM_FORMAT_YUV420:
+   case GBM_FORMAT_YVU420:
+   case GBM_FORMAT_YUV422:
+   case GBM_FORMAT_YVU422:
+   case GBM_FORMAT_YUV444:
+   case GBM_FORMAT_YVU444:
+  return true;
+   default:
+  return false;
+   }
+
+}
+
 static struct gbm_bo *
 create_dumb(struct gbm_device *gbm,
   uint32_t width, uint32_t height,
@@ -816,6 +842,11 @@ create_dumb(struct gbm_device *gbm,
   return NULL;
}
 
+   if (is_planar_format(format)) {
+  errno = EINVAL;
+  return NULL;
+   }
+
bo = calloc(1, sizeof *bo);
if (bo == NULL)
   return NULL;
-- 
2.12.0

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


[Mesa-dev] [PATCH] gbm: Explicitly disallow a planar dumb BO

2017-03-07 Thread Ben Widawsky
As more GBM functionality support planes is being evaluated, it becomes
clear that a dumb bo can never actually be planar. It's questionable
whether it was ever feasible to do this, and later functionality will
implicitly assume a dumb BO is non-planar.

Cc: Jason Ekstrand 
Cc: Daniel Stone 
Cc: Kristian H. Kristensen 
Signed-off-by: Ben Widawsky 
---
 src/gbm/backends/dri/gbm_dri.c | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index ac7ede87b6..9ddc2159fc 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -795,6 +795,31 @@ gbm_dri_bo_import(struct gbm_device *gbm,
return &bo->base.base;
 }
 
+static bool
+is_planar_format(uint32_t format)
+{
+   switch (format) {
+   case GBM_FORMAT_NV12:
+   case GBM_FORMAT_NV21:
+   case GBM_FORMAT_NV16:
+   case GBM_FORMAT_NV61:
+   case GBM_FORMAT_YUV410:
+   case GBM_FORMAT_YVU410:
+   case GBM_FORMAT_YUV411:
+   case GBM_FORMAT_YVU411:
+   case GBM_FORMAT_YUV420:
+   case GBM_FORMAT_YVU420:
+   case GBM_FORMAT_YUV422:
+   case GBM_FORMAT_YVU422:
+   case GBM_FORMAT_YUV444:
+   case GBM_FORMAT_YVU444:
+  return true;
+   default:
+  return false;
+   }
+
+}
+
 static struct gbm_bo *
 create_dumb(struct gbm_device *gbm,
   uint32_t width, uint32_t height,
@@ -816,6 +841,11 @@ create_dumb(struct gbm_device *gbm,
   return NULL;
}
 
+   if (is_planar_format(format)) {
+  errno = EINVAL;
+  return NULL;
+   }
+
bo = calloc(1, sizeof *bo);
if (bo == NULL)
   return NULL;
-- 
2.12.0

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


Re: [Mesa-dev] [PATCH 2/5] gbm: Export a getter for per plane handles

2017-03-07 Thread Ben Widawsky

On 17-03-07 08:28:09, Jason Ekstrand wrote:

On Mon, Mar 6, 2017 at 6:37 PM, Ben Widawsky  wrote:


v2: Make the error return be -1 instead of 0 because I think 0 is
actually valid.

v3: Set errno to EINVAL when the specified plane is above the total
planes. (Jason Ekstrand)
Return the bo's handle if there is no image ie. for dumb images like
cursor (Daniel)

Signed-off-by: Ben Widawsky 
Acked-by: Daniel Stone 
---
 src/gbm/backends/dri/gbm_dri.c | 35 +++
 src/gbm/gbm-symbols-check  |  1 +
 src/gbm/main/gbm.c | 18 ++
 src/gbm/main/gbm.h |  3 +++
 src/gbm/main/gbmint.h  |  1 +
 5 files changed, 58 insertions(+)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_
dri.c
index 0b75e411df..c3704e505b 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -624,6 +624,40 @@ gbm_dri_bo_get_planes(struct gbm_bo *_bo)
return get_number_planes(dri, bo->image);
 }

+static union gbm_bo_handle
+gbm_dri_bo_get_handle_for_plane(struct gbm_bo *_bo, int plane)
+{
+   struct gbm_dri_device *dri = gbm_dri_device(_bo->gbm);
+   struct gbm_dri_bo *bo = gbm_dri_bo(_bo);
+   union gbm_bo_handle ret;
+   ret.s32 = -1;
+
+   if (!dri->image || dri->image->base.version < 13 ||
!dri->image->fromPlanar) {
+  errno = ENOSYS;
+  return ret;
+   }
+
+   if (plane >= get_number_planes(dri, bo->image)) {
+  errno = EINVAL;
+  return ret;
+   }
+
+   if (!bo->image) {
+  ret.s32 = bo->handle;
+  return ret;
+   }
+
+   __DRIimage *image = dri->image->fromPlanar(bo->image, plane, NULL);
+   if (!image) {
+  /* Use the parent's handle */
+  image = bo->image;



Assuming get_number_of_planes does the right thing, I think this is
correct.  Would it make sense to add an assert(plane == 0) to this error
case and the one above?




Let me claim ignorance...

For "the one above": I thought it might be possible to have a planar dumb bo, in
which case, the assertion wouldn't always hold. However, I have other code here
which prevents that, so I think I'll modify the commit message, add some
comments, and most importantly make a patch before this which prevents dumb BOs
from being planar formats.

For the !image case: this assertion should also hold, but since fromPlanar can
be implemented however by the DRI implementation, I don't know if it's the right
thing to add assertions in that path. I'm fine with adding it, I just claim some
level of ignorance.

[snip]

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


[Mesa-dev] [PATCH 3/5] gbm: Create a gbm_device getter for stride

2017-03-06 Thread Ben Widawsky
This will be used so we can query information per plane.

Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom 
Acked-by: Daniel Stone 
---
 src/gbm/backends/dri/gbm_dri.c | 7 +++
 src/gbm/main/gbm.c | 2 +-
 src/gbm/main/gbmint.h  | 1 +
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index c3704e505b..3d9c540d95 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -658,6 +658,12 @@ gbm_dri_bo_get_handle_for_plane(struct gbm_bo *_bo, int 
plane)
return ret;
 }
 
+static uint32_t
+gbm_dri_bo_get_stride(struct gbm_bo *_bo, int plane)
+{
+   return _bo->stride;
+}
+
 static void
 gbm_dri_bo_destroy(struct gbm_bo *_bo)
 {
@@ -1122,6 +1128,7 @@ dri_device_create(int fd)
dri->base.base.bo_get_fd = gbm_dri_bo_get_fd;
dri->base.base.bo_get_planes = gbm_dri_bo_get_planes;
dri->base.base.bo_get_handle = gbm_dri_bo_get_handle_for_plane;
+   dri->base.base.bo_get_stride = gbm_dri_bo_get_stride;
dri->base.base.bo_destroy = gbm_dri_bo_destroy;
dri->base.base.destroy = dri_destroy;
dri->base.base.surface_create = gbm_dri_surface_create;
diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c
index 066ceffc0a..7462e90c4c 100644
--- a/src/gbm/main/gbm.c
+++ b/src/gbm/main/gbm.c
@@ -165,7 +165,7 @@ gbm_bo_get_height(struct gbm_bo *bo)
 GBM_EXPORT uint32_t
 gbm_bo_get_stride(struct gbm_bo *bo)
 {
-   return bo->stride;
+   return bo->gbm->bo_get_stride(bo, 0);
 }
 
 /** Get the format of the buffer object
diff --git a/src/gbm/main/gbmint.h b/src/gbm/main/gbmint.h
index 0ec531d099..26d18bab6b 100644
--- a/src/gbm/main/gbmint.h
+++ b/src/gbm/main/gbmint.h
@@ -78,6 +78,7 @@ struct gbm_device {
int (*bo_get_fd)(struct gbm_bo *bo);
int (*bo_get_planes)(struct gbm_bo *bo);
union gbm_bo_handle (*bo_get_handle)(struct gbm_bo *bo, int plane);
+   uint32_t (*bo_get_stride)(struct gbm_bo *bo, int plane);
void (*bo_destroy)(struct gbm_bo *bo);
 
struct gbm_surface *(*surface_create)(struct gbm_device *gbm,
-- 
2.12.0

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


[Mesa-dev] [PATCH 1/5] gbm: Export a plane getter function

2017-03-06 Thread Ben Widawsky
This will be used by clients that need to know the number of planes
allocated for them on behalf of the GL or other API. The best current
example of this is when an extra "plane" is allocated to store
compression data for the primary plane.

v2: Return 1 for cases where there is no image, ie. dumb bo (Daniel)

Cc: Daniel Stone 
Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom 
Acked-by: Daniel Stone 
---
 src/gbm/backends/dri/gbm_dri.c | 27 +++
 src/gbm/gbm-symbols-check  |  1 +
 src/gbm/main/gbm.c | 10 ++
 src/gbm/main/gbm.h |  3 +++
 src/gbm/main/gbmint.h  |  1 +
 5 files changed, 42 insertions(+)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index ac7ede87b6..0b75e411df 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -598,6 +598,32 @@ gbm_dri_bo_get_fd(struct gbm_bo *_bo)
return fd;
 }
 
+static int
+get_number_planes(struct gbm_dri_device *dri, __DRIimage *image)
+{
+   int num_planes = 0;
+
+   /* Dumb buffers are single-plane only. */
+   if (!image)
+  return 1;
+
+   dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_NUM_PLANES, &num_planes);
+
+   if (num_planes <= 0)
+  num_planes = 1;
+
+   return num_planes;
+}
+
+static int
+gbm_dri_bo_get_planes(struct gbm_bo *_bo)
+{
+   struct gbm_dri_device *dri = gbm_dri_device(_bo->gbm);
+   struct gbm_dri_bo *bo = gbm_dri_bo(_bo);
+
+   return get_number_planes(dri, bo->image);
+}
+
 static void
 gbm_dri_bo_destroy(struct gbm_bo *_bo)
 {
@@ -1060,6 +1086,7 @@ dri_device_create(int fd)
dri->base.base.is_format_supported = gbm_dri_is_format_supported;
dri->base.base.bo_write = gbm_dri_bo_write;
dri->base.base.bo_get_fd = gbm_dri_bo_get_fd;
+   dri->base.base.bo_get_planes = gbm_dri_bo_get_planes;
dri->base.base.bo_destroy = gbm_dri_bo_destroy;
dri->base.base.destroy = dri_destroy;
dri->base.base.surface_create = gbm_dri_surface_create;
diff --git a/src/gbm/gbm-symbols-check b/src/gbm/gbm-symbols-check
index 5a333ffcda..8c4da1b7ea 100755
--- a/src/gbm/gbm-symbols-check
+++ b/src/gbm/gbm-symbols-check
@@ -18,6 +18,7 @@ gbm_bo_get_format
 gbm_bo_get_device
 gbm_bo_get_handle
 gbm_bo_get_fd
+gbm_bo_get_plane_count
 gbm_bo_write
 gbm_bo_set_user_data
 gbm_bo_get_user_data
diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c
index e96297ec52..3779517564 100644
--- a/src/gbm/main/gbm.c
+++ b/src/gbm/main/gbm.c
@@ -223,6 +223,16 @@ gbm_bo_get_fd(struct gbm_bo *bo)
return bo->gbm->bo_get_fd(bo);
 }
 
+/** Get the number of planes for the given bo.
+ *
+ * \param bo The buffer object
+ * \return The number of planes
+ */
+GBM_EXPORT int
+gbm_bo_get_plane_count(struct gbm_bo *bo)
+{
+   return bo->gbm->bo_get_planes(bo);
+}
 
 /** Write data into the buffer object
  *
diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h
index 59daaa164d..203a236357 100644
--- a/src/gbm/main/gbm.h
+++ b/src/gbm/main/gbm.h
@@ -316,6 +316,9 @@ int
 gbm_bo_get_fd(struct gbm_bo *bo);
 
 int
+gbm_bo_get_plane_count(struct gbm_bo *bo);
+
+int
 gbm_bo_write(struct gbm_bo *bo, const void *buf, size_t count);
 
 void
diff --git a/src/gbm/main/gbmint.h b/src/gbm/main/gbmint.h
index cfef5eea29..c6a6701464 100644
--- a/src/gbm/main/gbmint.h
+++ b/src/gbm/main/gbmint.h
@@ -76,6 +76,7 @@ struct gbm_device {
void (*bo_unmap)(struct gbm_bo *bo, void *map_data);
int (*bo_write)(struct gbm_bo *bo, const void *buf, size_t data);
int (*bo_get_fd)(struct gbm_bo *bo);
+   int (*bo_get_planes)(struct gbm_bo *bo);
void (*bo_destroy)(struct gbm_bo *bo);
 
struct gbm_surface *(*surface_create)(struct gbm_device *gbm,
-- 
2.12.0

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


[Mesa-dev] [PATCH 4/5] gbm: Export a per plane getter for stride

2017-03-06 Thread Ben Widawsky
v2: Preserve legacy behavior when plane is 0 (Jason Ekstrand)
EINVAL when input plane is greater than total planes (Jason Ekstrand)
Don't leak the image after fromPlanar (Daniel)
Move bo->image check below plane count preventing bad index succeeding (Daniel)

v3: Fix DRIimage leak (using Jason's recommended change)
Make plane 0 return planar stride. This might break legacy behavior (Jason)

Cc: Jason Ekstrand 
Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom  (v1)
Acked-by: Daniel Stone 
---
 src/gbm/backends/dri/gbm_dri.c | 45 --
 src/gbm/gbm-symbols-check  |  1 +
 src/gbm/main/gbm.c | 15 +-
 src/gbm/main/gbm.h |  3 +++
 4 files changed, 57 insertions(+), 7 deletions(-)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index 3d9c540d95..ecba3ead5a 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -648,20 +648,53 @@ gbm_dri_bo_get_handle_for_plane(struct gbm_bo *_bo, int 
plane)
}
 
__DRIimage *image = dri->image->fromPlanar(bo->image, plane, NULL);
-   if (!image) {
-  /* Use the parent's handle */
-  image = bo->image;
+   if (image) {
+  dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_HANDLE, &ret.s32);
+  dri->image->destroyImage(image);
+   } else {
+  dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_HANDLE, &ret.s32);
}
 
-   dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_HANDLE, &ret.s32);
-
return ret;
 }
 
 static uint32_t
 gbm_dri_bo_get_stride(struct gbm_bo *_bo, int plane)
 {
-   return _bo->stride;
+   struct gbm_dri_device *dri = gbm_dri_device(_bo->gbm);
+   struct gbm_dri_bo *bo = gbm_dri_bo(_bo);
+   __DRIimage *image;
+   int stride = 0;
+
+   if (!dri->image || dri->image->base.version < 11 || 
!dri->image->fromPlanar) {
+  /* Preserve legacy behavior if plane is 0 */
+  if (plane == 0)
+ return _bo->stride;
+
+  errno = ENOSYS;
+  return 0;
+   }
+
+   if (plane >= get_number_planes(dri, bo->image)) {
+  errno = EINVAL;
+  return 0;
+   }
+
+   if (bo->image == NULL)
+  return _bo->stride;
+
+   image = dri->image->fromPlanar(bo->image, plane, NULL);
+   if (!image) {
+  /* Use the parent stride */
+  image = bo->image;
+   }
+
+   dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_STRIDE, &stride);
+
+   if (image != bo->image)
+  dri->image->destroyImage(image);
+
+   return (uint32_t)stride;
 }
 
 static void
diff --git a/src/gbm/gbm-symbols-check b/src/gbm/gbm-symbols-check
index 1e6dd4d3ec..459006a63f 100755
--- a/src/gbm/gbm-symbols-check
+++ b/src/gbm/gbm-symbols-check
@@ -14,6 +14,7 @@ gbm_bo_unmap
 gbm_bo_get_width
 gbm_bo_get_height
 gbm_bo_get_stride
+gbm_bo_get_stride_for_plane
 gbm_bo_get_format
 gbm_bo_get_device
 gbm_bo_get_handle
diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c
index 7462e90c4c..0a9f0bef7e 100644
--- a/src/gbm/main/gbm.c
+++ b/src/gbm/main/gbm.c
@@ -165,7 +165,20 @@ gbm_bo_get_height(struct gbm_bo *bo)
 GBM_EXPORT uint32_t
 gbm_bo_get_stride(struct gbm_bo *bo)
 {
-   return bo->gbm->bo_get_stride(bo, 0);
+   return gbm_bo_get_stride_for_plane(bo, 0);
+}
+
+/** Get the stride for the given plane
+ *
+ * \param bo The buffer object
+ * \param plane for which you want the stride
+ *
+ * \sa gbm_bo_get_stride()
+ */
+GBM_EXPORT uint32_t
+gbm_bo_get_stride_for_plane(struct gbm_bo *bo, int plane)
+{
+   return bo->gbm->bo_get_stride(bo, plane);
 }
 
 /** Get the format of the buffer object
diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h
index 67548206c4..1719c5312a 100644
--- a/src/gbm/main/gbm.h
+++ b/src/gbm/main/gbm.h
@@ -304,6 +304,9 @@ uint32_t
 gbm_bo_get_stride(struct gbm_bo *bo);
 
 uint32_t
+gbm_bo_get_stride_for_plane(struct gbm_bo *bo, int plane);
+
+uint32_t
 gbm_bo_get_format(struct gbm_bo *bo);
 
 struct gbm_device *
-- 
2.12.0

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


[Mesa-dev] [PATCH 5/5] gbm: Export a per plane getter for offset

2017-03-06 Thread Ben Widawsky
Unlike stride, there was no previous offset getter, so it can be right
on the first try.

v2: Return EINVAL when plane is greater than total planes to make it
match the similar APIs.
Avoid leak after fromPlanar (Daniel)
Make sure when getting offsets we consider dumb images (Daniel)

v3: Use Jason's recommendation for handling the non-planar case.

Signed-off-by: Ben Widawsky 
Reviewed-by: Eric Engestrom 
Acked-by: Daniel Stone 
---
 src/gbm/backends/dri/gbm_dri.c | 33 +
 src/gbm/gbm-symbols-check  |  1 +
 src/gbm/main/gbm.c | 15 +++
 src/gbm/main/gbm.h |  3 +++
 src/gbm/main/gbmint.h  |  1 +
 5 files changed, 53 insertions(+)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index ecba3ead5a..6215116fd0 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -697,6 +697,38 @@ gbm_dri_bo_get_stride(struct gbm_bo *_bo, int plane)
return (uint32_t)stride;
 }
 
+static uint32_t
+gbm_dri_bo_get_offset(struct gbm_bo *_bo, int plane)
+{
+   struct gbm_dri_device *dri = gbm_dri_device(_bo->gbm);
+   struct gbm_dri_bo *bo = gbm_dri_bo(_bo);
+   int offset = 0;
+
+   if (!dri->image || dri->image->base.version < 13 || 
!dri->image->fromPlanar) {
+  errno = ENOSYS;
+  return 0;
+   }
+
+   if (plane >= get_number_planes(dri, bo->image)) {
+  errno = EINVAL;
+  return 0;
+   }
+
+/* Dumb images have no offset */
+   if (!bo->image)
+  return 0;
+
+   __DRIimage *image = dri->image->fromPlanar(bo->image, plane, NULL);
+   if (image) {
+  dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_OFFSET, &offset);
+  dri->image->destroyImage(image);
+   } else {
+  dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_OFFSET, &offset);
+   }
+
+   return (uint32_t)offset;
+}
+
 static void
 gbm_dri_bo_destroy(struct gbm_bo *_bo)
 {
@@ -1162,6 +1194,7 @@ dri_device_create(int fd)
dri->base.base.bo_get_planes = gbm_dri_bo_get_planes;
dri->base.base.bo_get_handle = gbm_dri_bo_get_handle_for_plane;
dri->base.base.bo_get_stride = gbm_dri_bo_get_stride;
+   dri->base.base.bo_get_offset = gbm_dri_bo_get_offset;
dri->base.base.bo_destroy = gbm_dri_bo_destroy;
dri->base.base.destroy = dri_destroy;
dri->base.base.surface_create = gbm_dri_surface_create;
diff --git a/src/gbm/gbm-symbols-check b/src/gbm/gbm-symbols-check
index 459006a63f..7ff78ab400 100755
--- a/src/gbm/gbm-symbols-check
+++ b/src/gbm/gbm-symbols-check
@@ -16,6 +16,7 @@ gbm_bo_get_height
 gbm_bo_get_stride
 gbm_bo_get_stride_for_plane
 gbm_bo_get_format
+gbm_bo_get_offset
 gbm_bo_get_device
 gbm_bo_get_handle
 gbm_bo_get_fd
diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c
index 0a9f0bef7e..295f6894eb 100644
--- a/src/gbm/main/gbm.c
+++ b/src/gbm/main/gbm.c
@@ -194,6 +194,21 @@ gbm_bo_get_format(struct gbm_bo *bo)
return bo->format;
 }
 
+/** Get the offset for the data of the specified plane
+ *
+ * Extra planes, and even the first plane, may have an offset from the start of
+ * the buffer object. This function will provide the offset for the given plane
+ * to be used in various KMS APIs.
+ *
+ * \param bo The buffer object
+ * \return The offset
+ */
+GBM_EXPORT uint32_t
+gbm_bo_get_offset(struct gbm_bo *bo, int plane)
+{
+   return bo->gbm->bo_get_offset(bo, plane);
+}
+
 /** Get the gbm device used to create the buffer object
  *
  * \param bo The buffer object
diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h
index 1719c5312a..b089359b01 100644
--- a/src/gbm/main/gbm.h
+++ b/src/gbm/main/gbm.h
@@ -309,6 +309,9 @@ gbm_bo_get_stride_for_plane(struct gbm_bo *bo, int plane);
 uint32_t
 gbm_bo_get_format(struct gbm_bo *bo);
 
+uint32_t
+gbm_bo_get_offset(struct gbm_bo *bo, int plane);
+
 struct gbm_device *
 gbm_bo_get_device(struct gbm_bo *bo);
 
diff --git a/src/gbm/main/gbmint.h b/src/gbm/main/gbmint.h
index 26d18bab6b..ac6078361a 100644
--- a/src/gbm/main/gbmint.h
+++ b/src/gbm/main/gbmint.h
@@ -79,6 +79,7 @@ struct gbm_device {
int (*bo_get_planes)(struct gbm_bo *bo);
union gbm_bo_handle (*bo_get_handle)(struct gbm_bo *bo, int plane);
uint32_t (*bo_get_stride)(struct gbm_bo *bo, int plane);
+   uint32_t (*bo_get_offset)(struct gbm_bo *bo, int plane);
void (*bo_destroy)(struct gbm_bo *bo);
 
struct gbm_surface *(*surface_create)(struct gbm_device *gbm,
-- 
2.12.0

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


[Mesa-dev] [PATCH 2/5] gbm: Export a getter for per plane handles

2017-03-06 Thread Ben Widawsky
v2: Make the error return be -1 instead of 0 because I think 0 is
actually valid.

v3: Set errno to EINVAL when the specified plane is above the total
planes. (Jason Ekstrand)
Return the bo's handle if there is no image ie. for dumb images like cursor 
(Daniel)

Signed-off-by: Ben Widawsky 
Acked-by: Daniel Stone 
---
 src/gbm/backends/dri/gbm_dri.c | 35 +++
 src/gbm/gbm-symbols-check  |  1 +
 src/gbm/main/gbm.c | 18 ++
 src/gbm/main/gbm.h |  3 +++
 src/gbm/main/gbmint.h  |  1 +
 5 files changed, 58 insertions(+)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index 0b75e411df..c3704e505b 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -624,6 +624,40 @@ gbm_dri_bo_get_planes(struct gbm_bo *_bo)
return get_number_planes(dri, bo->image);
 }
 
+static union gbm_bo_handle
+gbm_dri_bo_get_handle_for_plane(struct gbm_bo *_bo, int plane)
+{
+   struct gbm_dri_device *dri = gbm_dri_device(_bo->gbm);
+   struct gbm_dri_bo *bo = gbm_dri_bo(_bo);
+   union gbm_bo_handle ret;
+   ret.s32 = -1;
+
+   if (!dri->image || dri->image->base.version < 13 || 
!dri->image->fromPlanar) {
+  errno = ENOSYS;
+  return ret;
+   }
+
+   if (plane >= get_number_planes(dri, bo->image)) {
+  errno = EINVAL;
+  return ret;
+   }
+
+   if (!bo->image) {
+  ret.s32 = bo->handle;
+  return ret;
+   }
+
+   __DRIimage *image = dri->image->fromPlanar(bo->image, plane, NULL);
+   if (!image) {
+  /* Use the parent's handle */
+  image = bo->image;
+   }
+
+   dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_HANDLE, &ret.s32);
+
+   return ret;
+}
+
 static void
 gbm_dri_bo_destroy(struct gbm_bo *_bo)
 {
@@ -1087,6 +1121,7 @@ dri_device_create(int fd)
dri->base.base.bo_write = gbm_dri_bo_write;
dri->base.base.bo_get_fd = gbm_dri_bo_get_fd;
dri->base.base.bo_get_planes = gbm_dri_bo_get_planes;
+   dri->base.base.bo_get_handle = gbm_dri_bo_get_handle_for_plane;
dri->base.base.bo_destroy = gbm_dri_bo_destroy;
dri->base.base.destroy = dri_destroy;
dri->base.base.surface_create = gbm_dri_surface_create;
diff --git a/src/gbm/gbm-symbols-check b/src/gbm/gbm-symbols-check
index 8c4da1b7ea..1e6dd4d3ec 100755
--- a/src/gbm/gbm-symbols-check
+++ b/src/gbm/gbm-symbols-check
@@ -19,6 +19,7 @@ gbm_bo_get_device
 gbm_bo_get_handle
 gbm_bo_get_fd
 gbm_bo_get_plane_count
+gbm_bo_get_handle_for_plane
 gbm_bo_write
 gbm_bo_set_user_data
 gbm_bo_get_user_data
diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c
index 3779517564..066ceffc0a 100644
--- a/src/gbm/main/gbm.c
+++ b/src/gbm/main/gbm.c
@@ -234,6 +234,24 @@ gbm_bo_get_plane_count(struct gbm_bo *bo)
return bo->gbm->bo_get_planes(bo);
 }
 
+/** Get the handle for the specified plane of the buffer object
+ *
+ * This function gets the handle for any plane associated with the BO. When
+ * dealing with multi-planar formats, or formats which might have implicit
+ * planes based on different underlying hardware it is necessary for the client
+ * to be able to get this information to pass to the DRM.
+ *
+ * \param bo The buffer object
+ * \param plane the plane to get a handle for
+ *
+ * \sa gbm_bo_get_handle()
+ */
+GBM_EXPORT union gbm_bo_handle
+gbm_bo_get_handle_for_plane(struct gbm_bo *bo, int plane)
+{
+   return bo->gbm->bo_get_handle(bo, plane);
+}
+
 /** Write data into the buffer object
  *
  * If the buffer object was created with the GBM_BO_USE_WRITE flag,
diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h
index 203a236357..67548206c4 100644
--- a/src/gbm/main/gbm.h
+++ b/src/gbm/main/gbm.h
@@ -318,6 +318,9 @@ gbm_bo_get_fd(struct gbm_bo *bo);
 int
 gbm_bo_get_plane_count(struct gbm_bo *bo);
 
+union gbm_bo_handle
+gbm_bo_get_handle_for_plane(struct gbm_bo *bo, int plane);
+
 int
 gbm_bo_write(struct gbm_bo *bo, const void *buf, size_t count);
 
diff --git a/src/gbm/main/gbmint.h b/src/gbm/main/gbmint.h
index c6a6701464..0ec531d099 100644
--- a/src/gbm/main/gbmint.h
+++ b/src/gbm/main/gbmint.h
@@ -77,6 +77,7 @@ struct gbm_device {
int (*bo_write)(struct gbm_bo *bo, const void *buf, size_t data);
int (*bo_get_fd)(struct gbm_bo *bo);
int (*bo_get_planes)(struct gbm_bo *bo);
+   union gbm_bo_handle (*bo_get_handle)(struct gbm_bo *bo, int plane);
void (*bo_destroy)(struct gbm_bo *bo);
 
struct gbm_surface *(*surface_create)(struct gbm_device *gbm,
-- 
2.12.0

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


[Mesa-dev] [PATCH 0/5] Per plane GBM functions

2017-03-06 Thread Ben Widawsky
This was the first chunk of the Renderbuffer Decompression series (aka GBM
modifiers). Splitting this up to make merging easier. These patches are just the
new GBM entry points for the functions required to support modifiers.

Cc: Kristian H. Kristensen 
Cc: Daniel Stone 
Cc: Eric Engestrom 
Cc: Jason Ekstrand 

Ben Widawsky (5):
  gbm: Export a plane getter function
  gbm: Export a getter for per plane handles
  gbm: Create a gbm_device getter for stride
  gbm: Export a per plane getter for stride
  gbm: Export a per plane getter for offset

 src/gbm/backends/dri/gbm_dri.c | 135 +
 src/gbm/gbm-symbols-check  |   4 ++
 src/gbm/main/gbm.c |  58 +-
 src/gbm/main/gbm.h |  12 
 src/gbm/main/gbmint.h  |   4 ++
 5 files changed, 212 insertions(+), 1 deletion(-)

-- 
2.12.0

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


  1   2   3   4   5   6   7   8   9   10   >