Skip to content

Commit

Permalink
[Vulkan] Make the compute sample work for one frame
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Jan 26, 2024
1 parent c047e59 commit 0cacbee
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ void kinc_internal_restore_render_target(kinc_g5_command_list_t *list, struct ki
scissor.offset.y = 0;
vkCmdSetScissor(list->impl._buffer, 0, 1, &scissor);

if (onBackBuffer) {
if (onBackBuffer && in_render_pass) {
return;
}

Expand Down Expand Up @@ -542,19 +542,20 @@ void kinc_internal_restore_render_target(kinc_g5_command_list_t *list, struct ki
}

void kinc_g5_command_list_set_render_targets(kinc_g5_command_list_t *list, struct kinc_g5_render_target **targets, int count) {
for (int i = 0; i < count; ++i) {
currentRenderTargets[i] = targets[i];
}
for (int i = count; i < 8; ++i) {
currentRenderTargets[i] = NULL;
}

if (targets[0]->framebuffer_index >= 0) {
kinc_internal_restore_render_target(list, targets[0]);
return;
}

endPass(list);

for (int i = 0; i < count; ++i) {
currentRenderTargets[i] = targets[i];
}
for (int i = count; i < 8; ++i) {
currentRenderTargets[i] = NULL;
}
onBackBuffer = false;

VkClearValue clear_values[9];
Expand Down Expand Up @@ -879,10 +880,15 @@ void kinc_g5_command_list_set_texture(kinc_g5_command_list_t *list, kinc_g5_text
}

void kinc_g5_command_list_set_sampler(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_sampler_t *sampler) {
vulkanSamplers[unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]] = sampler->impl.sampler;
if (unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT] >= 0) {
vulkanSamplers[unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]] = sampler->impl.sampler;
}
}

void kinc_g5_command_list_set_image_texture(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture) {}
void kinc_g5_command_list_set_image_texture(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture) {
vulkanTextures[unit.stages[KINC_G5_SHADER_TYPE_COMPUTE]] = texture;
vulkanRenderTargets[unit.stages[KINC_G5_SHADER_TYPE_COMPUTE]] = NULL;
}

void kinc_g5_command_list_set_render_target_face(kinc_g5_command_list_t *list, kinc_g5_render_target_t *texture, int face) {}

Expand Down Expand Up @@ -919,14 +925,21 @@ void kinc_g5_command_list_set_compute_shader(kinc_g5_command_list_t *list, kinc_
}

void kinc_g5_command_list_compute(kinc_g5_command_list_t *list, int x, int y, int z) {
endPass(list);
if (in_render_pass) {
vkCmdEndRenderPass(list->impl._buffer);
in_render_pass = false;
}

vkCmdDispatch(list->impl._buffer, x, y, z);

int render_target_count = 0;
for (int i = 0; i < 8; ++i) {
if (currentRenderTargets[i] == NULL) {
break;
}
++render_target_count;
}
kinc_g5_command_list_set_render_targets(list, currentRenderTargets, render_target_count);
if (render_target_count > 0) {
kinc_g5_command_list_set_render_targets(list, currentRenderTargets, render_target_count);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ kinc_g5_texture_unit_t kinc_g5_compute_shader_get_texture_unit(kinc_g5_compute_s
for (int i = 0; i < KINC_G5_SHADER_TYPE_COUNT; ++i) {
unit.stages[i] = -1;
}
unit.stages[KINC_G5_SHADER_TYPE_COMPUTE] = 0;
/*kinc_internal_hash_index_t *compute_unit = findComputeTextureUnit(shader->impl.textures, hash);
if (compute_unit == NULL) {
#ifndef NDEBUG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ VkDescriptorSet getDescriptorSet() {
}
texture_count++;
}
tex_desc[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
tex_desc[i].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
}

VkWriteDescriptorSet writes[18];
Expand Down Expand Up @@ -1021,8 +1021,8 @@ static VkDescriptorSet get_compute_descriptor_set() {
int texture_count = 0;
for (int i = 0; i < 16; ++i) {
if (vulkanTextures[i] != NULL) {
assert(vulkanSamplers[i] != VK_NULL_HANDLE);
tex_desc[i].sampler = vulkanSamplers[i];
// assert(vulkanSamplers[i] != VK_NULL_HANDLE);
tex_desc[i].sampler = VK_NULL_HANDLE; // vulkanSamplers[i];
tex_desc[i].imageView = vulkanTextures[i]->impl.texture.view;
texture_count++;
}
Expand All @@ -1037,7 +1037,7 @@ static VkDescriptorSet get_compute_descriptor_set() {
}
texture_count++;
}
tex_desc[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
tex_desc[i].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
}

VkWriteDescriptorSet writes[18];
Expand All @@ -1062,7 +1062,7 @@ static VkDescriptorSet get_compute_descriptor_set() {
writes[i].dstSet = descriptor_set;
writes[i].dstBinding = i;
writes[i].descriptorCount = 1;
writes[i].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
writes[i].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
writes[i].pImageInfo = &tex_desc[i - 2];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ void kinc_g5_texture_init_from_image(kinc_g5_texture_t *texture, kinc_image_t *i
if ((props.linearTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) && !use_staging_buffer) {
// Device can texture using linear textures
prepare_texture_image((uint8_t *)image->data, (uint32_t)image->width, (uint32_t)image->height, &texture->impl.texture, VK_IMAGE_TILING_LINEAR,
VK_IMAGE_USAGE_SAMPLED_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &texture->impl.deviceSize, tex_format);
VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &texture->impl.deviceSize,
tex_format);

flush_init_cmd();
}
Expand All @@ -247,8 +248,8 @@ void kinc_g5_texture_init_from_image(kinc_g5_texture_t *texture, kinc_image_t *i
prepare_texture_image((uint8_t *)image->data, (uint32_t)image->width, (uint32_t)image->height, &staging_texture, VK_IMAGE_TILING_LINEAR,
VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &texture->impl.deviceSize, tex_format);
prepare_texture_image((uint8_t *)image->data, (uint32_t)image->width, (uint32_t)image->height, &texture->impl.texture, VK_IMAGE_TILING_OPTIMAL,
(VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT), VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &texture->impl.deviceSize,
tex_format);
(VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT), VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
&texture->impl.deviceSize, tex_format);
set_image_layout(staging_texture.image, VK_IMAGE_ASPECT_COLOR_BIT, staging_texture.imageLayout, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
set_image_layout(texture->impl.texture.image, VK_IMAGE_ASPECT_COLOR_BIT, texture->impl.texture.imageLayout, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);

Expand Down Expand Up @@ -315,8 +316,8 @@ void kinc_g5_texture_init(kinc_g5_texture_t *texture, int width, int height, kin
vkGetPhysicalDeviceFormatProperties(vk_ctx.gpu, tex_format, &props);

// Device can texture using linear textures
prepare_texture_image(NULL, (uint32_t)width, (uint32_t)height, &texture->impl.texture, VK_IMAGE_TILING_LINEAR, VK_IMAGE_USAGE_SAMPLED_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &texture->impl.deviceSize, tex_format);
prepare_texture_image(NULL, (uint32_t)width, (uint32_t)height, &texture->impl.texture, VK_IMAGE_TILING_LINEAR,
VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &texture->impl.deviceSize, tex_format);

flush_init_cmd();

Expand Down

0 comments on commit 0cacbee

Please sign in to comment.