From 92cb93cb1d839f8b1101e1d46903898093fbb843 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 24 Apr 2023 14:01:53 +0200 Subject: [PATCH 01/14] Add blank UWP unit test project --- ComputeSharp.sln | 19 +++ .../ComputeSharp.D2D1.UI.Tests.projitems | 13 ++ .../ComputeSharp.D2D1.UI.Tests.shproj | 13 ++ .../Assets/LockScreenLogo.scale-200.png | Bin 0 -> 1430 bytes .../Assets/SplashScreen.scale-200.png | Bin 0 -> 7700 bytes .../Assets/Square150x150Logo.scale-200.png | Bin 0 -> 2937 bytes .../Assets/Square44x44Logo.scale-200.png | Bin 0 -> 1647 bytes ...x44Logo.targetsize-24_altform-unplated.png | Bin 0 -> 1255 bytes .../Assets/StoreLogo.png | Bin 0 -> 1451 bytes .../Assets/Wide310x150Logo.scale-200.png | Bin 0 -> 3204 bytes .../ComputeSharp.D2D1.Uwp.Tests.csproj | 117 ++++++++++++++++++ .../Package.appxmanifest | 44 +++++++ .../Properties/AssemblyInfo.cs | 16 +++ .../Properties/Default.rd.xml | 22 ++++ .../UnitTestApp.xaml | 4 + .../UnitTestApp.xaml.cs | 31 +++++ 16 files changed, 279 insertions(+) create mode 100644 tests/ComputeSharp.D2D1.UI.Tests/ComputeSharp.D2D1.UI.Tests.projitems create mode 100644 tests/ComputeSharp.D2D1.UI.Tests/ComputeSharp.D2D1.UI.Tests.shproj create mode 100644 tests/ComputeSharp.D2D1.Uwp.Tests/Assets/LockScreenLogo.scale-200.png create mode 100644 tests/ComputeSharp.D2D1.Uwp.Tests/Assets/SplashScreen.scale-200.png create mode 100644 tests/ComputeSharp.D2D1.Uwp.Tests/Assets/Square150x150Logo.scale-200.png create mode 100644 tests/ComputeSharp.D2D1.Uwp.Tests/Assets/Square44x44Logo.scale-200.png create mode 100644 tests/ComputeSharp.D2D1.Uwp.Tests/Assets/Square44x44Logo.targetsize-24_altform-unplated.png create mode 100644 tests/ComputeSharp.D2D1.Uwp.Tests/Assets/StoreLogo.png create mode 100644 tests/ComputeSharp.D2D1.Uwp.Tests/Assets/Wide310x150Logo.scale-200.png create mode 100644 tests/ComputeSharp.D2D1.Uwp.Tests/ComputeSharp.D2D1.Uwp.Tests.csproj create mode 100644 tests/ComputeSharp.D2D1.Uwp.Tests/Package.appxmanifest create mode 100644 tests/ComputeSharp.D2D1.Uwp.Tests/Properties/AssemblyInfo.cs create mode 100644 tests/ComputeSharp.D2D1.Uwp.Tests/Properties/Default.rd.xml create mode 100644 tests/ComputeSharp.D2D1.Uwp.Tests/UnitTestApp.xaml create mode 100644 tests/ComputeSharp.D2D1.Uwp.Tests/UnitTestApp.xaml.cs diff --git a/ComputeSharp.sln b/ComputeSharp.sln index 97cfd4ee..1f3e2fa9 100644 --- a/ComputeSharp.sln +++ b/ComputeSharp.sln @@ -150,6 +150,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Assets", "Assets", "{345F62 assets\icon_highres.png = assets\icon_highres.png EndProjectSection EndProject +Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "ComputeSharp.D2D1.UI.Tests", "tests\ComputeSharp.D2D1.UI.Tests\ComputeSharp.D2D1.UI.Tests.shproj", "{346AEB10-A4EA-427E-8578-F60915DB3053}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputeSharp.D2D1.Uwp.Tests", "tests\ComputeSharp.D2D1.Uwp.Tests\ComputeSharp.D2D1.Uwp.Tests.csproj", "{4D4BB2F6-5653-4DB5-A8DD-90D58D8FE4D3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -414,6 +418,18 @@ Global {9EA5AE9D-C39A-4F43-B03E-0A848EA2558A}.Release|ARM64.Build.0 = Release|ARM64 {9EA5AE9D-C39A-4F43-B03E-0A848EA2558A}.Release|x64.ActiveCfg = Release|x64 {9EA5AE9D-C39A-4F43-B03E-0A848EA2558A}.Release|x64.Build.0 = Release|x64 + {4D4BB2F6-5653-4DB5-A8DD-90D58D8FE4D3}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {4D4BB2F6-5653-4DB5-A8DD-90D58D8FE4D3}.Debug|ARM64.Build.0 = Debug|ARM64 + {4D4BB2F6-5653-4DB5-A8DD-90D58D8FE4D3}.Debug|ARM64.Deploy.0 = Debug|ARM64 + {4D4BB2F6-5653-4DB5-A8DD-90D58D8FE4D3}.Debug|x64.ActiveCfg = Debug|x64 + {4D4BB2F6-5653-4DB5-A8DD-90D58D8FE4D3}.Debug|x64.Build.0 = Debug|x64 + {4D4BB2F6-5653-4DB5-A8DD-90D58D8FE4D3}.Debug|x64.Deploy.0 = Debug|x64 + {4D4BB2F6-5653-4DB5-A8DD-90D58D8FE4D3}.Release|ARM64.ActiveCfg = Release|ARM64 + {4D4BB2F6-5653-4DB5-A8DD-90D58D8FE4D3}.Release|ARM64.Build.0 = Release|ARM64 + {4D4BB2F6-5653-4DB5-A8DD-90D58D8FE4D3}.Release|ARM64.Deploy.0 = Release|ARM64 + {4D4BB2F6-5653-4DB5-A8DD-90D58D8FE4D3}.Release|x64.ActiveCfg = Release|x64 + {4D4BB2F6-5653-4DB5-A8DD-90D58D8FE4D3}.Release|x64.Build.0 = Release|x64 + {4D4BB2F6-5653-4DB5-A8DD-90D58D8FE4D3}.Release|x64.Deploy.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -451,6 +467,8 @@ Global {568E7009-5C13-4153-9C94-0AC7A3E6883C} = {1A9C4108-F61A-4ABE-B5CF-F524521EAE2D} {B54B6DCA-6EAB-46A8-83D3-15154659F47F} = {1A9C4108-F61A-4ABE-B5CF-F524521EAE2D} {9EA5AE9D-C39A-4F43-B03E-0A848EA2558A} = {0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1} + {346AEB10-A4EA-427E-8578-F60915DB3053} = {F8EFBB27-4EE2-4463-A75B-7EFDFB55D0F7} + {4D4BB2F6-5653-4DB5-A8DD-90D58D8FE4D3} = {F8EFBB27-4EE2-4463-A75B-7EFDFB55D0F7} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {4664C5E3-0340-4E22-BCFD-98AAEDF5F2DC} @@ -464,6 +482,7 @@ Global src\TerraFX.Interop.Windows.Dynamic\TerraFX.Interop.Windows.Dynamic.projitems*{158f984d-cd96-4062-bd02-2268946031a0}*SharedItemsImports = 13 samples\ComputeSharp.SwapChain.Shaders.D2D1.Shared\ComputeSharp.SwapChain.Shaders.D2D1.Shared.projitems*{209c95a3-fa53-431b-b688-3299ca6c29d2}*SharedItemsImports = 5 src\TerraFX.Interop.Windows\TerraFX.Interop.Windows.projitems*{314eb353-e7e3-4146-8111-685cc83ec1de}*SharedItemsImports = 5 + tests\ComputeSharp.D2D1.UI.Tests\ComputeSharp.D2D1.UI.Tests.projitems*{346aeb10-a4ea-427e-8578-f60915db3053}*SharedItemsImports = 13 src\TerraFX.Interop.Windows.D2D1\TerraFX.Interop.Windows.D2D1.projitems*{4d7d9ba8-a821-4b1c-9ee2-cbcf5849906e}*SharedItemsImports = 5 src\TerraFX.Interop.Windows\TerraFX.Interop.Windows.projitems*{514ff00e-bbf0-4d55-a47c-eeeb6208adce}*SharedItemsImports = 13 src\ComputeSharp.SourceGeneration\ComputeSharp.SourceGeneration.projitems*{51d5a422-d3a5-4c4d-8a6d-a048940bf279}*SharedItemsImports = 13 diff --git a/tests/ComputeSharp.D2D1.UI.Tests/ComputeSharp.D2D1.UI.Tests.projitems b/tests/ComputeSharp.D2D1.UI.Tests/ComputeSharp.D2D1.UI.Tests.projitems new file mode 100644 index 00000000..b7d37ed3 --- /dev/null +++ b/tests/ComputeSharp.D2D1.UI.Tests/ComputeSharp.D2D1.UI.Tests.projitems @@ -0,0 +1,13 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + 346aeb10-a4ea-427e-8578-f60915db3053 + + + ComputeSharp.D2D1.UI.Tests + + + + diff --git a/tests/ComputeSharp.D2D1.UI.Tests/ComputeSharp.D2D1.UI.Tests.shproj b/tests/ComputeSharp.D2D1.UI.Tests/ComputeSharp.D2D1.UI.Tests.shproj new file mode 100644 index 00000000..9abf6f55 --- /dev/null +++ b/tests/ComputeSharp.D2D1.UI.Tests/ComputeSharp.D2D1.UI.Tests.shproj @@ -0,0 +1,13 @@ + + + + 346aeb10-a4ea-427e-8578-f60915db3053 + 14.0 + + + + + + + + diff --git a/tests/ComputeSharp.D2D1.Uwp.Tests/Assets/LockScreenLogo.scale-200.png b/tests/ComputeSharp.D2D1.Uwp.Tests/Assets/LockScreenLogo.scale-200.png new file mode 100644 index 0000000000000000000000000000000000000000..735f57adb5dfc01886d137b4e493d7e97cf13af3 GIT binary patch literal 1430 zcmaJ>TTC2P7~aKltDttVHYH6u8Io4i*}3fO&d$gd*bA_<3j~&e7%8(eXJLfhS!M@! zKrliY>>6yT4+Kr95$!DoD(Qn-5TP|{V_KS`k~E6(LGS@#`v$hQo&^^BKsw3HIsZBT z_y6C2n`lK@apunKojRQ^(_P}Mgewt$(^BBKCTZ;*xa?J3wQ7~@S0lUvbcLeq1Bg4o zH-bvQi|wt~L7q$~a-gDFP!{&TQfc3fX*6=uHv* zT&1&U(-)L%Xp^djI2?~eBF2cxC@YOP$+9d?P&h?lPy-9M2UT9fg5jKm1t$m#iWE{M zIf%q9@;fyT?0UP>tcw-bLkz;s2LlKl2qeP0w zECS7Ate+Awk|KQ+DOk;fl}Xsy4o^CY=pwq%QAAKKl628_yNPsK>?A>%D8fQG6IgdJ ztnxttBz#NI_a@fk7SU`WtrpsfZsNs9^0(2a z@C3#YO3>k~w7?2hipBf{#b6`}Xw1hlG$yi?;1dDs7k~xDAw@jiI*+tc;t2Lflg&bM)0!Y;0_@=w%`LW^8DsYpS#-bLOklX9r?Ei}TScw|4DbpW%+7 zFgAI)f51s}{y-eWb|vrU-Ya!GuYKP)J7z#*V_k^Xo>4!1Yqj*m)x&0L^tg3GJbVAJ zJ-Pl$R=NAabouV=^z_t;^K*0AvFs!vYU>_<|I^#c?>>CR<(T?=%{;U=aI*SbZADLH z&(f2wz_Y0??Tf|g;?|1Znw6}6U43Q#qNRwv1vp9uFn1)V#*4p&%$mP9x&15^OaBiDS(XppT|z^>;B{PLVEbS3IFYV yGvCsSX*m literal 0 HcmV?d00001 diff --git a/tests/ComputeSharp.D2D1.Uwp.Tests/Assets/SplashScreen.scale-200.png b/tests/ComputeSharp.D2D1.Uwp.Tests/Assets/SplashScreen.scale-200.png new file mode 100644 index 0000000000000000000000000000000000000000..023e7f1feda78d5100569825acedfd213a0d84e9 GIT binary patch literal 7700 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 literal 0 HcmV?d00001 diff --git a/tests/ComputeSharp.D2D1.Uwp.Tests/Assets/Square150x150Logo.scale-200.png b/tests/ComputeSharp.D2D1.Uwp.Tests/Assets/Square150x150Logo.scale-200.png new file mode 100644 index 0000000000000000000000000000000000000000..af49fec1a5484db1d52a7f9b5ec90a27c7030186 GIT binary patch literal 2937 zcma)84OCO-8BSud5)jwMLRVKgX(S?$n?Ld|vrsm<$CF7)&zTbyy1FE5bU`Q17MRv`9ue$;R(@8kR;#vJ*IM0>cJIAOte!d7oRgdH zd%ySjdB6L9=gX^A6)VzH7p2l@v~3zJAMw|DFy#^)F@@F*`mqUn=Il>l)8_+ab;nOW{%+iPx z+s{Eu|&pIs)Z7{La9~?xKfyl z#43?gjEL15d4WbOZo#SiP%>DB^+BcnJ=7dHEe;r#G=tuw|ka z%q@}##Uh7;tc%L_64m(kHtw74ty%BJMb)_1)#S0j`)F8_1jF7vScpsnH=0V19bO8y zR`0SjIdCUo&=>JwMQF8KHA<{ODHTiQh}0^@5QRmCA?gOH6_H3K^-_sNB^RrdNuK-R zOO*vOrKCVvDwgUck`kF(E7j{I#iiN;b*ZdCt4m@HPA`EuEqGGf4%!K<;(=I=&Vyrw z%TwcWtxa}8mCZ%Cyf&ActJ6_$ox5z6-D!0-dvnRx6t7y3d+h6QYpKWO;8OdnvERo7 zuEf>ih5`wqY)~o@OeVt-wM?Q!>QzdGRj!bz6fzYrfw$hZfAKzr2-M+D+R>}~oT574c;_3zquHcElqKIsryILt3g8n3jcMb+j?i?-L3FpZJ z2WRVBRdDPc+G5aaYg#5hpE+6nQ|(VSoxT3|biF;BUq#==-27Xi=gihDPYP$7?=9cP zYKE$jeQ|3~_L0VG-(F~2ZPyD0=k{J4Q~h(t__{-mz_w8{JDY9{`1ouzz!Vr5!ECdE z6U~O1k8c}24V7~zzXWTV-Pe4)y}wQJS&q%H5`Fo_f_JvIU489aCX$;P`u#!I-=^4ijC2{&9!O&h>mi?9oYD=GC#%)6{GzN6nQYw+Fal50!#x^asjBBR50i`+mho*ttoqV)ubM2KD9S~k7+FR4>{29?6 z{!l6kDdyTN0YJ9LgkPWeXm|gyi@zM3?0@{&pXT12w|78&W-q!RRF)&iLCEZVH<|fR zN0fr2^t8H(>L?>K#>^+jWROLral(Qy-xoBq1U7A&DV||wClb)Otd9?(gZ|8znMF}D zf<1haWz^s0qgecz;RFGt0C-B4g`jNGHsFU+;{<%t65v^sjk^h$lmWn#B0#_)9ij&d z-~lc`A)YYExi^7sBuPM^Y|wA2g*5?`K?#7tzELQYNxGo$UB$4J8RJp1k(8Jj+~hMT zlN~>M@KTTh^--8y3PK_NZ@AC!{PT=CziBzGd+wTJ^@icH!Bd}%)g8V)%K?|c&WTUk zy}qv1C%(fjRoZ4ozC3{O%@5?)XzH35zHns$pgU*Q?fj4v?fp1Qbm+j;3l;9jam9Da zXVcKjPlQ73x78QPu|Ffm6x?`~e3oD=gl=4kYK?={kD5j~QCXU)`HSdduNNENzA*2$ zOm3PzF!lN5e*06-f1Uot67wY#{o-S1!KZ7E=!~7ynnk9_iJR#kFoNbAOT#^2Gd17F zMmvU6>lndZQGd|ax9kUoXXO+$N?|j@6qpsF&_j7YXvwo_C{JpmLw5&#e6k>atv%es z5)7r*Wvv_JkUpT}M!_o!nVlEk1Zbl=a*2hQ*<|%*K1Glj^FcF`6kTzGQ3lz~2tCc@ z&x|tj;aH&1&9HwcJBcT`;{?a+pnej;M1HO(6Z{#J!cZA04hnFl;NXA+&`=7bjW_^o zfC40u3LMG?NdPtwGl>Tq6u}*QG)}-y;)lu-_>ee3kibW(69n0$0Zy!}9rQz%*v1iO zT9_H>99yIrSPYVy6^);rR}7Yo=J_T@hi+qhTZXnVWyf;JDYm5#eYLTxr*?kiNn!+Y zQ+LUkBafNJ#rH#C(?d5^;gw9o#%daEI{mA*LHPIHPU`#|H$hD zwm>0&+kahQ)E#%~k>&5@&#Vg82H?s%71=)(soi@174pi9--2{w{1$}Sz4zGn3Du&x bht0Iza^2ykEt4(epJ78uh5nDlX8(TxzDYwP literal 0 HcmV?d00001 diff --git a/tests/ComputeSharp.D2D1.Uwp.Tests/Assets/Square44x44Logo.scale-200.png b/tests/ComputeSharp.D2D1.Uwp.Tests/Assets/Square44x44Logo.scale-200.png new file mode 100644 index 0000000000000000000000000000000000000000..ce342a2ec8a61291ba76c54604aea7e9d20af11b GIT binary patch literal 1647 zcmaJ?eM}Q)7(e+G1Q(|`V9JhTI2>MkceK4;p;PR&$Pi?ejk3YQ_3o`S&|W_dsOZ8# zWPTt69g`t$ab`0cj-Y0yiBSOqmd)tG7G(}M5aP0_%&9TijB#&)I{zSE^4@#z^FF`l z`8{8`o%wlL(UI|y2!cdsuVamHH~H86F!*-15em4)NqUpCQM5?aoC_eCf@lV4wvF2a zjDQn1JBL69f&@2M3rvzJcfE!eZ8FZUBlFlC5RD)it33{mF9#B82AiyQE%w)`vlwa> zv{<1sm&kSKK$&%2jSFn7$t&P%%6Ue>R=EAnG8N7fqynWG8L3p!4801a;8{+nliO(qd(jNJ_?+9W3#hLIDLoT6~3fx9=`CC-D}-AMrpEO7HK zt3$GicGPc?GmDjy7K2P@La;eu4!$zWCZ`ym{Z$b zu-O6RM&K4JT|BIZB`E-gxqG%FzanI#+2FFmqHqXG7yxWB=w55RGOM)$xMb(>kSNR z2w=1AZi%z=AmG~yea~XaXJR!v7vLn(RUnELfiB1|6D84ICOS}^Zo2AdN}<&*h}G_u z{xZ!(%>tLT3J3<5XhWy-tg+6)0nmUUENLW8TWA{R6bgVd3X;anYFZ^IRis*_P-C-r z;i>%1^eL3UI2-{w8nuFFcs0e~7J{O2k^~Ce%+Ly4U?|=!0LH=t6()xi<^I-rs+9sF z*q{E-CxZbGPeu#a;XJwE;9S1?#R&uns>^0G3p`hEUF*v`M?@h%T%J%RChmD|EVydq zmHWh*_=S%emRC*mhxaVLzT@>Z2SX0u9v*DIJ@WC^kLVdlGV6LpK$KIrlJqc zpJ921)+3JJdTx|<`G&kXpKkjGJv=76R`yYIQ{#c-`%+`#V(7}Q;&@6U8!Td1`d;?N z_9mnI#?AA}4J!r)LN4!E-@H5eXauuB7TOawS>Y|{-P?NNx-lq+z1W-+y(;39P&&LP zL{N80?&=C*qKmdA^moMZRuPcD!B<*mq$ch=0Cnlitw#txRWhb3%TQvPqjkC`F69G4b! ze7z9MZ#+;_#l?H37UqUhDFb^l&s2{oM$3I0o^Q!yx;;V)QmCMo)Tb_ui|mit8MS?U zm##6$sZZ1$@|s%?l@>4Z<*Q}sRBSKMhb4I{e5LdEhsHIHTe8Bod5c>6QtT>$XgUBz z6MK`kO$=jmt@FqggOhJ5j~e@ygRbG;<{Vu)*+nn9aQeo0;$#j;|MS=S$&L?BeV25z xs3B`@=#`5TF{^6(A1rvdY@|-RtQ|iS5{tyX+wH?;n8E)G$kykv-D^wh{{!TZT%7;_ literal 0 HcmV?d00001 diff --git a/tests/ComputeSharp.D2D1.Uwp.Tests/Assets/Square44x44Logo.targetsize-24_altform-unplated.png b/tests/ComputeSharp.D2D1.Uwp.Tests/Assets/Square44x44Logo.targetsize-24_altform-unplated.png new file mode 100644 index 0000000000000000000000000000000000000000..f6c02ce97e0a802b85f6021e822c89f8bf57d5cd GIT binary patch literal 1255 zcmaJ>TWs4@7*5+{G#S+&C!qC#> zf>5N3P6jO*Cz>ug*(_DmW=)kea&m$gZ^+nyiF`;j%w@}y8)>p*SH}C`m?DXeieF2U zyQHecc_L%Gh!7GMt+hG06y;+|p4>m~}PjA}rKViGiEnn7G0ZO<>G|7q;2?NwGCM3s?eued6%hd$B+ z*kQJ{#~$S=DFE(%=E+UkmlEI*%3llUf~8Ja9YU1Vui0IbGBkW_gHB%Rd&!!ioX zs40O?i9I{};kle7GMvE7(rk`la=gTI)47=>%?q@^iL-nUo3}h4S}N-KHn8t5mVP8w z&bSErwp+37 zNJJ8?a|{r5Q3R0Z5s-LB1WHOwYC@7pCHWND#cL1cZ?{kJ368_*(UDWUDyb<}0y@o# zfMF016iMWPCb6obAxT$JlB6(2DrlXDTB&!0`!m??4F(qWMhjVZo?JXQmz`1*58Z=& zcDmB|S-E@j?BoFGix0flckqdS4jsPNzhfWyWIM98GxcLs89C(~dw%$_t;JjX-SD}E zfiGV;{8Q%8r}w9x>EEigW81>`kvnU@pK)4+xk9@+bNj9L!AAZ@SZ@q|)&BmY3+HZx zul~BeG4|}-;L%cHViQGQX?^zFfO0&#cHwel=d`lH9sJ-@Sl@n*(8J2>%Ac`IxyY?Q z{=GhWvC#gu-~Ia7*n{=+;qM?Ul_wy1+u7ho;=`>EwP^g~R@{unBds`!#@}tluZQpS zm)M~nYEifJWJGx?_6DcTy>#uh%>!H9=hb^(v`=m3F1{L>db=<5_tm+_&knAQ2EU$s Mu9UqpbNZeC0BbUo^Z)<= literal 0 HcmV?d00001 diff --git a/tests/ComputeSharp.D2D1.Uwp.Tests/Assets/StoreLogo.png b/tests/ComputeSharp.D2D1.Uwp.Tests/Assets/StoreLogo.png new file mode 100644 index 0000000000000000000000000000000000000000..7385b56c0e4d3c6b0efe3324aa1194157d837826 GIT binary patch literal 1451 zcmaJ>eN5D57_Z|bH;{0+1#mbl)eTU3{h)Wf7EZV?;HD@XL@{B`Ui%(2aMxQ~xdXSv z5nzWi(LW)U2=Vc-cY@s7nPt{i0hc6!7xN4NNHI#EQl>YNBy8l4%x9gr_W-j zEZMQmmTIy(>;lblRfh`dIyTgc9W5d!VP$L4(kKrN1c5G~(O_#xG zAJCNTstD^5SeXFB+&$h=ToJP2H>xr$iqPs-#O*;4(!Fjw25-!gEb*)mU}=)J;Iu>w zxK(5XoD0wrPSKQ~rbL^Cw6O_03*l*}i=ydbu7adJ6y;%@tjFeXIXT+ms30pmbOP%Q zX}S;+LBh8Tea~TSkHzvX6$rYb)+n&{kSbIqh|c7hmlxmwSiq5iVhU#iEQ<>a18|O^Sln-8t&+t`*{qBWo5M?wFM(JuimAOb5!K#D}XbslM@#1ZVz_;!9U zpfEpLAOz=0g@bd6Xj_ILi-x^!M}73h^o@}hM$1jflTs|Yuj9AL@A3<-?MV4!^4q`e z)fO@A;{9K^?W?DbnesnPr6kK>$zaKo&;FhFd(GYFCIU^T+OIMb%Tqo+P%oq(IdX7S zf6+HLO?7o0m+p>~Tp5UrXWh!UH!wZ5kv!E`_w)PTpI(#Iw{AS`gH4^b(bm^ZCq^FZ zY9DD7bH}rq9mg88+KgA$Zp!iWncuU2n1AuIa@=sWvUR-s`Qb{R*kk(SPU^`$6BXz8 zn#7yaFOIK%qGxyi`dYtm#&qqox0$h=pNi#u=M8zUG@bpiZ=3sT=1}Trr}39cC)H|v zbL?W)=&s4zrh)7>L(|cc%$1#!zfL?HjpeP%T+x_a+jZ16b^iKOHxFEX$7d|8${H-* zIrOJ5w&i$>*D>AKaIoYg`;{L@jM((Kt?$N$5OnuPqVvq**Nm}(f0wwOF%iX_Pba;V z;m@wxX&NcV3?<1+u?A{y_DIj7#m3Af1rCE)o`D&Y3}0%7E;iX1yMDiS)sh0wKi!36 zL!Wmq?P^Ku&rK~HJd97KkLTRl>ScGFYZNlYytWnhmuu|)L&ND8_PmkayQb{HOY640 bno1(wj@u8DCVuFR|31B*4ek@pZJqxCDDe1x literal 0 HcmV?d00001 diff --git a/tests/ComputeSharp.D2D1.Uwp.Tests/Assets/Wide310x150Logo.scale-200.png b/tests/ComputeSharp.D2D1.Uwp.Tests/Assets/Wide310x150Logo.scale-200.png new file mode 100644 index 0000000000000000000000000000000000000000..288995b397fdbef1fb7e85afd71445d5de1952c5 GIT binary patch literal 3204 zcmbVPeQXow8NYmBd90>}0NP?GhXW~VaeThm=a0tV#EwJMI!)6M3}|c4_Bl3=Kd>G0 z(GHx1wl<7(tP?FsOQkTilSo*iIvF%uArExJ73~P zSv1xEy!U(Wd4A9D`FQV@W3@F^qJ@PEF$@z`Z!*BbFsS(^?B zyiAzJ+q})bkgiQHWqEb*jJD-coHYr1^iocg)l!Qa{Xqs-l~6J}p-|##ZHYofskQ3$ zI0;xzXyhazBeXhIsg5A=%ufo@f)1yy&ScKS0;HF^!r_2UE^lpZEom(+@duma3awTv zCrCL-%D_SvYWIcdHkmI}#50(fkUi)Qgx!80ju>g1za^}ff>JI8Z@^-iCiaCgg@TgF z+vtE?Q9{VQUX&MW9SYYmGcxA14%N2@7FwBTD4N<(2{nWgV8$e3?-F=L^&FrtWn~(U_Q~~^uYiyeY6-KoTnfh9AWz@ zIKje0)u!_Lw)E}G!#kEfwKVdNt(UAf9*f>tEL_(=xco-T%jTi@7YlC3hs2ik%Le0H ztj}RTeCF(5mwvi3_56>-yB?l;J>-1%!9~=fs|QcNG3J~a@JCu`4SB460s0ZO+##4fFUSGLcj_ja^fL4&BKALfb#$6$O?>P@qx2Agl^x0i&ugt zsy5Pyu=()`7HRMG3IB7F1@`_ z+-!J%#i6e^U$e#+C%Q>_qVRzWRsG^W_n+@OcX@vzI&z;mzHNb!GQ?LWA(wtpqHqTM z1OFw_{Zn?fD)p)`c`kOgv{de=v@suGRqY{N^U7gI1VF3*F=obwaXI6ob5__Yn zVTguS!%(NI09J8x#AO_aW!9W7k*UvB;IWDFC3srwftr{kHj%g)fvnAm;&h_dnl~

MY- zf+K}sCe8qU6Ujs`3ua{U0Of$R_gVQBuUA za0v=mu#vIOqiiAZOr&h*$WyOw&k-xr$;G4Ixa!#TJNr>95(h>l%)PUy4p+^SgR(uR zta%k*?ny-+nAr8spEk1fo{J4i!b^Fia`N{_F6@zidA2ZTTrjl#^5Z-2KfB@Cu}l9s z(*|Z2jc?p~vn2f)3y9i*7zJV1L{$?|&q)4oaT;uXi6>1GkRXVTOzAz(RHEmr=eFIi z`}<>-Q?K0GN8!IYxeP1XKXO+jsJbp~o^);Bc;%b7Flpe7;1`Ny@3r7ZR;?R)aJt8C ziNlEC<@3f_lIV4TwV}&e;D!Ee5_|e#g0LUh=5vmYWYm7&2h*M>QPKvGh9-)wfMMW3 z8J9b%1k7dzPzO0_NGQy92BZ^FR6R~6;^6?lqO;-QUP4BY%cG%3vEhbm#>4vIhPBh3 z-+pZGjh$x%Hp{?=FHsMp0&wNPlj00us{&`1ZOZTqs8%4X&xH=UDr*xyBW(Zp&Em94 zf)ZSfn#yg0N)>!1kWdkqJ^S*z0FF5|fj&qcE#Na|%OY0$uO>!&hP+1ywfD_WXk@4J(?MBftK7>$Nvqh@tDuarN%PrTLQ2Uzysx>UV=V zk^RrDSvdQ?0;=hY67EgII-f4`t=+i*yS=Y~!XlqIy_4x&%+OdfbKOFPXS2X5%4R{N z$SQMX^AK6(fA + + + + Debug + x64 + {4D4BB2F6-5653-4DB5-A8DD-90D58D8FE4D3} + AppContainerExe + Properties + ComputeSharp.D2D1.Uwp.Tests + ComputeSharp.D2D1.Uwp.Tests + en-US + UAP + 10.0.22621.0 + 10.0.17763.0 + 14 + 512 + {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(VisualStudioVersion) + false + + + true + bin\ARM64\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + full + ARM64 + false + prompt + true + true + + + bin\ARM64\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + true + ;2008 + pdbonly + ARM64 + false + prompt + true + true + + + true + bin\x64\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + full + x64 + false + prompt + true + + + bin\x64\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + true + ;2008 + pdbonly + x64 + false + prompt + true + true + + + PackageReference + + + + + + + + UnitTestApp.xaml + + + + + MSBuild:Compile + Designer + + + + + Designer + + + + + + + + + + + + + + + 6.2.14 + + + 2.2.7 + + + 2.2.7 + + + + 14.0 + + + \ No newline at end of file diff --git a/tests/ComputeSharp.D2D1.Uwp.Tests/Package.appxmanifest b/tests/ComputeSharp.D2D1.Uwp.Tests/Package.appxmanifest new file mode 100644 index 00000000..24fb011e --- /dev/null +++ b/tests/ComputeSharp.D2D1.Uwp.Tests/Package.appxmanifest @@ -0,0 +1,44 @@ + + + + + + + + + ComputeSharp.D2D1.Uwp.Tests + sergiopedri + Assets\StoreLogo.png + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/ComputeSharp.D2D1.Uwp.Tests/Properties/AssemblyInfo.cs b/tests/ComputeSharp.D2D1.Uwp.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..8fb8814e --- /dev/null +++ b/tests/ComputeSharp.D2D1.Uwp.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,16 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("ComputeSharp.D2D1.Uwp.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ComputeSharp.D2D1.Uwp.Tests")] +[assembly: AssemblyCopyright("Copyright © 2023")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: AssemblyMetadata("TargetPlatform","UAP")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: ComVisible(false)] \ No newline at end of file diff --git a/tests/ComputeSharp.D2D1.Uwp.Tests/Properties/Default.rd.xml b/tests/ComputeSharp.D2D1.Uwp.Tests/Properties/Default.rd.xml new file mode 100644 index 00000000..922d306f --- /dev/null +++ b/tests/ComputeSharp.D2D1.Uwp.Tests/Properties/Default.rd.xml @@ -0,0 +1,22 @@ + + + + + + + \ No newline at end of file diff --git a/tests/ComputeSharp.D2D1.Uwp.Tests/UnitTestApp.xaml b/tests/ComputeSharp.D2D1.Uwp.Tests/UnitTestApp.xaml new file mode 100644 index 00000000..606340e6 --- /dev/null +++ b/tests/ComputeSharp.D2D1.Uwp.Tests/UnitTestApp.xaml @@ -0,0 +1,4 @@ + diff --git a/tests/ComputeSharp.D2D1.Uwp.Tests/UnitTestApp.xaml.cs b/tests/ComputeSharp.D2D1.Uwp.Tests/UnitTestApp.xaml.cs new file mode 100644 index 00000000..0f6c05d2 --- /dev/null +++ b/tests/ComputeSharp.D2D1.Uwp.Tests/UnitTestApp.xaml.cs @@ -0,0 +1,31 @@ +using Windows.ApplicationModel.Activation; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; + +namespace ComputeSharp.D2D1.Uwp.Tests; + +///

+/// Provides application-specific behavior to supplement the default Application class. +/// +public sealed partial class App : Application +{ + /// + /// Creates a new instance. + /// + public App() + { + InitializeComponent(); + } + + /// + protected override void OnLaunched(LaunchActivatedEventArgs e) + { + Window.Current.Content ??= new Frame(); + + Microsoft.VisualStudio.TestPlatform.TestExecutor.UnitTestClient.CreateDefaultUI(); + + Window.Current.Activate(); + + Microsoft.VisualStudio.TestPlatform.TestExecutor.UnitTestClient.Run(e.Arguments); + } +} \ No newline at end of file From 204dba3ab5c06ebde5d124e2d3f76a085e9c394f Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 24 Apr 2023 17:32:35 +0200 Subject: [PATCH 02/14] Add basic PixelShaderEffect drawing and buffer tests --- ComputeSharp.sln | 2 + .../ComputeSharp.D2D1.UI.Tests.projitems | 5 +- .../PixelShaderEffectTests.cs | 76 ++++++++++++++++ .../ShadersTests.cs | 89 +++++++++++++++++++ .../ComputeSharp.D2D1.Uwp.Tests.csproj | 40 +++++++++ 5 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs create mode 100644 tests/ComputeSharp.D2D1.UI.Tests/ShadersTests.cs diff --git a/ComputeSharp.sln b/ComputeSharp.sln index 1f3e2fa9..987e7491 100644 --- a/ComputeSharp.sln +++ b/ComputeSharp.sln @@ -483,6 +483,8 @@ Global samples\ComputeSharp.SwapChain.Shaders.D2D1.Shared\ComputeSharp.SwapChain.Shaders.D2D1.Shared.projitems*{209c95a3-fa53-431b-b688-3299ca6c29d2}*SharedItemsImports = 5 src\TerraFX.Interop.Windows\TerraFX.Interop.Windows.projitems*{314eb353-e7e3-4146-8111-685cc83ec1de}*SharedItemsImports = 5 tests\ComputeSharp.D2D1.UI.Tests\ComputeSharp.D2D1.UI.Tests.projitems*{346aeb10-a4ea-427e-8578-f60915db3053}*SharedItemsImports = 13 + samples\ComputeSharp.SwapChain.Shaders.D2D1.Shared\ComputeSharp.SwapChain.Shaders.D2D1.Shared.projitems*{4d4bb2f6-5653-4db5-a8dd-90d58d8fe4d3}*SharedItemsImports = 4 + tests\ComputeSharp.D2D1.UI.Tests\ComputeSharp.D2D1.UI.Tests.projitems*{4d4bb2f6-5653-4db5-a8dd-90d58d8fe4d3}*SharedItemsImports = 4 src\TerraFX.Interop.Windows.D2D1\TerraFX.Interop.Windows.D2D1.projitems*{4d7d9ba8-a821-4b1c-9ee2-cbcf5849906e}*SharedItemsImports = 5 src\TerraFX.Interop.Windows\TerraFX.Interop.Windows.projitems*{514ff00e-bbf0-4d55-a47c-eeeb6208adce}*SharedItemsImports = 13 src\ComputeSharp.SourceGeneration\ComputeSharp.SourceGeneration.projitems*{51d5a422-d3a5-4c4d-8a6d-a048940bf279}*SharedItemsImports = 13 diff --git a/tests/ComputeSharp.D2D1.UI.Tests/ComputeSharp.D2D1.UI.Tests.projitems b/tests/ComputeSharp.D2D1.UI.Tests/ComputeSharp.D2D1.UI.Tests.projitems index b7d37ed3..fa0581dd 100644 --- a/tests/ComputeSharp.D2D1.UI.Tests/ComputeSharp.D2D1.UI.Tests.projitems +++ b/tests/ComputeSharp.D2D1.UI.Tests/ComputeSharp.D2D1.UI.Tests.projitems @@ -9,5 +9,8 @@ ComputeSharp.D2D1.UI.Tests + + + - + \ No newline at end of file diff --git a/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs b/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs new file mode 100644 index 00000000..674bd754 --- /dev/null +++ b/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs @@ -0,0 +1,76 @@ +using System; +using ComputeSharp.D2D1.Uwp; +using Microsoft.Graphics.Canvas; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace ComputeSharp.D2D1.UI.Tests; + +[TestClass] +[TestCategory("PixelShaderEffect")] +public partial class PixelShaderEffectTests +{ + [TestMethod] + public unsafe void ConstantBuffer_IsInitiallySetToDefault() + { + PixelShaderEffect effect = new(); + + ShaderWithSomeProperties shader = effect.ConstantBuffer; + ShaderWithSomeProperties defaultShader = default; + + ReadOnlySpan actual = new(&shader, sizeof(ShaderWithSomeProperties)); + ReadOnlySpan expected = new(&defaultShader, sizeof(ShaderWithSomeProperties)); + + // The default constant buffer is set to 0, and it can be retrieved correctly + Assert.IsTrue(actual.SequenceEqual(expected)); + } + + [TestMethod] + public unsafe void ConstantBuffer_RoundTripsCorrectly() + { + ShaderWithSomeProperties shader = new( + A: 3.14f, + B: 123456, + C: new int2(111, -222), + D: new uint2x2(8888, 123456, 98765, 192837465), + E: new float2(-3.14f, 6.28f)); + + PixelShaderEffect effect = new() { ConstantBuffer = shader }; + + ShaderWithSomeProperties roundTripShader = effect.ConstantBuffer; + + ReadOnlySpan expected = new(&shader, sizeof(ShaderWithSomeProperties)); + ReadOnlySpan actual = new(&roundTripShader, sizeof(ShaderWithSomeProperties)); + + // The resulting constant buffer matches the source, when the effect is not realized + Assert.IsTrue(actual.SequenceEqual(expected)); + + // Draw the effect, to force realization + using (CanvasRenderTarget renderTarget = new(new CanvasDevice(), 128, 128, 96.0f)) + using (CanvasDrawingSession drawingSession = renderTarget.CreateDrawingSession()) + { + drawingSession.DrawImage(effect); + } + + roundTripShader = effect.ConstantBuffer; + actual = new(&roundTripShader, sizeof(ShaderWithSomeProperties)); + + // The shader also matches when retrieving it through the realized effect + Assert.IsTrue(actual.SequenceEqual(expected)); + } + + [D2DInputCount(0)] + [AutoConstructor] + private partial struct ShaderWithSomeProperties : ID2D1PixelShader + { + public float A; + public int B; + public int2 C; + public uint2x2 D; + public float2 E; + + public float4 Execute() + { + return default; + } + } +} diff --git a/tests/ComputeSharp.D2D1.UI.Tests/ShadersTests.cs b/tests/ComputeSharp.D2D1.UI.Tests/ShadersTests.cs new file mode 100644 index 00000000..aa4378c5 --- /dev/null +++ b/tests/ComputeSharp.D2D1.UI.Tests/ShadersTests.cs @@ -0,0 +1,89 @@ +using System; +using System.IO; +using System.Threading.Tasks; +using ComputeSharp.D2D1.Uwp; +using ComputeSharp.SwapChain.Shaders.D2D1; +using ComputeSharp.Tests.Helpers; +using Microsoft.Graphics.Canvas; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.PixelFormats; +using Windows.Storage; + +namespace ComputeSharp.D2D1.UI.Tests; + +[TestClass] +[TestCategory("Shaders")] +public class ShadersTests +{ + [TestMethod] + public async Task HelloWorld() + { + await RunTestAsync(); + } + + [TestMethod] + public async Task ColorfulInfinity() + { + await RunTestAsync(); + } + + [TestMethod] + public async Task FractalTiling() + { + await RunTestAsync(); + } + + [TestMethod] + public async Task MengerJourney() + { + await RunTestAsync(0.000011f); + } + + [TestMethod] + public async Task Octagrams() + { + await RunTestAsync(); + } + + [TestMethod] + public async Task ProteanClouds() + { + await RunTestAsync(); + } + + [TestMethod] + public async Task TerracedHills() + { + await RunTestAsync(0.000026f); + } + + private static async Task RunTestAsync(float threshold = 0.00001f) + where T : unmanaged, ID2D1PixelShader + { + T shader = (T)Activator.CreateInstance(typeof(T), 0f, new int2(1280, 720))!; + PixelShaderEffect effect = new() { ConstantBuffer = shader }; + + byte[] pixelBytes; + + using (CanvasRenderTarget renderTarget = new(new CanvasDevice(), 1280, 720, 96.0f)) + { + // Draw the shader on the render target + using (CanvasDrawingSession drawingSession = renderTarget.CreateDrawingSession()) + { + drawingSession.DrawImage(effect); + } + + // Get the BGRA32 pixel data from the render target + pixelBytes = renderTarget.GetPixelBytes(); + } + + StorageFile imageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///Assets/Shaders/{typeof(T).Name}.png")); + + using Stream stream = await imageFile.OpenStreamForReadAsync(); + using Image expected = await Image.LoadAsync(stream); + using Image result = Image.WrapMemory(pixelBytes, 1280, 720); + + TolerantImageComparer.AssertEqual(expected, result, threshold); + } +} \ No newline at end of file diff --git a/tests/ComputeSharp.D2D1.Uwp.Tests/ComputeSharp.D2D1.Uwp.Tests.csproj b/tests/ComputeSharp.D2D1.Uwp.Tests/ComputeSharp.D2D1.Uwp.Tests.csproj index daae7b31..9e3a82af 100644 --- a/tests/ComputeSharp.D2D1.Uwp.Tests/ComputeSharp.D2D1.Uwp.Tests.csproj +++ b/tests/ComputeSharp.D2D1.Uwp.Tests/ComputeSharp.D2D1.Uwp.Tests.csproj @@ -90,6 +90,34 @@ + + Assets\Shaders\ColorfulInfinity.png + PreserveNewest + + + Assets\Shaders\FractalTiling.png + PreserveNewest + + + Assets\Shaders\HelloWorld.png + PreserveNewest + + + Assets\Shaders\MengerJourney.png + PreserveNewest + + + Assets\Shaders\Octagrams.png + PreserveNewest + + + Assets\Shaders\ProteanClouds.png + PreserveNewest + + + Assets\Shaders\TerracedHills.png + PreserveNewest + @@ -109,7 +137,19 @@ 2.2.7 + + 2.1.4 + + + + + + + + + + 14.0 From 5adce3d048408fa8be05c0db630e8475970ae2a3 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 25 Apr 2023 03:07:10 +0200 Subject: [PATCH 03/14] Add D2D1 UWP unit tests to CI script --- .github/workflows/dotnet.yml | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 35b382fa..cae3f955 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -71,7 +71,7 @@ jobs: path: artifacts\*.nupkg if-no-files-found: error - # Run all unit tests referencing the ComputeSharp project directly + # Run all unit tests referencing the ComputeSharp projects directly run-tests: needs: [build-solution] strategy: @@ -122,6 +122,32 @@ jobs: - name: Run ComputeSharp.D2D1.Tests.AssemblyLevelAttributes run: dotnet test tests\ComputeSharp.D2D1.Tests.AssemblyLevelAttributes\ComputeSharp.D2D1.Tests.AssemblyLevelAttributes.csproj -c Release -f ${{matrix.framework}} -v n -l "console;verbosity=detailed" + # Run all UWP tests (separately, as they need VS Test) + run-tests-uwp: + needs: [build-solution] + strategy: + matrix: + configuration: [Debug, Release] + runs-on: windows-2022 + steps: + - name: Git checkout + uses: actions/checkout@v3 + - name: Add msbuild to PATH + uses: microsoft/setup-msbuild@v1.1 + + # Build the D2D1 UWP unit tests (need to restore and build separately for it to build correctly) + - name: Build ComputeSharp.D2D1.Uwp.Tests + run: > + msbuild tests\ComputeSharp.D2D1.Uwp.Tests\ComputeSharp.D2D1.Uwp.Tests.csproj -t:restore /p:Configuration=${{matrix.configuration}} /p:Platform=x64; + msbuild tests\ComputeSharp.D2D1.Uwp.Tests\ComputeSharp.D2D1.Uwp.Tests.csproj -t:build /p:Configuration=${{matrix.configuration}} /p:Platform=x64 + + # Run the D2D1 UWP unit tests with VS Test (need to use vswhere to find the VS Test runner) + - name: Run ComputeSharp.D2D1.Uwp.Tests + run: > + $vs_path = vswhere -latest -products * -requires Microsoft.VisualStudio.Workload.ManagedDesktop -requiresAny -property installationPath; + $vstest_path = join-path $vs_path 'Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe'; + & $vstest_path /Platform:x64 /framework:frameworkuap10 tests\ComputeSharp.D2D1.Uwp.Tests\bin\x64\${{matrix.configuration}}\ComputeSharp.D2D1.Uwp.Tests.build.appxrecipe + # Run all the local samples to ensure they build and run with no errors run-samples: needs: [build-solution] @@ -255,7 +281,7 @@ jobs: # Publish the packages to GitHub packages publish-nightlies-github: - needs: [run-tests, run-samples, run-samples-aot, verify-packages] + needs: [run-tests, run-tests-uwp, run-samples, run-samples-aot, verify-packages] runs-on: windows-2022 if: ${{github.event_name == 'push'}} steps: @@ -267,7 +293,7 @@ jobs: # Publish the packages to Azure DevOps publish-nightlies-azure-devops: - needs: [run-tests, run-samples, run-samples-aot, verify-packages] + needs: [run-tests, run-tests-uwp, run-samples, run-samples-aot, verify-packages] runs-on: windows-2022 if: ${{github.event_name == 'push'}} steps: From fdf35114892079b4a02da326e0ec6300076f996e Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 25 Apr 2023 03:59:27 +0200 Subject: [PATCH 04/14] Switch image comparer in UWP tests to Win2D --- .../ComputeSharp.D2D1.UI.Tests.projitems | 2 +- .../Helpers/TolerantImageComparer.cs | 117 ++++++++++++++++++ .../ShadersTests.cs | 21 ++-- .../ComputeSharp.D2D1.Uwp.Tests.csproj | 3 - .../Helpers/TolerantImageComparer.cs | 3 + 5 files changed, 133 insertions(+), 13 deletions(-) create mode 100644 tests/ComputeSharp.D2D1.UI.Tests/Helpers/TolerantImageComparer.cs diff --git a/tests/ComputeSharp.D2D1.UI.Tests/ComputeSharp.D2D1.UI.Tests.projitems b/tests/ComputeSharp.D2D1.UI.Tests/ComputeSharp.D2D1.UI.Tests.projitems index fa0581dd..64c69933 100644 --- a/tests/ComputeSharp.D2D1.UI.Tests/ComputeSharp.D2D1.UI.Tests.projitems +++ b/tests/ComputeSharp.D2D1.UI.Tests/ComputeSharp.D2D1.UI.Tests.projitems @@ -9,8 +9,8 @@ ComputeSharp.D2D1.UI.Tests + - \ No newline at end of file diff --git a/tests/ComputeSharp.D2D1.UI.Tests/Helpers/TolerantImageComparer.cs b/tests/ComputeSharp.D2D1.UI.Tests/Helpers/TolerantImageComparer.cs new file mode 100644 index 00000000..fd008045 --- /dev/null +++ b/tests/ComputeSharp.D2D1.UI.Tests/Helpers/TolerantImageComparer.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.CompilerServices; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.Graphics.Canvas; +using System.Drawing; +using Color = Windows.UI.Color; + +namespace ComputeSharp.D2D1.UI.Tests.Helpers; + +/// +/// An tolerant image comparer type, inspired from ImageSharp. +/// +internal static class TolerantImageComparer +{ + /// + /// Asserts that two images are equal. + /// + /// The reference image. + /// The expected image. + /// The allowed difference threshold for the normalized delta. + public static void AssertEqual(CanvasBitmap expected, CanvasBitmap actual, float threshold) + { + if (expected.SizeInPixels.Width != actual.SizeInPixels.Width || + expected.SizeInPixels.Height != actual.SizeInPixels.Height) + { + Assert.Fail($"The input images have different sizes: {expected.SizeInPixels} and {actual.SizeInPixels}"); + } + + Color[] expectedColors = expected.GetPixelColors(); + Color[] actualColors = actual.GetPixelColors(); + + float totalDifference = 0F; + + List differences = new(20); + + for (int i = 0; i < expectedColors.Length; i++) + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static int GetManhattanDistanceInRgbaSpace(ref Color a, ref Color b) + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static int Diff(ushort a, ushort b) => Math.Abs(a - b); + + return Diff(a.R, b.R) + Diff(a.G, b.G) + Diff(a.B, b.B) + Diff(a.A, b.A); + } + + int d = GetManhattanDistanceInRgbaSpace(ref expectedColors[i], ref actualColors[i]); + + if (d > 0) + { + if (differences.Count < 20) + { + int offsetY = (int)(i / expected.SizeInPixels.Width); + int offsetX = (int)(i % expected.SizeInPixels.Width); + + PixelDifference diff = new(new Point(offsetX, offsetY), expectedColors[i], actualColors[i]); + + differences.Add(diff); + } + + totalDifference += d; + } + } + + float normalizedDifference = totalDifference / (actual.SizeInPixels.Width * (float)actual.SizeInPixels.Height); + + normalizedDifference /= 4F * 65535F; + + if (normalizedDifference > threshold) + { + StringBuilder builder = new(); + + _ = builder.AppendLine($"The input images don't match. Normalized delta: {normalizedDifference}%"); + _ = builder.AppendLine($"First {differences.Count} pixel deltas:"); + + foreach (PixelDifference delta in differences) + { + _ = builder.AppendLine(delta.ToString()); + } + + Assert.Fail(builder.ToString()); + } + } + + /// + /// A simple model repressenting info about a difference between two pixels. + /// + private readonly struct PixelDifference + { + public PixelDifference(Point position, Color expected, Color actual) + { + this.Position = position; + this.RedDifference = actual.R - expected.R; + this.GreenDifference = actual.G - expected.G; + this.BlueDifference = actual.B - expected.B; + this.AlphaDifference = actual.A - expected.A; + } + + public readonly Point Position; + + public readonly int RedDifference; + + public readonly int GreenDifference; + + public readonly int BlueDifference; + + public readonly int AlphaDifference; + + /// + public override string ToString() + { + return $"[delta({this.RedDifference},{this.GreenDifference},{this.BlueDifference},{this.AlphaDifference}) @ ({this.Position.X},{this.Position.Y})]"; + } + } +} \ No newline at end of file diff --git a/tests/ComputeSharp.D2D1.UI.Tests/ShadersTests.cs b/tests/ComputeSharp.D2D1.UI.Tests/ShadersTests.cs index aa4378c5..e7cd49a2 100644 --- a/tests/ComputeSharp.D2D1.UI.Tests/ShadersTests.cs +++ b/tests/ComputeSharp.D2D1.UI.Tests/ShadersTests.cs @@ -1,14 +1,13 @@ using System; using System.IO; using System.Threading.Tasks; +using ComputeSharp.D2D1.UI.Tests.Helpers; using ComputeSharp.D2D1.Uwp; using ComputeSharp.SwapChain.Shaders.D2D1; -using ComputeSharp.Tests.Helpers; using Microsoft.Graphics.Canvas; using Microsoft.VisualStudio.TestTools.UnitTesting; -using SixLabors.ImageSharp; -using SixLabors.ImageSharp.PixelFormats; using Windows.Storage; +using Windows.UI; namespace ComputeSharp.D2D1.UI.Tests; @@ -64,9 +63,12 @@ public class ShadersTests T shader = (T)Activator.CreateInstance(typeof(T), 0f, new int2(1280, 720))!; PixelShaderEffect effect = new() { ConstantBuffer = shader }; - byte[] pixelBytes; + Color[] pixelColors; - using (CanvasRenderTarget renderTarget = new(new CanvasDevice(), 1280, 720, 96.0f)) + using CanvasDevice canvasDevice = new(); + + // Compute the resulting image + using (CanvasRenderTarget renderTarget = new(canvasDevice, 1280, 720, 96.0f)) { // Draw the shader on the render target using (CanvasDrawingSession drawingSession = renderTarget.CreateDrawingSession()) @@ -75,15 +77,16 @@ public class ShadersTests } // Get the BGRA32 pixel data from the render target - pixelBytes = renderTarget.GetPixelBytes(); + pixelColors = renderTarget.GetPixelColors(); } StorageFile imageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///Assets/Shaders/{typeof(T).Name}.png")); + // Retrieve the expected image using Stream stream = await imageFile.OpenStreamForReadAsync(); - using Image expected = await Image.LoadAsync(stream); - using Image result = Image.WrapMemory(pixelBytes, 1280, 720); + using CanvasBitmap expected = await CanvasBitmap.LoadAsync(canvasDevice, stream.AsRandomAccessStream()); + using CanvasBitmap actual = CanvasBitmap.CreateFromColors(canvasDevice, pixelColors, 1280, 720); - TolerantImageComparer.AssertEqual(expected, result, threshold); + TolerantImageComparer.AssertEqual(expected, actual, threshold); } } \ No newline at end of file diff --git a/tests/ComputeSharp.D2D1.Uwp.Tests/ComputeSharp.D2D1.Uwp.Tests.csproj b/tests/ComputeSharp.D2D1.Uwp.Tests/ComputeSharp.D2D1.Uwp.Tests.csproj index 9e3a82af..797c5c22 100644 --- a/tests/ComputeSharp.D2D1.Uwp.Tests/ComputeSharp.D2D1.Uwp.Tests.csproj +++ b/tests/ComputeSharp.D2D1.Uwp.Tests/ComputeSharp.D2D1.Uwp.Tests.csproj @@ -137,9 +137,6 @@ 2.2.7 - - 2.1.4 - diff --git a/tests/ComputeSharp.Tests/Helpers/TolerantImageComparer.cs b/tests/ComputeSharp.Tests/Helpers/TolerantImageComparer.cs index 97ed11aa..078c4777 100644 --- a/tests/ComputeSharp.Tests/Helpers/TolerantImageComparer.cs +++ b/tests/ComputeSharp.Tests/Helpers/TolerantImageComparer.cs @@ -85,6 +85,7 @@ internal static class TolerantImageComparer if (differences.Count < 20) { PixelDifference diff = new(new Point(x, y), aBuffer[x], bBuffer[x]); + differences.Add(diff); } @@ -94,11 +95,13 @@ internal static class TolerantImageComparer } float normalizedDifference = totalDifference / (actual.Width * (float)actual.Height); + normalizedDifference /= 4F * 65535F; if (normalizedDifference > threshold) { StringBuilder builder = new(); + _ = builder.AppendLine($"The input images don't match. Normalized delta: {normalizedDifference}%"); _ = builder.AppendLine($"First {differences.Count} pixel deltas:"); From c561c18b5e9b3e80e63b4ed3f68d4a1d85f77195 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 25 Apr 2023 18:43:16 +0200 Subject: [PATCH 05/14] Add CanvasEffect integration tests --- .../CanvasEffectTests.cs | 98 +++++++++++++++++++ .../ComputeSharp.D2D1.UI.Tests.projitems | 1 + .../PixelShaderEffectTests.cs | 14 +++ .../ShadersTests.cs | 86 ++++++++++++---- 4 files changed, 182 insertions(+), 17 deletions(-) create mode 100644 tests/ComputeSharp.D2D1.UI.Tests/CanvasEffectTests.cs diff --git a/tests/ComputeSharp.D2D1.UI.Tests/CanvasEffectTests.cs b/tests/ComputeSharp.D2D1.UI.Tests/CanvasEffectTests.cs new file mode 100644 index 00000000..8f80e15d --- /dev/null +++ b/tests/ComputeSharp.D2D1.UI.Tests/CanvasEffectTests.cs @@ -0,0 +1,98 @@ +using ComputeSharp.D2D1.Uwp; +using Microsoft.Graphics.Canvas; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +#nullable enable + +namespace ComputeSharp.D2D1.UI.Tests; + +[TestClass] +[TestCategory("CanvasEffect")] +public partial class CanvasEffectTests +{ + [TestMethod] + public unsafe void CanvasEffect_IsRealizedAndInvalidatedCorrectly() + { + EffectWithNoInputs effect = new(); + + using (CanvasRenderTarget renderTarget = new(new CanvasDevice(), 128, 128, 96.0f)) + using (CanvasDrawingSession drawingSession = renderTarget.CreateDrawingSession()) + { + drawingSession.DrawImage(effect); + } + + Assert.AreEqual(effect.NumberOfBuildEffectGraphCalls, 1); + Assert.AreEqual(effect.NumberOfConfigureEffectGraphCalls, 1); + + effect.Value = 42; + + using (CanvasRenderTarget renderTarget = new(new CanvasDevice(), 128, 128, 96.0f)) + using (CanvasDrawingSession drawingSession = renderTarget.CreateDrawingSession()) + { + drawingSession.DrawImage(effect); + } + + Assert.AreEqual(effect.NumberOfBuildEffectGraphCalls, 1); + Assert.AreEqual(effect.NumberOfConfigureEffectGraphCalls, 2); + + effect.ValueWithReload = 123; + + using (CanvasRenderTarget renderTarget = new(new CanvasDevice(), 128, 128, 96.0f)) + using (CanvasDrawingSession drawingSession = renderTarget.CreateDrawingSession()) + { + drawingSession.DrawImage(effect); + } + + Assert.AreEqual(effect.NumberOfBuildEffectGraphCalls, 2); + Assert.AreEqual(effect.NumberOfConfigureEffectGraphCalls, 3); + } + + private sealed class EffectWithNoInputs : CanvasEffect + { + private PixelShaderEffect? effect; + + private int value; + + public int Value + { + get => this.value; + set => SetAndInvalidateEffectGraph(ref this.value, value); + } + + public int ValueWithReload + { + get => this.value; + set => SetAndInvalidateEffectGraph(ref this.value, value, InvalidationType.Creation); + } + + public int NumberOfBuildEffectGraphCalls { get; private set; } + + public int NumberOfConfigureEffectGraphCalls { get; private set; } + + protected override ICanvasImage BuildEffectGraph() + { + NumberOfBuildEffectGraphCalls++; + + return this.effect = new PixelShaderEffect(); + } + + protected override void ConfigureEffectGraph() + { + NumberOfConfigureEffectGraphCalls++; + + this.effect!.ConstantBuffer = new ShaderWithNoInputs(this.value); + } + } + + [D2DInputCount(0)] + [AutoConstructor] + private partial struct ShaderWithNoInputs : ID2D1PixelShader + { + public int Value; + + public float4 Execute() + { + return default; + } + } +} diff --git a/tests/ComputeSharp.D2D1.UI.Tests/ComputeSharp.D2D1.UI.Tests.projitems b/tests/ComputeSharp.D2D1.UI.Tests/ComputeSharp.D2D1.UI.Tests.projitems index 64c69933..3d54cb41 100644 --- a/tests/ComputeSharp.D2D1.UI.Tests/ComputeSharp.D2D1.UI.Tests.projitems +++ b/tests/ComputeSharp.D2D1.UI.Tests/ComputeSharp.D2D1.UI.Tests.projitems @@ -10,6 +10,7 @@ + diff --git a/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs b/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs index 674bd754..8ab42cf7 100644 --- a/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs +++ b/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs @@ -56,6 +56,20 @@ public partial class PixelShaderEffectTests // The shader also matches when retrieving it through the realized effect Assert.IsTrue(actual.SequenceEqual(expected)); + + // Draw the effect on a different device (this forces it to unrealize and re-realize). + // This also acts as a unit test for the device changed logic, since that's used here. + using (CanvasRenderTarget renderTarget = new(new CanvasDevice(), 128, 128, 96.0f)) + using (CanvasDrawingSession drawingSession = renderTarget.CreateDrawingSession()) + { + drawingSession.DrawImage(effect); + } + + roundTripShader = effect.ConstantBuffer; + actual = new(&roundTripShader, sizeof(ShaderWithSomeProperties)); + + // The shader also matches when retrieving it through the realized effect + Assert.IsTrue(actual.SequenceEqual(expected)); } [D2DInputCount(0)] diff --git a/tests/ComputeSharp.D2D1.UI.Tests/ShadersTests.cs b/tests/ComputeSharp.D2D1.UI.Tests/ShadersTests.cs index e7cd49a2..86e88d6d 100644 --- a/tests/ComputeSharp.D2D1.UI.Tests/ShadersTests.cs +++ b/tests/ComputeSharp.D2D1.UI.Tests/ShadersTests.cs @@ -9,6 +9,8 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Windows.Storage; using Windows.UI; +#nullable enable + namespace ComputeSharp.D2D1.UI.Tests; [TestClass] @@ -16,52 +18,72 @@ namespace ComputeSharp.D2D1.UI.Tests; public class ShadersTests { [TestMethod] - public async Task HelloWorld() + [DataRow(WrapperType.PixelShaderEffect)] + [DataRow(WrapperType.CanvasEffect)] + public async Task HelloWorld(WrapperType wrapperType) { - await RunTestAsync(); + await RunTestAsync(wrapperType); } [TestMethod] - public async Task ColorfulInfinity() + [DataRow(WrapperType.PixelShaderEffect)] + [DataRow(WrapperType.CanvasEffect)] + public async Task ColorfulInfinity(WrapperType wrapperType) { - await RunTestAsync(); + await RunTestAsync(wrapperType); } [TestMethod] - public async Task FractalTiling() + [DataRow(WrapperType.PixelShaderEffect)] + [DataRow(WrapperType.CanvasEffect)] + public async Task FractalTiling(WrapperType wrapperType) { - await RunTestAsync(); + await RunTestAsync(wrapperType); } [TestMethod] - public async Task MengerJourney() + [DataRow(WrapperType.PixelShaderEffect)] + [DataRow(WrapperType.CanvasEffect)] + public async Task MengerJourney(WrapperType wrapperType) { - await RunTestAsync(0.000011f); + await RunTestAsync(wrapperType, 0.000011f); } [TestMethod] - public async Task Octagrams() + [DataRow(WrapperType.PixelShaderEffect)] + [DataRow(WrapperType.CanvasEffect)] + public async Task Octagrams(WrapperType wrapperType) { - await RunTestAsync(); + await RunTestAsync(wrapperType); } [TestMethod] - public async Task ProteanClouds() + [DataRow(WrapperType.PixelShaderEffect)] + [DataRow(WrapperType.CanvasEffect)] + public async Task ProteanClouds(WrapperType wrapperType) { - await RunTestAsync(); + await RunTestAsync(wrapperType); } [TestMethod] - public async Task TerracedHills() + [DataRow(WrapperType.PixelShaderEffect)] + [DataRow(WrapperType.CanvasEffect)] + public async Task TerracedHills(WrapperType wrapperType) { - await RunTestAsync(0.000026f); + await RunTestAsync(wrapperType, 0.000026f); } - private static async Task RunTestAsync(float threshold = 0.00001f) + private static async Task RunTestAsync(WrapperType wrapperType, float threshold = 0.00001f) where T : unmanaged, ID2D1PixelShader { T shader = (T)Activator.CreateInstance(typeof(T), 0f, new int2(1280, 720))!; - PixelShaderEffect effect = new() { ConstantBuffer = shader }; + + // Either create the effect directly, or a canvas effect + ICanvasImage canvasImage = wrapperType switch + { + WrapperType.PixelShaderEffect => new PixelShaderEffect() { ConstantBuffer = shader }, + _ => new TestCanvasEffect { ConstantBuffer = shader } + }; Color[] pixelColors; @@ -73,7 +95,7 @@ public class ShadersTests // Draw the shader on the render target using (CanvasDrawingSession drawingSession = renderTarget.CreateDrawingSession()) { - drawingSession.DrawImage(effect); + drawingSession.DrawImage(canvasImage); } // Get the BGRA32 pixel data from the render target @@ -89,4 +111,34 @@ public class ShadersTests TolerantImageComparer.AssertEqual(expected, actual, threshold); } + + private sealed class TestCanvasEffect : CanvasEffect + where T : unmanaged, ID2D1PixelShader + { + private PixelShaderEffect? effect; + + private T constantBuffer; + + public T ConstantBuffer + { + get => this.constantBuffer; + set => SetAndInvalidateEffectGraph(ref this.constantBuffer, value); + } + + protected override ICanvasImage BuildEffectGraph() + { + return this.effect = new PixelShaderEffect(); + } + + protected override void ConfigureEffectGraph() + { + this.effect!.ConstantBuffer = this.constantBuffer; + } + } + + public enum WrapperType + { + PixelShaderEffect, + CanvasEffect + } } \ No newline at end of file From 452294cf84b5c366daafef91fdf260731949207c Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 25 Apr 2023 18:43:32 +0200 Subject: [PATCH 06/14] Fix CanvasEffect not invalidation on creation request --- src/ComputeSharp.D2D1.UI/CanvasEffect.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/ComputeSharp.D2D1.UI/CanvasEffect.cs b/src/ComputeSharp.D2D1.UI/CanvasEffect.cs index efef99d5..898aa459 100644 --- a/src/ComputeSharp.D2D1.UI/CanvasEffect.cs +++ b/src/ComputeSharp.D2D1.UI/CanvasEffect.cs @@ -124,14 +124,12 @@ public abstract partial class CanvasEffect : ICanvasImage, ICanvasImageInterop.I this.canvasImage?.Dispose(); this.canvasImage = null; - this.isInvalidated = false; - } - else - { - // Otherwise, just mark the internal state as not being valid anymore. The next - // time the image is requested, the effect graph will be configured if needed. - this.isInvalidated = true; } + + // For both invalidation types, always mark the internal state as not being valid anymore. + // The next time the image is requested, the effect graph will be configured if needed. + // This matches the default value for the field (which is needed for the first realization). + this.isInvalidated = true; } } From 3c2ec371eba42f70ed0e709326920dfde80b8b49 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 25 Apr 2023 19:27:52 +0200 Subject: [PATCH 07/14] Add more PixelShaderEffect unit tests, missing null check --- ...PixelShaderEffect{T}.Properties.Interop.cs | 4 + .../PixelShaderEffectTests.cs | 122 ++++++++++++++++++ 2 files changed, 126 insertions(+) diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.cs index 30546024..a36c1dc6 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.cs @@ -1,3 +1,4 @@ +using System; using ComputeSharp.D2D1.Interop; #if WINDOWS_UWP using ComputeSharp.D2D1.Uwp.Extensions; @@ -92,6 +93,9 @@ unsafe partial class PixelShaderEffect } else { + // If the effect is not realized, manually ensure the transform isn't null + default(ArgumentNullException).ThrowIfNull(value); + this.transformMapper = value; } } diff --git a/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs b/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs index 8ab42cf7..47e06960 100644 --- a/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs +++ b/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.InteropServices; using ComputeSharp.D2D1.Uwp; using Microsoft.Graphics.Canvas; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -72,6 +73,97 @@ public partial class PixelShaderEffectTests Assert.IsTrue(actual.SequenceEqual(expected)); } + [TestMethod] + [ExpectedException(typeof(ArgumentOutOfRangeException))] + public void SourcesOutOfRange_ThrowsArgumentOutOfRangeException() + { + PixelShaderEffect effect0 = new(); + + _ = Assert.ThrowsException(() => effect0.Sources[0] = null); + _ = Assert.ThrowsException(() => effect0.Sources[1] = null); + + PixelShaderEffect effect1 = new(); + + effect1.Sources[0] = null; + + _ = Assert.ThrowsException(() => effect1.Sources[1] = null); + _ = Assert.ThrowsException(() => effect1.Sources[2] = null); + + PixelShaderEffect effect2 = new(); + + effect2.Sources[0] = null; + effect2.Sources[1] = null; + + _ = Assert.ThrowsException(() => effect2.Sources[2] = null); + _ = Assert.ThrowsException(() => effect2.Sources[3] = null); + } + + [TestMethod] + [ExpectedException(typeof(ArgumentNullException))] + public void NullTransformMapper_UnrealizedEffect_ThrowsArgumentNullException() + { + PixelShaderEffect effect = new(); + + effect.TransformMapper = null!; + } + + [TestMethod] + [ExpectedException(typeof(ArgumentNullException))] + public void NullTransformMapper_RealizedEffect_ThrowsArgumentNullException() + { + PixelShaderEffect effect = new(); + + using (CanvasRenderTarget renderTarget = new(new CanvasDevice(), 128, 128, 96.0f)) + using (CanvasDrawingSession drawingSession = renderTarget.CreateDrawingSession()) + { + drawingSession.DrawImage(effect); + } + + effect.TransformMapper = null!; + } + + [TestMethod] + [ExpectedException(typeof(Exception), AllowDerivedTypes = true)] + public unsafe void GraphCycle_IsDetectedCorrectly() + { + PixelShaderEffect effect1 = new(); + PixelShaderEffect effect2 = new(); + PixelShaderEffect effect3 = new(); + PixelShaderEffect effect4 = new(); + PixelShaderEffect effect5 = new(); + PixelShaderEffect effect6 = new(); + PixelShaderEffect effect7 = new(); + + // Build a graph with a cycle in it: + // + // ┌───┐ ┌───┐ ┌───┐ + // │ 1 ├──►│ 2 ├──►│ 3 ├──────────┐ + // └───┘ └───┘ └───┘ ▼ + // ┌───┐ ┌───┐ ▲ │ ┌───┐ ┌───┐ + // │ 7 ├──►│ 6 ├─┘ └─►│ 4 ├──►│ 5 │ + // └───┘ └───┘ └───┘ └───┘ + // ▲ │ + // └─────────────────┘ + // + // The cycle is 4 -> 6 -> 2 -> 3 -> 4. + effect2.Sources[0] = effect1; + effect2.Sources[1] = effect6; + effect3.Sources[0] = effect2; + effect4.Sources[0] = effect3; + effect5.Sources[0] = effect3; + effect5.Sources[1] = effect4; + effect6.Sources[0] = effect4; + effect6.Sources[1] = effect7; + + using ComPtr d2D1Image = default; + + // Realize the effect for it to detect a graph cycle. We specifically don't want to draw + // the effect, because in that case we'd still get an exception from D2D, even if the + // effect from ComputeSharp failed to detect a graph cycle. We want to make sure the + // detection and subsequent error is coming from our wrapper, not from D2D's logic. + Win2DHelper.GetD2DImage(effect5, new CanvasDevice(), d2D1Image.GetAddressOf()); + } + [D2DInputCount(0)] [AutoConstructor] private partial struct ShaderWithSomeProperties : ID2D1PixelShader @@ -87,4 +179,34 @@ public partial class PixelShaderEffectTests return default; } } + + [D2DInputCount(0)] + private partial struct ShaderWith0Inputs : ID2D1PixelShader + { + public float4 Execute() + { + return default; + } + } + + [D2DInputCount(1)] + [D2DInputSimple(0)] + private partial struct ShaderWith1Input : ID2D1PixelShader + { + public float4 Execute() + { + return D2D.GetInput(0); + } + } + + [D2DInputCount(2)] + [D2DInputSimple(0)] + [D2DInputSimple(1)] + private partial struct ShaderWith2Inputs : ID2D1PixelShader + { + public float4 Execute() + { + return D2D.GetInput(0) + D2D.GetInput(1); + } + } } From 823a01c2e6e37ebbaebcbed7a104a22c17f746a9 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 26 Apr 2023 00:30:18 +0200 Subject: [PATCH 08/14] Fix wrapper registration from ICanvasEffectFactoryNative --- .../PixelShaderEffect{T}.ICanvasEffectFactoryNative.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffectFactoryNative.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffectFactoryNative.cs index d6c49f69..073b4ae2 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffectFactoryNative.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffectFactoryNative.cs @@ -139,7 +139,7 @@ unsafe partial class PixelShaderEffect // Register the new wrapper for the input resource. This has to be done manually in this // case, as the effect is not being realized through the usual path from GetD2DImage. - ResourceManager.RegisterWrapper((IUnknown*)resource, this); + ResourceManager.RegisterWrapper((IUnknown*)resource, @this); // Unwrap the PixelShaderEffect and return its CCW to the caller RcwMarshaller.GetNativeObject(@this, wrapper); From 60ae63ead2d2a6a965e986bd769d38b77311913f Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 26 Apr 2023 00:38:49 +0200 Subject: [PATCH 09/14] Fix PixelShaderEffect buffer precision marshalling --- .../PixelShaderEffect{T}.Properties.Interop.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.cs index a36c1dc6..bc5e4f2f 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.cs @@ -200,7 +200,7 @@ unsafe partial class PixelShaderEffect }; // Map from D2D1_BUFFER_PRECISION to CanvasBufferPrecision, and return null for D2D1_BUFFER_PRECISION_UNKNOWN - return this.d2D1BufferPrecision switch + return d2D1BufferPrecision switch { D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_8BPC_UNORM => CanvasBufferPrecision.Precision8UIntNormalized, D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_8BPC_UNORM_SRGB => CanvasBufferPrecision.Precision8UIntNormalizedSrgb, From ea887bf56e0ed90a72235cd9644b073b79efb920 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 26 Apr 2023 00:39:14 +0200 Subject: [PATCH 10/14] Add interop unit tests for PixelShaderEffect --- ComputeSharp.sln | 2 + .../ComputeSharp.D2D1.UI.Tests.projitems | 1 + .../Helpers/TolerantImageComparer.cs | 2 +- .../Helpers/Win2DHelper.cs | 119 +++++++++ .../PixelShaderEffectTests.cs | 226 ++++++++++++++++++ .../ComputeSharp.D2D1.Uwp.Tests.csproj | 14 +- tests/Directory.Build.props | 3 + 7 files changed, 362 insertions(+), 5 deletions(-) create mode 100644 tests/ComputeSharp.D2D1.UI.Tests/Helpers/Win2DHelper.cs diff --git a/ComputeSharp.sln b/ComputeSharp.sln index 987e7491..b39cce02 100644 --- a/ComputeSharp.sln +++ b/ComputeSharp.sln @@ -484,6 +484,8 @@ Global src\TerraFX.Interop.Windows\TerraFX.Interop.Windows.projitems*{314eb353-e7e3-4146-8111-685cc83ec1de}*SharedItemsImports = 5 tests\ComputeSharp.D2D1.UI.Tests\ComputeSharp.D2D1.UI.Tests.projitems*{346aeb10-a4ea-427e-8578-f60915db3053}*SharedItemsImports = 13 samples\ComputeSharp.SwapChain.Shaders.D2D1.Shared\ComputeSharp.SwapChain.Shaders.D2D1.Shared.projitems*{4d4bb2f6-5653-4db5-a8dd-90d58d8fe4d3}*SharedItemsImports = 4 + src\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems*{4d4bb2f6-5653-4db5-a8dd-90d58d8fe4d3}*SharedItemsImports = 4 + src\TerraFX.Interop.Windows.D2D1\TerraFX.Interop.Windows.D2D1.projitems*{4d4bb2f6-5653-4db5-a8dd-90d58d8fe4d3}*SharedItemsImports = 4 tests\ComputeSharp.D2D1.UI.Tests\ComputeSharp.D2D1.UI.Tests.projitems*{4d4bb2f6-5653-4db5-a8dd-90d58d8fe4d3}*SharedItemsImports = 4 src\TerraFX.Interop.Windows.D2D1\TerraFX.Interop.Windows.D2D1.projitems*{4d7d9ba8-a821-4b1c-9ee2-cbcf5849906e}*SharedItemsImports = 5 src\TerraFX.Interop.Windows\TerraFX.Interop.Windows.projitems*{514ff00e-bbf0-4d55-a47c-eeeb6208adce}*SharedItemsImports = 13 diff --git a/tests/ComputeSharp.D2D1.UI.Tests/ComputeSharp.D2D1.UI.Tests.projitems b/tests/ComputeSharp.D2D1.UI.Tests/ComputeSharp.D2D1.UI.Tests.projitems index 3d54cb41..826aaefe 100644 --- a/tests/ComputeSharp.D2D1.UI.Tests/ComputeSharp.D2D1.UI.Tests.projitems +++ b/tests/ComputeSharp.D2D1.UI.Tests/ComputeSharp.D2D1.UI.Tests.projitems @@ -9,6 +9,7 @@ ComputeSharp.D2D1.UI.Tests + diff --git a/tests/ComputeSharp.D2D1.UI.Tests/Helpers/TolerantImageComparer.cs b/tests/ComputeSharp.D2D1.UI.Tests/Helpers/TolerantImageComparer.cs index fd008045..60cb3c99 100644 --- a/tests/ComputeSharp.D2D1.UI.Tests/Helpers/TolerantImageComparer.cs +++ b/tests/ComputeSharp.D2D1.UI.Tests/Helpers/TolerantImageComparer.cs @@ -1,10 +1,10 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Text; using System.Runtime.CompilerServices; using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.Graphics.Canvas; -using System.Drawing; using Color = Windows.UI.Color; namespace ComputeSharp.D2D1.UI.Tests.Helpers; diff --git a/tests/ComputeSharp.D2D1.UI.Tests/Helpers/Win2DHelper.cs b/tests/ComputeSharp.D2D1.UI.Tests/Helpers/Win2DHelper.cs new file mode 100644 index 00000000..653fbfbd --- /dev/null +++ b/tests/ComputeSharp.D2D1.UI.Tests/Helpers/Win2DHelper.cs @@ -0,0 +1,119 @@ +using System; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.WindowsRuntime; +using Microsoft.Graphics.Canvas; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; + +#nullable enable + +namespace ComputeSharp.D2D1.UI.Tests.Helpers; + +/// +/// A helper type to marshal managed objects in unit tests. +/// +internal static class Win2DHelper +{ + /// + /// Gets the managed wrapper for a given object. + /// + /// The input object to get a wrapper for. + /// The realization instance to use. + /// The resulting managed wrapper for . + public static unsafe object GetOrCreate(ID2D1Image* d2D1Image, CanvasDevice? canvasDevice = null) + { + IActivationFactory activationFactory = WindowsRuntimeMarshal.GetActivationFactory(typeof(CanvasDevice)); + + using ComPtr activationFactoryUnknown = default; + + activationFactoryUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(activationFactory)); + + using ComPtr canvasFactoryNativeUnknown = default; + + Guid uuidOfCanvasFactoryNativeUnknown = new("695C440D-04B3-4EDD-BFD9-63E51E9F7202"); + + //Get the ICanvasFactoryNative object + int hresult = activationFactoryUnknown.CopyTo(&uuidOfCanvasFactoryNativeUnknown, (void**)canvasFactoryNativeUnknown.GetAddressOf()); + + Marshal.ThrowExceptionForHR(hresult); + + using ComPtr canvasDeviceUnknown = default; + + if (canvasDevice is not null) + { + canvasDeviceUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(canvasDevice)); + } + + using ComPtr canvasDeviceInterfaceUnknown = default; + + if (canvasDevice is not null) + { + Guid uuidOfCanvasDeviceInterface = new("A27F0B5D-EC2C-4D4F-948F-0AA1E95E33E6"); + + // Get the ICanvasDevice object (as an IUnknown* as well) + hresult = canvasDeviceUnknown.CopyTo(&uuidOfCanvasDeviceInterface, (void**)canvasDeviceInterfaceUnknown.GetAddressOf()); + } + + using ComPtr wrapperUnknown = default; + + // Invoke GetOrCreate to get the inspectable wrapper + hresult = ((delegate* unmanaged[Stdcall])(*(void***)canvasFactoryNativeUnknown.Get())[6])( + canvasFactoryNativeUnknown.Get(), + canvasDeviceInterfaceUnknown.Get(), + (IUnknown*)d2D1Image, + 0, + wrapperUnknown.GetAddressOf()); + + Marshal.ThrowExceptionForHR(hresult); + + // Get or create a managed object for the native object + return Marshal.GetObjectForIUnknown((IntPtr)wrapperUnknown.Get()); + } + + /// + /// Gets the D2D image from a given object. + /// + /// The input object. + /// The realization instance to use. + /// The resulting object. + public static unsafe void GetD2DImage(ICanvasImage canvasImage, CanvasDevice canvasDevice, ID2D1Image** d2D1Image) + { + using ComPtr effectUnknown = default; + + effectUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(canvasImage)); + + using ComPtr canvasImageInteropUnknown = default; + + Guid uuidOfCanvasImageInterop = new("E042D1F7-F9AD-4479-A713-67627EA31863"); + + // Get the ICanvasImageInterop object (as an IUnknown*) + int hresult = effectUnknown.CopyTo(&uuidOfCanvasImageInterop, (void**)canvasImageInteropUnknown.GetAddressOf()); + + Marshal.ThrowExceptionForHR(hresult); + + using ComPtr canvasDeviceUnknown = default; + + canvasDeviceUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(canvasDevice)); + + using ComPtr canvasDeviceInterfaceUnknown = default; + + Guid uuidOfCanvasDeviceInterface = new("A27F0B5D-EC2C-4D4F-948F-0AA1E95E33E6"); + + // Get the ICanvasDevice object (as an IUnknown* as well) + hresult = canvasDeviceUnknown.CopyTo(&uuidOfCanvasDeviceInterface, (void**)canvasDeviceInterfaceUnknown.GetAddressOf()); + + Marshal.ThrowExceptionForHR(hresult); + + // Invoke GetD2DImage (passing NEVER_INSERT_DPI_COMPENSATION | MINIMAL_REALIZATION | ALLOW_NULL_EFFECT_INPUTS) + hresult = ((delegate* unmanaged[Stdcall])(*(void***)canvasImageInteropUnknown.Get())[4])( + canvasImageInteropUnknown.Get(), + canvasDeviceInterfaceUnknown.Get(), + null, + 4 | 8 | 16, + 0, + null, + d2D1Image); + + Marshal.ThrowExceptionForHR(hresult); + } +} \ No newline at end of file diff --git a/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs b/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs index 47e06960..8176ff97 100644 --- a/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs +++ b/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs @@ -1,8 +1,12 @@ using System; using System.Runtime.InteropServices; +using ComputeSharp.D2D1.Interop; +using ComputeSharp.D2D1.UI.Tests.Helpers; using ComputeSharp.D2D1.Uwp; using Microsoft.Graphics.Canvas; using Microsoft.VisualStudio.TestTools.UnitTesting; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; namespace ComputeSharp.D2D1.UI.Tests; @@ -164,6 +168,216 @@ public partial class PixelShaderEffectTests Win2DHelper.GetD2DImage(effect5, new CanvasDevice(), d2D1Image.GetAddressOf()); } + [TestMethod] + public unsafe void Interop_EffectPropertiesAreForwardedCorrectly() + { + ShaderWithSomePropertiesAndInputs shader = new(-1234567); + + PixelShaderEffect effect0 = new(); + PixelShaderEffect effect1 = new() + { + ConstantBuffer = shader, + CacheOutput = true, + BufferPrecision = CanvasBufferPrecision.Precision32Float, + Sources = { [0] = effect0 } + }; + + CanvasDevice canvasDevice = new(); + + using ComPtr d2D1Image = default; + + // Realize the effect and get the D2D effect (this will also apply all local properties) + Win2DHelper.GetD2DImage(effect1, canvasDevice, d2D1Image.GetAddressOf()); + + using ComPtr d2D1Effect = default; + + Marshal.ThrowExceptionForHR(d2D1Image.CopyTo(d2D1Effect.GetAddressOf())); + + int constantBufferDataSize = D2D1PixelShader.GetConstantBufferSize(); + byte* constantBufferData = stackalloc byte[constantBufferDataSize]; + + int hresult = d2D1Effect.Get()->GetValue( + index: D2D1PixelShaderEffectProperty.ConstantBuffer, + type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_BLOB, + data: constantBufferData, + dataSize: (uint)constantBufferDataSize); + + Marshal.ThrowExceptionForHR(hresult); + + ReadOnlyMemory expectedConstantBufferData = D2D1PixelShader.GetConstantBuffer(in shader); + + Assert.IsTrue(expectedConstantBufferData.Span.SequenceEqual(new ReadOnlySpan(constantBufferData, constantBufferDataSize))); + + int cacheOutput; + + hresult = d2D1Effect.Get()->GetValue( + index: (uint)D2D1_PROPERTY.D2D1_PROPERTY_CACHED, + type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_BOOL, + data: (byte*)&cacheOutput, + dataSize: sizeof(int)); + + Marshal.ThrowExceptionForHR(hresult); + + Assert.AreEqual(1, cacheOutput); + + D2D1_BUFFER_PRECISION d2D1BufferPrecision; + + hresult = d2D1Effect.Get()->GetValue( + index: (uint)D2D1_PROPERTY.D2D1_PROPERTY_PRECISION, + type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_UNKNOWN, + data: (byte*)&d2D1BufferPrecision, + dataSize: sizeof(D2D1_BUFFER_PRECISION)); + + Marshal.ThrowExceptionForHR(hresult); + + Assert.AreEqual(D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_32BPC_FLOAT, d2D1BufferPrecision); + + using ComPtr d2D1Image1 = default; + using ComPtr d2D1Image2 = default; + + Win2DHelper.GetD2DImage(effect0, canvasDevice, d2D1Image1.GetAddressOf()); + + d2D1Effect.Get()->GetInput(0, d2D1Image2.GetAddressOf()); + + using ComPtr d2D1Image1Unknown = default; + using ComPtr d2D1Image2Unknown = default; + + Marshal.ThrowExceptionForHR(d2D1Image1.CopyTo(d2D1Image1Unknown.GetAddressOf())); + Marshal.ThrowExceptionForHR(d2D1Image2.CopyTo(d2D1Image2Unknown.GetAddressOf())); + + // The image from the effect input should be the same retrieved from the original source wrapper + Assert.IsTrue(d2D1Image1Unknown.Get() == d2D1Image2Unknown.Get()); + } + + [TestMethod] + public unsafe void Interop_EffectPropertiesAreUpdatedFromNativeEffectCorrectly() + { + ShaderWithSomePropertiesAndInputs shader = new(-1234567); + + PixelShaderEffect effect0 = new(); + PixelShaderEffect effect1 = new(); + + CanvasDevice canvasDevice = new(); + + using ComPtr d2D1Image0 = default; + using ComPtr d2D1Image1 = default; + + // Realize the effects and get the D2D effects + Win2DHelper.GetD2DImage(effect0, canvasDevice, d2D1Image0.GetAddressOf()); + Win2DHelper.GetD2DImage(effect1, canvasDevice, d2D1Image1.GetAddressOf()); + + using ComPtr d2D1Effect = default; + + Marshal.ThrowExceptionForHR(d2D1Image1.CopyTo(d2D1Effect.GetAddressOf())); + + D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(d2D1Effect.Get(), in shader); + + int cacheOutput = 1; + + int hresult = d2D1Effect.Get()->SetValue( + index: (uint)D2D1_PROPERTY.D2D1_PROPERTY_CACHED, + type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_BOOL, + data: (byte*)&cacheOutput, + dataSize: sizeof(int)); + + Marshal.ThrowExceptionForHR(hresult); + + Assert.AreEqual(1, cacheOutput); + + D2D1_BUFFER_PRECISION d2D1BufferPrecision = D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_32BPC_FLOAT; + + hresult = d2D1Effect.Get()->SetValue( + index: (uint)D2D1_PROPERTY.D2D1_PROPERTY_PRECISION, + type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_UNKNOWN, + data: (byte*)&d2D1BufferPrecision, + dataSize: sizeof(D2D1_BUFFER_PRECISION)); + + Marshal.ThrowExceptionForHR(hresult); + + d2D1Effect.Get()->SetInput(0, d2D1Image0.Get()); + + Assert.AreEqual(shader.Number, effect1.ConstantBuffer.Number); + Assert.IsTrue(effect1.CacheOutput); + Assert.AreEqual(CanvasBufferPrecision.Precision32Float, effect1.BufferPrecision); + Assert.AreSame(effect0, effect1.Sources[0]); + } + + [TestMethod] + public unsafe void Interop_IsWrapperRegisteredCorrectly() + { + PixelShaderEffect effect = new(); + + using ComPtr d2D1Image = default; + + Win2DHelper.GetD2DImage(effect, new CanvasDevice(), d2D1Image.GetAddressOf()); + + object wrapper = Win2DHelper.GetOrCreate(d2D1Image.Get()); + + Assert.AreSame(effect, wrapper); + } + + [TestMethod] + public unsafe void Interop_IsWrapperFactoryRegisteredCorrectlyAndWorking() + { + PixelShaderEffect effect = new(); + CanvasDevice canvasDevice1 = new(); + CanvasDevice canvasDevice2 = new(); + + using ComPtr d2D1Image1 = default; + using ComPtr d2D1Image2 = default; + + Win2DHelper.GetD2DImage(effect, canvasDevice1, d2D1Image1.GetAddressOf()); + Win2DHelper.GetD2DImage(effect, canvasDevice2, d2D1Image2.GetAddressOf()); + + // The first resource is orphaned, so a new wrapper will be created + object wrapper1 = Win2DHelper.GetOrCreate(d2D1Image1.Get(), canvasDevice1); + + Assert.IsTrue(wrapper1 is PixelShaderEffect); + Assert.AreNotSame(wrapper1, effect); + + // Getting the same wrapper again should return the newly created one + object wrapper1FromCache = Win2DHelper.GetOrCreate(d2D1Image1.Get(), canvasDevice1); + + Assert.AreSame(wrapper1, wrapper1FromCache); + + using ComPtr d2D1Image1FromNewWrapper = default; + + // Get the realized image from the newly created wrapper + Win2DHelper.GetD2DImage((ICanvasImage)wrapper1, canvasDevice1, d2D1Image1FromNewWrapper.GetAddressOf()); + + using ComPtr d2D1Image1Unknown = default; + using ComPtr d2D1Image1FromNewWrapperUnknown = default; + + Marshal.ThrowExceptionForHR(d2D1Image1.CopyTo(d2D1Image1Unknown.GetAddressOf())); + Marshal.ThrowExceptionForHR(d2D1Image1FromNewWrapper.CopyTo(d2D1Image1FromNewWrapperUnknown.GetAddressOf())); + + // The retrieved image should be the same one the new wrapper was created from + Assert.IsTrue(d2D1Image1Unknown.Get() == d2D1Image1FromNewWrapperUnknown.Get()); + + // The second resource is currently registered, so it returns the local wrapper + object wrapper2 = Win2DHelper.GetOrCreate(d2D1Image2.Get()); + + Assert.AreSame(effect, wrapper2); + } + + [TestMethod] + [ExpectedException(typeof(ArgumentException))] + public unsafe void Interop_WrapperFactoryDetectsMismatchedDevices() + { + PixelShaderEffect effect = new(); + CanvasDevice canvasDevice1 = new(); + CanvasDevice canvasDevice2 = new(); + + using ComPtr d2D1Image1 = default; + using ComPtr d2D1Image2 = default; + + Win2DHelper.GetD2DImage(effect, canvasDevice1, d2D1Image1.GetAddressOf()); + Win2DHelper.GetD2DImage(effect, canvasDevice2, d2D1Image2.GetAddressOf()); + + // The factory should detect we're passing an incompatible device for the resource + _ = Win2DHelper.GetOrCreate(d2D1Image1.Get(), canvasDevice2); + } + [D2DInputCount(0)] [AutoConstructor] private partial struct ShaderWithSomeProperties : ID2D1PixelShader @@ -180,6 +394,18 @@ public partial class PixelShaderEffectTests } } + [D2DInputCount(1)] + [AutoConstructor] + private partial struct ShaderWithSomePropertiesAndInputs : ID2D1PixelShader + { + public int Number; + + public float4 Execute() + { + return D2D.GetInput(0); + } + } + [D2DInputCount(0)] private partial struct ShaderWith0Inputs : ID2D1PixelShader { diff --git a/tests/ComputeSharp.D2D1.Uwp.Tests/ComputeSharp.D2D1.Uwp.Tests.csproj b/tests/ComputeSharp.D2D1.Uwp.Tests/ComputeSharp.D2D1.Uwp.Tests.csproj index 797c5c22..041635c7 100644 --- a/tests/ComputeSharp.D2D1.Uwp.Tests/ComputeSharp.D2D1.Uwp.Tests.csproj +++ b/tests/ComputeSharp.D2D1.Uwp.Tests/ComputeSharp.D2D1.Uwp.Tests.csproj @@ -23,7 +23,7 @@ true bin\ARM64\Debug\ DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP - ;2008 + $(NoWarn);2008 full ARM64 false @@ -35,7 +35,7 @@ bin\ARM64\Release\ TRACE;NETFX_CORE;WINDOWS_UWP true - ;2008 + $(NoWarn);2008 pdbonly ARM64 false @@ -47,7 +47,7 @@ true bin\x64\Debug\ DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP - ;2008 + $(NoWarn);2008 full x64 false @@ -58,7 +58,7 @@ bin\x64\Release\ TRACE;NETFX_CORE;WINDOWS_UWP true - ;2008 + $(NoWarn);2008 pdbonly x64 false @@ -137,6 +137,10 @@ 2.2.7 + + 1.13.1 + all + @@ -147,6 +151,8 @@ + + 14.0 diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index d3430177..7fe8533e 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -6,6 +6,9 @@ false + + $(NoWarn);CS0649 + $(NoWarn);CS1591 From 8dd6b584dae40026f909e2bc4cdc01692e886703 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 26 Apr 2023 16:19:22 +0200 Subject: [PATCH 11/14] Deterministically dispose all effects in unit tests This avoids the GC causing sporadic errors when running tests --- .../CanvasEffectTests.cs | 75 ++++++++++++------- .../PixelShaderEffectTests.cs | 47 ++++++------ .../ShadersTests.cs | 2 +- 3 files changed, 76 insertions(+), 48 deletions(-) diff --git a/tests/ComputeSharp.D2D1.UI.Tests/CanvasEffectTests.cs b/tests/ComputeSharp.D2D1.UI.Tests/CanvasEffectTests.cs index 8f80e15d..21a57cb2 100644 --- a/tests/ComputeSharp.D2D1.UI.Tests/CanvasEffectTests.cs +++ b/tests/ComputeSharp.D2D1.UI.Tests/CanvasEffectTests.cs @@ -15,36 +15,48 @@ public partial class CanvasEffectTests { EffectWithNoInputs effect = new(); - using (CanvasRenderTarget renderTarget = new(new CanvasDevice(), 128, 128, 96.0f)) - using (CanvasDrawingSession drawingSession = renderTarget.CreateDrawingSession()) + try { - drawingSession.DrawImage(effect); + using (CanvasRenderTarget renderTarget = new(new CanvasDevice(), 128, 128, 96.0f)) + using (CanvasDrawingSession drawingSession = renderTarget.CreateDrawingSession()) + { + drawingSession.DrawImage(effect); + } + + Assert.AreEqual(effect.NumberOfBuildEffectGraphCalls, 1); + Assert.AreEqual(effect.NumberOfConfigureEffectGraphCalls, 1); + Assert.AreEqual(effect.NumberOfDisposeCalls, 0); + + effect.Value = 42; + + using (CanvasRenderTarget renderTarget = new(new CanvasDevice(), 128, 128, 96.0f)) + using (CanvasDrawingSession drawingSession = renderTarget.CreateDrawingSession()) + { + drawingSession.DrawImage(effect); + } + + Assert.AreEqual(effect.NumberOfBuildEffectGraphCalls, 1); + Assert.AreEqual(effect.NumberOfConfigureEffectGraphCalls, 2); + Assert.AreEqual(effect.NumberOfDisposeCalls, 0); + + effect.ValueWithReload = 123; + + using (CanvasRenderTarget renderTarget = new(new CanvasDevice(), 128, 128, 96.0f)) + using (CanvasDrawingSession drawingSession = renderTarget.CreateDrawingSession()) + { + drawingSession.DrawImage(effect); + } + + Assert.AreEqual(effect.NumberOfBuildEffectGraphCalls, 2); + Assert.AreEqual(effect.NumberOfConfigureEffectGraphCalls, 3); + Assert.AreEqual(effect.NumberOfDisposeCalls, 0); } - - Assert.AreEqual(effect.NumberOfBuildEffectGraphCalls, 1); - Assert.AreEqual(effect.NumberOfConfigureEffectGraphCalls, 1); - - effect.Value = 42; - - using (CanvasRenderTarget renderTarget = new(new CanvasDevice(), 128, 128, 96.0f)) - using (CanvasDrawingSession drawingSession = renderTarget.CreateDrawingSession()) + finally { - drawingSession.DrawImage(effect); + effect.Dispose(); + + Assert.AreEqual(effect.NumberOfDisposeCalls, 1); } - - Assert.AreEqual(effect.NumberOfBuildEffectGraphCalls, 1); - Assert.AreEqual(effect.NumberOfConfigureEffectGraphCalls, 2); - - effect.ValueWithReload = 123; - - using (CanvasRenderTarget renderTarget = new(new CanvasDevice(), 128, 128, 96.0f)) - using (CanvasDrawingSession drawingSession = renderTarget.CreateDrawingSession()) - { - drawingSession.DrawImage(effect); - } - - Assert.AreEqual(effect.NumberOfBuildEffectGraphCalls, 2); - Assert.AreEqual(effect.NumberOfConfigureEffectGraphCalls, 3); } private sealed class EffectWithNoInputs : CanvasEffect @@ -69,6 +81,8 @@ public partial class CanvasEffectTests public int NumberOfConfigureEffectGraphCalls { get; private set; } + public int NumberOfDisposeCalls { get; private set; } + protected override ICanvasImage BuildEffectGraph() { NumberOfBuildEffectGraphCalls++; @@ -82,6 +96,15 @@ public partial class CanvasEffectTests this.effect!.ConstantBuffer = new ShaderWithNoInputs(this.value); } + + protected override void Dispose(bool disposing) + { + NumberOfDisposeCalls++; + + base.Dispose(disposing); + + this.effect?.Dispose(); + } } [D2DInputCount(0)] diff --git a/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs b/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs index 8176ff97..64e2291c 100644 --- a/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs +++ b/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs @@ -17,7 +17,7 @@ public partial class PixelShaderEffectTests [TestMethod] public unsafe void ConstantBuffer_IsInitiallySetToDefault() { - PixelShaderEffect effect = new(); + using PixelShaderEffect effect = new(); ShaderWithSomeProperties shader = effect.ConstantBuffer; ShaderWithSomeProperties defaultShader = default; @@ -39,7 +39,7 @@ public partial class PixelShaderEffectTests D: new uint2x2(8888, 123456, 98765, 192837465), E: new float2(-3.14f, 6.28f)); - PixelShaderEffect effect = new() { ConstantBuffer = shader }; + using PixelShaderEffect effect = new() { ConstantBuffer = shader }; ShaderWithSomeProperties roundTripShader = effect.ConstantBuffer; @@ -81,19 +81,19 @@ public partial class PixelShaderEffectTests [ExpectedException(typeof(ArgumentOutOfRangeException))] public void SourcesOutOfRange_ThrowsArgumentOutOfRangeException() { - PixelShaderEffect effect0 = new(); + using PixelShaderEffect effect0 = new(); _ = Assert.ThrowsException(() => effect0.Sources[0] = null); _ = Assert.ThrowsException(() => effect0.Sources[1] = null); - PixelShaderEffect effect1 = new(); + using PixelShaderEffect effect1 = new(); effect1.Sources[0] = null; _ = Assert.ThrowsException(() => effect1.Sources[1] = null); _ = Assert.ThrowsException(() => effect1.Sources[2] = null); - PixelShaderEffect effect2 = new(); + using PixelShaderEffect effect2 = new(); effect2.Sources[0] = null; effect2.Sources[1] = null; @@ -106,7 +106,7 @@ public partial class PixelShaderEffectTests [ExpectedException(typeof(ArgumentNullException))] public void NullTransformMapper_UnrealizedEffect_ThrowsArgumentNullException() { - PixelShaderEffect effect = new(); + using PixelShaderEffect effect = new(); effect.TransformMapper = null!; } @@ -115,7 +115,7 @@ public partial class PixelShaderEffectTests [ExpectedException(typeof(ArgumentNullException))] public void NullTransformMapper_RealizedEffect_ThrowsArgumentNullException() { - PixelShaderEffect effect = new(); + using PixelShaderEffect effect = new(); using (CanvasRenderTarget renderTarget = new(new CanvasDevice(), 128, 128, 96.0f)) using (CanvasDrawingSession drawingSession = renderTarget.CreateDrawingSession()) @@ -130,13 +130,13 @@ public partial class PixelShaderEffectTests [ExpectedException(typeof(Exception), AllowDerivedTypes = true)] public unsafe void GraphCycle_IsDetectedCorrectly() { - PixelShaderEffect effect1 = new(); - PixelShaderEffect effect2 = new(); - PixelShaderEffect effect3 = new(); - PixelShaderEffect effect4 = new(); - PixelShaderEffect effect5 = new(); - PixelShaderEffect effect6 = new(); - PixelShaderEffect effect7 = new(); + using PixelShaderEffect effect1 = new(); + using PixelShaderEffect effect2 = new(); + using PixelShaderEffect effect3 = new(); + using PixelShaderEffect effect4 = new(); + using PixelShaderEffect effect5 = new(); + using PixelShaderEffect effect6 = new(); + using PixelShaderEffect effect7 = new(); // Build a graph with a cycle in it: // @@ -173,8 +173,8 @@ public partial class PixelShaderEffectTests { ShaderWithSomePropertiesAndInputs shader = new(-1234567); - PixelShaderEffect effect0 = new(); - PixelShaderEffect effect1 = new() + using PixelShaderEffect effect0 = new(); + using PixelShaderEffect effect1 = new() { ConstantBuffer = shader, CacheOutput = true, @@ -254,8 +254,8 @@ public partial class PixelShaderEffectTests { ShaderWithSomePropertiesAndInputs shader = new(-1234567); - PixelShaderEffect effect0 = new(); - PixelShaderEffect effect1 = new(); + using PixelShaderEffect effect0 = new(); + using PixelShaderEffect effect1 = new(); CanvasDevice canvasDevice = new(); @@ -305,7 +305,7 @@ public partial class PixelShaderEffectTests [TestMethod] public unsafe void Interop_IsWrapperRegisteredCorrectly() { - PixelShaderEffect effect = new(); + using PixelShaderEffect effect = new(); using ComPtr d2D1Image = default; @@ -319,7 +319,8 @@ public partial class PixelShaderEffectTests [TestMethod] public unsafe void Interop_IsWrapperFactoryRegisteredCorrectlyAndWorking() { - PixelShaderEffect effect = new(); + using PixelShaderEffect effect = new(); + CanvasDevice canvasDevice1 = new(); CanvasDevice canvasDevice2 = new(); @@ -335,6 +336,9 @@ public partial class PixelShaderEffectTests Assert.IsTrue(wrapper1 is PixelShaderEffect); Assert.AreNotSame(wrapper1, effect); + // Property dispose the new wrapper as well + using PixelShaderEffect _ = (PixelShaderEffect)wrapper1; + // Getting the same wrapper again should return the newly created one object wrapper1FromCache = Win2DHelper.GetOrCreate(d2D1Image1.Get(), canvasDevice1); @@ -364,7 +368,8 @@ public partial class PixelShaderEffectTests [ExpectedException(typeof(ArgumentException))] public unsafe void Interop_WrapperFactoryDetectsMismatchedDevices() { - PixelShaderEffect effect = new(); + using PixelShaderEffect effect = new(); + CanvasDevice canvasDevice1 = new(); CanvasDevice canvasDevice2 = new(); diff --git a/tests/ComputeSharp.D2D1.UI.Tests/ShadersTests.cs b/tests/ComputeSharp.D2D1.UI.Tests/ShadersTests.cs index 86e88d6d..374fb3ad 100644 --- a/tests/ComputeSharp.D2D1.UI.Tests/ShadersTests.cs +++ b/tests/ComputeSharp.D2D1.UI.Tests/ShadersTests.cs @@ -79,7 +79,7 @@ public class ShadersTests T shader = (T)Activator.CreateInstance(typeof(T), 0f, new int2(1280, 720))!; // Either create the effect directly, or a canvas effect - ICanvasImage canvasImage = wrapperType switch + using ICanvasImage canvasImage = wrapperType switch { WrapperType.PixelShaderEffect => new PixelShaderEffect() { ConstantBuffer = shader }, _ => new TestCanvasEffect { ConstantBuffer = shader } From 4a15e11c9cb117cfc42aea57d976a349c0acbfdb Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 26 Apr 2023 16:19:55 +0200 Subject: [PATCH 12/14] Unregister PixelShaderEffect wrapper in finalizer --- .../PixelShaderEffect{T}.ReferenceTracking.cs | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ReferenceTracking.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ReferenceTracking.cs index dd5695ee..97ce8fa2 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ReferenceTracking.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ReferenceTracking.cs @@ -1,6 +1,12 @@ using System; using ComputeSharp.Interop; using System.Runtime.CompilerServices; +#if WINDOWS_UWP +using ComputeSharp.D2D1.Uwp.Helpers; +#else +using ComputeSharp.D2D1.WinUI.Helpers; +#endif +using TerraFX.Interop.Windows; #if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; @@ -41,15 +47,27 @@ partial class PixelShaderEffect } /// - void IReferenceTrackedObject.DangerousOnDispose() + unsafe void IReferenceTrackedObject.DangerousOnDispose() { + // When the effect is disposed, we also unregister it from the resource manager cache. This + // is analogous to what is done when manually unrealizing the effect (eg. when using a new + // device. Without this call, the resource manager would keep registered effects alive for + // the entire process duration, even if their original wrappers are gone (ie. collected). + if (this.d2D1Effect.Get() is not null) + { + ResourceManager.UnregisterWrapper((IUnknown*)this.d2D1Effect.Get()); + } + + // Release the native D2D objects that were set during realization this.canvasDevice.Dispose(); this.d2D1RealizationDevice.Dispose(); this.d2D1Effect.Dispose(); - // Also release all native resources for the used sources. - // The transform mapper and resource texture managers don't - // need to be disposed, as those could be shared between effects. + // Also release all native resources for the used sources. The transform mapper and + // resource texture managers don't need to be disposed, as those could be shared + // between effects. Note that SourceReference.Dispose() will only release the native + // resources (ie. D2D images and effects), but it will not also dispose the managed + // wrappers (ie. IGraphicsEffectSource objects), as those can be shared as well. for (int i = 0; i < Sources.Count; i++) { Sources.Storage[i].Dispose(); From bb8a7b4cf078d185fa2544e38d16588309c1dc3b Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 26 Apr 2023 17:05:01 +0200 Subject: [PATCH 13/14] Add PixelShaderEffect unregistration on dispose tests --- .../PixelShaderEffectTests.cs | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs b/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs index 64e2291c..f02cbcd9 100644 --- a/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs +++ b/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using ComputeSharp.D2D1.Interop; using ComputeSharp.D2D1.UI.Tests.Helpers; @@ -316,6 +317,68 @@ public partial class PixelShaderEffectTests Assert.AreSame(effect, wrapper); } + [TestMethod] + public unsafe void Interop_IsWrapperUnregisteredCorrectly_FromExplicitDispose() + { + using ComPtr d2D1Image = default; + + PixelShaderEffect effect = new(); + CanvasDevice canvasDevice = new(); + + try + { + Win2DHelper.GetD2DImage(effect, canvasDevice, d2D1Image.GetAddressOf()); + } + finally + { + effect.Dispose(); + } + + object wrapper = Win2DHelper.GetOrCreate(d2D1Image.Get(), canvasDevice); + + Assert.IsTrue(wrapper is PixelShaderEffect); + Assert.AreNotSame(effect, wrapper); + + // Ensure the new wrapper is disposed as well + using PixelShaderEffect _ = (PixelShaderEffect)wrapper; + } + + [TestMethod] + [ExpectedException(typeof(Exception), AllowDerivedTypes = true)] + public unsafe void Interop_IsWrapperUnregisteredCorrectly_FromExplicitDispose_FailsWithNoDevice() + { + using ComPtr d2D1Image = default; + + using (PixelShaderEffect effect = new()) + { + Win2DHelper.GetD2DImage(effect, new CanvasDevice(), d2D1Image.GetAddressOf()); + } + + _ = Win2DHelper.GetOrCreate(d2D1Image.Get()); + } + + [TestMethod] + [ExpectedException(typeof(Exception), AllowDerivedTypes = true)] + public unsafe void Interop_IsWrapperUnregisteredCorrectly_FromFinalizer_FailsWithNoDevice() + { + using ComPtr d2D1Image = default; + + [MethodImpl(MethodImplOptions.NoInlining)] + static void Test(ID2D1Image** d2D1Image) + { + PixelShaderEffect effect = new(); + + Win2DHelper.GetD2DImage(effect, new CanvasDevice(), d2D1Image); + } + + Test(d2D1Image.GetAddressOf()); + + GC.Collect(); + GC.WaitForPendingFinalizers(); + + _ = Win2DHelper.GetOrCreate(d2D1Image.Get()); + } + [TestMethod] public unsafe void Interop_IsWrapperFactoryRegisteredCorrectlyAndWorking() { From d4c4586369681d048960ad1eadda786849b2cfdc Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 26 Apr 2023 17:12:49 +0200 Subject: [PATCH 14/14] Return D2DERR_WRONG_FACTORY for wrong device in factory --- ...ixelShaderEffect{T}.ICanvasEffectFactoryNative.cs | 2 +- .../Windows/shared/winerror/D2DERR.cs | 7 +++++-- .../PixelShaderEffectTests.cs | 12 ++++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffectFactoryNative.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffectFactoryNative.cs index 073b4ae2..a894c2f2 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffectFactoryNative.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffectFactoryNative.cs @@ -124,7 +124,7 @@ unsafe partial class PixelShaderEffect { *wrapper = null; - return E.E_INVALIDARG; + return D2DERR.D2DERR_WRONG_FACTORY; } } diff --git a/src/TerraFX.Interop.Windows.D2D1/Windows/shared/winerror/D2DERR.cs b/src/TerraFX.Interop.Windows.D2D1/Windows/shared/winerror/D2DERR.cs index 542a9408..472a86b8 100644 --- a/src/TerraFX.Interop.Windows.D2D1/Windows/shared/winerror/D2DERR.cs +++ b/src/TerraFX.Interop.Windows.D2D1/Windows/shared/winerror/D2DERR.cs @@ -7,12 +7,15 @@ namespace TerraFX.Interop.DirectX; internal static partial class D2DERR { - [NativeTypeName("#define D2DERR_INSUFFICIENT_DEVICE_CAPABILITIES _HRESULT_TYPEDEF_(0x88990026L)")] - public const int D2DERR_INSUFFICIENT_DEVICE_CAPABILITIES = unchecked((int)(0x88990026)); + [NativeTypeName("#define D2DERR_WRONG_FACTORY _HRESULT_TYPEDEF_(0x88990012L)")] + public const int D2DERR_WRONG_FACTORY = unchecked((int)(0x88990012)); [NativeTypeName("#define D2DERR_CYCLIC_GRAPH _HRESULT_TYPEDEF_(0x88990020L)")] public const int D2DERR_CYCLIC_GRAPH = unchecked((int)(0x88990020)); + [NativeTypeName("#define D2DERR_INSUFFICIENT_DEVICE_CAPABILITIES _HRESULT_TYPEDEF_(0x88990026L)")] + public const int D2DERR_INSUFFICIENT_DEVICE_CAPABILITIES = unchecked((int)(0x88990026)); + [NativeTypeName("#define D2DERR_EFFECT_IS_NOT_REGISTERED _HRESULT_TYPEDEF_(0x88990028L)")] public const int D2DERR_EFFECT_IS_NOT_REGISTERED = unchecked((int)(0x88990028)); } \ No newline at end of file diff --git a/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs b/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs index f02cbcd9..d1ca0216 100644 --- a/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs +++ b/tests/ComputeSharp.D2D1.UI.Tests/PixelShaderEffectTests.cs @@ -428,7 +428,6 @@ public partial class PixelShaderEffectTests } [TestMethod] - [ExpectedException(typeof(ArgumentException))] public unsafe void Interop_WrapperFactoryDetectsMismatchedDevices() { using PixelShaderEffect effect = new(); @@ -443,7 +442,16 @@ public partial class PixelShaderEffectTests Win2DHelper.GetD2DImage(effect, canvasDevice2, d2D1Image2.GetAddressOf()); // The factory should detect we're passing an incompatible device for the resource - _ = Win2DHelper.GetOrCreate(d2D1Image1.Get(), canvasDevice2); + try + { + _ = Win2DHelper.GetOrCreate(d2D1Image1.Get(), canvasDevice2); + + Assert.Fail(); + } + catch (Exception e) + { + Assert.AreEqual(e.HResult, D2DERR.D2DERR_WRONG_FACTORY); + } } [D2DInputCount(0)]