Skip to content

microsoft/compiler: Support shader models up to 6.7

Jesse Natalie requested to merge jenatali/mesa:shader-model-upgrade into main

Generally speaking, the new shader models only add new functionality and don't change the overall shape of the IR. There's one exception though, with shader model 6.6, which completely changed how resource handles are created. Before, they looked like:

  %5 = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 1, i32 0, i32 6, i1 false)  ; CreateHandle(resourceClass,rangeId,index,nonUniformIndex)
  %6 = call %dx.types.ResRet.f32 @dx.op.textureLoad.f32(i32 66, %dx.types.Handle %5, i32 0, i32 0, i32 0, i32 undef, i32 undef, i32 undef, i32 undef)  ; TextureLoad(srv,mipLevelOrSampleCount,coord0,coord1,coord2,offset0,offset1,offset2)

After, they look like:

  %5 = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 217, %dx.types.ResBind { i32 5, i32 104, i32 1, i8 1 }, i32 6, i1 false)  ; CreateHandleFromBinding(bind,index,nonUniformIndex)
  %6 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %5, %dx.types.ResourceProperties { i32 4099, i32 777 })  ; AnnotateHandle(res,props)  resource: RWTexture2DMS<3xF32>
  %7 = call %dx.types.ResRet.f32 @dx.op.textureLoad.f32(i32 66, %dx.types.Handle %6, i32 0, i32 0, i32 0, i32 undef, i32 undef, i32 undef, i32 undef)  ; TextureLoad(srv,mipLevelOrSampleCount,coord0,coord1,coord2,offset0,offset1,offset2)

Essentially, the createHandle call takes (resource class, range ID), as a pair are enough to look up the other 3 binding parameters (lower bound, upper bound, space). The new createHandleFromBinding replaces the range ID with the other 3 binding parameters inline, combined with the resource class into the new ResBind struct type. This also happens to be the first time that the DXIL emitter actually needs to create a const of a struct type. Then, the annotateHandle call takes an input handle and produces an output handle. They point to the same resource, just with annotations inserted, which the driver previously would've had to look up from the global DXIL metadata - so we look up from the same metadata to produce the annotation.

The whole point of all of that is to be able to do away with descriptor tables and use a bindless approach, where resources are described inline at the call site, instead of globally declared. These use a createHandleFromHeap method which we can't really use yet.

The only other interesting thing to note here is that shader model 6.7 adds new overloads for sample and friends with int return types. These were flat out invalid before, but they can work now. No real changes are needed to take advantage of that besides just annotating shader model 6.7 in the metadata.

Edited by Jesse Natalie

Merge request reports