-
Notifications
You must be signed in to change notification settings - Fork 7
TBR Pipeline Implementation & Pipeline Optimization #14
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
24 commits
Select commit
Hold shift + click to select a range
979a251
fix typo
indevn b9f2ae8
Implement perspective division and viewport transformation with persp…
indevn 7093d82
implement tile-based rasterizer and refractor the pipeline to support…
indevn 8d58a84
Add Performance Profiling for Deffered Pipeline. Remove detailed debu…
indevn d0ddf62
Expand the Vertex data structure, implement frustum culling and backf…
indevn a4021cd
Fix rendering consistency between TRADITIONAL and TILE_BASED modes
indevn 70e1581
add debug mode
indevn 4538667
Revert "add debug mode", which is not necessary for rendering tests.
indevn b57d907
Add Early-Z to TBR. Remove obsolete functions previously used for TBR…
indevn 1d2d9a9
TBR: Pre-allocate and reuse fragment caches; add RasterizeTo; two-pas…
indevn 8a74379
vertex optimization: avoid data movement and multi-stage memory reall…
indevn bb5acc1
TBR: Use SoA vertex layout to improve cache locality
indevn 0549211
TBR: Use global framebuffer to avoid merge overhead
indevn 258607a
TBR: Optimize global buffer write-back logic
indevn ffe0d75
Optimize perspective correction, add helper func, simplify code
indevn 957c9b0
Refactor: Extract pipeline into standalone class; rename TraditionalP…
indevn d6e3b40
TBR: Replace barycentric coordinate computation with half-space testi…
indevn 30038ef
DR: Optimize fragment collection(pre-reserve per bucket, move-insert,…
indevn 61e75a8
Refactor: Modify the triangle binning logic in TBR to use the TileGri…
indevn 86d06ad
Change timing-related debug messages from SPDLOG_INFO to SPDLOG_DEBUG…
indevn 0ea7f22
TBR: Perform mask-based computation for TBR rasterization to achieve …
indevn b659f57
VS: Optimize the vertex matrix caching in shaders by adding cache pre…
indevn e81bcff
FS: Cache vectors and matrices to avoid redundant computations.
indevn b84cfd2
Enhanced shader class with LUT caching for specular reflection to opt…
indevn 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
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,31 @@ | ||
| #ifndef SIMPLERENDER_SRC_INCLUDE_RENDERERS_DEFERRED_RENDERER_HPP_ | ||
| #define SIMPLERENDER_SRC_INCLUDE_RENDERERS_DEFERRED_RENDERER_HPP_ | ||
|
|
||
| #include "renderers/renderer_base.hpp" | ||
|
|
||
| namespace simple_renderer { | ||
|
|
||
| /** | ||
| * @brief 延迟渲染器(Deferred) | ||
| * | ||
| * 组织处理方式模拟 OpenGL 在 GPU上的工作原理,模仿 GPU管线。 | ||
| * 但相比于另外两个前向渲染实现,导致内存使用增加和渲染速度变慢。 | ||
| * | ||
| * 特点: | ||
| * - AoS 顶点路径; | ||
| * - 首先按像素收集所有片段并选择最近深度; | ||
| * - 再对选择的片段执行片段着色(模拟经典 GPU 管线的一种教学实现)。 | ||
| * - | ||
| */ | ||
| class DeferredRenderer final : public RendererBase { | ||
| public: | ||
| using RendererBase::RendererBase; | ||
| /** | ||
| * @copydoc RendererBase::Render | ||
| */ | ||
| bool Render(const Model& model, const Shader& shader, uint32_t* out_color) override; | ||
| }; | ||
|
|
||
| } // namespace simple_renderer | ||
|
|
||
| #endif // SIMPLERENDER_SRC_INCLUDE_RENDERERS_DEFERRED_RENDERER_HPP_ |
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,28 @@ | ||
| #ifndef SIMPLERENDER_SRC_INCLUDE_RENDERERS_PER_TRIANGLE_RENDERER_HPP_ | ||
| #define SIMPLERENDER_SRC_INCLUDE_RENDERERS_PER_TRIANGLE_RENDERER_HPP_ | ||
|
|
||
| #include "renderers/renderer_base.hpp" | ||
|
|
||
| namespace simple_renderer { | ||
|
|
||
| /** | ||
| * @brief 逐三角形渲染器(Triangle‑Major) | ||
| * | ||
| * 特点: | ||
| * - AoS 顶点路径; | ||
| * - 每线程本地 framebuffer(depth/color)合并; | ||
| * - 背面剔除在屏幕空间完成; | ||
| * - 接近“传统”栈式前向渲染教学实现。 | ||
| */ | ||
| class PerTriangleRenderer final : public RendererBase { | ||
| public: | ||
| using RendererBase::RendererBase; | ||
| /** | ||
| * @copydoc RendererBase::Render | ||
| */ | ||
| bool Render(const Model& model, const Shader& shader, uint32_t* out_color) override; | ||
| }; | ||
|
|
||
| } // namespace simple_renderer | ||
|
|
||
| #endif // SIMPLERENDER_SRC_INCLUDE_RENDERERS_PER_TRIANGLE_RENDERER_HPP_ |
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,66 @@ | ||
| // Renderer base and options | ||
| #ifndef SIMPLERENDER_SRC_INCLUDE_RENDERERS_RENDERER_BASE_HPP_ | ||
| #define SIMPLERENDER_SRC_INCLUDE_RENDERERS_RENDERER_BASE_HPP_ | ||
|
|
||
| #include <cstdint> | ||
| #include <memory> | ||
|
|
||
| #include "rasterizer.hpp" | ||
| #include "vertex.hpp" | ||
| #include "model.hpp" | ||
| #include "shader.hpp" | ||
|
|
||
| namespace simple_renderer { | ||
|
|
||
|
|
||
| /** | ||
| * @brief 渲染器抽象基类 | ||
| * | ||
| * 约定: | ||
| * - Render 负责完成完整的渲染过程(顶点变换 + 光栅化 + 着色 + 写入输出缓冲)。 | ||
| * - 子类选择不同的“组织单元”:(按照并行组织单元)逐三角形、按 tile、或延迟管线。 | ||
| * - 公共的透视除法与视口变换在此提供,子类按需复用。 | ||
| */ | ||
| class RendererBase { | ||
| public: | ||
| RendererBase(size_t width, size_t height) | ||
| : width_(width), height_(height), rasterizer_(std::make_shared<Rasterizer>(width, height)) {} | ||
| virtual ~RendererBase() = default; | ||
|
|
||
| RendererBase(const RendererBase&) = delete; | ||
| RendererBase& operator=(const RendererBase&) = delete; | ||
|
|
||
| /** | ||
| * @brief 执行一次渲染 | ||
| * @param model 模型数据 | ||
| * @param shader 着色器(包含材质/光照/矩阵等 uniform) | ||
| * @param out_color 输出颜色缓冲(大小为 width*height) | ||
| * @return 是否渲染成功 | ||
| */ | ||
| virtual bool Render(const Model& model, const Shader& shader, uint32_t* out_color) = 0; | ||
|
|
||
| protected: | ||
| /** | ||
| * @brief 透视除法:裁剪空间 -> NDC | ||
| * @param vertex 裁剪空间顶点 | ||
| * @return NDC 顶点(保留 1/w 以供透视校正) | ||
| */ | ||
| Vertex PerspectiveDivision(const Vertex& vertex); | ||
| /** | ||
| * @brief 视口变换:NDC -> 屏幕坐标 | ||
| * @param vertex NDC 顶点 | ||
| * @return 屏幕空间顶点 | ||
| */ | ||
| Vertex ViewportTransformation(const Vertex& vertex); | ||
|
|
||
| protected: | ||
| size_t width_; | ||
| size_t height_; | ||
| std::shared_ptr<Rasterizer> rasterizer_; | ||
|
|
||
| static constexpr float kMinWValue = 1e-6f; | ||
| }; | ||
|
|
||
| } // namespace simple_renderer | ||
|
|
||
| #endif // SIMPLERENDER_SRC_INCLUDE_RENDERERS_RENDERER_BASE_HPP_ |
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.