CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/GPU/D3D11/StateMappingD3D11.cpp
Views: 1401
1
// Copyright (c) 2012- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#include <d3d11.h>
19
#include <d3d11_1.h>
20
21
#include <algorithm>
22
23
#include "Common/Data/Convert/SmallDataConvert.h"
24
25
#include "GPU/Math3D.h"
26
#include "GPU/GPUState.h"
27
#include "GPU/ge_constants.h"
28
#include "GPU/Common/GPUStateUtils.h"
29
#include "Core/System.h"
30
#include "Core/Config.h"
31
32
#include "GPU/Common/FramebufferManagerCommon.h"
33
#include "GPU/D3D11/DrawEngineD3D11.h"
34
#include "GPU/D3D11/StateMappingD3D11.h"
35
#include "GPU/D3D11/FramebufferManagerD3D11.h"
36
#include "GPU/D3D11/TextureCacheD3D11.h"
37
38
// These tables all fit into u8s.
39
static const D3D11_BLEND d3d11BlendFactorLookup[(size_t)BlendFactor::COUNT] = {
40
D3D11_BLEND_ZERO,
41
D3D11_BLEND_ONE,
42
D3D11_BLEND_SRC_COLOR,
43
D3D11_BLEND_INV_SRC_COLOR,
44
D3D11_BLEND_DEST_COLOR,
45
D3D11_BLEND_INV_DEST_COLOR,
46
D3D11_BLEND_SRC_ALPHA,
47
D3D11_BLEND_INV_SRC_ALPHA,
48
D3D11_BLEND_DEST_ALPHA,
49
D3D11_BLEND_INV_DEST_ALPHA,
50
D3D11_BLEND_BLEND_FACTOR,
51
D3D11_BLEND_INV_BLEND_FACTOR,
52
D3D11_BLEND_BLEND_FACTOR,
53
D3D11_BLEND_INV_BLEND_FACTOR,
54
D3D11_BLEND_SRC1_COLOR,
55
D3D11_BLEND_INV_SRC1_COLOR,
56
D3D11_BLEND_SRC1_ALPHA,
57
D3D11_BLEND_INV_SRC1_ALPHA,
58
};
59
60
static const D3D11_BLEND_OP d3d11BlendEqLookup[(size_t)BlendEq::COUNT] = {
61
D3D11_BLEND_OP_ADD,
62
D3D11_BLEND_OP_SUBTRACT,
63
D3D11_BLEND_OP_REV_SUBTRACT,
64
D3D11_BLEND_OP_MIN,
65
D3D11_BLEND_OP_MAX,
66
};
67
68
static const D3D11_CULL_MODE cullingMode[] = {
69
D3D11_CULL_BACK,
70
D3D11_CULL_FRONT,
71
};
72
73
static const D3D11_COMPARISON_FUNC compareOps[] = {
74
D3D11_COMPARISON_NEVER,
75
D3D11_COMPARISON_ALWAYS,
76
D3D11_COMPARISON_EQUAL,
77
D3D11_COMPARISON_NOT_EQUAL,
78
D3D11_COMPARISON_LESS,
79
D3D11_COMPARISON_LESS_EQUAL,
80
D3D11_COMPARISON_GREATER,
81
D3D11_COMPARISON_GREATER_EQUAL,
82
};
83
84
static const D3D11_STENCIL_OP stencilOps[] = {
85
D3D11_STENCIL_OP_KEEP,
86
D3D11_STENCIL_OP_ZERO,
87
D3D11_STENCIL_OP_REPLACE,
88
D3D11_STENCIL_OP_INVERT,
89
D3D11_STENCIL_OP_INCR_SAT,
90
D3D11_STENCIL_OP_DECR_SAT,
91
D3D11_STENCIL_OP_KEEP, // reserved
92
D3D11_STENCIL_OP_KEEP, // reserved
93
};
94
95
static const D3D11_PRIMITIVE_TOPOLOGY primToD3D11[8] = {
96
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, // Points are expanded to triangles.
97
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, // Lines are expanded to triangles too.
98
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, // Lines are expanded to triangles too.
99
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST,
100
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP,
101
D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, // D3D11 doesn't do triangle fans.
102
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, // Rectangles are expanded to triangles.
103
};
104
105
static const D3D11_LOGIC_OP logicOps[] = {
106
D3D11_LOGIC_OP_CLEAR,
107
D3D11_LOGIC_OP_AND,
108
D3D11_LOGIC_OP_AND_REVERSE,
109
D3D11_LOGIC_OP_COPY,
110
D3D11_LOGIC_OP_AND_INVERTED,
111
D3D11_LOGIC_OP_NOOP,
112
D3D11_LOGIC_OP_XOR,
113
D3D11_LOGIC_OP_OR,
114
D3D11_LOGIC_OP_NOR,
115
D3D11_LOGIC_OP_EQUIV,
116
D3D11_LOGIC_OP_INVERT,
117
D3D11_LOGIC_OP_OR_REVERSE,
118
D3D11_LOGIC_OP_COPY_INVERTED,
119
D3D11_LOGIC_OP_OR_INVERTED,
120
D3D11_LOGIC_OP_NAND,
121
D3D11_LOGIC_OP_SET,
122
};
123
124
class FramebufferManagerD3D11;
125
class ShaderManagerD3D11;
126
127
void DrawEngineD3D11::ApplyDrawState(int prim) {
128
dynState_.topology = primToD3D11[prim];
129
130
if (!gstate_c.IsDirty(DIRTY_BLEND_STATE | DIRTY_TEXTURE_IMAGE | DIRTY_TEXTURE_PARAMS | DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_RASTER_STATE | DIRTY_DEPTHSTENCIL_STATE)) {
131
// nothing to do
132
return;
133
}
134
135
bool useBufferedRendering = framebufferManager_->UseBufferedRendering();
136
// Blend
137
if (gstate_c.IsDirty(DIRTY_BLEND_STATE)) {
138
if (gstate.isModeClear()) {
139
keys_.blend.value = 0; // full wipe
140
keys_.blend.blendEnable = false;
141
dynState_.useBlendColor = false;
142
// Color Test
143
bool alphaMask = gstate.isClearModeAlphaMask();
144
bool colorMask = gstate.isClearModeColorMask();
145
keys_.blend.colorWriteMask = (colorMask ? (1 | 2 | 4) : 0) | (alphaMask ? 8 : 0);
146
} else {
147
keys_.blend.value = 0;
148
149
pipelineState_.Convert(draw_->GetShaderLanguageDesc().bitwiseOps);
150
GenericMaskState &maskState = pipelineState_.maskState;
151
GenericBlendState &blendState = pipelineState_.blendState;
152
// We ignore the logicState on D3D since there's no support, the emulation of it is blend-and-shader only.
153
154
if (pipelineState_.FramebufferRead()) {
155
FBOTexState fboTexBindState = FBO_TEX_NONE;
156
ApplyFramebufferRead(&fboTexBindState);
157
// The shader takes over the responsibility for blending, so recompute.
158
ApplyStencilReplaceAndLogicOpIgnoreBlend(blendState.replaceAlphaWithStencil, blendState);
159
160
if (fboTexBindState == FBO_TEX_COPY_BIND_TEX) {
161
framebufferManager_->BindFramebufferAsColorTexture(1, framebufferManager_->GetCurrentRenderVFB(), BINDFBCOLOR_MAY_COPY | BINDFBCOLOR_UNCACHED, 0);
162
// No sampler required, we do a plain Load in the pixel shader.
163
fboTexBound_ = true;
164
fboTexBindState = FBO_TEX_NONE;
165
166
framebufferManager_->RebindFramebuffer("RebindFramebuffer - ApplyDrawState");
167
// Must dirty blend state here so we re-copy next time. Example: Lunar's spell effects.
168
dirtyRequiresRecheck_ |= DIRTY_BLEND_STATE;
169
gstate_c.Dirty(DIRTY_BLEND_STATE);
170
}
171
172
dirtyRequiresRecheck_ |= DIRTY_FRAGMENTSHADER_STATE;
173
gstate_c.Dirty(DIRTY_FRAGMENTSHADER_STATE);
174
} else {
175
if (fboTexBound_) {
176
fboTexBound_ = false;
177
dirtyRequiresRecheck_ |= DIRTY_FRAGMENTSHADER_STATE;
178
gstate_c.Dirty(DIRTY_FRAGMENTSHADER_STATE);
179
}
180
}
181
182
if (blendState.blendEnabled) {
183
keys_.blend.blendEnable = true;
184
keys_.blend.logicOpEnable = false;
185
keys_.blend.blendOpColor = d3d11BlendEqLookup[(size_t)blendState.eqColor];
186
keys_.blend.blendOpAlpha = d3d11BlendEqLookup[(size_t)blendState.eqAlpha];
187
keys_.blend.srcColor = d3d11BlendFactorLookup[(size_t)blendState.srcColor];
188
keys_.blend.srcAlpha = d3d11BlendFactorLookup[(size_t)blendState.srcAlpha];
189
keys_.blend.destColor = d3d11BlendFactorLookup[(size_t)blendState.dstColor];
190
keys_.blend.destAlpha = d3d11BlendFactorLookup[(size_t)blendState.dstAlpha];
191
if (blendState.dirtyShaderBlendFixValues) {
192
dirtyRequiresRecheck_ |= DIRTY_SHADERBLEND;
193
gstate_c.Dirty(DIRTY_SHADERBLEND);
194
}
195
dynState_.useBlendColor = blendState.useBlendColor;
196
if (blendState.useBlendColor) {
197
dynState_.blendColor = blendState.blendColor;
198
}
199
} else {
200
keys_.blend.blendEnable = false;
201
dynState_.useBlendColor = false;
202
}
203
204
if (gstate_c.Use(GPU_USE_LOGIC_OP)) {
205
// Logic Ops
206
if (gstate.isLogicOpEnabled() && gstate.getLogicOp() != GE_LOGIC_COPY) {
207
keys_.blend.blendEnable = false; // Can't have both blend & logic op - although I think the PSP can!
208
keys_.blend.logicOpEnable = true;
209
keys_.blend.logicOp = logicOps[gstate.getLogicOp()];
210
} else {
211
keys_.blend.logicOpEnable = false;
212
}
213
}
214
215
keys_.blend.colorWriteMask = maskState.channelMask;
216
}
217
}
218
219
if (gstate_c.IsDirty(DIRTY_RASTER_STATE)) {
220
keys_.raster.value = 0;
221
bool wantCull = !gstate.isModeClear() && prim != GE_PRIM_RECTANGLES && prim > GE_PRIM_LINE_STRIP && gstate.isCullEnabled();
222
keys_.raster.cullMode = wantCull ? (gstate.getCullMode() ? D3D11_CULL_FRONT : D3D11_CULL_BACK) : D3D11_CULL_NONE;
223
224
if (gstate.isModeClear() || gstate.isModeThrough()) {
225
// TODO: Might happen in clear mode if not through...
226
keys_.raster.depthClipEnable = 1;
227
} else {
228
if (gstate.getDepthRangeMin() == 0 || gstate.getDepthRangeMax() == 65535) {
229
// TODO: Still has a bug where we clamp to depth range if one is not the full range.
230
// But the alternate is not clamping in either direction...
231
keys_.raster.depthClipEnable = !gstate.isDepthClampEnabled() || !gstate_c.Use(GPU_USE_DEPTH_CLAMP);
232
} else {
233
// We just want to clip in this case, the clamp would be clipped anyway.
234
keys_.raster.depthClipEnable = 1;
235
}
236
}
237
}
238
239
if (gstate_c.IsDirty(DIRTY_DEPTHSTENCIL_STATE)) {
240
GenericStencilFuncState stencilState;
241
ConvertStencilFuncState(stencilState);
242
243
if (gstate.isModeClear()) {
244
keys_.depthStencil.value = 0;
245
keys_.depthStencil.depthTestEnable = true;
246
keys_.depthStencil.depthCompareOp = D3D11_COMPARISON_ALWAYS;
247
keys_.depthStencil.depthWriteEnable = gstate.isClearModeDepthMask();
248
249
// Stencil Test
250
bool alphaMask = gstate.isClearModeAlphaMask();
251
if (alphaMask) {
252
keys_.depthStencil.stencilTestEnable = true;
253
keys_.depthStencil.stencilCompareFunc = D3D11_COMPARISON_ALWAYS;
254
keys_.depthStencil.stencilPassOp = D3D11_STENCIL_OP_REPLACE;
255
keys_.depthStencil.stencilFailOp = D3D11_STENCIL_OP_REPLACE;
256
keys_.depthStencil.stencilDepthFailOp = D3D11_STENCIL_OP_REPLACE;
257
dynState_.useStencil = true;
258
// In clear mode, the stencil value is set to the alpha value of the vertex.
259
// A normal clear will be 2 points, the second point has the color.
260
// We override this value in the pipeline from software transform for clear rectangles.
261
dynState_.stencilRef = 0xFF;
262
// But we still apply the stencil write mask.
263
keys_.depthStencil.stencilWriteMask = stencilState.writeMask;
264
} else {
265
keys_.depthStencil.stencilTestEnable = false;
266
dynState_.useStencil = false;
267
}
268
269
} else {
270
keys_.depthStencil.value = 0;
271
// Depth Test
272
if (!IsDepthTestEffectivelyDisabled()) {
273
keys_.depthStencil.depthTestEnable = true;
274
keys_.depthStencil.depthCompareOp = compareOps[gstate.getDepthTestFunction()];
275
keys_.depthStencil.depthWriteEnable = gstate.isDepthWriteEnabled();
276
UpdateEverUsedEqualDepth(gstate.getDepthTestFunction());
277
} else {
278
keys_.depthStencil.depthTestEnable = false;
279
keys_.depthStencil.depthWriteEnable = false;
280
keys_.depthStencil.depthCompareOp = D3D11_COMPARISON_ALWAYS;
281
}
282
283
// Stencil Test
284
if (stencilState.enabled) {
285
keys_.depthStencil.stencilTestEnable = true;
286
keys_.depthStencil.stencilCompareFunc = compareOps[stencilState.testFunc];
287
keys_.depthStencil.stencilPassOp = stencilOps[stencilState.zPass];
288
keys_.depthStencil.stencilFailOp = stencilOps[stencilState.sFail];
289
keys_.depthStencil.stencilDepthFailOp = stencilOps[stencilState.zFail];
290
keys_.depthStencil.stencilCompareMask = stencilState.testMask;
291
keys_.depthStencil.stencilWriteMask = stencilState.writeMask;
292
dynState_.useStencil = true;
293
dynState_.stencilRef = stencilState.testRef;
294
295
// Nasty special case for Spongebob and similar where it tries to write zeros to alpha/stencil during
296
// depth-fail. We can't write to alpha then because the pixel is killed. However, we can invert the depth
297
// test and modify the alpha function...
298
if (SpongebobDepthInverseConditions(stencilState)) {
299
keys_.blend.blendEnable = true;
300
keys_.blend.blendOpAlpha = D3D11_BLEND_OP_ADD;
301
keys_.blend.blendOpColor = D3D11_BLEND_OP_ADD;
302
keys_.blend.srcColor = D3D11_BLEND_ZERO;
303
keys_.blend.destColor = D3D11_BLEND_ZERO;
304
keys_.blend.logicOpEnable = false;
305
keys_.blend.srcAlpha = D3D11_BLEND_ZERO;
306
keys_.blend.destAlpha = D3D11_BLEND_ZERO;
307
keys_.blend.colorWriteMask = D3D11_COLOR_WRITE_ENABLE_ALPHA;
308
309
keys_.depthStencil.depthCompareOp = D3D11_COMPARISON_LESS; // Inverse of GREATER_EQUAL
310
keys_.depthStencil.stencilCompareFunc = D3D11_COMPARISON_ALWAYS;
311
// Invert
312
keys_.depthStencil.stencilPassOp = D3D11_STENCIL_OP_ZERO;
313
keys_.depthStencil.stencilFailOp = D3D11_STENCIL_OP_ZERO;
314
keys_.depthStencil.stencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
315
316
dirtyRequiresRecheck_ |= DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE;
317
gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE);
318
}
319
} else {
320
keys_.depthStencil.stencilTestEnable = false;
321
dynState_.useStencil = false;
322
}
323
}
324
}
325
326
if (gstate_c.IsDirty(DIRTY_VIEWPORTSCISSOR_STATE)) {
327
ViewportAndScissor vpAndScissor;
328
ConvertViewportAndScissor(useBufferedRendering,
329
framebufferManager_->GetRenderWidth(), framebufferManager_->GetRenderHeight(),
330
framebufferManager_->GetTargetBufferWidth(), framebufferManager_->GetTargetBufferHeight(),
331
vpAndScissor);
332
UpdateCachedViewportState(vpAndScissor);
333
334
float depthMin = vpAndScissor.depthRangeMin;
335
float depthMax = vpAndScissor.depthRangeMax;
336
337
if (depthMin < 0.0f) depthMin = 0.0f;
338
if (depthMax > 1.0f) depthMax = 1.0f;
339
340
Draw::Viewport &vp = dynState_.viewport;
341
vp.TopLeftX = vpAndScissor.viewportX;
342
vp.TopLeftY = vpAndScissor.viewportY;
343
vp.Width = vpAndScissor.viewportW;
344
vp.Height = vpAndScissor.viewportH;
345
vp.MinDepth = depthMin;
346
vp.MaxDepth = depthMax;
347
348
D3D11_RECT &scissor = dynState_.scissor;
349
scissor.left = vpAndScissor.scissorX;
350
scissor.top = vpAndScissor.scissorY;
351
scissor.right = vpAndScissor.scissorX + std::max(0, vpAndScissor.scissorW);
352
scissor.bottom = vpAndScissor.scissorY + std::max(0, vpAndScissor.scissorH);
353
}
354
355
// Actually create/set the state objects only after we're done mapping all the state.
356
// There might have been interactions between depth and blend above.
357
if (gstate_c.IsDirty(DIRTY_BLEND_STATE)) {
358
if (!device1_) {
359
ID3D11BlendState *bs = nullptr;
360
if (!blendCache_.Get(keys_.blend.value, &bs) || !bs) {
361
D3D11_BLEND_DESC desc{};
362
D3D11_RENDER_TARGET_BLEND_DESC &rt = desc.RenderTarget[0];
363
rt.BlendEnable = keys_.blend.blendEnable;
364
rt.BlendOp = (D3D11_BLEND_OP)keys_.blend.blendOpColor;
365
rt.BlendOpAlpha = (D3D11_BLEND_OP)keys_.blend.blendOpAlpha;
366
rt.SrcBlend = (D3D11_BLEND)keys_.blend.srcColor;
367
rt.DestBlend = (D3D11_BLEND)keys_.blend.destColor;
368
rt.SrcBlendAlpha = (D3D11_BLEND)keys_.blend.srcAlpha;
369
rt.DestBlendAlpha = (D3D11_BLEND)keys_.blend.destAlpha;
370
rt.RenderTargetWriteMask = keys_.blend.colorWriteMask;
371
ASSERT_SUCCESS(device_->CreateBlendState(&desc, &bs));
372
blendCache_.Insert(keys_.blend.value, bs);
373
}
374
blendState_ = bs;
375
} else {
376
ID3D11BlendState1 *bs1 = nullptr;
377
if (!blendCache1_.Get(keys_.blend.value, &bs1) || !bs1) {
378
D3D11_BLEND_DESC1 desc1{};
379
D3D11_RENDER_TARGET_BLEND_DESC1 &rt = desc1.RenderTarget[0];
380
rt.BlendEnable = keys_.blend.blendEnable;
381
rt.BlendOp = (D3D11_BLEND_OP)keys_.blend.blendOpColor;
382
rt.BlendOpAlpha = (D3D11_BLEND_OP)keys_.blend.blendOpAlpha;
383
rt.SrcBlend = (D3D11_BLEND)keys_.blend.srcColor;
384
rt.DestBlend = (D3D11_BLEND)keys_.blend.destColor;
385
rt.SrcBlendAlpha = (D3D11_BLEND)keys_.blend.srcAlpha;
386
rt.DestBlendAlpha = (D3D11_BLEND)keys_.blend.destAlpha;
387
rt.RenderTargetWriteMask = keys_.blend.colorWriteMask;
388
rt.LogicOpEnable = keys_.blend.logicOpEnable;
389
rt.LogicOp = (D3D11_LOGIC_OP)keys_.blend.logicOp;
390
ASSERT_SUCCESS(device1_->CreateBlendState1(&desc1, &bs1));
391
blendCache1_.Insert(keys_.blend.value, bs1);
392
}
393
blendState1_ = bs1;
394
}
395
}
396
397
if (gstate_c.IsDirty(DIRTY_RASTER_STATE)) {
398
ID3D11RasterizerState *rs;
399
if (!rasterCache_.Get(keys_.raster.value, &rs) || !rs) {
400
D3D11_RASTERIZER_DESC desc{};
401
desc.CullMode = (D3D11_CULL_MODE)(keys_.raster.cullMode);
402
desc.FillMode = D3D11_FILL_SOLID;
403
desc.ScissorEnable = TRUE;
404
desc.FrontCounterClockwise = TRUE;
405
desc.DepthClipEnable = keys_.raster.depthClipEnable;
406
ASSERT_SUCCESS(device_->CreateRasterizerState(&desc, &rs));
407
rasterCache_.Insert(keys_.raster.value, rs);
408
}
409
rasterState_ = rs;
410
}
411
412
if (gstate_c.IsDirty(DIRTY_DEPTHSTENCIL_STATE)) {
413
ID3D11DepthStencilState *ds;
414
if (!depthStencilCache_.Get(keys_.depthStencil.value, &ds) || !ds) {
415
D3D11_DEPTH_STENCIL_DESC desc{};
416
desc.DepthEnable = keys_.depthStencil.depthTestEnable;
417
desc.DepthWriteMask = keys_.depthStencil.depthWriteEnable ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
418
desc.DepthFunc = (D3D11_COMPARISON_FUNC)keys_.depthStencil.depthCompareOp;
419
desc.StencilEnable = keys_.depthStencil.stencilTestEnable;
420
desc.StencilReadMask = keys_.depthStencil.stencilCompareMask;
421
desc.StencilWriteMask = keys_.depthStencil.stencilWriteMask;
422
desc.FrontFace.StencilFailOp = (D3D11_STENCIL_OP)keys_.depthStencil.stencilFailOp;
423
desc.FrontFace.StencilPassOp = (D3D11_STENCIL_OP)keys_.depthStencil.stencilPassOp;
424
desc.FrontFace.StencilDepthFailOp = (D3D11_STENCIL_OP)keys_.depthStencil.stencilDepthFailOp;
425
desc.FrontFace.StencilFunc = (D3D11_COMPARISON_FUNC)keys_.depthStencil.stencilCompareFunc;
426
desc.BackFace = desc.FrontFace;
427
ASSERT_SUCCESS(device_->CreateDepthStencilState(&desc, &ds));
428
depthStencilCache_.Insert(keys_.depthStencil.value, ds);
429
}
430
depthStencilState_ = ds;
431
}
432
433
if (gstate_c.IsDirty(DIRTY_TEXTURE_IMAGE | DIRTY_TEXTURE_PARAMS) && !gstate.isModeClear() && gstate.isTextureMapEnabled()) {
434
textureCache_->SetTexture();
435
gstate_c.Clean(DIRTY_TEXTURE_IMAGE | DIRTY_TEXTURE_PARAMS);
436
} else if (gstate.getTextureAddress(0) == (gstate.getFrameBufRawAddress() | 0x04000000)) {
437
// This catches the case of clearing a texture.
438
gstate_c.Dirty(DIRTY_TEXTURE_IMAGE);
439
}
440
}
441
442
void DrawEngineD3D11::ApplyDrawStateLate(bool applyStencilRef, uint8_t stencilRef) {
443
// we go through Draw here because it automatically handles screen rotation, as needed in UWP on mobiles.
444
if (gstate_c.IsDirty(DIRTY_VIEWPORTSCISSOR_STATE)) {
445
draw_->SetViewport(dynState_.viewport);
446
draw_->SetScissorRect(dynState_.scissor.left, dynState_.scissor.top, dynState_.scissor.right - dynState_.scissor.left, dynState_.scissor.bottom - dynState_.scissor.top);
447
}
448
if (gstate_c.IsDirty(DIRTY_RASTER_STATE)) {
449
context_->RSSetState(rasterState_);
450
}
451
if (gstate_c.IsDirty(DIRTY_BLEND_STATE)) {
452
// Need to do this AFTER ApplyTexture because the process of depalettization can ruin the blend state.
453
float blendColor[4];
454
Uint8x4ToFloat4(blendColor, dynState_.blendColor);
455
if (device1_) {
456
context1_->OMSetBlendState(blendState1_, blendColor, 0xFFFFFFFF);
457
} else {
458
context_->OMSetBlendState(blendState_, blendColor, 0xFFFFFFFF);
459
}
460
}
461
if (gstate_c.IsDirty(DIRTY_DEPTHSTENCIL_STATE) || applyStencilRef) {
462
context_->OMSetDepthStencilState(depthStencilState_, applyStencilRef ? stencilRef : dynState_.stencilRef);
463
}
464
gstate_c.Clean(DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_BLEND_STATE);
465
gstate_c.Dirty(dirtyRequiresRecheck_);
466
dirtyRequiresRecheck_ = 0;
467
}
468
469