Skip to content

Commit f7c56ff

Browse files
Out parameters to handles now use ref instead of * (#3)
* Out parameters to handles now use ref instead of * * Bumped cosmicolor version
1 parent 9b16e21 commit f7c56ff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+109
-100
lines changed

modules/vulkan/dub.sdl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ dependency "inmath" version="~>1.3"
1919
libs "vulkan-1" platform="windows"
2020
lflags "/libpath:$VULKAN_SDK\\Lib\\" platform="windows"
2121

22-
preBuildCommands "dub run :vulkan-generator -- vk"
23-
2422
# Posix Platforms don't need $VULKAN_SDL
2523
libs "vulkan" platform="posix"
2624

modules/vulkan/generator/dub.sdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ workingDirectory ".."
99

1010
stringImportPaths "text"
1111

12-
dependency "cosmicolor" version="~>0.1.4"
12+
dependency "cosmicolor" version="~>0.1.5"
1313
dependency "yxml" version="~>0.1.7"
1414

1515
configuration "application" {

modules/vulkan/generator/source/emitter.d

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -356,15 +356,7 @@ class VkRegistryEmitter {
356356
file.writeln();
357357
}
358358

359-
if (command.params.empty) {
360-
file.writefln!"extern %s %s();"(command.type, command.name);
361-
} else {
362-
file.openf!"extern %s %s("(command.type, command.name);
363-
foreach (param; command.params) {
364-
file.writefln!"%s %s,"(param.type, param.safename);
365-
}
366-
file.close(");");
367-
}
359+
emitCommand(command);
368360
}
369361

370362
if (feature.minor > 0) {
@@ -739,6 +731,18 @@ class VkRegistryEmitter {
739731
}
740732
}
741733

734+
private void emitCommand(const ref VkCommand command) {
735+
if (command.params.empty) {
736+
file.writefln!"extern %s %s();"(command.type, command.name);
737+
} else {
738+
file.openf!"extern %s %s("(command.type, command.name);
739+
foreach (param; command.params) {
740+
file.writefln!"%s %s,"(param.type, param.safename);
741+
}
742+
file.close(");");
743+
}
744+
}
745+
742746
private void emitDeprecation(bool deprecated_, string reason) {
743747
if (deprecated_) {
744748
file.writefln!"deprecated(\"%s\")"(reason);

modules/vulkan/generator/source/parser.d

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,7 @@ class VkRegistryParser {
397397

398398
auto postfix = child.textContent[$ - postNameLength + member.name.length .. $ - commentLength];
399399
auto whole = child.textContent[0 .. $ - postNameLength] ~ postfix;
400-
member.type = parseTypeString(type.textContent, whole, &member.width);
401-
402-
// if (auto length = child.firstChildByTagName("enum")) {
403-
// member.type = format!"%s[%s]"(member.type, length.textContent);
404-
// }
400+
member.type = parseTypeString(type.textContent, whole, width: &member.width);
405401
}
406402
}
407403

@@ -465,10 +461,6 @@ class VkRegistryParser {
465461
auto postfix = child.textContent[$ - postNameLength + member.name.length .. $ - commentLength];
466462
auto whole = child.textContent[0 .. $ - postNameLength] ~ postfix;
467463
member.type = parseTypeString(type.textContent, whole);
468-
469-
// if (auto length = child.firstChildByTagName("enum")) {
470-
// member.type = format!"%s[%s]"(member.type, length.textContent);
471-
// }
472464
}
473465
}
474466

@@ -748,6 +740,12 @@ class VkRegistryParser {
748740

749741
VkParam param;
750742

743+
if (auto length = child.getAttribute("len")) {
744+
param.optional = true;
745+
} else if (auto optional = child.getAttribute("optional")) {
746+
param.optional = true;
747+
}
748+
751749
if (auto name = child.firstChildByTagName("name")) {
752750
param.name = name.textContent.idup;
753751

@@ -759,7 +757,7 @@ class VkRegistryParser {
759757
if (auto type = child.firstChildByTagName("type")) {
760758
auto postfix = child.textContent[$ - postNameLength + param.name.length .. $];
761759
auto whole = child.textContent[0 .. $ - postNameLength] ~ postfix;
762-
param.type = parseTypeString(type.textContent, whole);
760+
param.type = parseTypeString(type.textContent, whole, refify: !param.optional);
763761
}
764762
}
765763

@@ -1066,11 +1064,13 @@ class VkRegistryParser {
10661064
*
10671065
* Params:
10681066
* name = A type in string form as obtained from an XML document.
1067+
* width = Out parameter for returning the bit width of bitfields.
1068+
* refify = Whether to convert pointers to handles into refs.
10691069
*
10701070
* Returns: the D equivalent of the given type.
10711071
*/
1072-
private static string parseTypeString(xmlstring name, uint* width = null) {
1073-
return parseTypeString(name, name, width);
1072+
private string parseTypeString(xmlstring name, uint* width = null, bool refify = false) {
1073+
return parseTypeString(name, name, width, refify);
10741074
}
10751075

10761076
/**
@@ -1079,10 +1079,12 @@ class VkRegistryParser {
10791079
* Params:
10801080
* name = A type in string form as obtained from an XML document.
10811081
* whole = The surrounding text of the given type name.
1082+
* width = Out parameter for returning the bit width of bitfields.
1083+
* refify = Whether to convert pointers to handles into refs.
10821084
*
10831085
* Returns: the D equivalent of the given type.
10841086
*/
1085-
private static string parseTypeString(xmlstring name, xmlstring whole, uint* width = null) {
1087+
private string parseTypeString(xmlstring name, xmlstring whole, uint* width = null, bool refify = false) {
10861088
import std.ascii;
10871089

10881090
string result = typemap.get(name, name).idup;
@@ -1132,6 +1134,11 @@ class VkRegistryParser {
11321134
}
11331135
}
11341136

1137+
// Convert pointers to handles into refs instead.
1138+
if (refify && name in registry.handles && result.endsWith("*")) {
1139+
result = format!"ref %s"(result[0 .. $ - 1]);
1140+
}
1141+
11351142
return result;
11361143
}
11371144
}

modules/vulkan/source/vulkan/arm/data_graph.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ alias PFN_vkCreateDataGraphPipelineSessionARM = VkResult function(
286286
VkDevice device,
287287
const(VkDataGraphPipelineSessionCreateInfoARM)* pCreateInfo,
288288
const(VkAllocationCallbacks)* pAllocator,
289-
VkDataGraphPipelineSessionARM* pSession,
289+
ref VkDataGraphPipelineSessionARM pSession,
290290
);
291291

292292
alias PFN_vkGetDataGraphPipelineSessionBindPointRequirementsARM = VkResult function(

modules/vulkan/source/vulkan/arm/tensors.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ alias PFN_vkCreateTensorARM = VkResult function(
275275
VkDevice device,
276276
const(VkTensorCreateInfoARM)* pCreateInfo,
277277
const(VkAllocationCallbacks)* pAllocator,
278-
VkTensorARM* pTensor,
278+
ref VkTensorARM pTensor,
279279
);
280280

281281
alias PFN_vkDestroyTensorARM = void function(
@@ -288,7 +288,7 @@ alias PFN_vkCreateTensorViewARM = VkResult function(
288288
VkDevice device,
289289
const(VkTensorViewCreateInfoARM)* pCreateInfo,
290290
const(VkAllocationCallbacks)* pAllocator,
291-
VkTensorViewARM* pView,
291+
ref VkTensorViewARM pView,
292292
);
293293

294294
alias PFN_vkDestroyTensorViewARM = void function(

0 commit comments

Comments
 (0)