Support SPIR-V 1.4 pointer comparison opcodes

This commit is contained in:
baldurk
2020-04-23 19:14:08 +01:00
parent 3470079472
commit 31593f4373
3 changed files with 34 additions and 0 deletions
@@ -553,6 +553,29 @@ void ThreadState::StepNext(ShaderDebugState *state, const rdcarray<ThreadState>
break;
}
case Op::PtrEqual:
case Op::PtrNotEqual:
{
OpPtrEqual equal(it);
ShaderVariable a = GetSrc(equal.operand1);
ShaderVariable b = GetSrc(equal.operand2);
bool isEqual = debugger.ArePointersAndEqual(a, b);
ShaderVariable var;
var.rows = var.columns = 1;
// TODO we should add a bool type
var.type = VarType::UInt;
if(opdata.op == Op::PtrEqual)
var.value.uv[0] = isEqual ? 1 : 0;
else
var.value.uv[0] = isEqual ? 0 : 1;
SetDst(equal.result, var);
break;
}
//////////////////////////////////////////////////////////////////////////////
//
@@ -257,6 +257,7 @@ public:
uint32_t scalar1 = ~0U) const;
Id GetPointerBaseId(const ShaderVariable &v) const;
bool IsOpaquePointer(const ShaderVariable &v) const;
bool ArePointersAndEqual(const ShaderVariable &a, const ShaderVariable &b) const;
void WriteThroughPointer(const ShaderVariable &ptr, const ShaderVariable &val);
ShaderVariable MakeCompositePointer(const ShaderVariable &base, Id id, rdcarray<uint32_t> &indices);
@@ -1248,6 +1248,16 @@ bool Debugger::IsOpaquePointer(const ShaderVariable &ptr) const
return inner->type == VarType::ReadOnlyResource || inner->type == VarType::ReadWriteResource;
}
bool Debugger::ArePointersAndEqual(const ShaderVariable &a, const ShaderVariable &b) const
{
// we can do a pointer comparison by checking the values, since we store all pointer-related
// data in there
if(a.type == VarType::GPUPointer && b.type == VarType::GPUPointer)
return memcmp(&a.value, &b.value, sizeof(ShaderValue)) == 0;
return false;
}
void Debugger::WriteThroughPointer(const ShaderVariable &ptr, const ShaderVariable &val)
{
ShaderVariable *storage = (ShaderVariable *)(uintptr_t)ptr.value.u64v[0];