| 1 |
// Copyright (c) 2022 The Khronos Group Inc. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
// Tests instructions from SPV_NV_shader_invocation_reorder and |
| 16 |
// SPV_EXT_shader_invocation_reorder. |
| 17 |
|
| 18 |
#include <sstream> |
| 19 |
#include <string> |
| 20 |
|
| 21 |
#include "gmock/gmock.h" |
| 22 |
#include "test/val/val_fixtures.h" |
| 23 |
|
| 24 |
namespace spvtools { |
| 25 |
namespace val { |
| 26 |
namespace { |
| 27 |
|
| 28 |
using ::testing::HasSubstr; |
| 29 |
using ::testing::Values; |
| 30 |
|
| 31 |
using ValidateRayTracingReorderNV = spvtest::ValidateBase<bool>; |
| 32 |
|
| 33 |
std::string GenerateReorderThreadCode(const std::string& body = "", |
| 34 |
const std::string& declarations = "", |
| 35 |
const std::string& extensions = "", |
| 36 |
const std::string& capabilities = "") { |
| 37 |
std::ostringstream ss; |
| 38 |
ss << R"( |
| 39 |
OpCapability RayTracingKHR |
| 40 |
OpCapability ShaderInvocationReorderNV |
| 41 |
)"; |
| 42 |
ss << capabilities; |
| 43 |
ss << R"( |
| 44 |
OpExtension "SPV_KHR_ray_tracing" |
| 45 |
OpExtension "SPV_NV_shader_invocation_reorder" |
| 46 |
)"; |
| 47 |
ss << extensions; |
| 48 |
ss << R"( |
| 49 |
%1 = OpExtInstImport "GLSL.std.450" |
| 50 |
OpMemoryModel Logical GLSL450 |
| 51 |
OpEntryPoint RayGenerationNV %main "main" %hObj |
| 52 |
OpSourceExtension "GL_EXT_ray_tracing" |
| 53 |
OpSourceExtension "GL_NV_shader_invocation_reorder" |
| 54 |
OpName %main "main" |
| 55 |
%void = OpTypeVoid |
| 56 |
%3 = OpTypeFunction %void |
| 57 |
%6 = OpTypeHitObjectNV |
| 58 |
%_ptr_Private_6 = OpTypePointer Private %6 |
| 59 |
%hObj = OpVariable %_ptr_Private_6 Private |
| 60 |
)"; |
| 61 |
ss << declarations; |
| 62 |
|
| 63 |
ss << R"( |
| 64 |
%main = OpFunction %void None %3 |
| 65 |
%5 = OpLabel |
| 66 |
)"; |
| 67 |
|
| 68 |
ss << body; |
| 69 |
|
| 70 |
ss << R"( |
| 71 |
OpReturn |
| 72 |
OpFunctionEnd |
| 73 |
)"; |
| 74 |
return ss.str(); |
| 75 |
} |
| 76 |
|
| 77 |
TEST_F(ValidateRayTracingReorderNV, ReorderThreadWithHintNV) { |
| 78 |
const std::string declarations = R"( |
| 79 |
%uint = OpTypeInt 32 0 |
| 80 |
%uint_4 = OpConstant %uint 4 |
| 81 |
)"; |
| 82 |
|
| 83 |
const std::string body = R"( |
| 84 |
OpReorderThreadWithHintNV %uint_4 %uint_4 |
| 85 |
)"; |
| 86 |
|
| 87 |
CompileSuccessfully(GenerateReorderThreadCode(body, declarations).c_str(), |
| 88 |
SPV_ENV_VULKAN_1_2); |
| 89 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 90 |
} |
| 91 |
|
| 92 |
TEST_F(ValidateRayTracingReorderNV, ReorderThreadWithHitObjectNV) { |
| 93 |
const std::string declarations = R"( |
| 94 |
%uint = OpTypeInt 32 0 |
| 95 |
%uint_4 = OpConstant %uint 4 |
| 96 |
%uint_2 = OpConstant %uint 2 |
| 97 |
)"; |
| 98 |
|
| 99 |
const std::string body = R"( |
| 100 |
OpReorderThreadWithHitObjectNV %hObj |
| 101 |
OpReorderThreadWithHitObjectNV %hObj %uint_4 %uint_2 |
| 102 |
)"; |
| 103 |
|
| 104 |
CompileSuccessfully(GenerateReorderThreadCode(body, declarations).c_str(), |
| 105 |
SPV_ENV_VULKAN_1_2); |
| 106 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 107 |
} |
| 108 |
|
| 109 |
std::string GenerateReorderShaderCode( |
| 110 |
const std::string& body = "", const std::string& declarations = "", |
| 111 |
const std::string execution_model = "RayGenerationKHR") { |
| 112 |
std::ostringstream ss; |
| 113 |
ss << R"( |
| 114 |
OpCapability RayTracingKHR |
| 115 |
OpCapability ShaderInvocationReorderNV |
| 116 |
OpExtension "SPV_KHR_ray_tracing" |
| 117 |
OpExtension "SPV_NV_shader_invocation_reorder" |
| 118 |
%1 = OpExtInstImport "GLSL.std.450" |
| 119 |
OpMemoryModel Logical GLSL450 |
| 120 |
OpEntryPoint )" |
| 121 |
<< execution_model |
| 122 |
<< R"( %main "main" %attr %_ %hObj %payload %__0 %as %__1 |
| 123 |
OpSource GLSL 460 |
| 124 |
OpSourceExtension "GL_EXT_ray_tracing" |
| 125 |
OpSourceExtension "GL_NV_shader_invocation_reorder" |
| 126 |
OpName %main "main" |
| 127 |
OpName %attr "attr" |
| 128 |
OpName %hBlock "hBlock" |
| 129 |
OpMemberName %hBlock 0 "attrval" |
| 130 |
OpName %_ "" |
| 131 |
OpName %hObj "hObj" |
| 132 |
OpName %payload "payload" |
| 133 |
OpName %pBlock "pBlock" |
| 134 |
OpMemberName %pBlock 0 "val1" |
| 135 |
OpMemberName %pBlock 1 "val2" |
| 136 |
OpName %__0 "" |
| 137 |
OpName %as "as" |
| 138 |
OpName %block "block" |
| 139 |
OpMemberName %block 0 "op" |
| 140 |
OpName %__1 "" |
| 141 |
OpDecorate %hBlock Block |
| 142 |
OpDecorate %pBlock Block |
| 143 |
OpDecorate %as DescriptorSet 0 |
| 144 |
OpDecorate %as Binding 0 |
| 145 |
OpMemberDecorate %block 0 Offset 0 |
| 146 |
OpDecorate %block Block |
| 147 |
OpDecorate %__1 DescriptorSet 0 |
| 148 |
OpDecorate %__1 Binding 1 |
| 149 |
%void = OpTypeVoid |
| 150 |
%3 = OpTypeFunction %void |
| 151 |
%float = OpTypeFloat 32 |
| 152 |
%v2float = OpTypeVector %float 2 |
| 153 |
%_ptr_HitObjectAttributeNV_v2float = OpTypePointer HitObjectAttributeNV %v2float |
| 154 |
%attr = OpVariable %_ptr_HitObjectAttributeNV_v2float HitObjectAttributeNV |
| 155 |
%float_1 = OpConstant %float 1 |
| 156 |
%11 = OpConstantComposite %v2float %float_1 %float_1 |
| 157 |
%hBlock = OpTypeStruct %float |
| 158 |
%_ptr_HitObjectAttributeNV_hBlock = OpTypePointer HitObjectAttributeNV %hBlock |
| 159 |
%_ = OpVariable %_ptr_HitObjectAttributeNV_hBlock HitObjectAttributeNV |
| 160 |
%int = OpTypeInt 32 1 |
| 161 |
%int_0 = OpConstant %int 0 |
| 162 |
%float_2 = OpConstant %float 2 |
| 163 |
%_ptr_HitObjectAttributeNV_float = OpTypePointer HitObjectAttributeNV %float |
| 164 |
%20 = OpTypeHitObjectNV |
| 165 |
%_ptr_Private_20 = OpTypePointer Private %20 |
| 166 |
%hObj = OpVariable %_ptr_Private_20 Private |
| 167 |
%23 = OpTypeAccelerationStructureKHR |
| 168 |
%_ptr_UniformConstant_23 = OpTypePointer UniformConstant %23 |
| 169 |
%as = OpVariable %_ptr_UniformConstant_23 UniformConstant |
| 170 |
%v4float = OpTypeVector %float 4 |
| 171 |
%_ptr_RayPayloadNV_v4float = OpTypePointer RayPayloadNV %v4float |
| 172 |
%payload = OpVariable %_ptr_RayPayloadNV_v4float RayPayloadNV |
| 173 |
%pBlock = OpTypeStruct %v2float %v2float |
| 174 |
%_ptr_RayPayloadNV_pBlock = OpTypePointer RayPayloadNV %pBlock |
| 175 |
%__0 = OpVariable %_ptr_RayPayloadNV_pBlock RayPayloadNV |
| 176 |
%block = OpTypeStruct %float |
| 177 |
%_ptr_StorageBuffer_block = OpTypePointer StorageBuffer %block |
| 178 |
%__1 = OpVariable %_ptr_StorageBuffer_block StorageBuffer |
| 179 |
)"; |
| 180 |
|
| 181 |
ss << declarations; |
| 182 |
|
| 183 |
ss << R"( |
| 184 |
%main = OpFunction %void None %3 |
| 185 |
%5 = OpLabel |
| 186 |
)"; |
| 187 |
|
| 188 |
ss << body; |
| 189 |
|
| 190 |
ss << R"( |
| 191 |
OpReturn |
| 192 |
OpFunctionEnd)"; |
| 193 |
return ss.str(); |
| 194 |
} |
| 195 |
|
| 196 |
TEST_F(ValidateRayTracingReorderNV, HitObjectTraceRayNV) { |
| 197 |
const std::string declarations = R"( |
| 198 |
%uint = OpTypeInt 32 0 |
| 199 |
%uint_1 = OpConstant %uint 1 |
| 200 |
%v3float = OpTypeVector %float 3 |
| 201 |
%float_0_5 = OpConstant %float 0.5 |
| 202 |
%31 = OpConstantComposite %v3float %float_0_5 %float_0_5 %float_0_5 |
| 203 |
%32 = OpConstantComposite %v3float %float_1 %float_1 %float_1 |
| 204 |
%int_1 = OpConstant %int 1 |
| 205 |
)"; |
| 206 |
|
| 207 |
const std::string body = R"( |
| 208 |
OpStore %attr %11 |
| 209 |
%26 = OpLoad %23 %as |
| 210 |
OpHitObjectTraceRayNV %hObj %26 %uint_1 %uint_1 %uint_1 %uint_1 %uint_1 %31 %float_0_5 %32 %float_1 %payload |
| 211 |
)"; |
| 212 |
|
| 213 |
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(), |
| 214 |
SPV_ENV_VULKAN_1_2); |
| 215 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 216 |
} |
| 217 |
|
| 218 |
TEST_F(ValidateRayTracingReorderNV, HitObjectTraceRayMotionNV) { |
| 219 |
const std::string declarations = R"( |
| 220 |
%uint = OpTypeInt 32 0 |
| 221 |
%uint_1 = OpConstant %uint 1 |
| 222 |
%v3float = OpTypeVector %float 3 |
| 223 |
%float_0_5 = OpConstant %float 0.5 |
| 224 |
%31 = OpConstantComposite %v3float %float_0_5 %float_0_5 %float_0_5 |
| 225 |
%32 = OpConstantComposite %v3float %float_1 %float_1 %float_1 |
| 226 |
%float_10 = OpConstant %float 10 |
| 227 |
%int_2 = OpConstant %int 2 |
| 228 |
)"; |
| 229 |
|
| 230 |
const std::string body = R"( |
| 231 |
OpStore %attr %11 |
| 232 |
%26 = OpLoad %23 %as |
| 233 |
OpHitObjectTraceRayMotionNV %hObj %26 %uint_1 %uint_1 %uint_1 %uint_1 %uint_1 %31 %float_0_5 %32 %float_1 %float_10 %__0 |
| 234 |
)"; |
| 235 |
|
| 236 |
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(), |
| 237 |
SPV_ENV_VULKAN_1_2); |
| 238 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 239 |
} |
| 240 |
|
| 241 |
TEST_F(ValidateRayTracingReorderNV, HitObjectRecordHitNV) { |
| 242 |
const std::string declarations = R"( |
| 243 |
%int_1 = OpConstant %int 1 |
| 244 |
%uint = OpTypeInt 32 0 |
| 245 |
%uint_2 = OpConstant %uint 2 |
| 246 |
%v3float = OpTypeVector %float 3 |
| 247 |
%float_0_5 = OpConstant %float 0.5 |
| 248 |
%31 = OpConstantComposite %v3float %float_0_5 %float_0_5 %float_0_5 |
| 249 |
%32 = OpConstantComposite %v3float %float_1 %float_1 %float_1 |
| 250 |
%float_10 = OpConstant %float 10 |
| 251 |
%int_2 = OpConstant %int 2 |
| 252 |
)"; |
| 253 |
|
| 254 |
const std::string body = R"( |
| 255 |
OpStore %attr %11 |
| 256 |
%26 = OpLoad %23 %as |
| 257 |
OpHitObjectRecordHitNV %hObj %26 %int_1 %int_1 %int_1 %uint_2 %uint_2 %uint_2 %31 %float_1 %32 %float_2 %attr |
| 258 |
)"; |
| 259 |
|
| 260 |
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(), |
| 261 |
SPV_ENV_VULKAN_1_2); |
| 262 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 263 |
} |
| 264 |
|
| 265 |
TEST_F(ValidateRayTracingReorderNV, HitObjectRecordHitWithIndexNV) { |
| 266 |
const std::string declarations = R"( |
| 267 |
%int_1 = OpConstant %int 1 |
| 268 |
%uint = OpTypeInt 32 0 |
| 269 |
%uint_2 = OpConstant %uint 2 |
| 270 |
%v3float = OpTypeVector %float 3 |
| 271 |
%float_0_5 = OpConstant %float 0.5 |
| 272 |
%31 = OpConstantComposite %v3float %float_0_5 %float_0_5 %float_0_5 |
| 273 |
%32 = OpConstantComposite %v3float %float_1 %float_1 %float_1 |
| 274 |
%float_10 = OpConstant %float 10 |
| 275 |
%int_2 = OpConstant %int 2 |
| 276 |
)"; |
| 277 |
|
| 278 |
const std::string body = R"( |
| 279 |
OpStore %attr %11 |
| 280 |
%26 = OpLoad %23 %as |
| 281 |
OpHitObjectRecordHitWithIndexNV %hObj %26 %int_1 %int_1 %int_1 %uint_2 %uint_2 %31 %float_1 %32 %float_2 %_ |
| 282 |
)"; |
| 283 |
|
| 284 |
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(), |
| 285 |
SPV_ENV_VULKAN_1_2); |
| 286 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 287 |
} |
| 288 |
|
| 289 |
TEST_F(ValidateRayTracingReorderNV, HitObjectRecordEmptyNV) { |
| 290 |
const std::string body = R"( |
| 291 |
OpHitObjectRecordEmptyNV %hObj |
| 292 |
)"; |
| 293 |
|
| 294 |
CompileSuccessfully(GenerateReorderShaderCode(body).c_str(), |
| 295 |
SPV_ENV_VULKAN_1_2); |
| 296 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 297 |
} |
| 298 |
|
| 299 |
TEST_F(ValidateRayTracingReorderNV, HitObjectRecordMissNV) { |
| 300 |
const std::string declarations = R"( |
| 301 |
%uint = OpTypeInt 32 0 |
| 302 |
%uint_1 = OpConstant %uint 1 |
| 303 |
%v3float = OpTypeVector %float 3 |
| 304 |
%float_0_5 = OpConstant %float 0.5 |
| 305 |
%29 = OpConstantComposite %v3float %float_0_5 %float_0_5 %float_0_5 |
| 306 |
%float_1_5 = OpConstant %float 1.5 |
| 307 |
%31 = OpConstantComposite %v3float %float_1_5 %float_1_5 %float_1_5 |
| 308 |
%float_5 = OpConstant %float 5 |
| 309 |
)"; |
| 310 |
|
| 311 |
const std::string body = R"( |
| 312 |
OpHitObjectRecordMissNV %hObj %uint_1 %29 %float_2 %31 %float_5 |
| 313 |
)"; |
| 314 |
|
| 315 |
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(), |
| 316 |
SPV_ENV_VULKAN_1_2); |
| 317 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 318 |
} |
| 319 |
|
| 320 |
TEST_F(ValidateRayTracingReorderNV, HitObjectIsHitNV) { |
| 321 |
const std::string declarations = R"( |
| 322 |
%bool = OpTypeBool |
| 323 |
%_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float |
| 324 |
)"; |
| 325 |
|
| 326 |
const std::string body = R"( |
| 327 |
%26 = OpHitObjectIsHitNV %bool %hObj |
| 328 |
OpSelectionMerge %28 None |
| 329 |
OpBranchConditional %26 %27 %28 |
| 330 |
%27 = OpLabel |
| 331 |
%33 = OpAccessChain %_ptr_StorageBuffer_float %__1 %int_0 |
| 332 |
OpStore %33 %float_1 |
| 333 |
OpBranch %28 |
| 334 |
%28 = OpLabel |
| 335 |
)"; |
| 336 |
|
| 337 |
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(), |
| 338 |
SPV_ENV_VULKAN_1_2); |
| 339 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 340 |
} |
| 341 |
|
| 342 |
TEST_F(ValidateRayTracingReorderNV, HitObjectGetRayTMaxNV) { |
| 343 |
const std::string declarations = R"( |
| 344 |
%_ptr_Function_float = OpTypePointer Function %float |
| 345 |
)"; |
| 346 |
|
| 347 |
const std::string body = R"( |
| 348 |
%tmin = OpVariable %_ptr_Function_float Function |
| 349 |
%12 = OpHitObjectGetRayTMaxNV %float %hObj |
| 350 |
OpStore %tmin %12 |
| 351 |
)"; |
| 352 |
|
| 353 |
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(), |
| 354 |
SPV_ENV_VULKAN_1_2); |
| 355 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 356 |
} |
| 357 |
|
| 358 |
TEST_F(ValidateRayTracingReorderNV, HitObjectGetRayTMinNV) { |
| 359 |
const std::string declarations = R"( |
| 360 |
%_ptr_Function_float = OpTypePointer Function %float |
| 361 |
)"; |
| 362 |
|
| 363 |
const std::string body = R"( |
| 364 |
%tmin = OpVariable %_ptr_Function_float Function |
| 365 |
%12 = OpHitObjectGetRayTMinNV %float %hObj |
| 366 |
OpStore %tmin %12 |
| 367 |
)"; |
| 368 |
|
| 369 |
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(), |
| 370 |
SPV_ENV_VULKAN_1_2); |
| 371 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 372 |
} |
| 373 |
|
| 374 |
TEST_F(ValidateRayTracingReorderNV, HitObjectGetWorldRayOriginNV) { |
| 375 |
const std::string declarations = R"( |
| 376 |
%v3float = OpTypeVector %float 3 |
| 377 |
%_ptr_Function_v3float = OpTypePointer Function %v3float |
| 378 |
)"; |
| 379 |
|
| 380 |
const std::string body = R"( |
| 381 |
%orig = OpVariable %_ptr_Function_v3float Function |
| 382 |
%13 = OpHitObjectGetWorldRayOriginNV %v3float %hObj |
| 383 |
OpStore %orig %13 |
| 384 |
)"; |
| 385 |
|
| 386 |
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(), |
| 387 |
SPV_ENV_VULKAN_1_2); |
| 388 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 389 |
} |
| 390 |
|
| 391 |
TEST_F(ValidateRayTracingReorderNV, HitObjectGetObjectRayOriginNV) { |
| 392 |
const std::string declarations = R"( |
| 393 |
%v3float = OpTypeVector %float 3 |
| 394 |
%_ptr_Function_v3float = OpTypePointer Function %v3float |
| 395 |
)"; |
| 396 |
|
| 397 |
const std::string body = R"( |
| 398 |
%oorig = OpVariable %_ptr_Function_v3float Function |
| 399 |
%13 = OpHitObjectGetObjectRayOriginNV %v3float %hObj |
| 400 |
OpStore %oorig %13 |
| 401 |
)"; |
| 402 |
|
| 403 |
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(), |
| 404 |
SPV_ENV_VULKAN_1_2); |
| 405 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 406 |
} |
| 407 |
|
| 408 |
TEST_F(ValidateRayTracingReorderNV, HitObjectGetWorldRayDirectionNV) { |
| 409 |
const std::string declarations = R"( |
| 410 |
%v3float = OpTypeVector %float 3 |
| 411 |
%_ptr_Function_v3float = OpTypePointer Function %v3float |
| 412 |
)"; |
| 413 |
|
| 414 |
const std::string body = R"( |
| 415 |
%dir = OpVariable %_ptr_Function_v3float Function |
| 416 |
%13 = OpHitObjectGetWorldRayDirectionNV %v3float %hObj |
| 417 |
OpStore %dir %13 |
| 418 |
)"; |
| 419 |
|
| 420 |
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(), |
| 421 |
SPV_ENV_VULKAN_1_2); |
| 422 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 423 |
} |
| 424 |
|
| 425 |
TEST_F(ValidateRayTracingReorderNV, HitObjectGetObjectRayDirectionNV) { |
| 426 |
const std::string declarations = R"( |
| 427 |
%v3float = OpTypeVector %float 3 |
| 428 |
%_ptr_Function_v3float = OpTypePointer Function %v3float |
| 429 |
)"; |
| 430 |
|
| 431 |
const std::string body = R"( |
| 432 |
%odir = OpVariable %_ptr_Function_v3float Function |
| 433 |
%13 = OpHitObjectGetObjectRayDirectionNV %v3float %hObj |
| 434 |
OpStore %odir %13 |
| 435 |
)"; |
| 436 |
|
| 437 |
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(), |
| 438 |
SPV_ENV_VULKAN_1_2); |
| 439 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 440 |
} |
| 441 |
|
| 442 |
TEST_F(ValidateRayTracingReorderNV, HitObjectGetObjectToWorldNV) { |
| 443 |
const std::string declarations = R"( |
| 444 |
%v3float = OpTypeVector %float 3 |
| 445 |
%mat4v3float = OpTypeMatrix %v3float 4 |
| 446 |
%_ptr_Function_mat4v3float = OpTypePointer Function %mat4v3float |
| 447 |
)"; |
| 448 |
|
| 449 |
const std::string body = R"( |
| 450 |
%otw = OpVariable %_ptr_Function_mat4v3float Function |
| 451 |
%14 = OpHitObjectGetObjectToWorldNV %mat4v3float %hObj |
| 452 |
OpStore %otw %14 |
| 453 |
)"; |
| 454 |
|
| 455 |
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(), |
| 456 |
SPV_ENV_VULKAN_1_2); |
| 457 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 458 |
} |
| 459 |
|
| 460 |
TEST_F(ValidateRayTracingReorderNV, HitObjectGetWorldToObjectNV) { |
| 461 |
const std::string declarations = R"( |
| 462 |
%v3float = OpTypeVector %float 3 |
| 463 |
%mat4v3float = OpTypeMatrix %v3float 4 |
| 464 |
%_ptr_Function_mat4v3float = OpTypePointer Function %mat4v3float |
| 465 |
)"; |
| 466 |
|
| 467 |
const std::string body = R"( |
| 468 |
%wto = OpVariable %_ptr_Function_mat4v3float Function |
| 469 |
%14 = OpHitObjectGetWorldToObjectNV %mat4v3float %hObj |
| 470 |
OpStore %wto %14 |
| 471 |
)"; |
| 472 |
|
| 473 |
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(), |
| 474 |
SPV_ENV_VULKAN_1_2); |
| 475 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 476 |
} |
| 477 |
|
| 478 |
TEST_F(ValidateRayTracingReorderNV, HitObjectGetInstanceCustomIndexNV) { |
| 479 |
const std::string declarations = R"( |
| 480 |
%_ptr_Function_int = OpTypePointer Function %int |
| 481 |
)"; |
| 482 |
|
| 483 |
const std::string body = R"( |
| 484 |
%id = OpVariable %_ptr_Function_int Function |
| 485 |
%12 = OpHitObjectGetInstanceCustomIndexNV %int %hObj |
| 486 |
OpStore %id %12 |
| 487 |
)"; |
| 488 |
|
| 489 |
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(), |
| 490 |
SPV_ENV_VULKAN_1_2); |
| 491 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 492 |
} |
| 493 |
|
| 494 |
TEST_F(ValidateRayTracingReorderNV, HitObjectGetInstanceIdNV) { |
| 495 |
const std::string declarations = R"( |
| 496 |
%_ptr_Function_int = OpTypePointer Function %int |
| 497 |
)"; |
| 498 |
|
| 499 |
const std::string body = R"( |
| 500 |
%id = OpVariable %_ptr_Function_int Function |
| 501 |
%12 = OpHitObjectGetInstanceIdNV %int %hObj |
| 502 |
OpStore %id %12 |
| 503 |
)"; |
| 504 |
|
| 505 |
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(), |
| 506 |
SPV_ENV_VULKAN_1_2); |
| 507 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 508 |
} |
| 509 |
|
| 510 |
TEST_F(ValidateRayTracingReorderNV, HitObjectGetPrimitiveIndexNV) { |
| 511 |
const std::string declarations = R"( |
| 512 |
%_ptr_Function_int = OpTypePointer Function %int |
| 513 |
)"; |
| 514 |
|
| 515 |
const std::string body = R"( |
| 516 |
%id = OpVariable %_ptr_Function_int Function |
| 517 |
%12 = OpHitObjectGetPrimitiveIndexNV %int %hObj |
| 518 |
OpStore %id %12 |
| 519 |
)"; |
| 520 |
|
| 521 |
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(), |
| 522 |
SPV_ENV_VULKAN_1_2); |
| 523 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 524 |
} |
| 525 |
|
| 526 |
TEST_F(ValidateRayTracingReorderNV, HitObjectGetGeometryIndexNV) { |
| 527 |
const std::string declarations = R"( |
| 528 |
%_ptr_Function_int = OpTypePointer Function %int |
| 529 |
)"; |
| 530 |
|
| 531 |
const std::string body = R"( |
| 532 |
%id = OpVariable %_ptr_Function_int Function |
| 533 |
%12 = OpHitObjectGetGeometryIndexNV %int %hObj |
| 534 |
OpStore %id %12 |
| 535 |
)"; |
| 536 |
|
| 537 |
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(), |
| 538 |
SPV_ENV_VULKAN_1_2); |
| 539 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 540 |
} |
| 541 |
|
| 542 |
TEST_F(ValidateRayTracingReorderNV, HitObjectGetHitKindNV) { |
| 543 |
const std::string declarations = R"( |
| 544 |
%uint = OpTypeInt 32 0 |
| 545 |
%_ptr_Function_uint = OpTypePointer Function %uint |
| 546 |
)"; |
| 547 |
|
| 548 |
const std::string body = R"( |
| 549 |
%uid = OpVariable %_ptr_Function_uint Function |
| 550 |
%12 = OpHitObjectGetHitKindNV %uint %hObj |
| 551 |
OpStore %uid %12 |
| 552 |
)"; |
| 553 |
|
| 554 |
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(), |
| 555 |
SPV_ENV_VULKAN_1_2); |
| 556 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 557 |
} |
| 558 |
|
| 559 |
TEST_F(ValidateRayTracingReorderNV, HitObjectGetAttributesNV) { |
| 560 |
const std::string body = R"( |
| 561 |
OpHitObjectGetAttributesNV %hObj %attr |
| 562 |
)"; |
| 563 |
|
| 564 |
CompileSuccessfully(GenerateReorderShaderCode(body).c_str(), |
| 565 |
SPV_ENV_VULKAN_1_2); |
| 566 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 567 |
} |
| 568 |
|
| 569 |
TEST_F(ValidateRayTracingReorderNV, HitObjectGetShaderRecordBufferHandleNV) { |
| 570 |
const std::string declarations = R"( |
| 571 |
%uint = OpTypeInt 32 0 |
| 572 |
%v2uint = OpTypeVector %uint 2 |
| 573 |
%_ptr_Function_v2uint = OpTypePointer Function %v2uint |
| 574 |
)"; |
| 575 |
|
| 576 |
const std::string body = R"( |
| 577 |
%handle = OpVariable %_ptr_Function_v2uint Function |
| 578 |
%13 = OpHitObjectGetShaderRecordBufferHandleNV %v2uint %hObj |
| 579 |
OpStore %handle %13 |
| 580 |
)"; |
| 581 |
|
| 582 |
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(), |
| 583 |
SPV_ENV_VULKAN_1_2); |
| 584 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 585 |
} |
| 586 |
|
| 587 |
TEST_F(ValidateRayTracingReorderNV, |
| 588 |
HitObjectGetShaderBindingTableRecordIndexNV) { |
| 589 |
const std::string declarations = R"( |
| 590 |
%uint = OpTypeInt 32 0 |
| 591 |
%_ptr_Function_uint = OpTypePointer Function %uint |
| 592 |
)"; |
| 593 |
|
| 594 |
const std::string body = R"( |
| 595 |
%rid = OpVariable %_ptr_Function_uint Function |
| 596 |
%12 = OpHitObjectGetShaderBindingTableRecordIndexNV %uint %hObj |
| 597 |
OpStore %rid %12 |
| 598 |
)"; |
| 599 |
|
| 600 |
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(), |
| 601 |
SPV_ENV_VULKAN_1_2); |
| 602 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 603 |
} |
| 604 |
|
| 605 |
TEST_F(ValidateRayTracingReorderNV, ClusterASNV) { |
| 606 |
const std::string cap = R"( |
| 607 |
OpCapability RayTracingClusterAccelerationStructureNV |
| 608 |
)"; |
| 609 |
|
| 610 |
const std::string ext = R"( |
| 611 |
OpExtension "SPV_NV_cluster_acceleration_structure" |
| 612 |
)"; |
| 613 |
|
| 614 |
const std::string declarations = R"( |
| 615 |
%int = OpTypeInt 32 1 |
| 616 |
%_ptr_Function_int = OpTypePointer Function %int |
| 617 |
)"; |
| 618 |
|
| 619 |
const std::string body = R"( |
| 620 |
%id = OpVariable %_ptr_Function_int Function |
| 621 |
%12 = OpHitObjectGetClusterIdNV %int %hObj |
| 622 |
OpStore %id %12 |
| 623 |
)"; |
| 624 |
|
| 625 |
CompileSuccessfully( |
| 626 |
GenerateReorderThreadCode(body, declarations, ext, cap).c_str(), |
| 627 |
SPV_ENV_VULKAN_1_2); |
| 628 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 629 |
} |
| 630 |
|
| 631 |
TEST_F(ValidateRayTracingReorderNV, LSSGetSpherePositionNV) { |
| 632 |
const std::string cap = R"( |
| 633 |
OpCapability RayTracingSpheresGeometryNV |
| 634 |
)"; |
| 635 |
|
| 636 |
const std::string ext = R"( |
| 637 |
OpExtension "SPV_NV_linear_swept_spheres" |
| 638 |
)"; |
| 639 |
|
| 640 |
const std::string declarations = R"( |
| 641 |
%float = OpTypeFloat 32 |
| 642 |
%v3float = OpTypeVector %float 3 |
| 643 |
%_ptr_Function_v3float = OpTypePointer Function %v3float |
| 644 |
)"; |
| 645 |
|
| 646 |
const std::string body = R"( |
| 647 |
%pos = OpVariable %_ptr_Function_v3float Function |
| 648 |
%result = OpHitObjectGetSpherePositionNV %v3float %hObj |
| 649 |
OpStore %pos %result |
| 650 |
)"; |
| 651 |
|
| 652 |
CompileSuccessfully( |
| 653 |
GenerateReorderThreadCode(body, declarations, ext, cap).c_str(), |
| 654 |
SPV_ENV_VULKAN_1_2); |
| 655 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 656 |
} |
| 657 |
|
| 658 |
TEST_F(ValidateRayTracingReorderNV, LSSGetLSSPositionsNV) { |
| 659 |
const std::string cap = R"( |
| 660 |
OpCapability RayTracingSpheresGeometryNV |
| 661 |
OpCapability RayTracingLinearSweptSpheresGeometryNV |
| 662 |
)"; |
| 663 |
|
| 664 |
const std::string ext = R"( |
| 665 |
OpExtension "SPV_NV_linear_swept_spheres" |
| 666 |
)"; |
| 667 |
|
| 668 |
const std::string declarations = R"( |
| 669 |
%float = OpTypeFloat 32 |
| 670 |
%uint = OpTypeInt 32 0 |
| 671 |
%v3float = OpTypeVector %float 3 |
| 672 |
%uint_2 = OpConstant %uint 2 |
| 673 |
%arr = OpTypeArray %v3float %uint_2 |
| 674 |
%_ptr_Function_v3float = OpTypePointer Function %arr |
| 675 |
)"; |
| 676 |
|
| 677 |
const std::string body = R"( |
| 678 |
%lsspos = OpVariable %_ptr_Function_v3float Function |
| 679 |
%result = OpHitObjectGetLSSPositionsNV %arr %hObj |
| 680 |
OpStore %lsspos %result |
| 681 |
)"; |
| 682 |
|
| 683 |
CompileSuccessfully( |
| 684 |
GenerateReorderThreadCode(body, declarations, ext, cap).c_str(), |
| 685 |
SPV_ENV_VULKAN_1_2); |
| 686 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 687 |
} |
| 688 |
|
| 689 |
TEST_F(ValidateRayTracingReorderNV, LSSGetSphereRadiusNV) { |
| 690 |
const std::string cap = R"( |
| 691 |
OpCapability RayTracingSpheresGeometryNV |
| 692 |
)"; |
| 693 |
|
| 694 |
const std::string ext = R"( |
| 695 |
OpExtension "SPV_NV_linear_swept_spheres" |
| 696 |
)"; |
| 697 |
|
| 698 |
const std::string declarations = R"( |
| 699 |
%float = OpTypeFloat 32 |
| 700 |
%_ptr_Function_float = OpTypePointer Function %float |
| 701 |
)"; |
| 702 |
|
| 703 |
const std::string body = R"( |
| 704 |
%rad = OpVariable %_ptr_Function_float Function |
| 705 |
%result = OpHitObjectGetSphereRadiusNV %float %hObj |
| 706 |
OpStore %rad %result |
| 707 |
)"; |
| 708 |
|
| 709 |
CompileSuccessfully( |
| 710 |
GenerateReorderThreadCode(body, declarations, ext, cap).c_str(), |
| 711 |
SPV_ENV_VULKAN_1_2); |
| 712 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 713 |
} |
| 714 |
|
| 715 |
TEST_F(ValidateRayTracingReorderNV, LSSGetLSSRadiiNV) { |
| 716 |
const std::string cap = R"( |
| 717 |
OpCapability RayTracingLinearSweptSpheresGeometryNV |
| 718 |
)"; |
| 719 |
|
| 720 |
const std::string ext = R"( |
| 721 |
OpExtension "SPV_NV_linear_swept_spheres" |
| 722 |
)"; |
| 723 |
|
| 724 |
const std::string declarations = R"( |
| 725 |
%float = OpTypeFloat 32 |
| 726 |
%uint = OpTypeInt 32 0 |
| 727 |
%uint_2 = OpConstant %uint 2 |
| 728 |
%arr = OpTypeArray %float %uint_2 |
| 729 |
%_ptr_Function_float = OpTypePointer Function %arr |
| 730 |
)"; |
| 731 |
|
| 732 |
const std::string body = R"( |
| 733 |
%rad = OpVariable %_ptr_Function_float Function |
| 734 |
%result = OpHitObjectGetLSSRadiiNV %arr %hObj |
| 735 |
OpStore %rad %result |
| 736 |
)"; |
| 737 |
|
| 738 |
CompileSuccessfully( |
| 739 |
GenerateReorderThreadCode(body, declarations, ext, cap).c_str(), |
| 740 |
SPV_ENV_VULKAN_1_2); |
| 741 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 742 |
} |
| 743 |
|
| 744 |
TEST_F(ValidateRayTracingReorderNV, LSSIsSphereHitNV) { |
| 745 |
const std::string cap = R"( |
| 746 |
OpCapability RayTracingSpheresGeometryNV |
| 747 |
)"; |
| 748 |
|
| 749 |
const std::string ext = R"( |
| 750 |
OpExtension "SPV_NV_linear_swept_spheres" |
| 751 |
)"; |
| 752 |
|
| 753 |
const std::string declarations = R"( |
| 754 |
%bool = OpTypeBool |
| 755 |
%_ptr_Function_bool = OpTypePointer Function %bool |
| 756 |
)"; |
| 757 |
|
| 758 |
const std::string body = R"( |
| 759 |
%ishit = OpVariable %_ptr_Function_bool Function |
| 760 |
%result = OpHitObjectIsSphereHitNV %bool %hObj |
| 761 |
OpStore %ishit %result |
| 762 |
)"; |
| 763 |
|
| 764 |
CompileSuccessfully( |
| 765 |
GenerateReorderThreadCode(body, declarations, ext, cap).c_str(), |
| 766 |
SPV_ENV_VULKAN_1_2); |
| 767 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 768 |
} |
| 769 |
|
| 770 |
TEST_F(ValidateRayTracingReorderNV, LSSIsLSSHitNV) { |
| 771 |
const std::string cap = R"( |
| 772 |
OpCapability RayTracingLinearSweptSpheresGeometryNV |
| 773 |
)"; |
| 774 |
|
| 775 |
const std::string ext = R"( |
| 776 |
OpExtension "SPV_NV_linear_swept_spheres" |
| 777 |
)"; |
| 778 |
|
| 779 |
const std::string declarations = R"( |
| 780 |
%bool = OpTypeBool |
| 781 |
%_ptr_Function_bool = OpTypePointer Function %bool |
| 782 |
)"; |
| 783 |
|
| 784 |
const std::string body = R"( |
| 785 |
%ishit = OpVariable %_ptr_Function_bool Function |
| 786 |
%result = OpHitObjectIsLSSHitNV %bool %hObj |
| 787 |
OpStore %ishit %result |
| 788 |
)"; |
| 789 |
|
| 790 |
CompileSuccessfully( |
| 791 |
GenerateReorderThreadCode(body, declarations, ext, cap).c_str(), |
| 792 |
SPV_ENV_VULKAN_1_2); |
| 793 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 794 |
} |
| 795 |
|
| 796 |
// EXT Extension Tests |
| 797 |
using ValidateRayTracingReorderEXT = spvtest::ValidateBase<bool>; |
| 798 |
|
| 799 |
std::string GenerateReorderThreadCodeEXT(const std::string& body = "", |
| 800 |
const std::string& declarations = "", |
| 801 |
const std::string& extensions = "", |
| 802 |
const std::string& capabilities = "") { |
| 803 |
std::ostringstream ss; |
| 804 |
ss << R"( |
| 805 |
OpCapability RayTracingKHR |
| 806 |
OpCapability ShaderInvocationReorderEXT |
| 807 |
)"; |
| 808 |
ss << capabilities; |
| 809 |
ss << R"( |
| 810 |
OpExtension "SPV_KHR_ray_tracing" |
| 811 |
OpExtension "SPV_EXT_shader_invocation_reorder" |
| 812 |
)"; |
| 813 |
ss << extensions; |
| 814 |
ss << R"( |
| 815 |
%1 = OpExtInstImport "GLSL.std.450" |
| 816 |
OpMemoryModel Logical GLSL450 |
| 817 |
OpEntryPoint RayGenerationNV %main "main" %hObj |
| 818 |
OpSourceExtension "GL_EXT_ray_tracing" |
| 819 |
OpSourceExtension "GL_EXT_shader_invocation_reorder" |
| 820 |
OpName %main "main" |
| 821 |
%void = OpTypeVoid |
| 822 |
%3 = OpTypeFunction %void |
| 823 |
%6 = OpTypeHitObjectEXT |
| 824 |
%_ptr_Private_6 = OpTypePointer Private %6 |
| 825 |
%hObj = OpVariable %_ptr_Private_6 Private |
| 826 |
)"; |
| 827 |
ss << declarations; |
| 828 |
|
| 829 |
ss << R"( |
| 830 |
%main = OpFunction %void None %3 |
| 831 |
%5 = OpLabel |
| 832 |
)"; |
| 833 |
|
| 834 |
ss << body; |
| 835 |
|
| 836 |
ss << R"( |
| 837 |
OpReturn |
| 838 |
OpFunctionEnd |
| 839 |
)"; |
| 840 |
return ss.str(); |
| 841 |
} |
| 842 |
|
| 843 |
std::string GenerateReorderShaderCodeEXT(const std::string& body = "", |
| 844 |
const std::string& declarations = "", |
| 845 |
const std::string& extensions = "", |
| 846 |
const std::string& capabilties = "") { |
| 847 |
std::ostringstream ss; |
| 848 |
ss << R"( |
| 849 |
OpCapability RayTracingKHR |
| 850 |
OpCapability ShaderInvocationReorderEXT |
| 851 |
)"; |
| 852 |
ss << capabilties; |
| 853 |
ss << R"( OpExtension "SPV_KHR_ray_tracing" |
| 854 |
OpExtension "SPV_EXT_shader_invocation_reorder" |
| 855 |
)"; |
| 856 |
ss << extensions; |
| 857 |
ss << R"( |
| 858 |
%1 = OpExtInstImport "GLSL.std.450" |
| 859 |
OpMemoryModel Logical GLSL450 |
| 860 |
OpEntryPoint RayGenerationKHR %main "main" %attr %_ %hObj %payload %__0 %as %__1 |
| 861 |
OpSource GLSL 460 |
| 862 |
OpSourceExtension "GL_EXT_ray_tracing" |
| 863 |
OpSourceExtension "GL_EXT_shader_invocation_reorder" |
| 864 |
OpName %main "main" |
| 865 |
OpName %attr "attr" |
| 866 |
OpName %hBlock "hBlock" |
| 867 |
OpMemberName %hBlock 0 "attrval" |
| 868 |
OpName %_ "" |
| 869 |
OpName %hObj "hObj" |
| 870 |
OpName %payload "payload" |
| 871 |
OpName %pBlock "pBlock" |
| 872 |
OpMemberName %pBlock 0 "val1" |
| 873 |
OpMemberName %pBlock 1 "val2" |
| 874 |
OpName %__0 "" |
| 875 |
OpName %as "as" |
| 876 |
OpName %block "block" |
| 877 |
OpMemberName %block 0 "op" |
| 878 |
OpName %__1 "" |
| 879 |
OpDecorate %hBlock Block |
| 880 |
OpDecorate %pBlock Block |
| 881 |
OpDecorate %as DescriptorSet 0 |
| 882 |
OpDecorate %as Binding 0 |
| 883 |
OpMemberDecorate %block 0 Offset 0 |
| 884 |
OpDecorate %block Block |
| 885 |
OpDecorate %__1 DescriptorSet 0 |
| 886 |
OpDecorate %__1 Binding 1 |
| 887 |
%void = OpTypeVoid |
| 888 |
%3 = OpTypeFunction %void |
| 889 |
%float = OpTypeFloat 32 |
| 890 |
%v2float = OpTypeVector %float 2 |
| 891 |
%_ptr_HitObjectAttributeEXT_v2float = OpTypePointer HitObjectAttributeEXT %v2float |
| 892 |
%attr = OpVariable %_ptr_HitObjectAttributeEXT_v2float HitObjectAttributeEXT |
| 893 |
%float_1 = OpConstant %float 1 |
| 894 |
%11 = OpConstantComposite %v2float %float_1 %float_1 |
| 895 |
%hBlock = OpTypeStruct %float |
| 896 |
%_ptr_HitObjectAttributeEXT_hBlock = OpTypePointer HitObjectAttributeEXT %hBlock |
| 897 |
%_ = OpVariable %_ptr_HitObjectAttributeEXT_hBlock HitObjectAttributeEXT |
| 898 |
%int = OpTypeInt 32 1 |
| 899 |
%int_0 = OpConstant %int 0 |
| 900 |
%float_2 = OpConstant %float 2 |
| 901 |
%_ptr_HitObjectAttributeEXT_float = OpTypePointer HitObjectAttributeEXT %float |
| 902 |
%20 = OpTypeHitObjectEXT |
| 903 |
%_ptr_Private_20 = OpTypePointer Private %20 |
| 904 |
%hObj = OpVariable %_ptr_Private_20 Private |
| 905 |
%23 = OpTypeAccelerationStructureKHR |
| 906 |
%_ptr_UniformConstant_23 = OpTypePointer UniformConstant %23 |
| 907 |
%as = OpVariable %_ptr_UniformConstant_23 UniformConstant |
| 908 |
%v4float = OpTypeVector %float 4 |
| 909 |
%_ptr_RayPayloadKHR_v4float = OpTypePointer RayPayloadKHR %v4float |
| 910 |
%payload = OpVariable %_ptr_RayPayloadKHR_v4float RayPayloadKHR |
| 911 |
%pBlock = OpTypeStruct %v2float %v2float |
| 912 |
%_ptr_RayPayloadKHR_pBlock = OpTypePointer RayPayloadKHR %pBlock |
| 913 |
%__0 = OpVariable %_ptr_RayPayloadKHR_pBlock RayPayloadKHR |
| 914 |
%block = OpTypeStruct %float |
| 915 |
%_ptr_StorageBuffer_block = OpTypePointer StorageBuffer %block |
| 916 |
%__1 = OpVariable %_ptr_StorageBuffer_block StorageBuffer |
| 917 |
)"; |
| 918 |
|
| 919 |
ss << declarations; |
| 920 |
|
| 921 |
ss << R"( |
| 922 |
%main = OpFunction %void None %3 |
| 923 |
%5 = OpLabel |
| 924 |
)"; |
| 925 |
|
| 926 |
ss << body; |
| 927 |
|
| 928 |
ss << R"( |
| 929 |
OpReturn |
| 930 |
OpFunctionEnd)"; |
| 931 |
return ss.str(); |
| 932 |
} |
| 933 |
|
| 934 |
TEST_F(ValidateRayTracingReorderEXT, ReorderThreadWithHintEXT) { |
| 935 |
const std::string declarations = R"( |
| 936 |
%uint = OpTypeInt 32 0 |
| 937 |
%uint_4 = OpConstant %uint 4 |
| 938 |
)"; |
| 939 |
|
| 940 |
const std::string body = R"( |
| 941 |
OpReorderThreadWithHintEXT %uint_4 %uint_4 |
| 942 |
)"; |
| 943 |
|
| 944 |
CompileSuccessfully(GenerateReorderThreadCodeEXT(body, declarations).c_str(), |
| 945 |
SPV_ENV_VULKAN_1_2); |
| 946 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 947 |
} |
| 948 |
|
| 949 |
TEST_F(ValidateRayTracingReorderEXT, ReorderThreadWithHitObjectEXT) { |
| 950 |
const std::string declarations = R"( |
| 951 |
%uint = OpTypeInt 32 0 |
| 952 |
%uint_4 = OpConstant %uint 4 |
| 953 |
%uint_2 = OpConstant %uint 2 |
| 954 |
)"; |
| 955 |
|
| 956 |
const std::string body = R"( |
| 957 |
OpReorderThreadWithHitObjectEXT %hObj |
| 958 |
OpReorderThreadWithHitObjectEXT %hObj %uint_4 %uint_2 |
| 959 |
)"; |
| 960 |
|
| 961 |
CompileSuccessfully(GenerateReorderThreadCodeEXT(body, declarations).c_str(), |
| 962 |
SPV_ENV_VULKAN_1_2); |
| 963 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 964 |
} |
| 965 |
|
| 966 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectTraceRayEXT) { |
| 967 |
const std::string declarations = R"( |
| 968 |
%uint = OpTypeInt 32 0 |
| 969 |
%uint_1 = OpConstant %uint 1 |
| 970 |
%v3float = OpTypeVector %float 3 |
| 971 |
%float_0_5 = OpConstant %float 0.5 |
| 972 |
%31 = OpConstantComposite %v3float %float_0_5 %float_0_5 %float_0_5 |
| 973 |
%32 = OpConstantComposite %v3float %float_1 %float_1 %float_1 |
| 974 |
%int_1 = OpConstant %int 1 |
| 975 |
)"; |
| 976 |
|
| 977 |
const std::string body = R"( |
| 978 |
OpStore %attr %11 |
| 979 |
%26 = OpLoad %23 %as |
| 980 |
OpHitObjectTraceRayEXT %hObj %26 %uint_1 %uint_1 %uint_1 %uint_1 %uint_1 %31 %float_0_5 %32 %float_1 %payload |
| 981 |
)"; |
| 982 |
|
| 983 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 984 |
SPV_ENV_VULKAN_1_2); |
| 985 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 986 |
} |
| 987 |
|
| 988 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectTraceRayMotionEXT) { |
| 989 |
const std::string declarations = R"( |
| 990 |
%uint = OpTypeInt 32 0 |
| 991 |
%uint_1 = OpConstant %uint 1 |
| 992 |
%v3float = OpTypeVector %float 3 |
| 993 |
%float_0_5 = OpConstant %float 0.5 |
| 994 |
%31 = OpConstantComposite %v3float %float_0_5 %float_0_5 %float_0_5 |
| 995 |
%32 = OpConstantComposite %v3float %float_1 %float_1 %float_1 |
| 996 |
%float_10 = OpConstant %float 10 |
| 997 |
%int_2 = OpConstant %int 2 |
| 998 |
)"; |
| 999 |
|
| 1000 |
const std::string body = R"( |
| 1001 |
OpStore %attr %11 |
| 1002 |
%26 = OpLoad %23 %as |
| 1003 |
OpHitObjectTraceRayMotionEXT %hObj %26 %uint_1 %uint_1 %uint_1 %uint_1 %uint_1 %31 %float_0_5 %32 %float_1 %float_10 %__0 |
| 1004 |
)"; |
| 1005 |
|
| 1006 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1007 |
SPV_ENV_VULKAN_1_2); |
| 1008 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1009 |
} |
| 1010 |
|
| 1011 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectRecordEmptyEXT) { |
| 1012 |
const std::string body = R"( |
| 1013 |
OpHitObjectRecordEmptyEXT %hObj |
| 1014 |
)"; |
| 1015 |
|
| 1016 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body).c_str(), |
| 1017 |
SPV_ENV_VULKAN_1_2); |
| 1018 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1019 |
} |
| 1020 |
|
| 1021 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectRecordMissEXT) { |
| 1022 |
const std::string declarations = R"( |
| 1023 |
%uint = OpTypeInt 32 0 |
| 1024 |
%uint_1 = OpConstant %uint 1 |
| 1025 |
%v3float = OpTypeVector %float 3 |
| 1026 |
%float_0_5 = OpConstant %float 0.5 |
| 1027 |
%29 = OpConstantComposite %v3float %float_0_5 %float_0_5 %float_0_5 |
| 1028 |
%float_1_5 = OpConstant %float 1.5 |
| 1029 |
%31 = OpConstantComposite %v3float %float_1_5 %float_1_5 %float_1_5 |
| 1030 |
%float_5 = OpConstant %float 5 |
| 1031 |
)"; |
| 1032 |
|
| 1033 |
const std::string body = R"( |
| 1034 |
OpHitObjectRecordMissEXT %hObj %uint_1 %uint_1 %29 %float_2 %31 %float_5 |
| 1035 |
)"; |
| 1036 |
|
| 1037 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1038 |
SPV_ENV_VULKAN_1_2); |
| 1039 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1040 |
} |
| 1041 |
|
| 1042 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectIsHitEXT) { |
| 1043 |
const std::string declarations = R"( |
| 1044 |
%bool = OpTypeBool |
| 1045 |
%_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float |
| 1046 |
)"; |
| 1047 |
|
| 1048 |
const std::string body = R"( |
| 1049 |
%26 = OpHitObjectIsHitEXT %bool %hObj |
| 1050 |
OpSelectionMerge %28 None |
| 1051 |
OpBranchConditional %26 %27 %28 |
| 1052 |
%27 = OpLabel |
| 1053 |
%33 = OpAccessChain %_ptr_StorageBuffer_float %__1 %int_0 |
| 1054 |
OpStore %33 %float_1 |
| 1055 |
OpBranch %28 |
| 1056 |
%28 = OpLabel |
| 1057 |
)"; |
| 1058 |
|
| 1059 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1060 |
SPV_ENV_VULKAN_1_2); |
| 1061 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1062 |
} |
| 1063 |
|
| 1064 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectIsMissEXT) { |
| 1065 |
const std::string declarations = R"( |
| 1066 |
%bool = OpTypeBool |
| 1067 |
%_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float |
| 1068 |
)"; |
| 1069 |
|
| 1070 |
const std::string body = R"( |
| 1071 |
%26 = OpHitObjectIsMissEXT %bool %hObj |
| 1072 |
OpSelectionMerge %28 None |
| 1073 |
OpBranchConditional %26 %27 %28 |
| 1074 |
%27 = OpLabel |
| 1075 |
%33 = OpAccessChain %_ptr_StorageBuffer_float %__1 %int_0 |
| 1076 |
OpStore %33 %float_1 |
| 1077 |
OpBranch %28 |
| 1078 |
%28 = OpLabel |
| 1079 |
)"; |
| 1080 |
|
| 1081 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1082 |
SPV_ENV_VULKAN_1_2); |
| 1083 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1084 |
} |
| 1085 |
|
| 1086 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectIsEmptyEXT) { |
| 1087 |
const std::string declarations = R"( |
| 1088 |
%bool = OpTypeBool |
| 1089 |
%_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float |
| 1090 |
)"; |
| 1091 |
|
| 1092 |
const std::string body = R"( |
| 1093 |
%26 = OpHitObjectIsEmptyEXT %bool %hObj |
| 1094 |
OpSelectionMerge %28 None |
| 1095 |
OpBranchConditional %26 %27 %28 |
| 1096 |
%27 = OpLabel |
| 1097 |
%33 = OpAccessChain %_ptr_StorageBuffer_float %__1 %int_0 |
| 1098 |
OpStore %33 %float_1 |
| 1099 |
OpBranch %28 |
| 1100 |
%28 = OpLabel |
| 1101 |
)"; |
| 1102 |
|
| 1103 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1104 |
SPV_ENV_VULKAN_1_2); |
| 1105 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1106 |
} |
| 1107 |
|
| 1108 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectGetGeometryIndexEXT) { |
| 1109 |
const std::string declarations = R"( |
| 1110 |
%_ptr_Function_int = OpTypePointer Function %int |
| 1111 |
)"; |
| 1112 |
|
| 1113 |
const std::string body = R"( |
| 1114 |
%id = OpVariable %_ptr_Function_int Function |
| 1115 |
%12 = OpHitObjectGetGeometryIndexEXT %int %hObj |
| 1116 |
OpStore %id %12 |
| 1117 |
)"; |
| 1118 |
|
| 1119 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1120 |
SPV_ENV_VULKAN_1_2); |
| 1121 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1122 |
} |
| 1123 |
|
| 1124 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectGetPrimitiveIndexEXT) { |
| 1125 |
const std::string declarations = R"( |
| 1126 |
%_ptr_Function_int = OpTypePointer Function %int |
| 1127 |
)"; |
| 1128 |
|
| 1129 |
const std::string body = R"( |
| 1130 |
%id = OpVariable %_ptr_Function_int Function |
| 1131 |
%12 = OpHitObjectGetPrimitiveIndexEXT %int %hObj |
| 1132 |
OpStore %id %12 |
| 1133 |
)"; |
| 1134 |
|
| 1135 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1136 |
SPV_ENV_VULKAN_1_2); |
| 1137 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1138 |
} |
| 1139 |
|
| 1140 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectGetInstanceIdEXT) { |
| 1141 |
const std::string declarations = R"( |
| 1142 |
%_ptr_Function_int = OpTypePointer Function %int |
| 1143 |
)"; |
| 1144 |
|
| 1145 |
const std::string body = R"( |
| 1146 |
%id = OpVariable %_ptr_Function_int Function |
| 1147 |
%12 = OpHitObjectGetInstanceIdEXT %int %hObj |
| 1148 |
OpStore %id %12 |
| 1149 |
)"; |
| 1150 |
|
| 1151 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1152 |
SPV_ENV_VULKAN_1_2); |
| 1153 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1154 |
} |
| 1155 |
|
| 1156 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectGetInstanceCustomIndexEXT) { |
| 1157 |
const std::string declarations = R"( |
| 1158 |
%_ptr_Function_int = OpTypePointer Function %int |
| 1159 |
)"; |
| 1160 |
|
| 1161 |
const std::string body = R"( |
| 1162 |
%id = OpVariable %_ptr_Function_int Function |
| 1163 |
%12 = OpHitObjectGetInstanceCustomIndexEXT %int %hObj |
| 1164 |
OpStore %id %12 |
| 1165 |
)"; |
| 1166 |
|
| 1167 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1168 |
SPV_ENV_VULKAN_1_2); |
| 1169 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1170 |
} |
| 1171 |
|
| 1172 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectGetHitKindEXT) { |
| 1173 |
const std::string declarations = R"( |
| 1174 |
%uint = OpTypeInt 32 0 |
| 1175 |
%_ptr_Function_uint = OpTypePointer Function %uint |
| 1176 |
)"; |
| 1177 |
|
| 1178 |
const std::string body = R"( |
| 1179 |
%uid = OpVariable %_ptr_Function_uint Function |
| 1180 |
%12 = OpHitObjectGetHitKindEXT %uint %hObj |
| 1181 |
OpStore %uid %12 |
| 1182 |
)"; |
| 1183 |
|
| 1184 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1185 |
SPV_ENV_VULKAN_1_2); |
| 1186 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1187 |
} |
| 1188 |
|
| 1189 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectGetCurrentTimeEXT) { |
| 1190 |
const std::string declarations = R"( |
| 1191 |
%_ptr_Function_float = OpTypePointer Function %float |
| 1192 |
)"; |
| 1193 |
|
| 1194 |
const std::string body = R"( |
| 1195 |
%time = OpVariable %_ptr_Function_float Function |
| 1196 |
%12 = OpHitObjectGetCurrentTimeEXT %float %hObj |
| 1197 |
OpStore %time %12 |
| 1198 |
)"; |
| 1199 |
|
| 1200 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1201 |
SPV_ENV_VULKAN_1_2); |
| 1202 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1203 |
} |
| 1204 |
|
| 1205 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectGetObjectRayOriginEXT) { |
| 1206 |
const std::string declarations = R"( |
| 1207 |
%v3float = OpTypeVector %float 3 |
| 1208 |
%_ptr_Function_v3float = OpTypePointer Function %v3float |
| 1209 |
)"; |
| 1210 |
|
| 1211 |
const std::string body = R"( |
| 1212 |
%oorig = OpVariable %_ptr_Function_v3float Function |
| 1213 |
%13 = OpHitObjectGetObjectRayOriginEXT %v3float %hObj |
| 1214 |
OpStore %oorig %13 |
| 1215 |
)"; |
| 1216 |
|
| 1217 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1218 |
SPV_ENV_VULKAN_1_2); |
| 1219 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1220 |
} |
| 1221 |
|
| 1222 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectGetObjectRayDirectionEXT) { |
| 1223 |
const std::string declarations = R"( |
| 1224 |
%v3float = OpTypeVector %float 3 |
| 1225 |
%_ptr_Function_v3float = OpTypePointer Function %v3float |
| 1226 |
)"; |
| 1227 |
|
| 1228 |
const std::string body = R"( |
| 1229 |
%odir = OpVariable %_ptr_Function_v3float Function |
| 1230 |
%13 = OpHitObjectGetObjectRayDirectionEXT %v3float %hObj |
| 1231 |
OpStore %odir %13 |
| 1232 |
)"; |
| 1233 |
|
| 1234 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1235 |
SPV_ENV_VULKAN_1_2); |
| 1236 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1237 |
} |
| 1238 |
|
| 1239 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectGetRayTMaxEXT) { |
| 1240 |
const std::string declarations = R"( |
| 1241 |
%_ptr_Function_float = OpTypePointer Function %float |
| 1242 |
)"; |
| 1243 |
|
| 1244 |
const std::string body = R"( |
| 1245 |
%tmax = OpVariable %_ptr_Function_float Function |
| 1246 |
%12 = OpHitObjectGetRayTMaxEXT %float %hObj |
| 1247 |
OpStore %tmax %12 |
| 1248 |
)"; |
| 1249 |
|
| 1250 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1251 |
SPV_ENV_VULKAN_1_2); |
| 1252 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1253 |
} |
| 1254 |
|
| 1255 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectGetRayTMinEXT) { |
| 1256 |
const std::string declarations = R"( |
| 1257 |
%_ptr_Function_float = OpTypePointer Function %float |
| 1258 |
)"; |
| 1259 |
|
| 1260 |
const std::string body = R"( |
| 1261 |
%tmin = OpVariable %_ptr_Function_float Function |
| 1262 |
%12 = OpHitObjectGetRayTMinEXT %float %hObj |
| 1263 |
OpStore %tmin %12 |
| 1264 |
)"; |
| 1265 |
|
| 1266 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1267 |
SPV_ENV_VULKAN_1_2); |
| 1268 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1269 |
} |
| 1270 |
|
| 1271 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectGetRayFlagsEXT) { |
| 1272 |
const std::string declarations = R"( |
| 1273 |
%_ptr_Function_int = OpTypePointer Function %int |
| 1274 |
)"; |
| 1275 |
|
| 1276 |
const std::string body = R"( |
| 1277 |
%flags = OpVariable %_ptr_Function_int Function |
| 1278 |
%12 = OpHitObjectGetRayFlagsEXT %int %hObj |
| 1279 |
OpStore %flags %12 |
| 1280 |
)"; |
| 1281 |
|
| 1282 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1283 |
SPV_ENV_VULKAN_1_2); |
| 1284 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1285 |
} |
| 1286 |
|
| 1287 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectGetWorldRayOriginEXT) { |
| 1288 |
const std::string declarations = R"( |
| 1289 |
%v3float = OpTypeVector %float 3 |
| 1290 |
%_ptr_Function_v3float = OpTypePointer Function %v3float |
| 1291 |
)"; |
| 1292 |
|
| 1293 |
const std::string body = R"( |
| 1294 |
%orig = OpVariable %_ptr_Function_v3float Function |
| 1295 |
%13 = OpHitObjectGetWorldRayOriginEXT %v3float %hObj |
| 1296 |
OpStore %orig %13 |
| 1297 |
)"; |
| 1298 |
|
| 1299 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1300 |
SPV_ENV_VULKAN_1_2); |
| 1301 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1302 |
} |
| 1303 |
|
| 1304 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectGetWorldRayDirectionEXT) { |
| 1305 |
const std::string declarations = R"( |
| 1306 |
%v3float = OpTypeVector %float 3 |
| 1307 |
%_ptr_Function_v3float = OpTypePointer Function %v3float |
| 1308 |
)"; |
| 1309 |
|
| 1310 |
const std::string body = R"( |
| 1311 |
%dir = OpVariable %_ptr_Function_v3float Function |
| 1312 |
%13 = OpHitObjectGetWorldRayDirectionEXT %v3float %hObj |
| 1313 |
OpStore %dir %13 |
| 1314 |
)"; |
| 1315 |
|
| 1316 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1317 |
SPV_ENV_VULKAN_1_2); |
| 1318 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1319 |
} |
| 1320 |
|
| 1321 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectGetObjectToWorldEXT) { |
| 1322 |
const std::string declarations = R"( |
| 1323 |
%v3float = OpTypeVector %float 3 |
| 1324 |
%mat4v3float = OpTypeMatrix %v3float 4 |
| 1325 |
%_ptr_Function_mat4v3float = OpTypePointer Function %mat4v3float |
| 1326 |
)"; |
| 1327 |
|
| 1328 |
const std::string body = R"( |
| 1329 |
%otw = OpVariable %_ptr_Function_mat4v3float Function |
| 1330 |
%14 = OpHitObjectGetObjectToWorldEXT %mat4v3float %hObj |
| 1331 |
OpStore %otw %14 |
| 1332 |
)"; |
| 1333 |
|
| 1334 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1335 |
SPV_ENV_VULKAN_1_2); |
| 1336 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1337 |
} |
| 1338 |
|
| 1339 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectGetWorldToObjectEXT) { |
| 1340 |
const std::string declarations = R"( |
| 1341 |
%v3float = OpTypeVector %float 3 |
| 1342 |
%mat4v3float = OpTypeMatrix %v3float 4 |
| 1343 |
%_ptr_Function_mat4v3float = OpTypePointer Function %mat4v3float |
| 1344 |
)"; |
| 1345 |
|
| 1346 |
const std::string body = R"( |
| 1347 |
%wto = OpVariable %_ptr_Function_mat4v3float Function |
| 1348 |
%14 = OpHitObjectGetWorldToObjectEXT %mat4v3float %hObj |
| 1349 |
OpStore %wto %14 |
| 1350 |
)"; |
| 1351 |
|
| 1352 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1353 |
SPV_ENV_VULKAN_1_2); |
| 1354 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1355 |
} |
| 1356 |
|
| 1357 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectGetShaderRecordBufferHandleEXT) { |
| 1358 |
const std::string declarations = R"( |
| 1359 |
%uint = OpTypeInt 32 0 |
| 1360 |
%v2uint = OpTypeVector %uint 2 |
| 1361 |
%_ptr_Function_v2uint = OpTypePointer Function %v2uint |
| 1362 |
)"; |
| 1363 |
|
| 1364 |
const std::string body = R"( |
| 1365 |
%handle = OpVariable %_ptr_Function_v2uint Function |
| 1366 |
%13 = OpHitObjectGetShaderRecordBufferHandleEXT %v2uint %hObj |
| 1367 |
OpStore %handle %13 |
| 1368 |
)"; |
| 1369 |
|
| 1370 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1371 |
SPV_ENV_VULKAN_1_2); |
| 1372 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1373 |
} |
| 1374 |
|
| 1375 |
TEST_F(ValidateRayTracingReorderEXT, |
| 1376 |
HitObjectGetShaderBindingTableRecordIndexEXT) { |
| 1377 |
const std::string declarations = R"( |
| 1378 |
%uint = OpTypeInt 32 0 |
| 1379 |
%_ptr_Function_uint = OpTypePointer Function %uint |
| 1380 |
)"; |
| 1381 |
|
| 1382 |
const std::string body = R"( |
| 1383 |
%rid = OpVariable %_ptr_Function_uint Function |
| 1384 |
%12 = OpHitObjectGetShaderBindingTableRecordIndexEXT %uint %hObj |
| 1385 |
OpStore %rid %12 |
| 1386 |
)"; |
| 1387 |
|
| 1388 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1389 |
SPV_ENV_VULKAN_1_2); |
| 1390 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1391 |
} |
| 1392 |
|
| 1393 |
TEST_F(ValidateRayTracingReorderEXT, |
| 1394 |
HitObjectSetShaderBindingTableRecordIndexEXT) { |
| 1395 |
const std::string declarations = R"( |
| 1396 |
%uint = OpTypeInt 32 0 |
| 1397 |
%uint_5 = OpConstant %uint 5 |
| 1398 |
)"; |
| 1399 |
|
| 1400 |
const std::string body = R"( |
| 1401 |
OpHitObjectSetShaderBindingTableRecordIndexEXT %hObj %uint_5 |
| 1402 |
)"; |
| 1403 |
|
| 1404 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1405 |
SPV_ENV_VULKAN_1_2); |
| 1406 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1407 |
} |
| 1408 |
|
| 1409 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectGetAttributesEXT) { |
| 1410 |
const std::string body = R"( |
| 1411 |
OpHitObjectGetAttributesEXT %hObj %attr |
| 1412 |
)"; |
| 1413 |
|
| 1414 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body).c_str(), |
| 1415 |
SPV_ENV_VULKAN_1_2); |
| 1416 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1417 |
} |
| 1418 |
|
| 1419 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectExecuteShaderEXT) { |
| 1420 |
const std::string body = R"( |
| 1421 |
OpHitObjectExecuteShaderEXT %hObj %payload |
| 1422 |
)"; |
| 1423 |
|
| 1424 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body).c_str(), |
| 1425 |
SPV_ENV_VULKAN_1_2); |
| 1426 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1427 |
} |
| 1428 |
|
| 1429 |
TEST_F(ValidateRayTracingReorderEXT, |
| 1430 |
HitObjectGetIntersectionTriangleVertexPositionsEXT) { |
| 1431 |
const std::string declarations = R"( |
| 1432 |
%v3float = OpTypeVector %float 3 |
| 1433 |
%uint = OpTypeInt 32 0 |
| 1434 |
%uint_3 = OpConstant %uint 3 |
| 1435 |
%arr_3_v3float = OpTypeArray %v3float %uint_3 |
| 1436 |
%_ptr_Function_arr_3_v3float = OpTypePointer Function %arr_3_v3float |
| 1437 |
)"; |
| 1438 |
|
| 1439 |
const std::string body = R"( |
| 1440 |
%vertices = OpVariable %_ptr_Function_arr_3_v3float Function |
| 1441 |
%result = OpHitObjectGetIntersectionTriangleVertexPositionsEXT %arr_3_v3float %hObj |
| 1442 |
OpStore %vertices %result |
| 1443 |
)"; |
| 1444 |
|
| 1445 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1446 |
SPV_ENV_VULKAN_1_2); |
| 1447 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1448 |
} |
| 1449 |
|
| 1450 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectRecordFromQueryEXT) { |
| 1451 |
const std::string cap = R"( |
| 1452 |
OpCapability RayQueryKHR |
| 1453 |
)"; |
| 1454 |
const std::string extensions = R"( |
| 1455 |
OpExtension "SPV_KHR_ray_query" |
| 1456 |
)"; |
| 1457 |
const std::string declarations = R"( |
| 1458 |
%uint = OpTypeInt 32 0 |
| 1459 |
%uint_5 = OpConstant %uint 5 |
| 1460 |
%rayquery_type = OpTypeRayQueryKHR |
| 1461 |
%_ptr_Function_rayquery = OpTypePointer Function %rayquery_type |
| 1462 |
)"; |
| 1463 |
|
| 1464 |
const std::string body = R"( |
| 1465 |
%ray_query = OpVariable %_ptr_Function_rayquery Function |
| 1466 |
OpHitObjectRecordFromQueryEXT %hObj %ray_query %uint_5 %attr |
| 1467 |
)"; |
| 1468 |
|
| 1469 |
CompileSuccessfully( |
| 1470 |
GenerateReorderShaderCodeEXT(body, declarations, extensions, cap).c_str(), |
| 1471 |
SPV_ENV_VULKAN_1_2); |
| 1472 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1473 |
} |
| 1474 |
|
| 1475 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectRecordMissMotionEXT) { |
| 1476 |
const std::string declarations = R"( |
| 1477 |
%uint = OpTypeInt 32 0 |
| 1478 |
%uint_1 = OpConstant %uint 1 |
| 1479 |
%v3float = OpTypeVector %float 3 |
| 1480 |
%float_0_5 = OpConstant %float 0.5 |
| 1481 |
%29 = OpConstantComposite %v3float %float_0_5 %float_0_5 %float_0_5 |
| 1482 |
%float_1_5 = OpConstant %float 1.5 |
| 1483 |
%31 = OpConstantComposite %v3float %float_1_5 %float_1_5 %float_1_5 |
| 1484 |
%float_5 = OpConstant %float 5 |
| 1485 |
%float_10 = OpConstant %float 10 |
| 1486 |
)"; |
| 1487 |
|
| 1488 |
const std::string body = R"( |
| 1489 |
OpHitObjectRecordMissMotionEXT %hObj %uint_1 %uint_1 %29 %float_2 %31 %float_5 %float_10 |
| 1490 |
)"; |
| 1491 |
|
| 1492 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1493 |
SPV_ENV_VULKAN_1_2); |
| 1494 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1495 |
} |
| 1496 |
|
| 1497 |
// Fused Hit Object Instructions Tests |
| 1498 |
|
| 1499 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectReorderExecuteShaderEXT) { |
| 1500 |
const std::string declarations = R"( |
| 1501 |
%uint = OpTypeInt 32 0 |
| 1502 |
%uint_4 = OpConstant %uint 4 |
| 1503 |
%uint_2 = OpConstant %uint 2 |
| 1504 |
)"; |
| 1505 |
|
| 1506 |
const std::string body = R"( |
| 1507 |
OpHitObjectReorderExecuteShaderEXT %hObj %payload |
| 1508 |
OpHitObjectReorderExecuteShaderEXT %hObj %payload %uint_4 %uint_2 |
| 1509 |
)"; |
| 1510 |
|
| 1511 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1512 |
SPV_ENV_VULKAN_1_2); |
| 1513 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1514 |
} |
| 1515 |
|
| 1516 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectTraceReorderExecuteEXT) { |
| 1517 |
const std::string declarations = R"( |
| 1518 |
%uint = OpTypeInt 32 0 |
| 1519 |
%uint_1 = OpConstant %uint 1 |
| 1520 |
%uint_4 = OpConstant %uint 4 |
| 1521 |
%uint_2 = OpConstant %uint 2 |
| 1522 |
%v3float = OpTypeVector %float 3 |
| 1523 |
%float_0_5 = OpConstant %float 0.5 |
| 1524 |
%31 = OpConstantComposite %v3float %float_0_5 %float_0_5 %float_0_5 |
| 1525 |
%32 = OpConstantComposite %v3float %float_1 %float_1 %float_1 |
| 1526 |
%int_1 = OpConstant %int 1 |
| 1527 |
)"; |
| 1528 |
|
| 1529 |
const std::string body = R"( |
| 1530 |
OpStore %attr %11 |
| 1531 |
%26 = OpLoad %23 %as |
| 1532 |
OpHitObjectTraceReorderExecuteEXT %hObj %26 %uint_1 %uint_1 %uint_1 %uint_1 %uint_1 %31 %float_0_5 %32 %float_1 %payload |
| 1533 |
OpHitObjectTraceReorderExecuteEXT %hObj %26 %uint_1 %uint_1 %uint_1 %uint_1 %uint_1 %31 %float_0_5 %32 %float_1 %payload %uint_4 %uint_2 |
| 1534 |
)"; |
| 1535 |
|
| 1536 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1537 |
SPV_ENV_VULKAN_1_2); |
| 1538 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1539 |
} |
| 1540 |
|
| 1541 |
TEST_F(ValidateRayTracingReorderEXT, HitObjectTraceMotionReorderExecuteEXT) { |
| 1542 |
const std::string declarations = R"( |
| 1543 |
%uint = OpTypeInt 32 0 |
| 1544 |
%uint_1 = OpConstant %uint 1 |
| 1545 |
%uint_4 = OpConstant %uint 4 |
| 1546 |
%uint_2 = OpConstant %uint 2 |
| 1547 |
%v3float = OpTypeVector %float 3 |
| 1548 |
%float_0_5 = OpConstant %float 0.5 |
| 1549 |
%31 = OpConstantComposite %v3float %float_0_5 %float_0_5 %float_0_5 |
| 1550 |
%32 = OpConstantComposite %v3float %float_1 %float_1 %float_1 |
| 1551 |
%float_10 = OpConstant %float 10 |
| 1552 |
%int_2 = OpConstant %int 2 |
| 1553 |
)"; |
| 1554 |
|
| 1555 |
const std::string body = R"( |
| 1556 |
OpStore %attr %11 |
| 1557 |
%26 = OpLoad %23 %as |
| 1558 |
OpHitObjectTraceMotionReorderExecuteEXT %hObj %26 %uint_1 %uint_1 %uint_1 %uint_1 %uint_1 %31 %float_0_5 %32 %float_1 %float_10 %__0 |
| 1559 |
OpHitObjectTraceMotionReorderExecuteEXT %hObj %26 %uint_1 %uint_1 %uint_1 %uint_1 %uint_1 %31 %float_0_5 %32 %float_1 %float_10 %__0 %uint_4 %uint_2 |
| 1560 |
)"; |
| 1561 |
|
| 1562 |
CompileSuccessfully(GenerateReorderShaderCodeEXT(body, declarations).c_str(), |
| 1563 |
SPV_ENV_VULKAN_1_2); |
| 1564 |
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2)); |
| 1565 |
} |
| 1566 |
|
| 1567 |
} // namespace |
| 1568 |
} // namespace val |
| 1569 |
} // namespace spvtools |