summaryrefslogtreecommitdiffstats
path: root/src/gui/rhi/qshader_p_p.h
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2021-12-18 22:21:31 +0100
committerLaszlo Agocs <laszlo.agocs@qt.io>2022-01-03 14:57:01 +0100
commit04cdde30d64ed55adc8174dc379f131fb2aeba98 (patch)
tree4ce5ff5647ab97f46072951e6dacde3a7d0102fe /src/gui/rhi/qshader_p_p.h
parent66a79287f159d236090fd0092a81be133862bbdc (diff)
rhi: Enable exposing separate image and sampler objects from the shader
Adds the following in a QShader/QShaderDescription: - a list of separate images - a list of separate samplers - a list of "combined_sampler_uniform_name" -> [ separate_texture_binding, separate_sampler_binding ] mappings (relevant for GLSL only) On the QShader (and qsb/QShaderBaker) level not having separate image (texture) and sampler objects exposed in the reflection info is not entirely future proof. Right now we benefit strongly from the fact that Vulkan/SPIR-V supports both combined and separate images/samplers, while for HLSL and MSL SPIRV-Cross translates combined image samplers to separate texture and sampler objects, but it is not given that relying on combined image samplers will always be possible in the long run; it is mostly a legacy OpenGL thing that just happens to be supported in Vulkan/SPIR-V due to some benefits with certain implementations/hw, but is not something present in any newer APIs. In addition, before this patch, attempting to run a shader with separate textures and samplers through qsb will just fail for GLSL, even though SPIRV-Cross does have the ability to generate a "fake" combined sampler for each separate texture+sampler combination. Take this into use. This also involves generating and exposing a combined_name->[separate_texture_binding,separate_sampler_binding] mapping table for GLSL, not unlike we have the native binding map for HLSL and MSL. A user (such as, the GL backend of QRhi) would then use this table to recognize what user-provided texture+sampler binding point numbers correspond to which auto-generated sampler2Ds in the GL program. Take the following example: layout(binding = 1) uniform texture2D sepTex; layout(binding = 2) uniform sampler sepSampler; layout(binding = 3) uniform sampler sepSampler2; Inn the reflection info (QShaderDescription) this (assuming a corresponding qtshadertools patch in place) now gives one entry in separateImages() and two in separateSamplers(). Assuming sepTex is used both with sepSampler and sepSampler2, the GLSL output and mapping table from QShaderBaker will have two auto-generated sampler2Ds (and no 'texture2D' or 'sampler'). One immediate benefit is that it is now possible to create a shader that relies only on separate images and samplers, feed it into qsb, generate all the possible targets, and then also feed the SPIR-V binary into a tool or library such as Tint (e.g. to generate WGSL) that canot deal with combined image samplers. Change-Id: I9b19847ea5854837b45d3a23edc788c48502aa15 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src/gui/rhi/qshader_p_p.h')
-rw-r--r--src/gui/rhi/qshader_p_p.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/gui/rhi/qshader_p_p.h b/src/gui/rhi/qshader_p_p.h
index 2f6afb4a6d..51c3e29d45 100644
--- a/src/gui/rhi/qshader_p_p.h
+++ b/src/gui/rhi/qshader_p_p.h
@@ -60,7 +60,8 @@ QT_BEGIN_NAMESPACE
struct Q_GUI_EXPORT QShaderPrivate
{
- static const int QSB_VERSION = 5;
+ static const int QSB_VERSION = 6;
+ static const int QSB_VERSION_WITHOUT_SEPARATE_IMAGES_AND_SAMPLERS = 5;
static const int QSB_VERSION_WITHOUT_VAR_ARRAYDIMS = 4;
static const int QSB_VERSION_WITH_CBOR = 3;
static const int QSB_VERSION_WITH_BINARY_JSON = 2;
@@ -77,7 +78,8 @@ struct Q_GUI_EXPORT QShaderPrivate
stage(other->stage),
desc(other->desc),
shaders(other->shaders),
- bindings(other->bindings)
+ bindings(other->bindings),
+ combinedImageMap(other->combinedImageMap)
{
}
@@ -90,6 +92,7 @@ struct Q_GUI_EXPORT QShaderPrivate
QShaderDescription desc;
QHash<QShaderKey, QShaderCode> shaders;
QHash<QShaderKey, QShader::NativeResourceBindingMap> bindings;
+ QHash<QShaderKey, QShader::SeparateToCombinedImageSamplerMappingList> combinedImageMap;
};
QT_END_NAMESPACE