Tips on implementing Render Thread
I'm attempting to make a stand alone app using Noesis following the integration sample, with multiple window support. Below is code I have so far (work in progress). First, I was wondering if anyone could point me in the direction of where in the App framework I could find a render thread implementation. Anyhoo, my first issue is that MessageLoop cannot be started in a separate thread, it causes the window to freeze. If the MessageLoop is started in the main thread, everything is mostly fine. I'm going to try moving my init code to the uiThread.
When the message loop is started on the main thread I have the following issues:
- High cpu usage caused by the update running as fast as it wants. I was wondering how app framework does it, if they set up a vsync or do a simple sleep or use a multimedia timer?
- When maximizing the window, a Access violation error occurs in D3D12RenderContext line 383
Just looking for tips! Thanks!
When the message loop is started on the main thread I have the following issues:
- High cpu usage caused by the update running as fast as it wants. I was wondering how app framework does it, if they set up a vsync or do a simple sleep or use a multimedia timer?
- When maximizing the window, a Access violation error occurs in D3D12RenderContext line 383
Just looking for tips! Thanks!
Code: Select all
NoesisManager::Window::Window(const std::string& title)
: renderStop(false), title(title) {
display = CreateDisplay();
display->SetTitle(title.c_str());
context = createContext(display);
view = CreateView(LoadXaml<UserControl>("Settings.xaml"));
view->SetFlags(RenderFlags_PPAA | RenderFlags_LCD);
setupDisplay(display, context, view);
renderer = view->GetRenderer();
display->Render() += [this](NoesisApp::Display* display)
{
static uint64_t startTime = Noesis::HighResTimer::Ticks();
// Update (layout, animations). Note that global time is used, not a delta
uint64_t time = Noesis::HighResTimer::Ticks();
view->Update(Noesis::HighResTimer::Seconds(time - startTime));
};
renderThread = make_unique<std::thread>(thread([this]() {
renderer->Init(context->GetDevice());
while (!renderStop.load())
{
// Begin rendering
context->BeginRender();
// The offscreen rendering phase must be done before binding the framebuffer. This step
// populates all the internal textures that are needed for the active frame
renderer->UpdateRenderTree();
renderer->RenderOffscreen();
// Bind framebuffer and viewport. Do this per frame because the offscreen phase alters them
context->SetDefaultRenderTarget(display->GetClientWidth(), display->GetClientHeight(), true);
// -> # At this point, you can render your 3D scene... # <-
// Note that each function invocation of the renderer modifies the GPU state, you must
// save and restore it properly in your application
// After rendering the scene we draw the UI on top of it. Note that the render is performed
// in the active framebuffer, being it the backbuffer or a render texture
renderer->Render();
// End render and swap back buffer
context->EndRender();
context->Swap();
}
view->GetRenderer()->Shutdown();
context->Shutdown();
}));
uiThread = make_unique<std::thread>(thread([this]() {
display->EnterMessageLoop(false);
renderStop.store(true);
renderThread->join();
view.Reset();
context.Reset();
display.Reset();
}));
}Re: Tips on implementing Render Thread
My advice: since you're new to this technology, I recommend not implementing a render thread until you’ve become more familiar with Noesis. Doing so requires not only a solid understanding of Noesis but also an in-depth knowledge of the GPU you plan to use and the windowing system you intend to integrate.
Our framework uses V-Sync by default, so you shouldn’t experience high CPU usage.
A great advantage of our application framework is that its source code is available to you, allowing you to debug, experiment, and customize it as needed.
Our framework uses V-Sync by default, so you shouldn’t experience high CPU usage.
A great advantage of our application framework is that its source code is available to you, allowing you to debug, experiment, and customize it as needed.
Re: Tips on implementing Render Thread
I definitely did not want to do any of this lower level stuff to get Noesis working for my use case but I figured I'd dive into it since the documentation states that the application framework is not production ready. however this code does use some app framework code, as so did the integration sample. I thought that the methods I'm using abstract away the window and renderer systems. I did not know however, that a render thread implementation would be that involved.
Who is online
Users browsing this forum: No registered users and 6 guests