libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
8.69k stars 1.63k forks source link

Batch rendering not implemented for d3d11 #7534

Open LauPhi opened 1 year ago

LauPhi commented 1 year ago

OS: Windows 10 SDL: 2.26.4 GCC: 12.2.0 (x86_64-posix-seh-rev2, Built by MinGW-W64 project)

I was using RenderDoc to confirm that the batch rendering was working but it is actually not.
I am specifying a direct3d11 renderer because RenderDoc can not capture OpenGL 2 frames.

I am setting the hints like this:

SDL_SetHint(SDL_HINT_RENDER_DRIVER, "direct3d11");
SDL_SetHint(SDL_HINT_RENDER_BATCHING, "1");

Then creating the renderer with:

const Uint32 rendererFlags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC;
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, rendererFlags);

The texture is rendered using 8 times:

SDL_RenderCopy(renderer, texture, NULL, &imageRect);

So no flush should happen until SDL_RenderPresent(renderer); at the end of the frame.

Here is the frame capture from RenderDoc: RenderDoc

As you can see, there is 8 separate draw calls for essentially the same texture.

I tried spacing the drawn rectangles and it did not enable batching either.

Here is the minimal reproduction project: SDLBatchingNotWorking.zip

1bsyl commented 1 year ago

Indeed ...

d3d11 (nor d3d12) isn't really batching: https://github.com/libsdl-org/SDL/blob/main/src/render/direct3d11/SDL_render_d3d11.c#L2100 gles2 (and gl) does: https://github.com/libsdl-org/SDL/blob/main/src/render/opengles2/SDL_render_gles2.c#L1299

There are 3 levels of batching in sdl:

Though you can submit a PR to improve d3d11 ..