Skip to content

Add support for SPV_KHR_constant_data and SPV_KHR_abort#4196

Closed
Samsung-CraigG wants to merge 10 commits intoKhronosGroup:mainfrom
Samsung-CraigG:cgraham/khr_shader_abort
Closed

Add support for SPV_KHR_constant_data and SPV_KHR_abort#4196
Samsung-CraigG wants to merge 10 commits intoKhronosGroup:mainfrom
Samsung-CraigG:cgraham/khr_shader_abort

Conversation

@Samsung-CraigG
Copy link
Copy Markdown
Contributor

Used by VK_KHR_shader_abort / VK_KHR_shader_constant_data

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 23, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ Samsung-CraigG
✅ lordalcol
❌ Zhou, Shaochi(AMD)


Zhou, Shaochi(AMD) seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@Samsung-CraigG
Copy link
Copy Markdown
Contributor Author

Mirrors gitlab PR#141.

@Samsung-CraigG Samsung-CraigG changed the title Add support for SPV_KHR_constant_data and SPV_KHR_abortHide local variables Add support for SPV_KHR_constant_data and SPV_KHR_abort Mar 23, 2026
@arcady-lunarg
Copy link
Copy Markdown
Contributor

@Samsung-CraigG You're going to need to fix the CI failure before this can be merged.

@Samsung-CraigG
Copy link
Copy Markdown
Contributor Author

@arcady-lunarg done (sorry, hadn't noticed as Shaochi @ AMD wrote the code & I'd not tried a GCC build)

@jeremy-lunarg
Copy link
Copy Markdown
Contributor

@Samsung-CraigG Can you ask the other authors to sign the CLA.

@ShchchowAMD
Copy link
Copy Markdown
Contributor

Hi, this is Shaochi, and this is my account for open-source commit submission.
Looks like the above account can't be used to contribute outside so I can't sign CLA directly here.
Should I re-create a new PR from this account or other steps I should follow to let this work now?

@Samsung-CraigG
Copy link
Copy Markdown
Contributor Author

I've just been discussing this with Ralph (as there seems to be a process issue here). If @ShchchowAMD has time to squish & re-submit this PR that'd be great for this instance.

(we can discuss internally at Khronos ways to avoid this next time around)

@arcady-lunarg
Copy link
Copy Markdown
Contributor

I don't think you need to create a new PR but you do need to create a new branch with commits that have the appropriate author emails. The CLA bot ultimately goes off the emails in the author field in the commits.

- with no instructions following in the same way as OpReturn.
@ShchchowAMD
Copy link
Copy Markdown
Contributor

Sorry for the late response. I'll create commits with this account this weekend for abortKHR.

@Samsung-CraigG
Copy link
Copy Markdown
Contributor Author

Thanks @ShchchowAMD - appreciated.

@ShchchowAMD
Copy link
Copy Markdown
Contributor

Hi, I've created a new commit for submission under branch:
https://github.com/ShchchowAMD/glslang/tree/abortKHR

Please feel free to tell me what extra works needed if anything works not as expected, sorry for blocking PR submission.
Thanks!

@dnovillo dnovillo self-requested a review April 6, 2026 14:52
Comment thread SPIRV/GlslangToSpv.cpp
const char* formatSpecifiers[formatSpecifiersSize] = {"%d", "%i", "%f", "%u"};
// 1. Split original message string with format specifiers.
const glslang::TString* msg = !isEmptyMsg ? glslangOperands[0]->getAsConstantUnion()->getConstArray()[0].getSConst()
: new glslang::TString("\0");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

msg will own the heap allocation if the message is empty. This will likely create leaks. Could you either allocate on the stack or restructure the branches so no heap allocation is needed?

Comment thread SPIRV/GlslangToSpv.cpp
constStrInfo(glslang::TString str, int spec) : string(str), specifierIndex(spec){};
} strInfo;

std::vector<strInfo> splitedStr, tempSplitedStr;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

grammar nit: s/splitedStr/splitStr/ and s/tempSplitedStr/tempSplitStr/

Comment thread SPIRV/GlslangToSpv.cpp
pos = str.find(formatSpecifiers[i]);
}
if (str.size() > 0 || isEmptyMsg)
tempSplitedStr.push_back(strInfo(str, specifierIndex));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: Check for !str.empty() instead of str.size() > 0.

Note that isEmptyMsg is set when glslangOperands is empty (no arguments). If the caller passes an empty string (e.g., abortEXT("", v);) then msg will have size 0. This will make the loop not push anything into tempSplitedStr. When it goes on to pop from structMemberOffsets, it will leave the vector empty. So when the code tries to access structMemberOffsets.back() the vector is empty (undefined behaviour).

This needs a test for an empty string and special handling for empty string literals ("").

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yea. I'm now treating it as an empty string.

"#define GL_EXT_shared_memory_block 1\n"
"#define GL_EXT_shader_integer_mix 1\n"
"#define GL_EXT_spec_constant_composites 1\n"
"#define E_GL_EXT_abort 1\n"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

s/E_GL_EXT_abort/GL_EXT_abort/ since E_GL_EXT_abort is the C++ constant in Versions.h. The GLSL injection should use the GLSL extension name.

Comment thread SPIRV/SpvBuilder.cpp Outdated
Comment thread SPIRV/SpvBuilder.cpp
Instruction* op = new Instruction(getUniqueId(), typeId, opCode);
op->reserveOperands(operands.size());
for (auto id : operands)
op->addStringOperand(id);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does the encoding use LiteralString or LiteralBytes?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment thread SPIRV/GlslangToSpv.cpp
builder.addExtension(spv::E_SPV_KHR_constant_data);
builder.addExtension(spv::E_SPV_KHR_abort);

typedef struct constStrInfo {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit. No typedef necessary. This can use strInfo or constStrInfo. No need to have both.

Comment thread SPIRV/GlslangToSpv.cpp
// 1. Split original message string with format specifiers.
const glslang::TString* msg = !isEmptyMsg ? glslangOperands[0]->getAsConstantUnion()->getConstArray()[0].getSConst()
: new glslang::TString("\0");
splitedStr.push_back(strInfo(*const_cast<glslang::TString*>(msg), -1));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

No need to const_cast here. The constructor takes str by value. This can be strInfo(*msg, -1).

Comment thread SPIRV/GlslangToSpv.cpp

void TGlslangToSpvTraverser::createAbortEXT(const glslang::TIntermSequence glslangOperands)
{
bool isEmptyMsg = glslangOperands.size() == 0;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

s/.size() == 0/.empty()/

Comment thread SPIRV/GlslangToSpv.cpp
return builder.createCompositeConstruct(resultTypeId, constituents);
}

void TGlslangToSpvTraverser::createAbortEXT(const glslang::TIntermSequence glslangOperands)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this will copy the vector on every call. Pass it by const reference, please.

Use builder.makeStatementTerminator() instead.
@Samsung-CraigG
Copy link
Copy Markdown
Contributor Author

Samsung-CraigG commented Apr 13, 2026 via email

@ShchchowAMD
Copy link
Copy Markdown
Contributor

Hi Chow – couple of commits I made that will need applying to your new branch: Build fix for GCC: 2140ff5#diff-4c2971e76ad3cea3aee5bc8b1496244b0f2e891a4fabed3582990129c938925c (otherwise it’ll fail CI) OpAbortKHR should be the last instruction in a block: 71eef95 Remove Builder::makeAbortKHR(): d219610 To enforce the spec rule that states “This instruction must be the last instruction in a block.”. Regards, Craig. From: Chow @.> Sent: 05 April 2026 11:27 To: KhronosGroup/glslang @.> Cc: Craig Graham @.>; Mention @.> Subject: Re: [KhronosGroup/glslang] Add support for SPV_KHR_constant_data and SPV_KHR_abort (PR #4196) ShchchowAMD left a comment (KhronosGroup/glslang#4196) https://protect2.fireeye.com/v1/url?k=8d453406-ecce2123-8d44bf49-74fe485cbff6-325074c4d3a45289&q=1&e=55899f22-338a-4cf3-b55b-8a7432e521c2&u=https%3A%2F%2Fgithub.com%2FKhronosGroup%2Fglslang%2Fpull%2F4196%23issuecomment-4188667060 Hi, I've created a new commit for submission under branch: https://github.com/ShchchowAMD/glslang/tree/abortKHR https://protect2.fireeye.com/v1/url?k=113480d0-70bf95f5-11350b9f-74fe485cbff6-00461b2f5176b82c&q=1&e=55899f22-338a-4cf3-b55b-8a7432e521c2&u=https%3A%2F%2Fgithub.com%2FShchchowAMD%2Fglslang%2Ftree%2FabortKHR Please feel free to tell me what extra works needed if anything works not as expected, sorry for blocking PR submission. Thanks! — Reply to this email directly, https://protect2.fireeye.com/v1/url?k=4af55c31-2b7e4914-4af4d77e-74fe485cbff6-e536a3a1cc376389&q=1&e=55899f22-338a-4cf3-b55b-8a7432e521c2&u=https%3A%2F%2Fgithub.com%2FKhronosGroup%2Fglslang%2Fpull%2F4196%23issuecomment-4188667060 view it on GitHub, or https://protect2.fireeye.com/v1/url?k=3e283c4b-5fa3296e-3e29b704-74fe485cbff6-a8ab8bc6bc2b8bbc&q=1&e=55899f22-338a-4cf3-b55b-8a7432e521c2&u=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FB7GMNEH57BOONUQ7NVUZAXD4UIYF5AVCNFSM6AAAAACW4I6IKGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DCOBYGY3DOMBWGA unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

Hi, Sure.

Sorry for the late reply.
Please feel free to push commits into that branch or let me know if I need to do this work. I'll make commits to fix codes according to above reviews this week.

@Samsung-CraigG
Copy link
Copy Markdown
Contributor Author

Closed as superseded by #4222

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.

7 participants