From 745466652c266af6f960760b9b4731204105ebee Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sat, 18 Nov 2017 10:42:27 +0100 Subject: [PATCH] [dxvk] Removed shader resource slots for now, needs work --- src/dxbc/gen/dxbc_gen_pixel.cpp | 5 +- src/dxbc/gen/dxbc_gen_vertex.cpp | 5 +- src/dxvk/dxvk_compute.cpp | 9 ++-- src/dxvk/dxvk_context.cpp | 4 +- src/dxvk/dxvk_context_state.h | 38 +++++++++++++- src/dxvk/dxvk_descriptor.cpp | 16 +++--- src/dxvk/dxvk_limits.h | 10 ++-- src/dxvk/dxvk_shader.cpp | 43 +--------------- src/dxvk/dxvk_shader.h | 86 +++++-------------------------- tests/dxbc/test_dxbc_compiler.cpp | 2 +- 10 files changed, 77 insertions(+), 141 deletions(-) diff --git a/src/dxbc/gen/dxbc_gen_pixel.cpp b/src/dxbc/gen/dxbc_gen_pixel.cpp index 57ccd0a0..0b84db48 100644 --- a/src/dxbc/gen/dxbc_gen_pixel.cpp +++ b/src/dxbc/gen/dxbc_gen_pixel.cpp @@ -112,8 +112,9 @@ namespace dxvk { m_entryPointInterfaces.data()); m_module.setDebugName(m_entryPointId, "main"); - return new DxvkShader(VK_SHADER_STAGE_FRAGMENT_BIT, - m_module.compile(), 0, nullptr); + return new DxvkShader( + VK_SHADER_STAGE_FRAGMENT_BIT, + m_module.compile()); } diff --git a/src/dxbc/gen/dxbc_gen_vertex.cpp b/src/dxbc/gen/dxbc_gen_vertex.cpp index 33a9a374..9bd1f671 100644 --- a/src/dxbc/gen/dxbc_gen_vertex.cpp +++ b/src/dxbc/gen/dxbc_gen_vertex.cpp @@ -119,8 +119,9 @@ namespace dxvk { m_entryPointInterfaces.data()); m_module.setDebugName(m_entryPointId, "main"); - return new DxvkShader(VK_SHADER_STAGE_VERTEX_BIT, - m_module.compile(), 0, nullptr); + return new DxvkShader( + VK_SHADER_STAGE_VERTEX_BIT, + m_module.compile()); } diff --git a/src/dxvk/dxvk_compute.cpp b/src/dxvk/dxvk_compute.cpp index eadb73e0..92d420c3 100644 --- a/src/dxvk/dxvk_compute.cpp +++ b/src/dxvk/dxvk_compute.cpp @@ -9,9 +9,10 @@ namespace dxvk { TRACE(this, shader); std::vector bindings; - - for (uint32_t i = 0; i < shader->slotCount(); i++) - bindings.push_back(shader->slotBinding(0, i)); + + // TODO re-implement shader slots and bindings +// for (uint32_t i = 0; i < shader->slotCount(); i++) +// bindings.push_back(shader->slotBinding(0, i)); VkDescriptorSetLayoutCreateInfo dlayout; dlayout.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; @@ -39,7 +40,7 @@ namespace dxvk { throw DxvkError("DxvkComputePipeline::DxvkComputePipeline: Failed to create pipeline layout"); } - SpirvCodeBuffer code = shader->code(0); + SpirvCodeBuffer code = shader->code(); VkShaderModuleCreateInfo minfo; minfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index 278a55ea..48c00aa4 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -35,7 +35,7 @@ namespace dxvk { DxvkContextFlag::GpDirtyPipeline, DxvkContextFlag::GpDirtyPipelineState, DxvkContextFlag::GpDirtyResources, - DxvkContextFlag::GpDirtyIndexBuffers, + DxvkContextFlag::GpDirtyIndexBuffer, DxvkContextFlag::GpDirtyVertexBuffers, DxvkContextFlag::CpDirtyPipeline, DxvkContextFlag::CpDirtyResources); @@ -83,7 +83,7 @@ namespace dxvk { DxvkContextFlag::GpDirtyPipelineState, DxvkContextFlag::GpDirtyResources, DxvkContextFlag::GpDirtyVertexBuffers, - DxvkContextFlag::GpDirtyIndexBuffers); + DxvkContextFlag::GpDirtyIndexBuffer); } } } diff --git a/src/dxvk/dxvk_context_state.h b/src/dxvk/dxvk_context_state.h index bc3e39f5..12836e7f 100644 --- a/src/dxvk/dxvk_context_state.h +++ b/src/dxvk/dxvk_context_state.h @@ -23,7 +23,7 @@ namespace dxvk { GpDirtyPipelineState, ///< Graphics pipeline state (blending etc.) is dirty GpDirtyResources, ///< Graphics pipeline resource bindings are out of date GpDirtyVertexBuffers, ///< Vertex buffer bindings are out of date - GpDirtyIndexBuffers, ///< Index buffer binding are out of date + GpDirtyIndexBuffer, ///< Index buffer binding are out of date CpDirtyPipeline, ///< Compute pipeline binding are out of date CpDirtyResources, ///< Compute pipeline resource bindings are out of date @@ -44,6 +44,40 @@ namespace dxvk { }; + /** + * \brief Input assembly state + * + * Stores the primitive topology + * and the vertex input layout. + */ + struct DxvkInputAssemblyState { + VkPrimitiveTopology primitiveTopology; + VkBool32 primitiveRestart; + + uint32_t numVertexBindings = 0; + uint32_t numVertexAttributes = 0; + + std::array vertexBindings; + + std::array vertexAttributes; + }; + + + /** + * \brief Vertex input state + * + * Stores the currently bound index + * buffer and vertex buffers. + */ + struct DxvkVertexInputState { + Rc indexBuffer; + std::array, + DxvkLimits::MaxNumVertexBuffers> vertexBuffers; + }; + + /** * \brief Output merger state * @@ -69,6 +103,8 @@ namespace dxvk { DxvkShaderStageState fs; DxvkShaderStageState cs; + DxvkInputAssemblyState ia; + DxvkVertexInputState vi; DxvkOutputMergerState om; Rc activeGraphicsPipeline; diff --git a/src/dxvk/dxvk_descriptor.cpp b/src/dxvk/dxvk_descriptor.cpp index 11eaa146..f2af35fd 100644 --- a/src/dxvk/dxvk_descriptor.cpp +++ b/src/dxvk/dxvk_descriptor.cpp @@ -56,15 +56,17 @@ namespace dxvk { TRACE(this); // TODO tune these values, if necessary - constexpr uint32_t MaxSets = 256; + constexpr uint32_t MaxSets = 64; constexpr uint32_t MaxDesc = 256; - std::array pools = {{ - { VK_DESCRIPTOR_TYPE_SAMPLER, MaxDesc }, - { VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, MaxDesc }, - { VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, MaxDesc }, - { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MaxDesc }, - { VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, MaxDesc } }}; + std::array pools = {{ + { VK_DESCRIPTOR_TYPE_SAMPLER, MaxDesc }, + { VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, MaxDesc }, + { VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, MaxDesc }, + { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MaxDesc }, + { VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, MaxDesc }, + { VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, MaxDesc }, + { VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, MaxDesc } }}; VkDescriptorPoolCreateInfo info; info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; diff --git a/src/dxvk/dxvk_limits.h b/src/dxvk/dxvk_limits.h index 576c2418..5896660a 100644 --- a/src/dxvk/dxvk_limits.h +++ b/src/dxvk/dxvk_limits.h @@ -3,13 +3,9 @@ namespace dxvk { enum DxvkLimits : size_t { - MaxNumRenderTargets = 8, - MaxNumUniformBuffers = 16, - MaxNumSampledImages = 16, - MaxNumStorageBuffers = 128, - MaxNumStorageImages = 128, - MaxNumVertexBuffers = 32, - MaxNumOutputStreams = 4, + MaxNumRenderTargets = 8, + MaxNumVertexBuffers = 32, + MaxNumOutputStreams = 4, }; } \ No newline at end of file diff --git a/src/dxvk/dxvk_shader.cpp b/src/dxvk/dxvk_shader.cpp index c6025877..fe8466d5 100644 --- a/src/dxvk/dxvk_shader.cpp +++ b/src/dxvk/dxvk_shader.cpp @@ -4,15 +4,10 @@ namespace dxvk { DxvkShader::DxvkShader( VkShaderStageFlagBits stage, - SpirvCodeBuffer&& code, - uint32_t numResourceSlots, - const DxvkResourceSlot* resourceSlots) + SpirvCodeBuffer&& code) : m_stage (stage), m_code (std::move(code)) { - TRACE(this, stage, numResourceSlots); - - for (uint32_t i = 0; i < numResourceSlots; i++) - m_slots.push_back(resourceSlots[i]); + TRACE(this, stage); } @@ -20,38 +15,4 @@ namespace dxvk { TRACE(this); } - - SpirvCodeBuffer DxvkShader::code( - uint32_t bindingOffset) const { - // TODO implement properly - if (bindingOffset != 0) - Logger::warn("DxvkShader::code: bindingOffset != 0 not yet supported"); - return m_code; - } - - - uint32_t DxvkShader::slotCount() const { - return m_slots.size(); - } - - - DxvkResourceSlot DxvkShader::slot(uint32_t slotId) const { - return m_slots.at(slotId); - } - - - VkDescriptorSetLayoutBinding DxvkShader::slotBinding( - uint32_t slotId, - uint32_t bindingOffset) const { - auto dtype = static_cast(m_slots.at(slotId).type); - - VkDescriptorSetLayoutBinding info; - info.binding = bindingOffset + slotId; - info.descriptorType = dtype; - info.descriptorCount = 1; - info.stageFlags = m_stage; - info.pImmutableSamplers = nullptr; - return info; - } - } \ No newline at end of file diff --git a/src/dxvk/dxvk_shader.h b/src/dxvk/dxvk_shader.h index 3e2a636d..508848c4 100644 --- a/src/dxvk/dxvk_shader.h +++ b/src/dxvk/dxvk_shader.h @@ -8,19 +8,6 @@ namespace dxvk { - /** - * \brief Resource access mode - * - * Defines whether a resource will be - * used for reading, writing, or both. - */ - enum class DxvkResourceModeBit : uint32_t { - Read = 0, - Write = 1, - }; - - using DxvkResourceMode = Flags; - /** * \brief Shader resource type * @@ -28,21 +15,13 @@ namespace dxvk { * that can be accessed by shaders. */ enum class DxvkResourceType : uint32_t { - UniformBuffer = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, - ImageSampler = VK_DESCRIPTOR_TYPE_SAMPLER, - SampledImage = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, - StorageBuffer = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, - StorageImage = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, - }; - - - /** - * \brief Resource slot - */ - struct DxvkResourceSlot{ - DxvkResourceMode mode; - DxvkResourceType type; - uint32_t slot; + ImageSampler = VK_DESCRIPTOR_TYPE_SAMPLER, + SampledImage = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, + StorageImage = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, + UniformBuffer = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, + StorageBuffer = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, + UniformTexelBuffer = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, + StorageTexelBuffer = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, }; @@ -60,63 +39,22 @@ namespace dxvk { DxvkShader( VkShaderStageFlagBits stage, - SpirvCodeBuffer&& code, - uint32_t numResourceSlots, - const DxvkResourceSlot* resourceSlots); + SpirvCodeBuffer&& code); ~DxvkShader(); /** * \brief Retrieves shader code - * - * Since the exact binding IDs are not known by the - * time the shader is created, we need to offset them - * by the first binding index reserved for the shader - * stage that this shader belongs to. - * \param [in] bindingOffset First binding ID - * \returns Modified code buffer + * \returns Shader code buffer */ - SpirvCodeBuffer code( - uint32_t bindingOffset) const; - - /** - * \brief Number of resource slots - * \returns Number of enabled slots - */ - uint32_t slotCount() const; - - /** - * \brief Retrieves resource slot properties - * - * Resource slots store which resources that are bound - * to a DXVK context are used by the shader. The slot - * ID corresponds to the binding index relative to the - * first binding index within the shader. - * \param [in] slotId Slot index - * \returns The resource slot - */ - DxvkResourceSlot slot( - uint32_t slotId) const; - - /** - * \brief Descriptor set layout binding - * - * Creates Vulkan-compatible binding information for - * a single resource slot. Each resource slot used - * by the shader corresponds to one binding in Vulkan. - * \param [in] slotId Shader binding slot ID - * \param [in] bindingOffset Binding index offset - * \returns Binding info - */ - VkDescriptorSetLayoutBinding slotBinding( - uint32_t slotId, uint32_t bindingOffset) const; + const SpirvCodeBuffer& code() const { + return m_code; + } private: VkShaderStageFlagBits m_stage; SpirvCodeBuffer m_code; - std::vector m_slots; - }; } \ No newline at end of file diff --git a/tests/dxbc/test_dxbc_compiler.cpp b/tests/dxbc/test_dxbc_compiler.cpp index 8c303277..bb6724ee 100644 --- a/tests/dxbc/test_dxbc_compiler.cpp +++ b/tests/dxbc/test_dxbc_compiler.cpp @@ -37,7 +37,7 @@ int WINAPI WinMain(HINSTANCE hInstance, DxbcModule module(reader); auto shader = module.compile(); - shader->code(0).store(std::ofstream( + shader->code().store(std::ofstream( str::fromws(argv[2]), std::ios::binary)); return 0; } catch (const DxvkError& e) {