From 2ae9d6f6830bcb8059015bb6207691a6f1503c84 Mon Sep 17 00:00:00 2001 From: jpark37 Date: Thu, 5 Sep 2019 22:01:50 -0700 Subject: [PATCH 1/3] libobs-opengl: Support BGRA swap chains on Windows --- libobs-opengl/gl-windows.c | 1 + libobs-opengl/gl-x11.c | 47 -------------------------------------- 2 files changed, 1 insertion(+), 47 deletions(-) diff --git a/libobs-opengl/gl-windows.c b/libobs-opengl/gl-windows.c index 3b2e9cd1b..fd0ca6845 100644 --- a/libobs-opengl/gl-windows.c +++ b/libobs-opengl/gl-windows.c @@ -41,6 +41,7 @@ static inline int get_color_format_bits(enum gs_color_format format) { switch ((uint32_t)format) { case GS_RGBA: + case GS_BGRA: return 32; default: return 0; diff --git a/libobs-opengl/gl-x11.c b/libobs-opengl/gl-x11.c index ae35be9a9..ea06f51f0 100644 --- a/libobs-opengl/gl-x11.c +++ b/libobs-opengl/gl-x11.c @@ -95,53 +95,6 @@ struct gl_platform { GLXPbuffer pbuffer; }; -static void print_info_stuff(const struct gs_init_data *info) -{ - blog(LOG_INFO, - "X and Y: %i %i\n" - "Backbuffers: %i\n" - "Color Format: %i\n" - "ZStencil Format: %i\n" - "Adapter: %i\n", - info->cx, info->cy, info->num_backbuffers, info->format, - info->zsformat, info->adapter); -} -/* The following utility functions are copied verbatim from WGL code. - * GLX and WGL are more similar than most people realize. */ - -/* For now, only support basic 32bit formats for graphics output. */ -static inline int get_color_format_bits(enum gs_color_format format) -{ - switch ((uint32_t)format) { - case GS_RGBA: - return 32; - default: - return 0; - } -} - -static inline int get_depth_format_bits(enum gs_zstencil_format zsformat) -{ - switch ((uint32_t)zsformat) { - case GS_Z16: - return 16; - case GS_Z24_S8: - return 24; - default: - return 0; - } -} - -static inline int get_stencil_format_bits(enum gs_zstencil_format zsformat) -{ - switch ((uint32_t)zsformat) { - case GS_Z24_S8: - return 8; - default: - return 0; - } -} - /* * Since we cannot take advantage of the asynchronous nature of xcb, * all of the helper functions are synchronous but thread-safe. From 4da73445c3b30ee0775168f122dc4902191d923a Mon Sep 17 00:00:00 2001 From: jpark37 Date: Thu, 5 Sep 2019 22:46:00 -0700 Subject: [PATCH 2/3] graphics: libobs-d3d11: Use DXGI_SWAP_EFFECT_FLIP_DISCARD on Windows 10 This is supposed to eliminate a copy by DWM with extra benefits for borderless fullsceen, which should help the fullscreen projector. --- libobs-d3d11/d3d11-subsystem.cpp | 46 +++++++++++++++++++++++++------- libobs/graphics/graphics.c | 3 --- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/libobs-d3d11/d3d11-subsystem.cpp b/libobs-d3d11/d3d11-subsystem.cpp index 1fd20a98c..1801b6fa7 100644 --- a/libobs-d3d11/d3d11-subsystem.cpp +++ b/libobs-d3d11/d3d11-subsystem.cpp @@ -70,18 +70,41 @@ gs_obj::~gs_obj() next->prev_next = prev_next; } -static inline void make_swap_desc(DXGI_SWAP_CHAIN_DESC &desc, - const gs_init_data *data) +static inline void make_swap_desc_common(DXGI_SWAP_CHAIN_DESC &desc, + const gs_init_data *data, + UINT num_backbuffers, + DXGI_SWAP_EFFECT effect) { memset(&desc, 0, sizeof(desc)); - desc.BufferCount = data->num_backbuffers; - desc.BufferDesc.Format = ConvertGSTextureFormat(data->format); desc.BufferDesc.Width = data->cx; desc.BufferDesc.Height = data->cy; - desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; - desc.OutputWindow = (HWND)data->window.hwnd; + desc.BufferDesc.Format = ConvertGSTextureFormat(data->format); desc.SampleDesc.Count = 1; + desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + desc.BufferCount = num_backbuffers; + desc.OutputWindow = (HWND)data->window.hwnd; desc.Windowed = true; + desc.SwapEffect = effect; +} + +static inline void make_swap_desc_win7(DXGI_SWAP_CHAIN_DESC &desc, + const gs_init_data *data) +{ + UINT num_backbuffers = data->num_backbuffers; + if (num_backbuffers == 0) + num_backbuffers = 1; + make_swap_desc_common(desc, data, num_backbuffers, + DXGI_SWAP_EFFECT_DISCARD); +} + +static inline void make_swap_desc_win10(DXGI_SWAP_CHAIN_DESC &desc, + const gs_init_data *data) +{ + UINT num_backbuffers = data->num_backbuffers; + if (num_backbuffers == 0) + num_backbuffers = 2; + make_swap_desc_common(desc, data, num_backbuffers, + DXGI_SWAP_EFFECT_FLIP_DISCARD); } void gs_swap_chain::InitTarget(uint32_t cx, uint32_t cy) @@ -166,11 +189,16 @@ gs_swap_chain::gs_swap_chain(gs_device *device, const gs_init_data *data) { HRESULT hr; - make_swap_desc(swapDesc, data); + make_swap_desc_win10(swapDesc, data); hr = device->factory->CreateSwapChain(device->device, &swapDesc, swap.Assign()); - if (FAILED(hr)) - throw HRError("Failed to create swap chain", hr); + if (FAILED(hr)) { + make_swap_desc_win7(swapDesc, data); + hr = device->factory->CreateSwapChain(device->device, &swapDesc, + swap.Assign()); + if (FAILED(hr)) + throw HRError("Failed to create swap chain", hr); + } /* Ignore Alt+Enter */ device->factory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER); diff --git a/libobs/graphics/graphics.c b/libobs/graphics/graphics.c index 9e77cc393..480a570c8 100644 --- a/libobs/graphics/graphics.c +++ b/libobs/graphics/graphics.c @@ -1272,9 +1272,6 @@ gs_swapchain_t *gs_swapchain_create(const struct gs_init_data *data) if (!gs_valid_p("gs_swapchain_create", data)) return NULL; - if (new_data.num_backbuffers == 0) - new_data.num_backbuffers = 1; - return graphics->exports.device_swapchain_create(graphics->device, &new_data); } From a1f1e1080edc84cb5d5464c7fddac945c0b32050 Mon Sep 17 00:00:00 2001 From: jpark37 Date: Thu, 5 Sep 2019 22:47:20 -0700 Subject: [PATCH 3/3] UI: Switch from RGBA to BGRA swap chain format DirectX team member claims BGRA might have flip optimization benefits. --- UI/qt-display.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UI/qt-display.cpp b/UI/qt-display.cpp index 988068a6d..1bb97c7ba 100644 --- a/UI/qt-display.cpp +++ b/UI/qt-display.cpp @@ -86,7 +86,7 @@ void OBSQTDisplay::CreateDisplay() gs_init_data info = {}; info.cx = size.width(); info.cy = size.height(); - info.format = GS_RGBA; + info.format = GS_BGRA; info.zsformat = GS_ZS_NONE; QTToGSWindow(winId(), info.window);