yayyy vulkan. stuff

This commit is contained in:
Mars 2024-09-25 23:03:56 -04:00
commit 7181c58033
Signed by untrusted user: pupbrained
GPG key ID: 874E22DF2F9DFCB5
19 changed files with 4466 additions and 0 deletions

29
.clang-format Normal file
View file

@ -0,0 +1,29 @@
AlignAfterOpenBracket: BlockIndent
AlignArrayOfStructures: Right
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AllowShortBlocksOnASingleLine: Always
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortLoopsOnASingleLine: true
BasedOnStyle: Chromium
BinPackArguments: false
BinPackParameters: false
ColumnLimit: 100
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
Cpp11BracedListStyle: false
FixNamespaceComments: false
IndentAccessModifiers: false
IndentExternBlock: Indent
IndentWidth: 2
NamespaceIndentation: All
SpaceBeforeCpp11BracedList: true
SpacesBeforeTrailingComments: 1
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '".*"'
Priority: 1
- Regex: '<.*>'
Priority: -1

51
.clang-tidy Normal file
View file

@ -0,0 +1,51 @@
# noinspection SpellCheckingInspection
Checks: >
*,
-ctad-maybe-unsupported,
-abseil-*,
-altera-*,
-bugprone-easily-swappable-parameters,
-bugprone-implicit-widening-of-multiplication-result,
-cert-env33-c,
-concurrency-mt-unsafe,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-owning-memory,
-cppcoreguidelines-pro-type-member-init,
-cppcoreguidelines-pro-type-vararg,
-fuchsia-*,
-google-*,
-hicpp-*,
-llvm-include-order,
-llvm-include-order,
-llvm-namespace-comment,
-llvmlibc-*,
-misc-non-private-member-variables-in-classes,
-readability-braces-around-statements,
-readability-implicit-bool-conversion,
-readability-isolate-declaration,
-readability-magic-numbers
CheckOptions:
readability-identifier-naming.ClassCase: CamelCase
readability-identifier-naming.EnumCase: CamelCase
readability-identifier-naming.LocalConstantCase: camelBack
readability-identifier-naming.LocalVariableCase: camelBack
readability-identifier-naming.GlobalFunctionCase: CamelCase
readability-identifier-naming.MemberCase: lower_case
readability-identifier-naming.MethodCase: camelBack
readability-identifier-naming.MethodIgnoredRegexp: ((to|from)_class)
readability-identifier-naming.ParameterPackCase: lower_case
readability-identifier-naming.PrivateMemberCase: CamelCase
readability-identifier-naming.PrivateMemberPrefix: 'm'
readability-identifier-naming.PrivateMethodCase: camelBack
readability-identifier-naming.PrivateMethodPrefix: ''
readability-identifier-naming.ProtectedMemberPrefix: 'm'
readability-identifier-naming.ProtectedMethodPrefix: ''
readability-identifier-naming.PublicMemberCase: lower_case
readability-identifier-naming.StaticConstantCase: UPPER_CASE
readability-identifier-naming.StaticVariableCase: CamelCase
readability-identifier-naming.StructCase: CamelCase
readability-identifier-naming.TemplateParameterCase: lower_case
readability-identifier-naming.TemplateTemplateParameterCase: CamelCase
readability-identifier-naming.TypeTemplateParameterCase: CamelCase
readability-identifier-naming.TypedefCase: CamelCase
readability-identifier-naming.UnionCase: CamelCase

4
.clangd Normal file
View file

@ -0,0 +1,4 @@
Diagnostics:
Suppress: >
-Wmissing-template-arg-list-after-template-kw,
-Wctad-maybe-unsupported

1
.envrc Normal file
View file

@ -0,0 +1 @@
use_flake

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
.cache/
.direnv/
.vscode/
build/

22
_sources/generated.json Normal file
View file

@ -0,0 +1,22 @@
{
"fmt": {
"cargoLocks": null,
"date": null,
"extract": null,
"name": "fmt",
"passthru": null,
"pinned": false,
"src": {
"deepClone": false,
"fetchSubmodules": false,
"leaveDotGit": false,
"name": null,
"owner": "fmtlib",
"repo": "fmt",
"rev": "11.0.2",
"sha256": "sha256-IKNt4xUoVi750zBti5iJJcCk3zivTt7nU12RIf8pM+0=",
"type": "github"
},
"version": "11.0.2"
}
}

15
_sources/generated.nix Normal file
View file

@ -0,0 +1,15 @@
# This file was generated by nvfetcher, please do not modify it manually.
{ fetchgit, fetchurl, fetchFromGitHub, dockerTools }:
{
fmt = {
pname = "fmt";
version = "11.0.2";
src = fetchFromGitHub {
owner = "fmtlib";
repo = "fmt";
rev = "11.0.2";
fetchSubmodules = false;
sha256 = "sha256-IKNt4xUoVi750zBti5iJJcCk3zivTt7nU12RIf8pM+0=";
};
};
}

View file

@ -0,0 +1,315 @@
{
"file_format_version": "1.2.0",
"layer": {
"name": "VK_LAYER_LUNARG_api_dump",
"type": "GLOBAL",
"library_path": "../../../lib/libVkLayer_api_dump.dylib",
"api_version": "1.3.290",
"implementation_version": "2",
"description": "LunarG API dump layer",
"introduction": "The API Dump utility layer prints API calls, parameters, and values to the identified output stream.",
"url": "https://vulkan.lunarg.com/doc/sdk/latest/windows/api_dump_layer.html",
"platforms": [
"WINDOWS",
"LINUX",
"MACOS",
"ANDROID"
],
"instance_extensions": [
{
"name": "VK_EXT_layer_settings",
"spec_version": "2"
}
],
"device_extensions": [
{
"name": "VK_EXT_tooling_info",
"spec_version": "1",
"entrypoints": [
"vkGetPhysicalDeviceToolPropertiesEXT"
]
}
],
"features": {
"presets": [
{
"label": "Console Output",
"description": "Output API dump to stdout",
"platforms": [
"WINDOWS",
"LINUX",
"MACOS",
"ANDROID"
],
"status": "STABLE",
"settings": [
{
"key": "output_format",
"value": "text"
},
{
"key": "log_filename",
"value": "stdout"
},
{
"key": "file",
"value": false
}
]
},
{
"label": "Text Output",
"description": "Output API dump to a text file",
"platforms": [
"WINDOWS",
"LINUX",
"MACOS",
"ANDROID"
],
"status": "STABLE",
"settings": [
{
"key": "output_format",
"value": "text"
},
{
"key": "log_filename",
"value": "${VK_LOCAL}/vk_apidump.txt"
},
{
"key": "file",
"value": true
}
]
},
{
"label": "HTML Output",
"description": "Output API dump to a HTML file",
"platforms": [
"WINDOWS",
"LINUX",
"MACOS",
"ANDROID"
],
"status": "STABLE",
"settings": [
{
"key": "output_format",
"value": "html"
},
{
"key": "log_filename",
"value": "${VK_LOCAL}/vk_apidump.html"
},
{
"key": "file",
"value": true
}
]
},
{
"label": "JSON Output",
"description": "Output API dump to a JSON file",
"platforms": [
"WINDOWS",
"LINUX",
"MACOS",
"ANDROID"
],
"status": "STABLE",
"settings": [
{
"key": "output_format",
"value": "json"
},
{
"key": "log_filename",
"value": "${VK_LOCAL}/vk_apidump.json"
},
{
"key": "file",
"value": true
}
]
}
],
"settings": [
{
"key": "output_range",
"env": "VK_APIDUMP_OUTPUT_RANGE",
"label": "Output Range",
"description": "Comma separated list of frames to output or a range of frames with a start, count, and optional interval separated by a dash. A count of 0 will output every frame after the start of the range. Example: \"5-8-2\" will output frame 5, continue until frame 13, dumping every other frame. Example: \"3,8-2\" will output frames 3, 8, and 9.",
"type": "STRING",
"default": "0-0"
},
{
"key": "output_format",
"env": "VK_APIDUMP_OUTPUT_FORMAT",
"label": "Output Format",
"description": "Specifies the format used for output; can be HTML, JSON, or Text (default -- outputs plain text)",
"type": "ENUM",
"flags": [
{
"key": "text",
"label": "Text",
"description": "Plain text"
},
{
"key": "html",
"label": "HTML",
"description": "HTML"
},
{
"key": "json",
"label": "JSON",
"description": "Json"
}
],
"default": "text"
},
{
"key": "file",
"label": "Output to File",
"description": "Setting this to true indicates that output should be written to file instead of stdout",
"type": "BOOL",
"default": false,
"settings": [
{
"key": "log_filename",
"env": "VK_APIDUMP_LOG_FILENAME",
"label": "Log Filename",
"description": "Specifies the file to dump to when output files are enabled",
"type": "SAVE_FILE",
"filter": "*.txt,*.html,*.json",
"default": "stdout",
"dependence": {
"mode": "ALL",
"settings": [
{
"key": "file",
"value": true
}
]
}
}
]
},
{
"key": "flush",
"env": "VK_APIDUMP_FLUSH",
"label": "Log Flush After Write",
"description": "Setting this to true causes IO to be flushed after each API call that is written",
"type": "BOOL",
"default": true
},
{
"key": "name_size",
"label": "Name Size",
"description": "The number of characters the name of a variable should consume, assuming more are not required",
"type": "INT",
"default": 32,
"range": {
"min": 1
},
"unit": "chars"
},
{
"key": "show_types",
"label": "Show Types",
"description": "Dump types in addition to values",
"type": "BOOL",
"default": true,
"settings": [
{
"key": "type_size",
"label": "Type Size",
"description": "The number of characters the name of a type should consume, assuming more are not required",
"type": "INT",
"default": 0,
"range": {
"min": 0
},
"dependence": {
"mode": "ALL",
"settings": [
{
"key": "show_types",
"value": true
}
]
}
}
]
},
{
"key": "timestamp",
"env": "VK_APIDUMP_TIMESTAMP",
"label": "Show Timestamp",
"description": "Show the timestamp of function calls since start in microseconds",
"type": "BOOL",
"default": false
},
{
"key": "show_shader",
"label": "Show Shader",
"description": "Dump the shader binary code in pCode",
"type": "BOOL",
"default": false
},
{
"key": "detailed",
"env": "VK_APIDUMP_DETAILED",
"label": "Show Parameter Details",
"description": "Dump parameter details in addition to API calls",
"type": "BOOL",
"default": true
},
{
"key": "no_addr",
"env": "VK_APIDUMP_NO_ADDR",
"label": "Hide Addresses",
"description": "Dump \"address\" in place of hex addresses",
"type": "BOOL",
"default": false
},
{
"key": "use_spaces",
"label": "Use Spaces",
"description": "Setting this to true causes all tab characters to be replaced with spaces",
"type": "BOOL",
"default": true,
"settings": [
{
"key": "indent_size",
"label": "Indent Size",
"description": "Specifies the number of spaces that a tab is equal to",
"type": "INT",
"default": 4,
"range": {
"min": 1,
"max": 16
},
"unit": "chars",
"dependence": {
"mode": "ALL",
"settings": [
{
"key": "use_spaces",
"value": true
}
]
}
}
]
},
{
"key": "show_thread_and_frame",
"label": "Show Thread and Frame",
"description": "Show the thread and frame of each function called",
"type": "BOOL",
"default": true
}
]
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,90 @@
{
"file_format_version": "1.2.0",
"layer": {
"name": "VK_LAYER_KHRONOS_shader_object",
"type": "GLOBAL",
"library_path": "../../../lib/libVkLayer_khronos_shader_object.dylib",
"api_version": "1.3.290",
"implementation_version": "1",
"description": "Khronos Shader object layer",
"instance_extensions": [
{
"name": "VK_EXT_layer_settings",
"spec_version": "2"
}
],
"device_extensions": [
{
"name": "VK_EXT_shader_object",
"spec_version": "1",
"entrypoints": [
"vkCmdBindShadersEXT",
"vkCmdBindVertexBuffers2EXT",
"vkCmdSetAlphaToCoverageEnableEXT",
"vkCmdSetAlphaToOneEnableEXT",
"vkCmdSetColorBlendAdvancedEXT",
"vkCmdSetColorBlendEnableEXT",
"vkCmdSetColorBlendEquationEXT",
"vkCmdSetColorWriteMaskEXT",
"vkCmdSetConservativeRasterizationModeEXT",
"vkCmdSetCoverageModulationModeNV",
"vkCmdSetCoverageModulationTableEnableNV",
"vkCmdSetCoverageModulationTableNV",
"vkCmdSetCoverageReductionModeNV",
"vkCmdSetCoverageToColorEnableNV",
"vkCmdSetCoverageToColorLocationNV",
"vkCmdSetCullModeEXT",
"vkCmdSetDepthBiasEnableEXT",
"vkCmdSetDepthBoundsTestEnableEXT",
"vkCmdSetDepthClampEnableEXT",
"vkCmdSetDepthClipEnableEXT",
"vkCmdSetDepthClipNegativeOneToOneEXT",
"vkCmdSetDepthCompareOpEXT",
"vkCmdSetDepthTestEnableEXT",
"vkCmdSetDepthWriteEnableEXT",
"vkCmdSetExtraPrimitiveOverestimationSizeEXT",
"vkCmdSetFrontFaceEXT",
"vkCmdSetLineRasterizationModeEXT",
"vkCmdSetLineStippleEnableEXT",
"vkCmdSetLogicOpEXT",
"vkCmdSetLogicOpEnableEXT",
"vkCmdSetPatchControlPointsEXT",
"vkCmdSetPolygonModeEXT",
"vkCmdSetPrimitiveRestartEnableEXT",
"vkCmdSetPrimitiveTopologyEXT",
"vkCmdSetProvokingVertexModeEXT",
"vkCmdSetRasterizationSamplesEXT",
"vkCmdSetRasterizationStreamEXT",
"vkCmdSetRasterizerDiscardEnableEXT",
"vkCmdSetRepresentativeFragmentTestEnableNV",
"vkCmdSetSampleLocationsEnableEXT",
"vkCmdSetSampleMaskEXT",
"vkCmdSetScissorWithCountEXT",
"vkCmdSetShadingRateImageEnableNV",
"vkCmdSetStencilOpEXT",
"vkCmdSetStencilTestEnableEXT",
"vkCmdSetTessellationDomainOriginEXT",
"vkCmdSetVertexInputEXT",
"vkCmdSetViewportSwizzleNV",
"vkCmdSetViewportWScalingEnableNV",
"vkCmdSetViewportWithCountEXT",
"vkCreateShadersEXT",
"vkDestroyShaderEXT",
"vkGetShaderBinaryDataEXT"
]
}
],
"features": {
"settings": [
{
"key": "force_enable",
"env": "VK_SHADER_OBJECT_FORCE_ENABLE",
"label": "Force Enable",
"description": "Force the layer to be active even if the underlying driver also implements the shader object extension.",
"type": "BOOL",
"default": false
}
]
}
}
}

View file

@ -0,0 +1,54 @@
{
"file_format_version": "1.2.0",
"layer": {
"name": "VK_LAYER_KHRONOS_synchronization2",
"type": "GLOBAL",
"library_path": "../../../lib/libVkLayer_khronos_synchronization2.dylib",
"api_version": "1.3.290",
"implementation_version": "1",
"description": "Khronos Synchronization2 layer",
"introduction": "The VK_LAYER_KHRONOS_synchronization2 extension layer implements the VK_KHR_synchronization2 extension.",
"url": "https://vulkan.lunarg.com/doc/sdk/latest/windows/synchronization2_layer.html",
"status": "STABLE",
"platforms": [
"WINDOWS",
"LINUX",
"MACOS",
"ANDROID"
],
"instance_extensions": [
{
"name": "VK_EXT_layer_settings",
"spec_version": "2"
}
],
"device_extensions": [
{
"name": "VK_KHR_synchronization2",
"spec_version": "1",
"entrypoints": [
"vkCmdSetEvent2KHR",
"vkCmdResetEvent2KHR",
"vkCmdWaitEvents2KHR",
"vkCmdPipelineBarrier2KHR",
"vkCmdWriteTimestamp2KHR",
"vkQueueSubmit2KHR",
"vkCmdWriteBufferMarker2AMD",
"vkGetQueueCheckpointData2NV"
]
}
],
"features": {
"settings": [
{
"key": "force_enable",
"env": "VK_SYNCHRONIZATION2_FORCE_ENABLE",
"label": "Force Enable",
"description": "Force the layer to be active even if the underlying driver also implements the synchonization2 extension.",
"type": "BOOL",
"default": false
}
]
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,104 @@
{
"file_format_version": "1.2.0",
"layer": {
"name": "VK_LAYER_LUNARG_screenshot",
"type": "GLOBAL",
"library_path": "../../../lib/libVkLayer_screenshot.dylib",
"api_version": "1.3.290",
"implementation_version": "1",
"description": "LunarG image capture layer",
"introduction": "The screenshot layer records frames to image files.",
"url": "https://vulkan.lunarg.com/doc/sdk/latest/windows/screenshot_layer.html",
"platforms": [
"WINDOWS",
"LINUX",
"MACOS",
"ANDROID"
],
"instance_extensions": [
{
"name": "VK_EXT_layer_settings",
"spec_version": "2"
}
],
"device_extensions": [
{
"name": "VK_EXT_tooling_info",
"spec_version": "1",
"entrypoints": [
"vkGetPhysicalDeviceToolPropertiesEXT"
]
}
],
"features": {
"settings": [
{
"key": "frames",
"env": "VK_SCREENSHOT_FRAMES",
"label": "Frames",
"description": "Specifies list of frames to output as screenshots. It is specified as a comma-separated list of frames or a range of frames with a start, count, and optional interval separated by a dash. Setting the variable to \"all\" will output every frame. Example: \"5-8-2\" will output frame 5, continue until frame 13, dumping every other frame. Example: \"3,8-2\" will output frames 3, 8, and 9. If it is not set or it set to an empty string, no screenshots are created.",
"type": "STRING",
"default": ""
},
{
"key": "dir",
"env": "VK_SCREENSHOT_DIR",
"label": "Directory",
"description": "Specifies the directory in which to create the screenshot files. If it is not set or is set to an empty string, the files will be created in the current working directory.",
"type": "SAVE_FOLDER",
"default": ""
},
{
"key": "format",
"env": "VK_SCREENSHOT_FORMAT",
"label": "Format",
"description": "Specify a color space for the output. If it is not set, set to null, or set to USE_SWAPCHAIN_COLORSPACE the format will be set to use the same color space as the swapchain object.",
"type": "ENUM",
"flags": [
{
"key": "UNORM",
"label": "UNORM",
"description": ""
},
{
"key": "SNORM",
"label": "SNORM",
"description": ""
},
{
"key": "USCALED",
"label": "USCALED",
"description": ""
},
{
"key": "SSCALED",
"label": "SSCALED",
"description": ""
},
{
"key": "UINT",
"label": "UINT",
"description": ""
},
{
"key": "SINT",
"label": "SINT",
"description": ""
},
{
"key": "SRGB",
"label": "SRGB",
"description": ""
},
{
"key": "USE_SWAPCHAIN_COLORSPACE",
"label": "USE_SWAPCHAIN_COLORSPACE",
"description": ""
}
],
"default": "USE_SWAPCHAIN_COLORSPACE"
}
]
}
}
}

95
flake.lock Normal file
View file

@ -0,0 +1,95 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1727065772,
"narHash": "sha256-U9baiEXL2YsS67QKlBAPIUq+OB+eUPKv8n1vGNdhiec=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "989dc4cbf6a95f2e5fefc8cd61d2198a8fb6834a",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1726481836,
"narHash": "sha256-MWTBH4dd5zIz2iatDb8IkqSjIeFum9jAqkFxgHLdzO4=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "20f9370d5f588fb8c72e844c54511cab054b5f40",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"treefmt-nix": "treefmt-nix",
"utils": "utils"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1726734507,
"narHash": "sha256-VUH5O5AcOSxb0uL/m34dDkxFKP6WLQ6y4I1B4+N3L2w=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "ee41a466c2255a3abe6bc50fc6be927cdee57a9f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
},
"utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1726560853,
"narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

127
flake.nix Normal file
View file

@ -0,0 +1,127 @@
{
description = "C/C++ environment";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
treefmt-nix.url = "github:numtide/treefmt-nix";
utils.url = "github:numtide/flake-utils";
};
outputs = {
self,
nixpkgs,
treefmt-nix,
utils,
...
}:
utils.lib.eachDefaultSystem (
system: let
pkgs = import nixpkgs {inherit system;};
stdenv =
if pkgs.hostPlatform.isLinux
then pkgs.stdenvAdapters.useMoldLinker pkgs.llvmPackages_18.stdenv
else pkgs.llvmPackages_18.stdenv;
sources = import ./_sources/generated.nix {
inherit (pkgs) fetchFromGitHub fetchgit fetchurl dockerTools;
};
mkPkg = name:
pkgs.pkgsStatic.${name}.overrideAttrs {
inherit (sources.${name}) pname version src;
};
fmt = mkPkg "fmt";
deps = with pkgs;
[
fmt
glfw
glm
]
++ lib.optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.AppKit
darwin.apple_sdk.frameworks.Cocoa
darwin.apple_sdk.frameworks.Metal
darwin.apple_sdk.frameworks.QuartzCore
];
in
with pkgs; {
packages = rec {
graphics-test = stdenv.mkDerivation {
name = "graphics-test";
version = "0.1.0";
src = self;
nativeBuildInputs = [
meson
ninja
pkg-config
];
buildInputs = deps;
configurePhase = ''
meson setup build
'';
buildPhase = ''
meson compile -C build
'';
installPhase = ''
mkdir -p $out/bin
mv build/graphics-test $out/bin/graphics-test
'';
};
default = graphics-test;
};
formatter = treefmt-nix.lib.mkWrapper pkgs {
projectRootFile = "flake.nix";
programs = {
alejandra.enable = true;
deadnix.enable = true;
clang-format = {
enable = true;
package = pkgs.clang-tools_18;
};
};
};
devShell = mkShell.override {inherit stdenv;} {
packages =
[
alejandra
bear
llvmPackages_18.clang-tools
lldb
meson
ninja
nvfetcher
pkg-config
unzip
(writeScriptBin "build" "meson compile -C build")
(writeScriptBin "clean" "meson setup build --wipe")
(writeScriptBin "reconfigure" "meson setup build --reconfigure")
(writeScriptBin "run" "meson compile -C build && build/graphics-test")
]
++ deps;
shellHook = lib.optionals stdenv.isDarwin ''
export PATH="${llvmPackages_18.clang-tools}/bin:$PATH"
export MOLTENVK_LIBRARY_PATH="${darwin.moltenvk}/lib";
export VULKAN_INCLUDE_DIRS="${darwin.moltenvk.dev}/include:${vulkan-headers}/include";
export VK_ICD_FILENAMES="${darwin.moltenvk}/share/vulkan/icd.d/MoltenVK_icd.json"
export VK_LAYER_PATH="${./explicit_layer.d}";
'';
name = "C++";
};
}
);
}

77
meson.build Normal file
View file

@ -0,0 +1,77 @@
project(
'graphics-test',
'cpp',
version: '0.1.0',
default_options: [
'cpp_std=c++20',
'warning_level=everything',
],
)
cpp = meson.get_compiler('cpp')
common_cpp_args = [
'-Wno-c++20-compat',
'-Wno-c++20-extensions',
'-Wno-c++98-compat',
'-Wno-c++98-compat-pedantic',
'-Wno-disabled-macro-expansion',
'-Wno-missing-prototypes',
'-Wno-padded',
'-Wno-pre-c++20-compat-pedantic',
'-Wno-switch-default',
'-Wno-unsafe-buffer-usage',
'-Wunused-function',
'-fvisibility=hidden',
]
add_project_arguments(cpp.get_supported_arguments(common_cpp_args), language: 'cpp')
source_file_names = [
'src/main.cpp',
]
sources = []
foreach file : source_file_names
sources += files(file)
endforeach
deps = [
dependency('fmt', static: true),
dependency('glfw3'),
dependency('glm'),
]
if build_machine.system() == 'darwin'
molten_dirs = []
pymodule = import('python3')
python3 = pymodule.find_python()
res = run_command(python3, '-c', 'import os; print(os.environ["MOLTENVK_LIBRARY_PATH"])', check: false)
if res.returncode() == 0
molten_dirs += res.stdout().strip()
elif import('fs').exists('/opt/homebrew/lib/libMoltenVK.a')
molten_dirs += '/opt/homebrew/lib'
endif
deps += cpp.find_library('MoltenVK', required: true, dirs: molten_dirs)
res = run_command(python3, '-c', 'import os; print(os.environ["VULKAN_INCLUDE_DIRS"])', check: false)
if res.returncode() == 0
include_dirs = include_directories(res.stdout().strip().split(':'), is_system: true)
endif
else
deps += dependency('vulkan')
endif
executable(
'graphics-test',
sources,
include_directories: include_dirs,
dependencies: deps,
)

3
nvfetcher.toml Normal file
View file

@ -0,0 +1,3 @@
[fmt]
src.github = "fmtlib/fmt"
fetch.github = "fmtlib/fmt"

147
src/main.cpp Normal file
View file

@ -0,0 +1,147 @@
#include <cstdlib>
#include <fmt/base.h>
#include <fmt/format.h>
#include <iostream>
#define GLFW_INCLUDE_NONE
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
#include "util/types.h"
constexpr u32 WIDTH = 800;
constexpr u32 HEIGHT = 600;
constexpr std::array<const char*, 1> validationLayers = { "VK_LAYER_KHRONOS_validation" };
#if defined(NDEBUG) or defined(__APPLE__)
const bool enableValidationLayers = false;
#else
const bool enableValidationLayers = true;
#endif
class Application {
public:
fn run() -> void {
initWindow();
initVulkan();
mainLoop();
cleanup();
}
private:
VkInstance mInstance;
GLFWwindow* mWindow;
static fn checkValidationLayerSupport() -> bool {
u32 layerCount = 0;
vkEnumerateInstanceLayerProperties(&layerCount, nullptr);
std::vector<VkLayerProperties> availableLayers(layerCount);
vkEnumerateInstanceLayerProperties(&layerCount, availableLayers.data());
fmt::println("Available layers:");
for (const auto& layerProperties : availableLayers) {
fmt::println("\t{}", layerProperties.layerName);
}
for (const char* layerName : validationLayers) {
bool layerFound = false;
for (const auto& layerProperties : availableLayers) {
if (strcmp(
static_cast<const char*>(layerName),
static_cast<const char*>(layerProperties.layerName)
) == 0) {
layerFound = true;
break;
}
}
if (!layerFound)
return false;
}
return true;
}
static fn getAvailableExtensions() -> std::vector<VkExtensionProperties> {
u32 extensionCount = 0;
vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr);
std::vector<VkExtensionProperties> extensions(extensionCount);
vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, extensions.data());
return extensions;
}
fn createInstance() -> void {
fmt::println("Available extensions:");
for (const fn& extension : getAvailableExtensions())
fmt::println("\t{}", extension.extensionName);
if (enableValidationLayers && !checkValidationLayerSupport())
throw std::runtime_error("Validation layers requested, but not available!");
VkApplicationInfo appInfo {};
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; // Used for pNext
appInfo.pApplicationName = "Hello Triangle";
appInfo.pEngineName = "No Engine";
appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
appInfo.apiVersion = VK_API_VERSION_1_0;
uint32_t glfwExtensionCount = 0;
const char** glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
VkInstanceCreateInfo createInfo {};
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
createInfo.pApplicationInfo = &appInfo;
createInfo.enabledExtensionCount = glfwExtensionCount;
createInfo.ppEnabledExtensionNames = glfwExtensions;
createInfo.enabledLayerCount = 0;
if (vkCreateInstance(&createInfo, nullptr, &mInstance) != VK_SUCCESS)
throw std::runtime_error("Failed to create Vulkan instance!");
}
fn initWindow() -> void {
// Initialize GLFW
glfwInit();
// Don't create an OpenGL context
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
// Disable Resizing
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
mWindow = glfwCreateWindow(WIDTH, HEIGHT, "Vulkan", nullptr, nullptr);
}
fn initVulkan() -> void { createInstance(); }
fn mainLoop() -> void {
while (!glfwWindowShouldClose(mWindow)) glfwPollEvents();
}
fn cleanup() -> void {
vkDestroyInstance(mInstance, nullptr);
glfwDestroyWindow(mWindow);
glfwTerminate();
}
};
fn main() -> int {
Application app;
try {
app.run();
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

128
src/util/types.h Normal file
View file

@ -0,0 +1,128 @@
#pragma once
#include <cstddef>
#include <cstdint>
#include <string>
#define fn auto
/**
* @typedef u8
* @brief Represents an 8-bit unsigned integer.
*
* This type alias is used for 8-bit unsigned integers, ranging from 0 to 255.
* It is based on the std::uint8_t type.
*/
using u8 = std::uint8_t;
/**
* @typedef u16
* @brief Represents a 16-bit unsigned integer.
*
* This type alias is used for 16-bit unsigned integers, ranging from 0 to 65,535.
* It is based on the std::uint16_t type.
*/
using u16 = std::uint16_t;
/**
* @typedef u32
* @brief Represents a 32-bit unsigned integer.
*
* This type alias is used for 32-bit unsigned integers, ranging from 0 to 4,294,967,295.
* It is based on the std::uint32_t type.
*/
using u32 = std::uint32_t;
/**
* @typedef u64
* @brief Represents a 64-bit unsigned integer.
*
* This type alias is used for 64-bit unsigned integers, ranging from 0 to
* 18,446,744,073,709,551,615. It is based on the std::uint64_t type.
*/
using u64 = std::uint64_t;
// Type Aliases for Signed Integers
/**
* @typedef i8
* @brief Represents an 8-bit signed integer.
*
* This type alias is used for 8-bit signed integers, ranging from -128 to 127.
* It is based on the std::int8_t type.
*/
using i8 = std::int8_t;
/**
* @typedef i16
* @brief Represents a 16-bit signed integer.
*
* This type alias is used for 16-bit signed integers, ranging from -32,768 to 32,767.
* It is based on the std::int16_t type.
*/
using i16 = std::int16_t;
/**
* @typedef i32
* @brief Represents a 32-bit signed integer.
*
* This type alias is used for 32-bit signed integers, ranging from -2,147,483,648 to 2,147,483,647.
* It is based on the std::int32_t type.
*/
using i32 = std::int32_t;
/**
* @typedef i64
* @brief Represents a 64-bit signed integer.
*
* This type alias is used for 64-bit signed integers, ranging from -9,223,372,036,854,775,808 to
* 9,223,372,036,854,775,807. It is based on the std::int64_t type.
*/
using i64 = std::int64_t;
// Type Aliases for Floating-Point Numbers
/**
* @typedef f32
* @brief Represents a 32-bit floating-point number.
*
* This type alias is used for 32-bit floating-point numbers, which follow the IEEE 754 standard.
* It is based on the float type.
*/
using f32 = float;
/**
* @typedef f64
* @brief Represents a 64-bit floating-point number.
*
* This type alias is used for 64-bit floating-point numbers, which follow the IEEE 754 standard.
* It is based on the double type.
*/
using f64 = double;
// Type Aliases for Size Types
/**
* @typedef usize
* @brief Represents an unsigned size type.
*
* This type alias is used for representing the size of objects in bytes.
* It is based on the std::size_t type, which is the result type of the sizeof operator.
*/
using usize = std::size_t;
/**
* @typedef isize
* @brief Represents a signed size type.
*
* This type alias is used for representing pointer differences.
* It is based on the std::ptrdiff_t type, which is the signed integer type returned when
* subtracting two pointers.
*/
using isize = std::ptrdiff_t;
/**
* @typedef string
* @brief Represents a string.
*/
using string = std::string;