From 4695edc3b7005e7f6ce31b001ac763cf1f950d88 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 3 Dec 2020 12:54:44 -0800 Subject: [PATCH] merged with atmosphere 0.16.0-p2 --- Makefile | 123 +- docs/building.md | 28 +- docs/cheat_sheet.txt | 18 + libraries/.gitrepo | 4 +- .../source/amsmitm_initialization.cpp | 20 +- .../source/amsmitm_module_management.cpp | 4 +- .../source/set_mitm/setsys_mitm_service.cpp | 52 +- .../loader/source/ldr_development_manager.cpp | 6 +- stratosphere/loader/source/ldr_meta.cpp | 2 +- troposphere/daybreak/nanovg/include/deko3d.h | 1353 +++++++++++++++++ .../daybreak/nanovg/include/deko3d.hpp | 1108 ++++++++++++++ .../daybreak/nanovg/include/nanovg/deko3d.h | 1353 +++++++++++++++++ .../daybreak/nanovg/include/nanovg/deko3d.hpp | 1108 ++++++++++++++ troposphere/daybreak/source/ui.cpp | 15 +- 14 files changed, 5090 insertions(+), 104 deletions(-) create mode 100644 docs/cheat_sheet.txt create mode 100644 troposphere/daybreak/nanovg/include/deko3d.h create mode 100644 troposphere/daybreak/nanovg/include/deko3d.hpp create mode 100644 troposphere/daybreak/nanovg/include/nanovg/deko3d.h create mode 100644 troposphere/daybreak/nanovg/include/nanovg/deko3d.hpp diff --git a/Makefile b/Makefile index bf8a9d9c3..04f9609e4 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ clean: $(MAKE) -C fusee clean rm -rf out -dist-no-debug: all +dist: all $(eval MAJORVER = $(shell grep 'define ATMOSPHERE_RELEASE_VERSION_MAJOR\b' libraries/libvapours/include/vapours/ams/ams_api_version.h \ | tr -s [:blank:] \ | cut -d' ' -f3)) @@ -49,67 +49,70 @@ dist-no-debug: all $(eval MICROVER = $(shell grep 'define ATMOSPHERE_RELEASE_VERSION_MICRO\b' libraries/libvapours/include/vapours/ams/ams_api_version.h \ | tr -s [:blank:] \ | cut -d' ' -f3)) - $(eval AMSVER = $(MAJORVER).$(MINORVER).$(MICROVER)-$(AMSREV)) + $(eval AMSVER = out) + + rm -rf ../atmosphere-$(AMSVER).zip rm -rf atmosphere-$(AMSVER) rm -rf out - mkdir atmosphere-$(AMSVER) - mkdir atmosphere-$(AMSVER)/atmosphere - mkdir atmosphere-$(AMSVER)/sept - mkdir atmosphere-$(AMSVER)/switch - mkdir -p atmosphere-$(AMSVER)/atmosphere/contents/0100000000000008 - mkdir -p atmosphere-$(AMSVER)/atmosphere/contents/010000000000000D - mkdir -p atmosphere-$(AMSVER)/atmosphere/contents/010000000000002B - mkdir -p atmosphere-$(AMSVER)/atmosphere/contents/0100000000000032 - mkdir -p atmosphere-$(AMSVER)/atmosphere/contents/0100000000000034 - mkdir -p atmosphere-$(AMSVER)/atmosphere/contents/0100000000000036 - mkdir -p atmosphere-$(AMSVER)/atmosphere/contents/0100000000000037 - mkdir -p atmosphere-$(AMSVER)/atmosphere/contents/010000000000003C - mkdir -p atmosphere-$(AMSVER)/atmosphere/contents/0100000000000042 - mkdir -p atmosphere-$(AMSVER)/atmosphere/fatal_errors - mkdir -p atmosphere-$(AMSVER)/atmosphere/config_templates - mkdir -p atmosphere-$(AMSVER)/atmosphere/config - cp fusee/fusee-primary/fusee-primary.bin atmosphere-$(AMSVER)/atmosphere/reboot_payload.bin - cp fusee/fusee-mtc/fusee-mtc.bin atmosphere-$(AMSVER)/atmosphere/fusee-mtc.bin - cp fusee/fusee-secondary/fusee-secondary-experimental.bin atmosphere-$(AMSVER)/atmosphere/fusee-secondary.bin - cp fusee/fusee-secondary/fusee-secondary-experimental.bin atmosphere-$(AMSVER)/sept/payload.bin - cp sept/sept-primary/sept-primary.bin atmosphere-$(AMSVER)/sept/sept-primary.bin - cp sept/sept-secondary/sept-secondary.bin atmosphere-$(AMSVER)/sept/sept-secondary.bin - cp sept/sept-secondary/sept-secondary_00.enc atmosphere-$(AMSVER)/sept/sept-secondary_00.enc - cp sept/sept-secondary/sept-secondary_01.enc atmosphere-$(AMSVER)/sept/sept-secondary_01.enc - cp sept/sept-secondary/sept-secondary_dev_00.enc atmosphere-$(AMSVER)/sept/sept-secondary_dev_00.enc - cp sept/sept-secondary/sept-secondary_dev_01.enc atmosphere-$(AMSVER)/sept/sept-secondary_dev_01.enc - cp config_templates/BCT.ini atmosphere-$(AMSVER)/atmosphere/config/BCT.ini - cp config_templates/override_config.ini atmosphere-$(AMSVER)/atmosphere/config_templates/override_config.ini - cp config_templates/system_settings.ini atmosphere-$(AMSVER)/atmosphere/config_templates/system_settings.ini - cp config_templates/exosphere.ini atmosphere-$(AMSVER)/atmosphere/config_templates/exosphere.ini - cp -r config_templates/kip_patches atmosphere-$(AMSVER)/atmosphere/kip_patches - cp -r config_templates/hbl_html atmosphere-$(AMSVER)/atmosphere/hbl_html - cp stratosphere/boot2/boot2.nsp atmosphere-$(AMSVER)/atmosphere/contents/0100000000000008/exefs.nsp - cp stratosphere/dmnt/dmnt.nsp atmosphere-$(AMSVER)/atmosphere/contents/010000000000000D/exefs.nsp - cp stratosphere/erpt/erpt.nsp atmosphere-$(AMSVER)/atmosphere/contents/010000000000002B/exefs.nsp - cp stratosphere/eclct.stub/eclct.stub.nsp atmosphere-$(AMSVER)/atmosphere/contents/0100000000000032/exefs.nsp - cp stratosphere/fatal/fatal.nsp atmosphere-$(AMSVER)/atmosphere/contents/0100000000000034/exefs.nsp - cp stratosphere/creport/creport.nsp atmosphere-$(AMSVER)/atmosphere/contents/0100000000000036/exefs.nsp - cp stratosphere/ro/ro.nsp atmosphere-$(AMSVER)/atmosphere/contents/0100000000000037/exefs.nsp - cp stratosphere/jpegdec/jpegdec.nsp atmosphere-$(AMSVER)/atmosphere/contents/010000000000003C/exefs.nsp - cp stratosphere/pgl/pgl.nsp atmosphere-$(AMSVER)/atmosphere/contents/0100000000000042/exefs.nsp - mkdir -p atmosphere-$(AMSVER)/atmosphere/contents/0100000000000032/flags - touch atmosphere-$(AMSVER)/atmosphere/contents/0100000000000032/flags/boot2.flag - mkdir -p atmosphere-$(AMSVER)/atmosphere/contents/0100000000000037/flags - touch atmosphere-$(AMSVER)/atmosphere/contents/0100000000000037/flags/boot2.flag - cp troposphere/reboot_to_payload/reboot_to_payload.nro atmosphere-$(AMSVER)/switch/reboot_to_payload.nro - cp troposphere/daybreak/daybreak.nro atmosphere-$(AMSVER)/switch/daybreak.nro - cd atmosphere-$(AMSVER); zip -r ../atmosphere-EXPERIMENTAL-$(AMSVER).zip ./*; cd ../; - cp fusee/fusee-secondary/fusee-secondary.bin atmosphere-$(AMSVER)/atmosphere/fusee-secondary.bin - cp fusee/fusee-secondary/fusee-secondary.bin atmosphere-$(AMSVER)/sept/payload.bin + + mkdir -p atmosphere-$(AMSVER) + mkdir -p atmosphere-$(AMSVER)/atmo/atmosphere + mkdir -p atmosphere-$(AMSVER)/base/bootloader/payloads + mkdir -p atmosphere-$(AMSVER)/atmo/sept + mkdir -p atmosphere-$(AMSVER)/atmo/switch/daybreak + mkdir -p atmosphere-$(AMSVER)/atmo/atmosphere/contents/0100000000000008 + mkdir -p atmosphere-$(AMSVER)/atmo/atmosphere/contents/010000000000000D + mkdir -p atmosphere-$(AMSVER)/atmo/atmosphere/contents/010000000000002B + mkdir -p atmosphere-$(AMSVER)/atmo/atmosphere/contents/0100000000000032 + mkdir -p atmosphere-$(AMSVER)/atmo/atmosphere/contents/0100000000000034 + mkdir -p atmosphere-$(AMSVER)/atmo/atmosphere/contents/0100000000000036 + mkdir -p atmosphere-$(AMSVER)/atmo/atmosphere/contents/0100000000000037 + mkdir -p atmosphere-$(AMSVER)/atmo/atmosphere/contents/010000000000003C + mkdir -p atmosphere-$(AMSVER)/atmo/atmosphere/contents/0100000000000042 + mkdir -p atmosphere-$(AMSVER)/atmo/atmosphere/fatal_errors + mkdir -p atmosphere-$(AMSVER)/atmo/atmosphere/config_templates + mkdir -p atmosphere-$(AMSVER)/atmo/atmosphere/config + + cp fusee/fusee-mtc/fusee-mtc.bin atmosphere-$(AMSVER)/atmo/atmosphere/fusee-mtc.bin + cp fusee/fusee-secondary/fusee-secondary.bin atmosphere-$(AMSVER)/atmo/atmosphere/fusee-secondary.bin + cp fusee/fusee-secondary/fusee-secondary.bin atmosphere-$(AMSVER)/atmo/sept/payload.bin + + + cp sept/sept-primary/sept-primary.bin atmosphere-$(AMSVER)/atmo/sept/sept-primary.bin + cp sept/sept-secondary/sept-secondary.bin atmosphere-$(AMSVER)/atmo/sept/sept-secondary.bin + cp sept/sept-secondary/sept-secondary_00.enc atmosphere-$(AMSVER)/atmo/sept/sept-secondary_00.enc + cp sept/sept-secondary/sept-secondary_01.enc atmosphere-$(AMSVER)/atmo/sept/sept-secondary_01.enc + cp sept/sept-secondary/sept-secondary_dev_00.enc atmosphere-$(AMSVER)/atmo/sept/sept-secondary_dev_00.enc + cp sept/sept-secondary/sept-secondary_dev_01.enc atmosphere-$(AMSVER)/atmo/sept/sept-secondary_dev_01.enc + + cp config_templates/override_config.ini atmosphere-$(AMSVER)/atmo/atmosphere/config_templates/override_config.ini + cp config_templates/system_settings.ini atmosphere-$(AMSVER)/atmo/atmosphere/config_templates/system_settings.ini + cp config_templates/exosphere.ini atmosphere-$(AMSVER)/atmo/atmosphere/config_templates/exosphere.ini + + cp -r config_templates/kip_patches atmosphere-$(AMSVER)/atmo/atmosphere/kip_patches + cp -r config_templates/hbl_html atmosphere-$(AMSVER)/atmo/atmosphere/hbl_html + cp stratosphere/boot2/boot2.nsp atmosphere-$(AMSVER)/atmo/atmosphere/contents/0100000000000008/exefs.nsp + cp stratosphere/dmnt/dmnt.nsp atmosphere-$(AMSVER)/atmo/atmosphere/contents/010000000000000D/exefs.nsp + cp stratosphere/erpt/erpt.nsp atmosphere-$(AMSVER)/atmo/atmosphere/contents/010000000000002B/exefs.nsp + cp stratosphere/eclct.stub/eclct.stub.nsp atmosphere-$(AMSVER)/atmo/atmosphere/contents/0100000000000032/exefs.nsp + cp stratosphere/fatal/fatal.nsp atmosphere-$(AMSVER)/atmo/atmosphere/contents/0100000000000034/exefs.nsp + cp stratosphere/creport/creport.nsp atmosphere-$(AMSVER)/atmo/atmosphere/contents/0100000000000036/exefs.nsp + cp stratosphere/ro/ro.nsp atmosphere-$(AMSVER)/atmo/atmosphere/contents/0100000000000037/exefs.nsp + cp stratosphere/jpegdec/jpegdec.nsp atmosphere-$(AMSVER)/atmo/atmosphere/contents/010000000000003C/exefs.nsp + cp stratosphere/pgl/pgl.nsp atmosphere-$(AMSVER)/atmo/atmosphere/contents/0100000000000042/exefs.nsp + + mkdir -p atmosphere-$(AMSVER)/atmo/atmosphere/contents/0100000000000032/flags + touch atmosphere-$(AMSVER)/atmo/atmosphere/contents/0100000000000032/flags/boot2.flag + mkdir -p atmosphere-$(AMSVER)/atmo/atmosphere/contents/0100000000000037/flags + touch atmosphere-$(AMSVER)/atmo/atmosphere/contents/0100000000000037/flags/boot2.flag + cp fusee/fusee-primary/fusee-primary.bin atmosphere-$(AMSVER)/base/bootloader/payloads/fusee-primary.bin + cp troposphere/daybreak/daybreak.nro atmosphere-$(AMSVER)/atmo/switch/daybreak/daybreak.nro cd atmosphere-$(AMSVER); zip -r ../atmosphere-$(AMSVER).zip ./*; cd ../; rm -r atmosphere-$(AMSVER) mkdir out - mv atmosphere-EXPERIMENTAL-$(AMSVER).zip out/atmosphere-EXPERIMENTAL-$(AMSVER).zip - mv atmosphere-$(AMSVER).zip out/atmosphere-$(AMSVER).zip - cp fusee/fusee-primary/fusee-primary.bin out/fusee-primary.bin + mv atmosphere-$(AMSVER).zip ../atmosphere-$(AMSVER).zip -dist: dist-no-debug +dist-debug: debug $(eval MAJORVER = $(shell grep 'define ATMOSPHERE_RELEASE_VERSION_MAJOR\b' libraries/libvapours/include/vapours/ams/ams_api_version.h \ | tr -s [:blank:] \ | cut -d' ' -f3)) @@ -131,7 +134,6 @@ dist: dist-no-debug cp exosphere/loader_stub/loader_stub.elf atmosphere-$(AMSVER)-debug/exosphere-loader-stub.elf cp exosphere/program/program.elf atmosphere-$(AMSVER)-debug/exosphere-program.elf cp exosphere/warmboot/warmboot.elf atmosphere-$(AMSVER)-debug/exosphere-warmboot.elf - cp exosphere/mariko_fatal/mariko_fatal.elf atmosphere-$(AMSVER)-debug/exosphere-mariko-fatal.elf cp exosphere/program/sc7fw/sc7fw.elf atmosphere-$(AMSVER)-debug/exosphere-sc7fw.elf cp exosphere/program/rebootstub/rebootstub.elf atmosphere-$(AMSVER)-debug/exosphere-rebootstub.elf cp mesosphere/kernel_ldr/kernel_ldr.elf atmosphere-$(AMSVER)-debug/kernel_ldr.elf @@ -141,16 +143,15 @@ dist: dist-no-debug cp stratosphere/creport/creport.elf atmosphere-$(AMSVER)-debug/creport.elf cp stratosphere/dmnt/dmnt.elf atmosphere-$(AMSVER)-debug/dmnt.elf cp stratosphere/eclct.stub/eclct.stub.elf atmosphere-$(AMSVER)-debug/eclct.stub.elf - cp stratosphere/erpt/erpt.elf atmosphere-$(AMSVER)-debug/erpt.elf cp stratosphere/fatal/fatal.elf atmosphere-$(AMSVER)-debug/fatal.elf - cp stratosphere/jpegdec/jpegdec.elf atmosphere-$(AMSVER)-debug/jpegdec.elf cp stratosphere/loader/loader.elf atmosphere-$(AMSVER)-debug/loader.elf - cp stratosphere/ncm/ncm.elf atmosphere-$(AMSVER)-debug/ncm.elf - cp stratosphere/pgl/pgl.elf atmosphere-$(AMSVER)-debug/pgl.elf cp stratosphere/pm/pm.elf atmosphere-$(AMSVER)-debug/pm.elf cp stratosphere/ro/ro.elf atmosphere-$(AMSVER)-debug/ro.elf cp stratosphere/sm/sm.elf atmosphere-$(AMSVER)-debug/sm.elf cp stratosphere/spl/spl.elf atmosphere-$(AMSVER)-debug/spl.elf + cp stratosphere/erpt/erpt.elf atmosphere-$(AMSVER)-debug/erpt.elf + cp stratosphere/jpegdec/jpegdec.elf atmosphere-$(AMSVER)-debug/jpegdec.elf + cp stratosphere/pgl/pgl.elf atmosphere-$(AMSVER)-debug/pgl.elf cp troposphere/daybreak/daybreak.elf atmosphere-$(AMSVER)-debug/daybreak.elf cd atmosphere-$(AMSVER)-debug; zip -r ../atmosphere-$(AMSVER)-debug.zip ./*; cd ../; rm -r atmosphere-$(AMSVER)-debug diff --git a/docs/building.md b/docs/building.md index 43447856b..2beb3fff3 100644 --- a/docs/building.md +++ b/docs/building.md @@ -9,20 +9,40 @@ Building Atmosphère is a very straightforward process that relies almost exclus ## Instructions 1. Follow the guide located [here](https://devkitpro.org/wiki/Getting_Started) to install and configure all the tools necessary for the build process. + 1. `sudo apt-get install gdebi-core` + 1. `wget https://github.com/devkitPro/pacman/releases/download/v1.0.2/devkitpro-pacman.amd64.deb` + 1. `sudo gdebi devkitpro-pacman.amd64.deb -y` -2. Install the following packages via (dkp-)pacman: +1. Sure that `zip` is installed. Instead `sudo apt-get install zip -y` + +1. Install the following packages via `sudo dkp-pacman -S` : + `switch-dev` + `switch-glm` + `switch-libjpeg-turbo` + `devkitARM` + `devkitarm-rules` + + `switch-glm` -3. (Optional) In order to build [sept](components/sept.md) the pycryptodome PyPi package is required, which can be installed by running `pip install pycryptodome` under the installed Python environment of your choice or by installing the complete zip package to support the `make dist` recipe. This is an optional step included for advanced users who have the ability to provide the necessary encryption/signing keys themselves. +1. Build and install master branch of libnx and needed extensions -4. It is, instead, possible to build [sept](components/sept.md) by providing previously encrypted/signed binaries distributed by official Atmosphère release packages. In order to do so, export the following variables in your current environment: + + `git clone https://github.com/switchbrew/libnx.git` + + `cd libnx` + + `make install` + + Unpack maked tar in `libnx/nx` to `opt/devkitpro/libnx` + + `sudo apt install python-pip` + + `sudo apt install python3-pip` + + `pip install pycryptodome` + + `pip install lz4==0.10.0` + +1. It is, instead, possible to build [sept](components/sept.md) by providing previously encrypted/signed binaries distributed by official Atmosphère release packages. In order to do so, export the following variables in your current environment (`sudo nano /etc/environment`): + `SEPT_00_ENC_PATH` (must point to the `sept-secondary_00.enc` file) + `SEPT_01_ENC_PATH` (must point to the `sept-secondary_01.enc` file) + `SEPT_DEV_00_ENC_PATH` (must point to the `sept-secondary_dev_00.enc` file) + `SEPT_DEV_01_ENC_PATH` (must point to the `sept-secondary_dev_01.enc` file) -5. Finally, clone the Atmosphère repository and run `make` under its root directory. + + `export SEPT_00_ENC_PATH="~/sept/sept-secondary_00.enc"` + + `export SEPT_01_ENC_PATH="~/sept/sept-secondary_01.enc"` + + `export SEPT_DEV_00_ENC_PATH="~/sept/sept-secondary_dev_00.enc"` + + `export SEPT_DEV_01_ENC_PATH="~/sept/sept-secondary_dev_01.enc"` + +1. Finally, clone the Atmosphère repository and run `make` under its root directory. diff --git a/docs/cheat_sheet.txt b/docs/cheat_sheet.txt new file mode 100644 index 000000000..01ca75ccd --- /dev/null +++ b/docs/cheat_sheet.txt @@ -0,0 +1,18 @@ +export SEPT_01_ENC_PATH="~/sept/sept-secondary_01.enc" +export SEPT_00_ENC_PATH="~/sept/sept-secondary_00.enc" +export SEPT_DEV_00_ENC_PATH="~/sept/sept-secondary_dev_00.enc" +export SEPT_DEV_01_ENC_PATH="~/sept/sept-secondary_dev_01.enc" + + git remote add atmo https://github.com/Atmosphere-NX/Atmosphere.git + git fetch atmo + git pull atmo master + + git checkout tags/0.15.0 -b 0.15.0 + + git clean -xdf + +git remote add fspusb https://github.com/XorTroll/Atmosphere.git +git fetch fspusb +git cherry-pick + +sudo nano ~/.bashrc - export \ No newline at end of file diff --git a/libraries/.gitrepo b/libraries/.gitrepo index c03fef33f..aa9cd1291 100644 --- a/libraries/.gitrepo +++ b/libraries/.gitrepo @@ -6,7 +6,7 @@ [subrepo] remote = https://github.com/Atmosphere-NX/Atmosphere-libs branch = master - commit = 49c1ace8906a967f2c92d369a0c66779b9cd225b - parent = 2b93bbd9ee174863dbf5c611c0d9d159fe9e6e31 + commit = 2c3ccef17e9b267a5d9d232f1aba689f2c591b95 + parent = d2f48d5e36cb2ba4e8cc014238457bd75df81797 method = merge cmdver = 0.4.1 diff --git a/stratosphere/ams_mitm/source/amsmitm_initialization.cpp b/stratosphere/ams_mitm/source/amsmitm_initialization.cpp index 38759498a..33f0ba3e9 100644 --- a/stratosphere/ams_mitm/source/amsmitm_initialization.cpp +++ b/stratosphere/ams_mitm/source/amsmitm_initialization.cpp @@ -65,8 +65,8 @@ namespace ams::mitm { FsFile g_emummc_file; /* Maintain exclusive access to the fusee-secondary archive. */ - FsFile g_secondary_file; - FsFile g_sept_payload_file; + // FsFile g_secondary_file; + // FsFile g_sept_payload_file; constexpr inline bool IsHexadecimal(const char *str) { while (*str) { @@ -134,14 +134,14 @@ namespace ams::mitm { /* NOTE: g_bis_key_file is intentionally not closed here. This prevents any other process from opening it. */ } - /* Open a reference to the fusee-secondary archive. */ - /* As upcoming/current atmosphere releases will contain more than one zip which users much choose between, */ - /* maintaining an open reference prevents cleanly the issue of "automatic" updaters selecting the incorrect */ - /* zip, and encourages good updating hygiene -- atmosphere should not be updated on SD while HOS is alive. */ - { - R_ABORT_UNLESS(mitm::fs::OpenSdFile(std::addressof(g_secondary_file), "/atmosphere/fusee-secondary.bin", ams::fs::OpenMode_Read)); - R_ABORT_UNLESS(mitm::fs::OpenSdFile(std::addressof(g_sept_payload_file), "/sept/payload.bin", ams::fs::OpenMode_Read)); - } + // /* Open a reference to the fusee-secondary archive. */ + // /* As upcoming/current atmosphere releases will contain more than one zip which users much choose between, */ + // /* maintaining an open reference prevents cleanly the issue of "automatic" updaters selecting the incorrect */ + // /* zip, and encourages good updating hygiene -- atmosphere should not be updated on SD while HOS is alive. */ + // { + // R_ABORT_UNLESS(mitm::fs::OpenSdFile(std::addressof(g_secondary_file), "/atmosphere/fusee-secondary.bin", ams::fs::OpenMode_ReadWrite)); + // R_ABORT_UNLESS(mitm::fs::OpenSdFile(std::addressof(g_sept_payload_file), "/sept/payload.bin", ams::fs::OpenMode_ReadWrite)); + // } } /* Initialization implementation */ diff --git a/stratosphere/ams_mitm/source/amsmitm_module_management.cpp b/stratosphere/ams_mitm/source/amsmitm_module_management.cpp index 03a7d779d..0a3eef27c 100644 --- a/stratosphere/ams_mitm/source/amsmitm_module_management.cpp +++ b/stratosphere/ams_mitm/source/amsmitm_module_management.cpp @@ -24,6 +24,7 @@ #include "ns_mitm/nsmitm_module.hpp" #include "hid_mitm/hidmitm_module.hpp" #include "sysupdater/sysupdater_module.hpp" +// #include "fsp_usb/fspusb_module.hpp" namespace ams::mitm { @@ -37,7 +38,7 @@ namespace ams::mitm { ModuleId_NsMitm, ModuleId_HidMitm, ModuleId_Sysupdater, - + // ModuleId_FspUsb, ModuleId_Count, }; @@ -70,6 +71,7 @@ namespace ams::mitm { GetModuleDefinition(), GetModuleDefinition(), GetModuleDefinition(), + // GetModuleDefinition(), }; } diff --git a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp index b1b49fe91..0bc19b810 100644 --- a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp +++ b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp @@ -28,6 +28,8 @@ namespace ams::mitm::settings { settings::FirmwareVersion g_firmware_version; settings::FirmwareVersion g_ams_firmware_version; + int g_kfr_firmware_version = 0; + void CacheFirmwareVersion() { std::scoped_lock lk(g_firmware_version_lock); @@ -35,6 +37,30 @@ namespace ams::mitm::settings { return; } + { + /* Mount the SD card. */ + if (R_SUCCEEDED(fs::MountSdCard("sdmc"))) { + ams::fs::FileHandle file; + if (R_SUCCEEDED(fs::OpenFile(std::addressof(file), "sdmc:/switch/kefirupdater/version", fs::OpenMode_Read))) { + ON_SCOPE_EXIT { ams::fs::CloseFile(file); }; + + /* Get file size. */ + s64 file_size; + R_ABORT_UNLESS(fs::GetFileSize(std::addressof(file_size), file)); + + /* Allocate cheat txt buffer. */ + char *kef_txt = static_cast(std::malloc(file_size + 1)); + ON_SCOPE_EXIT { std::free(kef_txt); }; + + /* Read cheats into buffer. */ + R_ABORT_UNLESS(fs::ReadFile(file, 0, kef_txt, file_size)); + kef_txt[file_size] = '\x00'; + + g_kfr_firmware_version = strtol(kef_txt, NULL, 10); + } + } + } + /* Mount firmware version data archive. */ { R_ABORT_UNLESS(ams::fs::MountSystemData("sysver", ncm::SystemDataId::SystemVersion)); @@ -56,19 +82,19 @@ namespace ams::mitm::settings { const auto api_info = exosphere::GetApiInfo(); const char emummc_char = emummc::IsActive() ? 'E' : 'S'; - /* NOTE: While Mesosphere is in experimental/opt-in, we will display it as part of the firmware. */ - const char mesosphere_char = svc::IsKernelMesosphere() ? 'M' : '0'; - - /* TODO: Remove separate display for mesosphere vs not mesosphere in Atmosphere 1.0.0. */ - AMS_ABORT_UNLESS(api_info.GetMajorVersion() == 0); - - /* NOTE: We have carefully accounted for the size of the string we print. */ - /* No truncation occurs assuming two-digits for all version number components. */ - char display_version[sizeof(g_ams_firmware_version.display_version)]; - - std::snprintf(display_version, sizeof(display_version), "%s|AMS %c.%u.%u|%c", g_ams_firmware_version.display_version, mesosphere_char, api_info.GetMinorVersion(), api_info.GetMicroVersion(), emummc_char); - - std::memcpy(g_ams_firmware_version.display_version, display_version, sizeof(display_version)); + /* GCC complains about the following snprintf possibly truncating, but this is not a problem and has been carefully accounted for. */ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wformat-truncation" + { + char display_version[sizeof(g_ams_firmware_version.display_version)]; + if ( g_kfr_firmware_version != 0 ) + std::snprintf(display_version, sizeof(display_version), "%s|KEF%d-%u.%u.%u|%c", g_ams_firmware_version.display_version, g_kfr_firmware_version, api_info.GetMajorVersion(), api_info.GetMinorVersion(), api_info.GetMicroVersion(), emummc_char); + else + std::snprintf(display_version, sizeof(display_version), "%s|KEF-%u.%u.%u|%c", g_ams_firmware_version.display_version, api_info.GetMajorVersion(), api_info.GetMinorVersion(), api_info.GetMicroVersion(), emummc_char); + + std::memcpy(g_ams_firmware_version.display_version, display_version, sizeof(display_version)); + } + #pragma GCC diagnostic pop } g_cached_firmware_version = true; diff --git a/stratosphere/loader/source/ldr_development_manager.cpp b/stratosphere/loader/source/ldr_development_manager.cpp index cf15a3e3f..f7ed0dfb9 100644 --- a/stratosphere/loader/source/ldr_development_manager.cpp +++ b/stratosphere/loader/source/ldr_development_manager.cpp @@ -50,15 +50,15 @@ namespace ams::ldr { } bool IsDevelopmentForAntiDowngradeCheck() { - return g_development_for_anti_downgrade_check; + return true; } bool IsDevelopmentForAcidSignatureCheck() { - return g_development_for_acid_signature_check; + return false; } bool IsEnabledProgramVerification() { - return g_enabled_program_verification; + return false; } } diff --git a/stratosphere/loader/source/ldr_meta.cpp b/stratosphere/loader/source/ldr_meta.cpp index ef6e32b78..852d259f1 100644 --- a/stratosphere/loader/source/ldr_meta.cpp +++ b/stratosphere/loader/source/ldr_meta.cpp @@ -132,7 +132,7 @@ namespace ams::ldr { const bool is_signature_valid = crypto::VerifyRsa2048PssSha256(sig, sig_size, mod, mod_size, exp, exp_size, msg, msg_size); R_UNLESS(is_signature_valid || !IsEnabledProgramVerification(), ResultInvalidAcidSignature()); - meta->check_verification_data = is_signature_valid; + meta->check_verification_data = false; return ResultSuccess(); } diff --git a/troposphere/daybreak/nanovg/include/deko3d.h b/troposphere/daybreak/nanovg/include/deko3d.h new file mode 100644 index 000000000..6b6ad5051 --- /dev/null +++ b/troposphere/daybreak/nanovg/include/deko3d.h @@ -0,0 +1,1353 @@ +/* +**----------------------------------------------------------------------------- +** deko3d.h - Main header file for deko3d +**----------------------------------------------------------------------------- +** +** Copyright (C) 2018-2020 fincs +** +** This software is provided 'as-is', without any express or implied +** warranty. In no event will the authors be held liable for any +** damages arising from the use of this software. +** +** Permission is granted to anyone to use this software for any +** purpose, including commercial applications, and to alter it and +** redistribute it freely, subject to the following restrictions: +** +** 1. The origin of this software must not be misrepresented; you +** must not claim that you wrote the original software. If you use +** this software in a product, an acknowledgment in the product +** documentation would be appreciated but is not required. +** 2. Altered source versions must be plainly marked as such, and +** must not be misrepresented as being the original software. +** 3. This notice may not be removed or altered from any source +** distribution. +** +** This file is currently written by hand; in the future it might be autogenerated. +** +*/ + +#pragma once +#include +#include +#include +#include + +#if __cplusplus >= 201402L +#define DK_CONSTEXPR constexpr +#else +#define DK_CONSTEXPR static inline +#endif + +#ifndef __cplusplus + +#define DK_DECL_HANDLE(_typename) \ + typedef struct tag_Dk##_typename *Dk##_typename + +#else + +#define DK_DECL_HANDLE(_typename) \ + namespace dk::detail { struct _typename; } \ + using Dk##_typename = dk::detail::_typename* + +#endif + +#ifndef __DK_INTERNAL__ + +#define DK_DECL_OPAQUE(_typename, _align, _size) \ + typedef struct Dk##_typename \ + { \ + alignas(_align) uint8_t _storage[_size]; \ + } Dk##_typename + +#else + +#define DK_DECL_OPAQUE(_typename, _align, _size) \ + namespace dk::detail { \ + struct _typename; /* forward declaration */ \ + constexpr unsigned _align_##_typename = _align; \ + constexpr unsigned _size_##_typename = _size; \ + } \ + using Dk##_typename = dk::detail::_typename + +#endif + +DK_DECL_HANDLE(Device); +DK_DECL_HANDLE(MemBlock); +DK_DECL_OPAQUE(Fence, 8, 64); +DK_DECL_HANDLE(CmdBuf); +DK_DECL_HANDLE(Queue); +DK_DECL_OPAQUE(Shader, 8, 128); +DK_DECL_OPAQUE(ImageLayout, 8, 128); +DK_DECL_OPAQUE(Image, 8, 128); +DK_DECL_OPAQUE(ImageDescriptor, 4, 32); +DK_DECL_OPAQUE(SamplerDescriptor, 4, 32); +DK_DECL_HANDLE(Swapchain); + +#undef DK_DECL_HANDLE +#undef DK_DECL_OPAQUE + +typedef enum +{ + DkResult_Success, + DkResult_Fail, + DkResult_Timeout, + DkResult_OutOfMemory, + DkResult_NotImplemented, + DkResult_MisalignedSize, + DkResult_MisalignedData, + DkResult_BadInput, + DkResult_BadFlags, + DkResult_BadState, +} DkResult; + +#define DK_GPU_ADDR_INVALID UINT64_MAX + +typedef uint64_t DkGpuAddr; +typedef uintptr_t DkCmdList; +typedef uint32_t DkResHandle; +typedef void (*DkDebugFunc)(void* userData, const char* context, DkResult result, const char* message); +typedef DkResult (*DkAllocFunc)(void* userData, size_t alignment, size_t size, void** out); +typedef void (*DkFreeFunc)(void* userData, void* mem); +typedef void (*DkCmdBufAddMemFunc)(void* userData, DkCmdBuf cmdbuf, size_t minReqSize); + +enum +{ + DkDeviceFlags_DepthZeroToOne = 0U << 8, + DkDeviceFlags_DepthMinusOneToOne = 1U << 8, + DkDeviceFlags_OriginUpperLeft = 0U << 9, + DkDeviceFlags_OriginLowerLeft = 1U << 9, +}; + +typedef struct DkDeviceMaker +{ + void* userData; + DkDebugFunc cbDebug; + DkAllocFunc cbAlloc; + DkFreeFunc cbFree; + uint32_t flags; +} DkDeviceMaker; + +DK_CONSTEXPR void dkDeviceMakerDefaults(DkDeviceMaker* maker) +{ + maker->userData = NULL; + maker->cbDebug = NULL; + maker->cbAlloc = NULL; + maker->cbFree = NULL; + maker->flags = DkDeviceFlags_DepthZeroToOne | DkDeviceFlags_OriginUpperLeft; +} + +#define DK_MEMBLOCK_ALIGNMENT 0x1000 +#define DK_CMDMEM_ALIGNMENT 4 +#define DK_QUEUE_MIN_CMDMEM_SIZE 0x10000 +#define DK_PER_WARP_SCRATCH_MEM_ALIGNMENT 0x200 +#define DK_NUM_UNIFORM_BUFS 16 +#define DK_NUM_STORAGE_BUFS 16 +#define DK_NUM_TEXTURE_BINDINGS 32 +#define DK_NUM_IMAGE_BINDINGS 8 +#define DK_UNIFORM_BUF_ALIGNMENT 0x100 +#define DK_UNIFORM_BUF_MAX_SIZE 0x10000 +#define DK_DEFAULT_MAX_COMPUTE_CONCURRENT_JOBS 128 +#define DK_SHADER_CODE_ALIGNMENT 0x100 +#define DK_SHADER_CODE_UNUSABLE_SIZE 0x400 +#define DK_IMAGE_DESCRIPTOR_ALIGNMENT 0x20 +#define DK_SAMPLER_DESCRIPTOR_ALIGNMENT 0x20 +#define DK_MAX_RENDER_TARGETS 8 +#define DK_NUM_VIEWPORTS 16 +#define DK_NUM_SCISSORS 16 +#define DK_MAX_VERTEX_ATTRIBS 32 +#define DK_MAX_VERTEX_BUFFERS 16 +#define DK_IMAGE_LINEAR_STRIDE_ALIGNMENT 32 + +enum +{ + DkMemAccess_None = 0U, + DkMemAccess_Uncached = 1U, + DkMemAccess_Cached = 2U, + DkMemAccess_Mask = 3U, +}; + +enum +{ + DkMemBlockFlags_CpuAccessShift = 0U, + DkMemBlockFlags_GpuAccessShift = 2U, + DkMemBlockFlags_CpuUncached = DkMemAccess_Uncached << DkMemBlockFlags_CpuAccessShift, + DkMemBlockFlags_CpuCached = DkMemAccess_Cached << DkMemBlockFlags_CpuAccessShift, + DkMemBlockFlags_CpuAccessMask = DkMemAccess_Mask << DkMemBlockFlags_CpuAccessShift, + DkMemBlockFlags_GpuUncached = DkMemAccess_Uncached << DkMemBlockFlags_GpuAccessShift, + DkMemBlockFlags_GpuCached = DkMemAccess_Cached << DkMemBlockFlags_GpuAccessShift, + DkMemBlockFlags_GpuAccessMask = DkMemAccess_Mask << DkMemBlockFlags_GpuAccessShift, + DkMemBlockFlags_Code = 1U << 4, + DkMemBlockFlags_Image = 1U << 5, + DkMemBlockFlags_ZeroFillInit = 1U << 8, +}; + +typedef struct DkMemBlockMaker +{ + DkDevice device; + uint32_t size; + uint32_t flags; + void* storage; +} DkMemBlockMaker; + +DK_CONSTEXPR void dkMemBlockMakerDefaults(DkMemBlockMaker* maker, DkDevice device, uint32_t size) +{ + maker->device = device; + maker->size = size; + maker->flags = DkMemBlockFlags_CpuUncached | DkMemBlockFlags_GpuCached; + maker->storage = NULL; +} + +typedef struct DkCmdBufMaker +{ + DkDevice device; + void* userData; + DkCmdBufAddMemFunc cbAddMem; +} DkCmdBufMaker; + +DK_CONSTEXPR void dkCmdBufMakerDefaults(DkCmdBufMaker* maker, DkDevice device) +{ + maker->device = device; + maker->userData = NULL; + maker->cbAddMem = NULL; +} + +enum +{ + DkQueueFlags_Graphics = 1U << 0, + DkQueueFlags_Compute = 1U << 1, + DkQueueFlags_MediumPrio = 0U << 2, + DkQueueFlags_HighPrio = 1U << 2, + DkQueueFlags_LowPrio = 2U << 2, + DkQueueFlags_PrioMask = 3U << 2, + DkQueueFlags_EnableZcull = 0U << 4, + DkQueueFlags_DisableZcull = 1U << 4, +}; + +typedef struct DkQueueMaker +{ + DkDevice device; + uint32_t flags; + uint32_t commandMemorySize; + uint32_t flushThreshold; + uint32_t perWarpScratchMemorySize; + uint32_t maxConcurrentComputeJobs; +} DkQueueMaker; + +DK_CONSTEXPR void dkQueueMakerDefaults(DkQueueMaker* maker, DkDevice device) +{ + maker->device = device; + maker->flags = + DkQueueFlags_Graphics | DkQueueFlags_Compute | DkQueueFlags_MediumPrio | + DkQueueFlags_EnableZcull; + maker->commandMemorySize = DK_QUEUE_MIN_CMDMEM_SIZE; + maker->flushThreshold = DK_QUEUE_MIN_CMDMEM_SIZE/8; + maker->perWarpScratchMemorySize = 4*DK_PER_WARP_SCRATCH_MEM_ALIGNMENT; + maker->maxConcurrentComputeJobs = DK_DEFAULT_MAX_COMPUTE_CONCURRENT_JOBS; +} + +typedef struct DkShaderMaker +{ + DkMemBlock codeMem; + const void* control; + uint32_t codeOffset; + uint32_t programId; +} DkShaderMaker; + +DK_CONSTEXPR void dkShaderMakerDefaults(DkShaderMaker* maker, DkMemBlock codeMem, uint32_t codeOffset) +{ + maker->codeMem = codeMem; + maker->control = NULL; + maker->codeOffset = codeOffset; + maker->programId = 0; +} + +typedef enum DkStage +{ + DkStage_Vertex = 0, + DkStage_TessCtrl = 1, + DkStage_TessEval = 2, + DkStage_Geometry = 3, + DkStage_Fragment = 4, + DkStage_Compute = 5, + + DkStage_MaxGraphics = 5, +} DkStage; + +enum +{ + DkStageFlag_Vertex = 1U << DkStage_Vertex, + DkStageFlag_TessCtrl = 1U << DkStage_TessCtrl, + DkStageFlag_TessEval = 1U << DkStage_TessEval, + DkStageFlag_Geometry = 1U << DkStage_Geometry, + DkStageFlag_Fragment = 1U << DkStage_Fragment, + DkStageFlag_Compute = 1U << DkStage_Compute, + + DkStageFlag_GraphicsMask = (1U << DkStage_MaxGraphics) - 1, +}; + +typedef enum DkBarrier +{ + DkBarrier_None = 0, // No ordering is performed + DkBarrier_Tiles = 1, // Orders the processing of tiles (similar to Vulkan subpasses) + DkBarrier_Fragments = 2, // Orders the processing of fragments (similar to Vulkan renderpasses) + DkBarrier_Primitives = 3, // Completes the processing of all previous primitives and compute jobs + DkBarrier_Full = 4, // Completes the processing of all previous commands while disabling command list prefetch +} DkBarrier; + +enum +{ + DkInvalidateFlags_Image = 1U << 0, // Invalidates the image (texture) cache + DkInvalidateFlags_Shader = 1U << 1, // Invalidates the shader code/data/uniform cache + DkInvalidateFlags_Descriptors = 1U << 2, // Invalidates the image/sampler descriptor cache + DkInvalidateFlags_Zcull = 1U << 3, // Invalidates Zcull state + DkInvalidateFlags_L2Cache = 1U << 4, // Invalidates the L2 cache +}; + +typedef enum DkImageType +{ + DkImageType_None = 0, + DkImageType_1D = 1, + DkImageType_2D = 2, + DkImageType_3D = 3, + DkImageType_1DArray = 4, + DkImageType_2DArray = 5, + DkImageType_2DMS = 6, + DkImageType_2DMSArray = 7, + DkImageType_Rectangle = 8, + DkImageType_Cubemap = 9, + DkImageType_CubemapArray = 10, + DkImageType_Buffer = 11, +} DkImageType; + +enum +{ + DkImageFlags_BlockLinear = 0U << 0, // Image is stored in Nvidia block linear format (default). + DkImageFlags_PitchLinear = 1U << 0, // Image is stored in standard pitch linear format. + DkImageFlags_CustomTileSize = 1U << 1, // Use a custom tile size for block linear images. + DkImageFlags_HwCompression = 1U << 2, // Specifies that hardware compression is allowed to be enabled. + DkImageFlags_Z16EnableZbc = 1U << 3, // For DkImageFormat_Z16 images, specifies that zero-bandwidth clear is preferred as the hardware compression format. + + DkImageFlags_UsageRender = 1U << 8, // Specifies that the image will be used as a render target. + DkImageFlags_UsageLoadStore = 1U << 9, // Specifies that the image will be used with shader image load/store commands. + DkImageFlags_UsagePresent = 1U << 10, // Specifies that the image will be used with a DkSwapchain. + DkImageFlags_Usage2DEngine = 1U << 11, // Specifies that the image will be used with the 2D Engine (e.g. for transfers between images) + DkImageFlags_UsageVideo = 1U << 12, // Specifies that the image will be used with hardware video encoding/decoding engines +}; + +typedef enum DkImageFormat +{ + DkImageFormat_None, + DkImageFormat_R8_Unorm, + DkImageFormat_R8_Snorm, + DkImageFormat_R8_Uint, + DkImageFormat_R8_Sint, + DkImageFormat_R16_Float, + DkImageFormat_R16_Unorm, + DkImageFormat_R16_Snorm, + DkImageFormat_R16_Uint, + DkImageFormat_R16_Sint, + DkImageFormat_R32_Float, + DkImageFormat_R32_Uint, + DkImageFormat_R32_Sint, + DkImageFormat_RG8_Unorm, + DkImageFormat_RG8_Snorm, + DkImageFormat_RG8_Uint, + DkImageFormat_RG8_Sint, + DkImageFormat_RG16_Float, + DkImageFormat_RG16_Unorm, + DkImageFormat_RG16_Snorm, + DkImageFormat_RG16_Uint, + DkImageFormat_RG16_Sint, + DkImageFormat_RG32_Float, + DkImageFormat_RG32_Uint, + DkImageFormat_RG32_Sint, + DkImageFormat_RGB32_Float, + DkImageFormat_RGB32_Uint, + DkImageFormat_RGB32_Sint, + DkImageFormat_RGBA8_Unorm, + DkImageFormat_RGBA8_Snorm, + DkImageFormat_RGBA8_Uint, + DkImageFormat_RGBA8_Sint, + DkImageFormat_RGBA16_Float, + DkImageFormat_RGBA16_Unorm, + DkImageFormat_RGBA16_Snorm, + DkImageFormat_RGBA16_Uint, + DkImageFormat_RGBA16_Sint, + DkImageFormat_RGBA32_Float, + DkImageFormat_RGBA32_Uint, + DkImageFormat_RGBA32_Sint, + DkImageFormat_S8, + DkImageFormat_Z16, + DkImageFormat_Z24X8, + DkImageFormat_ZF32, + DkImageFormat_Z24S8, + DkImageFormat_ZF32_X24S8, + DkImageFormat_RGBX8_Unorm_sRGB, + DkImageFormat_RGBA8_Unorm_sRGB, + DkImageFormat_RGBA4_Unorm, + DkImageFormat_RGB5_Unorm, + DkImageFormat_RGB5A1_Unorm, + DkImageFormat_RGB565_Unorm, + DkImageFormat_RGB10A2_Unorm, + DkImageFormat_RGB10A2_Uint, + DkImageFormat_RG11B10_Float, + DkImageFormat_E5BGR9_Float, + DkImageFormat_RGB_BC1, + DkImageFormat_RGBA_BC1, + DkImageFormat_RGBA_BC2, + DkImageFormat_RGBA_BC3, + DkImageFormat_RGB_BC1_sRGB, + DkImageFormat_RGBA_BC1_sRGB, + DkImageFormat_RGBA_BC2_sRGB, + DkImageFormat_RGBA_BC3_sRGB, + DkImageFormat_R_BC4_Unorm, + DkImageFormat_R_BC4_Snorm, + DkImageFormat_RG_BC5_Unorm, + DkImageFormat_RG_BC5_Snorm, + DkImageFormat_RGBA_BC7_Unorm, + DkImageFormat_RGBA_BC7_Unorm_sRGB, + DkImageFormat_RGBA_BC6H_SF16_Float, + DkImageFormat_RGBA_BC6H_UF16_Float, + DkImageFormat_RGBX8_Unorm, + DkImageFormat_RGBX8_Snorm, + DkImageFormat_RGBX8_Uint, + DkImageFormat_RGBX8_Sint, + DkImageFormat_RGBX16_Float, + DkImageFormat_RGBX16_Unorm, + DkImageFormat_RGBX16_Snorm, + DkImageFormat_RGBX16_Uint, + DkImageFormat_RGBX16_Sint, + DkImageFormat_RGBX32_Float, + DkImageFormat_RGBX32_Uint, + DkImageFormat_RGBX32_Sint, + DkImageFormat_RGBA_ASTC_4x4, + DkImageFormat_RGBA_ASTC_5x4, + DkImageFormat_RGBA_ASTC_5x5, + DkImageFormat_RGBA_ASTC_6x5, + DkImageFormat_RGBA_ASTC_6x6, + DkImageFormat_RGBA_ASTC_8x5, + DkImageFormat_RGBA_ASTC_8x6, + DkImageFormat_RGBA_ASTC_8x8, + DkImageFormat_RGBA_ASTC_10x5, + DkImageFormat_RGBA_ASTC_10x6, + DkImageFormat_RGBA_ASTC_10x8, + DkImageFormat_RGBA_ASTC_10x10, + DkImageFormat_RGBA_ASTC_12x10, + DkImageFormat_RGBA_ASTC_12x12, + DkImageFormat_RGBA_ASTC_4x4_sRGB, + DkImageFormat_RGBA_ASTC_5x4_sRGB, + DkImageFormat_RGBA_ASTC_5x5_sRGB, + DkImageFormat_RGBA_ASTC_6x5_sRGB, + DkImageFormat_RGBA_ASTC_6x6_sRGB, + DkImageFormat_RGBA_ASTC_8x5_sRGB, + DkImageFormat_RGBA_ASTC_8x6_sRGB, + DkImageFormat_RGBA_ASTC_8x8_sRGB, + DkImageFormat_RGBA_ASTC_10x5_sRGB, + DkImageFormat_RGBA_ASTC_10x6_sRGB, + DkImageFormat_RGBA_ASTC_10x8_sRGB, + DkImageFormat_RGBA_ASTC_10x10_sRGB, + DkImageFormat_RGBA_ASTC_12x10_sRGB, + DkImageFormat_RGBA_ASTC_12x12_sRGB, + DkImageFormat_BGR565_Unorm, + DkImageFormat_BGR5_Unorm, + DkImageFormat_BGR5A1_Unorm, + DkImageFormat_A5BGR5_Unorm, + DkImageFormat_BGRX8_Unorm, + DkImageFormat_BGRA8_Unorm, + DkImageFormat_BGRX8_Unorm_sRGB, + DkImageFormat_BGRA8_Unorm_sRGB, + DkImageFormat_R_ETC2_Unorm, + DkImageFormat_R_ETC2_Snorm, + DkImageFormat_RG_ETC2_Unorm, + DkImageFormat_RG_ETC2_Snorm, + DkImageFormat_RGB_ETC2, // compatible with ETC1 + DkImageFormat_RGB_PTA_ETC2, + DkImageFormat_RGBA_ETC2, + DkImageFormat_RGB_ETC2_sRGB, + DkImageFormat_RGB_PTA_ETC2_sRGB, + DkImageFormat_RGBA_ETC2_sRGB, + + DkImageFormat_Count, +} DkImageFormat; + +typedef enum DkImageSwizzle +{ + DkImageSwizzle_Zero = 0, + DkImageSwizzle_One = 1, + DkImageSwizzle_Red = 2, + DkImageSwizzle_Green = 3, + DkImageSwizzle_Blue = 4, + DkImageSwizzle_Alpha = 5, +} DkImageSwizzle; + +typedef enum DkMsMode +{ + DkMsMode_1x = 0, + DkMsMode_2x = 1, + DkMsMode_4x = 2, + DkMsMode_8x = 3, +} DkMsMode; + +typedef enum DkDsSource +{ + DkDsSource_Depth = 0, + DkDsSource_Stencil = 1, +} DkDsSource; + +typedef enum DkTileSize +{ + DkTileSize_OneGob = 0, + DkTileSize_TwoGobs = 1, + DkTileSize_FourGobs = 2, + DkTileSize_EightGobs = 3, + DkTileSize_SixteenGobs = 4, + DkTileSize_ThirtyTwoGobs = 5, +} DkTileSize; + +typedef struct DkImageLayoutMaker +{ + DkDevice device; + DkImageType type; + uint32_t flags; + DkImageFormat format; + DkMsMode msMode; + uint32_t dimensions[3]; + uint32_t mipLevels; + union + { + uint32_t pitchStride; + DkTileSize tileSize; + }; +} DkImageLayoutMaker; + +DK_CONSTEXPR void dkImageLayoutMakerDefaults(DkImageLayoutMaker* maker, DkDevice device) +{ + maker->device = device; + maker->type = DkImageType_2D; + maker->flags = 0; + maker->format = DkImageFormat_None; + maker->msMode = DkMsMode_1x; + maker->dimensions[0] = 0; + maker->dimensions[1] = 0; + maker->dimensions[2] = 0; + maker->mipLevels = 1; + maker->pitchStride = 0; +} + +typedef struct DkImageView +{ + DkImage const* pImage; + DkImageType type; + DkImageFormat format; + DkImageSwizzle swizzle[4]; + DkDsSource dsSource; + uint16_t layerOffset; + uint16_t layerCount; + uint8_t mipLevelOffset; + uint8_t mipLevelCount; +} DkImageView; + +DK_CONSTEXPR void dkImageViewDefaults(DkImageView* obj, DkImage const* pImage) +{ + obj->pImage = pImage; + obj->type = DkImageType_None; // no override + obj->format = DkImageFormat_None; // no override + obj->swizzle[0] = DkImageSwizzle_Red; + obj->swizzle[1] = DkImageSwizzle_Green; + obj->swizzle[2] = DkImageSwizzle_Blue; + obj->swizzle[3] = DkImageSwizzle_Alpha; + obj->dsSource = DkDsSource_Depth; + obj->layerOffset = 0; + obj->layerCount = 0; // no override + obj->mipLevelOffset = 0; + obj->mipLevelCount = 0; // no override +} + +typedef enum DkFilter +{ + DkFilter_Nearest = 1, + DkFilter_Linear = 2, +} DkFilter; + +typedef enum DkMipFilter +{ + DkMipFilter_None = 1, + DkMipFilter_Nearest = 2, + DkMipFilter_Linear = 3, +} DkMipFilter; + +typedef enum DkWrapMode +{ + DkWrapMode_Repeat = 0, + DkWrapMode_MirroredRepeat = 1, + DkWrapMode_ClampToEdge = 2, + DkWrapMode_ClampToBorder = 3, + DkWrapMode_Clamp = 4, + DkWrapMode_MirrorClampToEdge = 5, + DkWrapMode_MirrorClampToBorder = 6, + DkWrapMode_MirrorClamp = 7, +} DkWrapMode; + +typedef enum DkCompareOp +{ + DkCompareOp_Never = 1, + DkCompareOp_Less = 2, + DkCompareOp_Equal = 3, + DkCompareOp_Lequal = 4, + DkCompareOp_Greater = 5, + DkCompareOp_NotEqual = 6, + DkCompareOp_Gequal = 7, + DkCompareOp_Always = 8, +} DkCompareOp; + +typedef enum DkSamplerReduction +{ + DkSamplerReduction_WeightedAverage = 0, + DkSamplerReduction_Min = 1, + DkSamplerReduction_Max = 2, +} DkSamplerReduction; + +typedef struct DkSampler +{ + DkFilter minFilter; + DkFilter magFilter; + DkMipFilter mipFilter; + DkWrapMode wrapMode[3]; + float lodClampMin; + float lodClampMax; + float lodBias; + float lodSnap; + bool compareEnable; + DkCompareOp compareOp; + union + { + float value_f; + uint32_t value_ui; + int32_t value_i; + } borderColor[4]; + float maxAnisotropy; + DkSamplerReduction reductionMode; +} DkSampler; + +DK_CONSTEXPR void dkSamplerDefaults(DkSampler* obj) +{ + obj->minFilter = DkFilter_Nearest; + obj->magFilter = DkFilter_Nearest; + obj->mipFilter = DkMipFilter_None; + obj->wrapMode[0] = DkWrapMode_Repeat; + obj->wrapMode[1] = DkWrapMode_Repeat; + obj->wrapMode[2] = DkWrapMode_Repeat; + obj->lodClampMin = 0.0f; + obj->lodClampMax = 1000.0f; + obj->lodBias = 0.0f; + obj->lodSnap = 0.0f; + obj->compareEnable = false; + obj->compareOp = DkCompareOp_Less; + obj->borderColor[0].value_ui = 0; + obj->borderColor[1].value_ui = 0; + obj->borderColor[2].value_ui = 0; + obj->borderColor[3].value_ui = 0; + obj->maxAnisotropy = 1.0f; + obj->reductionMode = DkSamplerReduction_WeightedAverage; +} + +typedef struct DkBufExtents +{ + DkGpuAddr addr; + uint32_t size; +} DkBufExtents; + +DK_CONSTEXPR DkResHandle dkMakeImageHandle(uint32_t id) +{ + return id & ((1U << 20) - 1); +} + +DK_CONSTEXPR DkResHandle dkMakeSamplerHandle(uint32_t id) +{ + return id << 20; +} + +DK_CONSTEXPR DkResHandle dkMakeTextureHandle(uint32_t imageId, uint32_t samplerId) +{ + return dkMakeImageHandle(imageId) | dkMakeSamplerHandle(samplerId); +} + +typedef struct DkViewport +{ + float x; + float y; + float width; + float height; + float near; + float far; +} DkViewport; + +typedef enum DkSwizzle +{ + DkSwizzle_PositiveX = 0, + DkSwizzle_NegativeX = 1, + DkSwizzle_PositiveY = 2, + DkSwizzle_NegativeY = 3, + DkSwizzle_PositiveZ = 4, + DkSwizzle_NegativeZ = 5, + DkSwizzle_PositiveW = 6, + DkSwizzle_NegativeW = 7, +} DkSwizzle; + +typedef struct DkViewportSwizzle +{ + DkSwizzle x; + DkSwizzle y; + DkSwizzle z; + DkSwizzle w; +} DkViewportSwizzle; + +typedef struct DkScissor +{ + uint32_t x; + uint32_t y; + uint32_t width; + uint32_t height; +} DkScissor; + +typedef enum DkPolygonMode +{ + DkPolygonMode_Point = 0, + DkPolygonMode_Line = 1, + DkPolygonMode_Fill = 2, +} DkPolygonMode; + +enum +{ + DkPolygonFlag_Point = 1U << DkPolygonMode_Point, + DkPolygonFlag_Line = 1U << DkPolygonMode_Line, + DkPolygonFlag_Fill = 1U << DkPolygonMode_Fill, + + DkPolygonFlag_All = DkPolygonFlag_Point|DkPolygonFlag_Line|DkPolygonFlag_Fill, +}; + +typedef enum DkFace +{ + DkFace_None = 0, + DkFace_Front = 1, + DkFace_Back = 2, + DkFace_FrontAndBack = 3, +} DkFace; + +typedef enum DkFrontFace +{ + DkFrontFace_CW = 0, + DkFrontFace_CCW = 1, +} DkFrontFace; + +typedef struct DkRasterizerState +{ + uint32_t rasterizerEnable : 1; + uint32_t depthClampEnable : 1; + uint32_t fillRectangleEnable : 1; + DkPolygonMode polygonModeFront : 2; + DkPolygonMode polygonModeBack : 2; + DkFace cullMode : 2; + DkFrontFace frontFace : 1; + uint32_t polygonSmoothEnableMask : 3; + uint32_t depthBiasEnableMask : 3; +} DkRasterizerState; + +DK_CONSTEXPR void dkRasterizerStateDefaults(DkRasterizerState* state) +{ + state->rasterizerEnable = 1; + state->depthClampEnable = 0; + state->fillRectangleEnable = 0; + state->polygonModeFront = DkPolygonMode_Fill; + state->polygonModeBack = DkPolygonMode_Fill; + state->cullMode = DkFace_Back; + state->frontFace = DkFrontFace_CCW; + state->polygonSmoothEnableMask = 0; + state->depthBiasEnableMask = 0; +} + +typedef enum DkCoverageModulation +{ + DkCoverageModulation_None = 0, + DkCoverageModulation_Rgb = 1, + DkCoverageModulation_Alpha = 2, + DkCoverageModulation_Rgba = 3, +} DkCoverageModulation; + +typedef struct DkMultisampleState +{ + DkMsMode mode : 3; + DkMsMode rasterizerMode : 3; + uint32_t alphaToCoverageEnable : 1; + uint32_t alphaToCoverageDither : 1; + uint32_t coverageToColorEnable : 1; + uint32_t coverageToColorOutput : 3; + DkCoverageModulation coverageModulation : 2; + uint32_t : 18; + + uint32_t sampleLocations[4]; +} DkMultisampleState; + +DK_CONSTEXPR void dkMultisampleStateDefaults(DkMultisampleState* state) +{ + state->mode = DkMsMode_1x; + state->rasterizerMode = DkMsMode_1x; + state->alphaToCoverageEnable = false; + state->alphaToCoverageDither = true; + state->coverageToColorEnable = false; + state->coverageToColorOutput = 0; + state->coverageModulation = DkCoverageModulation_None; + state->sampleLocations[0] = 0x88888888; + state->sampleLocations[1] = 0x88888888; + state->sampleLocations[2] = 0x88888888; + state->sampleLocations[3] = 0x88888888; +} + +typedef struct DkSampleLocation +{ + float x; + float y; +} DkSampleLocation; + +typedef enum DkLogicOp +{ + DkLogicOp_Clear = 0, + DkLogicOp_And = 1, + DkLogicOp_AndReverse = 2, + DkLogicOp_Copy = 3, + DkLogicOp_AndInverted = 4, + DkLogicOp_NoOp = 5, + DkLogicOp_Xor = 6, + DkLogicOp_Or = 7, + DkLogicOp_Nor = 8, + DkLogicOp_Equivalent = 9, + DkLogicOp_Invert = 10, + DkLogicOp_OrReverse = 11, + DkLogicOp_CopyInverted = 12, + DkLogicOp_OrInverted = 13, + DkLogicOp_Nand = 14, + DkLogicOp_Set = 15, +} DkLogicOp; + +typedef struct DkColorState +{ + uint32_t blendEnableMask : 8; + DkLogicOp logicOp : 8; + DkCompareOp alphaCompareOp : 4; + uint32_t : 12; +} DkColorState; + +DK_CONSTEXPR void dkColorStateDefaults(DkColorState* state) +{ + state->blendEnableMask = 0x00; + state->logicOp = DkLogicOp_Copy; + state->alphaCompareOp = DkCompareOp_Always; +} + +DK_CONSTEXPR void dkColorStateSetBlendEnable(DkColorState* state, uint32_t id, bool enable) +{ + if (enable) + state->blendEnableMask |= 1U << id; + else + state->blendEnableMask &= ~(1U << id); +} + +enum +{ + DkColorMask_R = 1U << 0, + DkColorMask_G = 1U << 1, + DkColorMask_B = 1U << 2, + DkColorMask_A = 1U << 3, + + DkColorMask_RGB = DkColorMask_R|DkColorMask_G|DkColorMask_B, + DkColorMask_RGBA = DkColorMask_R|DkColorMask_G|DkColorMask_B|DkColorMask_A, +}; + +typedef struct DkColorWriteState +{ + uint32_t masks; +} DkColorWriteState; + +DK_CONSTEXPR void dkColorWriteStateDefaults(DkColorWriteState* state) +{ + state->masks = 0xFFFFFFFF; +} + +DK_CONSTEXPR void dkColorWriteStateSetMask(DkColorWriteState* state, uint32_t id, uint32_t colorWriteMask) +{ + state->masks &= ~(0xF << (id*4)); + state->masks |= (colorWriteMask&0xF) << (id*4); +} + +typedef enum DkBlendOp +{ + DkBlendOp_Add = 1, + DkBlendOp_Sub = 2, + DkBlendOp_RevSub = 3, + DkBlendOp_Min = 4, + DkBlendOp_Max = 5, +} DkBlendOp; + +typedef enum DkBlendFactor +{ + DkBlendFactor_Zero = 1, + DkBlendFactor_One = 2, + DkBlendFactor_SrcColor = 3, + DkBlendFactor_InvSrcColor = 4, + DkBlendFactor_SrcAlpha = 5, + DkBlendFactor_InvSrcAlpha = 6, + DkBlendFactor_DstAlpha = 7, + DkBlendFactor_InvDstAlpha = 8, + DkBlendFactor_DstColor = 9, + DkBlendFactor_InvDstColor = 10, + DkBlendFactor_SrcAlphaSaturate = 11, + DkBlendFactor_Src1Color = 16, + DkBlendFactor_InvSrc1Color = 17, + DkBlendFactor_Src1Alpha = 18, + DkBlendFactor_InvSrc1Alpha = 19, + DkBlendFactor_ConstColor = 1|0x20, + DkBlendFactor_InvConstColor = 2|0x20, + DkBlendFactor_ConstAlpha = 3|0x20, + DkBlendFactor_InvConstAlpha = 4|0x20, +} DkBlendFactor; + +typedef struct DkBlendState +{ + DkBlendOp colorBlendOp : 3; + DkBlendFactor srcColorBlendFactor : 6; + DkBlendFactor dstColorBlendFactor : 6; + + DkBlendOp alphaBlendOp : 3; + DkBlendFactor srcAlphaBlendFactor : 6; + DkBlendFactor dstAlphaBlendFactor : 6; +} DkBlendState; + +DK_CONSTEXPR void dkBlendStateDefaults(DkBlendState* state) +{ + state->colorBlendOp = DkBlendOp_Add; + state->srcColorBlendFactor = DkBlendFactor_SrcAlpha; + state->dstColorBlendFactor = DkBlendFactor_InvSrcAlpha; + + state->alphaBlendOp = DkBlendOp_Add; + state->srcAlphaBlendFactor = DkBlendFactor_One; + state->dstAlphaBlendFactor = DkBlendFactor_Zero; +} + +DK_CONSTEXPR void dkBlendStateSetOps(DkBlendState* state, DkBlendOp colorBlendOp, DkBlendOp alphaBlendOp) +{ + state->colorBlendOp = colorBlendOp; + state->alphaBlendOp = alphaBlendOp; +} + +DK_CONSTEXPR void dkBlendStateSetFactors(DkBlendState* state, DkBlendFactor srcColorBlendFactor, DkBlendFactor dstColorBlendFactor, DkBlendFactor srcAlphaBlendFactor, DkBlendFactor dstAlphaBlendFactor) +{ + state->srcColorBlendFactor = srcColorBlendFactor; + state->dstColorBlendFactor = dstColorBlendFactor; + state->srcAlphaBlendFactor = srcAlphaBlendFactor; + state->dstAlphaBlendFactor = dstAlphaBlendFactor; +} + +typedef enum DkStencilOp +{ + DkStencilOp_Keep = 1, + DkStencilOp_Zero = 2, + DkStencilOp_Replace = 3, + DkStencilOp_Incr = 4, + DkStencilOp_Decr = 5, + DkStencilOp_Invert = 6, + DkStencilOp_IncrWrap = 7, + DkStencilOp_DecrWrap = 8, +} DkStencilOp; + +typedef struct DkDepthStencilState +{ + uint32_t depthTestEnable : 1; + uint32_t depthWriteEnable : 1; + uint32_t stencilTestEnable : 1; + uint32_t : 1; + DkCompareOp depthCompareOp : 4; + uint32_t : 24; + + DkStencilOp stencilFrontFailOp : 4; + DkStencilOp stencilFrontPassOp : 4; + DkStencilOp stencilFrontDepthFailOp : 4; + DkCompareOp stencilFrontCompareOp : 4; + DkStencilOp stencilBackFailOp : 4; + DkStencilOp stencilBackPassOp : 4; + DkStencilOp stencilBackDepthFailOp : 4; + DkCompareOp stencilBackCompareOp : 4; +} DkDepthStencilState; + +DK_CONSTEXPR void dkDepthStencilStateDefaults(DkDepthStencilState* state) +{ + state->depthTestEnable = true; + state->depthWriteEnable = true; + state->stencilTestEnable = false; + state->depthCompareOp = DkCompareOp_Less; + + state->stencilFrontFailOp = DkStencilOp_Keep; + state->stencilFrontPassOp = DkStencilOp_Replace; + state->stencilFrontDepthFailOp = DkStencilOp_Keep; + state->stencilFrontCompareOp = DkCompareOp_Always; + + state->stencilBackFailOp = DkStencilOp_Keep; + state->stencilBackPassOp = DkStencilOp_Replace; + state->stencilBackDepthFailOp = DkStencilOp_Keep; + state->stencilBackCompareOp = DkCompareOp_Always; +} + +typedef enum DkTiledCacheOp +{ + DkTiledCacheOp_Disable = 0, + DkTiledCacheOp_Enable = 1, + DkTiledCacheOp_Flush = 2, + DkTiledCacheOp_FlushAlt = 3, + DkTiledCacheOp_UnkDisable = 4, + DkTiledCacheOp_UnkEnable = 5, +} DkTiledCacheOp; + +typedef enum DkVtxAttribSize +{ + // One to four 32-bit components + DkVtxAttribSize_1x32 = 0x12, + DkVtxAttribSize_2x32 = 0x04, + DkVtxAttribSize_3x32 = 0x02, + DkVtxAttribSize_4x32 = 0x01, + + // One to four 16-bit components + DkVtxAttribSize_1x16 = 0x1b, + DkVtxAttribSize_2x16 = 0x0f, + DkVtxAttribSize_3x16 = 0x05, + DkVtxAttribSize_4x16 = 0x03, + + // One to four 8-bit components + DkVtxAttribSize_1x8 = 0x1d, + DkVtxAttribSize_2x8 = 0x18, + DkVtxAttribSize_3x8 = 0x13, + DkVtxAttribSize_4x8 = 0x0a, + + // Misc arrangements + DkVtxAttribSize_10_10_10_2 = 0x30, + DkVtxAttribSize_11_11_10 = 0x31, +} DkVtxAttribSize; + +typedef enum DkVtxAttribType +{ + DkVtxAttribType_None = 0, + DkVtxAttribType_Snorm = 1, + DkVtxAttribType_Unorm = 2, + DkVtxAttribType_Sint = 3, + DkVtxAttribType_Uint = 4, + DkVtxAttribType_Uscaled = 5, + DkVtxAttribType_Sscaled = 6, + DkVtxAttribType_Float = 7, +} DkVtxAttribType; + +typedef struct DkVtxAttribState +{ + uint32_t bufferId : 5; + uint32_t : 1; + uint32_t isFixed : 1; + uint32_t offset : 14; + DkVtxAttribSize size : 6; + DkVtxAttribType type : 3; + uint32_t : 1; + uint32_t isBgra : 1; +} DkVtxAttribState; + +typedef struct DkVtxBufferState +{ + uint32_t stride; + uint32_t divisor; +} DkVtxBufferState; + +typedef enum DkPrimitive +{ + DkPrimitive_Points = 0, + DkPrimitive_Lines = 1, + DkPrimitive_LineLoop = 2, + DkPrimitive_LineStrip = 3, + DkPrimitive_Triangles = 4, + DkPrimitive_TriangleStrip = 5, + DkPrimitive_TriangleFan = 6, + DkPrimitive_Quads = 7, + DkPrimitive_QuadStrip = 8, + DkPrimitive_Polygon = 9, + DkPrimitive_LinesAdjacency = 10, + DkPrimitive_LineStripAdjacency = 11, + DkPrimitive_TrianglesAdjacency = 12, + DkPrimitive_TriangleStripAdjacency = 13, + DkPrimitive_Patches = 14, +} DkPrimitive; + +typedef enum DkIdxFormat +{ + DkIdxFormat_Uint8 = 0, + DkIdxFormat_Uint16 = 1, + DkIdxFormat_Uint32 = 2, +} DkIdxFormat; + +typedef struct DkDrawIndirectData +{ + uint32_t vertexCount; + uint32_t instanceCount; + uint32_t firstVertex; + uint32_t firstInstance; +} DkDrawIndirectData; + +typedef struct DkDrawIndexedIndirectData +{ + uint32_t indexCount; + uint32_t instanceCount; + uint32_t firstIndex; + int32_t vertexOffset; + uint32_t firstInstance; +} DkDrawIndexedIndirectData; + +typedef struct DkDispatchIndirectData +{ + uint32_t numGroupsX; + uint32_t numGroupsY; + uint32_t numGroupsZ; +} DkDispatchIndirectData; + +enum +{ + // Flip bits (for all) + DkBlitFlag_Flip_Mask = 7U << 0, + DkBlitFlag_FlipX = 1U << 0, // only for BlitImage and CopyDataToImage + DkBlitFlag_FlipY = 1U << 1, + DkBlitFlag_FlipZ = 1U << 2, + + // Filter mode (for BlitImage) + DkBlitFlag_Filter_Mask = 1U << 4, + DkBlitFlag_FilterNearest = 0U << 4, + DkBlitFlag_FilterLinear = 1U << 4, + + // Blit mode (for BlitImage) + DkBlitFlag_Mode_Mask = 7U << 5, + DkBlitFlag_ModeBlit = 0U << 5, + DkBlitFlag_ModeAlphaMask = 1U << 5, + DkBlitFlag_ModeAlphaBlend = 2U << 5, + DkBlitFlag_ModePremultBlit = 3U << 5, + DkBlitFlag_ModePremultBlend = 4U << 5, +}; + +typedef struct DkImageRect +{ + uint32_t x; + uint32_t y; + uint32_t z; + uint32_t width; + uint32_t height; + uint32_t depth; +} DkImageRect; + +typedef struct DkCopyBuf +{ + DkGpuAddr addr; + uint32_t rowLength; + uint32_t imageHeight; +} DkCopyBuf; + +typedef struct DkSwapchainMaker +{ + DkDevice device; + void* nativeWindow; + DkImage const* const* pImages; + uint32_t numImages; +} DkSwapchainMaker; + +DK_CONSTEXPR void dkSwapchainMakerDefaults(DkSwapchainMaker* maker, DkDevice device, void* nativeWindow, DkImage const* const pImages[], uint32_t numImages) +{ + maker->device = device; + maker->nativeWindow = nativeWindow; + maker->pImages = pImages; + maker->numImages = numImages; +} + +#ifdef __cplusplus +extern "C" { +#endif + +DkDevice dkDeviceCreate(DkDeviceMaker const* maker); +void dkDeviceDestroy(DkDevice obj); + +DkMemBlock dkMemBlockCreate(DkMemBlockMaker const* maker); +void dkMemBlockDestroy(DkMemBlock obj); +void* dkMemBlockGetCpuAddr(DkMemBlock obj); +DkGpuAddr dkMemBlockGetGpuAddr(DkMemBlock obj); +uint32_t dkMemBlockGetSize(DkMemBlock obj); +DkResult dkMemBlockFlushCpuCache(DkMemBlock obj, uint32_t offset, uint32_t size); + +DkResult dkFenceWait(DkFence* obj, int64_t timeout_ns); + +DkCmdBuf dkCmdBufCreate(DkCmdBufMaker const* maker); +void dkCmdBufDestroy(DkCmdBuf obj); +void dkCmdBufAddMemory(DkCmdBuf obj, DkMemBlock mem, uint32_t offset, uint32_t size); +DkCmdList dkCmdBufFinishList(DkCmdBuf obj); +void dkCmdBufClear(DkCmdBuf obj); +void dkCmdBufBeginCaptureCmds(DkCmdBuf obj, uint32_t* storage, uint32_t max_words); +uint32_t dkCmdBufEndCaptureCmds(DkCmdBuf obj); +void dkCmdBufReplayCmds(DkCmdBuf obj, const uint32_t* words, uint32_t num_words); +void dkCmdBufCallList(DkCmdBuf obj, DkCmdList list); +void dkCmdBufWaitFence(DkCmdBuf obj, DkFence* fence); +void dkCmdBufSignalFence(DkCmdBuf obj, DkFence* fence, bool flush); +void dkCmdBufBarrier(DkCmdBuf obj, DkBarrier mode, uint32_t invalidateFlags); +void dkCmdBufBindShaders(DkCmdBuf obj, uint32_t stageMask, DkShader const* const shaders[], uint32_t numShaders); +void dkCmdBufBindUniformBuffers(DkCmdBuf obj, DkStage stage, uint32_t firstId, DkBufExtents const buffers[], uint32_t numBuffers); +void dkCmdBufBindStorageBuffers(DkCmdBuf obj, DkStage stage, uint32_t firstId, DkBufExtents const buffers[], uint32_t numBuffers); +void dkCmdBufBindTextures(DkCmdBuf obj, DkStage stage, uint32_t firstId, DkResHandle const handles[], uint32_t numHandles); +void dkCmdBufBindImages(DkCmdBuf obj, DkStage stage, uint32_t firstId, DkResHandle const handles[], uint32_t numHandles); +void dkCmdBufBindImageDescriptorSet(DkCmdBuf obj, DkGpuAddr setAddr, uint32_t numDescriptors); +void dkCmdBufBindSamplerDescriptorSet(DkCmdBuf obj, DkGpuAddr setAddr, uint32_t numDescriptors); +void dkCmdBufBindRenderTargets(DkCmdBuf obj, DkImageView const* const colorTargets[], uint32_t numColorTargets, DkImageView const* depthTarget); +void dkCmdBufBindRasterizerState(DkCmdBuf obj, DkRasterizerState const* state); +void dkCmdBufBindMultisampleState(DkCmdBuf obj, DkMultisampleState const* state); +void dkCmdBufBindColorState(DkCmdBuf obj, DkColorState const* state); +void dkCmdBufBindColorWriteState(DkCmdBuf obj, DkColorWriteState const* state); +void dkCmdBufBindBlendStates(DkCmdBuf obj, uint32_t firstId, DkBlendState const states[], uint32_t numStates); +void dkCmdBufBindDepthStencilState(DkCmdBuf obj, DkDepthStencilState const* state); +void dkCmdBufBindVtxAttribState(DkCmdBuf obj, DkVtxAttribState const attribs[], uint32_t numAttribs); +void dkCmdBufBindVtxBufferState(DkCmdBuf obj, DkVtxBufferState const buffers[], uint32_t numBuffers); +void dkCmdBufBindVtxBuffers(DkCmdBuf obj, uint32_t firstId, DkBufExtents const buffers[], uint32_t numBuffers); +void dkCmdBufBindIdxBuffer(DkCmdBuf obj, DkIdxFormat format, DkGpuAddr address); +void dkCmdBufSetViewports(DkCmdBuf obj, uint32_t firstId, DkViewport const viewports[], uint32_t numViewports); +void dkCmdBufSetViewportSwizzles(DkCmdBuf obj, uint32_t firstId, DkViewportSwizzle const swizzles[], uint32_t numSwizzles); +void dkCmdBufSetSubpixelPrecisionBias(DkCmdBuf obj, uint32_t xbits, uint32_t ybits); +void dkCmdBufSetScissors(DkCmdBuf obj, uint32_t firstId, DkScissor const scissors[], uint32_t numScissors); +void dkCmdBufSetDepthBias(DkCmdBuf obj, float constantFactor, float clamp, float slopeFactor); +void dkCmdBufSetPointSize(DkCmdBuf obj, float size); +void dkCmdBufSetLineWidth(DkCmdBuf obj, float width); +void dkCmdBufSetConservativeRasterEnable(DkCmdBuf obj, bool enable); +void dkCmdBufSetConservativeRasterDilate(DkCmdBuf obj, float dilate); +void dkCmdBufSetSampleMask(DkCmdBuf obj, uint32_t mask); +void dkCmdBufSetCoverageModulationTable(DkCmdBuf obj, float const table[16]); +void dkCmdBufSetDepthBounds(DkCmdBuf obj, bool enable, float near, float far); +void dkCmdBufSetAlphaRef(DkCmdBuf obj, float ref); +void dkCmdBufSetBlendConst(DkCmdBuf obj, float red, float green, float blue, float alpha); +void dkCmdBufSetStencil(DkCmdBuf obj, DkFace face, uint8_t mask, uint8_t funcRef, uint8_t funcMask); +void dkCmdBufSetPrimitiveRestart(DkCmdBuf obj, bool enable, uint32_t index); +void dkCmdBufSetPatchSize(DkCmdBuf obj, uint32_t size); +void dkCmdBufSetTessOuterLevels(DkCmdBuf obj, float level0, float level1, float level2, float level3); +void dkCmdBufSetTessInnerLevels(DkCmdBuf obj, float level0, float level1); +void dkCmdBufSetTileSize(DkCmdBuf obj, uint32_t width, uint32_t height); +void dkCmdBufTiledCacheOp(DkCmdBuf obj, DkTiledCacheOp op); +void dkCmdBufClearColor(DkCmdBuf obj, uint32_t targetId, uint32_t clearMask, const void* clearData); +void dkCmdBufClearDepthStencil(DkCmdBuf obj, bool clearDepth, float depthValue, uint8_t stencilMask, uint8_t stencilValue); +void dkCmdBufDiscardColor(DkCmdBuf obj, uint32_t targetId); +void dkCmdBufDiscardDepthStencil(DkCmdBuf obj); +void dkCmdBufResolveDepthValues(DkCmdBuf obj); +void dkCmdBufDraw(DkCmdBuf obj, DkPrimitive prim, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance); +void dkCmdBufDrawIndirect(DkCmdBuf obj, DkPrimitive prim, DkGpuAddr indirect); +void dkCmdBufDrawIndexed(DkCmdBuf obj, DkPrimitive prim, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance); +void dkCmdBufDrawIndexedIndirect(DkCmdBuf obj, DkPrimitive prim, DkGpuAddr indirect); +void dkCmdBufDispatchCompute(DkCmdBuf obj, uint32_t numGroupsX, uint32_t numGroupsY, uint32_t numGroupsZ); +void dkCmdBufDispatchComputeIndirect(DkCmdBuf obj, DkGpuAddr indirect); +void dkCmdBufPushConstants(DkCmdBuf obj, DkGpuAddr uboAddr, uint32_t uboSize, uint32_t offset, uint32_t size, const void* data); +void dkCmdBufPushData(DkCmdBuf obj, DkGpuAddr addr, const void* data, uint32_t size); +void dkCmdBufCopyBuffer(DkCmdBuf obj, DkGpuAddr srcAddr, DkGpuAddr dstAddr, uint32_t size); +void dkCmdBufCopyImage(DkCmdBuf obj, DkImageView const* srcView, DkImageRect const* srcRect, DkImageView const* dstView, DkImageRect const* dstRect, uint32_t flags); +void dkCmdBufBlitImage(DkCmdBuf obj, DkImageView const* srcView, DkImageRect const* srcRect, DkImageView const* dstView, DkImageRect const* dstRect, uint32_t flags, uint32_t factor); +void dkCmdBufResolveImage(DkCmdBuf obj, DkImageView const* srcView, DkImageView const* dstView); +void dkCmdBufCopyBufferToImage(DkCmdBuf obj, DkCopyBuf const* src, DkImageView const* dstView, DkImageRect const* dstRect, uint32_t flags); +void dkCmdBufCopyImageToBuffer(DkCmdBuf obj, DkImageView const* srcView, DkImageRect const* srcRect, DkCopyBuf const* dst, uint32_t flags); + +DkQueue dkQueueCreate(DkQueueMaker const* maker); +void dkQueueDestroy(DkQueue obj); +bool dkQueueIsInErrorState(DkQueue obj); +void dkQueueWaitFence(DkQueue obj, DkFence* fence); +void dkQueueSignalFence(DkQueue obj, DkFence* fence, bool flush); +void dkQueueSubmitCommands(DkQueue obj, DkCmdList cmds); +void dkQueueFlush(DkQueue obj); +void dkQueueWaitIdle(DkQueue obj); +int dkQueueAcquireImage(DkQueue obj, DkSwapchain swapchain); +void dkQueuePresentImage(DkQueue obj, DkSwapchain swapchain, int imageSlot); + +void dkShaderInitialize(DkShader* obj, DkShaderMaker const* maker); +bool dkShaderIsValid(DkShader const* obj); +DkStage dkShaderGetStage(DkShader const* obj); + +void dkImageLayoutInitialize(DkImageLayout* obj, DkImageLayoutMaker const* maker); +uint64_t dkImageLayoutGetSize(DkImageLayout const* obj); +uint32_t dkImageLayoutGetAlignment(DkImageLayout const* obj); + +void dkImageInitialize(DkImage* obj, DkImageLayout const* layout, DkMemBlock memBlock, uint32_t offset); +DkGpuAddr dkImageGetGpuAddr(DkImage const* obj); + +void dkImageDescriptorInitialize(DkImageDescriptor* obj, DkImageView const* view, bool usesLoadOrStore, bool decayMS); + +void dkSamplerDescriptorInitialize(DkSamplerDescriptor* obj, DkSampler const* sampler); + +void dkMultisampleStateSetLocations(DkMultisampleState* obj, DkSampleLocation const* locations, uint32_t numLocations); + +DkSwapchain dkSwapchainCreate(DkSwapchainMaker const* maker); +void dkSwapchainDestroy(DkSwapchain obj); +void dkSwapchainAcquireImage(DkSwapchain obj, int* imageSlot, DkFence* fence); +void dkSwapchainSetCrop(DkSwapchain obj, int32_t left, int32_t top, int32_t right, int32_t bottom); +void dkSwapchainSetSwapInterval(DkSwapchain obj, uint32_t interval); + +static inline void dkCmdBufBindUniformBuffer(DkCmdBuf obj, DkStage stage, uint32_t id, DkGpuAddr bufAddr, uint32_t bufSize) +{ + DkBufExtents ext = { bufAddr, bufSize }; + dkCmdBufBindUniformBuffers(obj, stage, id, &ext, 1); +} + +static inline void dkCmdBufBindStorageBuffer(DkCmdBuf obj, DkStage stage, uint32_t id, DkGpuAddr bufAddr, uint32_t bufSize) +{ + DkBufExtents ext = { bufAddr, bufSize }; + dkCmdBufBindStorageBuffers(obj, stage, id, &ext, 1); +} + +static inline void dkCmdBufBindTexture(DkCmdBuf obj, DkStage stage, uint32_t id, DkResHandle handle) +{ + dkCmdBufBindTextures(obj, stage, id, &handle, 1); +} + +static inline void dkCmdBufBindImage(DkCmdBuf obj, DkStage stage, uint32_t id, DkResHandle handle) +{ + dkCmdBufBindImages(obj, stage, id, &handle, 1); +} + +static inline void dkCmdBufBindRenderTarget(DkCmdBuf obj, DkImageView const* colorTarget, DkImageView const* depthTarget) +{ + dkCmdBufBindRenderTargets(obj, &colorTarget, 1, depthTarget); +} + +static inline void dkCmdBufBindBlendState(DkCmdBuf obj, uint32_t id, DkBlendState const* state) +{ + dkCmdBufBindBlendStates(obj, id, state, 1); +} + +static inline void dkCmdBufBindVtxBuffer(DkCmdBuf obj, uint32_t id, DkGpuAddr bufAddr, uint32_t bufSize) +{ + DkBufExtents ext = { bufAddr, bufSize }; + dkCmdBufBindVtxBuffers(obj, id, &ext, 1); +} + +static inline void dkCmdBufClearColorFloat(DkCmdBuf obj, uint32_t targetId, uint32_t clearMask, float red, float green, float blue, float alpha) +{ + float data[] = { red, green, blue, alpha }; + dkCmdBufClearColor(obj, targetId, clearMask, data); +} + +static inline void dkCmdBufClearColorSint(DkCmdBuf obj, uint32_t targetId, uint32_t clearMask, int32_t red, int32_t green, int32_t blue, int32_t alpha) +{ + int32_t data[] = { red, green, blue, alpha }; + dkCmdBufClearColor(obj, targetId, clearMask, data); +} + +static inline void dkCmdBufClearColorUint(DkCmdBuf obj, uint32_t targetId, uint32_t clearMask, uint32_t red, uint32_t green, uint32_t blue, uint32_t alpha) +{ + uint32_t data[] = { red, green, blue, alpha }; + dkCmdBufClearColor(obj, targetId, clearMask, data); +} + +static inline DkImageLayout const* dkImageGetLayout(DkImage const* obj) +{ + return (DkImageLayout const*)obj; +} + +#ifdef __cplusplus +} +#endif diff --git a/troposphere/daybreak/nanovg/include/deko3d.hpp b/troposphere/daybreak/nanovg/include/deko3d.hpp new file mode 100644 index 000000000..022138fa8 --- /dev/null +++ b/troposphere/daybreak/nanovg/include/deko3d.hpp @@ -0,0 +1,1108 @@ +/* +**----------------------------------------------------------------------------- +** deko3d.hpp - C++ wrapper interface for deko3d +**----------------------------------------------------------------------------- +** +** Copyright (C) 2018-2020 fincs +** +** This software is provided 'as-is', without any express or implied +** warranty. In no event will the authors be held liable for any +** damages arising from the use of this software. +** +** Permission is granted to anyone to use this software for any +** purpose, including commercial applications, and to alter it and +** redistribute it freely, subject to the following restrictions: +** +** 1. The origin of this software must not be misrepresented; you +** must not claim that you wrote the original software. If you use +** this software in a product, an acknowledgment in the product +** documentation would be appreciated but is not required. +** 2. Altered source versions must be plainly marked as such, and +** must not be misrepresented as being the original software. +** 3. This notice may not be removed or altered from any source +** distribution. +** +** This file is currently written by hand; in the future it might be autogenerated. +** +*/ + +#pragma once +#include +#include +#include +#ifdef DK_HPP_SUPPORT_VECTOR +#include +#endif +#include "deko3d.h" + +namespace dk +{ + namespace detail + { + template + class Handle + { + T m_handle; + protected: + void _clear() noexcept { m_handle = nullptr; } + void _set(T h) noexcept { _clear(); m_handle = h; } + public: + using Type = T; + constexpr Handle() noexcept : m_handle{} { } + constexpr Handle(std::nullptr_t) noexcept : m_handle{} { } + constexpr Handle(T handle) noexcept : m_handle{handle} { } + constexpr operator T() const noexcept { return m_handle; } + constexpr operator bool() const noexcept { return m_handle != nullptr; } + constexpr bool operator !() const noexcept { return m_handle == nullptr; } + }; + + template + constexpr bool operator==(Handle const& lhs, Handle const& rhs) + { + return static_cast(lhs) == static_cast(rhs); + } + + template + constexpr bool operator!=(Handle const& lhs, Handle const& rhs) + { + return !(lhs == rhs); + } + + template + struct UniqueHandle final : public T + { + UniqueHandle() noexcept : T{} { } + UniqueHandle(UniqueHandle&) = delete; + constexpr UniqueHandle(T&& rhs) noexcept : T{rhs} { rhs = nullptr; } + ~UniqueHandle() + { + if (*this) T::destroy(); + } + UniqueHandle& operator=(std::nullptr_t) { if (*this) T::destroy(); return *this; } + UniqueHandle& operator=(UniqueHandle const&) = delete; + UniqueHandle& operator=(UniqueHandle&& rhs) { T::_set(rhs); rhs._clear(); return *this; } + }; + + template + struct Opaque : public T + { + constexpr Opaque() noexcept : T{} { } + }; + + // ArrayProxy borrowed from Vulkan-Hpp with ♥ + template + class ArrayProxy + { + using nonconst_T = typename std::remove_const::type; + using nonref_T = typename std::remove_reference::type; + uint32_t m_count; + T* m_ptr; + public: + constexpr ArrayProxy(std::nullptr_t) noexcept : m_count{}, m_ptr{} { } + ArrayProxy(nonref_T& ptr) : m_count{1}, m_ptr(&ptr) { } + ArrayProxy(uint32_t count, T* ptr) noexcept : m_count{count}, m_ptr{ptr} { } + + template + ArrayProxy(std::array& data) noexcept : + m_count{N}, m_ptr{data.data()} { } + + template + ArrayProxy(std::array const& data) noexcept : + m_count{N} , m_ptr{data.data()} { } + + ArrayProxy(std::initializer_list const& data) noexcept : + m_count{static_cast(data.end() - data.begin())}, + m_ptr{data.begin()} { } + +#ifdef DK_HPP_SUPPORT_VECTOR + template > + ArrayProxy(std::vector & data) noexcept : + m_count{static_cast(data.size())}, + m_ptr{data.data()} { } + + template > + ArrayProxy(std::vector const& data) noexcept : + m_count{static_cast(data.size())}, + m_ptr{data.data()} { } +#endif + + const T* begin() const noexcept { return m_ptr; } + const T* end() const noexcept { return m_ptr + m_count; } + const T& front() const noexcept { return *m_ptr; } + const T& back() const noexcept { return *(m_ptr + m_count - 1); } + bool empty() const noexcept { return m_count == 0; } + uint32_t size() const noexcept { return m_count; } + T* data() const noexcept { return m_ptr; } + }; + } + +#define DK_HANDLE_COMMON_MEMBERS(_name) \ + constexpr _name() noexcept : Handle{} { } \ + constexpr _name(std::nullptr_t arg) noexcept : Handle{arg} { } \ + constexpr _name(::Dk##_name arg) noexcept : Handle{arg} { } \ + _name& operator=(std::nullptr_t) noexcept { _clear(); return *this; } \ + void destroy() + +#define DK_OPAQUE_COMMON_MEMBERS(_name) \ + constexpr _name() noexcept : Opaque{} { } + + struct Device : public detail::Handle<::DkDevice> + { + DK_HANDLE_COMMON_MEMBERS(Device); + }; + + struct MemBlock : public detail::Handle<::DkMemBlock> + { + DK_HANDLE_COMMON_MEMBERS(MemBlock); + void* getCpuAddr(); + DkGpuAddr getGpuAddr(); + uint32_t getSize(); + DkResult flushCpuCache(uint32_t offset, uint32_t size); + }; + + struct Fence : public detail::Opaque<::DkFence> + { + DK_OPAQUE_COMMON_MEMBERS(Fence); + DkResult wait(int64_t timeout_ns = -1); + }; + + struct CmdBuf : public detail::Handle<::DkCmdBuf> + { + DK_HANDLE_COMMON_MEMBERS(CmdBuf); + void addMemory(DkMemBlock mem, uint32_t offset, uint32_t size); + DkCmdList finishList(); + void clear(); + void beginCaptureCmds(uint32_t* storage, uint32_t max_words); + uint32_t endCaptureCmds(); + void replayCmds(detail::ArrayProxy words); + void callList(DkCmdList list); + void waitFence(DkFence& fence); + void signalFence(DkFence& fence, bool flush = false); + void barrier(DkBarrier mode, uint32_t invalidateFlags); + void bindShaders(uint32_t stageMask, detail::ArrayProxy shaders); + void bindUniformBuffer(DkStage stage, uint32_t id, DkGpuAddr bufAddr, uint32_t bufSize); + void bindUniformBuffers(DkStage stage, uint32_t firstId, detail::ArrayProxy buffers); + void bindStorageBuffer(DkStage stage, uint32_t id, DkGpuAddr bufAddr, uint32_t bufSize); + void bindStorageBuffers(DkStage stage, uint32_t firstId, detail::ArrayProxy buffers); + void bindTextures(DkStage stage, uint32_t firstId, detail::ArrayProxy handles); + void bindImages(DkStage stage, uint32_t firstId, detail::ArrayProxy handles); + void bindImageDescriptorSet(DkGpuAddr setAddr, uint32_t numDescriptors); + void bindSamplerDescriptorSet(DkGpuAddr setAddr, uint32_t numDescriptors); + void bindRenderTargets(detail::ArrayProxy colorTargets, DkImageView const* depthTarget = nullptr); + void bindRasterizerState(DkRasterizerState const& state); + void bindMultisampleState(DkMultisampleState const& state); + void bindColorState(DkColorState const& state); + void bindColorWriteState(DkColorWriteState const& state); + void bindBlendStates(uint32_t id, detail::ArrayProxy states); + void bindDepthStencilState(DkDepthStencilState const& state); + void bindVtxAttribState(detail::ArrayProxy attribs); + void bindVtxBufferState(detail::ArrayProxy buffers); + void bindVtxBuffer(uint32_t id, DkGpuAddr bufAddr, uint32_t bufSize); + void bindVtxBuffers(uint32_t firstId, detail::ArrayProxy buffers); + void bindIdxBuffer(DkIdxFormat format, DkGpuAddr address); + void setViewports(uint32_t firstId, detail::ArrayProxy viewports); + void setViewportSwizzles(uint32_t firstId, detail::ArrayProxy swizzles); + void setSubpixelPrecisionBias(uint32_t xbits, uint32_t ybits); + void setScissors(uint32_t firstId, detail::ArrayProxy scissors); + void setDepthBias(float constantFactor, float clamp, float slopeFactor); + void setPointSize(float size); + void setLineWidth(float width); + void setConservativeRasterEnable(bool enable); + void setConservativeRasterDilate(float dilate); + void setSampleMask(uint32_t mask); + void setCoverageModulationTable(float const table[16]); + void setDepthBounds(bool enable, float near, float far); + void setAlphaRef(float ref); + void setBlendConst(float red, float green, float blue, float alpha); + void setStencil(DkFace face, uint8_t mask, uint8_t funcRef, uint8_t funcMask); + void setPrimitiveRestart(bool enable, uint32_t index); + void setPatchSize(uint32_t size); + void setTessOuterLevels(float level0, float level1, float level2, float level3 = 0.0f); + void setTessInnerLevels(float level0, float level1 = 0.0f); + void setTileSize(uint32_t width, uint32_t height); + void tiledCacheOp(DkTiledCacheOp op); + void clearColor(uint32_t targetId, uint32_t clearMask, const void* clearData); + template void clearColor(uint32_t targetId, uint32_t clearMask, T red = T{0}, T green = T{0}, T blue = T{0}, T alpha = T{0}); + void clearDepthStencil(bool clearDepth, float depthValue, uint8_t stencilMask, uint8_t stencilValue); + void discardColor(uint32_t targetId); + void discardDepthStencil(); + void resolveDepthValues(); + void draw(DkPrimitive prim, uint32_t numVertices, uint32_t numInstances, uint32_t firstVertex, uint32_t firstInstance); + void drawIndirect(DkPrimitive prim, DkGpuAddr indirect); + void drawIndexed(DkPrimitive prim, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance); + void drawIndexedIndirect(DkPrimitive prim, DkGpuAddr indirect); + void dispatchCompute(uint32_t numGroupsX, uint32_t numGroupsY, uint32_t numGroupsZ); + void dispatchComputeIndirect(DkGpuAddr indirect); + void pushConstants(DkGpuAddr uboAddr, uint32_t uboSize, uint32_t offset, uint32_t size, const void* data); + void pushData(DkGpuAddr addr, const void* data, uint32_t size); + void copyBuffer(DkGpuAddr srcAddr, DkGpuAddr dstAddr, uint32_t size); + void copyImage(DkImageView const& srcView, DkImageRect const& srcRect, DkImageView const& dstView, DkImageRect const& dstRect, uint32_t flags = 0); + void blitImage(DkImageView const& srcView, DkImageRect const& srcRect, DkImageView const& dstView, DkImageRect const& dstRect, uint32_t flags = 0, uint32_t factor = 0); + void resolveImage(DkImageView const& srcView, DkImageView const& dstView); + void copyBufferToImage(DkCopyBuf const& src, DkImageView const& dstView, DkImageRect const& dstRect, uint32_t flags = 0); + void copyImageToBuffer(DkImageView const& srcView, DkImageRect const& srcRect, DkCopyBuf const& dst, uint32_t flags = 0); + }; + + struct Queue : public detail::Handle<::DkQueue> + { + DK_HANDLE_COMMON_MEMBERS(Queue); + bool isInErrorState(); + void waitFence(DkFence& fence); + void signalFence(DkFence& fence, bool flush = false); + void submitCommands(DkCmdList cmds); + void flush(); + void waitIdle(); + int acquireImage(DkSwapchain swapchain); + void presentImage(DkSwapchain swapchain, int imageSlot); + }; + + struct Shader : public detail::Opaque<::DkShader> + { + DK_OPAQUE_COMMON_MEMBERS(Shader); + bool isValid() const; + DkStage getStage() const; + }; + + struct ImageLayout : public detail::Opaque<::DkImageLayout> + { + DK_OPAQUE_COMMON_MEMBERS(ImageLayout); + uint64_t getSize() const; + uint32_t getAlignment() const; + }; + + struct Image : public detail::Opaque<::DkImage> + { + DK_OPAQUE_COMMON_MEMBERS(Image); + void initialize(ImageLayout const& layout, DkMemBlock memBlock, uint32_t offset); + DkGpuAddr getGpuAddr() const; + ImageLayout const& getLayout() const; + }; + + struct Swapchain : public detail::Handle<::DkSwapchain> + { + DK_HANDLE_COMMON_MEMBERS(Swapchain); + void acquireImage(int& imageSlot, DkFence& fence); + void setCrop(int32_t left, int32_t top, int32_t right, int32_t bottom); + void setSwapInterval(uint32_t interval); + }; + + struct DeviceMaker : public ::DkDeviceMaker + { + DeviceMaker() noexcept : DkDeviceMaker{} { ::dkDeviceMakerDefaults(this); } + DeviceMaker(DeviceMaker&) = default; + DeviceMaker(DeviceMaker&&) = default; + DeviceMaker& setUserData(void* userData) noexcept { this->userData = userData; return *this; } + DeviceMaker& setCbDebug(DkDebugFunc cbDebug) noexcept { this->cbDebug = cbDebug; return *this; } + DeviceMaker& setCbAlloc(DkAllocFunc cbAlloc) noexcept { this->cbAlloc = cbAlloc; return *this; } + DeviceMaker& setCbFree(DkFreeFunc cbFree) noexcept { this->cbFree = cbFree; return *this; } + DeviceMaker& setFlags(uint32_t flags) noexcept { this->flags = flags; return *this; } + Device create() const; + }; + + struct MemBlockMaker : public ::DkMemBlockMaker + { + MemBlockMaker(DkDevice device, uint32_t size) noexcept : DkMemBlockMaker{} { ::dkMemBlockMakerDefaults(this, device, size); } + MemBlockMaker(MemBlockMaker&) = default; + MemBlockMaker(MemBlockMaker&&) = default; + MemBlockMaker& setFlags(uint32_t flags) noexcept { this->flags = flags; return *this; } + MemBlockMaker& setStorage(void* storage) noexcept { this->storage = storage; return *this; } + MemBlock create() const; + }; + + struct CmdBufMaker : public ::DkCmdBufMaker + { + CmdBufMaker(DkDevice device) noexcept : DkCmdBufMaker{} { ::dkCmdBufMakerDefaults(this, device); } + CmdBufMaker& setUserData(void* userData) noexcept { this->userData = userData; return *this; } + CmdBufMaker& setCbAddMem(DkCmdBufAddMemFunc cbAddMem) noexcept { this->cbAddMem = cbAddMem; return *this; } + CmdBuf create() const; + }; + + struct QueueMaker : public ::DkQueueMaker + { + QueueMaker(DkDevice device) noexcept : DkQueueMaker{} { ::dkQueueMakerDefaults(this, device); } + QueueMaker& setFlags(uint32_t flags) noexcept { this->flags = flags; return *this; } + QueueMaker& setCommandMemorySize(uint32_t commandMemorySize) noexcept { this->commandMemorySize = commandMemorySize; return *this; } + QueueMaker& setFlushThreshold(uint32_t flushThreshold) noexcept { this->flushThreshold = flushThreshold; return *this; } + QueueMaker& setPerWarpScratchMemorySize(uint32_t perWarpScratchMemorySize) noexcept { this->perWarpScratchMemorySize = perWarpScratchMemorySize; return *this; } + QueueMaker& setMaxConcurrentComputeJobs(uint32_t maxConcurrentComputeJobs) noexcept { this->maxConcurrentComputeJobs = maxConcurrentComputeJobs; return *this; } + Queue create() const; + }; + + struct ShaderMaker : public ::DkShaderMaker + { + ShaderMaker(DkMemBlock codeMem, uint32_t codeOffset) noexcept : DkShaderMaker{} { ::dkShaderMakerDefaults(this, codeMem, codeOffset); } + ShaderMaker& setControl(const void* control) noexcept { this->control = control; return *this; } + ShaderMaker& setProgramId(uint32_t programId) noexcept { this->programId = programId; return *this; } + void initialize(Shader& obj) const; + }; + + struct ImageLayoutMaker : public ::DkImageLayoutMaker + { + ImageLayoutMaker(DkDevice device) noexcept : DkImageLayoutMaker{} { ::dkImageLayoutMakerDefaults(this, device); } + ImageLayoutMaker& setType(DkImageType type) noexcept { this->type = type; return *this; } + ImageLayoutMaker& setFlags(uint32_t flags) noexcept { this->flags = flags; return *this; } + ImageLayoutMaker& setFormat(DkImageFormat format) noexcept { this->format = format; return *this; } + ImageLayoutMaker& setMsMode(DkMsMode msMode) noexcept { this->msMode = msMode; return *this; } + ImageLayoutMaker& setDimensions(uint32_t width, uint32_t height = 0, uint32_t depth = 0) noexcept + { + this->dimensions[0] = width; + this->dimensions[1] = height; + this->dimensions[2] = depth; + return *this; + } + ImageLayoutMaker& setMipLevels(uint32_t mipLevels) noexcept { this->mipLevels = mipLevels; return *this; } + ImageLayoutMaker& setPitchStride(uint32_t pitchStride) noexcept { this->pitchStride = pitchStride; return *this; } + ImageLayoutMaker& setTileSize(DkTileSize tileSize) noexcept { this->tileSize = tileSize; return *this; } + void initialize(ImageLayout& obj) const; + }; + + struct ImageView : public ::DkImageView + { + ImageView(Image const& image) noexcept : DkImageView{} { ::dkImageViewDefaults(this, &image); } + ImageView& setType(DkImageType type = DkImageType_None) noexcept { this->type = type; return *this; } + ImageView& setFormat(DkImageFormat format = DkImageFormat_None) noexcept { this->format = format; return *this; } + ImageView& setSwizzle(DkImageSwizzle x = DkImageSwizzle_Red, DkImageSwizzle y = DkImageSwizzle_Green, DkImageSwizzle z = DkImageSwizzle_Blue, DkImageSwizzle w = DkImageSwizzle_Alpha) noexcept + { + this->swizzle[0] = x; + this->swizzle[1] = y; + this->swizzle[2] = z; + this->swizzle[3] = w; + return *this; + } + ImageView& setDsSource(DkDsSource dsSource) noexcept { this->dsSource = dsSource; return *this; } + ImageView& setLayers(uint16_t layerOffset = 0, uint16_t layerCount = 0) noexcept + { + this->layerOffset = layerOffset; + this->layerCount = layerCount; + return *this; + } + ImageView& setMipLevels(uint8_t mipLevelOffset = 0, uint8_t mipLevelCount = 0) noexcept + { + this->mipLevelOffset = mipLevelOffset; + this->mipLevelCount = mipLevelCount; + return *this; + } + }; + + struct ImageDescriptor : public detail::Opaque<::DkImageDescriptor> + { + DK_OPAQUE_COMMON_MEMBERS(ImageDescriptor); + void initialize(ImageView const& view, bool usesLoadOrStore = false, bool decayMS = false); + }; + + struct Sampler : public ::DkSampler + { + Sampler() noexcept : DkSampler{} { ::dkSamplerDefaults(this); } + Sampler& setFilter(DkFilter min = DkFilter_Nearest, DkFilter mag = DkFilter_Nearest, DkMipFilter mip = DkMipFilter_None) + { + this->minFilter = min; + this->magFilter = mag; + this->mipFilter = mip; + return *this; + } + Sampler& setWrapMode(DkWrapMode u = DkWrapMode_Repeat, DkWrapMode v = DkWrapMode_Repeat, DkWrapMode p = DkWrapMode_Repeat) + { + this->wrapMode[0] = u; + this->wrapMode[1] = v; + this->wrapMode[2] = p; + return *this; + } + Sampler& setLodClamp(float min, float max) + { + this->lodClampMin = min; + this->lodClampMax = max; + return *this; + } + Sampler& setLodBias(float bias) { this->lodBias = bias; return *this; } + Sampler& setLodSnap(float snap) { this->lodSnap = snap; return *this; } + Sampler& setDepthCompare(bool enable, DkCompareOp op = DkCompareOp_Less) + { + this->compareEnable = enable; + this->compareOp = op; + return *this; + } + Sampler& setBorderColor(float r, float g, float b, float a) + { + this->borderColor[0].value_f = r; + this->borderColor[1].value_f = g; + this->borderColor[2].value_f = b; + this->borderColor[3].value_f = a; + return *this; + } + Sampler& setBorderColor(uint32_t r, uint32_t g, uint32_t b, uint32_t a) + { + this->borderColor[0].value_ui = r; + this->borderColor[1].value_ui = g; + this->borderColor[2].value_ui = b; + this->borderColor[3].value_ui = a; + return *this; + } + Sampler& setBorderColor(int32_t r, int32_t g, int32_t b, int32_t a) + { + this->borderColor[0].value_i = r; + this->borderColor[1].value_i = g; + this->borderColor[2].value_i = b; + this->borderColor[3].value_i = a; + return *this; + } + Sampler& setMaxAnisotropy(float max) { this->maxAnisotropy = max; return *this; } + Sampler& setReductionMode(DkSamplerReduction mode) { this->reductionMode = mode; return *this; } + }; + + struct SamplerDescriptor : public detail::Opaque<::DkSamplerDescriptor> + { + DK_OPAQUE_COMMON_MEMBERS(SamplerDescriptor); + void initialize(Sampler const& sampler); + }; + + struct RasterizerState : public ::DkRasterizerState + { + RasterizerState() : DkRasterizerState{} { ::dkRasterizerStateDefaults(this); } + RasterizerState& setRasterizerEnable(bool enable) { this->rasterizerEnable = enable; return *this; } + RasterizerState& setDepthClampEnable(bool enable) { this->depthClampEnable = enable; return *this; } + RasterizerState& setFillRectangleEnable(bool enable) { this->fillRectangleEnable = enable; return *this; } + RasterizerState& setPolygonMode(DkPolygonMode mode) { this->polygonModeFront = this->polygonModeBack = mode; return *this; } + RasterizerState& setPolygonModeFront(DkPolygonMode mode) { this->polygonModeFront = mode; return *this; } + RasterizerState& setPolygonModeBack(DkPolygonMode mode) { this->polygonModeBack = mode; return *this; } + RasterizerState& setCullMode(DkFace cullMode) { this->cullMode = cullMode; return *this; } + RasterizerState& setFrontFace(DkFrontFace frontFace) { this->frontFace = frontFace; return *this; } + RasterizerState& setPolygonSmoothEnable(bool enable) { this->polygonSmoothEnableMask = enable ? DkPolygonFlag_All : 0; return *this; } + RasterizerState& setPolygonSmoothEnableMask(uint32_t mask) { this->polygonSmoothEnableMask = mask; return *this; } + RasterizerState& setDepthBiasEnable(bool enable) { this->depthBiasEnableMask = enable ? DkPolygonFlag_All : 0; return *this; } + RasterizerState& setDepthBiasEnableMask(uint32_t mask) { this->depthBiasEnableMask = mask; return *this; } + }; + + struct MultisampleState : public ::DkMultisampleState + { + MultisampleState() : DkMultisampleState{} { ::dkMultisampleStateDefaults(this); } + MultisampleState& setMode(DkMsMode mode) { this->mode = mode; return *this; } + MultisampleState& setRasterizerMode(DkMsMode mode) { this->rasterizerMode = mode; return *this; } + MultisampleState& setAlphaToCoverageEnable(bool enable) { this->alphaToCoverageEnable = enable; return *this; } + MultisampleState& setAlphaToCoverageDither(bool dither) { this->alphaToCoverageDither = dither; return *this; } + MultisampleState& setCoverageToColorEnable(bool enable) { this->coverageToColorEnable = enable; return *this; } + MultisampleState& setCoverageToColorOutput(unsigned output) { this->coverageToColorOutput = output; return *this; } + MultisampleState& setCoverageModulation(DkCoverageModulation mod) { this->coverageModulation = mod; return *this; } + MultisampleState& setLocations() { ::dkMultisampleStateSetLocations(this, nullptr, 0); return *this; } + MultisampleState& setLocations(detail::ArrayProxy locations); + }; + + struct ColorState : public ::DkColorState + { + ColorState() : DkColorState{} { ::dkColorStateDefaults(this); } + ColorState& setBlendEnable(uint32_t id, bool enable) { ::dkColorStateSetBlendEnable(this, id, enable); return *this; } + ColorState& setBlendEnableMask(uint8_t mask) { this->blendEnableMask = mask; return *this; } + ColorState& setLogicOp(DkLogicOp op) { this->logicOp = op; return *this; } + ColorState& setAlphaCompareOp(DkCompareOp op) { this->alphaCompareOp = op; return *this; } + }; + + struct ColorWriteState : public ::DkColorWriteState + { + ColorWriteState() : DkColorWriteState{} { ::dkColorWriteStateDefaults(this); } + ColorWriteState& setMask(uint32_t id, uint32_t colorWriteMask) { ::dkColorWriteStateSetMask(this, id, colorWriteMask); return *this; } + }; + + struct BlendState : public ::DkBlendState + { + BlendState() : DkBlendState{} { ::dkBlendStateDefaults(this); } + BlendState& setOps(DkBlendOp colorBlendOp, DkBlendOp alphaBlendOp) { ::dkBlendStateSetOps(this, colorBlendOp, alphaBlendOp); return *this; } + BlendState& setFactors(DkBlendFactor srcColorBlendFactor, DkBlendFactor dstColorBlendFactor, DkBlendFactor srcAlphaBlendFactor, DkBlendFactor dstAlphaBlendFactor) { ::dkBlendStateSetFactors(this, srcColorBlendFactor, dstColorBlendFactor, srcAlphaBlendFactor, dstAlphaBlendFactor); return *this; } + BlendState& setColorBlendOp(DkBlendOp colorBlendOp) { this->colorBlendOp = colorBlendOp; return *this; } + BlendState& setSrcColorBlendFactor(DkBlendFactor srcColorBlendFactor) { this->srcColorBlendFactor = srcColorBlendFactor; return *this; } + BlendState& setDstColorBlendFactor(DkBlendFactor dstColorBlendFactor) { this->dstColorBlendFactor = dstColorBlendFactor; return *this; } + BlendState& setAlphaBlendOp(DkBlendOp alphaBlendOp) { this->alphaBlendOp = alphaBlendOp; return *this; } + BlendState& setSrcAlphaBlendFactor(DkBlendFactor srcAlphaBlendFactor) { this->srcAlphaBlendFactor = srcAlphaBlendFactor; return *this; } + BlendState& setDstAlphaBlendFactor(DkBlendFactor dstAlphaBlendFactor) { this->dstAlphaBlendFactor = dstAlphaBlendFactor; return *this; } + }; + + struct DepthStencilState : public ::DkDepthStencilState + { + DepthStencilState() : DkDepthStencilState{} { ::dkDepthStencilStateDefaults(this); } + DepthStencilState& setDepthTestEnable(bool enable) { this->depthTestEnable = enable; return *this; } + DepthStencilState& setDepthWriteEnable(bool enable) { this->depthWriteEnable = enable; return *this; } + DepthStencilState& setStencilTestEnable(bool enable) { this->stencilTestEnable = enable; return *this; } + DepthStencilState& setDepthCompareOp(DkCompareOp op) { this->depthCompareOp = op; return *this; } + DepthStencilState& setStencilFrontFailOp(DkStencilOp op) { this->stencilFrontFailOp = op; return *this; } + DepthStencilState& setStencilFrontPassOp(DkStencilOp op) { this->stencilFrontPassOp = op; return *this; } + DepthStencilState& setStencilFrontDepthFailOp(DkStencilOp op) { this->stencilFrontDepthFailOp = op; return *this; } + DepthStencilState& setStencilFrontCompareOp(DkCompareOp op) { this->stencilFrontCompareOp = op; return *this; } + DepthStencilState& setStencilBackFailOp(DkStencilOp op) { this->stencilBackFailOp = op; return *this; } + DepthStencilState& setStencilBackPassOp(DkStencilOp op) { this->stencilBackPassOp = op; return *this; } + DepthStencilState& setStencilBackDepthFailOp(DkStencilOp op) { this->stencilBackDepthFailOp = op; return *this; } + DepthStencilState& setStencilBackCompareOp(DkCompareOp op) { this->stencilBackCompareOp = op; return *this; } + }; + + struct SwapchainMaker : public ::DkSwapchainMaker + { + SwapchainMaker(DkDevice device, void* nativeWindow, DkImage const* const pImages[], uint32_t numImages) noexcept : DkSwapchainMaker{} { ::dkSwapchainMakerDefaults(this, device, nativeWindow, pImages, numImages); } + template SwapchainMaker(DkDevice device, void* nativeWindow, std::array const& images) noexcept : SwapchainMaker{device, nativeWindow, images.data(), (uint32_t)images.size()} { } +#ifdef DK_HPP_SUPPORT_VECTOR + SwapchainMaker(DkDevice device, void* nativeWindow, std::vector const& images) noexcept : SwapchainMaker{device, nativeWindow, images.data(), images.size()} { } +#endif + Swapchain create() const; + }; + + inline Device DeviceMaker::create() const + { + return Device{::dkDeviceCreate(this)}; + } + + inline void Device::destroy() + { + ::dkDeviceDestroy(*this); + _clear(); + } + + inline MemBlock MemBlockMaker::create() const + { + return MemBlock{::dkMemBlockCreate(this)}; + } + + inline void MemBlock::destroy() + { + ::dkMemBlockDestroy(*this); + _clear(); + } + + inline void* MemBlock::getCpuAddr() + { + return ::dkMemBlockGetCpuAddr(*this); + } + + inline DkGpuAddr MemBlock::getGpuAddr() + { + return ::dkMemBlockGetGpuAddr(*this); + } + + inline uint32_t MemBlock::getSize() + { + return ::dkMemBlockGetSize(*this); + } + + inline DkResult MemBlock::flushCpuCache(uint32_t offset, uint32_t size) + { + return ::dkMemBlockFlushCpuCache(*this, offset, size); + } + + inline DkResult Fence::wait(int64_t timeout_ns) + { + return ::dkFenceWait(this, timeout_ns); + } + + inline CmdBuf CmdBufMaker::create() const + { + return CmdBuf{::dkCmdBufCreate(this)}; + } + + inline void CmdBuf::destroy() + { + ::dkCmdBufDestroy(*this); + _clear(); + } + + inline void CmdBuf::addMemory(DkMemBlock mem, uint32_t offset, uint32_t size) + { + ::dkCmdBufAddMemory(*this, mem, offset, size); + } + + inline DkCmdList CmdBuf::finishList() + { + return ::dkCmdBufFinishList(*this); + } + + inline void CmdBuf::clear() + { + ::dkCmdBufClear(*this); + } + + inline void CmdBuf::beginCaptureCmds(uint32_t* storage, uint32_t max_words) + { + ::dkCmdBufBeginCaptureCmds(*this, storage, max_words); + } + + inline uint32_t CmdBuf::endCaptureCmds() + { + return ::dkCmdBufEndCaptureCmds(*this); + } + + inline void CmdBuf::replayCmds(detail::ArrayProxy words) + { + ::dkCmdBufReplayCmds(*this, words.data(), words.size()); + } + + inline void CmdBuf::callList(DkCmdList list) + { + ::dkCmdBufCallList(*this, list); + } + + inline void CmdBuf::waitFence(DkFence& fence) + { + return ::dkCmdBufWaitFence(*this, &fence); + } + + inline void CmdBuf::signalFence(DkFence& fence, bool flush) + { + return ::dkCmdBufSignalFence(*this, &fence, flush); + } + + inline void CmdBuf::barrier(DkBarrier mode, uint32_t invalidateFlags) + { + ::dkCmdBufBarrier(*this, mode, invalidateFlags); + } + + inline void CmdBuf::bindShaders(uint32_t stageMask, detail::ArrayProxy shaders) + { + ::dkCmdBufBindShaders(*this, stageMask, shaders.data(), shaders.size()); + } + + inline void CmdBuf::bindUniformBuffer(DkStage stage, uint32_t id, DkGpuAddr bufAddr, uint32_t bufSize) + { + ::dkCmdBufBindUniformBuffer(*this, stage, id, bufAddr, bufSize); + } + + inline void CmdBuf::bindUniformBuffers(DkStage stage, uint32_t firstId, detail::ArrayProxy buffers) + { + ::dkCmdBufBindUniformBuffers(*this, stage, firstId, buffers.data(), buffers.size()); + } + + inline void CmdBuf::bindStorageBuffer(DkStage stage, uint32_t id, DkGpuAddr bufAddr, uint32_t bufSize) + { + ::dkCmdBufBindStorageBuffer(*this, stage, id, bufAddr, bufSize); + } + + inline void CmdBuf::bindStorageBuffers(DkStage stage, uint32_t firstId, detail::ArrayProxy buffers) + { + ::dkCmdBufBindStorageBuffers(*this, stage, firstId, buffers.data(), buffers.size()); + } + + inline void CmdBuf::bindTextures(DkStage stage, uint32_t firstId, detail::ArrayProxy handles) + { + ::dkCmdBufBindTextures(*this, stage, firstId, handles.data(), handles.size()); + } + + inline void CmdBuf::bindImages(DkStage stage, uint32_t firstId, detail::ArrayProxy handles) + { + ::dkCmdBufBindImages(*this, stage, firstId, handles.data(), handles.size()); + } + + inline void CmdBuf::bindImageDescriptorSet(DkGpuAddr setAddr, uint32_t numDescriptors) + { + ::dkCmdBufBindImageDescriptorSet(*this, setAddr, numDescriptors); + } + + inline void CmdBuf::bindSamplerDescriptorSet(DkGpuAddr setAddr, uint32_t numDescriptors) + { + ::dkCmdBufBindSamplerDescriptorSet(*this, setAddr, numDescriptors); + } + + inline void CmdBuf::bindRenderTargets(detail::ArrayProxy colorTargets, DkImageView const* depthTarget) + { + ::dkCmdBufBindRenderTargets(*this, colorTargets.data(), colorTargets.size(), depthTarget); + } + + inline void CmdBuf::bindColorState(DkColorState const& state) + { + ::dkCmdBufBindColorState(*this, &state); + } + + inline void CmdBuf::bindColorWriteState(DkColorWriteState const& state) + { + ::dkCmdBufBindColorWriteState(*this, &state); + } + + inline void CmdBuf::bindBlendStates(uint32_t id, detail::ArrayProxy states) + { + ::dkCmdBufBindBlendStates(*this, id, states.data(), states.size()); + } + + inline void CmdBuf::bindRasterizerState(DkRasterizerState const& state) + { + ::dkCmdBufBindRasterizerState(*this, &state); + } + + inline void CmdBuf::bindMultisampleState(DkMultisampleState const& state) + { + ::dkCmdBufBindMultisampleState(*this, &state); + } + + inline void CmdBuf::bindDepthStencilState(DkDepthStencilState const& state) + { + ::dkCmdBufBindDepthStencilState(*this, &state); + } + + inline void CmdBuf::bindVtxAttribState(detail::ArrayProxy attribs) + { + ::dkCmdBufBindVtxAttribState(*this, attribs.data(), attribs.size()); + } + + inline void CmdBuf::bindVtxBufferState(detail::ArrayProxy buffers) + { + ::dkCmdBufBindVtxBufferState(*this, buffers.data(), buffers.size()); + } + + inline void CmdBuf::bindVtxBuffer(uint32_t id, DkGpuAddr bufAddr, uint32_t bufSize) + { + ::dkCmdBufBindVtxBuffer(*this, id, bufAddr, bufSize); + } + + inline void CmdBuf::bindVtxBuffers(uint32_t firstId, detail::ArrayProxy buffers) + { + ::dkCmdBufBindVtxBuffers(*this, firstId, buffers.data(), buffers.size()); + } + + inline void CmdBuf::bindIdxBuffer(DkIdxFormat format, DkGpuAddr address) + { + ::dkCmdBufBindIdxBuffer(*this, format, address); + } + + inline void CmdBuf::setViewports(uint32_t firstId, detail::ArrayProxy viewports) + { + ::dkCmdBufSetViewports(*this, firstId, viewports.data(), viewports.size()); + } + + inline void CmdBuf::setViewportSwizzles(uint32_t firstId, detail::ArrayProxy swizzles) + { + ::dkCmdBufSetViewportSwizzles(*this, firstId, swizzles.data(), swizzles.size()); + } + + inline void CmdBuf::setSubpixelPrecisionBias(uint32_t xbits, uint32_t ybits) + { + ::dkCmdBufSetSubpixelPrecisionBias(*this, xbits, ybits); + } + + inline void CmdBuf::setScissors(uint32_t firstId, detail::ArrayProxy scissors) + { + ::dkCmdBufSetScissors(*this, firstId, scissors.data(), scissors.size()); + } + + inline void CmdBuf::setDepthBias(float constantFactor, float clamp, float slopeFactor) + { + ::dkCmdBufSetDepthBias(*this, constantFactor, clamp, slopeFactor); + } + + inline void CmdBuf::setPointSize(float size) + { + ::dkCmdBufSetPointSize(*this, size); + } + + inline void CmdBuf::setLineWidth(float width) + { + ::dkCmdBufSetLineWidth(*this, width); + } + + inline void CmdBuf::setConservativeRasterEnable(bool enable) + { + ::dkCmdBufSetConservativeRasterEnable(*this, enable); + } + + inline void CmdBuf::setConservativeRasterDilate(float dilate) + { + ::dkCmdBufSetConservativeRasterDilate(*this, dilate); + } + + inline void CmdBuf::setSampleMask(uint32_t mask) + { + ::dkCmdBufSetSampleMask(*this, mask); + } + + inline void CmdBuf::setCoverageModulationTable(float const table[16]) + { + ::dkCmdBufSetCoverageModulationTable(*this, table); + } + + inline void CmdBuf::setDepthBounds(bool enable, float near, float far) + { + ::dkCmdBufSetDepthBounds(*this, enable, near, far); + } + + inline void CmdBuf::setAlphaRef(float ref) + { + ::dkCmdBufSetAlphaRef(*this, ref); + } + + inline void CmdBuf::setBlendConst(float red, float green, float blue, float alpha) + { + ::dkCmdBufSetBlendConst(*this, red, green, blue, alpha); + } + + inline void CmdBuf::setStencil(DkFace face, uint8_t mask, uint8_t funcRef, uint8_t funcMask) + { + ::dkCmdBufSetStencil(*this, face, mask, funcRef, funcMask); + } + + inline void CmdBuf::setPrimitiveRestart(bool enable, uint32_t index) + { + ::dkCmdBufSetPrimitiveRestart(*this, enable, index); + } + + inline void CmdBuf::setPatchSize(uint32_t size) + { + ::dkCmdBufSetPatchSize(*this, size); + } + + inline void CmdBuf::setTessOuterLevels(float level0, float level1, float level2, float level3) + { + ::dkCmdBufSetTessOuterLevels(*this, level0, level1, level2, level3); + } + + inline void CmdBuf::setTessInnerLevels(float level0, float level1) + { + ::dkCmdBufSetTessInnerLevels(*this, level0, level1); + } + + inline void CmdBuf::setTileSize(uint32_t width, uint32_t height) + { + ::dkCmdBufSetTileSize(*this, width, height); + } + + inline void CmdBuf::tiledCacheOp(DkTiledCacheOp op) + { + ::dkCmdBufTiledCacheOp(*this, op); + } + + inline void CmdBuf::clearColor(uint32_t targetId, uint32_t clearMask, const void* clearData) + { + ::dkCmdBufClearColor(*this, targetId, clearMask, clearData); + } + + template + inline void CmdBuf::clearColor(uint32_t targetId, uint32_t clearMask, T red, T green, T blue, T alpha) + { + static_assert(sizeof(T) == 4, "Bad size for T"); + T data[] = { red, green, blue, alpha }; + ::dkCmdBufClearColor(*this, targetId, clearMask, data); + } + + inline void CmdBuf::clearDepthStencil(bool clearDepth, float depthValue, uint8_t stencilMask, uint8_t stencilValue) + { + ::dkCmdBufClearDepthStencil(*this, clearDepth, depthValue, stencilMask, stencilValue); + } + + inline void CmdBuf::discardColor(uint32_t targetId) + { + ::dkCmdBufDiscardColor(*this, targetId); + } + + inline void CmdBuf::discardDepthStencil() + { + ::dkCmdBufDiscardDepthStencil(*this); + } + + inline void CmdBuf::resolveDepthValues() + { + ::dkCmdBufResolveDepthValues(*this); + } + + inline void CmdBuf::draw(DkPrimitive prim, uint32_t numVertices, uint32_t numInstances, uint32_t firstVertex, uint32_t firstInstance) + { + ::dkCmdBufDraw(*this, prim, numVertices, numInstances, firstVertex, firstInstance); + } + + inline void CmdBuf::drawIndirect(DkPrimitive prim, DkGpuAddr indirect) + { + ::dkCmdBufDrawIndirect(*this, prim, indirect); + } + + inline void CmdBuf::drawIndexed(DkPrimitive prim, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) + { + ::dkCmdBufDrawIndexed(*this, prim, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); + } + + inline void CmdBuf::drawIndexedIndirect(DkPrimitive prim, DkGpuAddr indirect) + { + ::dkCmdBufDrawIndexedIndirect(*this, prim, indirect); + } + + inline void CmdBuf::dispatchCompute(uint32_t numGroupsX, uint32_t numGroupsY, uint32_t numGroupsZ) + { + ::dkCmdBufDispatchCompute(*this, numGroupsX, numGroupsY, numGroupsZ); + } + + inline void CmdBuf::dispatchComputeIndirect(DkGpuAddr indirect) + { + ::dkCmdBufDispatchComputeIndirect(*this, indirect); + } + + inline void CmdBuf::pushConstants(DkGpuAddr uboAddr, uint32_t uboSize, uint32_t offset, uint32_t size, const void* data) + { + ::dkCmdBufPushConstants(*this, uboAddr, uboSize, offset, size, data); + } + + inline void CmdBuf::pushData(DkGpuAddr addr, const void* data, uint32_t size) + { + ::dkCmdBufPushData(*this, addr, data, size); + } + + inline void CmdBuf::copyBuffer(DkGpuAddr srcAddr, DkGpuAddr dstAddr, uint32_t size) + { + ::dkCmdBufCopyBuffer(*this, srcAddr, dstAddr, size); + } + + inline void CmdBuf::copyImage(DkImageView const& srcView, DkImageRect const& srcRect, DkImageView const& dstView, DkImageRect const& dstRect, uint32_t flags) + { + ::dkCmdBufCopyImage(*this, &srcView, &srcRect, &dstView, &dstRect, flags); + } + + inline void CmdBuf::blitImage(DkImageView const& srcView, DkImageRect const& srcRect, DkImageView const& dstView, DkImageRect const& dstRect, uint32_t flags, uint32_t factor) + { + ::dkCmdBufBlitImage(*this, &srcView, &srcRect, &dstView, &dstRect, flags, factor); + } + + inline void CmdBuf::resolveImage(DkImageView const& srcView, DkImageView const& dstView) + { + ::dkCmdBufResolveImage(*this, &srcView, &dstView); + } + + inline void CmdBuf::copyBufferToImage(DkCopyBuf const& src, DkImageView const& dstView, DkImageRect const& dstRect, uint32_t flags) + { + ::dkCmdBufCopyBufferToImage(*this, &src, &dstView, &dstRect, flags); + } + + inline void CmdBuf::copyImageToBuffer(DkImageView const& srcView, DkImageRect const& srcRect, DkCopyBuf const& dst, uint32_t flags) + { + ::dkCmdBufCopyImageToBuffer(*this, &srcView, &srcRect, &dst, flags); + } + + inline Queue QueueMaker::create() const + { + return Queue{::dkQueueCreate(this)}; + } + + inline void Queue::destroy() + { + ::dkQueueDestroy(*this); + _clear(); + } + + inline bool Queue::isInErrorState() + { + return ::dkQueueIsInErrorState(*this); + } + + inline void Queue::waitFence(DkFence& fence) + { + ::dkQueueWaitFence(*this, &fence); + } + + inline void Queue::signalFence(DkFence& fence, bool flush) + { + ::dkQueueSignalFence(*this, &fence, flush); + } + + inline void Queue::submitCommands(DkCmdList cmds) + { + ::dkQueueSubmitCommands(*this, cmds); + } + + inline void Queue::flush() + { + ::dkQueueFlush(*this); + } + + inline void Queue::waitIdle() + { + ::dkQueueWaitIdle(*this); + } + + inline int Queue::acquireImage(DkSwapchain swapchain) + { + return ::dkQueueAcquireImage(*this, swapchain); + } + + inline void Queue::presentImage(DkSwapchain swapchain, int imageSlot) + { + ::dkQueuePresentImage(*this, swapchain, imageSlot); + } + + inline void ShaderMaker::initialize(Shader& obj) const + { + ::dkShaderInitialize(&obj, this); + } + + inline bool Shader::isValid() const + { + return ::dkShaderIsValid(this); + } + + inline DkStage Shader::getStage() const + { + return ::dkShaderGetStage(this); + } + + inline void ImageLayoutMaker::initialize(ImageLayout& obj) const + { + ::dkImageLayoutInitialize(&obj, this); + } + + inline uint64_t ImageLayout::getSize() const + { + return ::dkImageLayoutGetSize(this); + } + + inline uint32_t ImageLayout::getAlignment() const + { + return ::dkImageLayoutGetAlignment(this); + } + + inline void Image::initialize(ImageLayout const& layout, DkMemBlock memBlock, uint32_t offset) + { + ::dkImageInitialize(this, &layout, memBlock, offset); + } + + inline DkGpuAddr Image::getGpuAddr() const + { + return ::dkImageGetGpuAddr(this); + } + + inline ImageLayout const& Image::getLayout() const + { + return *static_cast(::dkImageGetLayout(this)); + } + + inline void ImageDescriptor::initialize(ImageView const& view, bool usesLoadOrStore, bool decayMS) + { + ::dkImageDescriptorInitialize(this, &view, usesLoadOrStore, decayMS); + } + + inline void SamplerDescriptor::initialize(Sampler const& sampler) + { + ::dkSamplerDescriptorInitialize(this, &sampler); + } + + inline MultisampleState& MultisampleState::setLocations(detail::ArrayProxy locations) + { + ::dkMultisampleStateSetLocations(this, locations.data(), locations.size()); + return *this; + } + + inline Swapchain SwapchainMaker::create() const + { + return Swapchain{::dkSwapchainCreate(this)}; + } + + inline void Swapchain::destroy() + { + ::dkSwapchainDestroy(*this); + _clear(); + } + + inline void Swapchain::acquireImage(int& imageSlot, DkFence& fence) + { + ::dkSwapchainAcquireImage(*this, &imageSlot, &fence); + } + + inline void Swapchain::setCrop(int32_t left, int32_t top, int32_t right, int32_t bottom) + { + ::dkSwapchainSetCrop(*this, left, top, right, bottom); + } + + inline void Swapchain::setSwapInterval(uint32_t interval) + { + ::dkSwapchainSetSwapInterval(*this, interval); + } + + using UniqueDevice = detail::UniqueHandle; + using UniqueMemBlock = detail::UniqueHandle; + using UniqueCmdBuf = detail::UniqueHandle; + using UniqueQueue = detail::UniqueHandle; + using UniqueSwapchain = detail::UniqueHandle; +} diff --git a/troposphere/daybreak/nanovg/include/nanovg/deko3d.h b/troposphere/daybreak/nanovg/include/nanovg/deko3d.h new file mode 100644 index 000000000..6b6ad5051 --- /dev/null +++ b/troposphere/daybreak/nanovg/include/nanovg/deko3d.h @@ -0,0 +1,1353 @@ +/* +**----------------------------------------------------------------------------- +** deko3d.h - Main header file for deko3d +**----------------------------------------------------------------------------- +** +** Copyright (C) 2018-2020 fincs +** +** This software is provided 'as-is', without any express or implied +** warranty. In no event will the authors be held liable for any +** damages arising from the use of this software. +** +** Permission is granted to anyone to use this software for any +** purpose, including commercial applications, and to alter it and +** redistribute it freely, subject to the following restrictions: +** +** 1. The origin of this software must not be misrepresented; you +** must not claim that you wrote the original software. If you use +** this software in a product, an acknowledgment in the product +** documentation would be appreciated but is not required. +** 2. Altered source versions must be plainly marked as such, and +** must not be misrepresented as being the original software. +** 3. This notice may not be removed or altered from any source +** distribution. +** +** This file is currently written by hand; in the future it might be autogenerated. +** +*/ + +#pragma once +#include +#include +#include +#include + +#if __cplusplus >= 201402L +#define DK_CONSTEXPR constexpr +#else +#define DK_CONSTEXPR static inline +#endif + +#ifndef __cplusplus + +#define DK_DECL_HANDLE(_typename) \ + typedef struct tag_Dk##_typename *Dk##_typename + +#else + +#define DK_DECL_HANDLE(_typename) \ + namespace dk::detail { struct _typename; } \ + using Dk##_typename = dk::detail::_typename* + +#endif + +#ifndef __DK_INTERNAL__ + +#define DK_DECL_OPAQUE(_typename, _align, _size) \ + typedef struct Dk##_typename \ + { \ + alignas(_align) uint8_t _storage[_size]; \ + } Dk##_typename + +#else + +#define DK_DECL_OPAQUE(_typename, _align, _size) \ + namespace dk::detail { \ + struct _typename; /* forward declaration */ \ + constexpr unsigned _align_##_typename = _align; \ + constexpr unsigned _size_##_typename = _size; \ + } \ + using Dk##_typename = dk::detail::_typename + +#endif + +DK_DECL_HANDLE(Device); +DK_DECL_HANDLE(MemBlock); +DK_DECL_OPAQUE(Fence, 8, 64); +DK_DECL_HANDLE(CmdBuf); +DK_DECL_HANDLE(Queue); +DK_DECL_OPAQUE(Shader, 8, 128); +DK_DECL_OPAQUE(ImageLayout, 8, 128); +DK_DECL_OPAQUE(Image, 8, 128); +DK_DECL_OPAQUE(ImageDescriptor, 4, 32); +DK_DECL_OPAQUE(SamplerDescriptor, 4, 32); +DK_DECL_HANDLE(Swapchain); + +#undef DK_DECL_HANDLE +#undef DK_DECL_OPAQUE + +typedef enum +{ + DkResult_Success, + DkResult_Fail, + DkResult_Timeout, + DkResult_OutOfMemory, + DkResult_NotImplemented, + DkResult_MisalignedSize, + DkResult_MisalignedData, + DkResult_BadInput, + DkResult_BadFlags, + DkResult_BadState, +} DkResult; + +#define DK_GPU_ADDR_INVALID UINT64_MAX + +typedef uint64_t DkGpuAddr; +typedef uintptr_t DkCmdList; +typedef uint32_t DkResHandle; +typedef void (*DkDebugFunc)(void* userData, const char* context, DkResult result, const char* message); +typedef DkResult (*DkAllocFunc)(void* userData, size_t alignment, size_t size, void** out); +typedef void (*DkFreeFunc)(void* userData, void* mem); +typedef void (*DkCmdBufAddMemFunc)(void* userData, DkCmdBuf cmdbuf, size_t minReqSize); + +enum +{ + DkDeviceFlags_DepthZeroToOne = 0U << 8, + DkDeviceFlags_DepthMinusOneToOne = 1U << 8, + DkDeviceFlags_OriginUpperLeft = 0U << 9, + DkDeviceFlags_OriginLowerLeft = 1U << 9, +}; + +typedef struct DkDeviceMaker +{ + void* userData; + DkDebugFunc cbDebug; + DkAllocFunc cbAlloc; + DkFreeFunc cbFree; + uint32_t flags; +} DkDeviceMaker; + +DK_CONSTEXPR void dkDeviceMakerDefaults(DkDeviceMaker* maker) +{ + maker->userData = NULL; + maker->cbDebug = NULL; + maker->cbAlloc = NULL; + maker->cbFree = NULL; + maker->flags = DkDeviceFlags_DepthZeroToOne | DkDeviceFlags_OriginUpperLeft; +} + +#define DK_MEMBLOCK_ALIGNMENT 0x1000 +#define DK_CMDMEM_ALIGNMENT 4 +#define DK_QUEUE_MIN_CMDMEM_SIZE 0x10000 +#define DK_PER_WARP_SCRATCH_MEM_ALIGNMENT 0x200 +#define DK_NUM_UNIFORM_BUFS 16 +#define DK_NUM_STORAGE_BUFS 16 +#define DK_NUM_TEXTURE_BINDINGS 32 +#define DK_NUM_IMAGE_BINDINGS 8 +#define DK_UNIFORM_BUF_ALIGNMENT 0x100 +#define DK_UNIFORM_BUF_MAX_SIZE 0x10000 +#define DK_DEFAULT_MAX_COMPUTE_CONCURRENT_JOBS 128 +#define DK_SHADER_CODE_ALIGNMENT 0x100 +#define DK_SHADER_CODE_UNUSABLE_SIZE 0x400 +#define DK_IMAGE_DESCRIPTOR_ALIGNMENT 0x20 +#define DK_SAMPLER_DESCRIPTOR_ALIGNMENT 0x20 +#define DK_MAX_RENDER_TARGETS 8 +#define DK_NUM_VIEWPORTS 16 +#define DK_NUM_SCISSORS 16 +#define DK_MAX_VERTEX_ATTRIBS 32 +#define DK_MAX_VERTEX_BUFFERS 16 +#define DK_IMAGE_LINEAR_STRIDE_ALIGNMENT 32 + +enum +{ + DkMemAccess_None = 0U, + DkMemAccess_Uncached = 1U, + DkMemAccess_Cached = 2U, + DkMemAccess_Mask = 3U, +}; + +enum +{ + DkMemBlockFlags_CpuAccessShift = 0U, + DkMemBlockFlags_GpuAccessShift = 2U, + DkMemBlockFlags_CpuUncached = DkMemAccess_Uncached << DkMemBlockFlags_CpuAccessShift, + DkMemBlockFlags_CpuCached = DkMemAccess_Cached << DkMemBlockFlags_CpuAccessShift, + DkMemBlockFlags_CpuAccessMask = DkMemAccess_Mask << DkMemBlockFlags_CpuAccessShift, + DkMemBlockFlags_GpuUncached = DkMemAccess_Uncached << DkMemBlockFlags_GpuAccessShift, + DkMemBlockFlags_GpuCached = DkMemAccess_Cached << DkMemBlockFlags_GpuAccessShift, + DkMemBlockFlags_GpuAccessMask = DkMemAccess_Mask << DkMemBlockFlags_GpuAccessShift, + DkMemBlockFlags_Code = 1U << 4, + DkMemBlockFlags_Image = 1U << 5, + DkMemBlockFlags_ZeroFillInit = 1U << 8, +}; + +typedef struct DkMemBlockMaker +{ + DkDevice device; + uint32_t size; + uint32_t flags; + void* storage; +} DkMemBlockMaker; + +DK_CONSTEXPR void dkMemBlockMakerDefaults(DkMemBlockMaker* maker, DkDevice device, uint32_t size) +{ + maker->device = device; + maker->size = size; + maker->flags = DkMemBlockFlags_CpuUncached | DkMemBlockFlags_GpuCached; + maker->storage = NULL; +} + +typedef struct DkCmdBufMaker +{ + DkDevice device; + void* userData; + DkCmdBufAddMemFunc cbAddMem; +} DkCmdBufMaker; + +DK_CONSTEXPR void dkCmdBufMakerDefaults(DkCmdBufMaker* maker, DkDevice device) +{ + maker->device = device; + maker->userData = NULL; + maker->cbAddMem = NULL; +} + +enum +{ + DkQueueFlags_Graphics = 1U << 0, + DkQueueFlags_Compute = 1U << 1, + DkQueueFlags_MediumPrio = 0U << 2, + DkQueueFlags_HighPrio = 1U << 2, + DkQueueFlags_LowPrio = 2U << 2, + DkQueueFlags_PrioMask = 3U << 2, + DkQueueFlags_EnableZcull = 0U << 4, + DkQueueFlags_DisableZcull = 1U << 4, +}; + +typedef struct DkQueueMaker +{ + DkDevice device; + uint32_t flags; + uint32_t commandMemorySize; + uint32_t flushThreshold; + uint32_t perWarpScratchMemorySize; + uint32_t maxConcurrentComputeJobs; +} DkQueueMaker; + +DK_CONSTEXPR void dkQueueMakerDefaults(DkQueueMaker* maker, DkDevice device) +{ + maker->device = device; + maker->flags = + DkQueueFlags_Graphics | DkQueueFlags_Compute | DkQueueFlags_MediumPrio | + DkQueueFlags_EnableZcull; + maker->commandMemorySize = DK_QUEUE_MIN_CMDMEM_SIZE; + maker->flushThreshold = DK_QUEUE_MIN_CMDMEM_SIZE/8; + maker->perWarpScratchMemorySize = 4*DK_PER_WARP_SCRATCH_MEM_ALIGNMENT; + maker->maxConcurrentComputeJobs = DK_DEFAULT_MAX_COMPUTE_CONCURRENT_JOBS; +} + +typedef struct DkShaderMaker +{ + DkMemBlock codeMem; + const void* control; + uint32_t codeOffset; + uint32_t programId; +} DkShaderMaker; + +DK_CONSTEXPR void dkShaderMakerDefaults(DkShaderMaker* maker, DkMemBlock codeMem, uint32_t codeOffset) +{ + maker->codeMem = codeMem; + maker->control = NULL; + maker->codeOffset = codeOffset; + maker->programId = 0; +} + +typedef enum DkStage +{ + DkStage_Vertex = 0, + DkStage_TessCtrl = 1, + DkStage_TessEval = 2, + DkStage_Geometry = 3, + DkStage_Fragment = 4, + DkStage_Compute = 5, + + DkStage_MaxGraphics = 5, +} DkStage; + +enum +{ + DkStageFlag_Vertex = 1U << DkStage_Vertex, + DkStageFlag_TessCtrl = 1U << DkStage_TessCtrl, + DkStageFlag_TessEval = 1U << DkStage_TessEval, + DkStageFlag_Geometry = 1U << DkStage_Geometry, + DkStageFlag_Fragment = 1U << DkStage_Fragment, + DkStageFlag_Compute = 1U << DkStage_Compute, + + DkStageFlag_GraphicsMask = (1U << DkStage_MaxGraphics) - 1, +}; + +typedef enum DkBarrier +{ + DkBarrier_None = 0, // No ordering is performed + DkBarrier_Tiles = 1, // Orders the processing of tiles (similar to Vulkan subpasses) + DkBarrier_Fragments = 2, // Orders the processing of fragments (similar to Vulkan renderpasses) + DkBarrier_Primitives = 3, // Completes the processing of all previous primitives and compute jobs + DkBarrier_Full = 4, // Completes the processing of all previous commands while disabling command list prefetch +} DkBarrier; + +enum +{ + DkInvalidateFlags_Image = 1U << 0, // Invalidates the image (texture) cache + DkInvalidateFlags_Shader = 1U << 1, // Invalidates the shader code/data/uniform cache + DkInvalidateFlags_Descriptors = 1U << 2, // Invalidates the image/sampler descriptor cache + DkInvalidateFlags_Zcull = 1U << 3, // Invalidates Zcull state + DkInvalidateFlags_L2Cache = 1U << 4, // Invalidates the L2 cache +}; + +typedef enum DkImageType +{ + DkImageType_None = 0, + DkImageType_1D = 1, + DkImageType_2D = 2, + DkImageType_3D = 3, + DkImageType_1DArray = 4, + DkImageType_2DArray = 5, + DkImageType_2DMS = 6, + DkImageType_2DMSArray = 7, + DkImageType_Rectangle = 8, + DkImageType_Cubemap = 9, + DkImageType_CubemapArray = 10, + DkImageType_Buffer = 11, +} DkImageType; + +enum +{ + DkImageFlags_BlockLinear = 0U << 0, // Image is stored in Nvidia block linear format (default). + DkImageFlags_PitchLinear = 1U << 0, // Image is stored in standard pitch linear format. + DkImageFlags_CustomTileSize = 1U << 1, // Use a custom tile size for block linear images. + DkImageFlags_HwCompression = 1U << 2, // Specifies that hardware compression is allowed to be enabled. + DkImageFlags_Z16EnableZbc = 1U << 3, // For DkImageFormat_Z16 images, specifies that zero-bandwidth clear is preferred as the hardware compression format. + + DkImageFlags_UsageRender = 1U << 8, // Specifies that the image will be used as a render target. + DkImageFlags_UsageLoadStore = 1U << 9, // Specifies that the image will be used with shader image load/store commands. + DkImageFlags_UsagePresent = 1U << 10, // Specifies that the image will be used with a DkSwapchain. + DkImageFlags_Usage2DEngine = 1U << 11, // Specifies that the image will be used with the 2D Engine (e.g. for transfers between images) + DkImageFlags_UsageVideo = 1U << 12, // Specifies that the image will be used with hardware video encoding/decoding engines +}; + +typedef enum DkImageFormat +{ + DkImageFormat_None, + DkImageFormat_R8_Unorm, + DkImageFormat_R8_Snorm, + DkImageFormat_R8_Uint, + DkImageFormat_R8_Sint, + DkImageFormat_R16_Float, + DkImageFormat_R16_Unorm, + DkImageFormat_R16_Snorm, + DkImageFormat_R16_Uint, + DkImageFormat_R16_Sint, + DkImageFormat_R32_Float, + DkImageFormat_R32_Uint, + DkImageFormat_R32_Sint, + DkImageFormat_RG8_Unorm, + DkImageFormat_RG8_Snorm, + DkImageFormat_RG8_Uint, + DkImageFormat_RG8_Sint, + DkImageFormat_RG16_Float, + DkImageFormat_RG16_Unorm, + DkImageFormat_RG16_Snorm, + DkImageFormat_RG16_Uint, + DkImageFormat_RG16_Sint, + DkImageFormat_RG32_Float, + DkImageFormat_RG32_Uint, + DkImageFormat_RG32_Sint, + DkImageFormat_RGB32_Float, + DkImageFormat_RGB32_Uint, + DkImageFormat_RGB32_Sint, + DkImageFormat_RGBA8_Unorm, + DkImageFormat_RGBA8_Snorm, + DkImageFormat_RGBA8_Uint, + DkImageFormat_RGBA8_Sint, + DkImageFormat_RGBA16_Float, + DkImageFormat_RGBA16_Unorm, + DkImageFormat_RGBA16_Snorm, + DkImageFormat_RGBA16_Uint, + DkImageFormat_RGBA16_Sint, + DkImageFormat_RGBA32_Float, + DkImageFormat_RGBA32_Uint, + DkImageFormat_RGBA32_Sint, + DkImageFormat_S8, + DkImageFormat_Z16, + DkImageFormat_Z24X8, + DkImageFormat_ZF32, + DkImageFormat_Z24S8, + DkImageFormat_ZF32_X24S8, + DkImageFormat_RGBX8_Unorm_sRGB, + DkImageFormat_RGBA8_Unorm_sRGB, + DkImageFormat_RGBA4_Unorm, + DkImageFormat_RGB5_Unorm, + DkImageFormat_RGB5A1_Unorm, + DkImageFormat_RGB565_Unorm, + DkImageFormat_RGB10A2_Unorm, + DkImageFormat_RGB10A2_Uint, + DkImageFormat_RG11B10_Float, + DkImageFormat_E5BGR9_Float, + DkImageFormat_RGB_BC1, + DkImageFormat_RGBA_BC1, + DkImageFormat_RGBA_BC2, + DkImageFormat_RGBA_BC3, + DkImageFormat_RGB_BC1_sRGB, + DkImageFormat_RGBA_BC1_sRGB, + DkImageFormat_RGBA_BC2_sRGB, + DkImageFormat_RGBA_BC3_sRGB, + DkImageFormat_R_BC4_Unorm, + DkImageFormat_R_BC4_Snorm, + DkImageFormat_RG_BC5_Unorm, + DkImageFormat_RG_BC5_Snorm, + DkImageFormat_RGBA_BC7_Unorm, + DkImageFormat_RGBA_BC7_Unorm_sRGB, + DkImageFormat_RGBA_BC6H_SF16_Float, + DkImageFormat_RGBA_BC6H_UF16_Float, + DkImageFormat_RGBX8_Unorm, + DkImageFormat_RGBX8_Snorm, + DkImageFormat_RGBX8_Uint, + DkImageFormat_RGBX8_Sint, + DkImageFormat_RGBX16_Float, + DkImageFormat_RGBX16_Unorm, + DkImageFormat_RGBX16_Snorm, + DkImageFormat_RGBX16_Uint, + DkImageFormat_RGBX16_Sint, + DkImageFormat_RGBX32_Float, + DkImageFormat_RGBX32_Uint, + DkImageFormat_RGBX32_Sint, + DkImageFormat_RGBA_ASTC_4x4, + DkImageFormat_RGBA_ASTC_5x4, + DkImageFormat_RGBA_ASTC_5x5, + DkImageFormat_RGBA_ASTC_6x5, + DkImageFormat_RGBA_ASTC_6x6, + DkImageFormat_RGBA_ASTC_8x5, + DkImageFormat_RGBA_ASTC_8x6, + DkImageFormat_RGBA_ASTC_8x8, + DkImageFormat_RGBA_ASTC_10x5, + DkImageFormat_RGBA_ASTC_10x6, + DkImageFormat_RGBA_ASTC_10x8, + DkImageFormat_RGBA_ASTC_10x10, + DkImageFormat_RGBA_ASTC_12x10, + DkImageFormat_RGBA_ASTC_12x12, + DkImageFormat_RGBA_ASTC_4x4_sRGB, + DkImageFormat_RGBA_ASTC_5x4_sRGB, + DkImageFormat_RGBA_ASTC_5x5_sRGB, + DkImageFormat_RGBA_ASTC_6x5_sRGB, + DkImageFormat_RGBA_ASTC_6x6_sRGB, + DkImageFormat_RGBA_ASTC_8x5_sRGB, + DkImageFormat_RGBA_ASTC_8x6_sRGB, + DkImageFormat_RGBA_ASTC_8x8_sRGB, + DkImageFormat_RGBA_ASTC_10x5_sRGB, + DkImageFormat_RGBA_ASTC_10x6_sRGB, + DkImageFormat_RGBA_ASTC_10x8_sRGB, + DkImageFormat_RGBA_ASTC_10x10_sRGB, + DkImageFormat_RGBA_ASTC_12x10_sRGB, + DkImageFormat_RGBA_ASTC_12x12_sRGB, + DkImageFormat_BGR565_Unorm, + DkImageFormat_BGR5_Unorm, + DkImageFormat_BGR5A1_Unorm, + DkImageFormat_A5BGR5_Unorm, + DkImageFormat_BGRX8_Unorm, + DkImageFormat_BGRA8_Unorm, + DkImageFormat_BGRX8_Unorm_sRGB, + DkImageFormat_BGRA8_Unorm_sRGB, + DkImageFormat_R_ETC2_Unorm, + DkImageFormat_R_ETC2_Snorm, + DkImageFormat_RG_ETC2_Unorm, + DkImageFormat_RG_ETC2_Snorm, + DkImageFormat_RGB_ETC2, // compatible with ETC1 + DkImageFormat_RGB_PTA_ETC2, + DkImageFormat_RGBA_ETC2, + DkImageFormat_RGB_ETC2_sRGB, + DkImageFormat_RGB_PTA_ETC2_sRGB, + DkImageFormat_RGBA_ETC2_sRGB, + + DkImageFormat_Count, +} DkImageFormat; + +typedef enum DkImageSwizzle +{ + DkImageSwizzle_Zero = 0, + DkImageSwizzle_One = 1, + DkImageSwizzle_Red = 2, + DkImageSwizzle_Green = 3, + DkImageSwizzle_Blue = 4, + DkImageSwizzle_Alpha = 5, +} DkImageSwizzle; + +typedef enum DkMsMode +{ + DkMsMode_1x = 0, + DkMsMode_2x = 1, + DkMsMode_4x = 2, + DkMsMode_8x = 3, +} DkMsMode; + +typedef enum DkDsSource +{ + DkDsSource_Depth = 0, + DkDsSource_Stencil = 1, +} DkDsSource; + +typedef enum DkTileSize +{ + DkTileSize_OneGob = 0, + DkTileSize_TwoGobs = 1, + DkTileSize_FourGobs = 2, + DkTileSize_EightGobs = 3, + DkTileSize_SixteenGobs = 4, + DkTileSize_ThirtyTwoGobs = 5, +} DkTileSize; + +typedef struct DkImageLayoutMaker +{ + DkDevice device; + DkImageType type; + uint32_t flags; + DkImageFormat format; + DkMsMode msMode; + uint32_t dimensions[3]; + uint32_t mipLevels; + union + { + uint32_t pitchStride; + DkTileSize tileSize; + }; +} DkImageLayoutMaker; + +DK_CONSTEXPR void dkImageLayoutMakerDefaults(DkImageLayoutMaker* maker, DkDevice device) +{ + maker->device = device; + maker->type = DkImageType_2D; + maker->flags = 0; + maker->format = DkImageFormat_None; + maker->msMode = DkMsMode_1x; + maker->dimensions[0] = 0; + maker->dimensions[1] = 0; + maker->dimensions[2] = 0; + maker->mipLevels = 1; + maker->pitchStride = 0; +} + +typedef struct DkImageView +{ + DkImage const* pImage; + DkImageType type; + DkImageFormat format; + DkImageSwizzle swizzle[4]; + DkDsSource dsSource; + uint16_t layerOffset; + uint16_t layerCount; + uint8_t mipLevelOffset; + uint8_t mipLevelCount; +} DkImageView; + +DK_CONSTEXPR void dkImageViewDefaults(DkImageView* obj, DkImage const* pImage) +{ + obj->pImage = pImage; + obj->type = DkImageType_None; // no override + obj->format = DkImageFormat_None; // no override + obj->swizzle[0] = DkImageSwizzle_Red; + obj->swizzle[1] = DkImageSwizzle_Green; + obj->swizzle[2] = DkImageSwizzle_Blue; + obj->swizzle[3] = DkImageSwizzle_Alpha; + obj->dsSource = DkDsSource_Depth; + obj->layerOffset = 0; + obj->layerCount = 0; // no override + obj->mipLevelOffset = 0; + obj->mipLevelCount = 0; // no override +} + +typedef enum DkFilter +{ + DkFilter_Nearest = 1, + DkFilter_Linear = 2, +} DkFilter; + +typedef enum DkMipFilter +{ + DkMipFilter_None = 1, + DkMipFilter_Nearest = 2, + DkMipFilter_Linear = 3, +} DkMipFilter; + +typedef enum DkWrapMode +{ + DkWrapMode_Repeat = 0, + DkWrapMode_MirroredRepeat = 1, + DkWrapMode_ClampToEdge = 2, + DkWrapMode_ClampToBorder = 3, + DkWrapMode_Clamp = 4, + DkWrapMode_MirrorClampToEdge = 5, + DkWrapMode_MirrorClampToBorder = 6, + DkWrapMode_MirrorClamp = 7, +} DkWrapMode; + +typedef enum DkCompareOp +{ + DkCompareOp_Never = 1, + DkCompareOp_Less = 2, + DkCompareOp_Equal = 3, + DkCompareOp_Lequal = 4, + DkCompareOp_Greater = 5, + DkCompareOp_NotEqual = 6, + DkCompareOp_Gequal = 7, + DkCompareOp_Always = 8, +} DkCompareOp; + +typedef enum DkSamplerReduction +{ + DkSamplerReduction_WeightedAverage = 0, + DkSamplerReduction_Min = 1, + DkSamplerReduction_Max = 2, +} DkSamplerReduction; + +typedef struct DkSampler +{ + DkFilter minFilter; + DkFilter magFilter; + DkMipFilter mipFilter; + DkWrapMode wrapMode[3]; + float lodClampMin; + float lodClampMax; + float lodBias; + float lodSnap; + bool compareEnable; + DkCompareOp compareOp; + union + { + float value_f; + uint32_t value_ui; + int32_t value_i; + } borderColor[4]; + float maxAnisotropy; + DkSamplerReduction reductionMode; +} DkSampler; + +DK_CONSTEXPR void dkSamplerDefaults(DkSampler* obj) +{ + obj->minFilter = DkFilter_Nearest; + obj->magFilter = DkFilter_Nearest; + obj->mipFilter = DkMipFilter_None; + obj->wrapMode[0] = DkWrapMode_Repeat; + obj->wrapMode[1] = DkWrapMode_Repeat; + obj->wrapMode[2] = DkWrapMode_Repeat; + obj->lodClampMin = 0.0f; + obj->lodClampMax = 1000.0f; + obj->lodBias = 0.0f; + obj->lodSnap = 0.0f; + obj->compareEnable = false; + obj->compareOp = DkCompareOp_Less; + obj->borderColor[0].value_ui = 0; + obj->borderColor[1].value_ui = 0; + obj->borderColor[2].value_ui = 0; + obj->borderColor[3].value_ui = 0; + obj->maxAnisotropy = 1.0f; + obj->reductionMode = DkSamplerReduction_WeightedAverage; +} + +typedef struct DkBufExtents +{ + DkGpuAddr addr; + uint32_t size; +} DkBufExtents; + +DK_CONSTEXPR DkResHandle dkMakeImageHandle(uint32_t id) +{ + return id & ((1U << 20) - 1); +} + +DK_CONSTEXPR DkResHandle dkMakeSamplerHandle(uint32_t id) +{ + return id << 20; +} + +DK_CONSTEXPR DkResHandle dkMakeTextureHandle(uint32_t imageId, uint32_t samplerId) +{ + return dkMakeImageHandle(imageId) | dkMakeSamplerHandle(samplerId); +} + +typedef struct DkViewport +{ + float x; + float y; + float width; + float height; + float near; + float far; +} DkViewport; + +typedef enum DkSwizzle +{ + DkSwizzle_PositiveX = 0, + DkSwizzle_NegativeX = 1, + DkSwizzle_PositiveY = 2, + DkSwizzle_NegativeY = 3, + DkSwizzle_PositiveZ = 4, + DkSwizzle_NegativeZ = 5, + DkSwizzle_PositiveW = 6, + DkSwizzle_NegativeW = 7, +} DkSwizzle; + +typedef struct DkViewportSwizzle +{ + DkSwizzle x; + DkSwizzle y; + DkSwizzle z; + DkSwizzle w; +} DkViewportSwizzle; + +typedef struct DkScissor +{ + uint32_t x; + uint32_t y; + uint32_t width; + uint32_t height; +} DkScissor; + +typedef enum DkPolygonMode +{ + DkPolygonMode_Point = 0, + DkPolygonMode_Line = 1, + DkPolygonMode_Fill = 2, +} DkPolygonMode; + +enum +{ + DkPolygonFlag_Point = 1U << DkPolygonMode_Point, + DkPolygonFlag_Line = 1U << DkPolygonMode_Line, + DkPolygonFlag_Fill = 1U << DkPolygonMode_Fill, + + DkPolygonFlag_All = DkPolygonFlag_Point|DkPolygonFlag_Line|DkPolygonFlag_Fill, +}; + +typedef enum DkFace +{ + DkFace_None = 0, + DkFace_Front = 1, + DkFace_Back = 2, + DkFace_FrontAndBack = 3, +} DkFace; + +typedef enum DkFrontFace +{ + DkFrontFace_CW = 0, + DkFrontFace_CCW = 1, +} DkFrontFace; + +typedef struct DkRasterizerState +{ + uint32_t rasterizerEnable : 1; + uint32_t depthClampEnable : 1; + uint32_t fillRectangleEnable : 1; + DkPolygonMode polygonModeFront : 2; + DkPolygonMode polygonModeBack : 2; + DkFace cullMode : 2; + DkFrontFace frontFace : 1; + uint32_t polygonSmoothEnableMask : 3; + uint32_t depthBiasEnableMask : 3; +} DkRasterizerState; + +DK_CONSTEXPR void dkRasterizerStateDefaults(DkRasterizerState* state) +{ + state->rasterizerEnable = 1; + state->depthClampEnable = 0; + state->fillRectangleEnable = 0; + state->polygonModeFront = DkPolygonMode_Fill; + state->polygonModeBack = DkPolygonMode_Fill; + state->cullMode = DkFace_Back; + state->frontFace = DkFrontFace_CCW; + state->polygonSmoothEnableMask = 0; + state->depthBiasEnableMask = 0; +} + +typedef enum DkCoverageModulation +{ + DkCoverageModulation_None = 0, + DkCoverageModulation_Rgb = 1, + DkCoverageModulation_Alpha = 2, + DkCoverageModulation_Rgba = 3, +} DkCoverageModulation; + +typedef struct DkMultisampleState +{ + DkMsMode mode : 3; + DkMsMode rasterizerMode : 3; + uint32_t alphaToCoverageEnable : 1; + uint32_t alphaToCoverageDither : 1; + uint32_t coverageToColorEnable : 1; + uint32_t coverageToColorOutput : 3; + DkCoverageModulation coverageModulation : 2; + uint32_t : 18; + + uint32_t sampleLocations[4]; +} DkMultisampleState; + +DK_CONSTEXPR void dkMultisampleStateDefaults(DkMultisampleState* state) +{ + state->mode = DkMsMode_1x; + state->rasterizerMode = DkMsMode_1x; + state->alphaToCoverageEnable = false; + state->alphaToCoverageDither = true; + state->coverageToColorEnable = false; + state->coverageToColorOutput = 0; + state->coverageModulation = DkCoverageModulation_None; + state->sampleLocations[0] = 0x88888888; + state->sampleLocations[1] = 0x88888888; + state->sampleLocations[2] = 0x88888888; + state->sampleLocations[3] = 0x88888888; +} + +typedef struct DkSampleLocation +{ + float x; + float y; +} DkSampleLocation; + +typedef enum DkLogicOp +{ + DkLogicOp_Clear = 0, + DkLogicOp_And = 1, + DkLogicOp_AndReverse = 2, + DkLogicOp_Copy = 3, + DkLogicOp_AndInverted = 4, + DkLogicOp_NoOp = 5, + DkLogicOp_Xor = 6, + DkLogicOp_Or = 7, + DkLogicOp_Nor = 8, + DkLogicOp_Equivalent = 9, + DkLogicOp_Invert = 10, + DkLogicOp_OrReverse = 11, + DkLogicOp_CopyInverted = 12, + DkLogicOp_OrInverted = 13, + DkLogicOp_Nand = 14, + DkLogicOp_Set = 15, +} DkLogicOp; + +typedef struct DkColorState +{ + uint32_t blendEnableMask : 8; + DkLogicOp logicOp : 8; + DkCompareOp alphaCompareOp : 4; + uint32_t : 12; +} DkColorState; + +DK_CONSTEXPR void dkColorStateDefaults(DkColorState* state) +{ + state->blendEnableMask = 0x00; + state->logicOp = DkLogicOp_Copy; + state->alphaCompareOp = DkCompareOp_Always; +} + +DK_CONSTEXPR void dkColorStateSetBlendEnable(DkColorState* state, uint32_t id, bool enable) +{ + if (enable) + state->blendEnableMask |= 1U << id; + else + state->blendEnableMask &= ~(1U << id); +} + +enum +{ + DkColorMask_R = 1U << 0, + DkColorMask_G = 1U << 1, + DkColorMask_B = 1U << 2, + DkColorMask_A = 1U << 3, + + DkColorMask_RGB = DkColorMask_R|DkColorMask_G|DkColorMask_B, + DkColorMask_RGBA = DkColorMask_R|DkColorMask_G|DkColorMask_B|DkColorMask_A, +}; + +typedef struct DkColorWriteState +{ + uint32_t masks; +} DkColorWriteState; + +DK_CONSTEXPR void dkColorWriteStateDefaults(DkColorWriteState* state) +{ + state->masks = 0xFFFFFFFF; +} + +DK_CONSTEXPR void dkColorWriteStateSetMask(DkColorWriteState* state, uint32_t id, uint32_t colorWriteMask) +{ + state->masks &= ~(0xF << (id*4)); + state->masks |= (colorWriteMask&0xF) << (id*4); +} + +typedef enum DkBlendOp +{ + DkBlendOp_Add = 1, + DkBlendOp_Sub = 2, + DkBlendOp_RevSub = 3, + DkBlendOp_Min = 4, + DkBlendOp_Max = 5, +} DkBlendOp; + +typedef enum DkBlendFactor +{ + DkBlendFactor_Zero = 1, + DkBlendFactor_One = 2, + DkBlendFactor_SrcColor = 3, + DkBlendFactor_InvSrcColor = 4, + DkBlendFactor_SrcAlpha = 5, + DkBlendFactor_InvSrcAlpha = 6, + DkBlendFactor_DstAlpha = 7, + DkBlendFactor_InvDstAlpha = 8, + DkBlendFactor_DstColor = 9, + DkBlendFactor_InvDstColor = 10, + DkBlendFactor_SrcAlphaSaturate = 11, + DkBlendFactor_Src1Color = 16, + DkBlendFactor_InvSrc1Color = 17, + DkBlendFactor_Src1Alpha = 18, + DkBlendFactor_InvSrc1Alpha = 19, + DkBlendFactor_ConstColor = 1|0x20, + DkBlendFactor_InvConstColor = 2|0x20, + DkBlendFactor_ConstAlpha = 3|0x20, + DkBlendFactor_InvConstAlpha = 4|0x20, +} DkBlendFactor; + +typedef struct DkBlendState +{ + DkBlendOp colorBlendOp : 3; + DkBlendFactor srcColorBlendFactor : 6; + DkBlendFactor dstColorBlendFactor : 6; + + DkBlendOp alphaBlendOp : 3; + DkBlendFactor srcAlphaBlendFactor : 6; + DkBlendFactor dstAlphaBlendFactor : 6; +} DkBlendState; + +DK_CONSTEXPR void dkBlendStateDefaults(DkBlendState* state) +{ + state->colorBlendOp = DkBlendOp_Add; + state->srcColorBlendFactor = DkBlendFactor_SrcAlpha; + state->dstColorBlendFactor = DkBlendFactor_InvSrcAlpha; + + state->alphaBlendOp = DkBlendOp_Add; + state->srcAlphaBlendFactor = DkBlendFactor_One; + state->dstAlphaBlendFactor = DkBlendFactor_Zero; +} + +DK_CONSTEXPR void dkBlendStateSetOps(DkBlendState* state, DkBlendOp colorBlendOp, DkBlendOp alphaBlendOp) +{ + state->colorBlendOp = colorBlendOp; + state->alphaBlendOp = alphaBlendOp; +} + +DK_CONSTEXPR void dkBlendStateSetFactors(DkBlendState* state, DkBlendFactor srcColorBlendFactor, DkBlendFactor dstColorBlendFactor, DkBlendFactor srcAlphaBlendFactor, DkBlendFactor dstAlphaBlendFactor) +{ + state->srcColorBlendFactor = srcColorBlendFactor; + state->dstColorBlendFactor = dstColorBlendFactor; + state->srcAlphaBlendFactor = srcAlphaBlendFactor; + state->dstAlphaBlendFactor = dstAlphaBlendFactor; +} + +typedef enum DkStencilOp +{ + DkStencilOp_Keep = 1, + DkStencilOp_Zero = 2, + DkStencilOp_Replace = 3, + DkStencilOp_Incr = 4, + DkStencilOp_Decr = 5, + DkStencilOp_Invert = 6, + DkStencilOp_IncrWrap = 7, + DkStencilOp_DecrWrap = 8, +} DkStencilOp; + +typedef struct DkDepthStencilState +{ + uint32_t depthTestEnable : 1; + uint32_t depthWriteEnable : 1; + uint32_t stencilTestEnable : 1; + uint32_t : 1; + DkCompareOp depthCompareOp : 4; + uint32_t : 24; + + DkStencilOp stencilFrontFailOp : 4; + DkStencilOp stencilFrontPassOp : 4; + DkStencilOp stencilFrontDepthFailOp : 4; + DkCompareOp stencilFrontCompareOp : 4; + DkStencilOp stencilBackFailOp : 4; + DkStencilOp stencilBackPassOp : 4; + DkStencilOp stencilBackDepthFailOp : 4; + DkCompareOp stencilBackCompareOp : 4; +} DkDepthStencilState; + +DK_CONSTEXPR void dkDepthStencilStateDefaults(DkDepthStencilState* state) +{ + state->depthTestEnable = true; + state->depthWriteEnable = true; + state->stencilTestEnable = false; + state->depthCompareOp = DkCompareOp_Less; + + state->stencilFrontFailOp = DkStencilOp_Keep; + state->stencilFrontPassOp = DkStencilOp_Replace; + state->stencilFrontDepthFailOp = DkStencilOp_Keep; + state->stencilFrontCompareOp = DkCompareOp_Always; + + state->stencilBackFailOp = DkStencilOp_Keep; + state->stencilBackPassOp = DkStencilOp_Replace; + state->stencilBackDepthFailOp = DkStencilOp_Keep; + state->stencilBackCompareOp = DkCompareOp_Always; +} + +typedef enum DkTiledCacheOp +{ + DkTiledCacheOp_Disable = 0, + DkTiledCacheOp_Enable = 1, + DkTiledCacheOp_Flush = 2, + DkTiledCacheOp_FlushAlt = 3, + DkTiledCacheOp_UnkDisable = 4, + DkTiledCacheOp_UnkEnable = 5, +} DkTiledCacheOp; + +typedef enum DkVtxAttribSize +{ + // One to four 32-bit components + DkVtxAttribSize_1x32 = 0x12, + DkVtxAttribSize_2x32 = 0x04, + DkVtxAttribSize_3x32 = 0x02, + DkVtxAttribSize_4x32 = 0x01, + + // One to four 16-bit components + DkVtxAttribSize_1x16 = 0x1b, + DkVtxAttribSize_2x16 = 0x0f, + DkVtxAttribSize_3x16 = 0x05, + DkVtxAttribSize_4x16 = 0x03, + + // One to four 8-bit components + DkVtxAttribSize_1x8 = 0x1d, + DkVtxAttribSize_2x8 = 0x18, + DkVtxAttribSize_3x8 = 0x13, + DkVtxAttribSize_4x8 = 0x0a, + + // Misc arrangements + DkVtxAttribSize_10_10_10_2 = 0x30, + DkVtxAttribSize_11_11_10 = 0x31, +} DkVtxAttribSize; + +typedef enum DkVtxAttribType +{ + DkVtxAttribType_None = 0, + DkVtxAttribType_Snorm = 1, + DkVtxAttribType_Unorm = 2, + DkVtxAttribType_Sint = 3, + DkVtxAttribType_Uint = 4, + DkVtxAttribType_Uscaled = 5, + DkVtxAttribType_Sscaled = 6, + DkVtxAttribType_Float = 7, +} DkVtxAttribType; + +typedef struct DkVtxAttribState +{ + uint32_t bufferId : 5; + uint32_t : 1; + uint32_t isFixed : 1; + uint32_t offset : 14; + DkVtxAttribSize size : 6; + DkVtxAttribType type : 3; + uint32_t : 1; + uint32_t isBgra : 1; +} DkVtxAttribState; + +typedef struct DkVtxBufferState +{ + uint32_t stride; + uint32_t divisor; +} DkVtxBufferState; + +typedef enum DkPrimitive +{ + DkPrimitive_Points = 0, + DkPrimitive_Lines = 1, + DkPrimitive_LineLoop = 2, + DkPrimitive_LineStrip = 3, + DkPrimitive_Triangles = 4, + DkPrimitive_TriangleStrip = 5, + DkPrimitive_TriangleFan = 6, + DkPrimitive_Quads = 7, + DkPrimitive_QuadStrip = 8, + DkPrimitive_Polygon = 9, + DkPrimitive_LinesAdjacency = 10, + DkPrimitive_LineStripAdjacency = 11, + DkPrimitive_TrianglesAdjacency = 12, + DkPrimitive_TriangleStripAdjacency = 13, + DkPrimitive_Patches = 14, +} DkPrimitive; + +typedef enum DkIdxFormat +{ + DkIdxFormat_Uint8 = 0, + DkIdxFormat_Uint16 = 1, + DkIdxFormat_Uint32 = 2, +} DkIdxFormat; + +typedef struct DkDrawIndirectData +{ + uint32_t vertexCount; + uint32_t instanceCount; + uint32_t firstVertex; + uint32_t firstInstance; +} DkDrawIndirectData; + +typedef struct DkDrawIndexedIndirectData +{ + uint32_t indexCount; + uint32_t instanceCount; + uint32_t firstIndex; + int32_t vertexOffset; + uint32_t firstInstance; +} DkDrawIndexedIndirectData; + +typedef struct DkDispatchIndirectData +{ + uint32_t numGroupsX; + uint32_t numGroupsY; + uint32_t numGroupsZ; +} DkDispatchIndirectData; + +enum +{ + // Flip bits (for all) + DkBlitFlag_Flip_Mask = 7U << 0, + DkBlitFlag_FlipX = 1U << 0, // only for BlitImage and CopyDataToImage + DkBlitFlag_FlipY = 1U << 1, + DkBlitFlag_FlipZ = 1U << 2, + + // Filter mode (for BlitImage) + DkBlitFlag_Filter_Mask = 1U << 4, + DkBlitFlag_FilterNearest = 0U << 4, + DkBlitFlag_FilterLinear = 1U << 4, + + // Blit mode (for BlitImage) + DkBlitFlag_Mode_Mask = 7U << 5, + DkBlitFlag_ModeBlit = 0U << 5, + DkBlitFlag_ModeAlphaMask = 1U << 5, + DkBlitFlag_ModeAlphaBlend = 2U << 5, + DkBlitFlag_ModePremultBlit = 3U << 5, + DkBlitFlag_ModePremultBlend = 4U << 5, +}; + +typedef struct DkImageRect +{ + uint32_t x; + uint32_t y; + uint32_t z; + uint32_t width; + uint32_t height; + uint32_t depth; +} DkImageRect; + +typedef struct DkCopyBuf +{ + DkGpuAddr addr; + uint32_t rowLength; + uint32_t imageHeight; +} DkCopyBuf; + +typedef struct DkSwapchainMaker +{ + DkDevice device; + void* nativeWindow; + DkImage const* const* pImages; + uint32_t numImages; +} DkSwapchainMaker; + +DK_CONSTEXPR void dkSwapchainMakerDefaults(DkSwapchainMaker* maker, DkDevice device, void* nativeWindow, DkImage const* const pImages[], uint32_t numImages) +{ + maker->device = device; + maker->nativeWindow = nativeWindow; + maker->pImages = pImages; + maker->numImages = numImages; +} + +#ifdef __cplusplus +extern "C" { +#endif + +DkDevice dkDeviceCreate(DkDeviceMaker const* maker); +void dkDeviceDestroy(DkDevice obj); + +DkMemBlock dkMemBlockCreate(DkMemBlockMaker const* maker); +void dkMemBlockDestroy(DkMemBlock obj); +void* dkMemBlockGetCpuAddr(DkMemBlock obj); +DkGpuAddr dkMemBlockGetGpuAddr(DkMemBlock obj); +uint32_t dkMemBlockGetSize(DkMemBlock obj); +DkResult dkMemBlockFlushCpuCache(DkMemBlock obj, uint32_t offset, uint32_t size); + +DkResult dkFenceWait(DkFence* obj, int64_t timeout_ns); + +DkCmdBuf dkCmdBufCreate(DkCmdBufMaker const* maker); +void dkCmdBufDestroy(DkCmdBuf obj); +void dkCmdBufAddMemory(DkCmdBuf obj, DkMemBlock mem, uint32_t offset, uint32_t size); +DkCmdList dkCmdBufFinishList(DkCmdBuf obj); +void dkCmdBufClear(DkCmdBuf obj); +void dkCmdBufBeginCaptureCmds(DkCmdBuf obj, uint32_t* storage, uint32_t max_words); +uint32_t dkCmdBufEndCaptureCmds(DkCmdBuf obj); +void dkCmdBufReplayCmds(DkCmdBuf obj, const uint32_t* words, uint32_t num_words); +void dkCmdBufCallList(DkCmdBuf obj, DkCmdList list); +void dkCmdBufWaitFence(DkCmdBuf obj, DkFence* fence); +void dkCmdBufSignalFence(DkCmdBuf obj, DkFence* fence, bool flush); +void dkCmdBufBarrier(DkCmdBuf obj, DkBarrier mode, uint32_t invalidateFlags); +void dkCmdBufBindShaders(DkCmdBuf obj, uint32_t stageMask, DkShader const* const shaders[], uint32_t numShaders); +void dkCmdBufBindUniformBuffers(DkCmdBuf obj, DkStage stage, uint32_t firstId, DkBufExtents const buffers[], uint32_t numBuffers); +void dkCmdBufBindStorageBuffers(DkCmdBuf obj, DkStage stage, uint32_t firstId, DkBufExtents const buffers[], uint32_t numBuffers); +void dkCmdBufBindTextures(DkCmdBuf obj, DkStage stage, uint32_t firstId, DkResHandle const handles[], uint32_t numHandles); +void dkCmdBufBindImages(DkCmdBuf obj, DkStage stage, uint32_t firstId, DkResHandle const handles[], uint32_t numHandles); +void dkCmdBufBindImageDescriptorSet(DkCmdBuf obj, DkGpuAddr setAddr, uint32_t numDescriptors); +void dkCmdBufBindSamplerDescriptorSet(DkCmdBuf obj, DkGpuAddr setAddr, uint32_t numDescriptors); +void dkCmdBufBindRenderTargets(DkCmdBuf obj, DkImageView const* const colorTargets[], uint32_t numColorTargets, DkImageView const* depthTarget); +void dkCmdBufBindRasterizerState(DkCmdBuf obj, DkRasterizerState const* state); +void dkCmdBufBindMultisampleState(DkCmdBuf obj, DkMultisampleState const* state); +void dkCmdBufBindColorState(DkCmdBuf obj, DkColorState const* state); +void dkCmdBufBindColorWriteState(DkCmdBuf obj, DkColorWriteState const* state); +void dkCmdBufBindBlendStates(DkCmdBuf obj, uint32_t firstId, DkBlendState const states[], uint32_t numStates); +void dkCmdBufBindDepthStencilState(DkCmdBuf obj, DkDepthStencilState const* state); +void dkCmdBufBindVtxAttribState(DkCmdBuf obj, DkVtxAttribState const attribs[], uint32_t numAttribs); +void dkCmdBufBindVtxBufferState(DkCmdBuf obj, DkVtxBufferState const buffers[], uint32_t numBuffers); +void dkCmdBufBindVtxBuffers(DkCmdBuf obj, uint32_t firstId, DkBufExtents const buffers[], uint32_t numBuffers); +void dkCmdBufBindIdxBuffer(DkCmdBuf obj, DkIdxFormat format, DkGpuAddr address); +void dkCmdBufSetViewports(DkCmdBuf obj, uint32_t firstId, DkViewport const viewports[], uint32_t numViewports); +void dkCmdBufSetViewportSwizzles(DkCmdBuf obj, uint32_t firstId, DkViewportSwizzle const swizzles[], uint32_t numSwizzles); +void dkCmdBufSetSubpixelPrecisionBias(DkCmdBuf obj, uint32_t xbits, uint32_t ybits); +void dkCmdBufSetScissors(DkCmdBuf obj, uint32_t firstId, DkScissor const scissors[], uint32_t numScissors); +void dkCmdBufSetDepthBias(DkCmdBuf obj, float constantFactor, float clamp, float slopeFactor); +void dkCmdBufSetPointSize(DkCmdBuf obj, float size); +void dkCmdBufSetLineWidth(DkCmdBuf obj, float width); +void dkCmdBufSetConservativeRasterEnable(DkCmdBuf obj, bool enable); +void dkCmdBufSetConservativeRasterDilate(DkCmdBuf obj, float dilate); +void dkCmdBufSetSampleMask(DkCmdBuf obj, uint32_t mask); +void dkCmdBufSetCoverageModulationTable(DkCmdBuf obj, float const table[16]); +void dkCmdBufSetDepthBounds(DkCmdBuf obj, bool enable, float near, float far); +void dkCmdBufSetAlphaRef(DkCmdBuf obj, float ref); +void dkCmdBufSetBlendConst(DkCmdBuf obj, float red, float green, float blue, float alpha); +void dkCmdBufSetStencil(DkCmdBuf obj, DkFace face, uint8_t mask, uint8_t funcRef, uint8_t funcMask); +void dkCmdBufSetPrimitiveRestart(DkCmdBuf obj, bool enable, uint32_t index); +void dkCmdBufSetPatchSize(DkCmdBuf obj, uint32_t size); +void dkCmdBufSetTessOuterLevels(DkCmdBuf obj, float level0, float level1, float level2, float level3); +void dkCmdBufSetTessInnerLevels(DkCmdBuf obj, float level0, float level1); +void dkCmdBufSetTileSize(DkCmdBuf obj, uint32_t width, uint32_t height); +void dkCmdBufTiledCacheOp(DkCmdBuf obj, DkTiledCacheOp op); +void dkCmdBufClearColor(DkCmdBuf obj, uint32_t targetId, uint32_t clearMask, const void* clearData); +void dkCmdBufClearDepthStencil(DkCmdBuf obj, bool clearDepth, float depthValue, uint8_t stencilMask, uint8_t stencilValue); +void dkCmdBufDiscardColor(DkCmdBuf obj, uint32_t targetId); +void dkCmdBufDiscardDepthStencil(DkCmdBuf obj); +void dkCmdBufResolveDepthValues(DkCmdBuf obj); +void dkCmdBufDraw(DkCmdBuf obj, DkPrimitive prim, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance); +void dkCmdBufDrawIndirect(DkCmdBuf obj, DkPrimitive prim, DkGpuAddr indirect); +void dkCmdBufDrawIndexed(DkCmdBuf obj, DkPrimitive prim, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance); +void dkCmdBufDrawIndexedIndirect(DkCmdBuf obj, DkPrimitive prim, DkGpuAddr indirect); +void dkCmdBufDispatchCompute(DkCmdBuf obj, uint32_t numGroupsX, uint32_t numGroupsY, uint32_t numGroupsZ); +void dkCmdBufDispatchComputeIndirect(DkCmdBuf obj, DkGpuAddr indirect); +void dkCmdBufPushConstants(DkCmdBuf obj, DkGpuAddr uboAddr, uint32_t uboSize, uint32_t offset, uint32_t size, const void* data); +void dkCmdBufPushData(DkCmdBuf obj, DkGpuAddr addr, const void* data, uint32_t size); +void dkCmdBufCopyBuffer(DkCmdBuf obj, DkGpuAddr srcAddr, DkGpuAddr dstAddr, uint32_t size); +void dkCmdBufCopyImage(DkCmdBuf obj, DkImageView const* srcView, DkImageRect const* srcRect, DkImageView const* dstView, DkImageRect const* dstRect, uint32_t flags); +void dkCmdBufBlitImage(DkCmdBuf obj, DkImageView const* srcView, DkImageRect const* srcRect, DkImageView const* dstView, DkImageRect const* dstRect, uint32_t flags, uint32_t factor); +void dkCmdBufResolveImage(DkCmdBuf obj, DkImageView const* srcView, DkImageView const* dstView); +void dkCmdBufCopyBufferToImage(DkCmdBuf obj, DkCopyBuf const* src, DkImageView const* dstView, DkImageRect const* dstRect, uint32_t flags); +void dkCmdBufCopyImageToBuffer(DkCmdBuf obj, DkImageView const* srcView, DkImageRect const* srcRect, DkCopyBuf const* dst, uint32_t flags); + +DkQueue dkQueueCreate(DkQueueMaker const* maker); +void dkQueueDestroy(DkQueue obj); +bool dkQueueIsInErrorState(DkQueue obj); +void dkQueueWaitFence(DkQueue obj, DkFence* fence); +void dkQueueSignalFence(DkQueue obj, DkFence* fence, bool flush); +void dkQueueSubmitCommands(DkQueue obj, DkCmdList cmds); +void dkQueueFlush(DkQueue obj); +void dkQueueWaitIdle(DkQueue obj); +int dkQueueAcquireImage(DkQueue obj, DkSwapchain swapchain); +void dkQueuePresentImage(DkQueue obj, DkSwapchain swapchain, int imageSlot); + +void dkShaderInitialize(DkShader* obj, DkShaderMaker const* maker); +bool dkShaderIsValid(DkShader const* obj); +DkStage dkShaderGetStage(DkShader const* obj); + +void dkImageLayoutInitialize(DkImageLayout* obj, DkImageLayoutMaker const* maker); +uint64_t dkImageLayoutGetSize(DkImageLayout const* obj); +uint32_t dkImageLayoutGetAlignment(DkImageLayout const* obj); + +void dkImageInitialize(DkImage* obj, DkImageLayout const* layout, DkMemBlock memBlock, uint32_t offset); +DkGpuAddr dkImageGetGpuAddr(DkImage const* obj); + +void dkImageDescriptorInitialize(DkImageDescriptor* obj, DkImageView const* view, bool usesLoadOrStore, bool decayMS); + +void dkSamplerDescriptorInitialize(DkSamplerDescriptor* obj, DkSampler const* sampler); + +void dkMultisampleStateSetLocations(DkMultisampleState* obj, DkSampleLocation const* locations, uint32_t numLocations); + +DkSwapchain dkSwapchainCreate(DkSwapchainMaker const* maker); +void dkSwapchainDestroy(DkSwapchain obj); +void dkSwapchainAcquireImage(DkSwapchain obj, int* imageSlot, DkFence* fence); +void dkSwapchainSetCrop(DkSwapchain obj, int32_t left, int32_t top, int32_t right, int32_t bottom); +void dkSwapchainSetSwapInterval(DkSwapchain obj, uint32_t interval); + +static inline void dkCmdBufBindUniformBuffer(DkCmdBuf obj, DkStage stage, uint32_t id, DkGpuAddr bufAddr, uint32_t bufSize) +{ + DkBufExtents ext = { bufAddr, bufSize }; + dkCmdBufBindUniformBuffers(obj, stage, id, &ext, 1); +} + +static inline void dkCmdBufBindStorageBuffer(DkCmdBuf obj, DkStage stage, uint32_t id, DkGpuAddr bufAddr, uint32_t bufSize) +{ + DkBufExtents ext = { bufAddr, bufSize }; + dkCmdBufBindStorageBuffers(obj, stage, id, &ext, 1); +} + +static inline void dkCmdBufBindTexture(DkCmdBuf obj, DkStage stage, uint32_t id, DkResHandle handle) +{ + dkCmdBufBindTextures(obj, stage, id, &handle, 1); +} + +static inline void dkCmdBufBindImage(DkCmdBuf obj, DkStage stage, uint32_t id, DkResHandle handle) +{ + dkCmdBufBindImages(obj, stage, id, &handle, 1); +} + +static inline void dkCmdBufBindRenderTarget(DkCmdBuf obj, DkImageView const* colorTarget, DkImageView const* depthTarget) +{ + dkCmdBufBindRenderTargets(obj, &colorTarget, 1, depthTarget); +} + +static inline void dkCmdBufBindBlendState(DkCmdBuf obj, uint32_t id, DkBlendState const* state) +{ + dkCmdBufBindBlendStates(obj, id, state, 1); +} + +static inline void dkCmdBufBindVtxBuffer(DkCmdBuf obj, uint32_t id, DkGpuAddr bufAddr, uint32_t bufSize) +{ + DkBufExtents ext = { bufAddr, bufSize }; + dkCmdBufBindVtxBuffers(obj, id, &ext, 1); +} + +static inline void dkCmdBufClearColorFloat(DkCmdBuf obj, uint32_t targetId, uint32_t clearMask, float red, float green, float blue, float alpha) +{ + float data[] = { red, green, blue, alpha }; + dkCmdBufClearColor(obj, targetId, clearMask, data); +} + +static inline void dkCmdBufClearColorSint(DkCmdBuf obj, uint32_t targetId, uint32_t clearMask, int32_t red, int32_t green, int32_t blue, int32_t alpha) +{ + int32_t data[] = { red, green, blue, alpha }; + dkCmdBufClearColor(obj, targetId, clearMask, data); +} + +static inline void dkCmdBufClearColorUint(DkCmdBuf obj, uint32_t targetId, uint32_t clearMask, uint32_t red, uint32_t green, uint32_t blue, uint32_t alpha) +{ + uint32_t data[] = { red, green, blue, alpha }; + dkCmdBufClearColor(obj, targetId, clearMask, data); +} + +static inline DkImageLayout const* dkImageGetLayout(DkImage const* obj) +{ + return (DkImageLayout const*)obj; +} + +#ifdef __cplusplus +} +#endif diff --git a/troposphere/daybreak/nanovg/include/nanovg/deko3d.hpp b/troposphere/daybreak/nanovg/include/nanovg/deko3d.hpp new file mode 100644 index 000000000..022138fa8 --- /dev/null +++ b/troposphere/daybreak/nanovg/include/nanovg/deko3d.hpp @@ -0,0 +1,1108 @@ +/* +**----------------------------------------------------------------------------- +** deko3d.hpp - C++ wrapper interface for deko3d +**----------------------------------------------------------------------------- +** +** Copyright (C) 2018-2020 fincs +** +** This software is provided 'as-is', without any express or implied +** warranty. In no event will the authors be held liable for any +** damages arising from the use of this software. +** +** Permission is granted to anyone to use this software for any +** purpose, including commercial applications, and to alter it and +** redistribute it freely, subject to the following restrictions: +** +** 1. The origin of this software must not be misrepresented; you +** must not claim that you wrote the original software. If you use +** this software in a product, an acknowledgment in the product +** documentation would be appreciated but is not required. +** 2. Altered source versions must be plainly marked as such, and +** must not be misrepresented as being the original software. +** 3. This notice may not be removed or altered from any source +** distribution. +** +** This file is currently written by hand; in the future it might be autogenerated. +** +*/ + +#pragma once +#include +#include +#include +#ifdef DK_HPP_SUPPORT_VECTOR +#include +#endif +#include "deko3d.h" + +namespace dk +{ + namespace detail + { + template + class Handle + { + T m_handle; + protected: + void _clear() noexcept { m_handle = nullptr; } + void _set(T h) noexcept { _clear(); m_handle = h; } + public: + using Type = T; + constexpr Handle() noexcept : m_handle{} { } + constexpr Handle(std::nullptr_t) noexcept : m_handle{} { } + constexpr Handle(T handle) noexcept : m_handle{handle} { } + constexpr operator T() const noexcept { return m_handle; } + constexpr operator bool() const noexcept { return m_handle != nullptr; } + constexpr bool operator !() const noexcept { return m_handle == nullptr; } + }; + + template + constexpr bool operator==(Handle const& lhs, Handle const& rhs) + { + return static_cast(lhs) == static_cast(rhs); + } + + template + constexpr bool operator!=(Handle const& lhs, Handle const& rhs) + { + return !(lhs == rhs); + } + + template + struct UniqueHandle final : public T + { + UniqueHandle() noexcept : T{} { } + UniqueHandle(UniqueHandle&) = delete; + constexpr UniqueHandle(T&& rhs) noexcept : T{rhs} { rhs = nullptr; } + ~UniqueHandle() + { + if (*this) T::destroy(); + } + UniqueHandle& operator=(std::nullptr_t) { if (*this) T::destroy(); return *this; } + UniqueHandle& operator=(UniqueHandle const&) = delete; + UniqueHandle& operator=(UniqueHandle&& rhs) { T::_set(rhs); rhs._clear(); return *this; } + }; + + template + struct Opaque : public T + { + constexpr Opaque() noexcept : T{} { } + }; + + // ArrayProxy borrowed from Vulkan-Hpp with ♥ + template + class ArrayProxy + { + using nonconst_T = typename std::remove_const::type; + using nonref_T = typename std::remove_reference::type; + uint32_t m_count; + T* m_ptr; + public: + constexpr ArrayProxy(std::nullptr_t) noexcept : m_count{}, m_ptr{} { } + ArrayProxy(nonref_T& ptr) : m_count{1}, m_ptr(&ptr) { } + ArrayProxy(uint32_t count, T* ptr) noexcept : m_count{count}, m_ptr{ptr} { } + + template + ArrayProxy(std::array& data) noexcept : + m_count{N}, m_ptr{data.data()} { } + + template + ArrayProxy(std::array const& data) noexcept : + m_count{N} , m_ptr{data.data()} { } + + ArrayProxy(std::initializer_list const& data) noexcept : + m_count{static_cast(data.end() - data.begin())}, + m_ptr{data.begin()} { } + +#ifdef DK_HPP_SUPPORT_VECTOR + template > + ArrayProxy(std::vector & data) noexcept : + m_count{static_cast(data.size())}, + m_ptr{data.data()} { } + + template > + ArrayProxy(std::vector const& data) noexcept : + m_count{static_cast(data.size())}, + m_ptr{data.data()} { } +#endif + + const T* begin() const noexcept { return m_ptr; } + const T* end() const noexcept { return m_ptr + m_count; } + const T& front() const noexcept { return *m_ptr; } + const T& back() const noexcept { return *(m_ptr + m_count - 1); } + bool empty() const noexcept { return m_count == 0; } + uint32_t size() const noexcept { return m_count; } + T* data() const noexcept { return m_ptr; } + }; + } + +#define DK_HANDLE_COMMON_MEMBERS(_name) \ + constexpr _name() noexcept : Handle{} { } \ + constexpr _name(std::nullptr_t arg) noexcept : Handle{arg} { } \ + constexpr _name(::Dk##_name arg) noexcept : Handle{arg} { } \ + _name& operator=(std::nullptr_t) noexcept { _clear(); return *this; } \ + void destroy() + +#define DK_OPAQUE_COMMON_MEMBERS(_name) \ + constexpr _name() noexcept : Opaque{} { } + + struct Device : public detail::Handle<::DkDevice> + { + DK_HANDLE_COMMON_MEMBERS(Device); + }; + + struct MemBlock : public detail::Handle<::DkMemBlock> + { + DK_HANDLE_COMMON_MEMBERS(MemBlock); + void* getCpuAddr(); + DkGpuAddr getGpuAddr(); + uint32_t getSize(); + DkResult flushCpuCache(uint32_t offset, uint32_t size); + }; + + struct Fence : public detail::Opaque<::DkFence> + { + DK_OPAQUE_COMMON_MEMBERS(Fence); + DkResult wait(int64_t timeout_ns = -1); + }; + + struct CmdBuf : public detail::Handle<::DkCmdBuf> + { + DK_HANDLE_COMMON_MEMBERS(CmdBuf); + void addMemory(DkMemBlock mem, uint32_t offset, uint32_t size); + DkCmdList finishList(); + void clear(); + void beginCaptureCmds(uint32_t* storage, uint32_t max_words); + uint32_t endCaptureCmds(); + void replayCmds(detail::ArrayProxy words); + void callList(DkCmdList list); + void waitFence(DkFence& fence); + void signalFence(DkFence& fence, bool flush = false); + void barrier(DkBarrier mode, uint32_t invalidateFlags); + void bindShaders(uint32_t stageMask, detail::ArrayProxy shaders); + void bindUniformBuffer(DkStage stage, uint32_t id, DkGpuAddr bufAddr, uint32_t bufSize); + void bindUniformBuffers(DkStage stage, uint32_t firstId, detail::ArrayProxy buffers); + void bindStorageBuffer(DkStage stage, uint32_t id, DkGpuAddr bufAddr, uint32_t bufSize); + void bindStorageBuffers(DkStage stage, uint32_t firstId, detail::ArrayProxy buffers); + void bindTextures(DkStage stage, uint32_t firstId, detail::ArrayProxy handles); + void bindImages(DkStage stage, uint32_t firstId, detail::ArrayProxy handles); + void bindImageDescriptorSet(DkGpuAddr setAddr, uint32_t numDescriptors); + void bindSamplerDescriptorSet(DkGpuAddr setAddr, uint32_t numDescriptors); + void bindRenderTargets(detail::ArrayProxy colorTargets, DkImageView const* depthTarget = nullptr); + void bindRasterizerState(DkRasterizerState const& state); + void bindMultisampleState(DkMultisampleState const& state); + void bindColorState(DkColorState const& state); + void bindColorWriteState(DkColorWriteState const& state); + void bindBlendStates(uint32_t id, detail::ArrayProxy states); + void bindDepthStencilState(DkDepthStencilState const& state); + void bindVtxAttribState(detail::ArrayProxy attribs); + void bindVtxBufferState(detail::ArrayProxy buffers); + void bindVtxBuffer(uint32_t id, DkGpuAddr bufAddr, uint32_t bufSize); + void bindVtxBuffers(uint32_t firstId, detail::ArrayProxy buffers); + void bindIdxBuffer(DkIdxFormat format, DkGpuAddr address); + void setViewports(uint32_t firstId, detail::ArrayProxy viewports); + void setViewportSwizzles(uint32_t firstId, detail::ArrayProxy swizzles); + void setSubpixelPrecisionBias(uint32_t xbits, uint32_t ybits); + void setScissors(uint32_t firstId, detail::ArrayProxy scissors); + void setDepthBias(float constantFactor, float clamp, float slopeFactor); + void setPointSize(float size); + void setLineWidth(float width); + void setConservativeRasterEnable(bool enable); + void setConservativeRasterDilate(float dilate); + void setSampleMask(uint32_t mask); + void setCoverageModulationTable(float const table[16]); + void setDepthBounds(bool enable, float near, float far); + void setAlphaRef(float ref); + void setBlendConst(float red, float green, float blue, float alpha); + void setStencil(DkFace face, uint8_t mask, uint8_t funcRef, uint8_t funcMask); + void setPrimitiveRestart(bool enable, uint32_t index); + void setPatchSize(uint32_t size); + void setTessOuterLevels(float level0, float level1, float level2, float level3 = 0.0f); + void setTessInnerLevels(float level0, float level1 = 0.0f); + void setTileSize(uint32_t width, uint32_t height); + void tiledCacheOp(DkTiledCacheOp op); + void clearColor(uint32_t targetId, uint32_t clearMask, const void* clearData); + template void clearColor(uint32_t targetId, uint32_t clearMask, T red = T{0}, T green = T{0}, T blue = T{0}, T alpha = T{0}); + void clearDepthStencil(bool clearDepth, float depthValue, uint8_t stencilMask, uint8_t stencilValue); + void discardColor(uint32_t targetId); + void discardDepthStencil(); + void resolveDepthValues(); + void draw(DkPrimitive prim, uint32_t numVertices, uint32_t numInstances, uint32_t firstVertex, uint32_t firstInstance); + void drawIndirect(DkPrimitive prim, DkGpuAddr indirect); + void drawIndexed(DkPrimitive prim, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance); + void drawIndexedIndirect(DkPrimitive prim, DkGpuAddr indirect); + void dispatchCompute(uint32_t numGroupsX, uint32_t numGroupsY, uint32_t numGroupsZ); + void dispatchComputeIndirect(DkGpuAddr indirect); + void pushConstants(DkGpuAddr uboAddr, uint32_t uboSize, uint32_t offset, uint32_t size, const void* data); + void pushData(DkGpuAddr addr, const void* data, uint32_t size); + void copyBuffer(DkGpuAddr srcAddr, DkGpuAddr dstAddr, uint32_t size); + void copyImage(DkImageView const& srcView, DkImageRect const& srcRect, DkImageView const& dstView, DkImageRect const& dstRect, uint32_t flags = 0); + void blitImage(DkImageView const& srcView, DkImageRect const& srcRect, DkImageView const& dstView, DkImageRect const& dstRect, uint32_t flags = 0, uint32_t factor = 0); + void resolveImage(DkImageView const& srcView, DkImageView const& dstView); + void copyBufferToImage(DkCopyBuf const& src, DkImageView const& dstView, DkImageRect const& dstRect, uint32_t flags = 0); + void copyImageToBuffer(DkImageView const& srcView, DkImageRect const& srcRect, DkCopyBuf const& dst, uint32_t flags = 0); + }; + + struct Queue : public detail::Handle<::DkQueue> + { + DK_HANDLE_COMMON_MEMBERS(Queue); + bool isInErrorState(); + void waitFence(DkFence& fence); + void signalFence(DkFence& fence, bool flush = false); + void submitCommands(DkCmdList cmds); + void flush(); + void waitIdle(); + int acquireImage(DkSwapchain swapchain); + void presentImage(DkSwapchain swapchain, int imageSlot); + }; + + struct Shader : public detail::Opaque<::DkShader> + { + DK_OPAQUE_COMMON_MEMBERS(Shader); + bool isValid() const; + DkStage getStage() const; + }; + + struct ImageLayout : public detail::Opaque<::DkImageLayout> + { + DK_OPAQUE_COMMON_MEMBERS(ImageLayout); + uint64_t getSize() const; + uint32_t getAlignment() const; + }; + + struct Image : public detail::Opaque<::DkImage> + { + DK_OPAQUE_COMMON_MEMBERS(Image); + void initialize(ImageLayout const& layout, DkMemBlock memBlock, uint32_t offset); + DkGpuAddr getGpuAddr() const; + ImageLayout const& getLayout() const; + }; + + struct Swapchain : public detail::Handle<::DkSwapchain> + { + DK_HANDLE_COMMON_MEMBERS(Swapchain); + void acquireImage(int& imageSlot, DkFence& fence); + void setCrop(int32_t left, int32_t top, int32_t right, int32_t bottom); + void setSwapInterval(uint32_t interval); + }; + + struct DeviceMaker : public ::DkDeviceMaker + { + DeviceMaker() noexcept : DkDeviceMaker{} { ::dkDeviceMakerDefaults(this); } + DeviceMaker(DeviceMaker&) = default; + DeviceMaker(DeviceMaker&&) = default; + DeviceMaker& setUserData(void* userData) noexcept { this->userData = userData; return *this; } + DeviceMaker& setCbDebug(DkDebugFunc cbDebug) noexcept { this->cbDebug = cbDebug; return *this; } + DeviceMaker& setCbAlloc(DkAllocFunc cbAlloc) noexcept { this->cbAlloc = cbAlloc; return *this; } + DeviceMaker& setCbFree(DkFreeFunc cbFree) noexcept { this->cbFree = cbFree; return *this; } + DeviceMaker& setFlags(uint32_t flags) noexcept { this->flags = flags; return *this; } + Device create() const; + }; + + struct MemBlockMaker : public ::DkMemBlockMaker + { + MemBlockMaker(DkDevice device, uint32_t size) noexcept : DkMemBlockMaker{} { ::dkMemBlockMakerDefaults(this, device, size); } + MemBlockMaker(MemBlockMaker&) = default; + MemBlockMaker(MemBlockMaker&&) = default; + MemBlockMaker& setFlags(uint32_t flags) noexcept { this->flags = flags; return *this; } + MemBlockMaker& setStorage(void* storage) noexcept { this->storage = storage; return *this; } + MemBlock create() const; + }; + + struct CmdBufMaker : public ::DkCmdBufMaker + { + CmdBufMaker(DkDevice device) noexcept : DkCmdBufMaker{} { ::dkCmdBufMakerDefaults(this, device); } + CmdBufMaker& setUserData(void* userData) noexcept { this->userData = userData; return *this; } + CmdBufMaker& setCbAddMem(DkCmdBufAddMemFunc cbAddMem) noexcept { this->cbAddMem = cbAddMem; return *this; } + CmdBuf create() const; + }; + + struct QueueMaker : public ::DkQueueMaker + { + QueueMaker(DkDevice device) noexcept : DkQueueMaker{} { ::dkQueueMakerDefaults(this, device); } + QueueMaker& setFlags(uint32_t flags) noexcept { this->flags = flags; return *this; } + QueueMaker& setCommandMemorySize(uint32_t commandMemorySize) noexcept { this->commandMemorySize = commandMemorySize; return *this; } + QueueMaker& setFlushThreshold(uint32_t flushThreshold) noexcept { this->flushThreshold = flushThreshold; return *this; } + QueueMaker& setPerWarpScratchMemorySize(uint32_t perWarpScratchMemorySize) noexcept { this->perWarpScratchMemorySize = perWarpScratchMemorySize; return *this; } + QueueMaker& setMaxConcurrentComputeJobs(uint32_t maxConcurrentComputeJobs) noexcept { this->maxConcurrentComputeJobs = maxConcurrentComputeJobs; return *this; } + Queue create() const; + }; + + struct ShaderMaker : public ::DkShaderMaker + { + ShaderMaker(DkMemBlock codeMem, uint32_t codeOffset) noexcept : DkShaderMaker{} { ::dkShaderMakerDefaults(this, codeMem, codeOffset); } + ShaderMaker& setControl(const void* control) noexcept { this->control = control; return *this; } + ShaderMaker& setProgramId(uint32_t programId) noexcept { this->programId = programId; return *this; } + void initialize(Shader& obj) const; + }; + + struct ImageLayoutMaker : public ::DkImageLayoutMaker + { + ImageLayoutMaker(DkDevice device) noexcept : DkImageLayoutMaker{} { ::dkImageLayoutMakerDefaults(this, device); } + ImageLayoutMaker& setType(DkImageType type) noexcept { this->type = type; return *this; } + ImageLayoutMaker& setFlags(uint32_t flags) noexcept { this->flags = flags; return *this; } + ImageLayoutMaker& setFormat(DkImageFormat format) noexcept { this->format = format; return *this; } + ImageLayoutMaker& setMsMode(DkMsMode msMode) noexcept { this->msMode = msMode; return *this; } + ImageLayoutMaker& setDimensions(uint32_t width, uint32_t height = 0, uint32_t depth = 0) noexcept + { + this->dimensions[0] = width; + this->dimensions[1] = height; + this->dimensions[2] = depth; + return *this; + } + ImageLayoutMaker& setMipLevels(uint32_t mipLevels) noexcept { this->mipLevels = mipLevels; return *this; } + ImageLayoutMaker& setPitchStride(uint32_t pitchStride) noexcept { this->pitchStride = pitchStride; return *this; } + ImageLayoutMaker& setTileSize(DkTileSize tileSize) noexcept { this->tileSize = tileSize; return *this; } + void initialize(ImageLayout& obj) const; + }; + + struct ImageView : public ::DkImageView + { + ImageView(Image const& image) noexcept : DkImageView{} { ::dkImageViewDefaults(this, &image); } + ImageView& setType(DkImageType type = DkImageType_None) noexcept { this->type = type; return *this; } + ImageView& setFormat(DkImageFormat format = DkImageFormat_None) noexcept { this->format = format; return *this; } + ImageView& setSwizzle(DkImageSwizzle x = DkImageSwizzle_Red, DkImageSwizzle y = DkImageSwizzle_Green, DkImageSwizzle z = DkImageSwizzle_Blue, DkImageSwizzle w = DkImageSwizzle_Alpha) noexcept + { + this->swizzle[0] = x; + this->swizzle[1] = y; + this->swizzle[2] = z; + this->swizzle[3] = w; + return *this; + } + ImageView& setDsSource(DkDsSource dsSource) noexcept { this->dsSource = dsSource; return *this; } + ImageView& setLayers(uint16_t layerOffset = 0, uint16_t layerCount = 0) noexcept + { + this->layerOffset = layerOffset; + this->layerCount = layerCount; + return *this; + } + ImageView& setMipLevels(uint8_t mipLevelOffset = 0, uint8_t mipLevelCount = 0) noexcept + { + this->mipLevelOffset = mipLevelOffset; + this->mipLevelCount = mipLevelCount; + return *this; + } + }; + + struct ImageDescriptor : public detail::Opaque<::DkImageDescriptor> + { + DK_OPAQUE_COMMON_MEMBERS(ImageDescriptor); + void initialize(ImageView const& view, bool usesLoadOrStore = false, bool decayMS = false); + }; + + struct Sampler : public ::DkSampler + { + Sampler() noexcept : DkSampler{} { ::dkSamplerDefaults(this); } + Sampler& setFilter(DkFilter min = DkFilter_Nearest, DkFilter mag = DkFilter_Nearest, DkMipFilter mip = DkMipFilter_None) + { + this->minFilter = min; + this->magFilter = mag; + this->mipFilter = mip; + return *this; + } + Sampler& setWrapMode(DkWrapMode u = DkWrapMode_Repeat, DkWrapMode v = DkWrapMode_Repeat, DkWrapMode p = DkWrapMode_Repeat) + { + this->wrapMode[0] = u; + this->wrapMode[1] = v; + this->wrapMode[2] = p; + return *this; + } + Sampler& setLodClamp(float min, float max) + { + this->lodClampMin = min; + this->lodClampMax = max; + return *this; + } + Sampler& setLodBias(float bias) { this->lodBias = bias; return *this; } + Sampler& setLodSnap(float snap) { this->lodSnap = snap; return *this; } + Sampler& setDepthCompare(bool enable, DkCompareOp op = DkCompareOp_Less) + { + this->compareEnable = enable; + this->compareOp = op; + return *this; + } + Sampler& setBorderColor(float r, float g, float b, float a) + { + this->borderColor[0].value_f = r; + this->borderColor[1].value_f = g; + this->borderColor[2].value_f = b; + this->borderColor[3].value_f = a; + return *this; + } + Sampler& setBorderColor(uint32_t r, uint32_t g, uint32_t b, uint32_t a) + { + this->borderColor[0].value_ui = r; + this->borderColor[1].value_ui = g; + this->borderColor[2].value_ui = b; + this->borderColor[3].value_ui = a; + return *this; + } + Sampler& setBorderColor(int32_t r, int32_t g, int32_t b, int32_t a) + { + this->borderColor[0].value_i = r; + this->borderColor[1].value_i = g; + this->borderColor[2].value_i = b; + this->borderColor[3].value_i = a; + return *this; + } + Sampler& setMaxAnisotropy(float max) { this->maxAnisotropy = max; return *this; } + Sampler& setReductionMode(DkSamplerReduction mode) { this->reductionMode = mode; return *this; } + }; + + struct SamplerDescriptor : public detail::Opaque<::DkSamplerDescriptor> + { + DK_OPAQUE_COMMON_MEMBERS(SamplerDescriptor); + void initialize(Sampler const& sampler); + }; + + struct RasterizerState : public ::DkRasterizerState + { + RasterizerState() : DkRasterizerState{} { ::dkRasterizerStateDefaults(this); } + RasterizerState& setRasterizerEnable(bool enable) { this->rasterizerEnable = enable; return *this; } + RasterizerState& setDepthClampEnable(bool enable) { this->depthClampEnable = enable; return *this; } + RasterizerState& setFillRectangleEnable(bool enable) { this->fillRectangleEnable = enable; return *this; } + RasterizerState& setPolygonMode(DkPolygonMode mode) { this->polygonModeFront = this->polygonModeBack = mode; return *this; } + RasterizerState& setPolygonModeFront(DkPolygonMode mode) { this->polygonModeFront = mode; return *this; } + RasterizerState& setPolygonModeBack(DkPolygonMode mode) { this->polygonModeBack = mode; return *this; } + RasterizerState& setCullMode(DkFace cullMode) { this->cullMode = cullMode; return *this; } + RasterizerState& setFrontFace(DkFrontFace frontFace) { this->frontFace = frontFace; return *this; } + RasterizerState& setPolygonSmoothEnable(bool enable) { this->polygonSmoothEnableMask = enable ? DkPolygonFlag_All : 0; return *this; } + RasterizerState& setPolygonSmoothEnableMask(uint32_t mask) { this->polygonSmoothEnableMask = mask; return *this; } + RasterizerState& setDepthBiasEnable(bool enable) { this->depthBiasEnableMask = enable ? DkPolygonFlag_All : 0; return *this; } + RasterizerState& setDepthBiasEnableMask(uint32_t mask) { this->depthBiasEnableMask = mask; return *this; } + }; + + struct MultisampleState : public ::DkMultisampleState + { + MultisampleState() : DkMultisampleState{} { ::dkMultisampleStateDefaults(this); } + MultisampleState& setMode(DkMsMode mode) { this->mode = mode; return *this; } + MultisampleState& setRasterizerMode(DkMsMode mode) { this->rasterizerMode = mode; return *this; } + MultisampleState& setAlphaToCoverageEnable(bool enable) { this->alphaToCoverageEnable = enable; return *this; } + MultisampleState& setAlphaToCoverageDither(bool dither) { this->alphaToCoverageDither = dither; return *this; } + MultisampleState& setCoverageToColorEnable(bool enable) { this->coverageToColorEnable = enable; return *this; } + MultisampleState& setCoverageToColorOutput(unsigned output) { this->coverageToColorOutput = output; return *this; } + MultisampleState& setCoverageModulation(DkCoverageModulation mod) { this->coverageModulation = mod; return *this; } + MultisampleState& setLocations() { ::dkMultisampleStateSetLocations(this, nullptr, 0); return *this; } + MultisampleState& setLocations(detail::ArrayProxy locations); + }; + + struct ColorState : public ::DkColorState + { + ColorState() : DkColorState{} { ::dkColorStateDefaults(this); } + ColorState& setBlendEnable(uint32_t id, bool enable) { ::dkColorStateSetBlendEnable(this, id, enable); return *this; } + ColorState& setBlendEnableMask(uint8_t mask) { this->blendEnableMask = mask; return *this; } + ColorState& setLogicOp(DkLogicOp op) { this->logicOp = op; return *this; } + ColorState& setAlphaCompareOp(DkCompareOp op) { this->alphaCompareOp = op; return *this; } + }; + + struct ColorWriteState : public ::DkColorWriteState + { + ColorWriteState() : DkColorWriteState{} { ::dkColorWriteStateDefaults(this); } + ColorWriteState& setMask(uint32_t id, uint32_t colorWriteMask) { ::dkColorWriteStateSetMask(this, id, colorWriteMask); return *this; } + }; + + struct BlendState : public ::DkBlendState + { + BlendState() : DkBlendState{} { ::dkBlendStateDefaults(this); } + BlendState& setOps(DkBlendOp colorBlendOp, DkBlendOp alphaBlendOp) { ::dkBlendStateSetOps(this, colorBlendOp, alphaBlendOp); return *this; } + BlendState& setFactors(DkBlendFactor srcColorBlendFactor, DkBlendFactor dstColorBlendFactor, DkBlendFactor srcAlphaBlendFactor, DkBlendFactor dstAlphaBlendFactor) { ::dkBlendStateSetFactors(this, srcColorBlendFactor, dstColorBlendFactor, srcAlphaBlendFactor, dstAlphaBlendFactor); return *this; } + BlendState& setColorBlendOp(DkBlendOp colorBlendOp) { this->colorBlendOp = colorBlendOp; return *this; } + BlendState& setSrcColorBlendFactor(DkBlendFactor srcColorBlendFactor) { this->srcColorBlendFactor = srcColorBlendFactor; return *this; } + BlendState& setDstColorBlendFactor(DkBlendFactor dstColorBlendFactor) { this->dstColorBlendFactor = dstColorBlendFactor; return *this; } + BlendState& setAlphaBlendOp(DkBlendOp alphaBlendOp) { this->alphaBlendOp = alphaBlendOp; return *this; } + BlendState& setSrcAlphaBlendFactor(DkBlendFactor srcAlphaBlendFactor) { this->srcAlphaBlendFactor = srcAlphaBlendFactor; return *this; } + BlendState& setDstAlphaBlendFactor(DkBlendFactor dstAlphaBlendFactor) { this->dstAlphaBlendFactor = dstAlphaBlendFactor; return *this; } + }; + + struct DepthStencilState : public ::DkDepthStencilState + { + DepthStencilState() : DkDepthStencilState{} { ::dkDepthStencilStateDefaults(this); } + DepthStencilState& setDepthTestEnable(bool enable) { this->depthTestEnable = enable; return *this; } + DepthStencilState& setDepthWriteEnable(bool enable) { this->depthWriteEnable = enable; return *this; } + DepthStencilState& setStencilTestEnable(bool enable) { this->stencilTestEnable = enable; return *this; } + DepthStencilState& setDepthCompareOp(DkCompareOp op) { this->depthCompareOp = op; return *this; } + DepthStencilState& setStencilFrontFailOp(DkStencilOp op) { this->stencilFrontFailOp = op; return *this; } + DepthStencilState& setStencilFrontPassOp(DkStencilOp op) { this->stencilFrontPassOp = op; return *this; } + DepthStencilState& setStencilFrontDepthFailOp(DkStencilOp op) { this->stencilFrontDepthFailOp = op; return *this; } + DepthStencilState& setStencilFrontCompareOp(DkCompareOp op) { this->stencilFrontCompareOp = op; return *this; } + DepthStencilState& setStencilBackFailOp(DkStencilOp op) { this->stencilBackFailOp = op; return *this; } + DepthStencilState& setStencilBackPassOp(DkStencilOp op) { this->stencilBackPassOp = op; return *this; } + DepthStencilState& setStencilBackDepthFailOp(DkStencilOp op) { this->stencilBackDepthFailOp = op; return *this; } + DepthStencilState& setStencilBackCompareOp(DkCompareOp op) { this->stencilBackCompareOp = op; return *this; } + }; + + struct SwapchainMaker : public ::DkSwapchainMaker + { + SwapchainMaker(DkDevice device, void* nativeWindow, DkImage const* const pImages[], uint32_t numImages) noexcept : DkSwapchainMaker{} { ::dkSwapchainMakerDefaults(this, device, nativeWindow, pImages, numImages); } + template SwapchainMaker(DkDevice device, void* nativeWindow, std::array const& images) noexcept : SwapchainMaker{device, nativeWindow, images.data(), (uint32_t)images.size()} { } +#ifdef DK_HPP_SUPPORT_VECTOR + SwapchainMaker(DkDevice device, void* nativeWindow, std::vector const& images) noexcept : SwapchainMaker{device, nativeWindow, images.data(), images.size()} { } +#endif + Swapchain create() const; + }; + + inline Device DeviceMaker::create() const + { + return Device{::dkDeviceCreate(this)}; + } + + inline void Device::destroy() + { + ::dkDeviceDestroy(*this); + _clear(); + } + + inline MemBlock MemBlockMaker::create() const + { + return MemBlock{::dkMemBlockCreate(this)}; + } + + inline void MemBlock::destroy() + { + ::dkMemBlockDestroy(*this); + _clear(); + } + + inline void* MemBlock::getCpuAddr() + { + return ::dkMemBlockGetCpuAddr(*this); + } + + inline DkGpuAddr MemBlock::getGpuAddr() + { + return ::dkMemBlockGetGpuAddr(*this); + } + + inline uint32_t MemBlock::getSize() + { + return ::dkMemBlockGetSize(*this); + } + + inline DkResult MemBlock::flushCpuCache(uint32_t offset, uint32_t size) + { + return ::dkMemBlockFlushCpuCache(*this, offset, size); + } + + inline DkResult Fence::wait(int64_t timeout_ns) + { + return ::dkFenceWait(this, timeout_ns); + } + + inline CmdBuf CmdBufMaker::create() const + { + return CmdBuf{::dkCmdBufCreate(this)}; + } + + inline void CmdBuf::destroy() + { + ::dkCmdBufDestroy(*this); + _clear(); + } + + inline void CmdBuf::addMemory(DkMemBlock mem, uint32_t offset, uint32_t size) + { + ::dkCmdBufAddMemory(*this, mem, offset, size); + } + + inline DkCmdList CmdBuf::finishList() + { + return ::dkCmdBufFinishList(*this); + } + + inline void CmdBuf::clear() + { + ::dkCmdBufClear(*this); + } + + inline void CmdBuf::beginCaptureCmds(uint32_t* storage, uint32_t max_words) + { + ::dkCmdBufBeginCaptureCmds(*this, storage, max_words); + } + + inline uint32_t CmdBuf::endCaptureCmds() + { + return ::dkCmdBufEndCaptureCmds(*this); + } + + inline void CmdBuf::replayCmds(detail::ArrayProxy words) + { + ::dkCmdBufReplayCmds(*this, words.data(), words.size()); + } + + inline void CmdBuf::callList(DkCmdList list) + { + ::dkCmdBufCallList(*this, list); + } + + inline void CmdBuf::waitFence(DkFence& fence) + { + return ::dkCmdBufWaitFence(*this, &fence); + } + + inline void CmdBuf::signalFence(DkFence& fence, bool flush) + { + return ::dkCmdBufSignalFence(*this, &fence, flush); + } + + inline void CmdBuf::barrier(DkBarrier mode, uint32_t invalidateFlags) + { + ::dkCmdBufBarrier(*this, mode, invalidateFlags); + } + + inline void CmdBuf::bindShaders(uint32_t stageMask, detail::ArrayProxy shaders) + { + ::dkCmdBufBindShaders(*this, stageMask, shaders.data(), shaders.size()); + } + + inline void CmdBuf::bindUniformBuffer(DkStage stage, uint32_t id, DkGpuAddr bufAddr, uint32_t bufSize) + { + ::dkCmdBufBindUniformBuffer(*this, stage, id, bufAddr, bufSize); + } + + inline void CmdBuf::bindUniformBuffers(DkStage stage, uint32_t firstId, detail::ArrayProxy buffers) + { + ::dkCmdBufBindUniformBuffers(*this, stage, firstId, buffers.data(), buffers.size()); + } + + inline void CmdBuf::bindStorageBuffer(DkStage stage, uint32_t id, DkGpuAddr bufAddr, uint32_t bufSize) + { + ::dkCmdBufBindStorageBuffer(*this, stage, id, bufAddr, bufSize); + } + + inline void CmdBuf::bindStorageBuffers(DkStage stage, uint32_t firstId, detail::ArrayProxy buffers) + { + ::dkCmdBufBindStorageBuffers(*this, stage, firstId, buffers.data(), buffers.size()); + } + + inline void CmdBuf::bindTextures(DkStage stage, uint32_t firstId, detail::ArrayProxy handles) + { + ::dkCmdBufBindTextures(*this, stage, firstId, handles.data(), handles.size()); + } + + inline void CmdBuf::bindImages(DkStage stage, uint32_t firstId, detail::ArrayProxy handles) + { + ::dkCmdBufBindImages(*this, stage, firstId, handles.data(), handles.size()); + } + + inline void CmdBuf::bindImageDescriptorSet(DkGpuAddr setAddr, uint32_t numDescriptors) + { + ::dkCmdBufBindImageDescriptorSet(*this, setAddr, numDescriptors); + } + + inline void CmdBuf::bindSamplerDescriptorSet(DkGpuAddr setAddr, uint32_t numDescriptors) + { + ::dkCmdBufBindSamplerDescriptorSet(*this, setAddr, numDescriptors); + } + + inline void CmdBuf::bindRenderTargets(detail::ArrayProxy colorTargets, DkImageView const* depthTarget) + { + ::dkCmdBufBindRenderTargets(*this, colorTargets.data(), colorTargets.size(), depthTarget); + } + + inline void CmdBuf::bindColorState(DkColorState const& state) + { + ::dkCmdBufBindColorState(*this, &state); + } + + inline void CmdBuf::bindColorWriteState(DkColorWriteState const& state) + { + ::dkCmdBufBindColorWriteState(*this, &state); + } + + inline void CmdBuf::bindBlendStates(uint32_t id, detail::ArrayProxy states) + { + ::dkCmdBufBindBlendStates(*this, id, states.data(), states.size()); + } + + inline void CmdBuf::bindRasterizerState(DkRasterizerState const& state) + { + ::dkCmdBufBindRasterizerState(*this, &state); + } + + inline void CmdBuf::bindMultisampleState(DkMultisampleState const& state) + { + ::dkCmdBufBindMultisampleState(*this, &state); + } + + inline void CmdBuf::bindDepthStencilState(DkDepthStencilState const& state) + { + ::dkCmdBufBindDepthStencilState(*this, &state); + } + + inline void CmdBuf::bindVtxAttribState(detail::ArrayProxy attribs) + { + ::dkCmdBufBindVtxAttribState(*this, attribs.data(), attribs.size()); + } + + inline void CmdBuf::bindVtxBufferState(detail::ArrayProxy buffers) + { + ::dkCmdBufBindVtxBufferState(*this, buffers.data(), buffers.size()); + } + + inline void CmdBuf::bindVtxBuffer(uint32_t id, DkGpuAddr bufAddr, uint32_t bufSize) + { + ::dkCmdBufBindVtxBuffer(*this, id, bufAddr, bufSize); + } + + inline void CmdBuf::bindVtxBuffers(uint32_t firstId, detail::ArrayProxy buffers) + { + ::dkCmdBufBindVtxBuffers(*this, firstId, buffers.data(), buffers.size()); + } + + inline void CmdBuf::bindIdxBuffer(DkIdxFormat format, DkGpuAddr address) + { + ::dkCmdBufBindIdxBuffer(*this, format, address); + } + + inline void CmdBuf::setViewports(uint32_t firstId, detail::ArrayProxy viewports) + { + ::dkCmdBufSetViewports(*this, firstId, viewports.data(), viewports.size()); + } + + inline void CmdBuf::setViewportSwizzles(uint32_t firstId, detail::ArrayProxy swizzles) + { + ::dkCmdBufSetViewportSwizzles(*this, firstId, swizzles.data(), swizzles.size()); + } + + inline void CmdBuf::setSubpixelPrecisionBias(uint32_t xbits, uint32_t ybits) + { + ::dkCmdBufSetSubpixelPrecisionBias(*this, xbits, ybits); + } + + inline void CmdBuf::setScissors(uint32_t firstId, detail::ArrayProxy scissors) + { + ::dkCmdBufSetScissors(*this, firstId, scissors.data(), scissors.size()); + } + + inline void CmdBuf::setDepthBias(float constantFactor, float clamp, float slopeFactor) + { + ::dkCmdBufSetDepthBias(*this, constantFactor, clamp, slopeFactor); + } + + inline void CmdBuf::setPointSize(float size) + { + ::dkCmdBufSetPointSize(*this, size); + } + + inline void CmdBuf::setLineWidth(float width) + { + ::dkCmdBufSetLineWidth(*this, width); + } + + inline void CmdBuf::setConservativeRasterEnable(bool enable) + { + ::dkCmdBufSetConservativeRasterEnable(*this, enable); + } + + inline void CmdBuf::setConservativeRasterDilate(float dilate) + { + ::dkCmdBufSetConservativeRasterDilate(*this, dilate); + } + + inline void CmdBuf::setSampleMask(uint32_t mask) + { + ::dkCmdBufSetSampleMask(*this, mask); + } + + inline void CmdBuf::setCoverageModulationTable(float const table[16]) + { + ::dkCmdBufSetCoverageModulationTable(*this, table); + } + + inline void CmdBuf::setDepthBounds(bool enable, float near, float far) + { + ::dkCmdBufSetDepthBounds(*this, enable, near, far); + } + + inline void CmdBuf::setAlphaRef(float ref) + { + ::dkCmdBufSetAlphaRef(*this, ref); + } + + inline void CmdBuf::setBlendConst(float red, float green, float blue, float alpha) + { + ::dkCmdBufSetBlendConst(*this, red, green, blue, alpha); + } + + inline void CmdBuf::setStencil(DkFace face, uint8_t mask, uint8_t funcRef, uint8_t funcMask) + { + ::dkCmdBufSetStencil(*this, face, mask, funcRef, funcMask); + } + + inline void CmdBuf::setPrimitiveRestart(bool enable, uint32_t index) + { + ::dkCmdBufSetPrimitiveRestart(*this, enable, index); + } + + inline void CmdBuf::setPatchSize(uint32_t size) + { + ::dkCmdBufSetPatchSize(*this, size); + } + + inline void CmdBuf::setTessOuterLevels(float level0, float level1, float level2, float level3) + { + ::dkCmdBufSetTessOuterLevels(*this, level0, level1, level2, level3); + } + + inline void CmdBuf::setTessInnerLevels(float level0, float level1) + { + ::dkCmdBufSetTessInnerLevels(*this, level0, level1); + } + + inline void CmdBuf::setTileSize(uint32_t width, uint32_t height) + { + ::dkCmdBufSetTileSize(*this, width, height); + } + + inline void CmdBuf::tiledCacheOp(DkTiledCacheOp op) + { + ::dkCmdBufTiledCacheOp(*this, op); + } + + inline void CmdBuf::clearColor(uint32_t targetId, uint32_t clearMask, const void* clearData) + { + ::dkCmdBufClearColor(*this, targetId, clearMask, clearData); + } + + template + inline void CmdBuf::clearColor(uint32_t targetId, uint32_t clearMask, T red, T green, T blue, T alpha) + { + static_assert(sizeof(T) == 4, "Bad size for T"); + T data[] = { red, green, blue, alpha }; + ::dkCmdBufClearColor(*this, targetId, clearMask, data); + } + + inline void CmdBuf::clearDepthStencil(bool clearDepth, float depthValue, uint8_t stencilMask, uint8_t stencilValue) + { + ::dkCmdBufClearDepthStencil(*this, clearDepth, depthValue, stencilMask, stencilValue); + } + + inline void CmdBuf::discardColor(uint32_t targetId) + { + ::dkCmdBufDiscardColor(*this, targetId); + } + + inline void CmdBuf::discardDepthStencil() + { + ::dkCmdBufDiscardDepthStencil(*this); + } + + inline void CmdBuf::resolveDepthValues() + { + ::dkCmdBufResolveDepthValues(*this); + } + + inline void CmdBuf::draw(DkPrimitive prim, uint32_t numVertices, uint32_t numInstances, uint32_t firstVertex, uint32_t firstInstance) + { + ::dkCmdBufDraw(*this, prim, numVertices, numInstances, firstVertex, firstInstance); + } + + inline void CmdBuf::drawIndirect(DkPrimitive prim, DkGpuAddr indirect) + { + ::dkCmdBufDrawIndirect(*this, prim, indirect); + } + + inline void CmdBuf::drawIndexed(DkPrimitive prim, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) + { + ::dkCmdBufDrawIndexed(*this, prim, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); + } + + inline void CmdBuf::drawIndexedIndirect(DkPrimitive prim, DkGpuAddr indirect) + { + ::dkCmdBufDrawIndexedIndirect(*this, prim, indirect); + } + + inline void CmdBuf::dispatchCompute(uint32_t numGroupsX, uint32_t numGroupsY, uint32_t numGroupsZ) + { + ::dkCmdBufDispatchCompute(*this, numGroupsX, numGroupsY, numGroupsZ); + } + + inline void CmdBuf::dispatchComputeIndirect(DkGpuAddr indirect) + { + ::dkCmdBufDispatchComputeIndirect(*this, indirect); + } + + inline void CmdBuf::pushConstants(DkGpuAddr uboAddr, uint32_t uboSize, uint32_t offset, uint32_t size, const void* data) + { + ::dkCmdBufPushConstants(*this, uboAddr, uboSize, offset, size, data); + } + + inline void CmdBuf::pushData(DkGpuAddr addr, const void* data, uint32_t size) + { + ::dkCmdBufPushData(*this, addr, data, size); + } + + inline void CmdBuf::copyBuffer(DkGpuAddr srcAddr, DkGpuAddr dstAddr, uint32_t size) + { + ::dkCmdBufCopyBuffer(*this, srcAddr, dstAddr, size); + } + + inline void CmdBuf::copyImage(DkImageView const& srcView, DkImageRect const& srcRect, DkImageView const& dstView, DkImageRect const& dstRect, uint32_t flags) + { + ::dkCmdBufCopyImage(*this, &srcView, &srcRect, &dstView, &dstRect, flags); + } + + inline void CmdBuf::blitImage(DkImageView const& srcView, DkImageRect const& srcRect, DkImageView const& dstView, DkImageRect const& dstRect, uint32_t flags, uint32_t factor) + { + ::dkCmdBufBlitImage(*this, &srcView, &srcRect, &dstView, &dstRect, flags, factor); + } + + inline void CmdBuf::resolveImage(DkImageView const& srcView, DkImageView const& dstView) + { + ::dkCmdBufResolveImage(*this, &srcView, &dstView); + } + + inline void CmdBuf::copyBufferToImage(DkCopyBuf const& src, DkImageView const& dstView, DkImageRect const& dstRect, uint32_t flags) + { + ::dkCmdBufCopyBufferToImage(*this, &src, &dstView, &dstRect, flags); + } + + inline void CmdBuf::copyImageToBuffer(DkImageView const& srcView, DkImageRect const& srcRect, DkCopyBuf const& dst, uint32_t flags) + { + ::dkCmdBufCopyImageToBuffer(*this, &srcView, &srcRect, &dst, flags); + } + + inline Queue QueueMaker::create() const + { + return Queue{::dkQueueCreate(this)}; + } + + inline void Queue::destroy() + { + ::dkQueueDestroy(*this); + _clear(); + } + + inline bool Queue::isInErrorState() + { + return ::dkQueueIsInErrorState(*this); + } + + inline void Queue::waitFence(DkFence& fence) + { + ::dkQueueWaitFence(*this, &fence); + } + + inline void Queue::signalFence(DkFence& fence, bool flush) + { + ::dkQueueSignalFence(*this, &fence, flush); + } + + inline void Queue::submitCommands(DkCmdList cmds) + { + ::dkQueueSubmitCommands(*this, cmds); + } + + inline void Queue::flush() + { + ::dkQueueFlush(*this); + } + + inline void Queue::waitIdle() + { + ::dkQueueWaitIdle(*this); + } + + inline int Queue::acquireImage(DkSwapchain swapchain) + { + return ::dkQueueAcquireImage(*this, swapchain); + } + + inline void Queue::presentImage(DkSwapchain swapchain, int imageSlot) + { + ::dkQueuePresentImage(*this, swapchain, imageSlot); + } + + inline void ShaderMaker::initialize(Shader& obj) const + { + ::dkShaderInitialize(&obj, this); + } + + inline bool Shader::isValid() const + { + return ::dkShaderIsValid(this); + } + + inline DkStage Shader::getStage() const + { + return ::dkShaderGetStage(this); + } + + inline void ImageLayoutMaker::initialize(ImageLayout& obj) const + { + ::dkImageLayoutInitialize(&obj, this); + } + + inline uint64_t ImageLayout::getSize() const + { + return ::dkImageLayoutGetSize(this); + } + + inline uint32_t ImageLayout::getAlignment() const + { + return ::dkImageLayoutGetAlignment(this); + } + + inline void Image::initialize(ImageLayout const& layout, DkMemBlock memBlock, uint32_t offset) + { + ::dkImageInitialize(this, &layout, memBlock, offset); + } + + inline DkGpuAddr Image::getGpuAddr() const + { + return ::dkImageGetGpuAddr(this); + } + + inline ImageLayout const& Image::getLayout() const + { + return *static_cast(::dkImageGetLayout(this)); + } + + inline void ImageDescriptor::initialize(ImageView const& view, bool usesLoadOrStore, bool decayMS) + { + ::dkImageDescriptorInitialize(this, &view, usesLoadOrStore, decayMS); + } + + inline void SamplerDescriptor::initialize(Sampler const& sampler) + { + ::dkSamplerDescriptorInitialize(this, &sampler); + } + + inline MultisampleState& MultisampleState::setLocations(detail::ArrayProxy locations) + { + ::dkMultisampleStateSetLocations(this, locations.data(), locations.size()); + return *this; + } + + inline Swapchain SwapchainMaker::create() const + { + return Swapchain{::dkSwapchainCreate(this)}; + } + + inline void Swapchain::destroy() + { + ::dkSwapchainDestroy(*this); + _clear(); + } + + inline void Swapchain::acquireImage(int& imageSlot, DkFence& fence) + { + ::dkSwapchainAcquireImage(*this, &imageSlot, &fence); + } + + inline void Swapchain::setCrop(int32_t left, int32_t top, int32_t right, int32_t bottom) + { + ::dkSwapchainSetCrop(*this, left, top, right, bottom); + } + + inline void Swapchain::setSwapInterval(uint32_t interval) + { + ::dkSwapchainSetSwapInterval(*this, interval); + } + + using UniqueDevice = detail::UniqueHandle; + using UniqueMemBlock = detail::UniqueHandle; + using UniqueCmdBuf = detail::UniqueHandle; + using UniqueQueue = detail::UniqueHandle; + using UniqueSwapchain = detail::UniqueHandle; +} diff --git a/troposphere/daybreak/source/ui.cpp b/troposphere/daybreak/source/ui.cpp index e7e726f27..b03c5695e 100644 --- a/troposphere/daybreak/source/ui.cpp +++ b/troposphere/daybreak/source/ui.cpp @@ -62,8 +62,8 @@ namespace dbk { /* Update install state. */ char g_update_path[FS_MAX_PATH]; bool g_reset_to_factory = false; - bool g_exfat_supported = false; - bool g_use_exfat = false; + bool g_exfat_supported = true; + bool g_use_exfat = true; constexpr u32 MaxTapMovement = 20; @@ -881,7 +881,7 @@ namespace dbk { /* Check if exfat is supported. */ g_exfat_supported = m_update_info.exfat_supported && R_SUCCEEDED(m_validation_info.exfat_result); if (!g_exfat_supported) { - g_use_exfat = false; + g_use_exfat = true; } /* Warn the user if they're updating with exFAT supposed to be supported but not present/corrupted. */ @@ -941,11 +941,8 @@ namespace dbk { break; } - if (g_exfat_supported) { - ChangeMenu(std::make_shared(g_current_menu)); - } else { - ChangeMenu(std::make_shared(g_current_menu, std::make_shared(g_current_menu), "Ready to begin update installation", "Are you sure you want to proceed?")); - } + ChangeMenu(std::make_shared(g_current_menu, std::make_shared(g_current_menu), "Ready to begin update installation", "Are you sure you want to proceed?")); + } this->UpdateButtons(); @@ -997,7 +994,7 @@ namespace dbk { if (const Button *activated_button = this->GetActivatedButton(); activated_button != nullptr) { switch (activated_button->id) { case Fat32ButtonId: - g_use_exfat = false; + g_use_exfat = true; break; case ExFatButtonId: g_use_exfat = true;