Fix instance indexed shader data
This commit is contained in:
1 parent
f308900207
commit
4a726321e9
1 file changed
+70
-65
+70
-65
@@ -141,6 +141,7 @@ i32 main(void) {
|
||||
void *idx_buf_start = (void *)((uptr)vert_idx_buffer.cpu_mapping + vertices_size);
|
||||
memcpy(vert_idx_buffer.cpu_mapping, vertices, vertices_size);
|
||||
memcpy(idx_buf_start, indices, indices_size);
|
||||
gpuFlushBuffer((GpuBufferFlushRequest){ .device = device, .buffer = vert_idx_buffer });
|
||||
|
||||
wpStr8Format(&msg, "Created buffer with size %" PRIu64 " (CPU: %p, GPU: %" PRIu64 ")",
|
||||
vert_idx_buffer.size, vert_idx_buffer.cpu_mapping, vert_idx_buffer.gpu_device_address);
|
||||
@@ -183,7 +184,7 @@ i32 main(void) {
|
||||
Vec3sArray translations = wpArray(
|
||||
vec3s,
|
||||
(vec3s){},
|
||||
(vec3s){ .x = 1.0f, .z = -1.0f },
|
||||
(vec3s){ .x = 1.0f, .z = -3.0f },
|
||||
);
|
||||
|
||||
GpuBufferCreateRequest shader_data_req = { .device = device,
|
||||
@@ -220,11 +221,12 @@ i32 main(void) {
|
||||
),
|
||||
},
|
||||
);
|
||||
memcpy(shader_data.cpu_mapping, &data, wpArrayItemSize(data) * wpArrayCount(data));
|
||||
memcpy(shader_data.cpu_mapping, data, wpArrayItemSize(data) * wpArrayCount(data));
|
||||
gpuFlushBuffer((GpuBufferFlushRequest){ .device = device, .buffer = shader_data });
|
||||
|
||||
GpuDescriptorPoolSizeArray pool_sizes = wpArray(
|
||||
GpuDescriptorPoolSize,
|
||||
(GpuDescriptorPoolSize){ .type = GPU_DESCRIPTOR_TYPE_STORAGE_BUFFER, .count = wpArrayCount(data) }
|
||||
(GpuDescriptorPoolSize){ .type = GPU_DESCRIPTOR_TYPE_STORAGE_BUFFER, .count = 1 }
|
||||
);
|
||||
GpuDescriptorPoolCreateRequest desc_pool_req = {
|
||||
.descriptor_pool_sizes = pool_sizes,
|
||||
@@ -238,7 +240,7 @@ i32 main(void) {
|
||||
(GpuDescriptorSetBinding){
|
||||
.binding = 0,
|
||||
.type = GPU_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.descriptor_count = wpArrayCount(data),
|
||||
.descriptor_count = 1,
|
||||
.stages = GPU_SHADER_STAGE_VERTEX,
|
||||
}
|
||||
);
|
||||
@@ -259,8 +261,7 @@ i32 main(void) {
|
||||
.descriptor_type = GPU_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.buffer_infos = wpArray(
|
||||
GpuDescriptorBufferInfo,
|
||||
(GpuDescriptorBufferInfo){ .buffer = &shader_data, .range = sizeof(ShaderData) },
|
||||
(GpuDescriptorBufferInfo){ .buffer = &shader_data, .offset = sizeof(ShaderData), .range = sizeof(ShaderData) },
|
||||
(GpuDescriptorBufferInfo){ .buffer = &shader_data },
|
||||
),
|
||||
};
|
||||
GpuDescriptorSetWriteRequest desc_set_req = {
|
||||
@@ -373,6 +374,69 @@ i32 main(void) {
|
||||
.timeout = UINT64_MAX });
|
||||
gpuResetFences(&temp_arena, (GpuResetFencesRequest){ .device = device, .fences = fences });
|
||||
|
||||
if (windowIsKeyPressed(KEYBOARD_KEY_UP)) {
|
||||
camera.position.z -= 0.01f;
|
||||
data[0].mvp = modelViewProjection(
|
||||
glms_translate(glms_mat4_identity(), translations[0]),
|
||||
glms_lookat(camera.position, camera.target, camera.up),
|
||||
glms_perspective(glm_rad(projection.fov_deg), projection.aspect, projection.near, projection.far)
|
||||
);
|
||||
data[1].mvp = modelViewProjection(
|
||||
glms_translate(glms_mat4_identity(), translations[1]),
|
||||
glms_lookat(camera.position, camera.target, camera.up),
|
||||
glms_perspective(glm_rad(projection.fov_deg), projection.aspect, projection.near, projection.far)
|
||||
);
|
||||
memcpy(shader_data.cpu_mapping, data, wpArrayItemSize(data) * wpArrayCount(data));
|
||||
gpuFlushBuffer((GpuBufferFlushRequest){ .device = device, .buffer = shader_data });
|
||||
}
|
||||
if (windowIsKeyPressed(KEYBOARD_KEY_DOWN)) {
|
||||
camera.position.z += 0.01f;
|
||||
data[0].mvp = modelViewProjection(
|
||||
glms_translate(glms_mat4_identity(), translations[0]),
|
||||
glms_lookat(camera.position, camera.target, camera.up),
|
||||
glms_perspective(glm_rad(projection.fov_deg), projection.aspect, projection.near, projection.far)
|
||||
);
|
||||
data[1].mvp = modelViewProjection(
|
||||
glms_translate(glms_mat4_identity(), translations[1]),
|
||||
glms_lookat(camera.position, camera.target, camera.up),
|
||||
glms_perspective(glm_rad(projection.fov_deg), projection.aspect, projection.near, projection.far)
|
||||
);
|
||||
memcpy(shader_data.cpu_mapping, data, wpArrayItemSize(data) * wpArrayCount(data));
|
||||
gpuFlushBuffer((GpuBufferFlushRequest){ .device = device, .buffer = shader_data });
|
||||
}
|
||||
if (windowIsKeyPressed(KEYBOARD_KEY_RIGHT)) {
|
||||
camera.position.x += 0.01f;
|
||||
camera.target.x += 0.01f;
|
||||
data[0].mvp = modelViewProjection(
|
||||
glms_translate(glms_mat4_identity(), translations[0]),
|
||||
glms_lookat(camera.position, camera.target, camera.up),
|
||||
glms_perspective(glm_rad(projection.fov_deg), projection.aspect, projection.near, projection.far)
|
||||
);
|
||||
data[1].mvp = modelViewProjection(
|
||||
glms_translate(glms_mat4_identity(), translations[1]),
|
||||
glms_lookat(camera.position, camera.target, camera.up),
|
||||
glms_perspective(glm_rad(projection.fov_deg), projection.aspect, projection.near, projection.far)
|
||||
);
|
||||
memcpy(shader_data.cpu_mapping, data, wpArrayItemSize(data) * wpArrayCount(data));
|
||||
gpuFlushBuffer((GpuBufferFlushRequest){ .device = device, .buffer = shader_data });
|
||||
}
|
||||
if (windowIsKeyPressed(KEYBOARD_KEY_LEFT)) {
|
||||
camera.position.x -= 0.01f;
|
||||
camera.target.x -= 0.01f;
|
||||
data[0].mvp = modelViewProjection(
|
||||
glms_translate(glms_mat4_identity(), translations[0]),
|
||||
glms_lookat(camera.position, camera.target, camera.up),
|
||||
glms_perspective(glm_rad(projection.fov_deg), projection.aspect, projection.near, projection.far)
|
||||
);
|
||||
data[1].mvp = modelViewProjection(
|
||||
glms_translate(glms_mat4_identity(), translations[1]),
|
||||
glms_lookat(camera.position, camera.target, camera.up),
|
||||
glms_perspective(glm_rad(projection.fov_deg), projection.aspect, projection.near, projection.far)
|
||||
);
|
||||
memcpy(shader_data.cpu_mapping, data, wpArrayItemSize(data) * wpArrayCount(data));
|
||||
gpuFlushBuffer((GpuBufferFlushRequest){ .device = device, .buffer = shader_data });
|
||||
}
|
||||
|
||||
GpuSwapchainAcquireImageResult acquire_result = gpuAcquireNextSwapchainImage(
|
||||
(GpuSwapchainAcquireImageRequest){
|
||||
.swapchain = swapchain,
|
||||
@@ -546,65 +610,6 @@ i32 main(void) {
|
||||
.swapchain_infos = wpArray(GpuSwpachainPresentInfo, present_info),
|
||||
};
|
||||
gpuPresentSwapchains(&temp_arena, present_request);
|
||||
|
||||
if (windowIsKeyPressed(KEYBOARD_KEY_UP)) {
|
||||
camera.position.z -= 0.01f;
|
||||
data[0].mvp = modelViewProjection(
|
||||
glms_translate(glms_mat4_identity(), translations[0]),
|
||||
glms_lookat(camera.position, camera.target, camera.up),
|
||||
glms_perspective(glm_rad(projection.fov_deg), projection.aspect, projection.near, projection.far)
|
||||
);
|
||||
data[1].mvp = modelViewProjection(
|
||||
glms_translate(glms_mat4_identity(), translations[1]),
|
||||
glms_lookat(camera.position, camera.target, camera.up),
|
||||
glms_perspective(glm_rad(projection.fov_deg), projection.aspect, projection.near, projection.far)
|
||||
);
|
||||
memcpy(shader_data.cpu_mapping, &data, wpArrayItemSize(data) * wpArrayCount(data));
|
||||
}
|
||||
if (windowIsKeyPressed(KEYBOARD_KEY_DOWN)) {
|
||||
camera.position.z += 0.01f;
|
||||
data[0].mvp = modelViewProjection(
|
||||
glms_translate(glms_mat4_identity(), translations[0]),
|
||||
glms_lookat(camera.position, camera.target, camera.up),
|
||||
glms_perspective(glm_rad(projection.fov_deg), projection.aspect, projection.near, projection.far)
|
||||
);
|
||||
data[1].mvp = modelViewProjection(
|
||||
glms_translate(glms_mat4_identity(), translations[1]),
|
||||
glms_lookat(camera.position, camera.target, camera.up),
|
||||
glms_perspective(glm_rad(projection.fov_deg), projection.aspect, projection.near, projection.far)
|
||||
);
|
||||
memcpy(shader_data.cpu_mapping, &data, wpArrayItemSize(data) * wpArrayCount(data));
|
||||
}
|
||||
if (windowIsKeyPressed(KEYBOARD_KEY_RIGHT)) {
|
||||
camera.position.x += 0.01f;
|
||||
camera.target.x += 0.01f;
|
||||
data[0].mvp = modelViewProjection(
|
||||
glms_translate(glms_mat4_identity(), translations[0]),
|
||||
glms_lookat(camera.position, camera.target, camera.up),
|
||||
glms_perspective(glm_rad(projection.fov_deg), projection.aspect, projection.near, projection.far)
|
||||
);
|
||||
data[1].mvp = modelViewProjection(
|
||||
glms_translate(glms_mat4_identity(), translations[1]),
|
||||
glms_lookat(camera.position, camera.target, camera.up),
|
||||
glms_perspective(glm_rad(projection.fov_deg), projection.aspect, projection.near, projection.far)
|
||||
);
|
||||
memcpy(shader_data.cpu_mapping, &data, wpArrayItemSize(data) * wpArrayCount(data));
|
||||
}
|
||||
if (windowIsKeyPressed(KEYBOARD_KEY_LEFT)) {
|
||||
camera.position.x -= 0.01f;
|
||||
camera.target.x -= 0.01f;
|
||||
data[0].mvp = modelViewProjection(
|
||||
glms_translate(glms_mat4_identity(), translations[0]),
|
||||
glms_lookat(camera.position, camera.target, camera.up),
|
||||
glms_perspective(glm_rad(projection.fov_deg), projection.aspect, projection.near, projection.far)
|
||||
);
|
||||
data[1].mvp = modelViewProjection(
|
||||
glms_translate(glms_mat4_identity(), translations[1]),
|
||||
glms_lookat(camera.position, camera.target, camera.up),
|
||||
glms_perspective(glm_rad(projection.fov_deg), projection.aspect, projection.near, projection.far)
|
||||
);
|
||||
memcpy(shader_data.cpu_mapping, &data, wpArrayItemSize(data) * wpArrayCount(data));
|
||||
}
|
||||
}
|
||||
|
||||
gpuDeviceWaitIdle(device);
|
||||
|
||||
Reference in new issue
Block a user