From 4d20fd329956ac89408b1628a8291fea01bc9a6d Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 20 Feb 2024 12:24:00 -0800 Subject: Refactor compiler option representations. (#3598) * Refactor compiler option representation. * Fix binary compatibility. * Add a test for specifying compiler options at link time. * Fix binary compatibility. * Fix binary compatibility. * Fix backward compatibility on matrix layout. * Fix. * Fix. * Fix. * Fix gfx. * Fix gfx. * Fix dynamic dispatch. * Polish. --- tools/gfx/renderer-shared.cpp | 51 ++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 15 deletions(-) (limited to 'tools/gfx/renderer-shared.cpp') diff --git a/tools/gfx/renderer-shared.cpp b/tools/gfx/renderer-shared.cpp index 54311dd47..911d4712c 100644 --- a/tools/gfx/renderer-shared.cpp +++ b/tools/gfx/renderer-shared.cpp @@ -523,9 +523,18 @@ SLANG_NO_THROW Result SLANG_MCALL RendererBase::createShaderObject( slang::TypeReflection* type, ShaderObjectContainerType container, IShaderObject** outObject) +{ + return createShaderObject2(slangContext.session, type, container, outObject); +} + +SLANG_NO_THROW Result SLANG_MCALL RendererBase::createShaderObject2( + slang::ISession* slangSession, + slang::TypeReflection* type, + ShaderObjectContainerType container, + IShaderObject** outObject) { RefPtr shaderObjectLayout; - SLANG_RETURN_ON_FAIL(getShaderObjectLayout(type, container, shaderObjectLayout.writeRef())); + SLANG_RETURN_ON_FAIL(getShaderObjectLayout(slangSession, type, container, shaderObjectLayout.writeRef())); return createShaderObject(shaderObjectLayout, outObject); } @@ -533,9 +542,18 @@ SLANG_NO_THROW Result SLANG_MCALL RendererBase::createMutableShaderObject( slang::TypeReflection* type, ShaderObjectContainerType containerType, IShaderObject** outObject) +{ + return createMutableShaderObject2(slangContext.session, type, containerType, outObject); +} + +SLANG_NO_THROW Result SLANG_MCALL RendererBase::createMutableShaderObject2( + slang::ISession* slangSession, + slang::TypeReflection* type, + ShaderObjectContainerType containerType, + IShaderObject** outObject) { RefPtr shaderObjectLayout; - SLANG_RETURN_ON_FAIL(getShaderObjectLayout(type, containerType, shaderObjectLayout.writeRef())); + SLANG_RETURN_ON_FAIL(getShaderObjectLayout(slangSession, type, containerType, shaderObjectLayout.writeRef())); return createMutableShaderObject(shaderObjectLayout, outObject); } @@ -616,7 +634,7 @@ SLANG_NO_THROW Result SLANG_MCALL RendererBase::createShaderObjectFromTypeLayout slang::TypeLayoutReflection* typeLayout, IShaderObject** outObject) { RefPtr shaderObjectLayout; - SLANG_RETURN_ON_FAIL(getShaderObjectLayout(typeLayout, shaderObjectLayout.writeRef())); + SLANG_RETURN_ON_FAIL(getShaderObjectLayout(slangContext.session, typeLayout, shaderObjectLayout.writeRef())); return createShaderObject(shaderObjectLayout, outObject); } @@ -624,7 +642,7 @@ SLANG_NO_THROW Result SLANG_MCALL RendererBase::createMutableShaderObjectFromTyp slang::TypeLayoutReflection* typeLayout, IShaderObject** outObject) { RefPtr shaderObjectLayout; - SLANG_RETURN_ON_FAIL(getShaderObjectLayout(typeLayout, shaderObjectLayout.writeRef())); + SLANG_RETURN_ON_FAIL(getShaderObjectLayout(slangContext.session, typeLayout, shaderObjectLayout.writeRef())); return createMutableShaderObject(shaderObjectLayout, outObject); } @@ -702,6 +720,7 @@ Result RendererBase::getTextureRowAlignment(Size* outAlignment) } Result RendererBase::getShaderObjectLayout( + slang::ISession* session, slang::TypeReflection* type, ShaderObjectContainerType container, ShaderObjectLayoutBase** outLayout) @@ -709,26 +728,30 @@ Result RendererBase::getShaderObjectLayout( switch (container) { case ShaderObjectContainerType::StructuredBuffer: - type = slangContext.session->getContainerType(type, slang::ContainerType::StructuredBuffer); + type = session->getContainerType(type, slang::ContainerType::StructuredBuffer); break; case ShaderObjectContainerType::Array: - type = slangContext.session->getContainerType(type, slang::ContainerType::UnsizedArray); + type = session->getContainerType(type, slang::ContainerType::UnsizedArray); break; default: break; } - auto typeLayout = slangContext.session->getTypeLayout(type); - return getShaderObjectLayout(typeLayout, outLayout); + auto typeLayout = session->getTypeLayout(type); + SLANG_RETURN_ON_FAIL(getShaderObjectLayout(session, typeLayout, outLayout)); + (*outLayout)->m_slangSession = session; + return SLANG_OK; } Result RendererBase::getShaderObjectLayout( - slang::TypeLayoutReflection* typeLayout, ShaderObjectLayoutBase** outLayout) + slang::ISession* session, + slang::TypeLayoutReflection* typeLayout, + ShaderObjectLayoutBase** outLayout) { RefPtr shaderObjectLayout; if (!m_shaderObjectLayoutCache.tryGetValue(typeLayout, shaderObjectLayout)) { - SLANG_RETURN_ON_FAIL(createShaderObjectLayout(typeLayout, shaderObjectLayout.writeRef())); + SLANG_RETURN_ON_FAIL(createShaderObjectLayout(session, typeLayout, shaderObjectLayout.writeRef())); m_shaderObjectLayoutCache.add(typeLayout, shaderObjectLayout); } *outLayout = shaderObjectLayout.detach(); @@ -830,9 +853,10 @@ void ShaderCache::addSpecializedPipeline(PipelineKey key, Slang::RefPtrshaderCache.getComponentId(m_elementTypeLayout->getType()); } @@ -887,15 +911,12 @@ Result ShaderObjectBase::setExistentialHeader( // Slang runtime, so we can look up the ID for this particular conformance (which // will create it on demand). // - ComPtr slangSession; - SLANG_RETURN_ON_FAIL(getRenderer()->getSlangSession(slangSession.writeRef())); - // // Note: If the type doesn't actually conform to the required interface for // this sub-object range, then this is the point where we will detect that // fact and error out. // uint32_t conformanceID = 0xFFFFFFFF; - SLANG_RETURN_ON_FAIL(slangSession->getTypeConformanceWitnessSequentialID( + SLANG_RETURN_ON_FAIL(getLayoutBase()->m_slangSession->getTypeConformanceWitnessSequentialID( concreteType, existentialType, &conformanceID)); // // Once we have the conformance ID, then we can write it into the object -- cgit v1.2.3