walbourn / directx-vs-templates Goto Github PK
View Code? Open in Web Editor NEWDirect3D Visual Studio Templates
Home Page: https://walbourn.github.io/direct3d-game-visual-studio-templates-redux/
License: MIT License
Direct3D Visual Studio Templates
Home Page: https://walbourn.github.io/direct3d-game-visual-studio-templates-redux/
License: MIT License
Followed the doc and attempted to create a D3D11Texture2D
in the Win32 Game template, but it just fail:
0x00007FF8CBDC478C (KernelBase.dll) (Direct3D Win32 Game1.exe 中)处有未经处理的异常: 0x0000087A (参数: 0x0000000000000001, 0x000000751DAFC4B0, 0x000000751DAFE280)。
at m_deviceResources->GetD3DDevice()->CreateTexture2D(&desc, NULL, &pTexture)
creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
then receive E_INVALIDARG One or more arguments are invalid.
hr errorRepro: https://github.com/ryancheung/DirectX-Win32-Repro
OS: Windows 10/11
GPU0: Intel UHD Graphics 630
GPU1: NVIDIA GeForce GTX 1060
I'm stucking on getting started with DirectXTK for hours as a newbie, please help!
EDIT: It works in Release build
Visual Studio 2017 reaches it's mainstream end-of-life on April 2022.
As of the Windows 10 April 2018 Update (Version 1803) and the Windows 10 SDK (17134), you can use a new IDXGIFactory6
object with EnumAdapterByGpuPreference
to prefer discrete to integrated parts (or vise versa). See MSDN
The PC and UWP DeviceResources for DX11 & DX12 should be updated to use this when available.
I've been using .props files for project configuration these days, I typically start from a purely empty project and then apply a props file that sets language, rules, application type, include folders, library dependencies, and so forth. I mostly derived these settings by extracting them from these templates, but I find it is a much better way to manage project properties without having to go through the process of exporting a template file for the project. Then again, my engine does all of the window instantiation in the library, so the main() in my application is literally just loading the engine core class and running a basic while loop, not even MSG pump. Anyway, props files are really handy, would be a nice-to-have for Visual Studio users
ClayEngineClientCore.props.txt
Thanks for consideration!
This seems to be causing the d3d11* templates to be excluded from list on the "New Project" dialog in vs2019 community.
would it be possible to add boiler plate code for dpi changes in both win32 and uwp templates ?
After adding Microsoft.Windows.CppWinRT package 2.0.190425.5 to the UWP template project I get the following compile errors:
1>d:\source\gameproj\gameproj\generated files\winrt\base.h(8945): error C3246: 'winrt::impl::heap_implements<D>': cannot inherit from 'ViewProvider' as it has been declared as 'final'
1> with
1> [
1> D=ViewProvider
1> ] (compiling source file Source\Main.cpp)
1>d:\source\gameproj\gameproj\source\main.cpp(20): note: see declaration of 'ViewProvider' (compiling source file Source\Main.cpp)
1>d:\source\gameproj\gameproj\generated files\winrt\base.h(2005): note: see reference to class template instantiation 'winrt::impl::heap_implements<D>' being compiled
1> with
1> [
1> D=ViewProvider
1> ] (compiling source file Source\Main.cpp)
1>d:\source\gameproj\gameproj\source\main.cpp(377): note: see reference to function template instantiation 'auto winrt::make<ViewProvider,>(void)' being compiled
1>d:\source\gameproj\gameproj\source\main.cpp(395): error C2259: 'ViewProviderFactory': cannot instantiate abstract class
1>d:\source\gameproj\gameproj\source\main.cpp(395): note: due to following members:
1>d:\source\gameproj\gameproj\source\main.cpp(395): note: 'void winrt::implements<ViewProviderFactory,winrt::Windows::ApplicationModel::Core::IFrameworkViewSource>::use_make_function_to_create_this_object(void)': is abstract
1>d:\source\gameproj\gameproj\generated files\winrt\base.h(9050): note: see declaration of 'winrt::implements<ViewProviderFactory,winrt::Windows::ApplicationModel::Core::IFrameworkViewSource>::use_make_function_to_create_this_object'
Prior to adding the package (and I assume using winrt headers in the Win 10 SDK) I did not get this error, however VS Intellisense didn't like the call to Run()
:
CoreApplication::Run(viewProviderFactory);
One of the errors can be solved by removing final
from ViewProvider
however I'm too much of an UWP/WinRT n00b to figure out the other error.
Visual Studio version 15.9.11
Windows 10 SDK 10.0.17763.0
Project target platform 10.0.17763.0
Project min platform 10.0.15063.0
Originally reported here
How to repro:
Result:
Deployment and launch tests using WACK 10.0
FAILED
App prelaunch
Error Found: The app prelaunch validation detected the following errors:
The app failed prelaunch test - c06fbd2c-afed-49e9-ac00-37a11a7ce589_1.0.1.0_x86__m9k0q4hvj1fvp.
Impact if not fixed: The app will take a longer time to launch, even when prelaunch is enabled.
How to fix: In the OnLaunched method implementation of the app, ensure you handle the LaunchActivatedEventArgs.PreLaunch option to be prelaunch event aware.
Moved from DirectXTK
I am unable to use the templates from the Getting Started Guide VS 2013 / VS 2015 / VS 2017 VSIX
When attempting to create a new project using the templates I get an error dialog:
Error: this template attempted to load component assembly
'Microsoft.VisualStudio.WinRT.TemplateWizards, Version=14.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. For more
information on this problem and how to enable this template,
please see documentation on Customizing Project Templates.
I assume it's simply just looking for a certain version of the component assembly, I think Version 15 would be for 2017. I'm not sure how to get in there and actually edit the template by hand myself.
Hi, thanks for the templates, very useful
Just as a suggestion for your DirectX12 UWP WinRT template, maybe include the GraphicsMemory allocation in the Game.Cpp file. If you do all the https://github.com/microsoft/DirectXTK12/wiki/The-basic-game-loop stuff will just work. Otherwise, you get a std::logic_error exception...
Jon
Happens with Direct3D Win32 Game and Direct3D12 Win32 Game. Not sure what is causing the beep.
Rather than prompt for which Windows SDK to use, the VS 2019 Win32 projects should just default to 'latest installed'
I have noticed that when running a graphics debug session (Debug > Graphics > Start Graphics Debugging) that the following code (in DeviceResources::GetHardwareAdapter()
) path results in adapter
being unset and hence crashing:
for (UINT adapterIndex = 0;
DXGI_ERROR_NOT_FOUND != factory6->EnumAdapterByGpuPreference(adapterIndex,
DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE,
IID_PPV_ARGS(adapter.ReleaseAndGetAddressOf()));
adapterIndex++)
{
DXGI_ADAPTER_DESC1 desc;
adapter->GetDesc1(&desc);
If I test adapter
for null
and break
, I end up with the WARP driver, however the graphics debug session does work.
I can only assume that EnumAdapterByGpuPreference()
is returning something other than DXGI_ERROR_NOT_FOUND
when a capture device is being used.
By restructuring the code so that the EnumAdapters1()
iteration is called if adapter
is unset, instead of being in the else
clause, I get a non-WARP device and debugging works.
I am using the latest VS templates (as of yesterday) under Windows 10 17763 using the VS2019 (16.1.0) x64. I have also see this happen under VS2017 (latest) on a different machine.
Here is my final code (with local changes), however you can almost certainly do a better job:
void DeviceResources::GetHardwareAdapter(IDXGIAdapter1** ppAdapter)
{
*ppAdapter = nullptr;
ComPtr<IDXGIAdapter1> adapter;
#if defined(__dxgi1_6_h__) && defined(NTDDI_WIN10_RS4)
ComPtr<IDXGIFactory6> factory6;
HRESULT hr = m_dxgiFactory.As(&factory6);
if (SUCCEEDED(hr))
{
for (UINT adapterIndex = 0;
factory6->EnumAdapterByGpuPreference(adapterIndex,
DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE,
IID_PPV_ARGS(adapter.ReleaseAndGetAddressOf())) != DXGI_ERROR_NOT_FOUND;
adapterIndex++)
{
if (!adapter)
{
break;
}
DXGI_ADAPTER_DESC1 desc;
adapter->GetDesc1(&desc);
if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE)
{
// Don't select the Basic Render Driver adapter.
continue;
}
break;
}
}
#endif
if (!adapter)
{
for (UINT adapterIndex = 0;
DXGI_ERROR_NOT_FOUND != m_dxgiFactory->EnumAdapters1(adapterIndex, adapter.ReleaseAndGetAddressOf());
adapterIndex++)
{
DXGI_ADAPTER_DESC1 desc;
adapter->GetDesc1(&desc);
if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE)
{
// Don't select the Basic Render Driver adapter.
continue;
}
break;
}
}
*ppAdapter = adapter.Detach();
}
The latest version of C++/WinRT should have the Nuget package integrated. Is that something we can help with?
I moved DeviceResources to a master library so that I could reference it from lots of test projects. It builds and runs and I have never had any issues until I tried running Graphics Debugging. I cannot figure this issue out either. Can you help lead me in the direction of why this Graphics Debugging doesn't work from a reference library?
There are a few places in the templates where I use this guard.
#if defined(NTDDI_WIN10_RS2) && (NTDDI_VERSION >= NTDDI_WIN10_RS2)
This is specifically to support the Windows 10 SDK (14393) which was the last one supported for VS 2015. Since I no longer support VS 2015, I can remove these guards to simplify the code.
directx-vs-templates/d3d11game_win32/Game.cpp
Line 223 in 781af56
On and around the above line you're resetting some values on the D3D11DeviceContext object, I've separated the resources and pipelines into two separate classes and a do a full pointer unique_ptr::reset on the device and recreate it. Do you think it would be necessary still to execute these OMSetRenderTargets() and Flush() commands to clear any caches not direct associated with the device and devicecontext objects, or would recreating the objects be sufficent to give us a clean memory surface to rebuild our graphical content on?
I saw your link in the C++WinRT repo. This is exactly what I need. I was attempting to convert the sample from the default Direct3D 11 template to C++WinRT and I faced some issues. I couldn't get the ppl code to compile. Then I tried to use coroutines instead but I couldn't even get co_await to be compiled even though I added /await. Even the IDE (VS2015 Update 3) wouldn't colorize the keywords. This left me to scratch my head.
Could you please add some sample code to the sample to demonstrate asynchronous loading of resources e.g. shaders with ppl tasks and coroutines.
Direct2d/DirectWrite/Windows Imaging Component in gaming is also very common, provide one template would be handy.
Where are the template projects that combine XAML with Direct3D? I can't find any, and VS documentation for them is really poor.
In the DeviceResources.cpp implementation, I have the following guard:
#if defined(__dxgi1_6_h__) && defined(NTDDI_WIN10_RS4)
This was to allow the code to build with the Windows 10 SDK (14393, 15063, and 16299).
Add support for the template VSIX to install on VS 2022.
See Microsoft Docs for details.
Currently I download directx-vs-template for installation directly, but how can I build custom vsix based on code I forked from here?
Is there any scripts or .csproj file?
The comment next to the CreateWindowExW call says to use WS_POPUP for fullscreen, but the WM_SYSKEYDOWN handler seems to set GWL_STYLE to 0 instead. Is this a mistake?
Is it possible to add project templates for WindowsAppSDK? I think this helps developers get started with it.
Hello,
While studying the DeviceResources header file present on the d3d11game_uwp_cppwinrt_dr project, I noticed that the private member has:
Microsoft::WRL::ComPtr<ID3D11Device3> m_d3dDevice;
But the accessor has:
ID3D11Device2* GetD3DDevice() const { return m_d3dDevice.Get(); }
Was that on purpose? If so, why?
Thank you.
Current system configuration:
Windows 10 17763.134
Visual Studio 2017 15.9.2
Direct3DUWPGame VSIX version 6.3
Graphics Intel HD 4600 and NVIDIA GeForce GT 755M (optimus technology) with latest drivers from Intel and NVIDIA.
Note: I have been observing this error since very early days of Creator's update. I thought by this time this issue will be resolved but it hasn't.
I compile and run the default generated code in 32-bit debug build and resize the window continuously until it crashes and observe the following messages in output window
DXGI ERROR: IDXGISwapChain::GetContainingOutput: The swapchain's adapter does not control the output on which the swapchain's window resides. [ MISCELLANEOUS ERROR #80: ]
... repeated message above too many times
DXGI ERROR: IDXGISwapChain::ResizeBuffers: Swapchain cannot be resized unless all outstanding buffer references have been released. [ MISCELLANEOUS ERROR #19: ]
Exception thrown at 0x76BAAB32 in Direct3D UWP Game1.exe: Microsoft C++ exception: DX::com_exception at memory location 0x0314CE90.
Exception thrown at 0x76BAAB32 in Direct3D UWP Game1.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
Exception thrown at 0x76BAAB32 (KernelBase.dll) in Direct3D UWP Game1.exe: WinRT originate error - 0x80004005 : 'Failure with HRESULT of 887A0001'.
I see the DXGI Error message with Direct3D 11 but for some reason it does not seem to crash. Direct3D12 code crashes easily.
In the Win32 template when resizing the window by dragging the corner the white window background can be seen in the lower left corner. This is most clearly visible when quickly making the window smaller.
The sample is using DXGI_SCALING_STRETCH, but I don't think the issue is D3D, but rather that window messages that repaint the NC area lags behind.
I've dropped maintenance of the VS 2013 version of the VSIX
. The last version for VS 2013 was the July 2017 release.
When attempting to generate DirectX 11 Win32 projects (with or without DeviceResources) I get an error dialog about the template attempting to use Microsoft.VisualStudio.WinRT.Templates 14.0.0.0 and it not existing. The remapping does exist in devenv.exe.config however the .dll does not exist in PrivateAssemblies and I cannot see what component is missing.
It's not clear to me why a Win32 template would reference WinRT at all.
The Win32 templates should be updated to support the Agility SDK. Specifically in Main.cpp
:
extern "C"
{
// Indicates to hybrid graphics systems to prefer the discrete part by default
__declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
#ifdef USING_D3D12_AGILITY_SDK
// Used to enable the "Agility SDK" components
__declspec(dllexport) extern const UINT D3D12SDKVersion = D3D12_SDK_VERSION;
__declspec(dllexport) extern const char* D3D12SDKPath = u8".\\D3D12\\";
#endif
}
That said, currently the Agility SDK doesn't have any preprocessor defines I can use here, so it still requires manual work to add it.
I would like to request new templates relying solely on DX12 compute without any windowing or event handling. Computing the simplest SAXPY example. Seomthing akin to my compute samples using OpenCL or SYCL. (Apologies for slightly non-uniform project layout, otherwise they resemble each other for the most part.
I would very much like to add DX12 compute samples as well, just the shear amount flaming hoops to jump through is daunting. Ultimately it were nice if there were samples for the following:
Although this is not the best place to mention, it were nice if modern Windows & DirectX samples would open toward CMake as a build system. C++/WinRT, XAML and MSIX are awesome techs, but I've not touched MSBuild in 5+ years, fyling exclusively CMake (occasionally Meson), moreover primarily VS Code for the past 2 years.
I'd like to take DX12 for a ride outside its comfort zone where MSBuild isn't going to help me much.
The existing templates for Win32 use SetWindowsLongPtr
after creating the window and showing it.
The official DirectX-Graphics-Samples projects use WM_CREATE
and the lpParam
on CreateWindow instead.
HWND hwnd = CreateWindowExW(0, ..., g_game.get());
switch (message)
{
case WM_CREATE:
if (lParam)
{
auto pCreateStruct = reinterpret_cast<LPCREATESTRUCTW>(lParam);
SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pCreateStruct->lpCreateParams));
}
return 0;
Note this works fine, but needs one tweak to DeviceResources:
bool DeviceResources::WindowSizeChanged(int width, int height)
{
if (!m_window)
return false;
...
In DeviceResources::CreateDeviceResources you check a number of feature flags related to tearing and HDR. I have a question about the order of these checks - Is it possible for a device to fail to cast to factory4, but succeed in casting to factory5? That is, I'm putting these three checks into a function and I'm wondering if it's even necessary to check factory5 and factory5/allowTearing if you fail to cast to factory4. I've already put a return into the check for c_EnableHDR, if you FAIL on the cast to factory5 here, there's no reason to try to cast to factory5 for the c_AllowTearing check.
Using the absolute latest version of Visual Studio 2019, these templates still throw an error when you try to create a project with them. I checked the known issue, it says that it was fixed, but I still get this:
Has been happening for a while, just assumed it would be fixed, but I've updated VS 2019 at least four or five times since I've had this problem, and my entire system has been rebuilt at least once as well.
With the VS 2017 (15.5 update), the various built-in templates now use /permissive-
by default via the new <ConformanceMode>
VC++ project element.
The UWP templates do not use
/permissive-
as two-phase name lookup doesn't support C++/CX (/ZW). Technically they could usepermissive-
but have/Zc:twoPhase-
in the<AddititionalOptions>
section.
The Win32 templates and the C++/WinRT UWP templates should use <ConformanceMode>
for VS 2017, but I want to wait until the 15.5 update is more widely deployed.
When debugging, placing a breakpoint on the Run() method, caused the application shut-down after few (3-5) seconds, like if it went in time-out.
Placing the CoreWindow::GetForCurrentThread().Activate() call in the Run() method (like at the beginning of it) seems to solve the problem.
According to MSDN the Visual Studio debugger should prevent this, however that's related to C++/CX environment only.
I am not sure if this is related to the C++/WINRT or it is an intended behaviour.
I am posting this here because I started playing with C++/WinRT looking at the d3d12 game UWP C++/WinRT template.
When creating a new monogame UWP in VS 2017 you now get a new error.
Package Installation Error
Could not add all required packages to the project. The following packages failed to install from 'C:\Program Files (x86)\Microsoft SDKs\NuGetPackages':
After clicking the only option "OK" You still have the errors as before but build always fails
Hi - I don't get the cornflower background when the screen is resized - to blanks out to white during resizing.
Is there any particular reason why the window long pointer is set here instead of somewhere else? I realize the hwnd goes out of scope a few lines later, but I'm just wondering if perhaps I can just retain the handle and pass it into the constructor for the game class, and have it initialize the DX11 resources there instead? That is, is it strictly required that the window have a pointer to the game object before you can then have the DX11 resources target the window for rendering, or can I initialize the DX11 resources on the window and then after the game object and dx11 resources are initialized, set the window long pointer on the window kernel object?
For a while I've been maintaining two different variants of every template: One that creates the device 'inline' (CreateDevice
and CreateResources
), and the other with the DeviceResources
abstraction (CreateDeviceDependentResources
, CreateWindowSizeDependentResources
).
Generally the non-DR variants are only really useful when doing extremely simple samples, primarily focused on the creation of the device & swapchain itself. Otherwise, you pretty much always want to use the DR variant. Plus the DeviceResources
version is a lot more functional.
As such, I think I'm going to retire the non-DR versions primarily to reduce the work to maintain these things... (6 templates instead of 12)
Suggestion: Using iomanip you can do some of the HR code printing in the following manner, specifically setfill setw and hex can do same work as fprints
#include <iostream>
#include <iomanip>
#include <thread>
inline void PrintHR(std::wstring message, HRESULT hr)
{
std::wcout << L"[" << std::setfill(L'0') << std::setw(8) << std::this_thread::get_id()
<< L"] " << message << L" HRESULT: 0x" << std::setfill(L'0') << std::setw(8) << std::hex << hr << std::endl;
}
These templates have CMakeLists.txt and CMakeSettings.json files, but the source in the 'raw' template still has substitution parameters in it for VS. Need a script to take one of these four templates and a project name, then set up a new set of files.
Warnings when building with Intel C++ compiler:
DX12 versions of DR:
DeviceResources.h(75): message #82: storage class is not first const static size_t MAX_BACK_BUFFER_COUNT = 3;
All versions:
StepTimer.h(125): message #2557: comparison between signed and unsigned operands
if (abs(static_cast<int64_t>(timeDelta - m_targetElapsedTicks)) < TicksPerSecond / 4000)
detected during instantiation of "void DX::StepTimer::Tick(const TUpdate &) [with TUpdate=lambda []()->void]" at line 75 of "SimpleTrianglePC12.cpp"
It will be great if we could have common plumbing and app can be developed for DX11 with easy path to DX12. Right now the API models seem to be very different.
Similarly, a common 'static lib' approach for both win32 and uwp.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.