MCPcopy Create free account
hub / github.com/NVIDIA-RTX/Donut-Samples / MeshletExample

Class MeshletExample

examples/meshlets/meshlets.cpp:34–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32static const char* g_WindowTitle = "Donut Example: Meshlets";
33
34class MeshletExample : public app::IRenderPass
35{
36private:
37 nvrhi::ShaderHandle m_AmplificationShader;
38 nvrhi::ShaderHandle m_MeshShader;
39 nvrhi::ShaderHandle m_PixelShader;
40 nvrhi::MeshletPipelineHandle m_Pipeline;
41 nvrhi::CommandListHandle m_CommandList;
42
43public:
44 using IRenderPass::IRenderPass;
45
46 bool Init()
47 {
48 auto nativeFS = std::make_shared<vfs::NativeFileSystem>();
49
50 std::filesystem::path appShaderPath = app::GetDirectoryWithExecutable() / "shaders/meshlets" / app::GetShaderTypeName(GetDevice()->getGraphicsAPI());
51
52 engine::ShaderFactory shaderFactory(GetDevice(), nativeFS, appShaderPath);
53 m_AmplificationShader = shaderFactory.CreateShader("shaders.hlsl", "main_as", nullptr, nvrhi::ShaderType::Amplification);
54 m_MeshShader = shaderFactory.CreateShader("shaders.hlsl", "main_ms", nullptr, nvrhi::ShaderType::Mesh);
55 m_PixelShader = shaderFactory.CreateShader("shaders.hlsl", "main_ps", nullptr, nvrhi::ShaderType::Pixel);
56
57 if (!m_AmplificationShader || !m_MeshShader || !m_PixelShader)
58 {
59 return false;
60 }
61
62 m_CommandList = GetDevice()->createCommandList();
63
64 return true;
65 }
66
67 void Animate(float fElapsedTimeSeconds) override
68 {
69 GetDeviceManager()->SetInformativeWindowTitle(g_WindowTitle);
70 }
71
72 void BackBufferResizing() override
73 {
74 m_Pipeline = nullptr;
75 }
76
77 void Render(nvrhi::IFramebuffer* framebuffer) override
78 {
79 if (!m_Pipeline)
80 {
81 nvrhi::MeshletPipelineDesc psoDesc;
82 psoDesc.AS = m_AmplificationShader;
83 psoDesc.MS = m_MeshShader;
84 psoDesc.PS = m_PixelShader;
85 psoDesc.primType = nvrhi::PrimitiveType::TriangleList;
86 psoDesc.renderState.depthStencilState.depthTestEnable = false;
87
88 m_Pipeline = GetDevice()->createMeshletPipeline(psoDesc, framebuffer->getFramebufferInfo());
89 }
90
91 m_CommandList->open();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected