KhronosGroup / SPIR

Other
178 stars 49 forks source link

Capability Addresses is not allowed by Vulkan 1.0 specification #76

Closed pdsharma0 closed 6 years ago

pdsharma0 commented 6 years ago

Using LunarG's VulkanSDK=1.1.73.0, LLVM=spirv-3.6.1 and clang=spirv-1.0, I generated a SPIR-V binary from an OpenCL kernel and the disassembly looks like this:

; SPIR-V
; Version: 1.0
; Generator: Khronos LLVM/SPIR-V Translator; 14
; Bound: 18
; Schema: 0
               OpCapability Addresses
               OpCapability Linkage
               OpCapability Kernel
          %1 = OpExtInstImport "OpenCL.std"
               OpMemoryModel Physical32 OpenCL
               OpEntryPoint Kernel %9 "CopyBuffer"
               OpSource OpenCL_C 102000
               OpName %__spirv_BuiltInGlobalInvocationId "__spirv_BuiltInGlobalInvocationId"
               OpName %src "src"
               OpName %dst "dst"
               OpName %entry "entry"
               OpName %call "call"
               OpName %arrayidx "arrayidx"
               OpName %arrayidx1 "arrayidx1"
               OpDecorate %__spirv_BuiltInGlobalInvocationId BuiltIn GlobalInvocationId
               OpDecorate %__spirv_BuiltInGlobalInvocationId Constant
               OpDecorate %__spirv_BuiltInGlobalInvocationId LinkageAttributes "__spirv_BuiltInGlobalInvocationId" Import
       %uint = OpTypeInt 32 0
     %v3uint = OpTypeVector %uint 3
%_ptr_UniformConstant_v3uint = OpTypePointer UniformConstant %v3uint
       %void = OpTypeVoid
%_ptr_CrossWorkgroup_uint = OpTypePointer CrossWorkgroup %uint
          %8 = OpTypeFunction %void %_ptr_CrossWorkgroup_uint %_ptr_CrossWorkgroup_uint
%__spirv_BuiltInGlobalInvocationId = OpVariable %_ptr_UniformConstant_v3uint UniformConstant
          %9 = OpFunction %void None %8
        %src = OpFunctionParameter %_ptr_CrossWorkgroup_uint
        %dst = OpFunctionParameter %_ptr_CrossWorkgroup_uint
      %entry = OpLabel
         %13 = OpLoad %v3uint %__spirv_BuiltInGlobalInvocationId
       %call = OpCompositeExtract %uint %13 0
   %arrayidx = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_uint %src %call
         %16 = OpLoad %uint %arrayidx Aligned 4
  %arrayidx1 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_uint %dst %call
               OpStore %arrayidx1 %16 Aligned 4
               OpReturn
               OpFunctionEnd

But trying to create a shader module using vkShaderCreateModule(), this shows up:

Validation(ERROR): msg_code: 5: Object: VK_NULL_HANDLE (Type = 0) | SPIR-V module not valid: Capability Addresses is not allowed by Vulkan 1.0 specification (or requires extension)

This seems strange as I can see Addresses listed under the Capabilities column in SPIR-V 1.0 (https://www.khronos.org/registry/spir-v/specs/1.0/SPIRV.html#Capability).

The vkEnumerateInstanceVersion() returns 1.1.73 so I am definitely above Vulkan 1.0 version as well.

Also, the function returns a VK_ERROR_INITIALIZATION_FAILED code which doesn't seem to be inline with possible return return codes listed here : https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/vkCreateShaderModule.html. This seems more of an issue with AMD's Vulkan implementation though.

pdsharma0 commented 6 years ago

Tried the spirv-1.1 branch and still seeing the same error. The disassembly still shows Version: 1.0 but it should be have 1.1 instead.

Also, clang executable is no more, I see a clang-cl.exe instead now so looks like we need to update the README for the 1.1 branch. Help (--h) doesn't work for clang-cl but works fine for clang++. Will look into this discrepancy.

pdsharma0 commented 6 years ago

https://github.com/KhronosGroup/SPIRV-LLVM/issues/236