Skip to content

Commit 1cd72f3

Browse files
committedFeb 16, 2025
New dynamic rendering multi sampling example
Work-in-progress
1 parent a87dfde commit 1cd72f3

File tree

7 files changed

+594
-0
lines changed

7 files changed

+594
-0
lines changed
 

‎README.md

+4
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,10 @@ Vulkan is an extensible api with lots of functionality added by extensions. Thes
446446

447447
Shows usage of the VK_KHR_dynamic_rendering extension, which simplifies the rendering setup by no longer requiring render pass objects or framebuffers.
448448

449+
- [Dynamic rendering with multi sampling (VK_KHR_dynamic_rendering)](examples/dynamicrenderingmultisampling/)
450+
451+
Based on the dynamic rendering sample, this sample shows how to do implement multi sampling with dynamic rendering.
452+
449453
- [Graphics pipeline library (VK_EXT_graphics_pipeline_library)](./examples/graphicspipelinelibrary)
450454

451455
Uses the graphics pipeline library extensions to improve run-time pipeline creation. Instead of creating the whole pipeline at once, this sample pre builds shared pipeline parts like like vertex input state and fragment output state. These are then used to create full pipelines at runtime, reducing build times and possible hick-ups.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
cmake_minimum_required(VERSION 3.4.1 FATAL_ERROR)
2+
3+
set(NAME dynamicrenderingmultisampling)
4+
5+
set(SRC_DIR ../../../examples/${NAME})
6+
set(BASE_DIR ../../../base)
7+
set(EXTERNAL_DIR ../../../external)
8+
9+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -DVK_USE_PLATFORM_ANDROID_KHR -DVK_NO_PROTOTYPES")
10+
11+
file(GLOB EXAMPLE_SRC "${SRC_DIR}/*.cpp")
12+
13+
add_library(native-lib SHARED ${EXAMPLE_SRC})
14+
15+
add_library(native-app-glue STATIC ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)
16+
17+
add_subdirectory(../base ${CMAKE_SOURCE_DIR}/../base)
18+
19+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
20+
21+
include_directories(${BASE_DIR})
22+
include_directories(${EXTERNAL_DIR})
23+
include_directories(${EXTERNAL_DIR}/glm)
24+
include_directories(${EXTERNAL_DIR}/imgui)
25+
include_directories(${EXTERNAL_DIR}/tinygltf)
26+
include_directories(${ANDROID_NDK}/sources/android/native_app_glue)
27+
28+
target_link_libraries(
29+
native-lib
30+
native-app-glue
31+
libbase
32+
android
33+
log
34+
z
35+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
apply plugin: 'com.android.application'
2+
apply from: '../gradle/outputfilename.gradle'
3+
4+
android {
5+
compileSdkVersion rootProject.ext.compileSdkVersion
6+
defaultConfig {
7+
applicationId "de.saschawillems.vulkanDynamicrenderingmulitsampling"
8+
minSdkVersion rootProject.ext.minSdkVersion
9+
targetSdkVersion rootProject.ext.targetSdkVersion
10+
versionCode 1
11+
versionName "1.0"
12+
ndk {
13+
abiFilters rootProject.ext.abiFilters
14+
}
15+
externalNativeBuild {
16+
cmake {
17+
cppFlags "-std=c++14"
18+
arguments "-DANDROID_STL=c++_shared", '-DANDROID_TOOLCHAIN=clang'
19+
}
20+
}
21+
}
22+
sourceSets {
23+
main.assets.srcDirs = ['assets']
24+
}
25+
buildTypes {
26+
release {
27+
minifyEnabled false
28+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
29+
}
30+
}
31+
externalNativeBuild {
32+
cmake {
33+
path "CMakeLists.txt"
34+
}
35+
}
36+
}
37+
38+
task copyTask {
39+
copy {
40+
from '../../common/res/drawable'
41+
into "src/main/res/drawable"
42+
include 'icon.png'
43+
}
44+
45+
copy {
46+
from rootProject.ext.shaderPath + 'glsl/base'
47+
into 'assets/shaders/glsl/base'
48+
include '*.spv'
49+
}
50+
51+
copy {
52+
from rootProject.ext.shaderPath + 'glsl/dynamicrendering'
53+
into 'assets/shaders/glsl/dynamicrendering'
54+
include '*.*'
55+
}
56+
57+
copy {
58+
from rootProject.ext.assetPath + 'models'
59+
into 'assets/models'
60+
include 'voyager.gltf'
61+
}
62+
63+
}
64+
65+
preBuild.dependsOn copyTask
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<application
5+
android:label="Vulkan dynamic rendering with multi sampling"
6+
android:icon="@drawable/icon"
7+
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
8+
<activity android:name="de.saschawillems.vulkanSample.VulkanActivity"
9+
android:screenOrientation="landscape"
10+
android:configChanges="orientation|keyboardHidden"
11+
android:exported="true">
12+
<meta-data android:name="android.app.lib_name"
13+
android:value="native-lib" />
14+
<intent-filter>
15+
<action android:name="android.intent.action.MAIN" />
16+
<category android:name="android.intent.category.LAUNCHER" />
17+
</intent-filter>
18+
</activity>
19+
</application>
20+
21+
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
22+
<uses-feature android:name="android.hardware.gamepad" android:required="false" />
23+
24+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (C) 2018 by Sascha Willems - www.saschawillems.de
3+
*
4+
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
5+
*/
6+
package de.saschawillems.vulkanSample;
7+
8+
import android.app.AlertDialog;
9+
import android.app.NativeActivity;
10+
import android.content.DialogInterface;
11+
import android.content.pm.ApplicationInfo;
12+
import android.os.Bundle;
13+
14+
import java.util.concurrent.Semaphore;
15+
16+
public class VulkanActivity extends NativeActivity {
17+
18+
static {
19+
// Load native library
20+
System.loadLibrary("native-lib");
21+
}
22+
@Override
23+
protected void onCreate(Bundle savedInstanceState) {
24+
super.onCreate(savedInstanceState);
25+
}
26+
27+
// Use a semaphore to create a modal dialog
28+
29+
private final Semaphore semaphore = new Semaphore(0, true);
30+
31+
public void showAlert(final String message)
32+
{
33+
final VulkanActivity activity = this;
34+
35+
ApplicationInfo applicationInfo = activity.getApplicationInfo();
36+
final String applicationName = applicationInfo.nonLocalizedLabel.toString();
37+
38+
this.runOnUiThread(new Runnable() {
39+
public void run() {
40+
AlertDialog.Builder builder = new AlertDialog.Builder(activity, android.R.style.Theme_Material_Dialog_Alert);
41+
builder.setTitle(applicationName);
42+
builder.setMessage(message);
43+
builder.setPositiveButton("Close", new DialogInterface.OnClickListener() {
44+
public void onClick(DialogInterface dialog, int id) {
45+
semaphore.release();
46+
}
47+
});
48+
builder.setCancelable(false);
49+
AlertDialog dialog = builder.create();
50+
dialog.show();
51+
}
52+
});
53+
try {
54+
semaphore.acquire();
55+
}
56+
catch (InterruptedException e) { }
57+
}
58+
}

‎examples/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ set(EXAMPLES
109109
displacement
110110
distancefieldfonts
111111
dynamicrendering
112+
dynamicrenderingmultisampling
112113
dynamicstate
113114
dynamicuniformbuffer
114115
gears

‎examples/dynamicrenderingmultisampling/dynamicrenderingmultisampling.cpp

+407
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.