From d7f38ab4bf7d118f8dd3fa13f5defd345599b506 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Tue, 15 Aug 2017 13:28:16 +0200 Subject: [PATCH] Add support for SPV_KHR_multiview. --- .../vulkan/vert/multiview.nocompat.vk.vert | 15 +++++++++++++++ .../vulkan/vert/multiview.nocompat.vk.vert.vk | 15 +++++++++++++++ shaders/vulkan/vert/multiview.nocompat.vk.vert | 14 ++++++++++++++ spirv_glsl.cpp | 12 ++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 reference/shaders/vulkan/vert/multiview.nocompat.vk.vert create mode 100644 reference/shaders/vulkan/vert/multiview.nocompat.vk.vert.vk create mode 100644 shaders/vulkan/vert/multiview.nocompat.vk.vert diff --git a/reference/shaders/vulkan/vert/multiview.nocompat.vk.vert b/reference/shaders/vulkan/vert/multiview.nocompat.vk.vert new file mode 100644 index 00000000..533738ef --- /dev/null +++ b/reference/shaders/vulkan/vert/multiview.nocompat.vk.vert @@ -0,0 +1,15 @@ +#version 310 es +#extension GL_OVR_multiview2 : require + +layout(binding = 0, std140) uniform MVPs +{ + mat4 MVP[2]; +} _19; + +layout(location = 0) in vec4 Position; + +void main() +{ + gl_Position = _19.MVP[gl_ViewID_OVR] * Position; +} + diff --git a/reference/shaders/vulkan/vert/multiview.nocompat.vk.vert.vk b/reference/shaders/vulkan/vert/multiview.nocompat.vk.vert.vk new file mode 100644 index 00000000..90055473 --- /dev/null +++ b/reference/shaders/vulkan/vert/multiview.nocompat.vk.vert.vk @@ -0,0 +1,15 @@ +#version 310 es +#extension GL_EXT_multiview : require + +layout(set = 0, binding = 0, std140) uniform MVPs +{ + mat4 MVP[2]; +} _19; + +layout(location = 0) in vec4 Position; + +void main() +{ + gl_Position = _19.MVP[gl_ViewIndex] * Position; +} + diff --git a/shaders/vulkan/vert/multiview.nocompat.vk.vert b/shaders/vulkan/vert/multiview.nocompat.vk.vert new file mode 100644 index 00000000..eb1bc766 --- /dev/null +++ b/shaders/vulkan/vert/multiview.nocompat.vk.vert @@ -0,0 +1,14 @@ +#version 310 es +#extension GL_EXT_multiview : require + +layout(std140, binding = 0) uniform MVPs +{ + mat4 MVP[2]; +}; + +layout(location = 0) in vec4 Position; + +void main() +{ + gl_Position = MVP[gl_ViewIndex] * Position; +} diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index e29ae884..a449f9dc 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -3619,6 +3619,18 @@ string CompilerGLSL::builtin_to_glsl(BuiltIn builtin, StorageClass storage) SPIRV_CROSS_THROW("gl_SamplePosition not supported before GLSL 400."); return "gl_SamplePosition"; + case BuiltInViewIndex: + if (options.vulkan_semantics) + { + require_extension("GL_EXT_multiview"); + return "gl_ViewIndex"; + } + else + { + require_extension("GL_OVR_multiview2"); + return "gl_ViewID_OVR"; + } + default: return join("gl_BuiltIn_", convert_to_string(builtin)); }