diff --git a/client/decoder/android/android_decoder.cpp b/client/decoder/android/android_decoder.cpp index 087ac9b1..f979c133 100644 --- a/client/decoder/android/android_decoder.cpp +++ b/client/decoder/android/android_decoder.cpp @@ -63,7 +63,7 @@ struct wivrn::android::decoder::pipeline_context vkDestroySamplerYcbcrConversion(device, ycbcr_conversion, nullptr); } - pipeline_context(VkDevice device, VkAndroidHardwareBufferFormatPropertiesANDROID & ahb_format, VkRenderPass renderpass, const to_headset::video_stream_description::item& description) : + pipeline_context(VkDevice device, const AHardwareBuffer_Desc& buffer_desc, VkAndroidHardwareBufferFormatPropertiesANDROID & ahb_format, VkRenderPass renderpass, const to_headset::video_stream_description::item& description) : device(device), ahb_format(ahb_format) { assert(ahb_format.externalFormat != 0); @@ -168,6 +168,22 @@ struct wivrn::android::decoder::pipeline_context poolInfo.maxSets = poolSize.descriptorCount; CHECK_VK(vkCreateDescriptorPool(device, &poolInfo, nullptr, &descriptor_pool)); + float useful_size[] = + { + float(description.width) / buffer_desc.width, + float(description.height) / buffer_desc.height + }; + + std::vector specialization_constants_desc{ + {.constantID = 0, .offset = 0, .size = sizeof(float)}, + {.constantID = 1, .offset = sizeof(float), .size = sizeof(float)}}; + + VkSpecializationInfo specialization_info{ + .mapEntryCount = (uint32_t)specialization_constants_desc.size(), + .pMapEntries = specialization_constants_desc.data(), + .dataSize = sizeof(useful_size), + .pData = &useful_size}; + // Create graphics pipeline vk::shader vertex_shader(device, "stream.vert"); vk::shader fragment_shader(device, "stream.frag"); @@ -180,7 +196,7 @@ struct wivrn::android::decoder::pipeline_context vk::pipeline::graphics_info pipeline_info{ .shader_stages = - {{.stage = VK_SHADER_STAGE_VERTEX_BIT, .module = vertex_shader, .pName = "main"}, + {{.stage = VK_SHADER_STAGE_VERTEX_BIT, .module = vertex_shader, .pName = "main", .pSpecializationInfo = &specialization_info}, {.stage = VK_SHADER_STAGE_FRAGMENT_BIT, .module = fragment_shader, .pName = "main"}}, .vertex_input_bindings = {}, .vertex_input_attributes = {}, @@ -629,7 +645,7 @@ std::shared_ptr decoder::map_hardware_buffer(AI if (!pipeline || memcmp(&pipeline->ahb_format, &format_properties, sizeof(format_properties))) { pipeline.reset(); - pipeline = std::make_shared(device, format_properties, renderpass, description); + pipeline = std::make_shared(device, buffer_desc, format_properties, renderpass, description); hardware_buffer_map.clear(); } diff --git a/client/shaders/stream.glsl b/client/shaders/stream.glsl index ed9efc41..7da10d69 100644 --- a/client/shaders/stream.glsl +++ b/client/shaders/stream.glsl @@ -20,6 +20,10 @@ #version 450 #ifdef VERT_SHADER + +layout (constant_id = 0) const float useful_size_x = 1.0; +layout (constant_id = 1) const float useful_size_y = 1.0; + vec2 positions[3] = vec2[]( vec2(-1.0, -1.0), vec2(3.0, -1.0), @@ -27,8 +31,8 @@ vec2 positions[3] = vec2[]( vec2 uvs[3] = vec2[]( vec2(0.0, 0.0), - vec2(2.0, 0.0), - vec2(0.0, 2.0)); + vec2(2.0 * useful_size_x, 0.0), + vec2(0.0, 2.0 * useful_size_y)); layout(location = 0) out vec2 outUV; diff --git a/server/driver/wivrn_comp_target.cpp b/server/driver/wivrn_comp_target.cpp index 18647732..53c6396b 100644 --- a/server/driver/wivrn_comp_target.cpp +++ b/server/driver/wivrn_comp_target.cpp @@ -150,10 +150,10 @@ static void create_encoders(wivrn_comp_target * cn, std::vectorencoders.size(); auto & encoder = cn->encoders.emplace_back( VideoEncoder::Create(vk, settings, stream_index, desc.width, desc.height, desc.fps)); - desc.items.push_back(settings); std::vector images(cn->image_count); std::vector memory(cn->image_count);