Skip to content

Commit

Permalink
update sto
Browse files Browse the repository at this point in the history
  • Loading branch information
ccsdu2004 committed Aug 7, 2022
1 parent b9a0fd0 commit f27f488
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
16 changes: 8 additions & 8 deletions demo/main-storage-texel-buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const float texels[] = {1.0f, 0.0f, 0.0f,
VK_Context *context = nullptr;
VK_Pipeline *pipeline = nullptr;

uint32_t updateUniformBufferData(char *&data, uint32_t size)
uint32_t updateTexelBufferData(char *&data, uint32_t size)
{
int length = sizeof(texels);
memcpy(data, texels, length);
Expand All @@ -52,7 +52,7 @@ void onMouseButtonCallback(int button, int action, int mods)
int main()
{
VK_ContextConfig config;
config.debug = false;
config.debug = true;
config.name = "Storage texelbuffer";
config.mouseCallback = onMouseButtonCallback;

Expand All @@ -76,8 +76,8 @@ int main()

VkFormatProperties props;
vkGetPhysicalDeviceFormatProperties(context->getPhysicalDevice(), VK_FORMAT_R32_SFLOAT, &props);
if (!(props.bufferFeatures & VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT)) {
std::cout << "R32_SFLOAT format unsupported for texel buffer\n";
if (!(props.bufferFeatures & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT)) {
std::cout << "R32_SFLOAT format unsupported for storage texel buffer\n";
context->release();
return 0;
}
Expand All @@ -90,12 +90,12 @@ int main()

shaderSet->appendVertexAttributeDescription(0, sizeof (float) * 3, VK_FORMAT_R32G32B32_SFLOAT, 0);
shaderSet->appendVertexAttributeDescription(1, sizeof (float) * 4, VK_FORMAT_R32G32B32A32_SFLOAT,
sizeof(float) * 3);
sizeof(float) * 3);

shaderSet->appendVertexInputBindingDescription(7 * sizeof(float), 0, VK_VERTEX_INPUT_RATE_VERTEX);

VkDescriptorSetLayoutBinding uniformBinding = VK_ShaderSet::createDescriptorSetLayoutBinding(0,
VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, VK_SHADER_STAGE_VERTEX_BIT);
VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, VK_SHADER_STAGE_VERTEX_BIT);
shaderSet->addDescriptorSetLayoutBinding(uniformBinding);

if (!shaderSet->isValid()) {
Expand All @@ -106,15 +106,15 @@ int main()
}

auto ubo = shaderSet->addStorageTexelBuffer(0, sizeof(texels));
ubo->setWriteDataCallback(updateUniformBufferData);
ubo->setWriteDataCallback(updateTexelBufferData);

context->initVulkanContext();
pipeline = context->createPipeline(shaderSet);
pipeline->getDynamicState()->addDynamicState(VK_DYNAMIC_STATE_VIEWPORT);
pipeline->create();
pipeline->getDynamicState()->applyDynamicViewport({0, 0, 480, 480, 0, 1});

auto buffer = context->createVertexBuffer(vertices, 3 + 4, indices);
auto buffer = context->createVertexBuffer(vertices, 7, indices);
pipeline->addRenderBuffer(buffer);

context->createCommandBuffers();
Expand Down
Binary file added screenshots/storage-texel-buffer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions shader/storageTexelBuffer/texel-buffer.vert
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#version 400
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
layout(location = 0) in vec3 position;
layout(location = 1) in vec4 color;

layout (binding = 0) uniform samplerBuffer texels;
layout (binding = 0,rgba32f) uniform readonly imageBuffer texels;
layout (location = 0) out vec4 outColor;

void main() {
float r = texelFetch(texels, gl_VertexIndex*3).r;
float g = texelFetch(texels, gl_VertexIndex*3+1).r;
float b = texelFetch(texels, gl_VertexIndex*3+2).r;
outColor = vec4(r, g, b, 1.0);
float r = imageLoad(texels, gl_VertexIndex*3).r;
float g = imageLoad(texels, gl_VertexIndex*3+1).r;
float b = imageLoad(texels, gl_VertexIndex*3+2).r;
outColor = vec4(r,g,b,1.0);
gl_Position = vec4(position, 1.0);
}
Binary file modified shader/storageTexelBuffer/texel-buffer.vert.spv
Binary file not shown.
6 changes: 3 additions & 3 deletions source/VK_ValidationLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ VkBool32 VK_ValidationLayer::debugCallback(VkDebugUtilsMessageSeverityFlagBitsEX
const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData, void *pUserData)
{
(void)pUserData;
//if (messageSeverity == VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT)
std::cerr << "message type:" << messageType << " validation layer: " << pCallbackData->pMessage <<
std::endl;
if (messageSeverity == VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT)
std::cerr << "message type:" << messageType << " validation layer: " << pCallbackData->pMessage <<
std::endl;
return VK_TRUE;
}

Expand Down

0 comments on commit f27f488

Please sign in to comment.