Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am attempting to implement a simple compute operation of multiplying all values in a buffer by a push constant.

This shader:

#version 450
layout(local_size_x = 1024, local_size_y = 1, local_size_z = 1) in;

layout(binding = 0) buffer Buffer { float x[]; };
layout(push_constant) uniform PushConsts { float a; };

void main() {
    x[gl_GlobalInvocationID.x] *= a;
}

In my current implementation from my prints I get:

in:
1 2 3 4 5 5 4 3 2 1
[7]

workgroups: (1,1,1)

out:
7 14 3 4 5 5 4 3 2 1
  • 1 2 3 4 5 5 4 3 2 1 being the initial values of the buffer.
  • 7 being the value of the push constant.
  • (1,1,1) being the number of workgroups set.
  • 7 14 3 4 5 5 4 3 2 1 being the resultant values of the buffer after execution.

Strangely only the 1st 2 values have been multiplied by the push constant (which leads me to think only the 1st 2 invocations ran). I suspect this is likely an issue with memory allocation, although I don’t know where it may be coming from.

I would greatly appreciate any help, and if there is anything I can do to make this post better please let me know.

Project link, code file link and the .spv files (.comp files are in the repo, but I thought it worth including these in case you didn't want to compile the .comp files)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
263 views
Welcome To Ask or Share your Answers For Others

1 Answer

Problem originated with setting the size of the VkBuffer and VkDescriptorBufferInfo to the number of values rather than the number of bytes.

Making these changes fixes it:

  • bufferCreateInfo.size = size; -> bufferCreateInfo.size = sizeof(float)*size;
  • bindings[i].range = size; -> bindings[i].range = VK_WHOLE_SIZE;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...