Capitalize C types dawn -> Dawn

This is to match Chromium style.

Change-Id: Ic97cc03e2291c653ade9662ba3d5e629872b10ad
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/5482
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
Austin Eng 2019-03-11 16:52:42 +00:00 committed by Commit Bot service account
parent 97ffc1a8aa
commit 45f9730855
87 changed files with 596 additions and 596 deletions

View File

@ -17,24 +17,24 @@
#include "utils/DawnHelpers.h" #include "utils/DawnHelpers.h"
#include "utils/SystemUtils.h" #include "utils/SystemUtils.h"
dawnDevice device; DawnDevice device;
dawnQueue queue; DawnQueue queue;
dawnSwapChain swapchain; DawnSwapChain swapchain;
dawnRenderPipeline pipeline; DawnRenderPipeline pipeline;
dawnTextureFormat swapChainFormat; DawnTextureFormat swapChainFormat;
void init() { void init() {
device = CreateCppDawnDevice().Release(); device = CreateCppDawnDevice().Release();
queue = dawnDeviceCreateQueue(device); queue = dawnDeviceCreateQueue(device);
{ {
dawnSwapChainDescriptor descriptor; DawnSwapChainDescriptor descriptor;
descriptor.nextInChain = nullptr; descriptor.nextInChain = nullptr;
descriptor.implementation = GetSwapChainImplementation(); descriptor.implementation = GetSwapChainImplementation();
swapchain = dawnDeviceCreateSwapChain(device, &descriptor); swapchain = dawnDeviceCreateSwapChain(device, &descriptor);
} }
swapChainFormat = static_cast<dawnTextureFormat>(GetPreferredSwapChainTextureFormat()); swapChainFormat = static_cast<DawnTextureFormat>(GetPreferredSwapChainTextureFormat());
dawnSwapChainConfigure(swapchain, swapChainFormat, DAWN_TEXTURE_USAGE_BIT_OUTPUT_ATTACHMENT, 640, dawnSwapChainConfigure(swapchain, swapChainFormat, DAWN_TEXTURE_USAGE_BIT_OUTPUT_ATTACHMENT, 640,
480); 480);
@ -44,7 +44,7 @@ void init() {
"void main() {\n" "void main() {\n"
" gl_Position = vec4(pos[gl_VertexIndex], 0.0, 1.0);\n" " gl_Position = vec4(pos[gl_VertexIndex], 0.0, 1.0);\n"
"}\n"; "}\n";
dawnShaderModule vsModule = utils::CreateShaderModule(dawn::Device(device), dawn::ShaderStage::Vertex, vs).Release(); DawnShaderModule vsModule = utils::CreateShaderModule(dawn::Device(device), dawn::ShaderStage::Vertex, vs).Release();
const char* fs = const char* fs =
"#version 450\n" "#version 450\n"
@ -52,19 +52,19 @@ void init() {
"void main() {\n" "void main() {\n"
" fragColor = vec4(1.0, 0.0, 0.0, 1.0);\n" " fragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
"}\n"; "}\n";
dawnShaderModule fsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, fs).Release(); DawnShaderModule fsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, fs).Release();
{ {
dawnRenderPipelineDescriptor descriptor; DawnRenderPipelineDescriptor descriptor;
descriptor.nextInChain = nullptr; descriptor.nextInChain = nullptr;
dawnPipelineStageDescriptor vertexStage; DawnPipelineStageDescriptor vertexStage;
vertexStage.nextInChain = nullptr; vertexStage.nextInChain = nullptr;
vertexStage.module = vsModule; vertexStage.module = vsModule;
vertexStage.entryPoint = "main"; vertexStage.entryPoint = "main";
descriptor.vertexStage = &vertexStage; descriptor.vertexStage = &vertexStage;
dawnPipelineStageDescriptor fragmentStage; DawnPipelineStageDescriptor fragmentStage;
fragmentStage.nextInChain = nullptr; fragmentStage.nextInChain = nullptr;
fragmentStage.module = fsModule; fragmentStage.module = fsModule;
fragmentStage.entryPoint = "main"; fragmentStage.entryPoint = "main";
@ -72,11 +72,11 @@ void init() {
descriptor.sampleCount = 1; descriptor.sampleCount = 1;
dawnBlendDescriptor blendDescriptor; DawnBlendDescriptor blendDescriptor;
blendDescriptor.operation = DAWN_BLEND_OPERATION_ADD; blendDescriptor.operation = DAWN_BLEND_OPERATION_ADD;
blendDescriptor.srcFactor = DAWN_BLEND_FACTOR_ONE; blendDescriptor.srcFactor = DAWN_BLEND_FACTOR_ONE;
blendDescriptor.dstFactor = DAWN_BLEND_FACTOR_ONE; blendDescriptor.dstFactor = DAWN_BLEND_FACTOR_ONE;
dawnColorStateDescriptor colorStateDescriptor; DawnColorStateDescriptor colorStateDescriptor;
colorStateDescriptor.nextInChain = nullptr; colorStateDescriptor.nextInChain = nullptr;
colorStateDescriptor.format = swapChainFormat; colorStateDescriptor.format = swapChainFormat;
colorStateDescriptor.alphaBlend = blendDescriptor; colorStateDescriptor.alphaBlend = blendDescriptor;
@ -84,16 +84,16 @@ void init() {
colorStateDescriptor.colorWriteMask = DAWN_COLOR_WRITE_MASK_ALL; colorStateDescriptor.colorWriteMask = DAWN_COLOR_WRITE_MASK_ALL;
descriptor.colorStateCount = 1; descriptor.colorStateCount = 1;
dawnColorStateDescriptor* colorStatesPtr[] = {&colorStateDescriptor}; DawnColorStateDescriptor* colorStatesPtr[] = {&colorStateDescriptor};
descriptor.colorStates = colorStatesPtr; descriptor.colorStates = colorStatesPtr;
dawnPipelineLayoutDescriptor pl; DawnPipelineLayoutDescriptor pl;
pl.nextInChain = nullptr; pl.nextInChain = nullptr;
pl.bindGroupLayoutCount = 0; pl.bindGroupLayoutCount = 0;
pl.bindGroupLayouts = nullptr; pl.bindGroupLayouts = nullptr;
descriptor.layout = dawnDeviceCreatePipelineLayout(device, &pl); descriptor.layout = dawnDeviceCreatePipelineLayout(device, &pl);
dawnInputStateBuilder inputStateBuilder = dawnDeviceCreateInputStateBuilder(device); DawnInputStateBuilder inputStateBuilder = dawnDeviceCreateInputStateBuilder(device);
descriptor.inputState = dawnInputStateBuilderGetResult(inputStateBuilder); descriptor.inputState = dawnInputStateBuilderGetResult(inputStateBuilder);
dawnInputStateBuilderRelease(inputStateBuilder); dawnInputStateBuilderRelease(inputStateBuilder);
@ -112,14 +112,14 @@ void init() {
} }
void frame() { void frame() {
dawnTexture backbuffer = dawnSwapChainGetNextTexture(swapchain); DawnTexture backbuffer = dawnSwapChainGetNextTexture(swapchain);
dawnTextureView backbufferView; DawnTextureView backbufferView;
{ {
backbufferView = dawnTextureCreateDefaultTextureView(backbuffer); backbufferView = dawnTextureCreateDefaultTextureView(backbuffer);
} }
dawnRenderPassDescriptor renderpassInfo; DawnRenderPassDescriptor renderpassInfo;
dawnRenderPassColorAttachmentDescriptor colorAttachment; DawnRenderPassColorAttachmentDescriptor colorAttachment;
dawnRenderPassColorAttachmentDescriptor* colorAttachments = {&colorAttachment}; DawnRenderPassColorAttachmentDescriptor* colorAttachments = {&colorAttachment};
{ {
colorAttachment.attachment = backbufferView; colorAttachment.attachment = backbufferView;
colorAttachment.resolveTarget = nullptr; colorAttachment.resolveTarget = nullptr;
@ -130,11 +130,11 @@ void frame() {
renderpassInfo.colorAttachments = &colorAttachments; renderpassInfo.colorAttachments = &colorAttachments;
renderpassInfo.depthStencilAttachment = nullptr; renderpassInfo.depthStencilAttachment = nullptr;
} }
dawnCommandBuffer commands; DawnCommandBuffer commands;
{ {
dawnCommandEncoder encoder = dawnDeviceCreateCommandEncoder(device); DawnCommandEncoder encoder = dawnDeviceCreateCommandEncoder(device);
dawnRenderPassEncoder pass = dawnCommandEncoderBeginRenderPass(encoder, &renderpassInfo); DawnRenderPassEncoder pass = dawnCommandEncoderBeginRenderPass(encoder, &renderpassInfo);
dawnRenderPassEncoderSetPipeline(pass, pipeline); dawnRenderPassEncoderSetPipeline(pass, pipeline);
dawnRenderPassEncoderDraw(pass, 3, 1, 0, 0); dawnRenderPassEncoderDraw(pass, 3, 1, 0, 0);
dawnRenderPassEncoderEndPass(pass); dawnRenderPassEncoderEndPass(pass);

View File

@ -98,8 +98,8 @@ dawn::Device CreateCppDawnDevice() {
backendAdapter = *adapterIt; backendAdapter = *adapterIt;
} }
dawnDevice backendDevice = backendAdapter.CreateDevice(); DawnDevice backendDevice = backendAdapter.CreateDevice();
dawnProcTable backendProcs = dawn_native::GetProcs(); DawnProcTable backendProcs = dawn_native::GetProcs();
binding = utils::CreateBinding(backendType, window, backendDevice); binding = utils::CreateBinding(backendType, window, backendDevice);
if (binding == nullptr) { if (binding == nullptr) {
@ -107,8 +107,8 @@ dawn::Device CreateCppDawnDevice() {
} }
// Choose whether to use the backend procs and devices directly, or set up the wire. // Choose whether to use the backend procs and devices directly, or set up the wire.
dawnDevice cDevice = nullptr; DawnDevice cDevice = nullptr;
dawnProcTable procs; DawnProcTable procs;
switch (cmdBufType) { switch (cmdBufType) {
case CmdBufType::None: case CmdBufType::None:
@ -125,8 +125,8 @@ dawn::Device CreateCppDawnDevice() {
c2sBuf->SetHandler(wireServer); c2sBuf->SetHandler(wireServer);
wireClient = new dawn_wire::WireClient(c2sBuf); wireClient = new dawn_wire::WireClient(c2sBuf);
dawnDevice clientDevice = wireClient->GetDevice(); DawnDevice clientDevice = wireClient->GetDevice();
dawnProcTable clientProcs = wireClient->GetProcs(); DawnProcTable clientProcs = wireClient->GetProcs();
s2cBuf->SetHandler(wireClient); s2cBuf->SetHandler(wireClient);
procs = clientProcs; procs = clientProcs;

View File

@ -230,7 +230,7 @@ def as_cType(name):
if name.native: if name.native:
return name.concatcase() return name.concatcase()
else: else:
return 'dawn' + name.CamelCase() return 'Dawn' + name.CamelCase()
def as_cppType(name): def as_cppType(name):
if name.native: if name.native:
@ -272,7 +272,7 @@ def as_MethodSuffix(type_name, method_name):
def as_cProc(type_name, method_name): def as_cProc(type_name, method_name):
assert(not type_name.native and not method_name.native) assert(not type_name.native and not method_name.native)
return 'dawn' + 'Proc' + type_name.CamelCase() + method_name.CamelCase() return 'Dawn' + 'Proc' + type_name.CamelCase() + method_name.CamelCase()
def as_frontendType(typ): def as_frontendType(typ):
if typ.category == 'object': if typ.category == 'object':

View File

@ -14,11 +14,11 @@
#include "dawn/dawn.h" #include "dawn/dawn.h"
static dawnProcTable procs; static DawnProcTable procs;
static dawnProcTable nullProcs; static DawnProcTable nullProcs;
void dawnSetProcs(const dawnProcTable* procs_) { void dawnSetProcs(const DawnProcTable* procs_) {
if (procs_) { if (procs_) {
procs = *procs_; procs = *procs_;
} else { } else {

View File

@ -48,13 +48,13 @@
{% endfor %} {% endfor %}
// Custom types depending on the target language // Custom types depending on the target language
typedef uint64_t dawnCallbackUserdata; typedef uint64_t DawnCallbackUserdata;
typedef void (*dawnDeviceErrorCallback)(const char* message, dawnCallbackUserdata userdata); typedef void (*DawnDeviceErrorCallback)(const char* message, DawnCallbackUserdata userdata);
typedef void (*dawnBuilderErrorCallback)(dawnBuilderErrorStatus status, const char* message, dawnCallbackUserdata userdata1, dawnCallbackUserdata userdata2); typedef void (*DawnBuilderErrorCallback)(DawnBuilderErrorStatus status, const char* message, DawnCallbackUserdata userdata1, DawnCallbackUserdata userdata2);
typedef void (*dawnBufferMapReadCallback)(dawnBufferMapAsyncStatus status, const void* data, uint32_t dataLength, dawnCallbackUserdata userdata); typedef void (*DawnBufferMapReadCallback)(DawnBufferMapAsyncStatus status, const void* data, uint32_t dataLength, DawnCallbackUserdata userdata);
typedef void (*dawnBufferMapWriteCallback)(dawnBufferMapAsyncStatus status, void* data, uint32_t dataLength, dawnCallbackUserdata userdata); typedef void (*DawnBufferMapWriteCallback)(DawnBufferMapAsyncStatus status, void* data, uint32_t dataLength, DawnCallbackUserdata userdata);
typedef void (*dawnFenceOnCompletionCallback)(dawnFenceCompletionStatus status, typedef void (*DawnFenceOnCompletionCallback)(DawnFenceCompletionStatus status,
dawnCallbackUserdata userdata); DawnCallbackUserdata userdata);
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -73,7 +73,7 @@ extern "C" {
{% endfor %} {% endfor %}
struct dawnProcTable_s { struct DawnProcTable_s {
{% for type in by_category["object"] %} {% for type in by_category["object"] %}
{% for method in native_methods(type) %} {% for method in native_methods(type) %}
{{as_cProc(type.name, method.name)}} {{as_varName(type.name, method.name)}}; {{as_cProc(type.name, method.name)}} {{as_varName(type.name, method.name)}};
@ -81,12 +81,12 @@ struct dawnProcTable_s {
{% endfor %} {% endfor %}
}; };
typedef struct dawnProcTable_s dawnProcTable; typedef struct DawnProcTable_s DawnProcTable;
// Stuff below is for convenience and will forward calls to a static dawnProcTable. // Stuff below is for convenience and will forward calls to a static DawnProcTable.
// Set which dawnProcTable will be used // Set which DawnProcTable will be used
DAWN_EXPORT void dawnSetProcs(const dawnProcTable* procs); DAWN_EXPORT void dawnSetProcs(const DawnProcTable* procs);
{% for type in by_category["object"] %} {% for type in by_category["object"] %}
// Methods of {{type.name.CamelCase()}} // Methods of {{type.name.CamelCase()}}

View File

@ -170,8 +170,8 @@ namespace dawn_native {
{% endfor %} {% endfor %}
} }
dawnProcTable GetProcsAutogen() { DawnProcTable GetProcsAutogen() {
dawnProcTable table; DawnProcTable table;
{% for type in by_category["object"] %} {% for type in by_category["object"] %}
{% for method in native_methods(type) %} {% for method in native_methods(type) %}
table.{{as_varName(type.name, method.name)}} = Validating{{as_MethodSuffix(type.name, method.name)}}; table.{{as_varName(type.name, method.name)}} = Validating{{as_MethodSuffix(type.name, method.name)}};

View File

@ -72,9 +72,9 @@ namespace dawn_wire { namespace client {
{% if type.is_builder %} {% if type.is_builder %}
void Client{{as_MethodSuffix(type.name, Name("set error callback"))}}({{cType}} cSelf, void Client{{as_MethodSuffix(type.name, Name("set error callback"))}}({{cType}} cSelf,
dawnBuilderErrorCallback callback, DawnBuilderErrorCallback callback,
dawnCallbackUserdata userdata1, DawnCallbackUserdata userdata1,
dawnCallbackUserdata userdata2) { DawnCallbackUserdata userdata2) {
{{Type}}* self = reinterpret_cast<{{Type}}*>(cSelf); {{Type}}* self = reinterpret_cast<{{Type}}*>(cSelf);
self->builderCallback.callback = callback; self->builderCallback.callback = callback;
self->builderCallback.userdata1 = userdata1; self->builderCallback.userdata1 = userdata1;
@ -117,8 +117,8 @@ namespace dawn_wire { namespace client {
//* - An autogenerated Client{{suffix}} method that sends the command on the wire //* - An autogenerated Client{{suffix}} method that sends the command on the wire
//* - A manual ProxyClient{{suffix}} method that will be inserted in the proctable instead of //* - A manual ProxyClient{{suffix}} method that will be inserted in the proctable instead of
//* the autogenerated one, and that will have to call Client{{suffix}} //* the autogenerated one, and that will have to call Client{{suffix}}
dawnProcTable GetProcs() { DawnProcTable GetProcs() {
dawnProcTable table; DawnProcTable table;
{% for type in by_category["object"] %} {% for type in by_category["object"] %}
{% for method in native_methods(type) %} {% for method in native_methods(type) %}
{% set suffix = as_MethodSuffix(type.name, method.name) %} {% set suffix = as_MethodSuffix(type.name, method.name) %}

View File

@ -25,7 +25,7 @@ namespace dawn_wire {
if (object == nullptr) { if (object == nullptr) {
return true; return true;
} }
bool called = object->builderCallback.Call(static_cast<dawnBuilderErrorStatus>(status), message); bool called = object->builderCallback.Call(static_cast<DawnBuilderErrorStatus>(status), message);
//* Unhandled builder errors are forwarded to the device //* Unhandled builder errors are forwarded to the device
if (!called && status != DAWN_BUILDER_ERROR_STATUS_SUCCESS && status != DAWN_BUILDER_ERROR_STATUS_UNKNOWN) { if (!called && status != DAWN_BUILDER_ERROR_STATUS_SUCCESS && status != DAWN_BUILDER_ERROR_STATUS_UNKNOWN) {

View File

@ -28,7 +28,7 @@ namespace dawn_wire { namespace server {
virtual ~ServerBase() = default; virtual ~ServerBase() = default;
protected: protected:
void DestroyAllObjects(const dawnProcTable& procs) { void DestroyAllObjects(const DawnProcTable& procs) {
//* Free all objects when the server is destroyed //* Free all objects when the server is destroyed
{% for type in by_category["object"] if type.name.canonical_case() != "device" %} {% for type in by_category["object"] if type.name.canonical_case() != "device" %}
{ {

View File

@ -17,7 +17,7 @@
namespace dawn_wire { namespace server { namespace dawn_wire { namespace server {
{% for type in by_category["object"] if type.is_builder%} {% for type in by_category["object"] if type.is_builder%}
void Server::Forward{{type.name.CamelCase()}}(dawnBuilderErrorStatus status, const char* message, dawnCallbackUserdata userdata1, dawnCallbackUserdata userdata2) { void Server::Forward{{type.name.CamelCase()}}(DawnBuilderErrorStatus status, const char* message, DawnCallbackUserdata userdata1, DawnCallbackUserdata userdata2) {
auto server = reinterpret_cast<Server*>(static_cast<uintptr_t>(userdata1)); auto server = reinterpret_cast<Server*>(static_cast<uintptr_t>(userdata1));
uint32_t id = userdata2 & 0xFFFFFFFFu; uint32_t id = userdata2 & 0xFFFFFFFFu;
uint32_t serial = userdata2 >> uint64_t(32); uint32_t serial = userdata2 >> uint64_t(32);
@ -27,7 +27,7 @@ namespace dawn_wire { namespace server {
{% for type in by_category["object"] if type.is_builder%} {% for type in by_category["object"] if type.is_builder%}
{% set Type = type.name.CamelCase() %} {% set Type = type.name.CamelCase() %}
void Server::On{{Type}}Error(dawnBuilderErrorStatus status, const char* message, uint32_t id, uint32_t serial) { void Server::On{{Type}}Error(DawnBuilderErrorStatus status, const char* message, uint32_t id, uint32_t serial) {
auto* builder = {{Type}}Objects().Get(id); auto* builder = {{Type}}Objects().Get(id);
if (builder == nullptr || builder->serial != serial) { if (builder == nullptr || builder->serial != serial) {

View File

@ -14,13 +14,13 @@
// Forwarding callbacks // Forwarding callbacks
{% for type in by_category["object"] if type.is_builder%} {% for type in by_category["object"] if type.is_builder%}
static void Forward{{type.name.CamelCase()}}(dawnBuilderErrorStatus status, const char* message, dawnCallbackUserdata userdata1, dawnCallbackUserdata userdata2); static void Forward{{type.name.CamelCase()}}(DawnBuilderErrorStatus status, const char* message, DawnCallbackUserdata userdata1, DawnCallbackUserdata userdata2);
{% endfor %} {% endfor %}
// Error callbacks // Error callbacks
{% for type in by_category["object"] if type.is_builder%} {% for type in by_category["object"] if type.is_builder%}
{% set Type = type.name.CamelCase() %} {% set Type = type.name.CamelCase() %}
void On{{Type}}Error(dawnBuilderErrorStatus status, const char* message, uint32_t id, uint32_t serial); void On{{Type}}Error(DawnBuilderErrorStatus status, const char* message, uint32_t id, uint32_t serial);
{% endfor %} {% endfor %}
// Command handlers & doers // Command handlers & doers

View File

@ -38,7 +38,7 @@ namespace {
ProcTableAsClass::~ProcTableAsClass() { ProcTableAsClass::~ProcTableAsClass() {
} }
void ProcTableAsClass::GetProcTableAndDevice(dawnProcTable* table, dawnDevice* device) { void ProcTableAsClass::GetProcTableAndDevice(DawnProcTable* table, DawnDevice* device) {
*device = GetNewDevice(); *device = GetNewDevice();
{% for type in by_category["object"] %} {% for type in by_category["object"] %}
@ -48,7 +48,7 @@ void ProcTableAsClass::GetProcTableAndDevice(dawnProcTable* table, dawnDevice* d
{% endfor %} {% endfor %}
} }
void ProcTableAsClass::DeviceSetErrorCallback(dawnDevice self, dawnDeviceErrorCallback callback, dawnCallbackUserdata userdata) { void ProcTableAsClass::DeviceSetErrorCallback(DawnDevice self, DawnDeviceErrorCallback callback, DawnCallbackUserdata userdata) {
auto object = reinterpret_cast<ProcTableAsClass::Object*>(self); auto object = reinterpret_cast<ProcTableAsClass::Object*>(self);
object->deviceErrorCallback = callback; object->deviceErrorCallback = callback;
object->userdata1 = userdata; object->userdata1 = userdata;
@ -56,7 +56,7 @@ void ProcTableAsClass::DeviceSetErrorCallback(dawnDevice self, dawnDeviceErrorCa
OnDeviceSetErrorCallback(self, callback, userdata); OnDeviceSetErrorCallback(self, callback, userdata);
} }
void ProcTableAsClass::BufferMapReadAsync(dawnBuffer self, dawnBufferMapReadCallback callback, dawnCallbackUserdata userdata) { void ProcTableAsClass::BufferMapReadAsync(DawnBuffer self, DawnBufferMapReadCallback callback, DawnCallbackUserdata userdata) {
auto object = reinterpret_cast<ProcTableAsClass::Object*>(self); auto object = reinterpret_cast<ProcTableAsClass::Object*>(self);
object->mapReadCallback = callback; object->mapReadCallback = callback;
object->userdata1 = userdata; object->userdata1 = userdata;
@ -64,7 +64,7 @@ void ProcTableAsClass::BufferMapReadAsync(dawnBuffer self, dawnBufferMapReadCall
OnBufferMapReadAsyncCallback(self, callback, userdata); OnBufferMapReadAsyncCallback(self, callback, userdata);
} }
void ProcTableAsClass::BufferMapWriteAsync(dawnBuffer self, dawnBufferMapWriteCallback callback, dawnCallbackUserdata userdata) { void ProcTableAsClass::BufferMapWriteAsync(DawnBuffer self, DawnBufferMapWriteCallback callback, DawnCallbackUserdata userdata) {
auto object = reinterpret_cast<ProcTableAsClass::Object*>(self); auto object = reinterpret_cast<ProcTableAsClass::Object*>(self);
object->mapWriteCallback = callback; object->mapWriteCallback = callback;
object->userdata1 = userdata; object->userdata1 = userdata;
@ -72,10 +72,10 @@ void ProcTableAsClass::BufferMapWriteAsync(dawnBuffer self, dawnBufferMapWriteCa
OnBufferMapWriteAsyncCallback(self, callback, userdata); OnBufferMapWriteAsyncCallback(self, callback, userdata);
} }
void ProcTableAsClass::FenceOnCompletion(dawnFence self, void ProcTableAsClass::FenceOnCompletion(DawnFence self,
uint64_t value, uint64_t value,
dawnFenceOnCompletionCallback callback, DawnFenceOnCompletionCallback callback,
dawnCallbackUserdata userdata) { DawnCallbackUserdata userdata) {
auto object = reinterpret_cast<ProcTableAsClass::Object*>(self); auto object = reinterpret_cast<ProcTableAsClass::Object*>(self);
object->fenceOnCompletionCallback = callback; object->fenceOnCompletionCallback = callback;
object->userdata1 = userdata; object->userdata1 = userdata;
@ -83,38 +83,38 @@ void ProcTableAsClass::FenceOnCompletion(dawnFence self,
OnFenceOnCompletionCallback(self, value, callback, userdata); OnFenceOnCompletionCallback(self, value, callback, userdata);
} }
void ProcTableAsClass::CallDeviceErrorCallback(dawnDevice device, const char* message) { void ProcTableAsClass::CallDeviceErrorCallback(DawnDevice device, const char* message) {
auto object = reinterpret_cast<ProcTableAsClass::Object*>(device); auto object = reinterpret_cast<ProcTableAsClass::Object*>(device);
object->deviceErrorCallback(message, object->userdata1); object->deviceErrorCallback(message, object->userdata1);
} }
void ProcTableAsClass::CallBuilderErrorCallback(void* builder , dawnBuilderErrorStatus status, const char* message) { void ProcTableAsClass::CallBuilderErrorCallback(void* builder , DawnBuilderErrorStatus status, const char* message) {
auto object = reinterpret_cast<ProcTableAsClass::Object*>(builder); auto object = reinterpret_cast<ProcTableAsClass::Object*>(builder);
object->builderErrorCallback(status, message, object->userdata1, object->userdata2); object->builderErrorCallback(status, message, object->userdata1, object->userdata2);
} }
void ProcTableAsClass::CallMapReadCallback(dawnBuffer buffer, dawnBufferMapAsyncStatus status, const void* data, uint32_t dataLength) { void ProcTableAsClass::CallMapReadCallback(DawnBuffer buffer, DawnBufferMapAsyncStatus status, const void* data, uint32_t dataLength) {
auto object = reinterpret_cast<ProcTableAsClass::Object*>(buffer); auto object = reinterpret_cast<ProcTableAsClass::Object*>(buffer);
object->mapReadCallback(status, data, dataLength, object->userdata1); object->mapReadCallback(status, data, dataLength, object->userdata1);
} }
void ProcTableAsClass::CallMapWriteCallback(dawnBuffer buffer, dawnBufferMapAsyncStatus status, void* data, uint32_t dataLength) { void ProcTableAsClass::CallMapWriteCallback(DawnBuffer buffer, DawnBufferMapAsyncStatus status, void* data, uint32_t dataLength) {
auto object = reinterpret_cast<ProcTableAsClass::Object*>(buffer); auto object = reinterpret_cast<ProcTableAsClass::Object*>(buffer);
object->mapWriteCallback(status, data, dataLength, object->userdata1); object->mapWriteCallback(status, data, dataLength, object->userdata1);
} }
void ProcTableAsClass::CallFenceOnCompletionCallback(dawnFence fence, void ProcTableAsClass::CallFenceOnCompletionCallback(DawnFence fence,
dawnFenceCompletionStatus status) { DawnFenceCompletionStatus status) {
auto object = reinterpret_cast<ProcTableAsClass::Object*>(fence); auto object = reinterpret_cast<ProcTableAsClass::Object*>(fence);
object->fenceOnCompletionCallback(status, object->userdata1); object->fenceOnCompletionCallback(status, object->userdata1);
} }
{% for type in by_category["object"] if type.is_builder %} {% for type in by_category["object"] if type.is_builder %}
void ProcTableAsClass::{{as_MethodSuffix(type.name, Name("set error callback"))}}({{as_cType(type.name)}} self, dawnBuilderErrorCallback callback, dawnCallbackUserdata userdata1, dawnCallbackUserdata userdata2) { void ProcTableAsClass::{{as_MethodSuffix(type.name, Name("set error callback"))}}({{as_cType(type.name)}} self, DawnBuilderErrorCallback callback, DawnCallbackUserdata userdata1, DawnCallbackUserdata userdata2) {
auto object = reinterpret_cast<ProcTableAsClass::Object*>(self); auto object = reinterpret_cast<ProcTableAsClass::Object*>(self);
object->builderErrorCallback = callback; object->builderErrorCallback = callback;
object->userdata1 = userdata1; object->userdata1 = userdata1;
object->userdata2 = userdata2; object->userdata2 = userdata2;
OnBuilderSetErrorCallback(reinterpret_cast<dawnBufferBuilder>(self), callback, userdata1, userdata2); OnBuilderSetErrorCallback(reinterpret_cast<DawnBufferBuilder>(self), callback, userdata1, userdata2);
} }
{% endfor %} {% endfor %}

View File

@ -27,7 +27,7 @@ class ProcTableAsClass {
public: public:
virtual ~ProcTableAsClass(); virtual ~ProcTableAsClass();
void GetProcTableAndDevice(dawnProcTable* table, dawnDevice* device); void GetProcTableAndDevice(DawnProcTable* table, DawnDevice* device);
// Creates an object that can be returned by a mocked call as in WillOnce(Return(foo)). // Creates an object that can be returned by a mocked call as in WillOnce(Return(foo)).
// It returns an object of the write type that isn't equal to any previously returned object. // It returns an object of the write type that isn't equal to any previously returned object.
@ -51,45 +51,45 @@ class ProcTableAsClass {
// Stores callback and userdata and calls OnBuilderSetErrorCallback // Stores callback and userdata and calls OnBuilderSetErrorCallback
{% if type.is_builder %} {% if type.is_builder %}
void {{as_MethodSuffix(type.name, Name("set error callback"))}}({{as_cType(type.name)}} self, dawnBuilderErrorCallback callback, dawnCallbackUserdata userdata1, dawnCallbackUserdata userdata2); void {{as_MethodSuffix(type.name, Name("set error callback"))}}({{as_cType(type.name)}} self, DawnBuilderErrorCallback callback, DawnCallbackUserdata userdata1, DawnCallbackUserdata userdata2);
{% endif %} {% endif %}
{% endfor %} {% endfor %}
// Stores callback and userdata and calls the On* methods // Stores callback and userdata and calls the On* methods
void DeviceSetErrorCallback(dawnDevice self, dawnDeviceErrorCallback callback, dawnCallbackUserdata userdata); void DeviceSetErrorCallback(DawnDevice self, DawnDeviceErrorCallback callback, DawnCallbackUserdata userdata);
void BufferMapReadAsync(dawnBuffer self, dawnBufferMapReadCallback callback, dawnCallbackUserdata userdata); void BufferMapReadAsync(DawnBuffer self, DawnBufferMapReadCallback callback, DawnCallbackUserdata userdata);
void BufferMapWriteAsync(dawnBuffer self, dawnBufferMapWriteCallback callback, dawnCallbackUserdata userdata); void BufferMapWriteAsync(DawnBuffer self, DawnBufferMapWriteCallback callback, DawnCallbackUserdata userdata);
void FenceOnCompletion(dawnFence self, void FenceOnCompletion(DawnFence self,
uint64_t value, uint64_t value,
dawnFenceOnCompletionCallback callback, DawnFenceOnCompletionCallback callback,
dawnCallbackUserdata userdata); DawnCallbackUserdata userdata);
// Special cased mockable methods // Special cased mockable methods
virtual void OnDeviceSetErrorCallback(dawnDevice device, dawnDeviceErrorCallback callback, dawnCallbackUserdata userdata) = 0; virtual void OnDeviceSetErrorCallback(DawnDevice device, DawnDeviceErrorCallback callback, DawnCallbackUserdata userdata) = 0;
virtual void OnBuilderSetErrorCallback(dawnBufferBuilder builder, dawnBuilderErrorCallback callback, dawnCallbackUserdata userdata1, dawnCallbackUserdata userdata2) = 0; virtual void OnBuilderSetErrorCallback(DawnBufferBuilder builder, DawnBuilderErrorCallback callback, DawnCallbackUserdata userdata1, DawnCallbackUserdata userdata2) = 0;
virtual void OnBufferMapReadAsyncCallback(dawnBuffer buffer, dawnBufferMapReadCallback callback, dawnCallbackUserdata userdata) = 0; virtual void OnBufferMapReadAsyncCallback(DawnBuffer buffer, DawnBufferMapReadCallback callback, DawnCallbackUserdata userdata) = 0;
virtual void OnBufferMapWriteAsyncCallback(dawnBuffer buffer, dawnBufferMapWriteCallback callback, dawnCallbackUserdata userdata) = 0; virtual void OnBufferMapWriteAsyncCallback(DawnBuffer buffer, DawnBufferMapWriteCallback callback, DawnCallbackUserdata userdata) = 0;
virtual void OnFenceOnCompletionCallback(dawnFence fence, virtual void OnFenceOnCompletionCallback(DawnFence fence,
uint64_t value, uint64_t value,
dawnFenceOnCompletionCallback callback, DawnFenceOnCompletionCallback callback,
dawnCallbackUserdata userdata) = 0; DawnCallbackUserdata userdata) = 0;
// Calls the stored callbacks // Calls the stored callbacks
void CallDeviceErrorCallback(dawnDevice device, const char* message); void CallDeviceErrorCallback(DawnDevice device, const char* message);
void CallBuilderErrorCallback(void* builder , dawnBuilderErrorStatus status, const char* message); void CallBuilderErrorCallback(void* builder , DawnBuilderErrorStatus status, const char* message);
void CallMapReadCallback(dawnBuffer buffer, dawnBufferMapAsyncStatus status, const void* data, uint32_t dataLength); void CallMapReadCallback(DawnBuffer buffer, DawnBufferMapAsyncStatus status, const void* data, uint32_t dataLength);
void CallMapWriteCallback(dawnBuffer buffer, dawnBufferMapAsyncStatus status, void* data, uint32_t dataLength); void CallMapWriteCallback(DawnBuffer buffer, DawnBufferMapAsyncStatus status, void* data, uint32_t dataLength);
void CallFenceOnCompletionCallback(dawnFence fence, dawnFenceCompletionStatus status); void CallFenceOnCompletionCallback(DawnFence fence, DawnFenceCompletionStatus status);
struct Object { struct Object {
ProcTableAsClass* procs = nullptr; ProcTableAsClass* procs = nullptr;
dawnDeviceErrorCallback deviceErrorCallback = nullptr; DawnDeviceErrorCallback deviceErrorCallback = nullptr;
dawnBuilderErrorCallback builderErrorCallback = nullptr; DawnBuilderErrorCallback builderErrorCallback = nullptr;
dawnBufferMapReadCallback mapReadCallback = nullptr; DawnBufferMapReadCallback mapReadCallback = nullptr;
dawnBufferMapWriteCallback mapWriteCallback = nullptr; DawnBufferMapWriteCallback mapWriteCallback = nullptr;
dawnFenceOnCompletionCallback fenceOnCompletionCallback = nullptr; DawnFenceOnCompletionCallback fenceOnCompletionCallback = nullptr;
dawnCallbackUserdata userdata1 = 0; DawnCallbackUserdata userdata1 = 0;
dawnCallbackUserdata userdata2 = 0; DawnCallbackUserdata userdata2 = 0;
}; };
private: private:
@ -117,15 +117,15 @@ class MockProcTable : public ProcTableAsClass {
MOCK_METHOD1({{as_MethodSuffix(type.name, Name("release"))}}, void({{as_cType(type.name)}} self)); MOCK_METHOD1({{as_MethodSuffix(type.name, Name("release"))}}, void({{as_cType(type.name)}} self));
{% endfor %} {% endfor %}
MOCK_METHOD3(OnDeviceSetErrorCallback, void(dawnDevice device, dawnDeviceErrorCallback callback, dawnCallbackUserdata userdata)); MOCK_METHOD3(OnDeviceSetErrorCallback, void(DawnDevice device, DawnDeviceErrorCallback callback, DawnCallbackUserdata userdata));
MOCK_METHOD4(OnBuilderSetErrorCallback, void(dawnBufferBuilder builder, dawnBuilderErrorCallback callback, dawnCallbackUserdata userdata1, dawnCallbackUserdata userdata2)); MOCK_METHOD4(OnBuilderSetErrorCallback, void(DawnBufferBuilder builder, DawnBuilderErrorCallback callback, DawnCallbackUserdata userdata1, DawnCallbackUserdata userdata2));
MOCK_METHOD3(OnBufferMapReadAsyncCallback, void(dawnBuffer buffer, dawnBufferMapReadCallback callback, dawnCallbackUserdata userdata)); MOCK_METHOD3(OnBufferMapReadAsyncCallback, void(DawnBuffer buffer, DawnBufferMapReadCallback callback, DawnCallbackUserdata userdata));
MOCK_METHOD3(OnBufferMapWriteAsyncCallback, void(dawnBuffer buffer, dawnBufferMapWriteCallback callback, dawnCallbackUserdata userdata)); MOCK_METHOD3(OnBufferMapWriteAsyncCallback, void(DawnBuffer buffer, DawnBufferMapWriteCallback callback, DawnCallbackUserdata userdata));
MOCK_METHOD4(OnFenceOnCompletionCallback, MOCK_METHOD4(OnFenceOnCompletionCallback,
void(dawnFence fence, void(DawnFence fence,
uint64_t value, uint64_t value,
dawnFenceOnCompletionCallback callback, DawnFenceOnCompletionCallback callback,
dawnCallbackUserdata userdata)); DawnCallbackUserdata userdata));
}; };
#endif // MOCK_DAWN_H #endif // MOCK_DAWN_H

View File

@ -18,19 +18,19 @@
#include "dawn/dawn_wsi.h" #include "dawn/dawn_wsi.h"
template <typename T> template <typename T>
dawnSwapChainImplementation CreateSwapChainImplementation(T* swapChain) { DawnSwapChainImplementation CreateSwapChainImplementation(T* swapChain) {
dawnSwapChainImplementation impl = {}; DawnSwapChainImplementation impl = {};
impl.userData = swapChain; impl.userData = swapChain;
impl.Init = [](void* userData, void* wsiContext) { impl.Init = [](void* userData, void* wsiContext) {
auto* ctx = reinterpret_cast<typename T::WSIContext*>(wsiContext); auto* ctx = reinterpret_cast<typename T::WSIContext*>(wsiContext);
reinterpret_cast<T*>(userData)->Init(ctx); reinterpret_cast<T*>(userData)->Init(ctx);
}; };
impl.Destroy = [](void* userData) { delete reinterpret_cast<T*>(userData); }; impl.Destroy = [](void* userData) { delete reinterpret_cast<T*>(userData); };
impl.Configure = [](void* userData, dawnTextureFormat format, dawnTextureUsageBit allowedUsage, impl.Configure = [](void* userData, DawnTextureFormat format, DawnTextureUsageBit allowedUsage,
uint32_t width, uint32_t height) { uint32_t width, uint32_t height) {
return reinterpret_cast<T*>(userData)->Configure(format, allowedUsage, width, height); return reinterpret_cast<T*>(userData)->Configure(format, allowedUsage, width, height);
}; };
impl.GetNextTexture = [](void* userData, dawnSwapChainNextTexture* nextTexture) { impl.GetNextTexture = [](void* userData, DawnSwapChainNextTexture* nextTexture) {
return reinterpret_cast<T*>(userData)->GetNextTexture(nextTexture); return reinterpret_cast<T*>(userData)->GetNextTexture(nextTexture);
}; };
impl.Present = [](void* userData) { return reinterpret_cast<T*>(userData)->Present(); }; impl.Present = [](void* userData) { return reinterpret_cast<T*>(userData)->Present(); };

View File

@ -125,7 +125,7 @@ namespace dawn_native {
} }
void BufferBase::CallMapReadCallback(uint32_t serial, void BufferBase::CallMapReadCallback(uint32_t serial,
dawnBufferMapAsyncStatus status, DawnBufferMapAsyncStatus status,
const void* pointer, const void* pointer,
uint32_t dataLength) { uint32_t dataLength) {
ASSERT(!IsError()); ASSERT(!IsError());
@ -133,14 +133,14 @@ namespace dawn_native {
ASSERT(mMapWriteCallback == nullptr); ASSERT(mMapWriteCallback == nullptr);
// Tag the callback as fired before firing it, otherwise it could fire a second time if // Tag the callback as fired before firing it, otherwise it could fire a second time if
// for example buffer.Unmap() is called inside the application-provided callback. // for example buffer.Unmap() is called inside the application-provided callback.
dawnBufferMapReadCallback callback = mMapReadCallback; DawnBufferMapReadCallback callback = mMapReadCallback;
mMapReadCallback = nullptr; mMapReadCallback = nullptr;
callback(status, pointer, dataLength, mMapUserdata); callback(status, pointer, dataLength, mMapUserdata);
} }
} }
void BufferBase::CallMapWriteCallback(uint32_t serial, void BufferBase::CallMapWriteCallback(uint32_t serial,
dawnBufferMapAsyncStatus status, DawnBufferMapAsyncStatus status,
void* pointer, void* pointer,
uint32_t dataLength) { uint32_t dataLength) {
ASSERT(!IsError()); ASSERT(!IsError());
@ -148,7 +148,7 @@ namespace dawn_native {
ASSERT(mMapReadCallback == nullptr); ASSERT(mMapReadCallback == nullptr);
// Tag the callback as fired before firing it, otherwise it could fire a second time if // Tag the callback as fired before firing it, otherwise it could fire a second time if
// for example buffer.Unmap() is called inside the application-provided callback. // for example buffer.Unmap() is called inside the application-provided callback.
dawnBufferMapWriteCallback callback = mMapWriteCallback; DawnBufferMapWriteCallback callback = mMapWriteCallback;
mMapWriteCallback = nullptr; mMapWriteCallback = nullptr;
callback(status, pointer, dataLength, mMapUserdata); callback(status, pointer, dataLength, mMapUserdata);
} }
@ -165,8 +165,8 @@ namespace dawn_native {
} }
} }
void BufferBase::MapReadAsync(dawnBufferMapReadCallback callback, void BufferBase::MapReadAsync(DawnBufferMapReadCallback callback,
dawnCallbackUserdata userdata) { DawnCallbackUserdata userdata) {
if (GetDevice()->ConsumedError(ValidateMap(dawn::BufferUsageBit::MapRead))) { if (GetDevice()->ConsumedError(ValidateMap(dawn::BufferUsageBit::MapRead))) {
callback(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, userdata); callback(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, userdata);
return; return;
@ -204,8 +204,8 @@ namespace dawn_native {
return {}; return {};
} }
void BufferBase::MapWriteAsync(dawnBufferMapWriteCallback callback, void BufferBase::MapWriteAsync(DawnBufferMapWriteCallback callback,
dawnCallbackUserdata userdata) { DawnCallbackUserdata userdata) {
if (GetDevice()->ConsumedError(ValidateMap(dawn::BufferUsageBit::MapWrite))) { if (GetDevice()->ConsumedError(ValidateMap(dawn::BufferUsageBit::MapWrite))) {
callback(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, userdata); callback(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, userdata);
return; return;

View File

@ -54,8 +54,8 @@ namespace dawn_native {
// Dawn API // Dawn API
void SetSubData(uint32_t start, uint32_t count, const uint8_t* data); void SetSubData(uint32_t start, uint32_t count, const uint8_t* data);
void MapReadAsync(dawnBufferMapReadCallback callback, dawnCallbackUserdata userdata); void MapReadAsync(DawnBufferMapReadCallback callback, DawnCallbackUserdata userdata);
void MapWriteAsync(dawnBufferMapWriteCallback callback, dawnCallbackUserdata userdata); void MapWriteAsync(DawnBufferMapWriteCallback callback, DawnCallbackUserdata userdata);
void Unmap(); void Unmap();
void Destroy(); void Destroy();
@ -63,11 +63,11 @@ namespace dawn_native {
BufferBase(DeviceBase* device, ObjectBase::ErrorTag tag); BufferBase(DeviceBase* device, ObjectBase::ErrorTag tag);
void CallMapReadCallback(uint32_t serial, void CallMapReadCallback(uint32_t serial,
dawnBufferMapAsyncStatus status, DawnBufferMapAsyncStatus status,
const void* pointer, const void* pointer,
uint32_t dataLength); uint32_t dataLength);
void CallMapWriteCallback(uint32_t serial, void CallMapWriteCallback(uint32_t serial,
dawnBufferMapAsyncStatus status, DawnBufferMapAsyncStatus status,
void* pointer, void* pointer,
uint32_t dataLength); uint32_t dataLength);
@ -85,9 +85,9 @@ namespace dawn_native {
uint32_t mSize = 0; uint32_t mSize = 0;
dawn::BufferUsageBit mUsage = dawn::BufferUsageBit::None; dawn::BufferUsageBit mUsage = dawn::BufferUsageBit::None;
dawnBufferMapReadCallback mMapReadCallback = nullptr; DawnBufferMapReadCallback mMapReadCallback = nullptr;
dawnBufferMapWriteCallback mMapWriteCallback = nullptr; DawnBufferMapWriteCallback mMapWriteCallback = nullptr;
dawnCallbackUserdata mMapUserdata = 0; DawnCallbackUserdata mMapUserdata = 0;
uint32_t mMapSerial = 0; uint32_t mMapSerial = 0;
BufferState mState; BufferState mState;

View File

@ -83,7 +83,7 @@ namespace dawn_native {
} }
if (mCallback != nullptr) { if (mCallback != nullptr) {
mCallback(static_cast<dawnBuilderErrorStatus>(mStoredStatus), mStoredMessage.c_str(), mCallback(static_cast<DawnBuilderErrorStatus>(mStoredStatus), mStoredMessage.c_str(),
mUserdata1, mUserdata2); mUserdata1, mUserdata2);
} }

View File

@ -20,9 +20,9 @@
namespace dawn_native { namespace dawn_native {
dawnProcTable GetProcsAutogen(); DawnProcTable GetProcsAutogen();
dawnProcTable GetProcs() { DawnProcTable GetProcs() {
return GetProcsAutogen(); return GetProcsAutogen();
} }
@ -49,8 +49,8 @@ namespace dawn_native {
return mImpl != nullptr; return mImpl != nullptr;
} }
dawnDevice Adapter::CreateDevice() { DawnDevice Adapter::CreateDevice() {
return reinterpret_cast<dawnDevice>(mImpl->CreateDevice()); return reinterpret_cast<DawnDevice>(mImpl->CreateDevice());
} }
// AdapterDiscoverOptionsBase // AdapterDiscoverOptionsBase

View File

@ -45,8 +45,8 @@ namespace dawn_native {
return DAWN_VALIDATION_ERROR("Null implementation for the swapchain"); return DAWN_VALIDATION_ERROR("Null implementation for the swapchain");
} }
dawnSwapChainImplementation* impl = DawnSwapChainImplementation* impl =
reinterpret_cast<dawnSwapChainImplementation*>(descriptor->implementation); reinterpret_cast<DawnSwapChainImplementation*>(descriptor->implementation);
if (!impl->Init || !impl->Destroy || !impl->Configure || !impl->GetNextTexture || if (!impl->Init || !impl->Destroy || !impl->Configure || !impl->GetNextTexture ||
!impl->Present) { !impl->Present) {
@ -61,7 +61,7 @@ namespace dawn_native {
SwapChainBase::SwapChainBase(DeviceBase* device, const SwapChainDescriptor* descriptor) SwapChainBase::SwapChainBase(DeviceBase* device, const SwapChainDescriptor* descriptor)
: ObjectBase(device), : ObjectBase(device),
mImplementation( mImplementation(
*reinterpret_cast<dawnSwapChainImplementation*>(descriptor->implementation)) { *reinterpret_cast<DawnSwapChainImplementation*>(descriptor->implementation)) {
} }
SwapChainBase::SwapChainBase(DeviceBase* device, ObjectBase::ErrorTag tag) SwapChainBase::SwapChainBase(DeviceBase* device, ObjectBase::ErrorTag tag)
@ -95,8 +95,8 @@ namespace dawn_native {
mAllowedUsage = allowedUsage; mAllowedUsage = allowedUsage;
mWidth = width; mWidth = width;
mHeight = height; mHeight = height;
mImplementation.Configure(mImplementation.userData, static_cast<dawnTextureFormat>(format), mImplementation.Configure(mImplementation.userData, static_cast<DawnTextureFormat>(format),
static_cast<dawnTextureUsageBit>(allowedUsage), width, height); static_cast<DawnTextureUsageBit>(allowedUsage), width, height);
} }
TextureBase* SwapChainBase::GetNextTexture() { TextureBase* SwapChainBase::GetNextTexture() {
@ -132,7 +132,7 @@ namespace dawn_native {
mImplementation.Present(mImplementation.userData); mImplementation.Present(mImplementation.userData);
} }
const dawnSwapChainImplementation& SwapChainBase::GetImplementation() { const DawnSwapChainImplementation& SwapChainBase::GetImplementation() {
ASSERT(!IsError()); ASSERT(!IsError());
return mImplementation; return mImplementation;
} }

View File

@ -46,7 +46,7 @@ namespace dawn_native {
protected: protected:
SwapChainBase(DeviceBase* device, ObjectBase::ErrorTag tag); SwapChainBase(DeviceBase* device, ObjectBase::ErrorTag tag);
const dawnSwapChainImplementation& GetImplementation(); const DawnSwapChainImplementation& GetImplementation();
virtual TextureBase* GetNextTextureImpl(const TextureDescriptor*) = 0; virtual TextureBase* GetNextTextureImpl(const TextureDescriptor*) = 0;
virtual void OnBeforePresent(TextureBase* texture) = 0; virtual void OnBeforePresent(TextureBase* texture) = 0;
@ -58,7 +58,7 @@ namespace dawn_native {
MaybeError ValidateGetNextTexture() const; MaybeError ValidateGetNextTexture() const;
MaybeError ValidatePresent(TextureBase* texture) const; MaybeError ValidatePresent(TextureBase* texture) const;
dawnSwapChainImplementation mImplementation = {}; DawnSwapChainImplementation mImplementation = {};
dawn::TextureFormat mFormat = {}; dawn::TextureFormat mFormat = {};
dawn::TextureUsageBit mAllowedUsage; dawn::TextureUsageBit mAllowedUsage;
uint32_t mWidth = 0; uint32_t mWidth = 0;

View File

@ -23,20 +23,20 @@
namespace dawn_native { namespace d3d12 { namespace dawn_native { namespace d3d12 {
dawnSwapChainImplementation CreateNativeSwapChainImpl(dawnDevice device, HWND window) { DawnSwapChainImplementation CreateNativeSwapChainImpl(DawnDevice device, HWND window) {
Device* backendDevice = reinterpret_cast<Device*>(device); Device* backendDevice = reinterpret_cast<Device*>(device);
dawnSwapChainImplementation impl; DawnSwapChainImplementation impl;
impl = CreateSwapChainImplementation(new NativeSwapChainImpl(backendDevice, window)); impl = CreateSwapChainImplementation(new NativeSwapChainImpl(backendDevice, window));
impl.textureUsage = DAWN_TEXTURE_USAGE_BIT_PRESENT; impl.textureUsage = DAWN_TEXTURE_USAGE_BIT_PRESENT;
return impl; return impl;
} }
dawnTextureFormat GetNativeSwapChainPreferredFormat( DawnTextureFormat GetNativeSwapChainPreferredFormat(
const dawnSwapChainImplementation* swapChain) { const DawnSwapChainImplementation* swapChain) {
NativeSwapChainImpl* impl = reinterpret_cast<NativeSwapChainImpl*>(swapChain->userData); NativeSwapChainImpl* impl = reinterpret_cast<NativeSwapChainImpl*>(swapChain->userData);
return static_cast<dawnTextureFormat>(impl->GetPreferredFormat()); return static_cast<DawnTextureFormat>(impl->GetPreferredFormat());
} }
}} // namespace dawn_native::d3d12 }} // namespace dawn_native::d3d12

View File

@ -21,7 +21,7 @@
namespace dawn_native { namespace d3d12 { namespace dawn_native { namespace d3d12 {
namespace { namespace {
DXGI_USAGE D3D12SwapChainBufferUsage(dawnTextureUsageBit allowedUsages) { DXGI_USAGE D3D12SwapChainBufferUsage(DawnTextureUsageBit allowedUsages) {
DXGI_USAGE usage = DXGI_CPU_ACCESS_NONE; DXGI_USAGE usage = DXGI_CPU_ACCESS_NONE;
if (allowedUsages & DAWN_TEXTURE_USAGE_BIT_SAMPLED) { if (allowedUsages & DAWN_TEXTURE_USAGE_BIT_SAMPLED) {
usage |= DXGI_USAGE_SHADER_INPUT; usage |= DXGI_USAGE_SHADER_INPUT;
@ -45,16 +45,16 @@ namespace dawn_native { namespace d3d12 {
NativeSwapChainImpl::~NativeSwapChainImpl() { NativeSwapChainImpl::~NativeSwapChainImpl() {
} }
void NativeSwapChainImpl::Init(dawnWSIContextD3D12* /*context*/) { void NativeSwapChainImpl::Init(DawnWSIContextD3D12* /*context*/) {
} }
dawnSwapChainError NativeSwapChainImpl::Configure(dawnTextureFormat format, DawnSwapChainError NativeSwapChainImpl::Configure(DawnTextureFormat format,
dawnTextureUsageBit usage, DawnTextureUsageBit usage,
uint32_t width, uint32_t width,
uint32_t height) { uint32_t height) {
ASSERT(width > 0); ASSERT(width > 0);
ASSERT(height > 0); ASSERT(height > 0);
ASSERT(format == static_cast<dawnTextureFormat>(GetPreferredFormat())); ASSERT(format == static_cast<DawnTextureFormat>(GetPreferredFormat()));
ComPtr<IDXGIFactory4> factory = mDevice->GetFactory(); ComPtr<IDXGIFactory4> factory = mDevice->GetFactory();
ComPtr<ID3D12CommandQueue> queue = mDevice->GetCommandQueue(); ComPtr<ID3D12CommandQueue> queue = mDevice->GetCommandQueue();
@ -89,7 +89,7 @@ namespace dawn_native { namespace d3d12 {
return DAWN_SWAP_CHAIN_NO_ERROR; return DAWN_SWAP_CHAIN_NO_ERROR;
} }
dawnSwapChainError NativeSwapChainImpl::GetNextTexture(dawnSwapChainNextTexture* nextTexture) { DawnSwapChainError NativeSwapChainImpl::GetNextTexture(DawnSwapChainNextTexture* nextTexture) {
mCurrentBuffer = mSwapChain->GetCurrentBackBufferIndex(); mCurrentBuffer = mSwapChain->GetCurrentBackBufferIndex();
nextTexture->texture.ptr = mBuffers[mCurrentBuffer].Get(); nextTexture->texture.ptr = mBuffers[mCurrentBuffer].Get();
@ -100,7 +100,7 @@ namespace dawn_native { namespace d3d12 {
return DAWN_SWAP_CHAIN_NO_ERROR; return DAWN_SWAP_CHAIN_NO_ERROR;
} }
dawnSwapChainError NativeSwapChainImpl::Present() { DawnSwapChainError NativeSwapChainImpl::Present() {
// This assumes the texture has already been transition to the PRESENT state. // This assumes the texture has already been transition to the PRESENT state.
ASSERT_SUCCESS(mSwapChain->Present(1, 0)); ASSERT_SUCCESS(mSwapChain->Present(1, 0));

View File

@ -28,18 +28,18 @@ namespace dawn_native { namespace d3d12 {
class NativeSwapChainImpl { class NativeSwapChainImpl {
public: public:
using WSIContext = dawnWSIContextD3D12; using WSIContext = DawnWSIContextD3D12;
NativeSwapChainImpl(Device* device, HWND window); NativeSwapChainImpl(Device* device, HWND window);
~NativeSwapChainImpl(); ~NativeSwapChainImpl();
void Init(dawnWSIContextD3D12* context); void Init(DawnWSIContextD3D12* context);
dawnSwapChainError Configure(dawnTextureFormat format, DawnSwapChainError Configure(DawnTextureFormat format,
dawnTextureUsageBit, DawnTextureUsageBit,
uint32_t width, uint32_t width,
uint32_t height); uint32_t height);
dawnSwapChainError GetNextTexture(dawnSwapChainNextTexture* nextTexture); DawnSwapChainError GetNextTexture(DawnSwapChainNextTexture* nextTexture);
dawnSwapChainError Present(); DawnSwapChainError Present();
dawn::TextureFormat GetPreferredFormat() const; dawn::TextureFormat GetPreferredFormat() const;

View File

@ -24,8 +24,8 @@ namespace dawn_native { namespace d3d12 {
SwapChain::SwapChain(Device* device, const SwapChainDescriptor* descriptor) SwapChain::SwapChain(Device* device, const SwapChainDescriptor* descriptor)
: SwapChainBase(device, descriptor) { : SwapChainBase(device, descriptor) {
const auto& im = GetImplementation(); const auto& im = GetImplementation();
dawnWSIContextD3D12 wsiContext = {}; DawnWSIContextD3D12 wsiContext = {};
wsiContext.device = reinterpret_cast<dawnDevice>(GetDevice()); wsiContext.device = reinterpret_cast<DawnDevice>(GetDevice());
im.Init(im.userData, &wsiContext); im.Init(im.userData, &wsiContext);
ASSERT(im.textureUsage != DAWN_TEXTURE_USAGE_BIT_NONE); ASSERT(im.textureUsage != DAWN_TEXTURE_USAGE_BIT_NONE);
@ -37,8 +37,8 @@ namespace dawn_native { namespace d3d12 {
TextureBase* SwapChain::GetNextTextureImpl(const TextureDescriptor* descriptor) { TextureBase* SwapChain::GetNextTextureImpl(const TextureDescriptor* descriptor) {
const auto& im = GetImplementation(); const auto& im = GetImplementation();
dawnSwapChainNextTexture next = {}; DawnSwapChainNextTexture next = {};
dawnSwapChainError error = im.GetNextTexture(im.userData, &next); DawnSwapChainError error = im.GetNextTexture(im.userData, &next);
if (error) { if (error) {
GetDevice()->HandleError(error); GetDevice()->HandleError(error);
return nullptr; return nullptr;

View File

@ -15,7 +15,7 @@
#ifndef DAWNNATIVE_DAWNPLATFORM_H_ #ifndef DAWNNATIVE_DAWNPLATFORM_H_
#define DAWNNATIVE_DAWNPLATFORM_H_ #define DAWNNATIVE_DAWNPLATFORM_H_
// Use dawncpp to have the enum and bitfield definitions // Use cawncpp to have the enum and bitfield definitions
#include <dawn/dawncpp.h> #include <dawn/dawncpp.h>
// Use our autogenerated version of the dawn structures that point to dawn_native object types // Use our autogenerated version of the dawn structures that point to dawn_native object types

View File

@ -22,20 +22,20 @@
namespace dawn_native { namespace metal { namespace dawn_native { namespace metal {
id<MTLDevice> GetMetalDevice(dawnDevice cDevice) { id<MTLDevice> GetMetalDevice(DawnDevice cDevice) {
Device* device = reinterpret_cast<Device*>(cDevice); Device* device = reinterpret_cast<Device*>(cDevice);
return device->GetMTLDevice(); return device->GetMTLDevice();
} }
dawnTexture WrapIOSurface(dawnDevice cDevice, DawnTexture WrapIOSurface(DawnDevice cDevice,
const dawnTextureDescriptor* cDescriptor, const DawnTextureDescriptor* cDescriptor,
IOSurfaceRef ioSurface, IOSurfaceRef ioSurface,
uint32_t plane) { uint32_t plane) {
Device* device = reinterpret_cast<Device*>(cDevice); Device* device = reinterpret_cast<Device*>(cDevice);
const TextureDescriptor* descriptor = const TextureDescriptor* descriptor =
reinterpret_cast<const TextureDescriptor*>(cDescriptor); reinterpret_cast<const TextureDescriptor*>(cDescriptor);
TextureBase* texture = device->CreateTextureWrappingIOSurface(descriptor, ioSurface, plane); TextureBase* texture = device->CreateTextureWrappingIOSurface(descriptor, ioSurface, plane);
return reinterpret_cast<dawnTexture>(texture); return reinterpret_cast<DawnTexture>(texture);
} }
}} // namespace dawn_native::metal }} // namespace dawn_native::metal

View File

@ -24,7 +24,7 @@ namespace dawn_native { namespace metal {
SwapChain::SwapChain(Device* device, const SwapChainDescriptor* descriptor) SwapChain::SwapChain(Device* device, const SwapChainDescriptor* descriptor)
: SwapChainBase(device, descriptor) { : SwapChainBase(device, descriptor) {
const auto& im = GetImplementation(); const auto& im = GetImplementation();
dawnWSIContextMetal wsiContext = {}; DawnWSIContextMetal wsiContext = {};
wsiContext.device = ToBackend(GetDevice())->GetMTLDevice(); wsiContext.device = ToBackend(GetDevice())->GetMTLDevice();
im.Init(im.userData, &wsiContext); im.Init(im.userData, &wsiContext);
} }
@ -34,8 +34,8 @@ namespace dawn_native { namespace metal {
TextureBase* SwapChain::GetNextTextureImpl(const TextureDescriptor* descriptor) { TextureBase* SwapChain::GetNextTextureImpl(const TextureDescriptor* descriptor) {
const auto& im = GetImplementation(); const auto& im = GetImplementation();
dawnSwapChainNextTexture next = {}; DawnSwapChainNextTexture next = {};
dawnSwapChainError error = im.GetNextTexture(im.userData, &next); DawnSwapChainError error = im.GetNextTexture(im.userData, &next);
if (error) { if (error) {
GetDevice()->HandleError(error); GetDevice()->HandleError(error);
return nullptr; return nullptr;

View File

@ -271,18 +271,18 @@ namespace dawn_native { namespace null {
void NativeSwapChainImpl::Init(WSIContext* context) { void NativeSwapChainImpl::Init(WSIContext* context) {
} }
dawnSwapChainError NativeSwapChainImpl::Configure(dawnTextureFormat format, DawnSwapChainError NativeSwapChainImpl::Configure(DawnTextureFormat format,
dawnTextureUsageBit, DawnTextureUsageBit,
uint32_t width, uint32_t width,
uint32_t height) { uint32_t height) {
return DAWN_SWAP_CHAIN_NO_ERROR; return DAWN_SWAP_CHAIN_NO_ERROR;
} }
dawnSwapChainError NativeSwapChainImpl::GetNextTexture(dawnSwapChainNextTexture* nextTexture) { DawnSwapChainError NativeSwapChainImpl::GetNextTexture(DawnSwapChainNextTexture* nextTexture) {
return DAWN_SWAP_CHAIN_NO_ERROR; return DAWN_SWAP_CHAIN_NO_ERROR;
} }
dawnSwapChainError NativeSwapChainImpl::Present() { DawnSwapChainError NativeSwapChainImpl::Present() {
return DAWN_SWAP_CHAIN_NO_ERROR; return DAWN_SWAP_CHAIN_NO_ERROR;
} }

View File

@ -184,12 +184,12 @@ namespace dawn_native { namespace null {
public: public:
using WSIContext = struct {}; using WSIContext = struct {};
void Init(WSIContext* context); void Init(WSIContext* context);
dawnSwapChainError Configure(dawnTextureFormat format, DawnSwapChainError Configure(DawnTextureFormat format,
dawnTextureUsageBit, DawnTextureUsageBit,
uint32_t width, uint32_t width,
uint32_t height); uint32_t height);
dawnSwapChainError GetNextTexture(dawnSwapChainNextTexture* nextTexture); DawnSwapChainError GetNextTexture(DawnSwapChainNextTexture* nextTexture);
dawnSwapChainError Present(); DawnSwapChainError Present();
dawn::TextureFormat GetPreferredFormat() const; dawn::TextureFormat GetPreferredFormat() const;
}; };

View File

@ -22,8 +22,8 @@
namespace dawn_native { namespace null { namespace dawn_native { namespace null {
dawnSwapChainImplementation CreateNativeSwapChainImpl() { DawnSwapChainImplementation CreateNativeSwapChainImpl() {
dawnSwapChainImplementation impl; DawnSwapChainImplementation impl;
impl = CreateSwapChainImplementation(new NativeSwapChainImpl()); impl = CreateSwapChainImplementation(new NativeSwapChainImpl());
impl.textureUsage = DAWN_TEXTURE_USAGE_BIT_PRESENT; impl.textureUsage = DAWN_TEXTURE_USAGE_BIT_PRESENT;
return impl; return impl;

View File

@ -33,8 +33,8 @@ namespace dawn_native { namespace opengl {
TextureBase* SwapChain::GetNextTextureImpl(const TextureDescriptor* descriptor) { TextureBase* SwapChain::GetNextTextureImpl(const TextureDescriptor* descriptor) {
const auto& im = GetImplementation(); const auto& im = GetImplementation();
dawnSwapChainNextTexture next = {}; DawnSwapChainNextTexture next = {};
dawnSwapChainError error = im.GetNextTexture(im.userData, &next); DawnSwapChainError error = im.GetNextTexture(im.userData, &next);
if (error) { if (error) {
GetDevice()->HandleError(error); GetDevice()->HandleError(error);
return nullptr; return nullptr;

View File

@ -57,7 +57,7 @@ namespace dawn_native { namespace vulkan {
} }
} }
void NativeSwapChainImpl::Init(dawnWSIContextVulkan* /*context*/) { void NativeSwapChainImpl::Init(DawnWSIContextVulkan* /*context*/) {
if (mDevice->ConsumedError( if (mDevice->ConsumedError(
GatherSurfaceInfo(*ToBackend(mDevice->GetAdapter()), mSurface, &mInfo))) { GatherSurfaceInfo(*ToBackend(mDevice->GetAdapter()), mSurface, &mInfo))) {
ASSERT(false); ASSERT(false);
@ -68,8 +68,8 @@ namespace dawn_native { namespace vulkan {
} }
} }
dawnSwapChainError NativeSwapChainImpl::Configure(dawnTextureFormat format, DawnSwapChainError NativeSwapChainImpl::Configure(DawnTextureFormat format,
dawnTextureUsageBit usage, DawnTextureUsageBit usage,
uint32_t width, uint32_t width,
uint32_t height) { uint32_t height) {
ASSERT(mInfo.capabilities.minImageExtent.width <= width); ASSERT(mInfo.capabilities.minImageExtent.width <= width);
@ -77,7 +77,7 @@ namespace dawn_native { namespace vulkan {
ASSERT(mInfo.capabilities.minImageExtent.height <= height); ASSERT(mInfo.capabilities.minImageExtent.height <= height);
ASSERT(mInfo.capabilities.maxImageExtent.height >= height); ASSERT(mInfo.capabilities.maxImageExtent.height >= height);
ASSERT(format == static_cast<dawnTextureFormat>(GetPreferredFormat())); ASSERT(format == static_cast<DawnTextureFormat>(GetPreferredFormat()));
// TODO(cwallez@chromium.org): need to check usage works too // TODO(cwallez@chromium.org): need to check usage works too
// Create the swapchain with the configuration we chose // Create the swapchain with the configuration we chose
@ -151,7 +151,7 @@ namespace dawn_native { namespace vulkan {
return DAWN_SWAP_CHAIN_NO_ERROR; return DAWN_SWAP_CHAIN_NO_ERROR;
} }
dawnSwapChainError NativeSwapChainImpl::GetNextTexture(dawnSwapChainNextTexture* nextTexture) { DawnSwapChainError NativeSwapChainImpl::GetNextTexture(DawnSwapChainNextTexture* nextTexture) {
// Transiently create a semaphore that will be signaled when the presentation engine is done // Transiently create a semaphore that will be signaled when the presentation engine is done
// with the swapchain image. Further operations on the image will wait for this semaphore. // with the swapchain image. Further operations on the image will wait for this semaphore.
VkSemaphore semaphore = VK_NULL_HANDLE; VkSemaphore semaphore = VK_NULL_HANDLE;
@ -178,7 +178,7 @@ namespace dawn_native { namespace vulkan {
return DAWN_SWAP_CHAIN_NO_ERROR; return DAWN_SWAP_CHAIN_NO_ERROR;
} }
dawnSwapChainError NativeSwapChainImpl::Present() { DawnSwapChainError NativeSwapChainImpl::Present() {
// This assumes that the image has already been transitioned to the PRESENT layout and // This assumes that the image has already been transitioned to the PRESENT layout and
// writes were made available to the stage. // writes were made available to the stage.

View File

@ -26,18 +26,18 @@ namespace dawn_native { namespace vulkan {
class NativeSwapChainImpl { class NativeSwapChainImpl {
public: public:
using WSIContext = dawnWSIContextVulkan; using WSIContext = DawnWSIContextVulkan;
NativeSwapChainImpl(Device* device, VkSurfaceKHR surface); NativeSwapChainImpl(Device* device, VkSurfaceKHR surface);
~NativeSwapChainImpl(); ~NativeSwapChainImpl();
void Init(dawnWSIContextVulkan* context); void Init(DawnWSIContextVulkan* context);
dawnSwapChainError Configure(dawnTextureFormat format, DawnSwapChainError Configure(DawnTextureFormat format,
dawnTextureUsageBit, DawnTextureUsageBit,
uint32_t width, uint32_t width,
uint32_t height); uint32_t height);
dawnSwapChainError GetNextTexture(dawnSwapChainNextTexture* nextTexture); DawnSwapChainError GetNextTexture(DawnSwapChainNextTexture* nextTexture);
dawnSwapChainError Present(); DawnSwapChainError Present();
dawn::TextureFormat GetPreferredFormat() const; dawn::TextureFormat GetPreferredFormat() const;

View File

@ -22,7 +22,7 @@ namespace dawn_native { namespace vulkan {
SwapChain::SwapChain(Device* device, const SwapChainDescriptor* descriptor) SwapChain::SwapChain(Device* device, const SwapChainDescriptor* descriptor)
: SwapChainBase(device, descriptor) { : SwapChainBase(device, descriptor) {
const auto& im = GetImplementation(); const auto& im = GetImplementation();
dawnWSIContextVulkan wsiContext = {}; DawnWSIContextVulkan wsiContext = {};
im.Init(im.userData, &wsiContext); im.Init(im.userData, &wsiContext);
ASSERT(im.textureUsage != DAWN_TEXTURE_USAGE_BIT_NONE); ASSERT(im.textureUsage != DAWN_TEXTURE_USAGE_BIT_NONE);
@ -34,8 +34,8 @@ namespace dawn_native { namespace vulkan {
TextureBase* SwapChain::GetNextTextureImpl(const TextureDescriptor* descriptor) { TextureBase* SwapChain::GetNextTextureImpl(const TextureDescriptor* descriptor) {
const auto& im = GetImplementation(); const auto& im = GetImplementation();
dawnSwapChainNextTexture next = {}; DawnSwapChainNextTexture next = {};
dawnSwapChainError error = im.GetNextTexture(im.userData, &next); DawnSwapChainError error = im.GetNextTexture(im.userData, &next);
if (error) { if (error) {
GetDevice()->HandleError(error); GetDevice()->HandleError(error);

View File

@ -27,29 +27,29 @@
namespace dawn_native { namespace vulkan { namespace dawn_native { namespace vulkan {
VkInstance GetInstance(dawnDevice device) { VkInstance GetInstance(DawnDevice device) {
Device* backendDevice = reinterpret_cast<Device*>(device); Device* backendDevice = reinterpret_cast<Device*>(device);
return backendDevice->GetVkInstance(); return backendDevice->GetVkInstance();
} }
// Explicitly export this function because it uses the "native" type for surfaces while the // Explicitly export this function because it uses the "native" type for surfaces while the
// header as seen in this file uses the wrapped type. // header as seen in this file uses the wrapped type.
DAWN_NATIVE_EXPORT dawnSwapChainImplementation DAWN_NATIVE_EXPORT DawnSwapChainImplementation
CreateNativeSwapChainImpl(dawnDevice device, VkSurfaceKHRNative surfaceNative) { CreateNativeSwapChainImpl(DawnDevice device, VkSurfaceKHRNative surfaceNative) {
Device* backendDevice = reinterpret_cast<Device*>(device); Device* backendDevice = reinterpret_cast<Device*>(device);
VkSurfaceKHR surface = VkSurfaceKHR::CreateFromHandle(surfaceNative); VkSurfaceKHR surface = VkSurfaceKHR::CreateFromHandle(surfaceNative);
dawnSwapChainImplementation impl; DawnSwapChainImplementation impl;
impl = CreateSwapChainImplementation(new NativeSwapChainImpl(backendDevice, surface)); impl = CreateSwapChainImplementation(new NativeSwapChainImpl(backendDevice, surface));
impl.textureUsage = DAWN_TEXTURE_USAGE_BIT_PRESENT; impl.textureUsage = DAWN_TEXTURE_USAGE_BIT_PRESENT;
return impl; return impl;
} }
dawnTextureFormat GetNativeSwapChainPreferredFormat( DawnTextureFormat GetNativeSwapChainPreferredFormat(
const dawnSwapChainImplementation* swapChain) { const DawnSwapChainImplementation* swapChain) {
NativeSwapChainImpl* impl = reinterpret_cast<NativeSwapChainImpl*>(swapChain->userData); NativeSwapChainImpl* impl = reinterpret_cast<NativeSwapChainImpl*>(swapChain->userData);
return static_cast<dawnTextureFormat>(impl->GetPreferredFormat()); return static_cast<DawnTextureFormat>(impl->GetPreferredFormat());
} }
}} // namespace dawn_native::vulkan }} // namespace dawn_native::vulkan

View File

@ -24,11 +24,11 @@ namespace dawn_wire {
mImpl.reset(); mImpl.reset();
} }
dawnDevice WireClient::GetDevice() const { DawnDevice WireClient::GetDevice() const {
return mImpl->GetDevice(); return mImpl->GetDevice();
} }
dawnProcTable WireClient::GetProcs() const { DawnProcTable WireClient::GetProcs() const {
return client::GetProcs(); return client::GetProcs();
} }

View File

@ -17,8 +17,8 @@
namespace dawn_wire { namespace dawn_wire {
WireServer::WireServer(dawnDevice device, WireServer::WireServer(DawnDevice device,
const dawnProcTable& procs, const DawnProcTable& procs,
CommandSerializer* serializer) CommandSerializer* serializer)
: mImpl(new server::Server(device, procs, serializer)) { : mImpl(new server::Server(device, procs, serializer)) {
} }

View File

@ -18,9 +18,9 @@
namespace dawn_wire { namespace client { namespace dawn_wire { namespace client {
void ClientBufferMapReadAsync(dawnBuffer cBuffer, void ClientBufferMapReadAsync(DawnBuffer cBuffer,
dawnBufferMapReadCallback callback, DawnBufferMapReadCallback callback,
dawnCallbackUserdata userdata) { DawnCallbackUserdata userdata) {
Buffer* buffer = reinterpret_cast<Buffer*>(cBuffer); Buffer* buffer = reinterpret_cast<Buffer*>(cBuffer);
uint32_t serial = buffer->requestSerial++; uint32_t serial = buffer->requestSerial++;
@ -43,9 +43,9 @@ namespace dawn_wire { namespace client {
cmd.Serialize(allocatedBuffer); cmd.Serialize(allocatedBuffer);
} }
void ClientBufferMapWriteAsync(dawnBuffer cBuffer, void ClientBufferMapWriteAsync(DawnBuffer cBuffer,
dawnBufferMapWriteCallback callback, DawnBufferMapWriteCallback callback,
dawnCallbackUserdata userdata) { DawnCallbackUserdata userdata) {
Buffer* buffer = reinterpret_cast<Buffer*>(cBuffer); Buffer* buffer = reinterpret_cast<Buffer*>(cBuffer);
uint32_t serial = buffer->requestSerial++; uint32_t serial = buffer->requestSerial++;
@ -68,15 +68,15 @@ namespace dawn_wire { namespace client {
cmd.Serialize(allocatedBuffer); cmd.Serialize(allocatedBuffer);
} }
uint64_t ClientFenceGetCompletedValue(dawnFence cSelf) { uint64_t ClientFenceGetCompletedValue(DawnFence cSelf) {
auto fence = reinterpret_cast<Fence*>(cSelf); auto fence = reinterpret_cast<Fence*>(cSelf);
return fence->completedValue; return fence->completedValue;
} }
void ClientFenceOnCompletion(dawnFence cFence, void ClientFenceOnCompletion(DawnFence cFence,
uint64_t value, uint64_t value,
dawnFenceOnCompletionCallback callback, DawnFenceOnCompletionCallback callback,
dawnCallbackUserdata userdata) { DawnCallbackUserdata userdata) {
Fence* fence = reinterpret_cast<Fence*>(cFence); Fence* fence = reinterpret_cast<Fence*>(cFence);
if (value > fence->signaledValue) { if (value > fence->signaledValue) {
fence->device->HandleError("Value greater than fence signaled value"); fence->device->HandleError("Value greater than fence signaled value");
@ -95,7 +95,7 @@ namespace dawn_wire { namespace client {
fence->requests.Enqueue(std::move(request), value); fence->requests.Enqueue(std::move(request), value);
} }
void ClientBufferUnmap(dawnBuffer cBuffer) { void ClientBufferUnmap(DawnBuffer cBuffer) {
Buffer* buffer = reinterpret_cast<Buffer*>(cBuffer); Buffer* buffer = reinterpret_cast<Buffer*>(cBuffer);
// Invalidate the local pointer, and cancel all other in-flight requests that would // Invalidate the local pointer, and cancel all other in-flight requests that would
@ -133,7 +133,7 @@ namespace dawn_wire { namespace client {
cmd.Serialize(allocatedBuffer, *buffer->device->GetClient()); cmd.Serialize(allocatedBuffer, *buffer->device->GetClient());
} }
dawnFence ClientQueueCreateFence(dawnQueue cSelf, dawnFenceDescriptor const* descriptor) { DawnFence ClientQueueCreateFence(DawnQueue cSelf, DawnFenceDescriptor const* descriptor) {
Queue* queue = reinterpret_cast<Queue*>(cSelf); Queue* queue = reinterpret_cast<Queue*>(cSelf);
Device* device = queue->device; Device* device = queue->device;
@ -147,7 +147,7 @@ namespace dawn_wire { namespace client {
char* allocatedBuffer = static_cast<char*>(device->GetClient()->GetCmdSpace(requiredSize)); char* allocatedBuffer = static_cast<char*>(device->GetClient()->GetCmdSpace(requiredSize));
cmd.Serialize(allocatedBuffer, *device->GetClient()); cmd.Serialize(allocatedBuffer, *device->GetClient());
dawnFence cFence = reinterpret_cast<dawnFence>(allocation->object.get()); DawnFence cFence = reinterpret_cast<DawnFence>(allocation->object.get());
Fence* fence = reinterpret_cast<Fence*>(cFence); Fence* fence = reinterpret_cast<Fence*>(cFence);
fence->queue = queue; fence->queue = queue;
@ -156,7 +156,7 @@ namespace dawn_wire { namespace client {
return cFence; return cFence;
} }
void ClientQueueSignal(dawnQueue cQueue, dawnFence cFence, uint64_t signalValue) { void ClientQueueSignal(DawnQueue cQueue, DawnFence cFence, uint64_t signalValue) {
Fence* fence = reinterpret_cast<Fence*>(cFence); Fence* fence = reinterpret_cast<Fence*>(cFence);
Queue* queue = reinterpret_cast<Queue*>(cQueue); Queue* queue = reinterpret_cast<Queue*>(cQueue);
if (fence->queue != queue) { if (fence->queue != queue) {
@ -181,15 +181,15 @@ namespace dawn_wire { namespace client {
cmd.Serialize(allocatedBuffer, *fence->device->GetClient()); cmd.Serialize(allocatedBuffer, *fence->device->GetClient());
} }
void ClientDeviceReference(dawnDevice) { void ClientDeviceReference(DawnDevice) {
} }
void ClientDeviceRelease(dawnDevice) { void ClientDeviceRelease(DawnDevice) {
} }
void ClientDeviceSetErrorCallback(dawnDevice cSelf, void ClientDeviceSetErrorCallback(DawnDevice cSelf,
dawnDeviceErrorCallback callback, DawnDeviceErrorCallback callback,
dawnCallbackUserdata userdata) { DawnCallbackUserdata userdata) {
Device* device = reinterpret_cast<Device*>(cSelf); Device* device = reinterpret_cast<Device*>(cSelf);
device->SetErrorCallback(callback, userdata); device->SetErrorCallback(callback, userdata);
} }

View File

@ -26,7 +26,7 @@ namespace dawn_wire { namespace client {
} }
} }
void Buffer::ClearMapRequests(dawnBufferMapAsyncStatus status) { void Buffer::ClearMapRequests(DawnBufferMapAsyncStatus status) {
for (auto& it : requests) { for (auto& it : requests) {
if (it.second.isWrite) { if (it.second.isWrite) {
it.second.writeCallback(status, nullptr, 0, it.second.userdata); it.second.writeCallback(status, nullptr, 0, it.second.userdata);

View File

@ -27,15 +27,15 @@ namespace dawn_wire { namespace client {
using ObjectBase::ObjectBase; using ObjectBase::ObjectBase;
~Buffer(); ~Buffer();
void ClearMapRequests(dawnBufferMapAsyncStatus status); void ClearMapRequests(DawnBufferMapAsyncStatus status);
// We want to defer all the validation to the server, which means we could have multiple // We want to defer all the validation to the server, which means we could have multiple
// map request in flight at a single time and need to track them separately. // map request in flight at a single time and need to track them separately.
// On well-behaved applications, only one request should exist at a single time. // On well-behaved applications, only one request should exist at a single time.
struct MapRequestData { struct MapRequestData {
dawnBufferMapReadCallback readCallback = nullptr; DawnBufferMapReadCallback readCallback = nullptr;
dawnBufferMapWriteCallback writeCallback = nullptr; DawnBufferMapWriteCallback writeCallback = nullptr;
dawnCallbackUserdata userdata = 0; DawnCallbackUserdata userdata = 0;
bool isWrite = false; bool isWrite = false;
}; };
std::map<uint32_t, MapRequestData> requests; std::map<uint32_t, MapRequestData> requests;

View File

@ -36,8 +36,8 @@ namespace dawn_wire { namespace client {
return mSerializer->GetCmdSpace(size); return mSerializer->GetCmdSpace(size);
} }
dawnDevice GetDevice() const { DawnDevice GetDevice() const {
return reinterpret_cast<dawnDeviceImpl*>(mDevice); return reinterpret_cast<DawnDeviceImpl*>(mDevice);
} }
private: private:
@ -48,7 +48,7 @@ namespace dawn_wire { namespace client {
WireDeserializeAllocator mAllocator; WireDeserializeAllocator mAllocator;
}; };
dawnProcTable GetProcs(); DawnProcTable GetProcs();
}} // namespace dawn_wire::client }} // namespace dawn_wire::client

View File

@ -64,10 +64,10 @@ namespace dawn_wire { namespace client {
buffer->mappedData = malloc(dataLength); buffer->mappedData = malloc(dataLength);
memcpy(buffer->mappedData, data, dataLength); memcpy(buffer->mappedData, data, dataLength);
request.readCallback(static_cast<dawnBufferMapAsyncStatus>(status), buffer->mappedData, request.readCallback(static_cast<DawnBufferMapAsyncStatus>(status), buffer->mappedData,
dataLength, request.userdata); dataLength, request.userdata);
} else { } else {
request.readCallback(static_cast<dawnBufferMapAsyncStatus>(status), nullptr, 0, request.readCallback(static_cast<DawnBufferMapAsyncStatus>(status), nullptr, 0,
request.userdata); request.userdata);
} }
@ -111,10 +111,10 @@ namespace dawn_wire { namespace client {
buffer->mappedData = malloc(dataLength); buffer->mappedData = malloc(dataLength);
memset(buffer->mappedData, 0, dataLength); memset(buffer->mappedData, 0, dataLength);
request.writeCallback(static_cast<dawnBufferMapAsyncStatus>(status), buffer->mappedData, request.writeCallback(static_cast<DawnBufferMapAsyncStatus>(status), buffer->mappedData,
dataLength, request.userdata); dataLength, request.userdata);
} else { } else {
request.writeCallback(static_cast<dawnBufferMapAsyncStatus>(status), nullptr, 0, request.writeCallback(static_cast<DawnBufferMapAsyncStatus>(status), nullptr, 0,
request.userdata); request.userdata);
} }

View File

@ -31,8 +31,8 @@ namespace dawn_wire { namespace client {
} }
} }
void Device::SetErrorCallback(dawnDeviceErrorCallback errorCallback, void Device::SetErrorCallback(DawnDeviceErrorCallback errorCallback,
dawnCallbackUserdata errorUserdata) { DawnCallbackUserdata errorUserdata) {
mErrorCallback = errorCallback; mErrorCallback = errorCallback;
mErrorUserdata = errorUserdata; mErrorUserdata = errorUserdata;
} }

View File

@ -29,13 +29,13 @@ namespace dawn_wire { namespace client {
Client* GetClient(); Client* GetClient();
void HandleError(const char* message); void HandleError(const char* message);
void SetErrorCallback(dawnDeviceErrorCallback errorCallback, void SetErrorCallback(DawnDeviceErrorCallback errorCallback,
dawnCallbackUserdata errorUserdata); DawnCallbackUserdata errorUserdata);
private: private:
Client* mClient = nullptr; Client* mClient = nullptr;
dawnDeviceErrorCallback mErrorCallback = nullptr; DawnDeviceErrorCallback mErrorCallback = nullptr;
dawnCallbackUserdata mErrorUserdata; DawnCallbackUserdata mErrorUserdata;
}; };
}} // namespace dawn_wire::client }} // namespace dawn_wire::client

View File

@ -30,8 +30,8 @@ namespace dawn_wire { namespace client {
void CheckPassedFences(); void CheckPassedFences();
struct OnCompletionData { struct OnCompletionData {
dawnFenceOnCompletionCallback completionCallback = nullptr; DawnFenceOnCompletionCallback completionCallback = nullptr;
dawnCallbackUserdata userdata = 0; DawnCallbackUserdata userdata = 0;
}; };
Queue* queue = nullptr; Queue* queue = nullptr;
uint64_t signaledValue = 0; uint64_t signaledValue = 0;

View File

@ -22,7 +22,7 @@ namespace dawn_wire { namespace client {
class Device; class Device;
struct BuilderCallbackData { struct BuilderCallbackData {
bool Call(dawnBuilderErrorStatus status, const char* message) { bool Call(DawnBuilderErrorStatus status, const char* message) {
if (canCall && callback != nullptr) { if (canCall && callback != nullptr) {
canCall = true; canCall = true;
callback(status, message, userdata1, userdata2); callback(status, message, userdata1, userdata2);
@ -33,9 +33,9 @@ namespace dawn_wire { namespace client {
} }
// For help with development, prints all builder errors by default. // For help with development, prints all builder errors by default.
dawnBuilderErrorCallback callback = nullptr; DawnBuilderErrorCallback callback = nullptr;
dawnCallbackUserdata userdata1 = 0; DawnCallbackUserdata userdata1 = 0;
dawnCallbackUserdata userdata2 = 0; DawnCallbackUserdata userdata2 = 0;
bool canCall = true; bool canCall = true;
}; };

View File

@ -48,7 +48,7 @@ namespace dawn_wire { namespace server {
}; };
template <> template <>
struct ObjectData<dawnBuffer, false> : public ObjectDataBase<dawnBuffer> { struct ObjectData<DawnBuffer, false> : public ObjectDataBase<DawnBuffer> {
void* mappedData = nullptr; void* mappedData = nullptr;
size_t mappedDataSize = 0; size_t mappedDataSize = 0;
}; };

View File

@ -16,14 +16,14 @@
namespace dawn_wire { namespace server { namespace dawn_wire { namespace server {
Server::Server(dawnDevice device, const dawnProcTable& procs, CommandSerializer* serializer) Server::Server(DawnDevice device, const DawnProcTable& procs, CommandSerializer* serializer)
: mSerializer(serializer), mProcs(procs) { : mSerializer(serializer), mProcs(procs) {
// The client-server knowledge is bootstrapped with device 1. // The client-server knowledge is bootstrapped with device 1.
auto* deviceData = DeviceObjects().Allocate(1); auto* deviceData = DeviceObjects().Allocate(1);
deviceData->handle = device; deviceData->handle = device;
deviceData->valid = true; deviceData->valid = true;
auto userdata = static_cast<dawnCallbackUserdata>(reinterpret_cast<intptr_t>(this)); auto userdata = static_cast<DawnCallbackUserdata>(reinterpret_cast<intptr_t>(this));
procs.deviceSetErrorCallback(device, ForwardDeviceError, userdata); procs.deviceSetErrorCallback(device, ForwardDeviceError, userdata);
} }

View File

@ -37,7 +37,7 @@ namespace dawn_wire { namespace server {
class Server : public ServerBase { class Server : public ServerBase {
public: public:
Server(dawnDevice device, const dawnProcTable& procs, CommandSerializer* serializer); Server(DawnDevice device, const DawnProcTable& procs, CommandSerializer* serializer);
~Server(); ~Server();
const char* HandleCommands(const char* commands, size_t size); const char* HandleCommands(const char* commands, size_t size);
@ -46,25 +46,25 @@ namespace dawn_wire { namespace server {
void* GetCmdSpace(size_t size); void* GetCmdSpace(size_t size);
// Forwarding callbacks // Forwarding callbacks
static void ForwardDeviceError(const char* message, dawnCallbackUserdata userdata); static void ForwardDeviceError(const char* message, DawnCallbackUserdata userdata);
static void ForwardBufferMapReadAsync(dawnBufferMapAsyncStatus status, static void ForwardBufferMapReadAsync(DawnBufferMapAsyncStatus status,
const void* ptr, const void* ptr,
uint32_t dataLength, uint32_t dataLength,
dawnCallbackUserdata userdata); DawnCallbackUserdata userdata);
static void ForwardBufferMapWriteAsync(dawnBufferMapAsyncStatus status, static void ForwardBufferMapWriteAsync(DawnBufferMapAsyncStatus status,
void* ptr, void* ptr,
uint32_t dataLength, uint32_t dataLength,
dawnCallbackUserdata userdata); DawnCallbackUserdata userdata);
static void ForwardFenceCompletedValue(dawnFenceCompletionStatus status, static void ForwardFenceCompletedValue(DawnFenceCompletionStatus status,
dawnCallbackUserdata userdata); DawnCallbackUserdata userdata);
// Error callbacks // Error callbacks
void OnDeviceError(const char* message); void OnDeviceError(const char* message);
void OnBufferMapReadAsyncCallback(dawnBufferMapAsyncStatus status, void OnBufferMapReadAsyncCallback(DawnBufferMapAsyncStatus status,
const void* ptr, const void* ptr,
uint32_t dataLength, uint32_t dataLength,
MapUserdata* userdata); MapUserdata* userdata);
void OnBufferMapWriteAsyncCallback(dawnBufferMapAsyncStatus status, void OnBufferMapWriteAsyncCallback(DawnBufferMapAsyncStatus status,
void* ptr, void* ptr,
uint32_t dataLength, uint32_t dataLength,
MapUserdata* userdata); MapUserdata* userdata);
@ -74,7 +74,7 @@ namespace dawn_wire { namespace server {
CommandSerializer* mSerializer = nullptr; CommandSerializer* mSerializer = nullptr;
WireDeserializeAllocator mAllocator; WireDeserializeAllocator mAllocator;
dawnProcTable mProcs; DawnProcTable mProcs;
}; };
}} // namespace dawn_wire::server }} // namespace dawn_wire::server

View File

@ -93,23 +93,23 @@ namespace dawn_wire { namespace server {
return true; return true;
} }
void Server::ForwardBufferMapReadAsync(dawnBufferMapAsyncStatus status, void Server::ForwardBufferMapReadAsync(DawnBufferMapAsyncStatus status,
const void* ptr, const void* ptr,
uint32_t dataLength, uint32_t dataLength,
dawnCallbackUserdata userdata) { DawnCallbackUserdata userdata) {
auto data = reinterpret_cast<MapUserdata*>(static_cast<uintptr_t>(userdata)); auto data = reinterpret_cast<MapUserdata*>(static_cast<uintptr_t>(userdata));
data->server->OnBufferMapReadAsyncCallback(status, ptr, dataLength, data); data->server->OnBufferMapReadAsyncCallback(status, ptr, dataLength, data);
} }
void Server::ForwardBufferMapWriteAsync(dawnBufferMapAsyncStatus status, void Server::ForwardBufferMapWriteAsync(DawnBufferMapAsyncStatus status,
void* ptr, void* ptr,
uint32_t dataLength, uint32_t dataLength,
dawnCallbackUserdata userdata) { DawnCallbackUserdata userdata) {
auto data = reinterpret_cast<MapUserdata*>(static_cast<uintptr_t>(userdata)); auto data = reinterpret_cast<MapUserdata*>(static_cast<uintptr_t>(userdata));
data->server->OnBufferMapWriteAsyncCallback(status, ptr, dataLength, data); data->server->OnBufferMapWriteAsyncCallback(status, ptr, dataLength, data);
} }
void Server::OnBufferMapReadAsyncCallback(dawnBufferMapAsyncStatus status, void Server::OnBufferMapReadAsyncCallback(DawnBufferMapAsyncStatus status,
const void* ptr, const void* ptr,
uint32_t dataLength, uint32_t dataLength,
MapUserdata* userdata) { MapUserdata* userdata) {
@ -137,7 +137,7 @@ namespace dawn_wire { namespace server {
cmd.Serialize(allocatedBuffer); cmd.Serialize(allocatedBuffer);
} }
void Server::OnBufferMapWriteAsyncCallback(dawnBufferMapAsyncStatus status, void Server::OnBufferMapWriteAsyncCallback(DawnBufferMapAsyncStatus status,
void* ptr, void* ptr,
uint32_t dataLength, uint32_t dataLength,
MapUserdata* userdata) { MapUserdata* userdata) {

View File

@ -16,7 +16,7 @@
namespace dawn_wire { namespace server { namespace dawn_wire { namespace server {
void Server::ForwardDeviceError(const char* message, dawnCallbackUserdata userdata) { void Server::ForwardDeviceError(const char* message, DawnCallbackUserdata userdata) {
auto server = reinterpret_cast<Server*>(static_cast<intptr_t>(userdata)); auto server = reinterpret_cast<Server*>(static_cast<intptr_t>(userdata));
server->OnDeviceError(message); server->OnDeviceError(message);
} }

View File

@ -18,8 +18,8 @@
namespace dawn_wire { namespace server { namespace dawn_wire { namespace server {
void Server::ForwardFenceCompletedValue(dawnFenceCompletionStatus status, void Server::ForwardFenceCompletedValue(DawnFenceCompletionStatus status,
dawnCallbackUserdata userdata) { DawnCallbackUserdata userdata) {
auto data = reinterpret_cast<FenceCompletionUserdata*>(static_cast<uintptr_t>(userdata)); auto data = reinterpret_cast<FenceCompletionUserdata*>(static_cast<uintptr_t>(userdata));
if (status == DAWN_FENCE_COMPLETION_STATUS_SUCCESS) { if (status == DAWN_FENCE_COMPLETION_STATUS_SUCCESS) {
data->server->OnFenceCompletedValueUpdated(data); data->server->OnFenceCompletedValueUpdated(data);

View File

@ -17,7 +17,7 @@
namespace dawn_wire { namespace server { namespace dawn_wire { namespace server {
bool Server::DoQueueSignal(dawnQueue cSelf, dawnFence cFence, uint64_t signalValue) { bool Server::DoQueueSignal(DawnQueue cSelf, DawnFence cFence, uint64_t signalValue) {
if (cFence == nullptr) { if (cFence == nullptr) {
return false; return false;
} }

View File

@ -35,10 +35,10 @@ class DevNull : public dawn_wire::CommandSerializer {
std::vector<char> buf; std::vector<char> buf;
}; };
static dawnProcDeviceCreateSwapChain originalDeviceCreateSwapChain = nullptr; static DawnProcDeviceCreateSwapChain originalDeviceCreateSwapChain = nullptr;
dawnSwapChain ErrorDeviceCreateSwapChain(dawnDevice device, const dawnSwapChainDescriptor*) { DawnSwapChain ErrorDeviceCreateSwapChain(DawnDevice device, const DawnSwapChainDescriptor*) {
dawnSwapChainDescriptor desc; DawnSwapChainDescriptor desc;
desc.nextInChain = nullptr; desc.nextInChain = nullptr;
// A 0 implementation will trigger a swapchain creation error. // A 0 implementation will trigger a swapchain creation error.
desc.implementation = 0; desc.implementation = 0;
@ -46,7 +46,7 @@ dawnSwapChain ErrorDeviceCreateSwapChain(dawnDevice device, const dawnSwapChainD
} }
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
dawnProcTable procs = dawn_native::GetProcs(); DawnProcTable procs = dawn_native::GetProcs();
// Swapchains receive a pointer to an implementation. The fuzzer will pass garbage in so we // Swapchains receive a pointer to an implementation. The fuzzer will pass garbage in so we
// intercept calls to create swapchains and make sure they always return error swapchains. // intercept calls to create swapchains and make sure they always return error swapchains.

View File

@ -18,8 +18,8 @@
#include <dawn/dawn.h> #include <dawn/dawn.h>
// Error message (or nullptr if there was no error) // Error message (or nullptr if there was no error)
typedef const char* dawnSwapChainError; typedef const char* DawnSwapChainError;
constexpr dawnSwapChainError DAWN_SWAP_CHAIN_NO_ERROR = nullptr; constexpr DawnSwapChainError DAWN_SWAP_CHAIN_NO_ERROR = nullptr;
typedef struct { typedef struct {
/// Backend-specific texture id/name/pointer /// Backend-specific texture id/name/pointer
@ -28,40 +28,40 @@ typedef struct {
uint64_t u64; uint64_t u64;
uint32_t u32; uint32_t u32;
} texture; } texture;
} dawnSwapChainNextTexture; } DawnSwapChainNextTexture;
typedef struct { typedef struct {
/// Initialize the swap chain implementation. /// Initialize the swap chain implementation.
/// (*wsiContext) is one of dawnWSIContext{D3D12,Metal,GL} /// (*wsiContext) is one of DawnWSIContext{D3D12,Metal,GL}
void (*Init)(void* userData, void* wsiContext); void (*Init)(void* userData, void* wsiContext);
/// Destroy the swap chain implementation. /// Destroy the swap chain implementation.
void (*Destroy)(void* userData); void (*Destroy)(void* userData);
/// Configure/reconfigure the swap chain. /// Configure/reconfigure the swap chain.
dawnSwapChainError (*Configure)(void* userData, DawnSwapChainError (*Configure)(void* userData,
dawnTextureFormat format, DawnTextureFormat format,
dawnTextureUsageBit allowedUsage, DawnTextureUsageBit allowedUsage,
uint32_t width, uint32_t width,
uint32_t height); uint32_t height);
/// Acquire the next texture from the swap chain. /// Acquire the next texture from the swap chain.
dawnSwapChainError (*GetNextTexture)(void* userData, dawnSwapChainNextTexture* nextTexture); DawnSwapChainError (*GetNextTexture)(void* userData, DawnSwapChainNextTexture* nextTexture);
/// Present the last acquired texture to the screen. /// Present the last acquired texture to the screen.
dawnSwapChainError (*Present)(void* userData); DawnSwapChainError (*Present)(void* userData);
/// Each function is called with userData as its first argument. /// Each function is called with userData as its first argument.
void* userData; void* userData;
/// For use by the D3D12 and Vulkan backends: how the swapchain will use the texture. /// For use by the D3D12 and Vulkan backends: how the swapchain will use the texture.
dawnTextureUsageBit textureUsage; DawnTextureUsageBit textureUsage;
} dawnSwapChainImplementation; } DawnSwapChainImplementation;
#if defined(DAWN_ENABLE_BACKEND_D3D12) && defined(__cplusplus) #if defined(DAWN_ENABLE_BACKEND_D3D12) && defined(__cplusplus)
typedef struct { typedef struct {
dawnDevice device = nullptr; DawnDevice device = nullptr;
} dawnWSIContextD3D12; } DawnWSIContextD3D12;
#endif #endif
#if defined(DAWN_ENABLE_BACKEND_METAL) && defined(__OBJC__) #if defined(DAWN_ENABLE_BACKEND_METAL) && defined(__OBJC__)
@ -69,17 +69,17 @@ typedef struct {
typedef struct { typedef struct {
id<MTLDevice> device = nil; id<MTLDevice> device = nil;
} dawnWSIContextMetal; } DawnWSIContextMetal;
#endif #endif
#ifdef DAWN_ENABLE_BACKEND_OPENGL #ifdef DAWN_ENABLE_BACKEND_OPENGL
typedef struct { typedef struct {
} dawnWSIContextGL; } DawnWSIContextGL;
#endif #endif
#ifdef DAWN_ENABLE_BACKEND_VULKAN #ifdef DAWN_ENABLE_BACKEND_VULKAN
typedef struct { typedef struct {
} dawnWSIContextVulkan; } DawnWSIContextVulkan;
#endif #endif
#endif // DAWN_DAWN_WSI_H #endif // DAWN_DAWN_WSI_H

View File

@ -21,10 +21,10 @@
#include <windows.h> #include <windows.h>
namespace dawn_native { namespace d3d12 { namespace dawn_native { namespace d3d12 {
DAWN_NATIVE_EXPORT dawnSwapChainImplementation CreateNativeSwapChainImpl(dawnDevice device, DAWN_NATIVE_EXPORT DawnSwapChainImplementation CreateNativeSwapChainImpl(DawnDevice device,
HWND window); HWND window);
DAWN_NATIVE_EXPORT dawnTextureFormat DAWN_NATIVE_EXPORT DawnTextureFormat
GetNativeSwapChainPreferredFormat(const dawnSwapChainImplementation* swapChain); GetNativeSwapChainPreferredFormat(const DawnSwapChainImplementation* swapChain);
}} // namespace dawn_native::d3d12 }} // namespace dawn_native::d3d12
#endif // DAWNNATIVE_D3D12BACKEND_H_ #endif // DAWNNATIVE_D3D12BACKEND_H_

View File

@ -60,7 +60,7 @@ namespace dawn_native {
// Create a device on this adapter, note that the interface will change to include at least // Create a device on this adapter, note that the interface will change to include at least
// a device descriptor and a pointer to backend specific options. // a device descriptor and a pointer to backend specific options.
// On an error, nullptr is returned. // On an error, nullptr is returned.
dawnDevice CreateDevice(); DawnDevice CreateDevice();
private: private:
AdapterBase* mImpl = nullptr; AdapterBase* mImpl = nullptr;
@ -104,7 +104,7 @@ namespace dawn_native {
}; };
// Backend-agnostic API for dawn_native // Backend-agnostic API for dawn_native
DAWN_NATIVE_EXPORT dawnProcTable GetProcs(); DAWN_NATIVE_EXPORT DawnProcTable GetProcs();
} // namespace dawn_native } // namespace dawn_native

View File

@ -33,15 +33,15 @@ typedef __IOSurface* IOSurfaceRef;
#endif //__OBJC__ #endif //__OBJC__
namespace dawn_native { namespace metal { namespace dawn_native { namespace metal {
DAWN_NATIVE_EXPORT dawnTexture WrapIOSurface(dawnDevice device, DAWN_NATIVE_EXPORT DawnTexture WrapIOSurface(DawnDevice device,
const dawnTextureDescriptor* descriptor, const DawnTextureDescriptor* descriptor,
IOSurfaceRef ioSurface, IOSurfaceRef ioSurface,
uint32_t plane); uint32_t plane);
}} // namespace dawn_native::metal }} // namespace dawn_native::metal
#ifdef __OBJC__ #ifdef __OBJC__
namespace dawn_native { namespace metal { namespace dawn_native { namespace metal {
DAWN_NATIVE_EXPORT id<MTLDevice> GetMetalDevice(dawnDevice device); DAWN_NATIVE_EXPORT id<MTLDevice> GetMetalDevice(DawnDevice device);
}} // namespace dawn_native::metal }} // namespace dawn_native::metal
#endif // __OBJC__ #endif // __OBJC__

View File

@ -19,7 +19,7 @@
#include <dawn_native/DawnNative.h> #include <dawn_native/DawnNative.h>
namespace dawn_native { namespace null { namespace dawn_native { namespace null {
DAWN_NATIVE_EXPORT dawnSwapChainImplementation CreateNativeSwapChainImpl(); DAWN_NATIVE_EXPORT DawnSwapChainImplementation CreateNativeSwapChainImpl();
}} // namespace dawn_native::null }} // namespace dawn_native::null
#endif // DAWNNATIVE_NULLBACKEND_H_ #endif // DAWNNATIVE_NULLBACKEND_H_

View File

@ -23,12 +23,12 @@
#include <vector> #include <vector>
namespace dawn_native { namespace vulkan { namespace dawn_native { namespace vulkan {
DAWN_NATIVE_EXPORT VkInstance GetInstance(dawnDevice device); DAWN_NATIVE_EXPORT VkInstance GetInstance(DawnDevice device);
DAWN_NATIVE_EXPORT dawnSwapChainImplementation CreateNativeSwapChainImpl(dawnDevice device, DAWN_NATIVE_EXPORT DawnSwapChainImplementation CreateNativeSwapChainImpl(DawnDevice device,
VkSurfaceKHR surface); VkSurfaceKHR surface);
DAWN_NATIVE_EXPORT dawnTextureFormat DAWN_NATIVE_EXPORT DawnTextureFormat
GetNativeSwapChainPreferredFormat(const dawnSwapChainImplementation* swapChain); GetNativeSwapChainPreferredFormat(const DawnSwapChainImplementation* swapChain);
}} // namespace dawn_native::vulkan }} // namespace dawn_native::vulkan
#endif // DAWNNATIVE_VULKANBACKEND_H_ #endif // DAWNNATIVE_VULKANBACKEND_H_

View File

@ -30,8 +30,8 @@ namespace dawn_wire {
WireClient(CommandSerializer* serializer); WireClient(CommandSerializer* serializer);
~WireClient(); ~WireClient();
dawnDevice GetDevice() const; DawnDevice GetDevice() const;
dawnProcTable GetProcs() const; DawnProcTable GetProcs() const;
const char* HandleCommands(const char* commands, size_t size) override final; const char* HandleCommands(const char* commands, size_t size) override final;
private: private:

View File

@ -27,7 +27,7 @@ namespace dawn_wire {
class DAWN_WIRE_EXPORT WireServer : public CommandHandler { class DAWN_WIRE_EXPORT WireServer : public CommandHandler {
public: public:
WireServer(dawnDevice device, const dawnProcTable& procs, CommandSerializer* serializer); WireServer(DawnDevice device, const DawnProcTable& procs, CommandSerializer* serializer);
~WireServer(); ~WireServer();
const char* HandleCommands(const char* commands, size_t size) override final; const char* HandleCommands(const char* commands, size_t size) override final;

View File

@ -262,8 +262,8 @@ void DawnTest::SetUp() {
} }
mPCIInfo = backendAdapter.GetPCIInfo(); mPCIInfo = backendAdapter.GetPCIInfo();
dawnDevice backendDevice = backendAdapter.CreateDevice(); DawnDevice backendDevice = backendAdapter.CreateDevice();
dawnProcTable backendProcs = dawn_native::GetProcs(); DawnProcTable backendProcs = dawn_native::GetProcs();
// Get the test window and create the device using it (esp. for OpenGL) // Get the test window and create the device using it (esp. for OpenGL)
GLFWwindow* testWindow = gTestEnv->GetWindowForBackend(GetParam()); GLFWwindow* testWindow = gTestEnv->GetWindowForBackend(GetParam());
@ -272,8 +272,8 @@ void DawnTest::SetUp() {
DAWN_ASSERT(mBinding != nullptr); DAWN_ASSERT(mBinding != nullptr);
// Choose whether to use the backend procs and devices directly, or set up the wire. // Choose whether to use the backend procs and devices directly, or set up the wire.
dawnDevice cDevice = nullptr; DawnDevice cDevice = nullptr;
dawnProcTable procs; DawnProcTable procs;
if (gTestEnv->UseWire()) { if (gTestEnv->UseWire()) {
mC2sBuf = std::make_unique<utils::TerribleCommandBuffer>(); mC2sBuf = std::make_unique<utils::TerribleCommandBuffer>();
@ -283,8 +283,8 @@ void DawnTest::SetUp() {
mC2sBuf->SetHandler(mWireServer.get()); mC2sBuf->SetHandler(mWireServer.get());
mWireClient.reset(new dawn_wire::WireClient(mC2sBuf.get())); mWireClient.reset(new dawn_wire::WireClient(mC2sBuf.get()));
dawnDevice clientDevice = mWireClient->GetDevice(); DawnDevice clientDevice = mWireClient->GetDevice();
dawnProcTable clientProcs = mWireClient->GetProcs(); DawnProcTable clientProcs = mWireClient->GetProcs();
mS2cBuf->SetHandler(mWireClient.get()); mS2cBuf->SetHandler(mWireClient.get());
procs = clientProcs; procs = clientProcs;
@ -310,7 +310,7 @@ void DawnTest::SetUp() {
dawn::TextureUsageBit::OutputAttachment, 400, 400); dawn::TextureUsageBit::OutputAttachment, 400, 400);
device.SetErrorCallback(OnDeviceError, device.SetErrorCallback(OnDeviceError,
static_cast<dawnCallbackUserdata>(reinterpret_cast<uintptr_t>(this))); static_cast<DawnCallbackUserdata>(reinterpret_cast<uintptr_t>(this)));
} }
void DawnTest::TearDown() { void DawnTest::TearDown() {
@ -334,7 +334,7 @@ bool DawnTest::EndExpectDeviceError() {
} }
// static // static
void DawnTest::OnDeviceError(const char* message, dawnCallbackUserdata userdata) { void DawnTest::OnDeviceError(const char* message, DawnCallbackUserdata userdata) {
DawnTest* self = reinterpret_cast<DawnTest*>(static_cast<uintptr_t>(userdata)); DawnTest* self = reinterpret_cast<DawnTest*>(static_cast<uintptr_t>(userdata));
ASSERT_TRUE(self->mExpectError) << "Got unexpected device error: " << message; ASSERT_TRUE(self->mExpectError) << "Got unexpected device error: " << message;
@ -481,10 +481,10 @@ void DawnTest::MapSlotsSynchronously() {
} }
// static // static
void DawnTest::SlotMapReadCallback(dawnBufferMapAsyncStatus status, void DawnTest::SlotMapReadCallback(DawnBufferMapAsyncStatus status,
const void* data, const void* data,
uint32_t, uint32_t,
dawnCallbackUserdata userdata_) { DawnCallbackUserdata userdata_) {
DAWN_ASSERT(status == DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS); DAWN_ASSERT(status == DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS);
auto userdata = reinterpret_cast<MapReadUserdata*>(static_cast<uintptr_t>(userdata_)); auto userdata = reinterpret_cast<MapReadUserdata*>(static_cast<uintptr_t>(userdata_));

View File

@ -171,7 +171,7 @@ class DawnTest : public ::testing::TestWithParam<dawn_native::BackendType> {
void FlushWire(); void FlushWire();
// Tracking for validation errors // Tracking for validation errors
static void OnDeviceError(const char* message, dawnCallbackUserdata userdata); static void OnDeviceError(const char* message, DawnCallbackUserdata userdata);
bool mExpectError = false; bool mExpectError = false;
bool mError = false; bool mError = false;
@ -185,10 +185,10 @@ class DawnTest : public ::testing::TestWithParam<dawn_native::BackendType> {
// Maps all the buffers and fill ReadbackSlot::mappedData // Maps all the buffers and fill ReadbackSlot::mappedData
void MapSlotsSynchronously(); void MapSlotsSynchronously();
static void SlotMapReadCallback(dawnBufferMapAsyncStatus status, static void SlotMapReadCallback(DawnBufferMapAsyncStatus status,
const void* data, const void* data,
uint32_t dataLength, uint32_t dataLength,
dawnCallbackUserdata userdata); DawnCallbackUserdata userdata);
size_t mNumPendingMapOperations = 0; size_t mNumPendingMapOperations = 0;
// Reserve space where the data for an expectation can be copied // Reserve space where the data for an expectation can be copied

View File

@ -18,10 +18,10 @@
class BufferMapReadTests : public DawnTest { class BufferMapReadTests : public DawnTest {
protected: protected:
static void MapReadCallback(dawnBufferMapAsyncStatus status, static void MapReadCallback(DawnBufferMapAsyncStatus status,
const void* data, const void* data,
uint32_t, uint32_t,
dawnCallbackUserdata userdata) { DawnCallbackUserdata userdata) {
ASSERT_EQ(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, status); ASSERT_EQ(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, status);
ASSERT_NE(nullptr, data); ASSERT_NE(nullptr, data);
@ -85,10 +85,10 @@ DAWN_INSTANTIATE_TEST(BufferMapReadTests, D3D12Backend, MetalBackend, OpenGLBack
class BufferMapWriteTests : public DawnTest { class BufferMapWriteTests : public DawnTest {
protected: protected:
static void MapWriteCallback(dawnBufferMapAsyncStatus status, static void MapWriteCallback(DawnBufferMapAsyncStatus status,
void* data, void* data,
uint32_t, uint32_t,
dawnCallbackUserdata userdata) { DawnCallbackUserdata userdata) {
ASSERT_EQ(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, status); ASSERT_EQ(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, status);
ASSERT_NE(nullptr, data); ASSERT_NE(nullptr, data);

View File

@ -20,12 +20,12 @@
class MockFenceOnCompletionCallback { class MockFenceOnCompletionCallback {
public: public:
MOCK_METHOD2(Call, void(dawnFenceCompletionStatus status, dawnCallbackUserdata userdata)); MOCK_METHOD2(Call, void(DawnFenceCompletionStatus status, DawnCallbackUserdata userdata));
}; };
static std::unique_ptr<MockFenceOnCompletionCallback> mockFenceOnCompletionCallback; static std::unique_ptr<MockFenceOnCompletionCallback> mockFenceOnCompletionCallback;
static void ToMockFenceOnCompletionCallback(dawnFenceCompletionStatus status, static void ToMockFenceOnCompletionCallback(DawnFenceCompletionStatus status,
dawnCallbackUserdata userdata) { DawnCallbackUserdata userdata) {
mockFenceOnCompletionCallback->Call(status, userdata); mockFenceOnCompletionCallback->Call(status, userdata);
} }
class FenceTests : public DawnTest { class FenceTests : public DawnTest {
@ -33,10 +33,10 @@ class FenceTests : public DawnTest {
struct CallbackInfo { struct CallbackInfo {
FenceTests* test; FenceTests* test;
uint64_t value; uint64_t value;
dawnFenceCompletionStatus status; DawnFenceCompletionStatus status;
int32_t callIndex = -1; // If this is -1, the callback was not called int32_t callIndex = -1; // If this is -1, the callback was not called
void Update(dawnFenceCompletionStatus status) { void Update(DawnFenceCompletionStatus status) {
this->callIndex = test->mCallIndex++; this->callIndex = test->mCallIndex++;
this->status = status; this->status = status;
} }
@ -89,10 +89,10 @@ TEST_P(FenceTests, OnCompletionOrdering) {
queue.Signal(fence, 4); queue.Signal(fence, 4);
dawnCallbackUserdata userdata0 = 1282; DawnCallbackUserdata userdata0 = 1282;
dawnCallbackUserdata userdata1 = 4382; DawnCallbackUserdata userdata1 = 4382;
dawnCallbackUserdata userdata2 = 1211; DawnCallbackUserdata userdata2 = 1211;
dawnCallbackUserdata userdata3 = 1882; DawnCallbackUserdata userdata3 = 1882;
{ {
testing::InSequence s; testing::InSequence s;
@ -131,7 +131,7 @@ TEST_P(FenceTests, MultipleSignalOnCompletion) {
queue.Signal(fence, 2); queue.Signal(fence, 2);
queue.Signal(fence, 4); queue.Signal(fence, 4);
dawnCallbackUserdata userdata = 1234; DawnCallbackUserdata userdata = 1234;
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, userdata)) Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, userdata))
.Times(1); .Times(1);
@ -148,10 +148,10 @@ TEST_P(FenceTests, OnCompletionMultipleCallbacks) {
queue.Signal(fence, 4); queue.Signal(fence, 4);
dawnCallbackUserdata userdata0 = 2341; DawnCallbackUserdata userdata0 = 2341;
dawnCallbackUserdata userdata1 = 4598; DawnCallbackUserdata userdata1 = 4598;
dawnCallbackUserdata userdata2 = 5690; DawnCallbackUserdata userdata2 = 5690;
dawnCallbackUserdata userdata3 = 2783; DawnCallbackUserdata userdata3 = 2783;
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, userdata0)) Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, userdata0))
@ -192,10 +192,10 @@ TEST_P(FenceTests, DISABLED_DestroyBeforeOnCompletionEnd) {
queue.Signal(testFence, 4); queue.Signal(testFence, 4);
dawnCallbackUserdata userdata0 = 1341; DawnCallbackUserdata userdata0 = 1341;
dawnCallbackUserdata userdata1 = 1598; DawnCallbackUserdata userdata1 = 1598;
dawnCallbackUserdata userdata2 = 1690; DawnCallbackUserdata userdata2 = 1690;
dawnCallbackUserdata userdata3 = 1783; DawnCallbackUserdata userdata3 = 1783;
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_UNKNOWN, userdata0)) Call(DAWN_FENCE_COMPLETION_STATUS_UNKNOWN, userdata0))

View File

@ -96,8 +96,8 @@ namespace {
dawn::Texture WrapIOSurface(const dawn::TextureDescriptor* descriptor, dawn::Texture WrapIOSurface(const dawn::TextureDescriptor* descriptor,
IOSurfaceRef ioSurface, IOSurfaceRef ioSurface,
uint32_t plane) { uint32_t plane) {
dawnTexture texture = dawn_native::metal::WrapIOSurface( DawnTexture texture = dawn_native::metal::WrapIOSurface(
device.Get(), reinterpret_cast<const dawnTextureDescriptor*>(descriptor), ioSurface, device.Get(), reinterpret_cast<const DawnTextureDescriptor*>(descriptor), ioSurface,
plane); plane);
return dawn::Texture::Acquire(texture); return dawn::Texture::Acquire(texture);
} }

View File

@ -23,17 +23,17 @@ using namespace testing;
class MockBufferMapReadCallback { class MockBufferMapReadCallback {
public: public:
MOCK_METHOD4(Call, MOCK_METHOD4(Call,
void(dawnBufferMapAsyncStatus status, void(DawnBufferMapAsyncStatus status,
const uint32_t* ptr, const uint32_t* ptr,
uint32_t dataLength, uint32_t dataLength,
dawnCallbackUserdata userdata)); DawnCallbackUserdata userdata));
}; };
static std::unique_ptr<MockBufferMapReadCallback> mockBufferMapReadCallback; static std::unique_ptr<MockBufferMapReadCallback> mockBufferMapReadCallback;
static void ToMockBufferMapReadCallback(dawnBufferMapAsyncStatus status, static void ToMockBufferMapReadCallback(DawnBufferMapAsyncStatus status,
const void* ptr, const void* ptr,
uint32_t dataLength, uint32_t dataLength,
dawnCallbackUserdata userdata) { DawnCallbackUserdata userdata) {
// Assume the data is uint32_t to make writing matchers easier // Assume the data is uint32_t to make writing matchers easier
mockBufferMapReadCallback->Call(status, reinterpret_cast<const uint32_t*>(ptr), dataLength, mockBufferMapReadCallback->Call(status, reinterpret_cast<const uint32_t*>(ptr), dataLength,
userdata); userdata);
@ -42,17 +42,17 @@ static void ToMockBufferMapReadCallback(dawnBufferMapAsyncStatus status,
class MockBufferMapWriteCallback { class MockBufferMapWriteCallback {
public: public:
MOCK_METHOD4(Call, MOCK_METHOD4(Call,
void(dawnBufferMapAsyncStatus status, void(DawnBufferMapAsyncStatus status,
uint32_t* ptr, uint32_t* ptr,
uint32_t dataLength, uint32_t dataLength,
dawnCallbackUserdata userdata)); DawnCallbackUserdata userdata));
}; };
static std::unique_ptr<MockBufferMapWriteCallback> mockBufferMapWriteCallback; static std::unique_ptr<MockBufferMapWriteCallback> mockBufferMapWriteCallback;
static void ToMockBufferMapWriteCallback(dawnBufferMapAsyncStatus status, static void ToMockBufferMapWriteCallback(DawnBufferMapAsyncStatus status,
void* ptr, void* ptr,
uint32_t dataLength, uint32_t dataLength,
dawnCallbackUserdata userdata) { DawnCallbackUserdata userdata) {
// Assume the data is uint32_t to make writing matchers easier // Assume the data is uint32_t to make writing matchers easier
mockBufferMapWriteCallback->Call(status, reinterpret_cast<uint32_t*>(ptr), dataLength, mockBufferMapWriteCallback->Call(status, reinterpret_cast<uint32_t*>(ptr), dataLength,
userdata); userdata);

View File

@ -20,30 +20,30 @@ using namespace testing;
class MockFenceOnCompletionCallback { class MockFenceOnCompletionCallback {
public: public:
MOCK_METHOD2(Call, void(dawnFenceCompletionStatus status, dawnCallbackUserdata userdata)); MOCK_METHOD2(Call, void(DawnFenceCompletionStatus status, DawnCallbackUserdata userdata));
}; };
struct FenceOnCompletionExpectation { struct FenceOnCompletionExpectation {
dawn::Fence fence; dawn::Fence fence;
uint64_t value; uint64_t value;
dawnFenceCompletionStatus status; DawnFenceCompletionStatus status;
}; };
static std::unique_ptr<MockFenceOnCompletionCallback> mockFenceOnCompletionCallback; static std::unique_ptr<MockFenceOnCompletionCallback> mockFenceOnCompletionCallback;
static void ToMockFenceOnCompletionCallback(dawnFenceCompletionStatus status, static void ToMockFenceOnCompletionCallback(DawnFenceCompletionStatus status,
dawnCallbackUserdata userdata) { DawnCallbackUserdata userdata) {
mockFenceOnCompletionCallback->Call(status, userdata); mockFenceOnCompletionCallback->Call(status, userdata);
} }
class FenceValidationTest : public ValidationTest { class FenceValidationTest : public ValidationTest {
protected: protected:
void TestOnCompletion(dawn::Fence fence, uint64_t value, dawnFenceCompletionStatus status) { void TestOnCompletion(dawn::Fence fence, uint64_t value, DawnFenceCompletionStatus status) {
FenceOnCompletionExpectation* expectation = new FenceOnCompletionExpectation; FenceOnCompletionExpectation* expectation = new FenceOnCompletionExpectation;
expectation->fence = fence; expectation->fence = fence;
expectation->value = value; expectation->value = value;
expectation->status = status; expectation->status = status;
dawnCallbackUserdata userdata = DawnCallbackUserdata userdata =
static_cast<dawnCallbackUserdata>(reinterpret_cast<uintptr_t>(expectation)); static_cast<DawnCallbackUserdata>(reinterpret_cast<uintptr_t>(expectation));
EXPECT_CALL(*mockFenceOnCompletionCallback, Call(status, userdata)).Times(1); EXPECT_CALL(*mockFenceOnCompletionCallback, Call(status, userdata)).Times(1);
fence.OnCompletion(value, ToMockFenceOnCompletionCallback, userdata); fence.OnCompletion(value, ToMockFenceOnCompletionCallback, userdata);
@ -135,7 +135,7 @@ TEST_F(FenceValidationTest, GetCompletedValueInsideCallback) {
queue.Signal(fence, 3); queue.Signal(fence, 3);
fence.OnCompletion(2u, ToMockFenceOnCompletionCallback, 0); fence.OnCompletion(2u, ToMockFenceOnCompletionCallback, 0);
EXPECT_CALL(*mockFenceOnCompletionCallback, Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, 0)) EXPECT_CALL(*mockFenceOnCompletionCallback, Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, 0))
.WillOnce(Invoke([&](dawnFenceCompletionStatus status, dawnCallbackUserdata userdata) { .WillOnce(Invoke([&](DawnFenceCompletionStatus status, DawnCallbackUserdata userdata) {
EXPECT_EQ(fence.GetCompletedValue(), 3u); EXPECT_EQ(fence.GetCompletedValue(), 3u);
})); }));

View File

@ -21,10 +21,10 @@ namespace {
class QueueSubmitValidationTest : public ValidationTest { class QueueSubmitValidationTest : public ValidationTest {
}; };
static void StoreTrueMapWriteCallback(dawnBufferMapAsyncStatus status, static void StoreTrueMapWriteCallback(DawnBufferMapAsyncStatus status,
void*, void*,
uint32_t, uint32_t,
dawnCallbackUserdata userdata) { DawnCallbackUserdata userdata) {
bool* userdataPtr = reinterpret_cast<bool*>(static_cast<intptr_t>(userdata)); bool* userdataPtr = reinterpret_cast<bool*>(static_cast<intptr_t>(userdata));
*userdataPtr = true; *userdataPtr = true;
} }
@ -56,7 +56,7 @@ TEST_F(QueueSubmitValidationTest, SubmitWithMappedBuffer) {
// Map the buffer, submitting when the buffer is mapped should fail // Map the buffer, submitting when the buffer is mapped should fail
bool mapWriteFinished = false; bool mapWriteFinished = false;
dawnCallbackUserdata userdata = static_cast<dawnCallbackUserdata>(reinterpret_cast<intptr_t>(&mapWriteFinished)); DawnCallbackUserdata userdata = static_cast<DawnCallbackUserdata>(reinterpret_cast<intptr_t>(&mapWriteFinished));
buffer.MapWriteAsync(StoreTrueMapWriteCallback, userdata); buffer.MapWriteAsync(StoreTrueMapWriteCallback, userdata);
queue.Submit(0, nullptr); queue.Submit(0, nullptr);
ASSERT_TRUE(mapWriteFinished); ASSERT_TRUE(mapWriteFinished);

View File

@ -39,10 +39,10 @@ ValidationTest::ValidationTest() {
ASSERT(foundNullAdapter); ASSERT(foundNullAdapter);
device = dawn::Device::Acquire(nullAdapter.CreateDevice()); device = dawn::Device::Acquire(nullAdapter.CreateDevice());
dawnProcTable procs = dawn_native::GetProcs(); DawnProcTable procs = dawn_native::GetProcs();
dawnSetProcs(&procs); dawnSetProcs(&procs);
device.SetErrorCallback(ValidationTest::OnDeviceError, static_cast<dawnCallbackUserdata>(reinterpret_cast<uintptr_t>(this))); device.SetErrorCallback(ValidationTest::OnDeviceError, static_cast<DawnCallbackUserdata>(reinterpret_cast<uintptr_t>(this)));
} }
ValidationTest::~ValidationTest() { ValidationTest::~ValidationTest() {
@ -85,7 +85,7 @@ std::string ValidationTest::GetLastDeviceErrorMessage() const {
} }
// static // static
void ValidationTest::OnDeviceError(const char* message, dawnCallbackUserdata userdata) { void ValidationTest::OnDeviceError(const char* message, DawnCallbackUserdata userdata) {
auto self = reinterpret_cast<ValidationTest*>(static_cast<uintptr_t>(userdata)); auto self = reinterpret_cast<ValidationTest*>(static_cast<uintptr_t>(userdata));
self->mDeviceErrorMessage = message; self->mDeviceErrorMessage = message;
@ -102,7 +102,7 @@ void ValidationTest::OnDeviceError(const char* message, dawnCallbackUserdata use
} }
// static // static
void ValidationTest::OnBuilderErrorStatus(dawnBuilderErrorStatus status, const char* message, dawn::CallbackUserdata userdata1, dawn::CallbackUserdata userdata2) { void ValidationTest::OnBuilderErrorStatus(DawnBuilderErrorStatus status, const char* message, dawn::CallbackUserdata userdata1, dawn::CallbackUserdata userdata2) {
auto* self = reinterpret_cast<ValidationTest*>(static_cast<uintptr_t>(userdata1)); auto* self = reinterpret_cast<ValidationTest*>(static_cast<uintptr_t>(userdata1));
size_t index = static_cast<size_t>(userdata2); size_t index = static_cast<size_t>(userdata2);

View File

@ -74,7 +74,7 @@ class ValidationTest : public testing::Test {
private: private:
std::unique_ptr<dawn_native::Instance> mInstance; std::unique_ptr<dawn_native::Instance> mInstance;
static void OnDeviceError(const char* message, dawnCallbackUserdata userdata); static void OnDeviceError(const char* message, DawnCallbackUserdata userdata);
std::string mDeviceErrorMessage; std::string mDeviceErrorMessage;
bool mExpectError = false; bool mExpectError = false;
bool mError = false; bool mError = false;
@ -85,14 +85,14 @@ class ValidationTest : public testing::Test {
bool gotStatus = false; bool gotStatus = false;
std::string statusMessage; std::string statusMessage;
dawnBuilderErrorStatus status; DawnBuilderErrorStatus status;
}; };
std::vector<BuilderStatusExpectations> mExpectations; std::vector<BuilderStatusExpectations> mExpectations;
template<typename Builder> template<typename Builder>
Builder AddExpectation(Builder& builder, std::string debugName, bool expectSuccess); Builder AddExpectation(Builder& builder, std::string debugName, bool expectSuccess);
static void OnBuilderErrorStatus(dawnBuilderErrorStatus status, const char* message, dawn::CallbackUserdata userdata1, dawn::CallbackUserdata userdata2); static void OnBuilderErrorStatus(DawnBuilderErrorStatus status, const char* message, dawn::CallbackUserdata userdata1, dawn::CallbackUserdata userdata2);
}; };
// Template implementation details // Template implementation details

View File

@ -28,14 +28,14 @@ class WireArgumentTests : public WireTest {
// Test that the wire is able to send numerical values // Test that the wire is able to send numerical values
TEST_F(WireArgumentTests, ValueArgument) { TEST_F(WireArgumentTests, ValueArgument) {
dawnCommandEncoder encoder = dawnDeviceCreateCommandEncoder(device); DawnCommandEncoder encoder = dawnDeviceCreateCommandEncoder(device);
dawnComputePassEncoder pass = dawnCommandEncoderBeginComputePass(encoder); DawnComputePassEncoder pass = dawnCommandEncoderBeginComputePass(encoder);
dawnComputePassEncoderDispatch(pass, 1, 2, 3); dawnComputePassEncoderDispatch(pass, 1, 2, 3);
dawnCommandEncoder apiEncoder = api.GetNewCommandEncoder(); DawnCommandEncoder apiEncoder = api.GetNewCommandEncoder();
EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice)).WillOnce(Return(apiEncoder)); EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice)).WillOnce(Return(apiEncoder));
dawnComputePassEncoder apiPass = api.GetNewComputePassEncoder(); DawnComputePassEncoder apiPass = api.GetNewComputePassEncoder();
EXPECT_CALL(api, CommandEncoderBeginComputePass(apiEncoder)).WillOnce(Return(apiPass)); EXPECT_CALL(api, CommandEncoderBeginComputePass(apiEncoder)).WillOnce(Return(apiPass));
EXPECT_CALL(api, ComputePassEncoderDispatch(apiPass, 1, 2, 3)).Times(1); EXPECT_CALL(api, ComputePassEncoderDispatch(apiPass, 1, 2, 3)).Times(1);
@ -58,15 +58,15 @@ bool CheckPushConstantValues(const uint32_t* values) {
} }
TEST_F(WireArgumentTests, ValueArrayArgument) { TEST_F(WireArgumentTests, ValueArrayArgument) {
dawnCommandEncoder encoder = dawnDeviceCreateCommandEncoder(device); DawnCommandEncoder encoder = dawnDeviceCreateCommandEncoder(device);
dawnComputePassEncoder pass = dawnCommandEncoderBeginComputePass(encoder); DawnComputePassEncoder pass = dawnCommandEncoderBeginComputePass(encoder);
dawnComputePassEncoderSetPushConstants(pass, DAWN_SHADER_STAGE_BIT_VERTEX, 0, 4, dawnComputePassEncoderSetPushConstants(pass, DAWN_SHADER_STAGE_BIT_VERTEX, 0, 4,
testPushConstantValues); testPushConstantValues);
dawnCommandEncoder apiEncoder = api.GetNewCommandEncoder(); DawnCommandEncoder apiEncoder = api.GetNewCommandEncoder();
EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice)).WillOnce(Return(apiEncoder)); EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice)).WillOnce(Return(apiEncoder));
dawnComputePassEncoder apiPass = api.GetNewComputePassEncoder(); DawnComputePassEncoder apiPass = api.GetNewComputePassEncoder();
EXPECT_CALL(api, CommandEncoderBeginComputePass(apiEncoder)).WillOnce(Return(apiPass)); EXPECT_CALL(api, CommandEncoderBeginComputePass(apiEncoder)).WillOnce(Return(apiPass));
EXPECT_CALL(api, EXPECT_CALL(api,
@ -81,19 +81,19 @@ TEST_F(WireArgumentTests, ValueArrayArgument) {
// Test that the wire is able to send C strings // Test that the wire is able to send C strings
TEST_F(WireArgumentTests, CStringArgument) { TEST_F(WireArgumentTests, CStringArgument) {
// Create shader module // Create shader module
dawnShaderModuleDescriptor vertexDescriptor; DawnShaderModuleDescriptor vertexDescriptor;
vertexDescriptor.nextInChain = nullptr; vertexDescriptor.nextInChain = nullptr;
vertexDescriptor.codeSize = 0; vertexDescriptor.codeSize = 0;
dawnShaderModule vsModule = dawnDeviceCreateShaderModule(device, &vertexDescriptor); DawnShaderModule vsModule = dawnDeviceCreateShaderModule(device, &vertexDescriptor);
dawnShaderModule apiVsModule = api.GetNewShaderModule(); DawnShaderModule apiVsModule = api.GetNewShaderModule();
EXPECT_CALL(api, DeviceCreateShaderModule(apiDevice, _)).WillOnce(Return(apiVsModule)); EXPECT_CALL(api, DeviceCreateShaderModule(apiDevice, _)).WillOnce(Return(apiVsModule));
// Create the color state descriptor // Create the color state descriptor
dawnBlendDescriptor blendDescriptor; DawnBlendDescriptor blendDescriptor;
blendDescriptor.operation = DAWN_BLEND_OPERATION_ADD; blendDescriptor.operation = DAWN_BLEND_OPERATION_ADD;
blendDescriptor.srcFactor = DAWN_BLEND_FACTOR_ONE; blendDescriptor.srcFactor = DAWN_BLEND_FACTOR_ONE;
blendDescriptor.dstFactor = DAWN_BLEND_FACTOR_ONE; blendDescriptor.dstFactor = DAWN_BLEND_FACTOR_ONE;
dawnColorStateDescriptor colorStateDescriptor; DawnColorStateDescriptor colorStateDescriptor;
colorStateDescriptor.nextInChain = nullptr; colorStateDescriptor.nextInChain = nullptr;
colorStateDescriptor.format = DAWN_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM; colorStateDescriptor.format = DAWN_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM;
colorStateDescriptor.alphaBlend = blendDescriptor; colorStateDescriptor.alphaBlend = blendDescriptor;
@ -101,24 +101,24 @@ TEST_F(WireArgumentTests, CStringArgument) {
colorStateDescriptor.colorWriteMask = DAWN_COLOR_WRITE_MASK_ALL; colorStateDescriptor.colorWriteMask = DAWN_COLOR_WRITE_MASK_ALL;
// Create the input state // Create the input state
dawnInputStateBuilder inputStateBuilder = dawnDeviceCreateInputStateBuilder(device); DawnInputStateBuilder inputStateBuilder = dawnDeviceCreateInputStateBuilder(device);
dawnInputStateBuilder apiInputStateBuilder = api.GetNewInputStateBuilder(); DawnInputStateBuilder apiInputStateBuilder = api.GetNewInputStateBuilder();
EXPECT_CALL(api, DeviceCreateInputStateBuilder(apiDevice)) EXPECT_CALL(api, DeviceCreateInputStateBuilder(apiDevice))
.WillOnce(Return(apiInputStateBuilder)); .WillOnce(Return(apiInputStateBuilder));
dawnInputState inputState = dawnInputStateBuilderGetResult(inputStateBuilder); DawnInputState inputState = dawnInputStateBuilderGetResult(inputStateBuilder);
dawnInputState apiInputState = api.GetNewInputState(); DawnInputState apiInputState = api.GetNewInputState();
EXPECT_CALL(api, InputStateBuilderGetResult(apiInputStateBuilder)) EXPECT_CALL(api, InputStateBuilderGetResult(apiInputStateBuilder))
.WillOnce(Return(apiInputState)); .WillOnce(Return(apiInputState));
// Create the depth-stencil state // Create the depth-stencil state
dawnStencilStateFaceDescriptor stencilFace; DawnStencilStateFaceDescriptor stencilFace;
stencilFace.compare = DAWN_COMPARE_FUNCTION_ALWAYS; stencilFace.compare = DAWN_COMPARE_FUNCTION_ALWAYS;
stencilFace.failOp = DAWN_STENCIL_OPERATION_KEEP; stencilFace.failOp = DAWN_STENCIL_OPERATION_KEEP;
stencilFace.depthFailOp = DAWN_STENCIL_OPERATION_KEEP; stencilFace.depthFailOp = DAWN_STENCIL_OPERATION_KEEP;
stencilFace.passOp = DAWN_STENCIL_OPERATION_KEEP; stencilFace.passOp = DAWN_STENCIL_OPERATION_KEEP;
dawnDepthStencilStateDescriptor depthStencilState; DawnDepthStencilStateDescriptor depthStencilState;
depthStencilState.nextInChain = nullptr; depthStencilState.nextInChain = nullptr;
depthStencilState.format = DAWN_TEXTURE_FORMAT_D32_FLOAT_S8_UINT; depthStencilState.format = DAWN_TEXTURE_FORMAT_D32_FLOAT_S8_UINT;
depthStencilState.depthWriteEnabled = false; depthStencilState.depthWriteEnabled = false;
@ -129,32 +129,32 @@ TEST_F(WireArgumentTests, CStringArgument) {
depthStencilState.stencilWriteMask = 0xff; depthStencilState.stencilWriteMask = 0xff;
// Create the pipeline layout // Create the pipeline layout
dawnPipelineLayoutDescriptor layoutDescriptor; DawnPipelineLayoutDescriptor layoutDescriptor;
layoutDescriptor.nextInChain = nullptr; layoutDescriptor.nextInChain = nullptr;
layoutDescriptor.bindGroupLayoutCount = 0; layoutDescriptor.bindGroupLayoutCount = 0;
layoutDescriptor.bindGroupLayouts = nullptr; layoutDescriptor.bindGroupLayouts = nullptr;
dawnPipelineLayout layout = dawnDeviceCreatePipelineLayout(device, &layoutDescriptor); DawnPipelineLayout layout = dawnDeviceCreatePipelineLayout(device, &layoutDescriptor);
dawnPipelineLayout apiLayout = api.GetNewPipelineLayout(); DawnPipelineLayout apiLayout = api.GetNewPipelineLayout();
EXPECT_CALL(api, DeviceCreatePipelineLayout(apiDevice, _)).WillOnce(Return(apiLayout)); EXPECT_CALL(api, DeviceCreatePipelineLayout(apiDevice, _)).WillOnce(Return(apiLayout));
// Create pipeline // Create pipeline
dawnRenderPipelineDescriptor pipelineDescriptor; DawnRenderPipelineDescriptor pipelineDescriptor;
pipelineDescriptor.nextInChain = nullptr; pipelineDescriptor.nextInChain = nullptr;
dawnPipelineStageDescriptor vertexStage; DawnPipelineStageDescriptor vertexStage;
vertexStage.nextInChain = nullptr; vertexStage.nextInChain = nullptr;
vertexStage.module = vsModule; vertexStage.module = vsModule;
vertexStage.entryPoint = "main"; vertexStage.entryPoint = "main";
pipelineDescriptor.vertexStage = &vertexStage; pipelineDescriptor.vertexStage = &vertexStage;
dawnPipelineStageDescriptor fragmentStage; DawnPipelineStageDescriptor fragmentStage;
fragmentStage.nextInChain = nullptr; fragmentStage.nextInChain = nullptr;
fragmentStage.module = vsModule; fragmentStage.module = vsModule;
fragmentStage.entryPoint = "main"; fragmentStage.entryPoint = "main";
pipelineDescriptor.fragmentStage = &fragmentStage; pipelineDescriptor.fragmentStage = &fragmentStage;
pipelineDescriptor.colorStateCount = 1; pipelineDescriptor.colorStateCount = 1;
dawnColorStateDescriptor* colorStatesPtr[] = {&colorStateDescriptor}; DawnColorStateDescriptor* colorStatesPtr[] = {&colorStateDescriptor};
pipelineDescriptor.colorStates = colorStatesPtr; pipelineDescriptor.colorStates = colorStatesPtr;
pipelineDescriptor.sampleCount = 1; pipelineDescriptor.sampleCount = 1;
@ -167,7 +167,7 @@ TEST_F(WireArgumentTests, CStringArgument) {
dawnDeviceCreateRenderPipeline(device, &pipelineDescriptor); dawnDeviceCreateRenderPipeline(device, &pipelineDescriptor);
EXPECT_CALL(api, EXPECT_CALL(api,
DeviceCreateRenderPipeline( DeviceCreateRenderPipeline(
apiDevice, MatchesLambda([](const dawnRenderPipelineDescriptor* desc) -> bool { apiDevice, MatchesLambda([](const DawnRenderPipelineDescriptor* desc) -> bool {
return desc->vertexStage->entryPoint == std::string("main"); return desc->vertexStage->entryPoint == std::string("main");
}))) })))
.WillOnce(Return(nullptr)); .WillOnce(Return(nullptr));
@ -182,18 +182,18 @@ TEST_F(WireArgumentTests, CStringArgument) {
// Test that the wire is able to send objects as value arguments // Test that the wire is able to send objects as value arguments
TEST_F(WireArgumentTests, ObjectAsValueArgument) { TEST_F(WireArgumentTests, ObjectAsValueArgument) {
dawnCommandEncoder cmdBufEncoder = dawnDeviceCreateCommandEncoder(device); DawnCommandEncoder cmdBufEncoder = dawnDeviceCreateCommandEncoder(device);
dawnCommandEncoder apiEncoder = api.GetNewCommandEncoder(); DawnCommandEncoder apiEncoder = api.GetNewCommandEncoder();
EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice)).WillOnce(Return(apiEncoder)); EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice)).WillOnce(Return(apiEncoder));
dawnBufferDescriptor descriptor; DawnBufferDescriptor descriptor;
descriptor.nextInChain = nullptr; descriptor.nextInChain = nullptr;
descriptor.size = 8; descriptor.size = 8;
descriptor.usage = static_cast<dawnBufferUsageBit>(DAWN_BUFFER_USAGE_BIT_TRANSFER_SRC | descriptor.usage = static_cast<DawnBufferUsageBit>(DAWN_BUFFER_USAGE_BIT_TRANSFER_SRC |
DAWN_BUFFER_USAGE_BIT_TRANSFER_DST); DAWN_BUFFER_USAGE_BIT_TRANSFER_DST);
dawnBuffer buffer = dawnDeviceCreateBuffer(device, &descriptor); DawnBuffer buffer = dawnDeviceCreateBuffer(device, &descriptor);
dawnBuffer apiBuffer = api.GetNewBuffer(); DawnBuffer apiBuffer = api.GetNewBuffer();
EXPECT_CALL(api, DeviceCreateBuffer(apiDevice, _)) EXPECT_CALL(api, DeviceCreateBuffer(apiDevice, _))
.WillOnce(Return(apiBuffer)) .WillOnce(Return(apiBuffer))
.RetiresOnSaturation(); .RetiresOnSaturation();
@ -209,17 +209,17 @@ TEST_F(WireArgumentTests, ObjectAsValueArgument) {
// Test that the wire is able to send array of objects // Test that the wire is able to send array of objects
TEST_F(WireArgumentTests, ObjectsAsPointerArgument) { TEST_F(WireArgumentTests, ObjectsAsPointerArgument) {
dawnCommandBuffer cmdBufs[2]; DawnCommandBuffer cmdBufs[2];
dawnCommandBuffer apiCmdBufs[2]; DawnCommandBuffer apiCmdBufs[2];
// Create two command buffers we need to use a GMock sequence otherwise the order of the // Create two command buffers we need to use a GMock sequence otherwise the order of the
// CreateCommandEncoder might be swapped since they are equivalent in term of matchers // CreateCommandEncoder might be swapped since they are equivalent in term of matchers
Sequence s; Sequence s;
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
dawnCommandEncoder cmdBufEncoder = dawnDeviceCreateCommandEncoder(device); DawnCommandEncoder cmdBufEncoder = dawnDeviceCreateCommandEncoder(device);
cmdBufs[i] = dawnCommandEncoderFinish(cmdBufEncoder); cmdBufs[i] = dawnCommandEncoderFinish(cmdBufEncoder);
dawnCommandEncoder apiCmdBufEncoder = api.GetNewCommandEncoder(); DawnCommandEncoder apiCmdBufEncoder = api.GetNewCommandEncoder();
EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice)) EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice))
.InSequence(s) .InSequence(s)
.WillOnce(Return(apiCmdBufEncoder)); .WillOnce(Return(apiCmdBufEncoder));
@ -232,15 +232,15 @@ TEST_F(WireArgumentTests, ObjectsAsPointerArgument) {
} }
// Create queue // Create queue
dawnQueue queue = dawnDeviceCreateQueue(device); DawnQueue queue = dawnDeviceCreateQueue(device);
dawnQueue apiQueue = api.GetNewQueue(); DawnQueue apiQueue = api.GetNewQueue();
EXPECT_CALL(api, DeviceCreateQueue(apiDevice)).WillOnce(Return(apiQueue)); EXPECT_CALL(api, DeviceCreateQueue(apiDevice)).WillOnce(Return(apiQueue));
// Submit command buffer and check we got a call with both API-side command buffers // Submit command buffer and check we got a call with both API-side command buffers
dawnQueueSubmit(queue, 2, cmdBufs); dawnQueueSubmit(queue, 2, cmdBufs);
EXPECT_CALL( EXPECT_CALL(
api, QueueSubmit(apiQueue, 2, MatchesLambda([=](const dawnCommandBuffer* cmdBufs) -> bool { api, QueueSubmit(apiQueue, 2, MatchesLambda([=](const DawnCommandBuffer* cmdBufs) -> bool {
return cmdBufs[0] == apiCmdBufs[0] && cmdBufs[1] == apiCmdBufs[1]; return cmdBufs[0] == apiCmdBufs[0] && cmdBufs[1] == apiCmdBufs[1];
}))); })));
@ -250,7 +250,7 @@ TEST_F(WireArgumentTests, ObjectsAsPointerArgument) {
// Test that the wire is able to send structures that contain pure values (non-objects) // Test that the wire is able to send structures that contain pure values (non-objects)
TEST_F(WireArgumentTests, StructureOfValuesArgument) { TEST_F(WireArgumentTests, StructureOfValuesArgument) {
dawnSamplerDescriptor descriptor; DawnSamplerDescriptor descriptor;
descriptor.nextInChain = nullptr; descriptor.nextInChain = nullptr;
descriptor.magFilter = DAWN_FILTER_MODE_LINEAR; descriptor.magFilter = DAWN_FILTER_MODE_LINEAR;
descriptor.minFilter = DAWN_FILTER_MODE_NEAREST; descriptor.minFilter = DAWN_FILTER_MODE_NEAREST;
@ -265,7 +265,7 @@ TEST_F(WireArgumentTests, StructureOfValuesArgument) {
dawnDeviceCreateSampler(device, &descriptor); dawnDeviceCreateSampler(device, &descriptor);
EXPECT_CALL(api, DeviceCreateSampler( EXPECT_CALL(api, DeviceCreateSampler(
apiDevice, MatchesLambda([](const dawnSamplerDescriptor* desc) -> bool { apiDevice, MatchesLambda([](const DawnSamplerDescriptor* desc) -> bool {
return desc->nextInChain == nullptr && return desc->nextInChain == nullptr &&
desc->magFilter == DAWN_FILTER_MODE_LINEAR && desc->magFilter == DAWN_FILTER_MODE_LINEAR &&
desc->minFilter == DAWN_FILTER_MODE_NEAREST && desc->minFilter == DAWN_FILTER_MODE_NEAREST &&
@ -284,15 +284,15 @@ TEST_F(WireArgumentTests, StructureOfValuesArgument) {
// Test that the wire is able to send structures that contain objects // Test that the wire is able to send structures that contain objects
TEST_F(WireArgumentTests, StructureOfObjectArrayArgument) { TEST_F(WireArgumentTests, StructureOfObjectArrayArgument) {
dawnBindGroupLayoutDescriptor bglDescriptor; DawnBindGroupLayoutDescriptor bglDescriptor;
bglDescriptor.bindingCount = 0; bglDescriptor.bindingCount = 0;
bglDescriptor.bindings = nullptr; bglDescriptor.bindings = nullptr;
dawnBindGroupLayout bgl = dawnDeviceCreateBindGroupLayout(device, &bglDescriptor); DawnBindGroupLayout bgl = dawnDeviceCreateBindGroupLayout(device, &bglDescriptor);
dawnBindGroupLayout apiBgl = api.GetNewBindGroupLayout(); DawnBindGroupLayout apiBgl = api.GetNewBindGroupLayout();
EXPECT_CALL(api, DeviceCreateBindGroupLayout(apiDevice, _)).WillOnce(Return(apiBgl)); EXPECT_CALL(api, DeviceCreateBindGroupLayout(apiDevice, _)).WillOnce(Return(apiBgl));
dawnPipelineLayoutDescriptor descriptor; DawnPipelineLayoutDescriptor descriptor;
descriptor.nextInChain = nullptr; descriptor.nextInChain = nullptr;
descriptor.bindGroupLayoutCount = 1; descriptor.bindGroupLayoutCount = 1;
descriptor.bindGroupLayouts = &bgl; descriptor.bindGroupLayouts = &bgl;
@ -300,7 +300,7 @@ TEST_F(WireArgumentTests, StructureOfObjectArrayArgument) {
dawnDeviceCreatePipelineLayout(device, &descriptor); dawnDeviceCreatePipelineLayout(device, &descriptor);
EXPECT_CALL(api, DeviceCreatePipelineLayout( EXPECT_CALL(api, DeviceCreatePipelineLayout(
apiDevice, apiDevice,
MatchesLambda([apiBgl](const dawnPipelineLayoutDescriptor* desc) -> bool { MatchesLambda([apiBgl](const DawnPipelineLayoutDescriptor* desc) -> bool {
return desc->nextInChain == nullptr && return desc->nextInChain == nullptr &&
desc->bindGroupLayoutCount == 1 && desc->bindGroupLayoutCount == 1 &&
desc->bindGroupLayouts[0] == apiBgl; desc->bindGroupLayouts[0] == apiBgl;
@ -314,24 +314,24 @@ TEST_F(WireArgumentTests, StructureOfObjectArrayArgument) {
// Test that the wire is able to send structures that contain objects // Test that the wire is able to send structures that contain objects
TEST_F(WireArgumentTests, StructureOfStructureArrayArgument) { TEST_F(WireArgumentTests, StructureOfStructureArrayArgument) {
static constexpr int NUM_BINDINGS = 3; static constexpr int NUM_BINDINGS = 3;
dawnBindGroupLayoutBinding bindings[NUM_BINDINGS]{ DawnBindGroupLayoutBinding bindings[NUM_BINDINGS]{
{0, DAWN_SHADER_STAGE_BIT_VERTEX, DAWN_BINDING_TYPE_SAMPLER}, {0, DAWN_SHADER_STAGE_BIT_VERTEX, DAWN_BINDING_TYPE_SAMPLER},
{1, DAWN_SHADER_STAGE_BIT_VERTEX, DAWN_BINDING_TYPE_SAMPLED_TEXTURE}, {1, DAWN_SHADER_STAGE_BIT_VERTEX, DAWN_BINDING_TYPE_SAMPLED_TEXTURE},
{2, {2,
static_cast<dawnShaderStageBit>(DAWN_SHADER_STAGE_BIT_VERTEX | static_cast<DawnShaderStageBit>(DAWN_SHADER_STAGE_BIT_VERTEX |
DAWN_SHADER_STAGE_BIT_FRAGMENT), DAWN_SHADER_STAGE_BIT_FRAGMENT),
DAWN_BINDING_TYPE_UNIFORM_BUFFER}, DAWN_BINDING_TYPE_UNIFORM_BUFFER},
}; };
dawnBindGroupLayoutDescriptor bglDescriptor; DawnBindGroupLayoutDescriptor bglDescriptor;
bglDescriptor.bindingCount = NUM_BINDINGS; bglDescriptor.bindingCount = NUM_BINDINGS;
bglDescriptor.bindings = bindings; bglDescriptor.bindings = bindings;
dawnDeviceCreateBindGroupLayout(device, &bglDescriptor); dawnDeviceCreateBindGroupLayout(device, &bglDescriptor);
dawnBindGroupLayout apiBgl = api.GetNewBindGroupLayout(); DawnBindGroupLayout apiBgl = api.GetNewBindGroupLayout();
EXPECT_CALL( EXPECT_CALL(
api, api,
DeviceCreateBindGroupLayout( DeviceCreateBindGroupLayout(
apiDevice, MatchesLambda([bindings](const dawnBindGroupLayoutDescriptor* desc) -> bool { apiDevice, MatchesLambda([bindings](const DawnBindGroupLayoutDescriptor* desc) -> bool {
for (int i = 0; i < NUM_BINDINGS; ++i) { for (int i = 0; i < NUM_BINDINGS; ++i) {
const auto& a = desc->bindings[i]; const auto& a = desc->bindings[i];
const auto& b = bindings[i]; const auto& b = bindings[i];
@ -350,9 +350,9 @@ TEST_F(WireArgumentTests, StructureOfStructureArrayArgument) {
// Test passing nullptr instead of objects - array of objects version // Test passing nullptr instead of objects - array of objects version
TEST_F(WireArgumentTests, DISABLED_NullptrInArray) { TEST_F(WireArgumentTests, DISABLED_NullptrInArray) {
dawnBindGroupLayout nullBGL = nullptr; DawnBindGroupLayout nullBGL = nullptr;
dawnPipelineLayoutDescriptor descriptor; DawnPipelineLayoutDescriptor descriptor;
descriptor.nextInChain = nullptr; descriptor.nextInChain = nullptr;
descriptor.bindGroupLayoutCount = 1; descriptor.bindGroupLayoutCount = 1;
descriptor.bindGroupLayouts = &nullBGL; descriptor.bindGroupLayouts = &nullBGL;
@ -360,7 +360,7 @@ TEST_F(WireArgumentTests, DISABLED_NullptrInArray) {
dawnDeviceCreatePipelineLayout(device, &descriptor); dawnDeviceCreatePipelineLayout(device, &descriptor);
EXPECT_CALL(api, EXPECT_CALL(api,
DeviceCreatePipelineLayout( DeviceCreatePipelineLayout(
apiDevice, MatchesLambda([](const dawnPipelineLayoutDescriptor* desc) -> bool { apiDevice, MatchesLambda([](const DawnPipelineLayoutDescriptor* desc) -> bool {
return desc->nextInChain == nullptr && desc->bindGroupLayoutCount == 1 && return desc->nextInChain == nullptr && desc->bindGroupLayoutCount == 1 &&
desc->bindGroupLayouts[0] == nullptr; desc->bindGroupLayouts[0] == nullptr;
}))) })))

View File

@ -28,7 +28,7 @@ class WireBasicTests : public WireTest {
TEST_F(WireBasicTests, CallForwarded) { TEST_F(WireBasicTests, CallForwarded) {
dawnDeviceCreateCommandEncoder(device); dawnDeviceCreateCommandEncoder(device);
dawnCommandEncoder apiCmdBufEncoder = api.GetNewCommandEncoder(); DawnCommandEncoder apiCmdBufEncoder = api.GetNewCommandEncoder();
EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice)) EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice))
.WillOnce(Return(apiCmdBufEncoder)); .WillOnce(Return(apiCmdBufEncoder));
@ -38,14 +38,14 @@ TEST_F(WireBasicTests, CallForwarded) {
// Test that calling methods on a new object works as expected. // Test that calling methods on a new object works as expected.
TEST_F(WireBasicTests, CreateThenCall) { TEST_F(WireBasicTests, CreateThenCall) {
dawnCommandEncoder encoder = dawnDeviceCreateCommandEncoder(device); DawnCommandEncoder encoder = dawnDeviceCreateCommandEncoder(device);
dawnCommandEncoderFinish(encoder); dawnCommandEncoderFinish(encoder);
dawnCommandEncoder apiCmdBufEncoder = api.GetNewCommandEncoder(); DawnCommandEncoder apiCmdBufEncoder = api.GetNewCommandEncoder();
EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice)) EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice))
.WillOnce(Return(apiCmdBufEncoder)); .WillOnce(Return(apiCmdBufEncoder));
dawnCommandBuffer apiCmdBuf = api.GetNewCommandBuffer(); DawnCommandBuffer apiCmdBuf = api.GetNewCommandBuffer();
EXPECT_CALL(api, CommandEncoderFinish(apiCmdBufEncoder)).WillOnce(Return(apiCmdBuf)); EXPECT_CALL(api, CommandEncoderFinish(apiCmdBufEncoder)).WillOnce(Return(apiCmdBuf));
EXPECT_CALL(api, CommandEncoderRelease(apiCmdBufEncoder)); EXPECT_CALL(api, CommandEncoderRelease(apiCmdBufEncoder));
@ -55,12 +55,12 @@ TEST_F(WireBasicTests, CreateThenCall) {
// Test that client reference/release do not call the backend API. // Test that client reference/release do not call the backend API.
TEST_F(WireBasicTests, RefCountKeptInClient) { TEST_F(WireBasicTests, RefCountKeptInClient) {
dawnCommandEncoder encoder = dawnDeviceCreateCommandEncoder(device); DawnCommandEncoder encoder = dawnDeviceCreateCommandEncoder(device);
dawnCommandEncoderReference(encoder); dawnCommandEncoderReference(encoder);
dawnCommandEncoderRelease(encoder); dawnCommandEncoderRelease(encoder);
dawnCommandEncoder apiCmdBufEncoder = api.GetNewCommandEncoder(); DawnCommandEncoder apiCmdBufEncoder = api.GetNewCommandEncoder();
EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice)) EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice))
.WillOnce(Return(apiCmdBufEncoder)); .WillOnce(Return(apiCmdBufEncoder));
EXPECT_CALL(api, CommandEncoderRelease(apiCmdBufEncoder)); EXPECT_CALL(api, CommandEncoderRelease(apiCmdBufEncoder));
@ -70,11 +70,11 @@ TEST_F(WireBasicTests, RefCountKeptInClient) {
// Test that client reference/release do not call the backend API. // Test that client reference/release do not call the backend API.
TEST_F(WireBasicTests, ReleaseCalledOnRefCount0) { TEST_F(WireBasicTests, ReleaseCalledOnRefCount0) {
dawnCommandEncoder encoder = dawnDeviceCreateCommandEncoder(device); DawnCommandEncoder encoder = dawnDeviceCreateCommandEncoder(device);
dawnCommandEncoderRelease(encoder); dawnCommandEncoderRelease(encoder);
dawnCommandEncoder apiCmdBufEncoder = api.GetNewCommandEncoder(); DawnCommandEncoder apiCmdBufEncoder = api.GetNewCommandEncoder();
EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice)) EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice))
.WillOnce(Return(apiCmdBufEncoder)); .WillOnce(Return(apiCmdBufEncoder));

View File

@ -23,17 +23,17 @@ namespace {
class MockBufferMapReadCallback { class MockBufferMapReadCallback {
public: public:
MOCK_METHOD4(Call, MOCK_METHOD4(Call,
void(dawnBufferMapAsyncStatus status, void(DawnBufferMapAsyncStatus status,
const uint32_t* ptr, const uint32_t* ptr,
uint32_t dataLength, uint32_t dataLength,
dawnCallbackUserdata userdata)); DawnCallbackUserdata userdata));
}; };
std::unique_ptr<MockBufferMapReadCallback> mockBufferMapReadCallback; std::unique_ptr<MockBufferMapReadCallback> mockBufferMapReadCallback;
void ToMockBufferMapReadCallback(dawnBufferMapAsyncStatus status, void ToMockBufferMapReadCallback(DawnBufferMapAsyncStatus status,
const void* ptr, const void* ptr,
uint32_t dataLength, uint32_t dataLength,
dawnCallbackUserdata userdata) { DawnCallbackUserdata userdata) {
// Assume the data is uint32_t to make writing matchers easier // Assume the data is uint32_t to make writing matchers easier
mockBufferMapReadCallback->Call(status, static_cast<const uint32_t*>(ptr), dataLength, mockBufferMapReadCallback->Call(status, static_cast<const uint32_t*>(ptr), dataLength,
userdata); userdata);
@ -42,18 +42,18 @@ namespace {
class MockBufferMapWriteCallback { class MockBufferMapWriteCallback {
public: public:
MOCK_METHOD4(Call, MOCK_METHOD4(Call,
void(dawnBufferMapAsyncStatus status, void(DawnBufferMapAsyncStatus status,
uint32_t* ptr, uint32_t* ptr,
uint32_t dataLength, uint32_t dataLength,
dawnCallbackUserdata userdata)); DawnCallbackUserdata userdata));
}; };
std::unique_ptr<MockBufferMapWriteCallback> mockBufferMapWriteCallback; std::unique_ptr<MockBufferMapWriteCallback> mockBufferMapWriteCallback;
uint32_t* lastMapWritePointer = nullptr; uint32_t* lastMapWritePointer = nullptr;
void ToMockBufferMapWriteCallback(dawnBufferMapAsyncStatus status, void ToMockBufferMapWriteCallback(DawnBufferMapAsyncStatus status,
void* ptr, void* ptr,
uint32_t dataLength, uint32_t dataLength,
dawnCallbackUserdata userdata) { DawnCallbackUserdata userdata) {
// Assume the data is uint32_t to make writing matchers easier // Assume the data is uint32_t to make writing matchers easier
lastMapWritePointer = static_cast<uint32_t*>(ptr); lastMapWritePointer = static_cast<uint32_t*>(ptr);
mockBufferMapWriteCallback->Call(status, lastMapWritePointer, dataLength, userdata); mockBufferMapWriteCallback->Call(status, lastMapWritePointer, dataLength, userdata);
@ -74,7 +74,7 @@ class WireBufferMappingTests : public WireTest {
mockBufferMapWriteCallback = std::make_unique<MockBufferMapWriteCallback>(); mockBufferMapWriteCallback = std::make_unique<MockBufferMapWriteCallback>();
{ {
dawnBufferDescriptor descriptor; DawnBufferDescriptor descriptor;
descriptor.nextInChain = nullptr; descriptor.nextInChain = nullptr;
apiBuffer = api.GetNewBuffer(); apiBuffer = api.GetNewBuffer();
@ -87,7 +87,7 @@ class WireBufferMappingTests : public WireTest {
FlushClient(); FlushClient();
} }
{ {
dawnBufferDescriptor descriptor; DawnBufferDescriptor descriptor;
descriptor.nextInChain = nullptr; descriptor.nextInChain = nullptr;
errorBuffer = dawnDeviceCreateBuffer(device, &descriptor); errorBuffer = dawnDeviceCreateBuffer(device, &descriptor);
@ -109,18 +109,18 @@ class WireBufferMappingTests : public WireTest {
protected: protected:
// A successfully created buffer // A successfully created buffer
dawnBuffer buffer; DawnBuffer buffer;
dawnBuffer apiBuffer; DawnBuffer apiBuffer;
// An buffer that wasn't created on the server side // An buffer that wasn't created on the server side
dawnBuffer errorBuffer; DawnBuffer errorBuffer;
}; };
// MapRead-specific tests // MapRead-specific tests
// Check mapping for reading a succesfully created buffer // Check mapping for reading a succesfully created buffer
TEST_F(WireBufferMappingTests, MappingForReadSuccessBuffer) { TEST_F(WireBufferMappingTests, MappingForReadSuccessBuffer) {
dawnCallbackUserdata userdata = 8653; DawnCallbackUserdata userdata = 8653;
dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata); dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata);
uint32_t bufferContent = 31337; uint32_t bufferContent = 31337;
@ -148,7 +148,7 @@ TEST_F(WireBufferMappingTests, MappingForReadSuccessBuffer) {
// Check that things work correctly when a validation error happens when mapping the buffer for // Check that things work correctly when a validation error happens when mapping the buffer for
// reading // reading
TEST_F(WireBufferMappingTests, ErrorWhileMappingForRead) { TEST_F(WireBufferMappingTests, ErrorWhileMappingForRead) {
dawnCallbackUserdata userdata = 8654; DawnCallbackUserdata userdata = 8654;
dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata); dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata);
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _)) EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
@ -167,7 +167,7 @@ TEST_F(WireBufferMappingTests, ErrorWhileMappingForRead) {
// Check mapping for reading a buffer that didn't get created on the server side // Check mapping for reading a buffer that didn't get created on the server side
TEST_F(WireBufferMappingTests, MappingForReadErrorBuffer) { TEST_F(WireBufferMappingTests, MappingForReadErrorBuffer) {
dawnCallbackUserdata userdata = 8655; DawnCallbackUserdata userdata = 8655;
dawnBufferMapReadAsync(errorBuffer, ToMockBufferMapReadCallback, userdata); dawnBufferMapReadAsync(errorBuffer, ToMockBufferMapReadCallback, userdata);
FlushClient(); FlushClient();
@ -186,7 +186,7 @@ TEST_F(WireBufferMappingTests, MappingForReadErrorBuffer) {
// Check that the map read callback is called with UNKNOWN when the buffer is destroyed before the // Check that the map read callback is called with UNKNOWN when the buffer is destroyed before the
// request is finished // request is finished
TEST_F(WireBufferMappingTests, DestroyBeforeReadRequestEnd) { TEST_F(WireBufferMappingTests, DestroyBeforeReadRequestEnd) {
dawnCallbackUserdata userdata = 8656; DawnCallbackUserdata userdata = 8656;
dawnBufferMapReadAsync(errorBuffer, ToMockBufferMapReadCallback, userdata); dawnBufferMapReadAsync(errorBuffer, ToMockBufferMapReadCallback, userdata);
EXPECT_CALL(*mockBufferMapReadCallback, EXPECT_CALL(*mockBufferMapReadCallback,
@ -199,7 +199,7 @@ TEST_F(WireBufferMappingTests, DestroyBeforeReadRequestEnd) {
// Check the map read callback is called with UNKNOWN when the map request would have worked, but // Check the map read callback is called with UNKNOWN when the map request would have worked, but
// Unmap was called // Unmap was called
TEST_F(WireBufferMappingTests, UnmapCalledTooEarlyForRead) { TEST_F(WireBufferMappingTests, UnmapCalledTooEarlyForRead) {
dawnCallbackUserdata userdata = 8657; DawnCallbackUserdata userdata = 8657;
dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata); dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata);
uint32_t bufferContent = 31337; uint32_t bufferContent = 31337;
@ -224,7 +224,7 @@ TEST_F(WireBufferMappingTests, UnmapCalledTooEarlyForRead) {
// Check that an error map read callback gets nullptr while a buffer is already mapped // Check that an error map read callback gets nullptr while a buffer is already mapped
TEST_F(WireBufferMappingTests, MappingForReadingErrorWhileAlreadyMappedGetsNullptr) { TEST_F(WireBufferMappingTests, MappingForReadingErrorWhileAlreadyMappedGetsNullptr) {
// Successful map // Successful map
dawnCallbackUserdata userdata = 34098; DawnCallbackUserdata userdata = 34098;
dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata); dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata);
uint32_t bufferContent = 31337; uint32_t bufferContent = 31337;
@ -263,7 +263,7 @@ TEST_F(WireBufferMappingTests, MappingForReadingErrorWhileAlreadyMappedGetsNullp
// Test that the MapReadCallback isn't fired twice when unmap() is called inside the callback // Test that the MapReadCallback isn't fired twice when unmap() is called inside the callback
TEST_F(WireBufferMappingTests, UnmapInsideMapReadCallback) { TEST_F(WireBufferMappingTests, UnmapInsideMapReadCallback) {
dawnCallbackUserdata userdata = 2039; DawnCallbackUserdata userdata = 2039;
dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata); dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata);
uint32_t bufferContent = 31337; uint32_t bufferContent = 31337;
@ -290,7 +290,7 @@ TEST_F(WireBufferMappingTests, UnmapInsideMapReadCallback) {
// Test that the MapReadCallback isn't fired twice the buffer external refcount reaches 0 in the // Test that the MapReadCallback isn't fired twice the buffer external refcount reaches 0 in the
// callback // callback
TEST_F(WireBufferMappingTests, DestroyInsideMapReadCallback) { TEST_F(WireBufferMappingTests, DestroyInsideMapReadCallback) {
dawnCallbackUserdata userdata = 2039; DawnCallbackUserdata userdata = 2039;
dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata); dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata);
uint32_t bufferContent = 31337; uint32_t bufferContent = 31337;
@ -316,7 +316,7 @@ TEST_F(WireBufferMappingTests, DestroyInsideMapReadCallback) {
// Check mapping for writing a succesfully created buffer // Check mapping for writing a succesfully created buffer
TEST_F(WireBufferMappingTests, MappingForWriteSuccessBuffer) { TEST_F(WireBufferMappingTests, MappingForWriteSuccessBuffer) {
dawnCallbackUserdata userdata = 8653; DawnCallbackUserdata userdata = 8653;
dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata); dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata);
uint32_t serverBufferContent = 31337; uint32_t serverBufferContent = 31337;
@ -353,7 +353,7 @@ TEST_F(WireBufferMappingTests, MappingForWriteSuccessBuffer) {
// Check that things work correctly when a validation error happens when mapping the buffer for // Check that things work correctly when a validation error happens when mapping the buffer for
// writing // writing
TEST_F(WireBufferMappingTests, ErrorWhileMappingForWrite) { TEST_F(WireBufferMappingTests, ErrorWhileMappingForWrite) {
dawnCallbackUserdata userdata = 8654; DawnCallbackUserdata userdata = 8654;
dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata); dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata);
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _)) EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
@ -372,7 +372,7 @@ TEST_F(WireBufferMappingTests, ErrorWhileMappingForWrite) {
// Check mapping for writing a buffer that didn't get created on the server side // Check mapping for writing a buffer that didn't get created on the server side
TEST_F(WireBufferMappingTests, MappingForWriteErrorBuffer) { TEST_F(WireBufferMappingTests, MappingForWriteErrorBuffer) {
dawnCallbackUserdata userdata = 8655; DawnCallbackUserdata userdata = 8655;
dawnBufferMapWriteAsync(errorBuffer, ToMockBufferMapWriteCallback, userdata); dawnBufferMapWriteAsync(errorBuffer, ToMockBufferMapWriteCallback, userdata);
FlushClient(); FlushClient();
@ -391,7 +391,7 @@ TEST_F(WireBufferMappingTests, MappingForWriteErrorBuffer) {
// Check that the map write callback is called with UNKNOWN when the buffer is destroyed before the // Check that the map write callback is called with UNKNOWN when the buffer is destroyed before the
// request is finished // request is finished
TEST_F(WireBufferMappingTests, DestroyBeforeWriteRequestEnd) { TEST_F(WireBufferMappingTests, DestroyBeforeWriteRequestEnd) {
dawnCallbackUserdata userdata = 8656; DawnCallbackUserdata userdata = 8656;
dawnBufferMapWriteAsync(errorBuffer, ToMockBufferMapWriteCallback, userdata); dawnBufferMapWriteAsync(errorBuffer, ToMockBufferMapWriteCallback, userdata);
EXPECT_CALL(*mockBufferMapWriteCallback, EXPECT_CALL(*mockBufferMapWriteCallback,
@ -404,7 +404,7 @@ TEST_F(WireBufferMappingTests, DestroyBeforeWriteRequestEnd) {
// Check the map read callback is called with UNKNOWN when the map request would have worked, but // Check the map read callback is called with UNKNOWN when the map request would have worked, but
// Unmap was called // Unmap was called
TEST_F(WireBufferMappingTests, UnmapCalledTooEarlyForWrite) { TEST_F(WireBufferMappingTests, UnmapCalledTooEarlyForWrite) {
dawnCallbackUserdata userdata = 8657; DawnCallbackUserdata userdata = 8657;
dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata); dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata);
uint32_t bufferContent = 31337; uint32_t bufferContent = 31337;
@ -429,7 +429,7 @@ TEST_F(WireBufferMappingTests, UnmapCalledTooEarlyForWrite) {
// Check that an error map read callback gets nullptr while a buffer is already mapped // Check that an error map read callback gets nullptr while a buffer is already mapped
TEST_F(WireBufferMappingTests, MappingForWritingErrorWhileAlreadyMappedGetsNullptr) { TEST_F(WireBufferMappingTests, MappingForWritingErrorWhileAlreadyMappedGetsNullptr) {
// Successful map // Successful map
dawnCallbackUserdata userdata = 34098; DawnCallbackUserdata userdata = 34098;
dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata); dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata);
uint32_t bufferContent = 31337; uint32_t bufferContent = 31337;
@ -468,7 +468,7 @@ TEST_F(WireBufferMappingTests, MappingForWritingErrorWhileAlreadyMappedGetsNullp
// Test that the MapWriteCallback isn't fired twice when unmap() is called inside the callback // Test that the MapWriteCallback isn't fired twice when unmap() is called inside the callback
TEST_F(WireBufferMappingTests, UnmapInsideMapWriteCallback) { TEST_F(WireBufferMappingTests, UnmapInsideMapWriteCallback) {
dawnCallbackUserdata userdata = 2039; DawnCallbackUserdata userdata = 2039;
dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata); dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata);
uint32_t bufferContent = 31337; uint32_t bufferContent = 31337;
@ -495,7 +495,7 @@ TEST_F(WireBufferMappingTests, UnmapInsideMapWriteCallback) {
// Test that the MapWriteCallback isn't fired twice the buffer external refcount reaches 0 in the // Test that the MapWriteCallback isn't fired twice the buffer external refcount reaches 0 in the
// callback // callback
TEST_F(WireBufferMappingTests, DestroyInsideMapWriteCallback) { TEST_F(WireBufferMappingTests, DestroyInsideMapWriteCallback) {
dawnCallbackUserdata userdata = 2039; DawnCallbackUserdata userdata = 2039;
dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata); dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata);
uint32_t bufferContent = 31337; uint32_t bufferContent = 31337;

View File

@ -22,28 +22,28 @@ namespace {
// Mock classes to add expectations on the wire calling callbacks // Mock classes to add expectations on the wire calling callbacks
class MockDeviceErrorCallback { class MockDeviceErrorCallback {
public: public:
MOCK_METHOD2(Call, void(const char* message, dawnCallbackUserdata userdata)); MOCK_METHOD2(Call, void(const char* message, DawnCallbackUserdata userdata));
}; };
std::unique_ptr<MockDeviceErrorCallback> mockDeviceErrorCallback; std::unique_ptr<MockDeviceErrorCallback> mockDeviceErrorCallback;
void ToMockDeviceErrorCallback(const char* message, dawnCallbackUserdata userdata) { void ToMockDeviceErrorCallback(const char* message, DawnCallbackUserdata userdata) {
mockDeviceErrorCallback->Call(message, userdata); mockDeviceErrorCallback->Call(message, userdata);
} }
class MockBuilderErrorCallback { class MockBuilderErrorCallback {
public: public:
MOCK_METHOD4(Call, MOCK_METHOD4(Call,
void(dawnBuilderErrorStatus status, void(DawnBuilderErrorStatus status,
const char* message, const char* message,
dawnCallbackUserdata userdata1, DawnCallbackUserdata userdata1,
dawnCallbackUserdata userdata2)); DawnCallbackUserdata userdata2));
}; };
std::unique_ptr<MockBuilderErrorCallback> mockBuilderErrorCallback; std::unique_ptr<MockBuilderErrorCallback> mockBuilderErrorCallback;
void ToMockBuilderErrorCallback(dawnBuilderErrorStatus status, void ToMockBuilderErrorCallback(DawnBuilderErrorStatus status,
const char* message, const char* message,
dawnCallbackUserdata userdata1, DawnCallbackUserdata userdata1,
dawnCallbackUserdata userdata2) { DawnCallbackUserdata userdata2) {
mockBuilderErrorCallback->Call(status, message, userdata1, userdata2); mockBuilderErrorCallback->Call(status, message, userdata1, userdata2);
} }
@ -73,17 +73,17 @@ class WireCallbackTests : public WireTest {
// Test that we get a success builder error status when no error happens // Test that we get a success builder error status when no error happens
TEST_F(WireCallbackTests, SuccessCallbackOnBuilderSuccess) { TEST_F(WireCallbackTests, SuccessCallbackOnBuilderSuccess) {
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device); DawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
dawnBufferBuilderSetErrorCallback(bufferBuilder, ToMockBuilderErrorCallback, 1, 2); dawnBufferBuilderSetErrorCallback(bufferBuilder, ToMockBuilderErrorCallback, 1, 2);
dawnBufferBuilderGetResult(bufferBuilder); dawnBufferBuilderGetResult(bufferBuilder);
dawnBufferBuilder apiBufferBuilder = api.GetNewBufferBuilder(); DawnBufferBuilder apiBufferBuilder = api.GetNewBufferBuilder();
EXPECT_CALL(api, DeviceCreateBufferBuilderForTesting(apiDevice)) EXPECT_CALL(api, DeviceCreateBufferBuilderForTesting(apiDevice))
.WillOnce(Return(apiBufferBuilder)); .WillOnce(Return(apiBufferBuilder));
dawnBuffer apiBuffer = api.GetNewBuffer(); DawnBuffer apiBuffer = api.GetNewBuffer();
EXPECT_CALL(api, BufferBuilderGetResult(apiBufferBuilder)) EXPECT_CALL(api, BufferBuilderGetResult(apiBufferBuilder))
.WillOnce(InvokeWithoutArgs([&]() -> dawnBuffer { .WillOnce(InvokeWithoutArgs([&]() -> DawnBuffer {
api.CallBuilderErrorCallback(apiBufferBuilder, DAWN_BUILDER_ERROR_STATUS_SUCCESS, api.CallBuilderErrorCallback(apiBufferBuilder, DAWN_BUILDER_ERROR_STATUS_SUCCESS,
"I like cheese"); "I like cheese");
return apiBuffer; return apiBuffer;
@ -103,7 +103,7 @@ TEST_F(WireCallbackTests, SuccessCallbackOnBuilderSuccess) {
TEST_F(WireCallbackTests, UnknownBuilderErrorStatusCallback) { TEST_F(WireCallbackTests, UnknownBuilderErrorStatusCallback) {
// The builder is destroyed before the object is built // The builder is destroyed before the object is built
{ {
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device); DawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
dawnBufferBuilderSetErrorCallback(bufferBuilder, ToMockBuilderErrorCallback, 1, 2); dawnBufferBuilderSetErrorCallback(bufferBuilder, ToMockBuilderErrorCallback, 1, 2);
EXPECT_CALL(*mockBuilderErrorCallback, Call(DAWN_BUILDER_ERROR_STATUS_UNKNOWN, _, 1, 2)) EXPECT_CALL(*mockBuilderErrorCallback, Call(DAWN_BUILDER_ERROR_STATUS_UNKNOWN, _, 1, 2))
@ -114,7 +114,7 @@ TEST_F(WireCallbackTests, UnknownBuilderErrorStatusCallback) {
// If the builder has been consumed, it doesn't fire the callback with unknown // If the builder has been consumed, it doesn't fire the callback with unknown
{ {
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device); DawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
dawnBufferBuilderSetErrorCallback(bufferBuilder, ToMockBuilderErrorCallback, 3, 4); dawnBufferBuilderSetErrorCallback(bufferBuilder, ToMockBuilderErrorCallback, 3, 4);
dawnBufferBuilderGetResult(bufferBuilder); dawnBufferBuilderGetResult(bufferBuilder);
@ -127,9 +127,9 @@ TEST_F(WireCallbackTests, UnknownBuilderErrorStatusCallback) {
// If the builder has been consumed, and the object is destroyed before the result comes from // If the builder has been consumed, and the object is destroyed before the result comes from
// the server, then the callback is fired with unknown // the server, then the callback is fired with unknown
{ {
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device); DawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
dawnBufferBuilderSetErrorCallback(bufferBuilder, ToMockBuilderErrorCallback, 5, 6); dawnBufferBuilderSetErrorCallback(bufferBuilder, ToMockBuilderErrorCallback, 5, 6);
dawnBuffer buffer = dawnBufferBuilderGetResult(bufferBuilder); DawnBuffer buffer = dawnBufferBuilderGetResult(bufferBuilder);
EXPECT_CALL(*mockBuilderErrorCallback, Call(DAWN_BUILDER_ERROR_STATUS_UNKNOWN, _, 5, 6)) EXPECT_CALL(*mockBuilderErrorCallback, Call(DAWN_BUILDER_ERROR_STATUS_UNKNOWN, _, 5, 6))
.Times(1); .Times(1);
@ -142,16 +142,16 @@ TEST_F(WireCallbackTests, UnknownBuilderErrorStatusCallback) {
TEST_F(WireCallbackTests, SuccessCallbackNotForwardedToDevice) { TEST_F(WireCallbackTests, SuccessCallbackNotForwardedToDevice) {
dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, 0); dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, 0);
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device); DawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
dawnBufferBuilderGetResult(bufferBuilder); dawnBufferBuilderGetResult(bufferBuilder);
dawnBufferBuilder apiBufferBuilder = api.GetNewBufferBuilder(); DawnBufferBuilder apiBufferBuilder = api.GetNewBufferBuilder();
EXPECT_CALL(api, DeviceCreateBufferBuilderForTesting(apiDevice)) EXPECT_CALL(api, DeviceCreateBufferBuilderForTesting(apiDevice))
.WillOnce(Return(apiBufferBuilder)); .WillOnce(Return(apiBufferBuilder));
dawnBuffer apiBuffer = api.GetNewBuffer(); DawnBuffer apiBuffer = api.GetNewBuffer();
EXPECT_CALL(api, BufferBuilderGetResult(apiBufferBuilder)) EXPECT_CALL(api, BufferBuilderGetResult(apiBufferBuilder))
.WillOnce(InvokeWithoutArgs([&]() -> dawnBuffer { .WillOnce(InvokeWithoutArgs([&]() -> DawnBuffer {
api.CallBuilderErrorCallback(apiBufferBuilder, DAWN_BUILDER_ERROR_STATUS_SUCCESS, api.CallBuilderErrorCallback(apiBufferBuilder, DAWN_BUILDER_ERROR_STATUS_SUCCESS,
"I like cheese"); "I like cheese");
return apiBuffer; return apiBuffer;
@ -168,15 +168,15 @@ TEST_F(WireCallbackTests, ErrorCallbackForwardedToDevice) {
uint64_t userdata = 30495; uint64_t userdata = 30495;
dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, userdata); dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, userdata);
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device); DawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
dawnBufferBuilderGetResult(bufferBuilder); dawnBufferBuilderGetResult(bufferBuilder);
dawnBufferBuilder apiBufferBuilder = api.GetNewBufferBuilder(); DawnBufferBuilder apiBufferBuilder = api.GetNewBufferBuilder();
EXPECT_CALL(api, DeviceCreateBufferBuilderForTesting(apiDevice)) EXPECT_CALL(api, DeviceCreateBufferBuilderForTesting(apiDevice))
.WillOnce(Return(apiBufferBuilder)); .WillOnce(Return(apiBufferBuilder));
EXPECT_CALL(api, BufferBuilderGetResult(apiBufferBuilder)) EXPECT_CALL(api, BufferBuilderGetResult(apiBufferBuilder))
.WillOnce(InvokeWithoutArgs([&]() -> dawnBuffer { .WillOnce(InvokeWithoutArgs([&]() -> DawnBuffer {
api.CallBuilderErrorCallback(apiBufferBuilder, DAWN_BUILDER_ERROR_STATUS_ERROR, api.CallBuilderErrorCallback(apiBufferBuilder, DAWN_BUILDER_ERROR_STATUS_ERROR,
"Error :("); "Error :(");
return nullptr; return nullptr;
@ -213,9 +213,9 @@ TEST_F(WireCallbackTests, BuilderErrorCallback) {
uint64_t userdata2 = 982734239028; uint64_t userdata2 = 982734239028;
// Create the buffer builder, the callback is set immediately on the server side // Create the buffer builder, the callback is set immediately on the server side
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device); DawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
dawnBufferBuilder apiBufferBuilder = api.GetNewBufferBuilder(); DawnBufferBuilder apiBufferBuilder = api.GetNewBufferBuilder();
EXPECT_CALL(api, DeviceCreateBufferBuilderForTesting(apiDevice)) EXPECT_CALL(api, DeviceCreateBufferBuilderForTesting(apiDevice))
.WillOnce(Return(apiBufferBuilder)); .WillOnce(Return(apiBufferBuilder));
@ -231,9 +231,9 @@ TEST_F(WireCallbackTests, BuilderErrorCallback) {
// Create an object so that it is a valid case to call the error callback // Create an object so that it is a valid case to call the error callback
dawnBufferBuilderGetResult(bufferBuilder); dawnBufferBuilderGetResult(bufferBuilder);
dawnBuffer apiBuffer = api.GetNewBuffer(); DawnBuffer apiBuffer = api.GetNewBuffer();
EXPECT_CALL(api, BufferBuilderGetResult(apiBufferBuilder)) EXPECT_CALL(api, BufferBuilderGetResult(apiBufferBuilder))
.WillOnce(InvokeWithoutArgs([&]() -> dawnBuffer { .WillOnce(InvokeWithoutArgs([&]() -> DawnBuffer {
api.CallBuilderErrorCallback(apiBufferBuilder, DAWN_BUILDER_ERROR_STATUS_SUCCESS, api.CallBuilderErrorCallback(apiBufferBuilder, DAWN_BUILDER_ERROR_STATUS_SUCCESS,
"Success!"); "Success!");
return apiBuffer; return apiBuffer;

View File

@ -22,22 +22,22 @@ namespace {
// Mock classes to add expectations on the wire calling callbacks // Mock classes to add expectations on the wire calling callbacks
class MockDeviceErrorCallback { class MockDeviceErrorCallback {
public: public:
MOCK_METHOD2(Call, void(const char* message, dawnCallbackUserdata userdata)); MOCK_METHOD2(Call, void(const char* message, DawnCallbackUserdata userdata));
}; };
std::unique_ptr<MockDeviceErrorCallback> mockDeviceErrorCallback; std::unique_ptr<MockDeviceErrorCallback> mockDeviceErrorCallback;
void ToMockDeviceErrorCallback(const char* message, dawnCallbackUserdata userdata) { void ToMockDeviceErrorCallback(const char* message, DawnCallbackUserdata userdata) {
mockDeviceErrorCallback->Call(message, userdata); mockDeviceErrorCallback->Call(message, userdata);
} }
class MockFenceOnCompletionCallback { class MockFenceOnCompletionCallback {
public: public:
MOCK_METHOD2(Call, void(dawnFenceCompletionStatus status, dawnCallbackUserdata userdata)); MOCK_METHOD2(Call, void(DawnFenceCompletionStatus status, DawnCallbackUserdata userdata));
}; };
std::unique_ptr<MockFenceOnCompletionCallback> mockFenceOnCompletionCallback; std::unique_ptr<MockFenceOnCompletionCallback> mockFenceOnCompletionCallback;
void ToMockFenceOnCompletionCallback(dawnFenceCompletionStatus status, void ToMockFenceOnCompletionCallback(DawnFenceCompletionStatus status,
dawnCallbackUserdata userdata) { DawnCallbackUserdata userdata) {
mockFenceOnCompletionCallback->Call(status, userdata); mockFenceOnCompletionCallback->Call(status, userdata);
} }
@ -63,7 +63,7 @@ class WireFenceTests : public WireTest {
FlushClient(); FlushClient();
} }
{ {
dawnFenceDescriptor descriptor; DawnFenceDescriptor descriptor;
descriptor.initialValue = 1; descriptor.initialValue = 1;
descriptor.nextInChain = nullptr; descriptor.nextInChain = nullptr;
@ -98,11 +98,11 @@ class WireFenceTests : public WireTest {
} }
// A successfully created fence // A successfully created fence
dawnFence fence; DawnFence fence;
dawnFence apiFence; DawnFence apiFence;
dawnQueue queue; DawnQueue queue;
dawnQueue apiQueue; DawnQueue apiQueue;
}; };
// Check that signaling a fence succeeds // Check that signaling a fence succeeds
@ -116,7 +116,7 @@ TEST_F(WireFenceTests, QueueSignalSuccess) {
// Without any flushes, it is valid to signal a value greater than the current // Without any flushes, it is valid to signal a value greater than the current
// signaled value // signaled value
TEST_F(WireFenceTests, QueueSignalSynchronousValidationSuccess) { TEST_F(WireFenceTests, QueueSignalSynchronousValidationSuccess) {
dawnCallbackUserdata userdata = 9157; DawnCallbackUserdata userdata = 9157;
dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, userdata); dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, userdata);
EXPECT_CALL(*mockDeviceErrorCallback, Call(_, userdata)).Times(0); EXPECT_CALL(*mockDeviceErrorCallback, Call(_, userdata)).Times(0);
@ -128,7 +128,7 @@ TEST_F(WireFenceTests, QueueSignalSynchronousValidationSuccess) {
// Without any flushes, errors should be generated when signaling a value less // Without any flushes, errors should be generated when signaling a value less
// than or equal to the current signaled value // than or equal to the current signaled value
TEST_F(WireFenceTests, QueueSignalSynchronousValidationError) { TEST_F(WireFenceTests, QueueSignalSynchronousValidationError) {
dawnCallbackUserdata userdata = 3157; DawnCallbackUserdata userdata = 3157;
dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, userdata); dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, userdata);
EXPECT_CALL(*mockDeviceErrorCallback, Call(_, userdata)).Times(1); EXPECT_CALL(*mockDeviceErrorCallback, Call(_, userdata)).Times(1);
@ -152,7 +152,7 @@ TEST_F(WireFenceTests, QueueSignalSynchronousValidationError) {
TEST_F(WireFenceTests, OnCompletionImmediate) { TEST_F(WireFenceTests, OnCompletionImmediate) {
// Can call on value < (initial) signaled value happens immediately // Can call on value < (initial) signaled value happens immediately
{ {
dawnCallbackUserdata userdata = 9847; DawnCallbackUserdata userdata = 9847;
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, userdata)) Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, userdata))
.Times(1); .Times(1);
@ -161,7 +161,7 @@ TEST_F(WireFenceTests, OnCompletionImmediate) {
// Can call on value == (initial) signaled value happens immediately // Can call on value == (initial) signaled value happens immediately
{ {
dawnCallbackUserdata userdata = 4347; DawnCallbackUserdata userdata = 4347;
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, userdata)) Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, userdata))
.Times(1); .Times(1);
@ -174,10 +174,10 @@ TEST_F(WireFenceTests, OnCompletionMultiple) {
DoQueueSignal(3u); DoQueueSignal(3u);
DoQueueSignal(6u); DoQueueSignal(6u);
dawnCallbackUserdata userdata0 = 2134; DawnCallbackUserdata userdata0 = 2134;
dawnCallbackUserdata userdata1 = 7134; DawnCallbackUserdata userdata1 = 7134;
dawnCallbackUserdata userdata2 = 3144; DawnCallbackUserdata userdata2 = 3144;
dawnCallbackUserdata userdata3 = 1130; DawnCallbackUserdata userdata3 = 1130;
// Add callbacks in a non-monotonic order. They should still be called // Add callbacks in a non-monotonic order. They should still be called
// in order of increasing fence value. // in order of increasing fence value.
@ -221,8 +221,8 @@ TEST_F(WireFenceTests, OnCompletionSynchronousValidationSuccess) {
// Without any flushes, errors should be generated when waiting on a value greater // Without any flushes, errors should be generated when waiting on a value greater
// than the last signaled value // than the last signaled value
TEST_F(WireFenceTests, OnCompletionSynchronousValidationError) { TEST_F(WireFenceTests, OnCompletionSynchronousValidationError) {
dawnCallbackUserdata userdata1 = 3817; DawnCallbackUserdata userdata1 = 3817;
dawnCallbackUserdata userdata2 = 3857; DawnCallbackUserdata userdata2 = 3857;
dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, userdata2); dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, userdata2);
EXPECT_CALL(*mockFenceOnCompletionCallback, Call(DAWN_FENCE_COMPLETION_STATUS_ERROR, userdata1)) EXPECT_CALL(*mockFenceOnCompletionCallback, Call(DAWN_FENCE_COMPLETION_STATUS_ERROR, userdata1))
@ -255,7 +255,7 @@ TEST_F(WireFenceTests, GetCompletedValueNoUpdate) {
// Check that the callback is called with UNKNOWN when the fence is destroyed // Check that the callback is called with UNKNOWN when the fence is destroyed
// before the completed value is updated // before the completed value is updated
TEST_F(WireFenceTests, DestroyBeforeOnCompletionEnd) { TEST_F(WireFenceTests, DestroyBeforeOnCompletionEnd) {
dawnCallbackUserdata userdata = 8616; DawnCallbackUserdata userdata = 8616;
dawnQueueSignal(queue, fence, 3u); dawnQueueSignal(queue, fence, 3u);
dawnFenceOnCompletion(fence, 2u, ToMockFenceOnCompletionCallback, userdata); dawnFenceOnCompletion(fence, 2u, ToMockFenceOnCompletionCallback, userdata);
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
@ -267,13 +267,13 @@ TEST_F(WireFenceTests, DestroyBeforeOnCompletionEnd) {
// Test that signaling a fence on a wrong queue is invalid // Test that signaling a fence on a wrong queue is invalid
TEST_F(WireFenceTests, SignalWrongQueue) { TEST_F(WireFenceTests, SignalWrongQueue) {
dawnQueue queue2 = dawnDeviceCreateQueue(device); DawnQueue queue2 = dawnDeviceCreateQueue(device);
dawnQueue apiQueue2 = api.GetNewQueue(); DawnQueue apiQueue2 = api.GetNewQueue();
EXPECT_CALL(api, DeviceCreateQueue(apiDevice)).WillOnce(Return(apiQueue2)); EXPECT_CALL(api, DeviceCreateQueue(apiDevice)).WillOnce(Return(apiQueue2));
EXPECT_CALL(api, QueueRelease(apiQueue2)); EXPECT_CALL(api, QueueRelease(apiQueue2));
FlushClient(); FlushClient();
dawnCallbackUserdata userdata = 1520; DawnCallbackUserdata userdata = 1520;
dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, userdata); dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, userdata);
EXPECT_CALL(*mockDeviceErrorCallback, Call(_, userdata)).Times(1); EXPECT_CALL(*mockDeviceErrorCallback, Call(_, userdata)).Times(1);
@ -282,13 +282,13 @@ TEST_F(WireFenceTests, SignalWrongQueue) {
// Test that signaling a fence on a wrong queue does not update fence signaled value // Test that signaling a fence on a wrong queue does not update fence signaled value
TEST_F(WireFenceTests, SignalWrongQueueDoesNotUpdateValue) { TEST_F(WireFenceTests, SignalWrongQueueDoesNotUpdateValue) {
dawnQueue queue2 = dawnDeviceCreateQueue(device); DawnQueue queue2 = dawnDeviceCreateQueue(device);
dawnQueue apiQueue2 = api.GetNewQueue(); DawnQueue apiQueue2 = api.GetNewQueue();
EXPECT_CALL(api, DeviceCreateQueue(apiDevice)).WillOnce(Return(apiQueue2)); EXPECT_CALL(api, DeviceCreateQueue(apiDevice)).WillOnce(Return(apiQueue2));
EXPECT_CALL(api, QueueRelease(apiQueue2)); EXPECT_CALL(api, QueueRelease(apiQueue2));
FlushClient(); FlushClient();
dawnCallbackUserdata userdata = 1024; DawnCallbackUserdata userdata = 1024;
dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, userdata); dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, userdata);
EXPECT_CALL(*mockDeviceErrorCallback, Call(_, userdata)).Times(1); EXPECT_CALL(*mockDeviceErrorCallback, Call(_, userdata)).Times(1);

View File

@ -26,23 +26,23 @@ class WireOptionalTests : public WireTest {
// Test passing nullptr instead of objects - object as value version // Test passing nullptr instead of objects - object as value version
TEST_F(WireOptionalTests, OptionalObjectValue) { TEST_F(WireOptionalTests, OptionalObjectValue) {
dawnBindGroupLayoutDescriptor bglDesc; DawnBindGroupLayoutDescriptor bglDesc;
bglDesc.nextInChain = nullptr; bglDesc.nextInChain = nullptr;
bglDesc.bindingCount = 0; bglDesc.bindingCount = 0;
dawnBindGroupLayout bgl = dawnDeviceCreateBindGroupLayout(device, &bglDesc); DawnBindGroupLayout bgl = dawnDeviceCreateBindGroupLayout(device, &bglDesc);
dawnBindGroupLayout apiBindGroupLayout = api.GetNewBindGroupLayout(); DawnBindGroupLayout apiBindGroupLayout = api.GetNewBindGroupLayout();
EXPECT_CALL(api, DeviceCreateBindGroupLayout(apiDevice, _)) EXPECT_CALL(api, DeviceCreateBindGroupLayout(apiDevice, _))
.WillOnce(Return(apiBindGroupLayout)); .WillOnce(Return(apiBindGroupLayout));
// The `sampler`, `textureView` and `buffer` members of a binding are optional. // The `sampler`, `textureView` and `buffer` members of a binding are optional.
dawnBindGroupBinding binding; DawnBindGroupBinding binding;
binding.binding = 0; binding.binding = 0;
binding.sampler = nullptr; binding.sampler = nullptr;
binding.textureView = nullptr; binding.textureView = nullptr;
binding.buffer = nullptr; binding.buffer = nullptr;
dawnBindGroupDescriptor bgDesc; DawnBindGroupDescriptor bgDesc;
bgDesc.nextInChain = nullptr; bgDesc.nextInChain = nullptr;
bgDesc.layout = bgl; bgDesc.layout = bgl;
bgDesc.bindingCount = 1; bgDesc.bindingCount = 1;
@ -50,7 +50,7 @@ TEST_F(WireOptionalTests, OptionalObjectValue) {
dawnDeviceCreateBindGroup(device, &bgDesc); dawnDeviceCreateBindGroup(device, &bgDesc);
EXPECT_CALL(api, DeviceCreateBindGroup( EXPECT_CALL(api, DeviceCreateBindGroup(
apiDevice, MatchesLambda([](const dawnBindGroupDescriptor* desc) -> bool { apiDevice, MatchesLambda([](const DawnBindGroupDescriptor* desc) -> bool {
return desc->nextInChain == nullptr && desc->bindingCount == 1 && return desc->nextInChain == nullptr && desc->bindingCount == 1 &&
desc->bindings[0].binding == 0 && desc->bindings[0].binding == 0 &&
desc->bindings[0].sampler == nullptr && desc->bindings[0].sampler == nullptr &&
@ -66,19 +66,19 @@ TEST_F(WireOptionalTests, OptionalObjectValue) {
// Test that the wire is able to send optional pointers to structures // Test that the wire is able to send optional pointers to structures
TEST_F(WireOptionalTests, OptionalStructPointer) { TEST_F(WireOptionalTests, OptionalStructPointer) {
// Create shader module // Create shader module
dawnShaderModuleDescriptor vertexDescriptor; DawnShaderModuleDescriptor vertexDescriptor;
vertexDescriptor.nextInChain = nullptr; vertexDescriptor.nextInChain = nullptr;
vertexDescriptor.codeSize = 0; vertexDescriptor.codeSize = 0;
dawnShaderModule vsModule = dawnDeviceCreateShaderModule(device, &vertexDescriptor); DawnShaderModule vsModule = dawnDeviceCreateShaderModule(device, &vertexDescriptor);
dawnShaderModule apiVsModule = api.GetNewShaderModule(); DawnShaderModule apiVsModule = api.GetNewShaderModule();
EXPECT_CALL(api, DeviceCreateShaderModule(apiDevice, _)).WillOnce(Return(apiVsModule)); EXPECT_CALL(api, DeviceCreateShaderModule(apiDevice, _)).WillOnce(Return(apiVsModule));
// Create the color state descriptor // Create the color state descriptor
dawnBlendDescriptor blendDescriptor; DawnBlendDescriptor blendDescriptor;
blendDescriptor.operation = DAWN_BLEND_OPERATION_ADD; blendDescriptor.operation = DAWN_BLEND_OPERATION_ADD;
blendDescriptor.srcFactor = DAWN_BLEND_FACTOR_ONE; blendDescriptor.srcFactor = DAWN_BLEND_FACTOR_ONE;
blendDescriptor.dstFactor = DAWN_BLEND_FACTOR_ONE; blendDescriptor.dstFactor = DAWN_BLEND_FACTOR_ONE;
dawnColorStateDescriptor colorStateDescriptor; DawnColorStateDescriptor colorStateDescriptor;
colorStateDescriptor.nextInChain = nullptr; colorStateDescriptor.nextInChain = nullptr;
colorStateDescriptor.format = DAWN_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM; colorStateDescriptor.format = DAWN_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM;
colorStateDescriptor.alphaBlend = blendDescriptor; colorStateDescriptor.alphaBlend = blendDescriptor;
@ -86,24 +86,24 @@ TEST_F(WireOptionalTests, OptionalStructPointer) {
colorStateDescriptor.colorWriteMask = DAWN_COLOR_WRITE_MASK_ALL; colorStateDescriptor.colorWriteMask = DAWN_COLOR_WRITE_MASK_ALL;
// Create the input state // Create the input state
dawnInputStateBuilder inputStateBuilder = dawnDeviceCreateInputStateBuilder(device); DawnInputStateBuilder inputStateBuilder = dawnDeviceCreateInputStateBuilder(device);
dawnInputStateBuilder apiInputStateBuilder = api.GetNewInputStateBuilder(); DawnInputStateBuilder apiInputStateBuilder = api.GetNewInputStateBuilder();
EXPECT_CALL(api, DeviceCreateInputStateBuilder(apiDevice)) EXPECT_CALL(api, DeviceCreateInputStateBuilder(apiDevice))
.WillOnce(Return(apiInputStateBuilder)); .WillOnce(Return(apiInputStateBuilder));
dawnInputState inputState = dawnInputStateBuilderGetResult(inputStateBuilder); DawnInputState inputState = dawnInputStateBuilderGetResult(inputStateBuilder);
dawnInputState apiInputState = api.GetNewInputState(); DawnInputState apiInputState = api.GetNewInputState();
EXPECT_CALL(api, InputStateBuilderGetResult(apiInputStateBuilder)) EXPECT_CALL(api, InputStateBuilderGetResult(apiInputStateBuilder))
.WillOnce(Return(apiInputState)); .WillOnce(Return(apiInputState));
// Create the depth-stencil state // Create the depth-stencil state
dawnStencilStateFaceDescriptor stencilFace; DawnStencilStateFaceDescriptor stencilFace;
stencilFace.compare = DAWN_COMPARE_FUNCTION_ALWAYS; stencilFace.compare = DAWN_COMPARE_FUNCTION_ALWAYS;
stencilFace.failOp = DAWN_STENCIL_OPERATION_KEEP; stencilFace.failOp = DAWN_STENCIL_OPERATION_KEEP;
stencilFace.depthFailOp = DAWN_STENCIL_OPERATION_KEEP; stencilFace.depthFailOp = DAWN_STENCIL_OPERATION_KEEP;
stencilFace.passOp = DAWN_STENCIL_OPERATION_KEEP; stencilFace.passOp = DAWN_STENCIL_OPERATION_KEEP;
dawnDepthStencilStateDescriptor depthStencilState; DawnDepthStencilStateDescriptor depthStencilState;
depthStencilState.nextInChain = nullptr; depthStencilState.nextInChain = nullptr;
depthStencilState.format = DAWN_TEXTURE_FORMAT_D32_FLOAT_S8_UINT; depthStencilState.format = DAWN_TEXTURE_FORMAT_D32_FLOAT_S8_UINT;
depthStencilState.depthWriteEnabled = false; depthStencilState.depthWriteEnabled = false;
@ -114,32 +114,32 @@ TEST_F(WireOptionalTests, OptionalStructPointer) {
depthStencilState.stencilWriteMask = 0xff; depthStencilState.stencilWriteMask = 0xff;
// Create the pipeline layout // Create the pipeline layout
dawnPipelineLayoutDescriptor layoutDescriptor; DawnPipelineLayoutDescriptor layoutDescriptor;
layoutDescriptor.nextInChain = nullptr; layoutDescriptor.nextInChain = nullptr;
layoutDescriptor.bindGroupLayoutCount = 0; layoutDescriptor.bindGroupLayoutCount = 0;
layoutDescriptor.bindGroupLayouts = nullptr; layoutDescriptor.bindGroupLayouts = nullptr;
dawnPipelineLayout layout = dawnDeviceCreatePipelineLayout(device, &layoutDescriptor); DawnPipelineLayout layout = dawnDeviceCreatePipelineLayout(device, &layoutDescriptor);
dawnPipelineLayout apiLayout = api.GetNewPipelineLayout(); DawnPipelineLayout apiLayout = api.GetNewPipelineLayout();
EXPECT_CALL(api, DeviceCreatePipelineLayout(apiDevice, _)).WillOnce(Return(apiLayout)); EXPECT_CALL(api, DeviceCreatePipelineLayout(apiDevice, _)).WillOnce(Return(apiLayout));
// Create pipeline // Create pipeline
dawnRenderPipelineDescriptor pipelineDescriptor; DawnRenderPipelineDescriptor pipelineDescriptor;
pipelineDescriptor.nextInChain = nullptr; pipelineDescriptor.nextInChain = nullptr;
dawnPipelineStageDescriptor vertexStage; DawnPipelineStageDescriptor vertexStage;
vertexStage.nextInChain = nullptr; vertexStage.nextInChain = nullptr;
vertexStage.module = vsModule; vertexStage.module = vsModule;
vertexStage.entryPoint = "main"; vertexStage.entryPoint = "main";
pipelineDescriptor.vertexStage = &vertexStage; pipelineDescriptor.vertexStage = &vertexStage;
dawnPipelineStageDescriptor fragmentStage; DawnPipelineStageDescriptor fragmentStage;
fragmentStage.nextInChain = nullptr; fragmentStage.nextInChain = nullptr;
fragmentStage.module = vsModule; fragmentStage.module = vsModule;
fragmentStage.entryPoint = "main"; fragmentStage.entryPoint = "main";
pipelineDescriptor.fragmentStage = &fragmentStage; pipelineDescriptor.fragmentStage = &fragmentStage;
pipelineDescriptor.colorStateCount = 1; pipelineDescriptor.colorStateCount = 1;
dawnColorStateDescriptor* colorStatesPtr[] = {&colorStateDescriptor}; DawnColorStateDescriptor* colorStatesPtr[] = {&colorStateDescriptor};
pipelineDescriptor.colorStates = colorStatesPtr; pipelineDescriptor.colorStates = colorStatesPtr;
pipelineDescriptor.sampleCount = 1; pipelineDescriptor.sampleCount = 1;
@ -154,7 +154,7 @@ TEST_F(WireOptionalTests, OptionalStructPointer) {
EXPECT_CALL( EXPECT_CALL(
api, api,
DeviceCreateRenderPipeline( DeviceCreateRenderPipeline(
apiDevice, MatchesLambda([](const dawnRenderPipelineDescriptor* desc) -> bool { apiDevice, MatchesLambda([](const DawnRenderPipelineDescriptor* desc) -> bool {
return desc->depthStencilState != nullptr && return desc->depthStencilState != nullptr &&
desc->depthStencilState->nextInChain == nullptr && desc->depthStencilState->nextInChain == nullptr &&
desc->depthStencilState->depthWriteEnabled == false && desc->depthStencilState->depthWriteEnabled == false &&
@ -185,7 +185,7 @@ TEST_F(WireOptionalTests, OptionalStructPointer) {
dawnDeviceCreateRenderPipeline(device, &pipelineDescriptor); dawnDeviceCreateRenderPipeline(device, &pipelineDescriptor);
EXPECT_CALL(api, EXPECT_CALL(api,
DeviceCreateRenderPipeline( DeviceCreateRenderPipeline(
apiDevice, MatchesLambda([](const dawnRenderPipelineDescriptor* desc) -> bool { apiDevice, MatchesLambda([](const DawnRenderPipelineDescriptor* desc) -> bool {
return desc->depthStencilState == nullptr; return desc->depthStencilState == nullptr;
}))) })))
.WillOnce(Return(nullptr)); .WillOnce(Return(nullptr));

View File

@ -28,8 +28,8 @@ WireTest::~WireTest() {
} }
void WireTest::SetUp() { void WireTest::SetUp() {
dawnProcTable mockProcs; DawnProcTable mockProcs;
dawnDevice mockDevice; DawnDevice mockDevice;
api.GetProcTableAndDevice(&mockProcs, &mockDevice); api.GetProcTableAndDevice(&mockProcs, &mockDevice);
// This SetCallback call cannot be ignored because it is done as soon as we start the server // This SetCallback call cannot be ignored because it is done as soon as we start the server
@ -49,7 +49,7 @@ void WireTest::SetUp() {
mS2cBuf->SetHandler(mWireClient.get()); mS2cBuf->SetHandler(mWireClient.get());
device = mWireClient->GetDevice(); device = mWireClient->GetDevice();
dawnProcTable clientProcs = mWireClient->GetProcs(); DawnProcTable clientProcs = mWireClient->GetProcs();
dawnSetProcs(&clientProcs); dawnSetProcs(&clientProcs);
apiDevice = mockDevice; apiDevice = mockDevice;

View File

@ -86,8 +86,8 @@ class WireTest : public testing::Test {
void FlushServer(); void FlushServer();
MockProcTable api; MockProcTable api;
dawnDevice apiDevice; DawnDevice apiDevice;
dawnDevice device; DawnDevice device;
private: private:
bool mIgnoreSetCallbackCalls = false; bool mIgnoreSetCallbackCalls = false;

View File

@ -25,22 +25,22 @@
namespace utils { namespace utils {
#if defined(DAWN_ENABLE_BACKEND_D3D12) #if defined(DAWN_ENABLE_BACKEND_D3D12)
BackendBinding* CreateD3D12Binding(GLFWwindow* window, dawnDevice device); BackendBinding* CreateD3D12Binding(GLFWwindow* window, DawnDevice device);
#endif #endif
#if defined(DAWN_ENABLE_BACKEND_METAL) #if defined(DAWN_ENABLE_BACKEND_METAL)
BackendBinding* CreateMetalBinding(GLFWwindow* window, dawnDevice device); BackendBinding* CreateMetalBinding(GLFWwindow* window, DawnDevice device);
#endif #endif
#if defined(DAWN_ENABLE_BACKEND_NULL) #if defined(DAWN_ENABLE_BACKEND_NULL)
BackendBinding* CreateNullBinding(GLFWwindow* window, dawnDevice device); BackendBinding* CreateNullBinding(GLFWwindow* window, DawnDevice device);
#endif #endif
#if defined(DAWN_ENABLE_BACKEND_OPENGL) #if defined(DAWN_ENABLE_BACKEND_OPENGL)
BackendBinding* CreateOpenGLBinding(GLFWwindow* window, dawnDevice device); BackendBinding* CreateOpenGLBinding(GLFWwindow* window, DawnDevice device);
#endif #endif
#if defined(DAWN_ENABLE_BACKEND_VULKAN) #if defined(DAWN_ENABLE_BACKEND_VULKAN)
BackendBinding* CreateVulkanBinding(GLFWwindow* window, dawnDevice device); BackendBinding* CreateVulkanBinding(GLFWwindow* window, DawnDevice device);
#endif #endif
BackendBinding::BackendBinding(GLFWwindow* window, dawnDevice device) BackendBinding::BackendBinding(GLFWwindow* window, DawnDevice device)
: mWindow(window), mDevice(device) { : mWindow(window), mDevice(device) {
} }
@ -75,7 +75,7 @@ namespace utils {
BackendBinding* CreateBinding(dawn_native::BackendType type, BackendBinding* CreateBinding(dawn_native::BackendType type,
GLFWwindow* window, GLFWwindow* window,
dawnDevice device) { DawnDevice device) {
switch (type) { switch (type) {
#if defined(DAWN_ENABLE_BACKEND_D3D12) #if defined(DAWN_ENABLE_BACKEND_D3D12)
case dawn_native::BackendType::D3D12: case dawn_native::BackendType::D3D12:

View File

@ -27,13 +27,13 @@ namespace utils {
virtual ~BackendBinding() = default; virtual ~BackendBinding() = default;
virtual uint64_t GetSwapChainImplementation() = 0; virtual uint64_t GetSwapChainImplementation() = 0;
virtual dawnTextureFormat GetPreferredSwapChainTextureFormat() = 0; virtual DawnTextureFormat GetPreferredSwapChainTextureFormat() = 0;
protected: protected:
BackendBinding(GLFWwindow* window, dawnDevice device); BackendBinding(GLFWwindow* window, DawnDevice device);
GLFWwindow* mWindow = nullptr; GLFWwindow* mWindow = nullptr;
dawnDevice mDevice = nullptr; DawnDevice mDevice = nullptr;
}; };
void SetupGLFWWindowHintsForBackend(dawn_native::BackendType type); void SetupGLFWWindowHintsForBackend(dawn_native::BackendType type);
@ -42,7 +42,7 @@ namespace utils {
dawn_native::BackendType type); dawn_native::BackendType type);
BackendBinding* CreateBinding(dawn_native::BackendType type, BackendBinding* CreateBinding(dawn_native::BackendType type,
GLFWwindow* window, GLFWwindow* window,
dawnDevice device); DawnDevice device);
} // namespace utils } // namespace utils

View File

@ -27,7 +27,7 @@ namespace utils {
class D3D12Binding : public BackendBinding { class D3D12Binding : public BackendBinding {
public: public:
D3D12Binding(GLFWwindow* window, dawnDevice device) : BackendBinding(window, device) { D3D12Binding(GLFWwindow* window, DawnDevice device) : BackendBinding(window, device) {
} }
uint64_t GetSwapChainImplementation() override { uint64_t GetSwapChainImplementation() override {
@ -39,16 +39,16 @@ namespace utils {
return reinterpret_cast<uint64_t>(&mSwapchainImpl); return reinterpret_cast<uint64_t>(&mSwapchainImpl);
} }
dawnTextureFormat GetPreferredSwapChainTextureFormat() override { DawnTextureFormat GetPreferredSwapChainTextureFormat() override {
ASSERT(mSwapchainImpl.userData != nullptr); ASSERT(mSwapchainImpl.userData != nullptr);
return dawn_native::d3d12::GetNativeSwapChainPreferredFormat(&mSwapchainImpl); return dawn_native::d3d12::GetNativeSwapChainPreferredFormat(&mSwapchainImpl);
} }
private: private:
dawnSwapChainImplementation mSwapchainImpl = {}; DawnSwapChainImplementation mSwapchainImpl = {};
}; };
BackendBinding* CreateD3D12Binding(GLFWwindow* window, dawnDevice device) { BackendBinding* CreateD3D12Binding(GLFWwindow* window, DawnDevice device) {
return new D3D12Binding(window, device); return new D3D12Binding(window, device);
} }

View File

@ -27,7 +27,7 @@
namespace utils { namespace utils {
class SwapChainImplMTL { class SwapChainImplMTL {
public: public:
using WSIContext = dawnWSIContextMetal; using WSIContext = DawnWSIContextMetal;
SwapChainImplMTL(id nsWindow) : mNsWindow(nsWindow) { SwapChainImplMTL(id nsWindow) : mNsWindow(nsWindow) {
} }
@ -37,13 +37,13 @@ namespace utils {
[mCurrentDrawable release]; [mCurrentDrawable release];
} }
void Init(dawnWSIContextMetal* ctx) { void Init(DawnWSIContextMetal* ctx) {
mMtlDevice = ctx->device; mMtlDevice = ctx->device;
mCommandQueue = [mMtlDevice newCommandQueue]; mCommandQueue = [mMtlDevice newCommandQueue];
} }
dawnSwapChainError Configure(dawnTextureFormat format, DawnSwapChainError Configure(DawnTextureFormat format,
dawnTextureUsageBit usage, DawnTextureUsageBit usage,
uint32_t width, uint32_t width,
uint32_t height) { uint32_t height) {
if (format != DAWN_TEXTURE_FORMAT_B8_G8_R8_A8_UNORM) { if (format != DAWN_TEXTURE_FORMAT_B8_G8_R8_A8_UNORM) {
@ -76,7 +76,7 @@ namespace utils {
return DAWN_SWAP_CHAIN_NO_ERROR; return DAWN_SWAP_CHAIN_NO_ERROR;
} }
dawnSwapChainError GetNextTexture(dawnSwapChainNextTexture* nextTexture) { DawnSwapChainError GetNextTexture(DawnSwapChainNextTexture* nextTexture) {
[mCurrentDrawable release]; [mCurrentDrawable release];
mCurrentDrawable = [mLayer nextDrawable]; mCurrentDrawable = [mLayer nextDrawable];
[mCurrentDrawable retain]; [mCurrentDrawable retain];
@ -90,7 +90,7 @@ namespace utils {
return DAWN_SWAP_CHAIN_NO_ERROR; return DAWN_SWAP_CHAIN_NO_ERROR;
} }
dawnSwapChainError Present() { DawnSwapChainError Present() {
id<MTLCommandBuffer> commandBuffer = [mCommandQueue commandBuffer]; id<MTLCommandBuffer> commandBuffer = [mCommandQueue commandBuffer];
[commandBuffer presentDrawable:mCurrentDrawable]; [commandBuffer presentDrawable:mCurrentDrawable];
[commandBuffer commit]; [commandBuffer commit];
@ -110,7 +110,7 @@ namespace utils {
class MetalBinding : public BackendBinding { class MetalBinding : public BackendBinding {
public: public:
MetalBinding(GLFWwindow* window, dawnDevice device) : BackendBinding(window, device) { MetalBinding(GLFWwindow* window, DawnDevice device) : BackendBinding(window, device) {
} }
uint64_t GetSwapChainImplementation() override { uint64_t GetSwapChainImplementation() override {
@ -121,15 +121,15 @@ namespace utils {
return reinterpret_cast<uint64_t>(&mSwapchainImpl); return reinterpret_cast<uint64_t>(&mSwapchainImpl);
} }
dawnTextureFormat GetPreferredSwapChainTextureFormat() override { DawnTextureFormat GetPreferredSwapChainTextureFormat() override {
return DAWN_TEXTURE_FORMAT_B8_G8_R8_A8_UNORM; return DAWN_TEXTURE_FORMAT_B8_G8_R8_A8_UNORM;
} }
private: private:
dawnSwapChainImplementation mSwapchainImpl = {}; DawnSwapChainImplementation mSwapchainImpl = {};
}; };
BackendBinding* CreateMetalBinding(GLFWwindow* window, dawnDevice device) { BackendBinding* CreateMetalBinding(GLFWwindow* window, DawnDevice device) {
return new MetalBinding(window, device); return new MetalBinding(window, device);
} }
} }

View File

@ -23,7 +23,7 @@ namespace utils {
class NullBinding : public BackendBinding { class NullBinding : public BackendBinding {
public: public:
NullBinding(GLFWwindow* window, dawnDevice device) : BackendBinding(window, device) { NullBinding(GLFWwindow* window, DawnDevice device) : BackendBinding(window, device) {
} }
uint64_t GetSwapChainImplementation() override { uint64_t GetSwapChainImplementation() override {
@ -32,15 +32,15 @@ namespace utils {
} }
return reinterpret_cast<uint64_t>(&mSwapchainImpl); return reinterpret_cast<uint64_t>(&mSwapchainImpl);
} }
dawnTextureFormat GetPreferredSwapChainTextureFormat() override { DawnTextureFormat GetPreferredSwapChainTextureFormat() override {
return DAWN_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM; return DAWN_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM;
} }
private: private:
dawnSwapChainImplementation mSwapchainImpl = {}; DawnSwapChainImplementation mSwapchainImpl = {};
}; };
BackendBinding* CreateNullBinding(GLFWwindow* window, dawnDevice device) { BackendBinding* CreateNullBinding(GLFWwindow* window, DawnDevice device) {
return new NullBinding(window, device); return new NullBinding(window, device);
} }

View File

@ -29,7 +29,7 @@
namespace utils { namespace utils {
class SwapChainImplGL { class SwapChainImplGL {
public: public:
using WSIContext = dawnWSIContextGL; using WSIContext = DawnWSIContextGL;
SwapChainImplGL(GLFWwindow* window) : mWindow(window) { SwapChainImplGL(GLFWwindow* window) : mWindow(window) {
} }
@ -39,7 +39,7 @@ namespace utils {
glDeleteFramebuffers(1, &mBackFBO); glDeleteFramebuffers(1, &mBackFBO);
} }
void Init(dawnWSIContextGL*) { void Init(DawnWSIContextGL*) {
glGenTextures(1, &mBackTexture); glGenTextures(1, &mBackTexture);
glBindTexture(GL_TEXTURE_2D, mBackTexture); glBindTexture(GL_TEXTURE_2D, mBackTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
@ -50,8 +50,8 @@ namespace utils {
mBackTexture, 0); mBackTexture, 0);
} }
dawnSwapChainError Configure(dawnTextureFormat format, DawnSwapChainError Configure(DawnTextureFormat format,
dawnTextureUsageBit, DawnTextureUsageBit,
uint32_t width, uint32_t width,
uint32_t height) { uint32_t height) {
if (format != DAWN_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM) { if (format != DAWN_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM) {
@ -70,12 +70,12 @@ namespace utils {
return DAWN_SWAP_CHAIN_NO_ERROR; return DAWN_SWAP_CHAIN_NO_ERROR;
} }
dawnSwapChainError GetNextTexture(dawnSwapChainNextTexture* nextTexture) { DawnSwapChainError GetNextTexture(DawnSwapChainNextTexture* nextTexture) {
nextTexture->texture.u32 = mBackTexture; nextTexture->texture.u32 = mBackTexture;
return DAWN_SWAP_CHAIN_NO_ERROR; return DAWN_SWAP_CHAIN_NO_ERROR;
} }
dawnSwapChainError Present() { DawnSwapChainError Present() {
glBindFramebuffer(GL_READ_FRAMEBUFFER, mBackFBO); glBindFramebuffer(GL_READ_FRAMEBUFFER, mBackFBO);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBlitFramebuffer(0, 0, mWidth, mHeight, 0, mHeight, mWidth, 0, GL_COLOR_BUFFER_BIT, glBlitFramebuffer(0, 0, mWidth, mHeight, 0, mHeight, mWidth, 0, GL_COLOR_BUFFER_BIT,
@ -95,7 +95,7 @@ namespace utils {
class OpenGLBinding : public BackendBinding { class OpenGLBinding : public BackendBinding {
public: public:
OpenGLBinding(GLFWwindow* window, dawnDevice device) : BackendBinding(window, device) { OpenGLBinding(GLFWwindow* window, DawnDevice device) : BackendBinding(window, device) {
// Load the GL entry points in our copy of the glad static library // Load the GL entry points in our copy of the glad static library
gladLoadGLLoader(reinterpret_cast<GLADloadproc>(glfwGetProcAddress)); gladLoadGLLoader(reinterpret_cast<GLADloadproc>(glfwGetProcAddress));
} }
@ -107,15 +107,15 @@ namespace utils {
return reinterpret_cast<uint64_t>(&mSwapchainImpl); return reinterpret_cast<uint64_t>(&mSwapchainImpl);
} }
dawnTextureFormat GetPreferredSwapChainTextureFormat() override { DawnTextureFormat GetPreferredSwapChainTextureFormat() override {
return DAWN_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM; return DAWN_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM;
} }
private: private:
dawnSwapChainImplementation mSwapchainImpl = {}; DawnSwapChainImplementation mSwapchainImpl = {};
}; };
BackendBinding* CreateOpenGLBinding(GLFWwindow* window, dawnDevice device) { BackendBinding* CreateOpenGLBinding(GLFWwindow* window, DawnDevice device) {
return new OpenGLBinding(window, device); return new OpenGLBinding(window, device);
} }

View File

@ -26,7 +26,7 @@ namespace utils {
class VulkanBinding : public BackendBinding { class VulkanBinding : public BackendBinding {
public: public:
VulkanBinding(GLFWwindow* window, dawnDevice device) : BackendBinding(window, device) { VulkanBinding(GLFWwindow* window, DawnDevice device) : BackendBinding(window, device) {
} }
uint64_t GetSwapChainImplementation() override { uint64_t GetSwapChainImplementation() override {
@ -41,16 +41,16 @@ namespace utils {
} }
return reinterpret_cast<uint64_t>(&mSwapchainImpl); return reinterpret_cast<uint64_t>(&mSwapchainImpl);
} }
dawnTextureFormat GetPreferredSwapChainTextureFormat() override { DawnTextureFormat GetPreferredSwapChainTextureFormat() override {
ASSERT(mSwapchainImpl.userData != nullptr); ASSERT(mSwapchainImpl.userData != nullptr);
return dawn_native::vulkan::GetNativeSwapChainPreferredFormat(&mSwapchainImpl); return dawn_native::vulkan::GetNativeSwapChainPreferredFormat(&mSwapchainImpl);
} }
private: private:
dawnSwapChainImplementation mSwapchainImpl = {}; DawnSwapChainImplementation mSwapchainImpl = {};
}; };
BackendBinding* CreateVulkanBinding(GLFWwindow* window, dawnDevice device) { BackendBinding* CreateVulkanBinding(GLFWwindow* window, DawnDevice device) {
return new VulkanBinding(window, device); return new VulkanBinding(window, device);
} }