Blender V5.0
vk_state_manager.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "vk_state_manager.hh"
10#include "vk_context.hh"
11#include "vk_index_buffer.hh"
12#include "vk_shader.hh"
13#include "vk_storage_buffer.hh"
14#include "vk_texture.hh"
15#include "vk_vertex_buffer.hh"
16
17#include "GPU_capabilities.hh"
18
19namespace blender::gpu {
20
22{
23 /* Intentionally empty. State is polled during pipeline creation and doesn't need to be applied.
24 * If this leads to issues we should have an active state. */
25}
26
28{
29 /* Intentionally empty. State is polled during pipeline creation and is always forced. */
30}
31
33{
50 if (bool(barrier_bits & GPU_BARRIER_SHADER_IMAGE_ACCESS)) {
51 VKContext &context = *VKContext::get();
52 context.rendering_end();
53 }
54}
55
57{
58 textures_.bind(BindSpaceTextures::Type::Texture, texture, sampler, binding);
59 is_dirty = true;
60}
61
63{
64 textures_.unbind(texture);
65 is_dirty = true;
66}
67
69{
70 textures_.unbind_all();
71 is_dirty = true;
72}
73
74void VKStateManager::image_bind(Texture *tex, int binding)
75{
76 VKTexture *texture = unwrap(tex);
77 images_.bind(texture, binding, TextureWriteFormat(tex->format_get()), this);
78 is_dirty = true;
79}
80
82{
83 VKTexture *texture = unwrap(tex);
84 images_.unbind(texture, this);
85 is_dirty = true;
86}
87
89{
90 images_.unbind_all();
92 is_dirty = true;
93}
94
95void VKStateManager::uniform_buffer_bind(VKUniformBuffer *uniform_buffer, int binding)
96{
97 uniform_buffers_.bind(uniform_buffer, binding);
98 is_dirty = true;
99}
100
102{
103 uniform_buffers_.unbind(uniform_buffer);
104 is_dirty = true;
105}
106
108{
109 uniform_buffers_.unbind_all();
110 is_dirty = true;
111}
112
113void VKStateManager::texel_buffer_bind(VKVertexBuffer &vertex_buffer, int binding)
114{
116 &vertex_buffer,
118 binding);
119 is_dirty = true;
120}
121
123{
124 textures_.unbind(&vertex_buffer);
125 is_dirty = true;
126}
127
129 void *resource,
130 int binding,
131 VkDeviceSize offset)
132{
133 storage_buffers_.bind(resource_type, resource, binding, offset);
134 is_dirty = true;
135}
136
138{
139 storage_buffers_.unbind(resource);
140 is_dirty = true;
141}
142
144{
145 storage_buffers_.unbind_all();
146 is_dirty = true;
147}
148
150{
151 texture_unpack_row_length_ = len;
152}
153
155{
156 return texture_unpack_row_length_;
157}
158
159} // namespace blender::gpu
unsigned int uint
GPUBarrier
Definition GPU_state.hh:29
@ GPU_BARRIER_SHADER_IMAGE_ACCESS
Definition GPU_state.hh:35
std::array< TextureWriteFormat, GPU_MAX_IMAGE > image_formats
TextureFormat format_get() const
static VKContext * get()
void texel_buffer_bind(VKVertexBuffer &vertex_buffer, int slot)
void image_bind(Texture *tex, int unit) override
void uniform_buffer_unbind(VKUniformBuffer *uniform_buffer)
void storage_buffer_unbind(void *resource)
void uniform_buffer_bind(VKUniformBuffer *uniform_buffer, int slot)
void texture_unbind(Texture *tex) override
void texel_buffer_unbind(VKVertexBuffer &vertex_buffer)
void texture_bind(Texture *tex, GPUSamplerState sampler, int unit) override
void image_unbind(Texture *tex) override
void storage_buffer_bind(BindSpaceStorageBuffers::Type resource_type, void *resource, int binding)
void issue_barrier(GPUBarrier barrier_bits) override
void texture_unpack_row_length_set(uint len) override
#define resource
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
static Context * unwrap(GPUContext *ctx)
static constexpr GPUSamplerState default_sampler()
uint len