diff --git a/.clang-format b/.clang-format index 5a4cbb1..5b3c76f 100644 --- a/.clang-format +++ b/.clang-format @@ -1,6 +1,5 @@ BasedOnStyle: LLVM IndentWidth: 4 -Language: Cpp ColumnLimit: 140 DerivePointerAlignment: false PointerAlignment: Left \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 2146a8f..38e5436 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -18,11 +18,11 @@ "**/external": true, "**/res": true, }, - "editor.tabSize": 4, "editor.detectIndentation": false, "lldb.displayFormat": "auto", "lldb.showDisassembly": "auto", "lldb.dereferencePointers": true, "lldb.consoleMode": "commands", - "cmake.generator": "Ninja" + "cmake.generator": "Ninja", + "editor.tabSize": 4 } \ No newline at end of file diff --git a/cmake/SuperBuild.cmake b/cmake/SuperBuild.cmake index 41f85fa..4625c05 100644 --- a/cmake/SuperBuild.cmake +++ b/cmake/SuperBuild.cmake @@ -19,7 +19,7 @@ if(WIN32) ${SLANG_ROOT}lib/slang.lib DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) 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) install(FILES ${BINARY_ROOT}/lib/libslang.dylib diff --git a/res/shaders/DepthCullingMesh.slang b/res/shaders/DepthCullingMesh.slang index c13c588..cea1579 100644 --- a/res/shaders/DepthCullingMesh.slang +++ b/res/shaders/DepthCullingMesh.slang @@ -1,6 +1,7 @@ import Common; import Scene; import VertexData; +import StaticMeshVertexData; import MaterialParameter; struct PrimitiveAttributes @@ -36,10 +37,12 @@ void meshMain( uint local_idx0 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 0]; uint local_idx1 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 1]; 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 - prim[p].prim = encodePrimitive(meshletId); + primAttr.prim = encodePrimitive(meshletId); #endif + prim[p] = primAttr; } } for(uint i = threadID; i < MAX_VERTICES; i += MESH_GROUP_SIZE) diff --git a/res/shaders/DrawListMesh.slang b/res/shaders/DrawListMesh.slang index 2cbca3a..d6d5679 100644 --- a/res/shaders/DrawListMesh.slang +++ b/res/shaders/DrawListMesh.slang @@ -1,6 +1,7 @@ import Common; import Scene; import VertexData; +import StaticMeshVertexData; import MaterialParameter; struct PrimitiveAttributes @@ -37,11 +38,13 @@ void meshMain( uint local_idx0 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 0]; uint local_idx1 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 1]; uint local_idx2 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 2]; - indices[p] = uint3(local_idx0, local_idx1, local_idx2); - prim[p].cull = false;//cull.triangleCulled(p); + indices[p] = uint3(local_idx0, local_idx1, local_idx2); + PrimitiveAttributes primAttr; + primAttr.cull = false;//cull.triangleCulled(p); #ifdef VISIBILITY - prim[p].prim = encodePrimitive(meshletId); + primAttr.prim = encodePrimitive(meshletId); #endif + prim[p] = primAttr; } } for(uint i = threadID; i < MAX_VERTICES; i += MESH_GROUP_SIZE) diff --git a/res/shaders/WaterCompute.slang b/res/shaders/WaterCompute.slang index 5364874..c230f6f 100644 --- a/res/shaders/WaterCompute.slang +++ b/res/shaders/WaterCompute.slang @@ -19,7 +19,7 @@ struct ComputeParams uint N, lengthScale0, lengthScale1, lengthScale2, lengthScale3; float foamBias, foamDecayRate, foamAdd, foamThreshold; RWTexture2DArray spectrumTextures, initialSpectrumTextures, displacementTextures; - RWTexture2DArray slopeTexture; + RWTexture2DArray slopeTexture; RWTexture2D boyancyData; StructuredBuffer spectrums; 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.slopeTexture[uint3(id.xy, i)] = float2(slopes); + pParams.slopeTexture[uint3(id.xy, i)] = float4(slopes, 0, 0); if (i == 0) { pParams.boyancyData[id.xy] = half(displacement.y); diff --git a/res/shaders/WaterPass.slang b/res/shaders/WaterPass.slang index fd3c536..2057498 100644 --- a/res/shaders/WaterPass.slang +++ b/res/shaders/WaterPass.slang @@ -21,7 +21,7 @@ float Beckmann(float ndoth, float roughness) { } [shader("pixel")] -float4 main(WaterVertex vert) : SV_TARGET { +float4 fragmentMain(WaterVertex vert) : SV_TARGET { float3 lightDir = -normalize(pWaterMaterial.sunDirection); float3 viewDir = normalize(pViewParams.cameraPos_WS.xyz - vert.position_WS); float3 halfwayDir = normalize(lightDir + viewDir); diff --git a/res/shaders/lib/BRDF.slang b/res/shaders/lib/BRDF.slang index 6e96e9c..7685dd3 100644 --- a/res/shaders/lib/BRDF.slang +++ b/res/shaders/lib/BRDF.slang @@ -19,8 +19,12 @@ struct Phong : IBRDF __init() { + baseColor = float3(0, 0, 0); alpha = 1; + specular = float3(0, 0, 0); normal = float3(0, 0, 1); + ambient = float3(0, 0, 0); + shininess = 0; } float3 evaluate(float3 viewDir_TS, float3 lightDir_TS, float3 lightColor) @@ -58,8 +62,12 @@ struct BlinnPhong : IBRDF __init() { + baseColor = float3(0, 0, 0); alpha = 1; + specularColor = float3(0, 0, 0); normal = float3(0, 0, 1); + shininess = 0; + ambient = float3(0, 0, 0); } float3 evaluate(float3 viewDir_TS, float3 lightDir_TS, float3 lightColor) @@ -94,6 +102,7 @@ struct CelShading : IBRDF __init() { + baseColor = float3(0, 0, 0); alpha = 1; normal = float3(0, 0, 1); } @@ -140,6 +149,7 @@ struct CookTorrance : IBRDF __init() { + baseColor = float3(0, 0, 0); alpha = 1; normal = float3(0, 0, 1); roughness = 0; diff --git a/res/shaders/lib/Material.slang b/res/shaders/lib/Material.slang index 92e9c04..5184b2f 100644 --- a/res/shaders/lib/Material.slang +++ b/res/shaders/lib/Material.slang @@ -8,34 +8,35 @@ import Scene; // associatedtype BRDF : IBRDF; // BRDF prepare(MaterialParameter input); //}; - -layout(set=4, binding=0) -Texture2D textureArray[]; -layout(set=4, binding=1) -SamplerState samplerArray[]; -layout(set=4, binding=2) -StructuredBuffer floatArray; +struct MaterialResources +{ + StructuredBuffer floatArray; + Texture2D textureArray[512]; + SamplerState samplerArray[512]; +}; +layout(set=4) +ParameterBlock pResources; Texture2D getMaterialTextureParameter(uint index) { - return textureArray[pOffsets.textureOffset + index]; + return pResources.textureArray[pOffsets.textureOffset + index]; } SamplerState getMaterialSamplerParameter(uint index) { - return samplerArray[pOffsets.samplerOffset + index]; + return pResources.samplerArray[pOffsets.samplerOffset + index]; } float getMaterialFloatParameter(uint index) { - return floatArray[pOffsets.floatOffset + index]; + return pResources.floatArray[pOffsets.floatOffset + index]; } float3 getMaterialVectorParameter(uint index) { return float3( - floatArray[pOffsets.floatOffset + index], - floatArray[pOffsets.floatOffset + index + 1], - floatArray[pOffsets.floatOffset + index + 2] + pResources.floatArray[pOffsets.floatOffset + index], + pResources.floatArray[pOffsets.floatOffset + index + 1], + pResources.floatArray[pOffsets.floatOffset + index + 2] ); } diff --git a/src/Benchmark/main.cpp b/src/Benchmark/main.cpp index 9c58bb4..3f96e17 100644 --- a/src/Benchmark/main.cpp +++ b/src/Benchmark/main.cpp @@ -1,7 +1,11 @@ #include "Asset/AssetRegistry.h" #include "Graphics/Initializer.h" #include "Graphics/StaticMeshVertexData.h" +#ifdef __APPLE__ +#include "Graphics/Metal/Graphics.h" +#else #include "Graphics/Vulkan/Graphics.h" +#endif #include "PlayView.h" #include "Window/WindowManager.h" #include @@ -24,7 +28,12 @@ int main(int argc, char** argv) { } std::filesystem::path binaryPath = "C:/Users/Dynamitos/MeshShadingDemo/bin/MeshShadingDemo.dll"; - graphics = new Vulkan::Graphics(); + +#ifdef __APPLE__ + graphics = new Metal::Graphics(); +#else + graphics = new Vulkan::Graphics(); +#endif GraphicsInitializer initializer; graphics->init(initializer); StaticMeshVertexData* vd = StaticMeshVertexData::getInstance(); diff --git a/src/Editor/main.cpp b/src/Editor/main.cpp index 7bb5377..26e17c6 100644 --- a/src/Editor/main.cpp +++ b/src/Editor/main.cpp @@ -65,7 +65,7 @@ int main() { .type = TextureImportType::TEXTURE_CUBEMAP, }); AssetImporter::importMesh(MeshImportArgs{ - .filePath = sourcePath / "import/models/ship.glb", + .filePath = sourcePath / "import/models/ship.fbx", .importPath = "ship", }); // AssetImporter::importMesh(MeshImportArgs{ diff --git a/src/Engine/Graphics/Metal/Buffer.h b/src/Engine/Graphics/Metal/Buffer.h index ff835ef..cbf36a1 100644 --- a/src/Engine/Graphics/Metal/Buffer.h +++ b/src/Engine/Graphics/Metal/Buffer.h @@ -12,9 +12,11 @@ namespace Metal { DECLARE_REF(Graphics) class BufferAllocation : public CommandBoundResource { 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(); - 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 updateContents(uint64 regionOffset, uint64 regionSize, void* ptr); void readContents(uint64 regionOffset, uint64 regionSize, void* ptr); @@ -27,14 +29,15 @@ DECLARE_REF(BufferAllocation) class Buffer { public: Buffer(PGraphics graphics, uint64 size, Gfx::SeBufferUsageFlags usage, Gfx::QueueType queueType, bool dynamic, std::string name, - bool createCleared = false, uint32 clearValue = 0); + bool createCleared = false, uint32 clearValue = 0); virtual ~Buffer(); MTL::Buffer* getHandle() const { return buffers[currentBuffer]->buffer; } PBufferAllocation getAlloc() const { return buffers[currentBuffer]; } uint64 getSize() const { return buffers[currentBuffer]->size; } void updateContents(uint64 regionOffset, uint64 regionSize, void* ptr); void readContents(uint64 regionOffset, uint64 regionSize, void* ptr); - + void* map(); + void unmap(); protected: PGraphics graphics; @@ -51,8 +54,8 @@ class Buffer { void copyBuffer(uint64 src, uint64 dest); 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) @@ -60,7 +63,8 @@ class VertexBuffer : public Gfx::VertexBuffer, public Buffer { public: VertexBuffer(PGraphics graphics, const VertexBufferCreateInfo& createInfo); virtual ~VertexBuffer(); - virtual void updateRegion(DataSource update) override; + + virtual void updateRegion(uint64 offset, uint64 size, void* data) override; virtual void download(Array& buffer) override; protected: @@ -89,9 +93,8 @@ class UniformBuffer : public Gfx::UniformBuffer, public Buffer { public: UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo& createInfo); virtual ~UniformBuffer(); - + virtual void updateContents(uint64 offset, uint64 size, void* data) override; virtual void rotateBuffer(uint64 size) override; - virtual void updateContents(const DataSource& sourceData) override; protected: // Inherited via QueueOwnedResource @@ -104,9 +107,12 @@ class ShaderBuffer : public Gfx::ShaderBuffer, public Buffer { public: ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo& createInfo); virtual ~ShaderBuffer(); - virtual void readContents(Array& 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 updateContents(const ShaderBufferCreateInfo& sourceData) override; + virtual void* map() override; + virtual void unmap() override; + virtual void clear() override; protected: diff --git a/src/Engine/Graphics/Metal/Buffer.mm b/src/Engine/Graphics/Metal/Buffer.mm index ef9f84e..5af3bc8 100644 --- a/src/Engine/Graphics/Metal/Buffer.mm +++ b/src/Engine/Graphics/Metal/Buffer.mm @@ -18,41 +18,26 @@ BufferAllocation::BufferAllocation(PGraphics graphics, const std::string& name, } BufferAllocation::~BufferAllocation() { - if (buffer != nullptr) { - buffer->release(); - } + if (buffer != nullptr) { + buffer->release(); + } } -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); } -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); } -void* BufferAllocation::map() -{ - return buffer->contents(); -} +void* BufferAllocation::map() { 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, bool createCleared, uint32 clearValue) @@ -62,34 +47,33 @@ Buffer::Buffer(PGraphics graphics, uint64 size, Gfx::SeBufferUsageFlags usage, G } Buffer::~Buffer() { - for (size_t i = 0; i < buffers.size(); ++i) { - // TODO - } + for (size_t i = 0; i < buffers.size(); ++i) { + // TODO + } } -void Buffer::updateContents(uint64 regionOffset, uint64 regionSize, void* ptr) -{ +void Buffer::updateContents(uint64 regionOffset, uint64 regionSize, void* ptr) { getAlloc()->updateContents(regionOffset, regionSize, ptr); } -void Buffer::readContents(uint64 regionOffset, uint64 regionSize, void* ptr) -{ - getAlloc()->readContents(regionOffset, regionSize, ptr); -} +void Buffer::readContents(uint64 regionOffset, uint64 regionSize, void* ptr) { getAlloc()->readContents(regionOffset, regionSize, ptr); } -void Buffer::rotateBuffer(uint64 size, bool preserveContents) -{ - if(size == 0) +void* Buffer::map() { return getAlloc()->map(); } + +void Buffer::unmap() { return getAlloc()->unmap(); } + +void Buffer::rotateBuffer(uint64 size, bool preserveContents) { + if (size == 0) return; assert(dynamic); - for(uint32 i = 0; i < buffers.size(); ++i) { - if(buffers[i]->isCurrentlyBound()) { + for (uint32 i = 0; i < buffers.size(); ++i) { + if (buffers[i]->isCurrentlyBound()) { continue; } - if(buffers[i]->size < size) { + if (buffers[i]->size < size) { createBuffer(size, i); } - if(preserveContents) { + if (preserveContents) { copyBuffer(currentBuffer, i); } currentBuffer = i; @@ -97,153 +81,123 @@ void Buffer::rotateBuffer(uint64 size, bool preserveContents) } buffers.add(nullptr); createBuffer(size, buffers.size() - 1); - if(preserveContents) { + if (preserveContents) { copyBuffer(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); - if(createCleared) { + if (createCleared) { std::memset(buffers[destIndex]->map(), clearValue, buffers[destIndex]->size); } } -void Buffer::copyBuffer(uint64 src, uint64 dest) -{ - if(src == dest) { +void Buffer::copyBuffer(uint64 src, uint64 dest) { + if (src == dest) { return; } std::memcpy(buffers[dest]->map(), buffers[src]->map(), buffers[src]->size); } -void Buffer::transferOwnership(Gfx::QueueType newOwner) -{ - getAlloc()->transferOwnership(newOwner); -} +void Buffer::transferOwnership(Gfx::QueueType newOwner) { 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); } -VertexBuffer::VertexBuffer(PGraphics graphics, - const VertexBufferCreateInfo &createInfo) +VertexBuffer::VertexBuffer(PGraphics graphics, const VertexBufferCreateInfo& createInfo) : Gfx::VertexBuffer(graphics->getFamilyMapping(), createInfo), Metal::Buffer(graphics, createInfo.sourceData.size, Gfx::SE_BUFFER_USAGE_VERTEX_BUFFER_BIT, createInfo.sourceData.owner, false, - createInfo.name) { - if(createInfo.sourceData.size > 0 && createInfo.sourceData.data != nullptr) { + createInfo.name) { + if (createInfo.sourceData.size > 0 && createInfo.sourceData.data != nullptr) { getAlloc()->updateContents(createInfo.sourceData.offset, createInfo.sourceData.size, createInfo.sourceData.data); } } VertexBuffer::~VertexBuffer() {} -void VertexBuffer::updateRegion(DataSource update) { - void *data = getHandle()->contents(); - std::memcpy((char *)data + update.offset, update.data, update.size); +void VertexBuffer::updateRegion(uint64 offset, uint64 size, void* data) { getAlloc()->updateContents(offset, size, data); } + +void VertexBuffer::download(Array& buffer) { + void* data = getHandle()->contents(); + buffer.resize(getSize()); + std::memcpy(buffer.data(), data, getSize()); } -void VertexBuffer::download(Array &buffer) { - void *data = getHandle()->contents(); - buffer.resize(getSize()); - std::memcpy(buffer.data(), data, getSize()); -} +void VertexBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { Metal::Buffer::transferOwnership(newOwner); } -void VertexBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { - Metal::Buffer::transferOwnership(newOwner); -} - -void VertexBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, - Gfx::SePipelineStageFlags srcStage, - Gfx::SeAccessFlags dstAccess, +void VertexBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) { Metal::Buffer::pipelineBarrier(srcAccess, srcStage, dstAccess, dstStage); } -IndexBuffer::IndexBuffer(PGraphics graphics, - const IndexBufferCreateInfo &createInfo) +IndexBuffer::IndexBuffer(PGraphics graphics, const IndexBufferCreateInfo& createInfo) : Gfx::IndexBuffer(graphics->getFamilyMapping(), createInfo), 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, - createInfo.sourceData.owner, false, createInfo.name) { -} + 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) {} IndexBuffer::~IndexBuffer() {} -void IndexBuffer::download(Array &buffer) { - void *data = getHandle()->contents(); - buffer.resize(getSize()); - std::memcpy(buffer.data(), data, getSize()); -} -void IndexBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { - Metal::Buffer::transferOwnership(newOwner); +void IndexBuffer::download(Array& buffer) { + void* data = getHandle()->contents(); + buffer.resize(getSize()); + std::memcpy(buffer.data(), data, getSize()); } +void IndexBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { Metal::Buffer::transferOwnership(newOwner); } -void IndexBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, - Gfx::SePipelineStageFlags srcStage, - Gfx::SeAccessFlags dstAccess, +void IndexBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) { Metal::Buffer::pipelineBarrier(srcAccess, srcStage, dstAccess, dstStage); } -UniformBuffer::UniformBuffer(PGraphics graphics, - const UniformBufferCreateInfo &createInfo) +UniformBuffer::UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo& createInfo) : Gfx::UniformBuffer(graphics->getFamilyMapping(), createInfo), Metal::Buffer(graphics, createInfo.sourceData.size, Gfx::SE_BUFFER_USAGE_UNIFORM_BUFFER_BIT, createInfo.sourceData.owner, - createInfo.dynamic, createInfo.name) { - getAlloc()->updateContents(createInfo.sourceData.offset, createInfo.sourceData.size, createInfo.sourceData.data); + createInfo.dynamic, createInfo.name) { + if (createInfo.sourceData.size > 0 && createInfo.sourceData.data != nullptr) { + getAlloc()->updateContents(createInfo.sourceData.offset, createInfo.sourceData.size, createInfo.sourceData.data); + } } UniformBuffer::~UniformBuffer() {} -void UniformBuffer::rotateBuffer(uint64 size) { - Metal::Buffer::rotateBuffer(size); -} +void UniformBuffer::rotateBuffer(uint64 size) { Metal::Buffer::rotateBuffer(size); } -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::updateContents(uint64 offset, uint64 size, void* data) { + if (size > 0 && data != nullptr) { + Metal::Buffer::rotateBuffer(size); + getAlloc()->updateContents(offset, size, data); } } -void UniformBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { - Metal::Buffer::transferOwnership(newOwner); -} +void UniformBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { Metal::Buffer::transferOwnership(newOwner); } -void UniformBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, - Gfx::SePipelineStageFlags srcStage, - Gfx::SeAccessFlags dstAccess, +void UniformBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) { Metal::Buffer::pipelineBarrier(srcAccess, srcStage, dstAccess, dstStage); } -ShaderBuffer::ShaderBuffer(PGraphics graphics, - const ShaderBufferCreateInfo &createInfo) +ShaderBuffer::ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo& createInfo) : Gfx::ShaderBuffer(graphics->getFamilyMapping(), createInfo), - Seele::Metal::Buffer(graphics, createInfo.sourceData.size, - Gfx::SE_BUFFER_USAGE_STORAGE_BUFFER_BIT, - createInfo.sourceData.owner, createInfo.dynamic, createInfo.name, createInfo.createCleared, createInfo.clearValue) {} + Seele::Metal::Buffer(graphics, createInfo.sourceData.size, Gfx::SE_BUFFER_USAGE_STORAGE_BUFFER_BIT, createInfo.sourceData.owner, + createInfo.dynamic, createInfo.name, createInfo.createCleared, createInfo.clearValue) {} ShaderBuffer::~ShaderBuffer() {} -void ShaderBuffer::readContents(Array& data) { - data.resize(getSize()); - getAlloc()->readContents(0, data.size(), data.data()); -} +void ShaderBuffer::readContents(uint64 offset, uint64 size, void* data) { getAlloc()->readContents(offset, size, data); } -void ShaderBuffer::updateContents(const ShaderBufferCreateInfo& createInfo) { - if (createInfo.sourceData.data == nullptr) { +void ShaderBuffer::updateContents(uint64 offset, uint64 size, void* data) { + if (data == nullptr) { return; } // We always want to update, as the contents could be different on the GPU - if (createInfo.sourceData.size > 0 && createInfo.sourceData.data != nullptr) { - getAlloc()->updateContents(createInfo.sourceData.offset, createInfo.sourceData.size, createInfo.sourceData.data); + if (size > 0 && data != nullptr) { + getAlloc()->updateContents(offset, size, data); } - } void ShaderBuffer::rotateBuffer(uint64 size, bool preserveContents) { @@ -251,18 +205,15 @@ void ShaderBuffer::rotateBuffer(uint64 size, bool preserveContents) { Metal::Buffer::rotateBuffer(size, preserveContents); } +void* ShaderBuffer::map() { return Metal::Buffer::map(); } -void ShaderBuffer::clear() { - std::memset(getAlloc()->map(), 0, getSize()); -} +void ShaderBuffer::unmap() { Metal::Buffer::unmap(); } -void ShaderBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { - Metal::Buffer::transferOwnership(newOwner); -} +void ShaderBuffer::clear() { std::memset(getAlloc()->map(), 0, getSize()); } -void ShaderBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, - Gfx::SePipelineStageFlags srcStage, - Gfx::SeAccessFlags dstAccess, +void ShaderBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { Metal::Buffer::transferOwnership(newOwner); } + +void ShaderBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) { Metal::Buffer::pipelineBarrier(srcAccess, srcStage, dstAccess, dstStage); } diff --git a/src/Engine/Graphics/Metal/CMakeLists.txt b/src/Engine/Graphics/Metal/CMakeLists.txt index f1a977f..9f8e075 100644 --- a/src/Engine/Graphics/Metal/CMakeLists.txt +++ b/src/Engine/Graphics/Metal/CMakeLists.txt @@ -1,27 +1,29 @@ -target_sources(Engine - PRIVATE - Buffer.h - Buffer.mm - Command.h - Command.mm - Descriptor.h - Descriptor.mm - Enums.h - Enums.mm +target_sources(Engine + PRIVATE + Buffer.h + Buffer.mm + Command.h + Command.mm + Descriptor.h + Descriptor.mm + Enums.h + Enums.mm Graphics.h - Graphics.mm - Pipeline.h - Pipeline.mm - PipelineCache.h - PipelineCache.mm + Graphics.mm + Pipeline.h + Pipeline.mm + PipelineCache.h + PipelineCache.mm PrivateImpl.mm - RenderPass.h - RenderPass.mm - Resources.h - Resources.mm - Shader.h - Shader.mm - Texture.h - Texture.mm - Window.h + Query.h + Query.mm + RenderPass.h + RenderPass.mm + Resources.h + Resources.mm + Shader.h + Shader.mm + Texture.h + Texture.mm + Window.h Window.mm) \ No newline at end of file diff --git a/src/Engine/Graphics/Metal/Command.mm b/src/Engine/Graphics/Metal/Command.mm index 4607c5f..80fcd08 100644 --- a/src/Engine/Graphics/Metal/Command.mm +++ b/src/Engine/Graphics/Metal/Command.mm @@ -16,334 +16,223 @@ using namespace Seele; using namespace Seele::Metal; -Command::Command(PGraphics graphics, MTL::CommandBuffer *cmdBuffer) - : graphics(graphics), completed(new Event(graphics)), cmdBuffer(cmdBuffer) { -} +Command::Command(PGraphics graphics, MTL::CommandBuffer* cmdBuffer) + : graphics(graphics), completed(new Event(graphics)), cmdBuffer(cmdBuffer) {} Command::~Command() {} void Command::beginRenderPass(PRenderPass renderPass) { - if (blitEncoder) { - blitEncoder->endEncoding(); - blitEncoder = nullptr; - } - renderPass->updateRenderPass(); - parallelEncoder = - cmdBuffer->parallelRenderCommandEncoder(renderPass->getDescriptor()); + if (blitEncoder) { + blitEncoder->endEncoding(); + blitEncoder = nullptr; + } + renderPass->updateRenderPass(); + parallelEncoder = cmdBuffer->parallelRenderCommandEncoder(renderPass->getDescriptor()); } void Command::endRenderPass() { - parallelEncoder->endEncoding(); - parallelEncoder = nullptr; + parallelEncoder->endEncoding(); + parallelEncoder = nullptr; } -void Command::present(MTL::Drawable *drawable) { - cmdBuffer->presentDrawable(drawable); -} +void Command::present(MTL::Drawable* drawable) { cmdBuffer->presentDrawable(drawable); } void Command::end(PEvent signal) { - assert(!parallelEncoder); - blitEncoder->endEncoding(); - if (signal != nullptr) { - cmdBuffer->encodeSignalEvent(signal->getHandle(), 1); - } - cmdBuffer->encodeSignalEvent(completed->getHandle(), 1); - cmdBuffer->commit(); + assert(!parallelEncoder); + blitEncoder->endEncoding(); + if (signal != nullptr) { + cmdBuffer->encodeSignalEvent(signal->getHandle(), 1); + } + cmdBuffer->encodeSignalEvent(completed->getHandle(), 1); + cmdBuffer->commit(); } void Command::waitDeviceIdle() { cmdBuffer->waitUntilCompleted(); } -void Command::signalEvent(PEvent event) { - cmdBuffer->encodeSignalEvent(event->getHandle(), 1); -} +void Command::signalEvent(PEvent event) { cmdBuffer->encodeSignalEvent(event->getHandle(), 1); } -void Command::waitForEvent(PEvent event) { - cmdBuffer->encodeWait(event->getHandle(), 1); -} +void Command::waitForEvent(PEvent event) { cmdBuffer->encodeWait(event->getHandle(), 1); } -RenderCommand::RenderCommand(MTL::RenderCommandEncoder *encoder, - const std::string &name) - : encoder(encoder), name(name) {} +RenderCommand::RenderCommand(MTL::RenderCommandEncoder* encoder, const std::string& name) : encoder(encoder), name(name) {} RenderCommand::~RenderCommand() {} void RenderCommand::end() { encoder->endEncoding(); } void RenderCommand::setViewport(Gfx::PViewport viewport) { - MTL::Viewport vp = viewport.cast()->getHandle(); - MTL::ScissorRect rect = { - .x = static_cast(vp.originX), - .y = static_cast(vp.originY), - .width = static_cast(vp.width), - .height = static_cast(vp.height), - }; - encoder->setViewport(vp); - encoder->setScissorRect(rect); + MTL::Viewport vp = viewport.cast()->getHandle(); + MTL::ScissorRect rect = { + .x = static_cast(vp.originX), + .y = static_cast(vp.originY), + .width = static_cast(vp.width), + .height = static_cast(vp.height), + }; + encoder->setViewport(vp); + encoder->setScissorRect(rect); } void RenderCommand::bindPipeline(Gfx::PGraphicsPipeline pipeline) { - boundPipeline = pipeline.cast(); - encoder->setRenderPipelineState(boundPipeline->getHandle()); + boundPipeline = pipeline.cast(); + encoder->setRenderPipelineState(boundPipeline->getHandle()); } -void RenderCommand::bindPipeline(Gfx::PRayTracingPipeline pipeline) { - +void RenderCommand::bindPipeline(Gfx::PRayTracingPipeline pipeline) {} + +void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array offsets) { + auto metalSet = descriptorSet.cast(); + metalSet->bind(); } -void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet, - Array offsets) { - auto metalSet = descriptorSet.cast(); - uint32 parameterIndex = boundPipeline->getPipelineLayout()->findParameter( - 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; +void RenderCommand::bindDescriptor(const Array& descriptorSets, Array offsets) { + for (auto set : descriptorSets) { + bindDescriptor(set, offsets); } - 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; +} +void RenderCommand::bindVertexBuffer(const Array& buffers) { + uint32 i = 0; + for (auto buffer : buffers) { + encoder->setVertexBuffer(buffer.cast()->getHandle(), 0, METAL_VERTEXBUFFER_OFFSET + i++); } - for(size_t x = 0; x < metalSet->getBoundResources()[i].size(); ++x) - { - encoder->useResource(metalSet->getBoundResources()[i][x], usage); +} + +void RenderCommand::bindIndexBuffer(Gfx::PIndexBuffer gfxIndexBuffer) { boundIndexBuffer = gfxIndexBuffer.cast(); } + +void RenderCommand::pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) { + if (stage & Gfx::SE_SHADER_STAGE_VERTEX_BIT) { + encoder->setVertexBytes((char*)data + offset, size, 0); + } + if (stage & Gfx::SE_SHADER_STAGE_FRAGMENT_BIT) { + encoder->setFragmentBytes((char*)data + offset, size, 0); } - } } -void RenderCommand::bindDescriptor( - const Array &descriptorSets, Array offsets) { - for (auto set : descriptorSets) { - bindDescriptor(set, offsets); - } -} -void RenderCommand::bindVertexBuffer(const Array &buffers) { - uint32 i = 0; - for (auto buffer : buffers) { - encoder->setVertexBuffer(buffer.cast()->getHandle(), 0, - METAL_VERTEXBUFFER_OFFSET + i++); - } +void RenderCommand::draw(uint32 vertexCount, uint32 instanceCount, int32 firstVertex, uint32 firstInstance) { + encoder->drawPrimitives(boundPipeline->getPrimitive(), firstVertex, vertexCount, instanceCount, firstInstance); } -void RenderCommand::bindIndexBuffer(Gfx::PIndexBuffer gfxIndexBuffer) { - boundIndexBuffer = gfxIndexBuffer.cast(); -} - -void RenderCommand::pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, - uint32 size, const void *data) { - if (stage & Gfx::SE_SHADER_STAGE_VERTEX_BIT) { - encoder->setVertexBytes((char *)data + offset, size, 0); - } - if (stage & Gfx::SE_SHADER_STAGE_FRAGMENT_BIT) { - encoder->setFragmentBytes((char *)data + offset, size, 0); - } -} - -void RenderCommand::draw(uint32 vertexCount, uint32 instanceCount, - int32 firstVertex, uint32 firstInstance) { - encoder->drawPrimitives(boundPipeline->getPrimitive(), firstVertex, - vertexCount, instanceCount, firstInstance); -} - -void RenderCommand::drawIndexed(uint32 indexCount, uint32 instanceCount, - int32 firstIndex, uint32 vertexOffset, - uint32 firstInstance) { - encoder->drawIndexedPrimitives(boundPipeline->getPrimitive(), indexCount, - cast(boundIndexBuffer->getIndexType()), - boundIndexBuffer->getHandle(), firstIndex, - instanceCount, vertexOffset, firstInstance); +void RenderCommand::drawIndexed(uint32 indexCount, uint32 instanceCount, int32 firstIndex, uint32 vertexOffset, uint32 firstInstance) { + encoder->drawIndexedPrimitives(boundPipeline->getPrimitive(), indexCount, cast(boundIndexBuffer->getIndexType()), + boundIndexBuffer->getHandle(), firstIndex, instanceCount, vertexOffset, firstInstance); } void RenderCommand::drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) { - // TODO: - std::cout << "Draw" << std::endl; - encoder->setFragmentBuffer(argumentBuffer, 0, 2); - encoder->setMeshBuffer(argumentBuffer, 0, 2); - encoder->setObjectBuffer(argumentBuffer, 0, 2); - encoder->drawMeshThreadgroups(MTL::Size(groupX, groupY, groupZ), - MTL::Size(128, 1, 1), MTL::Size(32, 1, 1)); + // TODO: + std::cout << "Draw" << std::endl; + encoder->setFragmentBuffer(argumentBuffer, 0, 2); + encoder->setMeshBuffer(argumentBuffer, 0, 2); + encoder->setObjectBuffer(argumentBuffer, 0, 2); + encoder->drawMeshThreadgroups(MTL::Size(groupX, groupY, groupZ), MTL::Size(128, 1, 1), MTL::Size(32, 1, 1)); } -void RenderCommand::drawMeshIndirect(Gfx::PShaderBuffer buffer, uint64 offset, - uint32 drawCount, uint32 stride) { - // encoder->drawMeshThreadgroups() +void RenderCommand::drawMeshIndirect(Gfx::PShaderBuffer buffer, uint64 offset, uint32 drawCount, uint32 stride) { + // 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() {} void ComputeCommand::end() { - encoder->endEncoding(); - commandBuffer->commit(); + encoder->endEncoding(); + commandBuffer->commit(); } void ComputeCommand::bindPipeline(Gfx::PComputePipeline pipeline) { - boundPipeline = pipeline.cast(); - encoder->setComputePipelineState(boundPipeline->getHandle()); - argumentBuffer = boundPipeline->graphics->getDevice()->newBuffer( - sizeof(uint64) * - (boundPipeline->getPipelineLayout()->getLayouts().size() + 1), - MTL::ResourceStorageModeShared); - argumentBuffer->setLabel( - NS::String::string(pipeline->getPipelineLayout()->getName().c_str(), - NS::ASCIIStringEncoding)); + boundPipeline = pipeline.cast(); + encoder->setComputePipelineState(boundPipeline->getHandle()); + argumentBuffer = boundPipeline->graphics->getDevice()->newBuffer( + sizeof(uint64) * (boundPipeline->getPipelineLayout()->getLayouts().size() + 1), MTL::ResourceStorageModeShared); + argumentBuffer->setLabel(NS::String::string(pipeline->getPipelineLayout()->getName().c_str(), NS::ASCIIStringEncoding)); } -void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set, - Array offsets) { - auto metalSet = set.cast(); - 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(Gfx::PDescriptorSet set, Array offsets) { + auto metalSet = set.cast(); + metalSet->bind(); } -void ComputeCommand::bindDescriptor(const Array &sets, - Array offsets) { - for (auto &set : sets) { - bindDescriptor(set, offsets); - } +void ComputeCommand::bindDescriptor(const Array& sets, Array offsets) { + for (auto& set : sets) { + bindDescriptor(set, offsets); + } } -void ComputeCommand::pushConstants(Gfx::SeShaderStageFlags, uint32 offset, - uint32 size, const void *data) { - encoder->setBytes((char *)data + offset, size, 0); +void ComputeCommand::pushConstants(Gfx::SeShaderStageFlags, uint32 offset, uint32 size, const void* data) { + encoder->setBytes((char*)data + offset, size, 0); } void ComputeCommand::dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) { - // TODO - encoder->setBuffer(argumentBuffer, 0, 2); - encoder->dispatchThreadgroups(MTL::Size(threadX, threadY, threadZ), - MTL::Size(32, 32, 1)); + // TODO + encoder->setBuffer(argumentBuffer, 0, 2); + encoder->dispatchThreadgroups(MTL::Size(threadX, threadY, threadZ), MTL::Size(32, 32, 1)); } CommandQueue::CommandQueue(PGraphics graphics) : graphics(graphics) { - queue = graphics->getDevice()->newCommandQueue(); - MTL::CommandBufferDescriptor *descriptor = - MTL::CommandBufferDescriptor::alloc()->init(); - activeCommand = new Command(graphics, queue->commandBuffer(descriptor)); - descriptor->release(); + queue = graphics->getDevice()->newCommandQueue(); + MTL::CommandBufferDescriptor* descriptor = MTL::CommandBufferDescriptor::alloc()->init(); + activeCommand = new Command(graphics, queue->commandBuffer(descriptor)); + descriptor->release(); } CommandQueue::~CommandQueue() { queue->release(); } -ORenderCommand CommandQueue::getRenderCommand(const std::string &name) { - return new RenderCommand(activeCommand->createRenderEncoder(), name); +ORenderCommand CommandQueue::getRenderCommand(const std::string& name) { + return new RenderCommand(activeCommand->createRenderEncoder(), name); } -OComputeCommand CommandQueue::getComputeCommand(const std::string &name) { - return new ComputeCommand(queue->commandBuffer(), name); -} +OComputeCommand CommandQueue::getComputeCommand(const std::string& name) { return new ComputeCommand(queue->commandBuffer(), name); } void CommandQueue::executeCommands(Array commands) { - for (auto &command : commands) { - auto metalCmd = Gfx::PRenderCommand(command).cast(); - metalCmd->end(); - } + for (auto& command : commands) { + auto metalCmd = Gfx::PRenderCommand(command).cast(); + metalCmd->end(); + } } void CommandQueue::executeCommands(Array commands) { - submitCommands(); - for (auto &command : commands) { - auto metalCmd = Gfx::PComputeCommand(command).cast(); - metalCmd->end(); - } + submitCommands(); + for (auto& command : commands) { + auto metalCmd = Gfx::PComputeCommand(command).cast(); + metalCmd->end(); + } } void CommandQueue::submitCommands(PEvent signalSemaphore) { - activeCommand->getHandle()->addCompletedHandler( - MTL::CommandBufferHandler([&](MTL::CommandBuffer *cmdBuffer) { - for (auto it = pendingCommands.begin(); it != pendingCommands.end(); - it++) { - if ((*it)->getHandle() == cmdBuffer) { - pendingCommands.remove(it); - return; - } + activeCommand->getHandle()->addCompletedHandler(MTL::CommandBufferHandler([&](MTL::CommandBuffer* cmdBuffer) { + for (auto it = pendingCommands.begin(); it != pendingCommands.end(); it++) { + if ((*it)->getHandle() == cmdBuffer) { + pendingCommands.remove(it); + return; + } } - })); - activeCommand->end(signalSemaphore); - activeCommand->waitDeviceIdle(); - PEvent prevCmdEvent = activeCommand->getCompletedEvent(); - pendingCommands.add(std::move(activeCommand)); - MTL::CommandBufferDescriptor *descriptor = - MTL::CommandBufferDescriptor::alloc()->init(); - descriptor->setErrorOptions( - MTL::CommandBufferErrorOptionEncoderExecutionStatus); - activeCommand = new Command(graphics, queue->commandBuffer(descriptor)); - activeCommand->waitForEvent(prevCmdEvent); + })); + activeCommand->end(signalSemaphore); + activeCommand->waitDeviceIdle(); + PEvent prevCmdEvent = activeCommand->getCompletedEvent(); + pendingCommands.add(std::move(activeCommand)); + MTL::CommandBufferDescriptor* descriptor = MTL::CommandBufferDescriptor::alloc()->init(); + descriptor->setErrorOptions(MTL::CommandBufferErrorOptionEncoderExecutionStatus); + activeCommand = new Command(graphics, queue->commandBuffer(descriptor)); + activeCommand->waitForEvent(prevCmdEvent); } IOCommandQueue::IOCommandQueue(PGraphics graphics) : graphics(graphics) { - MTL::IOCommandQueueDescriptor *desc = - MTL::IOCommandQueueDescriptor::alloc()->init(); - desc->setType(MTL::IOCommandQueueTypeConcurrent); - desc->setPriority(MTL::IOPriorityNormal); - queue = graphics->getDevice()->newIOCommandQueue(desc, nullptr); - // activeCommand = new Command(graphics, queue->commandBuffer()); - desc->release(); + MTL::IOCommandQueueDescriptor* desc = MTL::IOCommandQueueDescriptor::alloc()->init(); + desc->setType(MTL::IOCommandQueueTypeConcurrent); + desc->setPriority(MTL::IOPriorityNormal); + queue = graphics->getDevice()->newIOCommandQueue(desc, nullptr); + // activeCommand = new Command(graphics, queue->commandBuffer()); + desc->release(); } IOCommandQueue::~IOCommandQueue() { queue->release(); } void IOCommandQueue::submitCommands(PEvent signalSemaphore) { - // TODO: scratch buffer - activeCommand->end(signalSemaphore); - PEvent prevCmdEvent = activeCommand->getCompletedEvent(); - // activeCommand = new Command(graphics, queue->commandBuffer()); - activeCommand->waitForEvent(prevCmdEvent); + // TODO: scratch buffer + activeCommand->end(signalSemaphore); + PEvent prevCmdEvent = activeCommand->getCompletedEvent(); + // activeCommand = new Command(graphics, queue->commandBuffer()); + activeCommand->waitForEvent(prevCmdEvent); } diff --git a/src/Engine/Graphics/Metal/Descriptor.h b/src/Engine/Graphics/Metal/Descriptor.h index a099064..0cf4b1f 100644 --- a/src/Engine/Graphics/Metal/Descriptor.h +++ b/src/Engine/Graphics/Metal/Descriptor.h @@ -1,11 +1,13 @@ #pragma once #include "Buffer.h" #include "Foundation/NSArray.hpp" +#include "Foundation/NSObject.hpp" #include "Graphics/Descriptor.h" #include "Graphics/Initializer.h" #include "Graphics/Metal/Resources.h" #include "Metal/MTLArgumentEncoder.hpp" #include "Metal/MTLLibrary.hpp" +#include "Metal/MTLResource.hpp" #include "MinimalEngine.h" namespace Seele { @@ -16,13 +18,11 @@ class DescriptorLayout : public Gfx::DescriptorLayout { DescriptorLayout(PGraphics graphics, const std::string& name); virtual ~DescriptorLayout(); virtual void create() override; - void setFunction(MTL::Function* func, uint64 ind) { function = func; index = ind; } - MTL::ArgumentEncoder* createEncoder() { return function->newArgumentEncoder(index); } + MTL::ArgumentEncoder* createEncoder(); private: PGraphics graphics; - MTL::Function* function; - uint64 index; + NS::Array* arguments; }; DEFINE_REF(DescriptorLayout) @@ -59,15 +59,14 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource { virtual void updateSamplerArray(uint32 binding, Array samplers) override; virtual void updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS as) override; - constexpr MTL::Buffer* getBuffer() const { return buffer; } constexpr const Array>& getBoundResources() const { return boundResources; } private: PGraphics graphics; PDescriptorPool owner; - MTL::ArgumentEncoder* encoder; - MTL::Buffer* buffer = nullptr; Array> boundResources; + MTL::ArgumentEncoder* encoder; + MTL::Buffer* argumentBuffer = nullptr; }; DEFINE_REF(DescriptorSet) diff --git a/src/Engine/Graphics/Metal/Descriptor.mm b/src/Engine/Graphics/Metal/Descriptor.mm index 4b3e0a9..4a8a358 100644 --- a/src/Engine/Graphics/Metal/Descriptor.mm +++ b/src/Engine/Graphics/Metal/Descriptor.mm @@ -1,120 +1,123 @@ #include "Descriptor.h" #include "Buffer.h" #include "Enums.h" +#include "Foundation/NSArray.hpp" #include "Foundation/NSObject.hpp" #include "Graphics/Descriptor.h" #include "Graphics/Initializer.h" #include "Graphics/Metal/Resources.h" +#include "Graphics/Metal/Shader.h" #include "Metal/MTLArgument.hpp" +#include "Metal/MTLArgumentEncoder.hpp" #include "Metal/MTLDevice.hpp" #include "Metal/MTLResource.hpp" +#include "Metal/MTLStageInputOutputDescriptor.hpp" #include "Metal/MTLTexture.hpp" #include "Texture.h" -#include #include +#include #include using namespace Seele; using namespace Seele::Metal; -DescriptorLayout::DescriptorLayout(PGraphics graphics, const std::string &name) - : Gfx::DescriptorLayout(name), graphics(graphics) {} +DescriptorLayout::DescriptorLayout(PGraphics graphics, const std::string& name) : Gfx::DescriptorLayout(name), graphics(graphics) {} DescriptorLayout::~DescriptorLayout() {} void DescriptorLayout::create() { pool = new DescriptorPool(graphics, this); - hash = - CRC::Calculate(descriptorBindings.data(), - sizeof(Gfx::DescriptorBinding) * descriptorBindings.size(), - CRC::CRC_32()); + hash = CRC::Calculate(descriptorBindings.data(), sizeof(Gfx::DescriptorBinding) * descriptorBindings.size(), CRC::CRC_32()); + MTL::ArgumentDescriptor** objects = new MTL::ArgumentDescriptor*[descriptorBindings.size()]; + for(uint32 i = 0; i < descriptorBindings.size(); ++i) { + 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) - : graphics(graphics), layout(layout) {} +MTL::ArgumentEncoder* DescriptorLayout::createEncoder() { + return graphics->getDevice()->newArgumentEncoder(arguments); +} + +DescriptorPool::DescriptorPool(PGraphics graphics, PDescriptorLayout layout) : graphics(graphics), layout(layout) {} DescriptorPool::~DescriptorPool() {} Gfx::PDescriptorSet DescriptorPool::allocateDescriptorSet() { - for (uint32 setIndex = 0; setIndex < allocatedSets.size(); ++setIndex) { - if (allocatedSets[setIndex]->isCurrentlyBound()) { - // Currently in use, skip - continue; + for (uint32 setIndex = 0; setIndex < allocatedSets.size(); ++setIndex) { + if (allocatedSets[setIndex]->isCurrentlyBound()) { + // Currently in use, skip + continue; + } + + // Found set, stop searching + return PDescriptorSet(allocatedSets[setIndex]); } - - // Found set, stop searching - return PDescriptorSet(allocatedSets[setIndex]); - } - allocatedSets.add(new DescriptorSet(graphics, this)); - return PDescriptorSet(allocatedSets.back()); + allocatedSets.add(new DescriptorSet(graphics, this)); + return PDescriptorSet(allocatedSets.back()); } -void DescriptorPool::reset() { -} +void DescriptorPool::reset() {} DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner) - : Gfx::DescriptorSet(owner->getLayout()), CommandBoundResource(graphics), - graphics(graphics), owner(owner) { - boundResources.resize(owner->getLayout()->getBindings().size()); - for(uint32 i = 0; i < boundResources.size(); ++i) { - boundResources[i].resize(owner->getLayout()->getBindings()[i].descriptorCount); - } - encoder = owner->getLayout()->createEncoder(); - buffer = graphics->getDevice()->newBuffer(encoder->encodedLength(), MTL::ResourceOptionCPUCacheModeDefault); - buffer->setLabel(NS::String::string(owner->getLayout()->getName().c_str(), - NS::ASCIIStringEncoding)); + : Gfx::DescriptorSet(owner->getLayout()), CommandBoundResource(graphics), graphics(graphics), owner(owner) { + boundResources.resize(owner->getLayout()->getBindings().size()); + for (uint32 i = 0; i < boundResources.size(); ++i) { + boundResources[i].resize(owner->getLayout()->getBindings()[i].descriptorCount); + } } -DescriptorSet::~DescriptorSet() { buffer->release(); } +DescriptorSet::~DescriptorSet() {} void DescriptorSet::writeChanges() {} -void DescriptorSet::updateBuffer(uint32 binding, Gfx::PUniformBuffer uniformBuffer) -{ - encoder->setBuffer(uniformBuffer.cast()->getHandle(), 0, binding); +void DescriptorSet::updateBuffer(uint32 binding, Gfx::PUniformBuffer uniformBuffer) { + boundResources[binding][0] = uniformBuffer.cast()->getHandle(); } -void DescriptorSet::updateBuffer(uint32 binding, Gfx::PShaderBuffer uniformBuffer) -{ - encoder->setBuffer(uniformBuffer.cast()->getHandle(), 0, binding); +void DescriptorSet::updateBuffer(uint32 binding, Gfx::PShaderBuffer uniformBuffer) { + boundResources[binding][0] = uniformBuffer.cast()->getHandle(); } -void DescriptorSet::updateBuffer(uint32 binding, Gfx::PIndexBuffer uniformBuffer) -{ - encoder->setBuffer(uniformBuffer.cast()->getHandle(), 0, binding); +void DescriptorSet::updateBuffer(uint32 binding, Gfx::PIndexBuffer uniformBuffer) { + boundResources[binding][0] = uniformBuffer.cast()->getHandle(); } -void DescriptorSet::updateBuffer(uint32 binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) -{ - encoder->setBuffer(uniformBuffer.cast()->getHandle(), 0, binding); +void DescriptorSet::updateBuffer(uint32 binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) { + boundResources[binding][0] = uniformBuffer.cast()->getHandle(); } -void DescriptorSet::updateSampler(uint32 binding, Gfx::PSampler samplerState) -{} -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 texture) -{} -void DescriptorSet::updateSamplerArray(uint32 binding, Array samplers) -{} -void DescriptorSet::updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS as) -{} +void DescriptorSet::updateSampler(uint32 binding, Gfx::PSampler samplerState) { + boundResources[binding][0] = nullptr; // Samplers are not resources?????? +} -PipelineLayout::PipelineLayout(PGraphics graphics, const std::string &name, - Gfx::PPipelineLayout baseLayout) +void DescriptorSet::updateSampler(uint32 binding, uint32 dstArrayIndex, Gfx::PSampler samplerState) { + boundResources[binding][dstArrayIndex] = nullptr; +} + +void DescriptorSet::updateTexture(uint32 binding, Gfx::PTexture texture, Gfx::PSampler sampler) {} + +void DescriptorSet::updateTexture(uint32 binding, uint32 dstArrayIndex, Gfx::PTexture texture) {} + +void DescriptorSet::updateTextureArray(uint32 binding, Array texture) {} + +void DescriptorSet::updateSamplerArray(uint32 binding, Array 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) {} PipelineLayout::~PipelineLayout() {} void PipelineLayout::create() { - for (auto &[_, set] : descriptorSetLayouts) { - assert(set->getHash() != 0); - uint32 setHash = set->getHash(); - layoutHash = - CRC::Calculate(&setHash, sizeof(uint32), CRC::CRC_32(), layoutHash); - } + for (auto& [_, set] : descriptorSetLayouts) { + assert(set->getHash() != 0); + uint32 setHash = set->getHash(); + layoutHash = CRC::Calculate(&setHash, sizeof(uint32), CRC::CRC_32(), layoutHash); + } } diff --git a/src/Engine/Graphics/Metal/Enums.mm b/src/Engine/Graphics/Metal/Enums.mm index b78f5bd..617b83a 100644 --- a/src/Engine/Graphics/Metal/Enums.mm +++ b/src/Engine/Graphics/Metal/Enums.mm @@ -7,810 +7,809 @@ using namespace Seele; using namespace Seele::Metal; MTL::PixelFormat Seele::Metal::cast(Gfx::SeFormat format) { - switch (format) { - case Gfx::SE_FORMAT_UNDEFINED: - return MTL::PixelFormatInvalid; - case Gfx::SE_FORMAT_R8_UNORM: - return MTL::PixelFormatR8Unorm; - case Gfx::SE_FORMAT_R8_SRGB: - return MTL::PixelFormatR8Unorm_sRGB; - case Gfx::SE_FORMAT_R8_SNORM: - return MTL::PixelFormatR8Snorm; - case Gfx::SE_FORMAT_R8_UINT: - return MTL::PixelFormatR8Uint; - case Gfx::SE_FORMAT_R8_SINT: - return MTL::PixelFormatR8Sint; - case Gfx::SE_FORMAT_R16_UNORM: - return MTL::PixelFormatR16Unorm; - case Gfx::SE_FORMAT_R16_SNORM: - return MTL::PixelFormatR16Snorm; - case Gfx::SE_FORMAT_R16_UINT: - return MTL::PixelFormatR16Uint; - case Gfx::SE_FORMAT_R16_SINT: - return MTL::PixelFormatR16Sint; - case Gfx::SE_FORMAT_R16_SFLOAT: - return MTL::PixelFormatR16Float; - case Gfx::SE_FORMAT_R8G8_UNORM: - return MTL::PixelFormatRG8Unorm; - case Gfx::SE_FORMAT_R8G8_SRGB: - return MTL::PixelFormatRG8Unorm_sRGB; - case Gfx::SE_FORMAT_R8G8_SNORM: - return MTL::PixelFormatRG8Snorm; - case Gfx::SE_FORMAT_R8G8_UINT: - return MTL::PixelFormatRG8Uint; - case Gfx::SE_FORMAT_R8G8_SINT: - return MTL::PixelFormatRG8Sint; - case Gfx::SE_FORMAT_B5G6R5_UNORM_PACK16: - return MTL::PixelFormatB5G6R5Unorm; - case Gfx::SE_FORMAT_R4G4B4A4_UNORM_PACK16: - return MTL::PixelFormatABGR4Unorm; - case Gfx::SE_FORMAT_B5G5R5A1_UNORM_PACK16: - return MTL::PixelFormatBGR5A1Unorm; - case Gfx::SE_FORMAT_R32_UINT: - return MTL::PixelFormatR32Uint; - case Gfx::SE_FORMAT_R32_SINT: - return MTL::PixelFormatR32Sint; - case Gfx::SE_FORMAT_R32_SFLOAT: - return MTL::PixelFormatR32Float; - case Gfx::SE_FORMAT_R16G16_UNORM: - return MTL::PixelFormatRG16Unorm; - case Gfx::SE_FORMAT_R16G16_SNORM: - return MTL::PixelFormatRG16Snorm; - case Gfx::SE_FORMAT_R16G16_UINT: - return MTL::PixelFormatRG16Uint; - case Gfx::SE_FORMAT_R16G16_SINT: - return MTL::PixelFormatRG16Sint; - case Gfx::SE_FORMAT_R16G16_SFLOAT: - return MTL::PixelFormatRG16Float; - case Gfx::SE_FORMAT_R8G8B8A8_UNORM: - return MTL::PixelFormatRGBA8Unorm; - case Gfx::SE_FORMAT_R8G8B8A8_SRGB: - return MTL::PixelFormatRGBA8Unorm_sRGB; - case Gfx::SE_FORMAT_R8G8B8A8_SNORM: - return MTL::PixelFormatRGBA8Snorm; - case Gfx::SE_FORMAT_R8G8B8A8_UINT: - return MTL::PixelFormatRGBA8Uint; - case Gfx::SE_FORMAT_R8G8B8A8_SINT: - return MTL::PixelFormatRGBA8Sint; - case Gfx::SE_FORMAT_B8G8R8A8_UNORM: - return MTL::PixelFormatBGRA8Unorm; - case Gfx::SE_FORMAT_B8G8R8A8_SRGB: - return MTL::PixelFormatBGRA8Unorm_sRGB; - case Gfx::SE_FORMAT_R32G32_UINT: - return MTL::PixelFormatRG32Uint; - case Gfx::SE_FORMAT_R32G32_SINT: - return MTL::PixelFormatRG32Sint; - case Gfx::SE_FORMAT_R32G32_SFLOAT: - return MTL::PixelFormatRG32Float; - case Gfx::SE_FORMAT_R16G16B16A16_UNORM: - return MTL::PixelFormatRGBA16Unorm; - case Gfx::SE_FORMAT_R16G16B16A16_SNORM: - return MTL::PixelFormatRGBA16Snorm; - case Gfx::SE_FORMAT_R16G16B16A16_UINT: - return MTL::PixelFormatRGBA16Uint; - case Gfx::SE_FORMAT_R16G16B16A16_SINT: - return MTL::PixelFormatRGBA16Sint; - case Gfx::SE_FORMAT_R16G16B16A16_SFLOAT: - return MTL::PixelFormatRGBA16Float; - case Gfx::SE_FORMAT_R32G32B32A32_UINT: - return MTL::PixelFormatRGBA32Uint; - case Gfx::SE_FORMAT_R32G32B32A32_SINT: - return MTL::PixelFormatRGBA32Sint; - case Gfx::SE_FORMAT_R32G32B32A32_SFLOAT: - return MTL::PixelFormatRGBA32Float; - case Gfx::SE_FORMAT_BC1_RGBA_UNORM_BLOCK: - return MTL::PixelFormatBC1_RGBA; - case Gfx::SE_FORMAT_BC1_RGBA_SRGB_BLOCK: - return MTL::PixelFormatBC1_RGBA_sRGB; - case Gfx::SE_FORMAT_BC2_UNORM_BLOCK: - return MTL::PixelFormatBC2_RGBA; - case Gfx::SE_FORMAT_BC2_SRGB_BLOCK: - return MTL::PixelFormatBC2_RGBA_sRGB; - case Gfx::SE_FORMAT_BC3_UNORM_BLOCK: - return MTL::PixelFormatBC3_RGBA; - case Gfx::SE_FORMAT_BC3_SRGB_BLOCK: - return MTL::PixelFormatBC3_RGBA_sRGB; - case Gfx::SE_FORMAT_BC4_UNORM_BLOCK: - return MTL::PixelFormatBC4_RUnorm; - case Gfx::SE_FORMAT_BC4_SNORM_BLOCK: - return MTL::PixelFormatBC4_RSnorm; - case Gfx::SE_FORMAT_BC5_UNORM_BLOCK: - return MTL::PixelFormatBC5_RGUnorm; - case Gfx::SE_FORMAT_BC5_SNORM_BLOCK: - return MTL::PixelFormatBC5_RGSnorm; - case Gfx::SE_FORMAT_BC6H_SFLOAT_BLOCK: - return MTL::PixelFormatBC6H_RGBFloat; - case Gfx::SE_FORMAT_BC6H_UFLOAT_BLOCK: - return MTL::PixelFormatBC6H_RGBUfloat; - case Gfx::SE_FORMAT_BC7_UNORM_BLOCK: - return MTL::PixelFormatBC7_RGBAUnorm; - case Gfx::SE_FORMAT_BC7_SRGB_BLOCK: - return MTL::PixelFormatBC7_RGBAUnorm_sRGB; - case Gfx::SE_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG: - return MTL::PixelFormatPVRTC_RGB_2BPP; - case Gfx::SE_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG: - return MTL::PixelFormatPVRTC_RGB_2BPP_sRGB; - case Gfx::SE_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG: - return MTL::PixelFormatPVRTC_RGB_4BPP; - case Gfx::SE_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG: - return MTL::PixelFormatPVRTC_RGB_4BPP_sRGB; - case Gfx::SE_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG: - return MTL::PixelFormatPVRTC_RGBA_2BPP; - case Gfx::SE_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG: - return MTL::PixelFormatPVRTC_RGBA_2BPP_sRGB; - case Gfx::SE_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG: - return MTL::PixelFormatPVRTC_RGBA_4BPP; - case Gfx::SE_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG: - return MTL::PixelFormatPVRTC_RGBA_4BPP_sRGB; - case Gfx::SE_FORMAT_EAC_R11_UNORM_BLOCK: - return MTL::PixelFormatEAC_R11Unorm; - case Gfx::SE_FORMAT_EAC_R11_SNORM_BLOCK: - return MTL::PixelFormatEAC_R11Snorm; - case Gfx::SE_FORMAT_EAC_R11G11_UNORM_BLOCK: - return MTL::PixelFormatEAC_RG11Unorm; - case Gfx::SE_FORMAT_EAC_R11G11_SNORM_BLOCK: - return MTL::PixelFormatEAC_RG11Snorm; - case Gfx::SE_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: - return MTL::PixelFormatETC2_RGB8; - case Gfx::SE_FORMAT_ETC2_R8G8B8_SRGB_BLOCK: - return MTL::PixelFormatETC2_RGB8_sRGB; - case Gfx::SE_FORMAT_ASTC_4x4_SRGB_BLOCK: - return MTL::PixelFormatASTC_4x4_sRGB; - case Gfx::SE_FORMAT_ASTC_5x4_SRGB_BLOCK: - return MTL::PixelFormatASTC_5x4_sRGB; - case Gfx::SE_FORMAT_ASTC_5x5_SRGB_BLOCK: - return MTL::PixelFormatASTC_5x5_sRGB; - case Gfx::SE_FORMAT_ASTC_6x5_SRGB_BLOCK: - return MTL::PixelFormatASTC_6x5_sRGB; - case Gfx::SE_FORMAT_ASTC_6x6_SRGB_BLOCK: - return MTL::PixelFormatASTC_6x6_sRGB; - case Gfx::SE_FORMAT_ASTC_8x5_SRGB_BLOCK: - return MTL::PixelFormatASTC_8x5_sRGB; - case Gfx::SE_FORMAT_ASTC_8x6_SRGB_BLOCK: - return MTL::PixelFormatASTC_8x6_sRGB; - case Gfx::SE_FORMAT_ASTC_8x8_SRGB_BLOCK: - return MTL::PixelFormatASTC_8x8_sRGB; - case Gfx::SE_FORMAT_ASTC_10x5_SRGB_BLOCK: - return MTL::PixelFormatASTC_10x5_sRGB; - case Gfx::SE_FORMAT_ASTC_10x6_SRGB_BLOCK: - return MTL::PixelFormatASTC_10x6_sRGB; - case Gfx::SE_FORMAT_ASTC_10x8_SRGB_BLOCK: - return MTL::PixelFormatASTC_10x8_sRGB; - case Gfx::SE_FORMAT_ASTC_10x10_SRGB_BLOCK: - return MTL::PixelFormatASTC_10x10_sRGB; - case Gfx::SE_FORMAT_ASTC_12x10_SRGB_BLOCK: - return MTL::PixelFormatASTC_12x10_sRGB; - case Gfx::SE_FORMAT_ASTC_12x12_SRGB_BLOCK: - return MTL::PixelFormatASTC_12x12_sRGB; - case Gfx::SE_FORMAT_ASTC_4x4_UNORM_BLOCK: - return MTL::PixelFormatASTC_4x4_LDR; - case Gfx::SE_FORMAT_ASTC_5x4_UNORM_BLOCK: - return MTL::PixelFormatASTC_5x4_LDR; - case Gfx::SE_FORMAT_ASTC_5x5_UNORM_BLOCK: - return MTL::PixelFormatASTC_5x5_LDR; - case Gfx::SE_FORMAT_ASTC_6x5_UNORM_BLOCK: - return MTL::PixelFormatASTC_6x5_LDR; - case Gfx::SE_FORMAT_ASTC_6x6_UNORM_BLOCK: - return MTL::PixelFormatASTC_6x6_LDR; - case Gfx::SE_FORMAT_ASTC_8x5_UNORM_BLOCK: - return MTL::PixelFormatASTC_8x5_LDR; - case Gfx::SE_FORMAT_ASTC_8x6_UNORM_BLOCK: - return MTL::PixelFormatASTC_8x6_LDR; - case Gfx::SE_FORMAT_ASTC_8x8_UNORM_BLOCK: - return MTL::PixelFormatASTC_8x8_LDR; - case Gfx::SE_FORMAT_ASTC_10x5_UNORM_BLOCK: - return MTL::PixelFormatASTC_10x5_LDR; - case Gfx::SE_FORMAT_ASTC_10x6_UNORM_BLOCK: - return MTL::PixelFormatASTC_10x6_LDR; - case Gfx::SE_FORMAT_ASTC_10x8_UNORM_BLOCK: - return MTL::PixelFormatASTC_10x8_LDR; - case Gfx::SE_FORMAT_ASTC_10x10_UNORM_BLOCK: - return MTL::PixelFormatASTC_10x10_LDR; - case Gfx::SE_FORMAT_ASTC_12x10_UNORM_BLOCK: - return MTL::PixelFormatASTC_12x10_LDR; - case Gfx::SE_FORMAT_ASTC_12x12_UNORM_BLOCK: - return MTL::PixelFormatASTC_12x12_LDR; - case Gfx::SE_FORMAT_ASTC_4x4_SFLOAT_BLOCK: - return MTL::PixelFormatASTC_4x4_HDR; - case Gfx::SE_FORMAT_ASTC_5x4_SFLOAT_BLOCK: - return MTL::PixelFormatASTC_5x4_HDR; - case Gfx::SE_FORMAT_ASTC_5x5_SFLOAT_BLOCK: - return MTL::PixelFormatASTC_5x5_HDR; - case Gfx::SE_FORMAT_ASTC_6x5_SFLOAT_BLOCK: - return MTL::PixelFormatASTC_6x5_HDR; - case Gfx::SE_FORMAT_ASTC_6x6_SFLOAT_BLOCK: - return MTL::PixelFormatASTC_6x6_HDR; - case Gfx::SE_FORMAT_ASTC_8x5_SFLOAT_BLOCK: - return MTL::PixelFormatASTC_8x5_HDR; - case Gfx::SE_FORMAT_ASTC_8x6_SFLOAT_BLOCK: - return MTL::PixelFormatASTC_8x6_HDR; - case Gfx::SE_FORMAT_ASTC_8x8_SFLOAT_BLOCK: - return MTL::PixelFormatASTC_8x8_HDR; - case Gfx::SE_FORMAT_ASTC_10x5_SFLOAT_BLOCK: - return MTL::PixelFormatASTC_10x5_HDR; - case Gfx::SE_FORMAT_ASTC_10x6_SFLOAT_BLOCK: - return MTL::PixelFormatASTC_10x6_HDR; - case Gfx::SE_FORMAT_ASTC_10x8_SFLOAT_BLOCK: - return MTL::PixelFormatASTC_10x8_HDR; - case Gfx::SE_FORMAT_ASTC_10x10_SFLOAT_BLOCK: - return MTL::PixelFormatASTC_10x10_HDR; - case Gfx::SE_FORMAT_ASTC_12x10_SFLOAT_BLOCK: - return MTL::PixelFormatASTC_12x10_HDR; - case Gfx::SE_FORMAT_ASTC_12x12_SFLOAT_BLOCK: - return MTL::PixelFormatASTC_12x12_HDR; - case Gfx::SE_FORMAT_G8B8G8R8_422_UNORM: - return MTL::PixelFormatGBGR422; - case Gfx::SE_FORMAT_B8G8R8G8_422_UNORM: - return MTL::PixelFormatBGRG422; - case Gfx::SE_FORMAT_D16_UNORM: - return MTL::PixelFormatDepth16Unorm; - case Gfx::SE_FORMAT_D32_SFLOAT: - return MTL::PixelFormatDepth32Float; - case Gfx::SE_FORMAT_S8_UINT: - return MTL::PixelFormatStencil8; - case Gfx::SE_FORMAT_D24_UNORM_S8_UINT: - return MTL::PixelFormatDepth24Unorm_Stencil8; - case Gfx::SE_FORMAT_D32_SFLOAT_S8_UINT: - return MTL::PixelFormatDepth32Float_Stencil8; - default: - throw std::logic_error("Not implemented"); - } + switch (format) { + case Gfx::SE_FORMAT_UNDEFINED: + return MTL::PixelFormatInvalid; + case Gfx::SE_FORMAT_R8_UNORM: + return MTL::PixelFormatR8Unorm; + case Gfx::SE_FORMAT_R8_SRGB: + return MTL::PixelFormatR8Unorm_sRGB; + case Gfx::SE_FORMAT_R8_SNORM: + return MTL::PixelFormatR8Snorm; + case Gfx::SE_FORMAT_R8_UINT: + return MTL::PixelFormatR8Uint; + case Gfx::SE_FORMAT_R8_SINT: + return MTL::PixelFormatR8Sint; + case Gfx::SE_FORMAT_R16_UNORM: + return MTL::PixelFormatR16Unorm; + case Gfx::SE_FORMAT_R16_SNORM: + return MTL::PixelFormatR16Snorm; + case Gfx::SE_FORMAT_R16_UINT: + return MTL::PixelFormatR16Uint; + case Gfx::SE_FORMAT_R16_SINT: + return MTL::PixelFormatR16Sint; + case Gfx::SE_FORMAT_R16_SFLOAT: + return MTL::PixelFormatR16Float; + case Gfx::SE_FORMAT_R8G8_UNORM: + return MTL::PixelFormatRG8Unorm; + case Gfx::SE_FORMAT_R8G8_SRGB: + return MTL::PixelFormatRG8Unorm_sRGB; + case Gfx::SE_FORMAT_R8G8_SNORM: + return MTL::PixelFormatRG8Snorm; + case Gfx::SE_FORMAT_R8G8_UINT: + return MTL::PixelFormatRG8Uint; + case Gfx::SE_FORMAT_R8G8_SINT: + return MTL::PixelFormatRG8Sint; + case Gfx::SE_FORMAT_B5G6R5_UNORM_PACK16: + return MTL::PixelFormatB5G6R5Unorm; + case Gfx::SE_FORMAT_R4G4B4A4_UNORM_PACK16: + return MTL::PixelFormatABGR4Unorm; + case Gfx::SE_FORMAT_B5G5R5A1_UNORM_PACK16: + return MTL::PixelFormatBGR5A1Unorm; + case Gfx::SE_FORMAT_R32_UINT: + return MTL::PixelFormatR32Uint; + case Gfx::SE_FORMAT_R32_SINT: + return MTL::PixelFormatR32Sint; + case Gfx::SE_FORMAT_R32_SFLOAT: + return MTL::PixelFormatR32Float; + case Gfx::SE_FORMAT_R16G16_UNORM: + return MTL::PixelFormatRG16Unorm; + case Gfx::SE_FORMAT_R16G16_SNORM: + return MTL::PixelFormatRG16Snorm; + case Gfx::SE_FORMAT_R16G16_UINT: + return MTL::PixelFormatRG16Uint; + case Gfx::SE_FORMAT_R16G16_SINT: + return MTL::PixelFormatRG16Sint; + case Gfx::SE_FORMAT_R16G16_SFLOAT: + return MTL::PixelFormatRG16Float; + case Gfx::SE_FORMAT_R8G8B8A8_UNORM: + return MTL::PixelFormatRGBA8Unorm; + case Gfx::SE_FORMAT_R8G8B8A8_SRGB: + return MTL::PixelFormatRGBA8Unorm_sRGB; + case Gfx::SE_FORMAT_R8G8B8A8_SNORM: + return MTL::PixelFormatRGBA8Snorm; + case Gfx::SE_FORMAT_R8G8B8A8_UINT: + return MTL::PixelFormatRGBA8Uint; + case Gfx::SE_FORMAT_R8G8B8A8_SINT: + return MTL::PixelFormatRGBA8Sint; + case Gfx::SE_FORMAT_B8G8R8A8_UNORM: + return MTL::PixelFormatBGRA8Unorm; + case Gfx::SE_FORMAT_B8G8R8A8_SRGB: + return MTL::PixelFormatBGRA8Unorm_sRGB; + case Gfx::SE_FORMAT_R32G32_UINT: + return MTL::PixelFormatRG32Uint; + case Gfx::SE_FORMAT_R32G32_SINT: + return MTL::PixelFormatRG32Sint; + case Gfx::SE_FORMAT_R32G32_SFLOAT: + return MTL::PixelFormatRG32Float; + case Gfx::SE_FORMAT_R16G16B16A16_UNORM: + return MTL::PixelFormatRGBA16Unorm; + case Gfx::SE_FORMAT_R16G16B16A16_SNORM: + return MTL::PixelFormatRGBA16Snorm; + case Gfx::SE_FORMAT_R16G16B16A16_UINT: + return MTL::PixelFormatRGBA16Uint; + case Gfx::SE_FORMAT_R16G16B16A16_SINT: + return MTL::PixelFormatRGBA16Sint; + case Gfx::SE_FORMAT_R16G16B16A16_SFLOAT: + return MTL::PixelFormatRGBA16Float; + case Gfx::SE_FORMAT_R32G32B32A32_UINT: + return MTL::PixelFormatRGBA32Uint; + case Gfx::SE_FORMAT_R32G32B32A32_SINT: + return MTL::PixelFormatRGBA32Sint; + case Gfx::SE_FORMAT_R32G32B32A32_SFLOAT: + return MTL::PixelFormatRGBA32Float; + case Gfx::SE_FORMAT_BC1_RGBA_UNORM_BLOCK: + return MTL::PixelFormatBC1_RGBA; + case Gfx::SE_FORMAT_BC1_RGBA_SRGB_BLOCK: + return MTL::PixelFormatBC1_RGBA_sRGB; + case Gfx::SE_FORMAT_BC2_UNORM_BLOCK: + return MTL::PixelFormatBC2_RGBA; + case Gfx::SE_FORMAT_BC2_SRGB_BLOCK: + return MTL::PixelFormatBC2_RGBA_sRGB; + case Gfx::SE_FORMAT_BC3_UNORM_BLOCK: + return MTL::PixelFormatBC3_RGBA; + case Gfx::SE_FORMAT_BC3_SRGB_BLOCK: + return MTL::PixelFormatBC3_RGBA_sRGB; + case Gfx::SE_FORMAT_BC4_UNORM_BLOCK: + return MTL::PixelFormatBC4_RUnorm; + case Gfx::SE_FORMAT_BC4_SNORM_BLOCK: + return MTL::PixelFormatBC4_RSnorm; + case Gfx::SE_FORMAT_BC5_UNORM_BLOCK: + return MTL::PixelFormatBC5_RGUnorm; + case Gfx::SE_FORMAT_BC5_SNORM_BLOCK: + return MTL::PixelFormatBC5_RGSnorm; + case Gfx::SE_FORMAT_BC6H_SFLOAT_BLOCK: + return MTL::PixelFormatBC6H_RGBFloat; + case Gfx::SE_FORMAT_BC6H_UFLOAT_BLOCK: + return MTL::PixelFormatBC6H_RGBUfloat; + case Gfx::SE_FORMAT_BC7_UNORM_BLOCK: + return MTL::PixelFormatBC7_RGBAUnorm; + case Gfx::SE_FORMAT_BC7_SRGB_BLOCK: + return MTL::PixelFormatBC7_RGBAUnorm_sRGB; + case Gfx::SE_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG: + return MTL::PixelFormatPVRTC_RGB_2BPP; + case Gfx::SE_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG: + return MTL::PixelFormatPVRTC_RGB_2BPP_sRGB; + case Gfx::SE_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG: + return MTL::PixelFormatPVRTC_RGB_4BPP; + case Gfx::SE_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG: + return MTL::PixelFormatPVRTC_RGB_4BPP_sRGB; + case Gfx::SE_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG: + return MTL::PixelFormatPVRTC_RGBA_2BPP; + case Gfx::SE_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG: + return MTL::PixelFormatPVRTC_RGBA_2BPP_sRGB; + case Gfx::SE_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG: + return MTL::PixelFormatPVRTC_RGBA_4BPP; + case Gfx::SE_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG: + return MTL::PixelFormatPVRTC_RGBA_4BPP_sRGB; + case Gfx::SE_FORMAT_EAC_R11_UNORM_BLOCK: + return MTL::PixelFormatEAC_R11Unorm; + case Gfx::SE_FORMAT_EAC_R11_SNORM_BLOCK: + return MTL::PixelFormatEAC_R11Snorm; + case Gfx::SE_FORMAT_EAC_R11G11_UNORM_BLOCK: + return MTL::PixelFormatEAC_RG11Unorm; + case Gfx::SE_FORMAT_EAC_R11G11_SNORM_BLOCK: + return MTL::PixelFormatEAC_RG11Snorm; + case Gfx::SE_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: + return MTL::PixelFormatETC2_RGB8; + case Gfx::SE_FORMAT_ETC2_R8G8B8_SRGB_BLOCK: + return MTL::PixelFormatETC2_RGB8_sRGB; + case Gfx::SE_FORMAT_ASTC_4x4_SRGB_BLOCK: + return MTL::PixelFormatASTC_4x4_sRGB; + case Gfx::SE_FORMAT_ASTC_5x4_SRGB_BLOCK: + return MTL::PixelFormatASTC_5x4_sRGB; + case Gfx::SE_FORMAT_ASTC_5x5_SRGB_BLOCK: + return MTL::PixelFormatASTC_5x5_sRGB; + case Gfx::SE_FORMAT_ASTC_6x5_SRGB_BLOCK: + return MTL::PixelFormatASTC_6x5_sRGB; + case Gfx::SE_FORMAT_ASTC_6x6_SRGB_BLOCK: + return MTL::PixelFormatASTC_6x6_sRGB; + case Gfx::SE_FORMAT_ASTC_8x5_SRGB_BLOCK: + return MTL::PixelFormatASTC_8x5_sRGB; + case Gfx::SE_FORMAT_ASTC_8x6_SRGB_BLOCK: + return MTL::PixelFormatASTC_8x6_sRGB; + case Gfx::SE_FORMAT_ASTC_8x8_SRGB_BLOCK: + return MTL::PixelFormatASTC_8x8_sRGB; + case Gfx::SE_FORMAT_ASTC_10x5_SRGB_BLOCK: + return MTL::PixelFormatASTC_10x5_sRGB; + case Gfx::SE_FORMAT_ASTC_10x6_SRGB_BLOCK: + return MTL::PixelFormatASTC_10x6_sRGB; + case Gfx::SE_FORMAT_ASTC_10x8_SRGB_BLOCK: + return MTL::PixelFormatASTC_10x8_sRGB; + case Gfx::SE_FORMAT_ASTC_10x10_SRGB_BLOCK: + return MTL::PixelFormatASTC_10x10_sRGB; + case Gfx::SE_FORMAT_ASTC_12x10_SRGB_BLOCK: + return MTL::PixelFormatASTC_12x10_sRGB; + case Gfx::SE_FORMAT_ASTC_12x12_SRGB_BLOCK: + return MTL::PixelFormatASTC_12x12_sRGB; + case Gfx::SE_FORMAT_ASTC_4x4_UNORM_BLOCK: + return MTL::PixelFormatASTC_4x4_LDR; + case Gfx::SE_FORMAT_ASTC_5x4_UNORM_BLOCK: + return MTL::PixelFormatASTC_5x4_LDR; + case Gfx::SE_FORMAT_ASTC_5x5_UNORM_BLOCK: + return MTL::PixelFormatASTC_5x5_LDR; + case Gfx::SE_FORMAT_ASTC_6x5_UNORM_BLOCK: + return MTL::PixelFormatASTC_6x5_LDR; + case Gfx::SE_FORMAT_ASTC_6x6_UNORM_BLOCK: + return MTL::PixelFormatASTC_6x6_LDR; + case Gfx::SE_FORMAT_ASTC_8x5_UNORM_BLOCK: + return MTL::PixelFormatASTC_8x5_LDR; + case Gfx::SE_FORMAT_ASTC_8x6_UNORM_BLOCK: + return MTL::PixelFormatASTC_8x6_LDR; + case Gfx::SE_FORMAT_ASTC_8x8_UNORM_BLOCK: + return MTL::PixelFormatASTC_8x8_LDR; + case Gfx::SE_FORMAT_ASTC_10x5_UNORM_BLOCK: + return MTL::PixelFormatASTC_10x5_LDR; + case Gfx::SE_FORMAT_ASTC_10x6_UNORM_BLOCK: + return MTL::PixelFormatASTC_10x6_LDR; + case Gfx::SE_FORMAT_ASTC_10x8_UNORM_BLOCK: + return MTL::PixelFormatASTC_10x8_LDR; + case Gfx::SE_FORMAT_ASTC_10x10_UNORM_BLOCK: + return MTL::PixelFormatASTC_10x10_LDR; + case Gfx::SE_FORMAT_ASTC_12x10_UNORM_BLOCK: + return MTL::PixelFormatASTC_12x10_LDR; + case Gfx::SE_FORMAT_ASTC_12x12_UNORM_BLOCK: + return MTL::PixelFormatASTC_12x12_LDR; + case Gfx::SE_FORMAT_ASTC_4x4_SFLOAT_BLOCK: + return MTL::PixelFormatASTC_4x4_HDR; + case Gfx::SE_FORMAT_ASTC_5x4_SFLOAT_BLOCK: + return MTL::PixelFormatASTC_5x4_HDR; + case Gfx::SE_FORMAT_ASTC_5x5_SFLOAT_BLOCK: + return MTL::PixelFormatASTC_5x5_HDR; + case Gfx::SE_FORMAT_ASTC_6x5_SFLOAT_BLOCK: + return MTL::PixelFormatASTC_6x5_HDR; + case Gfx::SE_FORMAT_ASTC_6x6_SFLOAT_BLOCK: + return MTL::PixelFormatASTC_6x6_HDR; + case Gfx::SE_FORMAT_ASTC_8x5_SFLOAT_BLOCK: + return MTL::PixelFormatASTC_8x5_HDR; + case Gfx::SE_FORMAT_ASTC_8x6_SFLOAT_BLOCK: + return MTL::PixelFormatASTC_8x6_HDR; + case Gfx::SE_FORMAT_ASTC_8x8_SFLOAT_BLOCK: + return MTL::PixelFormatASTC_8x8_HDR; + case Gfx::SE_FORMAT_ASTC_10x5_SFLOAT_BLOCK: + return MTL::PixelFormatASTC_10x5_HDR; + case Gfx::SE_FORMAT_ASTC_10x6_SFLOAT_BLOCK: + return MTL::PixelFormatASTC_10x6_HDR; + case Gfx::SE_FORMAT_ASTC_10x8_SFLOAT_BLOCK: + return MTL::PixelFormatASTC_10x8_HDR; + case Gfx::SE_FORMAT_ASTC_10x10_SFLOAT_BLOCK: + return MTL::PixelFormatASTC_10x10_HDR; + case Gfx::SE_FORMAT_ASTC_12x10_SFLOAT_BLOCK: + return MTL::PixelFormatASTC_12x10_HDR; + case Gfx::SE_FORMAT_ASTC_12x12_SFLOAT_BLOCK: + return MTL::PixelFormatASTC_12x12_HDR; + case Gfx::SE_FORMAT_G8B8G8R8_422_UNORM: + return MTL::PixelFormatGBGR422; + case Gfx::SE_FORMAT_B8G8R8G8_422_UNORM: + return MTL::PixelFormatBGRG422; + case Gfx::SE_FORMAT_D16_UNORM: + return MTL::PixelFormatDepth16Unorm; + case Gfx::SE_FORMAT_D32_SFLOAT: + return MTL::PixelFormatDepth32Float; + case Gfx::SE_FORMAT_S8_UINT: + return MTL::PixelFormatStencil8; + case Gfx::SE_FORMAT_D24_UNORM_S8_UINT: + return MTL::PixelFormatDepth24Unorm_Stencil8; + case Gfx::SE_FORMAT_D32_SFLOAT_S8_UINT: + return MTL::PixelFormatDepth32Float_Stencil8; + default: + throw std::logic_error("Not implemented"); + } } Gfx::SeFormat Seele::Metal::cast(MTL::PixelFormat format) { - switch (format) { - case MTL::PixelFormatInvalid: - return Gfx::SE_FORMAT_UNDEFINED; - case MTL::PixelFormatA8Unorm: - return Gfx::SE_FORMAT_UNDEFINED; - case MTL::PixelFormatR8Unorm: - return Gfx::SE_FORMAT_R8_UNORM; - case MTL::PixelFormatR8Unorm_sRGB: - return Gfx::SE_FORMAT_R8_SRGB; - case MTL::PixelFormatR8Snorm: - return Gfx::SE_FORMAT_R8_SNORM; - case MTL::PixelFormatR8Uint: - return Gfx::SE_FORMAT_R8_UINT; - case MTL::PixelFormatR8Sint: - return Gfx::SE_FORMAT_R8_SINT; - case MTL::PixelFormatR16Unorm: - return Gfx::SE_FORMAT_R16_UNORM; - case MTL::PixelFormatR16Snorm: - return Gfx::SE_FORMAT_R16_SNORM; - case MTL::PixelFormatR16Uint: - return Gfx::SE_FORMAT_R16_UINT; - case MTL::PixelFormatR16Sint: - return Gfx::SE_FORMAT_R16_SINT; - case MTL::PixelFormatR16Float: - return Gfx::SE_FORMAT_R16_SFLOAT; - case MTL::PixelFormatRG8Unorm: - return Gfx::SE_FORMAT_R8G8_UNORM; - case MTL::PixelFormatRG8Unorm_sRGB: - return Gfx::SE_FORMAT_R8G8_SRGB; - case MTL::PixelFormatRG8Snorm: - return Gfx::SE_FORMAT_R8G8_SNORM; - case MTL::PixelFormatRG8Uint: - return Gfx::SE_FORMAT_R8G8_UINT; - case MTL::PixelFormatRG8Sint: - return Gfx::SE_FORMAT_R8G8_SINT; - case MTL::PixelFormatB5G6R5Unorm: - return Gfx::SE_FORMAT_B5G6R5_UNORM_PACK16; - case MTL::PixelFormatA1BGR5Unorm: - return Gfx::SE_FORMAT_UNDEFINED; - case MTL::PixelFormatABGR4Unorm: - return Gfx::SE_FORMAT_R4G4B4A4_UNORM_PACK16; - case MTL::PixelFormatBGR5A1Unorm: - return Gfx::SE_FORMAT_B5G5R5A1_UNORM_PACK16; - case MTL::PixelFormatR32Uint: - return Gfx::SE_FORMAT_R32_UINT; - case MTL::PixelFormatR32Sint: - return Gfx::SE_FORMAT_R32_SINT; - case MTL::PixelFormatR32Float: - return Gfx::SE_FORMAT_R32_SFLOAT; - case MTL::PixelFormatRG16Unorm: - return Gfx::SE_FORMAT_R16G16_UNORM; - case MTL::PixelFormatRG16Snorm: - return Gfx::SE_FORMAT_R16G16_SNORM; - case MTL::PixelFormatRG16Uint: - return Gfx::SE_FORMAT_R16G16_UINT; - case MTL::PixelFormatRG16Sint: - return Gfx::SE_FORMAT_R16G16_SINT; - case MTL::PixelFormatRG16Float: - return Gfx::SE_FORMAT_R16G16_SFLOAT; - case MTL::PixelFormatRGBA8Unorm: - return Gfx::SE_FORMAT_R8G8B8A8_UNORM; - case MTL::PixelFormatRGBA8Unorm_sRGB: - return Gfx::SE_FORMAT_R8G8B8A8_SRGB; - case MTL::PixelFormatRGBA8Snorm: - return Gfx::SE_FORMAT_R8G8B8A8_SNORM; - case MTL::PixelFormatRGBA8Uint: - return Gfx::SE_FORMAT_R8G8B8A8_UINT; - case MTL::PixelFormatRGBA8Sint: - return Gfx::SE_FORMAT_R8G8B8A8_SINT; - case MTL::PixelFormatBGRA8Unorm: - return Gfx::SE_FORMAT_B8G8R8A8_UNORM; - case MTL::PixelFormatBGRA8Unorm_sRGB: - return Gfx::SE_FORMAT_B8G8R8A8_SRGB; - case MTL::PixelFormatRGB10A2Unorm: - return Gfx::SE_FORMAT_UNDEFINED; - case MTL::PixelFormatRGB10A2Uint: - return Gfx::SE_FORMAT_UNDEFINED; - case MTL::PixelFormatRG11B10Float: - return Gfx::SE_FORMAT_UNDEFINED; - case MTL::PixelFormatRGB9E5Float: - return Gfx::SE_FORMAT_UNDEFINED; - case MTL::PixelFormatBGR10A2Unorm: - return Gfx::SE_FORMAT_UNDEFINED; - case MTL::PixelFormatBGR10_XR: - return Gfx::SE_FORMAT_UNDEFINED; - case MTL::PixelFormatBGR10_XR_sRGB: - return Gfx::SE_FORMAT_UNDEFINED; - case MTL::PixelFormatRG32Uint: - return Gfx::SE_FORMAT_R32G32_UINT; - case MTL::PixelFormatRG32Sint: - return Gfx::SE_FORMAT_R32G32_SINT; - case MTL::PixelFormatRG32Float: - return Gfx::SE_FORMAT_R32G32_SFLOAT; - case MTL::PixelFormatRGBA16Unorm: - return Gfx::SE_FORMAT_R16G16B16A16_UNORM; - case MTL::PixelFormatRGBA16Snorm: - return Gfx::SE_FORMAT_R16G16B16A16_SNORM; - case MTL::PixelFormatRGBA16Uint: - return Gfx::SE_FORMAT_R16G16B16A16_UINT; - case MTL::PixelFormatRGBA16Sint: - return Gfx::SE_FORMAT_R16G16B16A16_SINT; - case MTL::PixelFormatRGBA16Float: - return Gfx::SE_FORMAT_R16G16B16A16_SFLOAT; - case MTL::PixelFormatBGRA10_XR: - return Gfx::SE_FORMAT_UNDEFINED; - case MTL::PixelFormatBGRA10_XR_sRGB: - return Gfx::SE_FORMAT_UNDEFINED; - case MTL::PixelFormatRGBA32Uint: - return Gfx::SE_FORMAT_R32G32B32A32_UINT; - case MTL::PixelFormatRGBA32Sint: - return Gfx::SE_FORMAT_R32G32B32A32_SINT; - case MTL::PixelFormatRGBA32Float: - return Gfx::SE_FORMAT_R32G32B32A32_SFLOAT; - case MTL::PixelFormatBC1_RGBA: - return Gfx::SE_FORMAT_BC1_RGBA_UNORM_BLOCK; - case MTL::PixelFormatBC1_RGBA_sRGB: - return Gfx::SE_FORMAT_BC1_RGBA_SRGB_BLOCK; - case MTL::PixelFormatBC2_RGBA: - return Gfx::SE_FORMAT_BC2_UNORM_BLOCK; - case MTL::PixelFormatBC2_RGBA_sRGB: - return Gfx::SE_FORMAT_BC2_SRGB_BLOCK; - case MTL::PixelFormatBC3_RGBA: - return Gfx::SE_FORMAT_BC3_UNORM_BLOCK; - case MTL::PixelFormatBC3_RGBA_sRGB: - return Gfx::SE_FORMAT_BC3_SRGB_BLOCK; - case MTL::PixelFormatBC4_RUnorm: - return Gfx::SE_FORMAT_BC4_UNORM_BLOCK; - case MTL::PixelFormatBC4_RSnorm: - return Gfx::SE_FORMAT_BC4_SNORM_BLOCK; - case MTL::PixelFormatBC5_RGUnorm: - return Gfx::SE_FORMAT_BC4_SNORM_BLOCK; - case MTL::PixelFormatBC5_RGSnorm: - return Gfx::SE_FORMAT_BC5_SNORM_BLOCK; - case MTL::PixelFormatBC6H_RGBFloat: - return Gfx::SE_FORMAT_BC6H_SFLOAT_BLOCK; - case MTL::PixelFormatBC6H_RGBUfloat: - return Gfx::SE_FORMAT_BC6H_UFLOAT_BLOCK; - case MTL::PixelFormatBC7_RGBAUnorm: - return Gfx::SE_FORMAT_BC7_UNORM_BLOCK; - case MTL::PixelFormatBC7_RGBAUnorm_sRGB: - return Gfx::SE_FORMAT_BC7_SRGB_BLOCK; - case MTL::PixelFormatPVRTC_RGB_2BPP: - return Gfx::SE_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG; - case MTL::PixelFormatPVRTC_RGB_2BPP_sRGB: - return Gfx::SE_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG; - case MTL::PixelFormatPVRTC_RGB_4BPP: - return Gfx::SE_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG; - case MTL::PixelFormatPVRTC_RGB_4BPP_sRGB: - return Gfx::SE_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG; - case MTL::PixelFormatPVRTC_RGBA_2BPP: - return Gfx::SE_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG; - case MTL::PixelFormatPVRTC_RGBA_2BPP_sRGB: - return Gfx::SE_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG; - case MTL::PixelFormatPVRTC_RGBA_4BPP: - return Gfx::SE_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG; - case MTL::PixelFormatPVRTC_RGBA_4BPP_sRGB: - return Gfx::SE_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG; - case MTL::PixelFormatEAC_R11Unorm: - return Gfx::SE_FORMAT_EAC_R11_UNORM_BLOCK; - case MTL::PixelFormatEAC_R11Snorm: - return Gfx::SE_FORMAT_EAC_R11_SNORM_BLOCK; - case MTL::PixelFormatEAC_RG11Unorm: - return Gfx::SE_FORMAT_EAC_R11G11_UNORM_BLOCK; - case MTL::PixelFormatEAC_RG11Snorm: - return Gfx::SE_FORMAT_EAC_R11G11_SNORM_BLOCK; - case MTL::PixelFormatEAC_RGBA8: - return Gfx::SE_FORMAT_UNDEFINED; - case MTL::PixelFormatEAC_RGBA8_sRGB: - return Gfx::SE_FORMAT_UNDEFINED; - case MTL::PixelFormatETC2_RGB8: - return Gfx::SE_FORMAT_ETC2_R8G8B8_UNORM_BLOCK; - case MTL::PixelFormatETC2_RGB8_sRGB: - return Gfx::SE_FORMAT_ETC2_R8G8B8_SRGB_BLOCK; - case MTL::PixelFormatETC2_RGB8A1: - return Gfx::SE_FORMAT_UNDEFINED; - case MTL::PixelFormatETC2_RGB8A1_sRGB: - return Gfx::SE_FORMAT_UNDEFINED; - case MTL::PixelFormatASTC_4x4_sRGB: - return Gfx::SE_FORMAT_ASTC_4x4_SRGB_BLOCK; - case MTL::PixelFormatASTC_5x4_sRGB: - return Gfx::SE_FORMAT_ASTC_5x4_SRGB_BLOCK; - case MTL::PixelFormatASTC_5x5_sRGB: - return Gfx::SE_FORMAT_ASTC_5x5_SRGB_BLOCK; - case MTL::PixelFormatASTC_6x5_sRGB: - return Gfx::SE_FORMAT_ASTC_6x5_SRGB_BLOCK; - case MTL::PixelFormatASTC_6x6_sRGB: - return Gfx::SE_FORMAT_ASTC_6x6_SRGB_BLOCK; - case MTL::PixelFormatASTC_8x5_sRGB: - return Gfx::SE_FORMAT_ASTC_8x5_SRGB_BLOCK; - case MTL::PixelFormatASTC_8x6_sRGB: - return Gfx::SE_FORMAT_ASTC_8x6_SRGB_BLOCK; - case MTL::PixelFormatASTC_8x8_sRGB: - return Gfx::SE_FORMAT_ASTC_8x8_SRGB_BLOCK; - case MTL::PixelFormatASTC_10x5_sRGB: - return Gfx::SE_FORMAT_ASTC_10x5_SRGB_BLOCK; - case MTL::PixelFormatASTC_10x6_sRGB: - return Gfx::SE_FORMAT_ASTC_10x6_SRGB_BLOCK; - case MTL::PixelFormatASTC_10x8_sRGB: - return Gfx::SE_FORMAT_ASTC_10x8_SRGB_BLOCK; - case MTL::PixelFormatASTC_10x10_sRGB: - return Gfx::SE_FORMAT_ASTC_10x10_SRGB_BLOCK; - case MTL::PixelFormatASTC_12x10_sRGB: - return Gfx::SE_FORMAT_ASTC_12x10_SRGB_BLOCK; - case MTL::PixelFormatASTC_12x12_sRGB: - return Gfx::SE_FORMAT_ASTC_12x12_SRGB_BLOCK; - case MTL::PixelFormatASTC_4x4_LDR: - return Gfx::SE_FORMAT_ASTC_4x4_UNORM_BLOCK; - case MTL::PixelFormatASTC_5x4_LDR: - return Gfx::SE_FORMAT_ASTC_5x4_UNORM_BLOCK; - case MTL::PixelFormatASTC_5x5_LDR: - return Gfx::SE_FORMAT_ASTC_5x5_UNORM_BLOCK; - case MTL::PixelFormatASTC_6x5_LDR: - return Gfx::SE_FORMAT_ASTC_6x5_UNORM_BLOCK; - case MTL::PixelFormatASTC_6x6_LDR: - return Gfx::SE_FORMAT_ASTC_6x6_UNORM_BLOCK; - case MTL::PixelFormatASTC_8x5_LDR: - return Gfx::SE_FORMAT_ASTC_8x5_UNORM_BLOCK; - case MTL::PixelFormatASTC_8x6_LDR: - return Gfx::SE_FORMAT_ASTC_8x6_UNORM_BLOCK; - case MTL::PixelFormatASTC_8x8_LDR: - return Gfx::SE_FORMAT_ASTC_8x8_UNORM_BLOCK; - case MTL::PixelFormatASTC_10x5_LDR: - return Gfx::SE_FORMAT_ASTC_10x5_UNORM_BLOCK; - case MTL::PixelFormatASTC_10x6_LDR: - return Gfx::SE_FORMAT_ASTC_10x6_UNORM_BLOCK; - case MTL::PixelFormatASTC_10x8_LDR: - return Gfx::SE_FORMAT_ASTC_10x8_UNORM_BLOCK; - case MTL::PixelFormatASTC_10x10_LDR: - return Gfx::SE_FORMAT_ASTC_10x10_UNORM_BLOCK; - case MTL::PixelFormatASTC_12x10_LDR: - return Gfx::SE_FORMAT_ASTC_12x10_UNORM_BLOCK; - case MTL::PixelFormatASTC_12x12_LDR: - return Gfx::SE_FORMAT_ASTC_12x12_UNORM_BLOCK; - case MTL::PixelFormatASTC_4x4_HDR: - return Gfx::SE_FORMAT_ASTC_4x4_SFLOAT_BLOCK; - case MTL::PixelFormatASTC_5x4_HDR: - return Gfx::SE_FORMAT_ASTC_5x4_SFLOAT_BLOCK; - case MTL::PixelFormatASTC_5x5_HDR: - return Gfx::SE_FORMAT_ASTC_5x5_SFLOAT_BLOCK; - case MTL::PixelFormatASTC_6x5_HDR: - return Gfx::SE_FORMAT_ASTC_6x5_SFLOAT_BLOCK; - case MTL::PixelFormatASTC_6x6_HDR: - return Gfx::SE_FORMAT_ASTC_6x6_SFLOAT_BLOCK; - case MTL::PixelFormatASTC_8x5_HDR: - return Gfx::SE_FORMAT_ASTC_8x5_SFLOAT_BLOCK; - case MTL::PixelFormatASTC_8x6_HDR: - return Gfx::SE_FORMAT_ASTC_8x6_SFLOAT_BLOCK; - case MTL::PixelFormatASTC_8x8_HDR: - return Gfx::SE_FORMAT_ASTC_8x8_SFLOAT_BLOCK; - case MTL::PixelFormatASTC_10x5_HDR: - return Gfx::SE_FORMAT_ASTC_10x5_SFLOAT_BLOCK; - case MTL::PixelFormatASTC_10x6_HDR: - return Gfx::SE_FORMAT_ASTC_10x6_SFLOAT_BLOCK; - case MTL::PixelFormatASTC_10x8_HDR: - return Gfx::SE_FORMAT_ASTC_10x8_SFLOAT_BLOCK; - case MTL::PixelFormatASTC_10x10_HDR: - return Gfx::SE_FORMAT_ASTC_10x10_SFLOAT_BLOCK; - case MTL::PixelFormatASTC_12x10_HDR: - return Gfx::SE_FORMAT_ASTC_12x10_SFLOAT_BLOCK; - case MTL::PixelFormatASTC_12x12_HDR: - return Gfx::SE_FORMAT_ASTC_12x12_SFLOAT_BLOCK; - case MTL::PixelFormatGBGR422: - return Gfx::SE_FORMAT_G8B8G8R8_422_UNORM; - case MTL::PixelFormatBGRG422: - return Gfx::SE_FORMAT_B8G8R8G8_422_UNORM; - case MTL::PixelFormatDepth16Unorm: - return Gfx::SE_FORMAT_D16_UNORM; - case MTL::PixelFormatDepth32Float: - return Gfx::SE_FORMAT_D32_SFLOAT; - case MTL::PixelFormatStencil8: - return Gfx::SE_FORMAT_S8_UINT; - case MTL::PixelFormatDepth24Unorm_Stencil8: - return Gfx::SE_FORMAT_D24_UNORM_S8_UINT; - case MTL::PixelFormatDepth32Float_Stencil8: - return Gfx::SE_FORMAT_D32_SFLOAT_S8_UINT; - case MTL::PixelFormatX32_Stencil8: - return Gfx::SE_FORMAT_UNDEFINED; - case MTL::PixelFormatX24_Stencil8: - return Gfx::SE_FORMAT_UNDEFINED; - default: - throw std::logic_error("Not implemented"); - } + switch (format) { + case MTL::PixelFormatInvalid: + return Gfx::SE_FORMAT_UNDEFINED; + case MTL::PixelFormatA8Unorm: + return Gfx::SE_FORMAT_UNDEFINED; + case MTL::PixelFormatR8Unorm: + return Gfx::SE_FORMAT_R8_UNORM; + case MTL::PixelFormatR8Unorm_sRGB: + return Gfx::SE_FORMAT_R8_SRGB; + case MTL::PixelFormatR8Snorm: + return Gfx::SE_FORMAT_R8_SNORM; + case MTL::PixelFormatR8Uint: + return Gfx::SE_FORMAT_R8_UINT; + case MTL::PixelFormatR8Sint: + return Gfx::SE_FORMAT_R8_SINT; + case MTL::PixelFormatR16Unorm: + return Gfx::SE_FORMAT_R16_UNORM; + case MTL::PixelFormatR16Snorm: + return Gfx::SE_FORMAT_R16_SNORM; + case MTL::PixelFormatR16Uint: + return Gfx::SE_FORMAT_R16_UINT; + case MTL::PixelFormatR16Sint: + return Gfx::SE_FORMAT_R16_SINT; + case MTL::PixelFormatR16Float: + return Gfx::SE_FORMAT_R16_SFLOAT; + case MTL::PixelFormatRG8Unorm: + return Gfx::SE_FORMAT_R8G8_UNORM; + case MTL::PixelFormatRG8Unorm_sRGB: + return Gfx::SE_FORMAT_R8G8_SRGB; + case MTL::PixelFormatRG8Snorm: + return Gfx::SE_FORMAT_R8G8_SNORM; + case MTL::PixelFormatRG8Uint: + return Gfx::SE_FORMAT_R8G8_UINT; + case MTL::PixelFormatRG8Sint: + return Gfx::SE_FORMAT_R8G8_SINT; + case MTL::PixelFormatB5G6R5Unorm: + return Gfx::SE_FORMAT_B5G6R5_UNORM_PACK16; + case MTL::PixelFormatA1BGR5Unorm: + return Gfx::SE_FORMAT_UNDEFINED; + case MTL::PixelFormatABGR4Unorm: + return Gfx::SE_FORMAT_R4G4B4A4_UNORM_PACK16; + case MTL::PixelFormatBGR5A1Unorm: + return Gfx::SE_FORMAT_B5G5R5A1_UNORM_PACK16; + case MTL::PixelFormatR32Uint: + return Gfx::SE_FORMAT_R32_UINT; + case MTL::PixelFormatR32Sint: + return Gfx::SE_FORMAT_R32_SINT; + case MTL::PixelFormatR32Float: + return Gfx::SE_FORMAT_R32_SFLOAT; + case MTL::PixelFormatRG16Unorm: + return Gfx::SE_FORMAT_R16G16_UNORM; + case MTL::PixelFormatRG16Snorm: + return Gfx::SE_FORMAT_R16G16_SNORM; + case MTL::PixelFormatRG16Uint: + return Gfx::SE_FORMAT_R16G16_UINT; + case MTL::PixelFormatRG16Sint: + return Gfx::SE_FORMAT_R16G16_SINT; + case MTL::PixelFormatRG16Float: + return Gfx::SE_FORMAT_R16G16_SFLOAT; + case MTL::PixelFormatRGBA8Unorm: + return Gfx::SE_FORMAT_R8G8B8A8_UNORM; + case MTL::PixelFormatRGBA8Unorm_sRGB: + return Gfx::SE_FORMAT_R8G8B8A8_SRGB; + case MTL::PixelFormatRGBA8Snorm: + return Gfx::SE_FORMAT_R8G8B8A8_SNORM; + case MTL::PixelFormatRGBA8Uint: + return Gfx::SE_FORMAT_R8G8B8A8_UINT; + case MTL::PixelFormatRGBA8Sint: + return Gfx::SE_FORMAT_R8G8B8A8_SINT; + case MTL::PixelFormatBGRA8Unorm: + return Gfx::SE_FORMAT_B8G8R8A8_UNORM; + case MTL::PixelFormatBGRA8Unorm_sRGB: + return Gfx::SE_FORMAT_B8G8R8A8_SRGB; + case MTL::PixelFormatRGB10A2Unorm: + return Gfx::SE_FORMAT_UNDEFINED; + case MTL::PixelFormatRGB10A2Uint: + return Gfx::SE_FORMAT_UNDEFINED; + case MTL::PixelFormatRG11B10Float: + return Gfx::SE_FORMAT_UNDEFINED; + case MTL::PixelFormatRGB9E5Float: + return Gfx::SE_FORMAT_UNDEFINED; + case MTL::PixelFormatBGR10A2Unorm: + return Gfx::SE_FORMAT_UNDEFINED; + case MTL::PixelFormatBGR10_XR: + return Gfx::SE_FORMAT_UNDEFINED; + case MTL::PixelFormatBGR10_XR_sRGB: + return Gfx::SE_FORMAT_UNDEFINED; + case MTL::PixelFormatRG32Uint: + return Gfx::SE_FORMAT_R32G32_UINT; + case MTL::PixelFormatRG32Sint: + return Gfx::SE_FORMAT_R32G32_SINT; + case MTL::PixelFormatRG32Float: + return Gfx::SE_FORMAT_R32G32_SFLOAT; + case MTL::PixelFormatRGBA16Unorm: + return Gfx::SE_FORMAT_R16G16B16A16_UNORM; + case MTL::PixelFormatRGBA16Snorm: + return Gfx::SE_FORMAT_R16G16B16A16_SNORM; + case MTL::PixelFormatRGBA16Uint: + return Gfx::SE_FORMAT_R16G16B16A16_UINT; + case MTL::PixelFormatRGBA16Sint: + return Gfx::SE_FORMAT_R16G16B16A16_SINT; + case MTL::PixelFormatRGBA16Float: + return Gfx::SE_FORMAT_R16G16B16A16_SFLOAT; + case MTL::PixelFormatBGRA10_XR: + return Gfx::SE_FORMAT_UNDEFINED; + case MTL::PixelFormatBGRA10_XR_sRGB: + return Gfx::SE_FORMAT_UNDEFINED; + case MTL::PixelFormatRGBA32Uint: + return Gfx::SE_FORMAT_R32G32B32A32_UINT; + case MTL::PixelFormatRGBA32Sint: + return Gfx::SE_FORMAT_R32G32B32A32_SINT; + case MTL::PixelFormatRGBA32Float: + return Gfx::SE_FORMAT_R32G32B32A32_SFLOAT; + case MTL::PixelFormatBC1_RGBA: + return Gfx::SE_FORMAT_BC1_RGBA_UNORM_BLOCK; + case MTL::PixelFormatBC1_RGBA_sRGB: + return Gfx::SE_FORMAT_BC1_RGBA_SRGB_BLOCK; + case MTL::PixelFormatBC2_RGBA: + return Gfx::SE_FORMAT_BC2_UNORM_BLOCK; + case MTL::PixelFormatBC2_RGBA_sRGB: + return Gfx::SE_FORMAT_BC2_SRGB_BLOCK; + case MTL::PixelFormatBC3_RGBA: + return Gfx::SE_FORMAT_BC3_UNORM_BLOCK; + case MTL::PixelFormatBC3_RGBA_sRGB: + return Gfx::SE_FORMAT_BC3_SRGB_BLOCK; + case MTL::PixelFormatBC4_RUnorm: + return Gfx::SE_FORMAT_BC4_UNORM_BLOCK; + case MTL::PixelFormatBC4_RSnorm: + return Gfx::SE_FORMAT_BC4_SNORM_BLOCK; + case MTL::PixelFormatBC5_RGUnorm: + return Gfx::SE_FORMAT_BC4_SNORM_BLOCK; + case MTL::PixelFormatBC5_RGSnorm: + return Gfx::SE_FORMAT_BC5_SNORM_BLOCK; + case MTL::PixelFormatBC6H_RGBFloat: + return Gfx::SE_FORMAT_BC6H_SFLOAT_BLOCK; + case MTL::PixelFormatBC6H_RGBUfloat: + return Gfx::SE_FORMAT_BC6H_UFLOAT_BLOCK; + case MTL::PixelFormatBC7_RGBAUnorm: + return Gfx::SE_FORMAT_BC7_UNORM_BLOCK; + case MTL::PixelFormatBC7_RGBAUnorm_sRGB: + return Gfx::SE_FORMAT_BC7_SRGB_BLOCK; + case MTL::PixelFormatPVRTC_RGB_2BPP: + return Gfx::SE_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG; + case MTL::PixelFormatPVRTC_RGB_2BPP_sRGB: + return Gfx::SE_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG; + case MTL::PixelFormatPVRTC_RGB_4BPP: + return Gfx::SE_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG; + case MTL::PixelFormatPVRTC_RGB_4BPP_sRGB: + return Gfx::SE_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG; + case MTL::PixelFormatPVRTC_RGBA_2BPP: + return Gfx::SE_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG; + case MTL::PixelFormatPVRTC_RGBA_2BPP_sRGB: + return Gfx::SE_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG; + case MTL::PixelFormatPVRTC_RGBA_4BPP: + return Gfx::SE_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG; + case MTL::PixelFormatPVRTC_RGBA_4BPP_sRGB: + return Gfx::SE_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG; + case MTL::PixelFormatEAC_R11Unorm: + return Gfx::SE_FORMAT_EAC_R11_UNORM_BLOCK; + case MTL::PixelFormatEAC_R11Snorm: + return Gfx::SE_FORMAT_EAC_R11_SNORM_BLOCK; + case MTL::PixelFormatEAC_RG11Unorm: + return Gfx::SE_FORMAT_EAC_R11G11_UNORM_BLOCK; + case MTL::PixelFormatEAC_RG11Snorm: + return Gfx::SE_FORMAT_EAC_R11G11_SNORM_BLOCK; + case MTL::PixelFormatEAC_RGBA8: + return Gfx::SE_FORMAT_UNDEFINED; + case MTL::PixelFormatEAC_RGBA8_sRGB: + return Gfx::SE_FORMAT_UNDEFINED; + case MTL::PixelFormatETC2_RGB8: + return Gfx::SE_FORMAT_ETC2_R8G8B8_UNORM_BLOCK; + case MTL::PixelFormatETC2_RGB8_sRGB: + return Gfx::SE_FORMAT_ETC2_R8G8B8_SRGB_BLOCK; + case MTL::PixelFormatETC2_RGB8A1: + return Gfx::SE_FORMAT_UNDEFINED; + case MTL::PixelFormatETC2_RGB8A1_sRGB: + return Gfx::SE_FORMAT_UNDEFINED; + case MTL::PixelFormatASTC_4x4_sRGB: + return Gfx::SE_FORMAT_ASTC_4x4_SRGB_BLOCK; + case MTL::PixelFormatASTC_5x4_sRGB: + return Gfx::SE_FORMAT_ASTC_5x4_SRGB_BLOCK; + case MTL::PixelFormatASTC_5x5_sRGB: + return Gfx::SE_FORMAT_ASTC_5x5_SRGB_BLOCK; + case MTL::PixelFormatASTC_6x5_sRGB: + return Gfx::SE_FORMAT_ASTC_6x5_SRGB_BLOCK; + case MTL::PixelFormatASTC_6x6_sRGB: + return Gfx::SE_FORMAT_ASTC_6x6_SRGB_BLOCK; + case MTL::PixelFormatASTC_8x5_sRGB: + return Gfx::SE_FORMAT_ASTC_8x5_SRGB_BLOCK; + case MTL::PixelFormatASTC_8x6_sRGB: + return Gfx::SE_FORMAT_ASTC_8x6_SRGB_BLOCK; + case MTL::PixelFormatASTC_8x8_sRGB: + return Gfx::SE_FORMAT_ASTC_8x8_SRGB_BLOCK; + case MTL::PixelFormatASTC_10x5_sRGB: + return Gfx::SE_FORMAT_ASTC_10x5_SRGB_BLOCK; + case MTL::PixelFormatASTC_10x6_sRGB: + return Gfx::SE_FORMAT_ASTC_10x6_SRGB_BLOCK; + case MTL::PixelFormatASTC_10x8_sRGB: + return Gfx::SE_FORMAT_ASTC_10x8_SRGB_BLOCK; + case MTL::PixelFormatASTC_10x10_sRGB: + return Gfx::SE_FORMAT_ASTC_10x10_SRGB_BLOCK; + case MTL::PixelFormatASTC_12x10_sRGB: + return Gfx::SE_FORMAT_ASTC_12x10_SRGB_BLOCK; + case MTL::PixelFormatASTC_12x12_sRGB: + return Gfx::SE_FORMAT_ASTC_12x12_SRGB_BLOCK; + case MTL::PixelFormatASTC_4x4_LDR: + return Gfx::SE_FORMAT_ASTC_4x4_UNORM_BLOCK; + case MTL::PixelFormatASTC_5x4_LDR: + return Gfx::SE_FORMAT_ASTC_5x4_UNORM_BLOCK; + case MTL::PixelFormatASTC_5x5_LDR: + return Gfx::SE_FORMAT_ASTC_5x5_UNORM_BLOCK; + case MTL::PixelFormatASTC_6x5_LDR: + return Gfx::SE_FORMAT_ASTC_6x5_UNORM_BLOCK; + case MTL::PixelFormatASTC_6x6_LDR: + return Gfx::SE_FORMAT_ASTC_6x6_UNORM_BLOCK; + case MTL::PixelFormatASTC_8x5_LDR: + return Gfx::SE_FORMAT_ASTC_8x5_UNORM_BLOCK; + case MTL::PixelFormatASTC_8x6_LDR: + return Gfx::SE_FORMAT_ASTC_8x6_UNORM_BLOCK; + case MTL::PixelFormatASTC_8x8_LDR: + return Gfx::SE_FORMAT_ASTC_8x8_UNORM_BLOCK; + case MTL::PixelFormatASTC_10x5_LDR: + return Gfx::SE_FORMAT_ASTC_10x5_UNORM_BLOCK; + case MTL::PixelFormatASTC_10x6_LDR: + return Gfx::SE_FORMAT_ASTC_10x6_UNORM_BLOCK; + case MTL::PixelFormatASTC_10x8_LDR: + return Gfx::SE_FORMAT_ASTC_10x8_UNORM_BLOCK; + case MTL::PixelFormatASTC_10x10_LDR: + return Gfx::SE_FORMAT_ASTC_10x10_UNORM_BLOCK; + case MTL::PixelFormatASTC_12x10_LDR: + return Gfx::SE_FORMAT_ASTC_12x10_UNORM_BLOCK; + case MTL::PixelFormatASTC_12x12_LDR: + return Gfx::SE_FORMAT_ASTC_12x12_UNORM_BLOCK; + case MTL::PixelFormatASTC_4x4_HDR: + return Gfx::SE_FORMAT_ASTC_4x4_SFLOAT_BLOCK; + case MTL::PixelFormatASTC_5x4_HDR: + return Gfx::SE_FORMAT_ASTC_5x4_SFLOAT_BLOCK; + case MTL::PixelFormatASTC_5x5_HDR: + return Gfx::SE_FORMAT_ASTC_5x5_SFLOAT_BLOCK; + case MTL::PixelFormatASTC_6x5_HDR: + return Gfx::SE_FORMAT_ASTC_6x5_SFLOAT_BLOCK; + case MTL::PixelFormatASTC_6x6_HDR: + return Gfx::SE_FORMAT_ASTC_6x6_SFLOAT_BLOCK; + case MTL::PixelFormatASTC_8x5_HDR: + return Gfx::SE_FORMAT_ASTC_8x5_SFLOAT_BLOCK; + case MTL::PixelFormatASTC_8x6_HDR: + return Gfx::SE_FORMAT_ASTC_8x6_SFLOAT_BLOCK; + case MTL::PixelFormatASTC_8x8_HDR: + return Gfx::SE_FORMAT_ASTC_8x8_SFLOAT_BLOCK; + case MTL::PixelFormatASTC_10x5_HDR: + return Gfx::SE_FORMAT_ASTC_10x5_SFLOAT_BLOCK; + case MTL::PixelFormatASTC_10x6_HDR: + return Gfx::SE_FORMAT_ASTC_10x6_SFLOAT_BLOCK; + case MTL::PixelFormatASTC_10x8_HDR: + return Gfx::SE_FORMAT_ASTC_10x8_SFLOAT_BLOCK; + case MTL::PixelFormatASTC_10x10_HDR: + return Gfx::SE_FORMAT_ASTC_10x10_SFLOAT_BLOCK; + case MTL::PixelFormatASTC_12x10_HDR: + return Gfx::SE_FORMAT_ASTC_12x10_SFLOAT_BLOCK; + case MTL::PixelFormatASTC_12x12_HDR: + return Gfx::SE_FORMAT_ASTC_12x12_SFLOAT_BLOCK; + case MTL::PixelFormatGBGR422: + return Gfx::SE_FORMAT_G8B8G8R8_422_UNORM; + case MTL::PixelFormatBGRG422: + return Gfx::SE_FORMAT_B8G8R8G8_422_UNORM; + case MTL::PixelFormatDepth16Unorm: + return Gfx::SE_FORMAT_D16_UNORM; + case MTL::PixelFormatDepth32Float: + return Gfx::SE_FORMAT_D32_SFLOAT; + case MTL::PixelFormatStencil8: + return Gfx::SE_FORMAT_S8_UINT; + case MTL::PixelFormatDepth24Unorm_Stencil8: + return Gfx::SE_FORMAT_D24_UNORM_S8_UINT; + case MTL::PixelFormatDepth32Float_Stencil8: + return Gfx::SE_FORMAT_D32_SFLOAT_S8_UINT; + case MTL::PixelFormatX32_Stencil8: + return Gfx::SE_FORMAT_UNDEFINED; + case MTL::PixelFormatX24_Stencil8: + return Gfx::SE_FORMAT_UNDEFINED; + default: + throw std::logic_error("Not implemented"); + } } MTL::LoadAction Seele::Metal::cast(Gfx::SeAttachmentLoadOp loadOp) { - switch (loadOp) { - case Seele::Gfx::SE_ATTACHMENT_LOAD_OP_LOAD: - return MTL::LoadActionLoad; - case Seele::Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR: - return MTL::LoadActionClear; - case Seele::Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE: - return MTL::LoadActionDontCare; - default: - throw std::logic_error("Not implemented"); - } + switch (loadOp) { + case Seele::Gfx::SE_ATTACHMENT_LOAD_OP_LOAD: + return MTL::LoadActionLoad; + case Seele::Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR: + return MTL::LoadActionClear; + case Seele::Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE: + return MTL::LoadActionDontCare; + default: + throw std::logic_error("Not implemented"); + } } Gfx::SeAttachmentLoadOp Seele::Metal::cast(MTL::LoadAction loadOp) { - switch (loadOp) { - case MTL::LoadActionDontCare: - return Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE; - case MTL::LoadActionLoad: - return Gfx::SE_ATTACHMENT_LOAD_OP_LOAD; - case MTL::LoadActionClear: - return Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR; - default: - throw std::logic_error("Not implemented"); - } + switch (loadOp) { + case MTL::LoadActionDontCare: + return Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE; + case MTL::LoadActionLoad: + return Gfx::SE_ATTACHMENT_LOAD_OP_LOAD; + case MTL::LoadActionClear: + return Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR; + default: + throw std::logic_error("Not implemented"); + } } MTL::StoreAction Seele::Metal::cast(Gfx::SeAttachmentStoreOp storeOp) { - switch (storeOp) { - case Seele::Gfx::SE_ATTACHMENT_STORE_OP_STORE: - return MTL::StoreActionStore; - case Seele::Gfx::SE_ATTACHMENT_STORE_OP_DONT_CARE: - return MTL::StoreActionDontCare; - default: - throw std::logic_error("Not implemented"); - } + switch (storeOp) { + case Seele::Gfx::SE_ATTACHMENT_STORE_OP_STORE: + return MTL::StoreActionStore; + case Seele::Gfx::SE_ATTACHMENT_STORE_OP_DONT_CARE: + return MTL::StoreActionDontCare; + default: + throw std::logic_error("Not implemented"); + } } Gfx::SeAttachmentStoreOp Seele::Metal::cast(MTL::StoreAction storeOp) { - switch (storeOp) { - case MTL::StoreActionDontCare: - return Gfx::SE_ATTACHMENT_STORE_OP_DONT_CARE; - case MTL::StoreActionStore: - return Gfx::SE_ATTACHMENT_STORE_OP_STORE; - default: - throw std::logic_error("Not implemented"); - } + switch (storeOp) { + case MTL::StoreActionDontCare: + return Gfx::SE_ATTACHMENT_STORE_OP_DONT_CARE; + case MTL::StoreActionStore: + return Gfx::SE_ATTACHMENT_STORE_OP_STORE; + default: + throw std::logic_error("Not implemented"); + } } MTL::BindingAccess Seele::Metal::cast(Gfx::SeDescriptorAccessTypeFlags access) { - switch (access) { - case Gfx::SE_DESCRIPTOR_ACCESS_READ_ONLY_BIT: - return MTL::ArgumentAccessReadOnly; - case Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT: - return MTL::ArgumentAccessReadWrite; - case Gfx::SE_DESCRIPTOR_ACCESS_WRITE_ONLY_BIT: - return MTL::ArgumentAccessWriteOnly; - default: - throw std::logic_error("Not implemented"); - } + switch (access) { + case Gfx::SE_DESCRIPTOR_ACCESS_READ_ONLY_BIT: + return MTL::ArgumentAccessReadOnly; + case Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT: + return MTL::ArgumentAccessReadWrite; + case Gfx::SE_DESCRIPTOR_ACCESS_WRITE_ONLY_BIT: + return MTL::ArgumentAccessWriteOnly; + default: + throw std::logic_error("Not implemented"); + } } Gfx::SeDescriptorAccessTypeFlags Seele::Metal::cast(MTL::BindingAccess access) { - switch (access) { - case MTL::ArgumentAccessReadOnly: - return Gfx::SE_DESCRIPTOR_ACCESS_READ_ONLY_BIT; - case MTL::ArgumentAccessReadWrite: - return Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT; - case MTL::ArgumentAccessWriteOnly: - return Gfx::SE_DESCRIPTOR_ACCESS_WRITE_ONLY_BIT; - default: - throw std::logic_error("Not implemented"); - } + switch (access) { + case MTL::ArgumentAccessReadOnly: + return Gfx::SE_DESCRIPTOR_ACCESS_READ_ONLY_BIT; + case MTL::ArgumentAccessReadWrite: + return Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT; + case MTL::ArgumentAccessWriteOnly: + return Gfx::SE_DESCRIPTOR_ACCESS_WRITE_ONLY_BIT; + default: + throw std::logic_error("Not implemented"); + } } MTL::SamplerBorderColor Seele::Metal::cast(Gfx::SeBorderColor color) { - switch (color) { - case Gfx::SE_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK: - return MTL::SamplerBorderColorTransparentBlack; - case Gfx::SE_BORDER_COLOR_INT_TRANSPARENT_BLACK: - return MTL::SamplerBorderColorTransparentBlack; - case Gfx::SE_BORDER_COLOR_FLOAT_OPAQUE_BLACK: - return MTL::SamplerBorderColorOpaqueBlack; - case Gfx::SE_BORDER_COLOR_INT_OPAQUE_BLACK: - return MTL::SamplerBorderColorOpaqueBlack; - case Gfx::SE_BORDER_COLOR_FLOAT_OPAQUE_WHITE: - return MTL::SamplerBorderColorOpaqueWhite; - case Gfx::SE_BORDER_COLOR_INT_OPAQUE_WHITE: - return MTL::SamplerBorderColorOpaqueWhite; - default: - throw std::logic_error("Not implemented"); - } + switch (color) { + case Gfx::SE_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK: + return MTL::SamplerBorderColorTransparentBlack; + case Gfx::SE_BORDER_COLOR_INT_TRANSPARENT_BLACK: + return MTL::SamplerBorderColorTransparentBlack; + case Gfx::SE_BORDER_COLOR_FLOAT_OPAQUE_BLACK: + return MTL::SamplerBorderColorOpaqueBlack; + case Gfx::SE_BORDER_COLOR_INT_OPAQUE_BLACK: + return MTL::SamplerBorderColorOpaqueBlack; + case Gfx::SE_BORDER_COLOR_FLOAT_OPAQUE_WHITE: + return MTL::SamplerBorderColorOpaqueWhite; + case Gfx::SE_BORDER_COLOR_INT_OPAQUE_WHITE: + return MTL::SamplerBorderColorOpaqueWhite; + default: + throw std::logic_error("Not implemented"); + } } Gfx::SeBorderColor Seele::Metal::cast(MTL::SamplerBorderColor color) { - switch (color) { - case MTL::SamplerBorderColorTransparentBlack: - return Gfx::SE_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK; - case MTL::SamplerBorderColorOpaqueBlack: - return Gfx::SE_BORDER_COLOR_FLOAT_OPAQUE_BLACK; - case MTL::SamplerBorderColorOpaqueWhite: - return Gfx::SE_BORDER_COLOR_FLOAT_OPAQUE_WHITE; - default: - throw std::logic_error("Not implemented"); - } + switch (color) { + case MTL::SamplerBorderColorTransparentBlack: + return Gfx::SE_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK; + case MTL::SamplerBorderColorOpaqueBlack: + return Gfx::SE_BORDER_COLOR_FLOAT_OPAQUE_BLACK; + case MTL::SamplerBorderColorOpaqueWhite: + return Gfx::SE_BORDER_COLOR_FLOAT_OPAQUE_WHITE; + default: + throw std::logic_error("Not implemented"); + } } MTL::CompareFunction Seele::Metal::cast(Gfx::SeCompareOp compare) { - switch (compare) { - case Gfx::SE_COMPARE_OP_NEVER: - return MTL::CompareFunctionNever; - case Gfx::SE_COMPARE_OP_LESS: - return MTL::CompareFunctionLess; - case Gfx::SE_COMPARE_OP_EQUAL: - return MTL::CompareFunctionEqual; - case Gfx::SE_COMPARE_OP_LESS_OR_EQUAL: - return MTL::CompareFunctionLessEqual; - case Gfx::SE_COMPARE_OP_GREATER: - return MTL::CompareFunctionGreater; - case Gfx::SE_COMPARE_OP_NOT_EQUAL: - return MTL::CompareFunctionNotEqual; - case Gfx::SE_COMPARE_OP_GREATER_OR_EQUAL: - return MTL::CompareFunctionGreaterEqual; - case Gfx::SE_COMPARE_OP_ALWAYS: - return MTL::CompareFunctionAlways; - default: - throw std::logic_error("Not implemented"); - } + switch (compare) { + case Gfx::SE_COMPARE_OP_NEVER: + return MTL::CompareFunctionNever; + case Gfx::SE_COMPARE_OP_LESS: + return MTL::CompareFunctionLess; + case Gfx::SE_COMPARE_OP_EQUAL: + return MTL::CompareFunctionEqual; + case Gfx::SE_COMPARE_OP_LESS_OR_EQUAL: + return MTL::CompareFunctionLessEqual; + case Gfx::SE_COMPARE_OP_GREATER: + return MTL::CompareFunctionGreater; + case Gfx::SE_COMPARE_OP_NOT_EQUAL: + return MTL::CompareFunctionNotEqual; + case Gfx::SE_COMPARE_OP_GREATER_OR_EQUAL: + return MTL::CompareFunctionGreaterEqual; + case Gfx::SE_COMPARE_OP_ALWAYS: + return MTL::CompareFunctionAlways; + default: + throw std::logic_error("Not implemented"); + } } Gfx::SeCompareOp Seele::Metal::cast(MTL::CompareFunction compare) { - switch (compare) { - case MTL::CompareFunctionNever: - return Gfx::SE_COMPARE_OP_NEVER; - case MTL::CompareFunctionLess: - return Gfx::SE_COMPARE_OP_LESS; - case MTL::CompareFunctionEqual: - return Gfx::SE_COMPARE_OP_EQUAL; - case MTL::CompareFunctionLessEqual: - return Gfx::SE_COMPARE_OP_LESS_OR_EQUAL; - case MTL::CompareFunctionGreater: - return Gfx::SE_COMPARE_OP_GREATER; - case MTL::CompareFunctionNotEqual: - return Gfx::SE_COMPARE_OP_NOT_EQUAL; - case MTL::CompareFunctionGreaterEqual: - return Gfx::SE_COMPARE_OP_GREATER_OR_EQUAL; - case MTL::CompareFunctionAlways: - return Gfx::SE_COMPARE_OP_ALWAYS; - } + switch (compare) { + case MTL::CompareFunctionNever: + return Gfx::SE_COMPARE_OP_NEVER; + case MTL::CompareFunctionLess: + return Gfx::SE_COMPARE_OP_LESS; + case MTL::CompareFunctionEqual: + return Gfx::SE_COMPARE_OP_EQUAL; + case MTL::CompareFunctionLessEqual: + return Gfx::SE_COMPARE_OP_LESS_OR_EQUAL; + case MTL::CompareFunctionGreater: + return Gfx::SE_COMPARE_OP_GREATER; + case MTL::CompareFunctionNotEqual: + return Gfx::SE_COMPARE_OP_NOT_EQUAL; + case MTL::CompareFunctionGreaterEqual: + return Gfx::SE_COMPARE_OP_GREATER_OR_EQUAL; + case MTL::CompareFunctionAlways: + return Gfx::SE_COMPARE_OP_ALWAYS; + } } MTL::SamplerMinMagFilter Seele::Metal::cast(Gfx::SeFilter filter) { - switch (filter) { - case Gfx::SE_FILTER_NEAREST: - return MTL::SamplerMinMagFilterNearest; - case Gfx::SE_FILTER_LINEAR: - return MTL::SamplerMinMagFilterLinear; - case Gfx::SE_FILTER_CUBIC_IMG: - return MTL::SamplerMinMagFilterLinear; - default: - throw std::logic_error("Not implemented"); - } + switch (filter) { + case Gfx::SE_FILTER_NEAREST: + return MTL::SamplerMinMagFilterNearest; + case Gfx::SE_FILTER_LINEAR: + return MTL::SamplerMinMagFilterLinear; + case Gfx::SE_FILTER_CUBIC_IMG: + return MTL::SamplerMinMagFilterLinear; + default: + throw std::logic_error("Not implemented"); + } } Gfx::SeFilter Seele::Metal::cast(MTL::SamplerMinMagFilter filter) { - switch (filter) { - case MTL::SamplerMinMagFilterNearest: - return Gfx::SE_FILTER_NEAREST; - case MTL::SamplerMinMagFilterLinear: - return Gfx::SE_FILTER_LINEAR; - } + switch (filter) { + case MTL::SamplerMinMagFilterNearest: + return Gfx::SE_FILTER_NEAREST; + case MTL::SamplerMinMagFilterLinear: + return Gfx::SE_FILTER_LINEAR; + } } MTL::SamplerMipFilter Seele::Metal::cast(Gfx::SeSamplerMipmapMode filter) { - switch (filter) { - case Seele::Gfx::SE_SAMPLER_MIPMAP_MODE_NEAREST: - return MTL::SamplerMipFilterNearest; - case Seele::Gfx::SE_SAMPLER_MIPMAP_MODE_LINEAR: - return MTL::SamplerMipFilterLinear; - default: - throw std::logic_error("Not implemented"); - } + switch (filter) { + case Seele::Gfx::SE_SAMPLER_MIPMAP_MODE_NEAREST: + return MTL::SamplerMipFilterNearest; + case Seele::Gfx::SE_SAMPLER_MIPMAP_MODE_LINEAR: + return MTL::SamplerMipFilterLinear; + default: + throw std::logic_error("Not implemented"); + } } Gfx::SeSamplerMipmapMode Seele::Metal::cast(MTL::SamplerMipFilter filter) { - switch (filter) { - case MTL::SamplerMipFilterNotMipmapped: - return Gfx::SE_SAMPLER_MIPMAP_MODE_LINEAR; - case MTL::SamplerMipFilterNearest: - return Gfx::SE_SAMPLER_MIPMAP_MODE_NEAREST; - case MTL::SamplerMipFilterLinear: - return Gfx::SE_SAMPLER_MIPMAP_MODE_LINEAR; - } + switch (filter) { + case MTL::SamplerMipFilterNotMipmapped: + return Gfx::SE_SAMPLER_MIPMAP_MODE_LINEAR; + case MTL::SamplerMipFilterNearest: + return Gfx::SE_SAMPLER_MIPMAP_MODE_NEAREST; + case MTL::SamplerMipFilterLinear: + return Gfx::SE_SAMPLER_MIPMAP_MODE_LINEAR; + } } MTL::SamplerAddressMode Seele::Metal::cast(Gfx::SeSamplerAddressMode mode) { - switch (mode) { - case Gfx::SE_SAMPLER_ADDRESS_MODE_REPEAT: - return MTL::SamplerAddressModeRepeat; - case Gfx::SE_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT: - return MTL::SamplerAddressModeMirrorRepeat; - case Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE: - return MTL::SamplerAddressModeMirrorClampToEdge; - case Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER: - return MTL::SamplerAddressModeClampToBorderColor; - case Gfx::SE_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE: - return MTL::SamplerAddressModeMirrorClampToEdge; - } + switch (mode) { + case Gfx::SE_SAMPLER_ADDRESS_MODE_REPEAT: + return MTL::SamplerAddressModeRepeat; + case Gfx::SE_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT: + return MTL::SamplerAddressModeMirrorRepeat; + case Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE: + return MTL::SamplerAddressModeMirrorClampToEdge; + case Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER: + return MTL::SamplerAddressModeClampToBorderColor; + case Gfx::SE_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE: + return MTL::SamplerAddressModeMirrorClampToEdge; + } } Gfx::SeSamplerAddressMode Seele::Metal::cast(MTL::SamplerAddressMode mode) { - switch (mode) { - case MTL::SamplerAddressModeClampToEdge: - return Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; - case MTL::SamplerAddressModeMirrorClampToEdge: - return Gfx::SE_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE; - case MTL::SamplerAddressModeRepeat: - return Gfx::SE_SAMPLER_ADDRESS_MODE_REPEAT; - case MTL::SamplerAddressModeMirrorRepeat: - return Gfx::SE_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT; - case MTL::SamplerAddressModeClampToZero: - return Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; - case MTL::SamplerAddressModeClampToBorderColor: - return Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; - } + switch (mode) { + case MTL::SamplerAddressModeClampToEdge: + return Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; + case MTL::SamplerAddressModeMirrorClampToEdge: + return Gfx::SE_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE; + case MTL::SamplerAddressModeRepeat: + return Gfx::SE_SAMPLER_ADDRESS_MODE_REPEAT; + case MTL::SamplerAddressModeMirrorRepeat: + return Gfx::SE_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT; + case MTL::SamplerAddressModeClampToZero: + return Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; + case MTL::SamplerAddressModeClampToBorderColor: + return Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; + } } -MTL::PrimitiveTopologyClass -Seele::Metal::cast(Gfx::SePrimitiveTopology topology) { - switch (topology) { - case Gfx::SE_PRIMITIVE_TOPOLOGY_POINT_LIST: - return MTL::PrimitiveTopologyClassPoint; - case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_LIST: - return MTL::PrimitiveTopologyClassLine; - case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_STRIP: - return MTL::PrimitiveTopologyClassLine; - case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST: - return MTL::PrimitiveTopologyClassTriangle; - case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP: - return MTL::PrimitiveTopologyClassTriangle; - case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN: - return MTL::PrimitiveTopologyClassTriangle; - case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY: - return MTL::PrimitiveTopologyClassLine; - case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY: - return MTL::PrimitiveTopologyClassLine; - case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY: - return MTL::PrimitiveTopologyClassTriangle; - case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY: - return MTL::PrimitiveTopologyClassTriangle; - case Gfx::SE_PRIMITIVE_TOPOLOGY_PATCH_LIST: - return MTL::PrimitiveTopologyClassUnspecified; - } +MTL::PrimitiveTopologyClass Seele::Metal::cast(Gfx::SePrimitiveTopology topology) { + switch (topology) { + case Gfx::SE_PRIMITIVE_TOPOLOGY_POINT_LIST: + return MTL::PrimitiveTopologyClassPoint; + case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_LIST: + return MTL::PrimitiveTopologyClassLine; + case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_STRIP: + return MTL::PrimitiveTopologyClassLine; + case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST: + return MTL::PrimitiveTopologyClassTriangle; + case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP: + return MTL::PrimitiveTopologyClassTriangle; + case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN: + return MTL::PrimitiveTopologyClassTriangle; + case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY: + return MTL::PrimitiveTopologyClassLine; + case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY: + return MTL::PrimitiveTopologyClassLine; + case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY: + return MTL::PrimitiveTopologyClassTriangle; + case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY: + return MTL::PrimitiveTopologyClassTriangle; + case Gfx::SE_PRIMITIVE_TOPOLOGY_PATCH_LIST: + return MTL::PrimitiveTopologyClassUnspecified; + } } MTL::IndexType Seele::Metal::cast(Gfx::SeIndexType indexType) { - switch (indexType) { - case Gfx::SE_INDEX_TYPE_UINT16: - return MTL::IndexTypeUInt16; - case Gfx::SE_INDEX_TYPE_UINT32: - return MTL::IndexTypeUInt32; - default: - throw std::logic_error("Not implemented"); - } + switch (indexType) { + case Gfx::SE_INDEX_TYPE_UINT16: + return MTL::IndexTypeUInt16; + case Gfx::SE_INDEX_TYPE_UINT32: + return MTL::IndexTypeUInt32; + default: + throw std::logic_error("Not implemented"); + } } Gfx::SeIndexType Seele::Metal::cast(MTL::IndexType indexType) { - switch (indexType) { - case MTL::IndexTypeUInt16: - return Gfx::SE_INDEX_TYPE_UINT16; - case MTL::IndexTypeUInt32: - return Gfx::SE_INDEX_TYPE_UINT32; - } + switch (indexType) { + case MTL::IndexTypeUInt16: + return Gfx::SE_INDEX_TYPE_UINT16; + case MTL::IndexTypeUInt32: + return Gfx::SE_INDEX_TYPE_UINT32; + } } diff --git a/src/Engine/Graphics/Metal/Graphics.h b/src/Engine/Graphics/Metal/Graphics.h index 401b502..5a1c19c 100644 --- a/src/Engine/Graphics/Metal/Graphics.h +++ b/src/Engine/Graphics/Metal/Graphics.h @@ -2,7 +2,6 @@ #include "Graphics/Graphics.h" #include "Metal/Metal.hpp" - namespace Seele { namespace Metal { DECLARE_REF(CommandQueue) @@ -24,6 +23,7 @@ class Graphics : public Gfx::Graphics { virtual void waitDeviceIdle() override; virtual void executeCommands(Array commands) override; + virtual void executeCommands(Gfx::OComputeCommand commands) override; virtual void executeCommands(Array commands) override; virtual Gfx::OTexture2D createTexture2D(const TextureCreateInfo& createInfo) override; diff --git a/src/Engine/Graphics/Metal/Graphics.mm b/src/Engine/Graphics/Metal/Graphics.mm index c751384..e2bff65 100644 --- a/src/Engine/Graphics/Metal/Graphics.mm +++ b/src/Engine/Graphics/Metal/Graphics.mm @@ -1,17 +1,19 @@ #include "Graphics.h" #include "Buffer.h" #include "Command.h" +#include "Graphics/Graphics.h" #include "Graphics/Initializer.h" #include "Graphics/Metal/Descriptor.h" #include "Graphics/Metal/Pipeline.h" #include "Graphics/Metal/PipelineCache.h" +#include "Graphics/Metal/Query.h" #include "Graphics/Metal/Resources.h" +#include "Graphics/slang-compile.h" #include "RenderPass.h" #include "Resources.h" #include "Shader.h" #include "Window.h" #include -#include "Graphics/slang-compile.h" using namespace Seele; using namespace Seele::Metal; @@ -21,198 +23,136 @@ Graphics::Graphics() {} Graphics::~Graphics() {} void Graphics::init(GraphicsInitializer) { - glfwInit(); - device = MTL::CreateSystemDefaultDevice(); - queue = new CommandQueue(this); - ioQueue = new IOCommandQueue(this); - cache = new PipelineCache(this, "pipelines.metal"); - meshShadingEnabled = false; + glfwInit(); + device = MTL::CreateSystemDefaultDevice(); + queue = new CommandQueue(this); + ioQueue = new IOCommandQueue(this); + cache = new PipelineCache(this, "pipelines.metal"); + meshShadingEnabled = true; } -Gfx::OWindow Graphics::createWindow(const WindowCreateInfo &createInfo) { - return new Window(this, createInfo); +Gfx::OWindow Graphics::createWindow(const WindowCreateInfo& createInfo) { return new Window(this, createInfo); } + +Gfx::OViewport Graphics::createViewport(Gfx::PWindow owner, const ViewportCreateInfo& createInfo) { + return new Viewport(owner, createInfo); } -Gfx::OViewport Graphics::createViewport(Gfx::PWindow owner, - const ViewportCreateInfo &createInfo) { - return new Viewport(owner, createInfo); +Gfx::ORenderPass Graphics::createRenderPass(Gfx::RenderTargetLayout layout, Array dependencies, + Gfx::PViewport renderArea, std::string name) { + return new RenderPass(this, layout, dependencies, renderArea, name); } -Gfx::ORenderPass -Graphics::createRenderPass(Gfx::RenderTargetLayout layout, - Array dependencies, - Gfx::PViewport renderArea, std::string name) { - return new RenderPass(this, layout, dependencies, renderArea, name); -} - -void Graphics::beginRenderPass(Gfx::PRenderPass renderPass) { - queue->getCommands()->beginRenderPass(renderPass.cast()); -} +void Graphics::beginRenderPass(Gfx::PRenderPass renderPass) { queue->getCommands()->beginRenderPass(renderPass.cast()); } void Graphics::endRenderPass() { queue->getCommands()->endRenderPass(); } void Graphics::waitDeviceIdle() { queue->getCommands()->waitDeviceIdle(); } -void Graphics::executeCommands(Array commands) { - queue->executeCommands(std::move(commands)); +void Graphics::executeCommands(Array commands) { queue->executeCommands(std::move(commands)); } + +void Graphics::executeCommands(Gfx::OComputeCommand commands) { + Array command; + command.add(std::move(commands)); + queue->executeCommands(std::move(command)); } -void Graphics::executeCommands(Array commands) { - queue->executeCommands(std::move(commands)); -} +void Graphics::executeCommands(Array commands) { queue->executeCommands(std::move(commands)); } -Gfx::OTexture2D Graphics::createTexture2D(const TextureCreateInfo &createInfo) { - return new Texture2D(this, createInfo); -} +Gfx::OTexture2D Graphics::createTexture2D(const TextureCreateInfo& 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 -Graphics::createTextureCube(const TextureCreateInfo &createInfo) { - return new TextureCube(this, createInfo); -} +Gfx::OUniformBuffer Graphics::createUniformBuffer(const UniformBufferCreateInfo& bulkData) { return new UniformBuffer(this, bulkData); } -Gfx::OUniformBuffer -Graphics::createUniformBuffer(const UniformBufferCreateInfo &bulkData) { - return new UniformBuffer(this, bulkData); -} +Gfx::OShaderBuffer Graphics::createShaderBuffer(const ShaderBufferCreateInfo& bulkData) { return new ShaderBuffer(this, bulkData); } -Gfx::OShaderBuffer -Graphics::createShaderBuffer(const ShaderBufferCreateInfo &bulkData) { - return new ShaderBuffer(this, bulkData); -} +Gfx::OVertexBuffer Graphics::createVertexBuffer(const VertexBufferCreateInfo& bulkData) { return new VertexBuffer(this, bulkData); } -Gfx::OVertexBuffer -Graphics::createVertexBuffer(const VertexBufferCreateInfo &bulkData) { - return new VertexBuffer(this, bulkData); -} +Gfx::OIndexBuffer Graphics::createIndexBuffer(const IndexBufferCreateInfo& bulkData) { return new IndexBuffer(this, bulkData); } -Gfx::OIndexBuffer -Graphics::createIndexBuffer(const IndexBufferCreateInfo &bulkData) { - return new IndexBuffer(this, bulkData); -} +Gfx::ORenderCommand Graphics::createRenderCommand(const std::string& name) { return queue->getRenderCommand(name); } -Gfx::ORenderCommand Graphics::createRenderCommand(const std::string &name) { - return queue->getRenderCommand(name); -} +Gfx::OComputeCommand Graphics::createComputeCommand(const std::string& name) { return queue->getComputeCommand(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); } -Gfx::OVertexShader -Graphics::createVertexShader(const ShaderCreateInfo &createInfo) { - OVertexShader result = new VertexShader(this); - result->create(createInfo); - return result; +Gfx::OVertexShader Graphics::createVertexShader(const ShaderCreateInfo& createInfo) { + OVertexShader result = new VertexShader(this); + result->create(createInfo); + return result; } -Gfx::OFragmentShader -Graphics::createFragmentShader(const ShaderCreateInfo &createInfo) { - OFragmentShader result = new FragmentShader(this); - result->create(createInfo); - return result; +Gfx::OFragmentShader Graphics::createFragmentShader(const ShaderCreateInfo& createInfo) { + OFragmentShader result = new FragmentShader(this); + result->create(createInfo); + return result; } -Gfx::OComputeShader -Graphics::createComputeShader(const ShaderCreateInfo &createInfo) { - OComputeShader result = new ComputeShader(this); - result->create(createInfo); - return result; +Gfx::OComputeShader Graphics::createComputeShader(const ShaderCreateInfo& createInfo) { + OComputeShader result = new ComputeShader(this); + result->create(createInfo); + return result; } -Gfx::OMeshShader -Graphics::createMeshShader(const ShaderCreateInfo &createInfo) { - OMeshShader result = new MeshShader(this); - result->create(createInfo); - return result; +Gfx::OMeshShader Graphics::createMeshShader(const ShaderCreateInfo& createInfo) { + OMeshShader result = new MeshShader(this); + result->create(createInfo); + return result; } -Gfx::OTaskShader -Graphics::createTaskShader(const ShaderCreateInfo &createInfo) { - OTaskShader result = new TaskShader(this); - result->create(createInfo); - return result; +Gfx::OTaskShader Graphics::createTaskShader(const ShaderCreateInfo& createInfo) { + OTaskShader result = new TaskShader(this); + result->create(createInfo); + return result; } -Gfx::PGraphicsPipeline -Graphics::createGraphicsPipeline(Gfx::LegacyPipelineCreateInfo createInfo) { - return cache->createPipeline(std::move(createInfo)); +Gfx::PGraphicsPipeline Graphics::createGraphicsPipeline(Gfx::LegacyPipelineCreateInfo createInfo) { + return cache->createPipeline(std::move(createInfo)); } -Gfx::PGraphicsPipeline -Graphics::createGraphicsPipeline(Gfx::MeshPipelineCreateInfo createInfo) { - return cache->createPipeline(std::move(createInfo)); +Gfx::PGraphicsPipeline Graphics::createGraphicsPipeline(Gfx::MeshPipelineCreateInfo createInfo) { + return cache->createPipeline(std::move(createInfo)); } -Gfx::PComputePipeline -Graphics::createComputePipeline(Gfx::ComputePipelineCreateInfo createInfo) { - return cache->createPipeline(std::move(createInfo)); +Gfx::PComputePipeline Graphics::createComputePipeline(Gfx::ComputePipelineCreateInfo createInfo) { + return cache->createPipeline(std::move(createInfo)); } -Gfx::PRayTracingPipeline Graphics::createRayTracingPipeline(Gfx::RayTracingPipelineCreateInfo createInfo) { - return nullptr; +Gfx::PRayTracingPipeline Graphics::createRayTracingPipeline(Gfx::RayTracingPipelineCreateInfo createInfo) { return nullptr; } + +Gfx::OSampler Graphics::createSampler(const SamplerCreateInfo& createInfo) { return new Sampler(this, createInfo); } + +Gfx::ODescriptorLayout Graphics::createDescriptorLayout(const std::string& name) { return new DescriptorLayout(this, name); } + +Gfx::OPipelineLayout Graphics::createPipelineLayout(const std::string& name, Gfx::PPipelineLayout baseLayout) { + return new PipelineLayout(this, name, baseLayout); } -Gfx::OSampler Graphics::createSampler(const SamplerCreateInfo &createInfo) { - return new Sampler(this, createInfo); -} +Gfx::OVertexInput Graphics::createVertexInput(VertexInputStateCreateInfo createInfo) { return new VertexInput(createInfo); } -Gfx::ODescriptorLayout -Graphics::createDescriptorLayout(const std::string &name) { - return new DescriptorLayout(this, name); -} - -Gfx::OPipelineLayout -Graphics::createPipelineLayout(const std::string &name, - Gfx::PPipelineLayout baseLayout) { - return new PipelineLayout(this, name, baseLayout); -} - -Gfx::OVertexInput -Graphics::createVertexInput(VertexInputStateCreateInfo createInfo) { - return new VertexInput(createInfo); -} - - -Gfx::OOcclusionQuery Graphics::createOcclusionQuery(const std::string& name) { - -} +Gfx::OOcclusionQuery Graphics::createOcclusionQuery(const std::string& name) { return new OcclusionQuery(this, name); } Gfx::OPipelineStatisticsQuery Graphics::createPipelineStatisticsQuery(const std::string& name) { - + return new PipelineStatisticsQuery(this, 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::copyTexture(Gfx::PTexture src, Gfx::PTexture dst) { - -} +void Graphics::resolveTexture(Gfx::PTexture source, Gfx::PTexture destination) {} +void Graphics::copyTexture(Gfx::PTexture src, Gfx::PTexture dst) {} // Ray Tracing -Gfx::OBottomLevelAS Graphics::createBottomLevelAccelerationStructure(const Gfx::BottomLevelASCreateInfo& createInfo) { - return nullptr; -} +Gfx::OBottomLevelAS Graphics::createBottomLevelAccelerationStructure(const Gfx::BottomLevelASCreateInfo& createInfo) { return nullptr; } -Gfx::OTopLevelAS Graphics::createTopLevelAccelerationStructure(const Gfx::TopLevelASCreateInfo& createInfo) { - return nullptr; -} +Gfx::OTopLevelAS Graphics::createTopLevelAccelerationStructure(const Gfx::TopLevelASCreateInfo& createInfo) { return nullptr; } -void Graphics::buildBottomLevelAccelerationStructures(Array data) { - -} +void Graphics::buildBottomLevelAccelerationStructures(Array data) {} Gfx::ORayGenShader Graphics::createRayGenShader(const ShaderCreateInfo& createInfo) { ORayGenShader shader = new RayGenShader(this); @@ -244,4 +184,3 @@ Gfx::OCallableShader Graphics::createCallableShader(const ShaderCreateInfo& crea shader->create(createInfo); return shader; } - diff --git a/src/Engine/Graphics/Metal/Pipeline.mm b/src/Engine/Graphics/Metal/Pipeline.mm index f9679b3..6f50940 100644 --- a/src/Engine/Graphics/Metal/Pipeline.mm +++ b/src/Engine/Graphics/Metal/Pipeline.mm @@ -7,23 +7,17 @@ using namespace Seele; using namespace Seele::Metal; -VertexInput::VertexInput(VertexInputStateCreateInfo createInfo) - : Gfx::VertexInput(createInfo) {} +VertexInput::VertexInput(VertexInputStateCreateInfo createInfo) : Gfx::VertexInput(createInfo) {} VertexInput::~VertexInput() {} -GraphicsPipeline::GraphicsPipeline(PGraphics graphics, - MTL::PrimitiveType primitive, - MTL::RenderPipelineState *pipeline, +GraphicsPipeline::GraphicsPipeline(PGraphics graphics, MTL::PrimitiveType primitive, MTL::RenderPipelineState* pipeline, Gfx::PPipelineLayout layout) - : Gfx::GraphicsPipeline(layout), graphics(graphics), state(pipeline), - primitiveType(primitive) {} + : Gfx::GraphicsPipeline(layout), graphics(graphics), state(pipeline), primitiveType(primitive) {} GraphicsPipeline::~GraphicsPipeline() {} -ComputePipeline::ComputePipeline(PGraphics graphics, - MTL::ComputePipelineState *pipeline, - Gfx::PPipelineLayout layout) +ComputePipeline::ComputePipeline(PGraphics graphics, MTL::ComputePipelineState* pipeline, Gfx::PPipelineLayout layout) : Gfx::ComputePipeline(layout), graphics(graphics), state(pipeline) {} ComputePipeline::~ComputePipeline() {} diff --git a/src/Engine/Graphics/Metal/Query.h b/src/Engine/Graphics/Metal/Query.h new file mode 100644 index 0000000..f6c2f07 --- /dev/null +++ b/src/Engine/Graphics/Metal/Query.h @@ -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& 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 getResults() override; + + private: + uint64 wrapping = 0; + uint64 lastMeasure = 0; + uint32 numTimestamps = 0; + uint32 currentTimestamp = 0; + Array pendingTimestamps; +}; +DEFINE_REF(TimestampQuery) +} // namespace Vulkan +} // namespace Seele \ No newline at end of file diff --git a/src/Engine/Graphics/Metal/Query.mm b/src/Engine/Graphics/Metal/Query.mm new file mode 100644 index 0000000..32a0fd2 --- /dev/null +++ b/src/Engine/Graphics/Metal/Query.mm @@ -0,0 +1,86 @@ +#include "Query.h" +#include "Buffer.h" +#include "Command.h" +#include "Containers/Array.h" +#include "Enums.h" +#include "Graphics.h" +#include + +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& 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 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 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 TimestampQuery::getResults() { +} \ No newline at end of file diff --git a/src/Engine/Graphics/Metal/RenderPass.h b/src/Engine/Graphics/Metal/RenderPass.h index 8f5454d..ef92ab2 100644 --- a/src/Engine/Graphics/Metal/RenderPass.h +++ b/src/Engine/Graphics/Metal/RenderPass.h @@ -7,7 +7,8 @@ namespace Metal { DECLARE_REF(Graphics) class RenderPass : public Gfx::RenderPass { public: - RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout, Array dependencies, Gfx::PViewport viewport, const std::string& name = ""); + RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout, Array dependencies, Gfx::PViewport viewport, + const std::string& name = ""); virtual ~RenderPass(); void updateRenderPass(); MTL::RenderPassDescriptor* getDescriptor() const { return renderPass; } diff --git a/src/Engine/Graphics/Metal/RenderPass.mm b/src/Engine/Graphics/Metal/RenderPass.mm index b62294e..294c5de 100644 --- a/src/Engine/Graphics/Metal/RenderPass.mm +++ b/src/Engine/Graphics/Metal/RenderPass.mm @@ -7,61 +7,53 @@ using namespace Seele; using namespace Seele::Metal; -RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout, - Array dependencies, +RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout, Array dependencies, Gfx::PViewport viewport, const std::string& name) - : Gfx::RenderPass(layout, dependencies), graphics(graphics), - viewport(viewport) { - renderPass = MTL::RenderPassDescriptor::renderPassDescriptor(); - renderPass->setRenderTargetArrayLength(1); - renderPass->setRenderTargetWidth(viewport->getWidth()); - renderPass->setRenderTargetHeight(viewport->getHeight()); - renderPass->setDefaultRasterSampleCount(viewport->getSamples()); + : Gfx::RenderPass(layout, dependencies), graphics(graphics), viewport(viewport) { + renderPass = MTL::RenderPassDescriptor::renderPassDescriptor(); + renderPass->setRenderTargetArrayLength(1); + renderPass->setRenderTargetWidth(viewport->getWidth()); + renderPass->setRenderTargetHeight(viewport->getHeight()); + renderPass->setDefaultRasterSampleCount(viewport->getSamples()); - for (size_t i = 0; i < layout.colorAttachments.size(); ++i) { - const auto &color = layout.colorAttachments[i]; - MTL::RenderPassColorAttachmentDescriptor *desc = - renderPass->colorAttachments()->object(i); - desc->setClearColor(MTL::ClearColor( - 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->setStoreAction(cast(color.getStoreOp())); - desc->setLevel(0); - if (!layout.resolveAttachments.empty()) { - const auto &resolve = layout.resolveAttachments[i]; - desc->setResolveLevel(0); - desc->setStoreAction(MTL::StoreActionStoreAndMultisampleResolve); - desc->setResolveTexture( - resolve.getTexture().cast()->getImage()); + for (size_t i = 0; i < layout.colorAttachments.size(); ++i) { + const auto& color = layout.colorAttachments[i]; + MTL::RenderPassColorAttachmentDescriptor* desc = renderPass->colorAttachments()->object(i); + desc->setClearColor(MTL::ClearColor(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->setStoreAction(cast(color.getStoreOp())); + desc->setLevel(0); + if (!layout.resolveAttachments.empty()) { + const auto& resolve = layout.resolveAttachments[i]; + desc->setResolveLevel(0); + desc->setStoreAction(MTL::StoreActionStoreAndMultisampleResolve); + desc->setResolveTexture(resolve.getTexture().cast()->getImage()); + } } - } - if (layout.depthAttachment.getTexture() != nullptr) { - auto depth = renderPass->depthAttachment(); - depth->setClearDepth(layout.depthAttachment.clear.depthStencil.depth); - depth->setLoadAction(cast(layout.depthAttachment.getLoadOp())); - depth->setStoreAction(cast(layout.depthAttachment.getStoreOp())); + if (layout.depthAttachment.getTexture() != nullptr) { + auto depth = renderPass->depthAttachment(); + depth->setClearDepth(layout.depthAttachment.clear.depthStencil.depth); + depth->setLoadAction(cast(layout.depthAttachment.getLoadOp())); + depth->setStoreAction(cast(layout.depthAttachment.getStoreOp())); - if (layout.depthResolveAttachment.getTexture() != nullptr) { - depth->setResolveTexture(layout.depthResolveAttachment.getTexture() - .cast() - ->getImage()); - depth->setStoreAction(MTL::StoreActionStoreAndMultisampleResolve); + if (layout.depthResolveAttachment.getTexture() != nullptr) { + depth->setResolveTexture(layout.depthResolveAttachment.getTexture().cast()->getImage()); + depth->setStoreAction(MTL::StoreActionStoreAndMultisampleResolve); + } } - } - // TODO: stencil + // TODO: stencil } RenderPass::~RenderPass() {} void RenderPass::updateRenderPass() { - for (size_t i = 0; i < layout.colorAttachments.size(); ++i) { - const auto &color = layout.colorAttachments[i]; - auto desc = renderPass->colorAttachments()->object(i); - desc->setTexture(color.getTexture().cast()->getImage()); - } - if (layout.depthAttachment.getTexture() != nullptr) { - auto depth = renderPass->depthAttachment(); - depth->setTexture( - layout.depthAttachment.getTexture().cast()->getImage()); - } + for (size_t i = 0; i < layout.colorAttachments.size(); ++i) { + const auto& color = layout.colorAttachments[i]; + auto desc = renderPass->colorAttachments()->object(i); + desc->setTexture(color.getTexture().cast()->getImage()); + } + if (layout.depthAttachment.getTexture() != nullptr) { + auto depth = renderPass->depthAttachment(); + depth->setTexture(layout.depthAttachment.getTexture().cast()->getImage()); + } } \ No newline at end of file diff --git a/src/Engine/Graphics/Metal/Resources.h b/src/Engine/Graphics/Metal/Resources.h index b6cecc7..3b4bb47 100644 --- a/src/Engine/Graphics/Metal/Resources.h +++ b/src/Engine/Graphics/Metal/Resources.h @@ -1,6 +1,6 @@ #pragma once -#include "Graphics/Resources.h" #include "Graphics/Initializer.h" +#include "Graphics/Resources.h" #include "Metal/MTLSampler.hpp" #include #include diff --git a/src/Engine/Graphics/Metal/Resources.mm b/src/Engine/Graphics/Metal/Resources.mm index cd5dba6..f14bbba 100644 --- a/src/Engine/Graphics/Metal/Resources.mm +++ b/src/Engine/Graphics/Metal/Resources.mm @@ -3,7 +3,6 @@ #include "Graphics.h" #include "Metal/MTLSampler.hpp" - using namespace Seele; using namespace Seele::Metal; @@ -15,24 +14,24 @@ Event::Event(PGraphics graphics) : handle(graphics->getDevice()->newEvent()) {} Event::~Event() { handle->release(); } -Sampler::Sampler(PGraphics graphics, const SamplerCreateInfo &createInfo) { - MTL::SamplerDescriptor *desc = MTL::SamplerDescriptor::alloc()->init(); - desc->setBorderColor(cast(createInfo.borderColor)); - desc->setCompareFunction(cast(createInfo.compareOp)); - desc->setLodAverage(createInfo.mipLodBias); - desc->setLodMaxClamp(createInfo.maxLod); - desc->setLodMinClamp(createInfo.minLod); - desc->setMinFilter(cast(createInfo.minFilter)); - desc->setMagFilter(cast(createInfo.magFilter)); - desc->setMipFilter(cast(createInfo.mipmapMode)); - desc->setMaxAnisotropy(createInfo.maxAnisotropy); - desc->setNormalizedCoordinates(!createInfo.unnormalizedCoordinates); - desc->setRAddressMode(cast(createInfo.addressModeU)); - desc->setSAddressMode(cast(createInfo.addressModeV)); - desc->setTAddressMode(cast(createInfo.addressModeW)); - desc->setSupportArgumentBuffers(true); - sampler = graphics->getDevice()->newSamplerState(desc); - desc->release(); +Sampler::Sampler(PGraphics graphics, const SamplerCreateInfo& createInfo) { + MTL::SamplerDescriptor* desc = MTL::SamplerDescriptor::alloc()->init(); + desc->setBorderColor(cast(createInfo.borderColor)); + desc->setCompareFunction(cast(createInfo.compareOp)); + desc->setLodAverage(createInfo.mipLodBias); + desc->setLodMaxClamp(createInfo.maxLod); + desc->setLodMinClamp(createInfo.minLod); + desc->setMinFilter(cast(createInfo.minFilter)); + desc->setMagFilter(cast(createInfo.magFilter)); + desc->setMipFilter(cast(createInfo.mipmapMode)); + desc->setMaxAnisotropy(createInfo.maxAnisotropy); + desc->setNormalizedCoordinates(!createInfo.unnormalizedCoordinates); + desc->setRAddressMode(cast(createInfo.addressModeU)); + desc->setSAddressMode(cast(createInfo.addressModeV)); + desc->setTAddressMode(cast(createInfo.addressModeW)); + desc->setSupportArgumentBuffers(true); + sampler = graphics->getDevice()->newSamplerState(desc); + desc->release(); } Sampler::~Sampler() { sampler->release(); } \ No newline at end of file diff --git a/src/Engine/Graphics/Metal/Shader.mm b/src/Engine/Graphics/Metal/Shader.mm index 9b36b85..5f989a0 100644 --- a/src/Engine/Graphics/Metal/Shader.mm +++ b/src/Engine/Graphics/Metal/Shader.mm @@ -14,40 +14,33 @@ using namespace Seele; using namespace Seele::Metal; -Shader::Shader(PGraphics graphics, Gfx::SeShaderStageFlags stage) - : stage(stage), graphics(graphics) {} +Shader::Shader(PGraphics graphics, Gfx::SeShaderStageFlags stage) : stage(stage), graphics(graphics) {} Shader::~Shader() { - if (function) { - function->release(); - library->release(); - } + if (function) { + function->release(); + library->release(); + } } -void Shader::create(const ShaderCreateInfo &createInfo) { - Map paramMapping; - auto [kernelBlob, entryPoint] = - generateShader(createInfo); - std::cout << (char *)kernelBlob->getBufferPointer() << std::endl; - hash = CRC::Calculate(kernelBlob->getBufferPointer(), - kernelBlob->getBufferSize(), CRC::CRC_32()); - NS::Error *error; - MTL::CompileOptions *options = MTL::CompileOptions::alloc()->init(); - library = graphics->getDevice()->newLibrary( - NS::String::string((char *)kernelBlob->getBufferPointer(), - NS::ASCIIStringEncoding), - options, &error); - options->release(); - if (error) { - std::cout << error->localizedDescription()->cString(NS::ASCIIStringEncoding) - << std::endl; - } - function = library->newFunction(NS::String::string( - entryPoint.c_str(), NS::ASCIIStringEncoding)); - if (!function) { - assert(false); - } - +void Shader::create(const ShaderCreateInfo& createInfo) { + auto [kernelBlob, entryPoint] = generateShader(createInfo); + std::ofstream test("test.metal"); + test.write((char*)kernelBlob->getBufferPointer(), kernelBlob->getBufferSize()); + test.close(); + hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32()); + NS::Error* error; + MTL::CompileOptions* options = MTL::CompileOptions::alloc()->init(); + library = graphics->getDevice()->newLibrary(NS::String::string((char*)kernelBlob->getBufferPointer(), NS::ASCIIStringEncoding), options, + &error); + options->release(); + if (error) { + std::cout << error->localizedDescription()->cString(NS::ASCIIStringEncoding) << std::endl; + } + function = library->newFunction(NS::String::string(entryPoint.c_str(), NS::ASCIIStringEncoding)); + if (!function) { + assert(false); + } } uint32 Shader::getShaderHash() const { return hash; } diff --git a/src/Engine/Graphics/Metal/Texture.h b/src/Engine/Graphics/Metal/Texture.h index 98b4c47..b67787f 100644 --- a/src/Engine/Graphics/Metal/Texture.h +++ b/src/Engine/Graphics/Metal/Texture.h @@ -11,13 +11,13 @@ class TextureHandle { TextureHandle(PGraphics graphics, MTL::TextureType type, const TextureCreateInfo& createInfo, MTL::Texture* existingImage); virtual ~TextureHandle(); void pipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess, - Gfx::SePipelineStageFlags dstStage); + Gfx::SePipelineStageFlags dstStage); void transferOwnership(Gfx::QueueType newOwner); - void changeLayout(Gfx::SeImageLayout newLayout, Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess, - Gfx::SePipelineStageFlags dstStage); + void changeLayout(Gfx::SeImageLayout newLayout, Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, + Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage); void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array& buffer); void generateMipmaps(); - + MTL::Texture* texture; MTL::TextureType type; uint32 width; @@ -35,7 +35,6 @@ class TextureHandle { }; DEFINE_REF(TextureHandle) - class TextureBase { public: TextureBase(PGraphics graphics, MTL::TextureType textureType, const TextureCreateInfo& createInfo, @@ -56,12 +55,13 @@ class TextureBase { constexpr bool isDepthStencil() const { return handle->aspect & (Gfx::SE_IMAGE_ASPECT_DEPTH_BIT | Gfx::SE_IMAGE_ASPECT_STENCIL_BIT); } void pipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess, - Gfx::SePipelineStageFlags dstStage); + Gfx::SePipelineStageFlags dstStage); void transferOwnership(Gfx::QueueType newOwner); - void changeLayout(Gfx::SeImageLayout newLayout, Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess, - Gfx::SePipelineStageFlags dstStage); + void changeLayout(Gfx::SeImageLayout newLayout, Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, + Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage); void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array& buffer); void generateMipmaps(); + protected: OTextureHandle handle; // Updates via reference diff --git a/src/Engine/Graphics/Metal/Texture.mm b/src/Engine/Graphics/Metal/Texture.mm index 64fda10..f61dd2d 100644 --- a/src/Engine/Graphics/Metal/Texture.mm +++ b/src/Engine/Graphics/Metal/Texture.mm @@ -9,83 +9,68 @@ using namespace Seele; using namespace Seele::Metal; -TextureHandle::TextureHandle(PGraphics graphics, MTL::TextureType type, - const TextureCreateInfo &createInfo, - MTL::Texture *existingImage) - : texture(existingImage), - type(type), width(createInfo.width), - height(createInfo.height), depth(createInfo.depth), - 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) { - MTL::TextureUsage mtlUsage = 0; - if (usage & Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT || - usage & Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) { - mtlUsage |= MTL::TextureUsageRenderTarget; +TextureHandle::TextureHandle(PGraphics graphics, MTL::TextureType type, const TextureCreateInfo& createInfo, MTL::Texture* existingImage) + : texture(existingImage), type(type), width(createInfo.width), height(createInfo.height), depth(createInfo.depth), + arrayCount(createInfo.elements), layerCount(createInfo.layers), mipLevels(1), samples(createInfo.samples), format(createInfo.format), + usage(createInfo.usage), layout(Gfx::SE_IMAGE_LAYOUT_UNDEFINED), ownsImage(existingImage == nullptr) { + if (createInfo.useMip) { + mipLevels = static_cast(std::floor(std::log2(std::max(width, height)))) + 1; } - if (usage & Gfx::SE_IMAGE_USAGE_SAMPLED_BIT) { - mtlUsage |= MTL::TextureUsageShaderRead; - } - if (usage & Gfx::SE_IMAGE_USAGE_STORAGE_BIT) { - mtlUsage |= MTL::TextureUsageShaderWrite; - } - MTL::TextureDescriptor *descriptor = - MTL::TextureDescriptor::alloc()->init(); - descriptor->setPixelFormat(cast(format)); - descriptor->setWidth(width); - descriptor->setHeight(height); - descriptor->setDepth(depth); - descriptor->setArrayLength(arrayCount); - descriptor->setMipmapLevelCount(mipLevels); - descriptor->setTextureType(type); - descriptor->setSampleCount(samples); - descriptor->setUsage(mtlUsage); + if (existingImage == nullptr) { + MTL::TextureUsage mtlUsage = 0; + if (usage & Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT || usage & Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) { + mtlUsage |= MTL::TextureUsageRenderTarget; + } + if (usage & Gfx::SE_IMAGE_USAGE_SAMPLED_BIT) { + mtlUsage |= MTL::TextureUsageShaderRead; + } + if (usage & Gfx::SE_IMAGE_USAGE_STORAGE_BIT) { + mtlUsage |= MTL::TextureUsageShaderWrite; + } + MTL::TextureDescriptor* descriptor = MTL::TextureDescriptor::alloc()->init(); + descriptor->setPixelFormat(cast(format)); + descriptor->setWidth(width); + descriptor->setHeight(height); + descriptor->setDepth(depth); + descriptor->setArrayLength(arrayCount); + descriptor->setMipmapLevelCount(mipLevels); + descriptor->setTextureType(type); + descriptor->setSampleCount(samples); + descriptor->setUsage(mtlUsage); - texture = graphics->getDevice()->newTexture(descriptor); + texture = graphics->getDevice()->newTexture(descriptor); - descriptor->release(); - } - // if(createInfo.sourceData.data != nullptr) - // { - // MTL::Region region(0, 0, 0, width, height, depth); - // texture->replaceRegion(region, 0, createInfo.sourceData.data, - // createInfo.sourceData.size / (depth * height)); - // } + descriptor->release(); + } + // if(createInfo.sourceData.data != nullptr) + // { + // MTL::Region region(0, 0, 0, width, height, depth); + // texture->replaceRegion(region, 0, createInfo.sourceData.data, + // createInfo.sourceData.size / (depth * height)); + // } } TextureHandle::~TextureHandle() { - if (ownsImage) { - texture->release(); - } + if (ownsImage) { + texture->release(); + } } -void TextureHandle::pipelineBarrier(Gfx::SeAccessFlags, - Gfx::SePipelineStageFlags, - Gfx::SeAccessFlags, - Gfx::SePipelineStageFlags) {} +void TextureHandle::pipelineBarrier(Gfx::SeAccessFlags, Gfx::SePipelineStageFlags, Gfx::SeAccessFlags, Gfx::SePipelineStageFlags) {} -void TextureHandle::changeLayout(Gfx::SeImageLayout, Gfx::SeAccessFlags, - Gfx::SePipelineStageFlags, Gfx::SeAccessFlags, - Gfx::SePipelineStageFlags) {} +void TextureHandle::changeLayout(Gfx::SeImageLayout, Gfx::SeAccessFlags, Gfx::SePipelineStageFlags, Gfx::SeAccessFlags, + Gfx::SePipelineStageFlags) {} -void TextureHandle::transferOwnership(Gfx::QueueType newOwner) { - -} +void TextureHandle::transferOwnership(Gfx::QueueType newOwner) {} -void TextureHandle::download(uint32, uint32, uint32, Array &) {} +void TextureHandle::download(uint32, uint32, uint32, Array&) {} -void TextureHandle::generateMipmaps() -{ -} +void TextureHandle::generateMipmaps() {} 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() {} void TextureBase::pipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) { diff --git a/src/Engine/Graphics/Metal/Window.mm b/src/Engine/Graphics/Metal/Window.mm index 3755b0d..97d1bd9 100644 --- a/src/Engine/Graphics/Metal/Window.mm +++ b/src/Engine/Graphics/Metal/Window.mm @@ -17,206 +17,180 @@ using namespace Seele::Metal; double currentFrameDelta = 0; double Gfx::getCurrentFrameDelta() { return currentFrameDelta; } + +double currentFrameTime = 0; +double Gfx::getCurrentFrameTime() { return currentFrameTime; } + uint32 currentFrameIndex = 0; uint32 Gfx::getCurrentFrameIndex() { return currentFrameIndex; } -void glfwKeyCallback(GLFWwindow *handle, int key, int, int action, - int modifier) { - if (key == -1) { - return; - } - Window *window = (Window *)glfwGetWindowUserPointer(handle); - window->keyPress((KeyCode)key, (InputAction)action, (KeyModifier)modifier); +void glfwKeyCallback(GLFWwindow* handle, int key, int, int action, int modifier) { + if (key == -1) { + return; + } + Window* window = (Window*)glfwGetWindowUserPointer(handle); + window->keyPress((KeyCode)key, (InputAction)action, (KeyModifier)modifier); } -void glfwMouseMoveCallback(GLFWwindow *handle, double xpos, double ypos) { - Window *window = (Window *)glfwGetWindowUserPointer(handle); - window->mouseMove(xpos, ypos); +void glfwMouseMoveCallback(GLFWwindow* handle, double xpos, double ypos) { + Window* window = (Window*)glfwGetWindowUserPointer(handle); + window->mouseMove(xpos, ypos); } -void glfwMouseButtonCallback(GLFWwindow *handle, int button, int action, - int modifier) { - Window *window = (Window *)glfwGetWindowUserPointer(handle); - window->mouseButton((MouseButton)button, (InputAction)action, - (KeyModifier)modifier); +void glfwMouseButtonCallback(GLFWwindow* handle, int button, int action, int modifier) { + Window* window = (Window*)glfwGetWindowUserPointer(handle); + window->mouseButton((MouseButton)button, (InputAction)action, (KeyModifier)modifier); } -void glfwScrollCallback(GLFWwindow *handle, double xoffset, double yoffset) { - Window *window = (Window *)glfwGetWindowUserPointer(handle); - window->scroll(xoffset, yoffset); +void glfwScrollCallback(GLFWwindow* handle, double xoffset, double yoffset) { + Window* window = (Window*)glfwGetWindowUserPointer(handle); + window->scroll(xoffset, yoffset); } -void glfwFileCallback(GLFWwindow *handle, int count, const char **paths) { - Window *window = (Window *)glfwGetWindowUserPointer(handle); - window->fileDrop(count, paths); +void glfwFileCallback(GLFWwindow* handle, int count, const char** paths) { + Window* window = (Window*)glfwGetWindowUserPointer(handle); + window->fileDrop(count, paths); } -void glfwCloseCallback(GLFWwindow *handle) { - Window *window = (Window *)glfwGetWindowUserPointer(handle); - window->close(); +void glfwCloseCallback(GLFWwindow* handle) { + Window* window = (Window*)glfwGetWindowUserPointer(handle); + window->close(); } -void glfwFramebufferResizeCallback(GLFWwindow *handle, int width, int height) { - Window *window = (Window *)glfwGetWindowUserPointer(handle); - window->resize(width, height); +void glfwFramebufferResizeCallback(GLFWwindow* handle, int width, int height) { + Window* window = (Window*)glfwGetWindowUserPointer(handle); + window->resize(width, height); } -Window::Window(PGraphics graphics, const WindowCreateInfo &createInfo) - : graphics(graphics), preferences(createInfo) { - glfwSetErrorCallback([](int, const char *description) { - std::cout << description << std::endl; - }); - float xscale = 1, yscale = 1; - glfwGetMonitorContentScale(glfwGetPrimaryMonitor(), &xscale, &yscale); - glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); - GLFWwindow *handle = - glfwCreateWindow(createInfo.width / xscale, createInfo.height / yscale, - createInfo.title, nullptr, nullptr); - windowHandle = handle; - glfwSetWindowUserPointer(handle, this); +Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo) : graphics(graphics), preferences(createInfo) { + glfwSetErrorCallback([](int, const char* description) { std::cout << description << std::endl; }); + float xscale = 1, yscale = 1; + glfwGetMonitorContentScale(glfwGetPrimaryMonitor(), &xscale, &yscale); + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + GLFWwindow* handle = glfwCreateWindow(createInfo.width / xscale, createInfo.height / yscale, createInfo.title, nullptr, nullptr); + windowHandle = handle; + glfwSetWindowUserPointer(handle, this); - glfwSetKeyCallback(handle, &glfwKeyCallback); - glfwSetCursorPosCallback(handle, &glfwMouseMoveCallback); - glfwSetMouseButtonCallback(handle, &glfwMouseButtonCallback); - glfwSetScrollCallback(handle, &glfwScrollCallback); - glfwSetDropCallback(handle, &glfwFileCallback); - glfwSetWindowCloseCallback(handle, &glfwCloseCallback); - glfwSetFramebufferSizeCallback(handle, &glfwFramebufferResizeCallback); - int width, height; - glfwGetFramebufferSize(handle, &width, &height); - framebufferWidth = width; - framebufferHeight = height; + glfwSetKeyCallback(handle, &glfwKeyCallback); + glfwSetCursorPosCallback(handle, &glfwMouseMoveCallback); + glfwSetMouseButtonCallback(handle, &glfwMouseButtonCallback); + glfwSetScrollCallback(handle, &glfwScrollCallback); + glfwSetDropCallback(handle, &glfwFileCallback); + glfwSetWindowCloseCallback(handle, &glfwCloseCallback); + glfwSetFramebufferSizeCallback(handle, &glfwFramebufferResizeCallback); + int width, height; + glfwGetFramebufferSize(handle, &width, &height); + framebufferWidth = width; + framebufferHeight = height; - metalWindow = glfwGetCocoaWindow(handle); - metalLayer = [CAMetalLayer layer]; - metalLayer.device = (__bridge id)graphics->getDevice(); - metalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm; - metalLayer.drawableSize = CGSizeMake(createInfo.width, createInfo.height); - metalWindow.contentView.layer = metalLayer; - metalWindow.contentView.wantsLayer = YES; + metalWindow = glfwGetCocoaWindow(handle); + metalLayer = [CAMetalLayer layer]; + metalLayer.device = (__bridge id)graphics->getDevice(); + metalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm; + metalLayer.drawableSize = CGSizeMake(createInfo.width, createInfo.height); + metalWindow.contentView.layer = metalLayer; + metalWindow.contentView.wantsLayer = YES; } -Window::~Window() { - glfwDestroyWindow(static_cast(windowHandle)); -} +Window::~Window() { glfwDestroyWindow(static_cast(windowHandle)); } void Window::pollInput() { glfwPollEvents(); } void Window::beginFrame() { - drawable = (__bridge CA::MetalDrawable *)[metalLayer nextDrawable]; - createBackBuffer(); + drawable = (__bridge CA::MetalDrawable*)[metalLayer nextDrawable]; + createBackBuffer(); + static double start = glfwGetTime(); + double end = glfwGetTime(); + currentFrameDelta = end - start; + currentFrameTime += currentFrameDelta; + start = end; } void Window::endFrame() { - graphics->getQueue()->getCommands()->present(drawable); - graphics->getQueue()->submitCommands(); - currentFrameIndex++; + graphics->getQueue()->getCommands()->present(drawable); + graphics->getQueue()->submitCommands(); + currentFrameIndex++; } void Window::onWindowCloseEvent() {} Gfx::PTexture2D Window::getBackBuffer() const { return PTexture2D(backBuffer); } -void Window::setKeyCallback( - std::function callback) { - keyCallback = callback; -} +void Window::setKeyCallback(std::function callback) { keyCallback = callback; } -void Window::setMouseMoveCallback( - std::function callback) { - mouseMoveCallback = callback; -} +void Window::setMouseMoveCallback(std::function callback) { mouseMoveCallback = callback; } -void Window::setMouseButtonCallback( - std::function callback) { - mouseButtonCallback = callback; -} +void Window::setMouseButtonCallback(std::function callback) { mouseButtonCallback = callback; } -void Window::setScrollCallback(std::function callback) { - scrollCallback = callback; -} +void Window::setScrollCallback(std::function callback) { scrollCallback = callback; } -void Window::setFileCallback(std::function callback) { - fileCallback = callback; -} +void Window::setFileCallback(std::function callback) { fileCallback = callback; } -void Window::setCloseCallback(std::function callback) { - closeCallback = callback; -} +void Window::setCloseCallback(std::function callback) { closeCallback = callback; } -void Window::setResizeCallback(std::function callback) { - resizeCallback = callback; -} +void Window::setResizeCallback(std::function callback) { resizeCallback = callback; } -void Window::keyPress(KeyCode code, InputAction action, KeyModifier modifier) { - keyCallback(code, action, modifier); -} +void Window::keyPress(KeyCode code, InputAction action, KeyModifier modifier) { keyCallback(code, action, modifier); } void Window::mouseMove(double x, double y) { mouseMoveCallback(x, y); } -void Window::mouseButton(MouseButton button, InputAction action, - KeyModifier modifier) { - mouseButtonCallback(button, action, modifier); -} +void Window::mouseButton(MouseButton button, InputAction action, KeyModifier modifier) { mouseButtonCallback(button, action, modifier); } void Window::scroll(double x, double y) { scrollCallback(x, y); } -void Window::fileDrop(int num, const char **files) { fileCallback(num, files); } +void Window::fileDrop(int num, const char** files) { fileCallback(num, files); } void Window::close() { closeCallback(); } void Window::resize(int width, int height) { - if (width == 0 || height == 0) { + if (width == 0 || height == 0) { + paused = true; + return; + } paused = true; - return; - } - paused = true; - metalLayer.drawableSize = CGSizeMake(width, height); - drawable->release(); - framebufferWidth = width; - framebufferHeight = height; - // Deallocate the textures if they have been created - drawable = - (__bridge CA::MetalDrawable *)[[metalLayer nextDrawable] autorelease]; - createBackBuffer(); - resizeCallback(width, height); + metalLayer.drawableSize = CGSizeMake(width, height); + drawable->release(); + framebufferWidth = width; + framebufferHeight = height; + // Deallocate the textures if they have been created + drawable = (__bridge CA::MetalDrawable*)[[metalLayer nextDrawable] autorelease]; + createBackBuffer(); + resizeCallback(width, height); } void Window::createBackBuffer() { - MTL::Texture *buf = drawable->texture(); - backBuffer = new Texture2D( - graphics, - TextureCreateInfo{ - .width = static_cast(buf->width()), - .height = static_cast(buf->height()), - .depth = static_cast(buf->depth()), - .elements = static_cast(buf->arrayLength()), - .mipLevels = static_cast(buf->mipmapLevelCount()), - .format = cast(buf->pixelFormat()), - .usage = MTL::TextureUsageRenderTarget, - .samples = static_cast(buf->sampleCount()), - }, - buf); + MTL::Texture* buf = drawable->texture(); + backBuffer = new Texture2D(graphics, + TextureCreateInfo{ + .width = static_cast(buf->width()), + .height = static_cast(buf->height()), + .depth = static_cast(buf->depth()), + .elements = static_cast(buf->arrayLength()), + .useMip = false, + .format = cast(buf->pixelFormat()), + .usage = MTL::TextureUsageRenderTarget, + .samples = static_cast(buf->sampleCount()), + }, + buf); } -Viewport::Viewport(PWindow owner, const ViewportCreateInfo &createInfo) - : Gfx::Viewport(owner, createInfo) { - viewport.width = sizeX; - viewport.height = sizeY; - viewport.originX = offsetX; - viewport.originY = offsetY; - viewport.znear = 0.0f; - viewport.zfar = 1.0f; +Viewport::Viewport(PWindow owner, const ViewportCreateInfo& createInfo) : Gfx::Viewport(owner, createInfo) { + viewport.width = sizeX; + viewport.height = sizeY; + viewport.originX = offsetX; + viewport.originY = offsetY; + viewport.znear = 0.0f; + viewport.zfar = 1.0f; } Viewport::~Viewport() {} void Viewport::resize(uint32 newX, uint32 newY) { - viewport.width = newX; - viewport.height = newY; + viewport.width = newX; + viewport.height = newY; } void Viewport::move(uint32 newOffset, uint32 newOffsetY) { - viewport.originX = newOffset; - viewport.originY = newOffsetY; + viewport.originX = newOffset; + viewport.originY = newOffsetY; } diff --git a/src/Engine/Graphics/Query.h b/src/Engine/Graphics/Query.h index 0d394a0..c4bd14d 100644 --- a/src/Engine/Graphics/Query.h +++ b/src/Engine/Graphics/Query.h @@ -34,7 +34,7 @@ struct PipelineStatisticsResult { 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, res.clippingInvocations, res.clippingPrimitives, res.fragmentShaderInvocations, res.computeShaderInvocations, res.taskShaderInvocations, res.meshShaderInvocations); diff --git a/src/Engine/Graphics/RenderPass/BasePass.cpp b/src/Engine/Graphics/RenderPass/BasePass.cpp index ffd831c..74d13e7 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.cpp +++ b/src/Engine/Graphics/RenderPass/BasePass.cpp @@ -26,7 +26,7 @@ void Seele::addDebugVertex(DebugVertex vert) { gDebugVertices.add(vert); } void Seele::addDebugVertices(Array verts) { gDebugVertices.addAll(verts); } 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->addDescriptorLayout(viewParamsLayout); @@ -98,7 +98,7 @@ void BasePass::beginFrame(const Component::Camera& cam) { opaqueCulling = lightCullingLayout->allocateDescriptorSet(); transparentCulling = lightCullingLayout->allocateDescriptorSet(); - waterRenderer->beginFrame(); + //waterRenderer->beginFrame(); // Debug vertices { @@ -248,7 +248,7 @@ void BasePass::render() { } } - commands.add(waterRenderer->render(viewParamsSet)); + //commands.add(waterRenderer->render(viewParamsSet)); // Skybox { diff --git a/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp b/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp index 2ac33e5..67d021d 100644 --- a/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp +++ b/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp @@ -1,6 +1,6 @@ #include "DepthCullingPass.h" #include "Graphics/Shader.h" -#include +#include using namespace Seele; @@ -218,8 +218,8 @@ void DepthCullingPass::publishOutputs() { mipOffsets.add(bufferSize); mipDims.add(UVector2(width, height)); bufferSize += width * height; - width = max((width + 1) / 2, 1); - height = max((height + 1) / 2, 1); + width = std::max((width + 1) / 2, 1u); + height = std::max((height + 1) / 2, 1u); } ShaderBufferCreateInfo depthMipInfo = { .sourceData = diff --git a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp index 1ccbc51..1d4d232 100644 --- a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp +++ b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp @@ -260,6 +260,7 @@ void LightCullingPass::setupFrustums() { .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_WRITE_ONLY_BIT, }); + dispatchParamsLayout->create(); frustumLayout = graphics->createPipelineLayout("FrustumLayout"); frustumLayout->addDescriptorLayout(viewParamsLayout); frustumLayout->addDescriptorLayout(dispatchParamsLayout); diff --git a/src/Engine/Graphics/RenderPass/WaterRenderer.cpp b/src/Engine/Graphics/RenderPass/WaterRenderer.cpp index 5bddcbc..d891243 100644 --- a/src/Engine/Graphics/RenderPass/WaterRenderer.cpp +++ b/src/Engine/Graphics/RenderPass/WaterRenderer.cpp @@ -248,7 +248,7 @@ WaterRenderer::WaterRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDescri { {"taskMain", "WaterTask"}, {"meshMain", "WaterMesh"}, - {"main", "WaterPass"}, + {"fragmentMain", "WaterPass"}, }, .rootSignature = waterLayout, .dumpIntermediate = true, diff --git a/src/Engine/Graphics/Shader.cpp b/src/Engine/Graphics/Shader.cpp index 87f7734..9fc216f 100644 --- a/src/Engine/Graphics/Shader.cpp +++ b/src/Engine/Graphics/Shader.cpp @@ -122,7 +122,7 @@ void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipeline { createInfo.dumpIntermediate = true; } - createInfo.typeParameter.add({Pair("IVertexData", permutation.vertexDataName)}); + //createInfo.typeParameter.add({Pair("IVertexData", permutation.vertexDataName)}); createInfo.modules.add(permutation.vertexDataName); if (permutation.useMeshShading) { diff --git a/src/Engine/Graphics/Vulkan/Texture.cpp b/src/Engine/Graphics/Vulkan/Texture.cpp index 23488c3..2a4527c 100644 --- a/src/Engine/Graphics/Vulkan/Texture.cpp +++ b/src/Engine/Graphics/Vulkan/Texture.cpp @@ -29,10 +29,10 @@ VkImageAspectFlags getAspectFromFormat(Gfx::SeFormat format) { } TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType, const TextureCreateInfo& createInfo, VkImage existingImage) - : CommandBoundResource(graphics, createInfo.name), image(existingImage), width(createInfo.width), height(createInfo.height), - depth(createInfo.depth), arrayCount(createInfo.elements), mipLevels(1), layerCount(createInfo.layers), samples(createInfo.samples), - format(createInfo.format), usage(createInfo.usage), layout(Gfx::SE_IMAGE_LAYOUT_UNDEFINED), - aspect(getAspectFromFormat(createInfo.format)), ownsImage(false), owner(createInfo.sourceData.owner) { + : CommandBoundResource(graphics, createInfo.name), image(existingImage), owner(createInfo.sourceData.owner), width(createInfo.width), + height(createInfo.height), depth(createInfo.depth), arrayCount(createInfo.elements), layerCount(createInfo.layers), mipLevels(1), + samples(createInfo.samples), format(createInfo.format), usage(createInfo.usage), + layout(Gfx::SE_IMAGE_LAYOUT_UNDEFINED), aspect(getAspectFromFormat(createInfo.format)), ownsImage(false) { if (createInfo.useMip) { mipLevels = static_cast(std::floor(std::log2(std::max(width, height)))) + 1; } diff --git a/src/Engine/Material/Material.cpp b/src/Engine/Material/Material.cpp index 92c1b7a..0fa49dd 100644 --- a/src/Engine/Material/Material.cpp +++ b/src/Engine/Material/Material.cpp @@ -22,9 +22,9 @@ Material::Material() {} Material::Material(Gfx::PGraphics graphics, uint32 numTextures, uint32 numSamplers, uint32 numFloats, bool twoSided, float opacity, std::string materialName, Array expressions, Array parameter, MaterialNode brdf) - : graphics(graphics), numTextures(numTextures), numSamplers(numSamplers), numFloats(numFloats), twoSided(twoSided), opacity(opacity), - instanceId(0), materialName(materialName), codeExpressions(std::move(expressions)), parameters(std::move(parameter)), - brdf(std::move(brdf)), materialId(materialIdCounter++) { + : graphics(graphics), numTextures(numTextures), numSamplers(numSamplers), numFloats(numFloats), instanceId(0), materialId(materialIdCounter++), + materialName(materialName), twoSided(twoSided), opacity(opacity), codeExpressions(std::move(expressions)), + parameters(std::move(parameter)), brdf(std::move(brdf)) { if (layout == nullptr) { init(graphics); } @@ -38,14 +38,14 @@ void Material::init(Gfx::PGraphics graphics) { layout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, - .descriptorCount = 2000, + .descriptorCount = 512, .bindingFlags = Gfx::SE_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT, .shaderStages = Gfx::SE_SHADER_STAGE_FRAGMENT_BIT | Gfx::SE_SHADER_STAGE_CLOSEST_HIT_BIT_KHR, }); layout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER, - .descriptorCount = 2000, + .descriptorCount = 512, .bindingFlags = Gfx::SE_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT, .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 textureOffset = textures.size(); textures.resize(textures.size() + numTextures); + assert(textures.size() < 512); return textureOffset; } uint32 Material::addSamplers(uint32 numSamplers) { uint32 samplerOffset = samplers.size(); samplers.resize(samplers.size() + numSamplers); + assert(textures.size() < 512); return samplerOffset; } diff --git a/src/Engine/Material/ShaderExpression.h b/src/Engine/Material/ShaderExpression.h index bcfdae4..4dc81bf 100644 --- a/src/Engine/Material/ShaderExpression.h +++ b/src/Engine/Material/ShaderExpression.h @@ -54,7 +54,7 @@ struct ShaderParameter : public ShaderExpression { virtual uint64 getIdentifier() const override = 0; virtual uint64 getCPUSize() const override = 0; virtual uint64 getGPUSize() const override = 0; - virtual std::string evaluate(Map& varState) const = 0; + virtual std::string evaluate(Map& varState) const override = 0; virtual void save(ArchiveBuffer& buffer) const 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 std::string evaluate(Map& varState) const override; virtual uint64 getIdentifier() const override { return IDENTIFIER; } - virtual uint64 getCPUSize() const { return sizeof(FloatParameter); } - virtual uint64 getGPUSize() const { return sizeof(float); } + virtual uint64 getCPUSize() const override { return sizeof(FloatParameter); } + virtual uint64 getGPUSize() const override { return sizeof(float); } virtual void save(ArchiveBuffer& buffer) const 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 std::string evaluate(Map& varState) const override; virtual uint64 getIdentifier() const override { return IDENTIFIER; } - virtual uint64 getCPUSize() const { return sizeof(VectorParameter); } - virtual uint64 getGPUSize() const { return sizeof(Vector); } + virtual uint64 getCPUSize() const override { return sizeof(VectorParameter); } + virtual uint64 getGPUSize() const override { return sizeof(Vector); } virtual void save(ArchiveBuffer& buffer) const 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 std::string evaluate(Map& varState) const override; virtual uint64 getIdentifier() const override { return IDENTIFIER; } - virtual uint64 getCPUSize() const { return sizeof(TextureParameter); } - virtual uint64 getGPUSize() const { return sizeof(void*); } // TODO: technically this is just a ref, but idk + virtual uint64 getCPUSize() const override { return sizeof(TextureParameter); } + 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 load(ArchiveBuffer& buffer) override; }; @@ -114,8 +114,8 @@ struct SamplerParameter : public ShaderParameter { virtual void updateDescriptorSet(uint32 textureOffset, uint32 samplerOffset, uint32 floatOffset) override; virtual std::string evaluate(Map& varState) const override; virtual uint64 getIdentifier() const override { return IDENTIFIER; } - virtual uint64 getCPUSize() const { return sizeof(SamplerParameter); } - virtual uint64 getGPUSize() const { return sizeof(void*); } + virtual uint64 getCPUSize() const override { return sizeof(SamplerParameter); } + virtual uint64 getGPUSize() const override { return sizeof(void*); } virtual void save(ArchiveBuffer& buffer) const 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 std::string evaluate(Map& varState) const override; virtual uint64 getIdentifier() const override { return IDENTIFIER; } - virtual uint64 getCPUSize() const { return sizeof(CombinedTextureParameter); } - virtual uint64 getGPUSize() const { return sizeof(void*); } + virtual uint64 getCPUSize() const override { return sizeof(CombinedTextureParameter); } + virtual uint64 getGPUSize() const override { return sizeof(void*); } virtual void save(ArchiveBuffer& buffer) const override; virtual void load(ArchiveBuffer& buffer) override; };