Skip to content

Commit

Permalink
Merge branch 'main' into opengl_framebuffer_format
Browse files Browse the repository at this point in the history
* main: (69 commits)
  The DeviceFeatureLimits::BufferAlignment is not always equals 16 byte on OpenGL backend. (facebook#113)
  Suppress swiftshader's TSAN false-positives
  Remove OpenGL dependency from Vulkan tests
  Disable debug names on Android due to emulator crash
  igl | vulkan - scope guard for locked hw buffer
  igl | vulkan - external hw buffer support facebook#2
  igl | vulkan - external hw buffer support facebook#1
  igl - native hw buffer desc helper
  igl | vulkan - native hw buffer
  igl | vulkan - hw native buffer external memory support
  igl - native hw buffer interface
  add multiviewmultisample devicefeature check
  Assert even if we don't terminate to allow debug break on validation error
  Fixed shell tests compilation
  igl | shell | Demonstrate both YUV formats `NV12` and `420p`.
  igl | shell | Enqueue key events on Windows
  igl | Add helper function `SamplerStateDesc::newYUV()`
  Bump the `apk` modes to NDK 26, API 31 and update Hyperspace
  igl | Add YUV 420p test data file
  igl | Add new texture format `YUV_420p`
  ...

# Conflicts:
#	src/igl/opengl/egl/PlatformDevice.cpp
  • Loading branch information
vinsentli committed Jun 27, 2024
2 parents cbdf982 + 004c6b5 commit 05a2cd4
Show file tree
Hide file tree
Showing 470 changed files with 4,331 additions and 3,558 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ if(ANDROID)
set(IGL_WITH_OPENGL OFF)
set(IGL_WITH_VULKAN ON)
set(IGL_WITH_WEBGL OFF)
# disable for all targets due to warnings in third-party code
add_definitions(-Wno-nullability-completeness)
add_definitions(-Wno-deprecated-volatile)
endif()

if(EMSCRIPTEN)
Expand Down Expand Up @@ -263,7 +266,7 @@ if(IGL_WITH_SAMPLES)
add_subdirectory(samples/desktop)
igl_set_folder(glfw "third-party/GLFW3")
endif()
endif()
endif()
endif()

if (IGL_WITH_VULKAN OR IGL_WITH_IGLU OR IGL_WITH_SAMPLES)
Expand Down
26 changes: 26 additions & 0 deletions IGLU/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ add_iglu_module(managedUniformBuffer)
add_iglu_module(sentinel)
add_iglu_module(simple_renderer)
add_iglu_module(state_pool)
add_iglu_module(shaderCross)
add_iglu_module(texture_accessor)
add_iglu_module(texture_loader)
add_iglu_module(uniform)
Expand Down Expand Up @@ -63,3 +64,28 @@ if(UNIX)
target_compile_options(IGLUimgui PUBLIC "-Wno-volatile")
endif()
endif()

# SPIRV-Cross
# cmake-format: off
set(SPIRV_CROSS_SHARED OFF CACHE BOOL "")
set(SPIRV_CROSS_STATIC ON CACHE BOOL "")
set(SPIRV_CROSS_CLI OFF CACHE BOOL "")
set(SPIRV_CROSS_ENABLE_TESTS OFF CACHE BOOL "")
set(SPIRV_CROSS_ENABLE_GLSL ON CACHE BOOL "")
set(SPIRV_CROSS_ENABLE_HLSL OFF CACHE BOOL "")
set(SPIRV_CROSS_ENABLE_MSL ON CACHE BOOL "")
set(SPIRV_CROSS_ENABLE_CPP OFF CACHE BOOL "")
set(SPIRV_CROSS_ENABLE_REFLECT OFF CACHE BOOL "")
set(SPIRV_CROSS_SKIP_INSTALL ON CACHE BOOL "")

add_subdirectory(${IGL_ROOT_DIR}/third-party/deps/src/SPIRV-Cross "SPIRV-Cross")

igl_set_folder(spirv-cross-core "third-party/spirv-cross/spirv-cross-core")
igl_set_folder(spirv-cross-glsl "third-party/spirv-cross/spirv-cross-glsl")
igl_set_folder(spirv-cross-msl "third-party/spirv-cross/spirv-cross-msl")
igl_set_folder(spirv-cross-util "third-party/spirv-cross/spirv-cross-util")
igl_set_folder(spirv-cross-c "third-party/spirv-cross/spirv-cross-c")
# cmake-format: on

target_include_directories(IGLUshaderCross PRIVATE "${IGL_ROOT_DIR}/third-party/deps/src/SPIRV-Cross" "${IGL_ROOT_DIR}/third-party/deps/src/glslang")
target_link_libraries(IGLUshaderCross PRIVATE IGLGlslang IGLUmanagedUniformBuffer spirv-cross-core spirv-cross-glsl spirv-cross-msl spirv-cross-util spirv-cross-c)
6 changes: 2 additions & 4 deletions IGLU/imgui/InputListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
// is one frame old. This can be a source of problems if we have multiple input listeners and
// depending on how they process inputs.

namespace iglu {
namespace imgui {
namespace iglu::imgui {

InputListener::InputListener(ImGuiContext* context) {
_context = context;
Expand Down Expand Up @@ -67,5 +66,4 @@ void InputListener::makeCurrentContext() const {
ImGui::SetCurrentContext(_context);
}

} // namespace imgui
} // namespace iglu
} // namespace iglu::imgui
6 changes: 2 additions & 4 deletions IGLU/imgui/InputListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

#include "imgui.h"

namespace iglu {
namespace imgui {
namespace iglu::imgui {

class InputListener : public igl::shell::IMouseListener, public igl::shell::ITouchListener {
public:
Expand All @@ -33,5 +32,4 @@ class InputListener : public igl::shell::IMouseListener, public igl::shell::ITou
void makeCurrentContext() const;
};

} // namespace imgui
} // namespace iglu
} // namespace iglu::imgui
36 changes: 17 additions & 19 deletions IGLU/imgui/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
#include <IGLU/simple_renderer/Material.h>
#include <igl/ShaderCreator.h>

namespace iglu {
namespace imgui {
namespace iglu::imgui {

/* internal renderer -- based on imgui_impl_metal.mm */

Expand Down Expand Up @@ -156,8 +155,8 @@ static std::unique_ptr<igl::IShaderStages> getShaderStagesForBackend(igl::IDevic
}
case igl::BackendType::OpenGL: {
auto shaderVersion = device.getShaderVersion();
std::string vertexStr = getOpenGLVertexShaderSource(shaderVersion);
std::string fragmentStr = getOpenGLFragmentShaderSource(shaderVersion);
const std::string vertexStr = getOpenGLVertexShaderSource(shaderVersion);
const std::string fragmentStr = getOpenGLFragmentShaderSource(shaderVersion);
return igl::ShaderStagesCreator::fromModuleStringInput(
device, vertexStr.c_str(), "main", "", fragmentStr.c_str(), "main", "", &result);
break;
Expand Down Expand Up @@ -203,7 +202,7 @@ struct DrawableData {

class Session::Renderer {
public:
Renderer(igl::IDevice& device);
explicit Renderer(igl::IDevice& device);
~Renderer();

void newFrame(const igl::FramebufferDesc& desc);
Expand Down Expand Up @@ -275,7 +274,7 @@ Session::Renderer::Renderer(igl::IDevice& device) {
}

Session::Renderer::~Renderer() {
ImGuiIO& io = ImGui::GetIO();
const ImGuiIO& io = ImGui::GetIO();
_fontTexture = nullptr;
io.Fonts->TexID = nullptr;
}
Expand All @@ -299,15 +298,15 @@ void Session::Renderer::renderDrawData(igl::IDevice& device,
ImDrawData* drawData) {
// Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates !=
// framebuffer coordinates)
int fb_width = (int)(drawData->DisplaySize.x * drawData->FramebufferScale.x);
int fb_height = (int)(drawData->DisplaySize.y * drawData->FramebufferScale.y);
const int fb_width = (int)(drawData->DisplaySize.x * drawData->FramebufferScale.x);
const int fb_height = (int)(drawData->DisplaySize.y * drawData->FramebufferScale.y);
if (fb_width <= 0 || fb_height <= 0 || drawData->CmdListsCount == 0) {
return;
}

cmdEncoder.pushDebugGroupLabel("ImGui Rendering", igl::Color(0, 1, 0));

igl::Viewport viewport = {
const igl::Viewport viewport = {
/*.x = */ 0.0,
/*.y = */ 0.0,
/*.width = */ (drawData->DisplaySize.x * drawData->FramebufferScale.x),
Expand All @@ -319,10 +318,10 @@ void Session::Renderer::renderDrawData(igl::IDevice& device,
float4x4 orthoProjection{};

{ // setup projection matrix
float L = drawData->DisplayPos.x;
float R = drawData->DisplayPos.x + drawData->DisplaySize.x;
float T = drawData->DisplayPos.y;
float B = drawData->DisplayPos.y + drawData->DisplaySize.y;
const float L = drawData->DisplayPos.x;
const float R = drawData->DisplayPos.x + drawData->DisplaySize.x;
const float T = drawData->DisplayPos.y;
const float B = drawData->DisplayPos.y + drawData->DisplaySize.y;
orthoProjection.columns[0] = float4{2.0f / (R - L), 0.0f, 0.0f, 0.0f};
orthoProjection.columns[1] = float4{0.0f, 2.0f / (T - B), 0.0f, 0.0f};
orthoProjection.columns[2] = float4{0.0f, 0.0f, -1.0f, 0.0f};
Expand All @@ -333,8 +332,8 @@ void Session::Renderer::renderDrawData(igl::IDevice& device,
}
}

ImVec2 clip_off = drawData->DisplayPos; // (0,0) unless using multi-viewports
ImVec2 clip_scale =
const ImVec2 clip_off = drawData->DisplayPos; // (0,0) unless using multi-viewports
const ImVec2 clip_scale =
drawData->FramebufferScale; // (1,1) unless using retina display which are often (2,2)

// Since vertex buffers are updated every frame, we must use triple buffering for Metal to work
Expand All @@ -352,7 +351,7 @@ void Session::Renderer::renderDrawData(igl::IDevice& device,
if (n >= curFrameDrawables.size()) {
curFrameDrawables.emplace_back(device, _vertexInputState, _material);
}
DrawableData& drawableData = curFrameDrawables[n];
const DrawableData& drawableData = curFrameDrawables[n];

// Upload vertex/index buffers
drawableData.vertexData->vertexBuffer().upload(
Expand Down Expand Up @@ -421,7 +420,7 @@ void Session::Renderer::renderDrawData(igl::IDevice& device,
Session::Session(igl::IDevice& device,
igl::shell::InputDispatcher& inputDispatcher,
bool needInitializeSession /* = true */) :
_inputDispatcher(inputDispatcher), _isInitialized(false) {
_inputDispatcher(inputDispatcher) {
_context = ImGui::CreateContext();
makeCurrentContext();

Expand Down Expand Up @@ -481,5 +480,4 @@ void Session::makeCurrentContext() const {
ImGui::SetCurrentContext(_context);
}

} // namespace imgui
} // namespace iglu
} // namespace iglu::imgui
8 changes: 3 additions & 5 deletions IGLU/imgui/Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

#include "imgui.h"

namespace iglu {
namespace imgui {
namespace iglu::imgui {

class Session {
public:
Expand All @@ -40,10 +39,9 @@ class Session {
std::shared_ptr<InputListener> _inputListener;
ImGuiContext* _context;
std::unique_ptr<Renderer> _renderer;
bool _isInitialized;
bool _isInitialized = false;

void makeCurrentContext() const;
};

} // namespace imgui
} // namespace iglu
} // namespace iglu::imgui
8 changes: 4 additions & 4 deletions IGLU/managedUniformBuffer/ManagedUniformBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ bool ManagedUniformBuffer::updateData(const char* name, const void* data, size_t
// This could mean the user knows only a portion of the uniform data needs updating
// However, if dataSize is larger than or equal to what we expect for this uniform, we will
// only copy data up to the expected data size for this uniform
size_t uniformDataSize = getUniformDataSizeInternal(uniform);
const size_t uniformDataSize = getUniformDataSizeInternal(uniform);
if (dataSize > uniformDataSize) {
dataSize = uniformDataSize;
#if IGL_DEBUG
Expand Down Expand Up @@ -236,9 +236,9 @@ size_t ManagedUniformBuffer::getUniformDataSize(const char* name) {
}

size_t ManagedUniformBuffer::getUniformDataSizeInternal(igl::UniformDesc& uniform) {
size_t uniformDataSize = uniform.elementStride != 0
? uniform.numElements * uniform.elementStride
: uniform.numElements * igl::sizeForUniformType(uniform.type);
const size_t uniformDataSize = uniform.elementStride != 0
? uniform.numElements * uniform.elementStride
: uniform.numElements * igl::sizeForUniformType(uniform.type);
return uniformDataSize;
}

Expand Down
6 changes: 2 additions & 4 deletions IGLU/simdtypes/SimdTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

/// Polyfill to make it so we don't have to have ifdefs in code

namespace iglu {
namespace simdtypes {
namespace iglu::simdtypes {

// Use Apple-provided simd if available.
#if defined(__APPLE__)
Expand Down Expand Up @@ -259,5 +258,4 @@ struct float2x2 {

#endif // defined(__APPLE__)

} // namespace simdtypes
} // namespace iglu
} // namespace iglu::simdtypes
14 changes: 6 additions & 8 deletions IGLU/simdtypes/SimdUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#include <IGLU/simdtypes/SimdTypes.h>
#include <cmath>

namespace iglu {
namespace simdtypes {
namespace iglu::simdtypes {

#if defined(__APPLE__)

Expand Down Expand Up @@ -54,7 +53,7 @@ inline float1 fract(float1 x) {
}

inline float4x4 inverse(const float4x4& m) {
float4x4 result;
float4x4 result{};

result.columns[0][0] = m.columns[1][1] * m.columns[2][2] * m.columns[3][3] -
m.columns[1][1] * m.columns[2][3] * m.columns[3][2] -
Expand Down Expand Up @@ -177,9 +176,9 @@ inline float4x4 inverse(const float4x4& m) {

det = 1.0f / det;

for (int i = 0; i < 4; i++) {
for (auto& column : result.columns) {
for (int j = 0; j < 4; j++) {
result.columns[i][j] *= det;
column[j] *= det;
}
}

Expand All @@ -202,13 +201,12 @@ inline float4 multiply(const float4x4& m, const float4& v) {

// result = m1 * m2
inline float4x4 multiply(const float4x4& m1, const float4x4& m2) {
float4x4 result;
float4x4 result{};
result.columns[0] = multiply(m1, m2.columns[0]);
result.columns[1] = multiply(m1, m2.columns[1]);
result.columns[2] = multiply(m1, m2.columns[2]);
result.columns[3] = multiply(m1, m2.columns[3]);
return result;
}
#endif
} // namespace simdtypes
} // namespace iglu
} // namespace iglu::simdtypes
8 changes: 3 additions & 5 deletions IGLU/simple_renderer/Drawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

#include <utility>

namespace iglu {
namespace drawable {
namespace iglu::drawable {

Drawable::Drawable(std::shared_ptr<vertexdata::VertexData> vertexData,
std::shared_ptr<material::Material> material) :
Expand All @@ -24,7 +23,7 @@ void Drawable::draw(igl::IDevice& device,
size_t pushConstantsDataSize,
const void* pushConstantsData) {
// Assumption: _vertexData and _material are immutable
size_t pipelineDescHash = std::hash<igl::RenderPipelineDesc>()(pipelineDesc);
const size_t pipelineDescHash = std::hash<igl::RenderPipelineDesc>()(pipelineDesc);
if (!_pipelineState || pipelineDescHash != _lastPipelineDescHash) {
igl::RenderPipelineDesc mutablePipelineDesc = pipelineDesc;
_vertexData->populatePipelineDescriptor(mutablePipelineDesc);
Expand All @@ -45,5 +44,4 @@ void Drawable::draw(igl::IDevice& device,
_vertexData->draw(commandEncoder);
}

} // namespace drawable
} // namespace iglu
} // namespace iglu::drawable
6 changes: 2 additions & 4 deletions IGLU/simple_renderer/Drawable.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
#include <IGLU/simple_renderer/VertexData.h>
#include <memory>

namespace iglu {
namespace drawable {
namespace iglu::drawable {

/// A drawable aggregates all the data and configurations for a single draw call.
///
Expand Down Expand Up @@ -44,5 +43,4 @@ class Drawable final {
size_t _lastPipelineDescHash = 0;
};

} // namespace drawable
} // namespace iglu
} // namespace iglu::drawable
10 changes: 4 additions & 6 deletions IGLU/simple_renderer/ForwardRenderPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@

#include <utility>

namespace iglu {
namespace renderpass {
namespace iglu::renderpass {

ForwardRenderPass::ForwardRenderPass(igl::IDevice& device) {
igl::CommandQueueDesc desc;
const igl::CommandQueueDesc desc{};
_commandQueue = device.createCommandQueue(desc, nullptr);
_backendType = device.getBackendType();
}
Expand Down Expand Up @@ -45,7 +44,7 @@ void ForwardRenderPass::begin(std::shared_ptr<igl::IFramebuffer> target,
const igl::RenderPassDesc* finalDesc = renderPassDescOverride ? renderPassDescOverride
: &defaultRenderPassDesc;

igl::CommandBufferDesc cbDesc;
const igl::CommandBufferDesc cbDesc;
_commandBuffer = _commandQueue->createCommandBuffer(cbDesc, nullptr);
_commandEncoder =
_commandBuffer->createRenderCommandEncoder(*finalDesc, _framebuffer, {}, nullptr);
Expand Down Expand Up @@ -98,5 +97,4 @@ igl::IRenderCommandEncoder& ForwardRenderPass::activeCommandEncoder() {
return *_commandEncoder;
}

} // namespace renderpass
} // namespace iglu
} // namespace iglu::renderpass
6 changes: 2 additions & 4 deletions IGLU/simple_renderer/ForwardRenderPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
#include <string>
#include <vector>

namespace iglu {
namespace renderpass {
namespace iglu::renderpass {

/// A simple "render pass" abstraction that hides low level graphics API details
/// like command queue, command encoder, render pipeline state and presentation.
Expand Down Expand Up @@ -62,5 +61,4 @@ class ForwardRenderPass final {
std::unique_ptr<igl::IRenderCommandEncoder> _commandEncoder;
};

} // namespace renderpass
} // namespace iglu
} // namespace iglu::renderpass
Loading

0 comments on commit 05a2cd4

Please sign in to comment.