Support Windows32 on bluegl as C backend (#6499)
This commit is contained in:
@@ -6,6 +6,7 @@ A new header is inserted each time a *tag* is created.
|
||||
## main branch
|
||||
|
||||
- engine: fix broken picking [⚠️ **Recompile Materials to get the fix**]
|
||||
- bluegl: support Windows32
|
||||
|
||||
## v1.31.3
|
||||
|
||||
|
||||
@@ -4,7 +4,13 @@ project(bluegl ASM)
|
||||
set(TARGET bluegl)
|
||||
set(PUBLIC_HDR_DIR include)
|
||||
|
||||
if (WIN32)
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(IS_64_BIT TRUE)
|
||||
else()
|
||||
set(IS_64_BIT FALSE)
|
||||
endif()
|
||||
|
||||
if (WIN32 AND IS_64_BIT)
|
||||
enable_language(ASM_MASM)
|
||||
set_property(SOURCE src/BlueGLCoreWindowsImpl.S PROPERTY LANGUAGE ASM_MASM)
|
||||
endif()
|
||||
@@ -19,7 +25,11 @@ set(SRCS
|
||||
|
||||
if (WIN32)
|
||||
set(SRCS ${SRCS} src/BlueGLWindows.cpp)
|
||||
set(SRCS ${SRCS} src/BlueGLCoreWindowsImpl.S)
|
||||
if(NOT IS_64_BIT)
|
||||
set(SRCS ${SRCS} src/BlueGLCoreWindows32Impl.cpp)
|
||||
else()
|
||||
set(SRCS ${SRCS} src/BlueGLCoreWindowsImpl.S)
|
||||
endif()
|
||||
elseif (APPLE AND NOT IOS)
|
||||
set(SRCS ${SRCS} src/BlueGLDarwin.cpp)
|
||||
set(SRCS ${SRCS} src/BlueGLCoreDarwinUniversalImpl.S)
|
||||
|
||||
+118
-42
@@ -33,14 +33,15 @@ def printApis(gl_apis):
|
||||
def parseFunctions(include_file, matcher):
|
||||
print('Parsing header %s...' % include_file)
|
||||
regex = re.compile(matcher)
|
||||
|
||||
functions = []
|
||||
|
||||
with open(include_file) as file:
|
||||
for line in file:
|
||||
match = regex.match(line)
|
||||
if match is not None:
|
||||
functions.append(match.group(1))
|
||||
functions.append({'return': match.group(1),
|
||||
'name': match.group(2),
|
||||
'parameters': match.group(3)})
|
||||
|
||||
return functions
|
||||
|
||||
@@ -223,9 +224,29 @@ def generateDefineHeader(api, functions, include_dir):
|
||||
with open(src_file, 'w') as file:
|
||||
file.write(header)
|
||||
for function in functions:
|
||||
file.write('#define %s %s\n' % (function, 'bluegl_' + function))
|
||||
file.write('#define %s %s\n' % (function['name'], 'bluegl_' + function['name']))
|
||||
file.write(footer)
|
||||
|
||||
|
||||
def parseArguments(parameters):
|
||||
arguments = []
|
||||
|
||||
if parameters != 'void':
|
||||
for parameter in parameters.split(","):
|
||||
beg = parameter.rfind('*')
|
||||
if beg == -1:
|
||||
beg = parameter.rfind(' ')
|
||||
beg += 1
|
||||
|
||||
end = parameter.rfind('[')
|
||||
if end == -1:
|
||||
end = len(parameter)
|
||||
|
||||
arguments.append(parameter[beg:end])
|
||||
|
||||
return arguments
|
||||
|
||||
|
||||
def generateProxies(api, functions, output_dir, platforms):
|
||||
suffix = api['suffix']
|
||||
|
||||
@@ -244,7 +265,6 @@ def generateProxies(api, functions, output_dir, platforms):
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**********************************************************************************************
|
||||
* Generated by bluegl/bluegl-gen.py
|
||||
* DO NOT EDIT
|
||||
@@ -266,23 +286,52 @@ def generateProxies(api, functions, output_dir, platforms):
|
||||
; See the License for the specific language governing permissions and
|
||||
; limitations under the License.
|
||||
;
|
||||
|
||||
;
|
||||
; Generated by bluegl/bluegl-gen.py
|
||||
; DO NOT EDIT
|
||||
;
|
||||
|
||||
.code
|
||||
''' % {
|
||||
'year': datetime.now().year,
|
||||
}
|
||||
|
||||
headerC = '''/*
|
||||
* Copyright (C) %(year)d The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**********************************************************************************************
|
||||
* Generated by bluegl/bluegl-gen.py
|
||||
* DO NOT EDIT
|
||||
**********************************************************************************************/
|
||||
|
||||
#include <bluegl/BlueGL.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
''' % {
|
||||
'year': datetime.now().year,
|
||||
}
|
||||
|
||||
osSpecificHeader = {
|
||||
'Linux': header ,
|
||||
'LinuxAArch64': header ,
|
||||
'Darwin': header ,
|
||||
'DarwinAArch64': header ,
|
||||
'Windows': headerMasM
|
||||
'Linux': header,
|
||||
'LinuxAArch64': header,
|
||||
'Darwin': header,
|
||||
'DarwinAArch64': header,
|
||||
'Windows': headerMasM,
|
||||
'Windows32': headerC,
|
||||
}
|
||||
|
||||
osSpecificFooter = {
|
||||
@@ -290,63 +339,89 @@ def generateProxies(api, functions, output_dir, platforms):
|
||||
'LinuxAArch64': '' ,
|
||||
'Darwin': '',
|
||||
'DarwinAArch64': '',
|
||||
'Windows': 'end\n'
|
||||
'Windows': 'end\n',
|
||||
'Windows32': '''
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
'''
|
||||
}
|
||||
|
||||
code = {
|
||||
'Linux': '''
|
||||
.global bluegl_%(function)s
|
||||
.type bluegl_%(function)s, %%function
|
||||
bluegl_%(function)s:
|
||||
mov __blue_gl%(suffix)s_%(function)s@GOTPCREL(%%rip), %%r11
|
||||
.global bluegl_%(name)s
|
||||
.type bluegl_%(name)s, %%function
|
||||
bluegl_%(name)s:
|
||||
mov __blue_gl%(suffix)s_%(name)s@GOTPCREL(%%rip), %%r11
|
||||
jmp *(%%r11)
|
||||
''',
|
||||
'LinuxAArch64': '''
|
||||
.align 2
|
||||
.global bluegl_%(function)s
|
||||
.type bluegl_%(function)s, %%function
|
||||
bluegl_%(function)s:
|
||||
adrp x16, :got:__blue_gl%(suffix)s_%(function)s
|
||||
ldr x16, [x16, #:got_lo12:__blue_gl%(suffix)s_%(function)s]
|
||||
.global bluegl_%(name)s
|
||||
.type bluegl_%(name)s, %%function
|
||||
bluegl_%(name)s:
|
||||
adrp x16, :got:__blue_gl%(suffix)s_%(name)s
|
||||
ldr x16, [x16, #:got_lo12:__blue_gl%(suffix)s_%(name)s]
|
||||
ldr x16, [x16]
|
||||
br x16
|
||||
.size bluegl_%(function)s, .-bluegl_%(function)s
|
||||
.size bluegl_%(name)s, .-bluegl_%(name)s
|
||||
''',
|
||||
'Darwin': '''
|
||||
.private_extern _bluegl_%(function)s
|
||||
_bluegl_%(function)s:
|
||||
mov ___blue_gl%(suffix)s_%(function)s@GOTPCREL(%%rip), %%r11
|
||||
.private_extern _bluegl_%(name)s
|
||||
_bluegl_%(name)s:
|
||||
mov ___blue_gl%(suffix)s_%(name)s@GOTPCREL(%%rip), %%r11
|
||||
jmp *(%%r11)
|
||||
''',
|
||||
'DarwinAArch64': '''
|
||||
.private_extern _bluegl_%(function)s
|
||||
.private_extern _bluegl_%(name)s
|
||||
.align 2
|
||||
_bluegl_%(function)s:
|
||||
adrp x16, ___blue_gl%(suffix)s_%(function)s@GOTPAGE
|
||||
ldr x16, [x16, ___blue_gl%(suffix)s_%(function)s@GOTPAGEOFF]
|
||||
_bluegl_%(name)s:
|
||||
adrp x16, ___blue_gl%(suffix)s_%(name)s@GOTPAGE
|
||||
ldr x16, [x16, ___blue_gl%(suffix)s_%(name)s@GOTPAGEOFF]
|
||||
ldr x16, [x16]
|
||||
br x16
|
||||
''',
|
||||
'Windows': '''
|
||||
extrn __blue_gl%(suffix)s_%(function)s: qword
|
||||
bluegl_%(function)s proc
|
||||
mov r11, __blue_gl%(suffix)s_%(function)s
|
||||
extrn __blue_gl%(suffix)s_%(name)s: qword
|
||||
bluegl_%(name)s proc
|
||||
mov r11, __blue_gl%(suffix)s_%(name)s
|
||||
jmp r11
|
||||
bluegl_%(function)s endp
|
||||
bluegl_%(name)s endp
|
||||
''',
|
||||
'Windows32': '''
|
||||
extern void* __blue_gl%(suffix)s_%(name)s;
|
||||
%(return)sAPIENTRY bluegl_%(name)s (%(parameters)s) {
|
||||
typedef %(return)s(APIENTRYP PFN_%(name)s) (%(parameters)s);
|
||||
return ((PFN_%(name)s)__blue_gl%(suffix)s_%(name)s)(%(arguments)s);
|
||||
}
|
||||
'''
|
||||
}
|
||||
|
||||
extension = {
|
||||
'Linux': 'S',
|
||||
'LinuxAArch64': 'S',
|
||||
'Darwin': 'S',
|
||||
'DarwinAArch64': 'S',
|
||||
'Windows': 'S',
|
||||
'Windows32': 'cpp',
|
||||
}
|
||||
|
||||
for platform in platforms:
|
||||
src_file = os.path.join(output_dir, 'BlueGL%s%sImpl.S' % (suffix, platform))
|
||||
src_file = os.path.join(output_dir, 'BlueGL%s%sImpl.%s' % (suffix, platform, extension[platform]))
|
||||
print('Generating proxy %s...' % src_file)
|
||||
|
||||
with open(src_file, 'w') as file:
|
||||
file.write(osSpecificHeader[platform])
|
||||
for function in functions:
|
||||
file.write(code[platform] % {'function': function, 'suffix': suffix})
|
||||
file.write(code[platform] % {
|
||||
'suffix': suffix,
|
||||
'return': function['return'],
|
||||
'name': function['name'],
|
||||
'parameters': function['parameters'],
|
||||
"arguments": ", ".join(parseArguments(function['parameters']))
|
||||
})
|
||||
file.write(osSpecificFooter[platform])
|
||||
|
||||
|
||||
def generateSource(api, functions, output_dir):
|
||||
suffix = api['suffix'] if api['suffix'] != 'Core' else ''
|
||||
gl_suffix = '_gl_' + suffix.lower() if len(suffix) > 0 else ''
|
||||
@@ -399,11 +474,11 @@ struct {
|
||||
file.write(header)
|
||||
file.write("extern \"C\" {\n")
|
||||
for function in functions:
|
||||
file.write('void* __blue_gl%s_%s;\n' % (api['suffix'], function))
|
||||
file.write('void* __blue_gl%s_%s;\n' % (api['suffix'], function['name']))
|
||||
file.write("}\n")
|
||||
file.write(struct_header)
|
||||
for function in functions:
|
||||
file.write(' { &__blue_gl%s_%s, "%s" },\n' % (api['suffix'], function, function))
|
||||
file.write(' { &__blue_gl%s_%s, "%s" },\n' % (api['suffix'], function['name'], function['name']))
|
||||
file.write(functions_footer)
|
||||
|
||||
file.write("size_t %s%sNumFunctions = %d;" % ("blue", api['suffix'], len(functions)))
|
||||
@@ -411,7 +486,7 @@ struct {
|
||||
|
||||
|
||||
def generateApis(apis, include_dir, output_dir):
|
||||
platforms = ['Linux', 'LinuxAArch64', 'Darwin', 'DarwinAArch64', 'Windows']
|
||||
platforms = ['Linux', 'LinuxAArch64', 'Darwin', 'DarwinAArch64', 'Windows', 'Windows32']
|
||||
|
||||
for api in apis:
|
||||
functions = []
|
||||
@@ -420,7 +495,7 @@ def generateApis(apis, include_dir, output_dir):
|
||||
functions += parseFunctions(include_file, api['matcher'])
|
||||
|
||||
# remove duplicates
|
||||
functions = list(set(functions))
|
||||
functions = list({function['name']: function for function in functions}.values())
|
||||
print('Found %s functions' % len(functions))
|
||||
|
||||
generateHeader(api, functions, include_dir, output_dir)
|
||||
@@ -428,6 +503,7 @@ def generateApis(apis, include_dir, output_dir):
|
||||
generateProxies(api, functions, output_dir, platforms)
|
||||
generateSource(api, functions, output_dir)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
gl_apis = [
|
||||
# OpenGL Core (4.x+) support
|
||||
@@ -438,7 +514,7 @@ if __name__ == '__main__':
|
||||
'suffix': 'Core',
|
||||
'directory': 'GL',
|
||||
'headers': ['glcorearb.h', 'glext.h'],
|
||||
'matcher': r'GLAPI.*APIENTRY\s+(\w+)',
|
||||
'matcher': r'GLAPI\s+(.*)APIENTRY\s+(\w+)\s\((.*)\)',
|
||||
'defines': ['GL_GLEXT_PROTOTYPES']
|
||||
},
|
||||
# Legacy OpenGL support
|
||||
@@ -449,7 +525,7 @@ if __name__ == '__main__':
|
||||
'suffix': 'Legacy',
|
||||
'directory': 'Legacy',
|
||||
'headers': ['gl.h', 'glext.h'],
|
||||
'matcher': r'GLAPI.*APIENTRY\s+(\w+)',
|
||||
'matcher': r'GLAPI\s+(.*)APIENTRY\s+(\w+)\s\((.*)\)',
|
||||
'defines': []
|
||||
}
|
||||
]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
+2564
-2564
File diff suppressed because it is too large
Load Diff
+20369
-20370
File diff suppressed because it is too large
Load Diff
+12748
-12749
File diff suppressed because it is too large
Load Diff
+25495
-25496
File diff suppressed because it is too large
Load Diff
+15311
-15312
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+15311
-15313
File diff suppressed because it is too large
Load Diff
+5127
-5127
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user