Lot more Metal changes

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