imageworks/OpenShadingLanguage — pull request #330 by lgritz (2014-01-17 00:59:30+00:00)
Title: Buffer error output so a shader invocation's output is contiguous in logs

The aim of this patch is to buffer a shader's printf, warning, and error
outputs and then send them to the error manager in a single atomic chunk
rather than individually, so that each individual shader invocation will
have all of its console output appear contiguous in a log, rather than
haphazardly interleaved with the individual lines of other shader
invocations running concurrently in different threads.

The buffer lives in the ShadingContext, and any accumulated output is sent
to the renderer all at once (and protected by a mutex) when the shader
execution is finished. Also, for good measure, we flush again when the
app gives the context back to the ShadingSystem (in case that now, or in the
future, there's a code path that involves a ShadingContext that encounters
errors but never calls execute).

Most of the individual line changes in this patch are tracking down all the
places that ShadingSystem->{error,warning,message,info} were called, and
instead calling equivalent routines in the ShadingContext instead, so it will
be buffered. (We had to add those functions to the context, and we do so
leveraging the wonderful Tinyformat package.)

One minor API gotcha is that, embarrassingly,
RendererServices::get_texture_info had direct output to std::err! We
wanted to change that to a context->error() call, but unfortunately that
function (unlike most other RS calls) didn't accept a ShaderGlobals*, so
I had to change the API signature of that function to add it. This is a
non-back-compatible API change, but it's clearly fixing an oversight.

I made a ShadingSystem option "buffer_printf", which controls this. It
default to being on, and I think that's what most people will want, but
you can turn it off if for some reason you really, really want every
shader's printf or error output to be passed to the error manager
immediately without waiting until the shader invocation has completed
(with the obvious effect of, as before, possibly being interleaved with
output of other concurrent shader invocations).