From f834f25794cfb746079e92d58c7410b767c57208 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 14 Jan 2021 15:48:54 -0800 Subject: COM-ify all slang-gfx interfaces. (#1656) * COM-ify all slang-gfx interfaces. --- examples/model-viewer/main.cpp | 67 +++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 33 deletions(-) (limited to 'examples/model-viewer/main.cpp') diff --git a/examples/model-viewer/main.cpp b/examples/model-viewer/main.cpp index 2dc7df3b5..387ec7293 100644 --- a/examples/model-viewer/main.cpp +++ b/examples/model-viewer/main.cpp @@ -23,7 +23,8 @@ #include "graphics-app-framework/window.h" #include "graphics-app-framework/gui.h" using namespace gfx; - +using Slang::RefObject; +using Slang::RefPtr; // We will use a few utilities from the C++ standard library, // just to keep the code short. Note that the Slang API does // not use or require any C++ standard library features. @@ -382,7 +383,7 @@ struct ParameterBlockLayout : RefObject // API-specific layout information computes from `slangTypelayout`. // - RefPtr descriptorSetLayout; + ComPtr descriptorSetLayout; }; // // A parameter block layout can be computed for any `struct` type @@ -423,7 +424,7 @@ RefPtr getParameterBlockLayout( // create a graphics-API-level descriptor-set layout that // is compatible with the original declaration. // - std::vector slotRanges; + std::vector slotRanges; // If the type has any ordinary data, then the descriptor set // will need a constant buffer to be the first thing it stores. @@ -438,7 +439,7 @@ RefPtr getParameterBlockLayout( if(primaryConstantBufferSize) { slotRanges.push_back( - gfx::DescriptorSetLayout::SlotRangeDesc( + gfx::IDescriptorSetLayout::SlotRangeDesc( gfx::DescriptorSlotType::UniformBuffer)); } @@ -453,7 +454,7 @@ RefPtr getParameterBlockLayout( // Now that we've collected the graphics-API level binding // information, we can construct a graphics API descriptor set // layout. - gfx::DescriptorSetLayout::Desc descriptorSetLayoutDesc; + gfx::IDescriptorSetLayout::Desc descriptorSetLayoutDesc; descriptorSetLayoutDesc.slotRangeCount = slotRanges.size(); descriptorSetLayoutDesc.slotRanges = slotRanges.data(); auto descriptorSetLayout = renderer->createDescriptorSetLayout(descriptorSetLayoutDesc); @@ -552,7 +553,7 @@ struct ParameterBlockEncoder // The underlying descriptor set being filled in. // - gfx::DescriptorSet* descriptorSet = nullptr; + gfx::IDescriptorSet* descriptorSet = nullptr; // The Slang type information for the part of the // block that we are filling in. This might be the @@ -648,11 +649,11 @@ struct ParameterBlock : RefObject // The (optional) constant buffer that holds the values // for any ordinay fields. This will be null if // `layout->primaryConstantBufferSize` is zero. - RefPtr primaryConstantBuffer; + ComPtr primaryConstantBuffer; // The graphics-API descriptor set that provides storage // for any resource fields. - RefPtr descriptorSet; + ComPtr descriptorSet; ParameterBlockEncoder beginEncoding(); }; @@ -674,15 +675,15 @@ RefPtr allocateParameterBlockImpl( // If the parameter block has any ordinary data, then it requires // a "primary" constant buffer to hold that data. // - RefPtr primaryConstantBuffer = nullptr; + ComPtr primaryConstantBuffer = nullptr; if(auto primaryConstantBufferSize = layout->primaryConstantBufferSize) { - gfx::BufferResource::Desc bufferDesc; + gfx::IBufferResource::Desc bufferDesc; bufferDesc.init(primaryConstantBufferSize); - bufferDesc.setDefaults(gfx::Resource::Usage::ConstantBuffer); - bufferDesc.cpuAccessFlags = gfx::Resource::AccessFlag::Write; + bufferDesc.setDefaults(gfx::IResource::Usage::ConstantBuffer); + bufferDesc.cpuAccessFlags = gfx::IResource::AccessFlag::Write; primaryConstantBuffer = renderer->createBufferResource( - gfx::Resource::Usage::ConstantBuffer, + gfx::IResource::Usage::ConstantBuffer, bufferDesc); // The primary constant buffer will always be the first thing @@ -774,7 +775,7 @@ struct Effect : RefObject // Additional state corresponding to the data needed // to create a graphics-API pipeline state object. - RefPtr inputLayout; + ComPtr inputLayout; Int renderTargetCount; }; @@ -791,8 +792,8 @@ struct EffectVariant : RefObject // that need to be bound in order to use this // effect. // - RefPtr pipelineLayout; - RefPtr pipelineState; + ComPtr pipelineLayout; + ComPtr pipelineState; }; // // A specialized variant is created based on a base effect @@ -839,13 +840,13 @@ RefPtr createEffectVaraint( // be determined based on the descriptor-set layouts // already cached in the given parameter block layouts. // - std::vector descriptorSets; + std::vector descriptorSets; for(UInt pp = 0; pp < parameterBlockCount; ++pp) { descriptorSets.emplace_back( parameterBlockLayouts[pp]->descriptorSetLayout); } - PipelineLayout::Desc pipelineLayoutDesc; + IPipelineLayout::Desc pipelineLayoutDesc; pipelineLayoutDesc.renderTargetCount = 1; pipelineLayoutDesc.descriptorSetCount = descriptorSets.size(); pipelineLayoutDesc.descriptorSets = descriptorSets.data(); @@ -927,7 +928,7 @@ RefPtr createEffectVaraint( // to the graphics APIs loading logic. // std::vector kernelBlobs; - std::vector kernelDescs; + std::vector kernelDescs; for(int ii = 0; ii < entryPointCount; ++ii) { auto entryPoint = program->entryPoints[ii]; @@ -937,7 +938,7 @@ RefPtr createEffectVaraint( kernelBlobs.push_back(blob); - ShaderProgram::KernelDesc kernelDesc; + IShaderProgram::KernelDesc kernelDesc; char const* codeBegin = (char const*) blob->getBufferPointer(); char const* codeEnd = codeBegin + blob->getBufferSize(); @@ -960,7 +961,7 @@ RefPtr createEffectVaraint( spDestroyCompileRequest(slangRequest); // We use the graphics API to load a program into the GPU - gfx::ShaderProgram::Desc programDesc; + gfx::IShaderProgram::Desc programDesc; programDesc.pipelineType = gfx::PipelineType::Graphics; programDesc.kernels = kernelDescs.data(); programDesc.kernelCount = kernelDescs.size(); @@ -1020,11 +1021,11 @@ struct ShaderCache : RefObject Slang::HashCode getHashCode() const { - auto hash = ::getHashCode(effect); - hash = combineHash(hash, ::getHashCode(parameterBlockCount)); + auto hash = Slang::getHashCode(effect); + hash = Slang::combineHash(hash, Slang::getHashCode(parameterBlockCount)); for( UInt ii = 0; ii < parameterBlockCount; ++ii ) { - hash = combineHash(hash, ::getHashCode(parameterBlockLayouts[ii])); + hash = Slang::combineHash(hash, Slang::getHashCode(parameterBlockLayouts[ii])); } return hash; } @@ -1033,7 +1034,7 @@ struct ShaderCache : RefObject // The shader cache is mostly just a dictionary mapping // variant keys to the associated variant, generated on-demand. // - Dictionary > variants; + Slang::Dictionary > variants; // Getting a variant is just a matter of looking for an // existing entry in the dictionary, and creating one @@ -1372,8 +1373,8 @@ struct Model : RefObject { typedef ModelLoader::Vertex Vertex; - RefPtr vertexBuffer; - RefPtr indexBuffer; + ComPtr vertexBuffer; + ComPtr indexBuffer; PrimitiveTopology primitiveTopology; int vertexCount; int indexCount; @@ -1911,7 +1912,7 @@ struct ModelViewer { Window* gWindow; Slang::ComPtr gRenderer; -RefPtr gDepthTarget; +ComPtr gDepthTarget; // We keep a pointer to the one effect we are using (for a forward // rendering pass), plus the parameter-block layouts for our `PerView` @@ -2069,16 +2070,16 @@ Result initialize() // Because we are rendering more than a single triangle this time, we // require a depth buffer to resolve visibility. // - TextureResource::Desc depthBufferDesc = gRenderer->getSwapChainTextureDesc(); + ITextureResource::Desc depthBufferDesc = gRenderer->getSwapChainTextureDesc(); depthBufferDesc.format = Format::D_Float32; - depthBufferDesc.setDefaults(Resource::Usage::DepthWrite); + depthBufferDesc.setDefaults(IResource::Usage::DepthWrite); auto depthTexture = gRenderer->createTextureResource( - Resource::Usage::DepthWrite, + IResource::Usage::DepthWrite, depthBufferDesc); if(!depthTexture) return SLANG_FAIL; - ResourceView::Desc textureViewDesc; - textureViewDesc.type = ResourceView::Type::DepthStencil; + IResourceView::Desc textureViewDesc; + textureViewDesc.type = IResourceView::Type::DepthStencil; auto depthTarget = gRenderer->createTextureView(depthTexture, textureViewDesc); if (!depthTarget) return SLANG_FAIL; -- cgit v1.2.3