DXGL r910 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r909‎ | r910 | r911 >
Date:00:44, 9 April 2019
Author:admin
Status:new
Tags:
Comment:
Decode YUV when Blting to RGB surface. Implement AYUV as a source format.
Modified paths:
  • /ddraw/ShaderGen2D.cpp (modified) (history)

Diff [purge]

Index: ddraw/ShaderGen2D.cpp
@@ -71,14 +71,12 @@
7272 0x16: 1-bit palette index (future)
7373 0x18: 24-bit Depth
7474 0x19: 24-bit Depth, 8-bit Stencil
75 -0x20: (first entry for specific RGB formats) (future)
76 -0x80: UYVY / UYNV
77 -0x81: YUY2 / YUNV
 75+0x20: 16-bit RGBG
 76+0x21: 16-bit GRGB
 77+0x80: UYVY / UYNV / Y422
 78+0x81: YUY2 / YUYV / YUNV
7879 0x82: YVYU
7980 0x83: AYUV
80 -0x9E: RGBG
81 -0x9F: GRGB
82 -0x84: AYUV
8381 0xC0: (first entry for compressed) (future)
8482 */
8583
@@ -148,6 +146,7 @@
149147 pattern = ivec4(texture2D(patterntex,patternst)*vec4(colorsizedest)+.5);\n";
150148 static const char op_destoutdestblend[] = "gl_FragColor = (vec4(pixel)/vec4(colorsizedest)) * texture2D(desttex,gl_TexCoord[1].st);\n";
151149 static const char op_destout[] = "gl_FragColor = vec4(pixel)/vec4(colorsizedest);\n";
 150+static const char op_destoutyuvrgb[] = "gl_FragColor = yuvatorgba(vec4(pixel)/vec4(colorsizedest));\n";
152151 static const char op_vertex[] = "vec4 xyzw = vec4(xy[0],xy[1],0,1);\n\
153152 mat4 proj = mat4(\n\
154153 vec4(2.0 / (view[1] - view[0]), 0, 0, 0),\n\
@@ -169,11 +168,24 @@
170169 static const char op_clip[] = "if(texture2D(stenciltex, gl_TexCoord[3].st).r < .5) discard;\n";
171170
172171 // Functions
173 -static const char func_yuvtorgb[] = "";
174 -static const char func_readuyvy[] = "";
175 -static const char func_readyuy2[] = "";
 172+static const char func_yuvatorgba[] =
 173+"vec4 yuvatorgba(vec4 yuva)\n\
 174+{\n\
 175+ vec4 rgba;\n\
 176+ yuva.r = 1.1643 * (yuva.r - 0.0625);\n\
 177+ yuva.g = yuva.g - 0.5;\n\
 178+ yuva.b = yuva.b - 0.5;\n\
 179+ rgba.r = yuva.r + (1.5958 * yuva.b);\n\
 180+ rgba.g = yuva.r - (0.39173 * yuva.g) - (0.8129 * yuva.b);\n\
 181+ rgba.b = yuva.r + (2.017 * yuva.g);\n\
 182+ rgba.a = yuva.a;\n\
 183+ return rgba;\n\
 184+}\n\n";
176185 static const char func_readrgbg[] = "";
177186 static const char func_readgrgb[] = "";
 187+static const char func_readuyvy[] = "";
 188+static const char func_readyuyv[] = "";
 189+static const char func_readyvyu[] = "";
178190
179191 // ROP Operations
180192 static const char *op_ROP[256] = {
@@ -871,12 +883,14 @@
872884 {
873885 switch (srctype)
874886 {
 887+ case 0x20:
 888+ case 0x21:
875889 case 0x80:
876890 case 0x81:
877891 case 0x82:
878 - case 0x83:
879892 String_Append(fsrc, unif_srctexrect);
880893 break;
 894+ case 0x83:
881895 default:
882896 String_Append(fsrc, unif_srctex);
883897 break;
@@ -934,6 +948,10 @@
935949 // Functions
936950 switch (srctype2)
937951 {
 952+ case 0x20:
 953+ break;
 954+ case 0x21:
 955+ break;
938956 case 0x80:
939957 break;
940958 case 0x81:
@@ -941,6 +959,7 @@
942960 case 0x82:
943961 break;
944962 case 0x83:
 963+ String_Append(fsrc, func_yuvatorgba);
945964 break;
946965 default:
947966 break;
@@ -954,7 +973,8 @@
955974 {
956975 switch (srctype2)
957976 {
958 - case 0x00:
 977+ case 0x00: // Classic RGB
 978+ case 0x83: // AYUV
959979 default:
960980 String_Append(fsrc, op_pixel);
961981 break;
@@ -971,6 +991,10 @@
972992 case 0x19:
973993 String_Append(fsrc, op_pixelmul256);
974994 break;
 995+ case 0x20:
 996+ break;
 997+ case 0x21:
 998+ break;
975999 case 0x80:
9761000 break;
9771001 case 0x81:
@@ -977,8 +1001,6 @@
9781002 break;
9791003 case 0x82:
9801004 break;
981 - case 0x83:
982 - break;
9831005 }
9841006 }
9851007 if (id & DDBLT_KEYSRC) String_Append(fsrc, op_src);
@@ -1004,7 +1026,18 @@
10051027 }
10061028 if (dxglcfg.DebugBlendDestColorKey && (id & DDBLT_KEYDEST))
10071029 String_Append(fsrc, op_destoutdestblend);
1008 - else String_Append(fsrc, op_destout);
 1030+ else
 1031+ {
 1032+ switch (srctype2)
 1033+ {
 1034+ case 0x83:
 1035+ String_Append(fsrc, op_destoutyuvrgb);
 1036+ break;
 1037+ default:
 1038+ String_Append(fsrc, op_destout);
 1039+ break;
 1040+ }
 1041+ }
10091042 String_Append(fsrc, mainend);
10101043 #ifdef _DEBUG
10111044 OutputDebugStringA("2D blitter fragment shader:\n");