aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetr Kraus <petr_kraus@email.cz>2017-11-30 14:49:20 +0100
committerTobin Ehlis <tobine@google.com>2017-12-15 15:18:26 -0700
commit9a4eb6ab133a978a471fbfc6c033b0e4d35bc4c4 (patch)
tree72476bf725049e24bdf8d05e925bc938a8c11bbe
parent64a9243638727603b933bf1824ad57bf8ef06bcb (diff)
downloadusermoji-9a4eb6ab133a978a471fbfc6c033b0e4d35bc4c4.tar.xz
demos: GH1054, make cube shaders inline
-rw-r--r--demos/CMakeLists.txt45
-rw-r--r--demos/android/include/cube.frag.inc22
-rw-r--r--demos/android/include/cube.vert.inc45
-rw-r--r--demos/cube.c109
-rw-r--r--demos/cube.cpp56
5 files changed, 121 insertions, 156 deletions
diff --git a/demos/CMakeLists.txt b/demos/CMakeLists.txt
index eb07b4af..3139d153 100644
--- a/demos/CMakeLists.txt
+++ b/demos/CMakeLists.txt
@@ -88,29 +88,28 @@ if(WIN32)
endif()
endforeach()
- add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/demos/cube-vert.spv
- COMMAND ${GLSLANG_VALIDATOR} -s -V -o ${CMAKE_BINARY_DIR}/demos/cube-vert.spv ${PROJECT_SOURCE_DIR}/demos/cube.vert
- DEPENDS cube.vert ${GLSLANG_VALIDATOR}
- )
- add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/demos/cube-frag.spv
- COMMAND ${GLSLANG_VALIDATOR} -s -V -o ${CMAKE_BINARY_DIR}/demos/cube-frag.spv ${PROJECT_SOURCE_DIR}/demos/cube.frag
- DEPENDS cube.frag ${GLSLANG_VALIDATOR}
- )
file(COPY cube.vcxproj.user DESTINATION ${CMAKE_BINARY_DIR}/demos)
file(COPY vulkaninfo.vcxproj.user DESTINATION ${CMAKE_BINARY_DIR}/demos)
-else()
- if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR})
- add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/demos/cube-vert.spv
- COMMAND ${GLSLANG_VALIDATOR} -s -V -o cube-vert.spv ${PROJECT_SOURCE_DIR}/demos/cube.vert
- DEPENDS cube.vert ${GLSLANG_VALIDATOR}
- )
- add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/demos/cube-frag.spv
- COMMAND ${GLSLANG_VALIDATOR} -s -V -o cube-frag.spv ${PROJECT_SOURCE_DIR}/demos/cube.frag
- DEPENDS cube.frag ${GLSLANG_VALIDATOR}
- )
- endif()
endif()
+add_custom_command(
+ COMMENT "Compiling cube demo vertex shader"
+ OUTPUT cube.vert.inc
+ COMMAND ${GLSLANG_VALIDATOR} -V -x -o ${CMAKE_CURRENT_BINARY_DIR}/cube.vert.inc ${PROJECT_SOURCE_DIR}/demos/cube.vert
+ MAIN_DEPENDENCY ${PROJECT_SOURCE_DIR}/demos/cube.vert
+ DEPENDS ${PROJECT_SOURCE_DIR}/demos/cube.vert ${GLSLANG_VALIDATOR}
+)
+add_custom_command(
+ COMMENT "Compiling cube demo fragment shader"
+ OUTPUT cube.frag.inc
+ COMMAND ${GLSLANG_VALIDATOR} -V -x -o ${CMAKE_CURRENT_BINARY_DIR}/cube.frag.inc ${PROJECT_SOURCE_DIR}/demos/cube.frag
+ MAIN_DEPENDENCY ${PROJECT_SOURCE_DIR}/demos/cube.frag
+ DEPENDS ${PROJECT_SOURCE_DIR}/demos/cube.frag ${GLSLANG_VALIDATOR}
+)
+
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
+
if(WIN32)
include_directories (
"${PROJECT_SOURCE_DIR}/icd/common"
@@ -125,7 +124,7 @@ target_link_libraries(${API_LOWERCASE}info ${LIBRARIES})
if(NOT WIN32)
if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR})
- add_executable(cube cube.c ${CMAKE_BINARY_DIR}/demos/cube-vert.spv ${CMAKE_BINARY_DIR}/demos/cube-frag.spv)
+ add_executable(cube cube.c ${PROJECT_SOURCE_DIR}/demos/cube.vert ${PROJECT_SOURCE_DIR}/demos/cube.frag cube.vert.inc cube.frag.inc)
target_link_libraries(cube ${LIBRARIES})
endif()
else()
@@ -135,13 +134,13 @@ else()
set (LIB_DIR "Win32")
endif()
- add_executable(cube WIN32 cube.c ${CMAKE_BINARY_DIR}/demos/cube-vert.spv ${CMAKE_BINARY_DIR}/demos/cube-frag.spv)
+ add_executable(cube WIN32 cube.c ${PROJECT_SOURCE_DIR}/demos/cube.vert ${PROJECT_SOURCE_DIR}/demos/cube.frag cube.vert.inc cube.frag.inc)
target_link_libraries(cube ${LIBRARIES})
endif()
if(NOT WIN32)
if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR})
- add_executable(cubepp cube.cpp ${CMAKE_BINARY_DIR}/demos/cube-vert.spv ${CMAKE_BINARY_DIR}/demos/cube-frag.spv)
+ add_executable(cubepp cube.cpp ${PROJECT_SOURCE_DIR}/demos/cube.vert ${PROJECT_SOURCE_DIR}/demos/cube.frag cube.vert.inc cube.frag.inc)
target_link_libraries(cubepp ${LIBRARIES})
endif()
else()
@@ -151,7 +150,7 @@ else()
set (LIB_DIR "Win32")
endif()
- add_executable(cubepp WIN32 cube.cpp ${CMAKE_BINARY_DIR}/demos/cube-vert.spv ${CMAKE_BINARY_DIR}/demos/cube-frag.spv)
+ add_executable(cubepp WIN32 cube.cpp ${PROJECT_SOURCE_DIR}/demos/cube.vert ${PROJECT_SOURCE_DIR}/demos/cube.frag cube.vert.inc cube.frag.inc)
target_link_libraries(cubepp ${LIBRARIES})
endif()
diff --git a/demos/android/include/cube.frag.inc b/demos/android/include/cube.frag.inc
new file mode 100644
index 00000000..e80adbb7
--- /dev/null
+++ b/demos/android/include/cube.frag.inc
@@ -0,0 +1,22 @@
+ // Overload400-PrecQual.2000 12-Apr-2017
+ 0x07230203,0x00010000,0x00080002,0x00000015,0x00000000,0x00020011,0x00000001,0x0006000b,
+ 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001,
+ 0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x00000009,0x00000010,0x00030010,
+ 0x00000004,0x00000007,0x00030003,0x00000002,0x00000190,0x00090004,0x415f4c47,0x735f4252,
+ 0x72617065,0x5f657461,0x64616873,0x6f5f7265,0x63656a62,0x00007374,0x00090004,0x415f4c47,
+ 0x735f4252,0x69646168,0x6c5f676e,0x75676e61,0x5f656761,0x70303234,0x006b6361,0x00040005,
+ 0x00000004,0x6e69616d,0x00000000,0x00050005,0x00000009,0x61724675,0x6c6f4367,0x0000726f,
+ 0x00030005,0x0000000d,0x00786574,0x00050005,0x00000010,0x63786574,0x64726f6f,0x00000000,
+ 0x00040047,0x00000009,0x0000001e,0x00000000,0x00040047,0x0000000d,0x00000022,0x00000000,
+ 0x00040047,0x0000000d,0x00000021,0x00000001,0x00040047,0x00000010,0x0000001e,0x00000000,
+ 0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00030016,0x00000006,0x00000020,
+ 0x00040017,0x00000007,0x00000006,0x00000004,0x00040020,0x00000008,0x00000003,0x00000007,
+ 0x0004003b,0x00000008,0x00000009,0x00000003,0x00090019,0x0000000a,0x00000006,0x00000001,
+ 0x00000000,0x00000000,0x00000000,0x00000001,0x00000000,0x0003001b,0x0000000b,0x0000000a,
+ 0x00040020,0x0000000c,0x00000000,0x0000000b,0x0004003b,0x0000000c,0x0000000d,0x00000000,
+ 0x00040020,0x0000000f,0x00000001,0x00000007,0x0004003b,0x0000000f,0x00000010,0x00000001,
+ 0x00040017,0x00000011,0x00000006,0x00000002,0x00050036,0x00000002,0x00000004,0x00000000,
+ 0x00000003,0x000200f8,0x00000005,0x0004003d,0x0000000b,0x0000000e,0x0000000d,0x0004003d,
+ 0x00000007,0x00000012,0x00000010,0x0007004f,0x00000011,0x00000013,0x00000012,0x00000012,
+ 0x00000000,0x00000001,0x00050057,0x00000007,0x00000014,0x0000000e,0x00000013,0x0003003e,
+ 0x00000009,0x00000014,0x000100fd,0x00010038
diff --git a/demos/android/include/cube.vert.inc b/demos/android/include/cube.vert.inc
new file mode 100644
index 00000000..bbfc1928
--- /dev/null
+++ b/demos/android/include/cube.vert.inc
@@ -0,0 +1,45 @@
+ // Overload400-PrecQual.2000 12-Apr-2017
+ 0x07230203,0x00010000,0x00080002,0x00000029,0x00000000,0x00020011,0x00000001,0x0006000b,
+ 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001,
+ 0x0008000f,0x00000000,0x00000004,0x6e69616d,0x00000000,0x00000009,0x00000015,0x0000001e,
+ 0x00030003,0x00000002,0x00000190,0x00090004,0x415f4c47,0x735f4252,0x72617065,0x5f657461,
+ 0x64616873,0x6f5f7265,0x63656a62,0x00007374,0x00090004,0x415f4c47,0x735f4252,0x69646168,
+ 0x6c5f676e,0x75676e61,0x5f656761,0x70303234,0x006b6361,0x00040005,0x00000004,0x6e69616d,
+ 0x00000000,0x00050005,0x00000009,0x63786574,0x64726f6f,0x00000000,0x00030005,0x0000000f,
+ 0x00667562,0x00040006,0x0000000f,0x00000000,0x0050564d,0x00060006,0x0000000f,0x00000001,
+ 0x69736f70,0x6e6f6974,0x00000000,0x00050006,0x0000000f,0x00000002,0x72747461,0x00000000,
+ 0x00040005,0x00000011,0x66756275,0x00000000,0x00060005,0x00000015,0x565f6c67,0x65747265,
+ 0x646e4978,0x00007865,0x00060005,0x0000001c,0x505f6c67,0x65567265,0x78657472,0x00000000,
+ 0x00060006,0x0000001c,0x00000000,0x505f6c67,0x7469736f,0x006e6f69,0x00070006,0x0000001c,
+ 0x00000001,0x505f6c67,0x746e696f,0x657a6953,0x00000000,0x00070006,0x0000001c,0x00000002,
+ 0x435f6c67,0x4470696c,0x61747369,0x0065636e,0x00030005,0x0000001e,0x00000000,0x00040047,
+ 0x00000009,0x0000001e,0x00000000,0x00040047,0x0000000d,0x00000006,0x00000010,0x00040047,
+ 0x0000000e,0x00000006,0x00000010,0x00040048,0x0000000f,0x00000000,0x00000005,0x00050048,
+ 0x0000000f,0x00000000,0x00000023,0x00000000,0x00050048,0x0000000f,0x00000000,0x00000007,
+ 0x00000010,0x00050048,0x0000000f,0x00000001,0x00000023,0x00000040,0x00050048,0x0000000f,
+ 0x00000002,0x00000023,0x00000280,0x00030047,0x0000000f,0x00000002,0x00040047,0x00000011,
+ 0x00000022,0x00000000,0x00040047,0x00000011,0x00000021,0x00000000,0x00040047,0x00000015,
+ 0x0000000b,0x0000002a,0x00050048,0x0000001c,0x00000000,0x0000000b,0x00000000,0x00050048,
+ 0x0000001c,0x00000001,0x0000000b,0x00000001,0x00050048,0x0000001c,0x00000002,0x0000000b,
+ 0x00000003,0x00030047,0x0000001c,0x00000002,0x00020013,0x00000002,0x00030021,0x00000003,
+ 0x00000002,0x00030016,0x00000006,0x00000020,0x00040017,0x00000007,0x00000006,0x00000004,
+ 0x00040020,0x00000008,0x00000003,0x00000007,0x0004003b,0x00000008,0x00000009,0x00000003,
+ 0x00040018,0x0000000a,0x00000007,0x00000004,0x00040015,0x0000000b,0x00000020,0x00000000,
+ 0x0004002b,0x0000000b,0x0000000c,0x00000024,0x0004001c,0x0000000d,0x00000007,0x0000000c,
+ 0x0004001c,0x0000000e,0x00000007,0x0000000c,0x0005001e,0x0000000f,0x0000000a,0x0000000d,
+ 0x0000000e,0x00040020,0x00000010,0x00000002,0x0000000f,0x0004003b,0x00000010,0x00000011,
+ 0x00000002,0x00040015,0x00000012,0x00000020,0x00000001,0x0004002b,0x00000012,0x00000013,
+ 0x00000002,0x00040020,0x00000014,0x00000001,0x00000012,0x0004003b,0x00000014,0x00000015,
+ 0x00000001,0x00040020,0x00000017,0x00000002,0x00000007,0x0004002b,0x0000000b,0x0000001a,
+ 0x00000001,0x0004001c,0x0000001b,0x00000006,0x0000001a,0x0005001e,0x0000001c,0x00000007,
+ 0x00000006,0x0000001b,0x00040020,0x0000001d,0x00000003,0x0000001c,0x0004003b,0x0000001d,
+ 0x0000001e,0x00000003,0x0004002b,0x00000012,0x0000001f,0x00000000,0x00040020,0x00000020,
+ 0x00000002,0x0000000a,0x0004002b,0x00000012,0x00000023,0x00000001,0x00050036,0x00000002,
+ 0x00000004,0x00000000,0x00000003,0x000200f8,0x00000005,0x0004003d,0x00000012,0x00000016,
+ 0x00000015,0x00060041,0x00000017,0x00000018,0x00000011,0x00000013,0x00000016,0x0004003d,
+ 0x00000007,0x00000019,0x00000018,0x0003003e,0x00000009,0x00000019,0x00050041,0x00000020,
+ 0x00000021,0x00000011,0x0000001f,0x0004003d,0x0000000a,0x00000022,0x00000021,0x0004003d,
+ 0x00000012,0x00000024,0x00000015,0x00060041,0x00000017,0x00000025,0x00000011,0x00000023,
+ 0x00000024,0x0004003d,0x00000007,0x00000026,0x00000025,0x00050091,0x00000007,0x00000027,
+ 0x00000022,0x00000026,0x00050041,0x00000008,0x00000028,0x0000001e,0x0000001f,0x0003003e,
+ 0x00000028,0x00000027,0x000100fd,0x00010038
diff --git a/demos/cube.c b/demos/cube.c
index 06a86d0d..e5b10b05 100644
--- a/demos/cube.c
+++ b/demos/cube.c
@@ -1924,109 +1924,35 @@ static void demo_prepare_render_pass(struct demo *demo) {
assert(!err);
}
-//TODO: Merge shader reading
-#ifndef __ANDROID__
-static VkShaderModule
-demo_prepare_shader_module(struct demo *demo, const void *code, size_t size) {
+static VkShaderModule demo_prepare_shader_module(struct demo *demo, const uint32_t *code, size_t size) {
VkShaderModule module;
VkShaderModuleCreateInfo moduleCreateInfo;
VkResult U_ASSERT_ONLY err;
moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
moduleCreateInfo.pNext = NULL;
-
+ moduleCreateInfo.flags = 0;
moduleCreateInfo.codeSize = size;
moduleCreateInfo.pCode = code;
- moduleCreateInfo.flags = 0;
+
err = vkCreateShaderModule(demo->device, &moduleCreateInfo, NULL, &module);
assert(!err);
return module;
}
-char *demo_read_spv(const char *filename, size_t *psize) {
- long int size;
- size_t U_ASSERT_ONLY retval;
- void *shader_code;
-
-#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
- filename =[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: @(filename)].UTF8String;
-#endif
-
- FILE *fp = fopen(filename, "rb");
- if (!fp)
- return NULL;
-
- fseek(fp, 0L, SEEK_END);
- size = ftell(fp);
-
- fseek(fp, 0L, SEEK_SET);
-
- shader_code = malloc(size);
- retval = fread(shader_code, size, 1, fp);
- assert(retval == 1);
-
- *psize = size;
-
- fclose(fp);
- return shader_code;
-}
-#endif
-
-static VkShaderModule demo_prepare_vs(struct demo *demo) {
-#ifdef __ANDROID__
- VkShaderModuleCreateInfo sh_info = {};
- sh_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
-
-#include "cube.vert.h"
- sh_info.codeSize = sizeof(cube_vert);
- sh_info.pCode = cube_vert;
- VkResult U_ASSERT_ONLY err = vkCreateShaderModule(demo->device, &sh_info, NULL, &demo->vert_shader_module);
- assert(!err);
-#else
- void *vertShaderCode;
- size_t size;
-
- vertShaderCode = demo_read_spv("cube-vert.spv", &size);
- if (!vertShaderCode) {
- ERR_EXIT("Failed to load cube-vert.spv", "Load Shader Failure");
- }
-
- demo->vert_shader_module =
- demo_prepare_shader_module(demo, vertShaderCode, size);
-
- free(vertShaderCode);
-#endif
-
- return demo->vert_shader_module;
+static void demo_prepare_vs(struct demo *demo) {
+ const uint32_t vs_code[] = {
+#include "cube.vert.inc"
+ };
+ demo->vert_shader_module = demo_prepare_shader_module(demo, vs_code, sizeof(vs_code));
}
-static VkShaderModule demo_prepare_fs(struct demo *demo) {
-#ifdef __ANDROID__
- VkShaderModuleCreateInfo sh_info = {};
- sh_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
-
-#include "cube.frag.h"
- sh_info.codeSize = sizeof(cube_frag);
- sh_info.pCode = cube_frag;
- VkResult U_ASSERT_ONLY err = vkCreateShaderModule(demo->device, &sh_info, NULL, &demo->frag_shader_module);
- assert(!err);
-#else
- void *fragShaderCode;
- size_t size;
-
- fragShaderCode = demo_read_spv("cube-frag.spv", &size);
- if (!fragShaderCode) {
- ERR_EXIT("Failed to load cube-frag.spv", "Load Shader Failure");
- }
-
- demo->frag_shader_module =
- demo_prepare_shader_module(demo, fragShaderCode, size);
-
- free(fragShaderCode);
-#endif
-
- return demo->frag_shader_module;
+static void demo_prepare_fs(struct demo *demo) {
+ const uint32_t fs_code[] = {
+#include "cube.frag.inc"
+ };
+ demo->frag_shader_module = demo_prepare_shader_module(demo, fs_code, sizeof(fs_code));
}
static void demo_prepare_pipeline(struct demo *demo) {
@@ -2104,19 +2030,21 @@ static void demo_prepare_pipeline(struct demo *demo) {
ms.pSampleMask = NULL;
ms.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
+ demo_prepare_vs(demo);
+ demo_prepare_fs(demo);
+
// Two stages: vs and fs
- pipeline.stageCount = 2;
VkPipelineShaderStageCreateInfo shaderStages[2];
memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
- shaderStages[0].module = demo_prepare_vs(demo);
+ shaderStages[0].module = demo->vert_shader_module;
shaderStages[0].pName = "main";
shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
- shaderStages[1].module = demo_prepare_fs(demo);
+ shaderStages[1].module = demo->frag_shader_module;
shaderStages[1].pName = "main";
memset(&pipelineCache, 0, sizeof(pipelineCache));
@@ -2133,6 +2061,7 @@ static void demo_prepare_pipeline(struct demo *demo) {
pipeline.pMultisampleState = &ms;
pipeline.pViewportState = &vp;
pipeline.pDepthStencilState = &ds;
+ pipeline.stageCount = ARRAY_SIZE(shaderStages);
pipeline.pStages = shaderStages;
pipeline.renderPass = demo->render_pass;
pipeline.pDynamicState = &dynamicState;
diff --git a/demos/cube.cpp b/demos/cube.cpp
index ef90220a..1cd32052 100644
--- a/demos/cube.cpp
+++ b/demos/cube.cpp
@@ -232,14 +232,14 @@ struct Demo {
void prepare_descriptor_pool();
void prepare_descriptor_set();
void prepare_framebuffers();
+ vk::ShaderModule prepare_shader_module(const uint32_t *, size_t);
+ vk::ShaderModule prepare_vs();
vk::ShaderModule prepare_fs();
void prepare_pipeline();
void prepare_render_pass();
- vk::ShaderModule prepare_shader_module(const void *, size_t);
void prepare_texture_image(const char *, texture_object *, vk::ImageTiling, vk::ImageUsageFlags, vk::MemoryPropertyFlags);
void prepare_textures();
- vk::ShaderModule prepare_vs();
- char *read_spv(const char *, size_t *);
+
void resize();
void set_image_layout(vk::Image, vk::ImageAspectFlags, vk::ImageLayout, vk::ImageLayout, vk::AccessFlags,
vk::PipelineStageFlags, vk::PipelineStageFlags);
@@ -1858,15 +1858,11 @@ Demo::Demo()
}
vk::ShaderModule Demo::prepare_fs() {
- size_t size = 0;
- void *fragShaderCode = read_spv("cube-frag.spv", &size);
- if (!fragShaderCode) {
- ERR_EXIT("Failed to load cube-frag.spv", "Load Shader Failure");
- }
-
- frag_shader_module = prepare_shader_module(fragShaderCode, size);
+ const uint32_t fragShaderCode[] = {
+#include "cube.frag.inc"
+ };
- free(fragShaderCode);
+ frag_shader_module = prepare_shader_module(fragShaderCode, sizeof(fragShaderCode));
return frag_shader_module;
}
@@ -2004,8 +2000,8 @@ Demo::Demo()
VERIFY(result == vk::Result::eSuccess);
}
- vk::ShaderModule Demo::prepare_shader_module(const void *code, size_t size) {
- auto const moduleCreateInfo = vk::ShaderModuleCreateInfo().setCodeSize(size).setPCode((uint32_t const *)code);
+ vk::ShaderModule Demo::prepare_shader_module(const uint32_t *code, size_t size) {
+ const auto moduleCreateInfo = vk::ShaderModuleCreateInfo().setCodeSize(size).setPCode(code);
vk::ShaderModule module;
auto result = device.createShaderModule(&moduleCreateInfo, nullptr, &module);
@@ -2167,41 +2163,15 @@ Demo::Demo()
}
vk::ShaderModule Demo::prepare_vs() {
- size_t size = 0;
- void *vertShaderCode = read_spv("cube-vert.spv", &size);
- if (!vertShaderCode) {
- ERR_EXIT("Failed to load cube-vert.spv", "Load Shader Failure");
- }
-
- vert_shader_module = prepare_shader_module(vertShaderCode, size);
+ const uint32_t vertShaderCode[] = {
+#include "cube.vert.inc"
+ };
- free(vertShaderCode);
+ vert_shader_module = prepare_shader_module(vertShaderCode, sizeof(vertShaderCode));
return vert_shader_module;
}
- char *Demo::read_spv(const char *filename, size_t *psize) {
- FILE *fp = fopen(filename, "rb");
- if (!fp) {
- return nullptr;
- }
-
- fseek(fp, 0L, SEEK_END);
- long int size = ftell(fp);
-
- fseek(fp, 0L, SEEK_SET);
-
- void *shader_code = malloc(size);
- size_t retval = fread(shader_code, size, 1, fp);
- VERIFY(retval == 1);
-
- *psize = size;
-
- fclose(fp);
-
- return (char *)shader_code;
- }
-
void Demo::resize() {
uint32_t i;