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.dereferencePointers": true,
"lldb.consoleMode": "commands",
"cmake.generator": "Ninja",
"cmake.generator": "Xcode",
"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[2] = computePlane(origin, corners[0], corners[1]);
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;
}
}
+1 -1
View File
@@ -17,7 +17,7 @@ Params vertexMain(
DebugVertex vert
){
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;
return result;
}
+5 -5
View File
@@ -30,7 +30,7 @@ groupshared bool meshVisible;
ParameterBlock<DepthData> pDepthAttachment;
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
int2 screenCornerMin = mipDimensions;
int2 screenCornerMax = int2(0, 0);
@@ -91,14 +91,14 @@ void taskMain(
p.instanceId = pOffsets.instanceOffset + groupID;
p.meshletOffset = mesh.meshletOffset;
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;
const float offset = 0.0f;
float3 corners[4] = {
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(offset, pViewParams.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.x - offset, 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.c.screenDimensions - float2(offset, offset), -1.0f, 1.0f)).xyz
};
viewFrustum.sides[0] = computePlane(origin, corners[2], corners[0]);
viewFrustum.sides[1] = computePlane(origin, corners[1], corners[3]);
+2 -2
View File
@@ -47,9 +47,9 @@ void reduceLevel(
void sourceCopy(
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;
}
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;
oLightCount = 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();
+2 -2
View File
@@ -73,10 +73,10 @@ VertexShaderOutput vertexMain(
};
VertexShaderOutput output;
float3x3 cameraRotation = float3x3(pViewParams.viewMatrix);
float3x3 cameraRotation = float3x3(pViewParams.c.viewMatrix);
float4 worldPos = float4(mul(cameraRotation, vertices[vertexIndex]), 1.0f);
//clip(dot(worldPos, clipPlane));
output.clipPos = mul(pViewParams.projectionMatrix, worldPos);
output.clipPos = mul(pViewParams.c.projectionMatrix, worldPos);
output.texCoords = normalize(vertices[vertexIndex]);
return output;
}
+1 -1
View File
@@ -66,7 +66,7 @@ VertexOutput vertexMain(VertexInput input)
float4 vertex = coordinates[input.vertexId];
VertexOutput output;
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;
return output;
}
+2 -2
View File
@@ -34,7 +34,7 @@ void meshMain(
out vertices WaterVertex vertices[TILE_VERTS],
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);
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);
float lodDisplacement = 0;
float3 camPos = pViewParams.cameraPos_WS.xyz;
float3 camPos = pViewParams.c.cameraPos_WS.xyz;
float cameraDistance = distance(worldPos, camPos);
float threshold = 0;
if(params.numMeshes == 3)
+1 -1
View File
@@ -23,7 +23,7 @@ float Beckmann(float ndoth, float roughness) {
[shader("pixel")]
float4 fragmentMain(WaterVertex vert) : SV_TARGET {
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);
float depth = vert.depth;
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.maxCorner = float3(tile.location.x + 1, tile.height, tile.location.y + 1) * tile.extent;
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;
uint numMeshes = groupID.y + 1;
+1 -1
View File
@@ -67,7 +67,7 @@ struct AABB
{
float4 clipCorner = mul(mvp, corners[i]);
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));
screenCornerMax = int2(max(screenCornerMax.x, screenCoords.x), max(screenCornerMax.y, screenCoords.y));
maxDepth = max(maxDepth, screenCorner.z);
+11 -7
View File
@@ -12,9 +12,13 @@ struct ViewParameter
float4x4 inverseProjection;
float4 cameraPos_WS;
float2 screenDimensions;
}
layout(set=0)
ParameterBlock<ViewParameter> pViewParams;
};
struct ViewParamWrapper
{
ParameterBlock<ViewParameter> c;
};
layout(set = 0)
ParameterBlock<ViewParamWrapper> pViewParams;
float4 worldToModel(float4x4 inverseTransform, float4 world)
{
@@ -27,7 +31,7 @@ float4 worldToModel(float4x4 inverseTransform, float4 world)
float4 viewToWorld(float4 view)
{
float4 world = mul(pViewParams.inverseViewMatrix, view);
float4 world = mul(pViewParams.c.inverseViewMatrix, view);
world = world / world.w;
@@ -43,7 +47,7 @@ float4 viewToModel(float4x4 inverseTransform, float4 view)
float4 clipToView(float4 clip)
{
float4 view = mul(pViewParams.inverseProjection, clip);
float4 view = mul(pViewParams.c.inverseProjection, clip);
view = view / view.w;
@@ -59,7 +63,7 @@ float4 clipToWorld(float4 clip)
float4 screenToView(float4 screen)
{
float2 texCoord = screen.xy / pViewParams.screenDimensions;
float2 texCoord = screen.xy / pViewParams.c.screenDimensions;
// Convert to clip space
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 pz = 0 - 1;
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
+7 -2
View File
@@ -6,6 +6,11 @@ struct DispatchParams
uint pad0;
uint3 numThreads;
uint pad1;
RWStructuredBuffer<Frustum> frustums;
};
struct DispatchParamWrapper
{
ParameterBlock<DispatchParams> p;
RWStructuredBuffer<Frustum> frustums;
}
ParameterBlock<DispatchParams> pDispatchParams;
ParameterBlock<DispatchParamWrapper> pDispatchParams;
+3 -6
View File
@@ -21,7 +21,6 @@ struct FragmentParameter
{
float4 position_CS : SV_Position;
#ifndef POS_ONLY
float3 cameraPos_WS: POSITION0;
float3 normal_WS : NORMAL0;
float3 tangent_WS : TANGENT0;
float3 biTangent_WS : TANGENT1;
@@ -52,7 +51,7 @@ struct FragmentParameter
float3x3 tbn = float3x3(normalize(tangent_WS), normalize(biTangent_WS), normalize(normal_WS));
result.tbn = tbn;
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);
return result;
}
@@ -67,7 +66,6 @@ struct FragmentParameter
FragmentParameter result;
result.position_CS = f0.position_CS * barycentricCoords.x + f1.position_CS * barycentricCoords.y + f2.position_CS * barycentricCoords.z;
#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.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;
@@ -104,8 +102,8 @@ struct VertexAttributes
{
float4 modelPos = float4(position_MS, 1);
float4 worldPos = mul(transformMatrix, modelPos);
float4 viewPos = mul(pViewParams.viewMatrix, worldPos);
float4 clipPos = mul(pViewParams.projectionMatrix, viewPos);
float4 viewPos = mul(pViewParams.c.viewMatrix, worldPos);
float4 clipPos = mul(pViewParams.c.projectionMatrix, viewPos);
FragmentParameter result;
result.position_CS = clipPos;
#ifndef POS_ONLY
@@ -113,7 +111,6 @@ struct VertexAttributes
float3 T = mul(normalMatrix, tangent_MS);
float3 N = mul(normalMatrix, normal_MS);
float3 B = mul(normalMatrix, biTangent_MS);
result.cameraPos_WS = pViewParams.cameraPos_WS.xyz;
result.normal_WS = N;
result.tangent_WS = T;
result.biTangent_WS = B;
+10 -10
View File
@@ -20,8 +20,8 @@ struct MeshData
uint32_t numIndices;
};
static const uint32_t MAX_VERTICES = 256;
static const uint32_t MAX_PRIMITIVES = 256;
static const uint32_t MAX_VERTICES = 64;
static const uint32_t MAX_PRIMITIVES = 126;
static const uint32_t MAX_MESHLETS_PER_INSTANCE = 2048;
struct InstanceData
@@ -39,19 +39,19 @@ struct MeshletCullingInfo
}
};
struct DrawCallOffsets
cbuffer DrawCallOffsets
{
uint instanceOffset;
uint textureOffset;
uint samplerOffset;
uint floatOffset;
};
#ifdef RAY_TRACING
layout(shaderRecordEXT)
#else
layout(push_constant)
#endif
ConstantBuffer<DrawCallOffsets> pOffsets;
} pOffsets;
//#ifdef RAY_TRACING
//layout(shaderRecordEXT)
//#else
//layout(push_constant)
//#endif
//ConstantBuffer<DrawCallOffsets> pOffsets;
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 inUV = pixelCenter / float2(LaunchSize.xy);
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.Origin = mul(pViewParams.inverseViewMatrix, float4(0, 0, 0, 1)).xyz;
rayDesc.Direction = mul(pViewParams.inverseViewMatrix, float4(normalize(target.xyz), 0)).xyz;
rayDesc.Origin = mul(pViewParams.c.inverseViewMatrix, float4(0, 0, 0, 1)).xyz;
rayDesc.Direction = mul(pViewParams.c.inverseViewMatrix, float4(normalize(target.xyz), 0)).xyz;
rayDesc.TMin = 0.001;
rayDesc.TMax = 10000.0;
+9 -11
View File
@@ -11,8 +11,6 @@
#include "Graphics/Vulkan/Graphics.h"
#endif
#include "Graphics/StaticMeshVertexData.h"
#include "Graphics/Vulkan/Buffer.h"
#include "Graphics/Vulkan/Graphics.h"
#include "Window/PlayView.h"
#include "Window/WindowManager.h"
#include <fmt/core.h>
@@ -60,22 +58,22 @@ int main() {
//AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/cube.fbx",
//});
AssetImporter::importMesh(MeshImportArgs{
.filePath = sourcePath / "import/models/culling.fbx",
});
//AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/culling.fbx",
//});
AssetImporter::importTexture(TextureImportArgs{
.filePath = sourcePath / "import/textures/skyboxsun5deg_tn.jpg",
.type = TextureImportType::TEXTURE_CUBEMAP,
});
//AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/ship.fbx",
// .importPath = "ship",
//});
AssetImporter::importMesh(MeshImportArgs{
.filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb",
.importPath = "Whitechapel",
.filePath = sourcePath / "import/models/ship.fbx",
.importPath = "ship",
});
//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",
// .importPath = "suburbs",
//});
+4 -4
View File
@@ -13,8 +13,8 @@ class RenderCommand {
virtual void setViewport(Gfx::PViewport viewport) = 0;
virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) = 0;
virtual void bindPipeline(Gfx::PRayTracingPipeline pipeline) = 0;
virtual void bindDescriptor(Gfx::PDescriptorSet set, Array<uint32> dynamicOffsets = {}) = 0;
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets, Array<uint32> dynamicOffsets = {}) = 0;
virtual void bindDescriptor(Gfx::PDescriptorSet set) = 0;
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) = 0;
virtual void bindVertexBuffer(const Array<PVertexBuffer>& buffer) = 0;
virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) = 0;
virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) = 0;
@@ -31,8 +31,8 @@ class ComputeCommand {
ComputeCommand();
virtual ~ComputeCommand();
virtual void bindPipeline(Gfx::PComputePipeline pipeline) = 0;
virtual void bindDescriptor(Gfx::PDescriptorSet set, Array<uint32> dynamicOffsets = {}) = 0;
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets, Array<uint32> dynamicOffsets = {}) = 0;
virtual void bindDescriptor(Gfx::PDescriptorSet set) = 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 dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) = 0;
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, PIndexBuffer indexBuffer) = 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_t binding, uint32 dstArrayIndex, Gfx::PSampler samplerState) = 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 updateSamplerArray(uint32_t binding, Array<PSampler> samplers) = 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]; }
void addMapping(std::string name, uint32 index);
constexpr std::string getName() const { return name; };
constexpr bool hasPushConstants() const { return !pushConstants.empty(); }
constexpr uint64 getPushConstantsSize() const { return pushConstants[0].size; }
protected:
uint32 layoutHash = 0;
+2 -2
View File
@@ -159,8 +159,8 @@ static constexpr bool useAsyncCompute = false;
static constexpr bool useMeshShading = true;
static constexpr uint32 numFramesBuffered = 3;
static constexpr uint32 numVerticesPerMeshlet = 256;
static constexpr uint32 numPrimitivesPerMeshlet = 256;
static constexpr uint32 numVerticesPerMeshlet = 64;
static constexpr uint32 numPrimitivesPerMeshlet = 126;
double getCurrentFrameDelta();
double getCurrentFrameTime();
uint32 getCurrentFrameIndex();
+2 -1
View File
@@ -68,7 +68,7 @@ struct SamplerCreateInfo {
Gfx::SeSamplerAddressMode addressModeW = Gfx::SE_SAMPLER_ADDRESS_MODE_REPEAT;
float mipLodBias = 0.0f;
uint32 anisotropyEnable = 0;
float maxAnisotropy = 0.0f;
float maxAnisotropy = 1.0f;
uint32 compareEnable = 0;
Gfx::SeCompareOp compareOp = Gfx::SE_COMPARE_OP_NEVER;
float minLod = 0.0f;
@@ -138,6 +138,7 @@ struct SePushConstantRange {
SeShaderStageFlags stageFlags;
uint32 offset;
uint32 size;
std::string name;
};
struct RasterizationState {
uint32 depthClampEnable = 0;
+12 -3
View File
@@ -42,8 +42,11 @@ void BufferAllocation::unmap() {}
Buffer::Buffer(PGraphics graphics, uint64 size, Gfx::SeBufferUsageFlags usage, Gfx::QueueType queueType, bool dynamic, std::string name,
bool createCleared, uint32 clearValue)
: graphics(graphics), currentBuffer(0), dynamic(dynamic), createCleared(createCleared), name(name), clearValue(clearValue) {
buffers.add(nullptr);
createBuffer(size, 0);
if(size > 0)
{
buffers.add(nullptr);
createBuffer(size, 0);
}
}
Buffer::~Buffer() {
@@ -101,10 +104,16 @@ void Buffer::copyBuffer(uint64 src, uint64 dest) {
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,
Gfx::SePipelineStageFlags dstStage) {
if(buffers.size() == 0)
return;
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 bindPipeline(Gfx::PGraphicsPipeline pipeline) override;
virtual void bindPipeline(Gfx::PRayTracingPipeline pipeline) override;
virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array<uint32> dynamicOffsets) override;
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets, Array<uint32> dynamicOffsets) override;
virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet) override;
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets) override;
virtual void bindVertexBuffer(const Array<Gfx::PVertexBuffer>& buffers) override;
virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) 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:
PGraphicsPipeline boundPipeline;
PIndexBuffer boundIndexBuffer;
MTL::ArgumentEncoder* argumentEncoder;
MTL::Buffer* argumentBuffer;
MTL::RenderCommandEncoder* encoder;
MTL::Buffer* constantsBuffer;
std::string name;
};
DEFINE_REF(RenderCommand)
@@ -83,8 +82,8 @@ class ComputeCommand : public Gfx::ComputeCommand {
virtual ~ComputeCommand();
void end();
virtual void bindPipeline(Gfx::PComputePipeline pipeline) override;
virtual void bindDescriptor(Gfx::PDescriptorSet set, Array<uint32> dynamicOffsets) override;
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets, Array<uint32> dynamicOffsets) override;
virtual void bindDescriptor(Gfx::PDescriptorSet set) 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 dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) override;
@@ -92,7 +91,7 @@ class ComputeCommand : public Gfx::ComputeCommand {
PComputePipeline boundPipeline;
MTL::CommandBuffer* commandBuffer;
MTL::ComputeCommandEncoder* encoder;
MTL::Buffer* argumentBuffer;
MTL::Buffer* constantsBuffer;
std::string name;
};
DEFINE_REF(ComputeCommand)
+34 -19
View File
@@ -3,6 +3,7 @@
#include "Containers/Array.h"
#include "Descriptor.h"
#include "Enums.h"
#include "Graphics/Graphics.h"
#include "Graphics/Command.h"
#include "Graphics/Enums.h"
#include "Graphics/Graphics.h"
@@ -74,35 +75,51 @@ void RenderCommand::setViewport(Gfx::PViewport viewport) {
void RenderCommand::bindPipeline(Gfx::PGraphicsPipeline pipeline) {
boundPipeline = pipeline.cast<GraphicsPipeline>();
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::bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array<uint32> offsets) {
void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet) {
auto metalSet = descriptorSet.cast<DescriptorSet>();
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) {
bindDescriptor(set, offsets);
bindDescriptor(set);
}
}
void RenderCommand::bindVertexBuffer(const Array<Gfx::PVertexBuffer>& buffers) {
uint32 i = 0;
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::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) {
encoder->setVertexBytes((char*)data + offset, size, 0);
encoder->setVertexBuffer(constantsBuffer, 0, pushIndex); // TODO: hardcoded
}
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) {
// 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));
}
@@ -143,29 +155,32 @@ void ComputeCommand::end() {
void ComputeCommand::bindPipeline(Gfx::PComputePipeline pipeline) {
boundPipeline = pipeline.cast<ComputePipeline>();
encoder->setComputePipelineState(boundPipeline->getHandle());
argumentBuffer = boundPipeline->graphics->getDevice()->newBuffer(
sizeof(uint64) * (boundPipeline->getPipelineLayout()->getLayouts().size() + 1), MTL::ResourceStorageModeShared);
argumentBuffer->setLabel(NS::String::string(pipeline->getPipelineLayout()->getName().c_str(), NS::ASCIIStringEncoding));
if(boundPipeline->getPipelineLayout()->hasPushConstants()) {
constantsBuffer = boundPipeline->graphics->getDevice()->newBuffer(boundPipeline->getPipelineLayout()->getPushConstantsSize(), 0);
}
}
void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set, Array<uint32> offsets) {
void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set) {
auto metalSet = set.cast<DescriptorSet>();
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) {
bindDescriptor(set, offsets);
bindDescriptor(set);
}
}
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) {
// TODO
encoder->setBuffer(argumentBuffer, 0, 2);
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::PShaderBuffer 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, uint32 dstArrayIndex, Gfx::PSampler samplerState) 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 updateSamplerArray(uint32 binding, Array<Gfx::PSampler> samplers) 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:
PGraphics graphics;
PDescriptorPool owner;
Array<Array<MTL::Resource*>> boundResources;
Array<MTL::Resource*> boundResources;
MTL::ArgumentEncoder* encoder;
MTL::Buffer* argumentBuffer = nullptr;
};
+79 -25
View File
@@ -4,6 +4,7 @@
#include "Foundation/NSArray.hpp"
#include "Foundation/NSObject.hpp"
#include "Graphics/Descriptor.h"
#include "Graphics/Enums.h"
#include "Graphics/Initializer.h"
#include "Graphics/Metal/Resources.h"
#include "Graphics/Metal/Shader.h"
@@ -15,8 +16,10 @@
#include "Metal/MTLTexture.hpp"
#include "Texture.h"
#include <CRC.h>
#include <CoreFoundation/CoreFoundation.h>
#include <Foundation/Foundation.h>
#include <iostream>
#include <stdexcept>
using namespace Seele;
using namespace Seele::Metal;
@@ -29,19 +32,68 @@ void DescriptorLayout::create() {
pool = new DescriptorPool(graphics, this);
hash = CRC::Calculate(descriptorBindings.data(), sizeof(Gfx::DescriptorBinding) * descriptorBindings.size(), CRC::CRC_32());
MTL::ArgumentDescriptor** objects = new MTL::ArgumentDescriptor*[descriptorBindings.size()];
for(uint32 i = 0; i < descriptorBindings.size(); ++i) {
for (uint32 i = 0; i < descriptorBindings.size(); ++i) {
objects[i] = MTL::ArgumentDescriptor::alloc()->init();
objects[i]->setIndex(i);
objects[i]->setAccess(cast(descriptorBindings[i].access));
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());
}
MTL::ArgumentEncoder* DescriptorLayout::createEncoder() {
return graphics->getDevice()->newArgumentEncoder(arguments);
}
MTL::ArgumentEncoder* DescriptorLayout::createEncoder() { return graphics->getDevice()->newArgumentEncoder(arguments); }
DescriptorPool::DescriptorPool(PGraphics graphics, PDescriptorLayout layout) : graphics(graphics), layout(layout) {}
@@ -65,10 +117,10 @@ void DescriptorPool::reset() {}
DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool 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());
for (uint32 i = 0; i < boundResources.size(); ++i) {
boundResources[i].resize(owner->getLayout()->getBindings()[i].descriptorCount);
}
}
DescriptorSet::~DescriptorSet() {}
@@ -76,38 +128,40 @@ DescriptorSet::~DescriptorSet() {}
void DescriptorSet::writeChanges() {}
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) {
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) {
boundResources[binding][0] = uniformBuffer.cast<IndexBuffer>()->getHandle();
}
void DescriptorSet::updateBuffer(uint32 binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) {
boundResources[binding][0] = uniformBuffer.cast<ShaderBuffer>()->getHandle();
PIndexBuffer buffer = uniformBuffer.cast<IndexBuffer>();
encoder->setBuffer(buffer->getHandle(), 0, binding);
boundResources[binding] = buffer->getHandle();
}
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) {
boundResources[binding][dstArrayIndex] = nullptr;
void DescriptorSet::updateTexture(uint32 binding, Gfx::PTexture texture, Gfx::PSampler sampler) {
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::updateSamplerArray(uint32 binding, Array<Gfx::PSampler> samplers) {}
void DescriptorSet::updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS as) {}
void DescriptorSet::updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS as) { assert(false && "TODO"); }
PipelineLayout::PipelineLayout(PGraphics graphics, const std::string& name, Gfx::PPipelineLayout baseLayout)
: 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) {
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); }
@@ -143,16 +143,16 @@ Gfx::OTimestampQuery Graphics::createTimestampQuery(uint64 numTimestamps, const
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
Gfx::OBottomLevelAS Graphics::createBottomLevelAccelerationStructure(const Gfx::BottomLevelASCreateInfo& 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) {
ORayGenShader shader = new RayGenShader(this);
+145 -179
View File
@@ -14,205 +14,171 @@
#include "Metal/MTLVertexDescriptor.hpp"
#include "Shader.h"
#include "Texture.h"
#include <Foundation/Foundation.h>
#include <iostream>
using namespace Seele;
using namespace Seele::Metal;
PipelineCache::PipelineCache(PGraphics graphics, const std::string &name)
: graphics(graphics), cacheFile(name) {}
PipelineCache::PipelineCache(PGraphics graphics, const std::string& name) : graphics(graphics), cacheFile(name) {}
PipelineCache::~PipelineCache() {}
PGraphicsPipeline
PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo createInfo) {
PPipelineLayout layout =
Gfx::PPipelineLayout(createInfo.pipelineLayout).cast<PipelineLayout>();
PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo createInfo) {
PPipelineLayout layout = Gfx::PPipelineLayout(createInfo.pipelineLayout).cast<PipelineLayout>();
MTL::RenderPipelineDescriptor *pipelineDescriptor =
MTL::RenderPipelineDescriptor::alloc()->init();
MTL::RenderPipelineDescriptor* pipelineDescriptor = MTL::RenderPipelineDescriptor::alloc()->init();
MTL::VertexDescriptor *vertexDescriptor =
pipelineDescriptor->vertexDescriptor()->init();
MTL::VertexAttributeDescriptorArray *attributes =
vertexDescriptor->attributes()->init();
if (createInfo.vertexInput != nullptr) {
const auto &vertexInfo = createInfo.vertexInput->getInfo();
for (size_t attr = 0; attr < vertexInfo.attributes.size(); ++attr) {
MTL::VertexAttributeDescriptor *attribute =
attributes->object(attr + METAL_VERTEXATTRIBUTE_OFFSET)->init();
attribute->setBufferIndex(vertexInfo.attributes[attr].binding +
METAL_VERTEXBUFFER_OFFSET);
switch (vertexInfo.attributes[attr].format) {
case Gfx::SE_FORMAT_R32G32B32_SFLOAT:
attribute->setFormat(MTL::VertexFormatFloat3);
MTL::VertexDescriptor* vertexDescriptor = pipelineDescriptor->vertexDescriptor()->init();
MTL::VertexAttributeDescriptorArray* attributes = vertexDescriptor->attributes()->init();
if (createInfo.vertexInput != nullptr) {
const auto& vertexInfo = createInfo.vertexInput->getInfo();
for (size_t attr = 0; attr < vertexInfo.attributes.size(); ++attr) {
MTL::VertexAttributeDescriptor* attribute = attributes->object(attr)->init();
attribute->setBufferIndex(vertexInfo.attributes[attr].binding);
switch (vertexInfo.attributes[attr].format) {
case Gfx::SE_FORMAT_R32G32B32_SFLOAT:
attribute->setFormat(MTL::VertexFormatFloat3);
break;
default:
throw std::logic_error("TODO");
}
attribute->setOffset(vertexInfo.attributes[attr].offset);
}
MTL::VertexBufferLayoutDescriptorArray* bufferLayout = vertexDescriptor->layouts()->init();
for (size_t binding = 0; binding < vertexInfo.bindings.size(); ++binding) {
MTL::VertexBufferLayoutDescriptor* buffer = bufferLayout->object(binding)->init();
buffer->setStride(vertexInfo.bindings[binding].stride);
buffer->setStepRate(1);
switch (vertexInfo.bindings[binding].inputRate) {
case Gfx::SE_VERTEX_INPUT_RATE_VERTEX:
buffer->setStepFunction(MTL::VertexStepFunctionPerVertex);
break;
case Gfx::SE_VERTEX_INPUT_RATE_INSTANCE:
buffer->setStepFunction(MTL::VertexStepFunctionPerInstance);
break;
}
}
}
pipelineDescriptor->setVertexDescriptor(vertexDescriptor);
pipelineDescriptor->setVertexFunction(createInfo.vertexShader.cast<VertexShader>()->getFunction());
if (createInfo.fragmentShader != nullptr) {
pipelineDescriptor->setFragmentFunction(createInfo.fragmentShader.cast<FragmentShader>()->getFunction());
}
pipelineDescriptor->setInputPrimitiveTopology(cast(createInfo.topology));
if (createInfo.renderPass->getLayout().depthAttachment.getTexture() != nullptr) {
pipelineDescriptor->setDepthAttachmentPixelFormat(
cast(createInfo.renderPass->getLayout().depthAttachment.getTexture().cast<Texture2D>()->getFormat()));
}
pipelineDescriptor->setAlphaToCoverageEnabled(createInfo.multisampleState.alphaCoverageEnable);
pipelineDescriptor->setAlphaToOneEnabled(createInfo.multisampleState.alphaToOneEnable);
pipelineDescriptor->setRasterSampleCount(createInfo.multisampleState.samples);
pipelineDescriptor->setRasterizationEnabled(!createInfo.rasterizationState.rasterizerDiscardEnable);
uint32 hash = pipelineDescriptor->hash();
if (graphicsPipelines.contains(hash)) {
return graphicsPipelines[hash];
}
MTL::PrimitiveType type = MTL::PrimitiveTypeTriangle;
switch (createInfo.topology) {
case Gfx::SE_PRIMITIVE_TOPOLOGY_POINT_LIST:
type = MTL::PrimitiveTypePoint;
break;
default:
throw std::logic_error("TODO");
}
attribute->setOffset(vertexInfo.attributes[attr].offset);
case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_LIST:
type = MTL::PrimitiveTypeLine;
break;
case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_STRIP:
type = MTL::PrimitiveTypeLineStrip;
break;
case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
type = MTL::PrimitiveTypeTriangle;
break;
case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
type = MTL::PrimitiveTypeTriangleStrip;
break;
case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
type = MTL::PrimitiveTypeTriangle;
break;
case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
type = MTL::PrimitiveTypeLine;
break;
case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
type = MTL::PrimitiveTypeLineStrip;
break;
case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
type = MTL::PrimitiveTypeTriangle;
break;
case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
type = MTL::PrimitiveTypeTriangleStrip;
break;
case Gfx::SE_PRIMITIVE_TOPOLOGY_PATCH_LIST:
type = MTL::PrimitiveTypeTriangle;
break;
}
NS::Error* error;
graphicsPipelines[hash] = new GraphicsPipeline(
graphics, type, graphics->getDevice()->newRenderPipelineState(pipelineDescriptor, &error), std::move(createInfo.pipelineLayout));
if (error) {
std::cout << error->localizedDescription()->cString(NS::ASCIIStringEncoding) << std::endl;
assert(false);
}
MTL::VertexBufferLayoutDescriptorArray *bufferLayout =
vertexDescriptor->layouts()->init();
for (size_t binding = 0; binding < vertexInfo.bindings.size(); ++binding) {
MTL::VertexBufferLayoutDescriptor *buffer =
bufferLayout->object(binding + METAL_VERTEXBUFFER_OFFSET)->init();
buffer->setStride(vertexInfo.bindings[binding].stride);
buffer->setStepRate(1);
switch (vertexInfo.bindings[binding].inputRate) {
case Gfx::SE_VERTEX_INPUT_RATE_VERTEX:
buffer->setStepFunction(MTL::VertexStepFunctionPerVertex);
break;
case Gfx::SE_VERTEX_INPUT_RATE_INSTANCE:
buffer->setStepFunction(MTL::VertexStepFunctionPerInstance);
break;
}
pipelineDescriptor->release();
return graphicsPipelines[hash];
}
PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo createInfo) {
MTL::MeshRenderPipelineDescriptor* pipelineDescriptor = MTL::MeshRenderPipelineDescriptor::alloc()->init();
pipelineDescriptor->setMeshFunction(createInfo.meshShader.cast<MeshShader>()->getFunction());
if (createInfo.taskShader != nullptr) {
pipelineDescriptor->setObjectFunction(createInfo.taskShader.cast<TaskShader>()->getFunction());
}
}
pipelineDescriptor->setVertexDescriptor(vertexDescriptor);
if (createInfo.fragmentShader != nullptr) {
pipelineDescriptor->setFragmentFunction(createInfo.fragmentShader.cast<FragmentShader>()->getFunction());
}
if (createInfo.renderPass->getLayout().depthAttachment.getTexture() != nullptr) {
pipelineDescriptor->setDepthAttachmentPixelFormat(
cast(createInfo.renderPass->getLayout().depthAttachment.getTexture().cast<Texture2D>()->getFormat()));
}
pipelineDescriptor->setAlphaToCoverageEnabled(createInfo.multisampleState.alphaCoverageEnable);
pipelineDescriptor->setAlphaToOneEnabled(createInfo.multisampleState.alphaToOneEnable);
pipelineDescriptor->setRasterSampleCount(createInfo.multisampleState.samples);
pipelineDescriptor->setRasterizationEnabled(!createInfo.rasterizationState.rasterizerDiscardEnable);
pipelineDescriptor->setVertexFunction(
createInfo.vertexShader.cast<VertexShader>()->getFunction());
if (createInfo.fragmentShader != nullptr) {
pipelineDescriptor->setFragmentFunction(
createInfo.fragmentShader.cast<FragmentShader>()->getFunction());
}
pipelineDescriptor->setInputPrimitiveTopology(cast(createInfo.topology));
if (createInfo.renderPass->getLayout().depthAttachment.getTexture() !=
nullptr) {
pipelineDescriptor->setDepthAttachmentPixelFormat(
cast(createInfo.renderPass->getLayout()
.depthAttachment.getTexture()
.cast<Texture2D>()
->getFormat()));
}
pipelineDescriptor->setAlphaToCoverageEnabled(
createInfo.multisampleState.alphaCoverageEnable);
pipelineDescriptor->setAlphaToOneEnabled(
createInfo.multisampleState.alphaToOneEnable);
pipelineDescriptor->setRasterSampleCount(createInfo.multisampleState.samples);
pipelineDescriptor->setRasterizationEnabled(
!createInfo.rasterizationState.rasterizerDiscardEnable);
uint32 hash = pipelineDescriptor->hash();
uint32 hash = pipelineDescriptor->hash();
if (graphicsPipelines.contains(hash)) {
return graphicsPipelines[hash];
}
NS::Error* error = nullptr;
MTL::AutoreleasedRenderPipelineReflection reflection;
graphicsPipelines[hash] = new GraphicsPipeline(
graphics, MTL::PrimitiveTypeTriangle,
graphics->getDevice()->newRenderPipelineState(pipelineDescriptor, MTL::PipelineOptionNone, &reflection, &error),
std::move(createInfo.pipelineLayout));
if (graphicsPipelines.contains(hash)) {
if (error) {
std::cout << error->debugDescription()->utf8String() << std::endl;
}
pipelineDescriptor->release();
return graphicsPipelines[hash];
}
MTL::PrimitiveType type = MTL::PrimitiveTypeTriangle;
switch (createInfo.topology) {
case Gfx::SE_PRIMITIVE_TOPOLOGY_POINT_LIST:
type = MTL::PrimitiveTypePoint;
break;
case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_LIST:
type = MTL::PrimitiveTypeLine;
break;
case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_STRIP:
type = MTL::PrimitiveTypeLineStrip;
break;
case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
type = MTL::PrimitiveTypeTriangle;
break;
case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
type = MTL::PrimitiveTypeTriangleStrip;
break;
case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
type = MTL::PrimitiveTypeTriangle;
break;
case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
type = MTL::PrimitiveTypeLine;
break;
case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
type = MTL::PrimitiveTypeLineStrip;
break;
case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
type = MTL::PrimitiveTypeTriangle;
break;
case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
type = MTL::PrimitiveTypeTriangleStrip;
break;
case Gfx::SE_PRIMITIVE_TOPOLOGY_PATCH_LIST:
type = MTL::PrimitiveTypeTriangle;
break;
}
NS::Error *error;
graphicsPipelines[hash] = new GraphicsPipeline(
graphics, type,
graphics->getDevice()->newRenderPipelineState(pipelineDescriptor, &error),
std::move(createInfo.pipelineLayout));
if (error) {
std::cout << error->localizedDescription()->cString(NS::ASCIIStringEncoding)
<< std::endl;
assert(false);
}
pipelineDescriptor->release();
return graphicsPipelines[hash];
}
PGraphicsPipeline
PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo createInfo) {
MTL::MeshRenderPipelineDescriptor *pipelineDescriptor =
MTL::MeshRenderPipelineDescriptor::alloc()->init();
PComputePipeline PipelineCache::createPipeline(Gfx::ComputePipelineCreateInfo createInfo) {
PComputeShader shader = createInfo.computeShader.cast<ComputeShader>();
uint32 hash = shader->getShaderHash();
if (computePipelines.contains(hash)) {
return computePipelines[hash];
}
pipelineDescriptor->setMeshFunction(
createInfo.meshShader.cast<MeshShader>()->getFunction());
if (createInfo.taskShader != nullptr) {
pipelineDescriptor->setObjectFunction(
createInfo.taskShader.cast<TaskShader>()->getFunction());
}
if (createInfo.fragmentShader != nullptr) {
pipelineDescriptor->setFragmentFunction(
createInfo.fragmentShader.cast<FragmentShader>()->getFunction());
}
if (createInfo.renderPass->getLayout().depthAttachment.getTexture() !=
nullptr) {
pipelineDescriptor->setDepthAttachmentPixelFormat(
cast(createInfo.renderPass->getLayout()
.depthAttachment.getTexture()
.cast<Texture2D>()
->getFormat()));
}
pipelineDescriptor->setAlphaToCoverageEnabled(
createInfo.multisampleState.alphaCoverageEnable);
pipelineDescriptor->setAlphaToOneEnabled(
createInfo.multisampleState.alphaToOneEnable);
pipelineDescriptor->setRasterSampleCount(createInfo.multisampleState.samples);
pipelineDescriptor->setRasterizationEnabled(
!createInfo.rasterizationState.rasterizerDiscardEnable);
uint32 hash = pipelineDescriptor->hash();
if (graphicsPipelines.contains(hash)) {
return graphicsPipelines[hash];
}
NS::Error *error = nullptr;
MTL::AutoreleasedRenderPipelineReflection reflection;
graphicsPipelines[hash] = new GraphicsPipeline(
graphics, MTL::PrimitiveTypeTriangle,
graphics->getDevice()->newRenderPipelineState(
pipelineDescriptor, MTL::PipelineOptionNone, &reflection, &error),
std::move(createInfo.pipelineLayout));
pipelineDescriptor->release();
return graphicsPipelines[hash];
}
PComputePipeline
PipelineCache::createPipeline(Gfx::ComputePipelineCreateInfo createInfo) {
PComputeShader shader = createInfo.computeShader.cast<ComputeShader>();
uint32 hash = shader->getShaderHash();
if (computePipelines.contains(hash)) {
NS::Error* error;
computePipelines[hash] = new ComputePipeline(graphics, graphics->getDevice()->newComputePipelineState(shader->getFunction(), &error),
std::move(createInfo.pipelineLayout));
assert(!error);
return computePipelines[hash];
}
NS::Error *error;
computePipelines[hash] =
new ComputePipeline(graphics,
graphics->getDevice()->newComputePipelineState(
shader->getFunction(), &error),
std::move(createInfo.pipelineLayout));
assert(!error);
return computePipelines[hash];
}
+1 -7
View File
@@ -40,16 +40,10 @@ class TimestampQuery : public Gfx::TimestampQuery, public QueryPool {
public:
TimestampQuery(PGraphics graphics, const std::string& name, uint32 numTimestamps);
virtual ~TimestampQuery();
virtual void begin() override;
virtual void write(Gfx::SePipelineStageFlagBits stage, const std::string& name = "") override;
virtual void end() override;
virtual Array<Gfx::Timestamp> getResults() override;
virtual Gfx::Timestamp getResult() override;
private:
uint64 wrapping = 0;
uint64 lastMeasure = 0;
uint32 numTimestamps = 0;
uint32 currentTimestamp = 0;
Array<std::string> pendingTimestamps;
};
DEFINE_REF(TimestampQuery)
+15 -27
View File
@@ -4,28 +4,23 @@
#include "Containers/Array.h"
#include "Enums.h"
#include "Graphics.h"
#include "Graphics/Query.h"
#include <vulkan/vulkan_core.h>
using namespace Seele;
using namespace Seele::Metal;
QueryPool::QueryPool(PGraphics graphics, const std::string& name)
: graphics(graphics) {
}
QueryPool::QueryPool(PGraphics graphics, const std::string&) : 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)
: QueryPool(graphics, name) {}
OcclusionQuery::OcclusionQuery(PGraphics graphics, const std::string& name) : QueryPool(graphics, name) {}
OcclusionQuery::~OcclusionQuery() {}
@@ -41,8 +36,7 @@ Gfx::OcclusionResult OcclusionQuery::getResults() {
};
}
PipelineStatisticsQuery::PipelineStatisticsQuery(PGraphics graphics, const std::string& name)
: QueryPool(graphics, name) {}
PipelineStatisticsQuery::PipelineStatisticsQuery(PGraphics graphics, const std::string& name) : QueryPool(graphics, name) {}
PipelineStatisticsQuery::~PipelineStatisticsQuery() {}
@@ -66,21 +60,15 @@ Gfx::PipelineStatisticsResult PipelineStatisticsQuery::getResults() {
};
}
TimestampQuery::TimestampQuery(PGraphics graphics, const std::string& name, uint32 numTimestamps)
: QueryPool(graphics, name), numTimestamps(numTimestamps) {
}
TimestampQuery::TimestampQuery(PGraphics graphics, const std::string& name, uint32) : QueryPool(graphics, name) {}
TimestampQuery::~TimestampQuery() {}
void TimestampQuery::begin() {
currentTimestamp = 0;
}
void TimestampQuery::write(Gfx::SePipelineStageFlagBits, const std::string&) {}
void TimestampQuery::write(Gfx::SePipelineStageFlagBits stage, const std::string& name) {
}
void TimestampQuery::end() {
}
Array<Gfx::Timestamp> TimestampQuery::getResults() {
Gfx::Timestamp TimestampQuery::getResult() {
return Gfx::Timestamp{
.name = "Test",
.time = 0,
};
}
+3 -3
View File
@@ -25,10 +25,10 @@ Shader::~Shader() {
void Shader::create(const ShaderCreateInfo& 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());
std::ofstream test("test.metal");
test.write((const char*)kernelBlob->getBufferPointer(), kernelBlob->getBufferSize());
test.close();
NS::Error* error;
MTL::CompileOptions* options = MTL::CompileOptions::alloc()->init();
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)
: 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() {}
+4
View File
@@ -90,6 +90,10 @@ Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo) : graphic
metalLayer.drawableSize = CGSizeMake(createInfo.width, createInfo.height);
metalWindow.contentView.layer = metalLayer;
metalWindow.contentView.wantsLayer = YES;
framebufferFormat = Gfx::SE_FORMAT_R8G8B8A8_UNORM;
drawable = (__bridge CA::MetalDrawable*)[metalLayer nextDrawable];
createBackBuffer();
}
Window::~Window() { glfwDestroyWindow(static_cast<GLFWwindow*>(windowHandle)); }
@@ -533,13 +533,13 @@ void WaterRenderer::updateFFTDescriptor() {
computeSet = computeLayout->allocateDescriptorSet();
computeSet->updateBuffer(0, paramsBuffer);
computeSet->updateTexture(1, 0, Gfx::PTexture2D(spectrumTextures));
computeSet->updateTexture(2, 0, Gfx::PTexture2D(initialSpectrumTextures));
computeSet->updateTexture(3, 0, Gfx::PTexture2D(displacementTextures));
computeSet->updateTexture(4, 0, Gfx::PTexture2D(slopeTextures));
computeSet->updateTexture(5, 0, Gfx::PTexture2D(boyancyData));
computeSet->updateBuffer(6, 0, spectrumBuffer);
computeSet->updateSampler(7, 0, linearRepeatSampler);
computeSet->updateTexture(1, Gfx::PTexture2D(spectrumTextures));
computeSet->updateTexture(2, Gfx::PTexture2D(initialSpectrumTextures));
computeSet->updateTexture(3, Gfx::PTexture2D(displacementTextures));
computeSet->updateTexture(4, Gfx::PTexture2D(slopeTextures));
computeSet->updateTexture(5, Gfx::PTexture2D(boyancyData));
computeSet->updateBuffer(6, spectrumBuffer);
computeSet->updateSampler(7, linearRepeatSampler);
computeSet->writeChanges();
}
+9 -6
View File
@@ -1,6 +1,7 @@
#include "StaticMeshVertexData.h"
#include "Graphics.h"
#include "Graphics/Enums.h"
#include "Graphics/VertexData.h"
#include "Mesh.h"
#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 = 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 = 5,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
.descriptorCount = MAX_TEXCOORDS,
});
for(uint i = 0; i < MAX_TEXCOORDS; ++i)
{
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 5 + i,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
}
descriptorLayout->create();
descriptorSet = descriptorLayout->allocateDescriptorSet();
}
@@ -223,7 +226,7 @@ void StaticMeshVertexData::updateBuffers() {
descriptorSet->updateBuffer(3, biTangents);
descriptorSet->updateBuffer(4, colors);
for (size_t i = 0; i < MAX_TEXCOORDS; ++i) {
descriptorSet->updateBuffer(5, i, texCoords[i]);
descriptorSet->updateBuffer(5 + i, texCoords[i]);
}
descriptorSet->writeChanges();
}
+1 -1
View File
@@ -274,7 +274,7 @@ MeshId VertexData::allocateVertexData(uint64 numVertices) {
return res;
}
void VertexData::serializeMesh(MeshId id, uint64 numVertices, ArchiveBuffer& buffer) {
void VertexData::serializeMesh(MeshId id, uint64, ArchiveBuffer& buffer) {
std::unique_lock l(vertexDataLock);
Array<Meshlet> out;
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 bindPipeline(Gfx::PGraphicsPipeline pipeline) override;
virtual void bindPipeline(Gfx::PRayTracingPipeline pipeline) override;
virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array<uint32> dynamicOffsets) override;
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets, Array<uint32> dynamicOffsets) override;
virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet) override;
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets) override;
virtual void bindVertexBuffer(const Array<Gfx::PVertexBuffer>& buffers) override;
virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) 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();
bool isReady();
virtual void bindPipeline(Gfx::PComputePipeline pipeline) override;
virtual void bindDescriptor(Gfx::PDescriptorSet set, Array<uint32> dynamicOffsets) override;
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets, Array<uint32> dynamicOffsets) override;
virtual void bindDescriptor(Gfx::PDescriptorSet set) 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 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) {
boundResources.resize(owner->getLayout()->getBindings().size());
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) {
PUniformBuffer vulkanBuffer = uniformBuffer.cast<UniformBuffer>();
if (boundResources[binding][0] == vulkanBuffer->getAlloc()) {
if (boundResources[binding] == vulkanBuffer->getAlloc()) {
return;
}
@@ -192,12 +192,12 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBu
.pBufferInfo = &bufferInfos.back(),
});
boundResources[binding][0] = vulkanBuffer->getAlloc();
boundResources[binding] = vulkanBuffer->getAlloc();
}
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer shaderBuffer) {
PShaderBuffer vulkanBuffer = shaderBuffer.cast<ShaderBuffer>();
if (boundResources[binding][0] == vulkanBuffer->getAlloc()) {
if (boundResources[binding] == vulkanBuffer->getAlloc()) {
return;
}
@@ -217,12 +217,12 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer shaderBuff
.pBufferInfo = &bufferInfos.back(),
});
boundResources[binding][0] = vulkanBuffer->getAlloc();
boundResources[binding] = vulkanBuffer->getAlloc();
}
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PIndexBuffer indexBuffer) {
PIndexBuffer vulkanBuffer = indexBuffer.cast<IndexBuffer>();
if (boundResources[binding][0] == vulkanBuffer->getAlloc()) {
if (boundResources[binding] == vulkanBuffer->getAlloc()) {
return;
}
@@ -242,38 +242,12 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PIndexBuffer indexBuffer
.pBufferInfo = &bufferInfos.back(),
});
boundResources[binding][0] = 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();
boundResources[binding] = vulkanBuffer->getAlloc();
}
void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState) {
PSampler vulkanSampler = samplerState.cast<Sampler>();
if (boundResources[binding][0] == vulkanSampler->getHandle()) {
if (boundResources[binding] == vulkanSampler->getHandle()) {
return;
}
@@ -294,38 +268,12 @@ void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState)
.pImageInfo = &imageInfos.back(),
});
boundResources[binding][0] = 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();
boundResources[binding] = vulkanSampler->getHandle();
}
void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler samplerState) {
TextureBase* vulkanTexture = texture.cast<TextureBase>().getHandle();
if (boundResources[binding][0] == vulkanTexture->getHandle()) {
if (boundResources[binding] == vulkanTexture->getHandle()) {
return;
}
@@ -346,33 +294,7 @@ void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::
.pImageInfo = &imageInfos.back(),
});
boundResources[binding][0] = 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();
boundResources[binding] = vulkanTexture->getHandle();
}
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;
for (auto& gfxTexture : textures) {
TextureBase* vulkanTexture = gfxTexture.cast<TextureBase>().getHandle();
if (boundResources[binding][arrayElement] == vulkanTexture->getHandle()) {
if (boundResources[binding+arrayElement] == vulkanTexture->getHandle()) {
continue;
}
imageInfos.add(VkDescriptorImageInfo{
@@ -389,7 +311,7 @@ void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture2D>
.imageLayout = cast(vulkanTexture->getLayout()),
});
boundResources[binding][arrayElement] = vulkanTexture->getHandle();
boundResources[binding+arrayElement] = vulkanTexture->getHandle();
writeDescriptors.add(VkWriteDescriptorSet{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = nullptr,
@@ -408,7 +330,7 @@ void DescriptorSet::updateSamplerArray(uint32_t binding, Array<Gfx::PSampler> sa
uint32 arrayElement = 0;
for (auto& gfxSampler : samplers) {
PSampler vulkanSampler = gfxSampler.cast<Sampler>();
if (boundResources[binding][arrayElement] == vulkanSampler->getHandle()) {
if (boundResources[binding+arrayElement] == vulkanSampler->getHandle()) {
continue;
}
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::PShaderBuffer 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, uint32 dstArrayIndex, Gfx::PSampler samplerState) 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 updateSamplerArray(uint32 binding, Array<Gfx::PSampler> samplers) 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
// would not work anyways, so casts should be safe
// Array<void*> cachedData;
Array<Array<PCommandBoundResource>> boundResources;
Array<PCommandBoundResource> boundResources;
VkDescriptorSet setHandle;
PGraphics graphics;
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) {
auto param = signature->getParameterByIndex(i);
layout->addMapping(param->getName(), param->getBindingIndex());
std::cout << param->getName() << ": " << param->getBindingIndex() << std::endl;
}
// workaround
layout->addMapping("pVertexData", 1);
layout->addMapping("pMaterial", 4);
layout->addMapping("pLightEnv", 3);
layout->addMapping("pRayTracingParams", 5);
layout->addMapping("pScene", 2);
layout->addMapping("pWaterMaterial", 1);
//layout->addMapping("pVertexData", 1);
//layout->addMapping("pMaterial", 4);
//layout->addMapping("pLightEnv", 3);
//layout->addMapping("pRayTracingParams", 5);
//layout->addMapping("pScene", 2);
//layout->addMapping("pWaterMaterial", 1);
}
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);
layout->reset();
set = layout->allocateDescriptorSet();
set->updateBuffer(0, floatBuffer);
uint32 binding = 0;
set->updateBuffer(binding++, floatBuffer);
for (uint32 i = 0; i < textures.size(); ++i) {
if (textures[i] != nullptr) {
set->updateTexture(1, i, textures[i]);
set->updateTexture(binding++, textures[i]);
}
}
for (uint32 i = 0; i < samplers.size(); ++i) {
if (samplers[i] != nullptr) {
set->updateSampler(2, i, samplers[i]);
set->updateSampler(binding++, samplers[i]);
}
}
set->writeChanges();
+2 -2
View File
@@ -27,8 +27,8 @@ template <typename... Components> class ComponentSystem : public SystemBase {
setupView((getDependencies<Components>() | ...));
}
virtual void update() override {}
virtual void update(Components&... components) {}
virtual void update(entt::entity id, Components&... components) {}
virtual void update(Components&...) {}
virtual void update(entt::entity, Components&...) {}
};
} // namespace System
} // 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 LightCullingPass(graphics, scene));
renderGraph.addPass(new BasePass(graphics, scene));
//renderGraph.addPass(new RayTracingPass(graphics, scene));
renderGraph.addPass(new RayTracingPass(graphics, scene));
renderGraph.setViewport(viewport);
renderGraph.createRenderPass();
}