mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-20 16:31:57 +09:00
Compare commits
31
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6c51d0711 | ||
|
|
2ec8e7f4a1 | ||
|
|
bf3e6f8ad3 | ||
|
|
2bd86664ec | ||
|
|
2d86e07ab6 | ||
|
|
71aa995128 | ||
|
|
98d0b96cbe | ||
|
|
16bfab1032 | ||
|
|
91d0cb78c7 | ||
|
|
5968863fb9 | ||
|
|
f98f2067db | ||
|
|
b3155525e8 | ||
|
|
8cd00f42fd | ||
|
|
e50463dc5c | ||
|
|
743d1facba | ||
|
|
570ebde9bc | ||
|
|
e766351299 | ||
|
|
15bd9a676c | ||
|
|
2afa000295 | ||
|
|
f6a0bd3024 | ||
|
|
1039502ee6 | ||
|
|
94e2f2e0d8 | ||
|
|
ea9fc7fa71 | ||
|
|
b0f4f8b744 | ||
|
|
207c31f6db | ||
|
|
e156ea5f7a | ||
|
|
a351836154 | ||
|
|
f4cbaa8945 | ||
|
|
a54ae47ab9 | ||
|
|
0bbe41c291 | ||
|
|
785fed0b00 |
@@ -61,40 +61,15 @@ if ! grep -Eq '^lib/[^/]+/libMobileGL\.so$' <<<"$plugin_contents"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# The render server is not trace-only: both flavors carry the control screen, the offscreen
|
||||
# service, the on-screen display activity, and (split native builds) the supervisor executable.
|
||||
# The plugin APK ships to users, so its build keeps the three components private (manifest
|
||||
# placeholder serverComponentsExported=false); only the debuggable trace APK exports them for adb.
|
||||
for component in ServerControlActivity MobileGLServerService MobileGLDisplayActivity; do
|
||||
require "$component" "$plugin_manifest" "plugin render server component ($component)"
|
||||
require "$component" "$trace_manifest" "trace render server component ($component)"
|
||||
done
|
||||
if [[ "${MOBILEGL_CI_DISAGGREGATED:-OFF}" == "ON" ]]; then
|
||||
trace_contents=$(unzip -Z1 "$trace_apk")
|
||||
for entry in "plugin:${plugin_contents}" "trace:${trace_contents}"; do
|
||||
if ! grep -Eq '^lib/[^/]+/libMobileGLServer\.so$' <<<"${entry#*:}"; then
|
||||
echo "::error::${entry%%:*} APK does not contain libMobileGLServer.so (both flavors ship the render server)" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
require 'top.mobilegl.plugin.trace' "$trace_manifest" 'trace package name'
|
||||
require 'top.mobilegl.plugin.TRACE_REPLAY' "$trace_manifest" 'trace replay action'
|
||||
if grep -Fq 'fclPlugin' <<<"$trace_manifest"; then
|
||||
echo '::error::Trace APK must not advertise renderer-plugin metadata' >&2
|
||||
exit 1
|
||||
fi
|
||||
# The trace APK IS a launchable app now: PostActivity (the POST self-test screen) is its
|
||||
# entry icon and the bottom navigation bar switches to the render server screen. What is
|
||||
# left of the old "no launcher" contract is the count - exactly ONE MAIN activity, so a
|
||||
# screen that accidentally grows a launcher entry (ServerControlActivity was one for a day)
|
||||
# reds here instead of shipping two icons.
|
||||
main_count=$(grep -Fc 'android.intent.action.MAIN' <<<"$trace_manifest")
|
||||
if [[ "$main_count" -ne 1 ]]; then
|
||||
echo "::error::Trace APK must expose exactly one launcher activity (PostActivity); found ${main_count} android.intent.action.MAIN" >&2
|
||||
if grep -Fq 'android.intent.action.MAIN' <<<"$trace_manifest"; then
|
||||
echo '::error::Trace APK must not expose a launcher activity' >&2
|
||||
exit 1
|
||||
fi
|
||||
require 'PostActivity' "$trace_manifest" 'trace launcher activity (PostActivity)'
|
||||
|
||||
echo 'Validated unified MobileGL plugin APK and isolated trace APK.'
|
||||
|
||||
@@ -11,19 +11,8 @@ on:
|
||||
# someone remembering to dispatch the workflow by hand.
|
||||
- feat/disaggregated
|
||||
- codex/fix-github-ci
|
||||
# A docs-only push builds nothing this workflow tests (231 emulator legs per run). The Test
|
||||
# workflow keeps running for docs: it hosts the doc citation lint.
|
||||
paths-ignore:
|
||||
- 'docs/**'
|
||||
- '**/*.md'
|
||||
workflow_dispatch:
|
||||
|
||||
# ONE LIVE RUN PER BRANCH, as in test.yml: a superseded push is cancelled rather than left queued
|
||||
# behind its successor; a manual dispatch gets a group of its own; dev queues rather than cancels.
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event_name == 'workflow_dispatch' && github.run_id || github.ref }}
|
||||
cancel-in-progress: ${{ github.event_name == 'push' && github.ref != 'refs/heads/dev' }}
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -364,7 +353,7 @@ jobs:
|
||||
--avd-name "${AVD_NAME}"
|
||||
|
||||
retrace:
|
||||
name: retrace (${{ matrix.backend.name }} / ${{ matrix.transport || 'monolith' }}, ${{ matrix.case.name }})
|
||||
name: retrace (${{ matrix.backend.name }} / ${{ matrix.lane || 'monolith-control' }} / ${{ matrix.transport || 'monolith' }}, ${{ matrix.case.name }})
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- build
|
||||
@@ -385,7 +374,7 @@ jobs:
|
||||
max-parallel: 4
|
||||
matrix: ${{ fromJSON(needs.trace-cases.outputs.android) }}
|
||||
steps:
|
||||
- name: Set swap space
|
||||
- name: Set Swap Space
|
||||
uses: pierotofy/set-swap-space@v1.0
|
||||
with:
|
||||
swap-size-gb: 8
|
||||
@@ -454,7 +443,7 @@ jobs:
|
||||
--profile pixel_6 \
|
||||
--avd-name "${AVD_NAME}"
|
||||
|
||||
- name: Launch emulator
|
||||
- name: Launch Emulator
|
||||
run: |
|
||||
sh android-plugin/run-avd-ci.sh start \
|
||||
--avd-name "${AVD_NAME}" \
|
||||
@@ -611,7 +600,7 @@ jobs:
|
||||
free -h > android-retrace-result/diagnostics/host-memory.txt 2>&1 || true
|
||||
sudo dmesg -T 2>/dev/null | tail -300 > android-retrace-result/diagnostics/host-dmesg.txt || true
|
||||
|
||||
- name: Stop emulator
|
||||
- name: Stop Emulator
|
||||
if: always()
|
||||
run: |
|
||||
sh android-plugin/run-avd-ci.sh stop \
|
||||
|
||||
+67
-705
File diff suppressed because it is too large
Load Diff
@@ -28,4 +28,3 @@ tools/trace_replay/work/
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
/.gradle
|
||||
/.trace-work/
|
||||
|
||||
Vendored
-538
@@ -1,538 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2011 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Benjamin Franzke <benjaminfranzke@googlemail.com>
|
||||
*/
|
||||
|
||||
#ifndef _GBM_H_
|
||||
#define _GBM_H_
|
||||
|
||||
#define __GBM__ 1
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* \file gbm.h
|
||||
* \brief Generic Buffer Manager
|
||||
*/
|
||||
|
||||
struct gbm_device;
|
||||
struct gbm_bo;
|
||||
struct gbm_surface;
|
||||
|
||||
/**
|
||||
* \mainpage The Generic Buffer Manager
|
||||
*
|
||||
* This module provides an abstraction that the caller can use to request a
|
||||
* buffer from the underlying memory management system for the platform.
|
||||
*
|
||||
* This allows the creation of portable code whilst still allowing access to
|
||||
* the underlying memory manager.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstraction representing the handle to a buffer allocated by the
|
||||
* manager
|
||||
*/
|
||||
union gbm_bo_handle {
|
||||
void *ptr;
|
||||
int32_t s32;
|
||||
uint32_t u32;
|
||||
int64_t s64;
|
||||
uint64_t u64;
|
||||
};
|
||||
|
||||
/** Format of the allocated buffer */
|
||||
enum gbm_bo_format {
|
||||
/** RGB with 8 bits per channel in a 32 bit value */
|
||||
GBM_BO_FORMAT_XRGB8888,
|
||||
/** ARGB with 8 bits per channel in a 32 bit value */
|
||||
GBM_BO_FORMAT_ARGB8888
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* The FourCC format codes are taken from the drm_fourcc.h definition, and
|
||||
* re-namespaced. New GBM formats must not be added, unless they are
|
||||
* identical ports from drm_fourcc.
|
||||
*/
|
||||
#define __gbm_fourcc_code(a,b,c,d) ((uint32_t)(a) | ((uint32_t)(b) << 8) | \
|
||||
((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))
|
||||
|
||||
#define GBM_FORMAT_BIG_ENDIAN (1<<31) /* format is big endian instead of little endian */
|
||||
|
||||
/* color index */
|
||||
#define GBM_FORMAT_C8 __gbm_fourcc_code('C', '8', ' ', ' ') /* [7:0] C */
|
||||
|
||||
/* 8 bpp Red */
|
||||
#define GBM_FORMAT_R8 __gbm_fourcc_code('R', '8', ' ', ' ') /* [7:0] R */
|
||||
|
||||
/* 16 bpp Red */
|
||||
#define GBM_FORMAT_R16 __gbm_fourcc_code('R', '1', '6', ' ') /* [15:0] R little endian */
|
||||
|
||||
/* 16 bpp RG */
|
||||
#define GBM_FORMAT_GR88 __gbm_fourcc_code('G', 'R', '8', '8') /* [15:0] G:R 8:8 little endian */
|
||||
|
||||
/* 32 bpp RG */
|
||||
#define GBM_FORMAT_RG1616 __gbm_fourcc_code('R', 'G', '3', '2') /* [31:0] R:G 16:16 little endian */
|
||||
#define GBM_FORMAT_GR1616 __gbm_fourcc_code('G', 'R', '3', '2') /* [31:0] G:R 16:16 little endian */
|
||||
|
||||
/* 8 bpp RGB */
|
||||
#define GBM_FORMAT_RGB332 __gbm_fourcc_code('R', 'G', 'B', '8') /* [7:0] R:G:B 3:3:2 */
|
||||
#define GBM_FORMAT_BGR233 __gbm_fourcc_code('B', 'G', 'R', '8') /* [7:0] B:G:R 2:3:3 */
|
||||
|
||||
/* 16 bpp RGB */
|
||||
#define GBM_FORMAT_XRGB4444 __gbm_fourcc_code('X', 'R', '1', '2') /* [15:0] x:R:G:B 4:4:4:4 little endian */
|
||||
#define GBM_FORMAT_XBGR4444 __gbm_fourcc_code('X', 'B', '1', '2') /* [15:0] x:B:G:R 4:4:4:4 little endian */
|
||||
#define GBM_FORMAT_RGBX4444 __gbm_fourcc_code('R', 'X', '1', '2') /* [15:0] R:G:B:x 4:4:4:4 little endian */
|
||||
#define GBM_FORMAT_BGRX4444 __gbm_fourcc_code('B', 'X', '1', '2') /* [15:0] B:G:R:x 4:4:4:4 little endian */
|
||||
|
||||
#define GBM_FORMAT_ARGB4444 __gbm_fourcc_code('A', 'R', '1', '2') /* [15:0] A:R:G:B 4:4:4:4 little endian */
|
||||
#define GBM_FORMAT_ABGR4444 __gbm_fourcc_code('A', 'B', '1', '2') /* [15:0] A:B:G:R 4:4:4:4 little endian */
|
||||
#define GBM_FORMAT_RGBA4444 __gbm_fourcc_code('R', 'A', '1', '2') /* [15:0] R:G:B:A 4:4:4:4 little endian */
|
||||
#define GBM_FORMAT_BGRA4444 __gbm_fourcc_code('B', 'A', '1', '2') /* [15:0] B:G:R:A 4:4:4:4 little endian */
|
||||
|
||||
#define GBM_FORMAT_XRGB1555 __gbm_fourcc_code('X', 'R', '1', '5') /* [15:0] x:R:G:B 1:5:5:5 little endian */
|
||||
#define GBM_FORMAT_XBGR1555 __gbm_fourcc_code('X', 'B', '1', '5') /* [15:0] x:B:G:R 1:5:5:5 little endian */
|
||||
#define GBM_FORMAT_RGBX5551 __gbm_fourcc_code('R', 'X', '1', '5') /* [15:0] R:G:B:x 5:5:5:1 little endian */
|
||||
#define GBM_FORMAT_BGRX5551 __gbm_fourcc_code('B', 'X', '1', '5') /* [15:0] B:G:R:x 5:5:5:1 little endian */
|
||||
|
||||
#define GBM_FORMAT_ARGB1555 __gbm_fourcc_code('A', 'R', '1', '5') /* [15:0] A:R:G:B 1:5:5:5 little endian */
|
||||
#define GBM_FORMAT_ABGR1555 __gbm_fourcc_code('A', 'B', '1', '5') /* [15:0] A:B:G:R 1:5:5:5 little endian */
|
||||
#define GBM_FORMAT_RGBA5551 __gbm_fourcc_code('R', 'A', '1', '5') /* [15:0] R:G:B:A 5:5:5:1 little endian */
|
||||
#define GBM_FORMAT_BGRA5551 __gbm_fourcc_code('B', 'A', '1', '5') /* [15:0] B:G:R:A 5:5:5:1 little endian */
|
||||
|
||||
#define GBM_FORMAT_RGB565 __gbm_fourcc_code('R', 'G', '1', '6') /* [15:0] R:G:B 5:6:5 little endian */
|
||||
#define GBM_FORMAT_BGR565 __gbm_fourcc_code('B', 'G', '1', '6') /* [15:0] B:G:R 5:6:5 little endian */
|
||||
|
||||
/* 24 bpp RGB */
|
||||
#define GBM_FORMAT_RGB888 __gbm_fourcc_code('R', 'G', '2', '4') /* [23:0] R:G:B little endian */
|
||||
#define GBM_FORMAT_BGR888 __gbm_fourcc_code('B', 'G', '2', '4') /* [23:0] B:G:R little endian */
|
||||
|
||||
/* 32 bpp RGB */
|
||||
#define GBM_FORMAT_XRGB8888 __gbm_fourcc_code('X', 'R', '2', '4') /* [31:0] x:R:G:B 8:8:8:8 little endian */
|
||||
#define GBM_FORMAT_XBGR8888 __gbm_fourcc_code('X', 'B', '2', '4') /* [31:0] x:B:G:R 8:8:8:8 little endian */
|
||||
#define GBM_FORMAT_RGBX8888 __gbm_fourcc_code('R', 'X', '2', '4') /* [31:0] R:G:B:x 8:8:8:8 little endian */
|
||||
#define GBM_FORMAT_BGRX8888 __gbm_fourcc_code('B', 'X', '2', '4') /* [31:0] B:G:R:x 8:8:8:8 little endian */
|
||||
|
||||
#define GBM_FORMAT_ARGB8888 __gbm_fourcc_code('A', 'R', '2', '4') /* [31:0] A:R:G:B 8:8:8:8 little endian */
|
||||
#define GBM_FORMAT_ABGR8888 __gbm_fourcc_code('A', 'B', '2', '4') /* [31:0] A:B:G:R 8:8:8:8 little endian */
|
||||
#define GBM_FORMAT_RGBA8888 __gbm_fourcc_code('R', 'A', '2', '4') /* [31:0] R:G:B:A 8:8:8:8 little endian */
|
||||
#define GBM_FORMAT_BGRA8888 __gbm_fourcc_code('B', 'A', '2', '4') /* [31:0] B:G:R:A 8:8:8:8 little endian */
|
||||
|
||||
#define GBM_FORMAT_XRGB2101010 __gbm_fourcc_code('X', 'R', '3', '0') /* [31:0] x:R:G:B 2:10:10:10 little endian */
|
||||
#define GBM_FORMAT_XBGR2101010 __gbm_fourcc_code('X', 'B', '3', '0') /* [31:0] x:B:G:R 2:10:10:10 little endian */
|
||||
#define GBM_FORMAT_RGBX1010102 __gbm_fourcc_code('R', 'X', '3', '0') /* [31:0] R:G:B:x 10:10:10:2 little endian */
|
||||
#define GBM_FORMAT_BGRX1010102 __gbm_fourcc_code('B', 'X', '3', '0') /* [31:0] B:G:R:x 10:10:10:2 little endian */
|
||||
|
||||
#define GBM_FORMAT_ARGB2101010 __gbm_fourcc_code('A', 'R', '3', '0') /* [31:0] A:R:G:B 2:10:10:10 little endian */
|
||||
#define GBM_FORMAT_ABGR2101010 __gbm_fourcc_code('A', 'B', '3', '0') /* [31:0] A:B:G:R 2:10:10:10 little endian */
|
||||
#define GBM_FORMAT_RGBA1010102 __gbm_fourcc_code('R', 'A', '3', '0') /* [31:0] R:G:B:A 10:10:10:2 little endian */
|
||||
#define GBM_FORMAT_BGRA1010102 __gbm_fourcc_code('B', 'A', '3', '0') /* [31:0] B:G:R:A 10:10:10:2 little endian */
|
||||
|
||||
/* 64 bpp RGB */
|
||||
#define GBM_FORMAT_XBGR16161616 __gbm_fourcc_code('X', 'B', '4', '8') /* [63:0] x:B:G:R 16:16:16:16 little endian */
|
||||
|
||||
#define GBM_FORMAT_ABGR16161616 __gbm_fourcc_code('A', 'B', '4', '8') /* [63:0] A:B:G:R 16:16:16:16 little endian */
|
||||
|
||||
/*
|
||||
* Floating point 64bpp RGB
|
||||
* IEEE 754-2008 binary16 half-precision float
|
||||
* [15:0] sign:exponent:mantissa 1:5:10
|
||||
*/
|
||||
#define GBM_FORMAT_XBGR16161616F __gbm_fourcc_code('X', 'B', '4', 'H') /* [63:0] x:B:G:R 16:16:16:16 little endian */
|
||||
|
||||
#define GBM_FORMAT_ABGR16161616F __gbm_fourcc_code('A', 'B', '4', 'H') /* [63:0] A:B:G:R 16:16:16:16 little endian */
|
||||
|
||||
/* packed YCbCr */
|
||||
#define GBM_FORMAT_YUYV __gbm_fourcc_code('Y', 'U', 'Y', 'V') /* [31:0] Cr0:Y1:Cb0:Y0 8:8:8:8 little endian */
|
||||
#define GBM_FORMAT_YVYU __gbm_fourcc_code('Y', 'V', 'Y', 'U') /* [31:0] Cb0:Y1:Cr0:Y0 8:8:8:8 little endian */
|
||||
#define GBM_FORMAT_UYVY __gbm_fourcc_code('U', 'Y', 'V', 'Y') /* [31:0] Y1:Cr0:Y0:Cb0 8:8:8:8 little endian */
|
||||
#define GBM_FORMAT_VYUY __gbm_fourcc_code('V', 'Y', 'U', 'Y') /* [31:0] Y1:Cb0:Y0:Cr0 8:8:8:8 little endian */
|
||||
|
||||
#define GBM_FORMAT_AYUV __gbm_fourcc_code('A', 'Y', 'U', 'V') /* [31:0] A:Y:Cb:Cr 8:8:8:8 little endian */
|
||||
|
||||
/*
|
||||
* 2 plane YCbCr
|
||||
* index 0 = Y plane, [7:0] Y
|
||||
* index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian
|
||||
* or
|
||||
* index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian
|
||||
*/
|
||||
#define GBM_FORMAT_NV12 __gbm_fourcc_code('N', 'V', '1', '2') /* 2x2 subsampled Cr:Cb plane */
|
||||
#define GBM_FORMAT_NV21 __gbm_fourcc_code('N', 'V', '2', '1') /* 2x2 subsampled Cb:Cr plane */
|
||||
#define GBM_FORMAT_NV16 __gbm_fourcc_code('N', 'V', '1', '6') /* 2x1 subsampled Cr:Cb plane */
|
||||
#define GBM_FORMAT_NV61 __gbm_fourcc_code('N', 'V', '6', '1') /* 2x1 subsampled Cb:Cr plane */
|
||||
|
||||
/*
|
||||
* 3 plane YCbCr
|
||||
* index 0: Y plane, [7:0] Y
|
||||
* index 1: Cb plane, [7:0] Cb
|
||||
* index 2: Cr plane, [7:0] Cr
|
||||
* or
|
||||
* index 1: Cr plane, [7:0] Cr
|
||||
* index 2: Cb plane, [7:0] Cb
|
||||
*/
|
||||
#define GBM_FORMAT_YUV410 __gbm_fourcc_code('Y', 'U', 'V', '9') /* 4x4 subsampled Cb (1) and Cr (2) planes */
|
||||
#define GBM_FORMAT_YVU410 __gbm_fourcc_code('Y', 'V', 'U', '9') /* 4x4 subsampled Cr (1) and Cb (2) planes */
|
||||
#define GBM_FORMAT_YUV411 __gbm_fourcc_code('Y', 'U', '1', '1') /* 4x1 subsampled Cb (1) and Cr (2) planes */
|
||||
#define GBM_FORMAT_YVU411 __gbm_fourcc_code('Y', 'V', '1', '1') /* 4x1 subsampled Cr (1) and Cb (2) planes */
|
||||
#define GBM_FORMAT_YUV420 __gbm_fourcc_code('Y', 'U', '1', '2') /* 2x2 subsampled Cb (1) and Cr (2) planes */
|
||||
#define GBM_FORMAT_YVU420 __gbm_fourcc_code('Y', 'V', '1', '2') /* 2x2 subsampled Cr (1) and Cb (2) planes */
|
||||
#define GBM_FORMAT_YUV422 __gbm_fourcc_code('Y', 'U', '1', '6') /* 2x1 subsampled Cb (1) and Cr (2) planes */
|
||||
#define GBM_FORMAT_YVU422 __gbm_fourcc_code('Y', 'V', '1', '6') /* 2x1 subsampled Cr (1) and Cb (2) planes */
|
||||
#define GBM_FORMAT_YUV444 __gbm_fourcc_code('Y', 'U', '2', '4') /* non-subsampled Cb (1) and Cr (2) planes */
|
||||
#define GBM_FORMAT_YVU444 __gbm_fourcc_code('Y', 'V', '2', '4') /* non-subsampled Cr (1) and Cb (2) planes */
|
||||
|
||||
struct gbm_format_name_desc {
|
||||
char name[5];
|
||||
};
|
||||
|
||||
/**
|
||||
* Flags to indicate the intended use for the buffer - these are passed into
|
||||
* gbm_bo_create(). The caller must set the union of all the flags that are
|
||||
* appropriate
|
||||
*
|
||||
* \sa Use gbm_device_is_format_supported() to check if the combination of format
|
||||
* and use flags are supported
|
||||
*/
|
||||
enum gbm_bo_flags {
|
||||
/**
|
||||
* Buffer is going to be presented to the screen using an API such as KMS
|
||||
*/
|
||||
GBM_BO_USE_SCANOUT = (1 << 0),
|
||||
/**
|
||||
* Buffer is going to be used as cursor
|
||||
*/
|
||||
GBM_BO_USE_CURSOR = (1 << 1),
|
||||
/**
|
||||
* Deprecated
|
||||
*/
|
||||
GBM_BO_USE_CURSOR_64X64 = GBM_BO_USE_CURSOR,
|
||||
/**
|
||||
* Buffer is to be used for rendering - for example it is going to be used
|
||||
* as the storage for a color buffer
|
||||
*/
|
||||
GBM_BO_USE_RENDERING = (1 << 2),
|
||||
/**
|
||||
* Buffer can be used for gbm_bo_write. This is guaranteed to work
|
||||
* with GBM_BO_USE_CURSOR, but may not work for other combinations.
|
||||
*/
|
||||
GBM_BO_USE_WRITE = (1 << 3),
|
||||
/**
|
||||
* Buffer is linear, i.e. not tiled.
|
||||
*/
|
||||
GBM_BO_USE_LINEAR = (1 << 4),
|
||||
/**
|
||||
* Buffer is protected, i.e. encrypted and not readable by CPU or any
|
||||
* other non-secure / non-trusted components nor by non-trusted OpenGL,
|
||||
* OpenCL, and Vulkan applications.
|
||||
*/
|
||||
GBM_BO_USE_PROTECTED = (1 << 5),
|
||||
|
||||
/**
|
||||
* The buffer will be used for front buffer rendering. On some
|
||||
* platforms this may (for example) disable framebuffer compression
|
||||
* to avoid problems with compression flags data being out of sync
|
||||
* with pixel data.
|
||||
*/
|
||||
GBM_BO_USE_FRONT_RENDERING = (1 << 6),
|
||||
|
||||
/**
|
||||
* Allow the driver to select fixed-rate compression parameters.
|
||||
*/
|
||||
GBM_BO_FIXED_COMPRESSION_DEFAULT = (1 << 7),
|
||||
|
||||
/**
|
||||
* Fixed-rate compression: at least 1bpc, less than 2bpc
|
||||
*/
|
||||
GBM_BO_FIXED_COMPRESSION_1BPC = (2 << 7),
|
||||
|
||||
/**
|
||||
* Fixed-rate compression: at least 2bpc, less than 3bpc
|
||||
*/
|
||||
GBM_BO_FIXED_COMPRESSION_2BPC = (3 << 7),
|
||||
|
||||
/**
|
||||
* Fixed-rate compression: at least 3bpc, less than 4bpc
|
||||
*/
|
||||
GBM_BO_FIXED_COMPRESSION_3BPC = (4 << 7),
|
||||
|
||||
/**
|
||||
* Fixed-rate compression: at least 4bpc, less than 5bpc
|
||||
*/
|
||||
GBM_BO_FIXED_COMPRESSION_4BPC = (5 << 7),
|
||||
|
||||
/**
|
||||
* Fixed-rate compression: at least 5bpc, less than 6bpc
|
||||
*/
|
||||
GBM_BO_FIXED_COMPRESSION_5BPC = (6 << 7),
|
||||
|
||||
/**
|
||||
* Fixed-rate compression: at least 6bpc, less than 7bpc
|
||||
*/
|
||||
GBM_BO_FIXED_COMPRESSION_6BPC = (7 << 7),
|
||||
|
||||
/**
|
||||
* Fixed-rate compression: at least 7bpc, less than 8bpc
|
||||
*/
|
||||
GBM_BO_FIXED_COMPRESSION_7BPC = (8 << 7),
|
||||
|
||||
/**
|
||||
* Fixed-rate compression: at least 8bpc, less than 9bpc
|
||||
*/
|
||||
GBM_BO_FIXED_COMPRESSION_8BPC = (9 << 7),
|
||||
|
||||
/**
|
||||
* Fixed-rate compression: at least 9bpc, less than 10bpc
|
||||
*/
|
||||
GBM_BO_FIXED_COMPRESSION_9BPC = (10 << 7),
|
||||
|
||||
/**
|
||||
* Fixed-rate compression: at least 10bpc, less than 11bpc
|
||||
*/
|
||||
GBM_BO_FIXED_COMPRESSION_10BPC = (11 << 7),
|
||||
|
||||
/**
|
||||
* Fixed-rate compression: at least 11bpc, less than 12bpc
|
||||
*/
|
||||
GBM_BO_FIXED_COMPRESSION_11BPC = (12 << 7),
|
||||
|
||||
/**
|
||||
* Fixed-rate compression: at least 12bpc, no maximum rate
|
||||
*/
|
||||
GBM_BO_FIXED_COMPRESSION_12BPC = (13 << 7),
|
||||
|
||||
/* next available value is (1 << 11) */
|
||||
};
|
||||
|
||||
#define GBM_BO_FIXED_COMPRESSION_MASK (((1 << 11) - 1) & ~((1 << 7) - 1))
|
||||
|
||||
int
|
||||
gbm_device_get_fd(struct gbm_device *gbm);
|
||||
|
||||
const char *
|
||||
gbm_device_get_backend_name(struct gbm_device *gbm);
|
||||
|
||||
int
|
||||
gbm_device_is_format_supported(struct gbm_device *gbm,
|
||||
uint32_t format, uint32_t flags);
|
||||
|
||||
int
|
||||
gbm_device_get_format_modifier_plane_count(struct gbm_device *gbm,
|
||||
uint32_t format,
|
||||
uint64_t modifier);
|
||||
|
||||
void
|
||||
gbm_device_destroy(struct gbm_device *gbm);
|
||||
|
||||
struct gbm_device *
|
||||
gbm_create_device(int fd);
|
||||
|
||||
struct gbm_bo *
|
||||
gbm_bo_create(struct gbm_device *gbm,
|
||||
uint32_t width, uint32_t height,
|
||||
uint32_t format, uint32_t flags);
|
||||
|
||||
struct gbm_bo *
|
||||
gbm_bo_create_with_modifiers(struct gbm_device *gbm,
|
||||
uint32_t width, uint32_t height,
|
||||
uint32_t format,
|
||||
const uint64_t *modifiers,
|
||||
const unsigned int count);
|
||||
|
||||
struct gbm_bo *
|
||||
gbm_bo_create_with_modifiers2(struct gbm_device *gbm,
|
||||
uint32_t width, uint32_t height,
|
||||
uint32_t format,
|
||||
const uint64_t *modifiers,
|
||||
const unsigned int count,
|
||||
uint32_t flags);
|
||||
|
||||
#define GBM_BO_IMPORT_WL_BUFFER 0x5501
|
||||
#define GBM_BO_IMPORT_EGL_IMAGE 0x5502
|
||||
#define GBM_BO_IMPORT_FD 0x5503
|
||||
#define GBM_BO_IMPORT_FD_MODIFIER 0x5504
|
||||
|
||||
struct gbm_import_fd_data {
|
||||
int fd;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t stride;
|
||||
uint32_t format;
|
||||
};
|
||||
|
||||
#define GBM_MAX_PLANES 4
|
||||
|
||||
struct gbm_import_fd_modifier_data {
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t format;
|
||||
uint32_t num_fds;
|
||||
int fds[GBM_MAX_PLANES];
|
||||
int strides[GBM_MAX_PLANES];
|
||||
int offsets[GBM_MAX_PLANES];
|
||||
uint64_t modifier;
|
||||
};
|
||||
|
||||
struct gbm_bo *
|
||||
gbm_bo_import(struct gbm_device *gbm, uint32_t type,
|
||||
void *buffer, uint32_t flags);
|
||||
|
||||
/**
|
||||
* Flags to indicate the type of mapping for the buffer - these are
|
||||
* passed into gbm_bo_map(). The caller must set the union of all the
|
||||
* flags that are appropriate.
|
||||
*
|
||||
* These flags are independent of the GBM_BO_USE_* creation flags. However,
|
||||
* mapping the buffer may require copying to/from a staging buffer.
|
||||
*
|
||||
* See also: pipe_map_flags
|
||||
*/
|
||||
enum gbm_bo_transfer_flags {
|
||||
/**
|
||||
* Buffer contents read back (or accessed directly) at transfer
|
||||
* create time.
|
||||
*/
|
||||
GBM_BO_TRANSFER_READ = (1 << 0),
|
||||
/**
|
||||
* Buffer contents will be written back at unmap time
|
||||
* (or modified as a result of being accessed directly).
|
||||
*/
|
||||
GBM_BO_TRANSFER_WRITE = (1 << 1),
|
||||
/**
|
||||
* Read/modify/write
|
||||
*/
|
||||
GBM_BO_TRANSFER_READ_WRITE = (GBM_BO_TRANSFER_READ | GBM_BO_TRANSFER_WRITE),
|
||||
};
|
||||
|
||||
void *
|
||||
gbm_bo_map(struct gbm_bo *bo,
|
||||
uint32_t x, uint32_t y, uint32_t width, uint32_t height,
|
||||
uint32_t flags, uint32_t *stride, void **map_data);
|
||||
|
||||
void
|
||||
gbm_bo_unmap(struct gbm_bo *bo, void *map_data);
|
||||
|
||||
uint32_t
|
||||
gbm_bo_get_width(struct gbm_bo *bo);
|
||||
|
||||
uint32_t
|
||||
gbm_bo_get_height(struct gbm_bo *bo);
|
||||
|
||||
uint32_t
|
||||
gbm_bo_get_stride(struct gbm_bo *bo);
|
||||
|
||||
uint32_t
|
||||
gbm_bo_get_stride_for_plane(struct gbm_bo *bo, int plane);
|
||||
|
||||
uint32_t
|
||||
gbm_bo_get_format(struct gbm_bo *bo);
|
||||
|
||||
uint32_t
|
||||
gbm_bo_get_bpp(struct gbm_bo *bo);
|
||||
|
||||
uint32_t
|
||||
gbm_bo_get_offset(struct gbm_bo *bo, int plane);
|
||||
|
||||
struct gbm_device *
|
||||
gbm_bo_get_device(struct gbm_bo *bo);
|
||||
|
||||
union gbm_bo_handle
|
||||
gbm_bo_get_handle(struct gbm_bo *bo);
|
||||
|
||||
int
|
||||
gbm_bo_get_fd(struct gbm_bo *bo);
|
||||
|
||||
uint64_t
|
||||
gbm_bo_get_modifier(struct gbm_bo *bo);
|
||||
|
||||
int
|
||||
gbm_bo_get_plane_count(struct gbm_bo *bo);
|
||||
|
||||
union gbm_bo_handle
|
||||
gbm_bo_get_handle_for_plane(struct gbm_bo *bo, int plane);
|
||||
|
||||
int
|
||||
gbm_bo_get_fd_for_plane(struct gbm_bo *bo, int plane);
|
||||
|
||||
int
|
||||
gbm_bo_write(struct gbm_bo *bo, const void *buf, size_t count);
|
||||
|
||||
void
|
||||
gbm_bo_set_user_data(struct gbm_bo *bo, void *data,
|
||||
void (*destroy_user_data)(struct gbm_bo *, void *));
|
||||
|
||||
void *
|
||||
gbm_bo_get_user_data(struct gbm_bo *bo);
|
||||
|
||||
void
|
||||
gbm_bo_destroy(struct gbm_bo *bo);
|
||||
|
||||
struct gbm_surface *
|
||||
gbm_surface_create(struct gbm_device *gbm,
|
||||
uint32_t width, uint32_t height,
|
||||
uint32_t format, uint32_t flags);
|
||||
|
||||
struct gbm_surface *
|
||||
gbm_surface_create_with_modifiers(struct gbm_device *gbm,
|
||||
uint32_t width, uint32_t height,
|
||||
uint32_t format,
|
||||
const uint64_t *modifiers,
|
||||
const unsigned int count);
|
||||
|
||||
struct gbm_surface *
|
||||
gbm_surface_create_with_modifiers2(struct gbm_device *gbm,
|
||||
uint32_t width, uint32_t height,
|
||||
uint32_t format,
|
||||
const uint64_t *modifiers,
|
||||
const unsigned int count,
|
||||
uint32_t flags);
|
||||
|
||||
struct gbm_bo *
|
||||
gbm_surface_lock_front_buffer(struct gbm_surface *surface);
|
||||
|
||||
void
|
||||
gbm_surface_release_buffer(struct gbm_surface *surface, struct gbm_bo *bo);
|
||||
|
||||
int
|
||||
gbm_surface_has_free_buffers(struct gbm_surface *surface);
|
||||
|
||||
void
|
||||
gbm_surface_destroy(struct gbm_surface *surface);
|
||||
|
||||
char *
|
||||
gbm_format_get_name(uint32_t gbm_format, struct gbm_format_name_desc *desc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Vendored
-11
@@ -1,11 +0,0 @@
|
||||
# glvnd vendor ABI headers
|
||||
|
||||
'libeglabi.h' and 'GLdispatchABI.h' from libglvnd (MIT), copied verbatim with their own licence
|
||||
headers intact.
|
||||
|
||||
They are here because MobileGL implements the *vendor* half of glvnd's EGL ABI - the side a library
|
||||
exposes so the system's 'libEGL.so.1', which IS glvnd, can dispatch to it. The distribution ships
|
||||
the runtime but not these headers in the base image, and a vendored copy of two MIT headers is a
|
||||
smaller dependency than a build-time download of a source tree.
|
||||
|
||||
Upstream ABI version implemented: 'EGL_VENDOR_ABI_MAJOR_VERSION' 0 (the header pins it).
|
||||
-141
@@ -1,141 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013, NVIDIA CORPORATION.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and/or associated documentation files (the
|
||||
* "Materials"), to deal in the Materials without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Materials, and to
|
||||
* permit persons to whom the Materials are furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* unaltered in all copies or substantial portions of the Materials.
|
||||
* Any additions, deletions, or changes to the original source files
|
||||
* must be clearly indicated in accompanying documentation.
|
||||
*
|
||||
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||
*/
|
||||
|
||||
#include <GL/gl.h>
|
||||
|
||||
#if !defined(__GL_DISPATCH_ABI_H)
|
||||
#define __GL_DISPATCH_ABI_H
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \defgroup gldispatchabi GL dispatching ABI
|
||||
*
|
||||
* This is not a complete ABI, but rather a fragment common to the libEGL and
|
||||
* libGLX ABIs. Changes to this file should be accompanied by a version bump to
|
||||
* these client ABIs.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* Thread-local implementation used by libglvnd. This is passed into the patch
|
||||
* function callback via the type parameter.
|
||||
*
|
||||
* For most architectures, the vendor library can ignore this parameter, since
|
||||
* it will always be the same value. It's used for systems like ARM, where the
|
||||
* stubs might be use the ARM or Thumb instruction sets.
|
||||
*
|
||||
* The stub type does not make any distinction between TLS and TSD stubs. The
|
||||
* entire purpose of entrypoint rewriting is to skip the dispatch table in
|
||||
* libGLdispatch.so, so it doesn't matter how that dispatch table is stored.
|
||||
*/
|
||||
enum {
|
||||
/*!
|
||||
* Indicates that the stubs aren't defined in assembly. For example, if the
|
||||
* dispatch stubs are written in C. Vendor libraries generally won't see
|
||||
* this value.
|
||||
*/
|
||||
__GLDISPATCH_STUB_UNKNOWN,
|
||||
|
||||
/*!
|
||||
* Used for stubs on x86 systems.
|
||||
*/
|
||||
__GLDISPATCH_STUB_X86,
|
||||
|
||||
/*!
|
||||
* Used for stubs on x86-64 systems.
|
||||
*/
|
||||
__GLDISPATCH_STUB_X86_64,
|
||||
|
||||
/*!
|
||||
* Used for stubs on ARMv7, using the Thumb instruction set.
|
||||
*/
|
||||
__GLDISPATCH_STUB_ARMV7_THUMB,
|
||||
|
||||
/*!
|
||||
* Used for stubs on ARMv7, using the normal ARM instruction set.
|
||||
*/
|
||||
__GLDISPATCH_STUB_ARMV7_ARM,
|
||||
|
||||
/*!
|
||||
* Used for stubs on ARMv8/aarch64.
|
||||
*/
|
||||
__GLDISPATCH_STUB_AARCH64,
|
||||
|
||||
/*!
|
||||
* Used for stubs on x32 builds (x86-64 with 32-bit pointers).
|
||||
*/
|
||||
__GLDISPATCH_STUB_X32,
|
||||
|
||||
/*!
|
||||
* Used for stubs on PPC64 systems.
|
||||
*/
|
||||
__GLDISPATCH_STUB_PPC64,
|
||||
|
||||
/*!
|
||||
* Used for stubs on PPC64LE systems. Same as PPC64, for compatibility.
|
||||
*/
|
||||
__GLDISPATCH_STUB_PPC64LE = __GLDISPATCH_STUB_PPC64,
|
||||
|
||||
/*!
|
||||
* Used for stubs on LOONGARCH/loongarch64.
|
||||
*/
|
||||
__GLDISPATCH_STUB_LOONGARCH64,
|
||||
};
|
||||
|
||||
/*!
|
||||
* A callback function called by the vendor library to fetch the address of an
|
||||
* entrypoint.
|
||||
*
|
||||
* The function returns two pointers, one writable and one executable. The two
|
||||
* pointers may or may not be the same virtual address, but they will both be
|
||||
* mappings of the same physical memory.
|
||||
*
|
||||
* The vendor library should write its entrypoint to the address returned by
|
||||
* \p writePtr, but should use the address from \p execPtr for things like
|
||||
* calculating PC-relative offsets.
|
||||
*
|
||||
* Note that if this function fails, then the vendor library can still try to
|
||||
* patch other entrypoints.
|
||||
*
|
||||
* Note that on ARM, the low-order bit of both \c execPtr and \p writePtr will
|
||||
* be zero, even if the stub uses the thumb instruction set. The vendor library
|
||||
* should use the \c type parameter of \c initiatePatch to determine which
|
||||
* instruction set to use.
|
||||
*
|
||||
* \param funcName The function name.
|
||||
* \param[out] writePtr The pointer that the vendor library can write to.
|
||||
* \param[out] execPtr The pointer to the executable code.
|
||||
* \return GL_TRUE if the entrypoint exists, or GL_FALSE if it doesn't.
|
||||
*/
|
||||
typedef GLboolean (*DispatchPatchLookupStubOffset)(const char *funcName,
|
||||
void **writePtr, const void **execPtr);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __GL_DISPATCH_ABI_H
|
||||
-464
@@ -1,464 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013, NVIDIA CORPORATION.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and/or associated documentation files (the
|
||||
* "Materials"), to deal in the Materials without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Materials, and to
|
||||
* permit persons to whom the Materials are furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* unaltered in all copies or substantial portions of the Materials.
|
||||
* Any additions, deletions, or changes to the original source files
|
||||
* must be clearly indicated in accompanying documentation.
|
||||
*
|
||||
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||
*/
|
||||
|
||||
#if !defined(__LIB_EGL_ABI_H)
|
||||
#define __LIB_EGL_ABI_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
|
||||
#include "glvnd/GLdispatchABI.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \defgroup eglvendorabi EGL Vendor ABI
|
||||
*
|
||||
* Definition of ABI exported by libEGL.so to libEGL_VENDOR.so libraries.
|
||||
*
|
||||
* Each vendor is associated with three distinct dispatch table types:
|
||||
*
|
||||
* - static EGL dispatch table: this is the fixed list of EGL 1.5 entrypoints
|
||||
* provided by the vendor at load time during the initial handshake.
|
||||
* - dynamic EGL dispatch table: this is a structure allocated by the API
|
||||
* library at runtime used to manage EGL extension functions which are not
|
||||
* present in the static table.
|
||||
* - core GL dispatch table: this is a structure maintained by the API library
|
||||
* which contains both GL core (static) and GL extension (dynamic) functions.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*
|
||||
* Rendering API handling:
|
||||
*
|
||||
* libEGL only supports OpenGL and OpenGL ES, not OpenVG. If OpenVG or any
|
||||
* other API is added, then the major version number will be incremented.
|
||||
*
|
||||
* When the application calls eglBindAPI, libEGL will forward the call to every
|
||||
* vendor library. In addition, a vendor library can query the current API from
|
||||
* libEGL using the getCurrentApi callback.
|
||||
*
|
||||
* Vendor libraries are not required to support both GL and GLES, but they must
|
||||
* be able to deal with either one as the current rendering API. If a vendor
|
||||
* doesn't support the current API, then it should return an error from
|
||||
* eglCreateContext.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* Current version of the ABI.
|
||||
*
|
||||
* This version number contains a major number in the high-order 16 bits, and
|
||||
* a minor version number in the low-order 16 bits.
|
||||
*
|
||||
* The major version number is incremented when an interface change will break
|
||||
* backwards compatibility with existing vendor libraries. The minor version
|
||||
* number is incremented when there's a change but existing vendor libraries
|
||||
* will still work.
|
||||
*/
|
||||
#define EGL_VENDOR_ABI_MAJOR_VERSION ((uint32_t) 0)
|
||||
#define EGL_VENDOR_ABI_MINOR_VERSION ((uint32_t) 2)
|
||||
#define EGL_VENDOR_ABI_VERSION ((EGL_VENDOR_ABI_MAJOR_VERSION << 16) | EGL_VENDOR_ABI_MINOR_VERSION)
|
||||
static inline uint32_t EGL_VENDOR_ABI_GET_MAJOR_VERSION(uint32_t version)
|
||||
{
|
||||
return version >> 16;
|
||||
}
|
||||
static inline uint32_t EGL_VENDOR_ABI_GET_MINOR_VERSION(uint32_t version)
|
||||
{
|
||||
return version & 0xFFFF;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* This opaque structure stores function pointers for EGL extension functions.
|
||||
* It is allocated at runtime by the API library. Vendor-provided dispatch
|
||||
* functions retrieve and operate on this structure using the API below.
|
||||
*/
|
||||
typedef struct __EGLvendorInfoRec __EGLvendorInfo;
|
||||
|
||||
/****************************************************************************
|
||||
* API library exports *
|
||||
****************************************************************************/
|
||||
|
||||
typedef struct __EGLapiExportsRec {
|
||||
/************************************************************************
|
||||
* The following routines are used by vendor-implemented EGL dispatch
|
||||
* functions to lookup and call into the right vendor.
|
||||
************************************************************************/
|
||||
|
||||
/*!
|
||||
* This function must be called at the start of every EGL dispatch stub. It
|
||||
* performs any necessary per-call bookkeeping.
|
||||
*/
|
||||
void (* threadInit) (void);
|
||||
|
||||
EGLenum (* getCurrentApi)(void);
|
||||
|
||||
/*!
|
||||
* This function retrieves the appropriate current dynamic dispatch table,
|
||||
* if a GL context is current. Otherwise, this returns NULL.
|
||||
*/
|
||||
__EGLvendorInfo *(*getCurrentVendor)(void);
|
||||
|
||||
/*!
|
||||
* This retrieves the current context for this thread.
|
||||
*/
|
||||
EGLContext (*getCurrentContext)(void);
|
||||
|
||||
/*!
|
||||
* Returns the current display for this thread.
|
||||
*/
|
||||
EGLDisplay (*getCurrentDisplay)(void);
|
||||
|
||||
/*!
|
||||
* Returns the current drawable for this thread.
|
||||
*/
|
||||
EGLSurface (*getCurrentSurface)(EGLint readDraw);
|
||||
|
||||
/*!
|
||||
* This function retrieves an entry point from the dynamic dispatch table
|
||||
* given an index into the table.
|
||||
*/
|
||||
__eglMustCastToProperFunctionPointerType (*fetchDispatchEntry) (__EGLvendorInfo *dynDispatch, int index);
|
||||
|
||||
/*!
|
||||
* Sets the last error for the current thread. The error will be returned
|
||||
* the next time the app calls eglGetError().
|
||||
*
|
||||
* This function will override a call to \c setLastVendor, and vice-versa.
|
||||
*/
|
||||
void (* setEGLError) (EGLint errorCode);
|
||||
|
||||
/*!
|
||||
* Notifies libEGL about the vendor library that an EGL function is
|
||||
* dispatched to. This is used to look up the last EGL error code from a
|
||||
* vendor.
|
||||
*
|
||||
* A vendor library may generate an EGL error asynchronously, if it
|
||||
* offloads some EGL functions onto a worker thread. In that case, calling
|
||||
* \c setEGLError to set the last error would not work.
|
||||
*
|
||||
* When an EGL dispatch stubs finds the vendor library, it must call this
|
||||
* function before it dispatches the function call.
|
||||
*
|
||||
* This function will override a call to \c setEGLError, and vice-versa.
|
||||
*
|
||||
* \param vendor The vendor library of the current EGL function call.
|
||||
* \return EGL_TRUE on success, or EGL_FALSE on failure.
|
||||
*/
|
||||
EGLBoolean (* setLastVendor) (__EGLvendorInfo *vendor);
|
||||
|
||||
/************************************************************************
|
||||
* These routines are used by vendor dispatch functions to look up
|
||||
* and add mappings between various objects and vendors.
|
||||
************************************************************************/
|
||||
|
||||
// As far as I can tell, all EGL functions that take a context or drawable
|
||||
// also take an EGLDisplay. So, we don't need any extra functions for
|
||||
// mapping a context/surface/whatever to a EGLDisplay or vendor.
|
||||
|
||||
/*!
|
||||
* Returns the EGL vendor for an EGLDisplay handle.
|
||||
*/
|
||||
__EGLvendorInfo *(*getVendorFromDisplay)(EGLDisplay dpy);
|
||||
|
||||
/*!
|
||||
* Returns the EGL vendor for an EGLDeviceEXT handle.
|
||||
*/
|
||||
__EGLvendorInfo *(*getVendorFromDevice)(EGLDeviceEXT dev);
|
||||
|
||||
/**
|
||||
* Sets the EGL vendor for an EGLDeviceEXT handle. The dispatch stub for
|
||||
* any function that returns an EGLDeviceEXT handle should call this.
|
||||
*
|
||||
* Supported since ABI version 1.2.
|
||||
*/
|
||||
EGLBoolean (* setVendorForDevice)(EGLDeviceEXT dev, __EGLvendorInfo *vendor);
|
||||
} __EGLapiExports;
|
||||
|
||||
/*****************************************************************************
|
||||
* API library imports *
|
||||
*****************************************************************************/
|
||||
|
||||
/*!
|
||||
* The enum values accepted by \c __EGLapiImports::getVendorString.
|
||||
*/
|
||||
enum
|
||||
{
|
||||
/*!
|
||||
* The set of platform extensions that the vendor supports.
|
||||
*
|
||||
* Platform extensions typically just add enums to the existing
|
||||
* eglGetPlatformDisplay function, so we don't need any additional logic
|
||||
* or special handling from libEGL itself.
|
||||
*
|
||||
* As a result, vendor libraries can add these extensions without having
|
||||
* to modify libEGL to match.
|
||||
*/
|
||||
__EGL_VENDOR_STRING_PLATFORM_EXTENSIONS,
|
||||
};
|
||||
|
||||
/*!
|
||||
* This structure stores required and optional vendor library callbacks.
|
||||
*/
|
||||
typedef struct __EGLapiImportsRec {
|
||||
/**
|
||||
* Creates an EGLDisplay. This function is used to handle both
|
||||
* \c eglGetDisplay and \c eglGetPlatformDisplay.
|
||||
*
|
||||
* For some platform types, libEGL may be able to identify a specific
|
||||
* vendor to use.
|
||||
*
|
||||
* If libEGL can't figure out which vendor to use on its own, then it will
|
||||
* go through the list of available vendor libraries and call this function
|
||||
* until one succeeds.
|
||||
*
|
||||
* If the application calls eglGetPlatformDisplay, then the parameters are
|
||||
* passed through from the application.
|
||||
*
|
||||
* If the application calls eglGetDisplay, and the native display handle is
|
||||
* not \c EGL_DEFAULT_DISPLAY, then libEGL will try to guess a platform
|
||||
* type, and will pass that platform to the vendor library.
|
||||
*
|
||||
* Lastly, if eglGetDisplay is called with \c EGL_DEFAULT_DISPLAY, then
|
||||
* libEGL will call into each vendor library with \p platform set to
|
||||
* \c EGL_NONE. The vendor library can then select a default display to
|
||||
* return.
|
||||
*
|
||||
* In all cases, if the vendor library can't find a matching EGLDisplay,
|
||||
* then it should return \c EGL_NO_DISPLAY. Any errors should be reported
|
||||
* through the vendor's \c eglGetError function.
|
||||
*/
|
||||
EGLDisplay (* getPlatformDisplay) (EGLenum platform, void *nativeDisplay,
|
||||
const EGLAttrib *attrib_list);
|
||||
|
||||
/*!
|
||||
* Checks if the vendor library supports a given client API (that is, the
|
||||
* API value passed to \c eglBindAPI).
|
||||
*/
|
||||
EGLBoolean (* getSupportsAPI) (EGLenum api);
|
||||
|
||||
/*!
|
||||
* (OPTIONAL) Returns a string from the vendor library. This is used for
|
||||
* anything that isn't available from eglQueryString.
|
||||
*/
|
||||
const char * (* getVendorString) (int name);
|
||||
|
||||
/*
|
||||
* NOTE: libEGL will load all of the vendor libraries up front, so it
|
||||
* handles extension functions slightly differently than EGL.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* This retrieves the pointer to the real EGL or core GL function.
|
||||
*
|
||||
* \param procName The name of the function.
|
||||
* \return A pointer to a function, or \c NULL if the vendor does not
|
||||
* support the function.
|
||||
*/
|
||||
void * (* getProcAddress) (const char *procName);
|
||||
|
||||
/*!
|
||||
* This retrieves vendor-neutral functions which use the
|
||||
* __EGLdispatchTableDynamic API above to dispatch to the correct vendor.
|
||||
*
|
||||
* A vendor library must provide a dispatch function for all EGL display
|
||||
* extension functions that it supports.
|
||||
*
|
||||
* Client extension functions cannot be dispatched based on an EGDisplay,
|
||||
* so they must be handled in libEGL itself.
|
||||
*
|
||||
* \param procName The name of the function.
|
||||
* \return A pointer to a function, or \c NULL if the vendor does not
|
||||
* support the function or \p procName is not a EGL display function.
|
||||
*/
|
||||
void * (*getDispatchAddress) (const char *procName);
|
||||
|
||||
/*!
|
||||
* This notifies the vendor library which dispatch table index is
|
||||
* assigned to a particular EGL extension function.
|
||||
*/
|
||||
void (*setDispatchIndex) (const char *procName, int index);
|
||||
|
||||
/*
|
||||
* The vendor library may use the isPatchSupported, initiatePatch,
|
||||
* releasePatch, and patchThreadAttach callbacks to re-write libglvnd's
|
||||
* entrypoints at make current time, provided no other contexts are current
|
||||
* and the TLS model supports this functionality. This is a performance
|
||||
* optimization that may not be available at runtime; the vendor library
|
||||
* must not depend on this functionality for correctness.
|
||||
*
|
||||
* To use this optimization, the vendor library must provide at least the
|
||||
* isPatchSupported and initiatePatch entrypoints.
|
||||
*
|
||||
* Note that these functions are identical to the ones used in GLX.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* (OPTIONAL) Checks to see if the vendor library supports patching the
|
||||
* given stub type and size.
|
||||
*
|
||||
* \param type The type of entrypoints. This will be a one of the
|
||||
* __GLDISPATCH_STUB_* values.
|
||||
* \param stubSize The maximum size of the stub that the vendor library can
|
||||
* write, in bytes.
|
||||
* \param lookupStubOffset A callback into libglvnd to look up the address
|
||||
* of each entrypoint.
|
||||
*/
|
||||
GLboolean (* isPatchSupported)(int type, int stubSize);
|
||||
|
||||
/*!
|
||||
* (OPTIONAL) Called by libglvnd to request that a vendor library patch its
|
||||
* top-level entrypoints.
|
||||
*
|
||||
* The vendor library should use the \p lookupStubOffset callback to find
|
||||
* the addresses of each entrypoint.
|
||||
*
|
||||
* This function may be called more than once to patch multiple sets of
|
||||
* entrypoints. For example, depending on how they're built, libOpenGL.so
|
||||
* or libGL.so may have their own entrypoints that are separate functions
|
||||
* from the ones in libGLdispatch.
|
||||
*
|
||||
* Note that during this call is the only time that the entrypoints can be
|
||||
* modified. After the call to \c initiatePatch returns, the vendor library
|
||||
* should treat the entrypoints as read-only.
|
||||
*
|
||||
* \param type The type of entrypoints. This will be a one of the
|
||||
* __GLDISPATCH_STUB_* values.
|
||||
* \param stubSize The maximum size of the stub that the vendor library can
|
||||
* write, in bytes.
|
||||
* \param lookupStubOffset A callback into libglvnd to look up the address
|
||||
* of each entrypoint.
|
||||
*
|
||||
* \return GL_TRUE if the vendor library supports patching with this type
|
||||
* and size.
|
||||
*/
|
||||
GLboolean (*initiatePatch)(int type,
|
||||
int stubSize,
|
||||
DispatchPatchLookupStubOffset lookupStubOffset);
|
||||
|
||||
/*!
|
||||
* (OPTIONAL) Called by libglvnd to notify the current vendor that it no
|
||||
* longer owns the top-level entrypoints.
|
||||
*
|
||||
* Libglvnd will take care of the restoring the entrypoints back to their
|
||||
* original state. The vendor library must not try to modify them.
|
||||
*/
|
||||
void (*releasePatch)(void);
|
||||
|
||||
/*!
|
||||
* (OPTIONAL) Called at the start of window-system functions (GLX and EGL).
|
||||
* This callback allows vendor libraries to perform any per-thread
|
||||
* initialization.
|
||||
*
|
||||
* This is basically a workaround for broken applications. A lot of apps
|
||||
* will make one or more invalid GLX/EGL calls on a thread (often including
|
||||
* a MakeCurrent with invalid parameters), and then will try to call an
|
||||
* OpenGL function.
|
||||
*
|
||||
* A non-libglvnd-based driver would be able to initialize any thread state
|
||||
* even on a bogus GLX call, but with libglvnd, those calls wouldn't get
|
||||
* past libGLX.
|
||||
*
|
||||
* This function is optional. If it's \c NULL, then libGLdispatch will
|
||||
* simply ignore it.
|
||||
*
|
||||
* \note This function may be called concurrently from multiple threads.
|
||||
*/
|
||||
void (*patchThreadAttach)(void);
|
||||
|
||||
/*!
|
||||
* (OPTIONAL) Tries to determine the platform type for a native display.
|
||||
*
|
||||
* If the vendor library provides this function, then libglvnd will call it
|
||||
* to determine which platform to use for a native display handle in
|
||||
* eglGetDisplay.
|
||||
*
|
||||
* If no vendor library identifies the platform, then libglvnd will fall
|
||||
* back to its own platform detection logic.
|
||||
*
|
||||
* Libglvnd can call this function for any native display handle except
|
||||
* \c EGL_DEFAULT_DISPLAY.
|
||||
*
|
||||
* No matter what the value of \p native_display, the vendor library must
|
||||
* not crash, and must not return a false match. If the vendor library
|
||||
* can't identify the display, then it must return \c EGL_NONE.
|
||||
*
|
||||
* In particular, that means that a vendor library must not return any sort
|
||||
* of default or fallback platform.
|
||||
*
|
||||
* \param native_display The native display handle passed to eglGetDisplay.
|
||||
* \return Either a platform type enum or EGL_NONE.
|
||||
*/
|
||||
EGLenum (* findNativeDisplayPlatform) (void *native_display);
|
||||
} __EGLapiImports;
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define __EGL_MAIN_PROTO_NAME "__egl_Main"
|
||||
|
||||
typedef EGLBoolean (* __PFNEGLMAINPROC) (uint32_t version, const __EGLapiExports *exports,
|
||||
__EGLvendorInfo *vendor, __EGLapiImports *imports);
|
||||
|
||||
/*!
|
||||
* Vendor libraries must export a function called __egl_Main() with the
|
||||
* following prototype.
|
||||
*
|
||||
* This function also performs a handshake based on the ABI version number.
|
||||
* Vendor libraries can optionally use the version number to support older
|
||||
* versions of the ABI.
|
||||
*
|
||||
* \param[in] version The ABI version. The upper 16 bits contains the major version
|
||||
* number, and the lower 16 bits contains the minor version number.
|
||||
*
|
||||
* \param[in] exports The table of functions provided by libEGL. This pointer will
|
||||
* remain valid for as long as the vendor is loaded.
|
||||
*
|
||||
* \param[in] vendor The opaque pointer used to identify this vendor library. This
|
||||
* may be used in future versions to provide additional per-vendor information.
|
||||
*
|
||||
* \param[out] imports The function table that the vendor library should fill
|
||||
* in. The vendor library must assign every non-optional function in the
|
||||
* struct.
|
||||
*
|
||||
* \return True on success. If the vendor library does not support the
|
||||
* requested ABI version or if some other error occurs, then it should return
|
||||
* False.
|
||||
*/
|
||||
EGLBoolean __egl_Main(uint32_t version, const __EGLapiExports *exports,
|
||||
__EGLvendorInfo *vendor, __EGLapiImports *imports);
|
||||
|
||||
/*!
|
||||
* @}
|
||||
*/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __LIB_EGL_ABI_H */
|
||||
-191
@@ -29,8 +29,6 @@ option(MOBILEGL_BUILD_DISAGGREGATED "Build the MG_Remote transport layer (two-pr
|
||||
# only decides whether the shims are compiled in.
|
||||
option(MOBILEGL_BUILD_DISAGGREGATED_INPROC "Compile the in-process (one-process, two-role) split shims; implies MOBILEGL_BUILD_DISAGGREGATED" OFF)
|
||||
option(MOBILEGL_BUILD_SERVER_SPIKE "Build the P0 spike-A MobileGLServer delivery-chain executable (Android only)" OFF)
|
||||
option(MOBILEGL_BUILD_EXTMEM_PROBE "Package tools/spikes/extmem_probe as libMobileGLExtmemProbe.so for the trace APK's exec hook (P11 A3, Android only)" OFF)
|
||||
option(MOBILEGL_EXTMEM_PROBE_AS_SERVER "Spike only (P11 B2 step 1): also package the probe as libMobileGLServer.so, the real server as libMobileGLServerReal.so" OFF)
|
||||
# The PipeInputs strangler (ARCHITECTURE.md 9.2). OFF is the pull build and must stay
|
||||
# byte-identical to a tree without either option: MGB_CTX is the live GLContext, no
|
||||
# MGPipe/PipeInputs source is compiled, every MGP_FILL is ((void)0).
|
||||
@@ -403,10 +401,7 @@ set(SOURCE_FILES
|
||||
MobileGL/MG_Impl/GLXImpl/LookUp/LookUp.cpp
|
||||
|
||||
MobileGL/MG_Impl/EGLImpl/Exporting/Definitions.cpp
|
||||
|
||||
MobileGL/MG_Impl/EGLImpl/Exporting/GlvndVendor.cpp
|
||||
MobileGL/MG_Impl/EGLImpl/EGLImpl.cpp
|
||||
MobileGL/MG_Impl/EGLImpl/WaylandWindow.cpp
|
||||
|
||||
# @INSERTION_POINT:SOURCE_FILE_GLIMPL@ #
|
||||
MobileGL/MG_Impl/GLImpl/Sampler/Validators.cpp
|
||||
@@ -437,14 +432,10 @@ set(SOURCE_FILES
|
||||
MobileGL/MG_Backend/Init.cpp
|
||||
MobileGL/MG_Backend/BackendObject.cpp
|
||||
|
||||
MobileGL/MG_Backend/HostFrameBridge.cpp
|
||||
MobileGL/MG_Backend/GbmFrameChannel.cpp
|
||||
|
||||
MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp
|
||||
MobileGL/MG_Backend/DirectGLES/BackendObject_DirectGLES.cpp
|
||||
MobileGL/MG_Backend/DirectGLES/Utils.cpp
|
||||
MobileGL/MG_Backend/DirectGLES/Managers.cpp
|
||||
MobileGL/MG_Backend/DirectGLES/HostFrameTarget.cpp
|
||||
MobileGL/MG_Backend/DirectGLES/MultiDraw.cpp
|
||||
|
||||
MobileGL/MG_Backend/DirectVulkan/DirectVulkan.cpp
|
||||
@@ -601,9 +592,6 @@ endif()
|
||||
if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
message(STATUS "MobileGL: disaggregated transport ON, appending MG_Remote sources")
|
||||
list(APPEND SOURCE_FILES
|
||||
MobileGL/MG_Remote/Transport/ShmLink.cpp
|
||||
MobileGL/MG_Remote/Transport/LinkMetrics.cpp
|
||||
MobileGL/MG_Remote/Transport/StreamLink.cpp
|
||||
MobileGL/MG_Remote/Transport/Ring.cpp
|
||||
MobileGL/MG_Remote/Transport/Doorbell.cpp
|
||||
MobileGL/MG_Remote/Transport/ShmSegment.cpp
|
||||
@@ -615,18 +603,9 @@ if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
MobileGL/MG_Remote/Transport/FdPassing.cpp
|
||||
MobileGL/MG_Remote/Transport/InProcessTransport.cpp
|
||||
MobileGL/MG_Remote/Transport/SocketTransport.cpp
|
||||
MobileGL/MG_Remote/Transport/ControlInbox.cpp
|
||||
# P9 W3: the server's log forward - a queue and a sender thread, graded by severity
|
||||
# (<= WARN lossy, >= ERROR lossless and paced), so no logging thread writes the socket.
|
||||
MobileGL/MG_Remote/Transport/LogForward.cpp
|
||||
# Keeps MG_Util/Debug/Log.h - and through it the GL frontend's
|
||||
# umbrella header - out of the header-only wire code (WireLog.h).
|
||||
MobileGL/MG_Remote/Transport/WireLog.cpp
|
||||
# P11 A1: the adopt tier settled at the handshake from the knob and the data plane, by
|
||||
# both roles (so SERVER-partition code in the link ratchet, not the client's tracker).
|
||||
MobileGL/MG_Remote/Transport/AdoptTier.cpp
|
||||
# P11 B2: T0 - the client's AHardwareBuffer store and its hop descriptor (both roles).
|
||||
MobileGL/MG_Remote/Transport/AdoptT0.cpp
|
||||
# ---- P5: the three new directories ------------------------------
|
||||
# Wire/ the G3 codec: MGPWireRec_* in and out of SEG_CMD, blobs and
|
||||
# var-tails in and out of SEG_STAGE. [w1]
|
||||
@@ -647,7 +626,6 @@ if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
MobileGL/MG_Remote/FatalFunnel.cpp
|
||||
MobileGL/MG_Remote/Wire/PipeWireCodec.cpp
|
||||
MobileGL/MG_Remote/Client/ClientSession.cpp
|
||||
MobileGL/MG_Remote/Client/DmaBufImport.cpp
|
||||
MobileGL/MG_Remote/Client/EmitTables.cpp
|
||||
MobileGL/MG_Remote/Client/CapsMirror.cpp
|
||||
# P5 c1: the client role's BackendObject. pActiveBackendObject holds one of these
|
||||
@@ -668,25 +646,11 @@ MobileGL/MG_Remote/Client/DmaBufImport.cpp
|
||||
MobileGL/MG_Remote/Server/PipeApplier.cpp
|
||||
MobileGL/MG_Remote/Server/ServerLoop.cpp
|
||||
MobileGL/MG_Remote/Server/ServerMain.cpp
|
||||
# P11 PAIR: a socket client's control and aux connections paired by the nonce each
|
||||
# presents first (PairBind), not by arrival order - both unix supervisors take pairs here.
|
||||
MobileGL/MG_Remote/Server/PairAcceptor.cpp
|
||||
# P11 B2: T0's Offers on the aux socket, matched to their map_persistent records by seq.
|
||||
MobileGL/MG_Remote/Server/AdoptInbox.cpp
|
||||
MobileGL/MG_Remote/Server/ServerSpawn.cpp
|
||||
# P5f fc: the value frame that replaced the control mailbox's function-pointer payload,
|
||||
# and its codec against protocol.fbs's SurfaceOp/SurfaceReply (the spawn arm's seam).
|
||||
MobileGL/MG_Remote/Server/SurfaceControlFrame.cpp
|
||||
MobileGL/MG_Remote/Protocol/SurfaceOpCodec.cpp
|
||||
# P12 (on-screen server window): the process-wide holder of the server's own window
|
||||
# (the display Activity's SurfaceView on Android; nobody installs one on the host, so a
|
||||
# ServerOwned request is refused by name there).
|
||||
MobileGL/MG_Remote/Server/ServerDisplay.cpp
|
||||
# P7 gate 5 (g5-msprobe): the Magma wire arm's two multisample depth/stencil resolve
|
||||
# arms and the probe that measures the first against the second, shared by the
|
||||
# renderer's bring-up and the Vulkan POST. Wire-only - the monolith records neither arm -
|
||||
# so it stays out of the pull build (gate G1).
|
||||
MobileGL/MG_Backend/DirectVulkan/Renderer/WireDepthResolveProbe.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -704,14 +668,6 @@ if (ANDROID)
|
||||
MobileGL/MG_Util/SelfTest/DriverPostJni.cpp
|
||||
MobileGL/MG_Util/SelfTest/DriverBenchJni.cpp
|
||||
)
|
||||
if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
# P12 (on-screen server window): the APK's MobileGLDisplayActivity - the in-process
|
||||
# display server's thread, its SurfaceView's ANativeWindow in and out of ServerDisplay, and
|
||||
# the geometry up-call. Split build only: nothing else has an in-process server to drive.
|
||||
list(APPEND SOURCE_FILES
|
||||
MobileGL/MG_Remote/Server/DisplayServerJni.cpp
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (WIN32)
|
||||
@@ -786,9 +742,6 @@ if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
# target, and above all no flatc in the build graph. protocol_generated.h
|
||||
# is committed and regenerated by scripts/gen_protocol.py.
|
||||
list(APPEND MOBILEGL_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/3rdparty/flatbuffers/include)
|
||||
# The vendored glvnd vendor-ABI headers (3rdparty/glvnd): the entry point a vendor library
|
||||
# exposes so the system libEGL - which IS glvnd - can dispatch to it.
|
||||
list(APPEND MOBILEGL_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/3rdparty/glvnd/include)
|
||||
endif()
|
||||
|
||||
add_library(${CMAKE_PROJECT_NAME} SHARED
|
||||
@@ -826,17 +779,6 @@ target_link_libraries(${CMAKE_PROJECT_NAME}
|
||||
${MOBILEGL_LINK_LIBRARIES}
|
||||
)
|
||||
|
||||
# A LINUX BUILD COMPILES THE DirectVulkan BACKEND BUT HAS NO VULKAN LOADER TO LINK AGAINST, so the
|
||||
# resulting shared library carries undefined vk* symbols - and that is not theoretical: glvnd dlopens
|
||||
# this file as the EGL vendor with RTLD_NOW, so the load fails outright with "undefined symbol:
|
||||
# vkGetQueryPoolResults" (measured on the phone's container). Android links the loader already; on
|
||||
# Linux the caller passes the runtime's own libvulkan.so.1, and leaving the variable empty keeps the
|
||||
# previous behaviour for every build that has no Vulkan runtime to point at.
|
||||
set(MOBILEGL_VULKAN_LOADER "" CACHE FILEPATH "Vulkan loader (libvulkan.so.1) to link into the GL library")
|
||||
if (UNIX AND NOT ANDROID AND MOBILEGL_VULKAN_LOADER)
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ${MOBILEGL_VULKAN_LOADER})
|
||||
endif()
|
||||
|
||||
target_compile_definitions(${CMAKE_PROJECT_NAME}
|
||||
PUBLIC
|
||||
${MOBILEGL_COMPILE_DEF}
|
||||
@@ -903,68 +845,6 @@ if(NOT ANDROID)
|
||||
)
|
||||
endif()
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# MobileGLGbm: the GBM drop-in the container's compositor loads.
|
||||
#
|
||||
# kwin - the Wayland compositor in the container half of the split - allocates the
|
||||
# buffers it renders into and scans out through libgbm, and the dma-buf fds it gets
|
||||
# back are what the Anland display producer ships to the phone. Mesa's libgbm cannot
|
||||
# serve that: its buffers belong to the host GPU, and the phone would receive a copy
|
||||
# through a path that was never designed to carry one. This target is the library
|
||||
# that is loaded in its place, under the name a loader looks for.
|
||||
#
|
||||
# It is deliberately NOT part of libMobileGL.so. The compositor needs one file named
|
||||
# libgbm.so that it loads instead of Mesa's, and folding this code into the GL
|
||||
# library would put a second GL frontend, a second Vulkan instance and a second
|
||||
# glslang in the compositor's address space to serve an API that shares none of them.
|
||||
#
|
||||
# The include paths below are borrowed rather than linked. Includes.h - which this
|
||||
# library includes for the MobileGL types and the MGLOG macros - pulls in the GL,
|
||||
# EGL, Vulkan, glslang, SPIRV-Cross and xxHash HEADERS transitively, and headers are
|
||||
# all this library wants from them: linking any of those static libraries into a
|
||||
# libgbm would embed a copy of each in a process that already has one.
|
||||
#
|
||||
# -Bsymbolic-functions, for the same reason the main target carries it: the point of
|
||||
# this library is to REPLACE a libgbm that may already be loaded in the process, so
|
||||
# every internal reference has to bind to this file's own definitions rather than to
|
||||
# whatever else the process has under the same names.
|
||||
# ---------------------------------------------------------------------------
|
||||
add_library(MobileGLGbm SHARED
|
||||
MobileGL/MG_Gbm/GbmDevice.cpp
|
||||
# The display host's socket protocol, kept in its own translation unit so that the
|
||||
# allocation paths never have to know how a frame arrives - only that one did.
|
||||
MobileGL/MG_Gbm/GbmHostChannel.cpp
|
||||
MobileGL/MG_Gbm/GbmApi.cpp
|
||||
# MGLOG_I/W/E expand to a call to MobileGL::MG_Util::Debug::Log, and this is the
|
||||
# one translation unit that defines it. It is compiled in rather than linked from
|
||||
# libMobileGL.so because this library has to load into a compositor that has no
|
||||
# libMobileGL in it at all - and because a libgbm with an undefined symbol is a
|
||||
# library that fails on the first diagnostic rather than at a link step somebody
|
||||
# could have read.
|
||||
MobileGL/MG_Util/Debug/Log.cpp
|
||||
)
|
||||
|
||||
# The vendored gbm.h first: this library implements THAT declaration set, and a
|
||||
# system <gbm.h> from another Mesa version on the include path ahead of it would
|
||||
# change the ABI under the implementations in GbmApi.cpp.
|
||||
target_include_directories(MobileGLGbm PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/3rdparty/gbm/include
|
||||
${MOBILEGL_INCLUDE_DIR}
|
||||
${CMAKE_SOURCE_DIR}/3rdparty/glslang
|
||||
${CMAKE_SOURCE_DIR}/3rdparty/SPIRV-Cross
|
||||
${CMAKE_SOURCE_DIR}/3rdparty/xxHash
|
||||
${CMAKE_SOURCE_DIR}/3rdparty/Vulkan-Headers/include
|
||||
)
|
||||
|
||||
set_target_properties(MobileGLGbm PROPERTIES
|
||||
OUTPUT_NAME gbm
|
||||
POSITION_INDEPENDENT_CODE ON
|
||||
)
|
||||
|
||||
if (UNIX AND NOT APPLE)
|
||||
target_link_options(MobileGLGbm PRIVATE "LINKER:-Bsymbolic-functions")
|
||||
endif()
|
||||
|
||||
if (TRACY_ENABLE)
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC Tracy::TracyClient)
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME}_s PUBLIC Tracy::TracyClient)
|
||||
@@ -972,19 +852,6 @@ if (TRACY_ENABLE)
|
||||
target_compile_definitions(${CMAKE_PROJECT_NAME}_s PUBLIC -DTRACY_ENABLE)
|
||||
endif ()
|
||||
|
||||
# GLVND, AND WHY THIS IS A LINKER FLAG RATHER THAN A VISIBILITY ONE.
|
||||
#
|
||||
# MobileGL can serve as a glvnd EGL vendor - the library the system's libEGL.so.1 dispatches to -
|
||||
# and a vendor must hand glvnd ITS OWN entry points: glvnd calls whatever address it is given, so
|
||||
# an address that resolves to another libEGL in the process is a call back into the dispatcher.
|
||||
# With default visibility every reference inside this library resolves against the whole process,
|
||||
# and a process that loaded the system libEGL first wins. Marking the entry points protected says
|
||||
# the same thing in the source, except the platform's own GL/EGL headers declare them default and
|
||||
# the two visibilities do not mix; this flag is that promise made by the linker instead.
|
||||
if (UNIX AND NOT APPLE)
|
||||
target_link_options(${CMAKE_PROJECT_NAME} PRIVATE "LINKER:-Bsymbolic-functions")
|
||||
endif()
|
||||
|
||||
if (ANDROID)
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC
|
||||
android
|
||||
@@ -1094,12 +961,6 @@ if (ANDROID AND MOBILEGL_BUILD_INTEGRATION_TEST)
|
||||
add_subdirectory(MobileGL/MG_IntegrationTest)
|
||||
endif()
|
||||
|
||||
# The replay runner also builds for Android: an adb-shell executable that can
|
||||
# dial a render server on the device (unix or TCP) without any Activity.
|
||||
if (ANDROID AND MOBILEGL_BUILD_TRACE_REPLAY)
|
||||
add_subdirectory(tools/trace_replay)
|
||||
endif()
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# P0 spike A: the Android delivery chain for a second native executable.
|
||||
#
|
||||
@@ -1208,55 +1069,3 @@ if (ANDROID AND MOBILEGL_BUILD_SERVER_SPIKE)
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (ANDROID AND MOBILEGL_BUILD_EXTMEM_PROBE)
|
||||
# P11 A3 (open question 3): the spike-B external-memory probe, exec'd from the trace
|
||||
# app's own process by the spike hook (`--es mobilegl_spike_spawn
|
||||
# libMobileGLExtmemProbe.so`), so its rows answer for the untrusted_app domain. The
|
||||
# same PIE-executable-named-like-a-library shape as MobileGLServerSpike above; it
|
||||
# links nothing from MobileGL.
|
||||
add_executable(MobileGLExtmemProbe
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tools/spikes/extmem_probe/extmem_probe.cpp)
|
||||
set_target_properties(MobileGLExtmemProbe PROPERTIES
|
||||
PREFIX "lib"
|
||||
SUFFIX ".so"
|
||||
OUTPUT_NAME "MobileGLExtmemProbe"
|
||||
POSITION_INDEPENDENT_CODE ON)
|
||||
target_compile_options(MobileGLExtmemProbe PRIVATE -fPIE)
|
||||
target_link_options(MobileGLExtmemProbe PRIVATE -pie)
|
||||
target_link_libraries(MobileGLExtmemProbe PRIVATE vulkan EGL GLESv3 android log)
|
||||
if (CMAKE_LIBRARY_OUTPUT_DIRECTORY)
|
||||
set_target_properties(MobileGLExtmemProbe PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
|
||||
endif()
|
||||
if (MOBILEGL_EXTMEM_PROBE_AS_SERVER)
|
||||
# P11 B2 step 1, spike APKs only: MobileGLServerService execs `libMobileGLServer.so
|
||||
# <endpoint> --serve` and B1's broker connects to whatever that listens on, so the probe
|
||||
# takes the server's file name and answers "does a client's AHardwareBuffer cross this
|
||||
# route into the server app" on the real route (tools/spikes/extmem_probe, route mode).
|
||||
if (TARGET MobileGLServer)
|
||||
set_target_properties(MobileGLServer PROPERTIES OUTPUT_NAME "MobileGLServerReal")
|
||||
endif()
|
||||
add_executable(MobileGLExtmemProbeAsServer
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tools/spikes/extmem_probe/extmem_probe.cpp)
|
||||
set_target_properties(MobileGLExtmemProbeAsServer PROPERTIES
|
||||
PREFIX "lib"
|
||||
SUFFIX ".so"
|
||||
OUTPUT_NAME "MobileGLServer"
|
||||
POSITION_INDEPENDENT_CODE ON)
|
||||
target_compile_options(MobileGLExtmemProbeAsServer PRIVATE -fPIE)
|
||||
target_link_options(MobileGLExtmemProbeAsServer PRIVATE -pie)
|
||||
target_link_libraries(MobileGLExtmemProbeAsServer PRIVATE vulkan EGL GLESv3 android log)
|
||||
if (CMAKE_LIBRARY_OUTPUT_DIRECTORY)
|
||||
set_target_properties(MobileGLExtmemProbeAsServer PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# The GBM library carries the tree's logger, which reaches Android's own log. The main target gets
|
||||
# these libraries in its own Android block; a library built from the same sources needs them for the
|
||||
# same reason, and without them it is the LINK that fails rather than anything in the code.
|
||||
if (ANDROID)
|
||||
target_link_libraries(MobileGLGbm PRIVATE log android)
|
||||
endif()
|
||||
|
||||
+8
-188
@@ -132,18 +132,6 @@ namespace MobileGL::MG_Config {
|
||||
Bool MagmaR11G11B10FFallback = false;
|
||||
// MOBILEGL_MAGMA_FRAMESINFLIGHT: requested Magma frames in flight, defaulting to 3.
|
||||
Uint32 MagmaFramesInFlight = 3;
|
||||
// MOBILEGL_MAGMA_MAX_DRAWS_PER_COMMAND_BUFFER: GL draws and dispatches Magma records into
|
||||
// one command buffer before it submits it and continues on a fresh one. 0 = unbounded.
|
||||
// Drivers back a command buffer with GPU memory that is only returned when the buffer is
|
||||
// freed; Adreno maps it into the process in 16 KiB chunks, so one ~1M-draw loading frame
|
||||
// exhausts vm.max_map_count. See VulkanRenderer::SplitOversizedRecording.
|
||||
Uint32 MagmaMaxDrawsPerCommandBuffer = 16384;
|
||||
// MOBILEGL_MAGMA_DESCRIPTOR_TRIM_FRAMES: how many consecutive frames (strictly, BeginFrame
|
||||
// epochs) a frame slot's descriptor pools must stay under a quarter full before Magma
|
||||
// hands the slot's whole set cache back and lets it re-grow. 0 = never trim. A loading
|
||||
// frame otherwise keeps its burst of sets (rd12: ~15k, where steady frames use a few dozen)
|
||||
// for the life of the process. See UniformManager::TrimFrameDescriptorPools.
|
||||
Uint32 MagmaDescriptorTrimFrames = 120;
|
||||
// MOBILEGL_ESPRYT_AVOID_SAMPLER_MIPMAP_MIN_FILTER: avoid mipmap min filters in samplers,
|
||||
// resolves certain rendering bugs on ANGLE + llvmpipe.
|
||||
Bool EsprytAvoidSamplerMipmapMinFilter = false;
|
||||
@@ -214,12 +202,9 @@ namespace MobileGL::MG_Config {
|
||||
// persistently+coherently mapped storage at definition time (negative control /
|
||||
// escape hatch). Frontend-scoped: it engages only where the active backend
|
||||
// provides AcquirePersistentMap. With adoption on, an app SubData into a busy
|
||||
// 128MB arena lands GPU-ordered through the backend's resident-subdata op
|
||||
// (BufferObject::LandBytesIntoResidentStore, since 0ee3384b: an in-place write
|
||||
// tore the frames still reading the old bytes) - still no driver-mediated write
|
||||
// into the busy mutable store, which on this class of Mali driver stalls the
|
||||
// thread or ghost-copies the whole arena, and the arena stops costing its size
|
||||
// again in RAM.
|
||||
// 128MB arena is a plain memcpy into GPU-visible memory; every driver-mediated
|
||||
// route for the same write stalls the thread or ghost-copies the whole arena on
|
||||
// this class of Mali driver, and the arena stops costing its size again in RAM.
|
||||
Bool DisableLargeBufferAdoption = false;
|
||||
// MOBILEGL_ESPRYT_FORCE_DS_READBACK_EMULATION: make DirectGLES skip the native ES
|
||||
// depth/stencil reads and always go through the shader-sampling emulation. Core GL
|
||||
@@ -471,20 +456,6 @@ namespace MobileGL::MG_Config {
|
||||
// The <path> of `unix:` / the <name> of `pipe:`. Empty for the other three modes.
|
||||
extern String TransportEndpoint;
|
||||
|
||||
// P7 F1. DID **THIS PROCESS'S OWN CONFIGURATION** ASK FOR A SPLIT TRANSPORT.
|
||||
//
|
||||
// `Transport` alone cannot answer that, and the difference is exactly the one the F1 gate
|
||||
// turns on. A unit fixture assigns `Transport` by hand to put the code under test on its
|
||||
// split arm (ServerLoopTest's main does, and says why) while building no client at all; a
|
||||
// real run gets it from MG_ConfigLoader::Init(), and that run WILL bring a client half up.
|
||||
// Only the second may be held to "never decide a record family's fate from a placeholder
|
||||
// caps mirror" - in the first there is no handshake, no mirror to adopt and nothing the
|
||||
// rule could mean.
|
||||
//
|
||||
// Written once, by InitTransport(), and never cleared: a process does not stop having been
|
||||
// configured. Read by MG_Remote::Client::CapsMirror::RequireFirstSnapshot.
|
||||
extern Bool SplitTransportRequestedByConfig;
|
||||
|
||||
// The MOBILEGL_IPC_* family. A separate table rather than more FeaturesTable members,
|
||||
// for the G1 reason above and because every field here is meaningless without the
|
||||
// transport: a build that cannot reach the MG_Remote code cannot honour one of them.
|
||||
@@ -494,25 +465,12 @@ namespace MobileGL::MG_Config {
|
||||
// the full planned inventory (PRESENT_CREDIT, POLL_ESCALATE, SHADOW_SHM,
|
||||
// INLINE_PAYLOADS, TRACE, ATTACH, RESPAWN, IDLE_EXIT_S), and every one of those belongs
|
||||
// to P6 or later.
|
||||
//
|
||||
// P12 (on-screen server window): MOBILEGL_IPC_SURFACE's two values. See IpcTable::Surface.
|
||||
enum class IpcSurface : Uint8 {
|
||||
Offscreen = 0, // a window surface is the client's own window, as before (the default)
|
||||
Server = 1, // a window surface is the SERVER's window: WindowKind::ServerOwned
|
||||
Host = 2, // a window surface draws into frames the DISPLAY HOST owns; the host presents
|
||||
};
|
||||
// IpcTable::AdoptTier when MOBILEGL_IPC_ADOPT_TIER is unset (or unparseable): T0 by default,
|
||||
// with QUIET fallbacks. Not a tier a user can type - the knob admits 0..2.
|
||||
inline constexpr Uint32 kAdoptTierUnset = 3;
|
||||
struct IpcTable {
|
||||
// MOBILEGL_IPC_SERVER_PATH: where to find libMobileGLServer. P6 consumes it; P5
|
||||
// lands the parse because t1's ctest ENVIRONMENT blocks and add_trace_replay_test's
|
||||
// SPLIT variant already carry it, and an environment variable that nothing parses is
|
||||
// indistinguishable from one that is parsed and ignored.
|
||||
String ServerPath;
|
||||
// Control endpoint and data-plane selection are independent of topology.
|
||||
String Control = "fork"; // fork | unix:<path> | tcp://host:port
|
||||
String Data = "auto"; // auto | shm | stream
|
||||
// MOBILEGL_IPC_RING_MB: SEG_CMD size. A RECORD MAY BE AT MOST HALF OF THIS
|
||||
// (RingProducer::MaxRecordBytes), so 8 MiB caps one record at 4 MiB; R-10 makes the
|
||||
// codec publish a max-record-bytes counter rather than assume that is enough.
|
||||
@@ -522,37 +480,8 @@ namespace MobileGL::MG_Config {
|
||||
// stage chunk budget (MGPipeStageChunkBytes, a quarter of this), and a record type with
|
||||
// no cut is Fatal{RingOverrun, "SEG_STAGE"} rather than allowed to exceed it.
|
||||
Uint32 StageMb = 32;
|
||||
// MOBILEGL_IPC_WIRE_DEFERRED_MB (P7 wave 4 M2, ID-P7-32): the SERVER's budget, in MiB,
|
||||
// for orphaned wire buffer stores - the old VkBuffer every glBufferData that crosses the
|
||||
// wire leaves behind - that a GPU command recorded but not yet retired may still name.
|
||||
// Stores no command names are destroyed at once and stores whose last submission has
|
||||
// retired are destroyed at the next park; this bounds the REST. When the parked bytes
|
||||
// exceed it after a sweep, the server flushes what it has recorded and waits for it
|
||||
// (WaitForWireBufferHostAccess's sync point, mid-frame), which retires every one. It is
|
||||
// not a frame count because a frame is not bounded: a snapshot-exiting pbuffer replay
|
||||
// delivers one present for 1.3 M calls. The same sync point also fires above a fixed
|
||||
// 1024 parked stores (VkBufferManager::kWireDeferredCountCeiling), because small
|
||||
// orphans never reach a byte budget. 0 IS THE NEGATIVE CONTROL for both, not "unlimited
|
||||
// by design": no forced sync, so a one-frame respecify-and-draw loop grows without bound
|
||||
// and MagmaWireReclaimScenario's watermark cases must go red.
|
||||
Uint32 WireDeferredMb = 64;
|
||||
// MOBILEGL_IPC_SPIN_US: spin before parking on a doorbell, either direction.
|
||||
Uint32 SpinUs = 50;
|
||||
// MOBILEGL_IPC_EVENT_WAIT_MS (PH-6, ID-P7-2): the SERVER's patience, in ms, for ONE
|
||||
// reverse-channel event that finds SEG_EVENT full under run-ahead. The apply thread
|
||||
// publishes, rings the client and parks until the client drains enough room; a client
|
||||
// that has not made room when this runs out - it stopped draining (NotDraining) or it
|
||||
// drains a slot at a time (TooSlow) - FORFEITS the reverse channel: that event and every
|
||||
// later one is dropped and counted (eventDropped), and the session stops by the ordinary
|
||||
// stop path rather than by Fatal{EventRingOverflow}. A peer that goes away (PeerGone) or
|
||||
// a session that is stopped (Stopped) ends the wait at once instead, so the knob may
|
||||
// exceed ServerLoop::Stop()'s 5000 ms join. It bounds the whole reservation, not one
|
||||
// park, so a trickling peer cannot stretch it - nor can a shm peer that writes the
|
||||
// (peer-writable) eventRingFull latch to 0 itself, though that one keeps the apply
|
||||
// thread spinning rather than parked until the budget runs out. Was a 30000 ms constant
|
||||
// spent twice. Read by the server only (ServerSpawn.cpp passes it to a spawned child);
|
||||
// the lockstep arm (no kCapRunAheadApply, i.e. Magma) never waits and keeps P5C's Fatal.
|
||||
Uint32 EventWaitMs = 2000;
|
||||
// MOBILEGL_IPC_PERSISTENT_BLOCK_KB: block granularity of the persistent-map push.
|
||||
// 0 IS A NEGATIVE CONTROL, NOT "unlimited": it disables the push, and
|
||||
// PersistentCoherentMapScenario must go RED under it (exit gate E3(a)).
|
||||
@@ -567,80 +496,11 @@ namespace MobileGL::MG_Config {
|
||||
// every reply-slot row), which is the only place BARRIER-PULLED fields are read. 0
|
||||
// restores the per-record barrier of R-1.
|
||||
Uint32 BatchWaits = 1;
|
||||
// MOBILEGL_IPC_CREATE_WINDOW: how many RESOURCE_CREATE answers may be outstanding before the
|
||||
// client waits for one. 1 = every create waits (the shape R-5 shipped with); N > 1 = up to N
|
||||
// creates go out fire-and-forget, their caller reads a PROVISIONAL accept, and the oldest
|
||||
// answer is taken when the window fills.
|
||||
//
|
||||
// DEFAULT 2, AND IT TOOK THREE THINGS TO GET HERE. The deferral was inert for two
|
||||
// measured reasons and one structural one, in the order they were found:
|
||||
// 1. the reply buffer was a ring of the last 8 answers, and between two creates this
|
||||
// client emits on the order of a thousand records - so the answer was always gone
|
||||
// (`want=310` on every miss while the ring spanned [1175..1504]);
|
||||
// 2. a residency budget that tried to take answers back early could not help, because
|
||||
// what displaces an answer is what the SERVER sends, not what the client emits;
|
||||
// 3. and so the fix was RETENTION - a link keeps a declared answer until its reader
|
||||
// takes it (Transport/ILink.h's RetainsReplies, StreamLink's declared-answer store).
|
||||
//
|
||||
// MEASURED ON THE DEVICE, load frame, both ends rebuilt (create 4,536, records 103,097,
|
||||
// frame-sent identical per op throughout):
|
||||
// window 1 4,536 blocking takes 28.66 s (the shape R-5 shipped)
|
||||
// window 2 2,500 17.27 s
|
||||
// window 4 1,644 11.02 s
|
||||
// and the round trip does NOT grow as the window deepens (5,285 / 4,082 us against 5,672
|
||||
// at 1), which is the measurement that says the ~5 ms is a WAKEUP the server batches away
|
||||
// rather than its apply throughput - so amortising four creates per wakeup is a real 2.6x.
|
||||
//
|
||||
// 6 IS THE DEFAULT, AND IT IS WHERE THE CURVE FLATTENS - the sweep that says so is the
|
||||
// one the paragraph above asked for, and it moved the ceiling too (kCreateWindowMax is 8
|
||||
// now; the old 4 was derived from a reply pool the window does not run on). Three
|
||||
// interleaved runs per arm on one binary, load frame, create 4,536 sent in every arm:
|
||||
//
|
||||
// window 4 1,503 blocking takes 13.23 s median (spread 11.37-16.29)
|
||||
// window 5 1,277 11.31 s (10.61-12.12)
|
||||
// window 6 1,155 10.79 s ( 9.69-10.81)
|
||||
// window 8 859 10.96 s ( 8.92-11.03)
|
||||
//
|
||||
// 4->5 buys 1.92 s, 5->6 buys 0.53 s, 6->8 buys NOTHING (-0.18 s, inside a session noise
|
||||
// of ~1.5-2 s) - so 6 is the smallest window on the flat part and the extra answers a
|
||||
// deeper one holds buy no time. AND PAST THIS POINT THE FRAME IS NOT WAIT-BOUND ANY MORE:
|
||||
// window 8 pays 296 fewer blocking takes than window 6 and the wall clock does not move.
|
||||
// The store is not the constraint either - its peak is logged as it crosses (StreamLink's
|
||||
// P12 line) and reads 6..11 against a cap of 24 at every arm from 5 up. What is left is
|
||||
// the constant ~350-400 creates that block for a reason depth does not reach, and the
|
||||
// 101 MB / 103k records the SERVER has to apply. NOTE THE PREDICATE the whole mechanism rests
|
||||
// on: an answer is retained because the wire DECLARED it will be read - NOT because its
|
||||
// caller was fire-and-forget. The window's own creates are fire-and-forget AND read, so a
|
||||
// flag keyed on wantReply would disable the very mechanism it exists to enable
|
||||
// (docs/Disaggregated/notes/p12/CREATE-WINDOW-MEASURED.md sections 7-11).
|
||||
Uint32 CreateWindow = 10;
|
||||
// MOBILEGL_IPC_PBO_READBACK_SYNC (P9 W1, MG_Remote/CONTRACT-P9.md §1): 1 = a glReadPixels
|
||||
// or glGetTexImage into a bound GL_PIXEL_PACK_BUFFER takes the reply-slot form again -
|
||||
// the client waits for the pixels and uploads them into the buffer itself, as before P9.
|
||||
// 0 (default) sends read_pixels_to_buffer / get_texture_image_to_buffer, waits for
|
||||
// nothing, and marks the buffer GPU-written. The 1 arm is the A/B control and the
|
||||
// red-once of the wait-count gate (PackBufferReadbackScenario): it must show a reply
|
||||
// wait per read.
|
||||
Uint32 PboReadbackSync = 0;
|
||||
// MOBILEGL_IPC_POLL_ESCALATE (P10, MG_Remote/CONTRACT-P10.md §1): a glClientWaitSync with a
|
||||
// zero timeout or a glGetSynciv(GL_SYNC_STATUS) is answered by the client from what the
|
||||
// server reported (kEventFenceSignaled) - "signaled" when it has been, "not yet" otherwise
|
||||
// - and only the Nth "not yet" in a row on one fence crosses as a real round trip, so a
|
||||
// poll loop cannot outlive a late report. 0 = every poll crosses, as before P10: the A/B
|
||||
// arm and the red-once of the no-reply gate (FencePollScenario).
|
||||
Uint32 PollEscalate = 64;
|
||||
// MOBILEGL_IPC_ADOPT_TIER, THE ZERO-COPY SWITCH (ruling ID-P11-14, CONTRACT-P11 B2):
|
||||
// UNSET (kAdoptTierUnset, the default since 2026-09-29, the user's decision) = T0 where the
|
||||
// session can run it, T2 QUIETLY where it cannot (MGLOG_D only, still counted);
|
||||
// 0 = T0 asked by name - a T0 this session cannot use (a stream plane, the server's allow
|
||||
// switch, no AHardwareBuffer, a failed server POST) is T2 plus one named line;
|
||||
// 1 = T1, closed - refused by name, then T2; 2 = emulate (T2: the client keeps the shadow
|
||||
// and pushes). Never a Fatal (MG_Remote/Transport/AdoptTier.h).
|
||||
Uint32 AdoptTier = kAdoptTierUnset;
|
||||
// MOBILEGL_IPC_ALLOW_ADOPT_T0 (server): 1 (default) = grant a client's T0 ask when this
|
||||
// platform and the backend's POST self-test allow it; 0 = never grant it (the session
|
||||
// runs T2 and says so). Read by the server role only; kept through ServerSpawn.
|
||||
Uint32 AllowAdoptT0 = 1;
|
||||
// MOBILEGL_IPC_ADOPT_TIER: 2 = emulate (client keeps the shadow and pushes), which
|
||||
// is the only tier P5 implements and the reason persistent-map-push can be non-zero
|
||||
// at all (R-6). 0 and 1 parse and are Fatal at use with "P11"; they exist now so the
|
||||
// negative control has a spelling the day P11 writes it.
|
||||
Uint32 AdoptTier = 2;
|
||||
// MOBILEGL_IPC_VERB_BARRIER: 1 = the client blocks at every verb boundary until
|
||||
// appliedSeq reaches its emitSeq (R-1). 0 is the negative control: it is EXPECTED to
|
||||
// be red, because 31 of the 63 PipeInputs fields are still pulled from a live
|
||||
@@ -673,21 +533,6 @@ namespace MobileGL::MG_Config {
|
||||
// client that is already CPU-bound and costs a frame of latency, which is why the
|
||||
// default is 1 and not "as deep as the ring".
|
||||
Uint32 PresentCredit = 1;
|
||||
// MOBILEGL_IPC_CONTROL_TIMEOUT_MS (CONTRACT-P6 §5.4 D5b): how long a spawn/tcp client
|
||||
// waits for the SurfaceReply to one surface-control op (eglCreate*Surface, MakeCurrent,
|
||||
// ...) once the server's backend is up. Its expiry is NOT fatal: the doorbell's death
|
||||
// latch decides dead (device lost) from alive-but-silent (a named diagnostic). The
|
||||
// contract named this knob from P6 on; the client hard-coded its default until P7.
|
||||
Uint32 ControlTimeoutMs = 5000;
|
||||
// MOBILEGL_IPC_COLD_START_MS (P7): the same wait for the three ops a server may bring its
|
||||
// NATIVE backend up inside - CreatePbufferSurface, CreateWindowSurface, MakeCurrent -
|
||||
// until the session's first MakeCurrent is answered ok. The bring-up is lazy (Espryt's
|
||||
// eglInitialize, Magma's Vulkan instance and device), ~100 ms on a workstation and more
|
||||
// than the steady 5 s on a loaded CI runner (retrace-split spawn legs, runs 35671704873
|
||||
// and 35706183230). Never shorter than CONTROL_TIMEOUT_MS; its expiry is the same
|
||||
// non-fatal named answer. The default is the spawn connect budget, for the same reason:
|
||||
// "the server has to create a backend, and a cold software rasteriser is not fast".
|
||||
Uint32 ColdStartMs = 20000;
|
||||
// MOBILEGL_IPC_STRICT_ERRORS: promote a BARRIER-PULLED field read - and, in a split
|
||||
// build, the seven sticky forwards that are otherwise exempt - from "count it in
|
||||
// rsp" to Fatal (R-7.3).
|
||||
@@ -712,33 +557,8 @@ namespace MobileGL::MG_Config {
|
||||
// because the resolved mask is logged by whoever starts the apply thread, and the
|
||||
// string is what an operator typed.
|
||||
String ServerAffinity = "auto";
|
||||
// MOBILEGL_IPC_SURFACE (P12, on-screen server window) = offscreen | server. `server` makes
|
||||
// the client a HEADLESS one: eglCreateWindowSurface / eglCreatePlatformWindowSurface accept
|
||||
// any native window including NULL, send ONE CreateWindowSurface naming
|
||||
// WindowKind::ServerOwned (token 0, the size from EGL_WIDTH/EGL_HEIGHT, 0/0 = the server's
|
||||
// own) and no SetWindowHandle, and take the surface's real geometry back from the server.
|
||||
// Meaningful only when this client talks to a remote server (MOBILEGL_TRANSPORT=spawn, the
|
||||
// fork or tcp:// control); under monolith / inproc it is parsed, logged as ignored, and
|
||||
// changes nothing. `offscreen` (the default) is today's behaviour byte for byte.
|
||||
// Pbuffers stay pbuffers in both modes (D4: one mode per session, decided by the first).
|
||||
IpcSurface Surface = IpcSurface::Offscreen;
|
||||
};
|
||||
extern IpcTable Ipc;
|
||||
|
||||
// P12: the one predicate every client-side consumer of MOBILEGL_IPC_SURFACE asks - a window
|
||||
// surface is the server's when the knob says so AND there is a remote server to own it.
|
||||
inline Bool ServerOwnedWindowSurfaces() {
|
||||
return Transport == TransportMode::Spawn && Ipc.Surface == IpcSurface::Server;
|
||||
}
|
||||
|
||||
// P12: the other on-screen shape, and the mirror image of the one above. The display host
|
||||
// (the Android side that owns the screen) allocates the frames, offers each one over the
|
||||
// host frame bridge, and puts it on the glass when this side says it is drawn - so a
|
||||
// client that asks for this has no window of its own either, and the server takes the
|
||||
// frames rather than making a window.
|
||||
inline Bool HostFrameWindowSurfaces() {
|
||||
return Transport == TransportMode::Spawn && Ipc.Surface == IpcSurface::Host;
|
||||
}
|
||||
#else
|
||||
// The whole point: in a build without MG_Remote this folds at compile time, so
|
||||
// `if (MG_Config::Transport != MG_Config::TransportMode::Monolith)` in Init.cpp is a
|
||||
|
||||
+9
-100
@@ -16,11 +16,6 @@
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstdlib>
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// std::strcmp, for InitIpc's server-role check (P12). Split-only, so the pull build's TU is
|
||||
// unchanged (G1).
|
||||
#include <cstring>
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
extern char** environ;
|
||||
@@ -37,7 +32,6 @@ namespace MobileGL::MG_Config {
|
||||
// and there is nothing to define.
|
||||
TransportMode Transport = TransportMode::Monolith;
|
||||
String TransportEndpoint;
|
||||
Bool SplitTransportRequestedByConfig = false;
|
||||
IpcTable Ipc;
|
||||
#endif
|
||||
} // namespace MobileGL::MG_Config
|
||||
@@ -230,9 +224,6 @@ namespace MobileGL::MG_ConfigLoader {
|
||||
features.AdvertiseFp64 = QueryEnvFlag("MOBILEGL_ADVERTISE_FP64");
|
||||
features.MagmaR11G11B10FFallback = QueryEnvFlag("MOBILEGL_MAGMA_R11G11B10F_FALLBACK");
|
||||
features.MagmaFramesInFlight = QueryEnvUint32("MOBILEGL_MAGMA_FRAMESINFLIGHT", 3, 1, 64);
|
||||
features.MagmaMaxDrawsPerCommandBuffer =
|
||||
QueryEnvUint32("MOBILEGL_MAGMA_MAX_DRAWS_PER_COMMAND_BUFFER", 16384, 0, 1u << 24);
|
||||
features.MagmaDescriptorTrimFrames = QueryEnvUint32("MOBILEGL_MAGMA_DESCRIPTOR_TRIM_FRAMES", 120, 0, 1u << 20);
|
||||
features.EsprytAvoidSamplerMipmapMinFilter =
|
||||
QueryEnvFlag("MOBILEGL_ESPRYT_AVOID_SAMPLER_MIPMAP_MIN_FILTER");
|
||||
features.EsprytAvoidExplicitLodBias = QueryEnvFlag("MOBILEGL_ESPRYT_AVOID_EXPLICIT_LOD_BIAS");
|
||||
@@ -339,10 +330,6 @@ namespace MobileGL::MG_ConfigLoader {
|
||||
}
|
||||
if (lowered == "inproc") {
|
||||
MG_Config::Transport = MG_Config::TransportMode::InProcess;
|
||||
// P7 F1: see Config.h. Set beside the mode, on the two arms that actually resolve
|
||||
// one, and NOT on the two that name a transport and then stay monolith - a process
|
||||
// that was refused its transport brings no client half up either.
|
||||
MG_Config::SplitTransportRequestedByConfig = true;
|
||||
MGLOG_I("Config: MOBILEGL_TRANSPORT=inproc - the MGPipe record stream crosses a real "
|
||||
"ring to an apply thread");
|
||||
return;
|
||||
@@ -355,7 +342,6 @@ namespace MobileGL::MG_ConfigLoader {
|
||||
// rather than the fork-coupled shape ARCHITECTURE.md:488 described.
|
||||
if (lowered == "spawn") {
|
||||
MG_Config::Transport = MG_Config::TransportMode::Spawn;
|
||||
MG_Config::SplitTransportRequestedByConfig = true; // P7 F1, as above.
|
||||
// THE SAME SHAPE AS THE inproc LINE ABOVE, AND FOR THE SAME REASON.
|
||||
// run_trace_case.cmake asserts on a distinctive sentence from this
|
||||
// function rather than on `MOBILEGL_TRANSPORT=spawn` alone, because
|
||||
@@ -392,22 +378,13 @@ namespace MobileGL::MG_ConfigLoader {
|
||||
inline void InitIpc() {
|
||||
auto& ipc = MG_Config::Ipc;
|
||||
QueryEnvVariable("MOBILEGL_IPC_SERVER_PATH", ipc.ServerPath, "");
|
||||
QueryEnvVariable("MOBILEGL_IPC_CONTROL", ipc.Control, "fork");
|
||||
QueryEnvVariable("MOBILEGL_IPC_DATA", ipc.Data, "auto");
|
||||
// Both ring floors are 1 MiB, not 0: a ring caps ONE record at half its size, and
|
||||
// the catalogue's largest fixed payload (MGPFramebufferState, 304 bytes) plus a
|
||||
// create_shader_state archive already needs far more than a toy ring. The ceilings
|
||||
// are sanity, not policy.
|
||||
ipc.RingMb = QueryEnvUint32("MOBILEGL_IPC_RING_MB", 8, 1, 1024);
|
||||
ipc.StageMb = QueryEnvUint32("MOBILEGL_IPC_STAGE_MB", 32, 1, 4096);
|
||||
// P7 wave 4 M2 (Config.h has the semantics). 0 is admitted ON PURPOSE as the negative
|
||||
// control: no forced sync, and MagmaWireReclaimScenario's watermark case must go red.
|
||||
ipc.WireDeferredMb = QueryEnvUint32("MOBILEGL_IPC_WIRE_DEFERRED_MB", 64, 0, 65536);
|
||||
ipc.SpinUs = QueryEnvUint32("MOBILEGL_IPC_SPIN_US", 50, 0, 1000000);
|
||||
// PH-6 (ID-P7-2; Config.h has the semantics). 0 is NOT admitted: a server with no
|
||||
// patience at all would forfeit a healthy run-ahead client the first time its ring
|
||||
// filled between two of the client's drains, which is an ordinary backlog.
|
||||
ipc.EventWaitMs = QueryEnvUint32("MOBILEGL_IPC_EVENT_WAIT_MS", 2000, 1, 600000);
|
||||
// 0 is admitted ON PURPOSE and is the negative control of exit gate E3(a): it turns
|
||||
// the persistent-map push OFF, and PersistentCoherentMapScenario must go red.
|
||||
ipc.PersistentBlockKb = QueryEnvUint32("MOBILEGL_IPC_PERSISTENT_BLOCK_KB", 64, 0, 65536);
|
||||
@@ -415,30 +392,14 @@ namespace MobileGL::MG_ConfigLoader {
|
||||
// xxHash64 changed since the last push are shipped.
|
||||
ipc.PersistentHashSuppress = QueryEnvUint32("MOBILEGL_IPC_PERSISTENT_HASH_SUPPRESS", 1, 0, 1);
|
||||
ipc.BatchWaits = QueryEnvUint32("MOBILEGL_IPC_BATCH_WAITS", 1, 0, 1);
|
||||
// The create window. DEFAULT 6, and it works because a link that declares RetainsReplies
|
||||
// keeps a declared answer until its reader takes it - Config.h carries the three reasons it
|
||||
// was inert before, the device numbers, and the sweep that put the default at 6 rather
|
||||
// than 4 or 8 (the curve flattens at 6: 4->5 buys 1.92 s, 5->6 0.53 s, 6->8 nothing).
|
||||
// Capped at 8: the retained set is bounded by the window's own depth, the store holds 24
|
||||
// declared answers, and the device sweep showed the wall clock still falling at the old
|
||||
// cap of 4 (see WireTables.cpp's kCreateWindowMax). WireTables.cpp's static_assert and
|
||||
// StreamLink's crossing log are the checks on this number.
|
||||
ipc.CreateWindow = QueryEnvUint32("MOBILEGL_IPC_CREATE_WINDOW", 10, 1, 12);
|
||||
// P9 W1: the pack-buffer readback's A/B and red-once control (Config.h says both).
|
||||
ipc.PboReadbackSync = QueryEnvUint32("MOBILEGL_IPC_PBO_READBACK_SYNC", 0, 0, 1);
|
||||
// P10: fence polls answered locally; 0 is the A/B arm (Config.h).
|
||||
ipc.PollEscalate = QueryEnvUint32("MOBILEGL_IPC_POLL_ESCALATE", 64, 0, 1000000);
|
||||
// The verify harness compares the pushed block against the applier per verb; a
|
||||
// batched queue lets the comparer read a supplied field mid-apply, which is a
|
||||
// torn read rather than a divergence. The batch is therefore off whenever the
|
||||
// shadow comparer is armed.
|
||||
if (MG_Config::Features.PipeVerify) ipc.BatchWaits = 0;
|
||||
// UNSET is T0 with quiet fallbacks (the default since 2026-09-29); 0 asks for T0 by name, 1 is
|
||||
// refused by name, 2 is T2 - settled at the handshake from the data plane (P11 A1/B2,
|
||||
// MG_Remote/Transport/AdoptTier.h). An unparseable value is warned about and reads as unset.
|
||||
ipc.AdoptTier = QueryEnvUint32("MOBILEGL_IPC_ADOPT_TIER", MG_Config::kAdoptTierUnset, 0, 2);
|
||||
// P11 B2: the server's own T0 allow switch (Config.h).
|
||||
ipc.AllowAdoptT0 = QueryEnvUint32("MOBILEGL_IPC_ALLOW_ADOPT_T0", 1, 0, 1);
|
||||
// 2 is the only tier P5 implements (R-6). 0 and 1 parse here and are refused at the
|
||||
// point of use, which is where the "P11" in the message belongs.
|
||||
ipc.AdoptTier = QueryEnvUint32("MOBILEGL_IPC_ADOPT_TIER", 2, 0, 2);
|
||||
ipc.VerbBarrier = QueryEnvUint32("MOBILEGL_IPC_VERB_BARRIER", 1, 0, 1);
|
||||
// P5e (MG_Remote/CONTRACT-P5E.md §1). The wait rule's A/B, parsed here like every
|
||||
// other IPC knob and armed only where the server publishes kCapRunAheadApply.
|
||||
@@ -451,10 +412,6 @@ namespace MobileGL::MG_ConfigLoader {
|
||||
// deeper queue buys nothing on a CPU-bound client and pays for it in latency. 0 is NOT
|
||||
// admitted: a credit of zero would mean "publish no present at all".
|
||||
ipc.PresentCredit = QueryEnvUint32("MOBILEGL_IPC_PRESENT_CREDIT", 1, 1, 8);
|
||||
// CONTRACT-P6 D5b's reply bound and P7's cold-start budget (Config.h has the semantics).
|
||||
// Both are floored at 100 ms: a zero bound would declare every live server silent.
|
||||
ipc.ControlTimeoutMs = QueryEnvUint32("MOBILEGL_IPC_CONTROL_TIMEOUT_MS", 5000, 100, 600000);
|
||||
ipc.ColdStartMs = QueryEnvUint32("MOBILEGL_IPC_COLD_START_MS", 20000, 100, 600000);
|
||||
ipc.StrictErrors = QueryEnvFlag("MOBILEGL_IPC_STRICT_ERRORS");
|
||||
ipc.Audit = QueryEnvFlag("MOBILEGL_IPC_AUDIT");
|
||||
QueryEnvVariable("MOBILEGL_IPC_SERVER_AFFINITY", ipc.ServerAffinity, "auto");
|
||||
@@ -494,69 +451,21 @@ namespace MobileGL::MG_ConfigLoader {
|
||||
}
|
||||
}
|
||||
|
||||
// P12 (on-screen): MOBILEGL_IPC_SURFACE = offscreen | server | host (Config.h has the
|
||||
// semantics). An unknown value is named and read as the default, like every knob here.
|
||||
{
|
||||
String surface;
|
||||
QueryEnvVariable("MOBILEGL_IPC_SURFACE", surface, "offscreen");
|
||||
std::transform(surface.begin(), surface.end(), surface.begin(),
|
||||
[](unsigned char c) { return static_cast<char>(std::tolower(c)); });
|
||||
if (surface.empty() || surface == "offscreen") {
|
||||
ipc.Surface = MG_Config::IpcSurface::Offscreen;
|
||||
} else if (surface == "server") {
|
||||
ipc.Surface = MG_Config::IpcSurface::Server;
|
||||
} else if (surface == "host") {
|
||||
ipc.Surface = MG_Config::IpcSurface::Host;
|
||||
} else {
|
||||
MGLOG_W("Config: Ignoring invalid env variable MOBILEGL_IPC_SURFACE='%s'; expected "
|
||||
"offscreen|server|host, using offscreen",
|
||||
surface.c_str());
|
||||
ipc.Surface = MG_Config::IpcSurface::Offscreen;
|
||||
}
|
||||
// (Not said by a server process: a spawned server inherits the client's environment,
|
||||
// parses this before RunSession sets its own transport, and has no client half anyway.)
|
||||
const char* role = std::getenv("MOBILEGL_IPC_ROLE");
|
||||
const Bool serverProcess = role != nullptr && std::strcmp(role, "server") == 0;
|
||||
if (ipc.Surface != MG_Config::IpcSurface::Offscreen && !serverProcess &&
|
||||
MG_Config::Transport != MG_Config::TransportMode::Spawn) {
|
||||
// Said, not silently honoured: there is no remote server here to own a window.
|
||||
MGLOG_W("Config: MOBILEGL_IPC_SURFACE=%s is IGNORED - it asks for an on-screen "
|
||||
"surface (the server's own window, or the frames the display host owns) and "
|
||||
"this run has no remote server to provide one: MOBILEGL_TRANSPORT is not "
|
||||
"spawn. Window surfaces stay the client's own",
|
||||
ipc.Surface == MG_Config::IpcSurface::Server ? "server" : "host");
|
||||
}
|
||||
}
|
||||
|
||||
if (MG_Config::Transport == MG_Config::TransportMode::Monolith) return;
|
||||
// One line, on the arm where these numbers decide behaviour, because every one of
|
||||
// them is a number a bug report has to quote.
|
||||
// CREATE-WINDOW IS IN THIS LINE BECAUSE A RUN HAS TO SAY WHICH WINDOW IT USED. It was
|
||||
// missing while the value was a number nobody varied, and the moment it became one that
|
||||
// changes the wall clock by seconds (the P12 sweep: 28.3 s at 1 down to 10.8 s at 6) a
|
||||
// log that does not name it makes every run ambiguous about its own configuration.
|
||||
MGLOG_I("Config: IPC ring=%uMiB stage=%uMiB wire-deferred=%uMiB spin=%uus event-wait=%ums "
|
||||
"persistent-block=%uKiB create-window=%u pbo-readback-sync=%u poll-escalate=%u "
|
||||
"adopt-tier=%s allow-t0=%u verb-barrier=%u run-ahead=%u present-credit=%u control-timeout=%ums "
|
||||
"cold-start=%ums strict=%d audit=%d role-split-state=%d affinity='%s' surface=%s",
|
||||
ipc.RingMb, ipc.StageMb, ipc.WireDeferredMb, ipc.SpinUs, ipc.EventWaitMs,
|
||||
ipc.PersistentBlockKb, ipc.CreateWindow, ipc.PboReadbackSync, ipc.PollEscalate,
|
||||
ipc.AdoptTier == 0 ? "0" : ipc.AdoptTier == 1 ? "1" : ipc.AdoptTier == 2 ? "2" : "unset(T0)",
|
||||
ipc.AllowAdoptT0,
|
||||
ipc.VerbBarrier, ipc.RunAhead, ipc.PresentCredit, ipc.ControlTimeoutMs, ipc.ColdStartMs,
|
||||
MGLOG_I("Config: IPC ring=%uMiB stage=%uMiB spin=%uus persistent-block=%uKiB "
|
||||
"adopt-tier=%u verb-barrier=%u run-ahead=%u present-credit=%u strict=%d "
|
||||
"audit=%d role-split-state=%d affinity='%s'",
|
||||
ipc.RingMb, ipc.StageMb, ipc.SpinUs, ipc.PersistentBlockKb, ipc.AdoptTier,
|
||||
ipc.VerbBarrier, ipc.RunAhead, ipc.PresentCredit,
|
||||
static_cast<int>(ipc.StrictErrors), static_cast<int>(ipc.Audit),
|
||||
static_cast<int>(ipc.RoleSplitState), ipc.ServerAffinity.c_str(),
|
||||
MG_Config::ServerOwnedWindowSurfaces() ? "server" : "offscreen");
|
||||
static_cast<int>(ipc.RoleSplitState), ipc.ServerAffinity.c_str());
|
||||
if (ipc.VerbBarrier == 0) {
|
||||
MGLOG_W("Config: MOBILEGL_IPC_VERB_BARRIER=0 is the R-1 NEGATIVE CONTROL and is "
|
||||
"expected to fail: the client still pulls 31 of 63 PipeInputs fields from a "
|
||||
"live GLContext, so an unbarriered queue lets the server read future values");
|
||||
}
|
||||
if (ipc.WireDeferredMb == 0) {
|
||||
MGLOG_W("Config: MOBILEGL_IPC_WIRE_DEFERRED_MB=0 is the M2 NEGATIVE CONTROL: the "
|
||||
"server never forces a sync for orphaned wire buffer stores, so a long frame "
|
||||
"that respecifies and draws holds every one of them until the frame ends");
|
||||
}
|
||||
if (ipc.PersistentBlockKb == 0) {
|
||||
MGLOG_W("Config: MOBILEGL_IPC_PERSISTENT_BLOCK_KB=0 is the E3(a) NEGATIVE CONTROL: "
|
||||
"the persistent-map push is OFF and a coherent-map scenario must go red");
|
||||
|
||||
+2
-9
@@ -8,8 +8,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
// ============== Platform-specific definitions and macros ============== //
|
||||
// No __ANDROID_API__ pin here on purpose. The effective API level is owned by
|
||||
// the build system (gradle minSdk 26 -> -DANDROID_PLATFORM=android-26, enforced
|
||||
@@ -36,11 +34,6 @@
|
||||
#ifdef _WIN32
|
||||
#define MOBILEGL_EXPORT extern "C" __declspec(dllexport)
|
||||
#else
|
||||
// Default visibility, which is what the platform's own GL and EGL headers declare their entry
|
||||
// points with. The one place where that is not enough - a vendor library handing glvnd its own
|
||||
// entry points, where a reference resolving against the process instead of this library would be a
|
||||
// call back into the dispatcher - is answered at link time with -Bsymbolic-functions rather than
|
||||
// here, because a second visibility on the same declaration does not compile.
|
||||
#define MOBILEGL_EXPORT extern "C" __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
@@ -112,8 +105,8 @@
|
||||
#define MOBILEGL_ASSERT(condition, ...) \
|
||||
do { \
|
||||
if (!(condition)) { \
|
||||
fprintf(stderr, "Assertion failed" __VA_OPT__(": ") "%s", "" __VA_ARGS__); \
|
||||
fprintf(stderr, " at %s:%d (%s)\n", __FILE__, __LINE__, __func__); \
|
||||
MGLOG_F("Assertion failed" __VA_OPT__(": ") __VA_ARGS__); \
|
||||
MGLOG_F(" at %s:%d (%s)", __FILE__, __LINE__, __func__); \
|
||||
TRAP; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
+1
-53
@@ -21,9 +21,6 @@
|
||||
#include <MG_Util/ShaderTranspiler/ShaderCompiler.h>
|
||||
#include <MG_State/GLState/ProgramState/ProgramTranslationCache.h>
|
||||
#include <MG_Util/ShaderTranspiler/TranslationCache.h>
|
||||
#if MOBILEGL_PIPE_VERIFY
|
||||
#include <MG_Backend/MGPipe/PipeInputs.h> // MGPipeVerifyFlushSummary, before Debug::Close in DestroyImpl
|
||||
#endif
|
||||
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
@@ -102,14 +99,6 @@ namespace MobileGL {
|
||||
MG_State::GLState::ClearProgramTranslationCache();
|
||||
MG_Backend::gBackendFunctionsTable = {};
|
||||
g_isInitialized = false;
|
||||
#if MOBILEGL_PIPE_VERIFY
|
||||
// BEFORE Close, and from here rather than from a static destructor (V1 fix round 2):
|
||||
// Close() nulls the role's sink and Log.cpp's next write reopens it with "w", so the
|
||||
// FATAL=0 summary the comparator used to write from __run_exit_handlers truncated the
|
||||
// client half of every such run to that one line. Verify builds only - the guard is
|
||||
// the compile definition, not a runtime knob, and the pull build gains no byte (G1).
|
||||
MG_Pipe::MGPipeVerifyFlushSummary();
|
||||
#endif
|
||||
if (logLifecycle) {
|
||||
MG_Util::Debug::Close();
|
||||
}
|
||||
@@ -132,50 +121,9 @@ namespace MobileGL {
|
||||
// boundary counters latch their enable flag here, so every counting site in the
|
||||
// two backends is a load of an already-settled global for the rest of the run.
|
||||
MG_Util::PipeStats::Init();
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// F1 (P7 wave 2). THE WIRE COMES UP BEFORE THE FIRST FRONTEND OBJECT IS BORN, and the
|
||||
// ORDER is the fix - not a wait, and not a friendlier default mask.
|
||||
//
|
||||
// MG_State::Init() constructs GLContext, and GLContext's TextureState constructor
|
||||
// materialises one default texture object per target (GL 3.3 core 3.8,
|
||||
// TextureState.cpp:62-71). TextureObjectBase's constructor emits resource_create for
|
||||
// every one of them (TextureState/TextureObject.cpp:168-169), and that emission is
|
||||
// gated, through PipeFill's FamilyIsLive, on
|
||||
// CapsMirror::ServerConsumes(kMGPipeSubsystemTextureResources). In the old order the
|
||||
// mirror was still GENERATION 0 when it was asked - it had no snapshot because the
|
||||
// session had not been started yet, MG_Backend::Init() being what starts it - so it
|
||||
// answered from the placeholder, every one of those creates was withheld, and the log
|
||||
// said so once and then never again:
|
||||
//
|
||||
// MG_Remote client: the server does not consume MGPipe subsystem 0x400 - this
|
||||
// family emits NOTHING and the legacy pull path runs for it (R-8). callMask=0x0,
|
||||
// caps generation 0
|
||||
//
|
||||
// That is not a race and it never was one: the line reproduces byte-for-byte on
|
||||
// lavapipe and on an Adreno 830, because the two Init calls are two statements in one
|
||||
// thread. And "the legacy pull path runs for it" is false under split - the client has
|
||||
// no pull path to fall back to - so the records are simply lost, and only a later
|
||||
// respecify's self-healing create (TextureEmit.h:872) ever brings one back.
|
||||
//
|
||||
// A BOUNDED WAIT INSIDE ServerConsumes CANNOT FIX THIS AND WOULD DEADLOCK: during
|
||||
// MG_State::Init() no handshake is in flight, and the one that will land is started
|
||||
// LATER BY THIS SAME THREAD. The only correct answer is to have already brought it up,
|
||||
// which is what this hook does. ServerConsumes now REFUSES to answer from a
|
||||
// placeholder (CapsMirror.cpp), so a regression of this order is a named Fatal rather
|
||||
// than a whole family of silently dropped records.
|
||||
//
|
||||
// In a build without MOBILEGL_BUILD_DISAGGREGATED this statement does not exist, so
|
||||
// the pull build gains no symbol, no branch and no byte - which is what G1 measures.
|
||||
const Bool splitBackendIsUp = MG_Backend::InitSplitRolesBeforeState();
|
||||
#endif
|
||||
MG_State::Init();
|
||||
MGLOG_D("MG_State initialized");
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (!splitBackendIsUp)
|
||||
#endif
|
||||
{
|
||||
MG_Backend::Init();
|
||||
}
|
||||
MG_Backend::Init();
|
||||
MGLOG_D("MG_Backend initialized");
|
||||
MG_Impl::Init();
|
||||
MGLOG_D("MG_Impl initialized");
|
||||
|
||||
@@ -172,15 +172,11 @@ namespace MobileGL::MG_Backend {
|
||||
return false;
|
||||
}
|
||||
|
||||
// A DISPLAY IS A CONNECTION, NOT A RESOURCE THIS BACKEND OWNS, and refusing the second one
|
||||
// refused a caller for a reason that is not there: the surface and context tables are keyed
|
||||
// by the display each was created on, every operation carries its own display handle, and
|
||||
// this field has no reader anywhere - it was the whole of the rule.
|
||||
//
|
||||
// What the rule cost was a compositor. One asks for the display it will draw into AFTER
|
||||
// probing another, so the second eglInitialize is the one that matters, and a refusal there
|
||||
// is reported one layer up as "no usable DRM render device" - the probe having succeeded
|
||||
// and the real display having failed, with nothing in between that says which was refused.
|
||||
if (m_eglDisplayInitialized && m_eglDisplay != dpy) {
|
||||
MGLOG_E("InitializeEGLDisplay failed: backend already bound to a different EGLDisplay");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_eglDisplay = dpy;
|
||||
m_eglDisplayInitialized = true;
|
||||
if (major) {
|
||||
@@ -213,28 +209,6 @@ namespace MobileGL::MG_Backend {
|
||||
return true;
|
||||
}
|
||||
|
||||
// The frame itself is the backend's business (InitHostFrameSurface); what happens here is
|
||||
// the registration every surface kind shares, so the swap path and the state mirrors see
|
||||
// a host-framed surface exactly like any other.
|
||||
Bool BackendObject::CreateEGLHostFrameSurface(EGLSurface surface, Uint32 width, Uint32 height) {
|
||||
const std::lock_guard<std::recursive_mutex> lock(m_eglStateMutex);
|
||||
if (!m_eglDisplayInitialized) {
|
||||
MGLOG_E("CreateEGLHostFrameSurface failed: EGL display is not initialized");
|
||||
return false;
|
||||
}
|
||||
if (surface == EGL_NO_SURFACE) {
|
||||
MGLOG_E("CreateEGLHostFrameSurface failed: invalid EGLSurface");
|
||||
return false;
|
||||
}
|
||||
auto& state = m_eglSurfaces[surface];
|
||||
state = EGLSurfaceState{
|
||||
.Kind = SurfaceKind::HostFrame,
|
||||
.Width = static_cast<EGLint>(std::max<Uint32>(width, 1)),
|
||||
.Height = static_cast<EGLint>(std::max<Uint32>(height, 1)),
|
||||
};
|
||||
return ActivateEGLSurface(surface);
|
||||
}
|
||||
|
||||
Bool BackendObject::CreateEGLPbufferSurface(EGLSurface surface, EGLint width, EGLint height) {
|
||||
const std::lock_guard<std::recursive_mutex> lock(m_eglStateMutex);
|
||||
return RegisterEGLPbufferSurface(surface, width, height) && ActivateEGLSurface(surface);
|
||||
@@ -316,11 +290,6 @@ namespace MobileGL::MG_Backend {
|
||||
MGLOG_E("ActivateEGLSurface failed: backend InitPbufferSurface failed");
|
||||
return false;
|
||||
}
|
||||
} else if (surfaceState->Kind == SurfaceKind::HostFrame) {
|
||||
if (!InitHostFrameSurface(surfaceState->Width, surfaceState->Height)) {
|
||||
MGLOG_E("ActivateEGLSurface failed: backend InitHostFrameSurface failed");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
MGLOG_E("ActivateEGLSurface failed: unsupported surface kind");
|
||||
return false;
|
||||
@@ -346,29 +315,6 @@ namespace MobileGL::MG_Backend {
|
||||
MGLOG_E("MakeEGLCurrent failed: EGL display mismatch or not initialized");
|
||||
return false;
|
||||
}
|
||||
// EGL_KHR_surfaceless_context. A context whose draw and read surfaces are both absent has
|
||||
// no framebuffer of its own to be bound to: the caller draws into framebuffers it binds
|
||||
// itself, and this side only has to have its own GL context current on this thread for the
|
||||
// records that follow. Everything below this point describes a surface, so none of it
|
||||
// applies - and what is recorded is exactly what was asked for, so a later swap on a
|
||||
// surface that does not exist is never made to look like one that does.
|
||||
if (draw == EGL_NO_SURFACE && read == EGL_NO_SURFACE && ctx != EGL_NO_CONTEXT) {
|
||||
if (!m_backendCapabilitiesInitialized) {
|
||||
if (!InitCapabilities()) {
|
||||
MGLOG_E("MakeEGLCurrent failed: InitCapabilities failed");
|
||||
return false;
|
||||
}
|
||||
m_backendCapabilitiesInitialized = true;
|
||||
}
|
||||
ReleaseEGLCurrentThread(threadKey);
|
||||
m_eglCurrentThreads[threadKey] = EGLCurrentState{
|
||||
.Display = dpy,
|
||||
.DrawSurface = EGL_NO_SURFACE,
|
||||
.ReadSurface = EGL_NO_SURFACE,
|
||||
.Context = ctx,
|
||||
};
|
||||
return true;
|
||||
}
|
||||
if (!m_eglSurfaceInitialized) {
|
||||
if (draw != read || !ActivateEGLSurface(draw)) {
|
||||
MGLOG_E("MakeEGLCurrent failed: EGL surface is not initialized");
|
||||
@@ -441,12 +387,6 @@ namespace MobileGL::MG_Backend {
|
||||
return false;
|
||||
}
|
||||
|
||||
// A host-framed surface has no swapchain: presenting it means telling the host the frame
|
||||
// is drawn, because the host is what puts it on the glass.
|
||||
if (m_eglSurfaceKind == SurfaceKind::HostFrame) {
|
||||
return PresentHostFrame();
|
||||
}
|
||||
|
||||
const auto& backendFunctions = GetBackendFunctions();
|
||||
if (!backendFunctions.Present) {
|
||||
MGLOG_E("SwapEGLBuffers failed: backend Present function is null");
|
||||
@@ -464,27 +404,6 @@ namespace MobileGL::MG_Backend {
|
||||
}
|
||||
}
|
||||
|
||||
// A backend that has no host-framed surfaces says so by name: the server may ask for one
|
||||
// (MOBILEGL_IPC_SURFACE=host) against a build that cannot serve it, and that has to be a
|
||||
// refusal with a reason rather than a surface that draws nowhere.
|
||||
Bool BackendObject::InitHostFrameSurface(EGLint width, EGLint height) {
|
||||
(void)width;
|
||||
(void)height;
|
||||
MGLOG_E("InitHostFrameSurface: this backend has no host-framed surfaces");
|
||||
return false;
|
||||
}
|
||||
|
||||
Bool BackendObject::PresentHostFrame() {
|
||||
MGLOG_E("PresentHostFrame: this backend has no host-framed surfaces");
|
||||
return false;
|
||||
}
|
||||
|
||||
Bool BackendObject::PresentHostFrameIfCurrent() {
|
||||
const std::lock_guard<std::recursive_mutex> lock(m_eglStateMutex);
|
||||
if (!m_eglSurfaceInitialized || m_eglSurfaceKind != SurfaceKind::HostFrame) return true;
|
||||
return PresentHostFrame();
|
||||
}
|
||||
|
||||
Bool BackendObject::IsEGLSurfaceCurrent(EGLSurface surface) const {
|
||||
if (surface == EGL_NO_SURFACE) {
|
||||
return false;
|
||||
|
||||
@@ -332,13 +332,13 @@ namespace MobileGL {
|
||||
};
|
||||
|
||||
struct DynamicBackendParameters {
|
||||
Uint64 UniformBufferOffsetAlignment = 256;
|
||||
SizeT UniformBufferOffsetAlignment = 256;
|
||||
// GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT, which is a SEPARATE limit from the
|
||||
// uniform one and is routinely larger: Adreno 830 reports 32 for uniform buffers and
|
||||
// 64 for storage buffers. Answering the storage query with the uniform value let an
|
||||
// application bind a storage range at an offset the driver cannot address, which it
|
||||
// accepted without error and then wrote somewhere else entirely.
|
||||
Uint64 ShaderStorageBufferOffsetAlignment = 256;
|
||||
SizeT ShaderStorageBufferOffsetAlignment = 256;
|
||||
// GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT. 1.0 means the backend cannot filter anisotropically,
|
||||
// which is also why the extension is not advertised in that case.
|
||||
Float MaxTextureMaxAnisotropy = 1.0f;
|
||||
@@ -460,8 +460,8 @@ namespace MobileGL {
|
||||
// VulkanRenderer::SelectProvokingVertexMode out of VK_EXT_provoking_vertex,
|
||||
// provokingVertexModePerPipeline and the topology, so no single convention is true
|
||||
// of the backend.
|
||||
Uint32 LayerProvokingVertex = GL_UNDEFINED_VERTEX;
|
||||
Uint32 ViewportIndexProvokingVertex = GL_UNDEFINED_VERTEX;
|
||||
GLenum LayerProvokingVertex = GL_UNDEFINED_VERTEX;
|
||||
GLenum ViewportIndexProvokingVertex = GL_UNDEFINED_VERTEX;
|
||||
Int MaxViewportWidth = 16384;
|
||||
Int MaxViewportHeight = 16384;
|
||||
Float ViewportBoundsRangeMin = 0.0f;
|
||||
@@ -558,7 +558,7 @@ namespace MobileGL {
|
||||
Bool SupportsTessellationPointSize = true;
|
||||
// The geometry-stage twin (OpCapability GeometryPointSize).
|
||||
Bool SupportsGeometryPointSize = true;
|
||||
Uint64 MaxShaderStorageBlockSize = 128 * 1024 * 1024;
|
||||
SizeT MaxShaderStorageBlockSize = 128 * 1024 * 1024;
|
||||
Uint32 SubgroupSize = 0;
|
||||
Uint32 SubgroupSupportedStages = 0;
|
||||
Uint32 SubgroupSupportedFeatures = 0;
|
||||
@@ -595,18 +595,6 @@ namespace MobileGL {
|
||||
virtual Bool CreateEGLWindowSurface(EGLSurface surface, const WindowHandle& handle);
|
||||
virtual Bool ResizeEGLWindowSurface(EGLSurface surface, Uint32 width, Uint32 height);
|
||||
virtual Bool CreateEGLPbufferSurface(EGLSurface surface, EGLint width, EGLint height);
|
||||
// The host owns the screen: this side never gets a window of the client's to draw
|
||||
// into, so the surface it draws into is a frame the host allocated and offered over
|
||||
// the host frame bridge. Each swap tells the host the frame is done and takes the
|
||||
// next; presentation is the host's, not a swapchain's.
|
||||
virtual Bool CreateEGLHostFrameSurface(EGLSurface surface, Uint32 width, Uint32 height);
|
||||
virtual Bool InitHostFrameSurface(EGLint width, EGLint height);
|
||||
virtual Bool PresentHostFrame();
|
||||
// The present RECORD's half of a host-framed swap. A split client's swap reaches the
|
||||
// server as a present record (ServerVerbSink::OnPresent), never as SwapEGLBuffers, so
|
||||
// without this the host was never told a frame was drawn. True when the current
|
||||
// surface is not host-framed: there is nothing to present then.
|
||||
Bool PresentHostFrameIfCurrent();
|
||||
virtual Bool MakeEGLCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
|
||||
virtual Bool SwapEGLBuffers(EGLDisplay dpy, EGLSurface draw);
|
||||
// Forwards the app-requested eglSwapInterval to the backend's native
|
||||
@@ -628,11 +616,7 @@ namespace MobileGL {
|
||||
enum class SurfaceKind {
|
||||
None,
|
||||
Window,
|
||||
Pbuffer,
|
||||
// A surface whose drawing target is a frame the display host owns. There is no
|
||||
// swapchain behind it: the host puts the frame on the glass when this side says
|
||||
// it is drawn, which is why presenting one is its own call and not a Present.
|
||||
HostFrame
|
||||
Pbuffer
|
||||
};
|
||||
|
||||
struct EGLCurrentState {
|
||||
|
||||
@@ -39,21 +39,5 @@ namespace MobileGL::MG_Backend {
|
||||
// client-minted and needs no backend call, which is P10's. CONTRACT-P5 4 flags this as a
|
||||
// KNOWN OPEN ITEM and asks v1 to record which way it went: P5 keeps today's order.
|
||||
void ShutdownSplitRoles();
|
||||
|
||||
// F1 (P7 wave 2). Init()'s SPLIT ARM, run BEFORE MG_State::Init() rather than after it.
|
||||
//
|
||||
// Returns true when this process took the split path - whether the bring-up succeeded or
|
||||
// was refused by name - and the caller must then NOT call Init() a second time. Returns
|
||||
// false under MG_Config::TransportMode::Monolith, where there is nothing to bring up and
|
||||
// Init() keeps its own place after MG_State::Init().
|
||||
//
|
||||
// WHY IT EXISTS AT ALL, rather than MobileGL::Initialize simply calling Init() earlier:
|
||||
// the monolith arm of Init() must keep running after MG_State::Init(), because
|
||||
// BackendObject_DirectGLES::Initialize() is the tree's own order for it and moving it is a
|
||||
// pull-build change G1 forbids. So the split arm - and only the split arm - moves.
|
||||
//
|
||||
// It exists ONLY in a split build, for the reason InitServerRoleForSpawn states: a
|
||||
// definition guarded only on the inside still emits a symbol, and G1 measured that.
|
||||
Bool InitSplitRolesBeforeState();
|
||||
#endif
|
||||
} // namespace MobileGL::MG_Backend
|
||||
|
||||
@@ -6,12 +6,6 @@
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED && defined(__ANDROID__)
|
||||
// The role's own backend is resolved the way Utils.cpp (C6 / ID-52) resolves it; that needs this
|
||||
// header, and it has to be included at file scope - a header included inside this file's namespace
|
||||
// would nest its own namespace under it.
|
||||
#include <MG_Remote/Server/ServerLoop.h>
|
||||
#endif
|
||||
#include "BackendObject_DirectGLES.h"
|
||||
#include "MG_Backend/BackendObject.h"
|
||||
#include "MG_Backend/BackendObjects.h"
|
||||
@@ -899,16 +893,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
DestroyEGLContext();
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
NoteNativeContextGone();
|
||||
// P12: under a transport this object is the SERVER's backend and its destruction is the
|
||||
// end of a session (ServerLoop's apply thread, after the final drain). The in-process
|
||||
// display server runs the next session in this same process, so the twins this one built
|
||||
// - naming ids of the context just destroyed - must not answer for the next client's
|
||||
// handles (Managers.h, DropEveryTwinForEndedServerSession). Monolith keeps its twins.
|
||||
if (MG_Config::Transport != MG_Config::TransportMode::Monolith) {
|
||||
DropEveryTwinForEndedServerSession();
|
||||
// Review fix: and the swap interval it asked for (DirectGLES.h).
|
||||
ForgetRequestedSwapInterval();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1034,241 +1018,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
#endif
|
||||
}
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED && defined(__ANDROID__)
|
||||
namespace {
|
||||
// The host may still be starting when the client asks for its surface: it is a separate
|
||||
// app that has to come up and allocate its pool. Waiting is better than refusing a
|
||||
// surface a client is entitled to, and the wait is answered by name if it expires.
|
||||
constexpr Int kHostFrameWaitMs = 30000;
|
||||
}
|
||||
|
||||
Bool TakeHostFrameForExternalTexture(Uint width, Uint height) {
|
||||
// THIS ROLE'S OWN BACKEND, resolved exactly the way ActiveBackendFormatCaps (Utils.cpp,
|
||||
// C6 / ID-52) resolves it: under a live split session the SERVER's private backend owns the
|
||||
// context on the apply thread, and pActiveBackendObject is the CLIENT's mirror there.
|
||||
MG_Backend::BackendObject* backend = nullptr;
|
||||
if (MG_Config::Transport != MG_Config::TransportMode::Monolith) {
|
||||
backend = MG_Remote::Server::ServerLoopInstance().Backend();
|
||||
} else {
|
||||
backend = MG_Backend::pActiveBackendObject.get();
|
||||
}
|
||||
if (backend == nullptr) return false;
|
||||
return backend->InitHostFrameSurface(static_cast<EGLint>(width), static_cast<EGLint>(height));
|
||||
}
|
||||
|
||||
Bool BackendObject_DirectGLES::InitHostFrameSurface(EGLint width, EGLint height) {
|
||||
// The EGL context comes from the same place a pbuffer session's does. What changes is not
|
||||
// how this side draws but what it draws INTO: a frame the display host allocated, bound as
|
||||
// this context's framebuffer. The pbuffer stays as the draw target for the moment before
|
||||
// the first frame arrives, which is the only moment it is used.
|
||||
if (!DirectGLES::InitPbufferSurface(width, height)) {
|
||||
MGLOG_E("InitHostFrameSurface: the context the host frames are drawn in did not come up");
|
||||
return false;
|
||||
}
|
||||
if (!m_hostFrameBridgeOpen) {
|
||||
String why;
|
||||
if (!m_hostFrameBridge.Open(MG_Backend::kHostFrameSocket, kHostFrameWaitMs, why)) {
|
||||
MGLOG_E("InitHostFrameSurface: no display host: %s", why.c_str());
|
||||
return false;
|
||||
}
|
||||
m_hostFrameBridgeOpen = true;
|
||||
}
|
||||
return TakeHostFrame();
|
||||
}
|
||||
|
||||
Bool BackendObject_DirectGLES::TakeHostFrame() {
|
||||
String why;
|
||||
struct AHardwareBuffer* frame = nullptr;
|
||||
MG_Backend::HostFrameOffer offer{};
|
||||
if (!m_hostFrameBridge.Acquire(&frame, offer, why)) {
|
||||
MGLOG_E("TakeHostFrame: %s", why.c_str());
|
||||
return false;
|
||||
}
|
||||
HostFrameTarget target;
|
||||
if (!HostFrameTargetCreate(frame, target, why)) {
|
||||
MGLOG_E("TakeHostFrame: the host frame %ux%u did not become a draw target: %s", offer.Width,
|
||||
offer.Height, why.c_str());
|
||||
AHardwareBuffer_release(frame);
|
||||
return false;
|
||||
}
|
||||
DestroyHostFrame();
|
||||
m_hostFrameTarget = target;
|
||||
m_hostFrameBuffer = frame;
|
||||
m_hostFrameOffer = offer;
|
||||
// The canvas is made at the first frame's size and kept; a failure leaves the frame itself
|
||||
// as the draw target, which is how this path behaved before the canvas existed.
|
||||
if (!EnsureHostFrameCanvas(target.Width, target.Height))
|
||||
MGLOG_E_ONCE("TakeHostFrame: no canvas in front of the host frames; drawing into the frame itself");
|
||||
const HostFrameTarget& drawTarget = HostFrameDrawTarget();
|
||||
// BEFORE the bind: every default-framebuffer bind the engine makes from here on has to
|
||||
// resolve to this target, and that resolution is what this global is.
|
||||
g_hostFrameFramebufferId = drawTarget.Framebuffer;
|
||||
// Published together with the framebuffer, because they describe the same target: the STORAGE
|
||||
// an attachment is bound to when the client's texture has none of its own, and the SIZE that
|
||||
// decides whether binding it is right at all.
|
||||
g_hostFrameRenderbuffer = drawTarget.Renderbuffer;
|
||||
g_hostFrameWidth = drawTarget.Width;
|
||||
g_hostFrameHeight = drawTarget.Height;
|
||||
FramebufferImpl::InvalidateFramebufferBindingCache();
|
||||
HostFrameTargetBind(drawTarget);
|
||||
// AND ON TO THE CONTAINER, as the dma-buf descriptor behind it. The Wayland compositor
|
||||
// over there renders into THESE frames - it runs this project's own GBM, whose
|
||||
// gbm_bo_create answers with the phone's frame instead of an allocation of its own - so
|
||||
// every frame taken here is useless to it until its descriptor has crossed. Open() binds
|
||||
// the listening socket a container dials, and the IsUp() test keeps the ordinary frame
|
||||
// down to an integer compare: the socket outlives every container and every connection,
|
||||
// while OfferFrame accepts whoever dialled since the last frame and opens the socket
|
||||
// itself when the first frame arrives before any container has.
|
||||
//
|
||||
// NEITHER ANSWER IS EXAMINED, and that is the channel's contract rather than an
|
||||
// oversight: no container running, a container that has died, or one that has taken the
|
||||
// descriptor and stopped reading must all leave this frame drawn and presented exactly as
|
||||
// it would have been without a channel - the descriptor is a copy of the pixels' route,
|
||||
// not a step in producing them.
|
||||
if (!m_gbmFrameChannel.IsUp()) m_gbmFrameChannel.Open();
|
||||
(void)m_gbmFrameChannel.OfferFrame(frame, offer);
|
||||
MGLOG_I("host frame %u is the draw target: %ux%u", offer.Index, target.Width, target.Height);
|
||||
return true;
|
||||
}
|
||||
|
||||
void BackendObject_DirectGLES::DestroyHostFrame() {
|
||||
// The canvas outlives the frame, so with one the globals keep naming it: the attachments
|
||||
// made over it stay valid between this frame being handed back and the next one arriving.
|
||||
g_hostFrameFramebufferId = m_hostFrameCanvas.Framebuffer;
|
||||
g_hostFrameRenderbuffer = m_hostFrameCanvas.Renderbuffer;
|
||||
g_hostFrameWidth = m_hostFrameCanvas.Width;
|
||||
g_hostFrameHeight = m_hostFrameCanvas.Height;
|
||||
HostFrameTargetDestroy(m_hostFrameTarget);
|
||||
if (m_hostFrameBuffer != nullptr) {
|
||||
AHardwareBuffer_release(m_hostFrameBuffer);
|
||||
m_hostFrameBuffer = nullptr;
|
||||
}
|
||||
// AND NOTHING IS SAID TO THE CHANNEL HERE, which is the fix rather than an omission. This
|
||||
// runs once per presented frame: it used to Close() the channel (unlinking the container's
|
||||
// socket node and dropping its connection sixty times a second - measured: connect()
|
||||
// answered EAGAIN(11) on every attempt) and it used to tell the channel to forget the frame,
|
||||
// which left the ONE window a compositor's first allocations arrive in - between this frame
|
||||
// being presented and the host handing the next one over, i.e. inside Complete() above -
|
||||
// with nothing to answer a dialer with. A compositor allocates its swapchain ONCE and keeps
|
||||
// those buffers for the life of the process, so a dialer that finds nothing here renders
|
||||
// its whole life into buffers nobody displays. The frame the channel remembers is the last
|
||||
// one the host handed over: the next offer replaces it and Close() releases it.
|
||||
}
|
||||
|
||||
Bool BackendObject_DirectGLES::PresentHostFrame() {
|
||||
// When this returns, the pixels are complete: glFinish is the fence the host is told
|
||||
// about, and the host's own readback - which Complete reads - is what proves the drawing
|
||||
// landed where the screen will look.
|
||||
BlitHostFrameCanvas();
|
||||
if (g_GLESFuncs.glFinish != nullptr) g_GLESFuncs.glFinish();
|
||||
// WHAT THE CONTAINER SAID WHILE THIS FRAME WAS BEING DRAWN. This is the one place the
|
||||
// server's apply loop passes through the host channel - the swap it runs lands here for a
|
||||
// host-framed surface - and a release is the container's compositor saying it is done
|
||||
// reading a frame this side handed over. Poll() is a bare recvmsg on a non-blocking
|
||||
// socket: with no container connected it returns on its first test, and a container that
|
||||
// is between frames answers EAGAIN, so a pass costs nothing when there is nothing to
|
||||
// read. Nothing here is waited for and nothing is required to arrive; the count of
|
||||
// frames offered and not released is a number the channel keeps for the log, never a
|
||||
// frame the render path waits on.
|
||||
m_gbmFrameChannel.Poll();
|
||||
String why;
|
||||
if (!m_hostFrameBridge.Complete(m_hostFrameOffer, /*imported=*/true, /*drawn=*/true, /*fenceOk=*/true, why)) {
|
||||
MGLOG_E("PresentHostFrame: %s", why.c_str());
|
||||
return false;
|
||||
}
|
||||
// The answer has been read, so the host has already put this frame on the glass: it is
|
||||
// this side's to drop, and the next one becomes the drawing target.
|
||||
DestroyHostFrame();
|
||||
return TakeHostFrame();
|
||||
}
|
||||
|
||||
Bool BackendObject_DirectGLES::EnsureHostFrameCanvas(Uint width, Uint height) {
|
||||
if (m_hostFrameCanvas.Framebuffer != 0) return true;
|
||||
if (width == 0 || height == 0 || !g_GLESFuncs.glRenderbufferStorage || !g_GLESFuncs.glBlitFramebuffer ||
|
||||
!g_GLESFuncs.glGenRenderbuffers || !g_GLESFuncs.glGenFramebuffers || !g_GLESFuncs.glCheckFramebufferStatus)
|
||||
return false;
|
||||
// RAW binds, as HostFrameTargetCreate makes them: the caller invalidates the engine's
|
||||
// framebuffer shadow and binds through it right after.
|
||||
GLuint renderbuffer = 0;
|
||||
g_GLESFuncs.glGenRenderbuffers(1, &renderbuffer);
|
||||
g_GLESFuncs.glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
|
||||
// The frames are R8G8B8A8_UNORM (the display host allocates them so), and so is this.
|
||||
g_GLESFuncs.glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, static_cast<GLsizei>(width),
|
||||
static_cast<GLsizei>(height));
|
||||
GLuint framebuffer = 0;
|
||||
g_GLESFuncs.glGenFramebuffers(1, &framebuffer);
|
||||
g_GLESFuncs.glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
||||
g_GLESFuncs.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer);
|
||||
const GLenum status = g_GLESFuncs.glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE) {
|
||||
MGLOG_E("host frame canvas %ux%u: framebuffer status 0x%04x", width, height, status);
|
||||
g_GLESFuncs.glDeleteFramebuffers(1, &framebuffer);
|
||||
g_GLESFuncs.glDeleteRenderbuffers(1, &renderbuffer);
|
||||
return false;
|
||||
}
|
||||
m_hostFrameCanvas.Renderbuffer = renderbuffer;
|
||||
m_hostFrameCanvas.Framebuffer = framebuffer;
|
||||
m_hostFrameCanvas.Width = width;
|
||||
m_hostFrameCanvas.Height = height;
|
||||
MGLOG_I("host frame canvas: %ux%u as framebuffer %u (renderbuffer %u), copied into each frame at present",
|
||||
width, height, framebuffer, renderbuffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
void BackendObject_DirectGLES::BlitHostFrameCanvas() {
|
||||
if (m_hostFrameCanvas.Framebuffer == 0 || m_hostFrameTarget.Framebuffer == 0) return;
|
||||
// Whatever the compositor had bound is put back as it was, raw for raw, so the engine's
|
||||
// shadow (which never saw this) is still right afterwards. The scissor test and
|
||||
// rasterizer discard both apply to a blit, so they are lifted for it.
|
||||
GLint readBinding = 0;
|
||||
GLint drawBinding = 0;
|
||||
g_GLESFuncs.glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &readBinding);
|
||||
g_GLESFuncs.glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &drawBinding);
|
||||
const GLboolean scissor = g_GLESFuncs.glIsEnabled(GL_SCISSOR_TEST);
|
||||
const GLboolean discard = g_GLESFuncs.glIsEnabled(GL_RASTERIZER_DISCARD);
|
||||
if (scissor) g_GLESFuncs.glDisable(GL_SCISSOR_TEST);
|
||||
if (discard) g_GLESFuncs.glDisable(GL_RASTERIZER_DISCARD);
|
||||
g_GLESFuncs.glBindFramebuffer(GL_READ_FRAMEBUFFER, m_hostFrameCanvas.Framebuffer);
|
||||
g_GLESFuncs.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_hostFrameTarget.Framebuffer);
|
||||
const Bool sameSize = m_hostFrameCanvas.Width == m_hostFrameTarget.Width &&
|
||||
m_hostFrameCanvas.Height == m_hostFrameTarget.Height;
|
||||
g_GLESFuncs.glBlitFramebuffer(0, 0, static_cast<GLint>(m_hostFrameCanvas.Width),
|
||||
static_cast<GLint>(m_hostFrameCanvas.Height), 0, 0,
|
||||
static_cast<GLint>(m_hostFrameTarget.Width),
|
||||
static_cast<GLint>(m_hostFrameTarget.Height), GL_COLOR_BUFFER_BIT,
|
||||
sameSize ? GL_NEAREST : GL_LINEAR);
|
||||
g_GLESFuncs.glBindFramebuffer(GL_READ_FRAMEBUFFER, static_cast<GLuint>(readBinding));
|
||||
g_GLESFuncs.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, static_cast<GLuint>(drawBinding));
|
||||
if (scissor) g_GLESFuncs.glEnable(GL_SCISSOR_TEST);
|
||||
if (discard) g_GLESFuncs.glEnable(GL_RASTERIZER_DISCARD);
|
||||
}
|
||||
|
||||
#else // !(MOBILEGL_BUILD_DISAGGREGATED && __ANDROID__)
|
||||
|
||||
// The other arm's half: on a build with no host frames there is no frame to take, and the
|
||||
// attach site's ordinary path (a storage-less external texture, exactly as before) is the honest
|
||||
// behaviour there rather than a link error.
|
||||
Bool TakeHostFrameForExternalTexture(Uint, Uint) { return false; }
|
||||
|
||||
Bool BackendObject_DirectGLES::InitHostFrameSurface(EGLint width, EGLint height) {
|
||||
(void)width;
|
||||
(void)height;
|
||||
MGLOG_E("InitHostFrameSurface: host frames are a disaggregated Android path");
|
||||
return false;
|
||||
}
|
||||
|
||||
Bool BackendObject_DirectGLES::TakeHostFrame() { return false; }
|
||||
void BackendObject_DirectGLES::DestroyHostFrame() {}
|
||||
Bool BackendObject_DirectGLES::EnsureHostFrameCanvas(Uint, Uint) { return false; }
|
||||
void BackendObject_DirectGLES::BlitHostFrameCanvas() {}
|
||||
|
||||
Bool BackendObject_DirectGLES::PresentHostFrame() {
|
||||
MGLOG_E("PresentHostFrame: host frames are a disaggregated Android path");
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Bool BackendObject_DirectGLES::InitPbufferSurface(EGLint width, EGLint height) {
|
||||
return DirectGLES::InitPbufferSurface(width, height);
|
||||
}
|
||||
@@ -1293,42 +1042,13 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
MGLOG_E("MakeEGLCurrent failed: EGL display mismatch or not initialized");
|
||||
return false;
|
||||
}
|
||||
// EGL_KHR_surfaceless_context, WHICH IS THE SHAPE A COMPOSITOR ASKS FOR. Its context has no
|
||||
// draw surface of its own - every frame goes into a framebuffer it binds itself, and under
|
||||
// this project that framebuffer is one of the display host's frames - so the surface checks
|
||||
// below describe a surface that legitimately does not exist. What the server still needs is
|
||||
// its own GL context current on this thread for the records that follow, and that is what
|
||||
// the native bind underneath them does.
|
||||
const Bool surfaceless = draw == EGL_NO_SURFACE && read == EGL_NO_SURFACE && ctx != EGL_NO_CONTEXT;
|
||||
if (surfaceless && !m_eglSurfaceInitialized) {
|
||||
// A DRAWABLE OF THIS SIDE'S OWN, WHICH IS WHAT A SURFACELESS CLIENT LEAVES TO US. The
|
||||
// backend's native context has to be current on a surface of some kind before a single
|
||||
// record of the client's can run - that is what the Init*Surface calls establish - and a
|
||||
// client that makes its context current with no surface at all supplies none of its own.
|
||||
// A pbuffer is the one that costs nothing to keep: it is never scanned out and never
|
||||
// read, because every frame the client draws goes into a framebuffer it binds itself.
|
||||
// The client is NOT told it has a surface - m_eglSurface stays EGL_NO_SURFACE - so a
|
||||
// swap on one is still the refusal it was.
|
||||
if (!InitPbufferSurface(1, 1)) {
|
||||
MGLOG_E("MakeEGLCurrent failed: the backend's own drawable for a surfaceless context could not "
|
||||
"be created");
|
||||
return false;
|
||||
}
|
||||
m_eglSurface = EGL_NO_SURFACE;
|
||||
m_eglSurfaceInitialized = true;
|
||||
m_eglSurfaceKind = SurfaceKind::Pbuffer;
|
||||
m_eglCurrentThreads.clear();
|
||||
m_backendCapabilitiesInitialized = false;
|
||||
if (!m_eglSurfaceInitialized) {
|
||||
MGLOG_E("MakeEGLCurrent failed: EGL surface is not initialized");
|
||||
return false;
|
||||
}
|
||||
if (!surfaceless) {
|
||||
if (!m_eglSurfaceInitialized) {
|
||||
MGLOG_E("MakeEGLCurrent failed: EGL surface is not initialized");
|
||||
return false;
|
||||
}
|
||||
if (draw == EGL_NO_SURFACE || read == EGL_NO_SURFACE || ctx == EGL_NO_CONTEXT) {
|
||||
MGLOG_E("MakeEGLCurrent failed: draw/read/context is invalid");
|
||||
return false;
|
||||
}
|
||||
if (draw == EGL_NO_SURFACE || read == EGL_NO_SURFACE || ctx == EGL_NO_CONTEXT) {
|
||||
MGLOG_E("MakeEGLCurrent failed: draw/read/context is invalid");
|
||||
return false;
|
||||
}
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
@@ -1356,9 +1076,9 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// function table instead of 1), or make NativeBindCanBeSkippedFor answer true for any tuple
|
||||
// (the ID-67 control's different tuple stays at 1 native bind where 2 are required).
|
||||
const Bool nativelyCurrentAlready = MG_Config::Transport != MG_Config::TransportMode::Monolith &&
|
||||
m_eglSurfaceInitialized && m_eglSurface == draw &&
|
||||
DirectGLES::IsBackendContextCurrentOnThisThread() &&
|
||||
(surfaceless || (m_eglSurfaceInitialized && m_eglSurface == draw &&
|
||||
NativeBindCanBeSkippedFor(dpy, draw, read, ctx)));
|
||||
NativeBindCanBeSkippedFor(dpy, draw, read, ctx);
|
||||
if (!nativelyCurrentAlready && !DirectGLES::MakeCurrent()) {
|
||||
NoteNativeContextGone();
|
||||
return false;
|
||||
@@ -1377,15 +1097,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
// A HOST-FRAMED SURFACE HAS TO BE PUT BACK AFTER EVERY MAKE-CURRENT. The native call
|
||||
// binds the surface's own default framebuffer - the pbuffer this path makes its context
|
||||
// with - and that is not where these pixels go. Both the driver and the engine's binding
|
||||
// shadow have to be told again, or the next default-framebuffer bind is deduped away and
|
||||
// every draw lands in a pbuffer nobody sees.
|
||||
if (m_eglSurfaceKind == SurfaceKind::HostFrame && m_hostFrameTarget.Framebuffer != 0) {
|
||||
FramebufferImpl::InvalidateFramebufferBindingCache();
|
||||
HostFrameTargetBind(HostFrameDrawTarget());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1542,40 +1253,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// Advertised with GL_NUM_PROGRAM_BINARY_FORMATS = 0, which the
|
||||
// extension explicitly permits. It is also the only thing that
|
||||
// exposes glProgramParameteri before GL 4.1.
|
||||
E_GL_ARB_get_program_binary,
|
||||
// kwin_wayland 6.7.3 will not use a context it cannot drive, and it asks for these
|
||||
// three names first: EglContext::checkSupported() (src/opengl/eglcontext.cpp) takes the
|
||||
// DESKTOP-OpenGL branch for every context whose GL_VERSION is not an "OpenGL ES"
|
||||
// string, and that branch requires GL_ARB_shader_objects, GL_ARB_fragment_shader and
|
||||
// GL_ARB_vertex_shader. GL_VERSION here is "4.6.0 MobileGL ...", so with the names
|
||||
// missing checkSupported() answered false, EglContext::create() returned nullptr,
|
||||
// EglBackend::createContext() returned false, and kwin printed "Could not initialize
|
||||
// rendering context" and quit before drawing a frame.
|
||||
//
|
||||
// The three are true statements about this backend now rather than a test unlock: every
|
||||
// procedure they define is implemented in MG_Impl/GLImpl/Exporting/Definitions.cpp over
|
||||
// the same shader and program objects the core entry points drive - the 39 of
|
||||
// ARB_shader_objects, ARB_vertex_shader's three attrib-location entry points, and none
|
||||
// at all for ARB_fragment_shader ("New Procedures and Functions: None" - it is the
|
||||
// capability half, and the reason kwin's conjunction names it).
|
||||
E_GL_ARB_shader_objects, E_GL_ARB_vertex_shader, E_GL_ARB_fragment_shader,
|
||||
// NPOT textures: core since GL 2.0, and every host this backend can run on provides
|
||||
// them. Full non-power-of-two support - mipmapping and every wrap mode, not ES 2.0's
|
||||
// CLAMP_TO_EDGE-only exception - is required from ES 3.0 on, and the entries this list
|
||||
// already advertises without any gate (compute shaders, shader storage buffers,
|
||||
// indirect draws) need an ES 3.1 host. Nothing in the texture path rejects or pads a
|
||||
// non-power-of-two size - storage and sampling are forwarded to that host - so the
|
||||
// string describes what an application actually gets.
|
||||
E_GL_ARB_texture_non_power_of_two,
|
||||
// GL_OES_EGL_image: the entry points are real (MG_Impl/GLImpl/Exporting/Definitions.cpp)
|
||||
// and this name is what makes them reachable - libepoxy in kwin resolves
|
||||
// glEGLImageTargetTexture2DOES BY NAME and refuses the import path without it, printing
|
||||
// "No provider of glEGLImageTargetTexture2DOES found. Requires one of: GL_OES_EGL_image".
|
||||
// That import path is how the compositor's scene reaches the display daemon's dma-bufs.
|
||||
// The render-server half of the import (fd over the GBM socket, then the server-side
|
||||
// EGLImage) is the next change; until it lands an imported texture has no storage behind
|
||||
// it, which is logged once at the entry point rather than left to look like a black frame.
|
||||
E_GL_OES_EGL_image};
|
||||
E_GL_ARB_get_program_binary};
|
||||
// Minecraft 26.3 checks this prerequisite before it even considers
|
||||
// GL_ARB_multi_draw_indirect. ES 3.1 supplies both single-draw entry points; the loader
|
||||
// folds the version and pointer checks into SupportsDrawIndirect.
|
||||
|
||||
@@ -8,9 +8,6 @@
|
||||
|
||||
#pragma once
|
||||
#include <Includes.h>
|
||||
#include "HostFrameTarget.h"
|
||||
#include "MG_Backend/HostFrameBridge.h"
|
||||
#include "MG_Backend/GbmFrameChannel.h"
|
||||
#include "../BackendObject.h"
|
||||
#include <MG_Util/BackendLoaders/OpenGL/Loader.h>
|
||||
|
||||
@@ -59,46 +56,8 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
private:
|
||||
void UpdateDynamicBackendParameters();
|
||||
Bool InitPbufferSurface(EGLint width, EGLint height) override;
|
||||
// A host-framed surface draws into a frame the display host owns; presenting one
|
||||
// tells the host the frame is drawn, because the host is what puts it on the glass.
|
||||
// NOT CreateEGLHostFrameSurface: the base class registers the surface and activates it,
|
||||
// and activation is what reaches InitHostFrameSurface below. There is nothing about the
|
||||
// EGL side of a host-framed surface this backend needs to do its own way.
|
||||
Bool InitHostFrameSurface(EGLint width, EGLint height) override;
|
||||
Bool PresentHostFrame() override;
|
||||
// Takes the next frame from the host and makes it this context's framebuffer.
|
||||
Bool TakeHostFrame();
|
||||
void DestroyHostFrame();
|
||||
// The canvas the compositor draws into, made once at the first frame's size.
|
||||
Bool EnsureHostFrameCanvas(Uint width, Uint height);
|
||||
// Copies the canvas into the frame about to be presented.
|
||||
void BlitHostFrameCanvas();
|
||||
// What draws resolve to: the canvas when there is one, the frame itself otherwise.
|
||||
const HostFrameTarget& HostFrameDrawTarget() const {
|
||||
return m_hostFrameCanvas.Framebuffer != 0 ? m_hostFrameCanvas : m_hostFrameTarget;
|
||||
}
|
||||
void OnEGLSurfaceReleased(EGLSurface surface) override;
|
||||
|
||||
// MOBILEGL_IPC_SURFACE=host: the frames the display host owns, one at a time, which
|
||||
// is what the host offers - it hands one over and waits for the answer before it
|
||||
// presents it and offers the next.
|
||||
MG_Backend::HostFrameBridge m_hostFrameBridge;
|
||||
// The frames the bridge just took, on to the container: the Wayland compositor over there
|
||||
// renders into this same memory, and the only route to it that end has is the dma-buf
|
||||
// descriptor this channel offers per frame and reads a release back from.
|
||||
MG_Backend::GbmFrameChannel m_gbmFrameChannel;
|
||||
HostFrameTarget m_hostFrameTarget;
|
||||
// A STABLE TARGET IN FRONT OF THE FRAMES. Every present hands the frame back and takes
|
||||
// a different one, and its renderbuffer is deleted with it - but a compositor attaches
|
||||
// its framebuffers ONCE (kwin: one per daemon buffer, for the life of the process), so
|
||||
// attachments bound to a frame's own renderbuffer named a deleted object from the second
|
||||
// frame on. The attachments name this instead, and each present copies it into the
|
||||
// frame. No EGLImage behind it (Image stays null).
|
||||
HostFrameTarget m_hostFrameCanvas;
|
||||
struct AHardwareBuffer* m_hostFrameBuffer = nullptr;
|
||||
MG_Backend::HostFrameOffer m_hostFrameOffer{};
|
||||
Bool m_hostFrameBridgeOpen = false;
|
||||
|
||||
Bool m_initialized = false;
|
||||
MG_External::EGLFunctionsTable m_EGLFunctions;
|
||||
MG_External::GLESFunctionsTable m_GLESFunctions;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -23,21 +23,15 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// Content uploads use scratch bindings, so draws and dispatches call this after
|
||||
// texture synchronization.
|
||||
void BindCurrentTextures();
|
||||
// Driver-side color/depth level readback. Returns tightly packed, owned
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
Bool ReadTextureImageWire(const MG_Pipe::MGPReadbackInfo& info, Vector<Uint8>& bytes);
|
||||
// Native/server-only color level readback. Returns tightly packed, owned
|
||||
// bytes in the requested pair; never consults a frontend texture or PACK/PBO.
|
||||
// The caller supplies identity and extent, and whether the SOURCE allocation
|
||||
// already uses an image carrier.
|
||||
// The caller resolves identity/extent from its resource record and supplies
|
||||
// whether the SOURCE allocation already uses an image carrier.
|
||||
Bool ReadTextureLevelTight(GLuint texture, TextureTarget target, TextureUploadTarget uploadTarget,
|
||||
TextureInternalFormat logicalFormat, GLint level, const IntVec3& logicalExtent,
|
||||
Bool sourceUsesImageCarrier, GLenum format, GLenum type, Vector<Uint8>& bytes);
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
Bool ReadTextureImageWire(const MG_Pipe::MGPReadbackInfo& info, Vector<Uint8>& bytes);
|
||||
// Whether the NATIVE texture currently holds `level` of `uploadTarget` at `logicalExtent`
|
||||
// (glGetTexLevelParameteriv). False for a level the driver never allocated - one defined after
|
||||
// the texture's last sync - so a re-mint does not read what is not there. A query the driver
|
||||
// refuses answers true, keeping the caller on its readback path.
|
||||
Bool NativeTextureLevelHasExtent(GLuint texture, TextureTarget target, TextureUploadTarget uploadTarget,
|
||||
GLint level, const IntVec3& logicalExtent);
|
||||
#endif
|
||||
void ClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil);
|
||||
void ClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value);
|
||||
@@ -194,13 +188,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// Applies (or defers until the window surface exists) the app-requested
|
||||
// eglSwapInterval on the native EGL surface.
|
||||
void SetSwapInterval(Int interval);
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P12 review fix: the swap interval an ended server session asked for is not the next one's.
|
||||
// The request outlives the context on purpose (a surface re-created mid-session re-applies it),
|
||||
// so the in-process display server's session end forgets it: the next session starts at the
|
||||
// driver's default until it asks (BackendObject_DirectGLES's destructor under a transport).
|
||||
void ForgetRequestedSwapInterval();
|
||||
#endif
|
||||
void SetEGLFuncsTable(const MG_External::EGLFunctionsTable& eglFuncs);
|
||||
void SetGLESFuncsTable(const MG_External::GLESFunctionsTable& glesFuncs);
|
||||
void SetGLESCapabilities(const MG_External::GLESCapabilities& capabilities);
|
||||
@@ -249,26 +236,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
void InvalidateSyncedRenderState();
|
||||
} // namespace RenderStateImpl
|
||||
|
||||
// MOBILEGL_IPC_SURFACE=host: what the client's DEFAULT framebuffer means while a host-framed
|
||||
// surface is current. Zero everywhere else, because the driver's own 0 IS the EGL surface
|
||||
// then - but on a host-framed surface the pixels belong to a frame the display host owns,
|
||||
// and drawing into the driver's 0 would draw into a pbuffer nobody ever sees.
|
||||
extern Uint g_hostFrameFramebufferId;
|
||||
// WHAT THE HOST FRAME'S STORAGE IS, for the one caller that has to bind it in place of a
|
||||
// storage-less attachment: an imported dma-buf is the display host's frame (same memory, same
|
||||
// size), and the frame's storage is a RENDERBUFFER (HostFrameTarget.cpp binds it with
|
||||
// glFramebufferRenderbuffer). A texture argument cannot name it, which is why these exist and
|
||||
// why g_hostFrameFramebufferId alone was not enough. Zero whenever no frame is held.
|
||||
extern Uint g_hostFrameRenderbuffer;
|
||||
extern Uint g_hostFrameWidth;
|
||||
extern Uint g_hostFrameHeight;
|
||||
// TAKE THE FRAME WHEN NOTHING ELSE WILL. On the anland route the container's compositor never
|
||||
// creates a window surface, so ActivateEGLSurface never runs and InitHostFrameSurface is never
|
||||
// reached: the FIRST proof that the display host's frame is wanted is an ATTACHMENT of an
|
||||
// imported external texture (Managers.cpp's 0x8D65 arm), and that is where the frame has to be
|
||||
// taken. The host's own offer carries the width/height, so the numbers passed here are only
|
||||
// what the bridge logs. Answers false (and changes nothing) whenever no backend is up.
|
||||
Bool TakeHostFrameForExternalTexture(Uint width, Uint height);
|
||||
extern MG_External::EGLFunctionsTable g_EGLFuncs;
|
||||
extern MG_External::GLESFunctionsTable g_GLESFuncs;
|
||||
extern MG_External::GLESCapabilities g_GLESCapabilities;
|
||||
|
||||
@@ -1,208 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Backend/DirectGLES/HostFrameTarget.cpp
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#include "HostFrameTarget.h"
|
||||
#include "DirectGLES.h"
|
||||
#include "Managers.h"
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED && defined(__ANDROID__)
|
||||
|
||||
#include <android/hardware_buffer.h>
|
||||
#include <cstring>
|
||||
#include <format>
|
||||
|
||||
namespace MobileGL::MG_Backend::DirectGLES {
|
||||
namespace {
|
||||
// The four entry points this is spelled in are optional everywhere: the loader's own
|
||||
// tables do not carry them (a missing EGL function there is MGLOG_F), so the extension
|
||||
// strings decide first and the pointers are taken only once they have.
|
||||
using GetNativeClientBufferFn = EGLClientBuffer (*)(const struct AHardwareBuffer*);
|
||||
using CreateImageFn = EGLImageKHR (*)(EGLDisplay, EGLContext, EGLenum, EGLClientBuffer, const EGLint*);
|
||||
using DestroyImageFn = EGLBoolean (*)(EGLDisplay, EGLImageKHR);
|
||||
using ImageTargetRenderbufferFn = void (*)(GLenum, GLeglImageOES);
|
||||
|
||||
Bool HasExtensionWord(const char* list, const char* word) {
|
||||
if (list == nullptr) return false;
|
||||
const SizeT n = std::strlen(word);
|
||||
for (const char* at = std::strstr(list, word); at != nullptr; at = std::strstr(at + 1, word)) {
|
||||
const Bool startOk = at == list || at[-1] == ' ';
|
||||
const Bool endOk = !at[n] || at[n] == ' ';
|
||||
if (startOk && endOk) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
struct EntryPoints {
|
||||
GetNativeClientBufferFn GetNativeClientBuffer = nullptr;
|
||||
CreateImageFn CreateImage = nullptr;
|
||||
DestroyImageFn DestroyImage = nullptr;
|
||||
ImageTargetRenderbufferFn TargetRenderbuffer = nullptr;
|
||||
};
|
||||
|
||||
// Resolved once per process and cached together with the refusal: a driver that lacks one
|
||||
// of these does not grow it later, and the answer names what is missing.
|
||||
const EntryPoints& Resolved(String& why) {
|
||||
static EntryPoints points;
|
||||
static Bool resolved = false;
|
||||
static String refusal;
|
||||
if (!resolved) {
|
||||
resolved = true;
|
||||
if (!g_EGLFuncs.eglGetProcAddress || !g_EGLFuncs.eglQueryString || !g_EGLFuncs.eglGetCurrentDisplay ||
|
||||
!g_GLESFuncs.glGetString) {
|
||||
refusal = "the loader has no eglGetProcAddress/eglQueryString/eglGetCurrentDisplay/glGetString";
|
||||
} else {
|
||||
const char* egl = g_EGLFuncs.eglQueryString(g_EGLFuncs.eglGetCurrentDisplay(), EGL_EXTENSIONS);
|
||||
const char* gl = reinterpret_cast<const char*>(g_GLESFuncs.glGetString(GL_EXTENSIONS));
|
||||
if (!HasExtensionWord(egl, "EGL_ANDROID_get_native_client_buffer")) {
|
||||
refusal = "EGL_ANDROID_get_native_client_buffer is not advertised";
|
||||
} else if (!HasExtensionWord(egl, "EGL_KHR_image_base")) {
|
||||
refusal = "EGL_KHR_image_base is not advertised";
|
||||
} else if (!HasExtensionWord(gl, "GL_OES_EGL_image")) {
|
||||
refusal = "GL_OES_EGL_image is not advertised";
|
||||
} else {
|
||||
points.GetNativeClientBuffer = reinterpret_cast<GetNativeClientBufferFn>(
|
||||
g_EGLFuncs.eglGetProcAddress("eglGetNativeClientBufferANDROID"));
|
||||
points.CreateImage =
|
||||
reinterpret_cast<CreateImageFn>(g_EGLFuncs.eglGetProcAddress("eglCreateImageKHR"));
|
||||
points.DestroyImage =
|
||||
reinterpret_cast<DestroyImageFn>(g_EGLFuncs.eglGetProcAddress("eglDestroyImageKHR"));
|
||||
points.TargetRenderbuffer = reinterpret_cast<ImageTargetRenderbufferFn>(
|
||||
g_EGLFuncs.eglGetProcAddress("glEGLImageTargetRenderbufferStorageOES"));
|
||||
if (points.GetNativeClientBuffer == nullptr || points.CreateImage == nullptr ||
|
||||
points.DestroyImage == nullptr || points.TargetRenderbuffer == nullptr) {
|
||||
refusal = "eglGetProcAddress gave no eglGetNativeClientBufferANDROID / eglCreateImageKHR / "
|
||||
"eglDestroyImageKHR / glEGLImageTargetRenderbufferStorageOES";
|
||||
points = EntryPoints{};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
why = refusal;
|
||||
return points;
|
||||
}
|
||||
|
||||
void DrainGLErrors() {
|
||||
if (!g_GLESFuncs.glGetError) return;
|
||||
for (Uint guard = 0; guard < 16 && g_GLESFuncs.glGetError() != GL_NO_ERROR; ++guard) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Bool HostFrameTargetSupported(String& why) {
|
||||
const EntryPoints& points = Resolved(why);
|
||||
return points.GetNativeClientBuffer != nullptr;
|
||||
}
|
||||
|
||||
Bool HostFrameTargetCreate(const struct AHardwareBuffer* buffer, HostFrameTarget& target, String& why) {
|
||||
target = HostFrameTarget{};
|
||||
if (buffer == nullptr) {
|
||||
why = "no buffer";
|
||||
return false;
|
||||
}
|
||||
const EntryPoints& points = Resolved(why);
|
||||
if (points.GetNativeClientBuffer == nullptr) return false;
|
||||
|
||||
if (!g_GLESFuncs.glGenRenderbuffers || !g_GLESFuncs.glBindRenderbuffer || !g_GLESFuncs.glGenFramebuffers ||
|
||||
!g_GLESFuncs.glBindFramebuffer || !g_GLESFuncs.glFramebufferRenderbuffer ||
|
||||
!g_GLESFuncs.glCheckFramebufferStatus) {
|
||||
why = "the loader has no glGenRenderbuffers/glBindRenderbuffer/glGenFramebuffers/glBindFramebuffer/"
|
||||
"glFramebufferRenderbuffer/glCheckFramebufferStatus";
|
||||
return false;
|
||||
}
|
||||
|
||||
AHardwareBuffer_Desc desc{};
|
||||
AHardwareBuffer_describe(buffer, &desc);
|
||||
|
||||
DrainGLErrors();
|
||||
const EGLClientBuffer clientBuffer = points.GetNativeClientBuffer(buffer);
|
||||
if (clientBuffer == nullptr) {
|
||||
why = "eglGetNativeClientBufferANDROID returned null";
|
||||
return false;
|
||||
}
|
||||
const EGLint imageAttribs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
|
||||
const EGLImageKHR image =
|
||||
points.CreateImage(g_EGLFuncs.eglGetCurrentDisplay(), EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID,
|
||||
clientBuffer, imageAttribs);
|
||||
if (image == EGL_NO_IMAGE_KHR) {
|
||||
why = "eglCreateImageKHR(EGL_NATIVE_BUFFER_ANDROID) refused the host frame";
|
||||
return false;
|
||||
}
|
||||
|
||||
GLuint renderbuffer = 0;
|
||||
g_GLESFuncs.glGenRenderbuffers(1, &renderbuffer);
|
||||
g_GLESFuncs.glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
|
||||
points.TargetRenderbuffer(GL_RENDERBUFFER, reinterpret_cast<GLeglImageOES>(image));
|
||||
const GLenum renderbufferError = g_GLESFuncs.glGetError ? g_GLESFuncs.glGetError() : GL_NO_ERROR;
|
||||
if (renderbufferError != GL_NO_ERROR) {
|
||||
why = std::format("glEGLImageTargetRenderbufferStorageOES -> 0x{:04x}", renderbufferError);
|
||||
g_GLESFuncs.glDeleteRenderbuffers(1, &renderbuffer);
|
||||
points.DestroyImage(g_EGLFuncs.eglGetCurrentDisplay(), image);
|
||||
return false;
|
||||
}
|
||||
|
||||
GLuint framebuffer = 0;
|
||||
g_GLESFuncs.glGenFramebuffers(1, &framebuffer);
|
||||
g_GLESFuncs.glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
||||
g_GLESFuncs.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer);
|
||||
const GLenum status = g_GLESFuncs.glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE) {
|
||||
why = std::format("the host frame as a color attachment -> framebuffer status 0x{:04x}", status);
|
||||
g_GLESFuncs.glDeleteFramebuffers(1, &framebuffer);
|
||||
g_GLESFuncs.glDeleteRenderbuffers(1, &renderbuffer);
|
||||
points.DestroyImage(g_EGLFuncs.eglGetCurrentDisplay(), image);
|
||||
return false;
|
||||
}
|
||||
|
||||
target.Image = image;
|
||||
target.Renderbuffer = renderbuffer;
|
||||
target.Framebuffer = framebuffer;
|
||||
target.Width = desc.width;
|
||||
target.Height = desc.height;
|
||||
MGLOG_I("host frame target: %ux%d as framebuffer %u (stride %u, format 0x%x)", desc.width, desc.height,
|
||||
framebuffer, desc.stride, desc.format);
|
||||
return true;
|
||||
}
|
||||
|
||||
void HostFrameTargetBind(const HostFrameTarget& target) {
|
||||
if (target.Framebuffer == 0) return;
|
||||
// THROUGH THE ENGINE'S SHADOW, never raw: a raw bind would leave the shadow claiming
|
||||
// the previous framebuffer and false-skip the next re-bind (FramebufferImpl, Managers.h).
|
||||
FramebufferImpl::BindFramebufferId(GL_FRAMEBUFFER, target.Framebuffer);
|
||||
}
|
||||
|
||||
void HostFrameTargetDestroy(HostFrameTarget& target) {
|
||||
if (target.Framebuffer != 0 && g_GLESFuncs.glDeleteFramebuffers)
|
||||
g_GLESFuncs.glDeleteFramebuffers(1, &target.Framebuffer);
|
||||
if (target.Renderbuffer != 0 && g_GLESFuncs.glDeleteRenderbuffers)
|
||||
g_GLESFuncs.glDeleteRenderbuffers(1, &target.Renderbuffer);
|
||||
if (target.Image != nullptr) {
|
||||
String why;
|
||||
const EntryPoints& points = Resolved(why);
|
||||
if (points.DestroyImage != nullptr && g_EGLFuncs.eglGetCurrentDisplay)
|
||||
points.DestroyImage(g_EGLFuncs.eglGetCurrentDisplay(), static_cast<EGLImageKHR>(target.Image));
|
||||
}
|
||||
target = HostFrameTarget{};
|
||||
}
|
||||
}
|
||||
|
||||
#else // !(MOBILEGL_BUILD_DISAGGREGATED && __ANDROID__)
|
||||
|
||||
namespace MobileGL::MG_Backend::DirectGLES {
|
||||
Bool HostFrameTargetSupported(String& why) {
|
||||
why = "host frames are a disaggregated Android path";
|
||||
return false;
|
||||
}
|
||||
Bool HostFrameTargetCreate(const struct AHardwareBuffer*, HostFrameTarget&, String& why) {
|
||||
why = "host frames are a disaggregated Android path";
|
||||
return false;
|
||||
}
|
||||
void HostFrameTargetBind(const HostFrameTarget&) {}
|
||||
void HostFrameTargetDestroy(HostFrameTarget& target) { target = HostFrameTarget{}; }
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,52 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Backend/DirectGLES/HostFrameTarget.h
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#pragma once
|
||||
#include <Includes.h>
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
|
||||
struct AHardwareBuffer;
|
||||
|
||||
namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// THE FRAME THE DISPLAY HOST IS ABOUT TO SCAN OUT, AS A DRAW TARGET.
|
||||
//
|
||||
// The display host (the Android side that owns the screen) allocates its frames itself and
|
||||
// offers each one over a socket as an AHardwareBuffer. That is not a convenience: measured
|
||||
// on the device, AHardwareBuffer_createFromHandle accepts an AHardwareBuffer this side
|
||||
// allocated and refuses one the display queue handed over (gralloc BAD_VALUE), so the frames
|
||||
// a render server can draw into are the ones the host made for it.
|
||||
//
|
||||
// What this makes of such a frame: an EGLImage the driver accepts as a renderbuffer, and a
|
||||
// framebuffer that is the drawing target while that frame is the current one. None of
|
||||
// Android's window machinery is involved - no ANativeWindow, no SurfaceFlinger - which is
|
||||
// the point: the host puts the frame on the glass when this side says it is drawn.
|
||||
struct HostFrameTarget {
|
||||
void* Image = nullptr; // EGLImageKHR; opaque here so this header stays free of EGL types
|
||||
Uint Renderbuffer = 0;
|
||||
Uint Framebuffer = 0;
|
||||
Uint Width = 0;
|
||||
Uint Height = 0;
|
||||
};
|
||||
|
||||
// Whether the driver advertises what this is spelled in. False is answered with the missing
|
||||
// name in `why`, never an abort: a server that cannot take host frames has to be able to
|
||||
// say so.
|
||||
Bool HostFrameTargetSupported(String& why);
|
||||
|
||||
// Imports `buffer` as a render target. On failure `target` is left empty and `why` says
|
||||
// which call refused; no GL name is leaked.
|
||||
Bool HostFrameTargetCreate(const struct AHardwareBuffer* buffer, HostFrameTarget& target, String& why);
|
||||
|
||||
// Binds the target as the current draw framebuffer, called when its frame becomes current.
|
||||
void HostFrameTargetBind(const HostFrameTarget& target);
|
||||
|
||||
// Drops the GL names and the EGLImage. The AHardwareBuffer belongs to the bridge, which
|
||||
// releases it; this never touches it.
|
||||
void HostFrameTargetDestroy(HostFrameTarget& target);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -479,29 +479,9 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
BackendPtr* GetOrCreateByHandle(MG_Pipe::MGPipeHandle handle) {
|
||||
if (!EsprytSlotTablesEnabled()) return nullptr;
|
||||
if (MG_Pipe::MGPipeHandleIsNull(handle)) return nullptr;
|
||||
if (handle.Slot >= SlotTable::kMaxHandleSlot) {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
MG_Pipe::MGPipeSessionFail( // @Ph-declined (ID-P7-1): PH-2 stays Fatal, CONTRACT-P7 §12
|
||||
MG_Pipe::MGPipeFatalFamily::ProtocolCorruption,
|
||||
"MGPipe: Fatal{ProtocolCorruption, \"BackendSlotTable.HandleSlot\"} - "
|
||||
"GetOrCreateByHandle named slot %u, past this table's %u bound",
|
||||
handle.Slot, SlotTable::kMaxHandleSlot);
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
if (handle.Slot >= SlotTable::kMaxHandleSlot) return nullptr;
|
||||
const Uint32 liveGen = m_slotTable.LiveGenAt(handle.Slot);
|
||||
if (liveGen != 0 && liveGen > handle.Gen) {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
MG_Pipe::MGPipeSessionFail( // @Ph-declined (ID-P7-1): PH-2 stays Fatal, CONTRACT-P7 §12
|
||||
MG_Pipe::MGPipeFatalFamily::ProtocolCorruption,
|
||||
"MGPipe: Fatal{ProtocolCorruption, \"BackendSlotTable.Generation\"} - "
|
||||
"GetOrCreateByHandle named generation %u at slot %u, behind live generation %u",
|
||||
handle.Gen, handle.Slot, liveGen);
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
if (liveGen != 0 && liveGen > handle.Gen) return nullptr;
|
||||
return &m_slotTable.GetOrCreate(handle);
|
||||
}
|
||||
|
||||
@@ -707,24 +687,12 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// BackendSamplerObject* rows;
|
||||
// programs - g_programTwinLookupMemo.
|
||||
//
|
||||
// THE DEPENDENCY ROWS ARE IN MG_Pipe/SubsystemDeps.def, ONCE (P3b/P4b R-5), and the four
|
||||
// resolvers below READ them through MGPipeSubsystemDependenciesAreSet rather than carrying a
|
||||
// copy: a dependency the table declares is diagnosed and REFUSED here rather than half-run,
|
||||
// the bit-8-requires-bit-7 shape ResolveVertexInputSubsystemArm already ships.
|
||||
//
|
||||
// THIS COMMENT USED TO RESTATE THE ROWS AND WAS WRONG IN TWO WAYS THAT NOTHING COULD FAIL,
|
||||
// in the header of the file that IMPLEMENTS the refusal. It said "THREE OF THEM CARRY A
|
||||
// DEPENDENCY" when there are six rows (bits 8 and 13 were the two it did not know about),
|
||||
// and it listed "10 without 11" among the mirror pairs that are FINE - when 10-without-11 is
|
||||
// precisely D-K2's FOURTH row (ID-14/ID-15), refused twenty lines below by
|
||||
// ResolveTextureResourceSubsystemArm and withheld by the client at PipeFill.cpp's own gate.
|
||||
// MGPipe.h carried the identical pair of defects and lost them with the table; this copy was
|
||||
// left behind because Managers.h belonged to a package in flight. The rows are not restated
|
||||
// here again: the file that states them is the one the code reads.
|
||||
//
|
||||
// The mirror pairs that really ARE fine are stated in MGPipe.h beside the table, because an
|
||||
// absence is not a row - and because that is the one place where saying it cannot drift away
|
||||
// from the rows it is the complement of.
|
||||
// THREE OF THEM CARRY A DEPENDENCY (MGPipe.h, D-K2) and it is diagnosed and REFUSED here
|
||||
// rather than half-run, the bit-8-requires-bit-7 shape ResolveVertexInputSubsystemArm
|
||||
// already ships: bit 11 requires bit 10, bit 9 requires bit 10, bit 10 requires bit 7. The
|
||||
// mirror pairs (10 without 11, 10 without 9, 7 without 10) are all FINE and are said so out
|
||||
// loud, because an unreachable branch that says something different is how the reachable
|
||||
// one drifts. Bit 12 depends on nothing: a ShaderCso handle names no texture and no buffer.
|
||||
//
|
||||
// ResolveFramebufferSubsystemArm additionally carries D-C3's bring-up refusal: the wire
|
||||
// array is MGPFramebufferState::Color[8] and GetDynamicParameters().MaxColorAttachments is
|
||||
@@ -802,48 +770,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// composite: this reader hides the split behind one lookup, exactly as the wire does.
|
||||
const MG_Pipe::MGPipeShaderCsoRecord* PipeShaderCsoRecordForHandle(MG_Pipe::MGPipeHandle cso);
|
||||
|
||||
// P3b/P4b (wave 2-D, package D3): THE STORAGE RECORD BEHIND A TEXTURE RECORD - the record of
|
||||
// the texture it views for a glTextureView, and itself for every other texture.
|
||||
//
|
||||
// WHY THERE IS A SECOND READER. A view owns no texels, and the client keeps ONE emission
|
||||
// cursor per storage: an upload through a view's own name is remapped onto its storage owner
|
||||
// before it is emitted (MG_Impl/Pipe/TextureEmit.h, `ViewOf names the storage owner, and ONE
|
||||
// HOP always reaches storage`), so every resource_subdata for either name is keyed on the
|
||||
// OWNER and the applier moves the OWNER's Serial and PendingUploads alone
|
||||
// (MG_Pipe/PipeApply.cpp, ApplyTextureUpload). A view therefore has a Serial that no upload
|
||||
// ever moves, and the two STORAGE clauses of its draw-path clean gate have to be asked of
|
||||
// this record instead of its own - which is what the monolith gate gets for free, because
|
||||
// GetContentVersion() through a view is forwarded to the owner
|
||||
// (MG_State/GLState/TextureState/TextureObjectView.cpp:100-102). CONTRACT-P5E.md §5.2 states
|
||||
// the rule; without it a view that has been sampled once never sees another owner write.
|
||||
//
|
||||
// NULL IS "ASK AGAIN", NEVER "CLEAN". Every caller treats a null answer as a reason to RUN
|
||||
// the sync, which is the direction that re-uploads rather than the direction that shows stale
|
||||
// texels, and it raises nothing: a missing record is PipeTextureRecordForHandle's own
|
||||
// null-on-miss answer one level up, not a protocol refusal.
|
||||
//
|
||||
// BOUNDED, THOUGH ONE HOP IS ALWAYS ENOUGH. glTextureView composes a view-of-a-view onto the
|
||||
// ROOT at creation - the spec's additive min-level rule - and TextureObjectView's invariant
|
||||
// is that its owner "is never a view itself", so Desc.ViewOf already names storage. The walk
|
||||
// is written transitively anyway and gives up after a fixed number of hops, because THIS side
|
||||
// may not depend on a client invariant to terminate: a chain the wire could make cyclic ends
|
||||
// as a null answer rather than as a hang.
|
||||
//
|
||||
// DELETION ORDERING: THE LIVE/GEN TEST IS THE GUARANTEE, NOT THE EMIT ORDER. A view holds a
|
||||
// strong SharedPtr to its storage owner (TextureObjectView::m_storageOwner) and the client
|
||||
// emits resource_destroy from the DESTRUCTOR - "the last SharedPtr to this object dropping,
|
||||
// not the glDelete* that only marks the name and leaves a still-bound object very much alive"
|
||||
// (MG_State/GLState/TextureState/TextureObject.cpp:63). So the owner's storage cannot go away
|
||||
// under a live view, whatever order the application deletes the two names in. But the two
|
||||
// destroys are emitted back to back from one destructor chain, and when the view holds the
|
||||
// owner's LAST reference the member is destroyed before the view's base destructor runs, so
|
||||
// the wire carries resource_destroy(owner) and then resource_destroy(view): for one apply the
|
||||
// view record is live with Desc.ViewOf naming a freed slot. No draw can land in between, and
|
||||
// PipeTextureRecordForHandle tests Live and Gen, so that window answers null (= not clean)
|
||||
// rather than a recycled stranger's record.
|
||||
const MG_Pipe::MGPipeResourceRecord* PipeTextureStorageRecordForRecord(
|
||||
const MG_Pipe::MGPipeResourceRecord& record);
|
||||
|
||||
// P5e (fb): the texture's own TARGET, from its descriptor. The image-unit bind needs it
|
||||
// (glBindImageTexture's layered/format rules are per target) and MGPImageView has no room
|
||||
// for it - 24 bytes, no pad - so it is read off the resource record instead of being added
|
||||
@@ -1004,14 +930,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// (the UBO binding walk) skip the probe while their pre-pass epoch read
|
||||
// matches, exactly like the per-VAO memo stamps.
|
||||
Uint64 drawCleanEpoch = 0;
|
||||
// Frame serial whose completion retires the last glCopyBufferSubData the upload
|
||||
// ring staged INTO this store (the flush ladder's ring tier: FlushPendingRangesNow
|
||||
// on the pull arm, FlushPendingRangesFrom on the push arm); 0 = none. Until it
|
||||
// retires, both keep every partial range off the range-invalidating map: on
|
||||
// Adreno 830 that map, on a store with a queued copy, loses the copy (see
|
||||
// FlushPendingRangesNow and InvalidateFlushAccessFor). Draw thread only, like the
|
||||
// flush.
|
||||
Uint64 ringCopyRetireSerial = 0;
|
||||
// Zero-copy coherent persistent map (EXT_buffer_storage): the GL store is
|
||||
// immutable, persistently+coherently mapped, and persistentPtr is what the app
|
||||
// (and the frontend PipeResource) write into directly. While set, draw-time
|
||||
@@ -1050,21 +968,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// the legacy arm did; this member exists for the drains that have no object, which
|
||||
// in P3a is the readback flush and the fp64 narrowing.
|
||||
const Uint8* hostBytes = nullptr;
|
||||
#endif
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P11 B2 (T0): the client's AHardwareBuffer this store IS - imported with
|
||||
// glBufferStorageExternalEXT, so `id` is immutable, persistentMapped and
|
||||
// persistentPtr is this server's own coherent map of the client's pages. The
|
||||
// reference is this twin's own, released only after a fence that follows the
|
||||
// store's last use has signalled (RetireT0Import). Survives an ES context loss:
|
||||
// the next ensure re-imports it. Null for every store T0 did not adopt.
|
||||
void* externalAhb = nullptr;
|
||||
// P8-C: A SHADER WROTE THIS STORE ON THIS SIDE since the R-11 staged copy (or, for
|
||||
// T0, the coherent map) was last known to match it - set by the draw / dispatch that
|
||||
// bound it writable (storage block, atomic counter, writable buffer image), cleared
|
||||
// by SplitHostBytesForCpuRead's refresh and by a respecify. Only the server's own
|
||||
// CPU readers consult it; the client keeps its own set (GpuWritePending.h).
|
||||
Bool serverGpuWritten = false;
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -1126,44 +1029,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// resolver. A no-op for a base that is not this resource's server shadow.
|
||||
void RequireStagedCoverage(GLESBufferResource& resource, const Uint8* hostBase, SizeT start,
|
||||
SizeT end, const char* site);
|
||||
|
||||
// P11 B2: THE CPU-READABLE BYTES OF A SPLIT SERVER'S BUFFER TWIN, for the handle-arm
|
||||
// readers that have no frontend object (indirect commands, primitive-restart
|
||||
// substitution, the multi-draw index rebase): the R-11 staged copy, or - for a T0 store,
|
||||
// which has none - this server's own coherent map of the client's AHardwareBuffer, read
|
||||
// exactly as the monolith arm reads the adopted map through MappedData().
|
||||
inline const Uint8* SplitHostBytes(const GLESBufferResource& resource) {
|
||||
if (resource.hostBytes != nullptr) return resource.hostBytes;
|
||||
return resource.externalAhb != nullptr ? static_cast<const Uint8*>(resource.persistentPtr) : nullptr;
|
||||
}
|
||||
|
||||
// P8-C: THE SAME BYTES, MADE CURRENT FIRST - for a reader that CONSUMES them (the restart
|
||||
// rewrite, the multi-draw rebase, the *IndirectCount count, an indirect command's
|
||||
// CPU-fed fields, the XFB scatter's pre-capture bytes). SplitHostBytes above is only
|
||||
// "what uploads staged": a store a shader wrote on this side (serverGpuWritten) is
|
||||
// refreshed from this server's own GL buffer - queued uploads flushed into it first,
|
||||
// then the whole store read back into the staged copy, which also gives an orphaned
|
||||
// store its first copy - and a T0 store lands its queued resident writes and finishes
|
||||
// before its coherent map is read. A clean staged store costs one flag test.
|
||||
// `res` names the record whose descriptor width the copy takes; `site` names the
|
||||
// reader in the one-time diagnostic when the refresh cannot run.
|
||||
const Uint8* SplitHostBytesForCpuRead(GLESBufferResource& resource, MG_Pipe::MGPipeHandle res,
|
||||
const char* site);
|
||||
// P8-C: bytes the SERVER itself put into a store's GL buffer and already holds on the CPU
|
||||
// (an XFB capture it mapped for the client's writeback, a scatter it composed) go into
|
||||
// the staged copy as well, so no refresh is owed for them. A T0 store has no copy.
|
||||
void StageServerWrittenRange(GLESBufferResource& resource, MG_Pipe::MGPipeHandle res, const void* bytes,
|
||||
SizeT offset, SizeT size);
|
||||
|
||||
// M-3's WHOLE-STORE predicate, and the GUARD every caller of RequireStagedCoverage over
|
||||
// a whole-store read has to carry: true when the application DECLARED the store's
|
||||
// content (glBufferData(size, data)), so a coverage gap is a missing record; false when
|
||||
// it ORPHANED the store (glBufferData(size, NULL)), where every byte it has not staged
|
||||
// since is undefined by its own declaration and the shadow's zero-fill is exactly what
|
||||
// the monolith arm would have uploaded from MappedData(). Managers.cpp's pool-reuse
|
||||
// ladder and DirectGLES.cpp's XFB scatter are its two callers and they must not be able
|
||||
// to answer it differently.
|
||||
Bool ResourceContentIsDeclared(MG_Pipe::MGPipeHandle res);
|
||||
#endif
|
||||
|
||||
// MONOLITH GLUE, and named as such: the handle of a resource this backend is looking
|
||||
@@ -1194,14 +1059,10 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// ("do not take tier 1"), which drops the range onto the staging ring and costs a copy
|
||||
// rather than a corruption.
|
||||
//
|
||||
// `ringCopyInFlight`: the store still has an upload-ring glCopyBufferSubData queued that the
|
||||
// GPU may not have run (GLESBufferResource::ringCopyRetireSerial not yet retired).
|
||||
//
|
||||
// Returns the glMapBufferRange access bits, or 0 when tier 1 must not be taken.
|
||||
inline constexpr SizeT kEsprytInvalidateRangeMinBytes = 128u * 1024u;
|
||||
constexpr GLbitfield InvalidateFlushAccessFor(SizeT queuedStart, SizeT queuedEnd, SizeT mapStart,
|
||||
SizeT mapEnd, SizeT limit, SizeT storageSize,
|
||||
Bool ringCopyInFlight) {
|
||||
SizeT mapEnd, SizeT limit, SizeT storageSize) {
|
||||
if (mapEnd <= mapStart) return 0u;
|
||||
// THE WIDENING REFUSAL. Not >=, not "covers": exactly, in both directions. A map
|
||||
// narrower than the queued range leaves bytes unwritten inside a range it has just
|
||||
@@ -1213,13 +1074,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// page-substitution fast path needs a page-coverable range to engage, and below it
|
||||
// the driver falls back to waiting out the WAR hazard on the CPU.
|
||||
if (!wholeBuffer && size < kEsprytInvalidateRangeMinBytes) return 0u;
|
||||
// A partial range-invalidating map must not overtake a ring copy into this store the GPU
|
||||
// has not run yet. Adreno 830 answers such a map on a store with a copy still queued by
|
||||
// losing the copy (dev f973008c, the pull arm's FlushPendingRangesNow: create-instancing
|
||||
// drew whole Embeddium terrain sections empty, SSIM 0.870). The range goes to the ring
|
||||
// instead, GPU-ordered behind the copies. The whole-buffer orphan-map is exempt: it
|
||||
// rewrites every byte from the shadow the queued copies were taken from.
|
||||
if (!wholeBuffer && ringCopyInFlight) return 0u;
|
||||
return GL_MAP_WRITE_BIT |
|
||||
(wholeBuffer ? GL_MAP_INVALIDATE_BUFFER_BIT : GL_MAP_INVALIDATE_RANGE_BIT);
|
||||
}
|
||||
@@ -1329,10 +1183,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// Deletes GL buffers whose owning frontend objects died (possibly on a
|
||||
// thread without a current ES context). Called from draw-time sync.
|
||||
void ProcessDeferredBufferReleases();
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P11 B2: the T0 half of that drain - run right after it (retired AHardwareBuffers).
|
||||
void ProcessDeferredT0Retires();
|
||||
#endif
|
||||
|
||||
// glBindBuffer with a redundant-bind cache for GL_ARRAY_BUFFER.
|
||||
void BindBufferId(GLenum target, Uint id);
|
||||
@@ -1879,9 +1729,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
return TextureTarget::Texture2D;
|
||||
case TextureTarget::Texture1DArray:
|
||||
return TextureTarget::Texture2DArray;
|
||||
// An external texture's storage is an imported EGLImage; to the driver it is 2D.
|
||||
case TextureTarget::TextureExternalOES:
|
||||
return TextureTarget::Texture2D;
|
||||
default:
|
||||
return target;
|
||||
}
|
||||
@@ -2032,10 +1879,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// allocation, or capture the old native contents, merge pending
|
||||
// upload regions and re-arm the server's whole-level replay set.
|
||||
// First allocations use staged bytes directly. No frontend dirty
|
||||
// flag, allocator or pixel-store object participates. P9 W2: a level
|
||||
// the driver does not hold (defined after the last sync) is never read
|
||||
// back, and a readback the driver refuses falls back to the staged
|
||||
// level when the store covers it (notes/p9/W2-REMINT.md).
|
||||
// flag, allocator or pixel-store object participates.
|
||||
void RequireImageBindableStorageByHandle(MG_Pipe::MGPipeHandle res,
|
||||
const MG_Pipe::MGPipeResourceRecord& record);
|
||||
#endif
|
||||
@@ -2044,9 +1888,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// carrier the storage is an integer texture holding codes and glGetTexImage still owes
|
||||
// the application floats.
|
||||
Bool RequiresImageBindableStorage() const { return m_imageBindableStorageRequired; }
|
||||
// See m_driverMayHoldGpuWrites. Callers holding the STATE texture use
|
||||
// NoteDriverSideTextureWrite, which also reaches the storage behind a view.
|
||||
void NoteDriverSideWrite() { m_driverMayHoldGpuWrites = true; }
|
||||
void Bind(GLenum target, Uint unit = TempTextureUnit);
|
||||
Uint GetBackendTextureId() const;
|
||||
|
||||
@@ -2163,15 +2004,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
Bool m_isInitialized = false;
|
||||
Bool m_imageBindableStorageRequired = false;
|
||||
Bool m_backendStorageImmutable = false;
|
||||
// Whether the driver texture may hold texels the shadow never saw. Set the first time
|
||||
// anything other than a texel upload can write it - an application framebuffer
|
||||
// attachment, a writable image binding, a copy or blit into it, a driver-side mipmap
|
||||
// generation - and never cleared. Until then the driver holds, outside a level's
|
||||
// pending writes, exactly the shadow bytes it was last sent, so those writes may go up
|
||||
// as their union box (one unpack-ring job, which is what Mali needs); from then on
|
||||
// only the texels the client wrote may go up, since the shadow is stale everywhere
|
||||
// else. See SyncMipmapsToBackend.
|
||||
Bool m_driverMayHoldGpuWrites = false;
|
||||
// Latches the "this driver has no buffer textures" report to once per texture. The
|
||||
// report is emitted from the respecify path, which bails before recording the state
|
||||
// it was asked to apply - so without the latch the texture stays permanently dirty
|
||||
@@ -2341,11 +2173,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
SharedPtr<BackendTextureObject>& SyncTextureObjectToBackend(
|
||||
const SharedPtr<MG_State::GLState::ITextureObject>& textureObject,
|
||||
Bool imageBindableStorageRequired = false);
|
||||
// Every path that lets the DRIVER write a texture's texels calls this (see
|
||||
// BackendTextureObject::m_driverMayHoldGpuWrites): an application framebuffer attachment,
|
||||
// a writable image binding, a copy, blit or mipmap generation into it. A view writes its
|
||||
// storage texture's image, so the storage texture is the one marked.
|
||||
void NoteDriverSideTextureWrite(const SharedPtr<MG_State::GLState::ITextureObject>& textureObject);
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// ---- P5e SEAM (MG_Remote/CONTRACT-P5E.md §4.2, §5.2; declared by c0e, bodied by
|
||||
// id/tx2) --------------------------------------------------------------------------
|
||||
@@ -2362,29 +2189,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
SharedPtr<BackendTextureObject>& SyncTextureToBackendByHandle(
|
||||
MG_Pipe::MGPipeHandle texture, Bool imageBindableStorageRequired = false);
|
||||
BackendTextureObject* ResolveTextureTwin(MG_Pipe::MGPipeHandle texture);
|
||||
// NoteDriverSideTextureWrite's HANDLE ARM, for the same paths when the caller holds a
|
||||
// Texture handle (a framebuffer surface's Res, an image unit's Res, VerbMipRes,
|
||||
// VerbCopyTexDst, a copy-image endpoint): the twin the handle's record names is marked, or
|
||||
// its storage owner's (Desc.ViewOf) for a view. Nothing on the apply thread reads a
|
||||
// frontend object for it.
|
||||
//
|
||||
// P8-E: under a transport the same storage owner's staged store is marked driver-written
|
||||
// too (StagedTextureStore::MarkDriverWritten), so a refused readback does not answer from
|
||||
// bytes the driver has since overwritten - unless `storeFollowsTheWrite`, which only
|
||||
// glCopyImageSubData passes: it tries FollowCopyImageInStagedStore first and marks the store
|
||||
// itself when that fails.
|
||||
void NoteDriverSideTextureWriteByHandle(MG_Pipe::MGPipeHandle texture, Bool storeFollowsTheWrite = false);
|
||||
#endif
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P8-E (notes/p8/E.md): make glCopyImageSubData's texel-block move in the server's staged
|
||||
// store too (StagedTextureStore::FollowCopy), so the destination level's bytes stay its
|
||||
// content. Box in each image's own texel grid. False when the store cannot follow: a cube
|
||||
// map or 1D array endpoint (copy-image puts faces / layers on z, the store does not), a view,
|
||||
// two different internal formats, a level whose bytes did not all cross, a source the
|
||||
// driver has written, or a monolith arm.
|
||||
Bool FollowCopyImageInStagedStore(MG_Pipe::MGPipeHandle source, Uint32 sourceLevel, const IntVec3& sourceOrigin,
|
||||
MG_Pipe::MGPipeHandle destination, Uint32 destinationLevel,
|
||||
const IntVec3& destinationOrigin, const IntVec3& size);
|
||||
#endif
|
||||
// Brings every texture the next draw reads - the touched units' bindings and the draw
|
||||
// FBO's texture attachments - onto the backend, through the two borrowed-pair memos
|
||||
@@ -3142,11 +2946,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// Same for gl_BaseVertex: only a program that reads it pays for the per-draw
|
||||
// uniform write, and only such a program needs the reset after one.
|
||||
Bool ReadsBaseVertex() const { return m_baseVertexUniformLocation >= 0; }
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P8-C: same for the gl_BaseInstance uniform - which an indirect draw feeds from the
|
||||
// command on the CPU only when the mg_IndirectParams view is absent.
|
||||
Bool ReadsBaseInstance() const { return m_baseInstanceUniformLocation >= 0; }
|
||||
#endif
|
||||
// Which viewport indices the next draw's fragments may keep, one bit each. Written
|
||||
// once per replay pass; see ForEachViewportRoutingPass.
|
||||
void SetViewportPassMask(Uint32 indexMask) const;
|
||||
@@ -3725,26 +3524,5 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// delete opcode may already have released (the idempotent-second-path shape the notice
|
||||
// arms document).
|
||||
Bool ReleaseTwinsForWireObjectDeath(MG_Pipe::MGPipeHandle handle, MG_Pipe::MGPipeKind kind);
|
||||
|
||||
// P12 (on-screen server window): A SERVER SESSION ENDS IN A PROCESS THAT OUTLIVES IT.
|
||||
//
|
||||
// The twin tables above are process globals, and until P12 every server process served ONE
|
||||
// session: the exec'd supervisor forks a child per session and the child exits with it, so the
|
||||
// twins a session built died with its process (InProcessTeardown's deliberate leak). The
|
||||
// in-process display server (mobilegl_server_serve_inprocess, the display Activity's process)
|
||||
// runs sessions ONE AFTER ANOTHER IN ONE PROCESS, and the next session's client mints its
|
||||
// handles from the same {slot, gen} space again. A twin the previous session left behind then
|
||||
// answers for the new session's object: a program twin names a program of the DESTROYED
|
||||
// context, so the link fails with an empty log and every draw no-ops (Espryt on Adreno and on
|
||||
// llvmpipe alike), a stale VAO/buffer twin feeds the driver a dead name (a SIGSEGV inside
|
||||
// Adreno's glDrawElements), and a stale live generation ahead of the new client's refuses its
|
||||
// handle as ProtocolCorruption.
|
||||
//
|
||||
// So the server backend's destruction - the end of a session under a transport, on the apply
|
||||
// thread, after DestroyEGLContext destroyed the context those ids belonged to - drops EVERY
|
||||
// twin of every kind, with InProcessTeardown() answering true for the duration so no twin
|
||||
// destructor calls into the driver (there is no current context, and the ids name nothing).
|
||||
// A no-op once exit() has begun (the statics may already be gone). Monolith never calls it.
|
||||
void DropEveryTwinForEndedServerSession();
|
||||
#endif
|
||||
} // namespace MobileGL::MG_Backend::DirectGLES
|
||||
|
||||
@@ -191,16 +191,15 @@ namespace MobileGL::MG_Backend::DirectGLES::MultiDrawImpl {
|
||||
if (question == IndexBufferQuestion::Presence) return view;
|
||||
|
||||
if (question == IndexBufferQuestion::HostBytes) {
|
||||
// The applier has already consumed the persistent-map blocks for this
|
||||
// resource before the draw verb replayed; the one Sync* this arm owes is the
|
||||
// monolith's SyncGpuWrites, and (P8-C) SplitHostBytesForCpuRead is it: a store
|
||||
// a shader wrote on this side is read back from this server's own GL buffer,
|
||||
// because no writeback ever reaches the server's staged copy. That is also why
|
||||
// this arm cannot be expressed as "find the object and run the monolith body".
|
||||
// No Sync* pair here and none is missing: on this side the applier has
|
||||
// already consumed the persistent-map blocks and the shader writebacks for
|
||||
// this resource before the draw verb replayed, so the server's staged shadow
|
||||
// IS the synced copy. That is also why this arm cannot be expressed as "find
|
||||
// the object and run the monolith body".
|
||||
auto* resource = BufferImpl::FindBufferResourceForHandle(res);
|
||||
if (resource == nullptr) RefuseMissingIndexBufferRecord(entry, res, "backend resource");
|
||||
view.Size = BufferImpl::ResourceWidthForHandle(res);
|
||||
view.HostBytes = BufferImpl::SplitHostBytesForCpuRead(*resource, res, "multidraw_index_rebase");
|
||||
view.HostBytes = resource->hostBytes;
|
||||
if (view.HostBytes != nullptr && IndexBufferRecordHasDefinedContent(st, res)) {
|
||||
BufferImpl::RequireStagedCoverage(*resource, view.HostBytes, 0, view.Size,
|
||||
"multidraw_index_rebase");
|
||||
|
||||
@@ -14,9 +14,6 @@
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
#include <MG_Impl/Pipe/SlotAllocator.h>
|
||||
#endif
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
#include <MG_Pipe/PipeSessionFail.h>
|
||||
#endif
|
||||
|
||||
// Espryt 0b, the first Track H slice: the DENSE, {slot, gen}-keyed twin table that replaces
|
||||
// StateBackendObjectRegistry's UnorderedMap<StateObject*, Entry>.
|
||||
@@ -348,19 +345,9 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// already orders of magnitude past any real GL object count, while a corrupt 32-bit
|
||||
// slot asks for a four-billion-entry resize.
|
||||
if (handle.Slot >= kMaxHandleSlot) {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// PH-2: handle.Slot is peer supplied on the disaggregated arm. Release builds
|
||||
// must publish a named protocol fault instead of silently returning m_nullTwin.
|
||||
MG_Pipe::MGPipeSessionFail( // @Ph-declined (ID-P7-1): PH-2 stays Fatal, CONTRACT-P7 §12
|
||||
MG_Pipe::MGPipeFatalFamily::ProtocolCorruption,
|
||||
"MGPipe: Fatal{ProtocolCorruption, \"BackendSlotTable.HandleSlot\"} - "
|
||||
"GetOrCreate(handle) named slot %u, past this table's %u bound",
|
||||
handle.Slot, kMaxHandleSlot);
|
||||
#else
|
||||
MOBILEGL_ASSERT(false, "GetOrCreate(handle) named slot %u, past this table's %u bound",
|
||||
handle.Slot, kMaxHandleSlot);
|
||||
return m_nullTwin;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Same arming as the minting overload, and for the same reason: twin creation is
|
||||
@@ -382,21 +369,11 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// below already gives the same input.
|
||||
Entry& entry = EntryAt(handle.Slot);
|
||||
if (entry.Live && entry.Gen > handle.Gen) {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// PH-2: a stale peer generation must not silently shed the incumbent twin in a
|
||||
// release server. The funnel names the exact identity fault and notifies the peer.
|
||||
MG_Pipe::MGPipeSessionFail( // @Ph-declined (ID-P7-1): PH-2 stays Fatal, CONTRACT-P7 §12
|
||||
MG_Pipe::MGPipeFatalFamily::ProtocolCorruption,
|
||||
"MGPipe: Fatal{ProtocolCorruption, \"BackendSlotTable.Generation\"} - "
|
||||
"GetOrCreate(handle) named generation %u at slot %u, behind live generation %u",
|
||||
handle.Gen, handle.Slot, entry.Gen);
|
||||
#else
|
||||
MOBILEGL_ASSERT(false,
|
||||
"GetOrCreate(handle) named generation %u at slot %u, which is BEHIND "
|
||||
"the live entry's %u - refusing rather than destroying the incumbent",
|
||||
handle.Gen, handle.Slot, entry.Gen);
|
||||
return m_nullTwin;
|
||||
#endif
|
||||
}
|
||||
if (entry.Live && entry.Gen != handle.Gen) entry.backend.reset();
|
||||
entry.Gen = handle.Gen;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Included in DirectGLES.cpp after the native packed-word readback helper.
|
||||
// A storage promotion needs the driver's own texels as owned tight rows, not
|
||||
// client PACK layout or a fallback into a frontend texture's potentially stale
|
||||
// shadow.
|
||||
// The server needs owned tight rows for a storage promotion, not client PACK
|
||||
// layout or a fallback into a frontend texture's potentially stale shadow.
|
||||
class ScopedWireTextureReadLevel {
|
||||
public:
|
||||
ScopedWireTextureReadLevel(GLuint texture, GLenum target, GLint level)
|
||||
@@ -281,144 +280,6 @@
|
||||
return true;
|
||||
}
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P9 W2-a. The store's Defined-ness follows the client's respecifies; the driver's follows the
|
||||
// twin's last sync. A re-mint asks this before reading a level back, because a level defined
|
||||
// after that sync (null data, or null data plus a partial upload) is not on the driver yet and
|
||||
// its FBO attachment is incomplete - which used to end the session at
|
||||
// Fatal{ResourceUnavailable, "image-promotion-readback"} on legal GL.
|
||||
Bool NativeTextureLevelHasExtent(GLuint texture, TextureTarget target, TextureUploadTarget uploadTarget,
|
||||
GLint level, const IntVec3& logicalExtent) {
|
||||
if (!texture || level < 0 || !g_GLESFuncs.glGetTexLevelParameteriv) return true;
|
||||
const IntVec3 extent = TextureImpl::GetBackendUploadSize(target, logicalExtent);
|
||||
const GLenum nativeTarget = TextureImpl::ConvertTextureTargetToBackendGLEnum(target);
|
||||
GLenum binding = GL_NONE;
|
||||
switch (nativeTarget) {
|
||||
case GL_TEXTURE_2D: binding = GL_TEXTURE_BINDING_2D; break;
|
||||
case GL_TEXTURE_3D: binding = GL_TEXTURE_BINDING_3D; break;
|
||||
case GL_TEXTURE_2D_ARRAY: binding = GL_TEXTURE_BINDING_2D_ARRAY; break;
|
||||
case GL_TEXTURE_CUBE_MAP: binding = GL_TEXTURE_BINDING_CUBE_MAP; break;
|
||||
case GL_TEXTURE_CUBE_MAP_ARRAY: binding = GL_TEXTURE_BINDING_CUBE_MAP_ARRAY; break;
|
||||
default: return true;
|
||||
}
|
||||
// A cube's levels are per face; every other target answers for the whole level.
|
||||
const GLenum queryTarget = nativeTarget == GL_TEXTURE_CUBE_MAP
|
||||
? TextureImpl::ConvertTextureUploadTargetToBackendGLEnum(uploadTarget) : nativeTarget;
|
||||
DrainESErrors();
|
||||
GLint previous = 0;
|
||||
g_GLESFuncs.glGetIntegerv(binding, &previous);
|
||||
g_GLESFuncs.glBindTexture(nativeTarget, texture);
|
||||
GLint width = 0, height = 0, depth = 0;
|
||||
g_GLESFuncs.glGetTexLevelParameteriv(queryTarget, level, GL_TEXTURE_WIDTH, &width);
|
||||
g_GLESFuncs.glGetTexLevelParameteriv(queryTarget, level, GL_TEXTURE_HEIGHT, &height);
|
||||
g_GLESFuncs.glGetTexLevelParameteriv(queryTarget, level, GL_TEXTURE_DEPTH, &depth);
|
||||
const Bool answered = g_GLESFuncs.glGetError() == GL_NO_ERROR;
|
||||
g_GLESFuncs.glBindTexture(nativeTarget, static_cast<GLuint>(previous));
|
||||
if (!answered) return true;
|
||||
const Bool layered = nativeTarget == GL_TEXTURE_3D || nativeTarget == GL_TEXTURE_2D_ARRAY ||
|
||||
nativeTarget == GL_TEXTURE_CUBE_MAP_ARRAY;
|
||||
return width == extent.x() && height == extent.y() && (!layered || depth == extent.z());
|
||||
}
|
||||
|
||||
// P8-E (notes/p8/E.md). MGITEST_ESPRYT_REFUSE_TEXTURE_READBACK_EXTENT=<w>x<h>, READ BY THE SERVER:
|
||||
// a colour level of exactly that extent is treated as one the driver refused to attach - what an
|
||||
// Adreno does for RGB16 and the 16-bit SNORM formats, and what no host driver can be made to do.
|
||||
// Scoped by the extent so the tcp lane's shared supervisor can carry it for the whole lane: only
|
||||
// the scenario that builds that extent (CopyImageStoreReadbackScenario) ever meets it.
|
||||
static Bool WireTextureReadbackRefusedForTesting(const IntVec3& extent) {
|
||||
static const IntVec3 s_refused = [] {
|
||||
const char* value = std::getenv("MGITEST_ESPRYT_REFUSE_TEXTURE_READBACK_EXTENT");
|
||||
if (value == nullptr) return IntVec3{0, 0, 0};
|
||||
char* end = nullptr;
|
||||
const long width = std::strtol(value, &end, 10);
|
||||
if (end == value || *end != 'x') return IntVec3{0, 0, 0};
|
||||
const long height = std::strtol(end + 1, nullptr, 10);
|
||||
if (width <= 0 || height <= 0) return IntVec3{0, 0, 0};
|
||||
return IntVec3{static_cast<Int>(width), static_cast<Int>(height), 1};
|
||||
}();
|
||||
return s_refused.x() > 0 && extent == s_refused;
|
||||
}
|
||||
|
||||
// P8-E: THE STORE ROUTE, for a level the driver refused to read back. The server's staged store
|
||||
// is the only CPU copy of the level on this side, and it answers only while its bytes ARE the
|
||||
// level: every byte crossed (IsCovered), at the extent asked for, and the texture was never
|
||||
// written by the driver except by copies the store followed (!IsDriverWritten - see
|
||||
// StagedTextureStore's P8-E block and FollowCopyImageInStagedStore). The conversion is
|
||||
// GetTexImageViaShadowConversion's, into tight rows: a packed format read with its own type
|
||||
// takes the stored words verbatim, everything else decodes to wide RGBA and converts row by row.
|
||||
// Anything else DECLINES BY NAME: the reply is an error, and the client's
|
||||
// Fatal{ReplyError, "ReadPixels"} ends the session instead of handing back bytes the driver has
|
||||
// since overwritten.
|
||||
static Bool ReadWireLevelFromStagedStore(MG_Pipe::MGPipeHandle res, TextureInternalFormat logicalFormat,
|
||||
TextureUploadTarget uploadTarget, GLint level, const IntVec3& extent,
|
||||
GLenum format, GLenum type, Vector<Uint8>& bytes) {
|
||||
auto& store = MG_Remote::Server::ServerStagedTexture();
|
||||
const Uint64 key = MG_Remote::Server::StagedTextureStore::KeyForHandle(res);
|
||||
const auto target = static_cast<Uint16>(uploadTarget);
|
||||
const auto mip = static_cast<Uint16>(level);
|
||||
ReadbackChannelMapping mapping{};
|
||||
const SizeT pixelBytes = GetReadbackChannelMapping(format, mapping) ? GetReadbackDstPixelSize(mapping, type) : 0;
|
||||
const SizeT texels = static_cast<SizeT>(std::max(extent.x(), 0)) * static_cast<SizeT>(std::max(extent.y(), 0)) *
|
||||
static_cast<SizeT>(std::max(extent.z(), 0));
|
||||
const char* declined = nullptr;
|
||||
if (!store.CopiesIntoServerStorage()) {
|
||||
declined = "this arm keeps no staged store";
|
||||
} else if (store.IsDriverWritten(key)) {
|
||||
declined = "the driver has written the texture since its bytes crossed";
|
||||
} else if (!store.IsCovered(key, target, mip)) {
|
||||
declined = "not every byte of the level crossed";
|
||||
} else if (store.LevelExtentOrUndefined(key, target, mip) != extent) {
|
||||
declined = "the staged level is not the extent asked for";
|
||||
} else if (pixelBytes == 0 || texels == 0) {
|
||||
declined = "the format/type pair has no readback mapping";
|
||||
}
|
||||
Vector<Uint8> out;
|
||||
if (declined == nullptr) {
|
||||
const Uint8* staged = store.RequireLevelBytes(key, target, mip, "texture-readback-from-store");
|
||||
if (MG_Util::PixelStoreProcessor::IsRawPackedPixelTransfer(
|
||||
logicalFormat, MG_Util::ConvertGLEnumToTextureInputFormat(format),
|
||||
MG_Util::ConvertGLEnumToTexturePixelDataType(type))) {
|
||||
if (store.LevelByteSize(key, target, mip) != texels * pixelBytes) {
|
||||
declined = "the staged words are not the client's word size";
|
||||
} else {
|
||||
out.assign(staged, staged + texels * pixelBytes);
|
||||
}
|
||||
} else {
|
||||
Vector<Uint8> wide;
|
||||
Bool isInteger = false;
|
||||
Bool isSigned = false;
|
||||
if (!MG_Util::PixelStoreProcessor::DecodeShadowDataToWideRGBA(logicalFormat, staged, texels, wide,
|
||||
isInteger, isSigned)) {
|
||||
declined = "the staged format has no wide decoding";
|
||||
} else if (mapping.isInteger != isInteger) {
|
||||
declined = "an integer read of a normalized level, or the reverse";
|
||||
} else {
|
||||
const GLenum wideType = isInteger ? (isSigned ? GL_INT : GL_UNSIGNED_INT) : GL_FLOAT;
|
||||
const SizeT rowTexels = static_cast<SizeT>(extent.x());
|
||||
const SizeT rows = texels / rowTexels;
|
||||
const SizeT wideRowBytes = rowTexels * 4 * GetReadbackComponentSize(wideType);
|
||||
out.resize(texels * pixelBytes);
|
||||
for (SizeT row = 0; row < rows; ++row) {
|
||||
ReadbackImpl::ConvertWideReadbackRow(wide.data() + row * wideRowBytes,
|
||||
out.data() + row * rowTexels * pixelBytes, rowTexels,
|
||||
wideType, mapping, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (declined != nullptr) {
|
||||
MGLOG_E_ONCE("MGPipe: texture {%u,%u} level %d: the driver refused the readback and the staged store "
|
||||
"cannot answer it (%s) - DECLINED (texture-readback-store-declined)",
|
||||
res.Slot, res.Gen, level, declined);
|
||||
return false;
|
||||
}
|
||||
MGLOG_W_ONCE("MGPipe: texture {%u,%u} level %d: the driver refused the readback (internal format %u); "
|
||||
"answered from the server's staged store (texture-readback-from-store)",
|
||||
res.Slot, res.Gen, level, static_cast<unsigned>(logicalFormat));
|
||||
bytes = Move(out);
|
||||
return true;
|
||||
}
|
||||
|
||||
Bool ReadTextureImageWire(const MG_Pipe::MGPReadbackInfo& info, Vector<Uint8>& bytes) {
|
||||
const auto* record = PipeTextureRecordForHandle(info.Res);
|
||||
if (!record) return false;
|
||||
@@ -432,32 +293,17 @@
|
||||
const Bool wholeCube = info.Target == GL_TEXTURE_CUBE_MAP;
|
||||
const IntVec3 extent{static_cast<Int>(info.Box.W), static_cast<Int>(info.Box.H),
|
||||
wholeCube ? 1 : static_cast<Int>(info.Box.D)};
|
||||
const auto logicalFormat = static_cast<TextureInternalFormat>(record->Desc.InternalFormat);
|
||||
// The R32UI word leg never goes through a framebuffer, so the knob leaves it alone (it is
|
||||
// ReadTextureLevelTight's first choice for exactly these reads).
|
||||
const Bool packedWordRead =
|
||||
!twin->RequiresImageBindableStorage() &&
|
||||
MG_Util::PixelStoreProcessor::IsRawPackedPixelTransfer(
|
||||
logicalFormat, MG_Util::ConvertGLEnumToTextureInputFormat(info.Format),
|
||||
MG_Util::ConvertGLEnumToTexturePixelDataType(info.Type)) &&
|
||||
MG_Util::GetInputBytesPerPixel(MG_Util::ConvertGLEnumToTextureInputFormat(info.Format),
|
||||
MG_Util::ConvertGLEnumToTexturePixelDataType(info.Type)) == sizeof(Uint32);
|
||||
const Bool refusedForTesting = !packedWordRead && WireTextureReadbackRefusedForTesting(extent);
|
||||
Vector<Uint8> result;
|
||||
for (Int face = 0; face < (wholeCube ? 6 : 1); ++face) {
|
||||
const auto uploadTarget = wholeCube
|
||||
? static_cast<TextureUploadTarget>(static_cast<Int>(TextureUploadTarget::CubeMapPositiveX) + face)
|
||||
: MG_Util::ConvertGLEnumToTextureUploadTarget(info.Target);
|
||||
Vector<Uint8> slice;
|
||||
if (refusedForTesting ||
|
||||
!ReadTextureLevelTight(twin->GetBackendTextureId(), target, uploadTarget, logicalFormat, info.Level,
|
||||
extent, twin->RequiresImageBindableStorage(), info.Format, info.Type, slice)) {
|
||||
if (!ReadWireLevelFromStagedStore(info.Res, logicalFormat, uploadTarget, info.Level, extent,
|
||||
info.Format, info.Type, slice)) return false;
|
||||
}
|
||||
if (!ReadTextureLevelTight(twin->GetBackendTextureId(), target, uploadTarget,
|
||||
static_cast<TextureInternalFormat>(record->Desc.InternalFormat), info.Level, extent,
|
||||
twin->RequiresImageBindableStorage(), info.Format, info.Type, slice)) return false;
|
||||
result.insert(result.end(), slice.begin(), slice.end());
|
||||
}
|
||||
bytes = Move(result);
|
||||
return true;
|
||||
}
|
||||
#endif // MOBILEGL_BUILD_DISAGGREGATED
|
||||
|
||||
@@ -330,29 +330,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
PopulateFormatCapabilitiesImpl(physicalDevice, getFormatProperties, capabilities, cache);
|
||||
}
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
BackendObject_DirectVulkan::~BackendObject_DirectVulkan() {
|
||||
// P12 review fix: A SERVER SESSION THAT ENDS WITHOUT A CLEAN TEARDOWN LEAVES NO RENDERER ON
|
||||
// THE WINDOW. The renderer - swapchain and VkSurfaceKHR on the window - is a process global
|
||||
// that only ReleaseEGLResources / a released surface drops, and a client that went away
|
||||
// without eglTerminate (a crash, a kill, a dropped connection) sends neither. Under a
|
||||
// transport this object is the server's and its destruction is the session's end (ServerLoop's
|
||||
// apply thread, after the final drain, before the display lease ends), so the renderer goes
|
||||
// here: nothing of the ended session keeps presenting into, or holding a surface on, the
|
||||
// server's window once its lease is over. Monolith keeps its renderer.
|
||||
if (MG_Config::Transport != MG_Config::TransportMode::Monolith && pVulkanRenderer != nullptr) {
|
||||
BumpRendererGeneration();
|
||||
pVulkanRenderer.reset();
|
||||
ClearProgramResourceCaches();
|
||||
}
|
||||
// And the swap interval it asked for (DirectVulkan.h).
|
||||
if (MG_Config::Transport != MG_Config::TransportMode::Monolith) {
|
||||
ForgetRequestedSwapInterval();
|
||||
}
|
||||
}
|
||||
#else
|
||||
BackendObject_DirectVulkan::~BackendObject_DirectVulkan() = default;
|
||||
#endif
|
||||
|
||||
BackendObject_DirectVulkan::BackendObject_DirectVulkan() : m_rendererInfo{GetRendererIdentity()} {}
|
||||
|
||||
@@ -367,9 +345,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// Any renderer instance this assignment replaces is destroyed here;
|
||||
// fence/timer-query handles stamped with the old generation go stale.
|
||||
BumpRendererGeneration();
|
||||
VulkanRendererConfig config;
|
||||
config.SwapInterval = GetRequestedSwapInterval();
|
||||
pVulkanRenderer = MakeUnique<MG_Backend::DirectVulkan::VulkanRenderer>(nativeWindow, config);
|
||||
pVulkanRenderer = MakeUnique<MG_Backend::DirectVulkan::VulkanRenderer>(nativeWindow);
|
||||
MOBILEGL_ASSERT(pVulkanRenderer != nullptr, "InitWindowSurface: VulkanRenderer creation failed");
|
||||
pVulkanRenderer->Initialize();
|
||||
return true;
|
||||
@@ -391,15 +367,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
void BackendObject_DirectVulkan::Initialize() {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
VkBufferManager::RegisterWireResourceOps();
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// P7 wave 2 package C (CONTRACT-P7 §5.5). BESIDE the resource ops and for the same
|
||||
// reason: this is the one place both Magma server roles pass through - the inproc
|
||||
// role and the spawn/TCP session child - and ServerLoop::CreateBackend calls it at
|
||||
// step 1 of InitServerRoleCommon, before the client session exists and therefore
|
||||
// before any frontend object can die unheard. A per-transport install is how one of
|
||||
// the two roles ends up without it.
|
||||
InstallStateObjectDeathOps();
|
||||
#endif
|
||||
#endif
|
||||
m_initialized = true;
|
||||
}
|
||||
@@ -492,12 +459,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
return BackendObject::SwapEGLBuffers(dpy, draw);
|
||||
}
|
||||
|
||||
void BackendObject_DirectVulkan::SetEGLSwapInterval(Int interval) {
|
||||
// Same lock as SwapEGLBuffers: the renderer reads the request in Present.
|
||||
const std::lock_guard<std::recursive_mutex> lock(m_eglStateMutex);
|
||||
BackendObject::SetEGLSwapInterval(interval);
|
||||
}
|
||||
|
||||
void BackendObject_DirectVulkan::ReleaseEGLSurface(EGLSurface surface) {
|
||||
const std::lock_guard<std::recursive_mutex> lock(m_eglStateMutex);
|
||||
BackendObject::ReleaseEGLSurface(surface);
|
||||
@@ -659,38 +620,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// Advertised with GL_NUM_PROGRAM_BINARY_FORMATS = 0, which the
|
||||
// extension explicitly permits. It is also the only thing that
|
||||
// exposes glProgramParameteri before GL 4.1.
|
||||
E_GL_ARB_get_program_binary,
|
||||
// kwin_wayland 6.7.3 will not use a context it cannot drive, and it asks for these
|
||||
// three names first: EglContext::checkSupported() (src/opengl/eglcontext.cpp) takes the
|
||||
// DESKTOP-OpenGL branch for every context whose GL_VERSION is not an "OpenGL ES"
|
||||
// string, and that branch requires GL_ARB_shader_objects, GL_ARB_fragment_shader and
|
||||
// GL_ARB_vertex_shader. GL_VERSION here is "4.6.0 MobileGL ...", so with the names
|
||||
// missing checkSupported() answered false, EglContext::create() returned nullptr,
|
||||
// EglBackend::createContext() returned false, and kwin printed "Could not initialize
|
||||
// rendering context" and quit before drawing a frame.
|
||||
//
|
||||
// The three are true statements about this backend too, and the entry points behind
|
||||
// them are the same ones the DirectGLES half of this list is advertised with: the
|
||||
// frontend implements all 39 ARB_shader_objects procedures, ARB_vertex_shader's three
|
||||
// attrib-location entry points, and nothing for ARB_fragment_shader, whose "New
|
||||
// Procedures and Functions" section reads "None". The shader and program objects live in
|
||||
// MG_Impl/MG_State, above the backend that draws with them, so a name that is true on
|
||||
// one backend is true on the other.
|
||||
E_GL_ARB_shader_objects, E_GL_ARB_vertex_shader, E_GL_ARB_fragment_shader,
|
||||
// NPOT textures: Vulkan puts no power-of-two restriction on an image, its mip chain or
|
||||
// its samplers, so this is the strongest form of the promise the string makes. Kept
|
||||
// identical to the DirectGLES group so the two backends do not disagree about what
|
||||
// MobileGL is.
|
||||
E_GL_ARB_texture_non_power_of_two,
|
||||
// GL_OES_EGL_image: the entry points are real (MG_Impl/GLImpl/Exporting/Definitions.cpp)
|
||||
// and this name is what makes them reachable - libepoxy in kwin resolves
|
||||
// glEGLImageTargetTexture2DOES BY NAME and refuses the import path without it, printing
|
||||
// "No provider of glEGLImageTargetTexture2DOES found. Requires one of: GL_OES_EGL_image".
|
||||
// That import path is how the compositor's scene reaches the display daemon's dma-bufs.
|
||||
// The render-server half of the import (fd over the GBM socket, then the server-side
|
||||
// EGLImage) is the next change; until it lands an imported texture has no storage behind
|
||||
// it, which is logged once at the entry point rather than left to look like a black frame.
|
||||
E_GL_OES_EGL_image};
|
||||
E_GL_ARB_get_program_binary};
|
||||
// Vulkan's drawIndirectFirstInstance feature is optional. Direct base-instance calls work
|
||||
// without it, but ARB_base_instance also promises non-zero firstInstance in GPU indirect
|
||||
// commands; the renderer supplies true only when that word is legal and gl_InstanceID can
|
||||
@@ -770,7 +700,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
static Bool funcsTableInitialized = false;
|
||||
if (!funcsTableInitialized) {
|
||||
funcsTable.Present = Present;
|
||||
funcsTable.SetSwapInterval = SetSwapInterval;
|
||||
funcsTable.GL.DrawArrays = DrawArrays;
|
||||
funcsTable.GL.DrawElements = DrawElements;
|
||||
funcsTable.GL.DrawElementsBaseVertex = DrawElementsBaseVertex;
|
||||
|
||||
@@ -34,7 +34,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
Bool CreateEGLPbufferSurface(EGLSurface surface, EGLint width, EGLint height) override;
|
||||
Bool MakeEGLCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) override;
|
||||
Bool SwapEGLBuffers(EGLDisplay dpy, EGLSurface draw) override;
|
||||
void SetEGLSwapInterval(Int interval) override;
|
||||
void ReleaseEGLSurface(EGLSurface surface) override;
|
||||
void ReleaseEGLResources() override;
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Backend/DirectVulkan/DescriptorPoolCensus.h
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// A count of Magma's per-frame descriptor pools and the sets they hold (UniformManager), for
|
||||
// tests. Dependency-free on purpose: the integration scenarios include it next to the system GL
|
||||
// headers. They link the static library on desktop; the shipping shared library is built with
|
||||
// hidden visibility, so on Android nothing outside the library can call GetDescriptorPoolCensus.
|
||||
struct DescriptorPoolCensus {
|
||||
bool available = false; // false when no Magma renderer is live (e.g. the DirectGLES backend)
|
||||
uint32_t frameSlots = 0;
|
||||
uint32_t pools = 0; // descriptor pools across every frame slot
|
||||
uint32_t maxPoolsInOneSlot = 0;
|
||||
uint64_t capacitySets = 0; // sum of maxSets over those pools
|
||||
uint64_t cachedSets = 0; // sets allocated from them and held in the per-layout caches
|
||||
uint64_t slotTrims = 0; // whole-slot trims since the renderer came up
|
||||
};
|
||||
|
||||
DescriptorPoolCensus GetDescriptorPoolCensus();
|
||||
} // namespace MobileGL::MG_Backend::DirectVulkan
|
||||
@@ -21,13 +21,6 @@
|
||||
#include <Config.h>
|
||||
#include <MG_Remote/Server/ServerLoop.h>
|
||||
#include <MG_Pipe/PipeApply.h>
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// P7 wave 2 package C (CONTRACT-P7 §5.5): Magma's own death-notice table. Both headers are
|
||||
// push-only and reached here for the same reason DirectGLES/Managers.cpp reaches them - the
|
||||
// notice is declared by the frontend and answered by whichever backend is running.
|
||||
#include <MG_Remote/Client/WireTables.h>
|
||||
#include <MG_State/GLState/StateObjectDeathNotice.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <atomic>
|
||||
#include <bit>
|
||||
@@ -62,66 +55,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
std::atomic<Uint64> g_rendererGeneration{1};
|
||||
} // namespace
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED && MOBILEGL_PIPE_PUSH
|
||||
namespace {
|
||||
// P7 wave 2 package C, CONTRACT-P7 §5.5: MAGMA'S MIRROR OF g_glesStateObjectDeathOps
|
||||
// (DirectGLES/Managers.cpp:335), and the one arm of that table Magma has any work in.
|
||||
//
|
||||
// WHAT THE NOTICE IS FOR HERE, and it is not what it is for on Espryt. Espryt's arm
|
||||
// destroys a BACKEND TWIN keyed by lifetime id; Magma keeps no such twin - its two
|
||||
// client-minted kinds (VertexElementsCso, Buffer) are keyed on {slot, gen} by
|
||||
// MagmaPipeIdentityTables and every other kind is still reached from its frontend
|
||||
// object. So the switch Espryt runs under `#else` has nothing to do on this backend
|
||||
// and this table is exactly the EMIT arm: with a transport up and off the apply
|
||||
// thread, the death crosses as the `object_death` record
|
||||
// (MG_Remote::Client::EmitObjectDeathRecord, CONTRACT-P5C §5.2).
|
||||
//
|
||||
// WHY THAT MATTERS, measured rather than argued (package L's probe,
|
||||
// notes/p7/magma-two-process-first-run.md §6): under SPAWN the client process has no
|
||||
// DirectVulkan backend at all, so InstallClientWireTables' own emitter already
|
||||
// answered the notice and CtWireScenario's two death cases PASSED. Under INPROC the
|
||||
// server role's backend is a thread of this process, Transport is Split rather than
|
||||
// Spawn, and WireTables' install condition deliberately stands aside for "the
|
||||
// backend's own dispatcher" - which on Magma did not exist. Both cases therefore
|
||||
// FAILED on inproc with `deaths` stuck at 0. This table is that dispatcher.
|
||||
//
|
||||
// FRAMEBUFFER IS WHY THE GAP WAS NOT MERELY COSMETIC. The client-side SLOT is freed
|
||||
// backend-neutrally by P4a's per-kind helpers (MG_Impl/Pipe/PipeFill.cpp's
|
||||
// NotifyAndFree frees whatever the notice does), so PipeSlotPeek never saw a leak.
|
||||
// What leaked was the SERVER's twin: a framebuffer has NO wire delete opcode at all
|
||||
// (BRIEF-P4A D-I2), so `object_death` is its only death delivery, and without a
|
||||
// consumer here the server's record stayed Live for the life of the session.
|
||||
void OnMagmaFrontendStateObjectDestroyed(MG_Pipe::MGPipeKind kind, Uint64 lifetimeId) {
|
||||
// Monolith has no record to emit and no server twin to tell.
|
||||
if (MG_Config::Transport == MG_Config::TransportMode::Monolith) return;
|
||||
// Raised ON the apply thread: the server role destroying a frontend object it
|
||||
// created itself (Magma's hidden blit / depth-mipmap resources). The client's
|
||||
// allocator is a client-thread surface (CONTRACT-P5C §3.1) and EmitObjectDeathRecord
|
||||
// probes it, so this arm stays silent exactly as Espryt's does.
|
||||
if (MG_Remote::Server::ServerLoop::OnApplyThread()) return;
|
||||
(void)MG_Remote::Client::EmitObjectDeathRecord(kind, lifetimeId);
|
||||
}
|
||||
|
||||
const MG_State::GLState::StateObjectDeathOps g_magmaStateObjectDeathOps = {
|
||||
.OnDestroyed = OnMagmaFrontendStateObjectDestroyed,
|
||||
};
|
||||
} // namespace
|
||||
|
||||
void InstallStateObjectDeathOps() {
|
||||
// Installed from BackendObject_DirectVulkan::Initialize(), i.e. step 1 of
|
||||
// InitServerRoleCommon (ServerLoop::CreateBackend calls Initialize), which is before
|
||||
// the client session starts and therefore before any frontend object can die.
|
||||
// Unconditional, exactly as Espryt's ResolveEsprytSlotTablesArm is: only one backend
|
||||
// is live at a time, and InstallClientWireTables' own "whoever installed first keeps
|
||||
// the notice" guard is what keeps the remote client from stomping this.
|
||||
MG_State::GLState::SetStateObjectDeathOps(&g_magmaStateObjectDeathOps);
|
||||
}
|
||||
|
||||
Bool StateObjectDeathOpsInstalled() {
|
||||
return MG_State::GLState::GetStateObjectDeathOps() == &g_magmaStateObjectDeathOps;
|
||||
}
|
||||
#endif // MOBILEGL_BUILD_DISAGGREGATED && MOBILEGL_PIPE_PUSH
|
||||
|
||||
Uint64 GetRendererGeneration() {
|
||||
return g_rendererGeneration.load(std::memory_order_acquire);
|
||||
}
|
||||
@@ -131,21 +64,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
}
|
||||
|
||||
namespace {
|
||||
#if !MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P7 wave 2 package C, OQ-8: THE PULL BUILD'S HALF, VERBATIM. A disaggregated build
|
||||
// answers GetShaderStorageBlock{Index,Binding} out of LinkArtifacts::storageBlocks
|
||||
// instead (see those functions below), which retires this whole cache - the map, the
|
||||
// SPIRV-Reflect rebuild, the teardown clear and the rehash hazard. It cannot be
|
||||
// retired HERE because the archive member it reads is itself disaggregated-only, for
|
||||
// G1: one more Vector in LinkArtifacts moves the pull build's .text, which is pinned
|
||||
// byte-for-byte at 0xa52203.
|
||||
//
|
||||
// NOTHING OUTSIDE THIS FILE READS ANY OF IT (measured: BufferVariableResource,
|
||||
// bufferVariables, activeVariables and StorageBlockResource have no reference anywhere
|
||||
// else in the tree, and `dataSize` is written and never read - GL_BUFFER_VARIABLE and
|
||||
// GL_ACTIVE_VARIABLES are answered by MG_Impl/GLImpl/Program/ProgramInterface.cpp out
|
||||
// of glslang's own reflection, which is a different index space). So the two arms
|
||||
// below differ in exactly the two functions their callers use, and in nothing else.
|
||||
struct BufferVariableResource {
|
||||
String name;
|
||||
GLuint blockIndex = 0;
|
||||
@@ -177,7 +95,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
Vector<StorageBlockResource> storageBlocks;
|
||||
Vector<BufferVariableResource> bufferVariables;
|
||||
};
|
||||
#endif // !MOBILEGL_BUILD_DISAGGREGATED
|
||||
|
||||
struct DrawElementsIndirectCommand {
|
||||
Uint32 count = 0;
|
||||
@@ -194,14 +111,12 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
Uint32 baseInstance = 0;
|
||||
};
|
||||
|
||||
#if !MOBILEGL_BUILD_DISAGGREGATED
|
||||
// Keyed by GL program name so the freed-name reuse in IndexGenerator bounds the
|
||||
// map at the peak-simultaneous-program high-water mark; each slot's ownership is
|
||||
// checked against the program's lifetime id before it is served (see
|
||||
// GetProgramResourceCache). Cleared wholesale at EGL teardown via
|
||||
// ClearProgramResourceCaches.
|
||||
UnorderedMap<GLuint, ProgramResourceCache> g_programResourceCaches;
|
||||
#endif
|
||||
|
||||
void ClearReadPixelsOutput(GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels) {
|
||||
if (!pixels || width <= 0 || height <= 0) {
|
||||
@@ -216,7 +131,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
}
|
||||
}
|
||||
|
||||
#if !MOBILEGL_BUILD_DISAGGREGATED
|
||||
String NormalizeDescriptorName(const SpvReflectDescriptorBinding& binding) {
|
||||
const char* rawName = binding.name;
|
||||
if (binding.type_description != nullptr && binding.type_description->type_name != nullptr) {
|
||||
@@ -367,39 +281,18 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
#endif // !MOBILEGL_BUILD_DISAGGREGATED
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// The verb's handles identify server stores; never inspect a client binding.
|
||||
//
|
||||
// P8-D: THE GPU READS THE WORDS (VulkanRenderer::DrawWireIndirectNative, WireDraw.inc), as
|
||||
// on the monolith arm. The CPU expansion below is kept for the one shape the monolith arm
|
||||
// also expands - a COUNT form the device cannot issue natively (no VK_KHR_draw_indirect_count,
|
||||
// or maxdrawcount > 1 without multiDrawIndirect: VulkanRenderer.cpp's
|
||||
// MultiDrawElementsIndirectCount) - where ReadWireBuffer orders GPU-produced command/count
|
||||
// bytes before the expansion.
|
||||
// The verb's handles identify server stores. Readback orders GPU-produced
|
||||
// command/count bytes before CPU tier expansion; never inspect a client binding.
|
||||
void DrawWireIndirect(GLenum mode, GLenum type, const void* indirect, GLsizei drawcount,
|
||||
GLsizei stride, Bool indexed, Bool counted = false, GLintptr countOffset = 0) {
|
||||
if (drawcount <= 0 || countOffset < 0) return;
|
||||
if (pVulkanRenderer->DrawWireIndirectNative(mode, type, reinterpret_cast<Uint64>(indirect), drawcount,
|
||||
stride, indexed, counted, static_cast<Uint64>(countOffset)))
|
||||
return;
|
||||
if (drawcount <= 0) return;
|
||||
auto& buffers = pVulkanRenderer->GetWireBufferManager();
|
||||
const auto& state = MG_Pipe::MGPipeApplier();
|
||||
// P8-D: this call reads its words on the CPU; the waits those reads take are its own.
|
||||
struct ExpansionCount {
|
||||
VkBufferManager& buffers;
|
||||
const Uint64 waitsBefore = buffers.GetWireHostWaitCount();
|
||||
~ExpansionCount() {
|
||||
if (!MG_Util::PipeStats::Enabled()) return;
|
||||
MG_Util::PipeStats::AddCalls(MG_Util::PipeStats::CallClass::WireIndirectCpuExpansions, 1);
|
||||
MG_Util::PipeStats::AddCalls(MG_Util::PipeStats::CallClass::WireHostWaitsIndirect,
|
||||
buffers.GetWireHostWaitCount() - waitsBefore);
|
||||
}
|
||||
} expansionCount{buffers};
|
||||
if (counted) {
|
||||
Uint32 count = 0;
|
||||
if (!buffers.ReadWireBuffer(state.VerbIndirectParameterBuffer,
|
||||
if (countOffset < 0 || !buffers.ReadWireBuffer(state.VerbIndirectParameterBuffer,
|
||||
static_cast<Uint64>(countOffset), sizeof(count), &count)) return;
|
||||
drawcount = static_cast<GLsizei>(std::min<Uint32>(count, static_cast<Uint32>(drawcount)));
|
||||
if (!drawcount) return;
|
||||
@@ -488,67 +381,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
|
||||
} // namespace
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P7 wave 2 package C, OQ-8 (CONTRACT-P7 §5.3): THE MONOLITH CONSUMER READS THE ARCHIVE
|
||||
// TOO, so one published list serves both of this backend's arms.
|
||||
//
|
||||
// THE TWO ARMS BELOW ARE NOT TWO ANSWERS. ProgramTest's
|
||||
// TheArchivesStorageBlockOrderIsTheOneSpirvReflectProduces runs the OLD arm's algorithm -
|
||||
// SPIRV-Reflect over the real modules, sorted and deduplicated exactly as
|
||||
// GetProgramResourceCache does it - over a multi-stage program with an arrayed SSBO and an
|
||||
// atomic-counter block, and asserts element-for-element equality with what the archive
|
||||
// published. That equivalence is what makes an #if here a build-time SELECTION rather than
|
||||
// a behavioural fork, and it is the reason the case exists.
|
||||
//
|
||||
// WHY AN #if AT ALL, AND WHAT IT COSTS. LinkArtifacts::storageBlocks is
|
||||
// MOBILEGL_BUILD_DISAGGREGATED-only, because one more Vector member changes the struct's
|
||||
// size, its implicit destructor and its move constructor in the PULL build whose .text G1
|
||||
// pins byte-for-byte (0xa52203). So the pull build keeps `g_programResourceCaches`, the
|
||||
// SPIRV-Reflect rebuild and `ClearProgramResourceCaches`, verbatim; only this build drops
|
||||
// them - and with them the rehash hazard the ordering comment below the block-binding
|
||||
// setter documents. Retiring the pull half is the day the member stops needing its guard,
|
||||
// which is a G1/P13 decision and not a wave-2 one; recorded in notes/p7/magma-c.md.
|
||||
void ClearProgramResourceCaches() {
|
||||
// Nothing to clear: there is no cache in this build. Kept as an entry point so
|
||||
// BackendObject_DirectVulkan's two EGL-teardown call sites stay statement for
|
||||
// statement what they are in the pull build.
|
||||
}
|
||||
|
||||
GLuint GetShaderStorageBlockIndex(const MG_State::GLState::ProgramObject& program, const String& name) {
|
||||
const auto& blocks = program.GetLinkReflection().storageBlocks;
|
||||
const auto find = [&blocks](const String& key) {
|
||||
return std::find_if(blocks.begin(), blocks.end(),
|
||||
[&](const MG_State::GLState::StorageBlockReflection& block) { return block.name == key; });
|
||||
};
|
||||
auto it = find(name);
|
||||
if (it == blocks.end()) {
|
||||
// Archive names are normalised, so an arrayed block that GL enumerates per element
|
||||
// - "B[0]", "B[1]" - is one entry here, spelled "B". Same second chance the cache
|
||||
// gave, for the same callers.
|
||||
const auto bracket = name.rfind('[');
|
||||
if (bracket == String::npos || name.empty() || name.back() != ']') return GL_INVALID_INDEX;
|
||||
it = find(name.substr(0, bracket));
|
||||
if (it == blocks.end()) return GL_INVALID_INDEX;
|
||||
}
|
||||
return static_cast<GLuint>(std::distance(blocks.begin(), it));
|
||||
}
|
||||
|
||||
GLuint GetShaderStorageBlockBinding(const MG_State::GLState::ProgramObject& program, GLuint blockIndex) {
|
||||
const auto& blocks = program.GetLinkReflection().storageBlocks;
|
||||
if (blockIndex >= blocks.size()) {
|
||||
return 0;
|
||||
}
|
||||
// THE OVERRIDE IS APPLIED ON READ, where the cache used to apply it on rebuild and
|
||||
// patch it in place on rebind. Same answer by a shorter route: the program is the
|
||||
// authoritative record of a rebound block (it is what GL_BUFFER_BINDING reports), the
|
||||
// archive carries the DECLARED binding only, and asking the program here means a
|
||||
// rebind can no longer be lost to a cache rebuild that happened to race a state-version
|
||||
// bump.
|
||||
const Int rebound = program.GetShaderStorageBlockBindingOverride(blocks[blockIndex].name);
|
||||
if (rebound >= 0) return static_cast<GLuint>(rebound);
|
||||
return blocks[blockIndex].binding;
|
||||
}
|
||||
#else
|
||||
void ClearProgramResourceCaches() {
|
||||
// Called from EGL teardown while the backend's m_eglStateMutex is held; GL
|
||||
// calls are serialized in this codebase (contexts migrate threads but never
|
||||
@@ -584,7 +416,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
}
|
||||
return cache.storageBlocks[blockIndex].binding;
|
||||
}
|
||||
#endif
|
||||
|
||||
void ClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil) {
|
||||
MOBILEGL_ASSERT(pVulkanRenderer, "DirectVulkan::ClearBufferfi called with null VulkanRenderer");
|
||||
@@ -937,12 +768,12 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
|
||||
void DispatchComputeIndirect(GLintptr indirect) {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P8-SV: THE GPU READS THE GROUP COUNTS on the wire arm too - VulkanRenderer's
|
||||
// DispatchComputeIndirect takes its transport branch into DispatchWireComputeIndirect
|
||||
// (WireDraw.inc), which issues vkCmdDispatchIndirect from the verb's store. The CPU read
|
||||
// that was here (ReadWireBuffer, a whole-GPU wait once a shader had written the store) is gone.
|
||||
if (MG_Config::Transport != MG_Config::TransportMode::Monolith) {
|
||||
pVulkanRenderer->DispatchComputeIndirect(indirect);
|
||||
Uint32 groups[3]{};
|
||||
if (indirect >= 0 && pVulkanRenderer->GetWireBufferManager().ReadWireBuffer(
|
||||
MG_Pipe::MGPipeApplier().VerbDispatchIndirectBuffer,
|
||||
static_cast<Uint64>(indirect), sizeof(groups), groups))
|
||||
pVulkanRenderer->DispatchCompute(groups[0], groups[1], groups[2]);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@@ -1051,27 +882,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
MakeUnique<GenericErrorInfo>("DirectVulkan", __func__, "Shader storage binding is out of range."));
|
||||
return;
|
||||
}
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P7 wave 2 package C, OQ-8: NOTHING LEFT TO PATCH, and the hazard goes with it.
|
||||
//
|
||||
// The frontend has already recorded the new binding on the program, and that record is
|
||||
// now what GetShaderStorageBlockBinding reads (it asks
|
||||
// GetShaderStorageBlockBindingOverride on every call, over an IMMUTABLE archive list).
|
||||
// What stood here was the other half of a mutable cache: resolve the index, take a
|
||||
// reference into g_programResourceCaches and patch `binding` in place so an
|
||||
// already-built entry need not be thrown away.
|
||||
//
|
||||
// THE HAZARD THAT CAME WITH IT IS GONE TOO, and it is worth naming because it was a
|
||||
// real crash rather than a theoretical one: GetShaderStorageBlockIndex re-entered
|
||||
// GetProgramResourceCache, which indexes an OPEN-ADDRESSED map and can therefore
|
||||
// insert, and a rehash moves entries - so a reference taken before that call dangled.
|
||||
// Binding one program's storage block while another program's entry was still absent
|
||||
// from the cache was a reproducible segfault (ProgramPipelineScenario's two
|
||||
// storage-block cases, in one process). The ordering above was the fix; having no
|
||||
// cache is the retirement. The pull build below keeps both.
|
||||
(void)storageBlockBinding;
|
||||
}
|
||||
#else
|
||||
// The frontend already validated that the name denotes an active block, and has
|
||||
// already recorded the new binding on the program - which is what reseeds this cache
|
||||
// whenever it is rebuilt. Writing the entry here as well keeps an ALREADY-BUILT cache
|
||||
@@ -1090,7 +900,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
if (blockIndex >= cache.storageBlocks.size()) return;
|
||||
cache.storageBlocks[blockIndex].binding = storageBlockBinding;
|
||||
}
|
||||
#endif
|
||||
void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels) {
|
||||
MOBILEGL_ASSERT(pVulkanRenderer, "DirectVulkan::ReadPixels called with null VulkanRenderer");
|
||||
MOBILEGL_ASSERT(MGB_CTX_LIVE, "DirectVulkan::ReadPixels called with null GL context");
|
||||
@@ -1761,52 +1570,4 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
MG_Util::PipeStats::OnPresent();
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
Optional<Int> g_requestedSwapInterval;
|
||||
} // namespace
|
||||
|
||||
void SetSwapInterval(Int interval) {
|
||||
g_requestedSwapInterval = interval;
|
||||
if (pVulkanRenderer) {
|
||||
pVulkanRenderer->SetSwapInterval(interval);
|
||||
}
|
||||
}
|
||||
|
||||
Optional<Int> GetRequestedSwapInterval() {
|
||||
return g_requestedSwapInterval;
|
||||
}
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
void ForgetRequestedSwapInterval() {
|
||||
g_requestedSwapInterval.reset();
|
||||
}
|
||||
#endif
|
||||
|
||||
DescriptorPoolCensus GetDescriptorPoolCensus() {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P11 M2: UNDER A TRANSPORT THE POOLS ARE THE SERVER RENDERER'S, and its apply thread
|
||||
// grows, rewinds and trims them while the test thread would be reading - a census taken
|
||||
// after a swap the client ran ahead of, or mid-burst, walks a set cache BeginFrame may be
|
||||
// clearing. Inproc, the server is a thread of this process: the read is posted to it as
|
||||
// the test probe, which runs between drain batches, so it sees every record published
|
||||
// before it and none half-applied - without waiting on the GPU, which is the point of the
|
||||
// trim case (it gives a burst back with other slots' work in flight). Spawn and tcp keep
|
||||
// their pools in another process; the client has no renderer and answers unavailable.
|
||||
if (MG_Config::Transport != MG_Config::TransportMode::Monolith &&
|
||||
!MG_Remote::Server::ServerLoop::OnApplyThread()) {
|
||||
if (MG_Config::Transport != MG_Config::TransportMode::InProcess) return DescriptorPoolCensus{};
|
||||
DescriptorPoolCensus census{};
|
||||
const MobileGLResult result = MG_Remote::Server::ServerLoopInstance().RunProbeOnApplyThreadForTesting(
|
||||
+[](void* user) -> MobileGLResult {
|
||||
*static_cast<DescriptorPoolCensus*>(user) =
|
||||
pVulkanRenderer ? pVulkanRenderer->GetDescriptorPoolCensus() : DescriptorPoolCensus{};
|
||||
return MOBILEGL_OK;
|
||||
},
|
||||
&census);
|
||||
return result == MOBILEGL_OK ? census : DescriptorPoolCensus{};
|
||||
}
|
||||
#endif
|
||||
return pVulkanRenderer ? pVulkanRenderer->GetDescriptorPoolCensus() : DescriptorPoolCensus{};
|
||||
}
|
||||
} // namespace MobileGL::MG_Backend::DirectVulkan
|
||||
|
||||
@@ -23,18 +23,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
Uint64 GetRendererGeneration();
|
||||
void BumpRendererGeneration();
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED && MOBILEGL_PIPE_PUSH
|
||||
// P7 wave 2 package C (CONTRACT-P7 §5.5). Magma's StateObjectDeathOps table, installed
|
||||
// from BackendObject_DirectVulkan::Initialize() so that GetStateObjectDeathOps() is
|
||||
// non-null on every Magma role that owns a backend. See the definition for what the one
|
||||
// arm does and for the inproc gap it closes. Push-only and disaggregated-only: a pull
|
||||
// build declares no notice at all (StateObjectDeathNotice.h) and has nothing to emit.
|
||||
void InstallStateObjectDeathOps();
|
||||
// True when the notice currently installed is this backend's. Read by MG_Test so the
|
||||
// install can be asserted without a death having to happen first.
|
||||
Bool StateObjectDeathOpsInstalled();
|
||||
#endif
|
||||
|
||||
// Drops every cached program-resource reflection entry (CPU-side strings/vectors
|
||||
// only, no Vulkan handles). Called at EGL teardown next to the renderer reset;
|
||||
// safe because GL calls are serialized in this codebase, and any still-live
|
||||
@@ -147,14 +135,4 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// only exist as vkCmdWriteTimestamp results); the frontend falls back.
|
||||
Int64 GetGpuTimestampNs();
|
||||
void Present();
|
||||
// eglSwapInterval. Remembered across renderers: one created for a later window surface
|
||||
// starts from the app's last request (GetRequestedSwapInterval) instead of the default.
|
||||
void SetSwapInterval(Int interval);
|
||||
Optional<Int> GetRequestedSwapInterval();
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// The swap interval an ended server session asked for is not the next one's, the same rule as
|
||||
// DirectGLES::ForgetRequestedSwapInterval: under a transport ~BackendObject_DirectVulkan forgets
|
||||
// it, so the next session starts at the default until it asks.
|
||||
void ForgetRequestedSwapInterval();
|
||||
#endif
|
||||
} // namespace MobileGL::MG_Backend::DirectVulkan
|
||||
|
||||
@@ -307,10 +307,8 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
if (result != VK_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
// Under disaggregation VulkanRenderer waits every registered fence
|
||||
// through this slot's last submit before calling here. That aggregate
|
||||
// proof covers mid-frame pooled-fence flushes too; the slot fence alone
|
||||
// would not. Initialize's first acquire has no prior submissions.
|
||||
// The slot's fence has been waited: every command buffer this slot
|
||||
// submitted (including mid-frame flushes) has finished executing.
|
||||
FreeRetiredCommandBuffers(frame);
|
||||
|
||||
result = vkAcquireNextImageKHR(device, swapchain, timeout, frame.imageAvailableSemaphore, acquireFence,
|
||||
|
||||
@@ -166,17 +166,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// WHAT IT DOES NOT COVER, AND WHY NO REPRODUCER OF THIS SHAPE CAN [fix-aba review v1,
|
||||
// MAJOR 1]. It does NOT exercise the GENERATION half of {slot, gen}:
|
||||
//
|
||||
// * THIS MINT still has no death notification, and that is now a narrower statement than
|
||||
// it was. P7 wave 2 package C gives DirectVulkan a StateObjectDeathOps table
|
||||
// (DirectVulkan.cpp's g_magmaStateObjectDeathOps, CONTRACT-P7 §5.5), so
|
||||
// NotifyStateObjectDestroyed DOES have a consumer on this backend - but that consumer's
|
||||
// one job is to emit the `object_death` RECORD so the server drops its twin, and it
|
||||
// never touches these per-renderer identity tables: they are the SERVER-side renderer's
|
||||
// own, the notice is raised on the CLIENT thread, and an Acquire/retire from the wrong
|
||||
// side is precisely the cross-role read CONTRACT-P5C §3.1 forbids. So a slot here still
|
||||
// returns to the free list only through OnFrameBoundary's age sweep (kSweepInterval
|
||||
// 256, kRetireAgeBoundaries 1024, below), and everything the two bullets below derive
|
||||
// from that is unchanged;
|
||||
// * this mint has no death notification - nothing in MG_Backend/DirectVulkan consumes
|
||||
// NotifyStateObjectDestroyed - so a slot returns to the free list only through
|
||||
// OnFrameBoundary's age sweep (kSweepInterval 256, kRetireAgeBoundaries 1024, below);
|
||||
// * HandleRecycleScenario issues five frame boundaries, so the free list is empty when
|
||||
// the replacement VAO acquires and it gets a BRAND-NEW slot at Gen 1 (measured:
|
||||
// redVao slot=2 gen=1, greenVao slot=3 gen=1). The knob-off FRESH verdict there is
|
||||
|
||||
@@ -7,11 +7,7 @@
|
||||
#include <MG_Pipe/PipeApply.h>
|
||||
#include <MG_State/GLState/ProgramState/ProgramArtifactsCodec.h>
|
||||
#include "../DirectVulkanResourceState.h"
|
||||
// P7 wave 2 package C, OQ-8: spirv_reflect.h is GONE from this header, and its absence is the
|
||||
// gate. Everything this class needed it for - the storage-block index space - now travels in
|
||||
// the archive (LinkArtifacts::storageBlocks), so the SPIR-V reflector is off the Magma wire
|
||||
// draw path entirely. A future edit that re-adds the include is re-adding a per-draw reflect,
|
||||
// because a MagmaProgramSource is constructed once per draw and can memoise nothing.
|
||||
#include <spirv_reflect.h>
|
||||
#endif
|
||||
|
||||
namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
@@ -157,49 +153,30 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
GLenum GetTransformFeedbackBufferMode() const {
|
||||
return IsWire() ? Link().xfbBufferMode : m_frontend->GetTransformFeedbackBufferMode();
|
||||
}
|
||||
// P7 wave 2 package C, OQ-8 (CONTRACT-P7 §5.3): READ OUT OF THE ARCHIVE.
|
||||
//
|
||||
// What stood here re-ran spvReflectCreateShaderModule over EVERY stage module of the
|
||||
// program, and it did so PER DRAW: a MagmaProgramSource is a borrowed view that
|
||||
// WireDraw.inc's WireProgramSource constructs afresh for each wire draw, so the lazy
|
||||
// `m_storageBlocksReady` latch could never outlive one. The list it rebuilt is a pure
|
||||
// function of the linked program, so it is now built once at link time and travels in
|
||||
// the archive (LinkArtifacts::storageBlocks), which takes the SPIR-V reflector off the
|
||||
// wire draw path entirely - this header no longer includes spirv_reflect.h at all.
|
||||
Uint GetShaderStorageBlockIndex(const String& name) const {
|
||||
if (!IsWire()) return DirectVulkan::GetShaderStorageBlockIndex(*m_frontend, name);
|
||||
const auto& blocks = Link().storageBlocks;
|
||||
// The archive carries NORMALISED names (the array subscript stripped), because
|
||||
// that is the spelling SPIRV-Reflect's type_name gives and the spelling
|
||||
// ProgramFactory::ReflectLayout looks up. A caller that still holds a GL-style
|
||||
// "Foo[2]" gets the same second chance it always had.
|
||||
const auto find = [&blocks](const String& key) {
|
||||
return std::find_if(blocks.begin(), blocks.end(),
|
||||
[&](const MG_State::GLState::StorageBlockReflection& block) {
|
||||
return block.name == key;
|
||||
});
|
||||
EnsureStorageBlocks();
|
||||
String key = name;
|
||||
auto find = [&] {
|
||||
return std::find_if(m_storageBlocks.begin(), m_storageBlocks.end(),
|
||||
[&](const StorageBlock& block) { return block.Name == key; });
|
||||
};
|
||||
auto found = find(name);
|
||||
if (found == blocks.end() && !name.empty() && name.back() == ']') {
|
||||
auto found = find();
|
||||
if (found == m_storageBlocks.end() && !name.empty() && name.back() == ']') {
|
||||
const auto bracket = name.rfind('[');
|
||||
if (bracket != String::npos) found = find(name.substr(0, bracket));
|
||||
if (bracket != String::npos) { key = name.substr(0, bracket); found = find(); }
|
||||
}
|
||||
return found == blocks.end() ? GL_INVALID_INDEX
|
||||
: static_cast<Uint>(found - blocks.begin());
|
||||
return found == m_storageBlocks.end() ? GL_INVALID_INDEX : static_cast<Uint>(found - m_storageBlocks.begin());
|
||||
}
|
||||
Uint GetShaderStorageBlockBinding(Uint index) const {
|
||||
if (!IsWire()) return DirectVulkan::GetShaderStorageBlockBinding(*m_frontend, index);
|
||||
const auto& blocks = Link().storageBlocks;
|
||||
if (index >= blocks.size()) return 0;
|
||||
const auto& block = blocks[index];
|
||||
// THE OVERRIDE STILL WINS, and it still comes off the RECORD rather than the
|
||||
// archive: glShaderStorageBlockBinding is a post-link mutable and the archive
|
||||
// carries link-time defaults only (rule on MagmaProgramSource, and the reason
|
||||
// StorageBlockReflection::binding is documented as the DECLARED binding).
|
||||
EnsureStorageBlocks();
|
||||
if (index >= m_storageBlocks.size()) return 0;
|
||||
const auto& block = m_storageBlocks[index];
|
||||
for (const auto& override : m_record->StorageOverrides) {
|
||||
if (override.Name == block.name) return override.Binding;
|
||||
if (override.Name == block.Name) return override.Binding;
|
||||
}
|
||||
return block.binding;
|
||||
return block.Binding;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -210,13 +187,48 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
return tIndex >= 0 && static_cast<SizeT>(tIndex) < Link().blockReflection.size()
|
||||
? &Link().blockReflection[tIndex] : nullptr;
|
||||
}
|
||||
struct StorageBlock { String Name; Uint Binding; };
|
||||
void EnsureStorageBlocks() const {
|
||||
if (m_storageBlocksReady) return;
|
||||
m_storageBlocksReady = true;
|
||||
// Match the legacy resource-query index order: stage order, then
|
||||
// normalized descriptor name/binding, deduplicated across stages.
|
||||
for (const auto& spirv : GetGeneratedSpirv()) {
|
||||
if (spirv.empty()) continue;
|
||||
SpvReflectShaderModule module{};
|
||||
if (spvReflectCreateShaderModule(spirv.size() * sizeof(Uint), spirv.data(), &module) != SPV_REFLECT_RESULT_SUCCESS) continue;
|
||||
Uint32 count = 0;
|
||||
if (spvReflectEnumerateDescriptorBindings(&module, &count, nullptr) == SPV_REFLECT_RESULT_SUCCESS) {
|
||||
Vector<SpvReflectDescriptorBinding*> bindings(count);
|
||||
if (spvReflectEnumerateDescriptorBindings(&module, &count, bindings.data()) == SPV_REFLECT_RESULT_SUCCESS) {
|
||||
auto name = [](const SpvReflectDescriptorBinding* binding) {
|
||||
const char* raw = binding->name;
|
||||
if (binding->type_description && binding->type_description->type_name) raw = binding->type_description->type_name;
|
||||
String result = raw ? raw : "";
|
||||
const auto suffix = result.find("[0]");
|
||||
return suffix == String::npos ? result : result.substr(0, suffix);
|
||||
};
|
||||
std::sort(bindings.begin(), bindings.end(), [&](const auto* a, const auto* b) {
|
||||
const String an = a ? name(a) : String(), bn = b ? name(b) : String();
|
||||
return an != bn ? an < bn : (a && b && a->binding < b->binding);
|
||||
});
|
||||
for (const auto* binding : bindings) {
|
||||
if (!binding || binding->descriptor_type != SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_BUFFER) continue;
|
||||
const String key = name(binding);
|
||||
if (key.empty() || std::any_of(m_storageBlocks.begin(), m_storageBlocks.end(),
|
||||
[&](const StorageBlock& block) { return block.Name == key; })) continue;
|
||||
m_storageBlocks.push_back({key, binding->binding});
|
||||
}
|
||||
}
|
||||
}
|
||||
spvReflectDestroyShaderModule(&module);
|
||||
}
|
||||
}
|
||||
const Program* m_frontend = nullptr;
|
||||
MG_Pipe::MGPipeHandle m_handle = MG_Pipe::kMGPipeNullHandle;
|
||||
const MG_Pipe::MGPipeShaderCsoRecord* m_record = nullptr;
|
||||
// P7 OQ-8: the two mutables that memoised the per-draw reflect are gone with it. They
|
||||
// were `mutable` precisely because this class is a borrowed const view - and that is
|
||||
// also why they never helped: a view lives for one draw, so the latch was cold every
|
||||
// time it was read.
|
||||
mutable Bool m_storageBlocksReady = false;
|
||||
mutable Vector<StorageBlock> m_storageBlocks;
|
||||
};
|
||||
#else
|
||||
using MagmaProgramSource = MG_State::GLState::ProgramObject;
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Backend/DirectVulkan/Renderer/SubmitFencePrefix.h
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
|
||||
// Collect every fence in the ordered submission prefix. Waiting on only the last matching
|
||||
// frame-serial record is insufficient: the same serial may have an earlier in-flight submit.
|
||||
template <typename Records, typename Fence>
|
||||
bool CollectSubmitFencePrefix(const Records& records, std::uint64_t submitIndex,
|
||||
Fence nullFence, std::vector<Fence>& fences) {
|
||||
fences.clear();
|
||||
bool foundTarget = false;
|
||||
for (const auto& record : records) {
|
||||
if (record.submitIndex > submitIndex) {
|
||||
break;
|
||||
}
|
||||
if (record.fence == nullFence) {
|
||||
fences.clear();
|
||||
return false;
|
||||
}
|
||||
fences.push_back(record.fence);
|
||||
foundTarget = foundTarget || record.submitIndex == submitIndex;
|
||||
}
|
||||
if (!foundTarget) {
|
||||
fences.clear();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace MobileGL::MG_Backend::DirectVulkan
|
||||
@@ -8,8 +8,6 @@
|
||||
|
||||
#include "SwapchainObject.h"
|
||||
|
||||
#include <span>
|
||||
|
||||
#include "MG_Impl/GLImpl/Framebuffer/GL_Framebuffer.h"
|
||||
#include "MG_State/GLState/TextureState/TextureObject2D.h"
|
||||
|
||||
@@ -142,26 +140,12 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
}
|
||||
|
||||
VkPresentModeKHR SwapchainObject::ChooseSwapchainPresentMode(
|
||||
const Vector<VkPresentModeKHR>& availablePresentModes, Optional<Int> swapInterval) {
|
||||
static constexpr VkPresentModeKHR s_unthrottledPresentModes[]{
|
||||
VK_PRESENT_MODE_IMMEDIATE_KHR, VK_PRESENT_MODE_MAILBOX_KHR, VK_PRESENT_MODE_FIFO_KHR};
|
||||
static constexpr VkPresentModeKHR s_vsyncPresentModes[]{VK_PRESENT_MODE_FIFO_KHR};
|
||||
static constexpr VkPresentModeKHR s_adaptiveVsyncPresentModes[]{VK_PRESENT_MODE_FIFO_RELAXED_KHR,
|
||||
VK_PRESENT_MODE_FIFO_KHR};
|
||||
std::span<const VkPresentModeKHR> ranked = s_desiredPresentModes;
|
||||
if (swapInterval) {
|
||||
if (*swapInterval == 0) {
|
||||
ranked = s_unthrottledPresentModes;
|
||||
} else if (*swapInterval > 0) {
|
||||
ranked = s_vsyncPresentModes;
|
||||
} else {
|
||||
ranked = s_adaptiveVsyncPresentModes;
|
||||
}
|
||||
}
|
||||
for (auto desiredPresentMode : ranked) {
|
||||
if (std::find(availablePresentModes.begin(), availablePresentModes.end(), desiredPresentMode) !=
|
||||
availablePresentModes.end()) {
|
||||
return desiredPresentMode;
|
||||
const Vector<VkPresentModeKHR>& availablePresentModes) {
|
||||
for (auto desiredPresentMode : s_desiredPresentModes) {
|
||||
for (const auto& presentMode : availablePresentModes) {
|
||||
if (presentMode == desiredPresentMode) {
|
||||
return presentMode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,13 +153,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
return availablePresentModes[0];
|
||||
}
|
||||
|
||||
const char* SwapchainObject::GetPresentModeName(VkPresentModeKHR presentMode) {
|
||||
return string_VkPresentModeKHR(presentMode);
|
||||
}
|
||||
|
||||
void SwapchainObject::Create(VkDevice device, VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
|
||||
Uint32 graphicsQueueFamily, Uint32 presentQueueFamily, Uint32 minImageCountHint,
|
||||
VkExtent2D desiredExtent, Optional<Int> swapInterval) {
|
||||
VkExtent2D desiredExtent) {
|
||||
const auto swapchainCapabilities = GetSwapchainCapabilities(physicalDevice, surface);
|
||||
MOBILEGL_ASSERT(swapchainCapabilities.IsComplete(),
|
||||
"SwapchainObject::Create failed: incomplete swapchain capabilities");
|
||||
@@ -194,10 +174,8 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
MGLOG_D(" %s", string_VkPresentModeKHR(pm));
|
||||
}
|
||||
|
||||
const auto presentMode = ChooseSwapchainPresentMode(swapchainCapabilities.presentModes, swapInterval);
|
||||
const auto presentMode = ChooseSwapchainPresentMode(swapchainCapabilities.presentModes);
|
||||
MGLOG_I("Picked present mode: %s", string_VkPresentModeKHR(presentMode));
|
||||
m_presentMode = presentMode;
|
||||
m_supportedPresentModes = swapchainCapabilities.presentModes;
|
||||
|
||||
const auto& swapchainCaps = swapchainCapabilities.capabilities;
|
||||
Uint32 targetImageCount = std::max<Uint32>(minImageCountHint, swapchainCaps.minImageCount);
|
||||
|
||||
@@ -26,23 +26,13 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
|
||||
static SwapchainCapabilities GetSwapchainCapabilities(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface);
|
||||
static VkSurfaceFormatKHR ChooseSwapchainSurfaceFormat(const Vector<VkSurfaceFormatKHR>& availableFormats);
|
||||
// swapInterval is the app's eglSwapInterval, empty until it asks (s_desiredPresentModes
|
||||
// ranks the modes then). 0 wants IMMEDIATE, else MAILBOX, else FIFO; >= 1 wants FIFO,
|
||||
// which cannot skip vblanks, so 2 and up pace like 1; a negative interval (adaptive
|
||||
// vsync) wants FIFO_RELAXED, else FIFO.
|
||||
static VkPresentModeKHR ChooseSwapchainPresentMode(const Vector<VkPresentModeKHR>& availablePresentModes,
|
||||
Optional<Int> swapInterval = Nullopt);
|
||||
static const char* GetPresentModeName(VkPresentModeKHR presentMode);
|
||||
static VkPresentModeKHR ChooseSwapchainPresentMode(const Vector<VkPresentModeKHR>& availablePresentModes);
|
||||
|
||||
void Create(VkDevice device, VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, Uint32 graphicsQueueFamily,
|
||||
Uint32 presentQueueFamily, Uint32 minImageCountHint, VkExtent2D desiredExtent,
|
||||
Optional<Int> swapInterval);
|
||||
Uint32 presentQueueFamily, Uint32 minImageCountHint, VkExtent2D desiredExtent);
|
||||
void Shutdown(VkDevice device);
|
||||
|
||||
VkSwapchainKHR GetHandle() const { return m_swapchain; }
|
||||
VkPresentModeKHR GetPresentMode() const { return m_presentMode; }
|
||||
// The surface's present modes as queried when this swapchain was created.
|
||||
const Vector<VkPresentModeKHR>& GetSupportedPresentModes() const { return m_supportedPresentModes; }
|
||||
const VkSurfaceFormatKHR& GetSurfaceFormat() const { return m_surfaceFormat; }
|
||||
VkExtent2D GetExtent() const { return m_extent; }
|
||||
// Surface-space extent (before the pre-rotation quarter-turn swap) this swapchain was
|
||||
@@ -89,8 +79,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
};
|
||||
|
||||
VkSwapchainKHR m_swapchain = VK_NULL_HANDLE;
|
||||
VkPresentModeKHR m_presentMode = VK_PRESENT_MODE_FIFO_KHR;
|
||||
Vector<VkPresentModeKHR> m_supportedPresentModes;
|
||||
VkSurfaceFormatKHR m_surfaceFormat{};
|
||||
VkExtent2D m_extent{};
|
||||
VkExtent2D m_surfaceExtent{};
|
||||
|
||||
@@ -31,10 +31,6 @@
|
||||
#include <Config.h>
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
#include <MG_Pipe/PipeApply.h>
|
||||
// P7 wave 0: the seam WireDescriptorFatal dies through. See MG_Pipe/PipeSessionFail.h.
|
||||
#include <MG_Pipe/PipeSessionFail.h>
|
||||
// P7 wave 2 package B3: rule I's tally for this file's silent wire-draw exits.
|
||||
#include "WireDeclineTally.h"
|
||||
#endif
|
||||
#include <vulkan/utility/vk_format_utils.h>
|
||||
#include <algorithm>
|
||||
@@ -69,11 +65,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
return hash;
|
||||
}
|
||||
|
||||
// P7 wave 0, the descriptor half of WireFramebuffer.inc's MagmaWireFatal - same message,
|
||||
// same seam, same reason. Four of the fifteen P7-marked refusals die here.
|
||||
[[noreturn]] static void WireDescriptorFatal(const char* detail) {
|
||||
MG_Pipe::MGPipeSessionFail(MG_Pipe::MGPipeFatalFamily::UnmigratedVerb,
|
||||
"MGPipe: Fatal{UnmigratedVerb, \"Magma:%s\"}", detail);
|
||||
MGLOG_F("MGPipe: Fatal{UnmigratedVerb, \"Magma:%s\"}", detail);
|
||||
std::abort();
|
||||
}
|
||||
|
||||
static Bool ResolveWireRange(Uint64 offset, Uint64 declaredSize, VkDeviceSize bufferSize,
|
||||
@@ -99,49 +93,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
}
|
||||
}
|
||||
|
||||
// GL ignores Layer/Layered for a target with no layers. In particular image1D stays a 1D
|
||||
// view, and an ignored nonzero Layer must not address another slice.
|
||||
static Bool WireTargetHasLayers(MG_Pipe::MGPipeResourceTarget target) {
|
||||
using T = MG_Pipe::MGPipeResourceTarget;
|
||||
return target == T::Tex1DArray || target == T::Tex2DArray || target == T::Tex2DMSArray ||
|
||||
target == T::Tex3D || target == T::TexCube || target == T::TexCubeArray;
|
||||
}
|
||||
|
||||
// GL 4.6 core 8.26: an access through an image unit whose texture does not HAVE the
|
||||
// (level, layer) the unit names is INVALID. A load returns zero, a store does nothing, an
|
||||
// atomic updates nothing - and none of it is an error, neither at bind time (the bind only
|
||||
// checks the level's and the layer's signs) nor at the draw. It is the observable an empty
|
||||
// unit has, so the answer is the empty unit's (ResolveWirePlaceholderImage): a NULL storage
|
||||
// descriptor where the device enables VK_EXT_robustness2 nullDescriptor, else a storage
|
||||
// placeholder private to the unit (per shape), cleared before each use, of the dimensionality
|
||||
// the SHADER declared.
|
||||
//
|
||||
// KHR-GL46.shader_image_load_store.incomplete_textures is the shape that found it: level 2
|
||||
// of a texture that defines only level 0 (MAX_LEVEL 7, a mipmapping filter). The same
|
||||
// question comes up empty for a level past an immutable texture's storage, a layer past an
|
||||
// array's last slice, a texture that has no storage at all, and a level past a texture
|
||||
// view's own window even where its owner has one. The record carries exactly what
|
||||
// glBindImageTexture was given, so it is decided here, by the walk every wire consumer uses
|
||||
// to find a texel's storage, and from that walk's "not there" answer ONLY: a null for any
|
||||
// other reason (a dead record, a stale view CSO) stays the descriptor resolve's refusal.
|
||||
//
|
||||
// NOT DECIDED HERE, deliberately: a level that IS in storage but lies outside
|
||||
// [BASE_LEVEL, MAX_LEVEL], or of a texture that is not mipmap-complete. The monolith arm
|
||||
// binds those as it finds them too, and the P7 gate 5 comparison is against that arm.
|
||||
static Bool WireShaderImageNamesNoTexel(VkTextureManager& textures, const MG_Pipe::MGPImageView& image) {
|
||||
const auto& state = MG_Pipe::MGPipeApplier();
|
||||
if (MG_Pipe::MGPipeHandleIsNull(image.Res) || image.Res.Slot >= state.TextureResources.size()) return false;
|
||||
const auto& record = state.TextureResources[image.Res.Slot];
|
||||
if (!record.Live || record.Gen != image.Res.Gen) return false;
|
||||
const Bool selectsLayer =
|
||||
WireTargetHasLayers(static_cast<MG_Pipe::MGPipeResourceTarget>(record.Desc.Target)) && !image.Layered;
|
||||
Uint32 level = image.Level;
|
||||
Uint32 layer = selectsLayer ? image.Layer : 0;
|
||||
Bool outsideWindow = false;
|
||||
(void)textures.ResolveWireTextureStorage(image.Res, level, layer, nullptr, nullptr, &outsideWindow);
|
||||
return outsideWindow;
|
||||
}
|
||||
|
||||
static VkComponentSwizzle WireSwizzle(Uint8 value) {
|
||||
switch (static_cast<TextureSwizzleParam>(value)) {
|
||||
case TextureSwizzleParam::Red: return VK_COMPONENT_SWIZZLE_R;
|
||||
@@ -167,31 +118,23 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
if (unit < 0 || static_cast<Uint32>(unit) >=
|
||||
(storage ? MG_Pipe::kMGPipeMaxImageUnits : MG_Pipe::kMGPipeMaxTextureUnits)) return false;
|
||||
const auto handle = storage ? state.BoundShaderImages[unit].Res : state.BoundSamplerViews[unit].Texture;
|
||||
// An EMPTY image unit is the same 8.26 invalid access as the named-but-missing texel
|
||||
// below, so it takes the same answer: a null storage descriptor where the device has
|
||||
// one, else the unit-private placeholder (codex closeout finding 2).
|
||||
if (MG_Pipe::MGPipeHandleIsNull(handle))
|
||||
return ResolveWirePlaceholderImage(commandBuffer, program, programObj, binding, storage, out,
|
||||
VK_FORMAT_UNDEFINED, static_cast<Uint32>(unit));
|
||||
return ResolveWirePlaceholderImage(commandBuffer, program, programObj, binding, storage, out);
|
||||
if (handle.Slot >= state.TextureResources.size()) WireDescriptorFatal("image-record");
|
||||
const auto& record = state.TextureResources[handle.Slot];
|
||||
if (!record.Live || record.Gen != handle.Gen) WireDescriptorFatal("image-record-generation");
|
||||
// Before the sync: a texture with no storage at all is one of the shapes, and syncing
|
||||
// it would refuse rather than answer.
|
||||
if (storage && WireShaderImageNamesNoTexel(*m_textureManager, state.BoundShaderImages[unit])) {
|
||||
const VkFormat bound = MG_Util::ConvertTextureInternalFormatToVkEnum(
|
||||
MG_Util::ConvertGLEnumToTextureInternalFormat(state.BoundShaderImages[unit].InternalFormat));
|
||||
return ResolveWirePlaceholderImage(commandBuffer, program, programObj, binding, storage, out, bound,
|
||||
static_cast<Uint32>(unit));
|
||||
}
|
||||
auto* resource = m_textureManager->SyncTextureResourceByHandle(handle, false, storage);
|
||||
if (!resource) WireDescriptorFatal("image-resource");
|
||||
m_textureManager->FlushPendingUploads();
|
||||
|
||||
const auto target = static_cast<MG_Pipe::MGPipeResourceTarget>(record.Desc.Target);
|
||||
const Bool layerable = WireTargetHasLayers(target);
|
||||
using Target = MG_Pipe::MGPipeResourceTarget;
|
||||
const Bool layerable = target == Target::Tex1DArray || target == Target::Tex2DArray ||
|
||||
target == Target::Tex2DMSArray || target == Target::Tex3D ||
|
||||
target == Target::TexCube || target == Target::TexCubeArray;
|
||||
Uint32 level = storage ? state.BoundShaderImages[unit].Level : record.Params.BaseLevel;
|
||||
// GL ignores Layer/Layered for non-layerable targets (WireTargetHasLayers).
|
||||
// GL ignores Layer/Layered for non-layerable targets. In particular image1D
|
||||
// stays a 1D view, and an ignored nonzero Layer must not address another slice.
|
||||
Uint32 layer = storage && layerable && !state.BoundShaderImages[unit].Layered
|
||||
? state.BoundShaderImages[unit].Layer : 0;
|
||||
const Uint32 localLevel = level;
|
||||
@@ -591,11 +534,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
m_samplerResolveMemoHighWater = 0;
|
||||
m_setsPerFrame = setsPerFrame;
|
||||
m_peakDescriptorSetsObserved = 0;
|
||||
m_trimQuietEpochs = MG_Config::Features.MagmaDescriptorTrimFrames;
|
||||
// The renderer records its first frame into slot 0 before any BeginFrame runs.
|
||||
m_epochSlot = 0;
|
||||
m_epochOpen = true;
|
||||
m_descriptorSlotTrims = 0;
|
||||
m_textureManager = textureManager;
|
||||
m_samplerManager = samplerManager;
|
||||
|
||||
@@ -605,8 +543,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
frame.activeDescriptorPoolIndex = 0;
|
||||
frame.allocatedSetsThisFrame = 0;
|
||||
frame.peakAllocatedSetsThisFrame = 0;
|
||||
frame.capacitySets = m_setsPerFrame;
|
||||
frame.quietEpochs = 0;
|
||||
frame.descriptorPools.clear();
|
||||
|
||||
VkDescriptorPool initialPool = VK_NULL_HANDLE;
|
||||
@@ -661,18 +597,12 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
frame.activeDescriptorPoolIndex = 0;
|
||||
frame.allocatedSetsThisFrame = 0;
|
||||
frame.peakAllocatedSetsThisFrame = 0;
|
||||
frame.capacitySets = 0;
|
||||
frame.quietEpochs = 0;
|
||||
}
|
||||
m_frames.clear();
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
for (auto& entry : m_wirePlaceholderImages) DestroyWirePlaceholderImage(entry.second);
|
||||
m_wirePlaceholderImages.clear();
|
||||
m_wirePrivateStoragePlaceholders = 0;
|
||||
m_wireInvalidStorageImagesBindNull = false;
|
||||
#endif
|
||||
m_epochSlot = 0;
|
||||
m_epochOpen = false;
|
||||
|
||||
m_bufferManager = nullptr;
|
||||
m_programFactory = nullptr;
|
||||
@@ -712,20 +642,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
"UniformDescriptorBinder: new descriptor set peak observed=%u (base setsPerFrame=%u, frame=%u, pools=%zu)",
|
||||
m_peakDescriptorSetsObserved, m_setsPerFrame, frameIndex, frame.descriptorPools.size());
|
||||
}
|
||||
// The epoch that just ended is the one of the slot begun last - this slot again on the
|
||||
// drain path, the previous frame's slot on the Present path. Its peak is still unreset.
|
||||
if (m_epochOpen && m_epochSlot < m_frames.size()) {
|
||||
NoteEndedEpochForTrim(m_frames[m_epochSlot].peakAllocatedSetsThisFrame);
|
||||
}
|
||||
m_epochSlot = frameIndex;
|
||||
m_epochOpen = true;
|
||||
// No pending command buffer references this slot's sets here (see TrimFrameDescriptorPools
|
||||
// for why that holds at both of BeginFrame's call sites), so a quiet grown slot can be
|
||||
// handed back whole.
|
||||
if (m_trimQuietEpochs != 0 && frame.descriptorPools.size() > 1 &&
|
||||
frame.capacitySets >= kDescriptorTrimMinCapacity && frame.quietEpochs >= m_trimQuietEpochs) {
|
||||
TrimFrameDescriptorPools(frame, frameIndex);
|
||||
}
|
||||
frame.activeDescriptorPoolIndex = 0;
|
||||
frame.allocatedSetsThisFrame = 0;
|
||||
frame.peakAllocatedSetsThisFrame = 0;
|
||||
@@ -734,7 +650,11 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
}
|
||||
// The frame's descriptor sets are recycled above, so last frame's reuse targets
|
||||
// are gone: start the per-draw descriptor-reuse cache fresh this frame.
|
||||
InvalidateDescriptorSetMemos();
|
||||
for (auto& entry : m_descriptorReuseMemo) {
|
||||
entry.valid = false;
|
||||
}
|
||||
m_fastRebindMemo.valid = false;
|
||||
m_lastBindValid = false;
|
||||
// Re-fingerprint the bound sampler set fresh this frame so any GL object address
|
||||
// reuse cannot outlive a single frame (see SamplerResolveMemo). Only the entries a
|
||||
// resolve has actually written can be valid, so the high-water mark bounds the
|
||||
@@ -748,103 +668,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
}
|
||||
}
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
Bool UniformManager::WireDescriptorSetBudgetReached(Uint32 frameIndex) const {
|
||||
MOBILEGL_ASSERT(frameIndex < m_frames.size(), "WireDescriptorSetBudgetReached invalid frame index");
|
||||
return m_frames[frameIndex].allocatedSetsThisFrame >= kWireDescriptorSetBudget;
|
||||
}
|
||||
|
||||
SizeT UniformManager::RewindWireDescriptorSets(Uint32 frameIndex) {
|
||||
MOBILEGL_ASSERT(frameIndex < m_frames.size(), "RewindWireDescriptorSets invalid frame index");
|
||||
auto& frame = m_frames[frameIndex];
|
||||
// The caller proved that the last graphics submit using these sets has
|
||||
// retired and that no unsubmitted command buffer still references them.
|
||||
// Keep the pools and sets: only the per-layout write cursors rewind.
|
||||
// Image and buffer views stay alive until the regular frame boundary.
|
||||
m_peakDescriptorSetsObserved = std::max(m_peakDescriptorSetsObserved, frame.peakAllocatedSetsThisFrame);
|
||||
SizeT cachedSets = 0;
|
||||
for (auto& entry : frame.descriptorSetCacheByLayout) {
|
||||
cachedSets += entry.second.sets.size();
|
||||
entry.second.cursor = 0;
|
||||
}
|
||||
frame.allocatedSetsThisFrame = 0;
|
||||
// The PEAK is not reset: a rewind ends a window of the epoch, not the epoch. The trim scores
|
||||
// an epoch by the most sets the slot held at once in it (NoteEndedEpochForTrim at the next
|
||||
// BeginFrame), and on this arm that is the largest window - resetting here would score a
|
||||
// burst frame by its last window alone and trim a slot that re-grows every frame.
|
||||
InvalidateDescriptorSetMemos();
|
||||
const Uint32 touchedBindings =
|
||||
std::min<Uint32>(m_samplerResolveMemoHighWater, static_cast<Uint32>(m_samplerResolveMemo.size()));
|
||||
for (Uint32 binding = 0; binding < touchedBindings; ++binding) {
|
||||
m_samplerResolveMemo[binding].valid = false;
|
||||
m_samplerResolveMemo[binding].infoValid = false;
|
||||
}
|
||||
return cachedSets;
|
||||
}
|
||||
#endif
|
||||
|
||||
void UniformManager::InvalidateDescriptorSetMemos() {
|
||||
// Every VkDescriptorSet handle held outside the per-layout caches - in this backend they all
|
||||
// live in this class. A trim can hand a destroyed set's handle value to a fresh allocation,
|
||||
// so the bind-dedup shadow must drop too, not only the two reuse memos.
|
||||
for (auto& entry : m_descriptorReuseMemo) {
|
||||
entry.valid = false;
|
||||
}
|
||||
m_fastRebindMemo.valid = false;
|
||||
m_lastBindValid = false;
|
||||
}
|
||||
|
||||
void UniformManager::NoteEndedEpochForTrim(Uint32 epochPeakSets) {
|
||||
for (auto& slot : m_frames) {
|
||||
if (static_cast<Uint64>(epochPeakSets) * kDescriptorTrimHeadroom > slot.capacitySets) {
|
||||
slot.quietEpochs = 0;
|
||||
} else if (slot.quietEpochs < std::numeric_limits<Uint32>::max()) {
|
||||
++slot.quietEpochs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UniformManager::TrimFrameDescriptorPools(FrameResources& frame, Uint32 frameIndex) {
|
||||
const SizeT poolsBefore = frame.descriptorPools.size();
|
||||
const Uint64 capacityBefore = frame.capacitySets;
|
||||
// Holders first: the per-layout cache and every memo that may name one of these sets.
|
||||
frame.descriptorSetCacheByLayout.clear();
|
||||
InvalidateDescriptorSetMemos();
|
||||
for (SizeT i = 1; i < frame.descriptorPools.size(); ++i) {
|
||||
if (frame.descriptorPools[i].handle != VK_NULL_HANDLE) {
|
||||
vkDestroyDescriptorPool(m_device, frame.descriptorPools[i].handle, nullptr);
|
||||
}
|
||||
}
|
||||
frame.descriptorPools.resize(1);
|
||||
auto& base = frame.descriptorPools[0];
|
||||
// Frees every set allocated from it; the spec defines no failure for vkResetDescriptorPool.
|
||||
vkResetDescriptorPool(m_device, base.handle, 0);
|
||||
base.allocatedSets = 0;
|
||||
frame.activeDescriptorPoolIndex = 0;
|
||||
frame.capacitySets = base.maxSets;
|
||||
frame.quietEpochs = 0;
|
||||
++m_descriptorSlotTrims;
|
||||
MGLOG_D("UniformDescriptorBinder: frame %u trimmed its descriptor pools (%zu pools / %llu sets -> 1 / %u)",
|
||||
frameIndex, poolsBefore, static_cast<unsigned long long>(capacityBefore), base.maxSets);
|
||||
}
|
||||
|
||||
DescriptorPoolCensus UniformManager::GetDescriptorPoolCensus() const {
|
||||
DescriptorPoolCensus census;
|
||||
census.available = true;
|
||||
census.frameSlots = static_cast<uint32_t>(m_frames.size());
|
||||
for (const auto& frame : m_frames) {
|
||||
const auto poolCount = static_cast<uint32_t>(frame.descriptorPools.size());
|
||||
census.pools += poolCount;
|
||||
census.maxPoolsInOneSlot = std::max(census.maxPoolsInOneSlot, poolCount);
|
||||
census.capacitySets += frame.capacitySets;
|
||||
for (const auto& cacheEntryPair : frame.descriptorSetCacheByLayout) {
|
||||
census.cachedSets += cacheEntryPair.second.sets.size();
|
||||
}
|
||||
}
|
||||
census.slotTrims = m_descriptorSlotTrims;
|
||||
return census;
|
||||
}
|
||||
|
||||
void UniformManager::OnDescriptorSetLayoutDestroyed(VkDescriptorSetLayout descriptorSetLayout) {
|
||||
SizeT purgedSets = 0;
|
||||
for (auto& frame : m_frames) {
|
||||
@@ -1326,58 +1149,16 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
state.BoundShaderImages[unit].InternalFormat));
|
||||
if (format == VK_FORMAT_UNDEFINED) format = MG_Util::ConvertTextureInternalFormatToVkEnum(internalFormat);
|
||||
const auto feature = storage ? VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT : VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT;
|
||||
if (format == VK_FORMAT_UNDEFINED || !BufferFormatSupportsFeature(m_physicalDevice, format, feature)) {
|
||||
// P7 A.5, a decline (rule I (a)). GL's buffer-texture format list is wider than what
|
||||
// Vulkan mandates for texel buffers - GL_RGB32{F,I,UI} and the 16-bit UNORM members
|
||||
// are the realistic misses on a real driver - so this is a device capability gap, not
|
||||
// anything the application did wrong, and nothing it could have sent differently.
|
||||
//
|
||||
// The placeholder is the RIGHT answer here, where it was not for the unaligned range
|
||||
// above, and the difference is whether a correct answer exists at all. There, the
|
||||
// bytes are addressable and only the descriptor cannot name them, so a placeholder
|
||||
// would have hidden a fixable gap behind silently dropped writes. Here the device
|
||||
// cannot represent this format as a texel buffer in any form - so the honest
|
||||
// observable is monolith's for a missing view: the fetch reads zeros and the draw
|
||||
// survives. AcquireUnboundTexelBufferView falls back to the R32 member of the
|
||||
// shader's numeric class, whose texel-buffer support is mandatory, so the fallback
|
||||
// itself cannot fail for want of device features.
|
||||
MGLOG_E_ONCE("ResolveWireTexelBufferDescriptor: binding %u wants VkFormat %d as a %s texel buffer and "
|
||||
"this device does not support it; the binding falls back to the zero placeholder and the "
|
||||
"fetch reads zeros (texel-buffer-native-format)",
|
||||
binding, static_cast<Int>(format), storage ? "storage" : "uniform");
|
||||
return placeholder();
|
||||
}
|
||||
if (format == VK_FORMAT_UNDEFINED || !BufferFormatSupportsFeature(m_physicalDevice, format, feature))
|
||||
WireDescriptorFatal("texel-buffer-native-format@P7");
|
||||
const VkDeviceSize texelSize = MG_Util::GetSizedInternalFormatSizeInBytes(internalFormat);
|
||||
VkDeviceSize start = 0, size = 0;
|
||||
if (texelSize == 0 || !ResolveWireRange(record.Desc.BufOffset, record.Desc.BufSize, slice.size, start, size)) return false;
|
||||
size = std::min(size / texelSize, static_cast<VkDeviceSize>(m_wireMaxTexelElements)) * texelSize;
|
||||
if (size == 0) return false;
|
||||
if (start > std::numeric_limits<VkDeviceSize>::max() - slice.offset)
|
||||
WireDescriptorFatal("texel-buffer-offset-overflow");
|
||||
if ((slice.offset + start) % m_wireTexelOffsetAlignment != 0) {
|
||||
// P7 A.4, a named decline (rule I (a)). Not reachable through the public API:
|
||||
// glTexBufferRange already refuses an offset that is not a multiple of
|
||||
// GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT (GL_Texture.cpp), and that cap is published
|
||||
// from this same minTexelBufferOffsetAlignment. It stays a decline rather than a
|
||||
// copy for the reason below.
|
||||
const Bool writable = storage && state.BoundShaderImages[unit].Access != kMGPipeImageAccessReadOnly;
|
||||
MGLOG_E_ONCE("ResolveWireTexelBufferDescriptor: binding %u is bound at offset %llu, which is not a "
|
||||
"multiple of this device's minTexelBufferOffsetAlignment (%llu); the %s view is DECLINED "
|
||||
"(unaligned-texel-buffer-range)", binding,
|
||||
static_cast<unsigned long long>(slice.offset + start),
|
||||
static_cast<unsigned long long>(m_wireTexelOffsetAlignment),
|
||||
writable ? "writable" : "read-only");
|
||||
// A read-only fetch can still be served the way an unbound buffer texture is -
|
||||
// zeros, which is what a missing view gives in monolith - and that keeps the draw.
|
||||
// A writable imageBuffer must not: the placeholder is shared by every unbound
|
||||
// binding, so absorbing real stores into it would alias other bindings AND lose
|
||||
// the application's writes without a word. Copying into an aligned transient slice
|
||||
// is not the answer either: the transient arena carries no
|
||||
// {UNIFORM,STORAGE}_TEXEL_BUFFER usage (VkBufferManager::InitializeTransientArenas),
|
||||
// so no VkBufferView can be made over it, and widening a shared per-frame
|
||||
// allocation to buy an unreachable path is the wrong trade. See notes/p7/magma-a.md.
|
||||
return writable ? false : placeholder();
|
||||
}
|
||||
if (start > std::numeric_limits<VkDeviceSize>::max() - slice.offset ||
|
||||
(slice.offset + start) % m_wireTexelOffsetAlignment != 0)
|
||||
WireDescriptorFatal("unaligned-texel-buffer-range@P7");
|
||||
VkBufferViewCreateInfo viewInfo{VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO};
|
||||
viewInfo.buffer = slice.buffer;
|
||||
viewInfo.format = format;
|
||||
@@ -1765,56 +1546,11 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
if (!m_bufferManager->AcquireWireSlice(BufferKind::ShaderStorage, range.Res, slice) || !slice.IsValid()) return false;
|
||||
VkDeviceSize start = 0, size = 0;
|
||||
if (!ResolveWireRange(range.Offset, range.Size, slice.size, start, size)) return false;
|
||||
if (start > std::numeric_limits<VkDeviceSize>::max() - slice.offset)
|
||||
WireDescriptorFatal("storage-buffer-offset-overflow");
|
||||
if ((slice.offset + start) % m_wireStorageOffsetAlignment != 0) {
|
||||
// P7 A.4, a named decline (rule I (a)), and the one shape in this cluster an
|
||||
// application can actually reach. GL has no queryable atomic-counter buffer
|
||||
// offset alignment, so glBindBufferRange only enforces offset % 4 for
|
||||
// GL_ATOMIC_COUNTER_BUFFER (GL 4.6 core 6.1.1, GL_Buffer.cpp
|
||||
// ValidateBufferRangeOffsetAndSize); glslang lowers the counter block onto a
|
||||
// storage buffer, whose descriptor offset must be a multiple of
|
||||
// minStorageBufferOffsetAlignment - 16 on lavapipe, 64 on Adreno. Offset 4 is
|
||||
// therefore a legal bind this backend cannot express. The plain SSBO half is
|
||||
// unreachable by comparison: GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT is
|
||||
// published from that same Vulkan limit, so the frontend already refused it
|
||||
// with GL_INVALID_VALUE.
|
||||
//
|
||||
// DECLINED RATHER THAN COPIED, deliberately. Copying the window into an aligned
|
||||
// transient slice reads correctly and then silently DROPS every shader write,
|
||||
// and this site cannot tell a writable block from a read-only one: there is no
|
||||
// readonly bit in the storage-block reflection (ProgramFactory.h carries only
|
||||
// name and index), an atomic counter is written by definition, and
|
||||
// MarkWireBufferGpuWritten below already assumes any binding here may be
|
||||
// written. A correct copy needs a post-dispatch copy-back from the transient
|
||||
// slice to the unaligned source, ordered with a barrier - and the place to
|
||||
// record that is the draw/dispatch tail in VulkanRenderer.cpp / WireDraw.inc,
|
||||
// which belong to wave-2 packages B and C, not to this file. Losing the
|
||||
// dispatch with a named line in the role log beats returning stale counters
|
||||
// with no error at all. notes/p7/magma-a.md carries the recipe.
|
||||
MGLOG_E_ONCE("ResolveStorageBufferDescriptor: block '%s' is bound at offset %llu, which is not a "
|
||||
"multiple of this device's minStorageBufferOffsetAlignment (%llu); %s ranges cannot be "
|
||||
"expressed as a descriptor and the shader's writes would be dropped by a read-only "
|
||||
"copy, so the binding is DECLINED (unaligned-%s-buffer-range)",
|
||||
blockName.c_str(), static_cast<unsigned long long>(slice.offset + start),
|
||||
static_cast<unsigned long long>(m_wireStorageOffsetAlignment),
|
||||
isAtomicCounterBlock ? "atomic-counter" : "shader-storage",
|
||||
isAtomicCounterBlock ? "atomic" : "storage");
|
||||
return false;
|
||||
}
|
||||
if (size > m_wireMaxStorageRange) {
|
||||
// P7 A.3: clamp, do not refuse. The monolith arm binds whatever the GL range
|
||||
// asked for and never consults maxStorageBufferRange at all (see the resident
|
||||
// path below), so refusing here was the wire arm inventing a death the other
|
||||
// backend does not have. A clamped binding keeps every byte the device can
|
||||
// name reachable; past it the shader is out of the descriptor and
|
||||
// robustBufferAccess answers zero, which beats losing the draw outright.
|
||||
MGLOG_E_ONCE("ResolveStorageBufferDescriptor: block '%s' bound %llu bytes, past this device's "
|
||||
"maxStorageBufferRange of %llu; the binding is clamped to the limit",
|
||||
blockName.c_str(), static_cast<unsigned long long>(size),
|
||||
static_cast<unsigned long long>(m_wireMaxStorageRange));
|
||||
size = m_wireMaxStorageRange;
|
||||
}
|
||||
if (start > std::numeric_limits<VkDeviceSize>::max() - slice.offset ||
|
||||
(slice.offset + start) % m_wireStorageOffsetAlignment != 0)
|
||||
WireDescriptorFatal(isAtomicCounterBlock ? "unaligned-atomic-buffer-range@P7"
|
||||
: "unaligned-storage-buffer-range@P7");
|
||||
if (size > m_wireMaxStorageRange) WireDescriptorFatal("storage-buffer-native-range@P7");
|
||||
outBufferInfo = {slice.buffer, slice.offset + start, size};
|
||||
// Shader writes stay in the canonical server VkBuffer. The event marks the
|
||||
// client's shadow stale; neither this path nor later acquires seed it back.
|
||||
@@ -2622,25 +2358,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
Uint32 blockIndex, Uint32 bindingPoint, UboBindResult& out) const {
|
||||
if (bindingPoint >= MG_Pipe::kMGPipeMaxBufferBindingPoints)
|
||||
WireDescriptorFatal("uniform-buffer-binding-point");
|
||||
VkDeviceSize blockSize = program.GetUBOSizeAt(blockIndex);
|
||||
const VkDeviceSize blockSize = program.GetUBOSizeAt(blockIndex);
|
||||
if (blockSize == 0) return false;
|
||||
if (blockSize > m_wireMaxUniformRange) {
|
||||
// P7 A.3: clamp, do not refuse. A conformant program cannot get here -
|
||||
// GL_MAX_UNIFORM_BLOCK_SIZE is published straight from this same
|
||||
// maxUniformBufferRange (BackendLoaders/Vulkan/Loader.cpp), so a block this big
|
||||
// fails to link long before a draw - which makes refusing it a Fatal for a shape
|
||||
// nothing can produce. If the two ever disagree, the honest answer is the bytes
|
||||
// the device CAN name: everything past the clamp is outside the descriptor and
|
||||
// reads back as zero under robustBufferAccess, which is inside GL's "undefined"
|
||||
// for a block the implementation never promised to hold. Clamping keeps the range
|
||||
// constant across draws, so the descriptor-set reuse hash is unaffected.
|
||||
MGLOG_E_ONCE("ResolveWireUniformBufferPayload: reflected uniform block %u is %llu bytes, past this "
|
||||
"device's maxUniformBufferRange of %llu; the binding is clamped to the limit and the "
|
||||
"remainder reads zero",
|
||||
blockIndex, static_cast<unsigned long long>(blockSize),
|
||||
static_cast<unsigned long long>(m_wireMaxUniformRange));
|
||||
blockSize = m_wireMaxUniformRange;
|
||||
}
|
||||
if (blockSize > m_wireMaxUniformRange) WireDescriptorFatal("uniform-block-native-range@P7");
|
||||
const auto& range = MG_Pipe::MGPipeApplier().BoundShaderBuffers[
|
||||
MG_Pipe::kMGPipeShaderBufferClassUniform][bindingPoint];
|
||||
BufferSlice source{};
|
||||
@@ -2667,45 +2387,17 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// inside the GL binding range. A readback here could retire the command buffer
|
||||
// whose value BindProgramUniformBuffers is currently holding.
|
||||
const VkDeviceSize copied = std::min(available, blockSize);
|
||||
if (bound && ((start & 3u) != 0 || ((source.offset + start) & 3u) != 0 || (copied & 3u) != 0))
|
||||
WireDescriptorFatal("uniform-buffer-byte-tail@P7");
|
||||
static thread_local Vector<Uint8> zero;
|
||||
zero.assign(static_cast<SizeT>(blockSize), 0);
|
||||
BufferSlice padded{};
|
||||
if (!m_bufferManager->UploadTransient(BufferKind::Uniform, m_wireFrameIndex, zero.data(), blockSize,
|
||||
std::max<VkDeviceSize>(4, m_minDynamicOffsetAlignment), padded) || !padded.IsValid()) return false;
|
||||
if (bound && copied != 0) {
|
||||
// P7 A.1 retires `uniform-buffer-byte-tail`. The window is word-aligned at both
|
||||
// ends on nearly every bind - glBindBufferRange already forces the offset onto
|
||||
// GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, and that is a multiple of four on every
|
||||
// device - but GL 4.6 core 6.1.1 puts no such rule on the SIZE, so `copied` is free
|
||||
// to end mid-word and the Redmi Minecraft run lands there
|
||||
// (notes/p5f/magma-inproc-fix.md #5). An unaligned start is not reachable through
|
||||
// the public API and only a protocol-level offset can produce one; the sub-word arm
|
||||
// handles it anyway rather than leaving a second shape to trip over later. Both arms
|
||||
// copy the same bytes to the same place: the sub-word one pays one extra transient
|
||||
// slice and one extra region copy, and nothing outside [start, start + copied)
|
||||
// reaches the block, which is what makes the padded zeros the visible tail.
|
||||
const Bool wordWindow = ((start | copied) & 3u) == 0;
|
||||
if (!(wordWindow
|
||||
? m_bufferManager->CopyWireBufferRangeToSlice(range.Res, start, copied, padded)
|
||||
: m_bufferManager->CopyWireBufferSubWordRangeToSlice(range.Res, start, copied,
|
||||
m_wireFrameIndex, padded, 0)))
|
||||
return false;
|
||||
}
|
||||
if (padded.offset > std::numeric_limits<Uint32>::max()) {
|
||||
// P7 A.2, a decline (rule I (a)), not a session death. A Vulkan dynamic offset is a
|
||||
// uint32_t, so a transient uniform ring that grew past 4 GiB inside one frame has
|
||||
// nowhere to put this block - which is our ring's problem, not a protocol fault, and
|
||||
// nothing the peer could have sent differently. One binding is skipped and the draw
|
||||
// is lost; the session keeps running and the next frame's rewound ring resolves it.
|
||||
// The monolith arm has the same ceiling and truncates silently on the way out
|
||||
// (ResolveDynamicUboDescriptor's static_cast<Uint32>), i.e. it binds a WRONG window
|
||||
// rather than none, so declining is the strictly better observable of the two.
|
||||
MGLOG_E_ONCE("ResolveWireUniformBufferPayload: the transient uniform ring reached offset "
|
||||
"%llu, past the 4 GiB a Vulkan dynamic offset can name; uniform binding "
|
||||
"point %u is declined for this draw",
|
||||
static_cast<unsigned long long>(padded.offset), bindingPoint);
|
||||
return false;
|
||||
}
|
||||
if (bound && copied != 0 &&
|
||||
!m_bufferManager->CopyWireBufferRangeToSlice(range.Res, start, copied, padded)) return false;
|
||||
if (padded.offset > std::numeric_limits<Uint32>::max())
|
||||
WireDescriptorFatal("uniform-buffer-dynamic-offset@P7");
|
||||
out.directBindable = true;
|
||||
out.buffer = padded.buffer;
|
||||
out.range = blockSize;
|
||||
@@ -2784,20 +2476,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
|
||||
auto& bindingPoint = MGB_CTX->GetBufferBindingPoint(BufferTarget::Uniform, frontendBinding);
|
||||
const auto& bufferObject = bindingPoint.GetBoundObject();
|
||||
static thread_local Vector<Uint8> paddedUbo;
|
||||
if (bufferObject == nullptr) {
|
||||
// A block the program declares at a point with nothing bound - never bound, or its
|
||||
// buffer was deleted while bound, which unbinds it (UnboundUniformBlockScenario,
|
||||
// DeletedBoundBufferScenario). GL leaves what the shader READS undefined and raises no
|
||||
// error; this used to dereference the null object. Answer it with a zeroed block of the
|
||||
// reflected size, as the wire arm does (ResolveWireUniformBufferPayload).
|
||||
const VkDeviceSize blockSize =
|
||||
static_cast<VkDeviceSize>(program.GetUBOSizeAt(static_cast<Uint32>(blockIndex)));
|
||||
paddedUbo.assign(static_cast<SizeT>(blockSize > 0 ? blockSize : 16), 0);
|
||||
out.payload = paddedUbo.data();
|
||||
out.payloadSize = static_cast<VkDeviceSize>(paddedUbo.size());
|
||||
return true;
|
||||
}
|
||||
MOBILEGL_ASSERT(bufferObject != nullptr,
|
||||
"ResolveUniformBufferPayload: no UBO bound at frontend binding %u for block '%s'",
|
||||
frontendBinding, program.GetUniformBlockName(static_cast<Uint32>(blockIndex)).c_str());
|
||||
bufferObject->SyncPersistentMappedRange();
|
||||
|
||||
MOBILEGL_ASSERT(bufferObject->MappedData() != nullptr && bufferObject->GetSize() != 0,
|
||||
@@ -2830,6 +2511,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
outSize = blockSize;
|
||||
outData = bufferObject->MappedData() + static_cast<SizeT>(rangeStart);
|
||||
if (available < blockSize) {
|
||||
static thread_local Vector<Uint8> paddedUbo;
|
||||
paddedUbo.assign(static_cast<SizeT>(blockSize), 0);
|
||||
Memcpy(paddedUbo.data(), outData, static_cast<SizeT>(available));
|
||||
outData = paddedUbo.data();
|
||||
@@ -2925,49 +2607,32 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
return true;
|
||||
}
|
||||
|
||||
Uint32 UniformManager::NextDescriptorPoolMaxSets(const Vector<DescriptorPoolBucket>& pools, Bool updateAfterBind,
|
||||
Uint32 initialMaxSets) {
|
||||
const Uint32 minSets = std::max<Uint32>(1, initialMaxSets);
|
||||
const Uint32 maxSets = std::max(minSets, kMaxDescriptorPoolSets);
|
||||
Uint32 largest = 0;
|
||||
for (const auto& pool : pools) {
|
||||
if (pool.updateAfterBind == updateAfterBind) {
|
||||
largest = std::max(largest, pool.maxSets);
|
||||
}
|
||||
}
|
||||
if (largest == 0) {
|
||||
return minSets;
|
||||
}
|
||||
const Uint64 doubled = static_cast<Uint64>(largest) * 2;
|
||||
return static_cast<Uint32>(std::clamp<Uint64>(doubled, minSets, maxSets));
|
||||
}
|
||||
|
||||
Bool UniformManager::GrowFrameDescriptorPool(FrameResources& frame, Uint32 frameIndex, Bool updateAfterBind) {
|
||||
if (frame.descriptorPools.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Uint32 grownMaxSets = NextDescriptorPoolMaxSets(frame.descriptorPools, updateAfterBind, m_setsPerFrame);
|
||||
const auto matchingBucket = std::find_if(
|
||||
frame.descriptorPools.begin(), frame.descriptorPools.end(),
|
||||
[updateAfterBind](const DescriptorPoolBucket& candidate) { return candidate.updateAfterBind == updateAfterBind; });
|
||||
const Uint32 currentMaxSets = matchingBucket != frame.descriptorPools.end()
|
||||
? std::max<Uint32>(1, matchingBucket->maxSets)
|
||||
: m_setsPerFrame;
|
||||
const Uint32 grownMaxSets = currentMaxSets <= (std::numeric_limits<Uint32>::max() / 2) ? (currentMaxSets * 2)
|
||||
: currentMaxSets;
|
||||
|
||||
VkDescriptorPool grownPool = VK_NULL_HANDLE;
|
||||
// A large pool is a large driver allocation; if the device refuses one, settle for less
|
||||
// rather than failing the draw - halving down to the base size, where the old policy lived.
|
||||
while (!CreateDescriptorPool(grownMaxSets, updateAfterBind, grownPool)) {
|
||||
if (grownMaxSets <= m_setsPerFrame) {
|
||||
MGLOG_E_ONCE("UniformDescriptorBinder::GrowFrameDescriptorPool failed: cannot create grown pool (%u sets)",
|
||||
grownMaxSets);
|
||||
return false;
|
||||
}
|
||||
grownMaxSets = std::max(m_setsPerFrame, grownMaxSets / 2);
|
||||
if (!CreateDescriptorPool(grownMaxSets, updateAfterBind, grownPool)) {
|
||||
MGLOG_E_ONCE("UniformDescriptorBinder::GrowFrameDescriptorPool failed: cannot create grown pool (%u -> %u sets)",
|
||||
currentMaxSets, grownMaxSets);
|
||||
return false;
|
||||
}
|
||||
|
||||
frame.descriptorPools.push_back({grownPool, grownMaxSets, 0, updateAfterBind});
|
||||
frame.activeDescriptorPoolIndex = static_cast<Uint32>(frame.descriptorPools.size() - 1);
|
||||
frame.capacitySets += grownMaxSets;
|
||||
// Growing is the opposite of quiet: a trim must wait a full quiet run from here.
|
||||
frame.quietEpochs = 0;
|
||||
MGLOG_D("UniformDescriptorBinder: frame %u descriptor pool exhausted, grew a %u-set pool (updateAfterBind=%d), "
|
||||
"poolCount=%zu",
|
||||
frameIndex, grownMaxSets, updateAfterBind ? 1 : 0, frame.descriptorPools.size());
|
||||
MGLOG_D(
|
||||
"UniformDescriptorBinder: frame %u descriptor pool exhausted, grew pool (%u -> %u sets), poolCount=%zu",
|
||||
frameIndex, currentMaxSets, grownMaxSets, frame.descriptorPools.size());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3144,10 +2809,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
Bool UniformManager::PrepareWireTextureResources(const MagmaProgramSource& program,
|
||||
const ProgramFactory::VkProgramObject& programObj) {
|
||||
if (!program.IsWire()) return true;
|
||||
if (programObj.declinedDescriptors || m_textureManager == nullptr) {
|
||||
MGL_WIRE_DECLINE_AT(DescriptorDeclined, "the program carries a descriptor MobileGL could not resolve");
|
||||
return false;
|
||||
}
|
||||
if (programObj.declinedDescriptors || m_textureManager == nullptr) return false;
|
||||
const auto& state = MG_Pipe::MGPipeApplier();
|
||||
// Resolve writable images first: aliases sampled by the same draw must
|
||||
// see the final STORAGE-capable allocation before any view is built.
|
||||
@@ -3161,28 +2823,16 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
const Uint32 count = BindingDescriptorCount(programObj, binding);
|
||||
for (Uint32 element = 0; element < count; ++element) {
|
||||
const Int location = baseLocation + static_cast<Int>(element);
|
||||
if (baseLocation < 0 || !program.UniformLocationsAliasSameUniform(baseLocation, location)) {
|
||||
MGL_WIRE_DECLINE_AT(SamplerLocationAlias,
|
||||
"binding %u element %u does not alias one sampler uniform", binding,
|
||||
element);
|
||||
if (baseLocation < 0 || !program.UniformLocationsAliasSameUniform(baseLocation, location))
|
||||
return false;
|
||||
}
|
||||
const Int unit = program.GetUniformSamplerOrImageUnitIndex(static_cast<Uint>(location));
|
||||
if (unit < 0 || static_cast<Uint32>(unit) >=
|
||||
(storage ? MG_Pipe::kMGPipeMaxImageUnits : MG_Pipe::kMGPipeMaxTextureUnits)) {
|
||||
MGL_WIRE_DECLINE_AT(SamplerUnitRange, "sampler/image unit %d is out of range", unit);
|
||||
return false;
|
||||
}
|
||||
(storage ? MG_Pipe::kMGPipeMaxImageUnits : MG_Pipe::kMGPipeMaxTextureUnits)) return false;
|
||||
const auto handle = storage ? state.BoundShaderImages[unit].Res
|
||||
: state.BoundSamplerViews[unit].Texture;
|
||||
// Null is the wire's unbound/incomplete binding. Its native
|
||||
// placeholder needs no resource upload or frontend allocation.
|
||||
if (MG_Pipe::MGPipeHandleIsNull(handle)) continue;
|
||||
// Nor does an image unit naming a (level, layer) its texture lacks: the
|
||||
// descriptor resolve binds that same placeholder (GL 4.6 core 8.26), and
|
||||
// preparing the texture would decline a storage-less one and lose the pass.
|
||||
if (storage && WireShaderImageNamesNoTexel(*m_textureManager, state.BoundShaderImages[unit]))
|
||||
continue;
|
||||
if (!m_textureManager->SyncTextureResourceByHandle(handle, false, storage)) return false;
|
||||
}
|
||||
}
|
||||
@@ -3230,12 +2880,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
(samplerBindingOverrides == nullptr || samplerBindingOverrides->empty());
|
||||
if (cacheable && samplerDescriptorsUnchangedHint && m_fastRebindMemo.valid &&
|
||||
m_fastRebindMemo.frameIndex == frameIndex &&
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// A wire store destroyed since the memo was taken may have handed its handle
|
||||
// value to a later mint (see FastRebindMemo): "same VkBuffer" then names a
|
||||
// different store, so the memo is refused and the full walk re-records it.
|
||||
m_fastRebindMemo.wireStoreDestroyEpoch == m_bufferManager->GetWireStoreDestroyEpoch() &&
|
||||
#endif
|
||||
m_fastRebindMemo.programLifetimeId == program.GetLifetimeId() &&
|
||||
m_fastRebindMemo.programHash == programObj.hash) {
|
||||
VkBuffer uboBuffer = VK_NULL_HANDLE;
|
||||
@@ -3532,16 +3176,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
}
|
||||
};
|
||||
mixWords(&programObj.descriptorSetLayout, sizeof(programObj.descriptorSetLayout));
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P7 M2 round 2 (ID-P7-43): the buffer infos below name WIRE stores by VkBuffer
|
||||
// handle, and a wire store can be destroyed mid-frame (VkBufferManager::
|
||||
// DeferredWireRelease) with its handle value re-minted before this frame's memo
|
||||
// is cleared. Folding the destroy epoch in makes every entry taken before such a
|
||||
// destroy miss, so a byte-identical info can never revive a set baked to a dead
|
||||
// store. NOT the slice epoch: that moves on every glBufferSubData and would make
|
||||
// the memo miss on every draw.
|
||||
mix64(m_bufferManager->GetWireStoreDestroyEpoch());
|
||||
#endif
|
||||
for (const auto& write : writes) {
|
||||
mix64((static_cast<Uint64>(write.dstBinding) << 40) ^
|
||||
(static_cast<Uint64>(write.descriptorType) << 8) ^
|
||||
@@ -3596,11 +3230,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
m_fastRebindMemo = FastRebindMemo{
|
||||
/*valid=*/true, frameIndex, program.GetLifetimeId(), programObj.hash,
|
||||
fastRebindUboBinding, bufferInfos[0].buffer,
|
||||
bufferInfos[0].range, descriptorSet,
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
m_bufferManager->GetWireStoreDestroyEpoch(),
|
||||
#endif
|
||||
};
|
||||
bufferInfos[0].range, descriptorSet};
|
||||
} else {
|
||||
m_fastRebindMemo.valid = false;
|
||||
}
|
||||
|
||||
@@ -13,8 +13,6 @@
|
||||
#include "VkBufferManager.h"
|
||||
#include "VkSamplerManager.h"
|
||||
#include "VkTextureManager.h"
|
||||
#include "WirePlaceholderKey.h"
|
||||
#include "../DescriptorPoolCensus.h"
|
||||
#include "../VkIncludes.h"
|
||||
#include <Includes.h>
|
||||
|
||||
@@ -56,25 +54,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
void Shutdown();
|
||||
|
||||
void BeginFrame(Uint32 frameIndex);
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// A present-less wire frame may run arbitrarily many draws. Before its
|
||||
// descriptor cursor reaches this budget, the renderer retires the
|
||||
// submission that last used the sets and rewinds every layout cursor.
|
||||
static constexpr Uint32 kWireDescriptorSetBudget = 2048;
|
||||
Bool WireDescriptorSetBudgetReached(Uint32 frameIndex) const;
|
||||
SizeT RewindWireDescriptorSets(Uint32 frameIndex);
|
||||
// How the wire arm answers a STORAGE image unit that GL 4.6 core 8.26 makes invalid (no
|
||||
// texture, or a (level, layer) its texture lacks): a load returns zero, a store and an
|
||||
// atomic are discarded. `deviceNullDescriptor` is the renderer's enablement of
|
||||
// VK_EXT_robustness2's nullDescriptor at device creation. With it the unit binds a NULL
|
||||
// storage-image descriptor, which is exactly that rule. Without it (or under
|
||||
// MGITEST_MAGMA_FORCE_PRIVATE_IMAGE_PLACEHOLDER=1, the host lanes' way onto this arm) the
|
||||
// unit binds a placeholder PRIVATE to its unit (per shape), cleared before each use, so no
|
||||
// two units ever alias; what that cannot give is a load of the SAME unit after its own
|
||||
// store inside one pass reading zero, nor privacy past kWirePrivateStoragePlaceholderCap
|
||||
// placeholders (CONTRACT-P7 §12). Called after Initialize.
|
||||
void SetWireInvalidStorageImageArm(Bool deviceNullDescriptor);
|
||||
#endif
|
||||
// A command buffer (re)began recording: descriptor bindings recorded into
|
||||
// the previous buffer do not carry over, so drop the bind-dedup shadow.
|
||||
void OnCommandBufferBoundary() { m_lastBindValid = false; }
|
||||
@@ -85,11 +64,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// FREE_DESCRIPTOR_SET_BIT) and the pool accounting is credited, so program
|
||||
// churn recycles pool capacity instead of abandoning it. GPU-safe: the layout
|
||||
// only dies after >1024 idle frame boundaries, so no in-flight command buffer
|
||||
// references its sets. This is the only PER-LAYOUT eviction path for the
|
||||
// caches - a live layout's entry must never be purged on its own (its sets would be
|
||||
// unreachable pool slots), so there is deliberately no age-based sweep here. The
|
||||
// other path, TrimFrameDescriptorPools, drops a slot's whole cache together with
|
||||
// the pools behind it.
|
||||
// references its sets. This is the only eviction path for the per-layout
|
||||
// caches - a live layout's entry must never be purged (its sets would be
|
||||
// unreachable pool slots), so there is deliberately no age-based sweep here.
|
||||
void OnDescriptorSetLayoutDestroyed(VkDescriptorSetLayout descriptorSetLayout);
|
||||
// One record per visited CombinedImageSampler DESCRIPTOR (post fallback substitution,
|
||||
// in binding order, and within a binding in array-element order): the resolved texture
|
||||
@@ -161,46 +138,13 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
static Bool ProgramSamplesOnlySingleLevelTextures(const MagmaProgramSource& program,
|
||||
const ProgramFactory::VkProgramObject& programObj);
|
||||
|
||||
// ---- per-frame descriptor pools ----------------------------------------------------
|
||||
// Each frame slot owns a list of pools. The first is the base pool (non-update-after-bind,
|
||||
// setsPerFrame sets) and is never destroyed while the manager lives; every later one was
|
||||
// added by GrowFrameDescriptorPool when an allocation found no room. A pool serves one
|
||||
// updateAfterBind flavour, because a set can only come from a pool created with the flag
|
||||
// its layout was.
|
||||
private:
|
||||
struct DescriptorPoolBucket {
|
||||
VkDescriptorPool handle = VK_NULL_HANDLE;
|
||||
Uint32 maxSets = 0;
|
||||
Uint32 allocatedSets = 0;
|
||||
Bool updateAfterBind = false;
|
||||
};
|
||||
// One pool's maxSets never exceeds this. It bounds one pool's driver memory: CreateDescriptorPool
|
||||
// declares 8 descriptors of each of 6 types per set, so a 4096-set pool asks for 196,608
|
||||
// descriptors - about 12 MiB at 64 bytes each on a driver that backs every declared one.
|
||||
static constexpr Uint32 kMaxDescriptorPoolSets = 4096;
|
||||
// The growth policy, pure so the host tests can drive it: the size of the next pool a slot
|
||||
// adds for `updateAfterBind` layouts, given the slot's existing pools. Twice the LARGEST pool
|
||||
// of that flavour, capped at kMaxDescriptorPoolSets; `initialMaxSets` when the slot has no
|
||||
// pool of that flavour yet. So a frame that needs N sets adds O(log N) pools while N stays
|
||||
// under the cap, and one more pool per kMaxDescriptorPoolSets sets beyond it. Taking the
|
||||
// largest (not the first) pool is the point: the first same-flavour pool is the oldest,
|
||||
// smallest one, and doubling IT made every grown pool the same size.
|
||||
static Uint32 NextDescriptorPoolMaxSets(const Vector<DescriptorPoolBucket>& pools, Bool updateAfterBind,
|
||||
Uint32 initialMaxSets);
|
||||
// Trim policy (see TrimFrameDescriptorPools). A slot is "quiet" in an epoch whose peak set
|
||||
// count times kDescriptorTrimHeadroom still fits its capacity; a slot that has been quiet for
|
||||
// MOBILEGL_MAGMA_DESCRIPTOR_TRIM_FRAMES consecutive epochs, and holds at least
|
||||
// kDescriptorTrimMinCapacity sets, is trimmed. The headroom is what keeps the trim from
|
||||
// thrashing: geometric growth leaves a re-grown slot at least a third full (the pool a growth
|
||||
// adds is at most twice the largest before it, so at most twice everything the slot held, and
|
||||
// the epoch that grew it needed more than that), so the epoch that grew a slot is never quiet
|
||||
// for it. The floor keeps a slot sized for ordinary
|
||||
// frames from being trimmed at all - the trim exists to give back a burst.
|
||||
static constexpr Uint32 kDescriptorTrimHeadroom = 4;
|
||||
static constexpr Uint32 kDescriptorTrimMinCapacity = 1024;
|
||||
// For tests (DescriptorPoolCensus.h): pools, capacity, cached sets and trims over every slot.
|
||||
DescriptorPoolCensus GetDescriptorPoolCensus() const;
|
||||
|
||||
private:
|
||||
|
||||
// A cached descriptor set together with the pool it was allocated from, so a
|
||||
// layout-destroyed purge can vkFreeDescriptorSets it back and credit the
|
||||
@@ -258,27 +202,13 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
Uint32 layers = 1;
|
||||
};
|
||||
// Keyed by shape, and a storage placeholder on the arm without a null descriptor by its
|
||||
// image unit too (WirePlaceholderKey.h: ChooseWirePlaceholderKey, and its cap).
|
||||
mutable UnorderedMap<WirePlaceholderKey, WirePlaceholderImage, WirePlaceholderKeyHash> m_wirePlaceholderImages;
|
||||
// How many of those are private to a unit (against kWirePrivateStoragePlaceholderCap).
|
||||
mutable SizeT m_wirePrivateStoragePlaceholders = 0;
|
||||
// See SetWireInvalidStorageImageArm.
|
||||
Bool m_wireInvalidStorageImagesBindNull = false;
|
||||
// boundStorageFormat: for a storage binding with no reflected format, the format the
|
||||
// unit's glBindImageTexture named, when the unit holds a texture it cannot address
|
||||
// (GL 4.6 core 8.26); UNDEFINED keeps the numeric-domain R32 default. `unit` is the image
|
||||
// unit of a storage binding (what its private placeholder is private to); unused for a sampler.
|
||||
mutable UnorderedMap<Uint64, WirePlaceholderImage> m_wirePlaceholderImages;
|
||||
Bool ResolveWirePlaceholderImage(VkCommandBuffer commandBuffer, const MagmaProgramSource& program,
|
||||
const ProgramFactory::VkProgramObject& programObj, Uint32 binding, Bool storage,
|
||||
VkDescriptorImageInfo& out, VkFormat boundStorageFormat = VK_FORMAT_UNDEFINED, Uint32 unit = ~0u) const;
|
||||
VkDescriptorImageInfo& out) const;
|
||||
void DestroyWirePlaceholderImage(WirePlaceholderImage& image) const;
|
||||
#endif
|
||||
|
||||
// descriptorSetCacheByLayout is the per-frame set cache: BeginFrame rewinds every cursor, so
|
||||
// a slot re-writes the sets it allocated in earlier frames instead of allocating new ones, and
|
||||
// the cache only ever grows - except through TrimFrameDescriptorPools, which gives a slot's
|
||||
// whole burst back at once (and OnDescriptorSetLayoutDestroyed, one dead layout at a time).
|
||||
struct FrameResources {
|
||||
Vector<DescriptorPoolBucket> descriptorPools;
|
||||
UnorderedMap<VkDescriptorSetLayout, DescriptorSetCacheEntry> descriptorSetCacheByLayout;
|
||||
@@ -292,10 +222,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
Uint32 activeDescriptorPoolIndex = 0;
|
||||
Uint32 allocatedSetsThisFrame = 0;
|
||||
Uint32 peakAllocatedSetsThisFrame = 0;
|
||||
// Sum of maxSets over descriptorPools, kept in step by Initialize, Grow and Trim.
|
||||
Uint64 capacitySets = 0;
|
||||
// Consecutive epochs (see NoteEndedEpochForTrim) that were quiet for THIS slot's capacity.
|
||||
Uint32 quietEpochs = 0;
|
||||
};
|
||||
|
||||
static Bool ResolveSamplerTexture(const MagmaProgramSource& program,
|
||||
@@ -439,28 +365,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
const Vector<Uint32>& dynamicOffsets);
|
||||
Bool CreateDescriptorPool(Uint32 maxSets, Bool updateAfterBind, VkDescriptorPool& outPool) const;
|
||||
Bool GrowFrameDescriptorPool(FrameResources& frame, Uint32 frameIndex, Bool updateAfterBind);
|
||||
// An epoch is the stretch between two BeginFrame calls: one frame, or the part of one between
|
||||
// two drains (VulkanRenderer::TryDrainFrameTransients). Called by BeginFrame with the epoch
|
||||
// that just ended, it updates every slot's quiet count - a burst in any slot counts against
|
||||
// all of them, so bursts that land in the other slots still hold a slot's trim off.
|
||||
void NoteEndedEpochForTrim(Uint32 epochPeakSets);
|
||||
// Gives a slot's whole descriptor burst back: clears its per-layout cache, destroys every
|
||||
// grown pool and resets the base pool, so the slot re-grows geometrically from setsPerFrame.
|
||||
// Whole-slot rather than per-set: vkFreeDescriptorSets fragments a pool and can never empty
|
||||
// a grown one. Called only from BeginFrame, which runs only when no pending command buffer
|
||||
// references the slot's sets:
|
||||
// - Present path (VulkanRenderer::Present, after WaitAndAcquireNextImage): the slot's
|
||||
// imageInFlightFence has been waited. That fence rides the slot's LAST submission - the
|
||||
// Present submit - and every mid-frame submission of the slot (FlushPendingCommands,
|
||||
// SplitOversizedRecording, readbacks) went to the same queue earlier, so the fence's
|
||||
// signal covers them (vkQueueSubmit's fence scope includes all earlier submissions).
|
||||
// - Drain path (VulkanRenderer::TryDrainFrameTransients): every submission has been
|
||||
// observed complete and no recording is open.
|
||||
// Sets are per slot: a slot's sets are only ever bound into recordings made while it is the
|
||||
// current slot, so trimming one slot never touches another slot's in-flight work.
|
||||
void TrimFrameDescriptorPools(FrameResources& frame, Uint32 frameIndex);
|
||||
// Drops every handle this class holds to a descriptor set outside the per-layout caches.
|
||||
void InvalidateDescriptorSetMemos();
|
||||
VkResult AllocateDescriptorSetsFromActivePool(
|
||||
Uint32 frameIndex, const ProgramFactory::VkProgramObject& programObj, VkDescriptorSet& outDescriptorSet);
|
||||
VkResult AcquireDescriptorSet(Uint32 frameIndex,
|
||||
@@ -478,13 +382,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
Uint32 m_maxBindings = 0;
|
||||
Uint32 m_setsPerFrame = 0;
|
||||
Uint32 m_peakDescriptorSetsObserved = 0;
|
||||
// MOBILEGL_MAGMA_DESCRIPTOR_TRIM_FRAMES, latched at Initialize (0 = never trim).
|
||||
Uint32 m_trimQuietEpochs = 0;
|
||||
// The slot whose epoch is open (the last one BeginFrame was called for); valid once
|
||||
// m_epochOpen is set. Its peak is the ended epoch's peak at the next BeginFrame.
|
||||
Uint32 m_epochSlot = 0;
|
||||
Bool m_epochOpen = false;
|
||||
Uint64 m_descriptorSlotTrims = 0;
|
||||
VkTextureManager* m_textureManager = nullptr;
|
||||
VkSamplerManager* m_samplerManager = nullptr;
|
||||
mutable SharedPtr<MG_State::GLState::ITextureObject> m_fallbackTexture2D;
|
||||
@@ -545,15 +442,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// drops the hint upstream; an arena wrap or growth resolves a different
|
||||
// VkBuffer and misses. AcquireDescriptorSet's per-frame cursor only
|
||||
// advances, so the recorded set is never re-written within its frame.
|
||||
// P7 M2 round 2 (ID-P7-43): a WIRE store can die MID-FRAME on the reclaim
|
||||
// path (VkBufferManager::DeferredWireRelease), and the next mint can hand
|
||||
// its VkBuffer handle value back - a heap pointer under lavapipe - so "the
|
||||
// same VkBuffer+range" is no longer proof of the same store. The memo
|
||||
// therefore records VkBufferManager::GetWireStoreDestroyEpoch() and misses
|
||||
// once any wire store has been destroyed since; the descriptor-reuse
|
||||
// signature below folds the same epoch in. On the wire arm this memo is
|
||||
// never consulted (SetupWireDraw passes no sampler hint), so the field is
|
||||
// the defensive half; the signature is the half the wire arm reaches.
|
||||
struct FastRebindMemo {
|
||||
Bool valid = false;
|
||||
Uint32 frameIndex = 0;
|
||||
@@ -563,9 +451,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
VkBuffer uboBuffer = VK_NULL_HANDLE;
|
||||
VkDeviceSize uboRange = 0;
|
||||
VkDescriptorSet set = VK_NULL_HANDLE;
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
Uint64 wireStoreDestroyEpoch = 0;
|
||||
#endif
|
||||
};
|
||||
FastRebindMemo m_fastRebindMemo;
|
||||
|
||||
|
||||
@@ -442,94 +442,41 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
for (Uint32 location = 0; location < elements.AttributeCount; ++location) {
|
||||
const auto& attr = elements.Attributes[location];
|
||||
if (!attr.Enabled || !(activeMask & (1u << location))) continue;
|
||||
// P7 wave 2 package C, CONTRACT-P7 §3.2 `vertex-layout`: THE ONE STRING BECAME TWO
|
||||
// VERDICTS, and the split is by what the reason is ABOUT rather than by severity.
|
||||
//
|
||||
// Every reason here used to return false, and the single caller answered that with
|
||||
// one P7-marked MagmaWireFatal - an abort, bypassing Session::Fail, invisible
|
||||
// to the census gate and with no equivalent on the monolith arm at all. But the
|
||||
// reasons are not one kind of thing:
|
||||
//
|
||||
// * `buffer-window` is a statement about the RECORD: an enabled attribute the
|
||||
// program reads names a slot outside the window set_vertex_buffers published.
|
||||
// Nothing about the device or the format is involved; the two halves of the
|
||||
// protocol disagree about what crossed. It stays a named Fatal through the hook
|
||||
// (see the caller), and it is load-bearing rather than defensive - it is what
|
||||
// caught the Redmi VAO hash collision fixed in 376c04be.
|
||||
//
|
||||
// * every other reason is a statement about what VULKAN CAN EXPRESS on this
|
||||
// device: a GL type with no VkFormat, a format without
|
||||
// VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT, a component size we cannot compute, an
|
||||
// offset sum that does not fit. The monolith arm has had an answer for these
|
||||
// since it was written, and it is not an abort: mask the attribute out of the
|
||||
// vertex input state and carry on (the `unsupportedAttribMask |= ...; continue;`
|
||||
// sites in GetOrCreateVertexInputState above). The draw path then decides,
|
||||
// loudly and once, whether the masked attribute was one the program actually
|
||||
// reads. This arm now does exactly that, which is what "same observable as the
|
||||
// monolith lane" means for this row.
|
||||
//
|
||||
// THE COUNT: the contract says "the other six"; there are SEVEN return sites below
|
||||
// it, because `offset-overflow` was added after the audit's count and is an
|
||||
// arithmetic guard rather than a shape one. It is masked with the rest: an
|
||||
// attribute whose base offsets cannot be added is one Vulkan cannot fetch, the
|
||||
// monolith arm never computes that sum at all, and masking is strictly safer than
|
||||
// a Fatal for a number no application can reach on purpose. Recorded in
|
||||
// notes/p7/magma-c.md rather than silently reconciled.
|
||||
const auto describe = [&](const char* reason, VkFormat format) {
|
||||
MGLOG_E_ONCE("Magma wire vertex layout: %s location=%u type=%u size=%u normalized=%u integer=%u long=%u bgra=%u stride=%d offset=%llu format=%d bufferWindow=%u+%u activeMask=0x%x",
|
||||
const auto reject = [&](const char* reason, VkFormat format = VK_FORMAT_UNDEFINED) {
|
||||
MGLOG_E("Magma wire vertex layout: %s location=%u type=%u size=%u normalized=%u integer=%u long=%u bgra=%u stride=%d offset=%llu format=%d bufferWindow=%u+%u activeMask=0x%x",
|
||||
reason, location, attr.Type, static_cast<Uint32>(attr.Size), static_cast<Uint32>(attr.Normalized),
|
||||
static_cast<Uint32>(attr.IsInteger), static_cast<Uint32>(attr.IsLong), static_cast<Uint32>(attr.IsBgra),
|
||||
attr.Stride, static_cast<unsigned long long>(attr.Offset), static_cast<Int>(format),
|
||||
state.VertexBufferStart, state.VertexBufferCount, activeMask);
|
||||
};
|
||||
// The protocol verdict: the caller turns a false into the named Fatal.
|
||||
const auto reject = [&](const char* reason, VkFormat format = VK_FORMAT_UNDEFINED) {
|
||||
describe(reason, format);
|
||||
return false;
|
||||
};
|
||||
// The device verdict: MGLOG_E_ONCE + mask + continue, the monolith arm's shape.
|
||||
// MGLOG_E_ONCE and not MGLOG_E, also the monolith arm's: an unmappable attribute is
|
||||
// a property of the VAO and the device, so it repeats every draw, and the per-draw
|
||||
// line is what made the old abort look preferable to whoever wrote it.
|
||||
const auto maskOut = [&](const char* reason, VkFormat format = VK_FORMAT_UNDEFINED) {
|
||||
describe(reason, format);
|
||||
out.unsupportedAttribMask |= 1u << location;
|
||||
};
|
||||
// set_vertex_buffers is flattened PER ATTRIBUTE (VertexInputEmit.h), not
|
||||
// indexed by the original ARB binding point in attr.BindingIndex.
|
||||
if (location < state.VertexBufferStart ||
|
||||
location - state.VertexBufferStart >= state.VertexBufferCount) return reject("buffer-window");
|
||||
const auto& buffer = state.VertexBuffers[location];
|
||||
const auto type = static_cast<DataType>(attr.Type);
|
||||
if (attr.Stride < 0 || attr.Size < 1 || attr.Size > 4) { maskOut("attribute-shape"); continue; }
|
||||
if (attr.Stride < 0 || attr.Size < 1 || attr.Size > 4) return reject("attribute-shape");
|
||||
VkFormat format = ToVkVertexFormat(type, attr.Size, attr.Normalized, attr.IsInteger,
|
||||
attr.IsBgra, attr.IsLong);
|
||||
auto conversion = VertexStreamConversion::None;
|
||||
if (format == VK_FORMAT_UNDEFINED && type == DataType::Float64) {
|
||||
const auto* backend = MG_Remote::Server::ServerLoopInstance().Backend();
|
||||
if (backend && backend->GetDynamicParameters().SupportsFloat64VertexAttributes) {
|
||||
// Exactly the monolith arm's answer for the same state: with native fp64
|
||||
// the module KEPT its 64-bit inputs (DemoteFloat64Pass did not run), so
|
||||
// narrowing the stream would feed float32 to a Float64 input - and the
|
||||
// monolith build therefore leaves sourceVkFormat UNDEFINED and falls into
|
||||
// its own mask-out below. Same place, same mask.
|
||||
maskOut("native-fp64-format");
|
||||
continue;
|
||||
}
|
||||
if (backend && backend->GetDynamicParameters().SupportsFloat64VertexAttributes) return reject("native-fp64-format");
|
||||
format = ToFloat32VertexFormat(attr.Size);
|
||||
conversion = VertexStreamConversion::Float64ToFloat32;
|
||||
}
|
||||
if (format == VK_FORMAT_UNDEFINED) { maskOut("format-map"); continue; }
|
||||
if (format == VK_FORMAT_UNDEFINED) return reject("format-map");
|
||||
if (!SupportsVertexBufferFormat(format)) {
|
||||
if (!IsScaledIntegerVertexFormat(format)) { maskOut("native-format-feature", format); continue; }
|
||||
if (!IsScaledIntegerVertexFormat(format)) return reject("native-format-feature", format);
|
||||
format = ToFloat32VertexFormat(attr.Size);
|
||||
conversion = VertexStreamConversion::ScaledIntegerToFloat32;
|
||||
if (!SupportsVertexBufferFormat(format)) { maskOut("converted-format-feature", format); continue; }
|
||||
if (!SupportsVertexBufferFormat(format)) return reject("converted-format-feature", format);
|
||||
}
|
||||
const SizeT elementSize = GetAttributeByteSize(type, attr.Size, attr.IsBgra);
|
||||
if (!elementSize) { maskOut("element-size", format); continue; }
|
||||
if (!elementSize) return reject("element-size", format);
|
||||
const Uint64 offset = attr.Offset + buffer.Offset;
|
||||
if (offset < attr.Offset) { maskOut("offset-overflow", format); continue; }
|
||||
if (offset < attr.Offset) return reject("offset-overflow", format);
|
||||
const SizeT alignment = (type == DataType::Int2101010Rev || type == DataType::Uint2101010Rev)
|
||||
? elementSize : GetComponentSize(type);
|
||||
if (conversion == VertexStreamConversion::None && alignment > 1 &&
|
||||
@@ -553,15 +500,8 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// resolved binding/attribute/divisor values, including a legal zero stride.
|
||||
Uint64 hash = XXH64(out.bindings.data(), out.bindings.size() * sizeof(out.bindings[0]), 0);
|
||||
hash = XXH64(out.attributes.data(), out.attributes.size() * sizeof(out.attributes[0]), hash);
|
||||
hash = XXH64(out.bindingDivisors.data(),
|
||||
out.layoutHash = XXH64(out.bindingDivisors.data(),
|
||||
out.bindingDivisors.size() * sizeof(out.bindingDivisors[0]), hash);
|
||||
// THE MASK IS PART OF THE LAYOUT NOW, for the same reason the monolith entry's hash
|
||||
// carries it (the XXH64_update over unsupportedAttribMask in GetOrCreateVertexInputState
|
||||
// above). Before this package the mask was always zero here, so leaving it out of the
|
||||
// hash was free; now two VAOs can produce the SAME bindings, attributes and divisors
|
||||
// and differ only in which enabled attribute was masked out, and a hash blind to that
|
||||
// would serve one of them the other's pipeline.
|
||||
out.layoutHash = XXH64(&out.unsupportedAttribMask, sizeof(out.unsupportedAttribMask), hash);
|
||||
out.state.vertexBindingDescriptionCount = static_cast<Uint32>(out.bindings.size());
|
||||
out.state.pVertexBindingDescriptions = out.bindings.data();
|
||||
out.state.vertexAttributeDescriptionCount = static_cast<Uint32>(out.attributes.size());
|
||||
|
||||
@@ -15,65 +15,12 @@
|
||||
#include "MG_Pipe/MGPipeCallbacks.h"
|
||||
#include "MG_Pipe/PipeApply.h"
|
||||
#include "MG_Remote/Server/StagedShadow.h"
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
#include "MG_Remote/Transport/AdoptT0.h"
|
||||
#endif
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED && defined(__ANDROID__)
|
||||
#include <android/hardware_buffer.h>
|
||||
#endif
|
||||
#include <Config.h>
|
||||
#include <chrono>
|
||||
#include <cstdlib>
|
||||
#endif
|
||||
|
||||
namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
namespace {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P7 wave 2 package B3, INVESTIGATION PROBE (split-only, read once, not in
|
||||
// ConfigLoader's accepted-env table - package B's MGITEST_MAGMA_FORCE_SHADER_MIPMAP
|
||||
// shape). MOBILEGL_MAGMA_WIREBUF_PROBE=1 prints one line per streamed-buffer event so
|
||||
// the `glBufferSubData -> draw` ordering of a trace can be read off a log instead of
|
||||
// inferred. Costs a branch on a cached bool when unset.
|
||||
Bool WireBufProbeEnabled() {
|
||||
static const Bool enabled = [] {
|
||||
const char* value = std::getenv("MOBILEGL_MAGMA_WIREBUF_PROBE");
|
||||
return value && value[0] == '1';
|
||||
}();
|
||||
return enabled;
|
||||
}
|
||||
|
||||
// P7 wave 2 package B3, FORCING KNOB (split-only, read once, not in ConfigLoader's
|
||||
// accepted-env table - package B's MGITEST_MAGMA_FORCE_SHADER_MIPMAP shape).
|
||||
//
|
||||
// WriteWireBuffer has exactly one unsafe shape: taking the immediate host memcpy
|
||||
// because `lastUseSerial > GetCompletedSerial()` said the buffer is idle. That
|
||||
// predicate's first term is PURE COUNTING (`m_frameSerial - frameCount`, no fence),
|
||||
// so on any arm where the frame serial advances without the GPU having proved the
|
||||
// frame's submissions complete, the answer is a guess. Host lanes never reach that
|
||||
// state on their own (measured: 0 mid-frame frame-boundary drains over the whole
|
||||
// OpenRA replay), so the lane cannot arm against it without forcing it.
|
||||
//
|
||||
// 0/unset = off. 1 = the serial term answers "idle" for every write it would have
|
||||
// ordered. N>1 = only the Nth such write (1-based), which is how one
|
||||
// `glBufferSubData -> draw` pair is poisoned in isolation and the device's "one draw
|
||||
// contributed nothing" signature is reproduced rather than the whole frame destroyed.
|
||||
//
|
||||
// The knob forces ONLY the counting term to lie. It does NOT bypass the ordered copy,
|
||||
// so it stays a valid red-once across the fix: before the submission term existed the
|
||||
// lie reached the host memcpy (red); with the submission term the lie is caught and
|
||||
// the copy is still ordered (green).
|
||||
Uint64 ForceStaleSerialSelector() {
|
||||
static const Uint64 selector = [] {
|
||||
const char* value = std::getenv("MGITEST_MAGMA_FORCE_STALE_BUFFER_SERIAL");
|
||||
if (!value || !value[0]) return Uint64{0};
|
||||
return static_cast<Uint64>(std::strtoull(value, nullptr, 10));
|
||||
}();
|
||||
return selector;
|
||||
}
|
||||
// Counts only the writes the busy predicate wanted to ORDER, so the selector indexes
|
||||
// the streamed subdata -> draw pairs and nothing else.
|
||||
Uint64 g_orderedWireWriteCounter = 0;
|
||||
#endif
|
||||
constexpr VmaAllocationCreateFlags kResidentBufferAllocationFlags =
|
||||
VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT;
|
||||
constexpr SizeT kLiveResourcePruneThreshold = 256;
|
||||
@@ -213,16 +160,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// modified ranges. A server pointer is never donated across the wire.
|
||||
.MapPersistent = [](MG_Pipe::MGPipeHandle, Uint64, const void*) -> void* { return nullptr; },
|
||||
.UnmapPersistent = [](MG_Pipe::MGPipeHandle) {},
|
||||
#if defined(__ANDROID__)
|
||||
// P11 B2 (T0): the one door a server pointer is still never donated through stays shut;
|
||||
// what T0 adds is the other direction - the CLIENT's pages imported as the store.
|
||||
.ImportExternal = [](MG_Pipe::MGPipeHandle res, void* ahb, Uint64 size) -> Bool {
|
||||
return WireManager().ImportWireBuffer(res, ahb, size);
|
||||
},
|
||||
.SelfTestExternal = [](char* why, Uint64 whyBytes) -> Bool {
|
||||
return VkBufferManager::SelfTestWireImport(why, whyBytes);
|
||||
},
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
} // namespace
|
||||
@@ -257,22 +194,10 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
res.Slot, res.Gen);
|
||||
std::abort();
|
||||
}
|
||||
// THE SERIAL IS READ BEFORE THE RESET BELOW ZEROES IT. Whether it is zero - whether any
|
||||
// GPU command has named this store - decides whether the orphan can go at once or has
|
||||
// to wait for a submission (DeferredWireRelease), and three lines from now the record
|
||||
// no longer carries it.
|
||||
const Uint64 orphanedUseSerial = resource->lastUseSerial;
|
||||
// P11 B2: a T0 store is ALWAYS released through the serial-gated list (never "at once"),
|
||||
// so the client's AHardwareBuffer outlives every submission that can still name it however
|
||||
// the client's own release (at this respecify) raced the frames in flight.
|
||||
DeferWireRelease(std::move(resource->buffer),
|
||||
resource->imported ? T0ReleaseSerial(orphanedUseSerial) : orphanedUseSerial);
|
||||
resource->imported = false;
|
||||
DeferRelease(std::move(resource->buffer));
|
||||
resource->size = desc.Width;
|
||||
resource->lastUseSerial = 0;
|
||||
resource->lastUseSubmitIndex = 0; // M2 r2: the new store carries no submission yet (B3's stamp is per store)
|
||||
resource->gpuWritesPending = false;
|
||||
resource->indirectReadBarrierPending = false;
|
||||
resource->stagedCoverage.clear();
|
||||
++m_sliceEpochCounter;
|
||||
if (resource->size == 0) return;
|
||||
@@ -291,9 +216,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
res.Slot, res.Gen, static_cast<unsigned long long>(resource->size));
|
||||
std::abort();
|
||||
}
|
||||
++m_wireStoreCount;
|
||||
NoteWireStorePeaks();
|
||||
PublishWireReclaimGauges();
|
||||
// Under transport, defined bytes follow as resource_subdata records. An
|
||||
// undefined store has no shadow to upload and no implicit zero snapshot.
|
||||
if (initialBytes != nullptr && desc.HasDefinedContent) {
|
||||
@@ -302,13 +224,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
}
|
||||
|
||||
Bool VkBufferManager::WaitForWireBufferHostAccess(WireBufferResource& resource) {
|
||||
// B3 review: the early return must consult the same submission term WriteWireBuffer
|
||||
// does, or a caller that reaches here with the serial term idle skips the wait the
|
||||
// term would have demanded.
|
||||
if (resource.lastUseSerial <= GetCompletedSerial() && !resource.gpuWritesPending &&
|
||||
(pVulkanRenderer == nullptr || pVulkanRenderer->IsSubmitIndexComplete(resource.lastUseSubmitIndex))) {
|
||||
return true;
|
||||
}
|
||||
if (resource.lastUseSerial <= GetCompletedSerial() && !resource.gpuWritesPending) return true;
|
||||
if (!m_copyProvider || !pVulkanRenderer) return false;
|
||||
const VkCommandBuffer commands = m_copyProvider->AcquireBufferCopyCommandBuffer();
|
||||
if (commands == VK_NULL_HANDLE) return false;
|
||||
@@ -317,25 +233,10 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
barrier.dstAccessMask = VK_ACCESS_HOST_READ_BIT | VK_ACCESS_HOST_WRITE_BIT;
|
||||
vkCmdPipelineBarrier(commands, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_HOST_BIT,
|
||||
0, 1, &barrier, 0, nullptr, 0, nullptr);
|
||||
// P8-D: counted here, past the idle early-out, so `whw` is waits TAKEN, not calls.
|
||||
++m_wireHostWaits;
|
||||
const Bool timed = MG_Util::PipeStats::Enabled();
|
||||
const auto waitStart = timed ? std::chrono::steady_clock::now() : std::chrono::steady_clock::time_point{};
|
||||
const Bool waited =
|
||||
pVulkanRenderer->WaitForSubmitIndex(pVulkanRenderer->GetSyncPointSubmitIndex(), UINT64_MAX, true);
|
||||
if (timed) {
|
||||
MG_Util::PipeStats::AddCalls(MG_Util::PipeStats::CallClass::WireHostWaits, 1);
|
||||
MG_Util::PipeStats::AddCalls(MG_Util::PipeStats::CallClass::WireHostWaitMicros,
|
||||
static_cast<Uint64>(std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::steady_clock::now() - waitStart).count()));
|
||||
}
|
||||
if (!waited) {
|
||||
if (!pVulkanRenderer->WaitForSubmitIndex(pVulkanRenderer->GetSyncPointSubmitIndex(), UINT64_MAX, true)) {
|
||||
return false;
|
||||
}
|
||||
resource.lastUseSerial = 0;
|
||||
// B3: the wait above proved every submission at or below the sync point complete, so
|
||||
// the submission term must be cleared with the serial or it would keep answering busy.
|
||||
resource.lastUseSubmitIndex = 0;
|
||||
resource.gpuWritesPending = false;
|
||||
return true;
|
||||
}
|
||||
@@ -350,52 +251,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
}
|
||||
if (size == 0) return;
|
||||
Bool uploaded = false;
|
||||
const Uint64 probeLastUse = resource->lastUseSerial;
|
||||
const Uint64 probeCompleted = GetCompletedSerial();
|
||||
|
||||
// ---- P7 wave 2 package B3: WHAT EACH TERM OF THIS PREDICATE IS FOR -----------------
|
||||
//
|
||||
// A streamed `glBufferSubData -> draw` pair is only correct if the write is ordered
|
||||
// against every draw that still reads the bytes it overwrites; a write this predicate
|
||||
// answers "idle" is applied as an unsynchronised host memcpy, and a draw still reading
|
||||
// the range then renders bytes that are not its own - silently, with no log line, no GL
|
||||
// error and no Fatal. That was the OpenRA device divergence (magma-b3.md §2).
|
||||
//
|
||||
// THE GUARANTEE IS THE SERIAL TERM, and it is sound because of the FLOOR, not because
|
||||
// of anything here. GetCompletedSerial() is max(m_frameSerial - frameCount,
|
||||
// m_completedSerialFloor). The floor used to be raised to a retired submission's frame
|
||||
// serial even while another submission carrying the SAME serial was still executing -
|
||||
// on the wire arm a serial has two (a mid-frame FlushPendingCommands under a pooled
|
||||
// fence, then Present) - so "frame N-1 complete" was asserted on a fence nobody waited.
|
||||
// VulkanRenderer::OnSubmitsCompletedUpTo now raises it only to a serial no in-flight
|
||||
// submission still carries, and run_trace_case.cmake reds a split retrace on any
|
||||
// "MGWIRE-FLOOR unsound-serial-complete" line, which is that fix's lane.
|
||||
//
|
||||
// THE SUBMISSION TERM IS A PROBE AND A DEFENCE, NOT A SECOND GUARANTEE. It is not sound
|
||||
// on its own: lastUseSubmitIndex is stamped at AcquireWireSlice with the next submission
|
||||
// index, but the draw that acquired the slice can still be pushed into a LATER
|
||||
// submission - BindProgramUniformBuffers -> SyncWireTextureShape's preserve path ->
|
||||
// FlushWirePendingCommandsForTextureUpdate submits the stamped index without the draw -
|
||||
// so the stamp can name S1 while the draw rides S2. What it does do: with the floor
|
||||
// sound it should never be the term that says "busy" (the WBUF probe reports bySubmit
|
||||
// separately, so a device that shows one has found a floor hole), and it is the only
|
||||
// thing the MGITEST_MAGMA_FORCE_STALE_BUFFER_SERIAL knob leaves standing, which is what
|
||||
// the StaleSerial. entries pin.
|
||||
Bool busyBySerial = resource->lastUseSerial > GetCompletedSerial();
|
||||
if (busyBySerial && ForceStaleSerialSelector() != 0) {
|
||||
const Uint64 index = ++g_orderedWireWriteCounter;
|
||||
const Uint64 selector = ForceStaleSerialSelector();
|
||||
if (selector == 1 || selector == index) {
|
||||
busyBySerial = false;
|
||||
MGLOG_W("MGITEST_MAGMA_FORCE_STALE_BUFFER_SERIAL: write #%llu {slot=%u, gen=%u} off=%llu "
|
||||
"size=%llu - the counting term is forced to answer \"idle\"",
|
||||
static_cast<unsigned long long>(index), res.Slot, res.Gen,
|
||||
static_cast<unsigned long long>(offset), static_cast<unsigned long long>(size));
|
||||
}
|
||||
}
|
||||
const Bool busyBySubmission =
|
||||
pVulkanRenderer != nullptr && !pVulkanRenderer->IsSubmitIndexComplete(resource->lastUseSubmitIndex);
|
||||
if (busyBySerial || busyBySubmission) {
|
||||
if (resource->lastUseSerial > GetCompletedSerial()) {
|
||||
// Vulkan buffer copies require four-byte aligned ranges. An odd GL
|
||||
// byte update waits, then writes only the exact range; rounding it
|
||||
// from a CPU shadow could overwrite neighbouring GPU-written bytes.
|
||||
@@ -403,7 +259,10 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
uploaded = StagedWireRangeCopy(*resource, bytes, static_cast<SizeT>(offset),
|
||||
static_cast<SizeT>(size));
|
||||
}
|
||||
if (!uploaded && !WaitForWireBufferHostAccess(*resource)) WireBufferSyncFatal("host-write");
|
||||
if (!uploaded && !WaitForWireBufferHostAccess(*resource)) {
|
||||
MGLOG_F("Magma: Fatal{ResourceUnavailable, \"buffer-write-sync\"}");
|
||||
std::abort();
|
||||
}
|
||||
}
|
||||
if (!uploaded) {
|
||||
uploaded = resource->buffer.Upload(bytes, size, offset);
|
||||
@@ -415,18 +274,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
MGLOG_F("Magma: Fatal{ResourceUnavailable, \"buffer-upload\"}");
|
||||
std::abort();
|
||||
}
|
||||
if (WireBufProbeEnabled()) {
|
||||
MGLOG_I("WBUF write slot=%u gen=%u off=%llu size=%llu branch=%s bySerial=%d bySubmit=%d "
|
||||
"lastUse=%llu completed=%llu frameSerial=%llu floor=%llu lastUseSubmit=%llu",
|
||||
res.Slot, res.Gen, static_cast<unsigned long long>(offset),
|
||||
static_cast<unsigned long long>(size),
|
||||
(busyBySerial || busyBySubmission) ? "STAGED-or-WAIT" : "HOST-IMMEDIATE",
|
||||
busyBySerial ? 1 : 0, busyBySubmission ? 1 : 0,
|
||||
static_cast<unsigned long long>(probeLastUse), static_cast<unsigned long long>(probeCompleted),
|
||||
static_cast<unsigned long long>(m_frameSerial),
|
||||
static_cast<unsigned long long>(m_completedSerialFloor),
|
||||
static_cast<unsigned long long>(resource->lastUseSubmitIndex));
|
||||
}
|
||||
MG_Remote::Server::StagedShadowStore::CoverageAdd(resource->stagedCoverage,
|
||||
static_cast<SizeT>(offset),
|
||||
static_cast<SizeT>(offset + size));
|
||||
@@ -457,17 +304,8 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
auto* resource = FindWireBuffer(res);
|
||||
if (!resource || !resource->buffer.IsValid() || resource->size == 0) return false;
|
||||
resource->lastUseSerial = m_frameSerial;
|
||||
// B3: the draw this slice is being acquired for is normally recorded into the NEXT
|
||||
// submission - normally, not always: a mid-draw flush (SyncWireTextureShape's preserve
|
||||
// path) can submit this index without the draw. This stamp is the defence term's input
|
||||
// (see WriteWireBuffer); the floor behind lastUseSerial is the guarantee.
|
||||
if (pVulkanRenderer) resource->lastUseSubmitIndex = pVulkanRenderer->GetWireNextSubmitIndex();
|
||||
outSlice = resource->buffer.GetSlice(0, resource->size);
|
||||
outSlice.mapped = nullptr;
|
||||
if (WireBufProbeEnabled()) {
|
||||
MGLOG_I("WBUF bind slot=%u gen=%u frameSerial=%llu", res.Slot, res.Gen,
|
||||
static_cast<unsigned long long>(m_frameSerial));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -485,9 +323,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// work, not the draw that will bind that previously acquired slice.
|
||||
// Preserve its reservation even if the idle drain advanced the frame.
|
||||
resource->lastUseSerial = m_frameSerial;
|
||||
// B3 review: and the submission half of the same reservation - the wait cleared it,
|
||||
// and the draw holding the slice has not been submitted yet.
|
||||
if (pVulkanRenderer) resource->lastUseSubmitIndex = pVulkanRenderer->GetWireNextSubmitIndex();
|
||||
}
|
||||
if (!resource->buffer.Invalidate(size, offset)) return false;
|
||||
Memcpy(dst, static_cast<const Uint8*>(resource->buffer.GetMappedData()) + offset, static_cast<SizeT>(size));
|
||||
@@ -518,77 +353,12 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
return true;
|
||||
}
|
||||
|
||||
Bool VkBufferManager::CopyWireBufferSubWordRangeToSlice(MG_Pipe::MGPipeHandle res, Uint64 offset,
|
||||
Uint64 size, Uint32 frameIndex,
|
||||
const BufferSlice& dst, Uint64 dstSkip) {
|
||||
auto* resource = FindWireBuffer(res);
|
||||
if (!resource || offset > resource->size || size > resource->size - offset) return false;
|
||||
if (dstSkip > dst.size || size > dst.size - dstSkip) return false;
|
||||
if (size == 0) return true;
|
||||
if (!m_copyProvider || dst.buffer == VK_NULL_HANDLE) return false;
|
||||
|
||||
// Round the read of the application's store OUT to whole words. The tail can only be
|
||||
// clipped by the end of the store itself, and [offset, offset + size) already fits
|
||||
// inside it, so the widened window still covers every byte the caller asked for.
|
||||
const Uint64 alignedOffset = offset & ~Uint64{3};
|
||||
const Uint64 stagedEnd = std::min<Uint64>((offset + size + 3) & ~Uint64{3}, resource->size);
|
||||
const Uint64 headPad = offset - alignedOffset;
|
||||
const Uint64 stagedSize = stagedEnd - alignedOffset;
|
||||
if (stagedSize < headPad + size) return false;
|
||||
|
||||
// Uninitialized on purpose: the widening copy below writes every byte of it. The
|
||||
// arena can grow to satisfy this, which parks (never frees) the buffer `dst` may
|
||||
// already name - see BufferArena::EnsureCapacity - so the two slices are allowed to
|
||||
// sit in different VkBuffers and the copy names each slice's own handle.
|
||||
BufferSlice staging{};
|
||||
if (!m_transientUploadArena.Allocate(frameIndex, stagedSize, 4, staging) || !staging.IsValid())
|
||||
return false;
|
||||
|
||||
const VkCommandBuffer commands = m_copyProvider->AcquireBufferCopyCommandBuffer();
|
||||
if (commands == VK_NULL_HANDLE) return false;
|
||||
VkMemoryBarrier before{VK_STRUCTURE_TYPE_MEMORY_BARRIER};
|
||||
before.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT | VK_ACCESS_HOST_WRITE_BIT;
|
||||
before.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
vkCmdPipelineBarrier(commands, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT | VK_PIPELINE_STAGE_HOST_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 1, &before, 0, nullptr, 0, nullptr);
|
||||
const VkBufferCopy widen{alignedOffset, staging.offset, stagedSize};
|
||||
vkCmdCopyBuffer(commands, resource->buffer.GetHandle(), staging.buffer, 1, &widen);
|
||||
// The shift reads what the widening copy just wrote, so it needs its own edge even
|
||||
// though both halves are transfers on one command buffer.
|
||||
VkMemoryBarrier staged{VK_STRUCTURE_TYPE_MEMORY_BARRIER};
|
||||
staged.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
staged.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
|
||||
vkCmdPipelineBarrier(commands, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
0, 1, &staged, 0, nullptr, 0, nullptr);
|
||||
const VkBufferCopy shift{staging.offset + headPad, dst.offset + dstSkip, size};
|
||||
vkCmdCopyBuffer(commands, staging.buffer, dst.buffer, 1, &shift);
|
||||
VkMemoryBarrier after{VK_STRUCTURE_TYPE_MEMORY_BARRIER};
|
||||
after.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
after.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT;
|
||||
vkCmdPipelineBarrier(commands, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
|
||||
0, 1, &after, 0, nullptr, 0, nullptr);
|
||||
resource->lastUseSerial = m_frameSerial;
|
||||
return true;
|
||||
}
|
||||
|
||||
void VkBufferManager::ReadbackWireBuffer(MG_Pipe::MGPipeHandle res, Uint64 offset, Uint64 size) {
|
||||
// P11 B2: A T0 STORE'S READBACK IS "DONE, NO BYTES". Its pages are the client's
|
||||
// AHardwareBuffer, so what the client needs before it reads them is this server's GPU
|
||||
// having finished every write to them - the resident copies WriteWireBuffer recorded and
|
||||
// any shader write - and nothing crossing SEG_EVENT. The wait is the store's own host-access
|
||||
// wait (a barrier to host, then the sync point's submission); the reply then says "done".
|
||||
// One death for both shapes: the store could not be made readable.
|
||||
auto* resource = FindWireBuffer(res);
|
||||
const Bool t0 = resource != nullptr && resource->imported;
|
||||
Vector<Uint8> bytes(t0 ? 0 : static_cast<SizeT>(size));
|
||||
if (t0 ? !WaitForWireBufferHostAccess(*resource) : !ReadWireBuffer(res, offset, size, bytes.data())) {
|
||||
Vector<Uint8> bytes(static_cast<SizeT>(size));
|
||||
if (!ReadWireBuffer(res, offset, size, bytes.data())) {
|
||||
MGLOG_F("Magma: Fatal{ResourceUnavailable, \"buffer-readback\"} {slot=%u, gen=%u}", res.Slot, res.Gen);
|
||||
std::abort();
|
||||
}
|
||||
if (t0) {
|
||||
++m_sliceEpochCounter;
|
||||
return;
|
||||
}
|
||||
if (MG_Pipe::gMGPipeCallbacks.OnBufferWriteback == nullptr) {
|
||||
MGLOG_F("Magma: Fatal{ResourceUnavailable, \"buffer-writeback-callback\"}");
|
||||
std::abort();
|
||||
@@ -608,7 +378,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
resource->lastUseSerial = m_frameSerial;
|
||||
resource->stagedCoverage.clear();
|
||||
resource->gpuWritesPending = true;
|
||||
resource->indirectReadBarrierPending = true;
|
||||
++m_sliceEpochCounter;
|
||||
// The existing client dirty-state protocol accepts one whole-store
|
||||
// notification. The store remains on the GPU and exact later SubData
|
||||
@@ -621,439 +390,12 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
MG_Pipe::gMGPipeCallbacks.OnGpuWritten(res, 1, &range);
|
||||
}
|
||||
|
||||
Bool VkBufferManager::TakeWireIndirectReadBarrier(MG_Pipe::MGPipeHandle res) {
|
||||
auto* resource = FindWireBuffer(res);
|
||||
if (!resource || !resource->indirectReadBarrierPending) return false;
|
||||
resource->indirectReadBarrierPending = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// ---- P11 B2: T0 - THE CLIENT'S AHardwareBuffer AS A WIRE STORE -----------------------------
|
||||
|
||||
// The serial a T0 store is released under: its last use, or - when no GPU command has named it
|
||||
// since a host-access wait - the current frame's, so the release still waits for the sync
|
||||
// point rather than taking DeferWireRelease's "never named, destroy now" arm. Conservative by
|
||||
// at most one submission.
|
||||
Uint64 VkBufferManager::T0ReleaseSerial(Uint64 lastUseSerial) const {
|
||||
if (lastUseSerial != 0) return lastUseSerial;
|
||||
return m_frameSerial != 0 ? m_frameSerial : 1;
|
||||
}
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
namespace {
|
||||
Int32 T0PickMemoryType(const VkPhysicalDeviceMemoryProperties& props, Uint32 bits,
|
||||
VkMemoryPropertyFlags want) {
|
||||
for (Uint32 i = 0; i < props.memoryTypeCount; ++i) {
|
||||
if ((bits & (1u << i)) != 0 && (props.memoryTypes[i].propertyFlags & want) == want)
|
||||
return static_cast<Int32>(i);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct T0ImportedBuffer {
|
||||
VkBuffer buffer = VK_NULL_HANDLE;
|
||||
VkDeviceMemory memory = VK_NULL_HANDLE;
|
||||
void* mapped = nullptr;
|
||||
Bool coherent = true;
|
||||
};
|
||||
|
||||
void T0DestroyImported(VkDevice device, T0ImportedBuffer& imported) {
|
||||
if (imported.mapped != nullptr) vkUnmapMemory(device, imported.memory);
|
||||
if (imported.buffer != VK_NULL_HANDLE) vkDestroyBuffer(device, imported.buffer, nullptr);
|
||||
if (imported.memory != VK_NULL_HANDLE) vkFreeMemory(device, imported.memory, nullptr);
|
||||
imported = T0ImportedBuffer{};
|
||||
}
|
||||
|
||||
// A VkBuffer on a dedicated allocation IMPORTED from `ahb`, in a host-visible memory type
|
||||
// (coherent preferred), mapped whole. The server's own host map is what WriteWireBuffer's
|
||||
// idle path and every CPU reader of a wire store use, so a type without HOST_VISIBLE is a
|
||||
// refusal, not a degraded import. Nothing is left behind on failure.
|
||||
Bool T0ImportAhb(const VulkanRenderer::WireAhbImport& ctx, void* ahb, Uint64 size, VkBufferUsageFlags usage,
|
||||
T0ImportedBuffer& out, String& why) {
|
||||
out = T0ImportedBuffer{};
|
||||
const auto getProperties =
|
||||
reinterpret_cast<PFN_vkGetAndroidHardwareBufferPropertiesANDROID>(ctx.getAhbProperties);
|
||||
VkAndroidHardwareBufferPropertiesANDROID properties{
|
||||
VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_PROPERTIES_ANDROID};
|
||||
VkResult result = getProperties(ctx.device, static_cast<const AHardwareBuffer*>(ahb), &properties);
|
||||
if (result != VK_SUCCESS) {
|
||||
why = "vkGetAndroidHardwareBufferPropertiesANDROID -> " + std::to_string(static_cast<int>(result));
|
||||
return false;
|
||||
}
|
||||
VkExternalMemoryBufferCreateInfo external{VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO};
|
||||
external.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;
|
||||
VkBufferCreateInfo bufferInfo{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO};
|
||||
bufferInfo.pNext = &external;
|
||||
bufferInfo.size = size;
|
||||
bufferInfo.usage = usage;
|
||||
bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
result = vkCreateBuffer(ctx.device, &bufferInfo, nullptr, &out.buffer);
|
||||
if (result != VK_SUCCESS) {
|
||||
out.buffer = VK_NULL_HANDLE;
|
||||
why = "vkCreateBuffer(external AHB) -> " + std::to_string(static_cast<int>(result));
|
||||
return false;
|
||||
}
|
||||
Int32 type = T0PickMemoryType(ctx.memory, properties.memoryTypeBits,
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
|
||||
out.coherent = type >= 0;
|
||||
if (type < 0)
|
||||
type = T0PickMemoryType(ctx.memory, properties.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
|
||||
if (type < 0) {
|
||||
why = "no host-visible memory type can import it (memoryTypeBits 0x" +
|
||||
std::to_string(properties.memoryTypeBits) + ")";
|
||||
T0DestroyImported(ctx.device, out);
|
||||
return false;
|
||||
}
|
||||
VkMemoryDedicatedAllocateInfo dedicated{VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO};
|
||||
dedicated.buffer = out.buffer;
|
||||
VkImportAndroidHardwareBufferInfoANDROID import{VK_STRUCTURE_TYPE_IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID};
|
||||
import.buffer = static_cast<AHardwareBuffer*>(ahb);
|
||||
import.pNext = &dedicated;
|
||||
VkMemoryAllocateInfo allocateInfo{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO};
|
||||
allocateInfo.pNext = &import;
|
||||
allocateInfo.allocationSize = properties.allocationSize;
|
||||
allocateInfo.memoryTypeIndex = static_cast<Uint32>(type);
|
||||
result = vkAllocateMemory(ctx.device, &allocateInfo, nullptr, &out.memory);
|
||||
if (result != VK_SUCCESS) {
|
||||
out.memory = VK_NULL_HANDLE;
|
||||
why = "vkAllocateMemory(import AHB) -> " + std::to_string(static_cast<int>(result));
|
||||
T0DestroyImported(ctx.device, out);
|
||||
return false;
|
||||
}
|
||||
result = vkBindBufferMemory(ctx.device, out.buffer, out.memory, 0);
|
||||
if (result == VK_SUCCESS) result = vkMapMemory(ctx.device, out.memory, 0, VK_WHOLE_SIZE, 0, &out.mapped);
|
||||
if (result != VK_SUCCESS || out.mapped == nullptr) {
|
||||
out.mapped = nullptr;
|
||||
why = "vkBindBufferMemory/vkMapMemory -> " + std::to_string(static_cast<int>(result));
|
||||
T0DestroyImported(ctx.device, out);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
Bool VkBufferManager::ImportWireBuffer(MG_Pipe::MGPipeHandle res, void* ahb, Uint64 size) {
|
||||
#if defined(__ANDROID__)
|
||||
auto* resource = FindWireBuffer(res);
|
||||
if (resource == nullptr || ahb == nullptr || size == 0 || size != resource->size) return false;
|
||||
VulkanRenderer::WireAhbImport ctx;
|
||||
if (pVulkanRenderer == nullptr || !pVulkanRenderer->GetWireAhbImport(ctx)) {
|
||||
MGLOG_W_ONCE("Magma T0: this device did not take VK_ANDROID_external_memory_android_hardware_buffer");
|
||||
return false;
|
||||
}
|
||||
VkBufferUsageFlags usage = kPersistentBackedUsage | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
|
||||
if (m_initInfo.transformFeedbackUsageEnabled) usage |= VK_BUFFER_USAGE_TRANSFORM_FEEDBACK_BUFFER_BIT_EXT;
|
||||
T0ImportedBuffer imported;
|
||||
String why;
|
||||
if (!T0ImportAhb(ctx, ahb, size, usage, imported, why)) {
|
||||
MGLOG_W("Magma T0: store {slot=%u, gen=%u} (%llu bytes) not imported - %s", res.Slot, res.Gen,
|
||||
static_cast<unsigned long long>(size), why.c_str());
|
||||
return false;
|
||||
}
|
||||
// The T2 store it replaces goes the way a respecify's does (and any draw still naming it
|
||||
// keeps it until its submission completes).
|
||||
DeferWireRelease(std::move(resource->buffer), resource->lastUseSerial);
|
||||
MG_Remote::Transport::AdoptT0::AcquireImported(ahb);
|
||||
resource->buffer.AdoptExternal(ctx.device, imported.buffer, imported.memory, size, imported.mapped,
|
||||
imported.coherent, ahb);
|
||||
resource->imported = true;
|
||||
resource->lastUseSerial = 0;
|
||||
resource->lastUseSubmitIndex = 0;
|
||||
resource->gpuWritesPending = false;
|
||||
// The whole store holds bytes the client supplied (its AHB, seeded from its shadow).
|
||||
resource->stagedCoverage.clear();
|
||||
MG_Remote::Server::StagedShadowStore::CoverageAdd(resource->stagedCoverage, 0, static_cast<SizeT>(size));
|
||||
++m_sliceEpochCounter;
|
||||
++m_wireStoreCount;
|
||||
NoteWireStorePeaks();
|
||||
PublishWireReclaimGauges();
|
||||
MGLOG_D("Magma T0: imported {slot=%u, gen=%u} (%llu bytes, %s memory)", res.Slot, res.Gen,
|
||||
static_cast<unsigned long long>(size), imported.coherent ? "coherent" : "non-coherent");
|
||||
return true;
|
||||
#else
|
||||
(void)res;
|
||||
(void)ahb;
|
||||
(void)size;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
// THE POST (B2; decided by probe, never by driver name). The AHB API promises CPU coherence only
|
||||
// across an unlock/lock, and T0 holds the client's lock for the store's life, so this exercises
|
||||
// that pattern on THIS device before kCapAdoptT0 may be published:
|
||||
// hold - a 64 KiB BLOB allocated and locked by the test, never unlocked while it runs;
|
||||
// read - this server's own host map of the import reads what the CPU wrote through the lock;
|
||||
// gpu - one submission copies that pattern out of the import (the GPU read) and fills another
|
||||
// region of it (the GPU write), then a transfer->host barrier and a fence wait;
|
||||
// back - the fill is read through the HELD pointer, the copy from a host-visible staging buffer.
|
||||
Bool VkBufferManager::SelfTestWireImport(char* whyOut, Uint64 whyBytes) {
|
||||
const auto answer = [&](Bool ok, const String& text) {
|
||||
std::snprintf(whyOut, static_cast<SizeT>(whyBytes), "%s", text.c_str());
|
||||
return ok;
|
||||
};
|
||||
#if defined(__ANDROID__)
|
||||
VulkanRenderer::WireAhbImport ctx;
|
||||
if (pVulkanRenderer == nullptr || !pVulkanRenderer->GetWireAhbImport(ctx))
|
||||
return answer(false, "the device did not take VK_ANDROID_external_memory_android_hardware_buffer");
|
||||
constexpr Uint64 kBytes = 64 * 1024;
|
||||
constexpr Uint32 kWords = 1024; // one 4 KiB region
|
||||
constexpr Uint64 kFillAt = 4 * 4096; // region 4
|
||||
constexpr Uint32 kFillWord = 0x6C0FFEE0u;
|
||||
Vector<Uint32> pattern(kBytes / 4);
|
||||
for (SizeT i = 0; i < pattern.size(); ++i) pattern[i] = 0x5A000000u ^ static_cast<Uint32>(i * 2654435761u);
|
||||
MG_Remote::Transport::AdoptT0::HeldStore held;
|
||||
String why;
|
||||
if (!MG_Remote::Transport::AdoptT0::AllocateHeld(kBytes, pattern.data(), held, why))
|
||||
return answer(false, "hold: " + why);
|
||||
T0ImportedBuffer imported, staging;
|
||||
VkCommandPool pool = VK_NULL_HANDLE;
|
||||
VkFence fence = VK_NULL_HANDLE;
|
||||
String verdict;
|
||||
Bool ok = false;
|
||||
do {
|
||||
if (!T0ImportAhb(ctx, held.ahb, kBytes,
|
||||
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT |
|
||||
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
|
||||
imported, why)) {
|
||||
verdict = "import: " + why;
|
||||
break;
|
||||
}
|
||||
if (!imported.coherent) {
|
||||
VkMappedMemoryRange range{VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE};
|
||||
range.memory = imported.memory;
|
||||
range.size = VK_WHOLE_SIZE;
|
||||
vkInvalidateMappedMemoryRanges(ctx.device, 1, &range);
|
||||
}
|
||||
if (std::memcmp(imported.mapped, pattern.data(), kWords * 4) != 0) {
|
||||
verdict = "read: the server's host map of the import does not hold the CPU's pattern";
|
||||
break;
|
||||
}
|
||||
// A host-visible staging buffer for the GPU read's destination.
|
||||
VkBufferCreateInfo stagingInfo{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO};
|
||||
stagingInfo.size = kWords * 4;
|
||||
stagingInfo.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
|
||||
stagingInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
if (vkCreateBuffer(ctx.device, &stagingInfo, nullptr, &staging.buffer) != VK_SUCCESS) {
|
||||
staging.buffer = VK_NULL_HANDLE;
|
||||
verdict = "staging buffer";
|
||||
break;
|
||||
}
|
||||
VkMemoryRequirements requirements{};
|
||||
vkGetBufferMemoryRequirements(ctx.device, staging.buffer, &requirements);
|
||||
const Int32 stagingType = T0PickMemoryType(ctx.memory, requirements.memoryTypeBits,
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
|
||||
VkMemoryAllocateInfo stagingAlloc{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO};
|
||||
stagingAlloc.allocationSize = requirements.size;
|
||||
stagingAlloc.memoryTypeIndex = static_cast<Uint32>(stagingType < 0 ? 0 : stagingType);
|
||||
if (stagingType < 0 || vkAllocateMemory(ctx.device, &stagingAlloc, nullptr, &staging.memory) != VK_SUCCESS ||
|
||||
vkBindBufferMemory(ctx.device, staging.buffer, staging.memory, 0) != VK_SUCCESS ||
|
||||
vkMapMemory(ctx.device, staging.memory, 0, VK_WHOLE_SIZE, 0, &staging.mapped) != VK_SUCCESS) {
|
||||
verdict = "staging memory";
|
||||
break;
|
||||
}
|
||||
std::memset(staging.mapped, 0, kWords * 4);
|
||||
VkCommandPoolCreateInfo poolInfo{VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO};
|
||||
poolInfo.queueFamilyIndex = ctx.queueFamily;
|
||||
poolInfo.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT;
|
||||
VkCommandBuffer commands = VK_NULL_HANDLE;
|
||||
VkCommandBufferAllocateInfo commandInfo{VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO};
|
||||
commandInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||
commandInfo.commandBufferCount = 1;
|
||||
VkFenceCreateInfo fenceInfo{VK_STRUCTURE_TYPE_FENCE_CREATE_INFO};
|
||||
if (vkCreateCommandPool(ctx.device, &poolInfo, nullptr, &pool) != VK_SUCCESS) {
|
||||
pool = VK_NULL_HANDLE;
|
||||
verdict = "command pool";
|
||||
break;
|
||||
}
|
||||
commandInfo.commandPool = pool;
|
||||
if (vkAllocateCommandBuffers(ctx.device, &commandInfo, &commands) != VK_SUCCESS ||
|
||||
vkCreateFence(ctx.device, &fenceInfo, nullptr, &fence) != VK_SUCCESS) {
|
||||
verdict = "command buffer / fence";
|
||||
break;
|
||||
}
|
||||
VkCommandBufferBeginInfo begin{VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO};
|
||||
begin.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
|
||||
vkBeginCommandBuffer(commands, &begin);
|
||||
VkMemoryBarrier hostWrites{VK_STRUCTURE_TYPE_MEMORY_BARRIER};
|
||||
hostWrites.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
|
||||
hostWrites.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
vkCmdPipelineBarrier(commands, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 1,
|
||||
&hostWrites, 0, nullptr, 0, nullptr);
|
||||
VkBufferCopy region{0, 0, kWords * 4};
|
||||
vkCmdCopyBuffer(commands, imported.buffer, staging.buffer, 1, ®ion);
|
||||
vkCmdFillBuffer(commands, imported.buffer, kFillAt, kWords * 4, kFillWord);
|
||||
VkMemoryBarrier toHost{VK_STRUCTURE_TYPE_MEMORY_BARRIER};
|
||||
toHost.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
toHost.dstAccessMask = VK_ACCESS_HOST_READ_BIT;
|
||||
vkCmdPipelineBarrier(commands, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 1, &toHost,
|
||||
0, nullptr, 0, nullptr);
|
||||
vkEndCommandBuffer(commands);
|
||||
VkSubmitInfo submit{VK_STRUCTURE_TYPE_SUBMIT_INFO};
|
||||
submit.commandBufferCount = 1;
|
||||
submit.pCommandBuffers = &commands;
|
||||
if (vkQueueSubmit(ctx.queue, 1, &submit, fence) != VK_SUCCESS ||
|
||||
vkWaitForFences(ctx.device, 1, &fence, VK_TRUE, 2'000'000'000ull) != VK_SUCCESS) {
|
||||
verdict = "gpu: the submission did not complete within 2 s";
|
||||
break;
|
||||
}
|
||||
Uint32 gpuRead = 0, heldSaw = 0;
|
||||
const auto* copied = static_cast<const Uint32*>(staging.mapped);
|
||||
const auto* heldWords = static_cast<const Uint32*>(held.ptr);
|
||||
for (Uint32 i = 0; i < kWords; ++i) {
|
||||
if (copied[i] == pattern[i]) ++gpuRead;
|
||||
if (heldWords[kFillAt / 4 + i] == kFillWord) ++heldSaw;
|
||||
}
|
||||
ok = gpuRead == kWords && heldSaw == kWords;
|
||||
verdict = "64 KiB AHB, lock held throughout: host map read ok (" +
|
||||
String(imported.coherent ? "coherent" : "non-coherent") + " memory), GPU read " +
|
||||
std::to_string(gpuRead) + "/1024 words of the CPU's pattern, GPU write seen through the "
|
||||
"held lock " + std::to_string(heldSaw) + "/1024 words";
|
||||
} while (false);
|
||||
if (fence != VK_NULL_HANDLE) vkDestroyFence(ctx.device, fence, nullptr);
|
||||
if (pool != VK_NULL_HANDLE) vkDestroyCommandPool(ctx.device, pool, nullptr);
|
||||
T0DestroyImported(ctx.device, staging);
|
||||
T0DestroyImported(ctx.device, imported);
|
||||
MG_Remote::Transport::AdoptT0::ReleaseHeld(held);
|
||||
return answer(ok, verdict);
|
||||
#else
|
||||
return answer(false, "no AHardwareBuffer on this platform");
|
||||
#endif
|
||||
}
|
||||
|
||||
void VkBufferManager::DestroyWireBuffer(MG_Pipe::MGPipeHandle res) {
|
||||
const auto found = m_wireBuffers.find(WireBufferKey(res));
|
||||
if (found == m_wireBuffers.end()) return;
|
||||
DeferWireRelease(std::move(found->second.buffer),
|
||||
found->second.imported ? T0ReleaseSerial(found->second.lastUseSerial)
|
||||
: found->second.lastUseSerial); // P11 B2, as Respecify
|
||||
DeferRelease(std::move(found->second.buffer));
|
||||
m_wireBuffers.erase(found);
|
||||
++m_sliceEpochCounter;
|
||||
PublishWireReclaimGauges();
|
||||
}
|
||||
|
||||
void VkBufferManager::DeferWireRelease(VkBufferObject&& buffer, Uint64 lastUseSerial) {
|
||||
if (!buffer.IsValid()) return;
|
||||
// Two stores go NOW rather than into the list. With no frame slots (DeferRelease's own
|
||||
// teardown guard, and for its reason) there is no manager left to reclaim anything
|
||||
// later. And a store whose last-use serial is 0 was never named by a GPU command since
|
||||
// it was minted or since a host-access wait retired everything recorded before it - see
|
||||
// DeferredWireRelease - so there is nothing to wait for.
|
||||
if (m_deferredBufferReleases.empty() || lastUseSerial == 0) {
|
||||
buffer.Destroy();
|
||||
++m_wireStoreDestroyEpoch;
|
||||
if (m_wireStoreCount > 0) --m_wireStoreCount;
|
||||
return;
|
||||
}
|
||||
DeferredWireRelease entry;
|
||||
entry.lastUseSerial = lastUseSerial;
|
||||
// The last submission that can name this store: see DeferredWireRelease. Zero when there
|
||||
// is no renderer, which is also when there is no queue and nothing to wait for.
|
||||
entry.submitIndex = pVulkanRenderer != nullptr ? pVulkanRenderer->GetSyncPointSubmitIndex() : 0;
|
||||
entry.bytes = static_cast<Uint64>(buffer.GetSize());
|
||||
entry.buffer = std::move(buffer);
|
||||
m_deferredWireBytes += entry.bytes;
|
||||
m_deferredWireReleases.push_back(std::move(entry));
|
||||
NoteWireStorePeaks();
|
||||
// EVERY PARK SWEEPS. The frame boundary is not a reclaim point this arm can lean on - a
|
||||
// pbuffer replay that snapshot-exits delivers ONE present for 1.3 M calls (ID-P7-32) -
|
||||
// so the only cadence that tracks the workload is the workload itself.
|
||||
SweepDeferredWireReleases();
|
||||
EnforceWireDeferredWatermark();
|
||||
}
|
||||
|
||||
void VkBufferManager::EnforceWireDeferredWatermark() {
|
||||
const Uint64 budget = static_cast<Uint64>(MG_Config::Ipc.WireDeferredMb) * 1024u * 1024u;
|
||||
// TWO TRIGGERS, ONE SWITCH. Bytes are what the knob names, but a VkBuffer costs per
|
||||
// OBJECT as well as per byte, and small orphans never reach a byte budget: measured on
|
||||
// bsl-esc-menu-854 (spawn, lavapipe), one stretch with no submission parked 12,498 stores
|
||||
// in 39.5 MB against 64 MiB. So a fixed count ceiling rides the same sync point; the
|
||||
// knob's 0 turns both off, which keeps it one negative control.
|
||||
if (budget == 0) return;
|
||||
if (m_deferredWireBytes <= budget && m_deferredWireReleases.size() <= kWireDeferredCountCeiling) return;
|
||||
// What is left after the sweep is named by work that is recorded but unsubmitted, or
|
||||
// submitted but unretired. Every entry is tagged at or below the sync point taken HERE,
|
||||
// so waiting it out - the host-access wait's own call, which flushes the recording first
|
||||
// - proves all of them dead. A mid-frame flush is what WaitForWireBufferHostAccess and a
|
||||
// glClientWaitSync already do to this command stream; it costs one submission per
|
||||
// budget's worth of orphans, not one per glBufferData.
|
||||
if (pVulkanRenderer == nullptr ||
|
||||
!pVulkanRenderer->WaitForSubmitIndex(pVulkanRenderer->GetSyncPointSubmitIndex(), UINT64_MAX, true)) {
|
||||
WireBufferSyncFatal("deferred-watermark");
|
||||
}
|
||||
++m_wireDeferredSyncs;
|
||||
SweepDeferredWireReleases();
|
||||
}
|
||||
|
||||
void VkBufferManager::NoteWireStorePeaks() {
|
||||
m_wireStoreCountPeak = std::max(m_wireStoreCountPeak, m_wireStoreCount);
|
||||
m_deferredWireBytesPeak = std::max(m_deferredWireBytesPeak, m_deferredWireBytes);
|
||||
}
|
||||
|
||||
void VkBufferManager::PublishWireReclaimGauges() {
|
||||
if (!MG_Util::PipeStats::Enabled()) return;
|
||||
using MG_Util::PipeStats::Gauge;
|
||||
MG_Util::PipeStats::PublishGauge(Gauge::WireBuffers, static_cast<Uint64>(m_wireBuffers.size()));
|
||||
MG_Util::PipeStats::PublishGauge(Gauge::WireStoresPeak, m_wireStoreCountPeak);
|
||||
MG_Util::PipeStats::PublishGauge(Gauge::WireDeferredBytesPeak, m_deferredWireBytesPeak);
|
||||
MG_Util::PipeStats::PublishGauge(Gauge::WireDeferredSyncs, m_wireDeferredSyncs);
|
||||
}
|
||||
|
||||
void VkBufferManager::WireBufferSyncFatal(const char* site) {
|
||||
MGLOG_F("Magma: Fatal{ResourceUnavailable, \"buffer-write-sync\"} {site=%s}", site);
|
||||
std::abort();
|
||||
}
|
||||
|
||||
SizeT VkBufferManager::SweepDeferredWireReleases() {
|
||||
if (m_deferredWireReleases.empty()) return 0;
|
||||
SizeT dead = 0;
|
||||
if (pVulkanRenderer == nullptr ||
|
||||
pVulkanRenderer->IsSubmitIndexComplete(pVulkanRenderer->GetSyncPointSubmitIndex())) {
|
||||
// Idle: nothing recorded, every submission retired - or no renderer, so no queue.
|
||||
// Every parked store is dead, including one tagged for a batch that was abandoned
|
||||
// instead of submitted.
|
||||
dead = m_deferredWireReleases.size();
|
||||
} else {
|
||||
// The list is in park order and GetSyncPointSubmitIndex() steps back only when a
|
||||
// pending recording is abandoned instead of submitted (RecreateSwapchain and the
|
||||
// minimized Present force-clear the recording flags, so `m_submitCounter + 1`
|
||||
// becomes `m_submitCounter`). Everywhere else the submit indices are non-decreasing
|
||||
// and the dead entries are a PREFIX: the first entry the renderer will not call
|
||||
// complete proves none after it is either. Across an abandonment a later entry can
|
||||
// carry the LOWER index; the walk then stops at the earlier, higher one and holds
|
||||
// both until the next submission takes that index and retires - conservative, never
|
||||
// early, and the idle rule above retires them regardless. That bounds the walk to a
|
||||
// couple of fence polls, which matters because this runs on every glBufferData the
|
||||
// wire carries.
|
||||
while (dead < m_deferredWireReleases.size() &&
|
||||
pVulkanRenderer->IsSubmitIndexComplete(m_deferredWireReleases[dead].submitIndex)) {
|
||||
++dead;
|
||||
}
|
||||
}
|
||||
if (dead == 0) return 0;
|
||||
for (SizeT i = 0; i < dead; ++i) {
|
||||
DeferredWireRelease& entry = m_deferredWireReleases[i];
|
||||
m_deferredWireBytes -= entry.bytes;
|
||||
entry.buffer.Destroy();
|
||||
}
|
||||
// One bump per sweep that destroyed anything is enough: what a memo needs to know
|
||||
// is "some handle it may name has been freed since", not how many.
|
||||
++m_wireStoreDestroyEpoch;
|
||||
m_deferredWireReleases.erase(m_deferredWireReleases.begin(),
|
||||
m_deferredWireReleases.begin() + static_cast<std::ptrdiff_t>(dead));
|
||||
const Uint64 destroyedCount = static_cast<Uint64>(dead);
|
||||
m_wireStoreCount = destroyedCount <= m_wireStoreCount ? m_wireStoreCount - destroyedCount : 0;
|
||||
return dead;
|
||||
}
|
||||
|
||||
void VkBufferManager::DestroyAllDeferredWireReleases() {
|
||||
if (!m_deferredWireReleases.empty()) ++m_wireStoreDestroyEpoch;
|
||||
for (auto& entry : m_deferredWireReleases) {
|
||||
entry.buffer.Destroy();
|
||||
if (m_wireStoreCount > 0) --m_wireStoreCount;
|
||||
}
|
||||
m_deferredWireReleases.clear();
|
||||
m_deferredWireBytes = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1098,14 +440,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
DestroyAllDeferredReleases();
|
||||
ReleaseAllLiveResources();
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// DestroyAllDeferredReleases above emptied the parked list; this destroys the stores the
|
||||
// records still hold, so nothing this arm minted outlives the count.
|
||||
if (!m_wireBuffers.empty()) ++m_wireStoreDestroyEpoch;
|
||||
m_wireBuffers.clear();
|
||||
m_wireStoreCount = 0;
|
||||
m_wireStoreCountPeak = 0;
|
||||
m_deferredWireBytesPeak = 0;
|
||||
m_wireDeferredSyncs = 0;
|
||||
#endif
|
||||
m_copyProvider = nullptr;
|
||||
m_initInfo = {};
|
||||
@@ -1135,13 +470,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
"VkBufferManager::BeginFrame frame index out of range");
|
||||
m_currentFrameIndex = frameIndex;
|
||||
++m_frameSerial;
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (WireBufProbeEnabled()) {
|
||||
MGLOG_I("WBUF BEGINFRAME idx=%u newSerial=%llu floor=%llu (arena slot rewound)", frameIndex,
|
||||
static_cast<unsigned long long>(m_frameSerial),
|
||||
static_cast<unsigned long long>(m_completedSerialFloor));
|
||||
}
|
||||
#endif
|
||||
CollectDeferredReleases(frameIndex);
|
||||
m_transientUploadArena.BeginFrame(frameIndex);
|
||||
}
|
||||
@@ -1158,9 +486,8 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// Nothing bumps the slice epoch for those other resources, so freeing the buffer
|
||||
// here left the streamed memo handing a destroyed VkBuffer to vkCmdBindIndexBuffer
|
||||
// (llvmpipe then faulted inside the draw; the Create/Flywheel indirect retrace died
|
||||
// exactly this way). Most mid-frame drains do not advance m_frameSerial; every
|
||||
// eighth does, but only through BeginFrame after the arena/memo boundary work.
|
||||
// The drain's per-resource sweep must not free arena storage: ResetFrame/BeginFrame is where
|
||||
// exactly this way). Mid-frame drains do not advance m_frameSerial, so they must not
|
||||
// free arena storage either: the arena's own ResetFrame/BeginFrame is the point where
|
||||
// the slot's slices stop being reachable, and that is where these releases land.
|
||||
for (Uint32 frameIndex = 0; frameIndex < m_deferredBufferReleases.size(); ++frameIndex) {
|
||||
CollectDeferredReleases(frameIndex);
|
||||
@@ -1439,9 +766,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
&afterBarrier, 0, nullptr, 0, nullptr);
|
||||
|
||||
resource.lastUseSerial = m_frameSerial;
|
||||
// B3: the copy just recorded rides the next submission too, so a later host write to
|
||||
// the same bytes must wait for it exactly as a draw's read must.
|
||||
if (pVulkanRenderer) resource.lastUseSubmitIndex = pVulkanRenderer->GetWireNextSubmitIndex();
|
||||
resource.gpuWritesPending = true;
|
||||
return true;
|
||||
}
|
||||
@@ -1823,12 +1147,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
"VkBufferManager::CollectDeferredReleases frame index out of range");
|
||||
m_deferredBufferReleases[frameIndex].clear();
|
||||
m_deferredResourceReleases[frameIndex].clear();
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// The wire list is not per-slot and does not wait for a frame boundary; a boundary is
|
||||
// just one more point to sweep at (BeginFrame after its slot fence, and every slot of
|
||||
// the idle drain, where the renderer-idle rule empties the list).
|
||||
SweepDeferredWireReleases();
|
||||
#endif
|
||||
}
|
||||
|
||||
BufferSlice VkBufferManager::AcquireUnboundStorageDescriptor() {
|
||||
@@ -1924,10 +1242,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
}
|
||||
|
||||
void VkBufferManager::DestroyAllDeferredReleases() {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// Both callers (Shutdown, RecreateTransientArenas) have proven the device idle.
|
||||
DestroyAllDeferredWireReleases();
|
||||
#endif
|
||||
for (auto& releases : m_deferredBufferReleases) {
|
||||
for (auto& buffer : releases) {
|
||||
buffer.Destroy();
|
||||
|
||||
@@ -113,26 +113,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
Bool ReadWireBuffer(MG_Pipe::MGPipeHandle res, Uint64 offset, Uint64 size, void* dst);
|
||||
Bool CopyWireBufferRangeToSlice(MG_Pipe::MGPipeHandle res, Uint64 offset, Uint64 size,
|
||||
const BufferSlice& dst);
|
||||
// P7 A.1, the sub-word half of the one above: the same copy for a window whose start
|
||||
// or end does not land on a four-byte boundary. The read of the APPLICATION's store is
|
||||
// rounded OUT to whole words and clamped to the store's end, so the widened window can
|
||||
// never touch a byte the application does not own; it lands in a transient staging
|
||||
// slice, and only the staging -> dst shift is sub-word - inside our own arena, where an
|
||||
// unaligned region cannot alias anything else. vkCmdCopyBuffer places no alignment rule
|
||||
// on a region's offsets or size (unlike vkCmdUpdateBuffer / vkCmdFillBuffer), so the
|
||||
// shift is a plain legal copy. `dstSkip` is the byte inside `dst` the window starts at.
|
||||
// This retires `uniform-buffer-byte-tail`.
|
||||
Bool CopyWireBufferSubWordRangeToSlice(MG_Pipe::MGPipeHandle res, Uint64 offset, Uint64 size,
|
||||
Uint32 frameIndex, const BufferSlice& dst, Uint64 dstSkip);
|
||||
void MarkWireBufferGpuWritten(MG_Pipe::MGPipeHandle res, Uint64 offset, Uint64 size);
|
||||
// P8-D: whether a shader write was marked on this store since the last indirect draw
|
||||
// read it natively, clearing the mark. The caller records the INDIRECT_COMMAND_READ
|
||||
// barrier before the draw when this answers true. Transfer writes need no mark: their own
|
||||
// after-barriers already make them visible to MEMORY_READ at ALL_COMMANDS.
|
||||
Bool TakeWireIndirectReadBarrier(MG_Pipe::MGPipeHandle res);
|
||||
// P8-D: every WaitForWireBufferHostAccess that actually waited, over this manager's life -
|
||||
// the attribution base a caller reads before and after its own ReadWireBuffer.
|
||||
Uint64 GetWireHostWaitCount() const { return m_wireHostWaits; }
|
||||
|
||||
// Resource-op entry points. All run on the server apply owner.
|
||||
void CreateWireBuffer(MG_Pipe::MGPipeHandle res, const MG_Pipe::MGPResourceDesc& desc);
|
||||
@@ -142,15 +123,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
void FlushWireBuffer(MG_Pipe::MGPipeHandle res, Uint64 offset, Uint64 size, const void* bytes);
|
||||
void ReadbackWireBuffer(MG_Pipe::MGPipeHandle res, Uint64 offset, Uint64 size);
|
||||
void DestroyWireBuffer(MG_Pipe::MGPipeHandle res);
|
||||
// P11 B2 (T0): make the client's AHardwareBuffer `ahb` (a BLOB of `size` bytes) buffer
|
||||
// `res`'s store - a VkBuffer on memory imported through
|
||||
// VK_ANDROID_external_memory_android_hardware_buffer, host-visible and mapped like every
|
||||
// wire store, so every wire path (draw binds, WriteWireBuffer's ordered copy, CPU readers)
|
||||
// applies unchanged. The T2 store it replaces goes through DeferWireRelease. False = not
|
||||
// imported (the T2 store is untouched and the client is DECLINED).
|
||||
Bool ImportWireBuffer(MG_Pipe::MGPipeHandle res, void* ahb, Uint64 size);
|
||||
// The POST self-test of the sustained-lock pattern on this device (see the definition).
|
||||
static Bool SelfTestWireImport(char* why, Uint64 whyBytes);
|
||||
#endif
|
||||
|
||||
// Recreate all per-frame transient arenas
|
||||
@@ -225,13 +197,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// back, and none was persistently mapped, in between - so a memo of resolved
|
||||
// slices needs no per-buffer re-check. See AcquirePersistentMap for the mapping half.
|
||||
Uint64 GetSliceEpochCounter() const { return m_sliceEpochCounter; }
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// Bumped every time this manager destroys a WIRE store's VkBuffer (see
|
||||
// m_wireStoreDestroyEpoch). Unchanged since a memo was taken means no VkBuffer handle
|
||||
// that memo names can have been freed and re-minted in between, which is the one
|
||||
// fact a handle-keyed memo of wire descriptors needs and cannot read off the handle.
|
||||
Uint64 GetWireStoreDestroyEpoch() const { return m_wireStoreDestroyEpoch; }
|
||||
#endif
|
||||
// Highest frame serial whose GPU work is known complete; serials at or
|
||||
// below it may be considered signaled. Drives IsResourceBusy and the
|
||||
// backend GL fence objects.
|
||||
@@ -252,117 +217,16 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
VkBufferObject buffer;
|
||||
Uint64 size = 0;
|
||||
Uint64 lastUseSerial = 0;
|
||||
// P7 wave 2 package B3: the submission expected to carry the most recent GPU use
|
||||
// of this buffer - the busy predicate's DEFENCE term, not its guarantee (see
|
||||
// WriteWireBuffer). IsSubmitIndexComplete polls the real fence and reports an
|
||||
// unsubmitted index as incomplete, but the stamp is taken before the draw is
|
||||
// recorded and a mid-draw flush can submit it without the draw.
|
||||
Uint64 lastUseSubmitIndex = 0;
|
||||
Bool gpuWritesPending = false;
|
||||
// Only ranges actually submitted by resource_subdata are covered. No
|
||||
// shadow is retained: flush cannot replay stale bytes over GPU writes.
|
||||
Vector<Range1D> stagedCoverage;
|
||||
// P11 B2 (T0): `buffer` is the client's imported AHardwareBuffer. Its readback posts
|
||||
// no bytes (the client reads its own pages once the wait below it is done).
|
||||
Bool imported = false;
|
||||
// P8-D: a shader write was marked (MarkWireBufferGpuWritten) and no indirect draw has
|
||||
// recorded its INDIRECT_COMMAND_READ barrier since (TakeWireIndirectReadBarrier).
|
||||
Bool indirectReadBarrierPending = false;
|
||||
};
|
||||
// P8-D: see GetWireHostWaitCount.
|
||||
Uint64 m_wireHostWaits = 0;
|
||||
static Uint64 WireBufferKey(MG_Pipe::MGPipeHandle res) {
|
||||
return (static_cast<Uint64>(res.Gen) << 32) | res.Slot;
|
||||
}
|
||||
WireBufferResource* FindWireBuffer(MG_Pipe::MGPipeHandle res);
|
||||
Bool WaitForWireBufferHostAccess(WireBufferResource& resource);
|
||||
// P11 B2: the serial a T0 store's release waits behind (never "destroy at once").
|
||||
Uint64 T0ReleaseSerial(Uint64 lastUseSerial) const;
|
||||
|
||||
// P7 wave 4 (M2), ID-P7-27: THE WIRE ARM'S ORPHANS NEED A RECLAIM THAT IS NOT A FRAME
|
||||
// BOUNDARY.
|
||||
//
|
||||
// RespecifyWireBuffer - which is every glBufferData that crosses the wire - orphans the
|
||||
// old store unconditionally, because unlike OnRespecify it has no shadow to upload in
|
||||
// place from and no cheap way to know the client is re-sending the same size. The orphan
|
||||
// is legitimate (M1 measured the conditional-orphan mirror: 6701 live against 6702).
|
||||
// What was missing is the RECLAIM. DeferRelease parks into m_deferredBufferReleases,
|
||||
// whose only sweep is CollectDeferredReleases from a frame boundary, and on a pbuffer
|
||||
// replay the server sees ONE present record for the whole run - so on
|
||||
// minecraft-1.21.4-fabric-iris-bsl-esc-menu-854 the buckets held 25,923 dead stores
|
||||
// against 28 live wire buffers, one memfd mapping each, and the server died in scudo's
|
||||
// secondary allocator.
|
||||
//
|
||||
// So a wire store is parked HERE instead, with the facts that say when it is dead, and
|
||||
// THE DEFER PATH ITSELF RECLAIMS - every park sweeps, and the frame boundary is only one
|
||||
// more sweep point (CollectDeferredReleases), never the one this depends on:
|
||||
//
|
||||
// * `lastUseSerial == 0` - read BEFORE RespecifyWireBuffer zeroes it. Zero means no
|
||||
// GPU command has named the store since it was minted or since the last host-access
|
||||
// wait proved every recorded command complete (WaitForWireBufferHostAccess); every
|
||||
// path that hands the store to the GPU stamps m_frameSerial, which starts at 1. Such
|
||||
// a store is destroyed at the park and never enters the list.
|
||||
// * `submitIndex` - the renderer's GetSyncPointSubmitIndex() at park time, which is by
|
||||
// construction the LAST submission that can name this store: every command that
|
||||
// names it was recorded before the park (the record left behind a bumped slice
|
||||
// epoch, so no memo can hand it out again), and a recorded command is either already
|
||||
// submitted (<= m_submitCounter) or in the batch that becomes m_submitCounter + 1.
|
||||
// IsSubmitIndexComplete(submitIndex) is a fence observation, so this is the gate
|
||||
// that empties the set MID-FRAME - the shape CollectWireObjects already uses for
|
||||
// the wire image/view tables.
|
||||
// * THE RENDERER IS IDLE - IsSubmitIndexComplete(GetSyncPointSubmitIndex()): nothing
|
||||
// is recorded and every submission has retired. Then every parked store is dead,
|
||||
// including one tagged for a batch that was abandoned rather than submitted (a
|
||||
// minimized Present drops its recording), whose own index may never complete.
|
||||
//
|
||||
// THE FRAME-SERIAL FLOOR IS DELIBERATELY NOT A PROOF HERE. It cannot move inside a
|
||||
// frame (NotifyFrameSerialComplete refuses the current serial), so it frees nothing in
|
||||
// the one-present replay this exists for; the submit index above is the fact that CAN
|
||||
// move mid-frame, and it is a fence observation rather than a count.
|
||||
//
|
||||
// AND EVERY DESTROY HERE HAPPENS MID-FRAME, which the memos above this manager were not
|
||||
// written for. UniformManager's descriptor memos are keyed on the VkBuffer HANDLE, and
|
||||
// before M2 a wire store only ever died at the same boundary that clears those memos
|
||||
// (UniformManager::BeginFrame, from Present or a drain). A store destroyed here can
|
||||
// have its handle value re-minted by the next Create - a heap pointer under lavapipe -
|
||||
// while a memo still maps that handle to a descriptor set baked to the dead store's
|
||||
// memory: silent wrong bytes, no Fatal (ID-P7-43). m_wireStoreDestroyEpoch is the
|
||||
// fact the memos fold in: every wire-store destroy bumps it, so a memo taken before
|
||||
// the destroy cannot match after it. Deliberately NOT m_sliceEpochCounter, which every
|
||||
// WriteWireBuffer bumps and which would defeat the memo on every glBufferSubData.
|
||||
struct DeferredWireRelease {
|
||||
VkBufferObject buffer;
|
||||
Uint64 lastUseSerial = 0;
|
||||
Uint64 submitIndex = 0;
|
||||
// Cached: GetSize() is gone once the object is destroyed, and the watermark's
|
||||
// running total has to stay exact as entries leave.
|
||||
Uint64 bytes = 0;
|
||||
};
|
||||
// Park a wire store, sweep, then hold the watermark. `lastUseSerial` is the releasing
|
||||
// resource's, captured before the caller resets it.
|
||||
void DeferWireRelease(VkBufferObject&& buffer, Uint64 lastUseSerial);
|
||||
// Destroy every parked store proven dead by the rules above. Returns how many.
|
||||
SizeT SweepDeferredWireReleases();
|
||||
// MOBILEGL_IPC_WIRE_DEFERRED_MB (Config.h has the semantics): when the parked bytes
|
||||
// still exceed the budget after a sweep, take the sync point WaitForWireBufferHostAccess
|
||||
// takes - flush what is recorded, wait for it - and sweep again, which retires every
|
||||
// parked store, because none can be tagged past the sync point it just waited out.
|
||||
void EnforceWireDeferredWatermark();
|
||||
// ...and the same sync point when more than this many stores are parked, whatever their
|
||||
// bytes (see the definition for the measurement). Not a knob: it bounds an object count
|
||||
// the byte budget cannot see, and MOBILEGL_IPC_WIRE_DEFERRED_MB=0 disables it too.
|
||||
static constexpr SizeT kWireDeferredCountCeiling = 1024;
|
||||
// Teardown: the caller has proven the device idle (Shutdown / RecreateTransientArenas).
|
||||
void DestroyAllDeferredWireReleases();
|
||||
// THE one Fatal{ResourceUnavailable, "buffer-write-sync"} site (rule I: no second abort
|
||||
// for the census to count), shared by the host write that cannot wait for the GPU and
|
||||
// the watermark that cannot. `site` says which.
|
||||
[[noreturn]] static void WireBufferSyncFatal(const char* site);
|
||||
// The wbuf[] gauges (PipeStats.h, Gauge::WireBuffers..WireDeferredSyncs). The peaks are
|
||||
// taken at the two points the numbers can rise - a park and a mint - and published when
|
||||
// the stats channel is on; MagmaWireReclaimScenario reads them off the server's line.
|
||||
void NoteWireStorePeaks();
|
||||
void PublishWireReclaimGauges();
|
||||
#endif
|
||||
Bool InitializeTransientArenas();
|
||||
static VkBufferUsageFlags GetVkBufferUsage(BufferKind kind);
|
||||
@@ -399,23 +263,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
Vector<WeakPtr<VkBufferResource>> m_liveResources;
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
std::unordered_map<Uint64, WireBufferResource> m_wireBuffers;
|
||||
// See DeferredWireRelease. ONE FLAT LIST rather than the per-frame-slot buckets above:
|
||||
// the whole point is that these entries do not wait for a frame slot to come round.
|
||||
Vector<DeferredWireRelease> m_deferredWireReleases;
|
||||
// Bytes currently parked in that list, kept exact so the watermark needs no walk.
|
||||
Uint64 m_deferredWireBytes = 0;
|
||||
// Live VkBuffers this arm owns: the stores held by m_wireBuffers plus the parked ones.
|
||||
// Maintained rather than counted, because the publish runs on every park.
|
||||
Uint64 m_wireStoreCount = 0;
|
||||
// Run maxima of the two numbers above and the watermark's sync count, for the gauges.
|
||||
Uint64 m_wireStoreCountPeak = 0;
|
||||
Uint64 m_deferredWireBytesPeak = 0;
|
||||
Uint64 m_wireDeferredSyncs = 0;
|
||||
// See GetWireStoreDestroyEpoch and the DeferredWireRelease comment. Bumped on every
|
||||
// path that destroys a wire store's VkBuffer, and never reset (not even by Shutdown),
|
||||
// for m_sliceEpochCounter's reason: a memo taken before a re-initialize must not match
|
||||
// a handle minted after it.
|
||||
Uint64 m_wireStoreDestroyEpoch = 0;
|
||||
#endif
|
||||
// Size m_liveResources had just after the last sweep; the next sweep waits for it to double.
|
||||
SizeT m_liveResourcesLastPruned = 0;
|
||||
|
||||
@@ -8,45 +8,13 @@
|
||||
|
||||
#include "VkBufferObject.h"
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
#include <MG_Remote/Transport/AdoptT0.h>
|
||||
#endif
|
||||
|
||||
namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
void VkBufferObject::MoveExternalFrom(VkBufferObject& other) {
|
||||
m_device = other.m_device;
|
||||
m_externalMemory = other.m_externalMemory;
|
||||
m_externalAhb = other.m_externalAhb;
|
||||
m_externalCoherent = other.m_externalCoherent;
|
||||
other.m_device = VK_NULL_HANDLE;
|
||||
other.m_externalMemory = VK_NULL_HANDLE;
|
||||
other.m_externalAhb = nullptr;
|
||||
other.m_externalCoherent = true;
|
||||
}
|
||||
|
||||
void VkBufferObject::AdoptExternal(VkDevice device, VkBuffer buffer, VkDeviceMemory memory, VkDeviceSize size,
|
||||
void* mapped, Bool coherent, void* ahb) {
|
||||
Destroy();
|
||||
m_device = device;
|
||||
m_buffer = buffer;
|
||||
m_externalMemory = memory;
|
||||
m_mappedData = mapped;
|
||||
m_size = size;
|
||||
m_externalCoherent = coherent;
|
||||
m_externalAhb = ahb;
|
||||
}
|
||||
#endif
|
||||
|
||||
VkBufferObject::VkBufferObject(VkBufferObject&& other) noexcept {
|
||||
m_allocator = other.m_allocator;
|
||||
m_buffer = other.m_buffer;
|
||||
m_allocation = other.m_allocation;
|
||||
m_mappedData = other.m_mappedData;
|
||||
m_size = other.m_size;
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
MoveExternalFrom(other);
|
||||
#endif
|
||||
|
||||
other.m_allocator = nullptr;
|
||||
other.m_buffer = VK_NULL_HANDLE;
|
||||
@@ -67,9 +35,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
m_allocation = other.m_allocation;
|
||||
m_mappedData = other.m_mappedData;
|
||||
m_size = other.m_size;
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
MoveExternalFrom(other);
|
||||
#endif
|
||||
|
||||
other.m_allocator = nullptr;
|
||||
other.m_buffer = VK_NULL_HANDLE;
|
||||
@@ -124,24 +89,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
}
|
||||
|
||||
void VkBufferObject::Destroy() {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (m_externalMemory != VK_NULL_HANDLE) {
|
||||
// P11 B2 (T0): an imported AHardwareBuffer store. Reached through the wire arm's
|
||||
// deferred release, i.e. once no submission can still name it.
|
||||
if (m_mappedData != nullptr) vkUnmapMemory(m_device, m_externalMemory);
|
||||
if (m_buffer != VK_NULL_HANDLE) vkDestroyBuffer(m_device, m_buffer, nullptr);
|
||||
vkFreeMemory(m_device, m_externalMemory, nullptr);
|
||||
MG_Remote::Transport::AdoptT0::ReleaseImported(m_externalAhb);
|
||||
m_mappedData = nullptr;
|
||||
m_buffer = VK_NULL_HANDLE;
|
||||
m_externalMemory = VK_NULL_HANDLE;
|
||||
m_externalAhb = nullptr;
|
||||
m_device = VK_NULL_HANDLE;
|
||||
m_externalCoherent = true;
|
||||
m_size = 0;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
Unmap();
|
||||
if (m_allocator != nullptr && m_buffer != VK_NULL_HANDLE && m_allocation != nullptr) {
|
||||
vmaDestroyBuffer(m_allocator, m_buffer, m_allocation);
|
||||
@@ -170,10 +117,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
}
|
||||
|
||||
void VkBufferObject::Unmap() {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// An imported store stays mapped for its life (Destroy unmaps it).
|
||||
if (m_externalMemory != VK_NULL_HANDLE) return;
|
||||
#endif
|
||||
if (!IsValid() || m_mappedData == nullptr) {
|
||||
m_mappedData = nullptr;
|
||||
return;
|
||||
@@ -200,16 +143,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
}
|
||||
|
||||
Memcpy(static_cast<Uint8*>(mapped) + offset, data, static_cast<SizeT>(size));
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (m_externalMemory != VK_NULL_HANDLE) {
|
||||
if (m_externalCoherent) return true;
|
||||
VkMappedMemoryRange range{VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE};
|
||||
range.memory = m_externalMemory;
|
||||
range.offset = 0;
|
||||
range.size = VK_WHOLE_SIZE;
|
||||
return vkFlushMappedMemoryRanges(m_device, 1, &range) == VK_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
const VkResult flushResult = vmaFlushAllocation(m_allocator, m_allocation, offset, size);
|
||||
if (flushResult != VK_SUCCESS) {
|
||||
MGLOG_E_ONCE("VkBufferObject::Upload failed: vmaFlushAllocation returned %d", flushResult);
|
||||
@@ -234,16 +167,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
if (resolvedSize == 0) {
|
||||
return true;
|
||||
}
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (m_externalMemory != VK_NULL_HANDLE) {
|
||||
if (m_externalCoherent) return true;
|
||||
VkMappedMemoryRange range{VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE};
|
||||
range.memory = m_externalMemory;
|
||||
range.offset = 0;
|
||||
range.size = VK_WHOLE_SIZE;
|
||||
return vkInvalidateMappedMemoryRanges(m_device, 1, &range) == VK_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
const VkResult result = vmaInvalidateAllocation(m_allocator, m_allocation, offset, resolvedSize);
|
||||
if (result != VK_SUCCESS) {
|
||||
|
||||
@@ -64,25 +64,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
}
|
||||
void* GetMappedData() const { return m_mappedData; }
|
||||
Bool IsMapped() const { return m_mappedData != nullptr; }
|
||||
Bool IsValid() const {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (m_externalMemory != VK_NULL_HANDLE) return m_buffer != VK_NULL_HANDLE;
|
||||
#endif
|
||||
return m_allocator != nullptr && m_buffer != VK_NULL_HANDLE && m_allocation != nullptr;
|
||||
}
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P11 B2 (T0): a store whose memory is NOT this allocator's - a client's AHardwareBuffer
|
||||
// imported with VK_ANDROID_external_memory_android_hardware_buffer into `memory` (a
|
||||
// dedicated allocation bound to `buffer`, mapped persistently at `mapped`). It behaves
|
||||
// like any mapped store (GetSlice, Upload, Invalidate), and Destroy frees the buffer and
|
||||
// the memory and drops `ahb` - which is why the store goes through the wire arm's
|
||||
// serial-gated deferred release like every other: the AHardwareBuffer is let go only once
|
||||
// no submission can still name it. `coherent` = the memory type is HOST_COHERENT.
|
||||
void AdoptExternal(VkDevice device, VkBuffer buffer, VkDeviceMemory memory, VkDeviceSize size,
|
||||
void* mapped, Bool coherent, void* ahb);
|
||||
Bool IsExternal() const { return m_externalMemory != VK_NULL_HANDLE; }
|
||||
#endif
|
||||
Bool IsValid() const { return m_allocator != nullptr && m_buffer != VK_NULL_HANDLE && m_allocation != nullptr; }
|
||||
|
||||
private:
|
||||
VmaAllocator m_allocator = nullptr;
|
||||
@@ -90,12 +72,5 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
VmaAllocation m_allocation = nullptr;
|
||||
void* m_mappedData = nullptr;
|
||||
VkDeviceSize m_size = 0;
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
VkDevice m_device = VK_NULL_HANDLE;
|
||||
VkDeviceMemory m_externalMemory = VK_NULL_HANDLE;
|
||||
void* m_externalAhb = nullptr;
|
||||
Bool m_externalCoherent = true;
|
||||
void MoveExternalFrom(VkBufferObject& other);
|
||||
#endif
|
||||
};
|
||||
} // namespace MobileGL::MG_Backend::DirectVulkan
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
#include <MG_Pipe/PipeApply.h>
|
||||
#include <MG_Remote/Server/StagedTextureStore.h>
|
||||
#include "../DirectVulkan.h"
|
||||
// P7 wave 2 package B3: rule I's tally for the silent exits on this file's wire arm.
|
||||
#include "WireDeclineTally.h"
|
||||
#endif
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
@@ -1333,42 +1331,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
}
|
||||
}
|
||||
|
||||
VkTextureManager::TextureResource* VkTextureManager::FindTextureResource(
|
||||
MG_State::GLState::ITextureObject& textureOrView) {
|
||||
auto it = m_textureResources.find(MakeTextureIdentity(&StorageTextureOf(textureOrView)));
|
||||
return it != m_textureResources.end() ? &it->second : nullptr;
|
||||
}
|
||||
|
||||
Bool VkTextureManager::HasLiveImage(MG_State::GLState::ITextureObject& textureOrView) const {
|
||||
auto it = m_textureResources.find(MakeTextureIdentity(&StorageTextureOf(textureOrView)));
|
||||
return it != m_textureResources.end() && it->second.image != VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
Bool VkTextureManager::HasPendingTexelUpload(MG_State::GLState::ITextureObject& textureOrView) const {
|
||||
auto& storage = StorageTextureOf(textureOrView);
|
||||
auto it = m_textureResources.find(MakeTextureIdentity(&storage));
|
||||
if (it == m_textureResources.end() || it->second.image == VK_NULL_HANDLE) {
|
||||
return false;
|
||||
}
|
||||
return it->second.syncedShapeVersion == storage.GetShapeVersion() &&
|
||||
it->second.syncedContentVersion != storage.GetContentVersion();
|
||||
}
|
||||
|
||||
Bool VkTextureManager::WasTextureWrittenThisRecording(MG_State::GLState::ITextureObject& textureOrView) const {
|
||||
auto it = m_textureResources.find(MakeTextureIdentity(&StorageTextureOf(textureOrView)));
|
||||
return it != m_textureResources.end() && it->second.lastRecordingWriteGeneration == m_recordingGeneration;
|
||||
}
|
||||
|
||||
void VkTextureManager::StampTextureRecordingWrite(MG_State::GLState::ITextureObject* texture) {
|
||||
if (texture == nullptr) {
|
||||
return;
|
||||
}
|
||||
auto it = m_textureResources.find(MakeTextureIdentity(&StorageTextureOf(*texture)));
|
||||
if (it != m_textureResources.end()) {
|
||||
StampResourceRecordingWrite(it->second);
|
||||
}
|
||||
}
|
||||
|
||||
void VkTextureManager::UpdateTrackedImageLayout(MG_State::GLState::ITextureObject* texture, VkImageLayout newLayout) {
|
||||
MOBILEGL_ASSERT(texture != nullptr, "UpdateTrackedImageLayout: texture is null");
|
||||
auto it = m_textureResources.find(MakeTextureIdentity(texture));
|
||||
@@ -1397,7 +1359,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
"UpdateTrackedImageLayoutAfterAttachmentWrite: textureId=%d mipLevel=%u out of range %u",
|
||||
texture->GetExternalIndex(), writtenMipLevel, resource.mipLevels);
|
||||
// Pre-pass stream bookkeeping: the render pass that just ended wrote this image.
|
||||
StampResourceRecordingWrite(resource);
|
||||
StampResourceRecordingUse(resource);
|
||||
|
||||
if (resource.layout != newLayout && resource.mipLevels > 1) {
|
||||
VkPipelineStageFlags srcStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
|
||||
@@ -1511,9 +1473,8 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
resource->aspect, 0, resource->mipLevels);
|
||||
MOBILEGL_ASSERT(ok, "TransitionTextureForStorageImage: transition failed for textureId=%d",
|
||||
texture.GetExternalIndex());
|
||||
// Pre-pass stream bookkeeping: a command referencing the image was recorded, and an
|
||||
// image unit may store to it.
|
||||
StampResourceRecordingWrite(*resource);
|
||||
// Pre-pass stream bookkeeping: a command referencing the image was recorded.
|
||||
StampResourceRecordingUse(*resource);
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -1844,8 +1805,8 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// SyncTexture reads the frontend ITextureObject: the target, the format, the level
|
||||
// chain, the dirty scan and - through UploadDirtyMipLevels - the CLIENT's mip shadow
|
||||
// texels. Under an active transport none of that memory is the server's to read
|
||||
// (rule E), which is exactly what Magma's texture-legacy-arm scope waived from P5c until
|
||||
// P7 retired it (SyncTexture). This arm is the same sync re-sourced: the SHAPE comes from the applier's
|
||||
// (rule E), which is exactly what Magma's texture-legacy-arm scope has been waiving
|
||||
// since P5c. This arm is the same sync re-sourced: the SHAPE comes from the applier's
|
||||
// resource record (MGPipeApplier().TextureResources - the resource_create /
|
||||
// resource_respecify descriptors), the TEXELS from the server's staged-texture store
|
||||
// (P5c tx, adopted at apply time), and the WHICH-LEVELS from the record's
|
||||
@@ -2108,21 +2069,13 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
if (desc.StorageKind != static_cast<Uint8>(TextureStorageType::Mipmap)) {
|
||||
MGLOG_W_ONCE("Magma wire texture {slot=%u, gen=%u}: buffer-backed textures are not migrated; declined",
|
||||
desc.Resource.Slot, desc.Resource.Gen);
|
||||
WireDeclineTally::Count(WireDeclineSite::ShapeBufferBacked);
|
||||
return false;
|
||||
}
|
||||
// ResolveWireTextureStorage has already followed ViewOf. Views share the storage
|
||||
// owner's image and layout; allocating a second image would break aliasing.
|
||||
if (!MG_Pipe::MGPipeHandleIsNull(desc.ViewOf)) {
|
||||
MGL_WIRE_DECLINE_AT(ShapeViewOfStorage,
|
||||
"texture {slot=%u, gen=%u} is a view whose storage owner did not resolve",
|
||||
desc.Resource.Slot, desc.Resource.Gen);
|
||||
return false;
|
||||
}
|
||||
if (!MG_Pipe::MGPipeHandleIsNull(desc.ViewOf)) return false;
|
||||
if (desc.Levels == 0) {
|
||||
// A create before the first respecify: no storage, nothing to back.
|
||||
MGL_WIRE_DECLINE_AT(ShapeNoLevels, "texture {slot=%u, gen=%u} has no defined level yet",
|
||||
desc.Resource.Slot, desc.Resource.Gen);
|
||||
return false;
|
||||
}
|
||||
TextureShapeInfo shapeInfo{};
|
||||
@@ -2131,7 +2084,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
"(%ux%ux%u, %u layers); declined",
|
||||
desc.Resource.Slot, desc.Resource.Gen, static_cast<Uint32>(desc.Target), desc.Width,
|
||||
desc.Height, desc.Depth, static_cast<Uint32>(desc.ArrayLayers));
|
||||
WireDeclineTally::Count(WireDeclineSite::ShapeNoVulkanShape);
|
||||
return false;
|
||||
}
|
||||
const TextureInternalFormat internalFormat = static_cast<TextureInternalFormat>(desc.InternalFormat);
|
||||
@@ -2140,7 +2092,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
if (format == VK_FORMAT_UNDEFINED) {
|
||||
MGLOG_W_ONCE("Magma wire texture {slot=%u, gen=%u}: no backing VkFormat for internal format 0x%x",
|
||||
desc.Resource.Slot, desc.Resource.Gen, desc.InternalFormat);
|
||||
WireDeclineTally::Count(WireDeclineSite::ShapeNoVkFormat);
|
||||
return false;
|
||||
}
|
||||
// X8_D24 lacks optimal-tiling support on several drivers (lavapipe included); the same
|
||||
@@ -2163,7 +2114,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
if (!TryResolveSampleCountFlagBits(static_cast<Int>(desc.Samples), resolvedSampleCount)) {
|
||||
MGLOG_W_ONCE("Magma wire texture {slot=%u, gen=%u}: unsupported sample count %u",
|
||||
desc.Resource.Slot, desc.Resource.Gen, static_cast<Uint32>(desc.Samples));
|
||||
WireDeclineTally::Count(WireDeclineSite::ShapeSampleCount);
|
||||
return false;
|
||||
}
|
||||
// glTexStorage*Multisample(samples = 1) is legal GL, but a one-sample image cannot
|
||||
@@ -2299,13 +2249,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// old image must reach the queue first; waiting only for the preservation
|
||||
// fence cannot order work that is still in the renderer's open recording.
|
||||
// The descriptor caller preflights this before capturing its command buffer.
|
||||
if (preserve && pVulkanRenderer && !pVulkanRenderer->FlushWirePendingCommandsForTextureUpdate()) {
|
||||
MGL_WIRE_DECLINE_AT(ShapePreserveFlushFailed,
|
||||
"texture {slot=%u, gen=%u}: earlier work could not be submitted before "
|
||||
"preserving its texels across a reallocation",
|
||||
desc.Resource.Slot, desc.Resource.Gen);
|
||||
return false;
|
||||
}
|
||||
if (preserve && pVulkanRenderer && !pVulkanRenderer->FlushWirePendingCommandsForTextureUpdate()) return false;
|
||||
TextureResource replacement;
|
||||
|
||||
VkImageCreateInfo imageInfo{};
|
||||
@@ -2352,14 +2296,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
}
|
||||
if (imageFormatResult != VK_SUCCESS ||
|
||||
(isMultisample && (imageFormatProperties.sampleCounts & resolvedSampleCount) == 0)) {
|
||||
// Was an MGLOG_D, which a Release build compiles away, so on the builds that ship
|
||||
// this exit left no line - one of five Shape* exits that did (with ViewOf,
|
||||
// NoLevels, preserve-flush and preserve-copy) before B3's review round.
|
||||
MGL_WIRE_DECLINE_AT(ShapeImageFlagsUnsupported,
|
||||
"texture {slot=%u, gen=%u}: image flags=0x%x sampleCount=%d are unsupported "
|
||||
"by the device",
|
||||
desc.Resource.Slot, desc.Resource.Gen, static_cast<Uint32>(imageInfo.flags),
|
||||
static_cast<Int>(imageInfo.samples));
|
||||
MGLOG_D("%s: image flags=0x%x sampleCount=%d are unsupported for texture {slot=%u, gen=%u}",
|
||||
__func__, static_cast<Uint32>(imageInfo.flags),
|
||||
static_cast<Int>(imageInfo.samples), desc.Resource.Slot, desc.Resource.Gen);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -2378,7 +2317,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
imageInfo.extent.height, imageInfo.extent.depth, imageInfo.arrayLayers,
|
||||
imageInfo.mipLevels, static_cast<Int>(imageInfo.samples),
|
||||
static_cast<Int>(imageInfo.format));
|
||||
WireDeclineTally::Count(WireDeclineSite::ShapeCreateImageFailed);
|
||||
return false;
|
||||
}
|
||||
++m_textureImageEpoch; // a new attachment image invalidates cached render passes
|
||||
@@ -2400,13 +2338,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
if (preserve) {
|
||||
FlushPendingUploads();
|
||||
if (!PreserveTextureContentsOnRecreate(m_device, m_commandPool, m_graphicsQueue,
|
||||
resource, replacement, true)) {
|
||||
MGL_WIRE_DECLINE_AT(ShapePreserveCopyFailed,
|
||||
"texture {slot=%u, gen=%u}: its texels could not be copied into the "
|
||||
"reallocated image",
|
||||
desc.Resource.Slot, desc.Resource.Gen);
|
||||
return false;
|
||||
}
|
||||
resource, replacement, true)) return false;
|
||||
}
|
||||
DeferResourceRelease(Move(resource));
|
||||
std::destroy_at(&resource);
|
||||
@@ -2453,7 +2385,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
MGLOG_E_ONCE("Magma wire texture {slot=%u, gen=%u}: pending upload for level %u exceeds the "
|
||||
"image's %u levels; left pending",
|
||||
handle.Slot, handle.Gen, static_cast<Uint32>(level), resource.mipLevels);
|
||||
WireDeclineTally::Count(WireDeclineSite::UploadLevelBeyondChain);
|
||||
continue;
|
||||
}
|
||||
const IntVec3 glExtent = store.LevelExtentOrUndefined(key, uploadTarget, level);
|
||||
@@ -2474,19 +2405,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
texelSize.y() != static_cast<Int>(std::max(resource.extent.height >> level, 1u)) ||
|
||||
(volume && texelSize.z() != static_cast<Int>(std::max(resource.depth >> level, 1u))) ||
|
||||
(!volume && Uint64(ResolveUploadArrayLayer(static_cast<TextureUploadTarget>(uploadTarget))) +
|
||||
static_cast<Uint64>(texelSize.z()) > resource.arrayLayers)) {
|
||||
// NOT `incomplete`: this arm reports SUCCESS while leaving the entry pending,
|
||||
// so the draw proceeds against texels that were never uploaded. Counted
|
||||
// separately for exactly that reason (B3).
|
||||
MGL_WIRE_DECLINE_AT(UploadLevelExtentMismatch,
|
||||
"texture {slot=%u, gen=%u} level %u: the staged extent does not match the "
|
||||
"image's extent for that level; left pending and NOT uploaded",
|
||||
handle.Slot, handle.Gen, static_cast<Uint32>(level));
|
||||
static_cast<Uint64>(texelSize.z()) > resource.arrayLayers))
|
||||
continue;
|
||||
}
|
||||
if (texelSize.x() <= 0 || texelSize.y() <= 0 || byteSize == 0) {
|
||||
MGL_WIRE_DECLINE_AT(UploadEmptyLevel, "texture {slot=%u, gen=%u} level %u is empty",
|
||||
handle.Slot, handle.Gen, static_cast<Uint32>(level));
|
||||
incomplete = true;
|
||||
continue;
|
||||
}
|
||||
@@ -2502,7 +2423,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
"level %u left pending",
|
||||
handle.Slot, handle.Gen, static_cast<Int>(resource.format),
|
||||
static_cast<Uint32>(level));
|
||||
WireDeclineTally::Count(WireDeclineSite::UploadConversion);
|
||||
incomplete = true;
|
||||
continue;
|
||||
}
|
||||
@@ -2515,10 +2435,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
(resource.aspect & VK_IMAGE_ASPECT_STENCIL_BIT);
|
||||
if (vkuFormatIsCompressed(resource.format) || !levelTexels ||
|
||||
item.byteSize % levelTexels != 0 || item.byteSize / levelTexels == 0) {
|
||||
MGL_WIRE_DECLINE_AT(UploadTexelArithmetic,
|
||||
"texture {slot=%u, gen=%u} level %u: compressed, or its byte size is not a "
|
||||
"whole number of texels",
|
||||
handle.Slot, handle.Gen, static_cast<Uint32>(level));
|
||||
incomplete = true;
|
||||
continue;
|
||||
}
|
||||
@@ -2538,10 +2454,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
if (offset[axis] < 0 || extent[axis] <= 0 ||
|
||||
static_cast<Uint64>(offset[axis]) + static_cast<Uint64>(extent[axis]) >
|
||||
static_cast<Uint64>(texelSize[axis])) {
|
||||
MGL_WIRE_DECLINE_AT(UploadRegionOutOfBounds,
|
||||
"texture {slot=%u, gen=%u} level %u: a staged region lies outside "
|
||||
"the level",
|
||||
handle.Slot, handle.Gen, static_cast<Uint32>(level));
|
||||
incomplete = true;
|
||||
return;
|
||||
}
|
||||
@@ -2584,25 +2496,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
addRegion({region.X, region.Y, region.Z, region.W, region.H, region.D});
|
||||
}
|
||||
}
|
||||
// B3: the pending gauge is sampled here, on every pass through the funnel, because a
|
||||
// refusal below does NOT consume the entries - they and their level shadows stay
|
||||
// alive for the next draw to trip over (and, on a heavy-texture trace, to accumulate).
|
||||
{
|
||||
Uint64 pendingBytes = 0;
|
||||
for (const auto& pending : record.PendingUploads) {
|
||||
pendingBytes += static_cast<Uint64>(
|
||||
store.LevelByteSize(MG_Remote::Server::StagedTextureStore::KeyForHandle(handle),
|
||||
pending.UploadTarget, pending.Level));
|
||||
}
|
||||
WireDeclineTally::SetPendingGauge(static_cast<Uint64>(record.PendingUploads.size()), pendingBytes);
|
||||
}
|
||||
if (incomplete) {
|
||||
MGL_WIRE_DECLINE_AT(UploadIncomplete,
|
||||
"texture {slot=%u, gen=%u}: at least one pending level could not be staged; "
|
||||
"every draw that samples it is declined until it can",
|
||||
handle.Slot, handle.Gen);
|
||||
return false;
|
||||
}
|
||||
if (incomplete) return false;
|
||||
if (items.empty()) {
|
||||
return true;
|
||||
}
|
||||
@@ -2611,13 +2505,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// Submit older renderer work before adding the new bytes to the batch,
|
||||
// otherwise Draw(old T), TexSubImage(T), Draw(new T) can upload before
|
||||
// the first draw. A clean texture never reaches this submission boundary.
|
||||
if (pVulkanRenderer && !pVulkanRenderer->FlushWirePendingCommandsForTextureUpdate()) {
|
||||
MGL_WIRE_DECLINE_AT(UploadFlushFailed,
|
||||
"texture {slot=%u, gen=%u}: earlier renderer work could not be submitted before "
|
||||
"its upload batch",
|
||||
handle.Slot, handle.Gen);
|
||||
return false;
|
||||
}
|
||||
if (pVulkanRenderer && !pVulkanRenderer->FlushWirePendingCommandsForTextureUpdate()) return false;
|
||||
|
||||
// UploadDirtyMipLevels' batching rules, verbatim: flush an open batch that already
|
||||
// writes this image and was touched by the open recording, and bound the staging bytes
|
||||
@@ -2714,14 +2602,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
|
||||
MG_Pipe::MGPipeHandle VkTextureManager::ResolveWireTextureStorage(
|
||||
MG_Pipe::MGPipeHandle handle, Uint32& level, Uint32& layer,
|
||||
VkFormat* viewFormat, Uint32* layerCount, Bool* outsideWindow) {
|
||||
VkFormat* viewFormat, Uint32* layerCount) {
|
||||
const auto& state = MG_Pipe::MGPipeApplier();
|
||||
if (viewFormat) *viewFormat = VK_FORMAT_UNDEFINED;
|
||||
if (outsideWindow) *outsideWindow = false;
|
||||
const auto outside = [outsideWindow] {
|
||||
if (outsideWindow) *outsideWindow = true;
|
||||
return MG_Pipe::kMGPipeNullHandle;
|
||||
};
|
||||
Uint32 mappedLevel = level, mappedLayer = layer;
|
||||
Uint32 remainingLayers = ~Uint32{0};
|
||||
VkFormat outerFormat = VK_FORMAT_UNDEFINED;
|
||||
@@ -2733,13 +2616,12 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
const auto& record = state.TextureResources[handle.Slot];
|
||||
if (!record.Live || record.Gen != handle.Gen) return MG_Pipe::kMGPipeNullHandle;
|
||||
if (MG_Pipe::MGPipeHandleIsNull(record.Desc.ViewOf)) {
|
||||
// Levels == 0 is a texture with no storage at all: every level is outside it.
|
||||
if (mappedLevel >= record.Desc.Levels) return outside();
|
||||
if (mappedLevel >= record.Desc.Levels) return MG_Pipe::kMGPipeNullHandle;
|
||||
const Uint32 layers = record.Desc.Target ==
|
||||
static_cast<Uint8>(MG_Pipe::MGPipeResourceTarget::Tex3D)
|
||||
? std::max(record.Desc.Depth >> mappedLevel, 1u)
|
||||
: std::max<Uint32>(record.Desc.ArrayLayers, 1u);
|
||||
if (mappedLayer >= layers) return outside();
|
||||
if (mappedLayer >= layers) return MG_Pipe::kMGPipeNullHandle;
|
||||
level = mappedLevel;
|
||||
layer = mappedLayer;
|
||||
if (viewFormat) *viewFormat = outerFormat;
|
||||
@@ -2751,9 +2633,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
return MG_Pipe::kMGPipeNullHandle;
|
||||
const auto& viewRecord = state.SamplerViewCsos[viewHandle.Slot];
|
||||
const auto& view = viewRecord.View;
|
||||
if (!viewRecord.Live || viewRecord.Gen != viewHandle.Gen || view.Texture != handle)
|
||||
if (!viewRecord.Live || viewRecord.Gen != viewHandle.Gen || view.Texture != handle ||
|
||||
mappedLevel >= view.NumLevels || mappedLayer >= view.NumLayers)
|
||||
return MG_Pipe::kMGPipeNullHandle;
|
||||
if (mappedLevel >= view.NumLevels || mappedLayer >= view.NumLayers) return outside();
|
||||
if (outerFormat == VK_FORMAT_UNDEFINED) {
|
||||
outerFormat = ResolveTextureFormatInfo(static_cast<TextureInternalFormat>(view.InternalFormat)).format;
|
||||
if (outerFormat == VK_FORMAT_UNDEFINED) return MG_Pipe::kMGPipeNullHandle;
|
||||
@@ -2777,12 +2659,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
Uint32 level = 0, layer = 0;
|
||||
VkFormat viewFormat = VK_FORMAT_UNDEFINED;
|
||||
const auto storage = ResolveWireTextureStorage(handle, level, layer, &viewFormat);
|
||||
if (MG_Pipe::MGPipeHandleIsNull(storage)) {
|
||||
MGL_WIRE_DECLINE_AT(TexResolveStorage,
|
||||
"texture {slot=%u, gen=%u}: no storage owner resolved", handle.Slot,
|
||||
handle.Gen);
|
||||
return nullptr;
|
||||
}
|
||||
if (MG_Pipe::MGPipeHandleIsNull(storage)) return nullptr;
|
||||
if (storage != handle) {
|
||||
auto* resource = SyncTextureResourceByHandle(storage, false, requireStorage);
|
||||
if (!resource) return nullptr;
|
||||
@@ -2791,7 +2668,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
vkuFormatCompatibilityClass(viewFormat) != vkuFormatCompatibilityClass(resource->format))) {
|
||||
MGLOG_E_ONCE("Magma wire view: format %d cannot reinterpret storage format %d",
|
||||
static_cast<Int>(viewFormat), static_cast<Int>(resource->format));
|
||||
WireDeclineTally::Count(WireDeclineSite::TexViewFormat);
|
||||
return nullptr;
|
||||
}
|
||||
return resource;
|
||||
@@ -2802,7 +2678,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
if (handle.Slot >= records.size()) {
|
||||
MGLOG_E_ONCE("Magma wire texture {slot=%u, gen=%u}: no applier record at that slot; declined",
|
||||
handle.Slot, handle.Gen);
|
||||
WireDeclineTally::Count(WireDeclineSite::TexNoApplierRecord);
|
||||
return nullptr;
|
||||
}
|
||||
auto& record = records[handle.Slot];
|
||||
@@ -2812,7 +2687,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
MGLOG_E_ONCE("Magma wire texture {slot=%u, gen=%u}: the applier's record is %s; declined",
|
||||
handle.Slot, handle.Gen,
|
||||
!record.Live ? "dead" : "of another generation");
|
||||
WireDeclineTally::Count(WireDeclineSite::TexRecordDeadOrStale);
|
||||
return nullptr;
|
||||
}
|
||||
const Uint64 key = MG_Remote::Server::StagedTextureStore::KeyForHandle(handle);
|
||||
@@ -2824,24 +2698,12 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
return &resource;
|
||||
}
|
||||
if (!SyncWireTextureShape(record, resource, requireStorage)) {
|
||||
MGL_WIRE_DECLINE_AT(TexShapeSync, "texture {slot=%u, gen=%u}: no backing image; see the Shape* tally",
|
||||
handle.Slot, handle.Gen);
|
||||
return nullptr;
|
||||
}
|
||||
if (!renderbuffer && !UploadPendingWireLevels(handle, record, resource)) {
|
||||
MGL_WIRE_DECLINE_AT(TexUploadPendingLevels,
|
||||
"texture {slot=%u, gen=%u}: pending levels could not be uploaded; see the "
|
||||
"Upload* tally",
|
||||
handle.Slot, handle.Gen);
|
||||
return nullptr;
|
||||
}
|
||||
if (requireStorage && (resource.usageFlags & VK_IMAGE_USAGE_STORAGE_BIT) == 0) {
|
||||
MGL_WIRE_DECLINE_AT(TexStorageUsage,
|
||||
"texture {slot=%u, gen=%u} is bound as a shader image but its allocation has no "
|
||||
"STORAGE usage",
|
||||
handle.Slot, handle.Gen);
|
||||
return nullptr;
|
||||
}
|
||||
if (requireStorage && (resource.usageFlags & VK_IMAGE_USAGE_STORAGE_BIT) == 0) return nullptr;
|
||||
resource.syncedWireSerial = record.Serial;
|
||||
return &resource;
|
||||
}
|
||||
@@ -3001,16 +2863,16 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
|
||||
Bool VkTextureManager::SyncTexture(MG_State::GLState::ITextureObject &texture,
|
||||
TextureResource &outResource) {
|
||||
// This is the FRONTEND-object sync: it reads - and clears - the client's mip shadow (the
|
||||
// dirty scan below, UploadDirtyMipLevels' texel / region reads and MarkStorageDirty(false)
|
||||
// clears), so it belongs to the monolith arm only. Under an active transport every wire
|
||||
// verb syncs through the handle-keyed arm (SyncTextureResourceByHandle, and the sampled
|
||||
// wire descriptors in UniformManager) from the applier's record and the staged-texture
|
||||
// store. P5c's named exemption for this function (MGPipeTextureLegacyArmScope) was retired
|
||||
// in P7 (ratchet88) once a probe proved it never armed on the apply thread; a regression
|
||||
// now meets the layer-1 guard (Fatal{RoleViolation, "texture-legacy-arm"},
|
||||
// MipmapStorage.cpp) by accessor name. This block is exactly as many lines as the one it
|
||||
// replaced: __LINE__ reaches this file's pull .text, and G1 compares the bytes.
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P5c (gt): Magma's texture sync still reads - and clears - the CLIENT's mip shadow:
|
||||
// the dirty scan below, and UploadDirtyMipLevels' texel reads / region reads /
|
||||
// MarkStorageDirty(false) clears. CONTRACT-P5C §2 migrated Espryt's sync and Magma's
|
||||
// T5 writes, and left THIS path on the legacy arm; under the verb barrier and one
|
||||
// address space the reads answer correctly, and the migration is P7's server-side
|
||||
// sync. The scope is the debt's greppable form (MipmapStorage.h); outside it the
|
||||
// layer-1 guard still aborts.
|
||||
const MG_State::GLState::MGPipeTextureLegacyArmScope textureLegacyArm;
|
||||
#endif
|
||||
// Cross-draw fast path: if the resource is already built and neither the texture's
|
||||
// pixel content (bumped in MarkStorageDirty), its SHAPE (bumped in BumpShapeVersion)
|
||||
// nor its params changed since the last sync, there is nothing to re-check or
|
||||
@@ -4114,17 +3976,18 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
VkDeviceSize offset = 0;
|
||||
// Sub-region upload (a small sprite in a big atlas): only the dirty box
|
||||
// is staged and copied. texelSize keeps the LEVEL extent - the staging
|
||||
// row copy needs it for the stride. Color formats only (an RGB-expanded
|
||||
// level is cut from its expanded bytes); the depth(+stencil) conversion
|
||||
// passes rewrite whole levels and stay full-size.
|
||||
// row copy needs it for the shadow's stride. Plain color formats only;
|
||||
// the RGB-expand and depth(+stencil) conversion passes rewrite whole
|
||||
// levels and stay full-size.
|
||||
Bool subRegion = false;
|
||||
IntVec3 regionLo = {0, 0, 0};
|
||||
IntVec3 regionSize = {0, 0, 0};
|
||||
SizeT texelBytes = 0;
|
||||
// The writes' exact footprint when it is more than one box (~100 sprites
|
||||
// whose union box spans the whole atlas): each rect is staged tightly and
|
||||
// copied with its own VkBufferImageCopy in ONE vkCmdCopyBufferToImage.
|
||||
// Empty means "stage the one box above". Only set while subRegion.
|
||||
// Scatter refinement of the single dirty box: when the storage's rect
|
||||
// list reports the writes' true footprint (~100 sprites whose union box
|
||||
// spans the whole atlas), each rect is staged tightly and copied with
|
||||
// its own VkBufferImageCopy in ONE vkCmdCopyBufferToImage. Empty means
|
||||
// "stage the one box above". Only set while subRegion.
|
||||
Vector<MG_State::GLState::MipmapDirtyRegion> rects;
|
||||
};
|
||||
|
||||
@@ -4136,7 +3999,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
targets.push_back(uploadTarget);
|
||||
}
|
||||
const TextureFormatInfo formatInfo = ResolveTextureFormatInfo(mipmapTexture.GetFormat());
|
||||
Vector<MG_State::GLState::MipmapDirtyRegion> dirtyFootprint;
|
||||
|
||||
VkDeviceSize stagingSize = 0;
|
||||
for (const TextureUploadTarget target : targets) {
|
||||
@@ -4179,48 +4041,34 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
uploadItem.source = source;
|
||||
uploadItem.offset = stagingSize;
|
||||
uploadItem.uploadByteSize = byteSize;
|
||||
// The RGB -> RGBA expansion rewrites the level texel for texel into a tight buffer
|
||||
// of its own, so it runs first and the dirty region below is taken from whichever
|
||||
// bytes are staged. Uploading an expanded level WHOLE put the shadow's stale texels
|
||||
// over whatever the GPU had drawn into the rest of it.
|
||||
if (formatInfo.expandRgbToRgba) {
|
||||
const Bool expanded = ExpandRgbSourceToRgba(source, byteSize, texelSize, formatInfo,
|
||||
uploadItem.expandedData);
|
||||
MOBILEGL_ASSERT(expanded,
|
||||
"UploadDirtyMipLevels: failed to expand RGB textureId=%d target=%s level=%u to RGBA staging data",
|
||||
mipmapTexture.GetExternalIndex(),
|
||||
MG_Util::ConvertTextureUploadTargetToString(target).c_str(), level);
|
||||
uploadItem.uploadByteSize = uploadItem.expandedData.size();
|
||||
}
|
||||
const SizeT levelBytes = uploadItem.uploadByteSize;
|
||||
if (GetAspectMaskForFormat(outResource.format) == VK_IMAGE_ASPECT_COLOR_BIT) {
|
||||
if (!formatInfo.expandRgbToRgba &&
|
||||
GetAspectMaskForFormat(outResource.format) == VK_IMAGE_ASPECT_COLOR_BIT) {
|
||||
const auto region = mipmapTexture.GetStorageDirtyRegion(target, level);
|
||||
const SizeT texelCount = static_cast<SizeT>(texelSize.x()) *
|
||||
static_cast<SizeT>(texelSize.y()) *
|
||||
static_cast<SizeT>(std::max(texelSize.z(), 1));
|
||||
// Exactly the texels the client wrote, never their union box or the storage's
|
||||
// rect list (which merges touching writes into their bounding box, folds when
|
||||
// full and is withheld past 3/4 of the box): the image may hold what the GPU
|
||||
// drew or cleared anywhere else, and the shadow is stale there. Each box is one
|
||||
// more VkBufferImageCopy in the same vkCmdCopyBufferToImage, which costs next
|
||||
// to nothing, so there is no cheaper shape worth being wrong for. A union box
|
||||
// that spans the level with gaps in it is not a whole-level write either.
|
||||
mipmapTexture.GetStorageDirtyFootprint(target, level, dirtyFootprint);
|
||||
if (!region.Empty() && (dirtyFootprint.size() >= 2 || !region.CoversWholeLevel(texelSize)) &&
|
||||
texelCount > 0 && levelBytes % texelCount == 0) {
|
||||
if (!region.Empty() && !region.CoversWholeLevel(texelSize) && texelCount > 0 &&
|
||||
byteSize % texelCount == 0) {
|
||||
uploadItem.subRegion = true;
|
||||
uploadItem.regionLo = region.lo;
|
||||
uploadItem.regionSize = {region.hi.x() - region.lo.x(), region.hi.y() - region.lo.y(),
|
||||
region.hi.z() - region.lo.z()};
|
||||
uploadItem.texelBytes = levelBytes / texelCount;
|
||||
uploadItem.texelBytes = byteSize / texelCount;
|
||||
uploadItem.uploadByteSize = static_cast<SizeT>(uploadItem.regionSize.x()) *
|
||||
static_cast<SizeT>(uploadItem.regionSize.y()) *
|
||||
static_cast<SizeT>(uploadItem.regionSize.z()) *
|
||||
uploadItem.texelBytes;
|
||||
// Several boxes: each is staged tightly and copied on its own. One box is
|
||||
// the union box above.
|
||||
if (dirtyFootprint.size() >= 2) {
|
||||
uploadItem.rects.assign(dirtyFootprint.begin(), dirtyFootprint.end());
|
||||
// Scatter refinement: the storage only hands out its rect list
|
||||
// when the rects' summed area is materially smaller than the
|
||||
// union box (0 otherwise), so taking it always stages fewer
|
||||
// bytes than the box - the very amplification this path exists
|
||||
// to avoid paying twice.
|
||||
MG_State::GLState::MipmapDirtyRegion
|
||||
dirtyRects[MG_State::GLState::MipmapStorage::kMaxDirtyRects];
|
||||
const SizeT dirtyRectCount = mipmapTexture.GetStorageDirtyRects(
|
||||
target, level, dirtyRects, MG_State::GLState::MipmapStorage::kMaxDirtyRects);
|
||||
if (dirtyRectCount >= 2) {
|
||||
uploadItem.rects.assign(dirtyRects, dirtyRects + dirtyRectCount);
|
||||
SizeT rectTexels = 0;
|
||||
for (const auto& rect : uploadItem.rects) {
|
||||
rectTexels += rect.TexelCount();
|
||||
@@ -4246,6 +4094,15 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (formatInfo.expandRgbToRgba) {
|
||||
const Bool expanded = ExpandRgbSourceToRgba(source, byteSize, texelSize, formatInfo,
|
||||
uploadItem.expandedData);
|
||||
MOBILEGL_ASSERT(expanded,
|
||||
"UploadDirtyMipLevels: failed to expand RGB textureId=%d target=%s level=%u to RGBA staging data",
|
||||
mipmapTexture.GetExternalIndex(),
|
||||
MG_Util::ConvertTextureUploadTargetToString(target).c_str(), level);
|
||||
uploadItem.uploadByteSize = uploadItem.expandedData.size();
|
||||
}
|
||||
uploadItems.push_back(Move(uploadItem));
|
||||
if (!uploadItems.back().expandedData.empty()) {
|
||||
uploadItems.back().source = uploadItems.back().expandedData.data();
|
||||
@@ -4480,7 +4337,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
const Bool depthSelectsArrayLayer = outResource.viewType == VK_IMAGE_VIEW_TYPE_1D_ARRAY ||
|
||||
outResource.viewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY ||
|
||||
outResource.viewType == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY;
|
||||
Vector<VkBufferImageCopy> rectCopies;
|
||||
for (const auto& item : uploadItems) {
|
||||
if (!item.rects.empty()) {
|
||||
// Multi-rect item: one VkBufferImageCopy per rect, all submitted in a
|
||||
@@ -4488,7 +4344,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// construction, so no two copies write the same texels. Multi-rect
|
||||
// implies subRegion, which implies a plain color aspect - the combined
|
||||
// depth-stencil split below can never see one of these.
|
||||
rectCopies.resize(item.rects.size());
|
||||
VkBufferImageCopy rectCopies[MG_State::GLState::MipmapStorage::kMaxDirtyRects];
|
||||
Uint32 rectCopyCount = 0;
|
||||
VkDeviceSize runningOffset = item.offset;
|
||||
for (const auto& rect : item.rects) {
|
||||
@@ -4519,7 +4375,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
runningOffset += static_cast<VkDeviceSize>(rect.TexelCount() * item.texelBytes);
|
||||
}
|
||||
vkCmdCopyBufferToImage(commandBuffer, stagingBuffer, outResource.image,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, rectCopyCount, rectCopies.data());
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, rectCopyCount, rectCopies);
|
||||
continue;
|
||||
}
|
||||
const Uint32 depthOrLayers = item.texelSize.z() > 0 ? static_cast<Uint32>(item.texelSize.z()) : 1u;
|
||||
|
||||
@@ -332,11 +332,6 @@ public:
|
||||
// into the frame's PRE command buffer - which executes strictly before the
|
||||
// frame's commands - instead of splitting the active render pass.
|
||||
Uint64 lastRecordingGeneration = 0;
|
||||
// The same, for the last recorded command that WRITES the image (a render pass it is an
|
||||
// attachment of, a clear, a blit/copy into it, a mip generation, a storage-image binding).
|
||||
// An upload into an image written this recording has to be ordered after that write
|
||||
// (VulkanRenderer::OrderPendingUploadAfterRecording).
|
||||
Uint64 lastRecordingWriteGeneration = 0;
|
||||
// Snapshot of ITextureObject::GetContentVersion() at the last successful sync;
|
||||
// lets SyncTexture skip the whole re-check/re-upload when content is unchanged.
|
||||
Uint64 syncedContentVersion = 0;
|
||||
@@ -386,7 +381,6 @@ public:
|
||||
std::swap(this->storageUsageResolved, that.storageUsageResolved);
|
||||
std::swap(this->syncedTextureParamsVersion, that.syncedTextureParamsVersion);
|
||||
std::swap(this->lastRecordingGeneration, that.lastRecordingGeneration);
|
||||
std::swap(this->lastRecordingWriteGeneration, that.lastRecordingWriteGeneration);
|
||||
std::swap(this->syncedContentVersion, that.syncedContentVersion);
|
||||
std::swap(this->syncedMipLevelCount, that.syncedMipLevelCount);
|
||||
std::swap(this->syncedShapeVersion, that.syncedShapeVersion);
|
||||
@@ -572,13 +566,8 @@ public:
|
||||
// Map a texture/view-relative subresource to its live storage owner. layerCount, when
|
||||
// supplied, receives the number of accessible layers starting at the input layer.
|
||||
// viewFormat is UNDEFINED for an ordinary texture, or the outer view's format.
|
||||
// outsideWindow, when supplied, says WHY a null came back: true only when every record on
|
||||
// the way was live and consistent and the (level, layer) simply is not there - past the
|
||||
// owner's levels or layers, or past a view's own window. A dead record, a missing or stale
|
||||
// view CSO and an unresolvable view format leave it false.
|
||||
MG_Pipe::MGPipeHandle ResolveWireTextureStorage(MG_Pipe::MGPipeHandle handle, Uint32& level,
|
||||
Uint32& layer, VkFormat* viewFormat = nullptr, Uint32* layerCount = nullptr,
|
||||
Bool* outsideWindow = nullptr);
|
||||
Uint32& layer, VkFormat* viewFormat = nullptr, Uint32* layerCount = nullptr);
|
||||
// Grows the live image of a handle-keyed resource to `requiredMipLevels`, carrying the
|
||||
// existing levels' content across with an in-command-buffer copy. The caller
|
||||
// (GenerateMipmap's record arm) has flushed every pending submission first, so the old
|
||||
@@ -629,26 +618,6 @@ public:
|
||||
Bool WasTouchedThisRecording(const TextureResource& resource) const {
|
||||
return resource.lastRecordingGeneration == m_recordingGeneration;
|
||||
}
|
||||
// A write is a use too. See TextureResource::lastRecordingWriteGeneration.
|
||||
void StampResourceRecordingWrite(TextureResource& resource) const {
|
||||
resource.lastRecordingGeneration = m_recordingGeneration;
|
||||
resource.lastRecordingWriteGeneration = m_recordingGeneration;
|
||||
}
|
||||
void StampTextureRecordingWrite(MG_State::GLState::ITextureObject* texture);
|
||||
// Upload-ordering queries (VulkanRenderer::OrderPendingUploadAfterRecording). None of them
|
||||
// syncs, so nothing pending is uploaded by asking. All answer for the STORAGE texture.
|
||||
//
|
||||
// Uploads are recorded into a batch submitted AHEAD of the frame's recording
|
||||
// (FlushPendingUploads), so an upload into an image the open recording already WROTE lands
|
||||
// before that write, which then overwrites the newer texels. (An image the recording only
|
||||
// read keeps the old trade: its earlier reads see the newer texels.)
|
||||
Bool HasLiveImage(MG_State::GLState::ITextureObject& textureOrView) const;
|
||||
// The next sync would record client texels into the image that is live now: same shape (a
|
||||
// shape change mints a new image instead) and content moved since the last sync.
|
||||
Bool HasPendingTexelUpload(MG_State::GLState::ITextureObject& textureOrView) const;
|
||||
Bool WasTextureWrittenThisRecording(MG_State::GLState::ITextureObject& textureOrView) const;
|
||||
// The live resource, or null.
|
||||
TextureResource* FindTextureResource(MG_State::GLState::ITextureObject& textureOrView);
|
||||
// Records that this texture is bound to a GL image unit, so its image must carry
|
||||
// VK_IMAGE_USAGE_STORAGE_BIT. Must be called before NeedsStorageImagePreparation, and
|
||||
// therefore before the render pass is committed: an image that has to be upgraded is
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -147,38 +147,8 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
VkBufferManager& GetWireBufferManager() { return m_bufferManager; }
|
||||
Bool FlushWirePendingCommandsForTextureUpdate() {
|
||||
// A new texture upload must not race graphics work that samples
|
||||
// the old texels. No current recording does not imply no in-flight
|
||||
// submission: finish the recorded work, then wait its whole prefix.
|
||||
if (HasPendingRecordedWork() && !FlushPendingCommands()) return false;
|
||||
return WaitForSubmitsUpTo(m_submitCounter, UINT64_MAX);
|
||||
return !HasPendingRecordedWork() || FlushPendingCommands();
|
||||
}
|
||||
// P7 wave 2 package B3: the submission that will carry whatever is recorded NEXT.
|
||||
// RetireWireObjects (WireDraw.inc) already tags future objects with exactly this, and
|
||||
// for the same reason: a draw being set up now is not in any submission yet, so the
|
||||
// index that names it is one past the counter. Deliberately NOT
|
||||
// GetSyncPointSubmitIndex(), which answers m_submitCounter when nothing is recorded -
|
||||
// true for a fence taken at that instant, wrong for work about to be recorded.
|
||||
Uint64 GetWireNextSubmitIndex() const { return m_submitCounter + 1; }
|
||||
// P8-D: the wire arm's indirect draw families, issued as vkCmdDraw[Indexed]Indirect[Count]
|
||||
// from the wire stores MGPipeApplier().VerbIndirectBuffer / VerbIndirectParameterBuffer
|
||||
// name. `offset` / `countOffset` are byte offsets into those stores; `stride` 0 means
|
||||
// tightly packed. FALSE = this device cannot issue the COUNT form natively (the monolith
|
||||
// arm's own condition, see the definition in WireDraw.inc) and the caller must read the
|
||||
// words on the CPU; TRUE = issued, or declined by name.
|
||||
Bool DrawWireIndirectNative(GLenum mode, GLenum type, Uint64 offset, GLsizei drawcount, GLsizei stride,
|
||||
Bool indexed, Bool counted, Uint64 countOffset);
|
||||
// P11 B2 (T0): what importing a client's AHardwareBuffer as a wire buffer store needs from
|
||||
// this device. False when the device did not take VK_ANDROID_external_memory_android_
|
||||
// hardware_buffer at creation (not Android, not advertised, or a monolith device).
|
||||
struct WireAhbImport {
|
||||
VkDevice device = VK_NULL_HANDLE;
|
||||
VkQueue queue = VK_NULL_HANDLE;
|
||||
Uint32 queueFamily = 0;
|
||||
VkPhysicalDeviceMemoryProperties memory{};
|
||||
void* getAhbProperties = nullptr; // PFN_vkGetAndroidHardwareBufferPropertiesANDROID
|
||||
};
|
||||
Bool GetWireAhbImport(WireAhbImport& out) const;
|
||||
#endif
|
||||
|
||||
// FrameContext::IRecordingObserver: prepares the frame's timer-query
|
||||
@@ -346,10 +316,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// signal as soon as the GPU actually finishes, which MC 1.21.5's
|
||||
// fence-paced ring buffers rely on to recycle their space.
|
||||
Uint64 GetSyncPointSubmitIndex() const;
|
||||
// For tests: the per-frame descriptor pools (see DescriptorPoolCensus.h).
|
||||
DescriptorPoolCensus GetDescriptorPoolCensus() const {
|
||||
return m_uniformManager ? m_uniformManager->GetDescriptorPoolCensus() : DescriptorPoolCensus{};
|
||||
}
|
||||
// Non-blocking: polls outstanding submission fences and reports
|
||||
// whether every submission up to `submitIndex` has completed.
|
||||
Bool IsSubmitIndexComplete(Uint64 submitIndex);
|
||||
@@ -413,12 +379,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
Bool ResolveOcclusionQueryResult(const Vector<Uint32>& slots, Uint64& outSamples);
|
||||
|
||||
void RequestSwapchainResize(Uint32 width, Uint32 height);
|
||||
// eglSwapInterval. Records the request; Present rebuilds the swapchain for it once the
|
||||
// current frame is on screen, and only when it maps to a different present mode. A
|
||||
// renderer created without an app window ignores it: its surface (headless, or an
|
||||
// AImageReader nobody consumes) is never displayed, and FIFO there would block once
|
||||
// the reader's queue fills.
|
||||
void SetSwapInterval(Int interval);
|
||||
// Re-query the surface and report whether the live swapchain no longer matches it
|
||||
// (size or orientation). This - not a VK_SUBOPTIMAL_KHR result - is what decides a
|
||||
// rebuild, so a surface the driver merely considers suboptimal cannot thrash.
|
||||
@@ -445,20 +405,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
Int padding[3] = {0, 0, 0};
|
||||
};
|
||||
|
||||
// P7 wave 2-B2, CONTRACT-P7 §5.2 (B'): THE FRONTEND MEMBERS ARE PULL-BUILD ONLY. In a
|
||||
// disaggregated build the monolith arm blits and generates depth mips with the baked
|
||||
// modules (WireColorBlit.inc, WireDepthMipmap.inc), so no DirectVulkan object holds a
|
||||
// ProgramObject, a ShaderObject or a SamplerObject any more - which is what takes
|
||||
// ProgramObject::{AllocateLifetimeId, AttachShader, Link, ~ProgramObject},
|
||||
// ShaderObject::{SetShaderSource, Compile, JoinPendingCompile, ReleaseCompileNode,
|
||||
// DropCompileNode} and SamplerObject::{SetWrapS, SetWrapT, SetWrapR, SetLodRange} out
|
||||
// of the link ratchet's `p7-magma` bucket (§4.2). The destructor of a SharedPtr member
|
||||
// is a reference too, so the MEMBER has to go and not only its construction.
|
||||
//
|
||||
// The structs stay, empty, so ShutdownBlitResources and the two `= {}` assignments read
|
||||
// the same on both builds.
|
||||
struct BlitResources {
|
||||
#if !MOBILEGL_BUILD_DISAGGREGATED
|
||||
SharedPtr<MG_State::GLState::ProgramObject> program;
|
||||
SharedPtr<MG_State::GLState::SamplerObject> nearestSampler;
|
||||
SharedPtr<MG_State::GLState::SamplerObject> linearSampler;
|
||||
@@ -466,18 +413,15 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
Int dstRectLocation = -1;
|
||||
Int surfaceTransformLocation = -1;
|
||||
Uint32 samplerBinding = 0;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct DepthMipmapResources {
|
||||
#if !MOBILEGL_BUILD_DISAGGREGATED
|
||||
SharedPtr<MG_State::GLState::ProgramObject> program;
|
||||
Int srcRectLocation = -1;
|
||||
Int dstRectLocation = -1;
|
||||
Int surfaceTransformLocation = -1;
|
||||
Int srcTexelSizeLocation = -1;
|
||||
Uint32 samplerBinding = 0;
|
||||
#endif
|
||||
};
|
||||
|
||||
// A single-sample staging image for multisample-resolve blits that also have to change
|
||||
@@ -523,8 +467,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
VkImageLayout* trackedLayout = nullptr;
|
||||
VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
VkImageAspectFlags aspect = 0;
|
||||
// Zero for the default framebuffer, which no arm that reads this ever reaches.
|
||||
VkImageUsageFlags usageFlags = 0;
|
||||
Uint32 level = 0, layer = 0, layers = 1, levels = 1;
|
||||
Bool isDefault = false;
|
||||
// Set when isDefault: the swapchain image index this role resolved to.
|
||||
@@ -546,89 +488,18 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
void ResolveWireDepthStencil(WireImage source, WireImage destination,
|
||||
GLint sx0, GLint sy0, GLint sx1, GLint sy1,
|
||||
GLint dx0, GLint dy0, GLint dx1, GLint dy1);
|
||||
// One aspect of a depth/stencil image through a buffer (source in TRANSFER_SRC_OPTIMAL,
|
||||
// destination in TRANSFER_DST_OPTIMAL, one format). The returned buffer is named by the
|
||||
// recorded commands and must be retired with them.
|
||||
UniquePtr<VkBufferObject> CopyWireAspectThroughBuffer(VkImage srcImage, Uint32 srcLevel, Uint32 srcLayer,
|
||||
GLint sx, GLint sy, const WireImage& destination,
|
||||
GLint dx, GLint dy, Uint32 width, Uint32 height,
|
||||
VkImageAspectFlags aspect, VkFormat format,
|
||||
Bool mirrorY, const char* fatalDetail);
|
||||
// A single-sample depth/stencil blit whose rectangles make it a plain copy, performed
|
||||
// without vkCmdBlitImage (P7 gate 5). False when the shape is not a plain copy.
|
||||
Bool CopyWireDepthStencilBlit(WireImage& source, WireImage& destination,
|
||||
GLint sx0, GLint sy0, GLint sx1, GLint sy1,
|
||||
GLint dx0, GLint dy0, GLint dx1, GLint dy1, VkImageAspectFlags aspect);
|
||||
// True when the rectangles give a multisample depth/stencil resolve a shape it declines
|
||||
// (a scale, an X mirror, a Y mirror across two formats); the decline has then been
|
||||
// logged and its INVALID_OPERATION recorded. BlitWireFramebuffers asks it BEFORE any
|
||||
// aspect runs, so a call the SHAPE declines leaves every attachment alone - the user
|
||||
// and the default draw framebuffer alike. The CAPABILITY decline inside
|
||||
// ResolveWireDepthStencil (a stencil-only resolve without VK_EXT_shader_stencil_export
|
||||
// on a device without VK_KHR_depth_stencil_resolve) is still decided per aspect, after
|
||||
// colour ran; rule I (a) accepts that (notes/p7/magma-b2.md §2.10).
|
||||
Bool DeclineWireDepthStencilResolveShape(const WireImage& source, const WireImage& destination,
|
||||
GLint sx0, GLint sy0, GLint sx1, GLint sy1,
|
||||
GLint dx0, GLint dy0, GLint dx1, GLint dy1);
|
||||
PFN_vkCreateRenderPass2 m_wireCreateRenderPass2 = nullptr;
|
||||
VkResolveModeFlags m_wireDepthResolveModes = 0;
|
||||
VkResolveModeFlags m_wireStencilResolveModes = 0;
|
||||
// P7 wave 2-B2, CONTRACT-P7 §3.2 (`multisample-blit-aspect`): the SECOND arm of the
|
||||
// multisample depth/stencil resolve, for the device that does not carry
|
||||
// VK_KHR_depth_stencil_resolve. One baked pass per aspect, sample zero, no frontend
|
||||
// object - see WireMultisampleResolve.inc. `resolved` must be a single-sample image of
|
||||
// the source's format and extent; the rect is expressed by the scissor.
|
||||
Bool ResolveWireDepthStencilWithShader(WireImage source, WireImage resolved,
|
||||
VkImageAspectFlags aspect, GLint sx0, GLint sy0,
|
||||
Uint32 width, Uint32 height);
|
||||
struct WireMultisampleResolveResources;
|
||||
WireMultisampleResolveResources* m_wireMultisampleResolveResources = nullptr;
|
||||
void DestroyWireMultisampleResolveResources();
|
||||
Bool m_wireShaderStencilExport = false;
|
||||
// VK_EXT_robustness2 (or its KHR promotion) with ONLY nullDescriptor enabled, wire arms
|
||||
// only: an invalid image unit binds a null storage descriptor (codex closeout finding 2).
|
||||
Bool m_wireNullDescriptor = false;
|
||||
// The resolve probe's verdict for this device (WireDepthResolveArm.h,
|
||||
// WireDepthResolveProbe.h): true when the no-draw render pass was measured leaving its
|
||||
// target unwritten while the shader control resolved - the shader arm then resolves
|
||||
// first and the render-pass arm is the fallback (P7 gate 5, g5-msprobe).
|
||||
Bool m_wirePreferShaderDepthResolve = false;
|
||||
// P11 B2 (T0): the device took the AHardwareBuffer import extensions at creation, and the
|
||||
// one entry point the import needs (PFN_vkGetAndroidHardwareBufferPropertiesANDROID).
|
||||
Bool m_wireAhbImport = false;
|
||||
void* m_wireGetAhbProperties = nullptr;
|
||||
// Runs the probe (memoized per device identity) and sets the member above. Called at the end of
|
||||
// device creation, after ArmPrimGenReroute: it records on m_graphicsQueue.
|
||||
void ArmWireDepthResolveOrder();
|
||||
Bool BlitWireColorToDefault(WireImage source, WireImage destination,
|
||||
GLint sx0, GLint sy0, GLint sx1, GLint sy1,
|
||||
GLint dx0, GLint dy0, GLint dx1, GLint dy1, GLenum filter);
|
||||
Bool BlitWireColorImage(WireImage source, WireImage destination,
|
||||
GLint sx0, GLint sy0, GLint sx1, GLint sy1,
|
||||
GLint dx0, GLint dy0, GLint dx1, GLint dy1, GLenum filter, Bool mipmap);
|
||||
// P7 wave 2-B, CONTRACT-P7 §3.2 (`default-color-blit-shape`): the rotated arm. Moves the
|
||||
// source region into an owned single-sample 2D image of a sampled-float format in the
|
||||
// same size-compatibility class, then shader-blits THAT to the rotated default
|
||||
// framebuffer - the shapes BlitWireColorImage itself cannot sample (an integer format, a
|
||||
// 3D or array source) become shapes it can.
|
||||
Bool BlitWireColorToDefaultThroughScratch(WireImage source, WireImage destination,
|
||||
GLint sx0, GLint sy0, GLint sx1, GLint sy1,
|
||||
GLint dx0, GLint dy0, GLint dx1, GLint dy1,
|
||||
GLenum filter);
|
||||
struct WireColorBlitResources;
|
||||
WireColorBlitResources* m_wireColorBlitResources = nullptr;
|
||||
void DestroyWireColorBlitResources();
|
||||
// P7 wave 2-B, CONTRACT-P7 §5.1 (A): the baked depth-mip program (WireDepthMipmap.inc).
|
||||
// One level of a depth chain, source and destination being two depth subresources of
|
||||
// the same image; the caller loops. It owns no frontend object, which is what the
|
||||
// monolith arm's GenerateDepthMipmapWithShader cannot say.
|
||||
Bool GenerateWireDepthMipLevel(WireImage source, WireImage destination);
|
||||
struct WireDepthMipmapResources;
|
||||
WireDepthMipmapResources* m_wireDepthMipmapResources = nullptr;
|
||||
void DestroyWireDepthMipmapResources();
|
||||
// P7 wave 2-B (exit gate 3): the readback's own write-visibility barrier, recorded before
|
||||
// the copy instead of inferred from the image's tracked layout. See WireFramebuffer.inc.
|
||||
void RecordWireReadbackWriteBarrier();
|
||||
void ReadWirePixels(GLint x, GLint y, GLsizei width, GLsizei height,
|
||||
GLenum format, GLenum type, void* pixels);
|
||||
void GenerateWireMipmap();
|
||||
@@ -688,15 +559,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
void CollectWireObjects(Uint64 completedSubmit, Bool all = false);
|
||||
Vector<WireRetiredObjects> m_wireRetiredObjects;
|
||||
Uint32 m_wirePreparationDepth = 0;
|
||||
// P8-D: set only while DrawWireIndirectNative is inside SetupDraw, so SetupWireDraw can
|
||||
// tell the wire arm's own indirect draw from a monolith indirect entry point reached under
|
||||
// a transport (still the `buffer-legacy-arm` role violation).
|
||||
Bool m_wireNativeIndirectDraw = false;
|
||||
void DispatchWireCompute(GLuint x, GLuint y, GLuint z);
|
||||
// P8-SV: glDispatchComputeIndirect on the wire arm - vkCmdDispatchIndirect from the
|
||||
// dispatch-indirect store, as the monolith arm issues it (WireDraw.inc).
|
||||
void DispatchWireComputeIndirect(GLintptr offset);
|
||||
void RewindWireDescriptorSetsIfDue();
|
||||
UniquePtr<RenderPassEntry> m_wireDrawPass;
|
||||
Vector<VkImageView> m_wireDrawViews;
|
||||
VkPipeline GetOrCreatePipelineWithInput(GLenum mode, const MagmaProgramSource& program,
|
||||
@@ -753,11 +616,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// was waited or the device was idled); drops their records and
|
||||
// recycles pooled fences.
|
||||
void OnSubmitsCompletedUpTo(Uint64 submitIndex);
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// A later fence alone cannot retire earlier submissions. Wait for the
|
||||
// whole still-live prefix before advancing the completed submit floor.
|
||||
Bool WaitForSubmitsUpTo(Uint64 submitIndex, Uint64 timeoutNs);
|
||||
#endif
|
||||
VkFence AcquirePooledSubmitFence();
|
||||
void DestroySubmitFencePool();
|
||||
Bool HasPendingRecordedWork() const;
|
||||
@@ -770,15 +628,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// only), so the presenting path's frames-in-flight pipelining is
|
||||
// untouched. Returns true when the drain ran.
|
||||
Bool TryDrainFrameTransients();
|
||||
// Bounded recording: called at the top of every GL draw and dispatch, before anything
|
||||
// of that call is recorded. Once the open frame command buffer holds
|
||||
// MagmaMaxDrawsPerCommandBuffer draws/dispatches, submits it (FlushPendingCommands) so
|
||||
// the call continues on a fresh one, then waits until at most frames-in-flight + 1
|
||||
// submissions are outstanding. A driver backs a command buffer with GPU memory it only
|
||||
// returns when the buffer is freed (Adreno: one 16 KiB mapping per chunk), so a frame
|
||||
// that is never split grows it without bound - rd12's loading frame records ~1M draws
|
||||
// into one buffer and runs the process out of vm.max_map_count.
|
||||
void SplitOversizedRecording();
|
||||
|
||||
Vector<SubmitRecord> m_inFlightSubmits;
|
||||
Vector<VkFence> m_freeSubmitFences;
|
||||
@@ -790,10 +639,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// aging clocks, while present-less loops still cross a boundary every few
|
||||
// iterations. Reset in Present.
|
||||
Uint32 m_drainsSinceLastPresent = 0;
|
||||
// GL draws/dispatches recorded into the open frame command buffer; reset whenever a
|
||||
// recording begins (OnFrameCommandRecordingBegan). See SplitOversizedRecording.
|
||||
Uint32 m_drawsInRecording = 0;
|
||||
Uint64 m_oversizedRecordingSplits = 0;
|
||||
|
||||
NativeWindowType m_window = 0;
|
||||
void* m_platformDisplay = nullptr;
|
||||
@@ -813,11 +658,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// Shutdown() deletes it.
|
||||
void* m_fallbackImageReader = nullptr;
|
||||
VulkanRendererConfig m_config;
|
||||
// Constructed for the app's window rather than a pbuffer (m_window is later filled in
|
||||
// for the pbuffer fallbacks too, so it cannot tell them apart).
|
||||
Bool m_presentsToAppWindow = false;
|
||||
// The m_config.SwapInterval the live swapchain was built for; Present compares the two.
|
||||
Optional<Int> m_swapchainSwapInterval;
|
||||
Bool m_swapchainResizeRequested = false;
|
||||
// Presentation is suspended while the window is zero-area (minimized): the
|
||||
// swapchain is unusable/out of date, so Present drops frames instead of
|
||||
@@ -936,12 +776,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
VkDeviceSize countBufferOffset, Uint32 maxDrawCount,
|
||||
Uint32 stride);
|
||||
static inline PFNDrawIndexedIndirectCountFunc s_vkCmdDrawIndexedIndirectCount = nullptr;
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P8-D: vkCmdDrawIndirectCount (same signature, same extension), for the wire arm's
|
||||
// glMultiDrawArraysIndirectCount. The monolith arm never loads it: it reads that count on
|
||||
// the CPU (DirectVulkan.cpp's MultiDrawArraysIndirectCount).
|
||||
static inline PFNDrawIndexedIndirectCountFunc s_vkCmdWireDrawIndirectCount = nullptr;
|
||||
#endif
|
||||
// VK_EXT_multi_draw entry points, loaded at device creation when the extension
|
||||
// (and its multiDraw feature) is enabled; null otherwise.
|
||||
static inline PFN_vkCmdDrawMultiEXT s_vkCmdDrawMultiEXT = nullptr;
|
||||
@@ -1925,28 +1759,8 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
MG_State::GLState::ITextureObject& texture, Uint32 mipLevel,
|
||||
Uint32 depthSlice, const VkClearValue& clearValue,
|
||||
VkImageLayout finalLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
// Records the texture's queued clears. By default the texture is synced first, which
|
||||
// uploads any pending texels BEFORE the clear - right only for texels written before it.
|
||||
// `uploadPendingTexels = false` leaves them pending (OrderPendingUploadAfterRecording).
|
||||
Bool MaterializePendingClearForTexture(VkCommandBuffer commandBuffer,
|
||||
MG_State::GLState::ITextureObject& texture,
|
||||
Bool uploadPendingTexels = true);
|
||||
// Texture uploads run in a batch submitted ahead of the frame's recording, so the upload
|
||||
// the next sync of `texture` records would land BEFORE a write already recorded into the
|
||||
// same image (a render, clear, blit or copy), and before a clear still queued for it (such
|
||||
// a clear predates the texels: SettleTexelsBeforeQueuedClear). When either holds, this
|
||||
// records the queued clear without the texels and submits the recording, so the upload
|
||||
// follows both. An image the recording only READ keeps the old trade: no submit, and its
|
||||
// earlier reads see the newer texels. It may end the render pass and replace
|
||||
// frame.commandBuffer (recording again on return), so call it only where the caller holds
|
||||
// no render-pass or command-buffer state across it. Returns whether it submitted.
|
||||
Bool OrderPendingUploadAfterRecording(FrameContext::FrameData& frame,
|
||||
MG_State::GLState::ITextureObject& texture);
|
||||
// Called for each texture a glClear/glClearBuffer* is about to queue a clear on: uploads
|
||||
// whatever texels are still pending (and mints the image if there is none), so that any
|
||||
// texel pending when the clear is materialized was written after it.
|
||||
void SettleTexelsBeforeQueuedClear(const MG_State::GLState::FramebufferObject& framebuffer,
|
||||
const MG_State::GLState::FramebufferAttachmentObject& attachment);
|
||||
MG_State::GLState::ITextureObject& texture);
|
||||
// The multisample arm of the above. Split out rather than branched inline because it
|
||||
// shares none of the transfer path: a multisample image carries no TRANSFER_DST usage, so
|
||||
// neither the TRANSFER_DST transition nor vkCmdClearColorImage is legal on one.
|
||||
@@ -1969,12 +1783,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
Bool MaterializePendingDepthStencilClearForDefaultFramebuffer(
|
||||
VkCommandBuffer commandBuffer, const MG_State::GLState::FramebufferAttachmentObject& attachment,
|
||||
const ClearAttachmentPayload& payload);
|
||||
#if !MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P7 wave 2-B2 (CONTRACT-P7 §5.2, (B')): the hidden blit program's pipeline. A
|
||||
// disaggregated build has no hidden program on either arm, so this has neither a body
|
||||
// nor a caller there.
|
||||
VkPipeline GetOrCreateBlitPipeline(const RenderPassEntry& renderPassEntry);
|
||||
#endif
|
||||
Bool GenerateDepthMipmapWithShader(FrameContext::FrameData& frame,
|
||||
MG_State::GLState::ITextureObject& texture,
|
||||
VkTextureManager::TextureResource& resource,
|
||||
|
||||
@@ -43,112 +43,6 @@
|
||||
return BlitWireColorImage(source, destination, sx0, sy0, sx1, sy1, dx0, dy0, dx1, dy1, filter, false);
|
||||
}
|
||||
|
||||
// P7 wave 2-B (CONTRACT-P7 §3.2, `default-color-blit-shape`). The shader blit below can only
|
||||
// SAMPLE its source: sampler2D, a float result, and one of two 2D view types. A framebuffer
|
||||
// whose colour attachment is RGBA8UI, or a layer of a 3D texture, is none of those, and on a
|
||||
// rotated Android surface there is no other arm - an axis-aligned vkCmdBlitImage cannot
|
||||
// express a quarter turn. So the source region becomes an owned 2D image first, through
|
||||
// vkCmdCopyImage, which cares about the texel BLOCK SIZE and not about how the block is
|
||||
// interpreted; the scratch then takes the shader blit as an ordinary 2D float source.
|
||||
//
|
||||
// REINTERPRETATION IS THE POINT FOR THE INTEGER CASE, and GL agrees: glBlitFramebuffer
|
||||
// between an integer and a normalized format is INVALID_OPERATION (GL 4.6 core 18.3.1), so
|
||||
// there is no defined result to be wrong about - only a shape that used to end the session
|
||||
// and now produces the source's bits. For a float source of the wrong VIEW TYPE the copy is
|
||||
// a plain slice extraction and the result is exactly right.
|
||||
Bool VulkanRenderer::BlitWireColorToDefaultThroughScratch(WireImage source, WireImage destination,
|
||||
GLint sx0, GLint sy0, GLint sx1, GLint sy1,
|
||||
GLint dx0, GLint dy0, GLint dx1, GLint dy1, GLenum filter) {
|
||||
if (!destination.isDefault || source.isDefault) return false;
|
||||
if (source.samples != VK_SAMPLE_COUNT_1_BIT || destination.samples != VK_SAMPLE_COUNT_1_BIT)
|
||||
return false;
|
||||
if (!source.image || !destination.image || source.image == destination.image) return false;
|
||||
const Int64 width = std::abs(static_cast<Int64>(sx1) - sx0);
|
||||
const Int64 height = std::abs(static_cast<Int64>(sy1) - sy0);
|
||||
if (!width || !height || dx0 == dx1 || dy0 == dy1) return true;
|
||||
if (std::min(sx0, sx1) < 0 || std::min(sy0, sy1) < 0 ||
|
||||
static_cast<Uint64>(std::max(sx0, sx1)) > source.extent.width ||
|
||||
static_cast<Uint64>(std::max(sy0, sy1)) > source.extent.height) return false;
|
||||
// A compressed source cannot be a colour attachment, so it cannot be a framebuffer blit's
|
||||
// source either - but the block arithmetic below would silently produce nonsense for one,
|
||||
// and "cannot happen" is the reason the guards this package retires were written as
|
||||
// asserts. The size-compatibility classes are Vulkan's own (VkFormat texel block size);
|
||||
// the destination format is whatever the swapchain uses and is always sampled-float.
|
||||
if (vkuFormatIsCompressed(source.format)) return false;
|
||||
VkFormat scratchFormat = VK_FORMAT_UNDEFINED;
|
||||
switch (vkuFormatTexelBlockSize(source.format)) {
|
||||
case 1: scratchFormat = VK_FORMAT_R8_UNORM; break;
|
||||
case 2: scratchFormat = VK_FORMAT_R8G8_UNORM; break;
|
||||
case 4: scratchFormat = VK_FORMAT_R8G8B8A8_UNORM; break;
|
||||
case 8: scratchFormat = VK_FORMAT_R16G16B16A16_SFLOAT; break;
|
||||
case 16: scratchFormat = VK_FORMAT_R32G32B32A32_SFLOAT; break;
|
||||
default: return false;
|
||||
}
|
||||
VkFormatProperties scratchProperties{};
|
||||
vkGetPhysicalDeviceFormatProperties(m_physicalDevice.handle, scratchFormat, &scratchProperties);
|
||||
const VkFormatFeatureFlags scratchRequired = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT |
|
||||
(filter == GL_LINEAR ? VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT : 0);
|
||||
if ((scratchProperties.optimalTilingFeatures & scratchRequired) != scratchRequired) return false;
|
||||
|
||||
auto scratch = MakeUnique<VkTextureManager::TextureResource>();
|
||||
VkImageCreateInfo info{VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO};
|
||||
info.imageType = VK_IMAGE_TYPE_2D;
|
||||
info.format = scratchFormat;
|
||||
info.extent = {static_cast<Uint32>(width), static_cast<Uint32>(height), 1};
|
||||
info.mipLevels = info.arrayLayers = 1;
|
||||
info.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
info.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||
info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
|
||||
info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
VmaAllocationCreateInfo allocation{};
|
||||
allocation.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE;
|
||||
allocation.requiredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
||||
if (vmaCreateImage(m_allocator, &info, &allocation, &scratch->image, &scratch->allocation,
|
||||
nullptr) != VK_SUCCESS)
|
||||
return false;
|
||||
scratch->format = scratchFormat;
|
||||
scratch->extent = {info.extent.width, info.extent.height};
|
||||
scratch->mipLevels = scratch->arrayLayers = scratch->depth = 1;
|
||||
scratch->aspect = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
WireImage staged{};
|
||||
staged.image = scratch->image;
|
||||
staged.format = scratchFormat;
|
||||
staged.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
staged.extent = scratch->extent;
|
||||
staged.trackedLayout = &scratch->layout;
|
||||
|
||||
m_textureManager->FlushPendingUploads();
|
||||
TransitionWireImage(source, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
||||
TransitionWireImage(staged, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
VkImageCopy copy{};
|
||||
// A 3D source carries its slice on z and always names layer 0; every other source
|
||||
// carries it on the layer axis, which is the same split ResolveWireImage records.
|
||||
copy.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, source.level, source.is3D ? 0u : source.layer, 1};
|
||||
copy.srcOffset = {std::min(sx0, sx1), std::min(sy0, sy1),
|
||||
source.is3D ? static_cast<Int32>(source.layer) : 0};
|
||||
copy.dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1};
|
||||
copy.dstOffset = {0, 0, 0};
|
||||
copy.extent = {static_cast<Uint32>(width), static_cast<Uint32>(height), 1};
|
||||
vkCmdCopyImage(m_frameContext.GetCurrent().commandBuffer, source.image,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, staged.image,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ©);
|
||||
staged.layout = scratch->layout;
|
||||
// The scratch holds the region at its own origin, so a reversed source rectangle
|
||||
// becomes a reversed rectangle OVER THE SCRATCH - the multisample resolve arm's shape.
|
||||
const GLint rx0 = sx1 > sx0 ? 0 : static_cast<GLint>(width);
|
||||
const GLint rx1 = sx1 > sx0 ? static_cast<GLint>(width) : 0;
|
||||
const GLint ry0 = sy1 > sy0 ? 0 : static_cast<GLint>(height);
|
||||
const GLint ry1 = sy1 > sy0 ? static_cast<GLint>(height) : 0;
|
||||
const Bool blitted = BlitWireColorImage(staged, destination, rx0, ry0, rx1, ry1,
|
||||
dx0, dy0, dx1, dy1, filter, false);
|
||||
// Retired whether or not the blit took: the copy above is already recorded against this
|
||||
// image, so the submission that consumes it owns the storage either way.
|
||||
WireRetiredObjects retired{};
|
||||
retired.textures.push_back(Move(scratch));
|
||||
RetireWireObjects(Move(retired));
|
||||
return blitted;
|
||||
}
|
||||
|
||||
Bool VulkanRenderer::BlitWireColorImage(WireImage source, WireImage destination,
|
||||
GLint sx0, GLint sy0, GLint sx1, GLint sy1,
|
||||
GLint dx0, GLint dy0, GLint dx1, GLint dy1, GLenum filter, Bool mipmap) {
|
||||
@@ -340,14 +234,7 @@
|
||||
alloc.descriptorSetCount = 1;
|
||||
alloc.pSetLayouts = &cache.descriptorLayout;
|
||||
VK_VERIFY(vkAllocateDescriptorSets(m_device, &alloc, &descriptorSet));
|
||||
// GL_LINEAR filters only a STRETCHED blit; an unscaled one (mirrored or not, on any of the
|
||||
// four transforms) is a copy and samples NEAREST, which is exact where linear filtering
|
||||
// at a quantised coordinate is not (WireColorBlitFilter.h). The format check above still
|
||||
// asks for SAMPLED_IMAGE_FILTER_LINEAR whenever GL said GL_LINEAR, so which blits reach
|
||||
// this pass is unchanged.
|
||||
const VkFilter samplerFilter = WireColorBlitFilterFor({sx0, sy0, sx1, sy1}, {dx0, dy0, dx1, dy1},
|
||||
filter, transform);
|
||||
const VkDescriptorImageInfo sampled{samplerFilter == VK_FILTER_LINEAR ? cache.linear : cache.nearest,
|
||||
const VkDescriptorImageInfo sampled{filter == GL_LINEAR ? cache.linear : cache.nearest,
|
||||
sourceView, sourceLayout};
|
||||
VkWriteDescriptorSet write{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET};
|
||||
write.dstSet = descriptorSet;
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Backend/DirectVulkan/Renderer/WireColorBlitFilter.h
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
#pragma once
|
||||
|
||||
#include <Includes.h>
|
||||
#include "../VkIncludes.h"
|
||||
|
||||
// P7 g3-blit (g3det, gate 3): WHICH SAMPLER THE WIRE ARM'S SHADER COLOUR BLIT READS ITS SOURCE
|
||||
// THROUGH.
|
||||
//
|
||||
// GL applies a blit's `filter` only where the image is STRETCHED (GL 4.6 core 18.3.1). A blit whose
|
||||
// source and destination rectangles are the same size is a copy, whatever `filter` says, and so is
|
||||
// a mirrored one. The wire arm's shader blit (WireColorBlit.inc, BlitWireColorImage) draws a quad
|
||||
// and samples `textureLod(sourceImage, texCoord, 0)` at interpolated coordinates, and it used the
|
||||
// LINEAR sampler for every GL_LINEAR blit. At 1:1 every fragment centre maps to a texel centre, so
|
||||
// in exact arithmetic linear filtering reads the same single texel. Adreno 830 quantises the
|
||||
// coordinate to sub-texel precision: a fragment that lands a fraction off the centre blends in a
|
||||
// small weight of a neighbour. minecraft-1.21.1-neoforge-create-instancing-in-world ends with a
|
||||
// 1:1 GL_LINEAR glBlitFramebuffer into FB 0, and on the wire arm 712 high-contrast pixels moved by
|
||||
// 1 LSB toward a neighbour. The monolith's vkCmdBlitImage copied them exactly
|
||||
// (~/w7/logs/g3det/VERDICT.md section 3). NEAREST within half a texel of the centre is exact, so an
|
||||
// unscaled blit takes NEAREST. Lavapipe samples texel centres exactly, so no host picture can see
|
||||
// the difference; this pure half is what the unit test pins
|
||||
// (MG_Test/Pipeline/PipelineQuirkTest.cpp, WireColorBlitSamples*).
|
||||
//
|
||||
// THE SURFACE TRANSFORM DOES NOT TURN A COPY INTO A STRETCH. BlitWireColorImage applies the
|
||||
// quarter and half turns in NDC, over a viewport of the native image, and for a quarter turn it
|
||||
// takes the logical extent as the native extent swapped. A native pixel then has exactly the pitch
|
||||
// of a logical one, and the rotation maps pixel centres onto pixel centres. So the scale test is on
|
||||
// GL's own (logical) rectangles for identity and all three rotations. BlitWireColorImage declines
|
||||
// any other transform before it chooses a sampler; for one, this answers with the filter's own
|
||||
// mapping, as before this package.
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// A glBlitFramebuffer rectangle as GL names it: two corners, either order.
|
||||
struct WireBlitRect {
|
||||
GLint x0 = 0, y0 = 0, x1 = 0, y1 = 0;
|
||||
};
|
||||
|
||||
// Same extent on both axes, orientation aside. The extents are taken in 64 bits: GL accepts any
|
||||
// GLint corner, and INT_MAX - INT_MIN does not fit in one.
|
||||
inline Bool WireBlitIsUnscaled(const WireBlitRect& source, const WireBlitRect& destination) {
|
||||
const auto extent = [](GLint a, GLint b) {
|
||||
return std::abs(static_cast<Int64>(b) - static_cast<Int64>(a));
|
||||
};
|
||||
return extent(source.x0, source.x1) == extent(destination.x0, destination.x1) &&
|
||||
extent(source.y0, source.y1) == extent(destination.y0, destination.y1);
|
||||
}
|
||||
|
||||
inline VkFilter WireColorBlitFilterFor(const WireBlitRect& source, const WireBlitRect& destination,
|
||||
GLenum filter, VkSurfaceTransformFlagBitsKHR transform) {
|
||||
if (filter != GL_LINEAR) return VK_FILTER_NEAREST;
|
||||
const Bool expressed = transform == VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR ||
|
||||
transform == VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR ||
|
||||
transform == VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR ||
|
||||
transform == VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR;
|
||||
if (expressed && WireBlitIsUnscaled(source, destination)) return VK_FILTER_NEAREST;
|
||||
return VK_FILTER_LINEAR;
|
||||
}
|
||||
} // namespace MobileGL::MG_Backend::DirectVulkan
|
||||
#endif
|
||||
@@ -1,11 +1,6 @@
|
||||
// Generated from WireColorBlit.vert / WireColorBlit.frag (Vulkan 1.0 / SPIR-V 1.0) by
|
||||
// scripts/bake_internal_shaders.py, which runs MG_Test's BakedInternalShadersTest with the
|
||||
// IN-TREE glslang and splices the words it emits into the arrays below. Do not edit the words
|
||||
// by hand: MOBILEGL_BAKED_INTERNAL_SHADERS (the same test, run as a gate) recompiles every
|
||||
// source in its table and reds on the first word that disagrees.
|
||||
//
|
||||
// These words were hand-run through glslangValidator before that gate existed, and the gate
|
||||
// reproduces them exactly - which is the one thing nobody could have known beforehand.
|
||||
// Generated from WireColorBlit.vert / WireColorBlit.frag with:
|
||||
// glslangValidator -V --target-env vulkan1.0 -o <stage>.spv <source>
|
||||
// Validated with spirv-val --target-env vulkan1.0. Do not edit the words by hand.
|
||||
#pragma once
|
||||
|
||||
static constexpr Uint32 kWireColorBlitVertexSpirv[] = {
|
||||
|
||||
@@ -1,172 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Backend/DirectVulkan/Renderer/WireDeclineTally.h
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Config.h>
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
|
||||
#include <Includes.h>
|
||||
#include <MG_Util/Debug/Log.h>
|
||||
|
||||
#include <atomic>
|
||||
|
||||
namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
|
||||
// P7 wave 2 package B3: the per-site tally behind CONTRACT-P7 §0 rule I.
|
||||
//
|
||||
// Shape is PipeApplier.h's ServerVerbSink tallies, and for the same reason (R-16: a probe may
|
||||
// not arm against a stub). "The retrace passed" and "the retrace silently dropped nine draws"
|
||||
// produce the same exit code and the same log, so the lane has to assert the number that only
|
||||
// this path can move.
|
||||
//
|
||||
// Counters are process-wide and monotone. On the spawn arm they live in the SERVER process,
|
||||
// which is where the draw path runs - a client-side reader would always see zero, so the
|
||||
// two-process case asserts pixels and reads these from the server's own dump.
|
||||
enum class WireDeclineSite : Uint32 {
|
||||
#define MGL_WIRE_DECLINE(name) name,
|
||||
#include "WireDeclines.def"
|
||||
#undef MGL_WIRE_DECLINE
|
||||
Count
|
||||
};
|
||||
|
||||
inline const char* WireDeclineSiteName(WireDeclineSite site) {
|
||||
switch (site) {
|
||||
#define MGL_WIRE_DECLINE(name) \
|
||||
case WireDeclineSite::name: \
|
||||
return #name;
|
||||
#include "WireDeclines.def"
|
||||
#undef MGL_WIRE_DECLINE
|
||||
case WireDeclineSite::Count:
|
||||
break;
|
||||
}
|
||||
return "Unnamed";
|
||||
}
|
||||
|
||||
class WireDeclineTally {
|
||||
public:
|
||||
static constexpr SizeT kSiteCount = static_cast<SizeT>(WireDeclineSite::Count);
|
||||
|
||||
static void Count(WireDeclineSite site) {
|
||||
Slots()[static_cast<SizeT>(site)].fetch_add(1, std::memory_order_relaxed);
|
||||
Total().fetch_add(1, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
static Uint64 Get(WireDeclineSite site) {
|
||||
return Slots()[static_cast<SizeT>(site)].load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
static Uint64 TotalDeclines() { return Total().load(std::memory_order_relaxed); }
|
||||
|
||||
// The memory half (package M1's thread): a refused upload does not consume its
|
||||
// PendingUpload entry, so the entry and the level shadow behind it stay alive. These are
|
||||
// GAUGES, not counters - the last observed live depth, sampled where the refusal happens -
|
||||
// so a monotone climb across frames is the signature that a refusal is also a leak.
|
||||
static void SetPendingGauge(Uint64 entries, Uint64 bytes) {
|
||||
PendingEntries().store(entries, std::memory_order_relaxed);
|
||||
PendingBytes().store(bytes, std::memory_order_relaxed);
|
||||
Uint64 peak = PeakPendingBytes().load(std::memory_order_relaxed);
|
||||
while (bytes > peak && !PeakPendingBytes().compare_exchange_weak(peak, bytes, std::memory_order_relaxed)) {
|
||||
}
|
||||
}
|
||||
// The frame-serial floor's own counter. An "unsound serial complete" is an advance of
|
||||
// VkBufferManager's completed-frame-serial floor to a serial that ANOTHER submission still
|
||||
// in flight also carries - i.e. the renderer telling the buffer manager "frame N-1 is done"
|
||||
// while the submission holding frame N-1's buffer copies is still executing. It is what
|
||||
// lets a streamed glBufferSubData take the unordered host path and tear one draw's vertex
|
||||
// range. With a provable floor it is unreachable, so this counter is the red-once's reading:
|
||||
// non-zero on the wire arms before the fix, zero after, zero on monolith either way.
|
||||
static void CountUnsoundSerialComplete() {
|
||||
UnsoundSerial().fetch_add(1, std::memory_order_relaxed);
|
||||
}
|
||||
static Uint64 UnsoundSerialCompleteEvents() { return UnsoundSerial().load(std::memory_order_relaxed); }
|
||||
|
||||
static Uint64 PendingUploadEntries() { return PendingEntries().load(std::memory_order_relaxed); }
|
||||
static Uint64 PendingUploadBytes() { return PendingBytes().load(std::memory_order_relaxed); }
|
||||
static Uint64 PeakPendingUploadBytes() { return PeakPendingBytes().load(std::memory_order_relaxed); }
|
||||
|
||||
static void Reset() {
|
||||
for (SizeT i = 0; i < kSiteCount; ++i) Slots()[i].store(0, std::memory_order_relaxed);
|
||||
Total().store(0, std::memory_order_relaxed);
|
||||
UnsoundSerial().store(0, std::memory_order_relaxed);
|
||||
PendingEntries().store(0, std::memory_order_relaxed);
|
||||
PendingBytes().store(0, std::memory_order_relaxed);
|
||||
PeakPendingBytes().store(0, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
// One line per site that moved, plus the pending gauges. Called at session teardown and
|
||||
// from the forced-condition harness; silent when nothing declined, so a green lane stays
|
||||
// quiet and a lane that dropped a draw cannot.
|
||||
static void Dump(const char* tag) {
|
||||
// The floor counter prints unconditionally: "zero unsound advances" is the reading the
|
||||
// red-once needs, and an absent line cannot be told from a lane that never ran.
|
||||
MGLOG_I("MGWIRE-FLOOR[%s] unsoundSerialComplete=%llu", tag,
|
||||
static_cast<unsigned long long>(UnsoundSerialCompleteEvents()));
|
||||
if (TotalDeclines() == 0 && PeakPendingUploadBytes() == 0) return;
|
||||
MGLOG_I("MGWIRE-DECLINES[%s] total=%llu pendingEntries=%llu pendingBytes=%llu peakPendingBytes=%llu", tag,
|
||||
static_cast<unsigned long long>(TotalDeclines()),
|
||||
static_cast<unsigned long long>(PendingUploadEntries()),
|
||||
static_cast<unsigned long long>(PendingUploadBytes()),
|
||||
static_cast<unsigned long long>(PeakPendingUploadBytes()));
|
||||
for (SizeT i = 0; i < kSiteCount; ++i) {
|
||||
const Uint64 value = Slots()[i].load(std::memory_order_relaxed);
|
||||
if (!value) continue;
|
||||
MGLOG_I("MGWIRE-DECLINES[%s] %s=%llu", tag, WireDeclineSiteName(static_cast<WireDeclineSite>(i)),
|
||||
static_cast<unsigned long long>(value));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static std::atomic<Uint64>* Slots() {
|
||||
static std::atomic<Uint64> slots[kSiteCount]{};
|
||||
return slots;
|
||||
}
|
||||
static std::atomic<Uint64>& Total() {
|
||||
static std::atomic<Uint64> total{0};
|
||||
return total;
|
||||
}
|
||||
static std::atomic<Uint64>& PendingEntries() {
|
||||
static std::atomic<Uint64> value{0};
|
||||
return value;
|
||||
}
|
||||
static std::atomic<Uint64>& PendingBytes() {
|
||||
static std::atomic<Uint64> value{0};
|
||||
return value;
|
||||
}
|
||||
static std::atomic<Uint64>& PeakPendingBytes() {
|
||||
static std::atomic<Uint64> value{0};
|
||||
return value;
|
||||
}
|
||||
static std::atomic<Uint64>& UnsoundSerial() {
|
||||
static std::atomic<Uint64> value{0};
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
// Every decline goes through this: the tally moves ALWAYS, the log line is once per site.
|
||||
// `MGL_WIRE_DECLINE_AT(Site, "why", ...); return false;` is the statement pair that replaces
|
||||
// a bare `return false;` (the few sites that call WireDeclineTally::Count directly stand
|
||||
// under an MGLOG_W/E of their own; scripts/ci/wire_declines_audit.py holds them to that).
|
||||
//
|
||||
// A DECLINE IS NOT ALWAYS A SKIPPED DRAW, so the line does not say "draw". The Tex*, Shape* and
|
||||
// Upload* rows are counted per texture SYNC: SyncTextureResourceByHandle is reached from the
|
||||
// draw/dispatch texture preparation, but also from the descriptor resolver, framebuffer
|
||||
// attachments, CopyTexSubImage, mipmap generation and CopyImageSubData - each of which Fatals
|
||||
// right after a failed sync - and from texture readback, which falls back to the unbacked
|
||||
// shadow. A draw that samples three unsyncable textures counts three; a failed attachment
|
||||
// sync counts once and is then a Fatal, not a skipped draw.
|
||||
#define MGL_WIRE_DECLINE_AT(site, fmt, ...) \
|
||||
do { \
|
||||
::MobileGL::MG_Backend::DirectVulkan::WireDeclineTally::Count( \
|
||||
::MobileGL::MG_Backend::DirectVulkan::WireDeclineSite::site); \
|
||||
MGLOG_E_ONCE("Magma wire decline [" #site "]: " fmt, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
} // namespace MobileGL::MG_Backend::DirectVulkan
|
||||
|
||||
#endif // MOBILEGL_BUILD_DISAGGREGATED
|
||||
@@ -1,128 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Backend/DirectVulkan/Renderer/WireDeclines.def
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
// P7 wave 2 package B3. THE NAMES OF EVERY WAY THE MAGMA WIRE ARM CAN DECLINE.
|
||||
//
|
||||
// A DECLINE IS NOT ALWAYS A SKIPPED DRAW. The SetupWireDraw / DispatchWireCompute rows are one
|
||||
// per refused draw or dispatch; the Tex* / Shape* / Upload* rows are counted per texture SYNC,
|
||||
// which the draw path reaches once per sampled texture and the descriptor resolver, framebuffer
|
||||
// attachments, CopyTexSubImage, mipmap generation, CopyImageSubData and texture readback reach
|
||||
// on their own (WireDeclineTally.h, above MGL_WIRE_DECLINE_AT).
|
||||
//
|
||||
// CONTRACT-P7 §0 rule I says a refusal on the wire arm is either a named decline or a named
|
||||
// Fatal. Before B3 the draw path had a third shape the rule does not admit: a bare
|
||||
// `return false` with no log, no counter and no census entry - roughly twenty of them in
|
||||
// SetupWireDraw alone, plus the texture-sync chain behind PrepareWireTextureResources. A draw
|
||||
// that took one of those exits left NO trace anywhere, which is precisely why the OpenRA
|
||||
// device divergence survived four device windows with client and server logs that were
|
||||
// LINE-IDENTICAL between a passing and a failing run.
|
||||
//
|
||||
// Each row below is one such exit. The name is what the decline logs and what the tally
|
||||
// counts, so "which exit did this frame take" is answerable from a counter dump instead of
|
||||
// from a bisect. Rows are append-only: the integration lane asserts specific counters moved.
|
||||
//
|
||||
// EVERY ROW HAS A SITE AND EVERY SITE HAS A LINE. A row with no site is a name that can never
|
||||
// be counted - it reads as "this cannot happen here" when it only means "nobody wired it up" -
|
||||
// and a site with no line puts the reader back on a bisect. Sites reached through a macro
|
||||
// (MGL_WIRE_DECLINE_AT) get both at once; the few that use WireDeclineTally::Count directly do
|
||||
// so ONLY because the statement above them already carries the same reason as an _ONCE log.
|
||||
// scripts/ci/wire_declines_audit.py holds both halves.
|
||||
//
|
||||
// MGL_WIRE_DECLINE(Name)
|
||||
|
||||
// ---- SetupWireDraw, in statement order -------------------------------------------------
|
||||
MGL_WIRE_DECLINE(ProgramLinkOrSpirv)
|
||||
MGL_WIRE_DECLINE(PointSizeCapability)
|
||||
MGL_WIRE_DECLINE(TextureResourcesUnprepared)
|
||||
MGL_WIRE_DECLINE(VertexFormatUnsupported)
|
||||
MGL_WIRE_DECLINE(VertexAttributeWindow)
|
||||
MGL_WIRE_DECLINE(VertexStreamCountZero)
|
||||
MGL_WIRE_DECLINE(VertexStreamRead)
|
||||
MGL_WIRE_DECLINE(VertexStreamConverter)
|
||||
MGL_WIRE_DECLINE(VertexTransientUpload)
|
||||
MGL_WIRE_DECLINE(IndexViewMissing)
|
||||
MGL_WIRE_DECLINE(IndexTypeWidth)
|
||||
MGL_WIRE_DECLINE(IndexWindow)
|
||||
MGL_WIRE_DECLINE(IndexStreamRead)
|
||||
MGL_WIRE_DECLINE(IndexTransientUpload)
|
||||
MGL_WIRE_DECLINE(IndexSliceInvalid)
|
||||
MGL_WIRE_DECLINE(UniformBufferBinding)
|
||||
MGL_WIRE_DECLINE(NoAttachments)
|
||||
MGL_WIRE_DECLINE(PipelineUnavailable)
|
||||
MGL_WIRE_DECLINE(CurrentAttributePayload)
|
||||
MGL_WIRE_DECLINE(CurrentAttributeUpload)
|
||||
MGL_WIRE_DECLINE(BeginRenderPass)
|
||||
|
||||
// ---- DispatchWireCompute (and DispatchWireComputeIndirect, P8-SV) -------------------------
|
||||
MGL_WIRE_DECLINE(ComputeProgramLinkOrSpirv)
|
||||
MGL_WIRE_DECLINE(ComputeTextureResourcesUnprepared)
|
||||
MGL_WIRE_DECLINE(ComputePipelineUnavailable)
|
||||
MGL_WIRE_DECLINE(ComputeUniformBufferBinding)
|
||||
|
||||
// ---- UniformManager::PrepareWireTextureResources ----------------------------------------
|
||||
MGL_WIRE_DECLINE(DescriptorDeclined)
|
||||
MGL_WIRE_DECLINE(SamplerLocationAlias)
|
||||
MGL_WIRE_DECLINE(SamplerUnitRange)
|
||||
|
||||
// ---- VkTextureManager::SyncTextureResourceByHandle --------------------------------------
|
||||
MGL_WIRE_DECLINE(TexResolveStorage)
|
||||
MGL_WIRE_DECLINE(TexViewFormat)
|
||||
MGL_WIRE_DECLINE(TexNoApplierRecord)
|
||||
MGL_WIRE_DECLINE(TexRecordDeadOrStale)
|
||||
MGL_WIRE_DECLINE(TexShapeSync)
|
||||
MGL_WIRE_DECLINE(TexUploadPendingLevels)
|
||||
MGL_WIRE_DECLINE(TexStorageUsage)
|
||||
|
||||
// ---- VkTextureManager::UploadPendingWireLevels ------------------------------------------
|
||||
// The five `incomplete`/false exits the investigation named, plus the two that leave an
|
||||
// entry pending WITHOUT failing (a `continue`) - those are the ones that can starve a draw
|
||||
// of its texels while still reporting success, so they are counted separately.
|
||||
MGL_WIRE_DECLINE(UploadLevelBeyondChain)
|
||||
MGL_WIRE_DECLINE(UploadLevelExtentMismatch)
|
||||
MGL_WIRE_DECLINE(UploadEmptyLevel)
|
||||
MGL_WIRE_DECLINE(UploadConversion)
|
||||
MGL_WIRE_DECLINE(UploadTexelArithmetic)
|
||||
MGL_WIRE_DECLINE(UploadRegionOutOfBounds)
|
||||
MGL_WIRE_DECLINE(UploadIncomplete)
|
||||
MGL_WIRE_DECLINE(UploadFlushFailed)
|
||||
|
||||
// ---- VkTextureManager::SyncWireTextureShape ---------------------------------------------
|
||||
MGL_WIRE_DECLINE(ShapeBufferBacked)
|
||||
MGL_WIRE_DECLINE(ShapeViewOfStorage)
|
||||
MGL_WIRE_DECLINE(ShapeNoLevels)
|
||||
MGL_WIRE_DECLINE(ShapeNoVulkanShape)
|
||||
MGL_WIRE_DECLINE(ShapeNoVkFormat)
|
||||
MGL_WIRE_DECLINE(ShapeSampleCount)
|
||||
MGL_WIRE_DECLINE(ShapePreserveFlushFailed)
|
||||
MGL_WIRE_DECLINE(ShapeImageFlagsUnsupported)
|
||||
MGL_WIRE_DECLINE(ShapeCreateImageFailed)
|
||||
// Appended by the B3 review round: the preserve-copy arm of a reallocation was the one exit in
|
||||
// SyncWireTextureShape still leaving no trace at all.
|
||||
MGL_WIRE_DECLINE(ShapePreserveCopyFailed)
|
||||
|
||||
// ---- VulkanRenderer::GenerateWireMipmap (P8-F) -----------------------------------------
|
||||
// `mipmap-shader-format-or-shape` was a Fatal on this arm and a decline on the monolith arm; it
|
||||
// is the monolith's decline now. Counted once per refused glGenerateMipmap, whose chain is left
|
||||
// as it was.
|
||||
MGL_WIRE_DECLINE(MipmapShaderFormatOrShape)
|
||||
|
||||
// ---- VulkanRenderer::DrawWireIndirectNative (P8-D), in statement order -----------------------
|
||||
MGL_WIRE_DECLINE(IndirectBufferUnbound)
|
||||
MGL_WIRE_DECLINE(IndirectCommandRange)
|
||||
MGL_WIRE_DECLINE(IndirectCountRange)
|
||||
MGL_WIRE_DECLINE(IndirectIndexStore)
|
||||
|
||||
// ---- P8-SV -------------------------------------------------------------------------------
|
||||
// VulkanRenderer::GenerateWireMipmap: a combined depth/stencil (or stencil-only) chain, which no
|
||||
// arm generates (CONTRACT-P7 §3.2). It logged but was never counted, so MGWIRE-DECLINES could
|
||||
// not see it. Counted once per refused glGenerateMipmap, whose chain is left as it was.
|
||||
MGL_WIRE_DECLINE(MipmapDepthStencilAspect)
|
||||
// VulkanRenderer::DispatchWireComputeIndirect, in statement order: the dispatch-indirect store
|
||||
// is missing, or the three group-count words lie outside it or are misaligned.
|
||||
MGL_WIRE_DECLINE(DispatchIndirectBufferUnbound)
|
||||
MGL_WIRE_DECLINE(DispatchIndirectRange)
|
||||
@@ -1,28 +0,0 @@
|
||||
#version 450
|
||||
// The monolith arm's kDepthMipmapFragmentShaderSource (VulkanRenderer.cpp), ported to the
|
||||
// baked pipeline: the same 2x2 box of texelFetches, the same clamp, the same average, the
|
||||
// same gl_FragDepth. It is a PORT and not a rewrite on purpose - CONTRACT-P7 §3.2 retires a
|
||||
// refusal by making the wire arm observably the monolith's, so the two arms have to agree
|
||||
// texel for texel, including where they read.
|
||||
//
|
||||
// uSrcTexelSize arrives on the push constant rather than in a uniform block: the wire arm
|
||||
// owns no GL program, so there is no default-block uniform to write and no global UBO to
|
||||
// bind. That is the whole of OQ-13's narrow half for this program.
|
||||
layout(push_constant) uniform DepthMipmapRect {
|
||||
vec4 srcRect;
|
||||
vec4 dstRect;
|
||||
int surfaceTransform;
|
||||
ivec2 srcTexelSize;
|
||||
} rect;
|
||||
layout(set = 0, binding = 0) uniform sampler2D sourceImage;
|
||||
layout(location = 0) in vec2 texCoord;
|
||||
|
||||
void main() {
|
||||
ivec2 srcBase = ivec2(texCoord * vec2(rect.srcTexelSize));
|
||||
ivec2 srcMax = rect.srcTexelSize - ivec2(1);
|
||||
float depth0 = texelFetch(sourceImage, clamp(srcBase, ivec2(0), srcMax), 0).r;
|
||||
float depth1 = texelFetch(sourceImage, clamp(srcBase + ivec2(1, 0), ivec2(0), srcMax), 0).r;
|
||||
float depth2 = texelFetch(sourceImage, clamp(srcBase + ivec2(0, 1), ivec2(0), srcMax), 0).r;
|
||||
float depth3 = texelFetch(sourceImage, clamp(srcBase + ivec2(1, 1), ivec2(0), srcMax), 0).r;
|
||||
gl_FragDepth = 0.25 * (depth0 + depth1 + depth2 + depth3);
|
||||
}
|
||||
@@ -1,328 +0,0 @@
|
||||
// Included by VulkanRenderer.cpp inside the backend namespace, after WireColorBlit.inc.
|
||||
// The native depth mip owns no frontend object and never invokes the GL shader compiler.
|
||||
//
|
||||
// WHY THIS FILE EXISTS AT ALL. vkCmdBlitImage is the ordinary way to halve a mip, and for a
|
||||
// depth format it is often not available: VK_FORMAT_FEATURE_BLIT_DST is optional for depth,
|
||||
// and the monolith arm has carried a shader fallback for exactly that case since before the
|
||||
// split (VulkanRenderer.cpp's GenerateDepthMipmapWithShader). The wire arm had no such
|
||||
// fallback, so every depth mip the device could not blit died as
|
||||
// `Magma:mipmap-shader-format-or-shape`, and a DEPTH|STENCIL texture died one guard earlier
|
||||
// as `Magma:depth-stencil-mipmap@P7` whether or not it could be blitted.
|
||||
//
|
||||
// The monolith fallback is not reusable here and that is the whole of CONTRACT-P7 §5.1 (A):
|
||||
// it builds a GL ProgramObject, two GL ShaderObjects and a GL sampler, binds through the
|
||||
// uniform manager's global UBO, and writes uSrcTexelSize as a default-block uniform - four
|
||||
// frontend objects and a GL compiler on the server's apply thread. The baked program below is
|
||||
// the same shader with the same arithmetic, driven by a push constant and its own descriptor
|
||||
// set, which is what lets the server generate a depth mip while owning nothing of the client.
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
#include "WireDepthMipmapSpirv.h"
|
||||
|
||||
struct VulkanRenderer::WireDepthMipmapResources {
|
||||
struct Target {
|
||||
VkFormat format = VK_FORMAT_UNDEFINED;
|
||||
VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
VkRenderPass renderPass = VK_NULL_HANDLE;
|
||||
VkPipeline pipeline = VK_NULL_HANDLE;
|
||||
};
|
||||
VkShaderModule vertex = VK_NULL_HANDLE, fragment = VK_NULL_HANDLE;
|
||||
VkDescriptorSetLayout descriptorLayout = VK_NULL_HANDLE;
|
||||
VkPipelineLayout pipelineLayout = VK_NULL_HANDLE;
|
||||
VkSampler nearest = VK_NULL_HANDLE;
|
||||
Vector<Target> targets;
|
||||
};
|
||||
|
||||
void VulkanRenderer::DestroyWireDepthMipmapResources() {
|
||||
if (!m_wireDepthMipmapResources) return;
|
||||
// Shutdown calls this after vkDeviceWaitIdle and after all per-submit
|
||||
// descriptor pools/framebuffers/views have been collected.
|
||||
auto& cache = *m_wireDepthMipmapResources;
|
||||
for (const auto& target : cache.targets) {
|
||||
vkDestroyPipeline(m_device, target.pipeline, nullptr);
|
||||
vkDestroyRenderPass(m_device, target.renderPass, nullptr);
|
||||
}
|
||||
vkDestroySampler(m_device, cache.nearest, nullptr);
|
||||
vkDestroyPipelineLayout(m_device, cache.pipelineLayout, nullptr);
|
||||
vkDestroyDescriptorSetLayout(m_device, cache.descriptorLayout, nullptr);
|
||||
vkDestroyShaderModule(m_device, cache.vertex, nullptr);
|
||||
vkDestroyShaderModule(m_device, cache.fragment, nullptr);
|
||||
delete m_wireDepthMipmapResources;
|
||||
m_wireDepthMipmapResources = nullptr;
|
||||
}
|
||||
|
||||
// ONE LEVEL, source -> destination, both depth subresources of the same image. The shape
|
||||
// mirrors BlitWireColorImage deliberately: the same lazily built module pair, the same
|
||||
// per-format render pass/pipeline cache, the same per-submit descriptor pool, and the
|
||||
// same GENERAL-on-both-sides layout rule for a same-image pass, so the two native passes
|
||||
// cannot disagree about how an image is handed between them.
|
||||
Bool VulkanRenderer::GenerateWireDepthMipLevel(WireImage source, WireImage destination) {
|
||||
const Bool sameImage = source.image == destination.image;
|
||||
if (!source.image || !destination.image) return false;
|
||||
if (sameImage && source.level == destination.level && source.layer == destination.layer)
|
||||
return false;
|
||||
if (source.isDefault || destination.isDefault) return false;
|
||||
if (source.samples != VK_SAMPLE_COUNT_1_BIT || destination.samples != VK_SAMPLE_COUNT_1_BIT)
|
||||
return false;
|
||||
if (source.is3D || destination.is3D) return false;
|
||||
// P8-SV: THE PASS MAKES 2D VIEWS (makeView below), which a 1D, 1D-array or 3D image does
|
||||
// not admit. A caller that fills viewType from the image gets a refusal here, and the
|
||||
// wire arm's GenerateWireMipmap asks the same question before it grows the chain.
|
||||
for (const VkImageViewType viewType : {source.viewType, destination.viewType}) {
|
||||
if (viewType == VK_IMAGE_VIEW_TYPE_1D || viewType == VK_IMAGE_VIEW_TYPE_1D_ARRAY ||
|
||||
viewType == VK_IMAGE_VIEW_TYPE_3D)
|
||||
return false;
|
||||
}
|
||||
if (source.format != destination.format) return false;
|
||||
// DEPTH ONLY. A combined depth/stencil image can be sampled for its depth and
|
||||
// rendered as a depth attachment, but this pass writes gl_FragDepth and NOTHING
|
||||
// else - the stencil aspect would come out of the render pass undefined, which is
|
||||
// not what GL's glGenerateMipmap promises for the level it just produced. The
|
||||
// caller declines that shape rather than producing half a level.
|
||||
if (source.aspect != VK_IMAGE_ASPECT_DEPTH_BIT ||
|
||||
destination.aspect != VK_IMAGE_ASPECT_DEPTH_BIT) return false;
|
||||
if (!source.extent.width || !source.extent.height ||
|
||||
!destination.extent.width || !destination.extent.height) return false;
|
||||
VkFormatProperties properties{};
|
||||
vkGetPhysicalDeviceFormatProperties(m_physicalDevice.handle, source.format, &properties);
|
||||
const VkFormatFeatureFlags required = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT |
|
||||
VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
||||
if ((properties.optimalTilingFeatures & required) != required) return false;
|
||||
|
||||
// The baked block's layout, and the offsets are not a guess: the generated header
|
||||
// decorates its members at 0 / 16 / 32 / 40, which is where a vec4, a vec4, an int
|
||||
// and an 8-byte-aligned ivec2 land. The pad is what makes the C++ agree.
|
||||
struct Constants {
|
||||
float srcRect[4];
|
||||
float dstRect[4];
|
||||
Int32 surfaceTransform;
|
||||
Int32 reservedForIvec2Alignment;
|
||||
Int32 srcTexelSize[2];
|
||||
};
|
||||
static_assert(sizeof(Constants) == 48);
|
||||
static_assert(offsetof(Constants, srcTexelSize) == 40);
|
||||
|
||||
if (!m_wireDepthMipmapResources) {
|
||||
m_wireDepthMipmapResources = new WireDepthMipmapResources;
|
||||
auto& cache = *m_wireDepthMipmapResources;
|
||||
const auto shader = [&](const Uint32* code, SizeT bytes, VkShaderModule& module) {
|
||||
VkShaderModuleCreateInfo info{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO};
|
||||
info.codeSize = bytes;
|
||||
info.pCode = code;
|
||||
VK_VERIFY(vkCreateShaderModule(m_device, &info, nullptr, &module));
|
||||
};
|
||||
shader(kWireDepthMipmapVertexSpirv, sizeof(kWireDepthMipmapVertexSpirv), cache.vertex);
|
||||
shader(kWireDepthMipmapFragmentSpirv, sizeof(kWireDepthMipmapFragmentSpirv), cache.fragment);
|
||||
const VkDescriptorSetLayoutBinding binding{0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||
1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
|
||||
VkDescriptorSetLayoutCreateInfo layout{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO};
|
||||
layout.bindingCount = 1;
|
||||
layout.pBindings = &binding;
|
||||
VK_VERIFY(vkCreateDescriptorSetLayout(m_device, &layout, nullptr, &cache.descriptorLayout));
|
||||
// BOTH STAGES ON ONE RANGE: the block is declared identically in the vertex and
|
||||
// fragment sources (a push-constant block must be), the vertex stage reads the
|
||||
// rects and the fragment stage reads srcTexelSize.
|
||||
const VkPushConstantRange push{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
0, sizeof(Constants)};
|
||||
VkPipelineLayoutCreateInfo pipelineLayout{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO};
|
||||
pipelineLayout.setLayoutCount = 1;
|
||||
pipelineLayout.pSetLayouts = &cache.descriptorLayout;
|
||||
pipelineLayout.pushConstantRangeCount = 1;
|
||||
pipelineLayout.pPushConstantRanges = &push;
|
||||
VK_VERIFY(vkCreatePipelineLayout(m_device, &pipelineLayout, nullptr, &cache.pipelineLayout));
|
||||
// NEAREST, and it is not a default: the fragment shader does its own 2x2 box with
|
||||
// texelFetch, so any filtering the sampler added would be applied twice. It also
|
||||
// keeps the sampler legal on a device that does not advertise linear filtering for
|
||||
// depth formats, which is most of them.
|
||||
VkSamplerCreateInfo sampler{VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO};
|
||||
sampler.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
|
||||
sampler.addressModeU = sampler.addressModeV = sampler.addressModeW =
|
||||
VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
||||
sampler.magFilter = sampler.minFilter = VK_FILTER_NEAREST;
|
||||
sampler.maxLod = 0.0f;
|
||||
VK_VERIFY(vkCreateSampler(m_device, &sampler, nullptr, &cache.nearest));
|
||||
}
|
||||
auto& cache = *m_wireDepthMipmapResources;
|
||||
|
||||
const VkImageLayout sourceLayout = sameImage ? VK_IMAGE_LAYOUT_GENERAL
|
||||
: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||
const VkImageLayout destinationLayout = sameImage ? VK_IMAGE_LAYOUT_GENERAL
|
||||
: VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||
WireDepthMipmapResources::Target* target = nullptr;
|
||||
for (auto& entry : cache.targets) {
|
||||
if (entry.format == destination.format && entry.layout == destinationLayout) {
|
||||
target = &entry;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!target) {
|
||||
cache.targets.emplace_back();
|
||||
target = &cache.targets.back();
|
||||
target->format = destination.format;
|
||||
target->layout = destinationLayout;
|
||||
VkAttachmentDescription attachment{};
|
||||
attachment.format = destination.format;
|
||||
attachment.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
// DONT_CARE, not LOAD: the pass writes gl_FragDepth at every texel of the level
|
||||
// it is producing, so there is nothing in the destination worth loading, and a
|
||||
// level that has just been grown has no defined contents to load anyway.
|
||||
attachment.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||
attachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
attachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||
attachment.initialLayout = attachment.finalLayout = destinationLayout;
|
||||
const VkAttachmentReference depth{0, destinationLayout};
|
||||
VkSubpassDescription subpass{};
|
||||
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
||||
subpass.pDepthStencilAttachment = &depth;
|
||||
VkRenderPassCreateInfo pass{VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO};
|
||||
pass.attachmentCount = 1;
|
||||
pass.pAttachments = &attachment;
|
||||
pass.subpassCount = 1;
|
||||
pass.pSubpasses = &subpass;
|
||||
VK_VERIFY(vkCreateRenderPass(m_device, &pass, nullptr, &target->renderPass));
|
||||
VkPipelineShaderStageCreateInfo stages[2]{};
|
||||
for (auto& stage : stages) {
|
||||
stage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||
stage.pName = "main";
|
||||
}
|
||||
stages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
|
||||
stages[0].module = cache.vertex;
|
||||
stages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
stages[1].module = cache.fragment;
|
||||
const VkPipelineVertexInputStateCreateInfo vertex{VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO};
|
||||
VkPipelineInputAssemblyStateCreateInfo assembly{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO};
|
||||
assembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
||||
VkPipelineViewportStateCreateInfo viewport{VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO};
|
||||
viewport.viewportCount = viewport.scissorCount = 1;
|
||||
VkPipelineRasterizationStateCreateInfo raster{VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO};
|
||||
raster.polygonMode = VK_POLYGON_MODE_FILL;
|
||||
raster.cullMode = VK_CULL_MODE_NONE;
|
||||
raster.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
|
||||
raster.lineWidth = 1.0f;
|
||||
VkPipelineMultisampleStateCreateInfo samples{VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO};
|
||||
samples.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
|
||||
// ALWAYS + write enabled: the fragment shader's gl_FragDepth is the answer, and a
|
||||
// comparison against whatever DONT_CARE left behind would discard some of it.
|
||||
VkPipelineDepthStencilStateCreateInfo depthStencil{VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO};
|
||||
depthStencil.depthTestEnable = VK_TRUE;
|
||||
depthStencil.depthWriteEnable = VK_TRUE;
|
||||
depthStencil.depthCompareOp = VK_COMPARE_OP_ALWAYS;
|
||||
depthStencil.minDepthBounds = 0.0f;
|
||||
depthStencil.maxDepthBounds = 1.0f;
|
||||
// No colour attachment in this render pass, so no attachment states either.
|
||||
VkPipelineColorBlendStateCreateInfo blend{VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO};
|
||||
const VkDynamicState dynamicStates[]{VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR};
|
||||
VkPipelineDynamicStateCreateInfo dynamic{VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO};
|
||||
dynamic.dynamicStateCount = 2;
|
||||
dynamic.pDynamicStates = dynamicStates;
|
||||
VkGraphicsPipelineCreateInfo pipeline{VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO};
|
||||
pipeline.stageCount = 2;
|
||||
pipeline.pStages = stages;
|
||||
pipeline.pVertexInputState = &vertex;
|
||||
pipeline.pInputAssemblyState = &assembly;
|
||||
pipeline.pViewportState = &viewport;
|
||||
pipeline.pRasterizationState = &raster;
|
||||
pipeline.pMultisampleState = &samples;
|
||||
pipeline.pDepthStencilState = &depthStencil;
|
||||
pipeline.pColorBlendState = &blend;
|
||||
pipeline.pDynamicState = &dynamic;
|
||||
pipeline.layout = cache.pipelineLayout;
|
||||
pipeline.renderPass = target->renderPass;
|
||||
VK_VERIFY(vkCreateGraphicsPipelines(m_device, VK_NULL_HANDLE, 1, &pipeline, nullptr, &target->pipeline));
|
||||
}
|
||||
|
||||
m_textureManager->FlushPendingUploads();
|
||||
// Distinct mip views of the same image are legal shader input and output at once.
|
||||
// GENERAL keeps the whole-image layout tracker truthful; the transition also orders
|
||||
// the previous level's attachment write against this level's sample of it.
|
||||
TransitionWireImage(source, sourceLayout);
|
||||
if (sameImage) destination.layout = source.layout;
|
||||
else TransitionWireImage(destination, destinationLayout);
|
||||
const auto makeView = [&](const WireImage& image) {
|
||||
VkImageViewCreateInfo view{VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO};
|
||||
view.image = image.image;
|
||||
view.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
||||
view.format = image.format;
|
||||
view.subresourceRange = {VK_IMAGE_ASPECT_DEPTH_BIT, image.level, 1, image.layer, 1};
|
||||
VkImageView handle = VK_NULL_HANDLE;
|
||||
VK_VERIFY(vkCreateImageView(m_device, &view, nullptr, &handle));
|
||||
return handle;
|
||||
};
|
||||
const VkImageView sourceView = makeView(source), destinationView = makeView(destination);
|
||||
VkFramebufferCreateInfo framebufferInfo{VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO};
|
||||
framebufferInfo.renderPass = target->renderPass;
|
||||
framebufferInfo.attachmentCount = 1;
|
||||
framebufferInfo.pAttachments = &destinationView;
|
||||
framebufferInfo.width = destination.extent.width;
|
||||
framebufferInfo.height = destination.extent.height;
|
||||
framebufferInfo.layers = 1;
|
||||
VkFramebuffer framebuffer = VK_NULL_HANDLE;
|
||||
VK_VERIFY(vkCreateFramebuffer(m_device, &framebufferInfo, nullptr, &framebuffer));
|
||||
// Each in-flight pass owns its descriptor set, for the colour blit's reason: updating
|
||||
// a cached set would rewrite the source view of an older queued pass.
|
||||
VkDescriptorPool descriptorPool = VK_NULL_HANDLE;
|
||||
VkDescriptorSet descriptorSet = VK_NULL_HANDLE;
|
||||
const VkDescriptorPoolSize poolSize{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1};
|
||||
VkDescriptorPoolCreateInfo pool{VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO};
|
||||
pool.maxSets = 1;
|
||||
pool.poolSizeCount = 1;
|
||||
pool.pPoolSizes = &poolSize;
|
||||
VK_VERIFY(vkCreateDescriptorPool(m_device, &pool, nullptr, &descriptorPool));
|
||||
VkDescriptorSetAllocateInfo alloc{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO};
|
||||
alloc.descriptorPool = descriptorPool;
|
||||
alloc.descriptorSetCount = 1;
|
||||
alloc.pSetLayouts = &cache.descriptorLayout;
|
||||
VK_VERIFY(vkAllocateDescriptorSets(m_device, &alloc, &descriptorSet));
|
||||
const VkDescriptorImageInfo sampled{cache.nearest, sourceView, sourceLayout};
|
||||
VkWriteDescriptorSet write{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET};
|
||||
write.dstSet = descriptorSet;
|
||||
write.dstBinding = 0;
|
||||
write.descriptorCount = 1;
|
||||
write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||
write.pImageInfo = &sampled;
|
||||
vkUpdateDescriptorSets(m_device, 1, &write, 0, nullptr);
|
||||
|
||||
// The destination rectangle is flipped exactly as BlitWireColorImage flips it for an
|
||||
// offscreen target, because it shares that file's vertex shader and therefore its
|
||||
// window-Y flip. With the flip undone, destination row r samples texCoord.y
|
||||
// (r + 0.5) / dstHeight, and the fragment's ivec2(texCoord * srcTexelSize) lands on
|
||||
// the same source texels the monolith arm's fullscreen triangle lands on - which is
|
||||
// the point: §3.2 retires a refusal by making the wire arm observably the monolith's,
|
||||
// half-texel offset included.
|
||||
const Constants constants{
|
||||
{0.0f, 0.0f, 1.0f, 1.0f},
|
||||
{0.0f, 1.0f, 1.0f, -1.0f},
|
||||
0, 0,
|
||||
{static_cast<Int32>(source.extent.width), static_cast<Int32>(source.extent.height)}};
|
||||
auto& frame = m_frameContext.GetCurrent();
|
||||
VkRenderPassBeginInfo begin{VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO};
|
||||
begin.renderPass = target->renderPass;
|
||||
begin.framebuffer = framebuffer;
|
||||
begin.renderArea = {{0, 0}, destination.extent};
|
||||
vkCmdBeginRenderPass(frame.commandBuffer, &begin, VK_SUBPASS_CONTENTS_INLINE);
|
||||
vkCmdBindPipeline(frame.commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, target->pipeline);
|
||||
const VkViewport viewport{0.0f, 0.0f, static_cast<float>(destination.extent.width),
|
||||
static_cast<float>(destination.extent.height), 0.0f, 1.0f};
|
||||
const VkRect2D scissor{{0, 0}, destination.extent};
|
||||
vkCmdSetViewport(frame.commandBuffer, 0, 1, &viewport);
|
||||
vkCmdSetScissor(frame.commandBuffer, 0, 1, &scissor);
|
||||
vkCmdBindDescriptorSets(frame.commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||
cache.pipelineLayout, 0, 1, &descriptorSet, 0, nullptr);
|
||||
vkCmdPushConstants(frame.commandBuffer, cache.pipelineLayout,
|
||||
VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
0, sizeof(constants), &constants);
|
||||
vkCmdDraw(frame.commandBuffer, 6, 1, 0, 0);
|
||||
vkCmdEndRenderPass(frame.commandBuffer);
|
||||
ResetDynamicStateShadow();
|
||||
InvalidatePipelineMemo();
|
||||
// This native pass binds its own set/layout without going through the application's
|
||||
// descriptor binder. Its next fast path must rebind.
|
||||
if (m_uniformManager) m_uniformManager->OnCommandBufferBoundary();
|
||||
WireRetiredObjects retired{};
|
||||
retired.framebuffers.push_back(framebuffer);
|
||||
retired.imageViews = {sourceView, destinationView};
|
||||
retired.descriptorPools.push_back(descriptorPool);
|
||||
RetireWireObjects(Move(retired));
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
@@ -1,33 +0,0 @@
|
||||
#version 450
|
||||
// Native Vulkan depth mip generation: no GL program, registry entry, or runtime transpilation.
|
||||
//
|
||||
// The geometry is WireColorBlit.vert's, unchanged - the same quad, the same push-constant
|
||||
// rect, the same GL-bottom-left to native-image mapping - so a depth mip and a colour blit
|
||||
// place their fragments identically and only the fragment stage differs. The block carries
|
||||
// one member more than the colour blit's, and the fragment stage is the member's only
|
||||
// reader: a push-constant block must be declared identically in every stage of one pipeline,
|
||||
// so it is declared here too rather than split into a second range.
|
||||
layout(push_constant) uniform DepthMipmapRect {
|
||||
vec4 srcRect;
|
||||
vec4 dstRect;
|
||||
int surfaceTransform;
|
||||
ivec2 srcTexelSize;
|
||||
} rect;
|
||||
layout(location = 0) out vec2 texCoord;
|
||||
|
||||
void main() {
|
||||
// A quad, rather than an oversized triangle, also clips partial blits to
|
||||
// their destination rectangle. The Vulkan viewport covers the native image.
|
||||
const vec2 corners[6] = vec2[](
|
||||
vec2(0.0, 0.0), vec2(1.0, 0.0), vec2(0.0, 1.0),
|
||||
vec2(0.0, 1.0), vec2(1.0, 0.0), vec2(1.0, 1.0));
|
||||
vec2 uv = corners[gl_VertexIndex];
|
||||
vec2 p = (rect.dstRect.xy + uv * rect.dstRect.zw) * 2.0 - 1.0;
|
||||
// Same GL-bottom-left to native-image mapping as the monolithic blit.
|
||||
p.y = -p.y;
|
||||
if (rect.surfaceTransform == 1) p = vec2(-p.y, p.x);
|
||||
else if (rect.surfaceTransform == 2) p = -p;
|
||||
else if (rect.surfaceTransform == 3) p = vec2(p.y, -p.x);
|
||||
gl_Position = vec4(p, 0.0, 1.0);
|
||||
texCoord = rect.srcRect.xy + uv * rect.srcRect.zw;
|
||||
}
|
||||
@@ -1,174 +0,0 @@
|
||||
// Generated from WireDepthMipmap.vert / WireDepthMipmap.frag by
|
||||
// scripts/bake_internal_shaders.py, which runs MG_Test's BakedInternalShadersTest with the
|
||||
// IN-TREE glslang and splices the words it emits into the arrays below. Do not edit the
|
||||
// words by hand: MOBILEGL_BAKED_INTERNAL_SHADERS (the same test, run as a gate) recompiles
|
||||
// every source in its table and reds on the first word that disagrees.
|
||||
#pragma once
|
||||
|
||||
static constexpr Uint32 kWireDepthMipmapVertexSpirv[] = {
|
||||
0x07230203u, 0x00010000u, 0x0008000bu, 0x00000071u, 0x00000000u, 0x00020011u, 0x00000001u, 0x0006000bu,
|
||||
0x00000001u, 0x4c534c47u, 0x6474732eu, 0x3035342eu, 0x00000000u, 0x0003000eu, 0x00000000u, 0x00000001u,
|
||||
0x0008000fu, 0x00000000u, 0x00000004u, 0x6e69616du, 0x00000000u, 0x00000016u, 0x0000005eu, 0x00000067u,
|
||||
0x00030003u, 0x00000002u, 0x000001c2u, 0x00040005u, 0x00000004u, 0x6e69616du, 0x00000000u, 0x00030005u,
|
||||
0x00000009u, 0x00007675u, 0x00060005u, 0x00000016u, 0x565f6c67u, 0x65747265u, 0x646e4978u, 0x00007865u,
|
||||
0x00050005u, 0x00000019u, 0x65646e69u, 0x6c626178u, 0x00000065u, 0x00030005u, 0x0000001cu, 0x00000070u,
|
||||
0x00060005u, 0x0000001fu, 0x74706544u, 0x70694d68u, 0x5270616du, 0x00746365u, 0x00050006u, 0x0000001fu,
|
||||
0x00000000u, 0x52637273u, 0x00746365u, 0x00050006u, 0x0000001fu, 0x00000001u, 0x52747364u, 0x00746365u,
|
||||
0x00080006u, 0x0000001fu, 0x00000002u, 0x66727573u, 0x54656361u, 0x736e6172u, 0x6d726f66u, 0x00000000u,
|
||||
0x00070006u, 0x0000001fu, 0x00000003u, 0x54637273u, 0x6c657865u, 0x657a6953u, 0x00000000u, 0x00040005u,
|
||||
0x00000021u, 0x74636572u, 0x00000000u, 0x00060005u, 0x0000005cu, 0x505f6c67u, 0x65567265u, 0x78657472u,
|
||||
0x00000000u, 0x00060006u, 0x0000005cu, 0x00000000u, 0x505f6c67u, 0x7469736fu, 0x006e6f69u, 0x00070006u,
|
||||
0x0000005cu, 0x00000001u, 0x505f6c67u, 0x746e696fu, 0x657a6953u, 0x00000000u, 0x00070006u, 0x0000005cu,
|
||||
0x00000002u, 0x435f6c67u, 0x4470696cu, 0x61747369u, 0x0065636eu, 0x00070006u, 0x0000005cu, 0x00000003u,
|
||||
0x435f6c67u, 0x446c6c75u, 0x61747369u, 0x0065636eu, 0x00030005u, 0x0000005eu, 0x00000000u, 0x00050005u,
|
||||
0x00000067u, 0x43786574u, 0x64726f6fu, 0x00000000u, 0x00040047u, 0x00000016u, 0x0000000bu, 0x0000002au,
|
||||
0x00030047u, 0x0000001fu, 0x00000002u, 0x00050048u, 0x0000001fu, 0x00000000u, 0x00000023u, 0x00000000u,
|
||||
0x00050048u, 0x0000001fu, 0x00000001u, 0x00000023u, 0x00000010u, 0x00050048u, 0x0000001fu, 0x00000002u,
|
||||
0x00000023u, 0x00000020u, 0x00050048u, 0x0000001fu, 0x00000003u, 0x00000023u, 0x00000028u, 0x00030047u,
|
||||
0x0000005cu, 0x00000002u, 0x00050048u, 0x0000005cu, 0x00000000u, 0x0000000bu, 0x00000000u, 0x00050048u,
|
||||
0x0000005cu, 0x00000001u, 0x0000000bu, 0x00000001u, 0x00050048u, 0x0000005cu, 0x00000002u, 0x0000000bu,
|
||||
0x00000003u, 0x00050048u, 0x0000005cu, 0x00000003u, 0x0000000bu, 0x00000004u, 0x00040047u, 0x00000067u,
|
||||
0x0000001eu, 0x00000000u, 0x00020013u, 0x00000002u, 0x00030021u, 0x00000003u, 0x00000002u, 0x00030016u,
|
||||
0x00000006u, 0x00000020u, 0x00040017u, 0x00000007u, 0x00000006u, 0x00000002u, 0x00040020u, 0x00000008u,
|
||||
0x00000007u, 0x00000007u, 0x00040015u, 0x0000000au, 0x00000020u, 0x00000000u, 0x0004002bu, 0x0000000au,
|
||||
0x0000000bu, 0x00000006u, 0x0004001cu, 0x0000000cu, 0x00000007u, 0x0000000bu, 0x0004002bu, 0x00000006u,
|
||||
0x0000000du, 0x00000000u, 0x0005002cu, 0x00000007u, 0x0000000eu, 0x0000000du, 0x0000000du, 0x0004002bu,
|
||||
0x00000006u, 0x0000000fu, 0x3f800000u, 0x0005002cu, 0x00000007u, 0x00000010u, 0x0000000fu, 0x0000000du,
|
||||
0x0005002cu, 0x00000007u, 0x00000011u, 0x0000000du, 0x0000000fu, 0x0005002cu, 0x00000007u, 0x00000012u,
|
||||
0x0000000fu, 0x0000000fu, 0x0009002cu, 0x0000000cu, 0x00000013u, 0x0000000eu, 0x00000010u, 0x00000011u,
|
||||
0x00000011u, 0x00000010u, 0x00000012u, 0x00040015u, 0x00000014u, 0x00000020u, 0x00000001u, 0x00040020u,
|
||||
0x00000015u, 0x00000001u, 0x00000014u, 0x0004003bu, 0x00000015u, 0x00000016u, 0x00000001u, 0x00040020u,
|
||||
0x00000018u, 0x00000007u, 0x0000000cu, 0x00040017u, 0x0000001du, 0x00000006u, 0x00000004u, 0x00040017u,
|
||||
0x0000001eu, 0x00000014u, 0x00000002u, 0x0006001eu, 0x0000001fu, 0x0000001du, 0x0000001du, 0x00000014u,
|
||||
0x0000001eu, 0x00040020u, 0x00000020u, 0x00000009u, 0x0000001fu, 0x0004003bu, 0x00000020u, 0x00000021u,
|
||||
0x00000009u, 0x0004002bu, 0x00000014u, 0x00000022u, 0x00000001u, 0x00040020u, 0x00000023u, 0x00000009u,
|
||||
0x0000001du, 0x0004002bu, 0x00000006u, 0x0000002du, 0x40000000u, 0x0004002bu, 0x0000000au, 0x00000031u,
|
||||
0x00000001u, 0x00040020u, 0x00000032u, 0x00000007u, 0x00000006u, 0x0004002bu, 0x00000014u, 0x00000037u,
|
||||
0x00000002u, 0x00040020u, 0x00000038u, 0x00000009u, 0x00000014u, 0x00020014u, 0x0000003bu, 0x0004002bu,
|
||||
0x0000000au, 0x00000042u, 0x00000000u, 0x0004002bu, 0x00000014u, 0x00000051u, 0x00000003u, 0x0004001cu,
|
||||
0x0000005bu, 0x00000006u, 0x00000031u, 0x0006001eu, 0x0000005cu, 0x0000001du, 0x00000006u, 0x0000005bu,
|
||||
0x0000005bu, 0x00040020u, 0x0000005du, 0x00000003u, 0x0000005cu, 0x0004003bu, 0x0000005du, 0x0000005eu,
|
||||
0x00000003u, 0x0004002bu, 0x00000014u, 0x0000005fu, 0x00000000u, 0x00040020u, 0x00000064u, 0x00000003u,
|
||||
0x0000001du, 0x00040020u, 0x00000066u, 0x00000003u, 0x00000007u, 0x0004003bu, 0x00000066u, 0x00000067u,
|
||||
0x00000003u, 0x00050036u, 0x00000002u, 0x00000004u, 0x00000000u, 0x00000003u, 0x000200f8u, 0x00000005u,
|
||||
0x0004003bu, 0x00000008u, 0x00000009u, 0x00000007u, 0x0004003bu, 0x00000018u, 0x00000019u, 0x00000007u,
|
||||
0x0004003bu, 0x00000008u, 0x0000001cu, 0x00000007u, 0x0004003du, 0x00000014u, 0x00000017u, 0x00000016u,
|
||||
0x0003003eu, 0x00000019u, 0x00000013u, 0x00050041u, 0x00000008u, 0x0000001au, 0x00000019u, 0x00000017u,
|
||||
0x0004003du, 0x00000007u, 0x0000001bu, 0x0000001au, 0x0003003eu, 0x00000009u, 0x0000001bu, 0x00050041u,
|
||||
0x00000023u, 0x00000024u, 0x00000021u, 0x00000022u, 0x0004003du, 0x0000001du, 0x00000025u, 0x00000024u,
|
||||
0x0007004fu, 0x00000007u, 0x00000026u, 0x00000025u, 0x00000025u, 0x00000000u, 0x00000001u, 0x0004003du,
|
||||
0x00000007u, 0x00000027u, 0x00000009u, 0x00050041u, 0x00000023u, 0x00000028u, 0x00000021u, 0x00000022u,
|
||||
0x0004003du, 0x0000001du, 0x00000029u, 0x00000028u, 0x0007004fu, 0x00000007u, 0x0000002au, 0x00000029u,
|
||||
0x00000029u, 0x00000002u, 0x00000003u, 0x00050085u, 0x00000007u, 0x0000002bu, 0x00000027u, 0x0000002au,
|
||||
0x00050081u, 0x00000007u, 0x0000002cu, 0x00000026u, 0x0000002bu, 0x0005008eu, 0x00000007u, 0x0000002eu,
|
||||
0x0000002cu, 0x0000002du, 0x00050050u, 0x00000007u, 0x0000002fu, 0x0000000fu, 0x0000000fu, 0x00050083u,
|
||||
0x00000007u, 0x00000030u, 0x0000002eu, 0x0000002fu, 0x0003003eu, 0x0000001cu, 0x00000030u, 0x00050041u,
|
||||
0x00000032u, 0x00000033u, 0x0000001cu, 0x00000031u, 0x0004003du, 0x00000006u, 0x00000034u, 0x00000033u,
|
||||
0x0004007fu, 0x00000006u, 0x00000035u, 0x00000034u, 0x00050041u, 0x00000032u, 0x00000036u, 0x0000001cu,
|
||||
0x00000031u, 0x0003003eu, 0x00000036u, 0x00000035u, 0x00050041u, 0x00000038u, 0x00000039u, 0x00000021u,
|
||||
0x00000037u, 0x0004003du, 0x00000014u, 0x0000003au, 0x00000039u, 0x000500aau, 0x0000003bu, 0x0000003cu,
|
||||
0x0000003au, 0x00000022u, 0x000300f7u, 0x0000003eu, 0x00000000u, 0x000400fau, 0x0000003cu, 0x0000003du,
|
||||
0x00000046u, 0x000200f8u, 0x0000003du, 0x00050041u, 0x00000032u, 0x0000003fu, 0x0000001cu, 0x00000031u,
|
||||
0x0004003du, 0x00000006u, 0x00000040u, 0x0000003fu, 0x0004007fu, 0x00000006u, 0x00000041u, 0x00000040u,
|
||||
0x00050041u, 0x00000032u, 0x00000043u, 0x0000001cu, 0x00000042u, 0x0004003du, 0x00000006u, 0x00000044u,
|
||||
0x00000043u, 0x00050050u, 0x00000007u, 0x00000045u, 0x00000041u, 0x00000044u, 0x0003003eu, 0x0000001cu,
|
||||
0x00000045u, 0x000200f9u, 0x0000003eu, 0x000200f8u, 0x00000046u, 0x00050041u, 0x00000038u, 0x00000047u,
|
||||
0x00000021u, 0x00000037u, 0x0004003du, 0x00000014u, 0x00000048u, 0x00000047u, 0x000500aau, 0x0000003bu,
|
||||
0x00000049u, 0x00000048u, 0x00000037u, 0x000300f7u, 0x0000004bu, 0x00000000u, 0x000400fau, 0x00000049u,
|
||||
0x0000004au, 0x0000004eu, 0x000200f8u, 0x0000004au, 0x0004003du, 0x00000007u, 0x0000004cu, 0x0000001cu,
|
||||
0x0004007fu, 0x00000007u, 0x0000004du, 0x0000004cu, 0x0003003eu, 0x0000001cu, 0x0000004du, 0x000200f9u,
|
||||
0x0000004bu, 0x000200f8u, 0x0000004eu, 0x00050041u, 0x00000038u, 0x0000004fu, 0x00000021u, 0x00000037u,
|
||||
0x0004003du, 0x00000014u, 0x00000050u, 0x0000004fu, 0x000500aau, 0x0000003bu, 0x00000052u, 0x00000050u,
|
||||
0x00000051u, 0x000300f7u, 0x00000054u, 0x00000000u, 0x000400fau, 0x00000052u, 0x00000053u, 0x00000054u,
|
||||
0x000200f8u, 0x00000053u, 0x00050041u, 0x00000032u, 0x00000055u, 0x0000001cu, 0x00000031u, 0x0004003du,
|
||||
0x00000006u, 0x00000056u, 0x00000055u, 0x00050041u, 0x00000032u, 0x00000057u, 0x0000001cu, 0x00000042u,
|
||||
0x0004003du, 0x00000006u, 0x00000058u, 0x00000057u, 0x0004007fu, 0x00000006u, 0x00000059u, 0x00000058u,
|
||||
0x00050050u, 0x00000007u, 0x0000005au, 0x00000056u, 0x00000059u, 0x0003003eu, 0x0000001cu, 0x0000005au,
|
||||
0x000200f9u, 0x00000054u, 0x000200f8u, 0x00000054u, 0x000200f9u, 0x0000004bu, 0x000200f8u, 0x0000004bu,
|
||||
0x000200f9u, 0x0000003eu, 0x000200f8u, 0x0000003eu, 0x0004003du, 0x00000007u, 0x00000060u, 0x0000001cu,
|
||||
0x00050051u, 0x00000006u, 0x00000061u, 0x00000060u, 0x00000000u, 0x00050051u, 0x00000006u, 0x00000062u,
|
||||
0x00000060u, 0x00000001u, 0x00070050u, 0x0000001du, 0x00000063u, 0x00000061u, 0x00000062u, 0x0000000du,
|
||||
0x0000000fu, 0x00050041u, 0x00000064u, 0x00000065u, 0x0000005eu, 0x0000005fu, 0x0003003eu, 0x00000065u,
|
||||
0x00000063u, 0x00050041u, 0x00000023u, 0x00000068u, 0x00000021u, 0x0000005fu, 0x0004003du, 0x0000001du,
|
||||
0x00000069u, 0x00000068u, 0x0007004fu, 0x00000007u, 0x0000006au, 0x00000069u, 0x00000069u, 0x00000000u,
|
||||
0x00000001u, 0x0004003du, 0x00000007u, 0x0000006bu, 0x00000009u, 0x00050041u, 0x00000023u, 0x0000006cu,
|
||||
0x00000021u, 0x0000005fu, 0x0004003du, 0x0000001du, 0x0000006du, 0x0000006cu, 0x0007004fu, 0x00000007u,
|
||||
0x0000006eu, 0x0000006du, 0x0000006du, 0x00000002u, 0x00000003u, 0x00050085u, 0x00000007u, 0x0000006fu,
|
||||
0x0000006bu, 0x0000006eu, 0x00050081u, 0x00000007u, 0x00000070u, 0x0000006au, 0x0000006fu, 0x0003003eu,
|
||||
0x00000067u, 0x00000070u, 0x000100fdu, 0x00010038u,
|
||||
};
|
||||
|
||||
static constexpr Uint32 kWireDepthMipmapFragmentSpirv[] = {
|
||||
0x07230203u, 0x00010000u, 0x0008000bu, 0x00000059u, 0x00000000u, 0x00020011u, 0x00000001u, 0x0006000bu,
|
||||
0x00000001u, 0x4c534c47u, 0x6474732eu, 0x3035342eu, 0x00000000u, 0x0003000eu, 0x00000000u, 0x00000001u,
|
||||
0x0007000fu, 0x00000004u, 0x00000004u, 0x6e69616du, 0x00000000u, 0x0000000du, 0x0000004fu, 0x00030010u,
|
||||
0x00000004u, 0x00000007u, 0x00030010u, 0x00000004u, 0x0000000cu, 0x00030003u, 0x00000002u, 0x000001c2u,
|
||||
0x00040005u, 0x00000004u, 0x6e69616du, 0x00000000u, 0x00040005u, 0x00000009u, 0x42637273u, 0x00657361u,
|
||||
0x00050005u, 0x0000000du, 0x43786574u, 0x64726f6fu, 0x00000000u, 0x00060005u, 0x00000010u, 0x74706544u,
|
||||
0x70694d68u, 0x5270616du, 0x00746365u, 0x00050006u, 0x00000010u, 0x00000000u, 0x52637273u, 0x00746365u,
|
||||
0x00050006u, 0x00000010u, 0x00000001u, 0x52747364u, 0x00746365u, 0x00080006u, 0x00000010u, 0x00000002u,
|
||||
0x66727573u, 0x54656361u, 0x736e6172u, 0x6d726f66u, 0x00000000u, 0x00070006u, 0x00000010u, 0x00000003u,
|
||||
0x54637273u, 0x6c657865u, 0x657a6953u, 0x00000000u, 0x00040005u, 0x00000012u, 0x74636572u, 0x00000000u,
|
||||
0x00040005u, 0x0000001au, 0x4d637273u, 0x00007861u, 0x00040005u, 0x00000021u, 0x74706564u, 0x00003068u,
|
||||
0x00050005u, 0x00000025u, 0x72756f73u, 0x6d496563u, 0x00656761u, 0x00040005u, 0x00000031u, 0x74706564u,
|
||||
0x00003168u, 0x00040005u, 0x0000003bu, 0x74706564u, 0x00003268u, 0x00040005u, 0x00000045u, 0x74706564u,
|
||||
0x00003368u, 0x00060005u, 0x0000004fu, 0x465f6c67u, 0x44676172u, 0x68747065u, 0x00000000u, 0x00040047u,
|
||||
0x0000000du, 0x0000001eu, 0x00000000u, 0x00030047u, 0x00000010u, 0x00000002u, 0x00050048u, 0x00000010u,
|
||||
0x00000000u, 0x00000023u, 0x00000000u, 0x00050048u, 0x00000010u, 0x00000001u, 0x00000023u, 0x00000010u,
|
||||
0x00050048u, 0x00000010u, 0x00000002u, 0x00000023u, 0x00000020u, 0x00050048u, 0x00000010u, 0x00000003u,
|
||||
0x00000023u, 0x00000028u, 0x00040047u, 0x00000025u, 0x00000021u, 0x00000000u, 0x00040047u, 0x00000025u,
|
||||
0x00000022u, 0x00000000u, 0x00040047u, 0x0000004fu, 0x0000000bu, 0x00000016u, 0x00020013u, 0x00000002u,
|
||||
0x00030021u, 0x00000003u, 0x00000002u, 0x00040015u, 0x00000006u, 0x00000020u, 0x00000001u, 0x00040017u,
|
||||
0x00000007u, 0x00000006u, 0x00000002u, 0x00040020u, 0x00000008u, 0x00000007u, 0x00000007u, 0x00030016u,
|
||||
0x0000000au, 0x00000020u, 0x00040017u, 0x0000000bu, 0x0000000au, 0x00000002u, 0x00040020u, 0x0000000cu,
|
||||
0x00000001u, 0x0000000bu, 0x0004003bu, 0x0000000cu, 0x0000000du, 0x00000001u, 0x00040017u, 0x0000000fu,
|
||||
0x0000000au, 0x00000004u, 0x0006001eu, 0x00000010u, 0x0000000fu, 0x0000000fu, 0x00000006u, 0x00000007u,
|
||||
0x00040020u, 0x00000011u, 0x00000009u, 0x00000010u, 0x0004003bu, 0x00000011u, 0x00000012u, 0x00000009u,
|
||||
0x0004002bu, 0x00000006u, 0x00000013u, 0x00000003u, 0x00040020u, 0x00000014u, 0x00000009u, 0x00000007u,
|
||||
0x0004002bu, 0x00000006u, 0x0000001du, 0x00000001u, 0x0005002cu, 0x00000007u, 0x0000001eu, 0x0000001du,
|
||||
0x0000001du, 0x00040020u, 0x00000020u, 0x00000007u, 0x0000000au, 0x00090019u, 0x00000022u, 0x0000000au,
|
||||
0x00000001u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000001u, 0x00000000u, 0x0003001bu, 0x00000023u,
|
||||
0x00000022u, 0x00040020u, 0x00000024u, 0x00000000u, 0x00000023u, 0x0004003bu, 0x00000024u, 0x00000025u,
|
||||
0x00000000u, 0x0004002bu, 0x00000006u, 0x00000028u, 0x00000000u, 0x0005002cu, 0x00000007u, 0x00000029u,
|
||||
0x00000028u, 0x00000028u, 0x00040015u, 0x0000002eu, 0x00000020u, 0x00000000u, 0x0004002bu, 0x0000002eu,
|
||||
0x0000002fu, 0x00000000u, 0x0005002cu, 0x00000007u, 0x00000034u, 0x0000001du, 0x00000028u, 0x0005002cu,
|
||||
0x00000007u, 0x0000003eu, 0x00000028u, 0x0000001du, 0x00040020u, 0x0000004eu, 0x00000003u, 0x0000000au,
|
||||
0x0004003bu, 0x0000004eu, 0x0000004fu, 0x00000003u, 0x0004002bu, 0x0000000au, 0x00000050u, 0x3e800000u,
|
||||
0x00050036u, 0x00000002u, 0x00000004u, 0x00000000u, 0x00000003u, 0x000200f8u, 0x00000005u, 0x0004003bu,
|
||||
0x00000008u, 0x00000009u, 0x00000007u, 0x0004003bu, 0x00000008u, 0x0000001au, 0x00000007u, 0x0004003bu,
|
||||
0x00000020u, 0x00000021u, 0x00000007u, 0x0004003bu, 0x00000020u, 0x00000031u, 0x00000007u, 0x0004003bu,
|
||||
0x00000020u, 0x0000003bu, 0x00000007u, 0x0004003bu, 0x00000020u, 0x00000045u, 0x00000007u, 0x0004003du,
|
||||
0x0000000bu, 0x0000000eu, 0x0000000du, 0x00050041u, 0x00000014u, 0x00000015u, 0x00000012u, 0x00000013u,
|
||||
0x0004003du, 0x00000007u, 0x00000016u, 0x00000015u, 0x0004006fu, 0x0000000bu, 0x00000017u, 0x00000016u,
|
||||
0x00050085u, 0x0000000bu, 0x00000018u, 0x0000000eu, 0x00000017u, 0x0004006eu, 0x00000007u, 0x00000019u,
|
||||
0x00000018u, 0x0003003eu, 0x00000009u, 0x00000019u, 0x00050041u, 0x00000014u, 0x0000001bu, 0x00000012u,
|
||||
0x00000013u, 0x0004003du, 0x00000007u, 0x0000001cu, 0x0000001bu, 0x00050082u, 0x00000007u, 0x0000001fu,
|
||||
0x0000001cu, 0x0000001eu, 0x0003003eu, 0x0000001au, 0x0000001fu, 0x0004003du, 0x00000023u, 0x00000026u,
|
||||
0x00000025u, 0x0004003du, 0x00000007u, 0x00000027u, 0x00000009u, 0x0004003du, 0x00000007u, 0x0000002au,
|
||||
0x0000001au, 0x0008000cu, 0x00000007u, 0x0000002bu, 0x00000001u, 0x0000002du, 0x00000027u, 0x00000029u,
|
||||
0x0000002au, 0x00040064u, 0x00000022u, 0x0000002cu, 0x00000026u, 0x0007005fu, 0x0000000fu, 0x0000002du,
|
||||
0x0000002cu, 0x0000002bu, 0x00000002u, 0x00000028u, 0x00050051u, 0x0000000au, 0x00000030u, 0x0000002du,
|
||||
0x00000000u, 0x0003003eu, 0x00000021u, 0x00000030u, 0x0004003du, 0x00000023u, 0x00000032u, 0x00000025u,
|
||||
0x0004003du, 0x00000007u, 0x00000033u, 0x00000009u, 0x00050080u, 0x00000007u, 0x00000035u, 0x00000033u,
|
||||
0x00000034u, 0x0004003du, 0x00000007u, 0x00000036u, 0x0000001au, 0x0008000cu, 0x00000007u, 0x00000037u,
|
||||
0x00000001u, 0x0000002du, 0x00000035u, 0x00000029u, 0x00000036u, 0x00040064u, 0x00000022u, 0x00000038u,
|
||||
0x00000032u, 0x0007005fu, 0x0000000fu, 0x00000039u, 0x00000038u, 0x00000037u, 0x00000002u, 0x00000028u,
|
||||
0x00050051u, 0x0000000au, 0x0000003au, 0x00000039u, 0x00000000u, 0x0003003eu, 0x00000031u, 0x0000003au,
|
||||
0x0004003du, 0x00000023u, 0x0000003cu, 0x00000025u, 0x0004003du, 0x00000007u, 0x0000003du, 0x00000009u,
|
||||
0x00050080u, 0x00000007u, 0x0000003fu, 0x0000003du, 0x0000003eu, 0x0004003du, 0x00000007u, 0x00000040u,
|
||||
0x0000001au, 0x0008000cu, 0x00000007u, 0x00000041u, 0x00000001u, 0x0000002du, 0x0000003fu, 0x00000029u,
|
||||
0x00000040u, 0x00040064u, 0x00000022u, 0x00000042u, 0x0000003cu, 0x0007005fu, 0x0000000fu, 0x00000043u,
|
||||
0x00000042u, 0x00000041u, 0x00000002u, 0x00000028u, 0x00050051u, 0x0000000au, 0x00000044u, 0x00000043u,
|
||||
0x00000000u, 0x0003003eu, 0x0000003bu, 0x00000044u, 0x0004003du, 0x00000023u, 0x00000046u, 0x00000025u,
|
||||
0x0004003du, 0x00000007u, 0x00000047u, 0x00000009u, 0x00050080u, 0x00000007u, 0x00000048u, 0x00000047u,
|
||||
0x0000001eu, 0x0004003du, 0x00000007u, 0x00000049u, 0x0000001au, 0x0008000cu, 0x00000007u, 0x0000004au,
|
||||
0x00000001u, 0x0000002du, 0x00000048u, 0x00000029u, 0x00000049u, 0x00040064u, 0x00000022u, 0x0000004bu,
|
||||
0x00000046u, 0x0007005fu, 0x0000000fu, 0x0000004cu, 0x0000004bu, 0x0000004au, 0x00000002u, 0x00000028u,
|
||||
0x00050051u, 0x0000000au, 0x0000004du, 0x0000004cu, 0x00000000u, 0x0003003eu, 0x00000045u, 0x0000004du,
|
||||
0x0004003du, 0x0000000au, 0x00000051u, 0x00000021u, 0x0004003du, 0x0000000au, 0x00000052u, 0x00000031u,
|
||||
0x00050081u, 0x0000000au, 0x00000053u, 0x00000051u, 0x00000052u, 0x0004003du, 0x0000000au, 0x00000054u,
|
||||
0x0000003bu, 0x00050081u, 0x0000000au, 0x00000055u, 0x00000053u, 0x00000054u, 0x0004003du, 0x0000000au,
|
||||
0x00000056u, 0x00000045u, 0x00050081u, 0x0000000au, 0x00000057u, 0x00000055u, 0x00000056u, 0x00050085u,
|
||||
0x0000000au, 0x00000058u, 0x00000050u, 0x00000057u, 0x0003003eu, 0x0000004fu, 0x00000058u, 0x000100fdu,
|
||||
0x00010038u,
|
||||
};
|
||||
@@ -1,329 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Backend/DirectVulkan/Renderer/WireDepthResolveArm.h
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
#pragma once
|
||||
|
||||
#include <Includes.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
#include <utility>
|
||||
|
||||
// P7 gate 5 (g5-msrbo, g5-msprobe): WHICH ARM RESOLVES A MULTISAMPLE DEPTH/STENCIL ASPECT FIRST.
|
||||
//
|
||||
// The wire arm has two (WireFramebuffer.inc, ResolveWireDepthStencil): a render pass that carries
|
||||
// a VK_KHR_depth_stencil_resolve attachment and no draw, and the baked shader pass of
|
||||
// WireMultisampleResolve.inc, which draws. P7 wave 2-B2 took the render pass wherever the
|
||||
// extension exists. On the Redmi (Adreno 830, Vulkan 1.3.284, driver 512.800.71) that pass left
|
||||
// its resolve target unwritten - KHR-GL46.direct_state_access.renderbuffers_storage_multisample
|
||||
// read every resolved depth and stencil value back as 0 on the inproc arm while the monolith arm
|
||||
// passed, and the same case passed on the device with the shader arm forced
|
||||
// (MGITEST_MAGMA_FORCE_SHADER_DEPTH_RESOLVE=1).
|
||||
//
|
||||
// A DRIVER THAT CLAIMS WHAT IT CANNOT DO IS A POST PROBE, NOT A VENDOR QUIRK (standing rule,
|
||||
// 2026-08-22). The first fix keyed the order on Qualcomm's vendor id; it is replaced by a probe
|
||||
// that reproduces the production resolve on the actual VkDevice (WireDepthResolveProbe.cpp) and
|
||||
// asks the one question the order depends on: does the no-draw render pass write the resolve
|
||||
// target? A driver that fixes the defect gets the fast arm back, and a driver of any vendor that
|
||||
// has it gets the shader arm - neither needs a table edit.
|
||||
//
|
||||
// EVERY BUG PROBE CARRIES A CONTROL (MG_Util/SelfTest/DriverBugProbes.h). The control is the
|
||||
// production SHADER arm fed the same inputs: when it does not resolve them either, the probe has
|
||||
// measured its own setup (or a device that cannot resolve depth at all) rather than the render
|
||||
// pass, the verdict is INCONCLUSIVE, and the default order stands.
|
||||
//
|
||||
// This header is the pure half - the measurement, the verdict, the test knob and the choice - so
|
||||
// a unit test pins every mapping with a fake result source (MG_Test/Pipeline/PipelineQuirkTest.cpp).
|
||||
// The Vulkan half that fills the measurement is WireDepthResolveProbe.{h,cpp}.
|
||||
namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// One aspect of one probed format, both arms. Values are the RAW aspect words the
|
||||
// buffer copy returns (D16: 16 bits; D24: the low 24 bits of the 32-bit word; D32F: the float's
|
||||
// bits; stencil: 8 bits), compared within `tolerance` (1 LSB for a UNORM depth, 0 otherwise).
|
||||
struct WireDepthResolveAspectReading {
|
||||
// The format has this aspect and the render-pass arm's copy of it was read back.
|
||||
Bool measured = false;
|
||||
Uint32 texels = 0;
|
||||
Uint32 expected = 0; // the multisample source's cleared value
|
||||
Uint32 sentinel = 0; // what the resolve target was pre-filled with
|
||||
Uint32 tolerance = 0;
|
||||
// THE SUBJECT: VK_KHR_depth_stencil_resolve render pass, no draw.
|
||||
Uint32 renderPassMatches = 0; // texels within tolerance of `expected`
|
||||
Uint32 renderPassSentinels = 0; // texels still holding the sentinel
|
||||
Uint32 renderPassFirst = 0; // texel (0,0)
|
||||
// THE CONTROL: the production shader pass, same inputs. False where it cannot run for this
|
||||
// aspect (a stencil aspect without VK_EXT_shader_stencil_export, a failed pipeline).
|
||||
Bool shaderRan = false;
|
||||
Uint32 shaderMatches = 0;
|
||||
Uint32 shaderFirst = 0;
|
||||
};
|
||||
|
||||
struct WireDepthResolveFormatReading {
|
||||
String name; // e.g. "D24_UNORM_S8_UINT"
|
||||
Int32 format = 0; // the VkFormat
|
||||
Uint32 samples = 0;
|
||||
// False when the format was not probed; `skipReason` says why (unsupported, the render-pass
|
||||
// arm would not be taken for it, an object the probe needed could not be created).
|
||||
Bool ran = false;
|
||||
String skipReason;
|
||||
WireDepthResolveAspectReading depth, stencil;
|
||||
};
|
||||
|
||||
struct WireDepthResolveProbeMeasurement {
|
||||
// At least one format was recorded, submitted and read back.
|
||||
Bool ran = false;
|
||||
// The bounded fence wait expired: every object the probe created was deliberately leaked
|
||||
// (the queue may still be executing it), and nothing was read back.
|
||||
Bool fenceWaitTimedOut = false;
|
||||
String failureReason;
|
||||
// Came from MGITEST_MAGMA_DEPTH_RESOLVE_PROBE=bug|clean, not from the device.
|
||||
Bool fromKnob = false;
|
||||
// Measured on the device, but with MGITEST_MAGMA_DEPTH_RESOLVE_PROBE=elide-subject: the probe
|
||||
// recorded no render-pass resolve at all, so the subject's target kept its sentinel.
|
||||
Bool subjectElided = false;
|
||||
Vector<WireDepthResolveFormatReading> formats;
|
||||
};
|
||||
|
||||
enum class WireDepthResolveProbeVerdict : Uint8 {
|
||||
// Nothing was measured: the render-pass arm is not available (nothing to choose between),
|
||||
// or the probe could not set itself up. The default order stands.
|
||||
NotRun,
|
||||
// Measured, but no format's CONTROL resolved: the probe cannot tell the render pass's
|
||||
// defect from its own. The default order stands, and the report must never call it a bug.
|
||||
Inconclusive,
|
||||
// Every format whose control resolved was resolved by the render pass too.
|
||||
Clean,
|
||||
// The defect: on at least one format the shader control resolved the inputs and the
|
||||
// render pass did not (wrote nothing - the sentinel survived - or wrote wrong values).
|
||||
RenderPassResolveBroken,
|
||||
};
|
||||
|
||||
inline const char* WireDepthResolveProbeVerdictName(WireDepthResolveProbeVerdict verdict) {
|
||||
switch (verdict) {
|
||||
case WireDepthResolveProbeVerdict::NotRun: return "not-run";
|
||||
case WireDepthResolveProbeVerdict::Inconclusive: return "inconclusive";
|
||||
case WireDepthResolveProbeVerdict::Clean: return "clean";
|
||||
case WireDepthResolveProbeVerdict::RenderPassResolveBroken: return "render-pass-resolve-broken";
|
||||
}
|
||||
return "?";
|
||||
}
|
||||
|
||||
inline Bool WireDepthResolveControlHolds(const WireDepthResolveAspectReading& aspect) {
|
||||
return aspect.measured && aspect.shaderRan && aspect.texels > 0 && aspect.shaderMatches == aspect.texels;
|
||||
}
|
||||
|
||||
inline Bool WireDepthResolveSubjectHolds(const WireDepthResolveAspectReading& aspect) {
|
||||
return aspect.texels > 0 && aspect.renderPassMatches == aspect.texels;
|
||||
}
|
||||
|
||||
// An aspect only counts where its control holds; a format is conclusive when any of its
|
||||
// aspects is. The render pass resolves every aspect of the format in one pass, so one aspect
|
||||
// it fails is the defect for the whole arm.
|
||||
inline WireDepthResolveProbeVerdict EvaluateWireDepthResolveProbe(const WireDepthResolveProbeMeasurement& measurement) {
|
||||
if (!measurement.ran || measurement.fenceWaitTimedOut) return WireDepthResolveProbeVerdict::NotRun;
|
||||
Bool conclusive = false, broken = false;
|
||||
for (const WireDepthResolveFormatReading& reading : measurement.formats) {
|
||||
if (!reading.ran) continue;
|
||||
for (const WireDepthResolveAspectReading* aspect : {&reading.depth, &reading.stencil}) {
|
||||
if (!WireDepthResolveControlHolds(*aspect)) continue;
|
||||
conclusive = true;
|
||||
if (!WireDepthResolveSubjectHolds(*aspect)) broken = true;
|
||||
}
|
||||
}
|
||||
if (broken) return WireDepthResolveProbeVerdict::RenderPassResolveBroken;
|
||||
return conclusive ? WireDepthResolveProbeVerdict::Clean : WireDepthResolveProbeVerdict::Inconclusive;
|
||||
}
|
||||
|
||||
// THE TEST KNOB, read by the SERVER (split and spawn arms only; the tcp server is a lane fixture
|
||||
// whose environment no entry reaches - spawn_lane_parity.py's MAGMA_SERVER_ENV_KNOB_NO_TCP).
|
||||
// Lavapipe resolves correctly through both arms, so no host lane can reach the verdict that
|
||||
// matters on the Redmi. MGITEST_MAGMA_DEPTH_RESOLVE_PROBE=bug|clean replaces the MEASUREMENT
|
||||
// with a canned one that says exactly that, and nothing else: the canned measurement still goes
|
||||
// through EvaluateWireDepthResolveProbe and the same member, so an entry that forces `bug` is red
|
||||
// when the evaluation stops detecting the defect.
|
||||
//
|
||||
// A canned measurement cannot see the REAL probe - its recording, readback and tally - stop
|
||||
// detecting the defect, and on lavapipe the real subject is clean, so nothing would. The third
|
||||
// value, MGITEST_MAGMA_DEPTH_RESOLVE_PROBE=elide-subject, is that negative control: the REAL
|
||||
// probe runs (ChooseWireDepthResolveArm treats it as Measure) and the caller passes it on as
|
||||
// WireDepthResolveProbeContext::elideSubject, so the probe records no render-pass resolve and
|
||||
// the real readback keeps the sentinel while the shader control still runs. The
|
||||
// DirectVulkan.{Split,Spawn}.MsResolveElide. entries then require the defect verdict from the
|
||||
// measurement itself.
|
||||
enum class WireDepthResolveProbeKnob : Uint8 { Measure, ForceBug, ForceClean, ElideSubject, Unrecognised };
|
||||
|
||||
inline WireDepthResolveProbeKnob ParseWireDepthResolveProbeKnob(const char* value) {
|
||||
if (value == nullptr || *value == '\0') return WireDepthResolveProbeKnob::Measure;
|
||||
if (std::strcmp(value, "bug") == 0) return WireDepthResolveProbeKnob::ForceBug;
|
||||
if (std::strcmp(value, "clean") == 0) return WireDepthResolveProbeKnob::ForceClean;
|
||||
if (std::strcmp(value, "elide-subject") == 0) return WireDepthResolveProbeKnob::ElideSubject;
|
||||
return WireDepthResolveProbeKnob::Unrecognised;
|
||||
}
|
||||
|
||||
// One packed format's worth of readings: the control resolved both aspects; the render pass
|
||||
// either did too (`renderPassWrites`) or left the sentinel everywhere.
|
||||
inline WireDepthResolveProbeMeasurement CannedWireDepthResolveProbeMeasurement(Bool renderPassWrites) {
|
||||
WireDepthResolveProbeMeasurement measurement;
|
||||
measurement.ran = true;
|
||||
measurement.fromKnob = true;
|
||||
WireDepthResolveFormatReading reading;
|
||||
reading.name = "MGITEST_MAGMA_DEPTH_RESOLVE_PROBE";
|
||||
reading.samples = 4;
|
||||
reading.ran = true;
|
||||
const auto fill = [&](WireDepthResolveAspectReading& aspect, Uint32 expected, Uint32 sentinel) {
|
||||
aspect.measured = true;
|
||||
aspect.texels = 16;
|
||||
aspect.expected = expected;
|
||||
aspect.sentinel = sentinel;
|
||||
aspect.renderPassMatches = renderPassWrites ? 16 : 0;
|
||||
aspect.renderPassSentinels = renderPassWrites ? 0 : 16;
|
||||
aspect.renderPassFirst = renderPassWrites ? expected : sentinel;
|
||||
aspect.shaderRan = true;
|
||||
aspect.shaderMatches = 16;
|
||||
aspect.shaderFirst = expected;
|
||||
};
|
||||
fill(reading.depth, 0x400000u, 0xBFFFFFu);
|
||||
fill(reading.stencil, 0x5Au, 0xA5u);
|
||||
measurement.formats.push_back(Move(reading));
|
||||
return measurement;
|
||||
}
|
||||
|
||||
struct WireDepthResolveArmChoice {
|
||||
WireDepthResolveProbeMeasurement measurement;
|
||||
WireDepthResolveProbeVerdict verdict = WireDepthResolveProbeVerdict::NotRun;
|
||||
// m_wirePreferShaderDepthResolve: the shader pass goes first, the render pass is the
|
||||
// fallback for what the shader cannot write.
|
||||
Bool preferShader = false;
|
||||
};
|
||||
|
||||
// The whole decision, with the Vulkan half behind `measure` (called at most once, and only when
|
||||
// the knob does not decide and the render-pass arm exists at all: without it the shader pass
|
||||
// is the only arm and there is no order to choose). ElideSubject does not decide: it is
|
||||
// measured like Measure, and the elision is the measuring callable's to apply.
|
||||
template <typename MeasureFn>
|
||||
WireDepthResolveArmChoice ChooseWireDepthResolveArm(WireDepthResolveProbeKnob knob, Bool renderPassArmAvailable,
|
||||
MeasureFn&& measure) {
|
||||
WireDepthResolveArmChoice choice;
|
||||
if (knob == WireDepthResolveProbeKnob::ForceBug || knob == WireDepthResolveProbeKnob::ForceClean) {
|
||||
choice.measurement = CannedWireDepthResolveProbeMeasurement(knob == WireDepthResolveProbeKnob::ForceClean);
|
||||
} else if (renderPassArmAvailable) {
|
||||
choice.measurement = measure();
|
||||
}
|
||||
choice.verdict = EvaluateWireDepthResolveProbe(choice.measurement);
|
||||
choice.preferShader = choice.verdict == WireDepthResolveProbeVerdict::RenderPassResolveBroken;
|
||||
return choice;
|
||||
}
|
||||
|
||||
// WHOSE VERDICT IT IS (codex closeout finding 7). The verdict is a property of ONE device and
|
||||
// driver, and a process can hold more than one: inproc tears a renderer down and initializes
|
||||
// another, possibly on a different physical device or under a different driver. The choice was
|
||||
// a function-static - the first renderer's answer for every renderer after it - so a second
|
||||
// device skipped its own probe and took an order measured elsewhere. It is now memoized per
|
||||
// IDENTITY: the device (vendor, device, driver version, pipeline-cache UUID - the last changes
|
||||
// with the driver build even where the version number does not) plus the two inputs the choice
|
||||
// itself depends on (whether a render-pass arm exists to judge, and the test knob). The same
|
||||
// identity is still probed once per process; a different one is probed for itself.
|
||||
struct WireDepthResolveDeviceIdentity {
|
||||
Uint32 vendorID = 0;
|
||||
Uint32 deviceID = 0;
|
||||
Uint32 driverVersion = 0;
|
||||
Uint8 pipelineCacheUUID[16] = {};
|
||||
Bool renderPassArmAvailable = false;
|
||||
WireDepthResolveProbeKnob knob = WireDepthResolveProbeKnob::Measure;
|
||||
|
||||
Bool operator==(const WireDepthResolveDeviceIdentity& other) const {
|
||||
return vendorID == other.vendorID && deviceID == other.deviceID && driverVersion == other.driverVersion &&
|
||||
std::memcmp(pipelineCacheUUID, other.pipelineCacheUUID, sizeof(pipelineCacheUUID)) == 0 &&
|
||||
renderPassArmAvailable == other.renderPassArmAvailable && knob == other.knob;
|
||||
}
|
||||
};
|
||||
|
||||
// The renderer's identity from its device's VkPhysicalDeviceProperties - the ONE place the fields
|
||||
// are filled (VulkanRenderer::ArmWireDepthResolveOrder calls it), so the unit test proves that each
|
||||
// property reaches the key: with only the cache tested, a field left out here stayed green.
|
||||
inline WireDepthResolveDeviceIdentity MakeWireDepthResolveDeviceIdentity(const VkPhysicalDeviceProperties& properties,
|
||||
Bool renderPassArmAvailable,
|
||||
WireDepthResolveProbeKnob knob) {
|
||||
WireDepthResolveDeviceIdentity identity;
|
||||
identity.vendorID = properties.vendorID;
|
||||
identity.deviceID = properties.deviceID;
|
||||
identity.driverVersion = properties.driverVersion;
|
||||
static_assert(sizeof(identity.pipelineCacheUUID) == sizeof(properties.pipelineCacheUUID));
|
||||
std::memcpy(identity.pipelineCacheUUID, properties.pipelineCacheUUID, sizeof(identity.pipelineCacheUUID));
|
||||
identity.renderPassArmAvailable = renderPassArmAvailable;
|
||||
identity.knob = knob;
|
||||
return identity;
|
||||
}
|
||||
|
||||
class WireDepthResolveArmCache {
|
||||
public:
|
||||
// The identity's memoized choice, or `decide()`'s - called at most once per identity, under
|
||||
// the cache's lock (a probe records on the device's queue; two renderers of one identity
|
||||
// must not both run it). `decided`, when given, says whether this call ran `decide`.
|
||||
template <typename DecideFn>
|
||||
WireDepthResolveArmChoice Resolve(const WireDepthResolveDeviceIdentity& identity, DecideFn&& decide,
|
||||
Bool* decided = nullptr) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
for (const auto& entry : m_entries) {
|
||||
if (entry.first == identity) {
|
||||
if (decided) *decided = false;
|
||||
return entry.second;
|
||||
}
|
||||
}
|
||||
WireDepthResolveArmChoice choice = decide();
|
||||
m_entries.emplace_back(identity, choice);
|
||||
if (decided) *decided = true;
|
||||
return choice;
|
||||
}
|
||||
|
||||
SizeT Size() const {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
return m_entries.size();
|
||||
}
|
||||
|
||||
private:
|
||||
mutable std::mutex m_mutex;
|
||||
Vector<std::pair<WireDepthResolveDeviceIdentity, WireDepthResolveArmChoice>> m_entries;
|
||||
};
|
||||
|
||||
// One format's readings, both arms: "D24_UNORM_S8_UINT x4: depth expected 0x400000 sentinel
|
||||
// 0xbfffff: render pass 0/16 (first 0xbfffff, sentinel 16), shader control 16/16 (first
|
||||
// 0x400000) / stencil ...".
|
||||
inline String DescribeWireDepthResolveFormat(const WireDepthResolveFormatReading& reading) {
|
||||
const auto aspectText = [](const char* name, const WireDepthResolveAspectReading& aspect) {
|
||||
String text = format("{} expected 0x{:x} sentinel 0x{:x}: render pass {}/{} (first 0x{:x}, sentinel {}), ",
|
||||
name, aspect.expected, aspect.sentinel, aspect.renderPassMatches, aspect.texels,
|
||||
aspect.renderPassFirst, aspect.renderPassSentinels);
|
||||
if (aspect.shaderRan) {
|
||||
text += format("shader control {}/{} (first 0x{:x})", aspect.shaderMatches, aspect.texels,
|
||||
aspect.shaderFirst);
|
||||
} else {
|
||||
text += "no shader control";
|
||||
}
|
||||
return text;
|
||||
};
|
||||
String out = reading.name;
|
||||
if (!reading.ran) return out + " skipped (" + reading.skipReason + ")";
|
||||
out += format(" x{}: ", reading.samples);
|
||||
if (reading.depth.measured) out += aspectText("depth", reading.depth);
|
||||
if (reading.depth.measured && reading.stencil.measured) out += " / ";
|
||||
if (reading.stencil.measured) out += aspectText("stencil", reading.stencil);
|
||||
return out;
|
||||
}
|
||||
|
||||
// Every format, "; "-separated, for the POST row.
|
||||
inline String DescribeWireDepthResolveProbe(const WireDepthResolveProbeMeasurement& measurement) {
|
||||
if (!measurement.ran) {
|
||||
return measurement.failureReason.empty() ? String("not run") : "not run (" + measurement.failureReason + ")";
|
||||
}
|
||||
String out;
|
||||
for (const WireDepthResolveFormatReading& reading : measurement.formats) {
|
||||
if (!out.empty()) out += "; ";
|
||||
out += DescribeWireDepthResolveFormat(reading);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
} // namespace MobileGL::MG_Backend::DirectVulkan
|
||||
@@ -1,992 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Backend/DirectVulkan/Renderer/WireDepthResolveProbe.cpp
|
||||
// Copyright (c) 2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
//
|
||||
// See WireDepthResolveProbe.h for the arms and the probe's shape, WireDepthResolveArm.h for the
|
||||
// verdict. The plumbing is the PRIMITIVES_GENERATED probe's (MG_Util/SelfTest/
|
||||
// PrimitivesGeneratedNoXfbProbe.cpp): one throwaway command buffer, a bounded fence wait that
|
||||
// leaks rather than idle-waits a hung GPU, teardown on every other path.
|
||||
|
||||
#include "WireDepthResolveProbe.h"
|
||||
|
||||
#include <MG_Util/Debug/Log.h>
|
||||
|
||||
#include <bit>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
#include "WireMultisampleResolveSpirv.h"
|
||||
|
||||
VkImageAspectFlags WireDepthStencilFormatAspects(VkFormat format) {
|
||||
if (format == VK_FORMAT_S8_UINT) return VK_IMAGE_ASPECT_STENCIL_BIT;
|
||||
if (format == VK_FORMAT_D16_UNORM_S8_UINT || format == VK_FORMAT_D24_UNORM_S8_UINT ||
|
||||
format == VK_FORMAT_D32_SFLOAT_S8_UINT)
|
||||
return VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
|
||||
return VK_IMAGE_ASPECT_DEPTH_BIT;
|
||||
}
|
||||
|
||||
VkImageViewCreateInfo WireDepthStencilViewInfo(VkImage image, VkFormat format, VkImageAspectFlags aspects,
|
||||
Uint32 level, Uint32 layer) {
|
||||
VkImageViewCreateInfo info{VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO};
|
||||
info.image = image;
|
||||
info.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
||||
info.format = format;
|
||||
info.subresourceRange = {aspects, level, 1, layer, 1};
|
||||
return info;
|
||||
}
|
||||
|
||||
VkResult CreateWireDepthStencilResolvePass(PFN_vkCreateRenderPass2 createRenderPass2, VkDevice device,
|
||||
VkFormat format, VkSampleCountFlagBits samples, VkRenderPass* pass) {
|
||||
const VkImageAspectFlags formatAspects = WireDepthStencilFormatAspects(format);
|
||||
VkAttachmentDescription2 attachments[2]{};
|
||||
for (Uint32 i = 0; i < 2; ++i) {
|
||||
auto& attachment = attachments[i];
|
||||
attachment.sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2;
|
||||
attachment.format = format;
|
||||
attachment.samples = i == 0 ? samples : VK_SAMPLE_COUNT_1_BIT;
|
||||
attachment.loadOp = attachment.stencilLoadOp =
|
||||
i == 0 ? VK_ATTACHMENT_LOAD_OP_LOAD : VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
attachment.storeOp = attachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||
attachment.initialLayout = attachment.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||
}
|
||||
VkAttachmentReference2 sourceReference{VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2};
|
||||
sourceReference.attachment = 0;
|
||||
sourceReference.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||
sourceReference.aspectMask = formatAspects;
|
||||
VkAttachmentReference2 resolveReference = sourceReference;
|
||||
resolveReference.attachment = 1;
|
||||
VkSubpassDescriptionDepthStencilResolve resolve{VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE};
|
||||
resolve.depthResolveMode =
|
||||
(formatAspects & VK_IMAGE_ASPECT_DEPTH_BIT) ? VK_RESOLVE_MODE_SAMPLE_ZERO_BIT : VK_RESOLVE_MODE_NONE;
|
||||
resolve.stencilResolveMode =
|
||||
(formatAspects & VK_IMAGE_ASPECT_STENCIL_BIT) ? VK_RESOLVE_MODE_SAMPLE_ZERO_BIT : VK_RESOLVE_MODE_NONE;
|
||||
resolve.pDepthStencilResolveAttachment = &resolveReference;
|
||||
VkSubpassDescription2 subpass{VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2};
|
||||
subpass.pNext = &resolve;
|
||||
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
||||
subpass.pDepthStencilAttachment = &sourceReference;
|
||||
VkRenderPassCreateInfo2 passInfo{VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2};
|
||||
passInfo.attachmentCount = 2;
|
||||
passInfo.pAttachments = attachments;
|
||||
passInfo.subpassCount = 1;
|
||||
passInfo.pSubpasses = &subpass;
|
||||
return createRenderPass2(device, &passInfo, nullptr, pass);
|
||||
}
|
||||
|
||||
VkResult CreateWireShaderResolveKit(VkDevice device, Bool shaderStencilExport, WireShaderResolveKit& kit) {
|
||||
const auto shader = [&](const Uint32* code, SizeT bytes, VkShaderModule& module) {
|
||||
VkShaderModuleCreateInfo info{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO};
|
||||
info.codeSize = bytes;
|
||||
info.pCode = code;
|
||||
return vkCreateShaderModule(device, &info, nullptr, &module);
|
||||
};
|
||||
VkResult result =
|
||||
shader(kWireMultisampleResolveVertexSpirv, sizeof(kWireMultisampleResolveVertexSpirv), kit.vertex);
|
||||
if (result != VK_SUCCESS) return result;
|
||||
result = shader(kWireMultisampleDepthResolveFragmentSpirv, sizeof(kWireMultisampleDepthResolveFragmentSpirv),
|
||||
kit.depthFragment);
|
||||
if (result != VK_SUCCESS) return result;
|
||||
// THE STENCIL MODULE IS ONLY CREATED WHERE IT CAN RUN: its SPIR-V declares the
|
||||
// StencilExportEXT capability, and handing a module with an unsupported capability to
|
||||
// vkCreateShaderModule is undefined behaviour - not an error this could catch.
|
||||
if (shaderStencilExport) {
|
||||
result = shader(kWireMultisampleStencilResolveFragmentSpirv,
|
||||
sizeof(kWireMultisampleStencilResolveFragmentSpirv), kit.stencilFragment);
|
||||
if (result != VK_SUCCESS) return result;
|
||||
}
|
||||
const VkDescriptorSetLayoutBinding binding{0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1,
|
||||
VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
|
||||
VkDescriptorSetLayoutCreateInfo layout{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO};
|
||||
layout.bindingCount = 1;
|
||||
layout.pBindings = &binding;
|
||||
result = vkCreateDescriptorSetLayout(device, &layout, nullptr, &kit.descriptorLayout);
|
||||
if (result != VK_SUCCESS) return result;
|
||||
// NO PUSH CONSTANT RANGE AT ALL: the pass reads its coordinate from gl_FragCoord and its
|
||||
// rectangle from the scissor, so neither stage takes an input.
|
||||
VkPipelineLayoutCreateInfo pipelineLayout{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO};
|
||||
pipelineLayout.setLayoutCount = 1;
|
||||
pipelineLayout.pSetLayouts = &kit.descriptorLayout;
|
||||
result = vkCreatePipelineLayout(device, &pipelineLayout, nullptr, &kit.pipelineLayout);
|
||||
if (result != VK_SUCCESS) return result;
|
||||
// NEAREST: texelFetch ignores the sampler's filter, and most devices do not advertise
|
||||
// linear filtering for a depth format anyway. The sampler exists only because GLSL's
|
||||
// sampler2DMS is a COMBINED image sampler.
|
||||
VkSamplerCreateInfo sampler{VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO};
|
||||
sampler.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
|
||||
sampler.addressModeU = sampler.addressModeV = sampler.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
||||
sampler.magFilter = sampler.minFilter = VK_FILTER_NEAREST;
|
||||
sampler.maxLod = 0.0f;
|
||||
return vkCreateSampler(device, &sampler, nullptr, &kit.nearest);
|
||||
}
|
||||
|
||||
void DestroyWireShaderResolveKit(VkDevice device, WireShaderResolveKit& kit) {
|
||||
vkDestroySampler(device, kit.nearest, nullptr);
|
||||
vkDestroyPipelineLayout(device, kit.pipelineLayout, nullptr);
|
||||
vkDestroyDescriptorSetLayout(device, kit.descriptorLayout, nullptr);
|
||||
vkDestroyShaderModule(device, kit.vertex, nullptr);
|
||||
vkDestroyShaderModule(device, kit.depthFragment, nullptr);
|
||||
vkDestroyShaderModule(device, kit.stencilFragment, nullptr);
|
||||
kit = {};
|
||||
}
|
||||
|
||||
VkResult CreateWireShaderResolveRenderPass(VkDevice device, VkFormat format, VkRenderPass* pass) {
|
||||
VkAttachmentDescription attachment{};
|
||||
attachment.format = format;
|
||||
attachment.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
// DONT_CARE on BOTH aspects: the pass writes every texel of the scissored rect for the
|
||||
// aspect it owns, and the caller copies only that aspect out. The other aspect of a packed
|
||||
// format is left undefined on purpose - it is never read, and LOADing it would order this
|
||||
// pass behind a write nobody is waiting for.
|
||||
attachment.loadOp = attachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
attachment.storeOp = attachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||
attachment.initialLayout = attachment.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||
const VkAttachmentReference depthStencil{0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
|
||||
VkSubpassDescription subpass{};
|
||||
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
||||
subpass.pDepthStencilAttachment = &depthStencil;
|
||||
VkRenderPassCreateInfo info{VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO};
|
||||
info.attachmentCount = 1;
|
||||
info.pAttachments = &attachment;
|
||||
info.subpassCount = 1;
|
||||
info.pSubpasses = &subpass;
|
||||
return vkCreateRenderPass(device, &info, nullptr, pass);
|
||||
}
|
||||
|
||||
VkResult CreateWireShaderResolvePipeline(VkDevice device, const WireShaderResolveKit& kit, VkRenderPass pass,
|
||||
VkImageAspectFlags aspect, VkPipeline* pipeline) {
|
||||
const VkShaderModule fragment =
|
||||
aspect == VK_IMAGE_ASPECT_STENCIL_BIT ? kit.stencilFragment : kit.depthFragment;
|
||||
if (fragment == VK_NULL_HANDLE || kit.vertex == VK_NULL_HANDLE) return VK_ERROR_FEATURE_NOT_PRESENT;
|
||||
VkPipelineShaderStageCreateInfo stages[2]{};
|
||||
for (auto& stage : stages) {
|
||||
stage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||
stage.pName = "main";
|
||||
}
|
||||
stages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
|
||||
stages[0].module = kit.vertex;
|
||||
stages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
stages[1].module = fragment;
|
||||
const VkPipelineVertexInputStateCreateInfo vertex{VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO};
|
||||
VkPipelineInputAssemblyStateCreateInfo assembly{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO};
|
||||
assembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
||||
VkPipelineViewportStateCreateInfo viewport{VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO};
|
||||
viewport.viewportCount = viewport.scissorCount = 1;
|
||||
VkPipelineRasterizationStateCreateInfo raster{VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO};
|
||||
raster.polygonMode = VK_POLYGON_MODE_FILL;
|
||||
raster.cullMode = VK_CULL_MODE_NONE;
|
||||
raster.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
|
||||
raster.lineWidth = 1.0f;
|
||||
VkPipelineMultisampleStateCreateInfo samples{VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO};
|
||||
samples.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
|
||||
VkPipelineDepthStencilStateCreateInfo depthStencilState{VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO};
|
||||
depthStencilState.minDepthBounds = 0.0f;
|
||||
depthStencilState.maxDepthBounds = 1.0f;
|
||||
if (aspect == VK_IMAGE_ASPECT_DEPTH_BIT) {
|
||||
// ALWAYS + write: gl_FragDepth is the answer, and a comparison against whatever
|
||||
// DONT_CARE left behind would discard some of it.
|
||||
depthStencilState.depthTestEnable = VK_TRUE;
|
||||
depthStencilState.depthWriteEnable = VK_TRUE;
|
||||
depthStencilState.depthCompareOp = VK_COMPARE_OP_ALWAYS;
|
||||
} else {
|
||||
// REPLACE on every outcome, compare ALWAYS, full write mask: that is what makes the
|
||||
// shader-exported reference the value that lands. The static `reference` is overridden
|
||||
// by gl_FragStencilRefARB, which is the whole point of the extension.
|
||||
depthStencilState.stencilTestEnable = VK_TRUE;
|
||||
VkStencilOpState op{};
|
||||
op.failOp = op.passOp = op.depthFailOp = VK_STENCIL_OP_REPLACE;
|
||||
op.compareOp = VK_COMPARE_OP_ALWAYS;
|
||||
op.compareMask = op.writeMask = 0xFFu;
|
||||
op.reference = 0;
|
||||
depthStencilState.front = depthStencilState.back = op;
|
||||
}
|
||||
// No colour attachment in this render pass, so no attachment states either.
|
||||
VkPipelineColorBlendStateCreateInfo blend{VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO};
|
||||
const VkDynamicState dynamicStates[]{VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR};
|
||||
VkPipelineDynamicStateCreateInfo dynamic{VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO};
|
||||
dynamic.dynamicStateCount = 2;
|
||||
dynamic.pDynamicStates = dynamicStates;
|
||||
VkGraphicsPipelineCreateInfo info{VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO};
|
||||
info.stageCount = 2;
|
||||
info.pStages = stages;
|
||||
info.pVertexInputState = &vertex;
|
||||
info.pInputAssemblyState = &assembly;
|
||||
info.pViewportState = &viewport;
|
||||
info.pRasterizationState = &raster;
|
||||
info.pMultisampleState = &samples;
|
||||
info.pDepthStencilState = &depthStencilState;
|
||||
info.pColorBlendState = &blend;
|
||||
info.pDynamicState = &dynamic;
|
||||
info.layout = kit.pipelineLayout;
|
||||
info.renderPass = pass;
|
||||
return vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &info, nullptr, pipeline);
|
||||
}
|
||||
|
||||
void RecordWireShaderResolveDraw(VkCommandBuffer commandBuffer, const WireShaderResolveKit& kit,
|
||||
VkRenderPass pass, VkPipeline pipeline, VkFramebuffer framebuffer,
|
||||
VkDescriptorSet descriptorSet, VkExtent2D attachmentExtent, VkRect2D rect) {
|
||||
VkRenderPassBeginInfo begin{VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO};
|
||||
begin.renderPass = pass;
|
||||
begin.framebuffer = framebuffer;
|
||||
// The RECTANGLE is the render area, exactly as the render-pass arm's renderArea is - the
|
||||
// scratch outside it is never read.
|
||||
begin.renderArea = rect;
|
||||
vkCmdBeginRenderPass(commandBuffer, &begin, VK_SUBPASS_CONTENTS_INLINE);
|
||||
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
|
||||
// THE VIEWPORT IS THE WHOLE ATTACHMENT AND THE SCISSOR IS THE RECT, and the two are not
|
||||
// interchangeable here: gl_FragCoord is what the fragment shader fetches by, so the
|
||||
// clip-space-to-attachment mapping has to be the identity for every rectangle. A viewport
|
||||
// shrunk onto the rect would slide the whole image instead of moving a window over it.
|
||||
const VkViewport viewport{0.0f, 0.0f, static_cast<float>(attachmentExtent.width),
|
||||
static_cast<float>(attachmentExtent.height), 0.0f, 1.0f};
|
||||
vkCmdSetViewport(commandBuffer, 0, 1, &viewport);
|
||||
vkCmdSetScissor(commandBuffer, 0, 1, &rect);
|
||||
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, kit.pipelineLayout, 0, 1,
|
||||
&descriptorSet, 0, nullptr);
|
||||
vkCmdDraw(commandBuffer, 3, 1, 0, 0);
|
||||
vkCmdEndRenderPass(commandBuffer);
|
||||
}
|
||||
|
||||
namespace {
|
||||
constexpr Uint32 kProbeExtent = 4;
|
||||
constexpr Uint32 kProbeTexels = kProbeExtent * kProbeExtent;
|
||||
// Every Vulkan device must support 4 samples on a depth/stencil attachment
|
||||
// (framebufferDepthSampleCounts), and the CTS case the probe stands for fails at 2 and 4.
|
||||
constexpr VkSampleCountFlagBits kProbeSamples = VK_SAMPLE_COUNT_4_BIT;
|
||||
constexpr Float kClearDepth = 0.25f;
|
||||
constexpr Float kSentinelDepth = 0.75f;
|
||||
constexpr Uint32 kClearStencil = 0x5Au;
|
||||
constexpr Uint32 kSentinelStencil = 0xA5u;
|
||||
constexpr Uint64 kFenceTimeoutNs = 5ull * 1000ull * 1000ull * 1000ull;
|
||||
|
||||
// The formats the wire maps GL's depth/stencil internal formats onto (VkTextureManager),
|
||||
// packed first: the case that set all this off failed on every one of them.
|
||||
struct ProbeFormat {
|
||||
VkFormat format;
|
||||
const char* name;
|
||||
};
|
||||
constexpr ProbeFormat kProbeFormats[] = {
|
||||
{VK_FORMAT_D24_UNORM_S8_UINT, "D24_UNORM_S8_UINT"},
|
||||
{VK_FORMAT_D32_SFLOAT_S8_UINT, "D32_SFLOAT_S8_UINT"},
|
||||
{VK_FORMAT_D16_UNORM, "D16_UNORM"},
|
||||
{VK_FORMAT_X8_D24_UNORM_PACK32, "X8_D24_UNORM_PACK32"},
|
||||
{VK_FORMAT_D32_SFLOAT, "D32_SFLOAT"},
|
||||
{VK_FORMAT_S8_UINT, "S8_UINT"},
|
||||
};
|
||||
|
||||
// The usages production gives the two images: a wire multisample depth/stencil attachment
|
||||
// (VkTextureManager: SAMPLED | DEPTH_STENCIL_ATTACHMENT | TRANSFER_SRC | TRANSFER_DST) and
|
||||
// ResolveWireDepthStencil's resolve scratch (DEPTH_STENCIL_ATTACHMENT | TRANSFER_SRC).
|
||||
constexpr VkImageUsageFlags kSourceUsage = VK_IMAGE_USAGE_SAMPLED_BIT |
|
||||
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
|
||||
VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||
constexpr VkImageUsageFlags kScratchUsage =
|
||||
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
|
||||
|
||||
Bool IsFloatDepth(VkFormat format) {
|
||||
return format == VK_FORMAT_D32_SFLOAT || format == VK_FORMAT_D32_SFLOAT_S8_UINT;
|
||||
}
|
||||
|
||||
Uint32 DepthCopyBytes(VkFormat format) { return format == VK_FORMAT_D16_UNORM ? 2u : 4u; }
|
||||
|
||||
Uint32 EncodeDepth(VkFormat format, Float depth) {
|
||||
if (IsFloatDepth(format)) return std::bit_cast<Uint32>(depth);
|
||||
const double scale = format == VK_FORMAT_D16_UNORM ? 65535.0 : 16777215.0;
|
||||
return static_cast<Uint32>(std::lround(static_cast<double>(depth) * scale));
|
||||
}
|
||||
|
||||
Uint32 ReadDepthWord(VkFormat format, const Uint8* texel) {
|
||||
if (format == VK_FORMAT_D16_UNORM) {
|
||||
Uint16 word = 0;
|
||||
std::memcpy(&word, texel, sizeof(word));
|
||||
return word;
|
||||
}
|
||||
Uint32 word = 0;
|
||||
std::memcpy(&word, texel, sizeof(word));
|
||||
// A D24 aspect copies out as a 32-bit word whose top byte is undefined.
|
||||
return IsFloatDepth(format) ? word : (word & 0x00FFFFFFu);
|
||||
}
|
||||
|
||||
Uint32 WordDistance(Uint32 a, Uint32 b) { return a > b ? a - b : b - a; }
|
||||
|
||||
struct ProbeImage {
|
||||
VkImage image = VK_NULL_HANDLE;
|
||||
VkDeviceMemory memory = VK_NULL_HANDLE;
|
||||
};
|
||||
|
||||
struct ControlPass {
|
||||
Bool ready = false;
|
||||
ProbeImage target;
|
||||
VkRenderPass pass = VK_NULL_HANDLE;
|
||||
VkPipeline pipeline = VK_NULL_HANDLE;
|
||||
VkImageView sampledView = VK_NULL_HANDLE;
|
||||
VkImageView targetView = VK_NULL_HANDLE;
|
||||
VkFramebuffer framebuffer = VK_NULL_HANDLE;
|
||||
VkDescriptorSet set = VK_NULL_HANDLE;
|
||||
VkDeviceSize offset = 0;
|
||||
};
|
||||
|
||||
struct FormatWork {
|
||||
SizeT reading = 0;
|
||||
VkFormat format = VK_FORMAT_UNDEFINED;
|
||||
VkImageAspectFlags aspects = 0;
|
||||
ProbeImage subjectSource, controlSource, subjectTarget;
|
||||
VkRenderPass resolvePass = VK_NULL_HANDLE;
|
||||
VkImageView resolveViews[2]{};
|
||||
VkFramebuffer resolveFramebuffer = VK_NULL_HANDLE;
|
||||
VkDeviceSize subjectDepthOffset = 0, subjectStencilOffset = 0;
|
||||
ControlPass depthControl, stencilControl;
|
||||
};
|
||||
|
||||
// Everything the probe creates, destroyed together (or leaked together on a timeout).
|
||||
struct ProbeObjects {
|
||||
VkDevice device = VK_NULL_HANDLE;
|
||||
Vector<VkImage> images;
|
||||
Vector<VkDeviceMemory> memories;
|
||||
Vector<VkImageView> views;
|
||||
Vector<VkRenderPass> passes;
|
||||
Vector<VkFramebuffer> framebuffers;
|
||||
Vector<VkPipeline> pipelines;
|
||||
VkBuffer buffer = VK_NULL_HANDLE;
|
||||
VkDescriptorPool descriptorPool = VK_NULL_HANDLE;
|
||||
VkCommandPool commandPool = VK_NULL_HANDLE;
|
||||
VkFence fence = VK_NULL_HANDLE;
|
||||
WireShaderResolveKit kit;
|
||||
|
||||
void Destroy() {
|
||||
for (VkPipeline pipeline : pipelines) vkDestroyPipeline(device, pipeline, nullptr);
|
||||
for (VkFramebuffer framebuffer : framebuffers) vkDestroyFramebuffer(device, framebuffer, nullptr);
|
||||
for (VkRenderPass pass : passes) vkDestroyRenderPass(device, pass, nullptr);
|
||||
for (VkImageView view : views) vkDestroyImageView(device, view, nullptr);
|
||||
for (VkImage image : images) vkDestroyImage(device, image, nullptr);
|
||||
vkDestroyBuffer(device, buffer, nullptr);
|
||||
for (VkDeviceMemory memory : memories) vkFreeMemory(device, memory, nullptr);
|
||||
vkDestroyDescriptorPool(device, descriptorPool, nullptr);
|
||||
vkDestroyCommandPool(device, commandPool, nullptr);
|
||||
vkDestroyFence(device, fence, nullptr);
|
||||
DestroyWireShaderResolveKit(device, kit);
|
||||
}
|
||||
};
|
||||
|
||||
Optional<Uint32> PickMemoryType(const VkPhysicalDeviceMemoryProperties& properties, Uint32 allowed,
|
||||
VkMemoryPropertyFlags wanted, VkMemoryPropertyFlags required) {
|
||||
Optional<Uint32> fallback;
|
||||
for (Uint32 i = 0; i < properties.memoryTypeCount; ++i) {
|
||||
if (!(allowed & (1u << i))) continue;
|
||||
const VkMemoryPropertyFlags flags = properties.memoryTypes[i].propertyFlags;
|
||||
if (flags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) continue;
|
||||
if ((flags & required) != required) continue;
|
||||
if ((flags & wanted) == wanted) return i;
|
||||
if (!fallback) fallback = i;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
void ImageBarrier(VkCommandBuffer commandBuffer, VkImage image, VkImageAspectFlags aspects,
|
||||
VkImageLayout oldLayout, VkImageLayout newLayout, VkPipelineStageFlags srcStage,
|
||||
VkAccessFlags srcAccess, VkPipelineStageFlags dstStage, VkAccessFlags dstAccess) {
|
||||
VkImageMemoryBarrier barrier{VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER};
|
||||
barrier.srcAccessMask = srcAccess;
|
||||
barrier.dstAccessMask = dstAccess;
|
||||
barrier.oldLayout = oldLayout;
|
||||
barrier.newLayout = newLayout;
|
||||
barrier.srcQueueFamilyIndex = barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
barrier.image = image;
|
||||
barrier.subresourceRange = {aspects, 0, 1, 0, VK_REMAINING_ARRAY_LAYERS};
|
||||
vkCmdPipelineBarrier(commandBuffer, srcStage, dstStage, 0, 0, nullptr, 0, nullptr, 1, &barrier);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
WireDepthResolveProbeMeasurement RunWireDepthResolveProbe(const WireDepthResolveProbeContext& context) {
|
||||
WireDepthResolveProbeMeasurement measurement;
|
||||
measurement.subjectElided = context.elideSubject;
|
||||
const VkDevice device = context.device;
|
||||
if (device == VK_NULL_HANDLE || context.queue == VK_NULL_HANDLE || context.createRenderPass2 == nullptr) {
|
||||
measurement.failureReason = "no device, queue or vkCreateRenderPass2";
|
||||
return measurement;
|
||||
}
|
||||
ProbeObjects objects;
|
||||
objects.device = device;
|
||||
Bool leak = false;
|
||||
struct Teardown {
|
||||
ProbeObjects& objects;
|
||||
Bool& leak;
|
||||
~Teardown() {
|
||||
if (!leak) objects.Destroy();
|
||||
}
|
||||
} teardown{objects, leak};
|
||||
const auto fail = [&](String reason) {
|
||||
measurement.ran = false;
|
||||
measurement.failureReason = Move(reason);
|
||||
return measurement;
|
||||
};
|
||||
|
||||
VkPhysicalDeviceMemoryProperties memoryProperties{};
|
||||
vkGetPhysicalDeviceMemoryProperties(context.physicalDevice, &memoryProperties);
|
||||
const auto makeImage = [&](VkFormat format, VkSampleCountFlagBits samples, VkImageUsageFlags usage,
|
||||
ProbeImage& out) -> Bool {
|
||||
VkImageCreateInfo info{VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO};
|
||||
info.imageType = VK_IMAGE_TYPE_2D;
|
||||
info.format = format;
|
||||
info.extent = {kProbeExtent, kProbeExtent, 1};
|
||||
info.mipLevels = info.arrayLayers = 1;
|
||||
info.samples = samples;
|
||||
info.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||
info.usage = usage;
|
||||
info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
if (vkCreateImage(device, &info, nullptr, &out.image) != VK_SUCCESS) return false;
|
||||
objects.images.push_back(out.image);
|
||||
VkMemoryRequirements requirements{};
|
||||
vkGetImageMemoryRequirements(device, out.image, &requirements);
|
||||
const Optional<Uint32> type = PickMemoryType(memoryProperties, requirements.memoryTypeBits,
|
||||
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, 0);
|
||||
if (!type) return false;
|
||||
VkMemoryAllocateInfo allocate{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO};
|
||||
allocate.allocationSize = requirements.size;
|
||||
allocate.memoryTypeIndex = *type;
|
||||
if (vkAllocateMemory(device, &allocate, nullptr, &out.memory) != VK_SUCCESS) return false;
|
||||
objects.memories.push_back(out.memory);
|
||||
return vkBindImageMemory(device, out.image, out.memory, 0) == VK_SUCCESS;
|
||||
};
|
||||
const auto makeView = [&](const VkImageViewCreateInfo& info, VkImageView& out) -> Bool {
|
||||
if (vkCreateImageView(device, &info, nullptr, &out) != VK_SUCCESS) return false;
|
||||
objects.views.push_back(out);
|
||||
return true;
|
||||
};
|
||||
const auto makeFramebuffer = [&](VkRenderPass pass, const VkImageView* views, Uint32 count,
|
||||
VkFramebuffer& out) -> Bool {
|
||||
VkFramebufferCreateInfo info{VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO};
|
||||
info.renderPass = pass;
|
||||
info.attachmentCount = count;
|
||||
info.pAttachments = views;
|
||||
info.width = info.height = kProbeExtent;
|
||||
info.layers = 1;
|
||||
if (vkCreateFramebuffer(device, &info, nullptr, &out) != VK_SUCCESS) return false;
|
||||
objects.framebuffers.push_back(out);
|
||||
return true;
|
||||
};
|
||||
// The wire's clear (WireFramebuffer.inc, ClearWireFramebuffer): a LOAD/STORE pass over every
|
||||
// aspect of the format with vkCmdClearAttachments inside it. Recorded later; built now.
|
||||
struct ClearPass {
|
||||
VkRenderPass pass = VK_NULL_HANDLE;
|
||||
VkFramebuffer framebuffer = VK_NULL_HANDLE;
|
||||
VkImageAspectFlags aspects = 0;
|
||||
Float depth = 0.0f;
|
||||
Uint32 stencil = 0;
|
||||
};
|
||||
Vector<ClearPass> clears;
|
||||
const auto makeClear = [&](const ProbeImage& image, VkFormat format, VkSampleCountFlagBits samples,
|
||||
Float depth, Uint32 stencil) -> Bool {
|
||||
const VkImageAspectFlags aspects = WireDepthStencilFormatAspects(format);
|
||||
VkImageView view = VK_NULL_HANDLE;
|
||||
if (!makeView(WireDepthStencilViewInfo(image.image, format, aspects, 0, 0), view)) return false;
|
||||
VkAttachmentDescription attachment{};
|
||||
attachment.format = format;
|
||||
attachment.samples = samples;
|
||||
attachment.loadOp = attachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
|
||||
attachment.storeOp = attachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||
attachment.initialLayout = attachment.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||
const VkAttachmentReference reference{0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
|
||||
VkSubpassDescription subpass{};
|
||||
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
||||
subpass.pDepthStencilAttachment = &reference;
|
||||
VkRenderPassCreateInfo info{VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO};
|
||||
info.attachmentCount = 1;
|
||||
info.pAttachments = &attachment;
|
||||
info.subpassCount = 1;
|
||||
info.pSubpasses = &subpass;
|
||||
ClearPass clear;
|
||||
if (vkCreateRenderPass(device, &info, nullptr, &clear.pass) != VK_SUCCESS) return false;
|
||||
objects.passes.push_back(clear.pass);
|
||||
if (!makeFramebuffer(clear.pass, &view, 1, clear.framebuffer)) return false;
|
||||
clear.aspects = aspects;
|
||||
clear.depth = depth;
|
||||
clear.stencil = stencil;
|
||||
clears.push_back(clear);
|
||||
return true;
|
||||
};
|
||||
|
||||
// THE CONTROL'S FORMAT-INDEPENDENT HALF. A kit that cannot be made leaves every control
|
||||
// un-run, which the verdict reads as INCONCLUSIVE - never as the bug.
|
||||
String kitFailure;
|
||||
if (const VkResult result = CreateWireShaderResolveKit(device, context.shaderStencilExport, objects.kit);
|
||||
result != VK_SUCCESS)
|
||||
kitFailure = format("shader resolve kit creation failed (VkResult {})", static_cast<Int>(result));
|
||||
|
||||
// Readback layout: every region on a 16-byte boundary (a depth/stencil buffer copy wants a
|
||||
// multiple of 4).
|
||||
VkDeviceSize bufferBytes = 0;
|
||||
const auto reserve = [&](VkDeviceSize bytes) {
|
||||
const VkDeviceSize offset = bufferBytes;
|
||||
bufferBytes += (bytes + 15u) & ~VkDeviceSize{15u};
|
||||
return offset;
|
||||
};
|
||||
|
||||
Vector<FormatWork> work;
|
||||
for (const ProbeFormat& probeFormat : kProbeFormats) {
|
||||
WireDepthResolveFormatReading reading;
|
||||
reading.name = probeFormat.name;
|
||||
reading.format = static_cast<Int32>(probeFormat.format);
|
||||
reading.samples = static_cast<Uint32>(kProbeSamples);
|
||||
const SizeT readingIndex = measurement.formats.size();
|
||||
measurement.formats.push_back(reading);
|
||||
auto& slot = measurement.formats.back();
|
||||
// A skipped format records nothing: the clears it had already built are dropped with it
|
||||
// (their images stay in `objects` and are only destroyed).
|
||||
const SizeT clearsBefore = clears.size();
|
||||
const auto skip = [&](String reason) {
|
||||
slot.skipReason = Move(reason);
|
||||
clears.resize(clearsBefore);
|
||||
};
|
||||
|
||||
const VkFormat format = probeFormat.format;
|
||||
const VkImageAspectFlags aspects = WireDepthStencilFormatAspects(format);
|
||||
VkFormatProperties formatProperties{};
|
||||
vkGetPhysicalDeviceFormatProperties(context.physicalDevice, format, &formatProperties);
|
||||
constexpr VkFormatFeatureFlags kRequired =
|
||||
VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT;
|
||||
if ((formatProperties.optimalTilingFeatures & kRequired) != kRequired) {
|
||||
skip("not a sampled depth/stencil attachment format here");
|
||||
continue;
|
||||
}
|
||||
VkImageFormatProperties imageProperties{};
|
||||
if (vkGetPhysicalDeviceImageFormatProperties(context.physicalDevice, format, VK_IMAGE_TYPE_2D,
|
||||
VK_IMAGE_TILING_OPTIMAL, kSourceUsage, 0,
|
||||
&imageProperties) != VK_SUCCESS ||
|
||||
!(imageProperties.sampleCounts & kProbeSamples)) {
|
||||
skip("no 4x multisample image with the wire's attachment usage");
|
||||
continue;
|
||||
}
|
||||
if (vkGetPhysicalDeviceImageFormatProperties(context.physicalDevice, format, VK_IMAGE_TYPE_2D,
|
||||
VK_IMAGE_TILING_OPTIMAL, kScratchUsage, 0,
|
||||
&imageProperties) != VK_SUCCESS) {
|
||||
skip("no single-sample image with the resolve scratch's usage");
|
||||
continue;
|
||||
}
|
||||
// ResolveWireDepthStencil's own test for the render-pass arm, per format.
|
||||
if (((aspects & VK_IMAGE_ASPECT_DEPTH_BIT) &&
|
||||
!(context.depthResolveModes & VK_RESOLVE_MODE_SAMPLE_ZERO_BIT)) ||
|
||||
((aspects & VK_IMAGE_ASPECT_STENCIL_BIT) &&
|
||||
!(context.stencilResolveModes & VK_RESOLVE_MODE_SAMPLE_ZERO_BIT))) {
|
||||
skip("the render-pass arm is not taken for this format (no SAMPLE_ZERO resolve mode)");
|
||||
continue;
|
||||
}
|
||||
|
||||
FormatWork item;
|
||||
item.reading = readingIndex;
|
||||
item.format = format;
|
||||
item.aspects = aspects;
|
||||
if (!makeImage(format, kProbeSamples, kSourceUsage, item.subjectSource) ||
|
||||
!makeImage(format, kProbeSamples, kSourceUsage, item.controlSource) ||
|
||||
!makeImage(format, VK_SAMPLE_COUNT_1_BIT, kScratchUsage, item.subjectTarget)) {
|
||||
skip("image creation failed");
|
||||
continue;
|
||||
}
|
||||
if (CreateWireDepthStencilResolvePass(context.createRenderPass2, device, format, kProbeSamples,
|
||||
&item.resolvePass) != VK_SUCCESS) {
|
||||
skip("the render-pass arm's vkCreateRenderPass2 failed");
|
||||
continue;
|
||||
}
|
||||
objects.passes.push_back(item.resolvePass);
|
||||
if (!makeView(WireDepthStencilViewInfo(item.subjectSource.image, format, aspects, 0, 0),
|
||||
item.resolveViews[0]) ||
|
||||
!makeView(WireDepthStencilViewInfo(item.subjectTarget.image, format, aspects, 0, 0),
|
||||
item.resolveViews[1]) ||
|
||||
!makeFramebuffer(item.resolvePass, item.resolveViews, 2, item.resolveFramebuffer)) {
|
||||
skip("the render-pass arm's views or framebuffer could not be created");
|
||||
continue;
|
||||
}
|
||||
if (!makeClear(item.subjectSource, format, kProbeSamples, kClearDepth, kClearStencil) ||
|
||||
!makeClear(item.controlSource, format, kProbeSamples, kClearDepth, kClearStencil) ||
|
||||
!makeClear(item.subjectTarget, format, VK_SAMPLE_COUNT_1_BIT, kSentinelDepth, kSentinelStencil)) {
|
||||
skip("the clear passes could not be created");
|
||||
continue;
|
||||
}
|
||||
// The control, one target per aspect: the shader pass's attachment is DONT_CARE on both
|
||||
// aspects, so a second aspect's pass into the same target would discard the first.
|
||||
const auto makeControl = [&](VkImageAspectFlags aspect, ControlPass& control) {
|
||||
if (!kitFailure.empty()) return;
|
||||
if (aspect == VK_IMAGE_ASPECT_STENCIL_BIT && objects.kit.stencilFragment == VK_NULL_HANDLE) return;
|
||||
if (!makeImage(format, VK_SAMPLE_COUNT_1_BIT, kScratchUsage, control.target)) return;
|
||||
if (CreateWireShaderResolveRenderPass(device, format, &control.pass) != VK_SUCCESS) return;
|
||||
objects.passes.push_back(control.pass);
|
||||
if (CreateWireShaderResolvePipeline(device, objects.kit, control.pass, aspect, &control.pipeline) !=
|
||||
VK_SUCCESS)
|
||||
return;
|
||||
objects.pipelines.push_back(control.pipeline);
|
||||
if (!makeView(WireDepthStencilViewInfo(item.controlSource.image, format, aspect, 0, 0),
|
||||
control.sampledView) ||
|
||||
!makeView(WireDepthStencilViewInfo(control.target.image, format, aspects, 0, 0),
|
||||
control.targetView) ||
|
||||
!makeFramebuffer(control.pass, &control.targetView, 1, control.framebuffer))
|
||||
return;
|
||||
if (!makeClear(control.target, format, VK_SAMPLE_COUNT_1_BIT, kSentinelDepth, kSentinelStencil))
|
||||
return;
|
||||
control.ready = true;
|
||||
};
|
||||
if (aspects & VK_IMAGE_ASPECT_DEPTH_BIT) makeControl(VK_IMAGE_ASPECT_DEPTH_BIT, item.depthControl);
|
||||
if (aspects & VK_IMAGE_ASPECT_STENCIL_BIT) makeControl(VK_IMAGE_ASPECT_STENCIL_BIT, item.stencilControl);
|
||||
|
||||
if (aspects & VK_IMAGE_ASPECT_DEPTH_BIT) {
|
||||
item.subjectDepthOffset = reserve(kProbeTexels * DepthCopyBytes(format));
|
||||
if (item.depthControl.ready) item.depthControl.offset = reserve(kProbeTexels * DepthCopyBytes(format));
|
||||
}
|
||||
if (aspects & VK_IMAGE_ASPECT_STENCIL_BIT) {
|
||||
item.subjectStencilOffset = reserve(kProbeTexels);
|
||||
if (item.stencilControl.ready) item.stencilControl.offset = reserve(kProbeTexels);
|
||||
}
|
||||
slot.ran = true;
|
||||
work.push_back(item);
|
||||
}
|
||||
if (work.empty()) return fail("no format could be probed");
|
||||
|
||||
// Descriptor sets for the controls, one per draw (the production shader arm's own rule).
|
||||
Uint32 controlDraws = 0;
|
||||
for (const FormatWork& item : work)
|
||||
controlDraws += (item.depthControl.ready ? 1u : 0u) + (item.stencilControl.ready ? 1u : 0u);
|
||||
if (controlDraws > 0) {
|
||||
const VkDescriptorPoolSize poolSize{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, controlDraws};
|
||||
VkDescriptorPoolCreateInfo pool{VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO};
|
||||
pool.maxSets = controlDraws;
|
||||
pool.poolSizeCount = 1;
|
||||
pool.pPoolSizes = &poolSize;
|
||||
if (vkCreateDescriptorPool(device, &pool, nullptr, &objects.descriptorPool) != VK_SUCCESS)
|
||||
return fail("vkCreateDescriptorPool failed");
|
||||
for (FormatWork& item : work) {
|
||||
for (ControlPass* control : {&item.depthControl, &item.stencilControl}) {
|
||||
if (!control->ready) continue;
|
||||
VkDescriptorSetAllocateInfo alloc{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO};
|
||||
alloc.descriptorPool = objects.descriptorPool;
|
||||
alloc.descriptorSetCount = 1;
|
||||
alloc.pSetLayouts = &objects.kit.descriptorLayout;
|
||||
if (vkAllocateDescriptorSets(device, &alloc, &control->set) != VK_SUCCESS)
|
||||
return fail("vkAllocateDescriptorSets failed");
|
||||
const VkDescriptorImageInfo sampled{objects.kit.nearest, control->sampledView,
|
||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL};
|
||||
VkWriteDescriptorSet write{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET};
|
||||
write.dstSet = control->set;
|
||||
write.dstBinding = 0;
|
||||
write.descriptorCount = 1;
|
||||
write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||
write.pImageInfo = &sampled;
|
||||
vkUpdateDescriptorSets(device, 1, &write, 0, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The host-visible readback buffer.
|
||||
VkDeviceMemory bufferMemory = VK_NULL_HANDLE;
|
||||
Bool bufferCoherent = false;
|
||||
{
|
||||
VkBufferCreateInfo info{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO};
|
||||
info.size = bufferBytes;
|
||||
info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
|
||||
info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
if (vkCreateBuffer(device, &info, nullptr, &objects.buffer) != VK_SUCCESS)
|
||||
return fail("vkCreateBuffer failed");
|
||||
VkMemoryRequirements requirements{};
|
||||
vkGetBufferMemoryRequirements(device, objects.buffer, &requirements);
|
||||
const Optional<Uint32> type =
|
||||
PickMemoryType(memoryProperties, requirements.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
|
||||
if (!type) return fail("no host-visible memory type for the readback buffer");
|
||||
bufferCoherent = (memoryProperties.memoryTypes[*type].propertyFlags &
|
||||
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) != 0;
|
||||
VkMemoryAllocateInfo allocate{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO};
|
||||
allocate.allocationSize = requirements.size;
|
||||
allocate.memoryTypeIndex = *type;
|
||||
if (vkAllocateMemory(device, &allocate, nullptr, &bufferMemory) != VK_SUCCESS)
|
||||
return fail("vkAllocateMemory (readback) failed");
|
||||
objects.memories.push_back(bufferMemory);
|
||||
if (vkBindBufferMemory(device, objects.buffer, bufferMemory, 0) != VK_SUCCESS)
|
||||
return fail("vkBindBufferMemory failed");
|
||||
}
|
||||
|
||||
VkCommandPoolCreateInfo poolInfo{VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO};
|
||||
poolInfo.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT;
|
||||
poolInfo.queueFamilyIndex = context.queueFamilyIndex;
|
||||
if (vkCreateCommandPool(device, &poolInfo, nullptr, &objects.commandPool) != VK_SUCCESS)
|
||||
return fail("vkCreateCommandPool failed");
|
||||
VkCommandBufferAllocateInfo commandInfo{VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO};
|
||||
commandInfo.commandPool = objects.commandPool;
|
||||
commandInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||
commandInfo.commandBufferCount = 1;
|
||||
VkCommandBuffer cmd = VK_NULL_HANDLE;
|
||||
if (vkAllocateCommandBuffers(device, &commandInfo, &cmd) != VK_SUCCESS)
|
||||
return fail("vkAllocateCommandBuffers failed");
|
||||
VkCommandBufferBeginInfo beginInfo{VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO};
|
||||
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
|
||||
if (vkBeginCommandBuffer(cmd, &beginInfo) != VK_SUCCESS) return fail("vkBeginCommandBuffer failed");
|
||||
|
||||
const VkRect2D fullRect{{0, 0}, {kProbeExtent, kProbeExtent}};
|
||||
// (1) Every image UNDEFINED -> DEPTH_STENCIL_ATTACHMENT_OPTIMAL, the way TransitionWireImage
|
||||
// moves a fresh image (source state from UNDEFINED, destination ALL_COMMANDS).
|
||||
for (const FormatWork& item : work) {
|
||||
const VkImage images[] = {item.subjectSource.image, item.controlSource.image, item.subjectTarget.image,
|
||||
item.depthControl.ready ? item.depthControl.target.image : VK_NULL_HANDLE,
|
||||
item.stencilControl.ready ? item.stencilControl.target.image : VK_NULL_HANDLE};
|
||||
for (const VkImage image : images) {
|
||||
if (image == VK_NULL_HANDLE) continue;
|
||||
ImageBarrier(cmd, image, item.aspects, VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0,
|
||||
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
|
||||
VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT);
|
||||
}
|
||||
}
|
||||
// (2) The inputs and the sentinels, cleared the wire's way.
|
||||
for (const ClearPass& clear : clears) {
|
||||
VkRenderPassBeginInfo begin{VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO};
|
||||
begin.renderPass = clear.pass;
|
||||
begin.framebuffer = clear.framebuffer;
|
||||
begin.renderArea = fullRect;
|
||||
vkCmdBeginRenderPass(cmd, &begin, VK_SUBPASS_CONTENTS_INLINE);
|
||||
VkClearAttachment attachment{};
|
||||
attachment.aspectMask = clear.aspects;
|
||||
attachment.clearValue.depthStencil = {clear.depth, clear.stencil};
|
||||
const VkClearRect rect{fullRect, 0, 1};
|
||||
vkCmdClearAttachments(cmd, 1, &attachment, 1, &rect);
|
||||
vkCmdEndRenderPass(cmd);
|
||||
}
|
||||
// (3) What TransitionWireImage records when the layout already matches - the case of a
|
||||
// source the application cleared and then resolves.
|
||||
{
|
||||
VkMemoryBarrier memory{VK_STRUCTURE_TYPE_MEMORY_BARRIER};
|
||||
memory.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT;
|
||||
memory.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT;
|
||||
vkCmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 1,
|
||||
&memory, 0, nullptr, 0, nullptr);
|
||||
}
|
||||
// (4) THE SUBJECT: the render-pass arm, begun and ended with no draw. Under the test-only
|
||||
// elideSubject it is not recorded at all: its target keeps the sentinel cleared in (2) and
|
||||
// the layout it was left in, which is what (6) expects either way.
|
||||
if (!context.elideSubject) {
|
||||
for (const FormatWork& item : work) {
|
||||
VkRenderPassBeginInfo begin{VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO};
|
||||
begin.renderPass = item.resolvePass;
|
||||
begin.framebuffer = item.resolveFramebuffer;
|
||||
begin.renderArea = fullRect;
|
||||
vkCmdBeginRenderPass(cmd, &begin, VK_SUBPASS_CONTENTS_INLINE);
|
||||
vkCmdEndRenderPass(cmd);
|
||||
}
|
||||
}
|
||||
// (5) THE CONTROL: the shader arm on the twin source, which TransitionWireImage moves to
|
||||
// SHADER_READ_ONLY_OPTIMAL first (both aspects of a packed format).
|
||||
for (const FormatWork& item : work) {
|
||||
if (!item.depthControl.ready && !item.stencilControl.ready) continue;
|
||||
ImageBarrier(cmd, item.controlSource.image, item.aspects, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
|
||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||
VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
|
||||
VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
|
||||
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT);
|
||||
for (const ControlPass* control : {&item.depthControl, &item.stencilControl}) {
|
||||
if (!control->ready) continue;
|
||||
RecordWireShaderResolveDraw(cmd, objects.kit, control->pass, control->pipeline, control->framebuffer,
|
||||
control->set, {kProbeExtent, kProbeExtent}, fullRect);
|
||||
}
|
||||
}
|
||||
// (6) Every target to TRANSFER_SRC with the barrier ResolveWireDepthStencil puts after its
|
||||
// resolve (a depth/stencil resolve writes in COLOR_ATTACHMENT_OUTPUT), then one copy per aspect.
|
||||
const auto copyOut = [&](VkImage image, VkImageAspectFlags aspect, VkDeviceSize offset) {
|
||||
VkBufferImageCopy copy{};
|
||||
copy.bufferOffset = offset;
|
||||
copy.imageSubresource = {aspect, 0, 0, 1};
|
||||
copy.imageExtent = {kProbeExtent, kProbeExtent, 1};
|
||||
vkCmdCopyImageToBuffer(cmd, image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, objects.buffer, 1, ©);
|
||||
};
|
||||
const auto toTransfer = [&](VkImage image, VkImageAspectFlags aspects) {
|
||||
ImageBarrier(cmd, image, aspects, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT |
|
||||
VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
|
||||
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_READ_BIT);
|
||||
};
|
||||
for (const FormatWork& item : work) {
|
||||
toTransfer(item.subjectTarget.image, item.aspects);
|
||||
if (item.aspects & VK_IMAGE_ASPECT_DEPTH_BIT)
|
||||
copyOut(item.subjectTarget.image, VK_IMAGE_ASPECT_DEPTH_BIT, item.subjectDepthOffset);
|
||||
if (item.aspects & VK_IMAGE_ASPECT_STENCIL_BIT)
|
||||
copyOut(item.subjectTarget.image, VK_IMAGE_ASPECT_STENCIL_BIT, item.subjectStencilOffset);
|
||||
if (item.depthControl.ready) {
|
||||
toTransfer(item.depthControl.target.image, item.aspects);
|
||||
copyOut(item.depthControl.target.image, VK_IMAGE_ASPECT_DEPTH_BIT, item.depthControl.offset);
|
||||
}
|
||||
if (item.stencilControl.ready) {
|
||||
toTransfer(item.stencilControl.target.image, item.aspects);
|
||||
copyOut(item.stencilControl.target.image, VK_IMAGE_ASPECT_STENCIL_BIT, item.stencilControl.offset);
|
||||
}
|
||||
}
|
||||
{
|
||||
VkBufferMemoryBarrier barrier{VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER};
|
||||
barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
barrier.dstAccessMask = VK_ACCESS_HOST_READ_BIT;
|
||||
barrier.srcQueueFamilyIndex = barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
barrier.buffer = objects.buffer;
|
||||
barrier.size = VK_WHOLE_SIZE;
|
||||
vkCmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 1,
|
||||
&barrier, 0, nullptr);
|
||||
}
|
||||
if (vkEndCommandBuffer(cmd) != VK_SUCCESS) return fail("vkEndCommandBuffer failed");
|
||||
|
||||
VkFenceCreateInfo fenceInfo{VK_STRUCTURE_TYPE_FENCE_CREATE_INFO};
|
||||
if (vkCreateFence(device, &fenceInfo, nullptr, &objects.fence) != VK_SUCCESS)
|
||||
return fail("vkCreateFence failed");
|
||||
VkSubmitInfo submit{VK_STRUCTURE_TYPE_SUBMIT_INFO};
|
||||
submit.commandBufferCount = 1;
|
||||
submit.pCommandBuffers = &cmd;
|
||||
if (const VkResult result = vkQueueSubmit(context.queue, 1, &submit, objects.fence); result != VK_SUCCESS)
|
||||
return fail(format("vkQueueSubmit failed (VkResult {})", static_cast<Int>(result)));
|
||||
const VkResult waited = vkWaitForFences(device, 1, &objects.fence, VK_TRUE, kFenceTimeoutNs);
|
||||
if (waited == VK_TIMEOUT) {
|
||||
// The submission may still be executing: destroying anything it names, or idle-waiting
|
||||
// the device, is the hang the bound exists to prevent. Everything leaks.
|
||||
leak = true;
|
||||
measurement.fenceWaitTimedOut = true;
|
||||
return fail("the probe's fence did not signal within 5 s");
|
||||
}
|
||||
if (waited != VK_SUCCESS) return fail(format("vkWaitForFences failed (VkResult {})", static_cast<Int>(waited)));
|
||||
|
||||
void* mapped = nullptr;
|
||||
if (vkMapMemory(device, bufferMemory, 0, VK_WHOLE_SIZE, 0, &mapped) != VK_SUCCESS || mapped == nullptr)
|
||||
return fail("vkMapMemory failed");
|
||||
if (!bufferCoherent) {
|
||||
VkMappedMemoryRange range{VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE};
|
||||
range.memory = bufferMemory;
|
||||
range.size = VK_WHOLE_SIZE;
|
||||
vkInvalidateMappedMemoryRanges(device, 1, &range);
|
||||
}
|
||||
const Uint8* bytes = static_cast<const Uint8*>(mapped);
|
||||
const auto tally = [&](WireDepthResolveAspectReading& aspect, VkDeviceSize offset, Uint32 texelBytes,
|
||||
Bool depth, VkFormat format, Bool subject) {
|
||||
Uint32 matches = 0, sentinels = 0, first = 0;
|
||||
for (Uint32 i = 0; i < kProbeTexels; ++i) {
|
||||
const Uint8* texel = bytes + offset + static_cast<VkDeviceSize>(i) * texelBytes;
|
||||
const Uint32 word = depth ? ReadDepthWord(format, texel) : static_cast<Uint32>(*texel);
|
||||
if (i == 0) first = word;
|
||||
if (WordDistance(word, aspect.expected) <= aspect.tolerance) ++matches;
|
||||
if (WordDistance(word, aspect.sentinel) <= aspect.tolerance) ++sentinels;
|
||||
}
|
||||
if (subject) {
|
||||
aspect.renderPassMatches = matches;
|
||||
aspect.renderPassSentinels = sentinels;
|
||||
aspect.renderPassFirst = first;
|
||||
} else {
|
||||
aspect.shaderRan = true;
|
||||
aspect.shaderMatches = matches;
|
||||
aspect.shaderFirst = first;
|
||||
}
|
||||
};
|
||||
for (const FormatWork& item : work) {
|
||||
WireDepthResolveFormatReading& reading = measurement.formats[item.reading];
|
||||
if (item.aspects & VK_IMAGE_ASPECT_DEPTH_BIT) {
|
||||
auto& aspect = reading.depth;
|
||||
aspect.measured = true;
|
||||
aspect.texels = kProbeTexels;
|
||||
aspect.expected = EncodeDepth(item.format, kClearDepth);
|
||||
aspect.sentinel = EncodeDepth(item.format, kSentinelDepth);
|
||||
aspect.tolerance = IsFloatDepth(item.format) ? 0u : 1u;
|
||||
tally(aspect, item.subjectDepthOffset, DepthCopyBytes(item.format), true, item.format, true);
|
||||
if (item.depthControl.ready)
|
||||
tally(aspect, item.depthControl.offset, DepthCopyBytes(item.format), true, item.format, false);
|
||||
}
|
||||
if (item.aspects & VK_IMAGE_ASPECT_STENCIL_BIT) {
|
||||
auto& aspect = reading.stencil;
|
||||
aspect.measured = true;
|
||||
aspect.texels = kProbeTexels;
|
||||
aspect.expected = kClearStencil;
|
||||
aspect.sentinel = kSentinelStencil;
|
||||
aspect.tolerance = 0;
|
||||
tally(aspect, item.subjectStencilOffset, 1, false, item.format, true);
|
||||
if (item.stencilControl.ready)
|
||||
tally(aspect, item.stencilControl.offset, 1, false, item.format, false);
|
||||
}
|
||||
}
|
||||
vkUnmapMemory(device, bufferMemory);
|
||||
measurement.ran = true;
|
||||
if (!kitFailure.empty()) measurement.failureReason = kitFailure;
|
||||
return measurement;
|
||||
}
|
||||
|
||||
WireDepthResolveProbeMeasurement RunWireDepthResolveProbeOnThrowawayDevice(
|
||||
PFN_vkGetInstanceProcAddr getInstanceProcAddr, VkInstance instance, VkPhysicalDevice physicalDevice,
|
||||
Uint32 graphicsQueueFamilyIndex, const Vector<VkExtensionProperties>& deviceExtensions,
|
||||
Bool& renderPassArmAvailable, Bool& shaderStencilExport) {
|
||||
WireDepthResolveProbeMeasurement measurement;
|
||||
const auto has = [&](const char* name) {
|
||||
for (const VkExtensionProperties& extension : deviceExtensions)
|
||||
if (std::strcmp(extension.extensionName, name) == 0) return true;
|
||||
return false;
|
||||
};
|
||||
renderPassArmAvailable = has(VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME) &&
|
||||
has(VK_KHR_DEPTH_STENCIL_RESOLVE_EXTENSION_NAME);
|
||||
shaderStencilExport = has(VK_EXT_SHADER_STENCIL_EXPORT_EXTENSION_NAME);
|
||||
if (!renderPassArmAvailable) {
|
||||
measurement.failureReason = "no VK_KHR_create_renderpass2 + VK_KHR_depth_stencil_resolve";
|
||||
return measurement;
|
||||
}
|
||||
VkPhysicalDeviceProperties properties{};
|
||||
vkGetPhysicalDeviceProperties(physicalDevice, &properties);
|
||||
auto getProperties2 = reinterpret_cast<PFN_vkGetPhysicalDeviceProperties2>(
|
||||
getInstanceProcAddr(instance, "vkGetPhysicalDeviceProperties2"));
|
||||
if (getProperties2 == nullptr)
|
||||
getProperties2 = reinterpret_cast<PFN_vkGetPhysicalDeviceProperties2>(
|
||||
getInstanceProcAddr(instance, "vkGetPhysicalDeviceProperties2KHR"));
|
||||
const auto createDevice =
|
||||
reinterpret_cast<PFN_vkCreateDevice>(getInstanceProcAddr(instance, "vkCreateDevice"));
|
||||
if (properties.apiVersion < VK_API_VERSION_1_1 || getProperties2 == nullptr || createDevice == nullptr) {
|
||||
renderPassArmAvailable = false;
|
||||
measurement.failureReason = "a pre-1.1 device, or no vkGetPhysicalDeviceProperties2 / vkCreateDevice";
|
||||
return measurement;
|
||||
}
|
||||
VkPhysicalDeviceDepthStencilResolveProperties resolveProperties{
|
||||
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES};
|
||||
VkPhysicalDeviceProperties2 properties2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2};
|
||||
properties2.pNext = &resolveProperties;
|
||||
getProperties2(physicalDevice, &properties2);
|
||||
|
||||
// The renderer's own extension set for the two arms (VulkanRenderer.cpp,
|
||||
// CreateLogicalDeviceAndQueues), nothing more.
|
||||
const Float priority = 1.0f;
|
||||
VkDeviceQueueCreateInfo queueInfo{VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO};
|
||||
queueInfo.queueFamilyIndex = graphicsQueueFamilyIndex;
|
||||
queueInfo.queueCount = 1;
|
||||
queueInfo.pQueuePriorities = &priority;
|
||||
Vector<const char*> extensions{VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME,
|
||||
VK_KHR_DEPTH_STENCIL_RESOLVE_EXTENSION_NAME};
|
||||
if (shaderStencilExport) extensions.push_back(VK_EXT_SHADER_STENCIL_EXPORT_EXTENSION_NAME);
|
||||
VkDeviceCreateInfo deviceInfo{VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO};
|
||||
deviceInfo.queueCreateInfoCount = 1;
|
||||
deviceInfo.pQueueCreateInfos = &queueInfo;
|
||||
deviceInfo.enabledExtensionCount = static_cast<Uint32>(extensions.size());
|
||||
deviceInfo.ppEnabledExtensionNames = extensions.data();
|
||||
VkDevice device = VK_NULL_HANDLE;
|
||||
if (const VkResult result = createDevice(physicalDevice, &deviceInfo, nullptr, &device);
|
||||
result != VK_SUCCESS || device == VK_NULL_HANDLE) {
|
||||
measurement.failureReason = format("vkCreateDevice failed (VkResult {})", static_cast<Int>(result));
|
||||
return measurement;
|
||||
}
|
||||
WireDepthResolveProbeContext context;
|
||||
context.physicalDevice = physicalDevice;
|
||||
context.device = device;
|
||||
vkGetDeviceQueue(device, graphicsQueueFamilyIndex, 0, &context.queue);
|
||||
context.queueFamilyIndex = graphicsQueueFamilyIndex;
|
||||
context.createRenderPass2 =
|
||||
reinterpret_cast<PFN_vkCreateRenderPass2>(vkGetDeviceProcAddr(device, "vkCreateRenderPass2KHR"));
|
||||
context.depthResolveModes = resolveProperties.supportedDepthResolveModes;
|
||||
context.stencilResolveModes = resolveProperties.supportedStencilResolveModes;
|
||||
context.shaderStencilExport = shaderStencilExport;
|
||||
measurement = RunWireDepthResolveProbe(context);
|
||||
// A timed-out probe leaked its children on purpose; destroying their device would block
|
||||
// exactly where the bound says not to.
|
||||
if (!measurement.fenceWaitTimedOut) vkDestroyDevice(device, nullptr);
|
||||
return measurement;
|
||||
}
|
||||
} // namespace MobileGL::MG_Backend::DirectVulkan
|
||||
#endif
|
||||
@@ -1,121 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Backend/DirectVulkan/Renderer/WireDepthResolveProbe.h
|
||||
// Copyright (c) 2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
#pragma once
|
||||
|
||||
#include "WireDepthResolveArm.h"
|
||||
|
||||
#include <Config.h>
|
||||
#include <Includes.h>
|
||||
|
||||
// P7 gate 5 (g5-msprobe): the Vulkan half of the multisample depth/stencil resolve probe, and the
|
||||
// two resolve arms it measures.
|
||||
//
|
||||
// THE ARMS LIVE HERE, NOT ONLY IN THE RENDERER. A probe that rebuilt "something like" the wire's
|
||||
// render pass would measure its own copy; the render-pass description, the shader pass's modules,
|
||||
// pipeline and draw, and the view shapes both arms attach are defined once below and called by
|
||||
// ResolveWireDepthStencil (WireFramebuffer.inc), ResolveWireDepthStencilWithShader
|
||||
// (WireMultisampleResolve.inc) and the probe alike.
|
||||
//
|
||||
// Two callers: the Magma renderer at device bring-up (server side, once per process, only where
|
||||
// the render-pass arm exists at all - VulkanRenderer::ArmWireDepthResolveOrder) and the POST's
|
||||
// "Known Driver Bugs" section (MG_Util/SelfTest/DriverBugProbes.cpp) on a throwaway device.
|
||||
//
|
||||
// Disaggregated builds only: the monolith never records either arm, and the pull build's image
|
||||
// must not change (P7 gate G1).
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// Every aspect a wire depth/stencil format has.
|
||||
VkImageAspectFlags WireDepthStencilFormatAspects(VkFormat format);
|
||||
|
||||
// A 2D view of one level/layer of a depth/stencil image naming `aspects`. The render-pass arm
|
||||
// attaches both images with every aspect of the format; the shader arm SAMPLES its source
|
||||
// through a view of exactly one aspect (a depth/stencil image can only be sampled that way) and
|
||||
// attaches its target with every aspect.
|
||||
VkImageViewCreateInfo WireDepthStencilViewInfo(VkImage image, VkFormat format, VkImageAspectFlags aspects,
|
||||
Uint32 level, Uint32 layer);
|
||||
|
||||
// THE RENDER-PASS ARM: attachment 0 the multisample source (LOAD/STORE), attachment 1 the
|
||||
// single-sample resolve target (DONT_CARE/STORE), both in DEPTH_STENCIL_ATTACHMENT_OPTIMAL, one
|
||||
// subpass whose VkSubpassDescriptionDepthStencilResolve resolves every aspect of the format
|
||||
// with VK_RESOLVE_MODE_SAMPLE_ZERO_BIT. The caller begins and ends it with NO draw.
|
||||
VkResult CreateWireDepthStencilResolvePass(PFN_vkCreateRenderPass2 createRenderPass2, VkDevice device,
|
||||
VkFormat format, VkSampleCountFlagBits samples, VkRenderPass* pass);
|
||||
|
||||
// THE SHADER ARM's device objects that do not depend on the format.
|
||||
struct WireShaderResolveKit {
|
||||
VkShaderModule vertex = VK_NULL_HANDLE;
|
||||
VkShaderModule depthFragment = VK_NULL_HANDLE;
|
||||
// Only where VK_EXT_shader_stencil_export is enabled: its SPIR-V declares StencilExportEXT.
|
||||
VkShaderModule stencilFragment = VK_NULL_HANDLE;
|
||||
VkDescriptorSetLayout descriptorLayout = VK_NULL_HANDLE;
|
||||
VkPipelineLayout pipelineLayout = VK_NULL_HANDLE;
|
||||
VkSampler nearest = VK_NULL_HANDLE;
|
||||
};
|
||||
// Creates every member; the first failure is returned and the members made so far stay set,
|
||||
// for DestroyWireShaderResolveKit.
|
||||
VkResult CreateWireShaderResolveKit(VkDevice device, Bool shaderStencilExport, WireShaderResolveKit& kit);
|
||||
void DestroyWireShaderResolveKit(VkDevice device, WireShaderResolveKit& kit);
|
||||
// One (format, aspect)'s single-attachment render pass: DONT_CARE/STORE on both aspects,
|
||||
// DEPTH_STENCIL_ATTACHMENT_OPTIMAL throughout.
|
||||
VkResult CreateWireShaderResolveRenderPass(VkDevice device, VkFormat format, VkRenderPass* pass);
|
||||
// Its pipeline: full-screen triangle, gl_FragDepth (ALWAYS + write) or gl_FragStencilRefARB
|
||||
// (REPLACE everywhere), viewport and scissor dynamic. VK_ERROR_FEATURE_NOT_PRESENT when the kit
|
||||
// has no fragment module for `aspect`.
|
||||
VkResult CreateWireShaderResolvePipeline(VkDevice device, const WireShaderResolveKit& kit, VkRenderPass pass,
|
||||
VkImageAspectFlags aspect, VkPipeline* pipeline);
|
||||
// Records the draw: the render area and the scissor are `rect`, the viewport is the WHOLE
|
||||
// attachment (gl_FragCoord is what the fragment stage fetches by), one triangle.
|
||||
void RecordWireShaderResolveDraw(VkCommandBuffer commandBuffer, const WireShaderResolveKit& kit,
|
||||
VkRenderPass pass, VkPipeline pipeline, VkFramebuffer framebuffer,
|
||||
VkDescriptorSet descriptorSet, VkExtent2D attachmentExtent, VkRect2D rect);
|
||||
|
||||
// What the probe runs on. The device must have been created with VK_KHR_create_renderpass2 and
|
||||
// VK_KHR_depth_stencil_resolve (or Vulkan 1.2 core), and with VK_EXT_shader_stencil_export where
|
||||
// `shaderStencilExport` says so. The queue must be otherwise idle for the probe's duration.
|
||||
struct WireDepthResolveProbeContext {
|
||||
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
|
||||
VkDevice device = VK_NULL_HANDLE;
|
||||
VkQueue queue = VK_NULL_HANDLE;
|
||||
Uint32 queueFamilyIndex = 0;
|
||||
PFN_vkCreateRenderPass2 createRenderPass2 = nullptr;
|
||||
VkResolveModeFlags depthResolveModes = 0;
|
||||
VkResolveModeFlags stencilResolveModes = 0;
|
||||
Bool shaderStencilExport = false;
|
||||
// TEST ONLY (MGITEST_MAGMA_DEPTH_RESOLVE_PROBE=elide-subject, WireDepthResolveArm.h): record
|
||||
// NO render-pass resolve, so every subject target keeps its sentinel - the Adreno 830's
|
||||
// reading - while the shader control runs as always. Everything else is the real probe.
|
||||
Bool elideSubject = false;
|
||||
};
|
||||
|
||||
// Per format the device can host as a 4x multisample depth/stencil attachment AND for which
|
||||
// ResolveWireDepthStencil would take the render-pass arm (D16, X8_D24, D32F, D24S8, D32FS8, S8):
|
||||
// - two identical 4x4 4x multisample sources (production usage), each cleared to depth 0.25 /
|
||||
// stencil 0x5A the way the wire clears (a LOAD pass with vkCmdClearAttachments);
|
||||
// - single-sample resolve targets (the production scratch usage) pre-filled with the sentinel
|
||||
// depth 0.75 / stencil 0xA5;
|
||||
// - SUBJECT: the render-pass arm's exact pass, begun and ended with no draw;
|
||||
// - CONTROL: the shader arm's exact pass on the other source, one target per aspect (stencil
|
||||
// only with VK_EXT_shader_stencil_export);
|
||||
// - every target copied aspect by aspect into a host-visible buffer and compared texel by texel.
|
||||
// One submission, a bounded fence wait (on timeout every object is leaked and the measurement
|
||||
// says so - the caller must then not destroy or idle-wait the device), teardown on every other
|
||||
// path. Never touches renderer state.
|
||||
WireDepthResolveProbeMeasurement RunWireDepthResolveProbe(const WireDepthResolveProbeContext& context);
|
||||
|
||||
// The POST's entry: creates a throwaway device on `physicalDevice` with exactly the extensions
|
||||
// the renderer enables for the two arms, runs the probe on its graphics queue and destroys the
|
||||
// device (leaks it on a fence timeout). `renderPassArmAvailable` is false - and nothing is run -
|
||||
// when the device lacks VK_KHR_create_renderpass2 / VK_KHR_depth_stencil_resolve; the shader
|
||||
// pass is then the only arm and the probe has nothing to choose between.
|
||||
// `shaderStencilExport` reports whether VK_EXT_shader_stencil_export was available.
|
||||
WireDepthResolveProbeMeasurement RunWireDepthResolveProbeOnThrowawayDevice(
|
||||
PFN_vkGetInstanceProcAddr getInstanceProcAddr, VkInstance instance, VkPhysicalDevice physicalDevice,
|
||||
Uint32 graphicsQueueFamilyIndex, const Vector<VkExtensionProperties>& deviceExtensions,
|
||||
Bool& renderPassArmAvailable, Bool& shaderStencilExport);
|
||||
} // namespace MobileGL::MG_Backend::DirectVulkan
|
||||
#endif
|
||||
@@ -11,13 +11,9 @@
|
||||
return MagmaProgramSource(handle, records[index]);
|
||||
}
|
||||
|
||||
// Through the same seam as MagmaWireFatal, and for the same reason (P7 wave 0). The family
|
||||
// stays RoleViolation: reaching the legacy buffer arm inside a Magma server is a role
|
||||
// invariant the two halves must hold, not a verb the wire failed to migrate.
|
||||
[[noreturn]] static void WireBufferLegacyFatal() {
|
||||
MG_Pipe::MGPipeSessionFail(
|
||||
MG_Pipe::MGPipeFatalFamily::RoleViolation,
|
||||
"MGPipe: Fatal{RoleViolation, \"buffer-legacy-arm\"} (Magma P7 buffer consumer)");
|
||||
MGLOG_F("MGPipe: Fatal{RoleViolation, \"buffer-legacy-arm\"} (Magma P7 buffer consumer)");
|
||||
std::abort();
|
||||
}
|
||||
|
||||
static const MG_Pipe::MGPStreamOutputBegin& WireXfbSpan() {
|
||||
@@ -203,14 +199,8 @@
|
||||
Flags<DrawSetupAspect> aspects, const DrawCmdParam& drawParams, const IndexBufferView* indices) {
|
||||
auto& state = MG_Pipe::MGPipeApplier();
|
||||
const auto program = WireProgramSource(state.BoundShaderCso);
|
||||
if (!program.GetLinkStatus() || !program.GetSpirvStatus()) {
|
||||
MGL_WIRE_DECLINE_AT(ProgramLinkOrSpirv, "program is not linked or carries no SPIR-V");
|
||||
return false;
|
||||
}
|
||||
// P8-D: the wire arm's own indirect draw (DrawWireIndirectNative) is the one caller that
|
||||
// may pass this aspect; a monolith indirect entry point reached here is still the role
|
||||
// violation.
|
||||
if ((aspects & DrawSetupAspect::IndirectDrawBuffer) && !m_wireNativeIndirectDraw)
|
||||
if (!program.GetLinkStatus() || !program.GetSpirvStatus()) return false;
|
||||
if (aspects & DrawSetupAspect::IndirectDrawBuffer)
|
||||
WireBufferLegacyFatal();
|
||||
MakeXfbWritesVisible();
|
||||
const auto* fbo = state.DrawFramebuffer();
|
||||
@@ -230,16 +220,10 @@
|
||||
flags |= ProgramFactory::CompileOptionBit::ZeroBaseVertex;
|
||||
programObject = &m_programFactory->GetOrCreateProgram(program, flags);
|
||||
}
|
||||
if (programObject->pointSizeCapabilityUnsupported) {
|
||||
MGL_WIRE_DECLINE_AT(PointSizeCapability, "the program writes gl_PointSize and the device cannot express it");
|
||||
return false;
|
||||
}
|
||||
if (programObject->pointSizeCapabilityUnsupported) return false;
|
||||
const auto& programObj = *programObject;
|
||||
m_currentDrawXfbCaptureDeclined = programObj.xfbCaptureDeclined;
|
||||
if (!m_uniformManager->PrepareWireTextureResources(program, programObj)) {
|
||||
MGL_WIRE_DECLINE_AT(TextureResourcesUnprepared, "a sampled/storage image could not be made ready; see the Tex* tally");
|
||||
return false;
|
||||
}
|
||||
if (!m_uniformManager->PrepareWireTextureResources(program, programObj)) return false;
|
||||
// Lazy image uploads/promotions can submit the old recording. Resolve
|
||||
// ALL attachments before descriptor binding captures the current cmd.
|
||||
for (Uint32 i = 0; i < MG_Pipe::kMGPipeMaxColorAttachments; ++i) {
|
||||
@@ -257,106 +241,37 @@
|
||||
const auto& vao = state.VertexElementsCsos[vaoHandle.Slot];
|
||||
if (!vao.Live || vao.Gen != vaoHandle.Gen) MagmaWireFatal("vertex-elements-generation");
|
||||
VertexInputStateFactory::BackendVertexInputState input{};
|
||||
// P7 wave 2 package C, CONTRACT-P7 §3.2: THE `vertex-layout` ROW IS RETIRED AND SPLIT.
|
||||
//
|
||||
// A false is now ONE reason and only one - `buffer-window`, an enabled attribute the
|
||||
// program reads whose slot lies outside the window set_vertex_buffers published. That
|
||||
// is a disagreement about what crossed, not about what this device can express, so it
|
||||
// keeps a named Fatal through the hook (MGPipeSessionFail -> Session::Fail, which is
|
||||
// what rule I asks of a refusal that must stay a refusal). It is the check that caught
|
||||
// the Redmi VAO hash collision fixed in 376c04be, which is why it is not softened.
|
||||
// The P7 marker is gone from the detail string with the abort: this is a permanent
|
||||
// protocol error, not a shape the split path has yet to migrate, so it must not keep
|
||||
// counting against the census of unmigrated refusals (scripts/ci/fatal_census.py
|
||||
// counts the marker literally, which is also why no comment in this package spells it).
|
||||
if (!m_vertexInputStateFactory->BuildWireVertexInput(vao, state,
|
||||
programObj.activeVertexInputLocationMask, input))
|
||||
MagmaWireFatal("vertex-layout-buffer-window");
|
||||
// The seven device/format reasons are now MASKED OUT of the vertex input state, and
|
||||
// this is the monolith arm's pre-flight for them, statement for statement
|
||||
// (VulkanRenderer.cpp's SetupDraw: "Fail loudly rather than render wrong pixels"). An
|
||||
// enabled array with no usable VkFormat never reaches the vertex input state, which
|
||||
// makes it indistinguishable from a DISABLED one - and a disabled one is answered
|
||||
// below by uploading the current attribute value, so without this check the draw would
|
||||
// quietly feed the shader a constant in place of the application's vertex data.
|
||||
//
|
||||
// A DECLINE, NOT A FATAL (rule I (a)): the draw is skipped, the reason is named once,
|
||||
// and the observable is the monolith lane's for the same VAO on the same device.
|
||||
// BuildWireVertexInput only considers attributes the program reads, so a masked bit is
|
||||
// always an active one and this predicate is the whole of the difference.
|
||||
if ((input.unsupportedAttribMask & programObj.activeVertexInputLocationMask) != 0) {
|
||||
MGLOG_E_ONCE("Magma wire draw skipped: program=%u reads vertex attribute location "
|
||||
"mask 0x%x whose enabled array has no supported vertex format",
|
||||
program.GetExternalIndex(),
|
||||
input.unsupportedAttribMask & programObj.activeVertexInputLocationMask);
|
||||
WireDeclineTally::Count(WireDeclineSite::VertexFormatUnsupported);
|
||||
return false;
|
||||
}
|
||||
programObj.activeVertexInputLocationMask, input)) MagmaWireFatal("vertex-layout@P7");
|
||||
Vector<BufferSlice> vertexSlices(input.bindings.size());
|
||||
for (SizeT binding = 0; binding < input.bindings.size(); ++binding) {
|
||||
const Uint32 location = input.bindingAttributeLocations[binding];
|
||||
const auto& attr = vao.Attributes[location];
|
||||
const auto& resource = state.VertexBuffers[location];
|
||||
// P8-F: A RECORD INVARIANT, NOT AN UNMIGRATED VERB (it carried a P8 phase tag).
|
||||
// The client turns every enabled client-memory array into an owned buffer before the
|
||||
// draw record is built, or refuses the draw itself (MG_Impl/Pipe/OwnedDrawInputs.h),
|
||||
// so an attribute the program reads with no buffer handle is a foreign peer's record.
|
||||
if (MG_Pipe::MGPipeHandleIsNull(resource.Res))
|
||||
MG_Pipe::MGPipeSessionFail(MG_Pipe::MGPipeFatalFamily::ProtocolCorruption,
|
||||
"MGPipe: Fatal{ProtocolCorruption, \"Magma:client-vertex-array\"} location=%u: an "
|
||||
"attribute the program reads carries no buffer handle", location);
|
||||
if (MG_Pipe::MGPipeHandleIsNull(resource.Res)) MagmaWireFatal("client-vertex-array@P8");
|
||||
BufferSlice slice{};
|
||||
if (!m_bufferManager.AcquireWireSlice(BufferKind::Vertex, resource.Res, slice))
|
||||
MagmaWireFatal("vertex-buffer-resource");
|
||||
const VkDeviceSize offset = input.bindingBaseOffsets[binding];
|
||||
const auto type = static_cast<DataType>(attr.Type);
|
||||
const SizeT elementSize = VertexInputStateFactory::GetAttributeByteSize(type, attr.Size, attr.IsBgra);
|
||||
if (offset > slice.size || elementSize > slice.size - offset) {
|
||||
MGL_WIRE_DECLINE_AT(VertexAttributeWindow, "an enabled attribute's first element lies outside its buffer");
|
||||
return false;
|
||||
}
|
||||
if (offset > slice.size || elementSize > slice.size - offset) return false;
|
||||
const auto conversion = input.bindingConversions[binding];
|
||||
if (conversion != VertexInputStateFactory::VertexStreamConversion::None) {
|
||||
const SizeT stride = static_cast<SizeT>(attr.Stride);
|
||||
SizeT count = stride ? 1 + (static_cast<SizeT>(slice.size - offset) - elementSize) / stride : 1;
|
||||
// Direct non-indexed draws bound the conversion; indexed/multi-draw may
|
||||
// name arbitrary vertices, so preserve the entire valid source stream. So may an
|
||||
// indirect draw (P8-D): its vertex range is in GPU words nobody read.
|
||||
if (stride && !(aspects & DrawSetupAspect::IndexBuffer) &&
|
||||
!(aspects & DrawSetupAspect::IndirectDrawBuffer) && !resource.Divisor)
|
||||
// name arbitrary vertices, so preserve the entire valid source stream.
|
||||
if (stride && !(aspects & DrawSetupAspect::IndexBuffer) && !resource.Divisor)
|
||||
count = std::min<SizeT>(count, static_cast<SizeT>(drawParams.firstVertex) + drawParams.vertexCount);
|
||||
if (!count) {
|
||||
MGL_WIRE_DECLINE_AT(VertexStreamCountZero, "the converted vertex stream would hold no elements");
|
||||
return false;
|
||||
}
|
||||
if (!count) return false;
|
||||
Vector<Uint8> source((count - 1) * stride + elementSize);
|
||||
if (!m_bufferManager.ReadWireBuffer(resource.Res, offset, source.size(), source.data())) {
|
||||
MGL_WIRE_DECLINE_AT(VertexStreamRead, "the vertex bytes to convert could not be read back");
|
||||
return false;
|
||||
}
|
||||
if (!m_bufferManager.ReadWireBuffer(resource.Res, offset, source.size(), source.data())) return false;
|
||||
Vector<Uint8> converted;
|
||||
// P7 wave 2 package C, CONTRACT-P7 §3.2 `vertex-format-conversion`: DECLINE.
|
||||
// The converter is asked only for a conversion BuildWireVertexInput already
|
||||
// chose, so a refusal here means the two disagree about what is convertible -
|
||||
// a MobileGL-internal defect, not a peer's malformed record and not a verb the
|
||||
// split path has yet to migrate. Killing the session for it told the peer
|
||||
// "protocol corruption" about a bug on this side; skipping the draw and naming
|
||||
// it once is the honest answer and is what the row asks for. The packed
|
||||
// converter that would make the refusal unreachable is the row's optional half
|
||||
// and is not taken here.
|
||||
if (!ConvertWireVertexStream(attr, conversion, source.data(), stride, count, converted)) {
|
||||
MGLOG_E_ONCE("Magma wire draw skipped: no vertex stream converter for "
|
||||
"location=%u type=%u size=%u conversion=%d",
|
||||
location, attr.Type, static_cast<Uint32>(attr.Size),
|
||||
static_cast<Int>(conversion));
|
||||
WireDeclineTally::Count(WireDeclineSite::VertexStreamConverter);
|
||||
return false;
|
||||
}
|
||||
if (!ConvertWireVertexStream(attr, conversion, source.data(), stride, count, converted))
|
||||
MagmaWireFatal("vertex-format-conversion@P7");
|
||||
if (!m_bufferManager.UploadTransient(BufferKind::Vertex, m_frameContext.GetCurrentFrameIndex(),
|
||||
converted.data(), converted.size(), 16, vertexSlices[binding])) {
|
||||
MGL_WIRE_DECLINE_AT(VertexTransientUpload, "the converted vertex stream did not fit the transient arena");
|
||||
return false;
|
||||
}
|
||||
converted.data(), converted.size(), 16, vertexSlices[binding])) return false;
|
||||
} else {
|
||||
slice.offset += offset;
|
||||
slice.size -= offset;
|
||||
@@ -367,15 +282,9 @@
|
||||
BufferSlice indexSlice{};
|
||||
VkIndexType indexType = VK_INDEX_TYPE_MAX_ENUM;
|
||||
if (aspects & DrawSetupAspect::IndexBuffer) {
|
||||
if (!indices) {
|
||||
MGL_WIRE_DECLINE_AT(IndexViewMissing, "an indexed draw arrived with no index view");
|
||||
return false;
|
||||
}
|
||||
if (!indices) return false;
|
||||
const SizeT width = MG_Util::GetGLTypeSize(indices->indexType);
|
||||
if (width != 1 && width != 2 && width != 4) {
|
||||
MGL_WIRE_DECLINE_AT(IndexTypeWidth, "the index type is not 1, 2 or 4 bytes wide");
|
||||
return false;
|
||||
}
|
||||
if (width != 1 && width != 2 && width != 4) return false;
|
||||
indexType = width == 4 ? VK_INDEX_TYPE_UINT32 : width == 2 ? VK_INDEX_TYPE_UINT16 : VK_INDEX_TYPE_UINT8;
|
||||
const auto& restart = MGB_CTX->GetRenderStateParameters();
|
||||
const Uint32 fixed = MG_Util::FixedRestartIndexForGLType(indices->indexType);
|
||||
@@ -391,16 +300,10 @@
|
||||
MagmaWireFatal("index-buffer-resource");
|
||||
const Uint64 offset = state.IndexBuffer.Offset + indices->indexByteOffset;
|
||||
if (offset < state.IndexBuffer.Offset || offset > indexSlice.size ||
|
||||
indices->indexByteSize > indexSlice.size - offset) {
|
||||
MGL_WIRE_DECLINE_AT(IndexWindow, "the index range lies outside its buffer");
|
||||
return false;
|
||||
}
|
||||
indices->indexByteSize > indexSlice.size - offset) return false;
|
||||
if (replaceRestart || expandByte || offset % width) {
|
||||
copied.resize(indices->indexByteSize);
|
||||
if (!m_bufferManager.ReadWireBuffer(state.IndexBuffer.Res, offset, copied.size(), copied.data())) {
|
||||
MGL_WIRE_DECLINE_AT(IndexStreamRead, "the indices to rewrite could not be read back");
|
||||
return false;
|
||||
}
|
||||
if (!m_bufferManager.ReadWireBuffer(state.IndexBuffer.Res, offset, copied.size(), copied.data())) return false;
|
||||
bytes = copied.data();
|
||||
}
|
||||
indexSlice.offset += offset;
|
||||
@@ -424,15 +327,9 @@
|
||||
if (expandByte) indexType = VK_INDEX_TYPE_UINT16;
|
||||
}
|
||||
if (!m_bufferManager.UploadTransient(BufferKind::Index, m_frameContext.GetCurrentFrameIndex(),
|
||||
bytes, uploadSize, 16, indexSlice)) {
|
||||
MGL_WIRE_DECLINE_AT(IndexTransientUpload, "the rewritten indices did not fit the transient arena");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!indexSlice.IsValid()) {
|
||||
MGL_WIRE_DECLINE_AT(IndexSliceInvalid, "no usable index slice was resolved");
|
||||
return false;
|
||||
bytes, uploadSize, 16, indexSlice)) return false;
|
||||
}
|
||||
if (!indexSlice.IsValid()) return false;
|
||||
}
|
||||
|
||||
if (!frame.isCommandRecording) m_frameContext.BeginCommandRecording();
|
||||
@@ -440,10 +337,7 @@
|
||||
// Resolve it before constructing framebuffer views so both roles of that image
|
||||
// name the same allocation even on its first storage-image use.
|
||||
if (!m_uniformManager->BindProgramUniformBuffers(frame.commandBuffer, program, programObj,
|
||||
m_frameContext.GetCurrentFrameIndex(), VK_PIPELINE_BIND_POINT_GRAPHICS)) {
|
||||
MGL_WIRE_DECLINE_AT(UniformBufferBinding, "the program's uniform/storage bindings could not be bound");
|
||||
return false;
|
||||
}
|
||||
m_frameContext.GetCurrentFrameIndex(), VK_PIPELINE_BIND_POINT_GRAPHICS)) return false;
|
||||
|
||||
Vector<VkAttachmentDescription> attachments;
|
||||
Vector<VkImageViewCreateInfo> viewInfos;
|
||||
@@ -515,10 +409,7 @@
|
||||
depth.attachment = add(fbo->Depth, VK_IMAGE_ASPECT_DEPTH_BIT);
|
||||
else if (fbo->Stencil.Kind != MG_Pipe::kMGPipeSurfaceKindNone)
|
||||
depth.attachment = add(fbo->Stencil, VK_IMAGE_ASPECT_STENCIL_BIT);
|
||||
if (attachments.empty()) {
|
||||
MGL_WIRE_DECLINE_AT(NoAttachments, "the draw framebuffer resolved to no attachments");
|
||||
return false;
|
||||
}
|
||||
if (attachments.empty()) return false;
|
||||
passKey.width = extent.width;
|
||||
passKey.height = extent.height;
|
||||
passKey.layers = layers;
|
||||
@@ -575,10 +466,7 @@
|
||||
const Uint64 compatibilityId = m_wireRenderPassCompatibility.Intern(pipelinePassKey);
|
||||
const auto pipeline = GetOrCreatePipelineWithInput(mode, program, programObj, flags, input, pass,
|
||||
ResolvePrimitiveRestartEnable(aspects, indices), compatibilityId);
|
||||
if (pipeline == VK_NULL_HANDLE) {
|
||||
MGL_WIRE_DECLINE_AT(PipelineUnavailable, "no graphics pipeline could be created for this draw");
|
||||
return false;
|
||||
}
|
||||
if (pipeline == VK_NULL_HANDLE) return false;
|
||||
for (Uint32 i = 0; i < vertexSlices.size(); ++i)
|
||||
vkCmdBindVertexBuffers(frame.commandBuffer, i, 1, &vertexSlices[i].buffer, &vertexSlices[i].offset);
|
||||
Uint32 binding = static_cast<Uint32>(vertexSlices.size());
|
||||
@@ -589,23 +477,14 @@
|
||||
const void* data = nullptr;
|
||||
VkDeviceSize size = 0;
|
||||
if (!TryGetCurrentVertexAttributeUploadPayload(MGB_CTX->GetCurrentVertexAttribute(location),
|
||||
programObj.vertexInputTypes[location], format, data, size)) {
|
||||
MGL_WIRE_DECLINE_AT(CurrentAttributePayload, "a disabled array's current attribute value has no upload payload");
|
||||
return false;
|
||||
}
|
||||
programObj.vertexInputTypes[location], format, data, size)) return false;
|
||||
BufferSlice slice{};
|
||||
if (!m_bufferManager.UploadTransient(BufferKind::Vertex, m_frameContext.GetCurrentFrameIndex(),
|
||||
data, size, 16, slice)) {
|
||||
MGL_WIRE_DECLINE_AT(CurrentAttributeUpload, "the current attribute value did not fit the transient arena");
|
||||
return false;
|
||||
}
|
||||
data, size, 16, slice)) return false;
|
||||
vkCmdBindVertexBuffers(frame.commandBuffer, binding++, 1, &slice.buffer, &slice.offset);
|
||||
}
|
||||
if (indexSlice.IsValid()) vkCmdBindIndexBuffer(frame.commandBuffer, indexSlice.buffer, indexSlice.offset, indexType);
|
||||
if (!VkRenderPassManager::BeginRenderPass(frame.commandBuffer, pass)) {
|
||||
MGL_WIRE_DECLINE_AT(BeginRenderPass, "the render pass for this draw could not be begun");
|
||||
return false;
|
||||
}
|
||||
if (!VkRenderPassManager::BeginRenderPass(frame.commandBuffer, pass)) return false;
|
||||
vkCmdBindPipeline(frame.commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
|
||||
ApplyDynamicDrawStateTail(frame, pass.extent, fbo->IsDefault,
|
||||
ResolveDrawViewportCount(programObj.writesViewportIndexBuiltin));
|
||||
@@ -613,237 +492,19 @@
|
||||
return true;
|
||||
}
|
||||
|
||||
// ---- P8-D: THE WIRE ARM'S INDIRECT DRAWS READ THEIR WORDS ON THE GPU ----------------------
|
||||
//
|
||||
// The shape the monolith arm records (VulkanRenderer.cpp's MultiDraw{Elements,Arrays}Indirect
|
||||
// and MultiDrawElementsIndirectCount), with the wire store's own VkBuffer in place of the
|
||||
// frontend buffer's resident slice. Before this, every wire indirect draw read its commands
|
||||
// through ReadWireBuffer and expanded them on the CPU, and a store a shader had written made
|
||||
// that read a whole-GPU wait (WaitForWireBufferHostAccess) per draw.
|
||||
//
|
||||
// THE ONE FALSE: a COUNT form this device cannot issue - the monolith arm's own condition for
|
||||
// vkCmdDrawIndexedIndirectCount (MultiDrawElementsIndirectCount), extended to the non-indexed
|
||||
// twin the monolith never loads. Everything else is issued here or declined by name.
|
||||
Bool VulkanRenderer::DrawWireIndirectNative(GLenum mode, GLenum type, Uint64 offset, GLsizei drawcount,
|
||||
GLsizei stride, Bool indexed, Bool counted, Uint64 countOffset) {
|
||||
if (drawcount <= 0) return true;
|
||||
if (counted) {
|
||||
const auto countEntry = indexed ? s_vkCmdDrawIndexedIndirectCount : s_vkCmdWireDrawIndirectCount;
|
||||
if (!m_drawIndirectCountExtensionEnabled || countEntry == nullptr ||
|
||||
(!m_multiDrawIndirectFeatureEnabled && drawcount != 1))
|
||||
return false;
|
||||
}
|
||||
const auto& state = MG_Pipe::MGPipeApplier();
|
||||
// GL's command sizes (GL 4.6 10.3.10), which are also Vulkan's.
|
||||
const Uint64 commandSize = indexed ? 5 * sizeof(Uint32) : 4 * sizeof(Uint32);
|
||||
if (stride == 0) stride = static_cast<GLsizei>(commandSize);
|
||||
BufferSlice commands{};
|
||||
if (MG_Pipe::MGPipeHandleIsNull(state.VerbIndirectBuffer) ||
|
||||
!m_bufferManager.AcquireWireSlice(BufferKind::Indirect, state.VerbIndirectBuffer, commands)) {
|
||||
MGL_WIRE_DECLINE_AT(IndirectBufferUnbound, "an indirect draw names no live indirect buffer store");
|
||||
return true;
|
||||
}
|
||||
const Uint64 span = static_cast<Uint64>(stride) * static_cast<Uint64>(drawcount - 1) + commandSize;
|
||||
// GL refuses a stride that is not a multiple of four (INVALID_VALUE), and Vulkan requires
|
||||
// it for drawCount > 1; a peer's record that breaks either is declined, not issued.
|
||||
if (stride < static_cast<GLsizei>(commandSize) || (stride & 3) != 0 || (offset & 3u) != 0 ||
|
||||
offset > commands.size || span > commands.size - offset) {
|
||||
MGL_WIRE_DECLINE_AT(IndirectCommandRange, "the indirect commands lie outside their store or are misaligned");
|
||||
return true;
|
||||
}
|
||||
BufferSlice parameters{};
|
||||
if (counted) {
|
||||
if (MG_Pipe::MGPipeHandleIsNull(state.VerbIndirectParameterBuffer) ||
|
||||
!m_bufferManager.AcquireWireSlice(BufferKind::Indirect, state.VerbIndirectParameterBuffer, parameters) ||
|
||||
(countOffset & 3u) != 0 || countOffset > parameters.size || parameters.size - countOffset < sizeof(Uint32)) {
|
||||
MGL_WIRE_DECLINE_AT(IndirectCountRange, "the indirect draw count lies outside its parameter store");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// The index view is the WHOLE bound element store past its binding offset, as the monolith
|
||||
// arm binds it: the commands name their own firstIndex, which only the GPU reads.
|
||||
IndexBufferView indices{};
|
||||
DrawCmdParam vertexRange{};
|
||||
vertexRange.instanceCount = 1;
|
||||
Flags<DrawSetupAspect> aspects = DrawSetupAspect::IndirectDrawBuffer;
|
||||
if (indexed) {
|
||||
const SizeT width = MG_Util::GetGLTypeSize(type);
|
||||
BufferSlice elements{};
|
||||
if (width == 0 || MG_Pipe::MGPipeHandleIsNull(state.IndexBuffer.Res) ||
|
||||
!m_bufferManager.AcquireWireSlice(BufferKind::Index, state.IndexBuffer.Res, elements) ||
|
||||
state.IndexBuffer.Offset > elements.size) {
|
||||
MGL_WIRE_DECLINE_AT(IndirectIndexStore, "an indexed indirect draw names no usable element store");
|
||||
return true;
|
||||
}
|
||||
indices.indexType = type;
|
||||
indices.indexByteOffset = 0;
|
||||
indices.indexByteSize = static_cast<SizeT>(elements.size - state.IndexBuffer.Offset);
|
||||
vertexRange.vertexCount = static_cast<Uint32>(indices.indexByteSize / width);
|
||||
aspects |= DrawSetupAspect::IndexBuffer;
|
||||
}
|
||||
|
||||
// A shader write the store was marked with (MarkWireBufferGpuWritten) is made visible to
|
||||
// the indirect read here, once per write, so a program that omits GL_COMMAND_BARRIER_BIT
|
||||
// is not left racing a read the old CPU path used to take after a whole-GPU wait. The
|
||||
// application's own glMemoryBarrier is BuildMemoryBarrierForGlBarriers, as on the monolith
|
||||
// arm; transfer writes carry their own MEMORY_READ after-barrier (VkBufferManager.cpp).
|
||||
const Bool commandsWritten = m_bufferManager.TakeWireIndirectReadBarrier(state.VerbIndirectBuffer);
|
||||
const Bool countWritten = counted && m_bufferManager.TakeWireIndirectReadBarrier(state.VerbIndirectParameterBuffer);
|
||||
if (commandsWritten || countWritten) {
|
||||
RetireWireDrawPass();
|
||||
auto& barrierFrame = m_frameContext.GetCurrent();
|
||||
if (!barrierFrame.isCommandRecording) m_frameContext.BeginCommandRecording();
|
||||
if (VkRenderPassManager::GetActiveRenderPass() != nullptr)
|
||||
VkRenderPassManager::EndRenderPass(barrierFrame.commandBuffer);
|
||||
VkMemoryBarrier barrier{VK_STRUCTURE_TYPE_MEMORY_BARRIER};
|
||||
barrier.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT;
|
||||
barrier.dstAccessMask = VK_ACCESS_INDIRECT_COMMAND_READ_BIT;
|
||||
vkCmdPipelineBarrier(barrierFrame.commandBuffer, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
|
||||
VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT, 0, 1, &barrier, 0, nullptr, 0, nullptr);
|
||||
if (MG_Util::PipeStats::Enabled())
|
||||
MG_Util::PipeStats::AddCalls(MG_Util::PipeStats::CallClass::WireIndirectBarriers, 1);
|
||||
}
|
||||
|
||||
auto& frame = m_frameContext.GetCurrent();
|
||||
m_wireNativeIndirectDraw = true;
|
||||
const Bool ready = SetupDraw(frame, mode, aspects, vertexRange, indexed ? &indices : nullptr);
|
||||
m_wireNativeIndirectDraw = false;
|
||||
if (!ready) return true;
|
||||
MOBILEGL_ASSERT(frame.isCommandRecording, "%s: frame recording was not started", __func__);
|
||||
|
||||
const VkCommandBuffer commandBuffer = frame.commandBuffer;
|
||||
const VkDeviceSize first = commands.offset + offset;
|
||||
const Uint32 count = static_cast<Uint32>(drawcount);
|
||||
const Uint32 byteStride = static_cast<Uint32>(stride);
|
||||
if (counted) {
|
||||
const auto countEntry = indexed ? s_vkCmdDrawIndexedIndirectCount : s_vkCmdWireDrawIndirectCount;
|
||||
countEntry(commandBuffer, commands.buffer, first, parameters.buffer, parameters.offset + countOffset,
|
||||
count, byteStride);
|
||||
} else if (count == 1 || (!m_multiDrawForceUnrollIndirect && m_multiDrawIndirectFeatureEnabled)) {
|
||||
// maxDrawIndirectCount bounds one call; GL's drawcount does not.
|
||||
const Uint32 limit = std::max<Uint32>(1u, m_physicalDevice.properties.limits.maxDrawIndirectCount);
|
||||
for (Uint32 base = 0; base < count; base += limit) {
|
||||
const Uint32 chunk = std::min(count - base, limit);
|
||||
const VkDeviceSize at = first + static_cast<VkDeviceSize>(base) * byteStride;
|
||||
if (indexed) vkCmdDrawIndexedIndirect(commandBuffer, commands.buffer, at, chunk, byteStride);
|
||||
else vkCmdDrawIndirect(commandBuffer, commands.buffer, at, chunk, byteStride);
|
||||
}
|
||||
} else {
|
||||
// No multiDrawIndirect: one indirect draw per command, still read by the GPU
|
||||
// (the monolith arm's own fallback).
|
||||
for (Uint32 i = 0; i < count; ++i) {
|
||||
const VkDeviceSize at = first + static_cast<VkDeviceSize>(i) * byteStride;
|
||||
if (indexed) vkCmdDrawIndexedIndirect(commandBuffer, commands.buffer, at, 1, 0);
|
||||
else vkCmdDrawIndirect(commandBuffer, commands.buffer, at, 1, 0);
|
||||
}
|
||||
}
|
||||
if (MG_Util::PipeStats::Enabled())
|
||||
MG_Util::PipeStats::AddCalls(MG_Util::PipeStats::CallClass::WireIndirectNativeDraws, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
void VulkanRenderer::DispatchWireCompute(GLuint x, GLuint y, GLuint z) {
|
||||
RetireWireDrawPass();
|
||||
auto& frame = m_frameContext.GetCurrent();
|
||||
const auto program = WireProgramSource(MG_Pipe::MGPipeApplier().DispatchProgram);
|
||||
if (!program.GetLinkStatus() || !program.GetSpirvStatus()) {
|
||||
MGL_WIRE_DECLINE_AT(ComputeProgramLinkOrSpirv, "the compute program is not linked or carries no SPIR-V");
|
||||
return;
|
||||
}
|
||||
if (!program.GetLinkStatus() || !program.GetSpirvStatus()) return;
|
||||
const auto& programObj = m_programFactory->GetOrCreateProgram(program, {});
|
||||
if (!m_uniformManager->PrepareWireTextureResources(program, programObj)) {
|
||||
MGL_WIRE_DECLINE_AT(ComputeTextureResourcesUnprepared, "a sampled/storage image could not be made ready for the dispatch");
|
||||
return;
|
||||
}
|
||||
if (!m_uniformManager->PrepareWireTextureResources(program, programObj)) return;
|
||||
const auto pipeline = GetOrCreateComputePipeline(programObj);
|
||||
if (!pipeline) {
|
||||
MGL_WIRE_DECLINE_AT(ComputePipelineUnavailable, "no compute pipeline could be created for this dispatch");
|
||||
return;
|
||||
}
|
||||
if (!pipeline) return;
|
||||
if (!frame.isCommandRecording) m_frameContext.BeginCommandRecording();
|
||||
if (!m_uniformManager->BindProgramUniformBuffers(frame.commandBuffer, program, programObj,
|
||||
m_frameContext.GetCurrentFrameIndex(), VK_PIPELINE_BIND_POINT_COMPUTE)) {
|
||||
MGL_WIRE_DECLINE_AT(ComputeUniformBufferBinding, "the dispatch's uniform/storage bindings could not be bound");
|
||||
return;
|
||||
}
|
||||
m_frameContext.GetCurrentFrameIndex(), VK_PIPELINE_BIND_POINT_COMPUTE)) return;
|
||||
vkCmdBindPipeline(frame.commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline);
|
||||
vkCmdDispatch(frame.commandBuffer, x, y, z);
|
||||
}
|
||||
|
||||
// ---- P8-SV: THE WIRE ARM'S INDIRECT DISPATCH READS ITS GROUP COUNTS ON THE GPU ----------
|
||||
//
|
||||
// The monolith arm's shape (VulkanRenderer.cpp's DispatchComputeIndirect) with the wire
|
||||
// store's own VkBuffer in place of the frontend buffer's resident slice. Before this the wire
|
||||
// arm read the three words through ReadWireBuffer and dispatched them from the CPU, and a store
|
||||
// a shader had written made that read a whole-GPU wait (WaitForWireBufferHostAccess) per call.
|
||||
// There is no shape the device cannot issue, so there is no CPU path left: a record whose
|
||||
// store or words are unusable is declined by name.
|
||||
//
|
||||
// The barrier is P8-D's draw rule (DrawWireIndirectNative): a store marked shader-written gets
|
||||
// one MEMORY_WRITE -> INDIRECT_COMMAND_READ barrier before its next indirect read, whether or
|
||||
// not the application issued GL_COMMAND_BARRIER_BIT; DRAW_INDIRECT is the stage that consumes
|
||||
// VkDispatchIndirectCommand too. It is TAKEN before the bindings below, because binding this
|
||||
// dispatch's own storage buffers marks them written, and a store that is both this dispatch's
|
||||
// parameters and one of its outputs must keep that mark for the next reader.
|
||||
void VulkanRenderer::DispatchWireComputeIndirect(GLintptr offset) {
|
||||
RetireWireDrawPass();
|
||||
const auto& state = MG_Pipe::MGPipeApplier();
|
||||
constexpr Uint64 kCommandSize = 3 * sizeof(Uint32); // GL 4.6 10.3.10 / VkDispatchIndirectCommand
|
||||
BufferSlice parameters{};
|
||||
if (MG_Pipe::MGPipeHandleIsNull(state.VerbDispatchIndirectBuffer) ||
|
||||
!m_bufferManager.AcquireWireSlice(BufferKind::Indirect, state.VerbDispatchIndirectBuffer, parameters)) {
|
||||
MGL_WIRE_DECLINE_AT(DispatchIndirectBufferUnbound, "an indirect dispatch names no live dispatch-indirect store");
|
||||
return;
|
||||
}
|
||||
// GL refuses an offset that is negative or not a multiple of four (INVALID_VALUE) and a
|
||||
// command past the end of the buffer (INVALID_OPERATION); a peer's record that breaks
|
||||
// either is declined, not issued.
|
||||
if (offset < 0 || (static_cast<Uint64>(offset) & 3u) != 0 || static_cast<Uint64>(offset) > parameters.size ||
|
||||
parameters.size - static_cast<Uint64>(offset) < kCommandSize) {
|
||||
MGL_WIRE_DECLINE_AT(DispatchIndirectRange, "the dispatch group counts lie outside their store or are misaligned");
|
||||
return;
|
||||
}
|
||||
auto& frame = m_frameContext.GetCurrent();
|
||||
if (m_bufferManager.TakeWireIndirectReadBarrier(state.VerbDispatchIndirectBuffer)) {
|
||||
if (!frame.isCommandRecording) m_frameContext.BeginCommandRecording();
|
||||
if (VkRenderPassManager::GetActiveRenderPass() != nullptr)
|
||||
VkRenderPassManager::EndRenderPass(frame.commandBuffer);
|
||||
VkMemoryBarrier barrier{VK_STRUCTURE_TYPE_MEMORY_BARRIER};
|
||||
barrier.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT;
|
||||
barrier.dstAccessMask = VK_ACCESS_INDIRECT_COMMAND_READ_BIT;
|
||||
vkCmdPipelineBarrier(frame.commandBuffer, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
|
||||
VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT, 0, 1, &barrier, 0, nullptr, 0, nullptr);
|
||||
if (MG_Util::PipeStats::Enabled())
|
||||
MG_Util::PipeStats::AddCalls(MG_Util::PipeStats::CallClass::WireIndirectBarriers, 1);
|
||||
}
|
||||
const auto program = WireProgramSource(state.DispatchProgram);
|
||||
if (!program.GetLinkStatus() || !program.GetSpirvStatus()) {
|
||||
MGL_WIRE_DECLINE_AT(ComputeProgramLinkOrSpirv, "the compute program is not linked or carries no SPIR-V");
|
||||
return;
|
||||
}
|
||||
const auto& programObj = m_programFactory->GetOrCreateProgram(program, {});
|
||||
if (!m_uniformManager->PrepareWireTextureResources(program, programObj)) {
|
||||
MGL_WIRE_DECLINE_AT(ComputeTextureResourcesUnprepared, "a sampled/storage image could not be made ready for the dispatch");
|
||||
return;
|
||||
}
|
||||
const auto pipeline = GetOrCreateComputePipeline(programObj);
|
||||
if (!pipeline) {
|
||||
MGL_WIRE_DECLINE_AT(ComputePipelineUnavailable, "no compute pipeline could be created for this dispatch");
|
||||
return;
|
||||
}
|
||||
// PrepareWireTextureResources may have flushed and begun a new recording.
|
||||
auto& dispatchFrame = m_frameContext.GetCurrent();
|
||||
if (!dispatchFrame.isCommandRecording) m_frameContext.BeginCommandRecording();
|
||||
if (!m_uniformManager->BindProgramUniformBuffers(dispatchFrame.commandBuffer, program, programObj,
|
||||
m_frameContext.GetCurrentFrameIndex(), VK_PIPELINE_BIND_POINT_COMPUTE)) {
|
||||
MGL_WIRE_DECLINE_AT(ComputeUniformBufferBinding, "the dispatch's uniform/storage bindings could not be bound");
|
||||
return;
|
||||
}
|
||||
vkCmdBindPipeline(dispatchFrame.commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline);
|
||||
vkCmdDispatchIndirect(dispatchFrame.commandBuffer, parameters.buffer,
|
||||
parameters.offset + static_cast<VkDeviceSize>(offset));
|
||||
if (MG_Util::PipeStats::Enabled())
|
||||
MG_Util::PipeStats::AddCalls(MG_Util::PipeStats::CallClass::WireIndirectNativeDispatches, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,16 +0,0 @@
|
||||
#version 450
|
||||
// SAMPLE ZERO, and it is not an approximation: VK_RESOLVE_MODE_SAMPLE_ZERO_BIT is the mode the
|
||||
// VK_KHR_depth_stencil_resolve arm asks for, and GL 4.6 core 18.3.1 says a depth resolve picks
|
||||
// a value "in an implementation-dependent manner where the result will be between the minimum
|
||||
// and maximum depth values in the pixel" - sample 0 is one of the samples, so it qualifies, and
|
||||
// taking the same sample as the extension arm is what makes the two arms interchangeable on one
|
||||
// device.
|
||||
//
|
||||
// AVERAGING WOULD NOT BE: a mean of four depths is a surface that exists nowhere, and GL's
|
||||
// bound is on the per-pixel min/max, which a mean satisfies but a shadow comparison against it
|
||||
// does not survive.
|
||||
layout(set = 0, binding = 0) uniform sampler2DMS sourceImage;
|
||||
|
||||
void main() {
|
||||
gl_FragDepth = texelFetch(sourceImage, ivec2(gl_FragCoord.xy), 0).r;
|
||||
}
|
||||
@@ -1,167 +0,0 @@
|
||||
// Included by VulkanRenderer.cpp inside the backend namespace, after WireDepthMipmap.inc.
|
||||
// The native multisample depth/stencil resolve owns no frontend object and never invokes the
|
||||
// GL shader compiler.
|
||||
//
|
||||
// WHY THIS FILE EXISTS. vkCmdResolveImage is COLOUR ONLY. The one way Vulkan resolves a depth
|
||||
// or stencil aspect without a shader is a render pass with a depth/stencil resolve attachment,
|
||||
// which needs VK_KHR_create_renderpass2 and VK_KHR_depth_stencil_resolve - and until this
|
||||
// package a device without either killed the session at
|
||||
// `Magma:multisample-depth-resolve-capability` the first time an application resolved a
|
||||
// multisample depth buffer, which is what glBlitFramebuffer(GL_DEPTH_BUFFER_BIT) from a
|
||||
// multisampled read framebuffer IS. CONTRACT-P7 §3.2's `multisample-blit-aspect` row names both
|
||||
// arms; this is the second one.
|
||||
//
|
||||
// SAMPLE ZERO IN BOTH ARMS. The extension arm asks for VK_RESOLVE_MODE_SAMPLE_ZERO_BIT, so the
|
||||
// shader arm fetches sample 0 - not an average. Two arms that answer differently on two devices
|
||||
// would make "the wire arm is observably the monolith's" untestable, and GL 4.6 core 18.3.1
|
||||
// requires a SELECTED sample for stencil anyway.
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// The pass's modules, layouts, render passes and pipeline, and the draw it records, are
|
||||
// WireDepthResolveProbe.cpp's (g5-msprobe): the multisample depth/stencil resolve probe runs
|
||||
// this exact arm as its CONTROL, so it is defined once for both.
|
||||
struct VulkanRenderer::WireMultisampleResolveResources {
|
||||
struct Target {
|
||||
VkFormat format = VK_FORMAT_UNDEFINED;
|
||||
VkImageAspectFlags aspect = 0; // the ONE aspect this pipeline writes
|
||||
VkRenderPass renderPass = VK_NULL_HANDLE;
|
||||
VkPipeline pipeline = VK_NULL_HANDLE;
|
||||
};
|
||||
WireShaderResolveKit kit;
|
||||
Vector<Target> targets;
|
||||
};
|
||||
|
||||
void VulkanRenderer::DestroyWireMultisampleResolveResources() {
|
||||
if (!m_wireMultisampleResolveResources) return;
|
||||
// Shutdown calls this after vkDeviceWaitIdle and after all per-submit descriptor
|
||||
// pools/framebuffers/views have been collected.
|
||||
auto& cache = *m_wireMultisampleResolveResources;
|
||||
for (const auto& target : cache.targets) {
|
||||
vkDestroyPipeline(m_device, target.pipeline, nullptr);
|
||||
vkDestroyRenderPass(m_device, target.renderPass, nullptr);
|
||||
}
|
||||
DestroyWireShaderResolveKit(m_device, cache.kit);
|
||||
delete m_wireMultisampleResolveResources;
|
||||
m_wireMultisampleResolveResources = nullptr;
|
||||
}
|
||||
|
||||
// ONE ASPECT, source -> resolved, both 2D images of the same format and extent, the source
|
||||
// multisampled and the destination not. Returns false for every shape it cannot express,
|
||||
// which the caller turns into a decline; it never ends the session.
|
||||
Bool VulkanRenderer::ResolveWireDepthStencilWithShader(WireImage source, WireImage resolved,
|
||||
VkImageAspectFlags aspect, GLint sx0, GLint sy0, Uint32 width, Uint32 height) {
|
||||
if (!source.image || !resolved.image || !width || !height) return false;
|
||||
if (aspect != VK_IMAGE_ASPECT_DEPTH_BIT && aspect != VK_IMAGE_ASPECT_STENCIL_BIT) return false;
|
||||
// A fragment shader cannot write the stencil aspect at all without
|
||||
// VK_EXT_shader_stencil_export. §3.2: decline stencil-only rather than produce a level
|
||||
// whose stencil is whatever the DONT_CARE left there.
|
||||
if (aspect == VK_IMAGE_ASPECT_STENCIL_BIT && !m_wireShaderStencilExport) return false;
|
||||
if (source.samples == VK_SAMPLE_COUNT_1_BIT) return false;
|
||||
if (source.format != resolved.format) return false;
|
||||
// SAMPLED is asked for by every attachment VkTextureManager creates; a device that
|
||||
// declined it would make the descriptor write below undefined, not failed.
|
||||
if (!(source.usageFlags & VK_IMAGE_USAGE_SAMPLED_BIT)) return false;
|
||||
VkFormatProperties properties{};
|
||||
vkGetPhysicalDeviceFormatProperties(m_physicalDevice.handle, source.format, &properties);
|
||||
const VkFormatFeatureFlags required = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT |
|
||||
VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
||||
if ((properties.optimalTilingFeatures & required) != required) return false;
|
||||
|
||||
const VkImageAspectFlags formatAspects = WireDepthStencilFormatAspects(source.format);
|
||||
if (!(formatAspects & aspect)) return false;
|
||||
|
||||
if (!m_wireMultisampleResolveResources) {
|
||||
m_wireMultisampleResolveResources = new WireMultisampleResolveResources;
|
||||
VK_VERIFY(CreateWireShaderResolveKit(m_device, m_wireShaderStencilExport,
|
||||
m_wireMultisampleResolveResources->kit));
|
||||
}
|
||||
auto& cache = *m_wireMultisampleResolveResources;
|
||||
const VkShaderModule fragment = aspect == VK_IMAGE_ASPECT_STENCIL_BIT ? cache.kit.stencilFragment
|
||||
: cache.kit.depthFragment;
|
||||
if (fragment == VK_NULL_HANDLE) return false;
|
||||
|
||||
WireMultisampleResolveResources::Target* target = nullptr;
|
||||
for (auto& entry : cache.targets)
|
||||
if (entry.format == resolved.format && entry.aspect == aspect) { target = &entry; break; }
|
||||
if (!target) {
|
||||
cache.targets.emplace_back();
|
||||
target = &cache.targets.back();
|
||||
target->format = resolved.format;
|
||||
target->aspect = aspect;
|
||||
VK_VERIFY(CreateWireShaderResolveRenderPass(m_device, resolved.format, &target->renderPass));
|
||||
if (CreateWireShaderResolvePipeline(m_device, cache.kit, target->renderPass, aspect,
|
||||
&target->pipeline) != VK_SUCCESS) {
|
||||
vkDestroyRenderPass(m_device, target->renderPass, nullptr);
|
||||
cache.targets.pop_back();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
m_textureManager->FlushPendingUploads();
|
||||
TransitionWireImage(source, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
||||
TransitionWireImage(resolved, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
||||
|
||||
// ONE ASPECT on the sampled view: a depth/stencil image can only be SAMPLED through a
|
||||
// view that names exactly one of its aspects, which is also what makes the stencil half
|
||||
// a usampler2DMS and the depth half a sampler2DMS.
|
||||
const VkImageViewCreateInfo sourceViewInfo =
|
||||
WireDepthStencilViewInfo(source.image, source.format, aspect, source.level, source.layer);
|
||||
VkImageView sourceView = VK_NULL_HANDLE;
|
||||
VK_VERIFY(vkCreateImageView(m_device, &sourceViewInfo, nullptr, &sourceView));
|
||||
// BOTH aspects on the attachment view: a depth/stencil ATTACHMENT names every aspect
|
||||
// its format has, whichever one the pipeline writes.
|
||||
const VkImageViewCreateInfo targetViewInfo =
|
||||
WireDepthStencilViewInfo(resolved.image, resolved.format, formatAspects, 0, 0);
|
||||
VkImageView targetView = VK_NULL_HANDLE;
|
||||
VK_VERIFY(vkCreateImageView(m_device, &targetViewInfo, nullptr, &targetView));
|
||||
|
||||
VkFramebufferCreateInfo framebufferInfo{VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO};
|
||||
framebufferInfo.renderPass = target->renderPass;
|
||||
framebufferInfo.attachmentCount = 1;
|
||||
framebufferInfo.pAttachments = &targetView;
|
||||
framebufferInfo.width = resolved.extent.width;
|
||||
framebufferInfo.height = resolved.extent.height;
|
||||
framebufferInfo.layers = 1;
|
||||
VkFramebuffer framebuffer = VK_NULL_HANDLE;
|
||||
VK_VERIFY(vkCreateFramebuffer(m_device, &framebufferInfo, nullptr, &framebuffer));
|
||||
|
||||
// Each in-flight pass owns its descriptor set, for the colour blit's reason: updating a
|
||||
// cached set would rewrite the source view of an older queued pass.
|
||||
VkDescriptorPool descriptorPool = VK_NULL_HANDLE;
|
||||
VkDescriptorSet descriptorSet = VK_NULL_HANDLE;
|
||||
const VkDescriptorPoolSize poolSize{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1};
|
||||
VkDescriptorPoolCreateInfo pool{VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO};
|
||||
pool.maxSets = 1;
|
||||
pool.poolSizeCount = 1;
|
||||
pool.pPoolSizes = &poolSize;
|
||||
VK_VERIFY(vkCreateDescriptorPool(m_device, &pool, nullptr, &descriptorPool));
|
||||
VkDescriptorSetAllocateInfo alloc{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO};
|
||||
alloc.descriptorPool = descriptorPool;
|
||||
alloc.descriptorSetCount = 1;
|
||||
alloc.pSetLayouts = &cache.kit.descriptorLayout;
|
||||
VK_VERIFY(vkAllocateDescriptorSets(m_device, &alloc, &descriptorSet));
|
||||
const VkDescriptorImageInfo sampled{cache.kit.nearest, sourceView,
|
||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL};
|
||||
VkWriteDescriptorSet write{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET};
|
||||
write.dstSet = descriptorSet;
|
||||
write.dstBinding = 0;
|
||||
write.descriptorCount = 1;
|
||||
write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||
write.pImageInfo = &sampled;
|
||||
vkUpdateDescriptorSets(m_device, 1, &write, 0, nullptr);
|
||||
|
||||
auto& frame = m_frameContext.GetCurrent();
|
||||
RecordWireShaderResolveDraw(frame.commandBuffer, cache.kit, target->renderPass, target->pipeline, framebuffer,
|
||||
descriptorSet, resolved.extent, {{sx0, sy0}, {width, height}});
|
||||
ResetDynamicStateShadow();
|
||||
InvalidatePipelineMemo();
|
||||
// This native pass binds its own set/layout without going through the application's
|
||||
// descriptor binder. Its next fast path must rebind.
|
||||
if (m_uniformManager) m_uniformManager->OnCommandBufferBoundary();
|
||||
WireRetiredObjects retired{};
|
||||
retired.framebuffers.push_back(framebuffer);
|
||||
retired.imageViews = {sourceView, targetView};
|
||||
retired.descriptorPools.push_back(descriptorPool);
|
||||
RetireWireObjects(Move(retired));
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
@@ -1,18 +0,0 @@
|
||||
#version 450
|
||||
// Native Vulkan multisample depth/stencil resolve: no GL program, registry entry, or runtime
|
||||
// transpilation.
|
||||
//
|
||||
// THIS STAGE CARRIES NOTHING, and that is the whole design. The scratch this pass writes has
|
||||
// the SAME extent and the SAME coordinate space as the multisample source it reads - both are
|
||||
// native images, neither is flipped against the other - so the fragment stage can take its
|
||||
// coordinate straight out of gl_FragCoord and needs no varying, no push constant and no rect.
|
||||
// The requested rectangle is expressed by the scissor instead, which is also what the
|
||||
// VK_KHR_depth_stencil_resolve arm next door expresses with its renderArea.
|
||||
//
|
||||
// An oversized triangle rather than WireDepthMipmap.vert's quad: there is no destination
|
||||
// rectangle to clip to here, only the scissor, and a triangle rasterizes the same area with
|
||||
// one fewer primitive and no shared edge.
|
||||
void main() {
|
||||
const vec2 corners[3] = vec2[](vec2(-1.0, -1.0), vec2(3.0, -1.0), vec2(-1.0, 3.0));
|
||||
gl_Position = vec4(corners[gl_VertexIndex], 0.0, 1.0);
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
// Generated from WireMultisampleResolve.vert / WireMultisampleDepthResolve.frag /
|
||||
// WireMultisampleStencilResolve.frag by scripts/bake_internal_shaders.py, which runs MG_Test's
|
||||
// BakedInternalShadersTest with the IN-TREE glslang and splices the words it emits into the
|
||||
// arrays below. Do not edit the words by hand: MOBILEGL_BAKED_INTERNAL_SHADERS (the same test,
|
||||
// run as a gate) recompiles every source in its table and reds on the first word that
|
||||
// disagrees.
|
||||
#pragma once
|
||||
|
||||
static constexpr Uint32 kWireMultisampleResolveVertexSpirv[] = {
|
||||
0x07230203u, 0x00010000u, 0x0008000bu, 0x00000028u, 0x00000000u, 0x00020011u, 0x00000001u, 0x0006000bu,
|
||||
0x00000001u, 0x4c534c47u, 0x6474732eu, 0x3035342eu, 0x00000000u, 0x0003000eu, 0x00000000u, 0x00000001u,
|
||||
0x0007000fu, 0x00000000u, 0x00000004u, 0x6e69616du, 0x00000000u, 0x0000000du, 0x0000001au, 0x00030003u,
|
||||
0x00000002u, 0x000001c2u, 0x00040005u, 0x00000004u, 0x6e69616du, 0x00000000u, 0x00060005u, 0x0000000bu,
|
||||
0x505f6c67u, 0x65567265u, 0x78657472u, 0x00000000u, 0x00060006u, 0x0000000bu, 0x00000000u, 0x505f6c67u,
|
||||
0x7469736fu, 0x006e6f69u, 0x00070006u, 0x0000000bu, 0x00000001u, 0x505f6c67u, 0x746e696fu, 0x657a6953u,
|
||||
0x00000000u, 0x00070006u, 0x0000000bu, 0x00000002u, 0x435f6c67u, 0x4470696cu, 0x61747369u, 0x0065636eu,
|
||||
0x00070006u, 0x0000000bu, 0x00000003u, 0x435f6c67u, 0x446c6c75u, 0x61747369u, 0x0065636eu, 0x00030005u,
|
||||
0x0000000du, 0x00000000u, 0x00060005u, 0x0000001au, 0x565f6c67u, 0x65747265u, 0x646e4978u, 0x00007865u,
|
||||
0x00050005u, 0x0000001du, 0x65646e69u, 0x6c626178u, 0x00000065u, 0x00030047u, 0x0000000bu, 0x00000002u,
|
||||
0x00050048u, 0x0000000bu, 0x00000000u, 0x0000000bu, 0x00000000u, 0x00050048u, 0x0000000bu, 0x00000001u,
|
||||
0x0000000bu, 0x00000001u, 0x00050048u, 0x0000000bu, 0x00000002u, 0x0000000bu, 0x00000003u, 0x00050048u,
|
||||
0x0000000bu, 0x00000003u, 0x0000000bu, 0x00000004u, 0x00040047u, 0x0000001au, 0x0000000bu, 0x0000002au,
|
||||
0x00020013u, 0x00000002u, 0x00030021u, 0x00000003u, 0x00000002u, 0x00030016u, 0x00000006u, 0x00000020u,
|
||||
0x00040017u, 0x00000007u, 0x00000006u, 0x00000004u, 0x00040015u, 0x00000008u, 0x00000020u, 0x00000000u,
|
||||
0x0004002bu, 0x00000008u, 0x00000009u, 0x00000001u, 0x0004001cu, 0x0000000au, 0x00000006u, 0x00000009u,
|
||||
0x0006001eu, 0x0000000bu, 0x00000007u, 0x00000006u, 0x0000000au, 0x0000000au, 0x00040020u, 0x0000000cu,
|
||||
0x00000003u, 0x0000000bu, 0x0004003bu, 0x0000000cu, 0x0000000du, 0x00000003u, 0x00040015u, 0x0000000eu,
|
||||
0x00000020u, 0x00000001u, 0x0004002bu, 0x0000000eu, 0x0000000fu, 0x00000000u, 0x00040017u, 0x00000010u,
|
||||
0x00000006u, 0x00000002u, 0x0004002bu, 0x00000008u, 0x00000011u, 0x00000003u, 0x0004001cu, 0x00000012u,
|
||||
0x00000010u, 0x00000011u, 0x0004002bu, 0x00000006u, 0x00000013u, 0xbf800000u, 0x0005002cu, 0x00000010u,
|
||||
0x00000014u, 0x00000013u, 0x00000013u, 0x0004002bu, 0x00000006u, 0x00000015u, 0x40400000u, 0x0005002cu,
|
||||
0x00000010u, 0x00000016u, 0x00000015u, 0x00000013u, 0x0005002cu, 0x00000010u, 0x00000017u, 0x00000013u,
|
||||
0x00000015u, 0x0006002cu, 0x00000012u, 0x00000018u, 0x00000014u, 0x00000016u, 0x00000017u, 0x00040020u,
|
||||
0x00000019u, 0x00000001u, 0x0000000eu, 0x0004003bu, 0x00000019u, 0x0000001au, 0x00000001u, 0x00040020u,
|
||||
0x0000001cu, 0x00000007u, 0x00000012u, 0x00040020u, 0x0000001eu, 0x00000007u, 0x00000010u, 0x0004002bu,
|
||||
0x00000006u, 0x00000021u, 0x00000000u, 0x0004002bu, 0x00000006u, 0x00000022u, 0x3f800000u, 0x00040020u,
|
||||
0x00000026u, 0x00000003u, 0x00000007u, 0x00050036u, 0x00000002u, 0x00000004u, 0x00000000u, 0x00000003u,
|
||||
0x000200f8u, 0x00000005u, 0x0004003bu, 0x0000001cu, 0x0000001du, 0x00000007u, 0x0004003du, 0x0000000eu,
|
||||
0x0000001bu, 0x0000001au, 0x0003003eu, 0x0000001du, 0x00000018u, 0x00050041u, 0x0000001eu, 0x0000001fu,
|
||||
0x0000001du, 0x0000001bu, 0x0004003du, 0x00000010u, 0x00000020u, 0x0000001fu, 0x00050051u, 0x00000006u,
|
||||
0x00000023u, 0x00000020u, 0x00000000u, 0x00050051u, 0x00000006u, 0x00000024u, 0x00000020u, 0x00000001u,
|
||||
0x00070050u, 0x00000007u, 0x00000025u, 0x00000023u, 0x00000024u, 0x00000021u, 0x00000022u, 0x00050041u,
|
||||
0x00000026u, 0x00000027u, 0x0000000du, 0x0000000fu, 0x0003003eu, 0x00000027u, 0x00000025u, 0x000100fdu,
|
||||
0x00010038u,
|
||||
};
|
||||
|
||||
static constexpr Uint32 kWireMultisampleDepthResolveFragmentSpirv[] = {
|
||||
0x07230203u, 0x00010000u, 0x0008000bu, 0x0000001du, 0x00000000u, 0x00020011u, 0x00000001u, 0x0006000bu,
|
||||
0x00000001u, 0x4c534c47u, 0x6474732eu, 0x3035342eu, 0x00000000u, 0x0003000eu, 0x00000000u, 0x00000001u,
|
||||
0x0007000fu, 0x00000004u, 0x00000004u, 0x6e69616du, 0x00000000u, 0x00000008u, 0x00000010u, 0x00030010u,
|
||||
0x00000004u, 0x00000007u, 0x00030010u, 0x00000004u, 0x0000000cu, 0x00030003u, 0x00000002u, 0x000001c2u,
|
||||
0x00040005u, 0x00000004u, 0x6e69616du, 0x00000000u, 0x00060005u, 0x00000008u, 0x465f6c67u, 0x44676172u,
|
||||
0x68747065u, 0x00000000u, 0x00050005u, 0x0000000cu, 0x72756f73u, 0x6d496563u, 0x00656761u, 0x00060005u,
|
||||
0x00000010u, 0x465f6c67u, 0x43676172u, 0x64726f6fu, 0x00000000u, 0x00040047u, 0x00000008u, 0x0000000bu,
|
||||
0x00000016u, 0x00040047u, 0x0000000cu, 0x00000021u, 0x00000000u, 0x00040047u, 0x0000000cu, 0x00000022u,
|
||||
0x00000000u, 0x00040047u, 0x00000010u, 0x0000000bu, 0x0000000fu, 0x00020013u, 0x00000002u, 0x00030021u,
|
||||
0x00000003u, 0x00000002u, 0x00030016u, 0x00000006u, 0x00000020u, 0x00040020u, 0x00000007u, 0x00000003u,
|
||||
0x00000006u, 0x0004003bu, 0x00000007u, 0x00000008u, 0x00000003u, 0x00090019u, 0x00000009u, 0x00000006u,
|
||||
0x00000001u, 0x00000000u, 0x00000000u, 0x00000001u, 0x00000001u, 0x00000000u, 0x0003001bu, 0x0000000au,
|
||||
0x00000009u, 0x00040020u, 0x0000000bu, 0x00000000u, 0x0000000au, 0x0004003bu, 0x0000000bu, 0x0000000cu,
|
||||
0x00000000u, 0x00040017u, 0x0000000eu, 0x00000006u, 0x00000004u, 0x00040020u, 0x0000000fu, 0x00000001u,
|
||||
0x0000000eu, 0x0004003bu, 0x0000000fu, 0x00000010u, 0x00000001u, 0x00040017u, 0x00000011u, 0x00000006u,
|
||||
0x00000002u, 0x00040015u, 0x00000014u, 0x00000020u, 0x00000001u, 0x00040017u, 0x00000015u, 0x00000014u,
|
||||
0x00000002u, 0x0004002bu, 0x00000014u, 0x00000017u, 0x00000000u, 0x00040015u, 0x0000001au, 0x00000020u,
|
||||
0x00000000u, 0x0004002bu, 0x0000001au, 0x0000001bu, 0x00000000u, 0x00050036u, 0x00000002u, 0x00000004u,
|
||||
0x00000000u, 0x00000003u, 0x000200f8u, 0x00000005u, 0x0004003du, 0x0000000au, 0x0000000du, 0x0000000cu,
|
||||
0x0004003du, 0x0000000eu, 0x00000012u, 0x00000010u, 0x0007004fu, 0x00000011u, 0x00000013u, 0x00000012u,
|
||||
0x00000012u, 0x00000000u, 0x00000001u, 0x0004006eu, 0x00000015u, 0x00000016u, 0x00000013u, 0x00040064u,
|
||||
0x00000009u, 0x00000018u, 0x0000000du, 0x0007005fu, 0x0000000eu, 0x00000019u, 0x00000018u, 0x00000016u,
|
||||
0x00000040u, 0x00000017u, 0x00050051u, 0x00000006u, 0x0000001cu, 0x00000019u, 0x00000000u, 0x0003003eu,
|
||||
0x00000008u, 0x0000001cu, 0x000100fdu, 0x00010038u,
|
||||
};
|
||||
|
||||
static constexpr Uint32 kWireMultisampleStencilResolveFragmentSpirv[] = {
|
||||
0x07230203u, 0x00010000u, 0x0008000bu, 0x0000001fu, 0x00000000u, 0x00020011u, 0x00000001u, 0x00020011u,
|
||||
0x00001395u, 0x0009000au, 0x5f565053u, 0x5f545845u, 0x64616873u, 0x735f7265u, 0x636e6574u, 0x655f6c69u,
|
||||
0x726f7078u, 0x00000074u, 0x0006000bu, 0x00000001u, 0x4c534c47u, 0x6474732eu, 0x3035342eu, 0x00000000u,
|
||||
0x0003000eu, 0x00000000u, 0x00000001u, 0x0007000fu, 0x00000004u, 0x00000004u, 0x6e69616du, 0x00000000u,
|
||||
0x00000008u, 0x00000012u, 0x00030010u, 0x00000004u, 0x00000007u, 0x00030010u, 0x00000004u, 0x000013a3u,
|
||||
0x00030003u, 0x00000002u, 0x000001c2u, 0x00090004u, 0x415f4c47u, 0x735f4252u, 0x65646168u, 0x74735f72u,
|
||||
0x69636e65u, 0x78655f6cu, 0x74726f70u, 0x00000000u, 0x00040005u, 0x00000004u, 0x6e69616du, 0x00000000u,
|
||||
0x00080005u, 0x00000008u, 0x465f6c67u, 0x53676172u, 0x636e6574u, 0x65526c69u, 0x42524166u, 0x00000000u,
|
||||
0x00050005u, 0x0000000du, 0x72756f73u, 0x6d496563u, 0x00656761u, 0x00060005u, 0x00000012u, 0x465f6c67u,
|
||||
0x43676172u, 0x64726f6fu, 0x00000000u, 0x00040047u, 0x00000008u, 0x0000000bu, 0x00001396u, 0x00040047u,
|
||||
0x0000000du, 0x00000021u, 0x00000000u, 0x00040047u, 0x0000000du, 0x00000022u, 0x00000000u, 0x00040047u,
|
||||
0x00000012u, 0x0000000bu, 0x0000000fu, 0x00020013u, 0x00000002u, 0x00030021u, 0x00000003u, 0x00000002u,
|
||||
0x00040015u, 0x00000006u, 0x00000020u, 0x00000001u, 0x00040020u, 0x00000007u, 0x00000003u, 0x00000006u,
|
||||
0x0004003bu, 0x00000007u, 0x00000008u, 0x00000003u, 0x00040015u, 0x00000009u, 0x00000020u, 0x00000000u,
|
||||
0x00090019u, 0x0000000au, 0x00000009u, 0x00000001u, 0x00000000u, 0x00000000u, 0x00000001u, 0x00000001u,
|
||||
0x00000000u, 0x0003001bu, 0x0000000bu, 0x0000000au, 0x00040020u, 0x0000000cu, 0x00000000u, 0x0000000bu,
|
||||
0x0004003bu, 0x0000000cu, 0x0000000du, 0x00000000u, 0x00030016u, 0x0000000fu, 0x00000020u, 0x00040017u,
|
||||
0x00000010u, 0x0000000fu, 0x00000004u, 0x00040020u, 0x00000011u, 0x00000001u, 0x00000010u, 0x0004003bu,
|
||||
0x00000011u, 0x00000012u, 0x00000001u, 0x00040017u, 0x00000013u, 0x0000000fu, 0x00000002u, 0x00040017u,
|
||||
0x00000016u, 0x00000006u, 0x00000002u, 0x0004002bu, 0x00000006u, 0x00000018u, 0x00000000u, 0x00040017u,
|
||||
0x0000001au, 0x00000009u, 0x00000004u, 0x0004002bu, 0x00000009u, 0x0000001cu, 0x00000000u, 0x00050036u,
|
||||
0x00000002u, 0x00000004u, 0x00000000u, 0x00000003u, 0x000200f8u, 0x00000005u, 0x0004003du, 0x0000000bu,
|
||||
0x0000000eu, 0x0000000du, 0x0004003du, 0x00000010u, 0x00000014u, 0x00000012u, 0x0007004fu, 0x00000013u,
|
||||
0x00000015u, 0x00000014u, 0x00000014u, 0x00000000u, 0x00000001u, 0x0004006eu, 0x00000016u, 0x00000017u,
|
||||
0x00000015u, 0x00040064u, 0x0000000au, 0x00000019u, 0x0000000eu, 0x0007005fu, 0x0000001au, 0x0000001bu,
|
||||
0x00000019u, 0x00000017u, 0x00000040u, 0x00000018u, 0x00050051u, 0x00000009u, 0x0000001du, 0x0000001bu,
|
||||
0x00000000u, 0x0004007cu, 0x00000006u, 0x0000001eu, 0x0000001du, 0x0003003eu, 0x00000008u, 0x0000001eu,
|
||||
0x000100fdu, 0x00010038u,
|
||||
};
|
||||
@@ -1,19 +0,0 @@
|
||||
#version 450
|
||||
// The stencil half, and it needs an extension to exist at all: a fragment shader cannot write
|
||||
// the stencil aspect without VK_EXT_shader_stencil_export (SPV_EXT_shader_stencil_export, which
|
||||
// this `#extension` line is how glslang is asked for). CONTRACT-P7 §3.2 says so and says what
|
||||
// happens otherwise - a stencil-only resolve DECLINES on a device without it, because there is
|
||||
// no second way to put a value in the stencil aspect from a pass.
|
||||
//
|
||||
// usampler2DMS and not sampler2DMS: the stencil aspect of a depth/stencil image is an unsigned
|
||||
// integer, and a float view of it would round the index.
|
||||
//
|
||||
// Sample zero, for WireMultisampleDepthResolve.frag's reason, and GL is stricter here: 18.3.1
|
||||
// says integer and stencil resolves SELECT one sample rather than combining them, so sample 0
|
||||
// is the answer and not merely an acceptable one.
|
||||
#extension GL_ARB_shader_stencil_export : require
|
||||
layout(set = 0, binding = 0) uniform usampler2DMS sourceImage;
|
||||
|
||||
void main() {
|
||||
gl_FragStencilRefARB = int(texelFetch(sourceImage, ivec2(gl_FragCoord.xy), 0).r);
|
||||
}
|
||||
@@ -13,28 +13,9 @@
|
||||
image = {};
|
||||
}
|
||||
|
||||
void UniformManager::SetWireInvalidStorageImageArm(Bool deviceNullDescriptor) {
|
||||
const char* forced = std::getenv("MGITEST_MAGMA_FORCE_PRIVATE_IMAGE_PLACEHOLDER");
|
||||
const Bool forcePrivate = forced != nullptr && std::strcmp(forced, "1") == 0;
|
||||
m_wireInvalidStorageImagesBindNull = deviceNullDescriptor && !forcePrivate;
|
||||
MGLOG_I("Magma wire: an invalid or unbound image unit binds %s (VK_EXT_robustness2 nullDescriptor %s%s)",
|
||||
m_wireInvalidStorageImagesBindNull ? "a NULL storage descriptor"
|
||||
: "a placeholder private to its unit",
|
||||
deviceNullDescriptor ? "enabled" : "unavailable",
|
||||
deviceNullDescriptor && forcePrivate ? "; MGITEST_MAGMA_FORCE_PRIVATE_IMAGE_PLACEHOLDER=1" : "");
|
||||
}
|
||||
|
||||
Bool UniformManager::ResolveWirePlaceholderImage(VkCommandBuffer commands, const MagmaProgramSource& program,
|
||||
const ProgramFactory::VkProgramObject& programObj, Uint32 binding, Bool storage,
|
||||
VkDescriptorImageInfo& out, VkFormat boundStorageFormat, Uint32 unit) const {
|
||||
// GL 4.6 core 8.26, codex closeout finding 2: every access through an invalid image unit
|
||||
// is invalid - a load returns zero, a store and an atomic are discarded. A NULL storage
|
||||
// descriptor (VK_EXT_robustness2 nullDescriptor) is exactly that, for any target, format
|
||||
// and sample count, so nothing below is needed.
|
||||
if (storage && m_wireInvalidStorageImagesBindNull) {
|
||||
out = {VK_NULL_HANDLE, VK_NULL_HANDLE, VK_IMAGE_LAYOUT_GENERAL};
|
||||
return true;
|
||||
}
|
||||
VkDescriptorImageInfo& out) const {
|
||||
if (binding >= programObj.samplerTextureTargetByBinding.size() ||
|
||||
binding >= programObj.samplerNumericDomainByBinding.size()) return false;
|
||||
const auto target = programObj.samplerTextureTargetByBinding[binding];
|
||||
@@ -55,20 +36,6 @@
|
||||
if (storage) {
|
||||
if (binding >= programObj.storageImageFormatByBinding.size()) return false;
|
||||
format = programObj.storageImageFormatByBinding[binding];
|
||||
// A formatless declaration of an INVALID binding (a unit whose texture lacks the
|
||||
// named level or layer) takes the format the application bound, where the device can
|
||||
// store to it and it is in the shader's numeric class. The R32 default expands a load
|
||||
// to (0, 0, 0, 1); a four-channel carrier cleared to zero reads (0, 0, 0, 0), which
|
||||
// is what KHR-GL46.shader_image_load_store.incomplete_textures compares against.
|
||||
if (format == VK_FORMAT_UNDEFINED && boundStorageFormat != VK_FORMAT_UNDEFINED) {
|
||||
const Bool classMatches = domain == SamplerNumericDomain::Float
|
||||
? !vkuFormatIsUINT(boundStorageFormat) && !vkuFormatIsSINT(boundStorageFormat)
|
||||
: domain == SamplerNumericDomain::SignedInteger ? vkuFormatIsSINT(boundStorageFormat)
|
||||
: domain == SamplerNumericDomain::UnsignedInteger && vkuFormatIsUINT(boundStorageFormat);
|
||||
VkFormatProperties properties{};
|
||||
if (classMatches) vkGetPhysicalDeviceFormatProperties(m_physicalDevice, boundStorageFormat, &properties);
|
||||
if (properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) format = boundStorageFormat;
|
||||
}
|
||||
if (format == VK_FORMAT_UNDEFINED) format = PlaceholderFormatForNumericDomain(domain);
|
||||
} else if (shadow) format = VK_FORMAT_D16_UNORM;
|
||||
else if (domain == SamplerNumericDomain::Float) format = VK_FORMAT_R8G8B8A8_UNORM;
|
||||
@@ -93,22 +60,8 @@
|
||||
break;
|
||||
default: return false;
|
||||
}
|
||||
// A STORAGE placeholder is private to its unit (per shape). Shared by shape alone, a store
|
||||
// through invalid unit A was visible, after a barrier, to a load through invalid unit B of
|
||||
// the same shape - one Vulkan image behind both (codex closeout finding 2). The clear
|
||||
// below still runs before each use; what a private image cannot hide is the SAME unit's
|
||||
// own store to its own later load inside one pass (CONTRACT-P7 §12). Not per binding: GL
|
||||
// aliases per unit, and a (binding, unit) key only multiplied allocations. Past
|
||||
// kWirePrivateStoragePlaceholderCap a new (shape, unit) shares its shape's (WirePlaceholderKey.h).
|
||||
const Uint64 shape = static_cast<Uint32>(format) | (static_cast<Uint64>(target) << 32) |
|
||||
(static_cast<Uint64>(storage) << 48) | (static_cast<Uint64>(shadow) << 49);
|
||||
const WirePlaceholderKey key = ChooseWirePlaceholderKey(shape, storage, unit, m_wirePrivateStoragePlaceholders,
|
||||
[this](const WirePlaceholderKey& candidate) { return m_wirePlaceholderImages.count(candidate) != 0; });
|
||||
if (storage && unit != WirePlaceholderKey::kShared && key.unit == WirePlaceholderKey::kShared) {
|
||||
MGLOG_W_ONCE("Magma wire: %zu image-unit-private placeholders exist (the cap); a further invalid or "
|
||||
"unbound unit shares its shape's placeholder, so two such units of one shape can alias",
|
||||
static_cast<size_t>(m_wirePrivateStoragePlaceholders));
|
||||
}
|
||||
const Uint64 key = static_cast<Uint32>(format) | (static_cast<Uint64>(target) << 32) |
|
||||
(static_cast<Uint64>(storage) << 48) | (static_cast<Uint64>(shadow) << 49);
|
||||
auto found = m_wirePlaceholderImages.find(key);
|
||||
if (found == m_wirePlaceholderImages.end()) {
|
||||
WirePlaceholderImage image{};
|
||||
@@ -198,12 +151,11 @@
|
||||
if (vkCreateFramebuffer(m_device, &framebuffer, nullptr, &image.clearFramebuffer) != VK_SUCCESS) return fail();
|
||||
}
|
||||
found = m_wirePlaceholderImages.emplace(key, image).first;
|
||||
if (key.unit != WirePlaceholderKey::kShared) ++m_wirePrivateStoragePlaceholders;
|
||||
}
|
||||
auto& image = found->second;
|
||||
// Sampled incomplete textures remain immutable opaque black. A storage
|
||||
// placeholder is reset before each use, so a prior discarded store cannot
|
||||
// leak into a later pass's loads through the same unit.
|
||||
// leak into an unrelated invocation's unbound image loads.
|
||||
if (storage || image.layout == VK_IMAGE_LAYOUT_UNDEFINED) {
|
||||
VkClearValue clear{};
|
||||
if (!storage) {
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Backend/DirectVulkan/Renderer/WirePlaceholderKey.h
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
#pragma once
|
||||
|
||||
#include <Includes.h>
|
||||
|
||||
// The pure half of UniformManager's wire placeholder cache (WirePlaceholderImages.inc): WHICH
|
||||
// placeholder a binding with no usable image takes. A unit test pins it
|
||||
// (MG_Test/Pipeline/PipelineQuirkTest.cpp); the Vulkan half that makes the image stays in the .inc.
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
#include <MG_Pipe/MGPipeTypes.h>
|
||||
|
||||
namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// The placeholder's SHAPE (format, target, storage, shadow) and, for a STORAGE placeholder on
|
||||
// the arm without a null descriptor, the image UNIT it is private to. GL aliases per UNIT, so the
|
||||
// unit is the whole of the no-alias guarantee (codex closeout finding 2): two bindings that name
|
||||
// one unit are one GL image, and keying them apart as well only multiplied allocations (cf-magma
|
||||
// critic). A sampled placeholder is never written, so it stays shared: its unit is kShared.
|
||||
struct WirePlaceholderKey {
|
||||
static constexpr Uint32 kShared = ~0u;
|
||||
Uint64 shape = 0;
|
||||
Uint32 unit = kShared;
|
||||
Bool operator==(const WirePlaceholderKey& other) const { return shape == other.shape && unit == other.unit; }
|
||||
};
|
||||
|
||||
struct WirePlaceholderKeyHash {
|
||||
SizeT operator()(const WirePlaceholderKey& key) const {
|
||||
Uint64 h = key.shape * 0x9E3779B97F4A7C15ull;
|
||||
h ^= static_cast<Uint64>(key.unit) + 0x9E3779B97F4A7C15ull + (h << 6) + (h >> 2);
|
||||
return static_cast<SizeT>(h);
|
||||
}
|
||||
};
|
||||
|
||||
// Every private placeholder is its own vkCreateImage + vkAllocateMemory, freed only at Shutdown.
|
||||
// (shape, unit) bounds them by shapes x kMGPipeMaxImageUnits, and a peer rotating formats and
|
||||
// targets across the units could still walk that towards maxMemoryAllocationCount (4096 is the
|
||||
// spec minimum). So past this many, a NEW (shape, unit) takes its shape's SHARED placeholder - the
|
||||
// pre-fix aliasing, logged once by the caller - instead of another allocation; a unit that already
|
||||
// has its private placeholder keeps it. Two per unit is far past any real program.
|
||||
inline constexpr SizeT kWirePrivateStoragePlaceholderCap = 2 * static_cast<SizeT>(MG_Pipe::kMGPipeMaxImageUnits);
|
||||
|
||||
// The key a placeholder of `shape` is found or made under. `privateStorage` = a storage binding on
|
||||
// the arm without a null descriptor (with one, the caller never gets here); `unit` = its image
|
||||
// unit; `privateCount` = how many private placeholders exist; `known(key)` = the cache holds `key`.
|
||||
template <typename KnownFn>
|
||||
WirePlaceholderKey ChooseWirePlaceholderKey(Uint64 shape, Bool privateStorage, Uint32 unit, SizeT privateCount,
|
||||
KnownFn&& known) {
|
||||
WirePlaceholderKey key;
|
||||
key.shape = shape;
|
||||
if (!privateStorage || unit == WirePlaceholderKey::kShared) return key;
|
||||
key.unit = unit;
|
||||
if (privateCount < kWirePrivateStoragePlaceholderCap || known(key)) return key;
|
||||
key.unit = WirePlaceholderKey::kShared;
|
||||
return key;
|
||||
}
|
||||
} // namespace MobileGL::MG_Backend::DirectVulkan
|
||||
#endif
|
||||
@@ -22,9 +22,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
Uint64 CacheVersion = MG_Config::CacheVersion;
|
||||
Uint32 SurfaceWidth = 1;
|
||||
Uint32 SurfaceHeight = 1;
|
||||
// The app's eglSwapInterval; empty until it asks. Window renderers only - see
|
||||
// VulkanRenderer::SetSwapInterval.
|
||||
Optional<Int> SwapInterval;
|
||||
Bool DisablePipelineCache = false;
|
||||
#if MOBILEGL_LOG_ACTIVE_LEVEL <= MOBILEGL_LOG_LEVEL_DEBUG
|
||||
Bool EnableValidationLayers = true;
|
||||
|
||||
@@ -1,737 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Backend/GbmFrameChannel.cpp
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#include "GbmFrameChannel.h"
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED && defined(__ANDROID__)
|
||||
|
||||
#include <android/hardware_buffer.h>
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
#include <poll.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
// WHAT THIS FILE IS WRITTEN AGAINST, AND WHAT HAS NOT BEEN RUN.
|
||||
//
|
||||
// The other end exists and is tested on this machine: MobileGL/MG_Gbm/GbmHostChannel.cpp dials
|
||||
// this socket with SOCK_SEQPACKET, reads one message per frame, computes that message's expected
|
||||
// length from the handle's own two counts, and refuses any other length. Every byte below is
|
||||
// written to that parser. There is no phone attached to the machine this was written on, so the
|
||||
// file is compile-verified for aarch64 Android and nothing more: the first run on a device is what
|
||||
// will say whether the relay in RelayHandle() reads back the handle's bytes exactly as
|
||||
// AHardwareBuffer_sendHandleToUnixSocket writes them, which is why that path is written to
|
||||
// survive both layouts the platform's serializer could have (see the note there).
|
||||
|
||||
namespace MobileGL::MG_Backend {
|
||||
namespace {
|
||||
// THE LAYOUT IS A PROTOCOL, SO ITS SIZES ARE ASSERTED AND NOT ASSUMED. The container
|
||||
// derives the length of a frame message from these three sizes plus the handle's counts,
|
||||
// so a field added here, or the packing attribute dropped, would not be a compile error
|
||||
// over there - it would be every frame skipped with a message about its length.
|
||||
static_assert(sizeof(GbmFrameOffer) == 10 * sizeof(Uint32), "the offer is ten 32 bit fields on the wire");
|
||||
static_assert(sizeof(GbmFrameRelease) == 3 * sizeof(Uint32), "the release is three 32 bit fields on the wire");
|
||||
static_assert(sizeof(GbmNativeHandleHeader) == 3 * sizeof(Int32),
|
||||
"a native handle begins with a version and two counts, on every Android ABI");
|
||||
|
||||
// The container reads one message per frame into a 4 KiB buffer and skips a message that
|
||||
// does not fit in it (GbmHostMessageMax, GbmHostChannel.cpp), so a message larger than this
|
||||
// is refused here rather than built and dropped there.
|
||||
constexpr SizeT kMessageMax = 4096;
|
||||
// The descriptors one handle may carry, which is the container's own cap (GbmHostMaxFds).
|
||||
// Every AHardwareBuffer handle this project has seen carries one - the dma-buf - and both
|
||||
// ends refuse a frame whose handle names more than they can take rather than forward a
|
||||
// truncated list into a buffer of unknown memory.
|
||||
constexpr Int kMaxHandleFds = 8;
|
||||
// How many release messages one call reads before it returns to the frame. A cap and not a
|
||||
// loop to exhaustion: the messages left behind stay in the socket, whose buffer the kernel
|
||||
// bounds, and the next frame drains them.
|
||||
constexpr Int kDrainMax = 64;
|
||||
// HOW MANY DIALERS THE KERNEL MAY HOLD FOR THIS LISTENER. One container is the protocol,
|
||||
// but the queue is not the connection: every compositor that was restarted dials once more,
|
||||
// and a listener that only ever has one slot leaves its queue full for the next one. With
|
||||
// listen(fd, 1) that is exactly what was measured - connect() from the container answered
|
||||
// EAGAIN(11) on four attempts out of four after two restarts, and no dialer reached this
|
||||
// side again for as long as the server lived.
|
||||
constexpr Int kDialerBacklog = 16;
|
||||
// The acceptor's poll timeout. It is a wake-up and not a schedule, so it only has to be
|
||||
// short enough that a container dialling into a socket nothing else touches is taken
|
||||
// promptly; a dialer that arrives while the thread is waiting wakes it at once.
|
||||
constexpr Int kAcceptPollMs = 100;
|
||||
// How long the relay read waits for bytes the send one statement earlier has already put in
|
||||
// the socket. It exists only so that an invariant broken somewhere else cannot park the
|
||||
// apply thread; on a local socketpair the wait is zero.
|
||||
constexpr Int kRelayWaitMs = 2;
|
||||
|
||||
// close() may overwrite the errno a caller is in the middle of reporting, and every caller
|
||||
// here is reporting a failure errno describes.
|
||||
void CloseQuietly(Int fd) {
|
||||
if (fd < 0) return;
|
||||
const Int savedErrno = errno;
|
||||
::close(fd);
|
||||
errno = savedErrno;
|
||||
}
|
||||
}
|
||||
|
||||
GbmFrameChannel::~GbmFrameChannel() { Close(); }
|
||||
|
||||
Bool GbmFrameChannel::Open() {
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
if (m_listen >= 0) return true;
|
||||
|
||||
const char* configured = ::getenv(kGbmFrameSocketEnv);
|
||||
const char* path = (configured != nullptr && configured[0] != 0) ? configured : kGbmFrameSocketPath;
|
||||
constexpr SizeT pathMax = sizeof(((struct sockaddr_un*)nullptr)->sun_path);
|
||||
if (std::strlen(path) >= pathMax) {
|
||||
MGLOG_E_ONCE("gbm frame channel: the container socket path %s does not fit in sun_path (%zu bytes); no "
|
||||
"container can be served",
|
||||
path, pathMax);
|
||||
return false;
|
||||
}
|
||||
|
||||
// SOCK_SEQPACKET because that is what the container dials with (GbmHostChannel::EnsureOpen
|
||||
// asks for exactly this), and a stream listener answers it EPROTOTYPE - the container
|
||||
// prints that as "a socket of a different type". SOCK_NONBLOCK because the accept below
|
||||
// runs on the apply thread and may not wait for a container that is not there; SOCK_CLOEXEC
|
||||
// because every process this server starts would otherwise inherit a socket that receives
|
||||
// the phone's frames.
|
||||
const Int fd = ::socket(AF_UNIX, SOCK_SEQPACKET | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
|
||||
if (fd < 0) {
|
||||
MGLOG_E_ONCE("gbm frame channel: socket(AF_UNIX, SOCK_SEQPACKET): %s; the frames are drawn and presented "
|
||||
"without a container",
|
||||
std::strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
// A node left behind by a server that died is not a reason to refuse a container: bind
|
||||
// would answer EADDRINUSE for a socket nobody is listening on.
|
||||
::unlink(path);
|
||||
|
||||
struct sockaddr_un address = {};
|
||||
address.sun_family = AF_UNIX;
|
||||
// The terminator travels with the name: sun_path is a C string for a pathname socket, and a
|
||||
// name without one is a name the kernel reads past the end of.
|
||||
std::memcpy(address.sun_path, path, std::strlen(path) + 1);
|
||||
if (::bind(fd, reinterpret_cast<struct sockaddr*>(&address), sizeof(address)) != 0) {
|
||||
MGLOG_E_ONCE("gbm frame channel: bind(%s): %s; the frames are drawn and presented without a container",
|
||||
path, std::strerror(errno));
|
||||
CloseQuietly(fd);
|
||||
return false;
|
||||
}
|
||||
// connect() to a pathname socket needs write permission on the node, and the container is
|
||||
// not this process's user, so the umask's usual 0755 would leave it refused for a reason it
|
||||
// could not see. 0666 is what makes the node reachable by the other half of a split run; a
|
||||
// chmod that fails is not fatal, because a peer running as this uid still dials it.
|
||||
if (::chmod(path, 0666) != 0) {
|
||||
MGLOG_W_ONCE("gbm frame channel: chmod(%s, 0666): %s; a container running as another user cannot dial "
|
||||
"this socket",
|
||||
path, std::strerror(errno));
|
||||
}
|
||||
if (::listen(fd, kDialerBacklog) != 0) {
|
||||
MGLOG_E_ONCE("gbm frame channel: listen(%s): %s; the frames are drawn and presented without a container",
|
||||
path, std::strerror(errno));
|
||||
::unlink(path);
|
||||
CloseQuietly(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_listen = fd;
|
||||
m_path = path;
|
||||
// THE ACCEPTOR IS STARTED WITH THE SOCKET AND NOT WITH THE FIRST FRAME. A compositor dials
|
||||
// at its device creation and keeps the connection, so the dial a frame would have answered
|
||||
// has already happened by the time that frame is offered: an accept on the offer path is an
|
||||
// accept that runs after the thing it exists for. The descriptor is copied into the thread
|
||||
// as an argument - it is the one piece of this object the thread reads without the lock,
|
||||
// which is what lets Close() join it before closing that descriptor.
|
||||
m_accepting.store(true, std::memory_order_release);
|
||||
try {
|
||||
m_acceptor = std::thread(&GbmFrameChannel::AcceptLoop, this, fd);
|
||||
} catch (...) {
|
||||
// A thread that cannot be made is a phone that is out of them, not a reason to refuse
|
||||
// the frames the container can still be given one at a time.
|
||||
m_accepting.store(false, std::memory_order_release);
|
||||
MGLOG_W_ONCE("gbm frame channel: the acceptor thread could not be started; a container is only taken in "
|
||||
"when a frame is offered, and one that dials between frames waits for the next one");
|
||||
}
|
||||
MGLOG_I("gbm frame channel: listening on %s for one container (SOCK_SEQPACKET, one message per frame)", path);
|
||||
return true;
|
||||
}
|
||||
|
||||
Bool GbmFrameChannel::EnsureRelay() {
|
||||
if (m_relay[0] >= 0 && m_relay[1] >= 0) return true;
|
||||
// Both ends are dropped before a new pair is made: half a socketpair is a socket with bytes
|
||||
// in it that nothing will ever read, and the next handle read from it would be the tail of
|
||||
// the last one.
|
||||
DropRelay();
|
||||
Int pair[2] = {-1, -1};
|
||||
if (::socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0, pair) != 0) {
|
||||
MGLOG_E_ONCE("gbm frame channel: socketpair for the handle relay: %s; no frame can be offered until one "
|
||||
"can be made",
|
||||
std::strerror(errno));
|
||||
return false;
|
||||
}
|
||||
m_relay[0] = pair[0];
|
||||
m_relay[1] = pair[1];
|
||||
return true;
|
||||
}
|
||||
|
||||
void GbmFrameChannel::DropRelay() {
|
||||
CloseQuietly(m_relay[0]);
|
||||
CloseQuietly(m_relay[1]);
|
||||
m_relay[0] = -1;
|
||||
m_relay[1] = -1;
|
||||
}
|
||||
|
||||
Bool GbmFrameChannel::RelayHandle(struct AHardwareBuffer* buffer, Uint8* payload, SizeT capacity, SizeT& payloadBytes,
|
||||
Int* fds, Int& fdCount) {
|
||||
payloadBytes = 0;
|
||||
fdCount = 0;
|
||||
if (!EnsureRelay()) return false;
|
||||
|
||||
// WHY A FRAME'S HANDLE GOES THROUGH A SOCKETPAIR OF THIS CHANNEL'S OWN.
|
||||
//
|
||||
// The container takes ONE message per frame - the offer, then the handle's counts, then the
|
||||
// arrays those counts describe, with the descriptors in that same message's SCM_RIGHTS
|
||||
// control data - and it refuses a message of any other length. Two sends cannot be one
|
||||
// message on a message-oriented socket, so AHardwareBuffer_sendHandleToUnixSocket, which
|
||||
// sends a handle as a message of its own, is pointed at a socketpair this channel owns, and
|
||||
// what comes out of the other end is both halves of what the container wants: the handle's
|
||||
// own bytes, read here, and its descriptors, as SCM_RIGHTS.
|
||||
//
|
||||
// The alternative does not exist: the NDK's <android/hardware_buffer.h> declares no way to
|
||||
// ask a buffer for its descriptors. AHardwareBuffer_getNativeHandle is a platform API and
|
||||
// is absent from the NDK's copy of that header (checked against NDK 27.3.13750724 in this
|
||||
// tree's build-termux toolchain), so this is the one route from an AHardwareBuffer to a
|
||||
// dma-buf descriptor that an app can take.
|
||||
const Int code = AHardwareBuffer_sendHandleToUnixSocket(buffer, m_relay[0]);
|
||||
if (code != 0) {
|
||||
MGLOG_W_ONCE("gbm frame channel: the frame's handle did not cross the relay socket (rc %d, errno %d); the "
|
||||
"frame is not offered to the container",
|
||||
code, errno);
|
||||
// The relay is dropped rather than kept: a send that failed part way through would
|
||||
// leave bytes that the next handle's read would take for its own header.
|
||||
DropRelay();
|
||||
return false;
|
||||
}
|
||||
|
||||
struct iovec vector = {};
|
||||
vector.iov_base = payload;
|
||||
vector.iov_len = capacity;
|
||||
Uint8 control[CMSG_SPACE(sizeof(Int) * (SizeT)kMaxHandleFds)] = {};
|
||||
struct msghdr message = {};
|
||||
message.msg_iov = &vector;
|
||||
message.msg_iovlen = 1;
|
||||
message.msg_control = control;
|
||||
message.msg_controllen = sizeof(control);
|
||||
|
||||
// MSG_DONTWAIT for the promise at the top of this file, and MSG_CMSG_CLOEXEC so a descriptor
|
||||
// read out of the relay does not survive into a child of this process, which would then hold
|
||||
// the phone's frame until it died.
|
||||
ssize_t got = ::recvmsg(m_relay[1], &message, MSG_DONTWAIT | MSG_CMSG_CLOEXEC);
|
||||
if (got < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
|
||||
struct pollfd waiting = {};
|
||||
waiting.fd = m_relay[1];
|
||||
waiting.events = POLLIN;
|
||||
if (::poll(&waiting, 1, kRelayWaitMs) > 0) {
|
||||
// The kernel rewrites these on every call, so a retry starts from the same state as
|
||||
// the first attempt.
|
||||
message.msg_controllen = sizeof(control);
|
||||
message.msg_flags = 0;
|
||||
got = ::recvmsg(m_relay[1], &message, MSG_DONTWAIT | MSG_CMSG_CLOEXEC);
|
||||
}
|
||||
}
|
||||
if (got < 0) {
|
||||
MGLOG_W_ONCE("gbm frame channel: a relayed handle could not be read back (%d: %s); the frame is not "
|
||||
"offered to the container",
|
||||
errno, std::strerror(errno));
|
||||
DropRelay();
|
||||
return false;
|
||||
}
|
||||
if (got == 0) {
|
||||
// Zero bytes on a connected socket is the end of it. Only this process holds either end
|
||||
// of this socketpair, so this is a bug being reported rather than a peer going away.
|
||||
MGLOG_W_ONCE("gbm frame channel: the handle relay is closed; the frame is not offered to the container");
|
||||
DropRelay();
|
||||
return false;
|
||||
}
|
||||
|
||||
// The descriptors come out of the control data before anything is decided about the
|
||||
// message, because they belong to this process from the moment they were received: a path
|
||||
// that returns without closing them leaks a descriptor per frame.
|
||||
Int collected = 0;
|
||||
for (struct cmsghdr* header = CMSG_FIRSTHDR(&message); header != nullptr;
|
||||
header = CMSG_NXTHDR(&message, header)) {
|
||||
if (header->cmsg_level != SOL_SOCKET || header->cmsg_type != SCM_RIGHTS) continue;
|
||||
const SizeT bytes = (SizeT)header->cmsg_len - CMSG_LEN(0);
|
||||
const Int count = (Int)(bytes / sizeof(Int));
|
||||
const Int* descriptors = reinterpret_cast<const Int*>(CMSG_DATA(header));
|
||||
for (Int i = 0; i < count; ++i) {
|
||||
if (collected < kMaxHandleFds) {
|
||||
fds[collected++] = descriptors[i];
|
||||
} else {
|
||||
// More descriptors than a frame can carry: they are this process's now, so they
|
||||
// are closed here rather than leaked.
|
||||
CloseQuietly(descriptors[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((message.msg_flags & MSG_CTRUNC) != 0) {
|
||||
MGLOG_W_ONCE("gbm frame channel: a frame's control data did not fit in %zu bytes; the frame is not "
|
||||
"offered because its descriptor list is incomplete",
|
||||
sizeof(control));
|
||||
for (Int i = 0; i < collected; ++i) CloseQuietly(fds[i]);
|
||||
DropRelay();
|
||||
return false;
|
||||
}
|
||||
if ((message.msg_flags & MSG_TRUNC) != 0 || (SizeT)got < sizeof(GbmNativeHandleHeader)) {
|
||||
// A message longer than a handle can be, or shorter than the three counts every handle
|
||||
// begins with. Either way it cannot describe a frame, and a relay that has been read
|
||||
// past the end of one message must not carry the next frame's header: it is recreated.
|
||||
MGLOG_W_ONCE("gbm frame channel: a relayed handle is %zd bytes and %s; the frame is not offered", got,
|
||||
((message.msg_flags & MSG_TRUNC) != 0) ? "longer than a handle can be"
|
||||
: "too short to hold its own counts");
|
||||
for (Int i = 0; i < collected; ++i) CloseQuietly(fds[i]);
|
||||
DropRelay();
|
||||
return false;
|
||||
}
|
||||
|
||||
// THE BYTES THAT COME BACK ARE THE HANDLE'S INTEGER ARRAY, NOT A handle AND ITS COUNTS.
|
||||
// Measured on the phone: parsing the front of this payload as {version, numFds, numInts}
|
||||
// produced a NumFds taken from the buffer's own integer data, and every frame was refused
|
||||
// with "its handle carries more descriptors than either end takes" - which is what the
|
||||
// container saw as a connection that was accepted and then closed without a frame. The two
|
||||
// counts are known HERE and are not in those bytes: the descriptors came out of the control
|
||||
// data (collected of them) and the payload is their integer array. So the header is BUILT
|
||||
// rather than copied, and what leaves this process is a real native_handle_t layout -
|
||||
// version, numFds, numInts, then the ints - which is exactly what the container's parser
|
||||
// reads (GbmInternal.h's AHBNativeHandleHeader).
|
||||
if (payloadBytes + sizeof(GbmNativeHandleHeader) > capacity) {
|
||||
MGLOG_W_ONCE("gbm frame channel: a handle's integer array does not fit in a frame message with its "
|
||||
"header; the frame is not offered to the container");
|
||||
for (Int i = 0; i < collected; ++i) CloseQuietly(fds[i]);
|
||||
DropRelay();
|
||||
return false;
|
||||
}
|
||||
std::memmove(payload + sizeof(GbmNativeHandleHeader), payload, payloadBytes);
|
||||
GbmNativeHandleHeader header = {};
|
||||
header.Version = (Int32)sizeof(GbmNativeHandleHeader);
|
||||
header.NumFds = (Int32)collected;
|
||||
header.NumInts = (Int32)(payloadBytes / sizeof(Int32));
|
||||
std::memcpy(payload, &header, sizeof(header));
|
||||
payloadBytes += sizeof(header);
|
||||
fdCount = collected;
|
||||
return true;
|
||||
}
|
||||
|
||||
// The acceptor. It touches the listener - its own copy of the descriptor, which nothing else
|
||||
// closes while this loop runs - and, once per dialer, the channel under its lock.
|
||||
void GbmFrameChannel::AcceptLoop(Int listen) {
|
||||
while (m_accepting.load(std::memory_order_acquire)) {
|
||||
struct pollfd waiting = {};
|
||||
waiting.fd = listen;
|
||||
waiting.events = POLLIN;
|
||||
const Int ready = ::poll(&waiting, 1, kAcceptPollMs);
|
||||
if (ready < 0) {
|
||||
if (errno == EINTR) continue;
|
||||
MGLOG_W_ONCE("gbm frame channel: poll on the listening socket failed (%d: %s); no container can be "
|
||||
"taken in until the socket is opened again",
|
||||
errno, std::strerror(errno));
|
||||
return;
|
||||
}
|
||||
if (ready == 0) continue;
|
||||
// accept4, so the connection is close-on-exec and non-blocking from the moment it
|
||||
// exists: a container that stops reading must not be able to park a send on either
|
||||
// thread.
|
||||
const Int fd = ::accept4(listen, nullptr, nullptr, SOCK_CLOEXEC | SOCK_NONBLOCK);
|
||||
if (fd < 0) {
|
||||
if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK || errno == ECONNABORTED) continue;
|
||||
MGLOG_W_ONCE("gbm frame channel: accept failed (%d: %s); no container can be taken in until the "
|
||||
"socket is opened again",
|
||||
errno, std::strerror(errno));
|
||||
return;
|
||||
}
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
AdoptLocked(fd);
|
||||
}
|
||||
}
|
||||
|
||||
void GbmFrameChannel::AdoptLocked(Int fd) {
|
||||
if (ClientAliveLocked()) {
|
||||
// ONE CLIENT, which is what the protocol is written for, and a dialer that arrives while
|
||||
// a live one is connected is closed rather than left connected - it learns it is not the
|
||||
// one being served instead of holding a connection whose frames nobody reads.
|
||||
CloseQuietly(fd);
|
||||
MGLOG_W_ONCE("gbm frame channel: a second peer dialled %s while a container is connected; it is closed "
|
||||
"and the frames stay with the connected one",
|
||||
m_path.c_str());
|
||||
return;
|
||||
}
|
||||
m_client = fd;
|
||||
MGLOG_I("gbm frame channel: a container is connected on %s; every frame the host offers is sent to it as "
|
||||
"the dma-buf descriptor behind it",
|
||||
m_path.c_str());
|
||||
// AND THE FRAME IT DIALED FOR GOES OUT FROM HERE. A compositor creates its GBM device before
|
||||
// it asks for a surface, so the frame that is the draw target right now was offered before
|
||||
// this connection existed; a container that is not told about it allocates every buffer of
|
||||
// its new swapchain locally, and keeps them for the life of the process.
|
||||
ReofferFrameLocked();
|
||||
}
|
||||
|
||||
Bool GbmFrameChannel::ClientAliveLocked() {
|
||||
if (m_client < 0) return false;
|
||||
Uint8 peek = 0;
|
||||
// MSG_PEEK, because a release waiting in the socket belongs to the render path: this test
|
||||
// only asks whether the peer is still there, and a release it consumed would be a frame the
|
||||
// channel believed was still outstanding.
|
||||
const ssize_t got = ::recv(m_client, &peek, sizeof(peek), MSG_DONTWAIT | MSG_PEEK);
|
||||
if (got > 0) return true;
|
||||
if (got == 0) {
|
||||
// Zero bytes on a connected socket is the end of it, whether the container exited or
|
||||
// the kernel gave up on it. A compositor that crashed and is being restarted is
|
||||
// exactly this, and its successor is the dialer standing right here.
|
||||
MarkDown("the container closed the connection", 0);
|
||||
return false;
|
||||
}
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) return true;
|
||||
MarkDown("recv", errno);
|
||||
return false;
|
||||
}
|
||||
|
||||
void GbmFrameChannel::MarkDown(const char* what, Int error) {
|
||||
if (m_client < 0) return;
|
||||
CloseQuietly(m_client);
|
||||
m_client = -1;
|
||||
if (error != 0) {
|
||||
MGLOG_W("gbm frame channel: the container connection is down: %s failed (%d: %s); the frames are still "
|
||||
"drawn and presented, and the container stops receiving them until it dials again",
|
||||
what, error, std::strerror(error));
|
||||
} else {
|
||||
MGLOG_W("gbm frame channel: the container connection is down: %s; the frames are still drawn and "
|
||||
"presented, and the container stops receiving them until it dials again",
|
||||
what);
|
||||
}
|
||||
}
|
||||
|
||||
Bool GbmFrameChannel::OfferFrame(struct AHardwareBuffer* buffer, const HostFrameOffer& offer) {
|
||||
if (buffer == nullptr) return false;
|
||||
// Open() does nothing once the socket exists, so this is an integer test in the common case.
|
||||
Open();
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
||||
// The releases the container has sent since the last frame, which is also how a container
|
||||
// that died is noticed. Whoever replaced it was taken by the acceptor's own thread the
|
||||
// moment it dialled: that thread is what makes a container's connect() succeed at all.
|
||||
PollLocked();
|
||||
// AND THE FRAME IS REMEMBERED BEFORE IT IS SENT. A container that dials while this call is
|
||||
// running is one the acceptor hands the frame it finds here to, so the two threads must not
|
||||
// be able to disagree about which frame is the one being drawn into.
|
||||
const Uint32 seq = m_nextSeq;
|
||||
RememberFrameLocked(buffer, offer, seq);
|
||||
if (m_client < 0) return false;
|
||||
return SendFrameLocked(buffer, offer, seq, /*counting=*/true);
|
||||
}
|
||||
|
||||
void GbmFrameChannel::RememberFrameLocked(struct AHardwareBuffer* buffer, const HostFrameOffer& offer, Uint32 seq) {
|
||||
if (m_frame == buffer) {
|
||||
// The host redrawing into the buffer it already handed over: the same frame under a new
|
||||
// sequence number. Acquiring it again would be a reference this channel takes and never
|
||||
// gives back.
|
||||
m_frameOffer = offer;
|
||||
m_frameSeq = seq;
|
||||
return;
|
||||
}
|
||||
// The reference is this channel's own, and it is what makes the frame a container that dials
|
||||
// late is owed safe to hold: the backend drops its handle the moment the frame is presented,
|
||||
// and a frame owed to a dialer arriving in the same millisecond may not be memory that has
|
||||
// already gone back to the host's pool.
|
||||
AHardwareBuffer_acquire(buffer);
|
||||
ReleaseFrameLocked();
|
||||
m_frame = buffer;
|
||||
m_frameOffer = offer;
|
||||
m_frameSeq = seq;
|
||||
}
|
||||
|
||||
void GbmFrameChannel::ReleaseFrameLocked() {
|
||||
if (m_frame == nullptr) return;
|
||||
AHardwareBuffer_release(m_frame);
|
||||
m_frame = nullptr;
|
||||
m_frameOffer = {};
|
||||
m_frameSeq = 0;
|
||||
}
|
||||
|
||||
void GbmFrameChannel::DropFrame() {
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
ReleaseFrameLocked();
|
||||
}
|
||||
|
||||
void GbmFrameChannel::ReofferFrameLocked() {
|
||||
if (m_frame == nullptr) return;
|
||||
// The same frame, under the sequence number it was offered with: it IS the frame that is the
|
||||
// draw target now, and a second number for it would be this channel claiming the host had
|
||||
// handed over a frame it never handed over.
|
||||
MGLOG_I("gbm frame channel: a container dialled after frame %u was offered; it is sent that frame, which is "
|
||||
"still the draw target",
|
||||
m_frameSeq);
|
||||
SendFrameLocked(m_frame, m_frameOffer, m_frameSeq, /*counting=*/false);
|
||||
}
|
||||
|
||||
Bool GbmFrameChannel::SendFrameLocked(struct AHardwareBuffer* buffer, const HostFrameOffer& offer, Uint32 seq,
|
||||
Bool counting) {
|
||||
if (m_client < 0) return false;
|
||||
|
||||
Uint8 payload[kMessageMax];
|
||||
SizeT payloadBytes = 0;
|
||||
Int fds[kMaxHandleFds];
|
||||
for (Int i = 0; i < kMaxHandleFds; ++i) fds[i] = -1;
|
||||
Int fdCount = 0;
|
||||
if (!RelayHandle(buffer, payload, sizeof(payload), payloadBytes, fds, fdCount)) return false;
|
||||
|
||||
GbmNativeHandleHeader handle = {};
|
||||
std::memcpy(&handle, payload, sizeof(handle));
|
||||
const SizeT tail = ((SizeT)handle.NumFds + (SizeT)handle.NumInts) * sizeof(Int32);
|
||||
const SizeT messageBytes = sizeof(GbmFrameOffer) + sizeof(GbmNativeHandleHeader) + tail;
|
||||
|
||||
// EVERY REASON THIS CHANNEL REFUSES A FRAME, IN ONE PLACE. Each of them is a frame the
|
||||
// container would refuse anyway - it checks the same counts and the same geometry - and a
|
||||
// frame that is refused here costs nothing: no message, no sequence number, and no entry in
|
||||
// the count of frames waiting to be released.
|
||||
const char* refusal = nullptr;
|
||||
if (offer.Width == 0 || offer.Height == 0 || offer.StrideBytes == 0) {
|
||||
refusal = "the host described it with a width, height or stride of zero, and a buffer with no size is "
|
||||
"not one a compositor can render into";
|
||||
} else if (handle.NumFds < 1) {
|
||||
refusal = "its handle carries no descriptor, and a frame without a dma-buf is not one the container "
|
||||
"can render into";
|
||||
} else if (handle.NumFds > kMaxHandleFds) {
|
||||
refusal = "its handle carries more descriptors than either end takes";
|
||||
} else if (handle.NumInts < 0) {
|
||||
refusal = "its handle claims a negative number of integers";
|
||||
} else if ((SizeT)handle.NumInts > kMessageMax / sizeof(Int32)) {
|
||||
// This is what keeps the message's length arithmetic from wrapping on a 32 bit ABI: a
|
||||
// handle whose integer array alone is longer than a whole message cannot be carried by
|
||||
// this protocol whatever the rest of it says, and the check below would otherwise be
|
||||
// reading a number that had already turned into a small and plausible one.
|
||||
refusal = "its handle names more integers than a whole message could carry";
|
||||
} else if (fdCount < handle.NumFds) {
|
||||
refusal = "fewer descriptors arrived with it than its handle names";
|
||||
} else if (messageBytes > kMessageMax) {
|
||||
refusal = "the message it makes is longer than the container reads";
|
||||
}
|
||||
|
||||
Bool offered = false;
|
||||
if (refusal != nullptr) {
|
||||
// ONCE, not per frame: a host that describes every frame the same broken way must not
|
||||
// turn this into a line per frame on the apply thread.
|
||||
MGLOG_W_ONCE("gbm frame channel: frame %u (%ux%u) is not offered to the container: %s", offer.Index,
|
||||
offer.Width, offer.Height, refusal);
|
||||
} else {
|
||||
// One message, built whole: the offer, then the handle's own three counts, then the two
|
||||
// arrays the counts describe. What came back from the relay is copied in as far as it
|
||||
// goes and the remainder is left zero, because the container checks the LENGTH it
|
||||
// derives from those counts and never reads the arrays themselves - it takes the
|
||||
// descriptors from the control data and hands the first one to GBM. So a handle whose
|
||||
// bytes are shorter than its own counts imply is padded rather than refused, and one
|
||||
// longer than they imply is cut to what the counts say; either way the length the
|
||||
// container computes is the length it receives.
|
||||
Uint8 message[kMessageMax] = {};
|
||||
GbmFrameOffer out = {};
|
||||
out.Magic = kGbmFrameOfferMagic;
|
||||
out.Version = kGbmFrameVersion;
|
||||
out.Seq = seq;
|
||||
out.Index = offer.Index;
|
||||
out.Width = offer.Width;
|
||||
out.Height = offer.Height;
|
||||
out.StrideBytes = offer.StrideBytes;
|
||||
out.Format = offer.Format;
|
||||
out.UsageLo = offer.UsageLo;
|
||||
out.UsageHi = offer.UsageHi;
|
||||
std::memcpy(message, &out, sizeof(out));
|
||||
const SizeT handleBytes = (payloadBytes < sizeof(GbmNativeHandleHeader) + tail)
|
||||
? payloadBytes
|
||||
: (sizeof(GbmNativeHandleHeader) + tail);
|
||||
std::memcpy(message + sizeof(out), payload, handleBytes);
|
||||
|
||||
struct iovec vector = {};
|
||||
vector.iov_base = message;
|
||||
vector.iov_len = messageBytes;
|
||||
Uint8 control[CMSG_SPACE(sizeof(Int) * (SizeT)kMaxHandleFds)] = {};
|
||||
struct msghdr outgoing = {};
|
||||
outgoing.msg_iov = &vector;
|
||||
outgoing.msg_iovlen = 1;
|
||||
outgoing.msg_control = control;
|
||||
outgoing.msg_controllen = CMSG_SPACE(sizeof(Int) * (SizeT)handle.NumFds);
|
||||
struct cmsghdr* rights = CMSG_FIRSTHDR(&outgoing);
|
||||
rights->cmsg_level = SOL_SOCKET;
|
||||
rights->cmsg_type = SCM_RIGHTS;
|
||||
rights->cmsg_len = CMSG_LEN(sizeof(Int) * (SizeT)handle.NumFds);
|
||||
std::memcpy(CMSG_DATA(rights), fds, sizeof(Int) * (SizeT)handle.NumFds);
|
||||
|
||||
// MSG_DONTWAIT for the promise at the top of this file, and MSG_NOSIGNAL because a
|
||||
// server killed by SIGPIPE when the container goes away takes the frames it was drawing
|
||||
// with it. A full socket, a reset peer and a broken pipe all say the same thing here:
|
||||
// this connection can no longer be trusted with a frame, so it is closed and the next
|
||||
// container to dial is served.
|
||||
const ssize_t sent = ::sendmsg(m_client, &outgoing, MSG_DONTWAIT | MSG_NOSIGNAL);
|
||||
if (sent != (ssize_t)messageBytes) {
|
||||
MarkDown("sendmsg", (sent < 0) ? errno : 0);
|
||||
} else {
|
||||
// A frame offered for the first time is the next sequence number and one more frame
|
||||
// outstanding. The same frame sent again to a container that has just dialled is
|
||||
// neither: the host handed over nothing new, and a count of frames waiting to be
|
||||
// released may not be moved by a message that describes one already in it.
|
||||
if (counting) {
|
||||
m_nextSeq = seq + 1;
|
||||
++m_offered;
|
||||
++m_outstanding;
|
||||
}
|
||||
offered = true;
|
||||
// The first offer is the one worth a line, and it carries the host's own numbers:
|
||||
// the format in particular is the field the two ends could disagree about without
|
||||
// either failing, so the value the host actually sends is put where a run on a
|
||||
// device can be read afterwards.
|
||||
MGLOG_I_ONCE("gbm frame channel: the first frame is offered to the container (seq %u index %u %ux%u "
|
||||
"stride %u format 0x%08x)",
|
||||
out.Seq, out.Index, out.Width, out.Height, out.StrideBytes, out.Format);
|
||||
MGLOG_D("gbm frame channel: frame seq=%u index=%u offered (%zu bytes, %d descriptor(s), %llu "
|
||||
"outstanding)",
|
||||
out.Seq, out.Index, messageBytes, handle.NumFds, (unsigned long long)m_outstanding);
|
||||
}
|
||||
}
|
||||
|
||||
// The kernel took its own copies of these when the message was sent, and one that was not
|
||||
// sent is not the container's to hold: every path closes what the relay handed over.
|
||||
for (Int i = 0; i < fdCount; ++i) CloseQuietly(fds[i]);
|
||||
return offered;
|
||||
}
|
||||
|
||||
void GbmFrameChannel::Poll() {
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
PollLocked();
|
||||
}
|
||||
|
||||
void GbmFrameChannel::PollLocked() {
|
||||
if (m_client < 0) return;
|
||||
for (Int drained = 0; drained < kDrainMax; ++drained) {
|
||||
GbmFrameRelease release = {};
|
||||
struct iovec vector = {};
|
||||
vector.iov_base = &release;
|
||||
vector.iov_len = sizeof(release);
|
||||
struct msghdr message = {};
|
||||
message.msg_iov = &vector;
|
||||
message.msg_iovlen = 1;
|
||||
// recvmsg and not recv, for MSG_TRUNC: a message longer than a release can only be a
|
||||
// peer speaking something else, and a release read out of the first twelve bytes of it
|
||||
// would name a frame nobody released.
|
||||
const ssize_t got = ::recvmsg(m_client, &message, MSG_DONTWAIT);
|
||||
if (got < 0) {
|
||||
if (errno == EINTR) continue;
|
||||
// Nothing said, which is what a container that is between frames looks like.
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK) return;
|
||||
MarkDown("recvmsg", errno);
|
||||
return;
|
||||
}
|
||||
if (got == 0) {
|
||||
// Zero bytes on a connected socket is the end of it, whether the container exited or
|
||||
// the kernel gave up on it. Its replacement is taken by the next frame.
|
||||
MarkDown("the container closed the connection", 0);
|
||||
return;
|
||||
}
|
||||
if ((message.msg_flags & MSG_TRUNC) != 0 || got != (ssize_t)sizeof(release)) {
|
||||
// The message is skipped, not the connection: on a message-oriented socket a
|
||||
// message too long for the buffer is consumed whole, so the next one is still a
|
||||
// message rather than the tail of this one.
|
||||
MGLOG_W_ONCE("gbm frame channel: the container sent a message that is not a %zu byte release; it is "
|
||||
"skipped",
|
||||
sizeof(release));
|
||||
continue;
|
||||
}
|
||||
if (release.Magic != kGbmFrameReleaseMagic) {
|
||||
MGLOG_W_ONCE("gbm frame channel: a message from the container begins with 0x%08x rather than 'MGGR'; "
|
||||
"it is skipped",
|
||||
release.Magic);
|
||||
continue;
|
||||
}
|
||||
if (release.Version != kGbmFrameVersion) {
|
||||
// Refused rather than acted on: the version is what says how the rest of the message
|
||||
// is laid out, and a release read with the wrong layout names a frame the container
|
||||
// did not mean.
|
||||
MGLOG_E_ONCE("gbm frame channel: the container speaks protocol version %u where this server speaks "
|
||||
"version %u; its releases are refused until the two agree",
|
||||
release.Version, (Uint32)kGbmFrameVersion);
|
||||
continue;
|
||||
}
|
||||
++m_released;
|
||||
if (m_outstanding > 0) --m_outstanding;
|
||||
// The first release is the only one worth a line: it is the proof that the container
|
||||
// took the descriptor and its compositor retired the frame, where every later one says
|
||||
// the same thing sixty times a second.
|
||||
MGLOG_I_ONCE("gbm frame channel: the container is releasing frames (first: seq %u)", release.Seq);
|
||||
}
|
||||
// Anything past this cap stays in the socket, whose buffer the kernel bounds, and goes out
|
||||
// with the next frame: a peer that says nothing but releases may not spend the apply thread
|
||||
// here.
|
||||
}
|
||||
|
||||
void GbmFrameChannel::Close() {
|
||||
// THE ACCEPTOR IS STOPPED AND JOINED FIRST, and outside the lock. It may be inside that
|
||||
// lock when this is called - a teardown that waited for it while holding it would wait for
|
||||
// ever - and it polls the listening descriptor, which may not be closed under it: the next
|
||||
// open() in this process hands out the descriptor number a moment later, and the thread
|
||||
// would then be polling somebody else's socket.
|
||||
m_accepting.store(false, std::memory_order_release);
|
||||
if (m_acceptor.joinable()) m_acceptor.join();
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
// The frame is this channel's reference and is released with it: the backend has already
|
||||
// dropped its own by the time a teardown here is a teardown of the frame as well.
|
||||
ReleaseFrameLocked();
|
||||
// The connection is closed quietly rather than marked down: this is a teardown, not a
|
||||
// failure, and a warning about it would be noise in a log read for the failures.
|
||||
CloseQuietly(m_client);
|
||||
m_client = -1;
|
||||
DropRelay();
|
||||
if (m_listen >= 0) {
|
||||
// The node is this channel's to remove only while it still IS this channel's socket: a
|
||||
// server that was restarted has bound the same path with a socket of its own, and a
|
||||
// teardown that unlinked it would take the successor's node away with it. st_dev and
|
||||
// st_ino against the listening descriptor is the cheapest way to ask, and a check that
|
||||
// fails only leaves a name behind that the next Open() unlinks anyway.
|
||||
struct stat node = {};
|
||||
struct stat socket = {};
|
||||
if (!m_path.empty() && ::stat(m_path.c_str(), &node) == 0 && ::fstat(m_listen, &socket) == 0 &&
|
||||
node.st_dev == socket.st_dev && node.st_ino == socket.st_ino) {
|
||||
::unlink(m_path.c_str());
|
||||
}
|
||||
CloseQuietly(m_listen);
|
||||
m_listen = -1;
|
||||
}
|
||||
m_path.clear();
|
||||
// The counters are history and stay: a caller that logs Outstanding() after a teardown is
|
||||
// asking what happened, and IsUp() is what answers what is connected now.
|
||||
}
|
||||
}
|
||||
|
||||
#else // !(MOBILEGL_BUILD_DISAGGREGATED && __ANDROID__)
|
||||
|
||||
namespace MobileGL::MG_Backend {
|
||||
// A build that is not the Android render server has no AHardwareBuffer to offer and no
|
||||
// container beside it. The class exists so that callers do not have to be compiled
|
||||
// differently, and every entry point answers the way an absent container does.
|
||||
GbmFrameChannel::~GbmFrameChannel() = default;
|
||||
Bool GbmFrameChannel::Open() { return false; }
|
||||
Bool GbmFrameChannel::OfferFrame(struct AHardwareBuffer*, const HostFrameOffer&) { return false; }
|
||||
void GbmFrameChannel::Poll() {}
|
||||
void GbmFrameChannel::Close() {}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// End of Source File Header
|
||||
@@ -1,281 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Backend/GbmFrameChannel.h
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#pragma once
|
||||
#include <Includes.h>
|
||||
|
||||
#include "HostFrameBridge.h"
|
||||
|
||||
struct AHardwareBuffer;
|
||||
|
||||
namespace MobileGL::MG_Backend {
|
||||
// THE FRAME THE HOST HANDED OVER, HANDED ON TO THE CONTAINER AS A dma-buf.
|
||||
//
|
||||
// The display host owns a pool of AHardwareBuffers: it allocates them, this side imports the
|
||||
// one it offers as a draw target (HostFrameBridge, DirectGLES::HostFrameTarget), and the host
|
||||
// puts it on the glass when this side answers that it is drawn. The Wayland compositor in the
|
||||
// Linux container has to render into THOSE SAME frames - it runs this project's own GBM, and a
|
||||
// gbm_bo_create there answers with the phone's frame instead of a dma-heap allocation of its
|
||||
// own - so every frame this side takes has to reach the container as that frame's dma-buf
|
||||
// descriptor. That, and the release that comes back, is all this channel carries.
|
||||
//
|
||||
// The container's end is MobileGL/MG_Gbm/GbmHostChannel.cpp. It reads exactly the bytes
|
||||
// declared below and answers with a release once its compositor no longer reads the frame.
|
||||
// The three shapes ARE that file's GbmFrameOffer/GbmFrameRelease and GbmInternal.h's
|
||||
// AHBNativeHandleHeader, field for field and packing included. They are restated here rather
|
||||
// than shared because the two ends are built into different libraries from different build
|
||||
// configurations: MG_Backend is the Android render server and never sees libgbm's headers,
|
||||
// while MG_Gbm is built for the container and never sees Android's. A change on either side
|
||||
// is a protocol change, and the magic is what makes a mismatched pair fail loudly instead of
|
||||
// being read as plausible numbers.
|
||||
//
|
||||
// ONE MESSAGE PER FRAME, on SOCK_SEQPACKET, and that is part of the protocol rather than an
|
||||
// implementation detail: an offer and its handle only mean anything together, and the message
|
||||
// boundary is what lets the reader take the two as one thing. The container derives the
|
||||
// length of the message it expects from the handle's own two counts and refuses any other
|
||||
// length, so this end sends the offer immediately followed by the handle's counts and its two
|
||||
// arrays, with the descriptors in the SCM_RIGHTS control data of that same sendmsg.
|
||||
//
|
||||
// The channel is OPTIONAL, and that is the rule the implementation is built around: a
|
||||
// container that is not running, has died, or has stopped reading may cost the render path a
|
||||
// syscall or two, and may never block it, fail it, or grow without bound. Every entry point
|
||||
// below is non-blocking and answers silence with silence.
|
||||
inline constexpr Uint32 kGbmFrameOfferMagic = 0x4647474Du; // 'M','G','G','F' in memory order
|
||||
inline constexpr Uint32 kGbmFrameReleaseMagic = 0x5247474Du; // 'M','G','G','R' in memory order
|
||||
inline constexpr Uint32 kGbmFrameVersion = 1u;
|
||||
// WHERE THE CONTAINER DIALS. /data/local/tmp is the one directory both halves of a split run
|
||||
// can be pointed at on a device, and the default lives on this end because this end is the
|
||||
// server. The container's compiled-in default is /run/mobilegl-gbm.sock - the same protocol
|
||||
// with the path each side can reach unaided - so a deployment that puts the two in different
|
||||
// mount namespaces sets MOBILEGL_GBM_SOCKET on both; it is read here and in
|
||||
// GbmHostChannelCreate, from the same variable, for that reason.
|
||||
inline constexpr const char* kGbmFrameSocketPath = "/data/local/tmp/mobilegl-gbm.sock";
|
||||
inline constexpr const char* kGbmFrameSocketEnv = "MOBILEGL_GBM_SOCKET";
|
||||
|
||||
// One frame the host offered, described for the container. Width, Height, StrideBytes and
|
||||
// Format are the host's own numbers for the frame (HostFrameOffer), carried through
|
||||
// unchanged: they describe the memory the descriptor points at, and this end is not the place
|
||||
// where a number the other two ends agreed on gets rewritten.
|
||||
struct GbmFrameOffer {
|
||||
Uint32 Magic;
|
||||
Uint32 Version;
|
||||
Uint32 Seq; // this channel's, one per frame offered
|
||||
Uint32 Index; // the host's own buffer index, echoed so the phone can match a frame
|
||||
Uint32 Width;
|
||||
Uint32 Height;
|
||||
Uint32 StrideBytes;
|
||||
Uint32 Format;
|
||||
Uint32 UsageLo;
|
||||
Uint32 UsageHi;
|
||||
} __attribute__((packed));
|
||||
|
||||
// What the container says once it is done with a frame. It may arrive late, it may never
|
||||
// arrive, and both are cheap here: the channel keeps a count and no per-frame record (see
|
||||
// Outstanding below), so nothing is leaked and nothing grows when one is missed.
|
||||
struct GbmFrameRelease {
|
||||
Uint32 Magic;
|
||||
Uint32 Version;
|
||||
Uint32 Seq;
|
||||
} __attribute__((packed));
|
||||
|
||||
// THE OTHER DIRECTION: A dma-buf THE CONTAINER WANTS THIS SIDE TO BACK A TEXTURE WITH.
|
||||
//
|
||||
// The compositor's scene reaches the display daemon's dma-bufs through glEGLImageTargetTexture2DOES
|
||||
// (MG_Impl/GLImpl/Exporting/Definitions.cpp, MG_Backend/DirectGLES/BackendObject_DirectGLES.cpp both
|
||||
// name this half as the next change). eglCreateImageKHR has already held a dup() of every plane's
|
||||
// descriptor since the image was made; what was missing is the render server's half - telling THIS
|
||||
// side which texture that dma-buf backs, over the one channel that can carry a descriptor across the
|
||||
// container boundary. This message is that half: the client names the texture target and the
|
||||
// texture's own name, describes the buffer exactly as drmModeAddFB2 would, and the plane descriptors
|
||||
// ride in the SCM_RIGHTS control data of the same sendmsg. One message per import, as SEQPACKET
|
||||
// requires, so a descriptor and its description are never read apart.
|
||||
//
|
||||
// The reply is what the client waits for before a framebuffer is allowed to be complete over the
|
||||
// texture: Ok=0 means this side could not make the import real, and the client keeps treating the
|
||||
// texture as having no storage rather than letting it render into nothing.
|
||||
inline constexpr Uint32 kGbmImportRequestMagic = 0x4947474Du; // 'M','G','G','I' in memory order
|
||||
inline constexpr Uint32 kGbmImportReplyMagic = 0x52474749u; // 'I','G','G','R' in memory order
|
||||
inline constexpr Uint32 kGbmImportVersion = 1u;
|
||||
inline constexpr Uint32 kGbmImportMaxPlanes = 4u;
|
||||
|
||||
struct GbmImportRequest {
|
||||
Uint32 Magic;
|
||||
Uint32 Version;
|
||||
Uint32 Target; // the GL texture target the image was bound to (0x8D65 = GL_TEXTURE_EXTERNAL_OES)
|
||||
Uint32 TexName; // the CLIENT's texture name; this side resolves its twin
|
||||
Uint32 Width;
|
||||
Uint32 Height;
|
||||
Uint32 FourCC;
|
||||
Uint32 PlaneCount; // 1..kGbmImportMaxPlanes; the descriptors are the message's control data
|
||||
Int32 Stride[kGbmImportMaxPlanes];
|
||||
Int32 Offset[kGbmImportMaxPlanes];
|
||||
Uint64 Modifier[kGbmImportMaxPlanes];
|
||||
Uint32 HasModifier[kGbmImportMaxPlanes];
|
||||
} __attribute__((packed));
|
||||
|
||||
struct GbmImportReply {
|
||||
Uint32 Magic;
|
||||
Uint32 Version;
|
||||
Uint32 Ok;
|
||||
Uint32 Reserved;
|
||||
} __attribute__((packed));
|
||||
|
||||
// An AHardwareBuffer native handle as it appears on the wire: the platform's native_handle_t
|
||||
// (version, then the two counts, then the descriptor array followed by the integer array),
|
||||
// written by AHardwareBuffer_sendHandleToUnixSocket and read by the container's
|
||||
// AHBNativeHandleHeader. The counts are 32 bit on every Android ABI, which is why they are
|
||||
// spelled out here rather than taken from a platform header this library cannot include.
|
||||
struct GbmNativeHandleHeader {
|
||||
Int32 Version;
|
||||
Int32 NumFds;
|
||||
Int32 NumInts;
|
||||
} __attribute__((packed));
|
||||
|
||||
// ONE CONTAINER, ONE LISTENING SOCKET, TWO THREADS: the render path's, and an acceptor's.
|
||||
//
|
||||
// A compositor dials ONCE - when it creates its GBM device - and keeps that connection for the
|
||||
// life of the process, while this side offers a frame per drawn frame. An accept that only ran
|
||||
// inside OfferFrame therefore ran after the dial it was supposed to answer, and a dialer that
|
||||
// nobody took kept the listener's queue full for every later one. That is measured on the
|
||||
// phone rather than argued: with accept() only on the offer path, connect() from the container
|
||||
// answered EAGAIN(11) on four attempts out of four while the node sat there listening.
|
||||
//
|
||||
// So the accept has a thread of its own, started by Open() and stopped by Close(), and it
|
||||
// adopts what it takes on the spot - including sending it the frame the host last handed over,
|
||||
// because a compositor's first allocation is the one its swapchain is built from. The
|
||||
// connected socket, the frame that is remembered, the relay and the counters are shared between
|
||||
// the two threads and guarded by the one mutex below; both entry points are non-blocking, so
|
||||
// neither thread can park the other for longer than a syscall.
|
||||
class GbmFrameChannel {
|
||||
public:
|
||||
GbmFrameChannel() = default;
|
||||
GbmFrameChannel(const GbmFrameChannel&) = delete;
|
||||
GbmFrameChannel& operator=(const GbmFrameChannel&) = delete;
|
||||
~GbmFrameChannel();
|
||||
|
||||
// Creates the listening socket if it is not there yet and starts the acceptor, and does
|
||||
// nothing otherwise. It never waits for a container: the socket is bound, a backlog is
|
||||
// given to listen(), and the acceptor takes whoever dials from then on - whether or not a
|
||||
// frame is being drawn. A caller that wants the container to find the socket before the
|
||||
// first frame - the container dials once at its own device creation and retries about once
|
||||
// a second - can call this when the host-framed surface is initialized, beside
|
||||
// HostFrameBridge::Open.
|
||||
Bool Open();
|
||||
|
||||
// Offers one frame the host just handed over, as the dma-buf descriptor behind it.
|
||||
// False means the frame did not go out, for any of the reasons this channel treats as
|
||||
// ordinary: no container is connected, the container just died, or the frame could not be
|
||||
// described. None of them is the caller's problem and none of them is fatal - the frame
|
||||
// is drawn and presented exactly as it would have been without a channel at all.
|
||||
Bool OfferFrame(struct AHardwareBuffer* buffer, const HostFrameOffer& offer);
|
||||
|
||||
// Reads whatever the container has said since the last call and marks the channel down if
|
||||
// the connection has ended. OfferFrame already does this once per frame, so a caller only
|
||||
// needs it if it wants releases drained on a path that has no new frame in it.
|
||||
void Poll();
|
||||
|
||||
// The frame the host handed over is gone - it was presented, or it was replaced - and this
|
||||
// channel may no longer hold it or offer it to anybody. THE CHANNEL ITSELF STAYS OPEN, and
|
||||
// that is the point of the call: the listening socket, its node and the container's
|
||||
// connection outlive every frame, and a channel that was closed and reopened per frame took
|
||||
// the node away sixty times a second - a container dialling at the wrong moment got ENOENT
|
||||
// for a socket that was there a millisecond earlier and would be there a millisecond later.
|
||||
void DropFrame();
|
||||
|
||||
// True while a container is connected and the frames are being offered to it.
|
||||
Bool IsUp() const {
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
return m_client >= 0;
|
||||
}
|
||||
|
||||
// How many frames have been offered and not released, as a count of messages and not a
|
||||
// record of them. It is here to be logged, and it is deliberately the only per-frame state
|
||||
// the channel keeps: a release that never arrives costs a number that is too high, and
|
||||
// nothing else, which is what makes a container that stops reading harmless.
|
||||
Uint64 Outstanding() const {
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
return m_outstanding;
|
||||
}
|
||||
|
||||
// Closes the connection, the listening socket and the node it created. Idempotent, safe
|
||||
// from a destructor, and safe to call while a container is connected: the container sees
|
||||
// the connection end and goes back to allocating its frames locally, which is the state it
|
||||
// starts in.
|
||||
void Close();
|
||||
|
||||
private:
|
||||
// The socketpair a frame's handle is handed to and read back from. Recreated on demand,
|
||||
// because the one call the NDK offers for a buffer's descriptors sends them as a message
|
||||
// of its own and the container takes one message per frame - see the note in the .cpp.
|
||||
Bool EnsureRelay();
|
||||
void DropRelay();
|
||||
Bool RelayHandle(struct AHardwareBuffer* buffer, Uint8* payload, SizeT capacity, SizeT& payloadBytes,
|
||||
Int* fds, Int& fdCount);
|
||||
|
||||
// Takes the one container the protocol allows, and closes anyone else who dials while a
|
||||
// LIVE one is connected rather than leaving them to believe they are being served. A
|
||||
// connection whose peer has exited is not a live one: it is closed here and its dialer's
|
||||
// replacement is taken, which is what a compositor that crashed and was restarted is.
|
||||
void AdoptLocked(Int fd);
|
||||
|
||||
// True while the connected container is still there. recvmsg with MSG_PEEK is what asks:
|
||||
// zero bytes is the peer's close, EAGAIN is a peer that is between frames, and a release
|
||||
// waiting in the socket is a peer that is alive - peeked at rather than read, because the
|
||||
// render path is the one that spends releases.
|
||||
Bool ClientAliveLocked();
|
||||
|
||||
// Takes the one container the protocol allows out of whoever dialled.
|
||||
void AcceptLoop(Int listen);
|
||||
|
||||
// Sends the frame that is the draw target to a container that has just connected.
|
||||
void ReofferFrameLocked();
|
||||
|
||||
// Remembers the frame the host last handed over, holding a reference to it so that a
|
||||
// container which dials after the offer can still be given it. The previous one is
|
||||
// released here; nothing else in the channel holds a frame.
|
||||
void RememberFrameLocked(struct AHardwareBuffer* buffer, const HostFrameOffer& offer, Uint32 seq);
|
||||
void ReleaseFrameLocked();
|
||||
|
||||
// The offer itself: the handle relayed out of the buffer, the message built, one sendmsg.
|
||||
// A frame that has already been offered once is sent again with the sequence number it was
|
||||
// offered under and does not move the counters, because it is the same frame and not a new
|
||||
// one.
|
||||
Bool SendFrameLocked(struct AHardwareBuffer* buffer, const HostFrameOffer& offer, Uint32 seq, Bool counting);
|
||||
|
||||
// The body of Poll(), for a caller that is already holding the lock.
|
||||
void PollLocked();
|
||||
|
||||
// Closes the connection and says why, once. The channel stays open for the next container.
|
||||
void MarkDown(const char* what, Int error);
|
||||
|
||||
Int m_listen = -1;
|
||||
Int m_client = -1;
|
||||
Int m_relay[2] = {-1, -1};
|
||||
String m_path;
|
||||
// Bumped only for a frame that actually went out, so a sequence number is never reused and
|
||||
// a release can never be read as belonging to a frame of an earlier connection.
|
||||
Uint32 m_nextSeq = 0;
|
||||
Uint64 m_offered = 0;
|
||||
Uint64 m_released = 0;
|
||||
Uint64 m_outstanding = 0;
|
||||
// The frame the host handed over most recently, held by this channel's own reference for as
|
||||
// long as it is the draw target: it is what a container that dials late is sent.
|
||||
struct AHardwareBuffer* m_frame = nullptr;
|
||||
HostFrameOffer m_frameOffer = {};
|
||||
Uint32 m_frameSeq = 0;
|
||||
// The acceptor, and the flag that ends it. The listening descriptor is handed to the thread
|
||||
// as its own copy, so it is the only thing in here that thread reads without the lock - and
|
||||
// Close() joins the thread before it closes that descriptor.
|
||||
std::thread m_acceptor;
|
||||
std::atomic<Bool> m_accepting{false};
|
||||
// Guards every member above, from both threads. Mutable because the two const questions a
|
||||
// caller asks about the channel - is a container connected, how many frames are outstanding
|
||||
// - are answers that have to be read under it.
|
||||
mutable std::mutex m_mutex;
|
||||
};
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Backend/HostFrameBridge.cpp
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#include "HostFrameBridge.h"
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED && defined(__ANDROID__)
|
||||
|
||||
#include <android/hardware_buffer.h>
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
#include <poll.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace MobileGL::MG_Backend {
|
||||
namespace {
|
||||
Bool ReadExactly(Int fd, void* out, SizeT n) {
|
||||
Uint8* at = static_cast<Uint8*>(out);
|
||||
while (n > 0) {
|
||||
const ssize_t got = ::read(fd, at, n);
|
||||
if (got <= 0) {
|
||||
if (got < 0 && errno == EINTR) continue;
|
||||
return false;
|
||||
}
|
||||
at += got;
|
||||
n -= static_cast<SizeT>(got);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Bool WriteExactly(Int fd, const void* in, SizeT n) {
|
||||
const Uint8* at = static_cast<const Uint8*>(in);
|
||||
while (n > 0) {
|
||||
const ssize_t put = ::write(fd, at, n);
|
||||
if (put <= 0) {
|
||||
if (put < 0 && errno == EINTR) continue;
|
||||
return false;
|
||||
}
|
||||
at += put;
|
||||
n -= static_cast<SizeT>(put);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
HostFrameBridge::~HostFrameBridge() { Close(); }
|
||||
|
||||
Bool HostFrameBridge::Open(const char* path, Int acceptTimeoutMs, String& why) {
|
||||
Close();
|
||||
const char* name = (path != nullptr && path[0] != 0) ? path : kHostFrameSocket;
|
||||
|
||||
m_listen = ::socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (m_listen < 0) {
|
||||
why = std::format("socket(AF_UNIX): {}", std::strerror(errno));
|
||||
return false;
|
||||
}
|
||||
sockaddr_un address{};
|
||||
address.sun_family = AF_UNIX;
|
||||
if (std::strlen(name) >= sizeof(address.sun_path)) {
|
||||
why = std::format("the socket name is longer than the kernel takes: {}", name);
|
||||
Close();
|
||||
return false;
|
||||
}
|
||||
// "@name" is the abstract namespace: sun_path[0] is NUL and the name follows it.
|
||||
// Nothing is created on disk, so nothing is left behind and no file permission stands
|
||||
// between two apps that may not write each other's directories.
|
||||
if (name[0] == '@') {
|
||||
address.sun_path[0] = 0;
|
||||
std::strncpy(address.sun_path + 1, name + 1, sizeof(address.sun_path) - 2);
|
||||
} else {
|
||||
std::strncpy(address.sun_path, name, sizeof(address.sun_path) - 1);
|
||||
// A leftover socket file from a server that died is not a reason to refuse the host.
|
||||
::unlink(name);
|
||||
}
|
||||
if (::bind(m_listen, reinterpret_cast<sockaddr*>(&address), sizeof(address)) != 0) {
|
||||
why = std::format("bind({}): {}", name, std::strerror(errno));
|
||||
Close();
|
||||
return false;
|
||||
}
|
||||
if (::listen(m_listen, 1) != 0) {
|
||||
why = std::format("listen({}): {}", name, std::strerror(errno));
|
||||
Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
pollfd waiting{};
|
||||
waiting.fd = m_listen;
|
||||
waiting.events = POLLIN;
|
||||
const Int ready = ::poll(&waiting, 1, acceptTimeoutMs);
|
||||
if (ready <= 0) {
|
||||
why = (ready == 0) ? std::format("no display host dialled {} within {} ms", name, acceptTimeoutMs)
|
||||
: std::format("poll({}): {}", name, std::strerror(errno));
|
||||
Close();
|
||||
return false;
|
||||
}
|
||||
m_fd = ::accept(m_listen, nullptr, nullptr);
|
||||
if (m_fd < 0) {
|
||||
why = std::format("accept({}): {}", name, std::strerror(errno));
|
||||
Close();
|
||||
return false;
|
||||
}
|
||||
MGLOG_I("host frame bridge: a display host is on %s", name);
|
||||
return true;
|
||||
}
|
||||
|
||||
Bool HostFrameBridge::Acquire(struct AHardwareBuffer** buffer, HostFrameOffer& offer, String& why) {
|
||||
*buffer = nullptr;
|
||||
offer = HostFrameOffer{};
|
||||
if (m_fd < 0) {
|
||||
why = "the bridge is not open";
|
||||
return false;
|
||||
}
|
||||
AHardwareBuffer* received = nullptr;
|
||||
if (AHardwareBuffer_recvHandleFromUnixSocket(m_fd, &received) != 0 || received == nullptr) {
|
||||
why = "the host stopped offering frames, or the handle did not cross";
|
||||
return false;
|
||||
}
|
||||
if (!ReadExactly(m_fd, &offer, sizeof(offer)) || offer.Magic != kHostFrameMagic) {
|
||||
// The handle is already this side's by the time this fails, so it goes back before
|
||||
// the failure does: a reference held past the connection starves the host's pool.
|
||||
AHardwareBuffer_release(received);
|
||||
why = std::format("the frame's description did not follow its handle (magic 0x{:08x})", offer.Magic);
|
||||
return false;
|
||||
}
|
||||
*buffer = received;
|
||||
return true;
|
||||
}
|
||||
|
||||
Bool HostFrameBridge::Complete(const HostFrameOffer& offer, Bool imported, Bool drawn, Bool fenceOk, String& why) {
|
||||
if (m_fd < 0) {
|
||||
why = "the bridge is not open";
|
||||
return false;
|
||||
}
|
||||
HostFrameAck ack{};
|
||||
ack.Magic = kHostFrameMagic;
|
||||
ack.Version = kHostFrameVersion;
|
||||
ack.Index = offer.Index;
|
||||
ack.Imported = imported ? 1u : 0u;
|
||||
ack.Drawn = drawn ? 1u : 0u;
|
||||
ack.FenceOk = fenceOk ? 1u : 0u;
|
||||
if (!WriteExactly(m_fd, &ack, sizeof(ack))) {
|
||||
why = std::format("the answer to frame {} did not go out: {}", offer.Index, std::strerror(errno));
|
||||
return false;
|
||||
}
|
||||
// The host answers with its own view of the pixels. It is what closes the round trip, so
|
||||
// it is read here and kept rather than left in the socket for the next frame to trip over.
|
||||
m_lastSeen = HostFrameSeen{};
|
||||
if (!ReadExactly(m_fd, &m_lastSeen, sizeof(m_lastSeen)) || m_lastSeen.Magic != kHostFrameMagic) {
|
||||
why = std::format("frame {} was answered but the host's readback did not arrive", offer.Index);
|
||||
m_lastSeen = HostFrameSeen{};
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void HostFrameBridge::Close() {
|
||||
if (m_fd >= 0) ::close(m_fd);
|
||||
if (m_listen >= 0) ::close(m_listen);
|
||||
m_fd = -1;
|
||||
m_listen = -1;
|
||||
}
|
||||
}
|
||||
|
||||
#else // !(MOBILEGL_BUILD_DISAGGREGATED && __ANDROID__)
|
||||
|
||||
namespace MobileGL::MG_Backend {
|
||||
HostFrameBridge::~HostFrameBridge() = default;
|
||||
Bool HostFrameBridge::Open(const char*, Int, String& why) {
|
||||
why = "host frames are a disaggregated Android path";
|
||||
return false;
|
||||
}
|
||||
Bool HostFrameBridge::Acquire(struct AHardwareBuffer**, HostFrameOffer&, String& why) {
|
||||
why = "host frames are a disaggregated Android path";
|
||||
return false;
|
||||
}
|
||||
Bool HostFrameBridge::Complete(const HostFrameOffer&, Bool, Bool, Bool, String& why) {
|
||||
why = "host frames are a disaggregated Android path";
|
||||
return false;
|
||||
}
|
||||
void HostFrameBridge::Close() {}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,103 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Backend/HostFrameBridge.h
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#pragma once
|
||||
#include <Includes.h>
|
||||
|
||||
struct AHardwareBuffer;
|
||||
|
||||
namespace MobileGL::MG_Backend {
|
||||
// THE DISPLAY HOST'S FRAMES, AS THEY ARRIVE.
|
||||
//
|
||||
// The Android side that owns the screen allocates its frames itself and offers each one over
|
||||
// an AF_UNIX socket: the handle travels ahead of a fixed-size description on the same
|
||||
// connection, and the host then waits for this side to say the frame is drawn before it puts
|
||||
// it on the glass. Why the host allocates rather than this side asking for the display's own
|
||||
// buffers is measured, not chosen: AHardwareBuffer_createFromHandle accepts an
|
||||
// AHardwareBuffer this process allocated and refuses one the display queue handed over
|
||||
// (gralloc BAD_VALUE), so the only frames a render server can draw into are the ones the host
|
||||
// made for it.
|
||||
//
|
||||
// The three message shapes below ARE the host's (its ahb_bridge.h), field for field and
|
||||
// packing included. They are restated here rather than shared because the two ends are built
|
||||
// by different projects; a change on either side is a protocol change, and the magic is what
|
||||
// makes a mismatched pair fail loudly instead of being read as plausible numbers.
|
||||
inline constexpr Uint32 kHostFrameMagic = 0x4D474C41u; // the host spells it "ALGM" in memory
|
||||
inline constexpr Uint32 kHostFrameVersion = 1u;
|
||||
// AN ABSTRACT NAME, not a path: the two ends are separate apps, and neither may create a
|
||||
// socket file in /data/local/tmp (its directory grants others traverse only). An abstract
|
||||
// name lives in the kernel namespace instead of the filesystem, so there is no file
|
||||
// permission to get wrong - the same reason this project names its own endpoints @mgl-*.
|
||||
inline constexpr const char* kHostFrameSocket = "@mobilegl-host-frame";
|
||||
|
||||
struct HostFrameOffer {
|
||||
Uint32 Magic;
|
||||
Uint32 Version;
|
||||
Uint32 Index;
|
||||
Uint32 Width;
|
||||
Uint32 Height;
|
||||
Uint32 StrideBytes;
|
||||
Uint32 Format;
|
||||
Uint32 UsageLo;
|
||||
Uint32 UsageHi;
|
||||
char Note[64];
|
||||
} __attribute__((packed));
|
||||
|
||||
struct HostFrameAck {
|
||||
Uint32 Magic;
|
||||
Uint32 Version;
|
||||
Uint32 Index;
|
||||
Uint32 Imported;
|
||||
Uint32 Drawn;
|
||||
Uint32 FenceOk;
|
||||
Uint8 Color[4];
|
||||
char Note[64];
|
||||
} __attribute__((packed));
|
||||
|
||||
struct HostFrameSeen {
|
||||
Uint32 Magic;
|
||||
Uint32 Version;
|
||||
Uint32 Index;
|
||||
Uint32 Locked;
|
||||
Uint8 Observed[4];
|
||||
Uint8 ObservedCorner[4];
|
||||
char Note[64];
|
||||
} __attribute__((packed));
|
||||
|
||||
// One host connection at a time, which is what the host offers: it dials, hands over a frame,
|
||||
// waits for the answer, and hands over the next.
|
||||
class HostFrameBridge {
|
||||
public:
|
||||
HostFrameBridge() = default;
|
||||
HostFrameBridge(const HostFrameBridge&) = delete;
|
||||
HostFrameBridge& operator=(const HostFrameBridge&) = delete;
|
||||
~HostFrameBridge();
|
||||
|
||||
// Listens on `path` (the well-known name by default) and waits for the host. A host that
|
||||
// never dials is answered with false and a reason, never an abort.
|
||||
Bool Open(const char* path, Int acceptTimeoutMs, String& why);
|
||||
|
||||
// Takes the next frame. Ownership of the returned AHardwareBuffer is the caller's, who
|
||||
// must hand it back through ReleaseOwned() once the frame is off the glass.
|
||||
Bool Acquire(struct AHardwareBuffer** buffer, HostFrameOffer& offer, String& why);
|
||||
|
||||
// Tells the host what became of the frame it offered, and reads back what the host's own
|
||||
// view of the pixels holds. `drawn` is what the host waits for before it presents.
|
||||
Bool Complete(const HostFrameOffer& offer, Bool imported, Bool drawn, Bool fenceOk, String& why);
|
||||
|
||||
// The readback the host returned for the last completed frame, as the host reported it.
|
||||
const HostFrameSeen& LastSeen() const { return m_lastSeen; }
|
||||
|
||||
void Close();
|
||||
|
||||
private:
|
||||
Int m_fd = -1;
|
||||
Int m_listen = -1;
|
||||
HostFrameSeen m_lastSeen{};
|
||||
};
|
||||
}
|
||||
+53
-123
@@ -14,9 +14,7 @@
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
#include <MG_Pipe/MGPipe.h>
|
||||
#include <MG_Pipe/PipeApply.h>
|
||||
#include <MG_Pipe/PipeMutation.h> // MGPipeForgetAllPublications, at the end of ShutdownSplitRoles
|
||||
#include <MG_Remote/Client/ClientSession.h>
|
||||
#include <MG_Remote/FatalFunnel.h> // InstallPipeSessionFailHook, installed at step 0 below
|
||||
#include <MG_Remote/Server/ServerLoop.h>
|
||||
#include <MG_Remote/Server/ServerSession.h>
|
||||
#endif
|
||||
@@ -82,10 +80,9 @@ namespace MobileGL::MG_Backend {
|
||||
// DirectGLES consumes all thirteen migrated families (P2's 0..6, P3a's 7..8, P4a's
|
||||
// 9..12): it registers the resource op table in Initialize()
|
||||
// (BackendObject_DirectGLES.cpp:849) and reads every other family out of gPipeInputs.
|
||||
// DirectVulkan registers its wire resource op table off monolith only
|
||||
// (VkBufferManager::RegisterWireResourceOps, VkBufferManager.cpp): under a transport it
|
||||
// owns buffer stores and claims bit 7 (the P4a mask, see ConsumedSubsystemsFor below);
|
||||
// under monolith it registers none and its buffers keep the legacy BufferBackendOps path.
|
||||
// DirectVulkan registers NO resource ops - MGPipeSetResourceOps has exactly one caller
|
||||
// in the whole tree and it is Managers.cpp:2594 - so bit 7 is CLEAR for it, which is
|
||||
// the same fact ObjectSubsystemControlScenario already pins from the client side.
|
||||
// P5e (MG_Remote/CONTRACT-P5E.md §6.2). THE ONE CONSTANT THE WHOLE PHASE HANGS ON.
|
||||
//
|
||||
// kCapRunAheadApply says "this server applies an unbarriered record without reading
|
||||
@@ -162,14 +159,6 @@ namespace MobileGL::MG_Backend {
|
||||
Bool InitServerRoleCommon() {
|
||||
using namespace MobileGL::MG_Remote;
|
||||
|
||||
// 0. the Magma wire funnels' route to Session::Fail (P7 wave 0). FIRST, before
|
||||
// CreateBackend can reach a wire arm: a hook installed after the first death it
|
||||
// was meant to catch is a hook that does nothing on the only run that mattered.
|
||||
// Here rather than in ServerMain because BOTH server roles pass through this
|
||||
// function - the inproc role and the spawn/TCP session child - and a per-transport
|
||||
// install is how one of the two ends up without it.
|
||||
InstallPipeSessionFailHook();
|
||||
|
||||
// 1. the SERVER role's private backend object, on the app thread, with no GL and no
|
||||
// EGL. The context is created and made current later, on mgl-srv-apply, when the
|
||||
// client's first eglMakeCurrent crosses as a blocking control request.
|
||||
@@ -187,9 +176,9 @@ namespace MobileGL::MG_Backend {
|
||||
// ZERO IS THE EXPLICIT ANSWER FOR P5, not an omission (ServerSession.h's block):
|
||||
// every optional capability bit belongs to the package that owns its question, and
|
||||
// withholding one leaves the legacy path running, which is the safe direction.
|
||||
// kCapNeedsHostIndexBytes, kCapNeedsHostUboBytes and kCapViewportArray are RESERVED
|
||||
// (P8-F) and never set here: the first two are the only things that ask for an
|
||||
// MGHostSpan, and 0 keeps every one of them off the wire (contract table 0).
|
||||
// kCapNeedsHostIndexBytes and kCapNeedsHostUboBytes must be 0 for the whole of P5
|
||||
// by ruling - they are the only two things that ask for an MGHostSpan, and 0 is
|
||||
// what keeps every one of them out of the first IPC frame (contract table 0).
|
||||
//
|
||||
// P5b t2 (CONTRACT-P5B.md §6.5) PUBLISHES THE ONE BIT P5b ADDS, and this is the
|
||||
// only place that can: the question kCapBackendOwnsXfbCapture answers is "does the
|
||||
@@ -222,32 +211,6 @@ namespace MobileGL::MG_Backend {
|
||||
capBits |= MG_Pipe::kCapTimerQuery;
|
||||
}
|
||||
}
|
||||
// P7 wave 2 package C, OQ-10 (CONTRACT-P7 §5.4): kCapResidentSubData, PUBLISHED
|
||||
// OFF THE SERVER'S OWN WIRE RESOURCE TABLE AND NOTHING ELSE.
|
||||
//
|
||||
// The question the bit answers is the one BufferObject::LandBytesIntoResidentStore
|
||||
// asks before it chooses between emitting `buffer_subdata_resident` (opcode 49) and
|
||||
// falling back to the ordered in-place host memcpy: "does the side that will APPLY
|
||||
// this record implement the resident arm at all?" Under a transport the client has
|
||||
// no op table to probe - MGPipeResourceOpsHaveSubDataResident says so in as many
|
||||
// words (MG_Impl/Pipe/PipeFill.cpp) and reads this bit instead - and until now
|
||||
// nothing ever set it, so the answer was permanently "no" and BOTH backends fell
|
||||
// back to the memcpy while both of them in fact register a SubDataResident arm
|
||||
// (DirectGLES Managers.cpp's g_glesResourceOps, Magma VkBufferManager.cpp's
|
||||
// g_vulkanWireResourceOps). Magma's implementation was dead code on the wire.
|
||||
//
|
||||
// BY THE TABLE, NEVER BY THE BACKEND ENUM, and that is ID-39's lesson rather than a
|
||||
// style preference: a mask is a statement about THIS backend's registered table, so
|
||||
// a bit derived from `ActiveBackendType == ...` would keep claiming the capability
|
||||
// for a build, a flavour or a future backend whose table does not carry the arm -
|
||||
// which is exactly how 66 uploads were lost to a consumer bit that nobody could
|
||||
// have honoured. `g_resourceOpsAtStep2` is the pointer this function just pinned,
|
||||
// and step 5 already refuses a run where that pointer was swapped underneath us, so
|
||||
// reading the arm off it means the published bit and the table that has to answer
|
||||
// for it cannot come apart.
|
||||
if (g_resourceOpsAtStep2 != nullptr && g_resourceOpsAtStep2->SubDataResident != nullptr) {
|
||||
capBits |= MG_Pipe::kCapResidentSubData;
|
||||
}
|
||||
// Each backend has an independent implementation-readiness gate.
|
||||
// The runtime RunAhead knob can decline the feature, never create it.
|
||||
const Bool runAheadReady = MG_Config::ActiveBackendType == BackendType::DirectVulkan
|
||||
@@ -304,16 +267,55 @@ namespace MobileGL::MG_Backend {
|
||||
pActiveBackendObject = MakeUnique<MG_Remote::Client::BackendObject_Remote>();
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
// F1 (P7 wave 2). THE WHOLE SPLIT ARM OF Init(), AS ONE BODY, so it can run from
|
||||
// either of the two places that may reach it - MobileGL::Initialize's early hook,
|
||||
// before MG_State::Init(), and Init() itself for a direct caller such as a unit
|
||||
// fixture - without a second copy. Two copies of a bring-up order is how the two
|
||||
// orders come to differ on the day one of them is wrong.
|
||||
Bool g_splitBackendBroughtUp = false;
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
void ShutdownSplitRoles() {
|
||||
if (MG_Config::Transport == MG_Config::TransportMode::Monolith) return;
|
||||
// ClientSession::Stop IS table 3's whole order and it is idempotent: publish and wait
|
||||
// for the server to drain (bounded - a lost record must be a red lane, not a hung
|
||||
// exit), Doorbell::Kill through the transport's Shutdown, ServerLoop::Stop's bounded
|
||||
// join - which also destroys the server's private BackendObject ON the apply thread
|
||||
// while it still owns the context - the transport, and only THEN anything an emitter
|
||||
// owns. A var-tail still named by an unapplied record is a use-after-free the join is
|
||||
// what prevents, which is why the order is not a preference.
|
||||
MG_Remote::Client::ClientSessionInstance().Stop();
|
||||
// M-6: ClientSession::Stop's !m_started arm (a Start that FAILED after
|
||||
// ServerSession::Accept - a refused Accept, an invalid cmd/reply ring) tears down only
|
||||
// the client half and never stops the apply thread or drops the server's private backend,
|
||||
// which ServerLoop::CreateBackend already built and which holds the process-wide
|
||||
// g_resourceOps. So call ServerLoop::Stop() here unconditionally. It is idempotent: on the
|
||||
// started path ClientSession::Stop already joined the thread, so this hits Stop's
|
||||
// !joinable arm, which resets a backend that never ran a thread and is otherwise a no-op.
|
||||
// Without this an early Start failure leaves BackendObject_DirectGLES permanently alive
|
||||
// and every later split bring-up in the process fails at CreateBackend's m_backend!=null
|
||||
// guard.
|
||||
MG_Remote::Server::ServerLoopInstance().Stop();
|
||||
}
|
||||
#endif
|
||||
|
||||
void InitSplitBackend() {
|
||||
g_splitBackendBroughtUp = true;
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// The spawn server's entry into the SAME bring-up the inproc server role
|
||||
// runs (ServerRole.h). A thin forwarder on purpose: the body stays in the
|
||||
// anonymous namespace beside InitSplitRoles so the two cannot drift.
|
||||
//
|
||||
// THE WHOLE FUNCTION IS INSIDE THE GUARD, not just its body. A version with
|
||||
// the guard inside still DEFINES the symbol in a pull build, and G1 caught
|
||||
// it: 2 symbols added, 1 removed, .text +16 bytes. The pull build's identity
|
||||
// is byte-for-byte, and "it returns false there" is not the same as "it is
|
||||
// not there".
|
||||
Bool InitServerRoleForSpawn() { return InitServerRoleCommon(); }
|
||||
#endif
|
||||
|
||||
void Init() {
|
||||
MGLOG_D("Initializing MobileGL Backend...");
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// THE SINGLE HOOK. In a build without MOBILEGL_BUILD_DISAGGREGATED, MG_Config::Transport
|
||||
// is a `constexpr Monolith` (Config.h) and this whole statement is discarded, so the
|
||||
// pull build gains no symbol, no branch and no byte - which is what G1 measures.
|
||||
if (MG_Config::Transport != MG_Config::TransportMode::Monolith) {
|
||||
if (!InitSplitRoles()) {
|
||||
// NOT a fallback to the switch. pActiveBackendObject stays null and the next GL
|
||||
// call fails loudly, which is the only honest outcome: the operator asked for a
|
||||
@@ -362,78 +364,6 @@ namespace MobileGL::MG_Backend {
|
||||
}
|
||||
}
|
||||
LogBackendInfo();
|
||||
}
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// F1 (P7 wave 2). See BackendObjects.h for why this exists and MobileGL/Init.cpp for the
|
||||
// defect the order closes.
|
||||
Bool InitSplitRolesBeforeState() {
|
||||
if (MG_Config::Transport == MG_Config::TransportMode::Monolith) return false;
|
||||
InitSplitBackend();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
void ShutdownSplitRoles() {
|
||||
g_splitBackendBroughtUp = false;
|
||||
if (MG_Config::Transport == MG_Config::TransportMode::Monolith) return;
|
||||
// ClientSession::Stop IS table 3's whole order and it is idempotent: publish and wait
|
||||
// for the server to drain (bounded - a lost record must be a red lane, not a hung
|
||||
// exit), Doorbell::Kill through the transport's Shutdown, ServerLoop::Stop's bounded
|
||||
// join - which also destroys the server's private BackendObject ON the apply thread
|
||||
// while it still owns the context - the transport, and only THEN anything an emitter
|
||||
// owns. A var-tail still named by an unapplied record is a use-after-free the join is
|
||||
// what prevents, which is why the order is not a preference.
|
||||
MG_Remote::Client::ClientSessionInstance().Stop();
|
||||
// M-6: ClientSession::Stop's !m_started arm (a Start that FAILED after
|
||||
// ServerSession::Accept - a refused Accept, an invalid cmd/reply ring) tears down only
|
||||
// the client half and never stops the apply thread or drops the server's private backend,
|
||||
// which ServerLoop::CreateBackend already built and which holds the process-wide
|
||||
// g_resourceOps. So call ServerLoop::Stop() here unconditionally. It is idempotent: on the
|
||||
// started path ClientSession::Stop already joined the thread, so this hits Stop's
|
||||
// !joinable arm, which resets a backend that never ran a thread and is otherwise a no-op.
|
||||
// Without this an early Start failure leaves BackendObject_DirectGLES permanently alive
|
||||
// and every later split bring-up in the process fails at CreateBackend's m_backend!=null
|
||||
// guard.
|
||||
MG_Remote::Server::ServerLoopInstance().Stop();
|
||||
// The server's twins died with the session; the frontend objects that are destroyed after
|
||||
// this (the GL context's) have nothing left on the other side to delete.
|
||||
MG_Pipe::MGPipeForgetAllPublications();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// The spawn server's entry into the SAME bring-up the inproc server role
|
||||
// runs (ServerRole.h). A thin forwarder on purpose: the body stays in the
|
||||
// anonymous namespace beside InitSplitRoles so the two cannot drift.
|
||||
//
|
||||
// THE WHOLE FUNCTION IS INSIDE THE GUARD, not just its body. A version with
|
||||
// the guard inside still DEFINES the symbol in a pull build, and G1 caught
|
||||
// it: 2 symbols added, 1 removed, .text +16 bytes. The pull build's identity
|
||||
// is byte-for-byte, and "it returns false there" is not the same as "it is
|
||||
// not there".
|
||||
Bool InitServerRoleForSpawn() { return InitServerRoleCommon(); }
|
||||
#endif
|
||||
|
||||
void Init() {
|
||||
MGLOG_D("Initializing MobileGL Backend...");
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// THE SINGLE HOOK. In a build without MOBILEGL_BUILD_DISAGGREGATED, MG_Config::Transport
|
||||
// is a `constexpr Monolith` (Config.h) and this whole statement is discarded, so the
|
||||
// pull build gains no symbol, no branch and no byte - which is what G1 measures.
|
||||
if (MG_Config::Transport != MG_Config::TransportMode::Monolith) {
|
||||
// F1: MobileGL::Initialize now brings the split roles up BEFORE MG_State::Init(),
|
||||
// through InitSplitRolesBeforeState() below, so by the time Init() is reached on
|
||||
// that path the work is done. A DIRECT caller - a unit fixture that calls
|
||||
// MG_Backend::Init() itself - still gets the whole bring-up here. The flag rather
|
||||
// than `pActiveBackendObject == nullptr`, because a bring-up that FAILED leaves
|
||||
// that pointer null too and retrying it would refuse at CreateBackend's
|
||||
// m_backend != nullptr guard with a second, misleading line.
|
||||
if (!g_splitBackendBroughtUp) InitSplitBackend();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -54,60 +54,6 @@ namespace MobileGL::MG_Pipe {
|
||||
namespace {
|
||||
Uint64 g_residualPulls = 0;
|
||||
|
||||
#if MOBILEGL_PIPE_VERIFY
|
||||
// ---- P7 wave 3 (V1): negative control B's SERVER half ----------------------------
|
||||
//
|
||||
// MOBILEGL_PIPE_POISON_OMIT withholds the STAMP of one (verb, field) pair, and until a
|
||||
// verify build first ran on the split arm it was only ever read by the client's filler
|
||||
// (MG_Impl/Pipe/PipeFill.cpp's ParsePoisonOmissionKnob). On the split arm that is not
|
||||
// where the stamp the backend reads comes from: the stamp below re-stamps every field
|
||||
// the verb's class can answer out of applied records, so it restamped the very field
|
||||
// the client had withheld and the control went GREEN - measured, both backends, the
|
||||
// child's glGenerateMipmap returned and the process exited 0 with
|
||||
// GenerateMipmap:GetActiveTextureUnit omitted. The knob means "this verb's stamp of this
|
||||
// field was never written", and under a transport the stamp that answers the backend is
|
||||
// this one, so this one honours it too.
|
||||
//
|
||||
// PARSED HERE, NOT SHARED WITH THE CLIENT'S PARSER, because this file is in the server
|
||||
// library and MG_Impl is not. A malformed value is the client's Fatal{PipeVerifyBadKnob}
|
||||
// (it parses first, at the first fill of the process); this side simply does not arm.
|
||||
// VERIFY BUILDS ONLY: the knob belongs to the verify harness, and a push build's stamp
|
||||
// stays the branch-free fill the P5d profile asked for.
|
||||
struct ServerPoisonOmission {
|
||||
Bool Parsed = false;
|
||||
String Value;
|
||||
Bool Armed = false;
|
||||
MGPipeVerb Verb = MGPipeVerb::kVerbCount;
|
||||
MGPipeInputField Field = MGPipeInputField::kFieldCount;
|
||||
};
|
||||
ServerPoisonOmission g_serverOmission;
|
||||
|
||||
const ServerPoisonOmission& ServerOmission() {
|
||||
const String& knob = MG_Config::Features.PipePoisonOmit;
|
||||
if (g_serverOmission.Parsed && knob.size() == g_serverOmission.Value.size() &&
|
||||
(knob.empty() || knob == g_serverOmission.Value)) {
|
||||
return g_serverOmission;
|
||||
}
|
||||
g_serverOmission = ServerPoisonOmission{};
|
||||
g_serverOmission.Parsed = true;
|
||||
g_serverOmission.Value = knob;
|
||||
const auto colon = knob.find(':');
|
||||
if (colon == String::npos || colon == 0 || colon + 1 >= knob.size()) return g_serverOmission;
|
||||
const auto verb = MGPipeFindVerb(knob.substr(0, colon).c_str());
|
||||
const auto field = MGPipeFindInputField(knob.substr(colon + 1).c_str());
|
||||
if (!verb || !field) return g_serverOmission;
|
||||
g_serverOmission.Armed = true;
|
||||
g_serverOmission.Verb = *verb;
|
||||
g_serverOmission.Field = *field;
|
||||
return g_serverOmission;
|
||||
}
|
||||
|
||||
Bool ServerOmitsStamp(MGPipeVerb verb, MGPipeInputField field) {
|
||||
const ServerPoisonOmission& omission = ServerOmission();
|
||||
return omission.Armed && omission.Verb == verb && omission.Field == field;
|
||||
}
|
||||
#endif // MOBILEGL_PIPE_VERIFY
|
||||
|
||||
// The strict arm of R-7.3. Same first line as the ordinary poison Fatal, so every
|
||||
// existing filter on Fatal{UnmigratedPipeInput still matches, plus the class and the
|
||||
// phase that retires it - a strict abort that did not say which phase owes the answer
|
||||
@@ -406,14 +352,6 @@ namespace MobileGL::MG_Pipe {
|
||||
|
||||
Bool MGPipeServerContextIsLive() { return g_serverContextLive; }
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
namespace { const void* g_serverOwnedWindow = nullptr; }
|
||||
|
||||
void MGPipeServerSetOwnedWindow(const void* window) { g_serverOwnedWindow = window; }
|
||||
|
||||
const void* MGPipeServerOwnedWindow() { return g_serverOwnedWindow; }
|
||||
#endif
|
||||
|
||||
void MGPipeServerBlockNoteIdentity() {
|
||||
// D10: THE WIDER PREDICATE, and the narrow one was a latent crash rather than a missing
|
||||
// optimisation. Gated on the REHEARSAL, this early-returned for the whole life of a
|
||||
@@ -477,15 +415,6 @@ namespace MobileGL::MG_Pipe {
|
||||
const Uint64 bit = (answerable.Words[i / 64] >> (i % 64)) & Uint64{1};
|
||||
filled.FilledGen[i] = serial & (Uint64{0} - bit);
|
||||
}
|
||||
#if MOBILEGL_PIPE_VERIFY
|
||||
// Negative control B's server half (ServerPoisonOmission above): the one withheld pair.
|
||||
{
|
||||
const ServerPoisonOmission& omission = ServerOmission();
|
||||
if (omission.Armed && omission.Verb == verb) {
|
||||
filled.FilledGen[static_cast<SizeT>(omission.Field)] = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
MGPipeStampAccess::SetServerStamped(inputs, true);
|
||||
// P5f (f1): the server block's identity rides the stamp (CONTRACT-P5E §3.2's
|
||||
// "SetIdentity moves to ApplyOne" - the stamp is the per-verb half of ApplyOne, and
|
||||
@@ -509,12 +438,6 @@ namespace MobileGL::MG_Pipe {
|
||||
// AND A READ OUTSIDE THE VERB'S OWN CLASS IS STILL FATAL even for a BARRIER-PULLED
|
||||
// field: the value it would be answered with was never copied for this verb, so
|
||||
// counting it would trade a loud staleness for a quiet one.
|
||||
#if MOBILEGL_PIPE_VERIFY
|
||||
// An injected omission is reported as what it models - a stamp nobody wrote, the
|
||||
// client filler's own Fatal{UnmigratedPipeInput, "<Field>@<Verb>"} - and never as the
|
||||
// RoleViolation below, which would blame the wire for a withdrawal the control made.
|
||||
if (serverStamped && ServerOmitsStamp(verb, field)) MGPipeInputPoisonFatalForVerb(field, verb);
|
||||
#endif
|
||||
if (!serverStamped ||
|
||||
kMGPipeFieldOwnership[static_cast<SizeT>(field)] != MGPipeFieldOwnership::kBarrierPulled ||
|
||||
!FieldIsInVerbClass(field, verb)) {
|
||||
|
||||
@@ -938,13 +938,6 @@ namespace MobileGL::MG_Pipe {
|
||||
// GLContext or resurrected by stamping a verb after teardown.
|
||||
void MGPipeServerSetContextLive(Bool live);
|
||||
Bool MGPipeServerContextIsLive();
|
||||
// P12 review fix (size reports without the knob). The SERVER's own display window while this
|
||||
// session holds its lease (ServerLoop's ServerOwned arm sets it, the lease's end clears it), else
|
||||
// null. A backend whose window surface does not otherwise publish its extent (Espryt) publishes
|
||||
// it only for this window: a window the client named itself keeps the format-only publish every
|
||||
// earlier session relied on. Apply thread only.
|
||||
void MGPipeServerSetOwnedWindow(const void* window);
|
||||
const void* MGPipeServerOwnedWindow();
|
||||
#else
|
||||
// The push-without-transport build has one role and one block, so the fill side's spelling
|
||||
// folds onto gPipeInputs and PipeFill.cpp reads identically in both build flavours. An
|
||||
@@ -1057,12 +1050,5 @@ namespace MobileGL::MG_Pipe {
|
||||
// dereferenced, the snapshot is only ever compared). Returns false for a forwarded field,
|
||||
// which has nothing to corrupt.
|
||||
Bool MGPipeApplyVerifyCorruption(PipeInputs& snapshot, MGPipeInputField field);
|
||||
// PipeFill.cpp. Writes the MOBILEGL_PIPE_VERIFY_FATAL=0 summary line ("N divergence(s)
|
||||
// survived") NOW, while the role's log file is still open. MobileGL::Destroy calls it right
|
||||
// before MG_Util::Debug::Close(): the line used to come from a namespace-scope static's
|
||||
// destructor, which runs AFTER Close, and Log.cpp reopens a closed sink with "w" - so that
|
||||
// summary was the only line the client half of every FATAL=0 run kept. Idempotent: a second
|
||||
// call with nothing new to report, the destructor's own included, writes nothing.
|
||||
void MGPipeVerifyFlushSummary();
|
||||
#endif
|
||||
} // namespace MobileGL::MG_Pipe
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,900 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Client/generated_wire_trampoline.h
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Includes.h>
|
||||
|
||||
// GENERATED by scripts/generate_client_trampoline.py
|
||||
|
||||
MOBILEGL_GL_API void glActiveProgramEXT(GLuint program);
|
||||
MOBILEGL_GL_API void glActiveShaderProgram(GLuint pipeline, GLuint program);
|
||||
MOBILEGL_GL_API void glActiveTexture(GLenum texture);
|
||||
MOBILEGL_GL_API void glAttachShader(GLuint program, GLuint shader);
|
||||
MOBILEGL_GL_API void glBeginConditionalRender(GLuint id, GLenum mode);
|
||||
MOBILEGL_GL_API void glBeginConditionalRenderNV(GLuint id, GLenum mode);
|
||||
MOBILEGL_GL_API void glBeginPerfMonitorAMD(GLuint monitor);
|
||||
MOBILEGL_GL_API void glBeginPerfQueryINTEL(GLuint queryHandle);
|
||||
MOBILEGL_GL_API void glBeginQuery(GLenum target, GLuint id);
|
||||
MOBILEGL_GL_API void glBeginQueryIndexed(GLenum target, GLuint index, GLuint id);
|
||||
MOBILEGL_GL_API void glBeginTransformFeedback(GLenum primitiveMode);
|
||||
MOBILEGL_GL_API void glBindAttribLocation(GLuint program, GLuint index, const GLchar* name);
|
||||
MOBILEGL_GL_API void glBindBuffer(GLenum target, GLuint buffer);
|
||||
MOBILEGL_GL_API void glBindBufferBase(GLenum target, GLuint index, GLuint buffer);
|
||||
MOBILEGL_GL_API void glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size);
|
||||
MOBILEGL_GL_API void glBindBuffersBase(GLenum target, GLuint first, GLsizei count, const GLuint* buffers);
|
||||
MOBILEGL_GL_API void glBindFragDataLocation(GLuint program, GLuint color, const GLchar* name);
|
||||
MOBILEGL_GL_API void glBindFragDataLocationIndexed(GLuint program, GLuint colorNumber, GLuint index, const GLchar* name);
|
||||
MOBILEGL_GL_API void glBindFramebuffer(GLenum target, GLuint framebuffer);
|
||||
MOBILEGL_GL_API void glBindImageTexture(GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format);
|
||||
MOBILEGL_GL_API void glBindImageTextures(GLuint first, GLsizei count, const GLuint* textures);
|
||||
MOBILEGL_GL_API void glBindMultiTextureEXT(GLenum texunit, GLenum target, GLuint texture);
|
||||
MOBILEGL_GL_API void glBindProgramPipeline(GLuint pipeline);
|
||||
MOBILEGL_GL_API void glBindRenderbuffer(GLenum target, GLuint renderbuffer);
|
||||
MOBILEGL_GL_API void glBindSampler(GLuint unit, GLuint sampler);
|
||||
MOBILEGL_GL_API void glBindSamplers(GLuint first, GLsizei count, const GLuint* samplers);
|
||||
MOBILEGL_GL_API void glBindShadingRateImageNV(GLuint texture);
|
||||
MOBILEGL_GL_API void glBindTexture(GLenum target, GLuint texture);
|
||||
MOBILEGL_GL_API void glBindTextureUnit(GLuint unit, GLuint texture);
|
||||
MOBILEGL_GL_API void glBindTextures(GLuint first, GLsizei count, const GLuint* textures);
|
||||
MOBILEGL_GL_API void glBindTransformFeedback(GLenum target, GLuint id);
|
||||
MOBILEGL_GL_API void glBindVertexArray(GLuint array);
|
||||
MOBILEGL_GL_API void glBindVertexBuffer(GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride);
|
||||
MOBILEGL_GL_API void glBlendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
|
||||
MOBILEGL_GL_API void glBlendEquation(GLenum mode);
|
||||
MOBILEGL_GL_API void glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha);
|
||||
MOBILEGL_GL_API void glBlendEquationSeparatei(GLuint buf, GLenum modeRGB, GLenum modeAlpha);
|
||||
MOBILEGL_GL_API void glBlendEquationSeparateiARB(GLuint buf, GLenum modeRGB, GLenum modeAlpha);
|
||||
MOBILEGL_GL_API void glBlendEquationi(GLuint buf, GLenum mode);
|
||||
MOBILEGL_GL_API void glBlendEquationiARB(GLuint buf, GLenum mode);
|
||||
MOBILEGL_GL_API void glBlendFunc(GLenum sfactor, GLenum dfactor);
|
||||
MOBILEGL_GL_API void glBlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
|
||||
MOBILEGL_GL_API void glBlendFuncSeparatei(GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
|
||||
MOBILEGL_GL_API void glBlendFuncSeparateiARB(GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
|
||||
MOBILEGL_GL_API void glBlendFunci(GLuint buf, GLenum src, GLenum dst);
|
||||
MOBILEGL_GL_API void glBlendFunciARB(GLuint buf, GLenum src, GLenum dst);
|
||||
MOBILEGL_GL_API void glBlendParameteriNV(GLenum pname, GLint value);
|
||||
MOBILEGL_GL_API void glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
|
||||
MOBILEGL_GL_API void glBlitNamedFramebuffer(GLuint readFramebuffer, GLuint drawFramebuffer, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
|
||||
MOBILEGL_GL_API void glBufferAddressRangeNV(GLenum pname, GLuint index, GLuint64EXT address, GLsizeiptr length);
|
||||
MOBILEGL_GL_API void glBufferAttachMemoryNV(GLenum target, GLuint memory, GLuint64 offset);
|
||||
MOBILEGL_GL_API void glBufferData(GLenum target, GLsizeiptr size, const void* data, GLenum usage);
|
||||
MOBILEGL_GL_API void glBufferPageCommitmentARB(GLenum target, GLintptr offset, GLsizeiptr size, GLboolean commit);
|
||||
MOBILEGL_GL_API void glBufferPageCommitmentMemNV(GLenum target, GLintptr offset, GLsizeiptr size, GLuint memory, GLuint64 memOffset, GLboolean commit);
|
||||
MOBILEGL_GL_API void glBufferStorage(GLenum target, GLsizeiptr size, const void* data, GLbitfield flags);
|
||||
MOBILEGL_GL_API void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void* data);
|
||||
MOBILEGL_GL_API void glCallCommandListNV(GLuint list);
|
||||
MOBILEGL_GL_API GLenum glCheckFramebufferStatus(GLenum target);
|
||||
MOBILEGL_GL_API GLenum glCheckNamedFramebufferStatus(GLuint framebuffer, GLenum target);
|
||||
MOBILEGL_GL_API GLenum glCheckNamedFramebufferStatusEXT(GLuint framebuffer, GLenum target);
|
||||
MOBILEGL_GL_API void glClampColor(GLenum target, GLenum clamp);
|
||||
MOBILEGL_GL_API void glClear(GLbitfield mask);
|
||||
MOBILEGL_GL_API void glClearBufferSubData(GLenum target, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void* data);
|
||||
MOBILEGL_GL_API void glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil);
|
||||
MOBILEGL_GL_API void glClearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
|
||||
MOBILEGL_GL_API void glClearDepth(GLclampd depth);
|
||||
MOBILEGL_GL_API void glClearDepthdNV(GLdouble depth);
|
||||
MOBILEGL_GL_API void glClearDepthf(GLfloat d);
|
||||
MOBILEGL_GL_API void glClearNamedBufferSubData(GLuint buffer, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void* data);
|
||||
MOBILEGL_GL_API void glClearNamedBufferSubDataEXT(GLuint buffer, GLenum internalformat, GLsizeiptr offset, GLsizeiptr size, GLenum format, GLenum type, const void* data);
|
||||
MOBILEGL_GL_API void glClearNamedFramebufferfi(GLuint framebuffer, GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil);
|
||||
MOBILEGL_GL_API void glClearStencil(GLint s);
|
||||
MOBILEGL_GL_API void glClientAttribDefaultEXT(GLbitfield mask);
|
||||
MOBILEGL_GL_API GLenum glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout);
|
||||
MOBILEGL_GL_API void glClipControl(GLenum origin, GLenum depth);
|
||||
MOBILEGL_GL_API void glColorFormatNV(GLint size, GLenum type, GLsizei stride);
|
||||
MOBILEGL_GL_API void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
|
||||
MOBILEGL_GL_API void glColorMaski(GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a);
|
||||
MOBILEGL_GL_API void glCommandListSegmentsNV(GLuint list, GLuint segments);
|
||||
MOBILEGL_GL_API void glCompileCommandListNV(GLuint list);
|
||||
MOBILEGL_GL_API void glCompileShader(GLuint shader);
|
||||
MOBILEGL_GL_API void glConservativeRasterParameterfNV(GLenum pname, GLfloat value);
|
||||
MOBILEGL_GL_API void glConservativeRasterParameteriNV(GLenum pname, GLint param);
|
||||
MOBILEGL_GL_API void glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
|
||||
MOBILEGL_GL_API void glCopyImageSubData(GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth);
|
||||
MOBILEGL_GL_API void glCopyMultiTexImage1DEXT(GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border);
|
||||
MOBILEGL_GL_API void glCopyMultiTexImage2DEXT(GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
|
||||
MOBILEGL_GL_API void glCopyMultiTexSubImage1DEXT(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
|
||||
MOBILEGL_GL_API void glCopyMultiTexSubImage2DEXT(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
MOBILEGL_GL_API void glCopyMultiTexSubImage3DEXT(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
MOBILEGL_GL_API void glCopyNamedBufferSubData(GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
|
||||
MOBILEGL_GL_API void glCopyPathNV(GLuint resultPath, GLuint srcPath);
|
||||
MOBILEGL_GL_API void glCopyTexImage1D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border);
|
||||
MOBILEGL_GL_API void glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
|
||||
MOBILEGL_GL_API void glCopyTexSubImage1D(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
|
||||
MOBILEGL_GL_API void glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
MOBILEGL_GL_API void glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
MOBILEGL_GL_API void glCopyTextureImage1DEXT(GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border);
|
||||
MOBILEGL_GL_API void glCopyTextureImage2DEXT(GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
|
||||
MOBILEGL_GL_API void glCopyTextureSubImage1D(GLuint texture, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
|
||||
MOBILEGL_GL_API void glCopyTextureSubImage1DEXT(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
|
||||
MOBILEGL_GL_API void glCopyTextureSubImage2D(GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
MOBILEGL_GL_API void glCopyTextureSubImage2DEXT(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
MOBILEGL_GL_API void glCopyTextureSubImage3D(GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
MOBILEGL_GL_API void glCopyTextureSubImage3DEXT(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
MOBILEGL_GL_API void glCoverFillPathNV(GLuint path, GLenum coverMode);
|
||||
MOBILEGL_GL_API void glCoverStrokePathNV(GLuint path, GLenum coverMode);
|
||||
MOBILEGL_GL_API void glCoverageModulationNV(GLenum components);
|
||||
MOBILEGL_GL_API void glCoverageModulationTableNV(GLsizei n, const GLfloat* v);
|
||||
MOBILEGL_GL_API void glCreateBuffers(GLsizei n, GLuint* buffers);
|
||||
MOBILEGL_GL_API void glCreateCommandListsNV(GLsizei n, GLuint* lists);
|
||||
MOBILEGL_GL_API void glCreateFramebuffers(GLsizei n, GLuint* framebuffers);
|
||||
MOBILEGL_GL_API void glCreateProgramPipelines(GLsizei n, GLuint* pipelines);
|
||||
MOBILEGL_GL_API void glCreateQueries(GLenum target, GLsizei n, GLuint* ids);
|
||||
MOBILEGL_GL_API void glCreateRenderbuffers(GLsizei n, GLuint* renderbuffers);
|
||||
MOBILEGL_GL_API void glCreateSamplers(GLsizei n, GLuint* samplers);
|
||||
MOBILEGL_GL_API GLuint glCreateShader(GLenum type);
|
||||
MOBILEGL_GL_API GLuint glCreateShaderProgramEXT(GLenum type, const GLchar* string);
|
||||
MOBILEGL_GL_API void glCreateStatesNV(GLsizei n, GLuint* states);
|
||||
MOBILEGL_GL_API void glCreateTextures(GLenum target, GLsizei n, GLuint* textures);
|
||||
MOBILEGL_GL_API void glCreateTransformFeedbacks(GLsizei n, GLuint* ids);
|
||||
MOBILEGL_GL_API void glCreateVertexArrays(GLsizei n, GLuint* arrays);
|
||||
MOBILEGL_GL_API void glCullFace(GLenum mode);
|
||||
MOBILEGL_GL_API void glDebugMessageControl(GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint* ids, GLboolean enabled);
|
||||
MOBILEGL_GL_API void glDebugMessageInsert(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* buf);
|
||||
MOBILEGL_GL_API void glDeleteBuffers(GLsizei n, const GLuint* buffers);
|
||||
MOBILEGL_GL_API void glDeleteCommandListsNV(GLsizei n, const GLuint* lists);
|
||||
MOBILEGL_GL_API void glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers);
|
||||
MOBILEGL_GL_API void glDeleteNamedStringARB(GLint namelen, const GLchar* name);
|
||||
MOBILEGL_GL_API void glDeletePathsNV(GLuint path, GLsizei range);
|
||||
MOBILEGL_GL_API void glDeletePerfMonitorsAMD(GLsizei n, GLuint* monitors);
|
||||
MOBILEGL_GL_API void glDeletePerfQueryINTEL(GLuint queryHandle);
|
||||
MOBILEGL_GL_API void glDeleteProgram(GLuint program);
|
||||
MOBILEGL_GL_API void glDeleteProgramPipelines(GLsizei n, const GLuint* pipelines);
|
||||
MOBILEGL_GL_API void glDeleteQueries(GLsizei n, const GLuint* ids);
|
||||
MOBILEGL_GL_API void glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers);
|
||||
MOBILEGL_GL_API void glDeleteSamplers(GLsizei count, const GLuint* samplers);
|
||||
MOBILEGL_GL_API void glDeleteShader(GLuint shader);
|
||||
MOBILEGL_GL_API void glDeleteStatesNV(GLsizei n, const GLuint* states);
|
||||
MOBILEGL_GL_API void glDeleteSync(GLsync sync);
|
||||
MOBILEGL_GL_API void glDeleteTextures(GLsizei n, const GLuint* textures);
|
||||
MOBILEGL_GL_API void glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids);
|
||||
MOBILEGL_GL_API void glDeleteVertexArrays(GLsizei n, const GLuint* arrays);
|
||||
MOBILEGL_GL_API void glDepthBoundsdNV(GLdouble zmin, GLdouble zmax);
|
||||
MOBILEGL_GL_API void glDepthFunc(GLenum func);
|
||||
MOBILEGL_GL_API void glDepthMask(GLboolean flag);
|
||||
MOBILEGL_GL_API void glDepthRange(GLclampd near_val, GLclampd far_val);
|
||||
MOBILEGL_GL_API void glDepthRangeArraydvNV(GLuint first, GLsizei count, const GLdouble* v);
|
||||
MOBILEGL_GL_API void glDepthRangeArrayv(GLuint first, GLsizei count, const GLdouble* v);
|
||||
MOBILEGL_GL_API void glDepthRangeIndexed(GLuint index, GLdouble n, GLdouble f);
|
||||
MOBILEGL_GL_API void glDepthRangeIndexeddNV(GLuint index, GLdouble n, GLdouble f);
|
||||
MOBILEGL_GL_API void glDepthRangedNV(GLdouble zNear, GLdouble zFar);
|
||||
MOBILEGL_GL_API void glDepthRangef(GLfloat n, GLfloat f);
|
||||
MOBILEGL_GL_API void glDetachShader(GLuint program, GLuint shader);
|
||||
MOBILEGL_GL_API void glDisable(GLenum cap);
|
||||
MOBILEGL_GL_API void glDisableClientStateIndexedEXT(GLenum array, GLuint index);
|
||||
MOBILEGL_GL_API void glDisableClientStateiEXT(GLenum array, GLuint index);
|
||||
MOBILEGL_GL_API void glDisableIndexedEXT(GLenum target, GLuint index);
|
||||
MOBILEGL_GL_API void glDisableVertexArrayAttrib(GLuint vaobj, GLuint index);
|
||||
MOBILEGL_GL_API void glDisableVertexArrayAttribEXT(GLuint vaobj, GLuint index);
|
||||
MOBILEGL_GL_API void glDisableVertexArrayEXT(GLuint vaobj, GLenum array);
|
||||
MOBILEGL_GL_API void glDisableVertexAttribArray(GLuint index);
|
||||
MOBILEGL_GL_API void glDisablei(GLenum target, GLuint index);
|
||||
MOBILEGL_GL_API void glDispatchCompute(GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z);
|
||||
MOBILEGL_GL_API void glDispatchComputeGroupSizeARB(GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z, GLuint group_size_x, GLuint group_size_y, GLuint group_size_z);
|
||||
MOBILEGL_GL_API void glDispatchComputeIndirect(GLintptr indirect);
|
||||
MOBILEGL_GL_API void glDrawArrays(GLenum mode, GLint first, GLsizei count);
|
||||
MOBILEGL_GL_API void glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instancecount);
|
||||
MOBILEGL_GL_API void glDrawArraysInstancedBaseInstance(GLenum mode, GLint first, GLsizei count, GLsizei instancecount, GLuint baseinstance);
|
||||
MOBILEGL_GL_API void glDrawBuffer(GLenum mode);
|
||||
MOBILEGL_GL_API void glDrawBuffers(GLsizei n, const GLenum* bufs);
|
||||
MOBILEGL_GL_API void glDrawCommandsAddressNV(GLenum primitiveMode, const GLuint64* indirects, const GLsizei* sizes, GLuint count);
|
||||
MOBILEGL_GL_API void glDrawCommandsStatesAddressNV(const GLuint64* indirects, const GLsizei* sizes, const GLuint* states, const GLuint* fbos, GLuint count);
|
||||
MOBILEGL_GL_API void glDrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices);
|
||||
MOBILEGL_GL_API void glDrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type, const void* indices, GLint basevertex);
|
||||
MOBILEGL_GL_API void glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const void* indices, GLsizei instancecount);
|
||||
MOBILEGL_GL_API void glDrawElementsInstancedBaseInstance(GLenum mode, GLsizei count, GLenum type, const void* indices, GLsizei instancecount, GLuint baseinstance);
|
||||
MOBILEGL_GL_API void glDrawElementsInstancedBaseVertex(GLenum mode, GLsizei count, GLenum type, const void* indices, GLsizei instancecount, GLint basevertex);
|
||||
MOBILEGL_GL_API void glDrawElementsInstancedBaseVertexBaseInstance(GLenum mode, GLsizei count, GLenum type, const void* indices, GLsizei instancecount, GLint basevertex, GLuint baseinstance);
|
||||
MOBILEGL_GL_API void glDrawMeshTasksIndirectNV(GLintptr indirect);
|
||||
MOBILEGL_GL_API void glDrawMeshTasksNV(GLuint first, GLuint count);
|
||||
MOBILEGL_GL_API void glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void* indices);
|
||||
MOBILEGL_GL_API void glDrawRangeElementsBaseVertex(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void* indices, GLint basevertex);
|
||||
MOBILEGL_GL_API void glDrawTransformFeedback(GLenum mode, GLuint id);
|
||||
MOBILEGL_GL_API void glDrawTransformFeedbackInstanced(GLenum mode, GLuint id, GLsizei instancecount);
|
||||
MOBILEGL_GL_API void glDrawTransformFeedbackStream(GLenum mode, GLuint id, GLuint stream);
|
||||
MOBILEGL_GL_API void glDrawTransformFeedbackStreamInstanced(GLenum mode, GLuint id, GLuint stream, GLsizei instancecount);
|
||||
MOBILEGL_GL_API void glDrawVkImageNV(GLuint64 vkImage, GLuint sampler, GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1, GLfloat z, GLfloat s0, GLfloat t0, GLfloat s1, GLfloat t1);
|
||||
MOBILEGL_GL_API void glEdgeFlagFormatNV(GLsizei stride);
|
||||
MOBILEGL_GL_API void glEnable(GLenum cap);
|
||||
MOBILEGL_GL_API void glEnableClientStateIndexedEXT(GLenum array, GLuint index);
|
||||
MOBILEGL_GL_API void glEnableClientStateiEXT(GLenum array, GLuint index);
|
||||
MOBILEGL_GL_API void glEnableIndexedEXT(GLenum target, GLuint index);
|
||||
MOBILEGL_GL_API void glEnableVertexArrayAttrib(GLuint vaobj, GLuint index);
|
||||
MOBILEGL_GL_API void glEnableVertexArrayAttribEXT(GLuint vaobj, GLuint index);
|
||||
MOBILEGL_GL_API void glEnableVertexArrayEXT(GLuint vaobj, GLenum array);
|
||||
MOBILEGL_GL_API void glEnableVertexAttribArray(GLuint index);
|
||||
MOBILEGL_GL_API void glEnablei(GLenum target, GLuint index);
|
||||
MOBILEGL_GL_API void glEndPerfMonitorAMD(GLuint monitor);
|
||||
MOBILEGL_GL_API void glEndPerfQueryINTEL(GLuint queryHandle);
|
||||
MOBILEGL_GL_API void glEndQuery(GLenum target);
|
||||
MOBILEGL_GL_API void glEndQueryIndexed(GLenum target, GLuint index);
|
||||
MOBILEGL_GL_API void glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length);
|
||||
MOBILEGL_GL_API void glFlushMappedNamedBufferRange(GLuint buffer, GLintptr offset, GLsizeiptr length);
|
||||
MOBILEGL_GL_API void glFlushMappedNamedBufferRangeEXT(GLuint buffer, GLintptr offset, GLsizeiptr length);
|
||||
MOBILEGL_GL_API void glFogCoordFormatNV(GLenum type, GLsizei stride);
|
||||
MOBILEGL_GL_API void glFragmentCoverageColorNV(GLuint color);
|
||||
MOBILEGL_GL_API void glFramebufferDrawBufferEXT(GLuint framebuffer, GLenum mode);
|
||||
MOBILEGL_GL_API void glFramebufferDrawBuffersEXT(GLuint framebuffer, GLsizei n, const GLenum* bufs);
|
||||
MOBILEGL_GL_API void glFramebufferParameteri(GLenum target, GLenum pname, GLint param);
|
||||
MOBILEGL_GL_API void glFramebufferParameteriMESA(GLenum target, GLenum pname, GLint param);
|
||||
MOBILEGL_GL_API void glFramebufferReadBufferEXT(GLuint framebuffer, GLenum mode);
|
||||
MOBILEGL_GL_API void glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
|
||||
MOBILEGL_GL_API void glFramebufferSampleLocationsfvARB(GLenum target, GLuint start, GLsizei count, const GLfloat* v);
|
||||
MOBILEGL_GL_API void glFramebufferSampleLocationsfvNV(GLenum target, GLuint start, GLsizei count, const GLfloat* v);
|
||||
MOBILEGL_GL_API void glFramebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level);
|
||||
MOBILEGL_GL_API void glFramebufferTexture1D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
|
||||
MOBILEGL_GL_API void glFramebufferTexture1DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
|
||||
MOBILEGL_GL_API void glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
|
||||
MOBILEGL_GL_API void glFramebufferTexture3D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
|
||||
MOBILEGL_GL_API void glFramebufferTexture3DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
|
||||
MOBILEGL_GL_API void glFramebufferTextureFaceARB(GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face);
|
||||
MOBILEGL_GL_API void glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer);
|
||||
MOBILEGL_GL_API void glFramebufferTextureMultiviewOVR(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint baseViewIndex, GLsizei numViews);
|
||||
MOBILEGL_GL_API void glFrontFace(GLenum mode);
|
||||
MOBILEGL_GL_API void glGenBuffers(GLsizei n, GLuint* buffers);
|
||||
MOBILEGL_GL_API void glGenFramebuffers(GLsizei n, GLuint* framebuffers);
|
||||
MOBILEGL_GL_API GLuint glGenPathsNV(GLsizei range);
|
||||
MOBILEGL_GL_API void glGenPerfMonitorsAMD(GLsizei n, GLuint* monitors);
|
||||
MOBILEGL_GL_API void glGenProgramPipelines(GLsizei n, GLuint* pipelines);
|
||||
MOBILEGL_GL_API void glGenQueries(GLsizei n, GLuint* ids);
|
||||
MOBILEGL_GL_API void glGenRenderbuffers(GLsizei n, GLuint* renderbuffers);
|
||||
MOBILEGL_GL_API void glGenSamplers(GLsizei count, GLuint* samplers);
|
||||
MOBILEGL_GL_API void glGenTextures(GLsizei n, GLuint* textures);
|
||||
MOBILEGL_GL_API void glGenTransformFeedbacks(GLsizei n, GLuint* ids);
|
||||
MOBILEGL_GL_API void glGenVertexArrays(GLsizei n, GLuint* arrays);
|
||||
MOBILEGL_GL_API void glGenerateMipmap(GLenum target);
|
||||
MOBILEGL_GL_API void glGenerateMultiTexMipmapEXT(GLenum texunit, GLenum target);
|
||||
MOBILEGL_GL_API void glGenerateTextureMipmap(GLuint texture);
|
||||
MOBILEGL_GL_API void glGenerateTextureMipmapEXT(GLuint texture, GLenum target);
|
||||
MOBILEGL_GL_API void glGetActiveAtomicCounterBufferiv(GLuint program, GLuint bufferIndex, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetActiveSubroutineUniformiv(GLuint program, GLenum shadertype, GLuint index, GLenum pname, GLint* values);
|
||||
MOBILEGL_GL_API void glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API GLint glGetAttribLocation(GLuint program, const GLchar* name);
|
||||
MOBILEGL_GL_API void glGetBooleanv(GLenum pname, GLboolean* data);
|
||||
MOBILEGL_GL_API void glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params);
|
||||
MOBILEGL_GL_API void glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetBufferParameterui64vNV(GLenum target, GLenum pname, GLuint64EXT* params);
|
||||
MOBILEGL_GL_API void glGetBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, void* data);
|
||||
MOBILEGL_GL_API GLuint glGetCommandHeaderNV(GLenum tokenID, GLuint size);
|
||||
MOBILEGL_GL_API GLuint glGetDebugMessageLog(GLuint count, GLsizei bufSize, GLenum* sources, GLenum* types, GLuint* ids, GLenum* severities, GLsizei* lengths, GLchar* messageLog);
|
||||
MOBILEGL_GL_API void glGetDoublei_vEXT(GLenum pname, GLuint index, GLdouble* params);
|
||||
MOBILEGL_GL_API void glGetDoublev(GLenum pname, GLdouble* params);
|
||||
MOBILEGL_GL_API void glGetFloati_vEXT(GLenum pname, GLuint index, GLfloat* params);
|
||||
MOBILEGL_GL_API void glGetFloatv(GLenum pname, GLfloat* data);
|
||||
MOBILEGL_GL_API GLint glGetFragDataIndex(GLuint program, const GLchar* name);
|
||||
MOBILEGL_GL_API GLint glGetFragDataLocation(GLuint program, const GLchar* name);
|
||||
MOBILEGL_GL_API void glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetFramebufferParameteriv(GLenum target, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetFramebufferParameterivMESA(GLenum target, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API GLuint64 glGetImageHandleARB(GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum format);
|
||||
MOBILEGL_GL_API GLuint64 glGetImageHandleNV(GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum format);
|
||||
MOBILEGL_GL_API void glGetInteger64v(GLenum pname, GLint64* data);
|
||||
MOBILEGL_GL_API void glGetIntegerv(GLenum pname, GLint* data);
|
||||
MOBILEGL_GL_API void glGetInternalformatSampleivNV(GLenum target, GLenum internalformat, GLsizei samples, GLenum pname, GLsizei count, GLint* params);
|
||||
MOBILEGL_GL_API void glGetInternalformati64v(GLenum target, GLenum internalformat, GLenum pname, GLsizei count, GLint64* params);
|
||||
MOBILEGL_GL_API void glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params);
|
||||
MOBILEGL_GL_API void glGetMemoryObjectDetachedResourcesuivNV(GLuint memory, GLenum pname, GLint first, GLsizei count, GLuint* params);
|
||||
MOBILEGL_GL_API void glGetMultiTexEnvfvEXT(GLenum texunit, GLenum target, GLenum pname, GLfloat* params);
|
||||
MOBILEGL_GL_API void glGetMultiTexEnvivEXT(GLenum texunit, GLenum target, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetMultiTexGendvEXT(GLenum texunit, GLenum coord, GLenum pname, GLdouble* params);
|
||||
MOBILEGL_GL_API void glGetMultiTexGenfvEXT(GLenum texunit, GLenum coord, GLenum pname, GLfloat* params);
|
||||
MOBILEGL_GL_API void glGetMultiTexGenivEXT(GLenum texunit, GLenum coord, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetMultiTexLevelParameterfvEXT(GLenum texunit, GLenum target, GLint level, GLenum pname, GLfloat* params);
|
||||
MOBILEGL_GL_API void glGetMultiTexLevelParameterivEXT(GLenum texunit, GLenum target, GLint level, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetMultiTexParameterIivEXT(GLenum texunit, GLenum target, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetMultiTexParameterIuivEXT(GLenum texunit, GLenum target, GLenum pname, GLuint* params);
|
||||
MOBILEGL_GL_API void glGetMultiTexParameterfvEXT(GLenum texunit, GLenum target, GLenum pname, GLfloat* params);
|
||||
MOBILEGL_GL_API void glGetMultiTexParameterivEXT(GLenum texunit, GLenum target, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetMultisamplefv(GLenum pname, GLuint index, GLfloat* val);
|
||||
MOBILEGL_GL_API void glGetNamedBufferParameteri64v(GLuint buffer, GLenum pname, GLint64* params);
|
||||
MOBILEGL_GL_API void glGetNamedBufferParameteriv(GLuint buffer, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetNamedBufferParameterivEXT(GLuint buffer, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetNamedBufferParameterui64vNV(GLuint buffer, GLenum pname, GLuint64EXT* params);
|
||||
MOBILEGL_GL_API void glGetNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizeiptr size, void* data);
|
||||
MOBILEGL_GL_API void glGetNamedBufferSubDataEXT(GLuint buffer, GLintptr offset, GLsizeiptr size, void* data);
|
||||
MOBILEGL_GL_API void glGetNamedFramebufferAttachmentParameteriv(GLuint framebuffer, GLenum attachment, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetNamedFramebufferAttachmentParameterivEXT(GLuint framebuffer, GLenum attachment, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetNamedFramebufferParameteriv(GLuint framebuffer, GLenum pname, GLint* param);
|
||||
MOBILEGL_GL_API void glGetNamedFramebufferParameterivEXT(GLuint framebuffer, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetNamedProgramivEXT(GLuint program, GLenum target, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetNamedRenderbufferParameteriv(GLuint renderbuffer, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetNamedRenderbufferParameterivEXT(GLuint renderbuffer, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetNamedStringivARB(GLint namelen, const GLchar* name, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API GLfloat glGetPathLengthNV(GLuint path, GLsizei startSegment, GLsizei numSegments);
|
||||
MOBILEGL_GL_API void glGetPathParameterfvNV(GLuint path, GLenum pname, GLfloat* value);
|
||||
MOBILEGL_GL_API void glGetPathParameterivNV(GLuint path, GLenum pname, GLint* value);
|
||||
MOBILEGL_GL_API void glGetPerfMonitorCounterDataAMD(GLuint monitor, GLenum pname, GLsizei dataSize, GLuint* data, GLint* bytesWritten);
|
||||
MOBILEGL_GL_API void glGetProgramInterfaceiv(GLuint program, GLenum programInterface, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetProgramPipelineiv(GLuint pipeline, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API GLuint glGetProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar* name);
|
||||
MOBILEGL_GL_API GLint glGetProgramResourceLocation(GLuint program, GLenum programInterface, const GLchar* name);
|
||||
MOBILEGL_GL_API GLint glGetProgramResourceLocationIndex(GLuint program, GLenum programInterface, const GLchar* name);
|
||||
MOBILEGL_GL_API void glGetProgramResourcefvNV(GLuint program, GLenum programInterface, GLuint index, GLsizei propCount, const GLenum* props, GLsizei count, GLsizei* length, GLfloat* params);
|
||||
MOBILEGL_GL_API void glGetProgramStageiv(GLuint program, GLenum shadertype, GLenum pname, GLint* values);
|
||||
MOBILEGL_GL_API void glGetProgramiv(GLuint program, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetQueryBufferObjecti64v(GLuint id, GLuint buffer, GLenum pname, GLintptr offset);
|
||||
MOBILEGL_GL_API void glGetQueryBufferObjectiv(GLuint id, GLuint buffer, GLenum pname, GLintptr offset);
|
||||
MOBILEGL_GL_API void glGetQueryBufferObjectui64v(GLuint id, GLuint buffer, GLenum pname, GLintptr offset);
|
||||
MOBILEGL_GL_API void glGetQueryBufferObjectuiv(GLuint id, GLuint buffer, GLenum pname, GLintptr offset);
|
||||
MOBILEGL_GL_API void glGetQueryIndexediv(GLenum target, GLuint index, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetQueryObjecti64v(GLuint id, GLenum pname, GLint64* params);
|
||||
MOBILEGL_GL_API void glGetQueryObjectiv(GLuint id, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetQueryObjectui64v(GLuint id, GLenum pname, GLuint64* params);
|
||||
MOBILEGL_GL_API void glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params);
|
||||
MOBILEGL_GL_API void glGetQueryiv(GLenum target, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetSamplerParameterIiv(GLuint sampler, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetSamplerParameterIuiv(GLuint sampler, GLenum pname, GLuint* params);
|
||||
MOBILEGL_GL_API void glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params);
|
||||
MOBILEGL_GL_API void glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetShaderiv(GLuint shader, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API GLushort glGetStageIndexNV(GLenum shadertype);
|
||||
MOBILEGL_GL_API const GLubyte* glGetString(GLenum name);
|
||||
MOBILEGL_GL_API const GLubyte* glGetStringi(GLenum name, GLuint index);
|
||||
MOBILEGL_GL_API GLuint glGetSubroutineIndex(GLuint program, GLenum shadertype, const GLchar* name);
|
||||
MOBILEGL_GL_API GLint glGetSubroutineUniformLocation(GLuint program, GLenum shadertype, const GLchar* name);
|
||||
MOBILEGL_GL_API void glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values);
|
||||
MOBILEGL_GL_API void glGetTexLevelParameterfv(GLenum target, GLint level, GLenum pname, GLfloat* params);
|
||||
MOBILEGL_GL_API void glGetTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetTexParameterIiv(GLenum target, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetTexParameterIuiv(GLenum target, GLenum pname, GLuint* params);
|
||||
MOBILEGL_GL_API void glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params);
|
||||
MOBILEGL_GL_API void glGetTexParameteriv(GLenum target, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API GLuint64 glGetTextureHandleARB(GLuint texture);
|
||||
MOBILEGL_GL_API GLuint64 glGetTextureHandleNV(GLuint texture);
|
||||
MOBILEGL_GL_API void glGetTextureLevelParameterfv(GLuint texture, GLint level, GLenum pname, GLfloat* params);
|
||||
MOBILEGL_GL_API void glGetTextureLevelParameterfvEXT(GLuint texture, GLenum target, GLint level, GLenum pname, GLfloat* params);
|
||||
MOBILEGL_GL_API void glGetTextureLevelParameteriv(GLuint texture, GLint level, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetTextureLevelParameterivEXT(GLuint texture, GLenum target, GLint level, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetTextureParameterIiv(GLuint texture, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetTextureParameterIivEXT(GLuint texture, GLenum target, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetTextureParameterIuiv(GLuint texture, GLenum pname, GLuint* params);
|
||||
MOBILEGL_GL_API void glGetTextureParameterIuivEXT(GLuint texture, GLenum target, GLenum pname, GLuint* params);
|
||||
MOBILEGL_GL_API void glGetTextureParameterfv(GLuint texture, GLenum pname, GLfloat* params);
|
||||
MOBILEGL_GL_API void glGetTextureParameterfvEXT(GLuint texture, GLenum target, GLenum pname, GLfloat* params);
|
||||
MOBILEGL_GL_API void glGetTextureParameteriv(GLuint texture, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetTextureParameterivEXT(GLuint texture, GLenum target, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API GLuint64 glGetTextureSamplerHandleARB(GLuint texture, GLuint sampler);
|
||||
MOBILEGL_GL_API GLuint64 glGetTextureSamplerHandleNV(GLuint texture, GLuint sampler);
|
||||
MOBILEGL_GL_API void glGetTransformFeedbacki64_v(GLuint xfb, GLenum pname, GLuint index, GLint64* param);
|
||||
MOBILEGL_GL_API void glGetTransformFeedbacki_v(GLuint xfb, GLenum pname, GLuint index, GLint* param);
|
||||
MOBILEGL_GL_API void glGetTransformFeedbackiv(GLuint xfb, GLenum pname, GLint* param);
|
||||
MOBILEGL_GL_API GLuint glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName);
|
||||
MOBILEGL_GL_API GLint glGetUniformLocation(GLuint program, const GLchar* name);
|
||||
MOBILEGL_GL_API void glGetVertexArrayIndexed64iv(GLuint vaobj, GLuint index, GLenum pname, GLint64* param);
|
||||
MOBILEGL_GL_API void glGetVertexArrayIndexediv(GLuint vaobj, GLuint index, GLenum pname, GLint* param);
|
||||
MOBILEGL_GL_API void glGetVertexArrayIntegeri_vEXT(GLuint vaobj, GLuint index, GLenum pname, GLint* param);
|
||||
MOBILEGL_GL_API void glGetVertexArrayIntegervEXT(GLuint vaobj, GLenum pname, GLint* param);
|
||||
MOBILEGL_GL_API void glGetVertexArrayiv(GLuint vaobj, GLenum pname, GLint* param);
|
||||
MOBILEGL_GL_API void glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params);
|
||||
MOBILEGL_GL_API void glGetVertexAttribLdv(GLuint index, GLenum pname, GLdouble* params);
|
||||
MOBILEGL_GL_API void glGetVertexAttribLi64vNV(GLuint index, GLenum pname, GLint64EXT* params);
|
||||
MOBILEGL_GL_API void glGetVertexAttribLui64vARB(GLuint index, GLenum pname, GLuint64EXT* params);
|
||||
MOBILEGL_GL_API void glGetVertexAttribLui64vNV(GLuint index, GLenum pname, GLuint64EXT* params);
|
||||
MOBILEGL_GL_API void glGetVertexAttribdv(GLuint index, GLenum pname, GLdouble* params);
|
||||
MOBILEGL_GL_API void glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params);
|
||||
MOBILEGL_GL_API void glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params);
|
||||
MOBILEGL_GL_API void glHint(GLenum target, GLenum mode);
|
||||
MOBILEGL_GL_API void glIndexFormatNV(GLenum type, GLsizei stride);
|
||||
MOBILEGL_GL_API void glInsertEventMarkerEXT(GLsizei length, const GLchar* marker);
|
||||
MOBILEGL_GL_API void glInterpolatePathsNV(GLuint resultPath, GLuint pathA, GLuint pathB, GLfloat weight);
|
||||
MOBILEGL_GL_API void glInvalidateBufferData(GLuint buffer);
|
||||
MOBILEGL_GL_API void glInvalidateBufferSubData(GLuint buffer, GLintptr offset, GLsizeiptr length);
|
||||
MOBILEGL_GL_API void glInvalidateTexImage(GLuint texture, GLint level);
|
||||
MOBILEGL_GL_API void glInvalidateTexSubImage(GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth);
|
||||
MOBILEGL_GL_API GLboolean glIsBuffer(GLuint buffer);
|
||||
MOBILEGL_GL_API GLboolean glIsBufferResidentNV(GLenum target);
|
||||
MOBILEGL_GL_API GLboolean glIsCommandListNV(GLuint list);
|
||||
MOBILEGL_GL_API GLboolean glIsEnabled(GLenum cap);
|
||||
MOBILEGL_GL_API GLboolean glIsEnabledIndexedEXT(GLenum target, GLuint index);
|
||||
MOBILEGL_GL_API GLboolean glIsEnabledi(GLenum target, GLuint index);
|
||||
MOBILEGL_GL_API GLboolean glIsFramebuffer(GLuint framebuffer);
|
||||
MOBILEGL_GL_API GLboolean glIsImageHandleResidentARB(GLuint64 handle);
|
||||
MOBILEGL_GL_API GLboolean glIsImageHandleResidentNV(GLuint64 handle);
|
||||
MOBILEGL_GL_API GLboolean glIsNamedBufferResidentNV(GLuint buffer);
|
||||
MOBILEGL_GL_API GLboolean glIsNamedStringARB(GLint namelen, const GLchar* name);
|
||||
MOBILEGL_GL_API GLboolean glIsPathNV(GLuint path);
|
||||
MOBILEGL_GL_API GLboolean glIsPointInFillPathNV(GLuint path, GLuint mask, GLfloat x, GLfloat y);
|
||||
MOBILEGL_GL_API GLboolean glIsPointInStrokePathNV(GLuint path, GLfloat x, GLfloat y);
|
||||
MOBILEGL_GL_API GLboolean glIsProgram(GLuint program);
|
||||
MOBILEGL_GL_API GLboolean glIsProgramPipeline(GLuint pipeline);
|
||||
MOBILEGL_GL_API GLboolean glIsQuery(GLuint id);
|
||||
MOBILEGL_GL_API GLboolean glIsRenderbuffer(GLuint renderbuffer);
|
||||
MOBILEGL_GL_API GLboolean glIsSampler(GLuint sampler);
|
||||
MOBILEGL_GL_API GLboolean glIsShader(GLuint shader);
|
||||
MOBILEGL_GL_API GLboolean glIsStateNV(GLuint state);
|
||||
MOBILEGL_GL_API GLboolean glIsSync(GLsync sync);
|
||||
MOBILEGL_GL_API GLboolean glIsTexture(GLuint texture);
|
||||
MOBILEGL_GL_API GLboolean glIsTextureHandleResidentARB(GLuint64 handle);
|
||||
MOBILEGL_GL_API GLboolean glIsTextureHandleResidentNV(GLuint64 handle);
|
||||
MOBILEGL_GL_API GLboolean glIsTransformFeedback(GLuint id);
|
||||
MOBILEGL_GL_API GLboolean glIsVertexArray(GLuint array);
|
||||
MOBILEGL_GL_API void glLabelObjectEXT(GLenum type, GLuint object, GLsizei length, const GLchar* label);
|
||||
MOBILEGL_GL_API void glLineWidth(GLfloat width);
|
||||
MOBILEGL_GL_API void glLinkProgram(GLuint program);
|
||||
MOBILEGL_GL_API void glLogicOp(GLenum opcode);
|
||||
MOBILEGL_GL_API void glMakeBufferNonResidentNV(GLenum target);
|
||||
MOBILEGL_GL_API void glMakeBufferResidentNV(GLenum target, GLenum access);
|
||||
MOBILEGL_GL_API void glMakeImageHandleNonResidentARB(GLuint64 handle);
|
||||
MOBILEGL_GL_API void glMakeImageHandleNonResidentNV(GLuint64 handle);
|
||||
MOBILEGL_GL_API void glMakeImageHandleResidentARB(GLuint64 handle, GLenum access);
|
||||
MOBILEGL_GL_API void glMakeImageHandleResidentNV(GLuint64 handle, GLenum access);
|
||||
MOBILEGL_GL_API void glMakeNamedBufferNonResidentNV(GLuint buffer);
|
||||
MOBILEGL_GL_API void glMakeNamedBufferResidentNV(GLuint buffer, GLenum access);
|
||||
MOBILEGL_GL_API void glMakeTextureHandleNonResidentARB(GLuint64 handle);
|
||||
MOBILEGL_GL_API void glMakeTextureHandleNonResidentNV(GLuint64 handle);
|
||||
MOBILEGL_GL_API void glMakeTextureHandleResidentARB(GLuint64 handle);
|
||||
MOBILEGL_GL_API void glMakeTextureHandleResidentNV(GLuint64 handle);
|
||||
MOBILEGL_GL_API void* glMapBuffer(GLenum target, GLenum access);
|
||||
MOBILEGL_GL_API void* glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access);
|
||||
MOBILEGL_GL_API void glMatrixFrustumEXT(GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
|
||||
MOBILEGL_GL_API void glMatrixLoadIdentityEXT(GLenum mode);
|
||||
MOBILEGL_GL_API void glMatrixOrthoEXT(GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
|
||||
MOBILEGL_GL_API void glMatrixPopEXT(GLenum mode);
|
||||
MOBILEGL_GL_API void glMatrixPushEXT(GLenum mode);
|
||||
MOBILEGL_GL_API void glMatrixRotatedEXT(GLenum mode, GLdouble ane, GLdouble x, GLdouble y, GLdouble z);
|
||||
MOBILEGL_GL_API void glMatrixRotatefEXT(GLenum mode, GLfloat ane, GLfloat x, GLfloat y, GLfloat z);
|
||||
MOBILEGL_GL_API void glMatrixScaledEXT(GLenum mode, GLdouble x, GLdouble y, GLdouble z);
|
||||
MOBILEGL_GL_API void glMatrixScalefEXT(GLenum mode, GLfloat x, GLfloat y, GLfloat z);
|
||||
MOBILEGL_GL_API void glMatrixTranslatedEXT(GLenum mode, GLdouble x, GLdouble y, GLdouble z);
|
||||
MOBILEGL_GL_API void glMatrixTranslatefEXT(GLenum mode, GLfloat x, GLfloat y, GLfloat z);
|
||||
MOBILEGL_GL_API void glMaxShaderCompilerThreadsARB(GLuint count);
|
||||
MOBILEGL_GL_API void glMaxShaderCompilerThreadsKHR(GLuint count);
|
||||
MOBILEGL_GL_API void glMemoryBarrier(GLbitfield barriers);
|
||||
MOBILEGL_GL_API void glMemoryBarrierByRegion(GLbitfield barriers);
|
||||
MOBILEGL_GL_API void glMinSampleShading(GLfloat value);
|
||||
MOBILEGL_GL_API void glMultiDrawMeshTasksIndirectCountNV(GLintptr indirect, GLintptr drawcount, GLsizei maxdrawcount, GLsizei stride);
|
||||
MOBILEGL_GL_API void glMultiDrawMeshTasksIndirectNV(GLintptr indirect, GLsizei drawcount, GLsizei stride);
|
||||
MOBILEGL_GL_API void glMultiTexBufferEXT(GLenum texunit, GLenum target, GLenum internalformat, GLuint buffer);
|
||||
MOBILEGL_GL_API void glMultiTexCoordPointerEXT(GLenum texunit, GLint size, GLenum type, GLsizei stride, const void* pointer);
|
||||
MOBILEGL_GL_API void glMultiTexEnvfEXT(GLenum texunit, GLenum target, GLenum pname, GLfloat param);
|
||||
MOBILEGL_GL_API void glMultiTexEnviEXT(GLenum texunit, GLenum target, GLenum pname, GLint param);
|
||||
MOBILEGL_GL_API void glMultiTexGendEXT(GLenum texunit, GLenum coord, GLenum pname, GLdouble param);
|
||||
MOBILEGL_GL_API void glMultiTexGenfEXT(GLenum texunit, GLenum coord, GLenum pname, GLfloat param);
|
||||
MOBILEGL_GL_API void glMultiTexGeniEXT(GLenum texunit, GLenum coord, GLenum pname, GLint param);
|
||||
MOBILEGL_GL_API void glMultiTexParameterfEXT(GLenum texunit, GLenum target, GLenum pname, GLfloat param);
|
||||
MOBILEGL_GL_API void glMultiTexParameteriEXT(GLenum texunit, GLenum target, GLenum pname, GLint param);
|
||||
MOBILEGL_GL_API void glMultiTexRenderbufferEXT(GLenum texunit, GLenum target, GLuint renderbuffer);
|
||||
MOBILEGL_GL_API void glNamedBufferAttachMemoryNV(GLuint buffer, GLuint memory, GLuint64 offset);
|
||||
MOBILEGL_GL_API void glNamedBufferData(GLuint buffer, GLsizeiptr size, const void* data, GLenum usage);
|
||||
MOBILEGL_GL_API void glNamedBufferDataEXT(GLuint buffer, GLsizeiptr size, const void* data, GLenum usage);
|
||||
MOBILEGL_GL_API void glNamedBufferPageCommitmentARB(GLuint buffer, GLintptr offset, GLsizeiptr size, GLboolean commit);
|
||||
MOBILEGL_GL_API void glNamedBufferPageCommitmentEXT(GLuint buffer, GLintptr offset, GLsizeiptr size, GLboolean commit);
|
||||
MOBILEGL_GL_API void glNamedBufferPageCommitmentMemNV(GLuint buffer, GLintptr offset, GLsizeiptr size, GLuint memory, GLuint64 memOffset, GLboolean commit);
|
||||
MOBILEGL_GL_API void glNamedBufferStorage(GLuint buffer, GLsizeiptr size, const void* data, GLbitfield flags);
|
||||
MOBILEGL_GL_API void glNamedBufferStorageEXT(GLuint buffer, GLsizeiptr size, const void* data, GLbitfield flags);
|
||||
MOBILEGL_GL_API void glNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizeiptr size, const void* data);
|
||||
MOBILEGL_GL_API void glNamedBufferSubDataEXT(GLuint buffer, GLintptr offset, GLsizeiptr size, const void* data);
|
||||
MOBILEGL_GL_API void glNamedCopyBufferSubDataEXT(GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
|
||||
MOBILEGL_GL_API void glNamedFramebufferDrawBuffer(GLuint framebuffer, GLenum buf);
|
||||
MOBILEGL_GL_API void glNamedFramebufferDrawBuffers(GLuint framebuffer, GLsizei n, const GLenum* bufs);
|
||||
MOBILEGL_GL_API void glNamedFramebufferParameteri(GLuint framebuffer, GLenum pname, GLint param);
|
||||
MOBILEGL_GL_API void glNamedFramebufferParameteriEXT(GLuint framebuffer, GLenum pname, GLint param);
|
||||
MOBILEGL_GL_API void glNamedFramebufferReadBuffer(GLuint framebuffer, GLenum src);
|
||||
MOBILEGL_GL_API void glNamedFramebufferRenderbuffer(GLuint framebuffer, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
|
||||
MOBILEGL_GL_API void glNamedFramebufferRenderbufferEXT(GLuint framebuffer, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
|
||||
MOBILEGL_GL_API void glNamedFramebufferSampleLocationsfvARB(GLuint framebuffer, GLuint start, GLsizei count, const GLfloat* v);
|
||||
MOBILEGL_GL_API void glNamedFramebufferSampleLocationsfvNV(GLuint framebuffer, GLuint start, GLsizei count, const GLfloat* v);
|
||||
MOBILEGL_GL_API void glNamedFramebufferTexture(GLuint framebuffer, GLenum attachment, GLuint texture, GLint level);
|
||||
MOBILEGL_GL_API void glNamedFramebufferTexture1DEXT(GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
|
||||
MOBILEGL_GL_API void glNamedFramebufferTexture2DEXT(GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
|
||||
MOBILEGL_GL_API void glNamedFramebufferTexture3DEXT(GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
|
||||
MOBILEGL_GL_API void glNamedFramebufferTextureEXT(GLuint framebuffer, GLenum attachment, GLuint texture, GLint level);
|
||||
MOBILEGL_GL_API void glNamedFramebufferTextureFaceEXT(GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLenum face);
|
||||
MOBILEGL_GL_API void glNamedFramebufferTextureLayer(GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLint layer);
|
||||
MOBILEGL_GL_API void glNamedFramebufferTextureLayerEXT(GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLint layer);
|
||||
MOBILEGL_GL_API void glNamedProgramLocalParameter4dEXT(GLuint program, GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
|
||||
MOBILEGL_GL_API void glNamedProgramLocalParameter4fEXT(GLuint program, GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
|
||||
MOBILEGL_GL_API void glNamedProgramLocalParameterI4iEXT(GLuint program, GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w);
|
||||
MOBILEGL_GL_API void glNamedProgramLocalParameterI4uiEXT(GLuint program, GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w);
|
||||
MOBILEGL_GL_API void glNamedProgramLocalParameters4fvEXT(GLuint program, GLenum target, GLuint index, GLsizei count, const GLfloat* params);
|
||||
MOBILEGL_GL_API void glNamedProgramLocalParametersI4ivEXT(GLuint program, GLenum target, GLuint index, GLsizei count, const GLint* params);
|
||||
MOBILEGL_GL_API void glNamedProgramLocalParametersI4uivEXT(GLuint program, GLenum target, GLuint index, GLsizei count, const GLuint* params);
|
||||
MOBILEGL_GL_API void glNamedRenderbufferStorage(GLuint renderbuffer, GLenum internalformat, GLsizei width, GLsizei height);
|
||||
MOBILEGL_GL_API void glNamedRenderbufferStorageEXT(GLuint renderbuffer, GLenum internalformat, GLsizei width, GLsizei height);
|
||||
MOBILEGL_GL_API void glNamedRenderbufferStorageMultisample(GLuint renderbuffer, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
|
||||
MOBILEGL_GL_API void glNamedRenderbufferStorageMultisampleAdvancedAMD(GLuint renderbuffer, GLsizei samples, GLsizei storageSamples, GLenum internalformat, GLsizei width, GLsizei height);
|
||||
MOBILEGL_GL_API void glNamedRenderbufferStorageMultisampleCoverageEXT(GLuint renderbuffer, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height);
|
||||
MOBILEGL_GL_API void glNamedRenderbufferStorageMultisampleEXT(GLuint renderbuffer, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
|
||||
MOBILEGL_GL_API void glNamedStringARB(GLenum type, GLint namelen, const GLchar* name, GLint strinen, const GLchar* string);
|
||||
MOBILEGL_GL_API void glNormalFormatNV(GLenum type, GLsizei stride);
|
||||
MOBILEGL_GL_API void glObjectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar* label);
|
||||
MOBILEGL_GL_API void glObjectPtrLabel(const void* ptr, GLsizei length, const GLchar* label);
|
||||
MOBILEGL_GL_API void glPatchParameteri(GLenum pname, GLint value);
|
||||
MOBILEGL_GL_API void glPathCoverDepthFuncNV(GLenum func);
|
||||
MOBILEGL_GL_API void glPathParameterfNV(GLuint path, GLenum pname, GLfloat value);
|
||||
MOBILEGL_GL_API void glPathParameteriNV(GLuint path, GLenum pname, GLint value);
|
||||
MOBILEGL_GL_API void glPathStencilDepthOffsetNV(GLfloat factor, GLfloat units);
|
||||
MOBILEGL_GL_API void glPathStencilFuncNV(GLenum func, GLint ref, GLuint mask);
|
||||
MOBILEGL_GL_API void glPathStringNV(GLuint path, GLenum format, GLsizei length, const void* pathString);
|
||||
MOBILEGL_GL_API void glPixelStoref(GLenum pname, GLfloat param);
|
||||
MOBILEGL_GL_API void glPixelStorei(GLenum pname, GLint param);
|
||||
MOBILEGL_GL_API void glPointParameterf(GLenum pname, GLfloat param);
|
||||
MOBILEGL_GL_API void glPointParameteri(GLenum pname, GLint param);
|
||||
MOBILEGL_GL_API void glPointSize(GLfloat size);
|
||||
MOBILEGL_GL_API void glPolygonMode(GLenum face, GLenum mode);
|
||||
MOBILEGL_GL_API void glPolygonOffset(GLfloat factor, GLfloat units);
|
||||
MOBILEGL_GL_API void glPolygonOffsetClamp(GLfloat factor, GLfloat units, GLfloat clamp);
|
||||
MOBILEGL_GL_API void glPolygonOffsetClampEXT(GLfloat factor, GLfloat units, GLfloat clamp);
|
||||
MOBILEGL_GL_API void glPrimitiveBoundingBoxARB(GLfloat minX, GLfloat minY, GLfloat minZ, GLfloat minW, GLfloat maxX, GLfloat maxY, GLfloat maxZ, GLfloat maxW);
|
||||
MOBILEGL_GL_API void glPrimitiveRestartIndex(GLuint index);
|
||||
MOBILEGL_GL_API void glProgramBinary(GLuint program, GLenum binaryFormat, const void* binary, GLsizei length);
|
||||
MOBILEGL_GL_API void glProgramParameteri(GLuint program, GLenum pname, GLint value);
|
||||
MOBILEGL_GL_API void glProgramUniform1d(GLuint program, GLint location, GLdouble v0);
|
||||
MOBILEGL_GL_API void glProgramUniform1dEXT(GLuint program, GLint location, GLdouble x);
|
||||
MOBILEGL_GL_API void glProgramUniform1dv(GLuint program, GLint location, GLsizei count, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glProgramUniform1dvEXT(GLuint program, GLint location, GLsizei count, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glProgramUniform1f(GLuint program, GLint location, GLfloat v0);
|
||||
MOBILEGL_GL_API void glProgramUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat* value);
|
||||
MOBILEGL_GL_API void glProgramUniform1i(GLuint program, GLint location, GLint v0);
|
||||
MOBILEGL_GL_API void glProgramUniform1i64ARB(GLuint program, GLint location, GLint64 x);
|
||||
MOBILEGL_GL_API void glProgramUniform1i64NV(GLuint program, GLint location, GLint64EXT x);
|
||||
MOBILEGL_GL_API void glProgramUniform1i64vARB(GLuint program, GLint location, GLsizei count, const GLint64* value);
|
||||
MOBILEGL_GL_API void glProgramUniform1i64vNV(GLuint program, GLint location, GLsizei count, const GLint64EXT* value);
|
||||
MOBILEGL_GL_API void glProgramUniform1iv(GLuint program, GLint location, GLsizei count, const GLint* value);
|
||||
MOBILEGL_GL_API void glProgramUniform1ui(GLuint program, GLint location, GLuint v0);
|
||||
MOBILEGL_GL_API void glProgramUniform1ui64ARB(GLuint program, GLint location, GLuint64 x);
|
||||
MOBILEGL_GL_API void glProgramUniform1ui64NV(GLuint program, GLint location, GLuint64EXT x);
|
||||
MOBILEGL_GL_API void glProgramUniform1ui64vARB(GLuint program, GLint location, GLsizei count, const GLuint64* value);
|
||||
MOBILEGL_GL_API void glProgramUniform1ui64vNV(GLuint program, GLint location, GLsizei count, const GLuint64EXT* value);
|
||||
MOBILEGL_GL_API void glProgramUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint* value);
|
||||
MOBILEGL_GL_API void glProgramUniform2d(GLuint program, GLint location, GLdouble v0, GLdouble v1);
|
||||
MOBILEGL_GL_API void glProgramUniform2dEXT(GLuint program, GLint location, GLdouble x, GLdouble y);
|
||||
MOBILEGL_GL_API void glProgramUniform2dv(GLuint program, GLint location, GLsizei count, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glProgramUniform2dvEXT(GLuint program, GLint location, GLsizei count, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glProgramUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1);
|
||||
MOBILEGL_GL_API void glProgramUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat* value);
|
||||
MOBILEGL_GL_API void glProgramUniform2i(GLuint program, GLint location, GLint v0, GLint v1);
|
||||
MOBILEGL_GL_API void glProgramUniform2i64ARB(GLuint program, GLint location, GLint64 x, GLint64 y);
|
||||
MOBILEGL_GL_API void glProgramUniform2i64NV(GLuint program, GLint location, GLint64EXT x, GLint64EXT y);
|
||||
MOBILEGL_GL_API void glProgramUniform2i64vARB(GLuint program, GLint location, GLsizei count, const GLint64* value);
|
||||
MOBILEGL_GL_API void glProgramUniform2i64vNV(GLuint program, GLint location, GLsizei count, const GLint64EXT* value);
|
||||
MOBILEGL_GL_API void glProgramUniform2iv(GLuint program, GLint location, GLsizei count, const GLint* value);
|
||||
MOBILEGL_GL_API void glProgramUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1);
|
||||
MOBILEGL_GL_API void glProgramUniform2ui64ARB(GLuint program, GLint location, GLuint64 x, GLuint64 y);
|
||||
MOBILEGL_GL_API void glProgramUniform2ui64NV(GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y);
|
||||
MOBILEGL_GL_API void glProgramUniform2ui64vARB(GLuint program, GLint location, GLsizei count, const GLuint64* value);
|
||||
MOBILEGL_GL_API void glProgramUniform2ui64vNV(GLuint program, GLint location, GLsizei count, const GLuint64EXT* value);
|
||||
MOBILEGL_GL_API void glProgramUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint* value);
|
||||
MOBILEGL_GL_API void glProgramUniform3d(GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2);
|
||||
MOBILEGL_GL_API void glProgramUniform3dEXT(GLuint program, GLint location, GLdouble x, GLdouble y, GLdouble z);
|
||||
MOBILEGL_GL_API void glProgramUniform3dv(GLuint program, GLint location, GLsizei count, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glProgramUniform3dvEXT(GLuint program, GLint location, GLsizei count, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glProgramUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
|
||||
MOBILEGL_GL_API void glProgramUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat* value);
|
||||
MOBILEGL_GL_API void glProgramUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2);
|
||||
MOBILEGL_GL_API void glProgramUniform3i64ARB(GLuint program, GLint location, GLint64 x, GLint64 y, GLint64 z);
|
||||
MOBILEGL_GL_API void glProgramUniform3i64NV(GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z);
|
||||
MOBILEGL_GL_API void glProgramUniform3i64vARB(GLuint program, GLint location, GLsizei count, const GLint64* value);
|
||||
MOBILEGL_GL_API void glProgramUniform3i64vNV(GLuint program, GLint location, GLsizei count, const GLint64EXT* value);
|
||||
MOBILEGL_GL_API void glProgramUniform3iv(GLuint program, GLint location, GLsizei count, const GLint* value);
|
||||
MOBILEGL_GL_API void glProgramUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2);
|
||||
MOBILEGL_GL_API void glProgramUniform3ui64ARB(GLuint program, GLint location, GLuint64 x, GLuint64 y, GLuint64 z);
|
||||
MOBILEGL_GL_API void glProgramUniform3ui64NV(GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z);
|
||||
MOBILEGL_GL_API void glProgramUniform3ui64vARB(GLuint program, GLint location, GLsizei count, const GLuint64* value);
|
||||
MOBILEGL_GL_API void glProgramUniform3ui64vNV(GLuint program, GLint location, GLsizei count, const GLuint64EXT* value);
|
||||
MOBILEGL_GL_API void glProgramUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint* value);
|
||||
MOBILEGL_GL_API void glProgramUniform4d(GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3);
|
||||
MOBILEGL_GL_API void glProgramUniform4dEXT(GLuint program, GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
|
||||
MOBILEGL_GL_API void glProgramUniform4dv(GLuint program, GLint location, GLsizei count, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glProgramUniform4dvEXT(GLuint program, GLint location, GLsizei count, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glProgramUniform4f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
|
||||
MOBILEGL_GL_API void glProgramUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat* value);
|
||||
MOBILEGL_GL_API void glProgramUniform4i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
|
||||
MOBILEGL_GL_API void glProgramUniform4i64ARB(GLuint program, GLint location, GLint64 x, GLint64 y, GLint64 z, GLint64 w);
|
||||
MOBILEGL_GL_API void glProgramUniform4i64NV(GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w);
|
||||
MOBILEGL_GL_API void glProgramUniform4i64vARB(GLuint program, GLint location, GLsizei count, const GLint64* value);
|
||||
MOBILEGL_GL_API void glProgramUniform4i64vNV(GLuint program, GLint location, GLsizei count, const GLint64EXT* value);
|
||||
MOBILEGL_GL_API void glProgramUniform4iv(GLuint program, GLint location, GLsizei count, const GLint* value);
|
||||
MOBILEGL_GL_API void glProgramUniform4ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
|
||||
MOBILEGL_GL_API void glProgramUniform4ui64ARB(GLuint program, GLint location, GLuint64 x, GLuint64 y, GLuint64 z, GLuint64 w);
|
||||
MOBILEGL_GL_API void glProgramUniform4ui64NV(GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w);
|
||||
MOBILEGL_GL_API void glProgramUniform4ui64vARB(GLuint program, GLint location, GLsizei count, const GLuint64* value);
|
||||
MOBILEGL_GL_API void glProgramUniform4ui64vNV(GLuint program, GLint location, GLsizei count, const GLuint64EXT* value);
|
||||
MOBILEGL_GL_API void glProgramUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint* value);
|
||||
MOBILEGL_GL_API void glProgramUniformHandleui64ARB(GLuint program, GLint location, GLuint64 value);
|
||||
MOBILEGL_GL_API void glProgramUniformHandleui64NV(GLuint program, GLint location, GLuint64 value);
|
||||
MOBILEGL_GL_API void glProgramUniformHandleui64vARB(GLuint program, GLint location, GLsizei count, const GLuint64* values);
|
||||
MOBILEGL_GL_API void glProgramUniformHandleui64vNV(GLuint program, GLint location, GLsizei count, const GLuint64* values);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix2dv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix2dvEXT(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix2fv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix2x3dv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix2x3dvEXT(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix2x3fv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix2x4dv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix2x4dvEXT(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix2x4fv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix3dv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix3dvEXT(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix3fv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix3x2dv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix3x2dvEXT(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix3x2fv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix3x4dv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix3x4dvEXT(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix3x4fv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix4dv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix4dvEXT(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix4fv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix4x2dv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix4x2dvEXT(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix4x2fv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix4x3dv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix4x3dvEXT(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glProgramUniformMatrix4x3fv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
|
||||
MOBILEGL_GL_API void glProgramUniformui64NV(GLuint program, GLint location, GLuint64EXT value);
|
||||
MOBILEGL_GL_API void glProgramUniformui64vNV(GLuint program, GLint location, GLsizei count, const GLuint64EXT* value);
|
||||
MOBILEGL_GL_API void glProvokingVertex(GLenum mode);
|
||||
MOBILEGL_GL_API void glPushClientAttribDefaultEXT(GLbitfield mask);
|
||||
MOBILEGL_GL_API void glPushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar* message);
|
||||
MOBILEGL_GL_API void glPushGroupMarkerEXT(GLsizei length, const GLchar* marker);
|
||||
MOBILEGL_GL_API void glQueryCounter(GLuint id, GLenum target);
|
||||
MOBILEGL_GL_API void glRasterSamplesEXT(GLuint samples, GLboolean fixedsamplelocations);
|
||||
MOBILEGL_GL_API void glReadBuffer(GLenum src);
|
||||
MOBILEGL_GL_API void glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
|
||||
MOBILEGL_GL_API void glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
|
||||
MOBILEGL_GL_API void glRenderbufferStorageMultisampleAdvancedAMD(GLenum target, GLsizei samples, GLsizei storageSamples, GLenum internalformat, GLsizei width, GLsizei height);
|
||||
MOBILEGL_GL_API void glRenderbufferStorageMultisampleCoverageNV(GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height);
|
||||
MOBILEGL_GL_API void glResetMemoryObjectParameterNV(GLuint memory, GLenum pname);
|
||||
MOBILEGL_GL_API void glSampleCoverage(GLfloat value, GLboolean invert);
|
||||
MOBILEGL_GL_API void glSampleMaski(GLuint maskNumber, GLbitfield mask);
|
||||
MOBILEGL_GL_API void glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param);
|
||||
MOBILEGL_GL_API void glSamplerParameteri(GLuint sampler, GLenum pname, GLint param);
|
||||
MOBILEGL_GL_API void glScissor(GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
MOBILEGL_GL_API void glScissorArrayv(GLuint first, GLsizei count, const GLint* v);
|
||||
MOBILEGL_GL_API void glScissorExclusiveArrayvNV(GLuint first, GLsizei count, const GLint* v);
|
||||
MOBILEGL_GL_API void glScissorExclusiveNV(GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
MOBILEGL_GL_API void glScissorIndexed(GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height);
|
||||
MOBILEGL_GL_API void glSecondaryColorFormatNV(GLint size, GLenum type, GLsizei stride);
|
||||
MOBILEGL_GL_API void glShaderBinary(GLsizei count, const GLuint* shaders, GLenum binaryformat, const void* binary, GLsizei length);
|
||||
MOBILEGL_GL_API void glShaderStorageBlockBinding(GLuint program, GLuint storageBlockIndex, GLuint storageBlockBinding);
|
||||
MOBILEGL_GL_API void glShadingRateImageBarrierNV(GLboolean synchronize);
|
||||
MOBILEGL_GL_API void glShadingRateImagePaletteNV(GLuint viewport, GLuint first, GLsizei count, const GLenum* rates);
|
||||
MOBILEGL_GL_API void glShadingRateSampleOrderNV(GLenum order);
|
||||
MOBILEGL_GL_API void glSignalVkFenceNV(GLuint64 vkFence);
|
||||
MOBILEGL_GL_API void glSignalVkSemaphoreNV(GLuint64 vkSemaphore);
|
||||
MOBILEGL_GL_API void glStateCaptureNV(GLuint state, GLenum mode);
|
||||
MOBILEGL_GL_API void glStencilFillPathNV(GLuint path, GLenum fillMode, GLuint mask);
|
||||
MOBILEGL_GL_API void glStencilFunc(GLenum func, GLint ref, GLuint mask);
|
||||
MOBILEGL_GL_API void glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask);
|
||||
MOBILEGL_GL_API void glStencilMask(GLuint mask);
|
||||
MOBILEGL_GL_API void glStencilMaskSeparate(GLenum face, GLuint mask);
|
||||
MOBILEGL_GL_API void glStencilOp(GLenum fail, GLenum zfail, GLenum zpass);
|
||||
MOBILEGL_GL_API void glStencilOpSeparate(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass);
|
||||
MOBILEGL_GL_API void glStencilStrokePathNV(GLuint path, GLint reference, GLuint mask);
|
||||
MOBILEGL_GL_API void glStencilThenCoverFillPathNV(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode);
|
||||
MOBILEGL_GL_API void glStencilThenCoverStrokePathNV(GLuint path, GLint reference, GLuint mask, GLenum coverMode);
|
||||
MOBILEGL_GL_API void glSubpixelPrecisionBiasNV(GLuint xbits, GLuint ybits);
|
||||
MOBILEGL_GL_API void glTexAttachMemoryNV(GLenum target, GLuint memory, GLuint64 offset);
|
||||
MOBILEGL_GL_API void glTexBuffer(GLenum target, GLenum internalformat, GLuint buffer);
|
||||
MOBILEGL_GL_API void glTexBufferRange(GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size);
|
||||
MOBILEGL_GL_API void glTexCoordFormatNV(GLint size, GLenum type, GLsizei stride);
|
||||
MOBILEGL_GL_API void glTexImage2DMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations);
|
||||
MOBILEGL_GL_API void glTexImage3DMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations);
|
||||
MOBILEGL_GL_API void glTexPageCommitmentARB(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLboolean commit);
|
||||
MOBILEGL_GL_API void glTexPageCommitmentMemNV(GLenum target, GLint layer, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLuint memory, GLuint64 offset, GLboolean commit);
|
||||
MOBILEGL_GL_API void glTexParameterf(GLenum target, GLenum pname, GLfloat param);
|
||||
MOBILEGL_GL_API void glTexParameteri(GLenum target, GLenum pname, GLint param);
|
||||
MOBILEGL_GL_API void glTexStorage1DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width);
|
||||
MOBILEGL_GL_API void glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
|
||||
MOBILEGL_GL_API void glTexStorage2DMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations);
|
||||
MOBILEGL_GL_API void glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
|
||||
MOBILEGL_GL_API void glTexStorage3DMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations);
|
||||
MOBILEGL_GL_API void glTextureAttachMemoryNV(GLuint texture, GLuint memory, GLuint64 offset);
|
||||
MOBILEGL_GL_API void glTextureBuffer(GLuint texture, GLenum internalformat, GLuint buffer);
|
||||
MOBILEGL_GL_API void glTextureBufferEXT(GLuint texture, GLenum target, GLenum internalformat, GLuint buffer);
|
||||
MOBILEGL_GL_API void glTextureBufferRange(GLuint texture, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size);
|
||||
MOBILEGL_GL_API void glTextureBufferRangeEXT(GLuint texture, GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size);
|
||||
MOBILEGL_GL_API void glTexturePageCommitmentEXT(GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLboolean commit);
|
||||
MOBILEGL_GL_API void glTexturePageCommitmentMemNV(GLuint texture, GLint layer, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLuint memory, GLuint64 offset, GLboolean commit);
|
||||
MOBILEGL_GL_API void glTextureParameterf(GLuint texture, GLenum pname, GLfloat param);
|
||||
MOBILEGL_GL_API void glTextureParameterfEXT(GLuint texture, GLenum target, GLenum pname, GLfloat param);
|
||||
MOBILEGL_GL_API void glTextureParameteri(GLuint texture, GLenum pname, GLint param);
|
||||
MOBILEGL_GL_API void glTextureParameteriEXT(GLuint texture, GLenum target, GLenum pname, GLint param);
|
||||
MOBILEGL_GL_API void glTextureRenderbufferEXT(GLuint texture, GLenum target, GLuint renderbuffer);
|
||||
MOBILEGL_GL_API void glTextureStorage1D(GLuint texture, GLsizei levels, GLenum internalformat, GLsizei width);
|
||||
MOBILEGL_GL_API void glTextureStorage1DEXT(GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width);
|
||||
MOBILEGL_GL_API void glTextureStorage2D(GLuint texture, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
|
||||
MOBILEGL_GL_API void glTextureStorage2DEXT(GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
|
||||
MOBILEGL_GL_API void glTextureStorage2DMultisample(GLuint texture, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations);
|
||||
MOBILEGL_GL_API void glTextureStorage2DMultisampleEXT(GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations);
|
||||
MOBILEGL_GL_API void glTextureStorage3D(GLuint texture, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
|
||||
MOBILEGL_GL_API void glTextureStorage3DEXT(GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
|
||||
MOBILEGL_GL_API void glTextureStorage3DMultisample(GLuint texture, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations);
|
||||
MOBILEGL_GL_API void glTextureStorage3DMultisampleEXT(GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations);
|
||||
MOBILEGL_GL_API void glTextureView(GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers);
|
||||
MOBILEGL_GL_API void glTransformFeedbackBufferBase(GLuint xfb, GLuint index, GLuint buffer);
|
||||
MOBILEGL_GL_API void glTransformFeedbackBufferRange(GLuint xfb, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size);
|
||||
MOBILEGL_GL_API void glUniform1d(GLint location, GLdouble x);
|
||||
MOBILEGL_GL_API void glUniform1dv(GLint location, GLsizei count, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glUniform1f(GLint location, GLfloat v0);
|
||||
MOBILEGL_GL_API void glUniform1fv(GLint location, GLsizei count, const GLfloat* value);
|
||||
MOBILEGL_GL_API void glUniform1i(GLint location, GLint v0);
|
||||
MOBILEGL_GL_API void glUniform1i64ARB(GLint location, GLint64 x);
|
||||
MOBILEGL_GL_API void glUniform1i64NV(GLint location, GLint64EXT x);
|
||||
MOBILEGL_GL_API void glUniform1i64vARB(GLint location, GLsizei count, const GLint64* value);
|
||||
MOBILEGL_GL_API void glUniform1i64vNV(GLint location, GLsizei count, const GLint64EXT* value);
|
||||
MOBILEGL_GL_API void glUniform1iv(GLint location, GLsizei count, const GLint* value);
|
||||
MOBILEGL_GL_API void glUniform1ui(GLint location, GLuint v0);
|
||||
MOBILEGL_GL_API void glUniform1ui64ARB(GLint location, GLuint64 x);
|
||||
MOBILEGL_GL_API void glUniform1ui64NV(GLint location, GLuint64EXT x);
|
||||
MOBILEGL_GL_API void glUniform1ui64vARB(GLint location, GLsizei count, const GLuint64* value);
|
||||
MOBILEGL_GL_API void glUniform1ui64vNV(GLint location, GLsizei count, const GLuint64EXT* value);
|
||||
MOBILEGL_GL_API void glUniform1uiv(GLint location, GLsizei count, const GLuint* value);
|
||||
MOBILEGL_GL_API void glUniform2d(GLint location, GLdouble x, GLdouble y);
|
||||
MOBILEGL_GL_API void glUniform2dv(GLint location, GLsizei count, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glUniform2f(GLint location, GLfloat v0, GLfloat v1);
|
||||
MOBILEGL_GL_API void glUniform2fv(GLint location, GLsizei count, const GLfloat* value);
|
||||
MOBILEGL_GL_API void glUniform2i(GLint location, GLint v0, GLint v1);
|
||||
MOBILEGL_GL_API void glUniform2i64ARB(GLint location, GLint64 x, GLint64 y);
|
||||
MOBILEGL_GL_API void glUniform2i64NV(GLint location, GLint64EXT x, GLint64EXT y);
|
||||
MOBILEGL_GL_API void glUniform2i64vARB(GLint location, GLsizei count, const GLint64* value);
|
||||
MOBILEGL_GL_API void glUniform2i64vNV(GLint location, GLsizei count, const GLint64EXT* value);
|
||||
MOBILEGL_GL_API void glUniform2iv(GLint location, GLsizei count, const GLint* value);
|
||||
MOBILEGL_GL_API void glUniform2ui(GLint location, GLuint v0, GLuint v1);
|
||||
MOBILEGL_GL_API void glUniform2ui64ARB(GLint location, GLuint64 x, GLuint64 y);
|
||||
MOBILEGL_GL_API void glUniform2ui64NV(GLint location, GLuint64EXT x, GLuint64EXT y);
|
||||
MOBILEGL_GL_API void glUniform2ui64vARB(GLint location, GLsizei count, const GLuint64* value);
|
||||
MOBILEGL_GL_API void glUniform2ui64vNV(GLint location, GLsizei count, const GLuint64EXT* value);
|
||||
MOBILEGL_GL_API void glUniform2uiv(GLint location, GLsizei count, const GLuint* value);
|
||||
MOBILEGL_GL_API void glUniform3d(GLint location, GLdouble x, GLdouble y, GLdouble z);
|
||||
MOBILEGL_GL_API void glUniform3dv(GLint location, GLsizei count, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glUniform3f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
|
||||
MOBILEGL_GL_API void glUniform3fv(GLint location, GLsizei count, const GLfloat* value);
|
||||
MOBILEGL_GL_API void glUniform3i(GLint location, GLint v0, GLint v1, GLint v2);
|
||||
MOBILEGL_GL_API void glUniform3i64ARB(GLint location, GLint64 x, GLint64 y, GLint64 z);
|
||||
MOBILEGL_GL_API void glUniform3i64NV(GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z);
|
||||
MOBILEGL_GL_API void glUniform3i64vARB(GLint location, GLsizei count, const GLint64* value);
|
||||
MOBILEGL_GL_API void glUniform3i64vNV(GLint location, GLsizei count, const GLint64EXT* value);
|
||||
MOBILEGL_GL_API void glUniform3iv(GLint location, GLsizei count, const GLint* value);
|
||||
MOBILEGL_GL_API void glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2);
|
||||
MOBILEGL_GL_API void glUniform3ui64ARB(GLint location, GLuint64 x, GLuint64 y, GLuint64 z);
|
||||
MOBILEGL_GL_API void glUniform3ui64NV(GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z);
|
||||
MOBILEGL_GL_API void glUniform3ui64vARB(GLint location, GLsizei count, const GLuint64* value);
|
||||
MOBILEGL_GL_API void glUniform3ui64vNV(GLint location, GLsizei count, const GLuint64EXT* value);
|
||||
MOBILEGL_GL_API void glUniform3uiv(GLint location, GLsizei count, const GLuint* value);
|
||||
MOBILEGL_GL_API void glUniform4d(GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
|
||||
MOBILEGL_GL_API void glUniform4dv(GLint location, GLsizei count, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glUniform4f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
|
||||
MOBILEGL_GL_API void glUniform4fv(GLint location, GLsizei count, const GLfloat* value);
|
||||
MOBILEGL_GL_API void glUniform4i(GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
|
||||
MOBILEGL_GL_API void glUniform4i64ARB(GLint location, GLint64 x, GLint64 y, GLint64 z, GLint64 w);
|
||||
MOBILEGL_GL_API void glUniform4i64NV(GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w);
|
||||
MOBILEGL_GL_API void glUniform4i64vARB(GLint location, GLsizei count, const GLint64* value);
|
||||
MOBILEGL_GL_API void glUniform4i64vNV(GLint location, GLsizei count, const GLint64EXT* value);
|
||||
MOBILEGL_GL_API void glUniform4iv(GLint location, GLsizei count, const GLint* value);
|
||||
MOBILEGL_GL_API void glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
|
||||
MOBILEGL_GL_API void glUniform4ui64ARB(GLint location, GLuint64 x, GLuint64 y, GLuint64 z, GLuint64 w);
|
||||
MOBILEGL_GL_API void glUniform4ui64NV(GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w);
|
||||
MOBILEGL_GL_API void glUniform4ui64vARB(GLint location, GLsizei count, const GLuint64* value);
|
||||
MOBILEGL_GL_API void glUniform4ui64vNV(GLint location, GLsizei count, const GLuint64EXT* value);
|
||||
MOBILEGL_GL_API void glUniform4uiv(GLint location, GLsizei count, const GLuint* value);
|
||||
MOBILEGL_GL_API void glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding);
|
||||
MOBILEGL_GL_API void glUniformHandleui64ARB(GLint location, GLuint64 value);
|
||||
MOBILEGL_GL_API void glUniformHandleui64NV(GLint location, GLuint64 value);
|
||||
MOBILEGL_GL_API void glUniformMatrix2dv(GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
|
||||
MOBILEGL_GL_API void glUniformMatrix2x3dv(GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
|
||||
MOBILEGL_GL_API void glUniformMatrix2x4dv(GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
|
||||
MOBILEGL_GL_API void glUniformMatrix3dv(GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
|
||||
MOBILEGL_GL_API void glUniformMatrix3x2dv(GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
|
||||
MOBILEGL_GL_API void glUniformMatrix3x4dv(GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
|
||||
MOBILEGL_GL_API void glUniformMatrix4dv(GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
|
||||
MOBILEGL_GL_API void glUniformMatrix4x2dv(GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
|
||||
MOBILEGL_GL_API void glUniformMatrix4x3dv(GLint location, GLsizei count, GLboolean transpose, const GLdouble* value);
|
||||
MOBILEGL_GL_API void glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
|
||||
MOBILEGL_GL_API void glUniformui64NV(GLint location, GLuint64EXT value);
|
||||
MOBILEGL_GL_API GLboolean glUnmapBuffer(GLenum target);
|
||||
MOBILEGL_GL_API GLboolean glUnmapNamedBuffer(GLuint buffer);
|
||||
MOBILEGL_GL_API GLboolean glUnmapNamedBufferEXT(GLuint buffer);
|
||||
MOBILEGL_GL_API void glUseProgram(GLuint program);
|
||||
MOBILEGL_GL_API void glUseProgramStages(GLuint pipeline, GLbitfield stages, GLuint program);
|
||||
MOBILEGL_GL_API void glUseShaderProgramEXT(GLenum type, GLuint program);
|
||||
MOBILEGL_GL_API void glValidateProgram(GLuint program);
|
||||
MOBILEGL_GL_API void glValidateProgramPipeline(GLuint pipeline);
|
||||
MOBILEGL_GL_API void glVertexArrayAttribBinding(GLuint vaobj, GLuint attribindex, GLuint bindingindex);
|
||||
MOBILEGL_GL_API void glVertexArrayAttribFormat(GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset);
|
||||
MOBILEGL_GL_API void glVertexArrayAttribIFormat(GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset);
|
||||
MOBILEGL_GL_API void glVertexArrayAttribLFormat(GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset);
|
||||
MOBILEGL_GL_API void glVertexArrayBindVertexBufferEXT(GLuint vaobj, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride);
|
||||
MOBILEGL_GL_API void glVertexArrayBindingDivisor(GLuint vaobj, GLuint bindingindex, GLuint divisor);
|
||||
MOBILEGL_GL_API void glVertexArrayColorOffsetEXT(GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset);
|
||||
MOBILEGL_GL_API void glVertexArrayEdgeFlagOffsetEXT(GLuint vaobj, GLuint buffer, GLsizei stride, GLintptr offset);
|
||||
MOBILEGL_GL_API void glVertexArrayElementBuffer(GLuint vaobj, GLuint buffer);
|
||||
MOBILEGL_GL_API void glVertexArrayFogCoordOffsetEXT(GLuint vaobj, GLuint buffer, GLenum type, GLsizei stride, GLintptr offset);
|
||||
MOBILEGL_GL_API void glVertexArrayIndexOffsetEXT(GLuint vaobj, GLuint buffer, GLenum type, GLsizei stride, GLintptr offset);
|
||||
MOBILEGL_GL_API void glVertexArrayMultiTexCoordOffsetEXT(GLuint vaobj, GLuint buffer, GLenum texunit, GLint size, GLenum type, GLsizei stride, GLintptr offset);
|
||||
MOBILEGL_GL_API void glVertexArrayNormalOffsetEXT(GLuint vaobj, GLuint buffer, GLenum type, GLsizei stride, GLintptr offset);
|
||||
MOBILEGL_GL_API void glVertexArraySecondaryColorOffsetEXT(GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset);
|
||||
MOBILEGL_GL_API void glVertexArrayTexCoordOffsetEXT(GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset);
|
||||
MOBILEGL_GL_API void glVertexArrayVertexAttribBindingEXT(GLuint vaobj, GLuint attribindex, GLuint bindingindex);
|
||||
MOBILEGL_GL_API void glVertexArrayVertexAttribDivisorEXT(GLuint vaobj, GLuint index, GLuint divisor);
|
||||
MOBILEGL_GL_API void glVertexArrayVertexAttribFormatEXT(GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset);
|
||||
MOBILEGL_GL_API void glVertexArrayVertexAttribIFormatEXT(GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset);
|
||||
MOBILEGL_GL_API void glVertexArrayVertexAttribIOffsetEXT(GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLsizei stride, GLintptr offset);
|
||||
MOBILEGL_GL_API void glVertexArrayVertexAttribLFormatEXT(GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset);
|
||||
MOBILEGL_GL_API void glVertexArrayVertexAttribLOffsetEXT(GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLsizei stride, GLintptr offset);
|
||||
MOBILEGL_GL_API void glVertexArrayVertexAttribOffsetEXT(GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLintptr offset);
|
||||
MOBILEGL_GL_API void glVertexArrayVertexBindingDivisorEXT(GLuint vaobj, GLuint bindingindex, GLuint divisor);
|
||||
MOBILEGL_GL_API void glVertexArrayVertexBuffer(GLuint vaobj, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride);
|
||||
MOBILEGL_GL_API void glVertexArrayVertexOffsetEXT(GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset);
|
||||
MOBILEGL_GL_API void glVertexAttrib1d(GLuint index, GLdouble x);
|
||||
MOBILEGL_GL_API void glVertexAttrib1f(GLuint index, GLfloat x);
|
||||
MOBILEGL_GL_API void glVertexAttrib1s(GLuint index, GLshort x);
|
||||
MOBILEGL_GL_API void glVertexAttrib2d(GLuint index, GLdouble x, GLdouble y);
|
||||
MOBILEGL_GL_API void glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y);
|
||||
MOBILEGL_GL_API void glVertexAttrib2s(GLuint index, GLshort x, GLshort y);
|
||||
MOBILEGL_GL_API void glVertexAttrib3d(GLuint index, GLdouble x, GLdouble y, GLdouble z);
|
||||
MOBILEGL_GL_API void glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z);
|
||||
MOBILEGL_GL_API void glVertexAttrib3s(GLuint index, GLshort x, GLshort y, GLshort z);
|
||||
MOBILEGL_GL_API void glVertexAttrib4Nub(GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w);
|
||||
MOBILEGL_GL_API void glVertexAttrib4d(GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
|
||||
MOBILEGL_GL_API void glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
|
||||
MOBILEGL_GL_API void glVertexAttrib4s(GLuint index, GLshort x, GLshort y, GLshort z, GLshort w);
|
||||
MOBILEGL_GL_API void glVertexAttribBinding(GLuint attribindex, GLuint bindingindex);
|
||||
MOBILEGL_GL_API void glVertexAttribDivisor(GLuint index, GLuint divisor);
|
||||
MOBILEGL_GL_API void glVertexAttribFormat(GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset);
|
||||
MOBILEGL_GL_API void glVertexAttribFormatNV(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride);
|
||||
MOBILEGL_GL_API void glVertexAttribI1i(GLuint index, GLint x);
|
||||
MOBILEGL_GL_API void glVertexAttribI1ui(GLuint index, GLuint x);
|
||||
MOBILEGL_GL_API void glVertexAttribI2i(GLuint index, GLint x, GLint y);
|
||||
MOBILEGL_GL_API void glVertexAttribI2ui(GLuint index, GLuint x, GLuint y);
|
||||
MOBILEGL_GL_API void glVertexAttribI3i(GLuint index, GLint x, GLint y, GLint z);
|
||||
MOBILEGL_GL_API void glVertexAttribI3ui(GLuint index, GLuint x, GLuint y, GLuint z);
|
||||
MOBILEGL_GL_API void glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w);
|
||||
MOBILEGL_GL_API void glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w);
|
||||
MOBILEGL_GL_API void glVertexAttribIFormat(GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset);
|
||||
MOBILEGL_GL_API void glVertexAttribIFormatNV(GLuint index, GLint size, GLenum type, GLsizei stride);
|
||||
MOBILEGL_GL_API void glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const void* pointer);
|
||||
MOBILEGL_GL_API void glVertexAttribL1d(GLuint index, GLdouble x);
|
||||
MOBILEGL_GL_API void glVertexAttribL1i64NV(GLuint index, GLint64EXT x);
|
||||
MOBILEGL_GL_API void glVertexAttribL1ui64ARB(GLuint index, GLuint64EXT x);
|
||||
MOBILEGL_GL_API void glVertexAttribL1ui64NV(GLuint index, GLuint64EXT x);
|
||||
MOBILEGL_GL_API void glVertexAttribL2d(GLuint index, GLdouble x, GLdouble y);
|
||||
MOBILEGL_GL_API void glVertexAttribL2i64NV(GLuint index, GLint64EXT x, GLint64EXT y);
|
||||
MOBILEGL_GL_API void glVertexAttribL2ui64NV(GLuint index, GLuint64EXT x, GLuint64EXT y);
|
||||
MOBILEGL_GL_API void glVertexAttribL3d(GLuint index, GLdouble x, GLdouble y, GLdouble z);
|
||||
MOBILEGL_GL_API void glVertexAttribL3i64NV(GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT z);
|
||||
MOBILEGL_GL_API void glVertexAttribL3ui64NV(GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z);
|
||||
MOBILEGL_GL_API void glVertexAttribL4d(GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
|
||||
MOBILEGL_GL_API void glVertexAttribL4i64NV(GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w);
|
||||
MOBILEGL_GL_API void glVertexAttribL4ui64NV(GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w);
|
||||
MOBILEGL_GL_API void glVertexAttribLFormat(GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset);
|
||||
MOBILEGL_GL_API void glVertexAttribLFormatNV(GLuint index, GLint size, GLenum type, GLsizei stride);
|
||||
MOBILEGL_GL_API void glVertexAttribLPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const void* pointer);
|
||||
MOBILEGL_GL_API void glVertexAttribP1ui(GLuint index, GLenum type, GLboolean normalized, GLuint value);
|
||||
MOBILEGL_GL_API void glVertexAttribP2ui(GLuint index, GLenum type, GLboolean normalized, GLuint value);
|
||||
MOBILEGL_GL_API void glVertexAttribP3ui(GLuint index, GLenum type, GLboolean normalized, GLuint value);
|
||||
MOBILEGL_GL_API void glVertexAttribP4ui(GLuint index, GLenum type, GLboolean normalized, GLuint value);
|
||||
MOBILEGL_GL_API void glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* pointer);
|
||||
MOBILEGL_GL_API void glVertexBindingDivisor(GLuint bindingindex, GLuint divisor);
|
||||
MOBILEGL_GL_API void glVertexFormatNV(GLint size, GLenum type, GLsizei stride);
|
||||
MOBILEGL_GL_API void glViewport(GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
MOBILEGL_GL_API void glViewportArrayv(GLuint first, GLsizei count, const GLfloat* v);
|
||||
MOBILEGL_GL_API void glViewportIndexedf(GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h);
|
||||
MOBILEGL_GL_API void glViewportPositionWScaleNV(GLuint index, GLfloat xcoeff, GLfloat ycoeff);
|
||||
MOBILEGL_GL_API void glViewportSwizzleNV(GLuint index, GLenum swizzlex, GLenum swizzley, GLenum swizzlez, GLenum swizzlew);
|
||||
MOBILEGL_GL_API void glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout);
|
||||
MOBILEGL_GL_API void glWaitVkSemaphoreNV(GLuint64 vkSemaphore);
|
||||
|
||||
namespace MobileGL::ClientTrampoline::Gen {
|
||||
// Resolves a GL function name against the exported trampoline table
|
||||
// (direct &glXxx references - no dlsym, mirroring monolith
|
||||
// MobileGL::MG_Impl::GetProcAddress semantics).
|
||||
void* LookupGeneratedProc(const char* name);
|
||||
}
|
||||
|
||||
// End of File
|
||||
@@ -1,663 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Gbm/GbmApi.cpp
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
//
|
||||
// The extern "C" surface: every entry point gbm.h declares, and nothing else.
|
||||
//
|
||||
// This file is a translation layer, and it is kept that way on purpose. Each entry
|
||||
// point does three things - check the pointers it was handed, take the device's one
|
||||
// mutex for the whole call, and hand the work to GbmDevice.cpp - so the concurrency
|
||||
// rule ("one mutex per device, taken once at the API boundary, never inside the
|
||||
// allocation code") is visible in one place instead of being spread over the
|
||||
// backends. A missing lock is a bug that only shows up in the compositor, so the
|
||||
// boilerplate is deliberately identical in every function.
|
||||
//
|
||||
// Two conventions are observable from outside and are stated here because they are
|
||||
// the ones a caller can get wrong:
|
||||
//
|
||||
// * gbm_bo_get_fd and gbm_bo_get_fd_for_plane return a DUP the caller owns. The
|
||||
// caller closes what it was given; the buffer's own descriptor is closed once,
|
||||
// when the buffer is destroyed, and never by a caller's close.
|
||||
// * Nothing here throws and nothing here aborts. A failure is reported the way
|
||||
// GBM reports failures: null or -1 with errno set, so that the strerror(errno)
|
||||
// a caller prints describes the failure that actually happened.
|
||||
|
||||
#include "GbmInternal.h"
|
||||
|
||||
#include <cerrno>
|
||||
|
||||
using namespace MobileGL;
|
||||
using namespace MobileGL::MG_Gbm;
|
||||
|
||||
namespace
|
||||
{
|
||||
// The one mutex that guards a record, reached through the device that owns it.
|
||||
// Null means the pointer was not one this library handed out, and every entry
|
||||
// point turns that into its own failure answer rather than dereferencing it.
|
||||
//
|
||||
// A buffer or surface with no owner cannot exist while the library is used
|
||||
// correctly - the device destroys everything it still holds before it goes away
|
||||
// - so null here is a defence against a stale pointer rather than a state the
|
||||
// code produces.
|
||||
std::mutex* MutexOf(struct gbm_device* device) noexcept
|
||||
{
|
||||
return device != nullptr ? &device->Impl.Mutex : nullptr;
|
||||
}
|
||||
|
||||
std::mutex* MutexOf(struct gbm_bo* bo) noexcept
|
||||
{
|
||||
return bo != nullptr ? MutexOf(bo->Impl.Owner) : nullptr;
|
||||
}
|
||||
|
||||
std::mutex* MutexOf(struct gbm_surface* surface) noexcept
|
||||
{
|
||||
return surface != nullptr ? MutexOf(surface->Impl.Owner) : nullptr;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Device
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
extern "C" struct gbm_device* gbm_create_device(int fd)
|
||||
{
|
||||
// No lock to take: the device being built is not reachable by any other thread
|
||||
// until this call returns it.
|
||||
return GbmDeviceCreate(fd);
|
||||
}
|
||||
|
||||
extern "C" void gbm_device_destroy(struct gbm_device* gbm)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(gbm);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// The lock is taken and deliberately never released: the mutex lives inside the
|
||||
// record this call deletes, and unlocking a destroyed mutex is worse than
|
||||
// leaving a dead one locked. Any other thread touching this device after its
|
||||
// owner declared it dead is already outside what GBM can be asked to survive.
|
||||
mutex->lock();
|
||||
GbmDeviceDestroy(*gbm);
|
||||
}
|
||||
|
||||
extern "C" int gbm_device_get_fd(struct gbm_device* gbm)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(gbm);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
// The device's own dup of the fd it was created with, or -1 when it was created
|
||||
// without one and no render node could be opened. That is not an error state:
|
||||
// the self-allocated backend never talks to the node, so a device can be fully
|
||||
// usable and still have no descriptor to report.
|
||||
return gbm->Impl.DeviceFd;
|
||||
}
|
||||
|
||||
extern "C" const char* gbm_device_get_backend_name(struct gbm_device* gbm)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(gbm);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
// The name says which memory this device hands out ("mobilegl-dma-heap" or
|
||||
// "mobilegl-memfd"), because the callers that read it - a compositor logging its
|
||||
// backend, a peer test recording what it got - are asking exactly that. The
|
||||
// string lives in the device and outlives every call that can read it.
|
||||
return gbm->Impl.BackendName.c_str();
|
||||
}
|
||||
|
||||
extern "C" int gbm_device_is_format_supported(struct gbm_device* gbm, uint32_t format, uint32_t flags)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(gbm);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
// Every buffer this device produces is linear, mappable and shareable, so the
|
||||
// usage flags do not narrow the answer to any of the usual combinations -
|
||||
// including GBM_BO_USE_SCANOUT, which a linear dma-buf from the system heap
|
||||
// satisfies. The one request the backend cannot honour is protected memory.
|
||||
if ((flags & GBM_BO_USE_PROTECTED) != 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return GbmFormatIsSupported(format) ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" int gbm_device_get_format_modifier_plane_count(struct gbm_device* gbm, uint32_t format, uint64_t modifier)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(gbm);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
// Only linear memory exists here, so any other modifier names a buffer this
|
||||
// device will never produce and the answer is zero planes. INVALID is answered
|
||||
// as well, because it means "no modifier was declared", which is the same
|
||||
// layout question asked without an answer.
|
||||
if (modifier != DrmFormatModLinear && modifier != DrmFormatModInvalid)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
GbmPlaneLayout planes[GbmMaxPlanes] = {};
|
||||
Int planeCount = 0;
|
||||
SizeT totalBytes = 0;
|
||||
if (!GbmDescribeFormat(format, 1, 1, planes, planeCount, totalBytes))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return planeCount;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Buffer objects
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
extern "C" struct gbm_bo* gbm_bo_create(struct gbm_device* gbm, uint32_t width, uint32_t height, uint32_t format,
|
||||
uint32_t flags)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(gbm);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
// No modifier list: the buffer is linear and gbm_bo_get_modifier says so.
|
||||
return GbmBufferCreate(*gbm, width, height, format, flags, nullptr, 0);
|
||||
}
|
||||
|
||||
extern "C" struct gbm_bo* gbm_bo_create_with_modifiers(struct gbm_device* gbm, uint32_t width, uint32_t height,
|
||||
uint32_t format, const uint64_t* modifiers,
|
||||
const unsigned int count)
|
||||
{
|
||||
// The modifier-less variant is the one with no flags parameter, so it is the
|
||||
// flags-0 case of the other, and saying that here keeps one implementation.
|
||||
return gbm_bo_create_with_modifiers2(gbm, width, height, format, modifiers, count, 0);
|
||||
}
|
||||
|
||||
extern "C" struct gbm_bo* gbm_bo_create_with_modifiers2(struct gbm_device* gbm, uint32_t width, uint32_t height,
|
||||
uint32_t format, const uint64_t* modifiers,
|
||||
const unsigned int count, uint32_t flags)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(gbm);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
return GbmBufferCreate(*gbm, width, height, format, flags, modifiers, (Uint32)count);
|
||||
}
|
||||
|
||||
extern "C" struct gbm_bo* gbm_bo_import(struct gbm_device* gbm, uint32_t type, void* buffer, uint32_t flags)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(gbm);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
return GbmBufferImport(*gbm, type, buffer, flags);
|
||||
}
|
||||
|
||||
extern "C" void* gbm_bo_map(struct gbm_bo* bo, uint32_t x, uint32_t y, uint32_t width, uint32_t height,
|
||||
uint32_t flags, uint32_t* stride, void** map_data)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
// The rectangle's size is not used to size the mapping: the whole buffer is
|
||||
// mapped once, at its own length, and the rectangle is applied as an offset into
|
||||
// it. That is what lets two overlapping maps share one address, and it is why a
|
||||
// buffer's mapping stays valid for a caller that only ever asks for a corner.
|
||||
(void)width;
|
||||
(void)height;
|
||||
(void)flags;
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
Uint32 mapStride = 0;
|
||||
void* address = GbmBufferMap(*bo, x, y, mapStride);
|
||||
if (address == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
if (stride != nullptr)
|
||||
{
|
||||
*stride = mapStride;
|
||||
}
|
||||
if (map_data != nullptr)
|
||||
{
|
||||
// The same address the function returns. Callers pass back either one to
|
||||
// gbm_bo_unmap, and both have to name this mapping.
|
||||
*map_data = address;
|
||||
}
|
||||
return address;
|
||||
}
|
||||
|
||||
extern "C" void gbm_bo_unmap(struct gbm_bo* bo, void* map_data)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
GbmBufferUnmap(*bo, map_data);
|
||||
}
|
||||
|
||||
extern "C" uint32_t gbm_bo_get_width(struct gbm_bo* bo)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
return bo->Impl.Width;
|
||||
}
|
||||
|
||||
extern "C" uint32_t gbm_bo_get_height(struct gbm_bo* bo)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
return bo->Impl.Height;
|
||||
}
|
||||
|
||||
extern "C" uint32_t gbm_bo_get_stride(struct gbm_bo* bo)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
return bo->Impl.Strides[0];
|
||||
}
|
||||
|
||||
extern "C" uint32_t gbm_bo_get_stride_for_plane(struct gbm_bo* bo, int plane)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
// A plane this buffer does not have is answered with zero, which is the only
|
||||
// value a caller can tell apart from a real stride.
|
||||
if (plane < 0 || plane >= bo->Impl.PlaneCount)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
return bo->Impl.Strides[plane];
|
||||
}
|
||||
|
||||
extern "C" uint32_t gbm_bo_get_format(struct gbm_bo* bo)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
return bo->Impl.Format;
|
||||
}
|
||||
|
||||
extern "C" uint32_t gbm_bo_get_bpp(struct gbm_bo* bo)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
// Bits per pixel: a 32 bit format answers 32, which is what a caller computing a
|
||||
// row length in bits or a row length in bytes from the same number expects.
|
||||
return bo->Impl.BytesPerPixel * 8;
|
||||
}
|
||||
|
||||
extern "C" uint32_t gbm_bo_get_offset(struct gbm_bo* bo, int plane)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
if (plane < 0 || plane >= bo->Impl.PlaneCount)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
return bo->Impl.Offsets[plane];
|
||||
}
|
||||
|
||||
extern "C" struct gbm_device* gbm_bo_get_device(struct gbm_bo* bo)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
return bo->Impl.Owner;
|
||||
}
|
||||
|
||||
extern "C" union gbm_bo_handle gbm_bo_get_handle(struct gbm_bo* bo)
|
||||
{
|
||||
union gbm_bo_handle handle;
|
||||
handle.ptr = nullptr;
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
handle.s32 = -1;
|
||||
return handle;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
// The kernel-level name of a dma-buf in this process is its file descriptor. A
|
||||
// GEM handle would be a name that exists only relative to a DRM node, and this
|
||||
// library deliberately does not require one, so the fd is the only answer here
|
||||
// that is true for every buffer it hands out. Callers that need a name for a
|
||||
// device should ask for the fd and pass that.
|
||||
handle.s32 = bo->Impl.Fds[0];
|
||||
return handle;
|
||||
}
|
||||
|
||||
extern "C" int gbm_bo_get_fd(struct gbm_bo* bo)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
// A dup, close-on-exec, owned by the caller. Closing it cannot affect the buffer
|
||||
// or any other caller's copy.
|
||||
return GbmBufferDupFd(*bo, 0);
|
||||
}
|
||||
|
||||
extern "C" uint64_t gbm_bo_get_modifier(struct gbm_bo* bo)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return DrmFormatModInvalid;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
return bo->Impl.Modifier;
|
||||
}
|
||||
|
||||
extern "C" int gbm_bo_get_plane_count(struct gbm_bo* bo)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
return bo->Impl.PlaneCount;
|
||||
}
|
||||
|
||||
extern "C" union gbm_bo_handle gbm_bo_get_handle_for_plane(struct gbm_bo* bo, int plane)
|
||||
{
|
||||
union gbm_bo_handle handle;
|
||||
handle.ptr = nullptr;
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
handle.s32 = -1;
|
||||
return handle;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
if (plane < 0 || plane >= bo->Impl.PlaneCount)
|
||||
{
|
||||
errno = EINVAL;
|
||||
handle.s32 = -1;
|
||||
return handle;
|
||||
}
|
||||
// Same reasoning as gbm_bo_get_handle: the fd is the buffer's kernel name. Every
|
||||
// plane of a self-allocated buffer lives in the one dma-buf, so all of them
|
||||
// answer with that descriptor; the plane's position inside it is
|
||||
// gbm_bo_get_offset.
|
||||
const Int fd = bo->Impl.Fds[plane] >= 0 ? bo->Impl.Fds[plane] : bo->Impl.Fds[0];
|
||||
handle.s32 = fd;
|
||||
return handle;
|
||||
}
|
||||
|
||||
extern "C" int gbm_bo_get_fd_for_plane(struct gbm_bo* bo, int plane)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
return GbmBufferDupFd(*bo, plane);
|
||||
}
|
||||
|
||||
extern "C" int gbm_bo_write(struct gbm_bo* bo, const void* buf, size_t count)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr || buf == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
if (count == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (count > bo->Impl.AllocationSize)
|
||||
{
|
||||
// Refused rather than truncated: a caller that writes 4 MiB into a 1 MiB
|
||||
// buffer and is told "0 bytes written, success" would read back memory it
|
||||
// never wrote and call the result correct.
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
// The write goes through the same counted mapping the rest of the API uses, so a
|
||||
// caller that already holds the buffer mapped does not get a second mapping (or
|
||||
// lose its own) behind its back.
|
||||
Uint32 stride = 0;
|
||||
void* address = GbmBufferMap(*bo, 0, 0, stride);
|
||||
if (address == nullptr)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
memcpy(address, buf, count);
|
||||
GbmBufferUnmap(*bo, address);
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" void gbm_bo_set_user_data(struct gbm_bo* bo, void* data,
|
||||
void (*destroy_user_data)(struct gbm_bo*, void*))
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
// Assigning over existing data does not call the old callback: the record calls
|
||||
// it exactly once, when the buffer goes away, which is the one moment a caller
|
||||
// can still recognise the pointer it registered.
|
||||
bo->Impl.UserData = data;
|
||||
bo->Impl.UserDataDestroy = destroy_user_data;
|
||||
}
|
||||
|
||||
extern "C" void* gbm_bo_get_user_data(struct gbm_bo* bo)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
return bo->Impl.UserData;
|
||||
}
|
||||
|
||||
extern "C" void gbm_bo_destroy(struct gbm_bo* bo)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
// Drops this caller's reference. A buffer a surface still holds stays alive -
|
||||
// that is what the surface's own reference is for - so destroying a buffer that
|
||||
// is currently presented is not a use-after-free waiting to happen.
|
||||
GbmBufferRelease(*bo->Impl.Owner, *bo);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Surfaces
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
extern "C" struct gbm_surface* gbm_surface_create(struct gbm_device* gbm, uint32_t width, uint32_t height,
|
||||
uint32_t format, uint32_t flags)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(gbm);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
return GbmSurfaceCreate(*gbm, width, height, format, flags, nullptr, 0);
|
||||
}
|
||||
|
||||
extern "C" struct gbm_surface* gbm_surface_create_with_modifiers(struct gbm_device* gbm, uint32_t width,
|
||||
uint32_t height, uint32_t format,
|
||||
const uint64_t* modifiers,
|
||||
const unsigned int count)
|
||||
{
|
||||
// As with the buffer pair: the modifier-less form is the flags-0 case.
|
||||
return gbm_surface_create_with_modifiers2(gbm, width, height, format, modifiers, count, 0);
|
||||
}
|
||||
|
||||
extern "C" struct gbm_surface* gbm_surface_create_with_modifiers2(struct gbm_device* gbm, uint32_t width,
|
||||
uint32_t height, uint32_t format,
|
||||
const uint64_t* modifiers,
|
||||
const unsigned int count, uint32_t flags)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(gbm);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
return GbmSurfaceCreate(*gbm, width, height, format, flags, modifiers, (Uint32)count);
|
||||
}
|
||||
|
||||
extern "C" struct gbm_bo* gbm_surface_lock_front_buffer(struct gbm_surface* surface)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(surface);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
// Null with errno = EBUSY when the compositor still holds every buffer: that is a
|
||||
// state the caller has to handle, and pretending otherwise by handing out a
|
||||
// buffer that is still being scanned out would be a torn frame rather than an
|
||||
// error.
|
||||
return GbmSurfaceLockFront(*surface);
|
||||
}
|
||||
|
||||
extern "C" void gbm_surface_release_buffer(struct gbm_surface* surface, struct gbm_bo* bo)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(surface);
|
||||
if (mutex == nullptr || bo == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
GbmSurfaceReleaseBuffer(*surface, *bo);
|
||||
}
|
||||
|
||||
extern "C" int gbm_surface_has_free_buffers(struct gbm_surface* surface)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(surface);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
// Truthful by construction: the swapchain exists from the moment the surface
|
||||
// does, so this answers about buffers that were really allocated rather than
|
||||
// about how many could still be.
|
||||
return GbmSurfaceHasFreeBuffers(*surface) ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" void gbm_surface_destroy(struct gbm_surface* surface)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(surface);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
GbmSurfaceDestroy(*surface);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Format names
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
extern "C" char* gbm_format_get_name(uint32_t gbm_format, struct gbm_format_name_desc* desc)
|
||||
{
|
||||
if (desc == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
// The name of a fourcc is its four characters, most significant byte last, and
|
||||
// that is all there is to it: a caller compares these strings against "AR24" and
|
||||
// friends, and the big-endian bit is part of the value rather than something to
|
||||
// spell out here.
|
||||
desc->name[0] = (char)(gbm_format & 0xffu);
|
||||
desc->name[1] = (char)((gbm_format >> 8) & 0xffu);
|
||||
desc->name[2] = (char)((gbm_format >> 16) & 0xffu);
|
||||
desc->name[3] = (char)((gbm_format >> 24) & 0xffu);
|
||||
desc->name[4] = '\0';
|
||||
return desc->name;
|
||||
}
|
||||
|
||||
// End of Source File Header
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,835 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Gbm/GbmHostChannel.cpp
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
//
|
||||
// The host-frame backend: the socket the container receives the phone's frames on.
|
||||
//
|
||||
// The container half of MobileGL runs a Wayland compositor, and the frames that
|
||||
// compositor renders into have to be the frames the phone already owns - the phone
|
||||
// allocates them, its GPU draws into them, and its display scans them out. A buffer
|
||||
// allocated from the container's own dma-heap would be a copy that has to travel back
|
||||
// to the phone before anything can be shown, so when the display host is reachable this
|
||||
// backend hands the compositor the phone's own buffers instead, and the fd the
|
||||
// compositor passes on is the fd of a frame the display path already knows.
|
||||
//
|
||||
// What that costs is the one thing GBM normally promises: the geometry. A frame's
|
||||
// width, height, stride and format are the display's and not the caller's, so a
|
||||
// gbm_bo_create that takes an offered frame answers with the offer's geometry, and the
|
||||
// caller reads it back with gbm_bo_get_width and its neighbours. That is this backend's
|
||||
// documented behaviour rather than a surprise: the host decides what a frame is.
|
||||
//
|
||||
// Three rules keep this backend from ever being worse than not having it.
|
||||
//
|
||||
// * Nothing on the allocation path blocks. The socket is non-blocking and connect()
|
||||
// to a pathname socket either succeeds or fails immediately, so a call that cannot
|
||||
// be served from the host falls through to a local allocation inside the same call
|
||||
// instead of waiting for a phone that may never answer. The one wait in this file is
|
||||
// in device creation, after a display host has already accepted the connection, and
|
||||
// it exists because of a measured race: the compositor builds its swapchain within
|
||||
// microseconds of creating the device, while the offer for the first frame needs the
|
||||
// round trip of the connection plus whatever the phone does before it sends. Without
|
||||
// that wait the swapchain - the buffers that are shown for the life of the process -
|
||||
// is allocated locally and the host's frames arrive for nobody to take.
|
||||
// * A channel that dies is closed and marked down, and the next frame is allocated
|
||||
// locally again. This library is loaded by a compositor that has to keep painting,
|
||||
// so losing the display host may cost the frames their path to the screen but it
|
||||
// may not cost the session.
|
||||
// * A frame is released exactly once, when the record holding it is destroyed, and
|
||||
// only into the connection that offered it. Releasing on gbm_bo_destroy would be a
|
||||
// lie - the surface may still be scanning that frame out - and releasing an old
|
||||
// frame into a new connection would free a slot belonging to another session.
|
||||
//
|
||||
// The device mutex is the only lock in here. Both callers of this file - the allocation
|
||||
// path and the buffer record's destructor - already run under it, so there is no second
|
||||
// lock to order against and no state of this file's own that another thread can see.
|
||||
|
||||
#include "GbmInternal.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cerrno>
|
||||
#include <chrono>
|
||||
|
||||
namespace MobileGL::MG_Gbm
|
||||
{
|
||||
namespace
|
||||
{
|
||||
// One frame per message, and a message is the offer followed by the handle the
|
||||
// offer describes. 4 KiB is far more than an AHardwareBuffer handle needs (a
|
||||
// handle is a version, two counts and their two arrays) while still being small
|
||||
// enough that a message which does not fit is a peer speaking something else -
|
||||
// which is worth refusing rather than growing a buffer for.
|
||||
constexpr SizeT GbmHostMessageMax = 4096;
|
||||
|
||||
// The descriptors one handle may carry. An AHardwareBuffer handle carries one
|
||||
// (the dma-buf) in every layout this library has seen and the protocol reads only
|
||||
// the first, so this sizes the control buffer rather than claiming anything about
|
||||
// real handles.
|
||||
constexpr Int GbmHostMaxFds = 8;
|
||||
|
||||
// How many messages one gbm_bo_create may look at before it gives up and
|
||||
// allocates locally. An unusable message is skipped rather than fatal, so this
|
||||
// bounds the work a peer that sends nothing but unusable messages can cause
|
||||
// inside a single allocation.
|
||||
constexpr Int GbmHostTakeAttempts = 16;
|
||||
|
||||
// The floor between two connection attempts. A container with no display host is
|
||||
// the normal case, so a retry may not turn every allocation into a connect plus a
|
||||
// log line; one attempt per second is often enough that a phone which comes up is
|
||||
// picked up within a frame or two of the compositor's next allocation.
|
||||
constexpr std::chrono::milliseconds GbmHostRetryInterval{1000};
|
||||
|
||||
// How long device creation waits for the display host's first frame once the
|
||||
// connection is up. A frame the phone offers immediately needs one round trip on
|
||||
// a unix socket, so this is orders of magnitude more than that and it is only
|
||||
// ever spent by a device that has a host which then says nothing; a compile or a
|
||||
// test run without a display host never reaches it, because the connect fails
|
||||
// first.
|
||||
constexpr Int GbmHostFirstOfferWaitMs = 250;
|
||||
|
||||
// Frame releases the socket would not take. A release is twelve bytes, so a full
|
||||
// socket buffer is hundreds of frames' worth of them and this queue is only
|
||||
// reached once the phone has stopped reading; the cap is what stops a peer that
|
||||
// never reads from growing it without bound.
|
||||
constexpr SizeT GbmHostMaxPendingReleases = 256;
|
||||
|
||||
// sun_path is where a pathname socket's name lives, and a name that does not fit
|
||||
// is one the kernel cannot be told about at all.
|
||||
constexpr SizeT GbmHostPathMax = sizeof(((struct sockaddr_un*)nullptr)->sun_path);
|
||||
|
||||
// close() may overwrite errno, and every caller here is in the middle of
|
||||
// reporting a failure that errno describes. Saving it around the close keeps the
|
||||
// reported failure the one that happened.
|
||||
void GbmHostCloseQuietly(Int fd) noexcept
|
||||
{
|
||||
if (fd < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
const Int savedErrno = errno;
|
||||
close(fd);
|
||||
errno = savedErrno;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// One connection to the display host, for the life of one device.
|
||||
class GbmHostChannel
|
||||
{
|
||||
public:
|
||||
explicit GbmHostChannel(const String& path) noexcept : Path(path) {}
|
||||
~GbmHostChannel() noexcept;
|
||||
|
||||
GbmHostChannel(const GbmHostChannel&) = delete;
|
||||
GbmHostChannel& operator=(const GbmHostChannel&) = delete;
|
||||
|
||||
// Connects when there is no connection and the retry interval has passed. A
|
||||
// failure is never the caller's problem: the channel stays closed and the
|
||||
// allocation that asked for a frame falls back to local memory.
|
||||
void EnsureOpen(::gbm_device& device) noexcept;
|
||||
|
||||
// Waits, once, for the connection's first frame to be readable. Called from
|
||||
// device creation and nowhere else: see the banner for why that one wait exists.
|
||||
void AwaitFirstOffer(::gbm_device& device) noexcept;
|
||||
|
||||
// The next frame the host offered, or false when none is waiting.
|
||||
Bool TakeFrame(::gbm_device& device, GbmHostFrame& frameOut) noexcept;
|
||||
|
||||
// Queues the release for one frame and tries to send what is queued.
|
||||
void ReleaseFrame(::gbm_device& device, Uint32 seq, Uint64 generation) noexcept;
|
||||
|
||||
private:
|
||||
// Turns one message into a frame. Everything it refuses is reported with the
|
||||
// reason, because a peer this library cannot understand is the one thing that
|
||||
// would otherwise be invisible from the outside.
|
||||
Bool ParseOffer(const Uint8* payload, SizeT length, const Int* fds, Int fdCount,
|
||||
GbmHostFrame& frameOut) noexcept;
|
||||
|
||||
// Sends what is queued. False means the connection can no longer be trusted to
|
||||
// carry a twelve byte message, with errno describing what happened.
|
||||
Bool FlushReleases() noexcept;
|
||||
|
||||
// Closes the socket and drops whatever was queued for it.
|
||||
void CloseSocket() noexcept;
|
||||
|
||||
// Closes the socket and tells the device what that means for its backend name.
|
||||
void MarkDown(::gbm_device& device, const char* what, Int error) noexcept;
|
||||
|
||||
String Path;
|
||||
Int SocketFd = -1;
|
||||
// Set by a connection this process has just made, and read once by the allocation that
|
||||
// follows it: the accept and the frame that answers the dial happen on the other side of
|
||||
// this socket, so an allocation that reads immediately after connecting reads before the
|
||||
// answer to its own connection has been written. See TakeFrame.
|
||||
Bool FreshConnection = false;
|
||||
// Bumped by every connection, so a frame taken from a connection which has since
|
||||
// died can be recognised as one that must not be released into its replacement.
|
||||
Uint64 Generation = 0;
|
||||
std::chrono::steady_clock::time_point NextRetry{};
|
||||
// The errno of the last failed attempt, so that a failure which repeats once a
|
||||
// second is not logged once a second.
|
||||
Int LastFailureErrno = 0;
|
||||
std::vector<GbmFrameRelease> PendingReleases;
|
||||
Bool ReleaseOverflowLogged = false;
|
||||
};
|
||||
|
||||
// ---- the offered-frame record ------------------------------------------
|
||||
|
||||
GbmHostFrame::~GbmHostFrame()
|
||||
{
|
||||
// The record owns the dup it was built on, which is why it is move-only: a copy
|
||||
// would close the same descriptor twice.
|
||||
if (Fd >= 0)
|
||||
{
|
||||
close(Fd);
|
||||
Fd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
GbmHostFrame::GbmHostFrame(GbmHostFrame&& other) noexcept
|
||||
{
|
||||
*this = static_cast<GbmHostFrame&&>(other);
|
||||
}
|
||||
|
||||
GbmHostFrame& GbmHostFrame::operator=(GbmHostFrame&& other) noexcept
|
||||
{
|
||||
if (this == &other)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
if (Fd >= 0)
|
||||
{
|
||||
close(Fd);
|
||||
}
|
||||
Seq = other.Seq;
|
||||
Index = other.Index;
|
||||
Width = other.Width;
|
||||
Height = other.Height;
|
||||
StrideBytes = other.StrideBytes;
|
||||
Format = other.Format;
|
||||
BytesPerPixel = other.BytesPerPixel;
|
||||
Usage = other.Usage;
|
||||
Generation = other.Generation;
|
||||
Fd = other.Fd;
|
||||
Size = other.Size;
|
||||
// The source must not close what this record now owns.
|
||||
other.Fd = -1;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ---- the connection ----------------------------------------------------
|
||||
|
||||
GbmHostChannel::~GbmHostChannel() noexcept
|
||||
{
|
||||
// One last try for whatever is queued - the phone may still be reading - and
|
||||
// then the socket goes away with the process.
|
||||
if (SocketFd >= 0 && !PendingReleases.empty())
|
||||
{
|
||||
FlushReleases();
|
||||
}
|
||||
if (!PendingReleases.empty())
|
||||
{
|
||||
MGLOG_W("gbm: %zu frame release(s) could not be sent to the display host at %s; the phone reclaims "
|
||||
"those slots when the session ends",
|
||||
PendingReleases.size(), Path.c_str());
|
||||
}
|
||||
CloseSocket();
|
||||
}
|
||||
|
||||
void GbmHostChannel::EnsureOpen(::gbm_device& device) noexcept
|
||||
{
|
||||
if (SocketFd >= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
const std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
|
||||
if (now < NextRetry)
|
||||
{
|
||||
return;
|
||||
}
|
||||
NextRetry = now + GbmHostRetryInterval;
|
||||
|
||||
// SOCK_SEQPACKET because a frame and its descriptors are one message and the
|
||||
// reader may not reassemble either half; SOCK_NONBLOCK because the caller is a
|
||||
// compositor's frame loop and may not be parked on a phone; SOCK_CLOEXEC because
|
||||
// every process this compositor starts would otherwise inherit a socket it can
|
||||
// read frames from.
|
||||
const Int fd = socket(AF_UNIX, SOCK_SEQPACKET | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
|
||||
if (fd < 0)
|
||||
{
|
||||
MGLOG_E_ONCE("gbm: cannot create the socket to the display host (%d: %s); every frame is allocated "
|
||||
"locally",
|
||||
errno, strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
if (Path.empty() || Path.size() >= GbmHostPathMax)
|
||||
{
|
||||
MGLOG_E_ONCE("gbm: the display host socket path \"%s\" does not fit in sun_path (%zu bytes); every "
|
||||
"frame is allocated locally",
|
||||
Path.c_str(), GbmHostPathMax);
|
||||
GbmHostCloseQuietly(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
struct sockaddr_un address = {};
|
||||
address.sun_family = AF_UNIX;
|
||||
// The terminator travels with the name: sun_path is a C string for a pathname
|
||||
// socket, and a name without one is a name the kernel reads past the end of.
|
||||
memcpy(address.sun_path, Path.c_str(), Path.size() + 1);
|
||||
|
||||
if (connect(fd, reinterpret_cast<struct sockaddr*>(&address), sizeof(address)) != 0)
|
||||
{
|
||||
const Int connectErrno = errno;
|
||||
GbmHostCloseQuietly(fd);
|
||||
// A failure that repeats once a second is not news: a container with no
|
||||
// display host fails here on every retry, and a line per second saying so
|
||||
// would bury the rest of the log. A failure that changed is news, because it
|
||||
// says the path or the peer changed.
|
||||
if (connectErrno != LastFailureErrno)
|
||||
{
|
||||
LastFailureErrno = connectErrno;
|
||||
if (connectErrno == EPROTOTYPE)
|
||||
{
|
||||
MGLOG_E("gbm: %s is a socket of a different type (%d: %s). The frame protocol is "
|
||||
"SOCK_SEQPACKET - one message per frame, carrying that frame's descriptors - "
|
||||
"because a reader cannot tell from a byte stream which frame a descriptor "
|
||||
"belongs to; frames are allocated locally instead",
|
||||
Path.c_str(), connectErrno, strerror(connectErrno));
|
||||
}
|
||||
else
|
||||
{
|
||||
MGLOG_I("gbm: no display host at %s (%d: %s); every frame is allocated locally until one "
|
||||
"answers",
|
||||
Path.c_str(), connectErrno, strerror(connectErrno));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
SocketFd = fd;
|
||||
FreshConnection = true;
|
||||
// A new connection is a new session with its own frames, which is what makes the
|
||||
// generation a correct answer to "may this release be sent here".
|
||||
Generation++;
|
||||
LastFailureErrno = 0;
|
||||
device.Impl.HostAvailable = true;
|
||||
device.Impl.BackendName = "mobilegl-host-frame";
|
||||
MGLOG_I("gbm: connected to the display host at %s (one SOCK_SEQPACKET message per frame, up to %zu "
|
||||
"bytes); frames offered over it become gbm_bos whose geometry is the offer's",
|
||||
Path.c_str(), GbmHostMessageMax);
|
||||
}
|
||||
|
||||
void GbmHostChannel::AwaitFirstOffer(::gbm_device& device) noexcept
|
||||
{
|
||||
if (SocketFd < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
const std::chrono::steady_clock::time_point deadline =
|
||||
std::chrono::steady_clock::now() + std::chrono::milliseconds(GbmHostFirstOfferWaitMs);
|
||||
for (;;)
|
||||
{
|
||||
const std::chrono::milliseconds left =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(deadline - std::chrono::steady_clock::now());
|
||||
if (left.count() <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
// poll() and not recvmsg(): the frame has to stay in the socket for the
|
||||
// allocation that is about to ask for it, and a peek at a message carrying
|
||||
// SCM_RIGHTS is a question with no safe answer.
|
||||
struct pollfd waiting = {};
|
||||
waiting.fd = SocketFd;
|
||||
waiting.events = POLLIN;
|
||||
const Int ready = poll(&waiting, 1, (Int)left.count());
|
||||
if (ready > 0)
|
||||
{
|
||||
MGLOG_I("gbm: the display host at %s has a frame waiting; the buffers the compositor is about "
|
||||
"to allocate come from it",
|
||||
Path.c_str());
|
||||
return;
|
||||
}
|
||||
if (ready == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (errno != EINTR)
|
||||
{
|
||||
MarkDown(device, "poll", errno);
|
||||
return;
|
||||
}
|
||||
}
|
||||
MGLOG_W("gbm: the display host at %s accepted the connection but offered no frame within %d ms; the "
|
||||
"buffers allocated before its first frame are local ones",
|
||||
Path.c_str(), GbmHostFirstOfferWaitMs);
|
||||
}
|
||||
|
||||
Bool GbmHostChannel::TakeFrame(::gbm_device& device, GbmHostFrame& frameOut) noexcept
|
||||
{
|
||||
EnsureOpen(device);
|
||||
if (SocketFd < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// THE FIRST ALLOCATION AFTER A DIAL WAITS FOR THE ANSWER TO IT. The accept and the offer that
|
||||
// answers the connection this call has just made are written by the phone, a round trip
|
||||
// behind the connect() that returns here — and what is allocated before that offer arrives
|
||||
// is a local buffer, which is what a compositor builds its whole swapchain out of and then
|
||||
// keeps for the life of the process. So a connection made on this path is given the same
|
||||
// first-offer window device creation gives one, once, and only while it is new.
|
||||
if (FreshConnection)
|
||||
{
|
||||
FreshConnection = false;
|
||||
AwaitFirstOffer(device);
|
||||
}
|
||||
// Releases the socket would not take last time are retried here, because this is
|
||||
// the one call in the library that happens once per frame and therefore the
|
||||
// natural place for a queue waiting for room to get its next chance.
|
||||
if (!PendingReleases.empty() && !FlushReleases())
|
||||
{
|
||||
MarkDown(device, "sendmsg", errno);
|
||||
return false;
|
||||
}
|
||||
|
||||
Uint8 payload[GbmHostMessageMax];
|
||||
for (Int attempt = 0; attempt < GbmHostTakeAttempts; ++attempt)
|
||||
{
|
||||
Int receivedFds[GbmHostMaxFds];
|
||||
for (Int i = 0; i < GbmHostMaxFds; ++i)
|
||||
{
|
||||
receivedFds[i] = -1;
|
||||
}
|
||||
|
||||
struct iovec payloadVector = {};
|
||||
payloadVector.iov_base = payload;
|
||||
payloadVector.iov_len = sizeof(payload);
|
||||
|
||||
Uint8 control[CMSG_SPACE(sizeof(Int) * GbmHostMaxFds)] = {};
|
||||
|
||||
struct msghdr message = {};
|
||||
message.msg_iov = &payloadVector;
|
||||
message.msg_iovlen = 1;
|
||||
message.msg_control = control;
|
||||
message.msg_controllen = sizeof(control);
|
||||
|
||||
// MSG_DONTWAIT for the promise at the top of this file, and MSG_CMSG_CLOEXEC
|
||||
// so a descriptor the phone sent does not survive into a child of this
|
||||
// compositor, which would then hold a frame nothing will ever release.
|
||||
const ssize_t received = recvmsg(SocketFd, &message, MSG_DONTWAIT | MSG_CMSG_CLOEXEC);
|
||||
if (received < 0)
|
||||
{
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK)
|
||||
{
|
||||
// Nothing offered yet, which is what an idle display looks like. The
|
||||
// caller allocates locally and asks again on its next frame.
|
||||
return false;
|
||||
}
|
||||
if (errno == EINTR)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
MarkDown(device, "recvmsg", errno);
|
||||
return false;
|
||||
}
|
||||
|
||||
// The descriptors come out of the control data before anything is decided
|
||||
// about the message, because they belong to this process from the moment it
|
||||
// was received: a path that returns without closing them leaks a descriptor
|
||||
// per unusable message.
|
||||
Int fdCount = 0;
|
||||
for (struct cmsghdr* header = CMSG_FIRSTHDR(&message); header != nullptr;
|
||||
header = CMSG_NXTHDR(&message, header))
|
||||
{
|
||||
if (header->cmsg_level != SOL_SOCKET || header->cmsg_type != SCM_RIGHTS)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
const SizeT bytes = (SizeT)header->cmsg_len - CMSG_LEN(0);
|
||||
const Int count = (Int)(bytes / sizeof(Int));
|
||||
const Int* descriptors = reinterpret_cast<const Int*>(CMSG_DATA(header));
|
||||
for (Int i = 0; i < count; ++i)
|
||||
{
|
||||
if (fdCount < GbmHostMaxFds)
|
||||
{
|
||||
receivedFds[fdCount++] = descriptors[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
// More descriptors than a frame can carry: they are this
|
||||
// process's now, so they are closed here rather than leaked.
|
||||
GbmHostCloseQuietly(descriptors[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((message.msg_flags & MSG_CTRUNC) != 0)
|
||||
{
|
||||
MGLOG_W_ONCE("gbm: an offered frame's control data did not fit in %zu bytes; the frame is "
|
||||
"skipped because its descriptor list is incomplete",
|
||||
sizeof(control));
|
||||
for (Int i = 0; i < fdCount; ++i)
|
||||
{
|
||||
GbmHostCloseQuietly(receivedFds[i]);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (received == 0)
|
||||
{
|
||||
// Zero bytes on a connected socket is the end of it, whether the phone
|
||||
// closed cleanly or the kernel gave up on it. Either way the frames have
|
||||
// to come from somewhere else from here on.
|
||||
for (Int i = 0; i < fdCount; ++i)
|
||||
{
|
||||
GbmHostCloseQuietly(receivedFds[i]);
|
||||
}
|
||||
MarkDown(device, "the display host closed the connection", 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((message.msg_flags & MSG_TRUNC) != 0)
|
||||
{
|
||||
// Longer than a frame message can be, so it is not one - and on a
|
||||
// message-oriented socket the rest is already gone while the next message
|
||||
// is still a whole message, which is why this skips one message instead
|
||||
// of ending the channel.
|
||||
MGLOG_W_ONCE("gbm: the display host sent a message longer than %zu bytes; it is skipped",
|
||||
GbmHostMessageMax);
|
||||
for (Int i = 0; i < fdCount; ++i)
|
||||
{
|
||||
GbmHostCloseQuietly(receivedFds[i]);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
const Bool parsed = ParseOffer(payload, (SizeT)received, receivedFds, fdCount, frameOut);
|
||||
// Whatever the frame did not keep is closed here: the copy of the dma-buf
|
||||
// descriptor the phone sent (the frame owns its own dup) and the rest of the
|
||||
// handle, which is a layout this library does not interpret.
|
||||
for (Int i = 0; i < fdCount; ++i)
|
||||
{
|
||||
GbmHostCloseQuietly(receivedFds[i]);
|
||||
}
|
||||
if (parsed)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Bool GbmHostChannel::ParseOffer(const Uint8* payload, SizeT length, const Int* fds, Int fdCount,
|
||||
GbmHostFrame& frameOut) noexcept
|
||||
{
|
||||
constexpr SizeT HeaderBytes = sizeof(GbmFrameOffer) + sizeof(AHBNativeHandleHeader);
|
||||
if (length < HeaderBytes)
|
||||
{
|
||||
MGLOG_W_ONCE("gbm: the display host sent a %zu byte message where a frame message is at least %zu "
|
||||
"bytes (the offer followed by the handle header); it is skipped",
|
||||
length, HeaderBytes);
|
||||
return false;
|
||||
}
|
||||
|
||||
GbmFrameOffer offer = {};
|
||||
memcpy(&offer, payload, sizeof(offer));
|
||||
if (offer.Magic != GbmFrameOfferMagic)
|
||||
{
|
||||
MGLOG_W_ONCE("gbm: a message from the display host begins with 0x%08x rather than 'MGGF'; it is "
|
||||
"skipped",
|
||||
offer.Magic);
|
||||
return false;
|
||||
}
|
||||
if (offer.Version != GbmHostProtocolVersion)
|
||||
{
|
||||
// Refused rather than read as if the versions agreed: the version is what
|
||||
// says how the rest of the message is laid out, and a frame read with the
|
||||
// wrong layout is memory the compositor would render into.
|
||||
MGLOG_E_ONCE("gbm: the display host offers frames in protocol version %u where this library speaks "
|
||||
"version %u; its frames are refused until the two agree",
|
||||
offer.Version, (Uint32)GbmHostProtocolVersion);
|
||||
return false;
|
||||
}
|
||||
|
||||
AHBNativeHandleHeader handle = {};
|
||||
memcpy(&handle, payload + sizeof(offer), sizeof(handle));
|
||||
if (handle.NumFds < 1 || handle.NumInts < 0)
|
||||
{
|
||||
MGLOG_W_ONCE("gbm: an offered frame's handle carries %d descriptor(s) and %d integer(s), where the "
|
||||
"dma-buf is the first descriptor and there has to be one; the frame is skipped",
|
||||
handle.NumFds, handle.NumInts);
|
||||
return false;
|
||||
}
|
||||
|
||||
// The handle describes itself with its two counts, so the message has to be
|
||||
// exactly as long as those counts make it. Any other length means the two ends
|
||||
// disagree about the layout, and a frame built from a message whose layout was
|
||||
// guessed is a buffer of unknown memory.
|
||||
const SizeT expected = HeaderBytes + ((SizeT)handle.NumFds + (SizeT)handle.NumInts) * sizeof(Int32);
|
||||
if (length != expected)
|
||||
{
|
||||
MGLOG_W_ONCE("gbm: an offered frame's message is %zu bytes where its handle (%d descriptors, %d "
|
||||
"integers) makes it %zu; the frame is skipped",
|
||||
length, handle.NumFds, handle.NumInts, expected);
|
||||
return false;
|
||||
}
|
||||
if (fdCount < handle.NumFds)
|
||||
{
|
||||
MGLOG_W_ONCE("gbm: an offered frame's handle names %d descriptor(s) and %d arrived with the "
|
||||
"message; the frame is skipped",
|
||||
handle.NumFds, fdCount);
|
||||
return false;
|
||||
}
|
||||
if (offer.Width == 0 || offer.Height == 0 || offer.StrideBytes == 0)
|
||||
{
|
||||
MGLOG_W_ONCE("gbm: an offered frame is %ux%u with a stride of %u bytes; a buffer with no size is "
|
||||
"not one this library can hand out",
|
||||
offer.Width, offer.Height, offer.StrideBytes);
|
||||
return false;
|
||||
}
|
||||
|
||||
// The frame is built on a dup of the first descriptor rather than on the
|
||||
// descriptor itself: the copy that arrived belongs to the message, and the frame
|
||||
// outlives it. Close-on-exec, like every other descriptor this library hands out.
|
||||
const Int frameFd = fcntl(fds[0], F_DUPFD_CLOEXEC, 0);
|
||||
if (frameFd < 0)
|
||||
{
|
||||
MGLOG_E_ONCE("gbm: cannot dup the descriptor of an offered frame (%d: %s)", errno, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
// How long the frame really is, asked of the descriptor instead of computed from
|
||||
// the geometry: a gralloc dma-buf is usually larger than stride x height, and a
|
||||
// mapping has to cover what exists rather than what the arithmetic expects.
|
||||
SizeT size = 0;
|
||||
const off_t end = lseek(frameFd, 0, SEEK_END);
|
||||
if (end > 0)
|
||||
{
|
||||
size = (SizeT)end;
|
||||
}
|
||||
const SizeT described = (SizeT)offer.StrideBytes * (SizeT)offer.Height;
|
||||
if (size == 0)
|
||||
{
|
||||
// A descriptor that does not answer for its own length - an exporter that
|
||||
// does not implement llseek - leaves the offer's arithmetic as the only
|
||||
// length there is.
|
||||
size = described;
|
||||
}
|
||||
if (size < described)
|
||||
{
|
||||
MGLOG_W_ONCE("gbm: an offered frame's descriptor holds %zu bytes where %u rows of %u bytes need %zu; "
|
||||
"the frame is skipped rather than mapped over memory that is not there",
|
||||
size, offer.Height, offer.StrideBytes, described);
|
||||
GbmHostCloseQuietly(frameFd);
|
||||
return false;
|
||||
}
|
||||
|
||||
frameOut.Seq = offer.Seq;
|
||||
frameOut.Index = offer.Index;
|
||||
frameOut.Width = offer.Width;
|
||||
frameOut.Height = offer.Height;
|
||||
frameOut.StrideBytes = offer.StrideBytes;
|
||||
frameOut.Format = offer.Format;
|
||||
frameOut.Usage = ((Uint64)offer.UsageHi << 32) | (Uint64)offer.UsageLo;
|
||||
frameOut.Generation = Generation;
|
||||
frameOut.Fd = frameFd;
|
||||
frameOut.Size = size;
|
||||
frameOut.BytesPerPixel = GbmFormatBytesPerPixel(offer.Format);
|
||||
if (frameOut.BytesPerPixel == 0)
|
||||
{
|
||||
// A format this library has no table entry for is still a frame the phone
|
||||
// drew. The offer's stride is then the only description of a pixel that
|
||||
// exists: a row of Width pixels is StrideBytes long.
|
||||
frameOut.BytesPerPixel = offer.StrideBytes / offer.Width;
|
||||
}
|
||||
|
||||
MGLOG_I("gbm: frame seq=%u index=%u %ux%u stride=%u format=0x%08x (%u bytes per pixel, %zu bytes "
|
||||
"measured) taken from the display host",
|
||||
offer.Seq, offer.Index, offer.Width, offer.Height, offer.StrideBytes, offer.Format,
|
||||
frameOut.BytesPerPixel, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
void GbmHostChannel::ReleaseFrame(::gbm_device& device, Uint32 seq, Uint64 generation) noexcept
|
||||
{
|
||||
if (SocketFd < 0)
|
||||
{
|
||||
// A release only means anything on the connection that offered the frame,
|
||||
// and there is none.
|
||||
return;
|
||||
}
|
||||
if (generation != Generation)
|
||||
{
|
||||
// The frame was offered by a connection that has since died and been
|
||||
// replaced. Sending this into the replacement would name a frame of another
|
||||
// session, and the phone would recycle a slot this buffer was not made of.
|
||||
MGLOG_W_ONCE("gbm: a frame offered by a display host connection that has since died is not "
|
||||
"released into its replacement");
|
||||
return;
|
||||
}
|
||||
if (PendingReleases.size() >= GbmHostMaxPendingReleases)
|
||||
{
|
||||
if (!ReleaseOverflowLogged)
|
||||
{
|
||||
ReleaseOverflowLogged = true;
|
||||
MGLOG_W("gbm: %zu frame releases to the display host at %s are already waiting for room in the "
|
||||
"socket; this one is dropped rather than queued without bound, and the phone reclaims "
|
||||
"the slot when the session ends",
|
||||
PendingReleases.size(), Path.c_str());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
GbmFrameRelease release = {};
|
||||
release.Magic = GbmFrameReleaseMagic;
|
||||
release.Version = GbmHostProtocolVersion;
|
||||
release.Seq = seq;
|
||||
PendingReleases.push_back(release);
|
||||
|
||||
if (!FlushReleases())
|
||||
{
|
||||
MarkDown(device, "sendmsg", errno);
|
||||
}
|
||||
}
|
||||
|
||||
Bool GbmHostChannel::FlushReleases() noexcept
|
||||
{
|
||||
while (!PendingReleases.empty())
|
||||
{
|
||||
struct iovec releaseVector = {};
|
||||
releaseVector.iov_base = &PendingReleases.front();
|
||||
releaseVector.iov_len = sizeof(GbmFrameRelease);
|
||||
|
||||
struct msghdr message = {};
|
||||
message.msg_iov = &releaseVector;
|
||||
message.msg_iovlen = 1;
|
||||
|
||||
// MSG_DONTWAIT for the same reason every other call here is non-blocking, and
|
||||
// MSG_NOSIGNAL because a compositor killed by SIGPIPE when the phone goes
|
||||
// away is a desktop that disappears with it.
|
||||
const ssize_t sent = sendmsg(SocketFd, &message, MSG_DONTWAIT | MSG_NOSIGNAL);
|
||||
if (sent == (ssize_t)sizeof(GbmFrameRelease))
|
||||
{
|
||||
PendingReleases.erase(PendingReleases.begin());
|
||||
continue;
|
||||
}
|
||||
if (sent < 0 && errno == EINTR)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (sent < 0 && (errno == EAGAIN || errno == EWOULDBLOCK))
|
||||
{
|
||||
// A full socket is a phone that has stopped reading rather than a dead
|
||||
// one: the release stays queued and goes out with a later frame.
|
||||
return true;
|
||||
}
|
||||
// A short send, a reset and a broken pipe all say the same thing: this
|
||||
// connection can no longer be trusted to have carried a twelve byte message,
|
||||
// and acting on a maybe is worse than handing the slot back when the session
|
||||
// ends. errno describes which of them it was.
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void GbmHostChannel::CloseSocket() noexcept
|
||||
{
|
||||
if (SocketFd >= 0)
|
||||
{
|
||||
GbmHostCloseQuietly(SocketFd);
|
||||
SocketFd = -1;
|
||||
}
|
||||
PendingReleases.clear();
|
||||
}
|
||||
|
||||
void GbmHostChannel::MarkDown(::gbm_device& device, const char* what, Int error) noexcept
|
||||
{
|
||||
if (!PendingReleases.empty())
|
||||
{
|
||||
MGLOG_W("gbm: %zu frame release(s) were still queued for the display host and cannot be sent over a "
|
||||
"connection that is gone; the phone reclaims those slots when the session ends",
|
||||
PendingReleases.size());
|
||||
}
|
||||
CloseSocket();
|
||||
if (error != 0)
|
||||
{
|
||||
MGLOG_W("gbm: the display host connection at %s is down: %s failed (%d: %s); frames are allocated "
|
||||
"locally from here on, and a new connection is attempted on a later allocation",
|
||||
Path.c_str(), what, error, strerror(error));
|
||||
}
|
||||
else
|
||||
{
|
||||
MGLOG_W("gbm: the display host connection at %s is down: %s; frames are allocated locally from here "
|
||||
"on, and a new connection is attempted on a later allocation",
|
||||
Path.c_str(), what);
|
||||
}
|
||||
device.Impl.HostAvailable = false;
|
||||
device.Impl.BackendName = device.Impl.SelfAllocatedBackendName;
|
||||
}
|
||||
|
||||
// ---- the device-facing entry points ------------------------------------
|
||||
|
||||
void GbmHostChannelCreate(::gbm_device& device) noexcept
|
||||
{
|
||||
const char* configured = getenv("MOBILEGL_GBM_SOCKET");
|
||||
const String path =
|
||||
(configured != nullptr && configured[0] != '\0') ? String(configured) : String("/run/mobilegl-gbm.sock");
|
||||
device.Impl.SocketPath = path;
|
||||
try
|
||||
{
|
||||
GbmHostChannel* channel = new GbmHostChannel(path);
|
||||
device.Impl.Host = channel;
|
||||
// The one attempt made at creation. It is allowed to fail: a machine that is
|
||||
// not the container half of a split run has no display host, and that is a
|
||||
// device which allocates locally rather than a device that could not exist.
|
||||
channel->EnsureOpen(device);
|
||||
// A connection that came up is waited on once, and only here, so that the
|
||||
// compositor's swapchain is built out of the host's frames rather than out of
|
||||
// local ones it will keep for the life of the process.
|
||||
channel->AwaitFirstOffer(device);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
device.Impl.Host = nullptr;
|
||||
device.Impl.HostAvailable = false;
|
||||
MGLOG_W("gbm: the display host channel could not be created; every frame is allocated locally");
|
||||
}
|
||||
}
|
||||
|
||||
void GbmHostChannelDestroy(::gbm_device& device) noexcept
|
||||
{
|
||||
GbmHostChannel* channel = device.Impl.Host;
|
||||
if (channel == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
device.Impl.Host = nullptr;
|
||||
device.Impl.HostAvailable = false;
|
||||
delete channel;
|
||||
}
|
||||
|
||||
Bool GbmHostChannelTakeFrame(::gbm_device& device, GbmHostFrame& frameOut) noexcept
|
||||
{
|
||||
GbmHostChannel* channel = device.Impl.Host;
|
||||
if (channel == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return channel->TakeFrame(device, frameOut);
|
||||
}
|
||||
|
||||
void GbmHostChannelReleaseFrame(::gbm_device& device, Uint32 seq, Uint64 generation) noexcept
|
||||
{
|
||||
GbmHostChannel* channel = device.Impl.Host;
|
||||
if (channel == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
channel->ReleaseFrame(device, seq, generation);
|
||||
}
|
||||
} // namespace MobileGL::MG_Gbm
|
||||
|
||||
// End of Source File Header
|
||||
@@ -1,476 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Gbm/GbmInternal.h
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
//
|
||||
// This header carries the internal model shared by the GBM front-end files: the
|
||||
// device, buffer-object and surface records, the two allocation backends, and the
|
||||
// wire protocol used to talk to a phone that owns the real display hardware.
|
||||
//
|
||||
// The reason a GBM implementation has to exist in this tree at all is that the
|
||||
// container half of MobileGL runs a Wayland compositor (kwin). That compositor
|
||||
// needs libgbm to allocate the buffers it renders into, and the fd of such a
|
||||
// buffer is handed to the Anland display producer, which ships the frame to the
|
||||
// phone. If Mesa's libgbm is loaded, the compositor renders into Mesa buffers and
|
||||
// the phone ends up receiving a copy through a path that was never designed to
|
||||
// carry them. When this library is loaded instead, the buffers are either frames
|
||||
// the phone itself offered to us, or buffers allocated from the kernel's dma-heap
|
||||
// so that they are dma-bufs the display host can consume directly.
|
||||
//
|
||||
// The ownership rules below are the whole contract, because every one of them is
|
||||
// observable from outside this library:
|
||||
//
|
||||
// * A buffer record owns its descriptors. gbm_bo_get_fd and
|
||||
// gbm_bo_get_fd_for_plane hand out a dup, so a caller that closes what it was
|
||||
// given cannot invalidate the buffer, and the matching close happens exactly
|
||||
// once, in ~GbmBufferObject.
|
||||
// * A mapping is one mmap of the buffer's fd, counted rather than duplicated, so
|
||||
// two overlapping gbm_bo_map calls share one address and the last matching
|
||||
// gbm_bo_unmap releases it.
|
||||
// * A surface owns one reference per swapchain buffer, and every
|
||||
// gbm_surface_lock_front_buffer hands the caller a reference of its own. That
|
||||
// is what makes gbm_bo_destroy on a locked buffer harmless: it drops the
|
||||
// caller's reference and leaves the surface's bookkeeping intact.
|
||||
// * One mutex per device. GBM calls arrive from the compositor's render thread
|
||||
// and from its main thread, and the state they touch (the buffer table, the
|
||||
// swapchains, the backends) is small enough that one lock is cheaper than
|
||||
// several - and, more importantly, one lock cannot be taken in the wrong order.
|
||||
//
|
||||
// The helpers declared at the bottom of this file are the entire internal interface
|
||||
// between GbmDevice.cpp (the records and the self-allocated backend) and GbmApi.cpp
|
||||
// (the extern "C" surface). Every one of them assumes the device mutex is already
|
||||
// held: the lock is taken once, in the API layer, so that a compositor call can
|
||||
// never interleave with another half way through a swapchain update.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Includes.h>
|
||||
|
||||
#include <gbm.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace MobileGL::MG_Gbm
|
||||
{
|
||||
// DRM_FORMAT_MOD_LINEAR and DRM_FORMAT_MOD_INVALID. drm_fourcc.h is not part of
|
||||
// libgbm's interface, and these two values are frozen kernel UAPI, so they are
|
||||
// spelled out here rather than made a build dependency on libdrm's headers.
|
||||
static constexpr Uint64 DrmFormatModLinear = 0ULL;
|
||||
static constexpr Uint64 DrmFormatModInvalid = 0x00ffffffffffffffULL;
|
||||
|
||||
// Every buffer this library hands out is described by one of these. HostFrame
|
||||
// buffers are owned by the phone and only borrowed by us, so they must be
|
||||
// released back over the channel instead of being freed locally.
|
||||
enum class GbmBackend
|
||||
{
|
||||
None = 0,
|
||||
HostFrame,
|
||||
DmaHeap,
|
||||
MemFd,
|
||||
};
|
||||
|
||||
// The phone offers frames with this packed struct immediately followed by an
|
||||
// AHardwareBuffer native handle in the payload of one message, with the handle's
|
||||
// descriptors in the SCM_RIGHTS control data of that same message. The layout is
|
||||
// fixed by the phone side, so the packing attribute is load bearing and the field
|
||||
// order may not be rearranged.
|
||||
//
|
||||
// The transport below the two structs is SOCK_SEQPACKET, and that is part of the
|
||||
// protocol rather than an implementation detail: a frame and its descriptors only
|
||||
// mean anything together, and the message boundary is what lets the reader take
|
||||
// the two as one thing. A stream socket would let a reader receive half an offer,
|
||||
// or a descriptor whose position in the byte stream it had to reconstruct, and the
|
||||
// failure mode of getting that arithmetic wrong is a frame silently made of
|
||||
// another frame's memory.
|
||||
//
|
||||
// Format is a DRM fourcc and not an AHardwareBuffer format, because it is what
|
||||
// gbm_bo_get_format has to answer with and a compositor compares it against
|
||||
// DRM_FORMAT_* values. StrideBytes is the byte distance between two rows of plane
|
||||
// 0, which is the same single-stride description GBM_BO_IMPORT_FD carries - and
|
||||
// the reason a frame read from this struct is reported as linear.
|
||||
struct GbmFrameOffer
|
||||
{
|
||||
uint32_t Magic; // 'M','G','G','F' little endian on both ends of the wire
|
||||
uint32_t Version;
|
||||
uint32_t Seq;
|
||||
uint32_t Index;
|
||||
uint32_t Width;
|
||||
uint32_t Height;
|
||||
uint32_t StrideBytes;
|
||||
uint32_t Format;
|
||||
uint32_t UsageLo;
|
||||
uint32_t UsageHi;
|
||||
} __attribute__((packed));
|
||||
|
||||
// The container replies with this once it no longer reads the frame, which is
|
||||
// what lets the phone recycle the slot. Without it the display host would run
|
||||
// out of buffers after a handful of frames.
|
||||
struct GbmFrameRelease
|
||||
{
|
||||
uint32_t Magic; // 'M','G','G','R'
|
||||
uint32_t Version;
|
||||
uint32_t Seq;
|
||||
} __attribute__((packed));
|
||||
|
||||
static constexpr uint32_t GbmFrameOfferMagic = 0x4647474Du; // "MGGF"
|
||||
static constexpr uint32_t GbmFrameReleaseMagic = 0x5247474Du; // "MGGR"
|
||||
static constexpr uint32_t GbmHostProtocolVersion = 1;
|
||||
|
||||
// THE REVERSE DIRECTION: this end asking the render server to back one of its textures with a
|
||||
// dma-buf. The compositor's scene reaches the display daemon's buffers through
|
||||
// glEGLImageTargetTexture2DOES, and the server has to be told which texture that dma-buf backs -
|
||||
// over this same socket, because it is the one channel that can carry a descriptor across the
|
||||
// container boundary. Restated here rather than shared with MG_Backend/GbmFrameChannel.h for the
|
||||
// same reason the two frame shapes are: the ends are built into different libraries from
|
||||
// different build configurations (that file is the Android render server and never sees libgbm).
|
||||
// Field for field, packing included; the plane descriptors ride in the SCM_RIGHTS control data of
|
||||
// the same sendmsg, one message per import.
|
||||
struct GbmImportRequest
|
||||
{
|
||||
uint32_t Magic; // 'M','G','G','I'
|
||||
uint32_t Version;
|
||||
uint32_t Target; // the GL texture target the image was bound to (0x8D65 = GL_TEXTURE_EXTERNAL_OES)
|
||||
uint32_t TexName; // THIS side's texture name; the server resolves its twin
|
||||
uint32_t Width;
|
||||
uint32_t Height;
|
||||
uint32_t FourCC;
|
||||
uint32_t PlaneCount;
|
||||
int32_t Stride[4];
|
||||
int32_t Offset[4];
|
||||
uint64_t Modifier[4];
|
||||
uint32_t HasModifier[4];
|
||||
} __attribute__((packed));
|
||||
|
||||
struct GbmImportReply
|
||||
{
|
||||
uint32_t Magic; // 'I','G','G','R'
|
||||
uint32_t Version;
|
||||
uint32_t Ok;
|
||||
uint32_t Reserved;
|
||||
} __attribute__((packed));
|
||||
|
||||
static constexpr uint32_t GbmImportRequestMagic = 0x4947474Du; // "MGGI"
|
||||
static constexpr uint32_t GbmImportReplyMagic = 0x52474749u; // "IGGR"
|
||||
static constexpr uint32_t GbmImportMaxPlanes = 4;
|
||||
|
||||
// An AHardwareBuffer native handle as it appears on the wire: three counts
|
||||
// followed by numFds file descriptors and numInts integers. The counts are
|
||||
// 32 bit even on 64 bit Android, which is why they are spelled out here
|
||||
// rather than using the platform's native_handle_t.
|
||||
struct AHBNativeHandleHeader
|
||||
{
|
||||
int32_t Version;
|
||||
int32_t NumFds;
|
||||
int32_t NumInts;
|
||||
} __attribute__((packed));
|
||||
|
||||
static constexpr uint32_t GbmMaxPlanes = 4;
|
||||
|
||||
// How one plane of a buffer is laid out inside the single allocation that backs
|
||||
// it. Multi-plane formats keep every plane in one dma-buf and describe the
|
||||
// separation with Offsets, which is the layout a modifier of
|
||||
// DRM_FORMAT_MOD_LINEAR can express and the only one this library produces.
|
||||
struct GbmPlaneLayout
|
||||
{
|
||||
Uint32 Stride = 0;
|
||||
Uint32 Offset = 0;
|
||||
SizeT Size = 0;
|
||||
};
|
||||
|
||||
// One frame the phone offered, as this process holds it: the offer's own
|
||||
// description of the memory, plus the descriptor this library duped out of the
|
||||
// handle the phone sent. It owns that descriptor for as long as it lives, so a
|
||||
// caller that takes a frame and then fails still closes it, and the descriptor the
|
||||
// phone sent is closed with the rest of the message's descriptors rather than kept.
|
||||
struct GbmHostFrame
|
||||
{
|
||||
Uint32 Seq = 0;
|
||||
Uint32 Index = 0;
|
||||
Uint32 Width = 0;
|
||||
Uint32 Height = 0;
|
||||
Uint32 StrideBytes = 0;
|
||||
Uint32 Format = 0;
|
||||
// Bytes per pixel of plane 0. The offer carries a fourcc, so it comes from the
|
||||
// format table when there is an entry for it and from the stride otherwise.
|
||||
Uint32 BytesPerPixel = 0;
|
||||
Uint64 Usage = 0;
|
||||
// Which connection offered the frame. A release names a frame, and a frame only
|
||||
// means anything to the connection that offered it.
|
||||
Uint64 Generation = 0;
|
||||
// The duped dma-buf descriptor, and how many bytes it actually backs as asked
|
||||
// of the descriptor itself rather than computed from the offered geometry.
|
||||
Int Fd = -1;
|
||||
SizeT Size = 0;
|
||||
|
||||
// Move-only, because two records naming one descriptor would close it twice.
|
||||
GbmHostFrame() = default;
|
||||
GbmHostFrame(const GbmHostFrame&) = delete;
|
||||
GbmHostFrame& operator=(const GbmHostFrame&) = delete;
|
||||
GbmHostFrame(GbmHostFrame&& other) noexcept;
|
||||
GbmHostFrame& operator=(GbmHostFrame&& other) noexcept;
|
||||
~GbmHostFrame();
|
||||
};
|
||||
|
||||
// One imported or locally allocated buffer. The struct is private to this
|
||||
// library; gbm_bo is the public opaque name and is defined in terms of it.
|
||||
struct GbmBufferObject
|
||||
{
|
||||
Uint32 Width = 0;
|
||||
Uint32 Height = 0;
|
||||
Uint32 Format = 0;
|
||||
Uint32 Stride = 0;
|
||||
Uint64 Modifier = DrmFormatModLinear;
|
||||
Uint64 Usage = 0;
|
||||
Int PlaneCount = 1;
|
||||
// Bytes per pixel of plane 0. Kept beside the layout because gbm_bo_map
|
||||
// needs it to place a sub-rectangle, and because a format this library can
|
||||
// allocate but cannot describe in bytes would be a format it must refuse.
|
||||
Uint32 BytesPerPixel = 0;
|
||||
|
||||
// Fds owned by this record. get_fd and get_fd_for_plane hand out dups so
|
||||
// that a caller closing its fd can never invalidate the buffer. Index 0 is
|
||||
// the only one a self-allocated buffer has: every plane of a linear image
|
||||
// lives in that one dma-buf, and Fds[1..] stay -1 for it. An import with
|
||||
// several descriptors fills several entries, and the destructor closes
|
||||
// every entry that is not -1.
|
||||
Int Fds[GbmMaxPlanes] = {-1, -1, -1, -1};
|
||||
Uint32 Strides[GbmMaxPlanes] = {0, 0, 0, 0};
|
||||
Uint32 Offsets[GbmMaxPlanes] = {0, 0, 0, 0};
|
||||
Uint64 Modifiers[GbmMaxPlanes] = {0, 0, 0, 0};
|
||||
|
||||
// The number of bytes the descriptors actually back, rounded up to the page
|
||||
// size because that is what both backends allocate. It is the only length
|
||||
// that is safe to mmap: a mapping longer than the object faults on the last
|
||||
// page, and a shorter one would hide the caller's own stride arithmetic.
|
||||
SizeT AllocationSize = 0;
|
||||
|
||||
GbmBackend Backend = GbmBackend::None;
|
||||
|
||||
// Set only for host frames: the slot index and sequence number that the
|
||||
// release message has to mention so the phone can recycle the right slot, and
|
||||
// the connection the frame arrived on. A frame left over from a connection
|
||||
// that has since died is never released into the one that replaced it, because
|
||||
// that would free a slot belonging to another session.
|
||||
Uint32 HostIndex = 0;
|
||||
Uint32 HostSeq = 0;
|
||||
Uint64 HostGeneration = 0;
|
||||
Bool HostOwned = false;
|
||||
|
||||
// How many maps are outstanding. The mapping itself is kept here so that
|
||||
// unmap can find and tear down the right one.
|
||||
Int MapRefCount = 0;
|
||||
void* MapAddress = nullptr;
|
||||
SizeT MapSize = 0;
|
||||
|
||||
// Surfaces keep their buffers alive by count rather than by ownership, so
|
||||
// the device knows when a bo is truly unreferenced.
|
||||
Int RefCount = 1;
|
||||
|
||||
// gbm_bo_set_user_data's pair. The destroy callback is invoked with the
|
||||
// gbm_bo that is going away, once, from the destructor below.
|
||||
void* UserData = nullptr;
|
||||
void (*UserDataDestroy)(::gbm_bo*, void*) = nullptr;
|
||||
|
||||
::gbm_device* Owner = nullptr;
|
||||
|
||||
// The record releases its own descriptors and its own mapping, so that no
|
||||
// failure path anywhere in this library can leak either one - an allocation
|
||||
// that fails half way through construction still cleans up when the record
|
||||
// it was building is destroyed.
|
||||
~GbmBufferObject();
|
||||
};
|
||||
|
||||
// A real swapchain. The compositor asks for a buffer to render into, presents
|
||||
// it, and later returns it; the three states below are exactly the states the
|
||||
// GBM API can express.
|
||||
struct GbmSurface
|
||||
{
|
||||
Uint32 Width = 0;
|
||||
Uint32 Height = 0;
|
||||
Uint32 Format = 0;
|
||||
Uint32 Flags = 0;
|
||||
|
||||
std::vector<::gbm_bo*> Buffers;
|
||||
// Index of the buffer currently handed to the compositor as the front
|
||||
// buffer, or -1 when nothing has been locked.
|
||||
Int LockedIndex = -1;
|
||||
// Indices of buffers the compositor has released and that may be handed
|
||||
// out again, plus the one that is locked.
|
||||
std::vector<Bool> Free;
|
||||
|
||||
::gbm_device* Owner = nullptr;
|
||||
|
||||
// Dropping the surface's references here is what keeps the creation path
|
||||
// free of a second failure path: if the third swapchain buffer cannot be
|
||||
// allocated, unwinding the half-built surface returns the two that exist.
|
||||
~GbmSurface();
|
||||
};
|
||||
|
||||
// The device ties one backend choice, one host channel and one mutex together.
|
||||
// The single mutex is deliberate: GBM calls arrive from the compositor's
|
||||
// render thread and from its main thread, and the state they touch (the bo
|
||||
// table, the backends) is small enough that one lock is cheaper than several.
|
||||
struct GbmDevice
|
||||
{
|
||||
// The fd this device was created with. It is a private dup taken at
|
||||
// creation, never the caller's descriptor, so gbm_device_destroy can close
|
||||
// it without ever closing an fd the caller still has open. -1 when the
|
||||
// caller passed none and no render node could be opened: the self-allocated
|
||||
// backend does not need a DRM node, so that is a working device and not an
|
||||
// error.
|
||||
Int DeviceFd = -1;
|
||||
// The dma-heap node this device allocates from, or -1 when none could be
|
||||
// opened, in which case every allocation falls back to a memfd.
|
||||
Int HeapFd = -1;
|
||||
String HeapPath;
|
||||
|
||||
// Where the display host is reached, as configured when the device was created.
|
||||
String SocketPath;
|
||||
GbmBackend DefaultBackend = GbmBackend::DmaHeap;
|
||||
// True while the channel below is connected and frames are arriving over it.
|
||||
// False means every allocation this device answers is answered locally.
|
||||
Bool HostAvailable = false;
|
||||
// The name gbm_device_get_backend_name reports. It names what this device
|
||||
// actually does, because a compositor that logs it is asking exactly that - so
|
||||
// it changes when the host channel connects and when that connection dies, and
|
||||
// SelfAllocatedBackendName is what it falls back to when it does.
|
||||
String BackendName = "mobilegl";
|
||||
String SelfAllocatedBackendName = "mobilegl";
|
||||
|
||||
std::mutex Mutex;
|
||||
std::unordered_map<::gbm_bo*, GbmBufferObject*> Buffers;
|
||||
std::unordered_map<::gbm_surface*, GbmSurface*> Surfaces;
|
||||
|
||||
// The host channel is a separate translation unit so that the socket protocol
|
||||
// never leaks into the allocation paths. It lives for as long as the device
|
||||
// does and is reached only under this device's mutex, which is what lets the
|
||||
// allocation path ask it for a frame without a second lock to order against.
|
||||
class GbmHostChannel* Host = nullptr;
|
||||
|
||||
// Closes the heap node and the private device dup, so that a device which
|
||||
// fails to finish constructing still releases the descriptors it opened.
|
||||
~GbmDevice();
|
||||
};
|
||||
|
||||
// ---- format description ------------------------------------------------
|
||||
|
||||
// Fills planes[]/planeCount/totalBytes with the linear layout this library
|
||||
// would allocate for format at width x height, and returns false for a format
|
||||
// it cannot lay out. gbm_bo_create refuses a format this refuses, because a
|
||||
// buffer whose plane layout was guessed is worse than a buffer that was not
|
||||
// handed out at all.
|
||||
Bool GbmDescribeFormat(Uint32 format, Uint32 width, Uint32 height, GbmPlaneLayout planes[GbmMaxPlanes],
|
||||
Int& planeCount, SizeT& totalBytes) noexcept;
|
||||
|
||||
// Whether this library can allocate the format at all.
|
||||
Bool GbmFormatIsSupported(Uint32 format) noexcept;
|
||||
|
||||
// Bytes per pixel of plane 0: what gbm_bo_map needs to place a sub-rectangle,
|
||||
// and half of what gbm_bo_get_bpp reports.
|
||||
Uint32 GbmFormatBytesPerPixel(Uint32 format) noexcept;
|
||||
|
||||
// ---- records and the self-allocated backend ----------------------------
|
||||
|
||||
// Builds a device. The only helper here that is called without the mutex,
|
||||
// because no other thread can see the device it is building.
|
||||
::gbm_device* GbmDeviceCreate(Int fd) noexcept;
|
||||
|
||||
// Tears the device down: every remaining surface, every remaining buffer, the
|
||||
// heap node, the private device fd, and the record itself.
|
||||
void GbmDeviceDestroy(::gbm_device& device) noexcept;
|
||||
|
||||
// Allocates a buffer from the device's heap node, or from a memfd when there
|
||||
// is none, and records it in the device's table. Returns null with errno set.
|
||||
::gbm_bo* GbmBufferCreate(::gbm_device& device, Uint32 width, Uint32 height, Uint32 format, Uint64 usage,
|
||||
const Uint64* modifiers, Uint32 modifierCount) noexcept;
|
||||
|
||||
// Wraps descriptors the caller already owns. The descriptors are duped, so the
|
||||
// caller keeps ownership of its own; type is GBM_BO_IMPORT_FD or
|
||||
// GBM_BO_IMPORT_FD_MODIFIER.
|
||||
::gbm_bo* GbmBufferImport(::gbm_device& device, Uint32 type, const void* buffer, Uint64 usage) noexcept;
|
||||
|
||||
// Drops one reference, destroying the buffer when it was the last one.
|
||||
void GbmBufferRelease(::gbm_device& device, ::gbm_bo& bo) noexcept;
|
||||
|
||||
// Destroys a buffer outright, whatever its reference count says. Only the
|
||||
// device's own teardown uses this: by then no caller's reference is meaningful.
|
||||
void GbmBufferForceDestroy(::gbm_device& device, ::gbm_bo& bo) noexcept;
|
||||
|
||||
// Hands out a dup of the descriptor backing a plane, which the caller then owns.
|
||||
// A plane this buffer does not have is refused with errno = EINVAL.
|
||||
Int GbmBufferDupFd(::gbm_bo& bo, Int plane) noexcept;
|
||||
|
||||
// Maps the whole buffer once and counts the call; strideOut receives the
|
||||
// stride of plane 0. The rect (x, y) is applied to the returned address.
|
||||
void* GbmBufferMap(::gbm_bo& bo, Uint32 x, Uint32 y, Uint32& strideOut) noexcept;
|
||||
|
||||
// Drops one mapping; the last one unmaps.
|
||||
void GbmBufferUnmap(::gbm_bo& bo, void* mapData) noexcept;
|
||||
|
||||
// ---- host frames -------------------------------------------------------
|
||||
|
||||
// Builds the channel to the display host and makes one attempt to connect it, then
|
||||
// stores it in the device. A machine that is not the container half of a split run
|
||||
// has nothing at that path, and that is a device which allocates locally from then
|
||||
// on - not a device that failed to be created.
|
||||
void GbmHostChannelCreate(::gbm_device& device) noexcept;
|
||||
|
||||
// Closes the channel and releases what it holds. Called from the device's
|
||||
// destructor, after the buffers that still name offered frames are gone, so that
|
||||
// their releases can still be sent.
|
||||
void GbmHostChannelDestroy(::gbm_device& device) noexcept;
|
||||
|
||||
// Takes the next frame the host offered, or returns false when none is waiting or
|
||||
// the channel is down. Never blocks: the socket is non-blocking, so a caller that
|
||||
// finds nothing allocates locally in the same call, which is what makes this usable
|
||||
// from a compositor's frame loop.
|
||||
Bool GbmHostChannelTakeFrame(::gbm_device& device, GbmHostFrame& frameOut) noexcept;
|
||||
|
||||
// Tells the host that a frame may be recycled. Called from the buffer record's
|
||||
// destructor, so a frame goes back exactly when nothing in this process can still
|
||||
// read it, and only into the connection that offered it.
|
||||
void GbmHostChannelReleaseFrame(::gbm_device& device, Uint32 seq, Uint64 generation) noexcept;
|
||||
|
||||
// ---- swapchains --------------------------------------------------------
|
||||
|
||||
// Builds a surface and its swapchain up front, so that
|
||||
// gbm_surface_has_free_buffers can answer truthfully from the first call.
|
||||
::gbm_surface* GbmSurfaceCreate(::gbm_device& device, Uint32 width, Uint32 height, Uint32 format, Uint64 usage,
|
||||
const Uint64* modifiers, Uint32 modifierCount) noexcept;
|
||||
|
||||
// Unregisters the surface and destroys it, returning the swapchain buffers it
|
||||
// still owns to the device.
|
||||
void GbmSurfaceDestroy(::gbm_surface& surface) noexcept;
|
||||
|
||||
// Hands out the next free swapchain buffer with a reference of its own, or
|
||||
// null with errno = EBUSY when the compositor still holds every one of them.
|
||||
::gbm_bo* GbmSurfaceLockFront(::gbm_surface& surface) noexcept;
|
||||
|
||||
// Takes a locked buffer back, dropping the reference the lock handed out.
|
||||
void GbmSurfaceReleaseBuffer(::gbm_surface& surface, ::gbm_bo& bo) noexcept;
|
||||
|
||||
Bool GbmSurfaceHasFreeBuffers(::gbm_surface& surface) noexcept;
|
||||
} // namespace MobileGL::MG_Gbm
|
||||
|
||||
// The public opaque types are the internal records. Callers only ever see the
|
||||
// pointers, so this costs nothing and removes a layer of casting.
|
||||
struct gbm_device
|
||||
{
|
||||
MobileGL::MG_Gbm::GbmDevice Impl;
|
||||
};
|
||||
|
||||
struct gbm_bo
|
||||
{
|
||||
MobileGL::MG_Gbm::GbmBufferObject Impl;
|
||||
};
|
||||
|
||||
struct gbm_surface
|
||||
{
|
||||
MobileGL::MG_Gbm::GbmSurface Impl;
|
||||
};
|
||||
|
||||
// End of Source File Header
|
||||
@@ -7,51 +7,14 @@
|
||||
// End of Source File Header
|
||||
|
||||
#include "EGLImpl.h"
|
||||
#include "EGLPlatformExtensions.h"
|
||||
#include "WaylandWindow.h"
|
||||
#include "../GetProcAddress.h"
|
||||
#include <Init.h>
|
||||
#include <MG_Backend/BackendObjects.h>
|
||||
#include <MG_State/EGLState/Core.h>
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// MG_Config::ServerOwnedWindowSurfaces (P12, MOBILEGL_IPC_SURFACE). Split-only: the pull build's
|
||||
// translation unit is unchanged (G1).
|
||||
#include <Config.h>
|
||||
#endif
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
#include <type_traits>
|
||||
|
||||
// The KHR spellings of the image entry points, exported by Exporting/Definitions.cpp. Declared
|
||||
// here because the bundled EGL headers declare them only under EGL_EGLEXT_PROTOTYPES, which no
|
||||
// build of this library defines, and because eglGetProcAddress below answers them by name.
|
||||
extern "C" EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer,
|
||||
const EGLint* attrib_list);
|
||||
extern "C" EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image);
|
||||
|
||||
// The swap-and-sync family the compositor resolves by name while bringing its EGL backend up; defined
|
||||
// in Exporting/Definitions.cpp and answered from GetProcAddress below (see the definitions).
|
||||
extern "C" EGLBoolean eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface surface, const EGLint* rects,
|
||||
EGLint n_rects);
|
||||
extern "C" EGLBoolean eglSwapBuffersWithDamageEXT(EGLDisplay dpy, EGLSurface surface, const EGLint* rects,
|
||||
EGLint n_rects);
|
||||
extern "C" EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint* attrib_list);
|
||||
extern "C" EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync);
|
||||
extern "C" EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout);
|
||||
extern "C" EGLBoolean eglWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags);
|
||||
extern "C" EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint* value);
|
||||
// THE DEVICE-QUERY FAMILY, exported by Exporting/Definitions.cpp and answered by name below: kwin
|
||||
// reaches eglQueryDisplayAttribEXT through libepoxy's pointer (that is how finding a render device
|
||||
// starts), and libepoxy asks for it by name. See the definitions for why these had to exist.
|
||||
extern "C" EGLBoolean eglQueryDevicesEXT(EGLint max_devices, EGLDeviceEXT* devices, EGLint* num_devices);
|
||||
extern "C" EGLBoolean eglQueryDeviceAttribEXT(EGLDeviceEXT device, EGLint attribute, EGLAttrib* value);
|
||||
extern "C" const char* eglQueryDeviceStringEXT(EGLDeviceEXT device, EGLint name);
|
||||
extern "C" EGLBoolean eglQueryDisplayAttribEXT(EGLDisplay dpy, EGLint attribute, EGLAttrib* value);
|
||||
extern "C" EGLSurface eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy, EGLConfig config, void* native_window,
|
||||
const EGLAttrib* attrib_list);
|
||||
extern "C" EGLSurface eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy, EGLConfig config, void* native_pixmap,
|
||||
const EGLAttrib* attrib_list);
|
||||
|
||||
namespace MobileGL::MG_Impl::EGLImpl {
|
||||
namespace {
|
||||
using EGLStateContext = MG_State::EGLState::EGLContext;
|
||||
@@ -148,73 +111,6 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
return reinterpret_cast<void*>(static_cast<SizeT>(nativeHandle));
|
||||
}
|
||||
}
|
||||
|
||||
#if MOBILEGL_WAYLAND_WINDOWS
|
||||
// Every Wayland window surface's presentation, by surface. Guarded by EGLOperationMutex,
|
||||
// which every entry point that reaches it holds.
|
||||
UnorderedMap<EGLSurface, UniquePtr<Wayland::WindowSurface>>& WaylandSurfaces() {
|
||||
static auto* surfaces = new UnorderedMap<EGLSurface, UniquePtr<Wayland::WindowSurface>>();
|
||||
return *surfaces;
|
||||
}
|
||||
|
||||
// A WINDOW ON A WAYLAND DISPLAY. Whatever MOBILEGL_IPC_SURFACE says, the window is this
|
||||
// application's own wl_surface, so neither the server's window nor the display host's frame
|
||||
// is what it shows: the backend draws into a pbuffer of the window's size, and each swap
|
||||
// reads the frame back and attaches it to the wl_surface (WaylandWindow.h). Answers false
|
||||
// when the display is not a Wayland one; otherwise *out is the surface, or EGL_NO_SURFACE
|
||||
// with the error set.
|
||||
template <typename State>
|
||||
Bool CreateWaylandWindowSurface(State* state, EGLDisplay dpy, EGLConfig config, void* window,
|
||||
Bool platformWindow, EGLSurface* out) {
|
||||
Uint64 nativeDisplay = 0;
|
||||
EGLenum platform = EGL_NONE;
|
||||
if (!state->GetDisplayNative(dpy, &nativeDisplay, &platform) ||
|
||||
!Wayland::IsWaylandDisplay(nativeDisplay, platform)) {
|
||||
return false;
|
||||
}
|
||||
*out = EGL_NO_SURFACE;
|
||||
if (!state->IsDisplayInitialized(dpy)) {
|
||||
state->SetError(EGL_NOT_INITIALIZED);
|
||||
return true;
|
||||
}
|
||||
if (!state->ValidateConfigOnDisplay(dpy, config)) {
|
||||
state->SetError(EGL_BAD_CONFIG);
|
||||
return true;
|
||||
}
|
||||
EGLint width = 0;
|
||||
EGLint height = 0;
|
||||
if (!Wayland::WindowSize(window, &width, &height)) {
|
||||
state->SetError(EGL_BAD_NATIVE_WINDOW);
|
||||
return true;
|
||||
}
|
||||
EGLint alpha = 0;
|
||||
(void)state->GetConfigAttrib(dpy, config, EGL_ALPHA_SIZE, &alpha);
|
||||
auto presentation =
|
||||
Wayland::WindowSurface::Create(reinterpret_cast<void*>(static_cast<uintptr_t>(nativeDisplay)), window,
|
||||
width, height, alpha > 0);
|
||||
if (!presentation) {
|
||||
state->SetError(EGL_BAD_NATIVE_WINDOW);
|
||||
return true;
|
||||
}
|
||||
const EGLSurface surface =
|
||||
platformWindow ? state->CreatePlatformWindowSurface(dpy, config, window, nullptr)
|
||||
: state->CreateWindowSurface(
|
||||
dpy, config, (NativeWindowType)(reinterpret_cast<uintptr_t>(window)), nullptr);
|
||||
if (surface == EGL_NO_SURFACE) return true;
|
||||
(void)state->ResizeSurface(dpy, surface, width, height);
|
||||
auto* backendObject = GetBackendObject(state);
|
||||
if (!backendObject || !backendObject->CreateEGLPbufferSurface(surface, width, height)) {
|
||||
MGLOG_E("eglCreateWindowSurface: the backend refused the %dx%d drawable behind a Wayland window",
|
||||
width, height);
|
||||
state->DestroySurface(dpy, surface);
|
||||
state->SetError(EGL_BAD_ALLOC);
|
||||
return true;
|
||||
}
|
||||
WaylandSurfaces()[surface] = std::move(presentation);
|
||||
*out = surface;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
} // namespace
|
||||
|
||||
EGLSurface CreateWindowSurface(EGLDisplay dpy, EGLConfig config, NativeWindowType window,
|
||||
@@ -223,16 +119,6 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
if (!state) {
|
||||
return EGL_NO_SURFACE;
|
||||
}
|
||||
#if MOBILEGL_WAYLAND_WINDOWS
|
||||
{
|
||||
const std::lock_guard<std::recursive_mutex> operationLock(EGLOperationMutex());
|
||||
EGLSurface waylandSurface = EGL_NO_SURFACE;
|
||||
if (CreateWaylandWindowSurface(state, dpy, config, ToVoidHandle(window), /*platformWindow=*/false,
|
||||
&waylandSurface)) {
|
||||
return waylandSurface;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (!state->IsDisplayInitialized(dpy)) {
|
||||
state->SetError(EGL_NOT_INITIALIZED);
|
||||
return EGL_NO_SURFACE;
|
||||
@@ -241,71 +127,19 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
state->SetError(EGL_BAD_CONFIG);
|
||||
return EGL_NO_SURFACE;
|
||||
}
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P12 (on-screen server window), D1. With MOBILEGL_IPC_SURFACE=server and a remote server,
|
||||
// the window is the SERVER's: a headless client passes none, so NULL is not
|
||||
// EGL_BAD_NATIVE_WINDOW here. Whatever the client passed never reaches the wire - the
|
||||
// remote backend sends WindowKind::ServerOwned with token 0 (BackendObject_Remote).
|
||||
// Either on-screen shape leaves this side without a window of its own: =server asks the
|
||||
// server for its own window, =host draws into the frames the display host offers.
|
||||
const Bool windowlessOnScreen =
|
||||
MG_Config::ServerOwnedWindowSurfaces() || MG_Config::HostFrameWindowSurfaces();
|
||||
if (IsNullNativeHandle(window) && !windowlessOnScreen) {
|
||||
#else
|
||||
if (IsNullNativeHandle(window)) {
|
||||
#endif
|
||||
state->SetError(EGL_BAD_NATIVE_WINDOW);
|
||||
return EGL_NO_SURFACE;
|
||||
}
|
||||
|
||||
Uint32 requestedWidth = static_cast<Uint32>(std::max<EGLint>(GetAttribValue(attrib_list, EGL_WIDTH, 0), 0));
|
||||
Uint32 requestedHeight = static_cast<Uint32>(std::max<EGLint>(GetAttribValue(attrib_list, EGL_HEIGHT, 0), 0));
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED && defined(__ANDROID__)
|
||||
// P12: A GAME'S OWN WINDOW SIZE IS THE SIZE OF THE FRAMES IT RENDERS, and a server-owned
|
||||
// window has to take that size or clip. SDL (Minecraft's Android backend) creates the EGL
|
||||
// window surface with no EGL_WIDTH / EGL_HEIGHT, so the request went out as 0x0 - "use the
|
||||
// server window's own size" - and a landscape 2620x1280 game drawn into a portrait 1280x2620
|
||||
// server window came out clipped to its bottom-left 1280x1280 corner (Espryt and Magma
|
||||
// alike; the same game in a landscape window was right). The native window it handed us
|
||||
// knows the size the game believes it has: ask for THAT, and the server fixes its window
|
||||
// buffer to it and aspect-fits the view (MobileGLDisplayActivity), letterboxed.
|
||||
if (windowlessOnScreen && requestedWidth == 0 && requestedHeight == 0 && !IsNullNativeHandle(window)) {
|
||||
auto* native = reinterpret_cast<ANativeWindow*>(ToVoidHandle(window));
|
||||
const int32_t nativeWidth = ANativeWindow_getWidth(native);
|
||||
const int32_t nativeHeight = ANativeWindow_getHeight(native);
|
||||
if (nativeWidth > 0 && nativeHeight > 0) {
|
||||
requestedWidth = static_cast<Uint32>(nativeWidth);
|
||||
requestedHeight = static_cast<Uint32>(nativeHeight);
|
||||
MGLOG_I("eglCreateWindowSurface: no EGL_WIDTH/EGL_HEIGHT; the on-screen surface is asked for "
|
||||
"the native window's %dx%d", nativeWidth, nativeHeight);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
const MG_Backend::WindowHandle windowHandle = {
|
||||
.Backend = DetectWindowBackend(),
|
||||
.Handle = ToVoidHandle(window),
|
||||
.Width = requestedWidth,
|
||||
.Height = requestedHeight,
|
||||
.Width = static_cast<Uint32>(std::max<EGLint>(GetAttribValue(attrib_list, EGL_WIDTH, 0), 0)),
|
||||
.Height = static_cast<Uint32>(std::max<EGLint>(GetAttribValue(attrib_list, EGL_HEIGHT, 0), 0)),
|
||||
};
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
EGLSurface surface = EGL_NO_SURFACE;
|
||||
if (MG_Config::ServerOwnedWindowSurfaces()) {
|
||||
// The server's own window: it makes one and draws into it.
|
||||
surface = state->CreateServerOwnedWindowSurface(
|
||||
dpy, config, windowHandle.Handle, static_cast<EGLint>(windowHandle.Width),
|
||||
static_cast<EGLint>(windowHandle.Height), /*platformWindow=*/false);
|
||||
} else if (MG_Config::HostFrameWindowSurfaces()) {
|
||||
// The display host's frames, as above: no window of the client's either way.
|
||||
surface = state->CreateHostFrameWindowSurface(
|
||||
dpy, config, windowHandle.Handle, static_cast<EGLint>(windowHandle.Width),
|
||||
static_cast<EGLint>(windowHandle.Height), /*platformWindow=*/false);
|
||||
} else {
|
||||
surface = state->CreateWindowSurface(dpy, config, window, attrib_list);
|
||||
}
|
||||
#else
|
||||
EGLSurface surface = state->CreateWindowSurface(dpy, config, window, attrib_list);
|
||||
#endif
|
||||
if (surface == EGL_NO_SURFACE) {
|
||||
return EGL_NO_SURFACE;
|
||||
}
|
||||
@@ -332,7 +166,6 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
return EGL_FALSE;
|
||||
}
|
||||
if (!state->ValidateSurfaceOnDisplay(dpy, draw)) {
|
||||
MGLOG_E_ONCE("eglSwapBuffers: surface %p is not a surface of display %p (EGL_BAD_SURFACE)", draw, dpy);
|
||||
state->SetError(EGL_BAD_SURFACE);
|
||||
return EGL_FALSE;
|
||||
}
|
||||
@@ -342,11 +175,6 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
MGLOG_E_ONCE("activeBackendObject not initialized!");
|
||||
return EGL_FALSE;
|
||||
}
|
||||
#if MOBILEGL_WAYLAND_WINDOWS
|
||||
// A Wayland window shows what is attached to it: the frame is read back and attached
|
||||
// BEFORE the swap, while it is still the drawable's content.
|
||||
if (auto it = WaylandSurfaces().find(draw); it != WaylandSurfaces().end()) (void)it->second->Present();
|
||||
#endif
|
||||
if (!backendObject->SwapEGLBuffers(dpy, draw)) {
|
||||
MGLOG_E_ONCE("eglSwapBuffers failed on thread=%s dpy=%p draw=%p", CurrentThreadIdString().c_str(), dpy, draw);
|
||||
state->SetError(EGL_BAD_SURFACE);
|
||||
@@ -357,13 +185,7 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
|
||||
EGLBoolean ChooseConfig(EGLDisplay dpy, const EGLint* attrib_list, EGLConfig* configs, EGLint config_size,
|
||||
EGLint* num_config) {
|
||||
// eglChooseConfig can be an application's first EGL call after eglGetPlatformDisplay + eglInitialize,
|
||||
// and for a display built from an EGLDeviceEXT nothing has brought MobileGL up yet: GetState()
|
||||
// then answers NULL and the call lands in EGLContext::ChooseConfig with a null this - measured as
|
||||
// a crash inside that function (pc/lr both resolved to it) with kwin's own "pEGLContext is null.
|
||||
// MG_State may not be initialized." as the only warning, and reported one layer up as
|
||||
// "Could not initialize rendering context".
|
||||
auto* state = GetStateEnsureInitialized();
|
||||
auto* state = GetState();
|
||||
if (!state) {
|
||||
return EGL_FALSE;
|
||||
}
|
||||
@@ -371,26 +193,11 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
}
|
||||
|
||||
EGLContext CreateContext(EGLDisplay dpy, EGLConfig config, EGLContext shareCtx, const EGLint* attrib_list) {
|
||||
// WHICH CONTEXT IS BEING ASKED FOR, and what came back. kwin's OpenGL compositing fails with
|
||||
// "Could not initialize rendering context" while the same path succeeds from a probe against
|
||||
// this same library (probe10: a 3.3 core context on a GBM surface, makeCurrent answered 1),
|
||||
// so the difference has to be in this argument list - and an EGL vendor cannot see it from the
|
||||
// outside. The list is dumped in EGL_NONE-terminated pairs; EGL_NONE is 0x3038, not 0.
|
||||
MGLOG_I("eglCreateContext(dpy=%p, config=%p, share=%p)", dpy, config, shareCtx);
|
||||
if (attrib_list != nullptr) {
|
||||
for (int index = 0; attrib_list[index] != EGL_NONE; index += 2) {
|
||||
MGLOG_I(" attrib 0x%04x = %d", attrib_list[index], attrib_list[index + 1]);
|
||||
}
|
||||
} else {
|
||||
MGLOG_I(" (no attribute list)");
|
||||
}
|
||||
auto* state = GetStateEnsureInitialized();
|
||||
auto* state = GetState();
|
||||
if (!state) {
|
||||
return EGL_NO_CONTEXT;
|
||||
}
|
||||
EGLContext context = state->CreateContext(dpy, config, shareCtx, attrib_list);
|
||||
MGLOG_I("eglCreateContext -> %p", static_cast<void*>(context));
|
||||
return context;
|
||||
return state->CreateContext(dpy, config, shareCtx, attrib_list);
|
||||
}
|
||||
|
||||
EGLBoolean Initialize(EGLDisplay dpy, EGLint* major, EGLint* minor) {
|
||||
@@ -430,13 +237,6 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
return state->ConsumeError();
|
||||
}
|
||||
|
||||
// THE DISPLAY HOST'S FRAME, AS THE COMPOSITOR PRESENTS IT. Set by the surfaceless-bind hook in
|
||||
// MakeCurrent when this client (the compositor) takes the host frame; read by glFlush, which is
|
||||
// that compositor's only frame boundary - it never calls eglSwapBuffers, and without a present
|
||||
// the display host is never told a frame is done, so nothing ever reaches the glass.
|
||||
EGLDisplay g_hostFramePresentDisplay = nullptr;
|
||||
EGLSurface g_hostFramePresentSurface = nullptr;
|
||||
|
||||
EGLBoolean MakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) {
|
||||
const std::lock_guard<std::recursive_mutex> operationLock(EGLOperationMutex());
|
||||
auto* state = GetState();
|
||||
@@ -453,81 +253,6 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
MGLOG_D("eglMakeCurrent begin thread=%s dpy=%p draw=%p read=%p ctx=%p oldDpy=%p oldDraw=%p oldRead=%p oldCtx=%p",
|
||||
threadId.c_str(), dpy, draw, read, ctx, oldDisplay, oldDraw, oldRead, oldContext);
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// THE DISPLAY HOST'S FRAMES, TO A CLIENT THAT ASKS FOR NO SURFACE.
|
||||
//
|
||||
// A compositor on this route never calls eglCreateWindowSurface: it imports the display host's
|
||||
// dma-bufs and draws into them through framebuffers, binding its contexts with EGL_NO_SURFACE.
|
||||
// The host frame bridge, though, is opened by exactly one thing - a surface being CREATED and
|
||||
// activated (ServerLoop's CreateWindowSurface with the host-frame window backend ->
|
||||
// InitHostFrameSurface) - so with no surface ever created the bridge stayed shut, the display
|
||||
// host kept offering frames into a name nobody served ("offer buffer 0: bridge fd=-1"), and no
|
||||
// frame could reach the glass no matter how much was drawn. So: when the session asked for
|
||||
// host-framed surfaces and a real context is being bound with no surface, make it the surface
|
||||
// eglCreatePlatformWindowSurface would have made, once, and bind that. The size is the display
|
||||
// host's own frame size; the client's window value is not on this path at all.
|
||||
// ONLY THE COMPOSITOR TAKES THE HOST FRAME. A desktop is full of processes that bind a
|
||||
// context with no surface - konsole, plasmashell, kactivitymanagerd - and measured with
|
||||
// probe15 as the second client: such a bind from a NON-compositor process made the host-frame
|
||||
// activation fail (makeCurrent=0) and the process aborted. The compositor is marked by its
|
||||
// launcher with MOBILEGL_HOST_FRAME_CLIENT=1; everyone else keeps the plain surfaceless bind,
|
||||
// which is all they ever wanted.
|
||||
if (draw == EGL_NO_SURFACE && read == EGL_NO_SURFACE && ctx != EGL_NO_CONTEXT &&
|
||||
MG_Config::HostFrameWindowSurfaces() &&
|
||||
(std::getenv("MOBILEGL_HOST_FRAME_CLIENT") != nullptr &&
|
||||
std::string("1") == std::getenv("MOBILEGL_HOST_FRAME_CLIENT"))) {
|
||||
static Bool hostFrameSurfaceTaken = false;
|
||||
if (!hostFrameSurfaceTaken) {
|
||||
hostFrameSurfaceTaken = true;
|
||||
EGLConfig hostFrameConfig = nullptr;
|
||||
EGLint hostFrameConfigCount = 0;
|
||||
const EGLint hostFrameChoose[] = {EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE};
|
||||
if (state->ChooseConfig(dpy, hostFrameChoose, &hostFrameConfig, 1,
|
||||
&hostFrameConfigCount) &&
|
||||
hostFrameConfigCount > 0 && hostFrameConfig != nullptr) {
|
||||
// BOTH HALVES, exactly as eglCreateWindowSurface makes one: the EGL state's
|
||||
// registration (without it every later bind and swap of this surface was refused
|
||||
// as EGL_BAD_SURFACE - measured: "eglMakeCurrent rejected by EGLState
|
||||
// error=0x300d", and glFlush's swaps returned before reaching the backend), then
|
||||
// the backend's own window-surface entry, which the remote backend routes to the
|
||||
// host frame (BackendObject_Remote::CreateHostFrameWindowSurface) - the call that
|
||||
// puts a CreateWindowSurface frame with the host-frame window backend on the wire.
|
||||
const EGLSurface hostFrameSurface = state->CreateHostFrameWindowSurface(
|
||||
dpy, hostFrameConfig, nullptr, 1440, 3200, /*platformWindow=*/false);
|
||||
MG_Backend::WindowHandle hostFrameHandle{};
|
||||
hostFrameHandle.Width = 1440;
|
||||
hostFrameHandle.Height = 3200;
|
||||
if (hostFrameSurface == EGL_NO_SURFACE) {
|
||||
MGLOG_E("host frame: the EGL state refused the display host's frame surface");
|
||||
} else if (!MG_Backend::pActiveBackendObject->CreateEGLWindowSurface(hostFrameSurface,
|
||||
hostFrameHandle)) {
|
||||
MGLOG_E("host frame: the backend refused the display host's frame surface");
|
||||
state->DestroySurface(dpy, hostFrameSurface);
|
||||
} else {
|
||||
// The frame boundary of a compositor that never swaps is its glFlush. glFlush
|
||||
// has no EGL context of its own, so remember HERE which surface presents the
|
||||
// display host's frame; glFlush presents it (see the host-frame present in
|
||||
// glFlush's implementation).
|
||||
g_hostFramePresentDisplay = dpy;
|
||||
g_hostFramePresentSurface = hostFrameSurface;
|
||||
MGLOG_I("host frame: the first surfaceless eglMakeCurrent made the display host's "
|
||||
"frame surface %p (%dx%d)",
|
||||
hostFrameSurface, 1440, 3200);
|
||||
}
|
||||
} else {
|
||||
MGLOG_E("host frame: no config for the display host's frame surface");
|
||||
}
|
||||
}
|
||||
// EVERY surfaceless bind, not only the first: the compositor rebinds with EGL_NO_SURFACE
|
||||
// all the time, and a bind without the surface leaves nothing current for glFlush's swap
|
||||
// to present (BackendObject::SwapEGLBuffers: "draw surface is not current on this thread").
|
||||
if (g_hostFramePresentSurface != nullptr && dpy == g_hostFramePresentDisplay) {
|
||||
draw = g_hostFramePresentSurface;
|
||||
read = g_hostFramePresentSurface;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!state->MakeCurrent(dpy, draw, read, ctx)) {
|
||||
const EGLint error = state->ConsumeError();
|
||||
MGLOG_D("eglMakeCurrent rejected by EGLState thread=%s error=0x%04x", threadId.c_str(), error);
|
||||
@@ -585,9 +310,6 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
if (!state->DestroySurface(dpy, surface)) {
|
||||
return EGL_FALSE;
|
||||
}
|
||||
#if MOBILEGL_WAYLAND_WINDOWS
|
||||
WaylandSurfaces().erase(surface);
|
||||
#endif
|
||||
if (auto* backendObject = MG_Backend::pActiveBackendObject.get()) {
|
||||
backendObject->ReleaseEGLSurface(surface);
|
||||
}
|
||||
@@ -696,10 +418,14 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
case EGL_CLIENT_APIS:
|
||||
return "OpenGL OpenGL_ES";
|
||||
case EGL_EXTENSIONS:
|
||||
// One list, in EGLPlatformExtensions.h, because the vendor string glvnd reads and
|
||||
// this query an application reads have to agree: an application that does not see the
|
||||
// platform extension here never asks for a platform display at all.
|
||||
return display == EGL_NO_DISPLAY ? kClientExtensionString : kDisplayExtensionString;
|
||||
if (display == EGL_NO_DISPLAY) {
|
||||
return "EGL_EXT_client_extensions "
|
||||
"EGL_EXT_platform_base "
|
||||
"EGL_KHR_platform_base "
|
||||
"EGL_MESA_platform_surfaceless";
|
||||
}
|
||||
return "EGL_KHR_create_context "
|
||||
"EGL_MESA_platform_surfaceless";
|
||||
default:
|
||||
state->SetError(EGL_BAD_PARAMETER);
|
||||
return nullptr;
|
||||
@@ -934,23 +660,6 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
return state->DestroyImage(dpy, image) ? EGL_TRUE : EGL_FALSE;
|
||||
}
|
||||
|
||||
EGLImageKHR CreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer,
|
||||
const EGLint* attrib_list) {
|
||||
// EGL_KHR_image_base spells its attribute list in EGLint pairs and the core eglCreateImage
|
||||
// in EGLAttrib pairs, and the two are not the same memory: on a 64-bit build one entry is
|
||||
// twice the width of the other, so the caller's array cannot be handed over as it stands.
|
||||
// Re-spelling it is therefore part of the entry point rather than a detail of the state.
|
||||
Vector<EGLAttrib> attribs;
|
||||
if (attrib_list != nullptr) {
|
||||
for (SizeT i = 0; attrib_list[i] != EGL_NONE; i += 2) {
|
||||
attribs.push_back(static_cast<EGLAttrib>(attrib_list[i]));
|
||||
attribs.push_back(static_cast<EGLAttrib>(attrib_list[i + 1]));
|
||||
}
|
||||
attribs.push_back(static_cast<EGLAttrib>(EGL_NONE));
|
||||
}
|
||||
return CreateImage(dpy, ctx, target, buffer, attribs.empty() ? nullptr : attribs.data());
|
||||
}
|
||||
|
||||
EGLDisplay GetPlatformDisplay(EGLenum platform, void* native_display, const EGLAttrib* attrib_list) {
|
||||
(void)attrib_list;
|
||||
|
||||
@@ -967,27 +676,7 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
if (!state) {
|
||||
return EGL_NO_SURFACE;
|
||||
}
|
||||
#if MOBILEGL_WAYLAND_WINDOWS
|
||||
{
|
||||
const std::lock_guard<std::recursive_mutex> operationLock(EGLOperationMutex());
|
||||
EGLSurface waylandSurface = EGL_NO_SURFACE;
|
||||
if (CreateWaylandWindowSurface(state, dpy, config, native_window, /*platformWindow=*/true,
|
||||
&waylandSurface)) {
|
||||
return waylandSurface;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P12 (on-screen server window), D1: as CreateWindowSurface - with MOBILEGL_IPC_SURFACE=server
|
||||
// the window is the server's, and a headless client's NULL is accepted.
|
||||
// Either on-screen shape leaves this side without a window of its own: =server asks the
|
||||
// server for its own window, =host draws into the frames the display host offers.
|
||||
const Bool windowlessOnScreen =
|
||||
MG_Config::ServerOwnedWindowSurfaces() || MG_Config::HostFrameWindowSurfaces();
|
||||
if (native_window == nullptr && !windowlessOnScreen) {
|
||||
#else
|
||||
if (native_window == nullptr) {
|
||||
#endif
|
||||
state->SetError(EGL_BAD_NATIVE_WINDOW);
|
||||
return EGL_NO_SURFACE;
|
||||
}
|
||||
@@ -1007,25 +696,7 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
.Height = static_cast<Uint32>(std::max<EGLint>(GetAttribValueAttrib(attrib_list, EGL_HEIGHT, 0), 0)),
|
||||
};
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
EGLSurface surface = EGL_NO_SURFACE;
|
||||
if (MG_Config::ServerOwnedWindowSurfaces()) {
|
||||
// The server's own window: it makes one and draws into it.
|
||||
surface = state->CreateServerOwnedWindowSurface(
|
||||
dpy, config, native_window, static_cast<EGLint>(windowHandle.Width),
|
||||
static_cast<EGLint>(windowHandle.Height), /*platformWindow=*/true);
|
||||
} else if (MG_Config::HostFrameWindowSurfaces()) {
|
||||
// The display host's frames: it allocates them, the server draws into them,
|
||||
// and the host puts each one on the glass when the server says it is drawn.
|
||||
surface = state->CreateHostFrameWindowSurface(
|
||||
dpy, config, native_window, static_cast<EGLint>(windowHandle.Width),
|
||||
static_cast<EGLint>(windowHandle.Height), /*platformWindow=*/true);
|
||||
} else {
|
||||
surface = state->CreatePlatformWindowSurface(dpy, config, native_window, attrib_list);
|
||||
}
|
||||
#else
|
||||
EGLSurface surface = state->CreatePlatformWindowSurface(dpy, config, native_window, attrib_list);
|
||||
#endif
|
||||
if (surface == EGL_NO_SURFACE) {
|
||||
return EGL_NO_SURFACE;
|
||||
}
|
||||
@@ -1091,72 +762,6 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
MobileGL::EnsureInitialized();
|
||||
|
||||
MGLOG_D("eglGetProcAddress(%s)", name);
|
||||
|
||||
// THE KHR SPELLINGS ARE ENTRY POINTS OF THEIR OWN, and by name is the only way anything
|
||||
// asks for them. Measured in the Fedora container that runs this library as the glvnd EGL
|
||||
// vendor, before they were answered here: eglGetProcAddress("eglCreateImageKHR") -> NULL and
|
||||
// eglGetProcAddress("eglDestroyImageKHR") -> NULL. kwin_wayland's anland backend imports
|
||||
// the display daemon's dma-bufs through exactly these two (AnlandEglLayer::importBuffers ->
|
||||
// EglBackend::importDmaBufAsTexture -> EglDisplay::importBufferAsImage ->
|
||||
// EglDisplay::createImage, which calls the pointer without a null check), so a NULL here is
|
||||
// a compositor that cannot draw a single pixel into the frames the daemon hands it. The
|
||||
// core spellings were already in the table below; these are the same functions under the
|
||||
// names EGL_KHR_image_base gives them, which is also why they answer in the glvnd vendor
|
||||
// table beside them (Exporting/GlvndVendor.cpp).
|
||||
if (std::strcmp(name, "eglCreateImageKHR") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglCreateImageKHR);
|
||||
}
|
||||
if (std::strcmp(name, "eglDestroyImageKHR") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglDestroyImageKHR);
|
||||
}
|
||||
// The device-query family and the EXT platform-surface spellings. Measured in the container
|
||||
// before they were answered here: eglGetProcAddress returned NULL for eglQueryDisplayAttribEXT,
|
||||
// eglQueryDevicesEXT, eglQueryDeviceAttribEXT, eglQueryDeviceStringEXT and
|
||||
// eglCreatePlatformWindowSurfaceEXT while the extension strings announced EGL_EXT_device_query -
|
||||
// a NULL libepoxy then called (kwin crashed at pc=0), and withdrawing the announcement instead
|
||||
// left kwin without a render device and its compositing inactive.
|
||||
if (std::strcmp(name, "eglQueryDevicesEXT") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglQueryDevicesEXT);
|
||||
}
|
||||
if (std::strcmp(name, "eglQueryDeviceAttribEXT") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglQueryDeviceAttribEXT);
|
||||
}
|
||||
if (std::strcmp(name, "eglQueryDeviceStringEXT") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglQueryDeviceStringEXT);
|
||||
}
|
||||
if (std::strcmp(name, "eglQueryDisplayAttribEXT") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglQueryDisplayAttribEXT);
|
||||
}
|
||||
if (std::strcmp(name, "eglCreatePlatformWindowSurfaceEXT") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglCreatePlatformWindowSurfaceEXT);
|
||||
}
|
||||
if (std::strcmp(name, "eglCreatePlatformPixmapSurfaceEXT") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglCreatePlatformPixmapSurfaceEXT);
|
||||
}
|
||||
// The swap-and-sync spellings kwin resolves by name while it is still bringing its EGL backend
|
||||
// up (see the definitions: EGL_KHR_fence_sync, the damage variants, EGL_EXT_buffer_age).
|
||||
if (std::strcmp(name, "eglSwapBuffersWithDamageKHR") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglSwapBuffersWithDamageKHR);
|
||||
}
|
||||
if (std::strcmp(name, "eglSwapBuffersWithDamageEXT") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglSwapBuffersWithDamageEXT);
|
||||
}
|
||||
if (std::strcmp(name, "eglCreateSyncKHR") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglCreateSyncKHR);
|
||||
}
|
||||
if (std::strcmp(name, "eglDestroySyncKHR") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglDestroySyncKHR);
|
||||
}
|
||||
if (std::strcmp(name, "eglClientWaitSyncKHR") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglClientWaitSyncKHR);
|
||||
}
|
||||
if (std::strcmp(name, "eglWaitSyncKHR") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglWaitSyncKHR);
|
||||
}
|
||||
if (std::strcmp(name, "eglGetSyncAttribKHR") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglGetSyncAttribKHR);
|
||||
}
|
||||
|
||||
void* proc = MG_Impl::GetProcAddress(name);
|
||||
if (!proc) {
|
||||
MGLOG_D("Failed to get function: %s", name);
|
||||
|
||||
@@ -8,18 +8,8 @@
|
||||
|
||||
#pragma once
|
||||
#include <Includes.h>
|
||||
// EGLImageKHR: the return type of the KHR spelling of eglCreateImage below. Includes.h brings in
|
||||
// the core egl.h, which has no KHR types in it.
|
||||
#include <EGL/eglext.h>
|
||||
|
||||
namespace MobileGL::MG_Impl::EGLImpl {
|
||||
// The display host's frame surface, as taken by the surfaceless-bind hook in MakeCurrent, and the
|
||||
// display it belongs to. glFlush reads these: a compositor's frame boundary is glFlush, and the
|
||||
// host frame's "frame is done" signal IS a swap of this surface. Null until a client marked
|
||||
// MOBILEGL_HOST_FRAME_CLIENT=1 actually took the frame.
|
||||
extern EGLDisplay g_hostFramePresentDisplay;
|
||||
extern EGLSurface g_hostFramePresentSurface;
|
||||
|
||||
EGLSurface CreateWindowSurface(EGLDisplay dpy, EGLConfig config, NativeWindowType window,
|
||||
const EGLint* attrib_list);
|
||||
EGLBoolean SwapBuffers(EGLDisplay dpy, EGLSurface draw);
|
||||
@@ -63,10 +53,6 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
EGLBoolean GetSyncAttrib(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib* value);
|
||||
EGLImage CreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer,
|
||||
const EGLAttrib* attrib_list);
|
||||
// The same image under EGL_KHR_image_base's name and its EGLint attribute list: the two lists
|
||||
// are pairs of different widths, so the caller's array is re-spelled rather than cast.
|
||||
EGLImageKHR CreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer,
|
||||
const EGLint* attrib_list);
|
||||
EGLBoolean DestroyImage(EGLDisplay dpy, EGLImage image);
|
||||
EGLDisplay GetPlatformDisplay(EGLenum platform, void* native_display, const EGLAttrib* attrib_list);
|
||||
EGLSurface CreatePlatformWindowSurface(EGLDisplay dpy, EGLConfig config, void* native_window,
|
||||
|
||||
@@ -1,158 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Impl/EGLImpl/EGLPlatformExtensions.h
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace MobileGL::MG_Impl::EGLImpl {
|
||||
// THE PLATFORMS THIS IMPLEMENTATION SERVES, in the words EGL spells them.
|
||||
//
|
||||
// Two callers need exactly the same list, and they disagree if it is written twice:
|
||||
// eglQueryString(EGL_EXTENSIONS) is what an application reads BEFORE it decides to call
|
||||
// eglGetPlatformDisplay at all - libepoxy refuses to use eglGetPlatformDisplayEXT unless the
|
||||
// string names EGL_EXT_platform_base - and the glvnd vendor string is what the system's
|
||||
// libEGL reads to decide which vendor library a platform request should be routed to. A
|
||||
// vendor that does not claim the platform is never asked for it, and the caller is told there
|
||||
// is no provider: the library can be loaded, initialized, and still never called.
|
||||
//
|
||||
// GBM is on the list because a compositor asks for its display on the GBM device it owns.
|
||||
// This side treats that device the way it treats every other native display - the frames come
|
||||
// from the display host, not from the device - so the claim is exact rather than optimistic.
|
||||
inline constexpr const char* kDeviceExtensionString =
|
||||
"EGL_EXT_device_base "
|
||||
"EGL_EXT_device_enumeration "
|
||||
"EGL_EXT_device_query "
|
||||
"EGL_EXT_device_drm "
|
||||
"EGL_EXT_device_drm_render_node";
|
||||
|
||||
// EGL_EXT_client_extensions IS ON THE PLATFORM LIST FOR A MEASURED REASON. libglvnd only folds
|
||||
// a vendor client-extension string (the answer to eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS))
|
||||
// into its own no-display answer when the vendor PLATFORM string - the one __egl_Main publishes
|
||||
// for the platform-extensions query - names EGL_EXT_client_extensions. Without it the client
|
||||
// string never reached libepoxy, so libepoxy concluded EGL_EXT_device_query was absent and left
|
||||
// epoxy_eglQueryDisplayAttribEXT as a NULL pointer, while kwin (which reads the display string,
|
||||
// where the extension IS present) called it: measured as signal 11, fault_addr=(nil), pc=0x0,
|
||||
// from KWin::EglDisplay::determineRenderNode() through the GOT slot whose relocation is
|
||||
// R_AARCH64_GLOB_DAT epoxy_eglQueryDisplayAttribEXT.
|
||||
// Wayland where a Wayland client can exist (WaylandWindow.h: window surfaces presented through
|
||||
// wl_shm). Without it glvnd never hands this vendor a Wayland display at all.
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
#define MOBILEGL_PLATFORM_WAYLAND_EXTENSIONS " EGL_KHR_platform_wayland EGL_EXT_platform_wayland"
|
||||
#else
|
||||
#define MOBILEGL_PLATFORM_WAYLAND_EXTENSIONS ""
|
||||
#endif
|
||||
inline constexpr const char* kPlatformExtensionString =
|
||||
"EGL_EXT_client_extensions "
|
||||
"EGL_EXT_platform_base "
|
||||
"EGL_KHR_platform_base "
|
||||
"EGL_KHR_platform_gbm "
|
||||
"EGL_EXT_platform_gbm "
|
||||
"EGL_MESA_platform_gbm "
|
||||
"EGL_EXT_platform_device "
|
||||
"EGL_MESA_platform_surfaceless" MOBILEGL_PLATFORM_WAYLAND_EXTENSIONS;
|
||||
|
||||
// What a display answers for EGL_EXTENSIONS: the extensions this implementation provides that
|
||||
// are not platform ones, then the platform list above.
|
||||
// EGL_KHR_no_config_context and EGL_KHR_surfaceless_context are on the display and client lists
|
||||
// because both are answered by this implementation rather than announced by a driver: a context
|
||||
// is created with EGL_NO_CONFIG_KHR and made current with EGL_NO_SURFACE, which is the pair a
|
||||
// compositor asks for when it renders into framebuffers of its own. Measured on kwin_wayland
|
||||
// against this vendor before they were here: createContext() refused with
|
||||
// "EGL_KHR_no_config_context extension is unsupported" and the session ended at
|
||||
// "no usable DRM render device; cannot bring up OpenGL compositing".
|
||||
//
|
||||
// EGL_KHR_image_base AND EGL_EXT_image_dma_buf_import ARE ONE FEATURE HERE, and they are on the
|
||||
// list for a measured reason rather than a plausible one. In the Fedora container that runs
|
||||
// this library as the glvnd EGL vendor, eglGetProcAddress("eglCreateImageKHR") and
|
||||
// eglGetProcAddress("eglDestroyImageKHR") both returned NULL, and kwin_wayland 6.7.3's anland
|
||||
// backend imports the display daemon's dma-bufs through exactly those two
|
||||
// (AnlandEglLayer::importBuffers -> EglBackend::importDmaBufAsTexture ->
|
||||
// EglDisplay::importBufferAsImage -> EglDisplay::createImage) before it can draw a pixel into a
|
||||
// frame the daemon produced - so with a NULL the whole composited scene has no image to be
|
||||
// drawn into. Both names are backed by entry points that exist: EGL_KHR_image_base by
|
||||
// eglCreateImage/eglDestroyImage and their KHR spellings (Exporting/Definitions.cpp, and the
|
||||
// same names in the glvnd vendor table), EGL_EXT_image_dma_buf_import by EGL_LINUX_DMA_BUF_EXT
|
||||
// images, which carry the caller's EGL_WIDTH, EGL_HEIGHT and EGL_LINUX_DRM_FOURCC_EXT and own a
|
||||
// dup() of every plane's fd, offset and pitch (EGLState/Core.cpp, CreateImage).
|
||||
//
|
||||
// EGL_EXT_image_dma_buf_import_modifiers IS DELIBERATELY NOT NAMED. Its own two entry points -
|
||||
// eglQueryDmaBufFormatsEXT and eglQueryDmaBufModifiersEXT - do not exist in this library, and a
|
||||
// name in this string means the entry points beside it are there. The modifier attributes
|
||||
// (EGL_DMA_BUF_PLANEn_MODIFIER_LO/HI_EXT) are nevertheless ACCEPTED and carried on the image:
|
||||
// a caller does not need the name to send them, and kwin's does not look at any extension
|
||||
// string before it does - EglDisplay::importDmaBufAsImage appends the pair whenever the
|
||||
// buffer's modifier is not DRM_FORMAT_MOD_INVALID.
|
||||
inline constexpr const char* kDisplayExtensionString =
|
||||
"EGL_KHR_create_context "
|
||||
// WHAT THE COMPOSITOR CHECKS BETWEEN ITS CONTEXT AND ITS FIRST SURFACE. EglBackend::init
|
||||
// asks for these three by name right after initRenderingContext() and before createSurfaces();
|
||||
// the entry points behind them are published beside this string (Exporting/Definitions.cpp),
|
||||
// so the announcement and the answers are one thing rather than two.
|
||||
"EGL_KHR_fence_sync "
|
||||
"EGL_KHR_wait_sync "
|
||||
"EGL_KHR_swap_buffers_with_damage "
|
||||
"EGL_EXT_swap_buffers_with_damage "
|
||||
"EGL_EXT_buffer_age "
|
||||
"EGL_KHR_image_base "
|
||||
"EGL_EXT_image_dma_buf_import "
|
||||
"EGL_KHR_no_config_context "
|
||||
"EGL_KHR_surfaceless_context "
|
||||
// ANNOUNCED BECAUSE IT IS NOW ANSWERED: the four names below are published as real entry
|
||||
// points and eglGetProcAddress answers them (see Exporting/Definitions.cpp and
|
||||
// EGLImpl::GetProcAddress). Both earlier states were measured failures: announcing the
|
||||
// extension while the names resolved to NULL made kwin jump to that NULL (signal 11,
|
||||
// pc=0x0, from KWin::EglDisplay::determineRenderNode()), and withdrawing the announcement
|
||||
// left kwin without a render device so its compositing never became active and nothing was
|
||||
// ever painted.
|
||||
"EGL_EXT_device_base "
|
||||
"EGL_EXT_device_enumeration "
|
||||
"EGL_EXT_device_query "
|
||||
"EGL_EXT_device_drm "
|
||||
"EGL_EXT_device_drm_render_node "
|
||||
// KWin::EglDisplay::determineRenderNode() at libkwin.so.6+0x308b9c. A compositor that is
|
||||
// never told the extension exists cannot take that path; announcing it again is the right
|
||||
// move once these four names are really published and resolvable.
|
||||
"EGL_EXT_platform_device "
|
||||
"EGL_EXT_platform_base "
|
||||
"EGL_KHR_platform_base "
|
||||
"EGL_KHR_platform_gbm "
|
||||
"EGL_EXT_platform_gbm "
|
||||
"EGL_MESA_platform_gbm "
|
||||
"EGL_MESA_platform_surfaceless";
|
||||
|
||||
// ... and what EGL_NO_DISPLAY answers: the same, plus the client-extension marker that tells a
|
||||
// caller the no-display query is meaningful here.
|
||||
inline constexpr const char* kClientExtensionString =
|
||||
"EGL_EXT_client_extensions "
|
||||
"EGL_KHR_create_context "
|
||||
"EGL_KHR_image_base "
|
||||
"EGL_EXT_image_dma_buf_import "
|
||||
"EGL_KHR_no_config_context "
|
||||
"EGL_KHR_surfaceless_context "
|
||||
// ANNOUNCED BECAUSE IT IS NOW ANSWERED: the four names below are published as real entry
|
||||
// points and eglGetProcAddress answers them (see Exporting/Definitions.cpp and
|
||||
// EGLImpl::GetProcAddress). Both earlier states were measured failures: announcing the
|
||||
// extension while the names resolved to NULL made kwin jump to that NULL (signal 11,
|
||||
// pc=0x0, from KWin::EglDisplay::determineRenderNode()), and withdrawing the announcement
|
||||
// left kwin without a render device so its compositing never became active and nothing was
|
||||
// ever painted.
|
||||
"EGL_EXT_device_base "
|
||||
"EGL_EXT_device_enumeration "
|
||||
"EGL_EXT_device_query "
|
||||
"EGL_EXT_device_drm "
|
||||
"EGL_EXT_device_drm_render_node "
|
||||
// KWin::EglDisplay::determineRenderNode() at libkwin.so.6+0x308b9c. A compositor that is
|
||||
// never told the extension exists cannot take that path; announcing it again is the right
|
||||
// move once these four names are really published and resolvable.
|
||||
"EGL_EXT_platform_device "
|
||||
"EGL_EXT_platform_base "
|
||||
"EGL_KHR_platform_base "
|
||||
"EGL_KHR_platform_gbm "
|
||||
"EGL_EXT_platform_gbm "
|
||||
"EGL_MESA_platform_gbm "
|
||||
"EGL_MESA_platform_surfaceless";
|
||||
}
|
||||
@@ -7,9 +7,6 @@
|
||||
// End of Source File Header
|
||||
|
||||
#include <Includes.h>
|
||||
// EGLImageKHR, for the KHR spellings of the image entry points defined at the bottom of this file:
|
||||
// Includes.h brings in the core egl.h only.
|
||||
#include <EGL/eglext.h>
|
||||
#include "../EGLImpl.h"
|
||||
|
||||
MOBILEGL_EGL_API EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, NativeWindowType window,
|
||||
@@ -231,25 +228,6 @@ MOBILEGL_EGL_API EGLBoolean eglDestroyImage(EGLDisplay dpy, EGLImage image) {
|
||||
return MobileGL::MG_Impl::EGLImpl::DestroyImage(dpy, image);
|
||||
}
|
||||
|
||||
// EGL_KHR_image_base's spellings of the same two entry points, exported under their own names
|
||||
// because that is the only thing that answers for them: measured in the Fedora container that runs
|
||||
// this library as the glvnd EGL vendor, eglGetProcAddress("eglCreateImageKHR") and
|
||||
// eglGetProcAddress("eglDestroyImageKHR") both returned NULL, and kwin_wayland's anland backend
|
||||
// imports the display daemon's dma-bufs through exactly these two.
|
||||
MOBILEGL_EGL_API EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer,
|
||||
const EGLint* attrib_list) {
|
||||
MGLOG_D("eglCreateImageKHR(dpy=%p, ctx=%p, target=%u, buffer=%p, attrib_list=%p)", dpy, ctx, target, buffer,
|
||||
attrib_list);
|
||||
// Not an alias of eglCreateImage: this list is EGLint pairs and the core one EGLAttrib pairs.
|
||||
return MobileGL::MG_Impl::EGLImpl::CreateImageKHR(dpy, ctx, target, buffer, attrib_list);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image) {
|
||||
MGLOG_D("eglDestroyImageKHR(dpy=%p, image=%p)", dpy, image);
|
||||
// One handle under two spellings: EGLImageKHR and EGLImage are the same pointer.
|
||||
return MobileGL::MG_Impl::EGLImpl::DestroyImage(dpy, image);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLDisplay eglGetPlatformDisplay(EGLenum platform, void* native_display,
|
||||
const EGLAttrib* attrib_list) {
|
||||
MGLOG_D("eglGetPlatformDisplay(platform=%u, native_display=%p, attrib_list=%p)", platform, native_display,
|
||||
@@ -272,138 +250,6 @@ MOBILEGL_EGL_API EGLSurface eglCreatePlatformWindowSurface(EGLDisplay dpy, EGLCo
|
||||
return MobileGL::MG_Impl::EGLImpl::CreatePlatformWindowSurface(dpy, config, native_window, attrib_list);
|
||||
}
|
||||
|
||||
// THE SWAP-AND-SYNC FAMILY, which kwin asks for in EglBackend::init right after the rendering
|
||||
// context is up and BEFORE it creates any surface: EGL_KHR_fence_sync, EGL_KHR_swap_buffers_with_damage
|
||||
// and EGL_EXT_buffer_age are checked there, and a compositing mode whose backend init returns false
|
||||
// is exactly the "Could not fulfill the requested compositing mode in KWIN_COMPOSE: 1" this run
|
||||
// reports. Each of these names is a spelling of something this library already implements (the core
|
||||
// eglSwapBuffers and the state layer's sync objects), so they are published as real exports rather
|
||||
// than promised and not delivered.
|
||||
MOBILEGL_EGL_API EGLBoolean eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface surface, const EGLint* rects,
|
||||
EGLint n_rects) {
|
||||
// The damage rectangles are a hint about what changed; this side swaps the whole surface either
|
||||
// way, so the honest answer is the core swap.
|
||||
(void)rects;
|
||||
(void)n_rects;
|
||||
return MobileGL::MG_Impl::EGLImpl::SwapBuffers(dpy, surface) ? EGL_TRUE : EGL_FALSE;
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglSwapBuffersWithDamageEXT(EGLDisplay dpy, EGLSurface surface, const EGLint* rects,
|
||||
EGLint n_rects) {
|
||||
return eglSwapBuffersWithDamageKHR(dpy, surface, rects, n_rects);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint* attrib_list) {
|
||||
// EGL_KHR_fence_sync's list is EGLint pairs; the state layer takes EGLAttrib pairs.
|
||||
EGLAttrib attributes[16];
|
||||
int count = 0;
|
||||
if (attrib_list != nullptr) {
|
||||
for (int index = 0; attrib_list[index] != EGL_NONE && count + 1 < 16; index += 2) {
|
||||
attributes[count++] = static_cast<EGLAttrib>(attrib_list[index]);
|
||||
attributes[count++] = static_cast<EGLAttrib>(attrib_list[index + 1]);
|
||||
}
|
||||
}
|
||||
attributes[count] = EGL_NONE;
|
||||
return reinterpret_cast<EGLSyncKHR>(MobileGL::MG_Impl::EGLImpl::CreateSync(dpy, type, attributes));
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync) {
|
||||
return MobileGL::MG_Impl::EGLImpl::DestroySync(dpy, reinterpret_cast<EGLSync>(sync)) ? EGL_TRUE : EGL_FALSE;
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout) {
|
||||
return MobileGL::MG_Impl::EGLImpl::ClientWaitSync(dpy, reinterpret_cast<EGLSync>(sync), flags,
|
||||
static_cast<EGLTime>(timeout));
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags) {
|
||||
return MobileGL::MG_Impl::EGLImpl::WaitSync(dpy, reinterpret_cast<EGLSync>(sync), flags) ? EGL_TRUE : EGL_FALSE;
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint* value) {
|
||||
EGLAttrib answered = EGL_NONE;
|
||||
if (!MobileGL::MG_Impl::EGLImpl::GetSyncAttrib(dpy, reinterpret_cast<EGLSync>(sync), attribute, &answered)) {
|
||||
return EGL_FALSE;
|
||||
}
|
||||
if (value != nullptr) {
|
||||
*value = static_cast<EGLint>(answered);
|
||||
}
|
||||
return EGL_TRUE;
|
||||
}
|
||||
|
||||
// THE DEVICE-QUERY FAMILY, PUBLISHED AS REAL ENTRY POINTS. It is not academic: with the extension
|
||||
// announced but these names unresolvable, libepoxy leaves epoxy_eglQueryDisplayAttribEXT NULL and
|
||||
// kwin, trusting the announcement, jumps to it (measured: signal 11, fault_addr=(nil), pc=0x0 from
|
||||
// KWin::EglDisplay::determineRenderNode()); with the announcement withdrawn instead, kwin stops
|
||||
// asking and its compositing never becomes active (measured: org.kde.kwin.Compositing active =
|
||||
// false), so nothing is ever painted and the display daemon frames are never imported. Publishing
|
||||
// them is the only answer that leaves kwin both safe and able to find its render device.
|
||||
namespace {
|
||||
// One device, one identity - the same shape the vendor side uses (Exporting/GlvndVendor.cpp): a
|
||||
// pointer to a private object, so a device from somewhere else cannot compare equal by accident.
|
||||
struct DeviceToken { int unused; };
|
||||
DeviceToken g_deviceToken;
|
||||
} // namespace
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglQueryDevicesEXT(EGLint max_devices, EGLDeviceEXT* devices, EGLint* num_devices) {
|
||||
if (num_devices == nullptr) return EGL_FALSE;
|
||||
*num_devices = 1;
|
||||
if (devices != nullptr && max_devices >= 1) devices[0] = reinterpret_cast<EGLDeviceEXT>(&g_deviceToken);
|
||||
return EGL_TRUE;
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglQueryDeviceAttribEXT(EGLDeviceEXT device, EGLint attribute, EGLAttrib* value) {
|
||||
if (device != reinterpret_cast<EGLDeviceEXT>(&g_deviceToken) || value == nullptr) return EGL_FALSE;
|
||||
switch (attribute) {
|
||||
case EGL_DRM_DEVICE_FILE_EXT:
|
||||
case EGL_DRM_RENDER_NODE_FILE_EXT:
|
||||
*value = reinterpret_cast<EGLAttrib>("/dev/dri/renderD128");
|
||||
return EGL_TRUE;
|
||||
default:
|
||||
return EGL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API const char* eglQueryDeviceStringEXT(EGLDeviceEXT device, EGLint name) {
|
||||
if (device != reinterpret_cast<EGLDeviceEXT>(&g_deviceToken)) return nullptr;
|
||||
// THE NODE IS NAMED, AND THAT CHANGED BECAUSE THE MEASUREMENT CHANGED. An empty answer was the
|
||||
// right shape while this query was unreachable: nothing asked, so nothing depended on it. Now
|
||||
// that the name resolves, it is exactly what kwin asks on the way into its EGL backend, and the
|
||||
// fork says out loud what an empty answer costs it - "Error during init of AnlandEglBackend",
|
||||
// after which it falls back to the plain AnlandBackend, whose compositing never becomes active
|
||||
// (supportInformation: "LogicalOutput backend: KWin::AnlandBackend" + "Compositing is not
|
||||
// active"), so nothing is ever painted and the display daemon frames are never imported. The
|
||||
// path answered is the one the environment configures the compositor with (ANLAND_DRM_DEVICE),
|
||||
// so the node named here and the node in use are the same node.
|
||||
if (name == EGL_DRM_DEVICE_FILE_EXT || name == EGL_DRM_RENDER_NODE_FILE_EXT) {
|
||||
return "/dev/dri/renderD128";
|
||||
}
|
||||
if (name == EGL_EXTENSIONS) return "EGL_EXT_device_drm_render_node";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglQueryDisplayAttribEXT(EGLDisplay dpy, EGLint attribute, EGLAttrib* value) {
|
||||
(void)dpy;
|
||||
if (value == nullptr) return EGL_FALSE;
|
||||
if (attribute == EGL_DEVICE_EXT) {
|
||||
*value = reinterpret_cast<EGLAttrib>(&g_deviceToken);
|
||||
return EGL_TRUE;
|
||||
}
|
||||
return EGL_FALSE;
|
||||
}
|
||||
|
||||
// The EXT spellings of the platform surface entry points: EGL_EXT_platform_base defines them by those
|
||||
// names, and a dispatcher-based client resolves them by those names. Identical ABI (EGLAttrib list).
|
||||
MOBILEGL_EGL_API EGLSurface eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy, EGLConfig config, void* native_window,
|
||||
const EGLAttrib* attrib_list) {
|
||||
return eglCreatePlatformWindowSurface(dpy, config, native_window, attrib_list);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLSurface eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy, EGLConfig config, void* native_pixmap,
|
||||
const EGLAttrib* attrib_list) {
|
||||
return eglCreatePlatformPixmapSurface(dpy, config, native_pixmap, attrib_list);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLSurface eglCreatePlatformPixmapSurface(EGLDisplay dpy, EGLConfig config, void* native_pixmap,
|
||||
const EGLAttrib* attrib_list) {
|
||||
MGLOG_D("eglCreatePlatformPixmapSurface(dpy=%p, config=%p, native_pixmap=%p, attrib_list=%p)", dpy, config,
|
||||
|
||||
@@ -1,395 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Impl/EGLImpl/Exporting/GlvndVendor.cpp
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
// MOBILEGL AS A GLVND EGL VENDOR.
|
||||
//
|
||||
// On a system with libglvnd, the libEGL.so.1 an application links is not an implementation at all:
|
||||
// it is a dispatcher, and the implementations are vendor libraries it loads from
|
||||
// /usr/share/glvnd/egl_vendor.d (or from whatever __EGL_VENDOR_LIBRARY_FILENAMES names) and routes
|
||||
// every EGL call to. That is the supported way to be the implementation an application actually
|
||||
// talks to, and on this machine it is the ONLY way that reaches a caller which does not link EGL
|
||||
// directly: kwin goes through libepoxy, which dlopen()s libEGL.so.1 and dlsyms its entry points at
|
||||
// startup, so a library injected with LD_PRELOAD is invisible to it however loudly it is named.
|
||||
//
|
||||
// What glvnd asks a vendor for is the other half of that ABI, and this file is it: glvnd calls
|
||||
// __egl_Main once, the library answers with the functions it wants dispatched to it, and - the part
|
||||
// that decides whether a compositor can use it at all - with the string naming the PLATFORMS it
|
||||
// serves. A vendor that does not claim EGL_PLATFORM_GBM_KHR is never asked for a GBM display, and
|
||||
// the caller that asked for one is told there is no usable device: the client sitting in its maps,
|
||||
// loaded and never called, is exactly what that looks like from the outside.
|
||||
//
|
||||
// The entry points below are this library's own (MG_Impl::EGLImpl, the same functions
|
||||
// Exporting/Definitions.cpp exports), so a vendor call and a direct call cannot drift apart.
|
||||
|
||||
#include <Includes.h>
|
||||
#include <glvnd/libeglabi.h>
|
||||
// EGLImageKHR, for the KHR spellings the entry-point table below answers: Includes.h brings in the
|
||||
// core egl.h only.
|
||||
#include <EGL/eglext.h>
|
||||
|
||||
#include "../EGLImpl.h"
|
||||
#include "../EGLPlatformExtensions.h"
|
||||
|
||||
// The KHR spellings of the image entry points, declared here because the bundled EGL headers
|
||||
// declare them only under EGL_EGLEXT_PROTOTYPES and because glvnd asks for entry points BY NAME -
|
||||
// the table below is where it finds this one.
|
||||
extern "C" EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer,
|
||||
const EGLint* attrib_list);
|
||||
extern "C" EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image);
|
||||
|
||||
// THE SWAP-AND-SYNC EXPORTS, declared here for the same reason the image pair is: they are defined in
|
||||
// Exporting/Definitions.cpp and this file only names them in the vendor table below.
|
||||
extern "C" EGLBoolean eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface surface, const EGLint* rects,
|
||||
EGLint n_rects);
|
||||
extern "C" EGLBoolean eglSwapBuffersWithDamageEXT(EGLDisplay dpy, EGLSurface surface, const EGLint* rects,
|
||||
EGLint n_rects);
|
||||
extern "C" EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint* attrib_list);
|
||||
extern "C" EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync);
|
||||
extern "C" EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout);
|
||||
extern "C" EGLBoolean eglWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags);
|
||||
extern "C" EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint* value);
|
||||
|
||||
namespace {
|
||||
using namespace MobileGL;
|
||||
|
||||
const __EGLapiExports* g_eglExports = nullptr;
|
||||
|
||||
// The platforms this vendor serves. GBM is the one that matters here: the compositor asks for
|
||||
// a display on the GBM device it opened, and a vendor that does not name the platform is not
|
||||
// asked at all. This side treats a GBM device as it treats every other native display - the
|
||||
// frames come from the display host, not from the device - so claiming the platform is honest
|
||||
// rather than optimistic.
|
||||
constexpr const char* kPlatformExtensions = MG_Impl::EGLImpl::kPlatformExtensionString;
|
||||
|
||||
// glvnd asks for the client-only extension list separately from the platform one; the split is
|
||||
// its own invention, and this side answers both from the same query.
|
||||
const char* EGLAPIENTRY VendorQueryString(EGLDisplay dpy, EGLint name) {
|
||||
return MG_Impl::EGLImpl::QueryString(dpy, name);
|
||||
}
|
||||
|
||||
EGLDisplay EGLAPIENTRY VendorGetPlatformDisplay(EGLenum platform, void* native_display,
|
||||
const EGLAttrib* attrib_list) {
|
||||
// EGL_NONE means the application called eglGetDisplay(EGL_DEFAULT_DISPLAY): the vendor is
|
||||
// being asked to name its own default display.
|
||||
if (platform == EGL_NONE) {
|
||||
return MG_Impl::EGLImpl::GetDisplay(EGL_DEFAULT_DISPLAY);
|
||||
}
|
||||
return MG_Impl::EGLImpl::GetPlatformDisplay(platform, native_display, attrib_list);
|
||||
}
|
||||
|
||||
EGLBoolean EGLAPIENTRY VendorGetSupportsAPI(EGLenum api) {
|
||||
// What this library answers for EGL_CLIENT_APIS, said as a question.
|
||||
return (api == EGL_OPENGL_ES_API || api == EGL_OPENGL_API) ? EGL_TRUE : EGL_FALSE;
|
||||
}
|
||||
|
||||
const char* EGLAPIENTRY VendorGetVendorString(int name) {
|
||||
if (name == __EGL_VENDOR_STRING_PLATFORM_EXTENSIONS) {
|
||||
return kPlatformExtensions;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// GLVND ASKS FOR EVERY EGL ENTRY POINT BY NAME, AND DROPS THE VENDOR IF ONE IS MISSING: the
|
||||
// first eight functions the table below names are looked up before this library is ever asked
|
||||
// for a display, and a single null answer means glvnd quietly stops considering it - the
|
||||
// library is loaded, __egl_Main has run, and nothing is ever dispatched to it.
|
||||
struct EntryPoint {
|
||||
const char* name;
|
||||
void* address;
|
||||
};
|
||||
|
||||
// ---- the device family -------------------------------------------------------------------
|
||||
//
|
||||
// A compositor does not ask for a display and hope. It asks which devices exist, reads the DRM
|
||||
// node off the one it wants, and only then asks for a display ON that device - so a vendor that
|
||||
// answers "no devices" is one it cannot use, however well the vendor draws. The message it
|
||||
// gives is "no usable DRM render device", which names where it stopped rather than why.
|
||||
//
|
||||
// This implementation therefore names one device: the render node of the machine it runs on.
|
||||
// That is an honest answer even though the frames do not come from that node - they come from
|
||||
// the display host on the other end of the socket, which is why every surface here is a host
|
||||
// frame - because the question is which device this display is associated with, and the answer
|
||||
// is what lets the compositor match its own node to the display it is about to draw into.
|
||||
const char* DrmRenderNode() {
|
||||
// MOBILEGL_DEVICE_DRM_NODE names another node: a machine with more than one GPU, or a test
|
||||
// that wants the mismatch refused rather than papered over.
|
||||
const char* configured = std::getenv("MOBILEGL_DEVICE_DRM_NODE");
|
||||
return (configured != nullptr && configured[0] != '\0') ? configured : "/dev/dri/renderD128";
|
||||
}
|
||||
|
||||
// One device, one identity. A pointer to a private object rather than a number, so that a
|
||||
// device from somewhere else cannot compare equal to this one by accident.
|
||||
struct DeviceToken { int unused; };
|
||||
DeviceToken g_deviceToken;
|
||||
|
||||
EGLBoolean EGLAPIENTRY VendorQueryDevicesEXT(EGLint max_devices, EGLDeviceEXT* devices, EGLint* num_devices) {
|
||||
if (num_devices == nullptr) {
|
||||
return EGL_FALSE;
|
||||
}
|
||||
*num_devices = 1;
|
||||
if (devices != nullptr && max_devices >= 1) {
|
||||
devices[0] = reinterpret_cast<EGLDeviceEXT>(&g_deviceToken);
|
||||
}
|
||||
return EGL_TRUE;
|
||||
}
|
||||
|
||||
EGLBoolean EGLAPIENTRY VendorQueryDeviceAttribEXT(EGLDeviceEXT device, EGLint attribute, EGLAttrib* value) {
|
||||
MGLOG_I("vendor eglQueryDeviceAttribEXT(device=%p, attribute=0x%04x)", static_cast<void*>(device),
|
||||
static_cast<unsigned>(attribute));
|
||||
if (device != reinterpret_cast<EGLDeviceEXT>(&g_deviceToken) || value == nullptr) {
|
||||
return EGL_FALSE;
|
||||
}
|
||||
switch (attribute) {
|
||||
case EGL_DRM_DEVICE_FILE_EXT:
|
||||
case EGL_DRM_RENDER_NODE_FILE_EXT:
|
||||
// THE ATTRIBUTE FORM OF THE SAME QUERY, and the last place the empty answer lived. kwin
|
||||
// asks for the node as an ATTRIBUTE as well as a string; with this one empty its log said
|
||||
// "couldn't find dev node for drm device" even after the string form was answered, and
|
||||
// the compositing mode it had just successfully started through this library was then
|
||||
// declared unfulfillable. The path is the environment's own (ANLAND_DRM_DEVICE).
|
||||
*value = reinterpret_cast<EGLAttrib>("/dev/dri/renderD128");
|
||||
return EGL_TRUE;
|
||||
default:
|
||||
return EGL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
const char* EGLAPIENTRY VendorQueryDeviceStringEXT(EGLDeviceEXT device, EGLint name) {
|
||||
// WHICH DEVICE QUERY THE COMPOSITOR MAKES, and by which name: the string form and the attribute
|
||||
// form are different entry points with different answers (glvnd answers the string form itself
|
||||
// and only forwards the attribute one), so the caller decides which of the two it gets.
|
||||
MGLOG_I("vendor eglQueryDeviceStringEXT(device=%p, name=0x%04x)", static_cast<void*>(device),
|
||||
static_cast<unsigned>(name));
|
||||
if (device != reinterpret_cast<EGLDeviceEXT>(&g_deviceToken)) {
|
||||
return nullptr;
|
||||
}
|
||||
// THE NODE IS NAMED HERE TOO, AND THAT IS WHAT THE VENDOR-SIDE ANSWER WAS MISSING. An empty
|
||||
// answer was measured to be harmless only while this query was unreachable; through glvnd it
|
||||
// IS the query a compositor makes before it opens anything, and an empty string is what its
|
||||
// next line reports - "Failed to open drm node : No such file or directory" (the name is the
|
||||
// blank between "node" and ":"), followed by "couldn't find dev node for drm device" and a
|
||||
// dead OpenGL compositing mode. The path is the one the environment configures the
|
||||
// compositor with (ANLAND_DRM_DEVICE), so the node named here and the node in use are one.
|
||||
if (name == EGL_DRM_DEVICE_FILE_EXT || name == EGL_DRM_RENDER_NODE_FILE_EXT) {
|
||||
return "/dev/dri/renderD128";
|
||||
}
|
||||
if (name == EGL_EXTENSIONS) {
|
||||
return "EGL_EXT_device_drm_render_node";
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
EGLBoolean EGLAPIENTRY VendorQueryDisplayAttribEXT(EGLDisplay dpy, EGLint attribute, EGLAttrib* value) {
|
||||
(void)dpy;
|
||||
if (value == nullptr) {
|
||||
return EGL_FALSE;
|
||||
}
|
||||
if (attribute == EGL_DEVICE_EXT) {
|
||||
*value = reinterpret_cast<EGLAttrib>(&g_deviceToken);
|
||||
return EGL_TRUE;
|
||||
}
|
||||
return EGL_FALSE;
|
||||
}
|
||||
|
||||
// Three of the names glvnd insists on are debug extensions this implementation does not
|
||||
// provide, and glvnd insists on them all the same - a vendor that answers null for any of them
|
||||
// is dropped. They are answered honestly rather than pretended: KHR_debug is not in the
|
||||
// extension strings above, so a caller that reads them will not call these at all.
|
||||
EGLint EGLAPIENTRY VendorDebugMessageControlKHR(EGLDEBUGPROCKHR callback, const EGLAttrib* attrib_list) {
|
||||
(void)callback;
|
||||
(void)attrib_list;
|
||||
return EGL_FALSE;
|
||||
}
|
||||
|
||||
EGLBoolean EGLAPIENTRY VendorQueryDebugKHR(EGLint attribute, EGLAttrib* value) {
|
||||
(void)attribute;
|
||||
(void)value;
|
||||
return EGL_FALSE;
|
||||
}
|
||||
|
||||
EGLint EGLAPIENTRY VendorLabelObjectKHR(EGLDisplay dpy, EGLenum objectType, EGLObjectKHR object, EGLLabelKHR label) {
|
||||
(void)dpy;
|
||||
(void)objectType;
|
||||
(void)object;
|
||||
(void)label;
|
||||
return EGL_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
const EntryPoint kEglEntryPoints[] = {
|
||||
// The core of EGL 1.5, every one of which glvnd looks up by name before it considers this
|
||||
// library usable.
|
||||
{"eglInitialize", reinterpret_cast<void*>(eglInitialize)},
|
||||
{"eglChooseConfig", reinterpret_cast<void*>(eglChooseConfig)},
|
||||
{"eglCopyBuffers", reinterpret_cast<void*>(eglCopyBuffers)},
|
||||
{"eglCreateContext", reinterpret_cast<void*>(eglCreateContext)},
|
||||
{"eglCreatePbufferSurface", reinterpret_cast<void*>(eglCreatePbufferSurface)},
|
||||
{"eglCreatePixmapSurface", reinterpret_cast<void*>(eglCreatePixmapSurface)},
|
||||
{"eglCreateWindowSurface", reinterpret_cast<void*>(eglCreateWindowSurface)},
|
||||
{"eglDestroyContext", reinterpret_cast<void*>(eglDestroyContext)},
|
||||
{"eglDestroySurface", reinterpret_cast<void*>(eglDestroySurface)},
|
||||
{"eglGetConfigAttrib", reinterpret_cast<void*>(eglGetConfigAttrib)},
|
||||
{"eglGetConfigs", reinterpret_cast<void*>(eglGetConfigs)},
|
||||
{"eglMakeCurrent", reinterpret_cast<void*>(eglMakeCurrent)},
|
||||
{"eglQueryContext", reinterpret_cast<void*>(eglQueryContext)},
|
||||
{"eglQuerySurface", reinterpret_cast<void*>(eglQuerySurface)},
|
||||
{"eglSwapBuffers", reinterpret_cast<void*>(eglSwapBuffers)},
|
||||
{"eglTerminate", reinterpret_cast<void*>(eglTerminate)},
|
||||
{"eglWaitGL", reinterpret_cast<void*>(eglWaitGL)},
|
||||
{"eglWaitNative", reinterpret_cast<void*>(eglWaitNative)},
|
||||
{"eglBindTexImage", reinterpret_cast<void*>(eglBindTexImage)},
|
||||
{"eglReleaseTexImage", reinterpret_cast<void*>(eglReleaseTexImage)},
|
||||
{"eglSurfaceAttrib", reinterpret_cast<void*>(eglSurfaceAttrib)},
|
||||
{"eglSwapInterval", reinterpret_cast<void*>(eglSwapInterval)},
|
||||
{"eglBindAPI", reinterpret_cast<void*>(eglBindAPI)},
|
||||
{"eglCreatePbufferFromClientBuffer", reinterpret_cast<void*>(eglCreatePbufferFromClientBuffer)},
|
||||
{"eglReleaseThread", reinterpret_cast<void*>(eglReleaseThread)},
|
||||
{"eglWaitClient", reinterpret_cast<void*>(eglWaitClient)},
|
||||
{"eglGetError", reinterpret_cast<void*>(eglGetError)},
|
||||
{"eglCreateSync", reinterpret_cast<void*>(eglCreateSync)},
|
||||
{"eglDestroySync", reinterpret_cast<void*>(eglDestroySync)},
|
||||
{"eglClientWaitSync", reinterpret_cast<void*>(eglClientWaitSync)},
|
||||
{"eglGetSyncAttrib", reinterpret_cast<void*>(eglGetSyncAttrib)},
|
||||
{"eglWaitSync", reinterpret_cast<void*>(eglWaitSync)},
|
||||
{"eglCreateImage", reinterpret_cast<void*>(eglCreateImage)},
|
||||
{"eglDestroyImage", reinterpret_cast<void*>(eglDestroyImage)},
|
||||
// THE KHR SPELLINGS OF THOSE TWO, and they are entries rather than aliases because glvnd
|
||||
// resolves a name it does not know through this table alone. Measured in the Fedora
|
||||
// container that runs this library as the EGL vendor: with only the core pair here,
|
||||
// eglGetProcAddress("eglCreateImageKHR") and eglGetProcAddress("eglDestroyImageKHR") both
|
||||
// answered NULL, and kwin_wayland's anland backend reaches the display daemon's dma-bufs
|
||||
// through them (AnlandEglLayer::importBuffers -> EglBackend::importDmaBufAsTexture ->
|
||||
// EglDisplay::importBufferAsImage) - so the compositor had no entry point to import a frame
|
||||
// with. eglCreateImageKHR is not the same ABI as eglCreateImage: EGL_KHR_image_base's
|
||||
// attribute list is EGLint pairs, which is why Exporting/Definitions.cpp exports it as its
|
||||
// own function rather than letting the core spelling stand in for it.
|
||||
{"eglCreateImageKHR", reinterpret_cast<void*>(eglCreateImageKHR)},
|
||||
{"eglDestroyImageKHR", reinterpret_cast<void*>(eglDestroyImageKHR)},
|
||||
{"eglCreatePlatformWindowSurface", reinterpret_cast<void*>(eglCreatePlatformWindowSurface)},
|
||||
{"eglCreatePlatformPixmapSurface", reinterpret_cast<void*>(eglCreatePlatformPixmapSurface)},
|
||||
// EGL_EXT_platform_base's OWN SPELLINGS, and the reason this file exists at all: the vendor
|
||||
// string below advertises that extension, whose entry points ARE the EXT-named ones, and a
|
||||
// dispatcher-based client resolves them by exactly those names (libepoxy in kwin does). With
|
||||
// only the core spellings in this table the lookup answered NULL and the caller - which had
|
||||
// already checked the extension string and so had every reason to trust it - jumped to it:
|
||||
// measured as signal 11 with fault_addr=(nil) and pc=0x0 immediately after "MobileGL
|
||||
// initialized", in both the systemd and the direct run, and it is what kept the compositor
|
||||
// from ever reaching its output. The ABI is identical (an EGLAttrib list, not EGLint pairs),
|
||||
// so the core implementation is what serves them.
|
||||
{"eglCreatePlatformWindowSurfaceEXT", reinterpret_cast<void*>(eglCreatePlatformWindowSurface)},
|
||||
{"eglCreatePlatformPixmapSurfaceEXT", reinterpret_cast<void*>(eglCreatePlatformPixmapSurface)},
|
||||
// The platform and current-state queries: not in glvnd's required list, but the names an
|
||||
// application that talks to a vendor through a dispatcher will ask for by name.
|
||||
{"eglGetDisplay", reinterpret_cast<void*>(eglGetDisplay)},
|
||||
{"eglGetCurrentDisplay", reinterpret_cast<void*>(eglGetCurrentDisplay)},
|
||||
{"eglGetCurrentSurface", reinterpret_cast<void*>(eglGetCurrentSurface)},
|
||||
{"eglGetCurrentContext", reinterpret_cast<void*>(eglGetCurrentContext)},
|
||||
{"eglQueryAPI", reinterpret_cast<void*>(eglQueryAPI)},
|
||||
{"eglGetProcAddress", reinterpret_cast<void*>(eglGetProcAddress)},
|
||||
// The two queries whose answer depends on which side of glvnd is asking.
|
||||
{"eglQueryString", reinterpret_cast<void*>(VendorQueryString)},
|
||||
{"eglGetPlatformDisplay", reinterpret_cast<void*>(VendorGetPlatformDisplay)},
|
||||
{"eglGetPlatformDisplayEXT", reinterpret_cast<void*>(VendorGetPlatformDisplay)},
|
||||
// What glvnd requires and this implementation does not otherwise have.
|
||||
{"eglQueryDevicesEXT", reinterpret_cast<void*>(VendorQueryDevicesEXT)},
|
||||
{"eglQueryDeviceAttribEXT", reinterpret_cast<void*>(VendorQueryDeviceAttribEXT)},
|
||||
{"eglQueryDeviceStringEXT", reinterpret_cast<void*>(VendorQueryDeviceStringEXT)},
|
||||
{"eglQueryDisplayAttribEXT", reinterpret_cast<void*>(VendorQueryDisplayAttribEXT)},
|
||||
// The swap-and-sync family, published through the same table the names are answered from.
|
||||
// Declared above this table because they are exports of Definitions.cpp, like the image pair.
|
||||
{"eglSwapBuffersWithDamageKHR", reinterpret_cast<void*>(eglSwapBuffersWithDamageKHR)},
|
||||
{"eglSwapBuffersWithDamageEXT", reinterpret_cast<void*>(eglSwapBuffersWithDamageEXT)},
|
||||
{"eglCreateSyncKHR", reinterpret_cast<void*>(eglCreateSyncKHR)},
|
||||
{"eglDestroySyncKHR", reinterpret_cast<void*>(eglDestroySyncKHR)},
|
||||
{"eglClientWaitSyncKHR", reinterpret_cast<void*>(eglClientWaitSyncKHR)},
|
||||
{"eglWaitSyncKHR", reinterpret_cast<void*>(eglWaitSyncKHR)},
|
||||
{"eglGetSyncAttribKHR", reinterpret_cast<void*>(eglGetSyncAttribKHR)},
|
||||
{"eglDebugMessageControlKHR", reinterpret_cast<void*>(VendorDebugMessageControlKHR)},
|
||||
{"eglQueryDebugKHR", reinterpret_cast<void*>(VendorQueryDebugKHR)},
|
||||
{"eglLabelObjectKHR", reinterpret_cast<void*>(VendorLabelObjectKHR)},
|
||||
};
|
||||
|
||||
// THE SAME ANSWER TO BOTH OF GLVND'S QUESTIONS, and that is not a shortcut - glvnd asks them
|
||||
// from two places and a library that answers one of them has a hole the size of the other:
|
||||
//
|
||||
// getProcAddress is asked for every entry point glvnd builds its own static EGL table
|
||||
// from, so a null here drops the vendor outright.
|
||||
// getDispatchAddress is what glvnd falls back to for eglGetProcAddress on any name it does
|
||||
// not know itself - which is every extension entry point that is not in
|
||||
// its list, the device queries among them. A vendor that answers these
|
||||
// from a GL-only table hands the application a null for a function the
|
||||
// vendor implements, and the caller reports the extension as missing.
|
||||
void* LookupEntryPoint(const char* procName) {
|
||||
if (procName == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
for (const EntryPoint& entry : kEglEntryPoints) {
|
||||
if (std::strcmp(entry.name, procName) == 0) {
|
||||
return entry.address;
|
||||
}
|
||||
}
|
||||
// Anything that is not EGL is a GL or GLES entry point, and the tree's own resolver is the
|
||||
// table for those.
|
||||
return reinterpret_cast<void*>(MG_Impl::EGLImpl::GetProcAddress(procName));
|
||||
}
|
||||
|
||||
void* EGLAPIENTRY VendorGetProcAddress(const char* procName) { return LookupEntryPoint(procName); }
|
||||
|
||||
// glvnd hands a vendor the index each EGL entry point occupies in its dispatch table, so that a
|
||||
// vendor whose entry points are thin wrappers around glvnd can call back into the right slot.
|
||||
// This library's entry points ARE the implementation - they never re-enter glvnd - so there is
|
||||
// nothing to record; the callback exists because glvnd refuses a vendor that does not provide
|
||||
// one, and refusing it means the library is loaded and never dispatched to.
|
||||
void EGLAPIENTRY VendorSetDispatchIndex(const char* procName, int index) {
|
||||
(void)procName;
|
||||
(void)index;
|
||||
}
|
||||
|
||||
void* EGLAPIENTRY VendorGetDispatchAddress(const char* procName) {
|
||||
// glvnd asks THIS vendor for GL entry points as well: after eglMakeCurrent, the dispatch
|
||||
// table of the now-current context is filled from here, one name at a time. LookupEntryPoint
|
||||
// knows EGL names only, so every GL name (glGetString, glCreateProgram, ...) answered NULL,
|
||||
// glvnd wrote NULL into its dispatch slots, and the first glGetString of the compositor's
|
||||
// context came back NULL - kwin's "Could not initialize rendering context", while the very
|
||||
// same context answered fine through a direct eglGetProcAddress (measured: probe6 vs probe12).
|
||||
// GL names go through the full GL/EGL lookup, which is the same table eglGetProcAddress uses.
|
||||
if (void* address = LookupEntryPoint(procName)) {
|
||||
return address;
|
||||
}
|
||||
return reinterpret_cast<void*>(MG_Impl::EGLImpl::GetProcAddress(procName));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
extern "C" MOBILEGL_EGL_API EGLBoolean __egl_Main(uint32_t version, const __EGLapiExports* exports,
|
||||
__EGLvendorInfo* vendor, __EGLapiImports* imports) {
|
||||
(void)vendor;
|
||||
if (EGL_VENDOR_ABI_GET_MAJOR_VERSION(version) != EGL_VENDOR_ABI_MAJOR_VERSION) {
|
||||
// A vendor that does not know the ABI it is being handed must say so, not guess: the
|
||||
// structures on either side are the ABI.
|
||||
MGLOG_E("__egl_Main: unsupported glvnd vendor ABI version 0x%08x (this library implements %u.%u)", version,
|
||||
static_cast<unsigned>(EGL_VENDOR_ABI_MAJOR_VERSION),
|
||||
static_cast<unsigned>(EGL_VENDOR_ABI_MINOR_VERSION));
|
||||
return EGL_FALSE;
|
||||
}
|
||||
if (exports == nullptr || imports == nullptr) {
|
||||
MGLOG_E("__egl_Main: glvnd handed no exports/imports table");
|
||||
return EGL_FALSE;
|
||||
}
|
||||
g_eglExports = exports;
|
||||
|
||||
imports->getPlatformDisplay = VendorGetPlatformDisplay;
|
||||
imports->getSupportsAPI = VendorGetSupportsAPI;
|
||||
imports->getVendorString = VendorGetVendorString;
|
||||
imports->getProcAddress = VendorGetProcAddress;
|
||||
imports->getDispatchAddress = VendorGetDispatchAddress;
|
||||
imports->setDispatchIndex = VendorSetDispatchIndex;
|
||||
|
||||
MGLOG_I("glvnd vendor: MobileGL is serving EGL through libglvnd (ABI %u.%u, platforms: %s)",
|
||||
static_cast<unsigned>(EGL_VENDOR_ABI_MAJOR_VERSION), static_cast<unsigned>(EGL_VENDOR_ABI_MINOR_VERSION),
|
||||
kPlatformExtensions);
|
||||
return EGL_TRUE;
|
||||
}
|
||||
@@ -1,398 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Impl/EGLImpl/WaylandWindow.cpp
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#include "WaylandWindow.h"
|
||||
|
||||
#if MOBILEGL_WAYLAND_WINDOWS
|
||||
|
||||
#include <MG_Impl/GLImpl/Buffer/GL_Buffer.h>
|
||||
#include <MG_Impl/GLImpl/Framebuffer/GL_Framebuffer.h>
|
||||
#include <MG_Impl/GLImpl/Getter/GL_Getter.h>
|
||||
#include <MG_Impl/GLImpl/RenderState/GL_RenderState.h>
|
||||
#include <MG_Util/Debug/Log.h>
|
||||
#include <cerrno>
|
||||
#include <cstdarg>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <dlfcn.h>
|
||||
#include <fcntl.h>
|
||||
#include <mutex>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace MobileGL::MG_Impl::EGLImpl::Wayland {
|
||||
namespace {
|
||||
// libwayland-client's types are opaque here: everything goes through wl_proxy_* and the
|
||||
// exported interface descriptions, and nothing reads a field of either.
|
||||
struct wl_proxy;
|
||||
struct wl_interface;
|
||||
struct wl_event_queue;
|
||||
|
||||
// wayland-egl-backend.h, WL_EGL_WINDOW_VERSION 3: the struct libwayland-egl allocates for
|
||||
// wl_egl_window_create and the driver reads. The ABI is versioned by its first word.
|
||||
struct EglWindow {
|
||||
const intptr_t version;
|
||||
int width;
|
||||
int height;
|
||||
int dx;
|
||||
int dy;
|
||||
int attached_width;
|
||||
int attached_height;
|
||||
void* driver_private;
|
||||
void (*resize_callback)(EglWindow*, void*);
|
||||
void (*destroy_window_callback)(void*);
|
||||
wl_proxy* surface;
|
||||
};
|
||||
constexpr intptr_t kEglWindowVersion = 3;
|
||||
|
||||
// Request opcodes (wayland.xml, the order the requests are declared in).
|
||||
constexpr uint32_t kDisplayGetRegistry = 1;
|
||||
constexpr uint32_t kRegistryBind = 0;
|
||||
constexpr uint32_t kShmCreatePool = 0;
|
||||
constexpr uint32_t kShmPoolCreateBuffer = 0;
|
||||
constexpr uint32_t kShmPoolDestroy = 1;
|
||||
constexpr uint32_t kBufferDestroy = 0;
|
||||
constexpr uint32_t kSurfaceAttach = 1;
|
||||
constexpr uint32_t kSurfaceDamage = 2;
|
||||
constexpr uint32_t kSurfaceCommit = 6;
|
||||
constexpr uint32_t kSurfaceDamageBuffer = 9; // since wl_surface version 4
|
||||
constexpr uint32_t kMarshalFlagDestroy = 1u << 0;
|
||||
// wl_shm formats. The two every compositor must support; byte order in memory is
|
||||
// B, G, R, A for both (little-endian 0xAARRGGBB).
|
||||
constexpr uint32_t kShmFormatArgb8888 = 0;
|
||||
constexpr uint32_t kShmFormatXrgb8888 = 1;
|
||||
|
||||
struct Api {
|
||||
Bool loaded = false;
|
||||
const wl_interface* displayInterface = nullptr;
|
||||
const wl_interface* registryInterface = nullptr;
|
||||
const wl_interface* shmInterface = nullptr;
|
||||
const wl_interface* shmPoolInterface = nullptr;
|
||||
const wl_interface* bufferInterface = nullptr;
|
||||
wl_proxy* (*marshalFlags)(wl_proxy*, uint32_t, const wl_interface*, uint32_t, uint32_t, ...) = nullptr;
|
||||
int (*addListener)(wl_proxy*, void (**)(void), void*) = nullptr;
|
||||
void (*destroy)(wl_proxy*) = nullptr;
|
||||
uint32_t (*getVersion)(wl_proxy*) = nullptr;
|
||||
void* (*createWrapper)(void*) = nullptr;
|
||||
void (*wrapperDestroy)(void*) = nullptr;
|
||||
void (*setQueue)(wl_proxy*, wl_event_queue*) = nullptr;
|
||||
wl_event_queue* (*createQueue)(void*) = nullptr;
|
||||
void (*queueDestroy)(wl_event_queue*) = nullptr;
|
||||
int (*roundtripQueue)(void*, wl_event_queue*) = nullptr;
|
||||
int (*dispatchQueue)(void*, wl_event_queue*) = nullptr;
|
||||
int (*dispatchQueuePending)(void*, wl_event_queue*) = nullptr;
|
||||
int (*flush)(void*) = nullptr;
|
||||
};
|
||||
|
||||
// Loaded once. RTLD_NOLOAD first: a Wayland client has the library already, and the copy
|
||||
// it is using is the one whose wl_display this must talk to.
|
||||
const Api& WaylandApi() {
|
||||
static Api api;
|
||||
static std::once_flag once;
|
||||
std::call_once(once, [] {
|
||||
void* lib = dlopen("libwayland-client.so.0", RTLD_NOW | RTLD_NOLOAD);
|
||||
if (lib == nullptr) lib = dlopen("libwayland-client.so.0", RTLD_NOW);
|
||||
if (lib == nullptr) return;
|
||||
const auto sym = [lib](const char* name) { return dlsym(lib, name); };
|
||||
api.displayInterface = static_cast<const wl_interface*>(sym("wl_display_interface"));
|
||||
api.registryInterface = static_cast<const wl_interface*>(sym("wl_registry_interface"));
|
||||
api.shmInterface = static_cast<const wl_interface*>(sym("wl_shm_interface"));
|
||||
api.shmPoolInterface = static_cast<const wl_interface*>(sym("wl_shm_pool_interface"));
|
||||
api.bufferInterface = static_cast<const wl_interface*>(sym("wl_buffer_interface"));
|
||||
api.marshalFlags = reinterpret_cast<decltype(api.marshalFlags)>(sym("wl_proxy_marshal_flags"));
|
||||
api.addListener = reinterpret_cast<decltype(api.addListener)>(sym("wl_proxy_add_listener"));
|
||||
api.destroy = reinterpret_cast<decltype(api.destroy)>(sym("wl_proxy_destroy"));
|
||||
api.getVersion = reinterpret_cast<decltype(api.getVersion)>(sym("wl_proxy_get_version"));
|
||||
api.createWrapper = reinterpret_cast<decltype(api.createWrapper)>(sym("wl_proxy_create_wrapper"));
|
||||
api.wrapperDestroy = reinterpret_cast<decltype(api.wrapperDestroy)>(sym("wl_proxy_wrapper_destroy"));
|
||||
api.setQueue = reinterpret_cast<decltype(api.setQueue)>(sym("wl_proxy_set_queue"));
|
||||
api.createQueue = reinterpret_cast<decltype(api.createQueue)>(sym("wl_display_create_queue"));
|
||||
api.queueDestroy = reinterpret_cast<decltype(api.queueDestroy)>(sym("wl_event_queue_destroy"));
|
||||
api.roundtripQueue = reinterpret_cast<decltype(api.roundtripQueue)>(sym("wl_display_roundtrip_queue"));
|
||||
api.dispatchQueue = reinterpret_cast<decltype(api.dispatchQueue)>(sym("wl_display_dispatch_queue"));
|
||||
api.dispatchQueuePending =
|
||||
reinterpret_cast<decltype(api.dispatchQueuePending)>(sym("wl_display_dispatch_queue_pending"));
|
||||
api.flush = reinterpret_cast<decltype(api.flush)>(sym("wl_display_flush"));
|
||||
api.loaded = api.displayInterface && api.registryInterface && api.shmInterface &&
|
||||
api.shmPoolInterface && api.bufferInterface && api.marshalFlags && api.addListener && api.destroy &&
|
||||
api.getVersion && api.createWrapper && api.wrapperDestroy && api.setQueue &&
|
||||
api.createQueue && api.queueDestroy && api.roundtripQueue && api.dispatchQueue &&
|
||||
api.dispatchQueuePending && api.flush;
|
||||
if (!api.loaded) MGLOG_E("Wayland: libwayland-client.so.0 lacks an entry point this library uses");
|
||||
});
|
||||
return api;
|
||||
}
|
||||
|
||||
struct ShmBuffer {
|
||||
wl_proxy* buffer = nullptr;
|
||||
void* map = nullptr;
|
||||
SizeT size = 0;
|
||||
EGLint width = 0;
|
||||
EGLint height = 0;
|
||||
EGLint stride = 0;
|
||||
Bool busy = false;
|
||||
};
|
||||
|
||||
// The compositor is done with a buffer: it may be drawn into again.
|
||||
void OnBufferRelease(void* data, wl_proxy*) { static_cast<ShmBuffer*>(data)->busy = false; }
|
||||
void (*const kBufferListener[])(void) = {reinterpret_cast<void (*)(void)>(&OnBufferRelease)};
|
||||
} // namespace
|
||||
|
||||
struct WindowSurface::Impl {
|
||||
void* display = nullptr;
|
||||
EglWindow* window = nullptr;
|
||||
wl_event_queue* queue = nullptr;
|
||||
void* displayWrapper = nullptr;
|
||||
wl_proxy* registry = nullptr;
|
||||
wl_proxy* shm = nullptr;
|
||||
uint32_t format = kShmFormatXrgb8888;
|
||||
EGLint width = 0;
|
||||
EGLint height = 0;
|
||||
// Three: one on the glass, one the compositor may still be reading, one to draw into.
|
||||
ShmBuffer buffers[3];
|
||||
Vector<Uint8> scratch;
|
||||
|
||||
~Impl() {
|
||||
const Api& api = WaylandApi();
|
||||
for (auto& buffer : buffers) Release(buffer);
|
||||
// Neither wl_shm (version 1) nor wl_registry has a destroy request: the proxies go
|
||||
// on this side only.
|
||||
if (shm) api.destroy(shm);
|
||||
if (registry) api.destroy(registry);
|
||||
if (displayWrapper) api.wrapperDestroy(displayWrapper);
|
||||
if (queue) api.queueDestroy(queue);
|
||||
if (window && window->driver_private == this) {
|
||||
window->driver_private = nullptr;
|
||||
window->destroy_window_callback = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void Release(ShmBuffer& buffer) {
|
||||
const Api& api = WaylandApi();
|
||||
if (buffer.buffer) api.marshalFlags(buffer.buffer, kBufferDestroy, nullptr, api.getVersion(buffer.buffer),
|
||||
kMarshalFlagDestroy);
|
||||
if (buffer.map) munmap(buffer.map, buffer.size);
|
||||
buffer = ShmBuffer{};
|
||||
}
|
||||
|
||||
Bool Allocate(ShmBuffer& buffer) {
|
||||
const Api& api = WaylandApi();
|
||||
Release(buffer);
|
||||
const EGLint stride = width * 4;
|
||||
const SizeT size = static_cast<SizeT>(stride) * static_cast<SizeT>(height);
|
||||
const int fd = memfd_create("mobilegl-wayland", MFD_CLOEXEC);
|
||||
if (fd < 0) {
|
||||
MGLOG_E("Wayland: memfd_create for a %dx%d buffer failed: %s", width, height, std::strerror(errno));
|
||||
return false;
|
||||
}
|
||||
if (ftruncate(fd, static_cast<off_t>(size)) != 0) {
|
||||
MGLOG_E("Wayland: sizing a %dx%d buffer failed: %s", width, height, std::strerror(errno));
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
void* map = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (map == MAP_FAILED) {
|
||||
MGLOG_E("Wayland: mapping a %dx%d buffer failed: %s", width, height, std::strerror(errno));
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
// One pool per buffer, destroyed at once: the buffer keeps the memory alive.
|
||||
wl_proxy* pool = api.marshalFlags(shm, kShmCreatePool, api.shmPoolInterface, api.getVersion(shm), 0, nullptr,
|
||||
fd, static_cast<int32_t>(size));
|
||||
close(fd);
|
||||
if (pool == nullptr) {
|
||||
munmap(map, size);
|
||||
return false;
|
||||
}
|
||||
wl_proxy* wlBuffer = api.marshalFlags(pool, kShmPoolCreateBuffer, api.bufferInterface, api.getVersion(pool),
|
||||
0, nullptr, 0, width, height, stride, format);
|
||||
api.marshalFlags(pool, kShmPoolDestroy, nullptr, api.getVersion(pool), kMarshalFlagDestroy);
|
||||
if (wlBuffer == nullptr) {
|
||||
munmap(map, size);
|
||||
return false;
|
||||
}
|
||||
buffer.buffer = wlBuffer;
|
||||
buffer.map = map;
|
||||
buffer.size = size;
|
||||
buffer.width = width;
|
||||
buffer.height = height;
|
||||
buffer.stride = stride;
|
||||
buffer.busy = false;
|
||||
api.addListener(wlBuffer, const_cast<void (**)(void)>(kBufferListener), &buffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
// A buffer the compositor is not reading: the events already received first, then (all
|
||||
// three still held) a blocking wait for the next release.
|
||||
ShmBuffer* NextFree() {
|
||||
const Api& api = WaylandApi();
|
||||
for (;;) {
|
||||
if (api.dispatchQueuePending(display, queue) < 0) return nullptr;
|
||||
for (auto& buffer : buffers) {
|
||||
if (buffer.buffer == nullptr || buffer.busy) continue;
|
||||
if (buffer.width != width || buffer.height != height) {
|
||||
if (!Allocate(buffer)) return nullptr;
|
||||
}
|
||||
return &buffer;
|
||||
}
|
||||
for (auto& buffer : buffers) {
|
||||
if (buffer.buffer == nullptr) return Allocate(buffer) ? &buffer : nullptr;
|
||||
}
|
||||
if (api.dispatchQueue(display, queue) < 0) return nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
namespace {
|
||||
void OnRegistryGlobal(void* data, wl_proxy* registry, uint32_t name, const char* interface, uint32_t) {
|
||||
auto* impl = static_cast<WindowSurface::Impl*>(data);
|
||||
if (impl->shm != nullptr || std::strcmp(interface, "wl_shm") != 0) return;
|
||||
const Api& api = WaylandApi();
|
||||
impl->shm = api.marshalFlags(registry, kRegistryBind, api.shmInterface, 1, 0, name, "wl_shm", 1u, nullptr);
|
||||
}
|
||||
void OnRegistryGlobalRemove(void*, wl_proxy*, uint32_t) {}
|
||||
void (*const kRegistryListener[])(void) = {reinterpret_cast<void (*)(void)>(&OnRegistryGlobal),
|
||||
reinterpret_cast<void (*)(void)>(&OnRegistryGlobalRemove)};
|
||||
|
||||
// The application destroyed its wl_egl_window first: nothing may be read from it after this.
|
||||
void OnWindowDestroyed(void* data) { static_cast<WindowSurface::Impl*>(data)->window = nullptr; }
|
||||
} // namespace
|
||||
|
||||
Bool IsWaylandDisplay(Uint64 nativeDisplay, EGLenum platform) {
|
||||
if (platform == kPlatformWayland) return true;
|
||||
if (nativeDisplay == 0 || (platform != EGL_NONE && platform != 0)) return false;
|
||||
const Api& api = WaylandApi();
|
||||
if (!api.loaded) return false;
|
||||
return *reinterpret_cast<const void* const*>(static_cast<uintptr_t>(nativeDisplay)) == api.displayInterface;
|
||||
}
|
||||
|
||||
Bool IsWaylandWindow(const void* window) {
|
||||
if (window == nullptr) return false;
|
||||
const auto* eglWindow = static_cast<const EglWindow*>(window);
|
||||
return eglWindow->version >= kEglWindowVersion && eglWindow->surface != nullptr;
|
||||
}
|
||||
|
||||
Bool WindowSize(const void* window, EGLint* width, EGLint* height) {
|
||||
if (!IsWaylandWindow(window)) return false;
|
||||
const auto* eglWindow = static_cast<const EglWindow*>(window);
|
||||
*width = eglWindow->width;
|
||||
*height = eglWindow->height;
|
||||
return eglWindow->width > 0 && eglWindow->height > 0;
|
||||
}
|
||||
|
||||
WindowSurface::WindowSurface(UniquePtr<Impl> impl) : m_impl(std::move(impl)) {}
|
||||
WindowSurface::~WindowSurface() = default;
|
||||
|
||||
UniquePtr<WindowSurface> WindowSurface::Create(void* wlDisplay, void* wlEglWindow, EGLint width, EGLint height,
|
||||
Bool hasAlpha) {
|
||||
const Api& api = WaylandApi();
|
||||
if (!api.loaded) {
|
||||
MGLOG_E("Wayland: a window surface needs libwayland-client.so.0, and it could not be used");
|
||||
return nullptr;
|
||||
}
|
||||
if (wlDisplay == nullptr || !IsWaylandWindow(wlEglWindow) || width <= 0 || height <= 0) return nullptr;
|
||||
auto impl = MakeUnique<Impl>();
|
||||
impl->display = wlDisplay;
|
||||
impl->window = static_cast<EglWindow*>(wlEglWindow);
|
||||
impl->width = width;
|
||||
impl->height = height;
|
||||
impl->format = hasAlpha ? kShmFormatArgb8888 : kShmFormatXrgb8888;
|
||||
// A queue of this surface's own, so the application's dispatching never sees these events
|
||||
// and this never dispatches the application's.
|
||||
impl->queue = api.createQueue(wlDisplay);
|
||||
impl->displayWrapper = api.createWrapper(wlDisplay);
|
||||
if (impl->queue == nullptr || impl->displayWrapper == nullptr) return nullptr;
|
||||
api.setQueue(static_cast<wl_proxy*>(impl->displayWrapper), impl->queue);
|
||||
auto* wrapper = static_cast<wl_proxy*>(impl->displayWrapper);
|
||||
impl->registry = api.marshalFlags(wrapper, kDisplayGetRegistry, api.registryInterface, api.getVersion(wrapper),
|
||||
0, nullptr);
|
||||
if (impl->registry == nullptr) return nullptr;
|
||||
api.addListener(impl->registry, const_cast<void (**)(void)>(kRegistryListener), impl.get());
|
||||
if (api.roundtripQueue(wlDisplay, impl->queue) < 0 || impl->shm == nullptr) {
|
||||
MGLOG_E("Wayland: the compositor offers no wl_shm; a window surface cannot be presented");
|
||||
return nullptr;
|
||||
}
|
||||
impl->window->driver_private = impl.get();
|
||||
impl->window->destroy_window_callback = &OnWindowDestroyed;
|
||||
MGLOG_I("Wayland: window surface %dx%d presented through wl_shm (%s)", width, height,
|
||||
hasAlpha ? "ARGB8888" : "XRGB8888");
|
||||
return UniquePtr<WindowSurface>(new WindowSurface(std::move(impl)));
|
||||
}
|
||||
|
||||
Bool WindowSurface::Present() {
|
||||
Impl& impl = *m_impl;
|
||||
if (impl.window == nullptr) return false;
|
||||
const Api& api = WaylandApi();
|
||||
ShmBuffer* buffer = impl.NextFree();
|
||||
if (buffer == nullptr) {
|
||||
MGLOG_E_ONCE("Wayland: no wl_shm buffer could be taken for the frame; it is not shown");
|
||||
return false;
|
||||
}
|
||||
|
||||
// The frame, out of the default framebuffer, through this library's own entry points: the
|
||||
// application's read framebuffer, pack buffer and pack state are saved and put back, so
|
||||
// the readback is invisible to it.
|
||||
namespace GL = MG_Impl::GLImpl;
|
||||
GLint readFramebuffer = 0, packBuffer = 0, alignment = 4, rowLength = 0, skipRows = 0, skipPixels = 0;
|
||||
GL::GetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &readFramebuffer);
|
||||
GL::GetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING, &packBuffer);
|
||||
GL::GetIntegerv(GL_PACK_ALIGNMENT, &alignment);
|
||||
GL::GetIntegerv(GL_PACK_ROW_LENGTH, &rowLength);
|
||||
GL::GetIntegerv(GL_PACK_SKIP_ROWS, &skipRows);
|
||||
GL::GetIntegerv(GL_PACK_SKIP_PIXELS, &skipPixels);
|
||||
if (readFramebuffer != 0) GL::BindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
if (packBuffer != 0) GL::BindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
||||
GL::PixelStorei(GL_PACK_ALIGNMENT, 4);
|
||||
GL::PixelStorei(GL_PACK_ROW_LENGTH, 0);
|
||||
GL::PixelStorei(GL_PACK_SKIP_ROWS, 0);
|
||||
GL::PixelStorei(GL_PACK_SKIP_PIXELS, 0);
|
||||
const SizeT rowBytes = static_cast<SizeT>(impl.width) * 4;
|
||||
impl.scratch.resize(rowBytes * static_cast<SizeT>(impl.height));
|
||||
GL::ReadPixels(0, 0, impl.width, impl.height, GL_RGBA, GL_UNSIGNED_BYTE, impl.scratch.data());
|
||||
GL::PixelStorei(GL_PACK_ALIGNMENT, alignment);
|
||||
GL::PixelStorei(GL_PACK_ROW_LENGTH, rowLength);
|
||||
GL::PixelStorei(GL_PACK_SKIP_ROWS, skipRows);
|
||||
GL::PixelStorei(GL_PACK_SKIP_PIXELS, skipPixels);
|
||||
if (packBuffer != 0) GL::BindBuffer(GL_PIXEL_PACK_BUFFER, static_cast<GLuint>(packBuffer));
|
||||
if (readFramebuffer != 0) GL::BindFramebuffer(GL_READ_FRAMEBUFFER, static_cast<GLuint>(readFramebuffer));
|
||||
|
||||
// GL's rows run bottom-up and RGBA; a wl_shm buffer's run top-down and B, G, R, A.
|
||||
auto* dst = static_cast<Uint8*>(buffer->map);
|
||||
for (EGLint y = 0; y < impl.height; ++y) {
|
||||
const Uint8* src = impl.scratch.data() + static_cast<SizeT>(impl.height - 1 - y) * rowBytes;
|
||||
Uint8* row = dst + static_cast<SizeT>(y) * static_cast<SizeT>(buffer->stride);
|
||||
for (EGLint x = 0; x < impl.width; ++x) {
|
||||
row[x * 4 + 0] = src[x * 4 + 2];
|
||||
row[x * 4 + 1] = src[x * 4 + 1];
|
||||
row[x * 4 + 2] = src[x * 4 + 0];
|
||||
row[x * 4 + 3] = src[x * 4 + 3];
|
||||
}
|
||||
}
|
||||
|
||||
wl_proxy* surface = impl.window->surface;
|
||||
const uint32_t surfaceVersion = api.getVersion(surface);
|
||||
api.marshalFlags(surface, kSurfaceAttach, nullptr, surfaceVersion, 0, buffer->buffer, impl.window->dx,
|
||||
impl.window->dy);
|
||||
if (surfaceVersion >= 4) {
|
||||
api.marshalFlags(surface, kSurfaceDamageBuffer, nullptr, surfaceVersion, 0, 0, 0, impl.width,
|
||||
impl.height);
|
||||
} else {
|
||||
api.marshalFlags(surface, kSurfaceDamage, nullptr, surfaceVersion, 0, 0, 0, impl.width, impl.height);
|
||||
}
|
||||
api.marshalFlags(surface, kSurfaceCommit, nullptr, surfaceVersion, 0);
|
||||
buffer->busy = true;
|
||||
impl.window->attached_width = impl.width;
|
||||
impl.window->attached_height = impl.height;
|
||||
impl.window->dx = 0;
|
||||
impl.window->dy = 0;
|
||||
api.flush(impl.display);
|
||||
return true;
|
||||
}
|
||||
} // namespace MobileGL::MG_Impl::EGLImpl::Wayland
|
||||
|
||||
#endif
|
||||
@@ -1,72 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Impl/EGLImpl/WaylandWindow.h
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#pragma once
|
||||
|
||||
// WAYLAND WINDOW SURFACES. A Wayland client hands eglCreateWindowSurface a wl_egl_window, and what
|
||||
// the compositor shows is whatever wl_buffer the client attaches to that window's wl_surface. The
|
||||
// pixels of a MobileGL frame are drawn where the backend is - on a split build, in another process
|
||||
// on another OS - so a window surface here is a pbuffer the backend draws into, plus this: at every
|
||||
// swap the frame is read back and attached to the wl_surface as a wl_shm buffer.
|
||||
//
|
||||
// libwayland-client is loaded at run time (it is already in every Wayland client's process), so the
|
||||
// library neither links it nor needs its headers to build.
|
||||
|
||||
#include <Includes.h>
|
||||
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
#define MOBILEGL_WAYLAND_WINDOWS 1
|
||||
#else
|
||||
#define MOBILEGL_WAYLAND_WINDOWS 0
|
||||
#endif
|
||||
|
||||
#if MOBILEGL_WAYLAND_WINDOWS
|
||||
|
||||
#include <EGL/egl.h>
|
||||
|
||||
namespace MobileGL::MG_Impl::EGLImpl::Wayland {
|
||||
// EGL_PLATFORM_WAYLAND_KHR and EGL_PLATFORM_WAYLAND_EXT are the same enum.
|
||||
inline constexpr EGLenum kPlatformWayland = 0x31D8;
|
||||
|
||||
// Whether a display is a Wayland one: asked for as EGL_PLATFORM_WAYLAND, or (eglGetDisplay with
|
||||
// no platform) a native display that is a wl_display - recognised the way Mesa does, by its
|
||||
// first word being libwayland-client's wl_display_interface.
|
||||
Bool IsWaylandDisplay(Uint64 nativeDisplay, EGLenum platform);
|
||||
|
||||
// Whether `window` looks like a wl_egl_window this library can present to.
|
||||
Bool IsWaylandWindow(const void* window);
|
||||
|
||||
// The size the application last gave its wl_egl_window.
|
||||
Bool WindowSize(const void* window, EGLint* width, EGLint* height);
|
||||
|
||||
// One window surface's presentation: the shm buffers, the event queue they are dispatched on,
|
||||
// and the readback scratch. Created for a wl_egl_window on a wl_display; null with the reason
|
||||
// logged when libwayland-client or the compositor's wl_shm is not there.
|
||||
class WindowSurface {
|
||||
public:
|
||||
static UniquePtr<WindowSurface> Create(void* wlDisplay, void* wlEglWindow, EGLint width, EGLint height,
|
||||
Bool hasAlpha);
|
||||
~WindowSurface();
|
||||
WindowSurface(const WindowSurface&) = delete;
|
||||
WindowSurface& operator=(const WindowSurface&) = delete;
|
||||
|
||||
// Reads the frame back out of the current context's default framebuffer and puts it on
|
||||
// the window: attach, damage, commit. The application's read-framebuffer and pack state
|
||||
// are put back exactly as they were. False (logged) when the frame did not reach the
|
||||
// window; the swap itself goes on regardless.
|
||||
Bool Present();
|
||||
|
||||
struct Impl;
|
||||
|
||||
private:
|
||||
explicit WindowSurface(UniquePtr<Impl> impl);
|
||||
UniquePtr<Impl> m_impl;
|
||||
};
|
||||
} // namespace MobileGL::MG_Impl::EGLImpl::Wayland
|
||||
|
||||
#endif
|
||||
@@ -6,9 +6,6 @@
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
// The dma-buf import's client half: eglCreateImageKHR keeps a dup() of every plane's descriptor,
|
||||
// and this is what tells the render server which texture that buffer backs (see the header).
|
||||
#include <MG_Remote/Client/DmaBufImport.h>
|
||||
#include <Includes.h>
|
||||
#include "../Buffer/GL_Buffer.h"
|
||||
#include "../Getter/GL_Getter.h"
|
||||
@@ -25,13 +22,6 @@
|
||||
#include "../Sync/GL_Sync.h"
|
||||
#include "../Debug/GL_Debug.h"
|
||||
#include <MG_State/GLState/Core.h>
|
||||
// The EGL side of the state, for the two GL_OES_EGL_image entry points: what an EGLImage handle
|
||||
// names is an object eglCreateImageKHR built (its geometry, its fourcc and the descriptors it owns),
|
||||
// and that object lives in the EGL state. Same include the other GLImpl files that touch it use.
|
||||
#include <MG_State/EGLState/Core.h>
|
||||
// The compositor's frame boundary: glFlush presents the display host's frame when the surfaceless
|
||||
// bind hook took one (see EGLImpl.cpp). The EGL side declares the pair and the swap entry.
|
||||
#include <MG_Impl/EGLImpl/EGLImpl.h>
|
||||
|
||||
#define DECLARE_GL_FUNCTION_STUB_HEAD(type, name, ...) MOBILEGL_GL_API type gl##name(__VA_ARGS__) {
|
||||
|
||||
@@ -130,23 +120,7 @@ MOBILEGL_GL_API void glFinish() {
|
||||
MobileGL::MG_Pipe::MGPipeClientFinish();
|
||||
#endif
|
||||
}
|
||||
MOBILEGL_GL_API void glFlush() {
|
||||
MGLOG_D("Implementing function: %s(...)", __FUNCTION__);
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
MobileGL::MG_Pipe::MGPipeClientFlush();
|
||||
#endif
|
||||
// A COMPOSITOR'S FRAME BOUNDARY. kwin binds the display host's frame surface and draws the
|
||||
// desktop into it, then calls glFlush - and glFlush alone. It never calls eglSwapBuffers, so
|
||||
// without this the stream reached the server and the server drew, but the display host was
|
||||
// never told a frame was done: the host's own present loop (AHardwareBuffer_acquire ->
|
||||
// draw -> notify) is what puts pixels on the glass, and its notify is exactly this swap.
|
||||
// Guarded by whether the surfaceless-bind hook actually took the host frame.
|
||||
if (MobileGL::MG_Impl::EGLImpl::g_hostFramePresentSurface != nullptr &&
|
||||
MobileGL::MG_Impl::EGLImpl::g_hostFramePresentDisplay != nullptr) {
|
||||
MobileGL::MG_Impl::EGLImpl::SwapBuffers(MobileGL::MG_Impl::EGLImpl::g_hostFramePresentDisplay,
|
||||
MobileGL::MG_Impl::EGLImpl::g_hostFramePresentSurface);
|
||||
}
|
||||
}
|
||||
MOBILEGL_GL_API void glFlush() { MGLOG_D("Implementing function: %s(...)", __FUNCTION__); }
|
||||
DECLARE_GL_FUNCTION_HEAD(void, FramebufferRenderbuffer, GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) DECLARE_GL_FUNCTION_END_NO_RETURN(void, FramebufferRenderbuffer, target, attachment, renderbuffertarget, renderbuffer)
|
||||
DECLARE_GL_FUNCTION_HEAD(void, FramebufferTexture2D, GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) DECLARE_GL_FUNCTION_END_NO_RETURN(void, FramebufferTexture2D, target, attachment, textarget, texture, level)
|
||||
DECLARE_GL_FUNCTION_HEAD(void, FrontFace, GLenum mode) DECLARE_GL_FUNCTION_END_NO_RETURN(void, FrontFace, mode)
|
||||
@@ -1318,325 +1292,17 @@ DECLARE_GL_FUNCTION_STUB_HEAD(void, GetnMinmaxARB, GLenum target, GLboolean rese
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, FramebufferSampleLocationsfvARB, GLenum target, GLuint start, GLsizei count, const GLfloat* v) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, FramebufferSampleLocationsfvARB, target, start, count, v)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, NamedFramebufferSampleLocationsfvARB, GLuint framebuffer, GLuint start, GLsizei count, const GLfloat* v) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, NamedFramebufferSampleLocationsfvARB, framebuffer, start, count, v)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, EvaluateDepthValuesARB, void) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, EvaluateDepthValuesARB, )
|
||||
// GL_ARB_shader_objects, GL_ARB_vertex_shader, GL_ARB_fragment_shader.
|
||||
//
|
||||
// kwin_wayland 6.7.3 refuses a MobileGL context over three of the names these extensions add.
|
||||
// EglContext::checkSupported() (src/opengl/eglcontext.cpp) takes the DESKTOP-OpenGL branch for
|
||||
// every context whose GL_VERSION is not an "OpenGL ES" string:
|
||||
// const bool supportsGLSL = m_isOpenglES || (hasOpenglExtension("GL_ARB_shader_objects") &&
|
||||
// hasOpenglExtension("GL_ARB_fragment_shader") && hasOpenglExtension("GL_ARB_vertex_shader"));
|
||||
// GL_VERSION here is "4.6.0 MobileGL ...", so all three names were REQUIRED of a context that did
|
||||
// not carry them: checkSupported() answered false, EglContext::create() returned nullptr,
|
||||
// EglBackend::createContext() returned false, and kwin printed "Could not initialize rendering
|
||||
// context" and quit without drawing a frame. Both backends now advertise the three, and this block
|
||||
// is what makes that advertisement true instead of a test unlock - every entry point the three
|
||||
// extensions define is implemented here, over the shader and program objects the core entry points
|
||||
// already own:
|
||||
//
|
||||
// ARB_shader_objects the 39 functions of the block include/GL/glext.h:4095-4173 declares.
|
||||
// ARB_vertex_shader the three attrib-location entry points of glext.h:4856-4862.
|
||||
// ARB_fragment_shader none. Its "New Procedures and Functions" section reads "None" - it is the
|
||||
// capability half of the pair, and the reason kwin names it at all.
|
||||
//
|
||||
// HANDLES. The ARB family names objects with GLhandleARB. This repository's own glext.h types that
|
||||
// as void* on Apple and as unsigned int on every other platform (glext.h:4055-4059, the same split
|
||||
// the system headers carry), so on Linux, Windows and Android a handle IS the GLuint name this
|
||||
// implementation hands out and both conversions below are the identity there. The pointer arm is
|
||||
// not decoration: a caller on Apple passes a pointer, and an id written straight into its void*
|
||||
// slot would be a size error rather than a cast error. H is a template parameter, and both arms
|
||||
// cast through it, so the arm a platform does not use is never instantiated - and never has to be
|
||||
// well-formed for the other typedef: reinterpret_cast between two integers, which is what the
|
||||
// pointer arm becomes on Linux, is not a cast clang accepts. The shape is the one
|
||||
// MG_State/EGLState/Core.h already uses for EGL's handles.
|
||||
template <typename H = GLhandleARB>
|
||||
static GLhandleARB ToGLHandleARB(GLuint name) {
|
||||
if constexpr (std::is_pointer_v<H>) {
|
||||
return reinterpret_cast<H>(static_cast<std::uintptr_t>(name));
|
||||
} else {
|
||||
return static_cast<H>(name);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename H = GLhandleARB>
|
||||
static GLuint FromGLHandleARB(GLhandleARB handle) {
|
||||
if constexpr (std::is_pointer_v<H>) {
|
||||
return static_cast<GLuint>(reinterpret_cast<std::uintptr_t>(static_cast<H>(handle)));
|
||||
} else {
|
||||
return static_cast<GLuint>(handle);
|
||||
}
|
||||
}
|
||||
|
||||
// The answer behind GetObjectParameter{if}vARB, and the reason neither of them carries a pname
|
||||
// translation table: the GL_OBJECT_*_ARB tokens ARE the core tokens, numerically. Core GL took the
|
||||
// object pnames over unchanged when ARB_shader_objects was folded in -
|
||||
// GL_OBJECT_DELETE_STATUS_ARB through GL_OBJECT_SHADER_SOURCE_LENGTH_ARB are 0x8B80-0x8B88, the
|
||||
// same numbers glcorearb.h gives GL_DELETE_STATUS through GL_SHADER_SOURCE_LENGTH
|
||||
// (glext.h:4086-4094) - so the mapping is a RENAME and the same pname goes to the core getter of
|
||||
// the same object kind. Handing it to that getter is also the right ERROR behaviour, and the reason
|
||||
// this does not whitelist pnames: GL_OBJECT_LINK_STATUS_ARB asked of a SHADER has to come back
|
||||
// INVALID_ENUM, and glGetShaderiv is where the set of pnames a shader accepts is defined.
|
||||
//
|
||||
// The one token core never took is GL_OBJECT_TYPE_ARB (0x8B4E; core's GL_OBJECT_TYPE, 0x9112, is
|
||||
// ARB_program_interface_query's interface class, a different question with a different value
|
||||
// space), so the object kind is the single thing answered here without a core getter. It is also
|
||||
// the only way an ARB-era caller can ask whether a handle names a program or a shader: there is no
|
||||
// glIsProgramARB/glIsShaderARB in ARB_shader_objects (include/GL/glext.h:4095-4173 declares
|
||||
// neither, and the glIsProgramARB the registry does know, glext.h:3280, belongs to
|
||||
// ARB_vertex_program/ARB_fragment_program - those ASM program objects are not these).
|
||||
static MobileGL::Bool AnswerObjectParameterARB(GLuint name, GLenum pname, GLint* params) {
|
||||
if (pname == GL_OBJECT_TYPE_ARB) {
|
||||
if (glIsProgram(name)) {
|
||||
*params = GL_PROGRAM_OBJECT_ARB;
|
||||
return true;
|
||||
}
|
||||
if (glIsShader(name)) {
|
||||
*params = GL_SHADER_OBJECT_ARB;
|
||||
return true;
|
||||
}
|
||||
// The error ARB_vertex_shader's own text specifies: "The error INVALID_VALUE is generated
|
||||
// by any command that takes one or more handles as input, and one or more handles are not
|
||||
// an object handle generated by OpenGL."
|
||||
MobileGL::MG_State::pGLContext->RecordError(
|
||||
MobileGL::ErrorCode::InvalidValue,
|
||||
MobileGL::MakeUnique<MobileGL::GenericErrorInfo>(
|
||||
"MG_Impl/GLImpl", __func__,
|
||||
std::to_string(name) + " is not an object handle generated by OpenGL."));
|
||||
return false;
|
||||
}
|
||||
if (glIsProgram(name)) {
|
||||
glGetProgramiv(name, pname, params);
|
||||
return true;
|
||||
}
|
||||
// A shader, or a name that is neither. glGetShaderiv owns both the shader pname set and the
|
||||
// name validation, which is the one place that splits a program name handed to a shader query
|
||||
// (INVALID_OPERATION) from a name GL never generated (INVALID_VALUE) - the split GL 3.3 core
|
||||
// 2.11 requires. It writes nothing in either error case, which is what the caller reads as
|
||||
// "no answer".
|
||||
const MobileGL::Bool isShader = glIsShader(name) == GL_TRUE;
|
||||
glGetShaderiv(name, pname, params);
|
||||
return isShader;
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glDeleteObjectARB(GLhandleARB obj) {
|
||||
// ARB_shader_objects has ONE object namespace - a handle names a program or a shader and
|
||||
// nothing else - and DeleteObjectARB is the deletion entry point for both kinds, so the kind
|
||||
// is decided here. IsProgram/IsShader answer over the same single namespace this
|
||||
// implementation hands names out of, so a program name cannot be taken for a shader name.
|
||||
// Zero, and a handle that names neither object, are ignored: there is no object to delete.
|
||||
const GLuint name = FromGLHandleARB(obj);
|
||||
if (glIsProgram(name)) {
|
||||
glDeleteProgram(name);
|
||||
} else if (glIsShader(name)) {
|
||||
glDeleteShader(name);
|
||||
}
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API GLhandleARB glGetHandleARB(GLenum pname) {
|
||||
if (pname != GL_PROGRAM_OBJECT_ARB) {
|
||||
MobileGL::MG_State::pGLContext->RecordError(
|
||||
MobileGL::ErrorCode::InvalidEnum,
|
||||
MobileGL::MakeUnique<MobileGL::GenericErrorInfo>(
|
||||
"MG_Impl/GLImpl", __func__,
|
||||
"pname " + std::to_string(pname) + " is not GL_PROGRAM_OBJECT_ARB."));
|
||||
return ToGLHandleARB(0u);
|
||||
}
|
||||
// "The program object currently in use", read from the state GL_CURRENT_PROGRAM is answered
|
||||
// from - so a program bound through glUseProgram is found here too, and a
|
||||
// UseProgramObjectARB(0) reads back as the zero handle.
|
||||
const auto& currentProgram = MobileGL::MG_State::pGLContext->GetCurrentProgram();
|
||||
return ToGLHandleARB(currentProgram ? static_cast<GLuint>(currentProgram->GetExternalIndex()) : 0u);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glDetachObjectARB(GLhandleARB containerObj, GLhandleARB attachedObj) {
|
||||
glDetachShader(FromGLHandleARB(containerObj), FromGLHandleARB(attachedObj));
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API GLhandleARB glCreateShaderObjectARB(GLenum shaderType) {
|
||||
return ToGLHandleARB(glCreateShader(shaderType));
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glShaderSourceARB(GLhandleARB shaderObj, GLsizei count, const GLcharARB** string,
|
||||
const GLint* length) {
|
||||
glShaderSource(FromGLHandleARB(shaderObj), count, string, length);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glCompileShaderARB(GLhandleARB shaderObj) {
|
||||
glCompileShader(FromGLHandleARB(shaderObj));
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API GLhandleARB glCreateProgramObjectARB(void) {
|
||||
return ToGLHandleARB(glCreateProgram());
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glAttachObjectARB(GLhandleARB containerObj, GLhandleARB obj) {
|
||||
glAttachShader(FromGLHandleARB(containerObj), FromGLHandleARB(obj));
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glLinkProgramARB(GLhandleARB programObj) {
|
||||
glLinkProgram(FromGLHandleARB(programObj));
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUseProgramObjectARB(GLhandleARB programObj) {
|
||||
glUseProgram(FromGLHandleARB(programObj));
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glValidateProgramARB(GLhandleARB programObj) {
|
||||
glValidateProgram(FromGLHandleARB(programObj));
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform1fARB(GLint location, GLfloat v0) {
|
||||
glUniform1f(location, v0);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform2fARB(GLint location, GLfloat v0, GLfloat v1) {
|
||||
glUniform2f(location, v0, v1);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform3fARB(GLint location, GLfloat v0, GLfloat v1, GLfloat v2) {
|
||||
glUniform3f(location, v0, v1, v2);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform4fARB(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) {
|
||||
glUniform4f(location, v0, v1, v2, v3);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform1iARB(GLint location, GLint v0) {
|
||||
glUniform1i(location, v0);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform2iARB(GLint location, GLint v0, GLint v1) {
|
||||
glUniform2i(location, v0, v1);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform3iARB(GLint location, GLint v0, GLint v1, GLint v2) {
|
||||
glUniform3i(location, v0, v1, v2);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform4iARB(GLint location, GLint v0, GLint v1, GLint v2, GLint v3) {
|
||||
glUniform4i(location, v0, v1, v2, v3);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform1fvARB(GLint location, GLsizei count, const GLfloat* value) {
|
||||
glUniform1fv(location, count, value);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform2fvARB(GLint location, GLsizei count, const GLfloat* value) {
|
||||
glUniform2fv(location, count, value);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform3fvARB(GLint location, GLsizei count, const GLfloat* value) {
|
||||
glUniform3fv(location, count, value);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform4fvARB(GLint location, GLsizei count, const GLfloat* value) {
|
||||
glUniform4fv(location, count, value);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform1ivARB(GLint location, GLsizei count, const GLint* value) {
|
||||
glUniform1iv(location, count, value);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform2ivARB(GLint location, GLsizei count, const GLint* value) {
|
||||
glUniform2iv(location, count, value);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform3ivARB(GLint location, GLsizei count, const GLint* value) {
|
||||
glUniform3iv(location, count, value);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform4ivARB(GLint location, GLsizei count, const GLint* value) {
|
||||
glUniform4iv(location, count, value);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniformMatrix2fvARB(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) {
|
||||
glUniformMatrix2fv(location, count, transpose, value);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniformMatrix3fvARB(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) {
|
||||
glUniformMatrix3fv(location, count, transpose, value);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniformMatrix4fvARB(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) {
|
||||
glUniformMatrix4fv(location, count, transpose, value);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glGetObjectParameterfvARB(GLhandleARB obj, GLenum pname, GLfloat* params) {
|
||||
// The fv form asks the same questions - the ARB object model holds no float-valued object
|
||||
// state - so the answer is the iv answer widened. A query the iv path refuses leaves the
|
||||
// output untouched here as well, rather than putting a plausible-looking 0.0 where there is
|
||||
// no answer.
|
||||
GLint value = 0;
|
||||
if (!AnswerObjectParameterARB(FromGLHandleARB(obj), pname, &value)) return;
|
||||
*params = static_cast<GLfloat>(value);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glGetObjectParameterivARB(GLhandleARB obj, GLenum pname, GLint* params) {
|
||||
AnswerObjectParameterARB(FromGLHandleARB(obj), pname, params);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glGetInfoLogARB(GLhandleARB obj, GLsizei maxLength, GLsizei* length, GLcharARB* infoLog) {
|
||||
// The same handle-kind dispatch as AnswerObjectParameterARB, and the same fallback: the shader
|
||||
// getter is also where the name validation and its error code live.
|
||||
const GLuint name = FromGLHandleARB(obj);
|
||||
if (glIsProgram(name)) {
|
||||
glGetProgramInfoLog(name, maxLength, length, infoLog);
|
||||
} else {
|
||||
glGetShaderInfoLog(name, maxLength, length, infoLog);
|
||||
}
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glGetAttachedObjectsARB(GLhandleARB containerObj, GLsizei maxCount, GLsizei* count,
|
||||
GLhandleARB* obj) {
|
||||
// The caller's array holds GLhandleARB while glGetAttachedShaders writes GLuint names, and on
|
||||
// Apple those are different sizes, so the ids are gathered first and converted one at a time.
|
||||
// A negative maxCount is passed through: glGetAttachedShaders is where its INVALID_VALUE is.
|
||||
MobileGL::Vector<GLuint> shaders(maxCount > 0 ? static_cast<MobileGL::SizeT>(maxCount) : 0, 0);
|
||||
GLsizei attached = 0;
|
||||
glGetAttachedShaders(FromGLHandleARB(containerObj), maxCount, &attached, shaders.data());
|
||||
for (GLsizei i = 0; i < attached; ++i) {
|
||||
obj[i] = ToGLHandleARB(shaders[i]);
|
||||
}
|
||||
if (count) *count = attached;
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API GLint glGetUniformLocationARB(GLhandleARB programObj, const GLcharARB* name) {
|
||||
return glGetUniformLocation(FromGLHandleARB(programObj), name);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glGetActiveUniformARB(GLhandleARB programObj, GLuint index, GLsizei maxLength,
|
||||
GLsizei* length, GLint* size, GLenum* type, GLcharARB* name) {
|
||||
glGetActiveUniform(FromGLHandleARB(programObj), index, maxLength, length, size, type, name);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glGetUniformfvARB(GLhandleARB programObj, GLint location, GLfloat* params) {
|
||||
glGetUniformfv(FromGLHandleARB(programObj), location, params);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glGetUniformivARB(GLhandleARB programObj, GLint location, GLint* params) {
|
||||
glGetUniformiv(FromGLHandleARB(programObj), location, params);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glGetShaderSourceARB(GLhandleARB obj, GLsizei maxLength, GLsizei* length,
|
||||
GLcharARB* source) {
|
||||
glGetShaderSource(FromGLHandleARB(obj), maxLength, length, source);
|
||||
}
|
||||
|
||||
// ARB_vertex_shader's three entry points. The generic-attribute family that extension also
|
||||
// describes is spelled with the ARB_vertex_program names (glVertexAttribPointerARB and the rest),
|
||||
// which glext.h declares in that other block and which MobileGL does not advertise; nothing here
|
||||
// claims them.
|
||||
MOBILEGL_GL_API void glBindAttribLocationARB(GLhandleARB programObj, GLuint index, const GLcharARB* name) {
|
||||
glBindAttribLocation(FromGLHandleARB(programObj), index, name);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glGetActiveAttribARB(GLhandleARB programObj, GLuint index, GLsizei maxLength,
|
||||
GLsizei* length, GLint* size, GLenum* type, GLcharARB* name) {
|
||||
glGetActiveAttrib(FromGLHandleARB(programObj), index, maxLength, length, size, type, name);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API GLint glGetAttribLocationARB(GLhandleARB programObj, const GLcharARB* name) {
|
||||
return glGetAttribLocation(FromGLHandleARB(programObj), name);
|
||||
}
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, DeleteObjectARB, GLhandleARB obj) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, DeleteObjectARB, obj)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(GLhandleARB, GetHandleARB, GLenum pname) DECLARE_GL_FUNCTION_STUB_END(GLhandleARB, GetHandleARB, pname)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, DetachObjectARB, GLhandleARB containerObj, GLhandleARB attachedObj) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, DetachObjectARB, containerObj, attachedObj)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(GLhandleARB, CreateShaderObjectARB, GLenum shaderType) DECLARE_GL_FUNCTION_STUB_END(GLhandleARB, CreateShaderObjectARB, shaderType)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(GLhandleARB, CreateProgramObjectARB, void) DECLARE_GL_FUNCTION_STUB_END(GLhandleARB, CreateProgramObjectARB, )
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, AttachObjectARB, GLhandleARB containerObj, GLhandleARB obj) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, AttachObjectARB, containerObj, obj)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, UseProgramObjectARB, GLhandleARB programObj) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, UseProgramObjectARB, programObj)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, GetObjectParameterfvARB, GLhandleARB obj, GLenum pname, GLfloat* params) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, GetObjectParameterfvARB, obj, pname, params)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, GetObjectParameterivARB, GLhandleARB obj, GLenum pname, GLint* params) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, GetObjectParameterivARB, obj, pname, params)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, GetInfoLogARB, GLhandleARB obj, GLsizei maxLength, GLsizei* length, GLcharARB* infoLog) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, GetInfoLogARB, obj, maxLength, length, infoLog)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, GetAttachedObjectsARB, GLhandleARB containerObj, GLsizei maxCount, GLsizei* count, GLhandleARB* obj) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, GetAttachedObjectsARB, containerObj, maxCount, count, obj)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, NamedStringARB, GLenum type, GLint namelen, const GLchar* name, GLint strinen, const GLchar* string) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, NamedStringARB, type, namelen, name, strinen, string)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, DeleteNamedStringARB, GLint namelen, const GLchar* name) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, DeleteNamedStringARB, namelen, name)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, CompileShaderIncludeARB, GLuint shader, GLsizei count, const GLchar* const* path, const GLint* length) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, CompileShaderIncludeARB, shader, count, path, length)
|
||||
@@ -2042,141 +1708,6 @@ DECLARE_GL_FUNCTION_STUB_HEAD(void, VertexBlendEnviATI, GLenum pname, GLint para
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, VertexBlendEnvfATI, GLenum pname, GLfloat param) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, VertexBlendEnvfATI, pname, param)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, EGLImageTargetTexStorageEXT, GLenum target, GLeglImageOES image, const GLint* attrib_list) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, EGLImageTargetTexStorageEXT, target, image, attrib_list)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, EGLImageTargetTextureStorageEXT, GLuint texture, GLeglImageOES image, const GLint* attrib_list) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, EGLImageTargetTextureStorageEXT, texture, image, attrib_list)
|
||||
|
||||
// GL_OES_EGL_image.
|
||||
//
|
||||
// MEASURED, and the whole reason this block exists: libepoxy in kwin_wayland prints
|
||||
// No provider of glEGLImageTargetTexture2DOES found. Requires one of: GL_OES_EGL_image
|
||||
// and refuses the import path there - and that path is how the compositor's scene reaches the
|
||||
// display daemon's dma-bufs, i.e. how a Linux desktop gets onto the phone's screen. The EGL half is
|
||||
// real: eglCreateImageKHR builds an EGL_LINUX_DMA_BUF_EXT image that owns a dup() of every plane's
|
||||
// descriptor and carries that buffer's geometry and fourcc (MG_State/EGLState/Core.h). So a handle
|
||||
// that arrives here is resolvable, and what these two entry points do is exactly that: resolve it,
|
||||
// refuse what names nothing, and say ONCE what is not wired yet. What is not wired yet is the
|
||||
// render-server half - telling the server which texture a dma-buf backs, over the one channel that
|
||||
// can carry a descriptor across the container boundary - so a framebuffer built over an imported
|
||||
// texture is not complete until that lands. Pretending otherwise (attaching the image to a texture
|
||||
// object that has no storage behind it) would turn "not implemented" into "mysteriously black",
|
||||
// which is what the log line below is here to prevent.
|
||||
MOBILEGL_GL_API void glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image) {
|
||||
// 0x8D65 is GL_TEXTURE_EXTERNAL_OES, which the headers this file compiles against do not spell
|
||||
// out. It matters here MORE than GL_TEXTURE_2D does: a compositor that could not map an
|
||||
// imported dma-buf's format to a non-external one binds its image to THIS target, so refusing it
|
||||
// would turn "no format map yet" into an INVALID_ENUM the caller cannot act on (kwin 6.7.3 does
|
||||
// exactly that when EglDisplay::queryImportFormats() answers nothing).
|
||||
constexpr GLenum kTextureExternalOes = 0x8D65;
|
||||
if (target != GL_TEXTURE_2D && target != kTextureExternalOes) {
|
||||
MobileGL::MG_State::pGLContext->RecordError(
|
||||
MobileGL::ErrorCode::InvalidEnum,
|
||||
MobileGL::MakeUnique<MobileGL::GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"target is not a texture target this entry point takes."));
|
||||
return;
|
||||
}
|
||||
EGLint imageWidth = 0;
|
||||
EGLint imageHeight = 0;
|
||||
EGLint imageFourCC = 0;
|
||||
EGLint imagePlanes = 0;
|
||||
const MobileGL::Bool imageKnown =
|
||||
MobileGL::MG_State::pEGLContext != nullptr &&
|
||||
MobileGL::MG_State::pEGLContext->DescribeImage(reinterpret_cast<::EGLImage>(image), &imageWidth, &imageHeight,
|
||||
&imageFourCC, &imagePlanes);
|
||||
if (!imageKnown) {
|
||||
// A handle this side did not hand out: ARB/OES text puts that on INVALID_VALUE, and it is
|
||||
// the answer a caller can act on rather than a texture that renders nowhere.
|
||||
MobileGL::MG_State::pGLContext->RecordError(
|
||||
MobileGL::ErrorCode::InvalidValue,
|
||||
MobileGL::MakeUnique<MobileGL::GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"image is not an EGLImage this display created."));
|
||||
return;
|
||||
}
|
||||
MGLOG_W_ONCE("glEGLImageTargetTexture2DOES: taking target 0x%04x over an EGLImage of %dx%d fourcc 0x%08x "
|
||||
"(%d plane(s)) that this side holds; the render server has NOT been told which texture that "
|
||||
"dma-buf backs yet, so a framebuffer over this texture is not complete (the fd transport over "
|
||||
"the GBM socket and the server-side import are the next change)",
|
||||
target, imageWidth, imageHeight, imageFourCC, imagePlanes);
|
||||
|
||||
// AND NOW WIRE IT: a texture bound to an imported EGLImage has no storage on the render server,
|
||||
// and a framebuffer built over it there is not complete - kwin 6.7.3 aborts on its own
|
||||
// RenderTarget assertion right after this log line (measured twice). So the server is told which
|
||||
// buffer backs the texture: one message per plane, each carrying that plane's descriptor over the
|
||||
// session transport's SCM_RIGHTS channel. No session, or a transport without that channel, is a
|
||||
// refusal by name from ShareImportedDmaBuf - the texture simply keeps having no storage, which is
|
||||
// the honest state rather than a silent render into nothing.
|
||||
MGLOG_I("dma-buf import: entry (target=0x%04x, image=%p)", static_cast<unsigned>(target), static_cast<void*>(image));
|
||||
if (MobileGL::MG_State::pEGLContext != nullptr) {
|
||||
constexpr MobileGL::Int kDmaBufImportPlanes = 4;
|
||||
EGLint planeCount = 0;
|
||||
EGLint planeFds[kDmaBufImportPlanes] = {-1, -1, -1, -1};
|
||||
EGLint planeOffsets[kDmaBufImportPlanes] = {0, 0, 0, 0};
|
||||
EGLint planePitches[kDmaBufImportPlanes] = {0, 0, 0, 0};
|
||||
MobileGL::Uint64 planeModifiers[kDmaBufImportPlanes] = {0, 0, 0, 0};
|
||||
MobileGL::Bool planeHasModifier[kDmaBufImportPlanes] = {false, false, false, false};
|
||||
if (MobileGL::MG_State::pEGLContext->DescribeImagePlanes(
|
||||
reinterpret_cast<::EGLImage>(image), &planeCount, planeFds, planeOffsets, planePitches,
|
||||
planeModifiers, planeHasModifier, kDmaBufImportPlanes)) {
|
||||
// The texture the image was bound to. 0x8D65 has no TextureTarget member in this state
|
||||
// layer (nothing else here binds it), so the name is looked up through Texture2D and may
|
||||
// come back 0 - the server logs what it was told rather than guessing.
|
||||
MobileGL::Uint32 texName = 0;
|
||||
if (MobileGL::MG_State::pGLContext != nullptr) {
|
||||
const MobileGL::Int unit = MobileGL::MG_State::pGLContext->GetActiveTextureUnit();
|
||||
// THE EXTERNAL SLOT, which is where a compositor's imported dma-buf texture lives.
|
||||
const auto& bound = MobileGL::MG_State::pGLContext->GetTextureUnitObject(unit)
|
||||
.GetBindingSlot(MobileGL::TextureTarget::TextureExternalOES)
|
||||
.GetBoundObject();
|
||||
if (bound != nullptr) {
|
||||
texName = static_cast<MobileGL::Uint32>(bound->GetExternalIndex());
|
||||
// AN IMPORTED TEXTURE IS BACKED, SO IT IS COMPLETE. Without this the state layer
|
||||
// answers incompletely (TextureObjectBase::IsComplete only looks at the internal
|
||||
// format) and the compositor, having attached it to a framebuffer, reports
|
||||
// "framebuffer for dmabuf 0 is not complete" and stops before drawing anything.
|
||||
bound->SetInternalFormat(MobileGL::TextureInternalFormat::RGBA8);
|
||||
}
|
||||
}
|
||||
MGLOG_I("dma-buf import: textures resolved (texName=%u planes=%d), sharing", texName,
|
||||
static_cast<int>(planeCount));
|
||||
for (MobileGL::Int plane = 0; plane < planeCount; plane++) {
|
||||
if (planeFds[plane] < 0) continue;
|
||||
MGLOG_I("dma-buf import: sharing plane %d fd=%d", static_cast<int>(plane), planeFds[plane]);
|
||||
(void)MobileGL::MG_Remote::Client::ShareImportedDmaBuf(
|
||||
static_cast<MobileGL::Uint32>(target), texName, static_cast<MobileGL::Uint32>(imageWidth),
|
||||
static_cast<MobileGL::Uint32>(imageHeight), static_cast<MobileGL::Uint32>(imageFourCC),
|
||||
static_cast<MobileGL::Uint32>(plane), static_cast<MobileGL::Uint32>(planeCount), planeFds[plane],
|
||||
planePitches[plane], planeOffsets[plane], planeModifiers[plane], planeHasModifier[plane]);
|
||||
MGLOG_I("dma-buf import: plane %d shared", static_cast<int>(plane));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image) {
|
||||
if (target != GL_RENDERBUFFER) {
|
||||
MobileGL::MG_State::pGLContext->RecordError(
|
||||
MobileGL::ErrorCode::InvalidEnum,
|
||||
MobileGL::MakeUnique<MobileGL::GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"target is not GL_RENDERBUFFER."));
|
||||
return;
|
||||
}
|
||||
EGLint imageWidth = 0;
|
||||
EGLint imageHeight = 0;
|
||||
EGLint imageFourCC = 0;
|
||||
EGLint imagePlanes = 0;
|
||||
const MobileGL::Bool imageKnown =
|
||||
MobileGL::MG_State::pEGLContext != nullptr &&
|
||||
MobileGL::MG_State::pEGLContext->DescribeImage(reinterpret_cast<::EGLImage>(image), &imageWidth, &imageHeight,
|
||||
&imageFourCC, &imagePlanes);
|
||||
if (!imageKnown) {
|
||||
MobileGL::MG_State::pGLContext->RecordError(
|
||||
MobileGL::ErrorCode::InvalidValue,
|
||||
MobileGL::MakeUnique<MobileGL::GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"image is not an EGLImage this display created."));
|
||||
return;
|
||||
}
|
||||
MGLOG_W_ONCE("glEGLImageTargetRenderbufferStorageOES: the renderbuffer takes an EGLImage of %dx%d fourcc "
|
||||
"0x%08x; the render-server half of the import is the next change, exactly as for the texture "
|
||||
"entry point beside this one",
|
||||
imageWidth, imageHeight, imageFourCC);
|
||||
}
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, UniformBufferEXT, GLuint program, GLint location, GLuint buffer) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, UniformBufferEXT, program, location, buffer)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(GLint, GetUniformBufferSizeEXT, GLuint program, GLint location) DECLARE_GL_FUNCTION_STUB_END(GLint, GetUniformBufferSizeEXT, program, location)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(GLintptr, GetUniformOffsetEXT, GLuint program, GLint location) DECLARE_GL_FUNCTION_STUB_END(GLintptr, GetUniformOffsetEXT, program, location)
|
||||
|
||||
@@ -100,13 +100,6 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
}
|
||||
|
||||
Bool HasDefinedAttachment(const MG_State::GLState::FramebufferObject& framebufferObject) {
|
||||
// NOT gated on the host frame, and that is deliberate: this only decides the ERROR CODE
|
||||
// once completeness has already failed (CheckFramebufferStatus_State asks
|
||||
// CheckCompleteness first), and the imported dma-buf's attachment is counted as valid
|
||||
// THERE (MG_State/GLState/FramebufferState/FramebufferObject.cpp, whose gate lands before
|
||||
// its own validity test for exactly this reason). Touching it here would add a second
|
||||
// place that has to know the backend's frame - and the frontend knowing that fact is the
|
||||
// compromise the completeness comment already names the end of.
|
||||
for (const auto& attachment : framebufferObject.GetAllAttachmentObjects()) {
|
||||
if (attachment.IsValid() && !attachment.IsEmpty()) {
|
||||
return true;
|
||||
@@ -618,9 +611,7 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
|
||||
const auto expectedTextureTarget = MG_Util::ConvertTextureUploadTargetToTextureTarget(textureUploadTarget);
|
||||
if (expectedTextureTarget == TextureTarget::Unknown ||
|
||||
(textureObject->GetTarget() != expectedTextureTarget &&
|
||||
!(textureObject->GetTarget() == TextureTarget::TextureExternalOES &&
|
||||
expectedTextureTarget == TextureTarget::Texture2D))) {
|
||||
textureObject->GetTarget() != expectedTextureTarget) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidOperation,
|
||||
MakeUnique<GenericErrorInfo>(
|
||||
@@ -1391,9 +1382,7 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
|
||||
const auto expectedTextureTarget = MG_Util::ConvertTextureUploadTargetToTextureTarget(textureUploadTarget);
|
||||
if (expectedTextureTarget == TextureTarget::Unknown ||
|
||||
(textureObject->GetTarget() != expectedTextureTarget &&
|
||||
!(textureObject->GetTarget() == TextureTarget::TextureExternalOES &&
|
||||
expectedTextureTarget == TextureTarget::Texture2D))) {
|
||||
textureObject->GetTarget() != expectedTextureTarget) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidOperation,
|
||||
MakeUnique<GenericErrorInfo>(
|
||||
@@ -1543,9 +1532,7 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
|
||||
const auto expectedTextureTarget = MG_Util::ConvertTextureUploadTargetToTextureTarget(textureUploadTarget);
|
||||
if (expectedTextureTarget == TextureTarget::Unknown ||
|
||||
(textureObject->GetTarget() != expectedTextureTarget &&
|
||||
!(textureObject->GetTarget() == TextureTarget::TextureExternalOES &&
|
||||
expectedTextureTarget == TextureTarget::Texture2D))) {
|
||||
textureObject->GetTarget() != expectedTextureTarget) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidOperation,
|
||||
MakeUnique<GenericErrorInfo>(
|
||||
|
||||
@@ -41,18 +41,6 @@
|
||||
// call sites below are declarations only, exactly as the frontend's mutators are.
|
||||
#include <MG_Pipe/PipeMutation.h>
|
||||
|
||||
// P9 (W1, MG_Remote/CONTRACT-P9.md §1): AN UNPACK SOURCE IS READ FROM THE BUFFER'S CLIENT SHADOW,
|
||||
// and under a transport a GPU write into that buffer - a read_pixels_to_buffer, which is how a
|
||||
// glReadPixels into a pack buffer now crosses, or a shader store - reaches the shadow only through
|
||||
// SyncGpuWrites, exactly as glMapBufferRange and glGetBufferSubData already do. Monolith keeps its
|
||||
// read as it was: its ReadPixels maps the driver PBO back into the shadow inside the call, and the
|
||||
// pull build compiles this to nothing (G1).
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
#define MGL_SYNC_PIXEL_UNPACK_SOURCE(buffer) do { if (MG_Config::Transport != MG_Config::TransportMode::Monolith) (buffer)->SyncGpuWrites(); } while (0)
|
||||
#else
|
||||
#define MGL_SYNC_PIXEL_UNPACK_SOURCE(buffer) ((void)0)
|
||||
#endif
|
||||
|
||||
namespace MobileGL::MG_Impl::GLImpl {
|
||||
static SharedPtr<MG_State::GLState::ITextureObject> nullTextureObject;
|
||||
static UnorderedMap<Uint, Bool> g_autoGenerateMipmapByTextureId;
|
||||
@@ -1785,7 +1773,6 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
const auto& unpackBuffer =
|
||||
MG_State::pGLContext->GetBufferBindingSlot(BufferTarget::PixelUnpack).GetBoundObject();
|
||||
if (!unpackBuffer) return data;
|
||||
MGL_SYNC_PIXEL_UNPACK_SOURCE(unpackBuffer);
|
||||
return reinterpret_cast<const char*>(unpackBuffer->MappedData()) + reinterpret_cast<SizeT>(data);
|
||||
}
|
||||
|
||||
@@ -1832,7 +1819,6 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
const auto& pixelUnpackBufferObject =
|
||||
MG_State::pGLContext->GetBufferBindingSlot(BufferTarget::PixelUnpack).GetBoundObject();
|
||||
if (pixelUnpackBufferObject) {
|
||||
MGL_SYNC_PIXEL_UNPACK_SOURCE(pixelUnpackBufferObject);
|
||||
originalPixels = reinterpret_cast<const char*>(pixelUnpackBufferObject->MappedData()) +
|
||||
reinterpret_cast<SizeT>(pixels);
|
||||
}
|
||||
@@ -1955,7 +1941,6 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
if (pixelUnpackBufferObject) {
|
||||
MGLOG_D("TexSubImage2D_State: Using Pixel Unpack Buffer Object ID: %u",
|
||||
pixelUnpackBufferObject->GetExternalIndex());
|
||||
MGL_SYNC_PIXEL_UNPACK_SOURCE(pixelUnpackBufferObject);
|
||||
originalPixels = reinterpret_cast<const char*>(pixelUnpackBufferObject->MappedData()) +
|
||||
reinterpret_cast<SizeT>(pixels);
|
||||
}
|
||||
@@ -2045,7 +2030,6 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
const auto& pixelUnpackBufferObject =
|
||||
MG_State::pGLContext->GetBufferBindingSlot(BufferTarget::PixelUnpack).GetBoundObject();
|
||||
if (pixelUnpackBufferObject) {
|
||||
MGL_SYNC_PIXEL_UNPACK_SOURCE(pixelUnpackBufferObject);
|
||||
originalPixels = reinterpret_cast<const char*>(pixelUnpackBufferObject->MappedData()) +
|
||||
reinterpret_cast<SizeT>(pixels);
|
||||
}
|
||||
@@ -2551,7 +2535,6 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
if (pixelUnpackBufferObject) {
|
||||
MGLOG_D("%s: Using Pixel Unpack Buffer Object ID: %u", __func__,
|
||||
pixelUnpackBufferObject->GetExternalIndex());
|
||||
MGL_SYNC_PIXEL_UNPACK_SOURCE(pixelUnpackBufferObject);
|
||||
originalPixels = reinterpret_cast<const char*>(pixelUnpackBufferObject->MappedData()) +
|
||||
reinterpret_cast<SizeT>(pixels);
|
||||
}
|
||||
@@ -2699,7 +2682,6 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
if (pixelUnpackBufferObject) {
|
||||
MGLOG_D("%s: Using Pixel Unpack Buffer Object ID: %u", __func__,
|
||||
pixelUnpackBufferObject->GetExternalIndex());
|
||||
MGL_SYNC_PIXEL_UNPACK_SOURCE(pixelUnpackBufferObject);
|
||||
originalPixels = reinterpret_cast<const char*>(pixelUnpackBufferObject->MappedData()) +
|
||||
reinterpret_cast<SizeT>(pixels);
|
||||
}
|
||||
@@ -2818,7 +2800,6 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
const auto& pixelUnpackBufferObject =
|
||||
MG_State::pGLContext->GetBufferBindingSlot(BufferTarget::PixelUnpack).GetBoundObject();
|
||||
if (pixelUnpackBufferObject) {
|
||||
MGL_SYNC_PIXEL_UNPACK_SOURCE(pixelUnpackBufferObject);
|
||||
originalPixels = reinterpret_cast<const char*>(pixelUnpackBufferObject->MappedData()) +
|
||||
reinterpret_cast<SizeT>(pixels);
|
||||
}
|
||||
@@ -6281,7 +6262,6 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
const auto& pixelUnpackBufferObject =
|
||||
MG_State::pGLContext->GetBufferBindingSlot(BufferTarget::PixelUnpack).GetBoundObject();
|
||||
if (pixelUnpackBufferObject) {
|
||||
MGL_SYNC_PIXEL_UNPACK_SOURCE(pixelUnpackBufferObject);
|
||||
originalPixels = reinterpret_cast<const char*>(pixelUnpackBufferObject->MappedData()) +
|
||||
reinterpret_cast<SizeT>(pixels);
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ namespace MobileGL::MG_Impl::GLXImpl {
|
||||
}
|
||||
|
||||
struct ContextObject {
|
||||
::Display* XDisplay = nullptr;
|
||||
Display* XDisplay = nullptr;
|
||||
EGLDisplay Display = EGL_NO_DISPLAY;
|
||||
EGLConfig Config = nullptr;
|
||||
EGLContext Context = EGL_NO_CONTEXT;
|
||||
|
||||
@@ -869,55 +869,6 @@ namespace MobileGL::MG_Impl {
|
||||
GETPROC(glNamedBufferPageCommitmentARB, name);
|
||||
GETPROC(glTexPageCommitmentARB, name);
|
||||
GETPROC(glTexBufferARB, name);
|
||||
// ARB_shader_objects and ARB_vertex_shader, by name, because a name is the only way an
|
||||
// application ever asks for an extension entry point. Measured path: kwin_wayland resolves GL
|
||||
// through libepoxy, and libepoxy asks eglGetProcAddress -> EGLImpl::GetProcAddress -> this
|
||||
// table. Before these lines the callers that need the extension whose STRINGS make
|
||||
// checkSupported() pass got a nullptr for every function of it - dlsym on the library found
|
||||
// them, this table did not. The strings and the implementations are advertised from
|
||||
// MG_Impl/GLImpl/Exporting/Definitions.cpp and the two BackendObject_* extension lists.
|
||||
GETPROC(glDeleteObjectARB, name);
|
||||
GETPROC(glGetHandleARB, name);
|
||||
GETPROC(glDetachObjectARB, name);
|
||||
GETPROC(glCreateShaderObjectARB, name);
|
||||
GETPROC(glShaderSourceARB, name);
|
||||
GETPROC(glCompileShaderARB, name);
|
||||
GETPROC(glCreateProgramObjectARB, name);
|
||||
GETPROC(glAttachObjectARB, name);
|
||||
GETPROC(glLinkProgramARB, name);
|
||||
GETPROC(glUseProgramObjectARB, name);
|
||||
GETPROC(glValidateProgramARB, name);
|
||||
GETPROC(glUniform1fARB, name);
|
||||
GETPROC(glUniform2fARB, name);
|
||||
GETPROC(glUniform3fARB, name);
|
||||
GETPROC(glUniform4fARB, name);
|
||||
GETPROC(glUniform1iARB, name);
|
||||
GETPROC(glUniform2iARB, name);
|
||||
GETPROC(glUniform3iARB, name);
|
||||
GETPROC(glUniform4iARB, name);
|
||||
GETPROC(glUniform1fvARB, name);
|
||||
GETPROC(glUniform2fvARB, name);
|
||||
GETPROC(glUniform3fvARB, name);
|
||||
GETPROC(glUniform4fvARB, name);
|
||||
GETPROC(glUniform1ivARB, name);
|
||||
GETPROC(glUniform2ivARB, name);
|
||||
GETPROC(glUniform3ivARB, name);
|
||||
GETPROC(glUniform4ivARB, name);
|
||||
GETPROC(glUniformMatrix2fvARB, name);
|
||||
GETPROC(glUniformMatrix3fvARB, name);
|
||||
GETPROC(glUniformMatrix4fvARB, name);
|
||||
GETPROC(glGetObjectParameterfvARB, name);
|
||||
GETPROC(glGetObjectParameterivARB, name);
|
||||
GETPROC(glGetInfoLogARB, name);
|
||||
GETPROC(glGetAttachedObjectsARB, name);
|
||||
GETPROC(glGetUniformLocationARB, name);
|
||||
GETPROC(glGetActiveUniformARB, name);
|
||||
GETPROC(glGetUniformfvARB, name);
|
||||
GETPROC(glGetUniformivARB, name);
|
||||
GETPROC(glGetShaderSourceARB, name);
|
||||
GETPROC(glBindAttribLocationARB, name);
|
||||
GETPROC(glGetActiveAttribARB, name);
|
||||
GETPROC(glGetAttribLocationARB, name);
|
||||
GETPROC(glDepthRangeArraydvNV, name);
|
||||
GETPROC(glDepthRangeIndexeddNV, name);
|
||||
GETPROC(glBlendBarrierKHR, name);
|
||||
@@ -935,8 +886,6 @@ namespace MobileGL::MG_Impl {
|
||||
GETPROC(glBeginPerfMonitorAMD, name);
|
||||
GETPROC(glEndPerfMonitorAMD, name);
|
||||
GETPROC(glGetPerfMonitorCounterDataAMD, name);
|
||||
GETPROC(glEGLImageTargetTexture2DOES, name);
|
||||
GETPROC(glEGLImageTargetRenderbufferStorageOES, name);
|
||||
GETPROC(glEGLImageTargetTexStorageEXT, name);
|
||||
GETPROC(glEGLImageTargetTextureStorageEXT, name);
|
||||
GETPROC(glLabelObjectEXT, name);
|
||||
|
||||
@@ -582,25 +582,12 @@ namespace MobileGL::MG_Pipe {
|
||||
Optional<MGPipeInputField> Corrupt;
|
||||
String CorruptKnob; // the MOBILEGL_PIPE_VERIFY_CORRUPT value the last arm saw
|
||||
std::atomic<Uint64> Divergences{0};
|
||||
Uint64 Summarised = 0; // how many of them the summary line has reported so far
|
||||
// THE SUMMARY IS WRITTEN FROM MobileGL::Destroy, NOT FROM HERE (V1 fix round 2). This
|
||||
// is a namespace-scope static, so this destructor runs from __run_exit_handlers, AFTER
|
||||
// DestroyImpl has called MG_Util::Debug::Close(). Close nulls the role's sink; Log.cpp's
|
||||
// WriteToFile then re-runs InitFile() for the next line, and InitFile opens the role's
|
||||
// file with "w". So the one line this destructor wrote was the only line the client half
|
||||
// of every FATAL=0 run kept - 121 bytes, the summary itself, with the entry compare's
|
||||
// own reports, the arming line and the config dump gone (and the monolith arm's
|
||||
// VerifyCorrupted. log wiped the same way). MGPipeVerifyFlushSummary runs before Close,
|
||||
// so by the time this destructor runs there is nothing new to say and it says nothing;
|
||||
// the arm is kept for a process that never called Destroy, where no Close ran and the
|
||||
// line lands in the still-open file as it always did.
|
||||
~VerifyState() { FlushSummary(); }
|
||||
void FlushSummary() {
|
||||
~VerifyState() {
|
||||
const Uint64 count = Divergences.load(std::memory_order_relaxed);
|
||||
if (count == 0 || count == Summarised) return;
|
||||
Summarised = count;
|
||||
MGLOG_E("MGPipe: verify summary - %llu divergence(s) survived MOBILEGL_PIPE_VERIFY_FATAL=0",
|
||||
static_cast<unsigned long long>(count));
|
||||
if (count != 0) {
|
||||
MGLOG_E("MGPipe: verify summary - %llu divergence(s) survived MOBILEGL_PIPE_VERIFY_FATAL=0",
|
||||
static_cast<unsigned long long>(count));
|
||||
}
|
||||
}
|
||||
};
|
||||
VerifyState g_verify;
|
||||
@@ -658,57 +645,6 @@ namespace MobileGL::MG_Pipe {
|
||||
MGPipeInputField differing = MGPipeInputField::kFieldCount;
|
||||
if (!MGPipeVerifyInputs(inputs, g_snapshot, mask, &differing)) ReportDivergence(differing, "entry");
|
||||
}
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// ---- P7 wave 3 (V1): the compare-at-read oracle inside the server's read_pixels ----
|
||||
//
|
||||
// WHAT THE SPLIT ARM FOUND THE FIRST TIME VERIFY AND SPLIT SHARED A BUILD. Every
|
||||
// glReadPixels on the inproc arm - 8530 reads over 220 of the lane's 1068 entries, and the
|
||||
// VerifySplitArming. entries on both backends - aborted with
|
||||
//
|
||||
// MGPipe: verify read of GetPixelStoreParameters (index 0, 0) differs from the live context
|
||||
// MGPipe: Fatal{PipeVerifyDiffer, "GetPixelStoreParameters@ReadPixels", verb=6, where=read}
|
||||
//
|
||||
// on the server's apply thread, and it was the ONLY field that diverged anywhere in the
|
||||
// lane. The mechanism is ID-49 and is deliberate: the pack state never shapes the wire
|
||||
// answer, so MG_Remote/Server/PipeApplier.cpp's read_pixels body writes a NEUTRAL pack
|
||||
// into the applier's copy of the field (MGPipeApplySetPixelPackState), makes the backend
|
||||
// read, and restores the pushed one; the client then scatters the tight reply through the
|
||||
// application's own pack state. The frontend context - this comparator's oracle - still
|
||||
// holds the application's pack (Alignment 4 by default), so the backend's read of the
|
||||
// pack half answers {Alignment 1} where the live context says {Alignment 4}. On the
|
||||
// monolith arm the same neutral window is opened on the frontend context itself
|
||||
// (GL_Texture.cpp's ScopedNeutralPackState), which is why the monolith lane never saw it.
|
||||
//
|
||||
// SO THE ORACLE, NOT THE RULE, IS WHAT CHANGES, AND ONLY IN THAT WINDOW: under a server
|
||||
// stamp, on the ReadPixels verb, the pack half's expected value is the neutral pack the
|
||||
// applier reads with, and the UNPACK half and every other field keep the live context as
|
||||
// their oracle. A server read of the pack half that is neither the application's value
|
||||
// nor exactly the neutral one is still a divergence and still Fatal.
|
||||
//
|
||||
// WHAT THIS GIVES UP IS ONE VALUE, NOT THE FIELD (corrected in P7 wave 3's V1 fix round;
|
||||
// the first statement of it here said the comparator could no longer see a client that
|
||||
// pushed a WRONG pack state at all, which is too broad). PipeApplier.cpp's read_pixels
|
||||
// reads `savedPack` THROUGH THE ACCESSOR - and therefore through this hook - BEFORE it
|
||||
// installs the neutral value, so the pushed pack has already been compared against the
|
||||
// live one by then: a correct push is equal and returns, and a wrong push that is not
|
||||
// exactly the neutral pack fails both compares and is still Fatal. The blind spot is the
|
||||
// single value {SwapBytes 0, LSBFirst 0, RowLength 0, ImageHeight 0, Skip* 0, Alignment 1},
|
||||
// and only while the application's own pack differs from it. The client-side scatter that
|
||||
// consumes the real pack is covered by the readback matrix cases, which compare bytes,
|
||||
// not fields.
|
||||
Bool ServerReadsInsideTheNeutralPackWindow(const PipeInputs& self, MGPipeInputField field) {
|
||||
return field == MGPipeInputField::GetPixelStoreParameters && self.ServerStampedVerb() &&
|
||||
self.CurrentVerb() == MGPipeVerb::ReadPixels;
|
||||
}
|
||||
|
||||
// The constant itself is MG_Pipe's (MGPipeTypes.h's MGPipeNeutralReadPixelsPack), which is
|
||||
// the same function MG_Remote/Server/PipeApplier.cpp's read_pixels installs. It used to be
|
||||
// re-typed here, field for field, to avoid reaching into MG_Remote/Server from MG_Impl -
|
||||
// but the owner of MGPPixelPackState is MG_Pipe, both sites already include it, and a
|
||||
// drift between the two spellings would have cost a false divergence rather than a build
|
||||
// break.
|
||||
#endif // MOBILEGL_BUILD_DISAGGREGATED
|
||||
#endif // MOBILEGL_PIPE_VERIFY
|
||||
} // namespace
|
||||
|
||||
@@ -743,77 +679,13 @@ namespace MobileGL::MG_Pipe {
|
||||
// never recurses (and never reports the inner read against a half-copied scratch).
|
||||
g_verify.InHook = true;
|
||||
MGPipeFillAccess::CopyField(g_readScratch, *ctx, field);
|
||||
// P7 wave 3 (V1): NEGATIVE CONTROL A REACHES THIS ARM TOO. Until this line the knob only
|
||||
// ever perturbed EntryCompare's snapshot, so every red it could produce said `where=entry`
|
||||
// and was produced on the CLIENT thread - which left the compare-at-read hook, the arm
|
||||
// that runs on the server's apply thread and does the whole of the split lane's per-read
|
||||
// work, with no falsifier at all: a hook that had stopped comparing would have looked
|
||||
// exactly like a hook with nothing to report. The perturbation goes on the ORACLE, for
|
||||
// EntryCompare's reason: the arm under test is the stored value, so corrupting THAT would
|
||||
// be testing the corruption.
|
||||
//
|
||||
// WHICH READ THIS BLOCK TURNS RED (V1 fix round 2). The server reads the pack field TWICE
|
||||
// inside the ReadPixels verb window, and both reads sit inside
|
||||
// ServerReadsInsideTheNeutralPackWindow below (the verb stamp is up for the whole apply):
|
||||
// PipeApplier::read_pixels saves the application's pack through the accessor BEFORE it
|
||||
// installs the neutral one, and the backend's ReadPixels reads the field AFTER. This block
|
||||
// is what turns the FIRST of them red: at that read `self` still holds the application's
|
||||
// pack, so the first compare only reaches the window if this perturbation made it differ,
|
||||
// and inside the window the application's pack against the neutral oracle differs on its
|
||||
// own. It does nothing for the second read - `self` IS the neutral pack there - which is
|
||||
// what the re-application inside the window is for.
|
||||
if (g_verify.Corrupt && *g_verify.Corrupt == field) {
|
||||
MGPipeApplyVerifyCorruption(g_readScratch, field);
|
||||
}
|
||||
const Bool equal = MGPipeInputsFieldEqual(field, self, g_readScratch);
|
||||
g_verify.InHook = false;
|
||||
if (equal) return;
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (ServerReadsInsideTheNeutralPackWindow(self, field)) {
|
||||
// The live context is the application's pack state and the server is, by ID-49,
|
||||
// reading with the neutral one; the oracle for THAT HALF is the neutral pack, and
|
||||
// every other byte of the field still has to match the live context.
|
||||
g_verify.InHook = true;
|
||||
PipeInputs::VisitStorage(field, g_readScratch, g_readScratch, [](auto& live, auto&) {
|
||||
if constexpr (std::is_same_v<std::remove_reference_t<decltype(live)>, PixelStoreParameters[2]>) {
|
||||
live[0] = MGPipeNeutralReadPixelsPack().Pack;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
// AND THE CONTROL IS RE-APPLIED, because the overwrite above replaces the pack half
|
||||
// WHOLESALE - the corruption included, since CorruptStorage perturbs an array's FIRST
|
||||
// ELEMENT and the pack half is element 0. This is the block for the POST-INSTALL read
|
||||
// (the backend's ReadPixels, after PipeApplier::read_pixels installed the neutral pack
|
||||
// into gPipeInputs): there `self` is the neutral pack, the overwrite just made the
|
||||
// oracle equal to it, and only a perturbation applied AFTER the overwrite can make
|
||||
// that compare differ - the block above cannot reach it. Without this line the one
|
||||
// window in which this arm is most load-bearing (the server's read_pixels, 8530 reads
|
||||
// over 220 of the lane's entries) would be the one window MOBILEGL_PIPE_VERIFY_CORRUPT=
|
||||
// GetPixelStoreParameters cannot turn red - and a control that accepted ONE report
|
||||
// would never notice, because the saved-pack read still reports through the block
|
||||
// above. The VerifySplitReadCorrupted. entries and the CI step therefore require at
|
||||
// least TWO `where=read` reports in the server half (V1 fix round 2). Measured: 3 on
|
||||
// DirectGLES (its backend reads the field twice after the install) / 2 on
|
||||
// DirectVulkan; without this block both drop to 1, without the block above
|
||||
// DirectVulkan drops to 1 while DirectGLES's two post-install reports keep it at 2 -
|
||||
// so this block is falsified on both backends and the one above on DirectVulkan.
|
||||
if (g_verify.Corrupt && *g_verify.Corrupt == field) {
|
||||
MGPipeApplyVerifyCorruption(g_readScratch, field);
|
||||
}
|
||||
const Bool equalToTheNeutralPack = MGPipeInputsFieldEqual(field, self, g_readScratch);
|
||||
g_verify.InHook = false;
|
||||
if (equalToTheNeutralPack) return;
|
||||
}
|
||||
#endif
|
||||
MGLOG_E("MGPipe: verify read of %s (index %u, %u) differs from the live context", kMGPipeInputFieldNames[index],
|
||||
index0, index1);
|
||||
ReportDivergence(field, "read");
|
||||
}
|
||||
|
||||
// PipeInputs.h. The FATAL=0 summary, written while the role's log is still open:
|
||||
// MobileGL::Destroy calls this right before MG_Util::Debug::Close() - see VerifyState for why
|
||||
// the static destructor cannot be the writer.
|
||||
void MGPipeVerifyFlushSummary() { g_verify.FlushSummary(); }
|
||||
#endif // MOBILEGL_PIPE_VERIFY
|
||||
|
||||
// ---- push on mutation (P1 lane finding F2) ----
|
||||
@@ -1112,24 +984,8 @@ namespace MobileGL::MG_Pipe {
|
||||
// below and this aborts by name on the first glBufferData that carries data.
|
||||
const Uint64 before = MG_Remote::Client::ClientWireRecordsEmitted();
|
||||
MGPipeEmitResourceSubData(buffer, 0, static_cast<SizeT>(buffer.GetSize()));
|
||||
// EXCEPT ON A SESSION THAT HAS STOPPED CARRYING RECORDS (P12). Once the device-lost
|
||||
// latch is set every verb is DECLINED by design (CONTRACT-P6 5.3, ClientSession.cpp
|
||||
// :1837) - the resource_subdata above included - so "it emitted nothing" is the latch
|
||||
// working, not bytes this client forgot to carry: there is no server left for them to
|
||||
// exist on, and P12's own exit gate (a) is that killing the server gives a CLEAN
|
||||
// device-lost latch rather than a corpse. Aborting here turned every clean loss into a
|
||||
// client SIGABRT at its next glBufferData that carries data.
|
||||
//
|
||||
// THE SELF-CHECK KEEPS ITS FULL FORCE ON A LIVE SESSION, which is the case it was
|
||||
// written for: there, a follow-up that emits nothing is still the R-13.3 gap it names
|
||||
// - and DeviceLost() is false.
|
||||
if (MG_Remote::Client::ClientWireRecordsEmitted() == before &&
|
||||
!MG_Remote::Client::ClientSession::DeviceLost()) {
|
||||
// UncarriedInitialBytes, not a second word for the same family: WireTables.cpp:418
|
||||
// already dies of exactly this - a respecify that crossed with no initial bytes -
|
||||
// under that name, and two words for one family is the vocabulary drift a6
|
||||
// censused and 5.2's .def exists to bound (P7 wave 0).
|
||||
MGLOG_F("MGPipe: Fatal{UncarriedInitialBytes, \"resource_respecify\"} - the "
|
||||
if (MG_Remote::Client::ClientWireRecordsEmitted() == before) {
|
||||
MGLOG_F("MGPipe: Fatal{InitialBytesNotCarried, \"resource_respecify\"} - the "
|
||||
"respecify crossed with initialBytes = nullptr (R-13.3) and the "
|
||||
"resource_subdata records that were supposed to follow it emitted "
|
||||
"NOTHING, so %llu bytes of initial content exist on no side of the wire",
|
||||
@@ -1217,14 +1073,6 @@ namespace MobileGL::MG_Pipe {
|
||||
#endif
|
||||
// The application's STAGING store, valid for the duration of the call only.
|
||||
MGPipeRouteBufferSubDataResident(record, base + (at - offset), length);
|
||||
// P7 wave 2 package C, OQ-10: `rsd=`, counted HERE rather than at the call
|
||||
// above so that one glBufferSubData cut into N chunk records counts N. See
|
||||
// PipeStats.h's CallClass::ResidentSubDataEmissions for why the count is the
|
||||
// only thing that can tell this arm from the in-place memcpy beside it.
|
||||
if (MG_Util::PipeStats::Enabled()) {
|
||||
MG_Util::PipeStats::AddCalls(
|
||||
MG_Util::PipeStats::CallClass::ResidentSubDataEmissions, 1);
|
||||
}
|
||||
}, MGPipeContentChunkCap());
|
||||
if (!encodable) {
|
||||
MGLOG_E_ONCE("MGPipe: buffer_subdata_resident range [%llu, +%llu) on buffer %u cannot be encoded",
|
||||
@@ -1403,14 +1251,6 @@ namespace MobileGL::MG_Pipe {
|
||||
|
||||
// P5e (ra), CONTRACT-P5E §2.5. Declared in PipeMutation.h; see there for why it is not a
|
||||
// ClientSession call at the GL entry point.
|
||||
void MGPipeClientFlush() {
|
||||
if (MG_Config::Transport == MG_Config::TransportMode::Monolith) return;
|
||||
if (MG_Remote::Client::RunsAsTheServerRole()) return;
|
||||
if (MG_Remote::Client::ClientSession* session = MG_Remote::Client::ClientSession::Active()) {
|
||||
session->Flush();
|
||||
}
|
||||
}
|
||||
|
||||
void MGPipeClientFinish() {
|
||||
if (MG_Config::Transport == MG_Config::TransportMode::Monolith) return;
|
||||
if (MG_Remote::Client::RunsAsTheServerRole()) return;
|
||||
@@ -1614,44 +1454,79 @@ namespace MobileGL::MG_Pipe {
|
||||
// above: with a dependency unmet the client emits NOTHING for that family and the legacy
|
||||
// pull path runs untouched, on both sides of the boundary.
|
||||
//
|
||||
// THE TABLE IS WRITTEN ONCE, IN MG_Pipe/SubsystemDeps.def, and every one of its rows is
|
||||
// the client mirror of the refusal Espryt already implements, bit for bit and
|
||||
// non-transitively - the two must say the SAME thing, because a client that withheld more
|
||||
// than the server refuses would leave the server's handle arm live with no records to
|
||||
// read, and a client that withheld less is the defect above.
|
||||
//
|
||||
// THIS FILE USED TO HOLD ITS OWN COPY of the four P4a rows (P3b/P4b R-5 found six
|
||||
// statements of one rule and two of them drifted). The rows moved to the .def with R-5
|
||||
// and this reader was left pointing at the copy deliberately, because PipeFill.cpp is the
|
||||
// contract package's file for the phase; wave 2-D package D3 switches it over.
|
||||
//
|
||||
// THE ARGUMENT IS MASKED TO kMGPipeP4aFamilySubsystems, AND THAT IS THE WHOLE DIFFERENCE
|
||||
// BETWEEN A REWRITE AND A BEHAVIOUR CHANGE. The .def carries SIX rows; the table deleted
|
||||
// from here carried FOUR, and this predicate is `wants()`'s fourth conjunct for P4a's
|
||||
// families only. Reading all six unmasked would make the CLIENT withhold bit 8's
|
||||
// vertex-input emissions at a mask with bit 7 clear - P3a's own rule, which this gate has
|
||||
// never narrowed and which TextureEmitTest's
|
||||
// EveryDKTwoDependencyRowGatesItsOwnFamilyAndTheMirrorPairsStayLive pins by name ("bit 8
|
||||
// alone, with bit 7 clear: P3a's own rule, which this table must not touch"). Bit 13 is
|
||||
// not narrowed here either; it asks the table for itself in P5eFamilyIsLive below,
|
||||
// because bit 13's conjunct is bit 13's own. So the ROWS now come from one place and WHO
|
||||
// each gate speaks for is still each gate's.
|
||||
//
|
||||
// The P4a-specific COVERAGE assertion stays for the same reason: a fifth P4a family
|
||||
// without a row in the .def has to be a compile error, not a silent "depends on nothing".
|
||||
// THE TABLE IS WRITTEN ONCE, HERE, and every one of its rows is the client mirror of the
|
||||
// refusal Espryt already implements, bit for bit and non-transitively - the two must say
|
||||
// the SAME thing, because a client that withheld more than the server refuses would
|
||||
// leave the server's handle arm live with no records to read, and a client that withheld
|
||||
// less is the defect above.
|
||||
struct P4aFamilyDependencyRow {
|
||||
Uint64 Family; // exactly one bit, and it is one of kMGPipeP4aFamilySubsystems
|
||||
Uint64 Requires; // the bits MOBILEGL_PIPE_PUSH must ALSO carry for it to be live
|
||||
};
|
||||
|
||||
inline constexpr P4aFamilyDependencyRow kMGPipeP4aFamilyDependencies[] = {
|
||||
// BIT 9 REQUIRES BIT 10. Every MGPSurface::Res in a set_framebuffer_state record
|
||||
// names a Texture or a Renderbuffer handle, and only bit 10 populates those two slot
|
||||
// tables (Managers.cpp ResolveFramebufferSubsystemArm).
|
||||
{kMGPipeSubsystemFramebuffer, kMGPipeSubsystemTextureResources},
|
||||
|
||||
// BIT 10 REQUIRES BIT 7 - a buffer texture's MGPResourceDesc::BufferForTexBuffer
|
||||
// names a Buffer handle and only bit 7 puts twins in the resource slot table (D-D1,
|
||||
// ResolveTextureResourceSubsystemArm's first row) - AND BIT 11, which is D-K2's
|
||||
// FOURTH row (ID-14/ID-15): MGPTextureParams::BuiltinSampler is a SamplerCso HANDLE,
|
||||
// only bit 11 mints sampler CSOs (c0b's four unconditional mints deliberately
|
||||
// exclude it), and the applier's verdict for a null one is Fatal{ProtocolCorruption}
|
||||
// rather than a decline. The brief's original "bit 10 without 11 is fine" is
|
||||
// WITHDRAWN for P4a as built.
|
||||
{kMGPipeSubsystemTextureResources,
|
||||
kMGPipeSubsystemResources | kMGPipeSubsystemSamplers},
|
||||
|
||||
// BIT 11 REQUIRES BIT 10. Every MGPBoundView::Texture and every MGPImageView::Res
|
||||
// names a Texture handle and only bit 10 populates that slot table; without it every
|
||||
// per-unit lookup would miss and the walk would `continue` WITHOUT unbinding
|
||||
// (ResolveSamplerSubsystemArm). With the row above this is SYMMETRIC: bits 10 and 11
|
||||
// are one arm with two switches, and the only two masks that reach either handle arm
|
||||
// are "both set" and "neither set".
|
||||
{kMGPipeSubsystemSamplers, kMGPipeSubsystemTextureResources},
|
||||
|
||||
// BIT 12 DEPENDS ON NOTHING, and that is a ROW rather than an absence so the table
|
||||
// covers the four families exhaustively (the static_assert below): a ShaderCso handle
|
||||
// names no texture and no buffer, the archive rides beside the record as a companion
|
||||
// pointer, and the extra inputs the server specialises on are read from state the
|
||||
// backend already holds (ResolveProgramSubsystemArm).
|
||||
{kMGPipeSubsystemPrograms, 0},
|
||||
};
|
||||
|
||||
// THE MIRROR PAIRS THAT STAY FINE, said out loud rather than left as an absence, because
|
||||
// an unreachable branch that says something different is how the reachable one drifts
|
||||
// (Managers.cpp's own words at :2377-2381) - and because the table is only trustworthy if
|
||||
// what it does NOT contain was decided rather than forgotten:
|
||||
// - bit 10 set, bit 9 clear: FINE. The legacy FBO sync reaches the texture twin through
|
||||
// SyncTextureObjectToBackend, which dispatches to the handle arm by itself.
|
||||
// - bit 11 set, bit 9 clear: FINE, for the same reason - a sampler view names a texture,
|
||||
// never a framebuffer.
|
||||
// - bit 7 set, bit 10 clear: FINE, and it is P3a's shipped configuration.
|
||||
// - bit 12 set with any or none of 9/10/11: FINE, per the last row.
|
||||
// - bit 10 set, bit 11 clear (and its mirror) is NOT fine and is the row above; this is
|
||||
// the one sentence in the brief that P4a as built withdrew.
|
||||
constexpr Uint64 P4aFamilyDependencyBits(Uint64 subsystem) {
|
||||
return MGPipeSubsystemRequires(subsystem & kMGPipeP4aFamilySubsystems);
|
||||
Uint64 required = 0;
|
||||
for (const P4aFamilyDependencyRow& row : kMGPipeP4aFamilyDependencies) {
|
||||
if ((subsystem & row.Family) != 0) required |= row.Requires;
|
||||
}
|
||||
return required;
|
||||
}
|
||||
|
||||
// The table covers the four families this phase migrates and nothing else, so a fifth
|
||||
// family added to kMGPipeP4aFamilySubsystems without a row here does not silently inherit
|
||||
// "depends on nothing".
|
||||
constexpr Uint64 P4aFamilyDependencyTableCoverage() {
|
||||
Uint64 covered = 0;
|
||||
for (const MGPipeSubsystemDependencyRow& row : kMGPipeSubsystemDependencies) covered |= row.Family;
|
||||
for (const P4aFamilyDependencyRow& row : kMGPipeP4aFamilyDependencies) covered |= row.Family;
|
||||
return covered;
|
||||
}
|
||||
static_assert((P4aFamilyDependencyTableCoverage() & kMGPipeP4aFamilySubsystems) ==
|
||||
kMGPipeP4aFamilySubsystems,
|
||||
"every P4a family needs a D-K2 dependency row in MG_Pipe/SubsystemDeps.def, "
|
||||
"even an empty one");
|
||||
static_assert(P4aFamilyDependencyTableCoverage() == kMGPipeP4aFamilySubsystems,
|
||||
"every P4a family needs a D-K2 dependency row, even an empty one");
|
||||
static_assert(P4aFamilyDependencyBits(kMGPipeSubsystemFramebuffer) ==
|
||||
kMGPipeSubsystemTextureResources,
|
||||
"bit 9 requires bit 10");
|
||||
@@ -1707,18 +1582,14 @@ namespace MobileGL::MG_Pipe {
|
||||
// server whose four binding-point walks still read the frontend, so a record sent to it
|
||||
// would be stored and never looked at while the client latched its suppressor.
|
||||
//
|
||||
// AND BIT 13'S OWN DEPENDENCY ROW IS READ FROM MG_Pipe/SubsystemDeps.def, exactly as
|
||||
// P4a's four are (P3b/P4b R-5, switched over by wave 2-D package D3). It used to be the
|
||||
// hand-coded `(pushMask & kMGPipeSubsystemResources) == 0` below - the sixth statement of
|
||||
// the rule, and the one that sat fifteen lines from the block stating the other three,
|
||||
// which is how "THREE OF THEM" survived two phases. Its reason is the table's: every
|
||||
// MGPBufferRange::Res names a Buffer handle and only bit 7 puts one in the resource slot
|
||||
// table, so without it every EnsureBufferResourceForHandle on the server would mint a
|
||||
// twin with no record behind it. Withholding the whole family is the safe direction - the
|
||||
// legacy frontend walk runs untouched on both sides.
|
||||
// AND BIT 13 REQUIRES BIT 7, for bit 11's reason one family over: every
|
||||
// MGPBufferRange::Res names a Buffer handle and only bit 7 puts one in the resource
|
||||
// slot table, so without it every EnsureBufferResourceForHandle on the server would
|
||||
// mint a twin with no record behind it. Withholding the whole family is the safe
|
||||
// direction - the legacy frontend walk runs untouched on both sides.
|
||||
Bool P5eFamilyIsLive(Uint64 subsystem, Uint64 pushMask) {
|
||||
if ((subsystem & kMGPipeSubsystemBufferBindings) == 0) return true;
|
||||
if (!MGPipeSubsystemDependenciesAreSet(kMGPipeSubsystemBufferBindings, pushMask)) return false;
|
||||
if ((pushMask & kMGPipeSubsystemResources) == 0) return false;
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (MG_Config::Transport != MG_Config::TransportMode::Monolith) {
|
||||
return MG_Remote::Client::CapsMirrorInstance().ServerConsumes(
|
||||
@@ -1828,11 +1699,6 @@ namespace MobileGL::MG_Pipe {
|
||||
*entry = Entry{};
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
for (auto& table : m_kinds) table.clear();
|
||||
m_band.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
struct Entry {
|
||||
Uint32 Gen = 0;
|
||||
@@ -1897,15 +1763,6 @@ namespace MobileGL::MG_Pipe {
|
||||
PublicationLatch().NoteUnpublished(kind, handle);
|
||||
}
|
||||
|
||||
void MGPipeForgetAllPublications() {
|
||||
PublicationLatch().Clear();
|
||||
// The two families whose death asks their own record rather than the latch: vertex
|
||||
// elements (MGPipeEmitVertexElementsDestroyAndFree's RecordIsPublished) and buffers
|
||||
// (MGPipeEmitResourceDestroyAndFree's WasPublished).
|
||||
MGPipeVertexInputEmitterInstance().ForgetAllRecords();
|
||||
MGPipeResourceTrackerInstance().ForgetAllPublished();
|
||||
}
|
||||
|
||||
// THE GATE ITSELF, AS AN OBSERVABLE (ID-39, widened by S-3 / ID-41). Every P4a birth hook
|
||||
// below and every `wants()` row in the walk resolve through FamilyIsLive /
|
||||
// P4aFamilyHasItsConsumer / P4aFamilyDependenciesAreSet, and none of the three is reachable
|
||||
@@ -2014,11 +1871,8 @@ namespace MobileGL::MG_Pipe {
|
||||
//
|
||||
// BACKEND-NEUTRAL FROM THE FIRST COMMIT, which is the whole point: before P3a's C-1 fix
|
||||
// the only thing that ever returned a VertexElementsCso slot was DirectGLES'
|
||||
// StateObjectDeathOps table, so under a backend that installed none every VAO leaked a slot
|
||||
// and a ~1.3 KB applier record for the life of the process. It stays the point now that
|
||||
// BOTH backends install one (P7 wave 2 package C gives Magma its own, CONTRACT-P7 §5.5):
|
||||
// Magma's table EMITS the death record and frees nothing, so the slot still comes back
|
||||
// from here and from nowhere else. P4a mints SIX kinds and there
|
||||
// StateObjectDeathOps table, so under a backend that installs none every VAO leaked a slot
|
||||
// and a ~1.3 KB applier record for the life of the process. P4a mints SIX kinds and there
|
||||
// is no intermediate state in which a backend table is the only path for any of them.
|
||||
//
|
||||
// THE THREE-STEP ORDER IS FIXED and each position is load-bearing (see PipeMutation.h):
|
||||
|
||||
@@ -61,15 +61,9 @@ namespace MobileGL::MG_Pipe {
|
||||
// 47 DirectGLES cases at ID-41). With them the four families emit NOTHING in that state and
|
||||
// the legacy pull path runs exactly as it does on a pull build.
|
||||
//
|
||||
// D-K2's ROWS ARE IN MG_Pipe/SubsystemDeps.def, ONCE (P3b/P4b R-5), and this comment no
|
||||
// longer restates them - restating them here is half of how the rule ended up with six
|
||||
// statements, two of which were wrong. PipeFill.cpp's kMGPipeP4aFamilyDependencies is still
|
||||
// the client's own copy and is still the bit-for-bit mirror of the four
|
||||
// `Resolve<Family>SubsystemArm()` refusals in DirectGLES/Managers.cpp; switching it to read
|
||||
// the .def is the integrator's one-line change (PipeFill.cpp is the contract package's file
|
||||
// for the whole phase, so the emitter packages do not edit it).
|
||||
// MG_Test/Backend/DirectGLES/SubsystemDepsTest.cpp drives BOTH readers at every interesting
|
||||
// mask and compares them against the .def, so the two cannot drift in the meantime.
|
||||
// D-K2's TABLE IS IN PipeFill.cpp, ONCE: bit 9 requires bit 10, bit 10 requires bits 7 and
|
||||
// 11, bit 11 requires bit 10, bit 12 depends on nothing - the client mirror, bit for bit, of
|
||||
// the four `Resolve<Family>SubsystemArm()` refusals in DirectGLES/Managers.cpp.
|
||||
//
|
||||
// It is exported for the unit gate and for no other caller: the gate itself is
|
||||
// FamilyIsLive() inside PipeFill.cpp, every birth hook and every `wants()` row resolves
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user