Drop the extra full-screen copy at render scale < 1

The SDL_GPU pipeline renders into its own view-sized colour target and
already composites it over the whole render target, so routing it through
gpu_scene_texture cost one extra same-size copy per frame. The scaled
intermediate is now used only by the SDL geometry fallback; the hardware
composite upscales with linear filtering.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-12 17:19:51 +09:00
co-authored by Claude Opus 5.5
parent b57f2fba99
commit df87bc64eb
4 changed files with 21 additions and 2 deletions
+5 -2
View File
@@ -2193,7 +2193,10 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
uint32_t clear_col = (last_phase == "game") ? current_env.fog.GetColorUint() : 0x00000000;
if (use_gpu_raster) {
// High Performance Hardware-Accelerated GPU Pipeline (Metal / Vulkan via SDL_RenderGeometry)
if (gpu_scene_texture) {
// Only the SDL geometry fallback rasterizes at screen coordinates and needs the
// scaled intermediate; the hardware pipeline upscales its colour target in one blit.
const bool scaled_target = gpu_scene_texture && !renderer3d->HasHardwarePipeline();
if (scaled_target) {
SDL_SetRenderTarget(renderer.get(), gpu_scene_texture.get());
SDL_SetRenderDrawColor(renderer.get(), (clear_col >> 16) & 0xFF, (clear_col >> 8) & 0xFF, clear_col & 0xFF, (clear_col >> 24) & 0xFF);
SDL_RenderClear(renderer.get());
@@ -2201,7 +2204,7 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
renderer3d->RenderSceneGPU(renderer.get(), draw_list);
if (gpu_scene_texture) {
if (scaled_target) {
SDL_SetRenderTarget(renderer.get(), nullptr);
SDL_FRect dst = { 0.0f, 0.0f, static_cast<float>(screen_width), static_cast<float>(screen_height) };
SDL_RenderTexture(renderer.get(), gpu_scene_texture.get(), nullptr, &dst);
+2
View File
@@ -96,6 +96,8 @@ public:
void RenderSceneGPU(SDL_Renderer* renderer, const std::vector<Render3DDraw>& draws);
void RenderSceneGPU(SDL_Renderer* renderer, const std::vector<const Render3DDraw*>& draws);
void SetGPUDevice(SDL_GPUDevice* device);
// The SDL_GPU pipeline composites its own (smaller) colour target to the full render target.
bool HasHardwarePipeline() const { return m_hardware != nullptr; }
void DestroyGPUTextures();
SDL_Texture* GetGPUTexture(SDL_Renderer* renderer, const std::string& texturePath);
+1
View File
@@ -127,6 +127,7 @@ bool HardwareScene::Initialize(SDL_Renderer* renderer,int width,int height) {
// The target accumulates premultiplied colors. Transparent pixels keep
// the Python selection background and other existing 2D layers intact.
SDL_SetTextureBlendMode(output_,SDL_BLENDMODE_BLEND_PREMULTIPLIED);
SDL_SetTextureScaleMode(output_,SDL_SCALEMODE_LINEAR); // render-scale < 1 upscales in the composite
width_=width;height_=height;
}
return true;
+13
View File
@@ -80,6 +80,19 @@ int main() {
for(int i=0;i<100;++i)UI::DrawText(renderer,"NPC label",12,0,0,i%2 ? 0xffff0000 : 0xff00ff00);
assert(SDL_RenderPresent(renderer));
}
{ // Render scale < 1: a smaller colour target is upscaled over the whole render target in the composite.
ava2::HardwareScene scaled(device);
std::vector<ava2::HardwareVertex> quad;
for(auto p: {std::pair{-1.f,-1.f},std::pair{1.f,-1.f},std::pair{1.f,1.f},std::pair{-1.f,1.f}})
quad.push_back({{p.first,p.second,.5f,1},{255,0,0,255},{0,0}});
SDL_SetRenderDrawColor(renderer,0,255,0,255);SDL_RenderClear(renderer);
assert(scaled.Render(renderer,32,32,quad,{0,1,2,0,2,3},{{0,6,nullptr,1,true,true,false,false,-1}}));
auto* pixels=SDL_RenderReadPixels(renderer,nullptr);assert(pixels);
auto redAt=[&](int x,int y){Uint32 v=0;std::memcpy(&v,static_cast<Uint8*>(pixels->pixels)+y*pixels->pitch+x*SDL_BYTESPERPIXEL(pixels->format),SDL_BYTESPERPIXEL(pixels->format));
Uint8 r,g,b,a;SDL_GetRGBA(v,SDL_GetPixelFormatDetails(pixels->format),nullptr,&r,&g,&b,&a);return r>245&&g<5;};
assert(redAt(1,1)&&redAt(62,62)&&redAt(62,1)&&redAt(1,62)&&redAt(32,32));
SDL_DestroySurface(pixels);SDL_RenderPresent(renderer);
}
{
ava2::Gr2SceneRenderer raster(64,64);
raster.SetGPUDevice(device);