Novidia: support (and allow forcing) BGRA texture uploads for extra performance
This commit is contained in:
@@ -11,7 +11,7 @@ void h_uploadModelTransformBuf_TexImage(DWORD* a1, int a2)
|
||||
|
||||
glActiveTexture(GL_TEXTURE8);
|
||||
glBindTexture(GL_TEXTURE_1D, buf_tex);
|
||||
glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA32F, 0x3000 / sizeof(float) / 4, 0, GL_RGBA, GL_FLOAT, *(float**)0x1411a3330);
|
||||
glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA32F, 0x3000 / sizeof(float) / 4, 0, tex_upload_format, GL_FLOAT, *(float**)0x1411a3330);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
void h_uploadModelTransformBuf_TexSubImage(DWORD* a1, int a2)
|
||||
@@ -20,7 +20,7 @@ void h_uploadModelTransformBuf_TexSubImage(DWORD* a1, int a2)
|
||||
|
||||
glActiveTexture(GL_TEXTURE8);
|
||||
glBindTexture(GL_TEXTURE_1D, buf_tex);
|
||||
glTexSubImage1D(GL_TEXTURE_1D, 0, 0, 0x3000 / sizeof(float) / 4, GL_RGBA, GL_FLOAT, *(float**)0x1411a3330);
|
||||
glTexSubImage1D(GL_TEXTURE_1D, 0, 0, 0x3000 / sizeof(float) / 4, tex_upload_format, GL_FLOAT, *(float**)0x1411a3330);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
|
||||
@@ -93,6 +93,35 @@ void h_glutSetCursor(int cursor)
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
|
||||
// BGRA texture uploads seem to run a little faster
|
||||
// ideally just asking the driver what to use would be fine,
|
||||
// but my driver says GL_RGBA is better (contrary to my testing)
|
||||
if (force_BGRA_upload)
|
||||
{
|
||||
tex_upload_format = GL_BGRA;
|
||||
}
|
||||
else
|
||||
{
|
||||
// ask the driver which image format to use for uploads
|
||||
glGetInternalformativ(GL_TEXTURE_1D, GL_RGBA32F, GL_TEXTURE_IMAGE_FORMAT, 1, &tex_upload_format);
|
||||
printf("[Novidia] Driver preferred texture upload format: %d\n", tex_upload_format);
|
||||
}
|
||||
|
||||
if (tex_upload_format == GL_BGRA)
|
||||
{
|
||||
printf("[Novidia] Using BGRA texture uploads\n");
|
||||
// set swizzling to make shader read as if it's RGBA still
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_SWIZZLE_R, GL_BLUE);
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_SWIZZLE_B, GL_RED);
|
||||
}
|
||||
else
|
||||
{
|
||||
tex_upload_format = GL_RGBA;
|
||||
printf("[Novidia] Using RGBA texture uploads\n");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
DetourTransactionBegin();
|
||||
@@ -139,6 +168,7 @@ using namespace PluginConfig;
|
||||
|
||||
PluginConfigOption config[] = {
|
||||
{ CONFIG_BOOLEAN, new PluginConfigBooleanData{ L"use_TexSubImage", L"general", CONFIG_FILE, L"Use glTexSubImage", L"glTexSubImage should offer higher performance, but stuttering has been reported when it is used.\nTry disabling this if you have issues.", true, false } },
|
||||
{ CONFIG_BOOLEAN, new PluginConfigBooleanData{ L"force_BGRA_upload", L"general", CONFIG_FILE, L"Force BGRA Texture Uploads", L"BGRA format uploads seem to run faster (on some hardware), but drivers may suggest RGBA instead.\nUsing this forces uploads to use the BGRA format.\n\nDisabling this may decrease or improve performance.", true, false } },
|
||||
};
|
||||
|
||||
extern "C" __declspec(dllexport) LPCWSTR GetPluginName(void)
|
||||
|
||||
@@ -25,6 +25,8 @@ int __stdcall stub() { return 1; }
|
||||
|
||||
|
||||
bool use_TexSubImage;
|
||||
bool force_BGRA_upload;
|
||||
GLint tex_upload_format;
|
||||
|
||||
std::wstring ExePath() {
|
||||
WCHAR buffer[MAX_PATH];
|
||||
@@ -45,4 +47,5 @@ LPCWSTR CONFIG_FILE = CONFIG_FILE_STRING.c_str();
|
||||
void loadConfig()
|
||||
{
|
||||
use_TexSubImage = GetPrivateProfileIntW(L"general", L"use_TexSubImage", 1, CONFIG_FILE) > 0 ? true : false;
|
||||
force_BGRA_upload = GetPrivateProfileIntW(L"general", L"force_BGRA_upload", 1, CONFIG_FILE) > 0 ? true : false;
|
||||
}
|
||||
@@ -22,14 +22,20 @@ typedef char GLchar;
|
||||
#define GL_TEXTURE_1D 0x0de0
|
||||
#define GL_TEXTURE_2D 0x0de1
|
||||
#define GL_FLOAT 0x1406
|
||||
#define GL_RED 0x1903
|
||||
#define GL_GREEN 0x1904
|
||||
#define GL_BLUE 0x1905
|
||||
#define GL_ALPHA 0x1906
|
||||
#define GL_RGBA 0x1908
|
||||
#define GL_NEAREST 0x2600
|
||||
#define GL_TEXTURE_MAG_FILTER 0x2800
|
||||
#define GL_TEXTURE_MIN_FILTER 0x2801
|
||||
#define GL_TEXTURE_WRAP_S 0x2802
|
||||
#define GL_TEXTURE_WRAP_T 0x2803
|
||||
#define GL_BGRA 0x80e1
|
||||
#define GL_CLAMP_TO_BORDER 0x812d
|
||||
#define GL_CLAMP_TO_EDGE 0x812f
|
||||
#define GL_TEXTURE_IMAGE_FORMAT 0x828f
|
||||
#define GL_TEXTURE0 0x84c0
|
||||
#define GL_TEXTURE8 0x84c8
|
||||
#define GL_BUFFER_SIZE 0x8764
|
||||
@@ -44,6 +50,11 @@ typedef char GLchar;
|
||||
#define GL_CURRENT_PROGRAM 0x8b8d
|
||||
#define GL_VERTEX_PROGRAM_PARAMETER_BUFFER_NV 0x8da2
|
||||
#define GL_FRAGMENT_PROGRAM_PARAMETER_BUFFER_NV 0x8da4
|
||||
#define GL_TEXTURE_SWIZZLE_R 0x8e42
|
||||
#define GL_TEXTURE_SWIZZLE_G 0x8e43
|
||||
#define GL_TEXTURE_SWIZZLE_B 0x8e44
|
||||
#define GL_TEXTURE_SWIZZLE_A 0x8e45
|
||||
#define GL_TEXTURE_SWIZZLE_RGBA 0x8e46
|
||||
#define GL_SHADER_STORAGE_BUFFER 0x90d2
|
||||
#define GL_COMPUTE_SHADER 0x91b9
|
||||
#define GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT 0x00000001
|
||||
@@ -60,6 +71,7 @@ void(__cdecl* glTexSubImage1D)(GLenum target, GLint level, GLint xoffset, GLsize
|
||||
// these are all imported using wglGetProcAddress and can't be initialised until after the OpenGL context is created
|
||||
void(__cdecl* glActiveTexture)(GLenum texture);
|
||||
void(__cdecl* glTexStorage1D)(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width);
|
||||
void(__cdecl* glGetInternalformativ)(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params);
|
||||
void(__cdecl* glBindBuffer)(GLenum target, GLuint buffer);
|
||||
void(__cdecl* glBindBufferARB)(GLenum target, GLuint buffer);
|
||||
void(__cdecl* glBufferData)(GLenum target, GLsizeiptr size, const void* data, GLenum usage);
|
||||
@@ -78,6 +90,7 @@ struct {
|
||||
{&glTexSubImage1D, "glTexSubImage1D", false},
|
||||
{&glActiveTexture, "glActiveTexture", true},
|
||||
{&glTexStorage1D, "glTexStorage1D", true},
|
||||
{&glGetInternalformativ, "glGetInternalformativ", true},
|
||||
{&glBindBuffer, "glBindBuffer", true},
|
||||
{&glBindBufferARB, "glBindBufferARB", true},
|
||||
{&glBufferData, "glBufferData", true},
|
||||
|
||||
Reference in New Issue
Block a user