Fixing some mac stuff

This commit is contained in:
Dynamitos
2024-05-17 18:08:11 +02:00
parent 5fd41b8388
commit 2b27ddd134
23 changed files with 747 additions and 539 deletions
+1
View File
@@ -12,6 +12,7 @@
"git.ignoreSubmodules": true, "git.ignoreSubmodules": true,
"cmake.configureOnOpen": true, "cmake.configureOnOpen": true,
"cmake.parallelJobs": 0, "cmake.parallelJobs": 0,
"cmake.buildDirectory": "${workspaceFolder}/build",
"C_Cpp.files.exclude": { "C_Cpp.files.exclude": {
"**/.vs": true, "**/.vs": true,
"**/.vscode": true, "**/.vscode": true,
+3 -3
View File
@@ -21,6 +21,7 @@ set(CMAKE_TOOLCHAIN_FILE ${EXTERNAL_ROOT}/vcpkg/scripts/buildsystems/vcpkg.cmake
set(CRCPP_ROOT ${EXTERNAL_ROOT}/CRCpp) set(CRCPP_ROOT ${EXTERNAL_ROOT}/CRCpp)
set(METAL_ROOT ${EXTERNAL_ROOT}/metal-cpp) set(METAL_ROOT ${EXTERNAL_ROOT}/metal-cpp)
set(SLANG_ROOT ${EXTERNAL_ROOT}/slang)
set(Boost_NO_WARN_NEW_VERSIONS 1) set(Boost_NO_WARN_NEW_VERSIONS 1)
@@ -51,7 +52,6 @@ find_package(Ktx CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED) find_package(nlohmann_json CONFIG REQUIRED)
find_package(fmt CONFIG REQUIRED) find_package(fmt CONFIG REQUIRED)
find_package(VulkanMemoryAllocator CONFIG REQUIRED) find_package(VulkanMemoryAllocator CONFIG REQUIRED)
find_package(OpenMP REQUIRED)
if(UNIX) if(UNIX)
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
@@ -77,7 +77,6 @@ target_link_libraries(Engine PUBLIC crcpp)
target_link_libraries(Engine PUBLIC fmt::fmt) target_link_libraries(Engine PUBLIC fmt::fmt)
target_link_libraries(Engine PUBLIC GPUOpen::VulkanMemoryAllocator) target_link_libraries(Engine PUBLIC GPUOpen::VulkanMemoryAllocator)
target_link_libraries(Engine PUBLIC slang) target_link_libraries(Engine PUBLIC slang)
target_link_libraries(Engine PUBLIC OpenMP::OpenMP_CXX)
if(APPLE) if(APPLE)
target_link_libraries(Engine PUBLIC metal) target_link_libraries(Engine PUBLIC metal)
SET(CMAKE_OSX_DEPLOYMENT_TARGET 14.3) SET(CMAKE_OSX_DEPLOYMENT_TARGET 14.3)
@@ -155,7 +154,8 @@ install(
Editor Editor
Engine Engine
crcpp crcpp
EXPORT metal
EXPORT
EngineTargets EngineTargets
FILE_SET HEADERS FILE_SET HEADERS
DESTINATION include/Seele) DESTINATION include/Seele)
+4 -4
View File
@@ -19,11 +19,11 @@ if(WIN32)
${SLANG_ROOT}slang.lib ${SLANG_ROOT}slang.lib
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
elseif(APPLE) elseif(APPLE)
set(BINARY_ROOT ${SLANG_ROOT}/bin/macosx-aarch64/release/) set(BINARY_ROOT ${SLANG_ROOT}/build/Debug/)
set_target_properties(slang PROPERTIES IMPORTED_LOCATION ${BINARY_ROOT}/libslang.dylib) set_target_properties(slang PROPERTIES IMPORTED_LOCATION ${BINARY_ROOT}/lib/libslang.dylib)
install(FILES install(FILES
${BINARY_ROOT}/libslang.dylib ${BINARY_ROOT}/lib/libslang.dylib
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
endif() endif()
target_include_directories(slang INTERFACE target_include_directories(slang INTERFACE
$<BUILD_INTERFACE:${EXTERNAL_ROOT}/slang> $<BUILD_INTERFACE:${EXTERNAL_ROOT}/slang>
+1 -1
+1 -1
+1 -2
View File
@@ -6,11 +6,10 @@ groupshared uint head;
groupshared Frustum viewFrustum; groupshared Frustum viewFrustum;
[numthreads(TASK_GROUP_SIZE, 1, 1)] [numthreads(TASK_GROUP_SIZE, 1, 1)]
[outputtopology("triangle")]
[shader("amplification")] [shader("amplification")]
void taskMain( void taskMain(
uint threadID: SV_GroupIndex, uint threadID: SV_GroupIndex,
uint groupID: SV_GroupID uint groupID: SV_GroupThreadID
){ ){
InstanceData instance = pScene.instances[pOffsets.instanceOffset + groupID]; InstanceData instance = pScene.instances[pOffsets.instanceOffset + groupID];
MeshData mesh = pScene.meshData[pOffsets.instanceOffset + groupID]; MeshData mesh = pScene.meshData[pOffsets.instanceOffset + groupID];
+1 -1
View File
@@ -206,7 +206,7 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Array<PTextureAsset>&
parameters.add(textureKey); parameters.add(textureKey);
bindingCounter++; bindingCounter++;
std::string samplerKey = std::format("{0}Sampler{1}", paramKey, index); std::string samplerKey = fmt::format("{0}Sampler{1}", paramKey, index);
SamplerCreateInfo samplerInfo = {}; SamplerCreateInfo samplerInfo = {};
switch (mapMode) switch (mapMode)
{ {
+1 -1
View File
@@ -64,7 +64,7 @@ void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset)
ss << "toktx --encode etc1s "; ss << "toktx --encode etc1s ";
if (args.type == TextureImportType::TEXTURE_NORMAL) if (args.type == TextureImportType::TEXTURE_NORMAL)
{ {
ss << "--normal_mode "; //ss << "--normal_mode ";
} }
ss << ktxFile << " " << args.filePath; ss << ktxFile << " " << args.filePath;
system(ss.str().c_str()); system(ss.str().c_str());
+1 -1
View File
@@ -59,7 +59,7 @@ int main() {
.filePath = sourcePath / "import/models/cube.fbx", .filePath = sourcePath / "import/models/cube.fbx",
}); });
AssetImporter::importMesh(MeshImportArgs{ AssetImporter::importMesh(MeshImportArgs{
.filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb", .filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.gltf",
.importPath = "Whitechapel" .importPath = "Whitechapel"
}); });
//AssetImporter::importMesh(MeshImportArgs{ //AssetImporter::importMesh(MeshImportArgs{
+30 -15
View File
@@ -7,6 +7,7 @@ class Buffer : public QueueOwnedResource {
public: public:
Buffer(QueueFamilyMapping mapping, QueueType startQueueType); Buffer(QueueFamilyMapping mapping, QueueType startQueueType);
virtual ~Buffer(); virtual ~Buffer();
protected: protected:
// Inherited via QueueOwnedResource // Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(QueueType newOwner) = 0; virtual void executeOwnershipBarrier(QueueType newOwner) = 0;
@@ -14,19 +15,22 @@ protected:
class VertexBuffer : public Buffer { class VertexBuffer : public Buffer {
public: public:
VertexBuffer(QueueFamilyMapping mapping, uint32 numVertices, uint32 vertexSize, QueueType startQueueType); VertexBuffer(QueueFamilyMapping mapping, uint32 numVertices,
uint32 vertexSize, QueueType startQueueType);
virtual ~VertexBuffer(); virtual ~VertexBuffer();
constexpr uint32 getNumVertices() const { return numVertices; } constexpr uint32 getNumVertices() const { return numVertices; }
// Size of one vertex in bytes // Size of one vertex in bytes
constexpr uint32 getVertexSize() const { return vertexSize; } constexpr uint32 getVertexSize() const { return vertexSize; }
virtual void updateRegion(DataSource update) = 0; virtual void updateRegion(DataSource update) = 0;
virtual void download(Array<uint8>& buffer) = 0; virtual void download(Array<uint8> &buffer) = 0;
protected: protected:
// Inherited via QueueOwnedResource // Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(QueueType newOwner) = 0; virtual void executeOwnershipBarrier(QueueType newOwner) = 0;
virtual void executePipelineBarrier(SeAccessFlags srcAccess, SePipelineStageFlags srcStage, SeAccessFlags dstAccess, virtual void executePipelineBarrier(SeAccessFlags srcAccess,
SePipelineStageFlags srcStage,
SeAccessFlags dstAccess,
SePipelineStageFlags dstStage) = 0; SePipelineStageFlags dstStage) = 0;
uint32 numVertices; uint32 numVertices;
uint32 vertexSize; uint32 vertexSize;
@@ -35,17 +39,20 @@ DEFINE_REF(VertexBuffer)
class IndexBuffer : public Buffer { class IndexBuffer : public Buffer {
public: public:
IndexBuffer(QueueFamilyMapping mapping, uint64 size, Gfx::SeIndexType index, QueueType startQueueType); IndexBuffer(QueueFamilyMapping mapping, uint64 size, Gfx::SeIndexType index,
QueueType startQueueType);
virtual ~IndexBuffer(); virtual ~IndexBuffer();
constexpr uint64 getNumIndices() const { return numIndices; } constexpr uint64 getNumIndices() const { return numIndices; }
constexpr Gfx::SeIndexType getIndexType() const { return indexType; } constexpr Gfx::SeIndexType getIndexType() const { return indexType; }
virtual void download(Array<uint8>& buffer) = 0; virtual void download(Array<uint8> &buffer) = 0;
protected: protected:
// Inherited via QueueOwnedResource // Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(QueueType newOwner) = 0; virtual void executeOwnershipBarrier(QueueType newOwner) = 0;
virtual void executePipelineBarrier(SeAccessFlags srcAccess, SePipelineStageFlags srcStage, SeAccessFlags dstAccess, virtual void executePipelineBarrier(SeAccessFlags srcAccess,
SePipelineStageFlags srcStage,
SeAccessFlags dstAccess,
SePipelineStageFlags dstStage) = 0; SePipelineStageFlags dstStage) = 0;
Gfx::SeIndexType indexType; Gfx::SeIndexType indexType;
uint64 numIndices; uint64 numIndices;
@@ -55,10 +62,11 @@ DEFINE_REF(IndexBuffer)
DECLARE_REF(UniformBuffer) DECLARE_REF(UniformBuffer)
class UniformBuffer : public Buffer { class UniformBuffer : public Buffer {
public: public:
UniformBuffer(QueueFamilyMapping mapping, const DataSource& sourceData); UniformBuffer(QueueFamilyMapping mapping, const DataSource &sourceData);
virtual ~UniformBuffer(); virtual ~UniformBuffer();
// returns true if an update was performed, false if the old contents == new contents // returns true if an update was performed, false if the old contents == new
virtual bool updateContents(const DataSource& sourceData); // contents
virtual bool updateContents(const DataSource &sourceData);
bool isDataEquals(PUniformBuffer other) { bool isDataEquals(PUniformBuffer other) {
if (other == nullptr) { if (other == nullptr) {
return false; return false;
@@ -66,7 +74,8 @@ public:
if (contents.size() != other->contents.size()) { if (contents.size() != other->contents.size()) {
return false; return false;
} }
if (std::memcmp(contents.data(), other->contents.data(), contents.size()) != 0) { if (std::memcmp(contents.data(), other->contents.data(), contents.size()) !=
0) {
return false; return false;
} }
return true; return true;
@@ -76,24 +85,30 @@ protected:
Array<uint8> contents; Array<uint8> contents;
// Inherited via QueueOwnedResource // Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(QueueType newOwner) = 0; virtual void executeOwnershipBarrier(QueueType newOwner) = 0;
virtual void executePipelineBarrier(SeAccessFlags srcAccess, SePipelineStageFlags srcStage, SeAccessFlags dstAccess, virtual void executePipelineBarrier(SeAccessFlags srcAccess,
SePipelineStageFlags srcStage,
SeAccessFlags dstAccess,
SePipelineStageFlags dstStage) = 0; SePipelineStageFlags dstStage) = 0;
}; };
DEFINE_REF(UniformBuffer) DEFINE_REF(UniformBuffer)
class ShaderBuffer : public Buffer { class ShaderBuffer : public Buffer {
public: public:
ShaderBuffer(QueueFamilyMapping mapping, uint32 numElements, const DataSource& bulkResourceData); ShaderBuffer(QueueFamilyMapping mapping, uint32 numElements,
const DataSource &bulkResourceData);
virtual ~ShaderBuffer(); virtual ~ShaderBuffer();
virtual void rotateBuffer(uint64 size) = 0; virtual void rotateBuffer(uint64 size) = 0;
virtual void updateContents(const ShaderBufferCreateInfo& sourceData); virtual void updateContents(const ShaderBufferCreateInfo &sourceData);
constexpr uint32 getNumElements() const { return numElements; } constexpr uint32 getNumElements() const { return numElements; }
virtual void* mapRegion(uint64 offset = 0, uint64 size = -1, bool writeOnly = true) = 0; virtual void *mapRegion(uint64 offset = 0, uint64 size = -1,
bool writeOnly = true) = 0;
virtual void unmap() = 0; virtual void unmap() = 0;
protected: protected:
// Inherited via QueueOwnedResource // Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(QueueType newOwner) = 0; virtual void executeOwnershipBarrier(QueueType newOwner) = 0;
virtual void executePipelineBarrier(SeAccessFlags srcAccess, SePipelineStageFlags srcStage, SeAccessFlags dstAccess, virtual void executePipelineBarrier(SeAccessFlags srcAccess,
SePipelineStageFlags srcStage,
SeAccessFlags dstAccess,
SePipelineStageFlags dstStage) = 0; SePipelineStageFlags dstStage) = 0;
Array<uint8> contents; Array<uint8> contents;
+24 -8
View File
@@ -2,18 +2,29 @@
#include "Graphics/Buffer.h" #include "Graphics/Buffer.h"
#include "Graphics/Enums.h" #include "Graphics/Enums.h"
#include "Graphics/Initializer.h" #include "Graphics/Initializer.h"
#include "Metal/MTLTypes.hpp"
#include "MinimalEngine.h"
#include "Resources.h" #include "Resources.h"
namespace Seele { namespace Seele {
namespace Metal { namespace Metal {
DECLARE_REF(Graphics) DECLARE_REF(Graphics)
class BufferAllocation : public CommandBoundResource
{
public:
BufferAllocation(PGraphics graphics);
virtual ~BufferAllocation();
MTL::Buffer* buffer = nullptr;
uint64 size = 0;
};
DECLARE_REF(BufferAllocation)
class Buffer { class Buffer {
public: public:
Buffer(PGraphics graphics, uint64 size, void *data, bool dynamic, const std::string& name); Buffer(PGraphics graphics, uint64 size, void *data, bool dynamic, const std::string& name);
virtual ~Buffer(); virtual ~Buffer();
MTL::Buffer *getHandle() const { return buffers[currentBuffer]; } MTL::Buffer *getHandle() const { return buffers[currentBuffer]->buffer; }
uint64 getSize() const { return size; } PBufferAllocation getAlloc() const { return buffers[currentBuffer]; }
void advanceBuffer() { currentBuffer = (currentBuffer + 1) % numBuffers; } uint64 getSize() const { return buffers[currentBuffer]->size; }
void *map(bool writeOnly = true); void *map(bool writeOnly = true);
void *mapRegion(uint64 regionOffset, uint64 regionSize, bool writeOnly); void *mapRegion(uint64 regionOffset, uint64 regionSize, bool writeOnly);
void unmap(); void unmap();
@@ -21,11 +32,14 @@ public:
protected: protected:
PGraphics graphics; PGraphics graphics;
uint32 currentBuffer = 0; uint32 currentBuffer = 0;
uint64 size; Array<OBufferAllocation> buffers;
MTL::Buffer *buffers[Gfx::numFramesBuffered]; bool dynamic;
uint32 numBuffers; std::string name;
void rotateBuffer(uint64 size);
void createBuffer(uint64 size, void* data);
}; };
DEFINE_REF(Buffer) DEFINE_REF(Buffer)
class VertexBuffer : public Gfx::VertexBuffer, public Buffer { class VertexBuffer : public Gfx::VertexBuffer, public Buffer {
public: public:
VertexBuffer(PGraphics graphics, const VertexBufferCreateInfo &createInfo); VertexBuffer(PGraphics graphics, const VertexBufferCreateInfo &createInfo);
@@ -72,8 +86,10 @@ class ShaderBuffer : public Gfx::ShaderBuffer, public Buffer {
public: public:
ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo &createInfo); ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo &createInfo);
virtual ~ShaderBuffer(); virtual ~ShaderBuffer();
virtual void rotateBuffer(uint64 size) override;
virtual bool updateContents(const DataSource &sourceData) override; virtual void updateContents(const ShaderBufferCreateInfo &sourceData) override;
virtual void *mapRegion(uint64 offset, uint64 size, bool writeOnly) override;
virtual void unmap() override;
protected: protected:
// Inherited via QueueOwnedResource // Inherited via QueueOwnedResource
+80 -23
View File
@@ -3,30 +3,35 @@
#include "Graphics/Buffer.h" #include "Graphics/Buffer.h"
#include "Graphics/Enums.h" #include "Graphics/Enums.h"
#include "Graphics/Initializer.h" #include "Graphics/Initializer.h"
#include "Graphics/Metal/Resources.h"
#include "Metal/MTLResource.hpp"
#include <iostream> #include <iostream>
using namespace Seele; using namespace Seele;
using namespace Seele::Metal; using namespace Seele::Metal;
Buffer::Buffer(PGraphics graphics, uint64 size, void* data, bool dynamic, const std::string& name) : graphics(graphics), size(size) { BufferAllocation::BufferAllocation(PGraphics graphics)
if (dynamic) { : CommandBoundResource(graphics)
numBuffers = Gfx::numFramesBuffered; {}
} else {
numBuffers = 1; BufferAllocation::~BufferAllocation()
} {
for (size_t i = 0; i < numBuffers; ++i) { if(buffer != nullptr)
if (data != nullptr) { {
buffers[i] = graphics->getDevice()->newBuffer(data, size, MTL::StorageModeShared); buffer->release();
} else {
buffers[i] = graphics->getDevice()->newBuffer(size, MTL::StorageModeShared);
}
buffers[i]->setLabel(NS::String::string(name.c_str(), NS::ASCIIStringEncoding));
} }
} }
Buffer::Buffer(PGraphics graphics, uint64 size, void* data, bool dynamic, const std::string& name)
: graphics(graphics)
, dynamic(dynamic)
, name(name) {
createBuffer(size, data);
}
Buffer::~Buffer() { Buffer::~Buffer() {
for (size_t i = 0; i < numBuffers; ++i) { for (size_t i = 0; i < buffers.size(); ++i) {
buffers[i]->release(); //TODO
} }
} }
@@ -36,6 +41,39 @@ void* Buffer::mapRegion(uint64 regionOffset, uint64, bool) { return (char*)getHa
void Buffer::unmap() {} void Buffer::unmap() {}
void Buffer::rotateBuffer(uint64 size)
{
size = std::max(getSize(), size);
for(size_t i = 0; i < buffers.size(); ++i)
{
if(buffers[i]->isCurrentlyBound())
{
continue;
}
if(buffers[i]->size < size)
{
buffers[i]->buffer->release();
buffers[i]->buffer = graphics->getDevice()->newBuffer(size, MTL::StorageModeShared);
buffers[i]->size = size;
}
currentBuffer = i;
return;
}
createBuffer(size, nullptr);
currentBuffer = buffers.size() - 1;
}
void Buffer::createBuffer(uint64 size, void* data)
{
buffers.add(new BufferAllocation(graphics));
if (data != nullptr) {
buffers.back()->buffer = graphics->getDevice()->newBuffer(data, size, MTL::StorageModeShared);
} else {
buffers.back()->buffer = graphics->getDevice()->newBuffer(size, MTL::StorageModeShared);
}
buffers.back()->buffer->setLabel(NS::String::string(name.c_str(), NS::ASCIIStringEncoding));
}
VertexBuffer::VertexBuffer(PGraphics graphics, const VertexBufferCreateInfo& createInfo) VertexBuffer::VertexBuffer(PGraphics graphics, const VertexBufferCreateInfo& createInfo)
: Gfx::VertexBuffer(graphics->getFamilyMapping(), createInfo.numVertices, createInfo.vertexSize, : Gfx::VertexBuffer(graphics->getFamilyMapping(), createInfo.numVertices, createInfo.vertexSize,
createInfo.sourceData.owner), createInfo.sourceData.owner),
@@ -50,8 +88,8 @@ void VertexBuffer::updateRegion(DataSource update) {
void VertexBuffer::download(Array<uint8>& buffer) { void VertexBuffer::download(Array<uint8>& buffer) {
void* data = getHandle()->contents(); void* data = getHandle()->contents();
buffer.resize(size); buffer.resize(getSize());
std::memcpy(buffer.data(), data, size); std::memcpy(buffer.data(), data, getSize());
} }
void VertexBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { currentOwner = newOwner; } void VertexBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { currentOwner = newOwner; }
@@ -70,8 +108,8 @@ IndexBuffer::~IndexBuffer() {}
void IndexBuffer::download(Array<uint8>& buffer) { void IndexBuffer::download(Array<uint8>& buffer) {
void* data = getHandle()->contents(); void* data = getHandle()->contents();
buffer.resize(size); buffer.resize(getSize());
std::memcpy(buffer.data(), data, size); std::memcpy(buffer.data(), data, getSize());
} }
void IndexBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { currentOwner = newOwner; } void IndexBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { currentOwner = newOwner; }
@@ -101,10 +139,29 @@ ShaderBuffer::ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo& cre
ShaderBuffer::~ShaderBuffer() {} ShaderBuffer::~ShaderBuffer() {}
bool ShaderBuffer::updateContents(const DataSource& sourceData) { void ShaderBuffer::rotateBuffer(uint64 size) {
void* data = getHandle()->contents(); Metal::Buffer::rotateBuffer(size);
std::memcpy((char*)data + sourceData.offset, sourceData.data, sourceData.size); }
return true;
void ShaderBuffer::updateContents(const ShaderBufferCreateInfo& createInfo) {
Gfx::ShaderBuffer::updateContents(createInfo);
if(createInfo.sourceData.data == nullptr)
{
return;
}
void* data = map();
std::memcpy((char*)data + createInfo.sourceData.offset, createInfo.sourceData.data, createInfo.sourceData.size);
unmap();
}
void* ShaderBuffer::mapRegion(uint64 offset, uint64 size, bool writeOnly)
{
return Metal::Buffer::mapRegion(offset, size, writeOnly);
}
void ShaderBuffer::unmap()
{
Metal::Buffer::unmap();
} }
void ShaderBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { currentOwner = newOwner; } void ShaderBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { currentOwner = newOwner; }
+7 -6
View File
@@ -56,16 +56,17 @@ public:
void end(); void end();
virtual void setViewport(Gfx::PViewport viewport) override; virtual void setViewport(Gfx::PViewport viewport) override;
virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) override; virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) override;
virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet) override; virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array<uint32> dynamicOffsets) override;
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets) override; virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets, Array<uint32> dynamicOffsets) override;
virtual void bindVertexBuffer(const Array<Gfx::PVertexBuffer>& buffers) override; virtual void bindVertexBuffer(const Array<Gfx::PVertexBuffer>& buffers) override;
virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) override; virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) override;
virtual void pushConstants(Gfx::PPipelineLayout layout, Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size,
const void* data) override; const void* data) override;
virtual void draw(uint32 vertexCount, uint32 instanceCount, int32 firstVertex, uint32 firstInstance) override; virtual void draw(uint32 vertexCount, uint32 instanceCount, int32 firstVertex, uint32 firstInstance) override;
virtual void drawIndexed(uint32 indexCount, uint32 instanceCount, int32 firstIndex, uint32 vertexOffset, virtual void drawIndexed(uint32 indexCount, uint32 instanceCount, int32 firstIndex, uint32 vertexOffset,
uint32 firstInstance) override; uint32 firstInstance) override;
virtual void drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) override; virtual void drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) override;
virtual void drawMeshIndirect(Gfx::PShaderBuffer buffer, uint64 offset, uint32 drawCount, uint32 stride) override;
private: private:
PGraphicsPipeline boundPipeline; PGraphicsPipeline boundPipeline;
@@ -81,9 +82,9 @@ public:
virtual ~ComputeCommand(); virtual ~ComputeCommand();
void end(); void end();
virtual void bindPipeline(Gfx::PComputePipeline pipeline) override; virtual void bindPipeline(Gfx::PComputePipeline pipeline) override;
virtual void bindDescriptor(Gfx::PDescriptorSet set) override; virtual void bindDescriptor(Gfx::PDescriptorSet set, Array<uint32> dynamicOffsets) override;
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) override; virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets, Array<uint32> dynamicOffsets) override;
virtual void pushConstants(Gfx::PPipelineLayout layout, Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size,
const void* data) override; const void* data) override;
virtual void dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) override; virtual void dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) override;
+12 -8
View File
@@ -84,7 +84,7 @@ void RenderCommand::bindPipeline(Gfx::PGraphicsPipeline pipeline) {
NS::String::string(boundPipeline->getPipelineLayout()->getName().c_str(), NS::ASCIIStringEncoding)); NS::String::string(boundPipeline->getPipelineLayout()->getName().c_str(), NS::ASCIIStringEncoding));
} }
void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet) { void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array<uint32> offsets) {
auto metalSet = descriptorSet.cast<DescriptorSet>(); auto metalSet = descriptorSet.cast<DescriptorSet>();
uint32 parameterIndex = boundPipeline->getPipelineLayout()->findParameter(descriptorSet->getLayout()->getName()); uint32 parameterIndex = boundPipeline->getPipelineLayout()->findParameter(descriptorSet->getLayout()->getName());
uint64* topLevelTable = (uint64*)argumentBuffer->contents(); uint64* topLevelTable = (uint64*)argumentBuffer->contents();
@@ -117,9 +117,9 @@ void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet) {
} }
} }
void RenderCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets) { void RenderCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets, Array<uint32> offsets) {
for (auto set : descriptorSets) { for (auto set : descriptorSets) {
bindDescriptor(set); bindDescriptor(set, offsets);
} }
} }
void RenderCommand::bindVertexBuffer(const Array<Gfx::PVertexBuffer>& buffers) { void RenderCommand::bindVertexBuffer(const Array<Gfx::PVertexBuffer>& buffers) {
@@ -133,7 +133,7 @@ void RenderCommand::bindIndexBuffer(Gfx::PIndexBuffer gfxIndexBuffer) {
boundIndexBuffer = gfxIndexBuffer.cast<IndexBuffer>(); boundIndexBuffer = gfxIndexBuffer.cast<IndexBuffer>();
} }
void RenderCommand::pushConstants(Gfx::PPipelineLayout, Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, void RenderCommand::pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size,
const void* data) { const void* data) {
if (stage & Gfx::SE_SHADER_STAGE_VERTEX_BIT) { if (stage & Gfx::SE_SHADER_STAGE_VERTEX_BIT) {
encoder->setVertexBytes((char*)data + offset, size, 0); encoder->setVertexBytes((char*)data + offset, size, 0);
@@ -162,6 +162,10 @@ void RenderCommand::drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) {
encoder->drawMeshThreadgroups(MTL::Size(groupX, groupY, groupZ), MTL::Size(128, 1, 1), MTL::Size(32, 1, 1)); encoder->drawMeshThreadgroups(MTL::Size(groupX, groupY, groupZ), MTL::Size(128, 1, 1), MTL::Size(32, 1, 1));
} }
void RenderCommand::drawMeshIndirect(Gfx::PShaderBuffer buffer, uint64 offset, uint32 drawCount, uint32 stride) {
//encoder->drawMeshThreadgroups()
}
ComputeCommand::ComputeCommand(MTL::CommandBuffer* cmdBuffer, const std::string& name) ComputeCommand::ComputeCommand(MTL::CommandBuffer* cmdBuffer, const std::string& name)
: commandBuffer(cmdBuffer), encoder(cmdBuffer->computeCommandEncoder()), name(name) {} : commandBuffer(cmdBuffer), encoder(cmdBuffer->computeCommandEncoder()), name(name) {}
@@ -181,7 +185,7 @@ void ComputeCommand::bindPipeline(Gfx::PComputePipeline pipeline) {
NS::String::string(pipeline->getPipelineLayout()->getName().c_str(), NS::ASCIIStringEncoding)); NS::String::string(pipeline->getPipelineLayout()->getName().c_str(), NS::ASCIIStringEncoding));
} }
void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set) { void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set, Array<uint32> offsets) {
auto metalSet = set.cast<DescriptorSet>(); auto metalSet = set.cast<DescriptorSet>();
metalSet->bind(); metalSet->bind();
uint32 parameterIndex = boundPipeline->getPipelineLayout()->findParameter(set->getLayout()->getName()); uint32 parameterIndex = boundPipeline->getPipelineLayout()->findParameter(set->getLayout()->getName());
@@ -215,13 +219,13 @@ void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set) {
} }
} }
void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) { void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& sets, Array<uint32> offsets) {
for (auto& set : sets) { for (auto& set : sets) {
bindDescriptor(set); bindDescriptor(set, offsets);
} }
} }
void ComputeCommand::pushConstants(Gfx::PPipelineLayout, Gfx::SeShaderStageFlags, uint32 offset, uint32 size, void ComputeCommand::pushConstants(Gfx::SeShaderStageFlags, uint32 offset, uint32 size,
const void* data) { const void* data) {
encoder->setBytes((char*)data + offset, size, 0); encoder->setBytes((char*)data + offset, size, 0);
} }
+24 -20
View File
@@ -1,15 +1,16 @@
#pragma once #pragma once
#include "Buffer.h"
#include "Graphics/Descriptor.h" #include "Graphics/Descriptor.h"
#include "Graphics/Initializer.h" #include "Graphics/Initializer.h"
#include "Graphics/Metal/Resources.h"
#include "MinimalEngine.h" #include "MinimalEngine.h"
#include "Buffer.h"
namespace Seele { namespace Seele {
namespace Metal { namespace Metal {
DECLARE_REF(Graphics) DECLARE_REF(Graphics)
class DescriptorLayout : public Gfx::DescriptorLayout { class DescriptorLayout : public Gfx::DescriptorLayout {
public: public:
DescriptorLayout(PGraphics graphics, const std::string& name); DescriptorLayout(PGraphics graphics, const std::string &name);
virtual ~DescriptorLayout(); virtual ~DescriptorLayout();
virtual void create() override; virtual void create() override;
@@ -34,44 +35,47 @@ private:
}; };
DEFINE_REF(DescriptorPool) DEFINE_REF(DescriptorPool)
class DescriptorSet : public Gfx::DescriptorSet { class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
public: public:
DescriptorSet(PGraphics graphics, PDescriptorPool owner); DescriptorSet(PGraphics graphics, PDescriptorPool owner);
virtual ~DescriptorSet(); virtual ~DescriptorSet();
virtual void writeChanges(); virtual void writeChanges() override;
virtual void updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer); virtual void updateBuffer(uint32_t binding,
virtual void updateBuffer(uint32_t binding, Gfx::PShaderBuffer uniformBuffer); Gfx::PUniformBuffer uniformBuffer) override;
virtual void updateSampler(uint32_t binding, Gfx::PSampler samplerState); virtual void updateBuffer(uint32_t binding, Gfx::PShaderBuffer uniformBuffer) override;
virtual void updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler sampler = nullptr); virtual void updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) override;
virtual void updateTextureArray(uint32_t binding, Array<Gfx::PTexture> texture); virtual void updateSampler(uint32_t binding, Gfx::PSampler samplerState) override;
virtual void updateTexture(uint32_t binding, Gfx::PTexture texture,
Gfx::PSampler sampler = nullptr) override;
virtual void updateTextureArray(uint32_t binding,
Array<Gfx::PTexture> texture) override;
constexpr bool isCurrentlyBound() const { return bindCount > 0; }
constexpr bool isCurrentlyInUse() const { return currentlyInUse; } constexpr bool isCurrentlyInUse() const { return currentlyInUse; }
constexpr void bind() { bindCount++; }
constexpr void unbind() { bindCount--; }
constexpr void allocate() { currentlyInUse = true; } constexpr void allocate() { currentlyInUse = true; }
constexpr void free() { currentlyInUse = false; } constexpr void free() { currentlyInUse = false; }
constexpr MTL::Buffer* getBuffer() const { return buffer; } constexpr MTL::Buffer *getBuffer() const { return buffer; }
constexpr const Array<MTL::Resource*>& getBoundResources() const { return boundResources; } constexpr const Array<MTL::Resource *> &getBoundResources() const {
return boundResources;
}
private: private:
PGraphics graphics; PGraphics graphics;
PDescriptorPool owner; PDescriptorPool owner;
MTL::Buffer* buffer = nullptr; MTL::Buffer *buffer = nullptr;
uint64* argumentBuffer = nullptr; uint64 *argumentBuffer = nullptr;
Array<MTL::Resource*> boundResources; Array<MTL::Resource *> boundResources;
uint32 bindCount;
bool currentlyInUse; bool currentlyInUse;
}; };
DEFINE_REF(DescriptorSet) DEFINE_REF(DescriptorSet)
class PipelineLayout : public Gfx::PipelineLayout { class PipelineLayout : public Gfx::PipelineLayout {
public: public:
PipelineLayout(PGraphics graphics, const std::string& name, Gfx::PPipelineLayout baseLayout); PipelineLayout(PGraphics graphics, const std::string &name,
Gfx::PPipelineLayout baseLayout);
virtual ~PipelineLayout(); virtual ~PipelineLayout();
virtual void create() override; virtual void create() override;
private: private:
PGraphics graphics; PGraphics graphics;
}; };
+84 -55
View File
@@ -3,6 +3,7 @@
#include "Enums.h" #include "Enums.h"
#include "Graphics/Descriptor.h" #include "Graphics/Descriptor.h"
#include "Graphics/Initializer.h" #include "Graphics/Initializer.h"
#include "Graphics/Metal/Resources.h"
#include "Metal/MTLArgument.hpp" #include "Metal/MTLArgument.hpp"
#include "Metal/MTLDevice.hpp" #include "Metal/MTLDevice.hpp"
#include "Metal/MTLResource.hpp" #include "Metal/MTLResource.hpp"
@@ -14,24 +15,28 @@
using namespace Seele; using namespace Seele;
using namespace Seele::Metal; using namespace Seele::Metal;
DescriptorLayout::DescriptorLayout(PGraphics graphics, const std::string& name) DescriptorLayout::DescriptorLayout(PGraphics graphics, const std::string &name)
: Gfx::DescriptorLayout(name), graphics(graphics) {} : Gfx::DescriptorLayout(name), graphics(graphics) {}
DescriptorLayout::~DescriptorLayout() {} DescriptorLayout::~DescriptorLayout() {}
void DescriptorLayout::create() { void DescriptorLayout::create() {
pool = new DescriptorPool(graphics, this); pool = new DescriptorPool(graphics, this);
hash = CRC::Calculate(descriptorBindings.data(), sizeof(Gfx::DescriptorBinding) * descriptorBindings.size(), hash =
CRC::CRC_32()); CRC::Calculate(descriptorBindings.data(),
sizeof(Gfx::DescriptorBinding) * descriptorBindings.size(),
CRC::CRC_32());
} }
DescriptorPool::DescriptorPool(PGraphics graphics, PDescriptorLayout layout) : graphics(graphics), layout(layout) {} DescriptorPool::DescriptorPool(PGraphics graphics, PDescriptorLayout layout)
: graphics(graphics), layout(layout) {}
DescriptorPool::~DescriptorPool() {} DescriptorPool::~DescriptorPool() {}
Gfx::PDescriptorSet DescriptorPool::allocateDescriptorSet() { Gfx::PDescriptorSet DescriptorPool::allocateDescriptorSet() {
for (uint32 setIndex = 0; setIndex < allocatedSets.size(); ++setIndex) { for (uint32 setIndex = 0; setIndex < allocatedSets.size(); ++setIndex) {
if (allocatedSets[setIndex]->isCurrentlyBound() || allocatedSets[setIndex]->isCurrentlyInUse()) { if (allocatedSets[setIndex]->isCurrentlyBound() ||
allocatedSets[setIndex]->isCurrentlyInUse()) {
// Currently in use, skip // Currently in use, skip
continue; continue;
} }
@@ -46,80 +51,104 @@ Gfx::PDescriptorSet DescriptorPool::allocateDescriptorSet() {
} }
void DescriptorPool::reset() { void DescriptorPool::reset() {
for (auto& set : allocatedSets) { for (auto &set : allocatedSets) {
set->free(); set->free();
} }
} }
DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner) DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner)
: Gfx::DescriptorSet(owner->getLayout()), graphics(graphics), owner(owner), bindCount(0), currentlyInUse(false) { : Gfx::DescriptorSet(owner->getLayout()), CommandBoundResource(graphics),
graphics(graphics), owner(owner), currentlyInUse(false) {
boundResources.resize(owner->getLayout()->getBindings().size()); boundResources.resize(owner->getLayout()->getBindings().size());
buffer = graphics->getDevice()->newBuffer(std::max<size_t>(8, sizeof(uint64_t) * 3 * owner->getLayout()->getBindings().size()), MTL::ResourceStorageModeShared); buffer = graphics->getDevice()->newBuffer(
argumentBuffer = (uint64*)buffer->contents(); std::max<size_t>(8, sizeof(uint64_t) * 3 *
buffer->setLabel(NS::String::string(owner->getLayout()->getName().c_str(), NS::ASCIIStringEncoding)); owner->getLayout()->getBindings().size()),
MTL::ResourceStorageModeShared);
argumentBuffer = (uint64 *)buffer->contents();
buffer->setLabel(NS::String::string(owner->getLayout()->getName().c_str(),
NS::ASCIIStringEncoding));
} }
DescriptorSet::~DescriptorSet() {buffer->release();} DescriptorSet::~DescriptorSet() { buffer->release(); }
void DescriptorSet::writeChanges() {} void DescriptorSet::writeChanges() {}
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer) { void DescriptorSet::updateBuffer(uint32_t binding,
Gfx::PUniformBuffer uniformBuffer) {
PUniformBuffer metalBuffer = uniformBuffer.cast<UniformBuffer>(); PUniformBuffer metalBuffer = uniformBuffer.cast<UniformBuffer>();
uint64 offset = binding * 3; uint64 offset = binding * 3;
argumentBuffer[offset + 0] = metalBuffer->getHandle()->gpuAddress(); argumentBuffer[offset + 0] = metalBuffer->getHandle()->gpuAddress();
argumentBuffer[offset + 1] = 0; argumentBuffer[offset + 1] = 0;
argumentBuffer[offset + 2] = (uint32)metalBuffer->getSize(); // TODO: buffer texture view, typed?? argumentBuffer[offset + 2] =
boundResources[binding] = metalBuffer->getHandle(); (uint32)metalBuffer->getSize(); // TODO: buffer texture view, typed??
boundResources[binding] = metalBuffer->getHandle();
} }
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer uniformBuffer) { void DescriptorSet::updateBuffer(uint32_t binding,
Gfx::PShaderBuffer uniformBuffer) {
PShaderBuffer metalBuffer = uniformBuffer.cast<ShaderBuffer>(); PShaderBuffer metalBuffer = uniformBuffer.cast<ShaderBuffer>();
uint64 offset = binding * 3; uint64 offset = binding * 3;
argumentBuffer[offset + 0] = metalBuffer->getHandle()->gpuAddress(); argumentBuffer[offset + 0] = metalBuffer->getHandle()->gpuAddress();
argumentBuffer[offset + 1] = 0; argumentBuffer[offset + 1] = 0;
argumentBuffer[offset + 2] = (uint32)metalBuffer->getSize(); // TODO: buffer texture view, typed?? argumentBuffer[offset + 2] =
boundResources[binding] = metalBuffer->getHandle(); (uint32)metalBuffer->getSize(); // TODO: buffer texture view, typed??
} boundResources[binding] = metalBuffer->getHandle();
void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState) {
PSampler sampler = samplerState.cast<Sampler>();
MTL::ResourceID resourceId =sampler->getHandle()->gpuResourceID();
uint64 offset = binding * 3;
argumentBuffer[offset + 0] = 0;
argumentBuffer[offset + 1] = *(uint64*)&resourceId;
argumentBuffer[offset + 2] = 0; // LOD bias
}
void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler samplerState) {
PTextureBase base = texture.cast<TextureBase>();
if(layout->getBindings()[binding].access == Gfx::SE_DESCRIPTOR_ACCESS_READ_ONLY_BIT)
{
MTL::ResourceID resourceId =base->getTexture()->gpuResourceID();
uint64 offset = binding * 3;
argumentBuffer[offset + 0] = 0;
argumentBuffer[offset + 1] = *(uint64*)&resourceId;
argumentBuffer[offset + 2] = 0; // min LOD clamp
}else{
uint64 offset = binding * 3;
argumentBuffer[offset + 0] = base->getTexture()->buffer()->gpuAddress();
argumentBuffer[offset + 1] = 0;
argumentBuffer[offset + 2] = (uint32)base->getTexture()->buffer()->length(); // TODO: buffer texture view, typed??
}
boundResources[binding] = base->getTexture();
} }
void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture> array) { void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer uniformBuffer)
for (auto& t : array) { {
updateTexture(binding++, t);
}
void DescriptorSet::updateSampler(uint32_t binding,
Gfx::PSampler samplerState) {
PSampler sampler = samplerState.cast<Sampler>();
MTL::ResourceID resourceId = sampler->getHandle()->gpuResourceID();
uint64 offset = binding * 3;
argumentBuffer[offset + 0] = 0;
argumentBuffer[offset + 1] = *(uint64 *)&resourceId;
argumentBuffer[offset + 2] = 0; // LOD bias
}
void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture,
Gfx::PSampler samplerState) {
PTextureBase base = texture.cast<TextureBase>();
if (layout->getBindings()[binding].access ==
Gfx::SE_DESCRIPTOR_ACCESS_READ_ONLY_BIT) {
MTL::ResourceID resourceId = base->getTexture()->gpuResourceID();
uint64 offset = binding * 3;
argumentBuffer[offset + 0] = 0;
argumentBuffer[offset + 1] = *(uint64 *)&resourceId;
argumentBuffer[offset + 2] = 0; // min LOD clamp
} else {
uint64 offset = binding * 3;
argumentBuffer[offset + 0] = base->getTexture()->buffer()->gpuAddress();
argumentBuffer[offset + 1] = 0;
argumentBuffer[offset + 2] =
(uint32)base->getTexture()
->buffer()
->length(); // TODO: buffer texture view, typed??
}
boundResources[binding] = base->getTexture();
}
void DescriptorSet::updateTextureArray(uint32_t binding,
Array<Gfx::PTexture> array) {
for (auto &t : array) {
updateTexture(binding++, t);
} }
} }
PipelineLayout::PipelineLayout(PGraphics graphics, const std::string& name, Gfx::PPipelineLayout baseLayout) PipelineLayout::PipelineLayout(PGraphics graphics, const std::string &name,
Gfx::PPipelineLayout baseLayout)
: Gfx::PipelineLayout(name, baseLayout), graphics(graphics) {} : Gfx::PipelineLayout(name, baseLayout), graphics(graphics) {}
PipelineLayout::~PipelineLayout() {} PipelineLayout::~PipelineLayout() {}
void PipelineLayout::create() { void PipelineLayout::create() {
for (auto& [_, set] : descriptorSetLayouts) { for (auto &[_, set] : descriptorSetLayouts) {
assert(set->getHash() != 0); assert(set->getHash() != 0);
uint32 setHash = set->getHash(); uint32 setHash = set->getHash();
layoutHash = CRC::Calculate(&setHash, sizeof(uint32), CRC::CRC_32(), layoutHash); layoutHash =
CRC::Calculate(&setHash, sizeof(uint32), CRC::CRC_32(), layoutHash);
} }
} }
+1 -1
View File
@@ -31,7 +31,7 @@ void Graphics::init(GraphicsInitializer)
queue = new CommandQueue(this); queue = new CommandQueue(this);
ioQueue = new IOCommandQueue(this); ioQueue = new IOCommandQueue(this);
cache = new PipelineCache(this, "pipelines.metal"); cache = new PipelineCache(this, "pipelines.metal");
meshShadingEnabled = true; meshShadingEnabled = false;
} }
Gfx::OWindow Graphics::createWindow(const WindowCreateInfo &createInfo) Gfx::OWindow Graphics::createWindow(const WindowCreateInfo &createInfo)
+21
View File
@@ -10,6 +10,27 @@
namespace Seele { namespace Seele {
namespace Metal { namespace Metal {
DECLARE_REF(Graphics); DECLARE_REF(Graphics);
class CommandBoundResource
{
public:
CommandBoundResource(PGraphics graphics)
: graphics(graphics)
{
}
virtual ~CommandBoundResource()
{
if (isCurrentlyBound())
abort();
}
constexpr bool isCurrentlyBound() const { return bindCount > 0; }
constexpr void bind() { bindCount++; }
constexpr void unbind() { bindCount--; }
protected:
PGraphics graphics;
uint64 bindCount = 0;
};
DEFINE_REF(CommandBoundResource)
class Fence { class Fence {
public: public:
Fence(PGraphics graphics); Fence(PGraphics graphics);
+21 -13
View File
@@ -14,7 +14,8 @@
using namespace Seele; using namespace Seele;
using namespace Seele::Metal; 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() { Shader::~Shader() {
if (function) { if (function) {
@@ -23,20 +24,27 @@ Shader::~Shader() {
} }
} }
void Shader::create(const ShaderCreateInfo& createInfo) { void Shader::create(const ShaderCreateInfo &createInfo) {
std::cout << "Compiling " << createInfo.name << std::endl; std::cout << "Compiling " << createInfo.name << std::endl;
Map<std::string, uint32> paramMapping; Map<std::string, uint32> paramMapping;
Slang::ComPtr<slang::IBlob> kernelBlob = generateShader(createInfo, SLANG_METAL, paramMapping); Slang::ComPtr<slang::IBlob> kernelBlob =
std::cout << (char*)kernelBlob->getBufferPointer() << std::endl; generateShader(createInfo, SLANG_METAL, paramMapping);
hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32()); std::cout << (char*)kernelBlob->getBufferPointer() << std::endl;
dispatch_data_t dispatchData = dispatch_data_create(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), dispatch_get_main_queue(), NULL); hash = CRC::Calculate(kernelBlob->getBufferPointer(),
NS::Error* error; kernelBlob->getBufferSize(), CRC::CRC_32());
library = graphics->getDevice()->newLibrary(dispatchData, &error); NS::Error *error;
if(error) MTL::CompileOptions *options = MTL::CompileOptions::alloc()->init();
{ library = graphics->getDevice()->newLibrary(
std::cout << error->localizedDescription()->cString(NS::ASCIIStringEncoding) << std::endl; NS::String::string((char *)kernelBlob->getBufferPointer(),
} NS::ASCIIStringEncoding),
function = library->newFunction(NS::String::string("main", NS::ASCIIStringEncoding)); options, &error);
options->release();
if (error) {
std::cout << error->localizedDescription()->cString(NS::ASCIIStringEncoding)
<< std::endl;
}
function =
library->newFunction(NS::String::string(createInfo.entryPoint.c_str(), NS::ASCIIStringEncoding));
if (!function) { if (!function) {
assert(false); assert(false);
} }
+396 -348
View File
@@ -5,462 +5,510 @@ using namespace Seele;
using namespace Seele::Vulkan; using namespace Seele::Vulkan;
BufferAllocation::BufferAllocation(PGraphics graphics) BufferAllocation::BufferAllocation(PGraphics graphics)
: CommandBoundResource(graphics) : CommandBoundResource(graphics) {}
{
}
BufferAllocation::~BufferAllocation() BufferAllocation::~BufferAllocation() {
{ if (buffer != VK_NULL_HANDLE) {
if (buffer != VK_NULL_HANDLE) vmaDestroyBuffer(graphics->getAllocator(), buffer, allocation);
{ }
vmaDestroyBuffer(graphics->getAllocator(), buffer, allocation);
}
} }
struct PendingBuffer { struct PendingBuffer {
OBufferAllocation allocation; OBufferAllocation allocation;
uint64 offset; uint64 offset;
Gfx::QueueType prevQueue; Gfx::QueueType prevQueue;
bool writeOnly; bool writeOnly;
}; };
static Map<Vulkan::Buffer*, PendingBuffer> pendingBuffers; static Map<Vulkan::Buffer *, PendingBuffer> pendingBuffers;
Buffer::Buffer(PGraphics graphics, uint64 size, VkBufferUsageFlags usage, Gfx::QueueType& queueType, bool dynamic, Buffer::Buffer(PGraphics graphics, uint64 size, VkBufferUsageFlags usage,
std::string name) Gfx::QueueType &queueType, bool dynamic, std::string name)
: graphics(graphics), currentBuffer(0), owner(queueType), usage(usage | VK_BUFFER_USAGE_TRANSFER_DST_BIT), dynamic(dynamic), name(name) { : graphics(graphics), currentBuffer(0), owner(queueType),
createBuffer(size); usage(usage | VK_BUFFER_USAGE_TRANSFER_DST_BIT), dynamic(dynamic),
name(name) {
createBuffer(size);
} }
Buffer::~Buffer() { Buffer::~Buffer() {
for (uint32 i = 0; i < buffers.size(); ++i) { for (uint32 i = 0; i < buffers.size(); ++i) {
graphics->getDestructionManager()->queueResourceForDestruction(std::move(buffers[i])); graphics->getDestructionManager()->queueResourceForDestruction(
} std::move(buffers[i]));
}
} }
void Buffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { void Buffer::executeOwnershipBarrier(Gfx::QueueType newOwner) {
if (getSize() == 0) if (getSize() == 0)
return; return;
Gfx::QueueFamilyMapping mapping = graphics->getFamilyMapping(); Gfx::QueueFamilyMapping mapping = graphics->getFamilyMapping();
VkBufferMemoryBarrier barrier = { VkBufferMemoryBarrier barrier = {
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
.pNext = nullptr, .pNext = nullptr,
.srcQueueFamilyIndex = mapping.getQueueTypeFamilyIndex(owner), .srcQueueFamilyIndex = mapping.getQueueTypeFamilyIndex(owner),
.dstQueueFamilyIndex = mapping.getQueueTypeFamilyIndex(newOwner), .dstQueueFamilyIndex = mapping.getQueueTypeFamilyIndex(newOwner),
.buffer = getHandle(), .buffer = getHandle(),
.offset = 0, .offset = 0,
.size = getSize(), .size = getSize(),
}; };
PCommandPool sourcePool = graphics->getQueueCommands(owner); PCommandPool sourcePool = graphics->getQueueCommands(owner);
PCommandPool dstPool = nullptr; PCommandPool dstPool = nullptr;
VkPipelineStageFlags srcStage = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; VkPipelineStageFlags srcStage = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
VkPipelineStageFlags dstStage = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; VkPipelineStageFlags dstStage = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
assert(barrier.srcQueueFamilyIndex != barrier.dstQueueFamilyIndex); assert(barrier.srcQueueFamilyIndex != barrier.dstQueueFamilyIndex);
if (owner == Gfx::QueueType::TRANSFER) { if (owner == Gfx::QueueType::TRANSFER) {
barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
srcStage = VK_PIPELINE_STAGE_TRANSFER_BIT; srcStage = VK_PIPELINE_STAGE_TRANSFER_BIT;
} } else if (owner == Gfx::QueueType::COMPUTE) {
else if (owner == Gfx::QueueType::COMPUTE) { barrier.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT;
barrier.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT; srcStage = VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
srcStage = VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT; } else if (owner == Gfx::QueueType::GRAPHICS) {
} barrier.srcAccessMask = getSourceAccessMask();
else if (owner == Gfx::QueueType::GRAPHICS) { srcStage = VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT;
barrier.srcAccessMask = getSourceAccessMask(); }
srcStage = VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT; if (newOwner == Gfx::QueueType::TRANSFER) {
} barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
if (newOwner == Gfx::QueueType::TRANSFER) { dstStage = VK_PIPELINE_STAGE_TRANSFER_BIT;
barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; dstPool = graphics->getTransferCommands();
dstStage = VK_PIPELINE_STAGE_TRANSFER_BIT; } else if (newOwner == Gfx::QueueType::COMPUTE) {
dstPool = graphics->getTransferCommands(); barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
} dstStage = VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
else if (newOwner == Gfx::QueueType::COMPUTE) { dstPool = graphics->getComputeCommands();
barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; } else if (newOwner == Gfx::QueueType::GRAPHICS) {
dstStage = VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT; barrier.dstAccessMask = getDestAccessMask();
dstPool = graphics->getComputeCommands(); dstStage = VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT;
} dstPool = graphics->getGraphicsCommands();
else if (newOwner == Gfx::QueueType::GRAPHICS) { }
barrier.dstAccessMask = getDestAccessMask(); VkCommandBuffer srcCommand = sourcePool->getCommands()->getHandle();
dstStage = VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT; VkCommandBuffer dstCommand = dstPool->getCommands()->getHandle();
dstPool = graphics->getGraphicsCommands(); vkCmdPipelineBarrier(srcCommand, srcStage, srcStage, 0, 0, nullptr, 1,
} &barrier, 0, nullptr);
VkCommandBuffer srcCommand = sourcePool->getCommands()->getHandle(); vkCmdPipelineBarrier(dstCommand, dstStage, dstStage, 0, 0, nullptr, 1,
VkCommandBuffer dstCommand = dstPool->getCommands()->getHandle(); &barrier, 0, nullptr);
vkCmdPipelineBarrier(srcCommand, srcStage, srcStage, 0, 0, nullptr, 1, &barrier, 0, nullptr); sourcePool->submitCommands();
vkCmdPipelineBarrier(dstCommand, dstStage, dstStage, 0, 0, nullptr, 1, &barrier, 0, nullptr);
sourcePool->submitCommands();
} }
void Buffer::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, VkAccessFlags dstAccess, void Buffer::executePipelineBarrier(VkAccessFlags srcAccess,
VkPipelineStageFlags dstStage) { VkPipelineStageFlags srcStage,
if (getSize() == 0) VkAccessFlags dstAccess,
return; VkPipelineStageFlags dstStage) {
PCommand commandBuffer = graphics->getQueueCommands(owner)->getCommands(); if (getSize() == 0)
VkBufferMemoryBarrier barrier = { return;
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, PCommand commandBuffer = graphics->getQueueCommands(owner)->getCommands();
.pNext = nullptr, VkBufferMemoryBarrier barrier = {
.srcAccessMask = srcAccess, .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
.dstAccessMask = dstAccess, .pNext = nullptr,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .srcAccessMask = srcAccess,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstAccessMask = dstAccess,
.buffer = getHandle(), .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.offset = 0, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.size = getSize(), .buffer = getHandle(),
}; .offset = 0,
vkCmdPipelineBarrier(commandBuffer->getHandle(), srcStage, dstStage, 0, 0, nullptr, 1, &barrier, 0, .size = getSize(),
nullptr); };
vkCmdPipelineBarrier(commandBuffer->getHandle(), srcStage, dstStage, 0, 0,
nullptr, 1, &barrier, 0, nullptr);
} }
void* Buffer::map(bool writeOnly) { return mapRegion(0, getSize(), writeOnly); } void *Buffer::map(bool writeOnly) { return mapRegion(0, getSize(), writeOnly); }
void* Buffer::mapRegion(uint64 regionOffset, uint64 regionSize, bool writeOnly) { void *Buffer::mapRegion(uint64 regionOffset, uint64 regionSize,
if (regionSize == 0) return nullptr; bool writeOnly) {
void* data = nullptr; if (regionSize == 0)
return nullptr;
void *data = nullptr;
PendingBuffer pending; PendingBuffer pending;
pending.allocation = new BufferAllocation(graphics); pending.allocation = new BufferAllocation(graphics);
pending.allocation->size = regionSize; pending.allocation->size = regionSize;
pending.writeOnly = writeOnly; pending.writeOnly = writeOnly;
pending.prevQueue = owner; pending.prevQueue = owner;
pending.offset = regionOffset; pending.offset = regionOffset;
if (writeOnly) { if (writeOnly) {
if (buffers[currentBuffer]->properties & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) { if (buffers[currentBuffer]->properties &
VK_CHECK(vmaMapMemory(graphics->getAllocator(), buffers[currentBuffer]->allocation, &data)); VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) {
} VK_CHECK(vmaMapMemory(graphics->getAllocator(),
else { buffers[currentBuffer]->allocation, &data));
VkBufferCreateInfo stagingInfo = { } else {
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, VkBufferCreateInfo stagingInfo = {
.pNext = nullptr, .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
.flags = 0, .pNext = nullptr,
.size = regionSize, .flags = 0,
.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT, .size = regionSize,
.sharingMode = VK_SHARING_MODE_EXCLUSIVE, .usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
}; .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
VmaAllocationCreateInfo allocInfo = { };
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT, VmaAllocationCreateInfo allocInfo = {
.usage = VMA_MEMORY_USAGE_AUTO, .flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT |
.requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, VMA_ALLOCATION_CREATE_MAPPED_BIT,
}; .usage = VMA_MEMORY_USAGE_AUTO,
VK_CHECK(vmaCreateBuffer(graphics->getAllocator(), &stagingInfo, &allocInfo, &pending.allocation->buffer, .requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
&pending.allocation->allocation, nullptr)); };
vmaMapMemory(graphics->getAllocator(), pending.allocation->allocation, &data); VK_CHECK(vmaCreateBuffer(graphics->getAllocator(), &stagingInfo,
vmaSetAllocationName(graphics->getAllocator(), pending.allocation->allocation, "MappingStaging"); &allocInfo, &pending.allocation->buffer,
} &pending.allocation->allocation, nullptr));
vmaMapMemory(graphics->getAllocator(), pending.allocation->allocation,
&data);
vmaSetAllocationName(graphics->getAllocator(),
pending.allocation->allocation, "MappingStaging");
} }
else { } else {
assert(false); assert(false);
} }
pendingBuffers[this] = std::move(pending); pendingBuffers[this] = std::move(pending);
assert(data); assert(data);
return data; return data;
} }
void Buffer::unmap() { void Buffer::unmap() {
auto found = pendingBuffers.find(this); auto found = pendingBuffers.find(this);
if (found != pendingBuffers.end()) { if (found != pendingBuffers.end()) {
PendingBuffer& pending = found->value; PendingBuffer &pending = found->value;
if (pending.writeOnly) { if (pending.writeOnly) {
if (buffers[currentBuffer]->properties & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) { if (buffers[currentBuffer]->properties &
vmaUnmapMemory(graphics->getAllocator(), buffers[currentBuffer]->allocation); VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) {
} vmaUnmapMemory(graphics->getAllocator(),
else { buffers[currentBuffer]->allocation);
vmaFlushAllocation(graphics->getAllocator(), pending.allocation->allocation, 0, VK_WHOLE_SIZE); } else {
vmaUnmapMemory(graphics->getAllocator(), pending.allocation->allocation); vmaFlushAllocation(graphics->getAllocator(),
PCommand command = graphics->getQueueCommands(owner)->getCommands(); pending.allocation->allocation, 0, VK_WHOLE_SIZE);
command->bindResource(PBufferAllocation(pending.allocation)); vmaUnmapMemory(graphics->getAllocator(),
VkCommandBuffer cmdHandle = command->getHandle(); pending.allocation->allocation);
PCommand command = graphics->getQueueCommands(owner)->getCommands();
command->bindResource(PBufferAllocation(pending.allocation));
VkCommandBuffer cmdHandle = command->getHandle();
VkBufferCopy region = { VkBufferCopy region = {
.srcOffset = 0, .srcOffset = 0,
.dstOffset = pending.offset, .dstOffset = pending.offset,
.size = pending.allocation->size, .size = pending.allocation->size,
}; };
VkBufferMemoryBarrier barrier = { VkBufferMemoryBarrier barrier = {
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
.pNext = nullptr, .pNext = nullptr,
.srcAccessMask = VK_ACCESS_MEMORY_READ_BIT, .srcAccessMask = VK_ACCESS_MEMORY_READ_BIT,
.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT, .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.buffer = buffers[currentBuffer]->buffer, .buffer = buffers[currentBuffer]->buffer,
.offset = 0, .offset = 0,
.size = buffers[currentBuffer]->size, .size = buffers[currentBuffer]->size,
}; };
vkCmdPipelineBarrier(cmdHandle, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, vkCmdPipelineBarrier(cmdHandle, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
nullptr, 1, &barrier, 0, nullptr); VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 1,
vkCmdCopyBuffer(cmdHandle, pending.allocation->buffer, buffers[currentBuffer]->buffer, 1, &region); &barrier, 0, nullptr);
barrier = { vkCmdCopyBuffer(cmdHandle, pending.allocation->buffer,
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, buffers[currentBuffer]->buffer, 1, &region);
.pNext = nullptr, barrier = {
.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT, .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT, .pNext = nullptr,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstAccessMask = VK_ACCESS_MEMORY_READ_BIT,
.buffer = buffers[currentBuffer]->buffer, .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.offset = 0, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.size = buffers[currentBuffer]->size, .buffer = buffers[currentBuffer]->buffer,
}; .offset = 0,
vkCmdPipelineBarrier(cmdHandle, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, .size = buffers[currentBuffer]->size,
nullptr, 1, &barrier, 0, nullptr); };
graphics->getDestructionManager()->queueResourceForDestruction(std::move(pending.allocation)); vkCmdPipelineBarrier(cmdHandle, VK_PIPELINE_STAGE_TRANSFER_BIT,
} VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
} 1, &barrier, 0, nullptr);
pendingBuffers.erase(this); graphics->getDestructionManager()->queueResourceForDestruction(
std::move(pending.allocation));
}
} }
pendingBuffers.erase(this);
}
} }
void Buffer::rotateBuffer(uint64 size) void Buffer::rotateBuffer(uint64 size) {
{ size = std::max(getSize(), size);
size = std::max(getSize(), size); for (size_t i = 0; i < buffers.size(); ++i) {
for (size_t i = 0; i < buffers.size(); ++i) if (buffers[i]->isCurrentlyBound()) {
{ continue;
if (buffers[i]->isCurrentlyBound())
{
continue;
}
if (buffers[i]->size < size)
{
vmaDestroyBuffer(graphics->getAllocator(), buffers[i]->buffer, buffers[i]->allocation);
VkBufferCreateInfo info = {
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
.pNext = nullptr,
.size = size,
.usage = usage,
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
};
VmaAllocationCreateInfo allocInfo = {
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT |
VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
.usage = VMA_MEMORY_USAGE_AUTO,
};
VK_CHECK(vmaCreateBuffer(graphics->getAllocator(), &info, &allocInfo, &buffers[i]->buffer, &buffers[i]->allocation,
&buffers[i]->info));
vmaGetAllocationMemoryProperties(graphics->getAllocator(), buffers[i]->allocation, &buffers[i]->properties);
if (!name.empty()) {
VkDebugUtilsObjectNameInfoEXT nameInfo = { .sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT,
.pNext = nullptr,
.objectType = VK_OBJECT_TYPE_BUFFER,
.objectHandle = (uint64)buffers[i]->buffer,
.pObjectName = this->name.c_str() };
graphics->vkSetDebugUtilsObjectNameEXT(&nameInfo);
}
buffers[i]->size = size;
}
currentBuffer = i;
return;
} }
createBuffer(size); if (buffers[i]->size < size) {
vmaDestroyBuffer(graphics->getAllocator(), buffers[i]->buffer,
buffers[i]->allocation);
VkBufferCreateInfo info = {
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
.pNext = nullptr,
.size = size,
.usage = usage,
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
};
VmaAllocationCreateInfo allocInfo = {
.flags =
VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT |
VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
.usage = VMA_MEMORY_USAGE_AUTO,
};
VK_CHECK(vmaCreateBuffer(graphics->getAllocator(), &info, &allocInfo,
&buffers[i]->buffer, &buffers[i]->allocation,
&buffers[i]->info));
vmaGetAllocationMemoryProperties(graphics->getAllocator(),
buffers[i]->allocation,
&buffers[i]->properties);
if (!name.empty()) {
VkDebugUtilsObjectNameInfoEXT nameInfo = {
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT,
.pNext = nullptr,
.objectType = VK_OBJECT_TYPE_BUFFER,
.objectHandle = (uint64)buffers[i]->buffer,
.pObjectName = this->name.c_str()};
graphics->vkSetDebugUtilsObjectNameEXT(&nameInfo);
}
buffers[i]->size = size;
}
currentBuffer = i;
return;
}
createBuffer(size);
currentBuffer = buffers.size() - 1;
} }
void Buffer::createBuffer(uint64 size) void Buffer::createBuffer(uint64 size) {
{ VkBufferCreateInfo info = {
VkBufferCreateInfo info = {
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
.pNext = nullptr, .pNext = nullptr,
.size = size, .size = size,
.usage = usage, .usage = usage,
.sharingMode = VK_SHARING_MODE_EXCLUSIVE, .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
}; };
VmaAllocationCreateInfo allocInfo = { VmaAllocationCreateInfo allocInfo = {
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT | .flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT |
VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT, VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
.usage = VMA_MEMORY_USAGE_AUTO, .usage = VMA_MEMORY_USAGE_AUTO,
}; };
buffers.add(new BufferAllocation(graphics)); buffers.add(new BufferAllocation(graphics));
if (size > 0) if (size > 0) {
{ VK_CHECK(vmaCreateBuffer(
VK_CHECK(vmaCreateBuffer(graphics->getAllocator(), &info, &allocInfo, &buffers.back()->buffer, &buffers.back()->allocation, graphics->getAllocator(), &info, &allocInfo, &buffers.back()->buffer,
&buffers.back()->info)); &buffers.back()->allocation, &buffers.back()->info));
buffers.back()->size = size; buffers.back()->size = size;
vmaGetAllocationMemoryProperties(graphics->getAllocator(), buffers.back()->allocation, &buffers.back()->properties); vmaGetAllocationMemoryProperties(graphics->getAllocator(),
if (!name.empty()) { buffers.back()->allocation,
VkDebugUtilsObjectNameInfoEXT nameInfo = { .sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT, &buffers.back()->properties);
.pNext = nullptr, if (!name.empty()) {
.objectType = VK_OBJECT_TYPE_BUFFER, VkDebugUtilsObjectNameInfoEXT nameInfo = {
.objectHandle = (uint64)buffers.back()->buffer, .sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT,
.pObjectName = this->name.c_str() }; .pNext = nullptr,
graphics->vkSetDebugUtilsObjectNameEXT(&nameInfo); .objectType = VK_OBJECT_TYPE_BUFFER,
} .objectHandle = (uint64)buffers.back()->buffer,
.pObjectName = this->name.c_str()};
graphics->vkSetDebugUtilsObjectNameEXT(&nameInfo);
} }
}
} }
UniformBuffer::UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo& createInfo) UniformBuffer::UniformBuffer(PGraphics graphics,
const UniformBufferCreateInfo &createInfo)
: Gfx::UniformBuffer(graphics->getFamilyMapping(), createInfo.sourceData), : Gfx::UniformBuffer(graphics->getFamilyMapping(), createInfo.sourceData),
Vulkan::Buffer(graphics, createInfo.sourceData.size, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, currentOwner, Vulkan::Buffer(graphics, createInfo.sourceData.size,
createInfo.dynamic, createInfo.name) { VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, currentOwner,
if (getSize() > 0 && createInfo.sourceData.data != nullptr) { createInfo.dynamic, createInfo.name) {
void* data = map(); if (getSize() > 0 && createInfo.sourceData.data != nullptr) {
std::memcpy(data, createInfo.sourceData.data, createInfo.sourceData.size); void *data = map();
unmap(); std::memcpy(data, createInfo.sourceData.data, createInfo.sourceData.size);
} unmap();
}
} }
UniformBuffer::~UniformBuffer() {} UniformBuffer::~UniformBuffer() {}
bool UniformBuffer::updateContents(const DataSource& sourceData) { bool UniformBuffer::updateContents(const DataSource &sourceData) {
if (!Gfx::UniformBuffer::updateContents(sourceData)) { if (!Gfx::UniformBuffer::updateContents(sourceData)) {
// no update was performed, skip // no update was performed, skip
return false; return false;
} }
void* data = map(); void *data = map();
std::memcpy(data, sourceData.data, sourceData.size); std::memcpy(data, sourceData.data, sourceData.size);
unmap(); unmap();
return true; return true;
} }
void UniformBuffer::requestOwnershipTransfer(Gfx::QueueType newOwner) { void UniformBuffer::requestOwnershipTransfer(Gfx::QueueType newOwner) {
Gfx::QueueOwnedResource::transferOwnership(newOwner); Gfx::QueueOwnedResource::transferOwnership(newOwner);
} }
void UniformBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { void UniformBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) {
Vulkan::Buffer::executeOwnershipBarrier(newOwner); Vulkan::Buffer::executeOwnershipBarrier(newOwner);
} }
void UniformBuffer::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, void UniformBuffer::executePipelineBarrier(VkAccessFlags srcAccess,
VkAccessFlags dstAccess, VkPipelineStageFlags dstStage) { VkPipelineStageFlags srcStage,
Vulkan::Buffer::executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage); VkAccessFlags dstAccess,
VkPipelineStageFlags dstStage) {
Vulkan::Buffer::executePipelineBarrier(srcAccess, srcStage, dstAccess,
dstStage);
} }
VkAccessFlags UniformBuffer::getSourceAccessMask() { return VK_ACCESS_MEMORY_WRITE_BIT; } VkAccessFlags UniformBuffer::getSourceAccessMask() {
return VK_ACCESS_MEMORY_WRITE_BIT;
}
VkAccessFlags UniformBuffer::getDestAccessMask() { return VK_ACCESS_UNIFORM_READ_BIT; } VkAccessFlags UniformBuffer::getDestAccessMask() {
return VK_ACCESS_UNIFORM_READ_BIT;
}
ShaderBuffer::ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo& sourceData) ShaderBuffer::ShaderBuffer(PGraphics graphics,
: Gfx::ShaderBuffer(graphics->getFamilyMapping(), sourceData.numElements, sourceData.sourceData), const ShaderBufferCreateInfo &sourceData)
Vulkan::Buffer(graphics, sourceData.sourceData.size, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, currentOwner, : Gfx::ShaderBuffer(graphics->getFamilyMapping(), sourceData.numElements,
sourceData.dynamic, sourceData.name) { sourceData.sourceData),
if (getSize() > 0 && sourceData.sourceData.data != nullptr) { Vulkan::Buffer(graphics, sourceData.sourceData.size,
void* data = map(); VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, currentOwner,
std::memcpy(data, sourceData.sourceData.data, sourceData.sourceData.size); sourceData.dynamic, sourceData.name) {
unmap(); if (getSize() > 0 && sourceData.sourceData.data != nullptr) {
} void *data = map();
std::memcpy(data, sourceData.sourceData.data, sourceData.sourceData.size);
unmap();
}
} }
ShaderBuffer::~ShaderBuffer() {} ShaderBuffer::~ShaderBuffer() {}
void ShaderBuffer::updateContents(const ShaderBufferCreateInfo& createInfo) { void ShaderBuffer::updateContents(const ShaderBufferCreateInfo &createInfo) {
Gfx::ShaderBuffer::updateContents(createInfo); Gfx::ShaderBuffer::updateContents(createInfo);
// We always want to update, as the contents could be different on the GPU // We always want to update, as the contents could be different on the GPU
if (createInfo.sourceData.data == nullptr) if (createInfo.sourceData.data == nullptr) {
{ return;
return; }
} void *data = map();
void* data = map(); std::memcpy((char*)data + createInfo.sourceData.offset, createInfo.sourceData.data, createInfo.sourceData.size);
std::memcpy(data, createInfo.sourceData.data, createInfo.sourceData.size); unmap();
unmap();
} }
void Seele::Vulkan::ShaderBuffer::rotateBuffer(uint64 size) void Seele::Vulkan::ShaderBuffer::rotateBuffer(uint64 size) {
{ assert(dynamic);
assert(dynamic); Vulkan::Buffer::rotateBuffer(size);
Vulkan::Buffer::rotateBuffer(size);
} }
void* ShaderBuffer::mapRegion(uint64 offset, uint64 size, bool writeOnly) void *ShaderBuffer::mapRegion(uint64 offset, uint64 size, bool writeOnly) {
{ return Vulkan::Buffer::mapRegion(offset, size, writeOnly);
return Vulkan::Buffer::mapRegion(offset, size, writeOnly);
} }
void ShaderBuffer::unmap() void ShaderBuffer::unmap() { Vulkan::Buffer::unmap(); }
{
Vulkan::Buffer::unmap();
}
void ShaderBuffer::requestOwnershipTransfer(Gfx::QueueType newOwner) { void ShaderBuffer::requestOwnershipTransfer(Gfx::QueueType newOwner) {
Gfx::QueueOwnedResource::transferOwnership(newOwner); Gfx::QueueOwnedResource::transferOwnership(newOwner);
} }
void ShaderBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { void ShaderBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) {
Vulkan::Buffer::executeOwnershipBarrier(newOwner); Vulkan::Buffer::executeOwnershipBarrier(newOwner);
} }
void ShaderBuffer::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, void ShaderBuffer::executePipelineBarrier(VkAccessFlags srcAccess,
VkAccessFlags dstAccess, VkPipelineStageFlags dstStage) { VkPipelineStageFlags srcStage,
Vulkan::Buffer::executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage); VkAccessFlags dstAccess,
VkPipelineStageFlags dstStage) {
Vulkan::Buffer::executePipelineBarrier(srcAccess, srcStage, dstAccess,
dstStage);
} }
VkAccessFlags ShaderBuffer::getSourceAccessMask() { return VK_ACCESS_MEMORY_WRITE_BIT; } VkAccessFlags ShaderBuffer::getSourceAccessMask() {
return VK_ACCESS_MEMORY_WRITE_BIT;
}
VkAccessFlags ShaderBuffer::getDestAccessMask() { return VK_ACCESS_MEMORY_READ_BIT; } VkAccessFlags ShaderBuffer::getDestAccessMask() {
return VK_ACCESS_MEMORY_READ_BIT;
}
VertexBuffer::VertexBuffer(PGraphics graphics, const VertexBufferCreateInfo& sourceData) VertexBuffer::VertexBuffer(PGraphics graphics,
: Gfx::VertexBuffer(graphics->getFamilyMapping(), sourceData.numVertices, sourceData.vertexSize, const VertexBufferCreateInfo &sourceData)
sourceData.sourceData.owner), : Gfx::VertexBuffer(graphics->getFamilyMapping(), sourceData.numVertices,
Vulkan::Buffer(graphics, sourceData.sourceData.size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, currentOwner, false, sourceData.vertexSize, sourceData.sourceData.owner),
sourceData.name) { Vulkan::Buffer(graphics, sourceData.sourceData.size,
if (sourceData.sourceData.data != nullptr) { VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, currentOwner, false,
void* data = map(); sourceData.name) {
std::memcpy(data, sourceData.sourceData.data, sourceData.sourceData.size); if (sourceData.sourceData.data != nullptr) {
unmap(); void *data = map();
} std::memcpy(data, sourceData.sourceData.data, sourceData.sourceData.size);
unmap();
}
} }
VertexBuffer::~VertexBuffer() {} VertexBuffer::~VertexBuffer() {}
void VertexBuffer::updateRegion(DataSource update) { void VertexBuffer::updateRegion(DataSource update) {
void* data = mapRegion(update.offset, update.size); void *data = mapRegion(update.offset, update.size);
std::memcpy(data, update.data, update.size); std::memcpy(data, update.data, update.size);
unmap(); unmap();
} }
void VertexBuffer::download(Array<uint8>& buffer) { void VertexBuffer::download(Array<uint8> &buffer) {
void* data = map(false); void *data = map(false);
buffer.resize(getSize()); buffer.resize(getSize());
std::memcpy(buffer.data(), data, getSize()); std::memcpy(buffer.data(), data, getSize());
unmap(); unmap();
} }
void VertexBuffer::requestOwnershipTransfer(Gfx::QueueType newOwner) { void VertexBuffer::requestOwnershipTransfer(Gfx::QueueType newOwner) {
Gfx::QueueOwnedResource::transferOwnership(newOwner); Gfx::QueueOwnedResource::transferOwnership(newOwner);
} }
void VertexBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { void VertexBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) {
Vulkan::Buffer::executeOwnershipBarrier(newOwner); Vulkan::Buffer::executeOwnershipBarrier(newOwner);
} }
void VertexBuffer::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, void VertexBuffer::executePipelineBarrier(VkAccessFlags srcAccess,
VkAccessFlags dstAccess, VkPipelineStageFlags dstStage) { VkPipelineStageFlags srcStage,
Vulkan::Buffer::executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage); VkAccessFlags dstAccess,
VkPipelineStageFlags dstStage) {
Vulkan::Buffer::executePipelineBarrier(srcAccess, srcStage, dstAccess,
dstStage);
} }
VkAccessFlags VertexBuffer::getSourceAccessMask() { return VK_ACCESS_MEMORY_WRITE_BIT; } VkAccessFlags VertexBuffer::getSourceAccessMask() {
return VK_ACCESS_MEMORY_WRITE_BIT;
}
VkAccessFlags VertexBuffer::getDestAccessMask() { return VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT; } VkAccessFlags VertexBuffer::getDestAccessMask() {
return VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT;
}
IndexBuffer::IndexBuffer(PGraphics graphics, const IndexBufferCreateInfo& sourceData) IndexBuffer::IndexBuffer(PGraphics graphics,
: Gfx::IndexBuffer(graphics->getFamilyMapping(), sourceData.sourceData.size, sourceData.indexType, const IndexBufferCreateInfo &sourceData)
sourceData.sourceData.owner), : Gfx::IndexBuffer(graphics->getFamilyMapping(), sourceData.sourceData.size,
Vulkan::Buffer(graphics, sourceData.sourceData.size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT, currentOwner, false, sourceData.indexType, sourceData.sourceData.owner),
sourceData.name) { Vulkan::Buffer(graphics, sourceData.sourceData.size,
if (sourceData.sourceData.data != nullptr) { VK_BUFFER_USAGE_INDEX_BUFFER_BIT, currentOwner, false,
void* data = map(); sourceData.name) {
std::memcpy(data, sourceData.sourceData.data, sourceData.sourceData.size); if (sourceData.sourceData.data != nullptr) {
unmap(); void *data = map();
} std::memcpy(data, sourceData.sourceData.data, sourceData.sourceData.size);
unmap();
}
} }
IndexBuffer::~IndexBuffer() {} IndexBuffer::~IndexBuffer() {}
void IndexBuffer::download(Array<uint8>& buffer) { void IndexBuffer::download(Array<uint8> &buffer) {
void* data = map(false); void *data = map(false);
buffer.resize(getSize()); buffer.resize(getSize());
std::memcpy(buffer.data(), data, getSize()); std::memcpy(buffer.data(), data, getSize());
unmap(); unmap();
} }
void IndexBuffer::requestOwnershipTransfer(Gfx::QueueType newOwner) { void IndexBuffer::requestOwnershipTransfer(Gfx::QueueType newOwner) {
Gfx::QueueOwnedResource::transferOwnership(newOwner); Gfx::QueueOwnedResource::transferOwnership(newOwner);
} }
void IndexBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { void IndexBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) {
Vulkan::Buffer::executeOwnershipBarrier(newOwner); Vulkan::Buffer::executeOwnershipBarrier(newOwner);
} }
void IndexBuffer::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, void IndexBuffer::executePipelineBarrier(VkAccessFlags srcAccess,
VkAccessFlags dstAccess, VkPipelineStageFlags dstStage) { VkPipelineStageFlags srcStage,
Vulkan::Buffer::executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage); VkAccessFlags dstAccess,
VkPipelineStageFlags dstStage) {
Vulkan::Buffer::executePipelineBarrier(srcAccess, srcStage, dstAccess,
dstStage);
} }
VkAccessFlags IndexBuffer::getSourceAccessMask() { return VK_ACCESS_MEMORY_WRITE_BIT; } VkAccessFlags IndexBuffer::getSourceAccessMask() {
return VK_ACCESS_MEMORY_WRITE_BIT;
}
VkAccessFlags IndexBuffer::getDestAccessMask() { return VK_ACCESS_INDEX_READ_BIT; } VkAccessFlags IndexBuffer::getDestAccessMask() {
return VK_ACCESS_INDEX_READ_BIT;
}
+30 -25
View File
@@ -9,13 +9,13 @@ DECLARE_REF(Command)
DECLARE_REF(Fence) DECLARE_REF(Fence)
class BufferAllocation : public CommandBoundResource { class BufferAllocation : public CommandBoundResource {
public: public:
BufferAllocation(PGraphics graphics); BufferAllocation(PGraphics graphics);
virtual ~BufferAllocation(); virtual ~BufferAllocation();
VkBuffer buffer = VK_NULL_HANDLE; VkBuffer buffer = VK_NULL_HANDLE;
VmaAllocation allocation = VmaAllocation(); VmaAllocation allocation = VmaAllocation();
VmaAllocationInfo info = VmaAllocationInfo(); VmaAllocationInfo info = VmaAllocationInfo();
VkMemoryPropertyFlags properties = 0; VkMemoryPropertyFlags properties = 0;
uint64 size = 0; uint64 size = 0;
}; };
DEFINE_REF(BufferAllocation); DEFINE_REF(BufferAllocation);
class Buffer { class Buffer {
@@ -70,10 +70,11 @@ protected:
virtual void requestOwnershipTransfer(Gfx::QueueType newOwner) override; virtual void requestOwnershipTransfer(Gfx::QueueType newOwner) override;
// Inherited via QueueOwnedResource // Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(Gfx::QueueType newOwner) override; virtual void executeOwnershipBarrier(Gfx::QueueType newOwner) override;
virtual void executePipelineBarrier(Gfx::SeAccessFlags srcAccess, virtual void
Gfx::SePipelineStageFlags srcStage, executePipelineBarrier(Gfx::SeAccessFlags srcAccess,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SePipelineStageFlags dstStage) override; Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) override;
}; };
DEFINE_REF(VertexBuffer) DEFINE_REF(VertexBuffer)
@@ -91,10 +92,11 @@ protected:
virtual void requestOwnershipTransfer(Gfx::QueueType newOwner) override; virtual void requestOwnershipTransfer(Gfx::QueueType newOwner) override;
// Inherited via QueueOwnedResource // Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(Gfx::QueueType newOwner) override; virtual void executeOwnershipBarrier(Gfx::QueueType newOwner) override;
virtual void executePipelineBarrier(Gfx::SeAccessFlags srcAccess, virtual void
Gfx::SePipelineStageFlags srcStage, executePipelineBarrier(Gfx::SeAccessFlags srcAccess,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SePipelineStageFlags dstStage) override; Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) override;
}; };
DEFINE_REF(IndexBuffer) DEFINE_REF(IndexBuffer)
class UniformBuffer : public Gfx::UniformBuffer, public Buffer { class UniformBuffer : public Gfx::UniformBuffer, public Buffer {
@@ -110,10 +112,11 @@ protected:
virtual void requestOwnershipTransfer(Gfx::QueueType newOwner) override; virtual void requestOwnershipTransfer(Gfx::QueueType newOwner) override;
// Inherited via QueueOwnedResource // Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(Gfx::QueueType newOwner) override; virtual void executeOwnershipBarrier(Gfx::QueueType newOwner) override;
virtual void executePipelineBarrier(Gfx::SeAccessFlags srcAccess, virtual void
Gfx::SePipelineStageFlags srcStage, executePipelineBarrier(Gfx::SeAccessFlags srcAccess,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SePipelineStageFlags dstStage) override; Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) override;
private: private:
}; };
@@ -123,9 +126,10 @@ class ShaderBuffer : public Gfx::ShaderBuffer, public Buffer {
public: public:
ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo &sourceData); ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo &sourceData);
virtual ~ShaderBuffer(); virtual ~ShaderBuffer();
virtual void updateContents(const ShaderBufferCreateInfo &createInfo) override; virtual void
updateContents(const ShaderBufferCreateInfo &createInfo) override;
virtual void rotateBuffer(uint64 size) override; virtual void rotateBuffer(uint64 size) override;
virtual void* mapRegion(uint64 offset, uint64 size, bool writeOnly) override; virtual void *mapRegion(uint64 offset, uint64 size, bool writeOnly) override;
virtual void unmap() override; virtual void unmap() override;
protected: protected:
@@ -135,10 +139,11 @@ protected:
virtual void requestOwnershipTransfer(Gfx::QueueType newOwner) override; virtual void requestOwnershipTransfer(Gfx::QueueType newOwner) override;
// Inherited via QueueOwnedResource // Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(Gfx::QueueType newOwner) override; virtual void executeOwnershipBarrier(Gfx::QueueType newOwner) override;
virtual void executePipelineBarrier(Gfx::SeAccessFlags srcAccess, virtual void
Gfx::SePipelineStageFlags srcStage, executePipelineBarrier(Gfx::SeAccessFlags srcAccess,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SePipelineStageFlags dstStage) override; Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) override;
private: private:
}; };
+2 -2
View File
@@ -23,9 +23,9 @@ Slang::ComPtr<slang::IBlob> Seele::generateShader(const ShaderCreateInfo& create
option[1].name = slang::CompilerOptionName::EmitSpirvViaGLSL; option[1].name = slang::CompilerOptionName::EmitSpirvViaGLSL;
option[1].value.kind = slang::CompilerOptionValueKind::Int; option[1].value.kind = slang::CompilerOptionValueKind::Int;
option[1].value.intValue0 = 1; option[1].value.intValue0 = 1;
option[2].name = slang::CompilerOptionName::DebugInformation; option[2].name = slang::CompilerOptionName::EmitIr;
option[2].value.kind = slang::CompilerOptionValueKind::Int; option[2].value.kind = slang::CompilerOptionValueKind::Int;
option[2].value.intValue0 = SLANG_DEBUG_INFO_LEVEL_NONE; option[2].value.intValue0 = 1;
option[3].name = slang::CompilerOptionName::DebugInformationFormat; option[3].name = slang::CompilerOptionName::DebugInformationFormat;
option[3].value.kind = slang::CompilerOptionValueKind::Int; option[3].value.kind = slang::CompilerOptionValueKind::Int;
option[3].value.intValue0 = SLANG_DEBUG_INFO_FORMAT_C7; option[3].value.intValue0 = SLANG_DEBUG_INFO_FORMAT_C7;
+1 -1
View File
@@ -22,7 +22,7 @@ public:
Gfx::PDescriptorLayout getDescriptorLayout() { return layout; } Gfx::PDescriptorLayout getDescriptorLayout() { return layout; }
OMaterialInstance instantiate(); OMaterialInstance instantiate();
const std::string& getName() const { return materialName; } const std::string& getName() const { return materialName; }
constexpr const uint64 getId() const { return materialId; } constexpr uint64 getId() const { return materialId; }
static constexpr const PMaterial findMaterialById(uint64 id) { return materials[id]; } static constexpr const PMaterial findMaterialById(uint64 id) { return materials[id]; }
void save(ArchiveBuffer& buffer) const; void save(ArchiveBuffer& buffer) const;