[Mesa-dev] Question about implementing viewport transfer and const load in nir

Qiang Yu yuq825 at gmail.com
Wed Aug 30 07:02:51 UTC 2017


Thanks Kenneth, here attach my RFC prototype patch implementing these,
and comments follows.

>> When working on lima gp compiler, I come across two problems about
>> inserting extra uniform
>> and instructions in nir for the driver and don't know where's the
>> right place to do it. So I'd like
>> to hear your opinion and if there's other driver already did so.
>>
>> 1. viewport transfer
>> lima gp needs embed viewport transfer into vertex shader, so need to
>> insert a uniform which
>> holds the scale and transfer and some instruction to apply the
>> calculation to the gl_Position
>> varying output. If do this in driver callback create_vs_state(), seems
>> won't affect the state
>> tracker to allocate uniform space for it, maybe add something in
>> st_create_vp_variant()?
>
> The best way to handle this is probably to use the statevars mechanism.
> Extend src/mesa/program/prog_statevars.[ch] with new STATE_VIEWPORT_*
> enum values, and populate it with the viewport values you need from the
> GL context.
>
> Then, you can just refer to special built-in uniforms in NIR.  See how
> nir_lower_wpos_ytransform.c does this, for example.
So you mean add a STATE for the viewport and implement all in a none-driver
spec way? In fact my prototype just use the STATE_INTERNAL_DRIVER
and add a new pipe_context callback to do all this before st_finalize_nir.
I think I can move the viewport part out of driver spec way, but not the const
part.

>
>> 2. const load
>> lima gp needs const be loaded just as uniform, so I have to allocate
>> uniform space for them.
>> Besides the same problem as 1 (where to do it), the const node may be
>> eliminated after driver
>> nir optimization and won't have a base filed as uniform.
>
> Not sure what to recommend here.  It might be best to handle it as part
> of your compiler backend.  Or, perhaps late in the process, you could
> convert load_const into load_uniform intrinsics.  You can decide on the
> constant buffer layout yourself, and just set the driver locations / load
> offsets yourself...
If I don't allocate space before st_finalize_nir, how does st part know to
reserve constant buffer space for it?

>
>> Seems some of these (space allocation) need be done in non-driver
>> layer and some (instruction
>> insertion and uniform base assign to const) can be done in driver.
>>
>> BTW. lima gp can only have one uniform buffer, so I can't just use a
>> dedicated uniform buffer
>> for viewport transfer and const uniform.
>
> Makes sense.  That shouldn't be a problem.
I mean "can't"...

Regards,
Qiang
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0004-lima-add-lower-constant-to-uniform.patch
Type: text/x-patch
Size: 8582 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170830/d7e669a2/attachment-0004.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-lima-add-lower-viewport-transform-pass.patch
Type: text/x-patch
Size: 7866 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170830/d7e669a2/attachment-0005.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-nir-add-nir_load_array_var.patch
Type: text/x-patch
Size: 1736 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170830/d7e669a2/attachment-0006.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-gallium-st-add-pipe_context-vs_nir_before_finalize.patch
Type: text/x-patch
Size: 1862 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170830/d7e669a2/attachment-0007.bin>


More information about the mesa-dev mailing list