ReactOS 0.4.17-dev-934-g091855f
hlsl_d3d9.c File Reference
#include "wine/test.h"
#include "d3dx9.h"
#include "d3dcompiler.h"
#include <math.h>
Include dependency graph for hlsl_d3d9.c:

Go to the source code of this file.

Classes

struct  vec2
 
struct  vec4
 
struct  test_context
 
struct  readback
 
struct  test_d3dinclude
 

Macros

#define COBJMACROS
 
#define D3DXERR_INVALIDDATA   0x88760b59
 
#define compile_shader(a, b, c)   compile_shader_(__LINE__, a, b, c)
 
#define init_test_context(a)   init_test_context_(__LINE__, a)
 
#define release_test_context(context)   release_test_context_(__LINE__, context)
 
#define draw_quad(device, ps_code)   draw_quad_(__LINE__, device, ps_code)
 

Typedefs

typedef HRESULT(* include_test_cb) (const char *source_name, ID3DInclude *include, ID3D10Blob **blob, ID3D10Blob **errors)
 

Functions

static HRESULT (WINAPI *pD3DAssemble)(const void *data
 
static BOOL create_file (const WCHAR *filename, const char *data, unsigned int size, WCHAR *out_path)
 
static void delete_file (const WCHAR *filename)
 
static BOOL create_directory (const WCHAR *dir)
 
static void delete_directory (const WCHAR *dir)
 
static ID3D10Blob * compile_shader_ (unsigned int line, const char *source, const char *target, unsigned int flags)
 
static IDirect3DDevice9 * create_device (HWND window)
 
static BOOL init_test_context_ (unsigned int line, struct test_context *context)
 
static void release_test_context_ (unsigned int line, struct test_context *context)
 
static void draw_quad_ (unsigned int line, IDirect3DDevice9 *device, ID3D10Blob *ps_code)
 
static void init_readback (IDirect3DDevice9 *device, struct readback *rb)
 
static const struct vec4 * get_readback_vec4 (const struct readback *rb, unsigned int x, unsigned int y)
 
static void release_readback (struct readback *rb)
 
static struct vec4 get_color_vec4 (IDirect3DDevice9 *device, unsigned int x, unsigned int y)
 
static BOOL compare_uint (unsigned int x, unsigned int y, unsigned int max_diff)
 
static BOOL compare_float (float f, float g, unsigned int ulps)
 
static BOOL compare_vec4 (const struct vec4 *vec, float x, float y, float z, float w, unsigned int ulps)
 
static void test_swizzle (void)
 
static void test_math (void)
 
static void test_conditionals (void)
 
static void test_float_vectors (void)
 
static void test_trig (void)
 
static void test_comma (void)
 
static void test_return (void)
 
static void test_array_dimensions (void)
 
static void test_majority (void)
 
static void test_struct_assignment (void)
 
static void test_struct_semantics (void)
 
static void test_global_initializer (void)
 
static void test_samplers (void)
 
static void check_constant_desc (const char *prefix, const D3DXCONSTANT_DESC *desc, const D3DXCONSTANT_DESC *expect, BOOL nonzero_defaultvalue)
 
static void test_constant_table (void)
 
static void test_fail (void)
 
static HRESULT WINAPI test_d3dinclude_open (ID3DInclude *iface, D3D_INCLUDE_TYPE include_type, const char *filename, const void *parent_data, const void **data, UINT *bytes)
 
static HRESULT WINAPI test_d3dinclude_close (ID3DInclude *iface, const void *data)
 
static HRESULT call_D3DAssemble (const char *source_name, ID3DInclude *include, ID3D10Blob **blob, ID3D10Blob **errors)
 
static HRESULT call_D3DCompile (const char *source_name, ID3DInclude *include, ID3D10Blob **blob, ID3D10Blob **errors)
 
static HRESULT call_D3DPreprocess (const char *source_name, ID3DInclude *include, ID3D10Blob **blob, ID3D10Blob **errors)
 
static void test_include (void)
 
static void test_no_output_blob (void)
 
static void test_hlsl_double (void)
 
 START_TEST (hlsl_d3d9)
 

Variables

static SIZE_T datasize
 
static SIZE_T const char * filename
 
static SIZE_T const char const D3D_SHADER_MACRO * defines
 
static SIZE_T const char const D3D_SHADER_MACRO ID3DInclude * include
 
static SIZE_T const char const D3D_SHADER_MACRO ID3DInclude UINT flags
 
static SIZE_T const char const D3D_SHADER_MACRO ID3DInclude UINT ID3DBlob ** shader
 
static SIZE_T const char const D3D_SHADER_MACRO ID3DInclude UINT ID3DBlob ID3DBlob ** error_messages
 
static ID3DXConstantTable ** constant_table
 
static WCHAR temp_dir [MAX_PATH]
 
static const struct ID3DIncludeVtbl test_d3dinclude_vtbl
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 19 of file hlsl_d3d9.c.

◆ compile_shader

#define compile_shader (   a,
  b,
  c 
)    compile_shader_(__LINE__, a, b, c)

Definition at line 101 of file hlsl_d3d9.c.

◆ D3DXERR_INVALIDDATA

#define D3DXERR_INVALIDDATA   0x88760b59

Definition at line 26 of file hlsl_d3d9.c.

◆ draw_quad

#define draw_quad (   device,
  ps_code 
)    draw_quad_(__LINE__, device, ps_code)

Definition at line 209 of file hlsl_d3d9.c.

◆ init_test_context

#define init_test_context (   a)    init_test_context_(__LINE__, a)

Definition at line 182 of file hlsl_d3d9.c.

◆ release_test_context

#define release_test_context (   context)    release_test_context_(__LINE__, context)

Definition at line 201 of file hlsl_d3d9.c.

Typedef Documentation

◆ include_test_cb

typedef HRESULT(* include_test_cb) (const char *source_name, ID3DInclude *include, ID3D10Blob **blob, ID3D10Blob **errors)

Definition at line 1607 of file hlsl_d3d9.c.

Function Documentation

◆ call_D3DAssemble()

static HRESULT call_D3DAssemble ( const char *  source_name,
ID3DInclude *  include,
ID3D10Blob **  blob,
ID3D10Blob **  errors 
)
static

Definition at line 1557 of file hlsl_d3d9.c.

1558{
1559 static const char ps_code[] =
1560 "ps_2_0\n"
1561 "#include \"include\\include3.h\"\n"
1562 "mov oC0, c0";
1563
1564 return pD3DAssemble(ps_code, sizeof(ps_code), source_name, NULL, include, 0, blob, errors);
1565}
#define NULL
Definition: types.h:112
static SIZE_T const char const D3D_SHADER_MACRO ID3DInclude * include
Definition: hlsl_d3d9.c:29
Definition: image.c:229

Referenced by test_include().

◆ call_D3DCompile()

static HRESULT call_D3DCompile ( const char *  source_name,
ID3DInclude *  include,
ID3D10Blob **  blob,
ID3D10Blob **  errors 
)
static

Definition at line 1567 of file hlsl_d3d9.c.

1568{
1569 static const char ps_code[] =
1570 "#include \"include\\include2.h\"\n"
1571 "\n"
1572 "float4 main() : COLOR\n"
1573 "{\n"
1574 " return light_color;\n"
1575 "}";
1576
1577 return D3DCompile(ps_code, sizeof(ps_code), source_name, NULL, include, "main", "ps_2_0", 0, 0, blob, errors);
1578}
HRESULT WINAPI D3DCompile(const void *data, SIZE_T data_size, const char *filename, const D3D_SHADER_MACRO *defines, ID3DInclude *include, const char *entrypoint, const char *target, UINT sflags, UINT eflags, ID3DBlob **shader, ID3DBlob **error_messages)
Definition: compiler.c:639

Referenced by test_include().

◆ call_D3DPreprocess()

static HRESULT call_D3DPreprocess ( const char *  source_name,
ID3DInclude *  include,
ID3D10Blob **  blob,
ID3D10Blob **  errors 
)
static

Definition at line 1596 of file hlsl_d3d9.c.

1597{
1598 static const char ps_code[] =
1599 "#include \"include\\include2.h\"\n"
1600 "#if LIGHT != 1\n"
1601 "#error\n"
1602 "#endif";
1603
1604 return D3DPreprocess(ps_code, sizeof(ps_code), source_name, NULL, include, blob, errors);
1605}
HRESULT WINAPI D3DPreprocess(const void *data, SIZE_T size, const char *filename, const D3D_SHADER_MACRO *defines, ID3DInclude *include, ID3DBlob **shader, ID3DBlob **error_messages)
Definition: compiler.c:652

Referenced by test_include().

◆ check_constant_desc()

static void check_constant_desc ( const char *  prefix,
const D3DXCONSTANT_DESC *  desc,
const D3DXCONSTANT_DESC *  expect,
BOOL  nonzero_defaultvalue 
)
static

Definition at line 1185 of file hlsl_d3d9.c.

1187{
1188 ok(!strcmp(desc->Name, expect->Name), "%s: got Name %s.\n", prefix, debugstr_a(desc->Name));
1189 ok(desc->RegisterSet == expect->RegisterSet, "%s: got RegisterSet %#x.\n", prefix, desc->RegisterSet);
1190 if (desc->RegisterSet == D3DXRS_SAMPLER)
1191 ok(desc->RegisterIndex == expect->RegisterIndex, "%s: got RegisterIndex %u.\n", prefix, desc->RegisterIndex);
1192 ok(desc->RegisterCount == expect->RegisterCount, "%s: got RegisterCount %u.\n", prefix, desc->RegisterCount);
1193 ok(desc->Class == expect->Class, "%s: got Class %#x.\n", prefix, desc->Class);
1194 ok(desc->Type == expect->Type, "%s: got Type %#x.\n", prefix, desc->Type);
1195 ok(desc->Rows == expect->Rows, "%s: got Rows %u.\n", prefix, desc->Rows);
1196 ok(desc->Columns == expect->Columns, "%s: got Columns %u.\n", prefix, desc->Columns);
1197 ok(desc->Elements == expect->Elements, "%s: got Elements %u.\n", prefix, desc->Elements);
1198 ok(desc->StructMembers == expect->StructMembers, "%s: got StructMembers %u.\n", prefix, desc->StructMembers);
1199 ok(desc->Bytes == expect->Bytes, "%s: got Bytes %u.\n", prefix, desc->Bytes);
1200 ok(!!desc->DefaultValue == nonzero_defaultvalue, "%s: got DefaultValue %p.\n", prefix, desc->DefaultValue);
1201}
#define expect(EXPECTED, GOT)
Definition: SystemMenu.c:483
#define ok(value,...)
Definition: atltest.h:57
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3324
@ D3DXRS_SAMPLER
Definition: d3dx9shader.h:56
#define debugstr_a
Definition: kernel32.h:31
D3D11_SHADER_VARIABLE_DESC desc
Definition: reflection.c:1683
Character const *const prefix
Definition: tempnam.cpp:195

Referenced by test_constant_table().

◆ compare_float()

static BOOL compare_float ( float  f,
float  g,
unsigned int  ulps 
)
static

Definition at line 339 of file hlsl_d3d9.c.

340{
341 int x = *(int *)&f;
342 int y = *(int *)&g;
343
344 if (x < 0)
345 x = INT_MIN - x;
346 if (y < 0)
347 y = INT_MIN - y;
348
349 return compare_uint(x, y, ulps);
350}
#define INT_MIN
Definition: limits.h:25
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLfloat f
Definition: glext.h:7540
GLboolean GLboolean g
Definition: glext.h:6204
static BOOL compare_uint(unsigned int x, unsigned int y, unsigned int max_diff)
Definition: hlsl_d3d9.c:332
unsigned int ulps
Definition: effect.c:4467

◆ compare_uint()

static BOOL compare_uint ( unsigned int  x,
unsigned int  y,
unsigned int  max_diff 
)
static

Definition at line 332 of file hlsl_d3d9.c.

333{
334 unsigned int diff = x > y ? x - y : y - x;
335
336 return diff <= max_diff;
337}

Referenced by compare_float().

◆ compare_vec4()

static BOOL compare_vec4 ( const struct vec4 *  vec,
float  x,
float  y,
float  z,
float  w,
unsigned int  ulps 
)
static

Definition at line 352 of file hlsl_d3d9.c.

353{
354 return compare_float(vec->x, x, ulps)
355 && compare_float(vec->y, y, ulps)
356 && compare_float(vec->z, z, ulps)
357 && compare_float(vec->w, w, ulps);
358}
FT_Vector * vec
Definition: ftbbox.c:469
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
GLdouble GLdouble z
Definition: glext.h:5874
#define compare_float(got, exp)
Definition: mesh.c:43
FT_Pos x
Definition: ftimage.h:77
FT_Pos y
Definition: ftimage.h:78

Referenced by test_array_dimensions(), test_comma(), test_conditionals(), test_float_vectors(), test_global_initializer(), test_hlsl_double(), test_majority(), test_math(), test_return(), test_samplers(), test_struct_assignment(), test_struct_semantics(), test_swizzle(), and test_trig().

◆ compile_shader_()

static ID3D10Blob * compile_shader_ ( unsigned int  line,
const char *  source,
const char *  target,
unsigned int  flags 
)
static

Definition at line 102 of file hlsl_d3d9.c.

104{
105 ID3D10Blob *blob = NULL, *errors = NULL;
106 HRESULT hr;
107
108 hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main", target, flags, 0, &blob, &errors);
109 ok_(__FILE__, line)(hr == D3D_OK, "Failed to compile shader, hr %#lx.\n", hr);
110 if (errors)
111 {
112 if (winetest_debug > 1)
113 trace_(__FILE__, line)("%s\n", (char *)ID3D10Blob_GetBufferPointer(errors));
114 ID3D10Blob_Release(errors);
115 }
116 return blob;
117}
#define ok_(x1, x2)
Definition: atltest.h:61
#define D3D_OK
Definition: d3d.h:106
HRESULT hr
Definition: delayimp.cpp:582
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1597
GLbitfield flags
Definition: glext.h:7161
#define trace_(file, line,...)
Definition: kmt_test.h:230
int winetest_debug
Definition: parser.c:49
Definition: tools.h:99

◆ create_device()

static IDirect3DDevice9 * create_device ( HWND  window)
static

Definition at line 119 of file hlsl_d3d9.c.

120{
121 D3DPRESENT_PARAMETERS present_parameters =
122 {
123 .Windowed = TRUE,
124 .hDeviceWindow = window,
125 .SwapEffect = D3DSWAPEFFECT_DISCARD,
126 .BackBufferWidth = 640,
127 .BackBufferHeight = 480,
128 .BackBufferFormat = D3DFMT_A8R8G8B8,
129 };
132 IDirect3D9 *d3d;
133 D3DCAPS9 caps;
134 HRESULT hr;
135
137 if (!d3d)
138 {
139 skip("Failed to create a D3D object.\n");
140 return NULL;
141 }
142
144 D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device);
146 if (FAILED(hr))
147 {
148 skip("Failed to create a 3D device, hr %#lx.\n", hr);
149 return NULL;
150 }
151
153 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
154 if (caps.PixelShaderVersion < D3DPS_VERSION(2, 0) || caps.VertexShaderVersion < D3DVS_VERSION(2, 0))
155 {
156 skip("No shader model 2 support.\n");
158 return NULL;
159 }
160
162 D3DMULTISAMPLE_NONE, 0, FALSE, &rt, NULL)))
163 {
164 skip("Failed to create an A32B32G32R32F surface, hr %#lx.\n", hr);
166 return NULL;
167 }
168 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
170 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
172
173 return device;
174}
#define skip(...)
Definition: atltest.h:64
#define D3DPS_VERSION(major, minor)
Definition: d3d8types.h:474
@ D3DMULTISAMPLE_NONE
Definition: d3d8types.h:672
@ D3DFMT_A8R8G8B8
Definition: d3d8types.h:604
@ D3DSWAPEFFECT_DISCARD
Definition: d3d8types.h:851
#define D3DVS_VERSION(major, minor)
Definition: d3d8types.h:475
@ D3DDEVTYPE_HAL
Definition: d3d8types.h:576
IDirect3D9 *WINAPI Direct3DCreate9(UINT SDKVersion)
Definition: d3d9.c:57
#define IDirect3D9_CreateDevice(p, a, b, c, d, e, f)
Definition: d3d9.h:224
#define IDirect3DDevice9_SetRenderTarget(p, a, b)
Definition: d3d9.h:1372
#define IDirect3DDevice9_GetDeviceCaps(p, a)
Definition: d3d9.h:1342
#define IDirect3D9_Release(p)
Definition: d3d9.h:209
#define IDirect3DDevice9_Release(p)
Definition: d3d9.h:1336
#define IDirect3DSurface9_Release(p)
Definition: d3d9.h:450
#define IDirect3DDevice9_CreateRenderTarget(p, a, b, c, d, e, f, g, h)
Definition: d3d9.h:1363
@ D3DFMT_A32B32G32R32F
Definition: d3d9types.h:861
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
DWORD IDirect3DSurface9
Definition: dxva2api.idl:23
DWORD IDirect3DDevice9
Definition: dxva2api.idl:22
#define FAILED(hr)
Definition: intsafe.h:51
static IHTMLWindow2 * window
Definition: events.c:77
#define D3DADAPTER_DEFAULT
Definition: d3d8.h:53
#define D3DCREATE_HARDWARE_VERTEXPROCESSING
Definition: d3d8.h:41
#define D3D_SDK_VERSION
Definition: d3d8.h:52
DWORD PixelShaderVersion
Definition: d3d9caps.h:315
DWORD VertexShaderVersion
Definition: d3d9caps.h:313
Definition: devices.h:37

◆ create_directory()

static BOOL create_directory ( const WCHAR *  dir)
static

Definition at line 83 of file hlsl_d3d9.c.

84{
86
89 return CreateDirectoryW(path, NULL);
90}
unsigned int dir
Definition: maze.c:112
#define MAX_PATH
Definition: compat.h:34
#define lstrcpyW
Definition: compat.h:749
BOOL WINAPI CreateDirectoryW(IN LPCWSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:58
static WCHAR temp_dir[MAX_PATH]
Definition: hlsl_d3d9.c:44
LPWSTR WINAPI lstrcatW(LPWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:274
short WCHAR
Definition: pedump.c:58

Referenced by test_include().

◆ create_file()

static BOOL create_file ( const WCHAR *  filename,
const char *  data,
unsigned int  size,
WCHAR *  out_path 
)
static

Definition at line 46 of file hlsl_d3d9.c.

47{
49 DWORD written;
51
52 if (!temp_dir[0])
56
59 return FALSE;
60
61 if (WriteFile(file, data, size, &written, NULL))
62 {
64
65 if (out_path)
66 lstrcpyW(out_path, path);
67 return TRUE;
68 }
69
71 return FALSE;
72}
#define ARRAY_SIZE(A)
Definition: main.h:20
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
BOOL WINAPI WriteFile(_In_ HANDLE hFile, _In_reads_bytes_opt_(nNumberOfBytesToWrite) LPCVOID lpBuffer, _In_ DWORD nNumberOfBytesToWrite, _Out_opt_ LPDWORD lpNumberOfBytesWritten, _Inout_opt_ LPOVERLAPPED lpOverlapped)
Definition: rw.c:25
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2098
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
const char * filename
Definition: ioapi.h:137
#define CREATE_ALWAYS
Definition: disk.h:72
#define GENERIC_WRITE
Definition: nt_native.h:90
Definition: fci.c:123

◆ delete_directory()

static void delete_directory ( const WCHAR *  dir)
static

Definition at line 92 of file hlsl_d3d9.c.

93{
95
99}
BOOL WINAPI RemoveDirectoryW(IN LPCWSTR lpPathName)
Definition: dir.c:700

Referenced by test_include().

◆ delete_file()

static void delete_file ( const WCHAR *  filename)
static

Definition at line 74 of file hlsl_d3d9.c.

75{
77
81}
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39

◆ draw_quad_()

static void draw_quad_ ( unsigned int  line,
IDirect3DDevice9 *  device,
ID3D10Blob *  ps_code 
)
static

Definition at line 210 of file hlsl_d3d9.c.

211{
212 IDirect3DVertexDeclaration9 *vertex_declaration;
213 IDirect3DVertexShader9 *vs;
214 IDirect3DPixelShader9 *ps;
215 ID3D10Blob *vs_code;
216 HRESULT hr;
217
218 static const D3DVERTEXELEMENT9 decl_elements[] =
219 {
223 };
224
225 static const struct
226 {
227 struct vec2 position;
228 struct vec2 t0;
229 }
230 quad[] =
231 {
232 {{-1.0f, -1.0f}, {0.0f, 1.0f}},
233 {{-1.0f, 1.0f}, {0.0f, 0.0f}},
234 {{ 1.0f, -1.0f}, {1.0f, 1.0f}},
235 {{ 1.0f, 1.0f}, {1.0f, 0.0f}},
236 };
237
238 static const char vs_source[] =
239 "float4 main(float4 pos : POSITION, inout float2 texcoord : TEXCOORD0) : POSITION\n"
240 "{\n"
241 " return pos;\n"
242 "}";
243
244 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &vertex_declaration);
245 ok_(__FILE__, line)(hr == D3D_OK, "Failed to create vertex declaration, hr %#lx.\n", hr);
246
247 hr = IDirect3DDevice9_SetVertexDeclaration(device, vertex_declaration);
248 ok_(__FILE__, line)(hr == D3D_OK, "Failed to set vertex declaration, hr %#lx.\n", hr);
249
250 vs_code = compile_shader(vs_source, "vs_2_0", 0);
251
252 hr = IDirect3DDevice9_CreateVertexShader(device, ID3D10Blob_GetBufferPointer(vs_code), &vs);
253 ok_(__FILE__, line)(hr == D3D_OK, "Failed to create vertex shader, hr %#lx.\n", hr);
254
256 ok_(__FILE__, line)(hr == D3D_OK, "Failed to set vertex shader, hr %#lx.\n", hr);
257
258 hr = IDirect3DDevice9_CreatePixelShader(device, ID3D10Blob_GetBufferPointer(ps_code), &ps);
259 ok_(__FILE__, line)(hr == D3D_OK, "Failed to create pixel shader, hr %#lx.\n", hr);
260
262 ok_(__FILE__, line)(hr == D3D_OK, "Failed to set pixel shader, hr %#lx.\n", hr);
263
265 ok_(__FILE__, line)(hr == D3D_OK, "Failed to draw, hr %#lx.\n", hr);
266
268 ok_(__FILE__, line)(hr == D3D_OK, "Failed to draw, hr %#lx.\n", hr);
269
271 ok_(__FILE__, line)(hr == D3D_OK, "Failed to draw, hr %#lx.\n", hr);
272
273 IDirect3DVertexDeclaration9_Release(vertex_declaration);
276 ID3D10Blob_Release(vs_code);
277}
@ D3DPT_TRIANGLESTRIP
Definition: d3d8types.h:722
#define IDirect3DDevice9_EndScene(p)
Definition: d3d9.h:1377
#define IDirect3DDevice9_BeginScene(p)
Definition: d3d9.h:1376
#define IDirect3DDevice9_CreatePixelShader(p, a, b)
Definition: d3d9.h:1441
#define IDirect3DDevice9_CreateVertexDeclaration(p, a, b)
Definition: d3d9.h:1421
#define IDirect3DDevice9_DrawPrimitiveUP(p, a, b, c, d)
Definition: d3d9.h:1418
#define IDirect3DDevice9_SetPixelShader(p, a)
Definition: d3d9.h:1442
#define IDirect3DVertexDeclaration9_Release(p)
Definition: d3d9.h:1013
#define IDirect3DPixelShader9_Release(p)
Definition: d3d9.h:1089
#define IDirect3DVertexShader9_Release(p)
Definition: d3d9.h:1051
#define IDirect3DDevice9_SetVertexShader(p, a)
Definition: d3d9.h:1427
#define IDirect3DDevice9_SetVertexDeclaration(p, a)
Definition: d3d9.h:1422
#define IDirect3DDevice9_CreateVertexShader(p, a, b)
Definition: d3d9.h:1426
@ D3DDECLUSAGE_TEXCOORD
Definition: d3d9types.h:241
@ D3DDECLUSAGE_POSITION
Definition: d3d9types.h:236
@ D3DDECLTYPE_FLOAT2
Definition: d3d9types.h:272
#define D3DDECL_END()
Definition: d3d9types.h:329
@ D3DDECLMETHOD_DEFAULT
Definition: d3d9types.h:258
#define compile_shader(a, b, c)
Definition: hlsl_d3d9.c:101
static vector_t * vs
Definition: server.c:146
static void quad(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3, GLuint pv)
Definition: quads.c:63

◆ get_color_vec4()

static struct vec4 get_color_vec4 ( IDirect3DDevice9 *  device,
unsigned int  x,
unsigned int  y 
)
static

Definition at line 320 of file hlsl_d3d9.c.

321{
322 struct readback rb;
323 struct vec4 ret;
324
325 init_readback(device, &rb);
326 ret = *get_readback_vec4(&rb, x, y);
327 release_readback(&rb);
328
329 return ret;
330}
return ret
Definition: mutex.c:147
static void init_readback(IDirect3DDevice9 *device, struct readback *rb)
Definition: hlsl_d3d9.c:285
static const struct vec4 * get_readback_vec4(const struct readback *rb, unsigned int x, unsigned int y)
Definition: hlsl_d3d9.c:309
static void release_readback(struct readback *rb)
Definition: hlsl_d3d9.c:314

Referenced by test_array_dimensions(), test_comma(), test_float_vectors(), test_global_initializer(), test_hlsl_double(), test_majority(), test_math(), test_return(), test_samplers(), test_struct_assignment(), test_struct_semantics(), and test_swizzle().

◆ get_readback_vec4()

static const struct vec4 * get_readback_vec4 ( const struct readback *  rb,
unsigned int  x,
unsigned int  y 
)
static

Definition at line 309 of file hlsl_d3d9.c.

310{
311 return (struct vec4 *)((BYTE *)rb->rect.pBits + y * rb->rect.Pitch + x * sizeof(struct vec4));
312}
D3DLOCKED_RECT rect
Definition: hlsl_d3d9.c:282
unsigned char BYTE
Definition: xxhash.c:193

Referenced by get_color_vec4(), test_conditionals(), and test_trig().

◆ HRESULT()

static HRESULT ( WINAPI *  pD3DAssemble) const
static

◆ init_readback()

static void init_readback ( IDirect3DDevice9 *  device,
struct readback *  rb 
)
static

Definition at line 285 of file hlsl_d3d9.c.

286{
289 HRESULT hr;
290
292 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
293
295 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
297 desc.Format, D3DPOOL_SYSTEMMEM, &rb->surface, NULL);
298 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
299
301 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
302
304 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
305
307}
@ D3DPOOL_SYSTEMMEM
Definition: d3d8types.h:711
#define D3DLOCK_READONLY
Definition: d3d8types.h:69
#define IDirect3DSurface9_LockRect(p, a, b, c)
Definition: d3d9.h:463
#define IDirect3DDevice9_GetRenderTargetData(p, a, b)
Definition: d3d9.h:1367
#define IDirect3DSurface9_GetDesc(p, a)
Definition: d3d9.h:462
#define IDirect3DDevice9_CreateOffscreenPlainSurface(p, a, b, c, d, e, f)
Definition: d3d9.h:1371
#define IDirect3DDevice9_GetRenderTarget(p, a, b)
Definition: d3d9.h:1373
IDirect3DSurface9 * surface
Definition: hlsl_d3d9.c:281

Referenced by get_color_vec4(), test_conditionals(), and test_trig().

◆ init_test_context_()

static BOOL init_test_context_ ( unsigned int  line,
struct test_context *  context 
)
static

Definition at line 183 of file hlsl_d3d9.c.

184{
185 RECT rect = {0, 0, 640, 480};
186
188 context->window = CreateWindowA("static", "d3dcompiler_test", WS_OVERLAPPEDWINDOW,
190 ok(!!context->window, "Failed to create a window.\n");
191
192 if (!(context->device = create_device(context->window)))
193 {
194 DestroyWindow(context->window);
195 return FALSE;
196 }
197
198 return TRUE;
199}
RECT rect
Definition: combotst.c:67
static ID3D11Device * create_device(void)
Definition: hlsl_d3d11.c:102
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
BOOL WINAPI AdjustWindowRect(_Inout_ LPRECT, _In_ DWORD, _In_ BOOL)
#define CreateWindowA(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4469
BOOL WINAPI DestroyWindow(_In_ HWND)
Definition: dcommon.idl:28
long bottom
Definition: dcommon.idl:29
long right
Definition: dcommon.idl:29
long left
Definition: dcommon.idl:29
long top
Definition: dcommon.idl:29
Definition: http.c:7252

◆ release_readback()

static void release_readback ( struct readback *  rb)
static

Definition at line 314 of file hlsl_d3d9.c.

315{
318}
#define IDirect3DSurface9_UnlockRect(p)
Definition: d3d9.h:464

Referenced by get_color_vec4(), test_conditionals(), and test_trig().

◆ release_test_context_()

static void release_test_context_ ( unsigned int  line,
struct test_context *  context 
)
static

Definition at line 202 of file hlsl_d3d9.c.

203{
205 ok_(__FILE__, line)(!ref, "Device has %lu references left.\n", ref);
206 DestroyWindow(context->window);
207}
Definition: send.c:48
uint32_t ULONG
Definition: typedefs.h:59

◆ START_TEST()

START_TEST ( hlsl_d3d9  )

Definition at line 1855 of file hlsl_d3d9.c.

1856{
1857 char buffer[20];
1858 HMODULE mod;
1859
1860 if (!(mod = LoadLibraryA("d3dx9_36.dll")))
1861 {
1862 win_skip("Failed to load d3dx9_36.dll.\n");
1863 return;
1864 }
1865 pD3DXGetShaderConstantTable = (void *)GetProcAddress(mod, "D3DXGetShaderConstantTable");
1866
1867 sprintf(buffer, "d3dcompiler_%d", D3D_COMPILER_VERSION);
1869 pD3DAssemble = (void *)GetProcAddress(mod, "D3DAssemble");
1870
1871 test_swizzle();
1872 test_math();
1875 test_trig();
1876 test_comma();
1877 test_return();
1879 test_majority();
1883 test_samplers();
1885 test_fail();
1886 test_include();
1889}
std::map< E_MODULE, HMODULE > mod
Definition: LocaleTests.cpp:68
#define D3D_COMPILER_VERSION
Definition: d3d11shader.h:26
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
GLuint buffer
Definition: glext.h:5915
static void test_swizzle(void)
Definition: hlsl_d3d9.c:360
static void test_majority(void)
Definition: hlsl_d3d9.c:832
static void test_fail(void)
Definition: hlsl_d3d9.c:1353
static void test_constant_table(void)
Definition: hlsl_d3d9.c:1203
static void test_include(void)
Definition: hlsl_d3d9.c:1609
static void test_trig(void)
Definition: hlsl_d3d9.c:683
static void test_comma(void)
Definition: hlsl_d3d9.c:722
static void test_array_dimensions(void)
Definition: hlsl_d3d9.c:796
static void test_return(void)
Definition: hlsl_d3d9.c:749
static void test_global_initializer(void)
Definition: hlsl_d3d9.c:1060
static void test_math(void)
Definition: hlsl_d3d9.c:486
static void test_struct_semantics(void)
Definition: hlsl_d3d9.c:1013
static void test_struct_assignment(void)
Definition: hlsl_d3d9.c:975
static void test_conditionals(void)
Definition: hlsl_d3d9.c:536
static void test_samplers(void)
Definition: hlsl_d3d9.c:1099
static void test_hlsl_double(void)
Definition: hlsl_d3d9.c:1815
static void test_no_output_blob(void)
Definition: hlsl_d3d9.c:1799
static void test_float_vectors(void)
Definition: hlsl_d3d9.c:616
#define win_skip
Definition: minitest.h:67
#define sprintf
Definition: sprintf.c:45

◆ test_array_dimensions()

static void test_array_dimensions ( void  )
static

Definition at line 796 of file hlsl_d3d9.c.

797{
799 ID3D10Blob *ps_code = NULL;
800 struct vec4 v;
801
802 static const char shader[] =
803 "float4 main(float x : TEXCOORD0) : COLOR\n"
804 "{\n"
805 " const int dim = 4;\n"
806 " float a[2 * 2] = {0.1, 0.2, 0.3, 0.4};\n"
807 " float b[4.1] = a;\n"
808 " float c[dim] = b;\n"
809 " float d[true] = {c[0]};\n"
810 " float e[65536];\n"
811 " return float4(d[0], c[0], c[1], c[3]);\n"
812 "}";
813
815 return;
816
817 todo_wine ps_code = compile_shader(shader, "ps_2_0", 0);
818 if (ps_code)
819 {
820 draw_quad(test_context.device, ps_code);
821
823 ok(compare_vec4(&v, 0.1f, 0.1f, 0.2f, 0.4f, 0),
824 "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
825
826 ID3D10Blob_Release(ps_code);
827 }
828
830}
const GLdouble * v
Definition: gl.h:2040
GLuint shader
Definition: glext.h:6030
#define release_test_context(context)
Definition: hlsl_d3d9.c:201
#define init_test_context(a)
Definition: hlsl_d3d9.c:182
static BOOL compare_vec4(const struct vec4 *vec, float x, float y, float z, float w, unsigned int ulps)
Definition: hlsl_d3d9.c:352
static struct vec4 get_color_vec4(IDirect3DDevice9 *device, unsigned int x, unsigned int y)
Definition: hlsl_d3d9.c:320
#define draw_quad(device, ps_code)
Definition: hlsl_d3d9.c:209
#define todo_wine
Definition: minitest.h:80
ID3D11Device * device
Definition: hlsl_d3d11.c:90

Referenced by START_TEST().

◆ test_comma()

static void test_comma ( void  )
static

Definition at line 722 of file hlsl_d3d9.c.

723{
725 ID3D10Blob *ps_code = NULL;
726 struct vec4 v;
727
728 static const char ps_source[] =
729 "float4 main(float x: TEXCOORD0): COLOR\n"
730 "{\n"
731 " float4 ret;\n"
732 " return (ret = float4(0.1, 0.2, 0.3, 0.4)), ret + 0.5;\n"
733 "}";
734
736 return;
737
738 ps_code = compile_shader(ps_source, "ps_2_0", 0);
739 draw_quad(test_context.device, ps_code);
740
742 ok(compare_vec4(&v, 0.6f, 0.7f, 0.8f, 0.9f, 0),
743 "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
744
745 ID3D10Blob_Release(ps_code);
747}

Referenced by START_TEST().

◆ test_conditionals()

static void test_conditionals ( void  )
static

Definition at line 536 of file hlsl_d3d9.c.

537{
539 ID3D10Blob *ps_code = NULL;
541 const struct vec4 *v;
542 struct readback rb;
543 unsigned int i;
544
545 static const char ps_if_source[] =
546 "float4 main(float2 pos : TEXCOORD0) : COLOR\n"
547 "{\n"
548 " if((pos.x * 640.0) > 200.0)\n"
549 " return float4(0.1, 0.2, 0.3, 0.4);\n"
550 " else\n"
551 " return float4(0.9, 0.8, 0.7, 0.6);\n"
552 "}";
553
554 static const char ps_ternary_source[] =
555 "float4 main(float2 pos : TEXCOORD0) : COLOR\n"
556 "{\n"
557 " return (pos.x < 0.5 ? float4(0.5, 0.25, 0.5, 0.75) : float4(0.6, 0.8, 0.1, 0.2));\n"
558 "}";
559
561 return;
563
565 ps_code = compile_shader(ps_if_source, "ps_2_0", 0);
566 if (ps_code)
567 {
568 draw_quad(device, ps_code);
569 init_readback(device, &rb);
570
571 for (i = 0; i < 200; i += 40)
572 {
573 v = get_readback_vec4(&rb, i, 0);
574 todo_wine ok(compare_vec4(v, 0.9f, 0.8f, 0.7f, 0.6f, 0),
575 "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v->x, v->y, v->z, v->w);
576 }
577
578 for (i = 240; i < 640; i += 40)
579 {
580 v = get_readback_vec4(&rb, i, 0);
581 todo_wine ok(compare_vec4(v, 0.1f, 0.2f, 0.3f, 0.4f, 0),
582 "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v->x, v->y, v->z, v->w);
583 }
584
585 release_readback(&rb);
586 ID3D10Blob_Release(ps_code);
587 }
588
589 ps_code = compile_shader(ps_ternary_source, "ps_2_0", 0);
590 if (ps_code)
591 {
592 draw_quad(device, ps_code);
593 init_readback(device, &rb);
594
595 for (i = 0; i < 320; i += 40)
596 {
597 v = get_readback_vec4(&rb, i, 0);
598 ok(compare_vec4(v, 0.5f, 0.25f, 0.5f, 0.75f, 0),
599 "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v->x, v->y, v->z, v->w);
600 }
601
602 for (i = 360; i < 640; i += 40)
603 {
604 v = get_readback_vec4(&rb, i, 0);
605 ok(compare_vec4(v, 0.6f, 0.8f, 0.1f, 0.2f, 0),
606 "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v->x, v->y, v->z, v->w);
607 }
608
609 release_readback(&rb);
610 ID3D10Blob_Release(ps_code);
611 }
612
614}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248

Referenced by START_TEST().

◆ test_constant_table()

static void test_constant_table ( void  )
static

Definition at line 1203 of file hlsl_d3d9.c.

1204{
1205 static const char *source =
1206 "typedef float3x3 matrix_t;\n"
1207 "struct matrix_record { float3x3 a; } dummy;\n"
1208 "uniform float4 a;\n"
1209 "uniform float b;\n"
1210 "uniform float unused;\n"
1211 "uniform float3x1 c;\n"
1212 "uniform row_major float3x1 d;\n"
1213 "uniform uint e;\n"
1214 "uniform struct\n"
1215 "{\n"
1216 " float2x2 a;\n"
1217 " float b[2];\n"
1218 " float c;\n"
1219 "#pragma pack_matrix(row_major)\n"
1220 " float2x2 d;\n"
1221 "} f;\n"
1222 "uniform bool2 g[5];\n"
1223 "uniform matrix_t i;\n"
1224 "uniform struct matrix_record j;\n"
1225 "uniform matrix<float,3,1> k;\n"
1226 "sampler l : register(s5);\n"
1227 "sampler m {};\n"
1228 "texture dummy_texture;\n"
1229 "sampler n\n"
1230 "{\n"
1231 " Texture = dummy_texture;\n"
1232 " foo = bar + 2;\n"
1233 "};\n"
1234 "SamplerState o\n"
1235 "{\n"
1236 " Texture = dummy_texture;\n"
1237 " foo = bar + 2;\n"
1238 "};\n"
1239 "texture2D p;\n"
1240 "sampler q : register(s7);\n"
1241 "SamplerState r : register(s8);\n"
1242 "sampler2D s;\n"
1243 "float4 main(uniform float4 h, sampler t, uniform sampler u) : COLOR\n"
1244 "{\n"
1245 " return b + c._31 + d._31 + f.d._22 + tex2D(l, g[e]) + tex3D(m, h.xyz) + i._33 + j.a._33 + k._31\n"
1246 " + tex2D(n, a.xy) + tex2D(o, a.xy) + p.Sample(r, a.xy) + p.Sample(q, a.xy) + tex2D(s, a.xy)\n"
1247 " + tex2D(t, a.xy) + tex2D(u, a.xy);\n"
1248 "}";
1249
1250 D3DXCONSTANTTABLE_DESC table_desc;
1251 ID3DXConstantTable *constants;
1252 ID3D10Blob *ps_code = NULL;
1255 unsigned int i, j;
1256 HRESULT hr;
1257 UINT count;
1258
1259 static const D3DXCONSTANT_DESC expect_constants[] =
1260 {
1261 {"$h", D3DXRS_FLOAT4, 0, 1, D3DXPC_VECTOR, D3DXPT_FLOAT, 1, 4, 1, 0, 16},
1262 {"$u", D3DXRS_SAMPLER, 10, 1, D3DXPC_OBJECT, D3DXPT_SAMPLER2D, 1, 1, 1, 0, 4},
1263 {"a", D3DXRS_FLOAT4, 0, 1, D3DXPC_VECTOR, D3DXPT_FLOAT, 1, 4, 1, 0, 16},
1264 {"b", D3DXRS_FLOAT4, 0, 1, D3DXPC_SCALAR, D3DXPT_FLOAT, 1, 1, 1, 0, 4},
1265 {"c", D3DXRS_FLOAT4, 0, 1, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 3, 1, 1, 0, 12},
1266 {"d", D3DXRS_FLOAT4, 0, 3, D3DXPC_MATRIX_ROWS, D3DXPT_FLOAT, 3, 1, 1, 0, 12},
1267 {"e", D3DXRS_FLOAT4, 0, 1, D3DXPC_SCALAR, D3DXPT_INT, 1, 1, 1, 0, 4},
1268 {"f", D3DXRS_FLOAT4, 0, 7, D3DXPC_STRUCT, D3DXPT_VOID, 1, 11, 1, 4, 44},
1269 {"g", D3DXRS_FLOAT4, 0, 5, D3DXPC_VECTOR, D3DXPT_BOOL, 1, 2, 5, 0, 40},
1270 {"i", D3DXRS_FLOAT4, 0, 3, D3DXPC_MATRIX_ROWS, D3DXPT_FLOAT, 3, 3, 1, 0, 36},
1271 {"j", D3DXRS_FLOAT4, 0, 3, D3DXPC_STRUCT, D3DXPT_VOID, 1, 9, 1, 1, 36},
1272 {"k", D3DXRS_FLOAT4, 0, 3, D3DXPC_MATRIX_ROWS, D3DXPT_FLOAT, 3, 1, 1, 0, 12},
1273 {"l", D3DXRS_SAMPLER, 5, 1, D3DXPC_OBJECT, D3DXPT_SAMPLER2D, 1, 1, 1, 0, 4},
1274 {"m", D3DXRS_SAMPLER, 2, 1, D3DXPC_OBJECT, D3DXPT_SAMPLER3D, 1, 1, 1, 0, 4},
1275 {"n", D3DXRS_SAMPLER, 3, 1, D3DXPC_OBJECT, D3DXPT_SAMPLER2D, 1, 1, 1, 0, 4},
1276 {"o", D3DXRS_SAMPLER, 4, 1, D3DXPC_OBJECT, D3DXPT_SAMPLER2D, 1, 1, 1, 0, 4},
1277 {"q+p", D3DXRS_SAMPLER, 0, 1, D3DXPC_OBJECT, D3DXPT_TEXTURE2D, 1, 4, 1, 0, 16},
1278 {"r+p", D3DXRS_SAMPLER, 1, 1, D3DXPC_OBJECT, D3DXPT_TEXTURE2D, 1, 4, 1, 0, 16},
1279 {"s", D3DXRS_SAMPLER, 6, 1, D3DXPC_OBJECT, D3DXPT_SAMPLER2D, 1, 1, 1, 0, 4},
1280 {"t", D3DXRS_SAMPLER, 9, 1, D3DXPC_OBJECT, D3DXPT_SAMPLER2D, 1, 1, 1, 0, 4},
1281 };
1282
1283 static const D3DXCONSTANT_DESC expect_fields_f[] =
1284 {
1285 {"a", D3DXRS_FLOAT4, 0, 2, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 2, 2, 1, 0, 16},
1286 {"b", D3DXRS_FLOAT4, 0, 2, D3DXPC_SCALAR, D3DXPT_FLOAT, 1, 1, 2, 0, 8},
1287 {"c", D3DXRS_FLOAT4, 0, 1, D3DXPC_SCALAR, D3DXPT_FLOAT, 1, 1, 1, 0, 4},
1288 {"d", D3DXRS_FLOAT4, 0, 2, D3DXPC_MATRIX_ROWS, D3DXPT_FLOAT, 2, 2, 1, 0, 16},
1289 };
1290
1291 static const D3DXCONSTANT_DESC expect_fields_j =
1292 {"a", D3DXRS_FLOAT4, 0, 3, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 3, 3, 1, 0, 36};
1293
1294 todo_wine ps_code = compile_shader(source, "ps_2_0", 0);
1295 if (!ps_code)
1296 return;
1297
1298 hr = pD3DXGetShaderConstantTable(ID3D10Blob_GetBufferPointer(ps_code), &constants);
1299 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
1300
1301 hr = ID3DXConstantTable_GetDesc(constants, &table_desc);
1302 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
1303 ok(table_desc.Version == D3DPS_VERSION(2, 0), "Got unexpected version %#lx.\n", table_desc.Version);
1304 ok(table_desc.Constants == ARRAY_SIZE(expect_constants), "Got %u constants.\n", table_desc.Constants);
1305
1306 for (i = 0; i < table_desc.Constants; ++i)
1307 {
1308 char prefix[30];
1309
1311 ok(!!handle, "Failed to get constant.\n");
1312 memset(&desc, 0xcc, sizeof(desc));
1313 count = 1;
1315 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
1316 ok(count == 1, "Got count %u.\n", count);
1317 sprintf(prefix, "Test %u", i);
1318 check_constant_desc(prefix, &desc, &expect_constants[i], FALSE);
1319
1320 if (!strcmp(desc.Name, "f"))
1321 {
1322 for (j = 0; j < ARRAY_SIZE(expect_fields_f); ++j)
1323 {
1325 ok(!!field, "Failed to get constant.\n");
1326 memset(&desc, 0xcc, sizeof(desc));
1327 count = 1;
1329 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
1330 ok(count == 1, "Got count %u.\n", count);
1331 sprintf(prefix, "Test %u, %u", i, j);
1332 check_constant_desc(prefix, &desc, &expect_fields_f[j], !!j);
1333 }
1334 }
1335 else if (!strcmp(desc.Name, "j"))
1336 {
1338 ok(!!field, "Failed to get constant.\n");
1339 memset(&desc, 0xcc, sizeof(desc));
1340 count = 1;
1342 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
1343 ok(count == 1, "Got count %u.\n", count);
1344 sprintf(prefix, "Test %u", i);
1345 check_constant_desc(prefix, &desc, &expect_fields_j, FALSE);
1346 }
1347 }
1348
1350 ID3D10Blob_Release(ps_code);
1351}
@ D3DXPC_SCALAR
Definition: d3dx9shader.h:62
@ D3DXPC_MATRIX_COLUMNS
Definition: d3dx9shader.h:65
@ D3DXPC_STRUCT
Definition: d3dx9shader.h:67
@ D3DXPC_MATRIX_ROWS
Definition: d3dx9shader.h:64
@ D3DXPC_VECTOR
Definition: d3dx9shader.h:63
@ D3DXPC_OBJECT
Definition: d3dx9shader.h:66
#define ID3DXConstantTable_GetDesc(p, a)
Definition: d3dx9shader.h:182
@ D3DXRS_FLOAT4
Definition: d3dx9shader.h:55
#define ID3DXConstantTable_Release(p)
Definition: d3dx9shader.h:177
const char * D3DXHANDLE
Definition: d3dx9shader.h:48
#define ID3DXConstantTable_GetConstantDesc(p, a, b, c)
Definition: d3dx9shader.h:183
@ D3DXPT_SAMPLER3D
Definition: d3dx9shader.h:86
@ D3DXPT_FLOAT
Definition: d3dx9shader.h:76
@ D3DXPT_BOOL
Definition: d3dx9shader.h:74
@ D3DXPT_INT
Definition: d3dx9shader.h:75
@ D3DXPT_VOID
Definition: d3dx9shader.h:73
@ D3DXPT_SAMPLER2D
Definition: d3dx9shader.h:85
@ D3DXPT_TEXTURE2D
Definition: d3dx9shader.h:80
#define ID3DXConstantTable_GetConstant(p, a, b)
Definition: d3dx9shader.h:185
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
unsigned int UINT
Definition: sysinfo.c:13
static void check_constant_desc(const char *prefix, const D3DXCONSTANT_DESC *desc, const D3DXCONSTANT_DESC *expect, BOOL nonzero_defaultvalue)
Definition: hlsl_d3d9.c:1185
constants
Definition: resource.c:30
#define memset(x, y, z)
Definition: compat.h:39
Definition: parser.c:44

Referenced by START_TEST(), and test_constant_tables().

◆ test_d3dinclude_close()

static HRESULT WINAPI test_d3dinclude_close ( ID3DInclude *  iface,
const void *  data 
)
static

Definition at line 1540 of file hlsl_d3d9.c.

1541{
1542 free((void *)data);
1543 return S_OK;
1544}
#define free
Definition: debug_ros.c:5
#define S_OK
Definition: intsafe.h:52

◆ test_d3dinclude_open()

static HRESULT WINAPI test_d3dinclude_open ( ID3DInclude *  iface,
D3D_INCLUDE_TYPE  include_type,
const char *  filename,
const void *  parent_data,
const void **  data,
UINT *  bytes 
)
static

Definition at line 1489 of file hlsl_d3d9.c.

1491{
1492 static const char include1[] =
1493 "#define LIGHT 1\n";
1494 static const char include2[] =
1495 "#include \"include1.h\"\n"
1496 "float4 light_color = LIGHT;\n";
1497 static const char include3[] =
1498 "#include \"include1.h\"\n"
1499 "def c0, LIGHT, 0, 0, 0\n";
1500 char *buffer;
1501
1502 trace("filename %s.\n", filename);
1503 trace("parent_data %p: %s.\n", parent_data, parent_data ? (char *)parent_data : "(null)");
1504
1505 if (!strcmp(filename, "include1.h"))
1506 {
1507 buffer = strdup(include1);
1508 *bytes = strlen(include1);
1509 buffer[*bytes] = '$'; /* everything should still work without a null terminator */
1510 ok(include_type == D3D_INCLUDE_LOCAL, "Unexpected include type %d.\n", include_type);
1511 ok(!strncmp(include2, parent_data, strlen(include2)) || !strncmp(include3, parent_data, strlen(include3)),
1512 "Unexpected parent_data value.\n");
1513 }
1514 else if (!strcmp(filename, "include\\include2.h"))
1515 {
1516 buffer = strdup(include2);
1517 *bytes = strlen(include2);
1518 buffer[*bytes] = '$'; /* everything should still work without a null terminator */
1519 ok(!parent_data, "Unexpected parent_data value.\n");
1520 ok(include_type == D3D_INCLUDE_LOCAL, "Unexpected include type %d.\n", include_type);
1521 }
1522 else if (!strcmp(filename, "include\\include3.h"))
1523 {
1524 buffer = strdup(include3);
1525 *bytes = strlen(include3);
1526 buffer[*bytes] = '$'; /* everything should still work without a null terminator */
1527 ok(!parent_data, "Unexpected parent_data value.\n");
1528 ok(include_type == D3D_INCLUDE_LOCAL, "Unexpected include type %d.\n", include_type);
1529 }
1530 else
1531 {
1532 ok(0, "Unexpected #include for file %s.\n", filename);
1533 return D3DERR_INVALIDCALL;
1534 }
1535
1536 *data = buffer;
1537 return S_OK;
1538}
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
#define trace
Definition: atltest.h:70
#define D3DERR_INVALIDCALL
Definition: d3d10_private.h:42
_ACRTIMP int __cdecl strncmp(const char *, const char *, size_t)
Definition: string.c:3335
static char * strdup(const char *buf)
Definition: string.h:83

◆ test_fail()

static void test_fail ( void  )
static

Definition at line 1353 of file hlsl_d3d9.c.

1354{
1355 static const char *tests[] =
1356 {
1357 /* 0 */
1358 "float4 test() : SV_TARGET\n"
1359 "{\n"
1360 " return y;\n"
1361 "}",
1362
1363 "float4 test() : SV_TARGET\n"
1364 "{\n"
1365 " float4 x = float4(0, 0, 0, 0);\n"
1366 " x.xzzx = float4(1, 2, 3, 4);\n"
1367 " return x;\n"
1368 "}",
1369
1370 "float4 test(float2 pos: TEXCOORD0) : SV_TARGET\n"
1371 "{\n"
1372 " float4 x = pos;\n"
1373 " return x;\n"
1374 "}",
1375
1376 "float4 test(float2 pos, TEXCOORD0) ; SV_TARGET\n"
1377 "{\n"
1378 " pos = float4 x;\n"
1379 " mul(float4(5, 4, 3, 2), mvp) = x;\n"
1380 " return float4;\n"
1381 "}",
1382
1383 "float4 563r(float2 45s: TEXCOORD0) : SV_TARGET\n"
1384 "{\n"
1385 " float2 x = 45s;\n"
1386 " return float4(x.x, x.y, 0, 0);\n"
1387 "}",
1388
1389 /* 5 */
1390 "float4 test() : SV_TARGET\n"
1391 "{\n"
1392 " struct { int b,c; } x = {0};\n"
1393 " return y;\n"
1394 "}",
1395
1396 "float4 test() : SV_TARGET\n"
1397 "{\n"
1398 " struct {} x = {};\n"
1399 " return y;\n"
1400 "}",
1401
1402 "float4 test(float2 pos : TEXCOORD0) : SV_TARGET\n"
1403 "{\n"
1404 " return;\n"
1405 "}",
1406
1407 "void test(float2 pos : TEXCOORD0)\n"
1408 "{\n"
1409 " return pos;\n"
1410 "}",
1411
1412 "float4 test(float2 pos : TEXCOORD0) : SV_TARGET\n"
1413 "{\n"
1414 " return pos;\n"
1415 "}",
1416
1417 /* 10 */
1418 "float4 test(float2 pos: TEXCOORD0) : SV_TARGET\n"
1419 "{\n"
1420 " float a[0];\n"
1421 " return float4(0, 0, 0, 0);\n"
1422 "}",
1423
1424 "float4 test(float2 pos: TEXCOORD0) : SV_TARGET\n"
1425 "{\n"
1426 " float a[65537];\n"
1427 " return float4(0, 0, 0, 0);\n"
1428 "}",
1429
1430 "float4 test(float2 pos: TEXCOORD0) : SV_TARGET\n"
1431 "{\n"
1432 " int x;\n"
1433 " float a[(x = 2)];\n"
1434 " return float4(0, 0, 0, 0);\n"
1435 "}",
1436
1437 "uniform float4 test() : SV_TARGET\n"
1438 "{\n"
1439 " return float4(0, 0, 0, 0);\n"
1440 "}",
1441
1442 "typedef row_major float4x4 matrix_t;\n"
1443 "typedef column_major matrix_t matrix2_t;\n"
1444 "float4 test() : SV_TARGET\n"
1445 "{\n"
1446 " return float4(0, 0, 0, 0);\n"
1447 "}",
1448
1449 /* 15 */
1450 "float4 test()\n"
1451 "{\n"
1452 " return float4(0, 0, 0, 0);\n"
1453 "}",
1454
1455 "float4 test(out float4 o : SV_TARGET)\n"
1456 "{\n"
1457 " o = float4(1, 1, 1, 1);\n"
1458 " return float4(0, 0, 0, 0);\n"
1459 "}",
1460
1461 "struct {float4 a;};\n"
1462 "float4 test() : SV_TARGET\n"
1463 "{\n"
1464 " return float4(0, 0, 0, 0);\n"
1465 "}",
1466 };
1467
1468 static const char *targets[] = {"ps_2_0", "ps_3_0", "ps_4_0"};
1469
1470 ID3D10Blob *compiled, *errors;
1471 unsigned int i, j;
1472 HRESULT hr;
1473
1474 for (j = 0; j < ARRAY_SIZE(targets); ++j)
1475 {
1476 for (i = 0; i < ARRAY_SIZE(tests); ++i)
1477 {
1478 errors = NULL;
1479 compiled = (void *)0xdeadbeef;
1480 hr = D3DCompile(tests[i], strlen(tests[i]), NULL, NULL, NULL, "test", targets[j], 0, 0, &compiled, &errors);
1481 ok(hr == E_FAIL, "Test %u, target %s: Got unexpected hr %#lx.\n", i, targets[j], hr);
1482 ok(!!errors, "Test %u, target %s, expected non-NULL error blob.\n", i, targets[j]);
1483 ID3D10Blob_Release(errors);
1484 ok(!compiled, "Test %u, target %s, expected no compiled shader blob.\n", i, targets[j]);
1485 }
1486 }
1487}
#define E_FAIL
Definition: ddrawi.h:102
static struct test_info tests[]

Referenced by START_TEST().

◆ test_float_vectors()

static void test_float_vectors ( void  )
static

Definition at line 616 of file hlsl_d3d9.c.

617{
619 ID3DXConstantTable *constants;
620 ID3D10Blob *ps_code = NULL;
622 struct vec4 v;
623 HRESULT hr;
624
625 static const char ps_indexing_source[] =
626 "float4 main() : COLOR\n"
627 "{\n"
628 " float4 color;\n"
629 " color[0] = 0.020;\n"
630 " color[1] = 0.245;\n"
631 " color[2] = 0.351;\n"
632 " color[3] = 1.0;\n"
633 " return color;\n"
634 "}";
635
636 /* A uniform index is used so that the compiler can't optimize. */
637 static const char ps_uniform_indexing_source[] =
638 "uniform int i;\n"
639 "float4 main() : COLOR\n"
640 "{\n"
641 " float4 color = float4(0.5, 0.4, 0.3, 0.2);\n"
642 " color.g = color[i];\n"
643 " color.b = 0.8;\n"
644 " return color;\n"
645 "}";
646
648 return;
650
651 ps_code = compile_shader(ps_indexing_source, "ps_2_0", 0);
652 if (ps_code)
653 {
654 draw_quad(device, ps_code);
655
656 v = get_color_vec4(device, 0, 0);
657 ok(compare_vec4(&v, 0.02f, 0.245f, 0.351f, 1.0f, 0),
658 "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
659
660 ID3D10Blob_Release(ps_code);
661 }
662
663 ps_code = compile_shader(ps_uniform_indexing_source, "ps_2_0", 0);
664 if (ps_code)
665 {
666 hr = pD3DXGetShaderConstantTable(ID3D10Blob_GetBufferPointer(ps_code), &constants);
667 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
669 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
671 draw_quad(device, ps_code);
672
673 v = get_color_vec4(device, 0, 0);
674 ok(compare_vec4(&v, 0.5f, 0.3f, 0.8f, 0.2f, 0),
675 "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
676
677 ID3D10Blob_Release(ps_code);
678 }
679
681}
#define ID3DXConstantTable_SetInt(p, a, b, c)
Definition: d3dx9shader.h:192

Referenced by START_TEST().

◆ test_global_initializer()

static void test_global_initializer ( void  )
static

Definition at line 1060 of file hlsl_d3d9.c.

1061{
1063 ID3DXConstantTable *constants;
1064 ID3D10Blob *ps_code = NULL;
1065 struct vec4 v;
1066 HRESULT hr;
1067
1068 static const char ps_source[] =
1069 "float myfunc()\n"
1070 "{\n"
1071 " return 0.6;\n"
1072 "}\n"
1073 "static float sf = myfunc() + 0.2;\n"
1074 "uniform float uf = 0.2;\n"
1075 "float4 main() : COLOR\n"
1076 "{\n"
1077 " return float4(sf, uf, 0, 0);\n"
1078 "}";
1079
1081 return;
1082
1083 ps_code = compile_shader(ps_source, "ps_2_0", 0);
1084 hr = pD3DXGetShaderConstantTable(ID3D10Blob_GetBufferPointer(ps_code), &constants);
1085 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
1087 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
1089 draw_quad(test_context.device, ps_code);
1090
1092 ok(compare_vec4(&v, 0.8f, 0.2f, 0.0f, 0.0f, 4096),
1093 "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
1094
1095 ID3D10Blob_Release(ps_code);
1097}
#define ID3DXConstantTable_SetDefaults(p, a)
Definition: d3dx9shader.h:188

Referenced by START_TEST().

◆ test_hlsl_double()

static void test_hlsl_double ( void  )
static

Definition at line 1815 of file hlsl_d3d9.c.

1816{
1817 static const char ps_hlsl[] =
1818 "float func(float x){return 0.1;}\n"
1819 "float func(half x){return 0.2;}\n"
1820 "float func(double x){return 0.3;}\n"
1821 "\n"
1822 "float4 main(uniform double u) : COLOR\n"
1823 "{\n"
1824 " return func(u);\n"
1825 "}\n";
1826 ID3DBlob *ps_bytecode, *errors;
1827 struct test_context context;
1828 struct vec4 color;
1829 HRESULT hr;
1830
1832 return;
1833
1834 hr = D3DCompile(ps_hlsl, sizeof(ps_hlsl), NULL, NULL, NULL, "main", "ps_2_0", 0, 0, &ps_bytecode, &errors);
1835#if D3D_COMPILER_VERSION >= 46
1836 todo_wine ok(hr == E_FAIL, "Unexpected hr %#lx.\n", hr);
1837#else
1838 todo_wine ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1839#endif
1840 if (FAILED(hr))
1841 {
1842 trace("%s\n", (char *)ID3D10Blob_GetBufferPointer(errors));
1844 return;
1845 }
1846
1847 draw_quad(context.device, ps_bytecode);
1848
1849 color = get_color_vec4(context.device, 320, 240);
1850 ok(compare_vec4(&color, 0.3, 0.3, 0.3, 0.3, 0), "Unexpected color {%.8e, %.8e, %.8e, %.8e}.\n",
1851 color.x, color.y, color.z, color.w);
1853}
GLuint color
Definition: glext.h:6243

Referenced by START_TEST().

◆ test_include()

static void test_include ( void  )
static

Definition at line 1609 of file hlsl_d3d9.c.

1610{
1612 WCHAR filename[MAX_PATH], include_filename[MAX_PATH];
1613 ID3D10Blob *blob = NULL, *errors = NULL;
1614 CHAR filename_a[MAX_PATH];
1615 unsigned int i;
1616 HRESULT hr;
1617 DWORD len;
1618 static const char ps_code[] =
1619 "#include \"include\\include2.h\"\n"
1620 "\n"
1621 "float4 main() : COLOR\n"
1622 "{\n"
1623 " return light_color;\n"
1624 "}";
1625 static const char include1[] =
1626 "#define LIGHT 1\n";
1627 static const char include1_wrong[] =
1628 "#define LIGHT nope\n";
1629 static const char include2[] =
1630 "#include \"include1.h\"\n"
1631 "float4 light_color = LIGHT;\n";
1632 static const char include3[] =
1633 "#include \"include1.h\"\n"
1634 "def c0, LIGHT, 0, 0, 0\n";
1635
1636#if D3D_COMPILER_VERSION >= 46
1638 static const char ps_absolute_template[] =
1639 "#include \"%ls\"\n"
1640 "\n"
1641 "float4 main() : COLOR\n"
1642 "{\n"
1643 " return light_color;\n"
1644 "}";
1645 char ps_absolute_buffer[sizeof(ps_absolute_template) + MAX_PATH];
1646#endif
1647
1648 static const include_test_cb tests[] =
1649 {
1653#if D3D_COMPILER_VERSION >= 46
1654 call_D3DCompile2,
1655#endif
1656 };
1657
1658 create_file(L"source.ps", ps_code, strlen(ps_code), filename);
1659 create_directory(L"include");
1660 create_file(L"include\\include1.h", include1_wrong, strlen(include1_wrong), NULL);
1661 create_file(L"include1.h", include1, strlen(include1), NULL);
1662 create_file(L"include\\include2.h", include2, strlen(include2), include_filename);
1663 create_file(L"include\\include3.h", include3, strlen(include3), NULL);
1664
1666 WideCharToMultiByte(CP_ACP, 0, filename, -1, filename_a, len, NULL, NULL);
1667
1668 for (i = 0; i < ARRAY_SIZE(tests); ++i)
1669 {
1670 winetest_push_context("Test %u", i);
1671
1672 hr = tests[i](filename_a, &include.ID3DInclude_iface, &blob, &errors);
1673 todo_wine_if (i == 1)
1674 {
1675 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1676 ok(!!blob, "Got unexpected blob.\n");
1677 }
1678 todo_wine_if (i == 1)
1679 ok(!errors, "Got unexpected errors.\n");
1680 if (blob)
1681 {
1682 ID3D10Blob_Release(blob);
1683 blob = NULL;
1684 }
1685
1686#if D3D_COMPILER_VERSION >= 46
1688 todo_wine_if (!i)
1689 ok(hr == (i == 0 ? D3DXERR_INVALIDDATA : E_FAIL), "Got unexpected hr %#lx.\n", hr);
1690 ok(!blob, "Got unexpected blob.\n");
1691 ok(!!errors, "Got unexpected errors.\n");
1692 ID3D10Blob_Release(errors);
1693 errors = NULL;
1694
1695 /* Windows always seems to resolve includes from the initial file location
1696 * instead of using the immediate parent, as it would be the case for
1697 * standard C preprocessor includes. */
1698 hr = tests[i](filename_a, D3D_COMPILE_STANDARD_FILE_INCLUDE, &blob, &errors);
1699 todo_wine_if (i == 1)
1700 {
1701 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1702 ok(!!blob, "Got unexpected blob.\n");
1703 ok(!errors, "Got unexpected errors.\n");
1704 }
1705 if (blob)
1706 {
1707 ID3D10Blob_Release(blob);
1708 blob = NULL;
1709 }
1710#endif /* D3D_COMPILER_VERSION >= 46 */
1711
1713 }
1714
1715#if D3D_COMPILER_VERSION >= 46
1716
1717 hr = D3DCompileFromFile(L"nonexistent", NULL, NULL, "main", "vs_2_0", 0, 0, &blob, &errors);
1718 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "Got unexpected hr %#lx.\n", hr);
1719 ok(!blob, "Got unexpected blob.\n");
1720 ok(!errors, "Got unexpected errors.\n");
1721
1722 hr = D3DCompileFromFile(filename, NULL, NULL, "main", "ps_2_0", 0, 0, &blob, &errors);
1723 ok(hr == E_FAIL, "Got unexpected hr %#lx.\n", hr);
1724 ok(!blob, "Got unexpected blob.\n");
1725 ok(!!errors, "Got unexpected errors.\n");
1726 trace("%s.\n", (char *)ID3D10Blob_GetBufferPointer(errors));
1727 ID3D10Blob_Release(errors);
1728 errors = NULL;
1729
1730 hr = D3DCompileFromFile(filename, NULL, &include.ID3DInclude_iface, "main", "ps_2_0", 0, 0, &blob, &errors);
1731 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1732 ok(!!blob, "Got unexpected blob.\n");
1733 ok(!errors, "Got unexpected errors.\n");
1734 ID3D10Blob_Release(blob);
1735 blob = NULL;
1736
1737 /* Windows always seems to resolve includes from the initial file location
1738 * instead of using the immediate parent, as it would be the case for
1739 * standard C preprocessor includes. */
1740 hr = D3DCompileFromFile(filename, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, "main", "ps_2_0", 0, 0, &blob, &errors);
1741 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1742 ok(!!blob, "Got unexpected blob.\n");
1743 ok(!errors, "Got unexpected errors.\n");
1744 ID3D10Blob_Release(blob);
1745 blob = NULL;
1746
1747 sprintf(ps_absolute_buffer, ps_absolute_template, include_filename);
1748 hr = D3DCompile(ps_absolute_buffer, sizeof(ps_absolute_buffer), filename_a, NULL,
1749 D3D_COMPILE_STANDARD_FILE_INCLUDE, "main", "ps_2_0", 0, 0, &blob, &errors);
1750 todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1751 todo_wine ok(!!blob, "Got unexpected blob.\n");
1752 todo_wine ok(!errors, "Got unexpected errors.\n");
1753 if (blob)
1754 {
1755 ID3D10Blob_Release(blob);
1756 blob = NULL;
1757 }
1758
1761
1762 for (i = 0; i < ARRAY_SIZE(tests); ++i)
1763 {
1764 winetest_push_context("Test %u", i);
1765
1767 todo_wine_if (i == 1)
1768 {
1769 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1770 ok(!!blob, "Got unexpected blob.\n");
1771 ok(!errors, "Got unexpected errors.\n");
1772 }
1773 if (blob)
1774 {
1775 ID3D10Blob_Release(blob);
1776 blob = NULL;
1777 }
1778
1780 }
1781
1782 hr = D3DCompileFromFile(L"source.ps", NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, "main", "ps_2_0", 0, 0, &blob, &errors);
1783 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1784 ok(!!blob, "Got unexpected blob.\n");
1785 ok(!errors, "Got unexpected errors.\n");
1786 ID3D10Blob_Release(blob);
1787 blob = NULL;
1788
1790#endif /* D3D_COMPILER_VERSION >= 46 */
1791
1792 delete_file(L"source.ps");
1793 delete_file(L"include\\include1.h");
1794 delete_file(L"include1.h");
1795 delete_file(L"include\\include2.h");
1796 delete_directory(L"include");
1797}
#define D3D_COMPILE_STANDARD_FILE_INCLUDE
Definition: d3dcompiler.h:85
HRESULT WINAPI D3DCompileFromFile(const WCHAR *filename, const D3D_SHADER_MACRO *defines, ID3DInclude *include, const char *entrypoint, const char *target, UINT flags1, UINT flags2, ID3DBlob **code, ID3DBlob **errors)
Definition: compiler.c:743
#define GetCurrentDirectoryW(x, y)
Definition: compat.h:756
#define CP_ACP
Definition: compat.h:109
#define WideCharToMultiByte
Definition: compat.h:111
BOOL WINAPI SetCurrentDirectoryW(IN LPCWSTR lpPathName)
Definition: path.c:2267
void CDECL unexpected(void)
Definition: cpp.c:711
#define L(x)
Definition: resources.c:13
GLdouble n
Definition: glext.h:7729
GLenum GLsizei len
Definition: glext.h:6722
static HRESULT call_D3DAssemble(const char *source_name, ID3DInclude *include, ID3D10Blob **blob, ID3D10Blob **errors)
Definition: hlsl_d3d9.c:1557
static void delete_directory(const WCHAR *dir)
Definition: hlsl_d3d9.c:92
HRESULT(* include_test_cb)(const char *source_name, ID3DInclude *include, ID3D10Blob **blob, ID3D10Blob **errors)
Definition: hlsl_d3d9.c:1607
static BOOL create_directory(const WCHAR *dir)
Definition: hlsl_d3d9.c:83
#define D3DXERR_INVALIDDATA
Definition: hlsl_d3d9.c:26
static HRESULT call_D3DPreprocess(const char *source_name, ID3DInclude *include, ID3D10Blob **blob, ID3D10Blob **errors)
Definition: hlsl_d3d9.c:1596
static const struct ID3DIncludeVtbl test_d3dinclude_vtbl
Definition: hlsl_d3d9.c:1546
static HRESULT call_D3DCompile(const char *source_name, ID3DInclude *include, ID3D10Blob **blob, ID3D10Blob **errors)
Definition: hlsl_d3d9.c:1567
if(dx< 0)
Definition: linetemp.h:194
#define todo_wine_if(is_todo)
Definition: minitest.h:81
void __cdecl void __cdecl void __cdecl void __cdecl void __cdecl void winetest_pop_context(void)
void __cdecl void __cdecl void __cdecl void __cdecl void __cdecl winetest_push_context(const char *fmt,...) __WINE_PRINTF_ATTR(1
Definition: test.h:539
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define create_file(name, size)
Definition: asmcache.c:811
char CHAR
Definition: pedump.c:57
#define delete_file(f)
Definition: reg_test.h:97
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210

Referenced by START_TEST().

◆ test_majority()

static void test_majority ( void  )
static

Definition at line 832 of file hlsl_d3d9.c.

833{
834 static const float data[] = { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f };
836 ID3D10Blob *ps_code = NULL;
837 struct vec4 v;
838 HRESULT hr;
839
840 static const char ps_typedef_source[] =
841 "typedef float2x2 matrix_t;\n"
842 "typedef row_major matrix_t row_matrix_t;\n"
843 "typedef column_major matrix_t col_matrix_t;\n"
844 "uniform row_matrix_t m1;\n"
845 "uniform col_matrix_t m2;\n"
846 "float4 main() : COLOR\n"
847 "{\n"
848 " float4 ret;\n"
849 " ret.xy = m1[0];\n"
850 " ret.zw = m2[0];\n"
851 " return ret;\n"
852 "}";
853
854 static const char ps_pragmas_source[] =
855 "#pragma pack_matrix(row_major)\n"
856 "uniform float2x2 m1;\n"
857 "#pragma pack_matrix(column_major)\n"
858 "uniform float2x2 m2;\n"
859 "float4 main() : COLOR\n"
860 "{\n"
861 " float4 ret;\n"
862 " ret.xy = m1[0];\n"
863 " ret.zw = m2[0];\n"
864 " return ret;\n"
865 "}";
866
867 static const char ps_row_source[] =
868 "uniform row_major float2x2 m1;\n"
869 "uniform row_major float2x2 m2;\n"
870 "float4 main() : COLOR\n"
871 "{\n"
872 " float4 ret;\n"
873 " ret.xy = m1[0];\n"
874 " ret.zw = m2[0];\n"
875 " return ret;\n"
876 "}";
877
878 static const char ps_column_source[] =
879 "uniform column_major float2x2 m1;\n"
880 "uniform column_major float2x2 m2;\n"
881 "float4 main() : COLOR\n"
882 "{\n"
883 " float4 ret;\n"
884 " ret.xy = m1[0];\n"
885 " ret.zw = m2[0];\n"
886 " return ret;\n"
887 "}";
888
889 static const char ps_no_modifiers_source[] =
890 "uniform float2x2 m1;\n"
891 "uniform float2x2 m2;\n"
892 "float4 main() : COLOR\n"
893 "{\n"
894 " float4 ret;\n"
895 " ret.xy = m1[0];\n"
896 " ret.zw = m2[0];\n"
897 " return ret;\n"
898 "}";
899
900 static const struct test
901 {
902 const char *code;
903 struct vec4 color;
904 unsigned int flags;
905 }
906 tests[] =
907 {
908 { ps_typedef_source, { 0.1f, 0.2f, 0.1f, 0.5f } },
909 { ps_pragmas_source, { 0.1f, 0.2f, 0.1f, 0.5f } },
910 { ps_row_source, { 0.1f, 0.2f, 0.1f, 0.2f } },
911 { ps_column_source, { 0.1f, 0.5f, 0.1f, 0.5f } },
912 { ps_no_modifiers_source, { 0.1f, 0.2f, 0.1f, 0.2f }, D3DCOMPILE_PACK_MATRIX_ROW_MAJOR },
913 { ps_no_modifiers_source, { 0.1f, 0.5f, 0.1f, 0.5f }, D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR },
914 { ps_no_modifiers_source, { 0.1f, 0.2f, 0.1f, 0.2f }, D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR | D3DCOMPILE_PACK_MATRIX_ROW_MAJOR },
915 { ps_pragmas_source, { 0.1f, 0.2f, 0.1f, 0.5f }, D3DCOMPILE_PACK_MATRIX_ROW_MAJOR },
916 { ps_pragmas_source, { 0.1f, 0.2f, 0.1f, 0.5f }, D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR },
917 };
918 unsigned int i;
919
921 return;
922
923 for (i = 0; i < ARRAY_SIZE(tests); ++i)
924 {
925 const struct vec4 *c = &tests[i].color;
926
927 winetest_push_context("Test %u", i);
928
929 ps_code = compile_shader(tests[i].code, "ps_2_0", tests[i].flags);
930 if (ps_code)
931 {
932 ID3DXConstantTable *constants;
935 UINT count;
936
937 hr = pD3DXGetShaderConstantTable(ID3D10Blob_GetBufferPointer(ps_code), &constants);
938 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
939
941 ok(!!h, "Failed to find a constant.\n");
942 count = 1;
944 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
946 data, desc.RegisterCount);
947 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
948
950 ok(!!h, "Failed to find a constant.\n");
951 count = 1;
953 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
955 data, desc.RegisterCount);
956 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
957
959
960 draw_quad(test_context.device, ps_code);
961
963 ok(compare_vec4(&v, c->x, c->y, c->z, c->w, 1),
964 "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
965
966 ID3D10Blob_Release(ps_code);
967 }
968
970 }
971
973}
#define IDirect3DDevice9_SetPixelShaderConstantF(p, a, b, c)
Definition: d3d9.h:1444
#define D3DCOMPILE_PACK_MATRIX_ROW_MAJOR
Definition: d3dcompiler.h:45
#define D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR
Definition: d3dcompiler.h:46
#define ID3DXConstantTable_GetConstantByName(p, a, b)
Definition: d3dx9shader.h:186
const GLubyte * c
Definition: glext.h:8905
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
#define test
Definition: rosglue.h:37
Definition: inflate.c:139

Referenced by START_TEST().

◆ test_math()

static void test_math ( void  )
static

Definition at line 486 of file hlsl_d3d9.c.

487{
489 ID3DXConstantTable *constants;
490 ID3D10Blob *ps_code = NULL;
492 struct vec4 v;
493 HRESULT hr;
494
495 static const char ps_source[] =
496 "float4 main(uniform float u, uniform float v, uniform float w, uniform float x,\n"
497 " uniform float y, uniform float z): COLOR\n"
498 "{\n"
499 " return float4(x * y - z / w + --u / -v,\n"
500 " z * x / y + w / -v,\n"
501 " u + v - w,\n"
502 " x / y / w);\n"
503 "}";
504
506 return;
508
509 ps_code = compile_shader(ps_source, "ps_2_0", 0);
510 hr = pD3DXGetShaderConstantTable(ID3D10Blob_GetBufferPointer(ps_code), &constants);
511 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
513 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
515 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
517 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
519 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
521 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
523 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
525
526 draw_quad(device, ps_code);
527
528 v = get_color_vec4(device, 0, 0);
529 ok(compare_vec4(&v, -12.43f, 9.833333f, 1.6f, 35.0f, 1),
530 "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
531
532 ID3D10Blob_Release(ps_code);
534}
#define ID3DXConstantTable_SetFloat(p, a, b, c)
Definition: d3dx9shader.h:194

Referenced by START_TEST().

◆ test_no_output_blob()

static void test_no_output_blob ( void  )
static

Definition at line 1799 of file hlsl_d3d9.c.

1800{
1801 static const char vs_source[] =
1802 "float4 main(float4 pos : POSITION, inout float2 texcoord : TEXCOORD0) : POSITION\n"
1803 "{\n"
1804 " return pos;\n"
1805 "}";
1806 ID3D10Blob *errors;
1807 HRESULT hr;
1808
1809 errors = (void *)0xdeadbeef;
1810 hr = D3DCompile(vs_source, strlen(vs_source), NULL, NULL, NULL, "main", "vs_2_0", 0, 0, NULL, &errors);
1811 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1812 ok(!errors, "Unexpected errors blob.\n");
1813}

Referenced by START_TEST().

◆ test_return()

static void test_return ( void  )
static

Definition at line 749 of file hlsl_d3d9.c.

750{
752 ID3D10Blob *ps_code = NULL;
753 struct vec4 v;
754
755 static const char *void_source =
756 "void main(float x : TEXCOORD0, out float4 ret : COLOR)\n"
757 "{\n"
758 " ret = float4(0.1, 0.2, 0.3, 0.4);\n"
759 " return;\n"
760 " ret = float4(0.5, 0.6, 0.7, 0.8);\n"
761 "}";
762
763 static const char *implicit_conversion_source =
764 "float4 main(float x : TEXCOORD0) : COLOR\n"
765 "{\n"
766 " return float2x2(0.4, 0.3, 0.2, 0.1);\n"
767 "}";
768
770 return;
771
772 ps_code = compile_shader(void_source, "ps_2_0", 0);
773 draw_quad(test_context.device, ps_code);
774
776 ok(compare_vec4(&v, 0.1f, 0.2f, 0.3f, 0.4f, 0),
777 "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
778
779 ID3D10Blob_Release(ps_code);
780
781 ps_code = compile_shader(implicit_conversion_source, "ps_2_0", 0);
782 if (ps_code)
783 {
784 draw_quad(test_context.device, ps_code);
785
787 ok(compare_vec4(&v, 0.4f, 0.3f, 0.2f, 0.1f, 0),
788 "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
789
790 ID3D10Blob_Release(ps_code);
791 }
792
794}

Referenced by START_TEST().

◆ test_samplers()

static void test_samplers ( void  )
static

Definition at line 1099 of file hlsl_d3d9.c.

1100{
1102 IDirect3DTexture9 *texture;
1103 ID3D10Blob *ps_code = NULL;
1104 D3DLOCKED_RECT map_desc;
1105 unsigned int i;
1106 struct vec4 v;
1107 HRESULT hr;
1108
1109 static const char *tests[] =
1110 {
1111 "sampler s;\n"
1112 "float4 main() : COLOR\n"
1113 "{\n"
1114 " return tex2D(s, float2(0.75, 0.25));\n"
1115 "}",
1116
1117 "SamplerState s;\n"
1118 "float4 main() : COLOR\n"
1119 "{\n"
1120 " return tex2D(s, float2(0.75, 0.25));\n"
1121 "}",
1122
1123 "sampler2D s;\n"
1124 "float4 main() : COLOR\n"
1125 "{\n"
1126 " return tex2D(s, float2(0.75, 0.25));\n"
1127 "}",
1128
1129 "sampler s;\n"
1130 "Texture2D t;\n"
1131 "float4 main() : COLOR\n"
1132 "{\n"
1133 " return t.Sample(s, float2(0.75, 0.25));\n"
1134 "}",
1135
1136 "SamplerState s;\n"
1137 "Texture2D t;\n"
1138 "float4 main() : COLOR\n"
1139 "{\n"
1140 " return t.Sample(s, float2(0.75, 0.25));\n"
1141 "}",
1142 };
1143
1145 return;
1146
1149 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
1150
1152 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
1153 memset(map_desc.pBits, 0, 2 * map_desc.Pitch);
1154 ((DWORD *)map_desc.pBits)[1] = 0x00ff00ff;
1156 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
1157
1158 hr = IDirect3DDevice9_SetTexture(test_context.device, 0, (IDirect3DBaseTexture9 *)texture);
1159 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
1161 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
1162
1163 for (i = 0; i < ARRAY_SIZE(tests); ++i)
1164 {
1166 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#lx.\n", i, hr);
1167 todo_wine_if (i > 2)
1168 ps_code = compile_shader(tests[i], "ps_2_0", 0);
1169 if (ps_code)
1170 {
1171 draw_quad(test_context.device, ps_code);
1172
1174 ok(compare_vec4(&v, 1.0f, 0.0f, 1.0f, 0.0f, 0),
1175 "Test %u: Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", i, v.x, v.y, v.z, v.w);
1176
1177 ID3D10Blob_Release(ps_code);
1178 }
1179 }
1180
1183}
@ D3DTEXF_POINT
Definition: d3d8types.h:871
#define D3DLOCK_DISCARD
Definition: d3d8types.h:72
#define D3DUSAGE_DYNAMIC
Definition: d3d8types.h:99
@ D3DPOOL_DEFAULT
Definition: d3d8types.h:709
#define D3DCOLOR_XRGB(r, g, b)
Definition: d3d8types.h:44
#define D3DCLEAR_TARGET
Definition: d3d8types.h:30
#define IDirect3DTexture9_UnlockRect(p, a)
Definition: d3d9.h:863
#define IDirect3DDevice9_CreateTexture(p, a, b, c, d, e, f, g, h)
Definition: d3d9.h:1358
#define IDirect3DDevice9_Clear(p, a, b, c, d, e, f)
Definition: d3d9.h:1378
#define IDirect3DTexture9_LockRect(p, a, b, c, d)
Definition: d3d9.h:862
#define IDirect3DDevice9_SetTexture(p, a, b)
Definition: d3d9.h:1400
#define IDirect3DTexture9_Release(p)
Definition: d3d9.h:842
#define IDirect3DDevice9_SetSamplerState(p, a, b, c)
Definition: d3d9.h:1404
@ D3DSAMP_MAGFILTER
Definition: d3d9types.h:1237
GLenum GLuint texture
Definition: glext.h:6295

Referenced by START_TEST().

◆ test_struct_assignment()

static void test_struct_assignment ( void  )
static

Definition at line 975 of file hlsl_d3d9.c.

976{
978 ID3D10Blob *ps_code = NULL;
979 struct vec4 v;
980
981 static const char ps_source[] =
982 "struct apple\n"
983 "{\n"
984 " struct\n"
985 " {\n"
986 " float4 a;\n"
987 " } m;\n"
988 " float4 b;\n"
989 "};\n"
990 "float4 main() : COLOR\n"
991 "{\n"
992 " struct apple q, r, s;\n"
993 " q.m.a = float4(0.1, 0.2, 0.3, 0.4);\n"
994 " q.b = float4(0.5, 0.1, 0.4, 0.5);\n"
995 " s = r = q;\n"
996 " return s.m.a + s.b;\n"
997 "}";
998
1000 return;
1001
1002 ps_code = compile_shader(ps_source, "ps_2_0", 0);
1003 draw_quad(test_context.device, ps_code);
1004
1006 ok(compare_vec4(&v, 0.6f, 0.3f, 0.7f, 0.9f, 1),
1007 "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
1008
1009 ID3D10Blob_Release(ps_code);
1011}

Referenced by START_TEST().

◆ test_struct_semantics()

static void test_struct_semantics ( void  )
static

Definition at line 1013 of file hlsl_d3d9.c.

1014{
1016 ID3D10Blob *ps_code = NULL;
1017 struct vec4 v;
1018
1019 static const char ps_source[] =
1020 "struct input\n"
1021 "{\n"
1022 " struct\n"
1023 " {\n"
1024 " float4 texcoord : TEXCOORD0;\n"
1025 " } m;\n"
1026 "};\n"
1027 "struct output\n"
1028 "{\n"
1029 " struct\n"
1030 " {\n"
1031 " float4 color : COLOR;\n"
1032 " } m;\n"
1033 "};\n"
1034 "struct output main(struct input i)\n"
1035 "{\n"
1036 " struct output o;\n"
1037 " o.m.color = i.m.texcoord;\n"
1038 " return o;\n"
1039 "}";
1040
1042 return;
1043
1044 ps_code = compile_shader(ps_source, "ps_2_0", 0);
1045 draw_quad(test_context.device, ps_code);
1046
1048 v.z = v.w = 0.0f;
1049 ok(compare_vec4(&v, 0.1f, 0.1f, 0.0f, 0.0f, 4096),
1050 "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
1051 v = get_color_vec4(test_context.device, 320, 240);
1052 v.z = v.w = 0.0f;
1053 ok(compare_vec4(&v, 0.5f, 0.5f, 0.0f, 0.0f, 4096),
1054 "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
1055
1056 ID3D10Blob_Release(ps_code);
1058}

Referenced by START_TEST().

◆ test_swizzle()

static void test_swizzle ( void  )
static

Definition at line 360 of file hlsl_d3d9.c.

361{
362 static const D3DXVECTOR4 color = {0.0303f, 0.0f, 0.0f, 0.0202f};
364 ID3DXConstantTable *constants;
365 ID3D10Blob *ps_code = NULL;
367 unsigned int i;
368 struct vec4 v;
369 HRESULT hr;
370
371 static const struct
372 {
373 const char *source;
374 struct vec4 color;
375 }
376 tests[] =
377 {
378 {
379 "uniform float4 color;\n"
380 "float4 main() : COLOR\n"
381 "{\n"
382 " float4 ret = color;\n"
383 " ret.gb = ret.ra;\n"
384 " ret.ra = float2(0.0101, 0.0404);\n"
385 " return ret;\n"
386 "}",
387 {0.0101f, 0.0303f, 0.0202f, 0.0404f}
388 },
389 {
390 "float4 main() : COLOR\n"
391 "{\n"
392 " float4 ret = float4(0.1, 0.2, 0.3, 0.4);\n"
393 " ret.wyz.yx = float2(0.5, 0.6).yx;\n"
394 " return ret;\n"
395 "}",
396 {0.1f, 0.6f, 0.3f, 0.5f}
397 },
398 {
399 "float4 main() : COLOR\n"
400 "{\n"
401 " float4 ret;\n"
402 " ret.zwyx = float4(0.1, 0.2, 0.3, 0.4);\n"
403 " return ret;\n"
404 "}",
405 {0.4f, 0.3f, 0.1f, 0.2f}
406 },
407 {
408 "float4 main() : COLOR\n"
409 "{\n"
410 " float4 ret;\n"
411 " ret.yw.y = 0.1;\n"
412 " ret.xzy.yz.y.x = 0.2;\n"
413 " ret.yzwx.yzwx.wz.y = 0.3;\n"
414 " ret.zxy.xyz.zxy.xy.y = 0.4;\n"
415 " return ret;\n"
416 "}",
417 {0.3f, 0.2f, 0.4f, 0.1f}
418 },
419 {
420 "float4 main() : COLOR\n"
421 "{\n"
422 " float4 ret;\n"
423 " ret.yxz.yx = float2(0.1, 0.2);\n"
424 " ret.w.x = 0.3;\n"
425 " ret.wzyx.zyx.yx.x = 0.4;\n"
426 " return ret;\n"
427 "}",
428 {0.1f, 0.2f, 0.4f, 0.3f}
429 },
430 {
431 "float4 main() : COLOR\n"
432 "{\n"
433 " float4 ret = float4(0.1, 0.2, 0.3, 0.4).ywxz.zyyz;\n"
434 " return ret;\n"
435 "}",
436 {0.1f, 0.4f, 0.4f, 0.1f}
437 },
438 {
439 "float4 main() : COLOR\n"
440 "{\n"
441 " float4 ret = float4(0.1, 0.2, 0.3, 0.4);\n"
442 " ret.yxwz = ret;\n"
443 " ret = ret.wyzx;\n"
444 " return ret;\n"
445 "}",
446 {0.3f, 0.1f, 0.4f, 0.2f}
447 },
448 {
449 "float4 main() : COLOR\n"
450 "{\n"
451 " float4 ret;\n"
452 " ret.xyzw.xyzw = float4(0.1, 0.2, 0.3, 0.4);\n"
453 " return ret;\n"
454 "}",
455 {0.1f, 0.2f, 0.3f, 0.4f}
456 },
457 };
458
460 return;
462
463 for (i = 0; i < ARRAY_SIZE(tests); ++i)
464 {
465 ps_code = compile_shader(tests[i].source, "ps_2_0", 0);
466 if (i == 0)
467 {
468 hr = pD3DXGetShaderConstantTable(ID3D10Blob_GetBufferPointer(ps_code), &constants);
469 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
471 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
473 }
474 draw_quad(device, ps_code);
475
476 v = get_color_vec4(device, 0, 0);
477 ok(compare_vec4(&v, tests[i].color.x, tests[i].color.y, tests[i].color.z, tests[i].color.w, 0),
478 "Test %u: Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", i, v.x, v.y, v.z, v.w);
479
480 ID3D10Blob_Release(ps_code);
481 }
482
484}
#define ID3DXConstantTable_SetVector(p, a, b, c)
Definition: d3dx9shader.h:196

Referenced by START_TEST().

◆ test_trig()

static void test_trig ( void  )
static

Definition at line 683 of file hlsl_d3d9.c.

684{
686 ID3D10Blob *ps_code = NULL;
688 const struct vec4 *v;
689 struct readback rb;
690 unsigned int i;
691
692 static const char ps_source[] =
693 "float4 main(float x : TEXCOORD0) : COLOR\n"
694 "{\n"
695 " const float pi2 = 6.2831853;\n"
696 " float calcd_sin = (sin(x * pi2) + 1)/2;\n"
697 " float calcd_cos = (cos(x * pi2) + 1)/2;\n"
698 " return float4(calcd_sin, calcd_cos, 0, 0);\n"
699 "}";
700
702 return;
704
705 ps_code = compile_shader(ps_source, "ps_2_0", 0);
706 draw_quad(device, ps_code);
707 init_readback(device, &rb);
708 for (i = 0; i < 32; ++i)
709 {
710 float expect_x = (sinf(i * 2 * M_PI / 32) + 1.0f) / 2.0f;
711 float expect_y = (cosf(i * 2 * M_PI / 32) + 1.0f) / 2.0f;
712 v = get_readback_vec4(&rb, i * 640 / 32, 0);
713 ok(compare_vec4(v, expect_x, expect_y, 0.0f, 0.0f, 4096),
714 "Test %u: Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
715 i, v->x, v->y, v->z, v->w, expect_x, expect_y, 0.0f, 0.0f);
716 }
717 release_readback(&rb);
718 ID3D10Blob_Release(ps_code);
720}
_ACRTIMP float __cdecl cosf(float)
Definition: cosf.c:13
_ACRTIMP float __cdecl sinf(float)
Definition: sinf.c:13
#define M_PI
Definition: macros.h:263

Referenced by START_TEST().

Variable Documentation

◆ constant_table

◆ datasize

SIZE_T datasize

Definition at line 28 of file hlsl_d3d9.c.

◆ defines

Definition at line 29 of file hlsl_d3d9.c.

◆ error_messages

Definition at line 30 of file hlsl_d3d9.c.

◆ filename

Definition at line 28 of file hlsl_d3d9.c.

◆ flags

◆ include

◆ shader

◆ temp_dir

◆ test_d3dinclude_vtbl

const struct ID3DIncludeVtbl test_d3dinclude_vtbl
static
Initial value:
=
{
}
static HRESULT WINAPI test_d3dinclude_open(ID3DInclude *iface, D3D_INCLUDE_TYPE include_type, const char *filename, const void *parent_data, const void **data, UINT *bytes)
Definition: hlsl_d3d9.c:1489
static HRESULT WINAPI test_d3dinclude_close(ID3DInclude *iface, const void *data)
Definition: hlsl_d3d9.c:1540

Definition at line 1546 of file hlsl_d3d9.c.

Referenced by test_include().