Code Monkey home page Code Monkey logo

directx-vs-templates's People

Contributors

crisspl avatar walbourn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

directx-vs-templates's Issues

CreatureTexture2D failed in DirectX Win32 Game template.

Followed the doc and attempted to create a D3D11Texture2D in the Win32 Game template, but it just fail:

  1. It just crash with 0x00007FF8CBDC478C (KernelBase.dll) (Direct3D Win32 Game1.exe 中)处有未经处理的异常: 0x0000087A (参数: 0x0000000000000001, 0x000000751DAFC4B0, 0x000000751DAFE280)。 at m_deviceResources->GetD3DDevice()->CreateTexture2D(&desc, NULL, &pTexture)
  2. Comment out creationFlags |= D3D11_CREATE_DEVICE_DEBUG; then receive E_INVALIDARG One or more arguments are invalid. hr error

Repro: 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

Use DXGI_GPU_PREFERENCE when available

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.

Include Props File?

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

image

Thanks for consideration!

DpiChanged capability

would it be possible to add boiler plate code for dpi changes in both win32 and uwp templates ?

C++/WinRT Main.cpp is no longer compatible with latest base.h

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

Direct3D 11 UWP Template fails WACK Prelaunch tests

How to repro:

  1. Create a new VS2015 project using the Direct3D UWP Game template
  2. Create a store package and run the WACK Prelaunch test

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.

VS 2017 templates fail unless VS 2015 also installed

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.

DirectX 11 UWP DeviceResources::GetHardwareAdapter selects an invalid adapter when using Debug > Graphics

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();
}

Remove support for Windows 10 SDK (14393) or earlier

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.

Question on Context Reset

m_d3dContext->OMSetRenderTargets(static_cast<UINT>(std::size(nullViews)), nullViews, nullptr);

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?

Add a sample with assets loading

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.

Missing templates with XAML

Where are the template projects that combine XAML with Direct3D? I can't find any, and VS documentation for them is really poor.

Remove support for Windows SDK (16299) or earlier

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).

WS_POPUP recommended but not used

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?

Mismatch for the D3D11Device between the private member and the Accessor?

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.

Direct3D12 UWP Game DR (C++/WinRT) template generated code crashes

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

log.txt

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.

Flicker when resizing window

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.

Cannot create DirectX 11 Win32 projects on VS2019 16.2.0

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.

Add opt-in support for the DirectX Agilty SDK

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.

Template request: DX12 compute console application

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.

SAXPY via OpenCL

kép

SAXPY via SYCL

kép

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:

  • Hello SAXPY DX12 WinAPI Win32 console
  • Hello SAXPY DX12 C++/WinRT Win32 console
  • Hello SAXPY DX12 C++/WinRT UWP console

Note

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.

Move setting game object for user pointer into WM_CREATE

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;
...

DeviceResources Option flags check ordering

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.

Still Doesn't Load

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:
image
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.

Use of permissive- in templates

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 use permissive- 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.

C++/WINRT: beware where calling CoreWindow::GetForCurrentThread().Activate();

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.

Package installation error

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':

Microsoft.NETCore.UniversalWindowsPlatform.5.1.0 : Unable to find version '5.1.0' of package 'Microsoft.NETCore.UniversalWindowsPlatform'.

After clicking the only option "OK" You still have the errors as before but build always fails

Initialization Ordering

SetWindowLongPtr(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(g_game.get()) );

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?

Retire the 'non-DR' variant of the template

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)

Rendering at the beginning does not show correctly.

I create a DirectX11 App (Windows Universal) project using Visual Studio 15.9.2 and hit a breakpoint at the end of function Render in file "SampleFpsTextRenderer.cpp", then I run that project, but the text does not show up correctly at the bottom right corner in the first time.
qq 20181128140326

OS: 17134.407

STL Print HR Codes

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;
}

Create a script to set up new cmake-based projects

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.

Compilation issues with Intel C++ 18 compiler

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"

Common template framework for Directx 11 and 12

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.