subobjects-syntax.hlsl 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // RUN: %clang_cc1 -Wno-unused-value -ffreestanding -verify %s
  2. string globalRs = "CBV(b0)";
  3. string localRs = "UAV(u0, visibility = SHADER_VISIBILITY_GEOMETRY)";
  4. GlobalRootSignature grs1_1 = {"CBV(b0)"};
  5. GlobalRootSignature grs1_2 = { globalRs };
  6. GlobalRootSignature grs2_2 = globalRs; /* expected-error {{cannot initialize a variable of type 'GlobalRootSignature' with an lvalue of type 'string'}} */
  7. GlobalRootSignature grs2_3 = "CBV(b0)"; /* expected-error {{cannot initialize a variable of type 'GlobalRootSignature' with an lvalue of type 'literal string'}} */
  8. GlobalRootSignature grs2_4 = 10; /* expected-error {{cannot initialize a variable of type 'GlobalRootSignature' with an rvalue of type 'literal int'}} */
  9. GlobalRootSignature grs2_5 = {"CBV(b0)", 78};; /* expected-error {{too many elements in subobject initialization (expected 1 element, have 2)}} */
  10. GlobalRootSignature grs2_6 = {""};; /* TODO: add error here */
  11. StateObjectConfig soc1_1 = { STATE_OBJECT_FLAGS_ALLOW_LOCAL_DEPENDENCIES_ON_EXTERNAL_DEFINITONS };
  12. StateObjectConfig soc1_2 = { STATE_OBJECT_FLAGS_ALLOW_LOCAL_DEPENDENCIES_ON_EXTERNAL_DEFINITONS | STATE_OBJECT_FLAGS_ALLOW_EXTERNAL_DEPENDENCIES_ON_LOCAL_DEFINITIONS };
  13. StateObjectConfig soc1_3 = { 0xFF };
  14. StateObjectConfig soc1_4 = { 1 };
  15. StateObjectConfig soc1_5 = { 0.1f }; /* expected-warning {{implicit conversion from 'float' to 'unsigned int' changes value from 0.1 to 0}} */
  16. StateObjectConfig soc2_2 = STATE_OBJECT_FLAGS_ALLOW_LOCAL_DEPENDENCIES_ON_EXTERNAL_DEFINITONS; /* expected-error {{cannot initialize a variable of type 'StateObjectConfig' with an lvalue of type 'const unsigned int'}} */
  17. StateObjectConfig soc2_3 = 0x1; /* expected-error {{cannot initialize a variable of type 'StateObjectConfig' with an rvalue of type 'literal int'}} */
  18. StateObjectConfig soc2_4 = "none"; /* expected-error {{cannot initialize a variable of type 'StateObjectConfig' with an lvalue of type 'literal string'}} */
  19. StateObjectConfig soc2_5 = { STATE_OBJECT_FLAGS_ALLOW_LOCAL_DEPENDENCIES_ON_EXTERNAL_DEFINITONS, STATE_OBJECT_FLAGS_ALLOW_EXTERNAL_DEPENDENCIES_ON_LOCAL_DEFINITIONS }; /* expected-error {{too many elements in subobject initialization (expected 1 element, have 2)}} */
  20. StateObjectConfig soc2_6 = { 0x1, 0x2 }; /* expected-error {{too many elements in subobject initialization (expected 1 element, have 2)}} */
  21. StateObjectConfig soc2_7 = 1.5f; /* expected-error {{cannot initialize a variable of type 'StateObjectConfig' with an rvalue of type 'float'}} */
  22. LocalRootSignature lrs1_1 = {"UAV(u0, visibility = SHADER_VISIBILITY_GEOMETRY)"};
  23. LocalRootSignature lrs1_2 = { localRs };
  24. LocalRootSignature lrs2_2 = localRs; /* expected-error {{cannot initialize a variable of type 'LocalRootSignature' with an lvalue of type 'string'}} */
  25. LocalRootSignature lrs2_3 = "UAV(u0, visibility = SHADER_VISIBILITY_GEOMETRY)"; /* expected-error {{cannot initialize a variable of type 'LocalRootSignature' with an lvalue of type 'literal string'}} */
  26. LocalRootSignature lrs2_4 = 10; /* expected-error {{cannot initialize a variable of type 'LocalRootSignature' with an rvalue of type 'literal int'}} */
  27. LocalRootSignature lrs2_5 = { 1.7f, "UAV(u0, visibility = SHADER_VISIBILITY_GEOMETRY)" };; /* expected-error {{too many elements in subobject initialization (expected 1 element, have 2)}} */
  28. LocalRootSignature lrs2_6 = {""};; /* TODO: add error here */
  29. string s1 = "abc";
  30. string s2 = "edf";
  31. string s3 = s1;
  32. string s4 = s1 + s2; /* expected-error {{scalar, vector, or matrix expected}} */
  33. SubobjectToExportsAssociation sea1_1 = { "grs", "a;b;foo;c" };
  34. SubobjectToExportsAssociation sea1_2 = { "grs", ";;;" };
  35. SubobjectToExportsAssociation sea1_4 = { s1, s2 };
  36. SubobjectToExportsAssociation sea1_5 = { "a", s3 };
  37. SubobjectToExportsAssociation sea1_6 = { "b", s4 };
  38. SubobjectToExportsAssociation sea2_4 = { 15, 0.01f }; /* expected-error {{type mismatch}} */
  39. SubobjectToExportsAssociation sea2_5 = { s1, s2 + ';' + s2 }; /* expected-error {{scalar, vector, or matrix expected}} */
  40. SubobjectToExportsAssociation sea2_6 = { 51 }; /* expected-error {{too few elements in subobject initialization (expected 2 elements, have 1)}} */
  41. SubobjectToExportsAssociation sea2_7 = "foo"; /* expected-error {{cannot initialize a variable of type 'SubobjectToExportsAssociation' with an lvalue of type 'literal string'}} */
  42. SubobjectToExportsAssociation sea2_8 = 65412; /* expected-error {{cannot initialize a variable of type 'SubobjectToExportsAssociation' with an rvalue of type 'literal int'}} */
  43. int i1 = 10, i2 = 156;
  44. RaytracingShaderConfig rsc1_1 = { 128, 64 };
  45. RaytracingShaderConfig rsc1_2 = { int2(128, 64) };
  46. RaytracingShaderConfig rsc1_3 = { i1, i1 + i2 };
  47. RaytracingShaderConfig rsc2_2 = int2(128, 64); /* expected-error {{cannot initialize a variable of type 'RaytracingShaderConfig' with an rvalue of type 'int2'}} */
  48. RaytracingShaderConfig rsc2_3 = { 128, 64, 32 }; /* expected-error {{too many elements in subobject initialization (expected 2 elements, have 3)}} */
  49. RaytracingShaderConfig rsc2_4 = { 128 }; /* expected-error {{too few elements in subobject initialization (expected 2 elements, have 1)}} */
  50. RaytracingShaderConfig rsc2_5 = { 128f, 64f }; /* expected-error {{invalid digit 'f' in decimal constant}} expected-error {{invalid digit 'f' in decimal constant}} */
  51. RaytracingShaderConfig rsc2_6 = { "foo" }; /* expected-error {{too few elements in subobject initialization (expected 2 elements, have 1)}} */
  52. RaytracingShaderConfig rsc2_7 = "foo"; /* expected-error {{cannot initialize a variable of type 'RaytracingShaderConfig' with an lvalue of type 'literal string'}} */
  53. RaytracingShaderConfig rsc2_8 = 128; /* expected-error {{cannot initialize a variable of type 'RaytracingShaderConfig' with an rvalue of type 'literal int'}} */
  54. RaytracingPipelineConfig rpc1_1 = { 512 };
  55. RaytracingPipelineConfig rpc1_2 = { 512.15f }; /* expected-warning {{implicit conversion from 'float' to 'unsigned int' changes value from 512.15002 to 512}} */
  56. RaytracingPipelineConfig rpc2_2 = { 512, 128 }; /* expected-error {{too many elements in subobject initialization (expected 1 element, have 2)}} */
  57. RaytracingPipelineConfig rpc2_3 = 512; /* expected-error {{cannot initialize a variable of type 'RaytracingPipelineConfig' with an rvalue of type 'literal int'}} */
  58. RaytracingPipelineConfig rpc2_4 = 51.1f; /* expected-error {{cannot initialize a variable of type 'RaytracingPipelineConfig' with an rvalue of type 'float'}} */
  59. RaytracingPipelineConfig rpc2_5 = "foo"; /* expected-error {{cannot initialize a variable of type 'RaytracingPipelineConfig' with an lvalue of type 'literal string'}} */
  60. TriangleHitGroup trHitGt1_1 = { "a", "b" };
  61. TriangleHitGroup trHitGt1_2 = { s1, s2 };
  62. TriangleHitGroup trHitGt1_3 = { "", "" };
  63. TriangleHitGroup trHitGt2_2 = { "a", "b", "c"}; /* expected-error {{too many elements in subobject initialization (expected 2 elements, have 3)}} */
  64. TriangleHitGroup trHitGt2_3 = { "a", 10 }; /* expected-error {{type mismatch}} */
  65. TriangleHitGroup trHitGt2_4 = { 1, 2 }; /* expected-error {{type mismatch}} */
  66. TriangleHitGroup trHitGt2_5 = "foo"; /* expected-error {{cannot initialize a variable of type 'TriangleHitGroup' with an lvalue of type 'literal string'}} */
  67. TriangleHitGroup trHitGt2_6 = 115; /* expected-error {{cannot initialize a variable of type 'TriangleHitGroup' with an rvalue of type 'literal int'}} */
  68. TriangleHitGroup trHitGt2_7 = s2; /* expected-error {{cannot initialize a variable of type 'TriangleHitGroup' with an lvalue of type 'string'}} */
  69. ProceduralPrimitiveHitGroup ppHitGt1_1 = { "a", "b", "c"};
  70. ProceduralPrimitiveHitGroup ppHitGt1_2 = { s1, s2, s3 };
  71. ProceduralPrimitiveHitGroup ppHitGt1_3 = { "", "", "c" };
  72. ProceduralPrimitiveHitGroup ppHitGt2_2 = { "a", "b"}; /* expected-error {{too few elements in subobject initialization (expected 3 elements, have 2)}} */
  73. ProceduralPrimitiveHitGroup ppHitGt2_3 = { "a", "b", 10 }; /* expected-error {{type mismatch}} */
  74. ProceduralPrimitiveHitGroup ppHitGt2_4 = { 1, 2, 3 }; /* expected-error {{type mismatch}} */
  75. ProceduralPrimitiveHitGroup ppHitGt2_5 = "foo"; /* expected-error {{cannot initialize a variable of type 'ProceduralPrimitiveHitGroup' with an lvalue of type 'literal string'}} */
  76. ProceduralPrimitiveHitGroup ppHitGt2_6 = 115; /* expected-error {{cannot initialize a variable of type 'ProceduralPrimitiveHitGroup' with an rvalue of type 'literal int'}} */
  77. ProceduralPrimitiveHitGroup ppHitGt2_7 = s2; /* expected-error {{cannot initialize a variable of type 'ProceduralPrimitiveHitGroup' with an lvalue of type 'string'}} */
  78. TriangleHitGroup trHitGt2_8 = { s1, s4 };
  79. ProceduralPrimitiveHitGroup ppHitGt2_8 = { s1, "", s4 };
  80. ProceduralPrimitiveHitGroup ppHitGt2_9 = { "a", "b", ""};
  81. int main(int i : INDEX) : SV_Target {
  82. return 1;
  83. }