-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Open
Description
SDL3 version 3.2.24
The direct3d11 renderer seems to have a worse performance when rendering things, compared to other backends.
You should be able to set the renderer backend, for example by using this line: SDL_SetHint(SDL_HINT_RENDER_DRIVER, "direct3d");
If you use an external fps counter, (E.g RivaTuner from MSI Afterburner) it might show a different framerate, compared to the one in the test code.
The renderer by default seems to use direct3d11 on windows.
Here is the test code:
#include <SDL3/SDL.h>
SDL_Window* window;
SDL_Renderer* renderer;
bool active = true;
Uint64 ticks = 0;
Uint64 lastTicks = 0;
float timer = 1;
float duration = 1;
int fps = 0;
SDL_FRect theRect = { 0, 200, 32, 32 };
SDL_Texture* surfaceTex;
// if your computer is too fast, you can increase this value
int amountOfTexturesRendered = 20;
void Render();
void CreateTestSurface();
int main(int argc, char* argv[])
{
// If you switch the hint renderer driver to anything except direct3d11 it should be much smoother.
//SDL_SetHint(SDL_HINT_RENDER_DRIVER, "direct3d12");
//SDL_SetHint(SDL_HINT_RENDER_DRIVER, "direct3d11");
//SDL_SetHint(SDL_HINT_RENDER_DRIVER, "direct3d");
SDL_CreateWindowAndRenderer("Rendering Speed", 640, 480, SDL_WINDOW_RESIZABLE, &window, &renderer);
SDL_SetRenderLogicalPresentation(renderer, 320, 240, SDL_LOGICAL_PRESENTATION_STRETCH);
CreateTestSurface();
while (active)
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
if (event.type == SDL_EVENT_QUIT)
{
active = false;
}
}
ticks = SDL_GetTicksNS();
Uint64 frameTicks = (ticks - lastTicks);
float deltaTime = (ticks - lastTicks) / (1000000000.0f);
lastTicks = ticks;
if (timer >= 0)
{
timer -= deltaTime;
}
else
{
fps = 1000000000.0 / frameTicks;
timer = duration;
}
theRect.x += deltaTime * 60;
if (theRect.x > 320)
theRect.x = -32;
Render();
}
return 0;
}
void Render()
{
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
SDL_FRect bgrect = { 0, 0, 320, 240 };
for (int i = 0; i < amountOfTexturesRendered; i++)
{
SDL_RenderTexture(renderer, surfaceTex, NULL, &bgrect);
}
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
SDL_RenderFillRect(renderer, &theRect);
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderDebugTextFormat(renderer, 32, 32 + (12 * 1), "FPS: %i", fps);
SDL_RenderPresent(renderer);
}
void CreateTestSurface()
{
SDL_Surface* surface = SDL_CreateSurface(1920, 1080, SDL_PIXELFORMAT_ABGR8888);
Uint32* pixels = (Uint32*)surface->pixels;
int pixelCount = surface->w * surface->h;
for (int i = 0; i < pixelCount; i++)
{
if (i < (pixelCount / 2))
{
pixels[i] = 0xFF000000;
}
else
{
pixels[i] = 0xFF205020;
}
}
surfaceTex = SDL_CreateTextureFromSurface(renderer, surface);
SDL_DestroySurface(surface);
}

Metadata
Metadata
Assignees
Labels
No labels