diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2020-10-15 18:03:14 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2020-10-16 09:48:09 +0200 |
commit | 802d98d318d1dabf377d1030b81e99fe57f1b483 (patch) | |
tree | 6d92ebe86fdce4ec850f8a7b9e9673059f9644cc /src/gui | |
parent | aa6b865899f1ef1b9960d70763cbd19cc18fffd4 (diff) |
rhi: Unroll the res.binding factory functions
Trading typing in a few lines of straightforward code for a full
sizeof(QRhiShaderResourceBinding::Data) copy (with less fortunate
compilers that do not manage to optimize it away) is a bad deal.
Change-Id: If227320f8a9598508c1fe02c4f56e6d75f0a787b
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/rhi/qrhi.cpp | 70 |
1 files changed, 59 insertions, 11 deletions
diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index 5db0791322..b29e9bc8f5 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -2992,9 +2992,14 @@ QRhiShaderResourceBinding QRhiShaderResourceBinding::uniformBuffer( int binding, StageFlags stage, QRhiBuffer *buf, int offset, int size) { Q_ASSERT(size > 0); - QRhiShaderResourceBinding b = uniformBuffer(binding, stage, buf); + QRhiShaderResourceBinding b; + b.d.binding = binding; + b.d.stage = stage; + b.d.type = UniformBuffer; + b.d.u.ubuf.buf = buf; b.d.u.ubuf.offset = offset; b.d.u.ubuf.maybeSize = size; + b.d.u.ubuf.hasDynamicOffset = false; return b; } @@ -3020,7 +3025,14 @@ QRhiShaderResourceBinding QRhiShaderResourceBinding::uniformBuffer( QRhiShaderResourceBinding QRhiShaderResourceBinding::uniformBufferWithDynamicOffset( int binding, StageFlags stage, QRhiBuffer *buf, int size) { - QRhiShaderResourceBinding b = uniformBuffer(binding, stage, buf, 0, size); + Q_ASSERT(size > 0); + QRhiShaderResourceBinding b; + b.d.binding = binding; + b.d.stage = stage; + b.d.type = UniformBuffer; + b.d.u.ubuf.buf = buf; + b.d.u.ubuf.offset = 0; + b.d.u.ubuf.maybeSize = size; b.d.u.ubuf.hasDynamicOffset = true; return b; } @@ -3045,8 +3057,14 @@ QRhiShaderResourceBinding QRhiShaderResourceBinding::uniformBufferWithDynamicOff QRhiShaderResourceBinding QRhiShaderResourceBinding::sampledTexture( int binding, StageFlags stage, QRhiTexture *tex, QRhiSampler *sampler) { - const TextureAndSampler texSampler = { tex, sampler }; - return sampledTextures(binding, stage, 1, &texSampler); + QRhiShaderResourceBinding b; + b.d.binding = binding; + b.d.stage = stage; + b.d.type = SampledTexture; + b.d.u.stex.count = 1; + b.d.u.stex.texSamplers[0].tex = tex; + b.d.u.stex.texSamplers[0].sampler = sampler; + return b; } /*! @@ -3148,8 +3166,12 @@ QRhiShaderResourceBinding QRhiShaderResourceBinding::imageLoad( QRhiShaderResourceBinding QRhiShaderResourceBinding::imageStore( int binding, StageFlags stage, QRhiTexture *tex, int level) { - QRhiShaderResourceBinding b = imageLoad(binding, stage, tex, level); + QRhiShaderResourceBinding b; + b.d.binding = binding; + b.d.stage = stage; b.d.type = ImageStore; + b.d.u.simage.tex = tex; + b.d.u.simage.level = level; return b; } @@ -3172,8 +3194,12 @@ QRhiShaderResourceBinding QRhiShaderResourceBinding::imageStore( QRhiShaderResourceBinding QRhiShaderResourceBinding::imageLoadStore( int binding, StageFlags stage, QRhiTexture *tex, int level) { - QRhiShaderResourceBinding b = imageLoad(binding, stage, tex, level); + QRhiShaderResourceBinding b; + b.d.binding = binding; + b.d.stage = stage; b.d.type = ImageLoadStore; + b.d.u.simage.tex = tex; + b.d.u.simage.level = level; return b; } @@ -3223,7 +3249,11 @@ QRhiShaderResourceBinding QRhiShaderResourceBinding::bufferLoad( int binding, StageFlags stage, QRhiBuffer *buf, int offset, int size) { Q_ASSERT(size > 0); - QRhiShaderResourceBinding b = bufferLoad(binding, stage, buf); + QRhiShaderResourceBinding b; + b.d.binding = binding; + b.d.stage = stage; + b.d.type = BufferLoad; + b.d.u.sbuf.buf = buf; b.d.u.sbuf.offset = offset; b.d.u.sbuf.maybeSize = size; return b; @@ -3246,8 +3276,13 @@ QRhiShaderResourceBinding QRhiShaderResourceBinding::bufferLoad( QRhiShaderResourceBinding QRhiShaderResourceBinding::bufferStore( int binding, StageFlags stage, QRhiBuffer *buf) { - QRhiShaderResourceBinding b = bufferLoad(binding, stage, buf); + QRhiShaderResourceBinding b; + b.d.binding = binding; + b.d.stage = stage; b.d.type = BufferStore; + b.d.u.sbuf.buf = buf; + b.d.u.sbuf.offset = 0; + b.d.u.sbuf.maybeSize = 0; // entire buffer return b; } @@ -3270,7 +3305,11 @@ QRhiShaderResourceBinding QRhiShaderResourceBinding::bufferStore( int binding, StageFlags stage, QRhiBuffer *buf, int offset, int size) { Q_ASSERT(size > 0); - QRhiShaderResourceBinding b = bufferStore(binding, stage, buf); + QRhiShaderResourceBinding b; + b.d.binding = binding; + b.d.stage = stage; + b.d.type = BufferStore; + b.d.u.sbuf.buf = buf; b.d.u.sbuf.offset = offset; b.d.u.sbuf.maybeSize = size; return b; @@ -3293,8 +3332,13 @@ QRhiShaderResourceBinding QRhiShaderResourceBinding::bufferStore( QRhiShaderResourceBinding QRhiShaderResourceBinding::bufferLoadStore( int binding, StageFlags stage, QRhiBuffer *buf) { - QRhiShaderResourceBinding b = bufferLoad(binding, stage, buf); + QRhiShaderResourceBinding b; + b.d.binding = binding; + b.d.stage = stage; b.d.type = BufferLoadStore; + b.d.u.sbuf.buf = buf; + b.d.u.sbuf.offset = 0; + b.d.u.sbuf.maybeSize = 0; // entire buffer return b; } @@ -3317,7 +3361,11 @@ QRhiShaderResourceBinding QRhiShaderResourceBinding::bufferLoadStore( int binding, StageFlags stage, QRhiBuffer *buf, int offset, int size) { Q_ASSERT(size > 0); - QRhiShaderResourceBinding b = bufferLoadStore(binding, stage, buf); + QRhiShaderResourceBinding b; + b.d.binding = binding; + b.d.stage = stage; + b.d.type = BufferLoadStore; + b.d.u.sbuf.buf = buf; b.d.u.sbuf.offset = offset; b.d.u.sbuf.maybeSize = size; return b; |