2 * Copyright 2011 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
20 #include "d3d10_private.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(d3d10
);
24 struct d3d10_stateblock
26 ID3D10StateBlock ID3D10StateBlock_iface
;
30 D3D10_STATE_BLOCK_MASK mask
;
32 ID3D10VertexShader
*vs
;
33 ID3D10SamplerState
*vs_samplers
[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT
];
34 ID3D10ShaderResourceView
*vs_resources
[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT
];
35 ID3D10Buffer
*vs_cbs
[D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT
];
36 ID3D10GeometryShader
*gs
;
37 ID3D10SamplerState
*gs_samplers
[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT
];
38 ID3D10ShaderResourceView
*gs_resources
[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT
];
39 ID3D10Buffer
*gs_cbs
[D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT
];
40 ID3D10PixelShader
*ps
;
41 ID3D10SamplerState
*ps_samplers
[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT
];
42 ID3D10ShaderResourceView
*ps_resources
[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT
];
43 ID3D10Buffer
*ps_cbs
[D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT
];
44 ID3D10Buffer
*vbs
[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT
];
45 UINT vb_strides
[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT
];
46 UINT vb_offsets
[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT
];
48 DXGI_FORMAT ib_format
;
50 ID3D10InputLayout
*il
;
51 D3D10_PRIMITIVE_TOPOLOGY topology
;
52 ID3D10RenderTargetView
*rtvs
[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT
];
53 ID3D10DepthStencilView
*dsv
;
54 ID3D10DepthStencilState
*dss
;
57 float blend_factor
[4];
59 D3D10_VIEWPORT vps
[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE
];
60 D3D10_RECT scissor_rects
[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE
];
61 ID3D10RasterizerState
*rs
;
62 ID3D10Buffer
*so_buffers
[D3D10_SO_BUFFER_SLOT_COUNT
];
63 UINT so_offsets
[D3D10_SO_BUFFER_SLOT_COUNT
];
64 ID3D10Predicate
*predicate
;
68 #define WINE_D3D10_TO_STR(x) case x: return #x
70 static const char *debug_d3d10_device_state_types(D3D10_DEVICE_STATE_TYPES t
)
74 WINE_D3D10_TO_STR(D3D10_DST_SO_BUFFERS
);
75 WINE_D3D10_TO_STR(D3D10_DST_OM_RENDER_TARGETS
);
76 WINE_D3D10_TO_STR(D3D10_DST_DEPTH_STENCIL_STATE
);
77 WINE_D3D10_TO_STR(D3D10_DST_BLEND_STATE
);
78 WINE_D3D10_TO_STR(D3D10_DST_VS
);
79 WINE_D3D10_TO_STR(D3D10_DST_VS_SAMPLERS
);
80 WINE_D3D10_TO_STR(D3D10_DST_VS_SHADER_RESOURCES
);
81 WINE_D3D10_TO_STR(D3D10_DST_VS_CONSTANT_BUFFERS
);
82 WINE_D3D10_TO_STR(D3D10_DST_GS
);
83 WINE_D3D10_TO_STR(D3D10_DST_GS_SAMPLERS
);
84 WINE_D3D10_TO_STR(D3D10_DST_GS_SHADER_RESOURCES
);
85 WINE_D3D10_TO_STR(D3D10_DST_GS_CONSTANT_BUFFERS
);
86 WINE_D3D10_TO_STR(D3D10_DST_PS
);
87 WINE_D3D10_TO_STR(D3D10_DST_PS_SAMPLERS
);
88 WINE_D3D10_TO_STR(D3D10_DST_PS_SHADER_RESOURCES
);
89 WINE_D3D10_TO_STR(D3D10_DST_PS_CONSTANT_BUFFERS
);
90 WINE_D3D10_TO_STR(D3D10_DST_IA_VERTEX_BUFFERS
);
91 WINE_D3D10_TO_STR(D3D10_DST_IA_INDEX_BUFFER
);
92 WINE_D3D10_TO_STR(D3D10_DST_IA_INPUT_LAYOUT
);
93 WINE_D3D10_TO_STR(D3D10_DST_IA_PRIMITIVE_TOPOLOGY
);
94 WINE_D3D10_TO_STR(D3D10_DST_RS_VIEWPORTS
);
95 WINE_D3D10_TO_STR(D3D10_DST_RS_SCISSOR_RECTS
);
96 WINE_D3D10_TO_STR(D3D10_DST_RS_RASTERIZER_STATE
);
97 WINE_D3D10_TO_STR(D3D10_DST_PREDICATION
);
99 FIXME("Unrecognised D3D10_DEVICE_STATE_TYPES %#x.\n", t
);
100 return "unrecognised";
104 #undef WINE_D3D10_TO_STR
106 static inline struct d3d10_stateblock
*impl_from_ID3D10StateBlock(ID3D10StateBlock
*iface
)
108 return CONTAINING_RECORD(iface
, struct d3d10_stateblock
, ID3D10StateBlock_iface
);
111 static void stateblock_cleanup(struct d3d10_stateblock
*stateblock
)
117 ID3D10VertexShader_Release(stateblock
->vs
);
118 stateblock
->vs
= NULL
;
120 for (i
= 0; i
< D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT
; ++i
)
122 if (stateblock
->vs_samplers
[i
])
124 ID3D10SamplerState_Release(stateblock
->vs_samplers
[i
]);
125 stateblock
->vs_samplers
[i
] = NULL
;
128 for (i
= 0; i
< D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT
; ++i
)
130 if (stateblock
->vs_resources
[i
])
132 ID3D10ShaderResourceView_Release(stateblock
->vs_resources
[i
]);
133 stateblock
->vs_resources
[i
] = NULL
;
136 for (i
= 0; i
< D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT
; ++i
)
138 if (stateblock
->vs_cbs
[i
])
140 ID3D10Buffer_Release(stateblock
->vs_cbs
[i
]);
141 stateblock
->vs_cbs
[i
] = NULL
;
147 ID3D10GeometryShader_Release(stateblock
->gs
);
148 stateblock
->gs
= NULL
;
150 for (i
= 0; i
< D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT
; ++i
)
152 if (stateblock
->gs_samplers
[i
])
154 ID3D10SamplerState_Release(stateblock
->gs_samplers
[i
]);
155 stateblock
->gs_samplers
[i
] = NULL
;
158 for (i
= 0; i
< D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT
; ++i
)
160 if (stateblock
->gs_resources
[i
])
162 ID3D10ShaderResourceView_Release(stateblock
->gs_resources
[i
]);
163 stateblock
->gs_resources
[i
] = NULL
;
166 for (i
= 0; i
< D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT
; ++i
)
168 if (stateblock
->gs_cbs
[i
])
170 ID3D10Buffer_Release(stateblock
->gs_cbs
[i
]);
171 stateblock
->gs_cbs
[i
] = NULL
;
177 ID3D10PixelShader_Release(stateblock
->ps
);
178 stateblock
->ps
= NULL
;
180 for (i
= 0; i
< D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT
; ++i
)
182 if (stateblock
->ps_samplers
[i
])
184 ID3D10SamplerState_Release(stateblock
->ps_samplers
[i
]);
185 stateblock
->ps_samplers
[i
] = NULL
;
188 for (i
= 0; i
< D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT
; ++i
)
190 if (stateblock
->ps_resources
[i
])
192 ID3D10ShaderResourceView_Release(stateblock
->ps_resources
[i
]);
193 stateblock
->ps_resources
[i
] = NULL
;
196 for (i
= 0; i
< D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT
; ++i
)
198 if (stateblock
->ps_cbs
[i
])
200 ID3D10Buffer_Release(stateblock
->ps_cbs
[i
]);
201 stateblock
->ps_cbs
[i
] = NULL
;
205 for (i
= 0; i
< D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT
; ++i
)
207 if (stateblock
->vbs
[i
])
209 ID3D10Buffer_Release(stateblock
->vbs
[i
]);
210 stateblock
->vbs
[i
] = NULL
;
215 ID3D10Buffer_Release(stateblock
->ib
);
216 stateblock
->ib
= NULL
;
220 ID3D10InputLayout_Release(stateblock
->il
);
221 stateblock
->il
= NULL
;
224 for (i
= 0; i
< D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT
; ++i
)
226 if (stateblock
->rtvs
[i
])
228 ID3D10RenderTargetView_Release(stateblock
->rtvs
[i
]);
229 stateblock
->rtvs
[i
] = NULL
;
234 ID3D10DepthStencilView_Release(stateblock
->dsv
);
235 stateblock
->dsv
= NULL
;
239 ID3D10DepthStencilState_Release(stateblock
->dss
);
240 stateblock
->dss
= NULL
;
244 ID3D10BlendState_Release(stateblock
->bs
);
245 stateblock
->bs
= NULL
;
250 ID3D10RasterizerState_Release(stateblock
->rs
);
251 stateblock
->rs
= NULL
;
254 for (i
= 0; i
< D3D10_SO_BUFFER_SLOT_COUNT
; ++i
)
256 if (stateblock
->so_buffers
[i
])
258 ID3D10Buffer_Release(stateblock
->so_buffers
[i
]);
259 stateblock
->so_buffers
[i
] = NULL
;
263 if (stateblock
->predicate
)
265 ID3D10Predicate_Release(stateblock
->predicate
);
266 stateblock
->predicate
= NULL
;
270 static HRESULT STDMETHODCALLTYPE
d3d10_stateblock_QueryInterface(ID3D10StateBlock
*iface
, REFIID iid
, void **object
)
272 struct d3d10_stateblock
*stateblock
;
274 TRACE("iface %p, iid %s, object %p.\n", iface
, debugstr_guid(iid
), object
);
276 stateblock
= impl_from_ID3D10StateBlock(iface
);
278 if (IsEqualGUID(iid
, &IID_ID3D10StateBlock
)
279 || IsEqualGUID(iid
, &IID_IUnknown
))
281 IUnknown_AddRef(&stateblock
->ID3D10StateBlock_iface
);
282 *object
= &stateblock
->ID3D10StateBlock_iface
;
286 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
289 return E_NOINTERFACE
;
292 static ULONG STDMETHODCALLTYPE
d3d10_stateblock_AddRef(ID3D10StateBlock
*iface
)
294 struct d3d10_stateblock
*stateblock
= impl_from_ID3D10StateBlock(iface
);
295 ULONG refcount
= InterlockedIncrement(&stateblock
->refcount
);
297 TRACE("%p increasing refcount to %u.\n", stateblock
, refcount
);
302 static ULONG STDMETHODCALLTYPE
d3d10_stateblock_Release(ID3D10StateBlock
*iface
)
304 struct d3d10_stateblock
*stateblock
= impl_from_ID3D10StateBlock(iface
);
305 ULONG refcount
= InterlockedDecrement(&stateblock
->refcount
);
307 TRACE("%p decreasing refcount to %u.\n", stateblock
, refcount
);
311 stateblock_cleanup(stateblock
);
312 ID3D10Device_Release(stateblock
->device
);
313 heap_free(stateblock
);
319 static HRESULT STDMETHODCALLTYPE
d3d10_stateblock_Capture(ID3D10StateBlock
*iface
)
321 unsigned int vp_count
= D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE
;
322 struct d3d10_stateblock
*stateblock
= impl_from_ID3D10StateBlock(iface
);
325 TRACE("iface %p.\n", iface
);
327 stateblock_cleanup(stateblock
);
329 if (stateblock
->mask
.VS
)
330 ID3D10Device_VSGetShader(stateblock
->device
, &stateblock
->vs
);
331 for (i
= 0; i
< D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT
; ++i
)
333 if (stateblock
->mask
.VSSamplers
[i
>> 3] & (1 << (i
& 7)))
334 ID3D10Device_VSGetSamplers(stateblock
->device
, i
, 1, &stateblock
->vs_samplers
[i
]);
336 for (i
= 0; i
< D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT
; ++i
)
338 if (stateblock
->mask
.VSShaderResources
[i
>> 3] & (1 << (i
& 7)))
339 ID3D10Device_VSGetShaderResources(stateblock
->device
, i
, 1, &stateblock
->vs_resources
[i
]);
341 for (i
= 0; i
< D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT
; ++i
)
343 if (stateblock
->mask
.VSConstantBuffers
[i
>> 3] & (1 << (i
& 7)))
344 ID3D10Device_VSGetConstantBuffers(stateblock
->device
, i
, 1, &stateblock
->vs_cbs
[i
]);
347 if (stateblock
->mask
.GS
)
348 ID3D10Device_GSGetShader(stateblock
->device
, &stateblock
->gs
);
349 for (i
= 0; i
< D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT
; ++i
)
351 if (stateblock
->mask
.GSSamplers
[i
>> 3] & (1 << (i
& 7)))
352 ID3D10Device_GSGetSamplers(stateblock
->device
, i
, 1, &stateblock
->gs_samplers
[i
]);
354 for (i
= 0; i
< D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT
; ++i
)
356 if (stateblock
->mask
.GSShaderResources
[i
>> 3] & (1 << (i
& 7)))
357 ID3D10Device_GSGetShaderResources(stateblock
->device
, i
, 1, &stateblock
->gs_resources
[i
]);
359 for (i
= 0; i
< D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT
; ++i
)
361 if (stateblock
->mask
.GSConstantBuffers
[i
>> 3] & (1 << (i
& 7)))
362 ID3D10Device_GSGetConstantBuffers(stateblock
->device
, i
, 1, &stateblock
->gs_cbs
[i
]);
365 if (stateblock
->mask
.PS
)
366 ID3D10Device_PSGetShader(stateblock
->device
, &stateblock
->ps
);
367 for (i
= 0; i
< D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT
; ++i
)
369 if (stateblock
->mask
.PSSamplers
[i
>> 3] & (1 << (i
& 7)))
370 ID3D10Device_PSGetSamplers(stateblock
->device
, i
, 1, &stateblock
->ps_samplers
[i
]);
372 for (i
= 0; i
< D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT
; ++i
)
374 if (stateblock
->mask
.PSShaderResources
[i
>> 3] & (1 << (i
& 7)))
375 ID3D10Device_PSGetShaderResources(stateblock
->device
, i
, 1, &stateblock
->ps_resources
[i
]);
377 for (i
= 0; i
< D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT
; ++i
)
379 if (stateblock
->mask
.PSConstantBuffers
[i
>> 3] & (1 << (i
& 7)))
380 ID3D10Device_PSGetConstantBuffers(stateblock
->device
, i
, 1, &stateblock
->ps_cbs
[i
]);
383 for (i
= 0; i
< D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT
; ++i
)
385 if (stateblock
->mask
.IAVertexBuffers
[i
>> 3] & (1 << (i
& 7)))
386 ID3D10Device_IAGetVertexBuffers(stateblock
->device
, i
, 1, &stateblock
->vbs
[i
],
387 &stateblock
->vb_strides
[i
], &stateblock
->vb_offsets
[i
]);
389 if (stateblock
->mask
.IAIndexBuffer
)
390 ID3D10Device_IAGetIndexBuffer(stateblock
->device
, &stateblock
->ib
,
391 &stateblock
->ib_format
, &stateblock
->ib_offset
);
392 if (stateblock
->mask
.IAInputLayout
)
393 ID3D10Device_IAGetInputLayout(stateblock
->device
, &stateblock
->il
);
394 if (stateblock
->mask
.IAPrimitiveTopology
)
395 ID3D10Device_IAGetPrimitiveTopology(stateblock
->device
, &stateblock
->topology
);
397 if (stateblock
->mask
.OMRenderTargets
)
398 ID3D10Device_OMGetRenderTargets(stateblock
->device
, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT
,
399 stateblock
->rtvs
, &stateblock
->dsv
);
400 if (stateblock
->mask
.OMDepthStencilState
)
401 ID3D10Device_OMGetDepthStencilState(stateblock
->device
, &stateblock
->dss
, &stateblock
->stencil_ref
);
402 if (stateblock
->mask
.OMBlendState
)
403 ID3D10Device_OMGetBlendState(stateblock
->device
, &stateblock
->bs
,
404 stateblock
->blend_factor
, &stateblock
->sample_mask
);
406 if (stateblock
->mask
.RSViewports
)
407 ID3D10Device_RSGetViewports(stateblock
->device
, &vp_count
, stateblock
->vps
);
408 if (stateblock
->mask
.RSScissorRects
)
409 ID3D10Device_RSGetScissorRects(stateblock
->device
, &vp_count
, stateblock
->scissor_rects
);
410 if (stateblock
->mask
.RSRasterizerState
)
411 ID3D10Device_RSGetState(stateblock
->device
, &stateblock
->rs
);
413 if (stateblock
->mask
.SOBuffers
)
414 ID3D10Device_SOGetTargets(stateblock
->device
, D3D10_SO_BUFFER_SLOT_COUNT
,
415 stateblock
->so_buffers
, stateblock
->so_offsets
);
417 if (stateblock
->mask
.Predication
)
418 ID3D10Device_GetPredication(stateblock
->device
, &stateblock
->predicate
, &stateblock
->predicate_value
);
423 static HRESULT STDMETHODCALLTYPE
d3d10_stateblock_Apply(ID3D10StateBlock
*iface
)
425 struct d3d10_stateblock
*stateblock
= impl_from_ID3D10StateBlock(iface
);
428 TRACE("iface %p.\n", iface
);
430 if (stateblock
->mask
.VS
)
431 ID3D10Device_VSSetShader(stateblock
->device
, stateblock
->vs
);
432 for (i
= 0; i
< D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT
; ++i
)
434 if (stateblock
->mask
.VSSamplers
[i
>> 3] & (1 << (i
& 7)))
435 ID3D10Device_VSSetSamplers(stateblock
->device
, i
, 1, &stateblock
->vs_samplers
[i
]);
437 for (i
= 0; i
< D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT
; ++i
)
439 if (stateblock
->mask
.VSShaderResources
[i
>> 3] & (1 << (i
& 7)))
440 ID3D10Device_VSSetShaderResources(stateblock
->device
, i
, 1, &stateblock
->vs_resources
[i
]);
442 for (i
= 0; i
< D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT
; ++i
)
444 if (stateblock
->mask
.VSConstantBuffers
[i
>> 3] & (1 << (i
& 7)))
445 ID3D10Device_VSSetConstantBuffers(stateblock
->device
, i
, 1, &stateblock
->vs_cbs
[i
]);
448 if (stateblock
->mask
.GS
)
449 ID3D10Device_GSSetShader(stateblock
->device
, stateblock
->gs
);
450 for (i
= 0; i
< D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT
; ++i
)
452 if (stateblock
->mask
.GSSamplers
[i
>> 3] & (1 << (i
& 7)))
453 ID3D10Device_GSSetSamplers(stateblock
->device
, i
, 1, &stateblock
->gs_samplers
[i
]);
455 for (i
= 0; i
< D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT
; ++i
)
457 if (stateblock
->mask
.GSShaderResources
[i
>> 3] & (1 << (i
& 7)))
458 ID3D10Device_GSSetShaderResources(stateblock
->device
, i
, 1, &stateblock
->gs_resources
[i
]);
460 for (i
= 0; i
< D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT
; ++i
)
462 if (stateblock
->mask
.GSConstantBuffers
[i
>> 3] & (1 << (i
& 7)))
463 ID3D10Device_GSSetConstantBuffers(stateblock
->device
, i
, 1, &stateblock
->gs_cbs
[i
]);
466 if (stateblock
->mask
.PS
)
467 ID3D10Device_PSSetShader(stateblock
->device
, stateblock
->ps
);
468 for (i
= 0; i
< D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT
; ++i
)
470 if (stateblock
->mask
.PSSamplers
[i
>> 3] & (1 << (i
& 7)))
471 ID3D10Device_PSSetSamplers(stateblock
->device
, i
, 1, &stateblock
->ps_samplers
[i
]);
473 for (i
= 0; i
< D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT
; ++i
)
475 if (stateblock
->mask
.PSShaderResources
[i
>> 3] & (1 << (i
& 7)))
476 ID3D10Device_PSSetShaderResources(stateblock
->device
, i
, 1, &stateblock
->ps_resources
[i
]);
478 for (i
= 0; i
< D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT
; ++i
)
480 if (stateblock
->mask
.PSConstantBuffers
[i
>> 3] & (1 << (i
& 7)))
481 ID3D10Device_PSSetConstantBuffers(stateblock
->device
, i
, 1, &stateblock
->ps_cbs
[i
]);
484 for (i
= 0; i
< D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT
; ++i
)
486 if (stateblock
->mask
.IAVertexBuffers
[i
>> 3] & (1 << (i
& 7)))
487 ID3D10Device_IASetVertexBuffers(stateblock
->device
, i
, 1, &stateblock
->vbs
[i
],
488 &stateblock
->vb_strides
[i
], &stateblock
->vb_offsets
[i
]);
490 if (stateblock
->mask
.IAIndexBuffer
)
491 ID3D10Device_IASetIndexBuffer(stateblock
->device
, stateblock
->ib
,
492 stateblock
->ib_format
, stateblock
->ib_offset
);
493 if (stateblock
->mask
.IAInputLayout
)
494 ID3D10Device_IASetInputLayout(stateblock
->device
, stateblock
->il
);
495 if (stateblock
->mask
.IAPrimitiveTopology
)
496 ID3D10Device_IASetPrimitiveTopology(stateblock
->device
, stateblock
->topology
);
498 if (stateblock
->mask
.OMRenderTargets
)
499 ID3D10Device_OMSetRenderTargets(stateblock
->device
, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT
,
500 stateblock
->rtvs
, stateblock
->dsv
);
501 if (stateblock
->mask
.OMDepthStencilState
)
502 ID3D10Device_OMSetDepthStencilState(stateblock
->device
, stateblock
->dss
, stateblock
->stencil_ref
);
503 if (stateblock
->mask
.OMBlendState
)
504 ID3D10Device_OMSetBlendState(stateblock
->device
, stateblock
->bs
,
505 stateblock
->blend_factor
, stateblock
->sample_mask
);
507 if (stateblock
->mask
.RSViewports
)
508 ID3D10Device_RSSetViewports(stateblock
->device
, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE
,
510 if (stateblock
->mask
.RSScissorRects
)
511 ID3D10Device_RSSetScissorRects(stateblock
->device
, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE
,
512 stateblock
->scissor_rects
);
513 if (stateblock
->mask
.RSRasterizerState
)
514 ID3D10Device_RSSetState(stateblock
->device
, stateblock
->rs
);
516 if (stateblock
->mask
.SOBuffers
)
517 ID3D10Device_SOSetTargets(stateblock
->device
, D3D10_SO_BUFFER_SLOT_COUNT
,
518 stateblock
->so_buffers
, stateblock
->so_offsets
);
520 if (stateblock
->mask
.Predication
)
521 ID3D10Device_SetPredication(stateblock
->device
, stateblock
->predicate
, stateblock
->predicate_value
);
526 static HRESULT STDMETHODCALLTYPE
d3d10_stateblock_ReleaseAllDeviceObjects(ID3D10StateBlock
*iface
)
528 FIXME("iface %p stub!\n", iface
);
533 static HRESULT STDMETHODCALLTYPE
d3d10_stateblock_GetDevice(ID3D10StateBlock
*iface
, ID3D10Device
**device
)
535 FIXME("iface %p, device %p stub!\n", iface
, device
);
540 static const struct ID3D10StateBlockVtbl d3d10_stateblock_vtbl
=
542 /* IUnknown methods */
543 d3d10_stateblock_QueryInterface
,
544 d3d10_stateblock_AddRef
,
545 d3d10_stateblock_Release
,
546 /* ID3D10StateBlock methods */
547 d3d10_stateblock_Capture
,
548 d3d10_stateblock_Apply
,
549 d3d10_stateblock_ReleaseAllDeviceObjects
,
550 d3d10_stateblock_GetDevice
,
553 HRESULT WINAPI
D3D10CreateStateBlock(ID3D10Device
*device
,
554 D3D10_STATE_BLOCK_MASK
*mask
, ID3D10StateBlock
**stateblock
)
556 struct d3d10_stateblock
*object
;
558 TRACE("device %p, mask %p, stateblock %p.\n", device
, mask
, stateblock
);
560 if (!(object
= heap_alloc_zero(sizeof(*object
))))
562 ERR("Failed to allocate D3D10 stateblock object memory.\n");
563 return E_OUTOFMEMORY
;
566 object
->ID3D10StateBlock_iface
.lpVtbl
= &d3d10_stateblock_vtbl
;
567 object
->refcount
= 1;
569 object
->device
= device
;
570 ID3D10Device_AddRef(object
->device
);
571 object
->mask
= *mask
;
573 TRACE("Created stateblock %p.\n", object
);
574 *stateblock
= &object
->ID3D10StateBlock_iface
;
579 static BOOL
stateblock_mask_get_bit(BYTE
*field
, UINT field_size
, UINT idx
)
581 if (idx
>= field_size
)
584 return field
[idx
>> 3] & (1 << (idx
& 7));
587 static HRESULT
stateblock_mask_set_bits(BYTE
*field
, UINT field_size
, UINT start_bit
, UINT count
)
589 UINT end_bit
= start_bit
+ count
;
590 BYTE start_mask
= 0xff << (start_bit
& 7);
591 BYTE end_mask
= 0x7f >> (~end_bit
& 7);
592 UINT start_idx
= start_bit
>> 3;
593 UINT end_idx
= end_bit
>> 3;
595 if (start_bit
>= field_size
|| field_size
- start_bit
< count
)
598 if (start_idx
== end_idx
)
600 field
[start_idx
] |= start_mask
& end_mask
;
606 field
[start_idx
] |= start_mask
;
610 memset(&field
[start_idx
], 0xff, end_idx
- start_idx
);
613 field
[end_idx
] |= end_mask
;
618 static HRESULT
stateblock_mask_clear_bits(BYTE
*field
, UINT field_size
, UINT start_bit
, UINT count
)
620 UINT end_bit
= start_bit
+ count
;
621 BYTE start_mask
= 0x7f >> (~start_bit
& 7);
622 BYTE end_mask
= 0xff << (end_bit
& 7);
623 UINT start_idx
= start_bit
>> 3;
624 UINT end_idx
= end_bit
>> 3;
626 if (start_bit
>= field_size
|| field_size
- start_bit
< count
)
629 if (start_idx
== end_idx
)
631 field
[start_idx
] &= start_mask
| end_mask
;
637 field
[start_idx
] &= start_mask
;
641 memset(&field
[start_idx
], 0, end_idx
- start_idx
);
644 field
[end_idx
] &= end_mask
;
649 HRESULT WINAPI
D3D10StateBlockMaskDifference(D3D10_STATE_BLOCK_MASK
*mask_x
,
650 D3D10_STATE_BLOCK_MASK
*mask_y
, D3D10_STATE_BLOCK_MASK
*result
)
652 UINT count
= sizeof(*result
) / sizeof(DWORD
);
655 TRACE("mask_x %p, mask_y %p, result %p.\n", mask_x
, mask_y
, result
);
657 if (!mask_x
|| !mask_y
|| !result
)
660 for (i
= 0; i
< count
; ++i
)
662 ((DWORD
*)result
)[i
] = ((DWORD
*)mask_x
)[i
] ^ ((DWORD
*)mask_y
)[i
];
664 for (i
= count
* sizeof(DWORD
); i
< sizeof(*result
); ++i
)
666 ((BYTE
*)result
)[i
] = ((BYTE
*)mask_x
)[i
] ^ ((BYTE
*)mask_y
)[i
];
672 HRESULT WINAPI
D3D10StateBlockMaskDisableAll(D3D10_STATE_BLOCK_MASK
*mask
)
674 TRACE("mask %p.\n", mask
);
679 memset(mask
, 0, sizeof(*mask
));
684 HRESULT WINAPI
D3D10StateBlockMaskDisableCapture(D3D10_STATE_BLOCK_MASK
*mask
,
685 D3D10_DEVICE_STATE_TYPES state_type
, UINT start_idx
, UINT count
)
687 TRACE("mask %p state_type %s, start_idx %u, count %u.\n",
688 mask
, debug_d3d10_device_state_types(state_type
), start_idx
, count
);
695 case D3D10_DST_SO_BUFFERS
:
696 return stateblock_mask_clear_bits(&mask
->SOBuffers
, 1, start_idx
, count
);
697 case D3D10_DST_OM_RENDER_TARGETS
:
698 return stateblock_mask_clear_bits(&mask
->OMRenderTargets
, 1, start_idx
, count
);
699 case D3D10_DST_DEPTH_STENCIL_STATE
:
700 return stateblock_mask_clear_bits(&mask
->OMDepthStencilState
, 1, start_idx
, count
);
701 case D3D10_DST_BLEND_STATE
:
702 return stateblock_mask_clear_bits(&mask
->OMBlendState
, 1, start_idx
, count
);
704 return stateblock_mask_clear_bits(&mask
->VS
, 1, start_idx
, count
);
705 case D3D10_DST_VS_SAMPLERS
:
706 return stateblock_mask_clear_bits(mask
->VSSamplers
,
707 D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT
, start_idx
, count
);
708 case D3D10_DST_VS_SHADER_RESOURCES
:
709 return stateblock_mask_clear_bits(mask
->VSShaderResources
,
710 D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT
, start_idx
, count
);
711 case D3D10_DST_VS_CONSTANT_BUFFERS
:
712 return stateblock_mask_clear_bits(mask
->VSConstantBuffers
,
713 D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT
, start_idx
, count
);
715 return stateblock_mask_clear_bits(&mask
->GS
, 1, start_idx
, count
);
716 case D3D10_DST_GS_SAMPLERS
:
717 return stateblock_mask_clear_bits(mask
->GSSamplers
,
718 D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT
, start_idx
, count
);
719 case D3D10_DST_GS_SHADER_RESOURCES
:
720 return stateblock_mask_clear_bits(mask
->GSShaderResources
,
721 D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT
, start_idx
, count
);
722 case D3D10_DST_GS_CONSTANT_BUFFERS
:
723 return stateblock_mask_clear_bits(mask
->GSConstantBuffers
,
724 D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT
, start_idx
, count
);
726 return stateblock_mask_clear_bits(&mask
->PS
, 1, start_idx
, count
);
727 case D3D10_DST_PS_SAMPLERS
:
728 return stateblock_mask_clear_bits(mask
->PSSamplers
,
729 D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT
, start_idx
, count
);
730 case D3D10_DST_PS_SHADER_RESOURCES
:
731 return stateblock_mask_clear_bits(mask
->PSShaderResources
,
732 D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT
, start_idx
, count
);
733 case D3D10_DST_PS_CONSTANT_BUFFERS
:
734 return stateblock_mask_clear_bits(mask
->PSConstantBuffers
,
735 D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT
, start_idx
, count
);
736 case D3D10_DST_IA_VERTEX_BUFFERS
:
737 return stateblock_mask_clear_bits(mask
->IAVertexBuffers
,
738 D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT
, start_idx
, count
);
739 case D3D10_DST_IA_INDEX_BUFFER
:
740 return stateblock_mask_clear_bits(&mask
->IAIndexBuffer
, 1, start_idx
, count
);
741 case D3D10_DST_IA_INPUT_LAYOUT
:
742 return stateblock_mask_clear_bits(&mask
->IAInputLayout
, 1, start_idx
, count
);
743 case D3D10_DST_IA_PRIMITIVE_TOPOLOGY
:
744 return stateblock_mask_clear_bits(&mask
->IAPrimitiveTopology
, 1, start_idx
, count
);
745 case D3D10_DST_RS_VIEWPORTS
:
746 return stateblock_mask_clear_bits(&mask
->RSViewports
, 1, start_idx
, count
);
747 case D3D10_DST_RS_SCISSOR_RECTS
:
748 return stateblock_mask_clear_bits(&mask
->RSScissorRects
, 1, start_idx
, count
);
749 case D3D10_DST_RS_RASTERIZER_STATE
:
750 return stateblock_mask_clear_bits(&mask
->RSRasterizerState
, 1, start_idx
, count
);
751 case D3D10_DST_PREDICATION
:
752 return stateblock_mask_clear_bits(&mask
->Predication
, 1, start_idx
, count
);
754 FIXME("Unhandled state_type %#x.\n", state_type
);
759 HRESULT WINAPI
D3D10StateBlockMaskEnableAll(D3D10_STATE_BLOCK_MASK
*mask
)
761 TRACE("mask %p.\n", mask
);
766 memset(mask
, 0xff, sizeof(*mask
));
771 HRESULT WINAPI
D3D10StateBlockMaskEnableCapture(D3D10_STATE_BLOCK_MASK
*mask
,
772 D3D10_DEVICE_STATE_TYPES state_type
, UINT start_idx
, UINT count
)
774 TRACE("mask %p state_type %s, start_idx %u, count %u.\n",
775 mask
, debug_d3d10_device_state_types(state_type
), start_idx
, count
);
782 case D3D10_DST_SO_BUFFERS
:
783 return stateblock_mask_set_bits(&mask
->SOBuffers
, 1, start_idx
, count
);
784 case D3D10_DST_OM_RENDER_TARGETS
:
785 return stateblock_mask_set_bits(&mask
->OMRenderTargets
, 1, start_idx
, count
);
786 case D3D10_DST_DEPTH_STENCIL_STATE
:
787 return stateblock_mask_set_bits(&mask
->OMDepthStencilState
, 1, start_idx
, count
);
788 case D3D10_DST_BLEND_STATE
:
789 return stateblock_mask_set_bits(&mask
->OMBlendState
, 1, start_idx
, count
);
791 return stateblock_mask_set_bits(&mask
->VS
, 1, start_idx
, count
);
792 case D3D10_DST_VS_SAMPLERS
:
793 return stateblock_mask_set_bits(mask
->VSSamplers
,
794 D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT
, start_idx
, count
);
795 case D3D10_DST_VS_SHADER_RESOURCES
:
796 return stateblock_mask_set_bits(mask
->VSShaderResources
,
797 D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT
, start_idx
, count
);
798 case D3D10_DST_VS_CONSTANT_BUFFERS
:
799 return stateblock_mask_set_bits(mask
->VSConstantBuffers
,
800 D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT
, start_idx
, count
);
802 return stateblock_mask_set_bits(&mask
->GS
, 1, start_idx
, count
);
803 case D3D10_DST_GS_SAMPLERS
:
804 return stateblock_mask_set_bits(mask
->GSSamplers
,
805 D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT
, start_idx
, count
);
806 case D3D10_DST_GS_SHADER_RESOURCES
:
807 return stateblock_mask_set_bits(mask
->GSShaderResources
,
808 D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT
, start_idx
, count
);
809 case D3D10_DST_GS_CONSTANT_BUFFERS
:
810 return stateblock_mask_set_bits(mask
->GSConstantBuffers
,
811 D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT
, start_idx
, count
);
813 return stateblock_mask_set_bits(&mask
->PS
, 1, start_idx
, count
);
814 case D3D10_DST_PS_SAMPLERS
:
815 return stateblock_mask_set_bits(mask
->PSSamplers
,
816 D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT
, start_idx
, count
);
817 case D3D10_DST_PS_SHADER_RESOURCES
:
818 return stateblock_mask_set_bits(mask
->PSShaderResources
,
819 D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT
, start_idx
, count
);
820 case D3D10_DST_PS_CONSTANT_BUFFERS
:
821 return stateblock_mask_set_bits(mask
->PSConstantBuffers
,
822 D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT
, start_idx
, count
);
823 case D3D10_DST_IA_VERTEX_BUFFERS
:
824 return stateblock_mask_set_bits(mask
->IAVertexBuffers
,
825 D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT
, start_idx
, count
);
826 case D3D10_DST_IA_INDEX_BUFFER
:
827 return stateblock_mask_set_bits(&mask
->IAIndexBuffer
, 1, start_idx
, count
);
828 case D3D10_DST_IA_INPUT_LAYOUT
:
829 return stateblock_mask_set_bits(&mask
->IAInputLayout
, 1, start_idx
, count
);
830 case D3D10_DST_IA_PRIMITIVE_TOPOLOGY
:
831 return stateblock_mask_set_bits(&mask
->IAPrimitiveTopology
, 1, start_idx
, count
);
832 case D3D10_DST_RS_VIEWPORTS
:
833 return stateblock_mask_set_bits(&mask
->RSViewports
, 1, start_idx
, count
);
834 case D3D10_DST_RS_SCISSOR_RECTS
:
835 return stateblock_mask_set_bits(&mask
->RSScissorRects
, 1, start_idx
, count
);
836 case D3D10_DST_RS_RASTERIZER_STATE
:
837 return stateblock_mask_set_bits(&mask
->RSRasterizerState
, 1, start_idx
, count
);
838 case D3D10_DST_PREDICATION
:
839 return stateblock_mask_set_bits(&mask
->Predication
, 1, start_idx
, count
);
841 FIXME("Unhandled state_type %#x.\n", state_type
);
846 BOOL WINAPI
D3D10StateBlockMaskGetSetting(D3D10_STATE_BLOCK_MASK
*mask
,
847 D3D10_DEVICE_STATE_TYPES state_type
, UINT idx
)
849 TRACE("mask %p state_type %s, idx %u.\n",
850 mask
, debug_d3d10_device_state_types(state_type
), idx
);
857 case D3D10_DST_SO_BUFFERS
:
858 return stateblock_mask_get_bit(&mask
->SOBuffers
, 1, idx
);
859 case D3D10_DST_OM_RENDER_TARGETS
:
860 return stateblock_mask_get_bit(&mask
->OMRenderTargets
, 1, idx
);
861 case D3D10_DST_DEPTH_STENCIL_STATE
:
862 return stateblock_mask_get_bit(&mask
->OMDepthStencilState
, 1, idx
);
863 case D3D10_DST_BLEND_STATE
:
864 return stateblock_mask_get_bit(&mask
->OMBlendState
, 1, idx
);
866 return stateblock_mask_get_bit(&mask
->VS
, 1, idx
);
867 case D3D10_DST_VS_SAMPLERS
:
868 return stateblock_mask_get_bit(mask
->VSSamplers
,
869 D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT
, idx
);
870 case D3D10_DST_VS_SHADER_RESOURCES
:
871 return stateblock_mask_get_bit(mask
->VSShaderResources
,
872 D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT
, idx
);
873 case D3D10_DST_VS_CONSTANT_BUFFERS
:
874 return stateblock_mask_get_bit(mask
->VSConstantBuffers
,
875 D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT
, idx
);
877 return stateblock_mask_get_bit(&mask
->GS
, 1, idx
);
878 case D3D10_DST_GS_SAMPLERS
:
879 return stateblock_mask_get_bit(mask
->GSSamplers
,
880 D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT
, idx
);
881 case D3D10_DST_GS_SHADER_RESOURCES
:
882 return stateblock_mask_get_bit(mask
->GSShaderResources
,
883 D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT
, idx
);
884 case D3D10_DST_GS_CONSTANT_BUFFERS
:
885 return stateblock_mask_get_bit(mask
->GSConstantBuffers
,
886 D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT
, idx
);
888 return stateblock_mask_get_bit(&mask
->PS
, 1, idx
);
889 case D3D10_DST_PS_SAMPLERS
:
890 return stateblock_mask_get_bit(mask
->PSSamplers
,
891 D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT
, idx
);
892 case D3D10_DST_PS_SHADER_RESOURCES
:
893 return stateblock_mask_get_bit(mask
->PSShaderResources
,
894 D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT
, idx
);
895 case D3D10_DST_PS_CONSTANT_BUFFERS
:
896 return stateblock_mask_get_bit(mask
->PSConstantBuffers
,
897 D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT
, idx
);
898 case D3D10_DST_IA_VERTEX_BUFFERS
:
899 return stateblock_mask_get_bit(mask
->IAVertexBuffers
,
900 D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT
, idx
);
901 case D3D10_DST_IA_INDEX_BUFFER
:
902 return stateblock_mask_get_bit(&mask
->IAIndexBuffer
, 1, idx
);
903 case D3D10_DST_IA_INPUT_LAYOUT
:
904 return stateblock_mask_get_bit(&mask
->IAInputLayout
, 1, idx
);
905 case D3D10_DST_IA_PRIMITIVE_TOPOLOGY
:
906 return stateblock_mask_get_bit(&mask
->IAPrimitiveTopology
, 1, idx
);
907 case D3D10_DST_RS_VIEWPORTS
:
908 return stateblock_mask_get_bit(&mask
->RSViewports
, 1, idx
);
909 case D3D10_DST_RS_SCISSOR_RECTS
:
910 return stateblock_mask_get_bit(&mask
->RSScissorRects
, 1, idx
);
911 case D3D10_DST_RS_RASTERIZER_STATE
:
912 return stateblock_mask_get_bit(&mask
->RSRasterizerState
, 1, idx
);
913 case D3D10_DST_PREDICATION
:
914 return stateblock_mask_get_bit(&mask
->Predication
, 1, idx
);
916 FIXME("Unhandled state_type %#x.\n", state_type
);
921 HRESULT WINAPI
D3D10StateBlockMaskIntersect(D3D10_STATE_BLOCK_MASK
*mask_x
,
922 D3D10_STATE_BLOCK_MASK
*mask_y
, D3D10_STATE_BLOCK_MASK
*result
)
924 UINT count
= sizeof(*result
) / sizeof(DWORD
);
927 TRACE("mask_x %p, mask_y %p, result %p.\n", mask_x
, mask_y
, result
);
929 if (!mask_x
|| !mask_y
|| !result
)
932 for (i
= 0; i
< count
; ++i
)
934 ((DWORD
*)result
)[i
] = ((DWORD
*)mask_x
)[i
] & ((DWORD
*)mask_y
)[i
];
936 for (i
= count
* sizeof(DWORD
); i
< sizeof(*result
); ++i
)
938 ((BYTE
*)result
)[i
] = ((BYTE
*)mask_x
)[i
] & ((BYTE
*)mask_y
)[i
];
944 HRESULT WINAPI
D3D10StateBlockMaskUnion(D3D10_STATE_BLOCK_MASK
*mask_x
,
945 D3D10_STATE_BLOCK_MASK
*mask_y
, D3D10_STATE_BLOCK_MASK
*result
)
947 UINT count
= sizeof(*result
) / sizeof(DWORD
);
950 TRACE("mask_x %p, mask_y %p, result %p.\n", mask_x
, mask_y
, result
);
952 if (!mask_x
|| !mask_y
|| !result
)
955 for (i
= 0; i
< count
; ++i
)
957 ((DWORD
*)result
)[i
] = ((DWORD
*)mask_x
)[i
] | ((DWORD
*)mask_y
)[i
];
959 for (i
= count
* sizeof(DWORD
); i
< sizeof(*result
); ++i
)
961 ((BYTE
*)result
)[i
] = ((BYTE
*)mask_x
)[i
] | ((BYTE
*)mask_y
)[i
];