Add validation support for SPV_NV_shader_invocation_reorder. (#4979)

Co-authored-by: Pankaj Mistry <pmistry@nvidia.com>
This commit is contained in:
alelenv 2022-11-24 06:50:45 -08:00 committed by GitHub
parent 597631b693
commit f33d152400
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 1274 additions and 4 deletions

View File

@ -71,6 +71,7 @@ SPVTOOLS_SRC_FILES := \
source/val/validate_primitives.cpp \
source/val/validate_ray_query.cpp \
source/val/validate_ray_tracing.cpp \
source/val/validate_ray_tracing_reorder.cpp \
source/val/validate_scopes.cpp \
source/val/validate_small_type_uses.cpp \
source/val/validate_type.cpp

View File

@ -328,6 +328,7 @@ set(SPIRV_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/val/validate_primitives.cpp
${CMAKE_CURRENT_SOURCE_DIR}/val/validate_ray_query.cpp
${CMAKE_CURRENT_SOURCE_DIR}/val/validate_ray_tracing.cpp
${CMAKE_CURRENT_SOURCE_DIR}/val/validate_ray_tracing_reorder.cpp
${CMAKE_CURRENT_SOURCE_DIR}/val/validate_scopes.cpp
${CMAKE_CURRENT_SOURCE_DIR}/val/validate_small_type_uses.cpp
${CMAKE_CURRENT_SOURCE_DIR}/val/validate_type.cpp

View File

@ -342,6 +342,7 @@ int32_t spvOpcodeGeneratesType(spv::Op op) {
// case spv::Op::OpTypeAccelerationStructureKHR: covered by
// spv::Op::OpTypeAccelerationStructureNV
case spv::Op::OpTypeRayQueryKHR:
case spv::Op::OpTypeHitObjectNV:
return true;
default:
// In particular, OpTypeForwardPointer does not generate a type,

View File

@ -482,6 +482,7 @@ void IRContext::AddCombinatorsForCapability(uint32_t capability) {
(uint32_t)spv::Op::OpTypeAccelerationStructureNV,
(uint32_t)spv::Op::OpTypeAccelerationStructureKHR,
(uint32_t)spv::Op::OpTypeRayQueryKHR,
(uint32_t)spv::Op::OpTypeHitObjectNV,
(uint32_t)spv::Op::OpTypeArray,
(uint32_t)spv::Op::OpTypeRuntimeArray,
(uint32_t)spv::Op::OpTypeStruct,

View File

@ -53,7 +53,8 @@ inline bool IsTypeInst(spv::Op opcode) {
opcode == spv::Op::OpTypeAccelerationStructureNV ||
opcode == spv::Op::OpTypeAccelerationStructureKHR ||
opcode == spv::Op::OpTypeRayQueryKHR ||
opcode == spv::Op::OpTypeCooperativeMatrixNV;
opcode == spv::Op::OpTypeCooperativeMatrixNV ||
opcode == spv::Op::OpTypeHitObjectNV;
}
inline bool IsConstantInst(spv::Op opcode) {
return (opcode >= spv::Op::OpConstantTrue &&

View File

@ -234,6 +234,7 @@ uint32_t TypeManager::GetTypeInstruction(const Type* type) {
DefineParameterlessCase(NamedBarrier);
DefineParameterlessCase(AccelerationStructureNV);
DefineParameterlessCase(RayQueryKHR);
DefineParameterlessCase(HitObjectNV);
#undef DefineParameterlessCase
case Type::kInteger:
typeInst = MakeUnique<Instruction>(
@ -527,6 +528,7 @@ Type* TypeManager::RebuildType(const Type& type) {
DefineNoSubtypeCase(NamedBarrier);
DefineNoSubtypeCase(AccelerationStructureNV);
DefineNoSubtypeCase(RayQueryKHR);
DefineNoSubtypeCase(HitObjectNV);
#undef DefineNoSubtypeCase
case Type::kVector: {
const Vector* vec_ty = type.AsVector();
@ -864,6 +866,9 @@ Type* TypeManager::RecordIfTypeDefinition(const Instruction& inst) {
case spv::Op::OpTypeRayQueryKHR:
type = new RayQueryKHR();
break;
case spv::Op::OpTypeHitObjectNV:
type = new HitObjectNV();
break;
default:
SPIRV_UNIMPLEMENTED(consumer_, "unhandled type");
break;

View File

@ -131,6 +131,7 @@ std::unique_ptr<Type> Type::Clone() const {
DeclareKindCase(AccelerationStructureNV);
DeclareKindCase(CooperativeMatrixNV);
DeclareKindCase(RayQueryKHR);
DeclareKindCase(HitObjectNV);
#undef DeclareKindCase
default:
assert(false && "Unhandled type");
@ -177,6 +178,7 @@ bool Type::operator==(const Type& other) const {
DeclareKindCase(AccelerationStructureNV);
DeclareKindCase(CooperativeMatrixNV);
DeclareKindCase(RayQueryKHR);
DeclareKindCase(HitObjectNV);
#undef DeclareKindCase
default:
assert(false && "Unhandled type");
@ -231,6 +233,7 @@ size_t Type::ComputeHashValue(size_t hash, SeenTypes* seen) const {
DeclareKindCase(AccelerationStructureNV);
DeclareKindCase(CooperativeMatrixNV);
DeclareKindCase(RayQueryKHR);
DeclareKindCase(HitObjectNV);
#undef DeclareKindCase
default:
assert(false && "Unhandled type");

View File

@ -61,6 +61,7 @@ class NamedBarrier;
class AccelerationStructureNV;
class CooperativeMatrixNV;
class RayQueryKHR;
class HitObjectNV;
// Abstract class for a SPIR-V type. It has a bunch of As<sublcass>() methods,
// which is used as a way to probe the actual <subclass>.
@ -100,6 +101,7 @@ class Type {
kAccelerationStructureNV,
kCooperativeMatrixNV,
kRayQueryKHR,
kHitObjectNV,
kLast
};
@ -196,6 +198,7 @@ class Type {
DeclareCastMethod(AccelerationStructureNV)
DeclareCastMethod(CooperativeMatrixNV)
DeclareCastMethod(RayQueryKHR)
DeclareCastMethod(HitObjectNV)
#undef DeclareCastMethod
protected:
@ -648,6 +651,7 @@ DefineParameterlessType(PipeStorage, pipe_storage);
DefineParameterlessType(NamedBarrier, named_barrier);
DefineParameterlessType(AccelerationStructureNV, accelerationStructureNV);
DefineParameterlessType(RayQueryKHR, rayQueryKHR);
DefineParameterlessType(HitObjectNV, hitObjectNV);
#undef DefineParameterlessType
} // namespace analysis

View File

@ -365,6 +365,7 @@ spv_result_t ValidateBinaryUsingContextAndValidationState(
if (auto error = LiteralsPass(*vstate, &instruction)) return error;
if (auto error = RayQueryPass(*vstate, &instruction)) return error;
if (auto error = RayTracingPass(*vstate, &instruction)) return error;
if (auto error = RayReorderNVPass(*vstate, &instruction)) return error;
if (auto error = MeshShadingPass(*vstate, &instruction)) return error;
}

View File

@ -203,6 +203,9 @@ spv_result_t RayQueryPass(ValidationState_t& _, const Instruction* inst);
/// Validates correctness of ray tracing instructions.
spv_result_t RayTracingPass(ValidationState_t& _, const Instruction* inst);
/// Validates correctness of shader execution reorder instructions.
spv_result_t RayReorderNVPass(ValidationState_t& _, const Instruction* inst);
/// Validates correctness of mesh shading instructions.
spv_result_t MeshShadingPass(ValidationState_t& _, const Instruction* inst);

View File

@ -200,7 +200,8 @@ spv_result_t ValidateDecorationTarget(ValidationState_t& _, spv::Decoration dec,
sc != spv::StorageClass::HitAttributeKHR &&
sc != spv::StorageClass::CallableDataKHR &&
sc != spv::StorageClass::IncomingCallableDataKHR &&
sc != spv::StorageClass::ShaderRecordBufferKHR) {
sc != spv::StorageClass::ShaderRecordBufferKHR &&
sc != spv::StorageClass::HitObjectAttributeNV) {
return _.diag(SPV_ERROR_INVALID_ID, target)
<< _.VkErrorID(6672) << _.SpvDecorationString(dec)
<< " decoration must not be applied to this storage class";

View File

@ -757,7 +757,8 @@ spv_result_t ValidateExtension(ValidationState_t& _, const Instruction* inst) {
std::string extension = GetExtensionString(&(inst->c_inst()));
if (extension ==
ExtensionToString(kSPV_KHR_workgroup_memory_explicit_layout) ||
extension == ExtensionToString(kSPV_EXT_mesh_shader)) {
extension == ExtensionToString(kSPV_EXT_mesh_shader) ||
extension == ExtensionToString(kSPV_NV_shader_invocation_reorder)) {
return _.diag(SPV_ERROR_WRONG_VERSION, inst)
<< extension << " extension requires SPIR-V version 1.4 or later.";
}

View File

@ -447,7 +447,8 @@ spv_result_t ValidateVariable(ValidationState_t& _, const Instruction* inst) {
storage_class != spv::StorageClass::HitAttributeKHR &&
storage_class != spv::StorageClass::CallableDataKHR &&
storage_class != spv::StorageClass::IncomingCallableDataKHR &&
storage_class != spv::StorageClass::TaskPayloadWorkgroupEXT) {
storage_class != spv::StorageClass::TaskPayloadWorkgroupEXT &&
storage_class != spv::StorageClass::HitObjectAttributeNV) {
bool storage_input_or_output = storage_class == spv::StorageClass::Input ||
storage_class == spv::StorageClass::Output;
bool builtin = false;
@ -656,6 +657,11 @@ spv_result_t ValidateVariable(ValidationState_t& _, const Instruction* inst) {
<< "OpVariable, <id> " << _.getIdName(inst->id())
<< ", initializer are not allowed for Input";
}
if (storage_class == spv::StorageClass::HitObjectAttributeNV) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpVariable, <id> " << _.getIdName(inst->id())
<< ", initializer are not allowed for HitObjectAttributeNV";
}
}
if (storage_class == spv::StorageClass::PhysicalStorageBuffer) {

View File

@ -0,0 +1,623 @@
// Copyright (c) 2022 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Validates ray tracing instructions from SPV_NV_shader_execution_reorder
#include "source/opcode.h"
#include "source/val/instruction.h"
#include "source/val/validate.h"
#include "source/val/validation_state.h"
namespace spvtools {
namespace val {
static const uint32_t KRayParamInvalidId = std::numeric_limits<uint32_t>::max();
spv_result_t ValidateHitObjectPointer(ValidationState_t& _,
const Instruction* inst,
uint32_t hit_object_index) {
const uint32_t hit_object_id = inst->GetOperandAs<uint32_t>(hit_object_index);
auto variable = _.FindDef(hit_object_id);
const auto var_opcode = variable->opcode();
if (!variable || (var_opcode != spv::Op::OpVariable &&
var_opcode != spv::Op::OpFunctionParameter &&
var_opcode != spv::Op::OpAccessChain)) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Hit Object must be a memory object declaration";
}
auto pointer = _.FindDef(variable->GetOperandAs<uint32_t>(0));
if (!pointer || pointer->opcode() != spv::Op::OpTypePointer) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Hit Object must be a pointer";
}
auto type = _.FindDef(pointer->GetOperandAs<uint32_t>(2));
if (!type || type->opcode() != spv::Op::OpTypeHitObjectNV) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Type must be OpTypeHitObjectNV";
}
return SPV_SUCCESS;
}
spv_result_t ValidateHitObjectInstructionCommonParameters(
ValidationState_t& _, const Instruction* inst,
uint32_t acceleration_struct_index, uint32_t instance_id_index,
uint32_t primtive_id_index, uint32_t geometry_index,
uint32_t ray_flags_index, uint32_t cull_mask_index, uint32_t hit_kind_index,
uint32_t sbt_index, uint32_t sbt_offset_index, uint32_t sbt_stride_index,
uint32_t sbt_record_offset_index, uint32_t sbt_record_stride_index,
uint32_t miss_index, uint32_t ray_origin_index, uint32_t ray_tmin_index,
uint32_t ray_direction_index, uint32_t ray_tmax_index,
uint32_t payload_index, uint32_t hit_object_attr_index) {
auto isValidId = [](uint32_t spvid) { return spvid < KRayParamInvalidId; };
if (isValidId(acceleration_struct_index) &&
_.GetIdOpcode(_.GetOperandTypeId(inst, acceleration_struct_index)) !=
spv::Op::OpTypeAccelerationStructureKHR) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Expected Acceleration Structure to be of type "
"OpTypeAccelerationStructureKHR";
}
if (isValidId(instance_id_index)) {
const uint32_t instance_id = _.GetOperandTypeId(inst, instance_id_index);
if (!_.IsIntScalarType(instance_id) || _.GetBitWidth(instance_id) != 32) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Instance Id must be a 32-bit int scalar";
}
}
if (isValidId(primtive_id_index)) {
const uint32_t primitive_id = _.GetOperandTypeId(inst, primtive_id_index);
if (!_.IsIntScalarType(primitive_id) || _.GetBitWidth(primitive_id) != 32) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Primitive Id must be a 32-bit int scalar";
}
}
if (isValidId(geometry_index)) {
const uint32_t geometry_index_id = _.GetOperandTypeId(inst, geometry_index);
if (!_.IsIntScalarType(geometry_index_id) ||
_.GetBitWidth(geometry_index_id) != 32) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Geometry Index must be a 32-bit int scalar";
}
}
if (isValidId(miss_index)) {
const uint32_t miss_index_id = _.GetOperandTypeId(inst, miss_index);
if (!_.IsUnsignedIntScalarType(miss_index_id) ||
_.GetBitWidth(miss_index_id) != 32) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Miss Index must be a 32-bit int scalar";
}
}
if (isValidId(cull_mask_index)) {
const uint32_t cull_mask_id = _.GetOperandTypeId(inst, cull_mask_index);
if (!_.IsUnsignedIntScalarType(cull_mask_id) ||
_.GetBitWidth(cull_mask_id) != 32) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Cull mask must be a 32-bit int scalar";
}
}
if (isValidId(sbt_index)) {
const uint32_t sbt_index_id = _.GetOperandTypeId(inst, sbt_index);
if (!_.IsUnsignedIntScalarType(sbt_index_id) ||
_.GetBitWidth(sbt_index_id) != 32) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "SBT Index must be a 32-bit unsigned int scalar";
}
}
if (isValidId(sbt_offset_index)) {
const uint32_t sbt_offset_id = _.GetOperandTypeId(inst, sbt_offset_index);
if (!_.IsUnsignedIntScalarType(sbt_offset_id) ||
_.GetBitWidth(sbt_offset_id) != 32) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "SBT Offset must be a 32-bit unsigned int scalar";
}
}
if (isValidId(sbt_stride_index)) {
const uint32_t sbt_stride_index_id =
_.GetOperandTypeId(inst, sbt_stride_index);
if (!_.IsUnsignedIntScalarType(sbt_stride_index_id) ||
_.GetBitWidth(sbt_stride_index_id) != 32) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "SBT Stride must be a 32-bit unsigned int scalar";
}
}
if (isValidId(sbt_record_offset_index)) {
const uint32_t sbt_record_offset_index_id =
_.GetOperandTypeId(inst, sbt_record_offset_index);
if (!_.IsUnsignedIntScalarType(sbt_record_offset_index_id) ||
_.GetBitWidth(sbt_record_offset_index_id) != 32) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "SBT record offset must be a 32-bit unsigned int scalar";
}
}
if (isValidId(sbt_record_stride_index)) {
const uint32_t sbt_record_stride_index_id =
_.GetOperandTypeId(inst, sbt_record_stride_index);
if (!_.IsUnsignedIntScalarType(sbt_record_stride_index_id) ||
_.GetBitWidth(sbt_record_stride_index_id) != 32) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "SBT record stride must be a 32-bit unsigned int scalar";
}
}
if (isValidId(ray_origin_index)) {
const uint32_t ray_origin_id = _.GetOperandTypeId(inst, ray_origin_index);
if (!_.IsFloatVectorType(ray_origin_id) ||
_.GetDimension(ray_origin_id) != 3 ||
_.GetBitWidth(ray_origin_id) != 32) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Ray Origin must be a 32-bit float 3-component vector";
}
}
if (isValidId(ray_tmin_index)) {
const uint32_t ray_tmin_id = _.GetOperandTypeId(inst, ray_tmin_index);
if (!_.IsFloatScalarType(ray_tmin_id) || _.GetBitWidth(ray_tmin_id) != 32) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Ray TMin must be a 32-bit float scalar";
}
}
if (isValidId(ray_direction_index)) {
const uint32_t ray_direction_id =
_.GetOperandTypeId(inst, ray_direction_index);
if (!_.IsFloatVectorType(ray_direction_id) ||
_.GetDimension(ray_direction_id) != 3 ||
_.GetBitWidth(ray_direction_id) != 32) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Ray Direction must be a 32-bit float 3-component vector";
}
}
if (isValidId(ray_tmax_index)) {
const uint32_t ray_tmax_id = _.GetOperandTypeId(inst, ray_tmax_index);
if (!_.IsFloatScalarType(ray_tmax_id) || _.GetBitWidth(ray_tmax_id) != 32) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Ray TMax must be a 32-bit float scalar";
}
}
if (isValidId(ray_flags_index)) {
const uint32_t ray_flags_id = _.GetOperandTypeId(inst, ray_flags_index);
if (!_.IsIntScalarType(ray_flags_id) || _.GetBitWidth(ray_flags_id) != 32) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Ray Flags must be a 32-bit int scalar";
}
}
if (isValidId(payload_index)) {
const uint32_t payload_id = inst->GetOperandAs<uint32_t>(payload_index);
auto variable = _.FindDef(payload_id);
const auto var_opcode = variable->opcode();
if (!variable || var_opcode != spv::Op::OpVariable ||
(variable->GetOperandAs<spv::StorageClass>(2) !=
spv::StorageClass::RayPayloadKHR &&
variable->GetOperandAs<spv::StorageClass>(2) !=
spv::StorageClass::IncomingRayPayloadKHR)) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "payload must be a OpVariable of storage "
"class RayPayloadKHR or IncomingRayPayloadKHR";
}
}
if (isValidId(hit_kind_index)) {
const uint32_t hit_kind_id = _.GetOperandTypeId(inst, hit_kind_index);
if (!_.IsUnsignedIntScalarType(hit_kind_id) ||
_.GetBitWidth(hit_kind_id) != 32) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Hit Kind must be a 32-bit unsigned int scalar";
}
}
if (isValidId(hit_object_attr_index)) {
const uint32_t hit_object_attr_id =
inst->GetOperandAs<uint32_t>(hit_object_attr_index);
auto variable = _.FindDef(hit_object_attr_id);
const auto var_opcode = variable->opcode();
if (!variable || var_opcode != spv::Op::OpVariable ||
(variable->GetOperandAs<spv::StorageClass>(2)) !=
spv::StorageClass::HitObjectAttributeNV) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Hit Object Attributes id must be a OpVariable of storage "
"class HitObjectAttributeNV";
}
}
return SPV_SUCCESS;
}
spv_result_t RayReorderNVPass(ValidationState_t& _, const Instruction* inst) {
const spv::Op opcode = inst->opcode();
const uint32_t result_type = inst->type_id();
auto RegisterOpcodeForValidModel = [](ValidationState_t& vs,
const Instruction* rtinst) {
std::string opcode_name = spvOpcodeString(rtinst->opcode());
vs.function(rtinst->function()->id())
->RegisterExecutionModelLimitation(
[opcode_name](spv::ExecutionModel model, std::string* message) {
if (model != spv::ExecutionModel::RayGenerationKHR &&
model != spv::ExecutionModel::ClosestHitKHR &&
model != spv::ExecutionModel::MissKHR) {
if (message) {
*message = opcode_name +
" requires RayGenerationKHR, ClosestHitKHR and "
"MissKHR execution models";
}
return false;
}
return true;
});
return;
};
switch (opcode) {
case spv::Op::OpHitObjectIsMissNV:
case spv::Op::OpHitObjectIsHitNV:
case spv::Op::OpHitObjectIsEmptyNV: {
RegisterOpcodeForValidModel(_, inst);
if (!_.IsBoolScalarType(result_type)) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "expected Result Type to be bool scalar type";
}
if (auto error = ValidateHitObjectPointer(_, inst, 2)) return error;
break;
}
case spv::Op::OpHitObjectGetShaderRecordBufferHandleNV: {
RegisterOpcodeForValidModel(_, inst);
if (auto error = ValidateHitObjectPointer(_, inst, 2)) return error;
if (!_.IsIntVectorType(result_type) ||
(_.GetDimension(result_type) != 2) ||
(_.GetBitWidth(result_type) != 32))
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Expected 32-bit integer type 2-component vector as Result "
"Type: "
<< spvOpcodeString(opcode);
break;
}
case spv::Op::OpHitObjectGetHitKindNV:
case spv::Op::OpHitObjectGetPrimitiveIndexNV:
case spv::Op::OpHitObjectGetGeometryIndexNV:
case spv::Op::OpHitObjectGetInstanceIdNV:
case spv::Op::OpHitObjectGetInstanceCustomIndexNV:
case spv::Op::OpHitObjectGetShaderBindingTableRecordIndexNV: {
RegisterOpcodeForValidModel(_, inst);
if (auto error = ValidateHitObjectPointer(_, inst, 2)) return error;
if (!_.IsIntScalarType(result_type) || !_.GetBitWidth(result_type))
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Expected 32-bit integer type scalar as Result Type: "
<< spvOpcodeString(opcode);
break;
}
case spv::Op::OpHitObjectGetCurrentTimeNV:
case spv::Op::OpHitObjectGetRayTMaxNV:
case spv::Op::OpHitObjectGetRayTMinNV: {
RegisterOpcodeForValidModel(_, inst);
if (auto error = ValidateHitObjectPointer(_, inst, 2)) return error;
if (!_.IsFloatScalarType(result_type) || _.GetBitWidth(result_type) != 32)
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Expected 32-bit floating-point type scalar as Result Type: "
<< spvOpcodeString(opcode);
break;
}
case spv::Op::OpHitObjectGetObjectToWorldNV:
case spv::Op::OpHitObjectGetWorldToObjectNV: {
RegisterOpcodeForValidModel(_, inst);
if (auto error = ValidateHitObjectPointer(_, inst, 2)) return error;
uint32_t num_rows = 0;
uint32_t num_cols = 0;
uint32_t col_type = 0;
uint32_t component_type = 0;
if (!_.GetMatrixTypeInfo(result_type, &num_rows, &num_cols, &col_type,
&component_type)) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "expected matrix type as Result Type: "
<< spvOpcodeString(opcode);
}
if (num_cols != 4) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "expected Result Type matrix to have a Column Count of 4"
<< spvOpcodeString(opcode);
}
if (!_.IsFloatScalarType(component_type) ||
_.GetBitWidth(result_type) != 32 || num_rows != 3) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "expected Result Type matrix to have a Column Type of "
"3-component 32-bit float vectors: "
<< spvOpcodeString(opcode);
}
break;
}
case spv::Op::OpHitObjectGetObjectRayOriginNV:
case spv::Op::OpHitObjectGetObjectRayDirectionNV:
case spv::Op::OpHitObjectGetWorldRayDirectionNV:
case spv::Op::OpHitObjectGetWorldRayOriginNV: {
RegisterOpcodeForValidModel(_, inst);
if (auto error = ValidateHitObjectPointer(_, inst, 2)) return error;
if (!_.IsFloatVectorType(result_type) ||
(_.GetDimension(result_type) != 3) ||
(_.GetBitWidth(result_type) != 32))
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Expected 32-bit floating-point type 3-component vector as "
"Result Type: "
<< spvOpcodeString(opcode);
break;
}
case spv::Op::OpHitObjectGetAttributesNV: {
RegisterOpcodeForValidModel(_, inst);
if (auto error = ValidateHitObjectPointer(_, inst, 0)) return error;
const uint32_t hit_object_attr_id = inst->GetOperandAs<uint32_t>(1);
auto variable = _.FindDef(hit_object_attr_id);
const auto var_opcode = variable->opcode();
if (!variable || var_opcode != spv::Op::OpVariable ||
variable->GetOperandAs<spv::StorageClass>(2) !=
spv::StorageClass::HitObjectAttributeNV) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Hit Object Attributes id must be a OpVariable of storage "
"class HitObjectAttributeNV";
}
break;
}
case spv::Op::OpHitObjectExecuteShaderNV: {
RegisterOpcodeForValidModel(_, inst);
if (auto error = ValidateHitObjectPointer(_, inst, 0)) return error;
const uint32_t hit_object_attr_id = inst->GetOperandAs<uint32_t>(1);
auto variable = _.FindDef(hit_object_attr_id);
const auto var_opcode = variable->opcode();
if (!variable || var_opcode != spv::Op::OpVariable ||
(variable->GetOperandAs<spv::StorageClass>(2)) !=
spv::StorageClass::RayPayloadKHR) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Hit Object Attributes id must be a OpVariable of storage "
"class RayPayloadKHR";
}
break;
}
case spv::Op::OpHitObjectRecordEmptyNV: {
RegisterOpcodeForValidModel(_, inst);
if (auto error = ValidateHitObjectPointer(_, inst, 0)) return error;
break;
}
case spv::Op::OpHitObjectRecordMissNV: {
RegisterOpcodeForValidModel(_, inst);
if (auto error = ValidateHitObjectPointer(_, inst, 0)) return error;
const uint32_t miss_index = _.GetOperandTypeId(inst, 1);
if (!_.IsUnsignedIntScalarType(miss_index) ||
_.GetBitWidth(miss_index) != 32) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Miss Index must be a 32-bit int scalar";
}
const uint32_t ray_origin = _.GetOperandTypeId(inst, 2);
if (!_.IsFloatVectorType(ray_origin) || _.GetDimension(ray_origin) != 3 ||
_.GetBitWidth(ray_origin) != 32) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Ray Origin must be a 32-bit float 3-component vector";
}
const uint32_t ray_tmin = _.GetOperandTypeId(inst, 3);
if (!_.IsFloatScalarType(ray_tmin) || _.GetBitWidth(ray_tmin) != 32) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Ray TMin must be a 32-bit float scalar";
}
const uint32_t ray_direction = _.GetOperandTypeId(inst, 4);
if (!_.IsFloatVectorType(ray_direction) ||
_.GetDimension(ray_direction) != 3 ||
_.GetBitWidth(ray_direction) != 32) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Ray Direction must be a 32-bit float 3-component vector";
}
const uint32_t ray_tmax = _.GetOperandTypeId(inst, 5);
if (!_.IsFloatScalarType(ray_tmax) || _.GetBitWidth(ray_tmax) != 32) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Ray TMax must be a 32-bit float scalar";
}
break;
}
case spv::Op::OpHitObjectRecordHitWithIndexNV: {
RegisterOpcodeForValidModel(_, inst);
if (auto error = ValidateHitObjectPointer(_, inst, 0)) return error;
if (auto error = ValidateHitObjectInstructionCommonParameters(
_, inst, 1 /* Acceleration Struct */, 2 /* Instance Id */,
3 /* Primtive Id */, 4 /* Geometry Index */,
KRayParamInvalidId /* Ray Flags */,
KRayParamInvalidId /* Cull Mask */, 5 /* Hit Kind*/,
6 /* SBT index */, KRayParamInvalidId /* SBT Offset */,
KRayParamInvalidId /* SBT Stride */,
KRayParamInvalidId /* SBT Record Offset */,
KRayParamInvalidId /* SBT Record Stride */,
KRayParamInvalidId /* Miss Index */, 7 /* Ray Origin */,
8 /* Ray TMin */, 9 /* Ray Direction */, 10 /* Ray TMax */,
KRayParamInvalidId /* Payload */, 11 /* Hit Object Attribute */))
return error;
break;
}
case spv::Op::OpHitObjectRecordHitNV: {
RegisterOpcodeForValidModel(_, inst);
if (auto error = ValidateHitObjectPointer(_, inst, 0)) return error;
if (auto error = ValidateHitObjectInstructionCommonParameters(
_, inst, 1 /* Acceleration Struct */, 2 /* Instance Id */,
3 /* Primtive Id */, 4 /* Geometry Index */,
KRayParamInvalidId /* Ray Flags */,
KRayParamInvalidId /* Cull Mask */, 5 /* Hit Kind*/,
KRayParamInvalidId /* SBT index */,
KRayParamInvalidId /* SBT Offset */,
KRayParamInvalidId /* SBT Stride */, 6 /* SBT Record Offset */,
7 /* SBT Record Stride */, KRayParamInvalidId /* Miss Index */,
8 /* Ray Origin */, 9 /* Ray TMin */, 10 /* Ray Direction */,
11 /* Ray TMax */, KRayParamInvalidId /* Payload */,
12 /* Hit Object Attribute */))
return error;
break;
}
case spv::Op::OpHitObjectTraceRayMotionNV: {
RegisterOpcodeForValidModel(_, inst);
if (auto error = ValidateHitObjectPointer(_, inst, 0)) return error;
if (auto error = ValidateHitObjectInstructionCommonParameters(
_, inst, 1 /* Acceleration Struct */,
KRayParamInvalidId /* Instance Id */,
KRayParamInvalidId /* Primtive Id */,
KRayParamInvalidId /* Geometry Index */, 2 /* Ray Flags */,
3 /* Cull Mask */, KRayParamInvalidId /* Hit Kind*/,
KRayParamInvalidId /* SBT index */, 4 /* SBT Offset */,
5 /* SBT Stride */, KRayParamInvalidId /* SBT Record Offset */,
KRayParamInvalidId /* SBT Record Stride */, 6 /* Miss Index */,
7 /* Ray Origin */, 8 /* Ray TMin */, 9 /* Ray Direction */,
10 /* Ray TMax */, 12 /* Payload */,
KRayParamInvalidId /* Hit Object Attribute */))
return error;
// Current Time
const uint32_t current_time_id = _.GetOperandTypeId(inst, 11);
if (!_.IsFloatScalarType(current_time_id) ||
_.GetBitWidth(current_time_id) != 32) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Current Times must be a 32-bit float scalar type";
}
break;
}
case spv::Op::OpHitObjectTraceRayNV: {
RegisterOpcodeForValidModel(_, inst);
if (auto error = ValidateHitObjectPointer(_, inst, 0)) return error;
if (auto error = ValidateHitObjectInstructionCommonParameters(
_, inst, 1 /* Acceleration Struct */,
KRayParamInvalidId /* Instance Id */,
KRayParamInvalidId /* Primtive Id */,
KRayParamInvalidId /* Geometry Index */, 2 /* Ray Flags */,
3 /* Cull Mask */, KRayParamInvalidId /* Hit Kind*/,
KRayParamInvalidId /* SBT index */, 4 /* SBT Offset */,
5 /* SBT Stride */, KRayParamInvalidId /* SBT Record Offset */,
KRayParamInvalidId /* SBT Record Stride */, 6 /* Miss Index */,
7 /* Ray Origin */, 8 /* Ray TMin */, 9 /* Ray Direction */,
10 /* Ray TMax */, 11 /* Payload */,
KRayParamInvalidId /* Hit Object Attribute */))
return error;
break;
}
case spv::Op::OpReorderThreadWithHitObjectNV: {
std::string opcode_name = spvOpcodeString(inst->opcode());
_.function(inst->function()->id())
->RegisterExecutionModelLimitation(
[opcode_name](spv::ExecutionModel model, std::string* message) {
if (model != spv::ExecutionModel::RayGenerationKHR) {
if (message) {
*message = opcode_name +
" requires RayGenerationKHR execution model";
}
return false;
}
return true;
});
if (auto error = ValidateHitObjectPointer(_, inst, 0)) return error;
if (inst->operands().size() > 1) {
if (inst->operands().size() != 3) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Hint and Bits are optional together i.e "
<< " Either both Hint and Bits should be provided or neither.";
}
// Validate the optional opreands Hint and Bits
const uint32_t hint_id = _.GetOperandTypeId(inst, 1);
if (!_.IsIntScalarType(hint_id) || _.GetBitWidth(hint_id) != 32) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Hint must be a 32-bit int scalar";
}
const uint32_t bits_id = _.GetOperandTypeId(inst, 2);
if (!_.IsIntScalarType(bits_id) || _.GetBitWidth(bits_id) != 32) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "bits must be a 32-bit int scalar";
}
}
break;
}
case spv::Op::OpReorderThreadWithHintNV: {
std::string opcode_name = spvOpcodeString(inst->opcode());
_.function(inst->function()->id())
->RegisterExecutionModelLimitation(
[opcode_name](spv::ExecutionModel model, std::string* message) {
if (model != spv::ExecutionModel::RayGenerationKHR) {
if (message) {
*message = opcode_name +
" requires RayGenerationKHR execution model";
}
return false;
}
return true;
});
const uint32_t hint_id = _.GetOperandTypeId(inst, 0);
if (!_.IsIntScalarType(hint_id) || _.GetBitWidth(hint_id) != 32) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Hint must be a 32-bit int scalar";
}
const uint32_t bits_id = _.GetOperandTypeId(inst, 1);
if (!_.IsIntScalarType(bits_id) || _.GetBitWidth(bits_id) != 32) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "bits must be a 32-bit int scalar";
}
}
default:
break;
}
return SPV_SUCCESS;
}
} // namespace val
} // namespace spvtools

View File

@ -790,6 +790,22 @@ void ValidationState_t::RegisterStorageClassConsumer(
}
return true;
});
} else if (storage_class == spv::StorageClass::HitObjectAttributeNV) {
function(consumer->function()->id())
->RegisterExecutionModelLimitation([](spv::ExecutionModel model,
std::string* message) {
if (model != spv::ExecutionModel::RayGenerationKHR &&
model != spv::ExecutionModel::ClosestHitKHR &&
model != spv::ExecutionModel::MissKHR) {
if (message) {
*message =
"HitObjectAttributeNV Storage Class is limited to "
"RayGenerationKHR, ClosestHitKHR or MissKHR execution model";
}
return false;
}
return true;
});
}
}
@ -1555,6 +1571,7 @@ bool ValidationState_t::IsValidStorageClass(
case spv::StorageClass::IncomingCallableDataKHR:
case spv::StorageClass::ShaderRecordBufferKHR:
case spv::StorageClass::TaskPayloadWorkgroupEXT:
case spv::StorageClass::HitObjectAttributeNV:
return true;
default:
return false;

View File

@ -172,6 +172,7 @@ std::vector<std::unique_ptr<Type>> GenerateAllTypes() {
types.emplace_back(new AccelerationStructureNV());
types.emplace_back(new CooperativeMatrixNV(f32, 24, 24, 24));
types.emplace_back(new RayQueryKHR());
types.emplace_back(new HitObjectNV());
return types;
}
@ -1085,6 +1086,7 @@ TEST(TypeManager, GetTypeInstructionAllTypes) {
; CHECK: OpTypeAccelerationStructureKHR
; CHECK: OpTypeCooperativeMatrixNV [[f32]] [[uint24]] [[uint24]] [[uint24]]
; CHECK: OpTypeRayQueryKHR
; CHECK: OpTypeHitObjectNV
OpCapability Shader
OpCapability Int64
OpCapability Linkage

View File

@ -93,6 +93,7 @@ add_spvtools_unittest(TARGET val_rstuvw
SRCS
val_ray_query_test.cpp
val_ray_tracing_test.cpp
val_ray_tracing_reorder_test.cpp
val_small_type_uses_test.cpp
val_ssa_test.cpp
val_state_test.cpp

View File

@ -0,0 +1,598 @@
// Copyright (c) 2022 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Tests instructions from SPV_NV_shader_invocation_reorder.
#include <sstream>
#include <string>
#include "gmock/gmock.h"
#include "test/val/val_fixtures.h"
namespace spvtools {
namespace val {
namespace {
using ::testing::HasSubstr;
using ::testing::Values;
using ValidateRayTracingReorderNV = spvtest::ValidateBase<bool>;
std::string GenerateReorderThreadCode(const std::string& body = "",
const std::string& declarations = "") {
std::ostringstream ss;
ss << R"(
OpCapability RayTracingKHR
OpCapability ShaderInvocationReorderNV
OpExtension "SPV_KHR_ray_tracing"
OpExtension "SPV_NV_shader_invocation_reorder"
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint RayGenerationNV %main "main" %hObj
OpSourceExtension "GL_EXT_ray_tracing"
OpSourceExtension "GL_NV_shader_invocation_reorder"
OpName %main "main"
%void = OpTypeVoid
%3 = OpTypeFunction %void
%6 = OpTypeHitObjectNV
%_ptr_Private_6 = OpTypePointer Private %6
%hObj = OpVariable %_ptr_Private_6 Private
)";
ss << declarations;
ss << R"(
%main = OpFunction %void None %3
%5 = OpLabel
)";
ss << body;
ss << R"(
OpReturn
OpFunctionEnd
)";
return ss.str();
}
TEST_F(ValidateRayTracingReorderNV, ReorderThreadWithHintNV) {
const std::string declarations = R"(
%uint = OpTypeInt 32 0
%uint_4 = OpConstant %uint 4
)";
const std::string body = R"(
OpReorderThreadWithHintNV %uint_4 %uint_4
)";
CompileSuccessfully(GenerateReorderThreadCode(body, declarations).c_str(),
SPV_ENV_VULKAN_1_2);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
}
TEST_F(ValidateRayTracingReorderNV, ReorderThreadWithHitObjectNV) {
const std::string declarations = R"(
%uint = OpTypeInt 32 0
%uint_4 = OpConstant %uint 4
%uint_2 = OpConstant %uint 2
)";
const std::string body = R"(
OpReorderThreadWithHitObjectNV %hObj
OpReorderThreadWithHitObjectNV %hObj %uint_4 %uint_2
)";
CompileSuccessfully(GenerateReorderThreadCode(body, declarations).c_str(),
SPV_ENV_VULKAN_1_2);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
}
std::string GenerateReorderShaderCode(
const std::string& body = "", const std::string& declarations = "",
const std::string execution_model = "RayGenerationKHR") {
std::ostringstream ss;
ss << R"(
OpCapability RayTracingKHR
OpCapability ShaderInvocationReorderNV
OpExtension "SPV_KHR_ray_tracing"
OpExtension "SPV_NV_shader_invocation_reorder"
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint )"
<< execution_model
<< R"( %main "main" %attr %_ %hObj %payload %__0 %as %__1
OpSource GLSL 460
OpSourceExtension "GL_EXT_ray_tracing"
OpSourceExtension "GL_NV_shader_invocation_reorder"
OpName %main "main"
OpName %attr "attr"
OpName %hBlock "hBlock"
OpMemberName %hBlock 0 "attrval"
OpName %_ ""
OpName %hObj "hObj"
OpName %payload "payload"
OpName %pBlock "pBlock"
OpMemberName %pBlock 0 "val1"
OpMemberName %pBlock 1 "val2"
OpName %__0 ""
OpName %as "as"
OpName %block "block"
OpMemberName %block 0 "op"
OpName %__1 ""
OpDecorate %hBlock Block
OpDecorate %pBlock Block
OpDecorate %as DescriptorSet 0
OpDecorate %as Binding 0
OpMemberDecorate %block 0 Offset 0
OpDecorate %block Block
OpDecorate %__1 DescriptorSet 0
OpDecorate %__1 Binding 1
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v2float = OpTypeVector %float 2
%_ptr_HitObjectAttributeNV_v2float = OpTypePointer HitObjectAttributeNV %v2float
%attr = OpVariable %_ptr_HitObjectAttributeNV_v2float HitObjectAttributeNV
%float_1 = OpConstant %float 1
%11 = OpConstantComposite %v2float %float_1 %float_1
%hBlock = OpTypeStruct %float
%_ptr_HitObjectAttributeNV_hBlock = OpTypePointer HitObjectAttributeNV %hBlock
%_ = OpVariable %_ptr_HitObjectAttributeNV_hBlock HitObjectAttributeNV
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%float_2 = OpConstant %float 2
%_ptr_HitObjectAttributeNV_float = OpTypePointer HitObjectAttributeNV %float
%20 = OpTypeHitObjectNV
%_ptr_Private_20 = OpTypePointer Private %20
%hObj = OpVariable %_ptr_Private_20 Private
%23 = OpTypeAccelerationStructureKHR
%_ptr_UniformConstant_23 = OpTypePointer UniformConstant %23
%as = OpVariable %_ptr_UniformConstant_23 UniformConstant
%v4float = OpTypeVector %float 4
%_ptr_RayPayloadNV_v4float = OpTypePointer RayPayloadNV %v4float
%payload = OpVariable %_ptr_RayPayloadNV_v4float RayPayloadNV
%pBlock = OpTypeStruct %v2float %v2float
%_ptr_RayPayloadNV_pBlock = OpTypePointer RayPayloadNV %pBlock
%__0 = OpVariable %_ptr_RayPayloadNV_pBlock RayPayloadNV
%block = OpTypeStruct %float
%_ptr_StorageBuffer_block = OpTypePointer StorageBuffer %block
%__1 = OpVariable %_ptr_StorageBuffer_block StorageBuffer
)";
ss << declarations;
ss << R"(
%main = OpFunction %void None %3
%5 = OpLabel
)";
ss << body;
ss << R"(
OpReturn
OpFunctionEnd)";
return ss.str();
}
TEST_F(ValidateRayTracingReorderNV, HitObjectTraceRayNV) {
const std::string declarations = R"(
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%v3float = OpTypeVector %float 3
%float_0_5 = OpConstant %float 0.5
%31 = OpConstantComposite %v3float %float_0_5 %float_0_5 %float_0_5
%32 = OpConstantComposite %v3float %float_1 %float_1 %float_1
%int_1 = OpConstant %int 1
)";
const std::string body = R"(
OpStore %attr %11
%26 = OpLoad %23 %as
OpHitObjectTraceRayNV %hObj %26 %uint_1 %uint_1 %uint_1 %uint_1 %uint_1 %31 %float_0_5 %32 %float_1 %payload
)";
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(),
SPV_ENV_VULKAN_1_2);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
}
TEST_F(ValidateRayTracingReorderNV, HitObjectTraceRayMotionNV) {
const std::string declarations = R"(
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%v3float = OpTypeVector %float 3
%float_0_5 = OpConstant %float 0.5
%31 = OpConstantComposite %v3float %float_0_5 %float_0_5 %float_0_5
%32 = OpConstantComposite %v3float %float_1 %float_1 %float_1
%float_10 = OpConstant %float 10
%int_2 = OpConstant %int 2
)";
const std::string body = R"(
OpStore %attr %11
%26 = OpLoad %23 %as
OpHitObjectTraceRayMotionNV %hObj %26 %uint_1 %uint_1 %uint_1 %uint_1 %uint_1 %31 %float_0_5 %32 %float_1 %float_10 %__0
)";
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(),
SPV_ENV_VULKAN_1_2);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
}
TEST_F(ValidateRayTracingReorderNV, HitObjectRecordHitNV) {
const std::string declarations = R"(
%int_1 = OpConstant %int 1
%uint = OpTypeInt 32 0
%uint_2 = OpConstant %uint 2
%v3float = OpTypeVector %float 3
%float_0_5 = OpConstant %float 0.5
%31 = OpConstantComposite %v3float %float_0_5 %float_0_5 %float_0_5
%32 = OpConstantComposite %v3float %float_1 %float_1 %float_1
%float_10 = OpConstant %float 10
%int_2 = OpConstant %int 2
)";
const std::string body = R"(
OpStore %attr %11
%26 = OpLoad %23 %as
OpHitObjectRecordHitNV %hObj %26 %int_1 %int_1 %int_1 %uint_2 %uint_2 %uint_2 %31 %float_1 %32 %float_2 %attr
)";
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(),
SPV_ENV_VULKAN_1_2);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
}
TEST_F(ValidateRayTracingReorderNV, HitObjectRecordHitWithIndexNV) {
const std::string declarations = R"(
%int_1 = OpConstant %int 1
%uint = OpTypeInt 32 0
%uint_2 = OpConstant %uint 2
%v3float = OpTypeVector %float 3
%float_0_5 = OpConstant %float 0.5
%31 = OpConstantComposite %v3float %float_0_5 %float_0_5 %float_0_5
%32 = OpConstantComposite %v3float %float_1 %float_1 %float_1
%float_10 = OpConstant %float 10
%int_2 = OpConstant %int 2
)";
const std::string body = R"(
OpStore %attr %11
%26 = OpLoad %23 %as
OpHitObjectRecordHitWithIndexNV %hObj %26 %int_1 %int_1 %int_1 %uint_2 %uint_2 %31 %float_1 %32 %float_2 %_
)";
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(),
SPV_ENV_VULKAN_1_2);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
}
TEST_F(ValidateRayTracingReorderNV, HitObjectRecordEmptyNV) {
const std::string body = R"(
OpHitObjectRecordEmptyNV %hObj
)";
CompileSuccessfully(GenerateReorderShaderCode(body).c_str(),
SPV_ENV_VULKAN_1_2);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
}
TEST_F(ValidateRayTracingReorderNV, HitObjectRecordMissNV) {
const std::string declarations = R"(
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%v3float = OpTypeVector %float 3
%float_0_5 = OpConstant %float 0.5
%29 = OpConstantComposite %v3float %float_0_5 %float_0_5 %float_0_5
%float_1_5 = OpConstant %float 1.5
%31 = OpConstantComposite %v3float %float_1_5 %float_1_5 %float_1_5
%float_5 = OpConstant %float 5
)";
const std::string body = R"(
OpHitObjectRecordMissNV %hObj %uint_1 %29 %float_2 %31 %float_5
)";
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(),
SPV_ENV_VULKAN_1_2);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
}
TEST_F(ValidateRayTracingReorderNV, HitObjectIsHitNV) {
const std::string declarations = R"(
%bool = OpTypeBool
%_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float
)";
const std::string body = R"(
%26 = OpHitObjectIsHitNV %bool %hObj
OpSelectionMerge %28 None
OpBranchConditional %26 %27 %28
%27 = OpLabel
%33 = OpAccessChain %_ptr_StorageBuffer_float %__1 %int_0
OpStore %33 %float_1
OpBranch %28
%28 = OpLabel
)";
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(),
SPV_ENV_VULKAN_1_2);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
}
TEST_F(ValidateRayTracingReorderNV, HitObjectGetRayTMaxNV) {
const std::string declarations = R"(
%_ptr_Function_float = OpTypePointer Function %float
)";
const std::string body = R"(
%tmin = OpVariable %_ptr_Function_float Function
%12 = OpHitObjectGetRayTMaxNV %float %hObj
OpStore %tmin %12
)";
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(),
SPV_ENV_VULKAN_1_2);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
}
TEST_F(ValidateRayTracingReorderNV, HitObjectGetRayTMinNV) {
const std::string declarations = R"(
%_ptr_Function_float = OpTypePointer Function %float
)";
const std::string body = R"(
%tmin = OpVariable %_ptr_Function_float Function
%12 = OpHitObjectGetRayTMinNV %float %hObj
OpStore %tmin %12
)";
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(),
SPV_ENV_VULKAN_1_2);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
}
TEST_F(ValidateRayTracingReorderNV, HitObjectGetWorldRayOriginNV) {
const std::string declarations = R"(
%v3float = OpTypeVector %float 3
%_ptr_Function_v3float = OpTypePointer Function %v3float
)";
const std::string body = R"(
%orig = OpVariable %_ptr_Function_v3float Function
%13 = OpHitObjectGetWorldRayOriginNV %v3float %hObj
OpStore %orig %13
)";
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(),
SPV_ENV_VULKAN_1_2);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
}
TEST_F(ValidateRayTracingReorderNV, HitObjectGetObjectRayOriginNV) {
const std::string declarations = R"(
%v3float = OpTypeVector %float 3
%_ptr_Function_v3float = OpTypePointer Function %v3float
)";
const std::string body = R"(
%oorig = OpVariable %_ptr_Function_v3float Function
%13 = OpHitObjectGetObjectRayOriginNV %v3float %hObj
OpStore %oorig %13
)";
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(),
SPV_ENV_VULKAN_1_2);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
}
TEST_F(ValidateRayTracingReorderNV, HitObjectGetWorldRayDirectionNV) {
const std::string declarations = R"(
%v3float = OpTypeVector %float 3
%_ptr_Function_v3float = OpTypePointer Function %v3float
)";
const std::string body = R"(
%dir = OpVariable %_ptr_Function_v3float Function
%13 = OpHitObjectGetWorldRayDirectionNV %v3float %hObj
OpStore %dir %13
)";
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(),
SPV_ENV_VULKAN_1_2);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
}
TEST_F(ValidateRayTracingReorderNV, HitObjectGetObjectRayDirectionNV) {
const std::string declarations = R"(
%v3float = OpTypeVector %float 3
%_ptr_Function_v3float = OpTypePointer Function %v3float
)";
const std::string body = R"(
%odir = OpVariable %_ptr_Function_v3float Function
%13 = OpHitObjectGetObjectRayDirectionNV %v3float %hObj
OpStore %odir %13
)";
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(),
SPV_ENV_VULKAN_1_2);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
}
TEST_F(ValidateRayTracingReorderNV, HitObjectGetObjectToWorldNV) {
const std::string declarations = R"(
%v3float = OpTypeVector %float 3
%mat4v3float = OpTypeMatrix %v3float 4
%_ptr_Function_mat4v3float = OpTypePointer Function %mat4v3float
)";
const std::string body = R"(
%otw = OpVariable %_ptr_Function_mat4v3float Function
%14 = OpHitObjectGetObjectToWorldNV %mat4v3float %hObj
OpStore %otw %14
)";
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(),
SPV_ENV_VULKAN_1_2);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
}
TEST_F(ValidateRayTracingReorderNV, HitObjectGetWorldToObjectNV) {
const std::string declarations = R"(
%v3float = OpTypeVector %float 3
%mat4v3float = OpTypeMatrix %v3float 4
%_ptr_Function_mat4v3float = OpTypePointer Function %mat4v3float
)";
const std::string body = R"(
%wto = OpVariable %_ptr_Function_mat4v3float Function
%14 = OpHitObjectGetWorldToObjectNV %mat4v3float %hObj
OpStore %wto %14
)";
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(),
SPV_ENV_VULKAN_1_2);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
}
TEST_F(ValidateRayTracingReorderNV, HitObjectGetInstanceCustomIndexNV) {
const std::string declarations = R"(
%_ptr_Function_int = OpTypePointer Function %int
)";
const std::string body = R"(
%id = OpVariable %_ptr_Function_int Function
%12 = OpHitObjectGetInstanceCustomIndexNV %int %hObj
OpStore %id %12
)";
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(),
SPV_ENV_VULKAN_1_2);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
}
TEST_F(ValidateRayTracingReorderNV, HitObjectGetInstanceIdNV) {
const std::string declarations = R"(
%_ptr_Function_int = OpTypePointer Function %int
)";
const std::string body = R"(
%id = OpVariable %_ptr_Function_int Function
%12 = OpHitObjectGetInstanceIdNV %int %hObj
OpStore %id %12
)";
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(),
SPV_ENV_VULKAN_1_2);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
}
TEST_F(ValidateRayTracingReorderNV, HitObjectGetPrimitiveIndexNV) {
const std::string declarations = R"(
%_ptr_Function_int = OpTypePointer Function %int
)";
const std::string body = R"(
%id = OpVariable %_ptr_Function_int Function
%12 = OpHitObjectGetPrimitiveIndexNV %int %hObj
OpStore %id %12
)";
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(),
SPV_ENV_VULKAN_1_2);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
}
TEST_F(ValidateRayTracingReorderNV, HitObjectGetGeometryIndexNV) {
const std::string declarations = R"(
%_ptr_Function_int = OpTypePointer Function %int
)";
const std::string body = R"(
%id = OpVariable %_ptr_Function_int Function
%12 = OpHitObjectGetGeometryIndexNV %int %hObj
OpStore %id %12
)";
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(),
SPV_ENV_VULKAN_1_2);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
}
TEST_F(ValidateRayTracingReorderNV, HitObjectGetHitKindNV) {
const std::string declarations = R"(
%uint = OpTypeInt 32 0
%_ptr_Function_uint = OpTypePointer Function %uint
)";
const std::string body = R"(
%uid = OpVariable %_ptr_Function_uint Function
%12 = OpHitObjectGetHitKindNV %uint %hObj
OpStore %uid %12
)";
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(),
SPV_ENV_VULKAN_1_2);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
}
TEST_F(ValidateRayTracingReorderNV, HitObjectGetAttributesNV) {
const std::string body = R"(
OpHitObjectGetAttributesNV %hObj %attr
)";
CompileSuccessfully(GenerateReorderShaderCode(body).c_str(),
SPV_ENV_VULKAN_1_2);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
}
TEST_F(ValidateRayTracingReorderNV, HitObjectGetShaderRecordBufferHandleNV) {
const std::string declarations = R"(
%uint = OpTypeInt 32 0
%v2uint = OpTypeVector %uint 2
%_ptr_Function_v2uint = OpTypePointer Function %v2uint
)";
const std::string body = R"(
%handle = OpVariable %_ptr_Function_v2uint Function
%13 = OpHitObjectGetShaderRecordBufferHandleNV %v2uint %hObj
OpStore %handle %13
)";
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(),
SPV_ENV_VULKAN_1_2);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
}
TEST_F(ValidateRayTracingReorderNV,
HitObjectGetShaderBindingTableRecordIndexNV) {
const std::string declarations = R"(
%uint = OpTypeInt 32 0
%_ptr_Function_uint = OpTypePointer Function %uint
)";
const std::string body = R"(
%rid = OpVariable %_ptr_Function_uint Function
%12 = OpHitObjectGetShaderBindingTableRecordIndexNV %uint %hObj
OpStore %rid %12
)";
CompileSuccessfully(GenerateReorderShaderCode(body, declarations).c_str(),
SPV_ENV_VULKAN_1_2);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
}
} // namespace
} // namespace val
} // namespace spvtools