diff --git a/shaders/InterfacePS.hlsl b/shaders/InterfacePS.hlsl index bcfc444..e692ed4 100644 --- a/shaders/InterfacePS.hlsl +++ b/shaders/InterfacePS.hlsl @@ -1,5 +1,5 @@ SamplerState gSampler : register(s1, space0); -Texture2D gTexture : register(t0, space1); +Texture2D gTexture : register(t2, space0); void PSMain( in float4 iColor : COLOR, diff --git a/src/ui.cpp b/src/ui.cpp index 511845a..2f5d045 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -48,15 +48,17 @@ void CalculateTextureRowWidthPadding(uint32_t rowPitch, uint32_t &rowWidth, uint rowWidth += rowPadding; } -struct RmlRenderInterfaceHeap : public RT64::RenderDescriptorHeapBase { +struct RmlRenderInterfaceHeapBase : public RT64::RenderDescriptorHeapBase { uint32_t gSampler; + uint32_t gTexture; - RmlRenderInterfaceHeap(const RT64::RenderSampler* linear_sampler) { + RmlRenderInterfaceHeapBase(const RT64::RenderSampler* linear_sampler) { assert(linear_sampler != nullptr); builder.begin(); builder.beginSet(); gSampler = builder.addImmutableSampler(1, linear_sampler); + gTexture = builder.addTexture(2); builder.endSet(); builder.end(); } @@ -123,8 +125,7 @@ class RmlRenderInterface_RT64 : public Rml::RenderInterface { std::unique_ptr linearSampler_{}; std::unique_ptr vertex_shader_{}; std::unique_ptr pixel_shader_{}; - std::unique_ptr heap_{}; - std::unique_ptr texture_heap_builder_{}; + std::unique_ptr heap_base_{}; std::unique_ptr layout_{}; std::unique_ptr pipeline_{}; uint32_t upload_buffer_size_ = 0; @@ -172,24 +173,14 @@ public: // Create the descriptor heap - heap_ = std::make_unique(linearSampler_.get()); - heap_->create(render_context->device); - - texture_heap_builder_ = std::make_unique(); - texture_heap_builder_->begin(); - texture_heap_builder_->beginSet(); - texture_heap_builder_->addTexture(0); - texture_heap_builder_->endSet(); - texture_heap_builder_->end(); + heap_base_ = std::make_unique(linearSampler_.get()); // Create the pipeline layout RT64::RenderPipelineLayoutBuilder layout_builder{}; layout_builder.begin(false, true); layout_builder.addPushConstant(0, 0, sizeof(RmlPushConstants), RT64::RenderShaderStageFlag::VERTEX); // Add the descriptor set for descriptors changed once per frame. - layout_builder.addDescriptorSetsFromHeap(heap_->builder); - // Add the descriptor set for descriptors changed once per draw. - layout_builder.addDescriptorSetsFromHeap(*texture_heap_builder_); + layout_builder.addDescriptorSetsFromHeap(heap_base_->builder); layout_builder.end(); layout_ = layout_builder.create(render_context->device); @@ -341,7 +332,7 @@ public: list_->setIndexBuffer(&index_view); RT64::RenderVertexBufferView vertex_view{vertex_buffer_->at(0), vert_size_bytes}; list_->setVertexBuffers(0, &vertex_view, 1, &vertex_slot_); - list_->setGraphicsDescriptorHeap(textures_[texture].heap.get(), 0, per_draw_descriptor_set); + list_->setGraphicsDescriptorHeap(textures_[texture].heap.get()); RmlPushConstants constants{ .transform = mvp_, @@ -500,8 +491,9 @@ public: list_->barriers(RT64::RenderTextureBarrier::Transition(texture.get(), RT64::RenderTextureState::PIXEL_SHADER_ACCESS)); // Create a descriptor heap with this texture in it. - std::unique_ptr heap = texture_heap_builder_->create(render_context_->device); - heap->setTexture(0, 0, texture.get(), RT64::RenderTextureState::PIXEL_SHADER_ACCESS); + std::unique_ptr heap = heap_base_->builder.create(render_context_->device); + + heap->setTexture(heap_base_->gTexture, 0, texture.get(), RT64::RenderTextureState::PIXEL_SHADER_ACCESS); textures_.emplace(texture_handle, TextureHandle{ std::move(texture), std::move(heap) }); @@ -528,7 +520,6 @@ public: list_ = list; list_->setPipeline(pipeline_.get()); list_->setGraphicsPipelineLayout(layout_.get()); - list_->setGraphicsDescriptorHeap(heap_->get(), 0, per_frame_descriptor_set); projection_mtx_ = Rml::Matrix4f::ProjectOrtho(0.0f, static_cast(image_width), static_cast(image_height), 0.0f, -10000, 10000); recalculate_mvp();