From d26084f0cae078d2379c08f9f2266d82abd785a8 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 18 Jan 2018 16:47:43 -0800 Subject: [PATCH] Allow us to catch invalid slots at batch setup time --- libraries/gpu/src/gpu/Batch.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/libraries/gpu/src/gpu/Batch.cpp b/libraries/gpu/src/gpu/Batch.cpp index c432e19368..7141a7eac7 100644 --- a/libraries/gpu/src/gpu/Batch.cpp +++ b/libraries/gpu/src/gpu/Batch.cpp @@ -14,9 +14,12 @@ #include +#include "GPULogging.h" + #if defined(NSIGHT_FOUND) #include "nvToolsExt.h" + ProfileRangeBatch::ProfileRangeBatch(gpu::Batch& batch, const char *name) : _batch(batch) { _batch.pushProfileRange(name); } @@ -30,6 +33,11 @@ ProfileRangeBatch::~ProfileRangeBatch() { using namespace gpu; +// FIXME make these backend / pipeline dependent. +static const int MAX_NUM_UNIFORM_BUFFERS = 12; +static const int MAX_NUM_RESOURCE_BUFFERS = 16; +static const int MAX_NUM_RESOURCE_TEXTURES = 16; + size_t Batch::_commandsMax { BATCH_PREALLOCATE_MIN }; size_t Batch::_commandOffsetsMax { BATCH_PREALLOCATE_MIN }; size_t Batch::_paramsMax { BATCH_PREALLOCATE_MIN }; @@ -281,7 +289,9 @@ void Batch::setStateScissorRect(const Vec4i& rect) { void Batch::setUniformBuffer(uint32 slot, const BufferPointer& buffer, Offset offset, Offset size) { ADD_COMMAND(setUniformBuffer); - + if (slot >= MAX_NUM_UNIFORM_BUFFERS) { + qCWarning(gpulogging) << "Slot" << slot << "exceeds max uniform buffer count of" << MAX_NUM_UNIFORM_BUFFERS; + } _params.emplace_back(size); _params.emplace_back(offset); _params.emplace_back(_buffers.cache(buffer)); @@ -294,6 +304,9 @@ void Batch::setUniformBuffer(uint32 slot, const BufferView& view) { void Batch::setResourceBuffer(uint32 slot, const BufferPointer& buffer) { ADD_COMMAND(setResourceBuffer); + if (slot >= MAX_NUM_RESOURCE_BUFFERS) { + qCWarning(gpulogging) << "Slot" << slot << "exceeds max resources buffer count of" << MAX_NUM_RESOURCE_BUFFERS; + } _params.emplace_back(_buffers.cache(buffer)); _params.emplace_back(slot); @@ -302,6 +315,10 @@ void Batch::setResourceBuffer(uint32 slot, const BufferPointer& buffer) { void Batch::setResourceTexture(uint32 slot, const TexturePointer& texture) { ADD_COMMAND(setResourceTexture); + if (slot >= MAX_NUM_RESOURCE_TEXTURES) { + qCWarning(gpulogging) << "Slot" << slot << "exceeds max texture count of" << MAX_NUM_RESOURCE_TEXTURES; + } + _params.emplace_back(_textures.cache(texture)); _params.emplace_back(slot); }