Skip to content

Commit

Permalink
fix working CS <-> VS split
Browse files Browse the repository at this point in the history
  • Loading branch information
Try committed Aug 21, 2022
1 parent 97e044c commit 42e8916
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
23 changes: 13 additions & 10 deletions Engine/gapi/spirv/meshconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ void MeshConverter::exec() {
it.setToNop();
continue;
}
if(i.op()==spv::OpMemberDecorate) {
if(i[3]==spv::DecorationBuiltIn ||
i[3]==spv::DecorationPerViewNV)
if(i.op()==spv::OpMemberDecorate && i[3]==spv::DecorationBuiltIn) {
if(i[4]==spv::BuiltInPosition || i[4]==spv::BuiltInPointSize)
it.setToNop();
continue;
}
Expand All @@ -103,13 +102,14 @@ void MeshConverter::exec() {

if(an.canGenerateVs()) {
generateVsSplit();
removeMultiview(code);
removeCullClip(code);
} else {
removeMultiview(code);
removeCullClip(code);
generateVsDefault();
}

removeMultiview(code);
removeCullClip(code);

// meslet entry-point
uint32_t idMain = -1;
{
Expand Down Expand Up @@ -797,16 +797,16 @@ void MeshConverter::removeMultiview(libspirv::MutableBytecode& code) {
if(an.idMeshPerVertexNV==0)
return;

std::unordered_set<uint32_t> perView;
std::unordered_set<uint32_t> fields;
for(auto it = code.begin(), end = code.end(); it!=end; ++it) {
auto& i = *it;
if(i.op()==spv::OpMemberDecorate && i[3]==spv::DecorationPerViewNV) {
perView.insert(i[2]);
fields.insert(i[2]);
continue;
}
}

removeFromPerVertex(code,perView);
removeFromPerVertex(code,fields);
}

void MeshConverter::removeCullClip(libspirv::MutableBytecode& code) {
Expand Down Expand Up @@ -834,6 +834,9 @@ void MeshConverter::removeCullClip(libspirv::MutableBytecode& code) {

void MeshConverter::removeFromPerVertex(libspirv::MutableBytecode& code,
const std::unordered_set<uint32_t>& fields) {
if(fields.size()==0)
return;

for(auto it = code.begin(), end = code.end(); it!=end; ++it) {
auto& i = *it;
if((i.op()!=spv::OpMemberDecorate && i.op()!=spv::OpMemberName) || i[1]!=an.idMeshPerVertexNV)
Expand Down Expand Up @@ -952,8 +955,8 @@ void MeshConverter::generateVsDefault() {
fn.insert(spv::OpTypeRuntimeArray, {_runtimearr_uint, uint_t});

std::unordered_map<uint32_t,uint32_t> constants;
uint32_t varCount = 0;
{
uint32_t varCount = 0;
for(auto& i:an.varying) {
// preallocate indexes
code.traverseType(i.second.type,[&](const libspirv::MutableBytecode::AccessChain* ids, uint32_t len) {
Expand Down
25 changes: 17 additions & 8 deletions Engine/gapi/spirv/shaderanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ ShaderAnalyzer::ShaderAnalyzer(libspirv::MutableBytecode& code)

template<class ... T>
void ShaderAnalyzer::log(const T& ... args) {
//int dummy[] = {(std::cout << args, 0)...}; (void)dummy;
//std::cout << std::endl;
// int dummy[] = {(std::cout << args, 0)...}; (void)dummy;
// std::cout << std::endl;
}

void ShaderAnalyzer::analyze() {
Expand Down Expand Up @@ -305,6 +305,8 @@ void ShaderAnalyzer::analyzeThreadMap() {

for(auto& i:variables) {
i.second.v.access = toAccessBits(spv::StorageClass(i.second.cls));
if(i.second.cls==spv::StorageClassOutput)
i.second.v.access = AC_None;
}

auto st = registers;
Expand Down Expand Up @@ -372,14 +374,15 @@ void ShaderAnalyzer::analyzeBlock(const uint32_t functionCurrent, const libspirv
return;
}
case spv::OpReturn: {
// std::cout << " + return" << std::endl;
log(" + return ");
break;
}
case spv::OpReturnValue: {
uint32_t ret = calee[2];
auto& l = registers[ret]; // reg
auto& r = registers[i[1]]; // reg
l.v = r.v;
// l.v.access |= fn.read;
log(" + return ", toStr(r.v.access));
break;
}
Expand Down Expand Up @@ -484,13 +487,18 @@ void ShaderAnalyzer::analyzeInstr(const uint32_t functionCurrent, const libspirv
break;
}
case spv::OpStore: {
// FIXME: control flow ?
auto l = registers[i[1]]; // ptr
auto r = registers[i[2]]; // reg
auto id = dereferenceAccessChain(l.v.pointer);

auto& v = variables[id];
v.v = r.v;
if(l.v.pointer.chain.size()<=1) {
v.v = r.v;
} else {
// composite object
v.v.hasVal = false;
v.v.access |= r.v.access;
}
v.v.access |= l.v.access;
v.v.access |= acExt;

Expand All @@ -503,10 +511,11 @@ void ShaderAnalyzer::analyzeInstr(const uint32_t functionCurrent, const libspirv
//std::cout << toStr(l.v);
std::cout << "] = " << toStr(v.v.access) << std::endl;
*/

if(l.v.pointer.chain.size()>1 && id!=idPrimitiveIndicesNV && id!=idPrimitiveCountNV) {
markOutputsAsThreadRelated(l.v.pointer.chain[1], currentThread, v.v.access);
}
else if(l.v.pointer.chain.size()>1 && id==idPrimitiveIndicesNV) {
else if(l.v.pointer.chain.size()>1 && id==idPrimitiveCountNV) {
markIndexAsThreadRelated(l.v.pointer.chain[1], currentThread, v.v.access);
}
}
Expand Down Expand Up @@ -534,7 +543,7 @@ void ShaderAnalyzer::analyzeInstr(const uint32_t functionCurrent, const libspirv
l.v.pointer.chain.push_back(uint32_t(-1));
}

makeWriteAccess(functionCurrent, blockId, t.access);
// makeWriteAccess(functionCurrent, blockId, t.access);
break;
}
case spv::OpCompositeConstruct:{
Expand Down Expand Up @@ -629,7 +638,7 @@ void ShaderAnalyzer::analyzeInstr(const uint32_t functionCurrent, const libspirv
l.v.access = (a.v.access | b.v.access);
break;
}
case spv::OpBitcast:{
case spv::OpBitcast: {
auto& l = registers[i[2]];
auto r = registers[i[3]];
l.v = r.v;
Expand Down
2 changes: 1 addition & 1 deletion Engine/gapi/vulkan/vmeshlethelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class VMeshletHelper {
public:
enum {
MeshletsMaxCount = 1024*32,
IndirectCmdCount = 4048,
IndirectCmdCount = 8096,
PipelinewordsCount = 32*1024*1024,
PipelineMemorySize = PipelinewordsCount*4,
MeshletsMemorySize = MeshletsMaxCount*3*4,
Expand Down
4 changes: 2 additions & 2 deletions Engine/gapi/vulkan/vmeshshaderemulated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ VMeshShaderEmulated::VMeshShaderEmulated(VDevice& device, const void *source, si
MeshConverter conv(code);
conv.exec();

// debugLog("mesh_orig.mesh.spv", reinterpret_cast<const uint32_t*>(source),src_size/4);
//debugLog("mesh_orig.mesh.spv", reinterpret_cast<const uint32_t*>(source),src_size/4);

auto& vert = conv.vertexPassthrough();
// debugLog("mesh_conv.comp.spv", code.opcodes(), code.size());
Expand All @@ -37,7 +37,7 @@ VMeshShaderEmulated::VMeshShaderEmulated(VDevice& device, const void *source, si
std::system("spirv-val.exe .\\mesh_conv.comp.spv");
*/

// debugLog("mesh_conv.vert.spv", vert.opcodes(), vert.size());
//debugLog("mesh_conv.vert.spv", vert.opcodes(), vert.size());
/*
std::system("spirv-cross.exe -V .\\mesh_conv.vert.spv");
std::system("spirv-val.exe .\\mesh_conv.vert.spv");
Expand Down

0 comments on commit 42e8916

Please sign in to comment.