Commit e404e088 by steve-lunarg

HLSL: fix for byte address buffers in fn parmeters

Byte address buffers were failing to detect that they were byte address buffers when used as fn parameters. Note: this detection is a little awkward, and could be simplified if it was easy to obtain the declared builtin type for an object.
parent ba5cc2fa
ByteAddressBuffer g_input: register(t0);
RWBuffer<uint2> g_output : register(u1);
uint2 testLoad(uint loc, ByteAddressBuffer buffer)
{
uint2 result = buffer.Load2(loc);
return result;
}
[numthreads(256, 1, 1)]
void main(uint dispatchId : SV_DispatchThreadID)
{
uint2 result = testLoad(dispatchId, g_input);
g_output[dispatchId] = result;
}
......@@ -251,6 +251,7 @@ INSTANTIATE_TEST_CASE_P(
{"hlsl.structbuffer.coherent.frag", "main"},
{"hlsl.structbuffer.incdec.frag", "main"},
{"hlsl.structbuffer.fn.frag", "main"},
{"hlsl.structbuffer.fn2.comp", "main"},
{"hlsl.structbuffer.rw.frag", "main"},
{"hlsl.structbuffer.rwbyte.frag", "main"},
{"hlsl.structin.vert", "main"},
......
......@@ -1612,6 +1612,8 @@ TIntermAggregate* HlslParseContext::handleFunctionDefinition(const TSourceLoc& l
paramNodes = intermediate.growAggregate(paramNodes,
intermediate.addSymbol(*variable, loc),
loc);
// TODO: for struct buffers with counters, pass counter buffer as hidden parameter
} else
paramNodes = intermediate.growAggregate(paramNodes, intermediate.addSymbol(*param.type, loc), loc);
}
......@@ -2536,13 +2538,7 @@ void HlslParseContext::decomposeStructBufferMethods(const TSourceLoc& loc, TInte
if (bufferObj == nullptr || bufferObj->getAsSymbolNode() == nullptr)
return;
TString bufferName(bufferObj->getAsSymbolNode()->getName());
const auto bivIt = structBufferBuiltIn.find(bufferName);
if (bivIt == structBufferBuiltIn.end())
return;
const TBuiltInVariable builtInType = bivIt->second;
const TString bufferName(bufferObj->getAsSymbolNode()->getName());
// Some methods require a hidden internal counter, obtained via getStructBufferCounter().
// This lambda adds something to it and returns the old value.
......@@ -2572,10 +2568,21 @@ void HlslParseContext::decomposeStructBufferMethods(const TSourceLoc& loc, TInte
{
TIntermTyped* argIndex = argAggregate->getSequence()[1]->getAsTyped(); // index
const auto bivIt = structBufferBuiltIn.find(bufferName);
const TBuiltInVariable builtInType = (bivIt != structBufferBuiltIn.end()) ? bivIt->second : EbvNone;
const TType& bufferType = bufferObj->getType();
// Byte address buffers index in bytes (only multiples of 4 permitted... not so much a byte address
// buffer then, but that's what it calls itself.
const bool isByteAddressBuffer = (builtInType == EbvByteAddressBuffer ||
builtInType == EbvRWByteAddressBuffer);
// TODO: it would be easier to track the declared (pre-sanitized) builtInType in the TType.
// If/when that happens, this should be simplified to look *only* at the builtin type.
const bool isByteAddressBuffer = (builtInType == EbvByteAddressBuffer ||
builtInType == EbvRWByteAddressBuffer ||
(builtInType == EbvNone && !bufferType.isVector() &&
bufferType.getBasicType() == EbtUint));
if (isByteAddressBuffer)
argIndex = intermediate.addBinaryNode(EOpRightShift, argIndex, intermediate.addConstantUnion(2, loc, true),
......@@ -4141,6 +4148,8 @@ TIntermTyped* HlslParseContext::handleFunctionCall(const TSourceLoc& loc, TFunct
arg0 = arguments->getAsSymbolNode();
if (arg0 != nullptr && isStructBufferType(arg0->getType())) {
// TODO: for struct buffers with counters, pass counter buffer as hidden parameter
static const int methodPrefixSize = sizeof(BUILTIN_PREFIX)-1;
if (function->getName().length() > methodPrefixSize &&
......
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