Fix errors with Vulkan Xcode build (#2906)
This commit is contained in:
@@ -209,6 +209,13 @@ GLFWView::GLFWView(bool fullscreen_,
|
||||
glfwSetScrollCallback(window, onScroll);
|
||||
glfwSetKeyCallback(window, onKey);
|
||||
glfwSetWindowFocusCallback(window, onWindowFocus);
|
||||
#if defined(__APPLE__) && defined(MLN_RENDER_BACKEND_VULKAN)
|
||||
glfwSetWindowRefreshCallback(window, onWindowRefresh);
|
||||
#endif
|
||||
|
||||
// "... applications will typically want to set the swap interval to one"
|
||||
// https://www.glfw.org/docs/latest/quick.html#quick_swap_buffers
|
||||
glfwSwapInterval(1);
|
||||
|
||||
glfwGetWindowSize(window, &width, &height);
|
||||
|
||||
@@ -915,6 +922,16 @@ void GLFWView::onFramebufferResize(GLFWwindow *window, int width, int height) {
|
||||
// different pixel ratio. We are forcing a repaint my invalidating the view,
|
||||
// which triggers a rerender with the new framebuffer dimensions.
|
||||
view->invalidate();
|
||||
|
||||
#if defined(__APPLE__) && defined(MLN_RENDER_BACKEND_VULKAN)
|
||||
// Render continuously while resizing
|
||||
// Untested elsewhere
|
||||
view->render();
|
||||
|
||||
#if defined(MLN_RENDER_BACKEND_OPENGL)
|
||||
glfwSwapBuffers(window);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void GLFWView::onMouseClick(GLFWwindow *window, int button, int action, int modifiers) {
|
||||
@@ -1021,6 +1038,49 @@ void GLFWView::onWindowFocus(GLFWwindow *window, int focused) {
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(__APPLE__) && defined(MLN_RENDER_BACKEND_VULKAN)
|
||||
void GLFWView::onWindowRefresh(GLFWwindow *window) {
|
||||
// Untested elsewhere
|
||||
if (auto *view = reinterpret_cast<GLFWView *>(glfwGetWindowUserPointer(window))) {
|
||||
view->invalidate();
|
||||
view->render();
|
||||
#if defined(MLN_RENDER_BACKEND_OPENGL)
|
||||
glfwSwapBuffers(window);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void GLFWView::render() {
|
||||
if (dirty && rendererFrontend) {
|
||||
MLN_TRACE_ZONE(ReRender);
|
||||
|
||||
dirty = false;
|
||||
const double started = glfwGetTime();
|
||||
|
||||
if (animateRouteCallback) {
|
||||
MLN_TRACE_ZONE(animateRouteCallback);
|
||||
|
||||
animateRouteCallback(map);
|
||||
}
|
||||
|
||||
updateAnimatedAnnotations();
|
||||
|
||||
mbgl::gfx::BackendScope scope{backend->getRendererBackend()};
|
||||
|
||||
rendererFrontend->render();
|
||||
|
||||
if (freeCameraDemoPhase >= 0.0) {
|
||||
updateFreeCameraDemo();
|
||||
}
|
||||
|
||||
report(static_cast<float>(1000 * (glfwGetTime() - started)));
|
||||
if (benchmark) {
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GLFWView::run() {
|
||||
MLN_TRACE_FUNC();
|
||||
|
||||
@@ -1040,33 +1100,7 @@ void GLFWView::run() {
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
if (dirty && rendererFrontend) {
|
||||
MLN_TRACE_ZONE(ReRender);
|
||||
|
||||
dirty = false;
|
||||
const double started = glfwGetTime();
|
||||
|
||||
if (animateRouteCallback) {
|
||||
MLN_TRACE_ZONE(animateRouteCallback);
|
||||
|
||||
animateRouteCallback(map);
|
||||
}
|
||||
|
||||
updateAnimatedAnnotations();
|
||||
|
||||
mbgl::gfx::BackendScope scope{backend->getRendererBackend()};
|
||||
|
||||
rendererFrontend->render();
|
||||
|
||||
if (freeCameraDemoPhase >= 0.0) {
|
||||
updateFreeCameraDemo();
|
||||
}
|
||||
|
||||
report(static_cast<float>(1000 * (glfwGetTime() - started)));
|
||||
if (benchmark) {
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
render();
|
||||
};
|
||||
|
||||
// Cap frame rate to 60hz if benchmark mode is disabled
|
||||
|
||||
@@ -77,10 +77,13 @@ private:
|
||||
static void onMouseClick(GLFWwindow *window, int button, int action, int modifiers);
|
||||
static void onMouseMove(GLFWwindow *window, double x, double y);
|
||||
static void onWindowFocus(GLFWwindow *window, int focused);
|
||||
static void onWindowRefresh(GLFWwindow *window);
|
||||
|
||||
// Internal
|
||||
void report(float duration);
|
||||
|
||||
void render();
|
||||
|
||||
mbgl::Color makeRandomColor() const;
|
||||
mbgl::Point<double> makeRandomPoint() const;
|
||||
static std::unique_ptr<mbgl::style::Image> makeImage(const std::string &id,
|
||||
|
||||
@@ -54,7 +54,7 @@ ShaderProgram::ShaderProgram(shaders::BuiltIn shaderID,
|
||||
|
||||
const auto preamble = defineStr + "\n" + prelude;
|
||||
const char* shaderData = data.data();
|
||||
const int shaderDataSize = data.size();
|
||||
const int shaderDataSize = static_cast<int>(data.size());
|
||||
|
||||
glslShader.setPreamble(preamble.c_str());
|
||||
glslShader.setStringsWithLengths(&shaderData, &shaderDataSize, 1);
|
||||
|
||||
@@ -207,9 +207,11 @@ void Context::beginFrame() {
|
||||
} else if (acquireImageResult.result == vk::Result::eSuboptimalKHR) {
|
||||
renderableResource.setAcquiredImageIndex(acquireImageResult.value);
|
||||
// TODO implement pre-rotation transform for surface orientation
|
||||
// requestSurfaceUpdate();
|
||||
// beginFrame();
|
||||
// return;
|
||||
#if defined(__APPLE__)
|
||||
requestSurfaceUpdate();
|
||||
beginFrame();
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
} catch (const vk::OutOfDateKHRError& e) {
|
||||
@@ -271,7 +273,9 @@ void Context::submitFrame() {
|
||||
const vk::Result presentResult = presentQueue.presentKHR(presentInfo);
|
||||
if (presentResult == vk::Result::eSuboptimalKHR) {
|
||||
// TODO implement pre-rotation transform for surface orientation
|
||||
// requestSurfaceUpdate();
|
||||
#if defined(__APPLE__)
|
||||
requestSurfaceUpdate();
|
||||
#endif
|
||||
}
|
||||
} catch (const vk::OutOfDateKHRError& e) {
|
||||
requestSurfaceUpdate();
|
||||
@@ -438,13 +442,13 @@ bool Context::renderTileClippingMasks(gfx::RenderPass& renderPass,
|
||||
clipping.pipelineInfo.inputBindings.push_back(
|
||||
vk::VertexInputBindingDescription()
|
||||
.setBinding(0)
|
||||
.setStride(VertexAttribute::getStrideOf(ShaderClass::attributes[0].dataType))
|
||||
.setStride(static_cast<uint32_t>(VertexAttribute::getStrideOf(ShaderClass::attributes[0].dataType)))
|
||||
.setInputRate(vk::VertexInputRate::eVertex));
|
||||
|
||||
clipping.pipelineInfo.inputAttributes.push_back(
|
||||
vk::VertexInputAttributeDescription()
|
||||
.setBinding(0)
|
||||
.setLocation(ShaderClass::attributes[0].index)
|
||||
.setLocation(static_cast<uint32_t>(ShaderClass::attributes[0].index))
|
||||
.setFormat(PipelineInfo::vulkanFormat(ShaderClass::attributes[0].dataType)));
|
||||
}
|
||||
|
||||
@@ -521,7 +525,7 @@ const vk::UniqueDescriptorSetLayout& Context::getUniformDescriptorSetLayout() {
|
||||
|
||||
for (size_t i = 0; i < shaders::maxUBOCountPerShader; ++i) {
|
||||
bindings.push_back(vk::DescriptorSetLayoutBinding()
|
||||
.setBinding(i)
|
||||
.setBinding(static_cast<uint32_t>(i))
|
||||
.setStageFlags(stageFlags)
|
||||
.setDescriptorType(vk::DescriptorType::eUniformBuffer)
|
||||
.setDescriptorCount(1));
|
||||
@@ -542,7 +546,7 @@ const vk::UniqueDescriptorSetLayout& Context::getImageDescriptorSetLayout() {
|
||||
|
||||
for (size_t i = 0; i < shaders::maxTextureCountPerShader; ++i) {
|
||||
bindings.push_back(vk::DescriptorSetLayoutBinding()
|
||||
.setBinding(i)
|
||||
.setBinding(static_cast<uint32_t>(i))
|
||||
.setStageFlags(vk::ShaderStageFlagBits::eFragment)
|
||||
.setDescriptorType(vk::DescriptorType::eCombinedImageSampler)
|
||||
.setDescriptorCount(1));
|
||||
|
||||
@@ -269,7 +269,7 @@ void Drawable::draw(PaintParameters& parameters) const {
|
||||
|
||||
impl->pipelineInfo.setRenderable(renderPass_.getDescriptor().renderable);
|
||||
|
||||
const uint32_t instances = instanceAttributes ? instanceAttributes->getMaxCount() : 1;
|
||||
const auto instances = instanceAttributes ? instanceAttributes->getMaxCount() : 1;
|
||||
|
||||
for (const auto& seg : impl->segments) {
|
||||
const auto& segment = seg->getSegment();
|
||||
@@ -283,9 +283,16 @@ void Drawable::draw(PaintParameters& parameters) const {
|
||||
commandBuffer->bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline.get());
|
||||
|
||||
if (segment.indexLength) {
|
||||
commandBuffer->drawIndexed(segment.indexLength, instances, segment.indexOffset, segment.vertexOffset, 0);
|
||||
commandBuffer->drawIndexed(static_cast<uint32_t>(segment.indexLength),
|
||||
static_cast<uint32_t>(instances),
|
||||
static_cast<uint32_t>(segment.indexOffset),
|
||||
static_cast<int32_t>(segment.vertexOffset),
|
||||
0);
|
||||
} else {
|
||||
commandBuffer->draw(segment.vertexLength, instances, segment.vertexOffset, 0);
|
||||
commandBuffer->draw(static_cast<uint32_t>(segment.vertexLength),
|
||||
static_cast<uint32_t>(instances),
|
||||
static_cast<uint32_t>(segment.vertexOffset),
|
||||
0);
|
||||
}
|
||||
|
||||
context.renderingStats().numDrawCalls++;
|
||||
@@ -344,7 +351,7 @@ void Drawable::buildVulkanInputBindings() noexcept {
|
||||
const auto& buffer = vertexBuffer->get();
|
||||
|
||||
const auto& buffIt = std::find(uniqueBuffers.begin(), uniqueBuffers.end(), binding->vertexBufferResource);
|
||||
uint32_t bindingIndex = 0;
|
||||
std::size_t bindingIndex = 0;
|
||||
|
||||
if (buffIt == uniqueBuffers.end()) {
|
||||
bindingIndex = impl->pipelineInfo.inputBindings.size();
|
||||
@@ -353,7 +360,7 @@ void Drawable::buildVulkanInputBindings() noexcept {
|
||||
|
||||
// add new buffer binding
|
||||
impl->pipelineInfo.inputBindings.push_back(vk::VertexInputBindingDescription()
|
||||
.setBinding(bindingIndex)
|
||||
.setBinding(static_cast<uint32_t>(bindingIndex))
|
||||
.setStride(binding->vertexStride)
|
||||
.setInputRate(inputRate));
|
||||
|
||||
@@ -365,8 +372,8 @@ void Drawable::buildVulkanInputBindings() noexcept {
|
||||
|
||||
impl->pipelineInfo.inputAttributes.push_back(
|
||||
vk::VertexInputAttributeDescription()
|
||||
.setBinding(bindingIndex)
|
||||
.setLocation(i)
|
||||
.setBinding(static_cast<uint32_t>(bindingIndex))
|
||||
.setLocation(static_cast<uint32_t>(i))
|
||||
.setFormat(PipelineInfo::vulkanFormat(binding->attribute.dataType))
|
||||
.setOffset(binding->attribute.offset));
|
||||
}
|
||||
@@ -431,7 +438,7 @@ bool Drawable::bindDescriptors(CommandEncoder& encoder) const noexcept {
|
||||
.setBufferInfo(descriptorBufferInfo)
|
||||
.setDescriptorCount(1)
|
||||
.setDescriptorType(vk::DescriptorType::eUniformBuffer)
|
||||
.setDstBinding(id)
|
||||
.setDstBinding(static_cast<uint32_t>(id))
|
||||
.setDstSet(uniformDescriptorSet);
|
||||
|
||||
device->updateDescriptorSets(writeDescriptorSet, nullptr);
|
||||
@@ -460,7 +467,7 @@ bool Drawable::bindDescriptors(CommandEncoder& encoder) const noexcept {
|
||||
.setImageInfo(descriptorImageInfo)
|
||||
.setDescriptorCount(1)
|
||||
.setDescriptorType(vk::DescriptorType::eCombinedImageSampler)
|
||||
.setDstBinding(id)
|
||||
.setDstBinding(static_cast<uint32_t>(id))
|
||||
.setDstSet(imageDescriptorSet);
|
||||
|
||||
device->updateDescriptorSets(writeDescriptorSet, nullptr);
|
||||
|
||||
@@ -496,7 +496,7 @@ std::shared_ptr<PremultipliedImage> Texture2D::readImage() {
|
||||
if (imageSize == layout.arrayPitch) {
|
||||
memcpy(imageData->data.get(), mappedData, imageSize);
|
||||
} else {
|
||||
uint32_t rowSize = size.width * getPixelStride();
|
||||
auto rowSize = static_cast<uint32_t>(size.width * getPixelStride());
|
||||
for (uint32_t i = 0; i < size.height; ++i) {
|
||||
memcpy(imageData->data.get() + rowSize * i, mappedData + layout.rowPitch * i, rowSize);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user