|
|
@@ -725,7 +725,7 @@ public:
|
|
|
ShaderProgramBinaryBlockInstance& instance = m_blockInstances[blockType][blockInstanceIdx];
|
|
|
instance.m_index = blockIdx;
|
|
|
instance.m_size = size;
|
|
|
- instance.m_variableInstances.setArray(m_alloc.newArray<ShaderProgramBinaryVariableInstance>(varSize), varSize);
|
|
|
+ m_alloc.newArray(varSize, instance.m_variableInstances);
|
|
|
|
|
|
return Error::NONE;
|
|
|
}
|
|
|
@@ -773,6 +773,150 @@ public:
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+static Bool ghostMemberActive(const ShaderProgramParserMember& member, const ShaderProgramBinaryMutation& mutation)
|
|
|
+{
|
|
|
+ Bool active = false;
|
|
|
+ if(member.m_dependentMutator == MAX_U32)
|
|
|
+ {
|
|
|
+ active = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ANKI_ASSERT(member.m_dependentMutator < mutation.m_values.getSize());
|
|
|
+ active = mutation.m_values[member.m_dependentMutator] == member.m_mutatorValue;
|
|
|
+ }
|
|
|
+
|
|
|
+ return active;
|
|
|
+}
|
|
|
+
|
|
|
+static Error doGhostStructReflection(const StringList& symbolsToReflect,
|
|
|
+ ConstWeakArray<ShaderProgramParserGhostStruct> ghostStructs,
|
|
|
+ ShaderProgramBinary& binary, GenericMemoryPoolAllocator<U8>& tmpAlloc,
|
|
|
+ GenericMemoryPoolAllocator<U8>& binaryAlloc)
|
|
|
+{
|
|
|
+ // Count reflectable ghost structs
|
|
|
+ DynamicArrayAuto<U32> ghostStructIndices(tmpAlloc);
|
|
|
+ for(U32 i = 0; i < ghostStructs.getSize(); ++i)
|
|
|
+ {
|
|
|
+ for(const String& s : symbolsToReflect)
|
|
|
+ {
|
|
|
+ if(s == ghostStructs[i].m_name)
|
|
|
+ {
|
|
|
+ ghostStructIndices.emplaceBack(i);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ghostStructIndices.getSize() == 0)
|
|
|
+ {
|
|
|
+ return Error::NONE;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Add the ghost structs to binary structs
|
|
|
+ const U32 nonGhostStructCount = binary.m_structs.getSize();
|
|
|
+ DynamicArrayAuto<ShaderProgramBinaryStruct> structs(binaryAlloc,
|
|
|
+ nonGhostStructCount + ghostStructIndices.getSize());
|
|
|
+
|
|
|
+ for(U32 i = 0; i < binary.m_structs.getSize(); ++i)
|
|
|
+ {
|
|
|
+ structs[i] = binary.m_structs[i];
|
|
|
+ }
|
|
|
+
|
|
|
+ for(U32 i = 0; i < ghostStructIndices.getSize(); ++i)
|
|
|
+ {
|
|
|
+ const ShaderProgramParserGhostStruct& in = ghostStructs[ghostStructIndices[i]];
|
|
|
+ ShaderProgramBinaryStruct& out = structs[nonGhostStructCount + i];
|
|
|
+
|
|
|
+ ANKI_CHECK(Refl::setName(in.m_name, out.m_name));
|
|
|
+
|
|
|
+ DynamicArrayAuto<ShaderProgramBinaryStructMember> members(binaryAlloc, in.m_members.getSize());
|
|
|
+ for(U32 j = 0; j < in.m_members.getSize(); ++j)
|
|
|
+ {
|
|
|
+ const ShaderProgramParserMember& inMember = in.m_members[j];
|
|
|
+ ShaderProgramBinaryStructMember& outMember = members[j];
|
|
|
+
|
|
|
+ ANKI_CHECK(Refl::setName(inMember.m_name, outMember.m_name));
|
|
|
+ outMember.m_type = inMember.m_type;
|
|
|
+ }
|
|
|
+
|
|
|
+ members.moveAndReset(out.m_members);
|
|
|
+ }
|
|
|
+
|
|
|
+ binaryAlloc.deleteArray(binary.m_structs);
|
|
|
+ structs.moveAndReset(binary.m_structs);
|
|
|
+
|
|
|
+ // For all mutations update the instances
|
|
|
+ DynamicArrayAuto<Bool> variantVisited(tmpAlloc, binary.m_variants.getSize(), false);
|
|
|
+ for(U32 mutationIdx = 0; mutationIdx < binary.m_mutations.getSize(); ++mutationIdx)
|
|
|
+ {
|
|
|
+ const ShaderProgramBinaryMutation& mutation = binary.m_mutations[mutationIdx];
|
|
|
+ if(variantVisited[mutation.m_variantIndex])
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ variantVisited[mutation.m_variantIndex] = true;
|
|
|
+
|
|
|
+ ShaderProgramBinaryVariant& variant = binary.m_variants[mutation.m_variantIndex];
|
|
|
+
|
|
|
+ DynamicArrayAuto<ShaderProgramBinaryStructInstance> structInstances(binaryAlloc);
|
|
|
+
|
|
|
+ // Copy the existing struct instances
|
|
|
+ for(U32 i = 0; i < variant.m_structs.getSize(); ++i)
|
|
|
+ {
|
|
|
+ structInstances.emplaceBack(variant.m_structs[i]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // For each ghost struct add member intances
|
|
|
+ for(U32 i = 0; i < ghostStructIndices.getSize(); ++i)
|
|
|
+ {
|
|
|
+ const ShaderProgramParserGhostStruct& inStruct = ghostStructs[ghostStructIndices[i]];
|
|
|
+
|
|
|
+ // Find which members are active in this mutation
|
|
|
+ BitSet<128, U64> activeMembers(false);
|
|
|
+ ANKI_ASSERT(inStruct.m_members.getSize() <= 128);
|
|
|
+ for(U32 j = 0; j < inStruct.m_members.getSize(); ++j)
|
|
|
+ {
|
|
|
+ activeMembers.set(j, ghostMemberActive(inStruct.m_members[j], mutation));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(activeMembers.getEnabledBitCount() == 0)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Add the active members
|
|
|
+ U32 offsetof = 0;
|
|
|
+ DynamicArrayAuto<ShaderProgramBinaryStructMemberInstance> memberInstances(binaryAlloc);
|
|
|
+ for(U32 j = 0; j < inStruct.m_members.getSize(); ++j)
|
|
|
+ {
|
|
|
+ if(!activeMembers.get(j))
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ ShaderProgramBinaryStructMemberInstance& outMember = *memberInstances.emplaceBack();
|
|
|
+ outMember.m_arraySize = 1;
|
|
|
+ outMember.m_index = j;
|
|
|
+ outMember.m_offset = offsetof;
|
|
|
+
|
|
|
+ offsetof += getShaderVariableDataTypeInfo(inStruct.m_members[j].m_type).m_size;
|
|
|
+ }
|
|
|
+
|
|
|
+ ShaderProgramBinaryStructInstance& outStructInstance = *structInstances.emplaceBack();
|
|
|
+ outStructInstance.m_index = nonGhostStructCount + i;
|
|
|
+ outStructInstance.m_size = offsetof;
|
|
|
+ memberInstances.moveAndReset(outStructInstance.m_memberInstances);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Replace data
|
|
|
+ binaryAlloc.deleteArray(variant.m_structs);
|
|
|
+ structInstances.moveAndReset(variant.m_structs);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Error::NONE;
|
|
|
+}
|
|
|
+
|
|
|
static Error doReflection(const StringList& symbolsToReflect, ShaderProgramBinary& binary,
|
|
|
GenericMemoryPoolAllocator<U8>& tmpAlloc, GenericMemoryPoolAllocator<U8>& binaryAlloc)
|
|
|
{
|
|
|
@@ -965,18 +1109,16 @@ Error compileShaderProgramInternal(CString fname, ShaderProgramFilesystemInterfa
|
|
|
U32 mutationCount = 0;
|
|
|
if(parser.getMutators().getSize() > 0)
|
|
|
{
|
|
|
- binary.m_mutators.setArray(binaryAllocator.newArray<ShaderProgramBinaryMutator>(parser.getMutators().getSize()),
|
|
|
- parser.getMutators().getSize());
|
|
|
+ binaryAllocator.newArray(parser.getMutators().getSize(), binary.m_mutators);
|
|
|
|
|
|
for(U32 i = 0; i < binary.m_mutators.getSize(); ++i)
|
|
|
{
|
|
|
ShaderProgramBinaryMutator& out = binary.m_mutators[i];
|
|
|
const ShaderProgramParserMutator& in = parser.getMutators()[i];
|
|
|
|
|
|
- ANKI_ASSERT(in.getName().getLength() < out.m_name.getSize());
|
|
|
- memcpy(&out.m_name[0], in.getName().cstr(), in.getName().getLength() + 1);
|
|
|
+ ANKI_CHECK(Refl::setName(in.getName(), out.m_name));
|
|
|
|
|
|
- out.m_values.setArray(binaryAllocator.newArray<I32>(in.getValues().getSize()), in.getValues().getSize());
|
|
|
+ binaryAllocator.newArray(in.getValues().getSize(), out.m_values);
|
|
|
memcpy(out.m_values.getBegin(), in.getValues().getBegin(), in.getValues().getSizeInBytes());
|
|
|
|
|
|
// Update the count
|
|
|
@@ -1038,8 +1180,7 @@ Error compileShaderProgramInternal(CString fname, ShaderProgramFilesystemInterfa
|
|
|
}
|
|
|
|
|
|
ShaderProgramBinaryMutation& mutation = mutations[mutationCount++];
|
|
|
- mutation.m_values.setArray(binaryAllocator.newArray<MutatorValue>(originalMutationValues.getSize()),
|
|
|
- originalMutationValues.getSize());
|
|
|
+ binaryAllocator.newArray(originalMutationValues.getSize(), mutation.m_values);
|
|
|
memcpy(mutation.m_values.getBegin(), originalMutationValues.getBegin(),
|
|
|
originalMutationValues.getSizeInBytes());
|
|
|
|
|
|
@@ -1084,9 +1225,7 @@ Error compileShaderProgramInternal(CString fname, ShaderProgramFilesystemInterfa
|
|
|
tempAllocator, binaryAllocator, taskManager, mtx, errorAtomic);
|
|
|
|
|
|
ShaderProgramBinaryMutation& otherMutation = mutations[mutationCount++];
|
|
|
- otherMutation.m_values.setArray(
|
|
|
- binaryAllocator.newArray<MutatorValue>(rewrittenMutationValues.getSize()),
|
|
|
- rewrittenMutationValues.getSize());
|
|
|
+ binaryAllocator.newArray(rewrittenMutationValues.getSize(), otherMutation.m_values);
|
|
|
memcpy(otherMutation.m_values.getBegin(), rewrittenMutationValues.getBegin(),
|
|
|
rewrittenMutationValues.getSizeInBytes());
|
|
|
|
|
|
@@ -1175,6 +1314,8 @@ Error compileShaderProgramInternal(CString fname, ShaderProgramFilesystemInterfa
|
|
|
|
|
|
// Reflection
|
|
|
ANKI_CHECK(doReflection(parser.getSymbolsToReflect(), binary, tempAllocator, binaryAllocator));
|
|
|
+ ANKI_CHECK(doGhostStructReflection(parser.getSymbolsToReflect(), parser.getGhostStructs(), binary, tempAllocator,
|
|
|
+ binaryAllocator));
|
|
|
|
|
|
return Error::NONE;
|
|
|
}
|