From 75a288b32d3c6b68d87f1daa74399e2a379e248f Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Sun, 1 Oct 2023 15:48:15 -0700 Subject: [PATCH 1/2] Add support for using WARP software rasterizer with the D3D11 backend by setting FNA3D_D3D11_USE_WARP=1 --- src/FNA3D_Driver_D3D11.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/FNA3D_Driver_D3D11.c b/src/FNA3D_Driver_D3D11.c index 11707f26..6efdc6f1 100644 --- a/src/FNA3D_Driver_D3D11.c +++ b/src/FNA3D_Driver_D3D11.c @@ -4848,6 +4848,11 @@ static uint8_t D3D11_PrepareWindowAttributes(uint32_t *flags) }; HRESULT res; + const char* useWarp = SDL_GetHint("FNA3D_D3D11_USE_WARP"); + const uint32_t driverType = (useWarp == NULL) || (SDL_strcmp(useWarp, "1") != 0) + ? D3D_DRIVER_TYPE_HARDWARE + : D3D_DRIVER_TYPE_WARP; + #ifdef FNA3D_DXVK_NATIVE const char *forceDriver = SDL_GetHint("FNA3D_FORCE_DRIVER"); if ((forceDriver == NULL) || (SDL_strcmp(forceDriver, "D3D11") != 0)) @@ -4885,7 +4890,7 @@ static uint8_t D3D11_PrepareWindowAttributes(uint32_t *flags) res = D3D11CreateDeviceFunc( NULL, - D3D_DRIVER_TYPE_HARDWARE, + driverType, NULL, D3D11_CREATE_DEVICE_BGRA_SUPPORT, levels, @@ -4901,7 +4906,7 @@ static uint8_t D3D11_PrepareWindowAttributes(uint32_t *flags) FNA3D_LogWarn("Creating device with feature level 11_1 failed. Lowering feature level.", res); res = D3D11CreateDeviceFunc( NULL, - D3D_DRIVER_TYPE_HARDWARE, + driverType, NULL, D3D11_CREATE_DEVICE_BGRA_SUPPORT, &levels[1], @@ -5110,6 +5115,11 @@ static FNA3D_Device* D3D11_CreateDevice( int32_t i; HRESULT res; + const char* useWarp = SDL_GetHint("FNA3D_D3D11_USE_WARP"); + const uint32_t driverType = (useWarp == NULL) || (SDL_strcmp(useWarp, "1") != 0) + ? D3D_DRIVER_TYPE_UNKNOWN /* Must be UNKNOWN if adapter is non-null according to spec */ + : D3D_DRIVER_TYPE_WARP; + /* Allocate and zero out the renderer */ renderer = (D3D11Renderer*) SDL_malloc(sizeof(D3D11Renderer)); SDL_memset(renderer, '\0', sizeof(D3D11Renderer)); @@ -5177,8 +5187,8 @@ static FNA3D_Device* D3D11_CreateDevice( for (i = 0; i < 2; i += 1) { res = D3D11CreateDeviceFunc( - (IDXGIAdapter*) renderer->adapter, - D3D_DRIVER_TYPE_UNKNOWN, /* Must be UNKNOWN if adapter is non-null according to spec */ + driverType == D3D_DRIVER_TYPE_WARP ? NULL : (IDXGIAdapter*) renderer->adapter, + driverType, NULL, flags, &levels[i], From 37ec1d96c097317be82e8b0a42134e0fe2278fc5 Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Sun, 1 Oct 2023 16:25:31 -0700 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Ethan Lee --- src/FNA3D_Driver_D3D11.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/FNA3D_Driver_D3D11.c b/src/FNA3D_Driver_D3D11.c index 6efdc6f1..df61e27b 100644 --- a/src/FNA3D_Driver_D3D11.c +++ b/src/FNA3D_Driver_D3D11.c @@ -4848,8 +4848,7 @@ static uint8_t D3D11_PrepareWindowAttributes(uint32_t *flags) }; HRESULT res; - const char* useWarp = SDL_GetHint("FNA3D_D3D11_USE_WARP"); - const uint32_t driverType = (useWarp == NULL) || (SDL_strcmp(useWarp, "1") != 0) + const uint32_t driverType = SDL_GetHintBoolean("FNA3D_D3D11_USE_WARP", SDL_FALSE) ? D3D_DRIVER_TYPE_HARDWARE : D3D_DRIVER_TYPE_WARP; @@ -5115,8 +5114,7 @@ static FNA3D_Device* D3D11_CreateDevice( int32_t i; HRESULT res; - const char* useWarp = SDL_GetHint("FNA3D_D3D11_USE_WARP"); - const uint32_t driverType = (useWarp == NULL) || (SDL_strcmp(useWarp, "1") != 0) + const uint32_t driverType = SDL_GetHintBoolean("FNA3D_D3D11_USE_WARP", SDL_FALSE) ? D3D_DRIVER_TYPE_UNKNOWN /* Must be UNKNOWN if adapter is non-null according to spec */ : D3D_DRIVER_TYPE_WARP; @@ -5187,7 +5185,7 @@ static FNA3D_Device* D3D11_CreateDevice( for (i = 0; i < 2; i += 1) { res = D3D11CreateDeviceFunc( - driverType == D3D_DRIVER_TYPE_WARP ? NULL : (IDXGIAdapter*) renderer->adapter, + (driverType == D3D_DRIVER_TYPE_WARP) ? NULL : (IDXGIAdapter*) renderer->adapter, driverType, NULL, flags,