Add 8-bit/16-bit transform feedback support for future use
This commit is contained in:
parent
dc2d5673a1
commit
eaf31ab98c
8 changed files with 288 additions and 9 deletions
|
|
@ -5463,14 +5463,23 @@ void TParseContext::layoutTypeCheck(const TSourceLoc& loc, const TType& type)
|
|||
|
||||
// "The offset must be a multiple of the size of the first component of the first
|
||||
// qualified variable or block member, or a compile-time error results. Further, if applied to an aggregate
|
||||
// containing a double, the offset must also be a multiple of 8..."
|
||||
if (type.containsBasicType(EbtDouble) && ! IsMultipleOfPow2(qualifier.layoutXfbOffset, 8))
|
||||
error(loc, "type contains double; xfb_offset must be a multiple of 8", "xfb_offset", "");
|
||||
// ..., if applied to an aggregate containing a float16_t, the offset must also be a multiple of 2..."
|
||||
else if (type.containsBasicType(EbtFloat16) && !IsMultipleOfPow2(qualifier.layoutXfbOffset, 2))
|
||||
error(loc, "type contains half float; xfb_offset must be a multiple of 2", "xfb_offset", "");
|
||||
// containing a double or 64-bit integer, the offset must also be a multiple of 8..."
|
||||
if ((type.containsBasicType(EbtDouble) || type.containsBasicType(EbtInt64) || type.containsBasicType(EbtUint64)) &&
|
||||
! IsMultipleOfPow2(qualifier.layoutXfbOffset, 8))
|
||||
error(loc, "type contains double or 64-bit integer; xfb_offset must be a multiple of 8", "xfb_offset", "");
|
||||
#ifdef AMD_EXTENSIONS
|
||||
else if ((type.containsBasicType(EbtBool) || type.containsBasicType(EbtFloat) ||
|
||||
type.containsBasicType(EbtInt) || type.containsBasicType(EbtUint)) &&
|
||||
! IsMultipleOfPow2(qualifier.layoutXfbOffset, 4))
|
||||
error(loc, "must be a multiple of size of first component", "xfb_offset", "");
|
||||
// ..., if applied to an aggregate containing a half float or 16-bit integer, the offset must also be a multiple of 2..."
|
||||
else if ((type.containsBasicType(EbtFloat16) || type.containsBasicType(EbtInt16) || type.containsBasicType(EbtUint16)) &&
|
||||
!IsMultipleOfPow2(qualifier.layoutXfbOffset, 2))
|
||||
error(loc, "type contains half float or 16-bit integer; xfb_offset must be a multiple of 2", "xfb_offset", "");
|
||||
#else
|
||||
else if (! IsMultipleOfPow2(qualifier.layoutXfbOffset, 4))
|
||||
error(loc, "must be a multiple of size of first component", "xfb_offset", "");
|
||||
#endif
|
||||
}
|
||||
|
||||
if (qualifier.hasXfbStride() && qualifier.hasXfbBuffer()) {
|
||||
|
|
@ -7287,12 +7296,24 @@ void TParseContext::fixXfbOffsets(TQualifier& qualifier, TTypeList& typeList)
|
|||
for (unsigned int member = 0; member < typeList.size(); ++member) {
|
||||
TQualifier& memberQualifier = typeList[member].type->getQualifier();
|
||||
bool contains64BitType = false;
|
||||
#ifdef AMD_EXTENSIONS
|
||||
bool contains32BitType = false;
|
||||
bool contains16BitType = false;
|
||||
int memberSize = intermediate.computeTypeXfbSize(*typeList[member].type, contains64BitType, contains32BitType, contains16BitType);
|
||||
#else
|
||||
int memberSize = intermediate.computeTypeXfbSize(*typeList[member].type, contains64BitType);
|
||||
#endif
|
||||
// see if we need to auto-assign an offset to this member
|
||||
if (! memberQualifier.hasXfbOffset()) {
|
||||
// "if applied to an aggregate containing a double or 64-bit integer, the offset must also be a multiple of 8"
|
||||
if (contains64BitType)
|
||||
RoundToPow2(nextOffset, 8);
|
||||
#ifdef AMD_EXTENSIONS
|
||||
else if (contains32BitType)
|
||||
RoundToPow2(nextOffset, 4);
|
||||
else if (contains16BitType)
|
||||
RoundToPow2(nextOffset, 2);
|
||||
#endif
|
||||
memberQualifier.layoutXfbOffset = nextOffset;
|
||||
} else
|
||||
nextOffset = memberQualifier.layoutXfbOffset;
|
||||
|
|
|
|||
|
|
@ -224,6 +224,12 @@ void TIntermediate::mergeModes(TInfoSink& infoSink, TIntermediate& unit)
|
|||
xfbBuffers[b].implicitStride = std::max(xfbBuffers[b].implicitStride, unit.xfbBuffers[b].implicitStride);
|
||||
if (unit.xfbBuffers[b].contains64BitType)
|
||||
xfbBuffers[b].contains64BitType = true;
|
||||
#ifdef AMD_EXTENSIONS
|
||||
if (unit.xfbBuffers[b].contains32BitType)
|
||||
xfbBuffers[b].contains32BitType = true;
|
||||
if (unit.xfbBuffers[b].contains16BitType)
|
||||
xfbBuffers[b].contains16BitType = true;
|
||||
#endif
|
||||
// TODO: 4.4 link: enhanced layouts: compare ranges
|
||||
}
|
||||
|
||||
|
|
@ -636,6 +642,12 @@ void TIntermediate::finalCheck(TInfoSink& infoSink, bool keepUncalled)
|
|||
for (size_t b = 0; b < xfbBuffers.size(); ++b) {
|
||||
if (xfbBuffers[b].contains64BitType)
|
||||
RoundToPow2(xfbBuffers[b].implicitStride, 8);
|
||||
#ifdef AMD_EXTENSIONS
|
||||
else if (xfbBuffers[b].contains32BitType)
|
||||
RoundToPow2(xfbBuffers[b].implicitStride, 4);
|
||||
else if (xfbBuffers[b].contains16BitType)
|
||||
RoundToPow2(xfbBuffers[b].implicitStride, 2);
|
||||
#endif
|
||||
|
||||
// "It is a compile-time or link-time error to have
|
||||
// any xfb_offset that overflows xfb_stride, whether stated on declarations before or after the xfb_stride, or
|
||||
|
|
@ -656,12 +668,25 @@ void TIntermediate::finalCheck(TInfoSink& infoSink, bool keepUncalled)
|
|||
error(infoSink, "xfb_stride must be multiple of 8 for buffer holding a double or 64-bit integer:");
|
||||
infoSink.info.prefix(EPrefixError);
|
||||
infoSink.info << " xfb_buffer " << (unsigned int)b << ", xfb_stride " << xfbBuffers[b].stride << "\n";
|
||||
#ifdef AMD_EXTENSIONS
|
||||
} else if (xfbBuffers[b].contains32BitType && ! IsMultipleOfPow2(xfbBuffers[b].stride, 4)) {
|
||||
#else
|
||||
} else if (! IsMultipleOfPow2(xfbBuffers[b].stride, 4)) {
|
||||
#endif
|
||||
error(infoSink, "xfb_stride must be multiple of 4:");
|
||||
infoSink.info.prefix(EPrefixError);
|
||||
infoSink.info << " xfb_buffer " << (unsigned int)b << ", xfb_stride " << xfbBuffers[b].stride << "\n";
|
||||
}
|
||||
#ifdef AMD_EXTENSIONS
|
||||
// "If the buffer is capturing any
|
||||
// outputs with half-precision or 16-bit integer components, the stride must be a multiple of 2"
|
||||
else if (xfbBuffers[b].contains16BitType && ! IsMultipleOfPow2(xfbBuffers[b].stride, 2)) {
|
||||
error(infoSink, "xfb_stride must be multiple of 2 for buffer holding a half float or 16-bit integer:");
|
||||
infoSink.info.prefix(EPrefixError);
|
||||
infoSink.info << " xfb_buffer " << (unsigned int)b << ", xfb_stride " << xfbBuffers[b].stride << "\n";
|
||||
}
|
||||
|
||||
#endif
|
||||
// "The resulting stride (implicit or explicit), when divided by 4, must be less than or equal to the
|
||||
// implementation-dependent constant gl_MaxTransformFeedbackInterleavedComponents."
|
||||
if (xfbBuffers[b].stride > (unsigned int)(4 * resources.maxTransformFeedbackInterleavedComponents)) {
|
||||
|
|
@ -1260,7 +1285,11 @@ int TIntermediate::addXfbBufferOffset(const TType& type)
|
|||
TXfbBuffer& buffer = xfbBuffers[qualifier.layoutXfbBuffer];
|
||||
|
||||
// compute the range
|
||||
#ifdef AMD_EXTENSIONS
|
||||
unsigned int size = computeTypeXfbSize(type, buffer.contains64BitType, buffer.contains32BitType, buffer.contains16BitType);
|
||||
#else
|
||||
unsigned int size = computeTypeXfbSize(type, buffer.contains64BitType);
|
||||
#endif
|
||||
buffer.implicitStride = std::max(buffer.implicitStride, qualifier.layoutXfbOffset + size);
|
||||
TRange range(qualifier.layoutXfbOffset, qualifier.layoutXfbOffset + size - 1);
|
||||
|
||||
|
|
@ -1279,9 +1308,16 @@ int TIntermediate::addXfbBufferOffset(const TType& type)
|
|||
|
||||
// Recursively figure out how many bytes of xfb buffer are used by the given type.
|
||||
// Return the size of type, in bytes.
|
||||
// Sets contains64BitType to true if the type contains a double.
|
||||
// Sets contains64BitType to true if the type contains a 64-bit data type.
|
||||
#ifdef AMD_EXTENSIONS
|
||||
// Sets contains32BitType to true if the type contains a 32-bit data type.
|
||||
// Sets contains16BitType to true if the type contains a 16-bit data type.
|
||||
// N.B. Caller must set contains64BitType, contains32BitType, and contains16BitType to false before calling.
|
||||
unsigned int TIntermediate::computeTypeXfbSize(const TType& type, bool& contains64BitType, bool& contains32BitType, bool& contains16BitType) const
|
||||
#else
|
||||
// N.B. Caller must set contains64BitType to false before calling.
|
||||
unsigned int TIntermediate::computeTypeXfbSize(const TType& type, bool& contains64BitType) const
|
||||
#endif
|
||||
{
|
||||
// "...if applied to an aggregate containing a double or 64-bit integer, the offset must also be a multiple of 8,
|
||||
// and the space taken in the buffer will be a multiple of 8.
|
||||
|
|
@ -1294,22 +1330,44 @@ unsigned int TIntermediate::computeTypeXfbSize(const TType& type, bool& contains
|
|||
// TODO: perf: this can be flattened by using getCumulativeArraySize(), and a deref that discards all arrayness
|
||||
assert(type.isSizedArray());
|
||||
TType elementType(type, 0);
|
||||
#ifdef AMD_EXTENSIONS
|
||||
return type.getOuterArraySize() * computeTypeXfbSize(elementType, contains64BitType, contains16BitType, contains16BitType);
|
||||
#else
|
||||
return type.getOuterArraySize() * computeTypeXfbSize(elementType, contains64BitType);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (type.isStruct()) {
|
||||
unsigned int size = 0;
|
||||
bool structContains64BitType = false;
|
||||
#ifdef AMD_EXTENSIONS
|
||||
bool structContains32BitType = false;
|
||||
bool structContains16BitType = false;
|
||||
#endif
|
||||
for (int member = 0; member < (int)type.getStruct()->size(); ++member) {
|
||||
TType memberType(type, member);
|
||||
// "... if applied to
|
||||
// an aggregate containing a double or 64-bit integer, the offset must also be a multiple of 8,
|
||||
// and the space taken in the buffer will be a multiple of 8."
|
||||
bool memberContains64BitType = false;
|
||||
#ifdef AMD_EXTENSIONS
|
||||
bool memberContains32BitType = false;
|
||||
bool memberContains16BitType = false;
|
||||
int memberSize = computeTypeXfbSize(memberType, memberContains64BitType, memberContains32BitType, memberContains16BitType);
|
||||
#else
|
||||
int memberSize = computeTypeXfbSize(memberType, memberContains64BitType);
|
||||
#endif
|
||||
if (memberContains64BitType) {
|
||||
structContains64BitType = true;
|
||||
RoundToPow2(size, 8);
|
||||
#ifdef AMD_EXTENSIONS
|
||||
} else if (memberContains32BitType) {
|
||||
structContains32BitType = true;
|
||||
RoundToPow2(size, 4);
|
||||
} else if (memberContains16BitType) {
|
||||
structContains16BitType = true;
|
||||
RoundToPow2(size, 2);
|
||||
#endif
|
||||
}
|
||||
size += memberSize;
|
||||
}
|
||||
|
|
@ -1317,6 +1375,14 @@ unsigned int TIntermediate::computeTypeXfbSize(const TType& type, bool& contains
|
|||
if (structContains64BitType) {
|
||||
contains64BitType = true;
|
||||
RoundToPow2(size, 8);
|
||||
#ifdef AMD_EXTENSIONS
|
||||
} else if (structContains32BitType) {
|
||||
contains32BitType = true;
|
||||
RoundToPow2(size, 4);
|
||||
} else if (structContains16BitType) {
|
||||
contains16BitType = true;
|
||||
RoundToPow2(size, 2);
|
||||
#endif
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
|
@ -1336,8 +1402,20 @@ unsigned int TIntermediate::computeTypeXfbSize(const TType& type, bool& contains
|
|||
if (type.getBasicType() == EbtDouble || type.getBasicType() == EbtInt64 || type.getBasicType() == EbtUint64) {
|
||||
contains64BitType = true;
|
||||
return 8 * numComponents;
|
||||
#ifdef AMD_EXTENSIONS
|
||||
} else if (type.getBasicType() == EbtFloat16 || type.getBasicType() == EbtInt16 || type.getBasicType() == EbtUint16) {
|
||||
contains16BitType = true;
|
||||
return 2 * numComponents;
|
||||
} else if (type.getBasicType() == EbtInt8 || type.getBasicType() == EbtUint8)
|
||||
return numComponents;
|
||||
else {
|
||||
contains32BitType = true;
|
||||
return 4 * numComponents;
|
||||
}
|
||||
#else
|
||||
} else
|
||||
return 4 * numComponents;
|
||||
#endif
|
||||
}
|
||||
|
||||
const int baseAlignmentVec4Std140 = 16;
|
||||
|
|
|
|||
|
|
@ -149,11 +149,20 @@ struct TOffsetRange {
|
|||
|
||||
// Things that need to be tracked per xfb buffer.
|
||||
struct TXfbBuffer {
|
||||
#ifdef AMD_EXTENSIONS
|
||||
TXfbBuffer() : stride(TQualifier::layoutXfbStrideEnd), implicitStride(0), contains64BitType(false),
|
||||
contains32BitType(false), contains16BitType(false) { }
|
||||
#else
|
||||
TXfbBuffer() : stride(TQualifier::layoutXfbStrideEnd), implicitStride(0), contains64BitType(false) { }
|
||||
#endif
|
||||
std::vector<TRange> ranges; // byte offsets that have already been assigned
|
||||
unsigned int stride;
|
||||
unsigned int implicitStride;
|
||||
bool contains64BitType;
|
||||
#ifdef AMD_EXTENSIONS
|
||||
bool contains32BitType;
|
||||
bool contains16BitType;
|
||||
#endif
|
||||
};
|
||||
|
||||
// Track a set of strings describing how the module was processed.
|
||||
|
|
@ -669,7 +678,11 @@ public:
|
|||
}
|
||||
unsigned getXfbStride(int buffer) const { return xfbBuffers[buffer].stride; }
|
||||
int addXfbBufferOffset(const TType&);
|
||||
#ifdef AMD_EXTENSIONS
|
||||
unsigned int computeTypeXfbSize(const TType&, bool& contains64BitType, bool& contains32BitType, bool& contains16BitType) const;
|
||||
#else
|
||||
unsigned int computeTypeXfbSize(const TType&, bool& contains64BitType) const;
|
||||
#endif
|
||||
static int getBaseAlignmentScalar(const TType&, int& size);
|
||||
static int getBaseAlignment(const TType&, int& size, int& stride, TLayoutPacking layoutPacking, bool rowMajor);
|
||||
static int getScalarAlignment(const TType&, int& size, int& stride, bool rowMajor);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue