Skip to content
Snippets Groups Projects
Verified Commit db38fec2 authored by Tobias Frisch's avatar Tobias Frisch
Browse files

Add some omp pragmas to utilize multiple CPU cores

parent 14d22d7c
No related branches found
No related tags found
No related merge requests found
......@@ -825,6 +825,7 @@ namespace vkcv::asset {
int loadScene(const std::filesystem::path &path, Scene &scene) {
int result = probeScene(path, scene);
size_t i;
if (result != ASSET_SUCCESS) {
vkcv_log(LogLevel::ERROR, "Loading scene failed '%s'",
......@@ -832,7 +833,13 @@ namespace vkcv::asset {
return result;
}
for (size_t i = 0; i < scene.meshes.size(); i++) {
/* Preloading the textures of the scene to improve performance */
#pragma omp parallel for shared(scene.textures) private(i)
for (i = 0; i < scene.textures.size(); i++) {
loadTextureData(scene.textures[i]);
}
for (i = 0; i < scene.meshes.size(); i++) {
result = loadMesh(scene, static_cast<int>(i));
if (result != ASSET_SUCCESS) {
......@@ -849,6 +856,7 @@ namespace vkcv::asset {
Texture texture;
texture.path = path;
texture.sampler = -1;
if (loadTextureData(texture) != ASSET_SUCCESS) {
texture.path.clear();
texture.w = texture.h = texture.channels = 0;
......
......@@ -7,11 +7,24 @@ namespace vkcv::shader {
const std::unordered_map<ShaderStage, const std::filesystem::path>& stages,
const ShaderProgramCompiledFunction& compiled,
const std::filesystem::path& includePath, bool update) {
std::vector<std::pair<ShaderStage, const std::filesystem::path>> stageList;
size_t i;
stageList.reserve(stages.size());
for (const auto& stage : stages) {
stageList.push_back(stage);
}
/* Compile a shader programs stages in parallel to improve performance */
#pragma omp parallel for shared(stageList, includePath, update) private(i)
for (i = 0; i < stageList.size(); i++) {
const auto& stage = stageList[i];
compile(
stage.first,
stage.second,
[&program](ShaderStage shaderStage, const std::filesystem::path& path) {
#pragma omp critical
program.addShader(shaderStage, path);
},
includePath,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment