Vulkan: Push constants #104880
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Depends on
#104518 Vulkan: Initial Compute Shaders support.
blender/blender
#105073 Vulkan: Refactor shader interface.
blender/blender
Reference: blender/blender#104880
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "Jeroen-Bakker/blender:vulkan-push-constants"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What are push constants?
Push constants is a way to quickly provide a small amount of uniform data to shaders.
It should be much quicker than UBOs but a huge limitation is the size of data - spec
requires 128 bytes to be available for a push constant range.
What are the challenges with push constants?
The challenge with push constants is that the limited available size. According to
the Vulkan spec each platform should at least have 128 bytes reserved for push
constants. Current Mesa/AMD drivers supports 256 bytes, but Mesa/Intel is only 128
bytes.
What is our solution?
Some shaders of Blender uses more than these boundaries. When more data is needed
push constants will not be used, but the shader will be patched to use an uniform
buffer instead. This mechanism will be part of the Vulkan backend and shader
developers should not see any difference on API level.
Known limitations
Current state of the vulkan backend does not track resources that are in the
command queue. This patch includes some test cases that identified this issue as
well. See #104771.
Jeroen Bakker referenced this pull request2023-02-17 15:41:58 +01:00
b904eb6859
toa8dc114efc
@ -50,2 +53,3 @@
vk_device, nullptr, 1, &pipeline_info, vk_allocation_callbacks, &vk_pipeline) !=
VK_SUCCESS) {
return VKPipeline();
//return VKPipeline();
This should be fixed.
@ -0,0 +112,4 @@
return 0;
}
size_t size_in_bytes() const
Add
const VKPushConstantsLayout& layout_get() const
as API and clean up the interface.@ -889,0 +926,4 @@
/* Add push constants to the descriptor when push constants are stored in a storage buffer.*/
const VKPushConstantsLayout &push_constants_layout = interface.push_constants_layout_get();
if (push_constants_layout.storage_type_get() ==
VKPushConstantsLayout::StorageType::STORAGE_BUFFER) {
Also check for uniform_buffer
@ -1033,12 +1096,6 @@ std::string VKShader::vertex_interface_declare(const shader::ShaderCreateInfo &i
ss << "layout(location = " << attr.index << ") ";
ss << "in " << to_string(attr.type) << " " << attr.name << ";\n";
}
/* NOTE(D4490): Fix a bug where shader without any vertex attributes do not behave correctly.
Should be removed outside this PR.
@ -58,0 +80,4 @@
.push_constant(Type::FLOAT, "filler2", 32)
.do_static_compilation(true);
/* It is expected that this shader will use uniform buffers and not push constants.*/
Remove line as this is vulkan specific.
@ -119,6 +137,10 @@ void VKDescriptorSet::update(VkDevice vk_device)
descriptor_writes.append(write_descriptor);
}
BLI_assert_msg(image_infos.size() + buffer_infos.size() == descriptor_writes.size(),
Apply to main directly.
WIP: Vulkan: Push constantsto Vulkan: Push constantsJeroen Bakker referenced this pull request2023-02-24 16:28:55 +01:00
Pretty solid. 👍
@ -0,0 +40,4 @@
}
}
void generate_test_data(const float components_mul, const float component_mul)
components_mul > vector_mul
component_mul > scalar_mul
@ -0,0 +39,4 @@
static uint32_t array_components_len(const shader::Type type);
};
template<typename Layout> static uint32_t element_stride(const shader::Type type)
I think
Layout
should beLayoutT
to avoid thinking it is the layout itself (as in the content of a UBO/SSBO).@ -0,0 +228,4 @@
* bytes.*/
BLI_assert(sizeof(T) == 4);
const T *src = input_data;
for (const int i : IndexRange(array_size)) {
You could test if the array is tightly packed and do only one
memcpy
.From my very (very) limited knowledge, code looks good besides note below.
Am getting this failure in tests on my GTX1080 though:
@ -70,0 +70,4 @@
VKPushConstants &push_constants = pipeline.push_constants_get();
/* Update push constants based on their storage type.*/
switch (push_constants.layout_get().storage_type_get()) {
I may be missing something, but this whole
switch
block feels like it does not belong here. It looks way too specific to me.Would rather see that logic as part of the
VKPushConstants
class itself, but no idea if this is doable in practice... At the very least would have it in a dedicated util function ofVKBackend
otherwise?Yes you're right, will move this part into a method of VKPushConstants.
GPUVulkanTest.shader_builtin test case should be removed as it has been replaced by ShaderBuilder. Will do that in main as this isn't part of this PR. #105482
We should also add a nicer message when running GPU debug without having the Vulkan SDK installed. Will add a task for this as well. #105483
Thanks for the input.
Thanks, LGTM now.