Skip to content

Commit

Permalink
Add WineD3D DX11 support
Browse files Browse the repository at this point in the history
* add environment variable SGL_WINED3D_DONT_VFLIP
* fix SGL_CMD_BUFFERSTORAGE which was incorrectly calling glBufferData
* bumped extensions from 52 to 81
* add icd_resize to glScissor
* add glActiveTextureARB, glClientActiveTextureARB
  • Loading branch information
dmaivel committed Jul 7, 2024
1 parent f6884f4 commit 4fda136
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 24 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Variables labeled with `host` get their values from the host/server when their o
| GLSL_VERSION_OVERRIDE | Digit.Digit | 4.4 | Override the GLSL version on the client side. Available for both Windows and Linux clients. |
| SGL_NET_OVER_SHARED | Ip:Port | | If networking is enabled, this environment variable must exist on the guest. Available for both Windows and Linux clients. |
| SGL_RUN_WITH_LOW_PRIORITY | Boolean | true | On older CPUs, by setting the process priority to low / `IDLE_PRIORITY_CLASS`, applications will run smoother as the kernel driver is given more CPU time. This may not be needed on systems with newer CPUs. Only available for Windows clients. |
| SGL_WINED3D_DONT_VFLIP | Boolean | false | If running a DirectX application via WineD3D, ensure this variable is set to `true` in order for the application to render the framebuffer in the proper orientation. Only available for Windows clients. |
### Network
Expand Down
1 change: 1 addition & 0 deletions inc/client/platform/windrv.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define _WINDRV_H_

void WinDrvSetModuleAddress(HMODULE module);
void WinDrvSetVflip(BOOL flip);

#endif
#endif
149 changes: 131 additions & 18 deletions src/client/glimpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,55 +136,149 @@ struct gl_map_buffer glimpl_map_buffer;

float glimpl_global_matrix_double_to_float[GLIMPL_MAX_COUNT_FOR_MATRIX_OP];

// #define NUM_EXTENSIONS 8
// static const char *glimpl_extensions_full = "GL_ARB_framebuffer_object GL_ARB_shading_language_100 GL_ARB_texture_storage GL_ARB_vertex_array_object GL_EXT_bgra GL_EXT_framebuffer_sRGB GL_EXT_paletted_texture GL_EXT_texture_filter_anisotropic";
// static const char glimpl_extensions_list[NUM_EXTENSIONS][64] = {
// "GL_ARB_framebuffer_object",
// "GL_ARB_shading_language_100",
// "GL_ARB_texture_storage",
// "GL_ARB_vertex_array_object",
// "GL_EXT_bgra",
// "GL_EXT_framebuffer_sRGB",
// "GL_EXT_paletted_texture",
// "GL_EXT_texture_filter_anisotropic"
// };

#define NUM_EXTENSIONS 52
static const char *glimpl_extensions_full = "GL_ARB_color_buffer_float GL_ARB_compressed_texture_pixel_storage GL_ARB_conservative_depth GL_ARB_copy_buffer GL_ARB_draw_buffers_blend GL_ARB_ES2_compatibility GL_ARB_ES3_compatibility GL_ARB_explicit_uniform_location GL_ARB_framebuffer_object GL_ARB_get_program_binary GL_ARB_half_float_pixel GL_ARB_internalformat_query GL_ARB_internalformat_query2 GL_ARB_map_buffer_alignment GL_ARB_map_buffer_range GL_ARB_multitexture GL_ARB_program_interface_query GL_ARB_separate_shader_objects GL_ARB_shader_precision GL_ARB_shading_language_420pack GL_ARB_shading_language_packing GL_ARB_sync GL_ARB_texture_buffer_object_rgb32 GL_ARB_texture_buffer_range GL_ARB_texture_compression_rgtc GL_ARB_texture_rectangle GL_ARB_texture_rg GL_ARB_texture_storage GL_ARB_texture_view GL_ARB_transform_feedback2 GL_ARB_transform_feedback3 GL_ARB_vertex_array_object GL_ARB_vertex_attrib_binding GL_ARB_viewport_array GL_EXT_abgr GL_EXT_bgra GL_EXT_bindable_uniform GL_EXT_draw_buffers2 GL_EXT_framebuffer_blit GL_EXT_framebuffer_multisample GL_EXT_framebuffer_object GL_EXT_framebuffer_sRGB GL_EXT_geometry_shader4 GL_EXT_gpu_shader4 GL_EXT_packed_depth_stencil GL_EXT_texture_compression_s3tc GL_EXT_texture_filter_anisotropic GL_EXT_texture_sRGB GL_NV_texture_barrier WGL_ARB_extensions_string WGL_ARB_framebuffer_sRGB WGL_ARB_pixel_format";
#define NUM_EXTENSIONS 81
static const char *glimpl_extensions_full = "GL_ARB_ES2_compatibility "
"GL_ARB_ES3_compatibility "
"GL_ARB_color_buffer_float "
"GL_ARB_compressed_texture_pixel_storage "
"GL_ARB_compute_shader "
"GL_ARB_conservative_depth "
"GL_ARB_copy_buffer "
"GL_ARB_cull_distance "
"GL_ARB_derivative_control "
"GL_ARB_draw_buffers_blend "
"GL_ARB_draw_elements_base_vertex "
"GL_ARB_draw_indirect "
"GL_ARB_draw_instanced "
"GL_ARB_explicit_uniform_location "
"GL_ARB_fragment_shader "
"GL_ARB_framebuffer_object "
"GL_ARB_geometry_shader4 "
"GL_ARB_get_program_binary "
"GL_ARB_gpu_shader5 "
"GL_ARB_half_float_pixel "
"GL_ARB_internalformat_query "
"GL_ARB_internalformat_query2 "
"GL_ARB_map_buffer_alignment "
"GL_ARB_map_buffer_range "
"GL_ARB_multitexture "
"GL_ARB_program_interface_query "
"GL_ARB_sampler_objects "
"GL_ARB_separate_shader_objects "
"GL_ARB_shader_atomic_counters "
"GL_ARB_shader_bit_encoding "
"GL_ARB_shader_image_load_store "
"GL_ARB_shader_image_size "
"GL_ARB_shader_objects "
"GL_ARB_shader_precision "
"GL_ARB_shading_language_420pack "
"GL_ARB_shading_language_packing "
"GL_ARB_sync "
"GL_ARB_tessellation_shader "
"GL_ARB_texture_buffer_object "
"GL_ARB_texture_buffer_object_rgb32 "
"GL_ARB_texture_buffer_range "
"GL_ARB_texture_compression_bptc "
"GL_ARB_texture_compression_rgtc "
"GL_ARB_texture_cube_map_array "
"GL_ARB_texture_gather "
"GL_ARB_texture_multisample "
"GL_ARB_texture_non_power_of_two "
"GL_ARB_texture_rectangle "
"GL_ARB_texture_rg "
"GL_ARB_texture_storage "
"GL_ARB_texture_swizzle "
"GL_ARB_texture_view "
"GL_ARB_transform_feedback2 "
"GL_ARB_transform_feedback3 "
"GL_ARB_uniform_buffer_object "
"GL_ARB_vertex_array_object "
"GL_ARB_vertex_attrib_binding "
"GL_ARB_vertex_buffer_object "
"GL_ARB_vertex_shader "
"GL_ARB_viewport_array "
"GL_EXT_abgr "
"GL_EXT_bgra "
"GL_EXT_bindable_uniform "
"GL_EXT_draw_buffers2 "
"GL_EXT_framebuffer_blit "
"GL_EXT_framebuffer_multisample "
"GL_EXT_framebuffer_object "
"GL_EXT_framebuffer_sRGB "
"GL_EXT_geometry_shader4 "
"GL_EXT_gpu_shader4 "
"GL_EXT_packed_depth_stencil "
"GL_EXT_polygon_offset_clamp "
"GL_EXT_shader_integer_mix "
"GL_EXT_texture_compression_s3tc "
"GL_EXT_texture_filter_anisotropic "
"GL_EXT_texture_sRGB "
"GL_EXT_texture_sRGB_decode "
"GL_NV_texture_barrier "
"WGL_ARB_extensions_string "
"WGL_ARB_framebuffer_sRGB "
"WGL_ARB_pixel_format";

static const char glimpl_extensions_list[NUM_EXTENSIONS][48] = {
"GL_ARB_ES2_compatibility",
"GL_ARB_ES3_compatibility",
"GL_ARB_color_buffer_float",
"GL_ARB_compressed_texture_pixel_storage",
"GL_ARB_compute_shader",
"GL_ARB_conservative_depth",
"GL_ARB_copy_buffer",
"GL_ARB_cull_distance",
"GL_ARB_derivative_control",
"GL_ARB_draw_buffers_blend",
"GL_ARB_ES2_compatibility",
"GL_ARB_ES3_compatibility",
"GL_ARB_draw_elements_base_vertex",
"GL_ARB_draw_indirect",
"GL_ARB_draw_instanced",
"GL_ARB_explicit_uniform_location",
"GL_ARB_fragment_shader",
"GL_ARB_framebuffer_object",
"GL_ARB_geometry_shader4",
"GL_ARB_get_program_binary",
"GL_ARB_gpu_shader5",
"GL_ARB_half_float_pixel",
"GL_ARB_internalformat_query",
"GL_ARB_internalformat_query2",
"GL_ARB_map_buffer_alignment",
"GL_ARB_map_buffer_range",
"GL_ARB_multitexture",
"GL_ARB_program_interface_query",
"GL_ARB_sampler_objects",
"GL_ARB_separate_shader_objects",
"GL_ARB_shader_atomic_counters",
"GL_ARB_shader_bit_encoding",
"GL_ARB_shader_image_load_store",
"GL_ARB_shader_image_size",
"GL_ARB_shader_objects",
"GL_ARB_shader_precision",
"GL_ARB_shading_language_420pack",
"GL_ARB_shading_language_packing",
"GL_ARB_sync",
"GL_ARB_tessellation_shader",
"GL_ARB_texture_buffer_object",
"GL_ARB_texture_buffer_object_rgb32",
"GL_ARB_texture_buffer_range",
"GL_ARB_texture_compression_bptc",
"GL_ARB_texture_compression_rgtc",
"GL_ARB_texture_cube_map_array",
"GL_ARB_texture_gather",
"GL_ARB_texture_multisample",
"GL_ARB_texture_non_power_of_two",
"GL_ARB_texture_rectangle",
"GL_ARB_texture_rg",
"GL_ARB_texture_storage",
"GL_ARB_texture_swizzle",
"GL_ARB_texture_view",
"GL_ARB_transform_feedback2",
"GL_ARB_transform_feedback3",
"GL_ARB_uniform_buffer_object",
"GL_ARB_vertex_array_object",
"GL_ARB_vertex_attrib_binding",
"GL_ARB_vertex_buffer_object",
"GL_ARB_vertex_shader",
"GL_ARB_viewport_array",
"GL_EXT_abgr",
"GL_EXT_bgra",
Expand All @@ -197,13 +291,16 @@ static const char glimpl_extensions_list[NUM_EXTENSIONS][48] = {
"GL_EXT_geometry_shader4",
"GL_EXT_gpu_shader4",
"GL_EXT_packed_depth_stencil",
"GL_EXT_polygon_offset_clamp",
"GL_EXT_shader_integer_mix",
"GL_EXT_texture_compression_s3tc",
"GL_EXT_texture_filter_anisotropic",
"GL_EXT_texture_sRGB",
"GL_EXT_texture_sRGB_decode",
"GL_NV_texture_barrier",
"WGL_ARB_extensions_string",
"WGL_ARB_framebuffer_sRGB",
"WGL_ARB_pixel_format"
"WGL_ARB_pixel_format",
};

static struct net_context *net_ctx = NULL;
Expand Down Expand Up @@ -1858,6 +1955,12 @@ void glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
pb_push(y);
pb_push(width);
pb_push(height);

/*
* icd hack for WineD3D bc it doesn't appear to call glViewport
*/
if (x == 0 && y == 0 && width > 64 && height > 64)
icd_resize(width, height);
}

void glTexParameterf(GLenum target, GLenum pname, GLfloat param)
Expand Down Expand Up @@ -3103,6 +3206,11 @@ void glActiveTexture(GLenum texture)
pb_push(texture);
}

void glActiveTextureARB(GLenum texture)
{
glActiveTexture(texture);
}

void glSampleCoverage(GLfloat value, GLboolean invert)
{
pb_push(SGL_CMD_SAMPLECOVERAGE);
Expand All @@ -3118,6 +3226,11 @@ void glClientActiveTexture(GLenum texture)
glimpl_client_active_texture = texture - (GLenum)GL_TEXTURE0;
}

void glClientActiveTextureARB(GLenum texture)
{
glClientActiveTexture(texture);
}

void glMultiTexCoord1d(GLenum target, GLdouble s)
{
pb_push(SGL_CMD_MULTITEXCOORD1D);
Expand Down
8 changes: 7 additions & 1 deletion src/client/platform/windrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,18 @@ static struct pfd_depth_info pfd_depths[4] = {
};

static HMODULE g_hModule = 0;
static BOOL do_vflip = TRUE;

void WinDrvSetModuleAddress(HMODULE module)
{
g_hModule = module;
}

void WinDrvSetVflip(BOOL flip)
{
do_vflip = flip;
}

static const char *wgl_extensions = "WGL_ARB_create_context WGL_ARB_create_context_profile WGL_ARB_extensions_string WGL_ARB_pixel_format";

const char* wglGetExtensionsStringARB(HDC hdc)
Expand Down Expand Up @@ -275,7 +281,7 @@ BOOL APIENTRY DrvSwapBuffers(HDC hdc)
Init = 1;
}

glimpl_swap_buffers(realWidth, realHeight, 1, GL_BGRA); /* to-do: fix overlay so vflip and -Height won't be needed */
glimpl_swap_buffers(realWidth, realHeight, do_vflip, GL_BGRA); /* to-do: fix overlay so vflip and -Height won't be needed */
SetDIBitsToDevice(hdc, 0, 0, realWidth, realHeight, 0, 0, 0, realHeight, Frame, &bmi, DIB_RGB_COLORS);
// StretchDIBits(hdc, 0, 0, realWidth, realHeight, 0, 0, realWidth, realHeight, Frame, &bmi, DIB_RGB_COLORS, SRCCOPY);

Expand Down
17 changes: 13 additions & 4 deletions src/client/winmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <client/glimpl.h>
#include <string.h>

static char sgl_run_with_low_priority_env_value[16];
static char env_value[16];

VOID Main()
{
Expand All @@ -23,12 +23,21 @@ BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved)
* by setting the priority of the program to "low", we give the kernel
* more CPU time, which is crucial because the kernel driver is how data
* between the VM and host move.
*
* appears to benefit systems with a single core the most
*/

DWORD result = GetEnvironmentVariableA("SGL_RUN_WITH_LOW_PRIORITY", sgl_run_with_low_priority_env_value, 16);
if (result == 0 || strcmp(sgl_run_with_low_priority_env_value, "true") == 0)
DWORD result = GetEnvironmentVariableA("SGL_RUN_WITH_LOW_PRIORITY", env_value, 16);
if (result == 0 || strcmp(env_value, "true") == 0)
SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS);

/*
* if running a directx application via WineD3D, we don't need to perform a
* vertical flip as the library appears to perform this action for us
*/
result = GetEnvironmentVariableA("SGL_WINED3D_DONT_VFLIP", env_value, 16);
if (strcmp(env_value, "true") == 0)
WinDrvSetVflip(FALSE);

WinDrvSetModuleAddress(module);
Main();
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/processor.c
Original file line number Diff line number Diff line change
Expand Up @@ -5361,7 +5361,7 @@ void sgl_cmd_processor_start(struct sgl_cmd_processor_args args)
size = *pb++,
use_uploaded = *pb++,
usage = *pb++;
glBufferData(target, size, use_uploaded ? uploaded : NULL, usage);
glBufferStorage(target, size, use_uploaded ? uploaded : NULL, usage);
break;
}
case SGL_CMD_CLEARTEXIMAGE: {
Expand Down

0 comments on commit 4fda136

Please sign in to comment.