Descriptors now work in metal hopefully

This commit is contained in:
Dynamitos
2024-09-16 13:00:53 +02:00
parent 49e94d3b74
commit 6417ab940d
45 changed files with 435 additions and 476 deletions
+1 -1
View File
@@ -23,6 +23,6 @@
"lldb.showDisassembly": "auto", "lldb.showDisassembly": "auto",
"lldb.dereferencePointers": true, "lldb.dereferencePointers": true,
"lldb.consoleMode": "commands", "lldb.consoleMode": "commands",
"cmake.generator": "Ninja", "cmake.generator": "Xcode",
"editor.tabSize": 4 "editor.tabSize": 4
} }
+1 -1
+2 -2
View File
@@ -25,9 +25,9 @@ void computeFrustums(ComputeShaderInput in)
frustum.sides[1] = computePlane(origin, corners[1], corners[3]); frustum.sides[1] = computePlane(origin, corners[1], corners[3]);
frustum.sides[2] = computePlane(origin, corners[0], corners[1]); frustum.sides[2] = computePlane(origin, corners[0], corners[1]);
frustum.sides[3] = computePlane(origin, corners[3], corners[2]); frustum.sides[3] = computePlane(origin, corners[3], corners[2]);
if(in.dispatchThreadID.x < pDispatchParams.numThreads.x && in.dispatchThreadID.y < pDispatchParams.numThreads.y) if(in.dispatchThreadID.x < pDispatchParams.p.numThreads.x && in.dispatchThreadID.y < pDispatchParams.p.numThreads.y)
{ {
uint index = in.dispatchThreadID.x + (in.dispatchThreadID.y * pDispatchParams.numThreads.x); uint index = in.dispatchThreadID.x + (in.dispatchThreadID.y * pDispatchParams.p.numThreads.x);
pDispatchParams.frustums[index] = frustum; pDispatchParams.frustums[index] = frustum;
} }
} }
+1 -1
View File
@@ -17,7 +17,7 @@ Params vertexMain(
DebugVertex vert DebugVertex vert
){ ){
Params result; Params result;
result.pos = mul(pViewParams.projectionMatrix, mul(pViewParams.viewMatrix, float4(vert.position, 1))); result.pos = mul(pViewParams.c.projectionMatrix, mul(pViewParams.c.viewMatrix, float4(vert.position, 1)));
result.color = vert.color; result.color = vert.color;
return result; return result;
} }
+5 -5
View File
@@ -30,7 +30,7 @@ groupshared bool meshVisible;
ParameterBlock<DepthData> pDepthAttachment; ParameterBlock<DepthData> pDepthAttachment;
bool isBoxVisible(AABB bounding) bool isBoxVisible(AABB bounding)
{ {
int2 mipDimensions = int2(int(pViewParams.screenDimensions.x), int(pViewParams.screenDimensions.y)); int2 mipDimensions = int2(int(pViewParams.c.screenDimensions.x), int(pViewParams.c.screenDimensions.y));
// now we calculate what mip level we need to only sample up to 4 texels covering the entire meshlet // now we calculate what mip level we need to only sample up to 4 texels covering the entire meshlet
int2 screenCornerMin = mipDimensions; int2 screenCornerMin = mipDimensions;
int2 screenCornerMax = int2(0, 0); int2 screenCornerMax = int2(0, 0);
@@ -91,14 +91,14 @@ void taskMain(
p.instanceId = pOffsets.instanceOffset + groupID; p.instanceId = pOffsets.instanceOffset + groupID;
p.meshletOffset = mesh.meshletOffset; p.meshletOffset = mesh.meshletOffset;
p.cullingOffset = pScene.cullingOffsets[p.instanceId]; p.cullingOffset = pScene.cullingOffsets[p.instanceId];
modelViewProjection = mul(mul(pViewParams.projectionMatrix, pViewParams.viewMatrix), instance.transformMatrix); modelViewProjection = mul(mul(pViewParams.c.projectionMatrix, pViewParams.c.viewMatrix), instance.transformMatrix);
float3 origin = viewToModel(instance.inverseTransformMatrix, float4(0, 0, 0, 1)).xyz; float3 origin = viewToModel(instance.inverseTransformMatrix, float4(0, 0, 0, 1)).xyz;
const float offset = 0.0f; const float offset = 0.0f;
float3 corners[4] = { float3 corners[4] = {
screenToModel(instance.inverseTransformMatrix, float4(offset, offset, -1.0f, 1.0f)).xyz, screenToModel(instance.inverseTransformMatrix, float4(offset, offset, -1.0f, 1.0f)).xyz,
screenToModel(instance.inverseTransformMatrix, float4(pViewParams.screenDimensions.x - offset, offset, -1.0f, 1.0f)).xyz, screenToModel(instance.inverseTransformMatrix, float4(pViewParams.c.screenDimensions.x - offset, offset, -1.0f, 1.0f)).xyz,
screenToModel(instance.inverseTransformMatrix, float4(offset, pViewParams.screenDimensions.y - offset, -1.0f, 1.0f)).xyz, screenToModel(instance.inverseTransformMatrix, float4(offset, pViewParams.c.screenDimensions.y - offset, -1.0f, 1.0f)).xyz,
screenToModel(instance.inverseTransformMatrix, float4(pViewParams.screenDimensions - float2(offset, offset), -1.0f, 1.0f)).xyz screenToModel(instance.inverseTransformMatrix, float4(pViewParams.c.screenDimensions - float2(offset, offset), -1.0f, 1.0f)).xyz
}; };
viewFrustum.sides[0] = computePlane(origin, corners[2], corners[0]); viewFrustum.sides[0] = computePlane(origin, corners[2], corners[0]);
viewFrustum.sides[1] = computePlane(origin, corners[1], corners[3]); viewFrustum.sides[1] = computePlane(origin, corners[1], corners[3]);
+2 -2
View File
@@ -47,9 +47,9 @@ void reduceLevel(
void sourceCopy( void sourceCopy(
uint2 dispatchID: SV_DispatchThreadID uint2 dispatchID: SV_DispatchThreadID
) { ) {
if(dispatchID.x >= pViewParams.screenDimensions.x || dispatchID.y >= pViewParams.screenDimensions.y) if(dispatchID.x >= pViewParams.c.screenDimensions.x || dispatchID.y >= pViewParams.c.screenDimensions.y)
{ {
return; return;
} }
pDepthAttachment.buffer[dispatchID.x + (dispatchID.y * uint(pViewParams.screenDimensions.x))] = pDepthAttachment.texture[uint2(dispatchID)]; pDepthAttachment.buffer[dispatchID.x + (dispatchID.y * uint(pViewParams.c.screenDimensions.x))] = pDepthAttachment.texture[uint2(dispatchID)];
} }
+1 -1
View File
@@ -72,7 +72,7 @@ void cullLights(ComputeShaderInput in)
uMaxDepth = 0x0; uMaxDepth = 0x0;
oLightCount = 0; oLightCount = 0;
tLightCount = 0; tLightCount = 0;
groupFrustum = pDispatchParams.frustums[in.groupID.x + (in.groupID.y * pDispatchParams.numThreadGroups.x)]; groupFrustum = pDispatchParams.frustums[in.groupID.x + (in.groupID.y * pDispatchParams.p.numThreadGroups.x)];
} }
GroupMemoryBarrierWithGroupSync(); GroupMemoryBarrierWithGroupSync();
+2 -2
View File
@@ -73,10 +73,10 @@ VertexShaderOutput vertexMain(
}; };
VertexShaderOutput output; VertexShaderOutput output;
float3x3 cameraRotation = float3x3(pViewParams.viewMatrix); float3x3 cameraRotation = float3x3(pViewParams.c.viewMatrix);
float4 worldPos = float4(mul(cameraRotation, vertices[vertexIndex]), 1.0f); float4 worldPos = float4(mul(cameraRotation, vertices[vertexIndex]), 1.0f);
//clip(dot(worldPos, clipPlane)); //clip(dot(worldPos, clipPlane));
output.clipPos = mul(pViewParams.projectionMatrix, worldPos); output.clipPos = mul(pViewParams.c.projectionMatrix, worldPos);
output.texCoords = normalize(vertices[vertexIndex]); output.texCoords = normalize(vertices[vertexIndex]);
return output; return output;
} }
+1 -1
View File
@@ -66,7 +66,7 @@ VertexOutput vertexMain(VertexInput input)
float4 vertex = coordinates[input.vertexId]; float4 vertex = coordinates[input.vertexId];
VertexOutput output; VertexOutput output;
output.texCoords = vertex.zw; output.texCoords = vertex.zw;
output.position = mul(pViewParams.projectionMatrix, float4(vertex.xy, 0, 1)); output.position = mul(pViewParams.c.projectionMatrix, float4(vertex.xy, 0, 1));
output.glyphIndex = pRender.instances[input.instanceId].glyphIndex; output.glyphIndex = pRender.instances[input.instanceId].glyphIndex;
return output; return output;
} }
+2 -2
View File
@@ -34,7 +34,7 @@ void meshMain(
out vertices WaterVertex vertices[TILE_VERTS], out vertices WaterVertex vertices[TILE_VERTS],
out indices uint3 indices[TILE_PRIMS], out indices uint3 indices[TILE_PRIMS],
) { ) {
float4x4 vp = mul(pViewParams.projectionMatrix, pViewParams.viewMatrix); float4x4 vp = mul(pViewParams.c.projectionMatrix, pViewParams.c.viewMatrix);
SetMeshOutputCounts(TILE_VERTS, TILE_PRIMS); SetMeshOutputCounts(TILE_VERTS, TILE_PRIMS);
for(uint i = threadID; i < TILE_PRIMS; i += MESH_GROUP_SIZE) for(uint i = threadID; i < TILE_PRIMS; i += MESH_GROUP_SIZE)
@@ -48,7 +48,7 @@ void meshMain(
float3 worldPos = params.offset + objectPos * params.extent + float3(groupID.x * params.extent, 0, groupID.y * params.extent); float3 worldPos = params.offset + objectPos * params.extent + float3(groupID.x * params.extent, 0, groupID.y * params.extent);
float lodDisplacement = 0; float lodDisplacement = 0;
float3 camPos = pViewParams.cameraPos_WS.xyz; float3 camPos = pViewParams.c.cameraPos_WS.xyz;
float cameraDistance = distance(worldPos, camPos); float cameraDistance = distance(worldPos, camPos);
float threshold = 0; float threshold = 0;
if(params.numMeshes == 3) if(params.numMeshes == 3)
+1 -1
View File
@@ -23,7 +23,7 @@ float Beckmann(float ndoth, float roughness) {
[shader("pixel")] [shader("pixel")]
float4 fragmentMain(WaterVertex vert) : SV_TARGET { float4 fragmentMain(WaterVertex vert) : SV_TARGET {
float3 lightDir = -normalize(pWaterMaterial.sunDirection); float3 lightDir = -normalize(pWaterMaterial.sunDirection);
float3 viewDir = normalize(pViewParams.cameraPos_WS.xyz - vert.position_WS); float3 viewDir = normalize(pViewParams.c.cameraPos_WS.xyz - vert.position_WS);
float3 halfwayDir = normalize(lightDir + viewDir); float3 halfwayDir = normalize(lightDir + viewDir);
float depth = vert.depth; float depth = vert.depth;
float LdotH = clamp(dot(lightDir, halfwayDir), 0, 1); float LdotH = clamp(dot(lightDir, halfwayDir), 0, 1);
+1 -1
View File
@@ -15,7 +15,7 @@ void taskMain(
bounding.minCorner = float3(tile.location.x, tile.height, tile.location.y) * tile.extent; bounding.minCorner = float3(tile.location.x, tile.height, tile.location.y) * tile.extent;
bounding.maxCorner = float3(tile.location.x + 1, tile.height, tile.location.y + 1) * tile.extent; bounding.maxCorner = float3(tile.location.x + 1, tile.height, tile.location.y + 1) * tile.extent;
float3 median = (bounding.minCorner + bounding.maxCorner) / 2; float3 median = (bounding.minCorner + bounding.maxCorner) / 2;
float distance = distance(median, pViewParams.cameraPos_WS.xyz); float distance = distance(median, pViewParams.c.cameraPos_WS.xyz);
float tileDistance = distance / tile.extent; float tileDistance = distance / tile.extent;
uint numMeshes = groupID.y + 1; uint numMeshes = groupID.y + 1;
+1 -1
View File
@@ -67,7 +67,7 @@ struct AABB
{ {
float4 clipCorner = mul(mvp, corners[i]); float4 clipCorner = mul(mvp, corners[i]);
float4 screenCorner = clipToScreen(clipCorner); float4 screenCorner = clipToScreen(clipCorner);
int2 screenCoords = int2(clamp(int(screenCorner.x), 0, int(pViewParams.screenDimensions.x)), clamp(int(screenCorner.y), 0, int(pViewParams.screenDimensions.y))); int2 screenCoords = int2(clamp(int(screenCorner.x), 0, int(pViewParams.c.screenDimensions.x)), clamp(int(screenCorner.y), 0, int(pViewParams.c.screenDimensions.y)));
screenCornerMin = int2(min(screenCornerMin.x, screenCoords.x), min(screenCornerMin.y, screenCoords.y)); screenCornerMin = int2(min(screenCornerMin.x, screenCoords.x), min(screenCornerMin.y, screenCoords.y));
screenCornerMax = int2(max(screenCornerMax.x, screenCoords.x), max(screenCornerMax.y, screenCoords.y)); screenCornerMax = int2(max(screenCornerMax.x, screenCoords.x), max(screenCornerMax.y, screenCoords.y));
maxDepth = max(maxDepth, screenCorner.z); maxDepth = max(maxDepth, screenCorner.z);
+10 -6
View File
@@ -12,9 +12,13 @@ struct ViewParameter
float4x4 inverseProjection; float4x4 inverseProjection;
float4 cameraPos_WS; float4 cameraPos_WS;
float2 screenDimensions; float2 screenDimensions;
} };
struct ViewParamWrapper
{
ParameterBlock<ViewParameter> c;
};
layout(set = 0) layout(set = 0)
ParameterBlock<ViewParameter> pViewParams; ParameterBlock<ViewParamWrapper> pViewParams;
float4 worldToModel(float4x4 inverseTransform, float4 world) float4 worldToModel(float4x4 inverseTransform, float4 world)
{ {
@@ -27,7 +31,7 @@ float4 worldToModel(float4x4 inverseTransform, float4 world)
float4 viewToWorld(float4 view) float4 viewToWorld(float4 view)
{ {
float4 world = mul(pViewParams.inverseViewMatrix, view); float4 world = mul(pViewParams.c.inverseViewMatrix, view);
world = world / world.w; world = world / world.w;
@@ -43,7 +47,7 @@ float4 viewToModel(float4x4 inverseTransform, float4 view)
float4 clipToView(float4 clip) float4 clipToView(float4 clip)
{ {
float4 view = mul(pViewParams.inverseProjection, clip); float4 view = mul(pViewParams.c.inverseProjection, clip);
view = view / view.w; view = view / view.w;
@@ -59,7 +63,7 @@ float4 clipToWorld(float4 clip)
float4 screenToView(float4 screen) float4 screenToView(float4 screen)
{ {
float2 texCoord = screen.xy / pViewParams.screenDimensions; float2 texCoord = screen.xy / pViewParams.c.screenDimensions;
// Convert to clip space // Convert to clip space
float4 clip = float4( float2( texCoord.x, 1.0f-texCoord.y ) * 2.0f - 1.0f, screen.z, screen.w); float4 clip = float4( float2( texCoord.x, 1.0f-texCoord.y ) * 2.0f - 1.0f, screen.z, screen.w);
@@ -88,7 +92,7 @@ float4 clipToScreen(float4 clip)
float oz = 1; float oz = 1;
float pz = 0 - 1; float pz = 0 - 1;
float zf = pz * ndc.z + oz; float zf = pz * ndc.z + oz;
return float4(float2(texCoords.x, 1 - texCoords.y) * pViewParams.screenDimensions, zf, 1.0f); return float4(float2(texCoords.x, 1 - texCoords.y) * pViewParams.c.screenDimensions, zf, 1.0f);
} }
struct Plane struct Plane
+6 -1
View File
@@ -6,6 +6,11 @@ struct DispatchParams
uint pad0; uint pad0;
uint3 numThreads; uint3 numThreads;
uint pad1; uint pad1;
};
struct DispatchParamWrapper
{
ParameterBlock<DispatchParams> p;
RWStructuredBuffer<Frustum> frustums; RWStructuredBuffer<Frustum> frustums;
} }
ParameterBlock<DispatchParams> pDispatchParams; ParameterBlock<DispatchParamWrapper> pDispatchParams;
+3 -6
View File
@@ -21,7 +21,6 @@ struct FragmentParameter
{ {
float4 position_CS : SV_Position; float4 position_CS : SV_Position;
#ifndef POS_ONLY #ifndef POS_ONLY
float3 cameraPos_WS: POSITION0;
float3 normal_WS : NORMAL0; float3 normal_WS : NORMAL0;
float3 tangent_WS : TANGENT0; float3 tangent_WS : TANGENT0;
float3 biTangent_WS : TANGENT1; float3 biTangent_WS : TANGENT1;
@@ -52,7 +51,7 @@ struct FragmentParameter
float3x3 tbn = float3x3(normalize(tangent_WS), normalize(biTangent_WS), normalize(normal_WS)); float3x3 tbn = float3x3(normalize(tangent_WS), normalize(biTangent_WS), normalize(normal_WS));
result.tbn = tbn; result.tbn = tbn;
result.position_TS = mul(tbn, position_WS); result.position_TS = mul(tbn, position_WS);
result.viewDir_TS = mul(tbn, normalize(cameraPos_WS - position_WS)); result.viewDir_TS = mul(tbn, normalize(pViewParams.c.cameraPos_WS.xyz - position_WS));
result.normal_TS = mul(tbn, normal_WS); result.normal_TS = mul(tbn, normal_WS);
return result; return result;
} }
@@ -67,7 +66,6 @@ struct FragmentParameter
FragmentParameter result; FragmentParameter result;
result.position_CS = f0.position_CS * barycentricCoords.x + f1.position_CS * barycentricCoords.y + f2.position_CS * barycentricCoords.z; result.position_CS = f0.position_CS * barycentricCoords.x + f1.position_CS * barycentricCoords.y + f2.position_CS * barycentricCoords.z;
#ifndef POS_ONLY #ifndef POS_ONLY
result.cameraPos_WS = f0.cameraPos_WS * barycentricCoords.x + f1.cameraPos_WS * barycentricCoords.y + f2.cameraPos_WS * barycentricCoords.z;
result.normal_WS = f0.normal_WS * barycentricCoords.x + f1.normal_WS * barycentricCoords.y + f2.normal_WS * barycentricCoords.z; result.normal_WS = f0.normal_WS * barycentricCoords.x + f1.normal_WS * barycentricCoords.y + f2.normal_WS * barycentricCoords.z;
result.tangent_WS = f0.tangent_WS * barycentricCoords.x + f1.tangent_WS * barycentricCoords.y + f2.tangent_WS * barycentricCoords.z; result.tangent_WS = f0.tangent_WS * barycentricCoords.x + f1.tangent_WS * barycentricCoords.y + f2.tangent_WS * barycentricCoords.z;
result.biTangent_WS = f0.biTangent_WS * barycentricCoords.x + f1.biTangent_WS * barycentricCoords.y + f2.biTangent_WS * barycentricCoords.z; result.biTangent_WS = f0.biTangent_WS * barycentricCoords.x + f1.biTangent_WS * barycentricCoords.y + f2.biTangent_WS * barycentricCoords.z;
@@ -104,8 +102,8 @@ struct VertexAttributes
{ {
float4 modelPos = float4(position_MS, 1); float4 modelPos = float4(position_MS, 1);
float4 worldPos = mul(transformMatrix, modelPos); float4 worldPos = mul(transformMatrix, modelPos);
float4 viewPos = mul(pViewParams.viewMatrix, worldPos); float4 viewPos = mul(pViewParams.c.viewMatrix, worldPos);
float4 clipPos = mul(pViewParams.projectionMatrix, viewPos); float4 clipPos = mul(pViewParams.c.projectionMatrix, viewPos);
FragmentParameter result; FragmentParameter result;
result.position_CS = clipPos; result.position_CS = clipPos;
#ifndef POS_ONLY #ifndef POS_ONLY
@@ -113,7 +111,6 @@ struct VertexAttributes
float3 T = mul(normalMatrix, tangent_MS); float3 T = mul(normalMatrix, tangent_MS);
float3 N = mul(normalMatrix, normal_MS); float3 N = mul(normalMatrix, normal_MS);
float3 B = mul(normalMatrix, biTangent_MS); float3 B = mul(normalMatrix, biTangent_MS);
result.cameraPos_WS = pViewParams.cameraPos_WS.xyz;
result.normal_WS = N; result.normal_WS = N;
result.tangent_WS = T; result.tangent_WS = T;
result.biTangent_WS = B; result.biTangent_WS = B;
+10 -10
View File
@@ -20,8 +20,8 @@ struct MeshData
uint32_t numIndices; uint32_t numIndices;
}; };
static const uint32_t MAX_VERTICES = 256; static const uint32_t MAX_VERTICES = 64;
static const uint32_t MAX_PRIMITIVES = 256; static const uint32_t MAX_PRIMITIVES = 126;
static const uint32_t MAX_MESHLETS_PER_INSTANCE = 2048; static const uint32_t MAX_MESHLETS_PER_INSTANCE = 2048;
struct InstanceData struct InstanceData
@@ -39,19 +39,19 @@ struct MeshletCullingInfo
} }
}; };
struct DrawCallOffsets cbuffer DrawCallOffsets
{ {
uint instanceOffset; uint instanceOffset;
uint textureOffset; uint textureOffset;
uint samplerOffset; uint samplerOffset;
uint floatOffset; uint floatOffset;
}; } pOffsets;
#ifdef RAY_TRACING //#ifdef RAY_TRACING
layout(shaderRecordEXT) //layout(shaderRecordEXT)
#else //#else
layout(push_constant) //layout(push_constant)
#endif //#endif
ConstantBuffer<DrawCallOffsets> pOffsets; //ConstantBuffer<DrawCallOffsets> pOffsets;
struct Scene struct Scene
{ {
+3 -3
View File
@@ -10,11 +10,11 @@ void raygen()
const float2 pixelCenter = float2(LaunchID.xy) + float2(0.5, 0.5); const float2 pixelCenter = float2(LaunchID.xy) + float2(0.5, 0.5);
const float2 inUV = pixelCenter / float2(LaunchSize.xy); const float2 inUV = pixelCenter / float2(LaunchSize.xy);
float2 d = float2(inUV.x, 1 - inUV.y) * 2.0 - 1.0; float2 d = float2(inUV.x, 1 - inUV.y) * 2.0 - 1.0;
float4 target = mul(pViewParams.inverseProjection, float4(d.x, d.y, 1, 1)); float4 target = mul(pViewParams.c.inverseProjection, float4(d.x, d.y, 1, 1));
RayDesc rayDesc; RayDesc rayDesc;
rayDesc.Origin = mul(pViewParams.inverseViewMatrix, float4(0, 0, 0, 1)).xyz; rayDesc.Origin = mul(pViewParams.c.inverseViewMatrix, float4(0, 0, 0, 1)).xyz;
rayDesc.Direction = mul(pViewParams.inverseViewMatrix, float4(normalize(target.xyz), 0)).xyz; rayDesc.Direction = mul(pViewParams.c.inverseViewMatrix, float4(normalize(target.xyz), 0)).xyz;
rayDesc.TMin = 0.001; rayDesc.TMin = 0.001;
rayDesc.TMax = 10000.0; rayDesc.TMax = 10000.0;
+9 -11
View File
@@ -11,8 +11,6 @@
#include "Graphics/Vulkan/Graphics.h" #include "Graphics/Vulkan/Graphics.h"
#endif #endif
#include "Graphics/StaticMeshVertexData.h" #include "Graphics/StaticMeshVertexData.h"
#include "Graphics/Vulkan/Buffer.h"
#include "Graphics/Vulkan/Graphics.h"
#include "Window/PlayView.h" #include "Window/PlayView.h"
#include "Window/WindowManager.h" #include "Window/WindowManager.h"
#include <fmt/core.h> #include <fmt/core.h>
@@ -60,22 +58,22 @@ int main() {
//AssetImporter::importMesh(MeshImportArgs{ //AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/cube.fbx", // .filePath = sourcePath / "import/models/cube.fbx",
//}); //});
AssetImporter::importMesh(MeshImportArgs{ //AssetImporter::importMesh(MeshImportArgs{
.filePath = sourcePath / "import/models/culling.fbx", // .filePath = sourcePath / "import/models/culling.fbx",
}); //});
AssetImporter::importTexture(TextureImportArgs{ AssetImporter::importTexture(TextureImportArgs{
.filePath = sourcePath / "import/textures/skyboxsun5deg_tn.jpg", .filePath = sourcePath / "import/textures/skyboxsun5deg_tn.jpg",
.type = TextureImportType::TEXTURE_CUBEMAP, .type = TextureImportType::TEXTURE_CUBEMAP,
}); });
//AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/ship.fbx",
// .importPath = "ship",
//});
AssetImporter::importMesh(MeshImportArgs{ AssetImporter::importMesh(MeshImportArgs{
.filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb", .filePath = sourcePath / "import/models/ship.fbx",
.importPath = "Whitechapel", .importPath = "ship",
}); });
//AssetImporter::importMesh(MeshImportArgs{ //AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb",
// .importPath = "Whitechapel",
//});
//AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/city-suburbs/source/city-suburbs.obj", // .filePath = sourcePath / "import/models/city-suburbs/source/city-suburbs.obj",
// .importPath = "suburbs", // .importPath = "suburbs",
//}); //});
+4 -4
View File
@@ -13,8 +13,8 @@ class RenderCommand {
virtual void setViewport(Gfx::PViewport viewport) = 0; virtual void setViewport(Gfx::PViewport viewport) = 0;
virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) = 0; virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) = 0;
virtual void bindPipeline(Gfx::PRayTracingPipeline pipeline) = 0; virtual void bindPipeline(Gfx::PRayTracingPipeline pipeline) = 0;
virtual void bindDescriptor(Gfx::PDescriptorSet set, Array<uint32> dynamicOffsets = {}) = 0; virtual void bindDescriptor(Gfx::PDescriptorSet set) = 0;
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets, Array<uint32> dynamicOffsets = {}) = 0; virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) = 0;
virtual void bindVertexBuffer(const Array<PVertexBuffer>& buffer) = 0; virtual void bindVertexBuffer(const Array<PVertexBuffer>& buffer) = 0;
virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) = 0; virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) = 0;
virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) = 0; virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) = 0;
@@ -31,8 +31,8 @@ class ComputeCommand {
ComputeCommand(); ComputeCommand();
virtual ~ComputeCommand(); virtual ~ComputeCommand();
virtual void bindPipeline(Gfx::PComputePipeline pipeline) = 0; virtual void bindPipeline(Gfx::PComputePipeline pipeline) = 0;
virtual void bindDescriptor(Gfx::PDescriptorSet set, Array<uint32> dynamicOffsets = {}) = 0; virtual void bindDescriptor(Gfx::PDescriptorSet set) = 0;
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets, Array<uint32> dynamicOffsets = {}) = 0; virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) = 0;
virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) = 0; virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) = 0;
virtual void dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) = 0; virtual void dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) = 0;
std::string name; std::string name;
+2 -3
View File
@@ -64,11 +64,8 @@ class DescriptorSet {
virtual void updateBuffer(uint32 binding, PUniformBuffer uniformBuffer) = 0; virtual void updateBuffer(uint32 binding, PUniformBuffer uniformBuffer) = 0;
virtual void updateBuffer(uint32 binding, PIndexBuffer indexBuffer) = 0; virtual void updateBuffer(uint32 binding, PIndexBuffer indexBuffer) = 0;
virtual void updateBuffer(uint32 binding, PShaderBuffer shaderBuffer) = 0; virtual void updateBuffer(uint32 binding, PShaderBuffer shaderBuffer) = 0;
virtual void updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) = 0;
virtual void updateSampler(uint32 binding, PSampler sampler) = 0; virtual void updateSampler(uint32 binding, PSampler sampler) = 0;
virtual void updateSampler(uint32_t binding, uint32 dstArrayIndex, Gfx::PSampler samplerState) = 0;
virtual void updateTexture(uint32 binding, PTexture texture, PSampler samplerState = nullptr) = 0; virtual void updateTexture(uint32 binding, PTexture texture, PSampler samplerState = nullptr) = 0;
virtual void updateTexture(uint32 binding, uint32 dstArrayIndex, PTexture texture) = 0;
virtual void updateTextureArray(uint32_t binding, Array<PTexture2D> texture) = 0; virtual void updateTextureArray(uint32_t binding, Array<PTexture2D> texture) = 0;
virtual void updateSamplerArray(uint32_t binding, Array<PSampler> samplers) = 0; virtual void updateSamplerArray(uint32_t binding, Array<PSampler> samplers) = 0;
virtual void updateAccelerationStructure(uint32 binding, PTopLevelAS as) = 0; virtual void updateAccelerationStructure(uint32 binding, PTopLevelAS as) = 0;
@@ -96,6 +93,8 @@ class PipelineLayout {
constexpr uint32 findParameter(const std::string& param) const { return parameterMapping[param]; } constexpr uint32 findParameter(const std::string& param) const { return parameterMapping[param]; }
void addMapping(std::string name, uint32 index); void addMapping(std::string name, uint32 index);
constexpr std::string getName() const { return name; }; constexpr std::string getName() const { return name; };
constexpr bool hasPushConstants() const { return !pushConstants.empty(); }
constexpr uint64 getPushConstantsSize() const { return pushConstants[0].size; }
protected: protected:
uint32 layoutHash = 0; uint32 layoutHash = 0;
+2 -2
View File
@@ -159,8 +159,8 @@ static constexpr bool useAsyncCompute = false;
static constexpr bool useMeshShading = true; static constexpr bool useMeshShading = true;
static constexpr uint32 numFramesBuffered = 3; static constexpr uint32 numFramesBuffered = 3;
static constexpr uint32 numVerticesPerMeshlet = 256; static constexpr uint32 numVerticesPerMeshlet = 64;
static constexpr uint32 numPrimitivesPerMeshlet = 256; static constexpr uint32 numPrimitivesPerMeshlet = 126;
double getCurrentFrameDelta(); double getCurrentFrameDelta();
double getCurrentFrameTime(); double getCurrentFrameTime();
uint32 getCurrentFrameIndex(); uint32 getCurrentFrameIndex();
+2 -1
View File
@@ -68,7 +68,7 @@ struct SamplerCreateInfo {
Gfx::SeSamplerAddressMode addressModeW = Gfx::SE_SAMPLER_ADDRESS_MODE_REPEAT; Gfx::SeSamplerAddressMode addressModeW = Gfx::SE_SAMPLER_ADDRESS_MODE_REPEAT;
float mipLodBias = 0.0f; float mipLodBias = 0.0f;
uint32 anisotropyEnable = 0; uint32 anisotropyEnable = 0;
float maxAnisotropy = 0.0f; float maxAnisotropy = 1.0f;
uint32 compareEnable = 0; uint32 compareEnable = 0;
Gfx::SeCompareOp compareOp = Gfx::SE_COMPARE_OP_NEVER; Gfx::SeCompareOp compareOp = Gfx::SE_COMPARE_OP_NEVER;
float minLod = 0.0f; float minLod = 0.0f;
@@ -138,6 +138,7 @@ struct SePushConstantRange {
SeShaderStageFlags stageFlags; SeShaderStageFlags stageFlags;
uint32 offset; uint32 offset;
uint32 size; uint32 size;
std::string name;
}; };
struct RasterizationState { struct RasterizationState {
uint32 depthClampEnable = 0; uint32 depthClampEnable = 0;
+10 -1
View File
@@ -42,9 +42,12 @@ void BufferAllocation::unmap() {}
Buffer::Buffer(PGraphics graphics, uint64 size, Gfx::SeBufferUsageFlags usage, Gfx::QueueType queueType, bool dynamic, std::string name, Buffer::Buffer(PGraphics graphics, uint64 size, Gfx::SeBufferUsageFlags usage, Gfx::QueueType queueType, bool dynamic, std::string name,
bool createCleared, uint32 clearValue) bool createCleared, uint32 clearValue)
: graphics(graphics), currentBuffer(0), dynamic(dynamic), createCleared(createCleared), name(name), clearValue(clearValue) { : graphics(graphics), currentBuffer(0), dynamic(dynamic), createCleared(createCleared), name(name), clearValue(clearValue) {
if(size > 0)
{
buffers.add(nullptr); buffers.add(nullptr);
createBuffer(size, 0); createBuffer(size, 0);
} }
}
Buffer::~Buffer() { Buffer::~Buffer() {
for (size_t i = 0; i < buffers.size(); ++i) { for (size_t i = 0; i < buffers.size(); ++i) {
@@ -101,10 +104,16 @@ void Buffer::copyBuffer(uint64 src, uint64 dest) {
std::memcpy(buffers[dest]->map(), buffers[src]->map(), buffers[src]->size); std::memcpy(buffers[dest]->map(), buffers[src]->map(), buffers[src]->size);
} }
void Buffer::transferOwnership(Gfx::QueueType newOwner) { getAlloc()->transferOwnership(newOwner); } void Buffer::transferOwnership(Gfx::QueueType newOwner) {
if(buffers.size() == 0)
return;
getAlloc()->transferOwnership(newOwner);
}
void Buffer::pipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess, void Buffer::pipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) { Gfx::SePipelineStageFlags dstStage) {
if(buffers.size() == 0)
return;
getAlloc()->pipelineBarrier(srcAccess, srcStage, dstAccess, dstStage); getAlloc()->pipelineBarrier(srcAccess, srcStage, dstAccess, dstStage);
} }
+6 -7
View File
@@ -57,8 +57,8 @@ class RenderCommand : public Gfx::RenderCommand {
virtual void setViewport(Gfx::PViewport viewport) override; virtual void setViewport(Gfx::PViewport viewport) override;
virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) override; virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) override;
virtual void bindPipeline(Gfx::PRayTracingPipeline pipeline) override; virtual void bindPipeline(Gfx::PRayTracingPipeline pipeline) override;
virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array<uint32> dynamicOffsets) override; virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet) override;
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets, Array<uint32> dynamicOffsets) override; virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets) override;
virtual void bindVertexBuffer(const Array<Gfx::PVertexBuffer>& buffers) override; virtual void bindVertexBuffer(const Array<Gfx::PVertexBuffer>& buffers) override;
virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) override; virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) override;
virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override; virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override;
@@ -71,9 +71,8 @@ class RenderCommand : public Gfx::RenderCommand {
private: private:
PGraphicsPipeline boundPipeline; PGraphicsPipeline boundPipeline;
PIndexBuffer boundIndexBuffer; PIndexBuffer boundIndexBuffer;
MTL::ArgumentEncoder* argumentEncoder;
MTL::Buffer* argumentBuffer;
MTL::RenderCommandEncoder* encoder; MTL::RenderCommandEncoder* encoder;
MTL::Buffer* constantsBuffer;
std::string name; std::string name;
}; };
DEFINE_REF(RenderCommand) DEFINE_REF(RenderCommand)
@@ -83,8 +82,8 @@ class ComputeCommand : public Gfx::ComputeCommand {
virtual ~ComputeCommand(); virtual ~ComputeCommand();
void end(); void end();
virtual void bindPipeline(Gfx::PComputePipeline pipeline) override; virtual void bindPipeline(Gfx::PComputePipeline pipeline) override;
virtual void bindDescriptor(Gfx::PDescriptorSet set, Array<uint32> dynamicOffsets) override; virtual void bindDescriptor(Gfx::PDescriptorSet set) override;
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets, Array<uint32> dynamicOffsets) override; virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) override;
virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override; virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override;
virtual void dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) override; virtual void dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) override;
@@ -92,7 +91,7 @@ class ComputeCommand : public Gfx::ComputeCommand {
PComputePipeline boundPipeline; PComputePipeline boundPipeline;
MTL::CommandBuffer* commandBuffer; MTL::CommandBuffer* commandBuffer;
MTL::ComputeCommandEncoder* encoder; MTL::ComputeCommandEncoder* encoder;
MTL::Buffer* argumentBuffer; MTL::Buffer* constantsBuffer;
std::string name; std::string name;
}; };
DEFINE_REF(ComputeCommand) DEFINE_REF(ComputeCommand)
+34 -19
View File
@@ -3,6 +3,7 @@
#include "Containers/Array.h" #include "Containers/Array.h"
#include "Descriptor.h" #include "Descriptor.h"
#include "Enums.h" #include "Enums.h"
#include "Graphics/Graphics.h"
#include "Graphics/Command.h" #include "Graphics/Command.h"
#include "Graphics/Enums.h" #include "Graphics/Enums.h"
#include "Graphics/Graphics.h" #include "Graphics/Graphics.h"
@@ -74,35 +75,51 @@ void RenderCommand::setViewport(Gfx::PViewport viewport) {
void RenderCommand::bindPipeline(Gfx::PGraphicsPipeline pipeline) { void RenderCommand::bindPipeline(Gfx::PGraphicsPipeline pipeline) {
boundPipeline = pipeline.cast<GraphicsPipeline>(); boundPipeline = pipeline.cast<GraphicsPipeline>();
encoder->setRenderPipelineState(boundPipeline->getHandle()); encoder->setRenderPipelineState(boundPipeline->getHandle());
if(boundPipeline->getPipelineLayout()->hasPushConstants()) {
constantsBuffer = boundPipeline->graphics->getDevice()->newBuffer(boundPipeline->getPipelineLayout()->getPushConstantsSize(), 0);
}
} }
void RenderCommand::bindPipeline(Gfx::PRayTracingPipeline pipeline) {} void RenderCommand::bindPipeline(Gfx::PRayTracingPipeline pipeline) {}
void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array<uint32> offsets) { void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet) {
auto metalSet = descriptorSet.cast<DescriptorSet>(); auto metalSet = descriptorSet.cast<DescriptorSet>();
metalSet->bind(); metalSet->bind();
uint32 descriptorIndex = boundPipeline->getPipelineLayout()->findParameter(metalSet->getLayout()->getName());
encoder->setVertexBuffer(metalSet->getArgumentBuffer(), 0, descriptorIndex);
encoder->setFragmentBuffer(metalSet->getArgumentBuffer(), 0, descriptorIndex);
encoder->setObjectBuffer(metalSet->getArgumentBuffer(), 0, descriptorIndex);
encoder->setMeshBuffer(metalSet->getArgumentBuffer(), 0, descriptorIndex);
} }
void RenderCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets, Array<uint32> offsets) { void RenderCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets) {
for (auto set : descriptorSets) { for (auto set : descriptorSets) {
bindDescriptor(set, offsets); bindDescriptor(set);
} }
} }
void RenderCommand::bindVertexBuffer(const Array<Gfx::PVertexBuffer>& buffers) { void RenderCommand::bindVertexBuffer(const Array<Gfx::PVertexBuffer>& buffers) {
uint32 i = 0; uint32 i = 0;
for (auto buffer : buffers) { for (auto buffer : buffers) {
encoder->setVertexBuffer(buffer.cast<VertexBuffer>()->getHandle(), 0, METAL_VERTEXBUFFER_OFFSET + i++); encoder->setVertexBuffer(buffer.cast<VertexBuffer>()->getHandle(), 0, buffer.cast<VertexBuffer>()->getVertexSize(), i++);
} }
} }
void RenderCommand::bindIndexBuffer(Gfx::PIndexBuffer gfxIndexBuffer) { boundIndexBuffer = gfxIndexBuffer.cast<IndexBuffer>(); } void RenderCommand::bindIndexBuffer(Gfx::PIndexBuffer gfxIndexBuffer) { boundIndexBuffer = gfxIndexBuffer.cast<IndexBuffer>(); }
void RenderCommand::pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) { void RenderCommand::pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) {
std::memcpy(constantsBuffer->contents(), data, size);
uint pushIndex = boundPipeline->getPipelineLayout()->findParameter("pOffsets");
if (stage & Gfx::SE_SHADER_STAGE_VERTEX_BIT) { if (stage & Gfx::SE_SHADER_STAGE_VERTEX_BIT) {
encoder->setVertexBytes((char*)data + offset, size, 0); encoder->setVertexBuffer(constantsBuffer, 0, pushIndex); // TODO: hardcoded
} }
if (stage & Gfx::SE_SHADER_STAGE_FRAGMENT_BIT) { if (stage & Gfx::SE_SHADER_STAGE_FRAGMENT_BIT) {
encoder->setFragmentBytes((char*)data + offset, size, 0); encoder->setFragmentBuffer(constantsBuffer, 0, pushIndex); // TODO: hardcoded
}
if (stage & Gfx::SE_SHADER_STAGE_TASK_BIT_EXT) {
encoder->setObjectBuffer(constantsBuffer, 0, pushIndex); // TODO: hardcoded
}
if (stage & Gfx::SE_SHADER_STAGE_MESH_BIT_EXT) {
encoder->setMeshBuffer(constantsBuffer, 0, pushIndex); // TODO: hardcoded
} }
} }
@@ -116,11 +133,6 @@ void RenderCommand::drawIndexed(uint32 indexCount, uint32 instanceCount, int32 f
} }
void RenderCommand::drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) { void RenderCommand::drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) {
// TODO:
std::cout << "Draw" << std::endl;
encoder->setFragmentBuffer(argumentBuffer, 0, 2);
encoder->setMeshBuffer(argumentBuffer, 0, 2);
encoder->setObjectBuffer(argumentBuffer, 0, 2);
encoder->drawMeshThreadgroups(MTL::Size(groupX, groupY, groupZ), MTL::Size(128, 1, 1), MTL::Size(32, 1, 1)); encoder->drawMeshThreadgroups(MTL::Size(groupX, groupY, groupZ), MTL::Size(128, 1, 1), MTL::Size(32, 1, 1));
} }
@@ -143,29 +155,32 @@ void ComputeCommand::end() {
void ComputeCommand::bindPipeline(Gfx::PComputePipeline pipeline) { void ComputeCommand::bindPipeline(Gfx::PComputePipeline pipeline) {
boundPipeline = pipeline.cast<ComputePipeline>(); boundPipeline = pipeline.cast<ComputePipeline>();
encoder->setComputePipelineState(boundPipeline->getHandle()); encoder->setComputePipelineState(boundPipeline->getHandle());
argumentBuffer = boundPipeline->graphics->getDevice()->newBuffer( if(boundPipeline->getPipelineLayout()->hasPushConstants()) {
sizeof(uint64) * (boundPipeline->getPipelineLayout()->getLayouts().size() + 1), MTL::ResourceStorageModeShared); constantsBuffer = boundPipeline->graphics->getDevice()->newBuffer(boundPipeline->getPipelineLayout()->getPushConstantsSize(), 0);
argumentBuffer->setLabel(NS::String::string(pipeline->getPipelineLayout()->getName().c_str(), NS::ASCIIStringEncoding)); }
} }
void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set, Array<uint32> offsets) { void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set) {
auto metalSet = set.cast<DescriptorSet>(); auto metalSet = set.cast<DescriptorSet>();
metalSet->bind(); metalSet->bind();
uint32 descriptorIndex = boundPipeline->getPipelineLayout()->findParameter(metalSet->getLayout()->getName());
encoder->setBuffer(metalSet->getArgumentBuffer(), 0, descriptorIndex);
} }
void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& sets, Array<uint32> offsets) { void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) {
for (auto& set : sets) { for (auto& set : sets) {
bindDescriptor(set, offsets); bindDescriptor(set);
} }
} }
void ComputeCommand::pushConstants(Gfx::SeShaderStageFlags, uint32 offset, uint32 size, const void* data) { void ComputeCommand::pushConstants(Gfx::SeShaderStageFlags, uint32 offset, uint32 size, const void* data) {
encoder->setBytes((char*)data + offset, size, 0); std::memcpy(constantsBuffer->contents(), data, size);
uint pushIndex = boundPipeline->getPipelineLayout()->findParameter("pMipParam");
encoder->setBuffer(constantsBuffer, 0, pushIndex); // TODO: hardcoded
} }
void ComputeCommand::dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) { void ComputeCommand::dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) {
// TODO // TODO
encoder->setBuffer(argumentBuffer, 0, 2);
encoder->dispatchThreadgroups(MTL::Size(threadX, threadY, threadZ), MTL::Size(32, 32, 1)); encoder->dispatchThreadgroups(MTL::Size(threadX, threadY, threadZ), MTL::Size(32, 32, 1));
} }
+4 -5
View File
@@ -50,21 +50,20 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
virtual void updateBuffer(uint32 binding, Gfx::PUniformBuffer uniformBuffer) override; virtual void updateBuffer(uint32 binding, Gfx::PUniformBuffer uniformBuffer) override;
virtual void updateBuffer(uint32 binding, Gfx::PShaderBuffer uniformBuffer) override; virtual void updateBuffer(uint32 binding, Gfx::PShaderBuffer uniformBuffer) override;
virtual void updateBuffer(uint32 binding, Gfx::PIndexBuffer uniformBuffer) override; virtual void updateBuffer(uint32 binding, Gfx::PIndexBuffer uniformBuffer) override;
virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) override;
virtual void updateSampler(uint32 binding, Gfx::PSampler samplerState) override; virtual void updateSampler(uint32 binding, Gfx::PSampler samplerState) override;
virtual void updateSampler(uint32 binding, uint32 dstArrayIndex, Gfx::PSampler samplerState) override;
virtual void updateTexture(uint32 binding, Gfx::PTexture texture, Gfx::PSampler sampler = nullptr) override; virtual void updateTexture(uint32 binding, Gfx::PTexture texture, Gfx::PSampler sampler = nullptr) override;
virtual void updateTexture(uint32 binding, uint32 dstArrayIndex, Gfx::PTexture texture) override;
virtual void updateTextureArray(uint32 binding, Array<Gfx::PTexture2D> texture) override; virtual void updateTextureArray(uint32 binding, Array<Gfx::PTexture2D> texture) override;
virtual void updateSamplerArray(uint32 binding, Array<Gfx::PSampler> samplers) override; virtual void updateSamplerArray(uint32 binding, Array<Gfx::PSampler> samplers) override;
virtual void updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS as) override; virtual void updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS as) override;
constexpr const Array<Array<MTL::Resource*>>& getBoundResources() const { return boundResources; } constexpr const Array<MTL::Resource*>& getBoundResources() const { return boundResources; }
MTL::Buffer* getArgumentBuffer() const { return argumentBuffer; }
private: private:
PGraphics graphics; PGraphics graphics;
PDescriptorPool owner; PDescriptorPool owner;
Array<Array<MTL::Resource*>> boundResources; Array<MTL::Resource*> boundResources;
MTL::ArgumentEncoder* encoder; MTL::ArgumentEncoder* encoder;
MTL::Buffer* argumentBuffer = nullptr; MTL::Buffer* argumentBuffer = nullptr;
}; };
+78 -24
View File
@@ -4,6 +4,7 @@
#include "Foundation/NSArray.hpp" #include "Foundation/NSArray.hpp"
#include "Foundation/NSObject.hpp" #include "Foundation/NSObject.hpp"
#include "Graphics/Descriptor.h" #include "Graphics/Descriptor.h"
#include "Graphics/Enums.h"
#include "Graphics/Initializer.h" #include "Graphics/Initializer.h"
#include "Graphics/Metal/Resources.h" #include "Graphics/Metal/Resources.h"
#include "Graphics/Metal/Shader.h" #include "Graphics/Metal/Shader.h"
@@ -15,8 +16,10 @@
#include "Metal/MTLTexture.hpp" #include "Metal/MTLTexture.hpp"
#include "Texture.h" #include "Texture.h"
#include <CRC.h> #include <CRC.h>
#include <CoreFoundation/CoreFoundation.h>
#include <Foundation/Foundation.h> #include <Foundation/Foundation.h>
#include <iostream> #include <iostream>
#include <stdexcept>
using namespace Seele; using namespace Seele;
using namespace Seele::Metal; using namespace Seele::Metal;
@@ -34,14 +37,63 @@ void DescriptorLayout::create() {
objects[i]->setIndex(i); objects[i]->setIndex(i);
objects[i]->setAccess(cast(descriptorBindings[i].access)); objects[i]->setAccess(cast(descriptorBindings[i].access));
objects[i]->setArrayLength(descriptorBindings[i].descriptorCount); objects[i]->setArrayLength(descriptorBindings[i].descriptorCount);
objects[i]->setDataType(MTL::DataTypeStruct); MTL::DataType dataType;
switch (descriptorBindings[i].descriptorType) {
case Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE:
case Gfx::SE_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
case Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
case Gfx::SE_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
dataType = MTL::DataTypeTexture;
break;
case Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER:
case Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
case Gfx::SE_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK:
dataType = MTL::DataTypePointer;
break;
case Gfx::SE_DESCRIPTOR_TYPE_SAMPLER:
dataType = MTL::DataTypeSampler;
break;
case Gfx::SE_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR:
dataType = MTL::DataTypeInstanceAccelerationStructure;
break;
default:
throw new std::logic_error("unknown descriptor type");
}
objects[i]->setDataType(dataType);
MTL::TextureType textureType;
switch (descriptorBindings[i].textureType) {
case Gfx::SE_IMAGE_VIEW_TYPE_1D:
textureType = MTL::TextureType1D;
break;
case Gfx::SE_IMAGE_VIEW_TYPE_2D:
textureType = MTL::TextureType2D;
break;
case Gfx::SE_IMAGE_VIEW_TYPE_3D:
textureType = MTL::TextureType3D;
break;
case Gfx::SE_IMAGE_VIEW_TYPE_CUBE:
textureType = MTL::TextureTypeCube;
break;
case Gfx::SE_IMAGE_VIEW_TYPE_1D_ARRAY:
textureType = MTL::TextureType1DArray;
break;
case Gfx::SE_IMAGE_VIEW_TYPE_2D_ARRAY:
textureType = MTL::TextureType2DArray;
break;
case Gfx::SE_IMAGE_VIEW_TYPE_CUBE_ARRAY:
textureType = MTL::TextureTypeCubeArray;
break;
}
objects[i]->setTextureType(textureType);
} }
arguments = NS::Array::array((NS::Object**)objects, descriptorBindings.size()); arguments = NS::Array::array((NS::Object**)objects, descriptorBindings.size());
} }
MTL::ArgumentEncoder* DescriptorLayout::createEncoder() { MTL::ArgumentEncoder* DescriptorLayout::createEncoder() { return graphics->getDevice()->newArgumentEncoder(arguments); }
return graphics->getDevice()->newArgumentEncoder(arguments);
}
DescriptorPool::DescriptorPool(PGraphics graphics, PDescriptorLayout layout) : graphics(graphics), layout(layout) {} DescriptorPool::DescriptorPool(PGraphics graphics, PDescriptorLayout layout) : graphics(graphics), layout(layout) {}
@@ -65,10 +117,10 @@ void DescriptorPool::reset() {}
DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner) DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner)
: Gfx::DescriptorSet(owner->getLayout()), CommandBoundResource(graphics), graphics(graphics), owner(owner) { : Gfx::DescriptorSet(owner->getLayout()), CommandBoundResource(graphics), graphics(graphics), owner(owner) {
encoder = owner->getLayout()->createEncoder();
argumentBuffer = graphics->getDevice()->newBuffer(encoder->encodedLength(), 0);
encoder->setArgumentBuffer(argumentBuffer, 0);
boundResources.resize(owner->getLayout()->getBindings().size()); boundResources.resize(owner->getLayout()->getBindings().size());
for (uint32 i = 0; i < boundResources.size(); ++i) {
boundResources[i].resize(owner->getLayout()->getBindings()[i].descriptorCount);
}
} }
DescriptorSet::~DescriptorSet() {} DescriptorSet::~DescriptorSet() {}
@@ -76,38 +128,40 @@ DescriptorSet::~DescriptorSet() {}
void DescriptorSet::writeChanges() {} void DescriptorSet::writeChanges() {}
void DescriptorSet::updateBuffer(uint32 binding, Gfx::PUniformBuffer uniformBuffer) { void DescriptorSet::updateBuffer(uint32 binding, Gfx::PUniformBuffer uniformBuffer) {
boundResources[binding][0] = uniformBuffer.cast<UniformBuffer>()->getHandle(); PUniformBuffer buffer = uniformBuffer.cast<UniformBuffer>();
encoder->setBuffer(buffer->getHandle(), 0, binding);
boundResources[binding] = buffer->getHandle();
} }
void DescriptorSet::updateBuffer(uint32 binding, Gfx::PShaderBuffer uniformBuffer) { void DescriptorSet::updateBuffer(uint32 binding, Gfx::PShaderBuffer uniformBuffer) {
boundResources[binding][0] = uniformBuffer.cast<ShaderBuffer>()->getHandle(); PShaderBuffer buffer = uniformBuffer.cast<ShaderBuffer>();
encoder->setBuffer(buffer->getHandle(), 0, binding);
boundResources[binding] = buffer->getHandle();
} }
void DescriptorSet::updateBuffer(uint32 binding, Gfx::PIndexBuffer uniformBuffer) { void DescriptorSet::updateBuffer(uint32 binding, Gfx::PIndexBuffer uniformBuffer) {
boundResources[binding][0] = uniformBuffer.cast<IndexBuffer>()->getHandle(); PIndexBuffer buffer = uniformBuffer.cast<IndexBuffer>();
} encoder->setBuffer(buffer->getHandle(), 0, binding);
boundResources[binding] = buffer->getHandle();
void DescriptorSet::updateBuffer(uint32 binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) {
boundResources[binding][0] = uniformBuffer.cast<ShaderBuffer>()->getHandle();
} }
void DescriptorSet::updateSampler(uint32 binding, Gfx::PSampler samplerState) { void DescriptorSet::updateSampler(uint32 binding, Gfx::PSampler samplerState) {
boundResources[binding][0] = nullptr; // Samplers are not resources?????? PSampler sampler = samplerState.cast<Sampler>();
encoder->setSamplerState(sampler->getHandle(), binding);
boundResources[binding] = nullptr; // Samplers are not resources??????
} }
void DescriptorSet::updateSampler(uint32 binding, uint32 dstArrayIndex, Gfx::PSampler samplerState) { void DescriptorSet::updateTexture(uint32 binding, Gfx::PTexture texture, Gfx::PSampler sampler) {
boundResources[binding][dstArrayIndex] = nullptr; PTextureBase base = texture.cast<TextureBase>();
encoder->setTexture(base->getHandle()->texture, binding);
boundResources[binding] = base->getHandle()->texture;
} }
void DescriptorSet::updateTexture(uint32 binding, Gfx::PTexture texture, Gfx::PSampler sampler) {} void DescriptorSet::updateTextureArray(uint32 binding, Array<Gfx::PTexture2D> texture) { assert(false && "TODO"); }
void DescriptorSet::updateTexture(uint32 binding, uint32 dstArrayIndex, Gfx::PTexture texture) {} void DescriptorSet::updateSamplerArray(uint32 binding, Array<Gfx::PSampler> samplers) { assert(false && "TODO"); }
void DescriptorSet::updateTextureArray(uint32 binding, Array<Gfx::PTexture2D> texture) {} void DescriptorSet::updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS as) { assert(false && "TODO"); }
void DescriptorSet::updateSamplerArray(uint32 binding, Array<Gfx::PSampler> samplers) {}
void DescriptorSet::updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS as) {}
PipelineLayout::PipelineLayout(PGraphics graphics, const std::string& name, Gfx::PPipelineLayout baseLayout) PipelineLayout::PipelineLayout(PGraphics graphics, const std::string& name, Gfx::PPipelineLayout baseLayout)
: Gfx::PipelineLayout(name, baseLayout), graphics(graphics) {} : Gfx::PipelineLayout(name, baseLayout), graphics(graphics) {}
+4 -4
View File
@@ -121,7 +121,7 @@ Gfx::PGraphicsPipeline Graphics::createGraphicsPipeline(Gfx::MeshPipelineCreateI
Gfx::PComputePipeline Graphics::createComputePipeline(Gfx::ComputePipelineCreateInfo createInfo) { Gfx::PComputePipeline Graphics::createComputePipeline(Gfx::ComputePipelineCreateInfo createInfo) {
return cache->createPipeline(std::move(createInfo)); return cache->createPipeline(std::move(createInfo));
} }
Gfx::PRayTracingPipeline Graphics::createRayTracingPipeline(Gfx::RayTracingPipelineCreateInfo createInfo) { return nullptr; } Gfx::PRayTracingPipeline Graphics::createRayTracingPipeline(Gfx::RayTracingPipelineCreateInfo) { return nullptr; }
Gfx::OSampler Graphics::createSampler(const SamplerCreateInfo& createInfo) { return new Sampler(this, createInfo); } Gfx::OSampler Graphics::createSampler(const SamplerCreateInfo& createInfo) { return new Sampler(this, createInfo); }
@@ -143,16 +143,16 @@ Gfx::OTimestampQuery Graphics::createTimestampQuery(uint64 numTimestamps, const
return new TimestampQuery(this, name, numTimestamps); return new TimestampQuery(this, name, numTimestamps);
} }
void Graphics::resolveTexture(Gfx::PTexture source, Gfx::PTexture destination) {} void Graphics::resolveTexture(Gfx::PTexture, Gfx::PTexture) {}
void Graphics::copyTexture(Gfx::PTexture src, Gfx::PTexture dst) {} void Graphics::copyTexture(Gfx::PTexture, Gfx::PTexture) {}
// Ray Tracing // Ray Tracing
Gfx::OBottomLevelAS Graphics::createBottomLevelAccelerationStructure(const Gfx::BottomLevelASCreateInfo& createInfo) { return nullptr; } Gfx::OBottomLevelAS Graphics::createBottomLevelAccelerationStructure(const Gfx::BottomLevelASCreateInfo& createInfo) { return nullptr; }
Gfx::OTopLevelAS Graphics::createTopLevelAccelerationStructure(const Gfx::TopLevelASCreateInfo& createInfo) { return nullptr; } Gfx::OTopLevelAS Graphics::createTopLevelAccelerationStructure(const Gfx::TopLevelASCreateInfo& createInfo) { return nullptr; }
void Graphics::buildBottomLevelAccelerationStructures(Array<Gfx::PBottomLevelAS> data) {} void Graphics::buildBottomLevelAccelerationStructures(Array<Gfx::PBottomLevelAS>) {}
Gfx::ORayGenShader Graphics::createRayGenShader(const ShaderCreateInfo& createInfo) { Gfx::ORayGenShader Graphics::createRayGenShader(const ShaderCreateInfo& createInfo) {
ORayGenShader shader = new RayGenShader(this); ORayGenShader shader = new RayGenShader(this);
+37 -71
View File
@@ -14,35 +14,28 @@
#include "Metal/MTLVertexDescriptor.hpp" #include "Metal/MTLVertexDescriptor.hpp"
#include "Shader.h" #include "Shader.h"
#include "Texture.h" #include "Texture.h"
#include <Foundation/Foundation.h>
#include <iostream> #include <iostream>
using namespace Seele; using namespace Seele;
using namespace Seele::Metal; using namespace Seele::Metal;
PipelineCache::PipelineCache(PGraphics graphics, const std::string &name) PipelineCache::PipelineCache(PGraphics graphics, const std::string& name) : graphics(graphics), cacheFile(name) {}
: graphics(graphics), cacheFile(name) {}
PipelineCache::~PipelineCache() {} PipelineCache::~PipelineCache() {}
PGraphicsPipeline PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo createInfo) {
PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo createInfo) { PPipelineLayout layout = Gfx::PPipelineLayout(createInfo.pipelineLayout).cast<PipelineLayout>();
PPipelineLayout layout =
Gfx::PPipelineLayout(createInfo.pipelineLayout).cast<PipelineLayout>();
MTL::RenderPipelineDescriptor *pipelineDescriptor = MTL::RenderPipelineDescriptor* pipelineDescriptor = MTL::RenderPipelineDescriptor::alloc()->init();
MTL::RenderPipelineDescriptor::alloc()->init();
MTL::VertexDescriptor *vertexDescriptor = MTL::VertexDescriptor* vertexDescriptor = pipelineDescriptor->vertexDescriptor()->init();
pipelineDescriptor->vertexDescriptor()->init(); MTL::VertexAttributeDescriptorArray* attributes = vertexDescriptor->attributes()->init();
MTL::VertexAttributeDescriptorArray *attributes =
vertexDescriptor->attributes()->init();
if (createInfo.vertexInput != nullptr) { if (createInfo.vertexInput != nullptr) {
const auto& vertexInfo = createInfo.vertexInput->getInfo(); const auto& vertexInfo = createInfo.vertexInput->getInfo();
for (size_t attr = 0; attr < vertexInfo.attributes.size(); ++attr) { for (size_t attr = 0; attr < vertexInfo.attributes.size(); ++attr) {
MTL::VertexAttributeDescriptor *attribute = MTL::VertexAttributeDescriptor* attribute = attributes->object(attr)->init();
attributes->object(attr + METAL_VERTEXATTRIBUTE_OFFSET)->init(); attribute->setBufferIndex(vertexInfo.attributes[attr].binding);
attribute->setBufferIndex(vertexInfo.attributes[attr].binding +
METAL_VERTEXBUFFER_OFFSET);
switch (vertexInfo.attributes[attr].format) { switch (vertexInfo.attributes[attr].format) {
case Gfx::SE_FORMAT_R32G32B32_SFLOAT: case Gfx::SE_FORMAT_R32G32B32_SFLOAT:
attribute->setFormat(MTL::VertexFormatFloat3); attribute->setFormat(MTL::VertexFormatFloat3);
@@ -53,11 +46,9 @@ PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo createInfo) {
attribute->setOffset(vertexInfo.attributes[attr].offset); attribute->setOffset(vertexInfo.attributes[attr].offset);
} }
MTL::VertexBufferLayoutDescriptorArray *bufferLayout = MTL::VertexBufferLayoutDescriptorArray* bufferLayout = vertexDescriptor->layouts()->init();
vertexDescriptor->layouts()->init();
for (size_t binding = 0; binding < vertexInfo.bindings.size(); ++binding) { for (size_t binding = 0; binding < vertexInfo.bindings.size(); ++binding) {
MTL::VertexBufferLayoutDescriptor *buffer = MTL::VertexBufferLayoutDescriptor* buffer = bufferLayout->object(binding)->init();
bufferLayout->object(binding + METAL_VERTEXBUFFER_OFFSET)->init();
buffer->setStride(vertexInfo.bindings[binding].stride); buffer->setStride(vertexInfo.bindings[binding].stride);
buffer->setStepRate(1); buffer->setStepRate(1);
switch (vertexInfo.bindings[binding].inputRate) { switch (vertexInfo.bindings[binding].inputRate) {
@@ -72,28 +63,19 @@ PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo createInfo) {
} }
pipelineDescriptor->setVertexDescriptor(vertexDescriptor); pipelineDescriptor->setVertexDescriptor(vertexDescriptor);
pipelineDescriptor->setVertexFunction( pipelineDescriptor->setVertexFunction(createInfo.vertexShader.cast<VertexShader>()->getFunction());
createInfo.vertexShader.cast<VertexShader>()->getFunction());
if (createInfo.fragmentShader != nullptr) { if (createInfo.fragmentShader != nullptr) {
pipelineDescriptor->setFragmentFunction( pipelineDescriptor->setFragmentFunction(createInfo.fragmentShader.cast<FragmentShader>()->getFunction());
createInfo.fragmentShader.cast<FragmentShader>()->getFunction());
} }
pipelineDescriptor->setInputPrimitiveTopology(cast(createInfo.topology)); pipelineDescriptor->setInputPrimitiveTopology(cast(createInfo.topology));
if (createInfo.renderPass->getLayout().depthAttachment.getTexture() != if (createInfo.renderPass->getLayout().depthAttachment.getTexture() != nullptr) {
nullptr) {
pipelineDescriptor->setDepthAttachmentPixelFormat( pipelineDescriptor->setDepthAttachmentPixelFormat(
cast(createInfo.renderPass->getLayout() cast(createInfo.renderPass->getLayout().depthAttachment.getTexture().cast<Texture2D>()->getFormat()));
.depthAttachment.getTexture()
.cast<Texture2D>()
->getFormat()));
} }
pipelineDescriptor->setAlphaToCoverageEnabled( pipelineDescriptor->setAlphaToCoverageEnabled(createInfo.multisampleState.alphaCoverageEnable);
createInfo.multisampleState.alphaCoverageEnable); pipelineDescriptor->setAlphaToOneEnabled(createInfo.multisampleState.alphaToOneEnable);
pipelineDescriptor->setAlphaToOneEnabled(
createInfo.multisampleState.alphaToOneEnable);
pipelineDescriptor->setRasterSampleCount(createInfo.multisampleState.samples); pipelineDescriptor->setRasterSampleCount(createInfo.multisampleState.samples);
pipelineDescriptor->setRasterizationEnabled( pipelineDescriptor->setRasterizationEnabled(!createInfo.rasterizationState.rasterizerDiscardEnable);
!createInfo.rasterizationState.rasterizerDiscardEnable);
uint32 hash = pipelineDescriptor->hash(); uint32 hash = pipelineDescriptor->hash();
@@ -138,12 +120,9 @@ PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo createInfo) {
} }
NS::Error* error; NS::Error* error;
graphicsPipelines[hash] = new GraphicsPipeline( graphicsPipelines[hash] = new GraphicsPipeline(
graphics, type, graphics, type, graphics->getDevice()->newRenderPipelineState(pipelineDescriptor, &error), std::move(createInfo.pipelineLayout));
graphics->getDevice()->newRenderPipelineState(pipelineDescriptor, &error),
std::move(createInfo.pipelineLayout));
if (error) { if (error) {
std::cout << error->localizedDescription()->cString(NS::ASCIIStringEncoding) std::cout << error->localizedDescription()->cString(NS::ASCIIStringEncoding) << std::endl;
<< std::endl;
assert(false); assert(false);
} }
@@ -151,36 +130,24 @@ PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo createInfo) {
return graphicsPipelines[hash]; return graphicsPipelines[hash];
} }
PGraphicsPipeline PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo createInfo) {
PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo createInfo) { MTL::MeshRenderPipelineDescriptor* pipelineDescriptor = MTL::MeshRenderPipelineDescriptor::alloc()->init();
MTL::MeshRenderPipelineDescriptor *pipelineDescriptor =
MTL::MeshRenderPipelineDescriptor::alloc()->init();
pipelineDescriptor->setMeshFunction( pipelineDescriptor->setMeshFunction(createInfo.meshShader.cast<MeshShader>()->getFunction());
createInfo.meshShader.cast<MeshShader>()->getFunction());
if (createInfo.taskShader != nullptr) { if (createInfo.taskShader != nullptr) {
pipelineDescriptor->setObjectFunction( pipelineDescriptor->setObjectFunction(createInfo.taskShader.cast<TaskShader>()->getFunction());
createInfo.taskShader.cast<TaskShader>()->getFunction());
} }
if (createInfo.fragmentShader != nullptr) { if (createInfo.fragmentShader != nullptr) {
pipelineDescriptor->setFragmentFunction( pipelineDescriptor->setFragmentFunction(createInfo.fragmentShader.cast<FragmentShader>()->getFunction());
createInfo.fragmentShader.cast<FragmentShader>()->getFunction());
} }
if (createInfo.renderPass->getLayout().depthAttachment.getTexture() != if (createInfo.renderPass->getLayout().depthAttachment.getTexture() != nullptr) {
nullptr) {
pipelineDescriptor->setDepthAttachmentPixelFormat( pipelineDescriptor->setDepthAttachmentPixelFormat(
cast(createInfo.renderPass->getLayout() cast(createInfo.renderPass->getLayout().depthAttachment.getTexture().cast<Texture2D>()->getFormat()));
.depthAttachment.getTexture()
.cast<Texture2D>()
->getFormat()));
} }
pipelineDescriptor->setAlphaToCoverageEnabled( pipelineDescriptor->setAlphaToCoverageEnabled(createInfo.multisampleState.alphaCoverageEnable);
createInfo.multisampleState.alphaCoverageEnable); pipelineDescriptor->setAlphaToOneEnabled(createInfo.multisampleState.alphaToOneEnable);
pipelineDescriptor->setAlphaToOneEnabled(
createInfo.multisampleState.alphaToOneEnable);
pipelineDescriptor->setRasterSampleCount(createInfo.multisampleState.samples); pipelineDescriptor->setRasterSampleCount(createInfo.multisampleState.samples);
pipelineDescriptor->setRasterizationEnabled( pipelineDescriptor->setRasterizationEnabled(!createInfo.rasterizationState.rasterizerDiscardEnable);
!createInfo.rasterizationState.rasterizerDiscardEnable);
uint32 hash = pipelineDescriptor->hash(); uint32 hash = pipelineDescriptor->hash();
@@ -191,16 +158,18 @@ PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo createInfo) {
MTL::AutoreleasedRenderPipelineReflection reflection; MTL::AutoreleasedRenderPipelineReflection reflection;
graphicsPipelines[hash] = new GraphicsPipeline( graphicsPipelines[hash] = new GraphicsPipeline(
graphics, MTL::PrimitiveTypeTriangle, graphics, MTL::PrimitiveTypeTriangle,
graphics->getDevice()->newRenderPipelineState( graphics->getDevice()->newRenderPipelineState(pipelineDescriptor, MTL::PipelineOptionNone, &reflection, &error),
pipelineDescriptor, MTL::PipelineOptionNone, &reflection, &error),
std::move(createInfo.pipelineLayout)); std::move(createInfo.pipelineLayout));
if (error) {
std::cout << error->debugDescription()->utf8String() << std::endl;
}
pipelineDescriptor->release(); pipelineDescriptor->release();
return graphicsPipelines[hash]; return graphicsPipelines[hash];
} }
PComputePipeline PComputePipeline PipelineCache::createPipeline(Gfx::ComputePipelineCreateInfo createInfo) {
PipelineCache::createPipeline(Gfx::ComputePipelineCreateInfo createInfo) {
PComputeShader shader = createInfo.computeShader.cast<ComputeShader>(); PComputeShader shader = createInfo.computeShader.cast<ComputeShader>();
uint32 hash = shader->getShaderHash(); uint32 hash = shader->getShaderHash();
if (computePipelines.contains(hash)) { if (computePipelines.contains(hash)) {
@@ -208,10 +177,7 @@ PipelineCache::createPipeline(Gfx::ComputePipelineCreateInfo createInfo) {
} }
NS::Error* error; NS::Error* error;
computePipelines[hash] = computePipelines[hash] = new ComputePipeline(graphics, graphics->getDevice()->newComputePipelineState(shader->getFunction(), &error),
new ComputePipeline(graphics,
graphics->getDevice()->newComputePipelineState(
shader->getFunction(), &error),
std::move(createInfo.pipelineLayout)); std::move(createInfo.pipelineLayout));
assert(!error); assert(!error);
return computePipelines[hash]; return computePipelines[hash];
+1 -7
View File
@@ -40,16 +40,10 @@ class TimestampQuery : public Gfx::TimestampQuery, public QueryPool {
public: public:
TimestampQuery(PGraphics graphics, const std::string& name, uint32 numTimestamps); TimestampQuery(PGraphics graphics, const std::string& name, uint32 numTimestamps);
virtual ~TimestampQuery(); virtual ~TimestampQuery();
virtual void begin() override;
virtual void write(Gfx::SePipelineStageFlagBits stage, const std::string& name = "") override; virtual void write(Gfx::SePipelineStageFlagBits stage, const std::string& name = "") override;
virtual void end() override; virtual Gfx::Timestamp getResult() override;
virtual Array<Gfx::Timestamp> getResults() override;
private: private:
uint64 wrapping = 0;
uint64 lastMeasure = 0;
uint32 numTimestamps = 0;
uint32 currentTimestamp = 0;
Array<std::string> pendingTimestamps; Array<std::string> pendingTimestamps;
}; };
DEFINE_REF(TimestampQuery) DEFINE_REF(TimestampQuery)
+14 -26
View File
@@ -4,28 +4,23 @@
#include "Containers/Array.h" #include "Containers/Array.h"
#include "Enums.h" #include "Enums.h"
#include "Graphics.h" #include "Graphics.h"
#include "Graphics/Query.h"
#include <vulkan/vulkan_core.h> #include <vulkan/vulkan_core.h>
using namespace Seele; using namespace Seele;
using namespace Seele::Metal; using namespace Seele::Metal;
QueryPool::QueryPool(PGraphics graphics, const std::string& name) QueryPool::QueryPool(PGraphics graphics, const std::string&) : graphics(graphics) {}
: graphics(graphics) {
}
QueryPool::~QueryPool() {} QueryPool::~QueryPool() {}
void QueryPool::begin() { void QueryPool::begin() {}
}
void QueryPool::end() { void QueryPool::end() {}
}
void QueryPool::getQueryResults(Array<uint64>& results) { void QueryPool::getQueryResults(Array<uint64>&) {}
}
OcclusionQuery::OcclusionQuery(PGraphics graphics, const std::string& name) OcclusionQuery::OcclusionQuery(PGraphics graphics, const std::string& name) : QueryPool(graphics, name) {}
: QueryPool(graphics, name) {}
OcclusionQuery::~OcclusionQuery() {} OcclusionQuery::~OcclusionQuery() {}
@@ -41,8 +36,7 @@ Gfx::OcclusionResult OcclusionQuery::getResults() {
}; };
} }
PipelineStatisticsQuery::PipelineStatisticsQuery(PGraphics graphics, const std::string& name) PipelineStatisticsQuery::PipelineStatisticsQuery(PGraphics graphics, const std::string& name) : QueryPool(graphics, name) {}
: QueryPool(graphics, name) {}
PipelineStatisticsQuery::~PipelineStatisticsQuery() {} PipelineStatisticsQuery::~PipelineStatisticsQuery() {}
@@ -66,21 +60,15 @@ Gfx::PipelineStatisticsResult PipelineStatisticsQuery::getResults() {
}; };
} }
TimestampQuery::TimestampQuery(PGraphics graphics, const std::string& name, uint32 numTimestamps) TimestampQuery::TimestampQuery(PGraphics graphics, const std::string& name, uint32) : QueryPool(graphics, name) {}
: QueryPool(graphics, name), numTimestamps(numTimestamps) {
}
TimestampQuery::~TimestampQuery() {} TimestampQuery::~TimestampQuery() {}
void TimestampQuery::begin() { void TimestampQuery::write(Gfx::SePipelineStageFlagBits, const std::string&) {}
currentTimestamp = 0;
}
void TimestampQuery::write(Gfx::SePipelineStageFlagBits stage, const std::string& name) { Gfx::Timestamp TimestampQuery::getResult() {
} return Gfx::Timestamp{
.name = "Test",
void TimestampQuery::end() { .time = 0,
} };
Array<Gfx::Timestamp> TimestampQuery::getResults() {
} }
+3 -3
View File
@@ -25,10 +25,10 @@ Shader::~Shader() {
void Shader::create(const ShaderCreateInfo& createInfo) { void Shader::create(const ShaderCreateInfo& createInfo) {
auto [kernelBlob, entryPoint] = generateShader(createInfo); auto [kernelBlob, entryPoint] = generateShader(createInfo);
std::ofstream test("test.metal");
test.write((char*)kernelBlob->getBufferPointer(), kernelBlob->getBufferSize());
test.close();
hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32()); hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32());
std::ofstream test("test.metal");
test.write((const char*)kernelBlob->getBufferPointer(), kernelBlob->getBufferSize());
test.close();
NS::Error* error; NS::Error* error;
MTL::CompileOptions* options = MTL::CompileOptions::alloc()->init(); MTL::CompileOptions* options = MTL::CompileOptions::alloc()->init();
library = graphics->getDevice()->newLibrary(NS::String::string((char*)kernelBlob->getBufferPointer(), NS::ASCIIStringEncoding), options, library = graphics->getDevice()->newLibrary(NS::String::string((char*)kernelBlob->getBufferPointer(), NS::ASCIIStringEncoding), options,
+4 -1
View File
@@ -88,7 +88,10 @@ void TextureBase::generateMipmaps() { handle->generateMipmaps(); }
Texture2D::Texture2D(PGraphics graphics, const TextureCreateInfo& createInfo, MTL::Texture* existingImage) Texture2D::Texture2D(PGraphics graphics, const TextureCreateInfo& createInfo, MTL::Texture* existingImage)
: Gfx::Texture2D(graphics->getFamilyMapping()), : Gfx::Texture2D(graphics->getFamilyMapping()),
TextureBase(graphics, createInfo.elements > 1 ? MTL::TextureType2DArray : MTL::TextureType2D, createInfo, existingImage) {} TextureBase(graphics,
createInfo.elements > 1 ? (createInfo.samples > 1 ? MTL::TextureType2DMultisampleArray : MTL::TextureType2DArray)
: (createInfo.samples > 1 ? MTL::TextureType2DMultisample : MTL::TextureType2D),
createInfo, existingImage) {}
Texture2D::~Texture2D() {} Texture2D::~Texture2D() {}
+4
View File
@@ -90,6 +90,10 @@ Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo) : graphic
metalLayer.drawableSize = CGSizeMake(createInfo.width, createInfo.height); metalLayer.drawableSize = CGSizeMake(createInfo.width, createInfo.height);
metalWindow.contentView.layer = metalLayer; metalWindow.contentView.layer = metalLayer;
metalWindow.contentView.wantsLayer = YES; metalWindow.contentView.wantsLayer = YES;
framebufferFormat = Gfx::SE_FORMAT_R8G8B8A8_UNORM;
drawable = (__bridge CA::MetalDrawable*)[metalLayer nextDrawable];
createBackBuffer();
} }
Window::~Window() { glfwDestroyWindow(static_cast<GLFWwindow*>(windowHandle)); } Window::~Window() { glfwDestroyWindow(static_cast<GLFWwindow*>(windowHandle)); }
@@ -533,13 +533,13 @@ void WaterRenderer::updateFFTDescriptor() {
computeSet = computeLayout->allocateDescriptorSet(); computeSet = computeLayout->allocateDescriptorSet();
computeSet->updateBuffer(0, paramsBuffer); computeSet->updateBuffer(0, paramsBuffer);
computeSet->updateTexture(1, 0, Gfx::PTexture2D(spectrumTextures)); computeSet->updateTexture(1, Gfx::PTexture2D(spectrumTextures));
computeSet->updateTexture(2, 0, Gfx::PTexture2D(initialSpectrumTextures)); computeSet->updateTexture(2, Gfx::PTexture2D(initialSpectrumTextures));
computeSet->updateTexture(3, 0, Gfx::PTexture2D(displacementTextures)); computeSet->updateTexture(3, Gfx::PTexture2D(displacementTextures));
computeSet->updateTexture(4, 0, Gfx::PTexture2D(slopeTextures)); computeSet->updateTexture(4, Gfx::PTexture2D(slopeTextures));
computeSet->updateTexture(5, 0, Gfx::PTexture2D(boyancyData)); computeSet->updateTexture(5, Gfx::PTexture2D(boyancyData));
computeSet->updateBuffer(6, 0, spectrumBuffer); computeSet->updateBuffer(6, spectrumBuffer);
computeSet->updateSampler(7, 0, linearRepeatSampler); computeSet->updateSampler(7, linearRepeatSampler);
computeSet->writeChanges(); computeSet->writeChanges();
} }
+6 -3
View File
@@ -1,6 +1,7 @@
#include "StaticMeshVertexData.h" #include "StaticMeshVertexData.h"
#include "Graphics.h" #include "Graphics.h"
#include "Graphics/Enums.h" #include "Graphics/Enums.h"
#include "Graphics/VertexData.h"
#include "Mesh.h" #include "Mesh.h"
#include <fstream> #include <fstream>
@@ -133,11 +134,13 @@ void StaticMeshVertexData::init(Gfx::PGraphics _graphics) {
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 2, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER}); descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 2, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 3, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER}); descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 3, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 4, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER}); descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 4, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
for(uint i = 0; i < MAX_TEXCOORDS; ++i)
{
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 5, .binding = 5 + i,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
.descriptorCount = MAX_TEXCOORDS,
}); });
}
descriptorLayout->create(); descriptorLayout->create();
descriptorSet = descriptorLayout->allocateDescriptorSet(); descriptorSet = descriptorLayout->allocateDescriptorSet();
} }
@@ -223,7 +226,7 @@ void StaticMeshVertexData::updateBuffers() {
descriptorSet->updateBuffer(3, biTangents); descriptorSet->updateBuffer(3, biTangents);
descriptorSet->updateBuffer(4, colors); descriptorSet->updateBuffer(4, colors);
for (size_t i = 0; i < MAX_TEXCOORDS; ++i) { for (size_t i = 0; i < MAX_TEXCOORDS; ++i) {
descriptorSet->updateBuffer(5, i, texCoords[i]); descriptorSet->updateBuffer(5 + i, texCoords[i]);
} }
descriptorSet->writeChanges(); descriptorSet->writeChanges();
} }
+1 -1
View File
@@ -274,7 +274,7 @@ MeshId VertexData::allocateVertexData(uint64 numVertices) {
return res; return res;
} }
void VertexData::serializeMesh(MeshId id, uint64 numVertices, ArchiveBuffer& buffer) { void VertexData::serializeMesh(MeshId id, uint64, ArchiveBuffer& buffer) {
std::unique_lock l(vertexDataLock); std::unique_lock l(vertexDataLock);
Array<Meshlet> out; Array<Meshlet> out;
MeshData data = meshData[id]; MeshData data = meshData[id];
+4 -4
View File
@@ -78,8 +78,8 @@ class RenderCommand : public Gfx::RenderCommand {
virtual void setViewport(Gfx::PViewport viewport) override; virtual void setViewport(Gfx::PViewport viewport) override;
virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) override; virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) override;
virtual void bindPipeline(Gfx::PRayTracingPipeline pipeline) override; virtual void bindPipeline(Gfx::PRayTracingPipeline pipeline) override;
virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array<uint32> dynamicOffsets) override; virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet) override;
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets, Array<uint32> dynamicOffsets) override; virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets) override;
virtual void bindVertexBuffer(const Array<Gfx::PVertexBuffer>& buffers) override; virtual void bindVertexBuffer(const Array<Gfx::PVertexBuffer>& buffers) override;
virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) override; virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) override;
virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override; virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override;
@@ -114,8 +114,8 @@ class ComputeCommand : public Gfx::ComputeCommand {
void reset(); void reset();
bool isReady(); bool isReady();
virtual void bindPipeline(Gfx::PComputePipeline pipeline) override; virtual void bindPipeline(Gfx::PComputePipeline pipeline) override;
virtual void bindDescriptor(Gfx::PDescriptorSet set, Array<uint32> dynamicOffsets) override; virtual void bindDescriptor(Gfx::PDescriptorSet set) override;
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets, Array<uint32> dynamicOffsets) override; virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) override;
virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override; virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override;
virtual void dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) override; virtual void dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) override;
+14 -92
View File
@@ -163,7 +163,7 @@ DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner)
graphics(graphics), owner(owner) { graphics(graphics), owner(owner) {
boundResources.resize(owner->getLayout()->getBindings().size()); boundResources.resize(owner->getLayout()->getBindings().size());
for (uint32 i = 0; i < boundResources.size(); ++i) { for (uint32 i = 0; i < boundResources.size(); ++i) {
boundResources[i].resize(owner->getLayout()->getBindings()[i].descriptorCount); if(owner->getLayout()->getBindings()[i].descriptorCount > 1) std::abort();
} }
} }
@@ -171,7 +171,7 @@ DescriptorSet::~DescriptorSet() {}
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer) { void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer) {
PUniformBuffer vulkanBuffer = uniformBuffer.cast<UniformBuffer>(); PUniformBuffer vulkanBuffer = uniformBuffer.cast<UniformBuffer>();
if (boundResources[binding][0] == vulkanBuffer->getAlloc()) { if (boundResources[binding] == vulkanBuffer->getAlloc()) {
return; return;
} }
@@ -192,12 +192,12 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBu
.pBufferInfo = &bufferInfos.back(), .pBufferInfo = &bufferInfos.back(),
}); });
boundResources[binding][0] = vulkanBuffer->getAlloc(); boundResources[binding] = vulkanBuffer->getAlloc();
} }
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer shaderBuffer) { void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer shaderBuffer) {
PShaderBuffer vulkanBuffer = shaderBuffer.cast<ShaderBuffer>(); PShaderBuffer vulkanBuffer = shaderBuffer.cast<ShaderBuffer>();
if (boundResources[binding][0] == vulkanBuffer->getAlloc()) { if (boundResources[binding] == vulkanBuffer->getAlloc()) {
return; return;
} }
@@ -217,12 +217,12 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer shaderBuff
.pBufferInfo = &bufferInfos.back(), .pBufferInfo = &bufferInfos.back(),
}); });
boundResources[binding][0] = vulkanBuffer->getAlloc(); boundResources[binding] = vulkanBuffer->getAlloc();
} }
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PIndexBuffer indexBuffer) { void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PIndexBuffer indexBuffer) {
PIndexBuffer vulkanBuffer = indexBuffer.cast<IndexBuffer>(); PIndexBuffer vulkanBuffer = indexBuffer.cast<IndexBuffer>();
if (boundResources[binding][0] == vulkanBuffer->getAlloc()) { if (boundResources[binding] == vulkanBuffer->getAlloc()) {
return; return;
} }
@@ -242,38 +242,12 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PIndexBuffer indexBuffer
.pBufferInfo = &bufferInfos.back(), .pBufferInfo = &bufferInfos.back(),
}); });
boundResources[binding][0] = vulkanBuffer->getAlloc(); boundResources[binding] = vulkanBuffer->getAlloc();
}
void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer shaderBuffer) {
PShaderBuffer vulkanBuffer = shaderBuffer.cast<ShaderBuffer>();
if (boundResources[binding][index] == vulkanBuffer->getAlloc()) {
return;
}
bufferInfos.add(VkDescriptorBufferInfo{
.buffer = vulkanBuffer->getHandle(),
.offset = 0,
.range = vulkanBuffer->getSize(),
});
writeDescriptors.add(VkWriteDescriptorSet{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = nullptr,
.dstSet = setHandle,
.dstBinding = binding,
.dstArrayElement = index,
.descriptorCount = 1,
.descriptorType = cast(layout->getBindings()[binding].descriptorType),
.pBufferInfo = &bufferInfos.back(),
});
boundResources[binding][index] = vulkanBuffer->getAlloc();
} }
void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState) { void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState) {
PSampler vulkanSampler = samplerState.cast<Sampler>(); PSampler vulkanSampler = samplerState.cast<Sampler>();
if (boundResources[binding][0] == vulkanSampler->getHandle()) { if (boundResources[binding] == vulkanSampler->getHandle()) {
return; return;
} }
@@ -294,38 +268,12 @@ void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState)
.pImageInfo = &imageInfos.back(), .pImageInfo = &imageInfos.back(),
}); });
boundResources[binding][0] = vulkanSampler->getHandle(); boundResources[binding] = vulkanSampler->getHandle();
}
void DescriptorSet::updateSampler(uint32_t binding, uint32 dstArrayIndex, Gfx::PSampler samplerState) {
PSampler vulkanSampler = samplerState.cast<Sampler>();
if (boundResources[binding][dstArrayIndex] == vulkanSampler->getHandle()) {
return;
}
imageInfos.add(VkDescriptorImageInfo{
.sampler = vulkanSampler->getSampler(),
.imageView = VK_NULL_HANDLE,
.imageLayout = VK_IMAGE_LAYOUT_UNDEFINED,
});
writeDescriptors.add(VkWriteDescriptorSet{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = nullptr,
.dstSet = setHandle,
.dstBinding = binding,
.dstArrayElement = dstArrayIndex,
.descriptorCount = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER,
.pImageInfo = &imageInfos.back(),
});
boundResources[binding][dstArrayIndex] = vulkanSampler->getHandle();
} }
void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler samplerState) { void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler samplerState) {
TextureBase* vulkanTexture = texture.cast<TextureBase>().getHandle(); TextureBase* vulkanTexture = texture.cast<TextureBase>().getHandle();
if (boundResources[binding][0] == vulkanTexture->getHandle()) { if (boundResources[binding] == vulkanTexture->getHandle()) {
return; return;
} }
@@ -346,33 +294,7 @@ void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::
.pImageInfo = &imageInfos.back(), .pImageInfo = &imageInfos.back(),
}); });
boundResources[binding][0] = vulkanTexture->getHandle(); boundResources[binding] = vulkanTexture->getHandle();
}
void DescriptorSet::updateTexture(uint32 binding, uint32 dstArrayIndex, Gfx::PTexture texture) {
TextureBase* vulkanTexture = texture.cast<TextureBase>().getHandle();
if (boundResources[binding][dstArrayIndex] == vulkanTexture->getHandle()) {
return;
}
// It is assumed that the image is in the correct layout
imageInfos.add(VkDescriptorImageInfo{
.sampler = VK_NULL_HANDLE,
.imageView = vulkanTexture->getView(),
.imageLayout = cast(vulkanTexture->getLayout()),
});
writeDescriptors.add(VkWriteDescriptorSet{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = nullptr,
.dstSet = setHandle,
.dstBinding = binding,
.dstArrayElement = dstArrayIndex,
.descriptorCount = 1,
.descriptorType = cast(layout->getBindings()[binding].descriptorType),
.pImageInfo = &imageInfos.back(),
});
boundResources[binding][dstArrayIndex] = vulkanTexture->getHandle();
} }
void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture2D> textures) { void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture2D> textures) {
@@ -380,7 +302,7 @@ void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture2D>
uint32 arrayElement = 0; uint32 arrayElement = 0;
for (auto& gfxTexture : textures) { for (auto& gfxTexture : textures) {
TextureBase* vulkanTexture = gfxTexture.cast<TextureBase>().getHandle(); TextureBase* vulkanTexture = gfxTexture.cast<TextureBase>().getHandle();
if (boundResources[binding][arrayElement] == vulkanTexture->getHandle()) { if (boundResources[binding+arrayElement] == vulkanTexture->getHandle()) {
continue; continue;
} }
imageInfos.add(VkDescriptorImageInfo{ imageInfos.add(VkDescriptorImageInfo{
@@ -389,7 +311,7 @@ void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture2D>
.imageLayout = cast(vulkanTexture->getLayout()), .imageLayout = cast(vulkanTexture->getLayout()),
}); });
boundResources[binding][arrayElement] = vulkanTexture->getHandle(); boundResources[binding+arrayElement] = vulkanTexture->getHandle();
writeDescriptors.add(VkWriteDescriptorSet{ writeDescriptors.add(VkWriteDescriptorSet{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = nullptr, .pNext = nullptr,
@@ -408,7 +330,7 @@ void DescriptorSet::updateSamplerArray(uint32_t binding, Array<Gfx::PSampler> sa
uint32 arrayElement = 0; uint32 arrayElement = 0;
for (auto& gfxSampler : samplers) { for (auto& gfxSampler : samplers) {
PSampler vulkanSampler = gfxSampler.cast<Sampler>(); PSampler vulkanSampler = gfxSampler.cast<Sampler>();
if (boundResources[binding][arrayElement] == vulkanSampler->getHandle()) { if (boundResources[binding+arrayElement] == vulkanSampler->getHandle()) {
continue; continue;
} }
imageInfos.add(VkDescriptorImageInfo{ imageInfos.add(VkDescriptorImageInfo{
+1 -4
View File
@@ -51,11 +51,8 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
virtual void updateBuffer(uint32 binding, Gfx::PUniformBuffer uniformBuffer) override; virtual void updateBuffer(uint32 binding, Gfx::PUniformBuffer uniformBuffer) override;
virtual void updateBuffer(uint32 binding, Gfx::PShaderBuffer uniformBuffer) override; virtual void updateBuffer(uint32 binding, Gfx::PShaderBuffer uniformBuffer) override;
virtual void updateBuffer(uint32 binding, Gfx::PIndexBuffer uniformBuffer) override; virtual void updateBuffer(uint32 binding, Gfx::PIndexBuffer uniformBuffer) override;
virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) override;
virtual void updateSampler(uint32 binding, Gfx::PSampler samplerState) override; virtual void updateSampler(uint32 binding, Gfx::PSampler samplerState) override;
virtual void updateSampler(uint32 binding, uint32 dstArrayIndex, Gfx::PSampler samplerState) override;
virtual void updateTexture(uint32 binding, Gfx::PTexture texture, Gfx::PSampler sampler = nullptr) override; virtual void updateTexture(uint32 binding, Gfx::PTexture texture, Gfx::PSampler sampler = nullptr) override;
virtual void updateTexture(uint32 binding, uint32 dstArrayIndex, Gfx::PTexture texture) override;
virtual void updateTextureArray(uint32 binding, Array<Gfx::PTexture2D> texture) override; virtual void updateTextureArray(uint32 binding, Array<Gfx::PTexture2D> texture) override;
virtual void updateSamplerArray(uint32 binding, Array<Gfx::PSampler> samplers) override; virtual void updateSamplerArray(uint32 binding, Array<Gfx::PSampler> samplers) override;
virtual void updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS as) override; virtual void updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS as) override;
@@ -71,7 +68,7 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
// since the layout is fixed, trying to bind a texture to a buffer // since the layout is fixed, trying to bind a texture to a buffer
// would not work anyways, so casts should be safe // would not work anyways, so casts should be safe
// Array<void*> cachedData; // Array<void*> cachedData;
Array<Array<PCommandBoundResource>> boundResources; Array<PCommandBoundResource> boundResources;
VkDescriptorSet setHandle; VkDescriptorSet setHandle;
PGraphics graphics; PGraphics graphics;
PDescriptorPool owner; PDescriptorPool owner;
+7 -6
View File
@@ -116,15 +116,16 @@ void Seele::beginCompilation(const ShaderCompilationInfo& info, SlangCompileTarg
for (size_t i = 0; i < signature->getParameterCount(); ++i) { for (size_t i = 0; i < signature->getParameterCount(); ++i) {
auto param = signature->getParameterByIndex(i); auto param = signature->getParameterByIndex(i);
layout->addMapping(param->getName(), param->getBindingIndex()); layout->addMapping(param->getName(), param->getBindingIndex());
std::cout << param->getName() << ": " << param->getBindingIndex() << std::endl;
} }
// workaround // workaround
layout->addMapping("pVertexData", 1); //layout->addMapping("pVertexData", 1);
layout->addMapping("pMaterial", 4); //layout->addMapping("pMaterial", 4);
layout->addMapping("pLightEnv", 3); //layout->addMapping("pLightEnv", 3);
layout->addMapping("pRayTracingParams", 5); //layout->addMapping("pRayTracingParams", 5);
layout->addMapping("pScene", 2); //layout->addMapping("pScene", 2);
layout->addMapping("pWaterMaterial", 1); //layout->addMapping("pWaterMaterial", 1);
} }
Pair<Slang::ComPtr<slang::IBlob>, std::string> Seele::generateShader(const ShaderCreateInfo& createInfo) { Pair<Slang::ComPtr<slang::IBlob>, std::string> Seele::generateShader(const ShaderCreateInfo& createInfo) {
+4 -3
View File
@@ -76,15 +76,16 @@ void Material::updateDescriptor() {
Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
layout->reset(); layout->reset();
set = layout->allocateDescriptorSet(); set = layout->allocateDescriptorSet();
set->updateBuffer(0, floatBuffer); uint32 binding = 0;
set->updateBuffer(binding++, floatBuffer);
for (uint32 i = 0; i < textures.size(); ++i) { for (uint32 i = 0; i < textures.size(); ++i) {
if (textures[i] != nullptr) { if (textures[i] != nullptr) {
set->updateTexture(1, i, textures[i]); set->updateTexture(binding++, textures[i]);
} }
} }
for (uint32 i = 0; i < samplers.size(); ++i) { for (uint32 i = 0; i < samplers.size(); ++i) {
if (samplers[i] != nullptr) { if (samplers[i] != nullptr) {
set->updateSampler(2, i, samplers[i]); set->updateSampler(binding++, samplers[i]);
} }
} }
set->writeChanges(); set->writeChanges();
+2 -2
View File
@@ -27,8 +27,8 @@ template <typename... Components> class ComponentSystem : public SystemBase {
setupView((getDependencies<Components>() | ...)); setupView((getDependencies<Components>() | ...));
} }
virtual void update() override {} virtual void update() override {}
virtual void update(Components&... components) {} virtual void update(Components&...) {}
virtual void update(entt::entity id, Components&... components) {} virtual void update(entt::entity, Components&...) {}
}; };
} // namespace System } // namespace System
} // namespace Seele } // namespace Seele
+1 -1
View File
@@ -28,7 +28,7 @@ GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreate
renderGraph.addPass(new VisibilityPass(graphics, scene)); renderGraph.addPass(new VisibilityPass(graphics, scene));
renderGraph.addPass(new LightCullingPass(graphics, scene)); renderGraph.addPass(new LightCullingPass(graphics, scene));
renderGraph.addPass(new BasePass(graphics, scene)); renderGraph.addPass(new BasePass(graphics, scene));
//renderGraph.addPass(new RayTracingPass(graphics, scene)); renderGraph.addPass(new RayTracingPass(graphics, scene));
renderGraph.setViewport(viewport); renderGraph.setViewport(viewport);
renderGraph.createRenderPass(); renderGraph.createRenderPass();
} }