Lot more Metal changes

This commit is contained in:
Dynamitos
2024-08-28 17:54:14 +02:00
parent e3b06dfb22
commit 6eb114e892
40 changed files with 1634 additions and 1737 deletions
-1
View File
@@ -1,6 +1,5 @@
BasedOnStyle: LLVM BasedOnStyle: LLVM
IndentWidth: 4 IndentWidth: 4
Language: Cpp
ColumnLimit: 140 ColumnLimit: 140
DerivePointerAlignment: false DerivePointerAlignment: false
PointerAlignment: Left PointerAlignment: Left
+2 -2
View File
@@ -18,11 +18,11 @@
"**/external": true, "**/external": true,
"**/res": true, "**/res": true,
}, },
"editor.tabSize": 4,
"editor.detectIndentation": false, "editor.detectIndentation": false,
"lldb.displayFormat": "auto", "lldb.displayFormat": "auto",
"lldb.showDisassembly": "auto", "lldb.showDisassembly": "auto",
"lldb.dereferencePointers": true, "lldb.dereferencePointers": true,
"lldb.consoleMode": "commands", "lldb.consoleMode": "commands",
"cmake.generator": "Ninja" "cmake.generator": "Ninja",
"editor.tabSize": 4
} }
+1 -1
View File
@@ -19,7 +19,7 @@ if(WIN32)
${SLANG_ROOT}lib/slang.lib ${SLANG_ROOT}lib/slang.lib
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
elseif(APPLE) elseif(APPLE)
set(BINARY_ROOT ${SOURCE_DIR}../../slang/build/Debug/) set(BINARY_ROOT ${PROJECT_SOURCE_DIR}/../slang/build/Debug)
set_target_properties(slang PROPERTIES IMPORTED_LOCATION ${BINARY_ROOT}/lib/libslang.dylib) set_target_properties(slang PROPERTIES IMPORTED_LOCATION ${BINARY_ROOT}/lib/libslang.dylib)
install(FILES install(FILES
${BINARY_ROOT}/lib/libslang.dylib ${BINARY_ROOT}/lib/libslang.dylib
+4 -1
View File
@@ -1,6 +1,7 @@
import Common; import Common;
import Scene; import Scene;
import VertexData; import VertexData;
import StaticMeshVertexData;
import MaterialParameter; import MaterialParameter;
struct PrimitiveAttributes struct PrimitiveAttributes
@@ -37,9 +38,11 @@ void meshMain(
uint local_idx1 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 1]; uint local_idx1 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 1];
uint local_idx2 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 2]; uint local_idx2 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 2];
indices[p] = uint3(local_idx0, local_idx1, local_idx2); indices[p] = uint3(local_idx0, local_idx1, local_idx2);
PrimitiveAttributes primAttr;
#ifdef VISIBILITY #ifdef VISIBILITY
prim[p].prim = encodePrimitive(meshletId); primAttr.prim = encodePrimitive(meshletId);
#endif #endif
prim[p] = primAttr;
} }
} }
for(uint i = threadID; i < MAX_VERTICES; i += MESH_GROUP_SIZE) for(uint i = threadID; i < MAX_VERTICES; i += MESH_GROUP_SIZE)
+5 -2
View File
@@ -1,6 +1,7 @@
import Common; import Common;
import Scene; import Scene;
import VertexData; import VertexData;
import StaticMeshVertexData;
import MaterialParameter; import MaterialParameter;
struct PrimitiveAttributes struct PrimitiveAttributes
@@ -38,10 +39,12 @@ void meshMain(
uint local_idx1 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 1]; uint local_idx1 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 1];
uint local_idx2 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 2]; uint local_idx2 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 2];
indices[p] = uint3(local_idx0, local_idx1, local_idx2); indices[p] = uint3(local_idx0, local_idx1, local_idx2);
prim[p].cull = false;//cull.triangleCulled(p); PrimitiveAttributes primAttr;
primAttr.cull = false;//cull.triangleCulled(p);
#ifdef VISIBILITY #ifdef VISIBILITY
prim[p].prim = encodePrimitive(meshletId); primAttr.prim = encodePrimitive(meshletId);
#endif #endif
prim[p] = primAttr;
} }
} }
for(uint i = threadID; i < MAX_VERTICES; i += MESH_GROUP_SIZE) for(uint i = threadID; i < MAX_VERTICES; i += MESH_GROUP_SIZE)
+2 -2
View File
@@ -19,7 +19,7 @@ struct ComputeParams
uint N, lengthScale0, lengthScale1, lengthScale2, lengthScale3; uint N, lengthScale0, lengthScale1, lengthScale2, lengthScale3;
float foamBias, foamDecayRate, foamAdd, foamThreshold; float foamBias, foamDecayRate, foamAdd, foamThreshold;
RWTexture2DArray<float4> spectrumTextures, initialSpectrumTextures, displacementTextures; RWTexture2DArray<float4> spectrumTextures, initialSpectrumTextures, displacementTextures;
RWTexture2DArray<float2> slopeTexture; RWTexture2DArray<float4> slopeTexture;
RWTexture2D<half> boyancyData; RWTexture2D<half> boyancyData;
StructuredBuffer<SpectrumParameters> spectrums; StructuredBuffer<SpectrumParameters> spectrums;
SamplerState linear_repeat_sampler; SamplerState linear_repeat_sampler;
@@ -306,7 +306,7 @@ void CS_AssembleMaps(uint3 id : SV_DISPATCHTHREADID) {
pParams.displacementTextures[uint3(id.xy, i)] = float4(displacement, foam); pParams.displacementTextures[uint3(id.xy, i)] = float4(displacement, foam);
pParams.slopeTexture[uint3(id.xy, i)] = float2(slopes); pParams.slopeTexture[uint3(id.xy, i)] = float4(slopes, 0, 0);
if (i == 0) { if (i == 0) {
pParams.boyancyData[id.xy] = half(displacement.y); pParams.boyancyData[id.xy] = half(displacement.y);
+1 -1
View File
@@ -21,7 +21,7 @@ float Beckmann(float ndoth, float roughness) {
} }
[shader("pixel")] [shader("pixel")]
float4 main(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.cameraPos_WS.xyz - vert.position_WS);
float3 halfwayDir = normalize(lightDir + viewDir); float3 halfwayDir = normalize(lightDir + viewDir);
+10
View File
@@ -19,8 +19,12 @@ struct Phong : IBRDF
__init() __init()
{ {
baseColor = float3(0, 0, 0);
alpha = 1; alpha = 1;
specular = float3(0, 0, 0);
normal = float3(0, 0, 1); normal = float3(0, 0, 1);
ambient = float3(0, 0, 0);
shininess = 0;
} }
float3 evaluate(float3 viewDir_TS, float3 lightDir_TS, float3 lightColor) float3 evaluate(float3 viewDir_TS, float3 lightDir_TS, float3 lightColor)
@@ -58,8 +62,12 @@ struct BlinnPhong : IBRDF
__init() __init()
{ {
baseColor = float3(0, 0, 0);
alpha = 1; alpha = 1;
specularColor = float3(0, 0, 0);
normal = float3(0, 0, 1); normal = float3(0, 0, 1);
shininess = 0;
ambient = float3(0, 0, 0);
} }
float3 evaluate(float3 viewDir_TS, float3 lightDir_TS, float3 lightColor) float3 evaluate(float3 viewDir_TS, float3 lightDir_TS, float3 lightColor)
@@ -94,6 +102,7 @@ struct CelShading : IBRDF
__init() __init()
{ {
baseColor = float3(0, 0, 0);
alpha = 1; alpha = 1;
normal = float3(0, 0, 1); normal = float3(0, 0, 1);
} }
@@ -140,6 +149,7 @@ struct CookTorrance : IBRDF
__init() __init()
{ {
baseColor = float3(0, 0, 0);
alpha = 1; alpha = 1;
normal = float3(0, 0, 1); normal = float3(0, 0, 1);
roughness = 0; roughness = 0;
+13 -12
View File
@@ -8,34 +8,35 @@ import Scene;
// associatedtype BRDF : IBRDF; // associatedtype BRDF : IBRDF;
// BRDF prepare(MaterialParameter input); // BRDF prepare(MaterialParameter input);
//}; //};
struct MaterialResources
layout(set=4, binding=0) {
Texture2D textureArray[];
layout(set=4, binding=1)
SamplerState samplerArray[];
layout(set=4, binding=2)
StructuredBuffer<float> floatArray; StructuredBuffer<float> floatArray;
Texture2D textureArray[512];
SamplerState samplerArray[512];
};
layout(set=4)
ParameterBlock<MaterialResources> pResources;
Texture2D getMaterialTextureParameter(uint index) Texture2D getMaterialTextureParameter(uint index)
{ {
return textureArray[pOffsets.textureOffset + index]; return pResources.textureArray[pOffsets.textureOffset + index];
} }
SamplerState getMaterialSamplerParameter(uint index) SamplerState getMaterialSamplerParameter(uint index)
{ {
return samplerArray[pOffsets.samplerOffset + index]; return pResources.samplerArray[pOffsets.samplerOffset + index];
} }
float getMaterialFloatParameter(uint index) float getMaterialFloatParameter(uint index)
{ {
return floatArray[pOffsets.floatOffset + index]; return pResources.floatArray[pOffsets.floatOffset + index];
} }
float3 getMaterialVectorParameter(uint index) float3 getMaterialVectorParameter(uint index)
{ {
return float3( return float3(
floatArray[pOffsets.floatOffset + index], pResources.floatArray[pOffsets.floatOffset + index],
floatArray[pOffsets.floatOffset + index + 1], pResources.floatArray[pOffsets.floatOffset + index + 1],
floatArray[pOffsets.floatOffset + index + 2] pResources.floatArray[pOffsets.floatOffset + index + 2]
); );
} }
+9
View File
@@ -1,7 +1,11 @@
#include "Asset/AssetRegistry.h" #include "Asset/AssetRegistry.h"
#include "Graphics/Initializer.h" #include "Graphics/Initializer.h"
#include "Graphics/StaticMeshVertexData.h" #include "Graphics/StaticMeshVertexData.h"
#ifdef __APPLE__
#include "Graphics/Metal/Graphics.h"
#else
#include "Graphics/Vulkan/Graphics.h" #include "Graphics/Vulkan/Graphics.h"
#endif
#include "PlayView.h" #include "PlayView.h"
#include "Window/WindowManager.h" #include "Window/WindowManager.h"
#include <fmt/core.h> #include <fmt/core.h>
@@ -24,7 +28,12 @@ int main(int argc, char** argv) {
} }
std::filesystem::path binaryPath = "C:/Users/Dynamitos/MeshShadingDemo/bin/MeshShadingDemo.dll"; std::filesystem::path binaryPath = "C:/Users/Dynamitos/MeshShadingDemo/bin/MeshShadingDemo.dll";
#ifdef __APPLE__
graphics = new Metal::Graphics();
#else
graphics = new Vulkan::Graphics(); graphics = new Vulkan::Graphics();
#endif
GraphicsInitializer initializer; GraphicsInitializer initializer;
graphics->init(initializer); graphics->init(initializer);
StaticMeshVertexData* vd = StaticMeshVertexData::getInstance(); StaticMeshVertexData* vd = StaticMeshVertexData::getInstance();
+1 -1
View File
@@ -65,7 +65,7 @@ int main() {
.type = TextureImportType::TEXTURE_CUBEMAP, .type = TextureImportType::TEXTURE_CUBEMAP,
}); });
AssetImporter::importMesh(MeshImportArgs{ AssetImporter::importMesh(MeshImportArgs{
.filePath = sourcePath / "import/models/ship.glb", .filePath = sourcePath / "import/models/ship.fbx",
.importPath = "ship", .importPath = "ship",
}); });
// AssetImporter::importMesh(MeshImportArgs{ // AssetImporter::importMesh(MeshImportArgs{
+16 -10
View File
@@ -12,9 +12,11 @@ namespace Metal {
DECLARE_REF(Graphics) DECLARE_REF(Graphics)
class BufferAllocation : public CommandBoundResource { class BufferAllocation : public CommandBoundResource {
public: public:
BufferAllocation(PGraphics graphics, const std::string& name, uint64 size, MTL::ResourceOptions options = MTL::ResourceOptionCPUCacheModeDefault); BufferAllocation(PGraphics graphics, const std::string& name, uint64 size,
MTL::ResourceOptions options = MTL::ResourceOptionCPUCacheModeDefault);
virtual ~BufferAllocation(); virtual ~BufferAllocation();
void pipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage); void pipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage);
void transferOwnership(Gfx::QueueType newOwner); void transferOwnership(Gfx::QueueType newOwner);
void updateContents(uint64 regionOffset, uint64 regionSize, void* ptr); void updateContents(uint64 regionOffset, uint64 regionSize, void* ptr);
void readContents(uint64 regionOffset, uint64 regionSize, void* ptr); void readContents(uint64 regionOffset, uint64 regionSize, void* ptr);
@@ -34,7 +36,8 @@ class Buffer {
uint64 getSize() const { return buffers[currentBuffer]->size; } uint64 getSize() const { return buffers[currentBuffer]->size; }
void updateContents(uint64 regionOffset, uint64 regionSize, void* ptr); void updateContents(uint64 regionOffset, uint64 regionSize, void* ptr);
void readContents(uint64 regionOffset, uint64 regionSize, void* ptr); void readContents(uint64 regionOffset, uint64 regionSize, void* ptr);
void* map();
void unmap();
protected: protected:
PGraphics graphics; PGraphics graphics;
@@ -51,8 +54,8 @@ class Buffer {
void copyBuffer(uint64 src, uint64 dest); void copyBuffer(uint64 src, uint64 dest);
void transferOwnership(Gfx::QueueType newOwner); void transferOwnership(Gfx::QueueType newOwner);
void pipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage); void pipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage);
}; };
DEFINE_REF(Buffer) DEFINE_REF(Buffer)
@@ -60,7 +63,8 @@ class VertexBuffer : public Gfx::VertexBuffer, public Buffer {
public: public:
VertexBuffer(PGraphics graphics, const VertexBufferCreateInfo& createInfo); VertexBuffer(PGraphics graphics, const VertexBufferCreateInfo& createInfo);
virtual ~VertexBuffer(); virtual ~VertexBuffer();
virtual void updateRegion(DataSource update) override;
virtual void updateRegion(uint64 offset, uint64 size, void* data) override;
virtual void download(Array<uint8>& buffer) override; virtual void download(Array<uint8>& buffer) override;
protected: protected:
@@ -89,9 +93,8 @@ class UniformBuffer : public Gfx::UniformBuffer, public Buffer {
public: public:
UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo& createInfo); UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo& createInfo);
virtual ~UniformBuffer(); virtual ~UniformBuffer();
virtual void updateContents(uint64 offset, uint64 size, void* data) override;
virtual void rotateBuffer(uint64 size) override; virtual void rotateBuffer(uint64 size) override;
virtual void updateContents(const DataSource& sourceData) override;
protected: protected:
// Inherited via QueueOwnedResource // Inherited via QueueOwnedResource
@@ -104,9 +107,12 @@ class ShaderBuffer : public Gfx::ShaderBuffer, public Buffer {
public: public:
ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo& createInfo); ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo& createInfo);
virtual ~ShaderBuffer(); virtual ~ShaderBuffer();
virtual void readContents(Array<uint8>& data) override; virtual void readContents(uint64 offset, uint64 size, void* data) override;
virtual void updateContents(uint64 offset, uint64 size, void* data) override;
virtual void rotateBuffer(uint64 size, bool preserveContents = false) override; virtual void rotateBuffer(uint64 size, bool preserveContents = false) override;
virtual void updateContents(const ShaderBufferCreateInfo& sourceData) override; virtual void* map() override;
virtual void unmap() override;
virtual void clear() override; virtual void clear() override;
protected: protected:
+50 -99
View File
@@ -23,36 +23,21 @@ BufferAllocation::~BufferAllocation() {
} }
} }
void BufferAllocation::pipelineBarrier(Gfx::SeAccessFlags, Gfx::SePipelineStageFlags , Gfx::SeAccessFlags, Gfx::SePipelineStageFlags) void BufferAllocation::pipelineBarrier(Gfx::SeAccessFlags, Gfx::SePipelineStageFlags, Gfx::SeAccessFlags, Gfx::SePipelineStageFlags) {}
{
} void BufferAllocation::transferOwnership(Gfx::QueueType) {}
void BufferAllocation::transferOwnership(Gfx::QueueType) void BufferAllocation::updateContents(uint64 regionOffset, uint64 regionSize, void* ptr) {
{
}
void BufferAllocation::updateContents(uint64 regionOffset, uint64 regionSize, void* ptr)
{
std::memcpy((uint8*)buffer->contents() + regionOffset, ptr, regionSize); std::memcpy((uint8*)buffer->contents() + regionOffset, ptr, regionSize);
} }
void BufferAllocation::readContents(uint64 regionOffset, uint64 regionSize, void* ptr) void BufferAllocation::readContents(uint64 regionOffset, uint64 regionSize, void* ptr) {
{
std::memcpy(ptr, (uint8*)buffer->contents() + regionOffset, regionSize); std::memcpy(ptr, (uint8*)buffer->contents() + regionOffset, regionSize);
} }
void* BufferAllocation::map() void* BufferAllocation::map() { return buffer->contents(); }
{
return buffer->contents();
}
void BufferAllocation::unmap()
{
}
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)
@@ -67,18 +52,17 @@ Buffer::~Buffer() {
} }
} }
void Buffer::updateContents(uint64 regionOffset, uint64 regionSize, void* ptr) void Buffer::updateContents(uint64 regionOffset, uint64 regionSize, void* ptr) {
{
getAlloc()->updateContents(regionOffset, regionSize, ptr); getAlloc()->updateContents(regionOffset, regionSize, ptr);
} }
void Buffer::readContents(uint64 regionOffset, uint64 regionSize, void* ptr) void Buffer::readContents(uint64 regionOffset, uint64 regionSize, void* ptr) { getAlloc()->readContents(regionOffset, regionSize, ptr); }
{
getAlloc()->readContents(regionOffset, regionSize, ptr);
}
void Buffer::rotateBuffer(uint64 size, bool preserveContents) void* Buffer::map() { return getAlloc()->map(); }
{
void Buffer::unmap() { return getAlloc()->unmap(); }
void Buffer::rotateBuffer(uint64 size, bool preserveContents) {
if (size == 0) if (size == 0)
return; return;
assert(dynamic); assert(dynamic);
@@ -103,34 +87,28 @@ void Buffer::rotateBuffer(uint64 size, bool preserveContents)
currentBuffer = buffers.size() - 1; currentBuffer = buffers.size() - 1;
} }
void Buffer::createBuffer(uint64 size, uint32 destIndex) void Buffer::createBuffer(uint64 size, uint32 destIndex) {
{
buffers[destIndex] = new BufferAllocation(graphics, name, size); buffers[destIndex] = new BufferAllocation(graphics, name, size);
if (createCleared) { if (createCleared) {
std::memset(buffers[destIndex]->map(), clearValue, buffers[destIndex]->size); std::memset(buffers[destIndex]->map(), clearValue, buffers[destIndex]->size);
} }
} }
void Buffer::copyBuffer(uint64 src, uint64 dest) void Buffer::copyBuffer(uint64 src, uint64 dest) {
{
if (src == dest) { if (src == dest) {
return; return;
} }
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) void Buffer::transferOwnership(Gfx::QueueType newOwner) { getAlloc()->transferOwnership(newOwner); }
{
getAlloc()->transferOwnership(newOwner);
}
void Buffer::pipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) void Buffer::pipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess,
{ Gfx::SePipelineStageFlags dstStage) {
getAlloc()->pipelineBarrier(srcAccess, srcStage, dstAccess, dstStage); getAlloc()->pipelineBarrier(srcAccess, srcStage, dstAccess, dstStage);
} }
VertexBuffer::VertexBuffer(PGraphics graphics, VertexBuffer::VertexBuffer(PGraphics graphics, const VertexBufferCreateInfo& createInfo)
const VertexBufferCreateInfo &createInfo)
: Gfx::VertexBuffer(graphics->getFamilyMapping(), createInfo), : Gfx::VertexBuffer(graphics->getFamilyMapping(), createInfo),
Metal::Buffer(graphics, createInfo.sourceData.size, Gfx::SE_BUFFER_USAGE_VERTEX_BUFFER_BIT, createInfo.sourceData.owner, false, Metal::Buffer(graphics, createInfo.sourceData.size, Gfx::SE_BUFFER_USAGE_VERTEX_BUFFER_BIT, createInfo.sourceData.owner, false,
createInfo.name) { createInfo.name) {
@@ -141,10 +119,7 @@ VertexBuffer::VertexBuffer(PGraphics graphics,
VertexBuffer::~VertexBuffer() {} VertexBuffer::~VertexBuffer() {}
void VertexBuffer::updateRegion(DataSource update) { void VertexBuffer::updateRegion(uint64 offset, uint64 size, void* data) { getAlloc()->updateContents(offset, size, data); }
void *data = getHandle()->contents();
std::memcpy((char *)data + update.offset, update.data, update.size);
}
void VertexBuffer::download(Array<uint8>& buffer) { void VertexBuffer::download(Array<uint8>& buffer) {
void* data = getHandle()->contents(); void* data = getHandle()->contents();
@@ -152,24 +127,18 @@ void VertexBuffer::download(Array<uint8> &buffer) {
std::memcpy(buffer.data(), data, getSize()); std::memcpy(buffer.data(), data, getSize());
} }
void VertexBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { void VertexBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { Metal::Buffer::transferOwnership(newOwner); }
Metal::Buffer::transferOwnership(newOwner);
}
void VertexBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, void VertexBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) { Gfx::SePipelineStageFlags dstStage) {
Metal::Buffer::pipelineBarrier(srcAccess, srcStage, dstAccess, dstStage); Metal::Buffer::pipelineBarrier(srcAccess, srcStage, dstAccess, dstStage);
} }
IndexBuffer::IndexBuffer(PGraphics graphics, IndexBuffer::IndexBuffer(PGraphics graphics, const IndexBufferCreateInfo& createInfo)
const IndexBufferCreateInfo &createInfo)
: Gfx::IndexBuffer(graphics->getFamilyMapping(), createInfo), : Gfx::IndexBuffer(graphics->getFamilyMapping(), createInfo),
Metal::Buffer(graphics, createInfo.sourceData.size, Metal::Buffer(graphics, createInfo.sourceData.size,
Gfx::SE_BUFFER_USAGE_INDEX_BUFFER_BIT | Gfx::SE_BUFFER_USAGE_TRANSFER_DST_BIT | Gfx::SE_BUFFER_USAGE_STORAGE_BUFFER_BIT, Gfx::SE_BUFFER_USAGE_INDEX_BUFFER_BIT | Gfx::SE_BUFFER_USAGE_TRANSFER_DST_BIT | Gfx::SE_BUFFER_USAGE_STORAGE_BUFFER_BIT,
createInfo.sourceData.owner, false, createInfo.name) { createInfo.sourceData.owner, false, createInfo.name) {}
}
IndexBuffer::~IndexBuffer() {} IndexBuffer::~IndexBuffer() {}
@@ -178,72 +147,57 @@ void IndexBuffer::download(Array<uint8> &buffer) {
buffer.resize(getSize()); buffer.resize(getSize());
std::memcpy(buffer.data(), data, getSize()); std::memcpy(buffer.data(), data, getSize());
} }
void IndexBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { void IndexBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { Metal::Buffer::transferOwnership(newOwner); }
Metal::Buffer::transferOwnership(newOwner);
}
void IndexBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, void IndexBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) { Gfx::SePipelineStageFlags dstStage) {
Metal::Buffer::pipelineBarrier(srcAccess, srcStage, dstAccess, dstStage); Metal::Buffer::pipelineBarrier(srcAccess, srcStage, dstAccess, dstStage);
} }
UniformBuffer::UniformBuffer(PGraphics graphics, UniformBuffer::UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo& createInfo)
const UniformBufferCreateInfo &createInfo)
: Gfx::UniformBuffer(graphics->getFamilyMapping(), createInfo), : Gfx::UniformBuffer(graphics->getFamilyMapping(), createInfo),
Metal::Buffer(graphics, createInfo.sourceData.size, Gfx::SE_BUFFER_USAGE_UNIFORM_BUFFER_BIT, createInfo.sourceData.owner, Metal::Buffer(graphics, createInfo.sourceData.size, Gfx::SE_BUFFER_USAGE_UNIFORM_BUFFER_BIT, createInfo.sourceData.owner,
createInfo.dynamic, createInfo.name) { createInfo.dynamic, createInfo.name) {
if (createInfo.sourceData.size > 0 && createInfo.sourceData.data != nullptr) {
getAlloc()->updateContents(createInfo.sourceData.offset, createInfo.sourceData.size, createInfo.sourceData.data); getAlloc()->updateContents(createInfo.sourceData.offset, createInfo.sourceData.size, createInfo.sourceData.data);
} }
}
UniformBuffer::~UniformBuffer() {} UniformBuffer::~UniformBuffer() {}
void UniformBuffer::rotateBuffer(uint64 size) { void UniformBuffer::rotateBuffer(uint64 size) { Metal::Buffer::rotateBuffer(size); }
void UniformBuffer::updateContents(uint64 offset, uint64 size, void* data) {
if (size > 0 && data != nullptr) {
Metal::Buffer::rotateBuffer(size); Metal::Buffer::rotateBuffer(size);
} getAlloc()->updateContents(offset, size, data);
void UniformBuffer::updateContents(const DataSource &sourceData) {
if (sourceData.size > 0 && sourceData.data != nullptr) {
Metal::Buffer::rotateBuffer(sourceData.size);
getAlloc()->updateContents(sourceData.offset, sourceData.size, sourceData.data);
} }
} }
void UniformBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { void UniformBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { Metal::Buffer::transferOwnership(newOwner); }
Metal::Buffer::transferOwnership(newOwner);
}
void UniformBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, void UniformBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) { Gfx::SePipelineStageFlags dstStage) {
Metal::Buffer::pipelineBarrier(srcAccess, srcStage, dstAccess, dstStage); Metal::Buffer::pipelineBarrier(srcAccess, srcStage, dstAccess, dstStage);
} }
ShaderBuffer::ShaderBuffer(PGraphics graphics, ShaderBuffer::ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo& createInfo)
const ShaderBufferCreateInfo &createInfo)
: Gfx::ShaderBuffer(graphics->getFamilyMapping(), createInfo), : Gfx::ShaderBuffer(graphics->getFamilyMapping(), createInfo),
Seele::Metal::Buffer(graphics, createInfo.sourceData.size, Seele::Metal::Buffer(graphics, createInfo.sourceData.size, Gfx::SE_BUFFER_USAGE_STORAGE_BUFFER_BIT, createInfo.sourceData.owner,
Gfx::SE_BUFFER_USAGE_STORAGE_BUFFER_BIT, createInfo.dynamic, createInfo.name, createInfo.createCleared, createInfo.clearValue) {}
createInfo.sourceData.owner, createInfo.dynamic, createInfo.name, createInfo.createCleared, createInfo.clearValue) {}
ShaderBuffer::~ShaderBuffer() {} ShaderBuffer::~ShaderBuffer() {}
void ShaderBuffer::readContents(Array<uint8>& data) { void ShaderBuffer::readContents(uint64 offset, uint64 size, void* data) { getAlloc()->readContents(offset, size, data); }
data.resize(getSize());
getAlloc()->readContents(0, data.size(), data.data());
}
void ShaderBuffer::updateContents(const ShaderBufferCreateInfo& createInfo) { void ShaderBuffer::updateContents(uint64 offset, uint64 size, void* data) {
if (createInfo.sourceData.data == nullptr) { if (data == nullptr) {
return; return;
} }
// We always want to update, as the contents could be different on the GPU // We always want to update, as the contents could be different on the GPU
if (createInfo.sourceData.size > 0 && createInfo.sourceData.data != nullptr) { if (size > 0 && data != nullptr) {
getAlloc()->updateContents(createInfo.sourceData.offset, createInfo.sourceData.size, createInfo.sourceData.data); getAlloc()->updateContents(offset, size, data);
} }
} }
void ShaderBuffer::rotateBuffer(uint64 size, bool preserveContents) { void ShaderBuffer::rotateBuffer(uint64 size, bool preserveContents) {
@@ -251,18 +205,15 @@ void ShaderBuffer::rotateBuffer(uint64 size, bool preserveContents) {
Metal::Buffer::rotateBuffer(size, preserveContents); Metal::Buffer::rotateBuffer(size, preserveContents);
} }
void* ShaderBuffer::map() { return Metal::Buffer::map(); }
void ShaderBuffer::clear() { void ShaderBuffer::unmap() { Metal::Buffer::unmap(); }
std::memset(getAlloc()->map(), 0, getSize());
}
void ShaderBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { void ShaderBuffer::clear() { std::memset(getAlloc()->map(), 0, getSize()); }
Metal::Buffer::transferOwnership(newOwner);
}
void ShaderBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, void ShaderBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { Metal::Buffer::transferOwnership(newOwner); }
Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, void ShaderBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) { Gfx::SePipelineStageFlags dstStage) {
Metal::Buffer::pipelineBarrier(srcAccess, srcStage, dstAccess, dstStage); Metal::Buffer::pipelineBarrier(srcAccess, srcStage, dstAccess, dstStage);
} }
+2
View File
@@ -15,6 +15,8 @@ target_sources(Engine
PipelineCache.h PipelineCache.h
PipelineCache.mm PipelineCache.mm
PrivateImpl.mm PrivateImpl.mm
Query.h
Query.mm
RenderPass.h RenderPass.h
RenderPass.mm RenderPass.mm
Resources.h Resources.h
+36 -147
View File
@@ -17,8 +17,7 @@ using namespace Seele;
using namespace Seele::Metal; using namespace Seele::Metal;
Command::Command(PGraphics graphics, MTL::CommandBuffer* cmdBuffer) Command::Command(PGraphics graphics, MTL::CommandBuffer* cmdBuffer)
: graphics(graphics), completed(new Event(graphics)), cmdBuffer(cmdBuffer) { : graphics(graphics), completed(new Event(graphics)), cmdBuffer(cmdBuffer) {}
}
Command::~Command() {} Command::~Command() {}
@@ -28,8 +27,7 @@ void Command::beginRenderPass(PRenderPass renderPass) {
blitEncoder = nullptr; blitEncoder = nullptr;
} }
renderPass->updateRenderPass(); renderPass->updateRenderPass();
parallelEncoder = parallelEncoder = cmdBuffer->parallelRenderCommandEncoder(renderPass->getDescriptor());
cmdBuffer->parallelRenderCommandEncoder(renderPass->getDescriptor());
} }
void Command::endRenderPass() { void Command::endRenderPass() {
@@ -37,9 +35,7 @@ void Command::endRenderPass() {
parallelEncoder = nullptr; parallelEncoder = nullptr;
} }
void Command::present(MTL::Drawable *drawable) { void Command::present(MTL::Drawable* drawable) { cmdBuffer->presentDrawable(drawable); }
cmdBuffer->presentDrawable(drawable);
}
void Command::end(PEvent signal) { void Command::end(PEvent signal) {
assert(!parallelEncoder); assert(!parallelEncoder);
@@ -53,17 +49,11 @@ void Command::end(PEvent signal) {
void Command::waitDeviceIdle() { cmdBuffer->waitUntilCompleted(); } void Command::waitDeviceIdle() { cmdBuffer->waitUntilCompleted(); }
void Command::signalEvent(PEvent event) { void Command::signalEvent(PEvent event) { cmdBuffer->encodeSignalEvent(event->getHandle(), 1); }
cmdBuffer->encodeSignalEvent(event->getHandle(), 1);
}
void Command::waitForEvent(PEvent event) { void Command::waitForEvent(PEvent event) { cmdBuffer->encodeWait(event->getHandle(), 1); }
cmdBuffer->encodeWait(event->getHandle(), 1);
}
RenderCommand::RenderCommand(MTL::RenderCommandEncoder *encoder, RenderCommand::RenderCommand(MTL::RenderCommandEncoder* encoder, const std::string& name) : encoder(encoder), name(name) {}
const std::string &name)
: encoder(encoder), name(name) {}
RenderCommand::~RenderCommand() {} RenderCommand::~RenderCommand() {}
@@ -86,50 +76,14 @@ void RenderCommand::bindPipeline(Gfx::PGraphicsPipeline pipeline) {
encoder->setRenderPipelineState(boundPipeline->getHandle()); encoder->setRenderPipelineState(boundPipeline->getHandle());
} }
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,
Array<uint32> offsets) {
auto metalSet = descriptorSet.cast<DescriptorSet>(); auto metalSet = descriptorSet.cast<DescriptorSet>();
uint32 parameterIndex = boundPipeline->getPipelineLayout()->findParameter( metalSet->bind();
descriptorSet->getLayout()->getName());
uint64 *topLevelTable = (uint64 *)argumentBuffer->contents();
topLevelTable[parameterIndex] = metalSet->getBuffer()->gpuAddress();
auto bindings = metalSet->getLayout()->getBindings();
encoder->useResource(metalSet->getBuffer(), MTL::ResourceUsageRead);
for (size_t i = 0; i < bindings.size(); ++i) {
auto binding = bindings[i];
if (binding.descriptorType == Gfx::SE_DESCRIPTOR_TYPE_SAMPLER) {
continue;
}
MTL::ResourceUsage usage;
switch (binding.access) {
case Gfx::SE_DESCRIPTOR_ACCESS_READ_ONLY_BIT:
if (binding.descriptorType == Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE) {
usage = MTL::ResourceUsageSample;
break;
} else {
usage = MTL::ResourceUsageRead;
break;
}
case Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT:
usage = MTL::ResourceUsageRead | MTL::ResourceUsageWrite;
break;
case Gfx::SE_DESCRIPTOR_ACCESS_WRITE_ONLY_BIT:
usage = MTL::ResourceUsageWrite;
break;
}
for(size_t x = 0; x < metalSet->getBoundResources()[i].size(); ++x)
{
encoder->useResource(metalSet->getBoundResources()[i][x], usage);
}
}
} }
void RenderCommand::bindDescriptor( void RenderCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets, Array<uint32> offsets) {
const Array<Gfx::PDescriptorSet> &descriptorSets, Array<uint32> offsets) {
for (auto set : descriptorSets) { for (auto set : descriptorSets) {
bindDescriptor(set, offsets); bindDescriptor(set, offsets);
} }
@@ -137,17 +91,13 @@ void RenderCommand::bindDescriptor(
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, encoder->setVertexBuffer(buffer.cast<VertexBuffer>()->getHandle(), 0, METAL_VERTEXBUFFER_OFFSET + i++);
METAL_VERTEXBUFFER_OFFSET + i++);
} }
} }
void RenderCommand::bindIndexBuffer(Gfx::PIndexBuffer gfxIndexBuffer) { void RenderCommand::bindIndexBuffer(Gfx::PIndexBuffer gfxIndexBuffer) { boundIndexBuffer = gfxIndexBuffer.cast<IndexBuffer>(); }
boundIndexBuffer = gfxIndexBuffer.cast<IndexBuffer>();
}
void RenderCommand::pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, void RenderCommand::pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) {
uint32 size, const void *data) {
if (stage & Gfx::SE_SHADER_STAGE_VERTEX_BIT) { if (stage & Gfx::SE_SHADER_STAGE_VERTEX_BIT) {
encoder->setVertexBytes((char*)data + offset, size, 0); encoder->setVertexBytes((char*)data + offset, size, 0);
} }
@@ -156,19 +106,13 @@ void RenderCommand::pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset,
} }
} }
void RenderCommand::draw(uint32 vertexCount, uint32 instanceCount, void RenderCommand::draw(uint32 vertexCount, uint32 instanceCount, int32 firstVertex, uint32 firstInstance) {
int32 firstVertex, uint32 firstInstance) { encoder->drawPrimitives(boundPipeline->getPrimitive(), firstVertex, vertexCount, instanceCount, firstInstance);
encoder->drawPrimitives(boundPipeline->getPrimitive(), firstVertex,
vertexCount, instanceCount, firstInstance);
} }
void RenderCommand::drawIndexed(uint32 indexCount, uint32 instanceCount, void RenderCommand::drawIndexed(uint32 indexCount, uint32 instanceCount, int32 firstIndex, uint32 vertexOffset, uint32 firstInstance) {
int32 firstIndex, uint32 vertexOffset, encoder->drawIndexedPrimitives(boundPipeline->getPrimitive(), indexCount, cast(boundIndexBuffer->getIndexType()),
uint32 firstInstance) { boundIndexBuffer->getHandle(), firstIndex, instanceCount, vertexOffset, firstInstance);
encoder->drawIndexedPrimitives(boundPipeline->getPrimitive(), indexCount,
cast(boundIndexBuffer->getIndexType()),
boundIndexBuffer->getHandle(), firstIndex,
instanceCount, vertexOffset, firstInstance);
} }
void RenderCommand::drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) { void RenderCommand::drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) {
@@ -177,23 +121,17 @@ void RenderCommand::drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) {
encoder->setFragmentBuffer(argumentBuffer, 0, 2); encoder->setFragmentBuffer(argumentBuffer, 0, 2);
encoder->setMeshBuffer(argumentBuffer, 0, 2); encoder->setMeshBuffer(argumentBuffer, 0, 2);
encoder->setObjectBuffer(argumentBuffer, 0, 2); encoder->setObjectBuffer(argumentBuffer, 0, 2);
encoder->drawMeshThreadgroups(MTL::Size(groupX, groupY, groupZ), encoder->drawMeshThreadgroups(MTL::Size(groupX, groupY, groupZ), MTL::Size(128, 1, 1), MTL::Size(32, 1, 1));
MTL::Size(128, 1, 1), MTL::Size(32, 1, 1));
} }
void RenderCommand::drawMeshIndirect(Gfx::PShaderBuffer buffer, uint64 offset, void RenderCommand::drawMeshIndirect(Gfx::PShaderBuffer buffer, uint64 offset, uint32 drawCount, uint32 stride) {
uint32 drawCount, uint32 stride) {
// encoder->drawMeshThreadgroups() // encoder->drawMeshThreadgroups()
} }
void RenderCommand::traceRays(uint32 width, uint32 height, uint32 depth){ void RenderCommand::traceRays(uint32 width, uint32 height, uint32 depth) {}
} ComputeCommand::ComputeCommand(MTL::CommandBuffer* cmdBuffer, const std::string& name)
: commandBuffer(cmdBuffer), encoder(cmdBuffer->computeCommandEncoder()), name(name) {}
ComputeCommand::ComputeCommand(MTL::CommandBuffer *cmdBuffer,
const std::string &name)
: commandBuffer(cmdBuffer), encoder(cmdBuffer->computeCommandEncoder()),
name(name) {}
ComputeCommand::~ComputeCommand() {} ComputeCommand::~ComputeCommand() {}
@@ -206,76 +144,34 @@ 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( argumentBuffer = boundPipeline->graphics->getDevice()->newBuffer(
sizeof(uint64) * sizeof(uint64) * (boundPipeline->getPipelineLayout()->getLayouts().size() + 1), MTL::ResourceStorageModeShared);
(boundPipeline->getPipelineLayout()->getLayouts().size() + 1), argumentBuffer->setLabel(NS::String::string(pipeline->getPipelineLayout()->getName().c_str(), NS::ASCIIStringEncoding));
MTL::ResourceStorageModeShared);
argumentBuffer->setLabel(
NS::String::string(pipeline->getPipelineLayout()->getName().c_str(),
NS::ASCIIStringEncoding));
} }
void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set, void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set, Array<uint32> offsets) {
Array<uint32> offsets) {
auto metalSet = set.cast<DescriptorSet>(); auto metalSet = set.cast<DescriptorSet>();
metalSet->bind(); metalSet->bind();
uint32 parameterIndex = boundPipeline->getPipelineLayout()->findParameter(
set->getLayout()->getName());
uint64 *topLevelTable = (uint64 *)argumentBuffer->contents();
topLevelTable[parameterIndex] = metalSet->getBuffer()->gpuAddress();
auto bindings = metalSet->getLayout()->getBindings();
encoder->useResource(metalSet->getBuffer(), MTL::ResourceUsageRead);
for (size_t i = 0; i < bindings.size(); ++i) {
auto binding = bindings[i];
if (binding.descriptorType == Gfx::SE_DESCRIPTOR_TYPE_SAMPLER) {
continue;
}
MTL::ResourceUsage usage;
switch (binding.access) {
case Gfx::SE_DESCRIPTOR_ACCESS_READ_ONLY_BIT:
if (binding.descriptorType == Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE) {
usage = MTL::ResourceUsageSample;
break;
} else {
usage = MTL::ResourceUsageRead;
break;
}
case Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT:
usage = MTL::ResourceUsageRead | MTL::ResourceUsageWrite;
break;
case Gfx::SE_DESCRIPTOR_ACCESS_WRITE_ONLY_BIT:
usage = MTL::ResourceUsageWrite;
break;
}
for(size_t x = 0; x < metalSet->getBoundResources()[i].size(); ++x)
{
encoder->useResource(metalSet->getBoundResources()[i][x], usage);
}
}
} }
void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet> &sets, void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& sets, Array<uint32> offsets) {
Array<uint32> offsets) {
for (auto& set : sets) { for (auto& set : sets) {
bindDescriptor(set, offsets); bindDescriptor(set, offsets);
} }
} }
void ComputeCommand::pushConstants(Gfx::SeShaderStageFlags, uint32 offset, void ComputeCommand::pushConstants(Gfx::SeShaderStageFlags, uint32 offset, uint32 size, const void* data) {
uint32 size, const void *data) {
encoder->setBytes((char*)data + offset, size, 0); encoder->setBytes((char*)data + offset, size, 0);
} }
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->setBuffer(argumentBuffer, 0, 2);
encoder->dispatchThreadgroups(MTL::Size(threadX, threadY, threadZ), encoder->dispatchThreadgroups(MTL::Size(threadX, threadY, threadZ), MTL::Size(32, 32, 1));
MTL::Size(32, 32, 1));
} }
CommandQueue::CommandQueue(PGraphics graphics) : graphics(graphics) { CommandQueue::CommandQueue(PGraphics graphics) : graphics(graphics) {
queue = graphics->getDevice()->newCommandQueue(); queue = graphics->getDevice()->newCommandQueue();
MTL::CommandBufferDescriptor *descriptor = MTL::CommandBufferDescriptor* descriptor = MTL::CommandBufferDescriptor::alloc()->init();
MTL::CommandBufferDescriptor::alloc()->init();
activeCommand = new Command(graphics, queue->commandBuffer(descriptor)); activeCommand = new Command(graphics, queue->commandBuffer(descriptor));
descriptor->release(); descriptor->release();
} }
@@ -286,9 +182,7 @@ ORenderCommand CommandQueue::getRenderCommand(const std::string &name) {
return new RenderCommand(activeCommand->createRenderEncoder(), name); return new RenderCommand(activeCommand->createRenderEncoder(), name);
} }
OComputeCommand CommandQueue::getComputeCommand(const std::string &name) { OComputeCommand CommandQueue::getComputeCommand(const std::string& name) { return new ComputeCommand(queue->commandBuffer(), name); }
return new ComputeCommand(queue->commandBuffer(), name);
}
void CommandQueue::executeCommands(Array<Gfx::ORenderCommand> commands) { void CommandQueue::executeCommands(Array<Gfx::ORenderCommand> commands) {
for (auto& command : commands) { for (auto& command : commands) {
@@ -306,10 +200,8 @@ void CommandQueue::executeCommands(Array<Gfx::OComputeCommand> commands) {
} }
void CommandQueue::submitCommands(PEvent signalSemaphore) { void CommandQueue::submitCommands(PEvent signalSemaphore) {
activeCommand->getHandle()->addCompletedHandler( activeCommand->getHandle()->addCompletedHandler(MTL::CommandBufferHandler([&](MTL::CommandBuffer* cmdBuffer) {
MTL::CommandBufferHandler([&](MTL::CommandBuffer *cmdBuffer) { for (auto it = pendingCommands.begin(); it != pendingCommands.end(); it++) {
for (auto it = pendingCommands.begin(); it != pendingCommands.end();
it++) {
if ((*it)->getHandle() == cmdBuffer) { if ((*it)->getHandle() == cmdBuffer) {
pendingCommands.remove(it); pendingCommands.remove(it);
return; return;
@@ -320,17 +212,14 @@ void CommandQueue::submitCommands(PEvent signalSemaphore) {
activeCommand->waitDeviceIdle(); activeCommand->waitDeviceIdle();
PEvent prevCmdEvent = activeCommand->getCompletedEvent(); PEvent prevCmdEvent = activeCommand->getCompletedEvent();
pendingCommands.add(std::move(activeCommand)); pendingCommands.add(std::move(activeCommand));
MTL::CommandBufferDescriptor *descriptor = MTL::CommandBufferDescriptor* descriptor = MTL::CommandBufferDescriptor::alloc()->init();
MTL::CommandBufferDescriptor::alloc()->init(); descriptor->setErrorOptions(MTL::CommandBufferErrorOptionEncoderExecutionStatus);
descriptor->setErrorOptions(
MTL::CommandBufferErrorOptionEncoderExecutionStatus);
activeCommand = new Command(graphics, queue->commandBuffer(descriptor)); activeCommand = new Command(graphics, queue->commandBuffer(descriptor));
activeCommand->waitForEvent(prevCmdEvent); activeCommand->waitForEvent(prevCmdEvent);
} }
IOCommandQueue::IOCommandQueue(PGraphics graphics) : graphics(graphics) { IOCommandQueue::IOCommandQueue(PGraphics graphics) : graphics(graphics) {
MTL::IOCommandQueueDescriptor *desc = MTL::IOCommandQueueDescriptor* desc = MTL::IOCommandQueueDescriptor::alloc()->init();
MTL::IOCommandQueueDescriptor::alloc()->init();
desc->setType(MTL::IOCommandQueueTypeConcurrent); desc->setType(MTL::IOCommandQueueTypeConcurrent);
desc->setPriority(MTL::IOPriorityNormal); desc->setPriority(MTL::IOPriorityNormal);
queue = graphics->getDevice()->newIOCommandQueue(desc, nullptr); queue = graphics->getDevice()->newIOCommandQueue(desc, nullptr);
+6 -7
View File
@@ -1,11 +1,13 @@
#pragma once #pragma once
#include "Buffer.h" #include "Buffer.h"
#include "Foundation/NSArray.hpp" #include "Foundation/NSArray.hpp"
#include "Foundation/NSObject.hpp"
#include "Graphics/Descriptor.h" #include "Graphics/Descriptor.h"
#include "Graphics/Initializer.h" #include "Graphics/Initializer.h"
#include "Graphics/Metal/Resources.h" #include "Graphics/Metal/Resources.h"
#include "Metal/MTLArgumentEncoder.hpp" #include "Metal/MTLArgumentEncoder.hpp"
#include "Metal/MTLLibrary.hpp" #include "Metal/MTLLibrary.hpp"
#include "Metal/MTLResource.hpp"
#include "MinimalEngine.h" #include "MinimalEngine.h"
namespace Seele { namespace Seele {
@@ -16,13 +18,11 @@ class DescriptorLayout : public Gfx::DescriptorLayout {
DescriptorLayout(PGraphics graphics, const std::string& name); DescriptorLayout(PGraphics graphics, const std::string& name);
virtual ~DescriptorLayout(); virtual ~DescriptorLayout();
virtual void create() override; virtual void create() override;
void setFunction(MTL::Function* func, uint64 ind) { function = func; index = ind; } MTL::ArgumentEncoder* createEncoder();
MTL::ArgumentEncoder* createEncoder() { return function->newArgumentEncoder(index); }
private: private:
PGraphics graphics; PGraphics graphics;
MTL::Function* function; NS::Array* arguments;
uint64 index;
}; };
DEFINE_REF(DescriptorLayout) DEFINE_REF(DescriptorLayout)
@@ -59,15 +59,14 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
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 MTL::Buffer* getBuffer() const { return buffer; }
constexpr const Array<Array<MTL::Resource*>>& getBoundResources() const { return boundResources; } constexpr const Array<Array<MTL::Resource*>>& getBoundResources() const { return boundResources; }
private: private:
PGraphics graphics; PGraphics graphics;
PDescriptorPool owner; PDescriptorPool owner;
MTL::ArgumentEncoder* encoder;
MTL::Buffer* buffer = nullptr;
Array<Array<MTL::Resource*>> boundResources; Array<Array<MTL::Resource*>> boundResources;
MTL::ArgumentEncoder* encoder;
MTL::Buffer* argumentBuffer = nullptr;
}; };
DEFINE_REF(DescriptorSet) DEFINE_REF(DescriptorSet)
+51 -48
View File
@@ -1,37 +1,49 @@
#include "Descriptor.h" #include "Descriptor.h"
#include "Buffer.h" #include "Buffer.h"
#include "Enums.h" #include "Enums.h"
#include "Foundation/NSArray.hpp"
#include "Foundation/NSObject.hpp" #include "Foundation/NSObject.hpp"
#include "Graphics/Descriptor.h" #include "Graphics/Descriptor.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 "Metal/MTLArgument.hpp" #include "Metal/MTLArgument.hpp"
#include "Metal/MTLArgumentEncoder.hpp"
#include "Metal/MTLDevice.hpp" #include "Metal/MTLDevice.hpp"
#include "Metal/MTLResource.hpp" #include "Metal/MTLResource.hpp"
#include "Metal/MTLStageInputOutputDescriptor.hpp"
#include "Metal/MTLTexture.hpp" #include "Metal/MTLTexture.hpp"
#include "Texture.h" #include "Texture.h"
#include <Foundation/Foundation.h>
#include <CRC.h> #include <CRC.h>
#include <Foundation/Foundation.h>
#include <iostream> #include <iostream>
using namespace Seele; using namespace Seele;
using namespace Seele::Metal; using namespace Seele::Metal;
DescriptorLayout::DescriptorLayout(PGraphics graphics, const std::string &name) DescriptorLayout::DescriptorLayout(PGraphics graphics, const std::string& name) : Gfx::DescriptorLayout(name), graphics(graphics) {}
: Gfx::DescriptorLayout(name), graphics(graphics) {}
DescriptorLayout::~DescriptorLayout() {} DescriptorLayout::~DescriptorLayout() {}
void DescriptorLayout::create() { void DescriptorLayout::create() {
pool = new DescriptorPool(graphics, this); pool = new DescriptorPool(graphics, this);
hash = hash = CRC::Calculate(descriptorBindings.data(), sizeof(Gfx::DescriptorBinding) * descriptorBindings.size(), CRC::CRC_32());
CRC::Calculate(descriptorBindings.data(), MTL::ArgumentDescriptor** objects = new MTL::ArgumentDescriptor*[descriptorBindings.size()];
sizeof(Gfx::DescriptorBinding) * descriptorBindings.size(), for(uint32 i = 0; i < descriptorBindings.size(); ++i) {
CRC::CRC_32()); 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);
}
arguments = NS::Array::array((NS::Object**)objects, descriptorBindings.size());
} }
DescriptorPool::DescriptorPool(PGraphics graphics, PDescriptorLayout layout) MTL::ArgumentEncoder* DescriptorLayout::createEncoder() {
: graphics(graphics), layout(layout) {} return graphics->getDevice()->newArgumentEncoder(arguments);
}
DescriptorPool::DescriptorPool(PGraphics graphics, PDescriptorLayout layout) : graphics(graphics), layout(layout) {}
DescriptorPool::~DescriptorPool() {} DescriptorPool::~DescriptorPool() {}
@@ -49,63 +61,55 @@ Gfx::PDescriptorSet DescriptorPool::allocateDescriptorSet() {
return PDescriptorSet(allocatedSets.back()); return PDescriptorSet(allocatedSets.back());
} }
void DescriptorPool::reset() { void DescriptorPool::reset() {}
}
DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner) DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner)
: Gfx::DescriptorSet(owner->getLayout()), CommandBoundResource(graphics), : Gfx::DescriptorSet(owner->getLayout()), CommandBoundResource(graphics), 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); boundResources[i].resize(owner->getLayout()->getBindings()[i].descriptorCount);
} }
encoder = owner->getLayout()->createEncoder();
buffer = graphics->getDevice()->newBuffer(encoder->encodedLength(), MTL::ResourceOptionCPUCacheModeDefault);
buffer->setLabel(NS::String::string(owner->getLayout()->getName().c_str(),
NS::ASCIIStringEncoding));
} }
DescriptorSet::~DescriptorSet() { buffer->release(); } 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();
encoder->setBuffer(uniformBuffer.cast<UniformBuffer>()->getHandle(), 0, binding);
} }
void DescriptorSet::updateBuffer(uint32 binding, Gfx::PShaderBuffer uniformBuffer) void DescriptorSet::updateBuffer(uint32 binding, Gfx::PShaderBuffer uniformBuffer) {
{ boundResources[binding][0] = uniformBuffer.cast<ShaderBuffer>()->getHandle();
encoder->setBuffer(uniformBuffer.cast<ShaderBuffer>()->getHandle(), 0, binding);
} }
void DescriptorSet::updateBuffer(uint32 binding, Gfx::PIndexBuffer uniformBuffer) void DescriptorSet::updateBuffer(uint32 binding, Gfx::PIndexBuffer uniformBuffer) {
{ boundResources[binding][0] = uniformBuffer.cast<IndexBuffer>()->getHandle();
encoder->setBuffer(uniformBuffer.cast<IndexBuffer>()->getHandle(), 0, binding);
} }
void DescriptorSet::updateBuffer(uint32 binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) void DescriptorSet::updateBuffer(uint32 binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) {
{ boundResources[binding][0] = uniformBuffer.cast<ShaderBuffer>()->getHandle();
encoder->setBuffer(uniformBuffer.cast<ShaderBuffer>()->getHandle(), 0, binding);
} }
void DescriptorSet::updateSampler(uint32 binding, Gfx::PSampler samplerState) void DescriptorSet::updateSampler(uint32 binding, Gfx::PSampler samplerState) {
{} boundResources[binding][0] = 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)
{}
void DescriptorSet::updateTexture(uint32 binding, uint32 dstArrayIndex, Gfx::PTexture texture)
{}
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)
{}
PipelineLayout::PipelineLayout(PGraphics graphics, const std::string &name, void DescriptorSet::updateSampler(uint32 binding, uint32 dstArrayIndex, Gfx::PSampler samplerState) {
Gfx::PPipelineLayout baseLayout) boundResources[binding][dstArrayIndex] = nullptr;
}
void DescriptorSet::updateTexture(uint32 binding, Gfx::PTexture texture, Gfx::PSampler sampler) {}
void DescriptorSet::updateTexture(uint32 binding, uint32 dstArrayIndex, Gfx::PTexture texture) {}
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) {}
PipelineLayout::PipelineLayout(PGraphics graphics, const std::string& name, Gfx::PPipelineLayout baseLayout)
: Gfx::PipelineLayout(name, baseLayout), graphics(graphics) {} : Gfx::PipelineLayout(name, baseLayout), graphics(graphics) {}
PipelineLayout::~PipelineLayout() {} PipelineLayout::~PipelineLayout() {}
@@ -114,7 +118,6 @@ void PipelineLayout::create() {
for (auto& [_, set] : descriptorSetLayouts) { for (auto& [_, set] : descriptorSetLayouts) {
assert(set->getHash() != 0); assert(set->getHash() != 0);
uint32 setHash = set->getHash(); uint32 setHash = set->getHash();
layoutHash = layoutHash = CRC::Calculate(&setHash, sizeof(uint32), CRC::CRC_32(), layoutHash);
CRC::Calculate(&setHash, sizeof(uint32), CRC::CRC_32(), layoutHash);
} }
} }
+1 -2
View File
@@ -767,8 +767,7 @@ Gfx::SeSamplerAddressMode Seele::Metal::cast(MTL::SamplerAddressMode mode) {
} }
} }
MTL::PrimitiveTopologyClass MTL::PrimitiveTopologyClass Seele::Metal::cast(Gfx::SePrimitiveTopology topology) {
Seele::Metal::cast(Gfx::SePrimitiveTopology topology) {
switch (topology) { switch (topology) {
case Gfx::SE_PRIMITIVE_TOPOLOGY_POINT_LIST: case Gfx::SE_PRIMITIVE_TOPOLOGY_POINT_LIST:
return MTL::PrimitiveTopologyClassPoint; return MTL::PrimitiveTopologyClassPoint;
+1 -1
View File
@@ -2,7 +2,6 @@
#include "Graphics/Graphics.h" #include "Graphics/Graphics.h"
#include "Metal/Metal.hpp" #include "Metal/Metal.hpp"
namespace Seele { namespace Seele {
namespace Metal { namespace Metal {
DECLARE_REF(CommandQueue) DECLARE_REF(CommandQueue)
@@ -24,6 +23,7 @@ class Graphics : public Gfx::Graphics {
virtual void waitDeviceIdle() override; virtual void waitDeviceIdle() override;
virtual void executeCommands(Array<Gfx::ORenderCommand> commands) override; virtual void executeCommands(Array<Gfx::ORenderCommand> commands) override;
virtual void executeCommands(Gfx::OComputeCommand commands) override;
virtual void executeCommands(Array<Gfx::OComputeCommand> commands) override; virtual void executeCommands(Array<Gfx::OComputeCommand> commands) override;
virtual Gfx::OTexture2D createTexture2D(const TextureCreateInfo& createInfo) override; virtual Gfx::OTexture2D createTexture2D(const TextureCreateInfo& createInfo) override;
+45 -106
View File
@@ -1,17 +1,19 @@
#include "Graphics.h" #include "Graphics.h"
#include "Buffer.h" #include "Buffer.h"
#include "Command.h" #include "Command.h"
#include "Graphics/Graphics.h"
#include "Graphics/Initializer.h" #include "Graphics/Initializer.h"
#include "Graphics/Metal/Descriptor.h" #include "Graphics/Metal/Descriptor.h"
#include "Graphics/Metal/Pipeline.h" #include "Graphics/Metal/Pipeline.h"
#include "Graphics/Metal/PipelineCache.h" #include "Graphics/Metal/PipelineCache.h"
#include "Graphics/Metal/Query.h"
#include "Graphics/Metal/Resources.h" #include "Graphics/Metal/Resources.h"
#include "Graphics/slang-compile.h"
#include "RenderPass.h" #include "RenderPass.h"
#include "Resources.h" #include "Resources.h"
#include "Shader.h" #include "Shader.h"
#include "Window.h" #include "Window.h"
#include <slang.h> #include <slang.h>
#include "Graphics/slang-compile.h"
using namespace Seele; using namespace Seele;
using namespace Seele::Metal; using namespace Seele::Metal;
@@ -26,193 +28,131 @@ void Graphics::init(GraphicsInitializer) {
queue = new CommandQueue(this); queue = new CommandQueue(this);
ioQueue = new IOCommandQueue(this); ioQueue = new IOCommandQueue(this);
cache = new PipelineCache(this, "pipelines.metal"); cache = new PipelineCache(this, "pipelines.metal");
meshShadingEnabled = false; meshShadingEnabled = true;
} }
Gfx::OWindow Graphics::createWindow(const WindowCreateInfo &createInfo) { Gfx::OWindow Graphics::createWindow(const WindowCreateInfo& createInfo) { return new Window(this, createInfo); }
return new Window(this, createInfo);
}
Gfx::OViewport Graphics::createViewport(Gfx::PWindow owner, Gfx::OViewport Graphics::createViewport(Gfx::PWindow owner, const ViewportCreateInfo& createInfo) {
const ViewportCreateInfo &createInfo) {
return new Viewport(owner, createInfo); return new Viewport(owner, createInfo);
} }
Gfx::ORenderPass Gfx::ORenderPass Graphics::createRenderPass(Gfx::RenderTargetLayout layout, Array<Gfx::SubPassDependency> dependencies,
Graphics::createRenderPass(Gfx::RenderTargetLayout layout,
Array<Gfx::SubPassDependency> dependencies,
Gfx::PViewport renderArea, std::string name) { Gfx::PViewport renderArea, std::string name) {
return new RenderPass(this, layout, dependencies, renderArea, name); return new RenderPass(this, layout, dependencies, renderArea, name);
} }
void Graphics::beginRenderPass(Gfx::PRenderPass renderPass) { void Graphics::beginRenderPass(Gfx::PRenderPass renderPass) { queue->getCommands()->beginRenderPass(renderPass.cast<RenderPass>()); }
queue->getCommands()->beginRenderPass(renderPass.cast<RenderPass>());
}
void Graphics::endRenderPass() { queue->getCommands()->endRenderPass(); } void Graphics::endRenderPass() { queue->getCommands()->endRenderPass(); }
void Graphics::waitDeviceIdle() { queue->getCommands()->waitDeviceIdle(); } void Graphics::waitDeviceIdle() { queue->getCommands()->waitDeviceIdle(); }
void Graphics::executeCommands(Array<Gfx::ORenderCommand> commands) { void Graphics::executeCommands(Array<Gfx::ORenderCommand> commands) { queue->executeCommands(std::move(commands)); }
queue->executeCommands(std::move(commands));
void Graphics::executeCommands(Gfx::OComputeCommand commands) {
Array<Gfx::OComputeCommand> command;
command.add(std::move(commands));
queue->executeCommands(std::move(command));
} }
void Graphics::executeCommands(Array<Gfx::OComputeCommand> commands) { void Graphics::executeCommands(Array<Gfx::OComputeCommand> commands) { queue->executeCommands(std::move(commands)); }
queue->executeCommands(std::move(commands));
}
Gfx::OTexture2D Graphics::createTexture2D(const TextureCreateInfo &createInfo) { Gfx::OTexture2D Graphics::createTexture2D(const TextureCreateInfo& createInfo) { return new Texture2D(this, createInfo); }
return new Texture2D(this, createInfo);
}
Gfx::OTexture3D Graphics::createTexture3D(const TextureCreateInfo &createInfo) { Gfx::OTexture3D Graphics::createTexture3D(const TextureCreateInfo& createInfo) { return new Texture3D(this, createInfo); }
return new Texture3D(this, createInfo); Gfx::OTextureCube Graphics::createTextureCube(const TextureCreateInfo& createInfo) { return new TextureCube(this, createInfo); }
}
Gfx::OTextureCube Gfx::OUniformBuffer Graphics::createUniformBuffer(const UniformBufferCreateInfo& bulkData) { return new UniformBuffer(this, bulkData); }
Graphics::createTextureCube(const TextureCreateInfo &createInfo) {
return new TextureCube(this, createInfo);
}
Gfx::OUniformBuffer Gfx::OShaderBuffer Graphics::createShaderBuffer(const ShaderBufferCreateInfo& bulkData) { return new ShaderBuffer(this, bulkData); }
Graphics::createUniformBuffer(const UniformBufferCreateInfo &bulkData) {
return new UniformBuffer(this, bulkData);
}
Gfx::OShaderBuffer Gfx::OVertexBuffer Graphics::createVertexBuffer(const VertexBufferCreateInfo& bulkData) { return new VertexBuffer(this, bulkData); }
Graphics::createShaderBuffer(const ShaderBufferCreateInfo &bulkData) {
return new ShaderBuffer(this, bulkData);
}
Gfx::OVertexBuffer Gfx::OIndexBuffer Graphics::createIndexBuffer(const IndexBufferCreateInfo& bulkData) { return new IndexBuffer(this, bulkData); }
Graphics::createVertexBuffer(const VertexBufferCreateInfo &bulkData) {
return new VertexBuffer(this, bulkData);
}
Gfx::OIndexBuffer Gfx::ORenderCommand Graphics::createRenderCommand(const std::string& name) { return queue->getRenderCommand(name); }
Graphics::createIndexBuffer(const IndexBufferCreateInfo &bulkData) {
return new IndexBuffer(this, bulkData);
}
Gfx::ORenderCommand Graphics::createRenderCommand(const std::string &name) { Gfx::OComputeCommand Graphics::createComputeCommand(const std::string& name) { return queue->getComputeCommand(name); }
return queue->getRenderCommand(name);
}
Gfx::OComputeCommand Graphics::createComputeCommand(const std::string &name) {
return queue->getComputeCommand(name);
}
void Graphics::beginShaderCompilation(const ShaderCompilationInfo& compileInfo) { void Graphics::beginShaderCompilation(const ShaderCompilationInfo& compileInfo) {
beginCompilation(compileInfo, SLANG_METAL, compileInfo.rootSignature); beginCompilation(compileInfo, SLANG_METAL, compileInfo.rootSignature);
} }
Gfx::OVertexShader Gfx::OVertexShader Graphics::createVertexShader(const ShaderCreateInfo& createInfo) {
Graphics::createVertexShader(const ShaderCreateInfo &createInfo) {
OVertexShader result = new VertexShader(this); OVertexShader result = new VertexShader(this);
result->create(createInfo); result->create(createInfo);
return result; return result;
} }
Gfx::OFragmentShader Gfx::OFragmentShader Graphics::createFragmentShader(const ShaderCreateInfo& createInfo) {
Graphics::createFragmentShader(const ShaderCreateInfo &createInfo) {
OFragmentShader result = new FragmentShader(this); OFragmentShader result = new FragmentShader(this);
result->create(createInfo); result->create(createInfo);
return result; return result;
} }
Gfx::OComputeShader Gfx::OComputeShader Graphics::createComputeShader(const ShaderCreateInfo& createInfo) {
Graphics::createComputeShader(const ShaderCreateInfo &createInfo) {
OComputeShader result = new ComputeShader(this); OComputeShader result = new ComputeShader(this);
result->create(createInfo); result->create(createInfo);
return result; return result;
} }
Gfx::OMeshShader Gfx::OMeshShader Graphics::createMeshShader(const ShaderCreateInfo& createInfo) {
Graphics::createMeshShader(const ShaderCreateInfo &createInfo) {
OMeshShader result = new MeshShader(this); OMeshShader result = new MeshShader(this);
result->create(createInfo); result->create(createInfo);
return result; return result;
} }
Gfx::OTaskShader Gfx::OTaskShader Graphics::createTaskShader(const ShaderCreateInfo& createInfo) {
Graphics::createTaskShader(const ShaderCreateInfo &createInfo) {
OTaskShader result = new TaskShader(this); OTaskShader result = new TaskShader(this);
result->create(createInfo); result->create(createInfo);
return result; return result;
} }
Gfx::PGraphicsPipeline Gfx::PGraphicsPipeline Graphics::createGraphicsPipeline(Gfx::LegacyPipelineCreateInfo createInfo) {
Graphics::createGraphicsPipeline(Gfx::LegacyPipelineCreateInfo createInfo) {
return cache->createPipeline(std::move(createInfo)); return cache->createPipeline(std::move(createInfo));
} }
Gfx::PGraphicsPipeline Gfx::PGraphicsPipeline Graphics::createGraphicsPipeline(Gfx::MeshPipelineCreateInfo createInfo) {
Graphics::createGraphicsPipeline(Gfx::MeshPipelineCreateInfo createInfo) {
return cache->createPipeline(std::move(createInfo)); return cache->createPipeline(std::move(createInfo));
} }
Gfx::PComputePipeline Gfx::PComputePipeline Graphics::createComputePipeline(Gfx::ComputePipelineCreateInfo createInfo) {
Graphics::createComputePipeline(Gfx::ComputePipelineCreateInfo createInfo) {
return cache->createPipeline(std::move(createInfo)); return cache->createPipeline(std::move(createInfo));
} }
Gfx::PRayTracingPipeline Graphics::createRayTracingPipeline(Gfx::RayTracingPipelineCreateInfo createInfo) { Gfx::PRayTracingPipeline Graphics::createRayTracingPipeline(Gfx::RayTracingPipelineCreateInfo createInfo) { return nullptr; }
return nullptr;
}
Gfx::OSampler Graphics::createSampler(const SamplerCreateInfo &createInfo) { Gfx::OSampler Graphics::createSampler(const SamplerCreateInfo& createInfo) { return new Sampler(this, createInfo); }
return new Sampler(this, createInfo);
}
Gfx::ODescriptorLayout Gfx::ODescriptorLayout Graphics::createDescriptorLayout(const std::string& name) { return new DescriptorLayout(this, name); }
Graphics::createDescriptorLayout(const std::string &name) {
return new DescriptorLayout(this, name);
}
Gfx::OPipelineLayout Gfx::OPipelineLayout Graphics::createPipelineLayout(const std::string& name, Gfx::PPipelineLayout baseLayout) {
Graphics::createPipelineLayout(const std::string &name,
Gfx::PPipelineLayout baseLayout) {
return new PipelineLayout(this, name, baseLayout); return new PipelineLayout(this, name, baseLayout);
} }
Gfx::OVertexInput Gfx::OVertexInput Graphics::createVertexInput(VertexInputStateCreateInfo createInfo) { return new VertexInput(createInfo); }
Graphics::createVertexInput(VertexInputStateCreateInfo createInfo) {
return new VertexInput(createInfo);
}
Gfx::OOcclusionQuery Graphics::createOcclusionQuery(const std::string& name) { return new OcclusionQuery(this, name); }
Gfx::OOcclusionQuery Graphics::createOcclusionQuery(const std::string& name) {
}
Gfx::OPipelineStatisticsQuery Graphics::createPipelineStatisticsQuery(const std::string& name) { Gfx::OPipelineStatisticsQuery Graphics::createPipelineStatisticsQuery(const std::string& name) {
return new PipelineStatisticsQuery(this, name);
} }
Gfx::OTimestampQuery Graphics::createTimestampQuery(uint64 numTimestamps, const std::string& name) { Gfx::OTimestampQuery Graphics::createTimestampQuery(uint64 numTimestamps, const std::string& name) {
return new TimestampQuery(this, name, numTimestamps);
} }
void Graphics::resolveTexture(Gfx::PTexture source, Gfx::PTexture destination) { void Graphics::resolveTexture(Gfx::PTexture source, Gfx::PTexture destination) {}
}
void Graphics::copyTexture(Gfx::PTexture src, Gfx::PTexture dst) {
}
void Graphics::copyTexture(Gfx::PTexture src, Gfx::PTexture dst) {}
// Ray Tracing // Ray Tracing
Gfx::OBottomLevelAS Graphics::createBottomLevelAccelerationStructure(const Gfx::BottomLevelASCreateInfo& createInfo) { Gfx::OBottomLevelAS Graphics::createBottomLevelAccelerationStructure(const Gfx::BottomLevelASCreateInfo& createInfo) { return nullptr; }
return nullptr;
}
Gfx::OTopLevelAS Graphics::createTopLevelAccelerationStructure(const Gfx::TopLevelASCreateInfo& createInfo) { Gfx::OTopLevelAS Graphics::createTopLevelAccelerationStructure(const Gfx::TopLevelASCreateInfo& createInfo) { return nullptr; }
return nullptr;
}
void Graphics::buildBottomLevelAccelerationStructures(Array<Gfx::PBottomLevelAS> data) { void Graphics::buildBottomLevelAccelerationStructures(Array<Gfx::PBottomLevelAS> data) {}
}
Gfx::ORayGenShader Graphics::createRayGenShader(const ShaderCreateInfo& createInfo) { Gfx::ORayGenShader Graphics::createRayGenShader(const ShaderCreateInfo& createInfo) {
ORayGenShader shader = new RayGenShader(this); ORayGenShader shader = new RayGenShader(this);
@@ -244,4 +184,3 @@ Gfx::OCallableShader Graphics::createCallableShader(const ShaderCreateInfo& crea
shader->create(createInfo); shader->create(createInfo);
return shader; return shader;
} }
+4 -10
View File
@@ -7,23 +7,17 @@
using namespace Seele; using namespace Seele;
using namespace Seele::Metal; using namespace Seele::Metal;
VertexInput::VertexInput(VertexInputStateCreateInfo createInfo) VertexInput::VertexInput(VertexInputStateCreateInfo createInfo) : Gfx::VertexInput(createInfo) {}
: Gfx::VertexInput(createInfo) {}
VertexInput::~VertexInput() {} VertexInput::~VertexInput() {}
GraphicsPipeline::GraphicsPipeline(PGraphics graphics, GraphicsPipeline::GraphicsPipeline(PGraphics graphics, MTL::PrimitiveType primitive, MTL::RenderPipelineState* pipeline,
MTL::PrimitiveType primitive,
MTL::RenderPipelineState *pipeline,
Gfx::PPipelineLayout layout) Gfx::PPipelineLayout layout)
: Gfx::GraphicsPipeline(layout), graphics(graphics), state(pipeline), : Gfx::GraphicsPipeline(layout), graphics(graphics), state(pipeline), primitiveType(primitive) {}
primitiveType(primitive) {}
GraphicsPipeline::~GraphicsPipeline() {} GraphicsPipeline::~GraphicsPipeline() {}
ComputePipeline::ComputePipeline(PGraphics graphics, ComputePipeline::ComputePipeline(PGraphics graphics, MTL::ComputePipelineState* pipeline, Gfx::PPipelineLayout layout)
MTL::ComputePipelineState *pipeline,
Gfx::PPipelineLayout layout)
: Gfx::ComputePipeline(layout), graphics(graphics), state(pipeline) {} : Gfx::ComputePipeline(layout), graphics(graphics), state(pipeline) {}
ComputePipeline::~ComputePipeline() {} ComputePipeline::~ComputePipeline() {}
+57
View File
@@ -0,0 +1,57 @@
#pragma once
#include "Buffer.h"
#include "Graphics.h"
#include "Graphics/Query.h"
namespace Seele {
namespace Metal {
class QueryPool {
public:
QueryPool(PGraphics graphics, const std::string& name);
virtual ~QueryPool();
void begin();
void end();
// stalls for the currently first pending query, dont call in render thread
void getQueryResults(Array<uint64>& results);
protected:
PGraphics graphics;
};
class OcclusionQuery : public Gfx::OcclusionQuery, public QueryPool {
public:
OcclusionQuery(PGraphics graphics, const std::string& name);
virtual ~OcclusionQuery();
virtual void beginQuery() override;
virtual void endQuery() override;
virtual Gfx::OcclusionResult getResults() override;
};
DEFINE_REF(OcclusionQuery)
class PipelineStatisticsQuery : public Gfx::PipelineStatisticsQuery, public QueryPool {
public:
PipelineStatisticsQuery(PGraphics graphics, const std::string& name);
virtual ~PipelineStatisticsQuery();
virtual void beginQuery() override;
virtual void endQuery() override;
virtual Gfx::PipelineStatisticsResult getResults() override;
};
DEFINE_REF(PipelineStatisticsQuery)
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;
private:
uint64 wrapping = 0;
uint64 lastMeasure = 0;
uint32 numTimestamps = 0;
uint32 currentTimestamp = 0;
Array<std::string> pendingTimestamps;
};
DEFINE_REF(TimestampQuery)
} // namespace Vulkan
} // namespace Seele
+86
View File
@@ -0,0 +1,86 @@
#include "Query.h"
#include "Buffer.h"
#include "Command.h"
#include "Containers/Array.h"
#include "Enums.h"
#include "Graphics.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() { }
void QueryPool::begin() {
}
void QueryPool::end() {
}
void QueryPool::getQueryResults(Array<uint64>& results) {
}
OcclusionQuery::OcclusionQuery(PGraphics graphics, const std::string& name)
: QueryPool(graphics, name) {}
OcclusionQuery::~OcclusionQuery() {}
void OcclusionQuery::beginQuery() { begin(); }
void OcclusionQuery::endQuery() { end(); }
Gfx::OcclusionResult OcclusionQuery::getResults() {
Array<uint64> result(1);
getQueryResults(result);
return Gfx::OcclusionResult{
.numFragments = result[0],
};
}
PipelineStatisticsQuery::PipelineStatisticsQuery(PGraphics graphics, const std::string& name)
: QueryPool(graphics, name) {}
PipelineStatisticsQuery::~PipelineStatisticsQuery() {}
void PipelineStatisticsQuery::beginQuery() { begin(); }
void PipelineStatisticsQuery::endQuery() { end(); }
Gfx::PipelineStatisticsResult PipelineStatisticsQuery::getResults() {
Array<uint64> result(9);
getQueryResults(result);
return Gfx::PipelineStatisticsResult{
.inputAssemblyVertices = result[0],
.inputAssemblyPrimitives = result[1],
.vertexShaderInvocations = result[2],
.clippingInvocations = result[3],
.clippingPrimitives = result[4],
.fragmentShaderInvocations = result[5],
.computeShaderInvocations = result[6],
.taskShaderInvocations = result[7],
.meshShaderInvocations = result[8],
};
}
TimestampQuery::TimestampQuery(PGraphics graphics, const std::string& name, uint32 numTimestamps)
: QueryPool(graphics, name), numTimestamps(numTimestamps) {
}
TimestampQuery::~TimestampQuery() {}
void TimestampQuery::begin() {
currentTimestamp = 0;
}
void TimestampQuery::write(Gfx::SePipelineStageFlagBits stage, const std::string& name) {
}
void TimestampQuery::end() {
}
Array<Gfx::Timestamp> TimestampQuery::getResults() {
}
+2 -1
View File
@@ -7,7 +7,8 @@ namespace Metal {
DECLARE_REF(Graphics) DECLARE_REF(Graphics)
class RenderPass : public Gfx::RenderPass { class RenderPass : public Gfx::RenderPass {
public: public:
RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout, Array<Gfx::SubPassDependency> dependencies, Gfx::PViewport viewport, const std::string& name = ""); RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout, Array<Gfx::SubPassDependency> dependencies, Gfx::PViewport viewport,
const std::string& name = "");
virtual ~RenderPass(); virtual ~RenderPass();
void updateRenderPass(); void updateRenderPass();
MTL::RenderPassDescriptor* getDescriptor() const { return renderPass; } MTL::RenderPassDescriptor* getDescriptor() const { return renderPass; }
+8 -16
View File
@@ -7,11 +7,9 @@
using namespace Seele; using namespace Seele;
using namespace Seele::Metal; using namespace Seele::Metal;
RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout, RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout, Array<Gfx::SubPassDependency> dependencies,
Array<Gfx::SubPassDependency> dependencies,
Gfx::PViewport viewport, const std::string& name) Gfx::PViewport viewport, const std::string& name)
: Gfx::RenderPass(layout, dependencies), graphics(graphics), : Gfx::RenderPass(layout, dependencies), graphics(graphics), viewport(viewport) {
viewport(viewport) {
renderPass = MTL::RenderPassDescriptor::renderPassDescriptor(); renderPass = MTL::RenderPassDescriptor::renderPassDescriptor();
renderPass->setRenderTargetArrayLength(1); renderPass->setRenderTargetArrayLength(1);
renderPass->setRenderTargetWidth(viewport->getWidth()); renderPass->setRenderTargetWidth(viewport->getWidth());
@@ -20,11 +18,9 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout,
for (size_t i = 0; i < layout.colorAttachments.size(); ++i) { for (size_t i = 0; i < layout.colorAttachments.size(); ++i) {
const auto& color = layout.colorAttachments[i]; const auto& color = layout.colorAttachments[i];
MTL::RenderPassColorAttachmentDescriptor *desc = MTL::RenderPassColorAttachmentDescriptor* desc = renderPass->colorAttachments()->object(i);
renderPass->colorAttachments()->object(i); desc->setClearColor(MTL::ClearColor(color.clear.color.float32[0], color.clear.color.float32[1], color.clear.color.float32[2],
desc->setClearColor(MTL::ClearColor( color.clear.color.float32[3]));
color.clear.color.float32[0], color.clear.color.float32[1],
color.clear.color.float32[2], color.clear.color.float32[3]));
desc->setLoadAction(cast(color.getLoadOp())); desc->setLoadAction(cast(color.getLoadOp()));
desc->setStoreAction(cast(color.getStoreOp())); desc->setStoreAction(cast(color.getStoreOp()));
desc->setLevel(0); desc->setLevel(0);
@@ -32,8 +28,7 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout,
const auto& resolve = layout.resolveAttachments[i]; const auto& resolve = layout.resolveAttachments[i];
desc->setResolveLevel(0); desc->setResolveLevel(0);
desc->setStoreAction(MTL::StoreActionStoreAndMultisampleResolve); desc->setStoreAction(MTL::StoreActionStoreAndMultisampleResolve);
desc->setResolveTexture( desc->setResolveTexture(resolve.getTexture().cast<TextureBase>()->getImage());
resolve.getTexture().cast<TextureBase>()->getImage());
} }
} }
if (layout.depthAttachment.getTexture() != nullptr) { if (layout.depthAttachment.getTexture() != nullptr) {
@@ -43,9 +38,7 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout,
depth->setStoreAction(cast(layout.depthAttachment.getStoreOp())); depth->setStoreAction(cast(layout.depthAttachment.getStoreOp()));
if (layout.depthResolveAttachment.getTexture() != nullptr) { if (layout.depthResolveAttachment.getTexture() != nullptr) {
depth->setResolveTexture(layout.depthResolveAttachment.getTexture() depth->setResolveTexture(layout.depthResolveAttachment.getTexture().cast<TextureBase>()->getImage());
.cast<TextureBase>()
->getImage());
depth->setStoreAction(MTL::StoreActionStoreAndMultisampleResolve); depth->setStoreAction(MTL::StoreActionStoreAndMultisampleResolve);
} }
} }
@@ -61,7 +54,6 @@ void RenderPass::updateRenderPass() {
} }
if (layout.depthAttachment.getTexture() != nullptr) { if (layout.depthAttachment.getTexture() != nullptr) {
auto depth = renderPass->depthAttachment(); auto depth = renderPass->depthAttachment();
depth->setTexture( depth->setTexture(layout.depthAttachment.getTexture().cast<TextureBase>()->getImage());
layout.depthAttachment.getTexture().cast<TextureBase>()->getImage());
} }
} }
+1 -1
View File
@@ -1,6 +1,6 @@
#pragma once #pragma once
#include "Graphics/Resources.h"
#include "Graphics/Initializer.h" #include "Graphics/Initializer.h"
#include "Graphics/Resources.h"
#include "Metal/MTLSampler.hpp" #include "Metal/MTLSampler.hpp"
#include <Foundation/Foundation.hpp> #include <Foundation/Foundation.hpp>
#include <Metal/Metal.hpp> #include <Metal/Metal.hpp>
-1
View File
@@ -3,7 +3,6 @@
#include "Graphics.h" #include "Graphics.h"
#include "Metal/MTLSampler.hpp" #include "Metal/MTLSampler.hpp"
using namespace Seele; using namespace Seele;
using namespace Seele::Metal; using namespace Seele::Metal;
+10 -17
View File
@@ -14,8 +14,7 @@
using namespace Seele; using namespace Seele;
using namespace Seele::Metal; using namespace Seele::Metal;
Shader::Shader(PGraphics graphics, Gfx::SeShaderStageFlags stage) Shader::Shader(PGraphics graphics, Gfx::SeShaderStageFlags stage) : stage(stage), graphics(graphics) {}
: stage(stage), graphics(graphics) {}
Shader::~Shader() { Shader::~Shader() {
if (function) { if (function) {
@@ -25,29 +24,23 @@ Shader::~Shader() {
} }
void Shader::create(const ShaderCreateInfo& createInfo) { void Shader::create(const ShaderCreateInfo& createInfo) {
Map<std::string, uint32> paramMapping; auto [kernelBlob, entryPoint] = generateShader(createInfo);
auto [kernelBlob, entryPoint] = std::ofstream test("test.metal");
generateShader(createInfo); test.write((char*)kernelBlob->getBufferPointer(), kernelBlob->getBufferSize());
std::cout << (char *)kernelBlob->getBufferPointer() << std::endl; test.close();
hash = CRC::Calculate(kernelBlob->getBufferPointer(), hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32());
kernelBlob->getBufferSize(), CRC::CRC_32());
NS::Error* error; NS::Error* error;
MTL::CompileOptions* options = MTL::CompileOptions::alloc()->init(); MTL::CompileOptions* options = MTL::CompileOptions::alloc()->init();
library = graphics->getDevice()->newLibrary( library = graphics->getDevice()->newLibrary(NS::String::string((char*)kernelBlob->getBufferPointer(), NS::ASCIIStringEncoding), options,
NS::String::string((char *)kernelBlob->getBufferPointer(), &error);
NS::ASCIIStringEncoding),
options, &error);
options->release(); options->release();
if (error) { if (error) {
std::cout << error->localizedDescription()->cString(NS::ASCIIStringEncoding) std::cout << error->localizedDescription()->cString(NS::ASCIIStringEncoding) << std::endl;
<< std::endl;
} }
function = library->newFunction(NS::String::string( function = library->newFunction(NS::String::string(entryPoint.c_str(), NS::ASCIIStringEncoding));
entryPoint.c_str(), NS::ASCIIStringEncoding));
if (!function) { if (!function) {
assert(false); assert(false);
} }
} }
uint32 Shader::getShaderHash() const { return hash; } uint32 Shader::getShaderHash() const { return hash; }
+5 -5
View File
@@ -13,8 +13,8 @@ class TextureHandle {
void pipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess, void pipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage); Gfx::SePipelineStageFlags dstStage);
void transferOwnership(Gfx::QueueType newOwner); void transferOwnership(Gfx::QueueType newOwner);
void changeLayout(Gfx::SeImageLayout newLayout, Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess, void changeLayout(Gfx::SeImageLayout newLayout, Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SePipelineStageFlags dstStage); Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage);
void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer); void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer);
void generateMipmaps(); void generateMipmaps();
@@ -35,7 +35,6 @@ class TextureHandle {
}; };
DEFINE_REF(TextureHandle) DEFINE_REF(TextureHandle)
class TextureBase { class TextureBase {
public: public:
TextureBase(PGraphics graphics, MTL::TextureType textureType, const TextureCreateInfo& createInfo, TextureBase(PGraphics graphics, MTL::TextureType textureType, const TextureCreateInfo& createInfo,
@@ -58,10 +57,11 @@ class TextureBase {
void pipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess, void pipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage); Gfx::SePipelineStageFlags dstStage);
void transferOwnership(Gfx::QueueType newOwner); void transferOwnership(Gfx::QueueType newOwner);
void changeLayout(Gfx::SeImageLayout newLayout, Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess, void changeLayout(Gfx::SeImageLayout newLayout, Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SePipelineStageFlags dstStage); Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage);
void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer); void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer);
void generateMipmaps(); void generateMipmaps();
protected: protected:
OTextureHandle handle; OTextureHandle handle;
// Updates via reference // Updates via reference
+15 -30
View File
@@ -9,21 +9,16 @@
using namespace Seele; using namespace Seele;
using namespace Seele::Metal; using namespace Seele::Metal;
TextureHandle::TextureHandle(PGraphics graphics, MTL::TextureType type, TextureHandle::TextureHandle(PGraphics graphics, MTL::TextureType type, const TextureCreateInfo& createInfo, MTL::Texture* existingImage)
const TextureCreateInfo &createInfo, : texture(existingImage), type(type), width(createInfo.width), height(createInfo.height), depth(createInfo.depth),
MTL::Texture *existingImage) arrayCount(createInfo.elements), layerCount(createInfo.layers), mipLevels(1), samples(createInfo.samples), format(createInfo.format),
: texture(existingImage), usage(createInfo.usage), layout(Gfx::SE_IMAGE_LAYOUT_UNDEFINED), ownsImage(existingImage == nullptr) {
type(type), width(createInfo.width), if (createInfo.useMip) {
height(createInfo.height), depth(createInfo.depth), mipLevels = static_cast<uint32_t>(std::floor(std::log2(std::max(width, height)))) + 1;
arrayCount(createInfo.elements), layerCount(createInfo.layers), }
mipLevels(createInfo.mipLevels), samples(createInfo.samples),
format(createInfo.format), usage(createInfo.usage),
layout(Gfx::SE_IMAGE_LAYOUT_UNDEFINED),
ownsImage(existingImage == nullptr) {
if (existingImage == nullptr) { if (existingImage == nullptr) {
MTL::TextureUsage mtlUsage = 0; MTL::TextureUsage mtlUsage = 0;
if (usage & Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT || if (usage & Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT || usage & Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) {
usage & Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) {
mtlUsage |= MTL::TextureUsageRenderTarget; mtlUsage |= MTL::TextureUsageRenderTarget;
} }
if (usage & Gfx::SE_IMAGE_USAGE_SAMPLED_BIT) { if (usage & Gfx::SE_IMAGE_USAGE_SAMPLED_BIT) {
@@ -32,8 +27,7 @@ TextureHandle::TextureHandle(PGraphics graphics, MTL::TextureType type,
if (usage & Gfx::SE_IMAGE_USAGE_STORAGE_BIT) { if (usage & Gfx::SE_IMAGE_USAGE_STORAGE_BIT) {
mtlUsage |= MTL::TextureUsageShaderWrite; mtlUsage |= MTL::TextureUsageShaderWrite;
} }
MTL::TextureDescriptor *descriptor = MTL::TextureDescriptor* descriptor = MTL::TextureDescriptor::alloc()->init();
MTL::TextureDescriptor::alloc()->init();
descriptor->setPixelFormat(cast(format)); descriptor->setPixelFormat(cast(format));
descriptor->setWidth(width); descriptor->setWidth(width);
descriptor->setHeight(height); descriptor->setHeight(height);
@@ -62,28 +56,19 @@ TextureHandle::~TextureHandle() {
} }
} }
void TextureHandle::pipelineBarrier(Gfx::SeAccessFlags, void TextureHandle::pipelineBarrier(Gfx::SeAccessFlags, Gfx::SePipelineStageFlags, Gfx::SeAccessFlags, Gfx::SePipelineStageFlags) {}
Gfx::SePipelineStageFlags,
Gfx::SeAccessFlags, void TextureHandle::changeLayout(Gfx::SeImageLayout, Gfx::SeAccessFlags, Gfx::SePipelineStageFlags, Gfx::SeAccessFlags,
Gfx::SePipelineStageFlags) {} Gfx::SePipelineStageFlags) {}
void TextureHandle::changeLayout(Gfx::SeImageLayout, Gfx::SeAccessFlags, void TextureHandle::transferOwnership(Gfx::QueueType newOwner) {}
Gfx::SePipelineStageFlags, Gfx::SeAccessFlags,
Gfx::SePipelineStageFlags) {}
void TextureHandle::transferOwnership(Gfx::QueueType newOwner) {
}
void TextureHandle::download(uint32, uint32, uint32, Array<uint8>&) {} void TextureHandle::download(uint32, uint32, uint32, Array<uint8>&) {}
void TextureHandle::generateMipmaps() void TextureHandle::generateMipmaps() {}
{
}
TextureBase::TextureBase(PGraphics graphics, MTL::TextureType viewType, const TextureCreateInfo& createInfo, MTL::Texture* existingImage) TextureBase::TextureBase(PGraphics graphics, MTL::TextureType viewType, const TextureCreateInfo& createInfo, MTL::Texture* existingImage)
: handle(new TextureHandle(graphics, viewType, createInfo, existingImage)), graphics(graphics) : handle(new TextureHandle(graphics, viewType, createInfo, existingImage)), graphics(graphics) {}
{}
TextureBase::~TextureBase() {} TextureBase::~TextureBase() {}
+29 -55
View File
@@ -17,11 +17,14 @@ using namespace Seele::Metal;
double currentFrameDelta = 0; double currentFrameDelta = 0;
double Gfx::getCurrentFrameDelta() { return currentFrameDelta; } double Gfx::getCurrentFrameDelta() { return currentFrameDelta; }
double currentFrameTime = 0;
double Gfx::getCurrentFrameTime() { return currentFrameTime; }
uint32 currentFrameIndex = 0; uint32 currentFrameIndex = 0;
uint32 Gfx::getCurrentFrameIndex() { return currentFrameIndex; } uint32 Gfx::getCurrentFrameIndex() { return currentFrameIndex; }
void glfwKeyCallback(GLFWwindow *handle, int key, int, int action, void glfwKeyCallback(GLFWwindow* handle, int key, int, int action, int modifier) {
int modifier) {
if (key == -1) { if (key == -1) {
return; return;
} }
@@ -34,11 +37,9 @@ void glfwMouseMoveCallback(GLFWwindow *handle, double xpos, double ypos) {
window->mouseMove(xpos, ypos); window->mouseMove(xpos, ypos);
} }
void glfwMouseButtonCallback(GLFWwindow *handle, int button, int action, void glfwMouseButtonCallback(GLFWwindow* handle, int button, int action, int modifier) {
int modifier) {
Window* window = (Window*)glfwGetWindowUserPointer(handle); Window* window = (Window*)glfwGetWindowUserPointer(handle);
window->mouseButton((MouseButton)button, (InputAction)action, window->mouseButton((MouseButton)button, (InputAction)action, (KeyModifier)modifier);
(KeyModifier)modifier);
} }
void glfwScrollCallback(GLFWwindow* handle, double xoffset, double yoffset) { void glfwScrollCallback(GLFWwindow* handle, double xoffset, double yoffset) {
@@ -61,17 +62,12 @@ void glfwFramebufferResizeCallback(GLFWwindow *handle, int width, int height) {
window->resize(width, height); window->resize(width, height);
} }
Window::Window(PGraphics graphics, const WindowCreateInfo &createInfo) Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo) : graphics(graphics), preferences(createInfo) {
: graphics(graphics), preferences(createInfo) { glfwSetErrorCallback([](int, const char* description) { std::cout << description << std::endl; });
glfwSetErrorCallback([](int, const char *description) {
std::cout << description << std::endl;
});
float xscale = 1, yscale = 1; float xscale = 1, yscale = 1;
glfwGetMonitorContentScale(glfwGetPrimaryMonitor(), &xscale, &yscale); glfwGetMonitorContentScale(glfwGetPrimaryMonitor(), &xscale, &yscale);
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
GLFWwindow *handle = GLFWwindow* handle = glfwCreateWindow(createInfo.width / xscale, createInfo.height / yscale, createInfo.title, nullptr, nullptr);
glfwCreateWindow(createInfo.width / xscale, createInfo.height / yscale,
createInfo.title, nullptr, nullptr);
windowHandle = handle; windowHandle = handle;
glfwSetWindowUserPointer(handle, this); glfwSetWindowUserPointer(handle, this);
@@ -96,15 +92,18 @@ Window::Window(PGraphics graphics, const WindowCreateInfo &createInfo)
metalWindow.contentView.wantsLayer = YES; metalWindow.contentView.wantsLayer = YES;
} }
Window::~Window() { Window::~Window() { glfwDestroyWindow(static_cast<GLFWwindow*>(windowHandle)); }
glfwDestroyWindow(static_cast<GLFWwindow *>(windowHandle));
}
void Window::pollInput() { glfwPollEvents(); } void Window::pollInput() { glfwPollEvents(); }
void Window::beginFrame() { void Window::beginFrame() {
drawable = (__bridge CA::MetalDrawable*)[metalLayer nextDrawable]; drawable = (__bridge CA::MetalDrawable*)[metalLayer nextDrawable];
createBackBuffer(); createBackBuffer();
static double start = glfwGetTime();
double end = glfwGetTime();
currentFrameDelta = end - start;
currentFrameTime += currentFrameDelta;
start = end;
} }
void Window::endFrame() { void Window::endFrame() {
@@ -117,47 +116,25 @@ void Window::onWindowCloseEvent() {}
Gfx::PTexture2D Window::getBackBuffer() const { return PTexture2D(backBuffer); } Gfx::PTexture2D Window::getBackBuffer() const { return PTexture2D(backBuffer); }
void Window::setKeyCallback( void Window::setKeyCallback(std::function<void(KeyCode, InputAction, KeyModifier)> callback) { keyCallback = callback; }
std::function<void(KeyCode, InputAction, KeyModifier)> callback) {
keyCallback = callback;
}
void Window::setMouseMoveCallback( void Window::setMouseMoveCallback(std::function<void(double, double)> callback) { mouseMoveCallback = callback; }
std::function<void(double, double)> callback) {
mouseMoveCallback = callback;
}
void Window::setMouseButtonCallback( void Window::setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifier)> callback) { mouseButtonCallback = callback; }
std::function<void(MouseButton, InputAction, KeyModifier)> callback) {
mouseButtonCallback = callback;
}
void Window::setScrollCallback(std::function<void(double, double)> callback) { void Window::setScrollCallback(std::function<void(double, double)> callback) { scrollCallback = callback; }
scrollCallback = callback;
}
void Window::setFileCallback(std::function<void(int, const char **)> callback) { void Window::setFileCallback(std::function<void(int, const char**)> callback) { fileCallback = callback; }
fileCallback = callback;
}
void Window::setCloseCallback(std::function<void()> callback) { void Window::setCloseCallback(std::function<void()> callback) { closeCallback = callback; }
closeCallback = callback;
}
void Window::setResizeCallback(std::function<void(uint32, uint32)> callback) { void Window::setResizeCallback(std::function<void(uint32, uint32)> callback) { resizeCallback = callback; }
resizeCallback = callback;
}
void Window::keyPress(KeyCode code, InputAction action, KeyModifier modifier) { void Window::keyPress(KeyCode code, InputAction action, KeyModifier modifier) { keyCallback(code, action, modifier); }
keyCallback(code, action, modifier);
}
void Window::mouseMove(double x, double y) { mouseMoveCallback(x, y); } void Window::mouseMove(double x, double y) { mouseMoveCallback(x, y); }
void Window::mouseButton(MouseButton button, InputAction action, void Window::mouseButton(MouseButton button, InputAction action, KeyModifier modifier) { mouseButtonCallback(button, action, modifier); }
KeyModifier modifier) {
mouseButtonCallback(button, action, modifier);
}
void Window::scroll(double x, double y) { scrollCallback(x, y); } void Window::scroll(double x, double y) { scrollCallback(x, y); }
@@ -176,22 +153,20 @@ void Window::resize(int width, int height) {
framebufferWidth = width; framebufferWidth = width;
framebufferHeight = height; framebufferHeight = height;
// Deallocate the textures if they have been created // Deallocate the textures if they have been created
drawable = drawable = (__bridge CA::MetalDrawable*)[[metalLayer nextDrawable] autorelease];
(__bridge CA::MetalDrawable *)[[metalLayer nextDrawable] autorelease];
createBackBuffer(); createBackBuffer();
resizeCallback(width, height); resizeCallback(width, height);
} }
void Window::createBackBuffer() { void Window::createBackBuffer() {
MTL::Texture* buf = drawable->texture(); MTL::Texture* buf = drawable->texture();
backBuffer = new Texture2D( backBuffer = new Texture2D(graphics,
graphics,
TextureCreateInfo{ TextureCreateInfo{
.width = static_cast<uint32>(buf->width()), .width = static_cast<uint32>(buf->width()),
.height = static_cast<uint32>(buf->height()), .height = static_cast<uint32>(buf->height()),
.depth = static_cast<uint32>(buf->depth()), .depth = static_cast<uint32>(buf->depth()),
.elements = static_cast<uint32>(buf->arrayLength()), .elements = static_cast<uint32>(buf->arrayLength()),
.mipLevels = static_cast<uint32>(buf->mipmapLevelCount()), .useMip = false,
.format = cast(buf->pixelFormat()), .format = cast(buf->pixelFormat()),
.usage = MTL::TextureUsageRenderTarget, .usage = MTL::TextureUsageRenderTarget,
.samples = static_cast<uint32>(buf->sampleCount()), .samples = static_cast<uint32>(buf->sampleCount()),
@@ -199,8 +174,7 @@ void Window::createBackBuffer() {
buf); buf);
} }
Viewport::Viewport(PWindow owner, const ViewportCreateInfo &createInfo) Viewport::Viewport(PWindow owner, const ViewportCreateInfo& createInfo) : Gfx::Viewport(owner, createInfo) {
: Gfx::Viewport(owner, createInfo) {
viewport.width = sizeX; viewport.width = sizeX;
viewport.height = sizeY; viewport.height = sizeY;
viewport.originX = offsetX; viewport.originX = offsetX;
+1 -1
View File
@@ -34,7 +34,7 @@ struct PipelineStatisticsResult {
friend std::ostream& operator<<(std::ostream& buf, const PipelineStatisticsResult& res); friend std::ostream& operator<<(std::ostream& buf, const PipelineStatisticsResult& res);
}; };
static std::ostream& operator<<(std::ostream & buf, const PipelineStatisticsResult& res) { inline std::ostream& operator<<(std::ostream & buf, const PipelineStatisticsResult& res) {
buf << fmt::format("{},{},{},{},{},{},{},{},{},", res.inputAssemblyVertices, res.inputAssemblyPrimitives, res.vertexShaderInvocations, buf << fmt::format("{},{},{},{},{},{},{},{},{},", res.inputAssemblyVertices, res.inputAssemblyPrimitives, res.vertexShaderInvocations,
res.clippingInvocations, res.clippingPrimitives, res.fragmentShaderInvocations, res.computeShaderInvocations, res.taskShaderInvocations, res.clippingInvocations, res.clippingPrimitives, res.fragmentShaderInvocations, res.computeShaderInvocations, res.taskShaderInvocations,
res.meshShaderInvocations); res.meshShaderInvocations);
+3 -3
View File
@@ -26,7 +26,7 @@ void Seele::addDebugVertex(DebugVertex vert) { gDebugVertices.add(vert); }
void Seele::addDebugVertices(Array<DebugVertex> verts) { gDebugVertices.addAll(verts); } void Seele::addDebugVertices(Array<DebugVertex> verts) { gDebugVertices.addAll(verts); }
BasePass::BasePass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics, scene) { BasePass::BasePass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics, scene) {
waterRenderer = new WaterRenderer(graphics, scene, viewParamsLayout); //waterRenderer = new WaterRenderer(graphics, scene, viewParamsLayout);
basePassLayout = graphics->createPipelineLayout("BasePassLayout"); basePassLayout = graphics->createPipelineLayout("BasePassLayout");
basePassLayout->addDescriptorLayout(viewParamsLayout); basePassLayout->addDescriptorLayout(viewParamsLayout);
@@ -98,7 +98,7 @@ void BasePass::beginFrame(const Component::Camera& cam) {
opaqueCulling = lightCullingLayout->allocateDescriptorSet(); opaqueCulling = lightCullingLayout->allocateDescriptorSet();
transparentCulling = lightCullingLayout->allocateDescriptorSet(); transparentCulling = lightCullingLayout->allocateDescriptorSet();
waterRenderer->beginFrame(); //waterRenderer->beginFrame();
// Debug vertices // Debug vertices
{ {
@@ -248,7 +248,7 @@ void BasePass::render() {
} }
} }
commands.add(waterRenderer->render(viewParamsSet)); //commands.add(waterRenderer->render(viewParamsSet));
// Skybox // Skybox
{ {
@@ -1,6 +1,6 @@
#include "DepthCullingPass.h" #include "DepthCullingPass.h"
#include "Graphics/Shader.h" #include "Graphics/Shader.h"
#include <minmax.h> #include <algorithm>
using namespace Seele; using namespace Seele;
@@ -218,8 +218,8 @@ void DepthCullingPass::publishOutputs() {
mipOffsets.add(bufferSize); mipOffsets.add(bufferSize);
mipDims.add(UVector2(width, height)); mipDims.add(UVector2(width, height));
bufferSize += width * height; bufferSize += width * height;
width = max((width + 1) / 2, 1); width = std::max((width + 1) / 2, 1u);
height = max((height + 1) / 2, 1); height = std::max((height + 1) / 2, 1u);
} }
ShaderBufferCreateInfo depthMipInfo = { ShaderBufferCreateInfo depthMipInfo = {
.sourceData = .sourceData =
@@ -260,6 +260,7 @@ void LightCullingPass::setupFrustums() {
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
.access = Gfx::SE_DESCRIPTOR_ACCESS_WRITE_ONLY_BIT, .access = Gfx::SE_DESCRIPTOR_ACCESS_WRITE_ONLY_BIT,
}); });
dispatchParamsLayout->create();
frustumLayout = graphics->createPipelineLayout("FrustumLayout"); frustumLayout = graphics->createPipelineLayout("FrustumLayout");
frustumLayout->addDescriptorLayout(viewParamsLayout); frustumLayout->addDescriptorLayout(viewParamsLayout);
frustumLayout->addDescriptorLayout(dispatchParamsLayout); frustumLayout->addDescriptorLayout(dispatchParamsLayout);
@@ -248,7 +248,7 @@ WaterRenderer::WaterRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDescri
{ {
{"taskMain", "WaterTask"}, {"taskMain", "WaterTask"},
{"meshMain", "WaterMesh"}, {"meshMain", "WaterMesh"},
{"main", "WaterPass"}, {"fragmentMain", "WaterPass"},
}, },
.rootSignature = waterLayout, .rootSignature = waterLayout,
.dumpIntermediate = true, .dumpIntermediate = true,
+1 -1
View File
@@ -122,7 +122,7 @@ void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipeline
{ {
createInfo.dumpIntermediate = true; createInfo.dumpIntermediate = true;
} }
createInfo.typeParameter.add({Pair<const char*, const char*>("IVertexData", permutation.vertexDataName)}); //createInfo.typeParameter.add({Pair<const char*, const char*>("IVertexData", permutation.vertexDataName)});
createInfo.modules.add(permutation.vertexDataName); createInfo.modules.add(permutation.vertexDataName);
if (permutation.useMeshShading) { if (permutation.useMeshShading) {
+4 -4
View File
@@ -29,10 +29,10 @@ VkImageAspectFlags getAspectFromFormat(Gfx::SeFormat format) {
} }
TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType, const TextureCreateInfo& createInfo, VkImage existingImage) TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType, const TextureCreateInfo& createInfo, VkImage existingImage)
: CommandBoundResource(graphics, createInfo.name), image(existingImage), width(createInfo.width), height(createInfo.height), : CommandBoundResource(graphics, createInfo.name), image(existingImage), owner(createInfo.sourceData.owner), width(createInfo.width),
depth(createInfo.depth), arrayCount(createInfo.elements), mipLevels(1), layerCount(createInfo.layers), samples(createInfo.samples), height(createInfo.height), depth(createInfo.depth), arrayCount(createInfo.elements), layerCount(createInfo.layers), mipLevels(1),
format(createInfo.format), usage(createInfo.usage), layout(Gfx::SE_IMAGE_LAYOUT_UNDEFINED), samples(createInfo.samples), format(createInfo.format), usage(createInfo.usage),
aspect(getAspectFromFormat(createInfo.format)), ownsImage(false), owner(createInfo.sourceData.owner) { layout(Gfx::SE_IMAGE_LAYOUT_UNDEFINED), aspect(getAspectFromFormat(createInfo.format)), ownsImage(false) {
if (createInfo.useMip) { if (createInfo.useMip) {
mipLevels = static_cast<uint32_t>(std::floor(std::log2(std::max(width, height)))) + 1; mipLevels = static_cast<uint32_t>(std::floor(std::log2(std::max(width, height)))) + 1;
} }
+7 -5
View File
@@ -22,9 +22,9 @@ Material::Material() {}
Material::Material(Gfx::PGraphics graphics, uint32 numTextures, uint32 numSamplers, uint32 numFloats, bool twoSided, float opacity, Material::Material(Gfx::PGraphics graphics, uint32 numTextures, uint32 numSamplers, uint32 numFloats, bool twoSided, float opacity,
std::string materialName, Array<OShaderExpression> expressions, Array<std::string> parameter, MaterialNode brdf) std::string materialName, Array<OShaderExpression> expressions, Array<std::string> parameter, MaterialNode brdf)
: graphics(graphics), numTextures(numTextures), numSamplers(numSamplers), numFloats(numFloats), twoSided(twoSided), opacity(opacity), : graphics(graphics), numTextures(numTextures), numSamplers(numSamplers), numFloats(numFloats), instanceId(0), materialId(materialIdCounter++),
instanceId(0), materialName(materialName), codeExpressions(std::move(expressions)), parameters(std::move(parameter)), materialName(materialName), twoSided(twoSided), opacity(opacity), codeExpressions(std::move(expressions)),
brdf(std::move(brdf)), materialId(materialIdCounter++) { parameters(std::move(parameter)), brdf(std::move(brdf)) {
if (layout == nullptr) { if (layout == nullptr) {
init(graphics); init(graphics);
} }
@@ -38,14 +38,14 @@ void Material::init(Gfx::PGraphics graphics) {
layout->addDescriptorBinding(Gfx::DescriptorBinding{ layout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0, .binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
.descriptorCount = 2000, .descriptorCount = 512,
.bindingFlags = Gfx::SE_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT, .bindingFlags = Gfx::SE_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT,
.shaderStages = Gfx::SE_SHADER_STAGE_FRAGMENT_BIT | Gfx::SE_SHADER_STAGE_CLOSEST_HIT_BIT_KHR, .shaderStages = Gfx::SE_SHADER_STAGE_FRAGMENT_BIT | Gfx::SE_SHADER_STAGE_CLOSEST_HIT_BIT_KHR,
}); });
layout->addDescriptorBinding(Gfx::DescriptorBinding{ layout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1, .binding = 1,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,
.descriptorCount = 2000, .descriptorCount = 512,
.bindingFlags = Gfx::SE_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT, .bindingFlags = Gfx::SE_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT,
.shaderStages = Gfx::SE_SHADER_STAGE_FRAGMENT_BIT | Gfx::SE_SHADER_STAGE_CLOSEST_HIT_BIT_KHR, .shaderStages = Gfx::SE_SHADER_STAGE_FRAGMENT_BIT | Gfx::SE_SHADER_STAGE_CLOSEST_HIT_BIT_KHR,
}); });
@@ -101,12 +101,14 @@ void Material::updateFloatData(uint32 offset, uint32 numFloats, float* data) {
uint32 Material::addTextures(uint32 numTextures) { uint32 Material::addTextures(uint32 numTextures) {
uint32 textureOffset = textures.size(); uint32 textureOffset = textures.size();
textures.resize(textures.size() + numTextures); textures.resize(textures.size() + numTextures);
assert(textures.size() < 512);
return textureOffset; return textureOffset;
} }
uint32 Material::addSamplers(uint32 numSamplers) { uint32 Material::addSamplers(uint32 numSamplers) {
uint32 samplerOffset = samplers.size(); uint32 samplerOffset = samplers.size();
samplers.resize(samplers.size() + numSamplers); samplers.resize(samplers.size() + numSamplers);
assert(textures.size() < 512);
return samplerOffset; return samplerOffset;
} }
+11 -11
View File
@@ -54,7 +54,7 @@ struct ShaderParameter : public ShaderExpression {
virtual uint64 getIdentifier() const override = 0; virtual uint64 getIdentifier() const override = 0;
virtual uint64 getCPUSize() const override = 0; virtual uint64 getCPUSize() const override = 0;
virtual uint64 getGPUSize() const override = 0; virtual uint64 getGPUSize() const override = 0;
virtual std::string evaluate(Map<std::string, std::string>& varState) const = 0; virtual std::string evaluate(Map<std::string, std::string>& varState) const override = 0;
virtual void save(ArchiveBuffer& buffer) const override; virtual void save(ArchiveBuffer& buffer) const override;
virtual void load(ArchiveBuffer& buffer) override; virtual void load(ArchiveBuffer& buffer) override;
}; };
@@ -68,8 +68,8 @@ struct FloatParameter : public ShaderParameter {
virtual void updateDescriptorSet(uint32 textureOffset, uint32 samplerOffset, uint32 floatOffset) override; virtual void updateDescriptorSet(uint32 textureOffset, uint32 samplerOffset, uint32 floatOffset) override;
virtual std::string evaluate(Map<std::string, std::string>& varState) const override; virtual std::string evaluate(Map<std::string, std::string>& varState) const override;
virtual uint64 getIdentifier() const override { return IDENTIFIER; } virtual uint64 getIdentifier() const override { return IDENTIFIER; }
virtual uint64 getCPUSize() const { return sizeof(FloatParameter); } virtual uint64 getCPUSize() const override { return sizeof(FloatParameter); }
virtual uint64 getGPUSize() const { return sizeof(float); } virtual uint64 getGPUSize() const override { return sizeof(float); }
virtual void save(ArchiveBuffer& buffer) const override; virtual void save(ArchiveBuffer& buffer) const override;
virtual void load(ArchiveBuffer& buffer) override; virtual void load(ArchiveBuffer& buffer) override;
}; };
@@ -83,8 +83,8 @@ struct VectorParameter : public ShaderParameter {
virtual void updateDescriptorSet(uint32 textureOffset, uint32 samplerOffset, uint32 floatOffset) override; virtual void updateDescriptorSet(uint32 textureOffset, uint32 samplerOffset, uint32 floatOffset) override;
virtual std::string evaluate(Map<std::string, std::string>& varState) const override; virtual std::string evaluate(Map<std::string, std::string>& varState) const override;
virtual uint64 getIdentifier() const override { return IDENTIFIER; } virtual uint64 getIdentifier() const override { return IDENTIFIER; }
virtual uint64 getCPUSize() const { return sizeof(VectorParameter); } virtual uint64 getCPUSize() const override { return sizeof(VectorParameter); }
virtual uint64 getGPUSize() const { return sizeof(Vector); } virtual uint64 getGPUSize() const override { return sizeof(Vector); }
virtual void save(ArchiveBuffer& buffer) const override; virtual void save(ArchiveBuffer& buffer) const override;
virtual void load(ArchiveBuffer& buffer) override; virtual void load(ArchiveBuffer& buffer) override;
}; };
@@ -98,8 +98,8 @@ struct TextureParameter : public ShaderParameter {
virtual void updateDescriptorSet(uint32 textureOffset, uint32 samplerOffset, uint32 floatOffset) override; virtual void updateDescriptorSet(uint32 textureOffset, uint32 samplerOffset, uint32 floatOffset) override;
virtual std::string evaluate(Map<std::string, std::string>& varState) const override; virtual std::string evaluate(Map<std::string, std::string>& varState) const override;
virtual uint64 getIdentifier() const override { return IDENTIFIER; } virtual uint64 getIdentifier() const override { return IDENTIFIER; }
virtual uint64 getCPUSize() const { return sizeof(TextureParameter); } virtual uint64 getCPUSize() const override { return sizeof(TextureParameter); }
virtual uint64 getGPUSize() const { return sizeof(void*); } // TODO: technically this is just a ref, but idk virtual uint64 getGPUSize() const override { return sizeof(void*); } // TODO: technically this is just a ref, but idk
virtual void save(ArchiveBuffer& buffer) const override; virtual void save(ArchiveBuffer& buffer) const override;
virtual void load(ArchiveBuffer& buffer) override; virtual void load(ArchiveBuffer& buffer) override;
}; };
@@ -114,8 +114,8 @@ struct SamplerParameter : public ShaderParameter {
virtual void updateDescriptorSet(uint32 textureOffset, uint32 samplerOffset, uint32 floatOffset) override; virtual void updateDescriptorSet(uint32 textureOffset, uint32 samplerOffset, uint32 floatOffset) override;
virtual std::string evaluate(Map<std::string, std::string>& varState) const override; virtual std::string evaluate(Map<std::string, std::string>& varState) const override;
virtual uint64 getIdentifier() const override { return IDENTIFIER; } virtual uint64 getIdentifier() const override { return IDENTIFIER; }
virtual uint64 getCPUSize() const { return sizeof(SamplerParameter); } virtual uint64 getCPUSize() const override { return sizeof(SamplerParameter); }
virtual uint64 getGPUSize() const { return sizeof(void*); } virtual uint64 getGPUSize() const override { return sizeof(void*); }
virtual void save(ArchiveBuffer& buffer) const override; virtual void save(ArchiveBuffer& buffer) const override;
virtual void load(ArchiveBuffer& buffer) override; virtual void load(ArchiveBuffer& buffer) override;
}; };
@@ -130,8 +130,8 @@ struct CombinedTextureParameter : public ShaderParameter {
virtual void updateDescriptorSet(uint32 textureOffset, uint32 samplerOffset, uint32 floatOffset) override; virtual void updateDescriptorSet(uint32 textureOffset, uint32 samplerOffset, uint32 floatOffset) override;
virtual std::string evaluate(Map<std::string, std::string>& varState) const override; virtual std::string evaluate(Map<std::string, std::string>& varState) const override;
virtual uint64 getIdentifier() const override { return IDENTIFIER; } virtual uint64 getIdentifier() const override { return IDENTIFIER; }
virtual uint64 getCPUSize() const { return sizeof(CombinedTextureParameter); } virtual uint64 getCPUSize() const override { return sizeof(CombinedTextureParameter); }
virtual uint64 getGPUSize() const { return sizeof(void*); } virtual uint64 getGPUSize() const override { return sizeof(void*); }
virtual void save(ArchiveBuffer& buffer) const override; virtual void save(ArchiveBuffer& buffer) const override;
virtual void load(ArchiveBuffer& buffer) override; virtual void load(ArchiveBuffer& buffer) override;
}; };