-
Notifications
You must be signed in to change notification settings - Fork 25
[TeleViz] Add DisplayBackend + WindowBackend + Window smoke test example #469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
bd999a0
M4 (1/3): viz_session — GLFW + Swapchain + tile_layout primitives
farbod-nv 5245fd6
M4 (2/3): wire DisplayMode::kWindow end-to-end
farbod-nv 1ba0025
M4 (3/3): examples/televiz/window_smoke + kWindow integration test
farbod-nv 2a9d77d
M4 (4/4): refactor mode dispatch into DisplayBackend abstraction
farbod-nv af0204c
M4 (5/5): smooth resize + present mode + frame pacer
farbod-nv 635b314
deps/glfw: disable Wayland by default, X11 only
farbod-nv 2edeffe
viz/session: trim verbose comments
farbod-nv 0f679ca
viz: address review findings (exception safety, GLFW refcount, CI deps)
farbod-nv f18fdf5
viz/session: WSI failure-path fixes
farbod-nv b5d7bf7
viz: clang-format pass
farbod-nv 43dceec
viz/session: define GLFW_INCLUDE_NONE to avoid GL/gl.h dependency
farbod-nv 1779020
viz/session: tighten WSI abort-recovery ordering
farbod-nv 80b2e61
viz/session: fence reset late + present OUT_OF_DATE recovery
farbod-nv 73d5622
viz/session: reset command buffer on every render() exit
farbod-nv dc691c8
viz/session: tighten end_frame contract docstring
farbod-nv 091580e
viz/session: skip the first-frame pacer sleep
farbod-nv d8546ec
viz/session: add missing <stdexcept> to display_backend.hpp
farbod-nv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| add_subdirectory(window_smoke) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| cmake_minimum_required(VERSION 3.20) | ||
|
|
||
| add_executable(viz_window_smoke main.cpp) | ||
|
|
||
| target_link_libraries(viz_window_smoke PRIVATE | ||
| viz::session | ||
| viz::layers | ||
| ) | ||
|
|
||
| set_target_properties(viz_window_smoke PROPERTIES OUTPUT_NAME "viz_window_smoke") | ||
| install(TARGETS viz_window_smoke RUNTIME DESTINATION examples/televiz/window_smoke) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| // Minimal kWindow demo: opens a 1024x768 GLFW window, fills four | ||
| // QuadLayers with solid RGBA patterns tiled 2x2, runs the render | ||
| // loop until the window closes. | ||
|
|
||
| #include <viz/core/vk_context.hpp> | ||
| #include <viz/layers/quad_layer.hpp> | ||
| #include <viz/session/viz_session.hpp> | ||
|
|
||
| #include <array> | ||
| #include <cstdint> | ||
| #include <cstdio> | ||
| #include <cstdlib> | ||
| #include <cuda_runtime.h> | ||
| #include <memory> | ||
| #include <stdexcept> | ||
| #include <vector> | ||
|
|
||
| namespace | ||
| { | ||
|
|
||
| struct Rgba | ||
| { | ||
| uint8_t r, g, b, a; | ||
| }; | ||
|
|
||
| // RAII wrapper around a cudaMalloc'd buffer. | ||
| struct CudaDeviceBuffer | ||
| { | ||
| void* ptr = nullptr; | ||
| CudaDeviceBuffer() = default; | ||
| explicit CudaDeviceBuffer(size_t bytes) | ||
| { | ||
| if (cudaMalloc(&ptr, bytes) != cudaSuccess) | ||
| { | ||
| ptr = nullptr; | ||
| throw std::runtime_error("cudaMalloc failed"); | ||
| } | ||
| } | ||
| ~CudaDeviceBuffer() | ||
| { | ||
| if (ptr != nullptr) | ||
| { | ||
| cudaFree(ptr); | ||
| } | ||
| } | ||
| CudaDeviceBuffer(const CudaDeviceBuffer&) = delete; | ||
| CudaDeviceBuffer& operator=(const CudaDeviceBuffer&) = delete; | ||
| CudaDeviceBuffer(CudaDeviceBuffer&& o) noexcept : ptr(o.ptr) | ||
| { | ||
| o.ptr = nullptr; | ||
| } | ||
| CudaDeviceBuffer& operator=(CudaDeviceBuffer&& o) noexcept | ||
| { | ||
| if (this != &o) | ||
| { | ||
| if (ptr != nullptr) | ||
| { | ||
| cudaFree(ptr); | ||
| } | ||
| ptr = o.ptr; | ||
| o.ptr = nullptr; | ||
| } | ||
| return *this; | ||
| } | ||
| }; | ||
|
|
||
| CudaDeviceBuffer make_solid_color_buffer(uint32_t width, uint32_t height, Rgba color) | ||
| { | ||
| std::vector<Rgba> host(static_cast<size_t>(width) * height, color); | ||
| CudaDeviceBuffer buf(host.size() * sizeof(Rgba)); | ||
| if (cudaMemcpy(buf.ptr, host.data(), host.size() * sizeof(Rgba), cudaMemcpyHostToDevice) != cudaSuccess) | ||
| { | ||
| throw std::runtime_error("cudaMemcpy failed"); | ||
| } | ||
| return buf; | ||
| } | ||
|
|
||
| void submit_solid(viz::QuadLayer& layer, void* dev_ptr, uint32_t w, uint32_t h) | ||
| { | ||
| viz::VizBuffer src{}; | ||
| src.data = dev_ptr; | ||
| src.width = w; | ||
| src.height = h; | ||
| src.format = viz::PixelFormat::kRGBA8; | ||
| src.pitch = static_cast<size_t>(w) * 4; | ||
| src.space = viz::MemorySpace::kDevice; | ||
| layer.submit(src); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| int main() | ||
| { | ||
| constexpr uint32_t kWindowW = 1024; | ||
| constexpr uint32_t kWindowH = 768; | ||
| constexpr uint32_t kQuadW = 256; | ||
| constexpr uint32_t kQuadH = 256; | ||
|
|
||
| viz::VizSession::Config cfg{}; | ||
| cfg.mode = viz::DisplayMode::kWindow; | ||
| cfg.window_width = kWindowW; | ||
| cfg.window_height = kWindowH; | ||
| cfg.app_name = "viz_window_smoke"; | ||
| // Dark grey clear so letterbox margins are visible against the quads. | ||
| cfg.clear_color[0] = 0.1f; | ||
| cfg.clear_color[1] = 0.1f; | ||
| cfg.clear_color[2] = 0.1f; | ||
| cfg.clear_color[3] = 1.0f; | ||
|
|
||
| try | ||
| { | ||
| auto session = viz::VizSession::create(cfg); | ||
| const viz::VkContext* ctx = session->get_vk_context(); | ||
| const VkRenderPass render_pass = session->get_render_pass(); | ||
|
|
||
| const std::array<Rgba, 4> palette = { { | ||
| { 220, 60, 60, 255 }, // red | ||
| { 60, 220, 60, 255 }, // green | ||
| { 60, 100, 220, 255 }, // blue | ||
| { 220, 220, 220, 255 }, // white | ||
| } }; | ||
|
|
||
| // RAII: buffers freed on scope exit (normal or exception). | ||
| // Outlive the session — submit() copies into the mailbox, so | ||
| // the device pointers can be freed any time after. | ||
| std::vector<CudaDeviceBuffer> device_buffers; | ||
| device_buffers.reserve(palette.size()); | ||
| for (size_t i = 0; i < palette.size(); ++i) | ||
| { | ||
| viz::QuadLayer::Config layer_cfg; | ||
| layer_cfg.name = "smoke_quad_" + std::to_string(i); | ||
| layer_cfg.resolution = { kQuadW, kQuadH }; | ||
| auto* layer = session->add_layer<viz::QuadLayer>(*ctx, render_pass, layer_cfg); | ||
|
|
||
| device_buffers.push_back(make_solid_color_buffer(kQuadW, kQuadH, palette[i])); | ||
| submit_solid(*layer, device_buffers.back().ptr, kQuadW, kQuadH); | ||
| } | ||
|
|
||
| // Print fps once per second (60 frames at 60Hz) so resize / | ||
| // move stalls show up as drops in the terminal output. | ||
| while (!session->should_close()) | ||
| { | ||
| const auto info = session->render(); | ||
| if (info.frame_index > 0 && info.frame_index % 60 == 0) | ||
| { | ||
| const auto stats = session->get_frame_timing_stats(); | ||
| std::printf("frame %llu: %.1f fps (%.2f ms/frame)\n", static_cast<unsigned long long>(info.frame_index), | ||
| stats.render_fps, stats.avg_frame_time_ms); | ||
| std::fflush(stdout); | ||
| } | ||
| } | ||
|
|
||
| session.reset(); // tear down before buffers go out of scope | ||
| } | ||
| catch (const std::exception& e) | ||
| { | ||
| std::fprintf(stderr, "viz_window_smoke: %s\n", e.what()); | ||
| return EXIT_FAILURE; | ||
| } | ||
| return EXIT_SUCCESS; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.