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

dxcopt: Support full container and restore extra data to module #4845

Merged
merged 30 commits into from
Dec 13, 2022

Conversation

tex3d
Copy link
Contributor

@tex3d tex3d commented Dec 3, 2022

This modifies IDxcOptimizer::RunOptimizier to accept full DxilContainer input. When full container input is used, this restores some data that is stripped from the module and placed in various other container parts.

Data restored:

  • Subobjects from RDAT
  • RootSignature from RTS0
  • ViewID and I/O dependency data from PSV0
  • Resource names and types/annotations from STAT

Serialization of these to metadata in module bitcode output still requires hlsl-dxilemit step.

Fixes #4874

This modifies IDxcOptimizer::RunOptimizier to accept full DxilContainer input.
When full container input is used, this also restores subobjects from RDAT or root signature data from RST0 to the DxilModule state.
Serialization of these to metadata in module bitcode output still requires hlsl-dxilemit step.
@AppVeyorBot
Copy link

@AppVeyorBot
Copy link

@AppVeyorBot
Copy link

@AppVeyorBot
Copy link

@AppVeyorBot
Copy link

@AppVeyorBot
Copy link

@AppVeyorBot
Copy link

@jeffnn jeffnn marked this pull request as ready for review December 7, 2022 19:15
Copy link
Collaborator

@jeffnn jeffnn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed that this fixes the PIX scenario.

@AppVeyorBot
Copy link

lib/HLSL/DxcOptimizer.cpp Outdated Show resolved Hide resolved
VERIFY_SUCCEEDED(m_dllSupport.CreateInstance(CLSID_DxcContainerReflection, &pReflection));
VERIFY_SUCCEEDED(pReflection->Load(pOptimizedContainer));
UINT32 dxilIndex;
VERIFY_SUCCEEDED(pReflection->FindFirstPartKind(hlsl::DFCC_DXIL, &dxilIndex));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this uses container reflection here, then the lower-level DxilContainer code below? Either one works, but it doesn't seem necessary to use a different method when getting a different part.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just because I had lifted the lower-level code from elsewhere prior to deleting the code in the optimizer that serialized the dxil to container.

reinterpret_cast<const char *>(pOptimizedContainer->GetBufferPointer());
unsigned blobSize = pOptimizedContainer->GetBufferSize();
const hlsl::DxilContainerHeader *pContainerHeader =
hlsl::IsDxilContainerLike(pBlobContent, blobSize);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note: After IsDxilContainerLike, you can also use IsValidDxilContainer to make sure the container is well-formed (though it's unlikely to be badly formed on output from AssembleToContainer).

Small refactor to separate code that translates between ViewID data format serialized in DxilModule and the PSV0 data format.
Added the equivalent functions to go back to DxilModule serialized version from PSV0 used in IDxcOptimizer.
hlsl::DXIL::SubobjectKind subobjectKind = subObject.getKind();
switch (subobjectKind) {
case hlsl::DXIL::SubobjectKind::StateObjectConfig:
VERIFY_IS_TRUE(0 == strcmp(subObject.getName(), "so_StateObjectConfig"));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to use VERIFY_ARE_EQUAL_STR, since that will be more informative if it fails.

@AppVeyorBot
Copy link

// ComputeViewIdState. It could be moved into some common location if this
// ViewID serialization/deserialization code were moved out of here.
static unsigned RoundUpToUINT(unsigned x) { return (x + 31) / 32; }
static unsigned ComputeSeriaizedViewIDStateSizeInUInts(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going to make ComputeViewIdState call this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, this could live in a common location, but I haven't yet figured out where that should be. Hence the comment on the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do plan to clean this up along with the format inconsistency between module and PSV0 in the near future, so I'd rather clean this up at that point.

VERIFY_ARE_EQUAL(originalRes->GetResDimName(), optimizedRes->GetResDimName());
VERIFY_ARE_EQUAL(originalRes->GetResIDPrefix(), optimizedRes->GetResIDPrefix());
VERIFY_ARE_EQUAL_STR(originalRes->GetResBindPrefix(), optimizedRes->GetResBindPrefix());
VERIFY_ARE_EQUAL_STR(originalRes->GetResIDPrefix(), optimizedRes->GetResIDPrefix());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are just the prefix character decoded from the Class, so comparing GetResBindPrefix and GetResIDPrefix are also unnecessary. Basically, if Class was wrong, there would be something very fundamentally wrong with which list the resource is in for the DxilModule. By which I mean we would have much bigger problems, and expect a whole lot of things to break.

@AppVeyorBot
Copy link

@AppVeyorBot
Copy link

@AppVeyorBot
Copy link

@AppVeyorBot
Copy link

@AppVeyorBot
Copy link

@AppVeyorBot
Copy link

@AppVeyorBot
Copy link

@AppVeyorBot
Copy link

@AppVeyorBot
Copy link

Copy link
Contributor

@adam-yang adam-yang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@tex3d tex3d changed the title dxcopt: Support full container and restore subobjects/root sig to module dxcopt: Support full container and restore extra data to module Dec 13, 2022
@tex3d tex3d enabled auto-merge (squash) December 13, 2022 01:23
@tex3d tex3d merged commit 2c3d965 into microsoft:main Dec 13, 2022
@tex3d tex3d deleted the dxcopt-from-container branch December 13, 2022 20:35
jeffnn added a commit that referenced this pull request Dec 16, 2022
PIX is unique in that it needs to deserialize, modify and then reserialize root sigs. The focus of this checkin is adding such modifications to PixPassHelpers.cpp. (This closes a gap in PIX support: PIX can now support shaders that use dxil-defined and attribute-style root signatures.)

But this required some work outside of the purely PIX-focused areas. Deserialized root sigs are described by a C-like structure with embedded arrays that are new/delete-ed by routines in DxilRootSignature.cpp. Since modifying these structs requires more new/delete calls, I chose to add a new entry point in DxilRootSignature.cpp to do the bare minimum that PIX needs: extend root params by one descriptor. This approach keeps all those raw new/deletes in one file.

I found a leak in DxilRootSignatureSerialzier.cpp, which I fixed. There appear to be no unit tests that exercise this path. I welcome feedback on adding one.

There were other leaks in class CVersionedRootSignatureDeserializer, but this class is unused so I deleted it.

Oh, and there are bazillions of commits because I was cherry-picking from a recent change (#4845) as it eveolved, since I needed that change and this to test PIX.
hekota pushed a commit to hekota/DirectXShaderCompiler that referenced this pull request Dec 16, 2022
…soft#4876)

PIX is unique in that it needs to deserialize, modify and then reserialize root sigs. The focus of this checkin is adding such modifications to PixPassHelpers.cpp. (This closes a gap in PIX support: PIX can now support shaders that use dxil-defined and attribute-style root signatures.)

But this required some work outside of the purely PIX-focused areas. Deserialized root sigs are described by a C-like structure with embedded arrays that are new/delete-ed by routines in DxilRootSignature.cpp. Since modifying these structs requires more new/delete calls, I chose to add a new entry point in DxilRootSignature.cpp to do the bare minimum that PIX needs: extend root params by one descriptor. This approach keeps all those raw new/deletes in one file.

I found a leak in DxilRootSignatureSerialzier.cpp, which I fixed. There appear to be no unit tests that exercise this path. I welcome feedback on adding one.

There were other leaks in class CVersionedRootSignatureDeserializer, but this class is unused so I deleted it.

Oh, and there are bazillions of commits because I was cherry-picking from a recent change (microsoft#4845) as it eveolved, since I needed that change and this to test PIX.

(cherry picked from commit 20bb3d0)
hekota pushed a commit to hekota/DirectXShaderCompiler that referenced this pull request Dec 16, 2022
…osoft#4845)

This modifies IDxcOptimizer::RunOptimizier to accept full DxilContainer input. When full container input is used, this restores some data that is stripped from the module and placed in various other container parts.

Data restored:
  - Subobjects from RDAT
  - RootSignature from RTS0
  - ViewID and I/O dependency data from PSV0
  - Resource names and types/annotations from STAT

Serialization of these to metadata in module bitcode output still requires hlsl-dxilemit step.

(cherry picked from commit 2c3d965)
hekota added a commit that referenced this pull request Dec 16, 2022
Cherry-pick of PIX and HLK changes for the 2212 release

Changes for PIX:
20bb3d0 PIX: Modify root sigs in place (plus fix root sig memory leak) (PIX: Modify root sigs in place (plus fix root sig memory leak) #4876)
2c3d965 dxcopt: Support full container and restore extra data to module (dxcopt: Support full container and restore extra data to module #4845)
21cf36a Fix hitgroup metadata argument order

HLK Test Updates:
ee0994e add barycentrics ordering check onto existing barycentrics test (add barycentrics ordering check onto existing barycentrics test #4635)
6acd11b ConvertFloat32ToFloat16: Use DirectXMath conversion functions (ConvertFloat32ToFloat16: Use DirectXMath conversion functions #4855)
e7aac8e Include TestConfig.h only if DEFAULT_TEST_DIR is not defined (Include TestConfig.h only if DEFAULT_TEST_DIR is not already defined #4884)
5decc4a Do not include TestConfig.h for all HLK build (Do not include TestConfig.h for all HLK build #4887)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extra container data lost when running IDxcOptimizer on bitcode from final DxilContainer
4 participants