@@ -1195,6 +1195,25 @@ void addVarDecorations(
1195
1195
}
1196
1196
}
1197
1197
1198
+ // / If `decl` has a modifier that should turn into a
1199
+ // / rate qualifier, then apply it to `inst`.
1200
+ void maybeSetRate (
1201
+ IRGenContext* context,
1202
+ IRInst* inst,
1203
+ Decl* decl)
1204
+ {
1205
+ auto builder = context->irBuilder ;
1206
+
1207
+ if (decl->HasModifier <HLSLGroupSharedModifier>())
1208
+ {
1209
+ inst->setFullType (builder->getRateQualifiedType (
1210
+ builder->getGroupSharedRate (),
1211
+ inst->getFullType ()));
1212
+ }
1213
+ }
1214
+
1215
+
1216
+
1198
1217
LoweredValInfo createVar (
1199
1218
IRGenContext* context,
1200
1219
IRType* type,
@@ -1205,6 +1224,8 @@ LoweredValInfo createVar(
1205
1224
1206
1225
if (decl)
1207
1226
{
1227
+ maybeSetRate (context, irAlloc, decl);
1228
+
1208
1229
addVarDecorations (context, irAlloc, decl);
1209
1230
1210
1231
builder->addHighLevelDeclDecoration (irAlloc, decl);
@@ -3192,22 +3213,6 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
3192
3213
{
3193
3214
IRType* varType = lowerType (context, decl->getType ());
3194
3215
3195
- if (decl->HasModifier <HLSLGroupSharedModifier>())
3196
- {
3197
- // TODO: here we are applying the rate qualifier to
3198
- // the *data type* of the variable, when we really
3199
- // should be applying the rate to the variable itself.
3200
- //
3201
- // This ends up making a distinction between
3202
- // `Ptr<@GroupShared X>` and `@GroupShared Ptr<X>`.
3203
- // The latter is more technically correct, but the
3204
- // code generation logic currently looks for the former.
3205
-
3206
- varType = getBuilder ()->getRateQualifiedType (
3207
- getBuilder ()->getGroupSharedRate (),
3208
- varType);
3209
- }
3210
-
3211
3216
auto builder = getBuilder ();
3212
3217
3213
3218
IRGlobalValueWithCode* irGlobal = nullptr ;
@@ -3226,6 +3231,8 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
3226
3231
}
3227
3232
irGlobal->mangledName = context->getSession ()->getNameObj (getMangledName (decl));
3228
3233
3234
+ maybeSetRate (context, irGlobal, decl);
3235
+
3229
3236
if (decl)
3230
3237
{
3231
3238
builder->addHighLevelDeclDecoration (irGlobal, decl);
@@ -3300,36 +3307,6 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
3300
3307
// initializer expression a bit carefully (it should only
3301
3308
// be initialized on-demand at its first use).
3302
3309
3303
- // Some qualifiers on a variable will change how we allocate it,
3304
- // so we need to reflect that somehow. The first example
3305
- // we run into is the `groupshared` qualifier, which marks
3306
- // a variable in a compute shader as having per-group allocation
3307
- // rather than the traditional per-thread (or rather per-thread
3308
- // per-activation-record) allocation.
3309
- //
3310
- // Options include:
3311
- //
3312
- // - Use a distinct allocation opration, so that the type
3313
- // of the variable address/value is unchanged.
3314
- //
3315
- // - Add a notion of an "address space" to pointer types,
3316
- // so that we can allocate things in distinct spaces.
3317
- //
3318
- // - Add a notion of a "rate" so that we can declare a
3319
- // variable with a distinct rate.
3320
- //
3321
- // For now we might do the expedient thing and handle this
3322
- // via a notion of an "address space."
3323
-
3324
- if (decl->HasModifier <HLSLGroupSharedModifier>())
3325
- {
3326
- // TODO: This logic is duplicated with the global-variable
3327
- // case. We should seek to share it.
3328
- varType = getBuilder ()->getRateQualifiedType (
3329
- getBuilder ()->getGroupSharedRate (),
3330
- varType);
3331
- }
3332
-
3333
3310
LoweredValInfo varVal = createVar (context, varType, decl);
3334
3311
3335
3312
if ( auto initExpr = decl->initExpr )
0 commit comments