GPUDevice: Don't recreate device on SW switch in GLES:

This commit is contained in:
Stenzek 2023-09-23 13:40:51 +10:00
parent 2a5b3aa695
commit 9517638bcb
3 changed files with 14 additions and 6 deletions

View file

@ -1954,7 +1954,8 @@ bool System::CreateGPU(GPURenderer renderer, bool is_switching)
{ {
const RenderAPI api = Settings::GetRenderAPIForRenderer(renderer); const RenderAPI api = Settings::GetRenderAPIForRenderer(renderer);
if (!g_gpu_device || (renderer != GPURenderer::Software && g_gpu_device->GetRenderAPI() != api)) if (!g_gpu_device ||
(renderer != GPURenderer::Software && !GPUDevice::IsSameRenderAPI(g_gpu_device->GetRenderAPI(), api)))
{ {
if (g_gpu_device) if (g_gpu_device)
{ {

View file

@ -108,10 +108,9 @@ bool GPUPipeline::InputLayout::operator==(const InputLayout& rhs) const
bool GPUPipeline::InputLayout::operator!=(const InputLayout& rhs) const bool GPUPipeline::InputLayout::operator!=(const InputLayout& rhs) const
{ {
return (vertex_stride != rhs.vertex_stride || return (vertex_stride != rhs.vertex_stride || vertex_attributes.size() != rhs.vertex_attributes.size() ||
vertex_attributes.size() != rhs.vertex_attributes.size() || std::memcmp(vertex_attributes.data(), rhs.vertex_attributes.data(),
std::memcmp(vertex_attributes.data(), rhs.vertex_attributes.data(), sizeof(VertexAttribute) * rhs.vertex_attributes.size()) != 0);
sizeof(VertexAttribute) * rhs.vertex_attributes.size()) != 0);
} }
GPUPipeline::RasterizationState GPUPipeline::RasterizationState::GetNoCullState() GPUPipeline::RasterizationState GPUPipeline::RasterizationState::GetNoCullState()
@ -199,7 +198,6 @@ RenderAPI GPUDevice::GetPreferredAPI()
const char* GPUDevice::RenderAPIToString(RenderAPI api) const char* GPUDevice::RenderAPIToString(RenderAPI api)
{ {
// TODO: Combine ES
switch (api) switch (api)
{ {
// clang-format off // clang-format off
@ -218,6 +216,12 @@ const char* GPUDevice::RenderAPIToString(RenderAPI api)
} }
} }
bool GPUDevice::IsSameRenderAPI(RenderAPI lhs, RenderAPI rhs)
{
return (lhs == rhs || ((lhs == RenderAPI::OpenGL || lhs == RenderAPI::OpenGLES) &&
(rhs == RenderAPI::OpenGL || rhs == RenderAPI::OpenGLES)));
}
bool GPUDevice::Create(const std::string_view& adapter, const std::string_view& shader_cache_path, bool GPUDevice::Create(const std::string_view& adapter, const std::string_view& shader_cache_path,
u32 shader_cache_version, bool debug_device, bool vsync, bool threaded_presentation) u32 shader_cache_version, bool debug_device, bool vsync, bool threaded_presentation)
{ {

View file

@ -472,6 +472,9 @@ public:
/// Returns a new device for the specified API. /// Returns a new device for the specified API.
static std::unique_ptr<GPUDevice> CreateDeviceForAPI(RenderAPI api); static std::unique_ptr<GPUDevice> CreateDeviceForAPI(RenderAPI api);
/// Returns true if the render API is the same (e.g. GLES and GL).
static bool IsSameRenderAPI(RenderAPI lhs, RenderAPI rhs);
/// Parses a fullscreen mode into its components (width * height @ refresh hz) /// Parses a fullscreen mode into its components (width * height @ refresh hz)
static bool GetRequestedExclusiveFullscreenMode(u32* width, u32* height, float* refresh_rate); static bool GetRequestedExclusiveFullscreenMode(u32* width, u32* height, float* refresh_rate);