Skip to content

Commit 14e32a1

Browse files
committed
added basic shader, spirv, and texture
1 parent b46fb43 commit 14e32a1

File tree

18 files changed

+569
-63
lines changed

18 files changed

+569
-63
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,6 @@
118118
[submodule "externals/dawn/dawn"]
119119
path = externals/dawn/dawn
120120
url = https://dawn.googlesource.com/dawn
121+
[submodule "externals/glslang/glslang"]
122+
path = externals/glslang/glslang
123+
url = https://github.com/KhronosGroup/glslang.git

externals/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,16 @@ add_subdirectory(curl)
9898
add_subdirectory(cpr)
9999

100100
add_subdirectory(fastnoise)
101+
add_subdirectory(glfw)
102+
add_subdirectory(glm)
101103
add_subdirectory(plf)
102104
add_subdirectory(simplefilewatcher)
103105
add_subdirectory(stb)
104106
add_subdirectory(unordered_dense)
105107
add_subdirectory(wamr)
106108

107109
add_subdirectory(dawn)
108-
add_subdirectory(glfw)
109-
add_subdirectory(glm)
110+
add_subdirectory(glslang)
110111
add_subdirectory(openxr-sdk)
111112

112113
if(cage_use_steam_sockets)

externals/dawn/CMakeLists.txt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ message(STATUS "----------------------------------------------------------------
44

55
set(CMAKE_DISABLE_FIND_PACKAGE_Python3 OFF)
66

7+
# dawn
78
set(DAWN_ENABLE_INSTALL ON CACHE INTERNAL "Enable install step for Dawn libraries" FORCE)
89
set(DAWN_ENABLE_D3D11 OFF CACHE INTERNAL "Enable compilation of the D3D11 backend" FORCE)
910
set(DAWN_ENABLE_D3D12 OFF CACHE INTERNAL "Enable compilation of the D3D12 backend" FORCE)
@@ -16,14 +17,15 @@ set(DAWN_ENABLE_VULKAN ON CACHE INTERNAL "Enable compilation of the Vulkan backe
1617
set(DAWN_FORCE_SYSTEM_COMPONENT_LOAD ON CACHE INTERNAL "Allow system component fallback" FORCE)
1718
set(DAWN_USE_WAYLAND OFF CACHE INTERNAL "Enable support for Wayland surface" FORCE)
1819
set(DAWN_USE_X11 OFF CACHE INTERNAL "Enable support for X11 surface" FORCE)
19-
set(DAWN_USE_GLFW OFF CACHE INTERNAL "Enable compilation of the GLFW windowing utils" FORCE)
20+
set(DAWN_USE_GLFW ON CACHE INTERNAL "Enable compilation of the GLFW windowing utils" FORCE)
2021
set(DAWN_USE_WINDOWS_UI OFF CACHE INTERNAL "Enable support for Windows UI surface" FORCE)
2122
set(DAWN_BUILD_SAMPLES OFF CACHE INTERNAL "Enables building Dawn's samples" FORCE)
2223
set(DAWN_BUILD_TESTS OFF CACHE INTERNAL "Enables building Dawn's tests" FORCE)
2324
set(DAWN_BUILD_PROTOBUF ${cage_use_steam_sockets} CACHE INTERNAL "Build the protobuf dependencies" FORCE)
2425
set(DAWN_ENABLE_PIC ON CACHE INTERNAL "Build with Position-Independent-Code enabled" FORCE)
2526
set(DAWN_BUILD_MONOLITHIC_LIBRARY "STATIC" CACHE INTERNAL "Build monolithic library: SHARED, STATIC, or OFF." FORCE)
2627

28+
# tint
2729
set(TINT_BUILD_SPV_READER ON CACHE INTERNAL "Build the SPIR-V input reader" FORCE)
2830
set(TINT_BUILD_WGSL_READER ON CACHE INTERNAL "Build the WGSL input reader" FORCE)
2931
set(TINT_BUILD_GLSL_WRITER OFF CACHE INTERNAL "Build the GLSL output writer" FORCE)
@@ -32,22 +34,26 @@ set(TINT_BUILD_HLSL_WRITER OFF CACHE INTERNAL "Build the HLSL output writer" FOR
3234
set(TINT_BUILD_MSL_WRITER OFF CACHE INTERNAL "Build the MSL output writer" FORCE)
3335
set(TINT_BUILD_SPV_WRITER ON CACHE INTERNAL "Build the SPIR-V output writer" FORCE)
3436
set(TINT_BUILD_WGSL_WRITER ON CACHE INTERNAL "Build the WGSL output writer" FORCE)
35-
3637
set(TINT_ENABLE_INSTALL OFF CACHE INTERNAL "Enable install step for Tint libraries" FORCE)
3738
set(TINT_BUILD_CMD_TOOLS OFF CACHE INTERNAL "Build the Tint command line tools" FORCE)
3839
set(TINT_BUILD_IR_BINARY OFF CACHE INTERNAL "Build IR binary format support" FORCE)
3940
set(TINT_BUILD_TESTS OFF CACHE INTERNAL "Build tests" FORCE)
4041
set(TINT_ENABLE_IR_VALIDATION ON CACHE INTERNAL "Enable IR validation for backend codegen" FORCE)
4142

43+
# protobuf
4244
add_library(libprotobuf-mutator INTERFACE) # subvert unnecessary dependencies
4345

46+
# add the externals
4447
add_subdirectory(dawn)
4548

46-
add_library(webgpu::dawn ALIAS webgpu_dawn)
47-
48-
49+
# dawn
50+
add_library(cage_dawn INTERFACE)
51+
target_link_libraries(cage_dawn INTERFACE $<TARGET_LINKER_FILE:webgpu_dawn> $<TARGET_LINKER_FILE:webgpu_glfw>)
52+
target_include_directories(cage_dawn INTERFACE $<TARGET_PROPERTY:webgpu_dawn,INTERFACE_INCLUDE_DIRECTORIES> $<TARGET_PROPERTY:webgpu_glfw,INTERFACE_INCLUDE_DIRECTORIES>)
53+
add_dependencies(cage_dawn webgpu_dawn webgpu_glfw)
54+
add_library(cage::dawn ALIAS cage_dawn)
4955

50-
# make protobuf available to steam sockets
56+
# protobuf
5157
if(cage_use_steam_sockets)
5258
set(filename "${CAGE_EXTERNALS_MODULE_PATH}/FindProtobuf.cmake")
5359
file(WRITE ${filename} "\n")

externals/glslang/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
message(STATUS "----------------------------------------------------------------")
2+
message(STATUS "glslang")
3+
message(STATUS "----------------------------------------------------------------")
4+
5+
set(BUILD_EXTERNAL OFF CACHE INTERNAL "Build external dependencies in /External" FORCE)
6+
set(GLSLANG_TESTS OFF CACHE INTERNAL "Enable glslang testing" FORCE)
7+
set(ENABLE_GLSLANG_BINARIES OFF CACHE INTERNAL "Builds glslang" FORCE)
8+
set(ENABLE_HLSL OFF CACHE INTERNAL "Enables HLSL input support" FORCE)
9+
10+
add_subdirectory(glslang)
11+
12+
add_library(cage_glslang INTERFACE)
13+
target_link_libraries(cage_glslang INTERFACE $<TARGET_LINKER_FILE:glslang>)
14+
target_link_libraries(cage_glslang INTERFACE $<TARGET_LINKER_FILE:glslang-default-resource-limits>)
15+
target_include_directories(cage_glslang INTERFACE $<TARGET_PROPERTY:glslang,INTERFACE_INCLUDE_DIRECTORIES>)
16+
add_dependencies(cage_glslang glslang glslang-default-resource-limits)
17+
add_library(cage::glslang ALIAS cage_glslang)

externals/glslang/glslang

Submodule glslang added at 8e1494f

sources/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ cage_ide_sort_files(cage-core)
7373

7474
file(GLOB_RECURSE cage-engine-sources "libengine/*" "include/cage-engine/*")
7575
add_library(cage-engine SHARED ${cage-engine-sources})
76-
target_link_libraries(cage-engine PRIVATE cubeb glfw webgpu::dawn openxr_loader freetype harfbuzz SheenBidi)
77-
target_link_libraries(cage-engine PUBLIC cage-core)
76+
target_link_libraries(cage-engine PRIVATE cubeb glfw openxr_loader freetype harfbuzz SheenBidi cage::glslang)
77+
target_link_libraries(cage-engine PUBLIC cage-core cage::dawn)
7878
file(GLOB_RECURSE controller-bindings RELATIVE "${CMAKE_CURRENT_LIST_DIR}" "controller-bindings/*")
7979
set(index 0)
8080
foreach(cb IN ITEMS ${controller-bindings})

sources/include/cage-engine/graphicsDevice.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,34 @@
33

44
#include <cage-engine/core.h>
55

6+
namespace wgpu
7+
{
8+
class Device;
9+
class Queue;
10+
}
11+
612
namespace cage
713
{
14+
class Window;
15+
class Texture;
16+
817
class CAGE_ENGINE_API GraphicsDevice : private Immovable
918
{
1019
public:
20+
void processEvents();
21+
22+
Holder<Texture> nextFrame(Window *window);
23+
24+
wgpu::Device nativeDevice();
25+
wgpu::Queue nativeQueue();
26+
};
27+
28+
struct CAGE_CORE_API GraphicsDeviceCreateConfig
29+
{
30+
Window *compatibility = nullptr;
1131
};
1232

13-
CAGE_ENGINE_API Holder<GraphicsDevice> newGraphicsDevice();
33+
CAGE_ENGINE_API Holder<GraphicsDevice> newGraphicsDevice(const GraphicsDeviceCreateConfig &config);
1434
}
1535

1636
#endif
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef guard_shader_cxvbjhgr85
2+
#define guard_shader_cxvbjhgr85
3+
4+
#include <cage-engine/core.h>
5+
6+
namespace wgpu
7+
{
8+
class ShaderModule;
9+
}
10+
11+
namespace cage
12+
{
13+
class GraphicsDevice;
14+
class Spirv;
15+
16+
class CAGE_ENGINE_API Shader : private Immovable
17+
{
18+
public:
19+
wgpu::ShaderModule nativeVertex();
20+
wgpu::ShaderModule nativeFragment();
21+
};
22+
23+
CAGE_ENGINE_API Holder<Shader> newShader(GraphicsDevice *device, const Spirv *spirv);
24+
}
25+
26+
#endif
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef guard_spirv_erst54fij
2+
#define guard_spirv_erst54fij
3+
4+
#include <string>
5+
6+
#include <cage-engine/core.h>
7+
8+
namespace cage
9+
{
10+
struct GlslConfig
11+
{
12+
std::string vertex;
13+
std::string fragment;
14+
};
15+
16+
class CAGE_ENGINE_API Spirv : private Immovable
17+
{
18+
public:
19+
void importGlsl(const GlslConfig &glsl);
20+
void importBuffer(PointerRange<const char> buffer);
21+
22+
PointerRange<const uint32> exportSpirvVertex() const;
23+
PointerRange<const uint32> exportSpirvFragment() const;
24+
Holder<PointerRange<char>> exportBuffer() const;
25+
};
26+
27+
CAGE_ENGINE_API Holder<Spirv> newSpirv();
28+
}
29+
30+
#endif
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#ifndef guard_graphicsTexture_sdrfgh4d5g
2+
#define guard_graphicsTexture_sdrfgh4d5g
3+
4+
#include <cage-engine/core.h>
5+
6+
namespace wgpu
7+
{
8+
class Texture;
9+
class TextureView;
10+
}
11+
12+
namespace cage
13+
{
14+
class GraphicsDevice;
15+
16+
class CAGE_ENGINE_API Texture : private Immovable
17+
{
18+
protected:
19+
detail::StringBase<128> label;
20+
21+
public:
22+
void setLabel(const String &name);
23+
24+
Vec2i resolution() const;
25+
Vec3i resolution3() const;
26+
uint32 mipLevels() const; // 1 is just base level
27+
Vec2i mipResolution(uint32 mipmapLevel) const;
28+
Vec3i mipResolution3(uint32 mipmapLevel) const;
29+
30+
wgpu::Texture nativeTexture();
31+
wgpu::TextureView nativeView();
32+
};
33+
34+
struct CAGE_ENGINE_API TextureCreateConfig
35+
{
36+
Vec3i resolution = Vec3i(0, 0, 1);
37+
uint32 mipLevels = 1;
38+
bool volume3D = false; // true = 3D texture; false = layers, cube
39+
};
40+
41+
CAGE_ENGINE_API Holder<Texture> newGraphicsTexture(GraphicsDevice *device, const TextureCreateConfig &config);
42+
}
43+
44+
#endif

0 commit comments

Comments
 (0)