mirror of
https://github.com/bkaradzic/bgfx.cmake.git
synced 2026-02-17 21:12:35 +01:00
Compare commits
13 Commits
v1.127.874
...
v1.128.883
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9af6a48ce0 | ||
|
|
f531516396 | ||
|
|
94184872a8 | ||
|
|
4ceffda6de | ||
|
|
8defeece11 | ||
|
|
5b8c8b9057 | ||
|
|
de5f4544ef | ||
|
|
85b9f3cf5f | ||
|
|
79e4993ca5 | ||
|
|
0211a63b99 | ||
|
|
1156dcc725 | ||
|
|
c2b7416a58 | ||
|
|
c0ce1388cc |
@@ -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)
|
||||
@@ -47,6 +43,7 @@ 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)
|
||||
|
||||
35
README.md
35
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_HEADER]
|
||||
)
|
||||
```
|
||||
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_HEADER
|
||||
)
|
||||
bgfx_compile_shader_to_header(
|
||||
TYPE FRAGMENT
|
||||
SHADERS fs.sc
|
||||
VARYING_DEF ${CMAKE_SOURCE_DIR}/varying.def.sc
|
||||
OUTPUT_DIR ${CMAKE_BINARY_DIR}/include/generated/shaders
|
||||
AS_HEADER
|
||||
)
|
||||
|
||||
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: 00fa5ad179...cc789e83a6
2
bimg
2
bimg
Submodule bimg updated: 98a40e8533...0d1c78e779
2
bx
2
bx
Submodule bx updated: d171a0f264...2cebc558eb
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,10 @@ if(NOT ${BGFX_CONFIG_DEFAULT_MAX_ENCODERS} STREQUAL "")
|
||||
)
|
||||
endif()
|
||||
|
||||
if(BGFX_WITH_WAYLAND)
|
||||
target_compile_definitions(bgfx PRIVATE "WL_EGL_PLATFORM=1")
|
||||
endif()
|
||||
|
||||
set(BGFX_CONFIG_OPTIONS "")
|
||||
list(
|
||||
APPEND
|
||||
|
||||
@@ -551,22 +551,23 @@ if(TARGET bgfx::shaderc)
|
||||
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)
|
||||
@@ -584,6 +585,8 @@ if(TARGET bgfx::shaderc)
|
||||
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()
|
||||
|
||||
@@ -597,15 +600,24 @@ if(TARGET bgfx::shaderc)
|
||||
# Build output targets and their commands
|
||||
set(OUTPUTS "")
|
||||
set(COMMANDS "")
|
||||
set(MKDIR_COMMANDS "")
|
||||
foreach(PROFILE ${PROFILES})
|
||||
_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_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}
|
||||
@@ -613,16 +625,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_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