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

Go to the source code of this file.

Classes

struct  vec2
 
struct  vec4
 
struct  test_context
 
struct  readback
 

Macros

#define COBJMACROS
 
#define compile_shader(a, b)   compile_shader_(__LINE__, a, b, 0)
 
#define compile_shader_flags(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 create_buffer(a, b, c, d)   create_buffer_(__LINE__, a, b, c, d)
 
#define draw_quad(context, ps_code)   draw_quad_(__LINE__, context, ps_code)
 

Functions

static HRESULT (WINAPI *pD3D11CreateDevice)(IDXGIAdapter *adapter
 
static ID3D10Blob * compile_shader_ (unsigned int line, const char *source, const char *target, UINT flags)
 
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 ID3D11Device * create_device (void)
 
static IDXGISwapChain * create_swapchain (ID3D11Device *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 ID3D11Buffer * create_buffer_ (unsigned int line, ID3D11Device *device, unsigned int bind_flags, unsigned int size, const void *data)
 
static void draw_quad_ (unsigned int line, struct test_context *context, ID3D10Blob *ps_code)
 
static void init_readback (struct test_context *context, struct readback *rb)
 
static void release_readback (struct test_context *context, struct readback *rb)
 
static const struct vec4 * get_readback_vec4 (struct readback *rb, unsigned int x, unsigned int y)
 
static struct vec4 get_color_vec4 (struct test_context *context, unsigned int x, unsigned int y)
 
static void test_swizzle (void)
 
static void test_math (void)
 
static void test_conditionals (void)
 
static void test_trig (void)
 
static void test_sampling (void)
 
static void check_type_desc (const D3D11_SHADER_TYPE_DESC *type, const D3D11_SHADER_TYPE_DESC *expect)
 
static void check_resource_binding (const D3D11_SHADER_INPUT_BIND_DESC *desc, const D3D11_SHADER_INPUT_BIND_DESC *expect)
 
static void test_reflection (void)
 
static void check_parameter_desc (const D3D11_SIGNATURE_PARAMETER_DESC *desc, const D3D11_SIGNATURE_PARAMETER_DESC *expect)
 
static void test_semantic_reflection (void)
 
 START_TEST (hlsl_d3d11)
 

Variables

static D3D_DRIVER_TYPE driver_type
 
static D3D_DRIVER_TYPE HMODULE swrast
 
static D3D_DRIVER_TYPE HMODULE UINT flags
 
static D3D_DRIVER_TYPE HMODULE UINT const D3D_FEATURE_LEVEL * feature_levels
 
static D3D_DRIVER_TYPE HMODULE UINT const D3D_FEATURE_LEVEL UINT levels
 
static D3D_DRIVER_TYPE HMODULE UINT const D3D_FEATURE_LEVEL UINT UINT sdk_version
 
static D3D_DRIVER_TYPE HMODULE UINT const D3D_FEATURE_LEVEL UINT UINT ID3D11Device ** device_out
 
static D3D_DRIVER_TYPE HMODULE UINT const D3D_FEATURE_LEVEL UINT UINT ID3D11Device D3D_FEATURE_LEVEL * obtained_feature_level
 
static D3D_DRIVER_TYPE HMODULE UINT const D3D_FEATURE_LEVEL UINT UINT ID3D11Device D3D_FEATURE_LEVEL ID3D11DeviceContext ** immediate_context
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 22 of file hlsl_d3d11.c.

◆ compile_shader

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

Definition at line 42 of file hlsl_d3d11.c.

◆ compile_shader_flags

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

Definition at line 43 of file hlsl_d3d11.c.

◆ create_buffer

#define create_buffer (   a,
  b,
  c,
  d 
)    create_buffer_(__LINE__, a, b, c, d)

Definition at line 244 of file hlsl_d3d11.c.

◆ draw_quad

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

Definition at line 263 of file hlsl_d3d11.c.

◆ init_test_context

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

Definition at line 166 of file hlsl_d3d11.c.

◆ release_test_context

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

Definition at line 222 of file hlsl_d3d11.c.

Function Documentation

◆ check_parameter_desc()

static void check_parameter_desc ( const D3D11_SIGNATURE_PARAMETER_DESC *  desc,
const D3D11_SIGNATURE_PARAMETER_DESC *  expect 
)
static

Definition at line 923 of file hlsl_d3d11.c.

925{
926 todo_wine_if(strcmp(desc->SemanticName, expect->SemanticName))
927 ok(!strcmp(desc->SemanticName, expect->SemanticName), "Got name %s.\n", debugstr_a(desc->SemanticName));
928 ok(desc->SemanticIndex == expect->SemanticIndex, "Got index %u.\n", desc->SemanticIndex);
929 ok(desc->Register == expect->Register, "Got register %u.\n", desc->Register);
930 todo_wine_if(desc->SystemValueType != expect->SystemValueType)
931 ok(desc->SystemValueType == expect->SystemValueType, "Got sysval %u.\n", desc->SystemValueType);
932 ok(desc->ComponentType == expect->ComponentType, "Got data type %u.\n", desc->ComponentType);
933 ok(desc->Mask == expect->Mask, "Got mask %#x.\n", desc->Mask);
934 todo_wine_if(desc->ReadWriteMask != expect->ReadWriteMask)
935 ok(desc->ReadWriteMask == expect->ReadWriteMask, "Got used mask %#x.\n", desc->ReadWriteMask);
936 ok(desc->Stream == expect->Stream, "Got stream %u.\n", desc->Stream);
937}
#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
unsigned int Mask
Definition: fpcontrol.c:82
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLdouble s
Definition: gl.h:2039
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLdouble n
Definition: glext.h:7729
GLuint index
Definition: glext.h:6031
GLenum GLint GLuint mask
Definition: glext.h:6028
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 * u
Definition: glfuncs.h:240
#define debugstr_a
Definition: kernel32.h:31
#define todo_wine_if(is_todo)
Definition: minitest.h:81
D3D11_SHADER_VARIABLE_DESC desc
Definition: reflection.c:1683
enum vkd3d_shader_sysval_semantic sysval
Definition: spirv.c:4839
Definition: name.c:39

Referenced by test_semantic_reflection().

◆ check_resource_binding()

static void check_resource_binding ( const D3D11_SHADER_INPUT_BIND_DESC *  desc,
const D3D11_SHADER_INPUT_BIND_DESC *  expect 
)
static

Definition at line 646 of file hlsl_d3d11.c.

648{
649 ok(!strcmp(desc->Name, expect->Name), "Got name %s.\n", debugstr_a(desc->Name));
650 ok(desc->Type == expect->Type, "Got type %#x.\n", desc->Type);
651 ok(desc->BindPoint == expect->BindPoint, "Got bind point %u.\n", desc->BindPoint);
652 ok(desc->BindCount == expect->BindCount, "Got bind count %u.\n", desc->BindCount);
653 ok(desc->uFlags == expect->uFlags, "Got flags %#x.\n", desc->uFlags);
654 ok(desc->ReturnType == expect->ReturnType, "Got return type %#x.\n", desc->ReturnType);
655 ok(desc->Dimension == expect->Dimension, "Got dimension %#x.\n", desc->Dimension);
656 ok(desc->NumSamples == expect->NumSamples, "Got multisample count %u.\n", desc->NumSamples);
657}

Referenced by test_reflection().

◆ check_type_desc()

static void check_type_desc ( const D3D11_SHADER_TYPE_DESC *  type,
const D3D11_SHADER_TYPE_DESC *  expect 
)
static

Definition at line 634 of file hlsl_d3d11.c.

635{
636 ok(type->Class == expect->Class, "Got class %#x.\n", type->Class);
637 ok(type->Type == expect->Type, "Got type %#x.\n", type->Type);
638 ok(type->Rows == expect->Rows, "Got %u rows.\n", type->Rows);
639 ok(type->Columns == expect->Columns, "Got %u columns.\n", type->Columns);
640 ok(type->Elements == expect->Elements, "Got %u elements.\n", type->Elements);
641 ok(type->Members == expect->Members, "Got %u members.\n", type->Members);
642 ok(type->Offset == expect->Offset, "Got %u members.\n", type->Members);
643 ok(!strcmp(type->Name, expect->Name), "Got name %s.\n", debugstr_a(type->Name));
644}

Referenced by test_reflection().

◆ compare_float()

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

Definition at line 67 of file hlsl_d3d11.c.

68{
69 int x = *(int *)&f;
70 int y = *(int *)&g;
71
72 if (x < 0)
73 x = INT_MIN - x;
74 if (y < 0)
75 y = INT_MIN - y;
76
77 return compare_uint(x, y, ulps);
78}
#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_d3d11.c:60
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 60 of file hlsl_d3d11.c.

61{
62 unsigned int diff = x > y ? x - y : y - x;
63
64 return diff <= max_diff;
65}

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 80 of file hlsl_d3d11.c.

81{
82 return compare_float(vec->x, x, ulps)
83 && compare_float(vec->y, y, ulps)
84 && compare_float(vec->z, z, ulps)
85 && compare_float(vec->w, w, ulps);
86}
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_conditionals(), test_math(), test_sampling(), test_swizzle(), and test_trig().

◆ compile_shader_()

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

Definition at line 44 of file hlsl_d3d11.c.

45{
46 ID3D10Blob *blob = NULL, *errors = NULL;
47 HRESULT hr;
48
49 hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main", target, flags, 0, &blob, &errors);
50 ok_(__FILE__, line)(hr == S_OK, "Failed to compile shader, hr %#lx.\n", hr);
51 if (errors)
52 {
53 if (winetest_debug > 1)
54 trace_(__FILE__, line)("%s\n", (char *)ID3D10Blob_GetBufferPointer(errors));
55 ID3D10Blob_Release(errors);
56 }
57 return blob;
58}
#define ok_(x1, x2)
Definition: atltest.h:61
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
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1597
GLbitfield flags
Definition: glext.h:7161
#define S_OK
Definition: intsafe.h:52
#define trace_(file, line,...)
Definition: kmt_test.h:230
int winetest_debug
Definition: image.c:229
Definition: parser.c:49
Definition: tools.h:99

Referenced by draw_quad_().

◆ create_buffer_()

static ID3D11Buffer * create_buffer_ ( unsigned int  line,
ID3D11Device *  device,
unsigned int  bind_flags,
unsigned int  size,
const void *  data 
)
static

Definition at line 245 of file hlsl_d3d11.c.

247{
248 D3D11_SUBRESOURCE_DATA resource_data = {.pSysMem = data};
249 D3D11_BUFFER_DESC buffer_desc =
250 {
251 .ByteWidth = size,
252 .Usage = D3D11_USAGE_DEFAULT,
253 .BindFlags = bind_flags,
254 };
255 ID3D11Buffer *buffer;
256 HRESULT hr;
257
258 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, data ? &resource_data : NULL, &buffer);
259 ok_(__FILE__, line)(hr == S_OK, "Failed to create buffer, hr %#lx.\n", hr);
260 return buffer;
261}
GLuint buffer
Definition: glext.h:5915
GLsizeiptr size
Definition: glext.h:5919
Definition: devices.h:37

Referenced by draw_quad_().

◆ create_device()

static ID3D11Device * create_device ( void  )
static

Definition at line 102 of file hlsl_d3d11.c.

103{
104 static const D3D_FEATURE_LEVEL feature_level[] =
105 {
109 };
110 ID3D11Device *device;
111
112 if (SUCCEEDED(pD3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0,
113 feature_level, ARRAY_SIZE(feature_level), D3D11_SDK_VERSION, &device, NULL, NULL)))
114 return device;
115 if (SUCCEEDED(pD3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, 0,
116 feature_level, ARRAY_SIZE(feature_level), D3D11_SDK_VERSION, &device, NULL, NULL)))
117 return device;
118 if (SUCCEEDED(pD3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, 0,
119 feature_level, ARRAY_SIZE(feature_level), D3D11_SDK_VERSION, &device, NULL, NULL)))
120 return device;
121
122 return NULL;
123}
#define ARRAY_SIZE(A)
Definition: main.h:20
D3D_FEATURE_LEVEL
Definition: d3dcommon.idl:102
@ D3D_FEATURE_LEVEL_10_0
Definition: d3dcommon.idl:107
@ D3D_FEATURE_LEVEL_10_1
Definition: d3dcommon.idl:108
@ D3D_FEATURE_LEVEL_11_0
Definition: d3dcommon.idl:109
@ D3D_DRIVER_TYPE_HARDWARE
Definition: d3dcommon.idl:94
@ D3D_DRIVER_TYPE_REFERENCE
Definition: d3dcommon.idl:95
@ D3D_DRIVER_TYPE_WARP
Definition: d3dcommon.idl:98
#define SUCCEEDED(hr)
Definition: intsafe.h:50

Referenced by create_device(), IDirectInput7AImpl_CreateDeviceEx(), IDirectInput7WImpl_CreateDeviceEx(), init_test_context(), init_test_context_(), START_TEST(), test_allocate_surface_helper(), test_changed3ddevice(), test_D3DXSHProjectCubeMap(), test_effect_clone(), test_effect_null_shader(), test_effect_unsupported_shader(), test_refcount(), and test_renderless_formats().

◆ create_swapchain()

static IDXGISwapChain * create_swapchain ( ID3D11Device *  device,
HWND  window 
)
static

Definition at line 125 of file hlsl_d3d11.c.

126{
127 DXGI_SWAP_CHAIN_DESC dxgi_desc;
128 IDXGISwapChain *swapchain;
129 IDXGIDevice *dxgi_device;
132 HRESULT hr;
133
134 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
135 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
136 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
137 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
138 IDXGIDevice_Release(dxgi_device);
139 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
140 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
141 IDXGIAdapter_Release(adapter);
142
143 dxgi_desc.BufferDesc.Width = 640;
144 dxgi_desc.BufferDesc.Height = 480;
145 dxgi_desc.BufferDesc.RefreshRate.Numerator = 60;
146 dxgi_desc.BufferDesc.RefreshRate.Denominator = 1;
150 dxgi_desc.SampleDesc.Count = 1;
151 dxgi_desc.SampleDesc.Quality = 0;
153 dxgi_desc.BufferCount = 1;
154 dxgi_desc.OutputWindow = window;
155 dxgi_desc.Windowed = TRUE;
157 dxgi_desc.Flags = 0;
158
159 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &dxgi_desc, &swapchain);
160 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
161 IDXGIFactory_Release(factory);
162
163 return swapchain;
164}
#define TRUE
Definition: types.h:120
@ DXGI_SWAP_EFFECT_DISCARD
Definition: dxgi.idl:65
const DXGI_USAGE DXGI_USAGE_RENDER_TARGET_OUTPUT
Definition: dxgi.idl:44
@ DXGI_FORMAT_R8G8B8A8_UNORM
Definition: dxgiformat.idl:51
@ DXGI_MODE_SCALING_UNSPECIFIED
Definition: dxgitype.idl:46
@ DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED
Definition: dxgitype.idl:38
return adapter
static IHTMLWindow2 * window
Definition: events.c:77
DXGI_FORMAT Format
Definition: dxgitype.idl:68
DXGI_MODE_SCANLINE_ORDER ScanlineOrdering
Definition: dxgitype.idl:69
DXGI_MODE_SCALING Scaling
Definition: dxgitype.idl:70
DXGI_RATIONAL RefreshRate
Definition: dxgitype.idl:67
DXGI_SWAP_EFFECT SwapEffect
Definition: dxgi.idl:141
DXGI_SAMPLE_DESC SampleDesc
Definition: dxgi.idl:136
DXGI_MODE_DESC BufferDesc
Definition: dxgi.idl:135
DXGI_USAGE BufferUsage
Definition: dxgi.idl:137
Definition: main.c:439

Referenced by init_test_context_().

◆ draw_quad_()

static void draw_quad_ ( unsigned int  line,
struct test_context *  context,
ID3D10Blob *  ps_code 
)
static

Definition at line 264 of file hlsl_d3d11.c.

265{
266 static const D3D11_INPUT_ELEMENT_DESC default_layout_desc[] =
267 {
268 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
269 };
270
271 static const char vs_source[] =
272 "float4 main(float4 position : POSITION) : SV_POSITION\n"
273 "{\n"
274 " return position;\n"
275 "}";
276
277 static const struct vec2 quad[] =
278 {
279 {-1.0f, -1.0f},
280 {-1.0f, 1.0f},
281 { 1.0f, -1.0f},
282 { 1.0f, 1.0f},
283 };
284
285 ID3D11Device *device = context->device;
286 unsigned int stride, offset;
287 ID3D11PixelShader *ps;
288 HRESULT hr;
289
290 if (!context->vs)
291 {
292 ID3D10Blob *vs_code = compile_shader_(line, vs_source, "vs_4_0", 0);
293
294 hr = ID3D11Device_CreateInputLayout(device, default_layout_desc, ARRAY_SIZE(default_layout_desc),
295 ID3D10Blob_GetBufferPointer(vs_code), ID3D10Blob_GetBufferSize(vs_code), &context->input_layout);
296 ok_(__FILE__, line)(hr == S_OK, "Failed to create input layout, hr %#lx.\n", hr);
297
298 hr = ID3D11Device_CreateVertexShader(device, ID3D10Blob_GetBufferPointer(vs_code),
299 ID3D10Blob_GetBufferSize(vs_code), NULL, &context->vs);
300 ok_(__FILE__, line)(hr == S_OK, "Failed to create vertex shader, hr %#lx.\n", hr);
301 }
302
303 if (!context->vb)
304 context->vb = create_buffer_(line, device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
305
306 hr = ID3D11Device_CreatePixelShader(device, ID3D10Blob_GetBufferPointer(ps_code),
307 ID3D10Blob_GetBufferSize(ps_code), NULL, &ps);
308 ok_(__FILE__, line)(hr == S_OK, "Failed to create pixel shader, hr %#lx.\n", hr);
309
310 ID3D11DeviceContext_IASetInputLayout(context->immediate_context, context->input_layout);
311 ID3D11DeviceContext_IASetPrimitiveTopology(context->immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
312 stride = sizeof(*quad);
313 offset = 0;
314 ID3D11DeviceContext_IASetVertexBuffers(context->immediate_context, 0, 1, &context->vb, &stride, &offset);
315 ID3D11DeviceContext_VSSetShader(context->immediate_context, context->vs, NULL, 0);
316 ID3D11DeviceContext_PSSetShader(context->immediate_context, ps, NULL, 0);
317
318 ID3D11DeviceContext_Draw(context->immediate_context, 4, 0);
319
320 ID3D11PixelShader_Release(ps);
321}
@ D3D11_INPUT_PER_VERTEX_DATA
Definition: d3d11.idl:953
@ D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP
Definition: d3dcommon.idl:442
@ DXGI_FORMAT_R32G32_FLOAT
Definition: dxgiformat.idl:39
GLsizei stride
Definition: glext.h:5848
GLintptr offset
Definition: glext.h:5920
static ID3D11Buffer * create_buffer_(unsigned int line, ID3D11Device *device, unsigned int bind_flags, unsigned int size, const void *data)
Definition: hlsl_d3d11.c:245
static ID3D10Blob * compile_shader_(unsigned int line, const char *source, const char *target, UINT flags)
Definition: hlsl_d3d11.c:44
static void quad(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3, GLuint pv)
Definition: quads.c:63
Definition: http.c:7252

◆ get_color_vec4()

static struct vec4 get_color_vec4 ( struct test_context *  context,
unsigned int  x,
unsigned int  y 
)
static

Definition at line 358 of file hlsl_d3d11.c.

359{
360 struct readback rb;
361 struct vec4 ret;
362
364 ret = *get_readback_vec4(&rb, x, y);
366 return ret;
367}
return ret
Definition: mutex.c:147
static const struct vec4 * get_readback_vec4(struct readback *rb, unsigned int x, unsigned int y)
Definition: hlsl_d3d11.c:353
static void release_readback(struct test_context *context, struct readback *rb)
Definition: hlsl_d3d11.c:347
static void init_readback(struct test_context *context, struct readback *rb)
Definition: hlsl_d3d11.c:329

Referenced by test_math(), test_sampling(), and test_swizzle().

◆ get_readback_vec4()

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

Definition at line 353 of file hlsl_d3d11.c.

354{
355 return (struct vec4 *)((BYTE *)rb->map_desc.pData + y * rb->map_desc.RowPitch) + x;
356}
D3D11_MAPPED_SUBRESOURCE map_desc
Definition: hlsl_d3d11.c:326
unsigned char BYTE
Definition: xxhash.c:193

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

◆ HRESULT()

static HRESULT ( WINAPI *  pD3D11CreateDevice)
static

◆ init_readback()

static void init_readback ( struct test_context *  context,
struct readback *  rb 
)
static

Definition at line 329 of file hlsl_d3d11.c.

330{
331 D3D11_TEXTURE2D_DESC texture_desc;
332 HRESULT hr;
333
334 ID3D11Texture2D_GetDesc(context->rt, &texture_desc);
335 texture_desc.Usage = D3D11_USAGE_STAGING;
336 texture_desc.BindFlags = 0;
337 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
338 texture_desc.MiscFlags = 0;
339 hr = ID3D11Device_CreateTexture2D(context->device, &texture_desc, NULL, (ID3D11Texture2D **)&rb->resource);
340 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
341
342 ID3D11DeviceContext_CopyResource(context->immediate_context, rb->resource, (ID3D11Resource *)context->rt);
343 hr = ID3D11DeviceContext_Map(context->immediate_context, rb->resource, 0, D3D11_MAP_READ, 0, &rb->map_desc);
344 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
345}
@ D3D11_MAP_READ
Definition: d3d11.idl:972
ID3D11Resource * resource
Definition: hlsl_d3d11.c:325

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 167 of file hlsl_d3d11.c.

168{
169 const D3D11_TEXTURE2D_DESC texture_desc =
170 {
171 .Width = 640,
172 .Height = 480,
173 .MipLevels = 1,
174 .ArraySize = 1,
176 .SampleDesc.Count = 1,
177 .Usage = D3D11_USAGE_DEFAULT,
178 .BindFlags = D3D11_BIND_RENDER_TARGET,
179 };
180 unsigned int rt_width, rt_height;
181 D3D11_VIEWPORT vp;
182 HRESULT hr;
183 RECT rect;
184
185 memset(context, 0, sizeof(*context));
186
187 if (!(context->device = create_device()))
188 {
189 skip_(__FILE__, line)("Failed to create device.\n");
190 return FALSE;
191 }
192
193 rt_width = 640;
194 rt_height = 480;
195 SetRect(&rect, 0, 0, rt_width, rt_height);
197 context->window = CreateWindowA("static", "d3dcompiler_test", WS_OVERLAPPEDWINDOW,
199 context->swapchain = create_swapchain(context->device, context->window);
200
201 hr = ID3D11Device_CreateTexture2D(context->device, &texture_desc, NULL, &context->rt);
202 ok_(__FILE__, line)(hr == S_OK, "Failed to create texture, hr %#lx.\n", hr);
203
204 hr = ID3D11Device_CreateRenderTargetView(context->device, (ID3D11Resource *)context->rt, NULL, &context->rtv);
205 ok_(__FILE__, line)(hr == S_OK, "Failed to create rendertarget view, hr %#lx.\n", hr);
206
207 ID3D11Device_GetImmediateContext(context->device, &context->immediate_context);
208
209 ID3D11DeviceContext_OMSetRenderTargets(context->immediate_context, 1, &context->rtv, NULL);
210
211 vp.TopLeftX = 0.0f;
212 vp.TopLeftY = 0.0f;
213 vp.Width = rt_width;
214 vp.Height = rt_height;
215 vp.MinDepth = 0.0f;
216 vp.MaxDepth = 1.0f;
217 ID3D11DeviceContext_RSSetViewports(context->immediate_context, 1, &vp);
218
219 return TRUE;
220}
RECT rect
Definition: combotst.c:67
#define FALSE
Definition: types.h:117
@ DXGI_FORMAT_R32G32B32A32_FLOAT
Definition: dxgiformat.idl:25
static ID3D11Device * create_device(void)
Definition: hlsl_d3d11.c:102
static IDXGISwapChain * create_swapchain(ID3D11Device *device, HWND window)
Definition: hlsl_d3d11.c:125
#define skip_(test, file, line,...)
Definition: kmt_test.h:231
#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 SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)
#define memset(x, y, z)
Definition: compat.h:39
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

◆ release_readback()

static void release_readback ( struct test_context *  context,
struct readback *  rb 
)
static

Definition at line 347 of file hlsl_d3d11.c.

348{
349 ID3D11DeviceContext_Unmap(context->immediate_context, rb->resource, 0);
350 ID3D11Resource_Release(rb->resource);
351}

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 223 of file hlsl_d3d11.c.

224{
225 ULONG ref;
226
227 if (context->input_layout)
228 ID3D11InputLayout_Release(context->input_layout);
229 if (context->vs)
230 ID3D11VertexShader_Release(context->vs);
231 if (context->vb)
232 ID3D11Buffer_Release(context->vb);
233
234 ID3D11DeviceContext_Release(context->immediate_context);
235 ID3D11RenderTargetView_Release(context->rtv);
236 ID3D11Texture2D_Release(context->rt);
237 IDXGISwapChain_Release(context->swapchain);
238 DestroyWindow(context->window);
239
240 ref = ID3D11Device_Release(context->device);
241 ok_(__FILE__, line)(!ref, "Device has %lu references left.\n", ref);
242}
BOOL WINAPI DestroyWindow(_In_ HWND)
Definition: send.c:48
uint32_t ULONG
Definition: typedefs.h:59

◆ START_TEST()

START_TEST ( hlsl_d3d11  )

Definition at line 1165 of file hlsl_d3d11.c.

1166{
1167 HMODULE mod;
1168
1171
1172 if (!(mod = LoadLibraryA("d3d11.dll")))
1173 {
1174 skip("Direct3D 11 is not available.\n");
1175 return;
1176 }
1177 pD3D11CreateDevice = (void *)GetProcAddress(mod, "D3D11CreateDevice");
1178
1179 test_swizzle();
1180 test_math();
1182 test_trig();
1183 test_sampling();
1184}
std::map< E_MODULE, HMODULE > mod
Definition: LocaleTests.cpp:68
#define skip(...)
Definition: atltest.h:64
#define GetProcAddress(x, y)
Definition: compat.h:753
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
static void test_swizzle(void)
Definition: hlsl_d3d11.c:369
static void test_trig(void)
Definition: hlsl_d3d11.c:482
static void test_semantic_reflection(void)
Definition: hlsl_d3d11.c:939
static void test_sampling(void)
Definition: hlsl_d3d11.c:516
static void test_reflection(void)
Definition: hlsl_d3d11.c:659
static void test_math(void)
Definition: hlsl_d3d11.c:404
static void test_conditionals(void)
Definition: hlsl_d3d11.c:439

◆ test_conditionals()

static void test_conditionals ( void  )
static

Definition at line 439 of file hlsl_d3d11.c.

440{
442 ID3D10Blob *ps_code = NULL;
443 const struct vec4 *v;
444 struct readback rb;
445 unsigned int i;
446
447 static const char ps_source[] =
448 "float4 main(float4 pos : SV_POSITION) : SV_TARGET\n"
449 "{\n"
450 " if(pos.x > 200.0)\n"
451 " return float4(0.1, 0.2, 0.3, 0.4);\n"
452 " else\n"
453 " return float4(0.9, 0.8, 0.7, 0.6);\n"
454 "}";
455
457 return;
458
459 ps_code = compile_shader(ps_source, "ps_4_0");
460 draw_quad(&test_context, ps_code);
462
463 for (i = 0; i < 200; i += 40)
464 {
465 v = get_readback_vec4(&rb, i, 0);
466 ok(compare_vec4(v, 0.9f, 0.8f, 0.7f, 0.6f, 0),
467 "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v->x, v->y, v->z, v->w);
468 }
469
470 for (i = 240; i < 640; i += 40)
471 {
472 v = get_readback_vec4(&rb, i, 0);
473 ok(compare_vec4(v, 0.1f, 0.2f, 0.3f, 0.4f, 0),
474 "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v->x, v->y, v->z, v->w);
475 }
476
478 ID3D10Blob_Release(ps_code);
480}
const GLdouble * v
Definition: gl.h:2040
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
#define release_test_context(context)
Definition: hlsl_d3d11.c:222
#define init_test_context(a)
Definition: hlsl_d3d11.c:166
static BOOL compare_vec4(const struct vec4 *vec, float x, float y, float z, float w, unsigned int ulps)
Definition: hlsl_d3d11.c:80
#define compile_shader(a, b)
Definition: hlsl_d3d11.c:42
#define draw_quad(context, ps_code)
Definition: hlsl_d3d11.c:263

Referenced by START_TEST().

◆ test_math()

static void test_math ( void  )
static

Definition at line 404 of file hlsl_d3d11.c.

405{
406 static const float uniforms[8] = {2.5f, 0.3f, 0.2f, 0.7f, 0.1f, 1.5f};
408 ID3D10Blob *ps_code = NULL;
409 ID3D11Buffer *cb;
410 struct vec4 v;
411
412 static const char ps_source[] =
413 "float4 main(uniform float u, uniform float v, uniform float w, uniform float x,\n"
414 " uniform float y, uniform float z) : SV_TARGET\n"
415 "{\n"
416 " return float4(x * y - z / w + --u / -v,\n"
417 " z * x / y + w / -v,\n"
418 " u + v - w,\n"
419 " x / y / w);\n"
420 "}";
421
423 return;
424
425 ps_code = compile_shader(ps_source, "ps_4_0");
426 cb = create_buffer(test_context.device, D3D11_BIND_CONSTANT_BUFFER, sizeof(uniforms), uniforms);
427 ID3D11DeviceContext_PSSetConstantBuffers(test_context.immediate_context, 0, 1, &cb);
428 draw_quad(&test_context, ps_code);
429
430 v = get_color_vec4(&test_context, 0, 0);
431 ok(compare_vec4(&v, -12.43f, 9.833333f, 1.6f, 35.0f, 1),
432 "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
433
434 ID3D11Buffer_Release(cb);
435 ID3D10Blob_Release(ps_code);
437}
static MonoProfilerRuntimeShutdownBeginCallback cb
Definition: metahost.c:118
static struct vec4 get_color_vec4(struct test_context *context, unsigned int x, unsigned int y)
Definition: hlsl_d3d11.c:358
#define create_buffer(a, b, c, d)
Definition: hlsl_d3d11.c:244
ID3D11Device * device
Definition: hlsl_d3d11.c:90
ID3D11DeviceContext * immediate_context
Definition: hlsl_d3d11.c:95

Referenced by START_TEST().

◆ test_reflection()

static void test_reflection ( void  )
static

Definition at line 659 of file hlsl_d3d11.c.

660{
663 D3D11_SHADER_BUFFER_DESC buffer_desc;
666 ID3D11ShaderReflection *reflection;
667 D3D11_SHADER_TYPE_DESC type_desc;
668 D3D11_SHADER_DESC shader_desc;
670 unsigned int i, j, k;
671 ULONG refcount;
672 HRESULT hr;
673
674 static const char vs_source[] =
675 "typedef uint uint_t;\n"
676 "float m;\n"
677 "\n"
678 "cbuffer b1\n"
679 "{\n"
680 " float a;\n"
681 " float2 b;\n"
682 " float4 c;\n"
683 " float d;\n"
684 " struct\n"
685 " {\n"
686 " float4 a;\n"
687 " float b;\n"
688 " float c;\n"
689 " } s;\n"
690 /* In direct contradiction to the documentation, this does not align. */
691 " bool g;\n"
692 " float h[2];\n"
693 " int i;\n"
694 " uint_t j;\n"
695 " float3x1 k;\n"
696 " row_major float3x1 l;\n"
697 "#pragma pack_matrix(row_major)\n"
698 " float3x1 o;\n"
699 " float4 p;\n"
700 " float q;\n"
701 " struct r_name {float a;} r;\n"
702 " column_major float3x1 t;\n"
703 "};\n"
704 "\n"
705 "cbuffer b5 : register(b5)\n"
706 "{\n"
707 " float4 u;\n"
708 "}\n"
709 "\n"
710 "float4 main(uniform float4 n) : SV_POSITION\n"
711 "{\n"
712 " return o._31 + m + n + u;\n"
713 "}";
714
715 struct shader_variable
716 {
718 D3D11_SHADER_TYPE_DESC type_desc;
719 const D3D11_SHADER_TYPE_DESC *field_types;
720 };
721
722 static const D3D11_SHADER_TYPE_DESC s_field_types[] =
723 {
724 {D3D_SVC_VECTOR, D3D_SVT_FLOAT, 1, 4, 0, 0, 0, "float4"},
725 {D3D_SVC_SCALAR, D3D_SVT_FLOAT, 1, 1, 0, 0, 16, "float"},
726 {D3D_SVC_SCALAR, D3D_SVT_FLOAT, 1, 1, 0, 0, 20, "float"},
727 };
728
729 static const D3D11_SHADER_TYPE_DESC r_field_types[] =
730 {
731 {D3D_SVC_SCALAR, D3D_SVT_FLOAT, 1, 1, 0, 0, 0, "float"},
732 };
733
734 static const struct shader_variable globals_vars =
735 {{"m", 0, 4, D3D_SVF_USED}, {D3D_SVC_SCALAR, D3D_SVT_FLOAT, 1, 1, 0, 0, 0, "float"}};
736 static const struct shader_variable params_vars =
737 {{"n", 0, 16, D3D_SVF_USED}, {D3D_SVC_VECTOR, D3D_SVT_FLOAT, 1, 4, 0, 0, 0, "float4"}};
738 static const struct shader_variable buffer_vars[] =
739 {
740 {{"a", 0, 4}, {D3D_SVC_SCALAR, D3D_SVT_FLOAT, 1, 1, 0, 0, 0, "float"}},
741 {{"b", 4, 8}, {D3D_SVC_VECTOR, D3D_SVT_FLOAT, 1, 2, 0, 0, 0, "float2"}},
742 {{"c", 16, 16}, {D3D_SVC_VECTOR, D3D_SVT_FLOAT, 1, 4, 0, 0, 0, "float4"}},
743 {{"d", 32, 4}, {D3D_SVC_SCALAR, D3D_SVT_FLOAT, 1, 1, 0, 0, 0, "float"}},
744 {{"s", 48, 24}, {D3D_SVC_STRUCT, D3D_SVT_VOID, 1, 6, 0, ARRAY_SIZE(s_field_types), 0, "<unnamed>"}, s_field_types},
745 {{"g", 72, 4}, {D3D_SVC_SCALAR, D3D_SVT_BOOL, 1, 1, 0, 0, 0, "bool"}},
746 {{"h", 80, 20}, {D3D_SVC_SCALAR, D3D_SVT_FLOAT, 1, 1, 2, 0, 0, "float"}},
747 {{"i", 100, 4}, {D3D_SVC_SCALAR, D3D_SVT_INT, 1, 1, 0, 0, 0, "int"}},
748 {{"j", 104, 4}, {D3D_SVC_SCALAR, D3D_SVT_UINT, 1, 1, 0, 0, 0, "uint_t"}},
749 {{"k", 112, 12}, {D3D_SVC_MATRIX_COLUMNS, D3D_SVT_FLOAT, 3, 1, 0, 0, 0, "float3x1"}},
750 {{"l", 128, 36}, {D3D_SVC_MATRIX_ROWS, D3D_SVT_FLOAT, 3, 1, 0, 0, 0, "float3x1"}},
751 {{"o", 176, 36, D3D_SVF_USED}, {D3D_SVC_MATRIX_ROWS, D3D_SVT_FLOAT, 3, 1, 0, 0, 0, "float3x1"}},
752 {{"p", 224, 16}, {D3D_SVC_VECTOR, D3D_SVT_FLOAT, 1, 4, 0, 0, 0, "float4"}},
753 {{"q", 240, 4}, {D3D_SVC_SCALAR, D3D_SVT_FLOAT, 1, 1, 0, 0, 0, "float"}},
754 {{"r", 256, 4}, {D3D_SVC_STRUCT, D3D_SVT_VOID, 1, 1, 0, ARRAY_SIZE(r_field_types), 0, "r_name"}, r_field_types},
755 {{"t", 260, 12}, {D3D_SVC_MATRIX_COLUMNS, D3D_SVT_FLOAT, 3, 1, 0, 0, 0, "float3x1"}},
756 };
757 static const struct shader_variable b5_vars =
758 {{"u", 0, 16, D3D_SVF_USED}, {D3D_SVC_VECTOR, D3D_SVT_FLOAT, 1, 4, 0, 0, 0, "float4"}};
759
760 static const struct
761 {
763 const struct shader_variable *vars;
764 }
765 vs_buffers[] =
766 {
767 {{"$Globals", D3D_CT_CBUFFER, 1, 16}, &globals_vars},
768 {{"$Params", D3D_CT_CBUFFER, 1, 16}, &params_vars},
769 {{"b1", D3D_CT_CBUFFER, ARRAY_SIZE(buffer_vars), 272}, buffer_vars},
770 {{"b5", D3D_CT_CBUFFER, 1, 16}, &b5_vars},
771 };
772
773 static const D3D11_SHADER_INPUT_BIND_DESC vs_bindings[] =
774 {
775 {"$Globals", D3D_SIT_CBUFFER, 0, 1},
776 {"$Params", D3D_SIT_CBUFFER, 1, 1},
777 {"b1", D3D_SIT_CBUFFER, 2, 1},
778 {"b5", D3D_SIT_CBUFFER, 5, 1, D3D_SIF_USERPACKED},
779 };
780
781 static const char ps_source[] =
782 "texture2D a;\n"
783 "sampler c {};\n"
784 "SamplerState d {};\n"
785 "sampler e\n"
786 "{\n"
787 " Texture = a;\n"
788 " foo = bar + 2;\n"
789 "};\n"
790 "SamplerState f\n"
791 "{\n"
792 " Texture = a;\n"
793 " foo = bar + 2;\n"
794 "};\n"
795 "sampler2D g;\n"
796 "sampler b : register(s5);\n"
797 "float4 main(float2 pos : texcoord) : SV_TARGET\n"
798 "{\n"
799 " return a.Sample(b, pos) + a.Sample(c, pos) + a.Sample(d, pos) + tex2D(f, pos) + tex2D(e, pos)"
800 " + tex2D(g, pos);\n"
801 "}";
802
803 static const D3D11_SHADER_INPUT_BIND_DESC ps_bindings[] =
804 {
805 {"c", D3D_SIT_SAMPLER, 0, 1},
806 {"d", D3D_SIT_SAMPLER, 1, 1},
807 {"e", D3D_SIT_SAMPLER, 2, 1},
808 {"f", D3D_SIT_SAMPLER, 3, 1},
809 {"g", D3D_SIT_SAMPLER, 4, 1},
815 };
816
817 code = compile_shader(vs_source, "vs_5_0");
818 hr = D3DReflect(ID3D10Blob_GetBufferPointer(code), ID3D10Blob_GetBufferSize(code),
819 &IID_ID3D11ShaderReflection, (void **)&reflection);
820 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
821
822 hr = reflection->lpVtbl->GetDesc(reflection, &shader_desc);
823 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
824 ok(shader_desc.ConstantBuffers == ARRAY_SIZE(vs_buffers), "Got %u buffers.\n", shader_desc.ConstantBuffers);
825 ok(shader_desc.BoundResources == ARRAY_SIZE(vs_bindings), "Got %u resources.\n", shader_desc.BoundResources);
826
827 for (i = 0; i < ARRAY_SIZE(vs_buffers); ++i)
828 {
829 winetest_push_context("Buffer %u", i);
830
831 cbuffer = reflection->lpVtbl->GetConstantBufferByIndex(reflection, i);
832 hr = cbuffer->lpVtbl->GetDesc(cbuffer, &buffer_desc);
833 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
834 ok(!strcmp(buffer_desc.Name, vs_buffers[i].desc.Name), "Got name %s.\n", debugstr_a(buffer_desc.Name));
835 ok(buffer_desc.Type == vs_buffers[i].desc.Type, "Got type %#x.\n", buffer_desc.Type);
836 ok(buffer_desc.Variables == vs_buffers[i].desc.Variables, "Got %u variables.\n", buffer_desc.Variables);
837 ok(buffer_desc.Size == vs_buffers[i].desc.Size, "Got size %u.\n", buffer_desc.Size);
838 ok(buffer_desc.uFlags == vs_buffers[i].desc.uFlags, "Got flags %#x.\n", buffer_desc.uFlags);
839
840 for (j = 0; j < buffer_desc.Variables; ++j)
841 {
842 const struct shader_variable *expect = &vs_buffers[i].vars[j];
843
844 winetest_push_context("Variable %u", j);
845
846 var = cbuffer->lpVtbl->GetVariableByIndex(cbuffer, j);
847 hr = var->lpVtbl->GetDesc(var, &var_desc);
848 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
849 ok(!strcmp(var_desc.Name, expect->var_desc.Name), "Got name %s.\n", debugstr_a(var_desc.Name));
850 ok(var_desc.StartOffset == expect->var_desc.StartOffset, "Got offset %u.\n", var_desc.StartOffset);
851 ok(var_desc.Size == expect->var_desc.Size, "Got size %u.\n", var_desc.Size);
852 ok(var_desc.uFlags == expect->var_desc.uFlags, "Got flags %#x.\n", var_desc.uFlags);
853 ok(!var_desc.DefaultValue, "Got default value %p.\n", var_desc.DefaultValue);
854
855 type = var->lpVtbl->GetType(var);
856 hr = type->lpVtbl->GetDesc(type, &type_desc);
857 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
858 check_type_desc(&type_desc, &expect->type_desc);
859
860 for (k = 0; k < type_desc.Members; ++k)
861 {
862 winetest_push_context("Field %u", k);
863
864 field = type->lpVtbl->GetMemberTypeByIndex(type, k);
865 hr = field->lpVtbl->GetDesc(field, &type_desc);
866 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
867 check_type_desc(&type_desc, &vs_buffers[i].vars[j].field_types[k]);
868
870 }
871
873 }
874
876 }
877
878 for (i = 0; i < ARRAY_SIZE(vs_bindings); ++i)
879 {
881
882 winetest_push_context("Binding %u", i);
883
884 hr = reflection->lpVtbl->GetResourceBindingDesc(reflection, i, &desc);
885 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
886 check_resource_binding(&desc, &vs_bindings[i]);
887
889 }
890
891 ID3D10Blob_Release(code);
892 refcount = reflection->lpVtbl->Release(reflection);
893 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
894
896 hr = D3DReflect(ID3D10Blob_GetBufferPointer(code), ID3D10Blob_GetBufferSize(code),
897 &IID_ID3D11ShaderReflection, (void **)&reflection);
898 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
899
900 hr = reflection->lpVtbl->GetDesc(reflection, &shader_desc);
901 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
902 ok(!shader_desc.ConstantBuffers, "Got %u buffers.\n", shader_desc.ConstantBuffers);
903 ok(shader_desc.BoundResources == ARRAY_SIZE(ps_bindings), "Got %u resources.\n", shader_desc.BoundResources);
904
905 for (i = 0; i < shader_desc.BoundResources; ++i)
906 {
908
909 winetest_push_context("Binding %u", i);
910
911 hr = reflection->lpVtbl->GetResourceBindingDesc(reflection, i, &desc);
912 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
913 check_resource_binding(&desc, &ps_bindings[i]);
914
916 }
917
918 ID3D10Blob_Release(code);
919 refcount = reflection->lpVtbl->Release(reflection);
920 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
921}
@ D3D_SIF_TEXTURE_COMPONENTS
Definition: d3dcommon.idl:287
@ D3D_SIF_USERPACKED
Definition: d3dcommon.idl:283
@ D3D_SVC_VECTOR
Definition: d3dcommon.idl:135
@ D3D_SVC_MATRIX_COLUMNS
Definition: d3dcommon.idl:137
@ D3D_SVC_SCALAR
Definition: d3dcommon.idl:134
@ D3D_SVC_STRUCT
Definition: d3dcommon.idl:139
@ D3D_SVC_MATRIX_ROWS
Definition: d3dcommon.idl:136
@ D3D_SVT_INT
Definition: d3dcommon.idl:170
@ D3D_SVT_UINT
Definition: d3dcommon.idl:187
@ D3D_SVT_VOID
Definition: d3dcommon.idl:168
@ D3D_SVT_FLOAT
Definition: d3dcommon.idl:171
@ D3D_SVT_BOOL
Definition: d3dcommon.idl:169
@ D3D_SRV_DIMENSION_TEXTURE2D
Definition: d3dcommon.idl:553
@ D3D_RETURN_TYPE_FLOAT
Definition: d3dcommon.idl:614
@ D3D_SIT_SAMPLER
Definition: d3dcommon.idl:697
@ D3D_SIT_TEXTURE
Definition: d3dcommon.idl:696
@ D3D_SIT_CBUFFER
Definition: d3dcommon.idl:694
@ D3D_CT_CBUFFER
Definition: d3dcommon.idl:535
@ D3D_SVF_USED
Definition: d3dcommon.idl:156
#define D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY
Definition: d3dcompiler.h:54
HRESULT WINAPI D3DReflect(const void *data, SIZE_T data_size, REFIID riid, void **reflector)
#define ID3D11ShaderReflectionType
Definition: reflection.c:30
#define ID3D11ShaderReflectionConstantBuffer
Definition: reflection.c:28
#define ID3D11ShaderReflection
Definition: reflection.c:26
#define ID3D11ShaderReflectionVariable
Definition: reflection.c:32
#define IID_ID3D11ShaderReflection
Definition: reflection.c:34
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
#define compile_shader_flags(a, b, c)
Definition: hlsl_d3d11.c:43
static void check_resource_binding(const D3D11_SHADER_INPUT_BIND_DESC *desc, const D3D11_SHADER_INPUT_BIND_DESC *expect)
Definition: hlsl_d3d11.c:646
static void check_type_desc(const D3D11_SHADER_TYPE_DESC *type, const D3D11_SHADER_TYPE_DESC *expect)
Definition: hlsl_d3d11.c:634
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
const char * var
Definition: shader.c:5879
int k
Definition: mpi.c:3369
D3D_CBUFFER_TYPE Type
Definition: d3d11shader.h:120
Definition: inflate.c:139
Definition: parser.c:44

Referenced by START_TEST().

◆ test_sampling()

static void test_sampling ( void  )
static

Definition at line 516 of file hlsl_d3d11.c.

517{
518 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc = {0};
520 ID3D11ShaderResourceView *srv;
521 ID3D11SamplerState *sampler;
522 ID3D10Blob *ps_code = NULL;
523 ID3D11Texture2D *texture;
524 unsigned int i;
525 struct vec4 v;
526 HRESULT hr;
527
528 static const char *tests[] =
529 {
530 "sampler s;\n"
531 "float4 main() : COLOR\n"
532 "{\n"
533 " return tex2D(s, float2(0.5, 0.5));\n"
534 "}",
535
536 "SamplerState s;\n"
537 "float4 main() : COLOR\n"
538 "{\n"
539 " return tex2D(s, float2(0.5, 0.5));\n"
540 "}",
541
542 "sampler2D s;\n"
543 "float4 main() : COLOR\n"
544 "{\n"
545 " return tex2D(s, float2(0.5, 0.5));\n"
546 "}",
547
548 "sampler s;\n"
549 "Texture2D t;\n"
550 "float4 main() : COLOR\n"
551 "{\n"
552 " return t.Sample(s, float2(0.5, 0.5));\n"
553 "}",
554
555 "SamplerState s;\n"
556 "Texture2D t;\n"
557 "float4 main() : COLOR\n"
558 "{\n"
559 " return t.Sample(s, float2(0.5, 0.5));\n"
560 "}",
561 };
562
563 static const D3D11_TEXTURE2D_DESC texture_desc =
564 {
565 .Width = 2,
566 .Height = 2,
567 .MipLevels = 1,
568 .ArraySize = 1,
570 .SampleDesc.Count = 1,
571 .Usage = D3D11_USAGE_DEFAULT,
572 .BindFlags = D3D11_BIND_SHADER_RESOURCE,
573 };
574
575 static const float texture_data[] =
576 {
577 0.0f, 0.0f, 0.0f, 0.0f,
578 0.0f, 0.0f, 0.0f, 0.0f,
579 0.0f, 0.0f, 0.0f, 0.0f,
580 1.0f, 0.0f, 1.0f, 0.0f,
581 };
582
583 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 2};
584
585 static const D3D11_SAMPLER_DESC sampler_desc =
586 {
588 .AddressU = D3D11_TEXTURE_ADDRESS_WRAP,
589 .AddressV = D3D11_TEXTURE_ADDRESS_WRAP,
590 .AddressW = D3D11_TEXTURE_ADDRESS_WRAP,
591 };
592
593 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
594
596 return;
597
598 hr = ID3D11Device_CreateTexture2D(test_context.device, &texture_desc, &resource_data, &texture);
599 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
600 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
601 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
602 srv_desc.Texture2D.MipLevels = 1;
603 hr = ID3D11Device_CreateShaderResourceView(test_context.device, (ID3D11Resource *)texture, &srv_desc, &srv);
604 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
605 ID3D11DeviceContext_PSSetShaderResources(test_context.immediate_context, 0, 1, &srv);
606
607 hr = ID3D11Device_CreateSamplerState(test_context.device, &sampler_desc, &sampler);
608 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
609 ID3D11DeviceContext_PSSetSamplers(test_context.immediate_context, 0, 1, &sampler);
610
611 for (i = 0; i < ARRAY_SIZE(tests); ++i)
612 {
613 winetest_push_context("Test %u", i);
614
615 ID3D11DeviceContext_ClearRenderTargetView(test_context.immediate_context, test_context.rtv, red);
617 draw_quad(&test_context, ps_code);
618
619 v = get_color_vec4(&test_context, 0, 0);
620 ok(compare_vec4(&v, 0.25f, 0.0f, 0.25f, 0.0f, 0),
621 "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
622
623 ID3D10Blob_Release(ps_code);
624
626 }
627
628 ID3D11Texture2D_Release(texture);
629 ID3D11SamplerState_Release(sampler);
630 ID3D11ShaderResourceView_Release(srv);
632}
@ D3D11_FILTER_MIN_MAG_MIP_LINEAR
Definition: d3d11.idl:902
@ D3D11_SRV_DIMENSION_TEXTURE2D
Definition: d3dcommon.idl:586
GLenum GLuint texture
Definition: glext.h:6295
GLuint sampler
Definition: glext.h:7283
#define red
Definition: linetest.c:67
static struct test_info tests[]
ID3D11RenderTargetView * rtv
Definition: hlsl_d3d11.c:94

Referenced by START_TEST().

◆ test_semantic_reflection()

static void test_semantic_reflection ( void  )
static

Definition at line 939 of file hlsl_d3d11.c.

940{
942 ID3D11ShaderReflection *reflection;
943 D3D11_SHADER_DESC shader_desc;
945 unsigned int i, j;
946 ULONG refcount;
947 HRESULT hr;
948
949 static const char vs1_source[] =
950 "void main(\n"
951 " in float4 a : apple,\n"
952 " out float4 b : banana2,\n"
953 " inout float4 c : color,\n"
954 " inout float4 d : depth,\n"
955 " inout float4 e : sv_position,\n"
956 " in uint3 f : fruit,\n"
957 " inout bool2 g : grape,\n"
958 " in int h : honeydew)\n"
959 "{\n"
960 " b.yw = a.xz;\n"
961 "}";
962
963 static const D3D11_SIGNATURE_PARAMETER_DESC vs1_inputs[] =
964 {
965 {"apple", 0, 0, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_FLOAT32, 0xf, 0x5},
966 {"color", 0, 1, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_FLOAT32, 0xf, 0xf},
967 {"depth", 0, 2, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_FLOAT32, 0xf, 0xf},
968 {"sv_position", 0, 3, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_FLOAT32, 0xf, 0xf},
970 {"grape", 0, 5, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_UINT32, 0x3, 0x3},
971 {"honeydew", 0, 6, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_SINT32, 0x1},
972 };
973
974 static const D3D11_SIGNATURE_PARAMETER_DESC vs1_outputs[] =
975 {
976 {"banana", 2, 0, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_FLOAT32, 0xf, 0x5},
979 {"sv_position", 0, 3, D3D_NAME_POSITION, D3D_REGISTER_COMPONENT_FLOAT32, 0xf},
980 {"grape", 0, 4, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_UINT32, 0x3, 0xc},
981 };
982
983 static const char vs2_source[] =
984 "void main(inout float4 pos : position)\n"
985 "{\n"
986 "}";
987
988 static const D3D11_SIGNATURE_PARAMETER_DESC vs2_inputs[] =
989 {
990 {"position", 0, 0, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_FLOAT32, 0xf, 0xf},
991 };
992
993 static const D3D11_SIGNATURE_PARAMETER_DESC vs2_outputs[] =
994 {
995 {"position", 0, 0, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_FLOAT32, 0xf},
996 };
997
998 static const D3D11_SIGNATURE_PARAMETER_DESC vs2_legacy_outputs[] =
999 {
1000 {"SV_Position", 0, 0, D3D_NAME_POSITION, D3D_REGISTER_COMPONENT_FLOAT32, 0xf},
1001 };
1002
1003 static const char ps1_source[] =
1004 "void main(\n"
1005 " in float2 a : apple,\n"
1006 " out float4 b : sv_target2,\n"
1007 " out float c : sv_depth,\n"
1008 " in float4 d : position,\n"
1009 " in float4 e : sv_position)\n"
1010 "{\n"
1011 " b = d;\n"
1012 " c = 0;\n"
1013 "}";
1014
1015 static const D3D11_SIGNATURE_PARAMETER_DESC ps1_inputs[] =
1016 {
1018 {"position", 0, 1, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_FLOAT32, 0xf, 0xf},
1019 {"sv_position", 0, 2, D3D_NAME_POSITION, D3D_REGISTER_COMPONENT_FLOAT32, 0xf},
1020 };
1021
1022 static const D3D11_SIGNATURE_PARAMETER_DESC ps1_outputs[] =
1023 {
1024 {"sv_target", 2, 2, D3D_NAME_TARGET, D3D_REGISTER_COMPONENT_FLOAT32, 0xf},
1025 {"sv_depth", 0, ~0u, D3D_NAME_DEPTH, D3D_REGISTER_COMPONENT_FLOAT32, 0x1, 0xe},
1026 };
1027
1028 static const char ps2_source[] =
1029 "void main(\n"
1030 " inout float4 a : color2,\n"
1031 " inout float b : depth,\n"
1032 " in float4 c : position)\n"
1033 "{\n"
1034 "}";
1035
1036 static const D3D11_SIGNATURE_PARAMETER_DESC ps2_inputs[] =
1037 {
1038 {"color", 2, 0, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_FLOAT32, 0xf, 0xf},
1039 {"depth", 0, 1, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_FLOAT32, 0x1, 0x1},
1040 {"SV_Position", 0, 2, D3D_NAME_POSITION, D3D_REGISTER_COMPONENT_FLOAT32, 0xf},
1041 };
1042
1043 static const D3D11_SIGNATURE_PARAMETER_DESC ps2_outputs[] =
1044 {
1045 {"SV_Target", 2, 2, D3D_NAME_TARGET, D3D_REGISTER_COMPONENT_FLOAT32, 0xf},
1046 {"SV_Depth", 0, ~0u, D3D_NAME_DEPTH, D3D_REGISTER_COMPONENT_FLOAT32, 0x1, 0xe},
1047 };
1048
1049 static const char cs1_source[] =
1050 "[numthreads(1, 1, 1)]\n"
1051 "void main(in uint a : sv_dispatchthreadid)\n"
1052 "{\n"
1053 "}";
1054
1055 static const char gs1_source[] =
1056 "struct input\n"
1057 "{\n"
1058 " float4 a : sv_position;\n"
1059 " float4 b : apple2;\n"
1060 "};\n"
1061 "struct vertex\n"
1062 "{\n"
1063 " float4 a : sv_position;\n"
1064 " float4 b : apple2;\n"
1065 " uint c : sv_primitiveid;\n"
1066 "};\n"
1067 "[maxvertexcount(1)]\n"
1068 "void main(\n"
1069 " point input i[1],\n"
1070 " inout PointStream<vertex> o,\n"
1071 " uint a : sv_primitiveid)\n"
1072 "{\n"
1073 " struct vertex v;\n"
1074 " v.a = i[0].a;\n"
1075 " v.b = i[0].b;\n"
1076 " v.c = a;\n"
1077 " o.Append(v);\n"
1078 "}";
1079
1080 static const D3D11_SIGNATURE_PARAMETER_DESC gs1_inputs[] =
1081 {
1082 {"sv_position", 0, 0, D3D_NAME_POSITION, D3D_REGISTER_COMPONENT_FLOAT32, 0xf, 0xf},
1083 {"apple", 2, 1, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_FLOAT32, 0xf, 0xf},
1084 {"sv_primitiveid", 0, ~0u, D3D_NAME_PRIMITIVE_ID, D3D_REGISTER_COMPONENT_UINT32, 0x1, 0x1},
1085 };
1086
1087 static const D3D11_SIGNATURE_PARAMETER_DESC gs1_outputs[] =
1088 {
1089 {"sv_position", 0, 0, D3D_NAME_POSITION, D3D_REGISTER_COMPONENT_FLOAT32, 0xf},
1091 {"sv_primitiveid", 0, 2, D3D_NAME_PRIMITIVE_ID, D3D_REGISTER_COMPONENT_UINT32, 0x1, 0xe},
1092 };
1093
1094 static const struct
1095 {
1096 const char *source;
1097 const char *target;
1098 BOOL legacy;
1099 const D3D11_SIGNATURE_PARAMETER_DESC *inputs;
1100 unsigned int input_count;
1101 const D3D11_SIGNATURE_PARAMETER_DESC *outputs;
1102 unsigned int output_count;
1103 }
1104 tests[] =
1105 {
1106 {vs1_source, "vs_4_0", FALSE, vs1_inputs, ARRAY_SIZE(vs1_inputs), vs1_outputs, ARRAY_SIZE(vs1_outputs)},
1107 {vs1_source, "vs_4_0", TRUE, vs1_inputs, ARRAY_SIZE(vs1_inputs), vs1_outputs, ARRAY_SIZE(vs1_outputs)},
1108 {vs2_source, "vs_4_0", FALSE, vs2_inputs, ARRAY_SIZE(vs2_inputs), vs2_outputs, ARRAY_SIZE(vs2_outputs)},
1109 {vs2_source, "vs_4_0", TRUE, vs2_inputs, ARRAY_SIZE(vs2_inputs), vs2_legacy_outputs, ARRAY_SIZE(vs2_legacy_outputs)},
1110 {ps1_source, "ps_4_0", FALSE, ps1_inputs, ARRAY_SIZE(ps1_inputs), ps1_outputs, ARRAY_SIZE(ps1_outputs)},
1111 {ps2_source, "ps_4_0", TRUE, ps2_inputs, ARRAY_SIZE(ps2_inputs), ps2_outputs, ARRAY_SIZE(ps2_outputs)},
1112 {cs1_source, "cs_4_0", FALSE, NULL, 0, NULL, 0},
1113 {gs1_source, "gs_4_0", FALSE, gs1_inputs, ARRAY_SIZE(gs1_inputs), gs1_outputs, ARRAY_SIZE(gs1_outputs)},
1114 };
1115
1116 for (i = 0; i < ARRAY_SIZE(tests); ++i)
1117 {
1118 winetest_push_context("Test %u", i);
1119
1122 if (!code)
1123 {
1125 continue;
1126 }
1127
1128 hr = D3DReflect(ID3D10Blob_GetBufferPointer(code), ID3D10Blob_GetBufferSize(code),
1129 &IID_ID3D11ShaderReflection, (void **)&reflection);
1130 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1131
1132 hr = reflection->lpVtbl->GetDesc(reflection, &shader_desc);
1133 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1134 ok(shader_desc.InputParameters == tests[i].input_count,
1135 "Got %u input parameters.\n", shader_desc.InputParameters);
1136 ok(shader_desc.OutputParameters == tests[i].output_count,
1137 "Got %u output parameters.\n", shader_desc.OutputParameters);
1138
1139 for (j = 0; j < shader_desc.InputParameters; ++j)
1140 {
1141 winetest_push_context("Input %u", j);
1142 hr = reflection->lpVtbl->GetInputParameterDesc(reflection, j, &desc);
1143 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1144 check_parameter_desc(&desc, &tests[i].inputs[j]);
1146 }
1147
1148 for (j = 0; j < shader_desc.OutputParameters; ++j)
1149 {
1150 winetest_push_context("Output %u", j);
1151 hr = reflection->lpVtbl->GetOutputParameterDesc(reflection, j, &desc);
1152 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1153 check_parameter_desc(&desc, &tests[i].outputs[j]);
1155 }
1156
1157 ID3D10Blob_Release(code);
1158 refcount = reflection->lpVtbl->Release(reflection);
1159 ok(!refcount, "Got unexpected refcount %lu.\n", refcount);
1160
1162 }
1163}
@ D3D_NAME_POSITION
Definition: d3dcommon.idl:637
@ D3D_NAME_UNDEFINED
Definition: d3dcommon.idl:636
@ D3D_NAME_TARGET
Definition: d3dcommon.idl:656
@ D3D_NAME_PRIMITIVE_ID
Definition: d3dcommon.idl:643
@ D3D_NAME_DEPTH
Definition: d3dcommon.idl:657
@ D3D_REGISTER_COMPONENT_FLOAT32
Definition: d3dcommon.idl:601
@ D3D_REGISTER_COMPONENT_UINT32
Definition: d3dcommon.idl:599
@ D3D_REGISTER_COMPONENT_SINT32
Definition: d3dcommon.idl:600
unsigned int BOOL
Definition: ntddk_ex.h:94
static void check_parameter_desc(const D3D11_SIGNATURE_PARAMETER_DESC *desc, const D3D11_SIGNATURE_PARAMETER_DESC *expect)
Definition: hlsl_d3d11.c:923
if(dx< 0)
Definition: linetemp.h:194
BOOL legacy
Definition: mkisofs.c:131

Referenced by START_TEST().

◆ test_swizzle()

static void test_swizzle ( void  )
static

Definition at line 369 of file hlsl_d3d11.c.

370{
371 static const struct vec4 uniform = {0.0303f, 0.0f, 0.0f, 0.0202f};
373 ID3D10Blob *ps_code = NULL;
374 ID3D11Buffer *cb;
375 struct vec4 v;
376
377 static const char ps_source[] =
378 "uniform float4 color;\n"
379 "float4 main() : SV_TARGET\n"
380 "{\n"
381 " float4 ret = color;\n"
382 " ret.gb = ret.ra;\n"
383 " ret.ra = float2(0.0101, 0.0404);\n"
384 " return ret;\n"
385 "}";
386
388 return;
389
390 ps_code = compile_shader(ps_source, "ps_4_0");
391 cb = create_buffer(test_context.device, D3D11_BIND_CONSTANT_BUFFER, sizeof(uniform), &uniform);
392 ID3D11DeviceContext_PSSetConstantBuffers(test_context.immediate_context, 0, 1, &cb);
393 draw_quad(&test_context, ps_code);
394
395 v = get_color_vec4(&test_context, 0, 0);
396 ok(compare_vec4(&v, 0.0101f, 0.0303f, 0.0202f, 0.0404f, 0),
397 "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
398
399 ID3D11Buffer_Release(cb);
400 ID3D10Blob_Release(ps_code);
402}

Referenced by START_TEST().

◆ test_trig()

static void test_trig ( void  )
static

Definition at line 482 of file hlsl_d3d11.c.

483{
485 ID3D10Blob *ps_code = NULL;
486 const struct vec4 *v;
487 struct readback rb;
488 unsigned int i;
489
490 static const char ps_source[] =
491 "float4 main(float4 pos : SV_POSITION) : SV_TARGET\n"
492 "{\n"
493 " return float4(sin(pos.x - 0.5), cos(pos.x - 0.5), 0, 0);\n"
494 "}";
495
497 return;
498
499 ps_code = compile_shader(ps_source, "ps_4_0");
500 draw_quad(&test_context, ps_code);
502
503 for (i = 0; i < 640; i += 20)
504 {
505 v = get_readback_vec4(&rb, i, 0);
506 ok(compare_vec4(v, sinf(i), cosf(i), 0.0f, 0.0f, 16384),
507 "Test %u: Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
508 i, v->x, v->y, v->z, v->w, sinf(i), cos(i), 0.0f, 0.0f);
509 }
510
512 ID3D10Blob_Release(ps_code);
514}
_ACRTIMP float __cdecl cosf(float)
Definition: cosf.c:13
_ACRTIMP float __cdecl sinf(float)
Definition: sinf.c:13
_ACRTIMP double __cdecl cos(double)
Definition: cos.c:21

Referenced by START_TEST().

Variable Documentation

◆ device_out

◆ driver_type

◆ feature_levels

◆ flags

Definition at line 28 of file hlsl_d3d11.c.

◆ immediate_context

◆ levels

◆ obtained_feature_level

◆ sdk_version

◆ swrast