Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added implementation for ID3D12FunctionReflection1::GetDesc1 #6827

Open
wants to merge 66 commits into
base: main
Choose a base branch
from

Conversation

Nielsbishere
Copy link
Contributor

Relates to microsoft/DirectX-Headers#135.

I have tested this version in my own project and it seems to work. Only thing is that this requires the DirectX-Headers dep to be updated to ensure D3D12_FUNCTION_DESC1 and co can be found.

@Nielsbishere Nielsbishere requested a review from a team as a code owner July 25, 2024 22:36
Copy link
Contributor

github-actions bot commented Jul 25, 2024

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff 9018970f265e4152a4313044afc06818aa635a2a e24d9888d62efe13028436da81b15100a32b9c4b -- include/dxc/Support/D3DReflection.h include/dxc/Support/Unicode.h include/dxc/Test/D3DReflectionDumper.h include/dxc/Test/D3DReflectionStrings.h include/dxc/WinAdapter.h lib/DxcSupport/Unicode.cpp lib/DxcSupport/dxcapi.use.cpp lib/DxilContainer/D3DReflectionDumper.cpp lib/DxilContainer/D3DReflectionStrings.cpp lib/HLSL/DxilContainerReflection.cpp projects/dxilconv/tools/dxbc2dxil/dxbc2dxil.cpp tools/clang/include/clang/AST/Attr.h tools/clang/tools/dxa/dxa.cpp tools/clang/tools/dxcvalidator/dxcvalidator.cpp tools/clang/tools/dxr/dxr.cpp tools/clang/unittests/HLSLExec/ExecutionTest.cpp tools/clang/unittests/HLSLTestLib/FileCheckerTest.cpp tools/dxexp/dxexp.cpp
View the diff from clang-format here.
diff --git a/lib/HLSL/DxilContainerReflection.cpp b/lib/HLSL/DxilContainerReflection.cpp
index d0573d829..08f150990 100644
--- a/lib/HLSL/DxilContainerReflection.cpp
+++ b/lib/HLSL/DxilContainerReflection.cpp
@@ -2876,7 +2876,7 @@ public:
   // Use D3D_RETURN_PARAMETER_INDEX to get description of the return value.
   STDMETHOD_(ID3D12FunctionParameterReflection *, GetFunctionParameter)
   (INT ParameterIndex) { return &g_InvalidFunctionParameter; }
-  
+
   STDMETHOD_(UINT64, GetRequiresFlags)() { return m_FeatureFlags; }
 };
 
  • Check this box to apply formatting changes to this branch.

@Nielsbishere Nielsbishere changed the title Added implementation for ID3D12FunctionReflection::GetDesc1 Added implementation for ID3D12FunctionReflection1::GetDesc1 Jul 27, 2024
@damyanp
Copy link
Member

damyanp commented Jul 31, 2024

Hi - thank you for all your effort here!

I just want to set appropriate expectations - this is a pretty large change adding a lot of new API surface area that we'll need to consider, taking into account future evolution of the language and compiler. As you may know we're hard at work adding HLSL support to clang, and so we need to consider the implications of a change that essentially exposes some amount of implementation details that may not be stable in the long term. Also, as we're focusing on clang, this means we have limited bandwidth for reviews of this nature, especially as we're in the middle of summer vacation season. So, be warned, it may take a while for us to find time to look at this properly.

In the meantime, I suggest you have a look at CONTRIBUTING.md to make sure that you have all your ducks in a row ready for a successful review. For example, I think some tests may be required.

Thanks again!

  • Damyan.

@Nielsbishere
Copy link
Contributor Author

Sounds reasonable, though I'm not sure if you're referring to unit tests or that the tests are failing on this PR.
Mainly the payloadSize/intersectionSize and some workgraph information is going to be useful for me. In my current parsers (also in production at work) I need to do custom work to parse struct sizes and other information that could hopefully be exposed even with a clang supported version of DXC. My goal there is to move as much as possible to a standardized DXC to avoid manual parser errors and missing functionality from my side. It is working in my PR, but it's tricky since this is dependent on the DirectX-Headers change. I updated the dependency, but still need to upstream some of the changes I had to make it build properly. If this PR is ever merged, it needs to change the external dependency's URL back from Oxsomi/DirectX-Headers to Microsoft/DirectX-Headers, since I have no other way to make the tests pass until that is merged.

@damyanp
Copy link
Member

damyanp commented Jul 31, 2024

...I'm not sure if you're referring to unit tests...

I'm referring to unit tests with the code. From CONTRIBUTING.md:

All changes that make functional or behavioral changes to the compiler whether by fixing bugs or adding features must include additional testing in the implementing pull request.

…not really possible to change things in DirectX-Headers without a Windows SDK update... Removed stupid hacks in dxexp.cpp, which were there because d3d12.h comes from the windows SDK. Now that DirectX-Headers is required, d3d12.h comes from the DirectX-Headers, meaning that the structs & enums that were hardcoded are now not needed anymore. It can now happily use the same headers without relying on specific windows SDKs :)
@Nielsbishere
Copy link
Contributor Author

Will take a look at Wednesday. Unexpectedly failing on remote. Also adding implementation for the reflection writer to know about these structs and output it as disassembly, along with a few unit tests.

…e. Also don't like an include named winadapter.h in a file named WinAdapter.h
…rt. Added CLSID_D3D12SDKConfiguration for older Windows sdks
…on info (where it makes sense). Only unit tests that provide unique scenarios have been touched. Fixed some misformatting in D3DReflectionDumper. Apparently m_pProps can be NULL, so made it S_OK instead of E_FAIL. Fixed problem with GetInputNode/GetOutputNode where it returned a string pointer of a C++ struct which implictly copied due to not being const&.
… else. Changed it to use ShaderReflection1 and LibraryReflection1
… in checks, same for ShaderReflection1. Also fixed the RDAT3 in wavesize-compute-node-rdat.hlsl
@Nielsbishere Nielsbishere changed the title Draft: Added implementation for ID3D12FunctionReflection1::GetDesc1 Added implementation for ID3D12FunctionReflection1::GetDesc1 Aug 24, 2024
@Nielsbishere
Copy link
Contributor Author

This should now be ready for review. Unless support in the disassembler is required, though I'm not sure how useful it would be since dxa and the unit testing tool both provide this functionality through D3DReflectionDumper.

@Nielsbishere
Copy link
Contributor Author

Added an important function to ID3D12FunctionReflection1; which is GetRequiresFlags such as in ID3D12ShaderReflection. Without this, it is impossible to find out what features are being used by a lib file (I thought the desc Flags was used for this, but nope).

This is especially important now that some GPUs don't always support the base featureset, so I use the following to check feature support of the underlying GPUs:

		D3D_SHADER_REQUIRES_RAYTRACING_TIER_1_1,
		D3D_SHADER_REQUIRES_NATIVE_16BIT_OPS,
		D3D_SHADER_REQUIRES_INT64_OPS,
		D3D_SHADER_REQUIRES_VIEW_ID,
		D3D_SHADER_REQUIRES_DOUBLES,
		D3D_SHADER_REQUIRES_11_1_DOUBLE_EXTENSIONS,
		D3D_SHADER_REQUIRES_ATOMIC_INT64_ON_TYPED_RESOURCE,
		D3D_SHADER_REQUIRES_ATOMIC_INT64_ON_GROUP_SHARED,
		D3D_SHADER_REQUIRES_DERIVATIVES_IN_MESH_AND_AMPLIFICATION_SHADERS,
		D3D_SHADER_REQUIRES_WRITEABLE_MSAA_TEXTURES,
		D3D_SHADER_REQUIRES_WAVE_OPS

I use this reflection to know whether a shader is really using a feature. It's possible someone enables I64 to include something that requires it but never actually uses I64 in the final shader. This is then used to retroactively disable that feature to ensure we don't go checking features that aren't really relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New
Development

Successfully merging this pull request may close these issues.

2 participants