/
SDL_render_d3d11.c
2996 lines (2686 loc) · 115 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
Simple DirectMedia Layer
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
21
#include "../../SDL_internal.h"
22
23
24
25
26
27
#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
#ifdef __WINRT__
#include <windows.ui.core.h>
#include <windows.foundation.h>
28
29
30
31
32
#if WINAPI_FAMILY == WINAPI_FAMILY_APP
#include <windows.ui.xaml.media.dxinterop.h>
#endif
33
34
35
using namespace Windows::UI::Core;
using namespace Windows::Graphics::Display;
#endif /* __WINRT__ */
36
37
#define COBJMACROS
38
#include "../../core/windows/SDL_windows.h"
39
#include "SDL_hints.h"
40
#include "SDL_loadso.h"
41
42
43
#include "SDL_syswm.h"
#include "../SDL_sysrender.h"
44
#include <d3d11_1.h>
45
46
47
#define SAFE_RELEASE(X) if ( (X) ) { IUnknown_Release( SDL_static_cast(IUnknown*, X ) ); X = NULL; }
48
49
50
51
52
53
typedef struct
{
float x;
float y;
} Float2;
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
typedef struct
{
float x;
float y;
float z;
} Float3;
typedef struct
{
float x;
float y;
float z;
float w;
} Float4;
69
70
71
72
73
74
75
76
77
78
79
80
81
typedef struct
{
union {
struct {
float _11, _12, _13, _14;
float _21, _22, _23, _24;
float _31, _32, _33, _34;
float _41, _42, _43, _44;
};
float m[4][4];
};
} Float4X4;
82
83
/* Vertex shader, common values */
84
typedef struct
85
{
86
87
88
Float4X4 model;
Float4X4 projectionAndView;
} VertexShaderConstants;
89
90
/* Per-vertex data */
91
typedef struct
92
{
93
94
95
96
Float3 pos;
Float2 tex;
Float4 color;
} VertexPositionColor;
97
98
99
100
/* Per-texture data */
typedef struct
{
101
102
103
104
105
106
ID3D11Texture2D *mainTexture;
ID3D11ShaderResourceView *mainTextureResourceView;
ID3D11RenderTargetView *mainTextureRenderTargetView;
ID3D11Texture2D *stagingTexture;
int lockedTexturePositionX;
int lockedTexturePositionY;
107
D3D11_FILTER scaleMode;
108
109
110
111
112
113
114
115
116
117
/* YV12 texture support */
SDL_bool yuv;
ID3D11Texture2D *mainTextureU;
ID3D11ShaderResourceView *mainTextureResourceViewU;
ID3D11Texture2D *mainTextureV;
ID3D11ShaderResourceView *mainTextureResourceViewV;
Uint8 *pixels;
int pitch;
SDL_Rect locked_rect;
118
119
120
121
122
} D3D11_TextureData;
/* Private renderer data */
typedef struct
{
123
124
125
126
127
128
129
130
131
132
133
void *hD3D11Mod;
ID3D11Device1 *d3dDevice;
ID3D11DeviceContext1 *d3dContext;
IDXGISwapChain1 *swapChain;
DXGI_SWAP_EFFECT swapEffect;
ID3D11RenderTargetView *mainRenderTargetView;
ID3D11RenderTargetView *currentOffscreenRenderTargetView;
ID3D11InputLayout *inputLayout;
ID3D11Buffer *vertexBuffer;
ID3D11VertexShader *vertexShader;
ID3D11PixelShader *colorPixelShader;
134
135
ID3D11PixelShader *texturePixelShader;
ID3D11PixelShader *yuvPixelShader;
136
137
138
139
140
ID3D11BlendState *blendModeBlend;
ID3D11BlendState *blendModeAdd;
ID3D11BlendState *blendModeMod;
ID3D11SamplerState *nearestPixelSampler;
ID3D11SamplerState *linearSampler;
141
142
D3D_FEATURE_LEVEL featureLevel;
143
144
145
/* Rasterizers */
ID3D11RasterizerState *mainRasterizer;
ID3D11RasterizerState *clippedRasterizer;
146
147
/* Vertex buffer constants */
148
VertexShaderConstants vertexShaderConstantsData;
149
150
151
152
153
154
155
156
157
158
ID3D11Buffer *vertexShaderConstants;
/* Cached renderer properties */
DXGI_MODE_ROTATION rotation;
ID3D11RenderTargetView *currentRenderTargetView;
ID3D11RasterizerState *currentRasterizerState;
ID3D11BlendState *currentBlendState;
ID3D11PixelShader *currentShader;
ID3D11ShaderResourceView *currentShaderResource;
ID3D11SamplerState *currentSampler;
159
} D3D11_RenderData;
160
161
162
163
164
165
166
167
168
169
/* Defined here so we don't have to include uuid.lib */
static const GUID IID_IDXGIFactory2 = { 0x50c83a1c, 0xe072, 0x4c48, { 0x87, 0xb0, 0x36, 0x30, 0xfa, 0x36, 0xa6, 0xd0 } };
static const GUID IID_IDXGIDevice1 = { 0x77db970f, 0x6276, 0x48ba, { 0xba, 0x28, 0x07, 0x01, 0x43, 0xb4, 0x39, 0x2c } };
static const GUID IID_ID3D11Texture2D = { 0x6f15aaf2, 0xd208, 0x4e89, { 0x9a, 0xb4, 0x48, 0x95, 0x35, 0xd3, 0x4f, 0x9c } };
static const GUID IID_ID3D11Device1 = { 0xa04bfb29, 0x08ef, 0x43d6, { 0xa4, 0x9c, 0xa9, 0xbd, 0xbd, 0xcb, 0xe6, 0x86 } };
static const GUID IID_ID3D11DeviceContext1 = { 0xbb2c6faa, 0xb5fb, 0x4082, { 0x8e, 0x6b, 0x38, 0x8b, 0x8c, 0xfa, 0x90, 0xe1 } };
static const GUID IID_ID3D11Debug = { 0x79cf2233, 0x7536, 0x4948, { 0x9d, 0x36, 0x1e, 0x46, 0x92, 0xdc, 0x57, 0x60 } };
170
171
172
173
174
/* Direct3D 11.x shaders
SDL's shaders are compiled into SDL itself, to simplify distribution.
All Direct3D 11.x shaders were compiled with the following:
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
fxc /E"main" /T "<TYPE>" /Fo"<OUTPUT FILE>" "<INPUT FILE>"
Variables:
- <TYPE>: the type of shader. A table of utilized shader types is
listed below.
- <OUTPUT FILE>: where to store compiled output
- <INPUT FILE>: where to read shader source code from
Shader types:
- ps_4_0_level_9_1: Pixel shader for Windows 8+, including Windows RT
- vs_4_0_level_9_1: Vertex shader for Windows 8+, including Windows RT
- ps_4_0_level_9_3: Pixel shader for Windows Phone 8
- vs_4_0_level_9_3: Vertex shader for Windows Phone 8
Shader object code was converted to a list of DWORDs via the following
*nix style command (available separately from Windows + MSVC):
hexdump -v -e '6/4 "0x%08.8x, " "\n"' <FILE>
*/
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
#define D3D11_USE_SHADER_MODEL_4_0_level_9_3
#else
#define D3D11_USE_SHADER_MODEL_4_0_level_9_1
#endif
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/* The color-only-rendering pixel shader:
--- D3D11_PixelShader_Colors.hlsl ---
struct PixelShaderInput
{
float4 pos : SV_POSITION;
float2 tex : TEXCOORD0;
float4 color : COLOR0;
};
float4 main(PixelShaderInput input) : SV_TARGET
{
return input.color;
}
*/
#if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1)
static const DWORD D3D11_PixelShader_Colors[] = {
0x43425844, 0xd74c28fe, 0xa1eb8804, 0x269d512a, 0x7699723d, 0x00000001,
0x00000240, 0x00000006, 0x00000038, 0x00000084, 0x000000c4, 0x00000140,
0x00000198, 0x0000020c, 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200,
0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0001, 0x02000001,
0x800f0800, 0xb0e40001, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040,
0x0000000e, 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2,
0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002,
0x0100003e, 0x54415453, 0x00000074, 0x00000002, 0x00000000, 0x00000000,
0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x46454452, 0x00000050, 0x00000000, 0x00000000,
0x00000000, 0x0000001c, 0xffff0400, 0x00000100, 0x0000001c, 0x7263694d,
0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072,
0x6c69706d, 0x39207265, 0x2e30332e, 0x30303239, 0x3336312e, 0xab003438,
0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000,
0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
0x00000000, 0x00000003, 0x00000001, 0x00000003, 0x00000065, 0x00000000,
0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f,
0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f,
0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
};
#elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3)
static const DWORD D3D11_PixelShader_Colors[] = {
0x43425844, 0x93f6ccfc, 0x5f919270, 0x7a11aa4f, 0x9148e931, 0x00000001,
0x00000240, 0x00000006, 0x00000038, 0x00000084, 0x000000c4, 0x00000140,
0x00000198, 0x0000020c, 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200,
0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
0x00240000, 0xffff0201, 0x0200001f, 0x80000000, 0xb00f0001, 0x02000001,
0x800f0800, 0xb0e40001, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040,
0x0000000e, 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2,
0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002,
0x0100003e, 0x54415453, 0x00000074, 0x00000002, 0x00000000, 0x00000000,
0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x46454452, 0x00000050, 0x00000000, 0x00000000,
0x00000000, 0x0000001c, 0xffff0400, 0x00000100, 0x0000001c, 0x7263694d,
0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072,
0x6c69706d, 0x39207265, 0x2e30332e, 0x30303239, 0x3336312e, 0xab003438,
0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000,
0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
0x00000000, 0x00000003, 0x00000001, 0x00000003, 0x00000065, 0x00000000,
0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f,
0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f,
0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
};
#else
#error "An appropriate 'colors' pixel shader is not defined."
#endif
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
/* The texture-rendering pixel shader:
--- D3D11_PixelShader_Textures.hlsl ---
Texture2D theTexture : register(t0);
SamplerState theSampler : register(s0);
struct PixelShaderInput
{
float4 pos : SV_POSITION;
float2 tex : TEXCOORD0;
float4 color : COLOR0;
};
float4 main(PixelShaderInput input) : SV_TARGET
{
return theTexture.Sample(theSampler, input.tex) * input.color;
}
*/
#if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1)
static const DWORD D3D11_PixelShader_Textures[] = {
0x43425844, 0x6299b59f, 0x155258f2, 0x873ab86a, 0xfcbb6dcd, 0x00000001,
0x00000330, 0x00000006, 0x00000038, 0x000000c0, 0x0000015c, 0x000001d8,
0x00000288, 0x000002fc, 0x396e6f41, 0x00000080, 0x00000080, 0xffff0200,
0x00000058, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001,
0x00280000, 0x00000000, 0xffff0200, 0x0200001f, 0x80000000, 0xb0030000,
0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, 0x90000000, 0xa00f0800,
0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, 0x03000005, 0x800f0000,
0x80e40000, 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff,
0x52444853, 0x00000094, 0x00000040, 0x00000025, 0x0300005a, 0x00106000,
0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03001062,
0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002, 0x03000065,
0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x09000045, 0x001000f2,
0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000, 0x00106000,
0x00000000, 0x07000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
0x00101e46, 0x00000002, 0x0100003e, 0x54415453, 0x00000074, 0x00000003,
0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x00000000, 0x00000000,
0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x46454452, 0x000000a8,
0x00000000, 0x00000000, 0x00000002, 0x0000001c, 0xffff0400, 0x00000100,
0x00000072, 0x0000005c, 0x00000003, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000001, 0x00000001, 0x00000067, 0x00000002, 0x00000005,
0x00000004, 0xffffffff, 0x00000000, 0x00000001, 0x0000000d, 0x53656874,
0x6c706d61, 0x74007265, 0x65546568, 0x72757478, 0x694d0065, 0x736f7263,
0x2074666f, 0x20295228, 0x4c534c48, 0x61685320, 0x20726564, 0x706d6f43,
0x72656c69, 0x332e3920, 0x32392e30, 0x312e3030, 0x34383336, 0xababab00,
0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000,
0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000065, 0x00000000,
0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f,
0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f,
0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
329
330
331
};
#elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3)
static const DWORD D3D11_PixelShader_Textures[] = {
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
0x43425844, 0x5876569a, 0x01b6c87e, 0x8447454f, 0xc7f3ef10, 0x00000001,
0x00000330, 0x00000006, 0x00000038, 0x000000c0, 0x0000015c, 0x000001d8,
0x00000288, 0x000002fc, 0x396e6f41, 0x00000080, 0x00000080, 0xffff0200,
0x00000058, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001,
0x00280000, 0x00000000, 0xffff0201, 0x0200001f, 0x80000000, 0xb0030000,
0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, 0x90000000, 0xa00f0800,
0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, 0x03000005, 0x800f0000,
0x80e40000, 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff,
0x52444853, 0x00000094, 0x00000040, 0x00000025, 0x0300005a, 0x00106000,
0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03001062,
0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002, 0x03000065,
0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x09000045, 0x001000f2,
0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000, 0x00106000,
0x00000000, 0x07000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
0x00101e46, 0x00000002, 0x0100003e, 0x54415453, 0x00000074, 0x00000003,
0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x00000000, 0x00000000,
0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x46454452, 0x000000a8,
0x00000000, 0x00000000, 0x00000002, 0x0000001c, 0xffff0400, 0x00000100,
0x00000072, 0x0000005c, 0x00000003, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000001, 0x00000001, 0x00000067, 0x00000002, 0x00000005,
0x00000004, 0xffffffff, 0x00000000, 0x00000001, 0x0000000d, 0x53656874,
0x6c706d61, 0x74007265, 0x65546568, 0x72757478, 0x694d0065, 0x736f7263,
0x2074666f, 0x20295228, 0x4c534c48, 0x61685320, 0x20726564, 0x706d6f43,
0x72656c69, 0x332e3920, 0x32392e30, 0x312e3030, 0x34383336, 0xababab00,
0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000,
0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000065, 0x00000000,
0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f,
0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f,
0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
365
366
367
368
369
370
0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
};
#else
#error "An appropriate 'textures' pixel shader is not defined"
#endif
371
/* The yuv-rendering pixel shader:
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
--- D3D11_PixelShader_YUV.hlsl ---
Texture2D theTextureY : register(t0);
Texture2D theTextureU : register(t1);
Texture2D theTextureV : register(t2);
SamplerState theSampler : register(s0);
struct PixelShaderInput
{
float4 pos : SV_POSITION;
float2 tex : TEXCOORD0;
float4 color : COLOR0;
};
float4 main(PixelShaderInput input) : SV_TARGET
{
const float3 offset = {-0.0625, -0.5, -0.5};
const float3 Rcoeff = {1.164, 0.000, 1.596};
const float3 Gcoeff = {1.164, -0.391, -0.813};
const float3 Bcoeff = {1.164, 2.018, 0.000};
float4 Output;
float3 yuv;
yuv.x = theTextureY.Sample(theSampler, input.tex).r;
yuv.y = theTextureU.Sample(theSampler, input.tex).r;
yuv.z = theTextureV.Sample(theSampler, input.tex).r;
yuv += offset;
Output.r = dot(yuv, Rcoeff);
Output.g = dot(yuv, Gcoeff);
Output.b = dot(yuv, Bcoeff);
Output.a = 1.0f;
return Output * input.color;
}
408
409
*/
410
#if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1)
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
static const DWORD D3D11_PixelShader_YUV[] = {
0x43425844, 0x04e69cba, 0x74ce6dd2, 0x7fcf84cb, 0x3003d677, 0x00000001,
0x000005e8, 0x00000006, 0x00000038, 0x000001dc, 0x000003bc, 0x00000438,
0x00000540, 0x000005b4, 0x396e6f41, 0x0000019c, 0x0000019c, 0xffff0200,
0x0000016c, 0x00000030, 0x00300000, 0x00300000, 0x00300000, 0x00240003,
0x00300000, 0x00000000, 0x00010001, 0x00020002, 0xffff0200, 0x05000051,
0xa00f0000, 0xbd800000, 0xbf000000, 0xbf000000, 0x3f800000, 0x05000051,
0xa00f0001, 0x3f94fdf4, 0x3fcc49ba, 0x00000000, 0x00000000, 0x05000051,
0xa00f0002, 0x3f94fdf4, 0xbec83127, 0xbf5020c5, 0x00000000, 0x05000051,
0xa00f0003, 0x3f94fdf4, 0x400126e9, 0x00000000, 0x00000000, 0x0200001f,
0x80000000, 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f,
0x90000000, 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x0200001f,
0x90000000, 0xa00f0802, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800,
0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40801, 0x03000042, 0x800f0002,
0xb0e40000, 0xa0e40802, 0x02000001, 0x80020000, 0x80000001, 0x02000001,
0x80040000, 0x80000002, 0x03000002, 0x80070000, 0x80e40000, 0xa0e40000,
0x03000005, 0x80080000, 0x80000000, 0xa0000001, 0x04000004, 0x80010001,
0x80aa0000, 0xa0550001, 0x80ff0000, 0x03000008, 0x80020001, 0x80e40000,
0xa0e40002, 0x0400005a, 0x80040001, 0x80e40000, 0xa0e40003, 0xa0aa0003,
0x02000001, 0x80080001, 0xa0ff0000, 0x03000005, 0x800f0000, 0x80e40001,
0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x52444853,
0x000001d8, 0x00000040, 0x00000076, 0x0300005a, 0x00106000, 0x00000000,
0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858, 0x00107000,
0x00000001, 0x00005555, 0x04001858, 0x00107000, 0x00000002, 0x00005555,
0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002,
0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x09000045,
0x001000f2, 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000,
0x00106000, 0x00000000, 0x09000045, 0x001000f2, 0x00000001, 0x00101046,
0x00000001, 0x00107e46, 0x00000001, 0x00106000, 0x00000000, 0x05000036,
0x00100022, 0x00000000, 0x0010000a, 0x00000001, 0x09000045, 0x001000f2,
0x00000001, 0x00101046, 0x00000001, 0x00107e46, 0x00000002, 0x00106000,
0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x0010000a, 0x00000001,
0x0a000000, 0x00100072, 0x00000000, 0x00100246, 0x00000000, 0x00004002,
0xbd800000, 0xbf000000, 0xbf000000, 0x00000000, 0x0a00000f, 0x00100012,
0x00000001, 0x00100086, 0x00000000, 0x00004002, 0x3f94fdf4, 0x3fcc49ba,
0x00000000, 0x00000000, 0x0a000010, 0x00100022, 0x00000001, 0x00100246,
0x00000000, 0x00004002, 0x3f94fdf4, 0xbec83127, 0xbf5020c5, 0x00000000,
0x0a00000f, 0x00100042, 0x00000001, 0x00100046, 0x00000000, 0x00004002,
0x3f94fdf4, 0x400126e9, 0x00000000, 0x00000000, 0x05000036, 0x00100082,
0x00000001, 0x00004001, 0x3f800000, 0x07000038, 0x001020f2, 0x00000000,
0x00100e46, 0x00000001, 0x00101e46, 0x00000002, 0x0100003e, 0x54415453,
0x00000074, 0x0000000c, 0x00000002, 0x00000000, 0x00000003, 0x00000005,
0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x46454452, 0x00000100, 0x00000000, 0x00000000, 0x00000004, 0x0000001c,
0xffff0400, 0x00000100, 0x000000cb, 0x0000009c, 0x00000003, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x000000a7,
0x00000002, 0x00000005, 0x00000004, 0xffffffff, 0x00000000, 0x00000001,
0x0000000d, 0x000000b3, 0x00000002, 0x00000005, 0x00000004, 0xffffffff,
0x00000001, 0x00000001, 0x0000000d, 0x000000bf, 0x00000002, 0x00000005,
0x00000004, 0xffffffff, 0x00000002, 0x00000001, 0x0000000d, 0x53656874,
0x6c706d61, 0x74007265, 0x65546568, 0x72757478, 0x74005965, 0x65546568,
0x72757478, 0x74005565, 0x65546568, 0x72757478, 0x4d005665, 0x6f726369,
0x74666f73, 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320,
0x656c6970, 0x2e362072, 0x36392e33, 0x312e3030, 0x34383336, 0xababab00,
0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000,
0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000065, 0x00000000,
0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f,
0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f,
0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
474
475
476
0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
};
#elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3)
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
static const DWORD D3D11_PixelShader_YUV[] = {
0x43425844, 0xe6d969fc, 0x63cac33c, 0xa4926502, 0x5d788135, 0x00000001,
0x000005c0, 0x00000006, 0x00000038, 0x000001b4, 0x00000394, 0x00000410,
0x00000518, 0x0000058c, 0x396e6f41, 0x00000174, 0x00000174, 0xffff0200,
0x00000144, 0x00000030, 0x00300000, 0x00300000, 0x00300000, 0x00240003,
0x00300000, 0x00000000, 0x00010001, 0x00020002, 0xffff0201, 0x05000051,
0xa00f0000, 0xbd800000, 0xbf000000, 0x3f800000, 0x00000000, 0x05000051,
0xa00f0001, 0x3f94fdf4, 0x3fcc49ba, 0x00000000, 0x400126e9, 0x05000051,
0xa00f0002, 0x3f94fdf4, 0xbec83127, 0xbf5020c5, 0x00000000, 0x0200001f,
0x80000000, 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f,
0x90000000, 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x0200001f,
0x90000000, 0xa00f0802, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40801,
0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40800, 0x02000001, 0x80020001,
0x80000000, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40802, 0x02000001,
0x80040001, 0x80000000, 0x03000002, 0x80070000, 0x80e40001, 0xa0d40000,
0x0400005a, 0x80010001, 0x80e80000, 0xa0e40001, 0xa0aa0001, 0x03000008,
0x80020001, 0x80e40000, 0xa0e40002, 0x0400005a, 0x80040001, 0x80e40000,
0xa0ec0001, 0xa0aa0001, 0x02000001, 0x80080001, 0xa0aa0000, 0x03000005,
0x800f0000, 0x80e40001, 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000,
0x0000ffff, 0x52444853, 0x000001d8, 0x00000040, 0x00000076, 0x0300005a,
0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04001858, 0x00107000,
0x00000002, 0x00005555, 0x03001062, 0x00101032, 0x00000001, 0x03001062,
0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
0x00000002, 0x09000045, 0x001000f2, 0x00000000, 0x00101046, 0x00000001,
0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x09000045, 0x001000f2,
0x00000001, 0x00101046, 0x00000001, 0x00107e46, 0x00000001, 0x00106000,
0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x0010000a, 0x00000001,
0x09000045, 0x001000f2, 0x00000001, 0x00101046, 0x00000001, 0x00107e46,
0x00000002, 0x00106000, 0x00000000, 0x05000036, 0x00100042, 0x00000000,
0x0010000a, 0x00000001, 0x0a000000, 0x00100072, 0x00000000, 0x00100246,
0x00000000, 0x00004002, 0xbd800000, 0xbf000000, 0xbf000000, 0x00000000,
0x0a00000f, 0x00100012, 0x00000001, 0x00100086, 0x00000000, 0x00004002,
0x3f94fdf4, 0x3fcc49ba, 0x00000000, 0x00000000, 0x0a000010, 0x00100022,
0x00000001, 0x00100246, 0x00000000, 0x00004002, 0x3f94fdf4, 0xbec83127,
0xbf5020c5, 0x00000000, 0x0a00000f, 0x00100042, 0x00000001, 0x00100046,
0x00000000, 0x00004002, 0x3f94fdf4, 0x400126e9, 0x00000000, 0x00000000,
0x05000036, 0x00100082, 0x00000001, 0x00004001, 0x3f800000, 0x07000038,
0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00101e46, 0x00000002,
0x0100003e, 0x54415453, 0x00000074, 0x0000000c, 0x00000002, 0x00000000,
0x00000003, 0x00000005, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x46454452, 0x00000100, 0x00000000, 0x00000000,
0x00000004, 0x0000001c, 0xffff0400, 0x00000100, 0x000000cb, 0x0000009c,
0x00000003, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
0x00000001, 0x000000a7, 0x00000002, 0x00000005, 0x00000004, 0xffffffff,
0x00000000, 0x00000001, 0x0000000d, 0x000000b3, 0x00000002, 0x00000005,
0x00000004, 0xffffffff, 0x00000001, 0x00000001, 0x0000000d, 0x000000bf,
0x00000002, 0x00000005, 0x00000004, 0xffffffff, 0x00000002, 0x00000001,
0x0000000d, 0x53656874, 0x6c706d61, 0x74007265, 0x65546568, 0x72757478,
0x74005965, 0x65546568, 0x72757478, 0x74005565, 0x65546568, 0x72757478,
0x4d005665, 0x6f726369, 0x74666f73, 0x29522820, 0x534c4820, 0x6853204c,
0x72656461, 0x6d6f4320, 0x656c6970, 0x2e362072, 0x36392e33, 0x312e3030,
0x34383336, 0xababab00, 0x4e475349, 0x0000006c, 0x00000003, 0x00000008,
0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000303,
0x00000065, 0x00000000, 0x00000000, 0x00000003, 0x00000002, 0x00000f0f,
0x505f5653, 0x5449534f, 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300,
0xab00524f, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
0x45475241, 0xabab0054
540
};
541
#else
542
#error "An appropriate 'yuv' pixel shader is not defined."
543
544
545
546
547
#endif
/* The sole vertex shader:
--- D3D11_VertexShader.hlsl ---
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
#pragma pack_matrix( row_major )
cbuffer VertexShaderConstants : register(b0)
{
matrix model;
matrix projectionAndView;
};
struct VertexShaderInput
{
float3 pos : POSITION;
float2 tex : TEXCOORD0;
float4 color : COLOR0;
};
struct VertexShaderOutput
{
float4 pos : SV_POSITION;
float2 tex : TEXCOORD0;
float4 color : COLOR0;
};
VertexShaderOutput main(VertexShaderInput input)
{
VertexShaderOutput output;
float4 pos = float4(input.pos, 1.0f);
// Transform the vertex position into projected space.
pos = mul(pos, model);
pos = mul(pos, projectionAndView);
output.pos = pos;
// Pass through texture coordinates and color values without transformation
output.tex = input.tex;
output.color = input.color;
return output;
}
586
587
588
*/
#if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1)
static const DWORD D3D11_VertexShader[] = {
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
0x43425844, 0x62dfae5f, 0x3e8bd8df, 0x9ec97127, 0x5044eefb, 0x00000001,
0x00000598, 0x00000006, 0x00000038, 0x0000016c, 0x00000334, 0x000003b0,
0x000004b4, 0x00000524, 0x396e6f41, 0x0000012c, 0x0000012c, 0xfffe0200,
0x000000f8, 0x00000034, 0x00240001, 0x00300000, 0x00300000, 0x00240000,
0x00300001, 0x00000000, 0x00010008, 0x00000000, 0x00000000, 0xfffe0200,
0x0200001f, 0x80000005, 0x900f0000, 0x0200001f, 0x80010005, 0x900f0001,
0x0200001f, 0x80020005, 0x900f0002, 0x03000005, 0x800f0000, 0x90550000,
0xa0e40002, 0x04000004, 0x800f0000, 0x90000000, 0xa0e40001, 0x80e40000,
0x04000004, 0x800f0000, 0x90aa0000, 0xa0e40003, 0x80e40000, 0x03000002,
0x800f0000, 0x80e40000, 0xa0e40004, 0x03000005, 0x800f0001, 0x80550000,
0xa0e40006, 0x04000004, 0x800f0001, 0x80000000, 0xa0e40005, 0x80e40001,
0x04000004, 0x800f0001, 0x80aa0000, 0xa0e40007, 0x80e40001, 0x04000004,
0x800f0000, 0x80ff0000, 0xa0e40008, 0x80e40001, 0x04000004, 0xc0030000,
0x80ff0000, 0xa0e40000, 0x80e40000, 0x02000001, 0xc00c0000, 0x80e40000,
0x02000001, 0xe0030000, 0x90e40001, 0x02000001, 0xe00f0001, 0x90e40002,
0x0000ffff, 0x52444853, 0x000001c0, 0x00010040, 0x00000070, 0x04000059,
0x00208e46, 0x00000000, 0x00000008, 0x0300005f, 0x00101072, 0x00000000,
0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x001010f2, 0x00000002,
0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102032,
0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000002,
0x08000038, 0x001000f2, 0x00000000, 0x00101556, 0x00000000, 0x00208e46,
0x00000000, 0x00000001, 0x0a000032, 0x001000f2, 0x00000000, 0x00101006,
0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
0x0a000032, 0x001000f2, 0x00000000, 0x00101aa6, 0x00000000, 0x00208e46,
0x00000000, 0x00000002, 0x00100e46, 0x00000000, 0x08000000, 0x001000f2,
0x00000000, 0x00100e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003,
0x08000038, 0x001000f2, 0x00000001, 0x00100556, 0x00000000, 0x00208e46,
0x00000000, 0x00000005, 0x0a000032, 0x001000f2, 0x00000001, 0x00100006,
0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x00100e46, 0x00000001,
0x0a000032, 0x001000f2, 0x00000001, 0x00100aa6, 0x00000000, 0x00208e46,
0x00000000, 0x00000006, 0x00100e46, 0x00000001, 0x0a000032, 0x001020f2,
0x00000000, 0x00100ff6, 0x00000000, 0x00208e46, 0x00000000, 0x00000007,
0x00100e46, 0x00000001, 0x05000036, 0x00102032, 0x00000001, 0x00101046,
0x00000001, 0x05000036, 0x001020f2, 0x00000002, 0x00101e46, 0x00000002,
0x0100003e, 0x54415453, 0x00000074, 0x0000000b, 0x00000002, 0x00000000,
0x00000006, 0x00000003, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x46454452, 0x000000fc, 0x00000001, 0x00000054,
0x00000001, 0x0000001c, 0xfffe0400, 0x00000100, 0x000000c6, 0x0000003c,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
0x00000001, 0x74726556, 0x68537865, 0x72656461, 0x736e6f43, 0x746e6174,
0xabab0073, 0x0000003c, 0x00000002, 0x0000006c, 0x00000080, 0x00000000,
0x00000000, 0x0000009c, 0x00000000, 0x00000040, 0x00000002, 0x000000a4,
0x00000000, 0x000000b4, 0x00000040, 0x00000040, 0x00000002, 0x000000a4,
0x00000000, 0x65646f6d, 0xabab006c, 0x00030002, 0x00040004, 0x00000000,
0x00000000, 0x6a6f7270, 0x69746365, 0x6e416e6f, 0x65695664, 0x694d0077,
0x736f7263, 0x2074666f, 0x20295228, 0x4c534c48, 0x61685320, 0x20726564,
0x706d6f43, 0x72656c69, 0x332e3920, 0x32392e30, 0x312e3030, 0x34383336,
0xababab00, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000707, 0x00000059,
0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000062,
0x00000000, 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x49534f50,
0x4e4f4954, 0x58455400, 0x524f4f43, 0x4f430044, 0x00524f4c, 0x4e47534f,
0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001,
0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
0x00000003, 0x00000001, 0x00000c03, 0x00000065, 0x00000000, 0x00000000,
0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
648
0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f
649
650
651
};
#elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3)
static const DWORD D3D11_VertexShader[] = {
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
0x43425844, 0x01a24e41, 0x696af551, 0x4b2a87d1, 0x82ea03f6, 0x00000001,
0x00000598, 0x00000006, 0x00000038, 0x0000016c, 0x00000334, 0x000003b0,
0x000004b4, 0x00000524, 0x396e6f41, 0x0000012c, 0x0000012c, 0xfffe0200,
0x000000f8, 0x00000034, 0x00240001, 0x00300000, 0x00300000, 0x00240000,
0x00300001, 0x00000000, 0x00010008, 0x00000000, 0x00000000, 0xfffe0201,
0x0200001f, 0x80000005, 0x900f0000, 0x0200001f, 0x80010005, 0x900f0001,
0x0200001f, 0x80020005, 0x900f0002, 0x03000005, 0x800f0000, 0x90550000,
0xa0e40002, 0x04000004, 0x800f0000, 0x90000000, 0xa0e40001, 0x80e40000,
0x04000004, 0x800f0000, 0x90aa0000, 0xa0e40003, 0x80e40000, 0x03000002,
0x800f0000, 0x80e40000, 0xa0e40004, 0x03000005, 0x800f0001, 0x80550000,
0xa0e40006, 0x04000004, 0x800f0001, 0x80000000, 0xa0e40005, 0x80e40001,
0x04000004, 0x800f0001, 0x80aa0000, 0xa0e40007, 0x80e40001, 0x04000004,
0x800f0000, 0x80ff0000, 0xa0e40008, 0x80e40001, 0x04000004, 0xc0030000,
0x80ff0000, 0xa0e40000, 0x80e40000, 0x02000001, 0xc00c0000, 0x80e40000,
0x02000001, 0xe0030000, 0x90e40001, 0x02000001, 0xe00f0001, 0x90e40002,
0x0000ffff, 0x52444853, 0x000001c0, 0x00010040, 0x00000070, 0x04000059,
0x00208e46, 0x00000000, 0x00000008, 0x0300005f, 0x00101072, 0x00000000,
0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x001010f2, 0x00000002,
0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102032,
0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000002,
0x08000038, 0x001000f2, 0x00000000, 0x00101556, 0x00000000, 0x00208e46,
0x00000000, 0x00000001, 0x0a000032, 0x001000f2, 0x00000000, 0x00101006,
0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
0x0a000032, 0x001000f2, 0x00000000, 0x00101aa6, 0x00000000, 0x00208e46,
0x00000000, 0x00000002, 0x00100e46, 0x00000000, 0x08000000, 0x001000f2,
0x00000000, 0x00100e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003,
0x08000038, 0x001000f2, 0x00000001, 0x00100556, 0x00000000, 0x00208e46,
0x00000000, 0x00000005, 0x0a000032, 0x001000f2, 0x00000001, 0x00100006,
0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x00100e46, 0x00000001,
0x0a000032, 0x001000f2, 0x00000001, 0x00100aa6, 0x00000000, 0x00208e46,
0x00000000, 0x00000006, 0x00100e46, 0x00000001, 0x0a000032, 0x001020f2,
0x00000000, 0x00100ff6, 0x00000000, 0x00208e46, 0x00000000, 0x00000007,
0x00100e46, 0x00000001, 0x05000036, 0x00102032, 0x00000001, 0x00101046,
0x00000001, 0x05000036, 0x001020f2, 0x00000002, 0x00101e46, 0x00000002,
0x0100003e, 0x54415453, 0x00000074, 0x0000000b, 0x00000002, 0x00000000,
0x00000006, 0x00000003, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x46454452, 0x000000fc, 0x00000001, 0x00000054,
0x00000001, 0x0000001c, 0xfffe0400, 0x00000100, 0x000000c6, 0x0000003c,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
0x00000001, 0x74726556, 0x68537865, 0x72656461, 0x736e6f43, 0x746e6174,
0xabab0073, 0x0000003c, 0x00000002, 0x0000006c, 0x00000080, 0x00000000,
0x00000000, 0x0000009c, 0x00000000, 0x00000040, 0x00000002, 0x000000a4,
0x00000000, 0x000000b4, 0x00000040, 0x00000040, 0x00000002, 0x000000a4,
0x00000000, 0x65646f6d, 0xabab006c, 0x00030002, 0x00040004, 0x00000000,
0x00000000, 0x6a6f7270, 0x69746365, 0x6e416e6f, 0x65695664, 0x694d0077,
0x736f7263, 0x2074666f, 0x20295228, 0x4c534c48, 0x61685320, 0x20726564,
0x706d6f43, 0x72656c69, 0x332e3920, 0x32392e30, 0x312e3030, 0x34383336,
0xababab00, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000707, 0x00000059,
0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000062,
0x00000000, 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x49534f50,
0x4e4f4954, 0x58455400, 0x524f4f43, 0x4f430044, 0x00524f4c, 0x4e47534f,
0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001,
0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
0x00000003, 0x00000001, 0x00000c03, 0x00000065, 0x00000000, 0x00000000,
0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f
712
713
714
715
716
};
#else
#error "An appropriate vertex shader is not defined."
#endif
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
/* Direct3D matrix math functions */
static Float4X4 MatrixIdentity()
{
Float4X4 m;
SDL_zero(m);
m._11 = 1.0f;
m._22 = 1.0f;
m._33 = 1.0f;
m._44 = 1.0f;
return m;
}
static Float4X4 MatrixMultiply(Float4X4 M1, Float4X4 M2)
{
Float4X4 m;
SDL_zero(m);
m._11 = M1._11 * M2._11 + M1._12 * M2._21 + M1._13 * M2._31 + M1._14 * M2._41;
m._12 = M1._11 * M2._12 + M1._12 * M2._22 + M1._13 * M2._32 + M1._14 * M2._42;
m._13 = M1._11 * M2._13 + M1._12 * M2._23 + M1._13 * M2._33 + M1._14 * M2._43;
m._14 = M1._11 * M2._14 + M1._12 * M2._24 + M1._13 * M2._34 + M1._14 * M2._44;
m._21 = M1._21 * M2._11 + M1._22 * M2._21 + M1._23 * M2._31 + M1._24 * M2._41;
m._22 = M1._21 * M2._12 + M1._22 * M2._22 + M1._23 * M2._32 + M1._24 * M2._42;
m._23 = M1._21 * M2._13 + M1._22 * M2._23 + M1._23 * M2._33 + M1._24 * M2._43;
m._24 = M1._21 * M2._14 + M1._22 * M2._24 + M1._23 * M2._34 + M1._24 * M2._44;
m._31 = M1._31 * M2._11 + M1._32 * M2._21 + M1._33 * M2._31 + M1._34 * M2._41;
m._32 = M1._31 * M2._12 + M1._32 * M2._22 + M1._33 * M2._32 + M1._34 * M2._42;
m._33 = M1._31 * M2._13 + M1._32 * M2._23 + M1._33 * M2._33 + M1._34 * M2._43;
m._34 = M1._31 * M2._14 + M1._32 * M2._24 + M1._33 * M2._34 + M1._34 * M2._44;
m._41 = M1._41 * M2._11 + M1._42 * M2._21 + M1._43 * M2._31 + M1._44 * M2._41;
m._42 = M1._41 * M2._12 + M1._42 * M2._22 + M1._43 * M2._32 + M1._44 * M2._42;
m._43 = M1._41 * M2._13 + M1._42 * M2._23 + M1._43 * M2._33 + M1._44 * M2._43;
m._44 = M1._41 * M2._14 + M1._42 * M2._24 + M1._43 * M2._34 + M1._44 * M2._44;
return m;
}
static Float4X4 MatrixScaling(float x, float y, float z)
{
Float4X4 m;
SDL_zero(m);
m._11 = x;
m._22 = y;
m._33 = z;
m._44 = 1.0f;
return m;
}
static Float4X4 MatrixTranslation(float x, float y, float z)
{
Float4X4 m;
SDL_zero(m);
m._11 = 1.0f;
m._22 = 1.0f;
m._33 = 1.0f;
m._44 = 1.0f;
m._41 = x;
m._42 = y;
m._43 = z;
return m;
}
static Float4X4 MatrixRotationX(float r)
{
float sinR = SDL_sinf(r);
float cosR = SDL_cosf(r);
Float4X4 m;
SDL_zero(m);
m._11 = 1.0f;
m._22 = cosR;
m._23 = sinR;
m._32 = -sinR;
m._33 = cosR;
m._44 = 1.0f;
return m;
}
static Float4X4 MatrixRotationY(float r)
{
float sinR = SDL_sinf(r);
float cosR = SDL_cosf(r);
Float4X4 m;
SDL_zero(m);
m._11 = cosR;
m._13 = -sinR;
m._22 = 1.0f;
m._31 = sinR;
m._33 = cosR;
m._44 = 1.0f;
return m;
}
static Float4X4 MatrixRotationZ(float r)
{
float sinR = SDL_sinf(r);
float cosR = SDL_cosf(r);
Float4X4 m;
SDL_zero(m);
m._11 = cosR;
m._12 = sinR;
m._21 = -sinR;
m._22 = cosR;
m._33 = 1.0f;
m._44 = 1.0f;
return m;
}
824
/* Direct3D 11.1 renderer implementation */
825
826
827
828
829
830
831
static SDL_Renderer *D3D11_CreateRenderer(SDL_Window * window, Uint32 flags);
static void D3D11_WindowEvent(SDL_Renderer * renderer,
const SDL_WindowEvent *event);
static int D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static int D3D11_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *srcPixels,
int srcPitch);
832
833
834
835
836
static int D3D11_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch);
837
838
839
840
841
static int D3D11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, void **pixels, int *pitch);
static void D3D11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static int D3D11_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture);
static int D3D11_UpdateViewport(SDL_Renderer * renderer);
842
static int D3D11_UpdateClipRect(SDL_Renderer * renderer);
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
static int D3D11_RenderClear(SDL_Renderer * renderer);
static int D3D11_RenderDrawPoints(SDL_Renderer * renderer,
const SDL_FPoint * points, int count);
static int D3D11_RenderDrawLines(SDL_Renderer * renderer,
const SDL_FPoint * points, int count);
static int D3D11_RenderFillRects(SDL_Renderer * renderer,
const SDL_FRect * rects, int count);
static int D3D11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_FRect * dstrect);
static int D3D11_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_FRect * dstrect,
const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip);
static int D3D11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, void * pixels, int pitch);
static void D3D11_RenderPresent(SDL_Renderer * renderer);
static void D3D11_DestroyTexture(SDL_Renderer * renderer,
SDL_Texture * texture);
static void D3D11_DestroyRenderer(SDL_Renderer * renderer);
/* Direct3D 11.1 Internal Functions */
863
864
865
866
867
static HRESULT D3D11_CreateDeviceResources(SDL_Renderer * renderer);
static HRESULT D3D11_CreateWindowSizeDependentResources(SDL_Renderer * renderer);
static HRESULT D3D11_UpdateForWindowSizeChange(SDL_Renderer * renderer);
static HRESULT D3D11_HandleDeviceLost(SDL_Renderer * renderer);
static void D3D11_ReleaseMainRenderTargetView(SDL_Renderer * renderer);
868
869
SDL_RenderDriver D3D11_RenderDriver = {
870
871
D3D11_CreateRenderer,
{
872
"direct3d11",
873
874
875
876
(
SDL_RENDERER_ACCELERATED |
SDL_RENDERER_PRESENTVSYNC |
SDL_RENDERER_TARGETTEXTURE
877
), /* flags. see SDL_RendererFlags */
878
4, /* num_texture_formats */
879
{ /* texture_formats */
880
SDL_PIXELFORMAT_ARGB8888,
881
SDL_PIXELFORMAT_RGB888,
882
883
SDL_PIXELFORMAT_YV12,
SDL_PIXELFORMAT_IYUV
884
},
885
886
0, /* max_texture_width: will be filled in later */
0 /* max_texture_height: will be filled in later */
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
}
};
static Uint32
DXGIFormatToSDLPixelFormat(DXGI_FORMAT dxgiFormat) {
switch (dxgiFormat) {
case DXGI_FORMAT_B8G8R8A8_UNORM:
return SDL_PIXELFORMAT_ARGB8888;
case DXGI_FORMAT_B8G8R8X8_UNORM:
return SDL_PIXELFORMAT_RGB888;
default:
return SDL_PIXELFORMAT_UNKNOWN;
}
}
static DXGI_FORMAT
SDLPixelFormatToDXGIFormat(Uint32 sdlFormat)
{
906
907
908
909
910
switch (sdlFormat) {
case SDL_PIXELFORMAT_ARGB8888:
return DXGI_FORMAT_B8G8R8A8_UNORM;
case SDL_PIXELFORMAT_RGB888:
return DXGI_FORMAT_B8G8R8X8_UNORM;
911
912
913
case SDL_PIXELFORMAT_YV12:
case SDL_PIXELFORMAT_IYUV:
return DXGI_FORMAT_R8_UNORM;
914
915
916
default:
return DXGI_FORMAT_UNKNOWN;
}
917
}
918
919
920
921
922
923
924
925
926
927
928
929
930
SDL_Renderer *
D3D11_CreateRenderer(SDL_Window * window, Uint32 flags)
{
SDL_Renderer *renderer;
D3D11_RenderData *data;
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
if (!renderer) {
SDL_OutOfMemory();
return NULL;
}
931
data = (D3D11_RenderData *) SDL_calloc(1, sizeof(*data));
932
933
934
935
936
937
938
939
if (!data) {
SDL_OutOfMemory();
return NULL;
}
renderer->WindowEvent = D3D11_WindowEvent;
renderer->CreateTexture = D3D11_CreateTexture;
renderer->UpdateTexture = D3D11_UpdateTexture;
940
renderer->UpdateTextureYUV = D3D11_UpdateTextureYUV;
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
renderer->LockTexture = D3D11_LockTexture;
renderer->UnlockTexture = D3D11_UnlockTexture;
renderer->SetRenderTarget = D3D11_SetRenderTarget;
renderer->UpdateViewport = D3D11_UpdateViewport;
renderer->UpdateClipRect = D3D11_UpdateClipRect;
renderer->RenderClear = D3D11_RenderClear;
renderer->RenderDrawPoints = D3D11_RenderDrawPoints;
renderer->RenderDrawLines = D3D11_RenderDrawLines;
renderer->RenderFillRects = D3D11_RenderFillRects;
renderer->RenderCopy = D3D11_RenderCopy;
renderer->RenderCopyEx = D3D11_RenderCopyEx;
renderer->RenderReadPixels = D3D11_RenderReadPixels;
renderer->RenderPresent = D3D11_RenderPresent;
renderer->DestroyTexture = D3D11_DestroyTexture;
renderer->DestroyRenderer = D3D11_DestroyRenderer;
renderer->info = D3D11_RenderDriver.info;
957
renderer->info.flags = (SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
958
959
renderer->driverdata = data;
960
961
962
963
964
965
966
if ((flags & SDL_RENDERER_PRESENTVSYNC)) {
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
}
/* HACK: make sure the SDL_Renderer references the SDL_Window data now, in
* order to give init functions access to the underlying window handle:
*/
967
968
969
970
971
972
973
974
975
976
977
978
979
renderer->window = window;
/* Initialize Direct3D resources */
if (FAILED(D3D11_CreateDeviceResources(renderer))) {
D3D11_DestroyRenderer(renderer);
return NULL;
}
if (FAILED(D3D11_CreateWindowSizeDependentResources(renderer))) {
D3D11_DestroyRenderer(renderer);
return NULL;
}
return renderer;
980
981
982
983
984
985
}
static void
D3D11_DestroyRenderer(SDL_Renderer * renderer)
{
D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
986
987
if (data) {
988
989
990
991
992
993
994
995
996
SAFE_RELEASE(data->d3dDevice);
SAFE_RELEASE(data->d3dContext);
SAFE_RELEASE(data->swapChain);
SAFE_RELEASE(data->mainRenderTargetView);
SAFE_RELEASE(data->currentOffscreenRenderTargetView);
SAFE_RELEASE(data->inputLayout);
SAFE_RELEASE(data->vertexBuffer);
SAFE_RELEASE(data->vertexShader);
SAFE_RELEASE(data->colorPixelShader);
997
998
SAFE_RELEASE(data->texturePixelShader);
SAFE_RELEASE(data->yuvPixelShader);
999
1000
SAFE_RELEASE(data->blendModeBlend);
SAFE_RELEASE(data->blendModeAdd);