Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate cpp code to latest #1374

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6d39469
Samsung C++ code
MarkY-LunarG Aug 21, 2023
2784581
Fix CPP output for Talos and VkCube
MarkY-LunarG Aug 22, 2023
10a9b12
Add per-handle nextIdx to make comparing easier
MarkY-LunarG Oct 12, 2023
751f1df
Fix pNext chain CPP output
MarkY-LunarG Oct 17, 2023
0ca0811
Update copyrights to include Google and LunarG
MarkY-LunarG Oct 17, 2023
fc9b3a8
Fix DescriptorUpdateTemplate usage
MarkY-LunarG Oct 18, 2023
d6d38a2
Applying coding standards
MarkY-LunarG Nov 20, 2023
ec7d451
Make toCPP conditional in CMake
MarkY-LunarG Nov 21, 2023
b3315e3
Remove xxHash source
MarkY-LunarG Nov 22, 2023
c931473
Increase memory, steps towards handling HW Bufs
MarkY-LunarG Nov 29, 2023
2428194
Get Android HW Buffer support compiling
MarkY-LunarG Dec 4, 2023
d223882
Fix ImportAndroidHWBuffer structure
MarkY-LunarG Dec 5, 2023
69b1d63
Fix imported semaphore support
MarkY-LunarG Dec 12, 2023
26011a9
Add initial opaque memory support
MarkY-LunarG Dec 15, 2023
460b979
Fix Aztec swapchain replay count
MarkY-LunarG Dec 18, 2023
a18e35c
First step to custom swapchain code
MarkY-LunarG Dec 21, 2023
2ad1f45
Implement toCpp virtual swapchain code
MarkY-LunarG Dec 28, 2023
aed8659
Add note in readme
MarkY-LunarG Jan 3, 2024
d9fcca6
toCpp: Remove pre-processor step
MarkY-LunarG Jan 4, 2024
2de6cd7
toCpp: Remove resource tracker
MarkY-LunarG Jan 7, 2024
3dad263
Add Android framebuffer boundary catch
MarkY-LunarG Jan 8, 2024
d746d0c
toCpp: Generator cleanup
MarkY-LunarG Jan 8, 2024
b40f146
toCpp: Fix a few minor issues
MarkY-LunarG Jan 16, 2024
b7366e4
toCpp: Update generated source
MarkY-LunarG Jan 16, 2024
60a1a25
toCpp: Fix talos replay on RADV
MarkY-LunarG Jan 22, 2024
f36dbbc
Modify Python
locke-lunarg Mar 6, 2024
ccfaaf3
Set TOCPP to default
locke-lunarg Mar 7, 2024
36ad2f2
Split too big string into three
locke-lunarg Mar 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ AlignEscapedNewlines: true
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortFunctionsOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ if(${GFXRECON_ENABLE_RELEASE_ASSERTS})
add_definitions(-DGFXRECON_ENABLE_RELEASE_ASSERTS)
endif()

option(GFXRECON_TOCPP_SUPPORT "Build ToCpp export tool as part of GFXReconstruct builds." TRUE)

if(MSVC)

# The host toolchain architecture (i.e. are the compiler and other tools compiled to ARM/Intel 32bit/64bit binaries):
Expand Down
1 change: 0 additions & 1 deletion android/framework/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ target_sources(gfxrecon_util
${GFXRECON_SOURCE_DIR}/framework/util/file_path.h
${GFXRECON_SOURCE_DIR}/framework/util/file_path.cpp
${GFXRECON_SOURCE_DIR}/framework/util/hash.h
${GFXRECON_SOURCE_DIR}/framework/util/hash.cpp
${GFXRECON_SOURCE_DIR}/framework/util/image_writer.h
${GFXRECON_SOURCE_DIR}/framework/util/image_writer.cpp
${GFXRECON_SOURCE_DIR}/framework/util/keyboard.h
Expand Down
77 changes: 77 additions & 0 deletions external/Tocpp-Android-Template/app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
cmake_minimum_required(VERSION 3.4.1)

function(sublist INPUT_LIST START_IDX LENGTH OUTPUT_LIST)
set(ENTRIES )
math(EXPR END_IDX "${START_IDX} + ${LENGTH}")

list(LENGTH ${INPUT_LIST} LIST_LENGTH)

foreach(IDX RANGE ${START_IDX} ${END_IDX})
if ((IDX GREATER LIST_LENGTH) OR (IDX EQUAL LIST_LENGTH))
break()
endif()

list(GET ${INPUT_LIST} ${IDX} ITEM)
list(APPEND ENTRIES ${ITEM})
endforeach()

set(${OUTPUT_LIST} ${ENTRIES} PARENT_SCOPE)

endfunction(sublist)

set(LIBNAME gfxtocpp)

# build native_app_glue as a static lib
set(APP_GLUE_DIR ${ANDROID_NDK}/sources/android/native_app_glue)
include_directories(${APP_GLUE_DIR})
add_library(app-glue STATIC ${APP_GLUE_DIR}/android_native_app_glue.c)

# build vulkan app
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Werror")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")

set(JNI_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/main/jni)
set(GENERATED_FRAMES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/main/assets/src)

# Base lib
add_library(${LIBNAME}-base SHARED
${JNI_DIR}/ScreenOrientation.cpp
${GENERATED_FRAMES_DIR}/swapchain_common.cpp
${GENERATED_FRAMES_DIR}/swapchain_common.h
${GENERATED_FRAMES_DIR}/global_var.cpp
${GENERATED_FRAMES_DIR}/global_var.h
${GENERATED_FRAMES_DIR}/loader.cpp
${GENERATED_FRAMES_DIR}/loader.h
)
target_link_libraries(${LIBNAME}-base PUBLIC log android vulkan)
target_include_directories(${LIBNAME}-base PUBLIC ${JNI_DIR})

# Main lib
add_library(${LIBNAME} SHARED
${JNI_DIR}/VulkanMain.cpp
${JNI_DIR}/AndroidMain.cpp
)
target_link_libraries(${LIBNAME} app-glue)

target_include_directories(${LIBNAME}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/main/assets/src/
${JNI_DIR}
)

# Frame libraries
set(FILE_LIMIT 500)

file(GLOB SRC_FILES ${GENERATED_FRAMES_DIR}/frame_*.cpp)
list(SORT SRC_FILES)
list(LENGTH SRC_FILES FILE_COUNT)
math(EXPR LIB_COUNT "${FILE_COUNT} / ${FILE_LIMIT}")

foreach(LIB_IDX RANGE 0 ${LIB_COUNT})
math(EXPR START_IDX "${LIB_IDX} * ${FILE_LIMIT}")
sublist(SRC_FILES ${START_IDX} ${FILE_LIMIT} LIB_FILES)

set(FRAME_LIBNAME ${LIBNAME}-frames-${LIB_IDX})
add_library(${FRAME_LIBNAME} SHARED ${LIB_FILES})
target_link_libraries(${FRAME_LIBNAME} PUBLIC ${LIBNAME}-base)
target_link_libraries(${LIBNAME} ${FRAME_LIBNAME})
endforeach()
29 changes: 29 additions & 0 deletions external/Tocpp-Android-Template/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 28

defaultConfig {
applicationId "com.lunarg.gfxreconstruct.tocpp"
minSdkVersion 28
targetSdkVersion 28
versionCode 1
versionName "0.0.1"

externalNativeBuild {
cmake {
abiFilters 'arm64-v8a'
arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_static'
}
}
}
aaptOptions {
// .spv and .bin files should not be compressed as reading compressed assets can be slow
noCompress 'spv', 'bin'
}
externalNativeBuild {
cmake {
path 'CMakeLists.txt'
}
}
}
25 changes: 25 additions & 0 deletions external/Tocpp-Android-Template/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- BEGIN_INCLUDE(manifest) -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lunarg.gfxreconstruct.tocpp">

<application android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">

<!-- Our activity is the built-in NativeActivity framework class.
This will take care of integrating with our NDK code. -->
<activity android:name="android.app.NativeActivity"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden">
<!-- Tell NativeActivity the name of or .so -->
<meta-data android:name="android.app.lib_name"
android:value="gfxtocpp" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
<!-- END_INCLUDE(manifest) -->
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef __ANDROIDLOGGING_HPP__
#define __ANDROIDLOGGING_HPP__

#include <android/log.h>

// Android log function wrappers
static const char* kTAG = "GFXReconstruct-ToCpp";
#define LOGI(...) \
((void)__android_log_print(ANDROID_LOG_INFO, kTAG, __VA_ARGS__))
#define LOGW(...) \
((void)__android_log_print(ANDROID_LOG_WARN, kTAG, __VA_ARGS__))
#define LOGE(...) \
((void)__android_log_print(ANDROID_LOG_ERROR, kTAG, __VA_ARGS__))

#endif // __ANDROIDLOGGING_HPP__
31 changes: 31 additions & 0 deletions external/Tocpp-Android-Template/app/src/main/jni/AndroidMain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "AndroidLogging.hpp"
#include "VulkanMain.hpp"

// Process the next main command.
void handle_cmd(android_app* app, int32_t cmd) {
LOGI("event not handled: %d", cmd);
}

void android_main(struct android_app* app) {
// Set the callback to process system events
app->onAppCmd = handle_cmd;

// Used to poll the events in the main loop
int events;
android_poll_source* source;

// Main loop
do {
if (ALooper_pollAll(1, nullptr,
&events, (void**)&source) >= 0) {
if (source != NULL) {
source->process(app, source);
}
}
if (app->window) {
VulkanDrawFrame(app);
}
} while (app->destroyRequested == 0);

ANativeActivity_finish(app->activity);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#include "ScreenOrientation.hpp"

#include "AndroidLogging.hpp"

#include <array>

AndroidScreen::AndroidScreen(android_app* application)
{
m_application = application;

if (m_application != nullptr && m_application->window != nullptr) {
m_width = ANativeWindow_getWidth(m_application->window);
m_height = ANativeWindow_getHeight(m_application->window);
} else {
m_width = -1;
m_height = -1;
}

m_pretransform = 0;
}

// NOTE: This function is the same with AndroidApplication::SetOrientation().
void AndroidScreen::windowSetOrientation(ScreenOrientation orientation)
{
JavaVM* jni_vm = nullptr;
jobject jni_activity = nullptr;
JNIEnv* env = nullptr;

if ((m_application != nullptr) && (m_application->activity != nullptr))
{
jni_vm = m_application->activity->vm;
jni_activity = m_application->activity->clazz;
}

if ((jni_vm != nullptr) && (jni_activity != 0) && (jni_vm->AttachCurrentThread(&env, nullptr) == JNI_OK))
{
jclass object_class = env->GetObjectClass(jni_activity);
jmethodID set_orientation = env->GetMethodID(object_class, "setRequestedOrientation", "(I)V");

env->CallVoidMethod(jni_activity, set_orientation, orientation);

jni_vm->DetachCurrentThread();
}
}

// NOTE: This function is the same with AndroidWindow::SetSizePreTransform().
void AndroidScreen::windowSetSizePreTransform(const uint32_t width, const uint32_t height, const uint32_t pre_transform)
{
if ((width != m_width) || (height != m_height) || (pre_transform != m_pretransform))
{
m_width = width;
m_height = height;
m_pretransform = pre_transform;

if ((m_application == nullptr) || (m_application->window == nullptr))
{
LOGE("Failed to resize the window!");
return;
}

// For Android, we adjust the screen orientation based on requested width and height.
int32_t pixel_width = ANativeWindow_getWidth(m_application->window);
int32_t pixel_height = ANativeWindow_getHeight(m_application->window);

// We don't change the current orientation if width == height or if the requested orientation matches the
// current orientation, unless a pre-transform has been applied to the swapchain, in which case the orientation
// will be adjusted to match the pre-transform.
if (((width != height) && ((width < height) != (pixel_width < pixel_height))) ||
(pre_transform != ResizeWindowPreTransform::kPreTransform0))
{
const std::array<ScreenOrientation, 2> kOrientations{
ScreenOrientation::kLandscape,
ScreenOrientation::kPortrait
};

uint32_t orientation_index = 0;

if (height > width)
{
orientation_index = 1;
}

// Toggle orientation between landscape and portrait for 90 and 270 degree pre-transform values.
if ((pre_transform == ResizeWindowPreTransform::kPreTransform90) ||
(pre_transform == ResizeWindowPreTransform::kPreTransform270))
{
orientation_index ^= 1;
}

windowSetOrientation(kOrientations[orientation_index]);
}

int32_t result = ANativeWindow_setBuffersGeometry(m_application->window, width, height, ANativeWindow_getFormat(m_application->window));
if (result != 0)
{
LOGE("Failed to change native window geometry: ANativeWindow_setBuffersGeometry returned %d", result);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef __SCREENORIENTATION_HPP__
#define __SCREENORIENTATION_HPP__

#include <android_native_app_glue.h>

class AndroidScreen {
public:
enum ScreenOrientation : int32_t
{
kLandscape = 0,
kPortrait = 1
};

enum ResizeWindowPreTransform : uint32_t
{
kPreTransform0 = 0,
kPreTransform90 = 1,
kPreTransform180 = 2,
kPreTransform270 = 3
};

AndroidScreen() {};
AndroidScreen(android_app* application);
void windowSetSizePreTransform(const uint32_t width, const uint32_t height, const uint32_t pre_transform);

private:
android_app* m_application;
int32_t m_width;
int32_t m_height;
int32_t m_pretransform;

void windowSetOrientation(ScreenOrientation orientation);
};

#endif // __SCREENORIENTATION_HPP__
35 changes: 35 additions & 0 deletions external/Tocpp-Android-Template/app/src/main/jni/VulkanMain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "VulkanMain.hpp"

#include <string>
#include <vulkan/vulkan.h>

#ifdef VK_USE_PLATFORM_ANDROID_KHR
void OverrideVkAndroidSurfaceCreateInfoKHR(VkAndroidSurfaceCreateInfoKHR* createInfo, struct ANativeWindow* window);
#endif /* VK_USE_PLATFORM_ANDROID_KHR */

void FuncCallCheck(VkResult returnValue);


void VulkanDrawFrame(android_app* app) {
// ---- The generated source is placed below. -----

// VkInstanceCreateInfo...

// ---- The generated source is ended. -----
}

#ifdef VK_USE_PLATFORM_ANDROID_KHR
void OverrideVkAndroidSurfaceCreateInfoKHR(VkAndroidSurfaceCreateInfoKHR* createInfo, struct ANativeWindow* window) {
createInfo->sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
createInfo->pNext = nullptr;
createInfo->flags = 0;
createInfo->window = window;
}
#endif /* VK_USE_PLATFORM_ANDROID_KHR */

void FuncCallCheck(VkResult returnValue)
{
if (returnValue != VK_SUCCESS) {
throw std::runtime_error("Command failed!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef __VULKANMAIN_HPP__
#define __VULKANMAIN_HPP__

#include <android_native_app_glue.h>

void VulkanDrawFrame(android_app* app);

#endif // __VULKANMAIN_HPP__
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">GFXReconstruct-ToCpp</string>
</resources>
Loading
Loading