Skip to content

Instantly share code, notes, and snippets.

@kovrov
Created September 8, 2016 06:55
Show Gist options
  • Save kovrov/0738b8de67c0684f915d3435eca75022 to your computer and use it in GitHub Desktop.
Save kovrov/0738b8de67c0684f915d3435eca75022 to your computer and use it in GitHub Desktop.
GLSL to SPIR-V at build-time.
[submodule "glslang"]
path = glslang
url = [email protected]:KhronosGroup/glslang.git
cmake_minimum_required (VERSION 3.1)
project (spirv)
aux_source_directory (. SRC_LIST)
file (GLOB SHADER_LIST triangle.frag triangle.vert)
add_subdirectory (glslang)
add_custom_command (
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/triangle.spv.hex
COMMAND glslangValidator -V -x -o triangle.spv.hex ${SHADER_LIST}
DEPENDS glslangValidator ${SHADER_LIST}
)
include_directories (${CMAKE_CURRENT_BINARY_DIR})
add_executable (${PROJECT_NAME} ${SRC_LIST} triangle.spv.hex)
set_property (TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14)
#include <cstdint>
#include <iostream>
#include <vector>
using namespace std;
vector<uint32_t> spirv {
#include "triangle.spv.hex"
};
int main(int argc, char *argv[])
{
cout << spirv.size() * sizeof(spirv[0]) << endl;
return 0;
}
#version 450
layout (location = 0) in vec4 in_color;
layout (location = 0) out vec4 out_color;
void main() {
out_color = in_color;
}
#version 450
layout (std140, binding = 0) uniform bufferVals {
mat4 mvp;
} buffer_vals;
layout (location = 0) in vec4 in_position;
layout (location = 1) in vec4 in_color;
layout (location = 0) out vec4 out_color;
out gl_PerVertex {
vec4 gl_Position;
};
void main() {
out_color = in_color;
gl_Position = buffer_vals.mvp * in_position;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment