Compare commits

...

14 Commits

Author SHA1 Message Date
dependabot[bot]
4ceffda6de build(deps): bump the submodules group across 1 directory with 3 updates
Bumps the submodules group with 3 updates in the / directory: [bgfx](https://github.com/bkaradzic/bgfx), [bx](https://github.com/bkaradzic/bx) and [bimg](https://github.com/bkaradzic/bimg).


Updates `bgfx` from `af12904` to `409fbc5`
- [Commits](af12904d8c...409fbc5d14)

Updates `bx` from `e7ede51` to `3d53a4a`
- [Commits](e7ede513dc...3d53a4abaa)

Updates `bimg` from `2afa64c` to `aaf9125`
- [Commits](2afa64c14c...aaf9125234)

---
updated-dependencies:
- dependency-name: bgfx
  dependency-type: direct:production
  dependency-group: submodules
- dependency-name: bx
  dependency-type: direct:production
  dependency-group: submodules
- dependency-name: bimg
  dependency-type: direct:production
  dependency-group: submodules
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-08-03 10:36:09 -04:00
Sandy
8defeece11 Update compile shaders example 2024-07-20 19:46:27 -04:00
Sandy Carter
5b8c8b9057 Cleanup pssl comment 2024-07-20 19:34:50 -04:00
Sandy Carter
de5f4544ef Change the output path of generated shaders
The paths now for output shaders is the same of the shader file inside of
a directory for the profile.
2024-07-20 19:34:50 -04:00
Sandy Carter
85b9f3cf5f Make bgfx_compile_shaders more generic
Allow compiling as header or as binaries
2024-07-20 19:34:50 -04:00
Sandy
79e4993ca5 Update cmake/bgfx/bgfx.cmake
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2024-07-09 09:41:37 -04:00
Sandy Carter
0211a63b99 Add option to use wayland on linux, enabled by default 2024-07-09 09:41:37 -04:00
dependabot[bot]
1156dcc725 build(deps): bump the submodules group with 3 updates
Bumps the submodules group with 3 updates: [bgfx](https://github.com/bkaradzic/bgfx), [bx](https://github.com/bkaradzic/bx) and [bimg](https://github.com/bkaradzic/bimg).


Updates `bgfx` from `d1feabe` to `af12904`
- [Commits](d1feabe319...af12904d8c)

Updates `bx` from `24527ea` to `e7ede51`
- [Commits](24527eabfd...e7ede513dc)

Updates `bimg` from `59f188a` to `2afa64c`
- [Commits](59f188a6ad...2afa64c14c)

---
updated-dependencies:
- dependency-name: bgfx
  dependency-type: direct:production
  dependency-group: submodules
- dependency-name: bx
  dependency-type: direct:production
  dependency-group: submodules
- dependency-name: bimg
  dependency-type: direct:production
  dependency-group: submodules
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-07-09 09:24:15 -04:00
exdal
c2b7416a58 Merge pull request #233 from bwrsandman/preprocessor
bx: Add /Zc:preprocessor
2024-06-16 13:51:25 +03:00
Sandy Carter
c0ce1388cc bx: Add /Zc:preprocessor 2024-06-15 19:34:35 -04:00
dependabot[bot]
19cb98d40b build(deps): bump the submodules group with 3 updates
Bumps the submodules group with 3 updates: [bgfx](https://github.com/bkaradzic/bgfx), [bx](https://github.com/bkaradzic/bx) and [bimg](https://github.com/bkaradzic/bimg).


Updates `bgfx` from `57d8a08` to `00fa5ad`
- [Commits](57d8a0838b...00fa5ad179)

Updates `bx` from `34ba9c7` to `d171a0f`
- [Commits](34ba9c7a5c...d171a0f264)

Updates `bimg` from `e9fa0ce` to `98a40e8`
- [Commits](e9fa0ceff2...98a40e8533)

---
updated-dependencies:
- dependency-name: bgfx
  dependency-type: direct:production
  dependency-group: submodules
- dependency-name: bx
  dependency-type: direct:production
  dependency-group: submodules
- dependency-name: bimg
  dependency-type: direct:production
  dependency-group: submodules
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-06-01 14:36:24 -04:00
Sandy Carter
701d84c222 tools: Add an option to insert search paths for tools 2024-05-19 16:13:58 -04:00
Sandy Carter
5940bb7cf8 tools: Rely on CMAKE_PROGRAM_PATH for finding tools 2024-05-19 11:38:19 -04:00
Sandy Carter
2fcbf437f2 tools: for vcpkg hint, use host install path 2024-05-19 07:31:02 -04:00
9 changed files with 52 additions and 36 deletions

View File

@@ -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)

View File

@@ -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

Submodule bgfx updated: 57d8a0838b...409fbc5d14

2
bimg

Submodule bimg updated: e9fa0ceff2...aaf9125234

2
bx

Submodule bx updated: 34ba9c7a5c...3d53a4abaa

View File

@@ -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}")

View File

@@ -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

View File

@@ -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,21 @@ 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)
set(OUTPUT ${ARGS_OUTPUT_DIR}/${PROFILE_EXT}/${SHADER_FILE_BASENAME}.bin$<$<BOOL:ARGS_AS_HEADERS>:.h>)
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 +622,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}
)

View File

@@ -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)