Upgrade to wgpu-native version 25.0.2.1

This commit is contained in:
Nikita Lisitsa 2025-08-08 23:20:44 +03:00
parent d3366b56aa
commit 46f672599d
51 changed files with 3813 additions and 1405 deletions

View file

@ -69,7 +69,7 @@ if(NOT DEFINED PSEMEK_GRAPHICS_API)
endif()
if(PSEMEK_GRAPHICS_API STREQUAL WEBGPU)
find_package(wgpu-native REQUIRED)
find_package(wgpu-native 25.0.2.1 REQUIRED)
endif()
message(STATUS "Using graphics API ${PSEMEK_GRAPHICS_API}")

View file

@ -92,21 +92,43 @@ namespace psemek::sdl2
wgpu_surface_ = instance.create_surface(surface_descriptor);
wgpu::adapter::request_options adapter_request_options;
// adapter_request_options.feature_level = wgpu::feature_level::compatibility;
adapter_request_options.compatible_surface = wgpu_surface_;
adapter_request_options.backend_type = wgpu::backend_type::undefined;
instance.request_adapter(adapter_request_options, [this](wgpu::adapter::request_status status, wgpu::adapter adapter_in, std::string const & message)
instance.request_adapter(wgpu::callback_mode::allow_process_events, adapter_request_options, [this](wgpu::adapter::request_status status, wgpu::adapter adapter_in, std::string_view message)
{
if (status != wgpu::adapter::request_status::success)
throw std::runtime_error("Failed to request WebGPU adapter: " + message);
throw std::runtime_error("Failed to request WebGPU adapter: " + std::string(message));
wgpu_adapter_ = std::move(adapter_in);
});
[[maybe_unused]] auto adapter_limits = wgpu_adapter_.get_limits();
wgpu::device::descriptor device_descriptor
{
.required_features = options.required_features,
.required_limits = std::nullopt,
.lost_callback = [](wgpu::device::lost_reason reason, std::string_view message)
{
std::ostringstream os;
os << "WebGPU device lost, reason: " << static_cast<std::uint32_t>(reason) << ", message: " << message;
auto str = os.str();
log::error() << str;
// This will most probably panic in wgpu-native internals
throw util::exception(std::move(str));
},
.lost_callback_mode = wgpu::callback_mode::allow_process_events,
.uncaptured_error_callback = [](wgpu::error_type type, std::string_view message)
{
std::ostringstream os;
os << "Uncaptured WebGPU error, type: " << static_cast<std::uint32_t>(type) << ", message: " << message;
auto str = os.str();
log::error() << str;
// This will most probably panic in wgpu-native internals
throw util::exception(std::move(str));
},
};
if (options.required_limits || options.required_native_limits)
@ -118,16 +140,18 @@ namespace psemek::sdl2
if (options.required_native_limits)
device_descriptor.required_limits->chain.push_back(wgpu::native_limits{*options.required_native_limits});
wgpu_adapter_.request_device(device_descriptor, [this](wgpu::device::request_status status, wgpu::device device_in, std::string const & message)
wgpu_adapter_.request_device(wgpu::callback_mode::allow_process_events, device_descriptor, [this](wgpu::device::request_status status, wgpu::device device_in, std::string_view message)
{
if (status != wgpu::device::request_status::success)
throw std::runtime_error("Failed to request WebGPU device: " + message);
throw std::runtime_error("Failed to request WebGPU device: " + std::string(message));
wgpu_device_ = std::move(device_in);
});
auto adapter_properties = wgpu_adapter_.get_properties();
[[maybe_unused]] auto device_limits = wgpu_device_.get_limits();
auto adapter_info = wgpu_adapter_.get_info();
std::string adapter_backend_str;
switch (adapter_properties.backend_type)
switch (adapter_info.backend_type)
{
case wgpu::backend_type::undefined:
adapter_backend_str = "undefined";
@ -158,7 +182,7 @@ namespace psemek::sdl2
break;
}
log::info() << "Initialized WebGPU: " << adapter_properties.name << ", " << adapter_backend_str << " backend";
log::info() << "Initialized WebGPU: " << adapter_info.device << ", " << adapter_backend_str << " backend";
log::info() << "Using wgpu-native version " << wgpu::get_version();
#endif
}

View file

@ -1,5 +1,6 @@
#pragma once
#include <psemek/wgpu/callback_mode.hpp>
#include <psemek/wgpu/chained_struct.hpp>
#include <psemek/wgpu/surface.hpp>
#include <psemek/wgpu/device.hpp>
@ -11,6 +12,12 @@
namespace psemek::wgpu
{
enum class feature_level : std::uint32_t
{
compatibility = 1,
core = 2,
};
enum class power_preference : std::uint32_t
{
undefined = 0x00000000,
@ -39,47 +46,49 @@ namespace psemek::wgpu
struct request_options
{
std::vector<chained_struct> chain = {};
surface compatible_surface = {};
wgpu::feature_level feature_level = feature_level::core;
wgpu::power_preference power_preference = power_preference::high;
wgpu::backend_type backend_type = backend_type::vulkan;
bool force_fallback_adapter = false;
wgpu::backend_type backend_type = backend_type::vulkan;
surface compatible_surface = {};
};
enum class request_status : std::uint32_t
{
success = 0x00000000,
unavailable = 0x00000001,
error = 0x00000002,
unknown = 0x00000003,
success = 0x00000001,
instance_dropped = 0x00000002,
unavailable = 0x00000003,
error = 0x00000004,
unknown = 0x00000005,
};
using request_callback = std::function<void(request_status, adapter, std::string)>;
using request_callback = std::function<void(request_status, adapter, std::string_view)>;
enum class type : std::uint32_t
{
discrete_gpu = 0x00000000,
integrated_gpu = 0x00000001,
cpu = 0x00000002,
unknown = 0x00000003,
discrete_gpu = 0x00000001,
integrated_gpu = 0x00000002,
cpu = 0x00000003,
unknown = 0x00000004,
};
struct properties
struct info
{
std::uint32_t vendor_id;
std::string vendor_name;
std::string architecture;
std::uint32_t device_id;
std::string name;
std::string driver_description;
enum type adapter_type;
std::string_view vendor;
std::string_view architecture;
std::string_view device;
std::string_view description;
wgpu::backend_type backend_type;
type adapter_type;
uint32_t vendor_id;
uint32_t device_id;
};
std::vector<feature> enumerate_features();
limits get_limits();
properties get_properties();
info get_info();
bool has_feature(feature feature);
void request_device(device::descriptor const & descriptor, device::request_callback const & callback);
void request_device(callback_mode mode, device::descriptor const & descriptor, device::request_callback const & callback);
static void reference(void * ptr);
static void release(void * ptr);

View file

@ -14,54 +14,57 @@ namespace psemek::wgpu
enum class buffer_binding_type : std::uint32_t
{
undefined = 0x00000000,
uniform = 0x00000001,
storage = 0x00000002,
read_only_storage = 0x00000003,
binding_not_used = 0x00000000,
undefined = 0x00000001,
uniform = 0x00000002,
storage = 0x00000003,
read_only_storage = 0x00000004,
};
struct buffer_binding_layout
{
std::vector<chained_struct> chain = {};
buffer_binding_type type = buffer_binding_type::undefined;
buffer_binding_type type = buffer_binding_type::binding_not_used;
bool has_dynamic_offset = false;
std::uint64_t min_binding_size = 0;
};
enum class sampler_binding_type : std::uint32_t
{
undefined = 0x00000000,
filtering = 0x00000001,
nonfiltering = 0x00000002,
comparison = 0x00000003,
binding_not_used = 0x00000000,
undefined = 0x00000001,
filtering = 0x00000002,
nonfiltering = 0x00000003,
comparison = 0x00000004,
};
struct sampler_binding_layout
{
std::vector<chained_struct> chain = {};
sampler_binding_type type = sampler_binding_type::undefined;
sampler_binding_type type = sampler_binding_type::binding_not_used;
};
struct texture_binding_layout
{
std::vector<chained_struct> chain = {};
texture::sample_type sample_type = texture::sample_type::undefined;
texture::sample_type sample_type = texture::sample_type::binding_not_used;
texture_view::dimension view_dimension = texture_view::dimension::undefined;
bool multisampled = false;
};
enum class storage_texture_access : std::uint32_t
{
undefined = 0x00000000,
write_only = 0x00000001,
read_only = 0x00000002,
read_write = 0x00000003,
binding_not_used = 0x00000000,
undefined = 0x00000001,
write_only = 0x00000002,
read_only = 0x00000003,
read_write = 0x00000004,
};
struct storage_texture_binding_layout
{
std::vector<chained_struct> chain = {};
storage_texture_access access = storage_texture_access::undefined;
storage_texture_access access = storage_texture_access::binding_not_used;
texture::format format = texture::format::undefined;
texture_view::dimension view_dimension = texture_view::dimension::undefined;
};

View file

@ -1,5 +1,6 @@
#pragma once
#include <psemek/wgpu/callback_mode.hpp>
#include <psemek/wgpu/chained_struct.hpp>
#include <psemek/wgpu/detail/object.hpp>
@ -15,46 +16,42 @@ namespace psemek::wgpu
{
using detail::object<buffer>::object;
enum class usage : std::uint32_t
enum class usage : std::uint64_t
{
none = 0x00000000,
map_read = 0x00000001,
map_write = 0x00000002,
copy_src = 0x00000004,
copy_dst = 0x00000008,
index = 0x00000010,
vertex = 0x00000020,
uniform = 0x00000040,
storage = 0x00000080,
indirect = 0x00000100,
none = 0x00000000,
map_read = 0x00000001,
map_write = 0x00000002,
copy_src = 0x00000004,
copy_dst = 0x00000008,
index = 0x00000010,
vertex = 0x00000020,
uniform = 0x00000040,
storage = 0x00000080,
indirect = 0x00000100,
query_resolve = 0x00000200,
};
enum class map_mode : std::uint32_t
enum class map_mode : std::uint64_t
{
none = 0x00000000,
read = 0x00000001,
none = 0x00000000,
read = 0x00000001,
write = 0x00000002,
};
enum class map_state : std::uint32_t
{
unmapped = 0x00000000,
pending = 0x00000001,
mapped = 0x00000002,
unmapped = 0x00000001,
pending = 0x00000002,
mapped = 0x00000003,
};
enum class map_async_status : std::uint32_t
{
success = 0x00000000,
validation_error = 0x00000001,
unknown = 0x00000002,
device_lost = 0x00000003,
destroyed_before_callback = 0x00000004,
unmapped_before_callback = 0x00000005,
mapping_already_pending = 0x00000006,
offset_out_of_range = 0x00000007,
size_out_of_range = 0x00000008,
success = 0x00000001,
instance_dropped = 0x00000002,
error = 0x00000003,
aborted = 0x00000004,
unknown = 0x00000005,
};
struct descriptor {
@ -65,7 +62,7 @@ namespace psemek::wgpu
bool mapped_at_creation = false;
};
using map_callback = std::function<void(map_async_status)>;
using map_callback = std::function<void(map_async_status, std::string_view)>;
void destroy();
std::uint64_t get_size();
@ -73,7 +70,7 @@ namespace psemek::wgpu
map_state get_map_state();
void const * get_const_mapped_range(std::size_t offset, std::size_t size);
void * get_mapped_range(std::size_t offset, std::size_t size);
void map_async(map_mode flags, std::size_t offset, std::size_t size, map_callback const & callback);
void map_async(callback_mode mode, map_mode flags, std::size_t offset, std::size_t size, map_callback const & callback);
void unmap();
void set_label(std::string const & label);

View file

@ -0,0 +1,15 @@
#pragma once
#include <cstdint>
namespace psemek::wgpu
{
enum class callback_mode : std::uint32_t
{
wait_any_only = 0x00000001,
allow_process_events = 0x00000002,
allow_spontaneous = 0x00000003,
};
}

View file

@ -45,6 +45,7 @@ namespace psemek::wgpu
};
void * fill_chain(std::vector<chained_struct> const & chain);
void * fill_chain_out(std::vector<chained_struct> const & chain);
using chained_struct_ptr = std::shared_ptr<chained_struct_base>;

View file

@ -31,9 +31,9 @@ namespace psemek::wgpu
render_pass_encoder begin_render_pass(render_pass_encoder::descriptor const & desc);
void clear_buffer(buffer const & buffer, std::uint64_t offset, std::uint64_t size);
void copy_buffer_to_buffer(buffer const & source, std::uint64_t source_offset, buffer const & destination, std::uint64_t destination_offset, std::uint64_t size);
void copy_buffer_to_texture(image_copy_buffer const & source, image_copy_texture const & destination, math::vector<std::uint32_t, 3> const & extent);
void copy_texture_to_buffer(image_copy_texture const & source, image_copy_buffer const & destination, math::vector<std::uint32_t, 3> const & extent);
void copy_texture_to_texture(image_copy_texture const & source, image_copy_texture const & destination, math::vector<std::uint32_t, 3> const & extent);
void copy_buffer_to_texture(texel_copy_buffer_info const & source, texel_copy_texture_info const & destination, math::vector<std::uint32_t, 3> const & extent);
void copy_texture_to_buffer(texel_copy_texture_info const & source, texel_copy_buffer_info const & destination, math::vector<std::uint32_t, 3> const & extent);
void copy_texture_to_texture(texel_copy_texture_info const & source, texel_copy_texture_info const & destination, math::vector<std::uint32_t, 3> const & extent);
void insert_debug_marker(std::string const & marker_label);
void push_debug_group(std::string const & group_label);
void pop_debug_group();

View file

@ -37,6 +37,8 @@ namespace psemek::wgpu
void set_pipeline(compute_pipeline const & pipeline);
void dispatch_workgroups(math::vector<std::uint32_t, 3> const & workgroup_count);
void dispatch_workgroups_indirect(buffer const & indirect_buffer, std::uint64_t offset);
void set_push_constants(std::uint32_t offset, util::span<char const> data);
void write_timestamp(query_set const & query_set, std::uint32_t query_index);
void insert_debug_marker(std::string const & marker_label);
void push_debug_group(std::string const & group_label);
void pop_debug_group();

View file

@ -0,0 +1,18 @@
#pragma once
#include <psemek/wgpu/external/webgpu.h>
#include <psemek/util/exception.hpp>
#include <string>
#include <string_view>
namespace psemek::wgpu::detail
{
inline void check_status(std::string_view caption, WGPUStatus status)
{
if (status != WGPUStatus_Success)
throw util::exception("wgpu error in " + std::string(caption));
}
}

View file

@ -0,0 +1,21 @@
#pragma once
#include <psemek/wgpu/external/webgpu.h>
#include <string>
#include <string_view>
namespace psemek::wgpu::detail
{
inline WGPUStringView to_string_view(std::string const & string)
{
return {.data = string.data(), .length = string.size()};
}
inline WGPUStringView to_string_view(std::string_view const & string_view)
{
return {.data = string_view.data(), .length = string_view.size()};
}
}

View file

@ -5,6 +5,7 @@
#include <psemek/wgpu/bind_group.hpp>
#include <psemek/wgpu/bind_group_layout.hpp>
#include <psemek/wgpu/buffer.hpp>
#include <psemek/wgpu/callback_mode.hpp>
#include <psemek/wgpu/command_encoder.hpp>
#include <psemek/wgpu/compute_pipeline.hpp>
#include <psemek/wgpu/pipeline_layout.hpp>
@ -26,16 +27,22 @@ namespace psemek::wgpu
enum class feature : std::uint32_t {
undefined = 0x00000000,
depth_clip_control = 0x00000001,
depth32float_stencil8 = 0x00000002,
depth32_float_stencil8 = 0x00000002,
timestamp_query = 0x00000003,
texture_compression_bc = 0x00000004,
texture_compression_etc2 = 0x00000005,
texture_compression_astc = 0x00000006,
indirect_first_instance = 0x00000007,
shader_f16 = 0x00000008,
rg11b10ufloat_renderable = 0x00000009,
bgra8unorm_storage = 0x0000000a,
float32_filterable = 0x0000000b,
texture_compression_BC = 0x00000004,
texture_compression_BC_sliced_3D = 0x00000005,
texture_compression_ETC2 = 0x00000006,
texture_compression_ASTC = 0x00000007,
texture_compression_ASTC_sliced_3D = 0x00000008,
indirect_first_instance = 0x00000009,
shader_f16 = 0x0000000A,
rg11b10_ufloat_renderable = 0x0000000B,
bgra8_unorm_storage = 0x0000000C,
float32_filterable = 0x0000000D,
float32_blendable = 0x0000000E,
clip_distances = 0x0000000F,
dual_source_blending = 0x00000010,
push_constants = 0x00030001,
texture_adapter_specific_format_features = 0x00030002,
@ -45,6 +52,27 @@ namespace psemek::wgpu
texture_binding_array = 0x00030006,
sampled_texture_and_storage_buffer_array_non_uniform_indexing = 0x00030007,
pipeline_statistics_query = 0x00030008,
storage_resource_binding_array = 0x00030009,
partially_bound_binding_array = 0x0003000a,
texture_format16bit_norm = 0x0003000b,
texture_compression_astc_hdr = 0x0003000c,
mappable_primary_buffers = 0x0003000e,
buffer_binding_array = 0x0003000f,
uniform_buffer_and_storage_texture_array_non_uniform_indexing = 0x00030010,
spirv_shader_passthrough = 0x00030017,
vertex_attribute64bit = 0x00030019,
texture_format_nv12 = 0x0003001a,
ray_tracing_acceleration_structure = 0x0003001b,
ray_query = 0x0003001c,
shader_f64 = 0x0003001d,
shader_i16 = 0x0003001e,
shader_primitive_index = 0x0003001f,
shader_early_depth_test = 0x00030020,
subgroup = 0x00030021,
subgroup_vertex = 0x00030022,
subgroup_barrier = 0x00030023,
timestamp_query_inside_encoders = 0x00030024,
timestamp_query_inside_passes = 0x00030025,
};
struct limits
@ -71,7 +99,6 @@ namespace psemek::wgpu
std::uint64_t max_buffer_size = 256 * 1024 * 1024;
std::uint32_t max_vertex_attributes = 16;
std::uint32_t max_vertex_buffer_array_stride = 2048;
std::uint32_t max_inter_stage_shader_components = 60;
std::uint32_t max_inter_stage_shader_variables = 15;
std::uint32_t max_color_attachments = 1;
std::uint32_t max_color_attachment_bytes_per_sample = 4;
@ -91,29 +118,34 @@ namespace psemek::wgpu
enum class create_pipeline_async_status : std::uint32_t
{
success = 0x00000000,
validation_error = 0x00000001,
internal_error = 0x00000002,
device_lost = 0x00000003,
device_destroyed = 0x00000004,
unknown = 0x00000005,
success = 0x00000001,
instance_dropped = 0x00000002,
validation_error = 0x00000003,
internal_error = 0x00000004,
unknown = 0x00000005,
};
enum class error_filter : std::uint32_t
{
validation = 0x00000000,
out_of_memory = 0x00000001,
internal = 0x00000002,
validation = 0x00000001,
out_of_memory = 0x00000002,
internal = 0x00000003,
};
enum class error_type : std::uint32_t
{
no_error = 0x00000000,
validation = 0x00000001,
out_of_memory = 0x00000002,
internal = 0x00000003,
unknown = 0x00000004,
device_lost = 0x00000005,
no_error = 0x00000001,
validation = 0x00000002,
out_of_memory = 0x00000003,
internal = 0x00000004,
unknown = 0x00000005,
};
enum class pop_error_scope_status : std::uint32_t
{
success = 0x00000001,
instance_dropped = 0x00000002,
empty_stack = 0x00000003,
};
struct device
@ -123,11 +155,14 @@ namespace psemek::wgpu
enum class lost_reason : std::uint32_t
{
undefined = 0x00000000,
destroyed = 0x00000001,
unknown = 0x00000001,
destroyed = 0x00000002,
instance_dropped = 0x00000003,
failed_creation = 0x00000004,
};
using lost_callback = std::function<void(lost_reason, std::string const &)>;
using lost_callback = std::function<void(lost_reason, std::string_view)>;
using uncaptured_error_callback = std::function<void(error_type, std::string_view)>;
struct required_limits
{
@ -143,18 +178,22 @@ namespace psemek::wgpu
std::optional<struct required_limits> required_limits = {};
queue::descriptor default_queue = {};
device::lost_callback lost_callback = {};
callback_mode lost_callback_mode = {};
device::uncaptured_error_callback uncaptured_error_callback = {};
};
enum class request_status : std::uint32_t
{
success = 0x00000000,
error = 0x00000001,
unknown = 0x00000002,
success = 0x00000001,
instance_dropped = 0x00000002,
error = 0x00000003,
unknown = 0x00000004,
};
using request_callback = std::function<void(request_status, device, std::string const & message)>;
using create_compute_pipeline_async_callback = std::function<void(create_pipeline_async_status, compute_pipeline, std::string const &)>;
using create_render_pipeline_async_callback = std::function<void(create_pipeline_async_status, render_pipeline, std::string const &)>;
using create_compute_pipeline_async_callback = std::function<void(create_pipeline_async_status, compute_pipeline, std::string_view)>;
using create_render_pipeline_async_callback = std::function<void(create_pipeline_async_status, render_pipeline, std::string_view)>;
using pop_error_callback = std::function<void(pop_error_scope_status, error_type, std::string_view)>;
using error_callback = std::function<void(error_type, std::string const &)>;
queue get_queue();
@ -163,11 +202,11 @@ namespace psemek::wgpu
buffer create_buffer(buffer::descriptor const & desc);
command_encoder create_command_encoder(command_encoder::descriptor const & desc);
compute_pipeline create_compute_pipeline(compute_pipeline::descriptor const & desc);
void create_compute_pipeline_async(compute_pipeline::descriptor const & desc, create_compute_pipeline_async_callback const & callback);
void create_compute_pipeline_async(callback_mode mode, compute_pipeline::descriptor const & desc, create_compute_pipeline_async_callback const & callback);
pipeline_layout create_pipeline_layout(pipeline_layout::descriptor const & desc);
query_set create_query_set(query_set::descriptor const & desc);
render_pipeline create_render_pipeline(render_pipeline::descriptor const & desc);
void create_render_pipeline_async(render_pipeline::descriptor const & desc, create_render_pipeline_async_callback const & callback);
void create_render_pipeline_async(callback_mode mode, render_pipeline::descriptor const & desc, create_render_pipeline_async_callback const & callback);
render_bundle_encoder create_render_bundle_encoder(render_bundle_encoder::descriptor const & desc);
sampler create_sampler(sampler::descriptor const & desc);
shader_module create_shader_module(shader_module::descriptor const & desc);
@ -177,8 +216,7 @@ namespace psemek::wgpu
limits get_limits();
bool has_feature(feature feature);
void push_error_scope(error_filter filter);
void pop_error_scope(error_callback const & callback);
void set_uncaptured_error_callback(error_callback const & callback);
void pop_error_scope(callback_mode mode, pop_error_callback const & callback);
void set_label(std::string const & label);
static void reference(void * ptr);

File diff suppressed because it is too large Load diff

View file

@ -6,10 +6,9 @@
typedef enum WGPUNativeSType {
// Start at 0003 since that's allocated range for wgpu-native
WGPUSType_DeviceExtras = 0x00030001,
WGPUSType_RequiredLimitsExtras = 0x00030002,
WGPUSType_NativeLimits = 0x00030002,
WGPUSType_PipelineLayoutExtras = 0x00030003,
WGPUSType_ShaderModuleGLSLDescriptor = 0x00030004,
WGPUSType_SupportedLimitsExtras = 0x00030005,
WGPUSType_ShaderSourceGLSL = 0x00030004,
WGPUSType_InstanceExtras = 0x00030006,
WGPUSType_BindGroupEntryExtras = 0x00030007,
WGPUSType_BindGroupLayoutEntryExtras = 0x00030008,
@ -29,6 +28,33 @@ typedef enum WGPUNativeFeature {
WGPUNativeFeature_PipelineStatisticsQuery = 0x00030008,
WGPUNativeFeature_StorageResourceBindingArray = 0x00030009,
WGPUNativeFeature_PartiallyBoundBindingArray = 0x0003000A,
WGPUNativeFeature_TextureFormat16bitNorm = 0x0003000B,
WGPUNativeFeature_TextureCompressionAstcHdr = 0x0003000C,
WGPUNativeFeature_MappablePrimaryBuffers = 0x0003000E,
WGPUNativeFeature_BufferBindingArray = 0x0003000F,
WGPUNativeFeature_UniformBufferAndStorageTextureArrayNonUniformIndexing = 0x00030010,
// TODO: requires wgpu.h api change
// WGPUNativeFeature_AddressModeClampToZero = 0x00030011,
// WGPUNativeFeature_AddressModeClampToBorder = 0x00030012,
// WGPUNativeFeature_PolygonModeLine = 0x00030013,
// WGPUNativeFeature_PolygonModePoint = 0x00030014,
// WGPUNativeFeature_ConservativeRasterization = 0x00030015,
// WGPUNativeFeature_ClearTexture = 0x00030016,
WGPUNativeFeature_SpirvShaderPassthrough = 0x00030017,
// WGPUNativeFeature_Multiview = 0x00030018,
WGPUNativeFeature_VertexAttribute64bit = 0x00030019,
WGPUNativeFeature_TextureFormatNv12 = 0x0003001A,
WGPUNativeFeature_RayTracingAccelerationStructure = 0x0003001B,
WGPUNativeFeature_RayQuery = 0x0003001C,
WGPUNativeFeature_ShaderF64 = 0x0003001D,
WGPUNativeFeature_ShaderI16 = 0x0003001E,
WGPUNativeFeature_ShaderPrimitiveIndex = 0x0003001F,
WGPUNativeFeature_ShaderEarlyDepthTest = 0x00030020,
WGPUNativeFeature_Subgroup = 0x00030021,
WGPUNativeFeature_SubgroupVertex = 0x00030022,
WGPUNativeFeature_SubgroupBarrier = 0x00030023,
WGPUNativeFeature_TimestampQueryInsideEncoders = 0x00030024,
WGPUNativeFeature_TimestampQueryInsidePasses = 0x00030025,
WGPUNativeFeature_Force32 = 0x7FFFFFFF
} WGPUNativeFeature;
@ -42,30 +68,26 @@ typedef enum WGPULogLevel {
WGPULogLevel_Force32 = 0x7FFFFFFF
} WGPULogLevel;
typedef enum WGPUInstanceBackend {
WGPUInstanceBackend_All = 0x00000000,
WGPUInstanceBackend_Vulkan = 1 << 0,
WGPUInstanceBackend_GL = 1 << 1,
WGPUInstanceBackend_Metal = 1 << 2,
WGPUInstanceBackend_DX12 = 1 << 3,
WGPUInstanceBackend_DX11 = 1 << 4,
WGPUInstanceBackend_BrowserWebGPU = 1 << 5,
WGPUInstanceBackend_Primary = WGPUInstanceBackend_Vulkan | WGPUInstanceBackend_Metal |
WGPUInstanceBackend_DX12 |
WGPUInstanceBackend_BrowserWebGPU,
WGPUInstanceBackend_Secondary = WGPUInstanceBackend_GL | WGPUInstanceBackend_DX11,
WGPUInstanceBackend_Force32 = 0x7FFFFFFF
} WGPUInstanceBackend;
typedef WGPUFlags WGPUInstanceBackendFlags;
typedef WGPUFlags WGPUInstanceBackend;
static const WGPUInstanceBackend WGPUInstanceBackend_All = 0x00000000;
static const WGPUInstanceBackend WGPUInstanceBackend_Vulkan = 1 << 0;
static const WGPUInstanceBackend WGPUInstanceBackend_GL = 1 << 1;
static const WGPUInstanceBackend WGPUInstanceBackend_Metal = 1 << 2;
static const WGPUInstanceBackend WGPUInstanceBackend_DX12 = 1 << 3;
static const WGPUInstanceBackend WGPUInstanceBackend_DX11 = 1 << 4;
static const WGPUInstanceBackend WGPUInstanceBackend_BrowserWebGPU = 1 << 5;
// Vulkan, Metal, DX12 and BrowserWebGPU
static const WGPUInstanceBackend WGPUInstanceBackend_Primary = (1 << 0) | (1 << 2) | (1 << 3) | (1 << 5);
// GL and DX11
static const WGPUInstanceBackend WGPUInstanceBackend_Secondary = (1 << 1) | (1 << 4);
static const WGPUInstanceBackend WGPUInstanceBackend_Force32 = 0x7FFFFFFF;
typedef enum WGPUInstanceFlag {
WGPUInstanceFlag_Default = 0x00000000,
WGPUInstanceFlag_Debug = 1 << 0,
WGPUInstanceFlag_Validation = 1 << 1,
WGPUInstanceFlag_DiscardHalLabels = 1 << 2,
WGPUInstanceFlag_Force32 = 0x7FFFFFFF
} WGPUInstanceFlag;
typedef WGPUFlags WGPUInstanceFlags;
typedef WGPUFlags WGPUInstanceFlag;
static const WGPUInstanceFlag WGPUInstanceFlag_Default = 0x00000000;
static const WGPUInstanceFlag WGPUInstanceFlag_Debug = 1 << 0;
static const WGPUInstanceFlag WGPUInstanceFlag_Validation = 1 << 1;
static const WGPUInstanceFlag WGPUInstanceFlag_DiscardHalLabels = 1 << 2;
static const WGPUInstanceFlag WGPUInstanceFlag_Force32 = 0x7FFFFFFF;
typedef enum WGPUDx12Compiler {
WGPUDx12Compiler_Undefined = 0x00000000,
@ -96,38 +118,50 @@ typedef enum WGPUNativeQueryType {
WGPUNativeQueryType_Force32 = 0x7FFFFFFF
} WGPUNativeQueryType WGPU_ENUM_ATTRIBUTE;
typedef enum WGPUDxcMaxShaderModel {
WGPUDxcMaxShaderModel_V6_0 = 0x00000000,
WGPUDxcMaxShaderModel_V6_1 = 0x00000001,
WGPUDxcMaxShaderModel_V6_2 = 0x00000002,
WGPUDxcMaxShaderModel_V6_3 = 0x00000003,
WGPUDxcMaxShaderModel_V6_4 = 0x00000004,
WGPUDxcMaxShaderModel_V6_5 = 0x00000005,
WGPUDxcMaxShaderModel_V6_6 = 0x00000006,
WGPUDxcMaxShaderModel_V6_7 = 0x00000007,
WGPUDxcMaxShaderModel_Force32 = 0x7FFFFFFF
} WGPUDxcMaxShaderModel;
typedef enum WGPUGLFenceBehaviour {
WGPUGLFenceBehaviour_Normal = 0x00000000,
WGPUGLFenceBehaviour_AutoFinish = 0x00000001,
WGPUGLFenceBehaviour_Force32 = 0x7FFFFFFF
} WGPUGLFenceBehaviour;
typedef struct WGPUInstanceExtras {
WGPUChainedStruct chain;
WGPUInstanceBackendFlags backends;
WGPUInstanceFlags flags;
WGPUInstanceBackend backends;
WGPUInstanceFlag flags;
WGPUDx12Compiler dx12ShaderCompiler;
WGPUGles3MinorVersion gles3MinorVersion;
const char * dxilPath;
const char * dxcPath;
WGPUGLFenceBehaviour glFenceBehaviour;
WGPUStringView dxilPath;
WGPUStringView dxcPath;
WGPUDxcMaxShaderModel dxcMaxShaderModel;
} WGPUInstanceExtras;
typedef struct WGPUDeviceExtras {
WGPUChainedStruct chain;
const char * tracePath;
WGPUStringView tracePath;
} WGPUDeviceExtras;
typedef struct WGPUNativeLimits {
/** This struct chain is used as mutable in some places and immutable in others. */
WGPUChainedStructOut chain;
uint32_t maxPushConstantSize;
uint32_t maxNonSamplerBindings;
} WGPUNativeLimits;
typedef struct WGPURequiredLimitsExtras {
WGPUChainedStruct chain;
WGPUNativeLimits limits;
} WGPURequiredLimitsExtras;
typedef struct WGPUSupportedLimitsExtras {
WGPUChainedStructOut chain;
WGPUNativeLimits limits;
} WGPUSupportedLimitsExtras;
typedef struct WGPUPushConstantRange {
WGPUShaderStageFlags stages;
WGPUShaderStage stages;
uint32_t start;
uint32_t end;
} WGPUPushConstantRange;
@ -140,29 +174,29 @@ typedef struct WGPUPipelineLayoutExtras {
typedef uint64_t WGPUSubmissionIndex;
typedef struct WGPUWrappedSubmissionIndex {
WGPUQueue queue;
WGPUSubmissionIndex submissionIndex;
} WGPUWrappedSubmissionIndex;
typedef struct WGPUShaderDefine {
char const * name;
char const * value;
WGPUStringView name;
WGPUStringView value;
} WGPUShaderDefine;
typedef struct WGPUShaderModuleGLSLDescriptor {
typedef struct WGPUShaderSourceGLSL {
WGPUChainedStruct chain;
WGPUShaderStage stage;
char const * code;
WGPUStringView code;
uint32_t defineCount;
WGPUShaderDefine * defines;
} WGPUShaderModuleGLSLDescriptor;
} WGPUShaderSourceGLSL;
typedef struct WGPUShaderModuleDescriptorSpirV {
WGPUStringView label;
uint32_t sourceSize;
uint32_t const * source;
} WGPUShaderModuleDescriptorSpirV;
typedef struct WGPURegistryReport {
size_t numAllocated;
size_t numKeptFromUser;
size_t numReleasedFromUser;
size_t numError;
size_t elementSize;
} WGPURegistryReport;
@ -178,6 +212,7 @@ typedef struct WGPUHubReport {
WGPURegistryReport renderBundles;
WGPURegistryReport renderPipelines;
WGPURegistryReport computePipelines;
WGPURegistryReport pipelineCaches;
WGPURegistryReport querySets;
WGPURegistryReport buffers;
WGPURegistryReport textures;
@ -187,16 +222,12 @@ typedef struct WGPUHubReport {
typedef struct WGPUGlobalReport {
WGPURegistryReport surfaces;
WGPUBackendType backendType;
WGPUHubReport vulkan;
WGPUHubReport metal;
WGPUHubReport dx12;
WGPUHubReport gl;
WGPUHubReport hub;
} WGPUGlobalReport;
typedef struct WGPUInstanceEnumerateAdapterOptions {
WGPUChainedStruct const * nextInChain;
WGPUInstanceBackendFlags backends;
WGPUInstanceBackend backends;
} WGPUInstanceEnumerateAdapterOptions;
typedef struct WGPUBindGroupEntryExtras {
@ -222,10 +253,22 @@ typedef struct WGPUQuerySetDescriptorExtras {
typedef struct WGPUSurfaceConfigurationExtras {
WGPUChainedStruct chain;
WGPUBool desiredMaximumFrameLatency;
uint32_t desiredMaximumFrameLatency;
} WGPUSurfaceConfigurationExtras WGPU_STRUCTURE_ATTRIBUTE;
typedef void (*WGPULogCallback)(WGPULogLevel level, char const * message, void * userdata);
typedef void (*WGPULogCallback)(WGPULogLevel level, WGPUStringView message, void * userdata);
typedef enum WGPUNativeTextureFormat {
// From Features::TEXTURE_FORMAT_16BIT_NORM
WGPUNativeTextureFormat_R16Unorm = 0x00030001,
WGPUNativeTextureFormat_R16Snorm = 0x00030002,
WGPUNativeTextureFormat_Rg16Unorm = 0x00030003,
WGPUNativeTextureFormat_Rg16Snorm = 0x00030004,
WGPUNativeTextureFormat_Rgba16Unorm = 0x00030005,
WGPUNativeTextureFormat_Rgba16Snorm = 0x00030006,
// From Features::TEXTURE_FORMAT_NV12
WGPUNativeTextureFormat_NV12 = 0x00030007,
} WGPUNativeTextureFormat;
#ifdef __cplusplus
extern "C" {
@ -237,7 +280,8 @@ size_t wgpuInstanceEnumerateAdapters(WGPUInstance instance, WGPU_NULLABLE WGPUIn
WGPUSubmissionIndex wgpuQueueSubmitForIndex(WGPUQueue queue, size_t commandCount, WGPUCommandBuffer const * commands);
// Returns true if the queue is empty, or false if there are more queue submissions still in flight.
WGPUBool wgpuDevicePoll(WGPUDevice device, WGPUBool wait, WGPU_NULLABLE WGPUWrappedSubmissionIndex const * wrappedSubmissionIndex);
WGPUBool wgpuDevicePoll(WGPUDevice device, WGPUBool wait, WGPU_NULLABLE WGPUSubmissionIndex const * submissionIndex);
WGPUShaderModule wgpuDeviceCreateShaderModuleSpirV(WGPUDevice device, WGPUShaderModuleDescriptorSpirV const * descriptor);
void wgpuSetLogCallback(WGPULogCallback callback, void * userdata);
@ -245,7 +289,9 @@ void wgpuSetLogLevel(WGPULogLevel level);
uint32_t wgpuGetVersion(void);
void wgpuRenderPassEncoderSetPushConstants(WGPURenderPassEncoder encoder, WGPUShaderStageFlags stages, uint32_t offset, uint32_t sizeBytes, void const * data);
void wgpuRenderPassEncoderSetPushConstants(WGPURenderPassEncoder encoder, WGPUShaderStage stages, uint32_t offset, uint32_t sizeBytes, void const * data);
void wgpuComputePassEncoderSetPushConstants(WGPUComputePassEncoder encoder, uint32_t offset, uint32_t sizeBytes, void const * data);
void wgpuRenderBundleEncoderSetPushConstants(WGPURenderBundleEncoder encoder, WGPUShaderStage stages, uint32_t offset, uint32_t sizeBytes, void const * data);
void wgpuRenderPassEncoderMultiDrawIndirect(WGPURenderPassEncoder encoder, WGPUBuffer buffer, uint64_t offset, uint32_t count);
void wgpuRenderPassEncoderMultiDrawIndexedIndirect(WGPURenderPassEncoder encoder, WGPUBuffer buffer, uint64_t offset, uint32_t count);
@ -258,6 +304,9 @@ void wgpuComputePassEncoderEndPipelineStatisticsQuery(WGPUComputePassEncoder com
void wgpuRenderPassEncoderBeginPipelineStatisticsQuery(WGPURenderPassEncoder renderPassEncoder, WGPUQuerySet querySet, uint32_t queryIndex);
void wgpuRenderPassEncoderEndPipelineStatisticsQuery(WGPURenderPassEncoder renderPassEncoder);
void wgpuComputePassEncoderWriteTimestamp(WGPUComputePassEncoder computePassEncoder, WGPUQuerySet querySet, uint32_t queryIndex);
void wgpuRenderPassEncoderWriteTimestamp(WGPURenderPassEncoder renderPassEncoder, WGPUQuerySet querySet, uint32_t queryIndex);
#ifdef __cplusplus
} // extern "C"
#endif

View file

@ -3,25 +3,28 @@
#include <psemek/wgpu/texture.hpp>
#include <psemek/wgpu/buffer.hpp>
#include <psemek/math/point.hpp>
#include <psemek/wgpu/chained_struct.hpp>
#include <vector>
namespace psemek::wgpu
{
struct image_copy_texture
struct texel_copy_texture_info
{
std::vector<chained_struct> chain = {};
struct texture texture;
std::uint32_t mip_level = 0;
math::point<std::uint32_t, 3> origin = {0, 0, 0};
texture::aspect aspect = texture::aspect::all;
};
struct image_copy_buffer {
std::vector<chained_struct> chain = {};
texture::data_layout layout;
struct texel_copy_buffer_layout
{
std::uint64_t offset = 0;
std::uint32_t bytes_per_row;
std::uint32_t rows_per_image;
};
struct texel_copy_buffer_info
{
texel_copy_buffer_layout layout;
struct buffer buffer;
};

View file

@ -13,6 +13,8 @@ namespace psemek::wgpu
{
using detail::object<instance>::object;
// TODO: add WGPUFuture stuff when it's supported in wgpu-native
struct descriptor
{
std::vector<chained_struct> chain = {};
@ -22,7 +24,7 @@ namespace psemek::wgpu
void process_events();
surface create_surface(surface::descriptor const & desc);
void request_adapter(adapter::request_options const & request_options, adapter::request_callback callback);
void request_adapter(callback_mode mode, adapter::request_options const & request_options, adapter::request_callback callback);
static void reference(void * ptr);
static void release(void * ptr);

View file

@ -16,8 +16,8 @@ namespace psemek::wgpu
enum class type : std::uint32_t
{
occlusion = 0x00000000,
timestamp = 0x00000001,
occlusion = 0x00000001,
timestamp = 0x00000002,
};
struct descriptor

View file

@ -5,6 +5,7 @@
#include <psemek/wgpu/buffer.hpp>
#include <psemek/wgpu/texture.hpp>
#include <psemek/wgpu/image_copy.hpp>
#include <psemek/wgpu/callback_mode.hpp>
#include <psemek/wgpu/detail/object.hpp>
#include <psemek/util/span.hpp>
@ -29,18 +30,18 @@ namespace psemek::wgpu
enum class work_done_status : std::uint32_t
{
success = 0x00000000,
error = 0x00000001,
unknown = 0x00000002,
device_lost = 0x00000003,
success = 0x00000001,
instance_dropped = 0x00000002,
error = 0x00000003,
unknown = 0x00000004,
};
using work_done_callback = std::function<void(work_done_status)>;
void submit(std::vector<command_buffer> const & commands);
void write_buffer(buffer const & buffer, std::uint64_t offset, util::span<char const> data);
void write_texture(image_copy_texture const & dest, util::span<char const> data, texture::data_layout const & data_layout, math::vector<std::uint32_t, 3> const & write_size);
void on_submitted_work_done(work_done_callback const & callback);
void write_texture(texel_copy_texture_info const & dest, util::span<char const> data, texel_copy_buffer_layout const & data_layout, math::vector<std::uint32_t, 3> const & write_size);
void on_submitted_work_done(callback_mode mode, work_done_callback const & callback);
void set_label(std::string const & label);
static void reference(void * ptr);

View file

@ -38,8 +38,8 @@ namespace psemek::wgpu
void draw_indexed(std::uint32_t index_count, std::uint32_t instance_count, std::uint32_t first_index, std::uint32_t base_vertex, std::uint32_t first_instance);
void draw_indirect(buffer const & indirect_buffer, std::uint64_t offset);
void draw_indexed_indirect(buffer const & indirect_buffer, std::uint64_t offset);
void insert_debug_marker(std::string const & marker_label);
void push_debug_group(std::string const & group_label);
void insert_debug_marker(std::string_view marker_label);
void push_debug_group(std::string_view group_label);
void pop_debug_group();
render_bundle finish(render_bundle::descriptor const & desc);
void set_label(std::string const & label);

View file

@ -21,15 +21,15 @@ namespace psemek::wgpu
enum class load_op : std::uint32_t
{
undefined = 0x00000000,
clear = 0x00000001,
load = 0x00000002,
load = 0x00000001,
clear = 0x00000002,
};
enum class store_op : std::uint32_t
{
undefined = 0x00000000,
store = 0x00000001,
discard = 0x00000002,
store = 0x00000001,
discard = 0x00000002,
};
struct render_pass_encoder
@ -41,6 +41,7 @@ namespace psemek::wgpu
{
std::vector<chained_struct> chain = {};
texture_view view;
std::uint32_t depth_slice = 0;
texture_view resolve_target = {};
enum load_op load_op;
enum store_op store_op;
@ -97,8 +98,9 @@ namespace psemek::wgpu
void execute_bundles(std::vector<render_bundle> const & bundles);
void begin_occlusion_query(std::uint32_t query_index);
void end_occlusion_query();
void insert_debug_marker(std::string const & marker_label);
void push_debug_group(std::string const & group_label);
void write_timestamp(query_set const & query_set, std::uint32_t query_index);
void insert_debug_marker(std::string_view marker_label);
void push_debug_group(std::string_view group_label);
void pop_debug_group();
void end();
void set_label(std::string const & label);

View file

@ -19,44 +19,55 @@ namespace psemek::wgpu
enum class vertex_step_mode : std::uint32_t
{
vertex = 0x00000000,
instance = 0x00000001,
vertex_buffer_not_used = 0x00000002,
vertex_buffer_not_used = 0x00000000,
undefined = 0x00000001,
vertex = 0x00000002,
instance = 0x00000003,
};
enum class vertex_format : std::uint32_t
{
undefined = 0x00000000,
uint8x2 = 0x00000001,
uint8x4 = 0x00000002,
sint8x2 = 0x00000003,
sint8x4 = 0x00000004,
unorm8x2 = 0x00000005,
unorm8x4 = 0x00000006,
snorm8x2 = 0x00000007,
snorm8x4 = 0x00000008,
uint16x2 = 0x00000009,
uint16x4 = 0x0000000a,
sint16x2 = 0x0000000b,
sint16x4 = 0x0000000c,
unorm16x2 = 0x0000000d,
unorm16x4 = 0x0000000e,
snorm16x2 = 0x0000000f,
snorm16x4 = 0x00000010,
float16x2 = 0x00000011,
float16x4 = 0x00000012,
float32 = 0x00000013,
float32x2 = 0x00000014,
float32x3 = 0x00000015,
float32x4 = 0x00000016,
uint32 = 0x00000017,
uint32x2 = 0x00000018,
uint32x3 = 0x00000019,
uint32x4 = 0x0000001a,
sint32 = 0x0000001b,
sint32x2 = 0x0000001c,
sint32x3 = 0x0000001d,
sint32x4 = 0x0000001e,
uint8 = 0x00000001,
uint8x2 = 0x00000002,
uint8x4 = 0x00000003,
sint8 = 0x00000004,
sint8x2 = 0x00000005,
sint8x4 = 0x00000006,
unorm8 = 0x00000007,
unorm8x2 = 0x00000008,
unorm8x4 = 0x00000009,
snorm8 = 0x0000000a,
snorm8x2 = 0x0000000b,
snorm8x4 = 0x0000000c,
uint16 = 0x0000000d,
uint16x2 = 0x0000000e,
uint16x4 = 0x0000000f,
sint16 = 0x00000010,
sint16x2 = 0x00000011,
sint16x4 = 0x00000012,
unorm16 = 0x00000013,
unorm16x2 = 0x00000014,
unorm16x4 = 0x00000015,
snorm16 = 0x00000016,
snorm16x2 = 0x00000017,
snorm16x4 = 0x00000018,
float16 = 0x00000019,
float16x2 = 0x0000001a,
float16x4 = 0x0000001b,
float32 = 0x0000001c,
float32x2 = 0x0000001d,
float32x3 = 0x0000001e,
float32x4 = 0x0000001f,
uint32 = 0x00000020,
uint32x2 = 0x00000021,
uint32x3 = 0x00000022,
uint32x4 = 0x00000023,
sint32 = 0x00000024,
sint32x2 = 0x00000025,
sint32x3 = 0x00000026,
sint32x4 = 0x00000027,
unorm10_10_10_2 = 0x00000028,
unorm8x4_bgra = 0x00000029,
};
struct vertex_attribute
@ -84,31 +95,34 @@ namespace psemek::wgpu
enum class primitive_topology : std::uint32_t
{
point_list = 0x00000000,
line_list = 0x00000001,
line_strip = 0x00000002,
triangle_list = 0x00000003,
triangle_strip = 0x00000004,
undefined = 0x00000000,
point_list = 0x00000001,
line_list = 0x00000002,
line_strip = 0x00000003,
triangle_list = 0x00000004,
triangle_strip = 0x00000005,
};
enum class index_format : std::uint32_t
{
undefined = 0x00000000,
uint16 = 0x00000001,
uint32 = 0x00000002,
uint16 = 0x00000001,
uint32 = 0x00000002,
};
enum class front_face : std::uint32_t
{
ccw = 0x00000000,
cw = 0x00000001,
undefined = 0x00000000,
ccw = 0x00000001,
cw = 0x00000002,
};
enum class cull_mode : std::uint32_t
{
none = 0x00000000,
front = 0x00000001,
back = 0x00000002,
undefined = 0x00000000,
none = 0x00000001,
front = 0x00000002,
back = 0x00000003,
};
struct primitive_state
@ -118,18 +132,20 @@ namespace psemek::wgpu
index_format strip_index_format = index_format::undefined;
enum front_face front_face;
enum cull_mode cull_mode;
bool clip_depth = true;
};
enum class stencil_operation : std::uint32_t
{
keep = 0x00000000,
zero = 0x00000001,
replace = 0x00000002,
invert = 0x00000003,
increment_clamp = 0x00000004,
decrement_clamp = 0x00000005,
increment_wrap = 0x00000006,
decrement_wrap = 0x00000007,
undefined = 0x00000000,
keep = 0x00000001,
zero = 0x00000002,
replace = 0x00000003,
invert = 0x00000004,
increment_clamp = 0x00000005,
decrement_clamp = 0x00000006,
increment_wrap = 0x00000007,
decrement_wrap = 0x00000008,
};
struct stencil_face_state
@ -144,8 +160,8 @@ namespace psemek::wgpu
{
std::vector<chained_struct> chain = {};
texture::format format;
bool depth_write = true;
compare_function depth_compare;
std::optional<bool> depth_write = true;
compare_function depth_compare = compare_function::always;
stencil_face_state stencil_front = {};
stencil_face_state stencil_back = {};
std::uint32_t stencil_read_mask = 0;
@ -165,28 +181,34 @@ namespace psemek::wgpu
enum class blend_operation : std::uint32_t
{
add = 0x00000000,
subtract = 0x00000001,
reverse_subtract = 0x00000002,
min = 0x00000003,
max = 0x00000004,
undefined = 0x00000000,
add = 0x00000001,
subtract = 0x00000002,
reverse_subtract = 0x00000003,
min = 0x00000004,
max = 0x00000005,
};
enum class blend_factor : std::uint32_t
{
zero = 0x00000000,
one = 0x00000001,
src = 0x00000002,
one_minus_src = 0x00000003,
src_alpha = 0x00000004,
one_minus_src_alpha = 0x00000005,
dst = 0x00000006,
one_minus_dst = 0x00000007,
dst_alpha = 0x00000008,
one_minus_dst_alpha = 0x00000009,
src_alpha_saturated = 0x0000000a,
constant = 0x0000000b,
one_minus_constant = 0x0000000c,
undefined = 0x00000000,
zero = 0x00000001,
one = 0x00000002,
src = 0x00000003,
one_minus_src = 0x00000004,
src_alpha = 0x00000005,
one_minus_src_alpha = 0x00000006,
dst = 0x00000007,
one_minus_dst = 0x00000008,
dst_alpha = 0x00000009,
one_minus_dst_alpha = 0x0000000a,
src_alpha_saturated = 0x0000000b,
constant = 0x0000000c,
one_minus_constant = 0x0000000d,
src1 = 0x0000000e,
one_minus_src1 = 0x0000000f,
src1_alpha = 0x00000010,
one_minus_src1_alpha = 0x00000011,
};
struct blend_component
@ -202,14 +224,14 @@ namespace psemek::wgpu
blend_component alpha;
};
enum color_write_mask : std::uint32_t
enum color_write_mask : std::uint64_t
{
none = 0x00000000,
red = 0x00000001,
none = 0x00000000,
red = 0x00000001,
green = 0x00000002,
blue = 0x00000004,
blue = 0x00000004,
alpha = 0x00000008,
all = 0x0000000f,
all = 0x0000000f,
};
struct color_target_state

View file

@ -13,34 +13,37 @@ namespace psemek::wgpu
enum class address_mode : std::uint32_t
{
repeat = 0x00000000,
mirror_repeat = 0x00000001,
clamp_to_edge = 0x00000002,
undefined = 0x00000000,
clamp_to_edge = 0x00000001,
repeat = 0x00000002,
mirror_repeat = 0x00000003,
};
enum class filter_mode : std::uint32_t
{
nearest = 0x00000000,
linear = 0x00000001,
undefined = 0x00000000,
nearest = 0x00000001,
linear = 0x00000002,
};
enum class mipmap_filter_mode : std::uint32_t
{
nearest = 0x00000000,
linear = 0x00000001,
undefined = 0x00000000,
nearest = 0x00000001,
linear = 0x00000002,
};
enum class compare_function : std::uint32_t
{
undefined = 0x00000000,
never = 0x00000001,
less = 0x00000002,
less_equal = 0x00000003,
greater = 0x00000004,
greater_equal = 0x00000005,
equal = 0x00000006,
not_equal = 0x00000007,
always = 0x00000008,
undefined = 0x00000000,
never = 0x00000001,
less = 0x00000002,
equal = 0x00000003,
less_equal = 0x00000004,
greater = 0x00000005,
not_equal = 0x00000006,
greater_equal = 0x00000007,
always = 0x00000008,
};
struct sampler

View file

@ -3,6 +3,7 @@
#include <psemek/wgpu/shader_stage.hpp>
#include <psemek/wgpu/chained_struct.hpp>
#include <psemek/wgpu/pipeline_layout.hpp>
#include <psemek/wgpu/callback_mode.hpp>
#include <psemek/wgpu/detail/object.hpp>
#include <psemek/util/span.hpp>
@ -21,17 +22,17 @@ namespace psemek::wgpu
enum class compilation_info_request_status : std::uint32_t
{
success = 0x00000000,
error = 0x00000001,
device_lost = 0x00000002,
unknown = 0x00000003,
success = 0x00000001,
instance_dropped = 0x00000002,
error = 0x00000003,
unknown = 0x00000004,
};
enum class compilation_message_type : std::uint32_t
{
error = 0x00000000,
warning = 0x00000001,
info = 0x00000002,
error = 0x00000001,
warning = 0x00000002,
info = 0x00000003,
};
struct compilation_message
@ -43,9 +44,6 @@ namespace psemek::wgpu
std::uint64_t line_pos;
std::uint64_t offset;
std::uint64_t length;
std::uint64_t utf16_line_pos;
std::uint64_t utf16_offset;
std::uint64_t utf16_length;
};
struct compilation_info
@ -54,24 +52,16 @@ namespace psemek::wgpu
std::vector<compilation_message> messages = {};
};
struct compilation_hint
{
std::vector<chained_struct> chain = {};
std::string entry_point;
pipeline_layout layout;
};
struct define
{
char const * name;
char const * value;
std::string_view name;
std::string_view value;
};
struct descriptor
{
std::vector<chained_struct> chain = {};
std::string label = {};
std::vector<compilation_hint> hints = {};
};
struct spirv_descriptor
@ -81,19 +71,19 @@ namespace psemek::wgpu
struct wgsl_descriptor
{
char const * code;
std::string_view code;
};
struct glsl_descriptor
{
shader_stage stage;
char const * code;
std::string_view code;
std::vector<define> defines = {};
};
using compilation_info_callback = std::function<void(compilation_info_request_status, compilation_info const &)>;
void get_compilation_info(compilation_info_callback const & callback);
void get_compilation_info(callback_mode mode, compilation_info_callback const & callback);
void set_label(std::string const & label);
static void reference(void * ptr);

View file

@ -5,17 +5,17 @@
namespace psemek::wgpu
{
enum class shader_stage : std::uint32_t
enum class shader_stage : std::uint64_t
{
none = 0x00000000,
vertex = 0x00000001,
none = 0x00000000,
vertex = 0x00000001,
fragment = 0x00000002,
compute = 0x00000004,
compute = 0x00000004,
};
inline shader_stage operator | (shader_stage s1, shader_stage s2)
{
return static_cast<shader_stage>(static_cast<std::uint32_t>(s1) | static_cast<std::uint32_t>(s2));
return static_cast<shader_stage>(static_cast<std::uint64_t>(s1) | static_cast<std::uint64_t>(s2));
}
}

View file

@ -27,19 +27,20 @@ namespace psemek::wgpu
enum class composite_alpha_mode : std::uint32_t
{
_auto = 0x00000000,
opaque = 0x00000001,
premultiplied = 0x00000002,
_auto = 0x00000000,
opaque = 0x00000001,
premultiplied = 0x00000002,
unpremultiplied = 0x00000003,
inherit = 0x00000004,
inherit = 0x00000004,
};
enum class present_mode : std::uint32_t
{
fifo = 0x00000000,
fifo_relaxed = 0x00000001,
immediate = 0x00000002,
mailbox = 0x00000003,
undefined = 0x00000000,
fifo = 0x00000001,
fifo_relaxed = 0x00000002,
immediate = 0x00000003,
mailbox = 0x00000004,
};
struct configuration
@ -63,6 +64,7 @@ namespace psemek::wgpu
struct capabilities
{
std::vector<chained_struct> chain = {};
texture::usage usage = texture::usage::none;
std::vector<texture::format> formats = {};
std::vector<present_mode> present_modes = {};
std::vector<composite_alpha_mode> alpha_modes = {};
@ -72,23 +74,23 @@ namespace psemek::wgpu
{
enum class status : std::uint32_t
{
success = 0x00000000,
timeout = 0x00000001,
outdated = 0x00000002,
lost = 0x00000003,
out_of_memory = 0x00000004,
device_lost = 0x00000005,
success_optimal = 0x00000001,
success_suboptimal = 0x00000002,
timeout = 0x00000003,
outdated = 0x00000004,
lost = 0x00000005,
out_of_memory = 0x00000006,
device_lost = 0x00000007,
error = 0x00000008,
};
wgpu::texture texture;
bool suboptimal;
enum status status;
};
void configure(configuration const & conf);
capabilities get_capabilities(adapter const & adapter);
current_texture get_current_texture();
wgpu::texture::format get_preferred_format(adapter const & adapter);
void present();
void unconfigure();
@ -97,11 +99,6 @@ namespace psemek::wgpu
void * window;
};
struct from_canvas_html_selected
{
std::string selector;
};
struct from_metal_layer
{
void * layer;
@ -144,7 +141,6 @@ namespace psemek::wgpu
detail::chained_struct_ptr to_chained_struct(surface::configuration::extras const & value);
detail::chained_struct_ptr to_chained_struct(surface::from_android_native_window const & value);
detail::chained_struct_ptr to_chained_struct(surface::from_canvas_html_selected const & value);
detail::chained_struct_ptr to_chained_struct(surface::from_metal_layer const & value);
detail::chained_struct_ptr to_chained_struct(surface::from_wayland_surface const & value);
detail::chained_struct_ptr to_chained_struct(surface::from_windows_hwnd const & value);

View file

@ -19,136 +19,150 @@ namespace psemek::wgpu
enum class format : std::uint32_t
{
undefined = 0x00000000,
r8unorm = 0x00000001,
r8snorm = 0x00000002,
r8uint = 0x00000003,
r8sint = 0x00000004,
r16uint = 0x00000005,
r16sint = 0x00000006,
r16float = 0x00000007,
rg8unorm = 0x00000008,
rg8snorm = 0x00000009,
rg8uint = 0x0000000a,
rg8sint = 0x0000000b,
r32float = 0x0000000c,
r32uint = 0x0000000d,
r32sint = 0x0000000e,
rg16uint = 0x0000000f,
rg16sint = 0x00000010,
rg16float = 0x00000011,
rgba8unorm = 0x00000012,
rgba8unorm_srgb = 0x00000013,
rgba8snorm = 0x00000014,
rgba8uint = 0x00000015,
rgba8sint = 0x00000016,
bgra8unorm = 0x00000017,
bgra8unorm_srgb = 0x00000018,
rgb10a2uint = 0x00000019,
rgb10a2unorm = 0x0000001a,
rg11b10ufloat = 0x0000001b,
rgb9e5ufloat = 0x0000001c,
rg32float = 0x0000001d,
rg32uint = 0x0000001e,
rg32sint = 0x0000001f,
rgba16uint = 0x00000020,
rgba16sint = 0x00000021,
rgba16float = 0x00000022,
rgba32float = 0x00000023,
rgba32uint = 0x00000024,
rgba32sint = 0x00000025,
stencil8 = 0x00000026,
depth16unorm = 0x00000027,
depth24plus = 0x00000028,
depth24plusstencil8 = 0x00000029,
depth32float = 0x0000002a,
undefined = 0x00000000,
r8unorm = 0x00000001,
r8snorm = 0x00000002,
r8uint = 0x00000003,
r8sint = 0x00000004,
r16uint = 0x00000005,
r16sint = 0x00000006,
r16float = 0x00000007,
rg8unorm = 0x00000008,
rg8snorm = 0x00000009,
rg8uint = 0x0000000a,
rg8sint = 0x0000000b,
r32float = 0x0000000c,
r32uint = 0x0000000d,
r32sint = 0x0000000e,
rg16uint = 0x0000000f,
rg16sint = 0x00000010,
rg16float = 0x00000011,
rgba8unorm = 0x00000012,
rgba8unorm_srgb = 0x00000013,
rgba8snorm = 0x00000014,
rgba8uint = 0x00000015,
rgba8sint = 0x00000016,
bgra8unorm = 0x00000017,
bgra8unorm_srgb = 0x00000018,
rgb10a2uint = 0x00000019,
rgb10a2unorm = 0x0000001a,
rg11b10ufloat = 0x0000001b,
rgb9e5ufloat = 0x0000001c,
rg32float = 0x0000001d,
rg32uint = 0x0000001e,
rg32sint = 0x0000001f,
rgba16uint = 0x00000020,
rgba16sint = 0x00000021,
rgba16float = 0x00000022,
rgba32float = 0x00000023,
rgba32uint = 0x00000024,
rgba32sint = 0x00000025,
stencil8 = 0x00000026,
depth16unorm = 0x00000027,
depth24plus = 0x00000028,
depth24plusstencil8 = 0x00000029,
depth32float = 0x0000002a,
depth32floatstencil8 = 0x0000002b,
bc1rgbaunorm = 0x0000002c,
bc1rgbaunorm_srgb = 0x0000002d,
bc2rgbaunorm = 0x0000002e,
bc2rgbaunorm_srgb = 0x0000002f,
bc3rgbaunorm = 0x00000030,
bc3rgbaunorm_srgb = 0x00000031,
bc4runorm = 0x00000032,
bc4rsnorm = 0x00000033,
bc5rgunorm = 0x00000034,
bc5rgsnorm = 0x00000035,
bc6hrgbufloat = 0x00000036,
bc6hrgbfloat = 0x00000037,
bc7rgbaunorm = 0x00000038,
bc7rgbaunorm_srgb = 0x00000039,
etc2rgb8unorm = 0x0000003a,
etc2rgb8unorm_srgb = 0x0000003b,
etc2rgb8a1unorm = 0x0000003c,
bc1rgbaunorm = 0x0000002c,
bc1rgbaunorm_srgb = 0x0000002d,
bc2rgbaunorm = 0x0000002e,
bc2rgbaunorm_srgb = 0x0000002f,
bc3rgbaunorm = 0x00000030,
bc3rgbaunorm_srgb = 0x00000031,
bc4runorm = 0x00000032,
bc4rsnorm = 0x00000033,
bc5rgunorm = 0x00000034,
bc5rgsnorm = 0x00000035,
bc6hrgbufloat = 0x00000036,
bc6hrgbfloat = 0x00000037,
bc7rgbaunorm = 0x00000038,
bc7rgbaunorm_srgb = 0x00000039,
etc2rgb8unorm = 0x0000003a,
etc2rgb8unorm_srgb = 0x0000003b,
etc2rgb8a1unorm = 0x0000003c,
etc2rgb8a1unorm_srgb = 0x0000003d,
etc2rgba8unorm = 0x0000003e,
etc2rgba8unorm_srgb = 0x0000003f,
eacr11unorm = 0x00000040,
eacr11snorm = 0x00000041,
eacrg11unorm = 0x00000042,
eacrg11snorm = 0x00000043,
astc4x4unorm = 0x00000044,
astc4x4unorm_srgb = 0x00000045,
astc5x4unorm = 0x00000046,
astc5x4unorm_srgb = 0x00000047,
astc5x5unorm = 0x00000048,
astc5x5unorm_srgb = 0x00000049,
astc6x5unorm = 0x0000004a,
astc6x5unorm_srgb = 0x0000004b,
astc6x6unorm = 0x0000004c,
astc6x6unorm_srgb = 0x0000004d,
astc8x5unorm = 0x0000004e,
astc8x5unorm_srgb = 0x0000004f,
astc8x6unorm = 0x00000050,
astc8x6unorm_srgb = 0x00000051,
astc8x8unorm = 0x00000052,
astc8x8unorm_srgb = 0x00000053,
astc10x5unorm = 0x00000054,
astc10x5unorm_srgb = 0x00000055,
astc10x6unorm = 0x00000056,
astc10x6unorm_srgb = 0x00000057,
astc10x8unorm = 0x00000058,
astc10x8unorm_srgb = 0x00000059,
astc10x10unorm = 0x0000005a,
astc10x10unorm_srgb = 0x0000005b,
astc12x10unorm = 0x0000005c,
astc12x10unorm_srgb = 0x0000005d,
astc12x12unorm = 0x0000005e,
astc12x12unorm_srgb = 0x0000005f,
etc2rgba8unorm = 0x0000003e,
etc2rgba8unorm_srgb = 0x0000003f,
eacr11unorm = 0x00000040,
eacr11snorm = 0x00000041,
eacrg11unorm = 0x00000042,
eacrg11snorm = 0x00000043,
astc4x4unorm = 0x00000044,
astc4x4unorm_srgb = 0x00000045,
astc5x4unorm = 0x00000046,
astc5x4unorm_srgb = 0x00000047,
astc5x5unorm = 0x00000048,
astc5x5unorm_srgb = 0x00000049,
astc6x5unorm = 0x0000004a,
astc6x5unorm_srgb = 0x0000004b,
astc6x6unorm = 0x0000004c,
astc6x6unorm_srgb = 0x0000004d,
astc8x5unorm = 0x0000004e,
astc8x5unorm_srgb = 0x0000004f,
astc8x6unorm = 0x00000050,
astc8x6unorm_srgb = 0x00000051,
astc8x8unorm = 0x00000052,
astc8x8unorm_srgb = 0x00000053,
astc10x5unorm = 0x00000054,
astc10x5unorm_srgb = 0x00000055,
astc10x6unorm = 0x00000056,
astc10x6unorm_srgb = 0x00000057,
astc10x8unorm = 0x00000058,
astc10x8unorm_srgb = 0x00000059,
astc10x10unorm = 0x0000005a,
astc10x10unorm_srgb = 0x0000005b,
astc12x10unorm = 0x0000005c,
astc12x10unorm_srgb = 0x0000005d,
astc12x12unorm = 0x0000005e,
astc12x12unorm_srgb = 0x0000005f,
// texture_format16bit_norm
r16unorm = 0x00030001,
r16snorm = 0x00030002,
rg16unorm = 0x00030003,
rg16snorm = 0x00030004,
rgba16unorm = 0x00030005,
rgba16snorm = 0x00030006,
// texture_format_nv12
nv12 = 0x00030007,
};
enum class usage : std::uint32_t
enum class usage : std::uint64_t
{
none = 0x00000000,
copy_src = 0x00000001,
copy_dst = 0x00000002,
texture_binding = 0x00000004,
storage_binding = 0x00000008,
none = 0x00000000,
copy_src = 0x00000001,
copy_dst = 0x00000002,
texture_binding = 0x00000004,
storage_binding = 0x00000008,
render_attachment = 0x00000010,
};
enum class dimension : std::uint32_t
{
_1d = 0x00000000,
_2d = 0x00000001,
_3d = 0x00000002,
undefined = 0x00000000,
_1d = 0x00000001,
_2d = 0x00000002,
_3d = 0x00000003,
};
enum class aspect : std::uint32_t
{
all = 0x00000000,
stencil_only = 0x00000001,
depth_only = 0x00000002,
undefined = 0x00000000,
all = 0x00000001,
stencil_only = 0x00000002,
depth_only = 0x00000003,
};
enum class sample_type : std::uint32_t
{
undefined = 0x00000000,
_float = 0x00000001,
unfilterable_float = 0x00000002,
depth = 0x00000003,
sint = 0x00000004,
uint = 0x00000005,
binding_not_used = 0x00000000,
undefined = 0x00000001,
_float = 0x00000002,
unfilterable_float = 0x00000003,
depth = 0x00000004,
sint = 0x00000005,
uint = 0x00000006,
};
struct descriptor
@ -164,14 +178,6 @@ namespace psemek::wgpu
std::vector<enum format> view_formats = {};
};
struct data_layout
{
std::vector<chained_struct> chain = {};
std::uint64_t offset = 0;
std::uint32_t bytes_per_row;
std::uint32_t rows_per_image;
};
texture_view create_view(texture_view::descriptor const & desc);
void destroy();
std::uint32_t get_width();

View file

@ -15,13 +15,13 @@ namespace psemek::wgpu
enum class dimension : std::uint32_t
{
undefined = 0x00000000,
_1d = 0x00000001,
_2d = 0x00000002,
_2d_array = 0x00000003,
cube = 0x00000004,
undefined = 0x00000000,
_1d = 0x00000001,
_2d = 0x00000002,
_2d_array = 0x00000003,
cube = 0x00000004,
cube_array = 0x00000005,
_3d = 0x00000006,
_3d = 0x00000006,
};
// Defined in wgpu/texture.hpp to break circular dependencies

View file

@ -1,4 +1,6 @@
#include <psemek/wgpu/adapter.hpp>
#include <psemek/wgpu/detail/string_view.hpp>
#include <psemek/wgpu/detail/status.hpp>
#include <psemek/wgpu/external/webgpu.h>
#include <cstring>
@ -8,37 +10,67 @@ namespace psemek::wgpu
std::vector<feature> adapter::enumerate_features()
{
std::size_t count = wgpuAdapterEnumerateFeatures((WGPUAdapter)get(), nullptr);
std::vector<feature> result(count);
wgpuAdapterEnumerateFeatures((WGPUAdapter)get(), (WGPUFeatureName *)result.data());
return result;
WGPUSupportedFeatures supported_features;
wgpuAdapterGetFeatures((WGPUAdapter)get(), &supported_features);
return std::vector<feature>((feature const *)supported_features.features, (feature const *)(supported_features.features) + supported_features.featureCount);
}
limits adapter::get_limits()
{
WGPUSupportedLimits limits = {};
wgpuAdapterGetLimits((WGPUAdapter)get(), &limits);
WGPULimits limits = {};
detail::check_status("wgpuAdapterGetLimits", wgpuAdapterGetLimits((WGPUAdapter)get(), &limits));
// TODO: support out chain
wgpu::limits result;
static_assert(sizeof(result) == sizeof(limits.limits));
std::memcpy((char *)&result, (char *)&limits.limits, sizeof(result));
result.max_texture_dimension_1D = limits.maxTextureDimension1D;
result.max_texture_dimension_2D = limits.maxTextureDimension2D;
result.max_texture_dimension_3D = limits.maxTextureDimension3D;
result.max_texture_array_layers = limits.maxTextureArrayLayers;
result.max_bind_groups = limits.maxBindGroups;
result.max_bind_groups_plus_vertex_buffers = limits.maxBindGroupsPlusVertexBuffers;
result.max_bindings_per_bind_group = limits.maxBindingsPerBindGroup;
result.max_dynamic_uniform_buffers_per_pipeline_layout = limits.maxDynamicUniformBuffersPerPipelineLayout;
result.max_dynamic_storage_buffers_per_pipeline_layout = limits.maxDynamicStorageBuffersPerPipelineLayout;
result.max_sampled_textures_per_shader_stage = limits.maxSampledTexturesPerShaderStage;
result.max_samplers_per_shader_stage = limits.maxSamplersPerShaderStage;
result.max_storage_buffers_per_shader_stage = limits.maxStorageBuffersPerShaderStage;
result.max_storage_textures_per_shader_stage = limits.maxStorageTexturesPerShaderStage;
result.max_uniform_buffers_per_shader_stage = limits.maxUniformBuffersPerShaderStage;
result.max_uniform_buffer_binding_size = limits.maxUniformBufferBindingSize;
result.max_storage_buffer_binding_size = limits.maxStorageBufferBindingSize;
result.min_uniform_buffer_offset_alignment = limits.minUniformBufferOffsetAlignment;
result.min_storage_buffer_offset_alignment = limits.minStorageBufferOffsetAlignment;
result.max_vertex_buffers = limits.maxVertexBuffers;
result.max_buffer_size = limits.maxBufferSize;
result.max_vertex_attributes = limits.maxVertexAttributes;
result.max_vertex_buffer_array_stride = limits.maxVertexBufferArrayStride;
result.max_inter_stage_shader_variables = limits.maxInterStageShaderVariables;
result.max_color_attachments = limits.maxColorAttachments;
result.max_color_attachment_bytes_per_sample = limits.maxColorAttachmentBytesPerSample;
result.max_compute_workgroup_storage_size = limits.maxComputeWorkgroupStorageSize;
result.max_compute_invocations_per_workgroup = limits.maxComputeInvocationsPerWorkgroup;
result.max_compute_workgroup_size_x = limits.maxComputeWorkgroupSizeX;
result.max_compute_workgroup_size_y = limits.maxComputeWorkgroupSizeY;
result.max_compute_workgroup_size_z = limits.maxComputeWorkgroupSizeZ;
result.max_compute_workgroups_per_dimension = limits.maxComputeWorkgroupsPerDimension;
return result;
}
adapter::properties adapter::get_properties()
adapter::info adapter::get_info()
{
WGPUAdapterProperties props;
wgpuAdapterGetProperties((WGPUAdapter)get(), &props);
WGPUAdapterInfo info;
detail::check_status("wgpuAdapterGetInfo", wgpuAdapterGetInfo((WGPUAdapter)get(), &info));
return {
.vendor_id = props.vendorID,
.vendor_name = props.vendorName,
.architecture = props.architecture,
.device_id = props.deviceID,
.name = props.name,
.driver_description = props.driverDescription,
.adapter_type = (adapter::type)props.adapterType,
.backend_type = (backend_type)props.backendType,
.vendor = std::string_view(info.vendor.data, info.vendor.length),
.architecture = std::string_view(info.architecture.data, info.architecture.length),
.device = std::string_view(info.device.data, info.device.length),
.description = std::string_view(info.description.data, info.description.length),
.backend_type = (backend_type)info.backendType,
.adapter_type = (type)info.adapterType,
.vendor_id = info.vendorID,
.device_id = info.deviceID,
};
}
@ -47,49 +79,83 @@ namespace psemek::wgpu
return wgpuAdapterHasFeature((WGPUAdapter)get(), (WGPUFeatureName)feature);
}
void adapter::request_device(device::descriptor const & descriptor, device::request_callback const & callback)
void adapter::request_device(callback_mode mode, device::descriptor const & descriptor, device::request_callback const & callback)
{
WGPURequiredLimits limits = {};
WGPULimits limits = {};
if (descriptor.required_limits)
{
static_assert(sizeof(limits.limits) == sizeof(descriptor.required_limits->limits));
limits.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(descriptor.required_limits->chain);
std::memcpy(&limits.limits, &descriptor.required_limits->limits, sizeof(limits.limits));
limits.nextInChain = (WGPUChainedStructOut *)detail::fill_chain_out(descriptor.required_limits->chain);
limits.maxTextureDimension1D = descriptor.required_limits->limits.max_texture_dimension_1D;
limits.maxTextureDimension2D = descriptor.required_limits->limits.max_texture_dimension_2D;
limits.maxTextureDimension3D = descriptor.required_limits->limits.max_texture_dimension_3D;
limits.maxTextureArrayLayers = descriptor.required_limits->limits.max_texture_array_layers;
limits.maxBindGroups = descriptor.required_limits->limits.max_bind_groups;
limits.maxBindGroupsPlusVertexBuffers = descriptor.required_limits->limits.max_bind_groups_plus_vertex_buffers;
limits.maxBindingsPerBindGroup = descriptor.required_limits->limits.max_bindings_per_bind_group;
limits.maxDynamicUniformBuffersPerPipelineLayout = descriptor.required_limits->limits.max_dynamic_uniform_buffers_per_pipeline_layout;
limits.maxDynamicStorageBuffersPerPipelineLayout = descriptor.required_limits->limits.max_dynamic_storage_buffers_per_pipeline_layout;
limits.maxSampledTexturesPerShaderStage = descriptor.required_limits->limits.max_sampled_textures_per_shader_stage;
limits.maxSamplersPerShaderStage = descriptor.required_limits->limits.max_samplers_per_shader_stage;
limits.maxStorageBuffersPerShaderStage = descriptor.required_limits->limits.max_storage_buffers_per_shader_stage;
limits.maxStorageTexturesPerShaderStage = descriptor.required_limits->limits.max_storage_textures_per_shader_stage;
limits.maxUniformBuffersPerShaderStage = descriptor.required_limits->limits.max_uniform_buffers_per_shader_stage;
limits.maxUniformBufferBindingSize = descriptor.required_limits->limits.max_uniform_buffer_binding_size;
limits.maxStorageBufferBindingSize = descriptor.required_limits->limits.max_storage_buffer_binding_size;
limits.minUniformBufferOffsetAlignment = descriptor.required_limits->limits.min_uniform_buffer_offset_alignment;
limits.minStorageBufferOffsetAlignment = descriptor.required_limits->limits.min_storage_buffer_offset_alignment;
limits.maxVertexBuffers = descriptor.required_limits->limits.max_vertex_buffers;
limits.maxBufferSize = descriptor.required_limits->limits.max_buffer_size;
limits.maxVertexAttributes = descriptor.required_limits->limits.max_vertex_attributes;
limits.maxVertexBufferArrayStride = descriptor.required_limits->limits.max_vertex_buffer_array_stride;
limits.maxInterStageShaderVariables = descriptor.required_limits->limits.max_inter_stage_shader_variables;
limits.maxColorAttachments = descriptor.required_limits->limits.max_color_attachments;
limits.maxColorAttachmentBytesPerSample = descriptor.required_limits->limits.max_color_attachment_bytes_per_sample;
limits.maxComputeWorkgroupStorageSize = descriptor.required_limits->limits.max_compute_workgroup_storage_size;
limits.maxComputeInvocationsPerWorkgroup = descriptor.required_limits->limits.max_compute_invocations_per_workgroup;
limits.maxComputeWorkgroupSizeX = descriptor.required_limits->limits.max_compute_workgroup_size_x;
limits.maxComputeWorkgroupSizeY = descriptor.required_limits->limits.max_compute_workgroup_size_y;
limits.maxComputeWorkgroupSizeZ = descriptor.required_limits->limits.max_compute_workgroup_size_z;
limits.maxComputeWorkgroupsPerDimension = descriptor.required_limits->limits.max_compute_workgroups_per_dimension;
}
auto device_lost_userdata = new device::lost_callback(descriptor.lost_callback);
auto device_lost_real_callback = [](WGPUDeviceLostReason reason, char const * message, void * userdata)
{
std::unique_ptr<device::lost_callback> callback((device::lost_callback *)userdata);
if (*callback) (*callback)((device::lost_reason)reason, message ? message : "");
};
WGPUDeviceDescriptor device_desc = {};
device_desc.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(descriptor.chain);
device_desc.label = descriptor.label.data();
device_desc.label = detail::to_string_view(descriptor.label);
device_desc.requiredFeatureCount = descriptor.required_features.size();
device_desc.requiredFeatures = (WGPUFeatureName const *)descriptor.required_features.data();
device_desc.requiredLimits = descriptor.required_limits ? &limits : nullptr;
device_desc.defaultQueue.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(descriptor.default_queue.chain);
device_desc.defaultQueue.label = descriptor.default_queue.label.data();
device_desc.deviceLostCallback = device_lost_real_callback;
device_desc.deviceLostUserdata = device_lost_userdata;
device_desc.defaultQueue.label = detail::to_string_view(descriptor.default_queue.label);
device_desc.deviceLostCallbackInfo.mode = (WGPUCallbackMode)descriptor.lost_callback_mode;
device_desc.deviceLostCallbackInfo.callback = [](WGPUDevice const *, WGPUDeviceLostReason reason, WGPUStringView message, void * userdata, void *)
{
std::unique_ptr<device::lost_callback> callback{(device::lost_callback *)userdata};
if (*callback) (*callback)((device::lost_reason)reason, std::string(message.data, message.length));
};
device_desc.deviceLostCallbackInfo.userdata1 = new device::lost_callback(descriptor.lost_callback);
device_desc.uncapturedErrorCallbackInfo.callback = [](WGPUDevice const *, WGPUErrorType type, WGPUStringView message, void * userdata, void *)
{
auto callback = (device::uncaptured_error_callback *)userdata;
if (*callback) (*callback)((error_type)type, std::string(message.data, message.length));
};
device_desc.uncapturedErrorCallbackInfo.userdata1 = new device::uncaptured_error_callback(descriptor.uncaptured_error_callback);
auto userdata = new device::request_callback(callback);
auto real_callback = [](WGPURequestDeviceStatus status, WGPUDevice device, char const * message, void * userdata)
WGPURequestDeviceCallbackInfo callback_info = {};
callback_info.mode = (WGPUCallbackMode)mode;
callback_info.callback = [](WGPURequestDeviceStatus status, WGPUDevice device, WGPUStringView message, void * userdata, void *)
{
std::unique_ptr<device::request_callback> callback{(device::request_callback *)userdata};
if (*callback) (*callback)((device::request_status)status, wgpu::device(device), message ? message : "");
if (*callback) (*callback)((device::request_status)status, wgpu::device(device), std::string(message.data, message.length));
};
callback_info.userdata1 = new device::request_callback(callback);
wgpuAdapterRequestDevice((WGPUAdapter)get(), &device_desc, real_callback, userdata);
wgpuAdapterRequestDevice((WGPUAdapter)get(), &device_desc, callback_info);
}
void adapter::reference(void * ptr)
{
wgpuAdapterReference((WGPUAdapter)ptr);
wgpuAdapterAddRef((WGPUAdapter)ptr);
}
void adapter::release(void * ptr)

View file

@ -1,4 +1,5 @@
#include <psemek/wgpu/bind_group.hpp>
#include <psemek/wgpu/detail/string_view.hpp>
#include <psemek/wgpu/external/webgpu.h>
namespace psemek::wgpu
@ -6,12 +7,12 @@ namespace psemek::wgpu
void bind_group::set_label(std::string const & label)
{
wgpuBindGroupSetLabel((WGPUBindGroup)get(), label.data());
wgpuBindGroupSetLabel((WGPUBindGroup)get(), detail::to_string_view(label));
}
void bind_group::reference(void * ptr)
{
wgpuBindGroupReference((WGPUBindGroup)ptr);
wgpuBindGroupAddRef((WGPUBindGroup)ptr);
}
void bind_group::release(void * ptr)

View file

@ -1,4 +1,5 @@
#include <psemek/wgpu/bind_group_layout.hpp>
#include <psemek/wgpu/detail/string_view.hpp>
#include <psemek/wgpu/external/webgpu.h>
namespace psemek::wgpu
@ -6,12 +7,12 @@ namespace psemek::wgpu
void bind_group_layout::set_label(std::string const & label)
{
wgpuBindGroupLayoutSetLabel((WGPUBindGroupLayout)get(), label.data());
wgpuBindGroupLayoutSetLabel((WGPUBindGroupLayout)get(), detail::to_string_view(label));
}
void bind_group_layout::reference(void * ptr)
{
wgpuBindGroupLayoutReference((WGPUBindGroupLayout)ptr);
wgpuBindGroupLayoutAddRef((WGPUBindGroupLayout)ptr);
}
void bind_group_layout::release(void * ptr)

View file

@ -1,4 +1,5 @@
#include <psemek/wgpu/buffer.hpp>
#include <psemek/wgpu/detail/string_view.hpp>
#include <psemek/wgpu/external/webgpu.h>
#include <memory>
@ -36,17 +37,18 @@ namespace psemek::wgpu
return wgpuBufferGetMappedRange((WGPUBuffer)get(), offset, size);
}
void buffer::map_async(map_mode flags, std::size_t offset, std::size_t size, map_callback const & callback)
void buffer::map_async(callback_mode mode, map_mode flags, std::size_t offset, std::size_t size, map_callback const & callback)
{
auto userdata = new map_callback(callback);
auto real_callback = [](WGPUBufferMapAsyncStatus status, void * userdata)
WGPUBufferMapCallbackInfo callback_info = {};
callback_info.mode = (WGPUCallbackMode)mode;
callback_info.callback = [](WGPUMapAsyncStatus status, WGPUStringView message, void * userdata, void *)
{
std::unique_ptr<map_callback> callback((map_callback *)userdata);
if (*callback) (*callback)((map_async_status)status);
if (*callback) (*callback)((map_async_status)status, std::string_view(message.data, message.length));
};
callback_info.userdata1 = new map_callback(callback);
wgpuBufferMapAsync((WGPUBuffer)get(), (WGPUMapModeFlags)flags, offset, size, real_callback, userdata);
wgpuBufferMapAsync((WGPUBuffer)get(), (WGPUMapMode)flags, offset, size, callback_info);
}
void buffer::unmap()
@ -56,12 +58,12 @@ namespace psemek::wgpu
void buffer::set_label(std::string const & label)
{
wgpuBufferSetLabel((WGPUBuffer)get(), label.data());
wgpuBufferSetLabel((WGPUBuffer)get(), detail::to_string_view(label));
}
void buffer::reference(void * ptr)
{
wgpuBufferReference((WGPUBuffer)ptr);
wgpuBufferAddRef((WGPUBuffer)ptr);
}
void buffer::release(void * ptr)

View file

@ -30,4 +30,30 @@ namespace psemek::wgpu::detail
return first;
}
void * fill_chain_out(std::vector<chained_struct> const & chain)
{
WGPUChainedStructOut * first = nullptr;
WGPUChainedStructOut * current = nullptr;
for (auto const & s : chain)
{
auto p = (WGPUChainedStructOut *)s.ptr();
if (!first)
{
first = p;
current = p;
}
else
{
current->next = p;
current = p;
}
}
if (current)
current->next = nullptr;
return first;
}
}

View file

@ -1,4 +1,5 @@
#include <psemek/wgpu/command_buffer.hpp>
#include <psemek/wgpu/detail/string_view.hpp>
#include <psemek/wgpu/external/webgpu.h>
namespace psemek::wgpu
@ -6,12 +7,12 @@ namespace psemek::wgpu
void command_buffer::set_label(std::string const & label)
{
wgpuCommandBufferSetLabel((WGPUCommandBuffer)get(), label.data());
wgpuCommandBufferSetLabel((WGPUCommandBuffer)get(), detail::to_string_view(label));
}
void command_buffer::reference(void * ptr)
{
wgpuCommandBufferReference((WGPUCommandBuffer)ptr);
wgpuCommandBufferAddRef((WGPUCommandBuffer)ptr);
}
void command_buffer::release(void * ptr)

View file

@ -1,4 +1,5 @@
#include <psemek/wgpu/command_encoder.hpp>
#include <psemek/wgpu/detail/string_view.hpp>
#include <psemek/wgpu/external/webgpu.h>
namespace psemek::wgpu
@ -16,7 +17,7 @@ namespace psemek::wgpu
WGPUComputePassDescriptor descriptor = {};
descriptor.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.chain);
descriptor.label = desc.label.data();
descriptor.label = detail::to_string_view(desc.label);
descriptor.timestampWrites = desc.timestamp_writes ? &timestamp_writes : nullptr;
return compute_pass_encoder(wgpuCommandEncoderBeginComputePass((WGPUCommandEncoder)get(), &descriptor));
@ -30,6 +31,7 @@ namespace psemek::wgpu
auto & dst = color_attachments.emplace_back();
dst.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(src.chain);
dst.view = (WGPUTextureView)src.view.get();
dst.depthSlice = src.depth_slice;
dst.resolveTarget = (WGPUTextureView)src.resolve_target.get();
dst.loadOp = (WGPULoadOp)src.load_op;
dst.storeOp = (WGPUStoreOp)src.store_op;
@ -43,11 +45,11 @@ namespace psemek::wgpu
depth_stencil_attachment.depthLoadOp = (WGPULoadOp)desc.depth_stencil_attachment->depth_load_op;
depth_stencil_attachment.depthStoreOp = (WGPUStoreOp)desc.depth_stencil_attachment->depth_store_op;
depth_stencil_attachment.depthClearValue = desc.depth_stencil_attachment->depth_clear_value;
depth_stencil_attachment.depthReadOnly = desc.depth_stencil_attachment->depth_read_only;
depth_stencil_attachment.depthReadOnly = desc.depth_stencil_attachment->depth_read_only ? 1 : 0;
depth_stencil_attachment.stencilLoadOp = (WGPULoadOp)desc.depth_stencil_attachment->stencil_load_op;
depth_stencil_attachment.stencilStoreOp = (WGPUStoreOp)desc.depth_stencil_attachment->stencil_store_op;
depth_stencil_attachment.stencilClearValue = desc.depth_stencil_attachment->stencil_clear_value;
depth_stencil_attachment.stencilReadOnly = desc.depth_stencil_attachment->stencil_clear_value;
depth_stencil_attachment.stencilReadOnly = desc.depth_stencil_attachment->stencil_read_only ? 1 : 0;
}
WGPURenderPassTimestampWrites timestamp_writes = {};
@ -60,7 +62,7 @@ namespace psemek::wgpu
WGPURenderPassDescriptor descriptor = {};
descriptor.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.chain);
descriptor.label = desc.label.data();
descriptor.label = detail::to_string_view(desc.label);
descriptor.colorAttachmentCount = color_attachments.size();
descriptor.colorAttachments = color_attachments.data();
descriptor.depthStencilAttachment = desc.depth_stencil_attachment ? &depth_stencil_attachment : nullptr;
@ -80,73 +82,65 @@ namespace psemek::wgpu
wgpuCommandEncoderCopyBufferToBuffer((WGPUCommandEncoder)get(), (WGPUBuffer)source.get(), source_offset, (WGPUBuffer)destination.get(), destination_offset, size);
}
void command_encoder::copy_buffer_to_texture(image_copy_buffer const & source, image_copy_texture const & destination, math::vector<std::uint32_t, 3> const & extent)
void command_encoder::copy_buffer_to_texture(texel_copy_buffer_info const & source, texel_copy_texture_info const & destination, math::vector<std::uint32_t, 3> const & extent)
{
WGPUImageCopyBuffer image_copy_src = {};
image_copy_src.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(source.chain);
image_copy_src.layout.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(source.layout.chain);
image_copy_src.layout.offset = source.layout.offset;
image_copy_src.layout.bytesPerRow = source.layout.bytes_per_row;
image_copy_src.layout.rowsPerImage = source.layout.rows_per_image;
image_copy_src.buffer = (WGPUBuffer)source.buffer.get();
WGPUTexelCopyBufferInfo texel_copy_buffer_info_src = {};
texel_copy_buffer_info_src.layout.offset = source.layout.offset;
texel_copy_buffer_info_src.layout.bytesPerRow = source.layout.bytes_per_row;
texel_copy_buffer_info_src.layout.rowsPerImage = source.layout.rows_per_image;
texel_copy_buffer_info_src.buffer = (WGPUBuffer)source.buffer.get();
WGPUImageCopyTexture image_copy_dst = {};
image_copy_dst.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(destination.chain);
image_copy_dst.texture = (WGPUTexture)destination.texture.get();
image_copy_dst.mipLevel = destination.mip_level;
image_copy_dst.origin = {destination.origin[0], destination.origin[1], destination.origin[2]};
image_copy_dst.aspect = (WGPUTextureAspect)destination.aspect;
WGPUTexelCopyTextureInfo texel_copy_texture_info_src_dst = {};
texel_copy_texture_info_src_dst.texture = (WGPUTexture)destination.texture.get();
texel_copy_texture_info_src_dst.mipLevel = destination.mip_level;
texel_copy_texture_info_src_dst.origin = {destination.origin[0], destination.origin[1], destination.origin[2]};
texel_copy_texture_info_src_dst.aspect = (WGPUTextureAspect)destination.aspect;
wgpuCommandEncoderCopyBufferToTexture((WGPUCommandEncoder)get(), &image_copy_src, &image_copy_dst, (WGPUExtent3D const *)(&extent));
wgpuCommandEncoderCopyBufferToTexture((WGPUCommandEncoder)get(), &texel_copy_buffer_info_src, &texel_copy_texture_info_src_dst, (WGPUExtent3D const *)(&extent));
}
void command_encoder::copy_texture_to_buffer(image_copy_texture const & source, image_copy_buffer const & destination, math::vector<std::uint32_t, 3> const & extent)
void command_encoder::copy_texture_to_buffer(texel_copy_texture_info const & source, texel_copy_buffer_info const & destination, math::vector<std::uint32_t, 3> const & extent)
{
WGPUImageCopyTexture image_copy_src = {};
image_copy_src.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(source.chain);
image_copy_src.texture = (WGPUTexture)source.texture.get();
image_copy_src.mipLevel = source.mip_level;
image_copy_src.origin = {source.origin[0], source.origin[1], source.origin[2]};
image_copy_src.aspect = (WGPUTextureAspect)source.aspect;
WGPUTexelCopyTextureInfo texel_copy_texture_info_src = {};
texel_copy_texture_info_src.texture = (WGPUTexture)source.texture.get();
texel_copy_texture_info_src.mipLevel = source.mip_level;
texel_copy_texture_info_src.origin = {source.origin[0], source.origin[1], source.origin[2]};
texel_copy_texture_info_src.aspect = (WGPUTextureAspect)source.aspect;
WGPUImageCopyBuffer image_copy_dst = {};
image_copy_dst.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(destination.chain);
image_copy_dst.layout.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(destination.layout.chain);
image_copy_dst.layout.offset = destination.layout.offset;
image_copy_dst.layout.bytesPerRow = destination.layout.bytes_per_row;
image_copy_dst.layout.rowsPerImage = destination.layout.rows_per_image;
image_copy_dst.buffer = (WGPUBuffer)destination.buffer.get();
WGPUTexelCopyBufferInfo texel_copy_buffer_info_dst = {};
texel_copy_buffer_info_dst.layout.offset = destination.layout.offset;
texel_copy_buffer_info_dst.layout.bytesPerRow = destination.layout.bytes_per_row;
texel_copy_buffer_info_dst.layout.rowsPerImage = destination.layout.rows_per_image;
texel_copy_buffer_info_dst.buffer = (WGPUBuffer)destination.buffer.get();
wgpuCommandEncoderCopyTextureToBuffer((WGPUCommandEncoder)get(), &image_copy_src, &image_copy_dst, (WGPUExtent3D const *)(&extent));
wgpuCommandEncoderCopyTextureToBuffer((WGPUCommandEncoder)get(), &texel_copy_texture_info_src, &texel_copy_buffer_info_dst, (WGPUExtent3D const *)(&extent));
}
void command_encoder::copy_texture_to_texture(image_copy_texture const & source, image_copy_texture const & destination, math::vector<std::uint32_t, 3> const & extent)
void command_encoder::copy_texture_to_texture(texel_copy_texture_info const & source, texel_copy_texture_info const & destination, math::vector<std::uint32_t, 3> const & extent)
{
WGPUImageCopyTexture image_copy_src = {};
image_copy_src.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(source.chain);
image_copy_src.texture = (WGPUTexture)source.texture.get();
image_copy_src.mipLevel = source.mip_level;
image_copy_src.origin = {source.origin[0], source.origin[1], source.origin[2]};
image_copy_src.aspect = (WGPUTextureAspect)source.aspect;
WGPUTexelCopyTextureInfo texel_copy_texture_info_src = {};
texel_copy_texture_info_src.texture = (WGPUTexture)source.texture.get();
texel_copy_texture_info_src.mipLevel = source.mip_level;
texel_copy_texture_info_src.origin = {source.origin[0], source.origin[1], source.origin[2]};
texel_copy_texture_info_src.aspect = (WGPUTextureAspect)source.aspect;
WGPUImageCopyTexture image_copy_dst = {};
image_copy_dst.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(destination.chain);
image_copy_dst.texture = (WGPUTexture)destination.texture.get();
image_copy_dst.mipLevel = destination.mip_level;
image_copy_dst.origin = {destination.origin[0], destination.origin[1], destination.origin[2]};
image_copy_dst.aspect = (WGPUTextureAspect)destination.aspect;
WGPUTexelCopyTextureInfo texel_copy_texture_info_dst = {};
texel_copy_texture_info_dst.texture = (WGPUTexture)destination.texture.get();
texel_copy_texture_info_dst.mipLevel = destination.mip_level;
texel_copy_texture_info_dst.origin = {destination.origin[0], destination.origin[1], destination.origin[2]};
texel_copy_texture_info_dst.aspect = (WGPUTextureAspect)destination.aspect;
wgpuCommandEncoderCopyTextureToTexture((WGPUCommandEncoder)get(), &image_copy_src, &image_copy_dst, (WGPUExtent3D const *)(&extent));
wgpuCommandEncoderCopyTextureToTexture((WGPUCommandEncoder)get(), &texel_copy_texture_info_src, &texel_copy_texture_info_dst, (WGPUExtent3D const *)(&extent));
}
void command_encoder::insert_debug_marker(std::string const & marker_label)
{
wgpuCommandEncoderInsertDebugMarker((WGPUCommandEncoder)get(), marker_label.data());
wgpuCommandEncoderInsertDebugMarker((WGPUCommandEncoder)get(), detail::to_string_view(marker_label));
}
void command_encoder::push_debug_group(std::string const & group_label)
{
wgpuCommandEncoderPushDebugGroup((WGPUCommandEncoder)get(), group_label.data());
wgpuCommandEncoderPushDebugGroup((WGPUCommandEncoder)get(), detail::to_string_view(group_label));
}
void command_encoder::pop_debug_group()
@ -168,18 +162,18 @@ namespace psemek::wgpu
{
WGPUCommandBufferDescriptor descriptor = {};
descriptor.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.chain);
descriptor.label = desc.label.data();
descriptor.label = detail::to_string_view(desc.label);
return command_buffer(wgpuCommandEncoderFinish((WGPUCommandEncoder)get(), &descriptor));
}
void command_encoder::set_label(std::string const & label)
{
wgpuCommandEncoderSetLabel((WGPUCommandEncoder)get(), label.data());
wgpuCommandEncoderSetLabel((WGPUCommandEncoder)get(), detail::to_string_view(label));
}
void command_encoder::reference(void * ptr)
{
wgpuCommandEncoderReference((WGPUCommandEncoder)ptr);
wgpuCommandEncoderAddRef((WGPUCommandEncoder)ptr);
}
void command_encoder::release(void * ptr)

View file

@ -1,5 +1,7 @@
#include <psemek/wgpu/compute_pass_encoder.hpp>
#include <psemek/wgpu/detail/string_view.hpp>
#include <psemek/wgpu/external/webgpu.h>
#include <psemek/wgpu/external/wgpu.h>
namespace psemek::wgpu
{
@ -24,14 +26,24 @@ namespace psemek::wgpu
wgpuComputePassEncoderDispatchWorkgroupsIndirect((WGPUComputePassEncoder)get(), (WGPUBuffer)indirect_buffer.get(), offset);
}
void compute_pass_encoder::set_push_constants(std::uint32_t offset, util::span<char const> data)
{
wgpuComputePassEncoderSetPushConstants((WGPUComputePassEncoder)get(), offset, data.size(), data.data());
}
void compute_pass_encoder::write_timestamp(query_set const & query_set, std::uint32_t query_index)
{
wgpuComputePassEncoderWriteTimestamp((WGPUComputePassEncoder)get(), (WGPUQuerySet)query_set.get(), query_index);
}
void compute_pass_encoder::insert_debug_marker(std::string const & marker_label)
{
wgpuComputePassEncoderInsertDebugMarker((WGPUComputePassEncoder)get(), marker_label.data());
wgpuComputePassEncoderInsertDebugMarker((WGPUComputePassEncoder)get(), detail::to_string_view(marker_label));
}
void compute_pass_encoder::push_debug_group(std::string const & group_label)
{
wgpuComputePassEncoderPushDebugGroup((WGPUComputePassEncoder)get(), group_label.data());
wgpuComputePassEncoderPushDebugGroup((WGPUComputePassEncoder)get(), detail::to_string_view(group_label));
}
void compute_pass_encoder::pop_debug_group()
@ -46,12 +58,12 @@ namespace psemek::wgpu
void compute_pass_encoder::set_label(std::string const & label)
{
wgpuComputePassEncoderSetLabel((WGPUComputePassEncoder)get(), label.data());
wgpuComputePassEncoderSetLabel((WGPUComputePassEncoder)get(), detail::to_string_view(label));
}
void compute_pass_encoder::reference(void * ptr)
{
wgpuComputePassEncoderReference((WGPUComputePassEncoder)ptr);
wgpuComputePassEncoderAddRef((WGPUComputePassEncoder)ptr);
}
void compute_pass_encoder::release(void * ptr)

View file

@ -1,4 +1,5 @@
#include <psemek/wgpu/compute_pipeline.hpp>
#include <psemek/wgpu/detail/string_view.hpp>
#include <psemek/wgpu/external/webgpu.h>
namespace psemek::wgpu
@ -11,12 +12,12 @@ namespace psemek::wgpu
void compute_pipeline::set_label(std::string const & label)
{
wgpuComputePipelineSetLabel((WGPUComputePipeline)get(), label.data());
wgpuComputePipelineSetLabel((WGPUComputePipeline)get(), detail::to_string_view(label));
}
void compute_pipeline::reference(void * ptr)
{
wgpuComputePipelineReference((WGPUComputePipeline)ptr);
wgpuComputePipelineAddRef((WGPUComputePipeline)ptr);
}
void compute_pipeline::release(void * ptr)

View file

@ -1,4 +1,6 @@
#include <psemek/wgpu/device.hpp>
#include <psemek/wgpu/detail/string_view.hpp>
#include <psemek/wgpu/detail/status.hpp>
#include <psemek/wgpu/external/webgpu.h>
#include <psemek/wgpu/external/wgpu.h>
@ -29,7 +31,7 @@ namespace psemek::wgpu
WGPUBindGroupDescriptor descriptor = {};
descriptor.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.chain);
descriptor.label = desc.label.data();
descriptor.label = detail::to_string_view(desc.label);
descriptor.layout = (WGPUBindGroupLayout)desc.layout.get();
descriptor.entryCount = entries.size();
descriptor.entries = entries.data();
@ -45,7 +47,7 @@ namespace psemek::wgpu
auto & entry_out = entries.emplace_back();
entry_out.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(entry_in.chain);
entry_out.binding = entry_in.binding;
entry_out.visibility = (WGPUShaderStageFlags)entry_in.visibility;
entry_out.visibility = (WGPUShaderStage)entry_in.visibility;
entry_out.buffer.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(entry_in.buffer.chain);
entry_out.buffer.type = (WGPUBufferBindingType)entry_in.buffer.type;
entry_out.buffer.hasDynamicOffset = entry_in.buffer.has_dynamic_offset;
@ -64,7 +66,7 @@ namespace psemek::wgpu
WGPUBindGroupLayoutDescriptor descriptor = {};
descriptor.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.chain);
descriptor.label = desc.label.data();
descriptor.label = detail::to_string_view(desc.label);
descriptor.entryCount = entries.size();
descriptor.entries = entries.data();
@ -75,8 +77,8 @@ namespace psemek::wgpu
{
WGPUBufferDescriptor descriptor = {};
descriptor.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.chain);
descriptor.label = desc.label.data();
descriptor.usage = (WGPUBufferUsageFlags)desc.usage;
descriptor.label = detail::to_string_view(desc.label);
descriptor.usage = (WGPUBufferUsage)desc.usage;
descriptor.size = desc.size;
descriptor.mappedAtCreation = desc.mapped_at_creation;
return buffer(wgpuDeviceCreateBuffer((WGPUDevice)get(), &descriptor));
@ -86,7 +88,7 @@ namespace psemek::wgpu
{
WGPUCommandEncoderDescriptor descriptor = {};
descriptor.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.chain);
descriptor.label = desc.label.data();
descriptor.label = detail::to_string_view(desc.label);
return command_encoder(wgpuDeviceCreateCommandEncoder((WGPUDevice)get(), &descriptor));
}
@ -99,16 +101,16 @@ namespace psemek::wgpu
{
auto & constant_out = constants.emplace_back();
constant_out.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(constant_in.chain);
constant_out.key = constant_in.key.data();
constant_out.key = detail::to_string_view(constant_in.key);
constant_out.value = constant_in.value;
}
descriptor.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.chain);
descriptor.label = desc.label.data();
descriptor.label = detail::to_string_view(desc.label);
descriptor.layout = (WGPUPipelineLayout)desc.layout.get();
descriptor.compute.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.compute.chain);
descriptor.compute.module = (WGPUShaderModule)desc.compute.module.get();
descriptor.compute.entryPoint = desc.compute.entry_point.data();
descriptor.compute.entryPoint = detail::to_string_view(desc.compute.entry_point);
descriptor.compute.constantCount = constants.size();
descriptor.compute.constants = constants.data();
}
@ -124,28 +126,29 @@ namespace psemek::wgpu
return compute_pipeline(wgpuDeviceCreateComputePipeline((WGPUDevice)get(), &descriptor));
}
void device::create_compute_pipeline_async(compute_pipeline::descriptor const & desc, create_compute_pipeline_async_callback const & callback)
void device::create_compute_pipeline_async(callback_mode mode, compute_pipeline::descriptor const & desc, create_compute_pipeline_async_callback const & callback)
{
std::vector<WGPUConstantEntry> constants;
WGPUComputePipelineDescriptor descriptor = {};
fill_compute_pipeline_descriptor(desc, constants, descriptor);
auto userdata = new create_compute_pipeline_async_callback(callback);
auto real_callback = [](WGPUCreatePipelineAsyncStatus status, WGPUComputePipeline pipeline, char const * message, void * userdata)
WGPUCreateComputePipelineAsyncCallbackInfo callback_info = {};
callback_info.mode = (WGPUCallbackMode)mode;
callback_info.callback = [](WGPUCreatePipelineAsyncStatus status, WGPUComputePipeline pipeline, WGPUStringView message, void * userdata, void *)
{
std::unique_ptr<create_compute_pipeline_async_callback> callback((create_compute_pipeline_async_callback *)userdata);
if (*callback) (*callback)((create_pipeline_async_status)status, compute_pipeline(pipeline), std::string(message ? message : ""));
if (*callback) (*callback)((create_pipeline_async_status)status, compute_pipeline(pipeline), std::string_view(message.data, message.length));
};
callback_info.userdata1 = new create_compute_pipeline_async_callback(callback);
wgpuDeviceCreateComputePipelineAsync((WGPUDevice)get(), &descriptor, real_callback, userdata);
wgpuDeviceCreateComputePipelineAsync((WGPUDevice)get(), &descriptor, callback_info);
}
pipeline_layout device::create_pipeline_layout(pipeline_layout::descriptor const & desc)
{
WGPUPipelineLayoutDescriptor descriptor = {};
descriptor.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.chain);
descriptor.label = desc.label.data();
descriptor.label = detail::to_string_view(desc.label);
descriptor.bindGroupLayoutCount = desc.layouts.size();
static_assert(sizeof(WGPUBindGroupLayout) == sizeof(bind_group_layout));
descriptor.bindGroupLayouts = (WGPUBindGroupLayout const *)desc.layouts.data();
@ -156,7 +159,7 @@ namespace psemek::wgpu
{
WGPUQuerySetDescriptor descriptor = {};
descriptor.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.chain);
descriptor.label = desc.label.data();
descriptor.label = detail::to_string_view(desc.label);
descriptor.type = (WGPUQueryType)desc.type;
descriptor.count = desc.count;
return query_set(wgpuDeviceCreateQuerySet((WGPUDevice)get(), &descriptor));
@ -165,6 +168,11 @@ namespace psemek::wgpu
namespace
{
WGPUOptionalBool to_optional_bool(std::optional<bool> value)
{
return value ? (*value ? WGPUOptionalBool_True : WGPUOptionalBool_False) : WGPUOptionalBool_Undefined;
}
void fill_render_pipeline_descriptor(render_pipeline::descriptor const & desc,
WGPURenderPipelineDescriptor & descriptor,
std::vector<WGPUConstantEntry> & vertex_constants,
@ -175,14 +183,14 @@ namespace psemek::wgpu
std::vector<WGPUColorTargetState> & color_targets)
{
descriptor.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.chain);
descriptor.label = desc.label.data();
descriptor.label = detail::to_string_view(desc.label);
descriptor.layout = (WGPUPipelineLayout)desc.layout.get();
for (auto const & constant_in : desc.vertex.constants)
{
auto & constant_out = vertex_constants.emplace_back();
constant_out.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(constant_in.chain);
constant_out.key = constant_in.key.data();
constant_out.key = detail::to_string_view(constant_in.key);
constant_out.value = constant_in.value;
}
@ -198,7 +206,7 @@ namespace psemek::wgpu
descriptor.vertex.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.vertex.chain);
descriptor.vertex.module = (WGPUShaderModule)desc.vertex.module.get();
descriptor.vertex.entryPoint = desc.vertex.entry_point.data();
descriptor.vertex.entryPoint = detail::to_string_view(desc.vertex.entry_point);
descriptor.vertex.constantCount = vertex_constants.size();
descriptor.vertex.constants = vertex_constants.data();
descriptor.vertex.bufferCount = vertex_buffers.size();
@ -209,12 +217,13 @@ namespace psemek::wgpu
descriptor.primitive.stripIndexFormat = (WGPUIndexFormat)desc.primitive.strip_index_format;
descriptor.primitive.frontFace = (WGPUFrontFace)desc.primitive.front_face;
descriptor.primitive.cullMode = (WGPUCullMode)desc.primitive.cull_mode;
descriptor.primitive.unclippedDepth = desc.primitive.clip_depth ? 0 : 1;
if (desc.depth_stencil)
{
depth_stencil_state.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.depth_stencil->chain);
depth_stencil_state.format = (WGPUTextureFormat)desc.depth_stencil->format;
depth_stencil_state.depthWriteEnabled = desc.depth_stencil->depth_write;
depth_stencil_state.depthWriteEnabled = to_optional_bool(desc.depth_stencil->depth_write);
depth_stencil_state.depthCompare = (WGPUCompareFunction)desc.depth_stencil->depth_compare;
depth_stencil_state.stencilFront.compare = (WGPUCompareFunction)desc.depth_stencil->stencil_front.compare;
depth_stencil_state.stencilFront.failOp = (WGPUStencilOperation)desc.depth_stencil->stencil_front.fail_op;
@ -244,7 +253,7 @@ namespace psemek::wgpu
{
auto & constant_out = fragment_constants.emplace_back();
constant_out.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(constant_in.chain);
constant_out.key = constant_in.key.data();
constant_out.key = detail::to_string_view(constant_in.key);
constant_out.value = constant_in.value;
}
@ -255,12 +264,12 @@ namespace psemek::wgpu
target_out.format = (WGPUTextureFormat)target_in.format;
static_assert(sizeof(WGPUBlendState) == sizeof(blend_state));
target_out.blend = (WGPUBlendState *)(target_in.blend ? &(*target_in.blend) : nullptr);
target_out.writeMask = (WGPUColorWriteMaskFlags)target_in.write_mask;
target_out.writeMask = (WGPUColorWriteMask)target_in.write_mask;
}
fragment_state.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.fragment->chain);
fragment_state.module = (WGPUShaderModule)desc.fragment->module.get();
fragment_state.entryPoint = desc.fragment->entry_point.data();
fragment_state.entryPoint = detail::to_string_view(desc.fragment->entry_point);
fragment_state.constantCount = fragment_constants.size();
fragment_state.constants = fragment_constants.data();
fragment_state.targetCount = color_targets.size();
@ -287,7 +296,7 @@ namespace psemek::wgpu
return render_pipeline(wgpuDeviceCreateRenderPipeline((WGPUDevice)get(), &descriptor));
}
void device::create_render_pipeline_async(render_pipeline::descriptor const & desc, create_render_pipeline_async_callback const & callback)
void device::create_render_pipeline_async(callback_mode mode, render_pipeline::descriptor const & desc, create_render_pipeline_async_callback const & callback)
{
WGPURenderPipelineDescriptor descriptor = {};
std::vector<WGPUConstantEntry> vertex_constants;
@ -299,22 +308,23 @@ namespace psemek::wgpu
fill_render_pipeline_descriptor(desc, descriptor, vertex_constants, vertex_buffers, depth_stencil_state, fragment_state, fragment_constants, color_targets);
auto userdata = new create_render_pipeline_async_callback(callback);
auto real_callback = [](WGPUCreatePipelineAsyncStatus status, WGPURenderPipeline pipeline, char const * message, void * userdata)
WGPUCreateRenderPipelineAsyncCallbackInfo callback_info = {};
callback_info.mode = (WGPUCallbackMode)mode;
callback_info.callback = [](WGPUCreatePipelineAsyncStatus status, WGPURenderPipeline pipeline, WGPUStringView message, void * userdata, void *)
{
std::unique_ptr<create_render_pipeline_async_callback> callback((create_render_pipeline_async_callback *)userdata);
if (*callback) (*callback)((create_pipeline_async_status)status, render_pipeline(pipeline), std::string(message ? message : ""));
if (*callback) (*callback)((create_pipeline_async_status)status, render_pipeline(pipeline), std::string_view(message.data, message.length));
};
callback_info.userdata1 = new create_render_pipeline_async_callback(callback);
wgpuDeviceCreateRenderPipelineAsync((WGPUDevice)get(), &descriptor, real_callback, userdata);
wgpuDeviceCreateRenderPipelineAsync((WGPUDevice)get(), &descriptor, callback_info);
}
render_bundle_encoder device::create_render_bundle_encoder(render_bundle_encoder::descriptor const & desc)
{
WGPURenderBundleEncoderDescriptor descriptor = {};
descriptor.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.chain);
descriptor.label = desc.label.data();
descriptor.label = detail::to_string_view(desc.label);
descriptor.colorFormatCount = desc.color_formats.size();
descriptor.colorFormats = (WGPUTextureFormat const *)desc.color_formats.data();
descriptor.depthStencilFormat = (WGPUTextureFormat)desc.depth_stencil_format;
@ -328,7 +338,7 @@ namespace psemek::wgpu
{
WGPUSamplerDescriptor descriptor = {};
descriptor.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.chain);
descriptor.label = desc.label.data();
descriptor.label = detail::to_string_view(desc.label);
descriptor.addressModeU = (WGPUAddressMode)desc.address_mode_u;
descriptor.addressModeV = (WGPUAddressMode)desc.address_mode_v;
descriptor.addressModeW = (WGPUAddressMode)desc.address_mode_w;
@ -344,20 +354,9 @@ namespace psemek::wgpu
shader_module device::create_shader_module(shader_module::descriptor const & desc)
{
std::vector<WGPUShaderModuleCompilationHint> hints;
for (auto const & hint_in : desc.hints)
{
auto & hint = hints.emplace_back();
hint.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(hint_in.chain);
hint.entryPoint = hint_in.entry_point.data();
hint.layout = (WGPUPipelineLayout)hint_in.layout.get();
}
WGPUShaderModuleDescriptor descriptor = {};
descriptor.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.chain);
descriptor.label = desc.label.data();
descriptor.hintCount = hints.size();
descriptor.hints = hints.data();
descriptor.label = detail::to_string_view(desc.label);
return shader_module(wgpuDeviceCreateShaderModule((WGPUDevice)get(), &descriptor));
}
@ -365,8 +364,8 @@ namespace psemek::wgpu
{
WGPUTextureDescriptor descriptor = {};
descriptor.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.chain);
descriptor.label = desc.label.data();
descriptor.usage = (WGPUTextureUsageFlags)desc.usage;
descriptor.label = detail::to_string_view(desc.label);
descriptor.usage = (WGPUTextureUsage)desc.usage;
descriptor.dimension = (WGPUTextureDimension)desc.dimension;
descriptor.size = {desc.size[0], desc.size[1], desc.size[2]};
descriptor.format = (WGPUTextureFormat)desc.format;
@ -384,21 +383,53 @@ namespace psemek::wgpu
std::vector<feature> device::enumerate_features()
{
std::size_t count = wgpuDeviceEnumerateFeatures((WGPUDevice)get(), nullptr);
std::vector<feature> result(count);
wgpuDeviceEnumerateFeatures((WGPUDevice)get(), (WGPUFeatureName *)result.data());
WGPUSupportedFeatures supported_features;
wgpuDeviceGetFeatures((WGPUDevice)get(), &supported_features);
std::vector<feature> result((feature const *)supported_features.features, (feature const *)(supported_features.features + supported_features.featureCount));
wgpuSupportedFeaturesFreeMembers(supported_features);
return result;
}
limits device::get_limits()
{
WGPUSupportedLimits limits = {};
wgpuDeviceGetLimits((WGPUDevice)get(), &limits);
WGPULimits limits = {};
detail::check_status("wgpuDeviceGetLimits", wgpuDeviceGetLimits((WGPUDevice)get(), &limits));
// TODO: support out chain
wgpu::limits result;
static_assert(sizeof(result) == sizeof(limits.limits));
std::memcpy((char *)&result, (char *)&limits.limits, sizeof(result));
result.max_texture_dimension_1D = limits.maxTextureDimension1D;
result.max_texture_dimension_2D = limits.maxTextureDimension2D;
result.max_texture_dimension_3D = limits.maxTextureDimension3D;
result.max_texture_array_layers = limits.maxTextureArrayLayers;
result.max_bind_groups = limits.maxBindGroups;
result.max_bind_groups_plus_vertex_buffers = limits.maxBindGroupsPlusVertexBuffers;
result.max_bindings_per_bind_group = limits.maxBindingsPerBindGroup;
result.max_dynamic_uniform_buffers_per_pipeline_layout = limits.maxDynamicUniformBuffersPerPipelineLayout;
result.max_dynamic_storage_buffers_per_pipeline_layout = limits.maxDynamicStorageBuffersPerPipelineLayout;
result.max_sampled_textures_per_shader_stage = limits.maxSampledTexturesPerShaderStage;
result.max_samplers_per_shader_stage = limits.maxSamplersPerShaderStage;
result.max_storage_buffers_per_shader_stage = limits.maxStorageBuffersPerShaderStage;
result.max_storage_textures_per_shader_stage = limits.maxStorageTexturesPerShaderStage;
result.max_uniform_buffers_per_shader_stage = limits.maxUniformBuffersPerShaderStage;
result.max_uniform_buffer_binding_size = limits.maxUniformBufferBindingSize;
result.max_storage_buffer_binding_size = limits.maxStorageBufferBindingSize;
result.min_uniform_buffer_offset_alignment = limits.minUniformBufferOffsetAlignment;
result.min_storage_buffer_offset_alignment = limits.minStorageBufferOffsetAlignment;
result.max_vertex_buffers = limits.maxVertexBuffers;
result.max_buffer_size = limits.maxBufferSize;
result.max_vertex_attributes = limits.maxVertexAttributes;
result.max_vertex_buffer_array_stride = limits.maxVertexBufferArrayStride;
result.max_inter_stage_shader_variables = limits.maxInterStageShaderVariables;
result.max_color_attachments = limits.maxColorAttachments;
result.max_color_attachment_bytes_per_sample = limits.maxColorAttachmentBytesPerSample;
result.max_compute_workgroup_storage_size = limits.maxComputeWorkgroupStorageSize;
result.max_compute_invocations_per_workgroup = limits.maxComputeInvocationsPerWorkgroup;
result.max_compute_workgroup_size_x = limits.maxComputeWorkgroupSizeX;
result.max_compute_workgroup_size_y = limits.maxComputeWorkgroupSizeY;
result.max_compute_workgroup_size_z = limits.maxComputeWorkgroupSizeZ;
result.max_compute_workgroups_per_dimension = limits.maxComputeWorkgroupsPerDimension;
return result;
}
@ -412,40 +443,28 @@ namespace psemek::wgpu
wgpuDevicePushErrorScope((WGPUDevice)get(), (WGPUErrorFilter)filter);
}
void device::pop_error_scope(error_callback const & callback)
void device::pop_error_scope(callback_mode mode, pop_error_callback const & callback)
{
auto userdata = new error_callback(callback);
auto real_callback = [](WGPUErrorType type, char const * message, void * userdata)
WGPUPopErrorScopeCallbackInfo callback_info = {};
callback_info.mode = (WGPUCallbackMode)mode;
callback_info.callback = [](WGPUPopErrorScopeStatus status, WGPUErrorType type, WGPUStringView message, void * userdata, void *)
{
std::unique_ptr<error_callback> callback((error_callback *)userdata);
if (*callback) (*callback)((error_type)type, message ? message : "");
std::unique_ptr<pop_error_callback> callback((pop_error_callback *)userdata);
if (*callback) (*callback)((pop_error_scope_status)status, (error_type)type, std::string_view(message.data, message.length));
};
callback_info.userdata1 = new pop_error_callback(callback);
wgpuDevicePopErrorScope((WGPUDevice)get(), real_callback, userdata);
}
void device::set_uncaptured_error_callback(error_callback const & callback)
{
auto userdata = new error_callback(callback);
auto real_callback = [](WGPUErrorType type, char const * message, void * userdata)
{
std::unique_ptr<error_callback> callback((error_callback *)userdata);
if (*callback) (*callback)((error_type)type, message ? message : "");
};
wgpuDeviceSetUncapturedErrorCallback((WGPUDevice)get(), real_callback, userdata);
wgpuDevicePopErrorScope((WGPUDevice)get(), callback_info);
}
void device::set_label(std::string const & label)
{
wgpuDeviceSetLabel((WGPUDevice)get(), label.data());
wgpuDeviceSetLabel((WGPUDevice)get(), detail::to_string_view(label));
}
void device::reference(void * ptr)
{
wgpuDeviceReference((WGPUDevice)ptr);
wgpuDeviceAddRef((WGPUDevice)ptr);
}
void device::release(void * ptr)
@ -455,10 +474,10 @@ namespace psemek::wgpu
detail::chained_struct_ptr to_chained_struct(native_limits && value)
{
WGPURequiredLimitsExtras chained = {};
chained.chain.sType = (WGPUSType)WGPUSType_RequiredLimitsExtras;
static_assert(sizeof(WGPUNativeLimits) == sizeof(native_limits));
std::memcpy(&chained.limits, &value, sizeof(value));
WGPUNativeLimits chained = {};
chained.chain.sType = (WGPUSType)WGPUSType_NativeLimits;
chained.maxPushConstantSize = value.max_push_constant_size;
chained.maxNonSamplerBindings = value.max_non_sampler_bindings;
return detail::make_chained_struct(chained);
}

View file

@ -1,4 +1,5 @@
#include <psemek/wgpu/instance.hpp>
#include <psemek/wgpu/detail/string_view.hpp>
#include <psemek/wgpu/external/webgpu.h>
#include <psemek/wgpu/external/wgpu.h>
@ -40,33 +41,35 @@ namespace psemek::wgpu
{
WGPUSurfaceDescriptor descriptor = {};
descriptor.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.chain);
descriptor.label = desc.label.data();
descriptor.label = detail::to_string_view(desc.label);
return surface{wgpuInstanceCreateSurface((WGPUInstance)get(), &descriptor)};
}
void instance::request_adapter(adapter::request_options const & request_options, adapter::request_callback callback)
void instance::request_adapter(callback_mode mode, adapter::request_options const & request_options, adapter::request_callback callback)
{
WGPURequestAdapterOptions options;
WGPURequestAdapterOptions options = {};
options.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(request_options.chain);
options.compatibleSurface = (WGPUSurface)request_options.compatible_surface.get();
options.featureLevel = (WGPUFeatureLevel)request_options.feature_level;
options.powerPreference = (WGPUPowerPreference)request_options.power_preference;
options.backendType = (WGPUBackendType)request_options.backend_type;
options.forceFallbackAdapter = request_options.force_fallback_adapter;
options.backendType = (WGPUBackendType)request_options.backend_type;
options.compatibleSurface = (WGPUSurface)request_options.compatible_surface.get();
auto userdata = new adapter::request_callback(callback);
auto real_callback = [](WGPURequestAdapterStatus status, WGPUAdapter adapter, char const * message, void * userdata)
WGPURequestAdapterCallbackInfo callback_info = {};
callback_info.mode = (WGPUCallbackMode)mode;
callback_info.callback = [](WGPURequestAdapterStatus status, WGPUAdapter adapter, WGPUStringView message, void * userdata, void *)
{
std::unique_ptr<adapter::request_callback> callback{(adapter::request_callback *)userdata};
if (*callback) (*callback)(adapter::request_status{status}, wgpu::adapter(adapter), message ? message : "");
if (*callback) (*callback)(adapter::request_status{status}, wgpu::adapter(adapter), std::string_view(message.data, message.length));
};
callback_info.userdata1 = new adapter::request_callback(callback);
wgpuInstanceRequestAdapter((WGPUInstance)get(), &options, real_callback, userdata);
wgpuInstanceRequestAdapter((WGPUInstance)get(), &options, callback_info);
}
void instance::reference(void * ptr)
{
wgpuInstanceReference((WGPUInstance)ptr);
wgpuInstanceAddRef((WGPUInstance)ptr);
}
void instance::release(void * ptr)

View file

@ -40,8 +40,8 @@ namespace psemek::wgpu
void setup_logging(log::level level)
{
wgpuSetLogLevel(to_wgpu_log_level(level));
wgpuSetLogCallback([](WGPULogLevel level, char const * message, void * /* userdata */){
log::log(to_psemek_log_level(level)) << "WebGPU: " << message;
wgpuSetLogCallback([](WGPULogLevel level, WGPUStringView message, void * /* userdata */){
log::log(to_psemek_log_level(level)) << "WebGPU: " << std::string_view(message.data, message.length);
}, nullptr);
}

View file

@ -1,4 +1,5 @@
#include <psemek/wgpu/pipeline_layout.hpp>
#include <psemek/wgpu/detail/string_view.hpp>
#include <psemek/wgpu/external/webgpu.h>
#include <psemek/wgpu/external/wgpu.h>
@ -7,12 +8,12 @@ namespace psemek::wgpu
void pipeline_layout::set_label(std::string const & label)
{
wgpuPipelineLayoutSetLabel((WGPUPipelineLayout)get(), label.data());
wgpuPipelineLayoutSetLabel((WGPUPipelineLayout)get(), detail::to_string_view(label));
}
void pipeline_layout::reference(void * ptr)
{
wgpuPipelineLayoutReference((WGPUPipelineLayout)ptr);
wgpuPipelineLayoutAddRef((WGPUPipelineLayout)ptr);
}
void pipeline_layout::release(void * ptr)

View file

@ -1,4 +1,5 @@
#include <psemek/wgpu/query_set.hpp>
#include <psemek/wgpu/detail/string_view.hpp>
#include <psemek/wgpu/external/webgpu.h>
namespace psemek::wgpu
@ -21,12 +22,12 @@ namespace psemek::wgpu
void query_set::set_label(std::string const & label)
{
wgpuQuerySetSetLabel((WGPUQuerySet)get(), label.data());
wgpuQuerySetSetLabel((WGPUQuerySet)get(), detail::to_string_view(label));
}
void query_set::reference(void * ptr)
{
wgpuQuerySetReference((WGPUQuerySet)ptr);
wgpuQuerySetAddRef((WGPUQuerySet)ptr);
}
void query_set::release(void * ptr)

View file

@ -1,4 +1,5 @@
#include <psemek/wgpu/queue.hpp>
#include <psemek/wgpu/detail/string_view.hpp>
#include <psemek/wgpu/external/webgpu.h>
namespace psemek::wgpu
@ -15,47 +16,46 @@ namespace psemek::wgpu
wgpuQueueWriteBuffer((WGPUQueue)get(), (WGPUBuffer)buffer.get(), offset, data.data(), data.size());
}
void queue::write_texture(image_copy_texture const & dest, util::span<char const> data, texture::data_layout const & data_layout, math::vector<std::uint32_t, 3> const & write_size)
void queue::write_texture(texel_copy_texture_info const & dest, util::span<char const> data, texel_copy_buffer_layout const & data_layout, math::vector<std::uint32_t, 3> const & write_size)
{
WGPUImageCopyTexture image_copy_texture = {};
image_copy_texture.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(dest.chain);
image_copy_texture.texture = (WGPUTexture)dest.texture.get();
image_copy_texture.mipLevel = dest.mip_level;
image_copy_texture.origin = {dest.origin[0], dest.origin[1], dest.origin[2]};
image_copy_texture.aspect = (WGPUTextureAspect)dest.aspect;
WGPUTexelCopyTextureInfo texel_copy_texture_info = {};
texel_copy_texture_info.texture = (WGPUTexture)dest.texture.get();
texel_copy_texture_info.mipLevel = dest.mip_level;
texel_copy_texture_info.origin = {dest.origin[0], dest.origin[1], dest.origin[2]};
texel_copy_texture_info.aspect = (WGPUTextureAspect)dest.aspect;
WGPUTextureDataLayout texture_data_layout = {};
texture_data_layout.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(data_layout.chain);
texture_data_layout.offset = data_layout.offset;
texture_data_layout.bytesPerRow = data_layout.bytes_per_row;
texture_data_layout.rowsPerImage = data_layout.rows_per_image;
WGPUTexelCopyBufferLayout texel_copy_buffer_layout = {};
texel_copy_buffer_layout.offset = data_layout.offset;
texel_copy_buffer_layout.bytesPerRow = data_layout.bytes_per_row;
texel_copy_buffer_layout.rowsPerImage = data_layout.rows_per_image;
WGPUExtent3D extent = {write_size[0], write_size[1], write_size[2]};
wgpuQueueWriteTexture((WGPUQueue)get(), &image_copy_texture, data.data(), data.size(), &texture_data_layout, &extent);
wgpuQueueWriteTexture((WGPUQueue)get(), &texel_copy_texture_info, data.data(), data.size(), &texel_copy_buffer_layout, &extent);
}
void queue::on_submitted_work_done(work_done_callback const & callback)
void queue::on_submitted_work_done(callback_mode mode, work_done_callback const & callback)
{
auto userdata = new work_done_callback(callback);
auto real_callback = [](WGPUQueueWorkDoneStatus status, void * userdata)
WGPUQueueWorkDoneCallbackInfo callback_info = {};
callback_info.mode = (WGPUCallbackMode)mode;
callback_info.callback = [](WGPUQueueWorkDoneStatus status, void * userdata, void *)
{
std::unique_ptr<work_done_callback> callback((work_done_callback*)userdata);
if (*callback) (*callback)((work_done_status)status);
};
callback_info.userdata1 = new work_done_callback(callback);
wgpuQueueOnSubmittedWorkDone((WGPUQueue)get(), real_callback, userdata);
wgpuQueueOnSubmittedWorkDone((WGPUQueue)get(), callback_info);
}
void queue::set_label(std::string const & label)
{
wgpuQueueSetLabel((WGPUQueue)get(), label.data());
wgpuQueueSetLabel((WGPUQueue)get(), detail::to_string_view(label));
}
void queue::reference(void * ptr)
{
wgpuQueueReference((WGPUQueue)ptr);
wgpuQueueAddRef((WGPUQueue)ptr);
}
void queue::release(void * ptr)

View file

@ -1,4 +1,5 @@
#include <psemek/wgpu/render_bundle.hpp>
#include <psemek/wgpu/detail/string_view.hpp>
#include <psemek/wgpu/external/webgpu.h>
namespace psemek::wgpu
@ -6,12 +7,12 @@ namespace psemek::wgpu
void render_bundle::set_label(std::string const & label)
{
wgpuRenderBundleSetLabel((WGPURenderBundle)get(), label.data());
wgpuRenderBundleSetLabel((WGPURenderBundle)get(), detail::to_string_view(label));
}
void render_bundle::reference(void * ptr)
{
wgpuRenderBundleReference((WGPURenderBundle)ptr);
wgpuRenderBundleAddRef((WGPURenderBundle)ptr);
}
void render_bundle::release(void * ptr)

View file

@ -1,4 +1,5 @@
#include <psemek/wgpu/render_bundle_encoder.hpp>
#include <psemek/wgpu/detail/string_view.hpp>
#include <psemek/wgpu/external/webgpu.h>
namespace psemek::wgpu
@ -44,14 +45,14 @@ namespace psemek::wgpu
wgpuRenderBundleEncoderDrawIndexedIndirect((WGPURenderBundleEncoder)get(), (WGPUBuffer)indirect_buffer.get(), offset);
}
void render_bundle_encoder::insert_debug_marker(std::string const & marker_label)
void render_bundle_encoder::insert_debug_marker(std::string_view marker_label)
{
wgpuRenderBundleEncoderInsertDebugMarker((WGPURenderBundleEncoder)get(), marker_label.data());
wgpuRenderBundleEncoderInsertDebugMarker((WGPURenderBundleEncoder)get(), detail::to_string_view(marker_label));
}
void render_bundle_encoder::push_debug_group(std::string const & group_label)
void render_bundle_encoder::push_debug_group(std::string_view group_label)
{
wgpuRenderBundleEncoderPushDebugGroup((WGPURenderBundleEncoder)get(), group_label.data());
wgpuRenderBundleEncoderPushDebugGroup((WGPURenderBundleEncoder)get(), detail::to_string_view(group_label));
}
void render_bundle_encoder::pop_debug_group()
@ -63,18 +64,18 @@ namespace psemek::wgpu
{
WGPURenderBundleDescriptor descriptor = {};
descriptor.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.chain);
descriptor.label = desc.label.data();
descriptor.label = detail::to_string_view(desc.label);
return render_bundle(wgpuRenderBundleEncoderFinish((WGPURenderBundleEncoder)get(), &descriptor));
}
void render_bundle_encoder::set_label(std::string const & label)
{
wgpuRenderBundleEncoderSetLabel((WGPURenderBundleEncoder)get(), label.data());
wgpuRenderBundleEncoderSetLabel((WGPURenderBundleEncoder)get(), detail::to_string_view(label));
}
void render_bundle_encoder::reference(void * ptr)
{
wgpuRenderBundleEncoderReference((WGPURenderBundleEncoder)ptr);
wgpuRenderBundleEncoderAddRef((WGPURenderBundleEncoder)ptr);
}
void render_bundle_encoder::release(void * ptr)

View file

@ -1,4 +1,5 @@
#include <psemek/wgpu/render_pass_encoder.hpp>
#include <psemek/wgpu/detail/string_view.hpp>
#include <psemek/wgpu/external/webgpu.h>
#include <psemek/wgpu/external/wgpu.h>
@ -48,7 +49,7 @@ namespace psemek::wgpu
void render_pass_encoder::set_push_constants(shader_stage stages, std::uint32_t offset, util::span<char const> data)
{
wgpuRenderPassEncoderSetPushConstants((WGPURenderPassEncoder)get(), (WGPUShaderStageFlags)stages, offset, data.size(), data.data());
wgpuRenderPassEncoderSetPushConstants((WGPURenderPassEncoder)get(), (WGPUShaderStage)stages, offset, data.size(), data.data());
}
void render_pass_encoder::draw(std::uint32_t vertex_count, std::uint32_t instance_count, std::uint32_t first_vertex, std::uint32_t first_instance)
@ -107,14 +108,19 @@ namespace psemek::wgpu
wgpuRenderPassEncoderEndOcclusionQuery((WGPURenderPassEncoder)get());
}
void render_pass_encoder::insert_debug_marker(std::string const & marker_label)
void render_pass_encoder::write_timestamp(query_set const & query_set, std::uint32_t query_index)
{
wgpuRenderPassEncoderInsertDebugMarker((WGPURenderPassEncoder)get(), marker_label.data());
wgpuRenderPassEncoderWriteTimestamp((WGPURenderPassEncoder)get(), (WGPUQuerySet)query_set.get(), query_index);
}
void render_pass_encoder::push_debug_group(std::string const & group_label)
void render_pass_encoder::insert_debug_marker(std::string_view marker_label)
{
wgpuRenderPassEncoderPushDebugGroup((WGPURenderPassEncoder)get(), group_label.data());
wgpuRenderPassEncoderInsertDebugMarker((WGPURenderPassEncoder)get(), detail::to_string_view(marker_label));
}
void render_pass_encoder::push_debug_group(std::string_view group_label)
{
wgpuRenderPassEncoderPushDebugGroup((WGPURenderPassEncoder)get(), detail::to_string_view(group_label));
}
void render_pass_encoder::pop_debug_group()
@ -129,12 +135,12 @@ namespace psemek::wgpu
void render_pass_encoder::set_label(std::string const & label)
{
wgpuRenderPassEncoderSetLabel((WGPURenderPassEncoder)get(), label.data());
wgpuRenderPassEncoderSetLabel((WGPURenderPassEncoder)get(), detail::to_string_view(label));
}
void render_pass_encoder::reference(void * ptr)
{
wgpuRenderPassEncoderReference((WGPURenderPassEncoder)ptr);
wgpuRenderPassEncoderAddRef((WGPURenderPassEncoder)ptr);
}
void render_pass_encoder::release(void * ptr)

View file

@ -1,4 +1,5 @@
#include <psemek/wgpu/render_pipeline.hpp>
#include <psemek/wgpu/detail/string_view.hpp>
#include <psemek/wgpu/external/webgpu.h>
namespace psemek::wgpu
@ -11,12 +12,12 @@ namespace psemek::wgpu
void render_pipeline::set_label(std::string const & label)
{
wgpuRenderPipelineSetLabel((WGPURenderPipeline)get(), label.data());
wgpuRenderPipelineSetLabel((WGPURenderPipeline)get(), detail::to_string_view(label));
}
void render_pipeline::reference(void * ptr)
{
wgpuRenderPipelineReference((WGPURenderPipeline)ptr);
wgpuRenderPipelineAddRef((WGPURenderPipeline)ptr);
}
void render_pipeline::release(void * ptr)

View file

@ -1,4 +1,5 @@
#include <psemek/wgpu/sampler.hpp>
#include <psemek/wgpu/detail/string_view.hpp>
#include <psemek/wgpu/external/webgpu.h>
namespace psemek::wgpu
@ -6,12 +7,12 @@ namespace psemek::wgpu
void sampler::set_label(std::string const & label)
{
wgpuSamplerSetLabel((WGPUSampler)get(), label.data());
wgpuSamplerSetLabel((WGPUSampler)get(), detail::to_string_view(label));
}
void sampler::reference(void * ptr)
{
wgpuSamplerReference((WGPUSampler)ptr);
wgpuSamplerAddRef((WGPUSampler)ptr);
}
void sampler::release(void * ptr)

View file

@ -1,4 +1,5 @@
#include <psemek/wgpu/shader_module.hpp>
#include <psemek/wgpu/detail/string_view.hpp>
#include <psemek/wgpu/external/webgpu.h>
#include <psemek/wgpu/external/wgpu.h>
@ -7,11 +8,11 @@
namespace psemek::wgpu
{
void shader_module::get_compilation_info(compilation_info_callback const & callback)
void shader_module::get_compilation_info(callback_mode mode, compilation_info_callback const & callback)
{
auto userdata = new compilation_info_callback(callback);
auto real_callback = [](WGPUCompilationInfoRequestStatus status, WGPUCompilationInfo const * info, void * userdata)
WGPUCompilationInfoCallbackInfo callback_info = {};
callback_info.mode = (WGPUCallbackMode)mode;
callback_info.callback = [](WGPUCompilationInfoRequestStatus status, WGPUCompilationInfo const * info, void * userdata, void *)
{
std::unique_ptr<compilation_info_callback> callback((compilation_info_callback *)userdata);
@ -24,32 +25,30 @@ namespace psemek::wgpu
auto & message = cinfo.messages.emplace_back();
auto & message_in = info->messages[i];
message.message = message_in.message;
message.message.assign(message_in.message.data, message_in.message.length);
message.type = (compilation_message_type)message_in.type;
message.line_num = message_in.lineNum;
message.line_pos = message_in.linePos;
message.offset = message_in.offset;
message.length = message_in.length;
message.utf16_line_pos = message_in.utf16LinePos;
message.utf16_offset = message_in.utf16Offset;
message.utf16_length = message_in.utf16Length;
}
}
if (*callback) (*callback)((compilation_info_request_status)status, cinfo);
};
callback_info.userdata1 = new compilation_info_callback(callback);
wgpuShaderModuleGetCompilationInfo((WGPUShaderModule)get(), real_callback, userdata);
wgpuShaderModuleGetCompilationInfo((WGPUShaderModule)get(), callback_info);
}
void shader_module::set_label(std::string const & label)
{
wgpuShaderModuleSetLabel((WGPUShaderModule)get(), label.data());
wgpuShaderModuleSetLabel((WGPUShaderModule)get(), detail::to_string_view(label));
}
void shader_module::reference(void * ptr)
{
wgpuShaderModuleReference((WGPUShaderModule)ptr);
wgpuShaderModuleAddRef((WGPUShaderModule)ptr);
}
void shader_module::release(void * ptr)
@ -59,8 +58,8 @@ namespace psemek::wgpu
detail::chained_struct_ptr to_chained_struct(shader_module::spirv_descriptor const & value)
{
WGPUShaderModuleSPIRVDescriptor chained = {};
chained.chain.sType = WGPUSType_ShaderModuleSPIRVDescriptor;
WGPUShaderSourceSPIRV chained = {};
chained.chain.sType = WGPUSType_ShaderSourceSPIRV;
chained.codeSize = value.code.size(); // TODO: is it in bytes or in words?
chained.code = value.code.data();
return detail::make_chained_struct(chained);
@ -68,22 +67,34 @@ namespace psemek::wgpu
detail::chained_struct_ptr to_chained_struct(shader_module::wgsl_descriptor const & value)
{
WGPUShaderModuleWGSLDescriptor chained = {};
chained.chain.sType = WGPUSType_ShaderModuleWGSLDescriptor;
chained.code = value.code;
WGPUShaderSourceWGSL chained = {};
chained.chain.sType = WGPUSType_ShaderSourceWGSL;
chained.code = detail::to_string_view(value.code);
return detail::make_chained_struct(chained);
}
detail::chained_struct_ptr to_chained_struct(shader_module::glsl_descriptor && value)
{
WGPUShaderModuleGLSLDescriptor chained = {};
chained.chain.sType = (WGPUSType)WGPUSType_ShaderModuleGLSLDescriptor;
struct chained_storage
{
std::vector<WGPUShaderDefine> defines;
};
chained_storage storage;
storage.defines.resize(value.defines.size());
for (int i = 0; i < value.defines.size(); ++i)
{
storage.defines[i].name = detail::to_string_view(value.defines[i].name);
storage.defines[i].value = detail::to_string_view(value.defines[i].value);
}
WGPUShaderSourceGLSL chained = {};
chained.chain.sType = (WGPUSType)WGPUSType_ShaderSourceGLSL;
chained.stage = (WGPUShaderStage)value.stage;
chained.code = value.code;
chained.defineCount = value.defines.size();
static_assert(sizeof(WGPUShaderDefine) == sizeof(shader_module::define));
chained.defines = (WGPUShaderDefine *)value.defines.data();
return detail::make_chained_struct(chained, std::move(value));
chained.code = detail::to_string_view(value.code);
chained.defineCount = storage.defines.size();
chained.defines = storage.defines.data();
return detail::make_chained_struct(chained, std::move(storage));
}
}

View file

@ -1,5 +1,7 @@
#include <psemek/wgpu/surface.hpp>
#include <psemek/wgpu/adapter.hpp>
#include <psemek/wgpu/detail/string_view.hpp>
#include <psemek/wgpu/detail/status.hpp>
#include <psemek/wgpu/external/webgpu.h>
#include <psemek/wgpu/external/wgpu.h>
@ -13,7 +15,7 @@ namespace psemek::wgpu
config.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(conf.chain);
config.device = (WGPUDevice)conf.device.get();
config.format = (WGPUTextureFormat)conf.format;
config.usage = (WGPUTextureUsageFlags)conf.usage;
config.usage = (WGPUTextureUsage)conf.usage;
config.viewFormatCount = conf.view_formats.size();
config.viewFormats = (WGPUTextureFormat const *)conf.view_formats.data();
config.alphaMode = (WGPUCompositeAlphaMode)conf.alpha_mode;
@ -26,13 +28,17 @@ namespace psemek::wgpu
surface::capabilities surface::get_capabilities(adapter const & adapter)
{
WGPUSurfaceCapabilities caps = {};
wgpuSurfaceGetCapabilities((WGPUSurface)get(), (WGPUAdapter)adapter.get(), &caps);
detail::check_status("wgpuSurfaceGetCapabilities", wgpuSurfaceGetCapabilities((WGPUSurface)get(), (WGPUAdapter)adapter.get(), &caps));
capabilities result;
// TODO: support out chain
result.usage = (texture::usage)caps.usages;
result.formats.assign((wgpu::texture::format *)(caps.formats), (wgpu::texture::format *)(caps.formats) + caps.formatCount);
result.present_modes.assign((present_mode *)(caps.presentModes), (present_mode *)(caps.presentModes) + caps.presentModeCount);
result.alpha_modes.assign((composite_alpha_mode *)(caps.alphaModes), (composite_alpha_mode *)(caps.alphaModes) + caps.alphaModeCount);
wgpuSurfaceCapabilitiesFreeMembers(caps);
return result;
}
@ -43,19 +49,13 @@ namespace psemek::wgpu
return {
.texture = wgpu::texture(tex.texture),
.suboptimal = tex.suboptimal,
.status = (enum current_texture::status)tex.status,
};
}
wgpu::texture::format surface::get_preferred_format(adapter const & adapter)
{
return (wgpu::texture::format)wgpuSurfaceGetPreferredFormat((WGPUSurface)get(), (WGPUAdapter)adapter.get());
}
void surface::present()
{
wgpuSurfacePresent((WGPUSurface)get());
detail::check_status("wgpuSurfacePresent", wgpuSurfacePresent((WGPUSurface)get()));
}
void surface::unconfigure()
@ -65,7 +65,7 @@ namespace psemek::wgpu
void surface::reference(void * ptr)
{
wgpuSurfaceReference((WGPUSurface)ptr);
wgpuSurfaceAddRef((WGPUSurface)ptr);
}
void surface::release(void * ptr)
@ -83,32 +83,24 @@ namespace psemek::wgpu
detail::chained_struct_ptr to_chained_struct(surface::from_android_native_window const & value)
{
WGPUSurfaceDescriptorFromAndroidNativeWindow chained = {};
chained.chain.sType = WGPUSType_SurfaceDescriptorFromAndroidNativeWindow;
WGPUSurfaceSourceAndroidNativeWindow chained = {};
chained.chain.sType = WGPUSType_SurfaceSourceAndroidNativeWindow;
chained.window = value.window;
return detail::make_chained_struct(chained);
}
detail::chained_struct_ptr to_chained_struct(surface::from_canvas_html_selected const & value)
{
WGPUSurfaceDescriptorFromCanvasHTMLSelector chained = {};
chained.chain.sType = WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector;
chained.selector = value.selector.data();
return detail::make_chained_struct(chained);
}
detail::chained_struct_ptr to_chained_struct(surface::from_metal_layer const & value)
{
WGPUSurfaceDescriptorFromMetalLayer chained = {};
chained.chain.sType = WGPUSType_SurfaceDescriptorFromMetalLayer;
WGPUSurfaceSourceMetalLayer chained = {};
chained.chain.sType = WGPUSType_SurfaceSourceMetalLayer;
chained.layer = value.layer;
return detail::make_chained_struct(chained);
}
detail::chained_struct_ptr to_chained_struct(surface::from_wayland_surface const & value)
{
WGPUSurfaceDescriptorFromWaylandSurface chained = {};
chained.chain.sType = WGPUSType_SurfaceDescriptorFromWaylandSurface;
WGPUSurfaceSourceWaylandSurface chained = {};
chained.chain.sType = WGPUSType_SurfaceSourceWaylandSurface;
chained.display = value.display;
chained.surface = value.surface;
return detail::make_chained_struct(chained);
@ -116,8 +108,8 @@ namespace psemek::wgpu
detail::chained_struct_ptr to_chained_struct(surface::from_windows_hwnd const & value)
{
WGPUSurfaceDescriptorFromWindowsHWND chained = {};
chained.chain.sType = WGPUSType_SurfaceDescriptorFromWindowsHWND;
WGPUSurfaceSourceWindowsHWND chained = {};
chained.chain.sType = WGPUSType_SurfaceSourceWindowsHWND;
chained.hinstance = value.hinstance;
chained.hwnd = value.hwnd;
return detail::make_chained_struct(chained);
@ -125,8 +117,8 @@ namespace psemek::wgpu
detail::chained_struct_ptr to_chained_struct(surface::from_xcb_window const & value)
{
WGPUSurfaceDescriptorFromXcbWindow chained = {};
chained.chain.sType = WGPUSType_SurfaceDescriptorFromXcbWindow;
WGPUSurfaceSourceXCBWindow chained = {};
chained.chain.sType = WGPUSType_SurfaceSourceXCBWindow;
chained.connection = value.connection;
chained.window = value.window;
return detail::make_chained_struct(chained);
@ -134,8 +126,8 @@ namespace psemek::wgpu
detail::chained_struct_ptr to_chained_struct(surface::from_xlib_window const & value)
{
WGPUSurfaceDescriptorFromXlibWindow chained = {};
chained.chain.sType = WGPUSType_SurfaceDescriptorFromXlibWindow;
WGPUSurfaceSourceXlibWindow chained = {};
chained.chain.sType = WGPUSType_SurfaceSourceXlibWindow;
chained.display = value.display;
chained.window = value.window;
return detail::make_chained_struct(chained);

View file

@ -1,4 +1,5 @@
#include <psemek/wgpu/texture.hpp>
#include <psemek/wgpu/detail/string_view.hpp>
#include <psemek/wgpu/external/webgpu.h>
namespace psemek::wgpu
@ -8,7 +9,7 @@ namespace psemek::wgpu
{
WGPUTextureViewDescriptor descriptor = {};
descriptor.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.chain);
descriptor.label = desc.label.data();
descriptor.label = detail::to_string_view(desc.label);
descriptor.format = (WGPUTextureFormat)desc.format;
descriptor.dimension = (WGPUTextureViewDimension)desc.dimension;
descriptor.baseMipLevel = desc.base_mip_level;
@ -62,12 +63,12 @@ namespace psemek::wgpu
void texture::set_label(std::string const & label)
{
wgpuTextureSetLabel((WGPUTexture)get(), label.data());
wgpuTextureSetLabel((WGPUTexture)get(), detail::to_string_view(label));
}
void texture::reference(void * ptr)
{
wgpuTextureReference((WGPUTexture)ptr);
wgpuTextureAddRef((WGPUTexture)ptr);
}
void texture::release(void * ptr)

View file

@ -1,4 +1,5 @@
#include <psemek/wgpu/texture_view.hpp>
#include <psemek/wgpu/detail/string_view.hpp>
#include <psemek/wgpu/external/webgpu.h>
namespace psemek::wgpu
@ -6,12 +7,12 @@ namespace psemek::wgpu
void texture_view::set_label(std::string const & label)
{
wgpuTextureViewSetLabel((WGPUTextureView)get(), label.data());
wgpuTextureViewSetLabel((WGPUTextureView)get(), detail::to_string_view(label));
}
void texture_view::reference(void * ptr)
{
wgpuTextureViewReference((WGPUTextureView)ptr);
wgpuTextureViewAddRef((WGPUTextureView)ptr);
}
void texture_view::release(void * ptr)