Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/gpu-clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
// by default, and we specify that our shaders will be SPIR-V ones (even through we
// aren't using any shaders)
// We'll also turn on debug mode to true, so we get debug stuff
let gpu = sdl3::gpu::Device::new(sdl3::gpu::ShaderFormat::SpirV, true)?.with_window(&window)?;
let gpu = sdl3::gpu::Device::new(sdl3::gpu::ShaderFormat::SPIRV, true)?.with_window(&window)?;

let mut event_pump = sdl_context.event_pump()?;
println!(
Expand Down Expand Up @@ -45,8 +45,8 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let color_targets = [
sdl3::gpu::ColorTargetInfo::default()
.with_texture(&swapchain) // Use swapchain texture
.with_load_op(sdl3::gpu::LoadOp::Clear) // Clear when load
.with_store_op(sdl3::gpu::StoreOp::Store) // Store back
.with_load_op(sdl3::gpu::LoadOp::CLEAR) // Clear when load
.with_store_op(sdl3::gpu::StoreOp::STORE) // Store back
.with_clear_color(sdl3::pixels::Color::RGB(5, 3, 255)), //blue with small RG bias
];
// Here we do all (none) of our drawing (clearing the screen)
Expand Down
28 changes: 14 additions & 14 deletions examples/gpu-cube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
.map_err(|e| e.to_string())?;

let gpu = Device::new(
ShaderFormat::SpirV | ShaderFormat::Dxil | ShaderFormat::Dxbc | ShaderFormat::MetalLib,
ShaderFormat::SPIRV | ShaderFormat::DXIL | ShaderFormat::DXBC | ShaderFormat::METALLIB,
true,
)?
.with_window(&window)?;
Expand All @@ -98,7 +98,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let vert_shader = gpu
.create_shader()
.with_code(
ShaderFormat::SpirV,
ShaderFormat::SPIRV,
include_bytes!("shaders/cube.vert.spv"),
ShaderStage::Vertex,
)
Expand All @@ -108,7 +108,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let frag_shader = gpu
.create_shader()
.with_code(
ShaderFormat::SpirV,
ShaderFormat::SPIRV,
include_bytes!("shaders/cube.frag.spv"),
ShaderStage::Fragment,
)
Expand Down Expand Up @@ -171,7 +171,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let transfer_buffer = gpu
.create_transfer_buffer()
.with_size(vertices_len_bytes.max(indices_len_bytes) as u32)
.with_usage(TransferBufferUsage::Upload)
.with_usage(TransferBufferUsage::UPLOAD)
.build()?;

// We need to start a copy pass in order to transfer data to the GPU
Expand All @@ -183,14 +183,14 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
&gpu,
&transfer_buffer,
&copy_pass,
BufferUsageFlags::Vertex,
BufferUsageFlags::VERTEX,
&CUBE_VERTICES,
)?;
let index_buffer = create_buffer_with_data(
&gpu,
&transfer_buffer,
&copy_pass,
BufferUsageFlags::Index,
BufferUsageFlags::INDEX,
&CUBE_INDICES,
)?;

Expand All @@ -211,7 +211,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
.with_num_levels(1)
.with_sample_count(SampleCount::NoMultiSampling)
.with_format(TextureFormat::D16Unorm)
.with_usage(TextureUsage::Sampler | TextureUsage::DepthStencilTarget),
.with_usage(TextureUsage::SAMPLER | TextureUsage::DEPTH_STENCIL_TARGET),
)?;

let mut rotation = 45.0f32;
Expand All @@ -238,19 +238,19 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
// Again, like in gpu-clear.rs, we'd want to define basic operations for our cube
let color_targets = [ColorTargetInfo::default()
.with_texture(&swapchain)
.with_load_op(LoadOp::Clear)
.with_store_op(StoreOp::Store)
.with_load_op(LoadOp::CLEAR)
.with_store_op(StoreOp::STORE)
.with_clear_color(Color::RGB(128, 128, 128))];
// This time, however, we want depth testing, so we need to also target a depth texture buffer
let depth_target = DepthStencilTargetInfo::new()
.with_texture(&mut depth_texture)
.with_cycle(true)
.with_clear_depth(1.0)
.with_clear_stencil(0)
.with_load_op(LoadOp::Clear)
.with_store_op(StoreOp::Store)
.with_stencil_load_op(LoadOp::Clear)
.with_stencil_store_op(StoreOp::Store);
.with_load_op(LoadOp::CLEAR)
.with_store_op(StoreOp::STORE)
.with_stencil_load_op(LoadOp::CLEAR)
.with_stencil_store_op(StoreOp::STORE);
let render_pass =
gpu.begin_render_pass(&command_buffer, &color_targets, Some(&depth_target))?;

Expand All @@ -268,7 +268,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
&BufferBinding::new()
.with_buffer(&index_buffer)
.with_offset(0),
IndexElementSize::_16Bit,
IndexElementSize::_16BIT,
);

// Set the rotation uniform for our cube vert shader
Expand Down
32 changes: 16 additions & 16 deletions examples/gpu-texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
.map_err(|e| e.to_string())?;

let gpu = sdl3::gpu::Device::new(
ShaderFormat::SpirV | ShaderFormat::Dxil | ShaderFormat::Dxbc | ShaderFormat::MetalLib,
ShaderFormat::SPIRV | ShaderFormat::DXIL | ShaderFormat::DXBC | ShaderFormat::METALLIB,
true,
)?
.with_window(&window)?;
Expand All @@ -203,7 +203,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let vert_shader = gpu
.create_shader()
.with_code(
ShaderFormat::SpirV,
ShaderFormat::SPIRV,
include_bytes!("shaders/cube-texture.vert.spv"),
ShaderStage::Vertex,
)
Expand All @@ -213,7 +213,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let frag_shader = gpu
.create_shader()
.with_code(
ShaderFormat::SpirV,
ShaderFormat::SPIRV,
include_bytes!("shaders/cube-texture.frag.spv"),
ShaderStage::Fragment,
)
Expand Down Expand Up @@ -284,7 +284,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let transfer_buffer = gpu
.create_transfer_buffer()
.with_size(vertices_len_bytes.max(indices_len_bytes) as u32)
.with_usage(TransferBufferUsage::Upload)
.with_usage(TransferBufferUsage::UPLOAD)
.build()?;

// We need to start a copy pass in order to transfer data to the GPU
Expand All @@ -296,14 +296,14 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
&gpu,
&transfer_buffer,
&copy_pass,
BufferUsageFlags::Vertex,
BufferUsageFlags::VERTEX,
&CUBE_VERTICES,
)?;
let index_buffer = create_buffer_with_data(
&gpu,
&transfer_buffer,
&copy_pass,
BufferUsageFlags::Index,
BufferUsageFlags::INDEX,
&CUBE_INDICES,
)?;

Expand Down Expand Up @@ -338,7 +338,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
.with_num_levels(1)
.with_sample_count(SampleCount::NoMultiSampling)
.with_format(TextureFormat::D16Unorm)
.with_usage(TextureUsage::Sampler | TextureUsage::DepthStencilTarget),
.with_usage(TextureUsage::SAMPLER | TextureUsage::DEPTH_STENCIL_TARGET),
)?;

let mut rotation = 45.0f32;
Expand All @@ -365,19 +365,19 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
// Again, like in gpu-clear.rs, we'd want to define basic operations for our cube
let color_targets = [ColorTargetInfo::default()
.with_texture(&swapchain)
.with_load_op(LoadOp::Clear)
.with_store_op(StoreOp::Store)
.with_load_op(LoadOp::CLEAR)
.with_store_op(StoreOp::STORE)
.with_clear_color(Color::RGB(128, 128, 128))];
// This time, however, we want depth testing, so we need to also target a depth texture buffer
let depth_target = DepthStencilTargetInfo::new()
.with_texture(&mut depth_texture)
.with_cycle(true)
.with_clear_depth(1.0)
.with_clear_stencil(0)
.with_load_op(LoadOp::Clear)
.with_store_op(StoreOp::Store)
.with_stencil_load_op(LoadOp::Clear)
.with_stencil_store_op(StoreOp::Store);
.with_load_op(LoadOp::CLEAR)
.with_store_op(StoreOp::STORE)
.with_stencil_load_op(LoadOp::CLEAR)
.with_stencil_store_op(StoreOp::STORE);
let render_pass =
gpu.begin_render_pass(&command_buffer, &color_targets, Some(&depth_target))?;

Expand All @@ -395,7 +395,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
&BufferBinding::new()
.with_buffer(&index_buffer)
.with_offset(0),
IndexElementSize::_16Bit,
IndexElementSize::_16BIT,
);
render_pass.bind_fragment_samplers(
0,
Expand Down Expand Up @@ -440,13 +440,13 @@ fn create_texture_from_image(
.with_height(image_size.1)
.with_layer_count_or_depth(1)
.with_num_levels(1)
.with_usage(TextureUsage::Sampler),
.with_usage(TextureUsage::SAMPLER),
)?;

let transfer_buffer = gpu
.create_transfer_buffer()
.with_size(size_bytes)
.with_usage(TransferBufferUsage::Upload)
.with_usage(TransferBufferUsage::UPLOAD)
.build()?;

let mut buffer_mem = transfer_buffer.map::<u8>(gpu, false);
Expand Down
10 changes: 5 additions & 5 deletions examples/gpu-triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
// aren't using any shaders)
// We'll also turn on debug mode to true, so we get debug stuff
let gpu = Device::new(
ShaderFormat::SpirV | ShaderFormat::Dxil | ShaderFormat::Dxbc | ShaderFormat::MetalLib,
ShaderFormat::SPIRV | ShaderFormat::DXIL | ShaderFormat::DXBC | ShaderFormat::METALLIB,
true,
)?
.with_window(&window)?;
Expand All @@ -36,13 +36,13 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
// Our shaders, require to be precompiled by a SPIR-V compiler beforehand
let vs_shader = gpu
.create_shader()
.with_code(ShaderFormat::SpirV, vs_source, ShaderStage::Vertex)
.with_code(ShaderFormat::SPIRV, vs_source, ShaderStage::Vertex)
.with_entrypoint(c"main")
.build()?;

let fs_shader = gpu
.create_shader()
.with_code(ShaderFormat::SpirV, fs_source, ShaderStage::Fragment)
.with_code(ShaderFormat::SPIRV, fs_source, ShaderStage::Fragment)
.with_entrypoint(c"main")
.build()?;

Expand Down Expand Up @@ -95,8 +95,8 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let color_targets = [
ColorTargetInfo::default()
.with_texture(&swapchain)
.with_load_op(LoadOp::Clear)
.with_store_op(StoreOp::Store)
.with_load_op(LoadOp::CLEAR)
.with_store_op(StoreOp::STORE)
.with_clear_color(Color::RGB(5, 3, 255)), //blue with small RG bias
];
let render_pass = gpu.begin_render_pass(&command_buffer, &color_targets, None)?;
Expand Down
10 changes: 5 additions & 5 deletions src/sdl3/gpu/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use std::sync::Arc;
use sys::gpu::{
SDL_CreateGPUBuffer, SDL_CreateGPUTransferBuffer, SDL_GPUBuffer, SDL_GPUBufferBinding,
SDL_GPUBufferCreateInfo, SDL_GPUBufferRegion, SDL_GPUTransferBuffer,
SDL_GPUTransferBufferCreateInfo, SDL_GPUTransferBufferLocation, SDL_GPUTransferBufferUsage,
SDL_GPUVertexBufferDescription, SDL_GPUVertexInputRate, SDL_MapGPUTransferBuffer,
SDL_ReleaseGPUBuffer, SDL_ReleaseGPUTransferBuffer, SDL_UnmapGPUTransferBuffer,
SDL_GPUTransferBufferCreateInfo, SDL_GPUTransferBufferLocation, SDL_GPUVertexBufferDescription,
SDL_GPUVertexInputRate, SDL_MapGPUTransferBuffer, SDL_ReleaseGPUBuffer,
SDL_ReleaseGPUTransferBuffer, SDL_UnmapGPUTransferBuffer,
};

#[repr(C)]
Expand Down Expand Up @@ -157,7 +157,7 @@ impl<'a> BufferBuilder<'a> {
}

pub fn with_usage(mut self, value: BufferUsageFlags) -> Self {
self.inner.usage = value as u32;
self.inner.usage = value.0;
self
}

Expand Down Expand Up @@ -267,7 +267,7 @@ impl<'a> TransferBufferBuilder<'a> {

/// How the buffer will be used.
pub fn with_usage(mut self, value: TransferBufferUsage) -> Self {
self.inner.usage = SDL_GPUTransferBufferUsage(value as i32);
self.inner.usage = value;
self
}

Expand Down
2 changes: 1 addition & 1 deletion src/sdl3/gpu/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Device {

#[doc(alias = "SDL_CreateGPUDevice")]
pub fn new(flags: ShaderFormat, debug_mode: bool) -> Result<Self, Error> {
let raw_device = unsafe { SDL_CreateGPUDevice(flags as u32, debug_mode, std::ptr::null()) };
let raw_device = unsafe { SDL_CreateGPUDevice(flags.0, debug_mode, std::ptr::null()) };
if raw_device.is_null() {
Err(get_error())
} else {
Expand Down
Loading
Loading