From 97a6dfdc6342b351810742b34c15130c39faec67 Mon Sep 17 00:00:00 2001 From: Philip Gossweiler Date: Wed, 21 Jun 2023 09:55:31 +0200 Subject: [PATCH] Add a WinAppSdk app that renders content with DirectX --- .gitattributes | 64 +++ .gitignore | 20 + SwapChainPanelBugRepro.sln | 35 ++ SwapChainPanelBugRepro/App.cpp | 32 ++ SwapChainPanelBugRepro/App.h | 17 + SwapChainPanelBugRepro/App.idl | 3 + SwapChainPanelBugRepro/App.xaml | 12 + .../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 SwapChainPanelBugRepro/Assets/StoreLogo.png | Bin 0 -> 1451 bytes .../Assets/Wide310x150Logo.scale-200.png | Bin 0 -> 3204 bytes SwapChainPanelBugRepro/MainWindow.cpp | 33 ++ SwapChainPanelBugRepro/MainWindow.h | 26 ++ SwapChainPanelBugRepro/MainWindow.idl | 8 + SwapChainPanelBugRepro/MainWindow.xaml | 24 ++ SwapChainPanelBugRepro/Package.appxmanifest | 51 +++ SwapChainPanelBugRepro/Page/SquarePage.cpp | 8 + SwapChainPanelBugRepro/Page/SquarePage.h | 19 + SwapChainPanelBugRepro/Page/SquarePage.idl | 8 + SwapChainPanelBugRepro/Page/SquarePage.xaml | 16 + SwapChainPanelBugRepro/Page/TrianglePage.cpp | 8 + SwapChainPanelBugRepro/Page/TrianglePage.h | 19 + SwapChainPanelBugRepro/Page/TrianglePage.idl | 8 + SwapChainPanelBugRepro/Page/TrianglePage.xaml | 16 + .../Renderer/SquareRenderer.cpp | 122 ++++++ .../Renderer/SquareRenderer.h | 64 +++ .../Renderer/TriangleRenderer.cpp | 122 ++++++ .../Renderer/TriangleRenderer.h | 61 +++ .../Shader/Compiled/PixelShaderCode.h | 107 +++++ .../Shader/Compiled/VertexShaderCode.h | 132 ++++++ .../Shader/PixelShader.hlsl | 11 + .../Shader/VertexShader.hlsl | 21 + .../SwapChainPanelBugRepro.vcxproj | 292 +++++++++++++ .../SwapChainPanelBugRepro.vcxproj.filters | 130 ++++++ SwapChainPanelBugRepro/Vertex/Vertex.h | 17 + SwapChainPanelBugRepro/View/BaseView.cpp | 389 ++++++++++++++++++ SwapChainPanelBugRepro/View/BaseView.h | 118 ++++++ SwapChainPanelBugRepro/View/BaseView.idl | 6 + SwapChainPanelBugRepro/View/SquareView.cpp | 75 ++++ SwapChainPanelBugRepro/View/SquareView.h | 36 ++ SwapChainPanelBugRepro/View/SquareView.idl | 11 + SwapChainPanelBugRepro/View/TriangleView.cpp | 75 ++++ SwapChainPanelBugRepro/View/TriangleView.h | 36 ++ SwapChainPanelBugRepro/View/TriangleView.idl | 11 + SwapChainPanelBugRepro/app.manifest | 18 + SwapChainPanelBugRepro/packages.config | 6 + SwapChainPanelBugRepro/pch.cpp | 1 + SwapChainPanelBugRepro/pch.h | 22 + 51 files changed, 2310 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 SwapChainPanelBugRepro.sln create mode 100644 SwapChainPanelBugRepro/App.cpp create mode 100644 SwapChainPanelBugRepro/App.h create mode 100644 SwapChainPanelBugRepro/App.idl create mode 100644 SwapChainPanelBugRepro/App.xaml create mode 100644 SwapChainPanelBugRepro/Assets/LockScreenLogo.scale-200.png create mode 100644 SwapChainPanelBugRepro/Assets/SplashScreen.scale-200.png create mode 100644 SwapChainPanelBugRepro/Assets/Square150x150Logo.scale-200.png create mode 100644 SwapChainPanelBugRepro/Assets/Square44x44Logo.scale-200.png create mode 100644 SwapChainPanelBugRepro/Assets/Square44x44Logo.targetsize-24_altform-unplated.png create mode 100644 SwapChainPanelBugRepro/Assets/StoreLogo.png create mode 100644 SwapChainPanelBugRepro/Assets/Wide310x150Logo.scale-200.png create mode 100644 SwapChainPanelBugRepro/MainWindow.cpp create mode 100644 SwapChainPanelBugRepro/MainWindow.h create mode 100644 SwapChainPanelBugRepro/MainWindow.idl create mode 100644 SwapChainPanelBugRepro/MainWindow.xaml create mode 100644 SwapChainPanelBugRepro/Package.appxmanifest create mode 100644 SwapChainPanelBugRepro/Page/SquarePage.cpp create mode 100644 SwapChainPanelBugRepro/Page/SquarePage.h create mode 100644 SwapChainPanelBugRepro/Page/SquarePage.idl create mode 100644 SwapChainPanelBugRepro/Page/SquarePage.xaml create mode 100644 SwapChainPanelBugRepro/Page/TrianglePage.cpp create mode 100644 SwapChainPanelBugRepro/Page/TrianglePage.h create mode 100644 SwapChainPanelBugRepro/Page/TrianglePage.idl create mode 100644 SwapChainPanelBugRepro/Page/TrianglePage.xaml create mode 100644 SwapChainPanelBugRepro/Renderer/SquareRenderer.cpp create mode 100644 SwapChainPanelBugRepro/Renderer/SquareRenderer.h create mode 100644 SwapChainPanelBugRepro/Renderer/TriangleRenderer.cpp create mode 100644 SwapChainPanelBugRepro/Renderer/TriangleRenderer.h create mode 100644 SwapChainPanelBugRepro/Shader/Compiled/PixelShaderCode.h create mode 100644 SwapChainPanelBugRepro/Shader/Compiled/VertexShaderCode.h create mode 100644 SwapChainPanelBugRepro/Shader/PixelShader.hlsl create mode 100644 SwapChainPanelBugRepro/Shader/VertexShader.hlsl create mode 100644 SwapChainPanelBugRepro/SwapChainPanelBugRepro.vcxproj create mode 100644 SwapChainPanelBugRepro/SwapChainPanelBugRepro.vcxproj.filters create mode 100644 SwapChainPanelBugRepro/Vertex/Vertex.h create mode 100644 SwapChainPanelBugRepro/View/BaseView.cpp create mode 100644 SwapChainPanelBugRepro/View/BaseView.h create mode 100644 SwapChainPanelBugRepro/View/BaseView.idl create mode 100644 SwapChainPanelBugRepro/View/SquareView.cpp create mode 100644 SwapChainPanelBugRepro/View/SquareView.h create mode 100644 SwapChainPanelBugRepro/View/SquareView.idl create mode 100644 SwapChainPanelBugRepro/View/TriangleView.cpp create mode 100644 SwapChainPanelBugRepro/View/TriangleView.h create mode 100644 SwapChainPanelBugRepro/View/TriangleView.idl create mode 100644 SwapChainPanelBugRepro/app.manifest create mode 100644 SwapChainPanelBugRepro/packages.config create mode 100644 SwapChainPanelBugRepro/pch.cpp create mode 100644 SwapChainPanelBugRepro/pch.h diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..f4742df --- /dev/null +++ b/.gitattributes @@ -0,0 +1,64 @@ +################################################################################ +# Git automatically determines whether it deals with text or binary files. If it +# determines that a file is a text file it will convert all line endings of that +# file to be just single LF (line feed) characters before committing the file. +# This behaviour can be altered by providing more specific instructions for +# files after the below statement. +################################################################################ + +* text=auto + + +################################################################################ +# Files interpreted by the Windows cmd.exe shall be treated as text files which +# means their line endings are converted to just LF instead of CRLF when such a +# file is committed. If the file is written out to the working directory the +# line endings are always converted to CRLF. +################################################################################ + +*.bat text eol=crlf +*.cmd text eol=crlf + + +################################################################################ +# Visual Studio project and solution files shall be treated as text files which +# means that their line endings are converted to just LF instead of CRLF when +# such files are committed. To prevent issues with Visual Studio, the line +# endings of those files are always converted to CRLF once the files are written +# out to the working directory, regardless of the operating system on which this +# happens. +################################################################################ + +*.props text eol=crlf +*.sln text eol=crlf +*.vcxitems text eol=crlf +*.vcxproj text eol=crlf + + +################################################################################ +# Treat the following files as text files which means that their line endings +# are converted to just LF instead of CRLF when such a file is committed. If the +# file is written out to the working directory the line endings are converted to +# the default line ending of the platform. +################################################################################ + +*.c text +*.cpp text +*.h text +*.hlsl text +*.hpp text +*.inl text +*.rc text +*.xaml text +*.xml text + + +################################################################################ +# Treat the following files as binary files which means there is no line endings +# conversion applied and changes are stored as binary patches. +################################################################################ + +*.gif binary +*.jpg binary +*.pdf binary +*.png binary diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d9f1f90 --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +################################################################################ +# Prevents specific files and folders from being added to Git. +################################################################################ + +/.vs +/bin +/packages +/SwapChainPanelBugRepro/Generated Files +/SwapChainPanelBugRepro/obj + + +################################################################################ +# Prevents files with the below listed file extensions from being added to Git. +################################################################################ + +*.db +*.opendb +*.user +*.suo +*.payload.desc diff --git a/SwapChainPanelBugRepro.sln b/SwapChainPanelBugRepro.sln new file mode 100644 index 0000000..08b5fb6 --- /dev/null +++ b/SwapChainPanelBugRepro.sln @@ -0,0 +1,35 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33414.496 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SwapChainPanelBugRepro", "SwapChainPanelBugRepro\SwapChainPanelBugRepro.vcxproj", "{08C7CA65-5B00-4BC9-8128-FA34B8EF8685}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {08C7CA65-5B00-4BC9-8128-FA34B8EF8685}.Debug|x64.ActiveCfg = Debug|x64 + {08C7CA65-5B00-4BC9-8128-FA34B8EF8685}.Debug|x64.Build.0 = Debug|x64 + {08C7CA65-5B00-4BC9-8128-FA34B8EF8685}.Debug|x64.Deploy.0 = Debug|x64 + {08C7CA65-5B00-4BC9-8128-FA34B8EF8685}.Debug|x86.ActiveCfg = Debug|Win32 + {08C7CA65-5B00-4BC9-8128-FA34B8EF8685}.Debug|x86.Build.0 = Debug|Win32 + {08C7CA65-5B00-4BC9-8128-FA34B8EF8685}.Debug|x86.Deploy.0 = Debug|Win32 + {08C7CA65-5B00-4BC9-8128-FA34B8EF8685}.Release|x64.ActiveCfg = Release|x64 + {08C7CA65-5B00-4BC9-8128-FA34B8EF8685}.Release|x64.Build.0 = Release|x64 + {08C7CA65-5B00-4BC9-8128-FA34B8EF8685}.Release|x64.Deploy.0 = Release|x64 + {08C7CA65-5B00-4BC9-8128-FA34B8EF8685}.Release|x86.ActiveCfg = Release|Win32 + {08C7CA65-5B00-4BC9-8128-FA34B8EF8685}.Release|x86.Build.0 = Release|Win32 + {08C7CA65-5B00-4BC9-8128-FA34B8EF8685}.Release|x86.Deploy.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FEC6CC4D-F5F7-4831-9E6F-4F1BD89DBFA5} + EndGlobalSection +EndGlobal diff --git a/SwapChainPanelBugRepro/App.cpp b/SwapChainPanelBugRepro/App.cpp new file mode 100644 index 0000000..2bc87fb --- /dev/null +++ b/SwapChainPanelBugRepro/App.cpp @@ -0,0 +1,32 @@ +#include "pch.h" +#include "App.h" +#include "MainWindow.h" + + +namespace winrt::SwapChainPanelBugRepro::implementation +{ + using namespace winrt::Microsoft::UI::Xaml; + + + App::App() + { + InitializeComponent(); + +#if defined _DEBUG && !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION + UnhandledException([](IInspectable const&, UnhandledExceptionEventArgs const& e) { + if(IsDebuggerPresent()) + { + auto errorMessage = e.Message(); + __debugbreak(); + } + }); +#endif + } + + + void App::OnLaunched(LaunchActivatedEventArgs const&) + { + window = winrt::make(); + window.Activate(); + } +} diff --git a/SwapChainPanelBugRepro/App.h b/SwapChainPanelBugRepro/App.h new file mode 100644 index 0000000..baad799 --- /dev/null +++ b/SwapChainPanelBugRepro/App.h @@ -0,0 +1,17 @@ +#pragma once + +#include "App.xaml.g.h" + + +namespace winrt::SwapChainPanelBugRepro::implementation +{ + struct App : AppT + { + public: + App(); + void OnLaunched(winrt::Microsoft::UI::Xaml::LaunchActivatedEventArgs const&); + + private: + winrt::Microsoft::UI::Xaml::Window window{ nullptr }; + }; +} diff --git a/SwapChainPanelBugRepro/App.idl b/SwapChainPanelBugRepro/App.idl new file mode 100644 index 0000000..efcd6dd --- /dev/null +++ b/SwapChainPanelBugRepro/App.idl @@ -0,0 +1,3 @@ +namespace SwapChainPanelBugRepro +{ +} diff --git a/SwapChainPanelBugRepro/App.xaml b/SwapChainPanelBugRepro/App.xaml new file mode 100644 index 0000000..a461f8f --- /dev/null +++ b/SwapChainPanelBugRepro/App.xaml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/SwapChainPanelBugRepro/Assets/LockScreenLogo.scale-200.png b/SwapChainPanelBugRepro/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/SwapChainPanelBugRepro/Assets/SplashScreen.scale-200.png b/SwapChainPanelBugRepro/Assets/SplashScreen.scale-200.png new file mode 100644 index 0000000000000000000000000000000000000000..023e7f1feda78d5100569825acedfd213a0d84e9 GIT binary patch literal 7700 zcmeHLYj~4Yw%(;oxoEH#Kxq-eR|+VkP17b#Vk;?4QwkI+A{L04G+#<<(x#Un1#+h5>eArRq zTw$)ZvTWW_Y?bDho0nPVTh08+s`sp!j74rJTTtXIDww0SILedFv?sZ?yb@@}GN;#8 znk_b~Q(A0YR#uV4ef!osoV1M3;vQ8N$O|fStfgf$S5;ddUNv`tWtGjM;koG#N;7M< zP*84lnx(bn_KF&9Z5Ai$)#Cs3a|$OFw>WKCT$of*L7_CqQEinflT|W{JT+aKp-E0v zsxmYg)1(T>DROm+LN1eQw8}KCTp=C!$H7`PU!t9_Hw@TsTI2`udRZv*!a5`#A9hK6Y95L(CDUX&_@QxKV z_feX{UhA#ZWlvgpL$#w^D#lq`_A4AzDqd|Zv6y9PX&DNcN|l}_D^{q@GG&H^Pg583 z8FI6N8^H7b5WjGp;urW)d7F+_lcp%KsLX0viCmE(OHH+=%ZfD_=`voUuoUxFO^L;- z;!;2{g-YiiO6m4bs89OuF9!p{FGtH-f%8<2gY!h9s)4ciN%{Kh1+`}{^}M~+TDH9N z^Z5PlgVXMC&2&k*Hw^Lb9gny#ro$MOIxIt{+r)EA10$VR3 zanN8D{TUkl+v0CQ_>ZoHP<M-x#8@8ZiT#$Kh`(uRaX1g$Bg|qy$<#7 zSSAi{Nb8Y=lvNVeio+UGLCAtoLBfL`iOv`)yoJMDJBN>4IH@(l7YRF;61@>qq1iM9 zr@b#OC~SAxSle?5Pp8Z78{VO0YFr1x7kZU64Z23eLf2T2#6J_t;-E}DkB?NufZ0Ug zi?J&byXeaB-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kG|W#amBZ5{&XS2@6R~H z{9o^y*BkH4$~yX9U&@CgbOzX1bn9xqF|zh$Dh0Y5y*E0e90*$!ObrHY3Ok0`2=O~r zCuke6KrP9KOf?V(YDsM<6pX2nVoN%M$LT^q#FmtaF?1^27F*IcNX~XRB(|hCFvdcc zc)$=S-)acdk$g4?_>jRqxpI6M3vHZk?0c^3=byamYDNf;uB{3NlKW5IhnOS3DNkMV z?tK8?kJ}pmvp%&&eTVOVjHP`q34hN1@!aK}H(K!vI`~gf|Gv+FNEQD5Yd<~yX7k_l h&G-K)@HZb3BABY{)U1?^%I#E6`MGoTtustd{~yM6srvu` literal 0 HcmV?d00001 diff --git a/SwapChainPanelBugRepro/Assets/Square150x150Logo.scale-200.png b/SwapChainPanelBugRepro/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!bz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nej;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/SwapChainPanelBugRepro/Assets/Square44x44Logo.scale-200.png b/SwapChainPanelBugRepro/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/SwapChainPanelBugRepro/Assets/Square44x44Logo.targetsize-24_altform-unplated.png b/SwapChainPanelBugRepro/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/SwapChainPanelBugRepro/Assets/StoreLogo.png b/SwapChainPanelBugRepro/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/SwapChainPanelBugRepro/Assets/Wide310x150Logo.scale-200.png b/SwapChainPanelBugRepro/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>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sJbp~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(); + navigationView.SelectedItem(navigationView.MenuItems().GetAt(0)); + } + + + void MainWindow::OnSelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args) const + { + std::string selectedItemTagValue = to_string(unbox_value(args.SelectedItem().try_as().Tag())); + sender.Content().try_as().Navigate(_tagValueToPageTypeMap.at(selectedItemTagValue)); + } + + + const std::map> MainWindow::_tagValueToPageTypeMap = + { + { "TrianglePage", xaml_typename() }, + { "SquarePage" , xaml_typename() }, + }; +} diff --git a/SwapChainPanelBugRepro/MainWindow.h b/SwapChainPanelBugRepro/MainWindow.h new file mode 100644 index 0000000..0f1ec48 --- /dev/null +++ b/SwapChainPanelBugRepro/MainWindow.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include "MainWindow.g.h" + + +namespace winrt::SwapChainPanelBugRepro::implementation +{ + struct MainWindow : MainWindowT + { + public: + void OnLoaded(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& args) const; + void OnSelectionChanged(winrt::Microsoft::UI::Xaml::Controls::NavigationView sender, winrt::Microsoft::UI::Xaml::Controls::NavigationViewSelectionChangedEventArgs args) const; + + private: + static const std::map> _tagValueToPageTypeMap; + }; +} + + +namespace winrt::SwapChainPanelBugRepro::factory_implementation +{ + struct MainWindow : MainWindowT + { + }; +} diff --git a/SwapChainPanelBugRepro/MainWindow.idl b/SwapChainPanelBugRepro/MainWindow.idl new file mode 100644 index 0000000..8d2fd89 --- /dev/null +++ b/SwapChainPanelBugRepro/MainWindow.idl @@ -0,0 +1,8 @@ +namespace SwapChainPanelBugRepro +{ + [default_interface] + runtimeclass MainWindow : Microsoft.UI.Xaml.Window + { + MainWindow(); + } +} diff --git a/SwapChainPanelBugRepro/MainWindow.xaml b/SwapChainPanelBugRepro/MainWindow.xaml new file mode 100644 index 0000000..b4ad5c3 --- /dev/null +++ b/SwapChainPanelBugRepro/MainWindow.xaml @@ -0,0 +1,24 @@ + + + + + + + + + + + diff --git a/SwapChainPanelBugRepro/Package.appxmanifest b/SwapChainPanelBugRepro/Package.appxmanifest new file mode 100644 index 0000000..71a1acc --- /dev/null +++ b/SwapChainPanelBugRepro/Package.appxmanifest @@ -0,0 +1,51 @@ + + + + + + + + SwapChainPanelBugRepro + ackh + Assets\StoreLogo.png + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SwapChainPanelBugRepro/Page/SquarePage.cpp b/SwapChainPanelBugRepro/Page/SquarePage.cpp new file mode 100644 index 0000000..0e43cac --- /dev/null +++ b/SwapChainPanelBugRepro/Page/SquarePage.cpp @@ -0,0 +1,8 @@ +#include "pch.h" +#include "SquarePage.h" +#include "SquarePage.g.cpp" + + +namespace winrt::SwapChainPanelBugRepro::implementation +{ +} diff --git a/SwapChainPanelBugRepro/Page/SquarePage.h b/SwapChainPanelBugRepro/Page/SquarePage.h new file mode 100644 index 0000000..7862346 --- /dev/null +++ b/SwapChainPanelBugRepro/Page/SquarePage.h @@ -0,0 +1,19 @@ +#pragma once + +#include "SquarePage.g.h" + + +namespace winrt::SwapChainPanelBugRepro::implementation +{ + struct SquarePage : SquarePageT + { + }; +} + + +namespace winrt::SwapChainPanelBugRepro::factory_implementation +{ + struct SquarePage : SquarePageT + { + }; +} diff --git a/SwapChainPanelBugRepro/Page/SquarePage.idl b/SwapChainPanelBugRepro/Page/SquarePage.idl new file mode 100644 index 0000000..ebe8fe8 --- /dev/null +++ b/SwapChainPanelBugRepro/Page/SquarePage.idl @@ -0,0 +1,8 @@ +namespace SwapChainPanelBugRepro +{ + [default_interface] + runtimeclass SquarePage : Microsoft.UI.Xaml.Controls.Page + { + SquarePage(); + } +} diff --git a/SwapChainPanelBugRepro/Page/SquarePage.xaml b/SwapChainPanelBugRepro/Page/SquarePage.xaml new file mode 100644 index 0000000..f9282dc --- /dev/null +++ b/SwapChainPanelBugRepro/Page/SquarePage.xaml @@ -0,0 +1,16 @@ + + + + + diff --git a/SwapChainPanelBugRepro/Page/TrianglePage.cpp b/SwapChainPanelBugRepro/Page/TrianglePage.cpp new file mode 100644 index 0000000..c28f17c --- /dev/null +++ b/SwapChainPanelBugRepro/Page/TrianglePage.cpp @@ -0,0 +1,8 @@ +#include "pch.h" +#include "TrianglePage.h" +#include "TrianglePage.g.cpp" + + +namespace winrt::SwapChainPanelBugRepro::implementation +{ +} diff --git a/SwapChainPanelBugRepro/Page/TrianglePage.h b/SwapChainPanelBugRepro/Page/TrianglePage.h new file mode 100644 index 0000000..ac7cfbf --- /dev/null +++ b/SwapChainPanelBugRepro/Page/TrianglePage.h @@ -0,0 +1,19 @@ +#pragma once + +#include "TrianglePage.g.h" + + +namespace winrt::SwapChainPanelBugRepro::implementation +{ + struct TrianglePage : TrianglePageT + { + }; +} + + +namespace winrt::SwapChainPanelBugRepro::factory_implementation +{ + struct TrianglePage : TrianglePageT + { + }; +} diff --git a/SwapChainPanelBugRepro/Page/TrianglePage.idl b/SwapChainPanelBugRepro/Page/TrianglePage.idl new file mode 100644 index 0000000..cd9a746 --- /dev/null +++ b/SwapChainPanelBugRepro/Page/TrianglePage.idl @@ -0,0 +1,8 @@ +namespace SwapChainPanelBugRepro +{ + [default_interface] + runtimeclass TrianglePage : Microsoft.UI.Xaml.Controls.Page + { + TrianglePage(); + } +} diff --git a/SwapChainPanelBugRepro/Page/TrianglePage.xaml b/SwapChainPanelBugRepro/Page/TrianglePage.xaml new file mode 100644 index 0000000..38b818a --- /dev/null +++ b/SwapChainPanelBugRepro/Page/TrianglePage.xaml @@ -0,0 +1,16 @@ + + + + + diff --git a/SwapChainPanelBugRepro/Renderer/SquareRenderer.cpp b/SwapChainPanelBugRepro/Renderer/SquareRenderer.cpp new file mode 100644 index 0000000..30a53c3 --- /dev/null +++ b/SwapChainPanelBugRepro/Renderer/SquareRenderer.cpp @@ -0,0 +1,122 @@ +#include "pch.h" +#include "SquareRenderer.h" +#include "../Shader/Compiled/VertexShaderCode.h" +#include "../Shader/Compiled/PixelShaderCode.h" + +using namespace SwapChainPanelBugRepro; + + +void SquareRenderer::SetScreenSize(float width, float height) +{ + _viewPort = CD3D11_VIEWPORT(0.0f, 0.0f, width, height); + _d3dContext->RSSetViewports(1, &_viewPort); +} + + +void SquareRenderer::RenderFrame() +{ + _d3dContext->OMSetRenderTargets(1, &_d3dRenderTargetView, _d3dDepthStencilView); + _d3dContext->ClearRenderTargetView(_d3dRenderTargetView, reinterpret_cast(&BACKGROUND_COLOR)); + _d3dContext->ClearDepthStencilView(_d3dDepthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); + _d3dContext->DrawIndexed(INDEX_COUNT, 0, 0); +} + + +void SquareRenderer::SetDevice(ID3D11Device1* d3dDevice) +{ + _d3dDevice = d3dDevice; +} + + +void SquareRenderer::SetContext(ID3D11DeviceContext1* d3dContext) +{ + _d3dContext = d3dContext; +} + + +void SquareRenderer::SetRenderTargetView(ID3D11RenderTargetView* renderTargetView) +{ + _d3dRenderTargetView = renderTargetView; +} + + +void SquareRenderer::SetDepthStencilView(ID3D11DepthStencilView* depthStencilView) +{ + _d3dDepthStencilView = depthStencilView; +} + + +void SquareRenderer::CreateDeviceResources() +{ + CreateVertexShader(); + CreatePixelShader(); + CreateVertexBuffer(); + CreateIndexBuffer(); + ConfigurePipeline(); +} + + +void SquareRenderer::CreateVertexShader() +{ + static constexpr D3D11_INPUT_ELEMENT_DESC vertexDesc[] = + { + { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, offsetof(Vertex, coordinates), D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "COLOR" , 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, offsetof(Vertex, color) , D3D11_INPUT_PER_VERTEX_DATA, 0 }, + }; + + auto shaderCode = reinterpret_cast(&_vertexShaderCode); + SIZE_T shaderSize = ARRAYSIZE(_vertexShaderCode); + + winrt::check_hresult(_d3dDevice->CreateVertexShader(shaderCode, shaderSize, nullptr, _vertexShader.put())); + winrt::check_hresult(_d3dDevice->CreateInputLayout(vertexDesc, ARRAYSIZE(vertexDesc), shaderCode, shaderSize, _inputLayout.put())); +} + + +void SquareRenderer::CreatePixelShader() +{ + auto shaderCode = reinterpret_cast(&_pixelShaderCode); + SIZE_T shaderSize = ARRAYSIZE(_pixelShaderCode); + + winrt::check_hresult(_d3dDevice->CreatePixelShader(shaderCode, shaderSize, nullptr, _pixelShader.put())); + _d3dContext->PSSetShader(_pixelShader.get(), nullptr, 0); +} + + +void SquareRenderer::CreateVertexBuffer() +{ + D3D11_SUBRESOURCE_DATA vertexBufferData{}; + vertexBufferData.pSysMem = VERTICES; + + D3D11_BUFFER_DESC vertexBufferDesc{}; + vertexBufferDesc.Usage = D3D11_USAGE_DYNAMIC; + vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; + vertexBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + vertexBufferDesc.ByteWidth = VERTICES_SIZE; + vertexBufferDesc.StructureByteStride = VERTEX_SIZE; + + winrt::check_hresult(_d3dDevice->CreateBuffer(&vertexBufferDesc, &vertexBufferData, _vertexBuffer.put())); +} + + +void SquareRenderer::CreateIndexBuffer() +{ + D3D11_SUBRESOURCE_DATA indexBufferData{}; + indexBufferData.pSysMem = INDICES; + + D3D11_BUFFER_DESC indexBufferDesc{}; + indexBufferDesc.Usage = D3D11_USAGE_IMMUTABLE; + indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; + indexBufferDesc.ByteWidth = INDICES_SIZE; + + winrt::check_hresult(_d3dDevice->CreateBuffer(&indexBufferDesc, &indexBufferData, _indexBuffer.put())); +} + + +void SquareRenderer::ConfigurePipeline() +{ + ID3D11Buffer* cubeVertexBuffer = _vertexBuffer.get(); + _d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + _d3dContext->VSSetShader(_vertexShader.get(), nullptr, 0); _d3dContext->IASetInputLayout(_inputLayout.get()); + _d3dContext->IASetVertexBuffers(0, 1, &cubeVertexBuffer, &VERTEX_SIZE, &OFFSET); + _d3dContext->IASetIndexBuffer(_indexBuffer.get(), DXGI_FORMAT_R32_UINT, 0); +} diff --git a/SwapChainPanelBugRepro/Renderer/SquareRenderer.h b/SwapChainPanelBugRepro/Renderer/SquareRenderer.h new file mode 100644 index 0000000..cf92081 --- /dev/null +++ b/SwapChainPanelBugRepro/Renderer/SquareRenderer.h @@ -0,0 +1,64 @@ +#pragma once + +#include +#include +#include "../Vertex/Vertex.h" + + +namespace SwapChainPanelBugRepro +{ + class SquareRenderer + { + public: + void SetScreenSize(float width, float height); + void RenderFrame(); + void SetDevice(ID3D11Device1* d3dDevice); + void SetContext(ID3D11DeviceContext1* d3dContext); + void SetRenderTargetView(ID3D11RenderTargetView* renderTargetView); + void SetDepthStencilView(ID3D11DepthStencilView* depthStencilView); + void CreateDeviceResources(); + + private: + static constexpr UINT OFFSET = 0; + static constexpr UINT VERTEX_SIZE = sizeof(Vertex); + static constexpr int VERTEX_COUNT = 4; + static constexpr int INDEX_COUNT = 6; + static constexpr int VERTICES_SIZE = VERTEX_COUNT * VERTEX_SIZE; + static constexpr int INDICES_SIZE = INDEX_COUNT * sizeof(int); + + static constexpr Vertex VERTICES[VERTEX_COUNT] = + { + { { -0.5f, 0.5f, 0.0f }, { 0.0f, 1.0f, 0.0f } }, + { { 0.5f, 0.5f, 0.0f }, { 0.0f, 0.0f, 1.0f } }, + { { 0.5f, -0.5f, 0.0f }, { 0.0f, 1.0f, 0.0f } }, + { { -0.5f, -0.5f, 0.0f }, { 0.0f, 0.0f, 1.0f } }, + }; + + static constexpr int INDICES[INDEX_COUNT] = + { + 0, 1, 2, + 2, 3, 0, + }; + + static constexpr ::DirectX::XMFLOAT4 BACKGROUND_COLOR = { 0.0f, 0.0f, 0.0f, 0.0f }; + + ID3D11Device1* _d3dDevice; + ID3D11DeviceContext1* _d3dContext; + ID3D11RenderTargetView* _d3dRenderTargetView; + ID3D11DepthStencilView* _d3dDepthStencilView; + + CD3D11_VIEWPORT _viewPort{}; + + winrt::com_ptr _inputLayout; + winrt::com_ptr _vertexShader; + winrt::com_ptr _pixelShader; + winrt::com_ptr _vertexBuffer; + winrt::com_ptr _indexBuffer; + + void CreateVertexShader(); + void CreatePixelShader(); + void CreateVertexBuffer(); + void CreateIndexBuffer(); + void ConfigurePipeline(); + }; +} diff --git a/SwapChainPanelBugRepro/Renderer/TriangleRenderer.cpp b/SwapChainPanelBugRepro/Renderer/TriangleRenderer.cpp new file mode 100644 index 0000000..27742af --- /dev/null +++ b/SwapChainPanelBugRepro/Renderer/TriangleRenderer.cpp @@ -0,0 +1,122 @@ +#include "pch.h" +#include "TriangleRenderer.h" +#include "../Shader/Compiled/VertexShaderCode.h" +#include "../Shader/Compiled/PixelShaderCode.h" + +using namespace SwapChainPanelBugRepro; + + +void TriangleRenderer::SetScreenSize(float width, float height) +{ + _viewPort = CD3D11_VIEWPORT(0.0f, 0.0f, width, height); + _d3dContext->RSSetViewports(1, &_viewPort); +} + + +void TriangleRenderer::RenderFrame() +{ + _d3dContext->OMSetRenderTargets(1, &_d3dRenderTargetView, _d3dDepthStencilView); + _d3dContext->ClearRenderTargetView(_d3dRenderTargetView, reinterpret_cast(&BACKGROUND_COLOR)); + _d3dContext->ClearDepthStencilView(_d3dDepthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); + _d3dContext->DrawIndexed(VERTEX_COUNT, 0, 0); +} + + +void TriangleRenderer::SetDevice(ID3D11Device1* d3dDevice) +{ + _d3dDevice = d3dDevice; +} + + +void TriangleRenderer::SetContext(ID3D11DeviceContext1* d3dContext) +{ + _d3dContext = d3dContext; +} + + +void TriangleRenderer::SetRenderTargetView(ID3D11RenderTargetView* renderTargetView) +{ + _d3dRenderTargetView = renderTargetView; +} + + +void TriangleRenderer::SetDepthStencilView(ID3D11DepthStencilView* depthStencilView) +{ + _d3dDepthStencilView = depthStencilView; +} + + +void TriangleRenderer::CreateDeviceResources() +{ + CreateVertexShader(); + CreatePixelShader(); + CreateVertexBuffer(); + CreateIndexBuffer(); + ConfigurePipeline(); +} + + +void TriangleRenderer::CreateVertexShader() +{ + static constexpr D3D11_INPUT_ELEMENT_DESC vertexDesc[] = + { + { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, offsetof(Vertex, coordinates), D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "COLOR" , 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, offsetof(Vertex, color) , D3D11_INPUT_PER_VERTEX_DATA, 0 }, + }; + + auto shaderCode = reinterpret_cast(&_vertexShaderCode); + SIZE_T shaderSize = ARRAYSIZE(_vertexShaderCode); + + winrt::check_hresult(_d3dDevice->CreateVertexShader(shaderCode, shaderSize, nullptr, _vertexShader.put())); + winrt::check_hresult(_d3dDevice->CreateInputLayout(vertexDesc, ARRAYSIZE(vertexDesc), shaderCode, shaderSize, _inputLayout.put())); +} + + +void TriangleRenderer::CreatePixelShader() +{ + auto shaderCode = reinterpret_cast(&_pixelShaderCode); + SIZE_T shaderSize = ARRAYSIZE(_pixelShaderCode); + + winrt::check_hresult(_d3dDevice->CreatePixelShader(shaderCode, shaderSize, nullptr, _pixelShader.put())); + _d3dContext->PSSetShader(_pixelShader.get(), nullptr, 0); +} + + +void TriangleRenderer::CreateVertexBuffer() +{ + D3D11_SUBRESOURCE_DATA vertexBufferData{}; + vertexBufferData.pSysMem = VERTICES; + + D3D11_BUFFER_DESC vertexBufferDesc{}; + vertexBufferDesc.Usage = D3D11_USAGE_DYNAMIC; + vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; + vertexBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + vertexBufferDesc.ByteWidth = VERTICES_SIZE; + vertexBufferDesc.StructureByteStride = VERTEX_SIZE; + + winrt::check_hresult(_d3dDevice->CreateBuffer(&vertexBufferDesc, &vertexBufferData, _vertexBuffer.put())); +} + + +void TriangleRenderer::CreateIndexBuffer() +{ + D3D11_SUBRESOURCE_DATA indexBufferData{}; + indexBufferData.pSysMem = INDICES; + + D3D11_BUFFER_DESC indexBufferDesc{}; + indexBufferDesc.Usage = D3D11_USAGE_IMMUTABLE; + indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; + indexBufferDesc.ByteWidth = INDICES_SIZE; + + winrt::check_hresult(_d3dDevice->CreateBuffer(&indexBufferDesc, &indexBufferData, _indexBuffer.put())); +} + + +void TriangleRenderer::ConfigurePipeline() +{ + ID3D11Buffer* cubeVertexBuffer = _vertexBuffer.get(); + _d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + _d3dContext->VSSetShader(_vertexShader.get(), nullptr, 0); _d3dContext->IASetInputLayout(_inputLayout.get()); + _d3dContext->IASetVertexBuffers(0, 1, &cubeVertexBuffer, &VERTEX_SIZE, &OFFSET); + _d3dContext->IASetIndexBuffer(_indexBuffer.get(), DXGI_FORMAT_R32_UINT, 0); +} diff --git a/SwapChainPanelBugRepro/Renderer/TriangleRenderer.h b/SwapChainPanelBugRepro/Renderer/TriangleRenderer.h new file mode 100644 index 0000000..7359311 --- /dev/null +++ b/SwapChainPanelBugRepro/Renderer/TriangleRenderer.h @@ -0,0 +1,61 @@ +#pragma once + +#include +#include +#include "../Vertex/Vertex.h" + + +namespace SwapChainPanelBugRepro +{ + class TriangleRenderer + { + public: + void SetScreenSize(float width, float height); + void RenderFrame(); + void SetDevice(ID3D11Device1* d3dDevice); + void SetContext(ID3D11DeviceContext1* d3dContext); + void SetRenderTargetView(ID3D11RenderTargetView* renderTargetView); + void SetDepthStencilView(ID3D11DepthStencilView* depthStencilView); + void CreateDeviceResources(); + + private: + static constexpr UINT OFFSET = 0; + static constexpr UINT VERTEX_SIZE = sizeof(Vertex); + static constexpr int VERTEX_COUNT = 3; + static constexpr int VERTICES_SIZE = VERTEX_COUNT * VERTEX_SIZE; + static constexpr int INDICES_SIZE = VERTEX_COUNT * sizeof(int); + + static constexpr Vertex VERTICES[VERTEX_COUNT] = + { + { { 0.0f, 0.5f, 0.0f }, { 1.0f, 0.0f, 0.0f } }, + { { 0.5f, -0.5f, 0.0f }, { 0.0f, 0.0f, 1.0f } }, + { { -0.5f, -0.5f, 0.0f }, { 0.0f, 1.0f, 0.0f } }, + }; + + static constexpr int INDICES[VERTEX_COUNT] = + { + 0, 1, 2, + }; + + static constexpr ::DirectX::XMFLOAT4 BACKGROUND_COLOR = { 0.0f, 0.0f, 0.0f, 0.0f }; + + ID3D11Device1* _d3dDevice; + ID3D11DeviceContext1* _d3dContext; + ID3D11RenderTargetView* _d3dRenderTargetView; + ID3D11DepthStencilView* _d3dDepthStencilView; + + CD3D11_VIEWPORT _viewPort{}; + + winrt::com_ptr _inputLayout; + winrt::com_ptr _vertexShader; + winrt::com_ptr _pixelShader; + winrt::com_ptr _vertexBuffer; + winrt::com_ptr _indexBuffer; + + void CreateVertexShader(); + void CreatePixelShader(); + void CreateVertexBuffer(); + void CreateIndexBuffer(); + void ConfigurePipeline(); + }; +} diff --git a/SwapChainPanelBugRepro/Shader/Compiled/PixelShaderCode.h b/SwapChainPanelBugRepro/Shader/Compiled/PixelShaderCode.h new file mode 100644 index 0000000..f84086c --- /dev/null +++ b/SwapChainPanelBugRepro/Shader/Compiled/PixelShaderCode.h @@ -0,0 +1,107 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// COLOR 0 xyzw 1 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_input_ps linear v1.xyzw +dcl_output o0.xyzw +mov o0.xyzw, v1.xyzw +ret +// Approximately 2 instruction slots used +#endif + +const BYTE _pixelShaderCode[] = +{ + 68, 88, 66, 67, 5, 145, + 138, 89, 190, 121, 149, 24, + 25, 10, 55, 219, 55, 198, + 37, 159, 1, 0, 0, 0, + 196, 1, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 128, 0, 0, 0, 212, 0, + 0, 0, 8, 1, 0, 0, + 72, 1, 0, 0, 82, 68, + 69, 70, 68, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 1, 0, 0, + 28, 0, 0, 0, 77, 105, + 99, 114, 111, 115, 111, 102, + 116, 32, 40, 82, 41, 32, + 72, 76, 83, 76, 32, 83, + 104, 97, 100, 101, 114, 32, + 67, 111, 109, 112, 105, 108, + 101, 114, 32, 49, 48, 46, + 49, 0, 73, 83, 71, 78, + 76, 0, 0, 0, 2, 0, + 0, 0, 8, 0, 0, 0, + 56, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 68, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 15, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 67, 79, 76, 79, 82, 0, + 171, 171, 79, 83, 71, 78, + 44, 0, 0, 0, 1, 0, + 0, 0, 8, 0, 0, 0, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 83, 86, 95, 84, 65, 82, + 71, 69, 84, 0, 171, 171, + 83, 72, 68, 82, 56, 0, + 0, 0, 64, 0, 0, 0, + 14, 0, 0, 0, 98, 16, + 0, 3, 242, 16, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 242, 32, 16, 0, + 0, 0, 0, 0, 70, 30, + 16, 0, 1, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 2, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 2, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; diff --git a/SwapChainPanelBugRepro/Shader/Compiled/VertexShaderCode.h b/SwapChainPanelBugRepro/Shader/Compiled/VertexShaderCode.h new file mode 100644 index 0000000..a5ff481 --- /dev/null +++ b/SwapChainPanelBugRepro/Shader/Compiled/VertexShaderCode.h @@ -0,0 +1,132 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyz 0 NONE float xyz +// COLOR 0 xyz 1 NONE float xyz +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float xyzw +// COLOR 0 xyzw 1 NONE float xyzw +// +vs_4_0 +dcl_input v0.xyz +dcl_input v1.xyz +dcl_output_siv o0.xyzw, position +dcl_output o1.xyzw +mov o0.xyz, v0.xyzx +mov o0.w, l(1.000000) +mov o1.xyz, v1.xyzx +mov o1.w, l(1.000000) +ret +// Approximately 5 instruction slots used +#endif + +const BYTE _vertexShaderCode[] = +{ + 68, 88, 66, 67, 58, 195, + 237, 110, 164, 146, 250, 86, + 115, 37, 243, 127, 145, 217, + 235, 67, 1, 0, 0, 0, + 56, 2, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 128, 0, 0, 0, 208, 0, + 0, 0, 36, 1, 0, 0, + 188, 1, 0, 0, 82, 68, + 69, 70, 68, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 28, 0, 0, 0, 77, 105, + 99, 114, 111, 115, 111, 102, + 116, 32, 40, 82, 41, 32, + 72, 76, 83, 76, 32, 83, + 104, 97, 100, 101, 114, 32, + 67, 111, 109, 112, 105, 108, + 101, 114, 32, 49, 48, 46, + 49, 0, 73, 83, 71, 78, + 72, 0, 0, 0, 2, 0, + 0, 0, 8, 0, 0, 0, + 56, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 7, 0, 0, + 65, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 7, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 67, 79, 76, + 79, 82, 0, 171, 79, 83, + 71, 78, 76, 0, 0, 0, + 2, 0, 0, 0, 8, 0, + 0, 0, 56, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 15, 0, + 0, 0, 68, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 1, 0, 0, 0, 15, 0, + 0, 0, 83, 86, 95, 80, + 79, 83, 73, 84, 73, 79, + 78, 0, 67, 79, 76, 79, + 82, 0, 171, 171, 83, 72, + 68, 82, 144, 0, 0, 0, + 64, 0, 1, 0, 36, 0, + 0, 0, 95, 0, 0, 3, + 114, 16, 16, 0, 0, 0, + 0, 0, 95, 0, 0, 3, + 114, 16, 16, 0, 1, 0, + 0, 0, 103, 0, 0, 4, + 242, 32, 16, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 1, 0, 0, 0, + 54, 0, 0, 5, 114, 32, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 32, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 0, 0, 128, 63, 54, 0, + 0, 5, 114, 32, 16, 0, + 1, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 54, 0, 0, 5, 130, 32, + 16, 0, 1, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 5, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 4, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; diff --git a/SwapChainPanelBugRepro/Shader/PixelShader.hlsl b/SwapChainPanelBugRepro/Shader/PixelShader.hlsl new file mode 100644 index 0000000..3a1fcf1 --- /dev/null +++ b/SwapChainPanelBugRepro/Shader/PixelShader.hlsl @@ -0,0 +1,11 @@ +struct PixelShaderInput +{ + float4 Position : SV_POSITION; + float4 Color : COLOR; +}; + + +float4 main(PixelShaderInput input) : SV_TARGET +{ + return input.Color; +} diff --git a/SwapChainPanelBugRepro/Shader/VertexShader.hlsl b/SwapChainPanelBugRepro/Shader/VertexShader.hlsl new file mode 100644 index 0000000..693631e --- /dev/null +++ b/SwapChainPanelBugRepro/Shader/VertexShader.hlsl @@ -0,0 +1,21 @@ +struct VertexShaderInput +{ + float3 Position : POSITION; + float3 Color : COLOR; +}; + + +struct VertexShaderOutput +{ + float4 Position : SV_POSITION; + float4 Color : COLOR; +}; + + +VertexShaderOutput main(VertexShaderInput input) +{ + VertexShaderOutput output; + output.Color = float4(input.Color, 1.0f); + output.Position = float4(input.Position, 1.0f); + return output; +} diff --git a/SwapChainPanelBugRepro/SwapChainPanelBugRepro.vcxproj b/SwapChainPanelBugRepro/SwapChainPanelBugRepro.vcxproj new file mode 100644 index 0000000..1cf7c27 --- /dev/null +++ b/SwapChainPanelBugRepro/SwapChainPanelBugRepro.vcxproj @@ -0,0 +1,292 @@ + + + + + + + true + true + true + {08c7ca65-5b00-4bc9-8128-fa34b8ef8685} + SwapChainPanelBugRepro + SwapChainPanelBugRepro + $(RootNamespace) + Application + en + false + true + Windows Store + 10.0 + 10.0 + 10.0.18362.0 + 16.0 + v143 + true + true + true + Unicode + $(SolutionDir)bin\Windows\$(Configuration)\$(Platform)\ + obj\$(Configuration)\$(Platform)\ + + false + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + true + true + + + false + true + false + + + + + + + + + + + + + + Designer + + + + + + + + + Designer + + + Designer + + + + + Use + pch.h + $(IntDir)pch.pch + Level4 + %(AdditionalOptions) /bigobj + %(AdditionalIncludeDirectories);$(GeneratedFilesDir)Page;$(GeneratedFilesDir)Control + stdcpp20 + + + + d3d11.lib; + dxgi.lib; + d2d1.lib; + dwrite.lib; + runtimeobject.lib; + %(AdditionalDependencies) + + + + + $(MSBuildThisFileDirectory); + $(MSBuildThisFileDirectory)Control; + $(MSBuildThisFileDirectory)Page; + $(MSBuildThisFileDirectory)View; + + + + + + _DEBUG;%(PreprocessorDefinitions) + + + + + NDEBUG;%(PreprocessorDefinitions) + + + true + true + + + + + Code + App.xaml + + + Code + MainWindow.xaml + + + Page\SquarePage.xaml + Code + + + Page\TrianglePage.xaml + Code + + + + + + + + App.xaml + + + MainWindow.xaml + + + Page\SquarePage.xaml + Code + + + Page\TrianglePage.xaml + Code + + + + + + + View\BaseView.idl + + + View\SquareView.idl + + + View\TriangleView.idl + + + + + App.xaml + + + MainWindow.xaml + + + + Page\SquarePage.xaml + Code + + + Page\TrianglePage.xaml + Code + + + Create + + + + + View\BaseView.idl + + + View\SquareView.idl + + + View\TriangleView.idl + + + + 4.0 + false + false + Document + + + + $(FileType) + Vertex + $(ShaderModel) + _vertexShaderCode + $(MSBuildThisFileDirectory)Shader\Compiled\VertexShaderCode.h + + + $(DisableOptimizations) + $(EnableDebuggingInformation) + + + $(FileType) + Pixel + $(ShaderModel) + _pixelShaderCode + $(MSBuildThisFileDirectory)Shader\Compiled\PixelShaderCode.h + + + $(DisableOptimizations) + $(EnableDebuggingInformation) + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + \ No newline at end of file diff --git a/SwapChainPanelBugRepro/SwapChainPanelBugRepro.vcxproj.filters b/SwapChainPanelBugRepro/SwapChainPanelBugRepro.vcxproj.filters new file mode 100644 index 0000000..0386528 --- /dev/null +++ b/SwapChainPanelBugRepro/SwapChainPanelBugRepro.vcxproj.filters @@ -0,0 +1,130 @@ + + + + + {7f5b9843-d5fb-43f2-8966-793064900cb6} + + + {6badc9d7-4508-4237-9df9-c04f231add3f} + + + {04da456e-9d07-434b-9f8a-85b2434f21ab} + + + {1fd25b04-8e88-44fb-b97e-9a361c639c5e} + + + {9c52c617-3b01-4ae1-8ca3-2b741e28c8cb} + + + {dfb87df8-985d-4748-a5d2-c1eecf20633e} + + + + + + + + + + + + + + + Page + + + Page + + + + + + + + + View + + + View + + + View + + + + + + Renderer + + + Renderer + + + Vertex + + + View + + + View + + + View + + + + + + + Renderer + + + Renderer + + + View + + + View + + + View + + + + + Shader + + + Shader + + + + + Assets + + + Assets + + + Assets + + + Assets + + + Assets + + + Assets + + + Assets + + + + + + \ No newline at end of file diff --git a/SwapChainPanelBugRepro/Vertex/Vertex.h b/SwapChainPanelBugRepro/Vertex/Vertex.h new file mode 100644 index 0000000..4012c94 --- /dev/null +++ b/SwapChainPanelBugRepro/Vertex/Vertex.h @@ -0,0 +1,17 @@ +#pragma once + +#include + + +namespace SwapChainPanelBugRepro +{ + struct Vertex + { + constexpr Vertex(::DirectX::XMFLOAT3 coordinates, ::DirectX::XMFLOAT3 color) : coordinates(coordinates), color(color) + { + } + + ::DirectX::XMFLOAT3 coordinates; + ::DirectX::XMFLOAT3 color; + }; +} diff --git a/SwapChainPanelBugRepro/View/BaseView.cpp b/SwapChainPanelBugRepro/View/BaseView.cpp new file mode 100644 index 0000000..0c3c953 --- /dev/null +++ b/SwapChainPanelBugRepro/View/BaseView.cpp @@ -0,0 +1,389 @@ +#include "pch.h" +#include "BaseView.h" +#include "BaseView.g.cpp" + + +namespace winrt::SwapChainPanelBugRepro::implementation +{ + using namespace winrt::Microsoft::UI::Xaml; + using namespace winrt::Microsoft::UI::Xaml::Controls; + using namespace winrt::Microsoft::UI::Xaml::Media; + using namespace winrt::Windows::Foundation; + using namespace winrt::Windows::UI; + + + BaseView::BaseView() + { + _loadedEventToken = Loaded({ this, &BaseView::OnLoaded }); + _unloadedEventToken = Unloaded({ this, &BaseView::OnUnloaded }); + } + + + BaseView::~BaseView() + { + Unloaded(_unloadedEventToken); + Loaded(_loadedEventToken); + } + + + void BaseView::CreateDeviceIndependentResources() + { + winrt::check_hresult(D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, FactoryOptions, _d2dFactory.put())); + winrt::check_hresult(CreateDXGIFactory1(IID_PPV_ARGS(_dxgiFactory.put()))); + winrt::check_hresult(_dxgiFactory->EnumAdapters(0, _dxgiAdapter.put())); + winrt::check_hresult(_dxgiAdapter->EnumOutputs(0, _dxgiOutput.put())); + } + + + void BaseView::CreateDeviceResources() + { + CreateD3D11Device(); + CreateD2D1Device(); + ExtractMultisamplingParameters(); + } + + + void BaseView::CreateSizeDependentResources() + { + CalculateRenderTargetSize(); + CreateOrResizeSwapChain(); + ScaleSwapChain(); + ObtainBackBuffer(); + + if(_multisampleAntiAliasingQuality <= 0) + { + CreateRenderTargetView(_d3dBackBuffer.get(), nullptr); + CreateDepthStencilView(1, D3D11_DSV_DIMENSION_TEXTURE2D); + SetD2D1Target(_d3dBackBuffer.as().get()); + } + + else + { + CD3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc(D3D11_RTV_DIMENSION_TEXTURE2DMS); + CreateMultiSampledBackBuffer(); + CreateRenderTargetView(_d3dBackBufferMultiSampled.get(), &renderTargetViewDesc); + CreateDepthStencilView(_multisampleAntiAliasingCount, D3D11_DSV_DIMENSION_TEXTURE2DMS); + SetD2D1Target(_d3dBackBufferMultiSampled.as().get()); + } + } + + + void BaseView::OnDeviceLost() + { + _dxgiSwapChain = nullptr; + DestroySizeDependentResources(); + DestroyDeviceResources(); + CreateDeviceResources(); + CreateSizeDependentResources(); + } + + + void BaseView::OnSizeChanged(IInspectable const&, SizeChangedEventArgs const&) + { + Concurrency::critical_section::scoped_lock lock(_criticalSection); + DestroySizeDependentResources(); + CreateSizeDependentResources(); + } + + + void BaseView::OnCompositionScaleChanged(SwapChainPanel const&, IInspectable const&) + { + float compositionScaleX = CompositionScaleX(); + float compositionScaleY = CompositionScaleY(); + + if(_compositionScaleX != compositionScaleX || _compositionScaleY != compositionScaleY) + { + Concurrency::critical_section::scoped_lock lock(_criticalSection); + _compositionScaleX = compositionScaleX; + _compositionScaleY = compositionScaleY; + DestroySizeDependentResources(); + CreateSizeDependentResources(); + } + } + + + IAsyncAction BaseView::OnLoaded(IInspectable const&, RoutedEventArgs const&) + { + // Obtaining a strong reference ensures that the instance is kept alive + // even while this coroutine is suspended. For more details see + // https://learn.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/weak-references#safely-accessing-the-this-pointer-in-a-class-member-coroutine + winrt::com_ptr keepInstanceAlive = get_strong(); + _sizeChangedEventToken = SizeChanged({ this, &BaseView::OnSizeChanged }); + _compositionScaleChangedEventToken = CompositionScaleChanged({ this, &BaseView::OnCompositionScaleChanged }); + co_await AfterLoaded(); + co_return; + } + + + IAsyncAction BaseView::AfterLoaded() + { + co_return; + } + + + IAsyncAction BaseView::OnUnloaded(IInspectable const&, RoutedEventArgs const&) + { + // Obtaining a strong reference ensures that the instance is kept alive + // even while this coroutine is suspended. For more details see + // https://learn.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/weak-references#safely-accessing-the-this-pointer-in-a-class-member-coroutine + winrt::com_ptr keepInstanceAlive = get_strong(); + co_await BeforeUnloaded(); + CompositionScaleChanged(_compositionScaleChangedEventToken); + SizeChanged(_sizeChangedEventToken); + co_return; + } + + + IAsyncAction BaseView::BeforeUnloaded() + { + co_return; + } + + + void BaseView::Present() + { + DownsampleMultiSampleBackBufferToBackBuffer(); + HandleResult(_dxgiSwapChain->Present1(1, 0, &PresentationParameters)); + } + + + ::DirectX::XMFLOAT3 BaseView::RgbFromBrush(SolidColorBrush const& brush) + { + Color color = brush.Color(); + return ::DirectX::XMFLOAT3(color.R / 255.0f, color.G / 255.0f, color.B / 255.0f); + } + + + ::DirectX::XMFLOAT4 BaseView::RgbaFromBrush(SolidColorBrush const& brush) + { + Color color = brush.Color(); + return ::DirectX::XMFLOAT4(color.R / 255.0f, color.G / 255.0f, color.B / 255.0f, color.A / 255.0f); + } + + + void BaseView::DestroyDeviceResources() + { + _d2dContext = nullptr; + _d3dContext = nullptr; + _d2dDevice = nullptr; + _d3dDevice = nullptr; + + _multisampleAntiAliasingQuality = 0; + } + + + void BaseView::DestroySizeDependentResources() + { + _d3dContext->OMSetRenderTargets(0, nullptr, nullptr); + _d3dContext->Flush(); + _d2dContext->SetTarget(nullptr); + + _d2dTargetBitmap = nullptr; + _d3dDepthStencilView = nullptr; + _d3dRenderTargetView = nullptr; + _d3dBackBufferMultiSampled = nullptr; + _d3dBackBuffer = nullptr; + } + + + void BaseView::CreateD3D11Device() + { + winrt::com_ptr device; + winrt::com_ptr context; + winrt::check_hresult(D3D11CreateDevice(nullptr, // Specify null to use the default adapter. + D3D_DRIVER_TYPE_HARDWARE, // Create a device using the hardware graphics driver. + nullptr, // Should be 0 unless the driver is D3D_DRIVER_TYPE_SOFTWARE. + DeviceCreationFlags, // Optionally set debug and Direct2D compatibility flags. + FeatureLevels, // List of feature levels this app can support. + ARRAYSIZE(FeatureLevels), // Size of the list above. + D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows Store apps. + device.put(), // Returns the Direct3D device created. + nullptr, // Returns feature level of device created. + context.put()) // Returns the device immediate context. + ); + + _d3dDevice = device.as(); + _d3dContext = context.as(); + + // Ensure that DXGI does not queue more than one frame at a time. This both reduces + // latency and ensures that the application will only render after each VSync, minimizing + // power consumption. + winrt::check_hresult(_d3dDevice.as()->SetMaximumFrameLatency(1)); + } + + + void BaseView::CreateD2D1Device() + { + winrt::check_hresult(_d2dFactory->CreateDevice(_d3dDevice.as().get(), _d2dDevice.put())); + winrt::check_hresult(_d2dDevice->CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS_NONE, _d2dContext.put())); + _d2dContext->SetTextAntialiasMode(D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE); + } + + + void BaseView::ExtractMultisamplingParameters() + { + if(_multisampleAntiAliasingCount > 0) + { + UINT formatSupport = 0; + _d3dDevice->CheckFormatSupport(DxgiFormat, &formatSupport); + + if((formatSupport & D3D11_FORMAT_SUPPORT_MULTISAMPLE_RESOLVE) && (formatSupport & D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET)) + { + _d3dDevice->CheckMultisampleQualityLevels(DxgiFormat, _multisampleAntiAliasingCount, &_multisampleAntiAliasingQuality); + } + } + } + + + void BaseView::CalculateRenderTargetSize() + { + // The buffers associated with the SwapChainPanel cannot have a width or height of 0. An exception + // is thrown if that is violated. However, Visual Studio's XAML Designer creates the user control + // before it knows the final size which means that both ActualWidth and ActualHeight could be 0 + // when the XAML Designer creates the control. This is not the case at runtime because this method + // is supposed to be invoked after the control is fully loaded, i.e. as reaction to the "Loaded" + // event. However, to be compatible with the XAML Designer we ensure that the buffers are never of + // size 0. + // See the following link for background information regarding this: + // https://developercommunity.visualstudio.com/t/XAML-Designer-fails-to-render-a-custom-D/875338 + // To debug a XAML control at design time see the following link: + // https://docs.microsoft.com/en-us/visualstudio/debugger/walkthrough-debugging-at-design-time + _renderTargetWidth = std::max(1.0f, static_cast(_compositionScaleX * ActualWidth())); + _renderTargetHeight = std::max(1.0f, static_cast(_compositionScaleY * ActualHeight())); + } + + + void BaseView::CreateOrResizeSwapChain() + { + if(!_dxgiSwapChain) + { + CreateSwapChain(); + } + + else + { + UINT width = static_cast(_renderTargetWidth); + UINT height = static_cast(_renderTargetHeight); + HandleResult(_dxgiSwapChain->ResizeBuffers(2, width, height, DxgiFormat, 0)); + } + } + + + void BaseView::CreateSwapChain() + { + DXGI_SWAP_CHAIN_DESC1 swapChainDesc{}; + swapChainDesc.Width = static_cast(_renderTargetWidth); + swapChainDesc.Height = static_cast(_renderTargetHeight); + swapChainDesc.Format = DxgiFormat; + swapChainDesc.Stereo = false; + swapChainDesc.SampleDesc.Count = 1; + swapChainDesc.SampleDesc.Quality = 0; + swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + swapChainDesc.BufferCount = 2; + swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; + swapChainDesc.Flags = 0; + swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED; + winrt::com_ptr swapChain; + winrt::check_hresult(_dxgiFactory->CreateSwapChainForComposition(_d3dDevice.get(), &swapChainDesc, nullptr, swapChain.put())); + winrt::check_hresult(this->try_as()->SetSwapChain(swapChain.get())); + _dxgiSwapChain = swapChain.as(); + } + + + void BaseView::ScaleSwapChain() + { + // Ensure the physical pixel size of the swap chain takes into account both the XAML + // SwapChainPanel's logical layout size and any cumulative composition scale applied + // due to zooming, render transforms, or the system's current scaling plateau. For + // example, if a 100x100 SwapChainPanel has a cumulative 2x scale transform applied, + // we instead create a 200x200 swap chain to avoid artifacts from scaling it up by + // 2x, then apply an inverse 1/2x transform to the swap chain to cancel out the 2x + // transform. + DXGI_MATRIX_3X2_F inverseScale{}; + inverseScale._11 = 1.0f / _compositionScaleX; + inverseScale._22 = 1.0f / _compositionScaleY; + _dxgiSwapChain->SetMatrixTransform(&inverseScale); + } + + + void BaseView::ObtainBackBuffer() + { + winrt::check_hresult(_dxgiSwapChain->GetBuffer(0, IID_PPV_ARGS(_d3dBackBuffer.put()))); + } + + + void BaseView::CreateRenderTargetView(ID3D11Resource* targetBuffer, const CD3D11_RENDER_TARGET_VIEW_DESC* renderTargetViewDesc) + { + winrt::check_hresult(_d3dDevice->CreateRenderTargetView(targetBuffer, renderTargetViewDesc, _d3dRenderTargetView.put())); + } + + + void BaseView::CreateDepthStencilView(UINT count, D3D11_DSV_DIMENSION dsvDimension) + { + CD3D11_TEXTURE2D_DESC depthStencilDesc{}; + depthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; + depthStencilDesc.Width = static_cast(_renderTargetWidth); + depthStencilDesc.Height = static_cast(_renderTargetHeight); + depthStencilDesc.ArraySize = 1; + depthStencilDesc.MipLevels = 1; + depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; + depthStencilDesc.SampleDesc.Count = count; + depthStencilDesc.SampleDesc.Quality = 0; + CD3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc(dsvDimension); + winrt::com_ptr depthStencilBuffer; + winrt::check_hresult(_d3dDevice->CreateTexture2D(&depthStencilDesc, nullptr, depthStencilBuffer.put())); + winrt::check_hresult(_d3dDevice->CreateDepthStencilView(depthStencilBuffer.get(), &depthStencilViewDesc, _d3dDepthStencilView.put())); + } + + + void BaseView::CreateMultiSampledBackBuffer() + { + D3D11_TEXTURE2D_DESC backBufferMultiSampledDesc{}; + backBufferMultiSampledDesc.Format = DxgiFormat; + backBufferMultiSampledDesc.Width = static_cast(_renderTargetWidth); + backBufferMultiSampledDesc.Height = static_cast(_renderTargetHeight); + backBufferMultiSampledDesc.BindFlags = D3D11_BIND_RENDER_TARGET; + backBufferMultiSampledDesc.MipLevels = 1; + backBufferMultiSampledDesc.ArraySize = 1; + backBufferMultiSampledDesc.SampleDesc.Count = _multisampleAntiAliasingCount; + backBufferMultiSampledDesc.SampleDesc.Quality = 0; + winrt::check_hresult(_d3dDevice->CreateTexture2D(&backBufferMultiSampledDesc, nullptr, _d3dBackBufferMultiSampled.put())); + } + + + void BaseView::SetD2D1Target(IDXGISurface* targetSurface) + { + D2D1_BITMAP_PROPERTIES1 bitmapProperties{}; + bitmapProperties.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW; + bitmapProperties.pixelFormat = D2D1::PixelFormat(DxgiFormat, D2D1_ALPHA_MODE_PREMULTIPLIED); + bitmapProperties.dpiX = _compositionScaleX; + bitmapProperties.dpiY = _compositionScaleY; + winrt::check_hresult(_d2dContext->CreateBitmapFromDxgiSurface(targetSurface, &bitmapProperties, _d2dTargetBitmap.put())); + _d2dContext->SetDpi(bitmapProperties.dpiX, bitmapProperties.dpiY); + _d2dContext->SetTarget(_d2dTargetBitmap.get()); + } + + + void BaseView::DownsampleMultiSampleBackBufferToBackBuffer() + { + if(_multisampleAntiAliasingQuality > 0) + { + const UINT index = D3D11CalcSubresource(0, 0, 1); + _d3dContext->ResolveSubresource(_d3dBackBuffer.get(), index, _d3dBackBufferMultiSampled.get(), index, DxgiFormat); + } + } + + + void BaseView::HandleResult(HRESULT result) + { + if(result == DXGI_ERROR_DEVICE_REMOVED || result == DXGI_ERROR_DEVICE_RESET) + { + OnDeviceLost(); + } + + else + { + winrt::check_hresult(result); + } + } +} diff --git a/SwapChainPanelBugRepro/View/BaseView.h b/SwapChainPanelBugRepro/View/BaseView.h new file mode 100644 index 0000000..4fd1862 --- /dev/null +++ b/SwapChainPanelBugRepro/View/BaseView.h @@ -0,0 +1,118 @@ +#pragma once + +#include +#include +#include +#include "BaseView.g.h" +#include +#include +#include + + +namespace winrt::SwapChainPanelBugRepro::implementation +{ + struct BaseView : BaseViewT + { + protected: + BaseView(); + ~BaseView(); + + virtual void CreateDeviceIndependentResources(); + virtual void CreateDeviceResources(); + virtual void CreateSizeDependentResources(); + + virtual void OnDeviceLost(); + + virtual void OnSizeChanged(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::SizeChangedEventArgs const& e); + virtual void OnCompositionScaleChanged(winrt::Microsoft::UI::Xaml::Controls::SwapChainPanel const& sender, winrt::Windows::Foundation::IInspectable const& args); + + virtual winrt::Windows::Foundation::IAsyncAction OnLoaded(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e); + virtual winrt::Windows::Foundation::IAsyncAction OnUnloaded(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e); + + virtual winrt::Windows::Foundation::IAsyncAction AfterLoaded(); + virtual winrt::Windows::Foundation::IAsyncAction BeforeUnloaded(); + + virtual void Present(); + + static ::DirectX::XMFLOAT3 RgbFromBrush(winrt::Microsoft::UI::Xaml::Media::SolidColorBrush const& brush); + static ::DirectX::XMFLOAT4 RgbaFromBrush(winrt::Microsoft::UI::Xaml::Media::SolidColorBrush const& brush); + + winrt::com_ptr _d3dDevice; + winrt::com_ptr _d3dContext; + winrt::com_ptr _d3dRenderTargetView; + winrt::com_ptr _d3dDepthStencilView; + winrt::com_ptr _d3dBackBuffer; + winrt::com_ptr _d3dBackBufferMultiSampled; + winrt::com_ptr _dxgiFactory; + winrt::com_ptr _dxgiAdapter; + winrt::com_ptr _dxgiOutput; + winrt::com_ptr _dxgiSwapChain; + winrt::com_ptr _d2dFactory; + winrt::com_ptr _d2dDevice; + winrt::com_ptr _d2dContext; + winrt::com_ptr _d2dTargetBitmap; + + winrt::event_token _sizeChangedEventToken; + winrt::event_token _compositionScaleChangedEventToken; + winrt::event_token _loadedEventToken; + winrt::event_token _unloadedEventToken; + + concurrency::critical_section _criticalSection; + + UINT _multisampleAntiAliasingCount = 4; + UINT _multisampleAntiAliasingQuality = 0; + + // Device Independent Pixels (DIPs) per inch. A DIP is defined as 1/96 of a logical inch. + // See https://learn.microsoft.com/en-us/windows/win32/learnwin32/dpi-and-device-independent-pixels + static constexpr float DipsPerInch = 96.0f; + static constexpr DXGI_FORMAT DxgiFormat = DXGI_FORMAT_B8G8R8A8_UNORM; + static constexpr DXGI_PRESENT_PARAMETERS PresentationParameters{}; + static constexpr D2D1_FACTORY_OPTIONS FactoryOptions + { +#if defined(_DEBUG) + D2D1_DEBUG_LEVEL_INFORMATION +#endif + }; + + static constexpr UINT DeviceCreationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT +#if defined(_DEBUG) + | D3D11_CREATE_DEVICE_DEBUG +#endif + ; + + static constexpr D3D_FEATURE_LEVEL FeatureLevels[] = + { + D3D_FEATURE_LEVEL_11_1, + D3D_FEATURE_LEVEL_11_0, + D3D_FEATURE_LEVEL_10_1, + D3D_FEATURE_LEVEL_10_0, + D3D_FEATURE_LEVEL_9_3, + D3D_FEATURE_LEVEL_9_2, + D3D_FEATURE_LEVEL_9_1 + }; + + float _renderTargetHeight; + float _renderTargetWidth; + + float _compositionScaleX = 1.0f; + float _compositionScaleY = 1.0f; + + private: + void DestroyDeviceResources(); + void DestroySizeDependentResources(); + void CreateD3D11Device(); + void CreateD2D1Device(); + void CalculateRenderTargetSize(); + void ExtractMultisamplingParameters(); + void CreateOrResizeSwapChain(); + void CreateSwapChain(); + void ScaleSwapChain(); + void ObtainBackBuffer(); + void CreateRenderTargetView(ID3D11Resource* targetBuffer, const CD3D11_RENDER_TARGET_VIEW_DESC* renderTargetViewDesc); + void CreateDepthStencilView(UINT count, D3D11_DSV_DIMENSION dsvDimension); + void CreateMultiSampledBackBuffer(); + void SetD2D1Target(IDXGISurface* targetSurface); + void DownsampleMultiSampleBackBufferToBackBuffer(); + void HandleResult(HRESULT result); + }; +} diff --git a/SwapChainPanelBugRepro/View/BaseView.idl b/SwapChainPanelBugRepro/View/BaseView.idl new file mode 100644 index 0000000..fb5d11d --- /dev/null +++ b/SwapChainPanelBugRepro/View/BaseView.idl @@ -0,0 +1,6 @@ +namespace SwapChainPanelBugRepro +{ + unsealed runtimeclass BaseView : Microsoft.UI.Xaml.Controls.SwapChainPanel + { + } +} diff --git a/SwapChainPanelBugRepro/View/SquareView.cpp b/SwapChainPanelBugRepro/View/SquareView.cpp new file mode 100644 index 0000000..7193c87 --- /dev/null +++ b/SwapChainPanelBugRepro/View/SquareView.cpp @@ -0,0 +1,75 @@ +#include "pch.h" +#include "SquareView.h" +#include "SquareView.g.cpp" + + +namespace winrt::SwapChainPanelBugRepro::implementation +{ + using namespace winrt::Microsoft::UI::Dispatching; + using namespace winrt::Windows::Foundation; + + + void SquareView::CreateDeviceResources() + { + _renderer->SetContext(nullptr); + _renderer->SetDevice(nullptr); + BaseView::CreateDeviceResources(); + _renderer->SetContext(_d3dContext.get()); + _renderer->SetDevice(_d3dDevice.get()); + _renderer->CreateDeviceResources(); + } + + + void SquareView::CreateSizeDependentResources() + { + _renderer->SetRenderTargetView(nullptr); + _renderer->SetDepthStencilView(nullptr); + BaseView::CreateSizeDependentResources(); + _renderer->SetRenderTargetView(_d3dRenderTargetView.get()); + _renderer->SetDepthStencilView(_d3dDepthStencilView.get()); + _renderer->SetScreenSize(_renderTargetWidth, _renderTargetHeight); + } + + + IAsyncAction SquareView::AfterLoaded() + { + _renderer = std::make_unique<::SwapChainPanelBugRepro::SquareRenderer>(); + CreateDeviceIndependentResources(); + CreateDeviceResources(); + CreateSizeDependentResources(); + StartRenderingLoop(); + co_return; + } + + + IAsyncAction SquareView::BeforeUnloaded() + { + _isRenderLoopRunning = false; + co_await _renderLoopController.ShutdownQueueAsync(); + co_return; + } + + + void SquareView::StartRenderingLoop() + { + if(!_isRenderLoopRunning) + { + _renderLoopController = DispatcherQueueController::CreateOnDedicatedThread(); + _isRenderLoopRunning = _renderLoopController.DispatcherQueue().TryEnqueue([this]() + { + while(_isRenderLoopRunning) + { + Render(); + _dxgiOutput->WaitForVBlank(); + } + }); + } + } + + + void SquareView::Render() + { + _renderer->RenderFrame(); + Present(); + } +} diff --git a/SwapChainPanelBugRepro/View/SquareView.h b/SwapChainPanelBugRepro/View/SquareView.h new file mode 100644 index 0000000..e5559f9 --- /dev/null +++ b/SwapChainPanelBugRepro/View/SquareView.h @@ -0,0 +1,36 @@ +#pragma once + +#include "BaseView.h" +#include "SquareView.g.h" +#include "../Renderer/SquareRenderer.h" + + +namespace winrt::SwapChainPanelBugRepro::implementation +{ + struct SquareView : SquareViewT + { + private: + std::unique_ptr<::SwapChainPanelBugRepro::SquareRenderer> _renderer; + + winrt::Microsoft::UI::Dispatching::DispatcherQueueController _renderLoopController{ nullptr }; + + bool _isRenderLoopRunning = false; + + void CreateDeviceResources() override; + void CreateSizeDependentResources() override; + + winrt::Windows::Foundation::IAsyncAction AfterLoaded() override; + winrt::Windows::Foundation::IAsyncAction BeforeUnloaded() override; + + void StartRenderingLoop(); + void Render(); + }; +} + + +namespace winrt::SwapChainPanelBugRepro::factory_implementation +{ + struct SquareView : SquareViewT + { + }; +} diff --git a/SwapChainPanelBugRepro/View/SquareView.idl b/SwapChainPanelBugRepro/View/SquareView.idl new file mode 100644 index 0000000..db44653 --- /dev/null +++ b/SwapChainPanelBugRepro/View/SquareView.idl @@ -0,0 +1,11 @@ +import "BaseView.idl"; + + +namespace SwapChainPanelBugRepro +{ + [default_interface] + runtimeclass SquareView : BaseView + { + SquareView(); + } +} diff --git a/SwapChainPanelBugRepro/View/TriangleView.cpp b/SwapChainPanelBugRepro/View/TriangleView.cpp new file mode 100644 index 0000000..81d150d --- /dev/null +++ b/SwapChainPanelBugRepro/View/TriangleView.cpp @@ -0,0 +1,75 @@ +#include "pch.h" +#include "TriangleView.h" +#include "TriangleView.g.cpp" + + +namespace winrt::SwapChainPanelBugRepro::implementation +{ + using namespace winrt::Microsoft::UI::Dispatching; + using namespace winrt::Windows::Foundation; + + + void TriangleView::CreateDeviceResources() + { + _renderer->SetContext(nullptr); + _renderer->SetDevice(nullptr); + BaseView::CreateDeviceResources(); + _renderer->SetContext(_d3dContext.get()); + _renderer->SetDevice(_d3dDevice.get()); + _renderer->CreateDeviceResources(); + } + + + void TriangleView::CreateSizeDependentResources() + { + _renderer->SetRenderTargetView(nullptr); + _renderer->SetDepthStencilView(nullptr); + BaseView::CreateSizeDependentResources(); + _renderer->SetRenderTargetView(_d3dRenderTargetView.get()); + _renderer->SetDepthStencilView(_d3dDepthStencilView.get()); + _renderer->SetScreenSize(_renderTargetWidth, _renderTargetHeight); + } + + + IAsyncAction TriangleView::AfterLoaded() + { + _renderer = std::make_unique<::SwapChainPanelBugRepro::TriangleRenderer>(); + CreateDeviceIndependentResources(); + CreateDeviceResources(); + CreateSizeDependentResources(); + StartRenderingLoop(); + co_return; + } + + + IAsyncAction TriangleView::BeforeUnloaded() + { + _isRenderLoopRunning = false; + co_await _renderLoopController.ShutdownQueueAsync(); + co_return; + } + + + void TriangleView::StartRenderingLoop() + { + if(!_isRenderLoopRunning) + { + _renderLoopController = DispatcherQueueController::CreateOnDedicatedThread(); + _isRenderLoopRunning = _renderLoopController.DispatcherQueue().TryEnqueue([this]() + { + while(_isRenderLoopRunning) + { + Render(); + _dxgiOutput->WaitForVBlank(); + } + }); + } + } + + + void TriangleView::Render() + { + _renderer->RenderFrame(); + Present(); + } +} diff --git a/SwapChainPanelBugRepro/View/TriangleView.h b/SwapChainPanelBugRepro/View/TriangleView.h new file mode 100644 index 0000000..67d6d7d --- /dev/null +++ b/SwapChainPanelBugRepro/View/TriangleView.h @@ -0,0 +1,36 @@ +#pragma once + +#include "BaseView.h" +#include "TriangleView.g.h" +#include "../Renderer/TriangleRenderer.h" + + +namespace winrt::SwapChainPanelBugRepro::implementation +{ + struct TriangleView : TriangleViewT + { + private: + std::unique_ptr<::SwapChainPanelBugRepro::TriangleRenderer> _renderer; + + winrt::Microsoft::UI::Dispatching::DispatcherQueueController _renderLoopController{ nullptr }; + + bool _isRenderLoopRunning = false; + + void CreateDeviceResources() override; + void CreateSizeDependentResources() override; + + winrt::Windows::Foundation::IAsyncAction AfterLoaded() override; + winrt::Windows::Foundation::IAsyncAction BeforeUnloaded() override; + + void StartRenderingLoop(); + void Render(); + }; +} + + +namespace winrt::SwapChainPanelBugRepro::factory_implementation +{ + struct TriangleView : TriangleViewT + { + }; +} diff --git a/SwapChainPanelBugRepro/View/TriangleView.idl b/SwapChainPanelBugRepro/View/TriangleView.idl new file mode 100644 index 0000000..9568501 --- /dev/null +++ b/SwapChainPanelBugRepro/View/TriangleView.idl @@ -0,0 +1,11 @@ +import "BaseView.idl"; + + +namespace SwapChainPanelBugRepro +{ + [default_interface] + runtimeclass TriangleView : BaseView + { + TriangleView(); + } +} diff --git a/SwapChainPanelBugRepro/app.manifest b/SwapChainPanelBugRepro/app.manifest new file mode 100644 index 0000000..bb2dd27 --- /dev/null +++ b/SwapChainPanelBugRepro/app.manifest @@ -0,0 +1,18 @@ + + + + + + + + + + + + + diff --git a/SwapChainPanelBugRepro/packages.config b/SwapChainPanelBugRepro/packages.config new file mode 100644 index 0000000..3453e87 --- /dev/null +++ b/SwapChainPanelBugRepro/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SwapChainPanelBugRepro/pch.cpp b/SwapChainPanelBugRepro/pch.cpp new file mode 100644 index 0000000..bcb5590 --- /dev/null +++ b/SwapChainPanelBugRepro/pch.cpp @@ -0,0 +1 @@ +#include "pch.h" diff --git a/SwapChainPanelBugRepro/pch.h b/SwapChainPanelBugRepro/pch.h new file mode 100644 index 0000000..5089cae --- /dev/null +++ b/SwapChainPanelBugRepro/pch.h @@ -0,0 +1,22 @@ +#pragma once + +// Suppresses the "min" and "max" macros which are defined in +// windef.h. Instead std::min and std::max which are defined +// in shall be used. +#define NOMINMAX + +#include +#include +#include + +// Undefine GetCurrentTime macro to prevent +// conflict with Storyboard::GetCurrentTime +#undef GetCurrentTime + +#include +#include +#include +#include +#include +#include +#include