Skip to content

[SPIRV] The result of isShader changes in the middle of compilation #171898

@s-perron

Description

@s-perron

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.

// 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions