<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Wed, Nov 14, 2018 at 6:02 AM Danylo Piliaiev <<a href="mailto:danylo.piliaiev@gmail.com">danylo.piliaiev@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Ilia, Jason,<br>
<br>
All these cases are indeed could induce confusion,<br>
I'll try to explain all of them:<br>
<br>
Texture is not layered:<br>
     Layers: 1<br>
     Base Layer: %layer of image unit% + %layer of texture view%<br>
<br>
Layered 3D texture:<br>
     Layers: Entire level is bound, texture view does not affect layers <br>
of it<br>
     Base Layer: 0<br>
<br>
Layered non 3D texture (Array):<br>
     Immutable (it's a texture view, see _mesa_set_texture_view_state):<br>
         Layers: correct values of MinLayer and NumLayers is baked into <br>
texObject in texture_view and in _mesa_set_texture_view_state<br>
         Base Layer: MinLayer<br>
<br>
     Mutable (MinLayer is always 0 since it can be set only via texture <br>
view which makes texture immutable):<br>
         Layers: array_len<br>
         Base Layer: 0<br></blockquote><div><br></div><div>Right.  Would you mind adding</div><div><br></div><div>assert(obj->Immutable || obj->MinLayer == 0);</div><div><br></div><div>With that,</div><div><br></div><div>Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
So while the code from my pov should work it could be presented better.<br>
However I'm not sure what will be better:<br>
<br>
     } else if (obj->Immutable) {<br>
         base_layer = obj->MinLayer;<br>
         num_layers = obj->NumLayers;<br>
     } else {<br>
         base_layer = 0;<br>
         num_layers = mt->surf.logical_level0_px.array_len;<br>
     }<br>
<br>
Or always calculate base_layer as "obj->MinLayer + u->_Layer" before the <br>
conditions,<br>
     which will look slightly misleading and induce questions of why we <br>
don't subtract them from array_len.<br>
<br>
What do you think?<br>
<br>
Thanks!<br>
<br>
On 11/14/18 12:01 AM, Ilia Mirkin wrote:<br>
> On Tue, Nov 13, 2018 at 4:53 PM Jason Ekstrand <<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>> wrote:<br>
>> On Mon, Sep 10, 2018 at 10:21 AM Danylo Piliaiev <<a href="mailto:danylo.piliaiev@gmail.com" target="_blank">danylo.piliaiev@gmail.com</a>> wrote:<br>
>>> Handle all cases in calculation of layers count for isl_view<br>
>>> taking into account texture view and image unit.<br>
>>> st_convert_image was taken as a reference.<br>
>>><br>
>>> When u->Layered is true the whole level is taken with respect to<br>
>>> image view. In other case only one layer is taken.<br>
>>><br>
>>> v3: (Józef Kucia and Ilia Mirkin)<br>
>>>      - Rewrote patch by taking st_convert_image as a reference<br>
>>>      - Removed now unused get_image_num_layers function<br>
>>>      - Changed commit message<br>
>>><br>
>>> Fixes: 5a8c8903<br>
>>> Bugzilla: <a href="https://bugs.freedesktop.org/show_bug.cgi?id=107856" rel="noreferrer" target="_blank">https://bugs.freedesktop.org/show_bug.cgi?id=107856</a><br>
>>><br>
>>> Signed-off-by: Danylo Piliaiev <<a href="mailto:danylo.piliaiev@globallogic.com" target="_blank">danylo.piliaiev@globallogic.com</a>><br>
>>> ---<br>
>>>   .../drivers/dri/i965/brw_wm_surface_state.c   | 32 ++++++++++---------<br>
>>>   1 file changed, 17 insertions(+), 15 deletions(-)<br>
>>><br>
>>> diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c<br>
>>> index 944762ec46..9bfe6e2037 100644<br>
>>> --- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c<br>
>>> +++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c<br>
>>> @@ -1499,18 +1499,6 @@ update_buffer_image_param(struct brw_context *brw,<br>
>>>      param->stride[0] = _mesa_get_format_bytes(u->_ActualFormat);<br>
>>>   }<br>
>>><br>
>>> -static unsigned<br>
>>> -get_image_num_layers(const struct intel_mipmap_tree *mt, GLenum target,<br>
>>> -                     unsigned level)<br>
>>> -{<br>
>>> -   if (target == GL_TEXTURE_CUBE_MAP)<br>
>>> -      return 6;<br>
>>> -<br>
>>> -   return target == GL_TEXTURE_3D ?<br>
>>> -      minify(mt->surf.logical_level0_px.depth, level) :<br>
>>> -      mt->surf.logical_level0_px.array_len;<br>
>>> -}<br>
>>> -<br>
>>>   static void<br>
>>>   update_image_surface(struct brw_context *brw,<br>
>>>                        struct gl_image_unit *u,<br>
>>> @@ -1541,14 +1529,28 @@ update_image_surface(struct brw_context *brw,<br>
>>>         } else {<br>
>>>            struct intel_texture_object *intel_obj = intel_texture_object(obj);<br>
>>>            struct intel_mipmap_tree *mt = intel_obj->mt;<br>
>>> -         const unsigned num_layers = u->Layered ?<br>
>>> -            get_image_num_layers(mt, obj->Target, u->Level) : 1;<br>
>>> +<br>
>>> +         unsigned base_layer, num_layers;<br>
>>> +         if (u->Layered) {<br>
>>> +            if (obj->Target == GL_TEXTURE_3D) {<br>
>>> +               base_layer = 0;<br>
>>> +               num_layers = minify(mt->surf.logical_level0_px.depth, u->Level);<br>
>>> +            } else {<br>
>>> +               base_layer = obj->MinLayer;<br>
>>> +               num_layers = obj->Immutable ?<br>
>>> +                                obj->NumLayers :<br>
>>> +                                mt->surf.logical_level0_px.array_len;<br>
>><br>
>> Doesn't this need to be array_len - base_layer?  I'm not sure on the others without digging.<br>
> Probably not intuitively obvious, but MinLayer/NumLayers are only set<br>
> for Immutable textures.<br>
><br>
>    -ilia<br>
<br>
</blockquote></div></div>