-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Description
In #129689, a new function SPIRVSubtarget::isShader was added. It is suppose to tell us of the module is a shader module so that the spir-v can be generated accordingly. The problem is that sometime, the compiler cannot know if the module is a shader by looking at the triple alone, so code was added to change the environment in the subtarget when lowering a function with the "hlsl.shader" attribute.
llvm-project/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
Lines 256 to 264 in 854ef8d
| // We will now change the Env based on the attribute, so we need to strip | |
| // `const` out of the ref to STI. | |
| SPIRVSubtarget *NonConstSTI = const_cast<SPIRVSubtarget *>(&STI); | |
| auto attribute = F.getFnAttribute("hlsl.shader"); | |
| if (!attribute.isValid()) { | |
| NonConstSTI->setEnv(SPIRVSubtarget::Kernel); | |
| return SPIRV::ExecutionModel::Kernel; | |
| } | |
| NonConstSTI->setEnv(SPIRVSubtarget::Shader); |
This means that if isShader is called before the entry point is processed, it will return false, and code that is not valid for a shader may be generated. This value needs to be set at the start of the compilation, and should not change.