Commit 771d4a25 authored by Laszlo Agocs's avatar Laszlo Agocs

gl: Reduce tex param changes

parent 6c868e83
......@@ -842,7 +842,6 @@ void QRhiD3D11::updateShaderResourceBindings(QD3D11ShaderResourceBindings *srbD)
srbD->fssamplers.clear();
srbD->fsshaderresources.clear();
srbD->boundResourceData.resize(srbD->sortedBindings.count());
for (int i = 0, ie = srbD->sortedBindings.count(); i != ie; ++i) {
const QRhiShaderResourceBinding &b(srbD->sortedBindings[i]);
QD3D11ShaderResourceBindings::BoundResourceData &bd(srbD->boundResourceData[i]);
......@@ -1628,6 +1627,8 @@ bool QD3D11ShaderResourceBindings::build()
return a.binding < b.binding;
});
boundResourceData.resize(sortedBindings.count());
QRHI_RES_RHI(QRhiD3D11);
rhiD->updateShaderResourceBindings(this);
......
......@@ -195,6 +195,8 @@ struct QD3D11ShaderResourceBindings : public QRhiShaderResourceBindings
friend class QRhiD3D11;
};
Q_DECLARE_TYPEINFO(QD3D11ShaderResourceBindings::BoundResourceData, Q_MOVABLE_TYPE);
struct QD3D11GraphicsPipeline : public QRhiGraphicsPipeline
{
QD3D11GraphicsPipeline(QRhiImplementation *rhi);
......@@ -330,6 +332,8 @@ struct QD3D11CommandBuffer : public QRhiCommandBuffer
}
};
Q_DECLARE_TYPEINFO(QD3D11CommandBuffer::Command, Q_MOVABLE_TYPE);
struct QD3D11SwapChain : public QRhiSwapChain
{
QD3D11SwapChain(QRhiImplementation *rhi);
......
......@@ -1000,8 +1000,11 @@ void QRhiGles2::executeBindGraphicsPipeline(QRhiGraphicsPipeline *ps, QRhiShader
void QRhiGles2::setChangedUniforms(QGles2GraphicsPipeline *psD, QRhiShaderResourceBindings *srb, bool changedOnly)
{
QGles2ShaderResourceBindings *srbD = QRHI_RES(QGles2ShaderResourceBindings, srb);
for (int i = 0, ie = srbD->m_bindings.count(); i != ie; ++i) {
const QRhiShaderResourceBinding &b(srbD->m_bindings[i]);
QGles2ShaderResourceBindings::BoundResourceData &bd(srbD->boundResourceData[i]);
switch (b.type) {
case QRhiShaderResourceBinding::UniformBuffer:
{
......@@ -1067,18 +1070,26 @@ void QRhiGles2::setChangedUniforms(QGles2GraphicsPipeline *psD, QRhiShaderResour
QGles2Texture *texD = QRHI_RES(QGles2Texture, b.stex.tex);
QGles2Sampler *samplerD = QRHI_RES(QGles2Sampler, b.stex.sampler);
const bool textureChanged = QRHI_RES(QGles2Texture, b.stex.tex)->generation != bd.stex.texGeneration;
if (textureChanged)
bd.stex.texGeneration = QRHI_RES(QGles2Texture, b.stex.tex)->generation;
const bool samplerChanged = QRHI_RES(QGles2Sampler, b.stex.sampler)->generation != bd.stex.samplerGeneration;
if (samplerChanged)
bd.stex.samplerGeneration = QRHI_RES(QGles2Sampler, b.stex.sampler)->generation;
int texUnit = 0;
for (QGles2GraphicsPipeline::Sampler &sampler : psD->samplers) {
if (sampler.binding == b.binding) {
// ### should this use sampler->generation or something to prevent doing it over and over again
f->glActiveTexture(GL_TEXTURE0 + texUnit);
f->glBindTexture(texD->target, texD->texture);
f->glTexParameteri(texD->target, GL_TEXTURE_MIN_FILTER, samplerD->glminfilter);
f->glTexParameteri(texD->target, GL_TEXTURE_MAG_FILTER, samplerD->glmagfilter);
f->glTexParameteri(texD->target, GL_TEXTURE_WRAP_S, samplerD->glwraps);
f->glTexParameteri(texD->target, GL_TEXTURE_WRAP_T, samplerD->glwrapt);
f->glTexParameteri(texD->target, GL_TEXTURE_WRAP_R, samplerD->glwrapr);
if (textureChanged || samplerChanged) {
f->glTexParameteri(texD->target, GL_TEXTURE_MIN_FILTER, samplerD->glminfilter);
f->glTexParameteri(texD->target, GL_TEXTURE_MAG_FILTER, samplerD->glmagfilter);
f->glTexParameteri(texD->target, GL_TEXTURE_WRAP_S, samplerD->glwraps);
f->glTexParameteri(texD->target, GL_TEXTURE_WRAP_T, samplerD->glwrapt);
f->glTexParameteri(texD->target, GL_TEXTURE_WRAP_R, samplerD->glwrapr);
}
f->glUniform1i(sampler.glslLocation, texUnit);
++texUnit;
......@@ -1323,6 +1334,7 @@ bool QGles2Texture::build()
rhiD->f->glTexImage2D(target, 0, glintformat, size.width(), size.height(), 0, glformat, gltype, nullptr);
}
generation += 1;
return true;
}
......@@ -1345,6 +1357,7 @@ bool QGles2Sampler::build()
glwrapt = toGlWrapMode(m_addressV);
glwrapr = toGlWrapMode(m_addressW);
generation += 1;
return true;
}
......@@ -1479,6 +1492,26 @@ void QGles2ShaderResourceBindings::release()
bool QGles2ShaderResourceBindings::build()
{
boundResourceData.resize(m_bindings.count());
for (int i = 0, ie = m_bindings.count(); i != ie; ++i) {
const QRhiShaderResourceBinding &b(m_bindings[i]);
BoundResourceData &bd(boundResourceData[i]);
switch (b.type) {
case QRhiShaderResourceBinding::UniformBuffer:
// nothing, we do not track buffer generations
break;
case QRhiShaderResourceBinding::SampledTexture:
// Start with values that will fail the first comparison for sure.
bd.stex.texGeneration = UINT_MAX; // QRHI_RES(QGles2Texture, b.stex.tex)->generation;
bd.stex.samplerGeneration = UINT_MAX; // QRHI_RES(QGles2Sampler, b.stex.sampler)->generation;
break;
default:
Q_UNREACHABLE();
break;
}
}
generation += 1;
return true;
}
......
......@@ -91,6 +91,8 @@ struct QGles2Texture : public QRhiTexture
GLenum glintformat;
GLenum glformat;
GLenum gltype;
uint generation = 0;
friend class QRhiGles2;
};
......@@ -106,6 +108,8 @@ struct QGles2Sampler : public QRhiSampler
GLenum glwraps;
GLenum glwrapt;
GLenum glwrapr;
uint generation = 0;
friend class QRhiGles2;
};
......@@ -156,10 +160,23 @@ struct QGles2ShaderResourceBindings : public QRhiShaderResourceBindings
void release() override;
bool build() override;
struct BoundSampledTextureData {
uint texGeneration;
uint samplerGeneration;
};
struct BoundResourceData {
union {
BoundSampledTextureData stex;
};
};
QVector<BoundResourceData> boundResourceData;
uint generation = 0;
friend class QRhiGles2;
};
Q_DECLARE_TYPEINFO(QGles2ShaderResourceBindings::BoundResourceData, Q_MOVABLE_TYPE);
struct QGles2GraphicsPipeline : public QRhiGraphicsPipeline
{
QGles2GraphicsPipeline(QRhiImplementation *rhi);
......
......@@ -13,38 +13,40 @@ test cubemap face as target
face cubemap readback? (test vk/d3d, impl for gl)
cbuffer alignment rules - some things fail to translate (to hlsl e.g. with structs), which is fine but how to mitigate
resource import/export, what's the co-op story?
copy-only passes for kicking off transfers early? (copy/transfer queue?)
copyimage (color and ds, no resolve or transforms here)
does reading back an msaa swapchain buffer work?
msaa offscreen (msaa texture. no readback.)
resolveimage (color and ds, only to resolve samples)
threading options? secondary command lists?
mipmap generation?
figure sg out for minimizing viewport/scissor cmds
vk: test FrameOpDeviceLost somehow
d3d device loss?
more what-if-resource-rebuilt cases
anisotropic
d3d: support DxcCompiler (in addition to d3dcompiler?) when runtime compiling hlsl?
gl: more ubuf types
gl: reduce state, reduce texparam
gl: tex size stuff (npot etc.)
gl: tex formats (texture, readback)
more QImage->tex formats
vk compressed tex: could it consume a complete ktx without any memcpys?
multi-buffer (region) readback?
depth readback?
d3d, gl, mtl: cache shader sources?
advanced blend modes?
resize to 0 width or height fails (vk)
gl: ubuf structs, arrays
gl: target QOpenGLWindow/Widget?
vk: subpasses?
compute?
vk: support instanceStepRate via VK_EXT_vertex_attribute_divisor
optional:
threading options? secondary command lists?
copy-only passes for kicking off transfers early? (copy/transfer queue?)
d3d: support DxcCompiler (in addition to d3dcompiler?) when runtime compiling hlsl?
tessellation?
indirect draw?
vk: subpasses?
more tex: 3d, array?
vk: support instanceStepRate via VK_EXT_vertex_attribute_divisor
vk compressed tex: could it consume a complete ktx without any memcpys?
multi-buffer (region) readback?
depth readback?
shadertools:
dxc for d3d as an alternative to fxc?
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment