Skip to content

Commit

Permalink
parse: honors api in require instruction
Browse files Browse the repository at this point in the history
The API in the require was honored before, but when the symbol from one
API require referenced the symbol from a different API require through
an alias, it was still brought in.

gh: Dav1dde#281
  • Loading branch information
Dav1dde committed Jun 18, 2020
1 parent ca498fb commit 6467cd6
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 5 deletions.
16 changes: 11 additions & 5 deletions glad/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,17 @@ def find(self, require, api, profile, recursive=False):
requirements.update(new_requirements)
open_requirements.extend(new_requirements)

alias = getattr(best_match, 'alias', None)
if recursive and alias is not None:
if alias not in requirements:
requirements.add(alias)
open_requirements.append(alias)
# Everything that is not a command alias is generated as a define, typedef etc.
# and not "copy-pasted", this means we have to resolve the alias of a type in order
# to be able to alias it properly.
# Commands are simply generated again instead of aliased.
# The `isinstance` check can be replaced with `if not alias in self.commands`.
if not isinstance(best_match, Command):
alias = getattr(best_match, 'alias', None)
if recursive and alias is not None:
if alias not in requirements:
requirements.add(alias)
open_requirements.append(alias)

yield best_match

Expand Down
18 changes: 18 additions & 0 deletions test/c/parse/002/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* VK_NV_ray_tracing depends on a type which depends on an aliased type.
* The aliased type is not part of the feature set.
* Make sure the aliased type is part generated, since the alias is done through a typedef.
*
* GLAD: $GLAD --out-path=$tmp --api="vulkan=1.1" --extensions="VK_NV_ray_tracing" c
* COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/vulkan.c -ldl
* RUN: $tmp/test
*/

#include <glad/vulkan.h>

int main(void) {
/* make sure something is referenced so stuff doesn't just get optimized away */
VkAccelerationStructureMemoryRequirementsInfoNV unused;
(void) unused;
return 0;
}
18 changes: 18 additions & 0 deletions test/c/parse/003/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* The GL_KHR_debug has suffixed symbols for GLES but symbols without suffix for GL.
* Make sure only the suffixed symbols appear in the generated output for gles.
* Related Issues: #281
*
* See also: 004
*
* GLAD: $GLAD --out-path=$tmp --api="gles2=3.1" --extensions="GL_KHR_debug" c
* COMPILE: ! $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gles2.c -ldl
* RUN: true
*/

#include <glad/gles2.h>

int main(void) {
(void) glObjectLabel;
return 0;
}
18 changes: 18 additions & 0 deletions test/c/parse/004/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* The GL_KHR_debug has suffixed symbols for GLES but symbols without suffix for GL.
* Make sure only the symbols without suffix appear in the generated output for gl.
* Related Issues: #281
*
* See also: 003
*
* GLAD: $GLAD --out-path=$tmp --api="gl:core=3.3" --extensions="GL_KHR_debug" c
* COMPILE: ! $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl
* RUN: true
*/

#include <glad/gl.h>

int main(void) {
(void) glObjectLabelKHR;
return 0;
}

0 comments on commit 6467cd6

Please sign in to comment.