KhronosGroup / SPIRV-Tools

Apache License 2.0
1.05k stars 549 forks source link

validate minimum SPIR-V version for operands #1602

Open dneto0 opened 6 years ago

dneto0 commented 6 years ago

VersionCheck in validate_instruction.cpp checks minimum version for a SPIR-V opcode. But it ignores min-version constraints on operands.

For example, when assembled with --target-env spv1.0, the following should fail validation because StorageBuffer is not in SPIR-V 1.0 core. (StorageBuffer is enabled by SPV_KHR_storage_buffer_storage_class)

; SPIR-V
; Version: 1.0
; Generator: Khronos SPIR-V Tools Assembler; 0
; Bound: 3
; Schema: 0
               OpCapability Shader
               OpCapability Linkage
               OpMemoryModel Logical GLSL450
       %uint = OpTypeInt 32 0
%_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
dneto0 commented 6 years ago

This should pass validation when assembled for 1.0:

               OpCapability Shader
               OpCapability Linkage
        OpExtension "SPV_KHR_storage_buffer_storage_class"
               OpMemoryModel Logical GLSL450
       %uint = OpTypeInt 32 0
%_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
dneto0 commented 5 years ago

I have a fix for this pending