@@ -5043,17 +5043,24 @@ RID RenderingDeviceVulkan::shader_create_from_bytecode(const Vector<uint8_t> &p_
50435043
50445044 _THREAD_SAFE_METHOD_
50455045
5046- Shader shader;
5046+ RID id;
5047+ if (p_placeholder.is_null ()) {
5048+ id = shader_owner.make_rid ();
5049+ } else {
5050+ id = p_placeholder;
5051+ }
5052+
5053+ Shader *shader = shader_owner.get_or_null (id);
50475054
5048- shader. vertex_input_mask = vertex_input_mask;
5049- shader. fragment_output_mask = fragment_output_mask;
5050- shader. push_constant = push_constant;
5051- shader. is_compute = is_compute;
5052- shader. compute_local_size [0 ] = compute_local_size[0 ];
5053- shader. compute_local_size [1 ] = compute_local_size[1 ];
5054- shader. compute_local_size [2 ] = compute_local_size[2 ];
5055- shader. specialization_constants = specialization_constants;
5056- shader. name = name;
5055+ shader-> vertex_input_mask = vertex_input_mask;
5056+ shader-> fragment_output_mask = fragment_output_mask;
5057+ shader-> push_constant = push_constant;
5058+ shader-> is_compute = is_compute;
5059+ shader-> compute_local_size [0 ] = compute_local_size[0 ];
5060+ shader-> compute_local_size [1 ] = compute_local_size[1 ];
5061+ shader-> compute_local_size [2 ] = compute_local_size[2 ];
5062+ shader-> specialization_constants = specialization_constants;
5063+ shader-> name = name;
50575064
50585065 String error_text;
50595066
@@ -5085,7 +5092,7 @@ RID RenderingDeviceVulkan::shader_create_from_bytecode(const Vector<uint8_t> &p_
50855092 shader_stage.pName = " main" ;
50865093 shader_stage.pSpecializationInfo = nullptr ;
50875094
5088- shader. pipeline_stages .push_back (shader_stage);
5095+ shader-> pipeline_stages .push_back (shader_stage);
50895096 }
50905097 // Proceed to create descriptor sets.
50915098
@@ -5128,8 +5135,8 @@ RID RenderingDeviceVulkan::shader_create_from_bytecode(const Vector<uint8_t> &p_
51285135 }
51295136 }
51305137
5131- shader. sets .push_back (set);
5132- shader. set_formats .push_back (format);
5138+ shader-> sets .push_back (set);
5139+ shader-> set_formats .push_back (format);
51335140 }
51345141 }
51355142
@@ -5139,13 +5146,13 @@ RID RenderingDeviceVulkan::shader_create_from_bytecode(const Vector<uint8_t> &p_
51395146 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO ;
51405147 pipeline_layout_create_info.pNext = nullptr ;
51415148 pipeline_layout_create_info.flags = 0 ;
5142- pipeline_layout_create_info.setLayoutCount = shader. sets .size ();
5149+ pipeline_layout_create_info.setLayoutCount = shader-> sets .size ();
51435150
51445151 Vector<VkDescriptorSetLayout> layouts;
5145- layouts.resize (shader. sets .size ());
5152+ layouts.resize (shader-> sets .size ());
51465153
51475154 for (int i = 0 ; i < layouts.size (); i++) {
5148- layouts.write [i] = shader. sets [i].descriptor_set_layout ;
5155+ layouts.write [i] = shader-> sets [i].descriptor_set_layout ;
51495156 }
51505157
51515158 pipeline_layout_create_info.pSetLayouts = layouts.ptr ();
@@ -5164,7 +5171,7 @@ RID RenderingDeviceVulkan::shader_create_from_bytecode(const Vector<uint8_t> &p_
51645171 pipeline_layout_create_info.pPushConstantRanges = nullptr ;
51655172 }
51665173
5167- VkResult err = vkCreatePipelineLayout (device, &pipeline_layout_create_info, nullptr , &shader. pipeline_layout );
5174+ VkResult err = vkCreatePipelineLayout (device, &pipeline_layout_create_info, nullptr , &shader-> pipeline_layout );
51685175
51695176 if (err) {
51705177 error_text = " Error (" + itos (err) + " ) creating pipeline layout." ;
@@ -5174,31 +5181,28 @@ RID RenderingDeviceVulkan::shader_create_from_bytecode(const Vector<uint8_t> &p_
51745181
51755182 if (!success) {
51765183 // Clean up if failed.
5177- for (int i = 0 ; i < shader. pipeline_stages .size (); i++) {
5178- vkDestroyShaderModule (device, shader. pipeline_stages [i].module , nullptr );
5184+ for (int i = 0 ; i < shader-> pipeline_stages .size (); i++) {
5185+ vkDestroyShaderModule (device, shader-> pipeline_stages [i].module , nullptr );
51795186 }
51805187
5181- for (int i = 0 ; i < shader. sets .size (); i++) {
5182- vkDestroyDescriptorSetLayout (device, shader. sets [i].descriptor_set_layout , nullptr );
5188+ for (int i = 0 ; i < shader-> sets .size (); i++) {
5189+ vkDestroyDescriptorSetLayout (device, shader-> sets [i].descriptor_set_layout , nullptr );
51835190 }
51845191
5192+ shader_owner.free (id);
5193+
51855194 ERR_FAIL_V_MSG (RID (), error_text);
51865195 }
5187- RID id;
5188- if (p_placeholder.is_null ()) {
5189- id = shader_owner.make_rid (shader);
5190- } else {
5191- shader_owner.initialize_rid (p_placeholder, shader);
5192- id = p_placeholder;
5193- }
5196+
51945197#ifdef DEV_ENABLED
51955198 set_resource_name (id, " RID:" + itos (id.get_id ()));
51965199#endif
51975200 return id;
51985201}
51995202
52005203RID RenderingDeviceVulkan::shader_create_placeholder () {
5201- return shader_owner.allocate_rid ();
5204+ Shader shader;
5205+ return shader_owner.make_rid (shader);
52025206}
52035207
52045208uint32_t RenderingDeviceVulkan::shader_get_vertex_input_attribute_mask (RID p_shader) {
0 commit comments