Skip to content

Commit

Permalink
Make IDL spec compliant again (gpuweb#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
kainino0x authored and kdashg committed May 14, 2019
1 parent a5a5ea6 commit 51be483
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 40 deletions.
2 changes: 1 addition & 1 deletion spec/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ all: index.html webgpu.idl
index.html: index.bs
bikeshed -f spec index.bs

webgpu.idl: index.bs
webgpu.idl: index.bs extract-idl.py
python extract-idl.py index.bs > webgpu.idl

online:
Expand Down
10 changes: 6 additions & 4 deletions spec/extract-idl.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// **** This file is auto-generated. Do not edit. ****
"""
""".lstrip()

inputfilename = sys.argv[1]
inputfile = open(inputfilename)
Expand All @@ -28,15 +28,17 @@
idlStart = re.compile("\<script .*type=[\'\"]?idl")
idlStop = re.compile("\</script\>")

idlLineList = []
for line in inputfile:
line = line.rstrip()
if idlStart.search(line) != None:
recording = True
elif idlStop.search(line) != None:
idlList.append("\n")
recording = False
idlList.append("\n".join(idlLineList))
idlLineList = []
elif recording:
idlList.append(line)
idlLineList.append(line)

headerTemplate = Template(HEADER)
print headerTemplate.substitute(YEAR=date.today().year) + "\n".join(idlList)
print headerTemplate.substitute(YEAR=date.today().year) + "\n\n\n".join(idlList)
75 changes: 40 additions & 35 deletions spec/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ dictionary GPUExtent3D {
required u32 depth;
};

typedef sequence<any> GPUMappedBuffer; // [GPUBuffer, ArrayBuffer]

interface GPUObjectBase {
DOMString? label;
attribute DOMString? label;
};

dictionary GPUObjectDescriptorBase {
Expand All @@ -58,15 +60,15 @@ Buffers {#buffers}
typedef u32 GPUBufferUsageFlags;

interface GPUBufferUsage {
const u32 NONE = 0;
const u32 MAP_READ = 1;
const u32 MAP_WRITE = 2;
const u32 TRANSFER_SRC = 4;
const u32 TRANSFER_DST = 8;
const u32 INDEX = 16;
const u32 VERTEX = 32;
const u32 UNIFORM = 64;
const u32 STORAGE = 128;
const u32 NONE = 0x0000;
const u32 MAP_READ = 0x0001;
const u32 MAP_WRITE = 0x0002;
const u32 TRANSFER_SRC = 0x0004;
const u32 TRANSFER_DST = 0x0008;
const u32 INDEX = 0x0010;
const u32 VERTEX = 0x0020;
const u32 UNIFORM = 0x0040;
const u32 STORAGE = 0x0080;
};

dictionary GPUBufferDescriptor : GPUObjectDescriptorBase {
Expand Down Expand Up @@ -167,12 +169,12 @@ enum GPUTextureFormat {
typedef u32 GPUTextureUsageFlags;

interface GPUTextureUsage {
const u32 NONE = 0;
const u32 TRANSFER_SRC = 1;
const u32 TRANSFER_DST = 2;
const u32 SAMPLED = 4;
const u32 STORAGE = 8;
const u32 OUTPUT_ATTACHMENT = 16;
const u32 NONE = 0x00;
const u32 TRANSFER_SRC = 0x01;
const u32 TRANSFER_DST = 0x02;
const u32 SAMPLED = 0x04;
const u32 STORAGE = 0x08;
const u32 OUTPUT_ATTACHMENT = 0x10;
};

dictionary GPUTextureDescriptor : GPUObjectDescriptorBase {
Expand Down Expand Up @@ -271,10 +273,10 @@ Binding and Layout {#binding}
typedef u32 GPUShaderStageFlags;

interface GPUShaderStageBit {
const u32 NONE = 0;
const u32 VERTEX = 1;
const u32 FRAGMENT = 2;
const u32 COMPUTE = 4;
const u32 NONE = 0x0;
const u32 VERTEX = 0x1;
const u32 FRAGMENT = 0x2;
const u32 COMPUTE = 0x4;
};

enum GPUBindingType {
Expand Down Expand Up @@ -398,12 +400,12 @@ enum GPUBlendOperation {

typedef u32 GPUColorWriteFlags;
interface GPUColorWriteBits {
const u32 NONE = 0;
const u32 RED = 1;
const u32 GREEN = 2;
const u32 BLUE = 4;
const u32 ALPHA = 8;
const u32 ALL = 15;
const u32 NONE = 0x0;
const u32 RED = 0x1;
const u32 GREEN = 0x2;
const u32 BLUE = 0x4;
const u32 ALPHA = 0x8;
const u32 ALL = 0xF;
};

dictionary GPUBlendDescriptor {
Expand All @@ -417,7 +419,7 @@ dictionary GPUColorStateDescriptor {

required GPUBlendDescriptor alphaBlend;
required GPUBlendDescriptor colorBlend;
GPUColorWriteFlags writeMask = GPUColorWriteBits.ALL;
GPUColorWriteFlags writeMask = 0xF; // GPUColorWriteBits.ALL
};

enum GPUStencilOperation {
Expand Down Expand Up @@ -647,7 +649,7 @@ dictionary GPURenderPassColorAttachmentDescriptor {

required GPULoadOp loadOp;
required GPUStoreOp storeOp;
GPUColor clearColor = {r: 0.0, g: 0.0, b: 0.0, a: 1.0};
GPUColor clearColor; // defaults to {r: 0.0, g: 0.0, b: 0.0, a: 1.0}
};

dictionary GPURenderPassDepthStencilAttachmentDescriptor {
Expand Down Expand Up @@ -684,7 +686,7 @@ dictionary GPUTextureCopyView {
required GPUTexture texture;
u32 mipLevel = 0;
u32 arrayLayer = 0;
GPUOrigin3D origin = {x: 0, y: 0, z: 0};
GPUOrigin3D origin; // defaults to {x: 0, y: 0, z: 0}
};

interface GPUCommandBuffer : GPUObjectBase {
Expand Down Expand Up @@ -761,12 +763,12 @@ interface GPUCanvasContext {
GPUSwapChain configureSwapChain(GPUSwapChainDescriptor descriptor);

Promise<GPUTextureFormat> getSwapChainPreferredFormat(GPUDevice device);
}
};

dictionary GPUSwapChainDescriptor : GPUObjectDescriptorBase {
required GPUDevice device;
required GPUTextureFormat format;
GPUTextureUsageFlags usage = GPUTextureUsage.OUTPUT_ATTACHMENT;
GPUTextureUsageFlags usage = 0x10; // GPUTextureUsage.OUTPUT_ATTACHMENT
};

interface GPUSwapChain : GPUObjectBase {
Expand All @@ -793,8 +795,8 @@ interface GPUDevice : GPUObjectBase {
readonly attribute GPUAdapter adapter;

GPUBuffer createBuffer(GPUBufferDescriptor descriptor);
(GPUBuffer, ArrayBuffer) createBufferMapped(GPUBufferDescriptor descriptor);
Promise<(GPUBuffer, ArrayBuffer)> createBufferMappedAsync(GPUBufferDescriptor descriptor);
GPUMappedBuffer createBufferMapped(GPUBufferDescriptor descriptor);
Promise<GPUMappedBuffer> createBufferMappedAsync(GPUBufferDescriptor descriptor);
GPUTexture createTexture(GPUTextureDescriptor descriptor);
GPUSampler createSampler(GPUSamplerDescriptor descriptor);

Expand Down Expand Up @@ -912,8 +914,11 @@ dictionary GPUUncapturedErrorEventInit : EventInit {
required GPUError error;
};

// TODO: is it possible to expose the EventTarget only on the main thread?
partial interface GPUDevice : EventTarget {
// TODO: EventTarget is actually an interface, not a mixin, but it probably should be a mixin.
[Exposed=Window]
GPUDevice includes EventTarget;

partial interface GPUDevice {
[Exposed=Window]
attribute EventHandler onuncapturederror;
};
Expand Down

0 comments on commit 51be483

Please sign in to comment.