xuning

init

正在显示 31 个修改的文件 包含 4861 行增加0 行删除

要显示太多修改。

为保证性能只显示 31 of 31+ 个文件。

  1 +*.iml
  2 +.kotlin
  3 +.gradle
  4 +**/build/
  5 +xcuserdata
  6 +!src/**/build/
  7 +local.properties
  8 +.idea
  9 +.DS_Store
  10 +captures
  11 +.externalNativeBuild
  12 +.cxx
  13 +*.xcodeproj/*
  14 +!*.xcodeproj/project.pbxproj
  15 +!*.xcodeproj/xcshareddata/
  16 +!*.xcodeproj/project.xcworkspace/
  17 +!*.xcworkspace/contents.xcworkspacedata
  18 +**/xcshareddata/WorkspaceSettings.xcsettings
  19 +/opencvsdk/
  1 +This is a Kotlin Multiplatform project targeting Android, iOS, Web, Desktop.
  2 +
  3 +* `/composeApp` is for code that will be shared across your Compose Multiplatform applications.
  4 + It contains several subfolders:
  5 + - `commonMain` is for code that’s common for all targets.
  6 + - Other folders are for Kotlin code that will be compiled for only the platform indicated in the folder name.
  7 + For example, if you want to use Apple’s CoreCrypto for the iOS part of your Kotlin app,
  8 + `iosMain` would be the right folder for such calls.
  9 +
  10 +* `/iosApp` contains iOS applications. Even if you’re sharing your UI with Compose Multiplatform,
  11 + you need this entry point for your iOS app. This is also where you should add SwiftUI code for your project.
  12 +
  13 +
  14 +Learn more about [Kotlin Multiplatform](https://www.jetbrains.com/help/kotlin-multiplatform-dev/get-started.html),
  15 +[Compose Multiplatform](https://github.com/JetBrains/compose-multiplatform/#compose-multiplatform),
  16 +[Kotlin/Wasm](https://kotl.in/wasm/)
  17 +
  18 +We would appreciate your feedback on Compose/Web and Kotlin/Wasm in the public Slack channel [#compose-web](https://slack-chats.kotlinlang.org/c/compose-web).
  19 +If you face any issues, please report them on [YouTrack](https://youtrack.jetbrains.com/newIssue?project=CMP).
  20 +
  21 +You can open the web application by running the `:composeApp:wasmJsBrowserDevelopmentRun` Gradle task.
  1 +plugins {
  2 + // this is necessary to avoid the plugins to be loaded multiple times
  3 + // in each subproject's classloader
  4 + alias(libs.plugins.androidApplication) apply false
  5 + alias(libs.plugins.androidLibrary) apply false
  6 + alias(libs.plugins.composeHotReload) apply false
  7 + alias(libs.plugins.composeMultiplatform) apply false
  8 + alias(libs.plugins.composeCompiler) apply false
  9 + alias(libs.plugins.kotlinMultiplatform) apply false
  10 +}
  1 +import org.jetbrains.compose.desktop.application.dsl.TargetFormat
  2 +import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
  3 +import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
  4 +import org.jetbrains.kotlin.gradle.dsl.JvmTarget
  5 +import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
  6 +
  7 +plugins {
  8 + alias(libs.plugins.kotlinMultiplatform)
  9 + alias(libs.plugins.androidApplication)
  10 + alias(libs.plugins.composeMultiplatform)
  11 + alias(libs.plugins.composeCompiler)
  12 + alias(libs.plugins.composeHotReload)
  13 + kotlin("plugin.serialization") version "2.2.0"
  14 +}
  15 +
  16 +kotlin {
  17 + val ktorVersion = "3.2.2"
  18 +
  19 +
  20 + androidTarget {
  21 + @OptIn(ExperimentalKotlinGradlePluginApi::class)
  22 + compilerOptions {
  23 + jvmTarget.set(JvmTarget.JVM_11)
  24 + }
  25 + }
  26 +
  27 + listOf(
  28 + iosX64(),
  29 + iosArm64(),
  30 + iosSimulatorArm64()
  31 + ).forEach { iosTarget ->
  32 + iosTarget.binaries.framework {
  33 + baseName = "ComposeApp"
  34 + isStatic = true
  35 + }
  36 + }
  37 +
  38 + jvm("desktop")
  39 +
  40 + @OptIn(ExperimentalWasmDsl::class)
  41 + wasmJs {
  42 + outputModuleName.set("composeApp")
  43 + browser {
  44 + val rootDirPath = project.rootDir.path
  45 + val projectDirPath = project.projectDir.path
  46 + commonWebpackConfig {
  47 + outputFileName = "composeApp.js"
  48 + devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply {
  49 + static = (static ?: mutableListOf()).apply {
  50 + // Serve sources to debug inside browser
  51 + add(rootDirPath)
  52 + add(projectDirPath)
  53 + }
  54 + }
  55 + }
  56 + }
  57 + binaries.executable()
  58 + }
  59 +
  60 + sourceSets {
  61 + val desktopMain by getting
  62 +
  63 + androidMain.dependencies {
  64 + implementation(compose.preview)
  65 + implementation(libs.androidx.activity.compose)
  66 + implementation("io.ktor:ktor-client-android:$ktorVersion")
  67 + implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2")
  68 + implementation("androidx.lifecycle:lifecycle-runtime-compose:2.6.2")
  69 + implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.6.2")
  70 + implementation("org.opencv:opencv:4.12.0")
  71 +
  72 + }
  73 + commonMain.dependencies {
  74 + implementation(compose.runtime)
  75 + implementation(compose.foundation)
  76 + implementation(compose.material3)
  77 + implementation(compose.ui)
  78 + implementation(compose.components.resources)
  79 + implementation(compose.components.uiToolingPreview)
  80 + implementation(libs.androidx.lifecycle.viewmodel)
  81 + implementation(libs.androidx.lifecycle.runtimeCompose)
  82 + implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.6.2")
  83 + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2")
  84 + implementation("io.ktor:ktor-client-core:$ktorVersion")
  85 + implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
  86 + implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
  87 +
  88 + implementation("io.ktor:ktor-client-cio:$ktorVersion")
  89 +
  90 + }
  91 + commonTest.dependencies {
  92 + implementation(libs.kotlin.test)
  93 + }
  94 + desktopMain.dependencies {
  95 + implementation(compose.desktop.currentOs)
  96 + implementation(libs.kotlinx.coroutinesSwing)
  97 + }
  98 + iosMain.dependencies {
  99 + implementation("io.ktor:ktor-client-darwin:$ktorVersion")
  100 + }
  101 + }
  102 +}
  103 +
  104 +android {
  105 + namespace = "org.example.project"
  106 + compileSdk = libs.versions.android.compileSdk.get().toInt()
  107 +
  108 + defaultConfig {
  109 + applicationId = "org.example.project"
  110 + minSdk = libs.versions.android.minSdk.get().toInt()
  111 + targetSdk = libs.versions.android.targetSdk.get().toInt()
  112 + versionCode = 1
  113 + versionName = "1.0"
  114 +
  115 + externalNativeBuild {
  116 + cmake {
  117 + arguments += "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
  118 + }
  119 + }
  120 + }
  121 + sourceSets {
  122 + getByName("main") {
  123 + jniLibs.srcDirs("src/androidMain/jniLibs")
  124 + }
  125 + }
  126 + packaging {
  127 + resources {
  128 + excludes += "/META-INF/{AL2.0,LGPL2.1}"
  129 + }
  130 + }
  131 + buildTypes {
  132 + getByName("release") {
  133 + isMinifyEnabled = false
  134 + }
  135 + }
  136 + compileOptions {
  137 + sourceCompatibility = JavaVersion.VERSION_11
  138 + targetCompatibility = JavaVersion.VERSION_11
  139 + }
  140 + externalNativeBuild {
  141 + cmake {
  142 + path = file("src/androidMain/jni/CMakeLists.txt")
  143 + }
  144 + }
  145 +}
  146 +
  147 +dependencies {
  148 + debugImplementation(compose.uiTooling)
  149 +}
  150 +
  151 +compose.desktop {
  152 + application {
  153 + mainClass = "org.example.project.MainKt"
  154 +
  155 + nativeDistributions {
  156 + targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
  157 + packageName = "org.example.project"
  158 + packageVersion = "1.0.0"
  159 + }
  160 + }
  161 +}
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<manifest xmlns:android="http://schemas.android.com/apk/res/android">
  3 + <uses-permission android:name="android.permission.INTERNET"/>
  4 + <uses-permission android:name="android.permission.CAMERA" />
  5 + <uses-feature android:name="android.hardware.camera2.full" />
  6 + <uses-feature android:name="android.hardware.camera" android:required="false" />
  7 +
  8 + <application
  9 + android:allowBackup="true"
  10 + android:icon="@mipmap/ic_launcher"
  11 + android:label="@string/app_name"
  12 + android:roundIcon="@mipmap/ic_launcher_round"
  13 + android:supportsRtl="true"
  14 + android:theme="@android:style/Theme.Material.Light.NoActionBar">
  15 + <activity
  16 + android:exported="true"
  17 + android:name=".MainActivity">
  18 + <intent-filter>
  19 + <action android:name="android.intent.action.MAIN" />
  20 +
  21 + <category android:name="android.intent.category.LAUNCHER" />
  22 + </intent-filter>
  23 + </activity>
  24 + </application>
  25 +
  26 +</manifest>
  1 +7767517
  2 +321 415
  3 +Input in0 0 1 in0
  4 +Split splitncnn_0 1 6 in0 1 2 3 4 5 6
  5 +Input in1 0 1 in1
  6 +Split splitncnn_1 1 7 in1 8 9 10 11 12 13 14
  7 +Input in2 0 1 in2
  8 +Split splitncnn_2 1 3 in2 16 17 18
  9 +Input in3 0 1 in3
  10 +Split splitncnn_3 1 3 in3 20 21 22
  11 +Input in4 0 1 in4
  12 +Split splitncnn_4 1 3 in4 24 25 26
  13 +Input in5 0 1 in5
  14 +Split splitncnn_5 1 3 in5 28 29 30
  15 +MemoryData pnnx_fold_mean0.1 0 1 31 0=1 1=1 2=3
  16 +MemoryData pnnx_fold_std0.1 0 1 32 0=1 1=1 2=3
  17 +BinaryOp sub_0 2 1 14 31 33 0=1
  18 +BinaryOp div_1 2 1 33 32 34 0=3
  19 +Convolution conv_12 1 1 34 35 0=16 1=3 11=3 12=1 13=2 14=1 2=1 3=2 4=1 5=1 6=432
  20 +HardSwish hswish_87 1 1 35 36 0=1.666667e-01 1=5.000000e-01
  21 +Split splitncnn_6 1 2 36 37 38
  22 +ConvolutionDepthWise convdwrelu_0 1 1 38 39 0=16 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=144 7=16 9=1
  23 +Convolution conv_13 1 1 39 40 0=16 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=256
  24 +BinaryOp add_2 2 1 40 37 41 0=0
  25 +Split splitncnn_7 1 2 41 42 43
  26 +Convolution convrelu_0 1 1 43 44 0=64 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=1024 9=1
  27 +ConvolutionDepthWise convdwrelu_1 1 1 44 45 0=64 1=3 11=3 12=1 13=2 14=1 2=1 3=2 4=1 5=1 6=576 7=64 9=1
  28 +Convolution conv_15 1 1 45 46 0=24 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=1536
  29 +Split splitncnn_8 1 2 46 47 48
  30 +Convolution convrelu_1 1 1 48 49 0=72 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=1728 9=1
  31 +ConvolutionDepthWise convdwrelu_2 1 1 49 50 0=72 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=648 7=72 9=1
  32 +Convolution conv_17 1 1 50 51 0=24 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=1728
  33 +BinaryOp add_3 2 1 51 47 52 0=0
  34 +Split splitncnn_9 1 2 52 53 54
  35 +Convolution convrelu_2 1 1 54 55 0=72 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=1728 9=1
  36 +ConvolutionDepthWise convdwrelu_3 1 1 55 56 0=72 1=5 11=5 12=1 13=2 14=2 2=1 3=2 4=2 5=1 6=1800 7=72 9=1
  37 +Split splitncnn_10 1 2 56 57 58
  38 +Pooling gap_0 1 1 58 59 0=1 4=1
  39 +Convolution convrelu_3 1 1 59 60 0=24 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=1728 9=1
  40 +Convolution conv_20 1 1 60 61 0=72 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=1728
  41 +HardSigmoid hsigmoid_79 1 1 61 62 0=1.666667e-01 1=5.000000e-01
  42 +Reshape reshape_147 1 1 62 63 0=1 1=1 2=-1
  43 +BinaryOp mul_4 2 1 63 57 64 0=2
  44 +Convolution conv_21 1 1 64 65 0=40 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=2880
  45 +Split splitncnn_11 1 2 65 66 67
  46 +Convolution convrelu_4 1 1 67 68 0=120 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=4800 9=1
  47 +ConvolutionDepthWise convdwrelu_4 1 1 68 69 0=120 1=5 11=5 12=1 13=1 14=2 2=1 3=1 4=2 5=1 6=3000 7=120 9=1
  48 +Split splitncnn_12 1 2 69 70 71
  49 +Pooling gap_1 1 1 71 72 0=1 4=1
  50 +Convolution convrelu_5 1 1 72 73 0=32 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=3840 9=1
  51 +Convolution conv_24 1 1 73 74 0=120 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=3840
  52 +HardSigmoid hsigmoid_80 1 1 74 75 0=1.666667e-01 1=5.000000e-01
  53 +Reshape reshape_148 1 1 75 76 0=1 1=1 2=-1
  54 +BinaryOp mul_5 2 1 76 70 77 0=2
  55 +Convolution conv_25 1 1 77 78 0=40 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=4800
  56 +BinaryOp add_6 2 1 78 66 79 0=0
  57 +Split splitncnn_13 1 2 79 80 81
  58 +Convolution convrelu_6 1 1 81 82 0=120 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=4800 9=1
  59 +ConvolutionDepthWise convdwrelu_5 1 1 82 83 0=120 1=5 11=5 12=1 13=1 14=2 2=1 3=1 4=2 5=1 6=3000 7=120 9=1
  60 +Split splitncnn_14 1 2 83 84 85
  61 +Pooling gap_2 1 1 85 86 0=1 4=1
  62 +Convolution convrelu_7 1 1 86 87 0=32 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=3840 9=1
  63 +Convolution conv_28 1 1 87 88 0=120 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=3840
  64 +HardSigmoid hsigmoid_81 1 1 88 89 0=1.666667e-01 1=5.000000e-01
  65 +Reshape reshape_149 1 1 89 90 0=1 1=1 2=-1
  66 +BinaryOp mul_7 2 1 90 84 91 0=2
  67 +Convolution conv_29 1 1 91 92 0=40 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=4800
  68 +BinaryOp add_8 2 1 92 80 93 0=0
  69 +Split splitncnn_15 1 2 93 94 95
  70 +Convolution conv_30 1 1 95 96 0=240 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=9600
  71 +HardSwish hswish_88 1 1 96 97 0=1.666667e-01 1=5.000000e-01
  72 +ConvolutionDepthWise convdw_165 1 1 97 98 0=240 1=3 11=3 12=1 13=2 14=1 2=1 3=2 4=1 5=1 6=2160 7=240
  73 +HardSwish hswish_89 1 1 98 99 0=1.666667e-01 1=5.000000e-01
  74 +Convolution conv_31 1 1 99 100 0=80 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=19200
  75 +Split splitncnn_16 1 2 100 101 102
  76 +Convolution conv_32 1 1 102 103 0=200 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=16000
  77 +HardSwish hswish_90 1 1 103 104 0=1.666667e-01 1=5.000000e-01
  78 +ConvolutionDepthWise convdw_166 1 1 104 105 0=200 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=1800 7=200
  79 +HardSwish hswish_91 1 1 105 106 0=1.666667e-01 1=5.000000e-01
  80 +Convolution conv_33 1 1 106 107 0=80 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=16000
  81 +BinaryOp add_9 2 1 107 101 108 0=0
  82 +Split splitncnn_17 1 2 108 109 110
  83 +Convolution conv_34 1 1 110 111 0=184 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=14720
  84 +HardSwish hswish_92 1 1 111 112 0=1.666667e-01 1=5.000000e-01
  85 +ConvolutionDepthWise convdw_167 1 1 112 113 0=184 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=1656 7=184
  86 +HardSwish hswish_93 1 1 113 114 0=1.666667e-01 1=5.000000e-01
  87 +Convolution conv_35 1 1 114 115 0=80 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=14720
  88 +BinaryOp add_10 2 1 115 109 116 0=0
  89 +Split splitncnn_18 1 2 116 117 118
  90 +Convolution conv_36 1 1 118 119 0=184 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=14720
  91 +HardSwish hswish_94 1 1 119 120 0=1.666667e-01 1=5.000000e-01
  92 +ConvolutionDepthWise convdw_168 1 1 120 121 0=184 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=1656 7=184
  93 +HardSwish hswish_95 1 1 121 122 0=1.666667e-01 1=5.000000e-01
  94 +Convolution conv_37 1 1 122 123 0=80 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=14720
  95 +BinaryOp add_11 2 1 123 117 124 0=0
  96 +Convolution conv_38 1 1 124 125 0=480 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=38400
  97 +HardSwish hswish_96 1 1 125 126 0=1.666667e-01 1=5.000000e-01
  98 +ConvolutionDepthWise convdw_169 1 1 126 127 0=480 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=4320 7=480
  99 +HardSwish hswish_97 1 1 127 128 0=1.666667e-01 1=5.000000e-01
  100 +Split splitncnn_19 1 2 128 129 130
  101 +Pooling gap_3 1 1 130 131 0=1 4=1
  102 +Convolution convrelu_8 1 1 131 132 0=120 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=57600 9=1
  103 +Convolution conv_40 1 1 132 133 0=480 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=57600
  104 +HardSigmoid hsigmoid_82 1 1 133 134 0=1.666667e-01 1=5.000000e-01
  105 +Reshape reshape_150 1 1 134 135 0=1 1=1 2=-1
  106 +BinaryOp mul_12 2 1 135 129 136 0=2
  107 +Convolution conv_41 1 1 136 137 0=112 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=53760
  108 +Split splitncnn_20 1 2 137 138 139
  109 +Convolution conv_42 1 1 139 140 0=672 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=75264
  110 +HardSwish hswish_98 1 1 140 141 0=1.666667e-01 1=5.000000e-01
  111 +ConvolutionDepthWise convdw_170 1 1 141 142 0=672 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=6048 7=672
  112 +HardSwish hswish_99 1 1 142 143 0=1.666667e-01 1=5.000000e-01
  113 +Split splitncnn_21 1 2 143 144 145
  114 +Pooling gap_4 1 1 145 146 0=1 4=1
  115 +Convolution convrelu_9 1 1 146 147 0=168 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=112896 9=1
  116 +Convolution conv_44 1 1 147 148 0=672 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=112896
  117 +HardSigmoid hsigmoid_83 1 1 148 149 0=1.666667e-01 1=5.000000e-01
  118 +Reshape reshape_151 1 1 149 150 0=1 1=1 2=-1
  119 +BinaryOp mul_13 2 1 150 144 151 0=2
  120 +Convolution conv_45 1 1 151 152 0=112 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=75264
  121 +BinaryOp add_14 2 1 152 138 153 0=0
  122 +Convolution conv_46 1 1 153 154 0=672 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=75264
  123 +HardSwish hswish_100 1 1 154 155 0=1.666667e-01 1=5.000000e-01
  124 +ConvolutionDepthWise convdw_171 1 1 155 156 0=672 1=5 11=5 12=2 13=1 14=4 2=2 3=1 4=4 5=1 6=16800 7=672
  125 +HardSwish hswish_101 1 1 156 157 0=1.666667e-01 1=5.000000e-01
  126 +Split splitncnn_22 1 2 157 158 159
  127 +Pooling gap_5 1 1 159 160 0=1 4=1
  128 +Convolution convrelu_10 1 1 160 161 0=168 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=112896 9=1
  129 +Convolution conv_48 1 1 161 162 0=672 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=112896
  130 +HardSigmoid hsigmoid_84 1 1 162 163 0=1.666667e-01 1=5.000000e-01
  131 +Reshape reshape_152 1 1 163 164 0=1 1=1 2=-1
  132 +BinaryOp mul_15 2 1 164 158 165 0=2
  133 +Convolution conv_49 1 1 165 166 0=160 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=107520
  134 +Split splitncnn_23 1 2 166 167 168
  135 +Convolution conv_50 1 1 168 169 0=960 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=153600
  136 +HardSwish hswish_102 1 1 169 170 0=1.666667e-01 1=5.000000e-01
  137 +ConvolutionDepthWise convdw_172 1 1 170 171 0=960 1=5 11=5 12=2 13=1 14=4 2=2 3=1 4=4 5=1 6=24000 7=960
  138 +HardSwish hswish_103 1 1 171 172 0=1.666667e-01 1=5.000000e-01
  139 +Split splitncnn_24 1 2 172 173 174
  140 +Pooling gap_6 1 1 174 175 0=1 4=1
  141 +Convolution convrelu_11 1 1 175 176 0=240 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=230400 9=1
  142 +Convolution conv_52 1 1 176 177 0=960 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=230400
  143 +HardSigmoid hsigmoid_85 1 1 177 178 0=1.666667e-01 1=5.000000e-01
  144 +Reshape reshape_153 1 1 178 179 0=1 1=1 2=-1
  145 +BinaryOp mul_16 2 1 179 173 180 0=2
  146 +Convolution conv_53 1 1 180 181 0=160 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=153600
  147 +BinaryOp add_17 2 1 181 167 182 0=0
  148 +Split splitncnn_25 1 2 182 183 184
  149 +Convolution conv_54 1 1 184 185 0=960 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=153600
  150 +HardSwish hswish_104 1 1 185 186 0=1.666667e-01 1=5.000000e-01
  151 +ConvolutionDepthWise convdw_173 1 1 186 187 0=960 1=5 11=5 12=2 13=1 14=4 2=2 3=1 4=4 5=1 6=24000 7=960
  152 +HardSwish hswish_105 1 1 187 188 0=1.666667e-01 1=5.000000e-01
  153 +Split splitncnn_26 1 2 188 189 190
  154 +Pooling gap_7 1 1 190 191 0=1 4=1
  155 +Convolution convrelu_12 1 1 191 192 0=240 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=230400 9=1
  156 +Convolution conv_56 1 1 192 193 0=960 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=230400
  157 +HardSigmoid hsigmoid_86 1 1 193 194 0=1.666667e-01 1=5.000000e-01
  158 +Reshape reshape_154 1 1 194 195 0=1 1=1 2=-1
  159 +BinaryOp mul_18 2 1 195 189 196 0=2
  160 +Convolution conv_57 1 1 196 197 0=160 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=153600
  161 +BinaryOp add_19 2 1 197 183 198 0=0
  162 +Convolution conv_58 1 1 198 199 0=960 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=153600
  163 +HardSwish hswish_106 1 1 199 200 0=1.666667e-01 1=5.000000e-01
  164 +Split splitncnn_27 1 2 200 201 202
  165 +Convolution convrelu_13 1 1 202 203 0=128 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=122880 9=1
  166 +Pooling gap_8 1 1 201 204 0=1 4=1
  167 +Convolution convsigmoid_21 1 1 204 205 0=128 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=0 6=122880 9=4
  168 +Reshape reshape_155 1 1 205 206 0=1 1=1 2=-1
  169 +BinaryOp mul_20 2 1 203 206 207 0=2
  170 +Pooling avgpool2d_9 1 1 12 208 0=1 1=2 11=2 12=2 13=0 2=2 3=0 5=0 6=0
  171 +Split splitncnn_28 1 3 208 209 210 211
  172 +Pooling avgpool2d_10 1 1 211 212 0=1 1=2 11=2 12=2 13=0 2=2 3=0 5=0 6=0
  173 +Split splitncnn_29 1 3 212 213 214 215
  174 +Pooling avgpool2d_11 1 1 215 216 0=1 1=2 11=2 12=2 13=0 2=2 3=0 5=0 6=0
  175 +Split splitncnn_30 1 2 216 217 218
  176 +Slice split_0 1 2 207 219 220 -23300=2,64,-233 1=0
  177 +Split splitncnn_31 1 2 220 221 222
  178 +Concat cat_0 2 1 221 28 223 0=0
  179 +Convolution convsigmoid_22 1 1 223 224 0=128 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=147456 9=4
  180 +Slice split_1 1 2 224 225 226 -23300=2,64,-233 1=0
  181 +Split splitncnn_32 1 2 226 227 228
  182 +BinaryOp mul_21 2 1 225 29 229 0=2
  183 +Concat cat_1 2 1 222 229 230 0=0
  184 +Convolution conv_62 1 1 230 231 0=64 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=73728
  185 +TanH tanh_139 1 1 231 232
  186 +BinaryOp mul_22 2 1 227 232 233 0=2
  187 +BinaryOp sub_23 1 1 228 234 0=7 1=1 2=1.000000e+00
  188 +BinaryOp mul_24 2 1 234 30 235 0=2
  189 +BinaryOp add_25 2 1 235 233 236 0=0
  190 +Split splitncnn_33 1 2 236 237 out10
  191 +Concat cat_2 2 1 219 237 239 0=0
  192 +Interp upsample_143 1 1 239 240 0=2 1=2.000000e+00 2=2.000000e+00 6=0
  193 +Crop slice3_0 2 1 240 218 241 19="0,0" 20="1h,1w" 21="1,2"
  194 +Concat cat_3 3 1 241 94 217 242 0=0
  195 +Convolution convrelu_14 1 1 242 243 0=80 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=123120 9=1
  196 +Slice split_2 1 2 243 244 245 -23300=2,40,-233 1=0
  197 +Split splitncnn_34 1 2 245 246 247
  198 +Concat cat_4 2 1 246 24 248 0=0
  199 +Convolution convsigmoid_23 1 1 248 249 0=80 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=57600 9=4
  200 +Slice split_3 1 2 249 250 251 -23300=2,40,-233 1=0
  201 +Split splitncnn_35 1 2 251 252 253
  202 +BinaryOp mul_26 2 1 250 25 254 0=2
  203 +Concat cat_5 2 1 247 254 255 0=0
  204 +Convolution conv_65 1 1 255 256 0=40 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=28800
  205 +TanH tanh_140 1 1 256 257
  206 +BinaryOp mul_27 2 1 252 257 258 0=2
  207 +BinaryOp sub_28 1 1 253 259 0=7 1=1 2=1.000000e+00
  208 +BinaryOp mul_29 2 1 259 26 260 0=2
  209 +BinaryOp add_30 2 1 260 258 261 0=0
  210 +Split splitncnn_36 1 2 261 262 out9
  211 +Concat cat_6 2 1 244 262 264 0=0
  212 +Interp upsample_144 1 1 264 265 0=2 1=2.000000e+00 2=2.000000e+00 6=0
  213 +Crop slice3_1 2 1 265 214 266 19="0,0" 20="1h,1w" 21="1,2"
  214 +Concat cat_7 3 1 266 53 213 267 0=0
  215 +Convolution convrelu_15 1 1 267 268 0=40 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=38520 9=1
  216 +Slice split_4 1 2 268 269 270 -23300=2,20,-233 1=0
  217 +Split splitncnn_37 1 2 270 271 272
  218 +Concat cat_8 2 1 271 20 273 0=0
  219 +Convolution convsigmoid_24 1 1 273 274 0=40 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=14400 9=4
  220 +Slice split_5 1 2 274 275 276 -23300=2,20,-233 1=0
  221 +Split splitncnn_38 1 2 276 277 278
  222 +BinaryOp mul_31 2 1 275 21 279 0=2
  223 +Concat cat_9 2 1 272 279 280 0=0
  224 +Convolution conv_68 1 1 280 281 0=20 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=7200
  225 +TanH tanh_141 1 1 281 282
  226 +BinaryOp mul_32 2 1 277 282 283 0=2
  227 +BinaryOp sub_33 1 1 278 284 0=7 1=1 2=1.000000e+00
  228 +BinaryOp mul_34 2 1 284 22 285 0=2
  229 +BinaryOp add_35 2 1 285 283 286 0=0
  230 +Split splitncnn_39 1 2 286 287 out8
  231 +Concat cat_10 2 1 269 287 289 0=0
  232 +Interp upsample_145 1 1 289 290 0=2 1=2.000000e+00 2=2.000000e+00 6=0
  233 +Crop slice3_2 2 1 290 210 291 19="0,0" 20="1h,1w" 21="1,2"
  234 +Concat cat_11 3 1 291 42 209 292 0=0
  235 +Convolution convrelu_16 1 1 292 293 0=32 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=16992 9=1
  236 +Slice split_6 1 2 293 294 295 -23300=2,16,-233 1=0
  237 +Split splitncnn_40 1 2 295 296 297
  238 +Concat cat_12 2 1 296 16 298 0=0
  239 +Convolution convsigmoid_25 1 1 298 299 0=32 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=9216 9=4
  240 +Slice split_7 1 2 299 300 301 -23300=2,16,-233 1=0
  241 +Split splitncnn_41 1 2 301 302 303
  242 +BinaryOp mul_36 2 1 300 17 304 0=2
  243 +Concat cat_13 2 1 297 304 305 0=0
  244 +Convolution conv_71 1 1 305 306 0=16 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=4608
  245 +TanH tanh_142 1 1 306 307
  246 +BinaryOp mul_37 2 1 302 307 308 0=2
  247 +BinaryOp sub_38 1 1 303 309 0=7 1=1 2=1.000000e+00
  248 +BinaryOp mul_39 2 1 309 18 310 0=2
  249 +BinaryOp add_40 2 1 310 308 311 0=0
  250 +Split splitncnn_42 1 2 311 312 out7
  251 +Concat cat_14 2 1 294 312 314 0=0
  252 +Interp upsample_146 1 1 314 315 0=2 1=2.000000e+00 2=2.000000e+00 6=0
  253 +Crop slice3_3 2 1 315 11 316 19="0,0" 20="1h,1w" 21="1,2"
  254 +Concat cat_15 2 1 316 8 317 0=0
  255 +Convolution convrelu_17 1 1 317 318 0=16 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=5040 9=1
  256 +Convolution convrelu_18 1 1 318 319 0=16 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=2304 9=1
  257 +Split splitncnn_43 1 3 319 320 321 322
  258 +Convolution conv_74 1 1 322 323 0=4 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=64
  259 +Slice split_8 1 2 323 324 325 -23300=2,3,1 1=0
  260 +Split splitncnn_45 1 2 325 326 out1
  261 +Split splitncnn_44 1 2 324 328 329
  262 +BinaryOp add_41 2 1 329 10 out0 0=0
  263 +Reduction mean_157 1 1 6 331 0=3 1=0 -23303=1,0 4=1 5=1
  264 +Concat cat_16 2 1 1 331 332 0=0
  265 +Split splitncnn_46 1 4 332 333 334 335 336
  266 +Reduction mean_158 1 1 13 337 0=3 1=0 -23303=1,0 4=1 5=1
  267 +Concat cat_17 2 1 9 337 338 0=0
  268 +Split splitncnn_47 1 5 338 339 340 341 342 343
  269 +Concat cat_18 2 1 328 326 344 0=0
  270 +Split splitncnn_48 1 3 344 345 346 347
  271 +ConvolutionDepthWise convdw_174 1 1 343 348 0=4 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=0 6=36 7=4
  272 +Split splitncnn_49 1 4 348 349 350 351 352
  273 +ConvolutionDepthWise convdw_175 1 1 347 353 0=4 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=0 6=36 7=4
  274 +Split splitncnn_50 1 2 353 354 355
  275 +BinaryOp mul_42 2 1 339 345 356 0=2
  276 +Split splitncnn_51 1 2 356 357 358
  277 +ConvolutionDepthWise convdw_176 1 1 358 359 0=4 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=0 6=36 7=4
  278 +BinaryOp mul_43 2 1 349 354 360 0=2
  279 +BinaryOp sub_44 2 1 359 360 361 0=1
  280 +BinaryOp mul_45 2 1 340 341 362 0=2
  281 +Split splitncnn_52 1 2 362 363 364
  282 +ConvolutionDepthWise convdw_177 1 1 364 365 0=4 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=0 6=36 7=4
  283 +BinaryOp mul_46 2 1 350 351 366 0=2
  284 +BinaryOp sub_47 2 1 365 366 367 0=1
  285 +Concat cat_19 3 1 361 367 320 368 0=0
  286 +Convolution convrelu_19 1 1 368 369 0=16 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=384 9=1
  287 +Convolution convrelu_20 1 1 369 370 0=16 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=256 9=1
  288 +Convolution conv_77 1 1 370 371 0=4 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=64
  289 +Split splitncnn_53 1 2 371 372 373
  290 +BinaryOp mul_48 2 1 373 352 374 0=2
  291 +BinaryOp sub_49 2 1 355 374 375 0=1
  292 +Interp F.upsample_89 2 1 372 4 376 0=2 5=1 6=0 9="1w,1h"
  293 +Interp F.upsample_90 2 1 375 5 377 0=2 5=1 6=0 9="1w,1h"
  294 +BinaryOp mul_50 2 1 376 333 378 0=2
  295 +BinaryOp add_51 2 1 378 377 379 0=0
  296 +Slice split_9 1 2 379 380 out3 -23300=2,3,1 1=0
  297 +BinaryOp add_52 2 1 380 2 out2 0=0
  298 +ConvolutionDepthWise convdw_178 1 1 342 383 0=4 1=3 11=1 12=1 13=1 14=0 2=1 3=1 4=1 5=0 6=12 7=4
  299 +ConvolutionDepthWise convdw_179 1 1 383 384 0=4 1=1 11=3 12=1 13=1 14=1 2=1 3=1 4=0 5=0 6=12 7=4
  300 +Split splitncnn_54 1 4 384 385 386 387 388
  301 +ConvolutionDepthWise convdw_180 1 1 346 389 0=4 1=3 11=1 12=1 13=1 14=0 2=1 3=1 4=1 5=0 6=12 7=4
  302 +ConvolutionDepthWise convdw_181 1 1 389 390 0=4 1=1 11=3 12=1 13=1 14=1 2=1 3=1 4=0 5=0 6=12 7=4
  303 +Split splitncnn_55 1 2 390 391 392
  304 +ConvolutionDepthWise convdw_182 1 1 357 393 0=4 1=3 11=1 12=1 13=1 14=0 2=1 3=1 4=1 5=0 6=12 7=4
  305 +ConvolutionDepthWise convdw_183 1 1 393 394 0=4 1=1 11=3 12=1 13=1 14=1 2=1 3=1 4=0 5=0 6=12 7=4
  306 +ConvolutionDepthWise convdw_184 1 1 363 395 0=4 1=3 11=1 12=1 13=1 14=0 2=1 3=1 4=1 5=0 6=12 7=4
  307 +ConvolutionDepthWise convdw_185 1 1 395 396 0=4 1=1 11=3 12=1 13=1 14=1 2=1 3=1 4=0 5=0 6=12 7=4
  308 +BinaryOp mul_53 2 1 385 386 397 0=2
  309 +BinaryOp sub_54 2 1 396 397 398 0=1
  310 +BinaryOp add_55 1 1 398 399 0=0 1=1 2=1.000000e-05
  311 +BinaryOp mul_56 2 1 387 391 400 0=2
  312 +BinaryOp sub_57 2 1 394 400 401 0=1
  313 +BinaryOp div_58 2 1 401 399 402 0=3 31=1
  314 +Split splitncnn_56 1 2 402 403 404
  315 +BinaryOp mul_59 2 1 404 388 405 0=2
  316 +BinaryOp sub_60 2 1 392 405 406 0=1
  317 +Interp F.upsample_91 2 1 403 335 407 0=2 5=1 6=0 9="1w,1h"
  318 +Interp F.upsample_92 2 1 406 336 408 0=2 5=1 6=0 9="1w,1h"
  319 +BinaryOp mul_61 2 1 407 334 409 0=2
  320 +BinaryOp add_62 2 1 409 408 410 0=0
  321 +Slice split_10 1 2 410 411 out5 -23300=2,3,1 1=0
  322 +BinaryOp add_63 2 1 411 3 out4 0=0
  323 +Convolution conv_78 1 1 321 out6 0=1 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=16
  1 +7767517
  2 +275 367
  3 +Input in0 0 1 in0
  4 +Split splitncnn_0 1 6 in0 1 2 3 4 5 6
  5 +Input in1 0 1 in1
  6 +Split splitncnn_1 1 7 in1 8 9 10 11 12 13 14
  7 +Input in2 0 1 in2
  8 +Split splitncnn_2 1 3 in2 16 17 18
  9 +Input in3 0 1 in3
  10 +Split splitncnn_3 1 3 in3 20 21 22
  11 +Input in4 0 1 in4
  12 +Split splitncnn_4 1 3 in4 24 25 26
  13 +Input in5 0 1 in5
  14 +Split splitncnn_5 1 3 in5 28 29 30
  15 +Convolution convrelu_0 1 1 13 31 0=64 1=7 11=7 12=1 13=2 14=3 2=1 3=2 4=3 5=1 6=9408 9=1
  16 +Split splitncnn_6 1 2 31 32 33
  17 +Pooling maxpool2d_77 1 1 33 34 0=0 1=3 11=3 12=2 13=1 2=2 3=1 5=1
  18 +Split splitncnn_7 1 2 34 35 36
  19 +Convolution convrelu_1 1 1 36 37 0=64 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=4096 9=1
  20 +Convolution convrelu_2 1 1 37 38 0=64 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=36864 9=1
  21 +Convolution conv_7 1 1 38 39 0=256 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=16384
  22 +Convolution conv_8 1 1 35 40 0=256 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=16384
  23 +BinaryOp add_0 2 1 39 40 41 0=0
  24 +ReLU relu_81 1 1 41 42
  25 +Split splitncnn_8 1 2 42 43 44
  26 +Convolution convrelu_3 1 1 44 45 0=64 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=16384 9=1
  27 +Convolution convrelu_4 1 1 45 46 0=64 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=36864 9=1
  28 +Convolution conv_11 1 1 46 47 0=256 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=16384
  29 +BinaryOp add_1 2 1 47 43 48 0=0
  30 +ReLU relu_84 1 1 48 49
  31 +Split splitncnn_9 1 2 49 50 51
  32 +Convolution convrelu_5 1 1 51 52 0=64 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=16384 9=1
  33 +Convolution convrelu_6 1 1 52 53 0=64 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=36864 9=1
  34 +Convolution conv_14 1 1 53 54 0=256 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=16384
  35 +BinaryOp add_2 2 1 54 50 55 0=0
  36 +ReLU relu_87 1 1 55 56
  37 +Split splitncnn_10 1 3 56 57 58 59
  38 +Convolution convrelu_7 1 1 59 60 0=128 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=32768 9=1
  39 +Convolution convrelu_8 1 1 60 61 0=128 1=3 11=3 12=1 13=2 14=1 2=1 3=2 4=1 5=1 6=147456 9=1
  40 +Convolution conv_17 1 1 61 62 0=512 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=65536
  41 +Convolution conv_18 1 1 58 63 0=512 1=1 11=1 12=1 13=2 14=0 2=1 3=2 4=0 5=1 6=131072
  42 +BinaryOp add_3 2 1 62 63 64 0=0
  43 +ReLU relu_90 1 1 64 65
  44 +Split splitncnn_11 1 2 65 66 67
  45 +Convolution convrelu_9 1 1 67 68 0=128 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=65536 9=1
  46 +Convolution convrelu_10 1 1 68 69 0=128 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=147456 9=1
  47 +Convolution conv_21 1 1 69 70 0=512 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=65536
  48 +BinaryOp add_4 2 1 70 66 71 0=0
  49 +ReLU relu_93 1 1 71 72
  50 +Split splitncnn_12 1 2 72 73 74
  51 +Convolution convrelu_11 1 1 74 75 0=128 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=65536 9=1
  52 +Convolution convrelu_12 1 1 75 76 0=128 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=147456 9=1
  53 +Convolution conv_24 1 1 76 77 0=512 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=65536
  54 +BinaryOp add_5 2 1 77 73 78 0=0
  55 +ReLU relu_96 1 1 78 79
  56 +Split splitncnn_13 1 2 79 80 81
  57 +Convolution convrelu_13 1 1 81 82 0=128 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=65536 9=1
  58 +Convolution convrelu_14 1 1 82 83 0=128 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=147456 9=1
  59 +Convolution conv_27 1 1 83 84 0=512 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=65536
  60 +BinaryOp add_6 2 1 84 80 85 0=0
  61 +ReLU relu_99 1 1 85 86
  62 +Split splitncnn_14 1 3 86 87 88 89
  63 +Convolution convrelu_15 1 1 89 90 0=256 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=131072 9=1
  64 +Convolution convrelu_16 1 1 90 91 0=256 1=3 11=3 12=1 13=2 14=1 2=1 3=2 4=1 5=1 6=589824 9=1
  65 +Convolution conv_30 1 1 91 92 0=1024 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=262144
  66 +Convolution conv_31 1 1 88 93 0=1024 1=1 11=1 12=1 13=2 14=0 2=1 3=2 4=0 5=1 6=524288
  67 +BinaryOp add_7 2 1 92 93 94 0=0
  68 +ReLU relu_102 1 1 94 95
  69 +Split splitncnn_15 1 2 95 96 97
  70 +Convolution convrelu_17 1 1 97 98 0=256 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=262144 9=1
  71 +Convolution convrelu_18 1 1 98 99 0=256 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=589824 9=1
  72 +Convolution conv_34 1 1 99 100 0=1024 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=262144
  73 +BinaryOp add_8 2 1 100 96 101 0=0
  74 +ReLU relu_105 1 1 101 102
  75 +Split splitncnn_16 1 2 102 103 104
  76 +Convolution convrelu_19 1 1 104 105 0=256 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=262144 9=1
  77 +Convolution convrelu_20 1 1 105 106 0=256 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=589824 9=1
  78 +Convolution conv_37 1 1 106 107 0=1024 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=262144
  79 +BinaryOp add_9 2 1 107 103 108 0=0
  80 +ReLU relu_108 1 1 108 109
  81 +Split splitncnn_17 1 2 109 110 111
  82 +Convolution convrelu_21 1 1 111 112 0=256 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=262144 9=1
  83 +Convolution convrelu_22 1 1 112 113 0=256 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=589824 9=1
  84 +Convolution conv_40 1 1 113 114 0=1024 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=262144
  85 +BinaryOp add_10 2 1 114 110 115 0=0
  86 +ReLU relu_111 1 1 115 116
  87 +Split splitncnn_18 1 2 116 117 118
  88 +Convolution convrelu_23 1 1 118 119 0=256 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=262144 9=1
  89 +Convolution convrelu_24 1 1 119 120 0=256 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=589824 9=1
  90 +Convolution conv_43 1 1 120 121 0=1024 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=262144
  91 +BinaryOp add_11 2 1 121 117 122 0=0
  92 +ReLU relu_114 1 1 122 123
  93 +Split splitncnn_19 1 2 123 124 125
  94 +Convolution convrelu_25 1 1 125 126 0=256 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=262144 9=1
  95 +Convolution convrelu_26 1 1 126 127 0=256 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=589824 9=1
  96 +Convolution conv_46 1 1 127 128 0=1024 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=262144
  97 +BinaryOp add_12 2 1 128 124 129 0=0
  98 +ReLU relu_117 1 1 129 130
  99 +Split splitncnn_20 1 2 130 131 132
  100 +Convolution convrelu_27 1 1 132 133 0=512 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=524288 9=1
  101 +Convolution convrelu_28 1 1 133 134 0=512 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=2359296 9=1
  102 +Convolution conv_49 1 1 134 135 0=2048 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=1048576
  103 +Convolution conv_50 1 1 131 136 0=2048 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=2097152
  104 +BinaryOp add_13 2 1 135 136 137 0=0
  105 +ReLU relu_120 1 1 137 138
  106 +Split splitncnn_21 1 2 138 139 140
  107 +Convolution convrelu_29 1 1 140 141 0=512 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=1048576 9=1
  108 +Convolution convrelu_30 1 1 141 142 0=512 1=3 11=3 12=2 13=1 14=2 2=2 3=1 4=2 5=1 6=2359296 9=1
  109 +Convolution conv_53 1 1 142 143 0=2048 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=1048576
  110 +BinaryOp add_14 2 1 143 139 144 0=0
  111 +ReLU relu_123 1 1 144 145
  112 +Split splitncnn_22 1 2 145 146 147
  113 +Convolution convrelu_31 1 1 147 148 0=512 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=1048576 9=1
  114 +Convolution convrelu_32 1 1 148 149 0=512 1=3 11=3 12=2 13=1 14=2 2=2 3=1 4=2 5=1 6=2359296 9=1
  115 +Convolution conv_56 1 1 149 150 0=2048 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=1048576
  116 +BinaryOp add_15 2 1 150 146 151 0=0
  117 +ReLU relu_126 1 1 151 152
  118 +Split splitncnn_23 1 2 152 153 154
  119 +Convolution convrelu_33 1 1 154 155 0=256 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=524288 9=1
  120 +Pooling gap_0 1 1 153 156 0=1 4=1
  121 +Convolution convsigmoid_41 1 1 156 157 0=256 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=0 6=524288 9=4
  122 +Reshape reshape_148 1 1 157 158 0=1 1=1 2=-1
  123 +BinaryOp mul_16 2 1 155 158 159 0=2
  124 +Pooling avgpool2d_1 1 1 12 160 0=1 1=2 11=2 12=2 13=0 2=2 3=0 5=0 6=0
  125 +Split splitncnn_24 1 3 160 161 162 163
  126 +Pooling avgpool2d_2 1 1 163 164 0=1 1=2 11=2 12=2 13=0 2=2 3=0 5=0 6=0
  127 +Split splitncnn_25 1 3 164 165 166 167
  128 +Pooling avgpool2d_3 1 1 167 168 0=1 1=2 11=2 12=2 13=0 2=2 3=0 5=0 6=0
  129 +Split splitncnn_26 1 2 168 169 170
  130 +Slice split_0 1 2 159 171 172 -23300=2,128,-233 1=0
  131 +Split splitncnn_27 1 2 172 173 174
  132 +Concat cat_0 2 1 173 28 175 0=0
  133 +Convolution convsigmoid_42 1 1 175 176 0=256 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=589824 9=4
  134 +Slice split_1 1 2 176 177 178 -23300=2,128,-233 1=0
  135 +Split splitncnn_28 1 2 178 179 180
  136 +BinaryOp mul_17 2 1 177 29 181 0=2
  137 +Concat cat_1 2 1 174 181 182 0=0
  138 +Convolution conv_60 1 1 182 183 0=128 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=294912
  139 +TanH tanh_140 1 1 183 184
  140 +BinaryOp mul_18 2 1 179 184 185 0=2
  141 +BinaryOp sub_19 1 1 180 186 0=7 1=1 2=1.000000e+00
  142 +BinaryOp mul_20 2 1 186 30 187 0=2
  143 +BinaryOp add_21 2 1 187 185 188 0=0
  144 +Split splitncnn_29 1 2 188 189 out10
  145 +Concat cat_2 2 1 171 189 191 0=0
  146 +Interp upsample_144 1 1 191 192 0=2 1=2.000000e+00 2=2.000000e+00 6=0
  147 +Crop slice3_0 2 1 192 170 193 19="0,0" 20="1h,1w" 21="1,2"
  148 +Concat cat_3 3 1 193 87 169 194 0=0
  149 +Convolution convrelu_34 1 1 194 195 0=128 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=888192 9=1
  150 +Slice split_2 1 2 195 196 197 -23300=2,64,-233 1=0
  151 +Split splitncnn_30 1 2 197 198 199
  152 +Concat cat_4 2 1 198 24 200 0=0
  153 +Convolution convsigmoid_43 1 1 200 201 0=128 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=147456 9=4
  154 +Slice split_3 1 2 201 202 203 -23300=2,64,-233 1=0
  155 +Split splitncnn_31 1 2 203 204 205
  156 +BinaryOp mul_22 2 1 202 25 206 0=2
  157 +Concat cat_5 2 1 199 206 207 0=0
  158 +Convolution conv_63 1 1 207 208 0=64 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=73728
  159 +TanH tanh_141 1 1 208 209
  160 +BinaryOp mul_23 2 1 204 209 210 0=2
  161 +BinaryOp sub_24 1 1 205 211 0=7 1=1 2=1.000000e+00
  162 +BinaryOp mul_25 2 1 211 26 212 0=2
  163 +BinaryOp add_26 2 1 212 210 213 0=0
  164 +Split splitncnn_32 1 2 213 214 out9
  165 +Concat cat_6 2 1 196 214 216 0=0
  166 +Interp upsample_145 1 1 216 217 0=2 1=2.000000e+00 2=2.000000e+00 6=0
  167 +Crop slice3_1 2 1 217 166 218 19="0,0" 20="1h,1w" 21="1,2"
  168 +Concat cat_7 3 1 218 57 165 219 0=0
  169 +Convolution convrelu_35 1 1 219 220 0=64 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=222912 9=1
  170 +Slice split_4 1 2 220 221 222 -23300=2,32,-233 1=0
  171 +Split splitncnn_33 1 2 222 223 224
  172 +Concat cat_8 2 1 223 20 225 0=0
  173 +Convolution convsigmoid_44 1 1 225 226 0=64 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=36864 9=4
  174 +Slice split_5 1 2 226 227 228 -23300=2,32,-233 1=0
  175 +Split splitncnn_34 1 2 228 229 230
  176 +BinaryOp mul_27 2 1 227 21 231 0=2
  177 +Concat cat_9 2 1 224 231 232 0=0
  178 +Convolution conv_66 1 1 232 233 0=32 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=18432
  179 +TanH tanh_142 1 1 233 234
  180 +BinaryOp mul_28 2 1 229 234 235 0=2
  181 +BinaryOp sub_29 1 1 230 236 0=7 1=1 2=1.000000e+00
  182 +BinaryOp mul_30 2 1 236 22 237 0=2
  183 +BinaryOp add_31 2 1 237 235 238 0=0
  184 +Split splitncnn_35 1 2 238 239 out8
  185 +Concat cat_10 2 1 221 239 241 0=0
  186 +Interp upsample_146 1 1 241 242 0=2 1=2.000000e+00 2=2.000000e+00 6=0
  187 +Crop slice3_2 2 1 242 162 243 19="0,0" 20="1h,1w" 21="1,2"
  188 +Concat cat_11 3 1 243 32 161 244 0=0
  189 +Convolution convrelu_36 1 1 244 245 0=32 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=37728 9=1
  190 +Slice split_6 1 2 245 246 247 -23300=2,16,-233 1=0
  191 +Split splitncnn_36 1 2 247 248 249
  192 +Concat cat_12 2 1 248 16 250 0=0
  193 +Convolution convsigmoid_45 1 1 250 251 0=32 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=9216 9=4
  194 +Slice split_7 1 2 251 252 253 -23300=2,16,-233 1=0
  195 +Split splitncnn_37 1 2 253 254 255
  196 +BinaryOp mul_32 2 1 252 17 256 0=2
  197 +Concat cat_13 2 1 249 256 257 0=0
  198 +Convolution conv_69 1 1 257 258 0=16 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=4608
  199 +TanH tanh_143 1 1 258 259
  200 +BinaryOp mul_33 2 1 254 259 260 0=2
  201 +BinaryOp sub_34 1 1 255 261 0=7 1=1 2=1.000000e+00
  202 +BinaryOp mul_35 2 1 261 18 262 0=2
  203 +BinaryOp add_36 2 1 262 260 263 0=0
  204 +Split splitncnn_38 1 2 263 264 out7
  205 +Concat cat_14 2 1 246 264 266 0=0
  206 +Interp upsample_147 1 1 266 267 0=2 1=2.000000e+00 2=2.000000e+00 6=0
  207 +Crop slice3_3 2 1 267 11 268 19="0,0" 20="1h,1w" 21="1,2"
  208 +Concat cat_15 2 1 268 8 269 0=0
  209 +Convolution convrelu_37 1 1 269 270 0=16 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=5040 9=1
  210 +Convolution convrelu_38 1 1 270 271 0=16 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=2304 9=1
  211 +Split splitncnn_39 1 3 271 272 273 274
  212 +Convolution conv_72 1 1 274 275 0=4 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=64
  213 +Slice split_8 1 2 275 276 277 -23300=2,3,1 1=0
  214 +Split splitncnn_41 1 2 277 278 out1
  215 +Split splitncnn_40 1 2 276 280 281
  216 +BinaryOp add_37 2 1 281 10 out0 0=0
  217 +Reduction mean_149 1 1 6 283 0=3 1=0 -23303=1,0 4=1 5=1
  218 +Concat cat_16 2 1 1 283 284 0=0
  219 +Split splitncnn_42 1 4 284 285 286 287 288
  220 +Reduction mean_150 1 1 14 289 0=3 1=0 -23303=1,0 4=1 5=1
  221 +Concat cat_17 2 1 9 289 290 0=0
  222 +Split splitncnn_43 1 5 290 291 292 293 294 295
  223 +Concat cat_18 2 1 280 278 296 0=0
  224 +Split splitncnn_44 1 3 296 297 298 299
  225 +ConvolutionDepthWise convdw_151 1 1 295 300 0=4 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=0 6=36 7=4
  226 +Split splitncnn_45 1 4 300 301 302 303 304
  227 +ConvolutionDepthWise convdw_152 1 1 299 305 0=4 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=0 6=36 7=4
  228 +Split splitncnn_46 1 2 305 306 307
  229 +BinaryOp mul_38 2 1 291 297 308 0=2
  230 +Split splitncnn_47 1 2 308 309 310
  231 +ConvolutionDepthWise convdw_153 1 1 310 311 0=4 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=0 6=36 7=4
  232 +BinaryOp mul_39 2 1 301 306 312 0=2
  233 +BinaryOp sub_40 2 1 311 312 313 0=1
  234 +BinaryOp mul_41 2 1 292 293 314 0=2
  235 +Split splitncnn_48 1 2 314 315 316
  236 +ConvolutionDepthWise convdw_154 1 1 316 317 0=4 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=0 6=36 7=4
  237 +BinaryOp mul_42 2 1 302 303 318 0=2
  238 +BinaryOp sub_43 2 1 317 318 319 0=1
  239 +Concat cat_19 3 1 313 319 272 320 0=0
  240 +Convolution convrelu_39 1 1 320 321 0=16 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=384 9=1
  241 +Convolution convrelu_40 1 1 321 322 0=16 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=256 9=1
  242 +Convolution conv_75 1 1 322 323 0=4 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=64
  243 +Split splitncnn_49 1 2 323 324 325
  244 +BinaryOp mul_44 2 1 325 304 326 0=2
  245 +BinaryOp sub_45 2 1 307 326 327 0=1
  246 +Interp F.upsample_84 2 1 324 4 328 0=2 5=1 6=0 9="1w,1h"
  247 +Interp F.upsample_85 2 1 327 5 329 0=2 5=1 6=0 9="1w,1h"
  248 +BinaryOp mul_46 2 1 328 285 330 0=2
  249 +BinaryOp add_47 2 1 330 329 331 0=0
  250 +Slice split_9 1 2 331 332 out3 -23300=2,3,1 1=0
  251 +BinaryOp add_48 2 1 332 2 out2 0=0
  252 +ConvolutionDepthWise convdw_155 1 1 294 335 0=4 1=3 11=1 12=1 13=1 14=0 2=1 3=1 4=1 5=0 6=12 7=4
  253 +ConvolutionDepthWise convdw_156 1 1 335 336 0=4 1=1 11=3 12=1 13=1 14=1 2=1 3=1 4=0 5=0 6=12 7=4
  254 +Split splitncnn_50 1 4 336 337 338 339 340
  255 +ConvolutionDepthWise convdw_157 1 1 298 341 0=4 1=3 11=1 12=1 13=1 14=0 2=1 3=1 4=1 5=0 6=12 7=4
  256 +ConvolutionDepthWise convdw_158 1 1 341 342 0=4 1=1 11=3 12=1 13=1 14=1 2=1 3=1 4=0 5=0 6=12 7=4
  257 +Split splitncnn_51 1 2 342 343 344
  258 +ConvolutionDepthWise convdw_159 1 1 309 345 0=4 1=3 11=1 12=1 13=1 14=0 2=1 3=1 4=1 5=0 6=12 7=4
  259 +ConvolutionDepthWise convdw_160 1 1 345 346 0=4 1=1 11=3 12=1 13=1 14=1 2=1 3=1 4=0 5=0 6=12 7=4
  260 +ConvolutionDepthWise convdw_161 1 1 315 347 0=4 1=3 11=1 12=1 13=1 14=0 2=1 3=1 4=1 5=0 6=12 7=4
  261 +ConvolutionDepthWise convdw_162 1 1 347 348 0=4 1=1 11=3 12=1 13=1 14=1 2=1 3=1 4=0 5=0 6=12 7=4
  262 +BinaryOp mul_49 2 1 337 338 349 0=2
  263 +BinaryOp sub_50 2 1 348 349 350 0=1
  264 +BinaryOp add_51 1 1 350 351 0=0 1=1 2=1.000000e-05
  265 +BinaryOp mul_52 2 1 339 343 352 0=2
  266 +BinaryOp sub_53 2 1 346 352 353 0=1
  267 +BinaryOp div_54 2 1 353 351 354 0=3 31=1
  268 +Split splitncnn_52 1 2 354 355 356
  269 +BinaryOp mul_55 2 1 356 340 357 0=2
  270 +BinaryOp sub_56 2 1 344 357 358 0=1
  271 +Interp F.upsample_86 2 1 355 287 359 0=2 5=1 6=0 9="1w,1h"
  272 +Interp F.upsample_87 2 1 358 288 360 0=2 5=1 6=0 9="1w,1h"
  273 +BinaryOp mul_57 2 1 359 286 361 0=2
  274 +BinaryOp add_58 2 1 361 360 362 0=0
  275 +Slice split_10 1 2 362 363 out5 -23300=2,3,1 1=0
  276 +BinaryOp add_59 2 1 363 3 out4 0=0
  277 +Convolution conv_76 1 1 273 out6 0=1 1=1 11=1 12=1 13=1 14=0 2=1 3=1 4=0 5=1 6=16
  1 +cmake_minimum_required(VERSION 3.10)
  2 +
  3 +set(OpenCV_DIR ${CMAKE_SOURCE_DIR}/opencv-mobile-4.11.0-android/sdk/native/jni)
  4 +find_package(OpenCV REQUIRED core imgproc)
  5 +
  6 +set(ncnn_DIR ${CMAKE_SOURCE_DIR}/ncnn-20250503-android-vulkan/${ANDROID_ABI}/lib/cmake/ncnn)
  7 +find_package(ncnn REQUIRED)
  8 +
  9 +add_library(rvmncnn SHARED rvmncnn.cpp rvm.cpp ndkcamera.cpp)
  10 +
  11 +target_link_libraries(rvmncnn ncnn ${OpenCV_LIBS} camera2ndk mediandk)
  1 +# 背景图片替换功能使用说明
  2 +
  3 +## 功能概述
  4 +此修改允许将Robust Video Matting (RVM)的背景从单一颜色替换为指定的图片。
  5 +
  6 +## 使用方式
  7 +
  8 +### 1. Java/Kotlin层调用
  9 +```java
  10 +// 设置背景图片
  11 +Bitmap backgroundBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.background);
  12 +RVMNcnn.setBackgroundImage(backgroundBitmap);
  13 +
  14 +// 清除背景图片,恢复默认颜色
  15 +RVMNcnn.setBackgroundImage(null);
  16 +```
  17 +
  18 +### 2. JNI接口
  19 +新增JNI函数:
  20 +- `Java_org_example_project_RVMNcnn_setBackgroundImage(JNIEnv* env, jobject thiz, jobject bitmap)`
  21 +
  22 +### 3. C++层API
  23 +新增RVM类方法:
  24 +- `void set_background_image(const cv::Mat& background)` - 设置背景图片
  25 +- `void clear_background_image()` - 清除背景图片,使用默认颜色
  26 +
  27 +## 技术细节
  28 +
  29 +### 背景图片处理
  30 +- 支持RGBA_8888和RGB_565格式的Bitmap
  31 +- 自动转换为OpenCV BGR格式
  32 +- 支持任意尺寸的图片,会自动缩放适配
  33 +- 如果未设置背景图片,使用默认颜色RGB(120, 255, 155)
  34 +
  35 +### 混合算法
  36 +使用alpha混合公式:
  37 +```
  38 +result = foreground * alpha + background * (1 - alpha)
  39 +```
  40 +
  41 +### 性能考虑
  42 +- 背景图片会在设置时进行一次格式转换和缩放
  43 +- 每帧渲染时进行实时像素采样
  44 +- 建议使用与输入视频分辨率相近的背景图片以获得最佳性能
  45 +
  46 +## 注意事项
  47 +1. 背景图片应该是RGB或RGBA格式的8位图像
  48 +2. 图片尺寸不需要与输入视频完全一致,会自动适配
  49 +3. 设置null可以恢复默认的背景颜色
  50 +4. 背景图片会在RVM实例销毁时自动释放
  1 +//
  2 +// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
  3 +// Copyright (C) 2013 LunarG, Inc.
  4 +//
  5 +// All rights reserved.
  6 +//
  7 +// Redistribution and use in source and binary forms, with or without
  8 +// modification, are permitted provided that the following conditions
  9 +// are met:
  10 +//
  11 +// Redistributions of source code must retain the above copyright
  12 +// notice, this list of conditions and the following disclaimer.
  13 +//
  14 +// Redistributions in binary form must reproduce the above
  15 +// copyright notice, this list of conditions and the following
  16 +// disclaimer in the documentation and/or other materials provided
  17 +// with the distribution.
  18 +//
  19 +// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
  20 +// contributors may be used to endorse or promote products derived
  21 +// from this software without specific prior written permission.
  22 +//
  23 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  26 +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  27 +// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  28 +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  29 +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  30 +// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31 +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32 +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  33 +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34 +// POSSIBILITY OF SUCH DAMAGE.
  35 +//
  36 +
  37 +#ifndef _RESOURCE_LIMITS_INCLUDED_
  38 +#define _RESOURCE_LIMITS_INCLUDED_
  39 +
  40 +struct TLimits {
  41 + bool nonInductiveForLoops;
  42 + bool whileLoops;
  43 + bool doWhileLoops;
  44 + bool generalUniformIndexing;
  45 + bool generalAttributeMatrixVectorIndexing;
  46 + bool generalVaryingIndexing;
  47 + bool generalSamplerIndexing;
  48 + bool generalVariableIndexing;
  49 + bool generalConstantMatrixVectorIndexing;
  50 +};
  51 +
  52 +struct TBuiltInResource {
  53 + int maxLights;
  54 + int maxClipPlanes;
  55 + int maxTextureUnits;
  56 + int maxTextureCoords;
  57 + int maxVertexAttribs;
  58 + int maxVertexUniformComponents;
  59 + int maxVaryingFloats;
  60 + int maxVertexTextureImageUnits;
  61 + int maxCombinedTextureImageUnits;
  62 + int maxTextureImageUnits;
  63 + int maxFragmentUniformComponents;
  64 + int maxDrawBuffers;
  65 + int maxVertexUniformVectors;
  66 + int maxVaryingVectors;
  67 + int maxFragmentUniformVectors;
  68 + int maxVertexOutputVectors;
  69 + int maxFragmentInputVectors;
  70 + int minProgramTexelOffset;
  71 + int maxProgramTexelOffset;
  72 + int maxClipDistances;
  73 + int maxComputeWorkGroupCountX;
  74 + int maxComputeWorkGroupCountY;
  75 + int maxComputeWorkGroupCountZ;
  76 + int maxComputeWorkGroupSizeX;
  77 + int maxComputeWorkGroupSizeY;
  78 + int maxComputeWorkGroupSizeZ;
  79 + int maxComputeUniformComponents;
  80 + int maxComputeTextureImageUnits;
  81 + int maxComputeImageUniforms;
  82 + int maxComputeAtomicCounters;
  83 + int maxComputeAtomicCounterBuffers;
  84 + int maxVaryingComponents;
  85 + int maxVertexOutputComponents;
  86 + int maxGeometryInputComponents;
  87 + int maxGeometryOutputComponents;
  88 + int maxFragmentInputComponents;
  89 + int maxImageUnits;
  90 + int maxCombinedImageUnitsAndFragmentOutputs;
  91 + int maxCombinedShaderOutputResources;
  92 + int maxImageSamples;
  93 + int maxVertexImageUniforms;
  94 + int maxTessControlImageUniforms;
  95 + int maxTessEvaluationImageUniforms;
  96 + int maxGeometryImageUniforms;
  97 + int maxFragmentImageUniforms;
  98 + int maxCombinedImageUniforms;
  99 + int maxGeometryTextureImageUnits;
  100 + int maxGeometryOutputVertices;
  101 + int maxGeometryTotalOutputComponents;
  102 + int maxGeometryUniformComponents;
  103 + int maxGeometryVaryingComponents;
  104 + int maxTessControlInputComponents;
  105 + int maxTessControlOutputComponents;
  106 + int maxTessControlTextureImageUnits;
  107 + int maxTessControlUniformComponents;
  108 + int maxTessControlTotalOutputComponents;
  109 + int maxTessEvaluationInputComponents;
  110 + int maxTessEvaluationOutputComponents;
  111 + int maxTessEvaluationTextureImageUnits;
  112 + int maxTessEvaluationUniformComponents;
  113 + int maxTessPatchComponents;
  114 + int maxPatchVertices;
  115 + int maxTessGenLevel;
  116 + int maxViewports;
  117 + int maxVertexAtomicCounters;
  118 + int maxTessControlAtomicCounters;
  119 + int maxTessEvaluationAtomicCounters;
  120 + int maxGeometryAtomicCounters;
  121 + int maxFragmentAtomicCounters;
  122 + int maxCombinedAtomicCounters;
  123 + int maxAtomicCounterBindings;
  124 + int maxVertexAtomicCounterBuffers;
  125 + int maxTessControlAtomicCounterBuffers;
  126 + int maxTessEvaluationAtomicCounterBuffers;
  127 + int maxGeometryAtomicCounterBuffers;
  128 + int maxFragmentAtomicCounterBuffers;
  129 + int maxCombinedAtomicCounterBuffers;
  130 + int maxAtomicCounterBufferSize;
  131 + int maxTransformFeedbackBuffers;
  132 + int maxTransformFeedbackInterleavedComponents;
  133 + int maxCullDistances;
  134 + int maxCombinedClipAndCullDistances;
  135 + int maxSamples;
  136 + int maxMeshOutputVerticesNV;
  137 + int maxMeshOutputPrimitivesNV;
  138 + int maxMeshWorkGroupSizeX_NV;
  139 + int maxMeshWorkGroupSizeY_NV;
  140 + int maxMeshWorkGroupSizeZ_NV;
  141 + int maxTaskWorkGroupSizeX_NV;
  142 + int maxTaskWorkGroupSizeY_NV;
  143 + int maxTaskWorkGroupSizeZ_NV;
  144 + int maxMeshViewCountNV;
  145 + int maxMeshOutputVerticesEXT;
  146 + int maxMeshOutputPrimitivesEXT;
  147 + int maxMeshWorkGroupSizeX_EXT;
  148 + int maxMeshWorkGroupSizeY_EXT;
  149 + int maxMeshWorkGroupSizeZ_EXT;
  150 + int maxTaskWorkGroupSizeX_EXT;
  151 + int maxTaskWorkGroupSizeY_EXT;
  152 + int maxTaskWorkGroupSizeZ_EXT;
  153 + int maxMeshViewCountEXT;
  154 + int maxDualSourceDrawBuffersEXT;
  155 +
  156 + TLimits limits;
  157 +};
  158 +
  159 +#endif // _RESOURCE_LIMITS_INCLUDED_
  1 +/**
  2 + This code is based on the glslang_c_interface implementation by Viktor Latypov
  3 +**/
  4 +
  5 +/**
  6 +BSD 2-Clause License
  7 +
  8 +Copyright (c) 2019, Viktor Latypov
  9 +All rights reserved.
  10 +
  11 +Redistribution and use in source and binary forms, with or without
  12 +modification, are permitted provided that the following conditions are met:
  13 +
  14 +1. Redistributions of source code must retain the above copyright notice, this
  15 + list of conditions and the following disclaimer.
  16 +
  17 +2. Redistributions in binary form must reproduce the above copyright notice,
  18 + this list of conditions and the following disclaimer in the documentation
  19 + and/or other materials provided with the distribution.
  20 +
  21 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22 +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  24 +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  25 +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26 +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  27 +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28 +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29 +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31 +**/
  32 +
  33 +#ifndef GLSLANG_C_IFACE_H_INCLUDED
  34 +#define GLSLANG_C_IFACE_H_INCLUDED
  35 +
  36 +#include <stdbool.h>
  37 +#include <stdlib.h>
  38 +
  39 +#include "glslang_c_shader_types.h"
  40 +#include "visibility.h"
  41 +
  42 +typedef struct glslang_shader_s glslang_shader_t;
  43 +typedef struct glslang_program_s glslang_program_t;
  44 +typedef struct glslang_mapper_s glslang_mapper_t;
  45 +typedef struct glslang_resolver_s glslang_resolver_t;
  46 +
  47 +/* Version counterpart */
  48 +typedef struct glslang_version_s {
  49 + int major;
  50 + int minor;
  51 + int patch;
  52 + const char* flavor;
  53 +} glslang_version_t;
  54 +
  55 +/* TLimits counterpart */
  56 +typedef struct glslang_limits_s {
  57 + bool non_inductive_for_loops;
  58 + bool while_loops;
  59 + bool do_while_loops;
  60 + bool general_uniform_indexing;
  61 + bool general_attribute_matrix_vector_indexing;
  62 + bool general_varying_indexing;
  63 + bool general_sampler_indexing;
  64 + bool general_variable_indexing;
  65 + bool general_constant_matrix_vector_indexing;
  66 +} glslang_limits_t;
  67 +
  68 +/* TBuiltInResource counterpart */
  69 +typedef struct glslang_resource_s {
  70 + int max_lights;
  71 + int max_clip_planes;
  72 + int max_texture_units;
  73 + int max_texture_coords;
  74 + int max_vertex_attribs;
  75 + int max_vertex_uniform_components;
  76 + int max_varying_floats;
  77 + int max_vertex_texture_image_units;
  78 + int max_combined_texture_image_units;
  79 + int max_texture_image_units;
  80 + int max_fragment_uniform_components;
  81 + int max_draw_buffers;
  82 + int max_vertex_uniform_vectors;
  83 + int max_varying_vectors;
  84 + int max_fragment_uniform_vectors;
  85 + int max_vertex_output_vectors;
  86 + int max_fragment_input_vectors;
  87 + int min_program_texel_offset;
  88 + int max_program_texel_offset;
  89 + int max_clip_distances;
  90 + int max_compute_work_group_count_x;
  91 + int max_compute_work_group_count_y;
  92 + int max_compute_work_group_count_z;
  93 + int max_compute_work_group_size_x;
  94 + int max_compute_work_group_size_y;
  95 + int max_compute_work_group_size_z;
  96 + int max_compute_uniform_components;
  97 + int max_compute_texture_image_units;
  98 + int max_compute_image_uniforms;
  99 + int max_compute_atomic_counters;
  100 + int max_compute_atomic_counter_buffers;
  101 + int max_varying_components;
  102 + int max_vertex_output_components;
  103 + int max_geometry_input_components;
  104 + int max_geometry_output_components;
  105 + int max_fragment_input_components;
  106 + int max_image_units;
  107 + int max_combined_image_units_and_fragment_outputs;
  108 + int max_combined_shader_output_resources;
  109 + int max_image_samples;
  110 + int max_vertex_image_uniforms;
  111 + int max_tess_control_image_uniforms;
  112 + int max_tess_evaluation_image_uniforms;
  113 + int max_geometry_image_uniforms;
  114 + int max_fragment_image_uniforms;
  115 + int max_combined_image_uniforms;
  116 + int max_geometry_texture_image_units;
  117 + int max_geometry_output_vertices;
  118 + int max_geometry_total_output_components;
  119 + int max_geometry_uniform_components;
  120 + int max_geometry_varying_components;
  121 + int max_tess_control_input_components;
  122 + int max_tess_control_output_components;
  123 + int max_tess_control_texture_image_units;
  124 + int max_tess_control_uniform_components;
  125 + int max_tess_control_total_output_components;
  126 + int max_tess_evaluation_input_components;
  127 + int max_tess_evaluation_output_components;
  128 + int max_tess_evaluation_texture_image_units;
  129 + int max_tess_evaluation_uniform_components;
  130 + int max_tess_patch_components;
  131 + int max_patch_vertices;
  132 + int max_tess_gen_level;
  133 + int max_viewports;
  134 + int max_vertex_atomic_counters;
  135 + int max_tess_control_atomic_counters;
  136 + int max_tess_evaluation_atomic_counters;
  137 + int max_geometry_atomic_counters;
  138 + int max_fragment_atomic_counters;
  139 + int max_combined_atomic_counters;
  140 + int max_atomic_counter_bindings;
  141 + int max_vertex_atomic_counter_buffers;
  142 + int max_tess_control_atomic_counter_buffers;
  143 + int max_tess_evaluation_atomic_counter_buffers;
  144 + int max_geometry_atomic_counter_buffers;
  145 + int max_fragment_atomic_counter_buffers;
  146 + int max_combined_atomic_counter_buffers;
  147 + int max_atomic_counter_buffer_size;
  148 + int max_transform_feedback_buffers;
  149 + int max_transform_feedback_interleaved_components;
  150 + int max_cull_distances;
  151 + int max_combined_clip_and_cull_distances;
  152 + int max_samples;
  153 + int max_mesh_output_vertices_nv;
  154 + int max_mesh_output_primitives_nv;
  155 + int max_mesh_work_group_size_x_nv;
  156 + int max_mesh_work_group_size_y_nv;
  157 + int max_mesh_work_group_size_z_nv;
  158 + int max_task_work_group_size_x_nv;
  159 + int max_task_work_group_size_y_nv;
  160 + int max_task_work_group_size_z_nv;
  161 + int max_mesh_view_count_nv;
  162 + int max_mesh_output_vertices_ext;
  163 + int max_mesh_output_primitives_ext;
  164 + int max_mesh_work_group_size_x_ext;
  165 + int max_mesh_work_group_size_y_ext;
  166 + int max_mesh_work_group_size_z_ext;
  167 + int max_task_work_group_size_x_ext;
  168 + int max_task_work_group_size_y_ext;
  169 + int max_task_work_group_size_z_ext;
  170 + int max_mesh_view_count_ext;
  171 + union
  172 + {
  173 + int max_dual_source_draw_buffers_ext;
  174 +
  175 + /* Incorrectly capitalized name retained for backward compatibility */
  176 + int maxDualSourceDrawBuffersEXT;
  177 + };
  178 +
  179 + glslang_limits_t limits;
  180 +} glslang_resource_t;
  181 +
  182 +/* Inclusion result structure allocated by C include_local/include_system callbacks */
  183 +typedef struct glsl_include_result_s {
  184 + /* Header file name or NULL if inclusion failed */
  185 + const char* header_name;
  186 +
  187 + /* Header contents or NULL */
  188 + const char* header_data;
  189 + size_t header_length;
  190 +
  191 +} glsl_include_result_t;
  192 +
  193 +/* Callback for local file inclusion */
  194 +typedef glsl_include_result_t* (*glsl_include_local_func)(void* ctx, const char* header_name, const char* includer_name,
  195 + size_t include_depth);
  196 +
  197 +/* Callback for system file inclusion */
  198 +typedef glsl_include_result_t* (*glsl_include_system_func)(void* ctx, const char* header_name,
  199 + const char* includer_name, size_t include_depth);
  200 +
  201 +/* Callback for include result destruction */
  202 +typedef int (*glsl_free_include_result_func)(void* ctx, glsl_include_result_t* result);
  203 +
  204 +/* Collection of callbacks for GLSL preprocessor */
  205 +typedef struct glsl_include_callbacks_s {
  206 + glsl_include_system_func include_system;
  207 + glsl_include_local_func include_local;
  208 + glsl_free_include_result_func free_include_result;
  209 +} glsl_include_callbacks_t;
  210 +
  211 +typedef struct glslang_input_s {
  212 + glslang_source_t language;
  213 + glslang_stage_t stage;
  214 + glslang_client_t client;
  215 + glslang_target_client_version_t client_version;
  216 + glslang_target_language_t target_language;
  217 + glslang_target_language_version_t target_language_version;
  218 + /** Shader source code */
  219 + const char* code;
  220 + int default_version;
  221 + glslang_profile_t default_profile;
  222 + int force_default_version_and_profile;
  223 + int forward_compatible;
  224 + glslang_messages_t messages;
  225 + const glslang_resource_t* resource;
  226 + glsl_include_callbacks_t callbacks;
  227 + void* callbacks_ctx;
  228 +} glslang_input_t;
  229 +
  230 +/* SpvOptions counterpart */
  231 +typedef struct glslang_spv_options_s {
  232 + bool generate_debug_info;
  233 + bool strip_debug_info;
  234 + bool disable_optimizer;
  235 + bool optimize_size;
  236 + bool disassemble;
  237 + bool validate;
  238 + bool emit_nonsemantic_shader_debug_info;
  239 + bool emit_nonsemantic_shader_debug_source;
  240 + bool compile_only;
  241 + bool optimize_allow_expanded_id_bound;
  242 +} glslang_spv_options_t;
  243 +
  244 +#ifdef __cplusplus
  245 +extern "C" {
  246 +#endif
  247 +
  248 +GLSLANG_EXPORT void glslang_get_version(glslang_version_t* version);
  249 +
  250 +GLSLANG_EXPORT int glslang_initialize_process(void);
  251 +GLSLANG_EXPORT void glslang_finalize_process(void);
  252 +
  253 +GLSLANG_EXPORT glslang_shader_t* glslang_shader_create(const glslang_input_t* input);
  254 +GLSLANG_EXPORT void glslang_shader_delete(glslang_shader_t* shader);
  255 +GLSLANG_EXPORT void glslang_shader_set_preamble(glslang_shader_t* shader, const char* s);
  256 +GLSLANG_EXPORT void glslang_shader_shift_binding(glslang_shader_t* shader, glslang_resource_type_t res, unsigned int base);
  257 +GLSLANG_EXPORT void glslang_shader_shift_binding_for_set(glslang_shader_t* shader, glslang_resource_type_t res, unsigned int base, unsigned int set);
  258 +GLSLANG_EXPORT void glslang_shader_set_options(glslang_shader_t* shader, int options); // glslang_shader_options_t
  259 +GLSLANG_EXPORT void glslang_shader_set_glsl_version(glslang_shader_t* shader, int version);
  260 +GLSLANG_EXPORT void glslang_shader_set_default_uniform_block_set_and_binding(glslang_shader_t* shader, unsigned int set, unsigned int binding);
  261 +GLSLANG_EXPORT void glslang_shader_set_default_uniform_block_name(glslang_shader_t* shader, const char *name);
  262 +GLSLANG_EXPORT void glslang_shader_set_resource_set_binding(glslang_shader_t* shader, const char *const *bindings, unsigned int num_bindings);
  263 +GLSLANG_EXPORT int glslang_shader_preprocess(glslang_shader_t* shader, const glslang_input_t* input);
  264 +GLSLANG_EXPORT int glslang_shader_parse(glslang_shader_t* shader, const glslang_input_t* input);
  265 +GLSLANG_EXPORT const char* glslang_shader_get_preprocessed_code(glslang_shader_t* shader);
  266 +GLSLANG_EXPORT void glslang_shader_set_preprocessed_code(glslang_shader_t* shader, const char* code);
  267 +GLSLANG_EXPORT const char* glslang_shader_get_info_log(glslang_shader_t* shader);
  268 +GLSLANG_EXPORT const char* glslang_shader_get_info_debug_log(glslang_shader_t* shader);
  269 +
  270 +GLSLANG_EXPORT glslang_program_t* glslang_program_create(void);
  271 +GLSLANG_EXPORT void glslang_program_delete(glslang_program_t* program);
  272 +GLSLANG_EXPORT void glslang_program_add_shader(glslang_program_t* program, glslang_shader_t* shader);
  273 +GLSLANG_EXPORT int glslang_program_link(glslang_program_t* program, int messages); // glslang_messages_t
  274 +GLSLANG_EXPORT void glslang_program_add_source_text(glslang_program_t* program, glslang_stage_t stage, const char* text, size_t len);
  275 +GLSLANG_EXPORT void glslang_program_set_source_file(glslang_program_t* program, glslang_stage_t stage, const char* file);
  276 +GLSLANG_EXPORT int glslang_program_map_io(glslang_program_t* program);
  277 +GLSLANG_EXPORT int glslang_program_map_io_with_resolver_and_mapper(glslang_program_t* program, glslang_resolver_t* resolver, glslang_mapper_t* mapper);
  278 +GLSLANG_EXPORT void glslang_program_SPIRV_generate(glslang_program_t* program, glslang_stage_t stage);
  279 +GLSLANG_EXPORT void glslang_program_SPIRV_generate_with_options(glslang_program_t* program, glslang_stage_t stage, glslang_spv_options_t* spv_options);
  280 +GLSLANG_EXPORT size_t glslang_program_SPIRV_get_size(glslang_program_t* program);
  281 +GLSLANG_EXPORT void glslang_program_SPIRV_get(glslang_program_t* program, unsigned int*);
  282 +GLSLANG_EXPORT unsigned int* glslang_program_SPIRV_get_ptr(glslang_program_t* program);
  283 +GLSLANG_EXPORT const char* glslang_program_SPIRV_get_messages(glslang_program_t* program);
  284 +GLSLANG_EXPORT const char* glslang_program_get_info_log(glslang_program_t* program);
  285 +GLSLANG_EXPORT const char* glslang_program_get_info_debug_log(glslang_program_t* program);
  286 +
  287 +GLSLANG_EXPORT glslang_mapper_t* glslang_glsl_mapper_create(void);
  288 +GLSLANG_EXPORT void glslang_glsl_mapper_delete(glslang_mapper_t* mapper);
  289 +
  290 +GLSLANG_EXPORT glslang_resolver_t* glslang_glsl_resolver_create(glslang_program_t* program, glslang_stage_t stage);
  291 +GLSLANG_EXPORT void glslang_glsl_resolver_delete(glslang_resolver_t* resolver);
  292 +
  293 +#ifdef __cplusplus
  294 +}
  295 +#endif
  296 +
  297 +#endif /* #ifdef GLSLANG_C_IFACE_INCLUDED */
  1 +/**
  2 + This code is based on the glslang_c_interface implementation by Viktor Latypov
  3 +**/
  4 +
  5 +/**
  6 +BSD 2-Clause License
  7 +
  8 +Copyright (c) 2019, Viktor Latypov
  9 +All rights reserved.
  10 +
  11 +Redistribution and use in source and binary forms, with or without
  12 +modification, are permitted provided that the following conditions are met:
  13 +
  14 +1. Redistributions of source code must retain the above copyright notice, this
  15 + list of conditions and the following disclaimer.
  16 +
  17 +2. Redistributions in binary form must reproduce the above copyright notice,
  18 + this list of conditions and the following disclaimer in the documentation
  19 + and/or other materials provided with the distribution.
  20 +
  21 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22 +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  24 +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  25 +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26 +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  27 +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28 +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29 +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31 +**/
  32 +
  33 +#ifndef C_SHADER_TYPES_H_INCLUDED
  34 +#define C_SHADER_TYPES_H_INCLUDED
  35 +
  36 +#define LAST_ELEMENT_MARKER(x) x
  37 +
  38 +/* EShLanguage counterpart */
  39 +typedef enum {
  40 + GLSLANG_STAGE_VERTEX,
  41 + GLSLANG_STAGE_TESSCONTROL,
  42 + GLSLANG_STAGE_TESSEVALUATION,
  43 + GLSLANG_STAGE_GEOMETRY,
  44 + GLSLANG_STAGE_FRAGMENT,
  45 + GLSLANG_STAGE_COMPUTE,
  46 + GLSLANG_STAGE_RAYGEN,
  47 + GLSLANG_STAGE_RAYGEN_NV = GLSLANG_STAGE_RAYGEN,
  48 + GLSLANG_STAGE_INTERSECT,
  49 + GLSLANG_STAGE_INTERSECT_NV = GLSLANG_STAGE_INTERSECT,
  50 + GLSLANG_STAGE_ANYHIT,
  51 + GLSLANG_STAGE_ANYHIT_NV = GLSLANG_STAGE_ANYHIT,
  52 + GLSLANG_STAGE_CLOSESTHIT,
  53 + GLSLANG_STAGE_CLOSESTHIT_NV = GLSLANG_STAGE_CLOSESTHIT,
  54 + GLSLANG_STAGE_MISS,
  55 + GLSLANG_STAGE_MISS_NV = GLSLANG_STAGE_MISS,
  56 + GLSLANG_STAGE_CALLABLE,
  57 + GLSLANG_STAGE_CALLABLE_NV = GLSLANG_STAGE_CALLABLE,
  58 + GLSLANG_STAGE_TASK,
  59 + GLSLANG_STAGE_TASK_NV = GLSLANG_STAGE_TASK,
  60 + GLSLANG_STAGE_MESH,
  61 + GLSLANG_STAGE_MESH_NV = GLSLANG_STAGE_MESH,
  62 + LAST_ELEMENT_MARKER(GLSLANG_STAGE_COUNT),
  63 +} glslang_stage_t; // would be better as stage, but this is ancient now
  64 +
  65 +/* EShLanguageMask counterpart */
  66 +typedef enum {
  67 + GLSLANG_STAGE_VERTEX_MASK = (1 << GLSLANG_STAGE_VERTEX),
  68 + GLSLANG_STAGE_TESSCONTROL_MASK = (1 << GLSLANG_STAGE_TESSCONTROL),
  69 + GLSLANG_STAGE_TESSEVALUATION_MASK = (1 << GLSLANG_STAGE_TESSEVALUATION),
  70 + GLSLANG_STAGE_GEOMETRY_MASK = (1 << GLSLANG_STAGE_GEOMETRY),
  71 + GLSLANG_STAGE_FRAGMENT_MASK = (1 << GLSLANG_STAGE_FRAGMENT),
  72 + GLSLANG_STAGE_COMPUTE_MASK = (1 << GLSLANG_STAGE_COMPUTE),
  73 + GLSLANG_STAGE_RAYGEN_MASK = (1 << GLSLANG_STAGE_RAYGEN),
  74 + GLSLANG_STAGE_RAYGEN_NV_MASK = GLSLANG_STAGE_RAYGEN_MASK,
  75 + GLSLANG_STAGE_INTERSECT_MASK = (1 << GLSLANG_STAGE_INTERSECT),
  76 + GLSLANG_STAGE_INTERSECT_NV_MASK = GLSLANG_STAGE_INTERSECT_MASK,
  77 + GLSLANG_STAGE_ANYHIT_MASK = (1 << GLSLANG_STAGE_ANYHIT),
  78 + GLSLANG_STAGE_ANYHIT_NV_MASK = GLSLANG_STAGE_ANYHIT_MASK,
  79 + GLSLANG_STAGE_CLOSESTHIT_MASK = (1 << GLSLANG_STAGE_CLOSESTHIT),
  80 + GLSLANG_STAGE_CLOSESTHIT_NV_MASK = GLSLANG_STAGE_CLOSESTHIT_MASK,
  81 + GLSLANG_STAGE_MISS_MASK = (1 << GLSLANG_STAGE_MISS),
  82 + GLSLANG_STAGE_MISS_NV_MASK = GLSLANG_STAGE_MISS_MASK,
  83 + GLSLANG_STAGE_CALLABLE_MASK = (1 << GLSLANG_STAGE_CALLABLE),
  84 + GLSLANG_STAGE_CALLABLE_NV_MASK = GLSLANG_STAGE_CALLABLE_MASK,
  85 + GLSLANG_STAGE_TASK_MASK = (1 << GLSLANG_STAGE_TASK),
  86 + GLSLANG_STAGE_TASK_NV_MASK = GLSLANG_STAGE_TASK_MASK,
  87 + GLSLANG_STAGE_MESH_MASK = (1 << GLSLANG_STAGE_MESH),
  88 + GLSLANG_STAGE_MESH_NV_MASK = GLSLANG_STAGE_MESH_MASK,
  89 + LAST_ELEMENT_MARKER(GLSLANG_STAGE_MASK_COUNT),
  90 +} glslang_stage_mask_t;
  91 +
  92 +/* EShSource counterpart */
  93 +typedef enum {
  94 + GLSLANG_SOURCE_NONE,
  95 + GLSLANG_SOURCE_GLSL,
  96 + GLSLANG_SOURCE_HLSL,
  97 + LAST_ELEMENT_MARKER(GLSLANG_SOURCE_COUNT),
  98 +} glslang_source_t;
  99 +
  100 +/* EShClient counterpart */
  101 +typedef enum {
  102 + GLSLANG_CLIENT_NONE,
  103 + GLSLANG_CLIENT_VULKAN,
  104 + GLSLANG_CLIENT_OPENGL,
  105 + LAST_ELEMENT_MARKER(GLSLANG_CLIENT_COUNT),
  106 +} glslang_client_t;
  107 +
  108 +/* EShTargetLanguage counterpart */
  109 +typedef enum {
  110 + GLSLANG_TARGET_NONE,
  111 + GLSLANG_TARGET_SPV,
  112 + LAST_ELEMENT_MARKER(GLSLANG_TARGET_COUNT),
  113 +} glslang_target_language_t;
  114 +
  115 +/* SH_TARGET_ClientVersion counterpart */
  116 +typedef enum {
  117 + GLSLANG_TARGET_VULKAN_1_0 = (1 << 22),
  118 + GLSLANG_TARGET_VULKAN_1_1 = (1 << 22) | (1 << 12),
  119 + GLSLANG_TARGET_VULKAN_1_2 = (1 << 22) | (2 << 12),
  120 + GLSLANG_TARGET_VULKAN_1_3 = (1 << 22) | (3 << 12),
  121 + GLSLANG_TARGET_VULKAN_1_4 = (1 << 22) | (4 << 12),
  122 + GLSLANG_TARGET_OPENGL_450 = 450,
  123 + LAST_ELEMENT_MARKER(GLSLANG_TARGET_CLIENT_VERSION_COUNT = 6),
  124 +} glslang_target_client_version_t;
  125 +
  126 +/* SH_TARGET_LanguageVersion counterpart */
  127 +typedef enum {
  128 + GLSLANG_TARGET_SPV_1_0 = (1 << 16),
  129 + GLSLANG_TARGET_SPV_1_1 = (1 << 16) | (1 << 8),
  130 + GLSLANG_TARGET_SPV_1_2 = (1 << 16) | (2 << 8),
  131 + GLSLANG_TARGET_SPV_1_3 = (1 << 16) | (3 << 8),
  132 + GLSLANG_TARGET_SPV_1_4 = (1 << 16) | (4 << 8),
  133 + GLSLANG_TARGET_SPV_1_5 = (1 << 16) | (5 << 8),
  134 + GLSLANG_TARGET_SPV_1_6 = (1 << 16) | (6 << 8),
  135 + LAST_ELEMENT_MARKER(GLSLANG_TARGET_LANGUAGE_VERSION_COUNT = 7),
  136 +} glslang_target_language_version_t;
  137 +
  138 +/* EShExecutable counterpart */
  139 +typedef enum { GLSLANG_EX_VERTEX_FRAGMENT, GLSLANG_EX_FRAGMENT } glslang_executable_t;
  140 +
  141 +// EShOptimizationLevel counterpart
  142 +// This enum is not used in the current C interface, but could be added at a later date.
  143 +// GLSLANG_OPT_NONE is the current default.
  144 +typedef enum {
  145 + GLSLANG_OPT_NO_GENERATION,
  146 + GLSLANG_OPT_NONE,
  147 + GLSLANG_OPT_SIMPLE,
  148 + GLSLANG_OPT_FULL,
  149 + LAST_ELEMENT_MARKER(GLSLANG_OPT_LEVEL_COUNT),
  150 +} glslang_optimization_level_t;
  151 +
  152 +/* EShTextureSamplerTransformMode counterpart */
  153 +typedef enum {
  154 + GLSLANG_TEX_SAMP_TRANS_KEEP,
  155 + GLSLANG_TEX_SAMP_TRANS_UPGRADE_TEXTURE_REMOVE_SAMPLER,
  156 + LAST_ELEMENT_MARKER(GLSLANG_TEX_SAMP_TRANS_COUNT),
  157 +} glslang_texture_sampler_transform_mode_t;
  158 +
  159 +/* EShMessages counterpart */
  160 +typedef enum {
  161 + GLSLANG_MSG_DEFAULT_BIT = 0,
  162 + GLSLANG_MSG_RELAXED_ERRORS_BIT = (1 << 0),
  163 + GLSLANG_MSG_SUPPRESS_WARNINGS_BIT = (1 << 1),
  164 + GLSLANG_MSG_AST_BIT = (1 << 2),
  165 + GLSLANG_MSG_SPV_RULES_BIT = (1 << 3),
  166 + GLSLANG_MSG_VULKAN_RULES_BIT = (1 << 4),
  167 + GLSLANG_MSG_ONLY_PREPROCESSOR_BIT = (1 << 5),
  168 + GLSLANG_MSG_READ_HLSL_BIT = (1 << 6),
  169 + GLSLANG_MSG_CASCADING_ERRORS_BIT = (1 << 7),
  170 + GLSLANG_MSG_KEEP_UNCALLED_BIT = (1 << 8),
  171 + GLSLANG_MSG_HLSL_OFFSETS_BIT = (1 << 9),
  172 + GLSLANG_MSG_DEBUG_INFO_BIT = (1 << 10),
  173 + GLSLANG_MSG_HLSL_ENABLE_16BIT_TYPES_BIT = (1 << 11),
  174 + GLSLANG_MSG_HLSL_LEGALIZATION_BIT = (1 << 12),
  175 + GLSLANG_MSG_HLSL_DX9_COMPATIBLE_BIT = (1 << 13),
  176 + GLSLANG_MSG_BUILTIN_SYMBOL_TABLE_BIT = (1 << 14),
  177 + GLSLANG_MSG_ENHANCED = (1 << 15),
  178 + GLSLANG_MSG_ABSOLUTE_PATH = (1 << 16),
  179 + GLSLANG_MSG_DISPLAY_ERROR_COLUMN = (1 << 17),
  180 + GLSLANG_MSG_LINK_TIME_OPTIMIZATION_BIT = (1 << 18),
  181 + LAST_ELEMENT_MARKER(GLSLANG_MSG_COUNT),
  182 +} glslang_messages_t;
  183 +
  184 +/* EShReflectionOptions counterpart */
  185 +typedef enum {
  186 + GLSLANG_REFLECTION_DEFAULT_BIT = 0,
  187 + GLSLANG_REFLECTION_STRICT_ARRAY_SUFFIX_BIT = (1 << 0),
  188 + GLSLANG_REFLECTION_BASIC_ARRAY_SUFFIX_BIT = (1 << 1),
  189 + GLSLANG_REFLECTION_INTERMEDIATE_IOO_BIT = (1 << 2),
  190 + GLSLANG_REFLECTION_SEPARATE_BUFFERS_BIT = (1 << 3),
  191 + GLSLANG_REFLECTION_ALL_BLOCK_VARIABLES_BIT = (1 << 4),
  192 + GLSLANG_REFLECTION_UNWRAP_IO_BLOCKS_BIT = (1 << 5),
  193 + GLSLANG_REFLECTION_ALL_IO_VARIABLES_BIT = (1 << 6),
  194 + GLSLANG_REFLECTION_SHARED_STD140_SSBO_BIT = (1 << 7),
  195 + GLSLANG_REFLECTION_SHARED_STD140_UBO_BIT = (1 << 8),
  196 + LAST_ELEMENT_MARKER(GLSLANG_REFLECTION_COUNT),
  197 +} glslang_reflection_options_t;
  198 +
  199 +/* EProfile counterpart (from Versions.h) */
  200 +typedef enum {
  201 + GLSLANG_BAD_PROFILE = 0,
  202 + GLSLANG_NO_PROFILE = (1 << 0),
  203 + GLSLANG_CORE_PROFILE = (1 << 1),
  204 + GLSLANG_COMPATIBILITY_PROFILE = (1 << 2),
  205 + GLSLANG_ES_PROFILE = (1 << 3),
  206 + LAST_ELEMENT_MARKER(GLSLANG_PROFILE_COUNT),
  207 +} glslang_profile_t;
  208 +
  209 +/* Shader options */
  210 +typedef enum {
  211 + GLSLANG_SHADER_DEFAULT_BIT = 0,
  212 + GLSLANG_SHADER_AUTO_MAP_BINDINGS = (1 << 0),
  213 + GLSLANG_SHADER_AUTO_MAP_LOCATIONS = (1 << 1),
  214 + GLSLANG_SHADER_VULKAN_RULES_RELAXED = (1 << 2),
  215 + LAST_ELEMENT_MARKER(GLSLANG_SHADER_COUNT),
  216 +} glslang_shader_options_t;
  217 +
  218 +/* TResourceType counterpart */
  219 +typedef enum {
  220 + GLSLANG_RESOURCE_TYPE_SAMPLER,
  221 + GLSLANG_RESOURCE_TYPE_TEXTURE,
  222 + GLSLANG_RESOURCE_TYPE_IMAGE,
  223 + GLSLANG_RESOURCE_TYPE_UBO,
  224 + GLSLANG_RESOURCE_TYPE_SSBO,
  225 + GLSLANG_RESOURCE_TYPE_UAV,
  226 + LAST_ELEMENT_MARKER(GLSLANG_RESOURCE_TYPE_COUNT),
  227 +} glslang_resource_type_t;
  228 +
  229 +#undef LAST_ELEMENT_MARKER
  230 +
  231 +#endif
  1 +//
  2 +// Copyright (C) 2023 LunarG, Inc.
  3 +//
  4 +// All rights reserved.
  5 +//
  6 +// Redistribution and use in source and binary forms, with or without
  7 +// modification, are permitted provided that the following conditions
  8 +// are met:
  9 +//
  10 +// Redistributions of source code must retain the above copyright
  11 +// notice, this list of conditions and the following disclaimer.
  12 +//
  13 +// Redistributions in binary form must reproduce the above
  14 +// copyright notice, this list of conditions and the following
  15 +// disclaimer in the documentation and/or other materials provided
  16 +// with the distribution.
  17 +//
  18 +// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
  19 +// contributors may be used to endorse or promote products derived
  20 +// from this software without specific prior written permission.
  21 +//
  22 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25 +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  26 +// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27 +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28 +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29 +// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  30 +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31 +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  32 +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33 +// POSSIBILITY OF SUCH DAMAGE.
  34 +//
  35 +#ifdef GLSLANG_IS_SHARED_LIBRARY
  36 + #ifdef _WIN32
  37 + #ifdef GLSLANG_EXPORTING
  38 + #define GLSLANG_EXPORT __declspec(dllexport)
  39 + #else
  40 + #define GLSLANG_EXPORT __declspec(dllimport)
  41 + #endif
  42 + #elif __GNUC__ >= 4
  43 + #define GLSLANG_EXPORT __attribute__((visibility("default")))
  44 + #endif
  45 +#endif // GLSLANG_IS_SHARED_LIBRARY
  46 +
  47 +#ifndef GLSLANG_EXPORT
  48 +#define GLSLANG_EXPORT
  49 +#endif
  50 +
  51 +// Symbols marked with this macro are only meant for public use by the test suite
  52 +// and do not appear in publicly installed headers. They are not considered to be
  53 +// part of the glslang library ABI.
  54 +#define GLSLANG_EXPORT_FOR_TESTS GLSLANG_EXPORT
  1 +//
  2 +// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
  3 +// Copyright (C) 2012-2013 LunarG, Inc.
  4 +// Copyright (C) 2017, 2022-2024 Arm Limited.
  5 +// Copyright (C) 2015-2018 Google, Inc.
  6 +// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
  7 +// Modifications Copyright (C) 2024 Valve Corporation.
  8 +//
  9 +// All rights reserved.
  10 +//
  11 +// Redistribution and use in source and binary forms, with or without
  12 +// modification, are permitted provided that the following conditions
  13 +// are met:
  14 +//
  15 +// Redistributions of source code must retain the above copyright
  16 +// notice, this list of conditions and the following disclaimer.
  17 +//
  18 +// Redistributions in binary form must reproduce the above
  19 +// copyright notice, this list of conditions and the following
  20 +// disclaimer in the documentation and/or other materials provided
  21 +// with the distribution.
  22 +//
  23 +// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
  24 +// contributors may be used to endorse or promote products derived
  25 +// from this software without specific prior written permission.
  26 +//
  27 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  30 +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  31 +// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  32 +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  33 +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  34 +// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  35 +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36 +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  37 +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38 +// POSSIBILITY OF SUCH DAMAGE.
  39 +//
  40 +
  41 +#ifndef _VERSIONS_INCLUDED_
  42 +#define _VERSIONS_INCLUDED_
  43 +
  44 +#define LAST_ELEMENT_MARKER(x) x
  45 +
  46 +//
  47 +// Help manage multiple profiles, versions, extensions etc.
  48 +//
  49 +
  50 +//
  51 +// Profiles are set up for masking operations, so queries can be done on multiple
  52 +// profiles at the same time.
  53 +//
  54 +// Don't maintain an ordinal set of enums (0,1,2,3...) to avoid all possible
  55 +// defects from mixing the two different forms.
  56 +//
  57 +typedef enum : unsigned {
  58 + EBadProfile = 0,
  59 + ENoProfile = (1 << 0), // only for desktop, before profiles showed up
  60 + ECoreProfile = (1 << 1),
  61 + ECompatibilityProfile = (1 << 2),
  62 + EEsProfile = (1 << 3),
  63 + LAST_ELEMENT_MARKER(EProfileCount),
  64 +} EProfile;
  65 +
  66 +namespace glslang {
  67 +
  68 +//
  69 +// Map from profile enum to externally readable text name.
  70 +//
  71 +inline const char* ProfileName(EProfile profile)
  72 +{
  73 + switch (profile) {
  74 + case ENoProfile: return "none";
  75 + case ECoreProfile: return "core";
  76 + case ECompatibilityProfile: return "compatibility";
  77 + case EEsProfile: return "es";
  78 + default: return "unknown profile";
  79 + }
  80 +}
  81 +
  82 +//
  83 +// What source rules, validation rules, target language, etc. are needed or
  84 +// desired for SPIR-V?
  85 +//
  86 +// 0 means a target or rule set is not enabled (ignore rules from that entity).
  87 +// Non-0 means to apply semantic rules arising from that version of its rule set.
  88 +// The union of all requested rule sets will be applied.
  89 +//
  90 +struct SpvVersion {
  91 + SpvVersion() : spv(0), vulkanGlsl(0), vulkan(0), openGl(0), vulkanRelaxed(false) {}
  92 + unsigned int spv; // the version of SPIR-V to target, as defined by "word 1" of the SPIR-V binary header
  93 + int vulkanGlsl; // the version of GLSL semantics for Vulkan, from GL_KHR_vulkan_glsl, for "#define VULKAN XXX"
  94 + int vulkan; // the version of Vulkan, for which SPIR-V execution environment rules to use
  95 + int openGl; // the version of GLSL semantics for OpenGL, from GL_ARB_gl_spirv, for "#define GL_SPIRV XXX"
  96 + bool vulkanRelaxed; // relax changes to GLSL for Vulkan, allowing some GL-specific to be compiled to Vulkan SPIR-V target
  97 +};
  98 +
  99 +//
  100 +// The behaviors from the GLSL "#extension extension_name : behavior"
  101 +//
  102 +typedef enum {
  103 + EBhMissing = 0,
  104 + EBhRequire,
  105 + EBhEnable,
  106 + EBhWarn,
  107 + EBhDisable,
  108 + EBhDisablePartial // use as initial state of an extension that is only partially implemented
  109 +} TExtensionBehavior;
  110 +
  111 +//
  112 +// Symbolic names for extensions. Strings may be directly used when calling the
  113 +// functions, but better to have the compiler do spelling checks.
  114 +//
  115 +const char* const E_GL_OES_texture_3D = "GL_OES_texture_3D";
  116 +const char* const E_GL_OES_standard_derivatives = "GL_OES_standard_derivatives";
  117 +const char* const E_GL_EXT_frag_depth = "GL_EXT_frag_depth";
  118 +const char* const E_GL_OES_EGL_image_external = "GL_OES_EGL_image_external";
  119 +const char* const E_GL_OES_EGL_image_external_essl3 = "GL_OES_EGL_image_external_essl3";
  120 +const char* const E_GL_EXT_YUV_target = "GL_EXT_YUV_target";
  121 +const char* const E_GL_EXT_shader_texture_lod = "GL_EXT_shader_texture_lod";
  122 +const char* const E_GL_EXT_shadow_samplers = "GL_EXT_shadow_samplers";
  123 +
  124 +const char* const E_GL_ARB_texture_rectangle = "GL_ARB_texture_rectangle";
  125 +const char* const E_GL_3DL_array_objects = "GL_3DL_array_objects";
  126 +const char* const E_GL_ARB_shading_language_420pack = "GL_ARB_shading_language_420pack";
  127 +const char* const E_GL_ARB_texture_gather = "GL_ARB_texture_gather";
  128 +const char* const E_GL_ARB_gpu_shader5 = "GL_ARB_gpu_shader5";
  129 +const char* const E_GL_ARB_separate_shader_objects = "GL_ARB_separate_shader_objects";
  130 +const char* const E_GL_ARB_compute_shader = "GL_ARB_compute_shader";
  131 +const char* const E_GL_ARB_tessellation_shader = "GL_ARB_tessellation_shader";
  132 +const char* const E_GL_ARB_enhanced_layouts = "GL_ARB_enhanced_layouts";
  133 +const char* const E_GL_ARB_texture_cube_map_array = "GL_ARB_texture_cube_map_array";
  134 +const char* const E_GL_ARB_texture_multisample = "GL_ARB_texture_multisample";
  135 +const char* const E_GL_ARB_shader_texture_lod = "GL_ARB_shader_texture_lod";
  136 +const char* const E_GL_ARB_explicit_attrib_location = "GL_ARB_explicit_attrib_location";
  137 +const char* const E_GL_ARB_explicit_uniform_location = "GL_ARB_explicit_uniform_location";
  138 +const char* const E_GL_ARB_shader_image_load_store = "GL_ARB_shader_image_load_store";
  139 +const char* const E_GL_ARB_shader_atomic_counters = "GL_ARB_shader_atomic_counters";
  140 +const char* const E_GL_ARB_shader_atomic_counter_ops = "GL_ARB_shader_atomic_counter_ops";
  141 +const char* const E_GL_ARB_shader_draw_parameters = "GL_ARB_shader_draw_parameters";
  142 +const char* const E_GL_ARB_shader_group_vote = "GL_ARB_shader_group_vote";
  143 +const char* const E_GL_ARB_derivative_control = "GL_ARB_derivative_control";
  144 +const char* const E_GL_ARB_shader_texture_image_samples = "GL_ARB_shader_texture_image_samples";
  145 +const char* const E_GL_ARB_viewport_array = "GL_ARB_viewport_array";
  146 +const char* const E_GL_ARB_gpu_shader_int64 = "GL_ARB_gpu_shader_int64";
  147 +const char* const E_GL_ARB_gpu_shader_fp64 = "GL_ARB_gpu_shader_fp64";
  148 +const char* const E_GL_ARB_shader_ballot = "GL_ARB_shader_ballot";
  149 +const char* const E_GL_ARB_sparse_texture2 = "GL_ARB_sparse_texture2";
  150 +const char* const E_GL_ARB_sparse_texture_clamp = "GL_ARB_sparse_texture_clamp";
  151 +const char* const E_GL_ARB_shader_stencil_export = "GL_ARB_shader_stencil_export";
  152 +// const char* const E_GL_ARB_cull_distance = "GL_ARB_cull_distance"; // present for 4.5, but need extension control over block members
  153 +const char* const E_GL_ARB_post_depth_coverage = "GL_ARB_post_depth_coverage";
  154 +const char* const E_GL_ARB_shader_viewport_layer_array = "GL_ARB_shader_viewport_layer_array";
  155 +const char* const E_GL_ARB_fragment_shader_interlock = "GL_ARB_fragment_shader_interlock";
  156 +const char* const E_GL_ARB_shader_clock = "GL_ARB_shader_clock";
  157 +const char* const E_GL_ARB_uniform_buffer_object = "GL_ARB_uniform_buffer_object";
  158 +const char* const E_GL_ARB_sample_shading = "GL_ARB_sample_shading";
  159 +const char* const E_GL_ARB_shader_bit_encoding = "GL_ARB_shader_bit_encoding";
  160 +const char* const E_GL_ARB_shader_image_size = "GL_ARB_shader_image_size";
  161 +const char* const E_GL_ARB_shader_storage_buffer_object = "GL_ARB_shader_storage_buffer_object";
  162 +const char* const E_GL_ARB_shading_language_packing = "GL_ARB_shading_language_packing";
  163 +const char* const E_GL_ARB_texture_query_lod = "GL_ARB_texture_query_lod";
  164 +const char* const E_GL_ARB_vertex_attrib_64bit = "GL_ARB_vertex_attrib_64bit";
  165 +const char* const E_GL_ARB_draw_instanced = "GL_ARB_draw_instanced";
  166 +const char* const E_GL_ARB_fragment_coord_conventions = "GL_ARB_fragment_coord_conventions";
  167 +const char* const E_GL_ARB_bindless_texture = "GL_ARB_bindless_texture";
  168 +
  169 +const char* const E_GL_KHR_shader_subgroup_basic = "GL_KHR_shader_subgroup_basic";
  170 +const char* const E_GL_KHR_shader_subgroup_vote = "GL_KHR_shader_subgroup_vote";
  171 +const char* const E_GL_KHR_shader_subgroup_arithmetic = "GL_KHR_shader_subgroup_arithmetic";
  172 +const char* const E_GL_KHR_shader_subgroup_ballot = "GL_KHR_shader_subgroup_ballot";
  173 +const char* const E_GL_KHR_shader_subgroup_shuffle = "GL_KHR_shader_subgroup_shuffle";
  174 +const char* const E_GL_KHR_shader_subgroup_shuffle_relative = "GL_KHR_shader_subgroup_shuffle_relative";
  175 +const char* const E_GL_KHR_shader_subgroup_rotate = "GL_KHR_shader_subgroup_rotate";
  176 +const char* const E_GL_KHR_shader_subgroup_clustered = "GL_KHR_shader_subgroup_clustered";
  177 +const char* const E_GL_KHR_shader_subgroup_quad = "GL_KHR_shader_subgroup_quad";
  178 +const char* const E_GL_KHR_memory_scope_semantics = "GL_KHR_memory_scope_semantics";
  179 +const char* const E_GL_KHR_cooperative_matrix = "GL_KHR_cooperative_matrix";
  180 +
  181 +const char* const E_GL_EXT_shader_atomic_int64 = "GL_EXT_shader_atomic_int64";
  182 +
  183 +const char* const E_GL_EXT_shader_non_constant_global_initializers = "GL_EXT_shader_non_constant_global_initializers";
  184 +const char* const E_GL_EXT_shader_image_load_formatted = "GL_EXT_shader_image_load_formatted";
  185 +
  186 +const char* const E_GL_EXT_shader_16bit_storage = "GL_EXT_shader_16bit_storage";
  187 +const char* const E_GL_EXT_shader_8bit_storage = "GL_EXT_shader_8bit_storage";
  188 +
  189 +
  190 +// EXT extensions
  191 +const char* const E_GL_EXT_device_group = "GL_EXT_device_group";
  192 +const char* const E_GL_EXT_multiview = "GL_EXT_multiview";
  193 +const char* const E_GL_EXT_post_depth_coverage = "GL_EXT_post_depth_coverage";
  194 +const char* const E_GL_EXT_control_flow_attributes = "GL_EXT_control_flow_attributes";
  195 +const char* const E_GL_EXT_nonuniform_qualifier = "GL_EXT_nonuniform_qualifier";
  196 +const char* const E_GL_EXT_samplerless_texture_functions = "GL_EXT_samplerless_texture_functions";
  197 +const char* const E_GL_EXT_scalar_block_layout = "GL_EXT_scalar_block_layout";
  198 +const char* const E_GL_EXT_fragment_invocation_density = "GL_EXT_fragment_invocation_density";
  199 +const char* const E_GL_EXT_buffer_reference = "GL_EXT_buffer_reference";
  200 +const char* const E_GL_EXT_buffer_reference2 = "GL_EXT_buffer_reference2";
  201 +const char* const E_GL_EXT_buffer_reference_uvec2 = "GL_EXT_buffer_reference_uvec2";
  202 +const char* const E_GL_EXT_demote_to_helper_invocation = "GL_EXT_demote_to_helper_invocation";
  203 +const char* const E_GL_EXT_shader_realtime_clock = "GL_EXT_shader_realtime_clock";
  204 +const char* const E_GL_EXT_debug_printf = "GL_EXT_debug_printf";
  205 +const char* const E_GL_EXT_ray_tracing = "GL_EXT_ray_tracing";
  206 +const char* const E_GL_EXT_ray_query = "GL_EXT_ray_query";
  207 +const char* const E_GL_EXT_ray_flags_primitive_culling = "GL_EXT_ray_flags_primitive_culling";
  208 +const char* const E_GL_EXT_ray_cull_mask = "GL_EXT_ray_cull_mask";
  209 +const char* const E_GL_EXT_blend_func_extended = "GL_EXT_blend_func_extended";
  210 +const char* const E_GL_EXT_shader_implicit_conversions = "GL_EXT_shader_implicit_conversions";
  211 +const char* const E_GL_EXT_fragment_shading_rate = "GL_EXT_fragment_shading_rate";
  212 +const char* const E_GL_EXT_shader_image_int64 = "GL_EXT_shader_image_int64";
  213 +const char* const E_GL_EXT_null_initializer = "GL_EXT_null_initializer";
  214 +const char* const E_GL_EXT_shared_memory_block = "GL_EXT_shared_memory_block";
  215 +const char* const E_GL_EXT_subgroup_uniform_control_flow = "GL_EXT_subgroup_uniform_control_flow";
  216 +const char* const E_GL_EXT_spirv_intrinsics = "GL_EXT_spirv_intrinsics";
  217 +const char* const E_GL_EXT_fragment_shader_barycentric = "GL_EXT_fragment_shader_barycentric";
  218 +const char* const E_GL_EXT_mesh_shader = "GL_EXT_mesh_shader";
  219 +const char* const E_GL_EXT_opacity_micromap = "GL_EXT_opacity_micromap";
  220 +const char* const E_GL_EXT_shader_quad_control = "GL_EXT_shader_quad_control";
  221 +const char* const E_GL_EXT_draw_instanced = "GL_EXT_draw_instanced";
  222 +const char* const E_GL_EXT_texture_array = "GL_EXT_texture_array";
  223 +const char* const E_GL_EXT_maximal_reconvergence = "GL_EXT_maximal_reconvergence";
  224 +const char* const E_GL_EXT_expect_assume = "GL_EXT_expect_assume";
  225 +const char* const E_GL_EXT_control_flow_attributes2 = "GL_EXT_control_flow_attributes2";
  226 +const char* const E_GL_EXT_spec_constant_composites = "GL_EXT_spec_constant_composites";
  227 +const char* const E_GL_EXT_texture_offset_non_const = "GL_EXT_texture_offset_non_const";
  228 +const char* const E_GL_EXT_nontemporal_keyword = "GL_EXT_nontemporal_keyword";
  229 +
  230 +// Arrays of extensions for the above viewportEXTs duplications
  231 +
  232 +const char* const post_depth_coverageEXTs[] = { E_GL_ARB_post_depth_coverage, E_GL_EXT_post_depth_coverage };
  233 +const int Num_post_depth_coverageEXTs = sizeof(post_depth_coverageEXTs) / sizeof(post_depth_coverageEXTs[0]);
  234 +
  235 +// Array of extensions to cover both extensions providing ray tracing capabilities.
  236 +const char* const ray_tracing_EXTs[] = { E_GL_EXT_ray_query, E_GL_EXT_ray_tracing };
  237 +const int Num_ray_tracing_EXTs = sizeof(ray_tracing_EXTs) / sizeof(ray_tracing_EXTs[0]);
  238 +
  239 +// OVR extensions
  240 +const char* const E_GL_OVR_multiview = "GL_OVR_multiview";
  241 +const char* const E_GL_OVR_multiview2 = "GL_OVR_multiview2";
  242 +
  243 +const char* const OVR_multiview_EXTs[] = { E_GL_OVR_multiview, E_GL_OVR_multiview2 };
  244 +const int Num_OVR_multiview_EXTs = sizeof(OVR_multiview_EXTs) / sizeof(OVR_multiview_EXTs[0]);
  245 +
  246 +// #line and #include
  247 +const char* const E_GL_GOOGLE_cpp_style_line_directive = "GL_GOOGLE_cpp_style_line_directive";
  248 +const char* const E_GL_GOOGLE_include_directive = "GL_GOOGLE_include_directive";
  249 +const char* const E_GL_ARB_shading_language_include = "GL_ARB_shading_language_include";
  250 +
  251 +const char* const E_GL_AMD_shader_ballot = "GL_AMD_shader_ballot";
  252 +const char* const E_GL_AMD_shader_trinary_minmax = "GL_AMD_shader_trinary_minmax";
  253 +const char* const E_GL_AMD_shader_explicit_vertex_parameter = "GL_AMD_shader_explicit_vertex_parameter";
  254 +const char* const E_GL_AMD_gcn_shader = "GL_AMD_gcn_shader";
  255 +const char* const E_GL_AMD_gpu_shader_half_float = "GL_AMD_gpu_shader_half_float";
  256 +const char* const E_GL_AMD_texture_gather_bias_lod = "GL_AMD_texture_gather_bias_lod";
  257 +const char* const E_GL_AMD_gpu_shader_int16 = "GL_AMD_gpu_shader_int16";
  258 +const char* const E_GL_AMD_shader_image_load_store_lod = "GL_AMD_shader_image_load_store_lod";
  259 +const char* const E_GL_AMD_shader_fragment_mask = "GL_AMD_shader_fragment_mask";
  260 +const char* const E_GL_AMD_gpu_shader_half_float_fetch = "GL_AMD_gpu_shader_half_float_fetch";
  261 +const char* const E_GL_AMD_shader_early_and_late_fragment_tests = "GL_AMD_shader_early_and_late_fragment_tests";
  262 +
  263 +const char* const E_GL_INTEL_shader_integer_functions2 = "GL_INTEL_shader_integer_functions2";
  264 +
  265 +const char* const E_GL_NV_sample_mask_override_coverage = "GL_NV_sample_mask_override_coverage";
  266 +const char* const E_SPV_NV_geometry_shader_passthrough = "GL_NV_geometry_shader_passthrough";
  267 +const char* const E_GL_NV_viewport_array2 = "GL_NV_viewport_array2";
  268 +const char* const E_GL_NV_stereo_view_rendering = "GL_NV_stereo_view_rendering";
  269 +const char* const E_GL_NVX_multiview_per_view_attributes = "GL_NVX_multiview_per_view_attributes";
  270 +const char* const E_GL_NV_shader_atomic_int64 = "GL_NV_shader_atomic_int64";
  271 +const char* const E_GL_NV_conservative_raster_underestimation = "GL_NV_conservative_raster_underestimation";
  272 +const char* const E_GL_NV_shader_noperspective_interpolation = "GL_NV_shader_noperspective_interpolation";
  273 +const char* const E_GL_NV_shader_subgroup_partitioned = "GL_NV_shader_subgroup_partitioned";
  274 +const char* const E_GL_NV_shading_rate_image = "GL_NV_shading_rate_image";
  275 +const char* const E_GL_NV_ray_tracing = "GL_NV_ray_tracing";
  276 +const char* const E_GL_NV_ray_tracing_motion_blur = "GL_NV_ray_tracing_motion_blur";
  277 +const char* const E_GL_NV_fragment_shader_barycentric = "GL_NV_fragment_shader_barycentric";
  278 +const char* const E_GL_NV_compute_shader_derivatives = "GL_NV_compute_shader_derivatives";
  279 +const char* const E_GL_NV_shader_texture_footprint = "GL_NV_shader_texture_footprint";
  280 +const char* const E_GL_NV_mesh_shader = "GL_NV_mesh_shader";
  281 +const char* const E_GL_NV_cooperative_matrix = "GL_NV_cooperative_matrix";
  282 +const char* const E_GL_NV_shader_sm_builtins = "GL_NV_shader_sm_builtins";
  283 +const char* const E_GL_NV_integer_cooperative_matrix = "GL_NV_integer_cooperative_matrix";
  284 +const char* const E_GL_NV_shader_invocation_reorder = "GL_NV_shader_invocation_reorder";
  285 +const char* const E_GL_EXT_ray_tracing_position_fetch = "GL_EXT_ray_tracing_position_fetch";
  286 +const char* const E_GL_NV_displacement_micromap = "GL_NV_displacement_micromap";
  287 +const char* const E_GL_NV_shader_atomic_fp16_vector = "GL_NV_shader_atomic_fp16_vector";
  288 +const char* const E_GL_NV_cooperative_matrix2 = "GL_NV_cooperative_matrix2";
  289 +const char* const E_GL_NV_cooperative_vector = "GL_NV_cooperative_vector";
  290 +const char* const E_GL_NV_cluster_acceleration_structure = "GL_NV_cluster_acceleration_structure";
  291 +const char* const E_GL_NV_linear_swept_spheres = "GL_NV_linear_swept_spheres";
  292 +
  293 +// ARM
  294 +const char* const E_GL_ARM_shader_core_builtins = "GL_ARM_shader_core_builtins";
  295 +
  296 +// Arrays of extensions for the above viewportEXTs duplications
  297 +
  298 +const char* const viewportEXTs[] = { E_GL_ARB_shader_viewport_layer_array, E_GL_NV_viewport_array2 };
  299 +const int Num_viewportEXTs = sizeof(viewportEXTs) / sizeof(viewportEXTs[0]);
  300 +
  301 +
  302 +const char* const E_GL_QCOM_image_processing = "GL_QCOM_image_processing";
  303 +const char* const E_GL_QCOM_image_processing2 = "GL_QCOM_image_processing2";
  304 +
  305 +// AEP
  306 +const char* const E_GL_ANDROID_extension_pack_es31a = "GL_ANDROID_extension_pack_es31a";
  307 +const char* const E_GL_KHR_blend_equation_advanced = "GL_KHR_blend_equation_advanced";
  308 +const char* const E_GL_OES_sample_variables = "GL_OES_sample_variables";
  309 +const char* const E_GL_OES_shader_image_atomic = "GL_OES_shader_image_atomic";
  310 +const char* const E_GL_OES_shader_multisample_interpolation = "GL_OES_shader_multisample_interpolation";
  311 +const char* const E_GL_OES_texture_storage_multisample_2d_array = "GL_OES_texture_storage_multisample_2d_array";
  312 +const char* const E_GL_EXT_geometry_shader = "GL_EXT_geometry_shader";
  313 +const char* const E_GL_EXT_geometry_point_size = "GL_EXT_geometry_point_size";
  314 +const char* const E_GL_EXT_gpu_shader5 = "GL_EXT_gpu_shader5";
  315 +const char* const E_GL_EXT_primitive_bounding_box = "GL_EXT_primitive_bounding_box";
  316 +const char* const E_GL_EXT_shader_io_blocks = "GL_EXT_shader_io_blocks";
  317 +const char* const E_GL_EXT_tessellation_shader = "GL_EXT_tessellation_shader";
  318 +const char* const E_GL_EXT_tessellation_point_size = "GL_EXT_tessellation_point_size";
  319 +const char* const E_GL_EXT_texture_buffer = "GL_EXT_texture_buffer";
  320 +const char* const E_GL_EXT_texture_cube_map_array = "GL_EXT_texture_cube_map_array";
  321 +const char* const E_GL_EXT_shader_integer_mix = "GL_EXT_shader_integer_mix";
  322 +
  323 +// OES matching AEP
  324 +const char* const E_GL_OES_geometry_shader = "GL_OES_geometry_shader";
  325 +const char* const E_GL_OES_geometry_point_size = "GL_OES_geometry_point_size";
  326 +const char* const E_GL_OES_gpu_shader5 = "GL_OES_gpu_shader5";
  327 +const char* const E_GL_OES_primitive_bounding_box = "GL_OES_primitive_bounding_box";
  328 +const char* const E_GL_OES_shader_io_blocks = "GL_OES_shader_io_blocks";
  329 +const char* const E_GL_OES_tessellation_shader = "GL_OES_tessellation_shader";
  330 +const char* const E_GL_OES_tessellation_point_size = "GL_OES_tessellation_point_size";
  331 +const char* const E_GL_OES_texture_buffer = "GL_OES_texture_buffer";
  332 +const char* const E_GL_OES_texture_cube_map_array = "GL_OES_texture_cube_map_array";
  333 +
  334 +// EXT
  335 +const char* const E_GL_EXT_shader_explicit_arithmetic_types = "GL_EXT_shader_explicit_arithmetic_types";
  336 +const char* const E_GL_EXT_shader_explicit_arithmetic_types_int8 = "GL_EXT_shader_explicit_arithmetic_types_int8";
  337 +const char* const E_GL_EXT_shader_explicit_arithmetic_types_int16 = "GL_EXT_shader_explicit_arithmetic_types_int16";
  338 +const char* const E_GL_EXT_shader_explicit_arithmetic_types_int32 = "GL_EXT_shader_explicit_arithmetic_types_int32";
  339 +const char* const E_GL_EXT_shader_explicit_arithmetic_types_int64 = "GL_EXT_shader_explicit_arithmetic_types_int64";
  340 +const char* const E_GL_EXT_shader_explicit_arithmetic_types_float16 = "GL_EXT_shader_explicit_arithmetic_types_float16";
  341 +const char* const E_GL_EXT_shader_explicit_arithmetic_types_float32 = "GL_EXT_shader_explicit_arithmetic_types_float32";
  342 +const char* const E_GL_EXT_shader_explicit_arithmetic_types_float64 = "GL_EXT_shader_explicit_arithmetic_types_float64";
  343 +
  344 +const char* const E_GL_EXT_shader_subgroup_extended_types_int8 = "GL_EXT_shader_subgroup_extended_types_int8";
  345 +const char* const E_GL_EXT_shader_subgroup_extended_types_int16 = "GL_EXT_shader_subgroup_extended_types_int16";
  346 +const char* const E_GL_EXT_shader_subgroup_extended_types_int64 = "GL_EXT_shader_subgroup_extended_types_int64";
  347 +const char* const E_GL_EXT_shader_subgroup_extended_types_float16 = "GL_EXT_shader_subgroup_extended_types_float16";
  348 +const char* const E_GL_EXT_terminate_invocation = "GL_EXT_terminate_invocation";
  349 +
  350 +const char* const E_GL_EXT_shader_atomic_float = "GL_EXT_shader_atomic_float";
  351 +const char* const E_GL_EXT_shader_atomic_float2 = "GL_EXT_shader_atomic_float2";
  352 +
  353 +const char* const E_GL_EXT_shader_tile_image = "GL_EXT_shader_tile_image";
  354 +
  355 +const char* const E_GL_EXT_texture_shadow_lod = "GL_EXT_texture_shadow_lod";
  356 +
  357 +const char* const E_GL_EXT_integer_dot_product = "GL_EXT_integer_dot_product";
  358 +
  359 +// Arrays of extensions for the above AEP duplications
  360 +
  361 +const char* const AEP_geometry_shader[] = { E_GL_EXT_geometry_shader, E_GL_OES_geometry_shader };
  362 +const int Num_AEP_geometry_shader = sizeof(AEP_geometry_shader)/sizeof(AEP_geometry_shader[0]);
  363 +
  364 +const char* const AEP_geometry_point_size[] = { E_GL_EXT_geometry_point_size, E_GL_OES_geometry_point_size };
  365 +const int Num_AEP_geometry_point_size = sizeof(AEP_geometry_point_size)/sizeof(AEP_geometry_point_size[0]);
  366 +
  367 +const char* const AEP_gpu_shader5[] = { E_GL_EXT_gpu_shader5, E_GL_OES_gpu_shader5 };
  368 +const int Num_AEP_gpu_shader5 = sizeof(AEP_gpu_shader5)/sizeof(AEP_gpu_shader5[0]);
  369 +
  370 +const char* const AEP_primitive_bounding_box[] = { E_GL_EXT_primitive_bounding_box, E_GL_OES_primitive_bounding_box };
  371 +const int Num_AEP_primitive_bounding_box = sizeof(AEP_primitive_bounding_box)/sizeof(AEP_primitive_bounding_box[0]);
  372 +
  373 +const char* const AEP_shader_io_blocks[] = { E_GL_EXT_shader_io_blocks, E_GL_OES_shader_io_blocks };
  374 +const int Num_AEP_shader_io_blocks = sizeof(AEP_shader_io_blocks)/sizeof(AEP_shader_io_blocks[0]);
  375 +
  376 +const char* const AEP_tessellation_shader[] = { E_GL_EXT_tessellation_shader, E_GL_OES_tessellation_shader };
  377 +const int Num_AEP_tessellation_shader = sizeof(AEP_tessellation_shader)/sizeof(AEP_tessellation_shader[0]);
  378 +
  379 +const char* const AEP_tessellation_point_size[] = { E_GL_EXT_tessellation_point_size, E_GL_OES_tessellation_point_size };
  380 +const int Num_AEP_tessellation_point_size = sizeof(AEP_tessellation_point_size)/sizeof(AEP_tessellation_point_size[0]);
  381 +
  382 +const char* const AEP_texture_buffer[] = { E_GL_EXT_texture_buffer, E_GL_OES_texture_buffer };
  383 +const int Num_AEP_texture_buffer = sizeof(AEP_texture_buffer)/sizeof(AEP_texture_buffer[0]);
  384 +
  385 +const char* const AEP_texture_cube_map_array[] = { E_GL_EXT_texture_cube_map_array, E_GL_OES_texture_cube_map_array };
  386 +const int Num_AEP_texture_cube_map_array = sizeof(AEP_texture_cube_map_array)/sizeof(AEP_texture_cube_map_array[0]);
  387 +
  388 +const char* const AEP_mesh_shader[] = { E_GL_NV_mesh_shader, E_GL_EXT_mesh_shader };
  389 +const int Num_AEP_mesh_shader = sizeof(AEP_mesh_shader)/sizeof(AEP_mesh_shader[0]);
  390 +
  391 +} // end namespace glslang
  392 +
  393 +#endif // _VERSIONS_INCLUDED_
  1 +//
  2 +// Copyright (C) 2016 Google, Inc.
  3 +//
  4 +// All rights reserved.
  5 +//
  6 +// Redistribution and use in source and binary forms, with or without
  7 +// modification, are permitted provided that the following conditions
  8 +// are met:
  9 +//
  10 +// Redistributions of source code must retain the above copyright
  11 +// notice, this list of conditions and the following disclaimer.
  12 +//
  13 +// Redistributions in binary form must reproduce the above
  14 +// copyright notice, this list of conditions and the following
  15 +// disclaimer in the documentation and/or other materials provided
  16 +// with the distribution.
  17 +//
  18 +// Neither the name of Google Inc. nor the names of its
  19 +// contributors may be used to endorse or promote products derived
  20 +// from this software without specific prior written permission.
  21 +//
  22 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25 +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  26 +// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27 +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28 +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29 +// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  30 +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31 +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  32 +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33 +// POSSIBILITY OF SUCH DAMAGE.
  34 +
  35 +#ifndef _STAND_ALONE_RESOURCE_LIMITS_INCLUDED_
  36 +#define _STAND_ALONE_RESOURCE_LIMITS_INCLUDED_
  37 +
  38 +#include <string>
  39 +
  40 +#include "../Include/ResourceLimits.h"
  41 +#include "../Include/visibility.h"
  42 +
  43 +// Return pointer to user-writable Resource to pass through API in
  44 +// future-proof way.
  45 +GLSLANG_EXPORT extern TBuiltInResource* GetResources();
  46 +
  47 +// These are the default resources for TBuiltInResources, used for both
  48 +// - parsing this string for the case where the user didn't supply one,
  49 +// - dumping out a template for user construction of a config file.
  50 +GLSLANG_EXPORT extern const TBuiltInResource* GetDefaultResources();
  51 +
  52 +// Returns the DefaultTBuiltInResource as a human-readable string.
  53 +GLSLANG_EXPORT std::string GetDefaultTBuiltInResourceString();
  54 +
  55 +// Decodes the resource limits from |config| to |resources|.
  56 +GLSLANG_EXPORT void DecodeResourceLimits(TBuiltInResource* resources, char* config);
  57 +
  58 +#endif // _STAND_ALONE_RESOURCE_LIMITS_INCLUDED_
  1 +//
  2 +// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
  3 +// Copyright (C) 2013-2016 LunarG, Inc.
  4 +// Copyright (C) 2015-2018 Google, Inc.
  5 +//
  6 +// All rights reserved.
  7 +//
  8 +// Redistribution and use in source and binary forms, with or without
  9 +// modification, are permitted provided that the following conditions
  10 +// are met:
  11 +//
  12 +// Redistributions of source code must retain the above copyright
  13 +// notice, this list of conditions and the following disclaimer.
  14 +//
  15 +// Redistributions in binary form must reproduce the above
  16 +// copyright notice, this list of conditions and the following
  17 +// disclaimer in the documentation and/or other materials provided
  18 +// with the distribution.
  19 +//
  20 +// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
  21 +// contributors may be used to endorse or promote products derived
  22 +// from this software without specific prior written permission.
  23 +//
  24 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  27 +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  28 +// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  29 +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  30 +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  31 +// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  32 +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33 +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  34 +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  35 +// POSSIBILITY OF SUCH DAMAGE.
  36 +//
  37 +#ifndef _COMPILER_INTERFACE_INCLUDED_
  38 +#define _COMPILER_INTERFACE_INCLUDED_
  39 +
  40 +#include "../Include/ResourceLimits.h"
  41 +#include "../Include/visibility.h"
  42 +#include "../MachineIndependent/Versions.h"
  43 +
  44 +#include <cstring>
  45 +#include <vector>
  46 +
  47 +#ifdef _WIN32
  48 + #define C_DECL __cdecl
  49 +#else
  50 + #define C_DECL
  51 +#endif
  52 +
  53 +//
  54 +// This is the platform independent interface between an OGL driver
  55 +// and the shading language compiler/linker.
  56 +//
  57 +
  58 +#ifdef __cplusplus
  59 + extern "C" {
  60 +#endif
  61 +
  62 +//
  63 +// Call before doing any other compiler/linker operations.
  64 +//
  65 +// (Call once per process, not once per thread.)
  66 +//
  67 +GLSLANG_EXPORT int ShInitialize();
  68 +
  69 +//
  70 +// Call this at process shutdown to clean up memory.
  71 +//
  72 +GLSLANG_EXPORT int ShFinalize();
  73 +
  74 +//
  75 +// Types of languages the compiler can consume.
  76 +//
  77 +typedef enum {
  78 + EShLangVertex,
  79 + EShLangTessControl,
  80 + EShLangTessEvaluation,
  81 + EShLangGeometry,
  82 + EShLangFragment,
  83 + EShLangCompute,
  84 + EShLangRayGen,
  85 + EShLangRayGenNV = EShLangRayGen,
  86 + EShLangIntersect,
  87 + EShLangIntersectNV = EShLangIntersect,
  88 + EShLangAnyHit,
  89 + EShLangAnyHitNV = EShLangAnyHit,
  90 + EShLangClosestHit,
  91 + EShLangClosestHitNV = EShLangClosestHit,
  92 + EShLangMiss,
  93 + EShLangMissNV = EShLangMiss,
  94 + EShLangCallable,
  95 + EShLangCallableNV = EShLangCallable,
  96 + EShLangTask,
  97 + EShLangTaskNV = EShLangTask,
  98 + EShLangMesh,
  99 + EShLangMeshNV = EShLangMesh,
  100 + LAST_ELEMENT_MARKER(EShLangCount),
  101 +} EShLanguage; // would be better as stage, but this is ancient now
  102 +
  103 +typedef enum : unsigned {
  104 + EShLangVertexMask = (1 << EShLangVertex),
  105 + EShLangTessControlMask = (1 << EShLangTessControl),
  106 + EShLangTessEvaluationMask = (1 << EShLangTessEvaluation),
  107 + EShLangGeometryMask = (1 << EShLangGeometry),
  108 + EShLangFragmentMask = (1 << EShLangFragment),
  109 + EShLangComputeMask = (1 << EShLangCompute),
  110 + EShLangRayGenMask = (1 << EShLangRayGen),
  111 + EShLangRayGenNVMask = EShLangRayGenMask,
  112 + EShLangIntersectMask = (1 << EShLangIntersect),
  113 + EShLangIntersectNVMask = EShLangIntersectMask,
  114 + EShLangAnyHitMask = (1 << EShLangAnyHit),
  115 + EShLangAnyHitNVMask = EShLangAnyHitMask,
  116 + EShLangClosestHitMask = (1 << EShLangClosestHit),
  117 + EShLangClosestHitNVMask = EShLangClosestHitMask,
  118 + EShLangMissMask = (1 << EShLangMiss),
  119 + EShLangMissNVMask = EShLangMissMask,
  120 + EShLangCallableMask = (1 << EShLangCallable),
  121 + EShLangCallableNVMask = EShLangCallableMask,
  122 + EShLangTaskMask = (1 << EShLangTask),
  123 + EShLangTaskNVMask = EShLangTaskMask,
  124 + EShLangMeshMask = (1 << EShLangMesh),
  125 + EShLangMeshNVMask = EShLangMeshMask,
  126 + LAST_ELEMENT_MARKER(EShLanguageMaskCount),
  127 +} EShLanguageMask;
  128 +
  129 +namespace glslang {
  130 +
  131 +class TType;
  132 +
  133 +typedef enum {
  134 + EShSourceNone,
  135 + EShSourceGlsl, // GLSL, includes ESSL (OpenGL ES GLSL)
  136 + EShSourceHlsl, // HLSL
  137 + LAST_ELEMENT_MARKER(EShSourceCount),
  138 +} EShSource; // if EShLanguage were EShStage, this could be EShLanguage instead
  139 +
  140 +typedef enum {
  141 + EShClientNone, // use when there is no client, e.g. for validation
  142 + EShClientVulkan, // as GLSL dialect, specifies KHR_vulkan_glsl extension
  143 + EShClientOpenGL, // as GLSL dialect, specifies ARB_gl_spirv extension
  144 + LAST_ELEMENT_MARKER(EShClientCount),
  145 +} EShClient;
  146 +
  147 +typedef enum {
  148 + EShTargetNone,
  149 + EShTargetSpv, // SPIR-V (preferred spelling)
  150 + EshTargetSpv = EShTargetSpv, // legacy spelling
  151 + LAST_ELEMENT_MARKER(EShTargetCount),
  152 +} EShTargetLanguage;
  153 +
  154 +typedef enum {
  155 + EShTargetVulkan_1_0 = (1 << 22), // Vulkan 1.0
  156 + EShTargetVulkan_1_1 = (1 << 22) | (1 << 12), // Vulkan 1.1
  157 + EShTargetVulkan_1_2 = (1 << 22) | (2 << 12), // Vulkan 1.2
  158 + EShTargetVulkan_1_3 = (1 << 22) | (3 << 12), // Vulkan 1.3
  159 + EShTargetVulkan_1_4 = (1 << 22) | (4 << 12), // Vulkan 1.4
  160 + EShTargetOpenGL_450 = 450, // OpenGL
  161 + LAST_ELEMENT_MARKER(EShTargetClientVersionCount = 6),
  162 +} EShTargetClientVersion;
  163 +
  164 +typedef EShTargetClientVersion EshTargetClientVersion;
  165 +
  166 +typedef enum {
  167 + EShTargetSpv_1_0 = (1 << 16), // SPIR-V 1.0
  168 + EShTargetSpv_1_1 = (1 << 16) | (1 << 8), // SPIR-V 1.1
  169 + EShTargetSpv_1_2 = (1 << 16) | (2 << 8), // SPIR-V 1.2
  170 + EShTargetSpv_1_3 = (1 << 16) | (3 << 8), // SPIR-V 1.3
  171 + EShTargetSpv_1_4 = (1 << 16) | (4 << 8), // SPIR-V 1.4
  172 + EShTargetSpv_1_5 = (1 << 16) | (5 << 8), // SPIR-V 1.5
  173 + EShTargetSpv_1_6 = (1 << 16) | (6 << 8), // SPIR-V 1.6
  174 + LAST_ELEMENT_MARKER(EShTargetLanguageVersionCount = 7),
  175 +} EShTargetLanguageVersion;
  176 +
  177 +//
  178 +// Following are a series of helper enums for managing layouts and qualifiers,
  179 +// used for TPublicType, TType, others.
  180 +//
  181 +
  182 +enum TLayoutPacking {
  183 + ElpNone,
  184 + ElpShared, // default, but different than saying nothing
  185 + ElpStd140,
  186 + ElpStd430,
  187 + ElpPacked,
  188 + ElpScalar,
  189 + ElpCount // If expanding, see bitfield width below
  190 +};
  191 +
  192 +struct TInputLanguage {
  193 + EShSource languageFamily; // redundant information with other input, this one overrides when not EShSourceNone
  194 + EShLanguage stage; // redundant information with other input, this one overrides when not EShSourceNone
  195 + EShClient dialect;
  196 + int dialectVersion; // version of client's language definition, not the client (when not EShClientNone)
  197 + bool vulkanRulesRelaxed;
  198 +};
  199 +
  200 +struct TClient {
  201 + EShClient client;
  202 + EShTargetClientVersion version; // version of client itself (not the client's input dialect)
  203 +};
  204 +
  205 +struct TTarget {
  206 + EShTargetLanguage language;
  207 + EShTargetLanguageVersion version; // version to target, if SPIR-V, defined by "word 1" of the SPIR-V header
  208 + bool hlslFunctionality1; // can target hlsl_functionality1 extension(s)
  209 +};
  210 +
  211 +// All source/client/target versions and settings.
  212 +// Can override previous methods of setting, when items are set here.
  213 +// Expected to grow, as more are added, rather than growing parameter lists.
  214 +struct TEnvironment {
  215 + TInputLanguage input; // definition of the input language
  216 + TClient client; // what client is the overall compilation being done for?
  217 + TTarget target; // what to generate
  218 +};
  219 +
  220 +GLSLANG_EXPORT const char* StageName(EShLanguage);
  221 +
  222 +} // end namespace glslang
  223 +
  224 +//
  225 +// Types of output the linker will create.
  226 +//
  227 +typedef enum {
  228 + EShExVertexFragment,
  229 + EShExFragment
  230 +} EShExecutable;
  231 +
  232 +//
  233 +// Optimization level for the compiler.
  234 +//
  235 +typedef enum {
  236 + EShOptNoGeneration,
  237 + EShOptNone,
  238 + EShOptSimple, // Optimizations that can be done quickly
  239 + EShOptFull, // Optimizations that will take more time
  240 + LAST_ELEMENT_MARKER(EshOptLevelCount),
  241 +} EShOptimizationLevel;
  242 +
  243 +//
  244 +// Texture and Sampler transformation mode.
  245 +//
  246 +typedef enum {
  247 + EShTexSampTransKeep, // keep textures and samplers as is (default)
  248 + EShTexSampTransUpgradeTextureRemoveSampler, // change texture w/o embeded sampler into sampled texture and throw away all samplers
  249 + LAST_ELEMENT_MARKER(EShTexSampTransCount),
  250 +} EShTextureSamplerTransformMode;
  251 +
  252 +//
  253 +// Message choices for what errors and warnings are given.
  254 +//
  255 +enum EShMessages : unsigned {
  256 + EShMsgDefault = 0, // default is to give all required errors and extra warnings
  257 + EShMsgRelaxedErrors = (1 << 0), // be liberal in accepting input
  258 + EShMsgSuppressWarnings = (1 << 1), // suppress all warnings, except those required by the specification
  259 + EShMsgAST = (1 << 2), // print the AST intermediate representation
  260 + EShMsgSpvRules = (1 << 3), // issue messages for SPIR-V generation
  261 + EShMsgVulkanRules = (1 << 4), // issue messages for Vulkan-requirements of GLSL for SPIR-V
  262 + EShMsgOnlyPreprocessor = (1 << 5), // only print out errors produced by the preprocessor
  263 + EShMsgReadHlsl = (1 << 6), // use HLSL parsing rules and semantics
  264 + EShMsgCascadingErrors = (1 << 7), // get cascading errors; risks error-recovery issues, instead of an early exit
  265 + EShMsgKeepUncalled = (1 << 8), // for testing, don't eliminate uncalled functions
  266 + EShMsgHlslOffsets = (1 << 9), // allow block offsets to follow HLSL rules instead of GLSL rules
  267 + EShMsgDebugInfo = (1 << 10), // save debug information
  268 + EShMsgHlslEnable16BitTypes = (1 << 11), // enable use of 16-bit types in SPIR-V for HLSL
  269 + EShMsgHlslLegalization = (1 << 12), // enable HLSL Legalization messages
  270 + EShMsgHlslDX9Compatible = (1 << 13), // enable HLSL DX9 compatible mode (for samplers and semantics)
  271 + EShMsgBuiltinSymbolTable = (1 << 14), // print the builtin symbol table
  272 + EShMsgEnhanced = (1 << 15), // enhanced message readability
  273 + EShMsgAbsolutePath = (1 << 16), // Output Absolute path for messages
  274 + EShMsgDisplayErrorColumn = (1 << 17), // Display error message column aswell as line
  275 + EShMsgLinkTimeOptimization = (1 << 18), // perform cross-stage optimizations during linking
  276 + LAST_ELEMENT_MARKER(EShMsgCount),
  277 +};
  278 +
  279 +//
  280 +// Options for building reflection
  281 +//
  282 +typedef enum {
  283 + EShReflectionDefault = 0, // default is original behaviour before options were added
  284 + EShReflectionStrictArraySuffix = (1 << 0), // reflection will follow stricter rules for array-of-structs suffixes
  285 + EShReflectionBasicArraySuffix = (1 << 1), // arrays of basic types will be appended with [0] as in GL reflection
  286 + EShReflectionIntermediateIO = (1 << 2), // reflect inputs and outputs to program, even with no vertex shader
  287 + EShReflectionSeparateBuffers = (1 << 3), // buffer variables and buffer blocks are reflected separately
  288 + EShReflectionAllBlockVariables = (1 << 4), // reflect all variables in blocks, even if they are inactive
  289 + EShReflectionUnwrapIOBlocks = (1 << 5), // unwrap input/output blocks the same as with uniform blocks
  290 + EShReflectionAllIOVariables = (1 << 6), // reflect all input/output variables, even if they are inactive
  291 + EShReflectionSharedStd140SSBO = (1 << 7), // Apply std140/shared rules for ubo to ssbo
  292 + EShReflectionSharedStd140UBO = (1 << 8), // Apply std140/shared rules for ubo to ssbo
  293 + LAST_ELEMENT_MARKER(EShReflectionCount),
  294 +} EShReflectionOptions;
  295 +
  296 +//
  297 +// Build a table for bindings. This can be used for locating
  298 +// attributes, uniforms, globals, etc., as needed.
  299 +//
  300 +typedef struct {
  301 + const char* name;
  302 + int binding;
  303 +} ShBinding;
  304 +
  305 +typedef struct {
  306 + int numBindings;
  307 + ShBinding* bindings; // array of bindings
  308 +} ShBindingTable;
  309 +
  310 +//
  311 +// ShHandle held by but opaque to the driver. It is allocated,
  312 +// managed, and de-allocated by the compiler/linker. Its contents
  313 +// are defined by and used by the compiler and linker. For example,
  314 +// symbol table information and object code passed from the compiler
  315 +// to the linker can be stored where ShHandle points.
  316 +//
  317 +// If handle creation fails, 0 will be returned.
  318 +//
  319 +typedef void* ShHandle;
  320 +
  321 +//
  322 +// Driver calls these to create and destroy compiler/linker
  323 +// objects.
  324 +//
  325 +GLSLANG_EXPORT ShHandle ShConstructCompiler(const EShLanguage, int /*debugOptions unused*/); // one per shader
  326 +GLSLANG_EXPORT ShHandle ShConstructLinker(const EShExecutable, int /*debugOptions unused*/); // one per shader pair
  327 +GLSLANG_EXPORT ShHandle ShConstructUniformMap(); // one per uniform namespace (currently entire program object)
  328 +GLSLANG_EXPORT void ShDestruct(ShHandle);
  329 +
  330 +//
  331 +// The return value of ShCompile is boolean, non-zero indicating
  332 +// success.
  333 +//
  334 +// The info-log should be written by ShCompile into
  335 +// ShHandle, so it can answer future queries.
  336 +//
  337 +GLSLANG_EXPORT int ShCompile(const ShHandle, const char* const shaderStrings[], const int numStrings,
  338 + const int* lengths, const EShOptimizationLevel, const TBuiltInResource* resources,
  339 + int, // debugOptions unused
  340 + int defaultVersion = 110, // use 100 for ES environment, overridden by #version in shader
  341 + bool forwardCompatible = false, // give errors for use of deprecated features
  342 + EShMessages messages = EShMsgDefault, // warnings and errors
  343 + const char* fileName = nullptr
  344 +);
  345 +
  346 +GLSLANG_EXPORT int ShLinkExt(
  347 + const ShHandle, // linker object
  348 + const ShHandle h[], // compiler objects to link together
  349 + const int numHandles);
  350 +
  351 +//
  352 +// ShSetEncrpytionMethod is a place-holder for specifying
  353 +// how source code is encrypted.
  354 +//
  355 +GLSLANG_EXPORT void ShSetEncryptionMethod(ShHandle);
  356 +
  357 +//
  358 +// All the following return 0 if the information is not
  359 +// available in the object passed down, or the object is bad.
  360 +//
  361 +GLSLANG_EXPORT const char* ShGetInfoLog(const ShHandle);
  362 +GLSLANG_EXPORT const void* ShGetExecutable(const ShHandle);
  363 +GLSLANG_EXPORT int ShSetVirtualAttributeBindings(const ShHandle, const ShBindingTable*); // to detect user aliasing
  364 +GLSLANG_EXPORT int ShSetFixedAttributeBindings(const ShHandle, const ShBindingTable*); // to force any physical mappings
  365 +//
  366 +// Tell the linker to never assign a vertex attribute to this list of physical attributes
  367 +//
  368 +GLSLANG_EXPORT int ShExcludeAttributes(const ShHandle, int *attributes, int count);
  369 +
  370 +//
  371 +// Returns the location ID of the named uniform.
  372 +// Returns -1 if error.
  373 +//
  374 +GLSLANG_EXPORT int ShGetUniformLocation(const ShHandle uniformMap, const char* name);
  375 +
  376 +#ifdef __cplusplus
  377 + } // end extern "C"
  378 +#endif
  379 +
  380 +////////////////////////////////////////////////////////////////////////////////////////////
  381 +//
  382 +// Deferred-Lowering C++ Interface
  383 +// -----------------------------------
  384 +//
  385 +// Below is a new alternate C++ interface, which deprecates the above
  386 +// opaque handle-based interface.
  387 +//
  388 +// The below is further designed to handle multiple compilation units per stage, where
  389 +// the intermediate results, including the parse tree, are preserved until link time,
  390 +// rather than the above interface which is designed to have each compilation unit
  391 +// lowered at compile time. In the above model, linking occurs on the lowered results,
  392 +// whereas in this model intra-stage linking can occur at the parse tree
  393 +// (treeRoot in TIntermediate) level, and then a full stage can be lowered.
  394 +//
  395 +
  396 +#include <list>
  397 +#include <string>
  398 +#include <utility>
  399 +
  400 +class TCompiler;
  401 +class TInfoSink;
  402 +
  403 +namespace glslang {
  404 +
  405 +struct Version {
  406 + int major;
  407 + int minor;
  408 + int patch;
  409 + const char* flavor;
  410 +};
  411 +
  412 +GLSLANG_EXPORT Version GetVersion();
  413 +GLSLANG_EXPORT const char* GetEsslVersionString();
  414 +GLSLANG_EXPORT const char* GetGlslVersionString();
  415 +GLSLANG_EXPORT int GetKhronosToolId();
  416 +
  417 +class TIntermediate;
  418 +class TProgram;
  419 +class TPoolAllocator;
  420 +class TIoMapResolver;
  421 +
  422 +// Call this exactly once per process before using anything else
  423 +GLSLANG_EXPORT bool InitializeProcess();
  424 +
  425 +// Call once per process to tear down everything
  426 +GLSLANG_EXPORT void FinalizeProcess();
  427 +
  428 +// Resource type for IO resolver
  429 +enum TResourceType {
  430 + EResSampler,
  431 + EResTexture,
  432 + EResImage,
  433 + EResUbo,
  434 + EResSsbo,
  435 + EResUav,
  436 + EResCount
  437 +};
  438 +
  439 +enum TBlockStorageClass
  440 +{
  441 + EbsUniform = 0,
  442 + EbsStorageBuffer,
  443 + EbsPushConstant,
  444 + EbsNone, // not a uniform or buffer variable
  445 + EbsCount,
  446 +};
  447 +
  448 +// Make one TShader per shader that you will link into a program. Then
  449 +// - provide the shader through setStrings() or setStringsWithLengths()
  450 +// - optionally call setEnv*(), see below for more detail
  451 +// - optionally use setPreamble() to set a special shader string that will be
  452 +// processed before all others but won't affect the validity of #version
  453 +// - optionally call addProcesses() for each setting/transform,
  454 +// see comment for class TProcesses
  455 +// - call parse(): source language and target environment must be selected
  456 +// either by correct setting of EShMessages sent to parse(), or by
  457 +// explicitly calling setEnv*()
  458 +// - query the info logs
  459 +//
  460 +// N.B.: Does not yet support having the same TShader instance being linked into
  461 +// multiple programs.
  462 +//
  463 +// N.B.: Destruct a linked program *before* destructing the shaders linked into it.
  464 +//
  465 +class TShader {
  466 +public:
  467 + GLSLANG_EXPORT explicit TShader(EShLanguage);
  468 + GLSLANG_EXPORT virtual ~TShader();
  469 + GLSLANG_EXPORT void setStrings(const char* const* s, int n);
  470 + GLSLANG_EXPORT void setStringsWithLengths(
  471 + const char* const* s, const int* l, int n);
  472 + GLSLANG_EXPORT void setStringsWithLengthsAndNames(
  473 + const char* const* s, const int* l, const char* const* names, int n);
  474 + void setPreamble(const char* s) { preamble = s; }
  475 + GLSLANG_EXPORT void setEntryPoint(const char* entryPoint);
  476 + GLSLANG_EXPORT void setSourceEntryPoint(const char* sourceEntryPointName);
  477 + GLSLANG_EXPORT void addProcesses(const std::vector<std::string>&);
  478 + GLSLANG_EXPORT void setUniqueId(unsigned long long id);
  479 + GLSLANG_EXPORT void setOverrideVersion(int version);
  480 + GLSLANG_EXPORT void setDebugInfo(bool debugInfo);
  481 +
  482 + // IO resolver binding data: see comments in ShaderLang.cpp
  483 + GLSLANG_EXPORT void setShiftBinding(TResourceType res, unsigned int base);
  484 + GLSLANG_EXPORT void setShiftSamplerBinding(unsigned int base); // DEPRECATED: use setShiftBinding
  485 + GLSLANG_EXPORT void setShiftTextureBinding(unsigned int base); // DEPRECATED: use setShiftBinding
  486 + GLSLANG_EXPORT void setShiftImageBinding(unsigned int base); // DEPRECATED: use setShiftBinding
  487 + GLSLANG_EXPORT void setShiftUboBinding(unsigned int base); // DEPRECATED: use setShiftBinding
  488 + GLSLANG_EXPORT void setShiftUavBinding(unsigned int base); // DEPRECATED: use setShiftBinding
  489 + GLSLANG_EXPORT void setShiftCbufferBinding(unsigned int base); // synonym for setShiftUboBinding
  490 + GLSLANG_EXPORT void setShiftSsboBinding(unsigned int base); // DEPRECATED: use setShiftBinding
  491 + GLSLANG_EXPORT void setShiftBindingForSet(TResourceType res, unsigned int base, unsigned int set);
  492 + GLSLANG_EXPORT void setResourceSetBinding(const std::vector<std::string>& base);
  493 + GLSLANG_EXPORT void setAutoMapBindings(bool map);
  494 + GLSLANG_EXPORT void setAutoMapLocations(bool map);
  495 + GLSLANG_EXPORT void addUniformLocationOverride(const char* name, int loc);
  496 + GLSLANG_EXPORT void setUniformLocationBase(int base);
  497 + GLSLANG_EXPORT void setInvertY(bool invert);
  498 + GLSLANG_EXPORT void setDxPositionW(bool dxPosW);
  499 + GLSLANG_EXPORT void setEnhancedMsgs();
  500 +#ifdef ENABLE_HLSL
  501 + GLSLANG_EXPORT void setHlslIoMapping(bool hlslIoMap);
  502 + GLSLANG_EXPORT void setFlattenUniformArrays(bool flatten);
  503 +#endif
  504 + GLSLANG_EXPORT void setNoStorageFormat(bool useUnknownFormat);
  505 + GLSLANG_EXPORT void setNanMinMaxClamp(bool nanMinMaxClamp);
  506 + GLSLANG_EXPORT void setTextureSamplerTransformMode(EShTextureSamplerTransformMode mode);
  507 + GLSLANG_EXPORT void addBlockStorageOverride(const char* nameStr, glslang::TBlockStorageClass backing);
  508 +
  509 + GLSLANG_EXPORT void setGlobalUniformBlockName(const char* name);
  510 + GLSLANG_EXPORT void setAtomicCounterBlockName(const char* name);
  511 + GLSLANG_EXPORT void setGlobalUniformSet(unsigned int set);
  512 + GLSLANG_EXPORT void setGlobalUniformBinding(unsigned int binding);
  513 + GLSLANG_EXPORT void setAtomicCounterBlockSet(unsigned int set);
  514 + GLSLANG_EXPORT void setAtomicCounterBlockBinding(unsigned int binding);
  515 +
  516 + GLSLANG_EXPORT void addSourceText(const char* text, size_t len);
  517 + GLSLANG_EXPORT void setSourceFile(const char* file);
  518 +
  519 + // For setting up the environment (cleared to nothingness in the constructor).
  520 + // These must be called so that parsing is done for the right source language and
  521 + // target environment, either indirectly through TranslateEnvironment() based on
  522 + // EShMessages et. al., or directly by the user.
  523 + //
  524 + // setEnvInput: The input source language and stage. If generating code for a
  525 + // specific client, the input client semantics to use and the
  526 + // version of that client's input semantics to use, otherwise
  527 + // use EShClientNone and version of 0, e.g. for validation mode.
  528 + // Note 'version' does not describe the target environment,
  529 + // just the version of the source dialect to compile under.
  530 + // For example, to choose the Vulkan dialect of GLSL defined by
  531 + // version 100 of the KHR_vulkan_glsl extension: lang = EShSourceGlsl,
  532 + // dialect = EShClientVulkan, and version = 100.
  533 + //
  534 + // See the definitions of TEnvironment, EShSource, EShLanguage,
  535 + // and EShClient for choices and more detail.
  536 + //
  537 + // setEnvClient: The client that will be hosting the execution, and its version.
  538 + // Note 'version' is not the version of the languages involved, but
  539 + // the version of the client environment.
  540 + // Use EShClientNone and version of 0 if there is no client, e.g.
  541 + // for validation mode.
  542 + //
  543 + // See EShTargetClientVersion for choices.
  544 + //
  545 + // setEnvTarget: The language to translate to when generating code, and that
  546 + // language's version.
  547 + // Use EShTargetNone and version of 0 if there is no client, e.g.
  548 + // for validation mode.
  549 + //
  550 + void setEnvInput(EShSource lang, EShLanguage envStage, EShClient client, int version)
  551 + {
  552 + environment.input.languageFamily = lang;
  553 + environment.input.stage = envStage;
  554 + environment.input.dialect = client;
  555 + environment.input.dialectVersion = version;
  556 + }
  557 + void setEnvClient(EShClient client, EShTargetClientVersion version)
  558 + {
  559 + environment.client.client = client;
  560 + environment.client.version = version;
  561 + }
  562 + void setEnvTarget(EShTargetLanguage lang, EShTargetLanguageVersion version)
  563 + {
  564 + environment.target.language = lang;
  565 + environment.target.version = version;
  566 + }
  567 +
  568 + void getStrings(const char* const* &s, int& n) { s = strings; n = numStrings; }
  569 +
  570 +#ifdef ENABLE_HLSL
  571 + void setEnvTargetHlslFunctionality1() { environment.target.hlslFunctionality1 = true; }
  572 + bool getEnvTargetHlslFunctionality1() const { return environment.target.hlslFunctionality1; }
  573 +#else
  574 + bool getEnvTargetHlslFunctionality1() const { return false; }
  575 +#endif
  576 +
  577 + void setEnvInputVulkanRulesRelaxed() { environment.input.vulkanRulesRelaxed = true; }
  578 + bool getEnvInputVulkanRulesRelaxed() const { return environment.input.vulkanRulesRelaxed; }
  579 +
  580 + void setCompileOnly() { compileOnly = true; }
  581 + bool getCompileOnly() const { return compileOnly; }
  582 +
  583 + // Interface to #include handlers.
  584 + //
  585 + // To support #include, a client of Glslang does the following:
  586 + // 1. Call setStringsWithNames to set the source strings and associated
  587 + // names. For example, the names could be the names of the files
  588 + // containing the shader sources.
  589 + // 2. Call parse with an Includer.
  590 + //
  591 + // When the Glslang parser encounters an #include directive, it calls
  592 + // the Includer's include method with the requested include name
  593 + // together with the current string name. The returned IncludeResult
  594 + // contains the fully resolved name of the included source, together
  595 + // with the source text that should replace the #include directive
  596 + // in the source stream. After parsing that source, Glslang will
  597 + // release the IncludeResult object.
  598 + class Includer {
  599 + public:
  600 + // An IncludeResult contains the resolved name and content of a source
  601 + // inclusion.
  602 + struct IncludeResult {
  603 + IncludeResult(const std::string& headerName, const char* const headerData, const size_t headerLength, void* userData) :
  604 + headerName(headerName), headerData(headerData), headerLength(headerLength), userData(userData) { }
  605 + // For a successful inclusion, the fully resolved name of the requested
  606 + // include. For example, in a file system-based includer, full resolution
  607 + // should convert a relative path name into an absolute path name.
  608 + // For a failed inclusion, this is an empty string.
  609 + const std::string headerName;
  610 + // The content and byte length of the requested inclusion. The
  611 + // Includer producing this IncludeResult retains ownership of the
  612 + // storage.
  613 + // For a failed inclusion, the header
  614 + // field points to a string containing error details.
  615 + const char* const headerData;
  616 + const size_t headerLength;
  617 + // Include resolver's context.
  618 + void* userData;
  619 + protected:
  620 + IncludeResult& operator=(const IncludeResult&);
  621 + IncludeResult();
  622 + };
  623 +
  624 + // For both include methods below:
  625 + //
  626 + // Resolves an inclusion request by name, current source name,
  627 + // and include depth.
  628 + // On success, returns an IncludeResult containing the resolved name
  629 + // and content of the include.
  630 + // On failure, returns a nullptr, or an IncludeResult
  631 + // with an empty string for the headerName and error details in the
  632 + // header field.
  633 + // The Includer retains ownership of the contents
  634 + // of the returned IncludeResult value, and those contents must
  635 + // remain valid until the releaseInclude method is called on that
  636 + // IncludeResult object.
  637 + //
  638 + // Note "local" vs. "system" is not an "either/or": "local" is an
  639 + // extra thing to do over "system". Both might get called, as per
  640 + // the C++ specification.
  641 +
  642 + // For the "system" or <>-style includes; search the "system" paths.
  643 + virtual IncludeResult* includeSystem(const char* /*headerName*/,
  644 + const char* /*includerName*/,
  645 + size_t /*inclusionDepth*/) { return nullptr; }
  646 +
  647 + // For the "local"-only aspect of a "" include. Should not search in the
  648 + // "system" paths, because on returning a failure, the parser will
  649 + // call includeSystem() to look in the "system" locations.
  650 + virtual IncludeResult* includeLocal(const char* /*headerName*/,
  651 + const char* /*includerName*/,
  652 + size_t /*inclusionDepth*/) { return nullptr; }
  653 +
  654 + // Signals that the parser will no longer use the contents of the
  655 + // specified IncludeResult.
  656 + virtual void releaseInclude(IncludeResult*) = 0;
  657 + virtual ~Includer() {}
  658 + };
  659 +
  660 + // Fail all Includer searches
  661 + class ForbidIncluder : public Includer {
  662 + public:
  663 + virtual void releaseInclude(IncludeResult*) override { }
  664 + };
  665 +
  666 + GLSLANG_EXPORT bool parse(
  667 + const TBuiltInResource*, int defaultVersion, EProfile defaultProfile,
  668 + bool forceDefaultVersionAndProfile, bool forwardCompatible,
  669 + EShMessages, Includer&);
  670 +
  671 + bool parse(const TBuiltInResource* res, int defaultVersion, EProfile defaultProfile, bool forceDefaultVersionAndProfile,
  672 + bool forwardCompatible, EShMessages messages)
  673 + {
  674 + TShader::ForbidIncluder includer;
  675 + return parse(res, defaultVersion, defaultProfile, forceDefaultVersionAndProfile, forwardCompatible, messages, includer);
  676 + }
  677 +
  678 + // Equivalent to parse() without a default profile and without forcing defaults.
  679 + bool parse(const TBuiltInResource* builtInResources, int defaultVersion, bool forwardCompatible, EShMessages messages)
  680 + {
  681 + return parse(builtInResources, defaultVersion, ENoProfile, false, forwardCompatible, messages);
  682 + }
  683 +
  684 + bool parse(const TBuiltInResource* builtInResources, int defaultVersion, bool forwardCompatible, EShMessages messages,
  685 + Includer& includer)
  686 + {
  687 + return parse(builtInResources, defaultVersion, ENoProfile, false, forwardCompatible, messages, includer);
  688 + }
  689 +
  690 + // NOTE: Doing just preprocessing to obtain a correct preprocessed shader string
  691 + // is not an officially supported or fully working path.
  692 + GLSLANG_EXPORT bool preprocess(
  693 + const TBuiltInResource* builtInResources, int defaultVersion,
  694 + EProfile defaultProfile, bool forceDefaultVersionAndProfile,
  695 + bool forwardCompatible, EShMessages message, std::string* outputString,
  696 + Includer& includer);
  697 +
  698 + GLSLANG_EXPORT const char* getInfoLog();
  699 + GLSLANG_EXPORT const char* getInfoDebugLog();
  700 + EShLanguage getStage() const { return stage; }
  701 + TIntermediate* getIntermediate() const { return intermediate; }
  702 +
  703 +protected:
  704 + TPoolAllocator* pool;
  705 + EShLanguage stage;
  706 + TCompiler* compiler;
  707 + TIntermediate* intermediate;
  708 + TInfoSink* infoSink;
  709 + // strings and lengths follow the standard for glShaderSource:
  710 + // strings is an array of numStrings pointers to string data.
  711 + // lengths can be null, but if not it is an array of numStrings
  712 + // integers containing the length of the associated strings.
  713 + // if lengths is null or lengths[n] < 0 the associated strings[n] is
  714 + // assumed to be null-terminated.
  715 + // stringNames is the optional names for all the strings. If stringNames
  716 + // is null, then none of the strings has name. If a certain element in
  717 + // stringNames is null, then the corresponding string does not have name.
  718 + const char* const* strings; // explicit code to compile, see previous comment
  719 + const int* lengths;
  720 + const char* const* stringNames;
  721 + int numStrings; // size of the above arrays
  722 + const char* preamble; // string of implicit code to compile before the explicitly provided code
  723 +
  724 + // a function in the source string can be renamed FROM this TO the name given in setEntryPoint.
  725 + std::string sourceEntryPointName;
  726 +
  727 + // overrides #version in shader source or default version if #version isn't present
  728 + int overrideVersion;
  729 +
  730 + TEnvironment environment;
  731 +
  732 + // Indicates this shader is meant to be used without linking
  733 + bool compileOnly = false;
  734 +
  735 + friend class TProgram;
  736 +
  737 +private:
  738 + TShader& operator=(TShader&);
  739 +};
  740 +
  741 +//
  742 +// A reflection database and its interface, consistent with the OpenGL API reflection queries.
  743 +//
  744 +
  745 +// Data needed for just a single object at the granularity exchanged by the reflection API
  746 +class TObjectReflection {
  747 +public:
  748 + GLSLANG_EXPORT TObjectReflection(const std::string& pName, const TType& pType, int pOffset, int pGLDefineType, int pSize, int pIndex);
  749 +
  750 + const TType* getType() const { return type; }
  751 + GLSLANG_EXPORT int getBinding() const;
  752 + GLSLANG_EXPORT void dump() const;
  753 + static TObjectReflection badReflection() { return TObjectReflection(); }
  754 +
  755 + GLSLANG_EXPORT unsigned int layoutLocation() const;
  756 +
  757 + std::string name;
  758 + int offset;
  759 + int glDefineType;
  760 + int size; // data size in bytes for a block, array size for a (non-block) object that's an array
  761 + int index;
  762 + int counterIndex;
  763 + int numMembers;
  764 + int arrayStride; // stride of an array variable
  765 + int topLevelArraySize; // size of the top-level variable in a storage buffer member
  766 + int topLevelArrayStride; // stride of the top-level variable in a storage buffer member
  767 + EShLanguageMask stages;
  768 +
  769 +protected:
  770 + TObjectReflection()
  771 + : offset(-1), glDefineType(-1), size(-1), index(-1), counterIndex(-1), numMembers(-1), arrayStride(0),
  772 + topLevelArrayStride(0), stages(EShLanguageMask(0)), type(nullptr)
  773 + {
  774 + }
  775 +
  776 + const TType* type;
  777 +};
  778 +
  779 +class TReflection;
  780 +class TIoMapper;
  781 +struct TVarEntryInfo;
  782 +
  783 +// Allows to customize the binding layout after linking.
  784 +// All used uniform variables will invoke at least validateBinding.
  785 +// If validateBinding returned true then the other resolveBinding,
  786 +// resolveSet, and resolveLocation are invoked to resolve the binding
  787 +// and descriptor set index respectively.
  788 +//
  789 +// Invocations happen in a particular order:
  790 +// 1) all shader inputs
  791 +// 2) all shader outputs
  792 +// 3) all uniforms with binding and set already defined
  793 +// 4) all uniforms with binding but no set defined
  794 +// 5) all uniforms with set but no binding defined
  795 +// 6) all uniforms with no binding and no set defined
  796 +//
  797 +// mapIO will use this resolver in two phases. The first
  798 +// phase is a notification phase, calling the corresponging
  799 +// notifiy callbacks, this phase ends with a call to endNotifications.
  800 +// Phase two starts directly after the call to endNotifications
  801 +// and calls all other callbacks to validate and to get the
  802 +// bindings, sets, locations, component and color indices.
  803 +//
  804 +// NOTE: that still limit checks are applied to bindings and sets
  805 +// and may result in an error.
  806 +class TIoMapResolver
  807 +{
  808 +public:
  809 + virtual ~TIoMapResolver() {}
  810 +
  811 + // Should return true if the resulting/current binding would be okay.
  812 + // Basic idea is to do aliasing binding checks with this.
  813 + virtual bool validateBinding(EShLanguage stage, TVarEntryInfo& ent) = 0;
  814 + // Should return a value >= 0 if the current binding should be overridden.
  815 + // Return -1 if the current binding (including no binding) should be kept.
  816 + virtual int resolveBinding(EShLanguage stage, TVarEntryInfo& ent) = 0;
  817 + // Should return a value >= 0 if the current set should be overridden.
  818 + // Return -1 if the current set (including no set) should be kept.
  819 + virtual int resolveSet(EShLanguage stage, TVarEntryInfo& ent) = 0;
  820 + // Should return a value >= 0 if the current location should be overridden.
  821 + // Return -1 if the current location (including no location) should be kept.
  822 + virtual int resolveUniformLocation(EShLanguage stage, TVarEntryInfo& ent) = 0;
  823 + // Should return true if the resulting/current setup would be okay.
  824 + // Basic idea is to do aliasing checks and reject invalid semantic names.
  825 + virtual bool validateInOut(EShLanguage stage, TVarEntryInfo& ent) = 0;
  826 + // Should return a value >= 0 if the current location should be overridden.
  827 + // Return -1 if the current location (including no location) should be kept.
  828 + virtual int resolveInOutLocation(EShLanguage stage, TVarEntryInfo& ent) = 0;
  829 + // Should return a value >= 0 if the current component index should be overridden.
  830 + // Return -1 if the current component index (including no index) should be kept.
  831 + virtual int resolveInOutComponent(EShLanguage stage, TVarEntryInfo& ent) = 0;
  832 + // Should return a value >= 0 if the current color index should be overridden.
  833 + // Return -1 if the current color index (including no index) should be kept.
  834 + virtual int resolveInOutIndex(EShLanguage stage, TVarEntryInfo& ent) = 0;
  835 + // Notification of a uniform variable
  836 + virtual void notifyBinding(EShLanguage stage, TVarEntryInfo& ent) = 0;
  837 + // Notification of a in or out variable
  838 + virtual void notifyInOut(EShLanguage stage, TVarEntryInfo& ent) = 0;
  839 + // Called by mapIO when it starts its notify pass for the given stage
  840 + virtual void beginNotifications(EShLanguage stage) = 0;
  841 + // Called by mapIO when it has finished the notify pass
  842 + virtual void endNotifications(EShLanguage stage) = 0;
  843 + // Called by mipIO when it starts its resolve pass for the given stage
  844 + virtual void beginResolve(EShLanguage stage) = 0;
  845 + // Called by mapIO when it has finished the resolve pass
  846 + virtual void endResolve(EShLanguage stage) = 0;
  847 + // Called by mapIO when it starts its symbol collect for teh given stage
  848 + virtual void beginCollect(EShLanguage stage) = 0;
  849 + // Called by mapIO when it has finished the symbol collect
  850 + virtual void endCollect(EShLanguage stage) = 0;
  851 + // Called by TSlotCollector to resolve storage locations or bindings
  852 + virtual void reserverStorageSlot(TVarEntryInfo& ent, TInfoSink& infoSink) = 0;
  853 + // Called by TSlotCollector to resolve resource locations or bindings
  854 + virtual void reserverResourceSlot(TVarEntryInfo& ent, TInfoSink& infoSink) = 0;
  855 + // Called by mapIO.addStage to set shader stage mask to mark a stage be added to this pipeline
  856 + virtual void addStage(EShLanguage stage, TIntermediate& stageIntermediate) = 0;
  857 +};
  858 +
  859 +// I/O mapper
  860 +class TIoMapper {
  861 +public:
  862 + TIoMapper() {}
  863 + virtual ~TIoMapper() {}
  864 + // grow the reflection stage by stage
  865 + bool virtual addStage(EShLanguage, TIntermediate&, TInfoSink&, TIoMapResolver*);
  866 + bool virtual doMap(TIoMapResolver*, TInfoSink&) { return true; }
  867 + bool virtual setAutoPushConstantBlock(const char*, unsigned int, TLayoutPacking) { return false; }
  868 +};
  869 +
  870 +// Get the default GLSL IO mapper
  871 +GLSLANG_EXPORT TIoMapper* GetGlslIoMapper();
  872 +
  873 +// Make one TProgram per set of shaders that will get linked together. Add all
  874 +// the shaders that are to be linked together. After calling shader.parse()
  875 +// for all shaders, call link().
  876 +//
  877 +// N.B.: Destruct a linked program *before* destructing the shaders linked into it.
  878 +//
  879 +class TProgram {
  880 +public:
  881 + GLSLANG_EXPORT TProgram();
  882 + GLSLANG_EXPORT virtual ~TProgram();
  883 + void addShader(TShader* shader) { stages[shader->stage].push_back(shader); }
  884 + std::list<TShader*>& getShaders(EShLanguage stage) { return stages[stage]; }
  885 + // Link Validation interface
  886 + GLSLANG_EXPORT bool link(EShMessages);
  887 + GLSLANG_EXPORT const char* getInfoLog();
  888 + GLSLANG_EXPORT const char* getInfoDebugLog();
  889 +
  890 + TIntermediate* getIntermediate(EShLanguage stage) const { return intermediate[stage]; }
  891 +
  892 + // Reflection Interface
  893 +
  894 + // call first, to do liveness analysis, index mapping, etc.; returns false on failure
  895 + GLSLANG_EXPORT bool buildReflection(int opts = EShReflectionDefault);
  896 + GLSLANG_EXPORT unsigned getLocalSize(int dim) const; // return dim'th local size
  897 + GLSLANG_EXPORT int getReflectionIndex(const char *name) const;
  898 + GLSLANG_EXPORT int getReflectionPipeIOIndex(const char* name, const bool inOrOut) const;
  899 + GLSLANG_EXPORT int getNumUniformVariables() const;
  900 + GLSLANG_EXPORT const TObjectReflection& getUniform(int index) const;
  901 + GLSLANG_EXPORT int getNumUniformBlocks() const;
  902 + GLSLANG_EXPORT const TObjectReflection& getUniformBlock(int index) const;
  903 + GLSLANG_EXPORT int getNumPipeInputs() const;
  904 + GLSLANG_EXPORT const TObjectReflection& getPipeInput(int index) const;
  905 + GLSLANG_EXPORT int getNumPipeOutputs() const;
  906 + GLSLANG_EXPORT const TObjectReflection& getPipeOutput(int index) const;
  907 + GLSLANG_EXPORT int getNumBufferVariables() const;
  908 + GLSLANG_EXPORT const TObjectReflection& getBufferVariable(int index) const;
  909 + GLSLANG_EXPORT int getNumBufferBlocks() const;
  910 + GLSLANG_EXPORT const TObjectReflection& getBufferBlock(int index) const;
  911 + GLSLANG_EXPORT int getNumAtomicCounters() const;
  912 + GLSLANG_EXPORT const TObjectReflection& getAtomicCounter(int index) const;
  913 +
  914 + // Legacy Reflection Interface - expressed in terms of above interface
  915 +
  916 + // can be used for glGetProgramiv(GL_ACTIVE_UNIFORMS)
  917 + int getNumLiveUniformVariables() const { return getNumUniformVariables(); }
  918 +
  919 + // can be used for glGetProgramiv(GL_ACTIVE_UNIFORM_BLOCKS)
  920 + int getNumLiveUniformBlocks() const { return getNumUniformBlocks(); }
  921 +
  922 + // can be used for glGetProgramiv(GL_ACTIVE_ATTRIBUTES)
  923 + int getNumLiveAttributes() const { return getNumPipeInputs(); }
  924 +
  925 + // can be used for glGetUniformIndices()
  926 + int getUniformIndex(const char *name) const { return getReflectionIndex(name); }
  927 +
  928 + int getPipeIOIndex(const char *name, const bool inOrOut) const
  929 + { return getReflectionPipeIOIndex(name, inOrOut); }
  930 +
  931 + // can be used for "name" part of glGetActiveUniform()
  932 + const char *getUniformName(int index) const { return getUniform(index).name.c_str(); }
  933 +
  934 + // returns the binding number
  935 + int getUniformBinding(int index) const { return getUniform(index).getBinding(); }
  936 +
  937 + // returns Shaders Stages where a Uniform is present
  938 + EShLanguageMask getUniformStages(int index) const { return getUniform(index).stages; }
  939 +
  940 + // can be used for glGetActiveUniformsiv(GL_UNIFORM_BLOCK_INDEX)
  941 + int getUniformBlockIndex(int index) const { return getUniform(index).index; }
  942 +
  943 + // can be used for glGetActiveUniformsiv(GL_UNIFORM_TYPE)
  944 + int getUniformType(int index) const { return getUniform(index).glDefineType; }
  945 +
  946 + // can be used for glGetActiveUniformsiv(GL_UNIFORM_OFFSET)
  947 + int getUniformBufferOffset(int index) const { return getUniform(index).offset; }
  948 +
  949 + // can be used for glGetActiveUniformsiv(GL_UNIFORM_SIZE)
  950 + int getUniformArraySize(int index) const { return getUniform(index).size; }
  951 +
  952 + // returns a TType*
  953 + const TType *getUniformTType(int index) const { return getUniform(index).getType(); }
  954 +
  955 + // can be used for glGetActiveUniformBlockName()
  956 + const char *getUniformBlockName(int index) const { return getUniformBlock(index).name.c_str(); }
  957 +
  958 + // can be used for glGetActiveUniformBlockiv(UNIFORM_BLOCK_DATA_SIZE)
  959 + int getUniformBlockSize(int index) const { return getUniformBlock(index).size; }
  960 +
  961 + // returns the block binding number
  962 + int getUniformBlockBinding(int index) const { return getUniformBlock(index).getBinding(); }
  963 +
  964 + // returns block index of associated counter.
  965 + int getUniformBlockCounterIndex(int index) const { return getUniformBlock(index).counterIndex; }
  966 +
  967 + // returns a TType*
  968 + const TType *getUniformBlockTType(int index) const { return getUniformBlock(index).getType(); }
  969 +
  970 + // can be used for glGetActiveAttrib()
  971 + const char *getAttributeName(int index) const { return getPipeInput(index).name.c_str(); }
  972 +
  973 + // can be used for glGetActiveAttrib()
  974 + int getAttributeType(int index) const { return getPipeInput(index).glDefineType; }
  975 +
  976 + // returns a TType*
  977 + const TType *getAttributeTType(int index) const { return getPipeInput(index).getType(); }
  978 +
  979 + GLSLANG_EXPORT void dumpReflection();
  980 +
  981 + // Get the IO resolver to use for mapIO
  982 + GLSLANG_EXPORT TIoMapResolver* getGlslIoResolver(EShLanguage stage);
  983 +
  984 + // I/O mapping: apply base offsets and map live unbound variables
  985 + // If resolver is not provided it uses the previous approach
  986 + // and respects auto assignment and offsets.
  987 + GLSLANG_EXPORT bool mapIO(TIoMapResolver* pResolver = nullptr, TIoMapper* pIoMapper = nullptr);
  988 +
  989 +protected:
  990 + GLSLANG_EXPORT bool linkStage(EShLanguage, EShMessages);
  991 + GLSLANG_EXPORT bool crossStageCheck(EShMessages);
  992 +
  993 + TPoolAllocator* pool;
  994 + std::list<TShader*> stages[EShLangCount];
  995 + TIntermediate* intermediate[EShLangCount];
  996 + bool newedIntermediate[EShLangCount]; // track which intermediate were "new" versus reusing a singleton unit in a stage
  997 + TInfoSink* infoSink;
  998 + TReflection* reflection;
  999 + bool linked;
  1000 +
  1001 +private:
  1002 + TProgram(TProgram&);
  1003 + TProgram& operator=(TProgram&);
  1004 +};
  1005 +
  1006 +} // end namespace glslang
  1007 +
  1008 +#endif // _COMPILER_INTERFACE_INCLUDED_
  1 +/**
  2 +BSD 2-Clause License
  3 +
  4 +Copyright (c) 2020, Travis Fort
  5 +All rights reserved.
  6 +
  7 +Redistribution and use in source and binary forms, with or without
  8 +modification, are permitted provided that the following conditions are met:
  9 +
  10 +1. Redistributions of source code must retain the above copyright notice, this
  11 + list of conditions and the following disclaimer.
  12 +
  13 +2. Redistributions in binary form must reproduce the above copyright notice,
  14 + this list of conditions and the following disclaimer in the documentation
  15 + and/or other materials provided with the distribution.
  16 +
  17 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  18 +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20 +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  21 +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22 +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  23 +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24 +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  25 +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27 +**/
  28 +
  29 +#ifndef _STAND_ALONE_RESOURCE_LIMITS_C_INCLUDED_
  30 +#define _STAND_ALONE_RESOURCE_LIMITS_C_INCLUDED_
  31 +
  32 +#include "../Include/glslang_c_interface.h"
  33 +#include "../Include/visibility.h"
  34 +
  35 +#ifdef __cplusplus
  36 +extern "C" {
  37 +#endif
  38 +
  39 +// Returns a struct that can be use to create custom resource values.
  40 +GLSLANG_EXPORT glslang_resource_t* glslang_resource(void);
  41 +
  42 +// These are the default resources for TBuiltInResources, used for both
  43 +// - parsing this string for the case where the user didn't supply one,
  44 +// - dumping out a template for user construction of a config file.
  45 +GLSLANG_EXPORT const glslang_resource_t* glslang_default_resource(void);
  46 +
  47 +// Returns the DefaultTBuiltInResource as a human-readable string.
  48 +// NOTE: User is responsible for freeing this string.
  49 +GLSLANG_EXPORT const char* glslang_default_resource_string();
  50 +
  51 +// Decodes the resource limits from |config| to |resources|.
  52 +GLSLANG_EXPORT void glslang_decode_resource_limits(glslang_resource_t* resources, char* config);
  53 +
  54 +#ifdef __cplusplus
  55 +}
  56 +#endif
  57 +
  58 +#endif // _STAND_ALONE_RESOURCE_LIMITS_C_INCLUDED_
  1 +//
  2 +// Copyright (C) 2014 LunarG, Inc.
  3 +// Copyright (C) 2015-2018 Google, Inc.
  4 +//
  5 +// All rights reserved.
  6 +//
  7 +// Redistribution and use in source and binary forms, with or without
  8 +// modification, are permitted provided that the following conditions
  9 +// are met:
  10 +//
  11 +// Redistributions of source code must retain the above copyright
  12 +// notice, this list of conditions and the following disclaimer.
  13 +//
  14 +// Redistributions in binary form must reproduce the above
  15 +// copyright notice, this list of conditions and the following
  16 +// disclaimer in the documentation and/or other materials provided
  17 +// with the distribution.
  18 +//
  19 +// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
  20 +// contributors may be used to endorse or promote products derived
  21 +// from this software without specific prior written permission.
  22 +//
  23 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  26 +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  27 +// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  28 +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  29 +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  30 +// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31 +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32 +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  33 +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34 +// POSSIBILITY OF SUCH DAMAGE.
  35 +
  36 +#pragma once
  37 +
  38 +#include <string>
  39 +#include <vector>
  40 +
  41 +#include "Logger.h"
  42 +#include "glslang/Include/visibility.h"
  43 +
  44 +namespace glslang {
  45 +class TIntermediate;
  46 +
  47 +struct SpvOptions {
  48 + bool generateDebugInfo {false};
  49 + bool stripDebugInfo {false};
  50 + bool disableOptimizer {true};
  51 + bool optimizeSize {false};
  52 + bool disassemble {false};
  53 + bool validate {false};
  54 + bool emitNonSemanticShaderDebugInfo {false};
  55 + bool emitNonSemanticShaderDebugSource{ false };
  56 + bool compileOnly{false};
  57 + bool optimizerAllowExpandedIDBound{false};
  58 +};
  59 +
  60 +GLSLANG_EXPORT void GetSpirvVersion(std::string&);
  61 +GLSLANG_EXPORT int GetSpirvGeneratorVersion();
  62 +GLSLANG_EXPORT void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
  63 + SpvOptions* options = nullptr);
  64 +GLSLANG_EXPORT void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
  65 + spv::SpvBuildLogger* logger, SpvOptions* options = nullptr);
  66 +GLSLANG_EXPORT bool OutputSpvBin(const std::vector<unsigned int>& spirv, const char* baseName);
  67 +GLSLANG_EXPORT bool OutputSpvHex(const std::vector<unsigned int>& spirv, const char* baseName, const char* varName);
  68 +
  69 +}
  1 +//
  2 +// Copyright (C) 2016 Google, Inc.
  3 +//
  4 +// All rights reserved.
  5 +//
  6 +// Redistribution and use in source and binary forms, with or without
  7 +// modification, are permitted provided that the following conditions
  8 +// are met:
  9 +//
  10 +// Redistributions of source code must retain the above copyright
  11 +// notice, this list of conditions and the following disclaimer.
  12 +//
  13 +// Redistributions in binary form must reproduce the above
  14 +// copyright notice, this list of conditions and the following
  15 +// disclaimer in the documentation and/or other materials provided
  16 +// with the distribution.
  17 +//
  18 +// Neither the name of Google Inc. nor the names of its
  19 +// contributors may be used to endorse or promote products derived
  20 +// from this software without specific prior written permission.
  21 +//
  22 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25 +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  26 +// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27 +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28 +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29 +// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  30 +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31 +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  32 +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33 +// POSSIBILITY OF SUCH DAMAGE.
  34 +
  35 +#ifndef GLSLANG_SPIRV_LOGGER_H
  36 +#define GLSLANG_SPIRV_LOGGER_H
  37 +
  38 +#include <string>
  39 +#include <vector>
  40 +#include "glslang/Include/visibility.h"
  41 +
  42 +namespace spv {
  43 +
  44 +// A class for holding all SPIR-V build status messages, including
  45 +// missing/TBD functionalities, warnings, and errors.
  46 +class GLSLANG_EXPORT SpvBuildLogger {
  47 +public:
  48 + SpvBuildLogger() {}
  49 +
  50 + // Registers a TBD functionality.
  51 + void tbdFunctionality(const std::string& f);
  52 + // Registers a missing functionality.
  53 + void missingFunctionality(const std::string& f);
  54 +
  55 + // Logs a warning.
  56 + void warning(const std::string& w) { warnings.push_back(w); }
  57 + // Logs an error.
  58 + void error(const std::string& e) { errors.push_back(e); }
  59 +
  60 + // Returns all messages accumulated in the order of:
  61 + // TBD functionalities, missing functionalities, warnings, errors.
  62 + std::string getAllMessages() const;
  63 +
  64 +private:
  65 + SpvBuildLogger(const SpvBuildLogger&);
  66 +
  67 + std::vector<std::string> tbdFeatures;
  68 + std::vector<std::string> missingFeatures;
  69 + std::vector<std::string> warnings;
  70 + std::vector<std::string> errors;
  71 +};
  72 +
  73 +} // end spv namespace
  74 +
  75 +#endif // GLSLANG_SPIRV_LOGGER_H
  1 +//
  2 +// Copyright (C) 2015 LunarG, Inc.
  3 +//
  4 +// All rights reserved.
  5 +//
  6 +// Redistribution and use in source and binary forms, with or without
  7 +// modification, are permitted provided that the following conditions
  8 +// are met:
  9 +//
  10 +// Redistributions of source code must retain the above copyright
  11 +// notice, this list of conditions and the following disclaimer.
  12 +//
  13 +// Redistributions in binary form must reproduce the above
  14 +// copyright notice, this list of conditions and the following
  15 +// disclaimer in the documentation and/or other materials provided
  16 +// with the distribution.
  17 +//
  18 +// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
  19 +// contributors may be used to endorse or promote products derived
  20 +// from this software without specific prior written permission.
  21 +//
  22 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25 +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  26 +// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27 +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28 +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29 +// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  30 +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31 +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  32 +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33 +// POSSIBILITY OF SUCH DAMAGE.
  34 +//
  35 +
  36 +#ifndef SPIRVREMAPPER_H
  37 +#define SPIRVREMAPPER_H
  38 +
  39 +#include <string>
  40 +#include <vector>
  41 +#include <cstdlib>
  42 +#include <exception>
  43 +
  44 +#ifdef GLSLANG_IS_SHARED_LIBRARY
  45 + #ifdef _WIN32
  46 + #ifdef GLSLANG_EXPORTING
  47 + #define GLSLANG_EXPORT __declspec(dllexport)
  48 + #else
  49 + #define GLSLANG_EXPORT __declspec(dllimport)
  50 + #endif
  51 + #elif __GNUC__ >= 4
  52 + #define GLSLANG_EXPORT __attribute__((visibility("default")))
  53 + #endif
  54 +#endif // GLSLANG_IS_SHARED_LIBRARY
  55 +#ifndef GLSLANG_EXPORT
  56 +#define GLSLANG_EXPORT
  57 +#endif
  58 +
  59 +namespace spv {
  60 +
  61 +class spirvbin_base_t
  62 +{
  63 +public:
  64 + enum Options {
  65 + NONE = 0,
  66 + STRIP = (1<<0),
  67 + MAP_TYPES = (1<<1),
  68 + MAP_NAMES = (1<<2),
  69 + MAP_FUNCS = (1<<3),
  70 + DCE_FUNCS = (1<<4),
  71 + DCE_VARS = (1<<5),
  72 + DCE_TYPES = (1<<6),
  73 + OPT_LOADSTORE = (1<<7),
  74 + OPT_FWD_LS = (1<<8), // EXPERIMENTAL: PRODUCES INVALID SCHEMA-0 SPIRV
  75 + MAP_ALL = (MAP_TYPES | MAP_NAMES | MAP_FUNCS),
  76 + DCE_ALL = (DCE_FUNCS | DCE_VARS | DCE_TYPES),
  77 + OPT_ALL = (OPT_LOADSTORE),
  78 +
  79 + ALL_BUT_STRIP = (MAP_ALL | DCE_ALL | OPT_ALL),
  80 + DO_EVERYTHING = (STRIP | ALL_BUT_STRIP)
  81 + };
  82 +};
  83 +
  84 +} // namespace SPV
  85 +
  86 +#include <functional>
  87 +#include <cstdint>
  88 +#include <unordered_map>
  89 +#include <unordered_set>
  90 +#include <map>
  91 +#include <set>
  92 +#include <cassert>
  93 +
  94 +#include "spirv.hpp"
  95 +
  96 +namespace spv {
  97 +
  98 +static inline constexpr Id NoResult = 0;
  99 +
  100 +// class to hold SPIR-V binary data for remapping, DCE, and debug stripping
  101 +class GLSLANG_EXPORT spirvbin_t : public spirvbin_base_t
  102 +{
  103 +public:
  104 + spirvbin_t(int verbose = 0) : entryPoint(spv::NoResult), largestNewId(0), verbose(verbose), errorLatch(false)
  105 + { }
  106 +
  107 + virtual ~spirvbin_t() { }
  108 +
  109 + // remap on an existing binary in memory
  110 + void remap(std::vector<std::uint32_t>& spv, const std::vector<std::string>& whiteListStrings,
  111 + std::uint32_t opts = DO_EVERYTHING);
  112 +
  113 + // remap on an existing binary in memory - legacy interface without white list
  114 + void remap(std::vector<std::uint32_t>& spv, std::uint32_t opts = DO_EVERYTHING);
  115 +
  116 + // Type for error/log handler functions
  117 + typedef std::function<void(const std::string&)> errorfn_t;
  118 + typedef std::function<void(const std::string&)> logfn_t;
  119 +
  120 + // Register error/log handling functions (can be lambda fn / functor / etc)
  121 + static void registerErrorHandler(errorfn_t handler) { errorHandler = handler; }
  122 + static void registerLogHandler(logfn_t handler) { logHandler = handler; }
  123 +
  124 +protected:
  125 + // This can be overridden to provide other message behavior if needed
  126 + virtual void msg(int minVerbosity, int indent, const std::string& txt) const;
  127 +
  128 +private:
  129 + // Local to global, or global to local ID map
  130 + typedef std::unordered_map<spv::Id, spv::Id> idmap_t;
  131 + typedef std::unordered_set<spv::Id> idset_t;
  132 + typedef std::unordered_map<spv::Id, int> blockmap_t;
  133 +
  134 + void remap(std::uint32_t opts = DO_EVERYTHING);
  135 +
  136 + // Map of names to IDs
  137 + typedef std::unordered_map<std::string, spv::Id> namemap_t;
  138 +
  139 + typedef std::uint32_t spirword_t;
  140 +
  141 + typedef std::pair<unsigned, unsigned> range_t;
  142 + typedef std::function<void(spv::Id&)> idfn_t;
  143 + typedef std::function<bool(spv::Op, unsigned start)> instfn_t;
  144 +
  145 + // Special Values for ID map:
  146 + static const spv::Id unmapped; // unchanged from default value
  147 + static const spv::Id unused; // unused ID
  148 + static const int header_size; // SPIR header = 5 words
  149 +
  150 + class id_iterator_t;
  151 +
  152 + // For mapping type entries between different shaders
  153 + typedef std::vector<spirword_t> typeentry_t;
  154 + typedef std::map<spv::Id, typeentry_t> globaltypes_t;
  155 +
  156 + // A set that preserves position order, and a reverse map
  157 + typedef std::set<int> posmap_t;
  158 + typedef std::unordered_map<spv::Id, int> posmap_rev_t;
  159 +
  160 + // Maps and ID to the size of its base type, if known.
  161 + typedef std::unordered_map<spv::Id, unsigned> typesize_map_t;
  162 +
  163 + // handle error
  164 + void error(const std::string& txt) const { errorLatch = true; errorHandler(txt); }
  165 +
  166 + bool isConstOp(spv::Op opCode) const;
  167 + bool isTypeOp(spv::Op opCode) const;
  168 + bool isStripOp(spv::Op opCode) const;
  169 + bool isFlowCtrl(spv::Op opCode) const;
  170 + range_t literalRange(spv::Op opCode) const;
  171 + range_t typeRange(spv::Op opCode) const;
  172 + range_t constRange(spv::Op opCode) const;
  173 + unsigned typeSizeInWords(spv::Id id) const;
  174 + unsigned idTypeSizeInWords(spv::Id id) const;
  175 +
  176 + bool isStripOp(spv::Op opCode, unsigned start) const;
  177 +
  178 + spv::Id& asId(unsigned word) { return spv[word]; }
  179 + const spv::Id& asId(unsigned word) const { return spv[word]; }
  180 + spv::Op asOpCode(unsigned word) const { return opOpCode(spv[word]); }
  181 + std::uint32_t asOpCodeHash(unsigned word);
  182 + spv::Decoration asDecoration(unsigned word) const { return spv::Decoration(spv[word]); }
  183 + unsigned asWordCount(unsigned word) const { return opWordCount(spv[word]); }
  184 + spv::Id asTypeConstId(unsigned word) const { return asId(word + (isTypeOp(asOpCode(word)) ? 1 : 2)); }
  185 + unsigned idPos(spv::Id id) const;
  186 +
  187 + static unsigned opWordCount(spirword_t data) { return data >> spv::WordCountShift; }
  188 + static spv::Op opOpCode(spirword_t data) { return spv::Op(data & spv::OpCodeMask); }
  189 +
  190 + // Header access & set methods
  191 + spirword_t magic() const { return spv[0]; } // return magic number
  192 + spirword_t bound() const { return spv[3]; } // return Id bound from header
  193 + spirword_t bound(spirword_t b) { return spv[3] = b; }
  194 + spirword_t genmagic() const { return spv[2]; } // generator magic
  195 + spirword_t genmagic(spirword_t m) { return spv[2] = m; }
  196 + spirword_t schemaNum() const { return spv[4]; } // schema number from header
  197 +
  198 + // Mapping fns: get
  199 + spv::Id localId(spv::Id id) const { return idMapL[id]; }
  200 +
  201 + // Mapping fns: set
  202 + inline spv::Id localId(spv::Id id, spv::Id newId);
  203 + void countIds(spv::Id id);
  204 +
  205 + // Return next unused new local ID.
  206 + // NOTE: boost::dynamic_bitset would be more efficient due to find_next(),
  207 + // which std::vector<bool> doens't have.
  208 + inline spv::Id nextUnusedId(spv::Id id);
  209 +
  210 + void buildLocalMaps();
  211 + std::string literalString(unsigned word) const; // Return literal as a std::string
  212 + int literalStringWords(const std::string& str) const { return (int(str.size())+4)/4; }
  213 +
  214 + bool isNewIdMapped(spv::Id newId) const { return isMapped(newId); }
  215 + bool isOldIdUnmapped(spv::Id oldId) const { return localId(oldId) == unmapped; }
  216 + bool isOldIdUnused(spv::Id oldId) const { return localId(oldId) == unused; }
  217 + bool isOldIdMapped(spv::Id oldId) const { return !isOldIdUnused(oldId) && !isOldIdUnmapped(oldId); }
  218 + bool isFunction(spv::Id oldId) const { return fnPos.find(oldId) != fnPos.end(); }
  219 +
  220 + // bool matchType(const globaltypes_t& globalTypes, spv::Id lt, spv::Id gt) const;
  221 + // spv::Id findType(const globaltypes_t& globalTypes, spv::Id lt) const;
  222 + std::uint32_t hashType(unsigned typeStart) const;
  223 +
  224 + spirvbin_t& process(instfn_t, idfn_t, unsigned begin = 0, unsigned end = 0);
  225 + int processInstruction(unsigned word, instfn_t, idfn_t);
  226 +
  227 + void validate() const;
  228 + void mapTypeConst();
  229 + void mapFnBodies();
  230 + void optLoadStore();
  231 + void dceFuncs();
  232 + void dceVars();
  233 + void dceTypes();
  234 + void mapNames();
  235 + void foldIds(); // fold IDs to smallest space
  236 + void forwardLoadStores(); // load store forwarding (EXPERIMENTAL)
  237 + void offsetIds(); // create relative offset IDs
  238 +
  239 + void applyMap(); // remap per local name map
  240 + void mapRemainder(); // map any IDs we haven't touched yet
  241 + void stripDebug(); // strip all debug info
  242 + void stripDeadRefs(); // strips debug info for now-dead references after DCE
  243 + void strip(); // remove debug symbols
  244 +
  245 + std::vector<spirword_t> spv; // SPIR words
  246 +
  247 + std::vector<std::string> stripWhiteList;
  248 +
  249 + namemap_t nameMap; // ID names from OpName
  250 +
  251 + // Since we want to also do binary ops, we can't use std::vector<bool>. we could use
  252 + // boost::dynamic_bitset, but we're trying to avoid a boost dependency.
  253 + typedef std::uint64_t bits_t;
  254 + std::vector<bits_t> mapped; // which new IDs have been mapped
  255 + static const int mBits = sizeof(bits_t) * 4;
  256 +
  257 + bool isMapped(spv::Id id) const { return id < maxMappedId() && ((mapped[id/mBits] & (1LL<<(id%mBits))) != 0); }
  258 + void setMapped(spv::Id id) { resizeMapped(id); mapped[id/mBits] |= (1LL<<(id%mBits)); }
  259 + void resizeMapped(spv::Id id) { if (id >= maxMappedId()) mapped.resize(id/mBits+1, 0); }
  260 + size_t maxMappedId() const { return mapped.size() * mBits; }
  261 +
  262 + // Add a strip range for a given instruction starting at 'start'
  263 + // Note: avoiding brace initializers to please older versions os MSVC.
  264 + void stripInst(unsigned start) { stripRange.push_back(range_t(start, start + asWordCount(start))); }
  265 +
  266 + // Function start and end. use unordered_map because we'll have
  267 + // many fewer functions than IDs.
  268 + std::unordered_map<spv::Id, range_t> fnPos;
  269 +
  270 + // Which functions are called, anywhere in the module, with a call count
  271 + std::unordered_map<spv::Id, int> fnCalls;
  272 +
  273 + posmap_t typeConstPos; // word positions that define types & consts (ordered)
  274 + posmap_rev_t idPosR; // reverse map from IDs to positions
  275 + typesize_map_t idTypeSizeMap; // maps each ID to its type size, if known.
  276 +
  277 + std::vector<spv::Id> idMapL; // ID {M}ap from {L}ocal to {G}lobal IDs
  278 +
  279 + spv::Id entryPoint; // module entry point
  280 + spv::Id largestNewId; // biggest new ID we have mapped anything to
  281 +
  282 + // Sections of the binary to strip, given as [begin,end)
  283 + std::vector<range_t> stripRange;
  284 +
  285 + // processing options:
  286 + std::uint32_t options;
  287 + int verbose; // verbosity level
  288 +
  289 + // Error latch: this is set if the error handler is ever executed. It would be better to
  290 + // use a try/catch block and throw, but that's not desired for certain environments, so
  291 + // this is the alternative.
  292 + mutable bool errorLatch;
  293 +
  294 + static errorfn_t errorHandler;
  295 + static logfn_t logHandler;
  296 +};
  297 +
  298 +} // namespace SPV
  299 +
  300 +#endif // SPIRVREMAPPER_H
  1 +//
  2 +// Copyright (C) 2014-2016 LunarG, Inc.
  3 +// Copyright (C) 2018 Google, Inc.
  4 +//
  5 +// All rights reserved.
  6 +//
  7 +// Redistribution and use in source and binary forms, with or without
  8 +// modification, are permitted provided that the following conditions
  9 +// are met:
  10 +//
  11 +// Redistributions of source code must retain the above copyright
  12 +// notice, this list of conditions and the following disclaimer.
  13 +//
  14 +// Redistributions in binary form must reproduce the above
  15 +// copyright notice, this list of conditions and the following
  16 +// disclaimer in the documentation and/or other materials provided
  17 +// with the distribution.
  18 +//
  19 +// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
  20 +// contributors may be used to endorse or promote products derived
  21 +// from this software without specific prior written permission.
  22 +//
  23 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  26 +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  27 +// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  28 +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  29 +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  30 +// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31 +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32 +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  33 +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34 +// POSSIBILITY OF SUCH DAMAGE.
  35 +
  36 +//
  37 +// Call into SPIRV-Tools to disassemble, validate, and optimize.
  38 +//
  39 +
  40 +#pragma once
  41 +#ifndef GLSLANG_SPV_TOOLS_H
  42 +#define GLSLANG_SPV_TOOLS_H
  43 +
  44 +#if ENABLE_OPT
  45 +#include <vector>
  46 +#include <ostream>
  47 +#include <unordered_set>
  48 +#include "spirv-tools/libspirv.h"
  49 +#endif
  50 +
  51 +#include "glslang/MachineIndependent/Versions.h"
  52 +#include "glslang/Include/visibility.h"
  53 +#include "GlslangToSpv.h"
  54 +#include "Logger.h"
  55 +
  56 +namespace glslang {
  57 +
  58 +#if ENABLE_OPT
  59 +
  60 +class TIntermediate;
  61 +
  62 +// Translate glslang's view of target versioning to what SPIRV-Tools uses.
  63 +GLSLANG_EXPORT spv_target_env MapToSpirvToolsEnv(const SpvVersion& spvVersion, spv::SpvBuildLogger* logger);
  64 +GLSLANG_EXPORT spv_target_env MapToSpirvToolsEnv(const glslang::TIntermediate& intermediate, spv::SpvBuildLogger* logger);
  65 +
  66 +// Use the SPIRV-Tools disassembler to print SPIR-V using a SPV_ENV_UNIVERSAL_1_3 environment.
  67 +GLSLANG_EXPORT void SpirvToolsDisassemble(std::ostream& out, const std::vector<unsigned int>& spirv);
  68 +
  69 +// Use the SPIRV-Tools disassembler to print SPIR-V with a provided SPIR-V environment.
  70 +GLSLANG_EXPORT void SpirvToolsDisassemble(std::ostream& out, const std::vector<unsigned int>& spirv,
  71 + spv_target_env requested_context);
  72 +
  73 +// Apply the SPIRV-Tools validator to generated SPIR-V.
  74 +GLSLANG_EXPORT void SpirvToolsValidate(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
  75 + spv::SpvBuildLogger*, bool prelegalization);
  76 +
  77 +// Apply the SPIRV-Tools optimizer to generated SPIR-V. HLSL SPIR-V is legalized in the process.
  78 +GLSLANG_EXPORT void SpirvToolsTransform(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
  79 + spv::SpvBuildLogger*, const SpvOptions*);
  80 +
  81 +// Apply the SPIRV-Tools EliminateDeadInputComponents pass to generated SPIR-V. Put result in |spirv|.
  82 +GLSLANG_EXPORT void SpirvToolsEliminateDeadInputComponents(spv_target_env target_env, std::vector<unsigned int>& spirv,
  83 + spv::SpvBuildLogger*);
  84 +
  85 +// Apply the SPIRV-Tools AnalyzeDeadOutputStores pass to generated SPIR-V. Put result in |live_locs|.
  86 +// Return true if the result is valid.
  87 +GLSLANG_EXPORT bool SpirvToolsAnalyzeDeadOutputStores(spv_target_env target_env, std::vector<unsigned int>& spirv,
  88 + std::unordered_set<uint32_t>* live_locs,
  89 + std::unordered_set<uint32_t>* live_builtins,
  90 + spv::SpvBuildLogger*);
  91 +
  92 +// Apply the SPIRV-Tools EliminateDeadOutputStores and AggressiveDeadCodeElimination passes to generated SPIR-V using
  93 +// |live_locs|. Put result in |spirv|.
  94 +GLSLANG_EXPORT void SpirvToolsEliminateDeadOutputStores(spv_target_env target_env, std::vector<unsigned int>& spirv,
  95 + std::unordered_set<uint32_t>* live_locs,
  96 + std::unordered_set<uint32_t>* live_builtins,
  97 + spv::SpvBuildLogger*);
  98 +
  99 +// Apply the SPIRV-Tools optimizer to strip debug info from SPIR-V. This is implicitly done by
  100 +// SpirvToolsTransform if spvOptions->stripDebugInfo is set, but can be called separately if
  101 +// optimization is disabled.
  102 +GLSLANG_EXPORT void SpirvToolsStripDebugInfo(const glslang::TIntermediate& intermediate,
  103 + std::vector<unsigned int>& spirv, spv::SpvBuildLogger*);
  104 +
  105 +#endif
  106 +
  107 +} // end namespace glslang
  108 +
  109 +#endif // GLSLANG_SPV_TOOLS_H
  1 +//
  2 +// Copyright (C) 2014-2015 LunarG, Inc.
  3 +//
  4 +// All rights reserved.
  5 +//
  6 +// Redistribution and use in source and binary forms, with or without
  7 +// modification, are permitted provided that the following conditions
  8 +// are met:
  9 +//
  10 +// Redistributions of source code must retain the above copyright
  11 +// notice, this list of conditions and the following disclaimer.
  12 +//
  13 +// Redistributions in binary form must reproduce the above
  14 +// copyright notice, this list of conditions and the following
  15 +// disclaimer in the documentation and/or other materials provided
  16 +// with the distribution.
  17 +//
  18 +// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
  19 +// contributors may be used to endorse or promote products derived
  20 +// from this software without specific prior written permission.
  21 +//
  22 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25 +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  26 +// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27 +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28 +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29 +// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  30 +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31 +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  32 +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33 +// POSSIBILITY OF SUCH DAMAGE.
  34 +
  35 +//
  36 +// Disassembler for SPIR-V.
  37 +//
  38 +
  39 +#pragma once
  40 +#ifndef disassembler_H
  41 +#define disassembler_H
  42 +
  43 +#include <iostream>
  44 +#include <vector>
  45 +
  46 +#include "glslang/Include/visibility.h"
  47 +
  48 +namespace spv {
  49 +
  50 + // disassemble with glslang custom disassembler
  51 + GLSLANG_EXPORT void Disassemble(std::ostream& out, const std::vector<unsigned int>&);
  52 +
  53 +} // end namespace spv
  54 +
  55 +#endif // disassembler_H
  1 +// Copyright (C) 2020 The Khronos Group Inc.
  2 +//
  3 +// All rights reserved.
  4 +//
  5 +// Redistribution and use in source and binary forms, with or without
  6 +// modification, are permitted provided that the following conditions
  7 +// are met:
  8 +//
  9 +// Redistributions of source code must retain the above copyright
  10 +// notice, this list of conditions and the following disclaimer.
  11 +//
  12 +// Redistributions in binary form must reproduce the above
  13 +// copyright notice, this list of conditions and the following
  14 +// disclaimer in the documentation and/or other materials provided
  15 +// with the distribution.
  16 +//
  17 +// Neither the name of The Khronos Group Inc. nor the names of its
  18 +// contributors may be used to endorse or promote products derived
  19 +// from this software without specific prior written permission.
  20 +//
  21 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24 +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25 +// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26 +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27 +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  28 +// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29 +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30 +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31 +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32 +// POSSIBILITY OF SUCH DAMAGE.
  33 +
  34 +#ifndef GLSLANG_BUILD_INFO
  35 +#define GLSLANG_BUILD_INFO
  36 +
  37 +#define GLSLANG_VERSION_MAJOR 15
  38 +#define GLSLANG_VERSION_MINOR 1
  39 +#define GLSLANG_VERSION_PATCH 0
  40 +#define GLSLANG_VERSION_FLAVOR ""
  41 +
  42 +#define GLSLANG_VERSION_GREATER_THAN(major, minor, patch) \
  43 + ((GLSLANG_VERSION_MAJOR) > (major) || ((major) == GLSLANG_VERSION_MAJOR && \
  44 + ((GLSLANG_VERSION_MINOR) > (minor) || ((minor) == GLSLANG_VERSION_MINOR && \
  45 + (GLSLANG_VERSION_PATCH) > (patch)))))
  46 +
  47 +#define GLSLANG_VERSION_GREATER_OR_EQUAL_TO(major, minor, patch) \
  48 + ((GLSLANG_VERSION_MAJOR) > (major) || ((major) == GLSLANG_VERSION_MAJOR && \
  49 + ((GLSLANG_VERSION_MINOR) > (minor) || ((minor) == GLSLANG_VERSION_MINOR && \
  50 + (GLSLANG_VERSION_PATCH >= (patch))))))
  51 +
  52 +#define GLSLANG_VERSION_LESS_THAN(major, minor, patch) \
  53 + ((GLSLANG_VERSION_MAJOR) < (major) || ((major) == GLSLANG_VERSION_MAJOR && \
  54 + ((GLSLANG_VERSION_MINOR) < (minor) || ((minor) == GLSLANG_VERSION_MINOR && \
  55 + (GLSLANG_VERSION_PATCH) < (patch)))))
  56 +
  57 +#define GLSLANG_VERSION_LESS_OR_EQUAL_TO(major, minor, patch) \
  58 + ((GLSLANG_VERSION_MAJOR) < (major) || ((major) == GLSLANG_VERSION_MAJOR && \
  59 + ((GLSLANG_VERSION_MINOR) < (minor) || ((minor) == GLSLANG_VERSION_MINOR && \
  60 + (GLSLANG_VERSION_PATCH <= (patch))))))
  61 +
  62 +#endif // GLSLANG_BUILD_INFO
  1 +// Tencent is pleased to support the open source community by making ncnn available.
  2 +//
  3 +// Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved.
  4 +//
  5 +// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  6 +// in compliance with the License. You may obtain a copy of the License at
  7 +//
  8 +// https://opensource.org/licenses/BSD-3-Clause
  9 +//
  10 +// Unless required by applicable law or agreed to in writing, software distributed
  11 +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  12 +// CONDITIONS OF ANY KIND, either express or implied. See the License for the
  13 +// specific language governing permissions and limitations under the License.
  14 +
  15 +#ifndef NCNN_ALLOCATOR_H
  16 +#define NCNN_ALLOCATOR_H
  17 +
  18 +#ifdef _WIN32
  19 +#define WIN32_LEAN_AND_MEAN
  20 +#include <windows.h>
  21 +#endif
  22 +
  23 +#include "platform.h"
  24 +
  25 +#include <stdlib.h>
  26 +
  27 +#if NCNN_PLATFORM_API
  28 +#if __ANDROID_API__ >= 26
  29 +#include <android/hardware_buffer.h>
  30 +#endif // __ANDROID_API__ >= 26
  31 +#endif // NCNN_PLATFORM_API
  32 +
  33 +namespace ncnn {
  34 +
  35 +// the alignment of all the allocated buffers
  36 +#if NCNN_AVX512
  37 +#define NCNN_MALLOC_ALIGN 64
  38 +#elif NCNN_AVX
  39 +#define NCNN_MALLOC_ALIGN 32
  40 +#else
  41 +#define NCNN_MALLOC_ALIGN 16
  42 +#endif
  43 +
  44 +// we have some optimized kernels that may overread buffer a bit in loop
  45 +// it is common to interleave next-loop data load with arithmetic instructions
  46 +// allocating more bytes keeps us safe from SEGV_ACCERR failure
  47 +#define NCNN_MALLOC_OVERREAD 64
  48 +
  49 +// Aligns a pointer to the specified number of bytes
  50 +// ptr Aligned pointer
  51 +// n Alignment size that must be a power of two
  52 +template<typename _Tp>
  53 +static NCNN_FORCEINLINE _Tp* alignPtr(_Tp* ptr, int n = (int)sizeof(_Tp))
  54 +{
  55 + return (_Tp*)(((size_t)ptr + n - 1) & -n);
  56 +}
  57 +
  58 +// Aligns a buffer size to the specified number of bytes
  59 +// The function returns the minimum number that is greater or equal to sz and is divisible by n
  60 +// sz Buffer size to align
  61 +// n Alignment size that must be a power of two
  62 +static NCNN_FORCEINLINE size_t alignSize(size_t sz, int n)
  63 +{
  64 + return (sz + n - 1) & -n;
  65 +}
  66 +
  67 +static NCNN_FORCEINLINE void* fastMalloc(size_t size)
  68 +{
  69 +#if _MSC_VER
  70 + return _aligned_malloc(size, NCNN_MALLOC_ALIGN);
  71 +#elif (defined(__unix__) || defined(__APPLE__)) && _POSIX_C_SOURCE >= 200112L || (__ANDROID__ && __ANDROID_API__ >= 17)
  72 + void* ptr = 0;
  73 + if (posix_memalign(&ptr, NCNN_MALLOC_ALIGN, size + NCNN_MALLOC_OVERREAD))
  74 + ptr = 0;
  75 + return ptr;
  76 +#elif __ANDROID__ && __ANDROID_API__ < 17
  77 + return memalign(NCNN_MALLOC_ALIGN, size + NCNN_MALLOC_OVERREAD);
  78 +#else
  79 + unsigned char* udata = (unsigned char*)malloc(size + sizeof(void*) + NCNN_MALLOC_ALIGN + NCNN_MALLOC_OVERREAD);
  80 + if (!udata)
  81 + return 0;
  82 + unsigned char** adata = alignPtr((unsigned char**)udata + 1, NCNN_MALLOC_ALIGN);
  83 + adata[-1] = udata;
  84 + return adata;
  85 +#endif
  86 +}
  87 +
  88 +static NCNN_FORCEINLINE void fastFree(void* ptr)
  89 +{
  90 + if (ptr)
  91 + {
  92 +#if _MSC_VER
  93 + _aligned_free(ptr);
  94 +#elif (defined(__unix__) || defined(__APPLE__)) && _POSIX_C_SOURCE >= 200112L || (__ANDROID__ && __ANDROID_API__ >= 17)
  95 + free(ptr);
  96 +#elif __ANDROID__ && __ANDROID_API__ < 17
  97 + free(ptr);
  98 +#else
  99 + unsigned char* udata = ((unsigned char**)ptr)[-1];
  100 + free(udata);
  101 +#endif
  102 + }
  103 +}
  104 +
  105 +#if NCNN_THREADS
  106 +// exchange-add operation for atomic operations on reference counters
  107 +#if defined __riscv && !defined __riscv_atomic
  108 +// riscv target without A extension
  109 +static NCNN_FORCEINLINE int NCNN_XADD(int* addr, int delta)
  110 +{
  111 + int tmp = *addr;
  112 + *addr += delta;
  113 + return tmp;
  114 +}
  115 +#elif defined __INTEL_COMPILER && !(defined WIN32 || defined _WIN32)
  116 +// atomic increment on the linux version of the Intel(tm) compiler
  117 +#define NCNN_XADD(addr, delta) (int)_InterlockedExchangeAdd(const_cast<void*>(reinterpret_cast<volatile void*>(addr)), delta)
  118 +#elif defined __GNUC__
  119 +#if defined __clang__ && __clang_major__ >= 3 && !defined __ANDROID__ && !defined __EMSCRIPTEN__ && !defined(__CUDACC__)
  120 +#ifdef __ATOMIC_ACQ_REL
  121 +#define NCNN_XADD(addr, delta) __c11_atomic_fetch_add((_Atomic(int)*)(addr), delta, __ATOMIC_ACQ_REL)
  122 +#else
  123 +#define NCNN_XADD(addr, delta) __atomic_fetch_add((_Atomic(int)*)(addr), delta, 4)
  124 +#endif
  125 +#else
  126 +#if defined __ATOMIC_ACQ_REL && !defined __clang__
  127 +// version for gcc >= 4.7
  128 +#define NCNN_XADD(addr, delta) (int)__atomic_fetch_add((unsigned*)(addr), (unsigned)(delta), __ATOMIC_ACQ_REL)
  129 +#else
  130 +#define NCNN_XADD(addr, delta) (int)__sync_fetch_and_add((unsigned*)(addr), (unsigned)(delta))
  131 +#endif
  132 +#endif
  133 +#elif defined _MSC_VER && !defined RC_INVOKED
  134 +#define NCNN_XADD(addr, delta) (int)_InterlockedExchangeAdd((long volatile*)addr, delta)
  135 +#else
  136 +// thread-unsafe branch
  137 +static NCNN_FORCEINLINE int NCNN_XADD(int* addr, int delta)
  138 +{
  139 + int tmp = *addr;
  140 + *addr += delta;
  141 + return tmp;
  142 +}
  143 +#endif
  144 +#else // NCNN_THREADS
  145 +static NCNN_FORCEINLINE int NCNN_XADD(int* addr, int delta)
  146 +{
  147 + int tmp = *addr;
  148 + *addr += delta;
  149 + return tmp;
  150 +}
  151 +#endif // NCNN_THREADS
  152 +
  153 +class NCNN_EXPORT Allocator
  154 +{
  155 +public:
  156 + virtual ~Allocator();
  157 + virtual void* fastMalloc(size_t size) = 0;
  158 + virtual void fastFree(void* ptr) = 0;
  159 +};
  160 +
  161 +class PoolAllocatorPrivate;
  162 +class NCNN_EXPORT PoolAllocator : public Allocator
  163 +{
  164 +public:
  165 + PoolAllocator();
  166 + ~PoolAllocator();
  167 +
  168 + // ratio range 0 ~ 1
  169 + // default cr = 0
  170 + void set_size_compare_ratio(float scr);
  171 +
  172 + // budget drop threshold
  173 + // default threshold = 10
  174 + void set_size_drop_threshold(size_t);
  175 +
  176 + // release all budgets immediately
  177 + void clear();
  178 +
  179 + virtual void* fastMalloc(size_t size);
  180 + virtual void fastFree(void* ptr);
  181 +
  182 +private:
  183 + PoolAllocator(const PoolAllocator&);
  184 + PoolAllocator& operator=(const PoolAllocator&);
  185 +
  186 +private:
  187 + PoolAllocatorPrivate* const d;
  188 +};
  189 +
  190 +class UnlockedPoolAllocatorPrivate;
  191 +class NCNN_EXPORT UnlockedPoolAllocator : public Allocator
  192 +{
  193 +public:
  194 + UnlockedPoolAllocator();
  195 + ~UnlockedPoolAllocator();
  196 +
  197 + // ratio range 0 ~ 1
  198 + // default cr = 0
  199 + void set_size_compare_ratio(float scr);
  200 +
  201 + // budget drop threshold
  202 + // default threshold = 10
  203 + void set_size_drop_threshold(size_t);
  204 +
  205 + // release all budgets immediately
  206 + void clear();
  207 +
  208 + virtual void* fastMalloc(size_t size);
  209 + virtual void fastFree(void* ptr);
  210 +
  211 +private:
  212 + UnlockedPoolAllocator(const UnlockedPoolAllocator&);
  213 + UnlockedPoolAllocator& operator=(const UnlockedPoolAllocator&);
  214 +
  215 +private:
  216 + UnlockedPoolAllocatorPrivate* const d;
  217 +};
  218 +
  219 +#if NCNN_VULKAN
  220 +
  221 +class VulkanDevice;
  222 +
  223 +class NCNN_EXPORT VkBufferMemory
  224 +{
  225 +public:
  226 + VkBuffer buffer;
  227 +
  228 + // the base offset assigned by allocator
  229 + size_t offset;
  230 + size_t capacity;
  231 +
  232 + VkDeviceMemory memory;
  233 + void* mapped_ptr;
  234 +
  235 + // buffer state, modified by command functions internally
  236 + mutable VkAccessFlags access_flags;
  237 + mutable VkPipelineStageFlags stage_flags;
  238 +
  239 + // initialize and modified by mat
  240 + int refcount;
  241 +};
  242 +
  243 +class NCNN_EXPORT VkImageMemory
  244 +{
  245 +public:
  246 + VkImage image;
  247 + VkImageView imageview;
  248 +
  249 + // underlying info assigned by allocator
  250 + int width;
  251 + int height;
  252 + int depth;
  253 + VkFormat format;
  254 +
  255 + VkDeviceMemory memory;
  256 + void* mapped_ptr;
  257 +
  258 + // the base offset assigned by allocator
  259 + size_t bind_offset;
  260 + size_t bind_capacity;
  261 +
  262 + // image state, modified by command functions internally
  263 + mutable VkAccessFlags access_flags;
  264 + mutable VkImageLayout image_layout;
  265 + mutable VkPipelineStageFlags stage_flags;
  266 +
  267 + // in-execution state, modified by command functions internally
  268 + mutable int command_refcount;
  269 +
  270 + // initialize and modified by mat
  271 + int refcount;
  272 +};
  273 +
  274 +class NCNN_EXPORT VkAllocator
  275 +{
  276 +public:
  277 + explicit VkAllocator(const VulkanDevice* _vkdev);
  278 + virtual ~VkAllocator();
  279 +
  280 + virtual void clear();
  281 +
  282 + virtual VkBufferMemory* fastMalloc(size_t size) = 0;
  283 + virtual void fastFree(VkBufferMemory* ptr) = 0;
  284 + virtual int flush(VkBufferMemory* ptr);
  285 + virtual int invalidate(VkBufferMemory* ptr);
  286 +
  287 + virtual VkImageMemory* fastMalloc(int w, int h, int c, size_t elemsize, int elempack) = 0;
  288 + virtual void fastFree(VkImageMemory* ptr) = 0;
  289 +
  290 +public:
  291 + const VulkanDevice* vkdev;
  292 + uint32_t buffer_memory_type_index;
  293 + uint32_t image_memory_type_index;
  294 + uint32_t reserved_type_index;
  295 + bool mappable;
  296 + bool coherent;
  297 +
  298 +protected:
  299 + VkBuffer create_buffer(size_t size, VkBufferUsageFlags usage);
  300 + VkDeviceMemory allocate_memory(size_t size, uint32_t memory_type_index);
  301 + VkDeviceMemory allocate_dedicated_memory(size_t size, uint32_t memory_type_index, VkImage image, VkBuffer buffer);
  302 +
  303 + VkImage create_image(int width, int height, int depth, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage);
  304 + VkImageView create_imageview(VkImage image, VkFormat format);
  305 +};
  306 +
  307 +class VkBlobAllocatorPrivate;
  308 +class NCNN_EXPORT VkBlobAllocator : public VkAllocator
  309 +{
  310 +public:
  311 + explicit VkBlobAllocator(const VulkanDevice* vkdev, size_t preferred_block_size = 16 * 1024 * 1024); // 16M
  312 + virtual ~VkBlobAllocator();
  313 +
  314 +public:
  315 + // release all budgets immediately
  316 + virtual void clear();
  317 +
  318 + virtual VkBufferMemory* fastMalloc(size_t size);
  319 + virtual void fastFree(VkBufferMemory* ptr);
  320 + virtual VkImageMemory* fastMalloc(int w, int h, int c, size_t elemsize, int elempack);
  321 + virtual void fastFree(VkImageMemory* ptr);
  322 +
  323 +private:
  324 + VkBlobAllocator(const VkBlobAllocator&);
  325 + VkBlobAllocator& operator=(const VkBlobAllocator&);
  326 +
  327 +private:
  328 + VkBlobAllocatorPrivate* const d;
  329 +};
  330 +
  331 +class VkWeightAllocatorPrivate;
  332 +class NCNN_EXPORT VkWeightAllocator : public VkAllocator
  333 +{
  334 +public:
  335 + explicit VkWeightAllocator(const VulkanDevice* vkdev, size_t preferred_block_size = 8 * 1024 * 1024); // 8M
  336 + virtual ~VkWeightAllocator();
  337 +
  338 +public:
  339 + // release all blocks immediately
  340 + virtual void clear();
  341 +
  342 +public:
  343 + virtual VkBufferMemory* fastMalloc(size_t size);
  344 + virtual void fastFree(VkBufferMemory* ptr);
  345 + virtual VkImageMemory* fastMalloc(int w, int h, int c, size_t elemsize, int elempack);
  346 + virtual void fastFree(VkImageMemory* ptr);
  347 +
  348 +private:
  349 + VkWeightAllocator(const VkWeightAllocator&);
  350 + VkWeightAllocator& operator=(const VkWeightAllocator&);
  351 +
  352 +private:
  353 + VkWeightAllocatorPrivate* const d;
  354 +};
  355 +
  356 +class VkStagingAllocatorPrivate;
  357 +class NCNN_EXPORT VkStagingAllocator : public VkAllocator
  358 +{
  359 +public:
  360 + explicit VkStagingAllocator(const VulkanDevice* vkdev);
  361 + virtual ~VkStagingAllocator();
  362 +
  363 +public:
  364 + // ratio range 0 ~ 1
  365 + // default cr = 0.75
  366 + void set_size_compare_ratio(float scr);
  367 +
  368 + // release all budgets immediately
  369 + virtual void clear();
  370 +
  371 + virtual VkBufferMemory* fastMalloc(size_t size);
  372 + virtual void fastFree(VkBufferMemory* ptr);
  373 + virtual VkImageMemory* fastMalloc(int w, int h, int c, size_t elemsize, int elempack);
  374 + virtual void fastFree(VkImageMemory* ptr);
  375 +
  376 +private:
  377 + VkStagingAllocator(const VkStagingAllocator&);
  378 + VkStagingAllocator& operator=(const VkStagingAllocator&);
  379 +
  380 +private:
  381 + VkStagingAllocatorPrivate* const d;
  382 +};
  383 +
  384 +class VkWeightStagingAllocatorPrivate;
  385 +class NCNN_EXPORT VkWeightStagingAllocator : public VkAllocator
  386 +{
  387 +public:
  388 + explicit VkWeightStagingAllocator(const VulkanDevice* vkdev);
  389 + virtual ~VkWeightStagingAllocator();
  390 +
  391 +public:
  392 + virtual VkBufferMemory* fastMalloc(size_t size);
  393 + virtual void fastFree(VkBufferMemory* ptr);
  394 + virtual VkImageMemory* fastMalloc(int w, int h, int c, size_t elemsize, int elempack);
  395 + virtual void fastFree(VkImageMemory* ptr);
  396 +
  397 +private:
  398 + VkWeightStagingAllocator(const VkWeightStagingAllocator&);
  399 + VkWeightStagingAllocator& operator=(const VkWeightStagingAllocator&);
  400 +
  401 +private:
  402 + VkWeightStagingAllocatorPrivate* const d;
  403 +};
  404 +
  405 +#if NCNN_PLATFORM_API
  406 +#if __ANDROID_API__ >= 26
  407 +class NCNN_EXPORT VkAndroidHardwareBufferImageAllocator : public VkAllocator
  408 +{
  409 +public:
  410 + VkAndroidHardwareBufferImageAllocator(const VulkanDevice* _vkdev, AHardwareBuffer* _hb);
  411 + virtual ~VkAndroidHardwareBufferImageAllocator();
  412 +
  413 +public:
  414 + virtual VkBufferMemory* fastMalloc(size_t size);
  415 + virtual void fastFree(VkBufferMemory* ptr);
  416 + virtual VkImageMemory* fastMalloc(int w, int h, int c, size_t elemsize, int elempack);
  417 + virtual void fastFree(VkImageMemory* ptr);
  418 +
  419 +private:
  420 + VkAndroidHardwareBufferImageAllocator(const VkAndroidHardwareBufferImageAllocator&);
  421 + VkAndroidHardwareBufferImageAllocator& operator=(const VkAndroidHardwareBufferImageAllocator&);
  422 +
  423 +public:
  424 + int init();
  425 +
  426 + int width() const;
  427 + int height() const;
  428 + uint64_t external_format() const;
  429 +
  430 +public:
  431 + AHardwareBuffer* hb;
  432 + AHardwareBuffer_Desc bufferDesc;
  433 + VkAndroidHardwareBufferFormatPropertiesANDROID bufferFormatProperties;
  434 + VkAndroidHardwareBufferPropertiesANDROID bufferProperties;
  435 + VkSamplerYcbcrConversionKHR samplerYcbcrConversion;
  436 +};
  437 +#endif // __ANDROID_API__ >= 26
  438 +#endif // NCNN_PLATFORM_API
  439 +
  440 +#endif // NCNN_VULKAN
  441 +
  442 +} // namespace ncnn
  443 +
  444 +#endif // NCNN_ALLOCATOR_H
  1 +// Tencent is pleased to support the open source community by making ncnn available.
  2 +//
  3 +// Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
  4 +//
  5 +// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  6 +// in compliance with the License. You may obtain a copy of the License at
  7 +//
  8 +// https://opensource.org/licenses/BSD-3-Clause
  9 +//
  10 +// Unless required by applicable law or agreed to in writing, software distributed
  11 +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  12 +// CONDITIONS OF ANY KIND, either express or implied. See the License for the
  13 +// specific language governing permissions and limitations under the License.
  14 +
  15 +#ifndef NCNN_BENCHMARK_H
  16 +#define NCNN_BENCHMARK_H
  17 +
  18 +#include "layer.h"
  19 +#include "mat.h"
  20 +#include "platform.h"
  21 +
  22 +namespace ncnn {
  23 +
  24 +// get now timestamp in ms
  25 +NCNN_EXPORT double get_current_time();
  26 +
  27 +// sleep milliseconds
  28 +NCNN_EXPORT void sleep(unsigned long long int milliseconds = 1000);
  29 +
  30 +#if NCNN_BENCHMARK
  31 +
  32 +NCNN_EXPORT void benchmark(const Layer* layer, double start, double end);
  33 +NCNN_EXPORT void benchmark(const Layer* layer, const Mat& bottom_blob, Mat& top_blob, double start, double end);
  34 +
  35 +#endif // NCNN_BENCHMARK
  36 +
  37 +} // namespace ncnn
  38 +
  39 +#endif // NCNN_BENCHMARK_H
  1 +// Tencent is pleased to support the open source community by making ncnn available.
  2 +//
  3 +// Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
  4 +//
  5 +// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  6 +// in compliance with the License. You may obtain a copy of the License at
  7 +//
  8 +// https://opensource.org/licenses/BSD-3-Clause
  9 +//
  10 +// Unless required by applicable law or agreed to in writing, software distributed
  11 +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  12 +// CONDITIONS OF ANY KIND, either express or implied. See the License for the
  13 +// specific language governing permissions and limitations under the License.
  14 +
  15 +#ifndef NCNN_BLOB_H
  16 +#define NCNN_BLOB_H
  17 +
  18 +#include "mat.h"
  19 +#include "platform.h"
  20 +
  21 +namespace ncnn {
  22 +
  23 +class NCNN_EXPORT Blob
  24 +{
  25 +public:
  26 + // empty
  27 + Blob();
  28 +
  29 +public:
  30 +#if NCNN_STRING
  31 + // blob name
  32 + std::string name;
  33 +#endif // NCNN_STRING
  34 + // layer index which produce this blob as output
  35 + int producer;
  36 + // layer index which need this blob as input
  37 + int consumer;
  38 + // shape hint
  39 + Mat shape;
  40 +};
  41 +
  42 +} // namespace ncnn
  43 +
  44 +#endif // NCNN_BLOB_H
  1 +/* Tencent is pleased to support the open source community by making ncnn available.
  2 + *
  3 + * Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
  4 + *
  5 + * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  6 + * in compliance with the License. You may obtain a copy of the License at
  7 + *
  8 + * https://opensource.org/licenses/BSD-3-Clause
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software distributed
  11 + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  12 + * CONDITIONS OF ANY KIND, either express or implied. See the License for the
  13 + * specific language governing permissions and limitations under the License.
  14 + */
  15 +
  16 +#ifndef NCNN_C_API_H
  17 +#define NCNN_C_API_H
  18 +
  19 +#include "platform.h"
  20 +
  21 +#if NCNN_C_API
  22 +
  23 +#include <stddef.h>
  24 +
  25 +#ifdef __cplusplus
  26 +extern "C" {
  27 +#endif
  28 +
  29 +NCNN_EXPORT const char* ncnn_version(void);
  30 +
  31 +/* allocator api */
  32 +typedef struct __ncnn_allocator_t* ncnn_allocator_t;
  33 +struct NCNN_EXPORT __ncnn_allocator_t
  34 +{
  35 + void* pthis;
  36 +
  37 + void* (*fast_malloc)(ncnn_allocator_t allocator, size_t size);
  38 + void (*fast_free)(ncnn_allocator_t allocator, void* ptr);
  39 +};
  40 +
  41 +NCNN_EXPORT ncnn_allocator_t ncnn_allocator_create_pool_allocator(void);
  42 +NCNN_EXPORT ncnn_allocator_t ncnn_allocator_create_unlocked_pool_allocator(void);
  43 +NCNN_EXPORT void ncnn_allocator_destroy(ncnn_allocator_t allocator);
  44 +
  45 +/* option api */
  46 +typedef struct __ncnn_option_t* ncnn_option_t;
  47 +
  48 +NCNN_EXPORT ncnn_option_t ncnn_option_create(void);
  49 +NCNN_EXPORT void ncnn_option_destroy(ncnn_option_t opt);
  50 +
  51 +NCNN_EXPORT int ncnn_option_get_num_threads(const ncnn_option_t opt);
  52 +NCNN_EXPORT void ncnn_option_set_num_threads(ncnn_option_t opt, int num_threads);
  53 +
  54 +NCNN_EXPORT int ncnn_option_get_use_local_pool_allocator(const ncnn_option_t opt);
  55 +NCNN_EXPORT void ncnn_option_set_use_local_pool_allocator(ncnn_option_t opt, int use_local_pool_allocator);
  56 +
  57 +NCNN_EXPORT void ncnn_option_set_blob_allocator(ncnn_option_t opt, ncnn_allocator_t allocator);
  58 +NCNN_EXPORT void ncnn_option_set_workspace_allocator(ncnn_option_t opt, ncnn_allocator_t allocator);
  59 +
  60 +NCNN_EXPORT int ncnn_option_get_use_vulkan_compute(const ncnn_option_t opt);
  61 +NCNN_EXPORT void ncnn_option_set_use_vulkan_compute(ncnn_option_t opt, int use_vulkan_compute);
  62 +
  63 +/* mat api */
  64 +typedef struct __ncnn_mat_t* ncnn_mat_t;
  65 +
  66 +NCNN_EXPORT ncnn_mat_t ncnn_mat_create(void);
  67 +NCNN_EXPORT ncnn_mat_t ncnn_mat_create_1d(int w, ncnn_allocator_t allocator);
  68 +NCNN_EXPORT ncnn_mat_t ncnn_mat_create_2d(int w, int h, ncnn_allocator_t allocator);
  69 +NCNN_EXPORT ncnn_mat_t ncnn_mat_create_3d(int w, int h, int c, ncnn_allocator_t allocator);
  70 +NCNN_EXPORT ncnn_mat_t ncnn_mat_create_4d(int w, int h, int d, int c, ncnn_allocator_t allocator);
  71 +NCNN_EXPORT ncnn_mat_t ncnn_mat_create_external_1d(int w, void* data, ncnn_allocator_t allocator);
  72 +NCNN_EXPORT ncnn_mat_t ncnn_mat_create_external_2d(int w, int h, void* data, ncnn_allocator_t allocator);
  73 +NCNN_EXPORT ncnn_mat_t ncnn_mat_create_external_3d(int w, int h, int c, void* data, ncnn_allocator_t allocator);
  74 +NCNN_EXPORT ncnn_mat_t ncnn_mat_create_external_4d(int w, int h, int d, int c, void* data, ncnn_allocator_t allocator);
  75 +NCNN_EXPORT ncnn_mat_t ncnn_mat_create_1d_elem(int w, size_t elemsize, int elempack, ncnn_allocator_t allocator);
  76 +NCNN_EXPORT ncnn_mat_t ncnn_mat_create_2d_elem(int w, int h, size_t elemsize, int elempack, ncnn_allocator_t allocator);
  77 +NCNN_EXPORT ncnn_mat_t ncnn_mat_create_3d_elem(int w, int h, int c, size_t elemsize, int elempack, ncnn_allocator_t allocator);
  78 +NCNN_EXPORT ncnn_mat_t ncnn_mat_create_4d_elem(int w, int h, int d, int c, size_t elemsize, int elempack, ncnn_allocator_t allocator);
  79 +NCNN_EXPORT ncnn_mat_t ncnn_mat_create_external_1d_elem(int w, void* data, size_t elemsize, int elempack, ncnn_allocator_t allocator);
  80 +NCNN_EXPORT ncnn_mat_t ncnn_mat_create_external_2d_elem(int w, int h, void* data, size_t elemsize, int elempack, ncnn_allocator_t allocator);
  81 +NCNN_EXPORT ncnn_mat_t ncnn_mat_create_external_3d_elem(int w, int h, int c, void* data, size_t elemsize, int elempack, ncnn_allocator_t allocator);
  82 +NCNN_EXPORT ncnn_mat_t ncnn_mat_create_external_4d_elem(int w, int h, int d, int c, void* data, size_t elemsize, int elempack, ncnn_allocator_t allocator);
  83 +NCNN_EXPORT void ncnn_mat_destroy(ncnn_mat_t mat);
  84 +
  85 +NCNN_EXPORT void ncnn_mat_fill_float(ncnn_mat_t mat, float v);
  86 +
  87 +NCNN_EXPORT ncnn_mat_t ncnn_mat_clone(const ncnn_mat_t mat, ncnn_allocator_t allocator);
  88 +NCNN_EXPORT ncnn_mat_t ncnn_mat_reshape_1d(const ncnn_mat_t mat, int w, ncnn_allocator_t allocator);
  89 +NCNN_EXPORT ncnn_mat_t ncnn_mat_reshape_2d(const ncnn_mat_t mat, int w, int h, ncnn_allocator_t allocator);
  90 +NCNN_EXPORT ncnn_mat_t ncnn_mat_reshape_3d(const ncnn_mat_t mat, int w, int h, int c, ncnn_allocator_t allocator);
  91 +NCNN_EXPORT ncnn_mat_t ncnn_mat_reshape_4d(const ncnn_mat_t mat, int w, int h, int d, int c, ncnn_allocator_t allocator);
  92 +
  93 +NCNN_EXPORT int ncnn_mat_get_dims(const ncnn_mat_t mat);
  94 +NCNN_EXPORT int ncnn_mat_get_w(const ncnn_mat_t mat);
  95 +NCNN_EXPORT int ncnn_mat_get_h(const ncnn_mat_t mat);
  96 +NCNN_EXPORT int ncnn_mat_get_d(const ncnn_mat_t mat);
  97 +NCNN_EXPORT int ncnn_mat_get_c(const ncnn_mat_t mat);
  98 +NCNN_EXPORT size_t ncnn_mat_get_elemsize(const ncnn_mat_t mat);
  99 +NCNN_EXPORT int ncnn_mat_get_elempack(const ncnn_mat_t mat);
  100 +NCNN_EXPORT size_t ncnn_mat_get_cstep(const ncnn_mat_t mat);
  101 +NCNN_EXPORT void* ncnn_mat_get_data(const ncnn_mat_t mat);
  102 +
  103 +NCNN_EXPORT void* ncnn_mat_get_channel_data(const ncnn_mat_t mat, int c);
  104 +
  105 +#if NCNN_PIXEL
  106 +
  107 +/* mat pixel api */
  108 +#define NCNN_MAT_PIXEL_RGB 1
  109 +#define NCNN_MAT_PIXEL_BGR 2
  110 +#define NCNN_MAT_PIXEL_GRAY 3
  111 +#define NCNN_MAT_PIXEL_RGBA 4
  112 +#define NCNN_MAT_PIXEL_BGRA 5
  113 +#define NCNN_MAT_PIXEL_X2Y(X, Y) (X | (Y << 16))
  114 +NCNN_EXPORT ncnn_mat_t ncnn_mat_from_pixels(const unsigned char* pixels, int type, int w, int h, int stride, ncnn_allocator_t allocator);
  115 +NCNN_EXPORT ncnn_mat_t ncnn_mat_from_pixels_resize(const unsigned char* pixels, int type, int w, int h, int stride, int target_width, int target_height, ncnn_allocator_t allocator);
  116 +NCNN_EXPORT ncnn_mat_t ncnn_mat_from_pixels_roi(const unsigned char* pixels, int type, int w, int h, int stride, int roix, int roiy, int roiw, int roih, ncnn_allocator_t allocator);
  117 +NCNN_EXPORT ncnn_mat_t ncnn_mat_from_pixels_roi_resize(const unsigned char* pixels, int type, int w, int h, int stride, int roix, int roiy, int roiw, int roih, int target_width, int target_height, ncnn_allocator_t allocator);
  118 +NCNN_EXPORT void ncnn_mat_to_pixels(const ncnn_mat_t mat, unsigned char* pixels, int type, int stride);
  119 +NCNN_EXPORT void ncnn_mat_to_pixels_resize(const ncnn_mat_t mat, unsigned char* pixels, int type, int target_width, int target_height, int target_stride);
  120 +
  121 +#endif /* NCNN_PIXEL */
  122 +
  123 +NCNN_EXPORT void ncnn_mat_substract_mean_normalize(ncnn_mat_t mat, const float* mean_vals, const float* norm_vals);
  124 +
  125 +NCNN_EXPORT void ncnn_convert_packing(const ncnn_mat_t src, ncnn_mat_t* dst, int elempack, const ncnn_option_t opt);
  126 +NCNN_EXPORT void ncnn_flatten(const ncnn_mat_t src, ncnn_mat_t* dst, const ncnn_option_t opt);
  127 +
  128 +/* blob api */
  129 +typedef struct __ncnn_blob_t* ncnn_blob_t;
  130 +
  131 +#if NCNN_STRING
  132 +NCNN_EXPORT const char* ncnn_blob_get_name(const ncnn_blob_t blob);
  133 +#endif /* NCNN_STRING */
  134 +
  135 +NCNN_EXPORT int ncnn_blob_get_producer(const ncnn_blob_t blob);
  136 +NCNN_EXPORT int ncnn_blob_get_consumer(const ncnn_blob_t blob);
  137 +
  138 +NCNN_EXPORT void ncnn_blob_get_shape(const ncnn_blob_t blob, int* dims, int* w, int* h, int* c);
  139 +
  140 +/* paramdict api */
  141 +typedef struct __ncnn_paramdict_t* ncnn_paramdict_t;
  142 +
  143 +NCNN_EXPORT ncnn_paramdict_t ncnn_paramdict_create(void);
  144 +NCNN_EXPORT void ncnn_paramdict_destroy(ncnn_paramdict_t pd);
  145 +
  146 +NCNN_EXPORT int ncnn_paramdict_get_type(const ncnn_paramdict_t pd, int id);
  147 +
  148 +NCNN_EXPORT int ncnn_paramdict_get_int(const ncnn_paramdict_t pd, int id, int def);
  149 +NCNN_EXPORT float ncnn_paramdict_get_float(const ncnn_paramdict_t pd, int id, float def);
  150 +NCNN_EXPORT ncnn_mat_t ncnn_paramdict_get_array(const ncnn_paramdict_t pd, int id, const ncnn_mat_t def);
  151 +
  152 +NCNN_EXPORT void ncnn_paramdict_set_int(ncnn_paramdict_t pd, int id, int i);
  153 +NCNN_EXPORT void ncnn_paramdict_set_float(ncnn_paramdict_t pd, int id, float f);
  154 +NCNN_EXPORT void ncnn_paramdict_set_array(ncnn_paramdict_t pd, int id, const ncnn_mat_t v);
  155 +
  156 +/* datareader api */
  157 +typedef struct __ncnn_datareader_t* ncnn_datareader_t;
  158 +struct NCNN_EXPORT __ncnn_datareader_t
  159 +{
  160 + void* pthis;
  161 +
  162 +#if NCNN_STRING
  163 + int (*scan)(ncnn_datareader_t dr, const char* format, void* p);
  164 +#endif /* NCNN_STRING */
  165 + size_t (*read)(ncnn_datareader_t dr, void* buf, size_t size);
  166 +};
  167 +
  168 +NCNN_EXPORT ncnn_datareader_t ncnn_datareader_create(void);
  169 +#if NCNN_STDIO
  170 +NCNN_EXPORT ncnn_datareader_t ncnn_datareader_create_from_stdio(FILE* fp);
  171 +#endif /* NCNN_STDIO */
  172 +NCNN_EXPORT ncnn_datareader_t ncnn_datareader_create_from_memory(const unsigned char** mem);
  173 +NCNN_EXPORT void ncnn_datareader_destroy(ncnn_datareader_t dr);
  174 +
  175 +/* modelbin api */
  176 +typedef struct __ncnn_modelbin_t* ncnn_modelbin_t;
  177 +struct NCNN_EXPORT __ncnn_modelbin_t
  178 +{
  179 + void* pthis;
  180 +
  181 + ncnn_mat_t (*load_1d)(const ncnn_modelbin_t mb, int w, int type);
  182 + ncnn_mat_t (*load_2d)(const ncnn_modelbin_t mb, int w, int h, int type);
  183 + ncnn_mat_t (*load_3d)(const ncnn_modelbin_t mb, int w, int h, int c, int type);
  184 +};
  185 +
  186 +NCNN_EXPORT ncnn_modelbin_t ncnn_modelbin_create_from_datareader(const ncnn_datareader_t dr);
  187 +NCNN_EXPORT ncnn_modelbin_t ncnn_modelbin_create_from_mat_array(const ncnn_mat_t* weights, int n);
  188 +NCNN_EXPORT void ncnn_modelbin_destroy(ncnn_modelbin_t mb);
  189 +
  190 +/* layer api */
  191 +typedef struct __ncnn_layer_t* ncnn_layer_t;
  192 +struct NCNN_EXPORT __ncnn_layer_t
  193 +{
  194 + void* pthis;
  195 +
  196 + int (*load_param)(ncnn_layer_t layer, const ncnn_paramdict_t pd);
  197 + int (*load_model)(ncnn_layer_t layer, const ncnn_modelbin_t mb);
  198 +
  199 + int (*create_pipeline)(ncnn_layer_t layer, const ncnn_option_t opt);
  200 + int (*destroy_pipeline)(ncnn_layer_t layer, const ncnn_option_t opt);
  201 +
  202 + int (*forward_1)(const ncnn_layer_t layer, const ncnn_mat_t bottom_blob, ncnn_mat_t* top_blob, const ncnn_option_t opt);
  203 + int (*forward_n)(const ncnn_layer_t layer, const ncnn_mat_t* bottom_blobs, int n, ncnn_mat_t* top_blobs, int n2, const ncnn_option_t opt);
  204 +
  205 + int (*forward_inplace_1)(const ncnn_layer_t layer, ncnn_mat_t bottom_top_blob, const ncnn_option_t opt);
  206 + int (*forward_inplace_n)(const ncnn_layer_t layer, ncnn_mat_t* bottom_top_blobs, int n, const ncnn_option_t opt);
  207 +};
  208 +
  209 +NCNN_EXPORT ncnn_layer_t ncnn_layer_create(void);
  210 +NCNN_EXPORT ncnn_layer_t ncnn_layer_create_by_typeindex(int typeindex);
  211 +#if NCNN_STRING
  212 +NCNN_EXPORT ncnn_layer_t ncnn_layer_create_by_type(const char* type);
  213 +NCNN_EXPORT int ncnn_layer_type_to_index(const char* type);
  214 +#endif /* NCNN_STRING */
  215 +NCNN_EXPORT void ncnn_layer_destroy(ncnn_layer_t layer);
  216 +
  217 +#if NCNN_STRING
  218 +NCNN_EXPORT const char* ncnn_layer_get_name(const ncnn_layer_t layer);
  219 +#endif /* NCNN_STRING */
  220 +
  221 +NCNN_EXPORT int ncnn_layer_get_typeindex(const ncnn_layer_t layer);
  222 +#if NCNN_STRING
  223 +NCNN_EXPORT const char* ncnn_layer_get_type(const ncnn_layer_t layer);
  224 +#endif /* NCNN_STRING */
  225 +
  226 +NCNN_EXPORT int ncnn_layer_get_one_blob_only(const ncnn_layer_t layer);
  227 +NCNN_EXPORT int ncnn_layer_get_support_inplace(const ncnn_layer_t layer);
  228 +NCNN_EXPORT int ncnn_layer_get_support_vulkan(const ncnn_layer_t layer);
  229 +NCNN_EXPORT int ncnn_layer_get_support_packing(const ncnn_layer_t layer);
  230 +NCNN_EXPORT int ncnn_layer_get_support_bf16_storage(const ncnn_layer_t layer);
  231 +NCNN_EXPORT int ncnn_layer_get_support_fp16_storage(const ncnn_layer_t layer);
  232 +NCNN_EXPORT int ncnn_layer_get_support_image_storage(const ncnn_layer_t layer);
  233 +
  234 +NCNN_EXPORT void ncnn_layer_set_one_blob_only(ncnn_layer_t layer, int enable);
  235 +NCNN_EXPORT void ncnn_layer_set_support_inplace(ncnn_layer_t layer, int enable);
  236 +NCNN_EXPORT void ncnn_layer_set_support_vulkan(ncnn_layer_t layer, int enable);
  237 +NCNN_EXPORT void ncnn_layer_set_support_packing(ncnn_layer_t layer, int enable);
  238 +NCNN_EXPORT void ncnn_layer_set_support_bf16_storage(ncnn_layer_t layer, int enable);
  239 +NCNN_EXPORT void ncnn_layer_set_support_fp16_storage(ncnn_layer_t layer, int enable);
  240 +NCNN_EXPORT void ncnn_layer_set_support_image_storage(ncnn_layer_t layer, int enable);
  241 +
  242 +NCNN_EXPORT int ncnn_layer_get_bottom_count(const ncnn_layer_t layer);
  243 +NCNN_EXPORT int ncnn_layer_get_bottom(const ncnn_layer_t layer, int i);
  244 +NCNN_EXPORT int ncnn_layer_get_top_count(const ncnn_layer_t layer);
  245 +NCNN_EXPORT int ncnn_layer_get_top(const ncnn_layer_t layer, int i);
  246 +
  247 +NCNN_EXPORT void ncnn_blob_get_bottom_shape(const ncnn_layer_t layer, int i, int* dims, int* w, int* h, int* c);
  248 +NCNN_EXPORT void ncnn_blob_get_top_shape(const ncnn_layer_t layer, int i, int* dims, int* w, int* h, int* c);
  249 +
  250 +/* layer factory function */
  251 +typedef ncnn_layer_t (*ncnn_layer_creator_t)(void* userdata);
  252 +typedef void (*ncnn_layer_destroyer_t)(ncnn_layer_t layer, void* userdata);
  253 +
  254 +typedef struct __ncnn_net_custom_layer_factory_t* ncnn_net_custom_layer_factory_t;
  255 +struct __ncnn_net_custom_layer_factory_t
  256 +{
  257 + ncnn_layer_creator_t creator;
  258 + ncnn_layer_destroyer_t destroyer;
  259 + void* userdata;
  260 + ncnn_net_custom_layer_factory_t next;
  261 +};
  262 +
  263 +/* net api */
  264 +typedef struct __ncnn_net_t* ncnn_net_t;
  265 +struct __ncnn_net_t
  266 +{
  267 + void* pthis;
  268 +
  269 + ncnn_net_custom_layer_factory_t custom_layer_factory;
  270 +};
  271 +
  272 +NCNN_EXPORT ncnn_net_t ncnn_net_create(void);
  273 +NCNN_EXPORT void ncnn_net_destroy(ncnn_net_t net);
  274 +
  275 +NCNN_EXPORT ncnn_option_t ncnn_net_get_option(ncnn_net_t net);
  276 +NCNN_EXPORT void ncnn_net_set_option(ncnn_net_t net, ncnn_option_t opt);
  277 +
  278 +#if NCNN_VULKAN
  279 +NCNN_EXPORT void ncnn_net_set_vulkan_device(ncnn_net_t net, int device_index);
  280 +#endif
  281 +
  282 +#if NCNN_STRING
  283 +NCNN_EXPORT void ncnn_net_register_custom_layer_by_type(ncnn_net_t net, const char* type, ncnn_layer_creator_t creator, ncnn_layer_destroyer_t destroyer, void* userdata);
  284 +#endif /* NCNN_STRING */
  285 +NCNN_EXPORT void ncnn_net_register_custom_layer_by_typeindex(ncnn_net_t net, int typeindex, ncnn_layer_creator_t creator, ncnn_layer_destroyer_t destroyer, void* userdata);
  286 +
  287 +#if NCNN_STDIO
  288 +#if NCNN_STRING
  289 +NCNN_EXPORT int ncnn_net_load_param(ncnn_net_t net, const char* path);
  290 +#endif /* NCNN_STRING */
  291 +NCNN_EXPORT int ncnn_net_load_param_bin(ncnn_net_t net, const char* path);
  292 +NCNN_EXPORT int ncnn_net_load_model(ncnn_net_t net, const char* path);
  293 +#endif /* NCNN_STDIO */
  294 +
  295 +#if NCNN_STDIO
  296 +#if NCNN_STRING
  297 +NCNN_EXPORT int ncnn_net_load_param_memory(ncnn_net_t net, const char* mem);
  298 +#endif /* NCNN_STRING */
  299 +#endif /* NCNN_STDIO */
  300 +NCNN_EXPORT int ncnn_net_load_param_bin_memory(ncnn_net_t net, const unsigned char* mem);
  301 +NCNN_EXPORT int ncnn_net_load_model_memory(ncnn_net_t net, const unsigned char* mem);
  302 +
  303 +#if NCNN_STRING
  304 +NCNN_EXPORT int ncnn_net_load_param_datareader(ncnn_net_t net, const ncnn_datareader_t dr);
  305 +#endif /* NCNN_STRING */
  306 +NCNN_EXPORT int ncnn_net_load_param_bin_datareader(ncnn_net_t net, const ncnn_datareader_t dr);
  307 +NCNN_EXPORT int ncnn_net_load_model_datareader(ncnn_net_t net, const ncnn_datareader_t dr);
  308 +
  309 +NCNN_EXPORT void ncnn_net_clear(ncnn_net_t net);
  310 +
  311 +NCNN_EXPORT int ncnn_net_get_input_count(const ncnn_net_t net);
  312 +NCNN_EXPORT int ncnn_net_get_output_count(const ncnn_net_t net);
  313 +#if NCNN_STRING
  314 +NCNN_EXPORT const char* ncnn_net_get_input_name(const ncnn_net_t net, int i);
  315 +NCNN_EXPORT const char* ncnn_net_get_output_name(const ncnn_net_t net, int i);
  316 +#endif /* NCNN_STRING */
  317 +NCNN_EXPORT int ncnn_net_get_input_index(const ncnn_net_t net, int i);
  318 +NCNN_EXPORT int ncnn_net_get_output_index(const ncnn_net_t net, int i);
  319 +
  320 +/* extractor api */
  321 +typedef struct __ncnn_extractor_t* ncnn_extractor_t;
  322 +
  323 +NCNN_EXPORT ncnn_extractor_t ncnn_extractor_create(ncnn_net_t net);
  324 +NCNN_EXPORT void ncnn_extractor_destroy(ncnn_extractor_t ex);
  325 +
  326 +NCNN_EXPORT void ncnn_extractor_set_option(ncnn_extractor_t ex, const ncnn_option_t opt);
  327 +
  328 +#if NCNN_STRING
  329 +NCNN_EXPORT int ncnn_extractor_input(ncnn_extractor_t ex, const char* name, const ncnn_mat_t mat);
  330 +NCNN_EXPORT int ncnn_extractor_extract(ncnn_extractor_t ex, const char* name, ncnn_mat_t* mat);
  331 +#endif /* NCNN_STRING */
  332 +NCNN_EXPORT int ncnn_extractor_input_index(ncnn_extractor_t ex, int index, const ncnn_mat_t mat);
  333 +NCNN_EXPORT int ncnn_extractor_extract_index(ncnn_extractor_t ex, int index, ncnn_mat_t* mat);
  334 +
  335 +/* mat process api */
  336 +#define NCNN_BORDER_CONSTANT 0
  337 +#define NCNN_BORDER_REPLICATE 1
  338 +#define NCNN_BORDER_REFLECT 2
  339 +#define NCNN_BORDER_TRANSPARENT -233
  340 +NCNN_EXPORT void ncnn_copy_make_border(const ncnn_mat_t src, ncnn_mat_t dst, int top, int bottom, int left, int right, int type, float v, const ncnn_option_t opt);
  341 +NCNN_EXPORT void ncnn_copy_make_border_3d(const ncnn_mat_t src, ncnn_mat_t dst, int top, int bottom, int left, int right, int front, int behind, int type, float v, const ncnn_option_t opt);
  342 +NCNN_EXPORT void ncnn_copy_cut_border(const ncnn_mat_t src, ncnn_mat_t dst, int top, int bottom, int left, int right, const ncnn_option_t opt);
  343 +NCNN_EXPORT void ncnn_copy_cut_border_3d(const ncnn_mat_t src, ncnn_mat_t dst, int top, int bottom, int left, int right, int front, int behind, const ncnn_option_t opt);
  344 +
  345 +#if NCNN_PIXEL_DRAWING
  346 +/* mat pixel drawing api*/
  347 +NCNN_EXPORT void ncnn_draw_rectangle_c1(unsigned char* pixels, int w, int h, int rx, int ry, int rw, int rh, unsigned int color, int thickness);
  348 +NCNN_EXPORT void ncnn_draw_rectangle_c2(unsigned char* pixels, int w, int h, int rx, int ry, int rw, int rh, unsigned int color, int thickness);
  349 +NCNN_EXPORT void ncnn_draw_rectangle_c3(unsigned char* pixels, int w, int h, int rx, int ry, int rw, int rh, unsigned int color, int thickness);
  350 +NCNN_EXPORT void ncnn_draw_rectangle_c4(unsigned char* pixels, int w, int h, int rx, int ry, int rw, int rh, unsigned int color, int thickness);
  351 +
  352 +NCNN_EXPORT void ncnn_draw_text_c1(unsigned char* pixels, int w, int h, const char* text, int x, int y, int fontpixelsize, unsigned int color);
  353 +NCNN_EXPORT void ncnn_draw_text_c2(unsigned char* pixels, int w, int h, const char* text, int x, int y, int fontpixelsize, unsigned int color);
  354 +NCNN_EXPORT void ncnn_draw_text_c3(unsigned char* pixels, int w, int h, const char* text, int x, int y, int fontpixelsize, unsigned int color);
  355 +NCNN_EXPORT void ncnn_draw_text_c4(unsigned char* pixels, int w, int h, const char* text, int x, int y, int fontpixelsize, unsigned int color);
  356 +
  357 +NCNN_EXPORT void ncnn_draw_circle_c1(unsigned char* pixels, int w, int h, int cx, int cy, int radius, unsigned int color, int thickness);
  358 +NCNN_EXPORT void ncnn_draw_circle_c2(unsigned char* pixels, int w, int h, int cx, int cy, int radius, unsigned int color, int thickness);
  359 +NCNN_EXPORT void ncnn_draw_circle_c3(unsigned char* pixels, int w, int h, int cx, int cy, int radius, unsigned int color, int thickness);
  360 +NCNN_EXPORT void ncnn_draw_circle_c4(unsigned char* pixels, int w, int h, int cx, int cy, int radius, unsigned int color, int thickness);
  361 +
  362 +NCNN_EXPORT void ncnn_draw_line_c1(unsigned char* pixels, int w, int h, int x0, int y0, int x1, int y1, unsigned int color, int thickness);
  363 +NCNN_EXPORT void ncnn_draw_line_c2(unsigned char* pixels, int w, int h, int x0, int y0, int x1, int y1, unsigned int color, int thickness);
  364 +NCNN_EXPORT void ncnn_draw_line_c3(unsigned char* pixels, int w, int h, int x0, int y0, int x1, int y1, unsigned int color, int thickness);
  365 +NCNN_EXPORT void ncnn_draw_line_c4(unsigned char* pixels, int w, int h, int x0, int y0, int x1, int y1, unsigned int color, int thickness);
  366 +#endif /* NCNN_PIXEL_DRAWING */
  367 +
  368 +#ifdef __cplusplus
  369 +} /* extern "C" */
  370 +#endif
  371 +
  372 +#endif /* NCNN_C_API */
  373 +
  374 +#endif /* NCNN_C_API_H */
  1 +// Tencent is pleased to support the open source community by making ncnn available.
  2 +//
  3 +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
  4 +//
  5 +// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  6 +// in compliance with the License. You may obtain a copy of the License at
  7 +//
  8 +// https://opensource.org/licenses/BSD-3-Clause
  9 +//
  10 +// Unless required by applicable law or agreed to in writing, software distributed
  11 +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  12 +// CONDITIONS OF ANY KIND, either express or implied. See the License for the
  13 +// specific language governing permissions and limitations under the License.
  14 +
  15 +#ifndef NCNN_COMMAND_H
  16 +#define NCNN_COMMAND_H
  17 +
  18 +#include "platform.h"
  19 +
  20 +#if NCNN_VULKAN
  21 +
  22 +#include "mat.h"
  23 +
  24 +namespace ncnn {
  25 +
  26 +class Pipeline;
  27 +#if NCNN_PLATFORM_API
  28 +#if __ANDROID_API__ >= 26
  29 +class ImportAndroidHardwareBufferPipeline;
  30 +#endif // __ANDROID_API__ >= 26
  31 +#endif // NCNN_PLATFORM_API
  32 +class VkComputePrivate;
  33 +class NCNN_EXPORT VkCompute
  34 +{
  35 +public:
  36 + explicit VkCompute(const VulkanDevice* vkdev);
  37 + virtual ~VkCompute();
  38 +
  39 +public:
  40 + void record_upload(const Mat& src, VkMat& dst, const Option& opt);
  41 +
  42 + void record_upload(const Mat& src, VkImageMat& dst, const Option& opt);
  43 +
  44 + void record_download(const VkMat& src, Mat& dst, const Option& opt);
  45 +
  46 + void record_download(const VkImageMat& src, Mat& dst, const Option& opt);
  47 +
  48 + void record_buffer_to_image(const VkMat& src, VkImageMat& dst, const Option& opt);
  49 +
  50 + void record_image_to_buffer(const VkImageMat& src, VkMat& dst, const Option& opt);
  51 +
  52 + void record_clone(const Mat& src, VkMat& dst, const Option& opt);
  53 +
  54 + void record_clone(const Mat& src, VkImageMat& dst, const Option& opt);
  55 +
  56 + void record_clone(const VkMat& src, Mat& dst, const Option& opt);
  57 +
  58 + void record_clone(const VkImageMat& src, Mat& dst, const Option& opt);
  59 +
  60 + void record_clone(const VkMat& src, VkMat& dst, const Option& opt);
  61 +
  62 + void record_clone(const VkImageMat& src, VkImageMat& dst, const Option& opt);
  63 +
  64 + void record_clone(const VkMat& src, VkImageMat& dst, const Option& opt);
  65 +
  66 + void record_clone(const VkImageMat& src, VkMat& dst, const Option& opt);
  67 +
  68 + void record_pipeline(const Pipeline* pipeline, const std::vector<VkMat>& bindings, const std::vector<vk_constant_type>& constants, const VkMat& dispatcher);
  69 +
  70 + void record_pipeline(const Pipeline* pipeline, const std::vector<VkImageMat>& bindings, const std::vector<vk_constant_type>& constants, const VkImageMat& dispatcher);
  71 +
  72 + void record_pipeline(const Pipeline* pipeline, const std::vector<VkMat>& buffer_bindings, const std::vector<VkImageMat>& image_bindings, const std::vector<vk_constant_type>& constants, const VkMat& dispatcher);
  73 + void record_pipeline(const Pipeline* pipeline, const std::vector<VkMat>& buffer_bindings, const std::vector<VkImageMat>& image_bindings, const std::vector<vk_constant_type>& constants, const VkImageMat& dispatcher);
  74 + void record_pipeline(const Pipeline* pipeline, const std::vector<VkMat>& buffer_bindings, const std::vector<VkImageMat>& image_bindings, const std::vector<vk_constant_type>& constants, const Mat& dispatcher);
  75 +
  76 +#if NCNN_BENCHMARK
  77 + void record_write_timestamp(uint32_t query);
  78 +#endif // NCNN_BENCHMARK
  79 +
  80 +#if NCNN_PLATFORM_API
  81 +#if __ANDROID_API__ >= 26
  82 + void record_import_android_hardware_buffer(const ImportAndroidHardwareBufferPipeline* pipeline, const VkImageMat& src, const VkMat& dst);
  83 +
  84 + void record_import_android_hardware_buffer(const ImportAndroidHardwareBufferPipeline* pipeline, const VkImageMat& src, const VkImageMat& dst);
  85 +#endif // __ANDROID_API__ >= 26
  86 +#endif // NCNN_PLATFORM_API
  87 +
  88 + int submit_and_wait();
  89 +
  90 + int reset();
  91 +
  92 +#if NCNN_BENCHMARK
  93 + int create_query_pool(uint32_t query_count);
  94 +
  95 + int get_query_pool_results(uint32_t first_query, uint32_t query_count, std::vector<uint64_t>& results);
  96 +#endif // NCNN_BENCHMARK
  97 +
  98 +protected:
  99 + const VulkanDevice* vkdev;
  100 +
  101 + void barrier_readwrite(const VkMat& binding);
  102 + void barrier_readwrite(const VkImageMat& binding);
  103 + void barrier_readonly(const VkImageMat& binding);
  104 +
  105 +private:
  106 + VkComputePrivate* const d;
  107 +};
  108 +
  109 +class VkTransferPrivate;
  110 +class NCNN_EXPORT VkTransfer
  111 +{
  112 +public:
  113 + explicit VkTransfer(const VulkanDevice* vkdev);
  114 + virtual ~VkTransfer();
  115 +
  116 +public:
  117 + void record_upload(const Mat& src, VkMat& dst, const Option& opt, bool flatten = true);
  118 +
  119 + void record_upload(const Mat& src, VkImageMat& dst, const Option& opt);
  120 +
  121 + int submit_and_wait();
  122 +
  123 +protected:
  124 + const VulkanDevice* vkdev;
  125 +
  126 +private:
  127 + VkTransferPrivate* const d;
  128 +};
  129 +
  130 +} // namespace ncnn
  131 +
  132 +#endif // NCNN_VULKAN
  133 +
  134 +#endif // NCNN_COMMAND_H