its running i think

This commit is contained in:
Dynamitos
2023-11-09 22:15:51 +01:00
parent 19c3e559b1
commit effb0c6214
34 changed files with 299 additions and 249 deletions
-1
View File
@@ -6,7 +6,6 @@
"ctestCommandArgs": "", "ctestCommandArgs": "",
"configurationType": "Debug", "configurationType": "Debug",
"generator": "Visual Studio 17 2022 Win64", "generator": "Visual Studio 17 2022 Win64",
"addressSanitizerEnabled": true,
"intelliSenseMode": "windows-msvc-x64", "intelliSenseMode": "windows-msvc-x64",
"inheritEnvironments": [ "msvc_x64" ], "inheritEnvironments": [ "msvc_x64" ],
"cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64",
+1 -2
View File
@@ -14,9 +14,8 @@ struct LightCullingData
ParameterBlock<LightCullingData> pLightCullingData; ParameterBlock<LightCullingData> pLightCullingData;
[shader("pixel")] [shader("pixel")]
void pixelMain(in VertexAttributes attribs, out float4 baseColor) void pixelMain(in MaterialParameter params : PARAMETER, out float4 baseColor)
{ {
MaterialParameter params = attribs.create();
BRDF brdf = pMaterial.prepare(params); BRDF brdf = pMaterial.prepare(params);
float3 result = float3(0, 0, 0); float3 result = float3(0, 0, 0);
for(int i = 0; i < pLightEnv.numDirectionalLights; ++i) for(int i = 0; i < pLightEnv.numDirectionalLights; ++i)
+3 -2
View File
@@ -1,4 +1,5 @@
import VertexData; import VertexData;
import MaterialParameter;
struct InstanceData struct InstanceData
{ {
@@ -13,11 +14,11 @@ struct Scene
ParameterBlock<Scene> pScene; ParameterBlock<Scene> pScene;
[shader("vertex")] [shader("vertex")]
IVertexAttributes vertexMain( VertexAttributes vertexMain(
uint vertexId: SV_VertexID, uint vertexId: SV_VertexID,
uint instanceId: SV_InstanceID, uint instanceId: SV_InstanceID,
){ ){
InstanceData inst = pScene.instances[instanceId]; InstanceData inst = pScene.instances[instanceId];
IVertexAttributes attr = pVertexData.getAttributes(vertexId, inst.transformMatrix); VertexAttributes attr = pVertexData.getAttributes(vertexId, inst.transformMatrix);
return attr; return attr;
} }
+2 -2
View File
@@ -61,7 +61,7 @@ void taskMain(
DispatchMesh(head, 1, 1, p); DispatchMesh(head, 1, 1, p);
} }
groupshared IVertexAttributes gs_vertices[MAX_VERTICES]; groupshared VertexAttributes gs_vertices[MAX_VERTICES];
groupshared uint3 gs_indices[MAX_PRIMITIVES]; groupshared uint3 gs_indices[MAX_PRIMITIVES];
groupshared uint gs_numVertices; groupshared uint gs_numVertices;
groupshared uint gs_numPrimitives; groupshared uint gs_numPrimitives;
@@ -78,7 +78,7 @@ void meshMain(
in uint threadID: SV_GroupIndex, in uint threadID: SV_GroupIndex,
in uint groupID: SV_GroupID, in uint groupID: SV_GroupID,
in payload MeshPayload meshPayload, in payload MeshPayload meshPayload,
out Vertices<IVertexAttributes, MAX_VERTICES> vertices, out Vertices<VertexAttributes, MAX_VERTICES> vertices,
out Indices<uint3, MAX_PRIMITIVES> indices out Indices<uint3, MAX_PRIMITIVES> indices
){ ){
InstanceData inst = pScene.instances[meshPayload.instanceId[groupID]]; InstanceData inst = pScene.instances[meshPayload.instanceId[groupID]];
+5
View File
@@ -9,3 +9,8 @@ struct MaterialParameter
float3 viewDir_TS; float3 viewDir_TS;
} }
struct VertexAttributes
{
MaterialParameter parameter : PARAMETER;
float4 clipPosition: SV_POSITION;
};
@@ -2,36 +2,6 @@ import VertexData;
import Common; import Common;
import Scene; import Scene;
struct SkinnedMeshVertexAttributes : VertexAttributes
{
float4 clipPosition: SV_Position;
float3 worldPosition: POSITION0;
float2 texCoords: TEXCOORD0;
float3 normal: NORMAL0;
float3 tangent: TANGENT0;
float3 biTangent: BITANGENT0;
float3 getWorldPosition()
{
return worldPosition;
}
float2 getTexCoords()
{
return texCoords;
}
float3 getNormal()
{
return normal;
}
float3 getTangent()
{
return tangent;
}
float3 getBiTangent()
{
return biTangent;
}
}
struct SkinnedMeshVertexData : VertexData struct SkinnedMeshVertexData : VertexData
{ {
SkinnedMeshVertexAttributes getAttributes(uint index, float4x4 transform) SkinnedMeshVertexAttributes getAttributes(uint index, float4x4 transform)
+11 -32
View File
@@ -2,45 +2,24 @@ import Common;
import VertexData; import VertexData;
import MaterialParameter; import MaterialParameter;
struct StaticMeshVertexAttributes : IVertexAttributes
{
float4 clipPosition: SV_Position;
float3 worldPosition: POSITION0;
float2 texCoords: TEXCOORD0;
float3 normal: NORMAL0;
float3 tangent: TANGENT0;
float3 biTangent: BITANGENT0;
MaterialParameter create()
{
MaterialParameter result;
result.worldPosition = worldPosition;
result.texCoords = texCoords;
result.normal = normal;
result.tangent = tangent;
result.biTangent = biTangent;
return result;
}
};
struct StaticMeshVertexData : IVertexData struct StaticMeshVertexData : IVertexData
{ {
typedef StaticMeshVertexAttributes VertexAttributes; VertexAttributes getAttributes(uint index, float4x4 transform)
StaticMeshVertexAttributes getAttributes(uint index, float4x4 transform)
{ {
StaticMeshVertexAttributes attr; VertexAttributes attributes;
MaterialParameter params;
float4 localPos = float4(positions[index], 1); float4 localPos = float4(positions[index], 1);
float4 worldPos = mul(transform, localPos); float4 worldPos = mul(transform, localPos);
float4 viewPos = mul(pViewParams.viewMatrix, worldPos); float4 viewPos = mul(pViewParams.viewMatrix, worldPos);
float4 clipPos = mul(pViewParams.projectionMatrix, viewPos); float4 clipPos = mul(pViewParams.projectionMatrix, viewPos);
attr.clipPosition = clipPos; params.worldPosition = worldPos.xyz;
attr.worldPosition = worldPos.xyz; params.texCoords = texCoords[index];
attr.texCoords = texCoords[index]; params.normal = normals[index];
attr.normal = normals[index]; params.tangent = tangents[index];
attr.tangent = tangents[index]; params.biTangent = biTangents[index];
attr.biTangent = biTangents[index]; attributes.parameter = params;
return attr; attributes.clipPosition = clipPos;
return attributes;
} }
StructuredBuffer<float3> positions; StructuredBuffer<float3> positions;
StructuredBuffer<float2> texCoords; StructuredBuffer<float2> texCoords;
-6
View File
@@ -1,13 +1,7 @@
import MaterialParameter; import MaterialParameter;
interface IVertexAttributes
{
MaterialParameter create();
};
interface IVertexData interface IVertexData
{ {
associatedtype VertexAttributes : IVertexAttributes;
VertexAttributes getAttributes(uint index, float4x4 transform); VertexAttributes getAttributes(uint index, float4x4 transform);
}; };
ParameterBlock<IVertexData> pVertexData; ParameterBlock<IVertexData> pVertexData;
+3 -3
View File
@@ -71,9 +71,9 @@ public:
virtual OComputeShader createComputeShader(const ShaderCreateInfo& createInfo) = 0; virtual OComputeShader createComputeShader(const ShaderCreateInfo& createInfo) = 0;
virtual OMeshShader createMeshShader(const ShaderCreateInfo& createInfo) = 0; virtual OMeshShader createMeshShader(const ShaderCreateInfo& createInfo) = 0;
virtual OTaskShader createTaskShader(const ShaderCreateInfo& createInfo) = 0; virtual OTaskShader createTaskShader(const ShaderCreateInfo& createInfo) = 0;
virtual OGraphicsPipeline createGraphicsPipeline(const LegacyPipelineCreateInfo& createInfo) = 0; virtual PGraphicsPipeline createGraphicsPipeline(LegacyPipelineCreateInfo createInfo) = 0;
virtual OGraphicsPipeline createGraphicsPipeline(const MeshPipelineCreateInfo& createInfo) = 0; virtual PGraphicsPipeline createGraphicsPipeline(MeshPipelineCreateInfo createInfo) = 0;
virtual OComputePipeline createComputePipeline(const ComputePipelineCreateInfo& createInfo) = 0; virtual PComputePipeline createComputePipeline(ComputePipelineCreateInfo createInfo) = 0;
virtual OSamplerState createSamplerState(const SamplerCreateInfo& createInfo) = 0; virtual OSamplerState createSamplerState(const SamplerCreateInfo& createInfo) = 0;
virtual ODescriptorLayout createDescriptorLayout(const std::string& name = "") = 0; virtual ODescriptorLayout createDescriptorLayout(const std::string& name = "") = 0;
+10
View File
@@ -1,4 +1,5 @@
#include "Initializer.h" #include "Initializer.h"
#include "Descriptor.h"
using namespace Seele; using namespace Seele;
using namespace Seele::Gfx; using namespace Seele::Gfx;
@@ -90,3 +91,12 @@ MeshPipelineCreateInfo::MeshPipelineCreateInfo()
MeshPipelineCreateInfo::~MeshPipelineCreateInfo() MeshPipelineCreateInfo::~MeshPipelineCreateInfo()
{ {
} }
ComputePipelineCreateInfo::ComputePipelineCreateInfo()
{
std::memset((void*)this, 0, sizeof(*this));
}
ComputePipelineCreateInfo::~ComputePipelineCreateInfo()
{
}
+11 -7
View File
@@ -203,12 +203,14 @@ struct LegacyPipelineCreateInfo
PVertexShader vertexShader; PVertexShader vertexShader;
PFragmentShader fragmentShader; PFragmentShader fragmentShader;
PRenderPass renderPass; PRenderPass renderPass;
PPipelineLayout pipelineLayout; OPipelineLayout pipelineLayout;
MultisampleState multisampleState; MultisampleState multisampleState;
RasterizationState rasterizationState; RasterizationState rasterizationState;
DepthStencilState depthStencilState; DepthStencilState depthStencilState;
ColorBlendState colorBlend; ColorBlendState colorBlend;
LegacyPipelineCreateInfo(); LegacyPipelineCreateInfo();
LegacyPipelineCreateInfo(LegacyPipelineCreateInfo&& rhs) = default;
LegacyPipelineCreateInfo& operator=(LegacyPipelineCreateInfo&& rhs) = default;
~LegacyPipelineCreateInfo(); ~LegacyPipelineCreateInfo();
}; };
@@ -218,22 +220,24 @@ struct MeshPipelineCreateInfo
PMeshShader meshShader; PMeshShader meshShader;
PFragmentShader fragmentShader; PFragmentShader fragmentShader;
PRenderPass renderPass; PRenderPass renderPass;
PPipelineLayout pipelineLayout; OPipelineLayout pipelineLayout;
MultisampleState multisampleState; MultisampleState multisampleState;
RasterizationState rasterizationState; RasterizationState rasterizationState;
DepthStencilState depthStencilState; DepthStencilState depthStencilState;
ColorBlendState colorBlend; ColorBlendState colorBlend;
MeshPipelineCreateInfo(); MeshPipelineCreateInfo();
MeshPipelineCreateInfo(MeshPipelineCreateInfo&& rhs) = default;
MeshPipelineCreateInfo& operator=(MeshPipelineCreateInfo&& rhs) = default;
~MeshPipelineCreateInfo(); ~MeshPipelineCreateInfo();
}; };
struct ComputePipelineCreateInfo struct ComputePipelineCreateInfo
{ {
Gfx::PComputeShader computeShader; Gfx::PComputeShader computeShader;
Gfx::PPipelineLayout pipelineLayout; Gfx::OPipelineLayout pipelineLayout;
ComputePipelineCreateInfo() ComputePipelineCreateInfo();
{ ComputePipelineCreateInfo(ComputePipelineCreateInfo&& rhs) = default;
std::memset((void*)this, 0, sizeof(*this)); ComputePipelineCreateInfo& operator=(ComputePipelineCreateInfo&& rhs) = default;
} ~ComputePipelineCreateInfo();
}; };
} // namespace Gfx } // namespace Gfx
} // namespace Seele } // namespace Seele
+13 -6
View File
@@ -121,10 +121,10 @@ void BasePass::render()
pipelineInfo.taskShader = collection->taskShader; pipelineInfo.taskShader = collection->taskShader;
pipelineInfo.meshShader = collection->meshShader; pipelineInfo.meshShader = collection->meshShader;
pipelineInfo.fragmentShader = collection->fragmentShader; pipelineInfo.fragmentShader = collection->fragmentShader;
pipelineInfo.pipelineLayout = layout; pipelineInfo.pipelineLayout = std::move(layout);
pipelineInfo.renderPass = renderPass; pipelineInfo.renderPass = renderPass;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL; pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL;
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(pipelineInfo); Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline); command->bindPipeline(pipeline);
} }
else else
@@ -133,10 +133,10 @@ void BasePass::render()
pipelineInfo.vertexDeclaration = collection->vertexDeclaration; pipelineInfo.vertexDeclaration = collection->vertexDeclaration;
pipelineInfo.vertexShader = collection->vertexShader; pipelineInfo.vertexShader = collection->vertexShader;
pipelineInfo.fragmentShader = collection->fragmentShader; pipelineInfo.fragmentShader = collection->fragmentShader;
pipelineInfo.pipelineLayout = layout; pipelineInfo.pipelineLayout = std::move(layout);
pipelineInfo.renderPass = renderPass; pipelineInfo.renderPass = renderPass;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL; pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL;
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(pipelineInfo); Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline); command->bindPipeline(pipeline);
} }
@@ -156,8 +156,15 @@ void BasePass::render()
for(const auto& mesh : instance.meshes) for(const auto& mesh : instance.meshes)
{ {
uint32 vertexOffset = vertexData->getMeshOffset(mesh.id); uint32 vertexOffset = vertexData->getMeshOffset(mesh.id);
command->bindIndexBuffer(mesh.indexBuffer); if (mesh.indexBuffer != nullptr)
command->drawIndexed(mesh.indexBuffer->getNumIndices(), 1, 0, vertexOffset, instanceOffset); {
command->bindIndexBuffer(mesh.indexBuffer);
command->drawIndexed(mesh.indexBuffer->getNumIndices(), 1, 0, vertexOffset, instanceOffset);
}
else
{
command->draw(vertexData->getMeshVertexCount(mesh.id), 1, vertexOffset, instanceOffset);
}
} }
} }
} }
+19 -17
View File
@@ -13,7 +13,7 @@ using namespace Seele;
DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, PScene scene) DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, PScene scene)
: RenderPass(graphics, scene) : RenderPass(graphics, scene)
, descriptorSets(4) , descriptorSets(3)
{ {
UniformBufferCreateInfo uniformInitializer; UniformBufferCreateInfo uniformInitializer;
@@ -39,18 +39,14 @@ void DepthPrepass::render()
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT); Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT);
depthAttachment->getTexture()->transferOwnership(Gfx::QueueType::GRAPHICS); depthAttachment->getTexture()->transferOwnership(Gfx::QueueType::GRAPHICS);
Gfx::ShaderPermutation permutation; Gfx::ShaderPermutation permutation;
permutation.hasFragment = false;
if(graphics->supportMeshShading()) if(graphics->supportMeshShading())
{ {
permutation.useMeshShading = true; permutation.setTaskFile("MeshletBasePass");
permutation.hasTaskShader = true; permutation.setMeshFile("MeshletBasePass");
std::strncpy(permutation.taskFile, "MeshletBasePass", sizeof("MeshletBasePass"));
std::strncpy(permutation.vertexMeshFile, "MeshletBasePass", sizeof("MeshletBasePass"));
} }
else else
{ {
permutation.useMeshShading = false; permutation.setVertexFile("LegacyBasePass");
std::strncpy(permutation.vertexMeshFile, "LegacyBasePass", sizeof("LegacyBasePass"));
} }
graphics->beginRenderPass(renderPass); graphics->beginRenderPass(renderPass);
for (VertexData* vertexData : VertexData::getList()) for (VertexData* vertexData : VertexData::getList())
@@ -65,12 +61,11 @@ void DepthPrepass::render()
// Material => per material // Material => per material
// VertexData => per meshtype // VertexData => per meshtype
// SceneData => per material instance // SceneData => per material instance
std::strncpy(permutation.materialName, materialData.material->getName().c_str(), sizeof(permutation.materialName));
Gfx::PermutationId id(permutation); Gfx::PermutationId id(permutation);
Gfx::PRenderCommand command = graphics->createRenderCommand("DepthRender"); Gfx::PRenderCommand command = graphics->createRenderCommand("DepthRender");
Gfx::OPipelineLayout layout = graphics->createPipelineLayout(depthPrepassLayout); Gfx::OPipelineLayout layout = graphics->createPipelineLayout(depthPrepassLayout);
layout->addDescriptorLayout(INDEX_MATERIAL, materialData.material->getDescriptorLayout()); //layout->addDescriptorLayout(INDEX_MATERIAL, materialData.material->getDescriptorLayout());
layout->addDescriptorLayout(INDEX_VERTEX_DATA, vertexData->getVertexDataLayout()); layout->addDescriptorLayout(INDEX_VERTEX_DATA, vertexData->getVertexDataLayout());
layout->addDescriptorLayout(INDEX_SCENE_DATA, vertexData->getInstanceDataLayout()); layout->addDescriptorLayout(INDEX_SCENE_DATA, vertexData->getInstanceDataLayout());
layout->create(); layout->create();
@@ -83,10 +78,10 @@ void DepthPrepass::render()
pipelineInfo.taskShader = collection->taskShader; pipelineInfo.taskShader = collection->taskShader;
pipelineInfo.meshShader = collection->meshShader; pipelineInfo.meshShader = collection->meshShader;
pipelineInfo.fragmentShader = collection->fragmentShader; pipelineInfo.fragmentShader = collection->fragmentShader;
pipelineInfo.pipelineLayout = layout; pipelineInfo.pipelineLayout = std::move(layout);
pipelineInfo.renderPass = renderPass; pipelineInfo.renderPass = renderPass;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL; pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL;
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(pipelineInfo); Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline); command->bindPipeline(pipeline);
} }
else else
@@ -95,17 +90,17 @@ void DepthPrepass::render()
pipelineInfo.vertexDeclaration = collection->vertexDeclaration; pipelineInfo.vertexDeclaration = collection->vertexDeclaration;
pipelineInfo.vertexShader = collection->vertexShader; pipelineInfo.vertexShader = collection->vertexShader;
pipelineInfo.fragmentShader = collection->fragmentShader; pipelineInfo.fragmentShader = collection->fragmentShader;
pipelineInfo.pipelineLayout = layout; pipelineInfo.pipelineLayout = std::move(layout);
pipelineInfo.renderPass = renderPass; pipelineInfo.renderPass = renderPass;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL; pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL;
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(pipelineInfo); Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline); command->bindPipeline(pipeline);
} }
descriptorSets[INDEX_VERTEX_DATA] = vertexData->getVertexDataSet(); descriptorSets[INDEX_VERTEX_DATA] = vertexData->getVertexDataSet();
for (const auto& [_, instance] : materialData.instances) for (const auto& [_, instance] : materialData.instances)
{ {
descriptorSets[INDEX_MATERIAL] = instance.materialInstance->getDescriptorSet(); //descriptorSets[INDEX_MATERIAL] = instance.materialInstance->getDescriptorSet();
descriptorSets[INDEX_SCENE_DATA] = instance.descriptorSet; descriptorSets[INDEX_SCENE_DATA] = instance.descriptorSet;
command->bindDescriptor(descriptorSets); command->bindDescriptor(descriptorSets);
if(graphics->supportMeshShading()) if(graphics->supportMeshShading())
@@ -118,8 +113,15 @@ void DepthPrepass::render()
for(const auto& mesh : instance.meshes) for(const auto& mesh : instance.meshes)
{ {
uint32 vertexOffset = vertexData->getMeshOffset(mesh.id); uint32 vertexOffset = vertexData->getMeshOffset(mesh.id);
command->bindIndexBuffer(mesh.indexBuffer); if (mesh.indexBuffer != nullptr)
command->drawIndexed(mesh.indexBuffer->getNumIndices(), 1, 0, vertexOffset, instanceOffset); {
command->bindIndexBuffer(mesh.indexBuffer);
command->drawIndexed(mesh.indexBuffer->getNumIndices(), 1, 0, vertexOffset, instanceOffset);
}
else
{
command->draw(vertexData->getMeshVertexCount(mesh.id), 1, vertexOffset, instanceOffset);
}
} }
} }
} }
@@ -25,12 +25,10 @@ private:
Gfx::OPipelineLayout depthPrepassLayout; Gfx::OPipelineLayout depthPrepassLayout;
// Set 0: viewParameter // Set 0: viewParameter
// Set 1: materials, generated // Set 1: vertices, from VertexData
constexpr static uint32 INDEX_MATERIAL = 1; constexpr static uint32 INDEX_VERTEX_DATA = 1;
// Set 2: vertices, from VertexData // Set 2: mesh data, either index buffer or meshlet data
constexpr static uint32 INDEX_VERTEX_DATA = 2; constexpr static uint32 INDEX_SCENE_DATA = 2;
// Set 3: mesh data, either index buffer or meshlet data
constexpr static uint32 INDEX_SCENE_DATA = 3;
Gfx::ODescriptorLayout sceneDataLayout; Gfx::ODescriptorLayout sceneDataLayout;
}; };
DEFINE_REF(DepthPrepass) DEFINE_REF(DepthPrepass)
@@ -117,7 +117,7 @@ void LightCullingPass::publishOutputs()
lightEnv = scene->getLightEnvironment(); lightEnv = scene->getLightEnvironment();
cullingLayout = graphics->createPipelineLayout(); Gfx::OPipelineLayout cullingLayout = graphics->createPipelineLayout();
cullingLayout->addDescriptorLayout(0, viewParamsLayout); cullingLayout->addDescriptorLayout(0, viewParamsLayout);
cullingLayout->addDescriptorLayout(1, lightEnv->getDescriptorLayout()); cullingLayout->addDescriptorLayout(1, lightEnv->getDescriptorLayout());
cullingLayout->addDescriptorLayout(2, cullingDescriptorLayout); cullingLayout->addDescriptorLayout(2, cullingDescriptorLayout);
@@ -132,8 +132,8 @@ void LightCullingPass::publishOutputs()
Gfx::ComputePipelineCreateInfo pipelineInfo; Gfx::ComputePipelineCreateInfo pipelineInfo;
pipelineInfo.computeShader = cullingShader; pipelineInfo.computeShader = cullingShader;
pipelineInfo.pipelineLayout = cullingLayout; pipelineInfo.pipelineLayout = std::move(cullingLayout);
cullingPipeline = graphics->createComputePipeline(pipelineInfo); cullingPipeline = graphics->createComputePipeline(std::move(pipelineInfo));
uint32 counterReset = 0; uint32 counterReset = 0;
ShaderBufferCreateInfo structInfo = ShaderBufferCreateInfo structInfo =
@@ -203,7 +203,7 @@ void LightCullingPass::setupFrustums()
frustumDescriptorLayout = graphics->createDescriptorLayout("FrustumLayout"); frustumDescriptorLayout = graphics->createDescriptorLayout("FrustumLayout");
frustumDescriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER); frustumDescriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
frustumDescriptorLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER); frustumDescriptorLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
frustumLayout = graphics->createPipelineLayout(); Gfx::OPipelineLayout frustumLayout = graphics->createPipelineLayout();
frustumLayout->addDescriptorLayout(0, viewParamsLayout); frustumLayout->addDescriptorLayout(0, viewParamsLayout);
frustumLayout->addDescriptorLayout(1, frustumDescriptorLayout); frustumLayout->addDescriptorLayout(1, frustumDescriptorLayout);
frustumLayout->create(); frustumLayout->create();
@@ -216,8 +216,8 @@ void LightCullingPass::setupFrustums()
Gfx::ComputePipelineCreateInfo pipelineInfo; Gfx::ComputePipelineCreateInfo pipelineInfo;
pipelineInfo.computeShader = frustumShader; pipelineInfo.computeShader = frustumShader;
pipelineInfo.pipelineLayout = frustumLayout; pipelineInfo.pipelineLayout = std::move(frustumLayout);
frustumPipeline = graphics->createComputePipeline(pipelineInfo); frustumPipeline = graphics->createComputePipeline(std::move(pipelineInfo));
Gfx::OUniformBuffer frustumDispatchParamsBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{ Gfx::OUniformBuffer frustumDispatchParamsBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{
.sourceData = { .sourceData = {
@@ -48,8 +48,7 @@ private:
Gfx::ODescriptorLayout frustumDescriptorLayout; Gfx::ODescriptorLayout frustumDescriptorLayout;
Gfx::PDescriptorSet frustumDescriptorSet; Gfx::PDescriptorSet frustumDescriptorSet;
Gfx::OComputeShader frustumShader; Gfx::OComputeShader frustumShader;
Gfx::OPipelineLayout frustumLayout; Gfx::PComputePipeline frustumPipeline;
Gfx::OComputePipeline frustumPipeline;
PLightEnvironment lightEnv; PLightEnvironment lightEnv;
Gfx::PTexture2D depthAttachment; Gfx::PTexture2D depthAttachment;
@@ -63,8 +62,7 @@ private:
Gfx::PDescriptorSet cullingDescriptorSet; Gfx::PDescriptorSet cullingDescriptorSet;
Gfx::ODescriptorLayout cullingDescriptorLayout; Gfx::ODescriptorLayout cullingDescriptorLayout;
Gfx::OComputeShader cullingShader; Gfx::OComputeShader cullingShader;
Gfx::OPipelineLayout cullingLayout; Gfx::PComputePipeline cullingPipeline;
Gfx::OComputePipeline cullingPipeline;
}; };
DEFINE_REF(LightCullingPass) DEFINE_REF(LightCullingPass)
} // namespace Seele } // namespace Seele
@@ -96,13 +96,16 @@ void SkyboxRenderPass::beginFrame(const Component::Camera& cam)
uniformUpdate.size = sizeof(ViewParameter); uniformUpdate.size = sizeof(ViewParameter);
uniformUpdate.data = (uint8*)&viewParams; uniformUpdate.data = (uint8*)&viewParams;
viewParamsBuffer->updateContents(uniformUpdate); viewParamsBuffer->updateContents(uniformUpdate);
descriptorLayout->reset(); skyboxDataLayout->reset();
descriptorSet = descriptorLayout->allocateDescriptorSet(); textureLayout->reset();
descriptorSet->updateBuffer(0, viewParamsBuffer); skyboxDataSet = skyboxDataLayout->allocateDescriptorSet();
descriptorSet->updateTexture(1, skybox.day); skyboxDataSet->updateBuffer(0, viewParamsBuffer);
descriptorSet->updateTexture(2, skybox.night); skyboxDataSet->writeChanges();
descriptorSet->updateSampler(3, skyboxSampler); textureSet = textureLayout->allocateDescriptorSet();
descriptorSet->writeChanges(); textureSet->updateTexture(0, skybox.day);
textureSet->updateTexture(1, skybox.night);
textureSet->updateSampler(2, skyboxSampler);
textureSet->writeChanges();
} }
void SkyboxRenderPass::render() void SkyboxRenderPass::render()
@@ -111,10 +114,8 @@ void SkyboxRenderPass::render()
Gfx::PRenderCommand renderCommand = graphics->createRenderCommand("SkyboxRender"); Gfx::PRenderCommand renderCommand = graphics->createRenderCommand("SkyboxRender");
renderCommand->setViewport(viewport); renderCommand->setViewport(viewport);
renderCommand->bindPipeline(pipeline); renderCommand->bindPipeline(pipeline);
renderCommand->bindDescriptor(descriptorSet); renderCommand->bindDescriptor({skyboxDataSet, textureSet});
renderCommand->bindVertexBuffer({ cubeBuffer }); renderCommand->bindVertexBuffer({ cubeBuffer });
renderCommand->pushConstants(pipelineLayout, Gfx::SE_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(Vector), &skybox.fogColor);
renderCommand->pushConstants(pipelineLayout, Gfx::SE_SHADER_STAGE_FRAGMENT_BIT, sizeof(Vector), sizeof(float), &skybox.blendFactor);
renderCommand->draw(36, 1, 0, 0); renderCommand->draw(36, 1, 0, 0);
graphics->executeCommands(Array{ renderCommand }); graphics->executeCommands(Array{ renderCommand });
graphics->endRenderPass(); graphics->endRenderPass();
@@ -136,22 +137,14 @@ void SkyboxRenderPass::publishOutputs()
}; };
viewParamsBuffer = graphics->createUniformBuffer(viewCreateInfo); viewParamsBuffer = graphics->createUniformBuffer(viewCreateInfo);
descriptorLayout = graphics->createDescriptorLayout("SkyboxDescLayout"); skyboxDataLayout = graphics->createDescriptorLayout("SkyboxDescLayout");
descriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER); skyboxDataLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
descriptorLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE); skyboxDataLayout->create();
descriptorLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE); textureLayout = graphics->createDescriptorLayout();
descriptorLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER); textureLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
descriptorLayout->create(); textureLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
textureLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER);
pipelineLayout = graphics->createPipelineLayout(); textureLayout->create();
pipelineLayout->addDescriptorLayout(0, descriptorLayout);
pipelineLayout->addPushConstants(Gfx::SePushConstantRange{
.stageFlags = Gfx::SE_SHADER_STAGE_FRAGMENT_BIT,
.offset = 0,
.size = sizeof(Vector4),
});
pipelineLayout->create();
skyboxSampler = graphics->createSamplerState({}); skyboxSampler = graphics->createSamplerState({});
} }
@@ -185,6 +178,11 @@ void SkyboxRenderPass::createRenderPass()
} }
}); });
Gfx::OPipelineLayout pipelineLayout = graphics->createPipelineLayout();
pipelineLayout->addDescriptorLayout(0, skyboxDataLayout);
pipelineLayout->addDescriptorLayout(0, textureLayout);
pipelineLayout->create();
Gfx::LegacyPipelineCreateInfo gfxInfo; Gfx::LegacyPipelineCreateInfo gfxInfo;
gfxInfo.vertexDeclaration = declaration; gfxInfo.vertexDeclaration = declaration;
gfxInfo.vertexShader = vertexShader; gfxInfo.vertexShader = vertexShader;
@@ -192,7 +190,7 @@ void SkyboxRenderPass::createRenderPass()
gfxInfo.rasterizationState.polygonMode = Gfx::SE_POLYGON_MODE_FILL; gfxInfo.rasterizationState.polygonMode = Gfx::SE_POLYGON_MODE_FILL;
gfxInfo.rasterizationState.lineWidth = 5.f; gfxInfo.rasterizationState.lineWidth = 5.f;
gfxInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; gfxInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
gfxInfo.pipelineLayout = pipelineLayout; gfxInfo.pipelineLayout = std::move(pipelineLayout);
gfxInfo.renderPass = renderPass; gfxInfo.renderPass = renderPass;
pipeline = graphics->createGraphicsPipeline(gfxInfo); pipeline = graphics->createGraphicsPipeline(std::move(gfxInfo));
} }
@@ -23,13 +23,14 @@ public:
private: private:
Gfx::OVertexBuffer cubeBuffer; Gfx::OVertexBuffer cubeBuffer;
Gfx::OUniformBuffer viewParamsBuffer; Gfx::OUniformBuffer viewParamsBuffer;
Gfx::ODescriptorLayout descriptorLayout; Gfx::ODescriptorLayout skyboxDataLayout;
Gfx::PDescriptorSet descriptorSet; Gfx::PDescriptorSet skyboxDataSet;
Gfx::OPipelineLayout pipelineLayout; Gfx::ODescriptorLayout textureLayout;
Gfx::PDescriptorSet textureSet;
Gfx::OVertexDeclaration declaration; Gfx::OVertexDeclaration declaration;
Gfx::OVertexShader vertexShader; Gfx::OVertexShader vertexShader;
Gfx::OFragmentShader fragmentShader; Gfx::OFragmentShader fragmentShader;
Gfx::OGraphicsPipeline pipeline; Gfx::PGraphicsPipeline pipeline;
Gfx::OSamplerState skyboxSampler; Gfx::OSamplerState skyboxSampler;
Component::Skybox skybox; Component::Skybox skybox;
}; };
+5 -4
View File
@@ -85,7 +85,7 @@ void TextPass::render()
command->bindDescriptor({generalSet, resource.textureArraySet}); command->bindDescriptor({generalSet, resource.textureArraySet});
command->bindVertexBuffer({resource.vertexBuffer}); command->bindVertexBuffer({resource.vertexBuffer});
command->pushConstants(pipelineLayout, Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(TextData), &resource.textData); command->pushConstants(layoutRef, Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(TextData), &resource.textData);
command->draw(4, static_cast<uint32>(resource.vertexBuffer->getNumVertices()), 0, 0); command->draw(4, static_cast<uint32>(resource.vertexBuffer->getNumVertices()), 0, 0);
} }
commands.add(command); commands.add(command);
@@ -176,7 +176,8 @@ void TextPass::createRenderPass()
generalSet->updateSampler(1, glyphSampler); generalSet->updateSampler(1, glyphSampler);
generalSet->writeChanges(); generalSet->writeChanges();
pipelineLayout = graphics->createPipelineLayout(); Gfx::OPipelineLayout pipelineLayout = graphics->createPipelineLayout();
layoutRef = pipelineLayout;
pipelineLayout->addDescriptorLayout(0, generalLayout); pipelineLayout->addDescriptorLayout(0, generalLayout);
pipelineLayout->addDescriptorLayout(1, textureArrayLayout); pipelineLayout->addDescriptorLayout(1, textureArrayLayout);
pipelineLayout->addPushConstants({ pipelineLayout->addPushConstants({
@@ -193,7 +194,7 @@ void TextPass::createRenderPass()
pipelineInfo.vertexShader = vertexShader; pipelineInfo.vertexShader = vertexShader;
pipelineInfo.fragmentShader = fragmentShader; pipelineInfo.fragmentShader = fragmentShader;
pipelineInfo.renderPass = renderPass; pipelineInfo.renderPass = renderPass;
pipelineInfo.pipelineLayout = pipelineLayout; pipelineInfo.pipelineLayout = std::move(pipelineLayout);
pipelineInfo.rasterizationState.cullMode = Gfx::SE_CULL_MODE_NONE; pipelineInfo.rasterizationState.cullMode = Gfx::SE_CULL_MODE_NONE;
pipelineInfo.colorBlend.attachmentCount = 1; pipelineInfo.colorBlend.attachmentCount = 1;
pipelineInfo.colorBlend.blendAttachments[0].blendEnable = true; pipelineInfo.colorBlend.blendAttachments[0].blendEnable = true;
@@ -206,7 +207,7 @@ void TextPass::createRenderPass()
pipelineInfo.colorBlend.blendAttachments[0].alphaBlendOp = Gfx::SE_BLEND_OP_ADD; pipelineInfo.colorBlend.blendAttachments[0].alphaBlendOp = Gfx::SE_BLEND_OP_ADD;
pipelineInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; pipelineInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
pipeline = graphics->createGraphicsPipeline(pipelineInfo); pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
} }
TextPass::FontData& TextPass::getFontData(PFontAsset font) TextPass::FontData& TextPass::getFontData(PFontAsset font)
{ {
+2 -2
View File
@@ -78,8 +78,8 @@ private:
Gfx::OVertexDeclaration declaration; Gfx::OVertexDeclaration declaration;
Gfx::OVertexShader vertexShader; Gfx::OVertexShader vertexShader;
Gfx::OFragmentShader fragmentShader; Gfx::OFragmentShader fragmentShader;
Gfx::OPipelineLayout pipelineLayout; Gfx::PPipelineLayout layoutRef;
Gfx::OGraphicsPipeline pipeline; Gfx::PGraphicsPipeline pipeline;
Array<TextRender> texts; Array<TextRender> texts;
}; };
DEFINE_REF(TextPass); DEFINE_REF(TextPass);
+3 -3
View File
@@ -173,7 +173,7 @@ void UIPass::createRenderPass()
descriptorSet->updateSampler(1, backgroundSampler); descriptorSet->updateSampler(1, backgroundSampler);
descriptorSet->writeChanges(); descriptorSet->writeChanges();
pipelineLayout = graphics->createPipelineLayout(); Gfx::OPipelineLayout pipelineLayout = graphics->createPipelineLayout();
pipelineLayout->addDescriptorLayout(0, descriptorLayout); pipelineLayout->addDescriptorLayout(0, descriptorLayout);
pipelineLayout->create(); pipelineLayout->create();
@@ -185,9 +185,9 @@ void UIPass::createRenderPass()
pipelineInfo.vertexShader = vertexShader; pipelineInfo.vertexShader = vertexShader;
pipelineInfo.fragmentShader = fragmentShader; pipelineInfo.fragmentShader = fragmentShader;
pipelineInfo.renderPass = renderPass; pipelineInfo.renderPass = renderPass;
pipelineInfo.pipelineLayout = pipelineLayout; pipelineInfo.pipelineLayout = std::move(pipelineLayout);
pipelineInfo.rasterizationState.cullMode = Gfx::SE_CULL_MODE_NONE; pipelineInfo.rasterizationState.cullMode = Gfx::SE_CULL_MODE_NONE;
pipelineInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; pipelineInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
pipeline = graphics->createGraphicsPipeline(pipelineInfo); pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
} }
+1 -2
View File
@@ -34,8 +34,7 @@ private:
Gfx::OVertexDeclaration declaration; Gfx::OVertexDeclaration declaration;
Gfx::OVertexShader vertexShader; Gfx::OVertexShader vertexShader;
Gfx::OFragmentShader fragmentShader; Gfx::OFragmentShader fragmentShader;
Gfx::OPipelineLayout pipelineLayout; Gfx::PGraphicsPipeline pipeline;
Gfx::OGraphicsPipeline pipeline;
Array<UI::RenderElementStyle> renderElements; Array<UI::RenderElementStyle> renderElements;
Array<Gfx::PTexture> usedTextures; Array<Gfx::PTexture> usedTextures;
+5 -4
View File
@@ -4,6 +4,7 @@
#include "Containers/Array.h" #include "Containers/Array.h"
#include "Containers/List.h" #include "Containers/List.h"
#include "Initializer.h" #include "Initializer.h"
#include "Descriptor.h"
#include "CRC.h" #include "CRC.h"
#include <functional> #include <functional>
@@ -92,22 +93,22 @@ DEFINE_REF(VertexDeclaration)
class GraphicsPipeline class GraphicsPipeline
{ {
public: public:
GraphicsPipeline(PPipelineLayout layout) : layout(layout) {} GraphicsPipeline(OPipelineLayout layout) : layout(std::move(layout)) {}
virtual ~GraphicsPipeline(){} virtual ~GraphicsPipeline(){}
PPipelineLayout getPipelineLayout() const { return layout; } PPipelineLayout getPipelineLayout() const { return layout; }
protected: protected:
PPipelineLayout layout; OPipelineLayout layout;
}; };
DEFINE_REF(GraphicsPipeline) DEFINE_REF(GraphicsPipeline)
class ComputePipeline class ComputePipeline
{ {
public: public:
ComputePipeline(PPipelineLayout layout) : layout(layout) {} ComputePipeline(OPipelineLayout layout) : layout(std::move(layout)) {}
virtual ~ComputePipeline(){} virtual ~ComputePipeline(){}
PPipelineLayout getPipelineLayout() const { return layout; } PPipelineLayout getPipelineLayout() const { return layout; }
protected: protected:
PPipelineLayout layout; OPipelineLayout layout;
}; };
DEFINE_REF(ComputePipeline) DEFINE_REF(ComputePipeline)
+4 -8
View File
@@ -53,32 +53,28 @@ void ShaderCompiler::compile()
ShaderPermutation permutation; ShaderPermutation permutation;
for (const auto& [name, pass] : passes) for (const auto& [name, pass] : passes)
{ {
permutation.hasFragment = pass.hasFragmentShader;
permutation.useMeshShading = pass.useMeshShading;
permutation.hasTaskShader = pass.hasTaskShader;
std::strncpy(permutation.vertexMeshFile, pass.mainFile.c_str(), sizeof(permutation.vertexMeshFile)); std::strncpy(permutation.vertexMeshFile, pass.mainFile.c_str(), sizeof(permutation.vertexMeshFile));
if (pass.hasFragmentShader) if (pass.hasFragmentShader)
{ {
std::strncpy(permutation.fragmentFile, pass.fragmentFile.c_str(), sizeof(permutation.fragmentFile)); permutation.setFragmentFile(pass.fragmentFile);
} }
if (pass.hasTaskShader) if (pass.hasTaskShader)
{ {
std::strncpy(permutation.taskFile, pass.taskFile.c_str(), sizeof(permutation.taskFile)); permutation.setTaskFile(pass.taskFile);
} }
for (const auto& [vdName, vd] : vertexData) for (const auto& [vdName, vd] : vertexData)
{ {
std::strncpy(permutation.vertexDataName, vd->getTypeName().c_str(), sizeof(permutation.vertexDataName)); permutation.setVertexData(vd->getTypeName());
if (pass.useMaterial) if (pass.useMaterial)
{ {
for (const auto& [matName, mat] : materials) for (const auto& [matName, mat] : materials)
{ {
std::strncpy(permutation.materialName, matName.c_str(), sizeof(permutation.materialName)); permutation.setMaterial(mat->getName());
createShaders(permutation); createShaders(permutation);
} }
} }
else else
{ {
std::memset(permutation.materialName, 0, sizeof(permutation.materialName));
createShaders(permutation); createShaders(permutation);
} }
} }
+38 -2
View File
@@ -49,8 +49,8 @@ public:
}; };
DEFINE_REF(ComputeShader) DEFINE_REF(ComputeShader)
//Uniquely identifies a permutation of shaders //Uniquely identifies a permutation of shaders
//using the type parameters used to generate it //using the type parameters used to generate it
struct ShaderPermutation struct ShaderPermutation
{ {
char taskFile[32]; char taskFile[32];
@@ -61,11 +61,47 @@ struct ShaderPermutation
uint8 hasFragment : 1; uint8 hasFragment : 1;
uint8 useMeshShading : 1; uint8 useMeshShading : 1;
uint8 hasTaskShader : 1; uint8 hasTaskShader : 1;
uint8 useMaterial : 1;
//TODO: lightmapping etc //TODO: lightmapping etc
ShaderPermutation() ShaderPermutation()
{ {
std::memset(this, 0, sizeof(ShaderPermutation)); std::memset(this, 0, sizeof(ShaderPermutation));
} }
void setTaskFile(std::string_view name)
{
std::memset(taskFile, 0, sizeof(taskFile));
hasTaskShader = 1;
std::strncpy(taskFile, name.data(), 32);
}
void setVertexFile(std::string_view name)
{
std::memset(vertexMeshFile, 0, sizeof(vertexMeshFile));
useMeshShading = 0;
std::strncpy(vertexMeshFile, name.data(), 32);
}
void setMeshFile(std::string_view name)
{
std::memset(vertexMeshFile, 0, sizeof(vertexMeshFile));
useMeshShading = 1;
std::strncpy(vertexMeshFile, name.data(), 32);
}
void setFragmentFile(std::string_view name)
{
std::memset(fragmentFile, 0, sizeof(fragmentFile));
hasFragment = 1;
std::strncpy(fragmentFile, name.data(), 32);
}
void setVertexData(std::string_view name)
{
std::memset(vertexDataName, 0, sizeof(vertexDataName));
std::strncpy(vertexDataName, name.data(), 32);
}
void setMaterial(std::string_view name)
{
std::memset(materialName, 0, sizeof(materialName));
useMaterial = 1;
std::strncpy(materialName, name.data(), 32);
}
}; };
//Hashed ShaderPermutation for fast lookup //Hashed ShaderPermutation for fast lookup
struct PermutationId struct PermutationId
+8 -1
View File
@@ -33,6 +33,7 @@ void VertexData::updateMesh(const Component::Transform& transform, PMesh mesh)
}, },
.indexBuffer = mesh->indexBuffer, .indexBuffer = mesh->indexBuffer,
}); });
matInstanceData.numMeshes += meshData[mesh->id].size();
} }
void VertexData::loadMesh(MeshId id, Array<Meshlet> loadedMeshlets) void VertexData::loadMesh(MeshId id, Array<Meshlet> loadedMeshlets)
@@ -143,6 +144,7 @@ MeshId VertexData::allocateVertexData(uint64 numVertices)
{ {
MeshId res{ idCounter++ }; MeshId res{ idCounter++ };
meshOffsets[res] = head; meshOffsets[res] = head;
meshVertexCounts[res] = numVertices;
head += numVertices; head += numVertices;
if (head > verticesAllocated) if (head > verticesAllocated)
{ {
@@ -152,11 +154,16 @@ MeshId VertexData::allocateVertexData(uint64 numVertices)
return res; return res;
} }
uint32 VertexData::getMeshOffset(MeshId id) uint64 VertexData::getMeshOffset(MeshId id)
{ {
return meshOffsets[id]; return meshOffsets[id];
} }
uint64 VertexData::getMeshVertexCount(MeshId id)
{
return meshVertexCounts[id];
}
List<VertexData*> vertexDataList; List<VertexData*> vertexDataList;
List<VertexData*> VertexData::getList() List<VertexData*> VertexData::getList()
+3 -1
View File
@@ -65,7 +65,8 @@ public:
void loadMesh(MeshId id, Array<Meshlet> meshlets); void loadMesh(MeshId id, Array<Meshlet> meshlets);
void createDescriptors(); void createDescriptors();
MeshId allocateVertexData(uint64 numVertices); MeshId allocateVertexData(uint64 numVertices);
uint32 getMeshOffset(MeshId id); uint64 getMeshOffset(MeshId id);
uint64 getMeshVertexCount(MeshId id);
virtual void serializeMesh(MeshId id, uint64 numVertices, ArchiveBuffer& buffer) = 0; virtual void serializeMesh(MeshId id, uint64 numVertices, ArchiveBuffer& buffer) = 0;
virtual void deserializeMesh(MeshId id, ArchiveBuffer& buffer) = 0; virtual void deserializeMesh(MeshId id, ArchiveBuffer& buffer) = 0;
virtual void bindBuffers(Gfx::PRenderCommand command) = 0; virtual void bindBuffers(Gfx::PRenderCommand command) = 0;
@@ -100,6 +101,7 @@ protected:
Map<std::string, MaterialData> materialData; Map<std::string, MaterialData> materialData;
Map<MeshId, Array<MeshData>> meshData; Map<MeshId, Array<MeshData>> meshData;
Map<MeshId, uint64> meshOffsets; Map<MeshId, uint64> meshOffsets;
Map<MeshId, uint64> meshVertexCounts;
Array<MeshletDescription> meshlets; Array<MeshletDescription> meshlets;
Array<uint8> primitiveIndices; Array<uint8> primitiveIndices;
Array<uint32> vertexIndices; Array<uint32> vertexIndices;
+6 -6
View File
@@ -191,18 +191,18 @@ Gfx::OMeshShader Graphics::createMeshShader(const ShaderCreateInfo& createInfo)
return std::move(shader); return std::move(shader);
} }
Gfx::OGraphicsPipeline Graphics::createGraphicsPipeline(const Gfx::LegacyPipelineCreateInfo& createInfo) Gfx::PGraphicsPipeline Graphics::createGraphicsPipeline(Gfx::LegacyPipelineCreateInfo createInfo)
{ {
return pipelineCache->createPipeline(createInfo); return pipelineCache->createPipeline(std::move(createInfo));
} }
Gfx::OGraphicsPipeline Graphics::createGraphicsPipeline(const Gfx::MeshPipelineCreateInfo& createInfo) Gfx::PGraphicsPipeline Graphics::createGraphicsPipeline(Gfx::MeshPipelineCreateInfo createInfo)
{ {
return pipelineCache->createPipeline(createInfo); return pipelineCache->createPipeline(std::move(createInfo));
} }
Gfx::OComputePipeline Graphics::createComputePipeline(const Gfx::ComputePipelineCreateInfo& createInfo) Gfx::PComputePipeline Graphics::createComputePipeline(Gfx::ComputePipelineCreateInfo createInfo)
{ {
return pipelineCache->createPipeline(createInfo); return pipelineCache->createPipeline(std::move(createInfo));
} }
Gfx::OSamplerState Graphics::createSamplerState(const SamplerCreateInfo& createInfo) Gfx::OSamplerState Graphics::createSamplerState(const SamplerCreateInfo& createInfo)
+3 -3
View File
@@ -64,9 +64,9 @@ public:
virtual Gfx::OComputeShader createComputeShader(const ShaderCreateInfo& createInfo) override; virtual Gfx::OComputeShader createComputeShader(const ShaderCreateInfo& createInfo) override;
virtual Gfx::OTaskShader createTaskShader(const ShaderCreateInfo& createInfo) override; virtual Gfx::OTaskShader createTaskShader(const ShaderCreateInfo& createInfo) override;
virtual Gfx::OMeshShader createMeshShader(const ShaderCreateInfo& createInfo) override; virtual Gfx::OMeshShader createMeshShader(const ShaderCreateInfo& createInfo) override;
virtual Gfx::OGraphicsPipeline createGraphicsPipeline(const Gfx::LegacyPipelineCreateInfo& createInfo) override; virtual Gfx::PGraphicsPipeline createGraphicsPipeline(Gfx::LegacyPipelineCreateInfo createInfo) override;
virtual Gfx::OGraphicsPipeline createGraphicsPipeline(const Gfx::MeshPipelineCreateInfo& createInfo) override; virtual Gfx::PGraphicsPipeline createGraphicsPipeline(Gfx::MeshPipelineCreateInfo createInfo) override;
virtual Gfx::OComputePipeline createComputePipeline(const Gfx::ComputePipelineCreateInfo& createInfo) override; virtual Gfx::PComputePipeline createComputePipeline(Gfx::ComputePipelineCreateInfo createInfo) override;
virtual Gfx::OSamplerState createSamplerState(const SamplerCreateInfo& createInfo) override; virtual Gfx::OSamplerState createSamplerState(const SamplerCreateInfo& createInfo) override;
virtual Gfx::ODescriptorLayout createDescriptorLayout(const std::string& name = "") override; virtual Gfx::ODescriptorLayout createDescriptorLayout(const std::string& name = "") override;
+6 -6
View File
@@ -5,8 +5,8 @@
using namespace Seele; using namespace Seele;
using namespace Seele::Vulkan; using namespace Seele::Vulkan;
GraphicsPipeline::GraphicsPipeline(PGraphics graphics, VkPipeline handle, PPipelineLayout pipelineLayout) GraphicsPipeline::GraphicsPipeline(PGraphics graphics, VkPipeline handle, Gfx::OPipelineLayout pipelineLayout)
: Gfx::GraphicsPipeline(pipelineLayout) : Gfx::GraphicsPipeline(std::move(pipelineLayout))
, graphics(graphics) , graphics(graphics)
, pipeline(handle) , pipeline(handle)
{ {
@@ -23,11 +23,11 @@ void GraphicsPipeline::bind(VkCommandBuffer handle)
VkPipelineLayout GraphicsPipeline::getLayout() const VkPipelineLayout GraphicsPipeline::getLayout() const
{ {
return layout.cast<PipelineLayout>()->getHandle(); return Gfx::PPipelineLayout(layout).cast<PipelineLayout>()->getHandle();
} }
ComputePipeline::ComputePipeline(PGraphics graphics, VkPipeline handle, PPipelineLayout pipelineLayout) ComputePipeline::ComputePipeline(PGraphics graphics, VkPipeline handle, Gfx::OPipelineLayout pipelineLayout)
: Gfx::ComputePipeline(pipelineLayout) : Gfx::ComputePipeline(std::move(pipelineLayout))
, graphics(graphics) , graphics(graphics)
, pipeline(handle) , pipeline(handle)
{ {
@@ -45,5 +45,5 @@ void ComputePipeline::bind(VkCommandBuffer handle)
VkPipelineLayout ComputePipeline::getLayout() const VkPipelineLayout ComputePipeline::getLayout() const
{ {
return layout.cast<PipelineLayout>()->getHandle(); return Gfx::PPipelineLayout(layout).cast<PipelineLayout>()->getHandle();
} }
+2 -2
View File
@@ -11,7 +11,7 @@ DECLARE_REF(Graphics)
class GraphicsPipeline : public Gfx::GraphicsPipeline class GraphicsPipeline : public Gfx::GraphicsPipeline
{ {
public: public:
GraphicsPipeline(PGraphics graphics, VkPipeline handle, PPipelineLayout pipelineLayout); GraphicsPipeline(PGraphics graphics, VkPipeline handle, Gfx::OPipelineLayout pipelineLayout);
virtual ~GraphicsPipeline(); virtual ~GraphicsPipeline();
void bind(VkCommandBuffer handle); void bind(VkCommandBuffer handle);
VkPipelineLayout getLayout() const; VkPipelineLayout getLayout() const;
@@ -23,7 +23,7 @@ DEFINE_REF(GraphicsPipeline)
class ComputePipeline : public Gfx::ComputePipeline class ComputePipeline : public Gfx::ComputePipeline
{ {
public: public:
ComputePipeline(PGraphics graphics, VkPipeline handle, PPipelineLayout pipelineLayout); ComputePipeline(PGraphics graphics, VkPipeline handle, Gfx::OPipelineLayout pipelineLayout);
virtual ~ComputePipeline(); virtual ~ComputePipeline();
void bind(VkCommandBuffer handle); void bind(VkCommandBuffer handle);
VkPipelineLayout getLayout() const; VkPipelineLayout getLayout() const;
+74 -36
View File
@@ -48,32 +48,10 @@ PipelineCache::~PipelineCache()
std::cout << "Written " << cacheSize << " bytes to cache" << std::endl; std::cout << "Written " << cacheSize << " bytes to cache" << std::endl;
} }
OGraphicsPipeline PipelineCache::createPipeline(const Gfx::LegacyPipelineCreateInfo& gfxInfo) PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo gfxInfo)
{ {
uint32 stageCount = 0; PPipelineLayout layout = Gfx::PPipelineLayout(gfxInfo.pipelineLayout).cast<PipelineLayout>();
uint32 hash = layout->getHash();
VkPipelineShaderStageCreateInfo stageInfos[2];
std::memset(stageInfos, 0, sizeof(stageInfos));
PVertexShader vertexShader = gfxInfo.vertexShader.cast<VertexShader>();
stageInfos[stageCount++] = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.stage = VK_SHADER_STAGE_VERTEX_BIT,
.module = vertexShader->getModuleHandle(),
.pName = vertexShader->getEntryPointName(),
};
if(gfxInfo.fragmentShader != nullptr)
{
PFragmentShader fragment = gfxInfo.fragmentShader.cast<FragmentShader>();
stageInfos[stageCount++] = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.stage = VK_SHADER_STAGE_FRAGMENT_BIT,
.module = fragment->getModuleHandle(),
.pName = fragment->getEntryPointName(),
};
}
VkPipelineVertexInputStateCreateInfo vertexInput = VkPipelineVertexInputStateCreateInfo vertexInput =
init::PipelineVertexInputStateCreateInfo(); init::PipelineVertexInputStateCreateInfo();
@@ -107,19 +85,47 @@ OGraphicsPipeline PipelineCache::createPipeline(const Gfx::LegacyPipelineCreateI
vertexInput.pVertexBindingDescriptions = bindings.data(); vertexInput.pVertexBindingDescriptions = bindings.data();
vertexInput.vertexBindingDescriptionCount = bindings.size(); vertexInput.vertexBindingDescriptionCount = bindings.size();
} }
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);
uint32 stageCount = 0;
VkPipelineShaderStageCreateInfo stageInfos[2];
std::memset(stageInfos, 0, sizeof(stageInfos));
PVertexShader vertexShader = gfxInfo.vertexShader.cast<VertexShader>();
stageInfos[stageCount++] = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.stage = VK_SHADER_STAGE_VERTEX_BIT,
.module = vertexShader->getModuleHandle(),
.pName = vertexShader->getEntryPointName(),
};
if (gfxInfo.fragmentShader != nullptr)
{
PFragmentShader fragment = gfxInfo.fragmentShader.cast<FragmentShader>();
stageInfos[stageCount++] = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.stage = VK_SHADER_STAGE_FRAGMENT_BIT,
.module = fragment->getModuleHandle(),
.pName = fragment->getEntryPointName(),
};
}
hash = CRC::Calculate(stageInfos, sizeof(stageInfos), CRC::CRC_32(), hash);
VkPipelineInputAssemblyStateCreateInfo assemblyInfo = VkPipelineInputAssemblyStateCreateInfo assemblyInfo =
init::PipelineInputAssemblyStateCreateInfo( init::PipelineInputAssemblyStateCreateInfo(
cast(gfxInfo.topology), cast(gfxInfo.topology),
0, 0,
false false
); );
hash = CRC::Calculate(&assemblyInfo, sizeof(assemblyInfo), CRC::CRC_32(), hash);
VkPipelineViewportStateCreateInfo viewportInfo = VkPipelineViewportStateCreateInfo viewportInfo =
init::PipelineViewportStateCreateInfo( init::PipelineViewportStateCreateInfo(
1, 1,
1, 1,
0 0
); );
hash = CRC::Calculate(&viewportInfo, sizeof(viewportInfo), CRC::CRC_32(), hash);
VkPipelineRasterizationStateCreateInfo rasterizationState = VkPipelineRasterizationStateCreateInfo rasterizationState =
init::PipelineRasterizationStateCreateInfo( init::PipelineRasterizationStateCreateInfo(
cast(gfxInfo.rasterizationState.polygonMode), cast(gfxInfo.rasterizationState.polygonMode),
@@ -134,6 +140,7 @@ OGraphicsPipeline PipelineCache::createPipeline(const Gfx::LegacyPipelineCreateI
rasterizationState.depthClampEnable = gfxInfo.rasterizationState.depthClampEnable; rasterizationState.depthClampEnable = gfxInfo.rasterizationState.depthClampEnable;
rasterizationState.lineWidth = gfxInfo.rasterizationState.lineWidth; rasterizationState.lineWidth = gfxInfo.rasterizationState.lineWidth;
rasterizationState.rasterizerDiscardEnable = gfxInfo.rasterizationState.rasterizerDiscardEnable; rasterizationState.rasterizerDiscardEnable = gfxInfo.rasterizationState.rasterizerDiscardEnable;
hash = CRC::Calculate(&rasterizationState, sizeof(rasterizationState), CRC::CRC_32(), hash);
VkPipelineMultisampleStateCreateInfo multisampleState = VkPipelineMultisampleStateCreateInfo multisampleState =
init::PipelineMultisampleStateCreateInfo( init::PipelineMultisampleStateCreateInfo(
@@ -143,6 +150,7 @@ OGraphicsPipeline PipelineCache::createPipeline(const Gfx::LegacyPipelineCreateI
multisampleState.alphaToOneEnable = gfxInfo.multisampleState.alphaToOneEnable; multisampleState.alphaToOneEnable = gfxInfo.multisampleState.alphaToOneEnable;
multisampleState.minSampleShading = gfxInfo.multisampleState.minSampleShading; multisampleState.minSampleShading = gfxInfo.multisampleState.minSampleShading;
multisampleState.sampleShadingEnable = gfxInfo.multisampleState.sampleShadingEnable; multisampleState.sampleShadingEnable = gfxInfo.multisampleState.sampleShadingEnable;
hash = CRC::Calculate(&multisampleState, sizeof(multisampleState), CRC::CRC_32(), hash);
VkPipelineDepthStencilStateCreateInfo depthStencilState = VkPipelineDepthStencilStateCreateInfo depthStencilState =
init::PipelineDepthStencilStateCreateInfo( init::PipelineDepthStencilStateCreateInfo(
@@ -150,6 +158,7 @@ OGraphicsPipeline PipelineCache::createPipeline(const Gfx::LegacyPipelineCreateI
gfxInfo.depthStencilState.depthWriteEnable, gfxInfo.depthStencilState.depthWriteEnable,
cast(gfxInfo.depthStencilState.depthCompareOp) cast(gfxInfo.depthStencilState.depthCompareOp)
); );
hash = CRC::Calculate(&depthStencilState, sizeof(depthStencilState), CRC::CRC_32(), hash);
const auto& colorAttachments = gfxInfo.renderPass->getLayout()->colorAttachments; const auto& colorAttachments = gfxInfo.renderPass->getLayout()->colorAttachments;
Array<VkPipelineColorBlendAttachmentState> blendAttachments(colorAttachments.size()); Array<VkPipelineColorBlendAttachmentState> blendAttachments(colorAttachments.size());
@@ -167,6 +176,8 @@ OGraphicsPipeline PipelineCache::createPipeline(const Gfx::LegacyPipelineCreateI
.colorWriteMask = attachment.colorWriteMask, .colorWriteMask = attachment.colorWriteMask,
}; };
} }
hash = CRC::Calculate(blendAttachments.data(), blendAttachments.size() * sizeof(VkPipelineColorBlendAttachmentState), CRC::CRC_32(), hash);
VkPipelineColorBlendStateCreateInfo blendState = VkPipelineColorBlendStateCreateInfo blendState =
init::PipelineColorBlendStateCreateInfo( init::PipelineColorBlendStateCreateInfo(
(uint32)blendAttachments.size(), (uint32)blendAttachments.size(),
@@ -180,6 +191,7 @@ OGraphicsPipeline PipelineCache::createPipeline(const Gfx::LegacyPipelineCreateI
StaticArray<VkDynamicState, 2> dynamicEnabled; StaticArray<VkDynamicState, 2> dynamicEnabled;
dynamicEnabled[numDynamicEnabled++] = VK_DYNAMIC_STATE_VIEWPORT; dynamicEnabled[numDynamicEnabled++] = VK_DYNAMIC_STATE_VIEWPORT;
dynamicEnabled[numDynamicEnabled++] = VK_DYNAMIC_STATE_SCISSOR; dynamicEnabled[numDynamicEnabled++] = VK_DYNAMIC_STATE_SCISSOR;
hash = CRC::Calculate(dynamicEnabled.data(), dynamicEnabled.size() * sizeof(VkDynamicState), CRC::CRC_32(), hash);
VkPipelineDynamicStateCreateInfo dynamicState = VkPipelineDynamicStateCreateInfo dynamicState =
init::PipelineDynamicStateCreateInfo( init::PipelineDynamicStateCreateInfo(
@@ -188,8 +200,10 @@ OGraphicsPipeline PipelineCache::createPipeline(const Gfx::LegacyPipelineCreateI
0 0
); );
PPipelineLayout layout = gfxInfo.pipelineLayout.cast<PipelineLayout>(); if (graphicsPipelines.contains(hash))
{
return graphicsPipelines[hash];
}
VkPipeline pipelineHandle; VkPipeline pipelineHandle;
VkGraphicsPipelineCreateInfo createInfo = { VkGraphicsPipelineCreateInfo createInfo = {
@@ -216,14 +230,17 @@ OGraphicsPipeline PipelineCache::createPipeline(const Gfx::LegacyPipelineCreateI
int64 delta = std::chrono::duration_cast<std::chrono::microseconds>(endTime - beginTime).count(); int64 delta = std::chrono::duration_cast<std::chrono::microseconds>(endTime - beginTime).count();
std::cout << "Gfx creation time: " << delta << std::endl; std::cout << "Gfx creation time: " << delta << std::endl;
OGraphicsPipeline pipeline = new GraphicsPipeline(graphics, pipelineHandle, std::move(gfxInfo.pipelineLayout));
OGraphicsPipeline result = new GraphicsPipeline(graphics, pipelineHandle, layout); PGraphicsPipeline result = pipeline;
graphicsPipelines[hash] = std::move(pipeline);
return result; return result;
} }
OGraphicsPipeline PipelineCache::createPipeline(const Gfx::MeshPipelineCreateInfo& gfxInfo) PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxInfo)
{ {
PPipelineLayout layout = Gfx::PPipelineLayout(gfxInfo.pipelineLayout).cast<PipelineLayout>();
uint32 hash = layout->getHash();
uint32 stageCount = 0; uint32 stageCount = 0;
VkPipelineShaderStageCreateInfo stageInfos[3]; VkPipelineShaderStageCreateInfo stageInfos[3];
@@ -259,12 +276,16 @@ OGraphicsPipeline PipelineCache::createPipeline(const Gfx::MeshPipelineCreateInf
.pName = fragment->getEntryPointName(), .pName = fragment->getEntryPointName(),
}; };
} }
hash = CRC::Calculate(stageInfos, sizeof(stageInfos), CRC::CRC_32(), hash);
VkPipelineViewportStateCreateInfo viewportInfo = VkPipelineViewportStateCreateInfo viewportInfo =
init::PipelineViewportStateCreateInfo( init::PipelineViewportStateCreateInfo(
1, 1,
1, 1,
0 0
); );
hash = CRC::Calculate(&viewportInfo, sizeof(viewportInfo), CRC::CRC_32(), hash);
VkPipelineRasterizationStateCreateInfo rasterizationState = VkPipelineRasterizationStateCreateInfo rasterizationState =
init::PipelineRasterizationStateCreateInfo( init::PipelineRasterizationStateCreateInfo(
cast(gfxInfo.rasterizationState.polygonMode), cast(gfxInfo.rasterizationState.polygonMode),
@@ -279,6 +300,7 @@ OGraphicsPipeline PipelineCache::createPipeline(const Gfx::MeshPipelineCreateInf
rasterizationState.depthClampEnable = gfxInfo.rasterizationState.depthClampEnable; rasterizationState.depthClampEnable = gfxInfo.rasterizationState.depthClampEnable;
rasterizationState.lineWidth = gfxInfo.rasterizationState.lineWidth; rasterizationState.lineWidth = gfxInfo.rasterizationState.lineWidth;
rasterizationState.rasterizerDiscardEnable = gfxInfo.rasterizationState.rasterizerDiscardEnable; rasterizationState.rasterizerDiscardEnable = gfxInfo.rasterizationState.rasterizerDiscardEnable;
hash = CRC::Calculate(&rasterizationState, sizeof(rasterizationState), CRC::CRC_32(), hash);
VkPipelineMultisampleStateCreateInfo multisampleState = VkPipelineMultisampleStateCreateInfo multisampleState =
init::PipelineMultisampleStateCreateInfo( init::PipelineMultisampleStateCreateInfo(
@@ -288,6 +310,7 @@ OGraphicsPipeline PipelineCache::createPipeline(const Gfx::MeshPipelineCreateInf
multisampleState.alphaToOneEnable = gfxInfo.multisampleState.alphaToOneEnable; multisampleState.alphaToOneEnable = gfxInfo.multisampleState.alphaToOneEnable;
multisampleState.minSampleShading = gfxInfo.multisampleState.minSampleShading; multisampleState.minSampleShading = gfxInfo.multisampleState.minSampleShading;
multisampleState.sampleShadingEnable = gfxInfo.multisampleState.sampleShadingEnable; multisampleState.sampleShadingEnable = gfxInfo.multisampleState.sampleShadingEnable;
hash = CRC::Calculate(&multisampleState, sizeof(multisampleState), CRC::CRC_32(), hash);
VkPipelineDepthStencilStateCreateInfo depthStencilState = VkPipelineDepthStencilStateCreateInfo depthStencilState =
init::PipelineDepthStencilStateCreateInfo( init::PipelineDepthStencilStateCreateInfo(
@@ -295,6 +318,7 @@ OGraphicsPipeline PipelineCache::createPipeline(const Gfx::MeshPipelineCreateInf
gfxInfo.depthStencilState.depthWriteEnable, gfxInfo.depthStencilState.depthWriteEnable,
cast(gfxInfo.depthStencilState.depthCompareOp) cast(gfxInfo.depthStencilState.depthCompareOp)
); );
hash = CRC::Calculate(&depthStencilState, sizeof(depthStencilState), CRC::CRC_32(), hash);
const auto& colorAttachments = gfxInfo.renderPass->getLayout()->colorAttachments; const auto& colorAttachments = gfxInfo.renderPass->getLayout()->colorAttachments;
Array<VkPipelineColorBlendAttachmentState> blendAttachments(colorAttachments.size()); Array<VkPipelineColorBlendAttachmentState> blendAttachments(colorAttachments.size());
@@ -312,6 +336,8 @@ OGraphicsPipeline PipelineCache::createPipeline(const Gfx::MeshPipelineCreateInf
.colorWriteMask = attachment.colorWriteMask, .colorWriteMask = attachment.colorWriteMask,
}; };
} }
hash = CRC::Calculate(blendAttachments.data(), blendAttachments.size() * sizeof(VkPipelineColorBlendAttachmentState), CRC::CRC_32(), hash);
VkPipelineColorBlendStateCreateInfo blendState = VkPipelineColorBlendStateCreateInfo blendState =
init::PipelineColorBlendStateCreateInfo( init::PipelineColorBlendStateCreateInfo(
(uint32)blendAttachments.size(), (uint32)blendAttachments.size(),
@@ -325,6 +351,7 @@ OGraphicsPipeline PipelineCache::createPipeline(const Gfx::MeshPipelineCreateInf
StaticArray<VkDynamicState, 2> dynamicEnabled; StaticArray<VkDynamicState, 2> dynamicEnabled;
dynamicEnabled[numDynamicEnabled++] = VK_DYNAMIC_STATE_VIEWPORT; dynamicEnabled[numDynamicEnabled++] = VK_DYNAMIC_STATE_VIEWPORT;
dynamicEnabled[numDynamicEnabled++] = VK_DYNAMIC_STATE_SCISSOR; dynamicEnabled[numDynamicEnabled++] = VK_DYNAMIC_STATE_SCISSOR;
hash = CRC::Calculate(dynamicEnabled.data(), dynamicEnabled.size() * sizeof(VkDynamicState), CRC::CRC_32(), hash);
VkPipelineDynamicStateCreateInfo dynamicState = VkPipelineDynamicStateCreateInfo dynamicState =
init::PipelineDynamicStateCreateInfo( init::PipelineDynamicStateCreateInfo(
@@ -333,8 +360,11 @@ OGraphicsPipeline PipelineCache::createPipeline(const Gfx::MeshPipelineCreateInf
0 0
); );
PPipelineLayout layout = gfxInfo.pipelineLayout.cast<PipelineLayout>(); if (graphicsPipelines.contains(hash))
{
std::cout << "Caching pipeline" << std::endl;
return graphicsPipelines[hash];
}
VkPipeline pipelineHandle; VkPipeline pipelineHandle;
VkGraphicsPipelineCreateInfo createInfo = { VkGraphicsPipelineCreateInfo createInfo = {
@@ -361,16 +391,20 @@ OGraphicsPipeline PipelineCache::createPipeline(const Gfx::MeshPipelineCreateInf
int64 delta = std::chrono::duration_cast<std::chrono::microseconds>(endTime - beginTime).count(); int64 delta = std::chrono::duration_cast<std::chrono::microseconds>(endTime - beginTime).count();
std::cout << "Gfx creation time: " << delta << std::endl; std::cout << "Gfx creation time: " << delta << std::endl;
OGraphicsPipeline result = new GraphicsPipeline(graphics, pipelineHandle, layout); OGraphicsPipeline pipeline = new GraphicsPipeline(graphics, pipelineHandle, std::move(gfxInfo.pipelineLayout));
PGraphicsPipeline result = pipeline;
graphicsPipelines[hash] = std::move(pipeline);
return result; return result;
} }
OComputePipeline PipelineCache::createPipeline(const Gfx::ComputePipelineCreateInfo& computeInfo) PComputePipeline PipelineCache::createPipeline(Gfx::ComputePipelineCreateInfo computeInfo)
{ {
auto layout = computeInfo.pipelineLayout.cast<PipelineLayout>(); PPipelineLayout layout = Gfx::PPipelineLayout(computeInfo.pipelineLayout).cast<PipelineLayout>();
auto computeStage = computeInfo.computeShader.cast<ComputeShader>(); auto computeStage = computeInfo.computeShader.cast<ComputeShader>();
uint32 hash = layout->getHash();
VkComputePipelineCreateInfo createInfo = { VkComputePipelineCreateInfo createInfo = {
.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
.pNext = 0, .pNext = 0,
@@ -383,6 +417,7 @@ OComputePipeline PipelineCache::createPipeline(const Gfx::ComputePipelineCreateI
.basePipelineHandle = VK_NULL_HANDLE, .basePipelineHandle = VK_NULL_HANDLE,
.basePipelineIndex = 0, .basePipelineIndex = 0,
}; };
hash = CRC::Calculate(&createInfo, sizeof(createInfo), CRC::CRC_32(), hash);
VkPipeline pipelineHandle; VkPipeline pipelineHandle;
auto beginTime = std::chrono::high_resolution_clock::now(); auto beginTime = std::chrono::high_resolution_clock::now();
@@ -390,6 +425,9 @@ OComputePipeline PipelineCache::createPipeline(const Gfx::ComputePipelineCreateI
auto endTime = std::chrono::high_resolution_clock::now(); auto endTime = std::chrono::high_resolution_clock::now();
int64 delta = std::chrono::duration_cast<std::chrono::microseconds>(endTime - beginTime).count(); int64 delta = std::chrono::duration_cast<std::chrono::microseconds>(endTime - beginTime).count();
std::cout << "Compute creation time: " << delta << std::endl; std::cout << "Compute creation time: " << delta << std::endl;
OComputePipeline result = new ComputePipeline(graphics, pipelineHandle, layout);
OComputePipeline pipeline = new ComputePipeline(graphics, pipelineHandle, std::move(computeInfo.pipelineLayout));
PComputePipeline result = pipeline;
graphicsPipelines[hash] = std::move(pipeline);
return result; return result;
} }
+5 -3
View File
@@ -10,10 +10,12 @@ class PipelineCache
public: public:
PipelineCache(PGraphics graphics, const std::string& cacheFilePath); PipelineCache(PGraphics graphics, const std::string& cacheFilePath);
~PipelineCache(); ~PipelineCache();
OGraphicsPipeline createPipeline(const Gfx::LegacyPipelineCreateInfo& createInfo); PGraphicsPipeline createPipeline(Gfx::LegacyPipelineCreateInfo createInfo);
OGraphicsPipeline createPipeline(const Gfx::MeshPipelineCreateInfo& createInfo); PGraphicsPipeline createPipeline(Gfx::MeshPipelineCreateInfo createInfo);
OComputePipeline createPipeline(const Gfx::ComputePipelineCreateInfo& createInfo); PComputePipeline createPipeline(Gfx::ComputePipelineCreateInfo createInfo);
private: private:
Map<uint32, OGraphicsPipeline> graphicsPipelines;
Map<uint32, OComputePipeline> computePipelines;
VkPipelineCache cache; VkPipelineCache cache;
PGraphics graphics; PGraphics graphics;
std::string cacheFile; std::string cacheFile;
+13 -10
View File
@@ -63,17 +63,19 @@ void Shader::create(const ShaderCreateInfo& createInfo)
Slang::ComPtr<slang::IBlob> diagnostics; Slang::ComPtr<slang::IBlob> diagnostics;
Array<slang::IComponentType*> modules; Array<slang::IComponentType*> modules;
Slang::ComPtr<slang::IEntryPoint> entrypoint; Slang::ComPtr<slang::IEntryPoint> entrypoint;
slang::IModule* mainModule = nullptr;
for (auto moduleName : createInfo.additionalModules) for (const auto& moduleName : createInfo.additionalModules)
{ {
modules.add(session->loadModule(moduleName.c_str(), diagnostics.writeRef())); modules.add(session->loadModule(moduleName.c_str(), diagnostics.writeRef()));
if (moduleName == createInfo.mainModule)
{
mainModule = (slang::IModule*)modules.back();
}
if(diagnostics) if(diagnostics)
{ {
std::cout << (const char*)diagnostics->getBufferPointer() << std::endl; std::cout << (const char*)diagnostics->getBufferPointer() << std::endl;
} }
} }
slang::IModule* mainModule = session->loadModule(createInfo.mainModule.c_str(), diagnostics.writeRef());
modules.add(mainModule);
if(diagnostics) if(diagnostics)
{ {
@@ -143,13 +145,14 @@ void Shader::create(const ShaderCreateInfo& createInfo)
} }
VkShaderModuleCreateInfo moduleInfo; VkShaderModuleCreateInfo moduleInfo;
moduleInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; moduleInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
moduleInfo.pNext = nullptr; moduleInfo.pNext = nullptr;
moduleInfo.flags = 0; moduleInfo.flags = 0;
moduleInfo.codeSize = kernelBlob->getBufferSize(); moduleInfo.codeSize = kernelBlob->getBufferSize();
moduleInfo.pCode = (uint32_t*)kernelBlob->getBufferPointer(); moduleInfo.pCode = (uint32_t*)kernelBlob->getBufferPointer();
VK_CHECK(vkCreateShaderModule(graphics->getDevice(), &moduleInfo, nullptr, &module)); VK_CHECK(vkCreateShaderModule(graphics->getDevice(), &moduleInfo, nullptr, &module));
hash = CRC::Calculate(entryPointName.data(), entryPointName.size(), CRC::CRC_32()); hash = CRC::Calculate(entryPointName.data(), entryPointName.size(), CRC::CRC_32());
hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32(), hash); hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32(), hash);
std::cout << "Creating Shader" << std::endl;
} }