Actually fixing pipeline cache

This commit is contained in:
2025-07-12 13:50:31 +02:00
parent 750dcf8318
commit 106dfe0423
5 changed files with 35 additions and 28 deletions
+2 -2
View File
@@ -136,9 +136,9 @@ EnvironmentLoader::EnvironmentLoader(Gfx::PGraphics graphics) : graphics(graphic
{Gfx::SubPassDependency{
.srcSubpass = 0,
.dstSubpass = ~0U,
.srcStage = Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
.srcStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
.dstStage = Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
.srcAccess = Gfx::SE_ACCESS_NONE,
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_SHADER_READ_BIT,
}},
URect{{512, 512}, {0, 0}}, "LUTGeneration");
+6
View File
@@ -1,5 +1,7 @@
#include "PlayView.h"
#include "Component/Mesh.h"
#include "Graphics/Enums.h"
#include "MinimalEngine.h"
#include "Window/Window.h"
using namespace Seele;
@@ -34,6 +36,10 @@ void PlayView::keyCallback(KeyCode code, InputAction action, KeyModifier modifie
getGlobals().useLightCulling = !getGlobals().useLightCulling;
std::cout << "Use Light Culling " << getGlobals().useLightCulling << std::endl;
}
if(code == KeyCode::KEY_K && action == InputAction::RELEASE) {
getGlobals().useImagebasedLighting = !getGlobals().useImagebasedLighting;
std::cout << "Use IBL " << getGlobals().useImagebasedLighting << std::endl;
}
if (code == KeyCode::KEY_G && action == InputAction::RELEASE) {
Component::Camera cam;
Component::Transform tra;
+5 -12
View File
@@ -518,17 +518,12 @@ template <typename T, size_t N> struct StaticArray {
using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
constexpr StaticArray() {
beginIt = iterator(_data);
endIt = iterator(_data + N);
}
constexpr StaticArray() {}
constexpr StaticArray(T value) {
for (size_t i = 0; i < N; ++i) {
_data[i] = value;
}
beginIt = iterator(_data);
endIt = iterator(_data + N);
}
constexpr StaticArray(std::initializer_list<T> init) {
@@ -555,14 +550,12 @@ template <typename T, size_t N> struct StaticArray {
assert(index < N);
return _data[index];
}
constexpr iterator begin() { return beginIt; }
constexpr iterator end() { return endIt; }
constexpr const_iterator begin() const { return beginIt; }
constexpr const_iterator end() const { return beginIt; }
constexpr iterator begin() { return iterator(_data); }
constexpr iterator end() { return iterator(_data + N); }
constexpr const_iterator begin() const { return iterator(_data); }
constexpr const_iterator end() const { return iterator(_data + N); }
private:
T _data[N] = {T()};
iterator beginIt;
iterator endIt;
};
} // namespace Seele
+19 -12
View File
@@ -45,11 +45,9 @@ PipelineCache::~PipelineCache() {
}
PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo gfxInfo) {
uint32 hash = CRC::Calculate(&gfxInfo, sizeof(Gfx::LegacyPipelineCreateInfo), CRC::CRC_32());
if (graphicsPipelines.contains(hash)) {
return graphicsPipelines[hash];
}
PPipelineLayout layout = gfxInfo.pipelineLayout.cast<PipelineLayout>();
PPipelineLayout layout = Gfx::PPipelineLayout(gfxInfo.pipelineLayout).cast<PipelineLayout>();
uint32 hash = layout->getHash();
Array<VkVertexInputBindingDescription> bindings;
Array<VkVertexInputAttributeDescription> attributes;
if (gfxInfo.vertexInput != nullptr) {
@@ -70,6 +68,9 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo gf
};
}
}
hash = CRC::Calculate(bindings.data(), bindings.size() * sizeof(VkVertexInputBindingDescription), CRC::CRC_32(), hash);
hash = CRC::Calculate(attributes.data(), attributes.size() * sizeof(VkVertexInputAttributeDescription), CRC::CRC_32(), hash);
VkPipelineVertexInputStateCreateInfo vertexInput = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
.pNext = nullptr,
@@ -81,8 +82,7 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo gf
};
uint32 stageCount = 0;
VkPipelineShaderStageCreateInfo stageInfos[2];
std::memset(stageInfos, 0, sizeof(stageInfos));
StaticArray<VkPipelineShaderStageCreateInfo, 2> stageInfos;
PVertexShader vertexShader = gfxInfo.vertexShader.cast<VertexShader>();
stageInfos[stageCount++] = {
@@ -108,6 +108,8 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo gf
.pSpecializationInfo = nullptr,
};
}
hash = CRC::Calculate(stageInfos.data(), stageInfos.size() * sizeof(VkVertexInputAttributeDescription), CRC::CRC_32(), hash);
VkPipelineInputAssemblyStateCreateInfo assemblyInfo = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
.pNext = nullptr,
@@ -115,6 +117,8 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo gf
.topology = cast(gfxInfo.topology),
.primitiveRestartEnable = false,
};
hash = CRC::Calculate(&assemblyInfo, sizeof(VkPipelineInputAssemblyStateCreateInfo), CRC::CRC_32(), hash);
VkPipelineViewportStateCreateInfo viewportInfo = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
.pNext = nullptr,
@@ -124,6 +128,7 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo gf
.scissorCount = 1,
.pScissors = nullptr,
};
hash = CRC::Calculate(&viewportInfo, sizeof(VkPipelineViewportStateCreateInfo), CRC::CRC_32(), hash);
VkPipelineRasterizationStateCreateInfo rasterizationState = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
.pNext = nullptr,
@@ -192,6 +197,9 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo gf
dynamicEnabled[numDynamicEnabled++] = VK_DYNAMIC_STATE_VIEWPORT;
dynamicEnabled[numDynamicEnabled++] = VK_DYNAMIC_STATE_SCISSOR;
if (graphicsPipelines.contains(hash)) {
return graphicsPipelines[hash];
}
VkPipelineDynamicStateCreateInfo dynamicState = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
.pNext = nullptr,
@@ -206,7 +214,7 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo gf
.pNext = 0,
.flags = 0,
.stageCount = stageCount,
.pStages = stageInfos,
.pStages = stageInfos.data(),
.pVertexInputState = &vertexInput,
.pInputAssemblyState = &assemblyInfo,
.pViewportState = &viewportInfo,
@@ -236,8 +244,7 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxI
uint32 hash = layout->getHash();
uint32 stageCount = 0;
VkPipelineShaderStageCreateInfo stageInfos[3];
std::memset(stageInfos, 0, sizeof(stageInfos));
StaticArray<VkPipelineShaderStageCreateInfo, 3> stageInfos;
if (gfxInfo.taskShader != nullptr) {
PTaskShader taskShader = gfxInfo.taskShader.cast<TaskShader>();
@@ -276,7 +283,7 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxI
.pSpecializationInfo = nullptr,
};
}
hash = CRC::Calculate(stageInfos, sizeof(stageInfos), CRC::CRC_32(), hash);
hash = CRC::Calculate(stageInfos.data(), sizeof(stageInfos), CRC::CRC_32(), hash);
VkPipelineViewportStateCreateInfo viewportInfo = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
@@ -401,7 +408,7 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxI
.pNext = 0,
.flags = 0,
.stageCount = stageCount,
.pStages = stageInfos,
.pStages = stageInfos.data(),
.pVertexInputState = nullptr,
.pInputAssemblyState = nullptr,
.pViewportState = &viewportInfo,
+1
View File
@@ -148,6 +148,7 @@ struct Globals {
bool usePositionOnly = true;
bool useDepthCulling = true;
bool useLightCulling = true;
bool useImagebasedLighting = true;
bool useRayTracing = false;
bool running = true;
};