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