Skip to content

Commit

Permalink
Fix MacOS build.
Browse files Browse the repository at this point in the history
  • Loading branch information
bluesky013 committed Apr 3, 2024
1 parent 83095a8 commit 1b253f5
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 19 deletions.
6 changes: 3 additions & 3 deletions cmake/thirdparty/Findimgui.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ set(${LIB_NAME}_INCLUDE_DIR ${${LIB_NAME}_PATH}/include)
set(${LIB_NAME}_LIBS_DIR ${${LIB_NAME}_PATH}/lib)

set(${LIB_NAME}_LIBRARY_DEBUG
${${LIB_NAME}_LIBS_DIR}/Debug/${CMAKE_STATIC_LIBRARY_PREFIX}Imgui${CMAKE_STATIC_LIBRARY_SUFFIX})
${${LIB_NAME}_LIBS_DIR}/Debug/${CMAKE_STATIC_LIBRARY_PREFIX}ImGui${CMAKE_STATIC_LIBRARY_SUFFIX})

set(${LIB_NAME}_LIBRARY_RELEASE
${${LIB_NAME}_LIBS_DIR}/Release/${CMAKE_STATIC_LIBRARY_PREFIX}Imgui${CMAKE_STATIC_LIBRARY_SUFFIX})
${${LIB_NAME}_LIBS_DIR}/Release/${CMAKE_STATIC_LIBRARY_PREFIX}ImGui${CMAKE_STATIC_LIBRARY_SUFFIX})

set(${LIB_NAME}_LIBRARY
"$<$<CONFIG:release>:${${LIB_NAME}_LIBRARY_RELEASE}>"
"$<$<CONFIG:debug>:${${LIB_NAME}_LIBRARY_DEBUG}>")
Expand Down
3 changes: 1 addition & 2 deletions render/backend/vulkan/include/vulkan/Swapchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ namespace sky::vk {
std::vector<ImagePtr> images;
std::vector<rhi::ImageViewPtr> imageViews;
};
#endif
using XRSwapChainPtr = std::shared_ptr<XRSwapChain>;

#endif
} // namespace sky::vk
2 changes: 1 addition & 1 deletion render/backend/vulkan/platform/macos/SwapchainImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
createInfo.pView = view;
createInfo.pNext = nullptr;

if (vkCreateMacOSSurfaceMVK(device.GetInstance(), &createInfo, nullptr, &surface) != VK_SUCCESS) {
if (vkCreateMacOSSurfaceMVK(device.GetInstanceId(), &createInfo, nullptr, &surface) != VK_SUCCESS) {
return false;
}
return true;
Expand Down
2 changes: 2 additions & 0 deletions render/core/include/render/rdg/RenderGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ namespace sky::rdg {
void ImportImage(const char *name, const rhi::ImagePtr &image, rhi::ImageViewType viewType, const rhi::AccessFlags &flags);

void ImportSwapChain(const char *name, const rhi::SwapChainPtr &swapchain);
#ifdef SKY_ENABLE_XR
void ImportXRSwapChain(const char *name, const rhi::XRSwapChainPtr &swapchain);
#endif
void AddImageView(const char *name, const char *source, const GraphImageView &view);

void AddBuffer(const char *name, const GraphBuffer &attachment);
Expand Down
3 changes: 3 additions & 0 deletions render/core/include/render/rdg/RenderGraphTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,14 @@ namespace sky::rdg {
uint32_t imageIndex = 0;
};


struct GraphXRSwapChain {
using Tag = ImportXRSwapChainTag;

#ifdef SKY_ENABLE_XR
rhi::XRSwapChainPtr swapchain;
uint32_t imageIndex = 0;
#endif
};

struct GraphImageView {
Expand Down
4 changes: 3 additions & 1 deletion render/core/src/RHI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ namespace sky {

void RHI::InitInstance(rhi::Instance::Descriptor desc)
{
#ifdef SKY_ENABLE_XR
desc.xrInterface = xrInterface;
#endif
instance = rhi::Instance::Create(desc);
api = desc.api;
}
Expand All @@ -24,4 +26,4 @@ namespace sky {
{
device.reset(instance->CreateDevice(desc));
}
}
}
3 changes: 2 additions & 1 deletion render/core/src/RenderPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,11 @@ namespace sky {
rhi::PresentInfo presentInfo = {};
presentInfo.semaphores.emplace_back(rdgContext->RenderFinishSemaphore());
for (auto &swc : rdg.presentPasses) {
#ifdef SKY_ENABLE_XR
if (swc.xrSwapChain) {
continue;
}

#endif
auto &res = rdg.resourceGraph.swapChains[Index(swc.imageID, rdg.resourceGraph)];
presentInfo.imageIndex = res.desc.imageIndex;
swc.swapChain->Present(*queue, presentInfo);
Expand Down
10 changes: 5 additions & 5 deletions render/core/src/RenderWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ namespace sky {
{
#ifdef SKY_ENABLE_XR
return swapChain ? swapChain->GetExtent().width : xrSwapChain->GetExtent().width;
#elif
return swapChain->GetExent().width;
#else
return swapChain->GetExtent().width;
#endif
}

uint32_t RenderWindow::GetHeight() const
{
#ifdef SKY_ENABLE_XR
return swapChain ? swapChain->GetExtent().height : xrSwapChain->GetExtent().height;
#elif
return swapChain->GetExent().height;
#else
return swapChain->GetExtent().height;
#endif
}
} // namespace sky
} // namespace sky
4 changes: 2 additions & 2 deletions render/core/src/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace sky {
rw->Init(hWnd, width, height, vSync);
return rw;
}

#ifdef SKY_ENABLE_XR
RenderWindow *Renderer::CreateRenderWindowByXR()
{
auto *renderWindow = new RenderWindow();
Expand All @@ -95,7 +95,7 @@ namespace sky {
windows.emplace_back(renderWindow, &Renderer::DestroyObj<RenderWindow>);
return renderWindow;
}

#endif
void Renderer::RemoveScene(sky::RenderScene *scene)
{
scenes.remove_if([scene](const auto &scn) {
Expand Down
2 changes: 2 additions & 0 deletions render/core/src/rdg/AccessUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,13 @@ namespace sky::rdg {
range.range = 1;
range.layers = 1;
},
#ifdef SKY_ENABLE_XR
[&](const ImportXRSwapChainTag &tag) {
const auto &res = resourceGraph.xrSwapChains[Index(resID, resourceGraph)];
range.range = 1;
range.layers = res.desc.swapchain->GetArrayLayers();
},
#endif
[&](const BufferTag &tag) {
const auto &buffer = resourceGraph.buffers[Index(resID, resourceGraph)];
range.range = buffer.desc.size;
Expand Down
6 changes: 4 additions & 2 deletions render/core/src/rdg/RenderGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ namespace sky::rdg {
{
add_edge(0, AddVertex(name, GraphSwapChain{swapchain}, *this), graph);
}

#ifdef SKY_ENABLE_XR
void ResourceGraph::ImportXRSwapChain(const char *name, const rhi::XRSwapChainPtr &swapchain)
{
add_edge(0, AddVertex(name, GraphXRSwapChain{swapchain}, *this), graph);
}

#endif
void ResourceGraph::AddImageView(const char *name, const char *source, const GraphImageView &view)
{
auto src = FindVertex(source, *this);
Expand Down Expand Up @@ -157,12 +157,14 @@ namespace sky::rdg {
add_edge(0, vtx, graph);
AddDependency(resID, vtx, DependencyInfo{PresentType::PRESENT, ResourceAccessBit::READ, {}});
},
#ifdef SKY_ENABLE_XR
[&](const ImportXRSwapChainTag &tag) {
const auto &res = resourceGraph.xrSwapChains[Index(resID, resourceGraph)];
auto vtx = AddVertex(name, PresentPass(resID, res.desc.swapchain, &context->resources), *this);
add_edge(0, vtx, graph);
AddDependency(resID, vtx, DependencyInfo{PresentType::PRESENT, ResourceAccessBit::READ, {}});
},
#endif
[&](const auto &) {}
}, rdg::Tag(resID, resourceGraph));
}
Expand Down
4 changes: 4 additions & 0 deletions render/core/src/rdg/RenderGraphExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ namespace sky::rdg {
const auto &image = resourceGraph.swapChains[Index(resID, resourceGraph)];
res = image.desc.swapchain->GetImage(image.desc.imageIndex);
},
#ifdef SKY_ENABLE_XR
[&](const ImportXRSwapChainTag &) {
const auto &image = resourceGraph.xrSwapChains[Index(resID, resourceGraph)];
res = image.desc.swapchain->GetImage(image.desc.imageIndex);
},
#endif
[&](const auto &) {
}
}, Tag(resID, resourceGraph));
Expand Down Expand Up @@ -69,6 +71,7 @@ namespace sky::rdg {
rhi::BarrierInfo{ barrier.srcFlags, barrier.dstFlags});
}
},
#ifdef SKY_ENABLE_XR
[&](const ImportXRSwapChainTag &) {
auto &image = graph.resourceGraph.xrSwapChains[Index(resID, graph.resourceGraph)];
for (const auto &barrier : barriers) {
Expand All @@ -79,6 +82,7 @@ namespace sky::rdg {
rhi::BarrierInfo{ barrier.srcFlags, barrier.dstFlags});
}
},
#endif
[&](const BufferTag &) {
auto &buffer = graph.resourceGraph.buffers[Index(resID, graph.resourceGraph)];
for (const auto &barrier : barriers) {
Expand Down
4 changes: 4 additions & 0 deletions render/core/src/rdg/RenderResourceCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,15 @@ namespace sky::rdg {
swc.res = swc.desc.swapchain->GetImageView(swc.desc.imageIndex);
}
},
#ifdef SKY_ENABLE_XR
[&](const ImportXRSwapChainTag &) {
auto &swc = rdg.resourceGraph.xrSwapChains[Index(res, rdg.resourceGraph)];
if (!swc.res) {
swc.desc.imageIndex = swc.desc.swapchain->AcquireNextImage();
swc.res = swc.desc.swapchain->GetImageView(swc.desc.imageIndex);
}
},
#endif
[&](const auto &) {}
}, Tag(res, rdg.resourceGraph));
}
Expand Down Expand Up @@ -241,11 +243,13 @@ namespace sky::rdg {
att.format = swc.desc.swapchain->GetFormat();
fbDesc.views[i] = swc.res;
},
#ifdef SKY_ENABLE_XR
[&](const ImportXRSwapChainTag &) {
auto &swc = rdg.resourceGraph.xrSwapChains[Index(attachment, rdg.resourceGraph)];
att.format = swc.desc.swapchain->GetFormat();
fbDesc.views[i] = swc.res;
},
#endif
[&](const ImageViewTag &) {
auto &source = rdg.resourceGraph.images[Index(Source(attachment, rdg.resourceGraph), rdg.resourceGraph)];
att.format = source.desc.format;
Expand Down
7 changes: 5 additions & 2 deletions sample/RDSceneProject/native/src/scenes/SampleMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ namespace sky {
renderWidth = ext.width * 2;
renderHeight = ext.height * 2;
rg.ImportSwapChain("SwapChain", swapChain);
} else {
}
#ifdef SKY_ENABLE_XR
else {
auto xrSwapChain = output->GetXRSwaChain();
const auto &ext = xrSwapChain->GetExtent();
outWidth = ext.width;
Expand All @@ -148,6 +150,7 @@ namespace sky {
}
rg.ImportXRSwapChain("SwapChain", xrSwapChain);
}
#endif


ShaderPassInfo passInfo = {};
Expand Down Expand Up @@ -295,4 +298,4 @@ namespace sky {
{
camera->GetComponent<CameraComponent>()->SetAspect(width, height);
}
} // namespace sky
} // namespace sky

0 comments on commit 1b253f5

Please sign in to comment.