<div dir="auto">the algorithm i was going to use would get the union of the sets of live variables at the barriers (union over barriers), create an array of structs that holds them all, then for each barrier, insert the code to store all live variables, then end the for loop over tid_in_workgroup, then run the memory barrier, then start another for loop over tid_in_workgroup, then load all live variables.<div dir="auto">Jacob Lifshay</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Feb 13, 2017 08:45, "Nicolai Hähnle" <<a href="mailto:nhaehnle@gmail.com">nhaehnle@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">[ re-adding mesa-dev on the assumption that it got dropped by accident ]<br>
<br>
On 13.02.2017 17:27, Jacob Lifshay wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
        I would start a thread for each cpu, then have each thread run the<br>
        compute shader a number of times instead of having a thread per<br>
        shader<br>
        invocation.<br>
<br>
<br>
    This will not work.<br>
<br>
    Please, read again what the barrier() instruction does: When the<br>
    barrier() call is reached, _all_ threads within the workgroup are<br>
    supposed to be run until they reach that barrier() call.<br>
<br>
<br>
to clarify, I had meant that each os thread would run the sections of<br>
the shader between the barriers for all the shaders in a work group,<br>
then, when it finished the work group, it would go to the next work<br>
group assigned to the os thread.<br>
<br>
so, if our shader is:<br>
a = b + tid;<br>
barrier();<br>
d = e + f;<br>
<br>
and our simd width is 4, our work-group size is 128, and we have 16 os<br>
threads, then it will run for each os thread:<br>
for(workgroup = os_thread_index; workgroup < workgroup_count; workgroup++)<br>
{<br>
    for(tid_in_workgroup = 0; tid_in_workgroup < 128; tid_in_workgroup += 4)<br>
    {<br>
        ivec4 tid = ivec4(0, 1, 2, 3) + ivec4(tid_in_workgroup +<br>
workgroup * 128);<br>
        a[tid_in_workgroup / 4] = ivec_add(b[tid_in_workgroup / 4], tid);<br>
    }<br>
    memory_fence(); // if needed<br>
    for(tid_in_workgroup = 0; tid_in_workgroup < 128; tid_in_workgroup += 4)<br>
    {<br>
        d[tid_in_workgroup / 4] = vec_add(e[tid_in_workgroup / 4],<br>
f[tid_in_workgroup / 4]);<br>
    }<br>
}<br>
// after this, we run the next rendering or compute job<br>
</blockquote>
<br>
Okay good, that's the right concept.<br>
<br>
Actually doing that is not at all straightforward though: consider that the barrier() might occur inside a loop in the shader.<br>
<br>
So if you implemented that within the framework of llvmpipe, you'd make a lot of people very happy: it would allow finally adding compute shader support to llvmpipe. Mind you, that in itself would already be a pretty decent-sized project for GSoC!<br>
<br>
Cheers,<br>
Nicolai<br>
</blockquote></div></div>