vkd3d-shader/hlsl: Use a block in hlsl_normalize_binary_exprs().
[vkd3d.git] / demos / demo.h
blob24302007b16abc66a3a3a7764a5b5bc1d2be174d
1 /*
2 * Copyright 2016 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 /* Hack for MinGW-w64 headers.
21 * We want to use WIDL C inline wrappers because some methods
22 * in D3D12 interfaces return aggregate objects. Unfortunately,
23 * WIDL C inline wrappers are broken when used with MinGW-w64
24 * headers because FORCEINLINE expands to extern inline
25 * which leads to the "multiple storage classes in declaration
26 * specifiers" compiler error.
28 #ifdef __MINGW32__
29 #include <_mingw.h>
30 # ifdef __MINGW64_VERSION_MAJOR
31 # undef __forceinline
32 # define __forceinline __inline__ __attribute__((__always_inline__,__gnu_inline__))
33 # endif
34 #endif
36 #include <vkd3d_windows.h>
37 #define WIDL_C_INLINE_WRAPPERS
38 #define COBJMACROS
39 #include <vkd3d_d3d12.h>
40 #include <inttypes.h>
42 #ifdef __WIN32__
43 #define DEMO_ASM_PUSHSECTION ".section rdata\n\t"
44 #define DEMO_ASM_POPSECTION ".text\n\t"
45 #define DEMO_ASM_OBJECT_TYPE(name)
46 #else
47 #define DEMO_ASM_PUSHSECTION ".pushsection .rodata\n\t"
48 #define DEMO_ASM_POPSECTION ".popsection\n\t"
49 #define DEMO_ASM_OBJECT_TYPE(name) ".type "name", @object\n\t"
50 #endif
52 #if defined(__WIN32__) && defined(__i386__)
53 #define DEMO_ASM_NAME(name) "_"#name
54 #else
55 #define DEMO_ASM_NAME(name) #name
56 #endif
58 #define DEMO_EMBED_ASM(name, file) \
59 DEMO_ASM_PUSHSECTION \
60 ".global "name"\n\t" \
61 DEMO_ASM_OBJECT_TYPE(name) \
62 ".balign 8\n\t" \
63 name":\n\t" \
64 ".incbin \""file"\"\n\t" \
65 name"_end:\n\t" \
66 ".global "name"_size\n\t" \
67 DEMO_ASM_OBJECT_TYPE(name"_size") \
68 ".balign 8\n\t" \
69 name"_size:\n\t" \
70 ".int "name"_end - "name"\n\t" \
71 DEMO_ASM_POPSECTION
73 #define DEMO_EMBED(name, file) \
74 extern const unsigned int name##_size; \
75 extern const uint8_t name[]; \
76 __asm__(DEMO_EMBED_ASM(DEMO_ASM_NAME(name), file))
78 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*x))
80 #define DEMO_KEY_UNKNOWN 0x0000
81 #define DEMO_KEY_ESCAPE 0xff1b
82 #define DEMO_KEY_LEFT 0xff51
83 #define DEMO_KEY_UP 0xff52
84 #define DEMO_KEY_RIGHT 0xff53
85 #define DEMO_KEY_DOWN 0xff54
87 struct demo_vec3
89 float x, y, z;
92 struct demo_vec4
94 float x, y, z, w;
97 struct demo_swapchain_desc
99 unsigned int width;
100 unsigned int height;
101 unsigned int buffer_count;
102 DXGI_FORMAT format;
105 typedef uint32_t demo_key;
107 static inline void demo_vec3_set(struct demo_vec3 *v, float x, float y, float z)
109 v->x = x;
110 v->y = y;
111 v->z = z;
114 static inline void demo_vec4_set(struct demo_vec4 *v, float x, float y, float z, float w)
116 v->x = x;
117 v->y = y;
118 v->z = z;
119 v->w = w;
122 static inline void demo_rasterizer_desc_init_default(D3D12_RASTERIZER_DESC *desc)
124 desc->FillMode = D3D12_FILL_MODE_SOLID;
125 desc->CullMode = D3D12_CULL_MODE_BACK;
126 desc->FrontCounterClockwise = FALSE;
127 desc->DepthBias = D3D12_DEFAULT_DEPTH_BIAS;
128 desc->DepthBiasClamp = D3D12_DEFAULT_DEPTH_BIAS_CLAMP;
129 desc->SlopeScaledDepthBias = D3D12_DEFAULT_SLOPE_SCALED_DEPTH_BIAS;
130 desc->DepthClipEnable = TRUE;
131 desc->MultisampleEnable = FALSE;
132 desc->AntialiasedLineEnable = FALSE;
133 desc->ForcedSampleCount = 0;
134 desc->ConservativeRaster = D3D12_CONSERVATIVE_RASTERIZATION_MODE_OFF;
137 static inline void demo_blend_desc_init_default(D3D12_BLEND_DESC *desc)
139 static const D3D12_RENDER_TARGET_BLEND_DESC rt_blend_desc =
141 .BlendEnable = FALSE,
142 .LogicOpEnable = FALSE,
143 .SrcBlend = D3D12_BLEND_ONE,
144 .DestBlend = D3D12_BLEND_ZERO,
145 .BlendOp = D3D12_BLEND_OP_ADD,
146 .SrcBlendAlpha = D3D12_BLEND_ONE,
147 .DestBlendAlpha = D3D12_BLEND_ZERO,
148 .BlendOpAlpha = D3D12_BLEND_OP_ADD,
149 .LogicOp = D3D12_LOGIC_OP_NOOP,
150 .RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL,
152 unsigned int i;
154 desc->AlphaToCoverageEnable = FALSE;
155 desc->IndependentBlendEnable = FALSE;
156 for (i = 0; i < ARRAY_SIZE(desc->RenderTarget); ++i)
158 desc->RenderTarget[i] = rt_blend_desc;
162 static inline HRESULT demo_create_root_signature(ID3D12Device *device,
163 const D3D12_ROOT_SIGNATURE_DESC *desc, ID3D12RootSignature **signature)
165 ID3DBlob *blob;
166 HRESULT hr;
168 if (FAILED(hr = D3D12SerializeRootSignature(desc, D3D_ROOT_SIGNATURE_VERSION_1, &blob, NULL)))
169 return hr;
170 hr = ID3D12Device_CreateRootSignature(device, 0, ID3D10Blob_GetBufferPointer(blob),
171 ID3D10Blob_GetBufferSize(blob), &IID_ID3D12RootSignature, (void **)signature);
172 ID3D10Blob_Release(blob);
174 return hr;
177 #ifdef _WIN32
178 #include "demo_win32.h"
179 #else
180 #define INFINITE VKD3D_INFINITE
181 #include "demo_xcb.h"
182 #endif