Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lamarrr committed Oct 30, 2023
1 parent 5d40231 commit e521bc7
Show file tree
Hide file tree
Showing 8 changed files with 734 additions and 1,713 deletions.
24 changes: 12 additions & 12 deletions ashura/include/ashura/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ struct Array
using Size = size_t;
using Index = size_t;

constexpr Array() : size_{0}
constexpr Array() : rep_{}, size_{0}
{
}

template <size_t SrcSize>
constexpr Array(T const (&arr)[SrcSize]) : size_{SrcSize}
constexpr Array(T const (&arr)[SrcSize]) : rep_{}, size_{SrcSize}
{
static_assert(SrcSize <= capacity);
for (size_t i = 0; i < SrcSize; i++)
Expand All @@ -47,15 +47,15 @@ struct Array
}
}

constexpr Array(Array const &other) : size_{other.size_}
constexpr Array(Array const &other) : rep_{}, size_{other.size_}
{
for (size_t i = 0; i < other.size_; i++)
{
new (data() + i) T{other.data()[i]};
}
}

constexpr Array(Array &&other) : size_{other.size_}
constexpr Array(Array &&other) : rep_{}, size_{other.size_}
{
for (size_t i = 0; i < other.size_; i++)
{
Expand All @@ -79,7 +79,7 @@ struct Array

constexpr Array &operator=(Array &&other)
{
this->~~Array();
this->~Array();
new (this) Array{(Array &&) other};
return *this;
}
Expand Down Expand Up @@ -119,12 +119,12 @@ struct Array

constexpr T *data()
{
return &storage_[0].value;
return data_;
}

constexpr T const *data() const
{
return &storage_[0].value;
return data_;
}

constexpr stx::Span<T> span()
Expand Down Expand Up @@ -177,7 +177,7 @@ struct Array
template <typename... Args>
constexpr void push_inplace_unsafe(Args &&...args)
{
new (&(storage_[size_].value)) T{((Args &&) args)...};
new (data_ + size_) T{((Args &&) args)...};
size_++;
}

Expand All @@ -199,11 +199,11 @@ struct Array

constexpr void extend_move_unsafe(stx::Span<T> span);

union Storage
union
{
T value;
uint8_t rep[sizeof(T)] = {};
} storage_[capacity];
T data_[capacity];
uint8_t rep_[capacity * sizeof(T)] = {};
};
size_t size_ = 0;
};

Expand Down
93 changes: 46 additions & 47 deletions ashura/include/ashura/gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
#include "stx/enum.h"
#include "stx/span.h"

#define ASH_DEFINE_HANDLE(handle) \
typedef struct handle##_T; \
typedef handle##_T *handle;
#define ASH_DEFINE_HANDLE(handle) typedef struct handle##_T *handle;

namespace ash
{
Expand All @@ -21,9 +19,9 @@ namespace gfx
constexpr u32 REMAINING_MIP_LEVELS = ~0U;
constexpr u32 REMAINING_ARRAY_LAYERS = ~0U;
constexpr u64 WHOLE_SIZE = ~0ULL;
constexpr u8 MAX_COLOR_ATTACHMENTS = 8;
constexpr u8 MAX_VERTEX_ATTRIBUTES = 16;
constexpr u8 MAX_PUSH_CONSTANT_SIZE = 128;
constexpr u32 MAX_COLOR_ATTACHMENTS = 8;
constexpr u32 MAX_VERTEX_ATTRIBUTES = 16;
constexpr u32 MAX_PUSH_CONSTANT_SIZE = 128;

ASH_DEFINE_HANDLE(Buffer);
/// format interpretation of a buffer's contents
Expand Down Expand Up @@ -606,7 +604,6 @@ enum class BufferUsageScope : u32
STX_DEFINE_ENUM_BIT_OPS(BufferUsageScope)

/// used for synchronization of state-mutating commands

/// must provide initial clear value or initial buffer initializer
// images implicitly have TransferDst usage scope
enum class ImageUsageScope : u32
Expand Down Expand Up @@ -770,9 +767,26 @@ struct FormatProperties
FormatFeatures buffer_features = FormatFeatures::None;
};

struct ImageSubresourceRange
{
ImageAspects aspects = ImageAspects::None;
u32 first_mip_level = 0;
u32 num_mip_levels = 0;
u32 first_array_layer = 0;
u32 num_array_layers = 0;
};

struct ImageSubresourceLayers
{
ImageAspects aspects = ImageAspects::None;
u32 mip_level = 0;
u32 first_array_layer = 0;
u32 num_array_layers = 0;
};

struct BufferDesc
{
char const *name = nullptr;
char const *label = nullptr;
u64 size = 0;
MemoryProperties properties = MemoryProperties::None;
BufferUsage usage = BufferUsage::None;
Expand All @@ -781,7 +795,7 @@ struct BufferDesc

struct BufferViewDesc
{
char const *name = nullptr;
char const *label = nullptr;
Buffer buffer = nullptr;
Format view_format = Format::Undefined;
u64 offset = 0;
Expand All @@ -790,34 +804,34 @@ struct BufferViewDesc

struct ImageDesc
{
char const *name = nullptr;
char const *label = nullptr;
ImageType type = ImageType::Type1D;
Format format = Format::Undefined;
ImageUsage usage = ImageUsage::None;
ImageUsageScope scope = ImageUsageScope::None;
ImageAspects aspects = ImageAspects::None;
Extent3D extent = {};
u32 mips = 0;
u32 mip_levels = 0;
u32 array_layers = 0;
};

struct ImageViewDesc
{
char const *name = nullptr;
char const *label = nullptr;
Image image = nullptr;
ImageViewType view_type = ImageViewType::Type1D;
Format view_format = Format::Undefined;
ComponentMapping mapping = ComponentMapping{};
ImageAspects aspects = ImageAspects::None;
u32 first_mip_level = 0;
u32 num_mip_levels = 0;
u32 first_array_layer = 0;
u32 num_array_layers = 0;
ImageAspects aspects = ImageAspects::None;
};

struct SamplerDesc
{
char const *name = nullptr;
char const *label = nullptr;
Filter mag_filter = Filter::Nearest;
Filter min_filter = Filter::Nearest;
SamplerMipMapMode mip_map_mode = SamplerMipMapMode::Nearest;
Expand Down Expand Up @@ -846,20 +860,19 @@ struct RenderPassAttachment

struct RenderPassDesc
{
char const *name = nullptr;
char const *label = nullptr;
stx::Array<RenderPassAttachment, MAX_COLOR_ATTACHMENTS> color_attachments = {};
stx::Array<RenderPassAttachment, MAX_COLOR_ATTACHMENTS> input_attachments = {};
RenderPassAttachment depth_stencil_attachment = {};
};

struct FramebufferDesc
{
char const *name = nullptr;
char const *label = nullptr;
RenderPass renderpass = nullptr;
Extent extent = {};
u32 layers = 0;
stx::Array<ImageView, MAX_COLOR_ATTACHMENTS> color_attachments = {};
stx::Array<ImageView, MAX_COLOR_ATTACHMENTS> input_attachments = {};
ImageView depth_stencil_attachment = nullptr;
};

Expand Down Expand Up @@ -984,7 +997,7 @@ struct ShaderStageDesc

struct ComputePipelineDesc
{
char const *name = nullptr;
char const *label = nullptr;
ShaderStageDesc compute_shader = {};
DescriptorSetLayout descriptor_set_layout = nullptr;
};
Expand Down Expand Up @@ -1052,7 +1065,7 @@ struct PipelineRasterizationState

struct GraphicsPipelineDesc
{
char const *name = nullptr;
char const *label = nullptr;
ShaderStageDesc vertex_shader_stage = {};
ShaderStageDesc fragment_shader_stage = {};
RenderPass render_pass = nullptr;
Expand All @@ -1075,42 +1088,27 @@ struct BufferCopy

struct BufferImageCopy
{
u64 buffer_offset = 0;
u32 buffer_row_length = 0;
u32 buffer_image_height = 0;
URect3D image_area = {};
u32 image_mip_level = 0;
u32 first_array_layer = 0;
u32 num_array_layers = 0;
ImageAspects image_aspects = ImageAspects::None;
u64 buffer_offset = 0;
u32 buffer_row_length = 0;
u32 buffer_image_height = 0;
URect3D image_area = {};
ImageSubresourceLayers image_layers = {};
};

struct ImageCopy
{
URect3D src_area = {};
u32 src_mip_level = 0;
u32 src_first_array_layer = 0;
u32 src_num_array_layers = 0;
ImageAspects src_aspects = ImageAspects::None;
Offset3D dst_offset = {};
u32 dst_mip_level = 0;
u32 dst_first_array_layer = 0;
u32 dst_num_array_layers = 0;
ImageAspects dst_aspects = ImageAspects::None;
URect3D src_area = {};
ImageSubresourceLayers src_layers = {};
Offset3D dst_offset = {};
ImageSubresourceLayers dst_layers = {};
};

struct ImageBlit
{
URect3D src_area = {};
u32 src_mip_level = 0;
u32 src_first_array_layer = 0;
u32 src_num_array_layers = 0;
ImageAspects src_aspects = ImageAspects::None;
URect3D dst_area = {};
u32 dst_mip_level = 0;
u32 dst_first_array_layer = 0;
u32 dst_num_array_layers = 0;
ImageAspects dst_aspects = ImageAspects::None;
URect3D src_area = {};
ImageSubresourceLayers src_layers = {};
URect3D dst_area = {};
ImageSubresourceLayers dst_layers = {};
};

union Color
Expand Down Expand Up @@ -1166,6 +1164,7 @@ struct ImageMemoryBarrier
ImageLayout old_layout = ImageLayout::Undefined;
ImageLayout new_layout = ImageLayout::Undefined;
Image image = nullptr;
ImageAspects aspects = ImageAspects::None;
};

// RESOURCES hold the backend/RHI handles
Expand Down
Loading

0 comments on commit e521bc7

Please sign in to comment.