Move reflection to separate file, implement GetOutputTopology()

This commit is contained in:
baldurk
2020-06-16 12:53:06 +01:00
parent 6fcd4fee91
commit fc5c58a6c9
4 changed files with 161 additions and 97 deletions
@@ -51,15 +51,6 @@ struct ProgramHeader
uint32_t BitcodeSize; // Size of LLVM bitcode.
};
enum class ShaderTag
{
ShaderFlags = 0,
Geometry = 1,
Domain = 2,
Hull = 3,
Compute = 4,
};
enum class KnownBlocks : uint32_t
{
BLOCKINFO = 0,
@@ -2220,94 +2211,6 @@ Program::Program(const byte *bytes, size_t length)
RDCASSERT(functionDecls.empty());
}
void Program::FetchComputeProperties(DXBC::Reflection *reflection)
{
for(const Function &f : m_Functions)
{
if(f.name.beginsWith("dx.op.threadId"))
{
SigParameter param;
param.systemValue = ShaderBuiltin::DispatchThreadIndex;
param.compCount = 3;
param.regChannelMask = param.channelUsedMask = 0x7;
param.semanticIdxName = param.semanticName = "threadId";
reflection->InputSig.push_back(param);
}
else if(f.name.beginsWith("dx.op.groupId"))
{
SigParameter param;
param.systemValue = ShaderBuiltin::GroupIndex;
param.compCount = 3;
param.regChannelMask = param.channelUsedMask = 0x7;
param.semanticIdxName = param.semanticName = "groupID";
reflection->InputSig.push_back(param);
}
else if(f.name.beginsWith("dx.op.threadIdInGroup"))
{
SigParameter param;
param.systemValue = ShaderBuiltin::GroupThreadIndex;
param.compCount = 3;
param.regChannelMask = param.channelUsedMask = 0x7;
param.semanticIdxName = param.semanticName = "threadIdInGroup";
reflection->InputSig.push_back(param);
}
else if(f.name.beginsWith("dx.op.flattenedThreadIdInGroup"))
{
SigParameter param;
param.systemValue = ShaderBuiltin::GroupFlatIndex;
param.compCount = 1;
param.regChannelMask = param.channelUsedMask = 0x1;
param.semanticIdxName = param.semanticName = "flattenedThreadIdInGroup";
reflection->InputSig.push_back(param);
}
}
for(size_t i = 0; i < m_NamedMeta.size(); i++)
{
if(m_NamedMeta[i].name == "dx.entryPoints")
{
// expect only one child for this, DX doesn't support multiple entry points for compute
// shaders
RDCASSERTEQUAL(m_NamedMeta[i].children.size(), 1);
Metadata &entry = *m_NamedMeta[i].children[0];
RDCASSERTEQUAL(entry.children.size(), 5);
Metadata &tags = *entry.children[4];
for(size_t t = 0; t < tags.children.size(); t += 2)
{
RDCASSERT(tags.children[t]->value);
if(ShaderTag(tags.children[t]->val->val.uv[0]) == ShaderTag::Compute)
{
Metadata &threadDim = *tags.children[t + 1];
RDCASSERTEQUAL(threadDim.children.size(), 3);
reflection->DispatchThreadsDimension[0] = threadDim.children[0]->val->val.uv[0];
reflection->DispatchThreadsDimension[1] = threadDim.children[1]->val->val.uv[0];
reflection->DispatchThreadsDimension[2] = threadDim.children[2]->val->val.uv[0];
return;
}
}
break;
}
}
RDCERR("Couldn't find thread dimension tag in shader");
reflection->DispatchThreadsDimension[0] = 1;
reflection->DispatchThreadsDimension[1] = 1;
reflection->DispatchThreadsDimension[2] = 1;
}
DXBC::Reflection *Program::GetReflection()
{
RDCWARN("Unimplemented DXIL::Program::GetReflection()");
return new DXBC::Reflection;
}
D3D_PRIMITIVE_TOPOLOGY Program::GetOutputTopology()
{
RDCERR("Unimplemented DXIL::Program::GetOutputTopology()");
return D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
}
uint32_t Program::GetOrAssignMetaID(Metadata *m)
{
if(m->id != ~0U)
@@ -0,0 +1,159 @@
/******************************************************************************
* 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 "common/formatting.h"
#include "dxil_bytecode.h"
namespace DXIL
{
enum class ShaderTag
{
ShaderFlags = 0,
Geometry = 1,
Domain = 2,
Hull = 3,
Compute = 4,
};
void Program::FetchComputeProperties(DXBC::Reflection *reflection)
{
for(const Function &f : m_Functions)
{
if(f.name.beginsWith("dx.op.threadId"))
{
SigParameter param;
param.systemValue = ShaderBuiltin::DispatchThreadIndex;
param.compCount = 3;
param.regChannelMask = param.channelUsedMask = 0x7;
param.semanticIdxName = param.semanticName = "threadId";
reflection->InputSig.push_back(param);
}
else if(f.name.beginsWith("dx.op.groupId"))
{
SigParameter param;
param.systemValue = ShaderBuiltin::GroupIndex;
param.compCount = 3;
param.regChannelMask = param.channelUsedMask = 0x7;
param.semanticIdxName = param.semanticName = "groupID";
reflection->InputSig.push_back(param);
}
else if(f.name.beginsWith("dx.op.threadIdInGroup"))
{
SigParameter param;
param.systemValue = ShaderBuiltin::GroupThreadIndex;
param.compCount = 3;
param.regChannelMask = param.channelUsedMask = 0x7;
param.semanticIdxName = param.semanticName = "threadIdInGroup";
reflection->InputSig.push_back(param);
}
else if(f.name.beginsWith("dx.op.flattenedThreadIdInGroup"))
{
SigParameter param;
param.systemValue = ShaderBuiltin::GroupFlatIndex;
param.compCount = 1;
param.regChannelMask = param.channelUsedMask = 0x1;
param.semanticIdxName = param.semanticName = "flattenedThreadIdInGroup";
reflection->InputSig.push_back(param);
}
}
for(size_t i = 0; i < m_NamedMeta.size(); i++)
{
if(m_NamedMeta[i].name == "dx.entryPoints")
{
// expect only one child for this, DX doesn't support multiple entry points for compute
// shaders
RDCASSERTEQUAL(m_NamedMeta[i].children.size(), 1);
Metadata &entry = *m_NamedMeta[i].children[0];
RDCASSERTEQUAL(entry.children.size(), 5);
Metadata &tags = *entry.children[4];
for(size_t t = 0; t < tags.children.size(); t += 2)
{
RDCASSERT(tags.children[t]->value);
if(ShaderTag(tags.children[t]->val->val.uv[0]) == ShaderTag::Compute)
{
Metadata &threadDim = *tags.children[t + 1];
RDCASSERTEQUAL(threadDim.children.size(), 3);
reflection->DispatchThreadsDimension[0] = threadDim.children[0]->val->val.uv[0];
reflection->DispatchThreadsDimension[1] = threadDim.children[1]->val->val.uv[0];
reflection->DispatchThreadsDimension[2] = threadDim.children[2]->val->val.uv[0];
return;
}
}
break;
}
}
RDCERR("Couldn't find thread dimension tag in shader");
reflection->DispatchThreadsDimension[0] = 1;
reflection->DispatchThreadsDimension[1] = 1;
reflection->DispatchThreadsDimension[2] = 1;
}
DXBC::Reflection *Program::GetReflection()
{
RDCWARN("Unimplemented DXIL::Program::GetReflection()");
return new DXBC::Reflection;
}
D3D_PRIMITIVE_TOPOLOGY Program::GetOutputTopology()
{
if(m_Type != DXBC::ShaderType::Geometry && m_Type != DXBC::ShaderType::Domain)
return D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
for(size_t i = 0; i < m_NamedMeta.size(); i++)
{
if(m_NamedMeta[i].name == "dx.entryPoints")
{
// expect only one child for this, DX doesn't support multiple entry points for compute
// shaders
RDCASSERTEQUAL(m_NamedMeta[i].children.size(), 1);
Metadata &entry = *m_NamedMeta[i].children[0];
RDCASSERTEQUAL(entry.children.size(), 5);
Metadata &tags = *entry.children[4];
for(size_t t = 0; t < tags.children.size(); t += 2)
{
RDCASSERT(tags.children[t]->value);
if(ShaderTag(tags.children[t]->val->val.uv[0]) == ShaderTag::Geometry)
{
Metadata &geomData = *tags.children[t + 1];
RDCASSERTEQUAL(geomData.children.size(), 5);
return (D3D_PRIMITIVE_TOPOLOGY)geomData.children[3]->val->val.uv[0];
}
}
break;
}
}
RDCERR("Couldn't find topology tag in shader");
return D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
}
}; // namespace DXIL
@@ -104,6 +104,7 @@
<ClCompile Include="dxil_bytecode.cpp" />
<ClCompile Include="dxil_debuginfo.cpp" />
<ClCompile Include="dxil_disassemble.cpp" />
<ClCompile Include="dxil_reflect.cpp" />
<ClCompile Include="llvm_decoder.cpp" />
<ClCompile Include="precompiled.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
@@ -8,6 +8,7 @@
<ClCompile Include="dxil_bytecode.cpp" />
<ClCompile Include="dxil_debuginfo.cpp" />
<ClCompile Include="dxil_disassemble.cpp" />
<ClCompile Include="dxil_reflect.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="precompiled.h">