GPU: Enable printf only between render boundaries and use a stack
Printf buffer read needs to be inside render boundaries to work. Since render boundaries can be nested, use a stack. Fixes assert when quitting blender.
This commit is contained in:
@@ -120,7 +120,6 @@ GPUContext *GPU_context_create(void *ghost_window, void *ghost_context)
|
||||
void GPU_context_discard(GPUContext *ctx_)
|
||||
{
|
||||
Context *ctx = unwrap(ctx_);
|
||||
printf_end(ctx);
|
||||
delete ctx;
|
||||
active_ctx = nullptr;
|
||||
|
||||
@@ -140,7 +139,6 @@ void GPU_context_active_set(GPUContext *ctx_)
|
||||
Context *ctx = unwrap(ctx_);
|
||||
|
||||
if (active_ctx) {
|
||||
printf_end(active_ctx);
|
||||
active_ctx->deactivate();
|
||||
}
|
||||
|
||||
@@ -148,7 +146,6 @@ void GPU_context_active_set(GPUContext *ctx_)
|
||||
|
||||
if (ctx) {
|
||||
ctx->activate();
|
||||
printf_begin(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,7 +205,6 @@ void GPU_render_begin()
|
||||
* but should be fixed for Metal. */
|
||||
if (backend) {
|
||||
backend->render_begin();
|
||||
printf_end(active_ctx);
|
||||
printf_begin(active_ctx);
|
||||
}
|
||||
}
|
||||
@@ -218,7 +214,6 @@ void GPU_render_end()
|
||||
BLI_assert(backend);
|
||||
if (backend) {
|
||||
printf_end(active_ctx);
|
||||
printf_begin(active_ctx);
|
||||
backend->render_end();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,8 @@ class Context {
|
||||
static int context_counter;
|
||||
int context_id = 0;
|
||||
|
||||
GPUStorageBuf *printf_buf = nullptr;
|
||||
/* Used as a stack. Each render_begin/end pair will push pop from the stack. */
|
||||
Vector<GPUStorageBuf *> printf_buf;
|
||||
|
||||
protected:
|
||||
/** Thread on which this context is active. */
|
||||
|
||||
@@ -451,8 +451,8 @@ void GPU_shader_bind(GPUShader *gpu_shader)
|
||||
}
|
||||
}
|
||||
#if GPU_SHADER_PRINTF_ENABLE
|
||||
if (ctx->printf_buf) {
|
||||
GPU_storagebuf_bind(ctx->printf_buf, GPU_SHADER_PRINTF_SLOT);
|
||||
if (!ctx->printf_buf.is_empty()) {
|
||||
GPU_storagebuf_bind(ctx->printf_buf.last(), GPU_SHADER_PRINTF_SLOT);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -333,9 +333,10 @@ void printf_begin(Context *ctx)
|
||||
if (!shader::gpu_shader_dependency_has_printf()) {
|
||||
return;
|
||||
}
|
||||
BLI_assert(ctx->printf_buf == nullptr);
|
||||
ctx->printf_buf = GPU_storagebuf_create(GPU_SHADER_PRINTF_MAX_CAPACITY * sizeof(uint32_t));
|
||||
GPU_storagebuf_clear_to_zero(ctx->printf_buf);
|
||||
GPUStorageBuf *printf_buf = GPU_storagebuf_create(GPU_SHADER_PRINTF_MAX_CAPACITY *
|
||||
sizeof(uint32_t));
|
||||
GPU_storagebuf_clear_to_zero(printf_buf);
|
||||
ctx->printf_buf.append(printf_buf);
|
||||
}
|
||||
|
||||
void printf_end(Context *ctx)
|
||||
@@ -343,14 +344,14 @@ void printf_end(Context *ctx)
|
||||
if (ctx == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (ctx->printf_buf == nullptr) {
|
||||
if (ctx->printf_buf.is_empty()) {
|
||||
return;
|
||||
}
|
||||
GPUStorageBuf *printf_buf = ctx->printf_buf.pop_last();
|
||||
|
||||
Vector<uint32_t> data(GPU_SHADER_PRINTF_MAX_CAPACITY);
|
||||
GPU_storagebuf_read(ctx->printf_buf, data.data());
|
||||
GPU_storagebuf_free(ctx->printf_buf);
|
||||
ctx->printf_buf = nullptr;
|
||||
GPU_storagebuf_read(printf_buf, data.data());
|
||||
GPU_storagebuf_free(printf_buf);
|
||||
|
||||
uint32_t data_len = data[0];
|
||||
if (data_len == 0) {
|
||||
|
||||
Reference in New Issue
Block a user