llvm / wg-hlsl

HLSL Working Group documentation and task tracking.
Other
11 stars 12 forks source link

[workstream] DXIL Shader Flags #57

Open damyanp opened 2 months ago

damyanp commented 2 months ago

DXIL output contains various flags that tell the runtime about what optional features the shader might be using - for example, wave operations, doubles, 64-bit integers.

All shader flags specified in DXC output along with conditions that set each of them is catalogued here.

Support for appropriately setting the same set of flags in the clang-based HLSL Shader compiler needs to be implemented by enhancing the existing ShaderFlagsAnalysis pass in DXILShaderFlags.cpp. The existing Module pass needs to be extended to walk all constituent functions to collect shader flags for the candidate function. Results of the analysis pass is a map of shader functions to corresponding shader flags mask.

NOTE: Analysis to set the following Shader Flags is not done as it appears that they are not being set in DXC sources based on module content. Listing them for the record and potential reclassification as needed.

Milestones

Compile particle_life.hlsl (#20)

Compile all DML shaders, and they pass the validator (#11)

damyanp commented 2 months ago

@bharadwajy - first step of this is to do some investigation and figure out what's involved in the work so we can take something to refinement.

bharadwajy commented 2 months ago

Adding some notes:

  1. A library DXIL shader can specify more than one entry points - see here. As a result, ShaderFlagsAnalysis pass needs to collect ShaderFlags information for each of the entry functions, if the shader profile specified for compilation is lib_*. Currently, the ShaderFlagsAnalysis pass collects ShaderFlags value by inspecting all the instructions of all functions of module. Collecting ShaderFlags per entry will allow for correct specification of the value EntryShaderFlags in the tag-value pair of {ShaderFlagsTag, EntryShaderFlags} in the metadata for entries - both for lib_* and non-lib_* profiles.
  2. collectShaderFlgs() would serve as a guide to analyze entry functions to create the ShaderFlags mask. A potential mechanism to encode static shader flags information for some of the DXIL Ops is to encode them as attributes in DXIL.td and query for the values. This will still require walking all the instructions of a function for shader flags that require compile-time instruction information such as operand type.
  3. Shader Flags based on DXIL/SM versions, and compiler options - such as disabling optimizations etc., are also to be collected at compile-time.
damyanp commented 2 months ago

Discussed in refinement today: this needs to be broken down further and the acceptance criteria defined. Note that it is reasonable to create subtasks to cover the work required to find all the shader flags / write a proposal etc.