diff --git a/CMakeLists.txt b/CMakeLists.txt index 932244d..f1e4683 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ set(METAL_ROOT ${EXTERNAL_ROOT}/metal-cpp) if(WIN32) set(VCPKG_BASE_FOLDER ${VCPKG_INSTALLED_DIR}/x64-windows/) elseif(APPLE) - set(VCPKG_BASE_FOLDER ${VCPKG_INSTALLED_DIR}/arm64-osx/) + set(VCPKG_BASE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/build/vcpkg_installed/arm64-osx/) endif() set(Boost_NO_WARN_NEW_VERSIONS 1) diff --git a/res/shaders/LightCulling.slang b/res/shaders/LightCulling.slang index 541847d..5c832c2 100644 --- a/res/shaders/LightCulling.slang +++ b/res/shaders/LightCulling.slang @@ -89,7 +89,7 @@ void cullLights(ComputeShaderInput in) float maxDepthWS = clipToWorld(float4(0, 0, fMaxDepth, 1)).z; float nearClipWS = clipToWorld(float4(0, 0, 0, 1)).z; - Plane maxPlane = {float3(0, 0, -1), -maxDepthWS}; + Plane maxPlane = {float4(0, 0, -1, -maxDepthWS)}; for ( uint i = in.groupIndex; i < pLightEnv.numPointLights; i += BLOCK_SIZE * BLOCK_SIZE ) { diff --git a/res/shaders/lib/Bounding.slang b/res/shaders/lib/Bounding.slang index b849cc3..19ab0b3 100644 --- a/res/shaders/lib/Bounding.slang +++ b/res/shaders/lib/Bounding.slang @@ -16,7 +16,7 @@ struct BoundingSphere bool result = true; for(int i = 0; i < 4 && result; ++i) { - if(dot(frustum.sides[i].n, getCenter()) - frustum.sides[i].d < -getRadius()) + if(dot(frustum.sides[i].getNormal(), getCenter()) - frustum.sides[i].getDistance() < -getRadius()) { result = false; } @@ -39,11 +39,11 @@ struct AABB bool result = true; for(int i = 0; i < 4 && result; ++i) { - const float r = extents.x * abs(frustum.sides[i].n.x) - + extents.y * abs(frustum.sides[i].n.y) - + extents.z * abs(frustum.sides[i].n.z); + const float r = extents.x * abs(frustum.sides[i].getNormal().x) + + extents.y * abs(frustum.sides[i].getNormal().y) + + extents.z * abs(frustum.sides[i].getNormal().z); - const float signedDistance = dot(frustum.sides[i].n, center) - frustum.sides[i].d; + const float signedDistance = dot(frustum.sides[i].getNormal(), center) - frustum.sides[i].getDistance(); if(signedDistance < -r) { result = false; diff --git a/res/shaders/lib/Common.slang b/res/shaders/lib/Common.slang index 2ff14ea..f94c0f3 100644 --- a/res/shaders/lib/Common.slang +++ b/res/shaders/lib/Common.slang @@ -101,11 +101,18 @@ float4 clipToScreen(float4 clip) struct Plane { - float3 n; - float d; + float4 nd; + float3 getNormal() + { + return nd.xyz; + } + float getDistance() + { + return nd.w; + } bool pointInside(float3 point) { - return dot(n, point) - d > 0.0f; + return dot(getNormal(), point) - getDistance() > 0.0f; } }; @@ -131,9 +138,11 @@ Plane computePlane(float3 p0, float3 p1, float3 p2) float3 v0 = p1 - p0; float3 v2 = p2 - p0; - plane.n = normalize(cross(v0, v2)); + float3 n = normalize(cross(v0, v2)); - plane.d = dot(plane.n, p0); + float d = dot(n, p0); + + plane.nd = float4(n, d); return plane; } diff --git a/res/shaders/lib/DispatchParams.slang b/res/shaders/lib/DispatchParams.slang index 8b3707b..67aa603 100644 --- a/res/shaders/lib/DispatchParams.slang +++ b/res/shaders/lib/DispatchParams.slang @@ -2,10 +2,8 @@ import Common; struct DispatchParams { - uint3 numThreadGroups; - uint pad0; - uint3 numThreads; - uint pad1; + uint4 numThreadGroups; + uint4 numThreads; RWStructuredBuffer frustums; }; diff --git a/res/shaders/lib/LightEnv.slang b/res/shaders/lib/LightEnv.slang index eaf6711..58e3770 100644 --- a/res/shaders/lib/LightEnv.slang +++ b/res/shaders/lib/LightEnv.slang @@ -34,7 +34,7 @@ struct PointLight : ILightEnv bool insidePlane(Plane plane, float3 position) { - return dot(plane.n, position) - plane.d < -colorRange.w; + return dot(plane.getNormal(), position) - plane.getDistance() < -colorRange.w; } bool insideFrustum(Frustum frustum, float3 position, float minDepth, float maxDepth) diff --git a/src/Editor/main.cpp b/src/Editor/main.cpp index 8f1777a..b795747 100644 --- a/src/Editor/main.cpp +++ b/src/Editor/main.cpp @@ -116,18 +116,18 @@ int main() { // .filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb", // .importPath = "Whitechapel", //}); - AssetImporter::importMesh(MeshImportArgs{ - .filePath = sourcePath / "import/models/box.glb", - .importPath = "", - }); - AssetImporter::importMesh(MeshImportArgs{ - .filePath = sourcePath / "import/models/rttest.glb", - .importPath = "", - }); - AssetImporter::importMesh(MeshImportArgs{ - .filePath = sourcePath / "import/models/town_hall.glb", - .importPath = "", - }); + //AssetImporter::importMesh(MeshImportArgs{ + // .filePath = sourcePath / "import/models/box.glb", + // .importPath = "", + //}); + //AssetImporter::importMesh(MeshImportArgs{ + // .filePath = sourcePath / "import/models/rttest.glb", + // .importPath = "", + //}); + //AssetImporter::importMesh(MeshImportArgs{ + // .filePath = sourcePath / "import/models/town_hall.glb", + // .importPath = "", + //}); getThreadPool().waitIdle(); vd->commitMeshes(); WindowCreateInfo mainWindowInfo = { diff --git a/src/Engine/Containers/Array.h b/src/Engine/Containers/Array.h index cd9d19a..97224c6 100644 --- a/src/Engine/Containers/Array.h +++ b/src/Engine/Containers/Array.h @@ -299,6 +299,7 @@ template > s constexpr void remove(value_type&& element, bool keepOrder = true) { erase(find(element), keepOrder); } constexpr void erase(iterator it, bool keepOrder = true) { removeAt(it - begin(), keepOrder); } constexpr void erase(const_iterator it, bool keepOrder = true) { removeAt(it - cbegin(), keepOrder); } + constexpr bool contains(const T& value) const { return find(value) != end(); } constexpr void removeAt(size_type index, bool keepOrder = true) { if (keepOrder) { for (size_type i = index; i < arraySize - 1; ++i) { @@ -385,7 +386,7 @@ template > s assert(result != nullptr); return result; } - void deallocateArray(T* ptr, size_type size) { allocator.deallocate(ptr, size); } + void deallocateArray(T* ptr, size_type size) { if(ptr == nullptr) return; allocator.deallocate(ptr, size); } template T& addInternal(Type&& t) noexcept { if (arraySize == allocated) { size_type newSize = arraySize + 1; diff --git a/src/Engine/Containers/List.h b/src/Engine/Containers/List.h index 161191e..0d1dfc6 100644 --- a/src/Engine/Containers/List.h +++ b/src/Engine/Containers/List.h @@ -280,7 +280,7 @@ template > c std::allocator_traits::construct(allocator, node, node->prev, node->next, std::forward(data)); } constexpr void destroyNode(Node* node) { std::allocator_traits::destroy(allocator, node); } - constexpr void deallocateNode(Node* node) { allocator.deallocate(node, 1); } + constexpr void deallocateNode(Node* node) { if(node == nullptr) return; allocator.deallocate(node, 1); } template constexpr iterator addInternal(ValueType&& value) { initializeNode(tail, std::forward(value)); Node* newTail = allocateNode(); @@ -308,4 +308,4 @@ template > c const_iterator cendIt; size_type _size; }; -} // namespace Seele \ No newline at end of file +} // namespace Seele diff --git a/src/Engine/Containers/Tree.h b/src/Engine/Containers/Tree.h index 27d4111..5daf90a 100644 --- a/src/Engine/Containers/Tree.h +++ b/src/Engine/Containers/Tree.h @@ -1,5 +1,6 @@ #pragma once #include "Pair.h" +#include "Array.h" #include @@ -226,13 +227,13 @@ template commands) = 0; virtual void executeCommands(OComputeCommand commands) = 0; virtual void executeCommands(Array commands) = 0; diff --git a/src/Engine/Graphics/Metal/Buffer.h b/src/Engine/Graphics/Metal/Buffer.h index e4dd91f..06998e4 100644 --- a/src/Engine/Graphics/Metal/Buffer.h +++ b/src/Engine/Graphics/Metal/Buffer.h @@ -96,8 +96,7 @@ class UniformBuffer : public Gfx::UniformBuffer { virtual ~UniformBuffer(); virtual void updateContents(uint64 offset, uint64 size, void* data) override; virtual void rotateBuffer(uint64 size) override; - void* getContents() const { return contents.data(); } - size_t getSize() const { return contents.size(); } + Array getContents() const { return contents; } protected: // Inherited via QueueOwnedResource diff --git a/src/Engine/Graphics/Metal/Command.mm b/src/Engine/Graphics/Metal/Command.mm index 64653bb..cb1e0fb 100644 --- a/src/Engine/Graphics/Metal/Command.mm +++ b/src/Engine/Graphics/Metal/Command.mm @@ -3,12 +3,14 @@ #include "Containers/Array.h" #include "Descriptor.h" #include "Enums.h" -#include "Graphics/Graphics.h" #include "Graphics/Command.h" #include "Graphics/Enums.h" #include "Graphics/Graphics.h" #include "Graphics/Resources.h" +#include "Metal/MTLArgumentEncoder.hpp" #include "Metal/MTLCaptureManager.hpp" +#include "Metal/MTLLibrary.hpp" +#include "Metal/MTLRenderCommandEncoder.hpp" #include "Pipeline.h" #include "Resources.h" #include "Window.h" @@ -40,8 +42,7 @@ void Command::present(MTL::Drawable* drawable) { cmdBuffer->presentDrawable(draw void Command::end(PEvent signal) { assert(!parallelEncoder); - if(blitEncoder) - { + if (blitEncoder) { blitEncoder->endEncoding(); } if (signal != nullptr) { @@ -51,9 +52,7 @@ void Command::end(PEvent signal) { cmdBuffer->commit(); } -void Command::waitDeviceIdle() { - cmdBuffer->waitUntilCompleted(); -} +void Command::waitDeviceIdle() { cmdBuffer->waitUntilCompleted(); } void Command::signalEvent(PEvent event) { cmdBuffer->encodeSignalEvent(event->getHandle(), 1); } @@ -80,7 +79,7 @@ void RenderCommand::setViewport(Gfx::PViewport viewport) { void RenderCommand::bindPipeline(Gfx::PGraphicsPipeline pipeline) { boundPipeline = pipeline.cast(); encoder->setRenderPipelineState(boundPipeline->getHandle()); - if(boundPipeline->getPipelineLayout()->hasPushConstants()) { + if (boundPipeline->getPipelineLayout()->hasPushConstants()) { constantsBuffer = boundPipeline->graphics->getDevice()->newBuffer(boundPipeline->getPipelineLayout()->getPushConstantsSize(), 0); } } @@ -91,10 +90,46 @@ void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet) { auto metalSet = descriptorSet.cast(); metalSet->bind(); uint32 descriptorIndex = boundPipeline->getPipelineLayout()->findParameter(metalSet->getLayout()->getName()); - encoder->setVertexBuffer(metalSet->getArgumentBuffer(), 0, descriptorIndex); - encoder->setFragmentBuffer(metalSet->getArgumentBuffer(), 0, descriptorIndex); - encoder->setObjectBuffer(metalSet->getArgumentBuffer(), 0, descriptorIndex); - encoder->setMeshBuffer(metalSet->getArgumentBuffer(), 0, descriptorIndex); + + auto createEncoder = [&metalSet, descriptorIndex](MTL::Function* function, const Array& usedSets) { + if(metalSet->encoder == nullptr) { + if (metalSet->isPlainDescriptor()) { + metalSet->encoder = metalSet->createEncoder(); + } else if (function != nullptr && usedSets.contains(descriptorIndex)) { + metalSet->encoder = function->newArgumentEncoder(descriptorIndex); + } + } + }; + createEncoder(boundPipeline->taskFunction, boundPipeline->taskSets); + createEncoder(boundPipeline->meshFunction, boundPipeline->meshSets); + createEncoder(boundPipeline->vertexFunction, boundPipeline->vertexSets); + createEncoder(boundPipeline->fragmentFunction, boundPipeline->fragmentSets); + if(metalSet->argumentBuffer == nullptr) { + metalSet->argumentBuffer = metalSet->graphics->getDevice()->newBuffer(metalSet->encoder->encodedLength(), MTL::ResourceOptionCPUCacheModeDefault); + metalSet->encoder->setArgumentBuffer(metalSet->argumentBuffer, 0); + } + for (const auto& write : metalSet->uniformWrites) { + write.apply(metalSet->encoder); + } + for (const auto& write : metalSet->bufferWrites) { + write.apply(metalSet->encoder); + } + + for (const auto& write : metalSet->samplerWrites) { + write.apply(metalSet->encoder); + } + + for (const auto& write : metalSet->textureWrites) { + write.apply(metalSet->encoder); + } + + for (const auto& write : metalSet->accelerationWrites) { + write.apply(metalSet->encoder); + } + encoder->setObjectBuffer(metalSet->argumentBuffer, 0, descriptorIndex); + encoder->setMeshBuffer(metalSet->argumentBuffer, 0, descriptorIndex); + encoder->setVertexBuffer(metalSet->argumentBuffer, 0, descriptorIndex); + encoder->setFragmentBuffer(metalSet->argumentBuffer, 0, descriptorIndex); } void RenderCommand::bindDescriptor(const Array& descriptorSets) { @@ -163,7 +198,7 @@ void ComputeCommand::end() { void ComputeCommand::bindPipeline(Gfx::PComputePipeline pipeline) { boundPipeline = pipeline.cast(); encoder->setComputePipelineState(boundPipeline->getHandle()); - if(boundPipeline->getPipelineLayout()->hasPushConstants()) { + if (boundPipeline->getPipelineLayout()->hasPushConstants()) { constantsBuffer = boundPipeline->graphics->getDevice()->newBuffer(boundPipeline->getPipelineLayout()->getPushConstantsSize(), 0); } } @@ -172,7 +207,34 @@ void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set) { auto metalSet = set.cast(); metalSet->bind(); uint32 descriptorIndex = boundPipeline->getPipelineLayout()->findParameter(metalSet->getLayout()->getName()); - encoder->setBuffer(metalSet->getArgumentBuffer(), 0, descriptorIndex); + if(metalSet->encoder == nullptr) { + if (metalSet->isPlainDescriptor()) { + metalSet->encoder = metalSet->createEncoder(); + } else { + metalSet->encoder = boundPipeline->computeFunction->newArgumentEncoder(descriptorIndex); + } + metalSet->argumentBuffer = metalSet->graphics->getDevice()->newBuffer(metalSet->encoder->encodedLength(), MTL::ResourceOptionCPUCacheModeDefault); + metalSet->encoder->setArgumentBuffer(metalSet->argumentBuffer, 0); + } + for (const auto& write : metalSet->uniformWrites) { + write.apply(metalSet->encoder); + } + for (const auto& write : metalSet->bufferWrites) { + write.apply(metalSet->encoder); + } + + for (const auto& write : metalSet->samplerWrites) { + write.apply(metalSet->encoder); + } + + for (const auto& write : metalSet->textureWrites) { + write.apply(metalSet->encoder); + } + + for (const auto& write : metalSet->accelerationWrites) { + write.apply(metalSet->encoder); + } + encoder->setBuffer(metalSet->argumentBuffer, 0, descriptorIndex); } void ComputeCommand::bindDescriptor(const Array& sets) { @@ -192,7 +254,7 @@ void ComputeCommand::dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) { encoder->dispatchThreadgroups(MTL::Size(threadX, threadY, threadZ), MTL::Size(32, 32, 1)); } -void ComputeCommand::dispatchIndirect(Gfx::PShaderBuffer buffer, uint32 offset){ +void ComputeCommand::dispatchIndirect(Gfx::PShaderBuffer buffer, uint32 offset) { encoder->dispatchThreadgroups(buffer.cast()->getHandle(), offset, MTL::Size(32, 32, 1)); } @@ -240,14 +302,11 @@ void CommandQueue::submitCommands(PEvent signalSemaphore) { activeCommand->waitDeviceIdle(); PEvent prevCmdEvent = activeCommand->getCompletedEvent(); pendingCommands.add(std::move(activeCommand)); - if(!readyCommands.empty()) - { + if (!readyCommands.empty()) { activeCommand = std::move(readyCommands.front()); readyCommands.removeAt(0); activeCommand->waitForEvent(prevCmdEvent); - } - else - { + } else { MTL::CommandBufferDescriptor* descriptor = MTL::CommandBufferDescriptor::alloc()->init(); descriptor->setErrorOptions(MTL::CommandBufferErrorOptionEncoderExecutionStatus); activeCommand = new Command(graphics, queue->commandBuffer(descriptor)); diff --git a/src/Engine/Graphics/Metal/Descriptor.h b/src/Engine/Graphics/Metal/Descriptor.h index 6bf4de9..c84776d 100644 --- a/src/Engine/Graphics/Metal/Descriptor.h +++ b/src/Engine/Graphics/Metal/Descriptor.h @@ -4,7 +4,9 @@ #include "Foundation/NSObject.hpp" #include "Graphics/Descriptor.h" #include "Graphics/Initializer.h" +#include "Graphics/Metal/Command.h" #include "Graphics/Metal/Resources.h" +#include "Metal/MTLAccelerationStructure.hpp" #include "Metal/MTLArgumentEncoder.hpp" #include "Metal/MTLLibrary.hpp" #include "Metal/MTLResource.hpp" @@ -21,6 +23,7 @@ class DescriptorLayout : public Gfx::DescriptorLayout { MTL::ArgumentEncoder* createEncoder(); uint32 getFlattenedIndex(uint32 binding, uint32 arrayIndex) const { return flattenMap.at(flattenIndex(binding, arrayIndex)); } constexpr uint32 getTotalBindingCount() const { return flattenedBindingCount; } + constexpr bool isPlainDescriptor() const { return plainDescriptor; } private: constexpr uint64 flattenIndex(uint32 binding, uint32 arrayIndex) const { return uint64(arrayIndex) << 32 | binding; } @@ -28,6 +31,9 @@ class DescriptorLayout : public Gfx::DescriptorLayout { NS::Array* arguments; Map flattenMap; uint32 flattenedBindingCount = 0; + // descriptor sets containing only uniform data are not actually argument buffers, so they need to be + // handled separately + bool plainDescriptor = true; }; DEFINE_REF(DescriptorLayout) @@ -62,15 +68,54 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource { virtual void updateAccelerationStructure(uint32 binding, uint32 index, Gfx::PTopLevelAS as) override; constexpr const Array& getBoundResources() const { return boundResources; } - - MTL::Buffer* getArgumentBuffer() const { return argumentBuffer; } + constexpr bool isPlainDescriptor() const { return owner->getLayout()->isPlainDescriptor(); } + constexpr MTL::ArgumentEncoder* createEncoder() const { return owner->getLayout()->createEncoder(); } private: PGraphics graphics; PDescriptorPool owner; Array boundResources; - MTL::ArgumentEncoder* encoder; MTL::Buffer* argumentBuffer = nullptr; + MTL::ArgumentEncoder* encoder = nullptr; + + struct UniformWriteInfo + { + uint32 index; + Array content; + void apply(MTL::ArgumentEncoder* encoder) const { std::memcpy(encoder->constantData(index), content.data(), content.size()); } + }; + Array uniformWrites; + struct BufferWriteInfo + { + uint32 index; + MTL::Buffer* buffer; + void apply(MTL::ArgumentEncoder* encoder) const { encoder->setBuffer(buffer, 0, 2); } + }; + Array bufferWrites; + struct TextureWriteInfo + { + uint32 index; + MTL::Texture* texture; + void apply(MTL::ArgumentEncoder* encoder) const { encoder->setTexture(texture, index); } + }; + Array textureWrites; + struct SamplerWriteInfo + { + uint32 index; + MTL::SamplerState* sampler; + void apply(MTL::ArgumentEncoder* encoder) const { encoder->setSamplerState(sampler, index); } + }; + Array samplerWrites; + struct AccelerationStructureWriteInfo + { + uint32 index; + MTL::AccelerationStructure* accelerationStructure; + void apply(MTL::ArgumentEncoder* encoder) const { encoder->setAccelerationStructure(accelerationStructure, index); } + }; + Array accelerationWrites; + + friend class RenderCommand; + friend class ComputeCommand; }; DEFINE_REF(DescriptorSet) diff --git a/src/Engine/Graphics/Metal/Descriptor.mm b/src/Engine/Graphics/Metal/Descriptor.mm index bfc6931..085346c 100644 --- a/src/Engine/Graphics/Metal/Descriptor.mm +++ b/src/Engine/Graphics/Metal/Descriptor.mm @@ -34,65 +34,16 @@ void DescriptorLayout::create() { MTL::ArgumentDescriptor** objects = new MTL::ArgumentDescriptor*[descriptorBindings.size()]; flattenedBindingCount = 0; for (uint32 i = 0; i < descriptorBindings.size(); ++i) { - objects[i] = MTL::ArgumentDescriptor::alloc()->init(); - objects[i]->setIndex(flattenedBindingCount); - objects[i]->setAccess(cast(descriptorBindings[i].access)); - objects[i]->setArrayLength(descriptorBindings[i].descriptorCount); - MTL::DataType dataType; - switch (descriptorBindings[i].descriptorType) { - case Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE: - case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE: - case Gfx::SE_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: - case Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: - case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: - case Gfx::SE_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: - dataType = MTL::DataTypeTexture; - break; - case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER: - case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: - dataType = MTL::DataTypePointer; - break; - case Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER: - case Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: - case Gfx::SE_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK: - dataType = MTL::DataTypeChar; + if(descriptorBindings[i].descriptorType != Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER) { + plainDescriptor = false; + } else { + objects[i] = MTL::ArgumentDescriptor::alloc()->init(); + objects[i]->setIndex(flattenedBindingCount); + objects[i]->setAccess(cast(descriptorBindings[i].access)); + objects[i]->setArrayLength(descriptorBindings[i].descriptorCount); + objects[i]->setDataType(MTL::DataTypeChar); objects[i]->setArrayLength(descriptorBindings[i].uniformLength); - break; - case Gfx::SE_DESCRIPTOR_TYPE_SAMPLER: - dataType = MTL::DataTypeSampler; - break; - case Gfx::SE_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR: - dataType = MTL::DataTypeInstanceAccelerationStructure; - break; - default: - throw new std::logic_error("unknown descriptor type"); } - objects[i]->setDataType(dataType); - MTL::TextureType textureType; - switch (descriptorBindings[i].textureType) { - case Gfx::SE_IMAGE_VIEW_TYPE_1D: - textureType = MTL::TextureType1D; - break; - case Gfx::SE_IMAGE_VIEW_TYPE_2D: - textureType = MTL::TextureType2D; - break; - case Gfx::SE_IMAGE_VIEW_TYPE_3D: - textureType = MTL::TextureType3D; - break; - case Gfx::SE_IMAGE_VIEW_TYPE_CUBE: - textureType = MTL::TextureTypeCube; - break; - case Gfx::SE_IMAGE_VIEW_TYPE_1D_ARRAY: - textureType = MTL::TextureType1DArray; - break; - case Gfx::SE_IMAGE_VIEW_TYPE_2D_ARRAY: - textureType = MTL::TextureType2DArray; - break; - case Gfx::SE_IMAGE_VIEW_TYPE_CUBE_ARRAY: - textureType = MTL::TextureTypeCubeArray; - break; - } - objects[i]->setTextureType(textureType); for(uint32 j = 0; j < descriptorBindings[i].descriptorCount; ++j) { flattenMap[flattenIndex(i, j)] = flattenedBindingCount++; } @@ -124,10 +75,6 @@ void DescriptorPool::reset() {} DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner) : Gfx::DescriptorSet(owner->getLayout()), CommandBoundResource(graphics), graphics(graphics), owner(owner) { - encoder = owner->getLayout()->createEncoder(); - argumentBuffer = graphics->getDevice()->newBuffer(encoder->encodedLength(), 0); - std::cout << owner->getLayout()->getName() << ": " << encoder->encodedLength() << std::endl; - encoder->setArgumentBuffer(argumentBuffer, 0); boundResources.resize(owner->getLayout()->getTotalBindingCount()); } @@ -138,56 +85,82 @@ void DescriptorSet::writeChanges() {} void DescriptorSet::updateBuffer(uint32 binding, uint32 index, Gfx::PUniformBuffer uniformBuffer) { uint32 flattenedIndex = owner->getLayout()->getFlattenedIndex(binding, index); PUniformBuffer buffer = uniformBuffer.cast(); - std::memcpy(encoder->constantData(flattenedIndex), buffer->getContents(), buffer->getSize()); boundResources[flattenedIndex] = nullptr; + uniformWrites.add(UniformWriteInfo{ + .index = flattenedIndex, + .content = buffer->getContents(), + }); } void DescriptorSet::updateBuffer(uint32 binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) { uint32 flattenedIndex = owner->getLayout()->getFlattenedIndex(binding, index); PShaderBuffer buffer = uniformBuffer.cast(); - encoder->setBuffer(buffer->getHandle(), 0, flattenedIndex); boundResources[flattenedIndex] = buffer->getHandle(); + bufferWrites.add(BufferWriteInfo{ + .index = flattenedIndex, + .buffer = buffer->getHandle(), + }); } void DescriptorSet::updateBuffer(uint32 binding, uint32 index, Gfx::PVertexBuffer uniformBuffer) { uint32 flattenedIndex = owner->getLayout()->getFlattenedIndex(binding, index); PVertexBuffer buffer = uniformBuffer.cast(); - encoder->setBuffer(buffer->getHandle(), 0, flattenedIndex); boundResources[flattenedIndex] = buffer->getHandle(); + bufferWrites.add(BufferWriteInfo{ + .index = flattenedIndex, + .buffer = buffer->getHandle(), + }); } + void DescriptorSet::updateBuffer(uint32 binding, uint32 index, Gfx::PIndexBuffer uniformBuffer) { uint32 flattenedIndex = owner->getLayout()->getFlattenedIndex(binding, index); PIndexBuffer buffer = uniformBuffer.cast(); - encoder->setBuffer(buffer->getHandle(), 0, flattenedIndex); boundResources[flattenedIndex] = buffer->getHandle(); + bufferWrites.add(BufferWriteInfo{ + .index = flattenedIndex, + .buffer = buffer->getHandle(), + }); } void DescriptorSet::updateSampler(uint32 binding, uint32 index, Gfx::PSampler samplerState) { uint32 flattenedIndex = owner->getLayout()->getFlattenedIndex(binding, index); PSampler sampler = samplerState.cast(); - encoder->setSamplerState(sampler->getHandle(), flattenedIndex); + boundResources[flattenedIndex] = nullptr; + samplerWrites.add(SamplerWriteInfo{ + .index = flattenedIndex, + .sampler = sampler->getHandle(), + }); boundResources[flattenedIndex] = nullptr; // Samplers are not resources?????? } void DescriptorSet::updateTexture(uint32 binding, uint32 index, Gfx::PTexture2D texture) { uint32 flattenedIndex = owner->getLayout()->getFlattenedIndex(binding, index); PTextureBase tex = texture.cast(); - encoder->setTexture(tex->getImage(), flattenedIndex); boundResources[flattenedIndex] = tex->getImage(); + textureWrites.add(TextureWriteInfo{ + .index = flattenedIndex, + .texture = tex->getImage(), + }); } void DescriptorSet::updateTexture(uint32 binding, uint32 index, Gfx::PTexture3D texture) { uint32 flattenedIndex = owner->getLayout()->getFlattenedIndex(binding, index); PTextureBase tex = texture.cast(); - encoder->setTexture(tex->getImage(), flattenedIndex); boundResources[flattenedIndex] = tex->getImage(); + textureWrites.add(TextureWriteInfo{ + .index = flattenedIndex, + .texture = tex->getImage(), + }); } void DescriptorSet::updateTexture(uint32 binding, uint32 index, Gfx::PTextureCube texture) { uint32 flattenedIndex = owner->getLayout()->getFlattenedIndex(binding, index); PTextureBase tex = texture.cast(); - encoder->setTexture(tex->getImage(), flattenedIndex); boundResources[flattenedIndex] = tex->getImage(); + textureWrites.add(TextureWriteInfo{ + .index = flattenedIndex, + .texture = tex->getImage(), + }); } void DescriptorSet::updateAccelerationStructure(uint32 binding, uint32 index, Gfx::PTopLevelAS as) { assert(false && "TODO"); } diff --git a/src/Engine/Graphics/Metal/Graphics.h b/src/Engine/Graphics/Metal/Graphics.h index fec5363..2f9f8c6 100644 --- a/src/Engine/Graphics/Metal/Graphics.h +++ b/src/Engine/Graphics/Metal/Graphics.h @@ -22,6 +22,7 @@ class Graphics : public Gfx::Graphics { virtual void endRenderPass() override; virtual void waitDeviceIdle() override; + virtual void executeCommands(Gfx::ORenderCommand commands) override; virtual void executeCommands(Array commands) override; virtual void executeCommands(Gfx::OComputeCommand commands) override; virtual void executeCommands(Array commands) override; diff --git a/src/Engine/Graphics/Metal/Graphics.mm b/src/Engine/Graphics/Metal/Graphics.mm index 3ad10c2..f60bd6c 100644 --- a/src/Engine/Graphics/Metal/Graphics.mm +++ b/src/Engine/Graphics/Metal/Graphics.mm @@ -50,6 +50,12 @@ void Graphics::waitDeviceIdle() { queue->submitCommands(); } +void Graphics::executeCommands(Gfx::ORenderCommand 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(Gfx::OComputeCommand commands) { diff --git a/src/Engine/Graphics/Metal/Pipeline.h b/src/Engine/Graphics/Metal/Pipeline.h index b778a36..dbc01ca 100644 --- a/src/Engine/Graphics/Metal/Pipeline.h +++ b/src/Engine/Graphics/Metal/Pipeline.h @@ -22,6 +22,14 @@ class GraphicsPipeline : public Gfx::GraphicsPipeline { PGraphics graphics; MTL::RenderPipelineState* state; MTL::PrimitiveType primitiveType; + MTL::Function* taskFunction = nullptr; + Array taskSets; + MTL::Function* meshFunction = nullptr; + Array meshSets; + MTL::Function* vertexFunction = nullptr; + Array vertexSets; + MTL::Function* fragmentFunction = nullptr; + Array fragmentSets; private: }; @@ -33,6 +41,7 @@ class ComputePipeline : public Gfx::ComputePipeline { constexpr MTL::ComputePipelineState* getHandle() const { return state; } PGraphics graphics; + MTL::Function* computeFunction; private: MTL::ComputePipelineState* state; diff --git a/src/Engine/Graphics/Metal/PipelineCache.mm b/src/Engine/Graphics/Metal/PipelineCache.mm index be074de..2b8c949 100644 --- a/src/Engine/Graphics/Metal/PipelineCache.mm +++ b/src/Engine/Graphics/Metal/PipelineCache.mm @@ -1,6 +1,7 @@ #include "PipelineCache.h" #include "Descriptor.h" #include "Enums.h" +#include "Metal/MTLLibrary.hpp" #include "RenderPass.h" #include "Foundation/NSError.hpp" #include "Foundation/NSString.hpp" @@ -62,10 +63,17 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo cr } } pipelineDescriptor->setVertexDescriptor(vertexDescriptor); - - pipelineDescriptor->setVertexFunction(createInfo.vertexShader.cast()->getFunction()); + auto vertShader = createInfo.vertexShader.cast(); + Array vertexSets = vertShader->usedDescriptors; + MTL::Function* vertexFunction = vertShader->getFunction(); + Array fragmentSets; + MTL::Function* fragmentFunction = nullptr; + pipelineDescriptor->setVertexFunction(vertexFunction); if (createInfo.fragmentShader != nullptr) { - pipelineDescriptor->setFragmentFunction(createInfo.fragmentShader.cast()->getFunction()); + auto fragShader = createInfo.fragmentShader.cast(); + fragmentSets = fragShader->usedDescriptors; + fragmentFunction = fragShader->getFunction(); + pipelineDescriptor->setFragmentFunction(fragmentFunction); } pipelineDescriptor->setInputPrimitiveTopology(cast(createInfo.topology)); for(uint c = 0; c < renderPass->getLayout().colorAttachments.size(); ++c) { @@ -137,6 +145,10 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo cr } pipelineDescriptor->release(); + graphicsPipelines[hash]->vertexSets = vertexSets; + graphicsPipelines[hash]->vertexFunction = vertexFunction; + graphicsPipelines[hash]->fragmentSets = fragmentSets; + graphicsPipelines[hash]->fragmentFunction = fragmentFunction; return graphicsPipelines[hash]; } @@ -144,12 +156,25 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo crea PRenderPass renderPass = createInfo.renderPass.cast(); MTL::MeshRenderPipelineDescriptor* pipelineDescriptor = MTL::MeshRenderPipelineDescriptor::alloc()->init(); - pipelineDescriptor->setMeshFunction(createInfo.meshShader.cast()->getFunction()); + auto meshShader = createInfo.meshShader.cast(); + Array meshSets = meshShader->usedDescriptors; + MTL::Function* meshFunction = meshShader->getFunction(); + Array taskSets; + MTL::Function* taskFunction = nullptr; + Array fragmentSets; + MTL::Function* fragmentFunction = nullptr; + pipelineDescriptor->setMeshFunction(meshFunction); if (createInfo.taskShader != nullptr) { - pipelineDescriptor->setObjectFunction(createInfo.taskShader.cast()->getFunction()); + auto taskShader = createInfo.taskShader.cast(); + taskSets = taskShader->usedDescriptors; + taskFunction = taskShader->getFunction(); + pipelineDescriptor->setObjectFunction(taskFunction); } if (createInfo.fragmentShader != nullptr) { - pipelineDescriptor->setFragmentFunction(createInfo.fragmentShader.cast()->getFunction()); + auto fragShader = createInfo.fragmentShader.cast(); + fragmentSets = fragShader->usedDescriptors; + fragmentFunction = fragShader->getFunction(); + pipelineDescriptor->setFragmentFunction(fragmentFunction); } for(uint c = 0; c < renderPass->getLayout().colorAttachments.size(); ++c) { const auto& color = renderPass->getLayout().colorAttachments[c]; @@ -187,6 +212,13 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo crea } pipelineDescriptor->release(); + + graphicsPipelines[hash]->taskSets = taskSets; + graphicsPipelines[hash]->taskFunction = taskFunction; + graphicsPipelines[hash]->meshSets = meshSets; + graphicsPipelines[hash]->meshFunction = meshFunction; + graphicsPipelines[hash]->fragmentSets = fragmentSets; + graphicsPipelines[hash]->fragmentFunction = fragmentFunction; return graphicsPipelines[hash]; } @@ -201,5 +233,6 @@ PComputePipeline PipelineCache::createPipeline(Gfx::ComputePipelineCreateInfo cr computePipelines[hash] = new ComputePipeline(graphics, graphics->getDevice()->newComputePipelineState(shader->getFunction(), &error), std::move(createInfo.pipelineLayout)); assert(!error); + computePipelines[hash]->computeFunction = shader->getFunction(); return computePipelines[hash]; } diff --git a/src/Engine/Graphics/Metal/Shader.h b/src/Engine/Graphics/Metal/Shader.h index 40a5ab2..6332e4f 100644 --- a/src/Engine/Graphics/Metal/Shader.h +++ b/src/Engine/Graphics/Metal/Shader.h @@ -25,7 +25,14 @@ class Shader { PGraphics graphics; MTL::Library* library; MTL::Function* function; + // since metal is stupid and doesnt let us create argument encoders for + // descriptors of stages that dont use them, we have to track + // which stage uses what descriptors, which makes sense since functions are independent + // but since metal ALSO doesnt provide any way to find out we have to + // literally manually string search the generated code to find out + Array usedDescriptors; uint32 hash; + friend class PipelineCache; }; DEFINE_REF(Shader) @@ -60,4 +67,4 @@ DEFINE_REF(AnyHitShader) DEFINE_REF(MissShader) DEFINE_REF(CallableShader) } // namespace Metal -} // namespace Seele \ No newline at end of file +} // namespace Seele diff --git a/src/Engine/Graphics/Metal/Shader.mm b/src/Engine/Graphics/Metal/Shader.mm index 37353b6..1b06549 100644 --- a/src/Engine/Graphics/Metal/Shader.mm +++ b/src/Engine/Graphics/Metal/Shader.mm @@ -10,6 +10,7 @@ #include #include #include +#include using namespace Seele; using namespace Seele::Metal; @@ -26,9 +27,16 @@ Shader::~Shader() { void Shader::create(const ShaderCreateInfo& createInfo) { auto [kernelBlob, entryPoint] = generateShader(createInfo); hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32()); - std::ofstream test("test.metal"); - test.write((const char*)kernelBlob->getBufferPointer(), kernelBlob->getBufferSize()); - test.close(); + std::regex pattern("\\[\\[buffer\\(\\d+\\)\\]\\]"); + + std::string codeStr = std::string((const char*)kernelBlob->getBufferPointer()); + auto matches_begin = std::sregex_iterator(codeStr.begin(), codeStr.end(), pattern); + auto matches_end = std::sregex_iterator(); + + for (auto it = matches_begin; it != matches_end; ++it) { + usedDescriptors.add(std::atoi((*it).str().c_str()+9)); // [[buffer( is 9 characters + } + NS::Error* error; MTL::CompileOptions* options = MTL::CompileOptions::alloc()->init(); library = graphics->getDevice()->newLibrary(NS::String::string((char*)kernelBlob->getBufferPointer(), NS::ASCIIStringEncoding), options, diff --git a/src/Engine/Graphics/RenderPass/BasePass.cpp b/src/Engine/Graphics/RenderPass/BasePass.cpp index 3c06a3e..3b99418 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.cpp +++ b/src/Engine/Graphics/RenderPass/BasePass.cpp @@ -138,7 +138,7 @@ void BasePass::beginFrame(const Component::Camera& cam) { } void BasePass::render() { - opaqueCulling->updateBuffer(0, 0, oLightIndexList); + /*opaqueCulling->updateBuffer(0, 0, oLightIndexList); opaqueCulling->updateTexture(1, 0, oLightGrid); transparentCulling->updateBuffer(0, 0, tLightIndexList); transparentCulling->updateTexture(1, 0, tLightGrid); @@ -250,16 +250,21 @@ void BasePass::render() { //commands.add(waterRenderer->render(viewParamsSet)); //commands.add(terrainRenderer->render(viewParamsSet)); - + */ // Skybox + graphics->waitDeviceIdle(); + graphics->beginRenderPass(renderPass); { Gfx::ORenderCommand skyboxCommand = graphics->createRenderCommand("SkyboxRender"); skyboxCommand->setViewport(viewport); skyboxCommand->bindPipeline(pipeline); skyboxCommand->bindDescriptor({viewParamsSet, skyboxDataSet, textureSet}); skyboxCommand->draw(36, 1, 0, 0); - commands.add(std::move(skyboxCommand)); + graphics->executeCommands(std::move(skyboxCommand)); } + graphics->endRenderPass(); + graphics->waitDeviceIdle(); + /* // Transparent rendering { permutation.setDepthCulling(false); // ignore visibility infos for transparency @@ -376,6 +381,7 @@ void BasePass::render() { query->endQuery(); timestamps->write(Gfx::SE_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, "BaseEnd"); gDebugVertices.clear(); + */ } void BasePass::endFrame() {} diff --git a/src/Engine/Graphics/RenderPass/CachedDepthPass.cpp b/src/Engine/Graphics/RenderPass/CachedDepthPass.cpp index 21c9794..8a2212e 100644 --- a/src/Engine/Graphics/RenderPass/CachedDepthPass.cpp +++ b/src/Engine/Graphics/RenderPass/CachedDepthPass.cpp @@ -43,7 +43,7 @@ CachedDepthPass::~CachedDepthPass() {} void CachedDepthPass::beginFrame(const Component::Camera& cam) { RenderPass::beginFrame(cam); } void CachedDepthPass::render() { - query->beginQuery(); +/* query->beginQuery(); timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "CachedBegin"); graphics->beginRenderPass(renderPass); Array commands; @@ -136,7 +136,7 @@ void CachedDepthPass::render() { graphics->endRenderPass(); graphics->waitDeviceIdle(); timestamps->write(Gfx::SE_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, "CachedEnd"); - query->endQuery(); + query->endQuery();*/ } void CachedDepthPass::endFrame() {} diff --git a/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp b/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp index c0d3343..79eaec2 100644 --- a/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp +++ b/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp @@ -68,7 +68,7 @@ DepthCullingPass::~DepthCullingPass() {} void DepthCullingPass::beginFrame(const Component::Camera& cam) { RenderPass::beginFrame(cam); } void DepthCullingPass::render() { - query->beginQuery(); + /*query->beginQuery(); depthAttachment.getTexture()->changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL, Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); @@ -217,7 +217,7 @@ void DepthCullingPass::render() { // Sync visibility write with compute read visibilityAttachment.getTexture()->pipelineBarrier(Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, - Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);*/ } void DepthCullingPass::endFrame() {} diff --git a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp index 1fe783c..73ca58e 100644 --- a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp +++ b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp @@ -5,6 +5,8 @@ #include "Graphics/Graphics.h" #include "RenderGraph.h" #include "Scene/Scene.h" +#include "Graphics/Metal/Descriptor.h" +#include "Graphics/Metal/Shader.h" using namespace Seele; @@ -36,7 +38,7 @@ void LightCullingPass::beginFrame(const Component::Camera& cam) { } void LightCullingPass::render() { - query->beginQuery(); + /*query->beginQuery(); timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "LightCullBegin"); oLightGrid->pipelineBarrier(Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); @@ -71,7 +73,7 @@ void LightCullingPass::render() { oLightGrid->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); tLightGrid->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, - Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); + Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);*/ } void LightCullingPass::endFrame() {} @@ -248,7 +250,7 @@ void LightCullingPass::setupFrustums() { dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER, - .uniformLength = 56,//sizeof(DispatchParams), + .uniformLength = sizeof(DispatchParams), }); dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 1, @@ -269,6 +271,8 @@ void LightCullingPass::setupFrustums() { graphics->beginShaderCompilation(createInfo); frustumShader = graphics->createComputeShader({0}); // Have to compile shader before finalizing layout as parameters get mapped later + Metal::ComputeShader* shader = (Metal::ComputeShader*)(*frustumShader); + std::cout << shader->getFunction()->newArgumentEncoder(1)->debugDescription()->cString(NS::ASCIIStringEncoding) << std::endl; frustumLayout->create(); Gfx::ComputePipelineCreateInfo pipelineInfo; @@ -315,7 +319,7 @@ void LightCullingPass::setupFrustums() { graphics->executeCommands(std::move(commands)); frustumBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); - graphics->waitDeviceIdle(); Frustum* frustums = (Frustum*)frustumBuffer->map(); - std::cout << frustums << std::endl; + graphics->waitDeviceIdle(); + } diff --git a/src/Engine/Graphics/RenderPass/VisibilityPass.cpp b/src/Engine/Graphics/RenderPass/VisibilityPass.cpp index da7a64d..014cd5a 100644 --- a/src/Engine/Graphics/RenderPass/VisibilityPass.cpp +++ b/src/Engine/Graphics/RenderPass/VisibilityPass.cpp @@ -13,7 +13,7 @@ void VisibilityPass::beginFrame(const Component::Camera& cam) { } void VisibilityPass::render() { - cullingBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_MESH_SHADER_BIT_EXT, + /*cullingBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_MESH_SHADER_BIT_EXT, Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT); cullingBuffer->clear(); @@ -38,7 +38,7 @@ void VisibilityPass::render() { query->endQuery(); cullingBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, - Gfx::SE_PIPELINE_STAGE_TASK_SHADER_BIT_EXT | Gfx::SE_PIPELINE_STAGE_MESH_SHADER_BIT_EXT); + Gfx::SE_PIPELINE_STAGE_TASK_SHADER_BIT_EXT | Gfx::SE_PIPELINE_STAGE_MESH_SHADER_BIT_EXT);*/ } void VisibilityPass::endFrame() {} diff --git a/src/Engine/Graphics/Shader.cpp b/src/Engine/Graphics/Shader.cpp index f91cb51..7c1c762 100644 --- a/src/Engine/Graphics/Shader.cpp +++ b/src/Engine/Graphics/Shader.cpp @@ -58,7 +58,7 @@ void ShaderCompiler::compile() { if (pass.useMaterial) { for (const auto& [matName, mat] : materials) { for (int y = 0; y < 2; y++) { - work.add([=]() { + work.add([=, this]() { ShaderPermutation permutation = getTemplate(name); permutation.setPositionOnly(false); permutation.setDepthCulling(y); diff --git a/src/Engine/Math/Vector.cpp b/src/Engine/Math/Vector.cpp index 3e198a9..78752b7 100644 --- a/src/Engine/Math/Vector.cpp +++ b/src/Engine/Math/Vector.cpp @@ -38,6 +38,20 @@ std::ostream& operator<<(std::ostream& stream, const Vector4& vector) { return stream; } + +std::ostream& operator<<(std::ostream& stream, const UVector2& vector) { + stream << "UVec2(" << vector.x << ", " << vector.y << ")"; + return stream; +} +std::ostream& operator<<(std::ostream& stream, const UVector& vector) { + stream << "UVec3(" << vector.x << ", " << vector.y << ", " << vector.z << ")"; + return stream; +} +std::ostream& operator<<(std::ostream& stream, const UVector4& vector) { + stream << "UVec4(" << vector.x << ", " << vector.y << ", " << vector.z << ", " << vector.w << ")"; + return stream; +} + std::ostream& operator<<(std::ostream& stream, const Quaternion& vector) { stream << "Quat(" << vector.w << ", " << vector.x << ", " << vector.y << ", " << vector.z << ")"; return stream; @@ -53,4 +67,4 @@ Vector Seele::parseVector(const char* str) { float y = std::stof(base_match[2].str()); float z = std::stof(base_match[3].str()); return Vector(x, y, z); -} \ No newline at end of file +} diff --git a/src/Engine/Math/Vector.h b/src/Engine/Math/Vector.h index 4ad6cf8..abf34af 100644 --- a/src/Engine/Math/Vector.h +++ b/src/Engine/Math/Vector.h @@ -45,4 +45,9 @@ void from_json(nlohmann::json& j, Vector& vec); std::ostream& operator<<(std::ostream& stream, const Seele::Vector2& vector); std::ostream& operator<<(std::ostream& stream, const Seele::Vector& vector); std::ostream& operator<<(std::ostream& stream, const Seele::Vector4& vector); -std::ostream& operator<<(std::ostream& stream, const Seele::Quaternion& vector); \ No newline at end of file + +std::ostream& operator<<(std::ostream& stream, const Seele::UVector2& vector); +std::ostream& operator<<(std::ostream& stream, const Seele::UVector& vector); +std::ostream& operator<<(std::ostream& stream, const Seele::UVector4& vector); + +std::ostream& operator<<(std::ostream& stream, const Seele::Quaternion& vector); diff --git a/src/Engine/Window/GameView.cpp b/src/Engine/Window/GameView.cpp index 804b555..8fae9fb 100644 --- a/src/Engine/Window/GameView.cpp +++ b/src/Engine/Window/GameView.cpp @@ -15,13 +15,11 @@ #include "System/LightGather.h" #include "System/MeshUpdater.h" #include "Window/Window.h" -#include -#include using namespace Seele; GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo, std::string dllPath) - : View(graphics, window, createInfo, "Game"), scene(new Scene(graphics)), gameInterface(dllPath) { + : View(graphics, window, createInfo, "Game"), graphics(graphics), scene(new Scene(graphics)), gameInterface(dllPath) { reloadGame(); renderGraph.addPass(new CachedDepthPass(graphics, scene)); renderGraph.addPass(new DepthCullingPass(graphics, scene)); diff --git a/src/Engine/Window/GameView.h b/src/Engine/Window/GameView.h index a898651..b788e1e 100644 --- a/src/Engine/Window/GameView.h +++ b/src/Engine/Window/GameView.h @@ -25,6 +25,7 @@ class GameView : public View { protected: virtual void applyArea(URect rect) override; + Gfx::PGraphics graphics; OScene scene; GameInterface gameInterface; RenderGraph renderGraph;