mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-22 09:12:15 +09:00
[Perf] (P8-D, Magma): the wire arm issues glDraw*Indirect / glMultiDraw*Indirect[Count] as vkCmdDraw*Indirect[Count] from the wire store instead of expanding them on the CPU behind a GPU-idle wait (create-indirect split: 321 waits / ~8 s -> 0), with an INDIRECT_COMMAND_READ barrier once per shader write; windr[] PipeStats counters, WireIndirectDrawScenario on both backends x every arm, notes/p8/D.md
This commit is contained in:
1 parent
8d3e2317a6
commit
d639e54616
15 files changed
+826
-8
No files matched your search
@@ -4648,6 +4648,41 @@ if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
# P8-D: the Magma wire arm issues indirect draws natively (docs/Disaggregated/notes/p8/D.md).
|
||||
# Public GL, so the source joins the binary unguarded and the ambient `DirectGLES.` /
|
||||
# `DirectVulkan.` monolith discovery runs it too. Split arms: DirectGLES through the registration
|
||||
# macro (which also replays it on Magma's informational tier), Magma's gated tier by hand, all
|
||||
# three transports - the counter halves read only on the inproc arm (WireIndirectPeek.h) and the
|
||||
# pixel halves everywhere, so there is no arm-only property to declare.
|
||||
target_sources(MobileGLIntegrationTest PRIVATE Harness/WireIndirectPeek.cpp Scenarios/WireIndirectDrawScenario.cpp)
|
||||
if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
mgl_itest_register_split_arms("WireIndirectDrawScenario.*" "")
|
||||
set(MGL_ITEST_MAGMA_INDIRECT_FLAVOUR_ENV
|
||||
"MOBILEGL_BACKEND_TYPE=DirectVulkan"
|
||||
"MOBILEGL_IPC_ROLE_SPLIT_STATE=1" "MOBILEGL_IPC_STRICT_ERRORS=1"
|
||||
"MOBILEGL_ITEST_REQUIRE_GPU=1" "MGITEST_SPLIT_LANE=1"
|
||||
${MGL_ITEST_CAPABILITY_ENV} ${MGL_ITEST_VULKAN_ENV})
|
||||
foreach(mglItestArm IN LISTS MGL_ITEST_MAGMA_ARMS)
|
||||
mgl_itest_magma_arm_shape(${mglItestArm} indirect)
|
||||
mgl_itest_join_environment(MGL_ITEST_MAGMA_INDIRECT_ENVIRONMENT
|
||||
${MGL_ITEST_MAGMA_INDIRECT_FLAVOUR_ENV} ${mglItestArmTransportEnv})
|
||||
foreach(indirectCase
|
||||
EveryIndirectFormIsIssuedNativelyFromItsStore
|
||||
ComputeWrittenCommandsDrawWithoutAHostWait
|
||||
ComputeWrittenCountWordIsTheOneTheGpuReads
|
||||
ShaderWrittenCommandsWithoutAnApplicationBarrierAreOrdered)
|
||||
gtest_discover_tests(MobileGLIntegrationTest
|
||||
TEST_PREFIX "DirectVulkan.${mglItestArm}.Indirect."
|
||||
TEST_FILTER "WireIndirectDrawScenario.${indirectCase}"
|
||||
DISCOVERY_TIMEOUT 30
|
||||
PROPERTIES LABELS "${mglItestMagmaLabels}"
|
||||
TIMEOUT ${MGL_ITEST_TIMEOUT}
|
||||
${mglItestArmProperties}
|
||||
ENVIRONMENT "${MGL_ITEST_MAGMA_INDIRECT_ENVIRONMENT}\;MOBILEGL_LOG_FILE_PATH=${CMAKE_CURRENT_BINARY_DIR}/magma-indirect${mglItestArmLogTag}-${indirectCase}.log")
|
||||
endforeach()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
# =====================================================================================
|
||||
# P7 PACKAGE L: THE INFORMATIONAL MAGMA CENSUS - TIER 2 OF TWO
|
||||
# =====================================================================================
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
// MobileGL - MobileGL/MG_IntegrationTest/Harness/WireIndirectPeek.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
|
||||
|
||||
#include "WireIndirectPeek.h"
|
||||
|
||||
#if !defined(__ANDROID__)
|
||||
#include <MG_Pipe/MGPipe.h>
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
#include <MG_Util/Metrics/PipeStats.h>
|
||||
#define MGITEST_WIRE_INDIRECT_PEEK_LIVE 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace MGITest {
|
||||
|
||||
#if defined(MGITEST_WIRE_INDIRECT_PEEK_LIVE)
|
||||
bool PeekWireIndirectCounters(WireIndirectCounters* out) {
|
||||
if (out == nullptr) return false;
|
||||
namespace Stats = MobileGL::MG_Util::PipeStats;
|
||||
if (!Stats::Enabled()) Stats::SetEnabledForTesting(true);
|
||||
out->nativeDraws = Stats::TotalCalls(Stats::CallClass::WireIndirectNativeDraws);
|
||||
out->cpuExpansions = Stats::TotalCalls(Stats::CallClass::WireIndirectCpuExpansions);
|
||||
out->barriers = Stats::TotalCalls(Stats::CallClass::WireIndirectBarriers);
|
||||
out->hostWaits = Stats::TotalCalls(Stats::CallClass::WireHostWaits);
|
||||
out->indirectWaits = Stats::TotalCalls(Stats::CallClass::WireHostWaitsIndirect);
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
bool PeekWireIndirectCounters(WireIndirectCounters*) { return false; }
|
||||
#endif
|
||||
|
||||
} // namespace MGITest
|
||||
@@ -0,0 +1,28 @@
|
||||
// MobileGL - MobileGL/MG_IntegrationTest/Harness/WireIndirectPeek.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
|
||||
//
|
||||
// P8-D: the Magma wire arm's indirect-draw counters (PipeStats `windr[...]`), read as run totals
|
||||
// out of THIS process - P4aFinalFixPeek.cpp's shape. Process-wide means the SERVER's counts only
|
||||
// where the server is this process: monolith and inproc, never spawn or tcp. The first call arms
|
||||
// the counters (a case reads before and after its workload, so it must peek before it draws).
|
||||
// False where the reading cannot be taken: a pull build, Android.
|
||||
#pragma once
|
||||
|
||||
namespace MGITest {
|
||||
|
||||
struct WireIndirectCounters {
|
||||
unsigned long long nativeDraws = 0; // wire-indirect-native-draws (`wind`)
|
||||
unsigned long long cpuExpansions = 0; // wire-indirect-cpu-expansions (`wixp`)
|
||||
unsigned long long barriers = 0; // wire-indirect-barriers (`wibar`)
|
||||
unsigned long long hostWaits = 0; // wire-host-waits (`whw`)
|
||||
unsigned long long indirectWaits = 0; // wire-host-waits-indirect (`whwi`)
|
||||
};
|
||||
|
||||
bool PeekWireIndirectCounters(WireIndirectCounters* out);
|
||||
|
||||
} // namespace MGITest
|
||||
@@ -0,0 +1,365 @@
|
||||
// MobileGL - MobileGL/MG_IntegrationTest/Scenarios/WireIndirectDrawScenario.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
|
||||
//
|
||||
// P8-D: THE MAGMA WIRE ARM ISSUES INDIRECT DRAWS FROM THE WIRE STORE, AS THE MONOLITH ARM DOES.
|
||||
//
|
||||
// Before P8-D every wire indirect draw read its commands (and its count word) through
|
||||
// ReadWireBuffer and expanded them on the CPU, and a store a shader had written turned that read
|
||||
// into a whole-GPU wait per draw (create-indirect: 321 expansions, 327 waits, ~4-8 s of waiting
|
||||
// per replay on lavapipe). The cases pin both halves of the change:
|
||||
// * PIXELS, on every arm and both backends where the backend's own semantics allow it - each
|
||||
// indirect form draws exactly the strips its commands name, and GPU-written commands are the
|
||||
// ones the draw sees (the poison the buffers start with names the OTHER strips);
|
||||
// * THE SERVER'S OWN COUNTERS (Harness/WireIndirectPeek.h), where they can be read - Magma on
|
||||
// the inproc arm, whose server is this process: every call issued natively, no CPU
|
||||
// expansion, no host wait, and the INDIRECT_COMMAND_READ barrier exactly once per write.
|
||||
//
|
||||
// Four strips across the viewport, one per quarter; a command draws one strip. Green = drawn,
|
||||
// red = the clear. The VBO opens with three padding vertices so a command that loses its `first`
|
||||
// or `firstIndex` draws a degenerate triangle rather than the right strip.
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "../Harness/HeadlessGL.h"
|
||||
#include "../Harness/ScenarioFixture.h"
|
||||
#include "../Harness/SplitRuntimePeek.h"
|
||||
#include "../Harness/WireIndirectPeek.h"
|
||||
|
||||
#ifdef GLAPI
|
||||
#undef GLAPI
|
||||
#endif
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glext.h>
|
||||
|
||||
namespace MGITest {
|
||||
namespace {
|
||||
|
||||
constexpr int kStrips = 4;
|
||||
constexpr std::uint32_t kPad = 3;
|
||||
constexpr std::uint32_t kStripVertices = 6;
|
||||
|
||||
constexpr const char* kVertexSource = R"(#version 430 core
|
||||
layout(location = 0) in vec2 aPos;
|
||||
void main() { gl_Position = vec4(aPos, 0.0, 1.0); }
|
||||
)";
|
||||
constexpr const char* kFragmentSource = R"(#version 430 core
|
||||
out vec4 oColor;
|
||||
void main() { oColor = vec4(0.0, 1.0, 0.0, 1.0); }
|
||||
)";
|
||||
// Copies `source` into `words`, one word per invocation: the compute write under test.
|
||||
constexpr const char* kCopySource = R"(#version 430 core
|
||||
layout(local_size_x = 1) in;
|
||||
layout(std430, binding = 0) buffer Words { uint words[]; };
|
||||
layout(std430, binding = 1) readonly buffer Source { uint source[]; };
|
||||
void main() { words[gl_GlobalInvocationID.x] = source[gl_GlobalInvocationID.x]; }
|
||||
)";
|
||||
|
||||
struct ArraysCommand {
|
||||
std::uint32_t count, instanceCount, first, baseInstance;
|
||||
};
|
||||
struct ElementsCommand {
|
||||
std::uint32_t count, instanceCount, firstIndex;
|
||||
std::int32_t baseVertex;
|
||||
std::uint32_t baseInstance;
|
||||
};
|
||||
// A padded elements command, for the stride case: 32 bytes, the tail unread.
|
||||
struct PaddedElementsCommand {
|
||||
ElementsCommand command;
|
||||
std::uint32_t padding[3];
|
||||
};
|
||||
|
||||
ArraysCommand Arrays(int strip) { return {kStripVertices, 1, kPad + kStripVertices * strip, 0}; }
|
||||
ElementsCommand Elements(int strip) { return {kStripVertices, 1, kStripVertices * strip, 0, 0}; }
|
||||
|
||||
using Strips = std::array<bool, kStrips>;
|
||||
|
||||
class WireIndirectDrawScenario : public ScenarioTest {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
ScenarioTest::SetUp();
|
||||
if (!Ready()) return;
|
||||
m_magma = Gl().BackendName() == "DirectVulkan";
|
||||
m_transport = PeekSplitRuntime().transportName;
|
||||
std::string error;
|
||||
m_program = CompileProgram(kVertexSource, kFragmentSource, &error);
|
||||
ASSERT_NE(m_program, 0u) << error;
|
||||
m_copy = CompileCompute(kCopySource);
|
||||
ASSERT_NE(m_copy, 0u);
|
||||
|
||||
std::vector<float> vertices(2 * kPad, 0.0f);
|
||||
for (int strip = 0; strip < kStrips; ++strip) {
|
||||
const float x0 = -1.0f + 0.5f * static_cast<float>(strip);
|
||||
const float x1 = x0 + 0.5f;
|
||||
const float quad[12] = {x0, -1.0f, x1, -1.0f, x1, 1.0f, x0, -1.0f, x1, 1.0f, x0, 1.0f};
|
||||
vertices.insert(vertices.end(), quad, quad + 12);
|
||||
}
|
||||
std::vector<std::uint32_t> indices;
|
||||
for (std::uint32_t i = 0; i < kStripVertices * kStrips; ++i) indices.push_back(kPad + i);
|
||||
|
||||
glGenVertexArrays(1, &m_vao);
|
||||
glBindVertexArray(m_vao);
|
||||
glGenBuffers(1, &m_vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, static_cast<GLsizeiptr>(vertices.size() * sizeof(float)),
|
||||
vertices.data(), GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), nullptr);
|
||||
glGenBuffers(1, &m_ebo);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ebo);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, static_cast<GLsizeiptr>(indices.size() * sizeof(std::uint32_t)),
|
||||
indices.data(), GL_STATIC_DRAW);
|
||||
ASSERT_EQ(FirstGLError(), GLenum(GL_NO_ERROR)) << "scene setup left a GL error behind";
|
||||
|
||||
// The counters are armed by the first peek, so it has to come before any draw.
|
||||
if (CountersReadable()) {
|
||||
ASSERT_TRUE(PeekWireIndirectCounters(&m_before))
|
||||
<< "Magma on the inproc arm must be able to read the wire arm's own counters";
|
||||
}
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
if (!Ready()) return;
|
||||
glBindVertexArray(0);
|
||||
for (GLuint* buffer : {&m_vbo, &m_ebo, &m_indirect, &m_parameter, &m_source}) {
|
||||
if (*buffer != 0) glDeleteBuffers(1, buffer);
|
||||
*buffer = 0;
|
||||
}
|
||||
if (m_vao != 0) glDeleteVertexArrays(1, &m_vao);
|
||||
if (m_program != 0) glDeleteProgram(m_program);
|
||||
if (m_copy != 0) glDeleteProgram(m_copy);
|
||||
}
|
||||
|
||||
static GLuint CompileCompute(const char* source) {
|
||||
const GLuint shader = glCreateShader(GL_COMPUTE_SHADER);
|
||||
glShaderSource(shader, 1, &source, nullptr);
|
||||
glCompileShader(shader);
|
||||
GLint ok = GL_FALSE;
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &ok);
|
||||
if (ok != GL_TRUE) {
|
||||
glDeleteShader(shader);
|
||||
return 0;
|
||||
}
|
||||
const GLuint program = glCreateProgram();
|
||||
glAttachShader(program, shader);
|
||||
glLinkProgram(program);
|
||||
glDeleteShader(shader);
|
||||
glGetProgramiv(program, GL_LINK_STATUS, &ok);
|
||||
if (ok != GL_TRUE) {
|
||||
glDeleteProgram(program);
|
||||
return 0;
|
||||
}
|
||||
return program;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void Fill(GLuint& name, GLenum target, const std::vector<T>& data) {
|
||||
if (name == 0) glGenBuffers(1, &name);
|
||||
glBindBuffer(target, name);
|
||||
glBufferData(target, static_cast<GLsizeiptr>(data.size() * sizeof(T)), data.data(), GL_DYNAMIC_COPY);
|
||||
}
|
||||
|
||||
// The compute write: `words` (already holding its poison) receives `data` from the GPU.
|
||||
template <typename T>
|
||||
void ComputeWrite(GLuint words, const std::vector<T>& data) {
|
||||
Fill(m_source, GL_SHADER_STORAGE_BUFFER, data);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, words);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_source);
|
||||
glUseProgram(m_copy);
|
||||
glDispatchCompute(static_cast<GLuint>(data.size() * sizeof(T) / sizeof(std::uint32_t)), 1, 1);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, 0);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, 0);
|
||||
}
|
||||
|
||||
template <typename DrawFn>
|
||||
Image Render(DrawFn&& draw) {
|
||||
BindDefaultFramebuffer();
|
||||
glViewport(0, 0, Gl().Width(), Gl().Height());
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
ClearTo(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
glUseProgram(m_program);
|
||||
glBindVertexArray(m_vao);
|
||||
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, m_indirect);
|
||||
draw();
|
||||
return ReadPixels(Gl().Width(), Gl().Height());
|
||||
}
|
||||
|
||||
static void ExpectStrips(const Image& image, const Strips& drawn, const std::string& what) {
|
||||
for (int strip = 0; strip < kStrips; ++strip) {
|
||||
const int x = image.Width() * (2 * strip + 1) / (2 * kStrips);
|
||||
EXPECT_STREQ(image.ColorName(x, image.Height() / 2), drawn[strip] ? "green" : "red")
|
||||
<< what << ": strip " << strip;
|
||||
}
|
||||
}
|
||||
|
||||
// Magma's server in THIS process: the inproc arm. Spawn and tcp servers are other
|
||||
// processes, and the monolith arm never takes the wire path at all.
|
||||
bool CountersReadable() const { return m_magma && m_transport == "inproc"; }
|
||||
|
||||
WireIndirectCounters Delta() const {
|
||||
WireIndirectCounters now{};
|
||||
EXPECT_TRUE(PeekWireIndirectCounters(&now));
|
||||
return {now.nativeDraws - m_before.nativeDraws, now.cpuExpansions - m_before.cpuExpansions,
|
||||
now.barriers - m_before.barriers, now.hostWaits - m_before.hostWaits,
|
||||
now.indirectWaits - m_before.indirectWaits};
|
||||
}
|
||||
|
||||
bool m_magma = false;
|
||||
std::string m_transport;
|
||||
WireIndirectCounters m_before{};
|
||||
GLuint m_program = 0, m_copy = 0, m_vao = 0, m_vbo = 0, m_ebo = 0;
|
||||
GLuint m_indirect = 0, m_parameter = 0, m_source = 0;
|
||||
};
|
||||
|
||||
// Every indirect form from CPU-written commands. On Magma/inproc the server must have
|
||||
// issued all six natively, expanded none, waited for nothing and recorded no barrier (no
|
||||
// shader ever wrote these stores).
|
||||
TEST_F(WireIndirectDrawScenario, EveryIndirectFormIsIssuedNativelyFromItsStore) {
|
||||
if (!Ready() || IsSkipped()) return;
|
||||
// Arrays commands at 0.., elements commands after them: the offsets are byte offsets
|
||||
// into one store, as an application packs them.
|
||||
const std::vector<ArraysCommand> arrays = {Arrays(0), Arrays(1), Arrays(3), Arrays(2)};
|
||||
Fill(m_indirect, GL_DRAW_INDIRECT_BUFFER, arrays);
|
||||
Image image = Render([&] { glDrawArraysIndirect(GL_TRIANGLES, reinterpret_cast<const void*>(16)); });
|
||||
ExpectStrips(image, {false, true, false, false}, "glDrawArraysIndirect at byte 16");
|
||||
image = Render([&] { glMultiDrawArraysIndirect(GL_TRIANGLES, nullptr, 3, 0); });
|
||||
ExpectStrips(image, {true, true, false, true}, "glMultiDrawArraysIndirect, 3 commands");
|
||||
|
||||
const std::vector<PaddedElementsCommand> padded = {{Elements(3), {}}, {Elements(0), {}}};
|
||||
Fill(m_indirect, GL_DRAW_INDIRECT_BUFFER, padded);
|
||||
image = Render([&] {
|
||||
glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT, nullptr, 2, sizeof(PaddedElementsCommand));
|
||||
});
|
||||
ExpectStrips(image, {true, false, false, true}, "glMultiDrawElementsIndirect, stride 32");
|
||||
image = Render([&] {
|
||||
glDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT,
|
||||
reinterpret_cast<const void*>(sizeof(PaddedElementsCommand)));
|
||||
});
|
||||
ExpectStrips(image, {true, false, false, false}, "glDrawElementsIndirect at byte 32");
|
||||
|
||||
// The count forms: three commands each, a count word that allows fewer.
|
||||
Fill(m_parameter, GL_PARAMETER_BUFFER, std::vector<std::uint32_t>{7, 2, 1});
|
||||
Fill(m_indirect, GL_DRAW_INDIRECT_BUFFER, std::vector<ArraysCommand>{Arrays(0), Arrays(1), Arrays(2)});
|
||||
image = Render([&] {
|
||||
glMultiDrawArraysIndirectCount(GL_TRIANGLES, nullptr, 4, 3, 0);
|
||||
});
|
||||
ExpectStrips(image, {true, true, false, false}, "glMultiDrawArraysIndirectCount, count word 2 of 3");
|
||||
Fill(m_indirect, GL_DRAW_INDIRECT_BUFFER, std::vector<ElementsCommand>{Elements(3), Elements(2), Elements(1)});
|
||||
image = Render([&] {
|
||||
glMultiDrawElementsIndirectCount(GL_TRIANGLES, GL_UNSIGNED_INT, nullptr, 8, 3, 0);
|
||||
});
|
||||
ExpectStrips(image, {false, false, false, true}, "glMultiDrawElementsIndirectCount, count word 1 of 3");
|
||||
EXPECT_EQ(FirstGLError(), GLenum(GL_NO_ERROR));
|
||||
|
||||
if (!CountersReadable()) return;
|
||||
const WireIndirectCounters delta = Delta();
|
||||
EXPECT_EQ(delta.nativeDraws, 6u) << "every indirect call must be issued as vkCmdDraw*Indirect[Count]";
|
||||
EXPECT_EQ(delta.cpuExpansions, 0u) << "no indirect call may read its words on the CPU";
|
||||
EXPECT_EQ(delta.indirectWaits, 0u) << "an indirect call took a host wait";
|
||||
EXPECT_EQ(delta.hostWaits, 0u) << "a host wait was taken with no GPU write anywhere";
|
||||
EXPECT_EQ(delta.barriers, 0u) << "no shader wrote these stores, so no barrier is due";
|
||||
}
|
||||
|
||||
// Commands a compute shader wrote, behind the application's own GL_COMMAND_BARRIER_BIT.
|
||||
// The buffers start with commands for the OTHER strips, so a read of stale words shows.
|
||||
// On Magma/inproc: issued natively, and - the point of the package - NO host wait.
|
||||
TEST_F(WireIndirectDrawScenario, ComputeWrittenCommandsDrawWithoutAHostWait) {
|
||||
if (!Ready() || IsSkipped()) return;
|
||||
Fill(m_indirect, GL_DRAW_INDIRECT_BUFFER, std::vector<ArraysCommand>{Arrays(2), Arrays(3)});
|
||||
ComputeWrite(m_indirect, std::vector<ArraysCommand>{Arrays(0), Arrays(1)});
|
||||
glMemoryBarrier(GL_COMMAND_BARRIER_BIT);
|
||||
Image image = Render([&] { glMultiDrawArraysIndirect(GL_TRIANGLES, nullptr, 2, 0); });
|
||||
ExpectStrips(image, {true, true, false, false}, "glMultiDrawArraysIndirect of compute-written commands");
|
||||
|
||||
Fill(m_indirect, GL_DRAW_INDIRECT_BUFFER, std::vector<ElementsCommand>{Elements(0), Elements(1)});
|
||||
ComputeWrite(m_indirect, std::vector<ElementsCommand>{Elements(3), Elements(2)});
|
||||
glMemoryBarrier(GL_COMMAND_BARRIER_BIT);
|
||||
image = Render([&] { glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT, nullptr, 2, 0); });
|
||||
ExpectStrips(image, {false, false, true, true}, "glMultiDrawElementsIndirect of compute-written commands");
|
||||
EXPECT_EQ(FirstGLError(), GLenum(GL_NO_ERROR));
|
||||
|
||||
if (!CountersReadable()) return;
|
||||
const WireIndirectCounters delta = Delta();
|
||||
EXPECT_EQ(delta.nativeDraws, 2u) << "both draws must be issued natively";
|
||||
EXPECT_EQ(delta.cpuExpansions, 0u) << "no indirect call may read its words on the CPU";
|
||||
EXPECT_EQ(delta.indirectWaits, 0u)
|
||||
<< "an indirect draw of shader-written commands waited for the GPU on the host";
|
||||
EXPECT_EQ(delta.hostWaits, 0u) << "a host wait was taken";
|
||||
EXPECT_EQ(delta.barriers, 2u) << "one INDIRECT_COMMAND_READ barrier per freshly written store";
|
||||
}
|
||||
|
||||
// The COUNT word a compute shader wrote. Magma only: Espryt reads that word from a
|
||||
// server shadow GPU writes do not update, on both arms (OPEN-QUESTIONS 15, P8-C's
|
||||
// package), so its answer here is a known divergence rather than this package's claim.
|
||||
TEST_F(WireIndirectDrawScenario, ComputeWrittenCountWordIsTheOneTheGpuReads) {
|
||||
if (!Ready() || IsSkipped()) return;
|
||||
if (!m_magma) {
|
||||
GTEST_SKIP() << "Espryt reads the count word from its shadow on both arms (OQ15, P8-C)";
|
||||
}
|
||||
Fill(m_indirect, GL_DRAW_INDIRECT_BUFFER, std::vector<ElementsCommand>{Elements(0), Elements(3), Elements(2)});
|
||||
Fill(m_parameter, GL_PARAMETER_BUFFER, std::vector<std::uint32_t>{3});
|
||||
ComputeWrite(m_parameter, std::vector<std::uint32_t>{1});
|
||||
glMemoryBarrier(GL_COMMAND_BARRIER_BIT);
|
||||
Image image = Render([&] {
|
||||
glMultiDrawElementsIndirectCount(GL_TRIANGLES, GL_UNSIGNED_INT, nullptr, 0, 3, 0);
|
||||
});
|
||||
ExpectStrips(image, {true, false, false, false}, "glMultiDrawElementsIndirectCount, shader-written count 1");
|
||||
if (m_transport == "monolith") {
|
||||
// DirectVulkan.cpp's monolith MultiDrawArraysIndirectCount reads this word from the
|
||||
// frontend shadow without SyncGpuWrites: recorded for dev (ID-P8-3), not this lane's.
|
||||
return;
|
||||
}
|
||||
Fill(m_indirect, GL_DRAW_INDIRECT_BUFFER, std::vector<ArraysCommand>{Arrays(1), Arrays(2), Arrays(3)});
|
||||
Fill(m_parameter, GL_PARAMETER_BUFFER, std::vector<std::uint32_t>{0});
|
||||
ComputeWrite(m_parameter, std::vector<std::uint32_t>{2});
|
||||
glMemoryBarrier(GL_COMMAND_BARRIER_BIT);
|
||||
image = Render([&] { glMultiDrawArraysIndirectCount(GL_TRIANGLES, nullptr, 0, 3, 0); });
|
||||
ExpectStrips(image, {false, true, true, false}, "glMultiDrawArraysIndirectCount, shader-written count 2");
|
||||
EXPECT_EQ(FirstGLError(), GLenum(GL_NO_ERROR));
|
||||
|
||||
if (!CountersReadable()) return;
|
||||
const WireIndirectCounters delta = Delta();
|
||||
EXPECT_EQ(delta.nativeDraws, 2u);
|
||||
EXPECT_EQ(delta.cpuExpansions, 0u) << "a count word was read on the CPU";
|
||||
EXPECT_EQ(delta.hostWaits, 0u) << "a host wait was taken";
|
||||
EXPECT_EQ(delta.barriers, 2u) << "one barrier per draw whose count store a shader wrote";
|
||||
}
|
||||
|
||||
// Flywheel's shape (create-indirect's trace: 322 cull-then-draw rounds, no glMemoryBarrier
|
||||
// between them). GL leaves it undefined; the wire arm orders it anyway, once per write,
|
||||
// because the CPU path it replaced did (by waiting). Magma's split arms only: the monolith
|
||||
// arm records no dependency here (recorded for dev), and Espryt's is its driver's.
|
||||
TEST_F(WireIndirectDrawScenario, ShaderWrittenCommandsWithoutAnApplicationBarrierAreOrdered) {
|
||||
if (!Ready() || IsSkipped()) return;
|
||||
if (!m_magma || m_transport == "monolith") {
|
||||
GTEST_SKIP() << "the implicit INDIRECT_COMMAND_READ barrier is the Magma wire arm's (P8-D)";
|
||||
}
|
||||
Fill(m_indirect, GL_DRAW_INDIRECT_BUFFER, std::vector<ArraysCommand>{Arrays(3), Arrays(2)});
|
||||
ComputeWrite(m_indirect, std::vector<ArraysCommand>{Arrays(0), Arrays(1)});
|
||||
Image image = Render([&] { glMultiDrawArraysIndirect(GL_TRIANGLES, nullptr, 2, 0); });
|
||||
ExpectStrips(image, {true, true, false, false}, "the first draw after the write");
|
||||
image = Render([&] { glDrawArraysIndirect(GL_TRIANGLES, reinterpret_cast<const void*>(16)); });
|
||||
ExpectStrips(image, {false, true, false, false}, "a second draw, no write between");
|
||||
ComputeWrite(m_indirect, std::vector<ArraysCommand>{Arrays(2), Arrays(3)});
|
||||
image = Render([&] { glMultiDrawArraysIndirect(GL_TRIANGLES, nullptr, 2, 0); });
|
||||
ExpectStrips(image, {false, false, true, true}, "the draw after a second write");
|
||||
EXPECT_EQ(FirstGLError(), GLenum(GL_NO_ERROR));
|
||||
|
||||
if (!CountersReadable()) return;
|
||||
const WireIndirectCounters delta = Delta();
|
||||
EXPECT_EQ(delta.nativeDraws, 3u);
|
||||
EXPECT_EQ(delta.cpuExpansions, 0u);
|
||||
EXPECT_EQ(delta.hostWaits, 0u) << "a host wait was taken";
|
||||
EXPECT_EQ(delta.barriers, 2u) << "exactly one barrier per write: the second draw reads no new write";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace MGITest
|
||||
Reference in new issue
Block a user