mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-07 19:58:32 +09:00
Merge commit '54826327' into dev
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
name: Benchmark
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ dev ]
|
||||
|
||||
jobs:
|
||||
benchmark:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
BENCH_ROOT: ${{github.workspace}}/MobileGL/MG_Benchmark
|
||||
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- name: Get CMake
|
||||
uses: lukka/get-cmake@latest
|
||||
|
||||
- name: Prepare Vulkan SDK
|
||||
uses: humbletim/setup-vulkan-sdk@v1.2.1
|
||||
with:
|
||||
vulkan-query-version: 1.4.304.1
|
||||
vulkan-components: Glslang, SPIRV-Cross, SPIRV-Tools, SPIRV-Reflect, SPIRV-Headers
|
||||
vulkan-use-cache: true
|
||||
|
||||
- name: Test Vulkan SDK Install
|
||||
run: |
|
||||
echo "Vulkan SDK Version=='$VULKAN_SDK_VERSION'"
|
||||
echo "VULKAN_SDK=='$VULKAN_SDK'"
|
||||
test -n "$VULKAN_SDK_VERSION" || exit 4
|
||||
ls $VULKAN_SDK/lib
|
||||
|
||||
- name: Configure CMake
|
||||
working-directory: ${{env.BENCH_ROOT}}
|
||||
run: cmake -S . -B build-bench -DCMAKE_BUILD_TYPE=Release -DBENCHMARK_DOWNLOAD_DEPENDENCIES=ON -DBENCHMARK_ENABLE_TESTING=OFF
|
||||
|
||||
- name: Build
|
||||
working-directory: ${{env.BENCH_ROOT}}/build-bench
|
||||
run: cmake --build . -j${nproc}
|
||||
|
||||
- name: Benchmark
|
||||
working-directory: ${{env.BENCH_ROOT}}/build-bench
|
||||
run: ctest -V
|
||||
@@ -0,0 +1,27 @@
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
project(MobileGLTest)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
benchmark
|
||||
GIT_REPOSITORY https://github.com/google/benchmark.git
|
||||
GIT_TAG v1.9.4
|
||||
)
|
||||
FetchContent_MakeAvailable(benchmark)
|
||||
|
||||
set(MGL_ROOT ${CMAKE_CURRENT_LIST_DIR}/../..)
|
||||
|
||||
add_executable(SanityBench
|
||||
SanityBench.cpp
|
||||
)
|
||||
target_link_libraries(SanityBench
|
||||
PRIVATE benchmark::benchmark
|
||||
)
|
||||
|
||||
enable_testing()
|
||||
|
||||
add_test(NAME SanityBench COMMAND SanityBench)
|
||||
@@ -0,0 +1,32 @@
|
||||
#include <benchmark/benchmark.h>
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
|
||||
static void Sanity_VectorResize(benchmark::State& state) {
|
||||
for (auto _ : state) {
|
||||
std::vector<int> v;
|
||||
v.resize(state.range(0), 0);
|
||||
for (int i = 0; i < state.range(0); i += 16) {
|
||||
v[i] = i;
|
||||
}
|
||||
}
|
||||
state.SetBytesProcessed(int64_t(state.iterations()) *
|
||||
int64_t(state.range(0)));
|
||||
}
|
||||
BENCHMARK(Sanity_VectorResize)->Arg(2<<5)->Arg(2<<10)->Arg(2<<20);
|
||||
|
||||
|
||||
static void Sanity_memcpy(benchmark::State& state) {
|
||||
char* src = new char[state.range(0)];
|
||||
char* dst = new char[state.range(0)];
|
||||
memset(src, 'x', state.range(0));
|
||||
for (auto _ : state)
|
||||
memcpy(dst, src, state.range(0));
|
||||
state.SetBytesProcessed(int64_t(state.iterations()) *
|
||||
int64_t(state.range(0)));
|
||||
delete[] src;
|
||||
delete[] dst;
|
||||
}
|
||||
BENCHMARK(Sanity_memcpy)->Range(8, 8<<10);
|
||||
|
||||
BENCHMARK_MAIN();
|
||||
@@ -36,7 +36,7 @@ namespace MobileGL {
|
||||
return m_bindingSlots[i];
|
||||
}
|
||||
}
|
||||
return m_bindingSlots[0]; // Fallback to the first slot if not found
|
||||
assert(false);
|
||||
}
|
||||
|
||||
void BufferState::MarkBufferObjectForDeletion(Uint index) {
|
||||
@@ -63,4 +63,4 @@ namespace MobileGL {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,8 +60,12 @@ namespace MobileGL {
|
||||
void GLContext::MarkBufferObjectForDeletion(Uint index) {
|
||||
if (ValidateBufferObject(index)) {
|
||||
auto bufferObject = m_bufferState.GetBufferObject(index);
|
||||
for (SizeT i = 0; i < m_vertexArrayState.GetAllVertexArrays().size(); ++i) {
|
||||
auto vao = m_vertexArrayState.GetAllVertexArrays()[i];
|
||||
auto& vaos = m_vertexArrayState.GetAllVertexArrays();
|
||||
for (SizeT i = 0; i < vaos.size(); ++i) {
|
||||
auto vao = vaos[i];
|
||||
if (vao == nullptr)
|
||||
continue;
|
||||
|
||||
if (vao->GetIndexBufferBindingSlot().GetBoundObject() == bufferObject) {
|
||||
vao->GetIndexBufferBindingSlot().Bind(nullptr);
|
||||
}
|
||||
|
||||
@@ -8,11 +8,11 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
SharedPtr<VertexArrayObject> VertexArrayState::GetVertexArrayObject(Uint index) {
|
||||
auto it = m_vertexArrays.find(index);
|
||||
if (it != m_vertexArrays.end()) {
|
||||
return it->second;
|
||||
}
|
||||
return nullptr;
|
||||
if (index >= m_vertexArrays.size())
|
||||
// FIXME: report a GL error here
|
||||
return nullptr;
|
||||
|
||||
return m_vertexArrays[index];
|
||||
}
|
||||
|
||||
Vector<Uint> VertexArrayState::GenerateNames(Uint number) {
|
||||
@@ -23,35 +23,37 @@ namespace MobileGL {
|
||||
|
||||
void VertexArrayState::Bind(Uint index) {
|
||||
if (index == 0) {
|
||||
// FIXME: should we make a dummy VAO at index 0?
|
||||
m_boundVertexArray = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
auto it = m_vertexArrays.find(index);
|
||||
if (it != m_vertexArrays.end()) {
|
||||
m_boundVertexArray = it->second;
|
||||
}
|
||||
else {
|
||||
m_boundVertexArray = nullptr;
|
||||
}
|
||||
m_boundVertexArray = GetVertexArrayObject(index);
|
||||
}
|
||||
|
||||
SharedPtr<VertexArrayObject> VertexArrayState::CreateVertexArrayObject(Uint index) {
|
||||
auto vao = MakeShared<VertexArrayObject>();
|
||||
m_vertexArrays[index] = vao;
|
||||
if (index >= m_vertexArrays.size()) {
|
||||
// power-of-2 reallocation
|
||||
m_vertexArrays.reserve(std::bit_ceil(index + 1));
|
||||
m_vertexArrays.resize(index + 1, nullptr);
|
||||
}
|
||||
auto vao = m_vertexArrays[index] = MakeShared<VertexArrayObject>();
|
||||
return vao;
|
||||
}
|
||||
|
||||
void VertexArrayState::MarkVertexArrayForDeletion(Uint index) {
|
||||
if (m_indexGenerator.IsValid(index)) {
|
||||
if (m_boundVertexArray && m_vertexArrays.find(index) != m_vertexArrays.end() &&
|
||||
m_vertexArrays[index] == m_boundVertexArray) {
|
||||
if (m_boundVertexArray) {
|
||||
m_boundVertexArray = nullptr;
|
||||
}
|
||||
|
||||
m_vertexArrays.erase(index);
|
||||
if (ValidateVertexArrayObject(index)) {
|
||||
m_vertexArrays[index] = nullptr;
|
||||
}
|
||||
|
||||
m_indexGenerator.Delete(index);
|
||||
}
|
||||
// FIXME: report GL error here?
|
||||
}
|
||||
|
||||
bool VertexArrayState::ValidateName(Uint index) const {
|
||||
@@ -59,20 +61,15 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
bool VertexArrayState::ValidateVertexArrayObject(Uint index) const {
|
||||
return m_vertexArrays.find(index) != m_vertexArrays.end();
|
||||
return index < m_vertexArrays.size() && m_vertexArrays[index] != nullptr;
|
||||
}
|
||||
|
||||
SharedPtr<VertexArrayObject> VertexArrayState::GetBoundVertexArray() {
|
||||
return m_boundVertexArray;
|
||||
}
|
||||
|
||||
Vector<SharedPtr<VertexArrayObject>> VertexArrayState::GetAllVertexArrays() {
|
||||
Vector<SharedPtr<VertexArrayObject>> arrays;
|
||||
arrays.reserve(m_vertexArrays.size());
|
||||
for (const auto& pair : m_vertexArrays) {
|
||||
arrays.push_back(pair.second);
|
||||
}
|
||||
return arrays;
|
||||
Vector<SharedPtr<VertexArrayObject>>& VertexArrayState::GetAllVertexArrays() {
|
||||
return m_vertexArrays;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,10 @@ namespace MobileGL {
|
||||
bool ValidateName(Uint index) const;
|
||||
bool ValidateVertexArrayObject(Uint index) const;
|
||||
SharedPtr<VertexArrayObject> GetBoundVertexArray();
|
||||
Vector<SharedPtr<VertexArrayObject>> GetAllVertexArrays();
|
||||
Vector<SharedPtr<VertexArrayObject>>& GetAllVertexArrays();
|
||||
|
||||
private:
|
||||
UnorderedMap<Uint, SharedPtr<VertexArrayObject>> m_vertexArrays;
|
||||
Vector<SharedPtr<VertexArrayObject>> m_vertexArrays;
|
||||
IndexGenerator<Uint> m_indexGenerator;
|
||||
SharedPtr<VertexArrayObject> m_boundVertexArray;
|
||||
};
|
||||
|
||||
@@ -223,4 +223,7 @@ TEST_F(ProgramTest, DecompProgram) {
|
||||
EXPECT_EQ(it->second, uniform.location);
|
||||
}
|
||||
}
|
||||
|
||||
auto ubo0 = sessions[0].GetShaderInterface(SPVC_RESOURCE_TYPE_UNIFORM_BUFFER);
|
||||
auto ubo1 = sessions[1].GetShaderInterface(SPVC_RESOURCE_TYPE_UNIFORM_BUFFER);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include "MG_Util/Debug/Log.h"
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_Util {
|
||||
@@ -95,6 +96,22 @@ namespace MobileGL {
|
||||
var.name = list[i].name;
|
||||
var.location = spvc_compiler_get_decoration(compiler, list[i].id, SpvDecorationLocation);
|
||||
variables.push_back(var);
|
||||
|
||||
if (resource_type == SPVC_RESOURCE_TYPE_UNIFORM_BUFFER) {
|
||||
spvc_type type = spvc_compiler_get_type_handle(compiler, list[i].base_type_id);
|
||||
size_t num_members = spvc_type_get_num_member_types(type);
|
||||
printf("uniform %s {\n", var.name.c_str());
|
||||
for (size_t j = 0; j < num_members; ++j) {
|
||||
const char *memberName = spvc_compiler_get_member_name(compiler, list[i].base_type_id, j);
|
||||
// auto memberTypeId = spvc_type_get_member_type(type, j);
|
||||
// auto memberType = spvc_compiler_get_type_handle(compiler, memberTypeId);
|
||||
|
||||
unsigned memberOffset = 0;
|
||||
spvc_compiler_type_struct_member_offset(compiler, type, j, &memberOffset);
|
||||
printf("\b%s; // %u\n", memberName, memberOffset);
|
||||
}
|
||||
printf("}\n");
|
||||
}
|
||||
}
|
||||
std::sort(variables.begin(), variables.end());
|
||||
return variables;
|
||||
|
||||
Reference in New Issue
Block a user