This commit is contained in:
Mars 2024-11-05 19:47:37 -05:00
parent 0f7c86bd4b
commit 450c92ec55
Signed by untrusted user: pupbrained
GPG key ID: 0FF5B8826803F895
3 changed files with 14 additions and 13 deletions

View file

@ -53,11 +53,11 @@
},
"nixpkgs_2": {
"locked": {
"lastModified": 1729632202,
"narHash": "sha256-BqWFOqG9Iuzf5wm9dyVWPeH1SPxSjCxo3inUSnYqxaQ=",
"lastModified": 1730853263,
"narHash": "sha256-Cnp2zjzaA4bYUOhM/xo9GxhgOgTHn+qNbSGu4su8RaQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "5a95c26209c2e136ef7da309824f562253b5fd7a",
"rev": "5d4d64e923ce570996c089d768710f61bde0b9d3",
"type": "github"
},
"original": {
@ -126,11 +126,11 @@
"nixpkgs": "nixpkgs_3"
},
"locked": {
"lastModified": 1729613947,
"narHash": "sha256-XGOvuIPW1XRfPgHtGYXd5MAmJzZtOuwlfKDgxX5KT3s=",
"lastModified": 1730321837,
"narHash": "sha256-vK+a09qq19QNu2MlLcvN4qcRctJbqWkX7ahgPZ/+maI=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "aac86347fb5063960eccb19493e0cadcdb4205ca",
"rev": "746901bb8dba96d154b66492a29f5db0693dbfcc",
"type": "github"
},
"original": {

View file

@ -14,6 +14,7 @@ common_cpp_args = [
'-Wno-c++98-compat-pedantic',
'-Wno-pre-c++20-compat-pedantic',
'-Wno-padded',
'-mavx2'
]
add_project_arguments(cpp.get_supported_arguments(common_cpp_args), language: 'cpp')

View file

@ -33,13 +33,13 @@ class ShaderCompiler {
) -> std::vector<u32> {
using namespace std;
const string cacheFile = getCacheFilePath(shaderName);
const filesystem::path cacheFile = getCacheFilePath(shaderName);
// Try loading from cache first
vector<u32> spirvCode = loadCachedShader(cacheFile);
if (!spirvCode.empty()) {
fmt::println("Loaded shader from cache: {}", cacheFile);
fmt::println("Loaded shader from cache: {}", cacheFile.string());
return spirvCode;
}
@ -64,7 +64,7 @@ class ShaderCompiler {
* This function determines the appropriate directory for caching shaders
* based on the operating system and returns the full path for the specified shader name.
*/
static fn getCacheFilePath(const string& shaderName) -> string {
static fn getCacheFilePath(const string& shaderName) -> std::filesystem::path {
using namespace std::filesystem;
#ifdef _WIN32
@ -78,7 +78,7 @@ class ShaderCompiler {
if (!exists(cacheDir))
create_directories(cacheDir); // Create the directory if it doesn't exist
return (cacheDir / (shaderName + ".spv")).string();
return cacheDir / (shaderName + ".spv");
}
/**
@ -117,7 +117,7 @@ class ShaderCompiler {
* This function checks if the specified cache file exists and reads its
* contents into a vector. If the file cannot be opened, an exception is thrown.
*/
static fn loadCachedShader(const string& cacheFile) -> std::vector<u32> {
static fn loadCachedShader(const std::filesystem::path& cacheFile) -> std::vector<u32> {
using namespace std;
if (!filesystem::exists(cacheFile))
@ -127,14 +127,14 @@ class ShaderCompiler {
// Check if the file was successfully opened
if (!file)
throw runtime_error("Failed to open cached shader file: " + cacheFile);
throw runtime_error("Failed to open cached shader file: " + cacheFile.string());
usize fileSize = filesystem::file_size(cacheFile);
vector<u32> spirvCode(fileSize / sizeof(u32));
// Read entire file content into the vector
if (!file.read(bit_cast<char*>(spirvCode.data()), static_cast<streamsize>(fileSize)))
throw runtime_error("Failed to read cached shader file: " + cacheFile);
throw runtime_error("Failed to read cached shader file: " + cacheFile.string());
return spirvCode;
}