1#include "Foundation/Platform/WindowData.h"
3#include "GraphicsDeviceWebGPU.h"
6#include "dawn/webgpu_cpp_print.h"
7#include "dawn/dawn_proc.h"
8#include "dawn/native/DawnNative.h"
12#include <emscripten/version.h>
15#include "Foundation/Logging/Logger.h"
20 void request_adapter(WGPURequestAdapterStatus status, WGPUAdapter adapter, WGPUStringView message,
void * userdata,
void * )
23 char const *msg = message.data ? message.data :
"";
24 int siz = message.data ?
static_cast<int>(message.length) : 0;
25 char const *stat = status == WGPURequestAdapterStatus_Success ?
"success" :
"";
26 LOG_INFO(logger,
"request_adapter %p %.*s %s", adapter, siz, msg, stat);
27 ptr->initialize_adapter(adapter);
30 void request_device(WGPURequestDeviceStatus status, WGPUDevice device, WGPUStringView message,
void * userdata,
void * )
33 char const *msg = message.data ? message.data :
"";
34 int siz = message.data ?
static_cast<int>(message.length) : 0;
35 char const *stat = status == WGPURequestDeviceStatus_Success ?
"success" :
"";
36 LOG_INFO(logger,
"request_device %p %.*s %s", device, siz, msg, stat);
37 ptr->initialize_device(device);
40 void error_callback(
const WGPUDevice * , WGPUErrorType type, WGPUStringView message,
void * userdata1,
void * )
44 LOG_ERROR(logger,
"WebGPU err (%d) %.*s", type, WGPUStringViewFormat(message));
48 void logging_callback(WGPULoggingType type, WGPUStringView message,
void * userdata1,
void * )
52 LOG_INFO(logger,
"WebGPU log (%d) x%.*s", type, WGPUStringViewFormat(message));
63 void device_lost(
const WGPUDevice * , WGPUDeviceLostReason reason, WGPUStringView message,
void * userdata,
void * )
67 if(reason == WGPUDeviceLostReason_Destroyed)
68 LOG_INFO(logger,
"device_lost (%d) %.*s", reason, WGPUStringViewFormat(message));
69 else if(reason != WGPUDeviceLostReason_CallbackCancelled) {
70 LOG_FATAL(logger,
"device_lost (%d) %.*s", reason, WGPUStringViewFormat(message));
71 assert(reason == WGPUDeviceLostReason_Destroyed);
75 WGPULimits WebGPUDefaultLimits()
78 WGPULimits limits = WGPU_LIMITS_INIT;
79 limits.maxTextureDimension1D = 8192;
80 limits.maxTextureDimension2D = 8192;
81 limits.maxTextureDimension3D = 2048;
82 limits.maxTextureArrayLayers = 256;
83 limits.maxBindGroups = 4;
84 limits.maxBindGroupsPlusVertexBuffers = 24;
85 limits.maxBindingsPerBindGroup = 1000;
86 limits.maxDynamicUniformBuffersPerPipelineLayout = 8;
87 limits.maxDynamicStorageBuffersPerPipelineLayout = 4;
88 limits.maxSampledTexturesPerShaderStage = 16;
89 limits.maxSamplersPerShaderStage = 16;
90 limits.maxStorageBuffersPerShaderStage = 8;
91 limits.maxStorageTexturesPerShaderStage = 4;
92 limits.maxUniformBuffersPerShaderStage = 12;
93 limits.maxUniformBufferBindingSize = 65536;
94 limits.maxStorageBufferBindingSize = 134217728;
95 limits.minUniformBufferOffsetAlignment = 256;
96 limits.minStorageBufferOffsetAlignment = 256;
97 limits.maxVertexBuffers = 8;
98 limits.maxBufferSize = 268435456;
99 limits.maxVertexAttributes = 16;
100 limits.maxVertexBufferArrayStride = 2048;
101 limits.maxInterStageShaderVariables = 16;
102 limits.maxColorAttachments = 8;
103 limits.maxColorAttachmentBytesPerSample = 32;
104 limits.maxComputeWorkgroupStorageSize = 16384;
105 limits.maxComputeInvocationsPerWorkgroup = 256;
106 limits.maxComputeWorkgroupSizeX = 256;
107 limits.maxComputeWorkgroupSizeY = 256;
108 limits.maxComputeWorkgroupSizeZ = 64;
109 limits.maxComputeWorkgroupsPerDimension = 65535;
110 limits.maxImmediateSize = 64;
117 GraphicsDeviceWebGPU::GraphicsDeviceWebGPU(RenderingAllocatorInfo* )
119 buffers.initialize(
this);
120 effects.initialize(
this, &buffers);
121 pipeline_states.initialize(
this);
122 renderTargets.initialize(
this);
123 context.initialize(
this);
124 textures.initialize(
this);
127 GraphicsDeviceWebGPU::~GraphicsDeviceWebGPU()
138#ifndef __EMSCRIPTEN__
140 DawnProcTable procTable = dawn::native::GetProcs();
141 dawnProcSetProcs(&procTable);
145 WGPUInstanceDescriptor instance_desc = WGPU_INSTANCE_DESCRIPTOR_INIT;
146 instance = wgpuCreateInstance(&instance_desc);
149 WGPUSurfaceDescriptor surface_desc = WGPU_SURFACE_DESCRIPTOR_INIT;
150 surface_desc.label = {
"WebGPU Surface", WGPU_STRLEN};
152 WGPUSurfaceSourceWindowsHWND hwnd_window = {};
153 hwnd_window.chain.sType = WGPUSType_SurfaceSourceWindowsHWND;
154 hwnd_window.hinstance = ::GetModuleHandle(
nullptr);
155 hwnd_window.hwnd = settings.
windowData->windowHandle;
156 surface_desc.nextInChain = (WGPUChainedStruct*)&hwnd_window;
163#elif defined(__EMSCRIPTEN__)
164 WGPUEmscriptenSurfaceSourceCanvasHTMLSelector html_canvas = WGPU_EMSCRIPTEN_SURFACE_SOURCE_CANVAS_HTML_SELECTOR_INIT;
165 html_canvas.chain.sType = WGPUSType_EmscriptenSurfaceSourceCanvasHTMLSelector;
166 html_canvas.selector = {
"canvas", WGPU_STRLEN};
167 surface_desc.nextInChain = (WGPUChainedStruct*)&html_canvas;
168#elif defined(__APPLE__)
172 static_assert(
false,
"Implement WebGPU Apple surface");
173#elif defined(__linux__)
174 WGPUSurfaceDescriptorFromXlibWindow x11_window = {};
175 x11_window.chain.sType = WGPUSType_SurfaceSourceXlibWindow;
176 x11_window.display = settings.
windowData->display;
177 x11_window.window = settings.
windowData->windowHandle;
178 surface_desc.nextInChain = (WGPUChainedStruct*)&x11_window;
183#elif defined(__ANDROID_API__)
187 static_assert(
false,
"Implement WebGPU Android surface");
189 surface = wgpuInstanceCreateSurface(instance, &surface_desc);
192 WGPURequestAdapterOptions adapter_options = WGPU_REQUEST_ADAPTER_OPTIONS_INIT;
193 adapter_options.nextInChain;
194 adapter_options.compatibleSurface = surface;
195 adapter_options.powerPreference = WGPUPowerPreference_HighPerformance;
196 adapter_options.forceFallbackAdapter;
197 adapter_options.backendType = WGPUBackendType_D3D11;
199 WGPURequestAdapterCallbackInfo callbackInfo = WGPU_REQUEST_ADAPTER_CALLBACK_INFO_INIT;
200 callbackInfo.nextInChain =
nullptr;
201 callbackInfo.callback = request_adapter;
202 callbackInfo.mode = WGPUCallbackMode_AllowSpontaneous;
203 callbackInfo.userdata1 =
this;
205 WGPUFuture future = wgpuInstanceRequestAdapter(instance, &adapter_options, callbackInfo);
207 WGPUFutureWaitInfo waitInfo = WGPU_FUTURE_WAIT_INFO_INIT;
208 waitInfo.future = future;
209 wgpuInstanceWaitAny(instance, 1, &waitInfo, 0);
214 void GraphicsDeviceWebGPU::initialize_adapter(WGPUAdapter adapter_in)
216 adapter = adapter_in;
220 WGPUAdapterInfo properties = WGPU_ADAPTER_INFO_INIT;
223 wgpuAdapterGetInfo(adapter, &properties);
224 LOG_INFO(logger,
"vendorID %u", properties.vendorID);
225 LOG_INFO(logger,
"vendor %.*s", WGPUStringViewFormat(properties.vendor));
226 LOG_INFO(logger,
"architecture %.*s", WGPUStringViewFormat(properties.architecture));
227 LOG_INFO(logger,
"deviceID %u", properties.deviceID);
228 LOG_INFO(logger,
"device %.*s", WGPUStringViewFormat(properties.device));
229 LOG_INFO(logger,
"description %.*s", WGPUStringViewFormat(properties.description));
230 LOG_INFO(logger,
"adapterType %d", properties.adapterType);
231 LOG_INFO(logger,
"backendType %d", properties.backendType);
232 LOG_INFO(logger,
"subgroupMinSize %u", properties.subgroupMinSize);
233 LOG_INFO(logger,
"subgroupMaxSize %u", properties.subgroupMaxSize);
235 if(properties.vendorID == 4130)
237 else if(properties.vendorID == 4318)
239 else if(properties.vendorID == 32902)
241 else if(properties.vendorID == 4203)
244 if(properties.vendorID == 4130){
245 if(strstr(properties.device.data,
"FireGL") !=
nullptr){
248 else if(strstr(properties.device.data,
"RadeonX") !=
nullptr){
251 else if(strstr(properties.device.data,
"RadeonHD") !=
nullptr){
255 else if(properties.vendorID == 4318){
256 if(strstr(properties.device.data,
"QuadroFX") !=
nullptr){
259 else if(strstr(properties.device.data,
"Quadro") !=
nullptr){
262 else if(strstr(properties.device.data,
"GeForce") !=
nullptr){
266 else if(properties.vendorID == 32902){
267 if(strstr(properties.device.data,
"IrisPro") !=
nullptr){
270 else if(strstr(properties.device.data,
"Iris") !=
nullptr){
273 else if(strstr(properties.device.data,
"HD") !=
nullptr){
278 capabilities.model = properties.deviceID;
280 WGPULimits adapter_limits = WGPU_LIMITS_INIT;
281 if(wgpuAdapterGetLimits(adapter, &adapter_limits)){
282 LOG_INFO(logger,
"adapter_limits ");
283 LOG_INFO(logger,
"maxTextureDimension1D %u", adapter_limits.maxTextureDimension1D);
284 LOG_INFO(logger,
"maxTextureDimension2D %u", adapter_limits.maxTextureDimension2D);
285 LOG_INFO(logger,
"maxTextureDimension3D %u", adapter_limits.maxTextureDimension3D);
286 LOG_INFO(logger,
"maxTextureArrayLayers %u", adapter_limits.maxTextureArrayLayers);
287 LOG_INFO(logger,
"maxBindGroups %u", adapter_limits.maxBindGroups);
288 LOG_INFO(logger,
"maxBindGroupsPlusVertexBuffers %u", adapter_limits.maxBindGroupsPlusVertexBuffers);
289 LOG_INFO(logger,
"maxBindingsPerBindGroup %u", adapter_limits.maxBindingsPerBindGroup);
290 LOG_INFO(logger,
"maxDynamicUniformBuffersPerPipelineLayout %u", adapter_limits.maxDynamicUniformBuffersPerPipelineLayout);
291 LOG_INFO(logger,
"maxDynamicStorageBuffersPerPipelineLayout %u", adapter_limits.maxDynamicStorageBuffersPerPipelineLayout);
292 LOG_INFO(logger,
"maxSampledTexturesPerShaderStage %u", adapter_limits.maxSampledTexturesPerShaderStage);
293 LOG_INFO(logger,
"maxSamplersPerShaderStage %u", adapter_limits.maxSamplersPerShaderStage);
294 LOG_INFO(logger,
"maxStorageBuffersPerShaderStage %u", adapter_limits.maxStorageBuffersPerShaderStage);
295 LOG_INFO(logger,
"maxStorageTexturesPerShaderStage %u", adapter_limits.maxStorageTexturesPerShaderStage);
296 LOG_INFO(logger,
"maxUniformBuffersPerShaderStage %u", adapter_limits.maxUniformBuffersPerShaderStage);
297 LOG_INFO(logger,
"maxUniformBufferBindingSize %llu", adapter_limits.maxUniformBufferBindingSize);
298 LOG_INFO(logger,
"maxStorageBufferBindingSize %llu", adapter_limits.maxStorageBufferBindingSize);
299 LOG_INFO(logger,
"minUniformBufferOffsetAlignment %u", adapter_limits.minUniformBufferOffsetAlignment);
300 LOG_INFO(logger,
"minStorageBufferOffsetAlignment %u", adapter_limits.minStorageBufferOffsetAlignment);
301 LOG_INFO(logger,
"maxVertexBuffers %u", adapter_limits.maxVertexBuffers);
302 LOG_INFO(logger,
"maxBufferSize %llu", adapter_limits.maxBufferSize);
303 LOG_INFO(logger,
"maxVertexAttributes %u", adapter_limits.maxVertexAttributes);
304 LOG_INFO(logger,
"maxVertexBufferArrayStride %u", adapter_limits.maxVertexBufferArrayStride);
305 LOG_INFO(logger,
"maxInterStageShaderVariables %u", adapter_limits.maxInterStageShaderVariables);
306 LOG_INFO(logger,
"maxColorAttachments %u", adapter_limits.maxColorAttachments);
307 LOG_INFO(logger,
"maxColorAttachmentBytesPerSample %u", adapter_limits.maxColorAttachmentBytesPerSample);
308 LOG_INFO(logger,
"maxComputeWorkgroupStorageSize %u", adapter_limits.maxComputeWorkgroupStorageSize);
309 LOG_INFO(logger,
"maxComputeInvocationsPerWorkgroup %u", adapter_limits.maxComputeInvocationsPerWorkgroup);
310 LOG_INFO(logger,
"maxComputeWorkgroupSizeX %u", adapter_limits.maxComputeWorkgroupSizeX);
311 LOG_INFO(logger,
"maxComputeWorkgroupSizeY %u", adapter_limits.maxComputeWorkgroupSizeY);
312 LOG_INFO(logger,
"maxComputeWorkgroupSizeZ %u", adapter_limits.maxComputeWorkgroupSizeZ);
313 LOG_INFO(logger,
"maxComputeWorkgroupsPerDimension %u", adapter_limits.maxComputeWorkgroupsPerDimension);
314 LOG_INFO(logger,
"maxImmediateSize %u", adapter_limits.maxImmediateSize);
353 WGPULimits required_limits = adapter_limits;
355 std::vector<WGPUFeatureName> features;
357 if(wgpuAdapterHasFeature(adapter, WGPUFeatureName_TextureCompressionBC)) {
358 features.push_back(WGPUFeatureName_TextureCompressionBC);
359 capabilities.capabilities.TextureCompressionBPTC =
true;
361 if(wgpuAdapterHasFeature(adapter, WGPUFeatureName_TextureCompressionASTC)) {
362 features.push_back(WGPUFeatureName_TextureCompressionASTC);
363 capabilities.capabilities.TextureCompressionASTC =
true;
365 if(wgpuAdapterHasFeature(adapter, WGPUFeatureName_TextureCompressionETC2)) {
366 features.push_back(WGPUFeatureName_TextureCompressionETC2);
367 capabilities.capabilities.TextureCompressionETC =
true;
369 if(wgpuAdapterHasFeature(adapter, WGPUFeatureName_Float32Filterable)) {
370 features.push_back(WGPUFeatureName_Float32Filterable);
374 WGPUDeviceDescriptor device_desc = WGPU_DEVICE_DESCRIPTOR_INIT;
375 device_desc.label = {
"WebGPU device", WGPU_STRLEN};
377 device_desc.requiredFeatureCount = features.size();
378 device_desc.requiredFeatures = features.data();
379 device_desc.requiredLimits = &required_limits;
380 device_desc.defaultQueue.label = {
"Default WebGPU queue", WGPU_STRLEN};
382 WGPUDeviceLostCallbackInfo deviceLostCallbackInfo = WGPU_DEVICE_LOST_CALLBACK_INFO_INIT;
383 deviceLostCallbackInfo.nextInChain =
nullptr;
384 deviceLostCallbackInfo.callback = device_lost;
385 deviceLostCallbackInfo.mode = WGPUCallbackMode_AllowSpontaneous;
386 deviceLostCallbackInfo.userdata1 =
this;
387 device_desc.deviceLostCallbackInfo = deviceLostCallbackInfo;
389 WGPUUncapturedErrorCallbackInfo uncapturedErrorCallbackInfo = WGPU_UNCAPTURED_ERROR_CALLBACK_INFO_INIT;
390 uncapturedErrorCallbackInfo.nextInChain =
nullptr;
391 uncapturedErrorCallbackInfo.callback = error_callback;
392 uncapturedErrorCallbackInfo.userdata1 =
this;
393 device_desc.uncapturedErrorCallbackInfo = uncapturedErrorCallbackInfo;
404 WGPURequestDeviceCallbackInfo requestDeviceCallbackInfo = WGPU_REQUEST_DEVICE_CALLBACK_INFO_INIT;
405 requestDeviceCallbackInfo.nextInChain =
nullptr;
406 requestDeviceCallbackInfo.mode = WGPUCallbackMode_AllowSpontaneous;
407 requestDeviceCallbackInfo.userdata1 =
this;
408 requestDeviceCallbackInfo.callback = request_device;
409 WGPUFuture future = wgpuAdapterRequestDevice(adapter, &device_desc, requestDeviceCallbackInfo);
411 WGPUFutureWaitInfo waitInfo = WGPU_FUTURE_WAIT_INFO_INIT;
412 waitInfo.future = future;
413 wgpuInstanceWaitAny(instance, 1, &waitInfo, 0);
416 void GraphicsDeviceWebGPU::maybeCreateUploadCommandEncoder()
418 if(commandEncoder)
return;
419 WGPUCommandEncoderDescriptor command_encoder_desc = WGPU_COMMAND_ENCODER_DESCRIPTOR_INIT;
420 command_encoder_desc.label = {
"Upload Command Encoder", WGPU_STRLEN};
421 commandEncoder = wgpuDeviceCreateCommandEncoder(device, &command_encoder_desc);
423 void GraphicsDeviceWebGPU::initialize_device(WGPUDevice device_in)
428#ifndef __EMSCRIPTEN__
429 WGPULoggingCallbackInfo loggingCallbackInfo = {};
430 loggingCallbackInfo.nextInChain =
nullptr;
431 loggingCallbackInfo.callback = logging_callback;
432 loggingCallbackInfo.userdata1 =
this;
433 wgpuDeviceSetLoggingCallback(device, loggingCallbackInfo);
436 WGPULimits device_limits = WGPU_LIMITS_INIT;
437 if(wgpuDeviceGetLimits(device, &device_limits)){
438 LOG_INFO(logger,
"device_limits ");
439 LOG_INFO(logger,
"maxTextureDimension1D %u", device_limits.maxTextureDimension1D);
440 LOG_INFO(logger,
"maxTextureDimension2D %u", device_limits.maxTextureDimension2D);
441 LOG_INFO(logger,
"maxTextureDimension3D %u", device_limits.maxTextureDimension3D);
442 LOG_INFO(logger,
"maxTextureArrayLayers %u", device_limits.maxTextureArrayLayers);
443 LOG_INFO(logger,
"maxBindGroups %u", device_limits.maxBindGroups);
444 LOG_INFO(logger,
"maxBindGroupsPlusVertexBuffers %u", device_limits.maxBindGroupsPlusVertexBuffers);
445 LOG_INFO(logger,
"maxBindingsPerBindGroup %u", device_limits.maxBindingsPerBindGroup);
446 LOG_INFO(logger,
"maxDynamicUniformBuffersPerPipelineLayout %u", device_limits.maxDynamicUniformBuffersPerPipelineLayout);
447 LOG_INFO(logger,
"maxDynamicStorageBuffersPerPipelineLayout %u", device_limits.maxDynamicStorageBuffersPerPipelineLayout);
448 LOG_INFO(logger,
"maxSampledTexturesPerShaderStage %u", device_limits.maxSampledTexturesPerShaderStage);
449 LOG_INFO(logger,
"maxSamplersPerShaderStage %u", device_limits.maxSamplersPerShaderStage);
450 LOG_INFO(logger,
"maxStorageBuffersPerShaderStage %u", device_limits.maxStorageBuffersPerShaderStage);
451 LOG_INFO(logger,
"maxStorageTexturesPerShaderStage %u", device_limits.maxStorageTexturesPerShaderStage);
452 LOG_INFO(logger,
"maxUniformBuffersPerShaderStage %u", device_limits.maxUniformBuffersPerShaderStage);
453 LOG_INFO(logger,
"maxUniformBufferBindingSize %llu", device_limits.maxUniformBufferBindingSize);
454 LOG_INFO(logger,
"maxStorageBufferBindingSize %llu", device_limits.maxStorageBufferBindingSize);
455 LOG_INFO(logger,
"minUniformBufferOffsetAlignment %u", device_limits.minUniformBufferOffsetAlignment);
456 LOG_INFO(logger,
"minStorageBufferOffsetAlignment %u", device_limits.minStorageBufferOffsetAlignment);
457 LOG_INFO(logger,
"maxVertexBuffers %u", device_limits.maxVertexBuffers);
458 LOG_INFO(logger,
"maxBufferSize %llu", device_limits.maxBufferSize);
459 LOG_INFO(logger,
"maxVertexAttributes %u", device_limits.maxVertexAttributes);
460 LOG_INFO(logger,
"maxVertexBufferArrayStride %u", device_limits.maxVertexBufferArrayStride);
461 LOG_INFO(logger,
"maxInterStageShaderVariables %u", device_limits.maxInterStageShaderVariables);
462 LOG_INFO(logger,
"maxColorAttachments %u", device_limits.maxColorAttachments);
463 LOG_INFO(logger,
"maxColorAttachmentBytesPerSample %u", device_limits.maxColorAttachmentBytesPerSample);
464 LOG_INFO(logger,
"maxComputeWorkgroupStorageSize %u", device_limits.maxComputeWorkgroupStorageSize);
465 LOG_INFO(logger,
"maxComputeInvocationsPerWorkgroup %u", device_limits.maxComputeInvocationsPerWorkgroup);
466 LOG_INFO(logger,
"maxComputeWorkgroupSizeX %u", device_limits.maxComputeWorkgroupSizeX);
467 LOG_INFO(logger,
"maxComputeWorkgroupSizeY %u", device_limits.maxComputeWorkgroupSizeY);
468 LOG_INFO(logger,
"maxComputeWorkgroupSizeZ %u", device_limits.maxComputeWorkgroupSizeZ);
469 LOG_INFO(logger,
"maxComputeWorkgroupsPerDimension %u", device_limits.maxComputeWorkgroupsPerDimension);
470 LOG_INFO(logger,
"maxImmediateSize %u", device_limits.maxImmediateSize);
474 capabilities.capabilities.RenderPass =
true;
476 capabilities.capabilities.GeometryShaders =
false;
477 capabilities.capabilities.TessellationShaders =
false;
478 capabilities.capabilities.ComputeShaders =
false;
479 capabilities.capabilities.SupportsHlsl =
false;
480 capabilities.capabilities.SupportsMultipleThreads =
false;
483 capabilities.capabilities.
MaxTexture2DSize = device_limits.maxTextureDimension2D;
484 capabilities.capabilities.
MaxTexture3DSize = device_limits.maxTextureDimension3D;
487 defaultSwapChain.initialize(device, surface);
489 queue = wgpuDeviceGetQueue(device);
491 LOG_INFO(logger,
"Has WebGPU Device");
495 void GraphicsDeviceWebGPU::destroy()
497 wgpuInstanceRelease(instance);
498 LOG_INFO(logger,
"WebGPU destroy");
500 wgpuCommandEncoderRelease(commandEncoder);
501 commandEncoder =
nullptr;
503 wgpuQueueRelease(queue);
504 defaultSwapChain.destroy();
505 wgpuSurfaceRelease(surface);
507 wgpuDeviceRelease(device);
508 wgpuAdapterRelease(adapter);
521 context.beginFrame();
524 WGPUCommandBufferDescriptor command_buffer_desc = WGPU_COMMAND_BUFFER_DESCRIPTOR_INIT;
525 command_buffer_desc.label = {
"Upload Command Buffer", WGPU_STRLEN};
526 WGPUCommandBuffer command_buffer = wgpuCommandEncoderFinish(commandEncoder, &command_buffer_desc);
527 wgpuCommandEncoderRelease(commandEncoder);
528 commandEncoder =
nullptr;
529 wgpuQueueSubmit(queue, 1, &command_buffer);
530 buffers.resetInstances();
533 context.ClearBindGroups();
535#ifndef __EMSCRIPTEN__
537 wgpuInstanceProcessEvents(instance);
538 wgpuDeviceTick(device);
543 WGPUCommandEncoderDescriptor command_encoder_desc = WGPU_COMMAND_ENCODER_DESCRIPTOR_INIT;
544 command_encoder_desc.label = {
"Default Command Encoder", WGPU_STRLEN};
545 commandEncoder = wgpuDeviceCreateCommandEncoder(device, &command_encoder_desc);
546 context.setDefaults();
551 context.updateRenderPass();
552 context.endRenderPassInt();
554#ifndef __EMSCRIPTEN__
555 WGPUTexelCopyTextureInfo src = WGPU_TEXEL_COPY_TEXTURE_INFO_INIT;
556 src.texture = defaultSwapChain.resolveTexture;
558 src.origin = {0, 0, 0};
559 src.aspect = WGPUTextureAspect_All;
560 WGPUTexelCopyTextureInfo dst = WGPU_TEXEL_COPY_TEXTURE_INFO_INIT;
561 WGPUSurfaceTexture surfaceTexture = context.graphicsDevice->defaultSwapChain.getTextureData();
562 dst.texture = surfaceTexture.texture;
564 dst.origin = {0, 0, 0};
565 dst.aspect = WGPUTextureAspect_All;
566 WGPUExtent3D copy_size = {(uint32_t)defaultSwapChain.set_width, (uint32_t)defaultSwapChain.set_height, 1};
567 wgpuCommandEncoderCopyTextureToTexture(commandEncoder, &src, &dst, ©_size);
570 WGPUCommandBufferDescriptor command_buffer_desc = WGPU_COMMAND_BUFFER_DESCRIPTOR_INIT;
571 command_buffer_desc.label = {
"Default Command Buffer", WGPU_STRLEN};
572 WGPUCommandBuffer command_buffer = wgpuCommandEncoderFinish(commandEncoder, &command_buffer_desc);
573 wgpuCommandEncoderRelease(commandEncoder);
574 commandEncoder =
nullptr;
575 wgpuQueueSubmit(queue, 1, &command_buffer);
576 buffers.resetInstances();
580 defaultSwapChain.
endFrame(syncInterval, presentFlags);
582 context.SwapBindGroups();
589 stats.bufferMemoryConsumption = buffers.bufferMemoryConsumption;
590 stats.textureMemoryConsumption = textures.textureMemoryConsumption;
591 stats.bufferCount =
static_cast<uint32_t
>(buffers.buffers.size());
592 stats.vertexArrayObjectCount = 0;
593 stats.inputLayoutCount =
static_cast<uint32_t
>(buffers.inputLayouts.size());
594 stats.textureCount =
static_cast<uint32_t
>(textures.textures.size());
595 stats.samplerStateCount =
static_cast<uint32_t
>(textures.samplerStates.size());
596 stats.effectCount =
static_cast<uint32_t
>(effects.effects.size());
597 stats.blendStateCount = 0;
598 stats.rasterizerStateCount = 0;
599 stats.depthStencilStateCount = 0;
600 stats.rendertargetsCount =
static_cast<uint32_t
>(renderTargets.render_targets.size());
601 stats.framebufferCount = 0;
virtual void releaseResources() override
Releases all allocated buffer resources.
virtual void releaseResources() override
Release all allocated effect resources.
virtual void beginFrame() override
Signal the beginning of a new frame to the graphics device.
virtual void releaseResources() override
Release all resources allocated.
virtual bool initialize() override
Initializes the graphics device with the settings previous set through calling setSettings.
virtual void endFrame(uint32_t=0, PresentFlags=PresentFlags::None) override
Signal the end of a frame to the graphics device.
Log implementation class.
virtual void releaseResources() override
Release all allocated render target resources.
virtual void beginFrame() override
Signal the beginning of a new frame to the graphics device.
virtual void endFrame(uint32_t syncInterval=0, PresentFlags presentFlags=PresentFlags::None) override
Signal the end of a frame to the graphics device.
virtual void releaseResources() override
Release all allocated texture resources.
constexpr Log getLogger(const char(&name)[LEN]) noexcept
Contains all Cogs related functionality.
PresentFlags
Flags controlling presentation.
void setIOHandler(IIOHandler *handler) override
Sets an external I/O handler to use for I/O operations.
uint32_t MaxTexture3DSize
Using D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION as default.
uint32_t MaxTexture2DSize
Using D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION as default.
bool SyncObjects
Support for syncronization objects.
uint32_t MaxTextureArrayLayers
Using D3D11_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION as default.
unsigned ConstantBufferOffsetAlignment
Minimum offset alignment when binding constant buffers.
bool ConstantBufferRange
supports binding a range of a constant buffer.
struct WindowData * windowData
Native window handle used to initialize the graphics device.
IIOHandler * ioHandler
Optional pointer to an IO handler.
@ QuadroFX
nVidia Quadro FX professional graphics adapters.
@ FireGL
AMD FireGL series.
@ geForce
nVidia geForce consumer adapters.
@ RadeonX
AMD Radeon X series.
@ RadeonHD
AMD Radeon HD series.
@ Quadro
nVidia Quadro professional graphics adapters.
@ nVidia
nVidia Corporation.