Commit 92797c27 by Ben Clayton

SpirvShader: Rework debug assertions

Use the new UNSUPPORTED() macro where possible. Switch to using UNREACHABLE() over UNIMPLEMENTED() for switch cases that do not exist according to the spec, or for cases that should be handled by validation in an earlier stage. Bug: b/131243109 Change-Id: Id9970b64cf248468c508e65366bc576cb03e8e58 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/29929Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Presubmit-Ready: Ben Clayton <bclayton@google.com> Tested-by: 's avatarBen Clayton <bclayton@google.com>
parent 46e28cb3
...@@ -561,13 +561,19 @@ namespace sw ...@@ -561,13 +561,19 @@ namespace sw
break; // Correctly handled. break; // Correctly handled.
case spv::StorageClassWorkgroup: case spv::StorageClassWorkgroup:
case spv::StorageClassCrossWorkgroup:
case spv::StorageClassGeneric:
case spv::StorageClassAtomicCounter: case spv::StorageClassAtomicCounter:
case spv::StorageClassImage: case spv::StorageClassImage:
UNIMPLEMENTED("StorageClass %d not yet implemented", (int)storageClass); UNIMPLEMENTED("StorageClass %d not yet implemented", (int)storageClass);
break; break;
case spv::StorageClassCrossWorkgroup:
UNSUPPORTED("SPIR-V OpenCL Execution Model (StorageClassCrossWorkgroup)");
break;
case spv::StorageClassGeneric:
UNSUPPORTED("SPIR-V GenericPointer Capability (StorageClassGeneric)");
break;
default: default:
UNREACHABLE("Unexpected StorageClass %d", storageClass); // See Appendix A of the Vulkan spec. UNREACHABLE("Unexpected StorageClass %d", storageClass); // See Appendix A of the Vulkan spec.
break; break;
...@@ -660,13 +666,16 @@ namespace sw ...@@ -660,13 +666,16 @@ namespace sw
// Due to preprocessing, the entrypoint and its function provide no value. // Due to preprocessing, the entrypoint and its function provide no value.
break; break;
case spv::OpExtInstImport: case spv::OpExtInstImport:
{
// We will only support the GLSL 450 extended instruction set, so no point in tracking the ID we assign it. // We will only support the GLSL 450 extended instruction set, so no point in tracking the ID we assign it.
// Valid shaders will not attempt to import any other instruction sets. // Valid shaders will not attempt to import any other instruction sets.
if (0 != strcmp("GLSL.std.450", reinterpret_cast<char const *>(insn.wordPointer(2)))) auto ext = reinterpret_cast<char const *>(insn.wordPointer(2));
if (0 != strcmp("GLSL.std.450", ext))
{ {
UNIMPLEMENTED("Only GLSL extended instruction set is supported"); UNSUPPORTED("SPIR-V Extension: %s", ext);
} }
break; break;
}
case spv::OpName: case spv::OpName:
case spv::OpMemberName: case spv::OpMemberName:
case spv::OpSource: case spv::OpSource:
...@@ -688,16 +697,19 @@ namespace sw ...@@ -688,16 +697,19 @@ namespace sw
case spv::OpSpecConstantTrue: case spv::OpSpecConstantTrue:
// These should have all been removed by preprocessing passes. If we see them here, // These should have all been removed by preprocessing passes. If we see them here,
// our assumptions are wrong and we will probably generate wrong code. // our assumptions are wrong and we will probably generate wrong code.
UNIMPLEMENTED("%s should have already been lowered.", OpcodeName(opcode).c_str()); UNREACHABLE("%s should have already been lowered.", OpcodeName(opcode).c_str());
break; break;
case spv::OpFConvert: case spv::OpFConvert:
UNIMPLEMENTED("No valid uses for OpFConvert until we support multiple bit widths enabled by features such as Float16/Float64 etc."); UNSUPPORTED("SPIR-V Float16 or Float64 Capability (OpFConvert)");
break; break;
case spv::OpSConvert: case spv::OpSConvert:
UNSUPPORTED("SPIR-V Int16 or Int64 Capability (OpSConvert)");
break;
case spv::OpUConvert: case spv::OpUConvert:
UNIMPLEMENTED("No valid uses for Op*Convert until we support multiple bit widths enabled by features such as Int16/Int64 etc."); UNSUPPORTED("SPIR-V Int16 or Int64 Capability (OpUConvert)");
break; break;
case spv::OpLoad: case spv::OpLoad:
...@@ -863,11 +875,11 @@ namespace sw ...@@ -863,11 +875,11 @@ namespace sw
case spv::OpExtension: case spv::OpExtension:
{ {
auto p = reinterpret_cast<char const *>(insn.wordPointer(1)); auto ext = reinterpret_cast<char const *>(insn.wordPointer(1));
// Part of core SPIR-V 1.3. Vulkan 1.1 implementations must also accept the pre-1.3 // Part of core SPIR-V 1.3. Vulkan 1.1 implementations must also accept the pre-1.3
// extension per Appendix A, `Vulkan Environment for SPIR-V`. // extension per Appendix A, `Vulkan Environment for SPIR-V`.
if (!strcmp(p, "SPV_KHR_storage_buffer_storage_class")) break; if (!strcmp(ext, "SPV_KHR_storage_buffer_storage_class")) break;
UNIMPLEMENTED("Unknown extension %s", p); UNSUPPORTED("SPIR-V Extension: %s", ext);
break; break;
} }
...@@ -1065,7 +1077,7 @@ namespace sw ...@@ -1065,7 +1077,7 @@ namespace sw
// This is always the case for a Vulkan shader. Do nothing. // This is always the case for a Vulkan shader. Do nothing.
break; break;
default: default:
UNIMPLEMENTED("No other execution modes are permitted"); UNREACHABLE("Execution mode: %d", int(mode));
} }
} }
...@@ -1122,8 +1134,7 @@ namespace sw ...@@ -1122,8 +1134,7 @@ namespace sw
return 1; return 1;
default: default:
// Some other random insn. UNREACHABLE("%s", OpcodeName(insn.opcode()).c_str());
UNIMPLEMENTED("Only types are supported");
return 0; return 0;
} }
} }
...@@ -1290,7 +1301,7 @@ namespace sw ...@@ -1290,7 +1301,7 @@ namespace sw
break; break;
} }
default: default:
UNIMPLEMENTED("%s", OpcodeName(type.opcode()).c_str()); UNREACHABLE("%s", OpcodeName(type.opcode()).c_str());
} }
} }
...@@ -1397,8 +1408,7 @@ namespace sw ...@@ -1397,8 +1408,7 @@ namespace sw
d->InsideMatrix = true; d->InsideMatrix = true;
break; break;
default: default:
UNIMPLEMENTED("Unexpected type '%s' in ApplyDecorationsForAccessChain", UNREACHABLE("%s", OpcodeName(type.definition.opcode()).c_str());
OpcodeName(type.definition.opcode()).c_str());
} }
} }
} }
...@@ -1498,7 +1508,7 @@ namespace sw ...@@ -1498,7 +1508,7 @@ namespace sw
break; break;
} }
default: default:
UNIMPLEMENTED("Unexpected type '%s' in WalkExplicitLayoutAccessChain", OpcodeName(type.definition.opcode()).c_str()); UNREACHABLE("%s", OpcodeName(type.definition.opcode()).c_str());
} }
} }
...@@ -1547,7 +1557,7 @@ namespace sw ...@@ -1547,7 +1557,7 @@ namespace sw
auto &obj = getObject(indexIds[i]); auto &obj = getObject(indexIds[i]);
if (obj.kind != Object::Kind::Constant) if (obj.kind != Object::Kind::Constant)
{ {
UNIMPLEMENTED("Nonconstant indexing of descriptor arrays is not supported"); UNSUPPORTED("SPIR-V SampledImageArrayDynamicIndexing Capability");
} }
auto d = descriptorDecorations.at(baseId); auto d = descriptorDecorations.at(baseId);
...@@ -1575,7 +1585,7 @@ namespace sw ...@@ -1575,7 +1585,7 @@ namespace sw
} }
default: default:
UNIMPLEMENTED("Unexpected type '%s' in WalkAccessChain", OpcodeName(type.opcode()).c_str()); UNREACHABLE("%s", OpcodeName(type.opcode()).c_str());
} }
} }
...@@ -1620,7 +1630,7 @@ namespace sw ...@@ -1620,7 +1630,7 @@ namespace sw
} }
default: default:
UNIMPLEMENTED("Unexpected type in WalkLiteralAccessChain"); UNREACHABLE("%s", OpcodeName(type.opcode()).c_str());
} }
} }
...@@ -2437,7 +2447,7 @@ namespace sw ...@@ -2437,7 +2447,7 @@ namespace sw
return EmitCopyMemory(insn, state); return EmitCopyMemory(insn, state);
default: default:
UNIMPLEMENTED("%s", OpcodeName(opcode).c_str()); UNREACHABLE("%s", OpcodeName(opcode).c_str());
break; break;
} }
...@@ -2513,7 +2523,7 @@ namespace sw ...@@ -2513,7 +2523,7 @@ namespace sw
break; break;
} }
default: default:
UNIMPLEMENTED("Storage class %d", objectTy.storageClass); UNREACHABLE("Storage class %d", objectTy.storageClass);
break; break;
} }
...@@ -3138,7 +3148,7 @@ namespace sw ...@@ -3138,7 +3148,7 @@ namespace sw
break; break;
} }
default: default:
UNIMPLEMENTED("%s", OpcodeName(insn.opcode()).c_str()); UNREACHABLE("%s", OpcodeName(insn.opcode()).c_str());
} }
} }
...@@ -3334,7 +3344,7 @@ namespace sw ...@@ -3334,7 +3344,7 @@ namespace sw
dst.move(i + lhsType.sizeInComponents, MulHigh(lhs.UInt(i), rhs.UInt(i))); dst.move(i + lhsType.sizeInComponents, MulHigh(lhs.UInt(i), rhs.UInt(i)));
break; break;
default: default:
UNIMPLEMENTED("%s", OpcodeName(insn.opcode()).c_str()); UNREACHABLE("%s", OpcodeName(insn.opcode()).c_str());
} }
} }
...@@ -4177,14 +4187,12 @@ namespace sw ...@@ -4177,14 +4187,12 @@ namespace sw
} }
case GLSLstd450PackDouble2x32: case GLSLstd450PackDouble2x32:
{ {
// Requires Float64 capability. UNSUPPORTED("SPIR-V Float64 Capability (GLSLstd450PackDouble2x32)");
UNIMPLEMENTED("GLSLstd450PackDouble2x32");
break; break;
} }
case GLSLstd450UnpackDouble2x32: case GLSLstd450UnpackDouble2x32:
{ {
// Requires Float64 capability. UNSUPPORTED("SPIR-V Float64 Capability (GLSLstd450UnpackDouble2x32)");
UNIMPLEMENTED("GLSLstd450UnpackDouble2x32");
break; break;
} }
case GLSLstd450FindILsb: case GLSLstd450FindILsb:
...@@ -4218,20 +4226,17 @@ namespace sw ...@@ -4218,20 +4226,17 @@ namespace sw
} }
case GLSLstd450InterpolateAtCentroid: case GLSLstd450InterpolateAtCentroid:
{ {
// Requires sampleRateShading / InterpolationFunction capability. UNSUPPORTED("SPIR-V SampleRateShading Capability (GLSLstd450InterpolateAtCentroid)");
UNIMPLEMENTED("GLSLstd450InterpolateAtCentroid");
break; break;
} }
case GLSLstd450InterpolateAtSample: case GLSLstd450InterpolateAtSample:
{ {
// Requires sampleRateShading / InterpolationFunction capability. UNSUPPORTED("SPIR-V SampleRateShading Capability (GLSLstd450InterpolateAtCentroid)");
UNIMPLEMENTED("GLSLstd450InterpolateAtSample");
break; break;
} }
case GLSLstd450InterpolateAtOffset: case GLSLstd450InterpolateAtOffset:
{ {
// Requires sampleRateShading / InterpolationFunction capability. UNSUPPORTED("SPIR-V SampleRateShading Capability (GLSLstd450InterpolateAtCentroid)");
UNIMPLEMENTED("GLSLstd450InterpolateAtOffset");
break; break;
} }
case GLSLstd450NMin: case GLSLstd450NMin:
...@@ -4267,7 +4272,7 @@ namespace sw ...@@ -4267,7 +4272,7 @@ namespace sw
break; break;
} }
default: default:
UNIMPLEMENTED("Unhandled ExtInst %d", extInstIndex); UNREACHABLE("ExtInst %d", int(extInstIndex));
break; break;
} }
...@@ -4727,7 +4732,7 @@ namespace sw ...@@ -4727,7 +4732,7 @@ namespace sw
break; break;
} }
default: default:
UNIMPLEMENTED("EmitImageQuerySize image descriptorType: %d", int(bindingLayout.descriptorType)); UNREACHABLE("Image descriptorType: %d", int(bindingLayout.descriptorType));
} }
return EmitResult::Continue; return EmitResult::Continue;
...@@ -4996,7 +5001,8 @@ namespace sw ...@@ -4996,7 +5001,8 @@ namespace sw
dst.move(3, SIMD::Float(1)); dst.move(3, SIMD::Float(1));
break; break;
default: default:
UNIMPLEMENTED(""); UNIMPLEMENTED("spv::ImageFormat %d", int(vkFormat));
break;
} }
return EmitResult::Continue; return EmitResult::Continue;
...@@ -5085,8 +5091,38 @@ namespace sw ...@@ -5085,8 +5091,38 @@ namespace sw
packed[1] = SIMD::UInt(texel.UInt(2) & SIMD::UInt(0xffff)) | (SIMD::UInt(texel.UInt(3) & SIMD::UInt(0xffff)) << 16); packed[1] = SIMD::UInt(texel.UInt(2) & SIMD::UInt(0xffff)) | (SIMD::UInt(texel.UInt(3) & SIMD::UInt(0xffff)) << 16);
numPackedElements = 2; numPackedElements = 2;
break; break;
case spv::ImageFormatRg32f:
case spv::ImageFormatRg16f:
case spv::ImageFormatR11fG11fB10f:
case spv::ImageFormatR16f:
case spv::ImageFormatRgba16:
case spv::ImageFormatRgb10A2:
case spv::ImageFormatRg16:
case spv::ImageFormatRg8:
case spv::ImageFormatR16:
case spv::ImageFormatR8:
case spv::ImageFormatRgba16Snorm:
case spv::ImageFormatRg16Snorm:
case spv::ImageFormatRg8Snorm:
case spv::ImageFormatR16Snorm:
case spv::ImageFormatR8Snorm:
case spv::ImageFormatRg32i:
case spv::ImageFormatRg16i:
case spv::ImageFormatRg8i:
case spv::ImageFormatR16i:
case spv::ImageFormatR8i:
case spv::ImageFormatRgb10a2ui:
case spv::ImageFormatRg32ui:
case spv::ImageFormatRg16ui:
case spv::ImageFormatRg8ui:
case spv::ImageFormatR16ui:
case spv::ImageFormatR8ui:
UNIMPLEMENTED("spv::ImageFormat %d", int(format));
break;
default: default:
UNIMPLEMENTED("spv::ImageFormat %u", format); UNREACHABLE("spv::ImageFormat %d", int(format));
break;
} }
auto basePtr = SIMD::Pointer(imageBase, imageSizeInBytes); auto basePtr = SIMD::Pointer(imageBase, imageSizeInBytes);
...@@ -5198,7 +5234,7 @@ namespace sw ...@@ -5198,7 +5234,7 @@ namespace sw
v = ExchangeAtomic(Pointer<UInt>(&ptr.base[offset]), laneValue, memoryOrder); v = ExchangeAtomic(Pointer<UInt>(&ptr.base[offset]), laneValue, memoryOrder);
break; break;
default: default:
UNIMPLEMENTED("%s", OpcodeName(insn.opcode()).c_str()); UNREACHABLE("%s", OpcodeName(insn.opcode()).c_str());
break; break;
} }
x = Insert(x, v, j); x = Insert(x, v, j);
......
...@@ -218,7 +218,7 @@ sw::AddressingMode SpirvShader::convertAddressingMode(int coordinateIndex, VkSam ...@@ -218,7 +218,7 @@ sw::AddressingMode SpirvShader::convertAddressingMode(int coordinateIndex, VkSam
case VK_IMAGE_VIEW_TYPE_CUBE: case VK_IMAGE_VIEW_TYPE_CUBE:
break; break;
case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY: case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
UNSUPPORTED("ImageCubeArray"); UNSUPPORTED("SPIR-V ImageCubeArray Capability (imageViewType: %d)", int(imageViewType));
if(coordinateIndex == 3) if(coordinateIndex == 3)
{ {
return ADDRESSING_LAYER; return ADDRESSING_LAYER;
...@@ -251,7 +251,7 @@ sw::AddressingMode SpirvShader::convertAddressingMode(int coordinateIndex, VkSam ...@@ -251,7 +251,7 @@ sw::AddressingMode SpirvShader::convertAddressingMode(int coordinateIndex, VkSam
case VK_IMAGE_VIEW_TYPE_CUBE: case VK_IMAGE_VIEW_TYPE_CUBE:
return ADDRESSING_SEAMLESS; return ADDRESSING_SEAMLESS;
// case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY: // case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
UNSUPPORTED("ImageCubeArray"); UNSUPPORTED("SPIR-V ImageCubeArray Capability (imageViewType: %d)", int(imageViewType));
return ADDRESSING_SEAMLESS; return ADDRESSING_SEAMLESS;
case VK_IMAGE_VIEW_TYPE_1D: case VK_IMAGE_VIEW_TYPE_1D:
case VK_IMAGE_VIEW_TYPE_2D: case VK_IMAGE_VIEW_TYPE_2D:
......
...@@ -1120,7 +1120,7 @@ var ( ...@@ -1120,7 +1120,7 @@ var (
// Regular expression to parse a test that failed due to UNIMPLEMENTED() // Regular expression to parse a test that failed due to UNIMPLEMENTED()
unimplementedRE = regexp.MustCompile(`[^\n]*UNIMPLEMENTED:[^\n]*`) unimplementedRE = regexp.MustCompile(`[^\n]*UNIMPLEMENTED:[^\n]*`)
// Regular expression to parse a test that failed due to UNSUPPORTED() // Regular expression to parse a test that failed due to UNSUPPORTED()
unsupportedRE = regexp.MustCompile(`[^\n]*UNSUPPORTED\([^\)]*\):[^\n]*`) unsupportedRE = regexp.MustCompile(`[^\n]*UNSUPPORTED:[^\n]*`)
// Regular expression to parse a test that failed due to UNREACHABLE() // Regular expression to parse a test that failed due to UNREACHABLE()
unreachableRE = regexp.MustCompile(`[^\n]*UNREACHABLE:[^\n]*`) unreachableRE = regexp.MustCompile(`[^\n]*UNREACHABLE:[^\n]*`)
// Regular expression to parse a test that failed due to ASSERT() // Regular expression to parse a test that failed due to ASSERT()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment