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