mirror of https://github.com/auygun/kaliber.git
Implement Vulkan renderer.
This commit is contained in:
parent
d8cb4b96b0
commit
671661758c
15
README.md
15
README.md
|
@ -1,6 +1,9 @@
|
|||
A simple, cross-platform 2D game engine with OpenGL renderer. Supports Linux and
|
||||
Android (lolipop+) platforms. My personal hobby project.
|
||||
I've published a game on [Google Play](https://play.google.com/store/apps/details?id=com.woom.game) based on the engine. The demo included in this repository is an early prototype of the game.
|
||||
A simple, cross-platform 2D game engine with OpenGL and Vulkan renderers.
|
||||
Supports Linux and Android (lolipop+) platforms.
|
||||
This is a personal hobby project. I've published a little game on
|
||||
[Google Play](https://play.google.com/store/apps/details?id=com.woom.game)
|
||||
based on this engine. The demo included in this repository is an early prototype
|
||||
of the game.
|
||||
#### Building the demo
|
||||
Linux:
|
||||
```text
|
||||
|
@ -24,4 +27,8 @@ ninja -C out/release
|
|||
[oboe](https://github.com/google/oboe),
|
||||
[stb](https://github.com/nothings/stb),
|
||||
[texture-compressor](https://github.com/auygun/kaliber/tree/master/src/third_party/texture_compressor),
|
||||
[minizip](https://github.com/madler/zlib/tree/master/contrib/minizip)
|
||||
[minizip](https://github.com/madler/zlib/tree/master/contrib/minizip),
|
||||
[glslang](https://github.com/KhronosGroup/glslang),
|
||||
[spirv-reflect](https://github.com/KhronosGroup/SPIRV-Reflect),
|
||||
[vma](https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator),
|
||||
[vulkan-sdk](https://vulkan.lunarg.com)
|
||||
|
|
|
@ -2,11 +2,23 @@
|
|||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec4 color;
|
||||
uniform sampler2D texture_0;
|
||||
IN(0) vec2 tex_coord_0;
|
||||
|
||||
varying vec2 tex_coord_0;
|
||||
UNIFORM_BEGIN
|
||||
UNIFORM_V(vec2 scale)
|
||||
UNIFORM_V(vec2 offset)
|
||||
UNIFORM_V(vec2 rotation)
|
||||
UNIFORM_V(vec2 tex_offset)
|
||||
UNIFORM_V(vec2 tex_scale)
|
||||
UNIFORM_V(mat4 projection)
|
||||
UNIFORM_F(vec4 color)
|
||||
UNIFORM_S(sampler2D texture_0)
|
||||
UNIFORM_END
|
||||
|
||||
SAMPLER(sampler2D texture_0)
|
||||
|
||||
FRAG_COLOR_OUT(frag_color)
|
||||
|
||||
void main() {
|
||||
gl_FragColor = texture2D(texture_0, tex_coord_0) * color;
|
||||
FRAG_COLOR(frag_color) = TEXTURE(texture_0, tex_coord_0) * PARAM(color);
|
||||
}
|
||||
|
|
|
@ -1,24 +1,27 @@
|
|||
attribute vec2 in_position;
|
||||
attribute vec2 in_tex_coord_0;
|
||||
IN(0) vec2 in_position;
|
||||
IN(1) vec2 in_tex_coord_0;
|
||||
|
||||
uniform vec2 scale;
|
||||
uniform vec2 offset;
|
||||
uniform vec2 rotation;
|
||||
uniform vec2 tex_offset;
|
||||
uniform vec2 tex_scale;
|
||||
uniform mat4 projection;
|
||||
UNIFORM_BEGIN
|
||||
UNIFORM_V(vec2 scale)
|
||||
UNIFORM_V(vec2 offset)
|
||||
UNIFORM_V(vec2 rotation)
|
||||
UNIFORM_V(vec2 tex_offset)
|
||||
UNIFORM_V(vec2 tex_scale)
|
||||
UNIFORM_V(mat4 projection)
|
||||
UNIFORM_F(vec4 color)
|
||||
UNIFORM_END
|
||||
|
||||
varying vec2 tex_coord_0;
|
||||
OUT(0) vec2 tex_coord_0;
|
||||
|
||||
void main() {
|
||||
// Simple 2d transform.
|
||||
vec2 position = in_position;
|
||||
position *= scale;
|
||||
position = vec2(position.x * rotation.y + position.y * rotation.x,
|
||||
position.y * rotation.y - position.x * rotation.x);
|
||||
position += offset;
|
||||
position *= PARAM(scale);
|
||||
position = vec2(position.x * PARAM(rotation).y + position.y * PARAM(rotation).x,
|
||||
position.y * PARAM(rotation).y - position.x * PARAM(rotation).x);
|
||||
position += PARAM(offset);
|
||||
|
||||
tex_coord_0 = (in_tex_coord_0 + tex_offset) * tex_scale;
|
||||
tex_coord_0 = (in_tex_coord_0 + PARAM(tex_offset)) * PARAM(tex_scale);
|
||||
|
||||
gl_Position = projection * vec4(position, 0.0, 1.0);
|
||||
gl_Position = PARAM(projection) * vec4(position, 0.0, 1.0);
|
||||
}
|
||||
|
|
|
@ -2,8 +2,16 @@
|
|||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec4 color;
|
||||
UNIFORM_BEGIN
|
||||
UNIFORM_V(vec2 scale)
|
||||
UNIFORM_V(vec2 offset)
|
||||
UNIFORM_V(vec2 rotation)
|
||||
UNIFORM_V(mat4 projection)
|
||||
UNIFORM_F(vec4 color)
|
||||
UNIFORM_END
|
||||
|
||||
FRAG_COLOR_OUT(frag_color)
|
||||
|
||||
void main() {
|
||||
gl_FragColor = color;
|
||||
FRAG_COLOR(frag_color) = PARAM(color);
|
||||
}
|
||||
|
|
|
@ -1,18 +1,21 @@
|
|||
attribute vec2 in_position;
|
||||
attribute vec2 in_tex_coord_0;
|
||||
IN(0) vec2 in_position;
|
||||
IN(1) vec2 in_tex_coord_0;
|
||||
|
||||
uniform vec2 scale;
|
||||
uniform vec2 offset;
|
||||
uniform vec2 rotation;
|
||||
uniform mat4 projection;
|
||||
UNIFORM_BEGIN
|
||||
UNIFORM_V(vec2 scale)
|
||||
UNIFORM_V(vec2 offset)
|
||||
UNIFORM_V(vec2 rotation)
|
||||
UNIFORM_V(mat4 projection)
|
||||
UNIFORM_F(vec4 color)
|
||||
UNIFORM_END
|
||||
|
||||
void main() {
|
||||
// Simple 2d transform.
|
||||
vec2 position = in_position;
|
||||
position *= scale;
|
||||
position = vec2(position.x * rotation.y + position.y * rotation.x,
|
||||
position.y * rotation.y - position.x * rotation.x);
|
||||
position += offset;
|
||||
position *= PARAM(scale);
|
||||
position = vec2(position.x * PARAM(rotation).y + position.y * PARAM(rotation).x,
|
||||
position.y * PARAM(rotation).y - position.x * PARAM(rotation).x);
|
||||
position += PARAM(offset);
|
||||
|
||||
gl_Position = projection * vec4(position, 0.0, 1.0);
|
||||
gl_Position = PARAM(projection) * vec4(position, 0.0, 1.0);
|
||||
}
|
||||
|
|
|
@ -1,24 +1,30 @@
|
|||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
precision highp float;
|
||||
#else
|
||||
#define lowp
|
||||
#define mediump
|
||||
#define highp
|
||||
#endif
|
||||
|
||||
uniform highp vec2 sky_offset;
|
||||
uniform vec3 nebula_color;
|
||||
IN(0) vec2 tex_coord_0;
|
||||
|
||||
varying highp vec2 tex_coord_0;
|
||||
UNIFORM_BEGIN
|
||||
UNIFORM_V(vec2 scale)
|
||||
UNIFORM_V(mat4 projection)
|
||||
UNIFORM_F(vec2 sky_offset)
|
||||
UNIFORM_F(vec3 nebula_color)
|
||||
UNIFORM_END
|
||||
|
||||
float random(highp vec2 p) {
|
||||
highp float sd = sin(dot(p, vec2(54.90898, 18.233)));
|
||||
FRAG_COLOR_OUT(frag_color)
|
||||
|
||||
float random(vec2 p) {
|
||||
float sd = sin(dot(p, vec2(54.90898, 18.233)));
|
||||
return fract(sd * 2671.6182);
|
||||
}
|
||||
|
||||
float nebula(in highp vec2 p) {
|
||||
highp vec2 i = floor(p);
|
||||
highp vec2 f = fract(p);
|
||||
float nebula(in vec2 p) {
|
||||
vec2 i = floor(p);
|
||||
vec2 f = fract(p);
|
||||
|
||||
float a = random(i);
|
||||
float b = random(i + vec2(1.0, 0.0));
|
||||
|
@ -32,24 +38,24 @@ float nebula(in highp vec2 p) {
|
|||
(d - b) * u.x * u.y;
|
||||
}
|
||||
|
||||
float stars(in highp vec2 p, float num_cells, float size) {
|
||||
highp vec2 n = p * num_cells;
|
||||
highp vec2 i = floor(n);
|
||||
float stars(in vec2 p, float num_cells, float size) {
|
||||
vec2 n = p * num_cells;
|
||||
vec2 i = floor(n);
|
||||
|
||||
vec2 a = n - i - random(i);
|
||||
a /= num_cells * size;
|
||||
float e = dot(a, a);
|
||||
|
||||
return smoothstep(0.95, 1.0, (1.0 - e * 35.0));
|
||||
return smoothstep(0.94, 1.0, (1.0 - e * 35.0));
|
||||
}
|
||||
|
||||
void main() {
|
||||
highp vec2 layer1_coord = tex_coord_0 + sky_offset;
|
||||
highp vec2 layer2_coord = tex_coord_0 + sky_offset * 0.7;
|
||||
vec3 result = vec3(0.);
|
||||
vec2 layer1_coord = tex_coord_0 + PARAM(sky_offset);
|
||||
vec2 layer2_coord = tex_coord_0 + PARAM(sky_offset) * 0.7;
|
||||
mediump vec3 result = vec3(0.);
|
||||
|
||||
float c = nebula(layer2_coord * 3.0) * 0.35 - 0.05;
|
||||
result += nebula_color * floor(c * 60.0) / 60.0;
|
||||
result += PARAM(nebula_color) * floor(c * 60.0) / 60.0;
|
||||
|
||||
c = stars(layer1_coord, 8.0, 0.05);
|
||||
result += vec3(0.97, 0.74, 0.74) * c;
|
||||
|
@ -57,5 +63,5 @@ void main() {
|
|||
c = stars(layer2_coord, 16.0, 0.025) * 0.5;
|
||||
result += vec3(0.9, 0.9, 0.95) * c;
|
||||
|
||||
gl_FragColor = vec4(result, 1.0);
|
||||
FRAG_COLOR(frag_color) = vec4(result, 1.0);
|
||||
}
|
||||
|
|
|
@ -1,17 +1,21 @@
|
|||
attribute vec2 in_position;
|
||||
attribute vec2 in_tex_coord_0;
|
||||
IN(0) vec2 in_position;
|
||||
IN(1) vec2 in_tex_coord_0;
|
||||
|
||||
uniform vec2 scale;
|
||||
uniform mat4 projection;
|
||||
UNIFORM_BEGIN
|
||||
UNIFORM_V(vec2 scale)
|
||||
UNIFORM_V(mat4 projection)
|
||||
UNIFORM_F(vec2 sky_offset)
|
||||
UNIFORM_F(vec3 nebula_color)
|
||||
UNIFORM_END
|
||||
|
||||
varying vec2 tex_coord_0;
|
||||
OUT(0) vec2 tex_coord_0;
|
||||
|
||||
void main() {
|
||||
// Simple 2d transform.
|
||||
vec2 position = in_position;
|
||||
position *= scale;
|
||||
position *= PARAM(scale);
|
||||
|
||||
tex_coord_0 = in_tex_coord_0;
|
||||
|
||||
gl_Position = projection * vec4(position, 0.0, 1.0);
|
||||
gl_Position = PARAM(projection) * vec4(position, 0.0, 1.0);
|
||||
}
|
||||
|
|
|
@ -36,9 +36,9 @@ add_library(native_app_glue STATIC
|
|||
|
||||
# now build app's shared lib
|
||||
if (CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -Werror -D_DEBUG")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -Werror -D_DEBUG -DVK_USE_PLATFORM_ANDROID_KHR")
|
||||
else ()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -Werror")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -Werror -DVK_USE_PLATFORM_ANDROID_KHR")
|
||||
endif ()
|
||||
|
||||
|
||||
|
@ -87,19 +87,69 @@ add_library(kaliber SHARED
|
|||
../../../src/engine/renderer/renderer_types.cc
|
||||
../../../src/engine/renderer/shader.cc
|
||||
../../../src/engine/renderer/texture.cc
|
||||
../../../src/engine/renderer/vulkan/renderer_vulkan_android.cc
|
||||
../../../src/engine/renderer/vulkan/renderer_vulkan.cc
|
||||
../../../src/engine/renderer/vulkan/vulkan_context_android.cc
|
||||
../../../src/engine/renderer/vulkan/vulkan_context.cc
|
||||
../../../src/engine/shader_source.cc
|
||||
../../../src/engine/solid_quad.cc
|
||||
../../../src/engine/sound_player.cc
|
||||
../../../src/engine/sound.cc
|
||||
../../../src/third_party/android/gl3stub.c
|
||||
../../../src/third_party/android/GLContext.cpp
|
||||
../../../src/third_party/android/vulkan_wrapper.cpp
|
||||
../../../src/third_party/glslang/glslang/CInterface/glslang_c_interface.cpp
|
||||
../../../src/third_party/glslang/glslang/GenericCodeGen/CodeGen.cpp
|
||||
../../../src/third_party/glslang/glslang/GenericCodeGen/Link.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/attribute.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/Constant.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/glslang_tab.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/InfoSink.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/Initialize.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/Intermediate.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/intermOut.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/IntermTraverse.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/iomapper.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/limits.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/linkValidate.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/parseConst.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/ParseContextBase.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/ParseHelper.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/PoolAlloc.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/preprocessor/Pp.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/preprocessor/PpAtom.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/preprocessor/PpContext.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/preprocessor/PpScanner.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/preprocessor/PpTokens.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/propagateNoContraction.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/reflection.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/RemoveTree.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/Scan.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/ShaderLang.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/SymbolTable.cpp
|
||||
../../../src/third_party/glslang/glslang/MachineIndependent/Versions.cpp
|
||||
../../../src/third_party/glslang/glslang/OSDependent/Unix/ossource.cpp
|
||||
../../../src/third_party/glslang/OGLCompilersDLL/InitializeDll.cpp
|
||||
../../../src/third_party/glslang/SPIRV/CInterface/spirv_c_interface.cpp
|
||||
../../../src/third_party/glslang/SPIRV/disassemble.cpp
|
||||
../../../src/third_party/glslang/SPIRV/doc.cpp
|
||||
../../../src/third_party/glslang/SPIRV/GlslangToSpv.cpp
|
||||
../../../src/third_party/glslang/SPIRV/InReadableOrder.cpp
|
||||
../../../src/third_party/glslang/SPIRV/Logger.cpp
|
||||
../../../src/third_party/glslang/SPIRV/SpvBuilder.cpp
|
||||
../../../src/third_party/glslang/SPIRV/SpvPostProcess.cpp
|
||||
../../../src/third_party/glslang/SPIRV/SPVRemapper.cpp
|
||||
../../../src/third_party/glslang/SPIRV/SpvTools.cpp
|
||||
../../../src/third_party/glslang/StandAlone/ResourceLimits.cpp
|
||||
../../../src/third_party/jsoncpp/jsoncpp.cc
|
||||
../../../src/third_party/minizip/ioapi.c
|
||||
../../../src/third_party/minizip/unzip.c
|
||||
../../../src/third_party/spirv-reflect/spirv_reflect.c
|
||||
../../../src/third_party/texture_compressor/dxt_encoder_internals.cc
|
||||
../../../src/third_party/texture_compressor/dxt_encoder.cc
|
||||
../../../src/third_party/texture_compressor/texture_compressor_etc1.cc
|
||||
../../../src/third_party/texture_compressor/texture_compressor.cc
|
||||
../../../src/third_party/vma/vk_mem_alloc.cpp
|
||||
)
|
||||
|
||||
if (ANDROID_ABI STREQUAL armeabi-v7a)
|
||||
|
|
|
@ -106,12 +106,16 @@ GLTEST_SRC := \
|
|||
$(SRC_ROOT)/engine/platform/platform_linux.cc \
|
||||
$(SRC_ROOT)/engine/renderer/geometry.cc \
|
||||
$(SRC_ROOT)/engine/renderer/opengl/render_command.cc \
|
||||
$(SRC_ROOT)/engine/renderer/render_resource.cc \
|
||||
$(SRC_ROOT)/engine/renderer/opengl/renderer_opengl_linux.cc \
|
||||
$(SRC_ROOT)/engine/renderer/opengl/renderer_opengl.cc \
|
||||
$(SRC_ROOT)/engine/renderer/render_resource.cc \
|
||||
$(SRC_ROOT)/engine/renderer/renderer_types.cc \
|
||||
$(SRC_ROOT)/engine/renderer/shader.cc \
|
||||
$(SRC_ROOT)/engine/renderer/texture.cc \
|
||||
$(SRC_ROOT)/engine/renderer/vulkan/renderer_vulkan_linux.cc \
|
||||
$(SRC_ROOT)/engine/renderer/vulkan/renderer_vulkan.cc \
|
||||
$(SRC_ROOT)/engine/renderer/vulkan/vulkan_context_linux.cc \
|
||||
$(SRC_ROOT)/engine/renderer/vulkan/vulkan_context.cc \
|
||||
$(SRC_ROOT)/engine/shader_source.cc \
|
||||
$(SRC_ROOT)/engine/solid_quad.cc \
|
||||
$(SRC_ROOT)/engine/sound_player.cc \
|
||||
|
|
|
@ -51,6 +51,10 @@ source_set("engine") {
|
|||
"renderer/shader.h",
|
||||
"renderer/texture.cc",
|
||||
"renderer/texture.h",
|
||||
"renderer/vulkan/renderer_vulkan_linux.cc",
|
||||
"renderer/vulkan/renderer_vulkan.cc",
|
||||
"renderer/vulkan/vulkan_context_linux.cc",
|
||||
"renderer/vulkan/vulkan_context.cc",
|
||||
"shader_source.cc",
|
||||
"shader_source.h",
|
||||
"solid_quad.cc",
|
||||
|
@ -61,6 +65,15 @@ source_set("engine") {
|
|||
"sound.h",
|
||||
]
|
||||
|
||||
defines = [
|
||||
"VK_USE_PLATFORM_XLIB_KHR",
|
||||
"VULKAN_NON_CMAKE_BUILD",
|
||||
"SYSCONFDIR=\"/etc\"",
|
||||
"FALLBACK_DATA_DIRS=\"/usr/local/share:/usr/share\"",
|
||||
"FALLBACK_CONFIG_DIRS=\"/etc/xdg\"",
|
||||
"HAVE_SECURE_GETENV",
|
||||
]
|
||||
|
||||
ldflags = [] libs = []
|
||||
|
||||
if (target_os == "linux") {
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
#include "../audio/audio.h"
|
||||
#include "../engine.h"
|
||||
#include "../renderer/opengl/renderer_opengl.h"
|
||||
#include "../renderer/vulkan/renderer_vulkan.h"
|
||||
|
||||
#define VULKAN_RENDERER
|
||||
|
||||
using namespace base;
|
||||
|
||||
|
@ -28,7 +31,11 @@ void PlatformBase::Initialize() {
|
|||
throw internal_error;
|
||||
}
|
||||
|
||||
#if defined(VULKAN_RENDERER)
|
||||
renderer_ = std::make_unique<RendererVulkan>();
|
||||
#else
|
||||
renderer_ = std::make_unique<RendererOpenGL>();
|
||||
#endif
|
||||
}
|
||||
|
||||
void PlatformBase::Shutdown() {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,257 @@
|
|||
#ifndef RENDERER_VULKAN_H
|
||||
#define RENDERER_VULKAN_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "vulkan_context.h"
|
||||
|
||||
#include "../../../third_party/vma/vk_mem_alloc.h"
|
||||
#include "../render_resource.h"
|
||||
#include "../renderer.h"
|
||||
|
||||
namespace eng {
|
||||
|
||||
class Image;
|
||||
|
||||
class RendererVulkan : public Renderer {
|
||||
public:
|
||||
RendererVulkan();
|
||||
~RendererVulkan() override;
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
bool Initialize(ANativeWindow* window) override;
|
||||
#elif defined(__linux__)
|
||||
bool Initialize(Display* display, Window window) override;
|
||||
#endif
|
||||
|
||||
void Shutdown() override;
|
||||
|
||||
void CreateGeometry(std::shared_ptr<void> impl_data,
|
||||
std::unique_ptr<Mesh> mesh) override;
|
||||
void DestroyGeometry(std::shared_ptr<void> impl_data) override;
|
||||
void Draw(std::shared_ptr<void> impl_data) override;
|
||||
|
||||
void UpdateTexture(std::shared_ptr<void> impl_data,
|
||||
std::unique_ptr<Image> image) override;
|
||||
void DestroyTexture(std::shared_ptr<void> impl_data) override;
|
||||
void ActivateTexture(std::shared_ptr<void> impl_data) override;
|
||||
|
||||
void CreateShader(std::shared_ptr<void> impl_data,
|
||||
std::unique_ptr<ShaderSource> source,
|
||||
const VertexDescripton& vertex_description,
|
||||
Primitive primitive) override;
|
||||
void DestroyShader(std::shared_ptr<void> impl_data) override;
|
||||
void ActivateShader(std::shared_ptr<void> impl_data) override;
|
||||
|
||||
void SetUniform(std::shared_ptr<void> impl_data,
|
||||
const std::string& name,
|
||||
const base::Vector2& val) override;
|
||||
void SetUniform(std::shared_ptr<void> impl_data,
|
||||
const std::string& name,
|
||||
const base::Vector3& val) override;
|
||||
void SetUniform(std::shared_ptr<void> impl_data,
|
||||
const std::string& name,
|
||||
const base::Vector4& val) override;
|
||||
void SetUniform(std::shared_ptr<void> impl_data,
|
||||
const std::string& name,
|
||||
const base::Matrix4x4& val) override;
|
||||
void SetUniform(std::shared_ptr<void> impl_data,
|
||||
const std::string& name,
|
||||
float val) override;
|
||||
void SetUniform(std::shared_ptr<void> impl_data,
|
||||
const std::string& name,
|
||||
int val) override;
|
||||
void UploadUniforms(std::shared_ptr<void> impl_data) override;
|
||||
|
||||
void PrepareForDrawing() override;
|
||||
void Present() override;
|
||||
|
||||
std::unique_ptr<RenderResource> CreateResource(
|
||||
RenderResourceFactoryBase& factory) override;
|
||||
void ReleaseResource(unsigned resource_id) override;
|
||||
|
||||
size_t GetAndResetFPS() override;
|
||||
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
XVisualInfo* GetXVisualInfo(Display* display) override;
|
||||
#endif
|
||||
|
||||
private:
|
||||
// VkBuffer or VkImage with allocator.
|
||||
template <typename T>
|
||||
using Buffer = std::tuple<T, VmaAllocation>;
|
||||
|
||||
// VkDescriptorPool with usage count.
|
||||
using DescPool = std::tuple<VkDescriptorPool, size_t>;
|
||||
|
||||
// VkDescriptorSet with the pool which it was allocated from.
|
||||
using DescSet = std::tuple<VkDescriptorSet, DescPool*>;
|
||||
|
||||
// Containers to keep information of resources to be destroyed.
|
||||
using BufferDeathRow = std::vector<Buffer<VkBuffer>>;
|
||||
using ImageDeathRow = std::vector<std::tuple<Buffer<VkImage>, VkImageView>>;
|
||||
using DescSetDeathRow = std::vector<DescSet>;
|
||||
using PipelineDeathRow =
|
||||
std::vector<std::tuple<VkPipeline, VkPipelineLayout>>;
|
||||
|
||||
struct GeometryVulkan {
|
||||
Buffer<VkBuffer> buffer;
|
||||
size_t num_vertices = 0;
|
||||
};
|
||||
|
||||
struct ShaderVulkan {
|
||||
std::unordered_map<std::string, std::array<size_t, 2>> variables;
|
||||
std::unique_ptr<char[]> push_constants;
|
||||
size_t push_constants_size = 0;
|
||||
std::string sampler_uniform_name;
|
||||
bool use_desc_set = false;
|
||||
std::vector<uint8_t> spirv_vertex;
|
||||
std::vector<uint8_t> spirv_fragment;
|
||||
VkPipelineLayout pipeline_layout = VK_NULL_HANDLE;
|
||||
VkPipeline pipeline = VK_NULL_HANDLE;
|
||||
};
|
||||
|
||||
struct TextureVulkan {
|
||||
Buffer<VkImage> image;
|
||||
VkImageView view = VK_NULL_HANDLE;
|
||||
DescSet desc_set = {};
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
};
|
||||
|
||||
// Each frame contains 2 command buffers with separate synchronization scopes.
|
||||
// One for creating resources (recorded outside a render pass) and another for
|
||||
// drawing (recorded inside a render pass). Also contains list of resources to
|
||||
// be destroyed when the frame is cycled. There are 2 or 3 frames (double or
|
||||
// tripple buffering) that are cycled constantly.
|
||||
struct Frame {
|
||||
VkCommandPool command_pool = VK_NULL_HANDLE;
|
||||
VkCommandBuffer setup_command_buffer = VK_NULL_HANDLE;
|
||||
VkCommandBuffer draw_command_buffer = VK_NULL_HANDLE;
|
||||
|
||||
BufferDeathRow buffers_to_destroy;
|
||||
ImageDeathRow images_to_destroy;
|
||||
DescSetDeathRow desc_sets_to_destroy;
|
||||
PipelineDeathRow pipelines_to_destroy;
|
||||
};
|
||||
|
||||
struct StagingBuffer {
|
||||
Buffer<VkBuffer> buffer{VK_NULL_HANDLE, nullptr};
|
||||
uint64_t frame_used = 0;
|
||||
uint32_t fill_amount = 0;
|
||||
VmaAllocationInfo alloc_info;
|
||||
};
|
||||
|
||||
VulkanContext context_;
|
||||
|
||||
VmaAllocator allocator_ = nullptr;
|
||||
|
||||
VkDevice device_ = VK_NULL_HANDLE;
|
||||
size_t frames_drawn_ = 0;
|
||||
std::vector<Frame> frames_;
|
||||
int current_frame_ = 0;
|
||||
|
||||
std::vector<StagingBuffer> staging_buffers_;
|
||||
int current_staging_buffer_ = 0;
|
||||
uint32_t staging_buffer_size_ = 256 * 1024;
|
||||
uint64_t max_staging_buffer_size_ = 16 * 1024 * 1024;
|
||||
bool staging_buffer_used_ = false;
|
||||
|
||||
VkPipeline active_pipeline_ = VK_NULL_HANDLE;
|
||||
|
||||
std::vector<std::unique_ptr<DescPool>> desc_pools_;
|
||||
VkDescriptorSetLayout descriptor_set_layout_ = VK_NULL_HANDLE;
|
||||
VkDescriptorSet active_descriptor_set_ = VK_NULL_HANDLE;
|
||||
VkDescriptorSet penging_descriptor_set_ = VK_NULL_HANDLE;
|
||||
|
||||
VkSampler sampler_ = VK_NULL_HANDLE;
|
||||
|
||||
std::unordered_map<unsigned, RenderResource*> resources_;
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
ANativeWindow* window_;
|
||||
#elif defined(__linux__)
|
||||
Display* display_ = NULL;
|
||||
Window window_ = 0;
|
||||
#endif
|
||||
|
||||
bool InitializeInternal();
|
||||
|
||||
void BeginFrame();
|
||||
|
||||
void Flush();
|
||||
|
||||
void FreePendingResources(int frame);
|
||||
|
||||
void MemoryBarrier(VkPipelineStageFlags src_stage_mask,
|
||||
VkPipelineStageFlags dst_stage_mask,
|
||||
VkAccessFlags src_access,
|
||||
VkAccessFlags dst_sccess);
|
||||
void FullBarrier();
|
||||
|
||||
bool AllocateStagingBuffer(uint32_t amount,
|
||||
uint32_t segment,
|
||||
uint32_t& alloc_offset,
|
||||
uint32_t& alloc_size);
|
||||
bool InsertStagingBuffer();
|
||||
|
||||
DescPool* AllocateDescriptorPool();
|
||||
void FreeDescriptorPool(DescPool* desc_pool);
|
||||
|
||||
bool AllocateBuffer(Buffer<VkBuffer>& buffer,
|
||||
uint32_t size,
|
||||
uint32_t usage,
|
||||
VmaMemoryUsage mapping);
|
||||
void FreeBuffer(Buffer<VkBuffer> buffer);
|
||||
bool UpdateBuffer(VkBuffer buffer,
|
||||
size_t offset,
|
||||
const void* data,
|
||||
size_t data_size);
|
||||
void BufferMemoryBarrier(VkBuffer buffer,
|
||||
uint64_t from,
|
||||
uint64_t size,
|
||||
VkPipelineStageFlags src_stage_mask,
|
||||
VkPipelineStageFlags dst_stage_mask,
|
||||
VkAccessFlags src_access,
|
||||
VkAccessFlags dst_sccess);
|
||||
|
||||
bool CreateTexture(Buffer<VkImage>& image,
|
||||
VkImageView& view,
|
||||
DescSet& desc_set,
|
||||
int width,
|
||||
int height,
|
||||
VkImageUsageFlags usage,
|
||||
VmaMemoryUsage mapping);
|
||||
void FreeTexture(Buffer<VkImage> image,
|
||||
VkImageView image_view,
|
||||
DescSet desc_set);
|
||||
bool UpdateImage(VkImage image, const uint8_t* data, int width, int height);
|
||||
void ImageMemoryBarrier(VkImage& image,
|
||||
VkPipelineStageFlags src_stage_mask,
|
||||
VkPipelineStageFlags dst_stage_mask,
|
||||
VkAccessFlags src_access,
|
||||
VkAccessFlags dst_sccess,
|
||||
VkImageLayout old_layout,
|
||||
VkImageLayout new_layout);
|
||||
|
||||
bool CreatePipelineLayout(ShaderVulkan* shader);
|
||||
|
||||
void DrawListBegin();
|
||||
void DrawListEnd();
|
||||
|
||||
void SwapBuffers();
|
||||
|
||||
template <typename T>
|
||||
bool SetUniformInternal(ShaderVulkan* shader, const std::string& name, T val);
|
||||
|
||||
void ContextLost();
|
||||
|
||||
void InvalidateAllResources();
|
||||
};
|
||||
|
||||
} // namespace eng
|
||||
|
||||
#endif // RENDERER_VULKAN_H
|
|
@ -0,0 +1,27 @@
|
|||
#include "renderer_vulkan.h"
|
||||
|
||||
#include <android/native_window.h>
|
||||
|
||||
#include "../../../base/log.h"
|
||||
|
||||
namespace eng {
|
||||
|
||||
bool RendererVulkan::Initialize(ANativeWindow* window) {
|
||||
LOG << "Initializing renderer.";
|
||||
|
||||
screen_width_ = ANativeWindow_getWidth(window);
|
||||
screen_height_ = ANativeWindow_getHeight(window);
|
||||
|
||||
if (!context_.Initialize()) {
|
||||
LOG << "Failed to initialize Vulkan context.";
|
||||
return false;
|
||||
}
|
||||
if (!context_.CreateWindow(window, screen_width_, screen_height_)) {
|
||||
LOG << "Vulkan context failed to create window.";
|
||||
return false;
|
||||
}
|
||||
|
||||
return InitializeInternal();
|
||||
}
|
||||
|
||||
} // namespace eng
|
|
@ -0,0 +1,39 @@
|
|||
#include "renderer_vulkan.h"
|
||||
|
||||
#include "../../../base/log.h"
|
||||
|
||||
namespace eng {
|
||||
|
||||
bool RendererVulkan::Initialize(Display* display, Window window) {
|
||||
LOG << "Initializing renderer.";
|
||||
|
||||
display_ = display;
|
||||
window_ = window;
|
||||
|
||||
XWindowAttributes xwa;
|
||||
XGetWindowAttributes(display_, window_, &xwa);
|
||||
screen_width_ = xwa.width;
|
||||
screen_height_ = xwa.height;
|
||||
|
||||
if (!context_.Initialize()) {
|
||||
LOG << "Failed to initialize Vulkan context.";
|
||||
return false;
|
||||
}
|
||||
if (!context_.CreateWindow(display, window, screen_width_, screen_height_)) {
|
||||
LOG << "Vulkan context failed to create window.";
|
||||
return false;
|
||||
}
|
||||
|
||||
return InitializeInternal();
|
||||
}
|
||||
|
||||
XVisualInfo* RendererVulkan::GetXVisualInfo(Display* display) {
|
||||
long visual_mask = VisualScreenMask;
|
||||
int num_visuals;
|
||||
XVisualInfo visual_info_template = {};
|
||||
visual_info_template.screen = DefaultScreen(display);
|
||||
return XGetVisualInfo(display, visual_mask, &visual_info_template,
|
||||
&num_visuals);
|
||||
}
|
||||
|
||||
} // namespace eng
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,191 @@
|
|||
#ifndef VULKAN_CONTEXT_H
|
||||
#define VULKAN_CONTEXT_H
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
#include "../../../third_party/android/vulkan_wrapper.h"
|
||||
#else
|
||||
#include "../../../third_party/vulkan/vulkan.h"
|
||||
#endif
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
struct ANativeWindow;
|
||||
#endif
|
||||
|
||||
namespace eng {
|
||||
|
||||
// Adapted from godot engin.
|
||||
// https://github.com/godotengine/godot
|
||||
class VulkanContext {
|
||||
public:
|
||||
VulkanContext();
|
||||
~VulkanContext();
|
||||
|
||||
bool Initialize();
|
||||
void Shutdown();
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
bool CreateWindow(ANativeWindow* window, int width, int height);
|
||||
#elif defined(__linux__)
|
||||
bool CreateWindow(Display* display, ::Window window, int width, int height);
|
||||
#endif
|
||||
|
||||
void ResizeWindow(int width, int height);
|
||||
void DestroyWindow();
|
||||
|
||||
VkFramebuffer GetFramebuffer();
|
||||
|
||||
VkRenderPass GetRenderPass() { return window_.render_pass; }
|
||||
|
||||
VkExtent2D GetSwapchainExtent() { return window_.swapchain_extent; }
|
||||
|
||||
void AppendCommandBuffer(const VkCommandBuffer& command_buffer);
|
||||
|
||||
void Flush();
|
||||
|
||||
bool PrepareBuffers();
|
||||
bool SwapBuffers();
|
||||
|
||||
VkInstance GetInstance() { return instance_; }
|
||||
VkDevice GetDevice() { return device_; }
|
||||
VkPhysicalDevice GetPhysicalDevice() { return gpu_; }
|
||||
|
||||
uint32_t GetSwapchainImageCount() const { return swapchain_image_count_; }
|
||||
|
||||
uint32_t GetGraphicsQueue() const { return graphics_queue_family_index_; }
|
||||
|
||||
VkFormat GetScreenFormat() const { return format_; }
|
||||
|
||||
VkPhysicalDeviceLimits GetDeviceLimits() const { return gpu_props_.limits; }
|
||||
|
||||
int GetWidth() { return window_.width; }
|
||||
int GetHeight() { return window_.height; }
|
||||
|
||||
size_t GetAndResetFPS();
|
||||
|
||||
private:
|
||||
enum { kMaxExtensions = 128, kMaxLayers = 64, kFrameLag = 2 };
|
||||
|
||||
struct SwapchainImageResources {
|
||||
VkImage image;
|
||||
VkCommandBuffer graphics_to_present_cmd;
|
||||
VkImageView view;
|
||||
VkFramebuffer frame_buffer;
|
||||
};
|
||||
|
||||
struct Window {
|
||||
VkSurfaceKHR surface = VK_NULL_HANDLE;
|
||||
VkSwapchainKHR swapchain = VK_NULL_HANDLE;
|
||||
std::unique_ptr<SwapchainImageResources[]> swapchain_image_resources;
|
||||
uint32_t current_buffer = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
VkCommandPool present_cmd_pool = VK_NULL_HANDLE;
|
||||
VkRenderPass render_pass = VK_NULL_HANDLE;
|
||||
VkExtent2D swapchain_extent = {0, 0};
|
||||
};
|
||||
|
||||
VkInstance instance_ = VK_NULL_HANDLE;
|
||||
VkPhysicalDevice gpu_ = VK_NULL_HANDLE;
|
||||
VkDevice device_ = VK_NULL_HANDLE;
|
||||
|
||||
VkPhysicalDeviceProperties gpu_props_;
|
||||
uint32_t queue_family_count_ = 0;
|
||||
std::unique_ptr<VkQueueFamilyProperties[]> queue_props_ = nullptr;
|
||||
|
||||
bool buffers_prepared_ = false;
|
||||
|
||||
bool queues_initialized_ = false;
|
||||
bool separate_present_queue_ = false;
|
||||
|
||||
uint32_t graphics_queue_family_index_ = 0;
|
||||
uint32_t present_queue_family_index_ = 0;
|
||||
VkQueue graphics_queue_ = VK_NULL_HANDLE;
|
||||
VkQueue present_queue_ = VK_NULL_HANDLE;
|
||||
|
||||
VkColorSpaceKHR color_space_;
|
||||
VkFormat format_;
|
||||
|
||||
uint32_t frame_index_ = 0;
|
||||
|
||||
VkSemaphore image_acquired_semaphores_[kFrameLag];
|
||||
VkSemaphore draw_complete_semaphores_[kFrameLag];
|
||||
VkSemaphore image_ownership_semaphores_[kFrameLag];
|
||||
VkFence fences_[kFrameLag];
|
||||
|
||||
VkPhysicalDeviceMemoryProperties memory_properties_;
|
||||
VkPhysicalDeviceFeatures physical_device_features_;
|
||||
|
||||
uint32_t swapchain_image_count_ = 0;
|
||||
|
||||
std::vector<VkCommandBuffer> command_buffers_;
|
||||
|
||||
Window window_;
|
||||
|
||||
size_t fps_ = 0;
|
||||
|
||||
// Extensions.
|
||||
uint32_t enabled_extension_count_ = 0;
|
||||
const char* extension_names_[kMaxExtensions];
|
||||
|
||||
uint32_t enabled_layer_count_ = 0;
|
||||
const char* enabled_layers_[kMaxLayers];
|
||||
|
||||
bool use_validation_layers_ = false;
|
||||
|
||||
PFN_vkCreateDebugUtilsMessengerEXT CreateDebugUtilsMessengerEXT;
|
||||
PFN_vkDestroyDebugUtilsMessengerEXT DestroyDebugUtilsMessengerEXT;
|
||||
|
||||
PFN_vkGetPhysicalDeviceSurfaceSupportKHR GetPhysicalDeviceSurfaceSupportKHR;
|
||||
PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR
|
||||
GetPhysicalDeviceSurfaceCapabilitiesKHR;
|
||||
PFN_vkGetPhysicalDeviceSurfaceFormatsKHR GetPhysicalDeviceSurfaceFormatsKHR;
|
||||
PFN_vkGetPhysicalDeviceSurfacePresentModesKHR
|
||||
GetPhysicalDeviceSurfacePresentModesKHR;
|
||||
PFN_vkCreateSwapchainKHR CreateSwapchainKHR;
|
||||
PFN_vkDestroySwapchainKHR DestroySwapchainKHR;
|
||||
PFN_vkGetSwapchainImagesKHR GetSwapchainImagesKHR;
|
||||
PFN_vkAcquireNextImageKHR AcquireNextImageKHR;
|
||||
PFN_vkQueuePresentKHR QueuePresentKHR;
|
||||
|
||||
VkDebugUtilsMessengerEXT dbg_messenger_ = VK_NULL_HANDLE;
|
||||
|
||||
bool CreateValidationLayers();
|
||||
bool InitializeExtensions();
|
||||
|
||||
VkBool32 CheckLayers(uint32_t check_count,
|
||||
const char** check_names,
|
||||
uint32_t layer_count,
|
||||
VkLayerProperties* layers);
|
||||
|
||||
static VKAPI_ATTR VkBool32 VKAPI_CALL DebugMessengerCallback(
|
||||
VkDebugUtilsMessageSeverityFlagBitsEXT message_severity,
|
||||
VkDebugUtilsMessageTypeFlagsEXT message_type,
|
||||
const VkDebugUtilsMessengerCallbackDataEXT* callback_data,
|
||||
void* user_data);
|
||||
|
||||
bool CreatePhysicalDevice();
|
||||
|
||||
bool InitializeQueues(VkSurfaceKHR surface);
|
||||
|
||||
bool CreateDevice();
|
||||
|
||||
bool CleanUpSwapChain(Window* window);
|
||||
|
||||
bool UpdateSwapChain(Window* window);
|
||||
|
||||
bool CreateSwapChain();
|
||||
bool CreateSemaphores();
|
||||
|
||||
const char* GetPlatformSurfaceExtension() const;
|
||||
|
||||
VulkanContext(const VulkanContext&) = delete;
|
||||
VulkanContext& operator=(const VulkanContext&) = delete;
|
||||
};
|
||||
|
||||
} // namespace eng
|
||||
|
||||
#endif // VULKAN_DEVICE_H
|
|
@ -0,0 +1,39 @@
|
|||
#include "vulkan_context.h"
|
||||
|
||||
#include "../../../base/log.h"
|
||||
|
||||
namespace eng {
|
||||
|
||||
const char* VulkanContext::GetPlatformSurfaceExtension() const {
|
||||
return VK_KHR_ANDROID_SURFACE_EXTENSION_NAME;
|
||||
}
|
||||
|
||||
bool VulkanContext::CreateWindow(ANativeWindow* window, int width, int height) {
|
||||
VkAndroidSurfaceCreateInfoKHR surface_info;
|
||||
surface_info.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
|
||||
surface_info.pNext = nullptr;
|
||||
surface_info.flags = 0;
|
||||
surface_info.window = window;
|
||||
|
||||
VkSurfaceKHR surface;
|
||||
VkResult err =
|
||||
vkCreateAndroidSurfaceKHR(instance_, &surface_info, nullptr, &surface);
|
||||
if (err != VK_SUCCESS) {
|
||||
LOG << "vkCreateAndroidSurfaceKHR failed with error "
|
||||
<< std::to_string(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!queues_initialized_ && !InitializeQueues(surface))
|
||||
return false;
|
||||
|
||||
window_.surface = surface;
|
||||
window_.width = width;
|
||||
window_.height = height;
|
||||
if (!UpdateSwapChain(&window_))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace eng
|
|
@ -0,0 +1,43 @@
|
|||
#include "vulkan_context.h"
|
||||
|
||||
#include "../../../base/log.h"
|
||||
|
||||
namespace eng {
|
||||
|
||||
const char* VulkanContext::GetPlatformSurfaceExtension() const {
|
||||
return VK_KHR_XLIB_SURFACE_EXTENSION_NAME;
|
||||
}
|
||||
|
||||
bool VulkanContext::CreateWindow(Display* display,
|
||||
::Window window,
|
||||
int width,
|
||||
int height) {
|
||||
VkXlibSurfaceCreateInfoKHR surface_info;
|
||||
surface_info.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR;
|
||||
surface_info.pNext = nullptr;
|
||||
surface_info.flags = 0;
|
||||
surface_info.dpy = display;
|
||||
surface_info.window = window;
|
||||
|
||||
VkSurfaceKHR surface;
|
||||
VkResult err =
|
||||
vkCreateXlibSurfaceKHR(instance_, &surface_info, nullptr, &surface);
|
||||
if (err != VK_SUCCESS) {
|
||||
LOG << "vkCreateAndroidSurfaceKHR failed with error "
|
||||
<< std::to_string(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!queues_initialized_ && !InitializeQueues(surface))
|
||||
return false;
|
||||
|
||||
window_.surface = surface;
|
||||
window_.width = width;
|
||||
window_.height = height;
|
||||
if (!UpdateSwapChain(&window_))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace eng
|
|
@ -6,40 +6,114 @@
|
|||
#include "engine.h"
|
||||
#include "platform/asset_file.h"
|
||||
|
||||
namespace {
|
||||
|
||||
// Helper macros for our glsl shaders. Makes it possible to write generic code
|
||||
// that compiles both for OpenGL and Vulkan.
|
||||
|
||||
const char kVertexShaderMacros[] = R"(
|
||||
#if defined(VULKAN)
|
||||
#define UNIFORM_BEGIN layout(push_constant) uniform Params {
|
||||
#define UNIFORM_V(X) X;
|
||||
#define UNIFORM_F(X) X;
|
||||
#define UNIFORM_END } params;
|
||||
#define IN(X) layout(location = X) in
|
||||
#define OUT(X) layout(location = X) out
|
||||
#define PARAM(X) params.X
|
||||
#else
|
||||
#define UNIFORM_BEGIN
|
||||
#define UNIFORM uniform
|
||||
#define UNIFORM_V(X) uniform X;
|
||||
#define UNIFORM_F(X)
|
||||
#define UNIFORM_END
|
||||
#define IN(X) attribute
|
||||
#define OUT(X) varying
|
||||
#define PARAM(X) X
|
||||
#endif
|
||||
)";
|
||||
|
||||
const char kFragmentShaderMacros[] = R"(
|
||||
#if defined(VULKAN)
|
||||
#define UNIFORM_BEGIN layout(push_constant) uniform Params {
|
||||
#define UNIFORM_V(X) X;
|
||||
#define UNIFORM_F(X) X;
|
||||
#define UNIFORM_S(X)
|
||||
#define UNIFORM_END } params;
|
||||
#define SAMPLER(X) layout(set = 0, binding = 0) uniform X;
|
||||
#define IN(X) layout(location = X) in
|
||||
#define OUT(X) layout(location = X) out
|
||||
#define FRAG_COLOR_OUT(X) layout(location = 0) out vec4 X;
|
||||
#define FRAG_COLOR(X) X
|
||||
#define PARAM(X) params.X
|
||||
#define TEXTURE texture
|
||||
#else
|
||||
#define UNIFORM_BEGIN
|
||||
#define UNIFORM_V(X)
|
||||
#define UNIFORM_F(X) uniform X;
|
||||
#define UNIFORM_S(X) uniform X;
|
||||
#define UNIFORM_END
|
||||
#define SAMPLER(X)
|
||||
#define IN(X) varying
|
||||
#define OUT(X) varying
|
||||
#define FRAG_COLOR_OUT(X)
|
||||
#define FRAG_COLOR(X) gl_FragColor
|
||||
#define PARAM(X) X
|
||||
#define TEXTURE texture2D
|
||||
#endif
|
||||
)";
|
||||
|
||||
template <size_t N>
|
||||
constexpr size_t length(char const (&)[N]) {
|
||||
return N - 1;
|
||||
}
|
||||
|
||||
constexpr size_t kVertexShaderMacrosLen = length(kVertexShaderMacros);
|
||||
constexpr size_t kFragmentShaderMacrosLen = length(kFragmentShaderMacros);
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace eng {
|
||||
|
||||
bool ShaderSource::Load(const std::string& name) {
|
||||
Engine& engine = Engine::Get();
|
||||
|
||||
name_ = name;
|
||||
|
||||
std::string vertex_file_name = name;
|
||||
vertex_file_name += "_vertex";
|
||||
auto vertex_source = AssetFile::ReadWholeFile(vertex_file_name.c_str(),
|
||||
engine.GetRootPath().c_str(),
|
||||
&vertex_source_size_, true);
|
||||
if (!vertex_source) {
|
||||
LOG << "Failed to read file: " << vertex_file_name;
|
||||
vertex_source_size_ =
|
||||
LoadInternal(name + "_vertex", vertex_source_, kVertexShaderMacros,
|
||||
kVertexShaderMacrosLen);
|
||||
if (!vertex_source_)
|
||||
return false;
|
||||
}
|
||||
|
||||
vertex_source_ = std::move(vertex_source);
|
||||
|
||||
std::string fragment_file_name = name;
|
||||
fragment_file_name += "_fragment";
|
||||
auto fragment_source = AssetFile::ReadWholeFile(fragment_file_name.c_str(),
|
||||
engine.GetRootPath().c_str(),
|
||||
&fragment_source_size_, true);
|
||||
if (!fragment_source) {
|
||||
LOG << "Failed to read file: " << fragment_file_name;
|
||||
fragment_source_size_ =
|
||||
LoadInternal(name + "_fragment", fragment_source_, kFragmentShaderMacros,
|
||||
kFragmentShaderMacrosLen);
|
||||
if (!fragment_source_)
|
||||
return false;
|
||||
}
|
||||
|
||||
LOG << "Loaded " << name;
|
||||
|
||||
fragment_source_ = std::move(fragment_source);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t ShaderSource::LoadInternal(const std::string& name,
|
||||
std::unique_ptr<char[]>& dst,
|
||||
const char* inject,
|
||||
size_t inject_len) {
|
||||
size_t size;
|
||||
auto source = AssetFile::ReadWholeFile(
|
||||
name.c_str(), Engine::Get().GetRootPath().c_str(), &size, true);
|
||||
if (!source) {
|
||||
LOG << "Failed to read file: " << name;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Inject macros.
|
||||
size++; // Include the null-terminator.
|
||||
size_t total_size = inject_len + size + 1;
|
||||
dst = std::make_unique<char[]>(total_size);
|
||||
memcpy(dst.get(), inject, inject_len);
|
||||
memcpy(dst.get() + inject_len, source.get(), size);
|
||||
|
||||
return total_size;
|
||||
}
|
||||
|
||||
} // namespace eng
|
||||
|
|
|
@ -29,6 +29,11 @@ class ShaderSource {
|
|||
|
||||
size_t vertex_source_size_ = 0;
|
||||
size_t fragment_source_size_ = 0;
|
||||
|
||||
size_t LoadInternal(const std::string& name,
|
||||
std::unique_ptr<char[]>& dst,
|
||||
const char* inject,
|
||||
size_t inject_len);
|
||||
};
|
||||
|
||||
} // namespace eng
|
||||
|
|
|
@ -0,0 +1,404 @@
|
|||
// Copyright 2016 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// This file is generated.
|
||||
#include "vulkan_wrapper.h"
|
||||
#include <dlfcn.h>
|
||||
|
||||
int InitVulkan(void) {
|
||||
void* libvulkan = dlopen("libvulkan.so", RTLD_NOW | RTLD_LOCAL);
|
||||
if (!libvulkan)
|
||||
return 0;
|
||||
|
||||
// Vulkan supported, set function addresses
|
||||
vkCreateInstance = reinterpret_cast<PFN_vkCreateInstance>(dlsym(libvulkan, "vkCreateInstance"));
|
||||
vkDestroyInstance = reinterpret_cast<PFN_vkDestroyInstance>(dlsym(libvulkan, "vkDestroyInstance"));
|
||||
vkEnumeratePhysicalDevices = reinterpret_cast<PFN_vkEnumeratePhysicalDevices>(dlsym(libvulkan, "vkEnumeratePhysicalDevices"));
|
||||
vkGetPhysicalDeviceFeatures = reinterpret_cast<PFN_vkGetPhysicalDeviceFeatures>(dlsym(libvulkan, "vkGetPhysicalDeviceFeatures"));
|
||||
vkGetPhysicalDeviceFormatProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceFormatProperties>(dlsym(libvulkan, "vkGetPhysicalDeviceFormatProperties"));
|
||||
vkGetPhysicalDeviceImageFormatProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceImageFormatProperties>(dlsym(libvulkan, "vkGetPhysicalDeviceImageFormatProperties"));
|
||||
vkGetPhysicalDeviceProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceProperties>(dlsym(libvulkan, "vkGetPhysicalDeviceProperties"));
|
||||
vkGetPhysicalDeviceQueueFamilyProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceQueueFamilyProperties>(dlsym(libvulkan, "vkGetPhysicalDeviceQueueFamilyProperties"));
|
||||
vkGetPhysicalDeviceMemoryProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceMemoryProperties>(dlsym(libvulkan, "vkGetPhysicalDeviceMemoryProperties"));
|
||||
vkGetInstanceProcAddr = reinterpret_cast<PFN_vkGetInstanceProcAddr>(dlsym(libvulkan, "vkGetInstanceProcAddr"));
|
||||
vkGetDeviceProcAddr = reinterpret_cast<PFN_vkGetDeviceProcAddr>(dlsym(libvulkan, "vkGetDeviceProcAddr"));
|
||||
vkCreateDevice = reinterpret_cast<PFN_vkCreateDevice>(dlsym(libvulkan, "vkCreateDevice"));
|
||||
vkDestroyDevice = reinterpret_cast<PFN_vkDestroyDevice>(dlsym(libvulkan, "vkDestroyDevice"));
|
||||
vkEnumerateInstanceExtensionProperties = reinterpret_cast<PFN_vkEnumerateInstanceExtensionProperties>(dlsym(libvulkan, "vkEnumerateInstanceExtensionProperties"));
|
||||
vkEnumerateDeviceExtensionProperties = reinterpret_cast<PFN_vkEnumerateDeviceExtensionProperties>(dlsym(libvulkan, "vkEnumerateDeviceExtensionProperties"));
|
||||
vkEnumerateInstanceLayerProperties = reinterpret_cast<PFN_vkEnumerateInstanceLayerProperties>(dlsym(libvulkan, "vkEnumerateInstanceLayerProperties"));
|
||||
vkEnumerateDeviceLayerProperties = reinterpret_cast<PFN_vkEnumerateDeviceLayerProperties>(dlsym(libvulkan, "vkEnumerateDeviceLayerProperties"));
|
||||
vkGetDeviceQueue = reinterpret_cast<PFN_vkGetDeviceQueue>(dlsym(libvulkan, "vkGetDeviceQueue"));
|
||||
vkQueueSubmit = reinterpret_cast<PFN_vkQueueSubmit>(dlsym(libvulkan, "vkQueueSubmit"));
|
||||
vkQueueWaitIdle = reinterpret_cast<PFN_vkQueueWaitIdle>(dlsym(libvulkan, "vkQueueWaitIdle"));
|
||||
vkDeviceWaitIdle = reinterpret_cast<PFN_vkDeviceWaitIdle>(dlsym(libvulkan, "vkDeviceWaitIdle"));
|
||||
vkAllocateMemory = reinterpret_cast<PFN_vkAllocateMemory>(dlsym(libvulkan, "vkAllocateMemory"));
|
||||
vkFreeMemory = reinterpret_cast<PFN_vkFreeMemory>(dlsym(libvulkan, "vkFreeMemory"));
|
||||
vkMapMemory = reinterpret_cast<PFN_vkMapMemory>(dlsym(libvulkan, "vkMapMemory"));
|
||||
vkUnmapMemory = reinterpret_cast<PFN_vkUnmapMemory>(dlsym(libvulkan, "vkUnmapMemory"));
|
||||
vkFlushMappedMemoryRanges = reinterpret_cast<PFN_vkFlushMappedMemoryRanges>(dlsym(libvulkan, "vkFlushMappedMemoryRanges"));
|
||||
vkInvalidateMappedMemoryRanges = reinterpret_cast<PFN_vkInvalidateMappedMemoryRanges>(dlsym(libvulkan, "vkInvalidateMappedMemoryRanges"));
|
||||
vkGetDeviceMemoryCommitment = reinterpret_cast<PFN_vkGetDeviceMemoryCommitment>(dlsym(libvulkan, "vkGetDeviceMemoryCommitment"));
|
||||
vkBindBufferMemory = reinterpret_cast<PFN_vkBindBufferMemory>(dlsym(libvulkan, "vkBindBufferMemory"));
|
||||
vkBindImageMemory = reinterpret_cast<PFN_vkBindImageMemory>(dlsym(libvulkan, "vkBindImageMemory"));
|
||||
vkGetBufferMemoryRequirements = reinterpret_cast<PFN_vkGetBufferMemoryRequirements>(dlsym(libvulkan, "vkGetBufferMemoryRequirements"));
|
||||
vkGetImageMemoryRequirements = reinterpret_cast<PFN_vkGetImageMemoryRequirements>(dlsym(libvulkan, "vkGetImageMemoryRequirements"));
|
||||
vkGetImageSparseMemoryRequirements = reinterpret_cast<PFN_vkGetImageSparseMemoryRequirements>(dlsym(libvulkan, "vkGetImageSparseMemoryRequirements"));
|
||||
vkGetPhysicalDeviceSparseImageFormatProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceSparseImageFormatProperties>(dlsym(libvulkan, "vkGetPhysicalDeviceSparseImageFormatProperties"));
|
||||
vkQueueBindSparse = reinterpret_cast<PFN_vkQueueBindSparse>(dlsym(libvulkan, "vkQueueBindSparse"));
|
||||
vkCreateFence = reinterpret_cast<PFN_vkCreateFence>(dlsym(libvulkan, "vkCreateFence"));
|
||||
vkDestroyFence = reinterpret_cast<PFN_vkDestroyFence>(dlsym(libvulkan, "vkDestroyFence"));
|
||||
vkResetFences = reinterpret_cast<PFN_vkResetFences>(dlsym(libvulkan, "vkResetFences"));
|
||||
vkGetFenceStatus = reinterpret_cast<PFN_vkGetFenceStatus>(dlsym(libvulkan, "vkGetFenceStatus"));
|
||||
vkWaitForFences = reinterpret_cast<PFN_vkWaitForFences>(dlsym(libvulkan, "vkWaitForFences"));
|
||||
vkCreateSemaphore = reinterpret_cast<PFN_vkCreateSemaphore>(dlsym(libvulkan, "vkCreateSemaphore"));
|
||||
vkDestroySemaphore = reinterpret_cast<PFN_vkDestroySemaphore>(dlsym(libvulkan, "vkDestroySemaphore"));
|
||||
vkCreateEvent = reinterpret_cast<PFN_vkCreateEvent>(dlsym(libvulkan, "vkCreateEvent"));
|
||||
vkDestroyEvent = reinterpret_cast<PFN_vkDestroyEvent>(dlsym(libvulkan, "vkDestroyEvent"));
|
||||
vkGetEventStatus = reinterpret_cast<PFN_vkGetEventStatus>(dlsym(libvulkan, "vkGetEventStatus"));
|
||||
vkSetEvent = reinterpret_cast<PFN_vkSetEvent>(dlsym(libvulkan, "vkSetEvent"));
|
||||
vkResetEvent = reinterpret_cast<PFN_vkResetEvent>(dlsym(libvulkan, "vkResetEvent"));
|
||||
vkCreateQueryPool = reinterpret_cast<PFN_vkCreateQueryPool>(dlsym(libvulkan, "vkCreateQueryPool"));
|
||||
vkDestroyQueryPool = reinterpret_cast<PFN_vkDestroyQueryPool>(dlsym(libvulkan, "vkDestroyQueryPool"));
|
||||
vkGetQueryPoolResults = reinterpret_cast<PFN_vkGetQueryPoolResults>(dlsym(libvulkan, "vkGetQueryPoolResults"));
|
||||
vkCreateBuffer = reinterpret_cast<PFN_vkCreateBuffer>(dlsym(libvulkan, "vkCreateBuffer"));
|
||||
vkDestroyBuffer = reinterpret_cast<PFN_vkDestroyBuffer>(dlsym(libvulkan, "vkDestroyBuffer"));
|
||||
vkCreateBufferView = reinterpret_cast<PFN_vkCreateBufferView>(dlsym(libvulkan, "vkCreateBufferView"));
|
||||
vkDestroyBufferView = reinterpret_cast<PFN_vkDestroyBufferView>(dlsym(libvulkan, "vkDestroyBufferView"));
|
||||
vkCreateImage = reinterpret_cast<PFN_vkCreateImage>(dlsym(libvulkan, "vkCreateImage"));
|
||||
vkDestroyImage = reinterpret_cast<PFN_vkDestroyImage>(dlsym(libvulkan, "vkDestroyImage"));
|
||||
vkGetImageSubresourceLayout = reinterpret_cast<PFN_vkGetImageSubresourceLayout>(dlsym(libvulkan, "vkGetImageSubresourceLayout"));
|
||||
vkCreateImageView = reinterpret_cast<PFN_vkCreateImageView>(dlsym(libvulkan, "vkCreateImageView"));
|
||||
vkDestroyImageView = reinterpret_cast<PFN_vkDestroyImageView>(dlsym(libvulkan, "vkDestroyImageView"));
|
||||
vkCreateShaderModule = reinterpret_cast<PFN_vkCreateShaderModule>(dlsym(libvulkan, "vkCreateShaderModule"));
|
||||
vkDestroyShaderModule = reinterpret_cast<PFN_vkDestroyShaderModule>(dlsym(libvulkan, "vkDestroyShaderModule"));
|
||||
vkCreatePipelineCache = reinterpret_cast<PFN_vkCreatePipelineCache>(dlsym(libvulkan, "vkCreatePipelineCache"));
|
||||
vkDestroyPipelineCache = reinterpret_cast<PFN_vkDestroyPipelineCache>(dlsym(libvulkan, "vkDestroyPipelineCache"));
|
||||
vkGetPipelineCacheData = reinterpret_cast<PFN_vkGetPipelineCacheData>(dlsym(libvulkan, "vkGetPipelineCacheData"));
|
||||
vkMergePipelineCaches = reinterpret_cast<PFN_vkMergePipelineCaches>(dlsym(libvulkan, "vkMergePipelineCaches"));
|
||||
vkCreateGraphicsPipelines = reinterpret_cast<PFN_vkCreateGraphicsPipelines>(dlsym(libvulkan, "vkCreateGraphicsPipelines"));
|
||||
vkCreateComputePipelines = reinterpret_cast<PFN_vkCreateComputePipelines>(dlsym(libvulkan, "vkCreateComputePipelines"));
|
||||
vkDestroyPipeline = reinterpret_cast<PFN_vkDestroyPipeline>(dlsym(libvulkan, "vkDestroyPipeline"));
|
||||
vkCreatePipelineLayout = reinterpret_cast<PFN_vkCreatePipelineLayout>(dlsym(libvulkan, "vkCreatePipelineLayout"));
|
||||
vkDestroyPipelineLayout = reinterpret_cast<PFN_vkDestroyPipelineLayout>(dlsym(libvulkan, "vkDestroyPipelineLayout"));
|
||||
vkCreateSampler = reinterpret_cast<PFN_vkCreateSampler>(dlsym(libvulkan, "vkCreateSampler"));
|
||||
vkDestroySampler = reinterpret_cast<PFN_vkDestroySampler>(dlsym(libvulkan, "vkDestroySampler"));
|
||||
vkCreateDescriptorSetLayout = reinterpret_cast<PFN_vkCreateDescriptorSetLayout>(dlsym(libvulkan, "vkCreateDescriptorSetLayout"));
|
||||
vkDestroyDescriptorSetLayout = reinterpret_cast<PFN_vkDestroyDescriptorSetLayout>(dlsym(libvulkan, "vkDestroyDescriptorSetLayout"));
|
||||
vkCreateDescriptorPool = reinterpret_cast<PFN_vkCreateDescriptorPool>(dlsym(libvulkan, "vkCreateDescriptorPool"));
|
||||
vkDestroyDescriptorPool = reinterpret_cast<PFN_vkDestroyDescriptorPool>(dlsym(libvulkan, "vkDestroyDescriptorPool"));
|
||||
vkResetDescriptorPool = reinterpret_cast<PFN_vkResetDescriptorPool>(dlsym(libvulkan, "vkResetDescriptorPool"));
|
||||
vkAllocateDescriptorSets = reinterpret_cast<PFN_vkAllocateDescriptorSets>(dlsym(libvulkan, "vkAllocateDescriptorSets"));
|
||||
vkFreeDescriptorSets = reinterpret_cast<PFN_vkFreeDescriptorSets>(dlsym(libvulkan, "vkFreeDescriptorSets"));
|
||||
vkUpdateDescriptorSets = reinterpret_cast<PFN_vkUpdateDescriptorSets>(dlsym(libvulkan, "vkUpdateDescriptorSets"));
|
||||
vkCreateFramebuffer = reinterpret_cast<PFN_vkCreateFramebuffer>(dlsym(libvulkan, "vkCreateFramebuffer"));
|
||||
vkDestroyFramebuffer = reinterpret_cast<PFN_vkDestroyFramebuffer>(dlsym(libvulkan, "vkDestroyFramebuffer"));
|
||||
vkCreateRenderPass = reinterpret_cast<PFN_vkCreateRenderPass>(dlsym(libvulkan, "vkCreateRenderPass"));
|
||||
vkDestroyRenderPass = reinterpret_cast<PFN_vkDestroyRenderPass>(dlsym(libvulkan, "vkDestroyRenderPass"));
|
||||
vkGetRenderAreaGranularity = reinterpret_cast<PFN_vkGetRenderAreaGranularity>(dlsym(libvulkan, "vkGetRenderAreaGranularity"));
|
||||
vkCreateCommandPool = reinterpret_cast<PFN_vkCreateCommandPool>(dlsym(libvulkan, "vkCreateCommandPool"));
|
||||
vkDestroyCommandPool = reinterpret_cast<PFN_vkDestroyCommandPool>(dlsym(libvulkan, "vkDestroyCommandPool"));
|
||||
vkResetCommandPool = reinterpret_cast<PFN_vkResetCommandPool>(dlsym(libvulkan, "vkResetCommandPool"));
|
||||
vkAllocateCommandBuffers = reinterpret_cast<PFN_vkAllocateCommandBuffers>(dlsym(libvulkan, "vkAllocateCommandBuffers"));
|
||||
vkFreeCommandBuffers = reinterpret_cast<PFN_vkFreeCommandBuffers>(dlsym(libvulkan, "vkFreeCommandBuffers"));
|
||||
vkBeginCommandBuffer = reinterpret_cast<PFN_vkBeginCommandBuffer>(dlsym(libvulkan, "vkBeginCommandBuffer"));
|
||||
vkEndCommandBuffer = reinterpret_cast<PFN_vkEndCommandBuffer>(dlsym(libvulkan, "vkEndCommandBuffer"));
|
||||
vkResetCommandBuffer = reinterpret_cast<PFN_vkResetCommandBuffer>(dlsym(libvulkan, "vkResetCommandBuffer"));
|
||||
vkCmdBindPipeline = reinterpret_cast<PFN_vkCmdBindPipeline>(dlsym(libvulkan, "vkCmdBindPipeline"));
|
||||
vkCmdSetViewport = reinterpret_cast<PFN_vkCmdSetViewport>(dlsym(libvulkan, "vkCmdSetViewport"));
|
||||
vkCmdSetScissor = reinterpret_cast<PFN_vkCmdSetScissor>(dlsym(libvulkan, "vkCmdSetScissor"));
|
||||
vkCmdSetLineWidth = reinterpret_cast<PFN_vkCmdSetLineWidth>(dlsym(libvulkan, "vkCmdSetLineWidth"));
|
||||
vkCmdSetDepthBias = reinterpret_cast<PFN_vkCmdSetDepthBias>(dlsym(libvulkan, "vkCmdSetDepthBias"));
|
||||
vkCmdSetBlendConstants = reinterpret_cast<PFN_vkCmdSetBlendConstants>(dlsym(libvulkan, "vkCmdSetBlendConstants"));
|
||||
vkCmdSetDepthBounds = reinterpret_cast<PFN_vkCmdSetDepthBounds>(dlsym(libvulkan, "vkCmdSetDepthBounds"));
|
||||
vkCmdSetStencilCompareMask = reinterpret_cast<PFN_vkCmdSetStencilCompareMask>(dlsym(libvulkan, "vkCmdSetStencilCompareMask"));
|
||||
vkCmdSetStencilWriteMask = reinterpret_cast<PFN_vkCmdSetStencilWriteMask>(dlsym(libvulkan, "vkCmdSetStencilWriteMask"));
|
||||
vkCmdSetStencilReference = reinterpret_cast<PFN_vkCmdSetStencilReference>(dlsym(libvulkan, "vkCmdSetStencilReference"));
|
||||
vkCmdBindDescriptorSets = reinterpret_cast<PFN_vkCmdBindDescriptorSets>(dlsym(libvulkan, "vkCmdBindDescriptorSets"));
|
||||
vkCmdBindIndexBuffer = reinterpret_cast<PFN_vkCmdBindIndexBuffer>(dlsym(libvulkan, "vkCmdBindIndexBuffer"));
|
||||
vkCmdBindVertexBuffers = reinterpret_cast<PFN_vkCmdBindVertexBuffers>(dlsym(libvulkan, "vkCmdBindVertexBuffers"));
|
||||
vkCmdDraw = reinterpret_cast<PFN_vkCmdDraw>(dlsym(libvulkan, "vkCmdDraw"));
|
||||
vkCmdDrawIndexed = reinterpret_cast<PFN_vkCmdDrawIndexed>(dlsym(libvulkan, "vkCmdDrawIndexed"));
|
||||
vkCmdDrawIndirect = reinterpret_cast<PFN_vkCmdDrawIndirect>(dlsym(libvulkan, "vkCmdDrawIndirect"));
|
||||
vkCmdDrawIndexedIndirect = reinterpret_cast<PFN_vkCmdDrawIndexedIndirect>(dlsym(libvulkan, "vkCmdDrawIndexedIndirect"));
|
||||
vkCmdDispatch = reinterpret_cast<PFN_vkCmdDispatch>(dlsym(libvulkan, "vkCmdDispatch"));
|
||||
vkCmdDispatchIndirect = reinterpret_cast<PFN_vkCmdDispatchIndirect>(dlsym(libvulkan, "vkCmdDispatchIndirect"));
|
||||
vkCmdCopyBuffer = reinterpret_cast<PFN_vkCmdCopyBuffer>(dlsym(libvulkan, "vkCmdCopyBuffer"));
|
||||
vkCmdCopyImage = reinterpret_cast<PFN_vkCmdCopyImage>(dlsym(libvulkan, "vkCmdCopyImage"));
|
||||
vkCmdBlitImage = reinterpret_cast<PFN_vkCmdBlitImage>(dlsym(libvulkan, "vkCmdBlitImage"));
|
||||
vkCmdCopyBufferToImage = reinterpret_cast<PFN_vkCmdCopyBufferToImage>(dlsym(libvulkan, "vkCmdCopyBufferToImage"));
|
||||
vkCmdCopyImageToBuffer = reinterpret_cast<PFN_vkCmdCopyImageToBuffer>(dlsym(libvulkan, "vkCmdCopyImageToBuffer"));
|
||||
vkCmdUpdateBuffer = reinterpret_cast<PFN_vkCmdUpdateBuffer>(dlsym(libvulkan, "vkCmdUpdateBuffer"));
|
||||
vkCmdFillBuffer = reinterpret_cast<PFN_vkCmdFillBuffer>(dlsym(libvulkan, "vkCmdFillBuffer"));
|
||||
vkCmdClearColorImage = reinterpret_cast<PFN_vkCmdClearColorImage>(dlsym(libvulkan, "vkCmdClearColorImage"));
|
||||
vkCmdClearDepthStencilImage = reinterpret_cast<PFN_vkCmdClearDepthStencilImage>(dlsym(libvulkan, "vkCmdClearDepthStencilImage"));
|
||||
vkCmdClearAttachments = reinterpret_cast<PFN_vkCmdClearAttachments>(dlsym(libvulkan, "vkCmdClearAttachments"));
|
||||
vkCmdResolveImage = reinterpret_cast<PFN_vkCmdResolveImage>(dlsym(libvulkan, "vkCmdResolveImage"));
|
||||
vkCmdSetEvent = reinterpret_cast<PFN_vkCmdSetEvent>(dlsym(libvulkan, "vkCmdSetEvent"));
|
||||
vkCmdResetEvent = reinterpret_cast<PFN_vkCmdResetEvent>(dlsym(libvulkan, "vkCmdResetEvent"));
|
||||
vkCmdWaitEvents = reinterpret_cast<PFN_vkCmdWaitEvents>(dlsym(libvulkan, "vkCmdWaitEvents"));
|
||||
vkCmdPipelineBarrier = reinterpret_cast<PFN_vkCmdPipelineBarrier>(dlsym(libvulkan, "vkCmdPipelineBarrier"));
|
||||
vkCmdBeginQuery = reinterpret_cast<PFN_vkCmdBeginQuery>(dlsym(libvulkan, "vkCmdBeginQuery"));
|
||||
vkCmdEndQuery = reinterpret_cast<PFN_vkCmdEndQuery>(dlsym(libvulkan, "vkCmdEndQuery"));
|
||||
vkCmdResetQueryPool = reinterpret_cast<PFN_vkCmdResetQueryPool>(dlsym(libvulkan, "vkCmdResetQueryPool"));
|
||||
vkCmdWriteTimestamp = reinterpret_cast<PFN_vkCmdWriteTimestamp>(dlsym(libvulkan, "vkCmdWriteTimestamp"));
|
||||
vkCmdCopyQueryPoolResults = reinterpret_cast<PFN_vkCmdCopyQueryPoolResults>(dlsym(libvulkan, "vkCmdCopyQueryPoolResults"));
|
||||
vkCmdPushConstants = reinterpret_cast<PFN_vkCmdPushConstants>(dlsym(libvulkan, "vkCmdPushConstants"));
|
||||
vkCmdBeginRenderPass = reinterpret_cast<PFN_vkCmdBeginRenderPass>(dlsym(libvulkan, "vkCmdBeginRenderPass"));
|
||||
vkCmdNextSubpass = reinterpret_cast<PFN_vkCmdNextSubpass>(dlsym(libvulkan, "vkCmdNextSubpass"));
|
||||
vkCmdEndRenderPass = reinterpret_cast<PFN_vkCmdEndRenderPass>(dlsym(libvulkan, "vkCmdEndRenderPass"));
|
||||
vkCmdExecuteCommands = reinterpret_cast<PFN_vkCmdExecuteCommands>(dlsym(libvulkan, "vkCmdExecuteCommands"));
|
||||
vkDestroySurfaceKHR = reinterpret_cast<PFN_vkDestroySurfaceKHR>(dlsym(libvulkan, "vkDestroySurfaceKHR"));
|
||||
vkGetPhysicalDeviceSurfaceSupportKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceSupportKHR>(dlsym(libvulkan, "vkGetPhysicalDeviceSurfaceSupportKHR"));
|
||||
vkGetPhysicalDeviceSurfaceCapabilitiesKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR>(dlsym(libvulkan, "vkGetPhysicalDeviceSurfaceCapabilitiesKHR"));
|
||||
vkGetPhysicalDeviceSurfaceFormatsKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceFormatsKHR>(dlsym(libvulkan, "vkGetPhysicalDeviceSurfaceFormatsKHR"));
|
||||
vkGetPhysicalDeviceSurfacePresentModesKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceSurfacePresentModesKHR>(dlsym(libvulkan, "vkGetPhysicalDeviceSurfacePresentModesKHR"));
|
||||
vkCreateSwapchainKHR = reinterpret_cast<PFN_vkCreateSwapchainKHR>(dlsym(libvulkan, "vkCreateSwapchainKHR"));
|
||||
vkDestroySwapchainKHR = reinterpret_cast<PFN_vkDestroySwapchainKHR>(dlsym(libvulkan, "vkDestroySwapchainKHR"));
|
||||
vkGetSwapchainImagesKHR = reinterpret_cast<PFN_vkGetSwapchainImagesKHR>(dlsym(libvulkan, "vkGetSwapchainImagesKHR"));
|
||||
vkAcquireNextImageKHR = reinterpret_cast<PFN_vkAcquireNextImageKHR>(dlsym(libvulkan, "vkAcquireNextImageKHR"));
|
||||
vkQueuePresentKHR = reinterpret_cast<PFN_vkQueuePresentKHR>(dlsym(libvulkan, "vkQueuePresentKHR"));
|
||||
vkGetPhysicalDeviceDisplayPropertiesKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceDisplayPropertiesKHR>(dlsym(libvulkan, "vkGetPhysicalDeviceDisplayPropertiesKHR"));
|
||||
vkGetPhysicalDeviceDisplayPlanePropertiesKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR>(dlsym(libvulkan, "vkGetPhysicalDeviceDisplayPlanePropertiesKHR"));
|
||||
vkGetDisplayPlaneSupportedDisplaysKHR = reinterpret_cast<PFN_vkGetDisplayPlaneSupportedDisplaysKHR>(dlsym(libvulkan, "vkGetDisplayPlaneSupportedDisplaysKHR"));
|
||||
vkGetDisplayModePropertiesKHR = reinterpret_cast<PFN_vkGetDisplayModePropertiesKHR>(dlsym(libvulkan, "vkGetDisplayModePropertiesKHR"));
|
||||
vkCreateDisplayModeKHR = reinterpret_cast<PFN_vkCreateDisplayModeKHR>(dlsym(libvulkan, "vkCreateDisplayModeKHR"));
|
||||
vkGetDisplayPlaneCapabilitiesKHR = reinterpret_cast<PFN_vkGetDisplayPlaneCapabilitiesKHR>(dlsym(libvulkan, "vkGetDisplayPlaneCapabilitiesKHR"));
|
||||
vkCreateDisplayPlaneSurfaceKHR = reinterpret_cast<PFN_vkCreateDisplayPlaneSurfaceKHR>(dlsym(libvulkan, "vkCreateDisplayPlaneSurfaceKHR"));
|
||||
vkCreateSharedSwapchainsKHR = reinterpret_cast<PFN_vkCreateSharedSwapchainsKHR>(dlsym(libvulkan, "vkCreateSharedSwapchainsKHR"));
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
||||
vkCreateXlibSurfaceKHR = reinterpret_cast<PFN_vkCreateXlibSurfaceKHR>(dlsym(libvulkan, "vkCreateXlibSurfaceKHR"));
|
||||
vkGetPhysicalDeviceXlibPresentationSupportKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR>(dlsym(libvulkan, "vkGetPhysicalDeviceXlibPresentationSupportKHR"));
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XCB_KHR
|
||||
vkCreateXcbSurfaceKHR = reinterpret_cast<PFN_vkCreateXcbSurfaceKHR>(dlsym(libvulkan, "vkCreateXcbSurfaceKHR"));
|
||||
vkGetPhysicalDeviceXcbPresentationSupportKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR>(dlsym(libvulkan, "vkGetPhysicalDeviceXcbPresentationSupportKHR"));
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||
vkCreateWaylandSurfaceKHR = reinterpret_cast<PFN_vkCreateWaylandSurfaceKHR>(dlsym(libvulkan, "vkCreateWaylandSurfaceKHR"));
|
||||
vkGetPhysicalDeviceWaylandPresentationSupportKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR>(dlsym(libvulkan, "vkGetPhysicalDeviceWaylandPresentationSupportKHR"));
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_MIR_KHR
|
||||
vkCreateMirSurfaceKHR = reinterpret_cast<PFN_vkCreateMirSurfaceKHR>(dlsym(libvulkan, "vkCreateMirSurfaceKHR"));
|
||||
vkGetPhysicalDeviceMirPresentationSupportKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceMirPresentationSupportKHR>(dlsym(libvulkan, "vkGetPhysicalDeviceMirPresentationSupportKHR"));
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||
vkCreateAndroidSurfaceKHR = reinterpret_cast<PFN_vkCreateAndroidSurfaceKHR>(dlsym(libvulkan, "vkCreateAndroidSurfaceKHR"));
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
||||
vkCreateWin32SurfaceKHR = reinterpret_cast<PFN_vkCreateWin32SurfaceKHR>(dlsym(libvulkan, "vkCreateWin32SurfaceKHR"));
|
||||
vkGetPhysicalDeviceWin32PresentationSupportKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR>(dlsym(libvulkan, "vkGetPhysicalDeviceWin32PresentationSupportKHR"));
|
||||
#endif
|
||||
#ifdef USE_DEBUG_EXTENTIONS
|
||||
vkCreateDebugReportCallbackEXT = reinterpret_cast<PFN_vkCreateDebugReportCallbackEXT>(dlsym(libvulkan, "vkCreateDebugReportCallbackEXT"));
|
||||
vkDestroyDebugReportCallbackEXT = reinterpret_cast<PFN_vkDestroyDebugReportCallbackEXT>(dlsym(libvulkan, "vkDestroyDebugReportCallbackEXT"));
|
||||
vkDebugReportMessageEXT = reinterpret_cast<PFN_vkDebugReportMessageEXT>(dlsym(libvulkan, "vkDebugReportMessageEXT"));
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
// No Vulkan support, do not set function addresses
|
||||
PFN_vkCreateInstance vkCreateInstance;
|
||||
PFN_vkDestroyInstance vkDestroyInstance;
|
||||
PFN_vkEnumeratePhysicalDevices vkEnumeratePhysicalDevices;
|
||||
PFN_vkGetPhysicalDeviceFeatures vkGetPhysicalDeviceFeatures;
|
||||
PFN_vkGetPhysicalDeviceFormatProperties vkGetPhysicalDeviceFormatProperties;
|
||||
PFN_vkGetPhysicalDeviceImageFormatProperties vkGetPhysicalDeviceImageFormatProperties;
|
||||
PFN_vkGetPhysicalDeviceProperties vkGetPhysicalDeviceProperties;
|
||||
PFN_vkGetPhysicalDeviceQueueFamilyProperties vkGetPhysicalDeviceQueueFamilyProperties;
|
||||
PFN_vkGetPhysicalDeviceMemoryProperties vkGetPhysicalDeviceMemoryProperties;
|
||||
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
|
||||
PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr;
|
||||
PFN_vkCreateDevice vkCreateDevice;
|
||||
PFN_vkDestroyDevice vkDestroyDevice;
|
||||
PFN_vkEnumerateInstanceExtensionProperties vkEnumerateInstanceExtensionProperties;
|
||||
PFN_vkEnumerateDeviceExtensionProperties vkEnumerateDeviceExtensionProperties;
|
||||
PFN_vkEnumerateInstanceLayerProperties vkEnumerateInstanceLayerProperties;
|
||||
PFN_vkEnumerateDeviceLayerProperties vkEnumerateDeviceLayerProperties;
|
||||
PFN_vkGetDeviceQueue vkGetDeviceQueue;
|
||||
PFN_vkQueueSubmit vkQueueSubmit;
|
||||
PFN_vkQueueWaitIdle vkQueueWaitIdle;
|
||||
PFN_vkDeviceWaitIdle vkDeviceWaitIdle;
|
||||
PFN_vkAllocateMemory vkAllocateMemory;
|
||||
PFN_vkFreeMemory vkFreeMemory;
|
||||
PFN_vkMapMemory vkMapMemory;
|
||||
PFN_vkUnmapMemory vkUnmapMemory;
|
||||
PFN_vkFlushMappedMemoryRanges vkFlushMappedMemoryRanges;
|
||||
PFN_vkInvalidateMappedMemoryRanges vkInvalidateMappedMemoryRanges;
|
||||
PFN_vkGetDeviceMemoryCommitment vkGetDeviceMemoryCommitment;
|
||||
PFN_vkBindBufferMemory vkBindBufferMemory;
|
||||
PFN_vkBindImageMemory vkBindImageMemory;
|
||||
PFN_vkGetBufferMemoryRequirements vkGetBufferMemoryRequirements;
|
||||
PFN_vkGetImageMemoryRequirements vkGetImageMemoryRequirements;
|
||||
PFN_vkGetImageSparseMemoryRequirements vkGetImageSparseMemoryRequirements;
|
||||
PFN_vkGetPhysicalDeviceSparseImageFormatProperties vkGetPhysicalDeviceSparseImageFormatProperties;
|
||||
PFN_vkQueueBindSparse vkQueueBindSparse;
|
||||
PFN_vkCreateFence vkCreateFence;
|
||||
PFN_vkDestroyFence vkDestroyFence;
|
||||
PFN_vkResetFences vkResetFences;
|
||||
PFN_vkGetFenceStatus vkGetFenceStatus;
|
||||
PFN_vkWaitForFences vkWaitForFences;
|
||||
PFN_vkCreateSemaphore vkCreateSemaphore;
|
||||
PFN_vkDestroySemaphore vkDestroySemaphore;
|
||||
PFN_vkCreateEvent vkCreateEvent;
|
||||
PFN_vkDestroyEvent vkDestroyEvent;
|
||||
PFN_vkGetEventStatus vkGetEventStatus;
|
||||
PFN_vkSetEvent vkSetEvent;
|
||||
PFN_vkResetEvent vkResetEvent;
|
||||
PFN_vkCreateQueryPool vkCreateQueryPool;
|
||||
PFN_vkDestroyQueryPool vkDestroyQueryPool;
|
||||
PFN_vkGetQueryPoolResults vkGetQueryPoolResults;
|
||||
PFN_vkCreateBuffer vkCreateBuffer;
|
||||
PFN_vkDestroyBuffer vkDestroyBuffer;
|
||||
PFN_vkCreateBufferView vkCreateBufferView;
|
||||
PFN_vkDestroyBufferView vkDestroyBufferView;
|
||||
PFN_vkCreateImage vkCreateImage;
|
||||
PFN_vkDestroyImage vkDestroyImage;
|
||||
PFN_vkGetImageSubresourceLayout vkGetImageSubresourceLayout;
|
||||
PFN_vkCreateImageView vkCreateImageView;
|
||||
PFN_vkDestroyImageView vkDestroyImageView;
|
||||
PFN_vkCreateShaderModule vkCreateShaderModule;
|
||||
PFN_vkDestroyShaderModule vkDestroyShaderModule;
|
||||
PFN_vkCreatePipelineCache vkCreatePipelineCache;
|
||||
PFN_vkDestroyPipelineCache vkDestroyPipelineCache;
|
||||
PFN_vkGetPipelineCacheData vkGetPipelineCacheData;
|
||||
PFN_vkMergePipelineCaches vkMergePipelineCaches;
|
||||
PFN_vkCreateGraphicsPipelines vkCreateGraphicsPipelines;
|
||||
PFN_vkCreateComputePipelines vkCreateComputePipelines;
|
||||
PFN_vkDestroyPipeline vkDestroyPipeline;
|
||||
PFN_vkCreatePipelineLayout vkCreatePipelineLayout;
|
||||
PFN_vkDestroyPipelineLayout vkDestroyPipelineLayout;
|
||||
PFN_vkCreateSampler vkCreateSampler;
|
||||
PFN_vkDestroySampler vkDestroySampler;
|
||||
PFN_vkCreateDescriptorSetLayout vkCreateDescriptorSetLayout;
|
||||
PFN_vkDestroyDescriptorSetLayout vkDestroyDescriptorSetLayout;
|
||||
PFN_vkCreateDescriptorPool vkCreateDescriptorPool;
|
||||
PFN_vkDestroyDescriptorPool vkDestroyDescriptorPool;
|
||||
PFN_vkResetDescriptorPool vkResetDescriptorPool;
|
||||
PFN_vkAllocateDescriptorSets vkAllocateDescriptorSets;
|
||||
PFN_vkFreeDescriptorSets vkFreeDescriptorSets;
|
||||
PFN_vkUpdateDescriptorSets vkUpdateDescriptorSets;
|
||||
PFN_vkCreateFramebuffer vkCreateFramebuffer;
|
||||
PFN_vkDestroyFramebuffer vkDestroyFramebuffer;
|
||||
PFN_vkCreateRenderPass vkCreateRenderPass;
|
||||
PFN_vkDestroyRenderPass vkDestroyRenderPass;
|
||||
PFN_vkGetRenderAreaGranularity vkGetRenderAreaGranularity;
|
||||
PFN_vkCreateCommandPool vkCreateCommandPool;
|
||||
PFN_vkDestroyCommandPool vkDestroyCommandPool;
|
||||
PFN_vkResetCommandPool vkResetCommandPool;
|
||||
PFN_vkAllocateCommandBuffers vkAllocateCommandBuffers;
|
||||
PFN_vkFreeCommandBuffers vkFreeCommandBuffers;
|
||||
PFN_vkBeginCommandBuffer vkBeginCommandBuffer;
|
||||
PFN_vkEndCommandBuffer vkEndCommandBuffer;
|
||||
PFN_vkResetCommandBuffer vkResetCommandBuffer;
|
||||
PFN_vkCmdBindPipeline vkCmdBindPipeline;
|
||||
PFN_vkCmdSetViewport vkCmdSetViewport;
|
||||
PFN_vkCmdSetScissor vkCmdSetScissor;
|
||||
PFN_vkCmdSetLineWidth vkCmdSetLineWidth;
|
||||
PFN_vkCmdSetDepthBias vkCmdSetDepthBias;
|
||||
PFN_vkCmdSetBlendConstants vkCmdSetBlendConstants;
|
||||
PFN_vkCmdSetDepthBounds vkCmdSetDepthBounds;
|
||||
PFN_vkCmdSetStencilCompareMask vkCmdSetStencilCompareMask;
|
||||
PFN_vkCmdSetStencilWriteMask vkCmdSetStencilWriteMask;
|
||||
PFN_vkCmdSetStencilReference vkCmdSetStencilReference;
|
||||
PFN_vkCmdBindDescriptorSets vkCmdBindDescriptorSets;
|
||||
PFN_vkCmdBindIndexBuffer vkCmdBindIndexBuffer;
|
||||
PFN_vkCmdBindVertexBuffers vkCmdBindVertexBuffers;
|
||||
PFN_vkCmdDraw vkCmdDraw;
|
||||
PFN_vkCmdDrawIndexed vkCmdDrawIndexed;
|
||||
PFN_vkCmdDrawIndirect vkCmdDrawIndirect;
|
||||
PFN_vkCmdDrawIndexedIndirect vkCmdDrawIndexedIndirect;
|
||||
PFN_vkCmdDispatch vkCmdDispatch;
|
||||
PFN_vkCmdDispatchIndirect vkCmdDispatchIndirect;
|
||||
PFN_vkCmdCopyBuffer vkCmdCopyBuffer;
|
||||
PFN_vkCmdCopyImage vkCmdCopyImage;
|
||||
PFN_vkCmdBlitImage vkCmdBlitImage;
|
||||
PFN_vkCmdCopyBufferToImage vkCmdCopyBufferToImage;
|
||||
PFN_vkCmdCopyImageToBuffer vkCmdCopyImageToBuffer;
|
||||
PFN_vkCmdUpdateBuffer vkCmdUpdateBuffer;
|
||||
PFN_vkCmdFillBuffer vkCmdFillBuffer;
|
||||
PFN_vkCmdClearColorImage vkCmdClearColorImage;
|
||||
PFN_vkCmdClearDepthStencilImage vkCmdClearDepthStencilImage;
|
||||
PFN_vkCmdClearAttachments vkCmdClearAttachments;
|
||||
PFN_vkCmdResolveImage vkCmdResolveImage;
|
||||
PFN_vkCmdSetEvent vkCmdSetEvent;
|
||||
PFN_vkCmdResetEvent vkCmdResetEvent;
|
||||
PFN_vkCmdWaitEvents vkCmdWaitEvents;
|
||||
PFN_vkCmdPipelineBarrier vkCmdPipelineBarrier;
|
||||
PFN_vkCmdBeginQuery vkCmdBeginQuery;
|
||||
PFN_vkCmdEndQuery vkCmdEndQuery;
|
||||
PFN_vkCmdResetQueryPool vkCmdResetQueryPool;
|
||||
PFN_vkCmdWriteTimestamp vkCmdWriteTimestamp;
|
||||
PFN_vkCmdCopyQueryPoolResults vkCmdCopyQueryPoolResults;
|
||||
PFN_vkCmdPushConstants vkCmdPushConstants;
|
||||
PFN_vkCmdBeginRenderPass vkCmdBeginRenderPass;
|
||||
PFN_vkCmdNextSubpass vkCmdNextSubpass;
|
||||
PFN_vkCmdEndRenderPass vkCmdEndRenderPass;
|
||||
PFN_vkCmdExecuteCommands vkCmdExecuteCommands;
|
||||
PFN_vkDestroySurfaceKHR vkDestroySurfaceKHR;
|
||||
PFN_vkGetPhysicalDeviceSurfaceSupportKHR vkGetPhysicalDeviceSurfaceSupportKHR;
|
||||
PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR vkGetPhysicalDeviceSurfaceCapabilitiesKHR;
|
||||
PFN_vkGetPhysicalDeviceSurfaceFormatsKHR vkGetPhysicalDeviceSurfaceFormatsKHR;
|
||||
PFN_vkGetPhysicalDeviceSurfacePresentModesKHR vkGetPhysicalDeviceSurfacePresentModesKHR;
|
||||
PFN_vkCreateSwapchainKHR vkCreateSwapchainKHR;
|
||||
PFN_vkDestroySwapchainKHR vkDestroySwapchainKHR;
|
||||
PFN_vkGetSwapchainImagesKHR vkGetSwapchainImagesKHR;
|
||||
PFN_vkAcquireNextImageKHR vkAcquireNextImageKHR;
|
||||
PFN_vkQueuePresentKHR vkQueuePresentKHR;
|
||||
PFN_vkGetPhysicalDeviceDisplayPropertiesKHR vkGetPhysicalDeviceDisplayPropertiesKHR;
|
||||
PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR vkGetPhysicalDeviceDisplayPlanePropertiesKHR;
|
||||
PFN_vkGetDisplayPlaneSupportedDisplaysKHR vkGetDisplayPlaneSupportedDisplaysKHR;
|
||||
PFN_vkGetDisplayModePropertiesKHR vkGetDisplayModePropertiesKHR;
|
||||
PFN_vkCreateDisplayModeKHR vkCreateDisplayModeKHR;
|
||||
PFN_vkGetDisplayPlaneCapabilitiesKHR vkGetDisplayPlaneCapabilitiesKHR;
|
||||
PFN_vkCreateDisplayPlaneSurfaceKHR vkCreateDisplayPlaneSurfaceKHR;
|
||||
PFN_vkCreateSharedSwapchainsKHR vkCreateSharedSwapchainsKHR;
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
||||
PFN_vkCreateXlibSurfaceKHR vkCreateXlibSurfaceKHR;
|
||||
PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR vkGetPhysicalDeviceXlibPresentationSupportKHR;
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XCB_KHR
|
||||
PFN_vkCreateXcbSurfaceKHR vkCreateXcbSurfaceKHR;
|
||||
PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR vkGetPhysicalDeviceXcbPresentationSupportKHR;
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||
PFN_vkCreateWaylandSurfaceKHR vkCreateWaylandSurfaceKHR;
|
||||
PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR vkGetPhysicalDeviceWaylandPresentationSupportKHR;
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_MIR_KHR
|
||||
PFN_vkCreateMirSurfaceKHR vkCreateMirSurfaceKHR;
|
||||
PFN_vkGetPhysicalDeviceMirPresentationSupportKHR vkGetPhysicalDeviceMirPresentationSupportKHR;
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||
PFN_vkCreateAndroidSurfaceKHR vkCreateAndroidSurfaceKHR;
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
||||
PFN_vkCreateWin32SurfaceKHR vkCreateWin32SurfaceKHR;
|
||||
PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR vkGetPhysicalDeviceWin32PresentationSupportKHR;
|
||||
#endif
|
||||
PFN_vkCreateDebugReportCallbackEXT vkCreateDebugReportCallbackEXT;
|
||||
PFN_vkDestroyDebugReportCallbackEXT vkDestroyDebugReportCallbackEXT;
|
||||
PFN_vkDebugReportMessageEXT vkDebugReportMessageEXT;
|
||||
|
|
@ -0,0 +1,236 @@
|
|||
// Copyright 2016 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// This file is generated.
|
||||
#ifndef VULKAN_WRAPPER_H
|
||||
#define VULKAN_WRAPPER_H
|
||||
|
||||
#define VK_NO_PROTOTYPES 1
|
||||
#include "../vulkan/vulkan.h"
|
||||
|
||||
/* Initialize the Vulkan function pointer variables declared in this header.
|
||||
* Returns 0 if vulkan is not available, non-zero if it is available.
|
||||
*/
|
||||
int InitVulkan(void);
|
||||
|
||||
// VK_core
|
||||
extern PFN_vkCreateInstance vkCreateInstance;
|
||||
extern PFN_vkDestroyInstance vkDestroyInstance;
|
||||
extern PFN_vkEnumeratePhysicalDevices vkEnumeratePhysicalDevices;
|
||||
extern PFN_vkGetPhysicalDeviceFeatures vkGetPhysicalDeviceFeatures;
|
||||
extern PFN_vkGetPhysicalDeviceFormatProperties vkGetPhysicalDeviceFormatProperties;
|
||||
extern PFN_vkGetPhysicalDeviceImageFormatProperties vkGetPhysicalDeviceImageFormatProperties;
|
||||
extern PFN_vkGetPhysicalDeviceProperties vkGetPhysicalDeviceProperties;
|
||||
extern PFN_vkGetPhysicalDeviceQueueFamilyProperties vkGetPhysicalDeviceQueueFamilyProperties;
|
||||
extern PFN_vkGetPhysicalDeviceMemoryProperties vkGetPhysicalDeviceMemoryProperties;
|
||||
extern PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
|
||||
extern PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr;
|
||||
extern PFN_vkCreateDevice vkCreateDevice;
|
||||
extern PFN_vkDestroyDevice vkDestroyDevice;
|
||||
extern PFN_vkEnumerateInstanceExtensionProperties vkEnumerateInstanceExtensionProperties;
|
||||
extern PFN_vkEnumerateDeviceExtensionProperties vkEnumerateDeviceExtensionProperties;
|
||||
extern PFN_vkEnumerateInstanceLayerProperties vkEnumerateInstanceLayerProperties;
|
||||
extern PFN_vkEnumerateDeviceLayerProperties vkEnumerateDeviceLayerProperties;
|
||||
extern PFN_vkGetDeviceQueue vkGetDeviceQueue;
|
||||
extern PFN_vkQueueSubmit vkQueueSubmit;
|
||||
extern PFN_vkQueueWaitIdle vkQueueWaitIdle;
|
||||
extern PFN_vkDeviceWaitIdle vkDeviceWaitIdle;
|
||||
extern PFN_vkAllocateMemory vkAllocateMemory;
|
||||
extern PFN_vkFreeMemory vkFreeMemory;
|
||||
extern PFN_vkMapMemory vkMapMemory;
|
||||
extern PFN_vkUnmapMemory vkUnmapMemory;
|
||||
extern PFN_vkFlushMappedMemoryRanges vkFlushMappedMemoryRanges;
|
||||
extern PFN_vkInvalidateMappedMemoryRanges vkInvalidateMappedMemoryRanges;
|
||||
extern PFN_vkGetDeviceMemoryCommitment vkGetDeviceMemoryCommitment;
|
||||
extern PFN_vkBindBufferMemory vkBindBufferMemory;
|
||||
extern PFN_vkBindImageMemory vkBindImageMemory;
|
||||
extern PFN_vkGetBufferMemoryRequirements vkGetBufferMemoryRequirements;
|
||||
extern PFN_vkGetImageMemoryRequirements vkGetImageMemoryRequirements;
|
||||
extern PFN_vkGetImageSparseMemoryRequirements vkGetImageSparseMemoryRequirements;
|
||||
extern PFN_vkGetPhysicalDeviceSparseImageFormatProperties vkGetPhysicalDeviceSparseImageFormatProperties;
|
||||
extern PFN_vkQueueBindSparse vkQueueBindSparse;
|
||||
extern PFN_vkCreateFence vkCreateFence;
|
||||
extern PFN_vkDestroyFence vkDestroyFence;
|
||||
extern PFN_vkResetFences vkResetFences;
|
||||
extern PFN_vkGetFenceStatus vkGetFenceStatus;
|
||||
extern PFN_vkWaitForFences vkWaitForFences;
|
||||
extern PFN_vkCreateSemaphore vkCreateSemaphore;
|
||||
extern PFN_vkDestroySemaphore vkDestroySemaphore;
|
||||
extern PFN_vkCreateEvent vkCreateEvent;
|
||||
extern PFN_vkDestroyEvent vkDestroyEvent;
|
||||
extern PFN_vkGetEventStatus vkGetEventStatus;
|
||||
extern PFN_vkSetEvent vkSetEvent;
|
||||
extern PFN_vkResetEvent vkResetEvent;
|
||||
extern PFN_vkCreateQueryPool vkCreateQueryPool;
|
||||
extern PFN_vkDestroyQueryPool vkDestroyQueryPool;
|
||||
extern PFN_vkGetQueryPoolResults vkGetQueryPoolResults;
|
||||
extern PFN_vkCreateBuffer vkCreateBuffer;
|
||||
extern PFN_vkDestroyBuffer vkDestroyBuffer;
|
||||
extern PFN_vkCreateBufferView vkCreateBufferView;
|
||||
extern PFN_vkDestroyBufferView vkDestroyBufferView;
|
||||
extern PFN_vkCreateImage vkCreateImage;
|
||||
extern PFN_vkDestroyImage vkDestroyImage;
|
||||
extern PFN_vkGetImageSubresourceLayout vkGetImageSubresourceLayout;
|
||||
extern PFN_vkCreateImageView vkCreateImageView;
|
||||
extern PFN_vkDestroyImageView vkDestroyImageView;
|
||||
extern PFN_vkCreateShaderModule vkCreateShaderModule;
|
||||
extern PFN_vkDestroyShaderModule vkDestroyShaderModule;
|
||||
extern PFN_vkCreatePipelineCache vkCreatePipelineCache;
|
||||
extern PFN_vkDestroyPipelineCache vkDestroyPipelineCache;
|
||||
extern PFN_vkGetPipelineCacheData vkGetPipelineCacheData;
|
||||
extern PFN_vkMergePipelineCaches vkMergePipelineCaches;
|
||||
extern PFN_vkCreateGraphicsPipelines vkCreateGraphicsPipelines;
|
||||
extern PFN_vkCreateComputePipelines vkCreateComputePipelines;
|
||||
extern PFN_vkDestroyPipeline vkDestroyPipeline;
|
||||
extern PFN_vkCreatePipelineLayout vkCreatePipelineLayout;
|
||||
extern PFN_vkDestroyPipelineLayout vkDestroyPipelineLayout;
|
||||
extern PFN_vkCreateSampler vkCreateSampler;
|
||||
extern PFN_vkDestroySampler vkDestroySampler;
|
||||
extern PFN_vkCreateDescriptorSetLayout vkCreateDescriptorSetLayout;
|
||||
extern PFN_vkDestroyDescriptorSetLayout vkDestroyDescriptorSetLayout;
|
||||
extern PFN_vkCreateDescriptorPool vkCreateDescriptorPool;
|
||||
extern PFN_vkDestroyDescriptorPool vkDestroyDescriptorPool;
|
||||
extern PFN_vkResetDescriptorPool vkResetDescriptorPool;
|
||||
extern PFN_vkAllocateDescriptorSets vkAllocateDescriptorSets;
|
||||
extern PFN_vkFreeDescriptorSets vkFreeDescriptorSets;
|
||||
extern PFN_vkUpdateDescriptorSets vkUpdateDescriptorSets;
|
||||
extern PFN_vkCreateFramebuffer vkCreateFramebuffer;
|
||||
extern PFN_vkDestroyFramebuffer vkDestroyFramebuffer;
|
||||
extern PFN_vkCreateRenderPass vkCreateRenderPass;
|
||||
extern PFN_vkDestroyRenderPass vkDestroyRenderPass;
|
||||
extern PFN_vkGetRenderAreaGranularity vkGetRenderAreaGranularity;
|
||||
extern PFN_vkCreateCommandPool vkCreateCommandPool;
|
||||
extern PFN_vkDestroyCommandPool vkDestroyCommandPool;
|
||||
extern PFN_vkResetCommandPool vkResetCommandPool;
|
||||
extern PFN_vkAllocateCommandBuffers vkAllocateCommandBuffers;
|
||||
extern PFN_vkFreeCommandBuffers vkFreeCommandBuffers;
|
||||
extern PFN_vkBeginCommandBuffer vkBeginCommandBuffer;
|
||||
extern PFN_vkEndCommandBuffer vkEndCommandBuffer;
|
||||
extern PFN_vkResetCommandBuffer vkResetCommandBuffer;
|
||||
extern PFN_vkCmdBindPipeline vkCmdBindPipeline;
|
||||
extern PFN_vkCmdSetViewport vkCmdSetViewport;
|
||||
extern PFN_vkCmdSetScissor vkCmdSetScissor;
|
||||
extern PFN_vkCmdSetLineWidth vkCmdSetLineWidth;
|
||||
extern PFN_vkCmdSetDepthBias vkCmdSetDepthBias;
|
||||
extern PFN_vkCmdSetBlendConstants vkCmdSetBlendConstants;
|
||||
extern PFN_vkCmdSetDepthBounds vkCmdSetDepthBounds;
|
||||
extern PFN_vkCmdSetStencilCompareMask vkCmdSetStencilCompareMask;
|
||||
extern PFN_vkCmdSetStencilWriteMask vkCmdSetStencilWriteMask;
|
||||
extern PFN_vkCmdSetStencilReference vkCmdSetStencilReference;
|
||||
extern PFN_vkCmdBindDescriptorSets vkCmdBindDescriptorSets;
|
||||
extern PFN_vkCmdBindIndexBuffer vkCmdBindIndexBuffer;
|
||||
extern PFN_vkCmdBindVertexBuffers vkCmdBindVertexBuffers;
|
||||
extern PFN_vkCmdDraw vkCmdDraw;
|
||||
extern PFN_vkCmdDrawIndexed vkCmdDrawIndexed;
|
||||
extern PFN_vkCmdDrawIndirect vkCmdDrawIndirect;
|
||||
extern PFN_vkCmdDrawIndexedIndirect vkCmdDrawIndexedIndirect;
|
||||
extern PFN_vkCmdDispatch vkCmdDispatch;
|
||||
extern PFN_vkCmdDispatchIndirect vkCmdDispatchIndirect;
|
||||
extern PFN_vkCmdCopyBuffer vkCmdCopyBuffer;
|
||||
extern PFN_vkCmdCopyImage vkCmdCopyImage;
|
||||
extern PFN_vkCmdBlitImage vkCmdBlitImage;
|
||||
extern PFN_vkCmdCopyBufferToImage vkCmdCopyBufferToImage;
|
||||
extern PFN_vkCmdCopyImageToBuffer vkCmdCopyImageToBuffer;
|
||||
extern PFN_vkCmdUpdateBuffer vkCmdUpdateBuffer;
|
||||
extern PFN_vkCmdFillBuffer vkCmdFillBuffer;
|
||||
extern PFN_vkCmdClearColorImage vkCmdClearColorImage;
|
||||
extern PFN_vkCmdClearDepthStencilImage vkCmdClearDepthStencilImage;
|
||||
extern PFN_vkCmdClearAttachments vkCmdClearAttachments;
|
||||
extern PFN_vkCmdResolveImage vkCmdResolveImage;
|
||||
extern PFN_vkCmdSetEvent vkCmdSetEvent;
|
||||
extern PFN_vkCmdResetEvent vkCmdResetEvent;
|
||||
extern PFN_vkCmdWaitEvents vkCmdWaitEvents;
|
||||
extern PFN_vkCmdPipelineBarrier vkCmdPipelineBarrier;
|
||||
extern PFN_vkCmdBeginQuery vkCmdBeginQuery;
|
||||
extern PFN_vkCmdEndQuery vkCmdEndQuery;
|
||||
extern PFN_vkCmdResetQueryPool vkCmdResetQueryPool;
|
||||
extern PFN_vkCmdWriteTimestamp vkCmdWriteTimestamp;
|
||||
extern PFN_vkCmdCopyQueryPoolResults vkCmdCopyQueryPoolResults;
|
||||
extern PFN_vkCmdPushConstants vkCmdPushConstants;
|
||||
extern PFN_vkCmdBeginRenderPass vkCmdBeginRenderPass;
|
||||
extern PFN_vkCmdNextSubpass vkCmdNextSubpass;
|
||||
extern PFN_vkCmdEndRenderPass vkCmdEndRenderPass;
|
||||
extern PFN_vkCmdExecuteCommands vkCmdExecuteCommands;
|
||||
|
||||
// VK_KHR_surface
|
||||
extern PFN_vkDestroySurfaceKHR vkDestroySurfaceKHR;
|
||||
extern PFN_vkGetPhysicalDeviceSurfaceSupportKHR vkGetPhysicalDeviceSurfaceSupportKHR;
|
||||
extern PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR vkGetPhysicalDeviceSurfaceCapabilitiesKHR;
|
||||
extern PFN_vkGetPhysicalDeviceSurfaceFormatsKHR vkGetPhysicalDeviceSurfaceFormatsKHR;
|
||||
extern PFN_vkGetPhysicalDeviceSurfacePresentModesKHR vkGetPhysicalDeviceSurfacePresentModesKHR;
|
||||
|
||||
// VK_KHR_swapchain
|
||||
extern PFN_vkCreateSwapchainKHR vkCreateSwapchainKHR;
|
||||
extern PFN_vkDestroySwapchainKHR vkDestroySwapchainKHR;
|
||||
extern PFN_vkGetSwapchainImagesKHR vkGetSwapchainImagesKHR;
|
||||
extern PFN_vkAcquireNextImageKHR vkAcquireNextImageKHR;
|
||||
extern PFN_vkQueuePresentKHR vkQueuePresentKHR;
|
||||
|
||||
// VK_KHR_display
|
||||
extern PFN_vkGetPhysicalDeviceDisplayPropertiesKHR vkGetPhysicalDeviceDisplayPropertiesKHR;
|
||||
extern PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR vkGetPhysicalDeviceDisplayPlanePropertiesKHR;
|
||||
extern PFN_vkGetDisplayPlaneSupportedDisplaysKHR vkGetDisplayPlaneSupportedDisplaysKHR;
|
||||
extern PFN_vkGetDisplayModePropertiesKHR vkGetDisplayModePropertiesKHR;
|
||||
extern PFN_vkCreateDisplayModeKHR vkCreateDisplayModeKHR;
|
||||
extern PFN_vkGetDisplayPlaneCapabilitiesKHR vkGetDisplayPlaneCapabilitiesKHR;
|
||||
extern PFN_vkCreateDisplayPlaneSurfaceKHR vkCreateDisplayPlaneSurfaceKHR;
|
||||
|
||||
// VK_KHR_display_swapchain
|
||||
extern PFN_vkCreateSharedSwapchainsKHR vkCreateSharedSwapchainsKHR;
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
||||
// VK_KHR_xlib_surface
|
||||
extern PFN_vkCreateXlibSurfaceKHR vkCreateXlibSurfaceKHR;
|
||||
extern PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR vkGetPhysicalDeviceXlibPresentationSupportKHR;
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XCB_KHR
|
||||
// VK_KHR_xcb_surface
|
||||
extern PFN_vkCreateXcbSurfaceKHR vkCreateXcbSurfaceKHR;
|
||||
extern PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR vkGetPhysicalDeviceXcbPresentationSupportKHR;
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||
// VK_KHR_wayland_surface
|
||||
extern PFN_vkCreateWaylandSurfaceKHR vkCreateWaylandSurfaceKHR;
|
||||
extern PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR vkGetPhysicalDeviceWaylandPresentationSupportKHR;
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_MIR_KHR
|
||||
// VK_KHR_mir_surface
|
||||
extern PFN_vkCreateMirSurfaceKHR vkCreateMirSurfaceKHR;
|
||||
extern PFN_vkGetPhysicalDeviceMirPresentationSupportKHR vkGetPhysicalDeviceMirPresentationSupportKHR;
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||
// VK_KHR_android_surface
|
||||
extern PFN_vkCreateAndroidSurfaceKHR vkCreateAndroidSurfaceKHR;
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
||||
// VK_KHR_win32_surface
|
||||
extern PFN_vkCreateWin32SurfaceKHR vkCreateWin32SurfaceKHR;
|
||||
extern PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR vkGetPhysicalDeviceWin32PresentationSupportKHR;
|
||||
#endif
|
||||
|
||||
#ifdef USE_DEBUG_EXTENTIONS
|
||||
#include <vulkan/vk_sdk_platform.h>
|
||||
// VK_EXT_debug_report
|
||||
extern PFN_vkCreateDebugReportCallbackEXT vkCreateDebugReportCallbackEXT;
|
||||
extern PFN_vkDestroyDebugReportCallbackEXT vkDestroyDebugReportCallbackEXT;
|
||||
extern PFN_vkDebugReportMessageEXT vkDebugReportMessageEXT;
|
||||
#endif
|
||||
|
||||
|
||||
#endif // VULKAN_WRAPPER_H
|
|
@ -1,3 +1,7 @@
|
|||
#if defined(__ANDROID__)
|
||||
#define VK_NO_PROTOTYPES 1
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
#endif
|
||||
#define VMA_IMPLEMENTATION
|
||||
#pragma clang diagnostic ignored "-Wnullability-completeness"
|
||||
#include "vk_mem_alloc.h"
|
||||
|
|
Loading…
Reference in New Issue