Skip to content

Commit c38910b

Browse files
authored
[mlir][spirv] Add support for RelaxedPrecision in function arguments (#138685)
With the current implementation only one attribute is attached to the argument and the deserializer fails if more decorations are specified, however I believe that the spec does not prohibit having both `Aliased`/`Restrict` and `RelaxedPrecision`. I am not sure how to attach multiple attributes to a single argument with the current code and at the same time I do not have a use case for it, so I think the patch in the current state is a good starting point and can be extended in the future.
1 parent d2c5fbe commit c38910b

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,21 @@ LogicalResult spirv::Deserializer::setFunctionArgAttrs(
448448
foundDecorationAttr = spirv::DecorationAttr::get(context, decoration);
449449
break;
450450
}
451+
452+
if (decAttr.getName() == getSymbolDecoration(stringifyDecoration(
453+
spirv::Decoration::RelaxedPrecision))) {
454+
// TODO: Current implementation supports only one decoration per function
455+
// parameter so RelaxedPrecision cannot be applied at the same time as,
456+
// for example, Aliased/Restrict/etc. This should be relaxed to allow any
457+
// combination of decoration allowed by the spec to be supported.
458+
if (foundDecorationAttr)
459+
return emitError(unknownLoc, "already found a decoration for function "
460+
"argument with result <id> ")
461+
<< argID;
462+
463+
foundDecorationAttr = spirv::DecorationAttr::get(
464+
context, spirv::Decoration::RelaxedPrecision);
465+
}
451466
}
452467

453468
if (!foundDecorationAttr)

mlir/test/Target/SPIRV/decorations.mlir

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,12 @@ spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [CacheControlsINTEL], [SP
151151
spirv.Return
152152
}
153153
}
154+
155+
// -----
156+
157+
spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
158+
// CHECK: spirv.func @relaxed_precision_arg({{%.*}}: !spirv.ptr<f32, Function> {spirv.decoration = #spirv.decoration<RelaxedPrecision>}) "None" attributes {relaxed_precision} {
159+
spirv.func @relaxed_precision_arg(%arg0: !spirv.ptr<f32, Function> {spirv.decoration = #spirv.decoration<RelaxedPrecision>}) -> () "None" attributes {relaxed_precision} {
160+
spirv.Return
161+
}
162+
}

0 commit comments

Comments
 (0)