Fixing metal swapchain

This commit is contained in:
Dynamitos
2024-04-18 13:33:35 +02:00
parent a72e92ee37
commit 21636f2460
11 changed files with 291 additions and 298 deletions
+10 -8
View File
@@ -78,7 +78,6 @@ target_link_libraries(Engine PUBLIC crcpp)
target_link_libraries(Engine PUBLIC fmt::fmt) target_link_libraries(Engine PUBLIC fmt::fmt)
target_link_libraries(Engine PUBLIC GPUOpen::VulkanMemoryAllocator) target_link_libraries(Engine PUBLIC GPUOpen::VulkanMemoryAllocator)
target_link_libraries(Engine PUBLIC slang) target_link_libraries(Engine PUBLIC slang)
target_link_libraries(Engine PUBLIC spirv-cross-glsl spirv-cross-msl)
target_link_libraries(Engine PUBLIC glslang::glslang) target_link_libraries(Engine PUBLIC glslang::glslang)
if(APPLE) if(APPLE)
target_include_directories(Engine PUBLIC /usr/local/include) target_include_directories(Engine PUBLIC /usr/local/include)
@@ -108,11 +107,11 @@ if(MSVC)
target_compile_options(Editor PUBLIC /std:c++20 /Zi /MP14 /W4 /DEBUG) target_compile_options(Editor PUBLIC /std:c++20 /Zi /MP14 /W4 /DEBUG)
target_sources(Engine INTERFACE target_sources(Engine INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Seele.natvis> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Seele.natvis>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/Seele.natvis> $<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/Seele/Seele.natvis>
) )
install(FILES install(FILES
Seele.natvis Seele.natvis
DESTINATION .) DESTINATION Seele/)
else() else()
target_compile_options(Engine PUBLIC -g -Wall -Wextra -Wno-error -pedantic -std=c++20 -Wno-missing-field-initializers -Wno-unused-function -fsanitize=address) target_compile_options(Engine PUBLIC -g -Wall -Wextra -Wno-error -pedantic -std=c++20 -Wno-missing-field-initializers -Wno-unused-function -fsanitize=address)
target_compile_options(Editor PUBLIC -g -Wall -Wextra -Wno-error -pedantic -std=c++20 -fsanitize=address) target_compile_options(Editor PUBLIC -g -Wall -Wextra -Wno-error -pedantic -std=c++20 -fsanitize=address)
@@ -161,7 +160,7 @@ install(
EXPORT EXPORT
EngineTargets EngineTargets
FILE_SET HEADERS FILE_SET HEADERS
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}/include) DESTINATION ${CMAKE_INSTALL_PREFIX}/include/Seele)
export(EXPORT EngineTargets export(EXPORT EngineTargets
FILE "${CMAKE_BINARY_DIR}/EngineTargets.cmake" FILE "${CMAKE_BINARY_DIR}/EngineTargets.cmake"
@@ -179,19 +178,22 @@ install(EXPORT EngineTargets
NAMESPACE NAMESPACE
Seele:: Seele::
DESTINATION DESTINATION
${CMAKE_INSTALL_PREFIX} ${CMAKE_INSTALL_PREFIX}/lib/cmake/Seele
) )
install( install(
FILES FILES
${CMAKE_BINARY_DIR}/SeeleConfig.cmake ${CMAKE_BINARY_DIR}/SeeleConfig.cmake
DESTINATION DESTINATION
${CMAKE_INSTALL_PREFIX} ${CMAKE_INSTALL_PREFIX}/lib/cmake/Seele
) )
install( install(
DIRECTORY DIRECTORY
${CMAKE_SOURCE_DIR}/res ${CMAKE_SOURCE_DIR}/res/cmake
${CMAKE_SOURCE_DIR}/res/fonts
${CMAKE_SOURCE_DIR}/res/shaders
${CMAKE_SOURCE_DIR}/res/textures
DESTINATION DESTINATION
${CMAKE_INSTALL_PREFIX} ${CMAKE_INSTALL_PREFIX}/bin
) )
+2 -2
View File
@@ -39,12 +39,12 @@ add_library(crcpp INTERFACE)
target_include_directories(crcpp INTERFACE target_include_directories(crcpp INTERFACE
$<BUILD_INTERFACE:${CRCPP_ROOT}/inc> $<BUILD_INTERFACE:${CRCPP_ROOT}/inc>
$<INSTALL_INTERFACE:include> $<INSTALL_INTERFACE:include/Seele/>
) )
install(FILES install(FILES
${CRCPP_ROOT}/inc/CRC.h ${CRCPP_ROOT}/inc/CRC.h
DESTINATION ${CMAKE_INSTALL_PREFIX}/include DESTINATION ${CMAKE_INSTALL_PREFIX}/include/Seele
) )
add_library(metal INTERFACE) add_library(metal INTERFACE)
+1 -1
View File
@@ -31,5 +31,5 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target
//uint lightIndex = pLightCullingData.lightIndexList[startOffset + i]; //uint lightIndex = pLightCullingData.lightIndexList[startOffset + i];
result += pLightEnv.pointLights[i].illuminate(lightingParams, brdf); result += pLightEnv.pointLights[i].illuminate(lightingParams, brdf);
} }
return float4(params.vertexColor, 1.0f); return float4(1.0f, 0.1f, 0.5f, 1.0f);
} }
+174 -178
View File
@@ -1,20 +1,17 @@
#include "Graphics/Initializer.h"
#include "Graphics/Metal/Graphics.h"
#include "Window/WindowManager.h"
#include "Window/SceneView.h"
#include "Window/PlayView.h"
#include "Window/InspectorView.h"
#include "Asset/AssetRegistry.h"
#include "Asset/AssetImporter.h" #include "Asset/AssetImporter.h"
#include "Asset/TextureLoader.h" #include "Asset/AssetRegistry.h"
#include "Graphics/Vulkan/Graphics.h" #include "Asset/FontLoader.h"
#include "Graphics/Metal/Graphics.h" #include "Asset/MaterialLoader.h"
#include "Asset/MeshLoader.h" #include "Asset/MeshLoader.h"
#include "Asset/TextureLoader.h" #include "Asset/TextureLoader.h"
#include "Asset/MaterialLoader.h" #include "Graphics/Initializer.h"
#include "Asset/FontLoader.h" #include "Graphics/Metal/Graphics.h"
#include "Asset/AssetImporter.h"
#include "Graphics/StaticMeshVertexData.h" #include "Graphics/StaticMeshVertexData.h"
#include "Graphics/Vulkan/Graphics.h"
#include "Window/InspectorView.h"
#include "Window/PlayView.h"
#include "Window/SceneView.h"
#include "Window/WindowManager.h"
#include <fmt/core.h> #include <fmt/core.h>
using namespace Seele; using namespace Seele;
@@ -23,22 +20,21 @@ using namespace Seele::Editor;
// make it global so it gets deleted last and automatically // make it global so it gets deleted last and automatically
static Gfx::OGraphics graphics; static Gfx::OGraphics graphics;
int main() int main() {
{
#ifdef WIN32 #ifdef WIN32
std::filesystem::path outputPath = "C:/Users/Dynamitos/TrackClearGame"; std::filesystem::path outputPath = "C:/Users/Dynamitos/MeshShadingDemoGame";
std::filesystem::path sourcePath= "C:/Users/Dynamitos/TrackClear"; std::filesystem::path sourcePath = "C:/Users/Dynamitos/MeshShadingDemo";
std::filesystem::path binaryPath = sourcePath / "bin" / "TrackClear.dll"; std::filesystem::path binaryPath = sourcePath / "bin" / "MeshShadingDemo.dll";
#elif __APPLE__ #elif __APPLE__
std::filesystem::path outputPath = "/Users/dynamitos/TrackClearGame"; std::filesystem::path outputPath = "/Users/dynamitos/MeshShadingDemoGame";
std::filesystem::path sourcePath= "/Users/dynamitos/TrackClear"; std::filesystem::path sourcePath = "/Users/dynamitos/MeshShadingDemo";
std::filesystem::path binaryPath = sourcePath / "cmake" / "libTrackClear.dylib"; std::filesystem::path binaryPath = sourcePath / "cmake" / "libMeshShadingDemo.dylib";
#else #else
std::filesystem::path outputPath = "/home/dynamitos/TrackClearGame"; std::filesystem::path outputPath = "/home/dynamitos/MeshShadingDemoGame";
std::filesystem::path sourcePath= "/home/dynamitos/TrackClear"; std::filesystem::path sourcePath = "/home/dynamitos/MeshShadingDemo";
std::filesystem::path binaryPath = sourcePath / "cmake" / "libTrackClear.so"; std::filesystem::path binaryPath = sourcePath / "cmake" / "libMeshShadingDemo.so";
#endif #endif
std::string gameName = "TrackClear"; std::string gameName = "MeshShadingDemo";
std::filesystem::path cmakePath = outputPath / "cmake"; std::filesystem::path cmakePath = outputPath / "cmake";
#ifdef __APPLE__ #ifdef __APPLE__
@@ -59,17 +55,17 @@ int main()
// AssetImporter::importMesh(MeshImportArgs{ // AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "old_resources/models/arena.fbx", // .filePath = sourcePath / "old_resources/models/arena.fbx",
// }); // });
AssetImporter::importMesh(MeshImportArgs{ // AssetImporter::importMesh(MeshImportArgs{
.filePath = sourcePath / "old_resources/models/frog.fbx", // .filePath = sourcePath / "old_resources/models/frog.fbx",
}); // });
AssetImporter::importMesh(MeshImportArgs{ // AssetImporter::importMesh(MeshImportArgs{
.filePath = sourcePath / "old_resources/models/train.fbx", // .filePath = sourcePath / "old_resources/models/train.fbx",
}); // });
// AssetImporter::importMesh(MeshImportArgs{ // AssetImporter::importMesh(MeshImportArgs{
// .filePath= sourcePath / "old_resources/models/bird.fbx", // .filePath= sourcePath / "old_resources/models/bird.fbx",
// }); // });
AssetImporter::importMesh(MeshImportArgs{ AssetImporter::importMesh(MeshImportArgs{
.filePath= sourcePath / "old_resources/models/cube.fbx", .filePath = sourcePath / "import/models/cube.fbx",
}); });
// AssetImporter::importMesh(MeshImportArgs{ // AssetImporter::importMesh(MeshImportArgs{
// .filePath= sourcePath / "old_resources/models/flameThrower.fbx", // .filePath= sourcePath / "old_resources/models/flameThrower.fbx",
@@ -87,146 +83,146 @@ int main()
// .filePath= sourcePath / "old_resources/models/zombie.fbx", // .filePath= sourcePath / "old_resources/models/zombie.fbx",
// }); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/Dirt.png", // .filePath= sourcePath / "old_resources/textures/Dirt.png",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/DirtGrass.png", // .filePath= sourcePath / "old_resources/textures/DirtGrass.png",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/Grass.png", // .filePath= sourcePath / "old_resources/textures/Grass.png",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/Ice.png", // .filePath= sourcePath / "old_resources/textures/Ice.png",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/Lava.png", // .filePath= sourcePath / "old_resources/textures/Lava.png",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/Obsidian.png", // .filePath= sourcePath / "old_resources/textures/Obsidian.png",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/Rocks.png", // .filePath= sourcePath / "old_resources/textures/Rocks.png",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/Sand.png", // .filePath= sourcePath / "old_resources/textures/Sand.png",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/Water.png", // .filePath= sourcePath / "old_resources/textures/Water.png",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/Wood.png", // .filePath= sourcePath / "old_resources/textures/Wood.png",
}); // });
//
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/level0/blendMap.png", // .filePath= sourcePath / "old_resources/textures/level0/blendMap.png",
.importPath = "level0", // .importPath = "level0",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/level0/heightMap.png", // .filePath= sourcePath / "old_resources/textures/level0/heightMap.png",
.importPath = "level0", // .importPath = "level0",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/level0/trackMap.png", // .filePath= sourcePath / "old_resources/textures/level0/trackMap.png",
.importPath = "level0", // .importPath = "level0",
}); // });
AssetImporter::importMaterial(MaterialImportArgs{ // AssetImporter::importMaterial(MaterialImportArgs{
.filePath= sourcePath / "old_resources/shaders/TerrainMaterial.json", // .filePath= sourcePath / "old_resources/shaders/TerrainMaterial.json",
.importPath = "level0", // .importPath = "level0",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/level1/blendMap.png", // .filePath= sourcePath / "old_resources/textures/level1/blendMap.png",
.importPath = "level1", // .importPath = "level1",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/level1/heightMap.png", // .filePath= sourcePath / "old_resources/textures/level1/heightMap.png",
.importPath = "level1", // .importPath = "level1",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/level1/trackMap.png", // .filePath= sourcePath / "old_resources/textures/level1/trackMap.png",
.importPath = "level1", // .importPath = "level1",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/level2/blendMap.png", // .filePath= sourcePath / "old_resources/textures/level2/blendMap.png",
.importPath = "level2", // .importPath = "level2",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/level2/heightMap.png", // .filePath= sourcePath / "old_resources/textures/level2/heightMap.png",
.importPath = "level2", // .importPath = "level2",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/level2/trackMap.png", // .filePath= sourcePath / "old_resources/textures/level2/trackMap.png",
.importPath = "level2", // .importPath = "level2",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/level3/blendMap.png", // .filePath= sourcePath / "old_resources/textures/level3/blendMap.png",
.importPath = "level3", // .importPath = "level3",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/level3/heightMap.png", // .filePath= sourcePath / "old_resources/textures/level3/heightMap.png",
.importPath = "level3", // .importPath = "level3",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/level3/trackMap.png", // .filePath= sourcePath / "old_resources/textures/level3/trackMap.png",
.importPath = "level3", // .importPath = "level3",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/level4/blendMap.png", // .filePath= sourcePath / "old_resources/textures/level4/blendMap.png",
.importPath = "level4", // .importPath = "level4",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/level4/heightMap.png", // .filePath= sourcePath / "old_resources/textures/level4/heightMap.png",
.importPath = "level4", // .importPath = "level4",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/level4/trackMap.png", // .filePath= sourcePath / "old_resources/textures/level4/trackMap.png",
.importPath = "level4", // .importPath = "level4",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/level5/blendMap.png", // .filePath= sourcePath / "old_resources/textures/level5/blendMap.png",
.importPath = "level5", // .importPath = "level5",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/level5/heightMap.png", // .filePath= sourcePath / "old_resources/textures/level5/heightMap.png",
.importPath = "level5", // .importPath = "level5",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/level5/trackMap.png", // .filePath= sourcePath / "old_resources/textures/level5/trackMap.png",
.importPath = "level5", // .importPath = "level5",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/level6/blendMap.png", // .filePath= sourcePath / "old_resources/textures/level6/blendMap.png",
.importPath = "level6", // .importPath = "level6",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/level6/heightMap.png", // .filePath= sourcePath / "old_resources/textures/level6/heightMap.png",
.importPath = "level6", // .importPath = "level6",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/level6/trackMap.png", // .filePath= sourcePath / "old_resources/textures/level6/trackMap.png",
.importPath = "level6", // .importPath = "level6",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/level7/blendMap.png", // .filePath= sourcePath / "old_resources/textures/level7/blendMap.png",
.importPath = "level7", // .importPath = "level7",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/level7/heightMap.png", // .filePath= sourcePath / "old_resources/textures/level7/heightMap.png",
.importPath = "level7", // .importPath = "level7",
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/textures/level7/trackMap.png", // .filePath= sourcePath / "old_resources/textures/level7/trackMap.png",
.importPath = "level7", // .importPath = "level7",
}); // });
//
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/skyboxes/FS000_Day_01.png", // .filePath= sourcePath / "old_resources/skyboxes/FS000_Day_01.png",
.type = TextureImportType::TEXTURE_CUBEMAP, // .type = TextureImportType::TEXTURE_CUBEMAP,
}); // });
AssetImporter::importTexture(TextureImportArgs{ // AssetImporter::importTexture(TextureImportArgs{
.filePath= sourcePath / "old_resources/skyboxes/FS000_Night_01.png", // .filePath= sourcePath / "old_resources/skyboxes/FS000_Night_01.png",
.type = TextureImportType::TEXTURE_CUBEMAP, // .type = TextureImportType::TEXTURE_CUBEMAP,
}); // });
WindowCreateInfo mainWindowInfo; WindowCreateInfo mainWindowInfo;
mainWindowInfo.title = "SeeleEngine"; mainWindowInfo.title = "SeeleEngine";
@@ -251,17 +247,17 @@ int main()
// window->addView(inspectorView); // window->addView(inspectorView);
sceneView->setFocused(); sceneView->setFocused();
while (windowManager->isActive()) {
while (windowManager->isActive())
{
windowManager->render(); windowManager->render();
} }
vd->destroy(); vd->destroy();
// export game // export game
if (false) if (false) {
{
std::filesystem::create_directories(outputPath); std::filesystem::create_directories(outputPath);
std::system(fmt::format("cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DGAME_TITLE=\"{}\" -DGAME_DESTINATION=\"{}\" -DGAME_BINARY=\"{}\" -P ./cmake/ExportProject.cmake", gameName, outputPath.generic_string(), binaryPath.generic_string()).c_str()); std::system(fmt::format("cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DGAME_TITLE=\"{}\" -DGAME_DESTINATION=\"{}\" "
"-DGAME_BINARY=\"{}\" -P ./cmake/ExportProject.cmake",
gameName, outputPath.generic_string(), binaryPath.generic_string())
.c_str());
std::system(fmt::format("cmake -S {} -B {}", cmakePath.generic_string(), cmakePath.generic_string()).c_str()); std::system(fmt::format("cmake -S {} -B {}", cmakePath.generic_string(), cmakePath.generic_string()).c_str());
std::system(fmt::format("cmake --build {}", cmakePath.generic_string()).c_str()); std::system(fmt::format("cmake --build {}", cmakePath.generic_string()).c_str());
std::filesystem::copy(sourcePath / "Assets", outputPath / "Assets", std::filesystem::copy_options::recursive); std::filesystem::copy(sourcePath / "Assets", outputPath / "Assets", std::filesystem::copy_options::recursive);
+1
View File
@@ -25,6 +25,7 @@ void Command::beginRenderPass(PRenderPass renderPass) {
blitEncoder->endEncoding(); blitEncoder->endEncoding();
blitEncoder = nullptr; blitEncoder = nullptr;
} }
renderPass->updateRenderPass();
parallelEncoder = cmdBuffer->parallelRenderCommandEncoder(renderPass->getDescriptor()); parallelEncoder = cmdBuffer->parallelRenderCommandEncoder(renderPass->getDescriptor());
} }
+1 -1
View File
@@ -31,7 +31,7 @@ void Graphics::init(GraphicsInitializer)
queue = new CommandQueue(this); queue = new CommandQueue(this);
ioQueue = new IOCommandQueue(this); ioQueue = new IOCommandQueue(this);
cache = new PipelineCache(this, "pipelines.metal"); cache = new PipelineCache(this, "pipelines.metal");
meshShadingEnabled = true; meshShadingEnabled = false;
} }
Gfx::OWindow Graphics::createWindow(const WindowCreateInfo &createInfo) Gfx::OWindow Graphics::createWindow(const WindowCreateInfo &createInfo)
+1 -2
View File
@@ -12,6 +12,7 @@ class RenderPass : public Gfx::RenderPass
public: public:
RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout, Array<Gfx::SubPassDependency> dependencies, Gfx::PViewport viewport); RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout, Array<Gfx::SubPassDependency> dependencies, Gfx::PViewport viewport);
virtual ~RenderPass(); virtual ~RenderPass();
void updateRenderPass();
MTL::RenderPassDescriptor* getDescriptor() const MTL::RenderPassDescriptor* getDescriptor() const
{ {
return renderPass; return renderPass;
@@ -20,8 +21,6 @@ private:
PGraphics graphics; PGraphics graphics;
Gfx::PViewport viewport; Gfx::PViewport viewport;
MTL::RenderPassDescriptor* renderPass; MTL::RenderPassDescriptor* renderPass;
MTL::RenderPassDepthAttachmentDescriptor* depth;
MTL::RenderPassStencilAttachmentDescriptor* stencil;
}; };
DEFINE_REF(RenderPass) DEFINE_REF(RenderPass)
} // namespace Metal } // namespace Metal
+21 -23
View File
@@ -7,12 +7,10 @@
using namespace Seele; using namespace Seele;
using namespace Seele::Metal; using namespace Seele::Metal;
RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout, RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout, Array<Gfx::SubPassDependency> dependencies,
Array<Gfx::SubPassDependency> dependencies,
Gfx::PViewport viewport) Gfx::PViewport viewport)
: Gfx::RenderPass(layout, dependencies), graphics(graphics), : Gfx::RenderPass(layout, dependencies), graphics(graphics), viewport(viewport) {
viewport(viewport) { renderPass = MTL::RenderPassDescriptor::renderPassDescriptor();
renderPass = MTL::RenderPassDescriptor::alloc()->init();
renderPass->setRenderTargetArrayLength(1); renderPass->setRenderTargetArrayLength(1);
renderPass->setRenderTargetWidth(viewport->getWidth()); renderPass->setRenderTargetWidth(viewport->getWidth());
renderPass->setRenderTargetHeight(viewport->getHeight()); renderPass->setRenderTargetHeight(viewport->getHeight());
@@ -20,42 +18,42 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout,
for (size_t i = 0; i < layout.colorAttachments.size(); ++i) { for (size_t i = 0; i < layout.colorAttachments.size(); ++i) {
const auto& color = layout.colorAttachments[i]; const auto& color = layout.colorAttachments[i];
MTL::RenderPassColorAttachmentDescriptor *desc = MTL::RenderPassColorAttachmentDescriptor* desc = renderPass->colorAttachments()->object(i);
renderPass->colorAttachments()->object(i); desc->setClearColor(MTL::ClearColor(color.clear.color.float32[0], color.clear.color.float32[1],
desc->setClearColor(MTL::ClearColor(
color.clear.color.float32[0], color.clear.color.float32[1],
color.clear.color.float32[2], color.clear.color.float32[3])); color.clear.color.float32[2], color.clear.color.float32[3]));
desc->setLoadAction(cast(color.getLoadOp())); desc->setLoadAction(cast(color.getLoadOp()));
desc->setStoreAction(cast(color.getStoreOp())); desc->setStoreAction(cast(color.getStoreOp()));
desc->setLevel(0); desc->setLevel(0);
desc->setTexture(color.getTexture().cast<TextureBase>()->getTexture());
if (!layout.resolveAttachments.empty()) { if (!layout.resolveAttachments.empty()) {
const auto& resolve = layout.resolveAttachments[i]; const auto& resolve = layout.resolveAttachments[i];
desc->setResolveLevel(0); desc->setResolveLevel(0);
desc->setStoreAction(MTL::StoreActionStoreAndMultisampleResolve); desc->setStoreAction(MTL::StoreActionStoreAndMultisampleResolve);
desc->setResolveTexture( desc->setResolveTexture(resolve.getTexture().cast<TextureBase>()->getTexture());
resolve.getTexture().cast<TextureBase>()->getTexture());
} }
} }
if (layout.depthAttachment.getTexture() != nullptr) { if (layout.depthAttachment.getTexture() != nullptr) {
depth = MTL::RenderPassDepthAttachmentDescriptor::alloc()->init(); auto depth = renderPass->depthAttachment();
depth->setClearDepth(layout.depthAttachment.clear.depthStencil.depth); depth->setClearDepth(layout.depthAttachment.clear.depthStencil.depth);
depth->setLoadAction(cast(layout.depthAttachment.getLoadOp())); depth->setLoadAction(cast(layout.depthAttachment.getLoadOp()));
depth->setStoreAction(cast(layout.depthAttachment.getStoreOp())); depth->setStoreAction(cast(layout.depthAttachment.getStoreOp()));
depth->setTexture(
layout.depthAttachment.getTexture().cast<TextureBase>()->getTexture());
if (layout.depthResolveAttachment.getTexture() != nullptr) { if (layout.depthResolveAttachment.getTexture() != nullptr) {
depth->setResolveTexture(layout.depthResolveAttachment.getTexture() depth->setResolveTexture(layout.depthResolveAttachment.getTexture().cast<TextureBase>()->getTexture());
.cast<TextureBase>()
->getTexture());
depth->setStoreAction(MTL::StoreActionStoreAndMultisampleResolve); depth->setStoreAction(MTL::StoreActionStoreAndMultisampleResolve);
} }
renderPass->setDepthAttachment(depth);
} }
// TODO: stencil // TODO: stencil
} }
RenderPass::~RenderPass() { RenderPass::~RenderPass() {}
depth->release();
stencil->release(); void RenderPass::updateRenderPass() {
renderPass->release(); 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>()->getTexture());
}
if (layout.depthAttachment.getTexture() != nullptr) {
auto depth = renderPass->depthAttachment();
depth->setTexture(layout.depthAttachment.getTexture().cast<TextureBase>()->getTexture());
}
} }
+1
View File
@@ -1,4 +1,5 @@
#pragma once #pragma once
#include "Foundation/NSAutoreleasePool.hpp"
#include "Graphics.h" #include "Graphics.h"
#include "Graphics/Window.h" #include "Graphics/Window.h"
#include "Resources.h" #include "Resources.h"
+2 -6
View File
@@ -1,5 +1,6 @@
#include "Window.h" #include "Window.h"
#include "Command.h" #include "Command.h"
#include "Foundation/NSAutoreleasePool.hpp"
#include "Graphics/Initializer.h" #include "Graphics/Initializer.h"
#include "Graphics/Metal/Enums.h" #include "Graphics/Metal/Enums.h"
#include "Graphics/Texture.h" #include "Graphics/Texture.h"
@@ -80,8 +81,6 @@ Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo) : graphic
metalLayer.drawableSize = CGSizeMake(createInfo.width, createInfo.height); metalLayer.drawableSize = CGSizeMake(createInfo.width, createInfo.height);
metalWindow.contentView.layer = metalLayer; metalWindow.contentView.layer = metalLayer;
metalWindow.contentView.wantsLayer = YES; metalWindow.contentView.wantsLayer = YES;
drawable = (__bridge CA::MetalDrawable*)[metalLayer nextDrawable];
createBackBuffer();
} }
Window::~Window() { glfwDestroyWindow(static_cast<GLFWwindow*>(windowHandle)); } Window::~Window() { glfwDestroyWindow(static_cast<GLFWwindow*>(windowHandle)); }
@@ -89,9 +88,6 @@ Window::~Window() { glfwDestroyWindow(static_cast<GLFWwindow*>(windowHandle)); }
void Window::pollInput() { glfwPollEvents(); } void Window::pollInput() { glfwPollEvents(); }
void Window::beginFrame() { void Window::beginFrame() {
if (drawable) {
drawable->release();
}
drawable = (__bridge CA::MetalDrawable*)[metalLayer nextDrawable]; drawable = (__bridge CA::MetalDrawable*)[metalLayer nextDrawable];
createBackBuffer(); createBackBuffer();
} }
@@ -146,7 +142,7 @@ void Window::resize(int width, int height) {
framebufferWidth = width; framebufferWidth = width;
framebufferHeight = height; framebufferHeight = height;
// Deallocate the textures if they have been created // Deallocate the textures if they have been created
drawable = (__bridge CA::MetalDrawable*)[metalLayer nextDrawable]; drawable = (__bridge CA::MetalDrawable*)[[metalLayer nextDrawable] autorelease];
createBackBuffer(); createBackBuffer();
resizeCallback(width, height); resizeCallback(width, height);
} }
+1 -1
View File
@@ -21,7 +21,7 @@ GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreate
renderGraph.addPass(new DepthPrepass(graphics, scene)); renderGraph.addPass(new DepthPrepass(graphics, scene));
renderGraph.addPass(new LightCullingPass(graphics, scene)); renderGraph.addPass(new LightCullingPass(graphics, scene));
renderGraph.addPass(new BasePass(graphics, scene)); renderGraph.addPass(new BasePass(graphics, scene));
renderGraph.addPass(new DebugPass(graphics, scene)); //renderGraph.addPass(new DebugPass(graphics, scene));
//renderGraph.addPass(new SkyboxRenderPass(graphics, scene)); //renderGraph.addPass(new SkyboxRenderPass(graphics, scene));
renderGraph.setViewport(viewport); renderGraph.setViewport(viewport);
renderGraph.createRenderPass(); renderGraph.createRenderPass();