Skip to content

Commit

Permalink
minor improvals to emulated mesh shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
Try committed Aug 7, 2022
1 parent 6844536 commit db38f54
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
1 change: 0 additions & 1 deletion Engine/gapi/vulkan/vcommandbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,6 @@ void VMeshCommandBuffer::dispatchMesh(size_t firstInstance, size_t instanceCount
firstInstance, meshIndirectId, 0,
instanceCount, 1, 1);
ms.drawIndirect(impl, meshIndirectId);

++meshIndirectId;
}

Expand Down
36 changes: 19 additions & 17 deletions Engine/gapi/vulkan/vpipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,25 @@ VPipeline::VPipeline(VDevice& device, const RenderState& st, Topology tp,
}
pipelineLayout = initLayout(device,ulay,pushStageFlags,pushSize,false);

if(auto ms=findShader(ShaderReflection::Stage::Mesh)) {
device.allocMeshletHelper();

pipelineLayoutMs = initLayout(device,ulay,pushStageFlags,pushSize,true);

VkComputePipelineCreateInfo info = {};
info.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO;
info.flags = VK_PIPELINE_CREATE_DISPATCH_BASE;
info.stage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
info.stage.stage = VK_SHADER_STAGE_COMPUTE_BIT;
info.stage.module = reinterpret_cast<const VMeshShaderEmulated*>(ms)->compPass;
info.stage.pName = "main";
info.layout = pipelineLayoutMs;
vkAssert(vkCreateComputePipelines(device.device.impl, VK_NULL_HANDLE, 1, &info, nullptr, &meshCompuePipeline));

// cancel native mesh shading
pushStageFlags &= ~VK_SHADER_STAGE_MESH_BIT_NV;
if(device.props.meshlets.meshShaderEmulated) {
if(auto ms=findShader(ShaderReflection::Stage::Mesh)) {
device.allocMeshletHelper();

pipelineLayoutMs = initLayout(device,ulay,pushStageFlags,pushSize,true);

VkComputePipelineCreateInfo info = {};
info.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO;
info.flags = VK_PIPELINE_CREATE_DISPATCH_BASE;
info.stage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
info.stage.stage = VK_SHADER_STAGE_COMPUTE_BIT;
info.stage.module = reinterpret_cast<const VMeshShaderEmulated*>(ms)->compPass;
info.stage.pName = "main";
info.layout = pipelineLayoutMs;
vkAssert(vkCreateComputePipelines(device.device.impl, VK_NULL_HANDLE, 1, &info, nullptr, &meshCompuePipeline));

// cancel native mesh shading
pushStageFlags &= ~VK_SHADER_STAGE_MESH_BIT_NV;
}
}
}
catch(...) {
Expand Down
4 changes: 2 additions & 2 deletions Engine/shaders/mesh_compactage.comp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ layout(binding = 3, std430) buffer EngineInternal4 {

void main() {
uint index = gl_GlobalInvocationID.x;
//if(index>mesh.grow)
// return;
if(index>mesh.desc.length())
return;

uint mestId = index*3;
uint self = mesh.desc[mestId+0];
Expand Down
4 changes: 3 additions & 1 deletion Engine/shaders/mesh_prefix_pass.comp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ void main() {
uint v = prefixVbo;
prefixVbo += indirect.cmd[i].instanceCount;

uint inst = indirect.cmd[i].indexCount>0 ? 1 : 0;

indirect.cmd[i].indexCount = 0;
indirect.cmd[i].instanceCount = 1;
indirect.cmd[i].instanceCount = inst;
indirect.cmd[i].firstIndex = s;
indirect.cmd[i].vertexOffset = 0;
indirect.cmd[i].firstInstance = 0;
Expand Down

0 comments on commit db38f54

Please sign in to comment.