Skip to content

Commit

Permalink
mangohud on drm
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Adenis-Lamarre <[email protected]>
  • Loading branch information
nadenislamarre committed Mar 23, 2022
1 parent db3457d commit c77664d
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 4 deletions.
10 changes: 8 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ if is_unixy
dep_wayland_client = dependency('wayland-client',
required: get_option('with_wayland'), version : '>=1.11')
dbus_dep = dependency('dbus-1', required: get_option('with_dbus')).partial_dependency(compile_args : true, includes : true)
dep_libdrm = dependency('libdrm', required: false).partial_dependency(compile_args : true, includes : true)
else
dep_x11 = null_dep
dep_wayland_client = null_dep
dbus_dep = null_dep
dep_libdrm = null_dep
endif

if dep_x11.found()
Expand All @@ -103,8 +105,8 @@ if dep_wayland_client.found()
vulkan_wsi_deps += dep_wayland_client
endif

if is_unixy and not dep_x11.found() and not dep_wayland_client.found()
error('At least one of "with_x11" and "with_wayland" should be enabled')
if is_unixy and not dep_x11.found() and not dep_wayland_client.found() and not dep_libdrm.found()
error('At least one of "with_x11" and "with_wayland" should be enabled or libdrm must be found')
endif

inc_common = [
Expand Down Expand Up @@ -186,6 +188,7 @@ else
dep_rt = null_dep
endif

if get_option('use_vulkan')
if dep_vulkan.found()
datadir = get_option('vulkan_datadir')
if datadir == ''
Expand All @@ -210,6 +213,9 @@ vk_enum_to_str = custom_target(
'--outdir', meson.current_build_dir()
],
)
else
vk_enum_to_str = []
endif

util_files = files(
'src/mesa/util/os_socket.c',
Expand Down
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ option('with_nvml', type : 'combo', value : 'enabled', choices: ['enabled', 'sys
option('with_xnvctrl', type : 'feature', value : 'enabled', description: 'Enable XNVCtrl support')
option('with_x11', type : 'feature', value : 'enabled')
option('with_wayland', type : 'feature', value : 'disabled')
option('use_vulkan', type : 'boolean', value : 'true')
option('with_dbus', type : 'feature', value : 'enabled')
option('with_dlsym', type : 'feature', value : 'disabled')
option('loglevel', type: 'combo', choices : ['trace', 'debug', 'info', 'warn', 'err', 'critical', 'off'], value : 'info', description: 'Max log level in non-debug build')
Expand Down
2 changes: 1 addition & 1 deletion src/gl/imgui_impl_opengl3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ static bool ImGui_ImplOpenGL3_CreateDeviceObjects()
"varying vec4 Frag_Color;\n"
"void main()\n"
"{\n"
" gl_FragColor = Frag_Color * vec4(1, 1, 1, texture2D(Texture, Frag_UV.st).r);\n"
" gl_FragColor = Frag_Color * texture2D(Texture, Frag_UV.st);\n"
"}\n";

const GLchar* fragment_shader_glsl_130 =
Expand Down
6 changes: 6 additions & 0 deletions src/gl/inject_egl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ void* get_egl_proc_address(const char* name) {
SPDLOG_ERROR("Failed to open " MANGOHUD_ARCH " libEGL.so.1: {}", dlerror());
} else {
pfn_eglGetProcAddress = reinterpret_cast<decltype(pfn_eglGetProcAddress)>(real_dlsym(handle, "eglGetProcAddress"));

if(gladLoadGLES2Loader((GLADloadproc)pfn_eglGetProcAddress) == 0) {
pfn_eglGetProcAddress = nullptr;
}
}
}

Expand Down Expand Up @@ -69,7 +73,9 @@ EXPORT_C_(unsigned int) eglSwapBuffers( void* dpy, void* surf)
using namespace std::chrono_literals;
if (fps_limit_stats.targetFrameTime > 0s){
fps_limit_stats.frameStart = Clock::now();
#ifdef HAVE_VULKAN
FpsLimiter(fps_limit_stats);
#endif
fps_limit_stats.frameEnd = Clock::now();
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/gl/inject_glx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ EXPORT_C_(void) glXSwapBuffers(void* dpy, void* drawable) {
using namespace std::chrono_literals;
if (!is_blacklisted() && fps_limit_stats.targetFrameTime > 0s){
fps_limit_stats.frameStart = Clock::now();
#ifdef HAVE_VULKAN
FpsLimiter(fps_limit_stats);
#endif
fps_limit_stats.frameEnd = Clock::now();
}
}
Expand All @@ -178,7 +180,9 @@ EXPORT_C_(int64_t) glXSwapBuffersMscOML(void* dpy, void* drawable, int64_t targe
using namespace std::chrono_literals;
if (!is_blacklisted() && fps_limit_stats.targetFrameTime > 0s){
fps_limit_stats.frameStart = Clock::now();
#ifdef HAVE_VULKAN
FpsLimiter(fps_limit_stats);
#endif
fps_limit_stats.frameEnd = Clock::now();
}
return ret;
Expand Down
10 changes: 10 additions & 0 deletions src/hud_elements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ void HudElements::engine_version(){
ImGui::TableNextRow(); ImGui::TableNextColumn();
ImGui::PushFont(HUDElements.sw_stats->font1);
if (HUDElements.is_vulkan) {
#ifdef HAVE_VULKAN
if ((HUDElements.sw_stats->engine == EngineTypes::DXVK || HUDElements.sw_stats->engine == EngineTypes::VKD3D)){
ImGui::TextColored(HUDElements.colors.engine,
"%s/%d.%d.%d", HUDElements.sw_stats->engineVersion.c_str(),
Expand All @@ -525,6 +526,7 @@ void HudElements::engine_version(){
HUDElements.sw_stats->version_vk.minor,
HUDElements.sw_stats->version_vk.patch);
}
#endif
} else {
ImGui::TextColored(HUDElements.colors.engine,
"%d.%d%s", HUDElements.sw_stats->version_gl.major, HUDElements.sw_stats->version_gl.minor,
Expand Down Expand Up @@ -680,8 +682,10 @@ void HudElements::image(){

HUDElements.image_infos.loaded = true;
if (HUDElements.is_vulkan) {
#ifdef HAVE_VULKAN
HUDElements.image_infos.vktexture = addTexture(value, &(HUDElements.image_infos.width), &(HUDElements.image_infos.height), maxwidth);
HUDElements.image_infos.valid = true;
#endif
} else {
HUDElements.image_infos.valid = GL_LoadTextureFromFile(value.c_str(),
&(HUDElements.image_infos.texture),
Expand All @@ -697,7 +701,9 @@ void HudElements::image(){
ImGui::TableNextRow(); ImGui::TableNextColumn();

if (HUDElements.is_vulkan) {
#ifdef HAVE_VULKAN
ImGui::Image(HUDElements.image_infos.vktexture, ImVec2(HUDElements.image_infos.width, HUDElements.image_infos.height));
#endif
} else {
ImGui::Image((void*)(intptr_t)(HUDElements.image_infos.texture), ImVec2(HUDElements.image_infos.width, HUDElements.image_infos.height));
}
Expand All @@ -711,8 +717,10 @@ void HudElements::background_image(){
if(HUDElements.background_image_infos.loaded == false) {
HUDElements.background_image_infos.loaded = true;
if (HUDElements.is_vulkan) {
#ifdef HAVE_VULKAN
HUDElements.background_image_infos.vktexture = addTexture(value, &(HUDElements.background_image_infos.width), &(HUDElements.background_image_infos.height), 0);
HUDElements.background_image_infos.valid = true;
#endif
} else {
HUDElements.background_image_infos.valid = GL_LoadTextureFromFile(value.c_str(),
&(HUDElements.background_image_infos.texture),
Expand All @@ -726,7 +734,9 @@ void HudElements::background_image(){
// render the image
if(HUDElements.background_image_infos.valid) {
if (HUDElements.is_vulkan) {
#ifdef HAVE_VULKAN
ImGui::GetBackgroundDrawList()->AddImage(HUDElements.background_image_infos.vktexture, ImVec2(0, 0), ImVec2(HUDElements.background_image_infos.width, HUDElements.background_image_infos.height));
#endif
} else {
ImGui::GetBackgroundDrawList()->AddImage((void*)(intptr_t)(HUDElements.background_image_infos.texture), ImVec2(0, 0), ImVec2(HUDElements.background_image_infos.width, HUDElements.background_image_infos.height));
}
Expand Down
2 changes: 1 addition & 1 deletion src/loadTextures.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#include "GL/gl.h"
//#include "GL/gl.h"
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#define STB_IMAGE_RESIZE_IMPLEMENTATION
Expand Down
4 changes: 4 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ if get_option('include_doc')
)
endif

if get_option('use_vulkan')
pre_args += '-DHAVE_VULKAN'
endif

configure_file(input : 'app/layer.json.in',
output : 'libMangoApp.json',
configuration : {'ld_libdir_mangohud' : ld_libdir_mangohud_vk},
Expand Down
6 changes: 6 additions & 0 deletions src/overlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ extern float g_overflow;
#endif
#include "logging.h"
#include "notify.h"
#ifdef HAVE_VULKAN
#include "vk_enum_to_str.h"
#include <vulkan/vk_layer.h>
#endif

using namespace std;

Expand Down Expand Up @@ -112,6 +114,7 @@ struct LOAD_DATA {
unsigned high_load;
};
#endif
#ifdef HAVE_VULKAN
/* Mapped from VkInstace/VkPhysicalDevice */
struct instance_data {
struct vk_instance_dispatch_table vtable;
Expand Down Expand Up @@ -141,6 +144,7 @@ struct device_data {

std::vector<struct queue_data *> queues;
};
#endif

#ifndef MANGOAPP_LAYER
extern struct fps_limit fps_limit_stats;
Expand Down Expand Up @@ -173,8 +177,10 @@ ImVec4 change_on_load_temp(LOAD_DATA& data, unsigned current);
float get_time_stat(void *_data, int _idx);
void stop_hw_updater();
ImTextureID addTexture(const std::string& filename, int* width, int* height, int maxwidth);
#ifdef HAVE_VULKAN
extern void control_client_check(struct device_data *device_data);
extern void process_control_socket(struct instance_data *instance_data);
#endif
#ifdef HAVE_DBUS
void render_mpris_metadata(overlay_params& params, mutexed_metadata& meta, uint64_t frame_timing);
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifdef HAVE_VULKAN
#ifdef _WIN32
#include <windows.h>
#endif
Expand Down Expand Up @@ -2114,3 +2115,4 @@ extern "C" VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL overlay_GetI
if (instance_data->vtable.GetInstanceProcAddr == NULL) return NULL;
return instance_data->vtable.GetInstanceProcAddr(instance, funcName);
}
#endif

0 comments on commit c77664d

Please sign in to comment.