mirror of
https://github.com/bkaradzic/bgfx.cmake.git
synced 2026-02-17 21:12:35 +01:00
Compare commits
33 Commits
v1.121.853
...
v1.128.883
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b12eb2882a | ||
|
|
1139067c7d | ||
|
|
b135fa3d77 | ||
|
|
9af6a48ce0 | ||
|
|
f531516396 | ||
|
|
94184872a8 | ||
|
|
4ceffda6de | ||
|
|
8defeece11 | ||
|
|
5b8c8b9057 | ||
|
|
de5f4544ef | ||
|
|
85b9f3cf5f | ||
|
|
79e4993ca5 | ||
|
|
0211a63b99 | ||
|
|
1156dcc725 | ||
|
|
c2b7416a58 | ||
|
|
c0ce1388cc | ||
|
|
19cb98d40b | ||
|
|
701d84c222 | ||
|
|
5940bb7cf8 | ||
|
|
2fcbf437f2 | ||
|
|
d7f59648a8 | ||
|
|
e8db646d2c | ||
|
|
e12aba94c7 | ||
|
|
8dcc50e992 | ||
|
|
011e8efe23 | ||
|
|
871eed8f8a | ||
|
|
2f0e950b8f | ||
|
|
26af75d78b | ||
|
|
1f65bfcb44 | ||
|
|
875927a712 | ||
|
|
f46699bb4a | ||
|
|
6a8aba37ff | ||
|
|
38de01cd8a |
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
@@ -23,7 +23,7 @@ jobs:
|
||||
- name: Install Linux dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt install -y libgl1-mesa-dev
|
||||
sudo apt install -y libgl1-mesa-dev libwayland-dev libwayland-egl-backend-dev
|
||||
- uses: lukka/get-cmake@latest
|
||||
with:
|
||||
cmakeVersion: ${{ env.CMAKE_VERSION }}
|
||||
@@ -63,7 +63,7 @@ jobs:
|
||||
- name: Install Linux dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt install -y libgl1-mesa-dev
|
||||
sudo apt install -y libgl1-mesa-dev libwayland-dev libwayland-egl-backend-dev
|
||||
if: matrix.os == 'ubuntu-latest'
|
||||
|
||||
# Setup the build machine with the most recent versions of CMake and Ninja. Both are cached if not already: on subsequent runs both will be quickly restored from GitHub cache service.
|
||||
@@ -100,7 +100,7 @@ jobs:
|
||||
- name: Install Linux dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt install -y libgl1-mesa-dev
|
||||
sudo apt install -y libgl1-mesa-dev libwayland-dev libwayland-egl-backend-dev
|
||||
if: matrix.os == 'ubuntu-latest'
|
||||
|
||||
# Setup the build machine with the most recent versions of CMake and Ninja. Both are cached if not already: on subsequent runs both will be quickly restored from GitHub cache service.
|
||||
|
||||
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -57,7 +57,7 @@ jobs:
|
||||
- name: Install Linux dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt install -y libgl1-mesa-dev
|
||||
sudo apt install -y libgl1-mesa-dev libwayland-dev libwayland-egl-backend-dev
|
||||
if: matrix.os == 'ubuntu-latest'
|
||||
# Setup the build machine with the most recent versions of CMake and Ninja. Both are cached if not already: on subsequent runs both will be quickly restored from GitHub cache service.
|
||||
- uses: lukka/get-cmake@latest
|
||||
|
||||
@@ -13,7 +13,7 @@ project(bgfx)
|
||||
cmake_policy(SET CMP0054 NEW)
|
||||
|
||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
@@ -22,10 +22,6 @@ if(APPLE AND NOT XCODE)
|
||||
set(CMAKE_CXX_FLAGS "-ObjC++")
|
||||
endif()
|
||||
|
||||
if(MSVC AND (MSVC_VERSION GREATER_EQUAL 1914))
|
||||
add_compile_options("/Zc:__cplusplus")
|
||||
endif()
|
||||
|
||||
include(CMakeDependentOption)
|
||||
|
||||
option(BX_AMALGAMATED "Amalgamated bx build for faster compilation" OFF)
|
||||
@@ -38,11 +34,16 @@ cmake_dependent_option(BGFX_BUILD_TOOLS_GEOMETRY "Build bgfx geometry tools." ON
|
||||
cmake_dependent_option(BGFX_BUILD_TOOLS_TEXTURE "Build bgfx texture tools." ON BGFX_BUILD_TOOLS OFF)
|
||||
set(BGFX_TOOLS_PREFIX "" CACHE STRING "Prefix name to add to name of tools (to avoid clashes)")
|
||||
option(BGFX_BUILD_EXAMPLES "Build bgfx examples." ON)
|
||||
cmake_dependent_option(
|
||||
BGFX_BUILD_EXAMPLE_COMMON "Build bgfx example-common project." OFF "NOT BGFX_BUILD_EXAMPLES;NOT BGFX_BUILD_TOOLS"
|
||||
ON
|
||||
)
|
||||
option(BGFX_BUILD_TESTS "Build bgfx tests." OFF)
|
||||
option(BGFX_INSTALL "Create installation target." ON)
|
||||
cmake_dependent_option(
|
||||
BGFX_INSTALL_EXAMPLES "Install examples and their runtimes." OFF "BGFX_INSTALL;BGFX_BUILD_EXAMPLES" OFF
|
||||
)
|
||||
cmake_dependent_option(BGFX_WITH_WAYLAND "Use Wayland backend." ON "CMAKE_SYSTEM_NAME STREQUAL Linux" OFF)
|
||||
option(BGFX_CUSTOM_TARGETS "Include convenience custom targets." ON)
|
||||
option(BGFX_CONFIG_MULTITHREADED "Build bgfx with multithreaded configuration" ON)
|
||||
option(BGFX_CONFIG_RENDERER_WEBGPU "Enable the webgpu renderer" OFF)
|
||||
|
||||
37
README.md
37
README.md
@@ -86,35 +86,38 @@ bgfx_compile_texture(
|
||||
)
|
||||
```
|
||||
|
||||
### `bgfx_compile_shader_to_header`
|
||||
### `bgfx_compile_shaders`
|
||||
Add a build rule for a `*.sc` shader to the generated build system using shaderc.
|
||||
```cmake
|
||||
bgfx_compile_shader_to_header(
|
||||
bgfx_compile_shaders(
|
||||
TYPE VERTEX|FRAGMENT|COMPUTE
|
||||
SHADERS filenames
|
||||
VARYING_DEF filename
|
||||
OUTPUT_DIR directory
|
||||
[AS_HEADERS]
|
||||
)
|
||||
```
|
||||
This defines a shaderc command to generate headers for a number of `TYPE` shaders with `SHADERS` files and `VARYING_DEF` file in the `OUTPUT_DIR` directory. There will be one generated shader for each supported rendering API on this current platform according to the `BGFX_EMBEDDED_SHADER` macro in `bgfx/embedded_shader.h`.
|
||||
This defines a shaderc command to generate binaries or headers for a number of `TYPE` shaders with `SHADERS` files and `VARYING_DEF` file in the `OUTPUT_DIR` directory. There will be one generated shader for each supported rendering API on this current platform according to the `BGFX_EMBEDDED_SHADER` macro in `bgfx/embedded_shader.h` for headers and in the directory expected by `load_shader` in `bgfx_utils.h`.
|
||||
|
||||
The generated headers will have names in the format of `${SHADERS}.${RENDERING_API}.bin.h` where `RENDERING_API` can be `glsl`, `essl`, `spv`, `dx9`, `dx11` and `mtl` depending on the availability of the platform.
|
||||
The generated headers will have names in the format of `${RENDERING_API}/${SHADERS}.bin[.h]` where `RENDERING_API` can be `glsl`, `essl`, `spv`, `dx11` and `mtl` depending on the availability of the platform.
|
||||
|
||||
Adding these `SHADERS` as source files to a target will run `shaderc` at build time and they will rebuild if either the contents of the `SHADERS` or the `VARYING_DEF` change.
|
||||
|
||||
#### Examples: Generating shaders as headers
|
||||
```cmake
|
||||
bgfx_compile_shader_to_header(
|
||||
bgfx_compile_shaders(
|
||||
TYPE VERTEX
|
||||
SHADERS vs.sc
|
||||
VARYING_DEF varying.def.sc
|
||||
OUTPUT_DIR ${CMAKE_BINARY_DIR}/include/generated/shaders
|
||||
AS_HEADERS
|
||||
)
|
||||
bgfx_compile_shader_to_header(
|
||||
bgfx_compile_shaders(
|
||||
TYPE FRAGMENT
|
||||
SHADERS fs.sc
|
||||
VARYING_DEF ${CMAKE_SOURCE_DIR}/varying.def.sc
|
||||
OUTPUT_DIR ${CMAKE_BINARY_DIR}/include/generated/shaders
|
||||
AS_HEADERS
|
||||
)
|
||||
|
||||
add_library(myLib main.cpp vs.sc fs.sc)
|
||||
@@ -123,21 +126,19 @@ target_include_directories(myLib ${CMAKE_BINARY_DIR}/include/generated/shaders)
|
||||
|
||||
```cpp
|
||||
// main.cpp
|
||||
#include <vs.sc.glsl.bin.h>
|
||||
#include <vs.sc.essl.bin.h>
|
||||
#include <vs.sc.spv.bin.h>
|
||||
#include <fs.sc.glsl.bin.h>
|
||||
#include <fs.sc.essl.bin.h>
|
||||
#include <fs.sc.spv.bin.h>
|
||||
#include <glsl/vs.sc.bin.h>
|
||||
#include <essl/vs.sc.bin.h>
|
||||
#include <spv/vs.sc.bin.h>
|
||||
#include <glsl/fs.sc.bin.h>
|
||||
#include <essl/fs.sc.bin.h>
|
||||
#include <spv/fs.sc.bin.h>
|
||||
#if defined(_WIN32)
|
||||
#include <vs.sc.dx9.bin.h>
|
||||
#include <vs.sc.dx11.bin.h>
|
||||
#include <fs.sc.dx9.bin.h>
|
||||
#include <fs.sc.dx11.bin.h>
|
||||
#include <dx11/vs.sc.bin.h>
|
||||
#include <dx11/fs.sc.bin.h>
|
||||
#endif // defined(_WIN32)
|
||||
#if __APPLE__
|
||||
#include <vs.sc.mtl.bin.h>
|
||||
#include <fs.sc.mtl.bin.h>
|
||||
#include <mtl/vs.sc.bin.h>
|
||||
#include <mtl/fs.sc.bin.h>
|
||||
#endif // __APPLE__
|
||||
|
||||
const bgfx::EmbeddedShader k_vs = BGFX_EMBEDDED_SHADER(vs);
|
||||
|
||||
2
bgfx
2
bgfx
Submodule bgfx updated: e2c5b1d3e1...cc789e83a6
2
bimg
2
bimg
Submodule bimg updated: ec02df824a...0d1c78e779
2
bx
2
bx
Submodule bx updated: 96748d9a58...2cebc558eb
@@ -14,10 +14,7 @@ macro(_bgfx_crosscompile_use_host_tool TOOL_NAME)
|
||||
find_program(
|
||||
${TOOL_NAME}_EXECUTABLE
|
||||
NAMES bgfx-${TOOL_NAME} ${TOOL_NAME}
|
||||
PATHS /usr/bin #
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/packages/bgfx_x64-linux/tools/bgfx
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/packages/bgfx_x64-windows/tools/bgfx
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/packages/bgfx_x64-osx/tools/bgfx
|
||||
PATHS @BGFX_ADDITIONAL_TOOL_PATHS@ /usr/bin
|
||||
)
|
||||
add_executable(bgfx::${TOOL_NAME} IMPORTED)
|
||||
set_target_properties(bgfx::${TOOL_NAME} PROPERTIES IMPORTED_LOCATION "${${TOOL_NAME}_EXECUTABLE}")
|
||||
|
||||
2
cmake/bgfx/3rdparty/spirv-opt.cmake
vendored
2
cmake/bgfx/3rdparty/spirv-opt.cmake
vendored
@@ -74,6 +74,8 @@ file(
|
||||
${SPIRV_TOOLS}/source/text.h
|
||||
${SPIRV_TOOLS}/source/text_handler.cpp
|
||||
${SPIRV_TOOLS}/source/text_handler.h
|
||||
${SPIRV_TOOLS}/source/to_string.cpp
|
||||
${SPIRV_TOOLS}/source/to_string.h
|
||||
${SPIRV_TOOLS}/source/util/bit_vector.cpp
|
||||
${SPIRV_TOOLS}/source/util/bit_vector.h
|
||||
${SPIRV_TOOLS}/source/util/bitutils.h
|
||||
|
||||
@@ -85,6 +85,11 @@ if(NOT ${BGFX_CONFIG_DEFAULT_MAX_ENCODERS} STREQUAL "")
|
||||
)
|
||||
endif()
|
||||
|
||||
if(BGFX_WITH_WAYLAND)
|
||||
target_compile_definitions(bgfx PRIVATE "WL_EGL_PLATFORM=1")
|
||||
target_link_libraries(bgfx PRIVATE wayland-egl)
|
||||
endif()
|
||||
|
||||
set(BGFX_CONFIG_OPTIONS "")
|
||||
list(
|
||||
APPEND
|
||||
|
||||
@@ -33,19 +33,6 @@ function(add_bgfx_shader FILE FOLDER)
|
||||
set(OUTPUTS_PRETTY "")
|
||||
|
||||
if(WIN32)
|
||||
# dx9
|
||||
if(NOT "${TYPE}" STREQUAL "COMPUTE")
|
||||
set(DX9_OUTPUT ${BGFX_DIR}/examples/runtime/shaders/dx9/${FILENAME}.bin)
|
||||
_bgfx_shaderc_parse(
|
||||
DX9 ${COMMON} WINDOWS
|
||||
PROFILE s_3_0
|
||||
O 3
|
||||
OUTPUT ${DX9_OUTPUT}
|
||||
)
|
||||
list(APPEND OUTPUTS "DX9")
|
||||
set(OUTPUTS_PRETTY "${OUTPUTS_PRETTY}DX9, ")
|
||||
endif()
|
||||
|
||||
# dx11
|
||||
set(DX11_OUTPUT ${BGFX_DIR}/examples/runtime/shaders/dx11/${FILENAME}.bin)
|
||||
if(NOT "${TYPE}" STREQUAL "COMPUTE")
|
||||
@@ -78,7 +65,7 @@ function(add_bgfx_shader FILE FOLDER)
|
||||
# essl
|
||||
if(NOT "${TYPE}" STREQUAL "COMPUTE")
|
||||
set(ESSL_OUTPUT ${BGFX_DIR}/examples/runtime/shaders/essl/${FILENAME}.bin)
|
||||
_bgfx_shaderc_parse(ESSL ${COMMON} ANDROID OUTPUT ${ESSL_OUTPUT})
|
||||
_bgfx_shaderc_parse(ESSL ${COMMON} ANDROID PROFILE 100_es OUTPUT ${ESSL_OUTPUT})
|
||||
list(APPEND OUTPUTS "ESSL")
|
||||
set(OUTPUTS_PRETTY "${OUTPUTS_PRETTY}ESSL, ")
|
||||
endif()
|
||||
@@ -149,14 +136,19 @@ function(add_example ARG_NAME)
|
||||
target_link_libraries(
|
||||
example-${ARG_NAME} PUBLIC bgfx bx bimg bimg_decode ${DEAR_IMGUI_LIBRARIES} ${MESHOPTIMIZER_LIBRARIES}
|
||||
)
|
||||
|
||||
if(BGFX_WITH_WAYLAND)
|
||||
target_compile_definitions(example-${ARG_NAME} PUBLIC ENTRY_CONFIG_USE_WAYLAND=1)
|
||||
endif()
|
||||
|
||||
if(BGFX_WITH_GLFW)
|
||||
find_package(glfw3 REQUIRED)
|
||||
target_link_libraries(example-${ARG_NAME} PUBLIC glfw)
|
||||
target_compile_definitions(example-${ARG_NAME} PUBLIC ENTRY_CONFIG_USE_GLFW)
|
||||
target_compile_definitions(example-${ARG_NAME} PUBLIC ENTRY_CONFIG_USE_GLFW=1)
|
||||
elseif(BGFX_WITH_SDL)
|
||||
find_package(SDL2 REQUIRED)
|
||||
target_link_libraries(example-${ARG_NAME} PUBLIC ${SDL2_LIBRARIES})
|
||||
target_compile_definitions(example-${ARG_NAME} PUBLIC ENTRY_CONFIG_USE_SDL)
|
||||
target_compile_definitions(example-${ARG_NAME} PUBLIC ENTRY_CONFIG_USE_SDL=1)
|
||||
elseif(UNIX AND NOT APPLE AND NOT ANDROID)
|
||||
target_link_libraries(example-${ARG_NAME} PUBLIC X11)
|
||||
endif()
|
||||
@@ -276,17 +268,19 @@ if(BGFX_CUSTOM_TARGETS)
|
||||
endif()
|
||||
|
||||
# Add common library for examples
|
||||
add_example(
|
||||
common
|
||||
COMMON
|
||||
DIRECTORIES
|
||||
${BGFX_DIR}/examples/common/debugdraw
|
||||
${BGFX_DIR}/examples/common/entry
|
||||
${BGFX_DIR}/examples/common/font
|
||||
${BGFX_DIR}/examples/common/imgui
|
||||
${BGFX_DIR}/examples/common/nanovg
|
||||
${BGFX_DIR}/examples/common/ps
|
||||
)
|
||||
if(BGFX_BUILD_EXAMPLE_COMMON)
|
||||
add_example(
|
||||
common
|
||||
COMMON
|
||||
DIRECTORIES
|
||||
${BGFX_DIR}/examples/common/debugdraw
|
||||
${BGFX_DIR}/examples/common/entry
|
||||
${BGFX_DIR}/examples/common/font
|
||||
${BGFX_DIR}/examples/common/imgui
|
||||
${BGFX_DIR}/examples/common/nanovg
|
||||
${BGFX_DIR}/examples/common/ps
|
||||
)
|
||||
endif()
|
||||
|
||||
# Only add examples if set, otherwise we still need exmaples common for tools
|
||||
if(BGFX_BUILD_EXAMPLES)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "@BGFX_DIR@/src/shader.cpp"
|
||||
#include "@BGFX_DIR@/src/shader_dx9bc.cpp"
|
||||
#include "@BGFX_DIR@/src/shader_dxbc.cpp"
|
||||
#include "@BGFX_DIR@/src/shader_spirv.cpp"
|
||||
#include "@BGFX_DIR@/src/shader_spirv.cpp"
|
||||
|
||||
@@ -215,7 +215,7 @@ if(TARGET bgfx::texturec)
|
||||
add_custom_command(
|
||||
OUTPUT ${ARG_OUTPUT} #
|
||||
COMMAND bgfx::texturec ${CLI} #
|
||||
MAIN_DEPENDENCY ${ARG_INPUT} #
|
||||
MAIN_DEPENDENCY ${ARG_FILE} #
|
||||
)
|
||||
endfunction()
|
||||
endif()
|
||||
@@ -279,12 +279,12 @@ if(TARGET bgfx::geometryc)
|
||||
|
||||
# --packnormal
|
||||
if(ARG_PACKNORMAL)
|
||||
list(APPEND CLI "--packnormal ${ARG_PACKNORMAL}")
|
||||
list(APPEND CLI "--packnormal" "${ARG_PACKNORMAL}")
|
||||
endif()
|
||||
|
||||
# --packuv
|
||||
if(ARG_PACKUV)
|
||||
list(APPEND CLI "--packuv" ${ARG_PACKUV})
|
||||
list(APPEND CLI "--packuv" "${ARG_PACKUV}")
|
||||
endif()
|
||||
|
||||
# --tangent
|
||||
@@ -352,7 +352,7 @@ if(TARGET bgfx::geometryc)
|
||||
add_custom_command(
|
||||
OUTPUT ${ARG_OUTPUT} #
|
||||
COMMAND bgfx::geometryc ${CLI} #
|
||||
MAIN_DEPENDENCY ${ARG_INPUT} #
|
||||
MAIN_DEPENDENCY ${ARG_FILE} #
|
||||
)
|
||||
endfunction()
|
||||
endif()
|
||||
@@ -365,7 +365,7 @@ if(TARGET bgfx::shaderc)
|
||||
# OUTPUT filename
|
||||
# FRAGMENT|VERTEX|COMPUTE
|
||||
# ANDROID|ASM_JS|IOS|LINUX|NACL|OSX|WINDOWS
|
||||
# [PROFILE profile]
|
||||
# PROFILE profile
|
||||
# [O 0|1|2|3]
|
||||
# [VARYINGDEF filename]
|
||||
# [BIN2C filename]
|
||||
@@ -392,6 +392,8 @@ if(TARGET bgfx::shaderc)
|
||||
# -f
|
||||
if(ARG_FILE)
|
||||
list(APPEND CLI "-f" "${ARG_FILE}")
|
||||
else()
|
||||
message(SEND_ERROR "Call to _bgfx_shaderc_parse() must have an input file path specified.")
|
||||
endif()
|
||||
|
||||
# -i
|
||||
@@ -405,6 +407,8 @@ if(TARGET bgfx::shaderc)
|
||||
# -o
|
||||
if(ARG_OUTPUT)
|
||||
list(APPEND CLI "-o" "${ARG_OUTPUT}")
|
||||
else()
|
||||
message(SEND_ERROR "Call to _bgfx_shaderc_parse() must have an output file path specified.")
|
||||
endif()
|
||||
|
||||
# --bin2c
|
||||
@@ -518,6 +522,8 @@ if(TARGET bgfx::shaderc)
|
||||
# --profile
|
||||
if(ARG_PROFILE)
|
||||
list(APPEND CLI "--profile" "${ARG_PROFILE}")
|
||||
else()
|
||||
message(SEND_ERROR "Call to _bgfx_shaderc_parse() must have a shader profile.")
|
||||
endif()
|
||||
|
||||
# -O
|
||||
@@ -533,34 +539,43 @@ if(TARGET bgfx::shaderc)
|
||||
set(${ARG_OUT} ${CLI} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# extensions consistent with those listed under bgfx/runtime/shaders
|
||||
function(_bgfx_get_profile_path_ext PROFILE PROFILE_PATH_EXT)
|
||||
string(REPLACE 300_es essl PROFILE ${PROFILE})
|
||||
string(REPLACE 120 glsl PROFILE ${PROFILE})
|
||||
string(REPLACE s_4_0 dx10 PROFILE ${PROFILE})
|
||||
string(REPLACE s_5_0 dx11 PROFILE ${PROFILE})
|
||||
set(${PROFILE_PATH_EXT} ${PROFILE} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# extensions consistent with embedded_shader.h
|
||||
function(_bgfx_get_profile_ext PROFILE PROFILE_EXT)
|
||||
string(REPLACE 300_es essl PROFILE ${PROFILE})
|
||||
string(REPLACE 120 glsl PROFILE ${PROFILE})
|
||||
string(REPLACE spirv spv PROFILE ${PROFILE})
|
||||
string(REPLACE metal mtl PROFILE ${PROFILE})
|
||||
string(REPLACE s_3_0 dx9 PROFILE ${PROFILE})
|
||||
string(REPLACE s_4_0 dx10 PROFILE ${PROFILE})
|
||||
string(REPLACE s_5_0 dx11 PROFILE ${PROFILE})
|
||||
|
||||
set(${PROFILE_EXT} ${PROFILE} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# bgfx_compile_shader_to_header(
|
||||
# bgfx_compile_shaders(
|
||||
# TYPE VERTEX|FRAGMENT|COMPUTE
|
||||
# SHADERS filenames
|
||||
# VARYING_DEF filename
|
||||
# OUTPUT_DIR directory
|
||||
# OUT_FILES_VAR variable name
|
||||
# INCLUDE_DIRS directories
|
||||
# [AS_HEADERS]
|
||||
# )
|
||||
#
|
||||
function(bgfx_compile_shader_to_header)
|
||||
set(options "")
|
||||
function(bgfx_compile_shaders)
|
||||
set(options AS_HEADERS)
|
||||
set(oneValueArgs TYPE VARYING_DEF OUTPUT_DIR OUT_FILES_VAR)
|
||||
set(multiValueArgs SHADERS INCLUDE_DIRS)
|
||||
cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}")
|
||||
|
||||
set(PROFILES 120 300_es spirv) # pssl
|
||||
set(PROFILES 120 300_es spirv)
|
||||
if(UNIX AND NOT APPLE)
|
||||
set(PLATFORM LINUX)
|
||||
elseif(EMSCRIPTEN)
|
||||
@@ -575,17 +590,11 @@ if(TARGET bgfx::shaderc)
|
||||
OR CYGWIN
|
||||
)
|
||||
set(PLATFORM WINDOWS)
|
||||
if(ARGS_TYPE STREQUAL "VERTEX" OR ARGS_TYPE STREQUAL "FRAGMENT")
|
||||
list(APPEND PROFILES s_3_0)
|
||||
list(APPEND PROFILES s_4_0)
|
||||
list(APPEND PROFILES s_5_0)
|
||||
elseif(ARGS_TYPE STREQUAL "COMPUTE")
|
||||
list(APPEND PROFILES s_4_0)
|
||||
list(APPEND PROFILES s_5_0)
|
||||
else()
|
||||
message(error "shaderc: Unsupported type")
|
||||
endif()
|
||||
list(APPEND PROFILES s_4_0)
|
||||
list(APPEND PROFILES s_5_0)
|
||||
else()
|
||||
# pssl for Agc and Gnm renderers
|
||||
# nvn for Nvn renderer
|
||||
message(error "shaderc: Unsupported platform")
|
||||
endif()
|
||||
|
||||
@@ -599,15 +608,25 @@ if(TARGET bgfx::shaderc)
|
||||
# Build output targets and their commands
|
||||
set(OUTPUTS "")
|
||||
set(COMMANDS "")
|
||||
set(MKDIR_COMMANDS "")
|
||||
foreach(PROFILE ${PROFILES})
|
||||
_bgfx_get_profile_path_ext(${PROFILE} PROFILE_PATH_EXT)
|
||||
_bgfx_get_profile_ext(${PROFILE} PROFILE_EXT)
|
||||
set(OUTPUT ${ARGS_OUTPUT_DIR}/${SHADER_FILE_BASENAME}.${PROFILE_EXT}.bin.h)
|
||||
if(ARGS_AS_HEADERS)
|
||||
set(HEADER_PREFIX .h)
|
||||
endif()
|
||||
set(OUTPUT ${ARGS_OUTPUT_DIR}/${PROFILE_PATH_EXT}/${SHADER_FILE_BASENAME}.bin${HEADER_PREFIX})
|
||||
set(PLATFORM_I ${PLATFORM})
|
||||
if(PROFILE STREQUAL "spirv")
|
||||
set(PLATFORM_I LINUX)
|
||||
endif()
|
||||
set(BIN2C_PART "")
|
||||
if(ARGS_AS_HEADERS)
|
||||
set(BIN2C_PART BIN2C ${SHADER_FILE_NAME_WE}_${PROFILE_EXT})
|
||||
endif()
|
||||
_bgfx_shaderc_parse(
|
||||
CLI #
|
||||
${BIN2C_PART} #
|
||||
${ARGS_TYPE} ${PLATFORM_I} WERROR "$<$<CONFIG:debug>:DEBUG>$<$<CONFIG:relwithdebinfo>:DEBUG>"
|
||||
FILE ${SHADER_FILE_ABSOLUTE}
|
||||
OUTPUT ${OUTPUT}
|
||||
@@ -615,16 +634,24 @@ if(TARGET bgfx::shaderc)
|
||||
O "$<$<CONFIG:debug>:0>$<$<CONFIG:release>:3>$<$<CONFIG:relwithdebinfo>:3>$<$<CONFIG:minsizerel>:3>"
|
||||
VARYINGDEF ${ARGS_VARYING_DEF}
|
||||
INCLUDES ${BGFX_SHADER_INCLUDE_PATH} ${ARGS_INCLUDE_DIRS}
|
||||
BIN2C BIN2C ${SHADER_FILE_NAME_WE}_${PROFILE_EXT}
|
||||
)
|
||||
list(APPEND OUTPUTS ${OUTPUT})
|
||||
list(APPEND ALL_OUTPUTS ${OUTPUT})
|
||||
list(
|
||||
APPEND
|
||||
MKDIR_COMMANDS
|
||||
COMMAND
|
||||
${CMAKE_COMMAND}
|
||||
-E
|
||||
make_directory
|
||||
${ARGS_OUTPUT_DIR}/${PROFILE_PATH_EXT}
|
||||
)
|
||||
list(APPEND COMMANDS COMMAND bgfx::shaderc ${CLI})
|
||||
endforeach()
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${OUTPUTS}
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${ARGS_OUTPUT_DIR} ${COMMANDS}
|
||||
COMMAND ${MKDIR_COMMANDS} ${COMMANDS}
|
||||
MAIN_DEPENDENCY ${SHADER_FILE_ABSOLUTE}
|
||||
DEPENDS ${ARGS_VARYING_DEF}
|
||||
)
|
||||
|
||||
@@ -92,7 +92,7 @@ target_compile_definitions(bx PUBLIC "__STDC_CONSTANT_MACROS")
|
||||
|
||||
target_compile_features(bx PUBLIC cxx_std_14)
|
||||
# (note: see bx\scripts\toolchain.lua for equivalent compiler flag)
|
||||
target_compile_options(bx PUBLIC $<$<CXX_COMPILER_ID:MSVC>:/Zc:__cplusplus>)
|
||||
target_compile_options(bx PUBLIC $<$<CXX_COMPILER_ID:MSVC>:/Zc:__cplusplus /Zc:preprocessor>)
|
||||
|
||||
# Link against psapi on Windows
|
||||
if(WIN32)
|
||||
|
||||
Reference in New Issue
Block a user