Skip to content

Commit 3da26c3

Browse files
committed
Add some higher level classes
1 parent 0599a05 commit 3da26c3

16 files changed

+1265
-0
lines changed

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ cmake_minimum_required(VERSION 3.11)
22
project(zvulkan)
33

44
set(ZVULKAN_SOURCES
5+
src/gpubindgroup.cpp
6+
src/gpubuffer.cpp
7+
src/gpucommands.cpp
8+
src/gpudevice.cpp
9+
src/gpupipeline.cpp
10+
src/gputexture.cpp
11+
src/gpuqueryset.cpp
512
src/vulkanbuilders.cpp
613
src/vulkandevice.cpp
714
src/vulkaninstance.cpp
@@ -116,6 +123,14 @@ set(ZVULKAN_SOURCES
116123
)
117124

118125
set(ZVULKAN_INCLUDES
126+
include/zvulkan/gpubindgroup.h
127+
include/zvulkan/gpubuffer.h
128+
include/zvulkan/gpucommands.h
129+
include/zvulkan/gpudevice.h
130+
include/zvulkan/gpupipeline.h
131+
include/zvulkan/gputexture.h
132+
include/zvulkan/gpuqueryset.h
133+
include/zvulkan/gpuformat.h
119134
include/zvulkan/vulkanbuilders.h
120135
include/zvulkan/vulkancompatibledevice.h
121136
include/zvulkan/vulkandevice.h

include/zvulkan/gpubindgroup.h

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
#include <memory>
5+
#include <vector>
6+
#include <string>
7+
#include "gpuformat.h"
8+
#include "vulkanobjects.h"
9+
10+
class GPUDevice;
11+
class GPUBuffer;
12+
class GPUExternalTexture;
13+
class GPUSampler;
14+
class GPUTextureView;
15+
class GPUBindGroupLayout;
16+
17+
struct GPUShaderStage
18+
{
19+
enum
20+
{
21+
vertex = 0x1,
22+
fragment = 0x2,
23+
compute = 0x4
24+
};
25+
};
26+
typedef uint32_t GPUShaderStageFlags;
27+
28+
class GPUBufferBinding
29+
{
30+
public:
31+
std::shared_ptr<GPUBuffer> buffer;
32+
size_t offset = 0;
33+
size_t size = 0;
34+
};
35+
36+
class GPUBindGroupBinding
37+
{
38+
public:
39+
int bindingIndex = 0;
40+
struct
41+
{
42+
GPUBufferBinding buffer;
43+
std::shared_ptr<GPUExternalTexture> externalTexture;
44+
std::shared_ptr<GPUSampler> sampler;
45+
std::shared_ptr<GPUTextureView> textureView;
46+
} resource;
47+
};
48+
49+
class GPUBindGroupDesc
50+
{
51+
public:
52+
std::vector<GPUBindGroupBinding> bindings;
53+
std::shared_ptr<GPUBindGroupLayout> layout;
54+
std::string label;
55+
};
56+
57+
class GPUBindGroup
58+
{
59+
public:
60+
GPUBindGroup(GPUDevice* device, const GPUBindGroupDesc& desc);
61+
62+
GPUDevice* device = nullptr;
63+
GPUBindGroupDesc desc;
64+
65+
std::unique_ptr<VulkanDescriptorSet> descriptorSet;
66+
};
67+
68+
enum class GPUBindGroupLayoutBufferType
69+
{
70+
uniform,
71+
readOnlyStorage,
72+
storage,
73+
};
74+
75+
enum class GPUBindGroupLayoutBindingType
76+
{
77+
buffer,
78+
externalTexture,
79+
sampler,
80+
storageTexture,
81+
texture
82+
};
83+
84+
enum class GPUSamplerType
85+
{
86+
filtering,
87+
comparison,
88+
nonFiltering
89+
};
90+
91+
enum class GPUAccess
92+
{
93+
readOnly,
94+
readWrite,
95+
writeOnly
96+
};
97+
98+
enum class GPUViewDimension
99+
{
100+
image1D,
101+
image2D,
102+
image2DArray,
103+
imageCube,
104+
imageCubeArray,
105+
image3D
106+
};
107+
108+
enum class GPUViewSampleType
109+
{
110+
float32,
111+
depth,
112+
sint,
113+
uint,
114+
unfilteredFloat
115+
};
116+
117+
class GPUBindGroupLayoutBinding
118+
{
119+
public:
120+
int bindingIndex = 0;
121+
GPUShaderStageFlags visibility = GPUShaderStage::fragment;
122+
GPUBindGroupLayoutBindingType type = {};
123+
struct
124+
{
125+
bool hasDynamicOffset = false;
126+
int minBindingSize = 0;
127+
GPUBindGroupLayoutBufferType type = GPUBindGroupLayoutBufferType::uniform;
128+
} buffer;
129+
struct
130+
{
131+
GPUSamplerType type = GPUSamplerType::filtering;
132+
} sampler;
133+
struct
134+
{
135+
GPUAccess access = GPUAccess::readOnly;
136+
GPUFormat format = {};
137+
GPUViewDimension viewDimension = GPUViewDimension::image2D;
138+
} storageTexture;
139+
struct
140+
{
141+
bool multisampled = false;
142+
GPUViewSampleType sampleType = GPUViewSampleType::float32;
143+
GPUViewDimension viewDimension = GPUViewDimension::image2D;
144+
} texture;
145+
};
146+
147+
class GPUBindGroupLayoutDesc
148+
{
149+
public:
150+
std::vector<GPUBindGroupLayoutBinding> bindings;
151+
std::string label;
152+
};
153+
154+
class GPUBindGroupLayout
155+
{
156+
public:
157+
GPUBindGroupLayout(GPUDevice* device, const GPUBindGroupLayoutDesc& desc);
158+
159+
GPUDevice* device = nullptr;
160+
GPUBindGroupLayoutDesc desc;
161+
162+
std::unique_ptr<VulkanDescriptorSetLayout> layout;
163+
std::unique_ptr<VulkanDescriptorPool> pool;
164+
};

include/zvulkan/gpubuffer.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
#include <string>
5+
#include "vulkanobjects.h"
6+
7+
class GPUDevice;
8+
class GPUPromise;
9+
10+
struct GPUUsage
11+
{
12+
enum
13+
{
14+
mapRead = 0x1,
15+
mapWrite = 0x2,
16+
copySrc = 0x4,
17+
copyDst = 0x8,
18+
index = 0x10,
19+
vertex = 0x20,
20+
uniform = 0x40,
21+
storage = 0x80,
22+
indirect = 0x100,
23+
queryResolve = 0x200,
24+
};
25+
};
26+
typedef uint32_t GPUUsageFlags;
27+
28+
class GPUBufferDesc
29+
{
30+
public:
31+
std::string label;
32+
bool mappedAtCreation = false;
33+
size_t size = 0;
34+
GPUUsageFlags usage = 0;
35+
};
36+
37+
class GPUMappedRange
38+
{
39+
public:
40+
void* data = nullptr;
41+
size_t offset = 0;
42+
size_t size = 0;
43+
};
44+
45+
class GPUBuffer
46+
{
47+
public:
48+
GPUBuffer(GPUDevice* device, const GPUBufferDesc& desc);
49+
50+
const GPUMappedRange& getMappedRange() const { return mappedRange; }
51+
52+
GPUPromise mapAsync();
53+
void unmap();
54+
55+
void destroy();
56+
57+
GPUDevice* device = nullptr;
58+
GPUBufferDesc desc;
59+
60+
std::unique_ptr<VulkanBuffer> buffer;
61+
62+
private:
63+
GPUMappedRange mappedRange;
64+
};

0 commit comments

Comments
 (0)