Progress i guess

This commit is contained in:
Dynamitos
2023-11-08 23:27:21 +01:00
parent ecb5050dc7
commit 19c3e559b1
49 changed files with 268 additions and 361 deletions
+1
View File
@@ -6,6 +6,7 @@
"ctestCommandArgs": "",
"configurationType": "Debug",
"generator": "Visual Studio 17 2022 Win64",
"addressSanitizerEnabled": true,
"intelliSenseMode": "windows-msvc-x64",
"inheritEnvironments": [ "msvc_x64" ],
"cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64",
+10 -2
View File
@@ -41,6 +41,14 @@
</ArrayItems>
</Expand>
</Type>
<Type Name="Seele::Map&lt;*&gt;::Node">
<DisplayString>[{pair}]</DisplayString>
<Expand>
<Item Name="[pair]">pair</Item>
<Item Name="[left]">leftChild</Item>
<Item Name="[right]">rightChild</Item>
</Expand>
</Type>
<Type Name="Seele::Map&lt;*&gt;::IteratorBase&lt;*&gt;">
<DisplayString Condition="nodeContainer.arraySize==0">empty</DisplayString>
<DisplayString>[{nodeContainer._data[node].pair}]</DisplayString>
@@ -50,9 +58,9 @@
</Type>
<Type Name="Seele::RefPtr&lt;*&gt;">
<DisplayString Condition="object == nullptr">empty</DisplayString>
<DisplayString>RefPtr {*object->handle} {object->refCount} references</DisplayString>
<DisplayString>RefPtr {*object}</DisplayString>
<Expand>
<ExpandedItem>object->handle</ExpandedItem>
<ExpandedItem>object</ExpandedItem>
</Expand>
</Type>
<Type Name="Seele::UniquePtr&lt;*&gt;">
+8 -8
View File
@@ -11,21 +11,21 @@ struct LightCullingData
RWTexture2D<uint2> oLightGrid;
RWTexture2D<uint2> tLightGrid;
};
ParameterBuffer<LightCullingData> gLightCullingData;
ParameterBlock<LightCullingData> pLightCullingData;
[shader("pixel")]
void pixelMain(in VertexAttributes attribs, out float4 baseColor)
{
MaterialParameter params = MaterialParameter.create(attribs);
BRDF brdf = gMaterial.prepare(params);
MaterialParameter params = attribs.create();
BRDF brdf = pMaterial.prepare(params);
float3 result = float3(0, 0, 0);
for(int i = 0; i < gLightEnv.numDirectionalLights; ++i)
for(int i = 0; i < pLightEnv.numDirectionalLights; ++i)
{
result += gLightEnv.directionalLights[i].illuminate(params, brdf);
result += pLightEnv.directionalLights[i].illuminate(params, brdf);
}
for(int i = 0; i < gLightEnv.numPointLights; ++i)
for(int i = 0; i < pLightEnv.numPointLights; ++i)
{
result += gLightEnv.pointLights[i].illuminate(params, brdf);
result += pLightEnv.pointLights[i].illuminate(params, brdf);
}
return float4(result, 1.0f);
return float4(1, 1, 0, 1.0f);
}
+5 -30
View File
@@ -14,43 +14,18 @@ struct DispatchParams
uint pad0;
uint3 numThreads;
uint pad1;
RWShaderBuffer<Frustum> frustums;
RWStructuredBuffer<Frustum> frustums;
}
ParameterBuffer<DispatchParams> dispatchParams;
ParameterBlock<DispatchParams> pDispatchParams;
[numthreads(BLOCK_SIZE, BLOCK_SIZE, 1)]
[shader("compute")]
void computeFrustums(ComputeShaderInput in)
{
const float3 eyePos = float3(0,0,0);
float4 screenSpace[4];
screenSpace[0] = float4(in.dispatchThreadID.xy * BLOCK_SIZE, -1.0f, 1.0f);
screenSpace[1] = float4(float2(in.dispatchThreadID.x + 1, in.dispatchThreadID.y) * BLOCK_SIZE, -1.0f, 1.0f);
screenSpace[2] = float4(float2(in.dispatchThreadID.x, in.dispatchThreadID.y + 1) * BLOCK_SIZE, -1.0f, 1.0f);
screenSpace[3] = float4(float2(in.dispatchThreadID.x + 1, in.dispatchThreadID.y + 1) * BLOCK_SIZE, -1.0f, 1.0f);
//Convert to viewSpace
float3 viewSpace[4];
for(int i = 0; i < 4; i++)
if(in.dispatchThreadID.x < pDispatchParams.numThreads.x && in.dispatchThreadID.y < pDispatchParams.numThreads.y)
{
viewSpace[i] = screenToClip(screenSpace[i]).xyz;
}
//Compute frustum
Frustum frustum;
frustum.planes[0] = computePlane(eyePos, viewSpace[2], viewSpace[0]);
frustum.planes[1] = computePlane(eyePos, viewSpace[1], viewSpace[3]);
frustum.planes[2] = computePlane(eyePos, viewSpace[0], viewSpace[1]);
frustum.planes[3] = computePlane(eyePos, viewSpace[3], viewSpace[2]);
if(in.dispatchThreadID.x < dispatchParams.numThreads.x && in.dispatchThreadID.y < dispatchParams.numThreads.y)
{
uint index = in.dispatchThreadID.x + (in.dispatchThreadID.y * numThreads.x);
dispatchParams.frustums[index] = frustum;
uint index = in.dispatchThreadID.x + (in.dispatchThreadID.y * pDispatchParams.numThreads.x);
//pDispatchParams.frustums[index] = frustum;
}
}
-24
View File
@@ -1,24 +0,0 @@
import Common;
import Material;
import PrimitiveSceneData;
import StaticMeshVertexInput;
struct VertexStageOutput
{
float4 position : SV_Position;
}
[shader("vertex")]
VertexStageOutput vertexMain(PositionOnlyVertexShaderInput input)
{
VertexStageOutput output;
float3 worldPosition = input.getWorldPosition();
//worldPosition += gMaterial.getWorldOffset();
float4 clipSpacePosition;
float4 viewSpacePosition = mul(gViewParams.viewMatrix, float4(worldPosition, 1));
clipSpacePosition = mul(gViewParams.projectionMatrix, viewSpacePosition);
output.position = clipSpacePosition;
return output;
}
+4 -5
View File
@@ -1,5 +1,4 @@
import VertexData;
import StaticMeshVertexData;
struct InstanceData
{
@@ -11,14 +10,14 @@ struct Scene
StructuredBuffer<InstanceData> instances;
}
ParameterBlock<Scene> scene;
ParameterBlock<Scene> pScene;
[shader("vertex")]
StaticMeshVertexAttributes vertexMain(
IVertexAttributes vertexMain(
uint vertexId: SV_VertexID,
uint instanceId: SV_InstanceID,
){
InstanceData inst = scene.instances[instanceId];
StaticMeshVertexAttributes attr = vertexData.getAttributes(vertexId, inst.transformMatrix);
InstanceData inst = pScene.instances[instanceId];
IVertexAttributes attr = pVertexData.getAttributes(vertexId, inst.transformMatrix);
return attr;
}
+11 -11
View File
@@ -28,7 +28,7 @@ struct CullingParams
StructuredBuffer<Frustum> frustums;
};
ParameterBlock<CullingParams> gCullingParams;
ParameterBlock<CullingParams> pCullingParams;
// Debug
//Texture2D lightCountHeatMap;
//RWTexture2D<float4> debugTexture;
@@ -72,7 +72,7 @@ void tAppendLight(uint lightIndex)
void cullLights(ComputeShaderInput in)
{
int2 texCoord = int2(in.dispatchThreadID.xy);
float fDepth = gCullingParams.depthTextureVS.Load(int3(texCoord, 0)).r;
float fDepth = pCullingParams.depthTextureVS.Load(int3(texCoord, 0)).r;
uint uDepth = asuint(fDepth);
if(in.groupIndex == 0)
@@ -81,7 +81,7 @@ void cullLights(ComputeShaderInput in)
uMaxDepth = 0x0;
oLightCount = 0;
tLightCount = 0;
groupFrustum = gCullingParams.frustums[in.groupID.x + (in.groupID.y * gCullingParams.numThreadGroups.x)];
groupFrustum = pCullingParams.frustums[in.groupID.x + (in.groupID.y * pCullingParams.numThreadGroups.x)];
}
GroupMemoryBarrierWithGroupSync();
@@ -100,9 +100,9 @@ void cullLights(ComputeShaderInput in)
Plane minPlane = {float3(0, 0, -1), -minDepthVS};
for ( uint i = in.groupIndex; i < gLightEnv.numPointLights; i += BLOCK_SIZE * BLOCK_SIZE )
for ( uint i = in.groupIndex; i < pLightEnv.numPointLights; i += BLOCK_SIZE * BLOCK_SIZE )
{
PointLight light = gLightEnv.pointLights[i];
PointLight light = pLightEnv.pointLights[i];
//TODO: why doesn't this check go through?
//if(light.insideFrustum(groupFrustum, nearClipVS, maxDepthVS))
{
@@ -118,23 +118,23 @@ void cullLights(ComputeShaderInput in)
if(in.groupIndex == 0)
{
InterlockedAdd(gCullingParams.oLightIndexCounter[0], oLightCount, oLightIndexStartOffset);
gCullingParams.oLightGrid[in.groupID.xy] = uint2(oLightIndexStartOffset, oLightCount);
InterlockedAdd(pCullingParams.oLightIndexCounter[0], oLightCount, oLightIndexStartOffset);
pCullingParams.oLightGrid[in.groupID.xy] = uint2(oLightIndexStartOffset, oLightCount);
InterlockedAdd(gCullingParams.tLightIndexCounter[0], tLightCount, tLightIndexStartOffset);
gCullingParams.tLightGrid[in.groupID.xy] = uint2(tLightIndexStartOffset, tLightCount);
InterlockedAdd(pCullingParams.tLightIndexCounter[0], tLightCount, tLightIndexStartOffset);
pCullingParams.tLightGrid[in.groupID.xy] = uint2(tLightIndexStartOffset, tLightCount);
}
GroupMemoryBarrierWithGroupSync();
for (uint j = in.groupIndex; j < oLightCount; j += BLOCK_SIZE * BLOCK_SIZE)
{
gCullingParams.oLightIndexList[oLightIndexStartOffset + j] = oLightList[j];
pCullingParams.oLightIndexList[oLightIndexStartOffset + j] = oLightList[j];
}
// For transparent geometry.
for ( uint k = in.groupIndex; k < tLightCount; k += BLOCK_SIZE * BLOCK_SIZE )
{
gCullingParams.tLightIndexList[tLightIndexStartOffset + k] = tLightList[k];
pCullingParams.tLightIndexList[tLightIndexStartOffset + k] = tLightList[k];
}
+17 -17
View File
@@ -22,11 +22,11 @@ void taskMain(
uint threadID: SV_GroupIndex,
uint groupID: SV_GroupID
){
InstanceData instance = scene.instances[groupID];
InstanceData instance = pScene.instances[groupID];
if(threadID == 0)
{
head = 0;
localToClip = mul(viewParams.projectionMatrix, mul(viewParams.viewMatrix, instance.transformMatrix));
localToClip = mul(pViewParams.projectionMatrix, mul(pViewParams.viewMatrix, instance.transformMatrix));
// Left
viewFrustum.sides[0].n = float3(1, 0, 0);
viewFrustum.sides[0].d = -1;
@@ -44,11 +44,11 @@ void taskMain(
viewFrustum.basePlane.d = 0;
}
GroupMemoryBarrierWithGroupSync();
MeshData mesh = scene.meshData[groupID];
MeshData mesh = pScene.meshData[groupID];
for(uint i = threadID; i < MAX_MESHLETS_PER_MESH; i += TASK_GROUP_SIZE)
{
uint m = mesh.meshletOffset + min(mesh.numMeshlets, i);
MeshletDescription meshlet = scene.meshlets.meshletInfos[m];
MeshletDescription meshlet = pScene.meshlets.meshletInfos[m];
//if(meshlet.boundingBox.insideFrustum(localToClip, viewFrustum))
{
uint index;
@@ -61,7 +61,7 @@ void taskMain(
DispatchMesh(head, 1, 1, p);
}
groupshared VertexAttributes gs_vertices[MAX_VERTICES];
groupshared IVertexAttributes gs_vertices[MAX_VERTICES];
groupshared uint3 gs_indices[MAX_PRIMITIVES];
groupshared uint gs_numVertices;
groupshared uint gs_numPrimitives;
@@ -78,12 +78,12 @@ void meshMain(
in uint threadID: SV_GroupIndex,
in uint groupID: SV_GroupID,
in payload MeshPayload meshPayload,
out Vertices<VertexAttributes, MAX_VERTICES> vertices,
out Vertices<IVertexAttributes, MAX_VERTICES> vertices,
out Indices<uint3, MAX_PRIMITIVES> indices
){
InstanceData inst = scene.instances[meshPayload.instanceId[groupID]];
MeshData md = scene.meshData[meshPayload.instanceId[groupID]];
MeshletDescription m = meshlets.meshletInfos[meshPayload.meshletId[groupID]];
InstanceData inst = pScene.instances[meshPayload.instanceId[groupID]];
MeshData md = pScene.meshData[meshPayload.instanceId[groupID]];
MeshletDescription m = pScene.meshletInfos[meshPayload.meshletId[groupID]];
const uint vertexLoops = (MAX_VERTICES + MESH_GROUP_SIZE - 1) / MESH_GROUP_SIZE;
for(uint loop = 0; loop < vertexLoops; ++loop)
{
@@ -91,8 +91,8 @@ void meshMain(
v = min(v, m.vertexCount - 1);
InterlockedMax(gs_numVertices, v + 1);
{
int vertexIndex = meshlets.vertexIndices[m.vertexOffset + v];
gs_vertices[v] = vertexData.getAttributes(md.indexOffset + vertexIndex, inst);
int vertexIndex = pScene.vertexIndices[m.vertexOffset + v];
gs_vertices[v] = pVertexData.getAttributes(md.indexOffset + vertexIndex, inst);
}
}
@@ -103,12 +103,12 @@ void meshMain(
p = min(p, m.primitiveCount - 1);
InterlockedMax(gs_numPrimitives, p + 1);
{
uint8_t local_idx0 = meshlets.primitiveIndices[m.primitiveOffset + (p * 3) + 0];
uint8_t local_idx1 = meshlets.primitiveIndices[m.primitiveOffset + (p * 3) + 1];
uint8_t local_idx2 = meshlets.primitiveIndices[m.primitiveOffset + (p * 3) + 2];
uint32_t idx0 = meshlets.vertexIndices[m.vertexOffset + local_idx0];
uint32_t idx1 = meshlets.vertexIndices[m.vertexOffset + local_idx1];
uint32_t idx2 = meshlets.vertexIndices[m.vertexOffset + local_idx2];
uint8_t local_idx0 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 0];
uint8_t local_idx1 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 1];
uint8_t local_idx2 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 2];
uint32_t idx0 = pScene.vertexIndices[m.vertexOffset + local_idx0];
uint32_t idx1 = pScene.vertexIndices[m.vertexOffset + local_idx1];
uint32_t idx2 = pScene.vertexIndices[m.vertexOffset + local_idx2];
gs_indices[p * 3 + 0] = idx0;
gs_indices[p * 3 + 1] = idx1;
gs_indices[p * 3 + 2] = idx2;
+8 -8
View File
@@ -15,17 +15,17 @@ struct SkyboxData
float4x4 transformMatrix;
float4 fogBlend;
};
ParameterBuffer<SkyboxData> gSkyboxData;
ParameterBlock<SkyboxData> pSkyboxData;
[shader("vertex")]
VertexShaderOutput vertexMain(
VertexShaderInput input)
{
VertexShaderOutput output;
float3x3 cameraRotation = float3x3(gViewParams.viewMatrix);
float3x3 cameraRotation = float3x3(pViewParams.viewMatrix);
float4 worldPos = float4(mul(cameraRotation, input.position), 1.0f);
//clip(dot(worldPos, clipPlane));
output.clipPos = mul(gViewParams.projectionMatrix, worldPos);
output.clipPos = mul(pViewParams.projectionMatrix, worldPos);
output.texCoords = normalize(input.position);
return output;
}
@@ -36,7 +36,7 @@ struct TextureData
TextureCube cubeMap2;
SamplerState sampler;
};
ParameterBuffer<TextureData> textures;
ParameterBlock<TextureData> pTextures;
static const float lowerLimit = 0.0;
static const float upperLimit = 0.1;
@@ -44,11 +44,11 @@ static const float upperLimit = 0.1;
float4 fragmentMain(
VertexShaderOutput output) : SV_Target
{
float4 texture1 = textures.cubeMap.Sample(textures.sampler, output.texCoords);
float4 texture2 = textures.cubeMap2.Sample(textures.sampler, output.texCoords);
float4 finalColor = lerp(texture1, texture2, gSkyboxData.fogBlend.w);
float4 texture1 = pTextures.cubeMap.Sample(pTextures.sampler, output.texCoords);
float4 texture2 = pTextures.cubeMap2.Sample(pTextures.sampler, output.texCoords);
float4 finalColor = lerp(texture1, texture2, pSkyboxData.fogBlend.w);
float factor = (output.texCoords.y - lowerLimit) / (upperLimit - lowerLimit);
factor = clamp(factor, 0.0, 1.0);
return lerp(float4(gSkyboxData.fogBlend.xyz, 1), finalColor, factor);
return lerp(float4(pSkyboxData.fogBlend.xyz, 1), finalColor, factor);
}
+6 -6
View File
@@ -9,14 +9,14 @@ struct TextData
float4 textColor;
float scale;
}
ParameterBuffer<SamplerState> glyphSampler;
ParameterBlock<SamplerState> glyphSampler;
//layout(set = 1)
//ShaderBuffer<GlyphData> glyphData;
ParameterBuffer<Texture2D<uint>[]> glyphTextures;
ParameterBuffer<Texture2D<uint>[]> pGlyphTextures;
[[vk::push_constant]]
ConstantBuffer<TextData> textData;
struct VertexStageInput
struct VertexInput
{
float2 position;
float2 widthHeight;
@@ -24,7 +24,7 @@ struct VertexStageInput
uint vertexId : SV_VertexID;
};
struct VertexStageOutput
struct VertexOutput
{
float4 position : SV_Position;
float2 texCoords : TEXCOORD;
@@ -32,7 +32,7 @@ struct VertexStageOutput
};
[shader("vertex")]
VertexStageOutput vertexMain(VertexStageInput input)
VertexOutput vertexMain(VertexInput input)
{
float xpos = input.position.x;
float ypos = input.position.y;
@@ -61,5 +61,5 @@ float4 fragmentMain(
uint glyphIndex : GLYPHINDEX
) : SV_Target
{
return textData.textColor * glyphTextures[glyphIndex].Sample(glyphSampler, texCoords);
return textData.textColor * pGlyphTextures[glyphIndex].Sample(glyphSampler, texCoords);
}
+6 -6
View File
@@ -24,9 +24,9 @@ struct UIParameter
Texture2D<float4> backgroundTextures[];
}
ParameterBuffer<UIParameter> params;
ParameterBlock<UIParameter> pParams;
struct VertexStageOutput
struct VertexOutput
{
float4 position : SV_Position;
float2 texCoords : TEXCOORD;
@@ -34,7 +34,7 @@ struct VertexStageOutput
};
[shader("vertex")]
VertexStageOutput vertexMain(uint vertexId : SV_VertexID, RenderElementStyle style)
VertexOutput vertexMain(uint vertexId : SV_VertexID, RenderElementStyle style)
{
float xMin = style.position.x;
float xMax = xMin + style.dimensions.x;
@@ -46,8 +46,8 @@ VertexStageOutput vertexMain(uint vertexId : SV_VertexID, RenderElementStyle sty
float4(xMax, yMin, 1, 0),
float4(xMax, yMax, 1, 1)
};
VertexStageOutput output;
output.position = mul(viewData.projectionMatrix, float4(coordinates[vertexId].xy, style.position.z, 1));
VertexOutput output;
output.position = mul(pViewData.projectionMatrix, float4(coordinates[vertexId].xy, style.position.z, 1));
output.texCoords = coordinates[vertexId].zw;
output.style = style;
return output;
@@ -64,7 +64,7 @@ float4 fragmentMain(
uint imageIndex = style.backgroundImageIndex;
if(imageIndex < numBackgroundTextures)
{
bgTextureColor = backgroundTextures[imageIndex].Sample(backgroundSampler, texCoords);
bgTextureColor = pParams.backgroundTextures[imageIndex].Sample(pParams.backgroundSampler, texCoords);
}
return float4(style.backgroundColor, style.opacity) * bgTextureColor;
}
+2 -3
View File
@@ -9,15 +9,14 @@ struct ViewParameter
float4 cameraPos_WS;
float2 screenDimensions;
}
layout(set = INDEX_VIEW_PARAMS)
ParameterBlock<ViewParameter> viewParams;
ParameterBlock<ViewParameter> pViewParams;
// Convert screen space coordinates to view space.
float4 screenToClip( float4 screen )
{
// Convert to normalized texture coordinates
float2 texCoord = screen.xy / viewParams.screenDimensions;
float2 texCoord = screen.xy / pViewParams.screenDimensions;
// Convert to clip space
return float4( float2( texCoord.x, 1.0f-texCoord.y ) * 2.0f - 1.0f, screen.z, screen.w );
+5 -5
View File
@@ -1,6 +1,6 @@
import MaterialParameter;
import BRDF;
import Common;
import BRDF;
import MaterialParameter;
interface ILightEnv
{
@@ -15,7 +15,7 @@ struct DirectionalLight : ILightEnv
float3 illuminate<B:IBRDF>(MaterialParameter input, B brdf)
{
float3 lightDir_TS = normalize(direction.xyz);
return brdf.evaluate(input.viewDir_TS, -lightDir_TS, color.xyz);
return brdf.evaluate(input.viewDir_TS, -lightDir_TS, color.xyz);
}
};
@@ -57,7 +57,7 @@ struct PointLight : ILightEnv
}
float3 getViewPos()
{
return mul(viewParams.viewMatrix, position_WS).xyz;
return mul(pViewParams.viewMatrix, position_WS).xyz;
}
};
@@ -69,4 +69,4 @@ struct LightEnv
uint numPointLights;
};
ParameterBlock<LightEnv> gLightEnv;
ParameterBlock<LightEnv> pLightEnv;
+1 -1
View File
@@ -8,4 +8,4 @@ interface IMaterial
BRDF prepare(MaterialParameter input);
};
ParameterBlock<IMaterial> gMaterial;
ParameterBlock<IMaterial> pMaterial;
+1 -14
View File
@@ -1,24 +1,11 @@
import VertexData;
struct MaterialParameter
{
float3 position_TS;
float3 position_TS;
float3 worldPosition;
float2 texCoords;
float3 normal;
float3 tangent;
float3 biTangent;
float3 viewDir_TS;
static MaterialParameter create(VertexAttributes attrib)
{
MaterialParameter result;
result.worldPosition = attrib.getWorldPosition().xyz;
result.texCoords = attrib.getTexCoords();
result.normal = attrib.getNormal();
result.tangent = attrib.getTangent();
result.biTangent = attrib.getBiTangent();
return result;
}
}
+1 -1
View File
@@ -37,5 +37,5 @@ struct Scene
StructuredBuffer<uint32_t> vertexIndices;
};
ParameterBlock<Scene> scene;
ParameterBlock<Scene> pScene;
+19 -26
View File
@@ -1,8 +1,8 @@
import VertexData;
import Common;
import Scene;
import VertexData;
import MaterialParameter;
struct StaticMeshVertexAttributes : VertexAttributes
struct StaticMeshVertexAttributes : IVertexAttributes
{
float4 clipPosition: SV_Position;
float3 worldPosition: POSITION0;
@@ -10,37 +10,30 @@ struct StaticMeshVertexAttributes : VertexAttributes
float3 normal: NORMAL0;
float3 tangent: TANGENT0;
float3 biTangent: BITANGENT0;
float3 getWorldPosition()
MaterialParameter create()
{
return worldPosition;
MaterialParameter result;
result.worldPosition = worldPosition;
result.texCoords = texCoords;
result.normal = normal;
result.tangent = tangent;
result.biTangent = biTangent;
return result;
}
float2 getTexCoords()
{
return texCoords;
}
float3 getNormal()
{
return normal;
}
float3 getTangent()
{
return tangent;
}
float3 getBiTangent()
{
return biTangent;
}
}
struct StaticMeshVertexData : VertexData
};
struct StaticMeshVertexData : IVertexData
{
typedef StaticMeshVertexAttributes VertexAttributes;
StaticMeshVertexAttributes getAttributes(uint index, float4x4 transform)
{
StaticMeshVertexAttributes attr;
float4 localPos = float4(positions[index], 1);
float4 worldPos = mul(transform, localPos);
float4 viewPos = mul(viewParams.viewMatrix, worldPos);
float4 clipPos = mul(viewParams.projectionMatrix, viewPos);
float4 viewPos = mul(pViewParams.viewMatrix, worldPos);
float4 clipPos = mul(pViewParams.projectionMatrix, viewPos);
attr.clipPosition = clipPos;
attr.worldPosition = worldPos.xyz;
attr.texCoords = texCoords[index];
@@ -54,4 +47,4 @@ struct StaticMeshVertexData : VertexData
StructuredBuffer<float3> normals;
StructuredBuffer<float3> tangents;
StructuredBuffer<float3> biTangents;
}
};
+7 -10
View File
@@ -1,16 +1,13 @@
import Scene;
import MaterialParameter;
interface VertexAttributes
interface IVertexAttributes
{
float3 getWorldPosition();
float2 getTexCoords();
float3 getNormal();
float3 getTangent();
float3 getBiTangent();
}
MaterialParameter create();
};
interface VertexData
interface IVertexData
{
associatedtype VertexAttributes : IVertexAttributes;
VertexAttributes getAttributes(uint index, float4x4 transform);
};
ParameterBlock<VertexData> vertexData;
ParameterBlock<IVertexData> pVertexData;
+2 -2
View File
@@ -47,9 +47,9 @@ void AssetImporter::importMaterial(MaterialImportArgs args)
get().materialLoader->importAsset(args);
}
void AssetImporter::init(Gfx::PGraphics graphics, AssetRegistry* registry)
void AssetImporter::init(Gfx::PGraphics graphics)
{
get().registry = registry;
get().registry = AssetRegistry::getInstance();
get().meshLoader = new MeshLoader(graphics);
get().textureLoader = new TextureLoader(graphics);
get().materialLoader = new MaterialLoader(graphics);
+1 -1
View File
@@ -15,7 +15,7 @@ public:
static void importTexture(struct TextureImportArgs args);
static void importFont(struct FontImportArgs args);
static void importMaterial(struct MaterialImportArgs args);
static void init(Gfx::PGraphics graphics, AssetRegistry* registry);
static void init(Gfx::PGraphics graphics);
private:
static AssetImporter& get();
UPTextureLoader textureLoader;
-1
View File
@@ -47,7 +47,6 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
Gfx::ODescriptorLayout layout = graphics->createDescriptorLayout(materialName + "Layout");
//Shader file needs to conform to the slang standard, which prohibits _
materialName.erase(std::remove(materialName.begin(), materialName.end(), '_'), materialName.end());
materialName.erase(std::remove(materialName.begin(), materialName.end(), '.'), materialName.end());
uint32 uniformBufferOffset = 0;
uint32 bindingCounter = 0; // Uniform buffers are always binding 0
+4 -2
View File
@@ -48,7 +48,9 @@ void MeshLoader::loadMaterials(const aiScene* scene, const std::string& baseName
{
aiMaterial* material = scene->mMaterials[i];
json matCode;
matCode["name"] = baseName + material->GetName().C_Str();
std::string materialName = std::format("{0}{1}", baseName, material->GetName().C_Str());
materialName.erase(std::remove(materialName.begin(), materialName.end(), '.'), materialName.end()); // dots break adding the .asset extension later
matCode["name"] = materialName;
matCode["profile"] = "BlinnPhong"; //TODO: other shading models
aiString texPath;
//TODO make samplers based on used textures
@@ -58,7 +60,7 @@ void MeshLoader::loadMaterials(const aiScene* scene, const std::string& baseName
};
if(material->GetTexture(aiTextureType_DIFFUSE, 0, &texPath) == AI_SUCCESS)
{
std::string texFilename = std::filesystem::path(texPath.C_Str()).replace_extension("asset").stem().string();
std::string texFilename = std::filesystem::path(texPath.C_Str()).stem().string();
matCode["params"]["diffuseTexture"] =
{
{"type", "Texture2D"},
+1 -3
View File
@@ -17,8 +17,6 @@
using namespace Seele;
using namespace Seele::Editor;
extern AssetRegistry* instance;
int main()
{
#ifdef WIN32
@@ -41,7 +39,7 @@ int main()
vd->init(graphics);
PWindowManager windowManager = new WindowManager();
AssetRegistry::init(sourcePath / "Assets", graphics);
AssetImporter::init(graphics, AssetRegistry::getInstance());
AssetImporter::init(graphics);
AssetImporter::importFont(FontImportArgs{
.filePath = "./fonts/Calibri.ttf",
});
+1 -1
View File
@@ -7,7 +7,7 @@ CameraActor::CameraActor(PScene scene)
: Actor(scene)
{
attachComponent<Component::Camera>();
attachComponent<Component::Transform>().setRelativeLocation(Vector(10, 5, 14));
accessComponent<Component::Transform>().setRelativeLocation(Vector(10, 5, 14));
}
CameraActor::~CameraActor()
@@ -19,6 +19,7 @@ DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, PScene scene)
depthPrepassLayout = graphics->createPipelineLayout();
depthPrepassLayout->addDescriptorLayout(INDEX_VIEW_PARAMS, viewParamsLayout);
graphics->getShaderCompiler()->registerRenderPass("DepthPass", "LegacyBasePass");
}
DepthPrepass::~DepthPrepass()
@@ -43,18 +44,18 @@ void DepthPrepass::render()
{
permutation.useMeshShading = true;
permutation.hasTaskShader = true;
std::memcpy(permutation.taskFile, "MeshletBasePass", sizeof("MeshletBasePass"));
std::memcpy(permutation.vertexMeshFile, "MeshletBasePass", sizeof("MeshletBasePass"));
std::strncpy(permutation.taskFile, "MeshletBasePass", sizeof("MeshletBasePass"));
std::strncpy(permutation.vertexMeshFile, "MeshletBasePass", sizeof("MeshletBasePass"));
}
else
{
permutation.useMeshShading = false;
std::memcpy(permutation.vertexMeshFile, "LegacyBasePass", sizeof("LegacyBasePass"));
std::strncpy(permutation.vertexMeshFile, "LegacyBasePass", sizeof("LegacyBasePass"));
}
graphics->beginRenderPass(renderPass);
for (VertexData* vertexData : VertexData::getList())
{
std::memcpy(permutation.vertexDataName, vertexData->getTypeName().c_str(), std::strlen(vertexData->getTypeName().c_str()));
std::strncpy(permutation.vertexDataName, vertexData->getTypeName().c_str(), sizeof(permutation.vertexDataName));
const auto& materials = vertexData->getMaterialData();
for (const auto& [_, materialData] : materials)
{
@@ -64,7 +65,7 @@ void DepthPrepass::render()
// Material => per material
// VertexData => per meshtype
// SceneData => per material instance
std::memcpy(permutation.materialName, materialData.material->getName().c_str(), std::strlen(materialData.material->getName().c_str()));
std::strncpy(permutation.materialName, materialData.material->getName().c_str(), sizeof(permutation.materialName));
Gfx::PermutationId id(permutation);
Gfx::PRenderCommand command = graphics->createRenderCommand("DepthRender");
@@ -18,8 +18,8 @@ public:
virtual void createRenderPass() override;
static void modifyRenderPassMacros(Map<const char*, const char*>& defines);
private:
Gfx::PRenderTargetAttachment depthAttachment;
Gfx::PTexture2D depthBuffer;
Gfx::ORenderTargetAttachment depthAttachment;
Gfx::OTexture2D depthBuffer;
Array<Gfx::PDescriptorSet> descriptorSets;
@@ -200,7 +200,7 @@ void LightCullingPass::setupFrustums()
dispatchParams.numThreads = numThreads;
dispatchParams.numThreadGroups = numThreadGroups;
Gfx::ODescriptorLayout frustumDescriptorLayout = graphics->createDescriptorLayout("FrustumLayout");
frustumDescriptorLayout = graphics->createDescriptorLayout("FrustumLayout");
frustumDescriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
frustumDescriptorLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
frustumLayout = graphics->createPipelineLayout();
@@ -45,6 +45,7 @@ private:
Gfx::OShaderBuffer frustumBuffer;
Gfx::OUniformBuffer dispatchParamsBuffer;
Gfx::OUniformBuffer viewParamsBuffer;
Gfx::ODescriptorLayout frustumDescriptorLayout;
Gfx::PDescriptorSet frustumDescriptorSet;
Gfx::OComputeShader frustumShader;
Gfx::OPipelineLayout frustumLayout;
+1 -1
View File
@@ -38,7 +38,7 @@ protected:
PRenderGraphResources resources;
static constexpr uint32 INDEX_VIEW_PARAMS = 0;
Gfx::ODescriptorLayout viewParamsLayout;
Gfx::OShaderBuffer viewParamsBuffer;
Gfx::OUniformBuffer viewParamsBuffer;
Gfx::PDescriptorSet viewParamsSet;
Gfx::ORenderPass renderPass;
Gfx::PGraphics graphics;
@@ -169,14 +169,13 @@ void SkyboxRenderPass::createRenderPass()
createInfo.name = "SkyboxVertex";
createInfo.mainModule = "Skybox";
createInfo.entryPoint = "vertexMain";
createInfo.defines["INDEX_VIEW_PARAMS"] = "0";
Gfx::PVertexShader vertexShader = graphics->createVertexShader(createInfo);
vertexShader = graphics->createVertexShader(createInfo);
createInfo.name = "SkyboxFragment";
createInfo.entryPoint = "fragmentMain";
Gfx::PFragmentShader fragmentShader = graphics->createFragmentShader(createInfo);
fragmentShader = graphics->createFragmentShader(createInfo);
Gfx::PVertexDeclaration vertexDecl = graphics->createVertexDeclaration({
declaration = graphics->createVertexDeclaration({
Gfx::VertexElement {
.binding = 0,
.offset = 0,
@@ -187,7 +186,7 @@ void SkyboxRenderPass::createRenderPass()
});
Gfx::LegacyPipelineCreateInfo gfxInfo;
gfxInfo.vertexDeclaration = vertexDecl;
gfxInfo.vertexDeclaration = declaration;
gfxInfo.vertexShader = vertexShader;
gfxInfo.fragmentShader = fragmentShader;
gfxInfo.rasterizationState.polygonMode = Gfx::SE_POLYGON_MODE_FILL;
@@ -26,6 +26,9 @@ private:
Gfx::ODescriptorLayout descriptorLayout;
Gfx::PDescriptorSet descriptorSet;
Gfx::OPipelineLayout pipelineLayout;
Gfx::OVertexDeclaration declaration;
Gfx::OVertexShader vertexShader;
Gfx::OFragmentShader fragmentShader;
Gfx::OGraphicsPipeline pipeline;
Gfx::OSamplerState skyboxSampler;
Component::Skybox skybox;
+2 -2
View File
@@ -155,8 +155,8 @@ void UIPass::createRenderPass()
},
.dynamic = false,
};
Gfx::PUniformBuffer uniformBuffer = graphics->createUniformBuffer(info);
Gfx::PSamplerState backgroundSampler = graphics->createSamplerState({});
Gfx::OUniformBuffer uniformBuffer = graphics->createUniformBuffer(info);
Gfx::OSamplerState backgroundSampler = graphics->createSamplerState({});
info = {
.sourceData = {
+20 -8
View File
@@ -53,27 +53,26 @@ void ShaderCompiler::compile()
ShaderPermutation permutation;
for (const auto& [name, pass] : passes)
{
std::memset(&permutation, 0, sizeof(ShaderPermutation));
permutation.hasFragment = pass.hasFragmentShader;
permutation.useMeshShading = pass.useMeshShading;
permutation.hasTaskShader = pass.hasTaskShader;
std::memcpy(permutation.vertexMeshFile, pass.mainFile.c_str(), sizeof(permutation.vertexMeshFile));
std::strncpy(permutation.vertexMeshFile, pass.mainFile.c_str(), sizeof(permutation.vertexMeshFile));
if (pass.hasFragmentShader)
{
std::memcpy(permutation.fragmentFile, pass.fragmentFile.c_str(), sizeof(permutation.fragmentFile));
std::strncpy(permutation.fragmentFile, pass.fragmentFile.c_str(), sizeof(permutation.fragmentFile));
}
if (pass.hasTaskShader)
{
std::memcpy(permutation.taskFile, pass.taskFile.c_str(), sizeof(permutation.taskFile));
std::strncpy(permutation.taskFile, pass.taskFile.c_str(), sizeof(permutation.taskFile));
}
for (const auto& [vdName, vd] : vertexData)
{
std::memcpy(permutation.vertexDataName, vd->getTypeName().c_str(), sizeof(permutation.vertexDataName));
std::strncpy(permutation.vertexDataName, vd->getTypeName().c_str(), sizeof(permutation.vertexDataName));
if (pass.useMaterial)
{
for (const auto& [matName, mat] : materials)
{
std::memcpy(permutation.materialName, matName.c_str(), sizeof(permutation.materialName));
std::strncpy(permutation.materialName, matName.c_str(), sizeof(permutation.materialName));
createShaders(permutation);
}
}
@@ -92,10 +91,23 @@ ShaderCollection& ShaderCompiler::createShaders(ShaderPermutation permutation)
ShaderCollection collection;
ShaderCreateInfo createInfo;
createInfo.typeParameter = { permutation.materialName, permutation.vertexDataName };
createInfo.typeParameter = { permutation.vertexDataName };
createInfo.name = std::format("Material {0}", permutation.materialName);
createInfo.additionalModules.add(permutation.materialName);
if (std::strlen(permutation.materialName) > 0)
{
createInfo.additionalModules.add(permutation.materialName);
createInfo.typeParameter.add(permutation.materialName);
}
createInfo.additionalModules.add(permutation.vertexDataName);
createInfo.additionalModules.add(permutation.vertexMeshFile);
if (permutation.hasFragment)
{
createInfo.additionalModules.add(permutation.fragmentFile);
}
if (permutation.hasTaskShader)
{
createInfo.additionalModules.add(permutation.taskFile);
}
if (permutation.useMeshShading)
{
+4
View File
@@ -62,6 +62,10 @@ struct ShaderPermutation
uint8 useMeshShading : 1;
uint8 hasTaskShader : 1;
//TODO: lightmapping etc
ShaderPermutation()
{
std::memset(this, 0, sizeof(ShaderPermutation));
}
};
//Hashed ShaderPermutation for fast lookup
struct PermutationId
+6 -5
View File
@@ -16,6 +16,7 @@ void VertexData::resetMeshData()
if (dirty)
{
updateBuffers();
dirty = false;
}
}
@@ -23,6 +24,7 @@ void VertexData::updateMesh(const Component::Transform& transform, PMesh mesh)
{
PMaterial mat = mesh->referencedMaterial->getHandle()->getBaseMaterial();
MaterialData& matData = materialData[mat->getName()];
matData.material = mat;
MaterialInstanceData& matInstanceData = matData.instances[mesh->referencedMaterial->getHandle()->getId()];
matInstanceData.meshes.add(MeshInstanceData{
.id = mesh->id,
@@ -89,7 +91,6 @@ void VertexData::loadMesh(MeshId id, Array<Meshlet> loadedMeshlets)
.stride = sizeof(uint8),
.dynamic = true,
});
}
void VertexData::createDescriptors()
@@ -108,7 +109,7 @@ void VertexData::createDescriptors()
meshes.add(mesh);
}
}
Gfx::PShaderBuffer instanceBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
matInst.instanceBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData = {
.size = sizeof(InstanceData) * instanceData.size(),
.data = (uint8*)instanceData.data(),
@@ -117,17 +118,17 @@ void VertexData::createDescriptors()
});
instanceDataLayout->reset();
matInst.descriptorSet = instanceDataLayout->allocateDescriptorSet();
matInst.descriptorSet->updateBuffer(0, instanceBuffer);
matInst.descriptorSet->updateBuffer(0, matInst.instanceBuffer);
if (graphics->supportMeshShading())
{
Gfx::PShaderBuffer meshDataBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
matInst.meshDataBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData = {
.size = sizeof(MeshData) * meshes.size(),
.data = (uint8*)meshes.data(),
},
.stride = sizeof(MeshData)
});
matInst.descriptorSet->updateBuffer(1, meshDataBuffer);
matInst.descriptorSet->updateBuffer(1, matInst.meshDataBuffer);
matInst.descriptorSet->updateBuffer(2, meshletBuffer);
matInst.descriptorSet->updateBuffer(3, primitiveIndicesBuffer);
matInst.descriptorSet->updateBuffer(4, vertexIndicesBuffer);
+2
View File
@@ -43,6 +43,8 @@ public:
struct MaterialInstanceData
{
PMaterialInstance materialInstance;
Gfx::OShaderBuffer instanceBuffer;
Gfx::OShaderBuffer meshDataBuffer;
Gfx::PDescriptorSet descriptorSet;
uint32 numMeshes; // not necessarily equal to meshes.size() if a MeshId has multiple meshes
Array<MeshInstanceData> meshes;
+40 -92
View File
@@ -4,12 +4,12 @@
using namespace Seele::Vulkan;
SubAllocation::SubAllocation(PAllocation owner, VkDeviceSize allocatedOffset, VkDeviceSize size, VkDeviceSize alignedOffset, VkDeviceSize allocatedSize)
SubAllocation::SubAllocation(PAllocation owner, VkDeviceSize requestedSize, VkDeviceSize allocatedOffset, VkDeviceSize allocatedSize, VkDeviceSize alignedOffset)
: owner(owner)
, size(size)
, requestedSize(requestedSize)
, allocatedOffset(allocatedOffset)
, alignedOffset(alignedOffset)
, allocatedSize(allocatedSize)
, alignedOffset(alignedOffset)
{
}
@@ -61,7 +61,7 @@ Allocation::Allocation(PGraphics graphics, PAllocator allocator, VkDeviceSize si
allocInfo.pNext = dedicatedInfo;
VK_CHECK(vkAllocateMemory(device, &allocInfo, nullptr, &allocatedMemory));
bytesAllocated = size;
freeRanges[0] = new SubAllocation(this, 0, size, 0, size);
freeRanges[0] = size;
canMap = (properties & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
isMapped = false;
@@ -69,16 +69,16 @@ Allocation::Allocation(PGraphics graphics, PAllocator allocator, VkDeviceSize si
Allocation::~Allocation()
{
assert(bytesUsed == 0);
}
OSubAllocation Allocation::getSuballocation(VkDeviceSize requestedSize, VkDeviceSize alignment)
{
std::scoped_lock lck(lock);
if (isDedicated)
{
if (activeAllocations.empty() && requestedSize == bytesAllocated)
{
OSubAllocation suballoc = std::move(freeRanges[0]);
OSubAllocation suballoc = new SubAllocation(this, requestedSize, 0, requestedSize, 0);
activeAllocations.add(suballoc);
freeRanges.clear();
bytesUsed += requestedSize;
@@ -89,32 +89,30 @@ OSubAllocation Allocation::getSuballocation(VkDeviceSize requestedSize, VkDevice
return nullptr;
}
}
for (auto& [allocatedOffset, freeAllocation] : freeRanges)
for (const auto& [lower, size] : freeRanges)
{
assert(allocatedOffset == freeAllocation->allocatedOffset);
VkDeviceSize alignedOffset = allocatedOffset + alignment - 1;
VkDeviceSize alignedOffset = lower + alignment - 1;
alignedOffset /= alignment;
alignedOffset *= alignment;
VkDeviceSize allocatedSize = requestedSize + (alignedOffset - allocatedOffset);
if (freeAllocation->size == allocatedSize)
VkDeviceSize allocatedSize = requestedSize + (alignedOffset - lower);
if (size == allocatedSize)
{
activeAllocations.add(freeAllocation);
freeRanges.erase(allocatedOffset);
OSubAllocation alloc = new SubAllocation(this, requestedSize, lower, allocatedSize, alignedOffset);
activeAllocations.add(alloc);
freeRanges.erase(lower);
bytesUsed += allocatedSize;
return std::move(freeAllocation);
return std::move(alloc);
}
else if (allocatedSize < freeAllocation->allocatedSize)
else if (allocatedSize < size)
{
freeAllocation->size -= allocatedSize;
freeAllocation->allocatedSize -= allocatedSize;
freeAllocation->allocatedOffset += allocatedSize;
freeAllocation->alignedOffset += allocatedSize;
OSubAllocation subAlloc = new SubAllocation(this, allocatedOffset, allocatedSize, alignedOffset, allocatedSize);
VkDeviceSize newSize = size - allocatedSize;
VkDeviceSize newLower = lower + allocatedSize;
OSubAllocation subAlloc = new SubAllocation(this, requestedSize, lower, allocatedSize, alignedOffset);
activeAllocations.add(subAlloc);
freeRanges[freeAllocation->allocatedOffset] = std::move(freeAllocation);
freeRanges.erase(allocatedOffset);
freeRanges.erase(lower);
freeRanges[newLower] = newSize;
bytesUsed += allocatedSize;
return subAlloc;
return std::move(subAlloc);
}
}
return nullptr;
@@ -122,70 +120,28 @@ OSubAllocation Allocation::getSuballocation(VkDeviceSize requestedSize, VkDevice
void Allocation::markFree(PSubAllocation allocation)
{
// Dont free if it is already a free allocation, since they also mark themselves on deletion
if (freeRanges.find(allocation->allocatedOffset) != freeRanges.end())
{
return;
}
assert(activeAllocations.find(allocation) != activeAllocations.end());
VkDeviceSize lowerBound = allocation->allocatedOffset;
VkDeviceSize upperBound = allocation->allocatedOffset + allocation->allocatedSize;
PSubAllocation allocHandle;
PSubAllocation freeRangeToDelete;
freeRanges[lowerBound] = allocation->allocatedSize;
for (const auto& [lower, size] : freeRanges)
{
std::scoped_lock lck(lock);
//Join lower bound
for (auto& [allocatedOffset, freeAlloc] : freeRanges)
if (lower + size == lowerBound)
{
if (freeAlloc->allocatedOffset <= lowerBound
&& freeAlloc->allocatedOffset + freeAlloc->allocatedSize >= upperBound)
{
// allocation is already in a free region
assert(false);
}
if (freeAlloc->allocatedOffset + freeAlloc->allocatedSize == lowerBound)
{
//extend freeAlloc by the allocatedSize
freeAlloc->allocatedSize += allocation->allocatedSize;
allocHandle = freeAlloc;
break;
}
freeRanges[lower] = upperBound;
freeRanges.erase(lowerBound);
lowerBound = lower;
break;
}
//Join upper bound
auto foundAlloc = freeRanges.find(upperBound);
if (foundAlloc != freeRanges.end())
{
// There is a free allocation ending where the new free one ends
freeRangeToDelete = foundAlloc->value;
if (allocHandle != nullptr)
{
// extend allocHandle by another foundAlloc->allocatedSize bytes
allocHandle->allocatedSize += foundAlloc->value->allocatedSize;
freeRanges.erase(foundAlloc->key);
}
else
{
// set foundAlloc back by size amount
allocHandle = foundAlloc->value;
allocHandle->allocatedOffset -= allocation->allocatedSize;
allocHandle->alignedOffset -= allocation->allocatedSize;
allocHandle->size += allocation->allocatedSize;
allocHandle->allocatedSize += allocation->allocatedSize;
// place back at correct offset, move original owning pointer
freeRanges[allocHandle->allocatedOffset] = std::move(foundAlloc->value);
// remove from offset map since key changes
freeRanges.erase(foundAlloc->key);
}
}
if (allocHandle == nullptr)
{
freeRanges[allocation->allocatedOffset] = new SubAllocation(this, allocation->allocatedOffset, allocation->size, allocation->alignedOffset, allocation->allocatedSize);
}
activeAllocations.remove_if([&](const PSubAllocation& a) {return a.getHandle() == allocation.getHandle(); });
}
if (freeRanges.find(upperBound) != freeRanges.end())
{
freeRanges[lowerBound] += freeRanges[upperBound];
freeRanges.erase(upperBound);
}
activeAllocations.remove(allocation, false);
bytesUsed -= allocation->allocatedSize;
if(bytesUsed == 0)
if (bytesUsed == 0)
{
allocator->free(this);
}
@@ -231,7 +187,6 @@ Allocator::Allocator(PGraphics graphics)
Allocator::~Allocator()
{
std::scoped_lock lck(lock);
for (auto& heap : heaps)
{
for (auto& alloc : heap.allocations)
@@ -246,7 +201,6 @@ Allocator::~Allocator()
OSubAllocation Allocator::allocate(const VkMemoryRequirements2 &memRequirements2, VkMemoryPropertyFlags properties, VkMemoryDedicatedAllocateInfo *dedicatedInfo)
{
std::scoped_lock lck(lock);
const VkMemoryRequirements &requirements = memRequirements2.memoryRequirements;
uint32 memoryTypeIndex = findMemoryType(requirements.memoryTypeBits, properties);
uint32 heapIndex = memProperties.memoryTypes[memoryTypeIndex].heapIndex;
@@ -270,7 +224,7 @@ OSubAllocation Allocator::allocate(const VkMemoryRequirements2 &memRequirements2
OSubAllocation suballoc = alloc->getSuballocation(requirements.size, requirements.alignment);
if (suballoc != nullptr)
{
return suballoc;
return std::move(suballoc);
}
}
}
@@ -284,7 +238,6 @@ OSubAllocation Allocator::allocate(const VkMemoryRequirements2 &memRequirements2
void Allocator::free(PAllocation allocation)
{
std::scoped_lock lck(lock);
for (uint32 heapIndex = 0; heapIndex < heaps.size(); ++heapIndex)
{
for (uint32 alloc = 0; alloc < heaps[heapIndex].allocations.size(); ++alloc)
@@ -293,7 +246,7 @@ void Allocator::free(PAllocation allocation)
{
heaps[heapIndex].inUse -= allocation->bytesAllocated;
std::cout << "Heap " << heapIndex << " -" <<allocation->bytesAllocated << ": " << (float)heaps[heapIndex].inUse / heaps[heapIndex].maxSize << "%" << std::endl;
heaps[heapIndex].allocations.removeAt(heapIndex, false);
heaps[heapIndex].allocations.removeAt(alloc, false);
return;
}
}
@@ -371,7 +324,6 @@ void StagingManager::clearPending()
OStagingBuffer StagingManager::allocateStagingBuffer(uint64 size, VkBufferUsageFlags usage, bool readable)
{
std::scoped_lock l(lock);
for (auto it = freeBuffers.begin(); it != freeBuffers.end(); ++it)
{
auto& freeBuffer = *it;
@@ -381,7 +333,7 @@ OStagingBuffer StagingManager::allocateStagingBuffer(uint64 size, VkBufferUsageF
activeBuffers.add(freeBuffer);
OStagingBuffer owner = std::move(freeBuffer);
freeBuffers.remove(it, false);
return owner;
return std::move(owner);
}
}
//std::cout << "Creating new stagingbuffer" << std::endl;
@@ -421,11 +373,9 @@ OStagingBuffer StagingManager::allocateStagingBuffer(uint64 size, VkBufferUsageF
);
vkBindBufferMemory(graphics->getDevice(), buffer, stagingBuffer->getMemoryHandle(), stagingBuffer->getOffset());
std::cout << "Creating new stagingbuffer size " << stagingBuffer->getSize() << std::endl;
activeBuffers.add(stagingBuffer);
return stagingBuffer;
return std::move(stagingBuffer);
}
void StagingManager::releaseStagingBuffer(OStagingBuffer buffer)
@@ -434,8 +384,6 @@ void StagingManager::releaseStagingBuffer(OStagingBuffer buffer)
{
return;
}
std::scoped_lock l(lock);
activeBuffers.remove(buffer);
std::cout << "Releasing stagingbuffer size " << buffer->getSize() << std::endl;
freeBuffers.add(std::move(buffer));
}
+4 -7
View File
@@ -15,13 +15,13 @@ DECLARE_REF(Allocation)
class SubAllocation
{
public:
SubAllocation(PAllocation owner, VkDeviceSize allocatedOffset, VkDeviceSize size, VkDeviceSize alignedOffset, VkDeviceSize allocatedSize);
SubAllocation(PAllocation owner, VkDeviceSize requestedSize, VkDeviceSize allocatedOffset, VkDeviceSize allocatedSize, VkDeviceSize alignedOffset);
~SubAllocation();
VkDeviceMemory getHandle() const;
constexpr VkDeviceSize getSize() const
{
return size;
return requestedSize;
}
constexpr VkDeviceSize getOffset() const
@@ -37,7 +37,7 @@ public:
private:
PAllocation owner;
VkDeviceSize size;
VkDeviceSize requestedSize;
VkDeviceSize allocatedOffset;
VkDeviceSize alignedOffset;
VkDeviceSize allocatedSize;
@@ -87,8 +87,7 @@ private:
VkDeviceSize bytesUsed;
VkDeviceMemory allocatedMemory;
Array<PSubAllocation> activeAllocations;
Map<VkDeviceSize, OSubAllocation> freeRanges;
std::mutex lock;
Map<VkDeviceSize, VkDeviceSize> freeRanges;
void *mappedPointer;
uint8 isDedicated : 1;
uint8 canMap : 1;
@@ -147,7 +146,6 @@ private:
};
Array<HeapInfo> heaps;
uint32 findMemoryType(uint32 typeBits, VkMemoryPropertyFlags properties);
std::mutex lock;
PGraphics graphics;
VkPhysicalDeviceMemoryProperties memProperties;
};
@@ -200,7 +198,6 @@ private:
PAllocator allocator;
Array<OStagingBuffer> freeBuffers;
Array<PStagingBuffer> activeBuffers;
std::mutex lock;
};
DEFINE_REF(StagingManager)
} // namespace Vulkan
+7 -7
View File
@@ -76,31 +76,31 @@ public:
virtual void updateTextureArray(uint32_t binding, Array<Gfx::PTexture> texture);
virtual bool operator<(Gfx::PDescriptorSet other);
inline bool isCurrentlyBound() const
constexpr bool isCurrentlyBound() const
{
return currentlyBound;
}
inline bool isCurrentlyInUse() const
constexpr bool isCurrentlyInUse() const
{
return currentlyInUse;
}
void bind()
constexpr void bind()
{
currentlyBound = true;
}
void unbind()
constexpr void unbind()
{
currentlyBound = false;
}
void allocate()
constexpr void allocate()
{
currentlyInUse = true;
}
void free()
constexpr void free()
{
currentlyInUse = false;
}
inline VkDescriptorSet getHandle() const
constexpr VkDescriptorSet getHandle() const
{
return setHandle;
}
+1 -1
View File
@@ -104,7 +104,7 @@ protected:
std::mutex viewportLock;
Array<PViewport> viewports;
std::mutex allocatedFrameBufferLock;
Map<uint32, PFramebuffer> allocatedFramebuffers;
Map<uint32, OFramebuffer> allocatedFramebuffers;
OAllocator allocator;
OStagingManager stagingManager;
+4 -4
View File
@@ -8,8 +8,8 @@
using namespace Seele;
using namespace Seele::Vulkan;
RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout layout, Gfx::PViewport viewport)
: Gfx::RenderPass(std::move(layout))
RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout _layout, Gfx::PViewport viewport)
: Gfx::RenderPass(std::move(_layout))
, graphics(graphics)
{
renderArea.extent.width = viewport->getSizeX();
@@ -22,7 +22,7 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout layout, Gfx:
Array<VkAttachmentReference> colorRefs;
VkAttachmentReference depthRef;
uint32 attachmentCounter = 0;
for (auto& inputAttachment : this->layout->inputAttachments)
for (auto& inputAttachment : layout->inputAttachments)
{
PTexture2D image = inputAttachment->getTexture().cast<Texture2D>();
VkAttachmentDescription& desc = attachments.add();
@@ -40,7 +40,7 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout layout, Gfx:
ref.attachment = attachmentCounter;
attachmentCounter++;
}
for (auto& colorAttachment : this->layout->colorAttachments)
for (auto& colorAttachment : layout->colorAttachments)
{
VkAttachmentDescription& desc = attachments.add();
desc.flags = 0;
+10 -10
View File
@@ -223,16 +223,16 @@ void Window::present()
backBufferImages[currentImageIndex]->changeLayout(Gfx::SE_IMAGE_LAYOUT_PRESENT_SRC_KHR);
graphics->getGraphicsCommands()->submitCommands(renderFinished[currentImageIndex]);
VkSemaphore renderFinishedHandle = renderFinished[currentImageIndex]->getHandle();
VkPresentInfoKHR info;
info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
info.pNext = nullptr;
info.swapchainCount = 1;
info.pSwapchains = &swapchain;
info.pImageIndices = (uint32 *)&currentImageIndex;
info.pResults = 0;
info.waitSemaphoreCount = 1;
info.pWaitSemaphores = &renderFinishedHandle;
VkPresentInfoKHR info = {
.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
.pNext = nullptr,
.waitSemaphoreCount = 1,
.pWaitSemaphores = &renderFinishedHandle,
.swapchainCount = 1,
.pSwapchains = &swapchain,
.pImageIndices = (uint32*)&currentImageIndex,
.pResults = 0,
};
VkResult presentResult = VK_ERROR_OUT_OF_DATE_KHR;
// Trial and error
while (presentResult != VK_SUCCESS)
+7 -6
View File
@@ -39,11 +39,11 @@ void Shader::create(const ShaderCreateInfo& createInfo)
sessionDesc.flags = 0;
sessionDesc.defaultMatrixLayoutMode = SLANG_MATRIX_LAYOUT_COLUMN_MAJOR;
Array<slang::PreprocessorMacroDesc> macros;
for(auto define : createInfo.defines)
for(const auto& [key, val] : createInfo.defines)
{
macros.add(slang::PreprocessorMacroDesc{
.name = define.key,
.value = define.value
.name = key,
.value = val,
});
}
sessionDesc.preprocessorMacroCount = macros.size();
@@ -91,10 +91,11 @@ void Shader::create(const ShaderCreateInfo& createInfo)
std::cout << (const char*)diagnostics->getBufferPointer() << std::endl;
}
/*for(auto typeParam : createInfo.typeParameter)
/*slang::ProgramLayout* layout = moduleComposition->getLayout();
for(auto typeParam : createInfo.typeParameter)
{
Slang::ComPtr<slang::ITypeConformance> typeConformance;
session->createTypeConformanceComponentType(moduleComposition->getLayout()->findTypeByName(typeParam), moduleComposition->getLayout()->findTypeByName("IMaterial"), typeConformance.writeRef(), -1, diagnostics.writeRef());
session->createTypeConformanceComponentType(layout->findTypeByName(typeParam), layout->findTypeByName("IMaterial"), typeConformance.writeRef(), -1, diagnostics.writeRef());
modules.add(typeConformance);
if(diagnostics)
{
@@ -104,7 +105,7 @@ void Shader::create(const ShaderCreateInfo& createInfo)
Slang::ComPtr<slang::IComponentType> conformingModule;
session->createCompositeComponentType(modules.data(), modules.size(), conformingModule.writeRef(), diagnostics.writeRef());
*/
*/
Slang::ComPtr<slang::IComponentType> linkedProgram;
moduleComposition->link(linkedProgram.writeRef(), diagnostics.writeRef());
if(diagnostics)
+3 -2
View File
@@ -21,7 +21,7 @@ LightEnvironment::LightEnvironment(Gfx::PGraphics graphics)
directionalLights = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData = {
.size = sizeof(Component::DirectionalLight) * MAX_DIRECTIONAL_LIGHTS,
.data = (uint8*)dirs.data(),
.data = nullptr,
},
.stride = sizeof(Component::DirectionalLight),
.dynamic = true,
@@ -29,7 +29,7 @@ LightEnvironment::LightEnvironment(Gfx::PGraphics graphics)
pointLights = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData = {
.size = sizeof(Component::PointLight) * MAX_POINT_LIGHTS,
.data = (uint8*)dirs.data(),
.data = nullptr,
},
.stride = sizeof(Component::PointLight),
.dynamic = true,
@@ -77,6 +77,7 @@ void LightEnvironment::commit()
set->updateBuffer(0, lightEnvBuffer);
set->updateBuffer(1, directionalLights);
set->updateBuffer(2, pointLights);
set->writeChanges();
}
const Gfx::PDescriptorLayout Seele::LightEnvironment::getDescriptorLayout() const
+9 -5
View File
@@ -4,6 +4,8 @@
#include "Component/KeyboardInput.h"
#include "Actor/CameraActor.h"
#include "Asset/AssetRegistry.h"
#include "System/LightGather.h"
#include "System/MeshUpdater.h"
using namespace Seele;
@@ -12,12 +14,13 @@ GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreate
, scene(new Scene(graphics))
, gameInterface(dllPath)
, renderGraph(RenderGraphBuilder::build(
DepthPrepass(graphics, scene),
LightCullingPass(graphics, scene),
BasePass(graphics, scene),
SkyboxRenderPass(graphics, scene)
DepthPrepass(graphics, scene)
//LightCullingPass(graphics, scene),
//BasePass(graphics, scene),
//SkyboxRenderPass(graphics, scene)
))
{
camera = new CameraActor(scene);
reloadGame();
renderGraph.updateViewport(viewport);
}
@@ -67,11 +70,12 @@ void GameView::render()
void GameView::reloadGame()
{
scene = new Scene(graphics);
gameInterface.reload(AssetRegistry::getInstance());
systemGraph = new SystemGraph();
gameInterface.getGame()->setupScene(scene, systemGraph);
systemGraph->addSystem(new System::LightGather(scene));
systemGraph->addSystem(new System::MeshUpdater(scene));
}
void GameView::keyCallback(KeyCode code, InputAction action, KeyModifier)
+5 -5
View File
@@ -28,13 +28,13 @@ public:
void reloadGame();
private:
OScene scene;
PEntity camera;
OEntity camera;
GameInterface gameInterface;
RenderGraph<
DepthPrepass,
LightCullingPass,
BasePass,
SkyboxRenderPass
DepthPrepass
//LightCullingPass,
//BasePass,
//SkyboxRenderPass
> renderGraph;
PSystemGraph systemGraph;
+2 -2
View File
@@ -4,9 +4,9 @@
using namespace Seele;
Window::Window(PWindowManager owner, Gfx::PWindow handle)
Window::Window(PWindowManager owner, Gfx::OWindow handle)
: owner(owner)
, gfxHandle(handle)
, gfxHandle(std::move(handle))
{
}
+2 -2
View File
@@ -9,7 +9,7 @@ DECLARE_REF(WindowManager)
class Window
{
public:
Window(PWindowManager owner, Gfx::PWindow handle);
Window(PWindowManager owner, Gfx::OWindow handle);
~Window();
void addView(PView view);
void render();
@@ -19,7 +19,7 @@ public:
protected:
PWindowManager owner;
Array<PView> views;
Gfx::PWindow gfxHandle;
Gfx::OWindow gfxHandle;
//void viewWorker(size_t viewIndex);
};
+1 -2
View File
@@ -13,8 +13,7 @@ WindowManager::~WindowManager()
PWindow WindowManager::addWindow(Gfx::PGraphics graphics, const WindowCreateInfo &createInfo)
{
Gfx::OWindow handle = graphics->createWindow(createInfo);
OWindow window = new Window(this, handle);
OWindow window = new Window(this, graphics->createWindow(createInfo));
PWindow ref = window;
windows.add(std::move(window));
return ref;