Mandelbrot set rendering on the compute shader and automatically synchronizes the result back to display.
{
class MandelbrotComputeDemoApp : public RenderApplication
{
struct PushConstant
{
};
{
ResourceHandle buffer = createResource(
RHITextureDesc{.usage = RHITextureUsageBits::SampledImage | RHITextureUsageBits::StorageImage,
.extent = mRenderer->GetSwapchainExtent3D(),
.format = RHIResourceFormat::R8G8B8A8Unorm});
ResourceHandle sampler = createSampler(
mRenderer.get(), {});
createPass(
mRenderer.get(),
"Mandelbrot", RHIDeviceQueueType::Compute,
[=](PassHandle self, Renderer* r)
{
r->BindShader(self, RHIShaderStageBits::Compute, "csMain", "data/shaders/MandelbrotCompute.spv");
r->BindPushConstant(self, RHIShaderStageBits::Compute, 0, sizeof(PushConstant));
r->BindTextureUAV(
self, buffer, "image", RHIPipelineStageBits::ComputeShader,
{.format = RHIResourceFormat::R8G8B8A8Unorm, .range = RHITextureSubresourceRange::Create()});
},
[=, this](PassHandle self, Renderer* r, RHICommandList* cmd)
{
auto image_wh = r->DerefResource(buffer).Get<RHITexture*>()->
mDesc.extent;
r->CmdSetPipeline(self, cmd);
r->CmdSetPushConstant(self, cmd, RHIShaderStageBits::Compute, 0,
r->CmdDispatch(self, cmd, image_wh);
});
createPSBackbufferBlitPass(
mRenderer.get(),
"Backbuffer Blit", sampler, buffer);
}
};
}
int main(
int argc,
char** argv)
{
const bool useAsync =
CreateMessageBox(
"Async Compute",
"Enable Async Compute?", MessageBoxType::YesNo,
MessageBoxIcon::Question, MessageBoxResult::Yes) == MessageBoxResult::Yes;
{.windowTitle = "Mandelbrot Async Compute", .renderer = {.enableAsyncCompute = useAsync}});
}
int main(int argc, char **argv)
Definition ImGui.cpp:26
Definition MandelbrotCompute.cpp:11
void OnRendererSetup() override
Set up the renderer by creating passes, resources, and other configurations.
Definition MandelbrotCompute.cpp:18
T GetApplicationTime() const
Returns a high-resolution time in seconds since the application started.
Definition Application.hpp:60
ApplicationInitDesc mDesc
Definition Application.hpp:93
void Initialize(ApplicationInitDesc const &desc={}, Args &&... args)
Initialize the application with the specified RHI backend.
Definition Application.hpp:205
UniquePtr< Renderer > mRenderer
Definition Application.hpp:102
void RunForever()
Start the Render thread and run the application loop indefinitely, until the window is closed or the ...
Definition Application.cpp:127
For a complete list of examples, see the Examples Page.
Definition Examples.hpp:12
MessageBoxResult CreateMessageBox(const char *title, const char *message, MessageBoxType type, MessageBoxIcon icon, MessageBoxResult default_result)
Creates a message box with the specified title and message.
Definition Application.cpp:66
RHIExtent2D resolution
Definition MandelbrotCompute.cpp:16
float pad
Definition MandelbrotCompute.cpp:15
float time
Definition MandelbrotCompute.cpp:14