Wine-devel
Threads by month
- ----- 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
February 2020
- 80 participants
- 745 discussions
[PATCH 1/5] wined3d: Optimize scanning changed texture states in wined3d_device_apply_stateblock().
by Matteo Bruni 28 Feb '20
by Matteo Bruni 28 Feb '20
28 Feb '20
Signed-off-by: Matteo Bruni <mbruni(a)codeweavers.com>
---
dlls/wined3d/device.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index e706c830d31..9478c459e0a 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -3951,12 +3951,13 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device,
}
}
- for (i = 0; i < ARRAY_SIZE(state->texture_states); ++i)
+ for (i = 0; i < ARRAY_SIZE(changed->textureState); ++i)
{
- for (j = 0; j < ARRAY_SIZE(state->texture_states[i]); ++j)
+ map = changed->textureState[i];
+ while (map)
{
- if (changed->textureState[i] & (1u << j))
- wined3d_device_set_texture_stage_state(device, i, j, state->texture_states[i][j]);
+ j = wined3d_bit_scan(&map);
+ wined3d_device_set_texture_stage_state(device, i, j, state->texture_states[i][j]);
}
}
--
2.24.1
2
9
[PATCH 1/4] ddraw: Retrieve transform state from the primary stateblock.
by Zebediah Figura 28 Feb '20
by Zebediah Figura 28 Feb '20
28 Feb '20
Signed-off-by: Zebediah Figura <z.figura12(a)gmail.com>
---
dlls/ddraw/ddraw_private.h | 6 +++---
dlls/ddraw/device.c | 38 +++++++++++++++-----------------------
dlls/ddraw/executebuffer.c | 2 +-
dlls/ddraw/utils.c | 21 +++------------------
dlls/ddraw/viewport.c | 24 +++++++++---------------
5 files changed, 31 insertions(+), 60 deletions(-)
diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h
index 088092830c..42a7a85e4e 100644
--- a/dlls/ddraw/ddraw_private.h
+++ b/dlls/ddraw/ddraw_private.h
@@ -333,8 +333,7 @@ struct d3d_device
BOOL legacyTextureBlending;
D3DTEXTUREBLEND texture_map_blend;
- D3DMATRIX legacy_projection;
- D3DMATRIX legacy_clipspace;
+ struct wined3d_matrix legacy_projection, legacy_clipspace;
/* Light state */
DWORD material;
@@ -615,7 +614,8 @@ void DDRAW_dump_cooperativelevel(DWORD cooplevel) DECLSPEC_HIDDEN;
void DDSD_to_DDSD2(const DDSURFACEDESC *in, DDSURFACEDESC2 *out) DECLSPEC_HIDDEN;
void DDSD2_to_DDSD(const DDSURFACEDESC2 *in, DDSURFACEDESC *out) DECLSPEC_HIDDEN;
-void multiply_matrix(D3DMATRIX *dst, const D3DMATRIX *src1, const D3DMATRIX *src2) DECLSPEC_HIDDEN;
+void multiply_matrix(struct wined3d_matrix *dst, const struct wined3d_matrix *src1,
+ const struct wined3d_matrix *src2) DECLSPEC_HIDDEN;
static inline BOOL format_is_compressed(const DDPIXELFORMAT *format)
{
diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c
index 92c726c10d..ee860d4010 100644
--- a/dlls/ddraw/device.c
+++ b/dlls/ddraw/device.c
@@ -3173,15 +3173,15 @@ static HRESULT WINAPI d3d_device3_SetTransform(IDirect3DDevice3 *iface,
if (state == D3DTRANSFORMSTATE_PROJECTION)
{
- D3DMATRIX projection;
+ struct wined3d_matrix projection;
wined3d_mutex_lock();
- multiply_matrix(&projection, &device->legacy_clipspace, matrix);
+ multiply_matrix(&projection, &device->legacy_clipspace, (struct wined3d_matrix *)matrix);
wined3d_stateblock_set_transform(device->state,
WINED3D_TS_PROJECTION, (struct wined3d_matrix *)&projection);
wined3d_device_set_transform(device->wined3d_device,
WINED3D_TS_PROJECTION, (struct wined3d_matrix *)&projection);
- device->legacy_projection = *matrix;
+ memcpy(&device->legacy_projection, matrix, sizeof(*matrix));
wined3d_mutex_unlock();
return D3D_OK;
@@ -3247,7 +3247,7 @@ static HRESULT d3d_device7_GetTransform(IDirect3DDevice7 *iface,
/* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
wined3d_mutex_lock();
- wined3d_device_get_transform(device->wined3d_device, wined3d_state, (struct wined3d_matrix *)matrix);
+ memcpy(matrix, &wined3d_stateblock_get_state(device->state)->transforms[wined3d_state], sizeof(*matrix));
wined3d_mutex_unlock();
return D3D_OK;
@@ -3285,7 +3285,7 @@ static HRESULT WINAPI d3d_device3_GetTransform(IDirect3DDevice3 *iface,
if (state == D3DTRANSFORMSTATE_PROJECTION)
{
wined3d_mutex_lock();
- *matrix = device->legacy_projection;
+ memcpy(matrix, &device->legacy_projection, sizeof(*matrix));
wined3d_mutex_unlock();
return DD_OK;
}
@@ -3385,15 +3385,13 @@ static HRESULT WINAPI d3d_device3_MultiplyTransform(IDirect3DDevice3 *iface,
if (state == D3DTRANSFORMSTATE_PROJECTION)
{
- D3DMATRIX projection, tmp;
+ struct wined3d_matrix projection, tmp;
wined3d_mutex_lock();
- multiply_matrix(&tmp, &device->legacy_projection, matrix);
+ multiply_matrix(&tmp, &device->legacy_projection, (struct wined3d_matrix *)matrix);
multiply_matrix(&projection, &device->legacy_clipspace, &tmp);
- wined3d_stateblock_set_transform(device->state,
- WINED3D_TS_PROJECTION, (struct wined3d_matrix *)&projection);
- wined3d_device_set_transform(device->wined3d_device,
- WINED3D_TS_PROJECTION, (struct wined3d_matrix *)&projection);
+ wined3d_stateblock_set_transform(device->state, WINED3D_TS_PROJECTION, &projection);
+ wined3d_device_set_transform(device->wined3d_device, WINED3D_TS_PROJECTION, &projection);
device->legacy_projection = tmp;
wined3d_mutex_unlock();
@@ -4579,21 +4577,15 @@ static DWORD in_plane(UINT idx, struct wined3d_vec4 p, D3DVECTOR center, D3DVALU
static void prepare_clip_space_planes(struct d3d_device *device, struct wined3d_vec4 *plane)
{
- D3DMATRIX m, temp;
+ const struct wined3d_stateblock_state *state;
+ struct wined3d_matrix m;
/* We want the wined3d matrices since those include the legacy viewport
* transformation. */
wined3d_mutex_lock();
- wined3d_device_get_transform(device->wined3d_device,
- WINED3D_TS_WORLD, (struct wined3d_matrix *)&m);
-
- wined3d_device_get_transform(device->wined3d_device,
- WINED3D_TS_VIEW, (struct wined3d_matrix *)&temp);
- multiply_matrix(&m, &temp, &m);
-
- wined3d_device_get_transform(device->wined3d_device,
- WINED3D_TS_PROJECTION, (struct wined3d_matrix *)&temp);
- multiply_matrix(&m, &temp, &m);
+ state = wined3d_stateblock_get_state(device->state);
+ multiply_matrix(&m, &state->transforms[WINED3D_TS_VIEW], &state->transforms[WINED3D_TS_WORLD]);
+ multiply_matrix(&m, &state->transforms[WINED3D_TS_PROJECTION], &m);
wined3d_mutex_unlock();
/* Left plane. */
@@ -6991,7 +6983,7 @@ static void ddraw_reset_viewport_state(struct ddraw *ddraw)
static HRESULT d3d_device_init(struct d3d_device *device, struct ddraw *ddraw,
struct ddraw_surface *target, IUnknown *rt_iface, UINT version, IUnknown *outer_unknown)
{
- static const D3DMATRIX ident =
+ static const struct wined3d_matrix ident =
{
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
diff --git a/dlls/ddraw/executebuffer.c b/dlls/ddraw/executebuffer.c
index 1b680f627e..e0a9445bf7 100644
--- a/dlls/ddraw/executebuffer.c
+++ b/dlls/ddraw/executebuffer.c
@@ -205,7 +205,7 @@ HRESULT d3d_execute_buffer_execute(struct d3d_execute_buffer *buffer, struct d3d
for (i = 0; i < count; ++i)
{
D3DMATRIXMULTIPLY *ci = (D3DMATRIXMULTIPLY *)instr;
- D3DMATRIX *a, *b, *c;
+ struct wined3d_matrix *a, *b, *c;
a = ddraw_get_object(&device->handle_table, ci->hDestMatrix - 1, DDRAW_HANDLE_MATRIX);
b = ddraw_get_object(&device->handle_table, ci->hSrcMatrix1 - 1, DDRAW_HANDLE_MATRIX);
diff --git a/dlls/ddraw/utils.c b/dlls/ddraw/utils.c
index 2aa4cc2e88..23e75a32fc 100644
--- a/dlls/ddraw/utils.c
+++ b/dlls/ddraw/utils.c
@@ -1155,23 +1155,9 @@ void DDRAW_dump_DDCAPS(const DDCAPS *lpcaps)
TRACE(" - ddsCaps : "); DDRAW_dump_DDSCAPS2(&lpcaps->ddsCaps);
}
-/*****************************************************************************
- * multiply_matrix
- *
- * Multiplies 2 4x4 matrices src1 and src2, and stores the result in dest.
- *
- * Params:
- * dest: Pointer to the destination matrix
- * src1: Pointer to the first source matrix
- * src2: Pointer to the second source matrix
- *
- *****************************************************************************/
-void
-multiply_matrix(D3DMATRIX *dest,
- const D3DMATRIX *src1,
- const D3DMATRIX *src2)
+void multiply_matrix(struct wined3d_matrix *dst, const struct wined3d_matrix *src1, const struct wined3d_matrix *src2)
{
- D3DMATRIX temp;
+ struct wined3d_matrix temp;
/* Now do the multiplication 'by hand'.
I know that all this could be optimised, but this will be done later :-) */
@@ -1195,8 +1181,7 @@ multiply_matrix(D3DMATRIX *dest,
temp._34 = (src1->_14 * src2->_31) + (src1->_24 * src2->_32) + (src1->_34 * src2->_33) + (src1->_44 * src2->_34);
temp._44 = (src1->_14 * src2->_41) + (src1->_24 * src2->_42) + (src1->_34 * src2->_43) + (src1->_44 * src2->_44);
- /* And copy the new matrix in the good storage.. */
- memcpy(dest, &temp, 16 * sizeof(D3DVALUE));
+ *dst = temp;
}
HRESULT
diff --git a/dlls/ddraw/viewport.c b/dlls/ddraw/viewport.c
index 1b7f778699..2f2515036d 100644
--- a/dlls/ddraw/viewport.c
+++ b/dlls/ddraw/viewport.c
@@ -28,20 +28,18 @@ WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
static void update_clip_space(struct d3d_device *device,
struct wined3d_vec3 *scale, struct wined3d_vec3 *offset)
{
- D3DMATRIX clip_space =
+ struct wined3d_matrix clip_space =
{
scale->x, 0.0f, 0.0f, 0.0f,
0.0f, scale->y, 0.0f, 0.0f,
0.0f, 0.0f, scale->z, 0.0f,
offset->x, offset->y, offset->z, 1.0f,
};
- D3DMATRIX projection;
+ struct wined3d_matrix projection;
multiply_matrix(&projection, &clip_space, &device->legacy_projection);
- wined3d_stateblock_set_transform(device->state,
- WINED3D_TS_PROJECTION, (struct wined3d_matrix *)&projection);
- wined3d_device_set_transform(device->wined3d_device,
- WINED3D_TS_PROJECTION, (struct wined3d_matrix *)&projection);
+ wined3d_stateblock_set_transform(device->state, WINED3D_TS_PROJECTION, &projection);
+ wined3d_device_set_transform(device->wined3d_device, WINED3D_TS_PROJECTION, &projection);
device->legacy_clipspace = clip_space;
}
@@ -486,9 +484,10 @@ static HRESULT WINAPI d3d_viewport_TransformVertices(IDirect3DViewport3 *iface,
DWORD dwVertexCount, D3DTRANSFORMDATA *data, DWORD dwFlags, DWORD *offscreen)
{
struct d3d_viewport *viewport = impl_from_IDirect3DViewport3(iface);
+ const struct wined3d_stateblock_state *state;
D3DVIEWPORT vp = viewport->viewports.vp1;
- D3DMATRIX view_mat, world_mat, proj_mat, mat;
struct transform_vertices_vertex *in, *out;
+ struct wined3d_matrix mat;
float x, y, z, w;
unsigned int i;
D3DHVERTEX *outH;
@@ -522,14 +521,9 @@ static HRESULT WINAPI d3d_viewport_TransformVertices(IDirect3DViewport3 *iface,
if (activate)
viewport_activate(viewport, TRUE);
- wined3d_device_get_transform(device->wined3d_device,
- D3DTRANSFORMSTATE_VIEW, (struct wined3d_matrix *)&view_mat);
- wined3d_device_get_transform(device->wined3d_device,
- WINED3D_TS_WORLD_MATRIX(0), (struct wined3d_matrix *)&world_mat);
- wined3d_device_get_transform(device->wined3d_device,
- WINED3D_TS_PROJECTION, (struct wined3d_matrix *)&proj_mat);
- multiply_matrix(&mat, &view_mat, &world_mat);
- multiply_matrix(&mat, &proj_mat, &mat);
+ state = wined3d_stateblock_get_state(device->state);
+ multiply_matrix(&mat, &state->transforms[WINED3D_TS_VIEW], &state->transforms[WINED3D_TS_WORLD_MATRIX(0)]);
+ multiply_matrix(&mat, &state->transforms[WINED3D_TS_PROJECTION], &mat);
/* The pointer is not tested against NULL on Windows. */
if (dwFlags & D3DTRANSFORM_CLIPPED)
--
2.25.0
2
7
28 Feb '20
Signed-off-by: Nikolay Sivov <nsivov(a)codeweavers.com>
---
include/mferror.h | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/include/mferror.h b/include/mferror.h
index 6341d832ab..523800d7f0 100644
--- a/include/mferror.h
+++ b/include/mferror.h
@@ -166,4 +166,46 @@
#define MF_E_CLOCK_NOT_SIMPLE _HRESULT_TYPEDEF_(0xc00d9c43)
#define MF_S_CLOCK_STOPPED _HRESULT_TYPEDEF_(0x000d9c44)
+#define MF_E_NO_MORE_DROP_MODES _HRESULT_TYPEDEF_(0xc00da028)
+#define MF_E_NO_MORE_QUALITY_LEVELS _HRESULT_TYPEDEF_(0xc00da029)
+#define MF_E_DROPTIME_NOT_SUPPORTED _HRESULT_TYPEDEF_(0xc00da02a)
+#define MF_E_QUALITYKNOB_WAIT_LONGER _HRESULT_TYPEDEF_(0xc00da02b)
+#define MF_E_QM_INVALIDSTATE _HRESULT_TYPEDEF_(0xc00da02c)
+
+#define MF_E_TRANSCODE_NO_CONTAINERTYPE _HRESULT_TYPEDEF_(0xc00da410)
+#define MF_E_TRANSCODE_PROFILE_NO_MATCHING_STREAMS _HRESULT_TYPEDEF_(0xc00da411)
+#define MF_E_TRANSCODE_NO_MATCHING_ENCODER _HRESULT_TYPEDEF_(0xc00da412)
+#define MF_E_TRANSCODE_INVALID_PROFILE _HRESULT_TYPEDEF_(0xc00da413)
+
+#define MF_E_ALLOCATOR_NOT_INITIALIZED _HRESULT_TYPEDEF_(0xc00da7f8)
+#define MF_E_ALLOCATOR_NOT_COMMITED _HRESULT_TYPEDEF_(0xc00da7f9)
+#define MF_E_ALLOCATOR_ALREADY_COMMITED _HRESULT_TYPEDEF_(0xc00da7fa)
+#define MF_E_STREAM_ERROR _HRESULT_TYPEDEF_(0xc00da7fb)
+#define MF_E_INVALID_STREAM_STATE _HRESULT_TYPEDEF_(0xc00da7fc)
+#define MF_E_HW_STREAM_NOT_CONNECTED _HRESULT_TYPEDEF_(0xc00da7fd)
+
+#define MF_E_NO_CAPTURE_DEVICES_AVAILABLE _HRESULT_TYPEDEF_(0xc00dabe0)
+#define MF_E_CAPTURE_SINK_OUTPUT_NOT_SET _HRESULT_TYPEDEF_(0xc00dabe1)
+#define MF_E_CAPTURE_SINK_MIRROR_ERROR _HRESULT_TYPEDEF_(0xc00dabe2)
+#define MF_E_CAPTURE_SINK_ROTATE_ERROR _HRESULT_TYPEDEF_(0xc00dabe3)
+#define MF_E_CAPTURE_ENGINE_INVALID_OP _HRESULT_TYPEDEF_(0xc00dabe4)
+#define MF_E_CAPTURE_ENGINE_ALL_EFFECTS_REMOVED _HRESULT_TYPEDEF_(0xc00dabe5)
+#define MF_E_CAPTURE_SOURCE_NO_INDEPENDENT_PHOTO_STREAM_PRESENT _HRESULT_TYPEDEF_(0xc00dabe6)
+#define MF_E_CAPTURE_SOURCE_NO_VIDEO_STREAM_PRESENT _HRESULT_TYPEDEF_(0xc00dabe7)
+#define MF_E_CAPTURE_SOURCE_NO_AUDIO_STREAM_PRESENT _HRESULT_TYPEDEF_(0xc00dabe8)
+#define MF_E_CAPTURE_SOURCE_DEVICE_EXTENDEDPROP_OP_IN_PROGRESS _HRESULT_TYPEDEF_(0xc00dabe9)
+#define MF_E_CAPTURE_PROPERTY_SET_DURING_PHOTO _HRESULT_TYPEDEF_(0xc00dabea)
+#define MF_E_CAPTURE_NO_SAMPLES_IN_QUEUE _HRESULT_TYPEDEF_(0xc00dabeb)
+#define MF_E_HW_ACCELERATED_THUMBNAIL_NOT_SUPPORTED _HRESULT_TYPEDEF_(0xc00dabec)
+#define MF_E_UNSUPPORTED_CAPTURE_DEVICE_PRESENT _HRESULT_TYPEDEF_(0xc00dabed)
+
+#define MF_E_TIMELINECONTROLLER_UNSUPPORTED_SOURCE_TYPE _HRESULT_TYPEDEF_(0xc00dafc8)
+#define MF_E_TIMELINECONTROLLER_NOT_ALLOWED _HRESULT_TYPEDEF_(0xc00dafc9)
+#define MF_E_TIMELINECONTROLLER_CANNOT_ATTACH _HRESULT_TYPEDEF_(0xc00dafca)
+
+#define MF_E_MEDIA_EXTENSION_APPSERVICE_CONNECTION_FAILED _HRESULT_TYPEDEF_(0xc00db3b0)
+#define MF_E_MEDIA_EXTENSION_APPSERVICE_REQUEST_FAILED _HRESULT_TYPEDEF_(0xc00db3b1)
+#define MF_E_MEDIA_EXTENSION_PACKAGE_INTEGRITY_CHECK_FAILED _HRESULT_TYPEDEF_(0xc00db3b2)
+#define MF_E_MEDIA_EXTENSION_PACKAGE_LICENSE_INVALID _HRESULT_TYPEDEF_(0xc00db3b3)
+
#endif /* __WINE_MFERROR_H */
--
2.25.0
1
13
[PATCH 1/3] d3dcompiler/tests: Rewrite to use a separate d3d9 device for each test.
by Matteo Bruni 28 Feb '20
by Matteo Bruni 28 Feb '20
28 Feb '20
From: Zebediah Figura <z.figura12(a)gmail.com>
This brings the d3dcompiler tests more in line with existing d3d9 tests, and
allows potentially running the tests in parallel.
Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni(a)codeweavers.com>
---
dlls/d3dcompiler_43/tests/Makefile.in | 2 +-
dlls/d3dcompiler_43/tests/hlsl.c | 701 --------------------------
dlls/d3dcompiler_43/tests/hlsl_d3d9.c | 678 +++++++++++++++++++++++++
dlls/d3dcompiler_47/tests/Makefile.in | 2 +-
4 files changed, 680 insertions(+), 703 deletions(-)
delete mode 100644 dlls/d3dcompiler_43/tests/hlsl.c
create mode 100644 dlls/d3dcompiler_43/tests/hlsl_d3d9.c
diff --git a/dlls/d3dcompiler_43/tests/Makefile.in b/dlls/d3dcompiler_43/tests/Makefile.in
index 51b1f934836..f00d8560826 100644
--- a/dlls/d3dcompiler_43/tests/Makefile.in
+++ b/dlls/d3dcompiler_43/tests/Makefile.in
@@ -5,5 +5,5 @@ EXTRADEFS = -DD3D_COMPILER_VERSION=43
C_SRCS = \
asm.c \
blob.c \
- hlsl.c \
+ hlsl_d3d9.c \
reflection.c
diff --git a/dlls/d3dcompiler_43/tests/hlsl.c b/dlls/d3dcompiler_43/tests/hlsl.c
deleted file mode 100644
index 868693838cc..00000000000
--- a/dlls/d3dcompiler_43/tests/hlsl.c
+++ /dev/null
@@ -1,701 +0,0 @@
-/*
- * Copyright (C) 2010 Travis Athougies
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
-#define COBJMACROS
-#include "wine/test.h"
-#include "d3dx9.h"
-#include "d3dcompiler.h"
-
-#include <math.h>
-
-static pD3DCompile ppD3DCompile;
-
-static HRESULT (WINAPI *pD3DXGetShaderConstantTable)(const DWORD *byte_code, ID3DXConstantTable **constant_table);
-static D3DMATRIX *(WINAPI *pD3DXMatrixOrthoLH)(D3DXMATRIX *pout, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf);
-
-struct vertex
-{
- float x, y, z;
- float tx, ty;
-};
-
-/* Tells compute_shader_probe* which pixels should be what colors */
-struct hlsl_probe_info
-{
- unsigned int x, y;
- /* The expected values in this region */
- D3DXCOLOR c;
- /* The max error for any value */
- float epsilon;
- /* An error message to print if this test fails */
- const char *message;
-};
-
-static HWND create_window(void)
-{
- WNDCLASSA wc = {0};
- wc.lpfnWndProc = DefWindowProcA;
- wc.lpszClassName = "d3d9_test_wc";
- RegisterClassA(&wc);
-
- return CreateWindowA("d3d9_test_wc", "d3d9_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
-}
-
-static IDirect3DDevice9 *init_d3d9(IDirect3DVertexDeclaration9 **vdeclaration,
- IDirect3DVertexBuffer9 **quad_geometry, IDirect3DVertexShader9 **vshader_passthru)
-{
- static const struct vertex quad_vertices[4] =
- {
- {-1.0f, -1.0f, 0.0f, 0.0f, 1.0f},
- {-1.0f, 1.0f, 0.0f, 0.0f, 0.0f},
- { 1.0f, -1.0f, 0.0f, 1.0f, 1.0f},
- { 1.0f, 1.0f, 0.0f, 1.0f, 0.0f}
- };
-
- static const D3DVERTEXELEMENT9 vdeclelements[] =
- {
- {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
- {0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
- D3DDECL_END()
- };
-
- static const char *vshader_passthru_hlsl =
- "float4 vshader(float4 pos: POSITION, inout float2 texcoord: TEXCOORD0): POSITION\n"
- "{\n"
- " return pos;\n"
- "}";
-
- IDirect3D9 *d3d9_ptr;
- IDirect3DDevice9 *device_ptr = NULL;
- D3DPRESENT_PARAMETERS present_parameters;
-
- void *temp_geometry_vertices;
-
- ID3D10Blob *compiled = NULL;
- ID3D10Blob *errors = NULL;
-
- HRESULT hr;
-
- d3d9_ptr = Direct3DCreate9(D3D_SDK_VERSION);
- if (!d3d9_ptr)
- {
- skip("could not create D3D9\n");
- return NULL;
- }
-
- hr = IDirect3D9_CheckDeviceFormat(d3d9_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
- 0, D3DRTYPE_SURFACE, D3DFMT_A32B32G32R32F);
- if (FAILED(hr))
- {
- skip("A32B32G32R32F format not available on this device\n");
- IDirect3D9_Release(d3d9_ptr);
- return NULL;
- }
-
- ZeroMemory(&present_parameters, sizeof(present_parameters));
- present_parameters.Windowed = TRUE;
- present_parameters.hDeviceWindow = create_window();
- present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
-
- hr = IDirect3D9_CreateDevice(d3d9_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL,
- D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device_ptr);
- IDirect3D9_Release(d3d9_ptr);
- if (FAILED(hr))
- {
- skip("could not create Direct3D9 device\n");
- return NULL;
- }
-
- /* Create the quad geometry */
- hr = IDirect3DDevice9_CreateVertexBuffer(device_ptr, 4 * sizeof(struct vertex),
- D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, quad_geometry, NULL);
- ok(SUCCEEDED(hr),
- "Could not create vertex buffer, IDirect3DDevice9_CreateVertexBuffer returned: %08x\n", hr);
-
- hr = IDirect3DVertexBuffer9_Lock(*quad_geometry, 0, sizeof(quad_vertices), &temp_geometry_vertices, 0);
- ok(SUCCEEDED(hr), "IDirect3DVertexBuffer9_Lock returned: %08x\n", hr);
- memcpy(temp_geometry_vertices, quad_vertices, sizeof(quad_vertices));
- IDirect3DVertexBuffer9_Unlock(*quad_geometry);
-
- hr = IDirect3DDevice9_CreateVertexDeclaration(device_ptr, vdeclelements, vdeclaration);
- ok(SUCCEEDED(hr), "Could not create vertex declaration: "
- "IDirect3DDevice9_CreateVertexDeclaration returned: %08x\n", hr);
-
- hr = IDirect3DDevice9_SetVertexDeclaration(device_ptr, *vdeclaration);
- ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexDeclaration returned: %08x\n", hr);
-
- /* Create a simple vertex shader to just pass through the values */
- hr = ppD3DCompile(vshader_passthru_hlsl, strlen(vshader_passthru_hlsl), NULL,
- NULL, NULL, "vshader", "vs_1_1", 0, 0, &compiled, &errors);
- if (FAILED(hr))
- {
- skip("not compiling vertex shader due to lacking wine HLSL support!\n");
- if (errors)
- ID3D10Blob_Release(errors);
- return NULL;
- }
-
- hr = IDirect3DDevice9_CreateVertexShader(device_ptr, ID3D10Blob_GetBufferPointer(compiled),
- vshader_passthru);
- ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateVertexShader returned: %08x\n", hr);
- ID3D10Blob_Release(compiled);
-
- return device_ptr;
-}
-
-/* Convenience functions */
-static void set_float4_d3d9(IDirect3DDevice9 *device, ID3DXConstantTable *constants, const char *name,
- float x, float y, float z, float w)
-{
- D3DXVECTOR4 vector;
- vector.x = x;
- vector.y = y;
- vector.z = z;
- vector.w = w;
- ID3DXConstantTable_SetVector(constants, device, name, &vector);
-}
-
-/* Compile our pixel shader and get back the compiled version and a constant table */
-static IDirect3DPixelShader9 *compile_pixel_shader9(IDirect3DDevice9 *device, const char *shader,
- const char *profile, ID3DXConstantTable **constants)
-{
- ID3D10Blob *compiled = NULL;
- ID3D10Blob *errors = NULL;
- IDirect3DPixelShader9 *pshader;
- HRESULT hr;
-
- hr = ppD3DCompile(shader, strlen(shader), NULL, NULL,
- NULL, "test", profile, /* test is the name of the entry point of our shader */
- 0, 0, &compiled, &errors);
- ok(hr == D3D_OK, "Pixel shader %s compilation failed: %s\n", shader,
- errors ? (char *)ID3D10Blob_GetBufferPointer(errors) : "");
- if (FAILED(hr)) return NULL;
-
- hr = pD3DXGetShaderConstantTable(ID3D10Blob_GetBufferPointer(compiled), constants);
- ok(hr == D3D_OK, "Could not get constant table from compiled pixel shader\n");
-
- hr = IDirect3DDevice9_CreatePixelShader(device, ID3D10Blob_GetBufferPointer(compiled), &pshader);
- ok(SUCCEEDED(hr), "IDirect3DDevice9_CreatePixelShader returned: %08x\n", hr);
- ID3D10Blob_Release(compiled);
- return pshader;
-}
-
-/* Draw a full screen quad */
-static void draw_quad_with_shader9(IDirect3DDevice9 *device, IDirect3DVertexBuffer9 *quad_geometry)
-{
- HRESULT hr;
- D3DXMATRIX projection_matrix;
-
- pD3DXMatrixOrthoLH(&projection_matrix, 2.0f, 2.0f, 0.0f, 1.0f);
- IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, &projection_matrix);
-
- hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
- ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned: %08x\n", hr);
-
- hr = IDirect3DDevice9_BeginScene(device);
- ok(hr == D3D_OK, "IDirect3DDevice9_BeginScene returned: %08x\n", hr);
-
- hr = IDirect3DDevice9_SetStreamSource(device, 0, quad_geometry, 0, sizeof(struct vertex));
- ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSource returned: %08x\n", hr);
- hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 2);
- ok(hr == D3D_OK, "IDirect3DDevice9_DrawPrimitive returned: %08x\n", hr);
-
- hr = IDirect3DDevice9_EndScene(device);
- ok(hr == D3D_OK, "IDirect3DDevice9_EndScene returned: %08x\n", hr);
-}
-
-static void setup_device9(IDirect3DDevice9 *device, IDirect3DSurface9 **render_target,
- IDirect3DSurface9 **readback, D3DFORMAT format, unsigned int width, unsigned int height,
- IDirect3DVertexShader9 *vshader, IDirect3DPixelShader9 *pshader)
-{
- HRESULT hr;
- hr = IDirect3DDevice9_CreateRenderTarget(device, width, height, format,
- D3DMULTISAMPLE_NONE, 0, FALSE, render_target, NULL);
- ok(hr == D3D_OK, "IDirect3DDevice9_CreateRenderTarget returned: %08x\n", hr);
-
- /* The Direct3D 9 docs state that we cannot lock a render target surface,
- instead we must copy the render target onto this surface to lock it */
- hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, width, height, format,
- D3DPOOL_SYSTEMMEM, readback, NULL);
- ok(hr == D3D_OK, "IDirect3DDevice9_CreateOffscreenPlainSurface returned: %08x\n", hr);
-
- hr = IDirect3DDevice9_SetRenderTarget(device, 0, *render_target);
- ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderTarget returned: %08x\n", hr);
-
- hr = IDirect3DDevice9_SetVertexShader(device, vshader);
- ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShader returned: %08x\n", hr);
- hr = IDirect3DDevice9_SetPixelShader(device, pshader);
- ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader returned: %08x\n", hr);
-}
-
-static BOOL colors_match(D3DXCOLOR a, D3DXCOLOR b, float epsilon)
-{
- return (fabs(a.r - b.r) < epsilon && fabs(a.g - b.g) < epsilon && fabs(a.b - b.b) < epsilon &&
- fabs(a.a - b.a) < epsilon);
-}
-
-/* Compute a shader on a width by height buffer and probes certain locations
- to see if they are as expected. */
-static void compute_shader_probe9(IDirect3DDevice9 *device, IDirect3DVertexShader9 *vshader,
- IDirect3DPixelShader9 *pshader, IDirect3DVertexBuffer9 *quad_geometry,
- const struct hlsl_probe_info *probes, unsigned int count,
- unsigned int width, unsigned int height, unsigned int line_number)
-{
- IDirect3DSurface9 *render_target;
- IDirect3DSurface9 *readback;
-
- HRESULT hr;
- D3DLOCKED_RECT lr;
- D3DXCOLOR *pbits_data;
- unsigned int i;
-
- setup_device9(device, &render_target, &readback, D3DFMT_A32B32G32R32F,
- width, height, vshader, pshader);
-
- /* Draw the quad with the shader and read back the data */
- draw_quad_with_shader9(device, quad_geometry);
- IDirect3DDevice9_GetRenderTargetData(device, render_target, readback);
- hr = IDirect3DSurface9_LockRect(readback, &lr, NULL, D3DLOCK_READONLY);
- ok(hr == D3D_OK, "IDirect3DSurface9_LockRect returned: %08x\n", hr);
- pbits_data = lr.pBits;
-
- /* Now go through the probes and check each one */
- for (i = 0; i < count; i++, probes++) {
- int index = probes->x + (probes->y * lr.Pitch / sizeof(D3DXCOLOR));
- ok(colors_match(probes->c, pbits_data[index], probes->epsilon),
- "Line %d: At (%d, %d): %s: Expected (%.04f,%.04f,%.04f, %.04f), got "
- "(%.04f,%.04f,%.04f,%.04f)\n", line_number, probes->x, probes->y, probes->message,
- probes->c.r, probes->c.g, probes->c.b, probes->c.a, pbits_data[index].r,
- pbits_data[index].g, pbits_data[index].b, pbits_data[index].a);
- }
-
- hr = IDirect3DSurface9_UnlockRect(readback);
- ok(hr == D3D_OK, "IDirect3DSurface9_UnlockRect returned: %08x\n", hr);
-
- /* We now present the scene. This is mostly for debugging purposes, since GetRenderTargetData
- also waits for drawing commands to complete. The reason this call is here and not in a
- draw function is because the contents of the render target surface are invalidated after
- this call. */
- hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
- ok(hr == D3D_OK, "IDirect3DDevice9_Present returned: %08x\n", hr);
-
- IDirect3DSurface9_Release(render_target);
- IDirect3DSurface9_Release(readback);
-}
-
-/* Now the actual test functions */
-static void test_swizzle(IDirect3DDevice9 *device, IDirect3DVertexBuffer9 *quad_geometry,
- IDirect3DVertexShader9 *vshader_passthru)
-{
- static const struct hlsl_probe_info probes[] =
- {
- {0, 0, {0.0101f, 0.0303f, 0.0202f, 0.0404f}, 0.0001f, "swizzle_test"}
- };
-
- static const char *swizzle_test_shader =
- "uniform float4 color;\n"
- "float4 test(): COLOR\n"
- "{\n"
- " float4 ret = color;\n"
- " ret.gb = ret.ra;\n"
- " ret.ra = float2(0.0101, 0.0404);\n"
- " return ret;\n"
- "}";
-
- ID3DXConstantTable *constants;
- IDirect3DPixelShader9 *pshader;
-
- pshader = compile_pixel_shader9(device, swizzle_test_shader, "ps_2_0", &constants);
- if (pshader != NULL)
- {
- set_float4_d3d9(device, constants, "color", 0.0303f, 0.0f, 0.0f, 0.0202f);
-
- compute_shader_probe9(device, vshader_passthru, pshader, quad_geometry,
- probes, ARRAY_SIZE(probes), 1, 1, __LINE__);
-
- ID3DXConstantTable_Release(constants);
- IDirect3DPixelShader9_Release(pshader);
- }
-}
-
-static void test_math(IDirect3DDevice9 *device, IDirect3DVertexBuffer9 *quad_geometry,
- IDirect3DVertexShader9 *vshader_passthru)
-{
- /* Tests order of operations */
- static const float u = 2.5f, v = 0.3f, w = 0.2f, x = 0.7f, y = 0.1f, z = 1.5f;
-
- static const struct hlsl_probe_info probes[] =
- {
- {0, 0, {-12.4300f, 9.8333f, 1.6000f, 34.9999f}, 0.0001f,
- "order of operations test"}
- };
-
- static const char *order_of_operations_shader =
- "float4 test(uniform float u, uniform float v, uniform float w, uniform float x,\n"
- " uniform float y, uniform float z): COLOR\n"
- "{\n"
- " return float4(x * y - z / w + --u / -v,\n"
- " z * x / y + w / -v,\n"
- " u + v - w,\n"
- " x / y / w);\n"
- "}";
-
- ID3DXConstantTable *constants;
- IDirect3DPixelShader9 *pshader;
-
- pshader = compile_pixel_shader9(device, order_of_operations_shader, "ps_2_0", &constants);
- if (pshader != NULL)
- {
- ID3DXConstantTable_SetFloat(constants, device, "$u", u);
- ID3DXConstantTable_SetFloat(constants, device, "$v", v);
- ID3DXConstantTable_SetFloat(constants, device, "$w", w);
- ID3DXConstantTable_SetFloat(constants, device, "$x", x);
- ID3DXConstantTable_SetFloat(constants, device, "$y", y);
- ID3DXConstantTable_SetFloat(constants, device, "$z", z);
-
- compute_shader_probe9(device, vshader_passthru, pshader, quad_geometry,
- probes, ARRAY_SIZE(probes), 1, 1, __LINE__);
-
- ID3DXConstantTable_Release(constants);
- IDirect3DPixelShader9_Release(pshader);
- }
-}
-
-static void test_conditionals(IDirect3DDevice9 *device, IDirect3DVertexBuffer9 *quad_geometry,
- IDirect3DVertexShader9 *vshader_passthru)
-{
- static const struct hlsl_probe_info if_greater_probes[] =
- {
- { 0, 0, {0.9f, 0.8f, 0.7f, 0.6f}, 0.0001f, "if greater test"},
- { 5, 0, {0.9f, 0.8f, 0.7f, 0.6f}, 0.0001f, "if greater test"},
- {10, 0, {0.9f, 0.8f, 0.7f, 0.6f}, 0.0001f, "if greater test"},
- {15, 0, {0.9f, 0.8f, 0.7f, 0.6f}, 0.0001f, "if greater test"},
- {25, 0, {0.1f, 0.2f, 0.3f, 0.4f}, 0.0001f, "if greater test"},
- {30, 0, {0.1f, 0.2f, 0.3f, 0.4f}, 0.0001f, "if greater test"}
- };
-
- static const char *if_greater_shader =
- "float4 test(float2 pos: TEXCOORD0): COLOR\n"
- "{\n"
- " if((pos.x * 32.0) > 20.0)\n"
- " return float4(0.1, 0.2, 0.3, 0.4);\n"
- " else\n"
- " return float4(0.9, 0.8, 0.7, 0.6);\n"
- "}";
-
- static const struct hlsl_probe_info ternary_operator_probes[] =
- {
- {0, 0, {0.50f, 0.25f, 0.50f, 0.75f}, 0.00001f, "ternary operator test"},
- {1, 0, {0.50f, 0.25f, 0.50f, 0.75f}, 0.00001f, "ternary operator test"},
- {2, 0, {0.50f, 0.25f, 0.50f, 0.75f}, 0.00001f, "ternary operator test"},
- {3, 0, {0.50f, 0.25f, 0.50f, 0.75f}, 0.00001f, "ternary operator test"},
- {4, 0, {0.60f, 0.80f, 0.10f, 0.20f}, 0.00001f, "ternary operator test"},
- {5, 0, {0.60f, 0.80f, 0.10f, 0.20f}, 0.00001f, "ternary operator test"},
- {6, 0, {0.60f, 0.80f, 0.10f, 0.20f}, 0.00001f, "ternary operator test"},
- {7, 0, {0.60f, 0.80f, 0.10f, 0.20f}, 0.00001f, "ternary operator test"}
- };
-
- static const char *ternary_operator_shader =
- "float4 test(float2 pos: TEXCOORD0): COLOR\n"
- "{\n"
- " return (pos.x < 0.5?float4(0.5, 0.25, 0.5, 0.75):float4(0.6, 0.8, 0.1, 0.2));\n"
- "}";
-
- ID3DXConstantTable *constants;
- IDirect3DPixelShader9 *pshader;
-
- pshader = compile_pixel_shader9(device, if_greater_shader, "ps_2_0", &constants);
- if (pshader != NULL)
- {
- compute_shader_probe9(device, vshader_passthru, pshader, quad_geometry, if_greater_probes,
- ARRAY_SIZE(if_greater_probes), 32, 1, __LINE__);
-
- ID3DXConstantTable_Release(constants);
- IDirect3DPixelShader9_Release(pshader);
- }
-
- pshader = compile_pixel_shader9(device, ternary_operator_shader, "ps_2_0", &constants);
- if (pshader != NULL)
- {
- compute_shader_probe9(device, vshader_passthru, pshader, quad_geometry, ternary_operator_probes,
- ARRAY_SIZE(ternary_operator_probes), 8, 1, __LINE__);
-
- ID3DXConstantTable_Release(constants);
- IDirect3DPixelShader9_Release(pshader);
- }
-}
-
-static void test_float_vectors(IDirect3DDevice9 *device, IDirect3DVertexBuffer9 *quad_geometry,
- IDirect3DVertexShader9 *vshader_passthru)
-{
- static const struct hlsl_probe_info vec4_indexing_test1_probes[] =
- {
- {0, 0, {0.020f, 0.245f, 0.351f, 1.000f}, 0.0001f, "vec4 indexing test 1"}
- };
-
- static const char *vec4_indexing_test1_shader =
- "float4 test(): COLOR\n"
- "{\n"
- " float4 color;\n"
- " color[0] = 0.020;\n"
- " color[1] = 0.245;\n"
- " color[2] = 0.351;\n"
- " color[3] = 1.0;\n"
- " return color;\n"
- "}";
-
- static const struct hlsl_probe_info vec4_indexing_test2_probes[] =
- {
- {0, 0, {0.5f, 0.3f, 0.8f, 0.2f}, 0.0001f, "vec4 indexing test 2"}
- };
-
- /* We have this uniform i here so the compiler can't optimize */
- static const char *vec4_indexing_test2_shader =
- "uniform int i;\n"
- "float4 test(): COLOR\n"
- "{\n"
- " float4 color = float4(0.5, 0.4, 0.3, 0.2);\n"
- " color.g = color[i];\n"
- " color.b = 0.8;\n"
- " return color;\n"
- "}";
-
- ID3DXConstantTable *constants;
- IDirect3DPixelShader9 *pshader;
-
- pshader = compile_pixel_shader9(device, vec4_indexing_test1_shader, "ps_2_0", &constants);
- if (pshader != NULL)
- {
- compute_shader_probe9(device, vshader_passthru, pshader, quad_geometry, vec4_indexing_test1_probes,
- ARRAY_SIZE(vec4_indexing_test1_probes), 1, 1, __LINE__);
-
- ID3DXConstantTable_Release(constants);
- IDirect3DPixelShader9_Release(pshader);
- }
-
- pshader = compile_pixel_shader9(device, vec4_indexing_test2_shader, "ps_2_0", &constants);
- if (pshader != NULL)
- {
- ID3DXConstantTable_SetInt(constants, device, "i", 2);
-
- compute_shader_probe9(device, vshader_passthru, pshader, quad_geometry, vec4_indexing_test2_probes,
- ARRAY_SIZE(vec4_indexing_test2_probes), 32, 1, __LINE__);
-
- ID3DXConstantTable_Release(constants);
- IDirect3DPixelShader9_Release(pshader);
- }
-}
-
-static void test_trig(IDirect3DDevice9 *device, IDirect3DVertexBuffer9 *quad_geometry,
- IDirect3DVertexShader9 *vshader_passthru)
-{
- static const struct hlsl_probe_info sincos_probes[] =
- {
- {0, 0, {0.5000f, 1.0000f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {1, 0, {0.5975f, 0.9904f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {2, 0, {0.6913f, 0.9620f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {3, 0, {0.7778f, 0.9160f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {4, 0, {0.8536f, 0.8536f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {5, 0, {0.9157f, 0.7778f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {6, 0, {0.9620f, 0.6913f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {7, 0, {0.9904f, 0.5975f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {8, 0, {1.0000f, 0.5000f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {9, 0, {0.9904f, 0.4025f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {10, 0, {0.9619f, 0.3087f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {11, 0, {0.9157f, 0.2222f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {12, 0, {0.8536f, 0.1464f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {13, 0, {0.7778f, 0.0843f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {14, 0, {0.6913f, 0.0381f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {15, 0, {0.5975f, 0.0096f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {16, 0, {0.5000f, 0.0000f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {17, 0, {0.4025f, 0.0096f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {18, 0, {0.3087f, 0.0381f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {19, 0, {0.2222f, 0.0843f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {20, 0, {0.1464f, 0.1464f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {21, 0, {0.0843f, 0.2222f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {22, 0, {0.0381f, 0.3087f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {23, 0, {0.0096f, 0.4025f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {24, 0, {0.0000f, 0.5000f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {25, 0, {0.0096f, 0.5975f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {26, 0, {0.0381f, 0.6913f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {27, 0, {0.0843f, 0.7778f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {28, 0, {0.1464f, 0.8536f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {29, 0, {0.2222f, 0.9157f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {30, 0, {0.3087f, 0.9619f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {31, 0, {0.4025f, 0.9904f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- };
-
- static const char *sincos_shader =
- "float4 test(float x: TEXCOORD0): COLOR\n"
- "{\n"
- " const float pi2 = 6.2831853;\n"
- " float calcd_sin = (sin(x * pi2) + 1)/2;\n"
- " float calcd_cos = (cos(x * pi2) + 1)/2;\n"
- " return float4(calcd_sin, calcd_cos, 0, 0);\n"
- "}";
-
- ID3DXConstantTable *constants;
- IDirect3DPixelShader9 *pshader;
-
- pshader = compile_pixel_shader9(device, sincos_shader, "ps_2_0", &constants);
- if (pshader != NULL)
- {
- compute_shader_probe9(device, vshader_passthru, pshader, quad_geometry, sincos_probes,
- ARRAY_SIZE(sincos_probes), 32, 1, __LINE__);
-
- ID3DXConstantTable_Release(constants);
- IDirect3DPixelShader9_Release(pshader);
- }
-}
-
-static void test_fail(IDirect3DDevice9 *device, IDirect3DVertexBuffer9 *qquad_geometry,
- IDirect3DVertexShader9 *vshader_passthru)
-{
- static const char *tests[] =
- {
- "float4 test(float2 pos: TEXCOORD0) : COLOR\n"
- "{\n"
- " return y;\n"
- "}",
-
- "float4 test(float2 pos: TEXCOORD0) : COLOR\n"
- "{\n"
- " float4 x = float4(0, 0, 0, 0);\n"
- " x.xzzx = float4(1, 2, 3, 4);\n"
- " return x;\n"
- "}",
-
- "float4 test(float2 pos: TEXCOORD0) : COLOR\n"
- "{\n"
- " float4 x = pos;\n"
- " return x;\n"
- "}",
-
- "float4 test(float2 pos, TEXCOORD0) ; COLOR\n"
- "{\n"
- " pos = float4 x;\n"
- " mul(float4(5, 4, 3, 2), mvp) = x;\n"
- " return float4;\n"
- "}",
-
- "float4 563r(float2 45s: TEXCOORD0) : COLOR\n"
- "{\n"
- " float2 x = 45s;\n"
- " return float4(x.x, x.y, 0, 0);\n"
- "}",
-
- "float4 test(float2 pos: TEXCOORD0) : COLOR\n"
- "{\n"
- " struct { int b,c; } x = {0};\n"
- " return y;\n"
- "}",
-
- "float4 test(float2 pos: TEXCOORD0) : COLOR\n"
- "{\n"
- " struct {} x = {};\n"
- " return y;\n"
- "}",
- };
-
- ID3D10Blob *compiled, *errors;
- unsigned int i;
- HRESULT hr;
-
- for (i = 0; i < ARRAY_SIZE(tests); ++i)
- {
- compiled = errors = NULL;
- hr = ppD3DCompile(tests[i], strlen(tests[i]), NULL, NULL, NULL, "test", "ps_2_0", 0, 0, &compiled, &errors);
- ok(hr == E_FAIL, "Test %u, got unexpected hr %#x.\n", i, hr);
- ok(!!errors, "Test %u, expected non-NULL error blob.\n", i);
- ok(!compiled, "Test %u, expected no compiled shader blob.\n", i);
- ID3D10Blob_Release(errors);
- }
-}
-
-static BOOL load_d3dcompiler(void)
-{
- HMODULE module;
-
-#if D3D_COMPILER_VERSION == 47
- if (!(module = LoadLibraryA("d3dcompiler_47.dll"))) return FALSE;
-#else
- if (!(module = LoadLibraryA("d3dcompiler_43.dll"))) return FALSE;
-#endif
-
- ppD3DCompile = (void*)GetProcAddress(module, "D3DCompile");
- return TRUE;
-}
-
-START_TEST(hlsl)
-{
- D3DCAPS9 caps;
- ULONG refcount;
- IDirect3DDevice9 *device;
- IDirect3DVertexDeclaration9 *vdeclaration;
- IDirect3DVertexBuffer9 *quad_geometry;
- IDirect3DVertexShader9 *vshader_passthru;
- HMODULE mod;
-
- if (!load_d3dcompiler())
- {
- win_skip("Could not load DLL.\n");
- return;
- }
-
- if (!(mod = LoadLibraryA("d3dx9_36.dll")))
- {
- win_skip("Failed to load d3dx9_36.dll.\n");
- return;
- }
- pD3DXGetShaderConstantTable = (void *)GetProcAddress(mod, "D3DXGetShaderConstantTable");
- pD3DXMatrixOrthoLH = (void *)GetProcAddress(mod, "D3DXMatrixOrthoLH");
-
- device = init_d3d9(&vdeclaration, &quad_geometry, &vshader_passthru);
- if (!device) return;
-
- /* Make sure we support pixel shaders, before trying to compile them! */
- /* Direct3D 9 (Shader model 1-3 tests) */
- IDirect3DDevice9_GetDeviceCaps(device, &caps);
- if (caps.PixelShaderVersion >= D3DPS_VERSION(2, 0))
- {
- todo_wine
- {
- test_swizzle(device, quad_geometry, vshader_passthru);
- test_math(device, quad_geometry, vshader_passthru);
- test_conditionals(device, quad_geometry, vshader_passthru);
- test_float_vectors(device, quad_geometry, vshader_passthru);
- test_trig(device, quad_geometry, vshader_passthru);
- test_fail(device, quad_geometry, vshader_passthru);
- }
- } else skip("no pixel shader support\n");
-
- /* Reference counting sanity checks */
- if (vshader_passthru)
- {
- refcount = IDirect3DVertexShader9_Release(vshader_passthru);
- ok(!refcount, "Pass-through vertex shader has %u references left\n", refcount);
- }
-
- refcount = IDirect3DVertexBuffer9_Release(quad_geometry);
- ok(!refcount, "Vertex buffer has %u references left\n", refcount);
-
- refcount = IDirect3DVertexDeclaration9_Release(vdeclaration);
- ok(!refcount, "Vertex declaration has %u references left\n", refcount);
-
- refcount = IDirect3DDevice9_Release(device);
- ok(!refcount, "Device has %u references left\n", refcount);
-}
diff --git a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c
new file mode 100644
index 00000000000..79f54d200e2
--- /dev/null
+++ b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c
@@ -0,0 +1,678 @@
+/*
+ * Copyright (C) 2010 Travis Athougies
+ * Copyright (C) 2020 Zebediah Figura for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+#define COBJMACROS
+#include "wine/test.h"
+#include "d3dx9.h"
+#include "d3dcompiler.h"
+
+#include <math.h>
+
+static pD3DCompile ppD3DCompile;
+
+static HRESULT (WINAPI *pD3DXGetShaderConstantTable)(const DWORD *byte_code, ID3DXConstantTable **constant_table);
+
+struct vec2
+{
+ float x, y;
+};
+
+struct vec4
+{
+ float x, y, z, w;
+};
+
+#define compile_shader(a, b) compile_shader_(__LINE__, a, b)
+static ID3D10Blob *compile_shader_(unsigned int line, const char *source, const char *target)
+{
+ ID3D10Blob *blob = NULL, *errors = NULL;
+ HRESULT hr;
+
+ hr = ppD3DCompile(source, strlen(source), NULL, NULL, NULL, "main", target, 0, 0, &blob, &errors);
+ ok_(__FILE__, line)(hr == D3D_OK, "Failed to compile shader, hr %#x.\n", hr);
+ if (errors)
+ {
+ if (winetest_debug > 1)
+ trace_(__FILE__, line)("%s\n", (char *)ID3D10Blob_GetBufferPointer(errors));
+ ID3D10Blob_Release(errors);
+ }
+ return blob;
+}
+
+static IDirect3DDevice9 *create_device(HWND window)
+{
+ D3DPRESENT_PARAMETERS present_parameters =
+ {
+ .Windowed = TRUE,
+ .hDeviceWindow = window,
+ .SwapEffect = D3DSWAPEFFECT_DISCARD,
+ .BackBufferWidth = 640,
+ .BackBufferHeight = 480,
+ .BackBufferFormat = D3DFMT_A8R8G8B8,
+ };
+ IDirect3DDevice9 *device;
+ IDirect3DSurface9 *rt;
+ IDirect3D9 *d3d;
+ D3DCAPS9 caps;
+ HRESULT hr;
+
+ d3d = Direct3DCreate9(D3D_SDK_VERSION);
+ ok(!!d3d, "Failed to create a D3D object.\n");
+
+ hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
+ D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device);
+ IDirect3D9_Release(d3d);
+ if (FAILED(hr))
+ {
+ skip("Failed to create a 3D device, hr %#x.\n", hr);
+ return NULL;
+ }
+
+ hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
+ ok(hr == D3D_OK, "Failed to get device caps, hr %#x.\n", hr);
+ if (caps.PixelShaderVersion < D3DPS_VERSION(2, 0) || caps.VertexShaderVersion < D3DVS_VERSION(2, 0))
+ {
+ skip("No shader model 2 support.\n");
+ IDirect3DDevice9_Release(device);
+ return NULL;
+ }
+
+ if (FAILED(hr = IDirect3DDevice9_CreateRenderTarget(device, 640, 480, D3DFMT_A32B32G32R32F,
+ D3DMULTISAMPLE_NONE, 0, FALSE, &rt, NULL)))
+ {
+ skip("Failed to create an A32B32G32R32F surface, hr %#x.\n", hr);
+ IDirect3DDevice9_Release(device);
+ return NULL;
+ }
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
+ ok(hr == D3D_OK, "Failed to set render target, hr %#x.\n", hr);
+ IDirect3DSurface9_Release(rt);
+
+ return device;
+}
+
+struct test_context
+{
+ IDirect3DDevice9 *device;
+ HWND window;
+};
+
+#define init_test_context(a) init_test_context_(__LINE__, a)
+static BOOL init_test_context_(unsigned int line, struct test_context *context)
+{
+ RECT rect = {0, 0, 640, 480};
+
+ AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);
+ context->window = CreateWindowA("static", "d3dcompiler_test", WS_OVERLAPPEDWINDOW,
+ 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
+ ok(!!context->window, "Failed to create a window.\n");
+
+ if (!(context->device = create_device(context->window)))
+ {
+ DestroyWindow(context->window);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+#define release_test_context(context) release_test_context_(__LINE__, context)
+static void release_test_context_(unsigned int line, struct test_context *context)
+{
+ ULONG ref = IDirect3DDevice9_Release(context->device);
+ ok_(__FILE__, line)(!ref, "Device has %u references left.\n", ref);
+ DestroyWindow(context->window);
+}
+
+#define draw_quad(device, ps_code) draw_quad_(__LINE__, device, ps_code)
+static void draw_quad_(unsigned int line, IDirect3DDevice9 *device, ID3D10Blob *ps_code)
+{
+ IDirect3DVertexDeclaration9 *vertex_declaration;
+ IDirect3DVertexShader9 *vs;
+ IDirect3DPixelShader9 *ps;
+ ID3D10Blob *vs_code;
+ HRESULT hr;
+
+ static const D3DVERTEXELEMENT9 decl_elements[] =
+ {
+ {0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
+ {0, 8, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
+ D3DDECL_END()
+ };
+
+ static const struct
+ {
+ struct vec2 position;
+ struct vec2 t0;
+ }
+ quad[] =
+ {
+ {{-1.0f, -1.0f}, {0.0f, 1.0f}},
+ {{-1.0f, 1.0f}, {0.0f, 0.0f}},
+ {{ 1.0f, -1.0f}, {1.0f, 1.0f}},
+ {{ 1.0f, 1.0f}, {1.0f, 0.0f}},
+ };
+
+ static const char vs_source[] =
+ "float4 main(float4 pos : POSITION, inout float2 texcoord : TEXCOORD0) : POSITION\n"
+ "{\n"
+ " return pos;\n"
+ "}";
+
+ hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &vertex_declaration);
+ ok_(__FILE__, line)(hr == D3D_OK, "Failed to create vertex declaration, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_SetVertexDeclaration(device, vertex_declaration);
+ ok_(__FILE__, line)(hr == D3D_OK, "Failed to set vertex declaration, hr %#x.\n", hr);
+
+ vs_code = compile_shader(vs_source, "vs_2_0");
+
+ hr = IDirect3DDevice9_CreateVertexShader(device, ID3D10Blob_GetBufferPointer(vs_code), &vs);
+ ok_(__FILE__, line)(hr == D3D_OK, "Failed to create vertex shader, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_SetVertexShader(device, vs);
+ ok_(__FILE__, line)(hr == D3D_OK, "Failed to set vertex shader, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_CreatePixelShader(device, ID3D10Blob_GetBufferPointer(ps_code), &ps);
+ ok_(__FILE__, line)(hr == D3D_OK, "Failed to create pixel shader, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_SetPixelShader(device, ps);
+ ok_(__FILE__, line)(hr == D3D_OK, "Failed to set pixel shader, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_BeginScene(device);
+ ok_(__FILE__, line)(hr == D3D_OK, "Failed to draw, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
+ ok_(__FILE__, line)(hr == D3D_OK, "Failed to draw, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_EndScene(device);
+ ok_(__FILE__, line)(hr == D3D_OK, "Failed to draw, hr %#x.\n", hr);
+
+ IDirect3DVertexDeclaration9_Release(vertex_declaration);
+ IDirect3DVertexShader9_Release(vs);
+ IDirect3DPixelShader9_Release(ps);
+ ID3D10Blob_Release(vs_code);
+}
+
+struct readback
+{
+ IDirect3DSurface9 *surface;
+ D3DLOCKED_RECT rect;
+};
+
+static void init_readback(IDirect3DDevice9 *device, struct readback *rb)
+{
+ IDirect3DSurface9 *rt;
+ D3DSURFACE_DESC desc;
+ HRESULT hr;
+
+ hr = IDirect3DDevice9Ex_GetRenderTarget(device, 0, &rt);
+ ok(hr == D3D_OK, "Failed to get render target, hr %#x.\n", hr);
+
+ hr = IDirect3DSurface9_GetDesc(rt, &desc);
+ ok(hr == D3D_OK, "Failed to get surface desc, hr %#x.\n", hr);
+ hr = IDirect3DDevice9Ex_CreateOffscreenPlainSurface(device, desc.Width, desc.Height,
+ desc.Format, D3DPOOL_SYSTEMMEM, &rb->surface, NULL);
+ ok(hr == D3D_OK, "Failed to create surface, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9Ex_GetRenderTargetData(device, rt, rb->surface);
+ ok(hr == D3D_OK, "Failed to get render target data, hr %#x.\n", hr);
+
+ hr = IDirect3DSurface9_LockRect(rb->surface, &rb->rect, NULL, D3DLOCK_READONLY);
+ ok(hr == D3D_OK, "Failed to lock surface, hr %#x.\n", hr);
+
+ IDirect3DSurface9_Release(rt);
+}
+
+static const struct vec4 *get_readback_vec4(const struct readback *rb, unsigned int x, unsigned int y)
+{
+ return (struct vec4 *)((BYTE *)rb->rect.pBits + y * rb->rect.Pitch + x * sizeof(struct vec4));
+}
+
+static void release_readback(struct readback *rb)
+{
+ IDirect3DSurface9_UnlockRect(rb->surface);
+ IDirect3DSurface9_Release(rb->surface);
+}
+
+static struct vec4 get_color_vec4(IDirect3DDevice9 *device, unsigned int x, unsigned int y)
+{
+ struct readback rb;
+ struct vec4 ret;
+
+ init_readback(device, &rb);
+ ret = *get_readback_vec4(&rb, x, y);
+ release_readback(&rb);
+
+ return ret;
+}
+
+static BOOL compare_float(float f, float g, unsigned int ulps)
+{
+ int x = *(int *)&f;
+ int y = *(int *)&g;
+
+ if (x < 0)
+ x = INT_MIN - x;
+ if (y < 0)
+ y = INT_MIN - y;
+
+ if (abs(x - y) > ulps)
+ return FALSE;
+
+ return TRUE;
+}
+
+static BOOL compare_vec4(const struct vec4 *vec, float x, float y, float z, float w, unsigned int ulps)
+{
+ return compare_float(vec->x, x, ulps)
+ && compare_float(vec->y, y, ulps)
+ && compare_float(vec->z, z, ulps)
+ && compare_float(vec->w, w, ulps);
+}
+
+static void test_swizzle(void)
+{
+ static const D3DXVECTOR4 color = {0.0303f, 0.0f, 0.0f, 0.0202f};
+ struct test_context test_context;
+ ID3DXConstantTable *constants;
+ ID3D10Blob *ps_code = NULL;
+ IDirect3DDevice9 *device;
+ struct vec4 v;
+ HRESULT hr;
+
+ static const char ps_source[] =
+ "uniform float4 color;\n"
+ "float4 main() : COLOR\n"
+ "{\n"
+ " float4 ret = color;\n"
+ " ret.gb = ret.ra;\n"
+ " ret.ra = float2(0.0101, 0.0404);\n"
+ " return ret;\n"
+ "}";
+
+ if (!init_test_context(&test_context))
+ return;
+ device = test_context.device;
+
+ todo_wine ps_code = compile_shader(ps_source, "ps_2_0");
+ if (ps_code)
+ {
+ hr = pD3DXGetShaderConstantTable(ID3D10Blob_GetBufferPointer(ps_code), &constants);
+ ok(hr == D3D_OK, "Failed to get constant table, hr %#x.\n", hr);
+ hr = ID3DXConstantTable_SetVector(constants, device, "color", &color);
+ ok(hr == D3D_OK, "Failed to set constant, hr %#x.\n", hr);
+ ID3DXConstantTable_Release(constants);
+
+ draw_quad(device, ps_code);
+
+ v = get_color_vec4(device, 0, 0);
+ ok(compare_vec4(&v, 0.0101f, 0.0303f, 0.0202f, 0.0404f, 0),
+ "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
+
+ ID3D10Blob_Release(ps_code);
+ }
+ release_test_context(&test_context);
+}
+
+static void test_math(void)
+{
+ struct test_context test_context;
+ ID3DXConstantTable *constants;
+ ID3D10Blob *ps_code = NULL;
+ IDirect3DDevice9 *device;
+ struct vec4 v;
+ HRESULT hr;
+
+ static const char ps_source[] =
+ "float4 main(uniform float u, uniform float v, uniform float w, uniform float x,\n"
+ " uniform float y, uniform float z): COLOR\n"
+ "{\n"
+ " return float4(x * y - z / w + --u / -v,\n"
+ " z * x / y + w / -v,\n"
+ " u + v - w,\n"
+ " x / y / w);\n"
+ "}";
+
+ if (!init_test_context(&test_context))
+ return;
+ device = test_context.device;
+
+ todo_wine ps_code = compile_shader(ps_source, "ps_2_0");
+ if (ps_code)
+ {
+ hr = pD3DXGetShaderConstantTable(ID3D10Blob_GetBufferPointer(ps_code), &constants);
+ ok(hr == D3D_OK, "Failed to get constant table, hr %#x.\n", hr);
+ hr = ID3DXConstantTable_SetFloat(constants, device, "$u", 2.5f);
+ ok(hr == D3D_OK, "Failed to set constant, hr %#x.\n", hr);
+ hr = ID3DXConstantTable_SetFloat(constants, device, "$v", 0.3f);
+ ok(hr == D3D_OK, "Failed to set constant, hr %#x.\n", hr);
+ hr = ID3DXConstantTable_SetFloat(constants, device, "$w", 0.2f);
+ ok(hr == D3D_OK, "Failed to set constant, hr %#x.\n", hr);
+ hr = ID3DXConstantTable_SetFloat(constants, device, "$x", 0.7f);
+ ok(hr == D3D_OK, "Failed to set constant, hr %#x.\n", hr);
+ hr = ID3DXConstantTable_SetFloat(constants, device, "$y", 0.1f);
+ ok(hr == D3D_OK, "Failed to set constant, hr %#x.\n", hr);
+ hr = ID3DXConstantTable_SetFloat(constants, device, "$z", 1.5f);
+ ok(hr == D3D_OK, "Failed to set constant, hr %#x.\n", hr);
+ ID3DXConstantTable_Release(constants);
+
+ draw_quad(device, ps_code);
+
+ v = get_color_vec4(device, 0, 0);
+ ok(compare_vec4(&v, -12.43f, 9.833333f, 1.6f, 35.0f, 1),
+ "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
+
+ ID3D10Blob_Release(ps_code);
+ }
+ release_test_context(&test_context);
+}
+
+static void test_conditionals(void)
+{
+ struct test_context test_context;
+ ID3D10Blob *ps_code = NULL;
+ IDirect3DDevice9 *device;
+ const struct vec4 *v;
+ struct readback rb;
+ unsigned int i;
+
+ static const char ps_if_source[] =
+ "float4 main(float2 pos : TEXCOORD0) : COLOR\n"
+ "{\n"
+ " if((pos.x * 640.0) > 200.0)\n"
+ " return float4(0.1, 0.2, 0.3, 0.4);\n"
+ " else\n"
+ " return float4(0.9, 0.8, 0.7, 0.6);\n"
+ "}";
+
+ static const char ps_ternary_source[] =
+ "float4 main(float2 pos : TEXCOORD0) : COLOR\n"
+ "{\n"
+ " return (pos.x < 0.5 ? float4(0.5, 0.25, 0.5, 0.75) : float4(0.6, 0.8, 0.1, 0.2));\n"
+ "}";
+
+ if (!init_test_context(&test_context))
+ return;
+ device = test_context.device;
+
+ todo_wine ps_code = compile_shader(ps_if_source, "ps_2_0");
+ if (ps_code)
+ {
+ draw_quad(device, ps_code);
+ init_readback(device, &rb);
+
+ for (i = 0; i < 200; i += 40)
+ {
+ v = get_readback_vec4(&rb, i, 0);
+ ok(compare_vec4(v, 0.9f, 0.8f, 0.7f, 0.6f, 0),
+ "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v->x, v->y, v->z, v->w);
+ }
+
+ for (i = 240; i < 640; i += 40)
+ {
+ v = get_readback_vec4(&rb, i, 0);
+ ok(compare_vec4(v, 0.1f, 0.2f, 0.3f, 0.4f, 0),
+ "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v->x, v->y, v->z, v->w);
+ }
+
+ release_readback(&rb);
+ ID3D10Blob_Release(ps_code);
+ }
+
+ todo_wine ps_code = compile_shader(ps_ternary_source, "ps_2_0");
+ if (ps_code)
+ {
+ draw_quad(device, ps_code);
+ init_readback(device, &rb);
+
+ for (i = 0; i < 320; i += 40)
+ {
+ v = get_readback_vec4(&rb, i, 0);
+ ok(compare_vec4(v, 0.5f, 0.25f, 0.5f, 0.75f, 0),
+ "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v->x, v->y, v->z, v->w);
+ }
+
+ for (i = 360; i < 640; i += 40)
+ {
+ v = get_readback_vec4(&rb, i, 0);
+ ok(compare_vec4(v, 0.6f, 0.8f, 0.1f, 0.2f, 0),
+ "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v->x, v->y, v->z, v->w);
+ }
+
+ release_readback(&rb);
+ ID3D10Blob_Release(ps_code);
+ }
+
+ release_test_context(&test_context);
+}
+
+static void test_float_vectors(void)
+{
+ struct test_context test_context;
+ ID3DXConstantTable *constants;
+ ID3D10Blob *ps_code = NULL;
+ IDirect3DDevice9 *device;
+ struct vec4 v;
+ HRESULT hr;
+
+ static const char ps_indexing_source[] =
+ "float4 main() : COLOR\n"
+ "{\n"
+ " float4 color;\n"
+ " color[0] = 0.020;\n"
+ " color[1] = 0.245;\n"
+ " color[2] = 0.351;\n"
+ " color[3] = 1.0;\n"
+ " return color;\n"
+ "}";
+
+ /* A uniform index is used so that the compiler can't optimize. */
+ static const char ps_uniform_indexing_source[] =
+ "uniform int i;\n"
+ "float4 main() : COLOR\n"
+ "{\n"
+ " float4 color = float4(0.5, 0.4, 0.3, 0.2);\n"
+ " color.g = color[i];\n"
+ " color.b = 0.8;\n"
+ " return color;\n"
+ "}";
+
+ if (!init_test_context(&test_context))
+ return;
+ device = test_context.device;
+
+ todo_wine ps_code = compile_shader(ps_indexing_source, "ps_2_0");
+ if (ps_code)
+ {
+ draw_quad(device, ps_code);
+
+ v = get_color_vec4(device, 0, 0);
+ ok(compare_vec4(&v, 0.02f, 0.245f, 0.351f, 1.0f, 0),
+ "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
+
+ ID3D10Blob_Release(ps_code);
+ }
+
+ todo_wine ps_code = compile_shader(ps_uniform_indexing_source, "ps_2_0");
+ if (ps_code)
+ {
+ hr = pD3DXGetShaderConstantTable(ID3D10Blob_GetBufferPointer(ps_code), &constants);
+ ok(hr == D3D_OK, "Failed to get constants, hr %#x.\n", hr);
+ hr = ID3DXConstantTable_SetInt(constants, device, "i", 2);
+ ok(hr == D3D_OK, "Failed to set constant, hr %#x.\n", hr);
+ ID3DXConstantTable_Release(constants);
+ draw_quad(device, ps_code);
+
+ v = get_color_vec4(device, 0, 0);
+ ok(compare_vec4(&v, 0.5f, 0.3f, 0.8f, 0.2f, 0),
+ "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
+
+ ID3D10Blob_Release(ps_code);
+ }
+
+ release_test_context(&test_context);
+}
+
+static void test_trig(void)
+{
+ struct test_context test_context;
+ ID3D10Blob *ps_code = NULL;
+ IDirect3DDevice9 *device;
+ const struct vec4 *v;
+ struct readback rb;
+ unsigned int i;
+
+ static const char ps_source[] =
+ "float4 main(float x : TEXCOORD0) : COLOR\n"
+ "{\n"
+ " const float pi2 = 6.2831853;\n"
+ " float calcd_sin = (sin(x * pi2) + 1)/2;\n"
+ " float calcd_cos = (cos(x * pi2) + 1)/2;\n"
+ " return float4(calcd_sin, calcd_cos, 0, 0);\n"
+ "}";
+
+ if (!init_test_context(&test_context))
+ return;
+ device = test_context.device;
+
+ todo_wine ps_code = compile_shader(ps_source, "ps_2_0");
+ if (ps_code)
+ {
+ draw_quad(device, ps_code);
+ init_readback(device, &rb);
+
+ for (i = 0; i < 32; ++i)
+ {
+ float expect_x = (sinf(i * 2 * M_PI / 32) + 1.0f) / 2.0f;
+ float expect_y = (cosf(i * 2 * M_PI / 32) + 1.0f) / 2.0f;
+ v = get_readback_vec4(&rb, i * 640 / 32, 0);
+ ok(compare_vec4(v, expect_x, expect_y, 0.0f, 0.0f, 4096),
+ "Test %u: Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
+ i, v->x, v->y, v->z, v->w, expect_x, expect_y, 0.0f, 0.0f);
+ }
+
+ release_readback(&rb);
+ ID3D10Blob_Release(ps_code);
+ }
+ release_test_context(&test_context);
+}
+
+static void test_fail(void)
+{
+ static const char *tests[] =
+ {
+ "float4 test(float2 pos: TEXCOORD0) : COLOR\n"
+ "{\n"
+ " return y;\n"
+ "}",
+
+ "float4 test(float2 pos: TEXCOORD0) : COLOR\n"
+ "{\n"
+ " float4 x = float4(0, 0, 0, 0);\n"
+ " x.xzzx = float4(1, 2, 3, 4);\n"
+ " return x;\n"
+ "}",
+
+ "float4 test(float2 pos: TEXCOORD0) : COLOR\n"
+ "{\n"
+ " float4 x = pos;\n"
+ " return x;\n"
+ "}",
+
+ "float4 test(float2 pos, TEXCOORD0) ; COLOR\n"
+ "{\n"
+ " pos = float4 x;\n"
+ " mul(float4(5, 4, 3, 2), mvp) = x;\n"
+ " return float4;\n"
+ "}",
+
+ "float4 563r(float2 45s: TEXCOORD0) : COLOR\n"
+ "{\n"
+ " float2 x = 45s;\n"
+ " return float4(x.x, x.y, 0, 0);\n"
+ "}",
+
+ "float4 test(float2 pos: TEXCOORD0) : COLOR\n"
+ "{\n"
+ " struct { int b,c; } x = {0};\n"
+ " return y;\n"
+ "}",
+
+ "float4 test(float2 pos: TEXCOORD0) : COLOR\n"
+ "{\n"
+ " struct {} x = {};\n"
+ " return y;\n"
+ "}",
+ };
+
+ ID3D10Blob *compiled, *errors;
+ unsigned int i;
+ HRESULT hr;
+
+ for (i = 0; i < ARRAY_SIZE(tests); ++i)
+ {
+ compiled = errors = NULL;
+ hr = ppD3DCompile(tests[i], strlen(tests[i]), NULL, NULL, NULL, "test", "ps_2_0", 0, 0, &compiled, &errors);
+ todo_wine ok(hr == E_FAIL, "Test %u, got unexpected hr %#x.\n", i, hr);
+ todo_wine_if (i == 1) ok(!!errors, "Test %u, expected non-NULL error blob.\n", i);
+ ok(!compiled, "Test %u, expected no compiled shader blob.\n", i);
+ if (errors)
+ ID3D10Blob_Release(errors);
+ }
+}
+
+static BOOL load_d3dcompiler(void)
+{
+ HMODULE module;
+
+#if D3D_COMPILER_VERSION == 47
+ if (!(module = LoadLibraryA("d3dcompiler_47.dll"))) return FALSE;
+#else
+ if (!(module = LoadLibraryA("d3dcompiler_43.dll"))) return FALSE;
+#endif
+
+ ppD3DCompile = (void*)GetProcAddress(module, "D3DCompile");
+ return TRUE;
+}
+
+START_TEST(hlsl_d3d9)
+{
+ HMODULE mod;
+
+ if (!load_d3dcompiler())
+ {
+ win_skip("Could not load DLL.\n");
+ return;
+ }
+
+ if (!(mod = LoadLibraryA("d3dx9_36.dll")))
+ {
+ win_skip("Failed to load d3dx9_36.dll.\n");
+ return;
+ }
+ pD3DXGetShaderConstantTable = (void *)GetProcAddress(mod, "D3DXGetShaderConstantTable");
+
+ test_swizzle();
+ test_math();
+ test_conditionals();
+ test_float_vectors();
+ test_trig();
+ test_fail();
+}
diff --git a/dlls/d3dcompiler_47/tests/Makefile.in b/dlls/d3dcompiler_47/tests/Makefile.in
index 401ed30b0f1..032e16fdb8f 100644
--- a/dlls/d3dcompiler_47/tests/Makefile.in
+++ b/dlls/d3dcompiler_47/tests/Makefile.in
@@ -6,5 +6,5 @@ PARENTSRC = ../../d3dcompiler_43/tests
C_SRCS = \
asm.c \
blob.c \
- hlsl.c \
+ hlsl_d3d9.c \
reflection.c
--
2.24.1
1
2
[PATCH v2 1/4] winegstreamer: Don't query or set GStreamer duration if the filter is stopped.
by Zebediah Figura 28 Feb '20
by Zebediah Figura 28 Feb '20
28 Feb '20
This check is not equivalent to the existence of "their_src" for the MPEG-1 splitter, since that always exposes a source audio pin.
Fixes: 40a4c782b7f77534535dfa7bb2a97049026fef47
Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com>
---
dlls/winegstreamer/gstdemux.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/dlls/winegstreamer/gstdemux.c b/dlls/winegstreamer/gstdemux.c
index 488c9bd8a13..d469f2dbbff 100644
--- a/dlls/winegstreamer/gstdemux.c
+++ b/dlls/winegstreamer/gstdemux.c
@@ -1841,7 +1841,8 @@ static HRESULT WINAPI GST_Seeking_GetCurrentPosition(IMediaSeeking *iface, REFER
mark_wine_thread();
- if (!This->their_src) {
+ if (This->pin.pin.filter->state == State_Stopped)
+ {
*pos = This->seek.llCurrent;
TRACE("Cached value\n");
if (This->seek.llDuration)
@@ -1892,7 +1893,7 @@ static HRESULT WINAPI GST_Seeking_SetPositions(IMediaSeeking *iface,
return E_NOTIMPL;
hr = SourceSeekingImpl_SetPositions(iface, pCur, curflags, pStop, stopflags);
- if (!This->their_src)
+ if (This->pin.pin.filter->state == State_Stopped)
return hr;
curtype = type_from_flags(curflags);
--
2.25.0
1
3
[PATCH 1/4] winegstreamer: Don't query or set GStreamer duration if the filter is stopped.
by Zebediah Figura 28 Feb '20
by Zebediah Figura 28 Feb '20
28 Feb '20
This check is not equivalent to the existence of "their_src" for the MPEG-1
splitter, since that always exposes a source audio pin.
Fixes: 40a4c782b7f77534535dfa7bb2a97049026fef47
Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com>
---
dlls/winegstreamer/gstdemux.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/dlls/winegstreamer/gstdemux.c b/dlls/winegstreamer/gstdemux.c
index 488c9bd8a13..d469f2dbbff 100644
--- a/dlls/winegstreamer/gstdemux.c
+++ b/dlls/winegstreamer/gstdemux.c
@@ -1841,7 +1841,8 @@ static HRESULT WINAPI GST_Seeking_GetCurrentPosition(IMediaSeeking *iface, REFER
mark_wine_thread();
- if (!This->their_src) {
+ if (This->pin.pin.filter->state == State_Stopped)
+ {
*pos = This->seek.llCurrent;
TRACE("Cached value\n");
if (This->seek.llDuration)
@@ -1892,7 +1893,7 @@ static HRESULT WINAPI GST_Seeking_SetPositions(IMediaSeeking *iface,
return E_NOTIMPL;
hr = SourceSeekingImpl_SetPositions(iface, pCur, curflags, pStop, stopflags);
- if (!This->their_src)
+ if (This->pin.pin.filter->state == State_Stopped)
return hr;
curtype = type_from_flags(curflags);
--
2.25.0
3
5
Signed-off-by: Jacek Caban <jacek(a)codeweavers.com>
---
dlls/msvcrt/crt_main.c | 12 +++++++++++-
dlls/msvcrt/crt_wmain.c | 12 +++++++++++-
dlls/ucrtbase/Makefile.in | 7 ++++++-
3 files changed, 28 insertions(+), 3 deletions(-)
3
2
[PATCH v3 1/3] d3dcompiler/tests: Rewrite to use a separate d3d9 device for each test.
by Zebediah Figura 27 Feb '20
by Zebediah Figura 27 Feb '20
27 Feb '20
This brings the d3dcompiler tests more in line with existing d3d9 tests, and
allows potentially running the tests in parallel.
Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com>
---
v3: make window creation more consistent
dlls/d3dcompiler_43/tests/Makefile.in | 2 +-
dlls/d3dcompiler_43/tests/hlsl.c | 701 --------------------------
dlls/d3dcompiler_43/tests/hlsl_d3d9.c | 678 +++++++++++++++++++++++++
dlls/d3dcompiler_47/tests/Makefile.in | 2 +-
4 files changed, 680 insertions(+), 703 deletions(-)
delete mode 100644 dlls/d3dcompiler_43/tests/hlsl.c
create mode 100644 dlls/d3dcompiler_43/tests/hlsl_d3d9.c
diff --git a/dlls/d3dcompiler_43/tests/Makefile.in b/dlls/d3dcompiler_43/tests/Makefile.in
index 51b1f934836..f00d8560826 100644
--- a/dlls/d3dcompiler_43/tests/Makefile.in
+++ b/dlls/d3dcompiler_43/tests/Makefile.in
@@ -5,5 +5,5 @@ EXTRADEFS = -DD3D_COMPILER_VERSION=43
C_SRCS = \
asm.c \
blob.c \
- hlsl.c \
+ hlsl_d3d9.c \
reflection.c
diff --git a/dlls/d3dcompiler_43/tests/hlsl.c b/dlls/d3dcompiler_43/tests/hlsl.c
deleted file mode 100644
index 868693838cc..00000000000
--- a/dlls/d3dcompiler_43/tests/hlsl.c
+++ /dev/null
@@ -1,701 +0,0 @@
-/*
- * Copyright (C) 2010 Travis Athougies
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
-#define COBJMACROS
-#include "wine/test.h"
-#include "d3dx9.h"
-#include "d3dcompiler.h"
-
-#include <math.h>
-
-static pD3DCompile ppD3DCompile;
-
-static HRESULT (WINAPI *pD3DXGetShaderConstantTable)(const DWORD *byte_code, ID3DXConstantTable **constant_table);
-static D3DMATRIX *(WINAPI *pD3DXMatrixOrthoLH)(D3DXMATRIX *pout, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf);
-
-struct vertex
-{
- float x, y, z;
- float tx, ty;
-};
-
-/* Tells compute_shader_probe* which pixels should be what colors */
-struct hlsl_probe_info
-{
- unsigned int x, y;
- /* The expected values in this region */
- D3DXCOLOR c;
- /* The max error for any value */
- float epsilon;
- /* An error message to print if this test fails */
- const char *message;
-};
-
-static HWND create_window(void)
-{
- WNDCLASSA wc = {0};
- wc.lpfnWndProc = DefWindowProcA;
- wc.lpszClassName = "d3d9_test_wc";
- RegisterClassA(&wc);
-
- return CreateWindowA("d3d9_test_wc", "d3d9_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
-}
-
-static IDirect3DDevice9 *init_d3d9(IDirect3DVertexDeclaration9 **vdeclaration,
- IDirect3DVertexBuffer9 **quad_geometry, IDirect3DVertexShader9 **vshader_passthru)
-{
- static const struct vertex quad_vertices[4] =
- {
- {-1.0f, -1.0f, 0.0f, 0.0f, 1.0f},
- {-1.0f, 1.0f, 0.0f, 0.0f, 0.0f},
- { 1.0f, -1.0f, 0.0f, 1.0f, 1.0f},
- { 1.0f, 1.0f, 0.0f, 1.0f, 0.0f}
- };
-
- static const D3DVERTEXELEMENT9 vdeclelements[] =
- {
- {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
- {0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
- D3DDECL_END()
- };
-
- static const char *vshader_passthru_hlsl =
- "float4 vshader(float4 pos: POSITION, inout float2 texcoord: TEXCOORD0): POSITION\n"
- "{\n"
- " return pos;\n"
- "}";
-
- IDirect3D9 *d3d9_ptr;
- IDirect3DDevice9 *device_ptr = NULL;
- D3DPRESENT_PARAMETERS present_parameters;
-
- void *temp_geometry_vertices;
-
- ID3D10Blob *compiled = NULL;
- ID3D10Blob *errors = NULL;
-
- HRESULT hr;
-
- d3d9_ptr = Direct3DCreate9(D3D_SDK_VERSION);
- if (!d3d9_ptr)
- {
- skip("could not create D3D9\n");
- return NULL;
- }
-
- hr = IDirect3D9_CheckDeviceFormat(d3d9_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
- 0, D3DRTYPE_SURFACE, D3DFMT_A32B32G32R32F);
- if (FAILED(hr))
- {
- skip("A32B32G32R32F format not available on this device\n");
- IDirect3D9_Release(d3d9_ptr);
- return NULL;
- }
-
- ZeroMemory(&present_parameters, sizeof(present_parameters));
- present_parameters.Windowed = TRUE;
- present_parameters.hDeviceWindow = create_window();
- present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
-
- hr = IDirect3D9_CreateDevice(d3d9_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL,
- D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device_ptr);
- IDirect3D9_Release(d3d9_ptr);
- if (FAILED(hr))
- {
- skip("could not create Direct3D9 device\n");
- return NULL;
- }
-
- /* Create the quad geometry */
- hr = IDirect3DDevice9_CreateVertexBuffer(device_ptr, 4 * sizeof(struct vertex),
- D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, quad_geometry, NULL);
- ok(SUCCEEDED(hr),
- "Could not create vertex buffer, IDirect3DDevice9_CreateVertexBuffer returned: %08x\n", hr);
-
- hr = IDirect3DVertexBuffer9_Lock(*quad_geometry, 0, sizeof(quad_vertices), &temp_geometry_vertices, 0);
- ok(SUCCEEDED(hr), "IDirect3DVertexBuffer9_Lock returned: %08x\n", hr);
- memcpy(temp_geometry_vertices, quad_vertices, sizeof(quad_vertices));
- IDirect3DVertexBuffer9_Unlock(*quad_geometry);
-
- hr = IDirect3DDevice9_CreateVertexDeclaration(device_ptr, vdeclelements, vdeclaration);
- ok(SUCCEEDED(hr), "Could not create vertex declaration: "
- "IDirect3DDevice9_CreateVertexDeclaration returned: %08x\n", hr);
-
- hr = IDirect3DDevice9_SetVertexDeclaration(device_ptr, *vdeclaration);
- ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexDeclaration returned: %08x\n", hr);
-
- /* Create a simple vertex shader to just pass through the values */
- hr = ppD3DCompile(vshader_passthru_hlsl, strlen(vshader_passthru_hlsl), NULL,
- NULL, NULL, "vshader", "vs_1_1", 0, 0, &compiled, &errors);
- if (FAILED(hr))
- {
- skip("not compiling vertex shader due to lacking wine HLSL support!\n");
- if (errors)
- ID3D10Blob_Release(errors);
- return NULL;
- }
-
- hr = IDirect3DDevice9_CreateVertexShader(device_ptr, ID3D10Blob_GetBufferPointer(compiled),
- vshader_passthru);
- ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateVertexShader returned: %08x\n", hr);
- ID3D10Blob_Release(compiled);
-
- return device_ptr;
-}
-
-/* Convenience functions */
-static void set_float4_d3d9(IDirect3DDevice9 *device, ID3DXConstantTable *constants, const char *name,
- float x, float y, float z, float w)
-{
- D3DXVECTOR4 vector;
- vector.x = x;
- vector.y = y;
- vector.z = z;
- vector.w = w;
- ID3DXConstantTable_SetVector(constants, device, name, &vector);
-}
-
-/* Compile our pixel shader and get back the compiled version and a constant table */
-static IDirect3DPixelShader9 *compile_pixel_shader9(IDirect3DDevice9 *device, const char *shader,
- const char *profile, ID3DXConstantTable **constants)
-{
- ID3D10Blob *compiled = NULL;
- ID3D10Blob *errors = NULL;
- IDirect3DPixelShader9 *pshader;
- HRESULT hr;
-
- hr = ppD3DCompile(shader, strlen(shader), NULL, NULL,
- NULL, "test", profile, /* test is the name of the entry point of our shader */
- 0, 0, &compiled, &errors);
- ok(hr == D3D_OK, "Pixel shader %s compilation failed: %s\n", shader,
- errors ? (char *)ID3D10Blob_GetBufferPointer(errors) : "");
- if (FAILED(hr)) return NULL;
-
- hr = pD3DXGetShaderConstantTable(ID3D10Blob_GetBufferPointer(compiled), constants);
- ok(hr == D3D_OK, "Could not get constant table from compiled pixel shader\n");
-
- hr = IDirect3DDevice9_CreatePixelShader(device, ID3D10Blob_GetBufferPointer(compiled), &pshader);
- ok(SUCCEEDED(hr), "IDirect3DDevice9_CreatePixelShader returned: %08x\n", hr);
- ID3D10Blob_Release(compiled);
- return pshader;
-}
-
-/* Draw a full screen quad */
-static void draw_quad_with_shader9(IDirect3DDevice9 *device, IDirect3DVertexBuffer9 *quad_geometry)
-{
- HRESULT hr;
- D3DXMATRIX projection_matrix;
-
- pD3DXMatrixOrthoLH(&projection_matrix, 2.0f, 2.0f, 0.0f, 1.0f);
- IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, &projection_matrix);
-
- hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
- ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned: %08x\n", hr);
-
- hr = IDirect3DDevice9_BeginScene(device);
- ok(hr == D3D_OK, "IDirect3DDevice9_BeginScene returned: %08x\n", hr);
-
- hr = IDirect3DDevice9_SetStreamSource(device, 0, quad_geometry, 0, sizeof(struct vertex));
- ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSource returned: %08x\n", hr);
- hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 2);
- ok(hr == D3D_OK, "IDirect3DDevice9_DrawPrimitive returned: %08x\n", hr);
-
- hr = IDirect3DDevice9_EndScene(device);
- ok(hr == D3D_OK, "IDirect3DDevice9_EndScene returned: %08x\n", hr);
-}
-
-static void setup_device9(IDirect3DDevice9 *device, IDirect3DSurface9 **render_target,
- IDirect3DSurface9 **readback, D3DFORMAT format, unsigned int width, unsigned int height,
- IDirect3DVertexShader9 *vshader, IDirect3DPixelShader9 *pshader)
-{
- HRESULT hr;
- hr = IDirect3DDevice9_CreateRenderTarget(device, width, height, format,
- D3DMULTISAMPLE_NONE, 0, FALSE, render_target, NULL);
- ok(hr == D3D_OK, "IDirect3DDevice9_CreateRenderTarget returned: %08x\n", hr);
-
- /* The Direct3D 9 docs state that we cannot lock a render target surface,
- instead we must copy the render target onto this surface to lock it */
- hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, width, height, format,
- D3DPOOL_SYSTEMMEM, readback, NULL);
- ok(hr == D3D_OK, "IDirect3DDevice9_CreateOffscreenPlainSurface returned: %08x\n", hr);
-
- hr = IDirect3DDevice9_SetRenderTarget(device, 0, *render_target);
- ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderTarget returned: %08x\n", hr);
-
- hr = IDirect3DDevice9_SetVertexShader(device, vshader);
- ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShader returned: %08x\n", hr);
- hr = IDirect3DDevice9_SetPixelShader(device, pshader);
- ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader returned: %08x\n", hr);
-}
-
-static BOOL colors_match(D3DXCOLOR a, D3DXCOLOR b, float epsilon)
-{
- return (fabs(a.r - b.r) < epsilon && fabs(a.g - b.g) < epsilon && fabs(a.b - b.b) < epsilon &&
- fabs(a.a - b.a) < epsilon);
-}
-
-/* Compute a shader on a width by height buffer and probes certain locations
- to see if they are as expected. */
-static void compute_shader_probe9(IDirect3DDevice9 *device, IDirect3DVertexShader9 *vshader,
- IDirect3DPixelShader9 *pshader, IDirect3DVertexBuffer9 *quad_geometry,
- const struct hlsl_probe_info *probes, unsigned int count,
- unsigned int width, unsigned int height, unsigned int line_number)
-{
- IDirect3DSurface9 *render_target;
- IDirect3DSurface9 *readback;
-
- HRESULT hr;
- D3DLOCKED_RECT lr;
- D3DXCOLOR *pbits_data;
- unsigned int i;
-
- setup_device9(device, &render_target, &readback, D3DFMT_A32B32G32R32F,
- width, height, vshader, pshader);
-
- /* Draw the quad with the shader and read back the data */
- draw_quad_with_shader9(device, quad_geometry);
- IDirect3DDevice9_GetRenderTargetData(device, render_target, readback);
- hr = IDirect3DSurface9_LockRect(readback, &lr, NULL, D3DLOCK_READONLY);
- ok(hr == D3D_OK, "IDirect3DSurface9_LockRect returned: %08x\n", hr);
- pbits_data = lr.pBits;
-
- /* Now go through the probes and check each one */
- for (i = 0; i < count; i++, probes++) {
- int index = probes->x + (probes->y * lr.Pitch / sizeof(D3DXCOLOR));
- ok(colors_match(probes->c, pbits_data[index], probes->epsilon),
- "Line %d: At (%d, %d): %s: Expected (%.04f,%.04f,%.04f, %.04f), got "
- "(%.04f,%.04f,%.04f,%.04f)\n", line_number, probes->x, probes->y, probes->message,
- probes->c.r, probes->c.g, probes->c.b, probes->c.a, pbits_data[index].r,
- pbits_data[index].g, pbits_data[index].b, pbits_data[index].a);
- }
-
- hr = IDirect3DSurface9_UnlockRect(readback);
- ok(hr == D3D_OK, "IDirect3DSurface9_UnlockRect returned: %08x\n", hr);
-
- /* We now present the scene. This is mostly for debugging purposes, since GetRenderTargetData
- also waits for drawing commands to complete. The reason this call is here and not in a
- draw function is because the contents of the render target surface are invalidated after
- this call. */
- hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
- ok(hr == D3D_OK, "IDirect3DDevice9_Present returned: %08x\n", hr);
-
- IDirect3DSurface9_Release(render_target);
- IDirect3DSurface9_Release(readback);
-}
-
-/* Now the actual test functions */
-static void test_swizzle(IDirect3DDevice9 *device, IDirect3DVertexBuffer9 *quad_geometry,
- IDirect3DVertexShader9 *vshader_passthru)
-{
- static const struct hlsl_probe_info probes[] =
- {
- {0, 0, {0.0101f, 0.0303f, 0.0202f, 0.0404f}, 0.0001f, "swizzle_test"}
- };
-
- static const char *swizzle_test_shader =
- "uniform float4 color;\n"
- "float4 test(): COLOR\n"
- "{\n"
- " float4 ret = color;\n"
- " ret.gb = ret.ra;\n"
- " ret.ra = float2(0.0101, 0.0404);\n"
- " return ret;\n"
- "}";
-
- ID3DXConstantTable *constants;
- IDirect3DPixelShader9 *pshader;
-
- pshader = compile_pixel_shader9(device, swizzle_test_shader, "ps_2_0", &constants);
- if (pshader != NULL)
- {
- set_float4_d3d9(device, constants, "color", 0.0303f, 0.0f, 0.0f, 0.0202f);
-
- compute_shader_probe9(device, vshader_passthru, pshader, quad_geometry,
- probes, ARRAY_SIZE(probes), 1, 1, __LINE__);
-
- ID3DXConstantTable_Release(constants);
- IDirect3DPixelShader9_Release(pshader);
- }
-}
-
-static void test_math(IDirect3DDevice9 *device, IDirect3DVertexBuffer9 *quad_geometry,
- IDirect3DVertexShader9 *vshader_passthru)
-{
- /* Tests order of operations */
- static const float u = 2.5f, v = 0.3f, w = 0.2f, x = 0.7f, y = 0.1f, z = 1.5f;
-
- static const struct hlsl_probe_info probes[] =
- {
- {0, 0, {-12.4300f, 9.8333f, 1.6000f, 34.9999f}, 0.0001f,
- "order of operations test"}
- };
-
- static const char *order_of_operations_shader =
- "float4 test(uniform float u, uniform float v, uniform float w, uniform float x,\n"
- " uniform float y, uniform float z): COLOR\n"
- "{\n"
- " return float4(x * y - z / w + --u / -v,\n"
- " z * x / y + w / -v,\n"
- " u + v - w,\n"
- " x / y / w);\n"
- "}";
-
- ID3DXConstantTable *constants;
- IDirect3DPixelShader9 *pshader;
-
- pshader = compile_pixel_shader9(device, order_of_operations_shader, "ps_2_0", &constants);
- if (pshader != NULL)
- {
- ID3DXConstantTable_SetFloat(constants, device, "$u", u);
- ID3DXConstantTable_SetFloat(constants, device, "$v", v);
- ID3DXConstantTable_SetFloat(constants, device, "$w", w);
- ID3DXConstantTable_SetFloat(constants, device, "$x", x);
- ID3DXConstantTable_SetFloat(constants, device, "$y", y);
- ID3DXConstantTable_SetFloat(constants, device, "$z", z);
-
- compute_shader_probe9(device, vshader_passthru, pshader, quad_geometry,
- probes, ARRAY_SIZE(probes), 1, 1, __LINE__);
-
- ID3DXConstantTable_Release(constants);
- IDirect3DPixelShader9_Release(pshader);
- }
-}
-
-static void test_conditionals(IDirect3DDevice9 *device, IDirect3DVertexBuffer9 *quad_geometry,
- IDirect3DVertexShader9 *vshader_passthru)
-{
- static const struct hlsl_probe_info if_greater_probes[] =
- {
- { 0, 0, {0.9f, 0.8f, 0.7f, 0.6f}, 0.0001f, "if greater test"},
- { 5, 0, {0.9f, 0.8f, 0.7f, 0.6f}, 0.0001f, "if greater test"},
- {10, 0, {0.9f, 0.8f, 0.7f, 0.6f}, 0.0001f, "if greater test"},
- {15, 0, {0.9f, 0.8f, 0.7f, 0.6f}, 0.0001f, "if greater test"},
- {25, 0, {0.1f, 0.2f, 0.3f, 0.4f}, 0.0001f, "if greater test"},
- {30, 0, {0.1f, 0.2f, 0.3f, 0.4f}, 0.0001f, "if greater test"}
- };
-
- static const char *if_greater_shader =
- "float4 test(float2 pos: TEXCOORD0): COLOR\n"
- "{\n"
- " if((pos.x * 32.0) > 20.0)\n"
- " return float4(0.1, 0.2, 0.3, 0.4);\n"
- " else\n"
- " return float4(0.9, 0.8, 0.7, 0.6);\n"
- "}";
-
- static const struct hlsl_probe_info ternary_operator_probes[] =
- {
- {0, 0, {0.50f, 0.25f, 0.50f, 0.75f}, 0.00001f, "ternary operator test"},
- {1, 0, {0.50f, 0.25f, 0.50f, 0.75f}, 0.00001f, "ternary operator test"},
- {2, 0, {0.50f, 0.25f, 0.50f, 0.75f}, 0.00001f, "ternary operator test"},
- {3, 0, {0.50f, 0.25f, 0.50f, 0.75f}, 0.00001f, "ternary operator test"},
- {4, 0, {0.60f, 0.80f, 0.10f, 0.20f}, 0.00001f, "ternary operator test"},
- {5, 0, {0.60f, 0.80f, 0.10f, 0.20f}, 0.00001f, "ternary operator test"},
- {6, 0, {0.60f, 0.80f, 0.10f, 0.20f}, 0.00001f, "ternary operator test"},
- {7, 0, {0.60f, 0.80f, 0.10f, 0.20f}, 0.00001f, "ternary operator test"}
- };
-
- static const char *ternary_operator_shader =
- "float4 test(float2 pos: TEXCOORD0): COLOR\n"
- "{\n"
- " return (pos.x < 0.5?float4(0.5, 0.25, 0.5, 0.75):float4(0.6, 0.8, 0.1, 0.2));\n"
- "}";
-
- ID3DXConstantTable *constants;
- IDirect3DPixelShader9 *pshader;
-
- pshader = compile_pixel_shader9(device, if_greater_shader, "ps_2_0", &constants);
- if (pshader != NULL)
- {
- compute_shader_probe9(device, vshader_passthru, pshader, quad_geometry, if_greater_probes,
- ARRAY_SIZE(if_greater_probes), 32, 1, __LINE__);
-
- ID3DXConstantTable_Release(constants);
- IDirect3DPixelShader9_Release(pshader);
- }
-
- pshader = compile_pixel_shader9(device, ternary_operator_shader, "ps_2_0", &constants);
- if (pshader != NULL)
- {
- compute_shader_probe9(device, vshader_passthru, pshader, quad_geometry, ternary_operator_probes,
- ARRAY_SIZE(ternary_operator_probes), 8, 1, __LINE__);
-
- ID3DXConstantTable_Release(constants);
- IDirect3DPixelShader9_Release(pshader);
- }
-}
-
-static void test_float_vectors(IDirect3DDevice9 *device, IDirect3DVertexBuffer9 *quad_geometry,
- IDirect3DVertexShader9 *vshader_passthru)
-{
- static const struct hlsl_probe_info vec4_indexing_test1_probes[] =
- {
- {0, 0, {0.020f, 0.245f, 0.351f, 1.000f}, 0.0001f, "vec4 indexing test 1"}
- };
-
- static const char *vec4_indexing_test1_shader =
- "float4 test(): COLOR\n"
- "{\n"
- " float4 color;\n"
- " color[0] = 0.020;\n"
- " color[1] = 0.245;\n"
- " color[2] = 0.351;\n"
- " color[3] = 1.0;\n"
- " return color;\n"
- "}";
-
- static const struct hlsl_probe_info vec4_indexing_test2_probes[] =
- {
- {0, 0, {0.5f, 0.3f, 0.8f, 0.2f}, 0.0001f, "vec4 indexing test 2"}
- };
-
- /* We have this uniform i here so the compiler can't optimize */
- static const char *vec4_indexing_test2_shader =
- "uniform int i;\n"
- "float4 test(): COLOR\n"
- "{\n"
- " float4 color = float4(0.5, 0.4, 0.3, 0.2);\n"
- " color.g = color[i];\n"
- " color.b = 0.8;\n"
- " return color;\n"
- "}";
-
- ID3DXConstantTable *constants;
- IDirect3DPixelShader9 *pshader;
-
- pshader = compile_pixel_shader9(device, vec4_indexing_test1_shader, "ps_2_0", &constants);
- if (pshader != NULL)
- {
- compute_shader_probe9(device, vshader_passthru, pshader, quad_geometry, vec4_indexing_test1_probes,
- ARRAY_SIZE(vec4_indexing_test1_probes), 1, 1, __LINE__);
-
- ID3DXConstantTable_Release(constants);
- IDirect3DPixelShader9_Release(pshader);
- }
-
- pshader = compile_pixel_shader9(device, vec4_indexing_test2_shader, "ps_2_0", &constants);
- if (pshader != NULL)
- {
- ID3DXConstantTable_SetInt(constants, device, "i", 2);
-
- compute_shader_probe9(device, vshader_passthru, pshader, quad_geometry, vec4_indexing_test2_probes,
- ARRAY_SIZE(vec4_indexing_test2_probes), 32, 1, __LINE__);
-
- ID3DXConstantTable_Release(constants);
- IDirect3DPixelShader9_Release(pshader);
- }
-}
-
-static void test_trig(IDirect3DDevice9 *device, IDirect3DVertexBuffer9 *quad_geometry,
- IDirect3DVertexShader9 *vshader_passthru)
-{
- static const struct hlsl_probe_info sincos_probes[] =
- {
- {0, 0, {0.5000f, 1.0000f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {1, 0, {0.5975f, 0.9904f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {2, 0, {0.6913f, 0.9620f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {3, 0, {0.7778f, 0.9160f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {4, 0, {0.8536f, 0.8536f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {5, 0, {0.9157f, 0.7778f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {6, 0, {0.9620f, 0.6913f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {7, 0, {0.9904f, 0.5975f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {8, 0, {1.0000f, 0.5000f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {9, 0, {0.9904f, 0.4025f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {10, 0, {0.9619f, 0.3087f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {11, 0, {0.9157f, 0.2222f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {12, 0, {0.8536f, 0.1464f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {13, 0, {0.7778f, 0.0843f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {14, 0, {0.6913f, 0.0381f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {15, 0, {0.5975f, 0.0096f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {16, 0, {0.5000f, 0.0000f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {17, 0, {0.4025f, 0.0096f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {18, 0, {0.3087f, 0.0381f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {19, 0, {0.2222f, 0.0843f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {20, 0, {0.1464f, 0.1464f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {21, 0, {0.0843f, 0.2222f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {22, 0, {0.0381f, 0.3087f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {23, 0, {0.0096f, 0.4025f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {24, 0, {0.0000f, 0.5000f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {25, 0, {0.0096f, 0.5975f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {26, 0, {0.0381f, 0.6913f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {27, 0, {0.0843f, 0.7778f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {28, 0, {0.1464f, 0.8536f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {29, 0, {0.2222f, 0.9157f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {30, 0, {0.3087f, 0.9619f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- {31, 0, {0.4025f, 0.9904f, 0.0f, 0.0f}, 0.001f, "sin/cos test"},
- };
-
- static const char *sincos_shader =
- "float4 test(float x: TEXCOORD0): COLOR\n"
- "{\n"
- " const float pi2 = 6.2831853;\n"
- " float calcd_sin = (sin(x * pi2) + 1)/2;\n"
- " float calcd_cos = (cos(x * pi2) + 1)/2;\n"
- " return float4(calcd_sin, calcd_cos, 0, 0);\n"
- "}";
-
- ID3DXConstantTable *constants;
- IDirect3DPixelShader9 *pshader;
-
- pshader = compile_pixel_shader9(device, sincos_shader, "ps_2_0", &constants);
- if (pshader != NULL)
- {
- compute_shader_probe9(device, vshader_passthru, pshader, quad_geometry, sincos_probes,
- ARRAY_SIZE(sincos_probes), 32, 1, __LINE__);
-
- ID3DXConstantTable_Release(constants);
- IDirect3DPixelShader9_Release(pshader);
- }
-}
-
-static void test_fail(IDirect3DDevice9 *device, IDirect3DVertexBuffer9 *qquad_geometry,
- IDirect3DVertexShader9 *vshader_passthru)
-{
- static const char *tests[] =
- {
- "float4 test(float2 pos: TEXCOORD0) : COLOR\n"
- "{\n"
- " return y;\n"
- "}",
-
- "float4 test(float2 pos: TEXCOORD0) : COLOR\n"
- "{\n"
- " float4 x = float4(0, 0, 0, 0);\n"
- " x.xzzx = float4(1, 2, 3, 4);\n"
- " return x;\n"
- "}",
-
- "float4 test(float2 pos: TEXCOORD0) : COLOR\n"
- "{\n"
- " float4 x = pos;\n"
- " return x;\n"
- "}",
-
- "float4 test(float2 pos, TEXCOORD0) ; COLOR\n"
- "{\n"
- " pos = float4 x;\n"
- " mul(float4(5, 4, 3, 2), mvp) = x;\n"
- " return float4;\n"
- "}",
-
- "float4 563r(float2 45s: TEXCOORD0) : COLOR\n"
- "{\n"
- " float2 x = 45s;\n"
- " return float4(x.x, x.y, 0, 0);\n"
- "}",
-
- "float4 test(float2 pos: TEXCOORD0) : COLOR\n"
- "{\n"
- " struct { int b,c; } x = {0};\n"
- " return y;\n"
- "}",
-
- "float4 test(float2 pos: TEXCOORD0) : COLOR\n"
- "{\n"
- " struct {} x = {};\n"
- " return y;\n"
- "}",
- };
-
- ID3D10Blob *compiled, *errors;
- unsigned int i;
- HRESULT hr;
-
- for (i = 0; i < ARRAY_SIZE(tests); ++i)
- {
- compiled = errors = NULL;
- hr = ppD3DCompile(tests[i], strlen(tests[i]), NULL, NULL, NULL, "test", "ps_2_0", 0, 0, &compiled, &errors);
- ok(hr == E_FAIL, "Test %u, got unexpected hr %#x.\n", i, hr);
- ok(!!errors, "Test %u, expected non-NULL error blob.\n", i);
- ok(!compiled, "Test %u, expected no compiled shader blob.\n", i);
- ID3D10Blob_Release(errors);
- }
-}
-
-static BOOL load_d3dcompiler(void)
-{
- HMODULE module;
-
-#if D3D_COMPILER_VERSION == 47
- if (!(module = LoadLibraryA("d3dcompiler_47.dll"))) return FALSE;
-#else
- if (!(module = LoadLibraryA("d3dcompiler_43.dll"))) return FALSE;
-#endif
-
- ppD3DCompile = (void*)GetProcAddress(module, "D3DCompile");
- return TRUE;
-}
-
-START_TEST(hlsl)
-{
- D3DCAPS9 caps;
- ULONG refcount;
- IDirect3DDevice9 *device;
- IDirect3DVertexDeclaration9 *vdeclaration;
- IDirect3DVertexBuffer9 *quad_geometry;
- IDirect3DVertexShader9 *vshader_passthru;
- HMODULE mod;
-
- if (!load_d3dcompiler())
- {
- win_skip("Could not load DLL.\n");
- return;
- }
-
- if (!(mod = LoadLibraryA("d3dx9_36.dll")))
- {
- win_skip("Failed to load d3dx9_36.dll.\n");
- return;
- }
- pD3DXGetShaderConstantTable = (void *)GetProcAddress(mod, "D3DXGetShaderConstantTable");
- pD3DXMatrixOrthoLH = (void *)GetProcAddress(mod, "D3DXMatrixOrthoLH");
-
- device = init_d3d9(&vdeclaration, &quad_geometry, &vshader_passthru);
- if (!device) return;
-
- /* Make sure we support pixel shaders, before trying to compile them! */
- /* Direct3D 9 (Shader model 1-3 tests) */
- IDirect3DDevice9_GetDeviceCaps(device, &caps);
- if (caps.PixelShaderVersion >= D3DPS_VERSION(2, 0))
- {
- todo_wine
- {
- test_swizzle(device, quad_geometry, vshader_passthru);
- test_math(device, quad_geometry, vshader_passthru);
- test_conditionals(device, quad_geometry, vshader_passthru);
- test_float_vectors(device, quad_geometry, vshader_passthru);
- test_trig(device, quad_geometry, vshader_passthru);
- test_fail(device, quad_geometry, vshader_passthru);
- }
- } else skip("no pixel shader support\n");
-
- /* Reference counting sanity checks */
- if (vshader_passthru)
- {
- refcount = IDirect3DVertexShader9_Release(vshader_passthru);
- ok(!refcount, "Pass-through vertex shader has %u references left\n", refcount);
- }
-
- refcount = IDirect3DVertexBuffer9_Release(quad_geometry);
- ok(!refcount, "Vertex buffer has %u references left\n", refcount);
-
- refcount = IDirect3DVertexDeclaration9_Release(vdeclaration);
- ok(!refcount, "Vertex declaration has %u references left\n", refcount);
-
- refcount = IDirect3DDevice9_Release(device);
- ok(!refcount, "Device has %u references left\n", refcount);
-}
diff --git a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c
new file mode 100644
index 00000000000..79f54d200e2
--- /dev/null
+++ b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c
@@ -0,0 +1,678 @@
+/*
+ * Copyright (C) 2010 Travis Athougies
+ * Copyright (C) 2020 Zebediah Figura for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+#define COBJMACROS
+#include "wine/test.h"
+#include "d3dx9.h"
+#include "d3dcompiler.h"
+
+#include <math.h>
+
+static pD3DCompile ppD3DCompile;
+
+static HRESULT (WINAPI *pD3DXGetShaderConstantTable)(const DWORD *byte_code, ID3DXConstantTable **constant_table);
+
+struct vec2
+{
+ float x, y;
+};
+
+struct vec4
+{
+ float x, y, z, w;
+};
+
+#define compile_shader(a, b) compile_shader_(__LINE__, a, b)
+static ID3D10Blob *compile_shader_(unsigned int line, const char *source, const char *target)
+{
+ ID3D10Blob *blob = NULL, *errors = NULL;
+ HRESULT hr;
+
+ hr = ppD3DCompile(source, strlen(source), NULL, NULL, NULL, "main", target, 0, 0, &blob, &errors);
+ ok_(__FILE__, line)(hr == D3D_OK, "Failed to compile shader, hr %#x.\n", hr);
+ if (errors)
+ {
+ if (winetest_debug > 1)
+ trace_(__FILE__, line)("%s\n", (char *)ID3D10Blob_GetBufferPointer(errors));
+ ID3D10Blob_Release(errors);
+ }
+ return blob;
+}
+
+static IDirect3DDevice9 *create_device(HWND window)
+{
+ D3DPRESENT_PARAMETERS present_parameters =
+ {
+ .Windowed = TRUE,
+ .hDeviceWindow = window,
+ .SwapEffect = D3DSWAPEFFECT_DISCARD,
+ .BackBufferWidth = 640,
+ .BackBufferHeight = 480,
+ .BackBufferFormat = D3DFMT_A8R8G8B8,
+ };
+ IDirect3DDevice9 *device;
+ IDirect3DSurface9 *rt;
+ IDirect3D9 *d3d;
+ D3DCAPS9 caps;
+ HRESULT hr;
+
+ d3d = Direct3DCreate9(D3D_SDK_VERSION);
+ ok(!!d3d, "Failed to create a D3D object.\n");
+
+ hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
+ D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device);
+ IDirect3D9_Release(d3d);
+ if (FAILED(hr))
+ {
+ skip("Failed to create a 3D device, hr %#x.\n", hr);
+ return NULL;
+ }
+
+ hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
+ ok(hr == D3D_OK, "Failed to get device caps, hr %#x.\n", hr);
+ if (caps.PixelShaderVersion < D3DPS_VERSION(2, 0) || caps.VertexShaderVersion < D3DVS_VERSION(2, 0))
+ {
+ skip("No shader model 2 support.\n");
+ IDirect3DDevice9_Release(device);
+ return NULL;
+ }
+
+ if (FAILED(hr = IDirect3DDevice9_CreateRenderTarget(device, 640, 480, D3DFMT_A32B32G32R32F,
+ D3DMULTISAMPLE_NONE, 0, FALSE, &rt, NULL)))
+ {
+ skip("Failed to create an A32B32G32R32F surface, hr %#x.\n", hr);
+ IDirect3DDevice9_Release(device);
+ return NULL;
+ }
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
+ ok(hr == D3D_OK, "Failed to set render target, hr %#x.\n", hr);
+ IDirect3DSurface9_Release(rt);
+
+ return device;
+}
+
+struct test_context
+{
+ IDirect3DDevice9 *device;
+ HWND window;
+};
+
+#define init_test_context(a) init_test_context_(__LINE__, a)
+static BOOL init_test_context_(unsigned int line, struct test_context *context)
+{
+ RECT rect = {0, 0, 640, 480};
+
+ AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);
+ context->window = CreateWindowA("static", "d3dcompiler_test", WS_OVERLAPPEDWINDOW,
+ 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
+ ok(!!context->window, "Failed to create a window.\n");
+
+ if (!(context->device = create_device(context->window)))
+ {
+ DestroyWindow(context->window);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+#define release_test_context(context) release_test_context_(__LINE__, context)
+static void release_test_context_(unsigned int line, struct test_context *context)
+{
+ ULONG ref = IDirect3DDevice9_Release(context->device);
+ ok_(__FILE__, line)(!ref, "Device has %u references left.\n", ref);
+ DestroyWindow(context->window);
+}
+
+#define draw_quad(device, ps_code) draw_quad_(__LINE__, device, ps_code)
+static void draw_quad_(unsigned int line, IDirect3DDevice9 *device, ID3D10Blob *ps_code)
+{
+ IDirect3DVertexDeclaration9 *vertex_declaration;
+ IDirect3DVertexShader9 *vs;
+ IDirect3DPixelShader9 *ps;
+ ID3D10Blob *vs_code;
+ HRESULT hr;
+
+ static const D3DVERTEXELEMENT9 decl_elements[] =
+ {
+ {0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
+ {0, 8, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
+ D3DDECL_END()
+ };
+
+ static const struct
+ {
+ struct vec2 position;
+ struct vec2 t0;
+ }
+ quad[] =
+ {
+ {{-1.0f, -1.0f}, {0.0f, 1.0f}},
+ {{-1.0f, 1.0f}, {0.0f, 0.0f}},
+ {{ 1.0f, -1.0f}, {1.0f, 1.0f}},
+ {{ 1.0f, 1.0f}, {1.0f, 0.0f}},
+ };
+
+ static const char vs_source[] =
+ "float4 main(float4 pos : POSITION, inout float2 texcoord : TEXCOORD0) : POSITION\n"
+ "{\n"
+ " return pos;\n"
+ "}";
+
+ hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &vertex_declaration);
+ ok_(__FILE__, line)(hr == D3D_OK, "Failed to create vertex declaration, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_SetVertexDeclaration(device, vertex_declaration);
+ ok_(__FILE__, line)(hr == D3D_OK, "Failed to set vertex declaration, hr %#x.\n", hr);
+
+ vs_code = compile_shader(vs_source, "vs_2_0");
+
+ hr = IDirect3DDevice9_CreateVertexShader(device, ID3D10Blob_GetBufferPointer(vs_code), &vs);
+ ok_(__FILE__, line)(hr == D3D_OK, "Failed to create vertex shader, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_SetVertexShader(device, vs);
+ ok_(__FILE__, line)(hr == D3D_OK, "Failed to set vertex shader, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_CreatePixelShader(device, ID3D10Blob_GetBufferPointer(ps_code), &ps);
+ ok_(__FILE__, line)(hr == D3D_OK, "Failed to create pixel shader, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_SetPixelShader(device, ps);
+ ok_(__FILE__, line)(hr == D3D_OK, "Failed to set pixel shader, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_BeginScene(device);
+ ok_(__FILE__, line)(hr == D3D_OK, "Failed to draw, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
+ ok_(__FILE__, line)(hr == D3D_OK, "Failed to draw, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_EndScene(device);
+ ok_(__FILE__, line)(hr == D3D_OK, "Failed to draw, hr %#x.\n", hr);
+
+ IDirect3DVertexDeclaration9_Release(vertex_declaration);
+ IDirect3DVertexShader9_Release(vs);
+ IDirect3DPixelShader9_Release(ps);
+ ID3D10Blob_Release(vs_code);
+}
+
+struct readback
+{
+ IDirect3DSurface9 *surface;
+ D3DLOCKED_RECT rect;
+};
+
+static void init_readback(IDirect3DDevice9 *device, struct readback *rb)
+{
+ IDirect3DSurface9 *rt;
+ D3DSURFACE_DESC desc;
+ HRESULT hr;
+
+ hr = IDirect3DDevice9Ex_GetRenderTarget(device, 0, &rt);
+ ok(hr == D3D_OK, "Failed to get render target, hr %#x.\n", hr);
+
+ hr = IDirect3DSurface9_GetDesc(rt, &desc);
+ ok(hr == D3D_OK, "Failed to get surface desc, hr %#x.\n", hr);
+ hr = IDirect3DDevice9Ex_CreateOffscreenPlainSurface(device, desc.Width, desc.Height,
+ desc.Format, D3DPOOL_SYSTEMMEM, &rb->surface, NULL);
+ ok(hr == D3D_OK, "Failed to create surface, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9Ex_GetRenderTargetData(device, rt, rb->surface);
+ ok(hr == D3D_OK, "Failed to get render target data, hr %#x.\n", hr);
+
+ hr = IDirect3DSurface9_LockRect(rb->surface, &rb->rect, NULL, D3DLOCK_READONLY);
+ ok(hr == D3D_OK, "Failed to lock surface, hr %#x.\n", hr);
+
+ IDirect3DSurface9_Release(rt);
+}
+
+static const struct vec4 *get_readback_vec4(const struct readback *rb, unsigned int x, unsigned int y)
+{
+ return (struct vec4 *)((BYTE *)rb->rect.pBits + y * rb->rect.Pitch + x * sizeof(struct vec4));
+}
+
+static void release_readback(struct readback *rb)
+{
+ IDirect3DSurface9_UnlockRect(rb->surface);
+ IDirect3DSurface9_Release(rb->surface);
+}
+
+static struct vec4 get_color_vec4(IDirect3DDevice9 *device, unsigned int x, unsigned int y)
+{
+ struct readback rb;
+ struct vec4 ret;
+
+ init_readback(device, &rb);
+ ret = *get_readback_vec4(&rb, x, y);
+ release_readback(&rb);
+
+ return ret;
+}
+
+static BOOL compare_float(float f, float g, unsigned int ulps)
+{
+ int x = *(int *)&f;
+ int y = *(int *)&g;
+
+ if (x < 0)
+ x = INT_MIN - x;
+ if (y < 0)
+ y = INT_MIN - y;
+
+ if (abs(x - y) > ulps)
+ return FALSE;
+
+ return TRUE;
+}
+
+static BOOL compare_vec4(const struct vec4 *vec, float x, float y, float z, float w, unsigned int ulps)
+{
+ return compare_float(vec->x, x, ulps)
+ && compare_float(vec->y, y, ulps)
+ && compare_float(vec->z, z, ulps)
+ && compare_float(vec->w, w, ulps);
+}
+
+static void test_swizzle(void)
+{
+ static const D3DXVECTOR4 color = {0.0303f, 0.0f, 0.0f, 0.0202f};
+ struct test_context test_context;
+ ID3DXConstantTable *constants;
+ ID3D10Blob *ps_code = NULL;
+ IDirect3DDevice9 *device;
+ struct vec4 v;
+ HRESULT hr;
+
+ static const char ps_source[] =
+ "uniform float4 color;\n"
+ "float4 main() : COLOR\n"
+ "{\n"
+ " float4 ret = color;\n"
+ " ret.gb = ret.ra;\n"
+ " ret.ra = float2(0.0101, 0.0404);\n"
+ " return ret;\n"
+ "}";
+
+ if (!init_test_context(&test_context))
+ return;
+ device = test_context.device;
+
+ todo_wine ps_code = compile_shader(ps_source, "ps_2_0");
+ if (ps_code)
+ {
+ hr = pD3DXGetShaderConstantTable(ID3D10Blob_GetBufferPointer(ps_code), &constants);
+ ok(hr == D3D_OK, "Failed to get constant table, hr %#x.\n", hr);
+ hr = ID3DXConstantTable_SetVector(constants, device, "color", &color);
+ ok(hr == D3D_OK, "Failed to set constant, hr %#x.\n", hr);
+ ID3DXConstantTable_Release(constants);
+
+ draw_quad(device, ps_code);
+
+ v = get_color_vec4(device, 0, 0);
+ ok(compare_vec4(&v, 0.0101f, 0.0303f, 0.0202f, 0.0404f, 0),
+ "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
+
+ ID3D10Blob_Release(ps_code);
+ }
+ release_test_context(&test_context);
+}
+
+static void test_math(void)
+{
+ struct test_context test_context;
+ ID3DXConstantTable *constants;
+ ID3D10Blob *ps_code = NULL;
+ IDirect3DDevice9 *device;
+ struct vec4 v;
+ HRESULT hr;
+
+ static const char ps_source[] =
+ "float4 main(uniform float u, uniform float v, uniform float w, uniform float x,\n"
+ " uniform float y, uniform float z): COLOR\n"
+ "{\n"
+ " return float4(x * y - z / w + --u / -v,\n"
+ " z * x / y + w / -v,\n"
+ " u + v - w,\n"
+ " x / y / w);\n"
+ "}";
+
+ if (!init_test_context(&test_context))
+ return;
+ device = test_context.device;
+
+ todo_wine ps_code = compile_shader(ps_source, "ps_2_0");
+ if (ps_code)
+ {
+ hr = pD3DXGetShaderConstantTable(ID3D10Blob_GetBufferPointer(ps_code), &constants);
+ ok(hr == D3D_OK, "Failed to get constant table, hr %#x.\n", hr);
+ hr = ID3DXConstantTable_SetFloat(constants, device, "$u", 2.5f);
+ ok(hr == D3D_OK, "Failed to set constant, hr %#x.\n", hr);
+ hr = ID3DXConstantTable_SetFloat(constants, device, "$v", 0.3f);
+ ok(hr == D3D_OK, "Failed to set constant, hr %#x.\n", hr);
+ hr = ID3DXConstantTable_SetFloat(constants, device, "$w", 0.2f);
+ ok(hr == D3D_OK, "Failed to set constant, hr %#x.\n", hr);
+ hr = ID3DXConstantTable_SetFloat(constants, device, "$x", 0.7f);
+ ok(hr == D3D_OK, "Failed to set constant, hr %#x.\n", hr);
+ hr = ID3DXConstantTable_SetFloat(constants, device, "$y", 0.1f);
+ ok(hr == D3D_OK, "Failed to set constant, hr %#x.\n", hr);
+ hr = ID3DXConstantTable_SetFloat(constants, device, "$z", 1.5f);
+ ok(hr == D3D_OK, "Failed to set constant, hr %#x.\n", hr);
+ ID3DXConstantTable_Release(constants);
+
+ draw_quad(device, ps_code);
+
+ v = get_color_vec4(device, 0, 0);
+ ok(compare_vec4(&v, -12.43f, 9.833333f, 1.6f, 35.0f, 1),
+ "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
+
+ ID3D10Blob_Release(ps_code);
+ }
+ release_test_context(&test_context);
+}
+
+static void test_conditionals(void)
+{
+ struct test_context test_context;
+ ID3D10Blob *ps_code = NULL;
+ IDirect3DDevice9 *device;
+ const struct vec4 *v;
+ struct readback rb;
+ unsigned int i;
+
+ static const char ps_if_source[] =
+ "float4 main(float2 pos : TEXCOORD0) : COLOR\n"
+ "{\n"
+ " if((pos.x * 640.0) > 200.0)\n"
+ " return float4(0.1, 0.2, 0.3, 0.4);\n"
+ " else\n"
+ " return float4(0.9, 0.8, 0.7, 0.6);\n"
+ "}";
+
+ static const char ps_ternary_source[] =
+ "float4 main(float2 pos : TEXCOORD0) : COLOR\n"
+ "{\n"
+ " return (pos.x < 0.5 ? float4(0.5, 0.25, 0.5, 0.75) : float4(0.6, 0.8, 0.1, 0.2));\n"
+ "}";
+
+ if (!init_test_context(&test_context))
+ return;
+ device = test_context.device;
+
+ todo_wine ps_code = compile_shader(ps_if_source, "ps_2_0");
+ if (ps_code)
+ {
+ draw_quad(device, ps_code);
+ init_readback(device, &rb);
+
+ for (i = 0; i < 200; i += 40)
+ {
+ v = get_readback_vec4(&rb, i, 0);
+ ok(compare_vec4(v, 0.9f, 0.8f, 0.7f, 0.6f, 0),
+ "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v->x, v->y, v->z, v->w);
+ }
+
+ for (i = 240; i < 640; i += 40)
+ {
+ v = get_readback_vec4(&rb, i, 0);
+ ok(compare_vec4(v, 0.1f, 0.2f, 0.3f, 0.4f, 0),
+ "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v->x, v->y, v->z, v->w);
+ }
+
+ release_readback(&rb);
+ ID3D10Blob_Release(ps_code);
+ }
+
+ todo_wine ps_code = compile_shader(ps_ternary_source, "ps_2_0");
+ if (ps_code)
+ {
+ draw_quad(device, ps_code);
+ init_readback(device, &rb);
+
+ for (i = 0; i < 320; i += 40)
+ {
+ v = get_readback_vec4(&rb, i, 0);
+ ok(compare_vec4(v, 0.5f, 0.25f, 0.5f, 0.75f, 0),
+ "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v->x, v->y, v->z, v->w);
+ }
+
+ for (i = 360; i < 640; i += 40)
+ {
+ v = get_readback_vec4(&rb, i, 0);
+ ok(compare_vec4(v, 0.6f, 0.8f, 0.1f, 0.2f, 0),
+ "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v->x, v->y, v->z, v->w);
+ }
+
+ release_readback(&rb);
+ ID3D10Blob_Release(ps_code);
+ }
+
+ release_test_context(&test_context);
+}
+
+static void test_float_vectors(void)
+{
+ struct test_context test_context;
+ ID3DXConstantTable *constants;
+ ID3D10Blob *ps_code = NULL;
+ IDirect3DDevice9 *device;
+ struct vec4 v;
+ HRESULT hr;
+
+ static const char ps_indexing_source[] =
+ "float4 main() : COLOR\n"
+ "{\n"
+ " float4 color;\n"
+ " color[0] = 0.020;\n"
+ " color[1] = 0.245;\n"
+ " color[2] = 0.351;\n"
+ " color[3] = 1.0;\n"
+ " return color;\n"
+ "}";
+
+ /* A uniform index is used so that the compiler can't optimize. */
+ static const char ps_uniform_indexing_source[] =
+ "uniform int i;\n"
+ "float4 main() : COLOR\n"
+ "{\n"
+ " float4 color = float4(0.5, 0.4, 0.3, 0.2);\n"
+ " color.g = color[i];\n"
+ " color.b = 0.8;\n"
+ " return color;\n"
+ "}";
+
+ if (!init_test_context(&test_context))
+ return;
+ device = test_context.device;
+
+ todo_wine ps_code = compile_shader(ps_indexing_source, "ps_2_0");
+ if (ps_code)
+ {
+ draw_quad(device, ps_code);
+
+ v = get_color_vec4(device, 0, 0);
+ ok(compare_vec4(&v, 0.02f, 0.245f, 0.351f, 1.0f, 0),
+ "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
+
+ ID3D10Blob_Release(ps_code);
+ }
+
+ todo_wine ps_code = compile_shader(ps_uniform_indexing_source, "ps_2_0");
+ if (ps_code)
+ {
+ hr = pD3DXGetShaderConstantTable(ID3D10Blob_GetBufferPointer(ps_code), &constants);
+ ok(hr == D3D_OK, "Failed to get constants, hr %#x.\n", hr);
+ hr = ID3DXConstantTable_SetInt(constants, device, "i", 2);
+ ok(hr == D3D_OK, "Failed to set constant, hr %#x.\n", hr);
+ ID3DXConstantTable_Release(constants);
+ draw_quad(device, ps_code);
+
+ v = get_color_vec4(device, 0, 0);
+ ok(compare_vec4(&v, 0.5f, 0.3f, 0.8f, 0.2f, 0),
+ "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
+
+ ID3D10Blob_Release(ps_code);
+ }
+
+ release_test_context(&test_context);
+}
+
+static void test_trig(void)
+{
+ struct test_context test_context;
+ ID3D10Blob *ps_code = NULL;
+ IDirect3DDevice9 *device;
+ const struct vec4 *v;
+ struct readback rb;
+ unsigned int i;
+
+ static const char ps_source[] =
+ "float4 main(float x : TEXCOORD0) : COLOR\n"
+ "{\n"
+ " const float pi2 = 6.2831853;\n"
+ " float calcd_sin = (sin(x * pi2) + 1)/2;\n"
+ " float calcd_cos = (cos(x * pi2) + 1)/2;\n"
+ " return float4(calcd_sin, calcd_cos, 0, 0);\n"
+ "}";
+
+ if (!init_test_context(&test_context))
+ return;
+ device = test_context.device;
+
+ todo_wine ps_code = compile_shader(ps_source, "ps_2_0");
+ if (ps_code)
+ {
+ draw_quad(device, ps_code);
+ init_readback(device, &rb);
+
+ for (i = 0; i < 32; ++i)
+ {
+ float expect_x = (sinf(i * 2 * M_PI / 32) + 1.0f) / 2.0f;
+ float expect_y = (cosf(i * 2 * M_PI / 32) + 1.0f) / 2.0f;
+ v = get_readback_vec4(&rb, i * 640 / 32, 0);
+ ok(compare_vec4(v, expect_x, expect_y, 0.0f, 0.0f, 4096),
+ "Test %u: Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
+ i, v->x, v->y, v->z, v->w, expect_x, expect_y, 0.0f, 0.0f);
+ }
+
+ release_readback(&rb);
+ ID3D10Blob_Release(ps_code);
+ }
+ release_test_context(&test_context);
+}
+
+static void test_fail(void)
+{
+ static const char *tests[] =
+ {
+ "float4 test(float2 pos: TEXCOORD0) : COLOR\n"
+ "{\n"
+ " return y;\n"
+ "}",
+
+ "float4 test(float2 pos: TEXCOORD0) : COLOR\n"
+ "{\n"
+ " float4 x = float4(0, 0, 0, 0);\n"
+ " x.xzzx = float4(1, 2, 3, 4);\n"
+ " return x;\n"
+ "}",
+
+ "float4 test(float2 pos: TEXCOORD0) : COLOR\n"
+ "{\n"
+ " float4 x = pos;\n"
+ " return x;\n"
+ "}",
+
+ "float4 test(float2 pos, TEXCOORD0) ; COLOR\n"
+ "{\n"
+ " pos = float4 x;\n"
+ " mul(float4(5, 4, 3, 2), mvp) = x;\n"
+ " return float4;\n"
+ "}",
+
+ "float4 563r(float2 45s: TEXCOORD0) : COLOR\n"
+ "{\n"
+ " float2 x = 45s;\n"
+ " return float4(x.x, x.y, 0, 0);\n"
+ "}",
+
+ "float4 test(float2 pos: TEXCOORD0) : COLOR\n"
+ "{\n"
+ " struct { int b,c; } x = {0};\n"
+ " return y;\n"
+ "}",
+
+ "float4 test(float2 pos: TEXCOORD0) : COLOR\n"
+ "{\n"
+ " struct {} x = {};\n"
+ " return y;\n"
+ "}",
+ };
+
+ ID3D10Blob *compiled, *errors;
+ unsigned int i;
+ HRESULT hr;
+
+ for (i = 0; i < ARRAY_SIZE(tests); ++i)
+ {
+ compiled = errors = NULL;
+ hr = ppD3DCompile(tests[i], strlen(tests[i]), NULL, NULL, NULL, "test", "ps_2_0", 0, 0, &compiled, &errors);
+ todo_wine ok(hr == E_FAIL, "Test %u, got unexpected hr %#x.\n", i, hr);
+ todo_wine_if (i == 1) ok(!!errors, "Test %u, expected non-NULL error blob.\n", i);
+ ok(!compiled, "Test %u, expected no compiled shader blob.\n", i);
+ if (errors)
+ ID3D10Blob_Release(errors);
+ }
+}
+
+static BOOL load_d3dcompiler(void)
+{
+ HMODULE module;
+
+#if D3D_COMPILER_VERSION == 47
+ if (!(module = LoadLibraryA("d3dcompiler_47.dll"))) return FALSE;
+#else
+ if (!(module = LoadLibraryA("d3dcompiler_43.dll"))) return FALSE;
+#endif
+
+ ppD3DCompile = (void*)GetProcAddress(module, "D3DCompile");
+ return TRUE;
+}
+
+START_TEST(hlsl_d3d9)
+{
+ HMODULE mod;
+
+ if (!load_d3dcompiler())
+ {
+ win_skip("Could not load DLL.\n");
+ return;
+ }
+
+ if (!(mod = LoadLibraryA("d3dx9_36.dll")))
+ {
+ win_skip("Failed to load d3dx9_36.dll.\n");
+ return;
+ }
+ pD3DXGetShaderConstantTable = (void *)GetProcAddress(mod, "D3DXGetShaderConstantTable");
+
+ test_swizzle();
+ test_math();
+ test_conditionals();
+ test_float_vectors();
+ test_trig();
+ test_fail();
+}
diff --git a/dlls/d3dcompiler_47/tests/Makefile.in b/dlls/d3dcompiler_47/tests/Makefile.in
index 401ed30b0f1..032e16fdb8f 100644
--- a/dlls/d3dcompiler_47/tests/Makefile.in
+++ b/dlls/d3dcompiler_47/tests/Makefile.in
@@ -6,5 +6,5 @@ PARENTSRC = ../../d3dcompiler_43/tests
C_SRCS = \
asm.c \
blob.c \
- hlsl.c \
+ hlsl_d3d9.c \
reflection.c
--
2.25.0
1
2
Games like Risk of Rain 2 need this with certain controllers.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode(a)gmail.com>
---
Andrew Eikum helped me test this out with a PS4 Controller on Windows
10. Using the test here, I took all the input reports from the Windows log
and sent them through this function in a simulation, to compare the outputs
with the dumped log from Windows. It was the same, so same input resulted
in same output.
dlls/hid/hid.spec | 2 +-
dlls/hid/hidp.c | 65 +++++++++++++++++++++++++++++++++++++++++
dlls/hid/tests/device.c | 37 +++++++++++++++++++----
include/ddk/hidpi.h | 1 +
4 files changed, 99 insertions(+), 6 deletions(-)
diff --git a/dlls/hid/hid.spec b/dlls/hid/hid.spec
index b8e29fe..98508a4 100644
--- a/dlls/hid/hid.spec
+++ b/dlls/hid/hid.spec
@@ -27,7 +27,7 @@
@ stdcall HidP_GetSpecificButtonCaps(long long long long ptr ptr ptr)
@ stdcall HidP_GetSpecificValueCaps(long long long long ptr ptr ptr)
@ stdcall HidP_GetUsageValue(long long long long ptr ptr ptr long)
-@ stub HidP_GetUsageValueArray
+@ stdcall HidP_GetUsageValueArray(long long long long ptr long ptr ptr long)
@ stdcall HidP_GetUsages(long long long ptr ptr ptr ptr long)
@ stdcall HidP_GetUsagesEx(long long ptr ptr ptr ptr long)
@ stdcall HidP_GetValueCaps(long ptr ptr ptr)
diff --git a/dlls/hid/hidp.c b/dlls/hid/hidp.c
index 817e021..c4d1626 100644
--- a/dlls/hid/hidp.c
+++ b/dlls/hid/hidp.c
@@ -117,6 +117,46 @@ static NTSTATUS set_report_data(BYTE *report, INT reportLength, INT startBit, IN
return HIDP_STATUS_SUCCESS;
}
+static NTSTATUS get_report_data_array(BYTE *report, UINT reportLength, UINT startBit, UINT elemSize,
+ UINT numElements, PCHAR values, UINT valuesSize)
+{
+ BYTE byte, *end, *p = report + startBit / 8;
+ ULONG size = elemSize * numElements;
+ ULONG m, bit_index = startBit % 8;
+ BYTE *data = (BYTE*)values;
+
+ if ((startBit + size) / 8 > reportLength)
+ return HIDP_STATUS_INVALID_REPORT_LENGTH;
+
+ if (valuesSize < (size + 7) / 8)
+ return HIDP_STATUS_BUFFER_TOO_SMALL;
+
+ end = report + (startBit + size + 7) / 8;
+
+ data--;
+ byte = *p++;
+ while (p != end)
+ {
+ *(++data) = byte >> bit_index;
+ byte = *p++;
+ *data |= byte << (8 - bit_index);
+ }
+
+ /* Handle the end and mask out bits beyond */
+ m = (startBit + size) % 8;
+ m = m ? m : 8;
+
+ if (m > bit_index)
+ *(++data) = (byte >> bit_index) & ((1 << (m - bit_index)) - 1);
+ else
+ *data &= (1 << (m + 8 - bit_index)) - 1;
+
+ if (++data < (BYTE*)values + valuesSize)
+ memset(data, 0, (BYTE*)values + valuesSize - data);
+
+ return HIDP_STATUS_SUCCESS;
+}
+
NTSTATUS WINAPI HidP_GetButtonCaps(HIDP_REPORT_TYPE ReportType, PHIDP_BUTTON_CAPS ButtonCaps,
PUSHORT ButtonCapsLength, PHIDP_PREPARSED_DATA PreparsedData)
@@ -325,6 +365,31 @@ NTSTATUS WINAPI HidP_GetUsageValue(HIDP_REPORT_TYPE ReportType, USAGE UsagePage,
}
+NTSTATUS WINAPI HidP_GetUsageValueArray(HIDP_REPORT_TYPE ReportType, USAGE UsagePage, USHORT LinkCollection,
+ USAGE Usage, PCHAR UsageValue, USHORT UsageValueByteLength,
+ PHIDP_PREPARSED_DATA PreparsedData, PCHAR Report, ULONG ReportLength)
+{
+ WINE_HID_ELEMENT element;
+ NTSTATUS rc;
+
+ TRACE("(%i, %x, %i, %i, %p, %u, %p, %p, %i)\n", ReportType, UsagePage, LinkCollection, Usage, UsageValue,
+ UsageValueByteLength, PreparsedData, Report, ReportLength);
+
+ rc = find_usage(ReportType, UsagePage, LinkCollection, Usage, PreparsedData, Report, ValueElement, &element);
+
+ if (rc == HIDP_STATUS_SUCCESS)
+ {
+ if (element.caps.value.IsRange || element.caps.value.ReportCount <= 1 || !element.bitCount)
+ return HIDP_STATUS_NOT_VALUE_ARRAY;
+
+ return get_report_data_array((BYTE*)Report, ReportLength, element.valueStartBit, element.bitCount,
+ element.caps.value.ReportCount, UsageValue, UsageValueByteLength);
+ }
+
+ return rc;
+}
+
+
NTSTATUS WINAPI HidP_GetUsages(HIDP_REPORT_TYPE ReportType, USAGE UsagePage, USHORT LinkCollection,
PUSAGE UsageList, PULONG UsageLength, PHIDP_PREPARSED_DATA PreparsedData,
PCHAR Report, ULONG ReportLength)
diff --git a/dlls/hid/tests/device.c b/dlls/hid/tests/device.c
index 24c3077..3dd22b7 100644
--- a/dlls/hid/tests/device.c
+++ b/dlls/hid/tests/device.c
@@ -253,11 +253,38 @@ static void process_data(HIDP_CAPS Caps, PHIDP_PREPARSED_DATA ppd, CHAR *data, D
trace("\tValues:\n");
for (i = 0; i < length; i++)
{
- status = HidP_GetUsageValue(HidP_Input, values[i].UsagePage, 0,
- values[i].Range.UsageMin, &value, ppd, data, data_length);
- ok(status == HIDP_STATUS_SUCCESS, "Failed to get value [%i,%i] (%x)\n",
- values[i].UsagePage, values[i].Range.UsageMin, status);
- trace("[%02x, %02x]: %u\n",values[i].UsagePage, values[i].Range.UsageMin, value);
+ ok(values[i].ReportCount, "Zero ReportCount for [%i,%i]\n", values[i].UsagePage, values[i].NotRange.Usage);
+ if (values[i].IsRange || values[i].ReportCount <= 1)
+ {
+ status = HidP_GetUsageValue(HidP_Input, values[i].UsagePage, 0,
+ values[i].Range.UsageMin, &value, ppd, data, data_length);
+ ok(status == HIDP_STATUS_SUCCESS, "Failed to get value [%i,%i] (%x)\n",
+ values[i].UsagePage, values[i].Range.UsageMin, status);
+ trace("[%02x, %02x]: %u\n", values[i].UsagePage, values[i].Range.UsageMin, value);
+ }
+ else
+ {
+ USHORT k, array_size = (values[i].BitSize * values[i].ReportCount + 7) / 8;
+ PCHAR array = HeapAlloc(GetProcessHeap(), 0, array_size);
+ char *dump = HeapAlloc(GetProcessHeap(), 0, array_size * 3 + 1);
+
+ status = HidP_GetUsageValueArray(HidP_Input, values[i].UsagePage, 0,
+ values[i].NotRange.Usage, array, array_size, ppd, data, data_length);
+ ok(status == HIDP_STATUS_SUCCESS, "Failed to get value array [%i,%i] (%x)\n",
+ values[i].UsagePage, values[i].NotRange.Usage, status);
+ dump[0] = 0;
+ for (k = 0; k < array_size; k++)
+ {
+ char bytestr[5];
+ sprintf(bytestr, " %02x", (BYTE)array[k]);
+ strcat(dump, bytestr);
+ }
+ trace("[%02x, %02x] element bit size %u num elements %u:%s\n", values[i].UsagePage,
+ values[i].NotRange.Usage, values[i].BitSize, values[i].ReportCount, dump);
+
+ HeapFree(GetProcessHeap(), 0, dump);
+ HeapFree(GetProcessHeap(), 0, array);
+ }
}
HeapFree(GetProcessHeap(), 0, values);
diff --git a/include/ddk/hidpi.h b/include/ddk/hidpi.h
index 51d61ea..fb497f3 100644
--- a/include/ddk/hidpi.h
+++ b/include/ddk/hidpi.h
@@ -195,6 +195,7 @@ NTSTATUS WINAPI HidP_GetButtonCaps(HIDP_REPORT_TYPE ReportType, PHIDP_BUTTON_CAP
NTSTATUS WINAPI HidP_GetCaps(PHIDP_PREPARSED_DATA PreparsedData, PHIDP_CAPS Capabilities);
NTSTATUS WINAPI HidP_GetUsages(HIDP_REPORT_TYPE ReportType, USAGE UsagePage, USHORT LinkCollection, PUSAGE UsageList, PULONG UsageLength, PHIDP_PREPARSED_DATA PreparsedData, PCHAR Report, ULONG ReportLength);
NTSTATUS WINAPI HidP_GetUsageValue(HIDP_REPORT_TYPE ReportType, USAGE UsagePage, USHORT LinkCollection, USAGE Usage, PULONG UsageValue, PHIDP_PREPARSED_DATA PreparsedData, PCHAR Report, ULONG ReportLength);
+NTSTATUS WINAPI HidP_GetUsageValueArray(HIDP_REPORT_TYPE ReportType, USAGE UsagePage, USHORT LinkCollection, USAGE Usage, PCHAR UsageValue, USHORT UsageValueByteLength, PHIDP_PREPARSED_DATA PreparsedData, PCHAR Report, ULONG ReportLength);
NTSTATUS WINAPI HidP_GetValueCaps(HIDP_REPORT_TYPE ReportType, PHIDP_VALUE_CAPS ValueCaps, PUSHORT ValueCapsLength, PHIDP_PREPARSED_DATA PreparsedData);
NTSTATUS WINAPI HidP_InitializeReportForID(HIDP_REPORT_TYPE ReportType, UCHAR ReportID, PHIDP_PREPARSED_DATA PreparsedData, PCHAR Report, ULONG ReportLength);
ULONG WINAPI HidP_MaxUsageListLength(HIDP_REPORT_TYPE ReportType, USAGE UsagePage, PHIDP_PREPARSED_DATA PreparsedData);
--
2.21.0
2
3
Signed-off-by: Matteo Bruni <mbruni(a)codeweavers.com>
---
In d3d8 there was no vertex shader texture fetch.
dlls/d3d8/device.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c
index 869a6a2dd0d..9793eda0c36 100644
--- a/dlls/d3d8/device.c
+++ b/dlls/d3d8/device.c
@@ -2159,10 +2159,7 @@ static HRESULT WINAPI d3d8_device_GetTexture(IDirect3DDevice8 *iface, DWORD stag
if (!texture)
return D3DERR_INVALIDCALL;
- if (stage >= WINED3DVERTEXTEXTURESAMPLER0 && stage <= WINED3DVERTEXTEXTURESAMPLER3)
- stage -= (WINED3DVERTEXTEXTURESAMPLER0 - WINED3D_MAX_FRAGMENT_SAMPLERS);
-
- if (stage >= WINED3D_MAX_COMBINED_SAMPLERS)
+ if (stage >= WINED3D_MAX_FRAGMENT_SAMPLERS)
{
WARN("Ignoring invalid stage %u.\n", stage);
*texture = NULL;
@@ -2253,10 +2250,7 @@ static HRESULT WINAPI d3d8_device_GetTextureStageState(IDirect3DDevice8 *iface,
TRACE("iface %p, stage %u, state %#x, value %p.\n", iface, stage, state, value);
- if (stage >= WINED3DVERTEXTEXTURESAMPLER0 && stage <= WINED3DVERTEXTEXTURESAMPLER3)
- stage -= (WINED3DVERTEXTEXTURESAMPLER0 - WINED3D_MAX_FRAGMENT_SAMPLERS);
-
- if (stage >= WINED3D_MAX_COMBINED_SAMPLERS)
+ if (stage >= WINED3D_MAX_FRAGMENT_SAMPLERS)
{
WARN("Invalid stage %u.\n", stage);
*value = 0;
--
2.24.1
2
9