/
PSTextureEncoder.cpp
1449 lines (1181 loc) · 46.3 KB
/
PSTextureEncoder.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
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
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
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
329
330
331
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
365
366
367
368
369
370
371
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
408
409
410
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
474
475
476
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
540
541
542
543
544
545
546
547
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
586
587
588
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
648
649
650
651
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
712
713
714
715
716
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
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2013 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
#include "PSTextureEncoder.h"
#include "D3DBase.h"
#include "D3DShader.h"
#include "GfxState.h"
#include "BPMemory.h"
#include "FramebufferManager.h"
#include "Render.h"
#include "HW/Memmap.h"
#include "TextureCache.h"
// "Static mode" will compile a new EFB encoder shader for every combination of
// encoding configurations. It's compatible with Shader Model 4.
// "Dynamic mode" will use the dynamic-linking feature of Shader Model 5. Only
// one shader needs to be compiled.
// Unfortunately, the June 2010 DirectX SDK includes a broken HLSL compiler
// which cripples dynamic linking for us.
// See <http://www.gamedev.net/topic/587232-dx11-dynamic-linking-compilation-warnings/>.
// Dynamic mode is disabled for now. To enable it, uncomment the line below.
//#define USE_DYNAMIC_MODE
// FIXME: When Microsoft fixes their HLSL compiler, make Dolphin enable dynamic
// mode on Shader Model 5-compatible cards.
namespace DX11
{
union EFBEncodeParams
{
struct
{
FLOAT NumHalfCacheLinesX;
FLOAT NumBlocksY;
FLOAT PosX;
FLOAT PosY;
FLOAT TexLeft;
FLOAT TexTop;
FLOAT TexRight;
FLOAT TexBottom;
};
// Constant buffers must be a multiple of 16 bytes in size.
u8 pad[32]; // Pad to the next multiple of 16 bytes
};
static const char EFB_ENCODE_VS[] =
"// dolphin-emu EFB encoder vertex shader\n"
"cbuffer cbParams : register(b0)\n"
"{\n"
"struct\n" // Should match EFBEncodeParams above
"{\n"
"float NumHalfCacheLinesX;\n"
"float NumBlocksY;\n"
"float PosX;\n" // Upper-left corner of source
"float PosY;\n"
"float TexLeft;\n" // Rectangle within EFBTexture representing the actual EFB (normalized)
"float TexTop;\n"
"float TexRight;\n"
"float TexBottom;\n"
"} Params;\n"
"}\n"
"struct Output\n"
"{\n"
"float4 Pos : SV_Position;\n"
"float2 Coord : ENCODECOORD;\n"
"};\n"
"Output main(in float2 Pos : POSITION)\n"
"{\n"
"Output result;\n"
"result.Pos = float4(2*Pos.x-1, -2*Pos.y+1, 0.0, 1.0);\n"
"result.Coord = Pos * float2(Params.NumHalfCacheLinesX, Params.NumBlocksY);\n"
"return result;\n"
"}\n"
;
static const char EFB_ENCODE_PS[] =
"// dolphin-emu EFB encoder pixel shader\n"
// Input
"cbuffer cbParams : register(b0)\n"
"{\n"
"struct\n" // Should match EFBEncodeParams above
"{\n"
"float NumHalfCacheLinesX;\n"
"float NumBlocksY;\n"
"float PosX;\n" // Upper-left corner of source
"float PosY;\n"
"float TexLeft;\n" // Rectangle within EFBTexture representing the actual EFB (normalized)
"float TexTop;\n"
"float TexRight;\n"
"float TexBottom;\n"
"} Params;\n"
"}\n"
"Texture2D EFBTexture : register(t0);\n"
"sampler EFBSampler : register(s0);\n"
// Constants
"static const float2 INV_EFB_DIMS = float2(1.0/640.0, 1.0/528.0);\n"
// FIXME: Is this correct?
"static const float3 INTENSITY_COEFFS = float3(0.257, 0.504, 0.098);\n"
"static const float INTENSITY_ADD = 16.0/255.0;\n"
// Utility functions
"uint4 Swap4_32(uint4 v) {\n"
"return (((v >> 24) & 0xFF) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000));\n"
"}\n"
"uint4 UINT4_8888_BE(uint4 a, uint4 b, uint4 c, uint4 d) {\n"
"return (d << 24) | (c << 16) | (b << 8) | a;\n"
"}\n"
"uint UINT_44444444_BE(uint a, uint b, uint c, uint d, uint e, uint f, uint g, uint h) {\n"
"return (g << 28) | (h << 24) | (e << 20) | (f << 16) | (c << 12) | (d << 8) | (a << 4) | b;\n"
"}\n"
"uint UINT_1555(uint a, uint b, uint c, uint d) {\n"
"return (a << 15) | (b << 10) | (c << 5) | d;\n"
"}\n"
"uint UINT_3444(uint a, uint b, uint c, uint d) {\n"
"return (a << 12) | (b << 8) | (c << 4) | d;\n"
"}\n"
"uint UINT_565(uint a, uint b, uint c) {\n"
"return (a << 11) | (b << 5) | c;\n"
"}\n"
"uint UINT_1616(uint a, uint b) {\n"
"return (a << 16) | b;\n"
"}\n"
"uint Float8ToUint3(float v) {\n"
"return (uint)(v*255.0) >> 5;\n"
"}\n"
"uint Float8ToUint4(float v) {\n"
"return (uint)(v*255.0) >> 4;\n"
"}\n"
"uint Float8ToUint5(float v) {\n"
"return (uint)(v*255.0) >> 3;\n"
"}\n"
"uint Float8ToUint6(float v) {\n"
"return (uint)(v*255.0) >> 2;\n"
"}\n"
"uint EncodeRGB5A3(float4 pixel) {\n"
"if (pixel.a >= 224.0/255.0) {\n"
// Encode to ARGB1555
"return UINT_1555(1, Float8ToUint5(pixel.r), Float8ToUint5(pixel.g), Float8ToUint5(pixel.b));\n"
"} else {\n"
// Encode to ARGB3444
"return UINT_3444(Float8ToUint3(pixel.a), Float8ToUint4(pixel.r), Float8ToUint4(pixel.g), Float8ToUint4(pixel.b));\n"
"}\n"
"}\n"
"uint EncodeRGB565(float4 pixel) {\n"
"return UINT_565(Float8ToUint5(pixel.r), Float8ToUint6(pixel.g), Float8ToUint5(pixel.b));\n"
"}\n"
"float2 CalcTexCoord(float2 coord)\n"
"{\n"
// Add 0.5,0.5 to sample from the center of the EFB pixel
"float2 efbCoord = coord + float2(0.5,0.5);\n"
"return lerp(float2(Params.TexLeft,Params.TexTop), float2(Params.TexRight,Params.TexBottom), efbCoord * INV_EFB_DIMS);\n"
"}\n"
// Interface and classes for different source formats
"float4 Fetch_0(float2 coord)\n"
"{\n"
"float2 texCoord = CalcTexCoord(coord);\n"
"float4 result = EFBTexture.Sample(EFBSampler, texCoord);\n"
"result.a = 1.0;\n"
"return result;\n"
"}\n"
"float4 Fetch_1(float2 coord)\n"
"{\n"
"float2 texCoord = CalcTexCoord(coord);\n"
"return EFBTexture.Sample(EFBSampler, texCoord);\n"
"}\n"
"float4 Fetch_2(float2 coord)\n"
"{\n"
"float2 texCoord = CalcTexCoord(coord);\n"
"float4 result = EFBTexture.Sample(EFBSampler, texCoord);\n"
"result.a = 1.0;\n"
"return result;\n"
"}\n"
"float4 Fetch_3(float2 coord)\n"
"{\n"
"float2 texCoord = CalcTexCoord(coord);\n"
"uint depth24 = 0xFFFFFF * EFBTexture.Sample(EFBSampler, texCoord).r;\n"
"uint4 bytes = uint4(\n"
"(depth24 >> 16) & 0xFF,\n" // r
"(depth24 >> 8) & 0xFF,\n" // g
"depth24 & 0xFF,\n" // b
"255);\n" // a
"return bytes / 255.0;\n"
"}\n"
"#ifdef DYNAMIC_MODE\n"
"interface iFetch\n"
"{\n"
"float4 Fetch(float2 coord);\n"
"};\n"
// Source format 0
"class cFetch_0 : iFetch\n"
"{\n"
"float4 Fetch(float2 coord)\n"
"{ return Fetch_0(coord); }\n"
"};\n"
// Source format 1
"class cFetch_1 : iFetch\n"
"{\n"
"float4 Fetch(float2 coord)\n"
"{ return Fetch_1(coord); }\n"
"};\n"
// Source format 2
"class cFetch_2 : iFetch\n"
"{\n"
"float4 Fetch(float2 coord)\n"
"{ return Fetch_2(coord); }\n"
"};\n"
// Source format 3
"class cFetch_3 : iFetch\n"
"{\n"
"float4 Fetch(float2 coord)\n"
"{ return Fetch_3(coord); }\n"
"};\n"
// Declare fetch interface; must be set by application
"iFetch g_fetch;\n"
"#define IMP_FETCH g_fetch.Fetch\n"
"#endif\n" // #ifdef DYNAMIC_MODE
"#ifndef IMP_FETCH\n"
"#error No Fetch specified\n"
"#endif\n"
// Interface and classes for different intensity settings (on or off)
"float4 Intensity_0(float4 sample)\n"
"{\n"
"return sample;\n"
"}\n"
"float4 Intensity_1(float4 sample)\n"
"{\n"
"sample.r = dot(INTENSITY_COEFFS, sample.rgb) + INTENSITY_ADD;\n"
// FIXME: Is this correct? What happens if you use one of the non-R
// formats with intensity on?
"sample = sample.rrrr;\n"
"return sample;\n"
"}\n"
"#ifdef DYNAMIC_MODE\n"
"interface iIntensity\n"
"{\n"
"float4 Intensity(float4 sample);\n"
"};\n"
// Intensity off
"class cIntensity_0 : iIntensity\n"
"{\n"
"float4 Intensity(float4 sample)\n"
"{ return Intensity_0(sample); }\n"
"};\n"
// Intensity on
"class cIntensity_1 : iIntensity\n"
"{\n"
"float4 Intensity(float4 sample)\n"
"{ return Intensity_1(sample); }\n"
"};\n"
// Declare intensity interface; must be set by application
"iIntensity g_intensity;\n"
"#define IMP_INTENSITY g_intensity.Intensity\n"
"#endif\n" // #ifdef DYNAMIC_MODE
"#ifndef IMP_INTENSITY\n"
"#error No Intensity specified\n"
"#endif\n"
// Interface and classes for different scale/filter settings (on or off)
"float4 ScaledFetch_0(float2 coord)\n"
"{\n"
"return IMP_FETCH(float2(Params.PosX,Params.PosY) + coord);\n"
"}\n"
"float4 ScaledFetch_1(float2 coord)\n"
"{\n"
"float2 ul = float2(Params.PosX,Params.PosY) + 2*coord;\n"
"float4 sample0 = IMP_FETCH(ul+float2(0,0));\n"
"float4 sample1 = IMP_FETCH(ul+float2(1,0));\n"
"float4 sample2 = IMP_FETCH(ul+float2(0,1));\n"
"float4 sample3 = IMP_FETCH(ul+float2(1,1));\n"
// Average all four samples together
// FIXME: Is this correct?
"return 0.25 * (sample0+sample1+sample2+sample3);\n"
"}\n"
"#ifdef DYNAMIC_MODE\n"
"interface iScaledFetch\n"
"{\n"
"float4 ScaledFetch(float2 coord);\n"
"};\n"
// Scale off
"class cScaledFetch_0 : iScaledFetch\n"
"{\n"
"float4 ScaledFetch(float2 coord)\n"
"{ return ScaledFetch_0(coord); }\n"
"};\n"
// Scale on
"class cScaledFetch_1 : iScaledFetch\n"
"{\n"
"float4 ScaledFetch(float2 coord)\n"
"{ return ScaledFetch_1(coord); }\n"
"};\n"
// Declare scaled fetch interface; must be set by application code
"iScaledFetch g_scaledFetch;\n"
"#define IMP_SCALEDFETCH g_scaledFetch.ScaledFetch\n"
"#endif\n" // #ifdef DYNAMIC_MODE
"#ifndef IMP_SCALEDFETCH\n"
"#error No ScaledFetch specified\n"
"#endif\n"
// Main EFB-sampling function: performs all steps of fetching pixels, scaling,
// applying intensity function
"float4 SampleEFB(float2 coord)\n"
"{\n"
// FIXME: Does intensity happen before or after scaling? Or does
// it matter?
"float4 sample = IMP_SCALEDFETCH(coord);\n"
"return IMP_INTENSITY(sample);\n"
"}\n"
// Interfaces and classes for different destination formats
"uint4 Generate_0(float2 cacheCoord)\n" // R4
"{\n"
"float2 blockCoord = floor(cacheCoord / float2(2,1));\n"
"float2 blockUL = blockCoord * float2(8,8);\n"
"float2 subBlockUL = blockUL + float2(0, 4*(cacheCoord.x%2));\n"
"float4 sample[32];\n"
"for (uint y = 0; y < 4; ++y) {\n"
"for (uint x = 0; x < 8; ++x) {\n"
"sample[y*8+x] = SampleEFB(subBlockUL+float2(x,y));\n"
"}\n"
"}\n"
"uint dw[4];\n"
"for (uint i = 0; i < 4; ++i) {\n"
"dw[i] = UINT_44444444_BE(\n"
"Float8ToUint4(sample[8*i+0].r),\n"
"Float8ToUint4(sample[8*i+1].r),\n"
"Float8ToUint4(sample[8*i+2].r),\n"
"Float8ToUint4(sample[8*i+3].r),\n"
"Float8ToUint4(sample[8*i+4].r),\n"
"Float8ToUint4(sample[8*i+5].r),\n"
"Float8ToUint4(sample[8*i+6].r),\n"
"Float8ToUint4(sample[8*i+7].r)\n"
");\n"
"}\n"
"return uint4(dw[0], dw[1], dw[2], dw[3]);\n"
"}\n"
// FIXME: Untested
"uint4 Generate_1(float2 cacheCoord)\n" // R8 (FIXME: Duplicate of R8 below?)
"{\n"
"float2 blockCoord = floor(cacheCoord / float2(2,1));\n"
"float2 blockUL = blockCoord * float2(8,4);\n"
"float2 subBlockUL = blockUL + float2(0, 2*(cacheCoord.x%2));\n"
"float4 sample0 = SampleEFB(subBlockUL+float2(0,0));\n"
"float4 sample1 = SampleEFB(subBlockUL+float2(1,0));\n"
"float4 sample2 = SampleEFB(subBlockUL+float2(2,0));\n"
"float4 sample3 = SampleEFB(subBlockUL+float2(3,0));\n"
"float4 sample4 = SampleEFB(subBlockUL+float2(4,0));\n"
"float4 sample5 = SampleEFB(subBlockUL+float2(5,0));\n"
"float4 sample6 = SampleEFB(subBlockUL+float2(6,0));\n"
"float4 sample7 = SampleEFB(subBlockUL+float2(7,0));\n"
"float4 sample8 = SampleEFB(subBlockUL+float2(0,1));\n"
"float4 sample9 = SampleEFB(subBlockUL+float2(1,1));\n"
"float4 sampleA = SampleEFB(subBlockUL+float2(2,1));\n"
"float4 sampleB = SampleEFB(subBlockUL+float2(3,1));\n"
"float4 sampleC = SampleEFB(subBlockUL+float2(4,1));\n"
"float4 sampleD = SampleEFB(subBlockUL+float2(5,1));\n"
"float4 sampleE = SampleEFB(subBlockUL+float2(6,1));\n"
"float4 sampleF = SampleEFB(subBlockUL+float2(7,1));\n"
"uint4 dw4 = UINT4_8888_BE(\n"
"255*float4(sample0.r, sample4.r, sample8.r, sampleC.r),\n"
"255*float4(sample1.r, sample5.r, sample9.r, sampleD.r),\n"
"255*float4(sample2.r, sample6.r, sampleA.r, sampleE.r),\n"
"255*float4(sample3.r, sample7.r, sampleB.r, sampleF.r)\n"
");\n"
"return dw4;\n"
"}\n"
// FIXME: Untested
"uint4 Generate_2(float2 cacheCoord)\n" // A4 R4
"{\n"
"float2 blockCoord = floor(cacheCoord / float2(2,1));\n"
"float2 blockUL = blockCoord * float2(8,4);\n"
"float2 subBlockUL = blockUL + float2(0, 2*(cacheCoord.x%2));\n"
"float4 sample0 = SampleEFB(subBlockUL+float2(0,0));\n"
"float4 sample1 = SampleEFB(subBlockUL+float2(1,0));\n"
"float4 sample2 = SampleEFB(subBlockUL+float2(2,0));\n"
"float4 sample3 = SampleEFB(subBlockUL+float2(3,0));\n"
"float4 sample4 = SampleEFB(subBlockUL+float2(4,0));\n"
"float4 sample5 = SampleEFB(subBlockUL+float2(5,0));\n"
"float4 sample6 = SampleEFB(subBlockUL+float2(6,0));\n"
"float4 sample7 = SampleEFB(subBlockUL+float2(7,0));\n"
"float4 sample8 = SampleEFB(subBlockUL+float2(0,1));\n"
"float4 sample9 = SampleEFB(subBlockUL+float2(1,1));\n"
"float4 sampleA = SampleEFB(subBlockUL+float2(2,1));\n"
"float4 sampleB = SampleEFB(subBlockUL+float2(3,1));\n"
"float4 sampleC = SampleEFB(subBlockUL+float2(4,1));\n"
"float4 sampleD = SampleEFB(subBlockUL+float2(5,1));\n"
"float4 sampleE = SampleEFB(subBlockUL+float2(6,1));\n"
"float4 sampleF = SampleEFB(subBlockUL+float2(7,1));\n"
"uint dw0 = UINT_44444444_BE(\n"
"Float8ToUint4(sample0.a), Float8ToUint4(sample0.r),\n"
"Float8ToUint4(sample1.a), Float8ToUint4(sample1.r),\n"
"Float8ToUint4(sample2.a), Float8ToUint4(sample2.r),\n"
"Float8ToUint4(sample3.a), Float8ToUint4(sample3.r)\n"
");\n"
"uint dw1 = UINT_44444444_BE(\n"
"Float8ToUint4(sample4.a), Float8ToUint4(sample4.r),\n"
"Float8ToUint4(sample5.a), Float8ToUint4(sample5.r),\n"
"Float8ToUint4(sample6.a), Float8ToUint4(sample6.r),\n"
"Float8ToUint4(sample7.a), Float8ToUint4(sample7.r)\n"
");\n"
"uint dw2 = UINT_44444444_BE(\n"
"Float8ToUint4(sample8.a), Float8ToUint4(sample8.r),\n"
"Float8ToUint4(sample9.a), Float8ToUint4(sample9.r),\n"
"Float8ToUint4(sampleA.a), Float8ToUint4(sampleA.r),\n"
"Float8ToUint4(sampleB.a), Float8ToUint4(sampleB.r)\n"
");\n"
"uint dw3 = UINT_44444444_BE(\n"
"Float8ToUint4(sampleC.a), Float8ToUint4(sampleC.r),\n"
"Float8ToUint4(sampleD.a), Float8ToUint4(sampleD.r),\n"
"Float8ToUint4(sampleE.a), Float8ToUint4(sampleE.r),\n"
"Float8ToUint4(sampleF.a), Float8ToUint4(sampleF.r)\n"
");\n"
"return uint4(dw0, dw1, dw2, dw3);\n"
"}\n"
// FIXME: Untested
"uint4 Generate_3(float2 cacheCoord)\n" // A8 R8
"{\n"
"float2 blockCoord = floor(cacheCoord / float2(2,1));\n"
"float2 blockUL = blockCoord * float2(4,4);\n"
"float2 subBlockUL = blockUL + float2(0, 2*(cacheCoord.x%2));\n"
"float4 sample0 = SampleEFB(subBlockUL+float2(0,0));\n"
"float4 sample1 = SampleEFB(subBlockUL+float2(1,0));\n"
"float4 sample2 = SampleEFB(subBlockUL+float2(2,0));\n"
"float4 sample3 = SampleEFB(subBlockUL+float2(3,0));\n"
"float4 sample4 = SampleEFB(subBlockUL+float2(0,1));\n"
"float4 sample5 = SampleEFB(subBlockUL+float2(1,1));\n"
"float4 sample6 = SampleEFB(subBlockUL+float2(2,1));\n"
"float4 sample7 = SampleEFB(subBlockUL+float2(3,1));\n"
"uint4 dw4 = UINT4_8888_BE(\n"
"255*float4(sample0.a, sample2.a, sample4.a, sample6.a),\n"
"255*float4(sample0.r, sample2.r, sample4.r, sample6.r),\n"
"255*float4(sample1.a, sample3.a, sample5.a, sample7.a),\n"
"255*float4(sample1.r, sample3.r, sample5.r, sample7.r)\n"
");\n"
"return dw4;\n"
"}\n"
"uint4 Generate_4(float2 cacheCoord)\n" // R5 G6 B5
"{\n"
"float2 blockCoord = floor(cacheCoord / float2(2,1));\n"
"float2 blockUL = blockCoord * float2(4,4);\n"
"float2 subBlockUL = blockUL + float2(0, 2*(cacheCoord.x%2));\n"
"float4 sample0 = SampleEFB(subBlockUL+float2(0,0));\n"
"float4 sample1 = SampleEFB(subBlockUL+float2(1,0));\n"
"float4 sample2 = SampleEFB(subBlockUL+float2(2,0));\n"
"float4 sample3 = SampleEFB(subBlockUL+float2(3,0));\n"
"float4 sample4 = SampleEFB(subBlockUL+float2(0,1));\n"
"float4 sample5 = SampleEFB(subBlockUL+float2(1,1));\n"
"float4 sample6 = SampleEFB(subBlockUL+float2(2,1));\n"
"float4 sample7 = SampleEFB(subBlockUL+float2(3,1));\n"
"uint dw0 = UINT_1616(EncodeRGB565(sample0), EncodeRGB565(sample1));\n"
"uint dw1 = UINT_1616(EncodeRGB565(sample2), EncodeRGB565(sample3));\n"
"uint dw2 = UINT_1616(EncodeRGB565(sample4), EncodeRGB565(sample5));\n"
"uint dw3 = UINT_1616(EncodeRGB565(sample6), EncodeRGB565(sample7));\n"
"return Swap4_32(uint4(dw0, dw1, dw2, dw3));\n"
"}\n"
"uint4 Generate_5(float2 cacheCoord)\n" // 1 R5 G5 B5 or 0 A3 R4 G4 G4
"{\n"
"float2 blockCoord = floor(cacheCoord / float2(2,1));\n"
"float2 blockUL = blockCoord * float2(4,4);\n"
"float2 subBlockUL = blockUL + float2(0, 2*(cacheCoord.x%2));\n"
"float4 sample0 = SampleEFB(subBlockUL+float2(0,0));\n"
"float4 sample1 = SampleEFB(subBlockUL+float2(1,0));\n"
"float4 sample2 = SampleEFB(subBlockUL+float2(2,0));\n"
"float4 sample3 = SampleEFB(subBlockUL+float2(3,0));\n"
"float4 sample4 = SampleEFB(subBlockUL+float2(0,1));\n"
"float4 sample5 = SampleEFB(subBlockUL+float2(1,1));\n"
"float4 sample6 = SampleEFB(subBlockUL+float2(2,1));\n"
"float4 sample7 = SampleEFB(subBlockUL+float2(3,1));\n"
"uint dw0 = UINT_1616(EncodeRGB5A3(sample0), EncodeRGB5A3(sample1));\n"
"uint dw1 = UINT_1616(EncodeRGB5A3(sample2), EncodeRGB5A3(sample3));\n"
"uint dw2 = UINT_1616(EncodeRGB5A3(sample4), EncodeRGB5A3(sample5));\n"
"uint dw3 = UINT_1616(EncodeRGB5A3(sample6), EncodeRGB5A3(sample7));\n"
"return Swap4_32(uint4(dw0, dw1, dw2, dw3));\n"
"}\n"
"uint4 Generate_6(float2 cacheCoord)\n" // A8 R8 A8 R8 | G8 B8 G8 B8
"{\n"
"float2 blockCoord = floor(cacheCoord / float2(4,1));\n"
"float2 blockUL = blockCoord * float2(4,4);\n"
"float2 subBlockUL = blockUL + float2(0, 2*(cacheCoord.x%2));\n"
"float4 sample0 = SampleEFB(subBlockUL+float2(0,0));\n"
"float4 sample1 = SampleEFB(subBlockUL+float2(1,0));\n"
"float4 sample2 = SampleEFB(subBlockUL+float2(2,0));\n"
"float4 sample3 = SampleEFB(subBlockUL+float2(3,0));\n"
"float4 sample4 = SampleEFB(subBlockUL+float2(0,1));\n"
"float4 sample5 = SampleEFB(subBlockUL+float2(1,1));\n"
"float4 sample6 = SampleEFB(subBlockUL+float2(2,1));\n"
"float4 sample7 = SampleEFB(subBlockUL+float2(3,1));\n"
"uint4 dw4;\n"
"if (cacheCoord.x % 4 < 2)\n"
"{\n"
// First cache line gets AR
"dw4 = UINT4_8888_BE(\n"
"255*float4(sample0.a, sample2.a, sample4.a, sample6.a),\n"
"255*float4(sample0.r, sample2.r, sample4.r, sample6.r),\n"
"255*float4(sample1.a, sample3.a, sample5.a, sample7.a),\n"
"255*float4(sample1.r, sample3.r, sample5.r, sample7.r)\n"
");\n"
"}\n"
"else\n"
"{\n"
// Second cache line gets GB
"dw4 = UINT4_8888_BE(\n"
"255*float4(sample0.g, sample2.g, sample4.g, sample6.g),\n"
"255*float4(sample0.b, sample2.b, sample4.b, sample6.b),\n"
"255*float4(sample1.g, sample3.g, sample5.g, sample7.g),\n"
"255*float4(sample1.b, sample3.b, sample5.b, sample7.b)\n"
");\n"
"}\n"
"return dw4;\n"
"}\n"
"uint4 Generate_7(float2 cacheCoord)\n" // A8
"{\n"
"float2 blockCoord = floor(cacheCoord / float2(2,1));\n"
"float2 blockUL = blockCoord * float2(8,4);\n"
"float2 subBlockUL = blockUL + float2(0, 2*(cacheCoord.x%2));\n"
"float4 sample0 = SampleEFB(subBlockUL+float2(0,0));\n"
"float4 sample1 = SampleEFB(subBlockUL+float2(1,0));\n"
"float4 sample2 = SampleEFB(subBlockUL+float2(2,0));\n"
"float4 sample3 = SampleEFB(subBlockUL+float2(3,0));\n"
"float4 sample4 = SampleEFB(subBlockUL+float2(4,0));\n"
"float4 sample5 = SampleEFB(subBlockUL+float2(5,0));\n"
"float4 sample6 = SampleEFB(subBlockUL+float2(6,0));\n"
"float4 sample7 = SampleEFB(subBlockUL+float2(7,0));\n"
"float4 sample8 = SampleEFB(subBlockUL+float2(0,1));\n"
"float4 sample9 = SampleEFB(subBlockUL+float2(1,1));\n"
"float4 sampleA = SampleEFB(subBlockUL+float2(2,1));\n"
"float4 sampleB = SampleEFB(subBlockUL+float2(3,1));\n"
"float4 sampleC = SampleEFB(subBlockUL+float2(4,1));\n"
"float4 sampleD = SampleEFB(subBlockUL+float2(5,1));\n"
"float4 sampleE = SampleEFB(subBlockUL+float2(6,1));\n"
"float4 sampleF = SampleEFB(subBlockUL+float2(7,1));\n"
"uint4 dw4 = UINT4_8888_BE(\n"
"255*float4(sample0.a, sample4.a, sample8.a, sampleC.a),\n"
"255*float4(sample1.a, sample5.a, sample9.a, sampleD.a),\n"
"255*float4(sample2.a, sample6.a, sampleA.a, sampleE.a),\n"
"255*float4(sample3.a, sample7.a, sampleB.a, sampleF.a)\n"
");\n"
"return dw4;\n"
"}\n"
"uint4 Generate_8(float2 cacheCoord)\n" // R8
"{\n"
"float2 blockCoord = floor(cacheCoord / float2(2,1));\n"
"float2 blockUL = blockCoord * float2(8,4);\n"
"float2 subBlockUL = blockUL + float2(0, 2*(cacheCoord.x%2));\n"
"float4 sample0 = SampleEFB(subBlockUL+float2(0,0));\n"
"float4 sample1 = SampleEFB(subBlockUL+float2(1,0));\n"
"float4 sample2 = SampleEFB(subBlockUL+float2(2,0));\n"
"float4 sample3 = SampleEFB(subBlockUL+float2(3,0));\n"
"float4 sample4 = SampleEFB(subBlockUL+float2(4,0));\n"
"float4 sample5 = SampleEFB(subBlockUL+float2(5,0));\n"
"float4 sample6 = SampleEFB(subBlockUL+float2(6,0));\n"
"float4 sample7 = SampleEFB(subBlockUL+float2(7,0));\n"
"float4 sample8 = SampleEFB(subBlockUL+float2(0,1));\n"
"float4 sample9 = SampleEFB(subBlockUL+float2(1,1));\n"
"float4 sampleA = SampleEFB(subBlockUL+float2(2,1));\n"
"float4 sampleB = SampleEFB(subBlockUL+float2(3,1));\n"
"float4 sampleC = SampleEFB(subBlockUL+float2(4,1));\n"
"float4 sampleD = SampleEFB(subBlockUL+float2(5,1));\n"
"float4 sampleE = SampleEFB(subBlockUL+float2(6,1));\n"
"float4 sampleF = SampleEFB(subBlockUL+float2(7,1));\n"
"uint4 dw4 = UINT4_8888_BE(\n"
"255*float4(sample0.r, sample4.r, sample8.r, sampleC.r),\n"
"255*float4(sample1.r, sample5.r, sample9.r, sampleD.r),\n"
"255*float4(sample2.r, sample6.r, sampleA.r, sampleE.r),\n"
"255*float4(sample3.r, sample7.r, sampleB.r, sampleF.r)\n"
");\n"
"return dw4;\n"
"}\n"
// FIXME: Untested
"uint4 Generate_9(float2 cacheCoord)\n" // G8
"{\n"
"float2 blockCoord = floor(cacheCoord / float2(2,1));\n"
"float2 blockUL = blockCoord * float2(8,4);\n"
"float2 subBlockUL = blockUL + float2(0, 2*(cacheCoord.x%2));\n"
"float4 sample0 = SampleEFB(subBlockUL+float2(0,0));\n"
"float4 sample1 = SampleEFB(subBlockUL+float2(1,0));\n"
"float4 sample2 = SampleEFB(subBlockUL+float2(2,0));\n"
"float4 sample3 = SampleEFB(subBlockUL+float2(3,0));\n"
"float4 sample4 = SampleEFB(subBlockUL+float2(4,0));\n"
"float4 sample5 = SampleEFB(subBlockUL+float2(5,0));\n"
"float4 sample6 = SampleEFB(subBlockUL+float2(6,0));\n"
"float4 sample7 = SampleEFB(subBlockUL+float2(7,0));\n"
"float4 sample8 = SampleEFB(subBlockUL+float2(0,1));\n"
"float4 sample9 = SampleEFB(subBlockUL+float2(1,1));\n"
"float4 sampleA = SampleEFB(subBlockUL+float2(2,1));\n"
"float4 sampleB = SampleEFB(subBlockUL+float2(3,1));\n"
"float4 sampleC = SampleEFB(subBlockUL+float2(4,1));\n"
"float4 sampleD = SampleEFB(subBlockUL+float2(5,1));\n"
"float4 sampleE = SampleEFB(subBlockUL+float2(6,1));\n"
"float4 sampleF = SampleEFB(subBlockUL+float2(7,1));\n"
"uint4 dw4 = UINT4_8888_BE(\n"
"255*float4(sample0.g, sample4.g, sample8.g, sampleC.g),\n"
"255*float4(sample1.g, sample5.g, sample9.g, sampleD.g),\n"
"255*float4(sample2.g, sample6.g, sampleA.g, sampleE.g),\n"
"255*float4(sample3.g, sample7.g, sampleB.g, sampleF.g)\n"
");\n"
"return dw4;\n"
"}\n"
"uint4 Generate_A(float2 cacheCoord)\n" // B8
"{\n"
"float2 blockCoord = floor(cacheCoord / float2(2,1));\n"
"float2 blockUL = blockCoord * float2(8,4);\n"
"float2 subBlockUL = blockUL + float2(0, 2*(cacheCoord.x%2));\n"
"float4 sample0 = SampleEFB(subBlockUL+float2(0,0));\n"
"float4 sample1 = SampleEFB(subBlockUL+float2(1,0));\n"
"float4 sample2 = SampleEFB(subBlockUL+float2(2,0));\n"
"float4 sample3 = SampleEFB(subBlockUL+float2(3,0));\n"
"float4 sample4 = SampleEFB(subBlockUL+float2(4,0));\n"
"float4 sample5 = SampleEFB(subBlockUL+float2(5,0));\n"
"float4 sample6 = SampleEFB(subBlockUL+float2(6,0));\n"
"float4 sample7 = SampleEFB(subBlockUL+float2(7,0));\n"
"float4 sample8 = SampleEFB(subBlockUL+float2(0,1));\n"
"float4 sample9 = SampleEFB(subBlockUL+float2(1,1));\n"
"float4 sampleA = SampleEFB(subBlockUL+float2(2,1));\n"
"float4 sampleB = SampleEFB(subBlockUL+float2(3,1));\n"
"float4 sampleC = SampleEFB(subBlockUL+float2(4,1));\n"
"float4 sampleD = SampleEFB(subBlockUL+float2(5,1));\n"
"float4 sampleE = SampleEFB(subBlockUL+float2(6,1));\n"
"float4 sampleF = SampleEFB(subBlockUL+float2(7,1));\n"
"uint4 dw4 = UINT4_8888_BE(\n"
"255*float4(sample0.b, sample4.b, sample8.b, sampleC.b),\n"
"255*float4(sample1.b, sample5.b, sample9.b, sampleD.b),\n"
"255*float4(sample2.b, sample6.b, sampleA.b, sampleE.b),\n"
"255*float4(sample3.b, sample7.b, sampleB.b, sampleF.b)\n"
");\n"
"return dw4;\n"
"}\n"
"uint4 Generate_B(float2 cacheCoord)\n" // G8 R8
"{\n"
"float2 blockCoord = floor(cacheCoord / float2(2,1));\n"
"float2 blockUL = blockCoord * float2(4,4);\n"
"float2 subBlockUL = blockUL + float2(0, 2*(cacheCoord.x%2));\n"
"float4 sample0 = SampleEFB(subBlockUL+float2(0,0));\n"
"float4 sample1 = SampleEFB(subBlockUL+float2(1,0));\n"
"float4 sample2 = SampleEFB(subBlockUL+float2(2,0));\n"
"float4 sample3 = SampleEFB(subBlockUL+float2(3,0));\n"
"float4 sample4 = SampleEFB(subBlockUL+float2(0,1));\n"
"float4 sample5 = SampleEFB(subBlockUL+float2(1,1));\n"
"float4 sample6 = SampleEFB(subBlockUL+float2(2,1));\n"
"float4 sample7 = SampleEFB(subBlockUL+float2(3,1));\n"
"uint4 dw4 = UINT4_8888_BE(\n"
"255*float4(sample0.g, sample2.g, sample4.g, sample6.g),\n"
"255*float4(sample0.r, sample2.r, sample4.r, sample6.r),\n"
"255*float4(sample1.g, sample3.g, sample5.g, sample7.g),\n"
"255*float4(sample1.r, sample3.r, sample5.r, sample7.r)\n"
");\n"
"return dw4;\n"
"}\n"
// FIXME: Untested
"uint4 Generate_C(float2 cacheCoord)\n" // B8 G8
"{\n"
"float2 blockCoord = floor(cacheCoord / float2(2,1));\n"
"float2 blockUL = blockCoord * float2(4,4);\n"
"float2 subBlockUL = blockUL + float2(0, 2*(cacheCoord.x%2));\n"
"float4 sample0 = SampleEFB(subBlockUL+float2(0,0));\n"
"float4 sample1 = SampleEFB(subBlockUL+float2(1,0));\n"
"float4 sample2 = SampleEFB(subBlockUL+float2(2,0));\n"
"float4 sample3 = SampleEFB(subBlockUL+float2(3,0));\n"
"float4 sample4 = SampleEFB(subBlockUL+float2(0,1));\n"
"float4 sample5 = SampleEFB(subBlockUL+float2(1,1));\n"
"float4 sample6 = SampleEFB(subBlockUL+float2(2,1));\n"
"float4 sample7 = SampleEFB(subBlockUL+float2(3,1));\n"
"uint4 dw4 = UINT4_8888_BE(\n"
"255*float4(sample0.b, sample2.b, sample4.b, sample6.b),\n"
"255*float4(sample0.g, sample2.g, sample4.g, sample6.g),\n"
"255*float4(sample1.b, sample3.b, sample5.b, sample7.b),\n"
"255*float4(sample1.g, sample3.g, sample5.g, sample7.g)\n"
");\n"
"return dw4;\n"
"}\n"
"#ifdef DYNAMIC_MODE\n"
"interface iGenerator\n"
"{\n"
"uint4 Generate(float2 cacheCoord);\n"
"};\n"
"class cGenerator_4 : iGenerator\n"
"{\n"
"uint4 Generate(float2 cacheCoord)\n"
"{ return Generate_4(cacheCoord); }\n"
"};\n"
"class cGenerator_5 : iGenerator\n"
"{\n"
"uint4 Generate(float2 cacheCoord)\n"
"{ return Generate_5(cacheCoord); }\n"
"};\n"
"class cGenerator_6 : iGenerator\n"
"{\n"
"uint4 Generate(float2 cacheCoord)\n"
"{ return Generate_6(cacheCoord); }\n"
"};\n"
"class cGenerator_8 : iGenerator\n"
"{\n"
"uint4 Generate(float2 cacheCoord)\n"
"{ return Generate_8(cacheCoord); }\n"
"};\n"
"class cGenerator_B : iGenerator\n"
"{\n"
"uint4 Generate(float2 cacheCoord)\n"
"{ return Generate_B(cacheCoord); }\n"
"};\n"
// Declare generator interface; must be set by application
"iGenerator g_generator;\n"
"#define IMP_GENERATOR g_generator.Generate\n"
"#endif\n"
"#ifndef IMP_GENERATOR\n"
"#error No generator specified\n"
"#endif\n"
"void main(out uint4 ocol0 : SV_Target, in float4 Pos : SV_Position, in float2 fCacheCoord : ENCODECOORD)\n"
"{\n"
"float2 cacheCoord = floor(fCacheCoord);\n"
"ocol0 = IMP_GENERATOR(cacheCoord);\n"
"}\n"
;
PSTextureEncoder::PSTextureEncoder()
: m_ready(false), m_out(NULL), m_outRTV(NULL), m_outStage(NULL),
m_encodeParams(NULL),
m_quad(NULL), m_vShader(NULL), m_quadLayout(NULL),
m_efbEncodeBlendState(NULL), m_efbEncodeDepthState(NULL),
m_efbEncodeRastState(NULL), m_efbSampler(NULL),
m_dynamicShader(NULL), m_classLinkage(NULL)
{
for (size_t i = 0; i < 4; ++i)
m_fetchClass[i] = NULL;
for (size_t i = 0; i < 2; ++i)
m_scaledFetchClass[i] = NULL;
for (size_t i = 0; i < 2; ++i)
m_intensityClass[i] = NULL;
for (size_t i = 0; i < 16; ++i)
m_generatorClass[i] = NULL;
}
static const D3D11_INPUT_ELEMENT_DESC QUAD_LAYOUT_DESC[] = {
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }
};
static const struct QuadVertex
{
float posX;
float posY;
} QUAD_VERTS[4] = { { 0, 0 }, { 1, 0 }, { 0, 1 }, { 1, 1 } };
void PSTextureEncoder::Init()
{
m_ready = false;
HRESULT hr;
// Create output texture RGBA format
// This format allows us to generate one cache line in two pixels.
D3D11_TEXTURE2D_DESC t2dd = CD3D11_TEXTURE2D_DESC(
DXGI_FORMAT_R32G32B32A32_UINT,
EFB_WIDTH, EFB_HEIGHT/4, 1, 1, D3D11_BIND_RENDER_TARGET);
hr = D3D::device->CreateTexture2D(&t2dd, NULL, &m_out);
CHECK(SUCCEEDED(hr), "create efb encode output texture");
D3D::SetDebugObjectName(m_out, "efb encoder output texture");
// Create output render target view
D3D11_RENDER_TARGET_VIEW_DESC rtvd = CD3D11_RENDER_TARGET_VIEW_DESC(m_out,
D3D11_RTV_DIMENSION_TEXTURE2D, DXGI_FORMAT_R32G32B32A32_UINT);
hr = D3D::device->CreateRenderTargetView(m_out, &rtvd, &m_outRTV);
CHECK(SUCCEEDED(hr), "create efb encode output render target view");
D3D::SetDebugObjectName(m_outRTV, "efb encoder output rtv");
// Create output staging buffer
t2dd.Usage = D3D11_USAGE_STAGING;
t2dd.BindFlags = 0;
t2dd.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
hr = D3D::device->CreateTexture2D(&t2dd, NULL, &m_outStage);
CHECK(SUCCEEDED(hr), "create efb encode output staging buffer");
D3D::SetDebugObjectName(m_outStage, "efb encoder output staging buffer");
// Create constant buffer for uploading data to shaders
D3D11_BUFFER_DESC bd = CD3D11_BUFFER_DESC(sizeof(EFBEncodeParams),
D3D11_BIND_CONSTANT_BUFFER);
hr = D3D::device->CreateBuffer(&bd, NULL, &m_encodeParams);
CHECK(SUCCEEDED(hr), "create efb encode params buffer");
D3D::SetDebugObjectName(m_encodeParams, "efb encoder params buffer");
// Create vertex quad
bd = CD3D11_BUFFER_DESC(sizeof(QUAD_VERTS), D3D11_BIND_VERTEX_BUFFER,
D3D11_USAGE_IMMUTABLE);
D3D11_SUBRESOURCE_DATA srd = { QUAD_VERTS, 0, 0 };
hr = D3D::device->CreateBuffer(&bd, &srd, &m_quad);
CHECK(SUCCEEDED(hr), "create efb encode quad vertex buffer");
D3D::SetDebugObjectName(m_quad, "efb encoder quad vertex buffer");
// Create vertex shader
D3DBlob* bytecode = NULL;
if (!D3D::CompileVertexShader(EFB_ENCODE_VS, sizeof(EFB_ENCODE_VS), &bytecode))
{
ERROR_LOG(VIDEO, "EFB encode vertex shader failed to compile");
return;
}
hr = D3D::device->CreateVertexShader(bytecode->Data(), bytecode->Size(), NULL, &m_vShader);
CHECK(SUCCEEDED(hr), "create efb encode vertex shader");
D3D::SetDebugObjectName(m_vShader, "efb encoder vertex shader");
// Create input layout for vertex quad using bytecode from vertex shader
hr = D3D::device->CreateInputLayout(QUAD_LAYOUT_DESC,
sizeof(QUAD_LAYOUT_DESC)/sizeof(D3D11_INPUT_ELEMENT_DESC),
bytecode->Data(), bytecode->Size(), &m_quadLayout);
CHECK(SUCCEEDED(hr), "create efb encode quad vertex layout");
D3D::SetDebugObjectName(m_quadLayout, "efb encoder quad layout");
bytecode->Release();
// Create pixel shader
#ifdef USE_DYNAMIC_MODE
if (!InitDynamicMode())
#else
if (!InitStaticMode())
#endif
return;
// Create blend state
D3D11_BLEND_DESC bld = CD3D11_BLEND_DESC(CD3D11_DEFAULT());
hr = D3D::device->CreateBlendState(&bld, &m_efbEncodeBlendState);
CHECK(SUCCEEDED(hr), "create efb encode blend state");
D3D::SetDebugObjectName(m_efbEncodeBlendState, "efb encoder blend state");
// Create depth state
D3D11_DEPTH_STENCIL_DESC dsd = CD3D11_DEPTH_STENCIL_DESC(CD3D11_DEFAULT());
dsd.DepthEnable = FALSE;
hr = D3D::device->CreateDepthStencilState(&dsd, &m_efbEncodeDepthState);
CHECK(SUCCEEDED(hr), "create efb encode depth state");
D3D::SetDebugObjectName(m_efbEncodeDepthState, "efb encoder depth state");
// Create rasterizer state
D3D11_RASTERIZER_DESC rd = CD3D11_RASTERIZER_DESC(CD3D11_DEFAULT());
rd.CullMode = D3D11_CULL_NONE;
rd.DepthClipEnable = FALSE;
hr = D3D::device->CreateRasterizerState(&rd, &m_efbEncodeRastState);
CHECK(SUCCEEDED(hr), "create efb encode rast state");
D3D::SetDebugObjectName(m_efbEncodeRastState, "efb encoder rast state");
// Create efb texture sampler
D3D11_SAMPLER_DESC sd = CD3D11_SAMPLER_DESC(CD3D11_DEFAULT());
sd.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
hr = D3D::device->CreateSamplerState(&sd, &m_efbSampler);
CHECK(SUCCEEDED(hr), "create efb encode texture sampler");
D3D::SetDebugObjectName(m_efbSampler, "efb encoder texture sampler");
m_ready = true;
}
void PSTextureEncoder::Shutdown()
{
m_ready = false;