Handle dx.op.annotateHandle type annotations

This commit is contained in:
baldurk
2020-06-17 11:20:51 +01:00
parent be65ec48d7
commit b7570358a4
8 changed files with 293 additions and 79 deletions
+1 -1
View File
@@ -86,7 +86,7 @@ enum ResourceRetType
NUM_RETURN_TYPES,
};
enum ComponentType
enum SigCompType
{
COMPONENT_TYPE_UNKNOWN = 0,
COMPONENT_TYPE_UINT32,
@@ -1251,7 +1251,7 @@ DXBCContainer::DXBCContainer(const void *ByteCode, size_t ByteCodeLength)
el = &el7->elem;
}
ComponentType compType = (ComponentType)el->componentType;
SigCompType compType = (SigCompType)el->componentType;
desc.varType = VarType::Float;
if(compType == COMPONENT_TYPE_UINT32)
desc.varType = VarType::UInt;
@@ -0,0 +1,51 @@
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2019-2020 Baldur Karlsson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
#include "dxil_common.h"
template <>
rdcstr DoStringise(const DXIL::ComponentType &el)
{
BEGIN_ENUM_STRINGISE(DXIL::ComponentType);
{
STRINGISE_ENUM_CLASS_NAMED(Invalid, "<invalid CompType>");
STRINGISE_ENUM_CLASS(I1);
STRINGISE_ENUM_CLASS(I16);
STRINGISE_ENUM_CLASS(U16);
STRINGISE_ENUM_CLASS(I32);
STRINGISE_ENUM_CLASS(U32);
STRINGISE_ENUM_CLASS(I64);
STRINGISE_ENUM_CLASS(U64);
STRINGISE_ENUM_CLASS(F16);
STRINGISE_ENUM_CLASS(F32);
STRINGISE_ENUM_CLASS(F64);
STRINGISE_ENUM_CLASS(SNormF16);
STRINGISE_ENUM_CLASS(UNormF16);
STRINGISE_ENUM_CLASS(SNormF32);
STRINGISE_ENUM_CLASS(UNormF32);
STRINGISE_ENUM_CLASS(SNormF64);
STRINGISE_ENUM_CLASS(UNormF64);
}
END_ENUM_STRINGISE();
}
@@ -0,0 +1,86 @@
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2019-2020 Baldur Karlsson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
#pragma once
namespace DXIL
{
enum class ResourceClass
{
SRV = 0,
UAV,
CBuffer,
Sampler,
Invalid
};
enum class ComponentType
{
Invalid = 0,
I1,
I16,
U16,
I32,
U32,
I64,
U64,
F16,
F32,
F64,
SNormF16,
UNormF16,
SNormF32,
UNormF32,
SNormF64,
UNormF64,
};
enum class ResourceKind
{
Unknown = 0,
Texture1D,
Texture2D,
Texture2DMS,
Texture3D,
TextureCube,
Texture1DArray,
Texture2DArray,
Texture2DMSArray,
TextureCubeArray,
TypedBuffer,
RawBuffer,
StructuredBuffer,
CBuffer,
Sampler,
TBuffer,
RTAccelerationStructure,
FeedbackTexture2D,
FeedbackTexture2DArray,
StructuredBufferWithCounter,
SamplerComparison,
};
}; // namespace DXIL
DECLARE_STRINGISE_TYPE(DXIL::ComponentType);
@@ -27,6 +27,7 @@
#include <algorithm>
#include "common/formatting.h"
#include "dxil_bytecode.h"
#include "dxil_common.h"
namespace DXIL
{
@@ -514,11 +515,8 @@ void Program::MakeDisassemblyString()
Metadata &m = m_Metadata[s.idx];
if(m.value && m.val && m.val->symbol)
ret += m.val->toString(withTypes);
else if(m.value && m.val && m.val->type->type == Type::Scalar)
else if(m.value && m.val && (m.val->type->type == Type::Scalar || m.val->nullconst))
ret += m.val->toString(withTypes);
else if(m.value && m.val && m.val->nullconst)
ret += withTypes ? StringFormat::Fmt("%s zeroinitializer", m.val->type->toString())
: "zeroinitializer";
else
ret += StringFormat::Fmt("!%u", GetOrAssignMetaID(&m));
}
@@ -1199,6 +1197,122 @@ void Program::MakeDisassemblyString()
}
}
if(inst.funcCall && inst.funcCall->name.beginsWith("dx.op.annotateHandle"))
{
if(inst.args[2].type == SymbolType::Constant && inst.args[3].type == SymbolType::Constant)
{
ResourceClass resClass =
(ResourceClass)GetFunctionValue(func, inst.args[2].idx)->val.uv[0];
ResourceKind resKind = (ResourceKind)GetFunctionValue(func, inst.args[3].idx)->val.uv[0];
m_Disassembly += " resource: ";
bool srv = (resClass == ResourceClass::SRV);
uint32_t packedProps[2] = {};
const Value *props = GetFunctionValue(func, inst.args[4].idx);
if(props && !props->nullconst)
{
packedProps[0] = props->members[0].val.uv[0];
packedProps[1] = props->members[1].val.uv[0];
}
ComponentType compType = ComponentType(packedProps[0] & 0x1f);
bool singleComp = (packedProps[0] & 0x20) != 0;
uint32_t sampleCount = (packedProps[0] & 0x1C0) >> 6;
uint32_t structStride = packedProps[0];
bool rov = (packedProps[1] & 0x1) != 0;
bool globallyCoherent = (packedProps[1] & 0x2) != 0;
switch(resKind)
{
case ResourceKind::Unknown: m_Disassembly += "Unknown"; break;
case ResourceKind::Texture1D:
case ResourceKind::Texture2D:
case ResourceKind::Texture3D:
case ResourceKind::TextureCube:
case ResourceKind::Texture1DArray:
case ResourceKind::Texture2DArray:
case ResourceKind::TextureCubeArray:
case ResourceKind::TypedBuffer:
if(globallyCoherent)
m_Disassembly += "globallycoherent ";
if(!srv && rov)
m_Disassembly += "ROV";
else if(!srv)
m_Disassembly += "RW";
switch(resKind)
{
case ResourceKind::Texture1D: m_Disassembly += "Texture1D"; break;
case ResourceKind::Texture2D: m_Disassembly += "Texture2D"; break;
case ResourceKind::Texture3D: m_Disassembly += "Texture3D"; break;
case ResourceKind::TextureCube: m_Disassembly += "TextureCube"; break;
case ResourceKind::Texture1DArray: m_Disassembly += "Texture1DArray"; break;
case ResourceKind::Texture2DArray: m_Disassembly += "Texture2DArray"; break;
case ResourceKind::TextureCubeArray: m_Disassembly += "TextureCubeArray"; break;
case ResourceKind::TypedBuffer: m_Disassembly += "TypedBuffer"; break;
default: break;
}
m_Disassembly += StringFormat::Fmt("<%s%s>", ToStr(compType).c_str(),
!srv && !singleComp ? "[vec]" : "");
break;
case ResourceKind::RTAccelerationStructure:
m_Disassembly += "RTAccelerationStructure";
break;
case ResourceKind::FeedbackTexture2D: m_Disassembly += "FeedbackTexture2D"; break;
case ResourceKind::FeedbackTexture2DArray:
m_Disassembly += "FeedbackTexture2DArray";
break;
case ResourceKind::StructuredBuffer:
if(globallyCoherent)
m_Disassembly += "globallycoherent ";
m_Disassembly += srv ? "StructuredBuffer" : "RWStructuredBuffer";
m_Disassembly += StringFormat::Fmt("<stride=%u>", structStride);
break;
case ResourceKind::StructuredBufferWithCounter:
if(globallyCoherent)
m_Disassembly += "globallycoherent ";
m_Disassembly +=
srv ? "StructuredBufferWithCounter" : "RWStructuredBufferWithCounter";
m_Disassembly += StringFormat::Fmt("<stride=%u>", structStride);
break;
case ResourceKind::RawBuffer:
if(globallyCoherent)
m_Disassembly += "globallycoherent ";
m_Disassembly += srv ? "ByteAddressBuffer" : "RWByteAddressBuffer";
break;
case ResourceKind::Texture2DMS:
m_Disassembly += StringFormat::Fmt("Texture2DMS<%s, samples=%u>",
ToStr(compType).c_str(), 1 << sampleCount);
break;
case ResourceKind::Texture2DMSArray:
m_Disassembly += StringFormat::Fmt("Texture2DMSArray<%s, samples=%u>",
ToStr(compType).c_str(), 1 << sampleCount);
break;
case ResourceKind::CBuffer:
RDCASSERT(resClass == ResourceClass::CBuffer);
m_Disassembly += "CBuffer";
break;
case ResourceKind::Sampler:
RDCASSERT(resClass == ResourceClass::Sampler);
m_Disassembly += "SamplerState";
break;
case ResourceKind::TBuffer:
RDCASSERT(resClass == ResourceClass::SRV);
m_Disassembly += "TBuffer";
break;
case ResourceKind::SamplerComparison:
RDCASSERT(resClass == ResourceClass::Sampler);
m_Disassembly += "SamplerComparisonState";
break;
}
}
}
m_Disassembly += "\n";
instructionLine++;
@@ -1560,6 +1674,10 @@ rdcstr Value::toString(bool withType) const
}
ret += ">";
}
else if(nullconst)
{
ret += "zeroinitializer";
}
else if(type->type == Type::Array)
{
ret += "[";
@@ -1574,7 +1692,7 @@ rdcstr Value::toString(bool withType) const
}
else if(type->type == Type::Struct)
{
ret += "{";
ret += "{ ";
for(size_t i = 0; i < members.size(); i++)
{
if(i > 0)
@@ -1582,7 +1700,7 @@ rdcstr Value::toString(bool withType) const
ret += members[i].toString(withType);
}
ret += "}";
ret += " }";
}
else
{
+26 -71
View File
@@ -24,6 +24,7 @@
#include "common/formatting.h"
#include "dxil_bytecode.h"
#include "dxil_common.h"
namespace DXIL
{
@@ -66,52 +67,6 @@ enum class ResField
SamplerTags = 7,
};
enum class ResShape
{
Unknown = 0,
Texture1D,
Texture2D,
Texture2DMS,
Texture3D,
TextureCube,
Texture1DArray,
Texture2DArray,
Texture2DMSArray,
TextureCubeArray,
TypedBuffer,
RawBuffer,
StructuredBuffer,
CBuffer,
Sampler,
TBuffer,
RTAccelerationStructure,
FeedbackTexture2D,
FeedbackTexture2DArray,
StructuredBufferWithCounter,
SamplerComparison,
};
enum class ComponentType
{
Invalid = 0,
I1,
I16,
U16,
I32,
U32,
I64,
U64,
F16,
F32,
F64,
SNormF16,
UNormF16,
SNormF32,
UNormF32,
SNormF64,
UNormF64,
};
enum class SRVUAVTag
{
ElementType = 0,
@@ -624,77 +579,77 @@ static void AddResourceBind(DXBC::Reflection *refl, const TypeInfo &typeInfo, co
}
}
ResShape shape = srv ? getival<ResShape>(r->children[(size_t)ResField::SRVShape])
: getival<ResShape>(r->children[(size_t)ResField::UAVShape]);
ResourceKind shape = srv ? getival<ResourceKind>(r->children[(size_t)ResField::SRVShape])
: getival<ResourceKind>(r->children[(size_t)ResField::UAVShape]);
switch(shape)
{
case ResShape::Unknown:
case ResShape::SamplerComparison:
case ResShape::RTAccelerationStructure:
case ResShape::CBuffer:
case ResShape::Sampler:
case ResShape::FeedbackTexture2D:
case ResShape::FeedbackTexture2DArray:
case ResourceKind::Unknown:
case ResourceKind::SamplerComparison:
case ResourceKind::RTAccelerationStructure:
case ResourceKind::CBuffer:
case ResourceKind::Sampler:
case ResourceKind::FeedbackTexture2D:
case ResourceKind::FeedbackTexture2DArray:
RDCERR("Unexpected %s shape %u", srv ? "SRV" : "UAV", shape);
break;
case ResShape::Texture1D:
case ResourceKind::Texture1D:
bind.type = srv ? ShaderInputBind::TYPE_TEXTURE : ShaderInputBind::TYPE_UAV_RWTYPED;
bind.dimension = ShaderInputBind::DIM_TEXTURE1D;
break;
case ResShape::Texture2D:
case ResourceKind::Texture2D:
bind.type = srv ? ShaderInputBind::TYPE_TEXTURE : ShaderInputBind::TYPE_UAV_RWTYPED;
bind.dimension = ShaderInputBind::DIM_TEXTURE2D;
break;
case ResShape::Texture2DMS:
case ResourceKind::Texture2DMS:
bind.type = srv ? ShaderInputBind::TYPE_TEXTURE : ShaderInputBind::TYPE_UAV_RWTYPED;
bind.dimension = ShaderInputBind::DIM_TEXTURE2DMS;
break;
case ResShape::Texture3D:
case ResourceKind::Texture3D:
bind.type = srv ? ShaderInputBind::TYPE_TEXTURE : ShaderInputBind::TYPE_UAV_RWTYPED;
bind.dimension = ShaderInputBind::DIM_TEXTURE3D;
break;
case ResShape::TextureCube:
case ResourceKind::TextureCube:
bind.type = srv ? ShaderInputBind::TYPE_TEXTURE : ShaderInputBind::TYPE_UAV_RWTYPED;
bind.dimension = ShaderInputBind::DIM_TEXTURECUBE;
break;
case ResShape::Texture1DArray:
case ResourceKind::Texture1DArray:
bind.type = srv ? ShaderInputBind::TYPE_TEXTURE : ShaderInputBind::TYPE_UAV_RWTYPED;
bind.dimension = ShaderInputBind::DIM_TEXTURE1DARRAY;
break;
case ResShape::Texture2DArray:
case ResourceKind::Texture2DArray:
bind.type = srv ? ShaderInputBind::TYPE_TEXTURE : ShaderInputBind::TYPE_UAV_RWTYPED;
bind.dimension = ShaderInputBind::DIM_TEXTURE2DARRAY;
break;
case ResShape::Texture2DMSArray:
case ResourceKind::Texture2DMSArray:
bind.type = srv ? ShaderInputBind::TYPE_TEXTURE : ShaderInputBind::TYPE_UAV_RWTYPED;
bind.dimension = ShaderInputBind::DIM_TEXTURE2DMSARRAY;
break;
case ResShape::TextureCubeArray:
case ResourceKind::TextureCubeArray:
bind.type = srv ? ShaderInputBind::TYPE_TEXTURE : ShaderInputBind::TYPE_UAV_RWTYPED;
bind.dimension = ShaderInputBind::DIM_TEXTURECUBEARRAY;
break;
case ResShape::TypedBuffer:
case ResourceKind::TypedBuffer:
bind.type = srv ? ShaderInputBind::TYPE_TEXTURE : ShaderInputBind::TYPE_UAV_RWTYPED;
bind.dimension = ShaderInputBind::DIM_BUFFER;
break;
case ResShape::TBuffer:
case ResourceKind::TBuffer:
bind.type = ShaderInputBind::TYPE_TBUFFER;
bind.dimension = ShaderInputBind::DIM_UNKNOWN;
bind.retType = RETURN_TYPE_UNKNOWN;
break;
case ResShape::RawBuffer:
case ResourceKind::RawBuffer:
bind.type = ShaderInputBind::TYPE_BYTEADDRESS;
bind.type = srv ? ShaderInputBind::TYPE_BYTEADDRESS : ShaderInputBind::TYPE_UAV_RWBYTEADDRESS;
bind.dimension = ShaderInputBind::DIM_BUFFER;
bind.retType = RETURN_TYPE_MIXED;
break;
case ResShape::StructuredBuffer:
case ResourceKind::StructuredBuffer:
bind.type = srv ? ShaderInputBind::TYPE_STRUCTURED : ShaderInputBind::TYPE_UAV_RWSTRUCTURED;
bind.dimension = ShaderInputBind::DIM_BUFFER;
bind.retType = RETURN_TYPE_MIXED;
break;
case ResShape::StructuredBufferWithCounter:
case ResourceKind::StructuredBufferWithCounter:
bind.type = srv ? ShaderInputBind::TYPE_STRUCTURED
: ShaderInputBind::TYPE_UAV_RWSTRUCTURED_WITH_COUNTER;
bind.dimension = ShaderInputBind::DIM_BUFFER;
@@ -710,8 +665,8 @@ static void AddResourceBind(DXBC::Reflection *refl, const TypeInfo &typeInfo, co
switch(shape)
{
case ResShape::StructuredBuffer:
case ResShape::StructuredBufferWithCounter:
case ResourceKind::StructuredBuffer:
case ResourceKind::StructuredBufferWithCounter:
refl->ResourceBinds[bind.name] = MakeCBufferVariableType(typeInfo, baseType->inner);
default: break;
}
@@ -102,6 +102,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="dxil_bytecode.cpp" />
<ClCompile Include="dxil_common.cpp" />
<ClCompile Include="dxil_debuginfo.cpp" />
<ClCompile Include="dxil_disassemble.cpp" />
<ClCompile Include="dxil_reflect.cpp" />
@@ -112,6 +113,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="dxil_bytecode.h" />
<ClInclude Include="dxil_common.h" />
<ClInclude Include="dxil_debuginfo.h" />
<ClInclude Include="llvm_bitreader.h" />
<ClInclude Include="llvm_decoder.h" />
@@ -9,6 +9,7 @@
<ClCompile Include="dxil_debuginfo.cpp" />
<ClCompile Include="dxil_disassemble.cpp" />
<ClCompile Include="dxil_reflect.cpp" />
<ClCompile Include="dxil_common.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="precompiled.h">
@@ -18,6 +19,7 @@
<ClInclude Include="llvm_decoder.h" />
<ClInclude Include="dxil_bytecode.h" />
<ClInclude Include="dxil_debuginfo.h" />
<ClInclude Include="dxil_common.h" />
</ItemGroup>
<ItemGroup>
<Filter Include="PCH">