Wine-devel
Threads by month
- ----- 2026 -----
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2003 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2002 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2001 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
December 2018
- 71 participants
- 407 discussions
17 Dec '18
From: Henri Verbeet <hverbeet(a)codeweavers.com>
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=45486
Signed-off-by: Matteo Bruni <mbruni(a)codeweavers.com>
---
dlls/d3d9/buffer.c | 24 ++++++++++++++--
dlls/d3d9/d3d9_private.h | 4 +++
dlls/d3d9/device.c | 60 ++++++++++++++++++++++++++++++++++++----
dlls/d3d9/stateblock.c | 17 ++++++++++++
4 files changed, 96 insertions(+), 9 deletions(-)
diff --git a/dlls/d3d9/buffer.c b/dlls/d3d9/buffer.c
index 02b3570402f..15b7e2bdbce 100644
--- a/dlls/d3d9/buffer.c
+++ b/dlls/d3d9/buffer.c
@@ -59,6 +59,8 @@ static ULONG WINAPI d3d9_vertexbuffer_AddRef(IDirect3DVertexBuffer9 *iface)
IDirect3DDevice9Ex_AddRef(buffer->parent_device);
wined3d_mutex_lock();
wined3d_buffer_incref(buffer->wined3d_buffer);
+ if (buffer->draw_buffer)
+ wined3d_buffer_incref(buffer->draw_buffer);
wined3d_mutex_unlock();
}
@@ -78,6 +80,8 @@ static ULONG WINAPI d3d9_vertexbuffer_Release(IDirect3DVertexBuffer9 *iface)
wined3d_mutex_lock();
wined3d_buffer_decref(buffer->wined3d_buffer);
+ if (buffer->draw_buffer)
+ wined3d_buffer_decref(buffer->draw_buffer);
wined3d_mutex_unlock();
/* Release the device last, as it may cause the device to be destroyed. */
@@ -274,6 +278,7 @@ static const struct wined3d_parent_ops d3d9_vertexbuffer_wined3d_parent_ops =
HRESULT vertexbuffer_init(struct d3d9_vertexbuffer *buffer, struct d3d9_device *device,
UINT size, UINT usage, DWORD fvf, D3DPOOL pool)
{
+ const struct wined3d_parent_ops *parent_ops = &d3d9_null_wined3d_parent_ops;
struct wined3d_buffer_desc desc;
HRESULT hr;
@@ -299,15 +304,28 @@ HRESULT vertexbuffer_init(struct d3d9_vertexbuffer *buffer, struct d3d9_device *
desc.byte_width = size;
desc.usage = usage & WINED3DUSAGE_MASK;
- desc.bind_flags = WINED3D_BIND_VERTEX_BUFFER;
+ desc.bind_flags = 0;
desc.access = wined3daccess_from_d3dpool(pool, usage)
| WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W;
desc.misc_flags = 0;
desc.structure_byte_stride = 0;
+ if (desc.access & WINED3D_RESOURCE_ACCESS_GPU)
+ {
+ desc.bind_flags = WINED3D_BIND_VERTEX_BUFFER;
+ parent_ops = &d3d9_vertexbuffer_wined3d_parent_ops;
+ }
+
wined3d_mutex_lock();
- hr = wined3d_buffer_create(device->wined3d_device, &desc, NULL, buffer,
- &d3d9_vertexbuffer_wined3d_parent_ops, &buffer->wined3d_buffer);
+ hr = wined3d_buffer_create(device->wined3d_device, &desc, NULL, buffer, parent_ops, &buffer->wined3d_buffer);
+ if (SUCCEEDED(hr) && !(desc.access & WINED3D_RESOURCE_ACCESS_GPU))
+ {
+ desc.bind_flags = WINED3D_BIND_VERTEX_BUFFER;
+ desc.access = WINED3D_RESOURCE_ACCESS_GPU;
+ if (FAILED(hr = wined3d_buffer_create(device->wined3d_device, &desc, NULL, buffer,
+ &d3d9_vertexbuffer_wined3d_parent_ops, &buffer->draw_buffer)))
+ wined3d_buffer_decref(buffer->wined3d_buffer);
+ }
wined3d_mutex_unlock();
if (FAILED(hr))
{
diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h
index d6155eba60b..8647aac4af1 100644
--- a/dlls/d3d9/d3d9_private.h
+++ b/dlls/d3d9/d3d9_private.h
@@ -42,6 +42,7 @@
#define D3D9_MAX_VERTEX_SHADER_CONSTANTF 256
#define D3D9_MAX_TEXTURE_UNITS 20
+#define D3D9_MAX_STREAMS 16
#define D3DPRESENTFLAGS_MASK 0x00000fffu
@@ -105,6 +106,8 @@ struct d3d9_device
BOOL in_destruction;
BOOL in_scene;
BOOL has_vertex_declaration;
+ BOOL recording;
+ unsigned int upload_map;
unsigned int max_user_clip_planes;
@@ -181,6 +184,7 @@ struct d3d9_vertexbuffer
struct d3d9_resource resource;
struct wined3d_buffer *wined3d_buffer;
IDirect3DDevice9Ex *parent_device;
+ struct wined3d_buffer *draw_buffer;
DWORD fvf;
};
diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
index f19e2ae6f65..7c488bfd601 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -974,6 +974,7 @@ static HRESULT d3d9_device_reset(struct d3d9_device *device,
if (!extended)
{
+ device->recording = FALSE;
wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZENABLE,
!!swapchain_desc.enable_auto_depth_stencil);
}
@@ -2317,7 +2318,8 @@ static HRESULT WINAPI d3d9_device_BeginStateBlock(IDirect3DDevice9Ex *iface)
TRACE("iface %p.\n", iface);
wined3d_mutex_lock();
- hr = wined3d_device_begin_stateblock(device->wined3d_device);
+ if (SUCCEEDED(hr = wined3d_device_begin_stateblock(device->wined3d_device)))
+ device->recording = TRUE;
wined3d_mutex_unlock();
return hr;
@@ -2340,6 +2342,7 @@ static HRESULT WINAPI d3d9_device_EndStateBlock(IDirect3DDevice9Ex *iface, IDire
WARN("Failed to end the state block, hr %#x.\n", hr);
return hr;
}
+ device->recording = FALSE;
if (!(object = heap_alloc_zero(sizeof(*object))))
{
@@ -2688,10 +2691,38 @@ static void d3d9_generate_auto_mipmaps(struct d3d9_device *device)
}
}
+static void d3d9_device_upload_sysmem_buffers(struct d3d9_device *device,
+ unsigned int start_vertex, unsigned int vertex_count)
+{
+ struct wined3d_box box = {0, 0, 0, 1, 0, 1};
+ struct d3d9_vertexbuffer *d3d9_buffer;
+ unsigned int i, offset, stride, map;
+ struct wined3d_buffer *dst_buffer;
+ HRESULT hr;
+
+ map = device->upload_map;
+ while (map)
+ {
+ i = ffs(map) - 1;
+ map ^= 1u << i;
+
+ if (FAILED(hr = wined3d_device_get_stream_source(device->wined3d_device, i, &dst_buffer, &offset, &stride)))
+ ERR("Failed to get stream source.\n");
+ d3d9_buffer = wined3d_buffer_get_parent(dst_buffer);
+ box.left = offset + start_vertex * stride;
+ box.right = box.left + vertex_count * stride;
+ if (FAILED(hr = wined3d_device_copy_sub_resource_region(device->wined3d_device,
+ wined3d_buffer_get_resource(dst_buffer), 0, box.left, 0, 0,
+ wined3d_buffer_get_resource(d3d9_buffer->wined3d_buffer), 0, &box, 0)))
+ ERR("Failed to update buffer.\n");
+ }
+}
+
static HRESULT WINAPI d3d9_device_DrawPrimitive(IDirect3DDevice9Ex *iface,
D3DPRIMITIVETYPE primitive_type, UINT start_vertex, UINT primitive_count)
{
struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
+ unsigned int vertex_count;
HRESULT hr;
TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
@@ -2704,10 +2735,11 @@ static HRESULT WINAPI d3d9_device_DrawPrimitive(IDirect3DDevice9Ex *iface,
WARN("Called without a valid vertex declaration set.\n");
return D3DERR_INVALIDCALL;
}
+ vertex_count = vertex_count_from_primitive_count(primitive_type, primitive_count);
+ d3d9_device_upload_sysmem_buffers(device, start_vertex, vertex_count);
d3d9_generate_auto_mipmaps(device);
wined3d_device_set_primitive_type(device->wined3d_device, primitive_type, 0);
- hr = wined3d_device_draw_primitive(device->wined3d_device, start_vertex,
- vertex_count_from_primitive_count(primitive_type, primitive_count));
+ hr = wined3d_device_draw_primitive(device->wined3d_device, start_vertex, vertex_count);
if (SUCCEEDED(hr))
d3d9_rts_flag_auto_gen_mipmap(device);
wined3d_mutex_unlock();
@@ -2734,6 +2766,7 @@ static HRESULT WINAPI d3d9_device_DrawIndexedPrimitive(IDirect3DDevice9Ex *iface
WARN("Called without a valid vertex declaration set.\n");
return D3DERR_INVALIDCALL;
}
+ d3d9_device_upload_sysmem_buffers(device, min_vertex_idx, vertex_count);
d3d9_generate_auto_mipmaps(device);
wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_idx);
wined3d_device_set_primitive_type(device->wined3d_device, primitive_type, 0);
@@ -3378,6 +3411,7 @@ static HRESULT WINAPI d3d9_device_SetStreamSource(IDirect3DDevice9Ex *iface,
{
struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
struct d3d9_vertexbuffer *buffer_impl = unsafe_impl_from_IDirect3DVertexBuffer9(buffer);
+ struct wined3d_buffer *wined3d_buffer;
HRESULT hr;
TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
@@ -3386,14 +3420,28 @@ static HRESULT WINAPI d3d9_device_SetStreamSource(IDirect3DDevice9Ex *iface,
wined3d_mutex_lock();
if (!stride)
{
- struct wined3d_buffer *wined3d_buffer;
unsigned int cur_offset;
hr = wined3d_device_get_stream_source(device->wined3d_device, stream_idx, &wined3d_buffer,
&cur_offset, &stride);
}
- hr = wined3d_device_set_stream_source(device->wined3d_device, stream_idx,
- buffer_impl ? buffer_impl->wined3d_buffer : NULL, offset, stride);
+
+ if (!buffer_impl)
+ wined3d_buffer = NULL;
+ else if (buffer_impl->draw_buffer)
+ wined3d_buffer = buffer_impl->draw_buffer;
+ else
+ wined3d_buffer = buffer_impl->wined3d_buffer;
+
+ hr = wined3d_device_set_stream_source(device->wined3d_device, stream_idx, wined3d_buffer, offset, stride);
+ if (SUCCEEDED(hr) && !device->recording)
+ {
+ if (buffer_impl && buffer_impl->draw_buffer)
+ device->upload_map |= (1u << stream_idx);
+ else
+ device->upload_map &= ~(1u << stream_idx);
+ }
+
wined3d_mutex_unlock();
return hr;
diff --git a/dlls/d3d9/stateblock.c b/dlls/d3d9/stateblock.c
index 62b3bacb28d..c5306fd80b3 100644
--- a/dlls/d3d9/stateblock.c
+++ b/dlls/d3d9/stateblock.c
@@ -108,11 +108,28 @@ static HRESULT WINAPI d3d9_stateblock_Capture(IDirect3DStateBlock9 *iface)
static HRESULT WINAPI d3d9_stateblock_Apply(IDirect3DStateBlock9 *iface)
{
struct d3d9_stateblock *stateblock = impl_from_IDirect3DStateBlock9(iface);
+ struct wined3d_buffer *wined3d_buffer;
+ struct d3d9_vertexbuffer *buffer;
+ unsigned int i, offset, stride;
+ struct d3d9_device *device;
+ HRESULT hr;
TRACE("iface %p.\n", iface);
wined3d_mutex_lock();
wined3d_stateblock_apply(stateblock->wined3d_stateblock);
+ device = impl_from_IDirect3DDevice9Ex(stateblock->parent_device);
+ device->upload_map = 0;
+ for (i = 0; i < D3D9_MAX_STREAMS; ++i)
+ {
+ if (FAILED(hr = wined3d_device_get_stream_source(device->wined3d_device,
+ i, &wined3d_buffer, &offset, &stride)))
+ continue;
+ if (!wined3d_buffer || !(buffer = wined3d_buffer_get_parent(wined3d_buffer)))
+ continue;
+ if (buffer->draw_buffer)
+ device->upload_map |= 1u << i;
+ }
wined3d_mutex_unlock();
return D3D_OK;
--
2.18.1
6
17
17 Dec '18
Signed-off-by: Zebediah Figura <z.figura12(a)gmail.com>
---
dlls/devenum/tests/devenum.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/dlls/devenum/tests/devenum.c b/dlls/devenum/tests/devenum.c
index 10ca27a614..e31f65c653 100644
--- a/dlls/devenum/tests/devenum.c
+++ b/dlls/devenum/tests/devenum.c
@@ -95,6 +95,7 @@ static void test_devenum(IBindCtx *bind_ctx)
if (winetest_debug > 1)
trace("%s %s:\n", wine_dbgstr_guid(&cat_guid), wine_dbgstr_w(V_BSTR(&var)));
+ VariantClear(&var);
IPropertyBag_Release(prop_bag);
IMoniker_Release(moniker);
@@ -688,6 +689,7 @@ static BOOL CALLBACK test_dsound(GUID *guid, const WCHAR *desc, const WCHAR *mod
ok(!lstrcmpW(buffer, V_BSTR(&var)), "expected %s, got %s\n",
wine_dbgstr_w(buffer), wine_dbgstr_w(V_BSTR(&var)));
+ VariantClear(&var);
IPropertyBag_Release(prop_bag);
IMoniker_Release(mon);
IParseDisplayName_Release(parser);
--
2.19.2
1
0
[PATCH vkd3d 2/2] vkd3d-shader: Implement DXBC checksum for root signatures.
by Józef Kucia 17 Dec '18
by Józef Kucia 17 Dec '18
17 Dec '18
From: Józef Kucia <jkucia(a)codeweavers.com>
Signed-off-by: Józef Kucia <jkucia(a)codeweavers.com>
---
MD5 code assumes that sizeof(unsigned int) == 4.
---
libs/vkd3d-shader/checksum.c | 73 ++++++++++++++++--------
libs/vkd3d-shader/dxbc.c | 6 +-
libs/vkd3d-shader/vkd3d_shader_private.h | 6 +-
tests/d3d12.c | 7 +--
4 files changed, 56 insertions(+), 36 deletions(-)
diff --git a/libs/vkd3d-shader/checksum.c b/libs/vkd3d-shader/checksum.c
index d2929da92635..b9a7140221e0 100644
--- a/libs/vkd3d-shader/checksum.c
+++ b/libs/vkd3d-shader/checksum.c
@@ -35,11 +35,15 @@
#include "vkd3d_shader_private.h"
+#define DXBC_CHECKSUM_BLOCK_SIZE 64
+
+STATIC_ASSERT(sizeof(unsigned int) == 4);
+
struct md5_ctx
{
unsigned int i[2];
unsigned int buf[4];
- unsigned char in[64];
+ unsigned char in[DXBC_CHECKSUM_BLOCK_SIZE];
unsigned char digest[16];
};
@@ -163,7 +167,7 @@ static void byte_reverse(unsigned char *buf, unsigned longs)
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
* initialization constants.
*/
-void md5_init(struct md5_ctx *ctx)
+static void md5_init(struct md5_ctx *ctx)
{
ctx->buf[0] = 0x67452301;
ctx->buf[1] = 0xefcdab89;
@@ -177,7 +181,7 @@ void md5_init(struct md5_ctx *ctx)
* Update context to reflect the concatenation of another buffer full
* of bytes.
*/
-void md5_update(struct md5_ctx *ctx, const unsigned char *buf, unsigned int len)
+static void md5_update(struct md5_ctx *ctx, const unsigned char *buf, unsigned int len)
{
unsigned int t;
@@ -194,7 +198,7 @@ void md5_update(struct md5_ctx *ctx, const unsigned char *buf, unsigned int len)
if (t)
{
unsigned char *p = (unsigned char *)ctx->in + t;
- t = 64 - t;
+ t = DXBC_CHECKSUM_BLOCK_SIZE - t;
if (len < t)
{
@@ -212,27 +216,25 @@ void md5_update(struct md5_ctx *ctx, const unsigned char *buf, unsigned int len)
}
/* Process data in 64-byte chunks */
- while (len >= 64)
+ while (len >= DXBC_CHECKSUM_BLOCK_SIZE)
{
- memcpy(ctx->in, buf, 64);
+ memcpy(ctx->in, buf, DXBC_CHECKSUM_BLOCK_SIZE);
byte_reverse(ctx->in, 16);
md5_transform(ctx->buf, (unsigned int *)ctx->in);
- buf += 64;
- len -= 64;
+ buf += DXBC_CHECKSUM_BLOCK_SIZE;
+ len -= DXBC_CHECKSUM_BLOCK_SIZE;
}
/* Handle any remaining bytes of data. */
memcpy(ctx->in, buf, len);
}
-/*
- * Final wrapup - pad to 64-byte boundary with the bit pattern
- * 1 0* (64-bit count of bits processed, MSB-first)
- */
-void md5_final(struct md5_ctx *ctx)
+static void dxbc_checksum_final(struct md5_ctx *ctx)
{
+ unsigned int padding;
+ unsigned int length;
unsigned int count;
unsigned char *p;
@@ -243,34 +245,57 @@ void md5_final(struct md5_ctx *ctx)
always at least one byte free */
p = ctx->in + count;
*p++ = 0x80;
+ ++count;
/* Bytes of padding needed to make 64 bytes */
- count = 64 - 1 - count;
+ padding = DXBC_CHECKSUM_BLOCK_SIZE - count;
/* Pad out to 56 mod 64 */
- if (count < 8)
+ if (padding < 8)
{
/* Two lots of padding: Pad the first block to 64 bytes */
- memset(p, 0, count);
+ memset(p, 0, padding);
byte_reverse(ctx->in, 16);
md5_transform(ctx->buf, (unsigned int *)ctx->in);
- /* Now fill the next block with 56 bytes */
- memset(ctx->in, 0, 56);
+ /* Now fill the next block */
+ memset(ctx->in, 0, DXBC_CHECKSUM_BLOCK_SIZE);
}
else
{
- /* Pad block to 56 bytes */
- memset(p, 0, count - 8);
- }
+ /* Make place for bitcount at the beginning of the block */
+ memmove(&ctx->in[4], ctx->in, count);
- byte_reverse(ctx->in, 14);
+ /* Pad block to 60 bytes */
+ memset(p + 4, 0, padding - 4);
+ }
/* Append length in bits and transform */
- ((unsigned int *)ctx->in)[14] = ctx->i[0];
- ((unsigned int *)ctx->in)[15] = ctx->i[1];
+ length = ctx->i[0];
+ memcpy(&ctx->in[0], &length, sizeof(length));
+ byte_reverse(&ctx->in[4], 14);
+ length = ctx->i[0] >> 2 | 0x1;
+ memcpy(&ctx->in[DXBC_CHECKSUM_BLOCK_SIZE - 4], &length, sizeof(length));
md5_transform(ctx->buf, (unsigned int *)ctx->in);
byte_reverse((unsigned char *)ctx->buf, 4);
memcpy(ctx->digest, ctx->buf, 16);
}
+
+#define DXBC_CHECKSUM_SKIP_BYTE_COUNT 20
+
+void vkd3d_compute_dxbc_checksum(const void *dxbc, size_t size, uint32_t checksum[4])
+{
+ const uint8_t *ptr = dxbc;
+ struct md5_ctx ctx;
+
+ assert(size > DXBC_CHECKSUM_SKIP_BYTE_COUNT);
+ ptr += DXBC_CHECKSUM_SKIP_BYTE_COUNT;
+ size -= DXBC_CHECKSUM_SKIP_BYTE_COUNT;
+
+ md5_init(&ctx);
+ md5_update(&ctx, ptr, size);
+ dxbc_checksum_final(&ctx);
+
+ memcpy(checksum, ctx.digest, sizeof(ctx.digest));
+}
diff --git a/libs/vkd3d-shader/dxbc.c b/libs/vkd3d-shader/dxbc.c
index b199749064f5..4b36ea644b84 100644
--- a/libs/vkd3d-shader/dxbc.c
+++ b/libs/vkd3d-shader/dxbc.c
@@ -2389,7 +2389,7 @@ static int shader_write_root_signature_header(struct root_signature_writer_conte
if (!write_dword(context, TAG_DXBC))
return VKD3D_ERROR_OUT_OF_MEMORY;
- WARN("DXBC checksum is not implemented.\n");
+ /* The checksum is computed when all data is generated. */
if (!write_dwords(context, 4, 0x00000000))
return VKD3D_ERROR_OUT_OF_MEMORY;
@@ -2596,6 +2596,7 @@ int vkd3d_shader_serialize_root_signature(const struct vkd3d_root_signature_desc
{
struct root_signature_writer_context context;
size_t total_size, chunk_size;
+ uint32_t checksum[4];
int ret;
TRACE("root_signature %p, version %#x, dxbc %p.\n", root_signature, version, dxbc);
@@ -2628,5 +2629,8 @@ int vkd3d_shader_serialize_root_signature(const struct vkd3d_root_signature_desc
dxbc->code = context.data;
dxbc->size = total_size;
+ vkd3d_compute_dxbc_checksum(dxbc->code, dxbc->size, checksum);
+ memcpy((uint32_t *)dxbc->code + 1, checksum, sizeof(checksum));
+
return VKD3D_OK;
}
diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h
index e0fad6852e53..bf2f45571375 100644
--- a/libs/vkd3d-shader/vkd3d_shader_private.h
+++ b/libs/vkd3d-shader/vkd3d_shader_private.h
@@ -815,11 +815,7 @@ int vkd3d_dxbc_compiler_generate_spirv(struct vkd3d_dxbc_compiler *compiler,
struct vkd3d_shader_code *spirv) DECLSPEC_HIDDEN;
void vkd3d_dxbc_compiler_destroy(struct vkd3d_dxbc_compiler *compiler) DECLSPEC_HIDDEN;
-struct md5_ctx;
-
-void md5_init(struct md5_ctx *ctx) DECLSPEC_HIDDEN;
-void md5_update(struct md5_ctx *ctx, const unsigned char *buf, unsigned int len) DECLSPEC_HIDDEN;
-void md5_final(struct md5_ctx *ctx) DECLSPEC_HIDDEN;
+void vkd3d_compute_dxbc_checksum(const void *dxbc, size_t size, uint32_t checksum[4]) DECLSPEC_HIDDEN;
static inline enum vkd3d_component_type vkd3d_component_type_from_data_type(
enum vkd3d_data_type data_type)
diff --git a/tests/d3d12.c b/tests/d3d12.c
index 7d67de2966dd..3ba2ce9fbb8f 100644
--- a/tests/d3d12.c
+++ b/tests/d3d12.c
@@ -9109,12 +9109,7 @@ static void test_root_signature_serialization_(unsigned int line, const DWORD *c
ok_(line)(blob_buffer[0] == code[0], "Got magic %#x, expected %#x.\n",
(unsigned int)blob_buffer[0], (unsigned int)code[0]);
- for (i = 1; i < 5; ++i)
- {
- todo ok_(line)(blob_buffer[i] == code[i], "Got checksum %#x, expected %#x at %u.\n",
- (unsigned int)blob_buffer[i], (unsigned int)code[i], i - 1);
- }
- for (; i < code_size / sizeof(DWORD); ++i)
+ for (i = 0; i < code_size / sizeof(DWORD); ++i)
{
ok_(line)(blob_buffer[i] == code[i], "Got dword %#x, expected %#x at %u.\n",
(unsigned int)blob_buffer[i], (unsigned int)code[i], i);
--
2.19.2
2
1
[PATCH 5/5] ddraw: Support drawing from D3DVBCAPS_SYSTEMMEMORY vertex buffers.
by Henri Verbeet 17 Dec '18
by Henri Verbeet 17 Dec '18
17 Dec '18
From: Matteo Bruni <mbruni(a)codeweavers.com>
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=45279
Signed-off-by: Matteo Bruni <mbruni(a)codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
---
dlls/ddraw/device.c | 44 +++++++++++++++++++-
dlls/ddraw/tests/ddraw4.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++
dlls/ddraw/tests/ddraw7.c | 93 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 236 insertions(+), 1 deletion(-)
diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c
index 0d48c7d704e..48803f8f937 100644
--- a/dlls/ddraw/device.c
+++ b/dlls/ddraw/device.c
@@ -4275,8 +4275,11 @@ static HRESULT d3d_device7_DrawPrimitiveVB(IDirect3DDevice7 *iface, D3DPRIMITIVE
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
struct d3d_vertex_buffer *vb_impl = unsafe_impl_from_IDirect3DVertexBuffer7(vb);
- HRESULT hr;
+ struct wined3d_resource *wined3d_resource;
+ struct wined3d_map_desc wined3d_map_desc;
+ struct wined3d_box wined3d_box = {0};
DWORD stride;
+ HRESULT hr;
TRACE("iface %p, primitive_type %#x, vb %p, start_vertex %u, vertex_count %u, flags %#x.\n",
iface, primitive_type, vb, start_vertex, vertex_count, flags);
@@ -4289,6 +4292,26 @@ static HRESULT d3d_device7_DrawPrimitiveVB(IDirect3DDevice7 *iface, D3DPRIMITIVE
stride = get_flexible_vertex_size(vb_impl->fvf);
+ if (vb_impl->Caps & D3DVBCAPS_SYSTEMMEMORY)
+ {
+ TRACE("Drawing from D3DVBCAPS_SYSTEMMEMORY vertex buffer, forwarding to DrawPrimitive().\n");
+ wined3d_mutex_lock();
+ wined3d_resource = wined3d_buffer_get_resource(vb_impl->wined3d_buffer);
+ wined3d_box.left = start_vertex * stride;
+ wined3d_box.right = wined3d_box.left + vertex_count * stride;
+ if (FAILED(hr = wined3d_resource_map(wined3d_resource, 0, &wined3d_map_desc,
+ &wined3d_box, WINED3D_MAP_READ)))
+ {
+ wined3d_mutex_unlock();
+ return D3DERR_VERTEXBUFFERLOCKED;
+ }
+ hr = d3d_device7_DrawPrimitive(iface, primitive_type, vb_impl->fvf, wined3d_map_desc.data,
+ vertex_count, flags);
+ wined3d_resource_unmap(wined3d_resource, 0);
+ wined3d_mutex_unlock();
+ return hr;
+ }
+
wined3d_mutex_lock();
wined3d_device_set_vertex_declaration(device->wined3d_device, vb_impl->wined3d_declaration);
if (FAILED(hr = wined3d_device_set_stream_source(device->wined3d_device,
@@ -4366,6 +4389,7 @@ static HRESULT d3d_device7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface,
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
struct d3d_vertex_buffer *vb_impl = unsafe_impl_from_IDirect3DVertexBuffer7(vb);
DWORD stride = get_flexible_vertex_size(vb_impl->fvf);
+ struct wined3d_resource *wined3d_resource;
struct wined3d_map_desc wined3d_map_desc;
struct wined3d_box wined3d_box = {0};
struct wined3d_resource *ib;
@@ -4382,6 +4406,24 @@ static HRESULT d3d_device7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface,
return D3D_OK;
}
+ if (vb_impl->Caps & D3DVBCAPS_SYSTEMMEMORY)
+ {
+ TRACE("Drawing from D3DVBCAPS_SYSTEMMEMORY vertex buffer, forwarding to DrawIndexedPrimitive().\n");
+ wined3d_mutex_lock();
+ wined3d_resource = wined3d_buffer_get_resource(vb_impl->wined3d_buffer);
+ if (FAILED(hr = wined3d_resource_map(wined3d_resource, 0, &wined3d_map_desc,
+ &wined3d_box, WINED3D_MAP_READ)))
+ {
+ wined3d_mutex_unlock();
+ return D3DERR_VERTEXBUFFERLOCKED;
+ }
+ hr = d3d_device7_DrawIndexedPrimitive(iface, primitive_type, vb_impl->fvf, wined3d_map_desc.data,
+ start_vertex + vertex_count, indices, index_count, flags);
+ wined3d_resource_unmap(wined3d_resource, 0);
+ wined3d_mutex_unlock();
+ return hr;
+ }
+
/* Steps:
* 1) Upload the indices to the index buffer
* 2) Set the index source
diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c
index 443c78b6439..1c4841891e4 100644
--- a/dlls/ddraw/tests/ddraw4.c
+++ b/dlls/ddraw/tests/ddraw4.c
@@ -15373,6 +15373,105 @@ static void test_killfocus(void)
UnregisterClassA("ddraw_killfocus_wndproc_wc", GetModuleHandleA(NULL));
}
+static void test_sysmem_draw(void)
+{
+ D3DRECT rect_full = {{0}, {0}, {640}, {480}};
+ IDirect3DViewport3 *viewport;
+ D3DVERTEXBUFFERDESC vb_desc;
+ IDirect3DVertexBuffer *vb;
+ IDirect3DDevice3 *device;
+ IDirectDrawSurface4 *rt;
+ IDirect3D3 *d3d;
+ D3DCOLOR color;
+ ULONG refcount;
+ HWND window;
+ HRESULT hr;
+ BYTE *data;
+
+ static const struct
+ {
+ struct vec3 position;
+ DWORD diffuse;
+ }
+ quad[] =
+ {
+ {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
+ {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
+ {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
+ {{ 1.0f, 1.0f, 0.0f}, 0xffffffff},
+ };
+ static WORD indices[] = {0, 1, 2, 3};
+
+ window = create_window();
+ ok(!!window, "Failed to create a window.\n");
+
+ if (!(device = create_device(window, DDSCL_NORMAL)))
+ {
+ skip("Failed to create a 3D device, skipping test.\n");
+ DestroyWindow(window);
+ return;
+ }
+
+ hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+
+ viewport = create_viewport(device, 0, 0, 640, 480);
+ hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+
+ vb_desc.dwSize = sizeof(vb_desc);
+ vb_desc.dwCaps = D3DVBCAPS_SYSTEMMEMORY;
+ vb_desc.dwFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;
+ vb_desc.dwNumVertices = 4;
+ hr = IDirect3D3_CreateVertexBuffer(d3d, &vb_desc, &vb, 0, NULL);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DVertexBuffer_Lock(vb, 0, (void **)&data, NULL);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+ memcpy(data, quad, sizeof(quad));
+ hr = IDirect3DVertexBuffer_Unlock(vb);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DViewport3_Clear2(viewport, 1, &rect_full, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice3_BeginScene(device);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice3_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 4, 0);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice3_EndScene(device);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+
+ color = get_surface_color(rt, 320, 240);
+ ok(compare_color(color, 0x00007f7f, 1), "Got unexpected color 0x%08x.\n", color);
+
+ hr = IDirect3DViewport3_Clear2(viewport, 1, &rect_full, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice3_BeginScene(device);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice3_DrawIndexedPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, indices, 4, 0);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice3_EndScene(device);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+
+ color = get_surface_color(rt, 320, 240);
+ ok(compare_color(color, 0x00007f7f, 1), "Got unexpected color 0x%08x.\n", color);
+
+ IDirect3DVertexBuffer_Release(vb);
+ IDirect3DViewport3_Release(viewport);
+ IDirectDrawSurface4_Release(rt);
+ IDirect3D3_Release(d3d);
+ refcount = IDirect3DDevice3_Release(device);
+ ok(!refcount, "Device has %u references left.\n", refcount);
+ DestroyWindow(window);
+}
+
START_TEST(ddraw4)
{
DDDEVICEIDENTIFIER identifier;
@@ -15501,4 +15600,5 @@ START_TEST(ddraw4)
test_viewport();
test_find_device();
test_killfocus();
+ test_sysmem_draw();
}
diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c
index 05151b06510..9ab8644191f 100644
--- a/dlls/ddraw/tests/ddraw7.c
+++ b/dlls/ddraw/tests/ddraw7.c
@@ -15088,6 +15088,98 @@ static void test_killfocus(void)
UnregisterClassA("ddraw_killfocus_wndproc_wc", GetModuleHandleA(NULL));
}
+static void test_sysmem_draw(void)
+{
+ D3DVERTEXBUFFERDESC vb_desc;
+ IDirect3DVertexBuffer7 *vb;
+ IDirect3DDevice7 *device;
+ IDirectDrawSurface7 *rt;
+ IDirect3D7 *d3d;
+ D3DCOLOR colour;
+ ULONG refcount;
+ HWND window;
+ HRESULT hr;
+ BYTE *data;
+
+ static const struct
+ {
+ struct vec3 position;
+ DWORD diffuse;
+ }
+ quad[] =
+ {
+ {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
+ {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
+ {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
+ {{ 1.0f, 1.0f, 0.0f}, 0xffffffff},
+ };
+ static WORD indices[] = {0, 1, 2, 3};
+
+ window = create_window();
+ ok(!!window, "Failed to create a window.\n");
+
+ if (!(device = create_device(window, DDSCL_NORMAL)))
+ {
+ skip("Failed to create a 3D device, skipping test.\n");
+ DestroyWindow(window);
+ return;
+ }
+
+ hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+
+ vb_desc.dwSize = sizeof(vb_desc);
+ vb_desc.dwCaps = D3DVBCAPS_SYSTEMMEMORY;
+ vb_desc.dwFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;
+ vb_desc.dwNumVertices = 4;
+ hr = IDirect3D7_CreateVertexBuffer(d3d, &vb_desc, &vb, 0);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DVertexBuffer7_Lock(vb, 0, (void **)&data, NULL);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+ memcpy(data, quad, sizeof(quad));
+ hr = IDirect3DVertexBuffer7_Unlock(vb);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x77777777, 0.0f, 0);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice7_BeginScene(device);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice7_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 4, 0);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice7_EndScene(device);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+
+ colour = get_surface_color(rt, 320, 240);
+ ok(compare_color(colour, 0x00007f7f, 1), "Got unexpected colour 0x%08x.\n", colour);
+
+ hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x77777777, 0.0f, 0);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice7_BeginScene(device);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice7_DrawIndexedPrimitiveVB(device, D3DPT_TRIANGLESTRIP, vb, 0, 4, indices, 4, 0);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice7_EndScene(device);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+
+ colour = get_surface_color(rt, 320, 240);
+ ok(compare_color(colour, 0x00007f7f, 1), "Got unexpected colour 0x%08x.\n", colour);
+
+ IDirect3DVertexBuffer7_Release(vb);
+ IDirectDrawSurface7_Release(rt);
+ IDirect3D7_Release(d3d);
+ refcount = IDirect3DDevice7_Release(device);
+ ok(!refcount, "Device has %u references left.\n", refcount);
+ DestroyWindow(window);
+}
+
START_TEST(ddraw7)
{
DDDEVICEIDENTIFIER2 identifier;
@@ -15227,4 +15319,5 @@ START_TEST(ddraw7)
test_device_load();
test_color_vertex();
test_killfocus();
+ test_sysmem_draw();
}
--
2.11.0
2
1
17 Dec '18
From: Matteo Bruni <mbruni(a)codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni(a)codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
---
dlls/d3d8/buffer.c | 24 +++++++++++--
dlls/d3d8/d3d8_private.h | 4 ++-
dlls/d3d8/device.c | 47 +++++++++++++++++++++---
dlls/d3d8/tests/visual.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++-
4 files changed, 160 insertions(+), 9 deletions(-)
diff --git a/dlls/d3d8/buffer.c b/dlls/d3d8/buffer.c
index 20efe6bd18a..58aaff275b1 100644
--- a/dlls/d3d8/buffer.c
+++ b/dlls/d3d8/buffer.c
@@ -377,6 +377,8 @@ static ULONG WINAPI d3d8_indexbuffer_AddRef(IDirect3DIndexBuffer8 *iface)
IDirect3DDevice8_AddRef(buffer->parent_device);
wined3d_mutex_lock();
wined3d_buffer_incref(buffer->wined3d_buffer);
+ if (buffer->draw_buffer)
+ wined3d_buffer_incref(buffer->draw_buffer);
wined3d_mutex_unlock();
}
@@ -396,6 +398,8 @@ static ULONG WINAPI d3d8_indexbuffer_Release(IDirect3DIndexBuffer8 *iface)
wined3d_mutex_lock();
wined3d_buffer_decref(buffer->wined3d_buffer);
+ if (buffer->draw_buffer)
+ wined3d_buffer_decref(buffer->draw_buffer);
wined3d_mutex_unlock();
/* Release the device last, as it may cause the device to be destroyed. */
@@ -592,6 +596,7 @@ static const struct wined3d_parent_ops d3d8_indexbuffer_wined3d_parent_ops =
HRESULT indexbuffer_init(struct d3d8_indexbuffer *buffer, struct d3d8_device *device,
UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool)
{
+ const struct wined3d_parent_ops *parent_ops = &d3d8_null_wined3d_parent_ops;
struct wined3d_buffer_desc desc;
HRESULT hr;
@@ -604,19 +609,32 @@ HRESULT indexbuffer_init(struct d3d8_indexbuffer *buffer, struct d3d8_device *de
desc.byte_width = size;
desc.usage = (usage & WINED3DUSAGE_MASK) | WINED3DUSAGE_STATICDECL;
- desc.bind_flags = WINED3D_BIND_INDEX_BUFFER;
+ desc.bind_flags = 0;
desc.access = wined3daccess_from_d3dpool(pool, usage)
| WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W;
desc.misc_flags = 0;
desc.structure_byte_stride = 0;
+ if (desc.access & WINED3D_RESOURCE_ACCESS_GPU)
+ {
+ desc.bind_flags = WINED3D_BIND_INDEX_BUFFER;
+ parent_ops = &d3d8_indexbuffer_wined3d_parent_ops;
+ }
+
buffer->IDirect3DIndexBuffer8_iface.lpVtbl = &d3d8_indexbuffer_vtbl;
d3d8_resource_init(&buffer->resource);
buffer->format = wined3dformat_from_d3dformat(format);
wined3d_mutex_lock();
- hr = wined3d_buffer_create(device->wined3d_device, &desc, NULL, buffer,
- &d3d8_indexbuffer_wined3d_parent_ops, &buffer->wined3d_buffer);
+ hr = wined3d_buffer_create(device->wined3d_device, &desc, NULL, buffer, parent_ops, &buffer->wined3d_buffer);
+ if (SUCCEEDED(hr) && !(desc.access & WINED3D_RESOURCE_ACCESS_GPU))
+ {
+ desc.bind_flags = WINED3D_BIND_INDEX_BUFFER;
+ desc.access = WINED3D_RESOURCE_ACCESS_GPU;
+ if (FAILED(hr = wined3d_buffer_create(device->wined3d_device, &desc, NULL, buffer,
+ &d3d8_indexbuffer_wined3d_parent_ops, &buffer->draw_buffer)))
+ wined3d_buffer_decref(buffer->wined3d_buffer);
+ }
wined3d_mutex_unlock();
if (FAILED(hr))
{
diff --git a/dlls/d3d8/d3d8_private.h b/dlls/d3d8/d3d8_private.h
index 4a62dbe40c0..81f4e2009fd 100644
--- a/dlls/d3d8/d3d8_private.h
+++ b/dlls/d3d8/d3d8_private.h
@@ -124,9 +124,10 @@ struct d3d8_device
LONG device_state;
DWORD sysmem_vb : 16; /* D3D8_MAX_STREAMS */
+ DWORD sysmem_ib : 1;
DWORD in_destruction : 1;
DWORD recording : 1;
- DWORD padding : 14;
+ DWORD padding : 13;
/* The d3d8 API supports only one implicit swapchain (no D3DCREATE_ADAPTERGROUP_DEVICE,
* no GetSwapchain, GetBackBuffer doesn't accept a swapchain number). */
@@ -220,6 +221,7 @@ struct d3d8_indexbuffer
struct d3d8_resource resource;
struct wined3d_buffer *wined3d_buffer;
IDirect3DDevice8 *parent_device;
+ struct wined3d_buffer *draw_buffer;
enum wined3d_format_id format;
};
diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c
index 8ae1502b566..1f61514b0b7 100644
--- a/dlls/d3d8/device.c
+++ b/dlls/d3d8/device.c
@@ -1899,6 +1899,7 @@ static HRESULT WINAPI d3d8_device_ApplyStateBlock(IDirect3DDevice8 *iface, DWORD
struct wined3d_buffer *wined3d_buffer;
struct d3d8_vertexbuffer *buffer;
unsigned int i, offset, stride;
+ enum wined3d_format_id format;
HRESULT hr;
TRACE("iface %p, token %#x.\n", iface, token);
@@ -1926,6 +1927,8 @@ static HRESULT WINAPI d3d8_device_ApplyStateBlock(IDirect3DDevice8 *iface, DWORD
if (buffer->draw_buffer)
device->sysmem_vb |= 1u << i;
}
+ device->sysmem_ib = (wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &format, &offset))
+ && (buffer = wined3d_buffer_get_parent(wined3d_buffer)) && buffer->draw_buffer;
wined3d_mutex_unlock();
return D3D_OK;
@@ -2274,6 +2277,31 @@ static void d3d8_device_upload_sysmem_vertex_buffers(struct d3d8_device *device,
}
}
+static void d3d8_device_upload_sysmem_index_buffer(struct d3d8_device *device,
+ unsigned int start_idx, unsigned int idx_count)
+{
+ struct wined3d_box box = {0, 0, 0, 1, 0, 1};
+ struct d3d8_vertexbuffer *d3d8_buffer;
+ struct wined3d_buffer *dst_buffer;
+ enum wined3d_format_id format;
+ unsigned int offset, idx_size;
+ HRESULT hr;
+
+ if (!device->sysmem_ib)
+ return;
+
+ if (!(dst_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &format, &offset)))
+ ERR("Failed to get index buffer.\n");
+ d3d8_buffer = wined3d_buffer_get_parent(dst_buffer);
+ idx_size = format == WINED3DFMT_R16_UINT ? 2 : 4;
+ box.left = offset + start_idx * idx_size;
+ box.right = box.left + idx_count * idx_size;
+ if (FAILED(hr = wined3d_device_copy_sub_resource_region(device->wined3d_device,
+ wined3d_buffer_get_resource(dst_buffer), 0, box.left, 0, 0,
+ wined3d_buffer_get_resource(d3d8_buffer->wined3d_buffer), 0, &box, 0)))
+ ERR("Failed to update buffer.\n");
+}
+
static HRESULT WINAPI d3d8_device_DrawPrimitive(IDirect3DDevice8 *iface,
D3DPRIMITIVETYPE primitive_type, UINT start_vertex, UINT primitive_count)
{
@@ -2299,16 +2327,18 @@ static HRESULT WINAPI d3d8_device_DrawIndexedPrimitive(IDirect3DDevice8 *iface,
UINT start_idx, UINT primitive_count)
{
struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
+ unsigned int index_count;
HRESULT hr;
TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, start_idx %u, primitive_count %u.\n",
iface, primitive_type, min_vertex_idx, vertex_count, start_idx, primitive_count);
+ index_count = vertex_count_from_primitive_count(primitive_type, primitive_count);
wined3d_mutex_lock();
d3d8_device_upload_sysmem_vertex_buffers(device, min_vertex_idx, vertex_count);
+ d3d8_device_upload_sysmem_index_buffer(device, start_idx, index_count);
wined3d_device_set_primitive_type(device->wined3d_device, primitive_type, 0);
- hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, start_idx,
- vertex_count_from_primitive_count(primitive_type, primitive_count));
+ hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, start_idx, index_count);
wined3d_mutex_unlock();
return hr;
@@ -2882,9 +2912,17 @@ static HRESULT WINAPI d3d8_device_SetIndices(IDirect3DDevice8 *iface,
{
struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
struct d3d8_indexbuffer *ib = unsafe_impl_from_IDirect3DIndexBuffer8(buffer);
+ struct wined3d_buffer *wined3d_buffer;
TRACE("iface %p, buffer %p, base_vertex_idx %u.\n", iface, buffer, base_vertex_idx);
+ if (!ib)
+ wined3d_buffer = NULL;
+ else if (ib->draw_buffer)
+ wined3d_buffer = ib->draw_buffer;
+ else
+ wined3d_buffer = ib->wined3d_buffer;
+
/* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
* the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
* vertex buffers can't be created to address them with an index that requires the 32nd bit
@@ -2893,8 +2931,9 @@ static HRESULT WINAPI d3d8_device_SetIndices(IDirect3DDevice8 *iface,
*/
wined3d_mutex_lock();
wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_idx);
- wined3d_device_set_index_buffer(device->wined3d_device,
- ib ? ib->wined3d_buffer : NULL, ib ? ib->format : WINED3DFMT_UNKNOWN, 0);
+ wined3d_device_set_index_buffer(device->wined3d_device, wined3d_buffer, ib ? ib->format : WINED3DFMT_UNKNOWN, 0);
+ if (!device->recording)
+ device->sysmem_ib = ib && ib->draw_buffer;
wined3d_mutex_unlock();
return D3D_OK;
diff --git a/dlls/d3d8/tests/visual.c b/dlls/d3d8/tests/visual.c
index 7576008b384..25f96fd3dd5 100644
--- a/dlls/d3d8/tests/visual.c
+++ b/dlls/d3d8/tests/visual.c
@@ -10448,7 +10448,8 @@ static void test_color_vertex(void)
static void test_sysmem_draw(void)
{
- IDirect3DVertexBuffer8 *vb;
+ IDirect3DVertexBuffer8 *vb, *vb_s0, *vb_s1;
+ IDirect3DIndexBuffer8 *ib;
IDirect3DDevice8 *device;
IDirect3D8 *d3d;
D3DCOLOR colour;
@@ -10456,7 +10457,16 @@ static void test_sysmem_draw(void)
HWND window;
HRESULT hr;
BYTE *data;
+ DWORD vs;
+ static const DWORD decl[] =
+ {
+ D3DVSD_STREAM(0),
+ D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3),
+ D3DVSD_STREAM(1),
+ D3DVSD_REG(D3DVSDE_DIFFUSE, D3DVSDT_D3DCOLOR),
+ D3DVSD_END()
+ };
static const struct
{
struct vec3 position;
@@ -10469,6 +10479,21 @@ static void test_sysmem_draw(void)
{{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
{{ 1.0f, 1.0f, 0.0f}, 0xffffffff},
};
+ static const struct vec3 quad_s0[] =
+ {
+ {-1.0f, -1.0f, 0.0f},
+ {-1.0f, 1.0f, 0.0f},
+ { 1.0f, -1.0f, 0.0f},
+ { 1.0f, 1.0f, 0.0f},
+ };
+ static const DWORD quad_s1[] =
+ {
+ 0xffff0000,
+ 0xff00ff00,
+ 0xff0000ff,
+ 0xffffffff,
+ };
+ static const short indices[] = {0, 1, 2, 3};
window = create_window();
ok(!!window, "Failed to create a window.\n");
@@ -10512,9 +10537,76 @@ static void test_sysmem_draw(void)
colour = getPixelColor(device, 320, 240);
ok(color_match(colour, 0x00007f7f, 1), "Got unexpected colour 0x%08x.\n", colour);
+ hr = IDirect3DDevice8_CreateIndexBuffer(device, sizeof(indices), 0,
+ D3DFMT_INDEX16, D3DPOOL_SYSTEMMEM, &ib);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DIndexBuffer8_Lock(ib, 0, sizeof(indices), (BYTE **)&data, 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ memcpy(data, indices, sizeof(indices));
+ hr = IDirect3DIndexBuffer8_Unlock(ib);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x77777777, 0.0f, 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice8_SetIndices(device, ib, 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice8_BeginScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice8_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 4, 0, 2);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice8_EndScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ colour = getPixelColor(device, 320, 240);
+ ok(color_match(colour, 0x00007f7f, 1), "Got unexpected colour 0x%08x.\n", colour);
+
+ hr = IDirect3DDevice8_CreateVertexShader(device, decl, NULL, &vs, 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice8_SetVertexShader(device, vs);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice8_CreateVertexBuffer(device, sizeof(quad_s0), 0, 0, D3DPOOL_SYSTEMMEM, &vb_s0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DVertexBuffer8_Lock(vb_s0, 0, sizeof(quad_s0), (BYTE **)&data, 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ memcpy(data, quad_s0, sizeof(quad_s0));
+ hr = IDirect3DVertexBuffer8_Unlock(vb_s0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice8_CreateVertexBuffer(device, sizeof(quad_s1), 0, 0, D3DPOOL_SYSTEMMEM, &vb_s1);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DVertexBuffer8_Lock(vb_s1, 0, sizeof(quad_s1), (BYTE **)&data, 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ memcpy(data, quad_s1, sizeof(quad_s1));
+ hr = IDirect3DVertexBuffer8_Unlock(vb_s1);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice8_SetStreamSource(device, 0, vb_s0, sizeof(*quad_s0));
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice8_SetStreamSource(device, 1, vb_s1, sizeof(*quad_s1));
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x77777777, 0.0f, 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice8_BeginScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice8_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 4, 0, 2);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice8_EndScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ colour = getPixelColor(device, 320, 240);
+ ok(color_match(colour, 0x00007f7f, 1), "Got unexpected colour 0x%08x.\n", colour);
+
hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ IDirect3DVertexBuffer8_Release(vb_s1);
+ IDirect3DVertexBuffer8_Release(vb_s0);
+ IDirect3DDevice8_DeleteVertexShader(device, vs);
+ IDirect3DIndexBuffer8_Release(ib);
IDirect3DVertexBuffer8_Release(vb);
refcount = IDirect3DDevice8_Release(device);
ok(!refcount, "Device has %u references left.\n", refcount);
--
2.11.0
2
1
[PATCH 3/5] d3d8: Support drawing from D3DPOOL_SYSTEMMEM vertex buffers.
by Henri Verbeet 17 Dec '18
by Henri Verbeet 17 Dec '18
17 Dec '18
From: Matteo Bruni <mbruni(a)codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni(a)codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
---
dlls/d3d8/buffer.c | 24 ++++++++++++--
dlls/d3d8/d3d8_private.h | 14 ++++++---
dlls/d3d8/device.c | 81 ++++++++++++++++++++++++++++++++++++++++++------
dlls/d3d8/tests/visual.c | 77 +++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 180 insertions(+), 16 deletions(-)
diff --git a/dlls/d3d8/buffer.c b/dlls/d3d8/buffer.c
index 626d74e964c..20efe6bd18a 100644
--- a/dlls/d3d8/buffer.c
+++ b/dlls/d3d8/buffer.c
@@ -57,6 +57,8 @@ static ULONG WINAPI d3d8_vertexbuffer_AddRef(IDirect3DVertexBuffer8 *iface)
IDirect3DDevice8_AddRef(buffer->parent_device);
wined3d_mutex_lock();
wined3d_buffer_incref(buffer->wined3d_buffer);
+ if (buffer->draw_buffer)
+ wined3d_buffer_incref(buffer->draw_buffer);
wined3d_mutex_unlock();
}
@@ -76,6 +78,8 @@ static ULONG WINAPI d3d8_vertexbuffer_Release(IDirect3DVertexBuffer8 *iface)
wined3d_mutex_lock();
wined3d_buffer_decref(buffer->wined3d_buffer);
+ if (buffer->draw_buffer)
+ wined3d_buffer_decref(buffer->draw_buffer);
wined3d_mutex_unlock();
/* Release the device last, as it may cause the device to be destroyed. */
@@ -273,6 +277,7 @@ static const struct wined3d_parent_ops d3d8_vertexbuffer_wined3d_parent_ops =
HRESULT vertexbuffer_init(struct d3d8_vertexbuffer *buffer, struct d3d8_device *device,
UINT size, DWORD usage, DWORD fvf, D3DPOOL pool)
{
+ const struct wined3d_parent_ops *parent_ops = &d3d8_null_wined3d_parent_ops;
struct wined3d_buffer_desc desc;
HRESULT hr;
@@ -292,15 +297,28 @@ HRESULT vertexbuffer_init(struct d3d8_vertexbuffer *buffer, struct d3d8_device *
desc.byte_width = size;
desc.usage = usage & WINED3DUSAGE_MASK;
- desc.bind_flags = WINED3D_BIND_VERTEX_BUFFER;
+ desc.bind_flags = 0;
desc.access = wined3daccess_from_d3dpool(pool, usage)
| WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W;
desc.misc_flags = 0;
desc.structure_byte_stride = 0;
+ if (desc.access & WINED3D_RESOURCE_ACCESS_GPU)
+ {
+ desc.bind_flags = WINED3D_BIND_VERTEX_BUFFER;
+ parent_ops = &d3d8_vertexbuffer_wined3d_parent_ops;
+ }
+
wined3d_mutex_lock();
- hr = wined3d_buffer_create(device->wined3d_device, &desc, NULL, buffer,
- &d3d8_vertexbuffer_wined3d_parent_ops, &buffer->wined3d_buffer);
+ hr = wined3d_buffer_create(device->wined3d_device, &desc, NULL, buffer, parent_ops, &buffer->wined3d_buffer);
+ if (SUCCEEDED(hr) && !(desc.access & WINED3D_RESOURCE_ACCESS_GPU))
+ {
+ desc.bind_flags = WINED3D_BIND_VERTEX_BUFFER;
+ desc.access = WINED3D_RESOURCE_ACCESS_GPU;
+ if (FAILED(hr = wined3d_buffer_create(device->wined3d_device, &desc, NULL, buffer,
+ &d3d8_vertexbuffer_wined3d_parent_ops, &buffer->draw_buffer)))
+ wined3d_buffer_decref(buffer->wined3d_buffer);
+ }
wined3d_mutex_unlock();
if (FAILED(hr))
{
diff --git a/dlls/d3d8/d3d8_private.h b/dlls/d3d8/d3d8_private.h
index 7f6049df574..4a62dbe40c0 100644
--- a/dlls/d3d8/d3d8_private.h
+++ b/dlls/d3d8/d3d8_private.h
@@ -39,9 +39,14 @@
#define D3DPRESENTFLAGS_MASK 0x00000fffu
+#define D3D8_MAX_VERTEX_SHADER_CONSTANTF 256
+#define D3D8_MAX_STREAMS 16
+
/* CreateVertexShader can return > 0xFFFF */
#define VS_HIGHESTFIXEDFXF 0xF0000000
+extern const struct wined3d_parent_ops d3d8_null_wined3d_parent_ops DECLSPEC_HIDDEN;
+
void d3dcaps_from_wined3dcaps(D3DCAPS8 *caps, const struct wined3d_caps *wined3d_caps) DECLSPEC_HIDDEN;
struct d3d8
@@ -118,8 +123,10 @@ struct d3d8_device
UINT index_buffer_pos;
LONG device_state;
- /* Avoids recursion with nested ReleaseRef to 0 */
- BOOL inDestruction;
+ DWORD sysmem_vb : 16; /* D3D8_MAX_STREAMS */
+ DWORD in_destruction : 1;
+ DWORD recording : 1;
+ DWORD padding : 14;
/* The d3d8 API supports only one implicit swapchain (no D3DCREATE_ADAPTERGROUP_DEVICE,
* no GetSwapchain, GetBackBuffer doesn't accept a swapchain number). */
@@ -199,6 +206,7 @@ struct d3d8_vertexbuffer
struct d3d8_resource resource;
struct wined3d_buffer *wined3d_buffer;
IDirect3DDevice8 *parent_device;
+ struct wined3d_buffer *draw_buffer;
DWORD fvf;
};
@@ -260,8 +268,6 @@ void d3d8_vertex_shader_destroy(struct d3d8_vertex_shader *shader) DECLSPEC_HIDD
HRESULT d3d8_vertex_shader_init(struct d3d8_vertex_shader *shader, struct d3d8_device *device,
const DWORD *declaration, const DWORD *byte_code, DWORD shader_handle, DWORD usage) DECLSPEC_HIDDEN;
-#define D3D8_MAX_VERTEX_SHADER_CONSTANTF 256
-
struct d3d8_pixel_shader
{
DWORD handle;
diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c
index 3c83811103f..8ae1502b566 100644
--- a/dlls/d3d8/device.c
+++ b/dlls/d3d8/device.c
@@ -36,7 +36,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
static void STDMETHODCALLTYPE d3d8_null_wined3d_object_destroyed(void *parent) {}
-static const struct wined3d_parent_ops d3d8_null_wined3d_parent_ops =
+const struct wined3d_parent_ops d3d8_null_wined3d_parent_ops =
{
d3d8_null_wined3d_object_destroyed,
};
@@ -564,7 +564,7 @@ static ULONG WINAPI d3d8_device_Release(IDirect3DDevice8 *iface)
struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
ULONG ref;
- if (device->inDestruction)
+ if (device->in_destruction)
return 0;
ref = InterlockedDecrement(&device->ref);
@@ -580,7 +580,7 @@ static ULONG WINAPI d3d8_device_Release(IDirect3DDevice8 *iface)
wined3d_mutex_lock();
- device->inDestruction = TRUE;
+ device->in_destruction = TRUE;
for (i = 0; i < device->numConvertedDecls; ++i)
{
@@ -891,6 +891,7 @@ static HRESULT WINAPI d3d8_device_Reset(IDirect3DDevice8 *iface,
if (SUCCEEDED(hr = wined3d_device_reset(device->wined3d_device, &swapchain_desc,
NULL, reset_enum_callback, TRUE)))
{
+ device->recording = FALSE;
present_parameters->BackBufferCount = swapchain_desc.backbuffer_count;
device->implicit_swapchain->swap_interval
= wined3dswapinterval_from_d3d(present_parameters->FullScreen_PresentationInterval);
@@ -1845,7 +1846,8 @@ static HRESULT WINAPI d3d8_device_BeginStateBlock(IDirect3DDevice8 *iface)
TRACE("iface %p.\n", iface);
wined3d_mutex_lock();
- hr = wined3d_device_begin_stateblock(device->wined3d_device);
+ if (SUCCEEDED(hr = wined3d_device_begin_stateblock(device->wined3d_device)))
+ device->recording = TRUE;
wined3d_mutex_unlock();
return hr;
@@ -1870,6 +1872,7 @@ static HRESULT WINAPI d3d8_device_EndStateBlock(IDirect3DDevice8 *iface, DWORD *
wined3d_mutex_unlock();
return hr;
}
+ device->recording = FALSE;
*token = d3d8_allocate_handle(&device->handle_table, stateblock, D3D8_HANDLE_SB);
wined3d_mutex_unlock();
@@ -1893,6 +1896,10 @@ static HRESULT WINAPI d3d8_device_ApplyStateBlock(IDirect3DDevice8 *iface, DWORD
{
struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
struct wined3d_stateblock *stateblock;
+ struct wined3d_buffer *wined3d_buffer;
+ struct d3d8_vertexbuffer *buffer;
+ unsigned int i, offset, stride;
+ HRESULT hr;
TRACE("iface %p, token %#x.\n", iface, token);
@@ -1908,6 +1915,17 @@ static HRESULT WINAPI d3d8_device_ApplyStateBlock(IDirect3DDevice8 *iface, DWORD
return D3DERR_INVALIDCALL;
}
wined3d_stateblock_apply(stateblock);
+ device->sysmem_vb = 0;
+ for (i = 0; i < D3D8_MAX_STREAMS; ++i)
+ {
+ if (FAILED(hr = wined3d_device_get_stream_source(device->wined3d_device,
+ i, &wined3d_buffer, &offset, &stride)))
+ continue;
+ if (!wined3d_buffer || !(buffer = wined3d_buffer_get_parent(wined3d_buffer)))
+ continue;
+ if (buffer->draw_buffer)
+ device->sysmem_vb |= 1u << i;
+ }
wined3d_mutex_unlock();
return D3D_OK;
@@ -2229,19 +2247,48 @@ static HRESULT WINAPI d3d8_device_GetCurrentTexturePalette(IDirect3DDevice8 *ifa
return D3DERR_INVALIDCALL;
}
+static void d3d8_device_upload_sysmem_vertex_buffers(struct d3d8_device *device,
+ unsigned int start_vertex, unsigned int vertex_count)
+{
+ struct wined3d_box box = {0, 0, 0, 1, 0, 1};
+ struct d3d8_vertexbuffer *d3d8_buffer;
+ unsigned int i, offset, stride, map;
+ struct wined3d_buffer *dst_buffer;
+ HRESULT hr;
+
+ map = device->sysmem_vb;
+ while (map)
+ {
+ i = ffs(map) - 1;
+ map ^= 1u << i;
+
+ if (FAILED(hr = wined3d_device_get_stream_source(device->wined3d_device, i, &dst_buffer, &offset, &stride)))
+ ERR("Failed to get stream source.\n");
+ d3d8_buffer = wined3d_buffer_get_parent(dst_buffer);
+ box.left = offset + start_vertex * stride;
+ box.right = box.left + vertex_count * stride;
+ if (FAILED(hr = wined3d_device_copy_sub_resource_region(device->wined3d_device,
+ wined3d_buffer_get_resource(dst_buffer), 0, box.left, 0, 0,
+ wined3d_buffer_get_resource(d3d8_buffer->wined3d_buffer), 0, &box, 0)))
+ ERR("Failed to update buffer.\n");
+ }
+}
+
static HRESULT WINAPI d3d8_device_DrawPrimitive(IDirect3DDevice8 *iface,
D3DPRIMITIVETYPE primitive_type, UINT start_vertex, UINT primitive_count)
{
struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
+ unsigned int vertex_count;
HRESULT hr;
TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
iface, primitive_type, start_vertex, primitive_count);
+ vertex_count = vertex_count_from_primitive_count(primitive_type, primitive_count);
wined3d_mutex_lock();
+ d3d8_device_upload_sysmem_vertex_buffers(device, start_vertex, vertex_count);
wined3d_device_set_primitive_type(device->wined3d_device, primitive_type, 0);
- hr = wined3d_device_draw_primitive(device->wined3d_device, start_vertex,
- vertex_count_from_primitive_count(primitive_type, primitive_count));
+ hr = wined3d_device_draw_primitive(device->wined3d_device, start_vertex, vertex_count);
wined3d_mutex_unlock();
return hr;
@@ -2258,6 +2305,7 @@ static HRESULT WINAPI d3d8_device_DrawIndexedPrimitive(IDirect3DDevice8 *iface,
iface, primitive_type, min_vertex_idx, vertex_count, start_idx, primitive_count);
wined3d_mutex_lock();
+ d3d8_device_upload_sysmem_vertex_buffers(device, min_vertex_idx, vertex_count);
wined3d_device_set_primitive_type(device->wined3d_device, primitive_type, 0);
hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, start_idx,
vertex_count_from_primitive_count(primitive_type, primitive_count));
@@ -3098,6 +3146,7 @@ static HRESULT WINAPI d3d8_device_SetStreamSource(IDirect3DDevice8 *iface,
{
struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
struct d3d8_vertexbuffer *buffer_impl = unsafe_impl_from_IDirect3DVertexBuffer8(buffer);
+ struct wined3d_buffer *wined3d_buffer;
HRESULT hr;
TRACE("iface %p, stream_idx %u, buffer %p, stride %u.\n",
@@ -3106,14 +3155,28 @@ static HRESULT WINAPI d3d8_device_SetStreamSource(IDirect3DDevice8 *iface,
wined3d_mutex_lock();
if (!stride)
{
- struct wined3d_buffer *wined3d_buffer;
unsigned int cur_offset;
hr = wined3d_device_get_stream_source(device->wined3d_device, stream_idx, &wined3d_buffer,
&cur_offset, &stride);
}
- hr = wined3d_device_set_stream_source(device->wined3d_device, stream_idx,
- buffer_impl ? buffer_impl->wined3d_buffer : NULL, 0, stride);
+
+ if (!buffer_impl)
+ wined3d_buffer = NULL;
+ else if (buffer_impl->draw_buffer)
+ wined3d_buffer = buffer_impl->draw_buffer;
+ else
+ wined3d_buffer = buffer_impl->wined3d_buffer;
+
+ hr = wined3d_device_set_stream_source(device->wined3d_device, stream_idx, wined3d_buffer, 0, stride);
+ if (SUCCEEDED(hr) && !device->recording)
+ {
+ if (buffer_impl && buffer_impl->draw_buffer)
+ device->sysmem_vb |= (1u << stream_idx);
+ else
+ device->sysmem_vb &= ~(1u << stream_idx);
+ }
+
wined3d_mutex_unlock();
return hr;
diff --git a/dlls/d3d8/tests/visual.c b/dlls/d3d8/tests/visual.c
index e8e6bf870e2..7576008b384 100644
--- a/dlls/d3d8/tests/visual.c
+++ b/dlls/d3d8/tests/visual.c
@@ -10446,6 +10446,82 @@ static void test_color_vertex(void)
DestroyWindow(window);
}
+static void test_sysmem_draw(void)
+{
+ IDirect3DVertexBuffer8 *vb;
+ IDirect3DDevice8 *device;
+ IDirect3D8 *d3d;
+ D3DCOLOR colour;
+ ULONG refcount;
+ HWND window;
+ HRESULT hr;
+ BYTE *data;
+
+ static const struct
+ {
+ struct vec3 position;
+ DWORD diffuse;
+ }
+ quad[] =
+ {
+ {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
+ {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
+ {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
+ {{ 1.0f, 1.0f, 0.0f}, 0xffffffff},
+ };
+
+ window = create_window();
+ ok(!!window, "Failed to create a window.\n");
+
+ d3d = Direct3DCreate8(D3D_SDK_VERSION);
+ ok(!!d3d, "Failed to create a D3D object.\n");
+ if (!(device = create_device(d3d, window, window, TRUE)))
+ {
+ skip("Failed to create a D3D device, skipping tests.\n");
+ IDirect3D8_Release(d3d);
+ DestroyWindow(window);
+ return;
+ }
+
+ hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice8_CreateVertexBuffer(device, sizeof(quad), 0, 0, D3DPOOL_SYSTEMMEM, &vb);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DVertexBuffer8_Lock(vb, 0, sizeof(quad), (BYTE **)&data, 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ memcpy(data, quad, sizeof(quad));
+ hr = IDirect3DVertexBuffer8_Unlock(vb);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x77777777, 0.0f, 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice8_SetStreamSource(device, 0, vb, sizeof(*quad));
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice8_BeginScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice8_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 2);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice8_EndScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ colour = getPixelColor(device, 320, 240);
+ ok(color_match(colour, 0x00007f7f, 1), "Got unexpected colour 0x%08x.\n", colour);
+
+ hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ IDirect3DVertexBuffer8_Release(vb);
+ refcount = IDirect3DDevice8_Release(device);
+ ok(!refcount, "Device has %u references left.\n", refcount);
+ IDirect3D8_Release(d3d);
+ DestroyWindow(window);
+}
+
START_TEST(visual)
{
D3DADAPTER_IDENTIFIER8 identifier;
@@ -10520,4 +10596,5 @@ START_TEST(visual)
test_map_synchronisation();
test_viewport();
test_color_vertex();
+ test_sysmem_draw();
}
--
2.11.0
2
1
17 Dec '18
From: Matteo Bruni <mbruni(a)codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni(a)codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
---
dlls/d3d9/buffer.c | 24 ++++++-
dlls/d3d9/d3d9_private.h | 4 +-
dlls/d3d9/device.c | 44 +++++++++++--
dlls/d3d9/stateblock.c | 3 +
dlls/d3d9/tests/visual.c | 167 +++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 234 insertions(+), 8 deletions(-)
diff --git a/dlls/d3d9/buffer.c b/dlls/d3d9/buffer.c
index 15b7e2bdbce..1533a8496d2 100644
--- a/dlls/d3d9/buffer.c
+++ b/dlls/d3d9/buffer.c
@@ -384,6 +384,8 @@ static ULONG WINAPI d3d9_indexbuffer_AddRef(IDirect3DIndexBuffer9 *iface)
IDirect3DDevice9Ex_AddRef(buffer->parent_device);
wined3d_mutex_lock();
wined3d_buffer_incref(buffer->wined3d_buffer);
+ if (buffer->draw_buffer)
+ wined3d_buffer_incref(buffer->draw_buffer);
wined3d_mutex_unlock();
}
@@ -403,6 +405,8 @@ static ULONG WINAPI d3d9_indexbuffer_Release(IDirect3DIndexBuffer9 *iface)
wined3d_mutex_lock();
wined3d_buffer_decref(buffer->wined3d_buffer);
+ if (buffer->draw_buffer)
+ wined3d_buffer_decref(buffer->draw_buffer);
wined3d_mutex_unlock();
/* Release the device last, as it may cause the device to be destroyed. */
@@ -597,6 +601,7 @@ static const struct wined3d_parent_ops d3d9_indexbuffer_wined3d_parent_ops =
HRESULT indexbuffer_init(struct d3d9_indexbuffer *buffer, struct d3d9_device *device,
UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool)
{
+ const struct wined3d_parent_ops *parent_ops = &d3d9_null_wined3d_parent_ops;
struct wined3d_buffer_desc desc;
HRESULT hr;
@@ -615,19 +620,32 @@ HRESULT indexbuffer_init(struct d3d9_indexbuffer *buffer, struct d3d9_device *de
desc.byte_width = size;
desc.usage = (usage & WINED3DUSAGE_MASK) | WINED3DUSAGE_STATICDECL;
- desc.bind_flags = WINED3D_BIND_INDEX_BUFFER;
+ desc.bind_flags = 0;
desc.access = wined3daccess_from_d3dpool(pool, usage)
| WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W;
desc.misc_flags = 0;
desc.structure_byte_stride = 0;
+ if (desc.access & WINED3D_RESOURCE_ACCESS_GPU)
+ {
+ desc.bind_flags = WINED3D_BIND_INDEX_BUFFER;
+ parent_ops = &d3d9_indexbuffer_wined3d_parent_ops;
+ }
+
buffer->IDirect3DIndexBuffer9_iface.lpVtbl = &d3d9_indexbuffer_vtbl;
buffer->format = wined3dformat_from_d3dformat(format);
d3d9_resource_init(&buffer->resource);
wined3d_mutex_lock();
- hr = wined3d_buffer_create(device->wined3d_device, &desc, NULL, buffer,
- &d3d9_indexbuffer_wined3d_parent_ops, &buffer->wined3d_buffer);
+ hr = wined3d_buffer_create(device->wined3d_device, &desc, NULL, buffer, parent_ops, &buffer->wined3d_buffer);
+ if (SUCCEEDED(hr) && !(desc.access & WINED3D_RESOURCE_ACCESS_GPU))
+ {
+ desc.bind_flags = WINED3D_BIND_INDEX_BUFFER;
+ desc.access = WINED3D_RESOURCE_ACCESS_GPU;
+ if (FAILED(hr = wined3d_buffer_create(device->wined3d_device, &desc, NULL, buffer,
+ &d3d9_indexbuffer_wined3d_parent_ops, &buffer->draw_buffer)))
+ wined3d_buffer_decref(buffer->wined3d_buffer);
+ }
wined3d_mutex_unlock();
if (FAILED(hr))
{
diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h
index bd6409ffaf5..a4dc3abb7a6 100644
--- a/dlls/d3d9/d3d9_private.h
+++ b/dlls/d3d9/d3d9_private.h
@@ -104,11 +104,12 @@ struct d3d9_device
LONG device_state;
DWORD sysmem_vb : 16; /* D3D9_MAX_STREAMS */
+ DWORD sysmem_ib : 1;
DWORD in_destruction : 1;
DWORD in_scene : 1;
DWORD has_vertex_declaration : 1;
DWORD recording : 1;
- DWORD padding : 12;
+ DWORD padding : 11;
unsigned int max_user_clip_planes;
@@ -199,6 +200,7 @@ struct d3d9_indexbuffer
struct d3d9_resource resource;
struct wined3d_buffer *wined3d_buffer;
IDirect3DDevice9Ex *parent_device;
+ struct wined3d_buffer *draw_buffer;
enum wined3d_format_id format;
};
diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
index ba84db9338f..6844ad62e9f 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -2718,6 +2718,31 @@ static void d3d9_device_upload_sysmem_vertex_buffers(struct d3d9_device *device,
}
}
+static void d3d9_device_upload_sysmem_index_buffer(struct d3d9_device *device,
+ unsigned int start_idx, unsigned int idx_count)
+{
+ struct wined3d_box box = {0, 0, 0, 1, 0, 1};
+ struct d3d9_vertexbuffer *d3d9_buffer;
+ struct wined3d_buffer *dst_buffer;
+ enum wined3d_format_id format;
+ unsigned int offset, idx_size;
+ HRESULT hr;
+
+ if (!device->sysmem_ib)
+ return;
+
+ if (!(dst_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &format, &offset)))
+ ERR("Failed to get index buffer.\n");
+ d3d9_buffer = wined3d_buffer_get_parent(dst_buffer);
+ idx_size = format == WINED3DFMT_R16_UINT ? 2 : 4;
+ box.left = offset + start_idx * idx_size;
+ box.right = box.left + idx_count * idx_size;
+ if (FAILED(hr = wined3d_device_copy_sub_resource_region(device->wined3d_device,
+ wined3d_buffer_get_resource(dst_buffer), 0, box.left, 0, 0,
+ wined3d_buffer_get_resource(d3d9_buffer->wined3d_buffer), 0, &box, 0)))
+ ERR("Failed to update buffer.\n");
+}
+
static HRESULT WINAPI d3d9_device_DrawPrimitive(IDirect3DDevice9Ex *iface,
D3DPRIMITIVETYPE primitive_type, UINT start_vertex, UINT primitive_count)
{
@@ -2752,6 +2777,7 @@ static HRESULT WINAPI d3d9_device_DrawIndexedPrimitive(IDirect3DDevice9Ex *iface
UINT vertex_count, UINT start_idx, UINT primitive_count)
{
struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
+ unsigned int index_count;
HRESULT hr;
TRACE("iface %p, primitive_type %#x, base_vertex_idx %u, min_vertex_idx %u, "
@@ -2766,12 +2792,13 @@ static HRESULT WINAPI d3d9_device_DrawIndexedPrimitive(IDirect3DDevice9Ex *iface
WARN("Called without a valid vertex declaration set.\n");
return D3DERR_INVALIDCALL;
}
+ index_count = vertex_count_from_primitive_count(primitive_type, primitive_count);
d3d9_device_upload_sysmem_vertex_buffers(device, min_vertex_idx, vertex_count);
+ d3d9_device_upload_sysmem_index_buffer(device, start_idx, index_count);
d3d9_generate_auto_mipmaps(device);
wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_idx);
wined3d_device_set_primitive_type(device->wined3d_device, primitive_type, 0);
- hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, start_idx,
- vertex_count_from_primitive_count(primitive_type, primitive_count));
+ hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, start_idx, index_count);
if (SUCCEEDED(hr))
d3d9_rts_flag_auto_gen_mipmap(device);
wined3d_mutex_unlock();
@@ -3512,12 +3539,21 @@ static HRESULT WINAPI d3d9_device_SetIndices(IDirect3DDevice9Ex *iface, IDirect3
{
struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
struct d3d9_indexbuffer *ib = unsafe_impl_from_IDirect3DIndexBuffer9(buffer);
+ struct wined3d_buffer *wined3d_buffer;
TRACE("iface %p, buffer %p.\n", iface, buffer);
+ if (!ib)
+ wined3d_buffer = NULL;
+ else if (ib->draw_buffer)
+ wined3d_buffer = ib->draw_buffer;
+ else
+ wined3d_buffer = ib->wined3d_buffer;
+
wined3d_mutex_lock();
- wined3d_device_set_index_buffer(device->wined3d_device,
- ib ? ib->wined3d_buffer : NULL, ib ? ib->format : WINED3DFMT_UNKNOWN, 0);
+ wined3d_device_set_index_buffer(device->wined3d_device, wined3d_buffer, ib ? ib->format : WINED3DFMT_UNKNOWN, 0);
+ if (!device->recording)
+ device->sysmem_ib = ib && ib->draw_buffer;
wined3d_mutex_unlock();
return D3D_OK;
diff --git a/dlls/d3d9/stateblock.c b/dlls/d3d9/stateblock.c
index 440df0c1e1a..6f39488fc11 100644
--- a/dlls/d3d9/stateblock.c
+++ b/dlls/d3d9/stateblock.c
@@ -111,6 +111,7 @@ static HRESULT WINAPI d3d9_stateblock_Apply(IDirect3DStateBlock9 *iface)
struct wined3d_buffer *wined3d_buffer;
struct d3d9_vertexbuffer *buffer;
unsigned int i, offset, stride;
+ enum wined3d_format_id format;
struct d3d9_device *device;
HRESULT hr;
@@ -130,6 +131,8 @@ static HRESULT WINAPI d3d9_stateblock_Apply(IDirect3DStateBlock9 *iface)
if (buffer->draw_buffer)
device->sysmem_vb |= 1u << i;
}
+ device->sysmem_ib = (wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &format, &offset))
+ && (buffer = wined3d_buffer_get_parent(wined3d_buffer)) && buffer->draw_buffer;
wined3d_mutex_unlock();
return D3D_OK;
diff --git a/dlls/d3d9/tests/visual.c b/dlls/d3d9/tests/visual.c
index 4f26b0d23f9..392369a3f79 100644
--- a/dlls/d3d9/tests/visual.c
+++ b/dlls/d3d9/tests/visual.c
@@ -24197,6 +24197,172 @@ static void test_color_vertex(void)
DestroyWindow(window);
}
+static void test_sysmem_draw(void)
+{
+ IDirect3DVertexDeclaration9 *vertex_declaration;
+ IDirect3DVertexBuffer9 *vb, *vb_s0, *vb_s1;
+ IDirect3DIndexBuffer9 *ib;
+ IDirect3DDevice9 *device;
+ IDirect3D9 *d3d;
+ D3DCOLOR colour;
+ ULONG refcount;
+ HWND window;
+ HRESULT hr;
+ BYTE *data;
+
+ static const D3DVERTEXELEMENT9 decl_elements[] =
+ {
+ {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
+ {1, 0, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
+ D3DDECL_END()
+ };
+ static const struct
+ {
+ struct vec3 position;
+ DWORD diffuse;
+ }
+ quad[] =
+ {
+ {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
+ {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
+ {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
+ {{ 1.0f, 1.0f, 0.0f}, 0xffffffff},
+ };
+ static const struct vec3 quad_s0[] =
+ {
+ {-1.0f, -1.0f, 0.0f},
+ {-1.0f, 1.0f, 0.0f},
+ { 1.0f, -1.0f, 0.0f},
+ { 1.0f, 1.0f, 0.0f},
+ };
+ static const DWORD quad_s1[] =
+ {
+ 0xffff0000,
+ 0xff00ff00,
+ 0xff0000ff,
+ 0xffffffff,
+ };
+ static const short indices[] = {0, 1, 2, 3};
+
+ window = create_window();
+ ok(!!window, "Failed to create a window.\n");
+
+ d3d = Direct3DCreate9(D3D_SDK_VERSION);
+ ok(!!d3d, "Failed to create a D3D object.\n");
+ if (!(device = create_device(d3d, window, window, TRUE)))
+ {
+ skip("Failed to create a D3D device, skipping tests.\n");
+ IDirect3D9_Release(d3d);
+ DestroyWindow(window);
+ return;
+ }
+
+ hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(quad), 0, 0, D3DPOOL_SYSTEMMEM, &vb, NULL);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DVertexBuffer9_Lock(vb, 0, sizeof(quad), (void **)&data, 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ memcpy(data, quad, sizeof(quad));
+ hr = IDirect3DVertexBuffer9_Unlock(vb);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x77777777, 0.0f, 0);
+ ok(SUCCEEDED(hr), "Failed to clear depth/stencil, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice9_SetStreamSource(device, 0, vb, 0, sizeof(*quad));
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_BeginScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 2);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice9_EndScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ colour = getPixelColor(device, 320, 240);
+ ok(color_match(colour, 0x00007f7f, 1), "Got unexpected colour 0x%08x.\n", colour);
+
+ hr = IDirect3DDevice9_CreateIndexBuffer(device, sizeof(indices), 0,
+ D3DFMT_INDEX16, D3DPOOL_SYSTEMMEM, &ib, NULL);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DIndexBuffer9_Lock(ib, 0, sizeof(indices), (void **)&data, 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ memcpy(data, indices, sizeof(indices));
+ hr = IDirect3DIndexBuffer9_Unlock(ib);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x77777777, 0.0f, 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_SetIndices(device, ib);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_BeginScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 0, 4, 0, 2);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice9_EndScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ colour = getPixelColor(device, 320, 240);
+ ok(color_match(colour, 0x00007f7f, 1), "Got unexpected colour 0x%08x.\n", colour);
+
+ hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &vertex_declaration);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice9_SetVertexDeclaration(device, vertex_declaration);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(quad_s0), 0, 0, D3DPOOL_SYSTEMMEM, &vb_s0, NULL);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DVertexBuffer9_Lock(vb_s0, 0, sizeof(quad_s0), (void **)&data, 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ memcpy(data, quad_s0, sizeof(quad_s0));
+ hr = IDirect3DVertexBuffer9_Unlock(vb_s0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(quad_s1), 0, 0, D3DPOOL_SYSTEMMEM, &vb_s1, NULL);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DVertexBuffer9_Lock(vb_s1, 0, sizeof(quad_s1), (void **)&data, 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ memcpy(data, quad_s1, sizeof(quad_s1));
+ hr = IDirect3DVertexBuffer9_Unlock(vb_s1);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_SetStreamSource(device, 0, vb_s0, 0, sizeof(*quad_s0));
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice9_SetStreamSource(device, 1, vb_s1, 0, sizeof(*quad_s1));
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x77777777, 0.0f, 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_BeginScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 0, 4, 0, 2);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice9_EndScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ colour = getPixelColor(device, 320, 240);
+ ok(color_match(colour, 0x00007f7f, 1), "Got unexpected colour 0x%08x.\n", colour);
+
+ hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ IDirect3DVertexBuffer9_Release(vb_s1);
+ IDirect3DVertexBuffer9_Release(vb_s0);
+ IDirect3DVertexDeclaration9_Release(vertex_declaration);
+ IDirect3DIndexBuffer9_Release(ib);
+ IDirect3DVertexBuffer9_Release(vb);
+ refcount = IDirect3DDevice9_Release(device);
+ ok(!refcount, "Device has %u references left.\n", refcount);
+ IDirect3D9_Release(d3d);
+ DestroyWindow(window);
+}
+
START_TEST(visual)
{
D3DADAPTER_IDENTIFIER9 identifier;
@@ -24335,4 +24501,5 @@ START_TEST(visual)
test_null_format();
test_map_synchronisation();
test_color_vertex();
+ test_sysmem_draw();
}
--
2.11.0
2
1
[PATCH 1/5] d3d9: Support drawing from D3DPOOL_SYSTEMMEM vertex buffers.
by Henri Verbeet 17 Dec '18
by Henri Verbeet 17 Dec '18
17 Dec '18
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=45486
Signed-off-by: Matteo Bruni <mbruni(a)codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
---
dlls/d3d9/buffer.c | 24 ++++++++++++++++---
dlls/d3d9/d3d9_private.h | 11 ++++++---
dlls/d3d9/device.c | 60 +++++++++++++++++++++++++++++++++++++++++++-----
dlls/d3d9/stateblock.c | 17 ++++++++++++++
4 files changed, 100 insertions(+), 12 deletions(-)
diff --git a/dlls/d3d9/buffer.c b/dlls/d3d9/buffer.c
index 02b3570402f..15b7e2bdbce 100644
--- a/dlls/d3d9/buffer.c
+++ b/dlls/d3d9/buffer.c
@@ -59,6 +59,8 @@ static ULONG WINAPI d3d9_vertexbuffer_AddRef(IDirect3DVertexBuffer9 *iface)
IDirect3DDevice9Ex_AddRef(buffer->parent_device);
wined3d_mutex_lock();
wined3d_buffer_incref(buffer->wined3d_buffer);
+ if (buffer->draw_buffer)
+ wined3d_buffer_incref(buffer->draw_buffer);
wined3d_mutex_unlock();
}
@@ -78,6 +80,8 @@ static ULONG WINAPI d3d9_vertexbuffer_Release(IDirect3DVertexBuffer9 *iface)
wined3d_mutex_lock();
wined3d_buffer_decref(buffer->wined3d_buffer);
+ if (buffer->draw_buffer)
+ wined3d_buffer_decref(buffer->draw_buffer);
wined3d_mutex_unlock();
/* Release the device last, as it may cause the device to be destroyed. */
@@ -274,6 +278,7 @@ static const struct wined3d_parent_ops d3d9_vertexbuffer_wined3d_parent_ops =
HRESULT vertexbuffer_init(struct d3d9_vertexbuffer *buffer, struct d3d9_device *device,
UINT size, UINT usage, DWORD fvf, D3DPOOL pool)
{
+ const struct wined3d_parent_ops *parent_ops = &d3d9_null_wined3d_parent_ops;
struct wined3d_buffer_desc desc;
HRESULT hr;
@@ -299,15 +304,28 @@ HRESULT vertexbuffer_init(struct d3d9_vertexbuffer *buffer, struct d3d9_device *
desc.byte_width = size;
desc.usage = usage & WINED3DUSAGE_MASK;
- desc.bind_flags = WINED3D_BIND_VERTEX_BUFFER;
+ desc.bind_flags = 0;
desc.access = wined3daccess_from_d3dpool(pool, usage)
| WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W;
desc.misc_flags = 0;
desc.structure_byte_stride = 0;
+ if (desc.access & WINED3D_RESOURCE_ACCESS_GPU)
+ {
+ desc.bind_flags = WINED3D_BIND_VERTEX_BUFFER;
+ parent_ops = &d3d9_vertexbuffer_wined3d_parent_ops;
+ }
+
wined3d_mutex_lock();
- hr = wined3d_buffer_create(device->wined3d_device, &desc, NULL, buffer,
- &d3d9_vertexbuffer_wined3d_parent_ops, &buffer->wined3d_buffer);
+ hr = wined3d_buffer_create(device->wined3d_device, &desc, NULL, buffer, parent_ops, &buffer->wined3d_buffer);
+ if (SUCCEEDED(hr) && !(desc.access & WINED3D_RESOURCE_ACCESS_GPU))
+ {
+ desc.bind_flags = WINED3D_BIND_VERTEX_BUFFER;
+ desc.access = WINED3D_RESOURCE_ACCESS_GPU;
+ if (FAILED(hr = wined3d_buffer_create(device->wined3d_device, &desc, NULL, buffer,
+ &d3d9_vertexbuffer_wined3d_parent_ops, &buffer->draw_buffer)))
+ wined3d_buffer_decref(buffer->wined3d_buffer);
+ }
wined3d_mutex_unlock();
if (FAILED(hr))
{
diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h
index d6155eba60b..bd6409ffaf5 100644
--- a/dlls/d3d9/d3d9_private.h
+++ b/dlls/d3d9/d3d9_private.h
@@ -42,6 +42,7 @@
#define D3D9_MAX_VERTEX_SHADER_CONSTANTF 256
#define D3D9_MAX_TEXTURE_UNITS 20
+#define D3D9_MAX_STREAMS 16
#define D3DPRESENTFLAGS_MASK 0x00000fffu
@@ -102,9 +103,12 @@ struct d3d9_device
struct d3d9_surface *render_targets[D3D_MAX_SIMULTANEOUS_RENDERTARGETS];
LONG device_state;
- BOOL in_destruction;
- BOOL in_scene;
- BOOL has_vertex_declaration;
+ DWORD sysmem_vb : 16; /* D3D9_MAX_STREAMS */
+ DWORD in_destruction : 1;
+ DWORD in_scene : 1;
+ DWORD has_vertex_declaration : 1;
+ DWORD recording : 1;
+ DWORD padding : 12;
unsigned int max_user_clip_planes;
@@ -181,6 +185,7 @@ struct d3d9_vertexbuffer
struct d3d9_resource resource;
struct wined3d_buffer *wined3d_buffer;
IDirect3DDevice9Ex *parent_device;
+ struct wined3d_buffer *draw_buffer;
DWORD fvf;
};
diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
index f19e2ae6f65..ba84db9338f 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -974,6 +974,7 @@ static HRESULT d3d9_device_reset(struct d3d9_device *device,
if (!extended)
{
+ device->recording = FALSE;
wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZENABLE,
!!swapchain_desc.enable_auto_depth_stencil);
}
@@ -2317,7 +2318,8 @@ static HRESULT WINAPI d3d9_device_BeginStateBlock(IDirect3DDevice9Ex *iface)
TRACE("iface %p.\n", iface);
wined3d_mutex_lock();
- hr = wined3d_device_begin_stateblock(device->wined3d_device);
+ if (SUCCEEDED(hr = wined3d_device_begin_stateblock(device->wined3d_device)))
+ device->recording = TRUE;
wined3d_mutex_unlock();
return hr;
@@ -2340,6 +2342,7 @@ static HRESULT WINAPI d3d9_device_EndStateBlock(IDirect3DDevice9Ex *iface, IDire
WARN("Failed to end the state block, hr %#x.\n", hr);
return hr;
}
+ device->recording = FALSE;
if (!(object = heap_alloc_zero(sizeof(*object))))
{
@@ -2688,10 +2691,38 @@ static void d3d9_generate_auto_mipmaps(struct d3d9_device *device)
}
}
+static void d3d9_device_upload_sysmem_vertex_buffers(struct d3d9_device *device,
+ unsigned int start_vertex, unsigned int vertex_count)
+{
+ struct wined3d_box box = {0, 0, 0, 1, 0, 1};
+ struct d3d9_vertexbuffer *d3d9_buffer;
+ unsigned int i, offset, stride, map;
+ struct wined3d_buffer *dst_buffer;
+ HRESULT hr;
+
+ map = device->sysmem_vb;
+ while (map)
+ {
+ i = ffs(map) - 1;
+ map ^= 1u << i;
+
+ if (FAILED(hr = wined3d_device_get_stream_source(device->wined3d_device, i, &dst_buffer, &offset, &stride)))
+ ERR("Failed to get stream source.\n");
+ d3d9_buffer = wined3d_buffer_get_parent(dst_buffer);
+ box.left = offset + start_vertex * stride;
+ box.right = box.left + vertex_count * stride;
+ if (FAILED(hr = wined3d_device_copy_sub_resource_region(device->wined3d_device,
+ wined3d_buffer_get_resource(dst_buffer), 0, box.left, 0, 0,
+ wined3d_buffer_get_resource(d3d9_buffer->wined3d_buffer), 0, &box, 0)))
+ ERR("Failed to update buffer.\n");
+ }
+}
+
static HRESULT WINAPI d3d9_device_DrawPrimitive(IDirect3DDevice9Ex *iface,
D3DPRIMITIVETYPE primitive_type, UINT start_vertex, UINT primitive_count)
{
struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
+ unsigned int vertex_count;
HRESULT hr;
TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
@@ -2704,10 +2735,11 @@ static HRESULT WINAPI d3d9_device_DrawPrimitive(IDirect3DDevice9Ex *iface,
WARN("Called without a valid vertex declaration set.\n");
return D3DERR_INVALIDCALL;
}
+ vertex_count = vertex_count_from_primitive_count(primitive_type, primitive_count);
+ d3d9_device_upload_sysmem_vertex_buffers(device, start_vertex, vertex_count);
d3d9_generate_auto_mipmaps(device);
wined3d_device_set_primitive_type(device->wined3d_device, primitive_type, 0);
- hr = wined3d_device_draw_primitive(device->wined3d_device, start_vertex,
- vertex_count_from_primitive_count(primitive_type, primitive_count));
+ hr = wined3d_device_draw_primitive(device->wined3d_device, start_vertex, vertex_count);
if (SUCCEEDED(hr))
d3d9_rts_flag_auto_gen_mipmap(device);
wined3d_mutex_unlock();
@@ -2734,6 +2766,7 @@ static HRESULT WINAPI d3d9_device_DrawIndexedPrimitive(IDirect3DDevice9Ex *iface
WARN("Called without a valid vertex declaration set.\n");
return D3DERR_INVALIDCALL;
}
+ d3d9_device_upload_sysmem_vertex_buffers(device, min_vertex_idx, vertex_count);
d3d9_generate_auto_mipmaps(device);
wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_idx);
wined3d_device_set_primitive_type(device->wined3d_device, primitive_type, 0);
@@ -3378,6 +3411,7 @@ static HRESULT WINAPI d3d9_device_SetStreamSource(IDirect3DDevice9Ex *iface,
{
struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
struct d3d9_vertexbuffer *buffer_impl = unsafe_impl_from_IDirect3DVertexBuffer9(buffer);
+ struct wined3d_buffer *wined3d_buffer;
HRESULT hr;
TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
@@ -3386,14 +3420,28 @@ static HRESULT WINAPI d3d9_device_SetStreamSource(IDirect3DDevice9Ex *iface,
wined3d_mutex_lock();
if (!stride)
{
- struct wined3d_buffer *wined3d_buffer;
unsigned int cur_offset;
hr = wined3d_device_get_stream_source(device->wined3d_device, stream_idx, &wined3d_buffer,
&cur_offset, &stride);
}
- hr = wined3d_device_set_stream_source(device->wined3d_device, stream_idx,
- buffer_impl ? buffer_impl->wined3d_buffer : NULL, offset, stride);
+
+ if (!buffer_impl)
+ wined3d_buffer = NULL;
+ else if (buffer_impl->draw_buffer)
+ wined3d_buffer = buffer_impl->draw_buffer;
+ else
+ wined3d_buffer = buffer_impl->wined3d_buffer;
+
+ hr = wined3d_device_set_stream_source(device->wined3d_device, stream_idx, wined3d_buffer, offset, stride);
+ if (SUCCEEDED(hr) && !device->recording)
+ {
+ if (buffer_impl && buffer_impl->draw_buffer)
+ device->sysmem_vb |= (1u << stream_idx);
+ else
+ device->sysmem_vb &= ~(1u << stream_idx);
+ }
+
wined3d_mutex_unlock();
return hr;
diff --git a/dlls/d3d9/stateblock.c b/dlls/d3d9/stateblock.c
index 62b3bacb28d..440df0c1e1a 100644
--- a/dlls/d3d9/stateblock.c
+++ b/dlls/d3d9/stateblock.c
@@ -108,11 +108,28 @@ static HRESULT WINAPI d3d9_stateblock_Capture(IDirect3DStateBlock9 *iface)
static HRESULT WINAPI d3d9_stateblock_Apply(IDirect3DStateBlock9 *iface)
{
struct d3d9_stateblock *stateblock = impl_from_IDirect3DStateBlock9(iface);
+ struct wined3d_buffer *wined3d_buffer;
+ struct d3d9_vertexbuffer *buffer;
+ unsigned int i, offset, stride;
+ struct d3d9_device *device;
+ HRESULT hr;
TRACE("iface %p.\n", iface);
wined3d_mutex_lock();
wined3d_stateblock_apply(stateblock->wined3d_stateblock);
+ device = impl_from_IDirect3DDevice9Ex(stateblock->parent_device);
+ device->sysmem_vb = 0;
+ for (i = 0; i < D3D9_MAX_STREAMS; ++i)
+ {
+ if (FAILED(hr = wined3d_device_get_stream_source(device->wined3d_device,
+ i, &wined3d_buffer, &offset, &stride)))
+ continue;
+ if (!wined3d_buffer || !(buffer = wined3d_buffer_get_parent(wined3d_buffer)))
+ continue;
+ if (buffer->draw_buffer)
+ device->sysmem_vb |= 1u << i;
+ }
wined3d_mutex_unlock();
return D3D_OK;
--
2.11.0
2
1
17 Dec '18
It is no longer referenced in other source files.
Signed-off-by: Francois Gouget <fgouget(a)free.fr>
---
dlls/wined3d/utils.c | 2 +-
dlls/wined3d/wined3d_private.h | 1 -
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c
index aa68799535e..f8da256b07e 100644
--- a/dlls/wined3d/utils.c
+++ b/dlls/wined3d/utils.c
@@ -3971,7 +3971,7 @@ static void init_format_depth_bias_scale(struct wined3d_adapter *adapter,
}
}
-BOOL wined3d_adapter_init_format_info(struct wined3d_adapter *adapter, size_t format_size)
+static BOOL wined3d_adapter_init_format_info(struct wined3d_adapter *adapter, size_t format_size)
{
unsigned int count = WINED3D_FORMAT_COUNT + ARRAY_SIZE(typeless_depth_stencil_formats);
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 5a6715a5906..6e39db4fa86 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2707,7 +2707,6 @@ struct wined3d_caps_gl_ctx
GLuint test_program_id;
};
-BOOL wined3d_adapter_init_format_info(struct wined3d_adapter *adapter, size_t format_size) DECLSPEC_HIDDEN;
BOOL wined3d_adapter_gl_init_format_info(struct wined3d_adapter *adapter,
struct wined3d_caps_gl_ctx *ctx) DECLSPEC_HIDDEN;
BOOL wined3d_adapter_no3d_init_format_info(struct wined3d_adapter *adapter) DECLSPEC_HIDDEN;
--
2.19.2
2
1
I am using Boss Linux 7.0 64Bit which is using GNOME 3.22Wine is 1.8.7.FMSLogo 7.3.0 is 32bit
I am able to run FMSLogo using wine successfully.But i am not able to save the current logo file.When i try to save it, a file with the provided name is created, but with 0 bytes.
Anyone has faced saving file issue ?Anyway to debug ?
Thanks,B.Sathish Kumar
3
2