-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
spirv: OpenCL printf support #24321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
spirv: OpenCL printf support #24321
Changes from all commits
2b12dd0
a230da2
96b6dba
199cda8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,6 +152,22 @@ const AsmValue = union(enum) { | |
.ty => |result| result, | ||
}; | ||
} | ||
|
||
/// Retrieve the result-id of this AsmValue, creating constants as needed. | ||
/// This is used by the assembler to convert constants and strings to result IDs. | ||
pub fn resultIdOrConstant(self: AsmValue, spv: *SpvModule) !Id { | ||
return switch (self) { | ||
.just_declared, | ||
.unresolved_forward_reference, | ||
.constant, | ||
=> unreachable, // TODO: Create constant integer instruction | ||
.string => |str| { | ||
return try spv.constStringGlobal(str); | ||
}, | ||
.value => |result| result, | ||
.ty => |result| result, | ||
}; | ||
} | ||
}; | ||
|
||
/// This map type maps results to values. Results can be addressed either by name (without the %), or by | ||
|
@@ -365,10 +381,18 @@ fn processTypeInstruction(self: *Assembler) !AsmValue { | |
const child_type = try self.resolveRefId(operands[1].ref_id); | ||
break :blk try self.spv.vectorType(operands[2].literal32, child_type); | ||
}, | ||
.OpTypeArray => { | ||
.OpTypeArray => blk: { | ||
// TODO: The length of an OpTypeArray is determined by a constant (which may be a spec constant), | ||
// and so some consideration must be taken when entering this in the type system. | ||
return self.todo("process OpTypeArray", .{}); | ||
const element_type = try self.resolveRefId(operands[1].ref_id); | ||
const length = try self.resolveRefId(operands[2].ref_id); | ||
const result_id = self.spv.allocId(); | ||
try section.emit(self.spv.gpa, .OpTypeArray, .{ | ||
.id_result = result_id, | ||
.element_type = element_type, | ||
.length = length, | ||
}); | ||
break :blk result_id; | ||
Comment on lines
+384
to
+395
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is unrelated change to the PR - I hoped to make better "string constants with c constraint" testing in tests/behavior/asm.zig. It does work though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I drop this commit since I am not trusted and no single test cover this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nah it looks correct |
||
}, | ||
.OpTypeRuntimeArray => blk: { | ||
const element_type = try self.resolveRefId(operands[1].ref_id); | ||
|
@@ -508,7 +532,7 @@ fn processGenericInstruction(self: *Assembler) !?AsmValue { | |
.ref_id => |index| { | ||
const result = try self.resolveRef(index); | ||
try section.ensureUnusedCapacity(self.spv.gpa, 1); | ||
section.writeOperand(spec.Id, result.resultId()); | ||
section.writeOperand(spec.Id, try result.resultIdOrConstant(self.spv)); | ||
}, | ||
.string => |offset| { | ||
const text = std.mem.sliceTo(self.inst.string_bytes.items[offset..], 0); | ||
|
@@ -559,7 +583,7 @@ fn resolveRef(self: *Assembler, ref: AsmValue.Ref) !AsmValue { | |
|
||
fn resolveRefId(self: *Assembler, ref: AsmValue.Ref) !Id { | ||
const value = try self.resolveRef(ref); | ||
return value.resultId(); | ||
return value.resultIdOrConstant(self.spv); | ||
ivanstepanovftw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/// Attempt to parse an instruction into `self.inst`. | ||
|
Uh oh!
There was an error while loading. Please reload this page.