@@ -229,10 +229,18 @@ GLSLSystemValueInfo* getGLSLSystemValueInfo(
229
229
230
230
auto semanticName = semanticNameSpelling.toLower ();
231
231
232
+ // HLSL semantic types can be found here
233
+ // https://docs.microsoft.com/en-us/windows/desktop/direct3dhlsl/dx-graphics-hlsl-semantics
234
+
235
+ auto builder = context->getBuilder ();
232
236
IRType* requiredType = nullptr ;
233
237
234
238
if (semanticName == " sv_position" )
235
239
{
240
+ // float4 in hlsl & glsl
241
+ // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/gl_FragCoord.xhtml
242
+ // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/gl_Position.xhtml
243
+
236
244
// This semantic can either work like `gl_FragCoord`
237
245
// when it is used as a fragment shader input, or
238
246
// like `gl_Position` when used in other stages.
@@ -271,10 +279,19 @@ GLSLSystemValueInfo* getGLSLSystemValueInfo(
271
279
else if (semanticName == " sv_clipdistance" )
272
280
{
273
281
// TODO: type conversion is required here.
282
+
283
+ // float in hlsl & glsl.
284
+ // "Clip distance data. SV_ClipDistance values are each assumed to be a float32 signed distance to a plane."
285
+ // In glsl clipping value meaning is probably different
286
+ // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/gl_ClipDistance.xhtml
287
+
274
288
name = " gl_ClipDistance" ;
275
289
}
276
290
else if (semanticName == " sv_culldistance" )
277
291
{
292
+ // float in hlsl & glsl.
293
+ // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/gl_CullDistance.xhtml
294
+
278
295
context->requireGLSLExtension (" ARB_cull_distance" );
279
296
280
297
// TODO: type conversion is required here.
@@ -285,80 +302,121 @@ GLSLSystemValueInfo* getGLSLSystemValueInfo(
285
302
// TODO: deal with `gl_SampleMaskIn` when used as an input.
286
303
287
304
// TODO: type conversion is required here.
305
+
306
+ // uint in hlsl, int in glsl
307
+ // https://www.opengl.org/sdk/docs/manglsl/docbook4/xhtml/gl_SampleMask.xml
308
+
309
+ requiredType = builder->getBasicType (BaseType::Int);
310
+
288
311
name = " gl_SampleMask" ;
289
312
}
290
313
else if (semanticName == " sv_depth" )
291
314
{
315
+ // Float in hlsl & glsl
316
+ // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/gl_FragDepth.xhtml
292
317
name = " gl_FragDepth" ;
293
318
}
294
319
else if (semanticName == " sv_depthgreaterequal" )
295
320
{
296
321
// TODO: layout(depth_greater) out float gl_FragDepth;
322
+
323
+ // Type is 'unknown' in hlsl
297
324
name = " gl_FragDepth" ;
298
325
}
299
326
else if (semanticName == " sv_depthlessequal" )
300
327
{
301
328
// TODO: layout(depth_greater) out float gl_FragDepth;
329
+
330
+ // 'unknown' in hlsl, float in glsl
302
331
name = " gl_FragDepth" ;
303
332
}
304
333
else if (semanticName == " sv_dispatchthreadid" )
305
334
{
335
+ // uint3 in hlsl, uvec3 in glsl
336
+ // https://www.opengl.org/sdk/docs/manglsl/docbook4/xhtml/gl_GlobalInvocationID.xml
306
337
name = " gl_GlobalInvocationID" ;
307
338
308
- auto builder = context->getBuilder ();
309
339
requiredType = builder->getVectorType (builder->getBasicType (BaseType::UInt), builder->getIntValue (builder->getIntType (), 3 ));
310
340
}
311
341
else if (semanticName == " sv_domainlocation" )
312
342
{
343
+ // TODO: Not 100% confident that say float2 will convert into float3 glsl?
344
+ // float2|3 in hlsl, vec3 in glsl
345
+ // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/gl_TessCoord.xhtml
346
+
347
+ requiredType = builder->getVectorType (builder->getBasicType (BaseType::Float), builder->getIntValue (builder->getIntType (), 3 ));
348
+
313
349
name = " gl_TessCoord" ;
314
350
}
315
351
else if (semanticName == " sv_groupid" )
316
352
{
353
+ // uint3 in hlsl, uvec3 in glsl
354
+ // https://www.opengl.org/sdk/docs/manglsl/docbook4/xhtml/gl_WorkGroupID.xml
317
355
name = " gl_WorkGroupID" ;
318
356
319
- auto builder = context->getBuilder ();
320
357
requiredType = builder->getVectorType (builder->getBasicType (BaseType::UInt), builder->getIntValue (builder->getIntType (), 3 ));
321
358
}
322
359
else if (semanticName == " sv_groupindex" )
323
360
{
361
+ // uint in hlsl & in glsl
324
362
name = " gl_LocalInvocationIndex" ;
325
363
}
326
364
else if (semanticName == " sv_groupthreadid" )
327
365
{
366
+ // uint3 in hlsl, uvec3 in glsl
328
367
name = " gl_LocalInvocationID" ;
329
368
330
- auto builder = context->getBuilder ();
331
369
requiredType = builder->getVectorType (builder->getBasicType (BaseType::UInt), builder->getIntValue (builder->getIntType (), 3 ));
332
370
}
333
371
else if (semanticName == " sv_gsinstanceid" )
334
372
{
373
+ // uint in hlsl, int in glsl
374
+ // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/gl_InvocationID.xhtml
375
+
376
+ requiredType = builder->getBasicType (BaseType::Int);
335
377
name = " gl_InvocationID" ;
336
378
}
337
379
else if (semanticName == " sv_instanceid" )
338
380
{
381
+ // https://docs.microsoft.com/en-us/windows/desktop/direct3d11/d3d10-graphics-programming-guide-input-assembler-stage-using#instanceid
382
+ // uint in hlsl, int in glsl
383
+
384
+ requiredType = builder->getBasicType (BaseType::Int);
339
385
name = " gl_InstanceIndex" ;
340
386
}
341
387
else if (semanticName == " sv_isfrontface" )
342
388
{
389
+ // bool in hlsl & glsl
390
+ // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/gl_FrontFacing.xhtml
343
391
name = " gl_FrontFacing" ;
344
392
}
345
393
else if (semanticName == " sv_outputcontrolpointid" )
346
394
{
395
+ // uint in hlsl, int in glsl
396
+ // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/gl_InvocationID.xhtml
397
+
347
398
name = " gl_InvocationID" ;
399
+
400
+ requiredType = builder->getBasicType (BaseType::Int);
348
401
}
349
402
else if (semanticName == " sv_pointsize" )
350
403
{
404
+ // float in hlsl & glsl
351
405
name = " gl_PointSize" ;
352
406
}
353
407
else if (semanticName == " sv_primitiveid" )
354
408
{
409
+ // uint in hlsl, int in glsl
410
+ // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/gl_PrimitiveID.xhtml
355
411
name = " gl_PrimitiveID" ;
356
412
357
- auto builder = context->getBuilder ();
358
413
requiredType = builder->getBasicType (BaseType::Int);
359
414
}
360
415
else if (semanticName == " sv_rendertargetarrayindex" )
361
416
{
417
+ // uint on hlsl, int on glsl
418
+ // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/gl_Layer.xhtml
419
+
362
420
switch (context->getStage ())
363
421
{
364
422
case Stage::Geometry:
@@ -376,27 +434,46 @@ GLSLSystemValueInfo* getGLSLSystemValueInfo(
376
434
}
377
435
378
436
name = " gl_Layer" ;
379
- requiredType = context-> getBuilder () ->getBasicType (BaseType::Int);
437
+ requiredType = builder ->getBasicType (BaseType::Int);
380
438
}
381
439
else if (semanticName == " sv_sampleindex" )
382
440
{
441
+ // uint in hlsl, int in glsl
442
+ // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/gl_SampleID.xhtml
443
+
444
+ requiredType = builder->getBasicType (BaseType::Int);
383
445
name = " gl_SampleID" ;
384
446
}
385
447
else if (semanticName == " sv_stencilref" )
386
448
{
449
+ // uint in hlsl, int in glsl
450
+ // https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_shader_stencil_export.txt
451
+
452
+ requiredType = builder->getBasicType (BaseType::Int);
453
+
387
454
context->requireGLSLExtension (" ARB_shader_stencil_export" );
388
455
name = " gl_FragStencilRef" ;
389
456
}
390
457
else if (semanticName == " sv_tessfactor" )
391
458
{
459
+ // TODO(JS): Need to ensure the adjustType can handle such a scenario.
460
+ // float[2|3|4] in hlsl, float[4] on glsl (ie both are arrays but might be different size)
461
+ // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/gl_TessLevelOuter.xhtml
462
+
392
463
name = " gl_TessLevelOuter" ;
393
464
}
394
465
else if (semanticName == " sv_vertexid" )
395
466
{
467
+ // uint in hlsl, int in glsl (https://www.khronos.org/opengl/wiki/Built-in_Variable_(GLSL))
468
+ requiredType = builder->getBasicType (BaseType::Int);
396
469
name = " gl_VertexIndex" ;
397
470
}
398
471
else if (semanticName == " sv_viewportarrayindex" )
399
472
{
473
+ // uint on hlsl, int on glsl
474
+ // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/gl_ViewportIndex.xhtml
475
+
476
+ requiredType = builder->getBasicType (BaseType::Int);
400
477
name = " gl_ViewportIndex" ;
401
478
}
402
479
else if (semanticName == " nv_x_right" )
@@ -425,6 +502,16 @@ GLSLSystemValueInfo* getGLSLSystemValueInfo(
425
502
}
426
503
else if (semanticName == " nv_viewport_mask" )
427
504
{
505
+ // TODO: This doesn't seem to work correctly on it's own between hlsl/glsl
506
+
507
+ // Indeed on slang issue 109 claims this remains a problem
508
+ // https://github.com/shader-slang/slang/issues/109
509
+
510
+ // On hlsl it's UINT related. "higher 16 bits for the right view, lower 16 bits for the left view."
511
+ // There is use in hlsl shader code as uint4 - not clear if that varies
512
+ // https://github.com/KhronosGroup/GLSL/blob/master/extensions/nvx/GL_NVX_multiview_per_view_attributes.txt
513
+ // On glsl its highp int gl_ViewportMaskPerViewNV[];
514
+
428
515
context->requireGLSLVersion (ProfileVersion::GLSL_450);
429
516
context->requireGLSLExtension (" GL_NVX_multiview_per_view_attributes" );
430
517
0 commit comments