Kenneth Graunke <kenn...@whitecape.org> writes: > [ Unknown signature status ] > On Saturday, August 26, 2017 6:40:14 AM PDT Qiang Yu wrote: >> Hi guys, >> >> 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.
In my case, VC4 has lots of custom state-dependent uniforms, and uniform upload is where we spend most of our CPU time (basically each draw call needs to re-upload the uniform stream, and the stream has to be in the order they will be used by instructions, rather than where they appear in NIR). So, I've just got an array of {type of uniform, some sort of index} tuples attached to the compiled shader to represent the stream. Each can reference "offset in gallium const buffer" or "a load_const value" or "my special viewport x scale" or whatever, and I walk it at draw time to write out my stream. >> 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... Lowering to load_uniform sounds like the way to go to me.
signature.asc
Description: PGP signature
_______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev