Commit 573cc9e9 by John Kessenich Committed by GitHub

Merge pull request #1111 from LoopDawg/per-set-binding-offsets

Add per-descriptor-set IO mapping shift values.
parents 7a9db71f 08a14422
// Test register class offsets for different resource types
SamplerState s1 : register(s1, space1);
SamplerComparisonState s2 : register(s2, space2);
Texture1D <float4> t1 : register(t1, space1);
Texture2D <float4> t2 : register(t2, space1);
Texture3D <float4> t3 : register(t1, space2);
StructuredBuffer<float4> t4 : register(t1, space3);
ByteAddressBuffer t5 : register(t2, space3);
Buffer<float4> t6 : register(t3, space3);
RWTexture1D <float4> u1 : register(u1, space1);
RWTexture2D <float4> u2 : register(u2, space2);
RWTexture3D <float4> u3 : register(u3, space2);
RWBuffer <float> u4 : register(u4, space1);
RWByteAddressBuffer u5 : register(u4, space2);
RWStructuredBuffer<float> u6 : register(u4, space3);
AppendStructuredBuffer<float> u7 : register(u4, space4);
ConsumeStructuredBuffer<float> u8 : register(u4, space5);
cbuffer cb : register(b1, space6) {
int cb1;
};
tbuffer tb : register(t7) {
int tb1;
};
float4 main() : SV_Target0
{
t1;
t2;
t3;
t4[0];
t5.Load(0);
t6;
s1;
s2;
u1;
u2;
u3;
u4[0];
u5.Load(0);
u6[0];
u7;
u8;
cb1;
tb1;
return 0;
}
......@@ -105,6 +105,13 @@ $EXE -V -D -e main -H -Od hlsl.explicitDescriptorSet.frag --hlsl-iomap --amb --s
diff -b $BASEDIR/hlsl.explicitDescriptorSet-2.frag.out $TARGETDIR/hlsl.explicitDescriptorSet-2.frag.out || HASERROR=1
#
# Testing per-descriptor-set IO map shift
#
echo 'Testing per-descriptor-set IO map shift'
$EXE -e main --hlsl-iomap --ssb 1 10 2 15 --stb 20 --stb 2 25 --suavb 30 --suavb 2 40 --sub 6 50 -i -q -D -V hlsl.shift.per-set.frag > $TARGETDIR/hlsl.shift.per-set.frag.out || HASERROR=1
diff -b $BASEDIR/hlsl.shift.per-set.frag.out $TARGETDIR/hlsl.shift.per-set.frag.out || HASERROR=1
#
# Testing location error
#
echo Testing SPV no location
......
......@@ -3222,4 +3222,20 @@ void TIntermediate::performTextureUpgradeAndSamplerRemovalTransformation(TInterm
root->traverse(&transform);
}
const char* TIntermediate::getResourceName(TResourceType res)
{
switch (res) {
case EResSampler: return "shift-sampler-binding";
case EResTexture: return "shift-texture-binding";
case EResImage: return "shift-image-binding";
case EResUbo: return "shift-UBO-binding";
case EResSsbo: return "shift-ssbo-binding";
case EResUav: return "shift-uav-binding";
default:
assert(0); // internal error: should only be called with valid resource types.
return nullptr;
}
}
} // end namespace glslang
......@@ -1661,20 +1661,30 @@ void TShader::addProcesses(const std::vector<std::string>& p)
intermediate->addProcesses(p);
}
// Set binding base for given resource type
void TShader::setShiftBinding(TResourceType res, unsigned int base) {
intermediate->setShiftBinding(res, base);
}
// Set binding base for given resource type for a given binding set.
void TShader::setShiftBindingForSet(TResourceType res, unsigned int set, unsigned int base) {
intermediate->setShiftBindingForSet(res, set, base);
}
// Set binding base for sampler types
void TShader::setShiftSamplerBinding(unsigned int base) { intermediate->setShiftSamplerBinding(base); }
void TShader::setShiftSamplerBinding(unsigned int base) { setShiftBinding(EResSampler, base); }
// Set binding base for texture types (SRV)
void TShader::setShiftTextureBinding(unsigned int base) { intermediate->setShiftTextureBinding(base); }
void TShader::setShiftTextureBinding(unsigned int base) { setShiftBinding(EResTexture, base); }
// Set binding base for image types
void TShader::setShiftImageBinding(unsigned int base) { intermediate->setShiftImageBinding(base); }
void TShader::setShiftImageBinding(unsigned int base) { setShiftBinding(EResImage, base); }
// Set binding base for uniform buffer objects (CBV)
void TShader::setShiftUboBinding(unsigned int base) { intermediate->setShiftUboBinding(base); }
void TShader::setShiftUboBinding(unsigned int base) { setShiftBinding(EResUbo, base); }
// Synonym for setShiftUboBinding, to match HLSL language.
void TShader::setShiftCbufferBinding(unsigned int base) { intermediate->setShiftUboBinding(base); }
void TShader::setShiftCbufferBinding(unsigned int base) { setShiftBinding(EResUbo, base); }
// Set binding base for UAV (unordered access view)
void TShader::setShiftUavBinding(unsigned int base) { intermediate->setShiftUavBinding(base); }
void TShader::setShiftUavBinding(unsigned int base) { setShiftBinding(EResUav, base); }
// Set binding base for SSBOs
void TShader::setShiftSsboBinding(unsigned int base) { intermediate->setShiftSsboBinding(base); }
void TShader::setShiftSsboBinding(unsigned int base) { setShiftBinding(EResSsbo, base); }
// Enables binding automapping using TIoMapper
void TShader::setAutoMapBindings(bool map) { intermediate->setAutoMapBindings(map); }
// Fragile: currently within one stage: simple auto-assignment of location
......
......@@ -42,6 +42,7 @@
#include <algorithm>
#include <set>
#include <array>
class TInfoSink;
......@@ -221,12 +222,6 @@ public:
layoutOverrideCoverage(false),
geoPassthroughEXT(false),
#endif
shiftSamplerBinding(0),
shiftTextureBinding(0),
shiftImageBinding(0),
shiftUboBinding(0),
shiftSsboBinding(0),
shiftUavBinding(0),
autoMapBindings(false),
autoMapLocations(false),
flattenUniformArrays(false),
......@@ -244,6 +239,8 @@ public:
localSizeSpecId[1] = TQualifier::layoutNotSet;
localSizeSpecId[2] = TQualifier::layoutNotSet;
xfbBuffers.resize(TQualifier::layoutXfbBufferEnd);
shiftBinding.fill(0);
}
void setLimits(const TBuiltInResource& r) { resources = r; }
......@@ -263,42 +260,39 @@ public:
const std::string& getEntryPointName() const { return entryPointName; }
const std::string& getEntryPointMangledName() const { return entryPointMangledName; }
void setShiftSamplerBinding(unsigned int shift)
{
shiftSamplerBinding = shift;
processes.addIfNonZero("shift-sampler-binding", shift);
}
unsigned int getShiftSamplerBinding() const { return shiftSamplerBinding; }
void setShiftTextureBinding(unsigned int shift)
{
shiftTextureBinding = shift;
processes.addIfNonZero("shift-texture-binding", shift);
}
unsigned int getShiftTextureBinding() const { return shiftTextureBinding; }
void setShiftImageBinding(unsigned int shift)
void setShiftBinding(TResourceType res, unsigned int shift)
{
shiftImageBinding = shift;
processes.addIfNonZero("shift-image-binding", shift);
}
unsigned int getShiftImageBinding() const { return shiftImageBinding; }
void setShiftUboBinding(unsigned int shift)
{
shiftUboBinding = shift;
processes.addIfNonZero("shift-UBO-binding", shift);
shiftBinding[res] = shift;
const char* name = getResourceName(res);
if (name != nullptr)
processes.addIfNonZero(name, shift);
}
unsigned int getShiftUboBinding() const { return shiftUboBinding; }
void setShiftSsboBinding(unsigned int shift)
unsigned int getShiftBinding(TResourceType res) const { return shiftBinding[res]; }
void setShiftBindingForSet(TResourceType res, unsigned int set, unsigned int shift)
{
shiftSsboBinding = shift;
processes.addIfNonZero("shift-ssbo-binding", shift);
if (shift == 0) // ignore if there's no shift: it's a no-op.
return;
shiftBindingForSet[res][set] = shift;
const char* name = getResourceName(res);
if (name != nullptr) {
processes.addProcess(name);
processes.addArgument(set);
processes.addArgument(shift);
}
}
unsigned int getShiftSsboBinding() const { return shiftSsboBinding; }
void setShiftUavBinding(unsigned int shift)
int getShiftBindingForSet(TResourceType res, unsigned int set) const
{
shiftUavBinding = shift;
processes.addIfNonZero("shift-uav-binding", shift);
const auto shift = shiftBindingForSet[res].find(set);
return shift == shiftBindingForSet[res].end() ? -1 : shift->second;
}
unsigned int getShiftUavBinding() const { return shiftUavBinding; }
bool hasShiftBindingForSet(TResourceType res) const { return !shiftBindingForSet[res].empty(); }
void setResourceSetBinding(const std::vector<std::string>& shift)
{
resourceSetBinding = shift;
......@@ -638,6 +632,7 @@ protected:
void pushSelector(TIntermSequence&, const TMatrixSelector&, const TSourceLoc&);
bool specConstantPropagates(const TIntermTyped&, const TIntermTyped&);
void performTextureUpgradeAndSamplerRemovalTransformation(TIntermNode* root);
static const char* getResourceName(TResourceType);
const EShLanguage language; // stage, known at construction time
EShSource source; // source language, known a bit later
......@@ -678,12 +673,13 @@ protected:
bool geoPassthroughEXT;
#endif
unsigned int shiftSamplerBinding;
unsigned int shiftTextureBinding;
unsigned int shiftImageBinding;
unsigned int shiftUboBinding;
unsigned int shiftSsboBinding;
unsigned int shiftUavBinding;
// Base shift values
std::array<unsigned int, EResCount> shiftBinding;
// Per-descriptor-set shift values
typedef std::map<int, int> TDescriptorSetShift;
TDescriptorSetShift shiftBindingForSet[EResCount];
std::vector<std::string> resourceSetBinding;
bool autoMapBindings;
bool autoMapLocations;
......
......@@ -324,6 +324,17 @@ bool InitializeProcess();
// Call once per process to tear down everything
void FinalizeProcess();
// Resource type for IO resolver
enum TResourceType {
EResSampler,
EResTexture,
EResImage,
EResUbo,
EResSsbo,
EResUav,
EResCount
};
// Make one TShader per shader that you will link into a program. Then provide
// the shader through setStrings() or setStringsWithLengths(), then call parse(),
// then query the info logs.
......@@ -347,13 +358,17 @@ public:
void setEntryPoint(const char* entryPoint);
void setSourceEntryPoint(const char* sourceEntryPointName);
void addProcesses(const std::vector<std::string>&);
void setShiftSamplerBinding(unsigned int base);
void setShiftTextureBinding(unsigned int base);
void setShiftImageBinding(unsigned int base);
void setShiftUboBinding(unsigned int base);
void setShiftUavBinding(unsigned int base);
void setShiftCbufferBinding(unsigned int base); // synonym for setShiftUboBinding
void setShiftSsboBinding(unsigned int base);
// IO resolver binding data: see comments in ShaderLang.cpp
void setShiftBinding(TResourceType res, unsigned int base);
void setShiftSamplerBinding(unsigned int base); // DEPRECATED: use setShiftBinding
void setShiftTextureBinding(unsigned int base); // DEPRECATED: use setShiftBinding
void setShiftImageBinding(unsigned int base); // DEPRECATED: use setShiftBinding
void setShiftUboBinding(unsigned int base); // DEPRECATED: use setShiftBinding
void setShiftUavBinding(unsigned int base); // DEPRECATED: use setShiftBinding
void setShiftCbufferBinding(unsigned int base); // synonym for setShiftUboBinding
void setShiftSsboBinding(unsigned int base); // DEPRECATED: use setShiftBinding
void setShiftBindingForSet(TResourceType res, unsigned int set, unsigned int base);
void setResourceSetBinding(const std::vector<std::string>& base);
void setAutoMapBindings(bool map);
void setAutoMapLocations(bool map);
......
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