Profiling under windows
This commit is contained in:
parent
ffe2764d29
commit
15a0b77960
|
@ -6,6 +6,16 @@ if (NOT WIN32)
|
|||
message(FATAL_ERROR "Only windows builds from top-level CMakeLists.txt")
|
||||
endif()
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
tracy
|
||||
GIT_REPOSITORY https://github.com/wolfpld/tracy.git
|
||||
GIT_TAG master
|
||||
GIT_SHALLOW TRUE
|
||||
GIT_PROGRESS TRUE
|
||||
)
|
||||
FetchContent_MakeAvailable(tracy)
|
||||
|
||||
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
|
||||
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
|
||||
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "AssetManager.h"
|
||||
#include "Log.h"
|
||||
#include "Profiling.h"
|
||||
|
||||
#define STBI_NO_STDIO
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
|
@ -11,6 +13,7 @@ AssetManager* AssetManager::ptr = nullptr;
|
|||
|
||||
bool AssetManager::loadTexture(const char* path, Texture* p_texture)
|
||||
{
|
||||
ZoneScoped;
|
||||
FileBuffer texture_data = {};
|
||||
if (!loadFile(path, &texture_data))
|
||||
return false;
|
||||
|
@ -30,6 +33,7 @@ bool AssetManager::loadTexture(const char* path, Texture* p_texture)
|
|||
|
||||
bool AssetManager::loadFontData(const char* path, float char_height, FontData* p_font)
|
||||
{
|
||||
ZoneScoped;
|
||||
FileBuffer ttf_data = {};
|
||||
if (!loadFile(path, &ttf_data))
|
||||
return false;
|
||||
|
@ -41,11 +45,13 @@ bool AssetManager::loadFontData(const char* path, float char_height, FontData* p
|
|||
0,
|
||||
char_height,
|
||||
bitmap_memory,
|
||||
STBTT_PH_VALUE, STBTT_PH_VALUE,
|
||||
32, 225, // latin-1 printable characters range
|
||||
STBTT_PH_VALUE,
|
||||
STBTT_PH_VALUE,
|
||||
32,
|
||||
225, // latin-1 printable characters range
|
||||
font_data.char_data);
|
||||
font_data.char_height = char_height;
|
||||
int off = stbtt_GetFontOffsetForIndex(data,0);
|
||||
int off = stbtt_GetFontOffsetForIndex(data, 0);
|
||||
if (off < 0) {
|
||||
releaseFileBuffer(ttf_data);
|
||||
return false;
|
||||
|
@ -69,8 +75,9 @@ bool AssetManager::loadFontData(const char* path, float char_height, FontData* p
|
|||
return true;
|
||||
}
|
||||
|
||||
bool AssetManager::loadFontBitmap(const char *path, float char_height, Texture* p_texture)
|
||||
bool AssetManager::loadFontBitmap(const char* path, float char_height, Texture* p_texture)
|
||||
{
|
||||
ZoneScoped;
|
||||
FileBuffer ttf_data = {};
|
||||
if (!loadFile(path, &ttf_data))
|
||||
return false;
|
||||
|
@ -80,8 +87,10 @@ bool AssetManager::loadFontBitmap(const char *path, float char_height, Texture*
|
|||
0,
|
||||
char_height,
|
||||
bitmap_memory,
|
||||
STBTT_PH_VALUE, STBTT_PH_VALUE,
|
||||
32, 225, // latin-1 printable characters range
|
||||
STBTT_PH_VALUE,
|
||||
STBTT_PH_VALUE,
|
||||
32,
|
||||
225, // latin-1 printable characters range
|
||||
char_data);
|
||||
*p_texture = Texture(STBTT_PH_VALUE, STBTT_PH_VALUE, bitmap_memory, GL_R8);
|
||||
releaseFileBuffer(ttf_data);
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
cmake_minimum_required(VERSION 3.18.1)
|
||||
project("kde")
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
|
||||
# INTEGRATION Füge deine CPP/H Dateien hier hinzu
|
||||
set(kde_SRCS
|
||||
Profiling.h
|
||||
Renderer.cpp
|
||||
Renderer.h
|
||||
Texture.cpp
|
||||
|
@ -47,6 +50,6 @@ elseif (WIN32)
|
|||
glad.h
|
||||
Win32AssetManager.cpp
|
||||
Win32AssetManager.h)
|
||||
target_link_libraries(kde glfw)
|
||||
target_include_directories(kde PRIVATE ${PROJECT_SOURCE_DIR}/../../../glfw/include)
|
||||
target_link_libraries(kde glfw TracyClient)
|
||||
target_include_directories(kde PRIVATE ${Tracy_SOURCE_DIR}/public)
|
||||
endif()
|
|
@ -1,21 +1,16 @@
|
|||
#include "Hash.h"
|
||||
#include "Profiling.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
Hash::Hash()
|
||||
: m_bucket_count(0),
|
||||
m_used_buckets(0),
|
||||
m_keys(nullptr),
|
||||
m_values(nullptr)
|
||||
Hash::Hash() : m_bucket_count(0), m_used_buckets(0), m_keys(nullptr), m_values(nullptr)
|
||||
{
|
||||
ZoneScoped;
|
||||
}
|
||||
|
||||
Hash::Hash(uint32_t bucket_count)
|
||||
: m_bucket_count(0),
|
||||
m_used_buckets(0),
|
||||
m_keys(nullptr),
|
||||
m_values(nullptr)
|
||||
Hash::Hash(uint32_t bucket_count) : m_bucket_count(0), m_used_buckets(0), m_keys(nullptr), m_values(nullptr)
|
||||
{
|
||||
ZoneScoped;
|
||||
auto* mem = reinterpret_cast<uint64_t*>(malloc(sizeof(uint64_t) * 2 * bucket_count));
|
||||
if (!mem)
|
||||
return;
|
||||
|
@ -31,6 +26,7 @@ Hash::Hash(const Hash& copy)
|
|||
m_keys(nullptr),
|
||||
m_values(nullptr)
|
||||
{
|
||||
ZoneScoped;
|
||||
auto* mem = reinterpret_cast<uint64_t*>(malloc(sizeof(uint64_t) * 2 * m_bucket_count));
|
||||
if (!mem)
|
||||
return;
|
||||
|
@ -41,6 +37,7 @@ Hash::Hash(const Hash& copy)
|
|||
|
||||
Hash& Hash::operator=(const Hash& rhs)
|
||||
{
|
||||
ZoneScoped;
|
||||
if (m_keys)
|
||||
free(m_keys);
|
||||
m_bucket_count = rhs.m_bucket_count;
|
||||
|
@ -60,6 +57,7 @@ Hash& Hash::operator=(const Hash& rhs)
|
|||
|
||||
Hash::~Hash()
|
||||
{
|
||||
ZoneScoped;
|
||||
free(m_keys);
|
||||
m_used_buckets = 0;
|
||||
m_bucket_count = 0;
|
||||
|
@ -69,6 +67,7 @@ Hash::~Hash()
|
|||
|
||||
uint64_t Hash::lookup(uint64_t key, uint64_t default_value)
|
||||
{
|
||||
ZoneScoped;
|
||||
if (m_bucket_count == 0)
|
||||
return default_value;
|
||||
uint64_t i = key % m_bucket_count;
|
||||
|
@ -84,6 +83,7 @@ uint64_t Hash::lookup(uint64_t key, uint64_t default_value)
|
|||
|
||||
bool Hash::insert(uint64_t key, uint64_t value)
|
||||
{
|
||||
ZoneScoped;
|
||||
if (key == HASH_EMPTY_KEY || key == HASH_TOMBSTONE_KEY) {
|
||||
return false;
|
||||
}
|
||||
|
@ -138,6 +138,7 @@ bool Hash::insert(uint64_t key, uint64_t value)
|
|||
|
||||
void Hash::remove(uint64_t key)
|
||||
{
|
||||
ZoneScoped;
|
||||
if (m_bucket_count == 0)
|
||||
return;
|
||||
uint64_t i = key % m_bucket_count;
|
||||
|
|
16
app/src/main/cpp/Profiling.h
Normal file
16
app/src/main/cpp/Profiling.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef KRIMI_DINNER_ENGINE_PROFILING_H
|
||||
#define KRIMI_DINNER_ENGINE_PROFILING_H
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <tracy/Tracy.hpp>
|
||||
|
||||
#else
|
||||
|
||||
#define FrameMark
|
||||
|
||||
#define ZoneScoped
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -2,6 +2,7 @@
|
|||
#include "Log.h"
|
||||
#include "AssetManager.h"
|
||||
#include "Texture.h"
|
||||
#include "Profiling.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
|
@ -62,17 +63,20 @@ static const char* g_frag_src = "#version 300 es
|
|||
|
||||
void Renderer::create()
|
||||
{
|
||||
ZoneScoped;
|
||||
Renderer::ptr = new Renderer;
|
||||
}
|
||||
|
||||
void Renderer::destroy()
|
||||
{
|
||||
ZoneScoped;
|
||||
delete Renderer::ptr;
|
||||
Renderer::ptr = nullptr;
|
||||
}
|
||||
|
||||
Renderer::Renderer()
|
||||
{
|
||||
ZoneScoped;
|
||||
GLuint vertex = 0, fragment = 0;
|
||||
vertex = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertex, 1, &g_vert_src, nullptr);
|
||||
|
@ -143,6 +147,7 @@ Renderer::Renderer()
|
|||
|
||||
Renderer::~Renderer()
|
||||
{
|
||||
ZoneScoped;
|
||||
for (auto texture : m_textures)
|
||||
texture.second.destroy();
|
||||
glDeleteProgram(m_shader);
|
||||
|
@ -152,21 +157,25 @@ Renderer::~Renderer()
|
|||
|
||||
void Renderer::addRect(float x, float y, float w, float h)
|
||||
{
|
||||
ZoneScoped;
|
||||
addRect(x, y, w, h, 1.f, 1.f, 1.f, 1.f, m_dummy_texture, 0.f, 0.f, 1.f, 1.f);
|
||||
}
|
||||
|
||||
void Renderer::addRect(float x, float y, float w, float h, StringHandle texture)
|
||||
{
|
||||
ZoneScoped;
|
||||
addRect(x, y, w, h, 1.f, 1.f, 1.f, 1.f, texture, 0.f, 0.f, 1.f, 1.f);
|
||||
}
|
||||
|
||||
void Renderer::addRect(float x, float y, float w, float h, float r, float g, float b, float a)
|
||||
{
|
||||
ZoneScoped;
|
||||
addRect(x, y, w, h, r, g, b, a, m_dummy_texture, 0.f, 0.f, 1.f, 1.f);
|
||||
}
|
||||
|
||||
void Renderer::addRect(float x, float y, float w, float h, float r, float g, float b, float a, StringHandle texture)
|
||||
{
|
||||
ZoneScoped;
|
||||
addRect(x, y, w, h, r, g, b, a, texture, 0.f, 0.f, 1.f, 1.f);
|
||||
}
|
||||
|
||||
|
@ -180,6 +189,7 @@ void Renderer::addRect(float x,
|
|||
float src_w,
|
||||
float src_h)
|
||||
{
|
||||
ZoneScoped;
|
||||
addRect(x, y, w, h, 1.f, 1.f, 1.f, 1.f, texture, src_x, src_y, src_w, src_h);
|
||||
}
|
||||
|
||||
|
@ -197,6 +207,7 @@ void Renderer::addRect(float x,
|
|||
float src_w,
|
||||
float src_h)
|
||||
{
|
||||
ZoneScoped;
|
||||
if (m_textures.find(texture) == m_textures.end()) {
|
||||
Texture tex;
|
||||
if (!AssetManager::ptr->loadTexture(StringRepository::global->getString(texture), &tex)) {
|
||||
|
@ -236,6 +247,7 @@ void Renderer::addFontRect(float x,
|
|||
float src_x1,
|
||||
float src_y1)
|
||||
{
|
||||
ZoneScoped;
|
||||
addFontRect(x, y, w, h, 0.f, 0.f, 0.f, 1.f, char_height, font, id, src_x0, src_y0, src_x1, src_y1);
|
||||
}
|
||||
|
||||
|
@ -255,6 +267,7 @@ void Renderer::addFontRect(float x,
|
|||
float src_x1,
|
||||
float src_y1)
|
||||
{
|
||||
ZoneScoped;
|
||||
if (m_textures.find(id) == m_textures.end()) {
|
||||
Texture tex;
|
||||
if (!AssetManager::ptr->loadFontBitmap(StringRepository::global->getString(font), char_height, &tex)) {
|
||||
|
@ -284,6 +297,7 @@ void Renderer::addFontRect(float x,
|
|||
|
||||
void Renderer::renderFrame(float width, float height)
|
||||
{
|
||||
ZoneScoped;
|
||||
assert(m_rects.size() == m_draw_textures.size());
|
||||
|
||||
glViewport(0, 0, static_cast<int>(width), static_cast<int>(height));
|
||||
|
@ -348,6 +362,7 @@ void Renderer::renderFrame(float width, float height)
|
|||
|
||||
void Renderer::getTextureSize(StringHandle texture, unsigned int* w, unsigned int* h)
|
||||
{
|
||||
ZoneScoped;
|
||||
if (m_textures.find(texture) == m_textures.end()) {
|
||||
Texture tex;
|
||||
if (!AssetManager::ptr->loadTexture(StringRepository::global->getString(texture), &tex)) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "StringRepository.h"
|
||||
#include "Profiling.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -7,6 +8,7 @@ StringRepository* StringRepository::global = &g_global_repository;
|
|||
|
||||
static uint64_t hashString(const char* string, unsigned int length)
|
||||
{
|
||||
ZoneScoped;
|
||||
uint64_t hash = 0xcbf29ce484222325;
|
||||
for (unsigned int i = 0; i < length; ++i) {
|
||||
hash = hash ^ string[i];
|
||||
|
@ -19,6 +21,7 @@ static uint64_t hashString(const char* string, unsigned int length)
|
|||
|
||||
StringRepository::StringRepository(const StringRepository& copy)
|
||||
{
|
||||
ZoneScoped;
|
||||
if (m_buffer)
|
||||
free(m_buffer);
|
||||
m_one_past_last_char = copy.m_one_past_last_char;
|
||||
|
@ -30,6 +33,7 @@ StringRepository::StringRepository(const StringRepository& copy)
|
|||
|
||||
StringRepository::~StringRepository()
|
||||
{
|
||||
ZoneScoped;
|
||||
m_one_past_last_char = 0;
|
||||
m_buffer_size = 0;
|
||||
free(m_buffer);
|
||||
|
@ -37,6 +41,7 @@ StringRepository::~StringRepository()
|
|||
|
||||
StringHandle StringRepository::internStringLength(const char* string, unsigned int length)
|
||||
{
|
||||
ZoneScoped;
|
||||
uint64_t hash = hashString(string, length);
|
||||
uint32_t offset = static_cast<uint32_t>(m_hash.lookup(hash, UINT32_MAX));
|
||||
if (offset == UINT32_MAX) {
|
||||
|
@ -61,11 +66,13 @@ StringHandle StringRepository::internStringLength(const char* string, unsigned i
|
|||
|
||||
StringHandle StringRepository::internString(const char* string)
|
||||
{
|
||||
ZoneScoped;
|
||||
return internStringLength(string, strlen(string));
|
||||
}
|
||||
|
||||
const char* StringRepository::getString(StringHandle handle)
|
||||
{
|
||||
ZoneScoped;
|
||||
if (handle == 0 || handle >= m_one_past_last_char)
|
||||
return nullptr;
|
||||
uint32_t offset = handle - 1;
|
||||
|
@ -79,6 +86,7 @@ void StringRepository::releaseString(StringHandle)
|
|||
|
||||
void StringRepository::freeAll()
|
||||
{
|
||||
ZoneScoped;
|
||||
m_one_past_last_char = 0;
|
||||
m_hash = Hash();
|
||||
m_buffer_size = 0;
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
#include "Texture.h"
|
||||
#include "Profiling.h"
|
||||
|
||||
Texture::Texture(unsigned int width, unsigned int height, const void* data) : m_texture(0)
|
||||
{
|
||||
ZoneScoped;
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glGenTextures(1, &m_texture);
|
||||
glBindTexture(GL_TEXTURE_2D, m_texture);
|
||||
|
@ -26,6 +29,8 @@ Texture::Texture(unsigned int width, unsigned int height, const void* data) : m_
|
|||
|
||||
Texture::Texture(unsigned int width, unsigned int height, const void* data, GLint format) : m_texture(0)
|
||||
{
|
||||
ZoneScoped;
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glGenTextures(1, &m_texture);
|
||||
glBindTexture(GL_TEXTURE_2D, m_texture);
|
||||
|
@ -51,16 +56,19 @@ Texture::Texture(unsigned int width, unsigned int height, const void* data, GLin
|
|||
|
||||
void Texture::destroy()
|
||||
{
|
||||
ZoneScoped;
|
||||
glDeleteTextures(1, &m_texture);
|
||||
}
|
||||
|
||||
void Texture::bind() const
|
||||
{
|
||||
ZoneScoped;
|
||||
glBindTexture(GL_TEXTURE_2D, m_texture);
|
||||
}
|
||||
|
||||
void Texture::getTextureSize(unsigned int* w, unsigned int* h)
|
||||
{
|
||||
ZoneScoped;
|
||||
if (w != nullptr) {
|
||||
*w = width_px;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
#include "Win32AssetManager.h"
|
||||
#include "Profiling.h"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
|
||||
void Win32AssetManager::create(const char* asset_root_dir)
|
||||
{
|
||||
ZoneScoped;
|
||||
static Win32AssetManager mgr;
|
||||
mgr.m_asset_root = asset_root_dir;
|
||||
AssetManager::ptr = &mgr;
|
||||
|
@ -12,6 +14,7 @@ void Win32AssetManager::create(const char* asset_root_dir)
|
|||
|
||||
bool Win32AssetManager::loadFile(const char* path, FileBuffer* p_file_buffer)
|
||||
{
|
||||
ZoneScoped;
|
||||
// TODO(Kevin): We could totally optimize this via a custom allocator
|
||||
char _cp[MAX_PATH];
|
||||
strncpy(_cp, m_asset_root, MAX_PATH);
|
||||
|
@ -62,6 +65,7 @@ bool Win32AssetManager::loadFile(const char* path, FileBuffer* p_file_buffer)
|
|||
|
||||
void Win32AssetManager::releaseFileBuffer(FileBuffer& fb)
|
||||
{
|
||||
ZoneScoped;
|
||||
void* data = const_cast<void*>(fb.data);
|
||||
VirtualFree(data, 0, MEM_RELEASE);
|
||||
fb.data = nullptr;
|
||||
|
@ -70,6 +74,7 @@ void Win32AssetManager::releaseFileBuffer(FileBuffer& fb)
|
|||
|
||||
bool Win32AssetManager::writeFile(const char* path, const void* data, size_t size)
|
||||
{
|
||||
ZoneScoped;
|
||||
char _cp[MAX_PATH];
|
||||
strncpy(_cp, m_asset_root, MAX_PATH);
|
||||
strncat(_cp, "\\", MAX_PATH);
|
||||
|
@ -104,5 +109,6 @@ bool Win32AssetManager::writeFile(const char* path, const void* data, size_t siz
|
|||
|
||||
bool Win32AssetManager::writeFile(const char* path, const FileBuffer& file_buffer)
|
||||
{
|
||||
ZoneScoped;
|
||||
return writeFile(path, file_buffer.data, file_buffer.size);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "TouchInput.h"
|
||||
#include "Position.h"
|
||||
#include "GameState.h"
|
||||
#include "Profiling.h"
|
||||
|
||||
#undef APIENTRY
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
|
@ -34,6 +35,8 @@ static void errorCallback(int error, const char* desc)
|
|||
|
||||
static void charCallback(GLFWwindow* window, unsigned int cp)
|
||||
{
|
||||
ZoneScoped;
|
||||
|
||||
UserData* ud = reinterpret_cast<UserData*>(glfwGetWindowUserPointer(window));
|
||||
assert(ud != nullptr);
|
||||
if (ud->cp_array.count < ud->cp_array.cap)
|
||||
|
@ -42,6 +45,8 @@ static void charCallback(GLFWwindow* window, unsigned int cp)
|
|||
|
||||
static void scrollCallback(GLFWwindow* window, double /* xoffset */, double yoffset)
|
||||
{
|
||||
ZoneScoped;
|
||||
|
||||
UserData* ud = reinterpret_cast<UserData*>(glfwGetWindowUserPointer(window));
|
||||
assert(ud != nullptr);
|
||||
ud->scroll_offset = yoffset;
|
||||
|
@ -209,6 +214,7 @@ int main()
|
|||
Renderer::ptr->renderFrame(static_cast<float>(w), static_cast<float>(h));
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
FrameMark;
|
||||
}
|
||||
|
||||
glfwDestroyWindow(window);
|
||||
|
|
Loading…
Reference in New Issue
Block a user