Skip to content

Commit

Permalink
[code] Compatibility with Qt 6.7+ RHI API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Jul 6, 2023
1 parent 82fa034 commit cb39194
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 29 deletions.
10 changes: 6 additions & 4 deletions src/plugins/score-plugin-avnd/Crousti/GpuComputeNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,13 @@ struct GpuComputeRenderer final : ComputeRendererBaseType<Node_T>
ossia::flat_map<int, QRhiBuffer*> createdUbos;
ossia::flat_map<int, QRhiTexture*> createdTexs;

#if QT_VERSION < QT_VERSION_CHECK(6, 7, 0)
std::vector<QRhiBufferReadbackResult*> bufReadbacks;
std::vector<QRhiReadbackResult*> texReadbacks;

void addReadback(QRhiBufferReadbackResult* r) { bufReadbacks.push_back(r); }
void addReadback(QRhiReadbackResult* r) { texReadbacks.push_back(r); }
#endif

std::vector<QRhiReadbackResult*> texReadbacks;
void addReadback(QRhiReadbackResult* r) { texReadbacks.push_back(r); }
GpuComputeRenderer(const GpuComputeNode<Node_T>& p)
: ComputeRendererBaseType<Node_T>{}
, parent{p}
Expand Down Expand Up @@ -407,9 +408,11 @@ struct GpuComputeRenderer final : ComputeRendererBaseType<Node_T>
}

// Clear the readbacks
#if QT_VERSION < QT_VERSION_CHECK(6, 7, 0)
for(auto rb : this->bufReadbacks)
delete rb;
this->bufReadbacks.clear();
#endif
for(auto rb : this->texReadbacks)
delete rb;
this->texReadbacks.clear();
Expand All @@ -432,7 +435,6 @@ struct GpuComputeRenderer final : ComputeRendererBaseType<Node_T>
}
};


template <typename Node_T>
inline score::gfx::OutputNodeRenderer*
GpuComputeNode<Node_T>::createRenderer(score::gfx::RenderList& r) const noexcept
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/score-plugin-avnd/Crousti/GpuUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ auto samples(C c)
return -1;
}


struct handle_release
{
QRhi& rhi;
Expand Down Expand Up @@ -558,7 +557,6 @@ struct handle_update
}
};


struct generate_shaders
{
template <typename T, int N>
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/score-plugin-gfx/Gfx/Graph/RenderState.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#pragma once
#include <QtGui/private/qrhi_p.h>

#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
using QRhiBufferReadbackResult = QRhiReadbackResult;
#endif

class QOffscreenSurface;
namespace score::gfx
{
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/score-plugin-gfx/Gfx/Graph/ShaderCache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

#include <ossia/detail/hash_map.hpp>

#if __has_include(<QtShaderTools/rhi/qshaderbaker.h>)
#include <QtShaderTools/rhi/qshaderbaker.h>
#else
#include <QtShaderTools/private/qshaderbaker_p.h>
#endif

namespace score::gfx
{
Expand Down
53 changes: 30 additions & 23 deletions src/plugins/score-plugin-gfx/Gfx/Graph/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,18 @@ void replaceBuffer(
// const auto bufType = newBuffer->resourceType();
for(QRhiShaderResourceBinding& b : tmp)
{
if(b.data()->binding == binding)
auto d = reinterpret_cast<QRhiShaderResourceBinding::Data*>(&b);
if(d->binding == binding)
{
switch(b.data()->type)
switch(d->type)
{
case QRhiShaderResourceBinding::Type::UniformBuffer:
b.data()->u.ubuf.buf = newBuffer;
d->u.ubuf.buf = newBuffer;
break;
case QRhiShaderResourceBinding::Type::BufferLoad:
case QRhiShaderResourceBinding::Type::BufferStore:
case QRhiShaderResourceBinding::Type::BufferLoadStore:
b.data()->u.sbuf.buf = newBuffer;
d->u.sbuf.buf = newBuffer;
break;
default:
break;
Expand All @@ -79,11 +80,12 @@ void replaceSampler(
{
for(QRhiShaderResourceBinding& b : tmp)
{
if(b.data()->binding == binding)
auto d = reinterpret_cast<QRhiShaderResourceBinding::Data*>(&b);
if(d->binding == binding)
{
if(b.data()->type == QRhiShaderResourceBinding::Type::SampledTexture)
if(d->type == QRhiShaderResourceBinding::Type::SampledTexture)
{
b.data()->u.stex.texSamplers[0].sampler = newSampler;
d->u.stex.texSamplers[0].sampler = newSampler;
}
}
}
Expand All @@ -94,17 +96,18 @@ void replaceTexture(
{
for(QRhiShaderResourceBinding& b : tmp)
{
if(b.data()->binding == binding)
auto d = reinterpret_cast<QRhiShaderResourceBinding::Data*>(&b);
if(d->binding == binding)
{
switch(b.data()->type)
switch(d->type)
{
case QRhiShaderResourceBinding::Type::SampledTexture:
b.data()->u.stex.texSamplers[0].tex = newTexture;
d->u.stex.texSamplers[0].tex = newTexture;
break;
case QRhiShaderResourceBinding::Type::ImageLoad:
case QRhiShaderResourceBinding::Type::ImageStore:
case QRhiShaderResourceBinding::Type::ImageLoadStore:
b.data()->u.simage.tex = newTexture;
d->u.simage.tex = newTexture;
break;
default:
break;
Expand Down Expand Up @@ -158,12 +161,13 @@ void replaceSampler(
tmp.assign(srb.cbeginBindings(), srb.cendBindings());
for(QRhiShaderResourceBinding& b : tmp)
{
if(b.data()->type == QRhiShaderResourceBinding::Type::SampledTexture)
auto d = reinterpret_cast<QRhiShaderResourceBinding::Data*>(&b);
if(d->type == QRhiShaderResourceBinding::Type::SampledTexture)
{
SCORE_ASSERT(b.data()->u.stex.count >= 1);
if(b.data()->u.stex.texSamplers[0].sampler == oldSampler)
SCORE_ASSERT(d->u.stex.count >= 1);
if(d->u.stex.texSamplers[0].sampler == oldSampler)
{
b.data()->u.stex.texSamplers[0].sampler = newSampler;
d->u.stex.texSamplers[0].sampler = newSampler;
}
}
}
Expand All @@ -180,12 +184,13 @@ void replaceTexture(
tmp.assign(srb.cbeginBindings(), srb.cendBindings());
for(QRhiShaderResourceBinding& b : tmp)
{
if(b.data()->type == QRhiShaderResourceBinding::Type::SampledTexture)
auto d = reinterpret_cast<QRhiShaderResourceBinding::Data*>(&b);
if(d->type == QRhiShaderResourceBinding::Type::SampledTexture)
{
SCORE_ASSERT(b.data()->u.stex.count >= 1);
if(b.data()->u.stex.texSamplers[0].sampler == sampler)
SCORE_ASSERT(d->u.stex.count >= 1);
if(d->u.stex.texSamplers[0].sampler == sampler)
{
b.data()->u.stex.texSamplers[0].tex = newTexture;
d->u.stex.texSamplers[0].tex = newTexture;
}
}
}
Expand All @@ -203,12 +208,14 @@ void replaceTexture(
{
bindings.push_back(*it);

auto& binding = *bindings.back().data();
if(binding.type == QRhiShaderResourceBinding::SampledTexture)
auto& binding = bindings.back();

auto& d = *reinterpret_cast<QRhiShaderResourceBinding::Data*>(&binding);
if(d.type == QRhiShaderResourceBinding::SampledTexture)
{
if(binding.u.stex.texSamplers[0].tex == old_tex)
if(d.u.stex.texSamplers[0].tex == old_tex)
{
binding.u.stex.texSamplers[0].tex = new_tex;
d.u.stex.texSamplers[0].tex = new_tex;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
#include <QLineEdit>
#include <QOffscreenSurface>
#include <QSpinBox>

#if __has_include(<QtGui/rhi/qrhi_platform.h>)
#include <QtGui/rhi/qrhi_platform.h>
#else
#include <QtGui/private/qrhigles2_p_p.h>
#endif

#include <shmdata/writer.hpp>

Expand Down

0 comments on commit cb39194

Please sign in to comment.