From 5c574938557742d5cab14e514c50cf55b4ccc157 Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 15 Jul 2020 13:53:56 +0100 Subject: [PATCH] Share common shader source on vulkan --- util/test/demos/gl/gl_test.cpp | 2 +- util/test/demos/vk/vk_cbuffer_zoo.cpp | 37 +------------- util/test/demos/vk/vk_discard_rects.cpp | 48 +---------------- util/test/demos/vk/vk_extended_dyn_state.cpp | 48 +---------------- util/test/demos/vk/vk_image_layouts.cpp | 48 +---------------- .../demos/vk/vk_imageless_framebuffer.cpp | 38 ++------------ util/test/demos/vk/vk_indirect.cpp | 48 +---------------- util/test/demos/vk/vk_int8_ibuffer.cpp | 48 +---------------- util/test/demos/vk/vk_large_buffer.cpp | 48 +---------------- util/test/demos/vk/vk_mesh_zoo.cpp | 14 ++--- util/test/demos/vk/vk_misaligned_dirty.cpp | 48 +---------------- .../test/demos/vk/vk_multi_thread_windows.cpp | 48 +---------------- util/test/demos/vk/vk_parameter_zoo.cpp | 51 ++----------------- util/test/demos/vk/vk_query_pool.cpp | 48 +---------------- util/test/demos/vk/vk_sample_locations.cpp | 48 +---------------- util/test/demos/vk/vk_secondary_cmdbuf.cpp | 48 +---------------- util/test/demos/vk/vk_shader_isa.cpp | 48 +---------------- util/test/demos/vk/vk_simple_triangle.cpp | 48 +---------------- util/test/demos/vk/vk_test.cpp | 44 ++++++++++++++++ util/test/demos/vk/vk_test.h | 3 ++ util/test/demos/vk/vk_triangle_fan.cpp | 48 +---------------- 21 files changed, 90 insertions(+), 771 deletions(-) diff --git a/util/test/demos/gl/gl_test.cpp b/util/test/demos/gl/gl_test.cpp index 8cae33b3f..5998d5805 100644 --- a/util/test/demos/gl/gl_test.cpp +++ b/util/test/demos/gl/gl_test.cpp @@ -25,7 +25,7 @@ #include "gl_test.h" #include -std::string common = R"EOSHADER( +static std::string common = R"EOSHADER( #version 420 core diff --git a/util/test/demos/vk/vk_cbuffer_zoo.cpp b/util/test/demos/vk/vk_cbuffer_zoo.cpp index 1efef36a1..b5e0e378b 100644 --- a/util/test/demos/vk/vk_cbuffer_zoo.cpp +++ b/util/test/demos/vk/vk_cbuffer_zoo.cpp @@ -29,41 +29,8 @@ RD_TEST(VK_CBuffer_Zoo, VulkanGraphicsTest) static constexpr const char *Description = "Tests every kind of constant that can be in a cbuffer to make sure it's decoded correctly."; - std::string common = R"EOSHADER( - -#version 430 core - -struct v2f -{ - vec4 pos; - vec4 col; - vec4 uv; -}; - -)EOSHADER"; - - std::string vertex = R"EOSHADER( - -layout(location = 0) in vec3 Position; -layout(location = 1) in vec4 Color; -layout(location = 2) in vec2 UV; - -layout(location = 0) out v2f vertOut; - -void main() -{ - vertOut.pos = vec4(Position.xyz, 1); - gl_Position = vertOut.pos; - vertOut.col = Color; - vertOut.uv = vec4(UV.xy, 0, 1); -} - -)EOSHADER"; - std::string glslpixel = R"EOSHADER( -layout(location = 0) in v2f vertIn; - layout(location = 0, index = 0) out vec4 Color; struct vec3_1 { vec3 a; float b; }; @@ -620,8 +587,8 @@ float4 main() : SV_Target0 }; pipeCreateInfo.stages = { - CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"), - CompileShaderModule(common + glslpixel, ShaderLang::glsl, ShaderStage::frag, "main"), + CompileShaderModule(VKDefaultVertex, ShaderLang::glsl, ShaderStage::vert, "main"), + CompileShaderModule(glslpixel, ShaderLang::glsl, ShaderStage::frag, "main"), }; float data[2] = {20.0f, 0.0f}; diff --git a/util/test/demos/vk/vk_discard_rects.cpp b/util/test/demos/vk/vk_discard_rects.cpp index 1cb6ba034..105a04dd4 100644 --- a/util/test/demos/vk/vk_discard_rects.cpp +++ b/util/test/demos/vk/vk_discard_rects.cpp @@ -30,50 +30,6 @@ RD_TEST(VK_Discard_Rectangles, VulkanGraphicsTest) "Draws a large number of triangles using VK_EXT_discard_rectangles discard rectangles to " "either cut-out or filter for a series of rects"; - std::string common = R"EOSHADER( - -#version 420 core - -struct v2f -{ - vec4 pos; - vec4 col; - vec4 uv; -}; - -)EOSHADER"; - - const std::string vertex = R"EOSHADER( - -layout(location = 0) in vec3 Position; -layout(location = 1) in vec4 Color; -layout(location = 2) in vec2 UV; - -layout(location = 0) out v2f vertOut; - -void main() -{ - vertOut.pos = vec4(Position.xyz*vec3(1,-1,1), 1); - gl_Position = vertOut.pos; - vertOut.col = Color; - vertOut.uv = vec4(UV.xy, 0, 1); -} - -)EOSHADER"; - - const std::string pixel = R"EOSHADER( - -layout(location = 0) in v2f vertIn; - -layout(location = 0, index = 0) out vec4 Color; - -void main() -{ - Color = vertIn.col; -} - -)EOSHADER"; - void Prepare(int argc, char **argv) { devExts.push_back(VK_EXT_DISCARD_RECTANGLES_EXTENSION_NAME); @@ -127,8 +83,8 @@ void main() }; pipeCreateInfo.stages = { - CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"), - CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"), + CompileShaderModule(VKDefaultVertex, ShaderLang::glsl, ShaderStage::vert, "main"), + CompileShaderModule(VKDefaultPixel, ShaderLang::glsl, ShaderStage::frag, "main"), }; pipeCreateInfo.dynamicState.dynamicStates.push_back(VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT); diff --git a/util/test/demos/vk/vk_extended_dyn_state.cpp b/util/test/demos/vk/vk_extended_dyn_state.cpp index 012011831..8fd951d33 100644 --- a/util/test/demos/vk/vk_extended_dyn_state.cpp +++ b/util/test/demos/vk/vk_extended_dyn_state.cpp @@ -29,50 +29,6 @@ RD_TEST(VK_Extended_Dynamic_State, VulkanGraphicsTest) static constexpr const char *Description = "Tests all possible dynamic state from VK_EXT_extended_dynamic_state"; - std::string common = R"EOSHADER( - -#version 420 core - -struct v2f -{ - vec4 pos; - vec4 col; - vec4 uv; -}; - -)EOSHADER"; - - const std::string vertex = R"EOSHADER( - -layout(location = 0) in vec3 Position; -layout(location = 1) in vec4 Color; -layout(location = 2) in vec2 UV; - -layout(location = 0) out v2f vertOut; - -void main() -{ - vertOut.pos = vec4(Position.xyz, 1); - gl_Position = vertOut.pos; - vertOut.col = Color; - vertOut.uv = vec4(UV.xy, 0, 1); -} - -)EOSHADER"; - - const std::string pixel = R"EOSHADER( - -layout(location = 0) in v2f vertIn; - -layout(location = 0, index = 0) out vec4 Color; - -void main() -{ - Color = vertIn.col; -} - -)EOSHADER"; - void Prepare(int argc, char **argv) { devExts.push_back(VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME); @@ -124,8 +80,8 @@ void main() }; pipeCreateInfo.stages = { - CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"), - CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"), + CompileShaderModule(VKDefaultVertex, ShaderLang::glsl, ShaderStage::vert, "main"), + CompileShaderModule(VKDefaultPixel, ShaderLang::glsl, ShaderStage::frag, "main"), }; pipeCreateInfo.viewportState.scissorCount = 0; diff --git a/util/test/demos/vk/vk_image_layouts.cpp b/util/test/demos/vk/vk_image_layouts.cpp index dfaaed776..3f9160fe6 100644 --- a/util/test/demos/vk/vk_image_layouts.cpp +++ b/util/test/demos/vk/vk_image_layouts.cpp @@ -30,50 +30,6 @@ RD_TEST(VK_Image_Layouts, VulkanGraphicsTest) "Tests edge-cases of image layout transitions, such as images being in UNDEFINED, " "PREINITIALIZED or PRESENT_SRC at the start of the frame."; - std::string common = R"EOSHADER( - -#version 420 core - -struct v2f -{ - vec4 pos; - vec4 col; - vec4 uv; -}; - -)EOSHADER"; - - const std::string vertex = R"EOSHADER( - -layout(location = 0) in vec3 Position; -layout(location = 1) in vec4 Color; -layout(location = 2) in vec2 UV; - -layout(location = 0) out v2f vertOut; - -void main() -{ - vertOut.pos = vec4(Position.xyz*vec3(1,-1,1), 1); - gl_Position = vertOut.pos; - vertOut.col = Color; - vertOut.uv = vec4(UV.xy, 0, 1); -} - -)EOSHADER"; - - const std::string pixel = R"EOSHADER( - -layout(location = 0) in v2f vertIn; - -layout(location = 0, index = 0) out vec4 Color; - -void main() -{ - Color = vertIn.col; -} - -)EOSHADER"; - int main() { // initialise, create window, create context, etc @@ -94,8 +50,8 @@ void main() }; pipeCreateInfo.stages = { - CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"), - CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"), + CompileShaderModule(VKDefaultVertex, ShaderLang::glsl, ShaderStage::vert, "main"), + CompileShaderModule(VKDefaultPixel, ShaderLang::glsl, ShaderStage::frag, "main"), }; VkPipeline pipe = createGraphicsPipeline(pipeCreateInfo); diff --git a/util/test/demos/vk/vk_imageless_framebuffer.cpp b/util/test/demos/vk/vk_imageless_framebuffer.cpp index acabf6ae2..8d25c23c3 100644 --- a/util/test/demos/vk/vk_imageless_framebuffer.cpp +++ b/util/test/demos/vk/vk_imageless_framebuffer.cpp @@ -29,40 +29,8 @@ RD_TEST(VK_Imageless_Framebuffer, VulkanGraphicsTest) static constexpr const char *Description = "Test using VK_KHR_imageless_framebuffer to specify image views at the last second"; - std::string common = R"EOSHADER( - -#version 420 core - -struct v2f -{ - vec4 pos; - vec4 col; - vec4 uv; -}; - -)EOSHADER"; - - const std::string vertex = R"EOSHADER( - -layout(location = 0) in vec3 Position; -layout(location = 1) in vec4 Color; -layout(location = 2) in vec2 UV; - -layout(location = 0) out v2f vertOut; - -void main() -{ - vertOut.pos = vec4(Position.xyz*vec3(1,-1,1), 1); - gl_Position = vertOut.pos; - vertOut.col = Color; - vertOut.uv = vec4(UV.xy, 0, 1); -} - -)EOSHADER"; - const std::string pixel = R"EOSHADER( - -layout(location = 0) in v2f vertIn; +#version 460 core layout(location = 0, index = 0) out vec4 Color; @@ -118,8 +86,8 @@ void main() }; pipeCreateInfo.stages = { - CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"), - CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"), + CompileShaderModule(VKDefaultVertex, ShaderLang::glsl, ShaderStage::vert, "main"), + CompileShaderModule(VKDefaultPixel, ShaderLang::glsl, ShaderStage::frag, "main"), }; VkPipeline pipe = createGraphicsPipeline(pipeCreateInfo); diff --git a/util/test/demos/vk/vk_indirect.cpp b/util/test/demos/vk/vk_indirect.cpp index e8a286af9..9583a3feb 100644 --- a/util/test/demos/vk/vk_indirect.cpp +++ b/util/test/demos/vk/vk_indirect.cpp @@ -30,50 +30,6 @@ RD_TEST(VK_Indirect, VulkanGraphicsTest) "Tests different indirect drawing and dispatching functions, including parameters that are " "generated on the GPU and not known on the CPU at submit time"; - std::string common = R"EOSHADER( - -#version 420 core - -struct v2f -{ - vec4 pos; - vec4 col; - vec4 uv; -}; - -)EOSHADER"; - - const std::string vertex = R"EOSHADER( - -layout(location = 0) in vec3 Position; -layout(location = 1) in vec4 Color; -layout(location = 2) in vec2 UV; - -layout(location = 0) out v2f vertOut; - -void main() -{ - vertOut.pos = vec4(Position.xyz*vec3(1,-1,1), 1); - gl_Position = vertOut.pos; - vertOut.col = Color; - vertOut.uv = vec4(UV.xy, 0, 1); -} - -)EOSHADER"; - - const std::string pixel = R"EOSHADER( - -layout(location = 0) in v2f vertIn; - -layout(location = 0, index = 0) out vec4 Color; - -void main() -{ - Color = vertIn.col; -} - -)EOSHADER"; - const std::string compute = R"EOSHADER( #version 430 core @@ -183,8 +139,8 @@ void main() }; pipeCreateInfo.stages = { - CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"), - CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"), + CompileShaderModule(VKDefaultVertex, ShaderLang::glsl, ShaderStage::vert, "main"), + CompileShaderModule(VKDefaultPixel, ShaderLang::glsl, ShaderStage::frag, "main"), }; VkPipeline drawpipe = createGraphicsPipeline(pipeCreateInfo); diff --git a/util/test/demos/vk/vk_int8_ibuffer.cpp b/util/test/demos/vk/vk_int8_ibuffer.cpp index 45d20be8f..1229a3736 100644 --- a/util/test/demos/vk/vk_int8_ibuffer.cpp +++ b/util/test/demos/vk/vk_int8_ibuffer.cpp @@ -28,50 +28,6 @@ RD_TEST(VK_Int8_IBuffer, VulkanGraphicsTest) { static constexpr const char *Description = "Draws a triangle strip with 8-bit width indices"; - std::string common = R"EOSHADER( - -#version 420 core - -struct v2f -{ - vec4 pos; - vec4 col; - vec4 uv; -}; - -)EOSHADER"; - - const std::string vertex = R"EOSHADER( - -layout(location = 0) in vec3 Position; -layout(location = 1) in vec4 Color; -layout(location = 2) in vec2 UV; - -layout(location = 0) out v2f vertOut; - -void main() -{ - vertOut.pos = vec4(Position.xyz*vec3(1,-1,1), 1); - gl_Position = vertOut.pos; - vertOut.col = Color; - vertOut.uv = vec4(UV.xy, 0, 1); -} - -)EOSHADER"; - - const std::string pixel = R"EOSHADER( - -layout(location = 0) in v2f vertIn; - -layout(location = 0, index = 0) out vec4 Color; - -void main() -{ - Color = vertIn.col; -} - -)EOSHADER"; - void Prepare(int argc, char **argv) { devExts.push_back(VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME); @@ -105,8 +61,8 @@ void main() }; pipeCreateInfo.stages = { - CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"), - CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"), + CompileShaderModule(VKDefaultVertex, ShaderLang::glsl, ShaderStage::vert, "main"), + CompileShaderModule(VKDefaultPixel, ShaderLang::glsl, ShaderStage::frag, "main"), }; pipeCreateInfo.inputAssemblyState.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; diff --git a/util/test/demos/vk/vk_large_buffer.cpp b/util/test/demos/vk/vk_large_buffer.cpp index 105208efd..62de3f085 100644 --- a/util/test/demos/vk/vk_large_buffer.cpp +++ b/util/test/demos/vk/vk_large_buffer.cpp @@ -29,50 +29,6 @@ RD_TEST(VK_Large_Buffer, VulkanGraphicsTest) static constexpr const char *Description = "Draws a triangle over the span of a very large buffer to ensure readbacks work correctly."; - std::string common = R"EOSHADER( - -#version 420 core - -struct v2f -{ - vec4 pos; - vec4 col; - vec4 uv; -}; - -)EOSHADER"; - - const std::string vertex = R"EOSHADER( - -layout(location = 0) in vec3 Position; -layout(location = 1) in vec4 Color; -layout(location = 2) in vec2 UV; - -layout(location = 0) out v2f vertOut; - -void main() -{ - vertOut.pos = vec4(Position.xyz*vec3(1,-1,1), 1); - gl_Position = vertOut.pos; - vertOut.col = Color; - vertOut.uv = vec4(UV.xy, 0, 1); -} - -)EOSHADER"; - - const std::string pixel = R"EOSHADER( - -layout(location = 0) in v2f vertIn; - -layout(location = 0, index = 0) out vec4 Color; - -void main() -{ - Color = vertIn.col; -} - -)EOSHADER"; - int main() { // initialise, create window, create context, etc @@ -93,8 +49,8 @@ void main() }; pipeCreateInfo.stages = { - CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"), - CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"), + CompileShaderModule(VKDefaultVertex, ShaderLang::glsl, ShaderStage::vert, "main"), + CompileShaderModule(VKDefaultPixel, ShaderLang::glsl, ShaderStage::frag, "main"), }; VkPipeline pipe = createGraphicsPipeline(pipeCreateInfo); diff --git a/util/test/demos/vk/vk_mesh_zoo.cpp b/util/test/demos/vk/vk_mesh_zoo.cpp index 766f8606f..9ba39b41b 100644 --- a/util/test/demos/vk/vk_mesh_zoo.cpp +++ b/util/test/demos/vk/vk_mesh_zoo.cpp @@ -28,13 +28,8 @@ RD_TEST(VK_Mesh_Zoo, VulkanGraphicsTest) { static constexpr const char *Description = "Draws some primitives for testing the mesh view."; - std::string common = R"EOSHADER( - -#version 420 core - -)EOSHADER"; - std::string vertex = R"EOSHADER( +#version 460 core layout(location = 0) in vec3 Position; layout(location = 1) in vec4 Color; @@ -71,6 +66,7 @@ void main() )EOSHADER"; std::string pixel = R"EOSHADER( +#version 460 core layout(location = 0) in vec2 vertInCol2; layout(location = 1) in vec4 vertIncol; @@ -170,8 +166,8 @@ void main() }; pipeCreateInfo.stages = { - CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"), - CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"), + CompileShaderModule(vertex, ShaderLang::glsl, ShaderStage::vert, "main"), + CompileShaderModule(pixel, ShaderLang::glsl, ShaderStage::frag, "main"), }; pipeCreateInfo.depthStencilState.depthTestEnable = VK_TRUE; @@ -181,7 +177,7 @@ void main() VkPipeline pipe = createGraphicsPipeline(pipeCreateInfo); - pipeCreateInfo.stages[0] = CompileShaderModule(common + "\n#define USE_POINTS\n" + vertex, + pipeCreateInfo.stages[0] = CompileShaderModule("\n#define USE_POINTS\n" + vertex, ShaderLang::glsl, ShaderStage::vert, "main"), pipeCreateInfo.inputAssemblyState.topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; diff --git a/util/test/demos/vk/vk_misaligned_dirty.cpp b/util/test/demos/vk/vk_misaligned_dirty.cpp index 5ece54098..5e6f4dd50 100644 --- a/util/test/demos/vk/vk_misaligned_dirty.cpp +++ b/util/test/demos/vk/vk_misaligned_dirty.cpp @@ -30,50 +30,6 @@ RD_TEST(VK_Misaligned_Dirty, VulkanGraphicsTest) "Generate a case where the initial states for a buffer end up being misaligned with what can " "be cleared."; - std::string common = R"EOSHADER( - -#version 420 core - -struct v2f -{ - vec4 pos; - vec4 col; - vec4 uv; -}; - -)EOSHADER"; - - const std::string vertex = R"EOSHADER( - -layout(location = 0) in vec3 Position; -layout(location = 1) in vec4 Color; -layout(location = 2) in vec2 UV; - -layout(location = 0) out v2f vertOut; - -void main() -{ - vertOut.pos = vec4(Position.xyz*vec3(1,-1,1), 1); - gl_Position = vertOut.pos; - vertOut.col = Color; - vertOut.uv = vec4(UV.xy, 0, 1); -} - -)EOSHADER"; - - const std::string pixel = R"EOSHADER( - -layout(location = 0) in v2f vertIn; - -layout(location = 0, index = 0) out vec4 Color; - -void main() -{ - Color = vertIn.col; -} - -)EOSHADER"; - int main() { // initialise, create window, create context, etc @@ -94,8 +50,8 @@ void main() }; pipeCreateInfo.stages = { - CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"), - CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"), + CompileShaderModule(VKDefaultVertex, ShaderLang::glsl, ShaderStage::vert, "main"), + CompileShaderModule(VKDefaultPixel, ShaderLang::glsl, ShaderStage::frag, "main"), }; VkPipeline pipe = createGraphicsPipeline(pipeCreateInfo); diff --git a/util/test/demos/vk/vk_multi_thread_windows.cpp b/util/test/demos/vk/vk_multi_thread_windows.cpp index ff5809e1f..997810eb7 100644 --- a/util/test/demos/vk/vk_multi_thread_windows.cpp +++ b/util/test/demos/vk/vk_multi_thread_windows.cpp @@ -30,50 +30,6 @@ RD_TEST(VK_Multi_Thread_Windows, VulkanGraphicsTest) static constexpr const char *Description = "Draws to as many windows as it can in parallel (one queue/thread per window)."; - std::string common = R"EOSHADER( - -#version 420 core - -struct v2f -{ - vec4 pos; - vec4 col; - vec4 uv; -}; - -)EOSHADER"; - - const std::string vertex = R"EOSHADER( - -layout(location = 0) in vec3 Position; -layout(location = 1) in vec4 Color; -layout(location = 2) in vec2 UV; - -layout(location = 0) out v2f vertOut; - -void main() -{ - vertOut.pos = vec4(Position.xyz*vec3(1,-1,1), 1); - gl_Position = vertOut.pos; - vertOut.col = Color; - vertOut.uv = vec4(UV.xy, 0, 1); -} - -)EOSHADER"; - - const std::string pixel = R"EOSHADER( - -layout(location = 0) in v2f vertIn; - -layout(location = 0, index = 0) out vec4 Color; - -void main() -{ - Color = vertIn.col; -} - -)EOSHADER"; - int main() { std::vector queueProps; @@ -115,8 +71,8 @@ void main() }; pipeCreateInfo.stages = { - CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"), - CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"), + CompileShaderModule(VKDefaultVertex, ShaderLang::glsl, ShaderStage::vert, "main"), + CompileShaderModule(VKDefaultPixel, ShaderLang::glsl, ShaderStage::frag, "main"), }; VkPipeline pipe = createGraphicsPipeline(pipeCreateInfo); diff --git a/util/test/demos/vk/vk_parameter_zoo.cpp b/util/test/demos/vk/vk_parameter_zoo.cpp index b1b867eab..d254f6787 100644 --- a/util/test/demos/vk/vk_parameter_zoo.cpp +++ b/util/test/demos/vk/vk_parameter_zoo.cpp @@ -34,52 +34,9 @@ RD_TEST(VK_Parameter_Zoo, VulkanGraphicsTest) "General tests of parameters known to cause problems - e.g. optional values that should be " "ignored, edge cases, special values, etc."; - std::string common = R"EOSHADER( - -#version 420 core - -struct v2f -{ - vec4 pos; - vec4 col; - vec4 uv; -}; - -)EOSHADER"; - - const std::string vertex = R"EOSHADER( - -layout(location = 0) in vec3 Position; -layout(location = 1) in vec4 Color; -layout(location = 2) in vec2 UV; - -layout(location = 0) out v2f vertOut; - -void main() -{ - vertOut.pos = vec4(Position.xyz*vec3(1,-1,1), 1); - gl_Position = vertOut.pos; - vertOut.col = Color; - vertOut.uv = vec4(UV.xy, 0, 1); -} - -)EOSHADER"; - - const std::string pixel = R"EOSHADER( - -layout(location = 0) in v2f vertIn; - -layout(location = 0, index = 0) out vec4 Color; - -void main() -{ - Color = vertIn.col; -} - -)EOSHADER"; - const std::string pixel2 = R"EOSHADER( #version 450 core + #extension GL_EXT_samplerless_texture_functions : enable layout(location = 0, index = 0) out vec4 Color; @@ -367,8 +324,8 @@ void main() }; pipeCreateInfo.stages = { - CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"), - CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"), + CompileShaderModule(VKDefaultVertex, ShaderLang::glsl, ShaderStage::vert, "main"), + CompileShaderModule(VKDefaultPixel, ShaderLang::glsl, ShaderStage::frag, "main"), }; VkPipeline pipe = createGraphicsPipeline(pipeCreateInfo); @@ -382,7 +339,7 @@ void main() VkPipeline refpipe = createGraphicsPipeline(pipeCreateInfo); pipeCreateInfo.stages = { - CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"), + CompileShaderModule(VKDefaultVertex, ShaderLang::glsl, ShaderStage::vert, "main"), CompileShaderModule(pixel2, ShaderLang::glsl, ShaderStage::frag, "main"), }; diff --git a/util/test/demos/vk/vk_query_pool.cpp b/util/test/demos/vk/vk_query_pool.cpp index 9df4efb6d..e5f052d13 100644 --- a/util/test/demos/vk/vk_query_pool.cpp +++ b/util/test/demos/vk/vk_query_pool.cpp @@ -28,50 +28,6 @@ RD_TEST(VK_Query_Pool, VulkanGraphicsTest) { static constexpr const char *Description = "Tests using a large query pool."; - std::string common = R"EOSHADER( - -#version 420 core - -struct v2f -{ - vec4 pos; - vec4 col; - vec4 uv; -}; - -)EOSHADER"; - - const std::string vertex = R"EOSHADER( - -layout(location = 0) in vec3 Position; -layout(location = 1) in vec4 Color; -layout(location = 2) in vec2 UV; - -layout(location = 0) out v2f vertOut; - -void main() -{ - vertOut.pos = vec4(Position.xyz*vec3(1,-1,1), 1); - gl_Position = vertOut.pos; - vertOut.col = Color; - vertOut.uv = vec4(UV.xy, 0, 1); -} - -)EOSHADER"; - - const std::string pixel = R"EOSHADER( - -layout(location = 0) in v2f vertIn; - -layout(location = 0, index = 0) out vec4 Color; - -void main() -{ - Color = vertIn.col; -} - -)EOSHADER"; - void Prepare(int argc, char **argv) { features.pipelineStatisticsQuery = true; @@ -99,8 +55,8 @@ void main() }; pipeCreateInfo.stages = { - CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"), - CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"), + CompileShaderModule(VKDefaultVertex, ShaderLang::glsl, ShaderStage::vert, "main"), + CompileShaderModule(VKDefaultPixel, ShaderLang::glsl, ShaderStage::frag, "main"), }; VkPipeline pipe = createGraphicsPipeline(pipeCreateInfo); diff --git a/util/test/demos/vk/vk_sample_locations.cpp b/util/test/demos/vk/vk_sample_locations.cpp index abd56cdbb..a33349a27 100644 --- a/util/test/demos/vk/vk_sample_locations.cpp +++ b/util/test/demos/vk/vk_sample_locations.cpp @@ -29,50 +29,6 @@ RD_TEST(VK_Sample_Locations, VulkanGraphicsTest) static constexpr const char *Description = "Draws two triangles with different sample locations using VK_EXT_sample_locations"; - std::string common = R"EOSHADER( - -#version 420 core - -struct v2f -{ - vec4 pos; - vec4 col; - vec4 uv; -}; - -)EOSHADER"; - - const std::string vertex = R"EOSHADER( - -layout(location = 0) in vec3 Position; -layout(location = 1) in vec4 Color; -layout(location = 2) in vec2 UV; - -layout(location = 0) out v2f vertOut; - -void main() -{ - vertOut.pos = vec4(Position.xyz*vec3(1,-1,1), 1); - gl_Position = vertOut.pos; - vertOut.col = Color; - vertOut.uv = vec4(UV.xy, 0, 1); -} - -)EOSHADER"; - - const std::string pixel = R"EOSHADER( - -layout(location = 0) in v2f vertIn; - -layout(location = 0, index = 0) out vec4 Color; - -void main() -{ - Color = vertIn.col; -} - -)EOSHADER"; - void Prepare(int argc, char **argv) { devExts.push_back(VK_EXT_SAMPLE_LOCATIONS_EXTENSION_NAME); @@ -144,8 +100,8 @@ void main() }; pipeCreateInfo.stages = { - CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"), - CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"), + CompileShaderModule(VKDefaultVertex, ShaderLang::glsl, ShaderStage::vert, "main"), + CompileShaderModule(VKDefaultPixel, ShaderLang::glsl, ShaderStage::frag, "main"), }; pipeCreateInfo.dynamicState.dynamicStates.push_back(VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT); diff --git a/util/test/demos/vk/vk_secondary_cmdbuf.cpp b/util/test/demos/vk/vk_secondary_cmdbuf.cpp index 1e0d61f86..40eaa5a1a 100644 --- a/util/test/demos/vk/vk_secondary_cmdbuf.cpp +++ b/util/test/demos/vk/vk_secondary_cmdbuf.cpp @@ -28,50 +28,6 @@ RD_TEST(VK_Secondary_CmdBuf, VulkanGraphicsTest) { static constexpr const char *Description = "Draw using secondary command buffers"; - std::string common = R"EOSHADER( - -#version 420 core - -struct v2f -{ - vec4 pos; - vec4 col; - vec4 uv; -}; - -)EOSHADER"; - - const std::string vertex = R"EOSHADER( - -layout(location = 0) in vec3 Position; -layout(location = 1) in vec4 Color; -layout(location = 2) in vec2 UV; - -layout(location = 0) out v2f vertOut; - -void main() -{ - vertOut.pos = vec4(Position.xyz*vec3(1,-1,1), 1); - gl_Position = vertOut.pos; - vertOut.col = Color; - vertOut.uv = vec4(UV.xy, 0, 1); -} - -)EOSHADER"; - - const std::string pixel = R"EOSHADER( - -layout(location = 0) in v2f vertIn; - -layout(location = 0, index = 0) out vec4 Color; - -void main() -{ - Color = vertIn.col; -} - -)EOSHADER"; - int main() { // initialise, create window, create context, etc @@ -122,8 +78,8 @@ void main() }; pipeCreateInfo.stages = { - CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"), - CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"), + CompileShaderModule(VKDefaultVertex, ShaderLang::glsl, ShaderStage::vert, "main"), + CompileShaderModule(VKDefaultPixel, ShaderLang::glsl, ShaderStage::frag, "main"), }; pipeCreateInfo.subpass = 0; diff --git a/util/test/demos/vk/vk_shader_isa.cpp b/util/test/demos/vk/vk_shader_isa.cpp index 45c523e97..8aeb5f8a2 100644 --- a/util/test/demos/vk/vk_shader_isa.cpp +++ b/util/test/demos/vk/vk_shader_isa.cpp @@ -30,50 +30,6 @@ RD_TEST(VK_Shader_ISA, VulkanGraphicsTest) "Draws a simple triangle with markers indicating which types of shader ISA we expect to be " "available (i.e. running on AMD or not)"; - std::string common = R"EOSHADER( - -#version 420 core - -struct v2f -{ - vec4 pos; - vec4 col; - vec4 uv; -}; - -)EOSHADER"; - - const std::string vertex = R"EOSHADER( - -layout(location = 0) in vec3 Position; -layout(location = 1) in vec4 Color; -layout(location = 2) in vec2 UV; - -layout(location = 0) out v2f vertOut; - -void main() -{ - vertOut.pos = vec4(Position.xyz*vec3(1,-1,1), 1); - gl_Position = vertOut.pos; - vertOut.col = Color; - vertOut.uv = vec4(UV.xy, 0, 1); -} - -)EOSHADER"; - - const std::string pixel = R"EOSHADER( - -layout(location = 0) in v2f vertIn; - -layout(location = 0, index = 0) out vec4 Color; - -void main() -{ - Color = vertIn.col; -} - -)EOSHADER"; - int main() { // initialise, create window, create context, etc @@ -94,8 +50,8 @@ void main() }; pipeCreateInfo.stages = { - CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"), - CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"), + CompileShaderModule(VKDefaultVertex, ShaderLang::glsl, ShaderStage::vert, "main"), + CompileShaderModule(VKDefaultPixel, ShaderLang::glsl, ShaderStage::frag, "main"), }; VkPipeline pipe = createGraphicsPipeline(pipeCreateInfo); diff --git a/util/test/demos/vk/vk_simple_triangle.cpp b/util/test/demos/vk/vk_simple_triangle.cpp index 97fbb71d9..8f05ef098 100644 --- a/util/test/demos/vk/vk_simple_triangle.cpp +++ b/util/test/demos/vk/vk_simple_triangle.cpp @@ -30,50 +30,6 @@ RD_TEST(VK_Simple_Triangle, VulkanGraphicsTest) "Just draws a simple triangle, using normal pipeline. Basic test that can be used " "for any dead-simple tests that don't require any particular API use"; - std::string common = R"EOSHADER( - -#version 420 core - -struct v2f -{ - vec4 pos; - vec4 col; - vec4 uv; -}; - -)EOSHADER"; - - const std::string vertex = R"EOSHADER( - -layout(location = 0) in vec3 Position; -layout(location = 1) in vec4 Color; -layout(location = 2) in vec2 UV; - -layout(location = 0) out v2f vertOut; - -void main() -{ - vertOut.pos = vec4(Position.xyz*vec3(1,-1,1), 1); - gl_Position = vertOut.pos; - vertOut.col = Color; - vertOut.uv = vec4(UV.xy, 0, 1); -} - -)EOSHADER"; - - const std::string pixel = R"EOSHADER( - -layout(location = 0) in v2f vertIn; - -layout(location = 0, index = 0) out vec4 Color; - -void main() -{ - Color = vertIn.col; -} - -)EOSHADER"; - int main() { // initialise, create window, create context, etc @@ -94,8 +50,8 @@ void main() }; pipeCreateInfo.stages = { - CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"), - CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"), + CompileShaderModule(VKDefaultVertex, ShaderLang::glsl, ShaderStage::vert, "main"), + CompileShaderModule(VKDefaultPixel, ShaderLang::glsl, ShaderStage::frag, "main"), }; VkPipeline pipe = createGraphicsPipeline(pipeCreateInfo); diff --git a/util/test/demos/vk/vk_test.cpp b/util/test/demos/vk/vk_test.cpp index 6ffdfe169..0b72f3437 100644 --- a/util/test/demos/vk/vk_test.cpp +++ b/util/test/demos/vk/vk_test.cpp @@ -24,6 +24,50 @@ #include "../test_common.h" +static std::string common = R"EOSHADER( + +#version 460 core + +#define v2f v2f_block \ +{ \ + vec4 pos; \ + vec4 col; \ + vec4 uv; \ +} + +)EOSHADER"; + +std::string VKDefaultVertex = common + R"EOSHADER( + +layout(location = 0) in vec3 Position; +layout(location = 1) in vec4 Color; +layout(location = 2) in vec2 UV; + +layout(location = 0) out v2f vertOut; + +void main() +{ + vertOut.pos = vec4(Position.xyz*vec3(1,-1,1), 1); + gl_Position = vertOut.pos; + vertOut.col = Color; + vertOut.uv = vec4(UV.xy, 0, 1); +} + +)EOSHADER"; + +std::string VKDefaultPixel = common + R"EOSHADER( + +layout(location = 0) in v2f vertIn; + +layout(location = 0, index = 0) out vec4 Color; + +void main() +{ + Color = vertIn.col; +} + +)EOSHADER"; + #define VMA_IMPLEMENTATION #define VMA_STATIC_VULKAN_FUNCTIONS 0 diff --git a/util/test/demos/vk/vk_test.h b/util/test/demos/vk/vk_test.h index 95a42fd86..a121681d8 100644 --- a/util/test/demos/vk/vk_test.h +++ b/util/test/demos/vk/vk_test.h @@ -290,3 +290,6 @@ private: GraphicsWindow *MakePlatformWindow(int width, int height, const char *title); }; + +extern std::string VKDefaultVertex; +extern std::string VKDefaultPixel; diff --git a/util/test/demos/vk/vk_triangle_fan.cpp b/util/test/demos/vk/vk_triangle_fan.cpp index a0978e4bc..316e623ec 100644 --- a/util/test/demos/vk/vk_triangle_fan.cpp +++ b/util/test/demos/vk/vk_triangle_fan.cpp @@ -29,50 +29,6 @@ RD_TEST(VK_Triangle_Fan, VulkanGraphicsTest) static constexpr const char *Description = "Draws a triangle fan with primitive restart to test different edge cases."; - std::string common = R"EOSHADER( - -#version 420 core - -struct v2f -{ - vec4 pos; - vec4 col; - vec4 uv; -}; - -)EOSHADER"; - - const std::string vertex = R"EOSHADER( - -layout(location = 0) in vec3 Position; -layout(location = 1) in vec4 Color; -layout(location = 2) in vec2 UV; - -layout(location = 0) out v2f vertOut; - -void main() -{ - vertOut.pos = vec4(Position.xyz*vec3(1,-1,1), 1); - gl_Position = vertOut.pos; - vertOut.col = Color; - vertOut.uv = vec4(UV.xy, 0, 1); -} - -)EOSHADER"; - - const std::string pixel = R"EOSHADER( - -layout(location = 0) in v2f vertIn; - -layout(location = 0, index = 0) out vec4 Color; - -void main() -{ - Color = vertIn.col; -} - -)EOSHADER"; - int main() { // initialise, create window, create context, etc @@ -96,8 +52,8 @@ void main() }; pipeCreateInfo.stages = { - CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"), - CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"), + CompileShaderModule(VKDefaultVertex, ShaderLang::glsl, ShaderStage::vert, "main"), + CompileShaderModule(VKDefaultPixel, ShaderLang::glsl, ShaderStage::frag, "main"), }; VkPipeline pipe = createGraphicsPipeline(pipeCreateInfo);