native renderer: game world at MT_RENDER_SCALE (0.75 on Android), MSAA default 2

Draws recorded inside CPythonApplication::RenderGame are marked Render3DDraw::scene and
drawn by a scene pass compatible with pass_ into a reduced-resolution image, composited
where RenderGame drew; the UI stays full resolution. --render-scale / MT_RENDER_SCALE,
desktop default 1.0 (unchanged path).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-09-30 11:28:05 +09:00
co-authored by Claude Opus 5.5
parent b7c215ee42
commit 44a020f01e
12 changed files with 307 additions and 11 deletions
+32
View File
@@ -136,6 +136,9 @@ public:
std::uint64_t frame_number() const { return frame_number_; }
int msaa_samples() const { return int(samples_); }
// The game world's resolution relative to the swapchain (MT_RENDER_SCALE; 1 = drawn in the
// back-buffer pass as before).
float render_scale() const { return scene_pass_ ? render_scale_ : 1.0f; }
std::uint32_t width() const { return extent_.width; }
std::uint32_t height() const { return extent_.height; }
std::uint32_t logical_width() const;
@@ -201,6 +204,9 @@ private:
// render()'s phases, in call order (vk_frame.cpp).
struct FrameDraws {
std::vector<PreparedDraw> prepared_draws; // the back-buffer pass
// Render3DDraw::scene draws at render_scale(): drawn by the scene pass into scene_texture_,
// which a quad in prepared_draws (where the first of them was recorded) composites.
std::vector<PreparedDraw> scene_draws;
// Draws into offscreen render targets (the shadow map), in recorded order, drawn before the
// back-buffer pass that samples them.
std::vector<PreparedDraw> offscreen_draws;
@@ -282,6 +288,19 @@ private:
// the device can render to it) + D32 depth, both loaded and stored, colour left shader-readable.
void create_offscreen_pass();
// The reduced-resolution scene pass: pass_'s attachments (so pass_ pipelines draw in it) at
// scene_extent_, resolving into the sampled scene_texture_. Unsupported when the swapchain
// format cannot be sampled; render_scale() is then 1.
void create_scene_pass();
// scene_texture_ and its attachments at render_scale_ of the current extent.
void ensure_scene_target();
void destroy_scene_target();
// The composite quad over the whole back buffer sampling scene_texture_.
PreparedDraw scene_composite_draw();
// "rt:<id>:<w>x<h>" -> its render target, created on first use (by a draw into it or by a draw
// sampling it); null for a malformed name.
RenderTarget* get_render_target(const std::string& name);
@@ -441,6 +460,19 @@ private:
std::unordered_map<std::string, PairedDescriptor> paired_descriptors_;
std::unordered_map<std::string, RenderTarget> render_targets_;
VkRenderPass offscreen_pass_ = VK_NULL_HANDLE;
float render_scale_ = 1.0f;
bool scene_supported_ = false;
VkRenderPass scene_pass_ = VK_NULL_HANDLE;
VkExtent2D scene_extent_{};
VkImage scene_msaa_image_ = VK_NULL_HANDLE;
VkDeviceMemory scene_msaa_memory_ = VK_NULL_HANDLE;
VkImageView scene_msaa_view_ = VK_NULL_HANDLE;
VkImage scene_depth_image_ = VK_NULL_HANDLE;
VkDeviceMemory scene_depth_memory_ = VK_NULL_HANDLE;
VkImageView scene_depth_view_ = VK_NULL_HANDLE;
VkFramebuffer scene_framebuffer_ = VK_NULL_HANDLE;
GpuTexture scene_texture_{};
Geometry scene_quad_{};
VkFormat offscreen_format_ = VK_FORMAT_R5G6B5_UNORM_PACK16;
std::size_t last_offscreen_draw_count_ = 0;
VkShaderModule vertex_module_ = VK_NULL_HANDLE;