| 1 |
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library \ |
| 2 |
// RUN: -fhlsl-strict-availability -fsyntax-only -verify %s |
| 3 |
|
| 4 |
__attribute__((availability(shadermodel, introduced = 6.5))) |
| 5 |
float fx(float); // #fx |
| 6 |
|
| 7 |
__attribute__((availability(shadermodel, introduced = 6.6))) |
| 8 |
half fx(half); // #fx_half |
| 9 |
|
| 10 |
__attribute__((availability(shadermodel, introduced = 5.0, environment = pixel))) |
| 11 |
__attribute__((availability(shadermodel, introduced = 6.5, environment = compute))) |
| 12 |
float fy(float); // #fy |
| 13 |
|
| 14 |
__attribute__((availability(shadermodel, introduced = 5.0, environment = pixel))) |
| 15 |
__attribute__((availability(shadermodel, introduced = 6.5, environment = mesh))) |
| 16 |
float fz(float); // #fz |
| 17 |
|
| 18 |
// FIXME: all diagnostics marked as FUTURE will come alive when HLSL default |
| 19 |
// diagnostic mode is implemented in a future PR which will verify calls in |
| 20 |
// all functions that are reachable from the shader library entry points |
| 21 |
|
| 22 |
float also_alive(float f) { |
| 23 |
// expected-error@#also_alive_fx_call {{'fx' is only available on Shader Model 6.5 or newer}} |
| 24 |
// expected-note@#fx {{'fx' has been marked as being introduced in Shader Model 6.5 here, but the deployment target is Shader Model 6.0}} |
| 25 |
float A = fx(f); // #also_alive_fx_call |
| 26 |
|
| 27 |
// expected-error@#also_alive_fy_call {{'fy' is only available in compute environment on Shader Model 6.5 or newer}} |
| 28 |
// expected-note@#fy {{'fy' has been marked as being introduced in Shader Model 6.5 in compute environment here, but the deployment target is Shader Model 6.0 compute environment}} |
| 29 |
float B = fy(f); // #also_alive_fy_call |
| 30 |
|
| 31 |
// expected-error@#also_alive_fz_call {{'fz' is unavailable}} |
| 32 |
// expected-note@#fz {{'fz' has been marked as being introduced in Shader Model 6.5 in mesh environment here, but the deployment target is Shader Model 6.0 compute environment}} |
| 33 |
float C = fz(f); // #also_alive_fz_call |
| 34 |
|
| 35 |
return 0; |
| 36 |
} |
| 37 |
|
| 38 |
float alive(float f) { |
| 39 |
// expected-error@#alive_fx_call {{'fx' is only available on Shader Model 6.5 or newer}} |
| 40 |
// expected-note@#fx {{'fx' has been marked as being introduced in Shader Model 6.5 here, but the deployment target is Shader Model 6.0}} |
| 41 |
float A = fx(f); // #alive_fx_call |
| 42 |
|
| 43 |
// expected-error@#alive_fy_call {{'fy' is only available in compute environment on Shader Model 6.5 or newer}} |
| 44 |
// expected-note@#fy {{'fy' has been marked as being introduced in Shader Model 6.5 in compute environment here, but the deployment target is Shader Model 6.0 compute environment}} |
| 45 |
float B = fy(f); // #alive_fy_call |
| 46 |
|
| 47 |
// expected-error@#alive_fz_call {{'fz' is unavailable}} |
| 48 |
// expected-note@#fz {{'fz' has been marked as being introduced in Shader Model 6.5 in mesh environment here, but the deployment target is Shader Model 6.0 compute environment}} |
| 49 |
float C = fz(f); // #alive_fz_call |
| 50 |
|
| 51 |
return also_alive(f); |
| 52 |
} |
| 53 |
|
| 54 |
float also_dead(float f) { |
| 55 |
// expected-error@#also_dead_fx_call {{'fx' is only available on Shader Model 6.5 or newer}} |
| 56 |
// expected-note@#fx {{'fx' has been marked as being introduced in Shader Model 6.5 here, but the deployment target is Shader Model 6.0}} |
| 57 |
float A = fx(f); // #also_dead_fx_call |
| 58 |
|
| 59 |
// Call to environment-specific function from an unreachable function |
| 60 |
// in a shader library - no diagnostic expected. |
| 61 |
float B = fy(f); // #also_dead_fy_call |
| 62 |
|
| 63 |
// Call to environment-specific function from an unreachable function |
| 64 |
// in a shader library - no diagnostic expected. |
| 65 |
float C = fz(f); // #also_dead_fz_call |
| 66 |
return 0; |
| 67 |
} |
| 68 |
|
| 69 |
float dead(float f) { |
| 70 |
// expected-error@#dead_fx_call {{'fx' is only available on Shader Model 6.5 or newer}} |
| 71 |
// expected-note@#fx {{'fx' has been marked as being introduced in Shader Model 6.5 here, but the deployment target is Shader Model 6.0}} |
| 72 |
float A = fx(f); // #dead_fx_call |
| 73 |
|
| 74 |
// Call to environment-specific function from an unreachable function |
| 75 |
// in a shader library - no diagnostic expected. |
| 76 |
float B = fy(f); // #dead_fy_call |
| 77 |
|
| 78 |
// Call to environment-specific function from an unreachable function |
| 79 |
// in a shader library - no diagnostic expected. |
| 80 |
float C = fz(f); // #dead_fz_call |
| 81 |
|
| 82 |
return also_dead(f); |
| 83 |
} |
| 84 |
|
| 85 |
template<typename T> |
| 86 |
T aliveTemp(T f) { |
| 87 |
// expected-error@#aliveTemp_fx_call {{'fx' is only available on Shader Model 6.5 or newer}} |
| 88 |
// expected-note@#aliveTemp_inst {{in instantiation of function template specialization 'aliveTemp<float>' requested here}} |
| 89 |
// expected-note@#fx {{'fx' has been marked as being introduced in Shader Model 6.5 here, but the deployment target is Shader Model 6.0}} |
| 90 |
float A = fx(f); // #aliveTemp_fx_call |
| 91 |
// expected-error@#aliveTemp_fy_call {{'fy' is only available in compute environment on Shader Model 6.5 or newer}} |
| 92 |
// expected-note@#fy {{'fy' has been marked as being introduced in Shader Model 6.5 in compute environment here, but the deployment target is Shader Model 6.0 compute environment}} |
| 93 |
float B = fy(f); // #aliveTemp_fy_call |
| 94 |
// expected-error@#aliveTemp_fz_call {{'fz' is unavailable}} |
| 95 |
// expected-note@#fz {{'fz' has been marked as being introduced in Shader Model 6.5 in mesh environment here, but the deployment target is Shader Model 6.0 compute environment}} |
| 96 |
float C = fz(f); // #aliveTemp_fz_call |
| 97 |
return 0; |
| 98 |
} |
| 99 |
|
| 100 |
template<typename T> T aliveTemp2(T f) { |
| 101 |
// expected-error@#aliveTemp2_fx_call {{'fx' is only available on Shader Model 6.6 or newer}} |
| 102 |
// expected-note@#fx_half {{'fx' has been marked as being introduced in Shader Model 6.6 here, but the deployment target is Shader Model 6.0}} |
| 103 |
// expected-error@#aliveTemp2_fx_call {{'fx' is only available on Shader Model 6.5 or newer}} |
| 104 |
// expected-note@#fx {{'fx' has been marked as being introduced in Shader Model 6.5 here, but the deployment target is Shader Model 6.0}} |
| 105 |
return fx(f); // #aliveTemp2_fx_call |
| 106 |
} |
| 107 |
|
| 108 |
half test(half x) { |
| 109 |
return aliveTemp2(x); // expected-note {{in instantiation of function template specialization 'aliveTemp2<half>' requested here}} |
| 110 |
} |
| 111 |
|
| 112 |
float test(float x) { |
| 113 |
return aliveTemp2(x); // expected-note {{in instantiation of function template specialization 'aliveTemp2<float>' requested here}} |
| 114 |
} |
| 115 |
|
| 116 |
class MyClass |
| 117 |
{ |
| 118 |
float F; |
| 119 |
float makeF() { |
| 120 |
// expected-error@#MyClass_makeF_fx_call {{'fx' is only available on Shader Model 6.5 or newer}} |
| 121 |
// expected-note@#fx {{'fx' has been marked as being introduced in Shader Model 6.5 here, but the deployment target is Shader Model 6.0}} |
| 122 |
float A = fx(F); // #MyClass_makeF_fx_call |
| 123 |
// expected-error@#MyClass_makeF_fy_call {{'fy' is only available in compute environment on Shader Model 6.5 or newer}} |
| 124 |
// expected-note@#fy {{'fy' has been marked as being introduced in Shader Model 6.5 in compute environment here, but the deployment target is Shader Model 6.0 compute environment}} |
| 125 |
float B = fy(F); // #MyClass_makeF_fy_call |
| 126 |
// expected-error@#MyClass_makeF_fz_call {{'fz' is unavailable}} |
| 127 |
// expected-note@#fz {{'fz' has been marked as being introduced in Shader Model 6.5 in mesh environment here, but the deployment target is Shader Model 6.0 compute environment}} |
| 128 |
float C = fz(F); // #MyClass_makeF_fz_call |
| 129 |
} |
| 130 |
}; |
| 131 |
|
| 132 |
// Exported function without body, not used |
| 133 |
export void exportedFunctionUnused(float f); |
| 134 |
|
| 135 |
// Exported function with body, without export, not used |
| 136 |
void exportedFunctionUnused(float f) { |
| 137 |
// expected-error@#exportedFunctionUnused_fx_call {{'fx' is only available on Shader Model 6.5 or newer}} |
| 138 |
// expected-note@#fx {{'fx' has been marked as being introduced in Shader Model 6.5 here, but the deployment target is Shader Model 6.0}} |
| 139 |
float A = fx(f); // #exportedFunctionUnused_fx_call |
| 140 |
|
| 141 |
// API with shader-stage-specific availability in unused exported library function |
| 142 |
// - no errors expected because the actual shader stage this function |
| 143 |
// will be used in not known at this time |
| 144 |
float B = fy(f); |
| 145 |
float C = fz(f); |
| 146 |
} |
| 147 |
|
| 148 |
// Exported function with body - called from main() which is a compute shader entry point |
| 149 |
export void exportedFunctionUsed(float f) { |
| 150 |
// expected-error@#exportedFunctionUsed_fx_call {{'fx' is only available on Shader Model 6.5 or newer}} |
| 151 |
// expected-note@#fx {{'fx' has been marked as being introduced in Shader Model 6.5 here, but the deployment target is Shader Model 6.0}} |
| 152 |
float A = fx(f); // #exportedFunctionUsed_fx_call |
| 153 |
|
| 154 |
// expected-error@#exportedFunctionUsed_fy_call {{'fy' is only available in compute environment on Shader Model 6.5 or newer}} |
| 155 |
// expected-note@#fy {{'fy' has been marked as being introduced in Shader Model 6.5 in compute environment here, but the deployment target is Shader Model 6.0 compute environment}} |
| 156 |
float B = fy(f); // #exportedFunctionUsed_fy_call |
| 157 |
|
| 158 |
// expected-error@#exportedFunctionUsed_fz_call {{'fz' is unavailable}} |
| 159 |
// expected-note@#fz {{'fz' has been marked as being introduced in Shader Model 6.5 in mesh environment here, but the deployment target is Shader Model 6.0 compute environment}} |
| 160 |
float C = fz(f); // #exportedFunctionUsed_fz_call |
| 161 |
} |
| 162 |
|
| 163 |
namespace A { |
| 164 |
namespace B { |
| 165 |
export { |
| 166 |
void exportedFunctionInNS(float x) { |
| 167 |
// expected-error@#exportedFunctionInNS_fx_call {{'fx' is only available on Shader Model 6.5 or newer}} |
| 168 |
// expected-note@#fx {{'fx' has been marked as being introduced in Shader Model 6.5 here, but the deployment target is Shader Model 6.0}} |
| 169 |
float A = fx(x); // #exportedFunctionInNS_fx_call |
| 170 |
|
| 171 |
// API with shader-stage-specific availability in exported library function |
| 172 |
// - no errors expected because the actual shader stage this function |
| 173 |
// will be used in not known at this time |
| 174 |
float B = fy(x); |
| 175 |
float C = fz(x); |
| 176 |
} |
| 177 |
} |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
[shader("compute")] |
| 182 |
[numthreads(4,1,1)] |
| 183 |
void main() { |
| 184 |
float f = 3; |
| 185 |
MyClass C = { 1.0f }; |
| 186 |
float a = alive(f);float b = aliveTemp<float>(f); // #aliveTemp_inst |
| 187 |
float c = C.makeF(); |
| 188 |
float d = test((float)1.0); |
| 189 |
float e = test((half)1.0); |
| 190 |
exportedFunctionUsed(1.0f); |
| 191 |
} |