Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 30 additions & 13 deletions layers/core_checks/cc_spirv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ bool CoreChecks::ValidateCooperativeVector(const spirv::Module &module_state, co
uint32_t component_count;
bool all_constant;

CoopVecType(uint32_t id, const spirv::Module &module_state, const ShaderStageState &stage_state) {
CoopVecType(uint32_t id, const spirv::Module &module_state, const ShaderStageState &stage_state, bool is_signed) {
const spirv::Instruction *insn = module_state.FindDef(id);
const spirv::Instruction *component_type_insn = module_state.FindDef(insn->Word(2));
const spirv::Instruction *component_count_insn = module_state.FindDef(insn->Word(3));
Expand All @@ -834,7 +834,7 @@ bool CoreChecks::ValidateCooperativeVector(const spirv::Module &module_state, co
if (!stage_state.GetInt32ConstantValue(*component_count_insn, &component_count)) {
all_constant = false;
}
component_type = GetComponentType(component_type_insn, false);
component_type = GetComponentType(component_type_insn, is_signed);
}

std::string Describe() {
Expand Down Expand Up @@ -868,23 +868,27 @@ bool CoreChecks::ValidateCooperativeVector(const spirv::Module &module_state, co
const spirv::Instruction &insn = *cooperative_vector_inst;
switch (insn.Opcode()) {
case spv::OpTypeCooperativeVectorNV: {
CoopVecType m(insn.Word(1), module_state, stage_state);
// SPIR-V integer types are not strictly signed or unsigned. Allow this type to
// match against either signed or unsigned types in the device properties.
CoopVecType m_signed(insn.Word(1), module_state, stage_state, true);
CoopVecType m_unsigned(insn.Word(1), module_state, stage_state, false);

if (!m.all_constant) {
if (!m_signed.all_constant) {
break;
}

if (m.component_count > phys_dev_ext_props.cooperative_vector_props_nv.maxCooperativeVectorComponents) {
if (m_signed.component_count > phys_dev_ext_props.cooperative_vector_props_nv.maxCooperativeVectorComponents) {
skip |= LogError("VUID-RuntimeSpirv-maxCooperativeVectorComponents-10094", module_state.handle(), loc,
"SPIR-V (%s) component count (%d) is greater than maxCooperativeVectorComponents (%d)",
string_VkShaderStageFlagBits(entrypoint.stage), m.component_count,
string_VkShaderStageFlagBits(entrypoint.stage), m_signed.component_count,
phys_dev_ext_props.cooperative_vector_props_nv.maxCooperativeVectorComponents);
}

bool found = false;
for (uint32_t i = 0; i < device_state->cooperative_vector_properties_nv.size(); ++i) {
const auto &property = device_state->cooperative_vector_properties_nv[i];
if (m.component_type == property.inputType || m.component_type == property.resultType) {
if (m_signed.component_type == property.inputType || m_signed.component_type == property.resultType ||
m_unsigned.component_type == property.inputType || m_unsigned.component_type == property.resultType) {
found = true;
break;
}
Expand All @@ -894,7 +898,7 @@ bool CoreChecks::ValidateCooperativeVector(const spirv::Module &module_state, co
skip |= LogError("VUID-RuntimeSpirv-OpTypeCooperativeVector-10095", module_state.handle(), loc,
"SPIR-V (%s) contains unsupported cooperative vector component type (%s)",
string_VkShaderStageFlagBits(entrypoint.stage),
string_VkComponentTypeKHR((VkComponentTypeKHR)m.component_type));
string_VkComponentTypeKHR((VkComponentTypeKHR)m_signed.component_type));
}

break;
Expand All @@ -906,8 +910,21 @@ bool CoreChecks::ValidateCooperativeVector(const spirv::Module &module_state, co
}
case spv::OpCooperativeVectorMatrixMulNV:
case spv::OpCooperativeVectorMatrixMulAddNV: {
CoopVecType result(id_to_type_id[insn.Word(2)], module_state, stage_state);
CoopVecType input(id_to_type_id[insn.Word(3)], module_state, stage_state);
uint32_t matrix_operands = 0;
if (insn.Opcode() == spv::OpCooperativeVectorMatrixMulAddNV) {
if (insn.Length() > 16) {
matrix_operands = insn.Word(16);
}
} else {
if (insn.Length() > 13) {
matrix_operands = insn.Word(13);
}
}
bool result_is_signed = matrix_operands & spv::CooperativeMatrixOperandsMatrixResultSignedComponentsKHRMask;
bool input_is_signed = matrix_operands & spv::CooperativeMatrixOperandsMatrixBSignedComponentsKHRMask;

CoopVecType result(id_to_type_id[insn.Word(2)], module_state, stage_state, result_is_signed);
CoopVecType input(id_to_type_id[insn.Word(3)], module_state, stage_state, input_is_signed);

uint32_t result_type = result.component_type;
uint32_t input_type = input.component_type;
Expand Down Expand Up @@ -985,7 +1002,7 @@ bool CoreChecks::ValidateCooperativeVector(const spirv::Module &module_state, co
break;
}
case spv::OpCooperativeVectorReduceSumAccumulateNV: {
CoopVecType v(id_to_type_id[insn.Word(3)], module_state, stage_state);
CoopVecType v(id_to_type_id[insn.Word(3)], module_state, stage_state, false);

switch (v.component_type) {
case VK_COMPONENT_TYPE_FLOAT16_KHR:
Expand Down Expand Up @@ -1057,8 +1074,8 @@ bool CoreChecks::ValidateCooperativeVector(const spirv::Module &module_state, co
}
}

CoopVecType a(id_to_type_id[insn.Word(3)], module_state, stage_state);
CoopVecType b(id_to_type_id[insn.Word(4)], module_state, stage_state);
CoopVecType a(id_to_type_id[insn.Word(3)], module_state, stage_state, false);
CoopVecType b(id_to_type_id[insn.Word(4)], module_state, stage_state, false);

if (a.component_type != VK_COMPONENT_TYPE_FLOAT16_KHR) {
skip |= LogError("VUID-RuntimeSpirv-OpCooperativeVectorOuterProductAccumulateNV-10093", module_state.handle(),
Expand Down
9 changes: 8 additions & 1 deletion tests/icd/test_icd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,7 @@ static VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceCooperativeVectorProperti
uint32_t* pPropertyCount,
VkCooperativeVectorPropertiesNV* pProperties) {
if (!pProperties) {
*pPropertyCount = 4;
*pPropertyCount = 5;
} else {
// arbitrary
pProperties[0].inputType = VK_COMPONENT_TYPE_UINT32_KHR;
Expand Down Expand Up @@ -1666,6 +1666,13 @@ static VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceCooperativeVectorProperti
pProperties[3].biasInterpretation = VK_COMPONENT_TYPE_FLOAT16_KHR;
pProperties[3].resultType = VK_COMPONENT_TYPE_FLOAT16_KHR;
pProperties[3].transpose = VK_FALSE;

pProperties[4].inputType = VK_COMPONENT_TYPE_SINT8_KHR;
pProperties[4].inputInterpretation = VK_COMPONENT_TYPE_SINT8_KHR;
pProperties[4].matrixInterpretation = VK_COMPONENT_TYPE_SINT8_KHR;
pProperties[4].biasInterpretation = VK_COMPONENT_TYPE_SINT32_KHR;
pProperties[4].resultType = VK_COMPONENT_TYPE_SINT32_KHR;
pProperties[4].transpose = VK_FALSE;
}
return VK_SUCCESS;
}
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/shader_cooperative_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,17 @@ TEST_F(NegativeShaderCooperativeVector, SPIRVMatMulParams) {
)");
}

TEST_F(NegativeShaderCooperativeVector, SPIRVMatMulParamsInt) {
TEST_DESCRIPTION("Validate Cooperative Vector SPIR-V environment rules.");

RunSPIRVTest("VUID-RuntimeSpirv-OpCooperativeVectorMatrixMulNV-10089",
R"(
coopvecNV<int8_t, 16> A;
coopvecNV<uint32_t, 32> R;
coopVecMatMulNV(R, A, gl_ComponentTypeSignedInt8NV, b.x, 0, gl_ComponentTypeSignedInt8NV, 32, 16, gl_CooperativeVectorMatrixLayoutInferencingOptimalNV, false, 0);
)");
}

TEST_F(NegativeShaderCooperativeVector, SPIRVFP8Layout) {
TEST_DESCRIPTION("Validate Cooperative Vector SPIR-V environment rules.");

Expand Down
4 changes: 4 additions & 0 deletions tests/unit/shader_cooperative_vector_positive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ TEST_F(PositiveShaderCooperativeVector, CooperativeVectorSPIRV) {
coopvecNV<float16_t, 32> R;
coopVecMatMulNV(R, A, gl_ComponentTypeFloat16NV, b.x, 0, gl_ComponentTypeFloat16NV, 32, 16, gl_CooperativeVectorMatrixLayoutInferencingOptimalNV, false, 0);
coopVecMatMulAddNV(R, A, gl_ComponentTypeFloat16NV, b.x, 0, gl_ComponentTypeFloat16NV, b.x, 0, gl_ComponentTypeFloat16NV, 32, 16, gl_CooperativeVectorMatrixLayoutInferencingOptimalNV, false, 0);

coopvecNV<int8_t, 16> A2;
coopvecNV<int32_t, 32> R2;
coopVecMatMulNV(R2, A2, gl_ComponentTypeSignedInt8NV, b.x, 0, gl_ComponentTypeSignedInt8NV, 32, 16, gl_CooperativeVectorMatrixLayoutInferencingOptimalNV, false, 0);
}
)glsl";

Expand Down