-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use DXGI #1
Comments
Function Call OrderIt is probably going to be useful to list the current and new order of operations including the prerequisites. Current Order
New Order
Thoughts
|
Make DXGI Output Shareable with OBSThis final item on the task list is going to tie together csharp-message-to-image-library, csharp-stream-controller, and obs-shm-image-source. In obs-shm-image-source I think I am going to want to get a handle to the DXGI surface*. In csharp-stream-controller I am going to be telling obs-shm-image-source to update the image. I think I am also going to want to relay the DXGI surface pointer to obs-shm-image-source. In obs-shm-image-source I am going to want to load the DXGI surface as a source and tell OBS when the source has changed. I will need a way of getting the handle to the DXGI surface. * In the above I say DXGI surface. I am assuming that is what I need, although I might need something else, such as the DXGI swap chain. My Relevant External Source CodeThis section includes source code from elsewhere and may be covered by different licences to this repository. Links to documentation and source files are included where possible. The majority of OBS Studio source code is licensed GPL version 2 or later. The inclusion of such source code and documentation here is also likely covered by fair use as I am commenting on it (commentary exception) in order to derive meaning (possible education exception), and am trying to derive meaning in order to inter-operate with it (technically the reverse engineering to provide interoperability exception doesn't apply as you don't need to reverse engineer open source code). OBS Graphics API FunctionThe following libobs API function in libobs/graphics/graphics.c is likely going to be called:
gs_texture_t *gs_texture_open_shared(uint32_t handle)
{
graphics_t *graphics = thread_graphics;
if (!gs_valid("gs_texture_open_shared"))
return NULL;
if (graphics->exports.device_texture_open_shared)
return graphics->exports.device_texture_open_shared(
graphics->device, handle);
return NULL;
}
OBS Internal FunctionThe above API function calls the internal function libobs-d3d11/d3d11-subsystem.hpp contains a definition of the function inside
As After a few searches, libobs-d3d11/d3d11-texture2d.cpp contains the function we're looking for: gs_texture_2d::gs_texture_2d(gs_device_t *device, uint32_t handle)
: gs_texture(device, gs_type::gs_texture_2d, GS_TEXTURE_2D),
isShared(true),
sharedHandle(handle)
{
HRESULT hr;
hr = device->device->OpenSharedResource((HANDLE)(uintptr_t)handle,
__uuidof(ID3D11Texture2D),
(void **)texture.Assign());
if (FAILED(hr))
throw HRError("Failed to open shared 2D texture", hr);
texture->GetDesc(&td);
this->type = GS_TEXTURE_2D;
this->format = ConvertDXGITextureFormat(td.Format);
this->levels = 1;
this->device = device;
this->width = td.Width;
this->height = td.Height;
this->dxgiFormat = td.Format;
memset(&resourceDesc, 0, sizeof(resourceDesc));
resourceDesc.Format = td.Format;
resourceDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
resourceDesc.Texture2D.MipLevels = 1;
hr = device->device->CreateShaderResourceView(texture, &resourceDesc,
shaderRes.Assign());
if (FAILED(hr))
throw HRError("Failed to create shader resource view", hr);
} This is where a difference in style is going to be useful. OBS Studio and libobs use snake_case whereas Direct3D (and a large amount of Microsoft code and APIs) use PascalCase. hr = device->device->OpenSharedResource((HANDLE)(uintptr_t)handle,
__uuidof(ID3D11Texture2D),
(void **)texture.Assign());
Microsoft's Win32 documentation has the syntax for ID3D11Device::OpenSharedResource method: HRESULT OpenSharedResource(
HANDLE hResource,
REFIID ReturnedInterface,
void **ppResource
);
I am not only using DXGI, DXGI is based on an OBS wants a After several hours of getting The next task is working out how to get my does-nothing OBS plugin to load a texture from shared memory and display it. Commit watfordjc/obs-shm-image-source@560a3fc combined with commit 6cefd97 added this functionality, but I still think the copying within the GPU is an unnecessary step that will need looking at again. |
Feature Branch
Current feature branch for this issue: feature/issue-1/d2d-1.
Progress
Background
The current version of the library uses Direct2D and WIC.
In order to interoperate with OBS efficiently, it seems like DXGI is the best option.
Based on Microsoft documentation and a bit of Googling, it looks like I need to insert or replace the functions called up to (and including)
CreateRenderTarget()
, possibly replacingCreateWICBitmap()
with something that creates a DXGI Surface.The text was updated successfully, but these errors were encountered: