From: Brendan Shanks Subject: [PATCH] d2d1: Make ShaderResourceView optional when creating bitmap. Message-Id: <20190923153939.24951-1-bshanks@codeweavers.com> Date: Mon, 23 Sep 2019 08:39:39 -0700 Fixes Rockstar Games Launcher when using DXVK. Original patch by Robin Kertels Signed-off-by: Brendan Shanks --- dlls/d2d1/bitmap.c | 67 +++++++++++++----------------------- dlls/d2d1/d2d1_private.h | 1 + dlls/d2d1/dc_render_target.c | 5 +-- 3 files changed, 26 insertions(+), 47 deletions(-) diff --git a/dlls/d2d1/bitmap.c b/dlls/d2d1/bitmap.c index 39e81192f7..b24e9e4cc7 100644 --- a/dlls/d2d1/bitmap.c +++ b/dlls/d2d1/bitmap.c @@ -66,11 +66,13 @@ static ULONG STDMETHODCALLTYPE d2d_bitmap_Release(ID2D1Bitmap1 *iface) if (!refcount) { - ID3D10ShaderResourceView_Release(bitmap->view); if (bitmap->rtv) ID3D10RenderTargetView_Release(bitmap->rtv); if (bitmap->surface) IDXGISurface_Release(bitmap->surface); + if (bitmap->view) + ID3D10ShaderResourceView_Release(bitmap->view); + ID3D10Resource_Release(bitmap->texture); ID2D1Factory_Release(bitmap->factory); heap_free(bitmap); } @@ -149,7 +151,6 @@ static HRESULT STDMETHODCALLTYPE d2d_bitmap_CopyFromMemory(ID2D1Bitmap1 *iface, { struct d2d_bitmap *bitmap = impl_from_ID2D1Bitmap1(iface); ID3D10Device *device; - ID3D10Resource *dst; D3D10_BOX box; TRACE("iface %p, dst_rect %p, src_data %p, pitch %u.\n", iface, dst_rect, src_data, pitch); @@ -164,11 +165,9 @@ static HRESULT STDMETHODCALLTYPE d2d_bitmap_CopyFromMemory(ID2D1Bitmap1 *iface, box.back = 1; } - ID3D10ShaderResourceView_GetResource(bitmap->view, &dst); - ID3D10ShaderResourceView_GetDevice(bitmap->view, &device); - ID3D10Device_UpdateSubresource(device, dst, 0, dst_rect ? &box : NULL, src_data, pitch, 0); + ID3D10Resource_GetDevice(bitmap->texture, &device); + ID3D10Device_UpdateSubresource(device, bitmap->texture, 0, dst_rect ? &box : NULL, src_data, pitch, 0); ID3D10Device_Release(device); - ID3D10Resource_Release(dst); return S_OK; } @@ -271,36 +270,37 @@ static BOOL format_supported(const D2D1_PIXEL_FORMAT *format) } static void d2d_bitmap_init(struct d2d_bitmap *bitmap, struct d2d_device_context *context, - ID3D10ShaderResourceView *view, D2D1_SIZE_U size, const D2D1_BITMAP_PROPERTIES1 *desc) + ID3D10Resource *texture, D2D1_SIZE_U size, const D2D1_BITMAP_PROPERTIES1 *desc) { - ID3D10Resource *resource; ID3D10Device *d3d_device; HRESULT hr; bitmap->ID2D1Bitmap1_iface.lpVtbl = &d2d_bitmap_vtbl; bitmap->refcount = 1; ID2D1Factory_AddRef(bitmap->factory = context->factory); - ID3D10ShaderResourceView_AddRef(bitmap->view = view); + ID3D10Resource_AddRef(bitmap->texture = texture); bitmap->pixel_size = size; bitmap->format = desc->pixelFormat; bitmap->dpi_x = desc->dpiX; bitmap->dpi_y = desc->dpiY; bitmap->options = desc->bitmapOptions; - ID3D10ShaderResourceView_GetResource(bitmap->view, &resource); - if (d2d_device_context_is_dxgi_target(context)) - ID3D10Resource_QueryInterface(resource, &IID_IDXGISurface, (void **)&bitmap->surface); + ID3D10Resource_QueryInterface(texture, &IID_IDXGISurface, (void **)&bitmap->surface); + ID3D10Resource_GetDevice(texture, &d3d_device); if (bitmap->options & D2D1_BITMAP_OPTIONS_TARGET) { - ID3D10Resource_GetDevice(resource, &d3d_device); - if (FAILED(hr = ID3D10Device_CreateRenderTargetView(d3d_device, resource, NULL, &bitmap->rtv))) + if (FAILED(hr = ID3D10Device_CreateRenderTargetView(d3d_device, texture, NULL, &bitmap->rtv))) WARN("Failed to create rtv, hr %#x.\n", hr); - ID3D10Device_Release(d3d_device); } - ID3D10Resource_Release(resource); + if (!(bitmap->options & D2D1_BITMAP_OPTIONS_CANNOT_DRAW)) + { + if (FAILED(hr = ID3D10Device_CreateShaderResourceView(d3d_device, texture, NULL, &bitmap->view))) + WARN("Failed to create view, hr %#x.\n", hr); + } + ID3D10Device_Release(d3d_device); if (bitmap->dpi_x == 0.0f && bitmap->dpi_y == 0.0f) { @@ -314,7 +314,6 @@ HRESULT d2d_bitmap_create(struct d2d_device_context *context, D2D1_SIZE_U size, { D3D10_SUBRESOURCE_DATA resource_data; D3D10_TEXTURE2D_DESC texture_desc; - ID3D10ShaderResourceView *view; ID3D10Texture2D *texture; HRESULT hr; @@ -355,21 +354,12 @@ HRESULT d2d_bitmap_create(struct d2d_device_context *context, D2D1_SIZE_U size, return hr; } - hr = ID3D10Device_CreateShaderResourceView(context->d3d_device, (ID3D10Resource *)texture, NULL, &view); - ID3D10Texture2D_Release(texture); - if (FAILED(hr)) - { - ERR("Failed to create view, hr %#x.\n", hr); - return hr; - } - if ((*bitmap = heap_alloc_zero(sizeof(**bitmap)))) { - d2d_bitmap_init(*bitmap, context, view, size, desc); + d2d_bitmap_init(*bitmap, context, (ID3D10Resource *)texture, size, desc); TRACE("Created bitmap %p.\n", *bitmap); } - - ID3D10ShaderResourceView_Release(view); + ID3D10Texture2D_Release(texture); return *bitmap ? S_OK : E_OUTOFMEMORY; } @@ -391,7 +381,7 @@ HRESULT d2d_bitmap_create_shared(struct d2d_device_context *context, REFIID iid, goto failed; } - ID3D10ShaderResourceView_GetDevice(src_impl->view, &device); + ID3D10Resource_GetDevice(src_impl->texture, &device); ID3D10Device_Release(device); if (device != context->d3d_device) { @@ -423,7 +413,7 @@ HRESULT d2d_bitmap_create_shared(struct d2d_device_context *context, REFIID iid, goto failed; } - d2d_bitmap_init(*bitmap, context, src_impl->view, src_impl->pixel_size, desc); + d2d_bitmap_init(*bitmap, context, src_impl->texture, src_impl->pixel_size, desc); TRACE("Created bitmap %p.\n", *bitmap); failed: @@ -432,7 +422,6 @@ HRESULT d2d_bitmap_create_shared(struct d2d_device_context *context, REFIID iid, if (IsEqualGUID(iid, &IID_IDXGISurface) || IsEqualGUID(iid, &IID_IDXGISurface1)) { - ID3D10ShaderResourceView *view; DXGI_SURFACE_DESC surface_desc; IDXGISurface *surface = data; ID3D10Resource *resource; @@ -454,17 +443,9 @@ HRESULT d2d_bitmap_create_shared(struct d2d_device_context *context, REFIID iid, return D2DERR_UNSUPPORTED_OPERATION; } - hr = ID3D10Device_CreateShaderResourceView(context->d3d_device, resource, NULL, &view); - ID3D10Resource_Release(resource); - if (FAILED(hr)) - { - WARN("Failed to create shader resource view, hr %#x.\n", hr); - return hr; - } - if (!(*bitmap = heap_alloc_zero(sizeof(**bitmap)))) { - ID3D10ShaderResourceView_Release(view); + ID3D10Resource_Release(resource); return E_OUTOFMEMORY; } @@ -472,7 +453,7 @@ HRESULT d2d_bitmap_create_shared(struct d2d_device_context *context, REFIID iid, if (FAILED(hr = IDXGISurface_GetDesc(surface, &surface_desc))) { WARN("Failed to get surface desc, hr %#x.\n", hr); - ID3D10ShaderResourceView_Release(view); + ID3D10Resource_Release(resource); return hr; } @@ -499,8 +480,8 @@ HRESULT d2d_bitmap_create_shared(struct d2d_device_context *context, REFIID iid, pixel_size.width = surface_desc.Width; pixel_size.height = surface_desc.Height; - d2d_bitmap_init(*bitmap, context, view, pixel_size, &d); - ID3D10ShaderResourceView_Release(view); + d2d_bitmap_init(*bitmap, context, resource, pixel_size, &d); + ID3D10Resource_Release(resource); TRACE("Created bitmap %p.\n", *bitmap); return S_OK; diff --git a/dlls/d2d1/d2d1_private.h b/dlls/d2d1/d2d1_private.h index b07893ae18..e377a731f8 100644 --- a/dlls/d2d1/d2d1_private.h +++ b/dlls/d2d1/d2d1_private.h @@ -349,6 +349,7 @@ struct d2d_bitmap ID3D10ShaderResourceView *view; ID3D10RenderTargetView *rtv; IDXGISurface *surface; + ID3D10Resource *texture; D2D1_SIZE_U pixel_size; D2D1_PIXEL_FORMAT format; float dpi_x; diff --git a/dlls/d2d1/dc_render_target.c b/dlls/d2d1/dc_render_target.c index 310c541296..eb76bd1ac9 100644 --- a/dlls/d2d1/dc_render_target.c +++ b/dlls/d2d1/dc_render_target.c @@ -687,7 +687,6 @@ static HRESULT STDMETHODCALLTYPE d2d_dc_render_target_BindDC(ID2D1DCRenderTarget struct d2d_bitmap *bitmap_impl; IDXGISurface1 *dxgi_surface; ID2D1DeviceContext *context; - ID3D10Resource *resource; D2D1_SIZE_U bitmap_size; ID2D1Bitmap *bitmap; HRESULT hr; @@ -716,9 +715,7 @@ static HRESULT STDMETHODCALLTYPE d2d_dc_render_target_BindDC(ID2D1DCRenderTarget } bitmap_impl = unsafe_impl_from_ID2D1Bitmap(bitmap); - ID3D10ShaderResourceView_GetResource(bitmap_impl->view, &resource); - ID3D10Resource_QueryInterface(resource, &IID_IDXGISurface1, (void **)&dxgi_surface); - ID3D10Resource_Release(resource); + ID3D10Resource_QueryInterface(bitmap_impl->texture, &IID_IDXGISurface1, (void **)&dxgi_surface); ID2D1DeviceContext_SetTarget(context, (ID2D1Image *)bitmap); ID2D1Bitmap_Release(bitmap); -- 2.17.1