Skip to content

Conversation

@V-FEXrt
Copy link
Collaborator

@V-FEXrt V-FEXrt commented Nov 7, 2025

Fixes #7846

Implments:

  • the HLSL type __builtin_la_MatrixRef
  • the HLSL intrinsic __builtin_la_CreateMatrix()
  • the DXIL type %dx.types.MatrixRef
  • the DXIL op @dx.op.createMatrix(i32 312)

Note: The DXIL op codes will change in response to microsoft/hlsl-specs#698

@@ -0,0 +1,8 @@
// RUN: %dxc -T cs_6_9 -E main %s -verify
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Pretty sure I also want a .ll test but I don't know the magic incantation to generate the IR upto but right before the dxilgen pass

Copy link
Collaborator

@pow2clk pow2clk Nov 24, 2025

Choose a reason for hiding this comment

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

./utils/hct/ExtractIRForPassTest.py -p dxilgen -o output.ll input.hlsl -- -T cs_6_9 -E main

Copy link
Member

@damyanp damyanp left a comment

Choose a reason for hiding this comment

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

I've read through this and didn't spot any obvious typos.

Do we need to apply the same "experimental DXIL" stuff to this that we're talking about for other SM 6.10 features?

Comment on lines +140 to 144
LICOMPTYPE_VK_BUFFER_POINTER = 55,
LICOMPTYPE_COUNT = 56
#else
LICOMPTYPE_COUNT = 54
LICOMPTYPE_COUNT = 55
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Does it matter that these values have changed?

I've no reason to think it does, just checking.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm assuming no but maybe someone else can weigh in. The ifdef basically forces them to change though since the last number is only incremented for SPIRV. Beyond that this seems to be an internal enum so changing it shouldn't be observable to end users.

Copy link
Contributor

Choose a reason for hiding this comment

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

These are mostly internal details, but the built-in intrinsic extension mechanism relies on this header (and this enum) as well. That's currently only used by Xbox backend, and wouldn't be impacted by these changes unless updated to depend on them, and even then, using the latest header would keep it in sync.

Ideally, I think we should get rid of the ifdef here (so LICOMPTYPE_VK_BUFFER_POINTER is always part of the enumeration), and update the corresponding table g_LegalIntrinsicCompTypes in SemaHLSL.cpp. But that should be a separate change.

Copy link
Collaborator

Choose a reason for hiding this comment

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

A lot of the ifdef SPIRV conditionals were removed in similar areas. This one was missed possibly as an oversight.

@V-FEXrt
Copy link
Collaborator Author

V-FEXrt commented Nov 7, 2025

Do we need to apply the same "experimental DXIL" stuff to this that we're talking about for other SM 6.10 features?

Yep

@pow2clk
Copy link
Collaborator

pow2clk commented Nov 24, 2025

In a discussion about a month ago, we agreed that createMatrix as written wasn't useful because it has no way of uniquely identifying the matrix in question, so any and all createMatrix calls will get merged as duplicates. From this discussion, we agreed to remove it, which would make the builtin unnecessary.

In my own further investigation that I've been trying to get the opportunity to discuss for weeks, I've determined that we may need a createMatrix that is generated for local or global allocas, but not parameters since, without global variables, we have to use the alloca as the unique identifier and the fact that they are opaque handles makes it difficult to cleanly merge duplicate parameter allocas through inlining and subsequent passes.

In any event, a creatematrix call that only takes the opcode isn't of much use.

@pow2clk
Copy link
Collaborator

pow2clk commented Dec 4, 2025

Per our discussion, you can disregard my last comment, however I just remembered that when I proposed a builtin for creatematrix and annotatematrix, @llvm-beanz rejected it on account of it would allow the header implementation or other method using builtins to generate invalid dxil. I found that a compelling argument. I don't know if he changed his mind since.

Similar create dxil ops are generated as part of clang CodeGen. As an example I wouldn't strongly recommend following exactly, but as the broad idea, see how resource handle creation is generated:

Value *Handle = CreateHandleFromResPtr(arg, HLM, HandleTy, Builder);

The way nodehandle creation is generated is the way I would/have approached it though it will be through local/global variables instead of entry function params:

TranslateInputNodeRecordArgToHandle(HLM, NodeInputRecordParams);
TranslateNodeOutputParamToHandle(HLM, NodeOutputParams);

@llvm-beanz
Copy link
Collaborator

Per our discussion, you can disregard my last comment, however I just remembered that when I proposed a builtin for creatematrix and annotatematrix, @llvm-beanz rejected it on account of it would allow the header implementation or other method using builtins to generate invalid dxil. I found that a compelling argument. I don't know if he changed his mind since.

I think a builtin for createMatrix is fine, and probably necessary. The exact shape it takes might need to shift because we may want to have a single builtin function that generates both a create and an annotate, but what is in this PR is a fine first step.

The annotate builtin is a bit more complicated but it isn't the "creating invalid dxil" that concerns me as much as I'm unsure that the annotate builtin could be used to create valid DXIL. I'm not strongly opposed to either of these additions a lot of it just depends on the implementation details as we progress.

@pow2clk
Copy link
Collaborator

pow2clk commented Dec 4, 2025

The annotate builtin is a bit more complicated but it isn't the "creating invalid dxil" that concerns me as much as I'm unsure that the annotate builtin could be used to create valid DXIL. I'm not strongly opposed to either of these additions a lot of it just depends on the implementation details as we progress.

Are you saying that create will have a builtin, but annotate will not?

As a sanity check, where do you see the create builtin being called in the linalg.h header?

@V-FEXrt
Copy link
Collaborator Author

V-FEXrt commented Dec 5, 2025

Are you saying that create will have a builtin, but annotate will not?

Currently the plan is that they both have builtins, and the annotate is just overemitted and then cleaned up/deduped in a late pass

As a sanity check, where do you see the create builtin being called in the linalg.h header?

Create and initial annotate are in the constructor of the Matrix type

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.

Enable creation of a LinAlg Matrix (type, intrinsic, dxil op)

5 participants