aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@theqtcompany.com>2016-06-10 21:12:28 +0200
committerLaszlo Agocs <laszlo.agocs@theqtcompany.com>2016-06-10 21:12:28 +0200
commit0c5a9ff9876cb1af53317720d1de8baae003e21d (patch)
tree333235a9873df74b8e9b3c4232e0f8f87854df11 /src/plugins
parentc9d8b85ec9efd90f9bd8071a58dc04f54c2c365d (diff)
parent2a999f870e791d99c5c0463a11be05fc5a14dfcc (diff)
Merge branch 'wip/scenegraphng' into dev
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/scenegraph/d3d12/qsgd3d12builtinmaterials.cpp167
-rw-r--r--src/plugins/scenegraph/d3d12/qsgd3d12builtinmaterials_p.h26
-rw-r--r--src/plugins/scenegraph/d3d12/shaders/flatcolor.hlsl27
-rw-r--r--src/plugins/scenegraph/d3d12/shaders/shaders.pri11
4 files changed, 179 insertions, 52 deletions
diff --git a/src/plugins/scenegraph/d3d12/qsgd3d12builtinmaterials.cpp b/src/plugins/scenegraph/d3d12/qsgd3d12builtinmaterials.cpp
index f51130deb7..ca92062120 100644
--- a/src/plugins/scenegraph/d3d12/qsgd3d12builtinmaterials.cpp
+++ b/src/plugins/scenegraph/d3d12/qsgd3d12builtinmaterials.cpp
@@ -45,6 +45,8 @@
#include "vs_vertexcolor.hlslh"
#include "ps_vertexcolor.hlslh"
+#include "vs_flatcolor.hlslh"
+#include "ps_flatcolor.hlslh"
#include "vs_smoothcolor.hlslh"
#include "ps_smoothcolor.hlslh"
#include "vs_texture.hlslh"
@@ -66,6 +68,31 @@ QT_BEGIN_NAMESPACE
// importantly, it is packed so that it does not cross a 16-byte (float4)
// boundary. Hence the need for padding in some cases.
+static inline QVector4D qsg_premultiply(const QVector4D &c, float globalOpacity)
+{
+ const float o = c.w() * globalOpacity;
+ return QVector4D(c.x() * o, c.y() * o, c.z() * o, o);
+}
+
+static inline QVector4D qsg_premultiply(const QColor &c, float globalOpacity)
+{
+ const float o = c.alphaF() * globalOpacity;
+ return QVector4D(c.redF() * o, c.greenF() * o, c.blueF() * o, o);
+}
+
+static inline int qsg_colorDiff(const QVector4D &a, const QVector4D &b)
+{
+ if (a.x() != b.x())
+ return a.x() > b.x() ? 1 : -1;
+ if (a.y() != b.y())
+ return a.y() > b.y() ? 1 : -1;
+ if (a.z() != b.z())
+ return a.z() > b.z() ? 1 : -1;
+ if (a.w() != b.w())
+ return a.w() > b.w() ? 1 : -1;
+ return 0;
+}
+
QSGMaterialType QSGD3D12VertexColorMaterial::mtype;
QSGMaterialType *QSGD3D12VertexColorMaterial::type() const
@@ -121,6 +148,67 @@ QSGD3D12Material::UpdateResults QSGD3D12VertexColorMaterial::updatePipeline(cons
return r;
}
+QSGMaterialType QSGD3D12FlatColorMaterial::mtype;
+
+QSGMaterialType *QSGD3D12FlatColorMaterial::type() const
+{
+ return &QSGD3D12FlatColorMaterial::mtype;
+}
+
+int QSGD3D12FlatColorMaterial::compare(const QSGMaterial *other) const
+{
+ Q_ASSERT(other && type() == other->type());
+ const QSGD3D12FlatColorMaterial *o = static_cast<const QSGD3D12FlatColorMaterial *>(other);
+ return m_color.rgba() - o->color().rgba();
+}
+
+static const int FLAT_COLOR_CB_SIZE_0 = 16 * sizeof(float); // float4x4
+static const int FLAT_COLOR_CB_SIZE_1 = 4 * sizeof(float); // float4
+static const int FLAT_COLOR_CB_SIZE = FLAT_COLOR_CB_SIZE_0 + FLAT_COLOR_CB_SIZE_1;
+
+int QSGD3D12FlatColorMaterial::constantBufferSize() const
+{
+ return QSGD3D12Engine::alignedConstantBufferSize(FLAT_COLOR_CB_SIZE);
+}
+
+void QSGD3D12FlatColorMaterial::preparePipeline(QSGD3D12PipelineState *pipelineState)
+{
+ pipelineState->shaders.vs = g_VS_FlatColor;
+ pipelineState->shaders.vsSize = sizeof(g_VS_FlatColor);
+ pipelineState->shaders.ps = g_PS_FlatColor;
+ pipelineState->shaders.psSize = sizeof(g_PS_FlatColor);
+}
+
+QSGD3D12Material::UpdateResults QSGD3D12FlatColorMaterial::updatePipeline(const QSGD3D12MaterialRenderState &state,
+ QSGD3D12PipelineState *,
+ ExtraState *,
+ quint8 *constantBuffer)
+{
+ QSGD3D12Material::UpdateResults r = 0;
+ quint8 *p = constantBuffer;
+
+ if (state.isMatrixDirty()) {
+ memcpy(p, state.combinedMatrix().constData(), FLAT_COLOR_CB_SIZE_0);
+ r |= UpdatedConstantBuffer;
+ }
+ p += FLAT_COLOR_CB_SIZE_0;
+
+ const QVector4D color = qsg_premultiply(m_color, state.opacity());
+ const float f[] = { color.x(), color.y(), color.z(), color.w() };
+ if (state.isOpacityDirty() || memcmp(p, f, FLAT_COLOR_CB_SIZE_1)) {
+ memcpy(p, f, FLAT_COLOR_CB_SIZE_1);
+ r |= UpdatedConstantBuffer;
+ }
+
+ return r;
+}
+
+void QSGD3D12FlatColorMaterial::setColor(const QColor &color)
+{
+ m_color = color;
+ setFlag(Blending, m_color.alpha() != 0xFF);
+}
+
QSGD3D12SmoothColorMaterial::QSGD3D12SmoothColorMaterial()
{
setFlag(RequiresFullMatrixExceptTranslate, true);
@@ -356,25 +444,6 @@ QSGD3D12Material::UpdateResults QSGD3D12SmoothTextureMaterial::updatePipeline(co
return r;
}
-static inline QVector4D qsg_premultiply(const QVector4D &c, float globalOpacity)
-{
- float o = c.w() * globalOpacity;
- return QVector4D(c.x() * o, c.y() * o, c.z() * o, o);
-}
-
-static inline int qsg_colorDiff(const QVector4D &a, const QVector4D &b)
-{
- if (a.x() != b.x())
- return a.x() > b.x() ? 1 : -1;
- if (a.y() != b.y())
- return a.y() > b.y() ? 1 : -1;
- if (a.z() != b.z())
- return a.z() > b.z() ? 1 : -1;
- if (a.w() != b.w())
- return a.w() > b.w() ? 1 : -1;
- return 0;
-}
-
QSGD3D12TextMaterial::QSGD3D12TextMaterial(StyleType styleType, QSGD3D12RenderContext *rc,
const QRawFont &font, QFontEngine::GlyphFormat glyphFormat)
: m_styleType(styleType),
@@ -503,56 +572,60 @@ QSGD3D12Material::UpdateResults QSGD3D12TextMaterial::updatePipeline(const QSGD3
}
p += TEXT_CB_SIZE_0;
- if (state.isCachedMaterialDataDirty() || m_lastGlyphCacheSize != glyphCache()->currentSize()) {
- m_lastGlyphCacheSize = glyphCache()->currentSize();
- const float textureScale[2] = { 1.0f / m_lastGlyphCacheSize.width(),
- 1.0f / m_lastGlyphCacheSize.height() };
+ const QSize sz = glyphCache()->currentSize();
+ const float textureScale[] = { 1.0f / sz.width(), 1.0f / sz.height() };
+ if (state.isCachedMaterialDataDirty() || memcmp(p, textureScale, TEXT_CB_SIZE_1)) {
memcpy(p, textureScale, TEXT_CB_SIZE_1);
r |= UpdatedConstantBuffer;
}
p += TEXT_CB_SIZE_1;
const float dpr = m_rc->engine()->windowDevicePixelRatio();
- if (state.isCachedMaterialDataDirty() || m_lastDpr != dpr) {
- m_lastDpr = dpr;
+ if (state.isCachedMaterialDataDirty() || memcmp(p, &dpr, TEXT_CB_SIZE_2)) {
memcpy(p, &dpr, TEXT_CB_SIZE_2);
r |= UpdatedConstantBuffer;
}
p += TEXT_CB_SIZE_2;
- if (state.isOpacityDirty() || m_lastColor != m_color) {
- m_lastColor = m_color;
- if (glyphCache()->glyphFormat() == QFontEngine::Format_A32) {
- const QVector4D color = qsg_premultiply(m_color, state.opacity());
- const float alpha = color.w();
+ if (glyphCache()->glyphFormat() == QFontEngine::Format_A32) {
+ const QVector4D color = qsg_premultiply(m_color, state.opacity());
+ const float alpha = color.w();
+ if (state.isOpacityDirty() || memcmp(p, &alpha, TEXT_CB_SIZE_3)) {
memcpy(p, &alpha, TEXT_CB_SIZE_3);
- } else if (glyphCache()->glyphFormat() == QFontEngine::Format_ARGB) {
- const float opacity = m_color.w() * state.opacity();
+ r |= UpdatedConstantBuffer;
+ }
+ } else if (glyphCache()->glyphFormat() == QFontEngine::Format_ARGB) {
+ const float opacity = m_color.w() * state.opacity();
+ if (state.isOpacityDirty() || memcmp(p, &opacity, TEXT_CB_SIZE_3)) {
memcpy(p, &opacity, TEXT_CB_SIZE_3);
- } else {
- const QVector4D color = qsg_premultiply(m_color, state.opacity());
- const float f[4] = { color.x(), color.y(), color.z(), color.w() };
+ r |= UpdatedConstantBuffer;
+ }
+ } else {
+ const QVector4D color = qsg_premultiply(m_color, state.opacity());
+ const float f[] = { color.x(), color.y(), color.z(), color.w() };
+ if (state.isOpacityDirty() || memcmp(p, f, TEXT_CB_SIZE_4)) {
memcpy(p + TEXT_CB_SIZE_3, f, TEXT_CB_SIZE_4);
+ r |= UpdatedConstantBuffer;
}
- r |= UpdatedConstantBuffer;
}
p += TEXT_CB_SIZE_3 + TEXT_CB_SIZE_4;
- if (m_styleType == Styled && (state.isCachedMaterialDataDirty() || m_lastStyleShift != m_styleShift)) {
- m_lastStyleShift = m_styleShift;
- const float f[2] = { m_styleShift.x(), m_styleShift.y() };
- memcpy(p, f, TEXT_CB_SIZE_5);
- r |= UpdatedConstantBuffer;
+ if (m_styleType == Styled) {
+ const float f[] = { m_styleShift.x(), m_styleShift.y() };
+ if (state.isCachedMaterialDataDirty() || memcmp(p, f, TEXT_CB_SIZE_5)) {
+ memcpy(p, f, TEXT_CB_SIZE_5);
+ r |= UpdatedConstantBuffer;
+ }
}
p += TEXT_CB_SIZE_5 + TEXT_CB_SIZE_5_PADDING;
- if ((m_styleType == Styled || m_styleType == Outlined)
- && (state.isOpacityDirty() || m_lastStyleColor != m_styleColor)) {
- m_lastStyleColor = m_styleColor;
+ if (m_styleType == Styled || m_styleType == Outlined) {
const QVector4D color = qsg_premultiply(m_styleColor, state.opacity());
- const float f[4] = { color.x(), color.y(), color.z(), color.w() };
- memcpy(p, f, TEXT_CB_SIZE_6);
- r |= UpdatedConstantBuffer;
+ const float f[] = { color.x(), color.y(), color.z(), color.w() };
+ if (state.isOpacityDirty() || memcmp(p, f, TEXT_CB_SIZE_6)) {
+ memcpy(p, f, TEXT_CB_SIZE_6);
+ r |= UpdatedConstantBuffer;
+ }
}
QSGD3D12TextureView &tv(pipelineState->shaders.rootSig.textureViews[0]);
diff --git a/src/plugins/scenegraph/d3d12/qsgd3d12builtinmaterials_p.h b/src/plugins/scenegraph/d3d12/qsgd3d12builtinmaterials_p.h
index c64ff52ab0..34ae73d2d6 100644
--- a/src/plugins/scenegraph/d3d12/qsgd3d12builtinmaterials_p.h
+++ b/src/plugins/scenegraph/d3d12/qsgd3d12builtinmaterials_p.h
@@ -77,6 +77,27 @@ private:
static QSGMaterialType mtype;
};
+class QSGD3D12FlatColorMaterial : public QSGD3D12Material
+{
+public:
+ QSGMaterialType *type() const override;
+ int compare(const QSGMaterial *other) const override;
+
+ int constantBufferSize() const override;
+ void preparePipeline(QSGD3D12PipelineState *pipelineState) override;
+ UpdateResults updatePipeline(const QSGD3D12MaterialRenderState &state,
+ QSGD3D12PipelineState *pipelineState,
+ ExtraState *extraState,
+ quint8 *constantBuffer) override;
+
+ void setColor(const QColor &color);
+ QColor color() const { return m_color; }
+
+private:
+ static QSGMaterialType mtype;
+ QColor m_color;
+};
+
class QSGD3D12SmoothColorMaterial : public QSGD3D12Material
{
public:
@@ -224,11 +245,6 @@ private:
QVector4D m_styleColor;
QRawFont m_font;
QExplicitlySharedDataPointer<QFontEngineGlyphCache> m_glyphCache;
- QSize m_lastGlyphCacheSize;
- float m_lastDpr = 0;
- QVector4D m_lastColor;
- QVector2D m_lastStyleShift;
- QVector4D m_lastStyleColor;
};
QT_END_NAMESPACE
diff --git a/src/plugins/scenegraph/d3d12/shaders/flatcolor.hlsl b/src/plugins/scenegraph/d3d12/shaders/flatcolor.hlsl
new file mode 100644
index 0000000000..034b51435a
--- /dev/null
+++ b/src/plugins/scenegraph/d3d12/shaders/flatcolor.hlsl
@@ -0,0 +1,27 @@
+struct VSInput
+{
+ float4 position : POSITION;
+};
+
+cbuffer ConstantBuffer : register(b0)
+{
+ float4x4 mvp;
+ float4 color;
+};
+
+struct PSInput
+{
+ float4 position : SV_POSITION;
+};
+
+PSInput VS_FlatColor(VSInput input)
+{
+ PSInput result;
+ result.position = mul(mvp, input.position);
+ return result;
+}
+
+float4 PS_FlatColor(PSInput input) : SV_TARGET
+{
+ return color;
+}
diff --git a/src/plugins/scenegraph/d3d12/shaders/shaders.pri b/src/plugins/scenegraph/d3d12/shaders/shaders.pri
index 41bac334de..41f0ee80f7 100644
--- a/src/plugins/scenegraph/d3d12/shaders/shaders.pri
+++ b/src/plugins/scenegraph/d3d12/shaders/shaders.pri
@@ -8,6 +8,16 @@ vertexcolor_pshader.header = ps_vertexcolor.hlslh
vertexcolor_pshader.entry = PS_VertexColor
vertexcolor_pshader.type = ps_5_0
+flatcolor_VSPS = $$PWD/flatcolor.hlsl
+flatcolor_vshader.input = flatcolor_VSPS
+flatcolor_vshader.header = vs_flatcolor.hlslh
+flatcolor_vshader.entry = VS_FlatColor
+flatcolor_vshader.type = vs_5_0
+flatcolor_pshader.input = flatcolor_VSPS
+flatcolor_pshader.header = ps_flatcolor.hlslh
+flatcolor_pshader.entry = PS_FlatColor
+flatcolor_pshader.type = ps_5_0
+
stencilclip_VSPS = $$PWD/stencilclip.hlsl
stencilclip_vshader.input = stencilclip_VSPS
stencilclip_vshader.header = vs_stencilclip.hlslh
@@ -106,6 +116,7 @@ tdr_cshader.type = cs_5_0
HLSL_SHADERS = \
vertexcolor_vshader vertexcolor_pshader \
+ flatcolor_vshader flatcolor_pshader \
stencilclip_vshader stencilclip_pshader \
smoothcolor_vshader smoothcolor_pshader \
texture_vshader texture_pshader \