summaryrefslogtreecommitdiffstats
path: root/tools/gfx/renderer-shared.cpp
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2024-10-29 14:49:26 +0800
committerGitHub <noreply@github.com>2024-10-29 14:49:26 +0800
commitf65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 (patch)
treeea1d61342cd29368e19135000ec2948813096205 /tools/gfx/renderer-shared.cpp
parenta729c15e9dce9f5116a38afc66329ab2ca4cea54 (diff)
format
* format * Minor test fixes * enable checking cpp format in ci
Diffstat (limited to 'tools/gfx/renderer-shared.cpp')
-rw-r--r--tools/gfx/renderer-shared.cpp372
1 files changed, 219 insertions, 153 deletions
diff --git a/tools/gfx/renderer-shared.cpp b/tools/gfx/renderer-shared.cpp
index 65a14c8cb..5a7aa4b64 100644
--- a/tools/gfx/renderer-shared.cpp
+++ b/tools/gfx/renderer-shared.cpp
@@ -1,11 +1,10 @@
#include "renderer-shared.h"
-#include "mutable-shader-object.h"
-#include "core/slang-io.h"
-#include "core/slang-token-reader.h"
-#include "../../source/core/slang-stable-hash.h"
#include "../../source/core/slang-file-system.h"
-
+#include "../../source/core/slang-stable-hash.h"
+#include "core/slang-io.h"
+#include "core/slang-token-reader.h"
+#include "mutable-shader-object.h"
#include "slang.h"
using namespace Slang;
@@ -45,8 +44,10 @@ const Slang::Guid GfxGUID::IID_IQueryPool = SLANG_UUID_IQueryPool;
const Slang::Guid GfxGUID::IID_IAccelerationStructure = SLANG_UUID_IAccelerationStructure;
const Slang::Guid GfxGUID::IID_IFence = SLANG_UUID_IFence;
const Slang::Guid GfxGUID::IID_IShaderTable = SLANG_UUID_IShaderTable;
-const Slang::Guid GfxGUID::IID_IPipelineCreationAPIDispatcher = SLANG_UUID_IPipelineCreationAPIDispatcher;
-const Slang::Guid GfxGUID::IID_IVulkanPipelineCreationAPIDispatcher = SLANG_UUID_IVulkanPipelineCreationAPIDispatcher;
+const Slang::Guid GfxGUID::IID_IPipelineCreationAPIDispatcher =
+ SLANG_UUID_IPipelineCreationAPIDispatcher;
+const Slang::Guid GfxGUID::IID_IVulkanPipelineCreationAPIDispatcher =
+ SLANG_UUID_IVulkanPipelineCreationAPIDispatcher;
const Slang::Guid GfxGUID::IID_ITransientResourceHeapD3D12 = SLANG_UUID_ITransientResourceHeapD3D12;
@@ -54,13 +55,10 @@ StageType translateStage(SlangStage slangStage)
{
switch (slangStage)
{
- default:
- SLANG_ASSERT(!"unhandled case");
- return gfx::StageType::Unknown;
+ default: SLANG_ASSERT(!"unhandled case"); return gfx::StageType::Unknown;
-#define CASE(FROM, TO) \
-case SLANG_STAGE_##FROM: \
-return gfx::StageType::TO
+#define CASE(FROM, TO) \
+ case SLANG_STAGE_##FROM: return gfx::StageType::TO
CASE(VERTEX, Vertex);
CASE(HULL, Hull);
@@ -96,8 +94,14 @@ IResource* BufferResource::getInterface(const Slang::Guid& guid)
return nullptr;
}
-SLANG_NO_THROW IResource::Type SLANG_MCALL BufferResource::getType() { return m_type; }
-SLANG_NO_THROW IBufferResource::Desc* SLANG_MCALL BufferResource::getDesc() { return &m_desc; }
+SLANG_NO_THROW IResource::Type SLANG_MCALL BufferResource::getType()
+{
+ return m_type;
+}
+SLANG_NO_THROW IBufferResource::Desc* SLANG_MCALL BufferResource::getDesc()
+{
+ return &m_desc;
+}
Result BufferResource::getNativeResourceHandle(InteropHandle* outHandle)
{
@@ -121,8 +125,14 @@ IResource* TextureResource::getInterface(const Slang::Guid& guid)
return nullptr;
}
-SLANG_NO_THROW IResource::Type SLANG_MCALL TextureResource::getType() { return m_type; }
-SLANG_NO_THROW ITextureResource::Desc* SLANG_MCALL TextureResource::getDesc() { return &m_desc; }
+SLANG_NO_THROW IResource::Type SLANG_MCALL TextureResource::getType()
+{
+ return m_type;
+}
+SLANG_NO_THROW ITextureResource::Desc* SLANG_MCALL TextureResource::getDesc()
+{
+ return &m_desc;
+}
Result TextureResource::getNativeResourceHandle(InteropHandle* outHandle)
{
@@ -140,25 +150,24 @@ Result TextureResource::getSharedHandle(InteropHandle* outHandle)
StageType mapStage(SlangStage stage)
{
- switch( stage )
+ switch (stage)
{
- default:
- return StageType::Unknown;
-
- case SLANG_STAGE_AMPLIFICATION: return gfx::StageType::Amplification;
- case SLANG_STAGE_ANY_HIT: return gfx::StageType::AnyHit;
- case SLANG_STAGE_CALLABLE: return gfx::StageType::Callable;
- case SLANG_STAGE_CLOSEST_HIT: return gfx::StageType::ClosestHit;
- case SLANG_STAGE_COMPUTE: return gfx::StageType::Compute;
- case SLANG_STAGE_DOMAIN: return gfx::StageType::Domain;
- case SLANG_STAGE_FRAGMENT: return gfx::StageType::Fragment;
- case SLANG_STAGE_GEOMETRY: return gfx::StageType::Geometry;
- case SLANG_STAGE_HULL: return gfx::StageType::Hull;
- case SLANG_STAGE_INTERSECTION: return gfx::StageType::Intersection;
- case SLANG_STAGE_MESH: return gfx::StageType::Mesh;
- case SLANG_STAGE_MISS: return gfx::StageType::Miss;
- case SLANG_STAGE_RAY_GENERATION: return gfx::StageType::RayGeneration;
- case SLANG_STAGE_VERTEX: return gfx::StageType::Vertex;
+ default: return StageType::Unknown;
+
+ case SLANG_STAGE_AMPLIFICATION: return gfx::StageType::Amplification;
+ case SLANG_STAGE_ANY_HIT: return gfx::StageType::AnyHit;
+ case SLANG_STAGE_CALLABLE: return gfx::StageType::Callable;
+ case SLANG_STAGE_CLOSEST_HIT: return gfx::StageType::ClosestHit;
+ case SLANG_STAGE_COMPUTE: return gfx::StageType::Compute;
+ case SLANG_STAGE_DOMAIN: return gfx::StageType::Domain;
+ case SLANG_STAGE_FRAGMENT: return gfx::StageType::Fragment;
+ case SLANG_STAGE_GEOMETRY: return gfx::StageType::Geometry;
+ case SLANG_STAGE_HULL: return gfx::StageType::Hull;
+ case SLANG_STAGE_INTERSECTION: return gfx::StageType::Intersection;
+ case SLANG_STAGE_MESH: return gfx::StageType::Mesh;
+ case SLANG_STAGE_MISS: return gfx::StageType::Miss;
+ case SLANG_STAGE_RAY_GENERATION: return gfx::StageType::RayGeneration;
+ case SLANG_STAGE_VERTEX: return gfx::StageType::Vertex;
}
}
@@ -199,8 +208,8 @@ IAccelerationStructure* AccelerationStructureBase::getInterface(const Slang::Gui
}
bool _doesValueFitInExistentialPayload(
- slang::TypeLayoutReflection* concreteTypeLayout,
- slang::TypeLayoutReflection* existentialTypeLayout)
+ slang::TypeLayoutReflection* concreteTypeLayout,
+ slang::TypeLayoutReflection* existentialTypeLayout)
{
// Our task here is to figure out if a value of `concreteTypeLayout`
// can fit into an existential value using `existentialTypelayout`.
@@ -220,7 +229,7 @@ bool _doesValueFitInExistentialPayload(
// If the concrete type consumes more ordinary bytes than we have in the payload,
// it cannot possibly fit.
//
- if(concreteValueSize > existentialPayloadSize)
+ if (concreteValueSize > existentialPayloadSize)
return false;
// It is possible that the ordinary bytes of `concreteTypeLayout` can fit
@@ -229,25 +238,24 @@ bool _doesValueFitInExistentialPayload(
// data can't fit in the payload at all.
//
auto categoryCount = concreteTypeLayout->getCategoryCount();
- for(unsigned int i = 0; i < categoryCount; ++i)
+ for (unsigned int i = 0; i < categoryCount; ++i)
{
auto category = concreteTypeLayout->getCategoryByIndex(i);
- switch(category)
+ switch (category)
{
// We want to ignore any ordinary/uniform data usage, since that
// was already checked above.
//
- case slang::ParameterCategory::Uniform:
- break;
+ case slang::ParameterCategory::Uniform: break;
// Any other kind of data consumed means the value cannot possibly fit.
default:
return false;
- // TODO: Are there any cases of resource usage that need to be ignored here?
- // E.g., if the sub-object contains its own existential-type fields (which
- // get reflected as consuming "existential value" storage) should that be
- // ignored?
+ // TODO: Are there any cases of resource usage that need to be ignored here?
+ // E.g., if the sub-object contains its own existential-type fields (which
+ // get reflected as consuming "existential value" storage) should that be
+ // ignored?
}
}
@@ -356,7 +364,11 @@ Result RendererBase::getEntryPointCodeFromShaderCache(
if (persistentShaderCache->readEntry(cacheKey, codeBlob.writeRef()) != SLANG_OK)
{
// No cached entry found. Generate the code and add it to the cache.
- SLANG_RETURN_ON_FAIL(program->getEntryPointCode(entryPointIndex, targetIndex, codeBlob.writeRef(), outDiagnostics));
+ SLANG_RETURN_ON_FAIL(program->getEntryPointCode(
+ entryPointIndex,
+ targetIndex,
+ codeBlob.writeRef(),
+ outDiagnostics));
persistentShaderCache->writeEntry(cacheKey, codeBlob);
}
@@ -419,8 +431,8 @@ SLANG_NO_THROW Result SLANG_MCALL RendererBase::getNativeDeviceHandles(InteropHa
return SLANG_OK;
}
-SLANG_NO_THROW Result SLANG_MCALL RendererBase::getFeatures(
- const char** outFeatures, Size bufferSize, GfxCount* outFeatureCount)
+SLANG_NO_THROW Result SLANG_MCALL
+RendererBase::getFeatures(const char** outFeatures, Size bufferSize, GfxCount* outFeatureCount)
{
if (bufferSize >= (UInt)m_features.getCount())
{
@@ -534,7 +546,8 @@ SLANG_NO_THROW Result SLANG_MCALL RendererBase::createShaderObject2(
IShaderObject** outObject)
{
RefPtr<ShaderObjectLayoutBase> shaderObjectLayout;
- SLANG_RETURN_ON_FAIL(getShaderObjectLayout(slangSession, type, container, shaderObjectLayout.writeRef()));
+ SLANG_RETURN_ON_FAIL(
+ getShaderObjectLayout(slangSession, type, container, shaderObjectLayout.writeRef()));
return createShaderObject(shaderObjectLayout, outObject);
}
@@ -553,7 +566,8 @@ SLANG_NO_THROW Result SLANG_MCALL RendererBase::createMutableShaderObject2(
IShaderObject** outObject)
{
RefPtr<ShaderObjectLayoutBase> shaderObjectLayout;
- SLANG_RETURN_ON_FAIL(getShaderObjectLayout(slangSession, type, containerType, shaderObjectLayout.writeRef()));
+ SLANG_RETURN_ON_FAIL(
+ getShaderObjectLayout(slangSession, type, containerType, shaderObjectLayout.writeRef()));
return createMutableShaderObject(shaderObjectLayout, outObject);
}
@@ -567,7 +581,7 @@ Result RendererBase::createProgram2(
ComPtr<slang::IBlob> diagnosticsBlob;
switch (desc.sourceType)
{
- case ShaderModuleSourceType::SlangSourceFile:
+ case ShaderModuleSourceType::SlangSourceFile:
{
auto fileName = (char*)desc.sourceData;
module = slangSession->loadModule(fileName, diagnosticsBlob.writeRef());
@@ -575,18 +589,21 @@ Result RendererBase::createProgram2(
return SLANG_FAIL;
break;
}
- case ShaderModuleSourceType::SlangSource:
+ case ShaderModuleSourceType::SlangSource:
{
auto hash = getStableHashCode32((char*)desc.sourceData, desc.sourceDataSize);
auto hashStr = String(hash);
auto srcBlob = UnownedRawBlob::create(desc.sourceData, desc.sourceDataSize);
- module = slangSession->loadModuleFromSource(hashStr.getBuffer(), hashStr.getBuffer(), srcBlob, diagnosticsBlob.writeRef());
+ module = slangSession->loadModuleFromSource(
+ hashStr.getBuffer(),
+ hashStr.getBuffer(),
+ srcBlob,
+ diagnosticsBlob.writeRef());
if (!module)
return SLANG_FAIL;
break;
}
- default:
- SLANG_RELEASE_ASSERT(false);
+ default: SLANG_RELEASE_ASSERT(false);
}
Slang::List<ComPtr<slang::IComponentType>> componentTypes;
@@ -606,7 +623,8 @@ Result RendererBase::createProgram2(
for (GfxCount i = 0; i < desc.entryPointCount; i++)
{
ComPtr<slang::IEntryPoint> entryPoint;
- SLANG_RETURN_ON_FAIL(module->findEntryPointByName(desc.entryPointNames[i], entryPoint.writeRef()));
+ SLANG_RETURN_ON_FAIL(
+ module->findEntryPointByName(desc.entryPointNames[i], entryPoint.writeRef()));
componentTypes.add(ComPtr<slang::IComponentType>(entryPoint.get()));
}
}
@@ -631,18 +649,22 @@ Result RendererBase::createProgram2(
}
SLANG_NO_THROW Result SLANG_MCALL RendererBase::createShaderObjectFromTypeLayout(
- slang::TypeLayoutReflection* typeLayout, IShaderObject** outObject)
+ slang::TypeLayoutReflection* typeLayout,
+ IShaderObject** outObject)
{
RefPtr<ShaderObjectLayoutBase> shaderObjectLayout;
- SLANG_RETURN_ON_FAIL(getShaderObjectLayout(slangContext.session, typeLayout, shaderObjectLayout.writeRef()));
+ SLANG_RETURN_ON_FAIL(
+ getShaderObjectLayout(slangContext.session, typeLayout, shaderObjectLayout.writeRef()));
return createShaderObject(shaderObjectLayout, outObject);
}
SLANG_NO_THROW Result SLANG_MCALL RendererBase::createMutableShaderObjectFromTypeLayout(
- slang::TypeLayoutReflection* typeLayout, IShaderObject** outObject)
+ slang::TypeLayoutReflection* typeLayout,
+ IShaderObject** outObject)
{
RefPtr<ShaderObjectLayoutBase> shaderObjectLayout;
- SLANG_RETURN_ON_FAIL(getShaderObjectLayout(slangContext.session, typeLayout, shaderObjectLayout.writeRef()));
+ SLANG_RETURN_ON_FAIL(
+ getShaderObjectLayout(slangContext.session, typeLayout, shaderObjectLayout.writeRef()));
return createMutableShaderObject(shaderObjectLayout, outObject);
}
@@ -671,7 +693,9 @@ Result RendererBase::createShaderTable(const IShaderTable::Desc& desc, IShaderTa
return SLANG_E_NOT_AVAILABLE;
}
-Result RendererBase::createRayTracingPipelineState(const RayTracingPipelineStateDesc& desc, IPipelineState** outState)
+Result RendererBase::createRayTracingPipelineState(
+ const RayTracingPipelineStateDesc& desc,
+ IPipelineState** outState)
{
SLANG_UNUSED(desc);
SLANG_UNUSED(outState);
@@ -679,7 +703,8 @@ Result RendererBase::createRayTracingPipelineState(const RayTracingPipelineState
}
Result RendererBase::createMutableRootShaderObject(
- IShaderProgram* program, IShaderObject** outObject)
+ IShaderProgram* program,
+ IShaderObject** outObject)
{
SLANG_UNUSED(program);
SLANG_UNUSED(outObject);
@@ -694,7 +719,11 @@ Result RendererBase::createFence(const IFence::Desc& desc, IFence** outFence)
}
Result RendererBase::waitForFences(
- GfxCount fenceCount, IFence** fences, uint64_t* fenceValues, bool waitForAll, uint64_t timeout)
+ GfxCount fenceCount,
+ IFence** fences,
+ uint64_t* fenceValues,
+ bool waitForAll,
+ uint64_t timeout)
{
SLANG_UNUSED(fenceCount);
SLANG_UNUSED(fences);
@@ -705,7 +734,9 @@ Result RendererBase::waitForFences(
}
Result RendererBase::getTextureAllocationInfo(
- const ITextureResource::Desc& desc, Size* outSize, Size* outAlignment)
+ const ITextureResource::Desc& desc,
+ Size* outSize,
+ Size* outAlignment)
{
SLANG_UNUSED(desc);
*outSize = 0;
@@ -733,8 +764,7 @@ Result RendererBase::getShaderObjectLayout(
case ShaderObjectContainerType::Array:
type = session->getContainerType(type, slang::ContainerType::UnsizedArray);
break;
- default:
- break;
+ default: break;
}
auto typeLayout = session->getTypeLayout(type);
@@ -751,7 +781,8 @@ Result RendererBase::getShaderObjectLayout(
RefPtr<ShaderObjectLayoutBase> shaderObjectLayout;
if (!m_shaderObjectLayoutCache.tryGetValue(typeLayout, shaderObjectLayout))
{
- SLANG_RETURN_ON_FAIL(createShaderObjectLayout(session, typeLayout, shaderObjectLayout.writeRef()));
+ SLANG_RETURN_ON_FAIL(
+ createShaderObjectLayout(session, typeLayout, shaderObjectLayout.writeRef()));
m_shaderObjectLayoutCache.add(typeLayout, shaderObjectLayout);
}
*outLayout = shaderObjectLayout.detach();
@@ -799,16 +830,17 @@ ShaderComponentID ShaderCache::getComponentId(slang::TypeReflection* type)
StringBuilder builder;
builder.append(UnownedTerminatedStringSlice(baseType->getName()));
- auto rawType = (SlangReflectionType*) type;
+ auto rawType = (SlangReflectionType*)type;
builder.appendChar('<');
SlangInt argCount = spReflectionType_getSpecializedTypeArgCount(rawType);
- for(SlangInt a = 0; a < argCount; ++a)
+ for (SlangInt a = 0; a < argCount; ++a)
{
- if(a != 0) builder.appendChar(',');
- if(auto rawArgType = spReflectionType_getSpecializedTypeArgType(rawType, a))
+ if (a != 0)
+ builder.appendChar(',');
+ if (auto rawArgType = spReflectionType_getSpecializedTypeArgType(rawType, a))
{
- auto argType = (slang::TypeReflection*) rawArgType;
+ auto argType = (slang::TypeReflection*)rawArgType;
builder.append(argType->getName());
}
}
@@ -819,8 +851,7 @@ ShaderComponentID ShaderCache::getComponentId(slang::TypeReflection* type)
}
// TODO: collect specialization arguments and append them to `key`.
SLANG_UNIMPLEMENTED_X("specialized type");
- default:
- break;
+ default: break;
}
key.updateHash();
return getComponentId(key);
@@ -848,12 +879,17 @@ ShaderComponentID ShaderCache::getComponentId(ComponentKey key)
return resultId;
}
-void ShaderCache::addSpecializedPipeline(PipelineKey key, Slang::RefPtr<PipelineStateBase> specializedPipeline)
+void ShaderCache::addSpecializedPipeline(
+ PipelineKey key,
+ Slang::RefPtr<PipelineStateBase> specializedPipeline)
{
specializedPipelines[key] = specializedPipeline;
}
-void ShaderObjectLayoutBase::initBase(RendererBase* renderer, slang::ISession* session, slang::TypeLayoutReflection* elementTypeLayout)
+void ShaderObjectLayoutBase::initBase(
+ RendererBase* renderer,
+ slang::ISession* session,
+ slang::TypeLayoutReflection* elementTypeLayout)
{
m_renderer = renderer;
m_slangSession = session;
@@ -861,8 +897,9 @@ void ShaderObjectLayoutBase::initBase(RendererBase* renderer, slang::ISession* s
m_componentID = m_renderer->shaderCache.getComponentId(m_elementTypeLayout->getType());
}
-// Get the final type this shader object represents. If the shader object's type has existential fields,
-// this function will return a specialized type using the bound sub-objects' type as specialization argument.
+// Get the final type this shader object represents. If the shader object's type has existential
+// fields, this function will return a specialized type using the bound sub-objects' type as
+// specialization argument.
Result ShaderObjectBase::getSpecializedShaderObjectType(ExtendedShaderObjectType* outType)
{
return _getSpecializedShaderObjectType(outType);
@@ -883,8 +920,10 @@ Result ShaderObjectBase::_getSpecializedShaderObjectType(ExtendedShaderObjectTyp
{
shaderObjectType.slangType = getRenderer()->slangContext.session->specializeType(
_getElementTypeLayout()->getType(),
- specializationArgs.components.getArrayView().getBuffer(), specializationArgs.getCount());
- shaderObjectType.componentID = getRenderer()->shaderCache.getComponentId(shaderObjectType.slangType);
+ specializationArgs.components.getArrayView().getBuffer(),
+ specializationArgs.getCount());
+ shaderObjectType.componentID =
+ getRenderer()->shaderCache.getComponentId(shaderObjectType.slangType);
}
*outType = shaderObjectType;
return SLANG_OK;
@@ -917,7 +956,9 @@ Result ShaderObjectBase::setExistentialHeader(
//
uint32_t conformanceID = 0xFFFFFFFF;
SLANG_RETURN_ON_FAIL(getLayoutBase()->m_slangSession->getTypeConformanceWitnessSequentialID(
- concreteType, existentialType, &conformanceID));
+ concreteType,
+ existentialType,
+ &conformanceID));
//
// Once we have the conformance ID, then we can write it into the object
// at the required offset.
@@ -945,7 +986,9 @@ ResourceViewBase* SimpleShaderObjectData::getResourceView(
desc.sizeInBytes = (Size)m_ordinaryData.getCount();
ComPtr<IBufferResource> bufferResource;
SLANG_RETURN_NULL_ON_FAIL(device->createBufferResource(
- desc, m_ordinaryData.getBuffer(), bufferResource.writeRef()));
+ desc,
+ m_ordinaryData.getBuffer(),
+ bufferResource.writeRef()));
m_structuredBuffer = static_cast<BufferResource*>(bufferResource.get());
// Create read-only (shader-resource) and mutable (unordered access) views.
@@ -954,24 +997,25 @@ ResourceViewBase* SimpleShaderObjectData::getResourceView(
viewDesc.format = Format::Unknown;
viewDesc.type = IResourceView::Type::ShaderResource;
SLANG_RETURN_NULL_ON_FAIL(device->createBufferView(
- bufferResource.get(), nullptr, viewDesc, resourceView.writeRef()));
+ bufferResource.get(),
+ nullptr,
+ viewDesc,
+ resourceView.writeRef()));
m_structuredBufferView = static_cast<ResourceViewBase*>(resourceView.get());
viewDesc.type = IResourceView::Type::UnorderedAccess;
- SLANG_RETURN_NULL_ON_FAIL(
- device->createBufferView(
- bufferResource.get(), nullptr, viewDesc, resourceView.writeRef()));
+ SLANG_RETURN_NULL_ON_FAIL(device->createBufferView(
+ bufferResource.get(),
+ nullptr,
+ viewDesc,
+ resourceView.writeRef()));
m_rwStructuredBufferView = static_cast<ResourceViewBase*>(resourceView.get());
}
switch (bindingType)
{
- case slang::BindingType::RawBuffer:
- return m_structuredBufferView.Ptr();
- case slang::BindingType::MutableRawBuffer:
- return m_rwStructuredBufferView.Ptr();
- default:
- SLANG_ASSERT(false && "Invalid binding type.");
- return nullptr;
+ case slang::BindingType::RawBuffer: return m_structuredBufferView.Ptr();
+ case slang::BindingType::MutableRawBuffer: return m_rwStructuredBufferView.Ptr();
+ default: SLANG_ASSERT(false && "Invalid binding type."); return nullptr;
}
}
@@ -1002,7 +1046,9 @@ void ShaderProgramBase::init(const IShaderProgram::Desc& inDesc)
components.add(desc.slangEntryPoints[i]);
}
session->createCompositeComponentType(
- components.getBuffer(), components.getCount(), linkedProgram.writeRef());
+ components.getBuffer(),
+ components.getCount(),
+ linkedProgram.writeRef());
}
else
{
@@ -1011,10 +1057,13 @@ void ShaderProgramBase::init(const IShaderProgram::Desc& inDesc)
if (desc.slangGlobalScope)
{
slang::IComponentType* entryPointComponents[2] = {
- desc.slangGlobalScope, desc.slangEntryPoints[i]};
+ desc.slangGlobalScope,
+ desc.slangEntryPoints[i]};
ComPtr<slang::IComponentType> linkedEntryPoint;
session->createCompositeComponentType(
- entryPointComponents, 2, linkedEntryPoint.writeRef());
+ entryPointComponents,
+ 2,
+ linkedEntryPoint.writeRef());
linkedEntryPoints.add(linkedEntryPoint);
}
else
@@ -1036,8 +1085,12 @@ Result ShaderProgramBase::compileShaders(RendererBase* device)
auto stage = entryPointInfo->getStage();
ComPtr<ISlangBlob> kernelCode;
ComPtr<ISlangBlob> diagnostics;
- auto compileResult = device->getEntryPointCodeFromShaderCache(entryPointComponent,
- entryPointIndex, 0, kernelCode.writeRef(), diagnostics.writeRef());
+ auto compileResult = device->getEntryPointCodeFromShaderCache(
+ entryPointComponent,
+ entryPointIndex,
+ 0,
+ kernelCode.writeRef(),
+ diagnostics.writeRef());
if (diagnostics)
{
DebugMessageType msgType = DebugMessageType::Warning;
@@ -1061,7 +1114,9 @@ Result ShaderProgramBase::compileShaders(RendererBase* device)
for (SlangUInt i = 0; i < programReflection->getEntryPointCount(); i++)
{
SLANG_RETURN_ON_FAIL(compileShader(
- programReflection->getEntryPointByIndex(i), linkedProgram, (SlangInt)i));
+ programReflection->getEntryPointByIndex(i),
+ linkedProgram,
+ (SlangInt)i));
}
}
else
@@ -1078,7 +1133,8 @@ Result ShaderProgramBase::compileShaders(RendererBase* device)
}
Result ShaderProgramBase::createShaderModule(
- slang::EntryPointReflection* entryPointInfo, ComPtr<ISlangBlob> kernelCode)
+ slang::EntryPointReflection* entryPointInfo,
+ ComPtr<ISlangBlob> kernelCode)
{
SLANG_UNUSED(entryPointInfo);
SLANG_UNUSED(kernelCode);
@@ -1089,17 +1145,17 @@ bool ShaderProgramBase::isMeshShaderProgram() const
{
// Similar to above, interrogate either explicity specified entry point
// componenets or the ones in the linked program entry point array
- if(linkedEntryPoints.getCount())
+ if (linkedEntryPoints.getCount())
{
- for(const auto& e : linkedEntryPoints)
- if(e->getLayout()->getEntryPointByIndex(0)->getStage() == SLANG_STAGE_MESH)
+ for (const auto& e : linkedEntryPoints)
+ if (e->getLayout()->getEntryPointByIndex(0)->getStage() == SLANG_STAGE_MESH)
return true;
}
else
{
const auto programReflection = linkedProgram->getLayout();
- for(SlangUInt i = 0; i < programReflection->getEntryPointCount(); ++i)
- if(programReflection->getEntryPointByIndex(i)->getStage() == SLANG_STAGE_MESH)
+ for (SlangUInt i = 0; i < programReflection->getEntryPointCount(); ++i)
+ if (programReflection->getEntryPointByIndex(i)->getStage() == SLANG_STAGE_MESH)
return true;
}
return false;
@@ -1111,11 +1167,12 @@ Result RendererBase::maybeSpecializePipeline(
RefPtr<PipelineStateBase>& outNewPipeline)
{
outNewPipeline = static_cast<PipelineStateBase*>(currentPipeline);
-
+
auto pipelineType = currentPipeline->desc.type;
if (currentPipeline->unspecializedPipelineState)
currentPipeline = currentPipeline->unspecializedPipelineState;
- // If the currently bound pipeline is specializable, we need to specialize it based on bound shader objects.
+ // If the currently bound pipeline is specializable, we need to specialize it based on bound
+ // shader objects.
if (currentPipeline->isSpecializable)
{
specializationArgs.clear();
@@ -1127,13 +1184,14 @@ Result RendererBase::maybeSpecializePipeline(
pipelineKey.specializationArgs.addRange(specializationArgs.componentIDs);
pipelineKey.updateHash();
- RefPtr<PipelineStateBase> specializedPipelineState = shaderCache.getSpecializedPipelineState(pipelineKey);
+ RefPtr<PipelineStateBase> specializedPipelineState =
+ shaderCache.getSpecializedPipelineState(pipelineKey);
// Try to find specialized pipeline from shader cache.
if (!specializedPipelineState)
{
- auto unspecializedProgram = static_cast<ShaderProgramBase*>(pipelineType == PipelineType::Compute
- ? currentPipeline->desc.compute.program
- : currentPipeline->desc.graphics.program);
+ auto unspecializedProgram = static_cast<ShaderProgramBase*>(
+ pipelineType == PipelineType::Compute ? currentPipeline->desc.compute.program
+ : currentPipeline->desc.graphics.program);
auto unspecializedProgramLayout = unspecializedProgram->linkedProgram->getLayout();
ComPtr<slang::IComponentType> specializedComponentType;
@@ -1159,50 +1217,56 @@ Result RendererBase::maybeSpecializePipeline(
if (specializedProgramDesc.linkingStyle == IShaderProgram::LinkingStyle::SingleProgram)
{
- // When linking style is GraphicsCompute, the specialized global scope already contains
- // entry-points, so we do not need to supply them again when creating the specialized
- // pipeline.
+ // When linking style is GraphicsCompute, the specialized global scope already
+ // contains entry-points, so we do not need to supply them again when creating the
+ // specialized pipeline.
specializedProgramDesc.entryPointCount = 0;
}
- SLANG_RETURN_ON_FAIL(createProgram(specializedProgramDesc, specializedProgram.writeRef()));
+ SLANG_RETURN_ON_FAIL(
+ createProgram(specializedProgramDesc, specializedProgram.writeRef()));
// Create specialized pipeline state.
ComPtr<IPipelineState> specializedPipelineComPtr;
switch (pipelineType)
{
case PipelineType::Compute:
- {
- auto pipelineDesc = currentPipeline->desc.compute;
- pipelineDesc.program = specializedProgram;
- SLANG_RETURN_ON_FAIL(
- createComputePipelineState(pipelineDesc, specializedPipelineComPtr.writeRef()));
- break;
- }
+ {
+ auto pipelineDesc = currentPipeline->desc.compute;
+ pipelineDesc.program = specializedProgram;
+ SLANG_RETURN_ON_FAIL(createComputePipelineState(
+ pipelineDesc,
+ specializedPipelineComPtr.writeRef()));
+ break;
+ }
case PipelineType::Graphics:
- {
- auto pipelineDesc = currentPipeline->desc.graphics;
- pipelineDesc.program = static_cast<ShaderProgramBase*>(specializedProgram.get());
- SLANG_RETURN_ON_FAIL(createGraphicsPipelineState(
- pipelineDesc, specializedPipelineComPtr.writeRef()));
- break;
- }
+ {
+ auto pipelineDesc = currentPipeline->desc.graphics;
+ pipelineDesc.program =
+ static_cast<ShaderProgramBase*>(specializedProgram.get());
+ SLANG_RETURN_ON_FAIL(createGraphicsPipelineState(
+ pipelineDesc,
+ specializedPipelineComPtr.writeRef()));
+ break;
+ }
case PipelineType::RayTracing:
- {
- auto pipelineDesc = currentPipeline->desc.rayTracing;
- pipelineDesc.program = static_cast<ShaderProgramBase*>(specializedProgram.get());
- SLANG_RETURN_ON_FAIL(createRayTracingPipelineState(
- pipelineDesc.get(), specializedPipelineComPtr.writeRef()));
- break;
- }
- default:
- break;
+ {
+ auto pipelineDesc = currentPipeline->desc.rayTracing;
+ pipelineDesc.program =
+ static_cast<ShaderProgramBase*>(specializedProgram.get());
+ SLANG_RETURN_ON_FAIL(createRayTracingPipelineState(
+ pipelineDesc.get(),
+ specializedPipelineComPtr.writeRef()));
+ break;
+ }
+ default: break;
}
specializedPipelineState =
static_cast<PipelineStateBase*>(specializedPipelineComPtr.get());
specializedPipelineState->unspecializedPipelineState = currentPipeline;
shaderCache.addSpecializedPipeline(pipelineKey, specializedPipelineState);
}
- auto specializedPipelineStateBase = static_cast<PipelineStateBase*>(specializedPipelineState.Ptr());
+ auto specializedPipelineStateBase =
+ static_cast<PipelineStateBase*>(specializedPipelineState.Ptr());
outNewPipeline = specializedPipelineStateBase;
}
return SLANG_OK;
@@ -1218,7 +1282,7 @@ class NullDebugCallback : public IDebugCallback
{
public:
virtual SLANG_NO_THROW void SLANG_MCALL
- handleMessage(DebugMessageType type, DebugMessageSource source, const char* message) override
+ handleMessage(DebugMessageType type, DebugMessageSource source, const char* message) override
{
SLANG_UNUSED(type);
SLANG_UNUSED(source);
@@ -1235,7 +1299,10 @@ Result ShaderObjectBase::copyFrom(IShaderObject* object, ITransientResourceHeap*
{
if (auto srcObj = dynamic_cast<MutableRootShaderObject*>(object))
{
- setData(gfx::ShaderOffset(), srcObj->m_data.begin(), (size_t)srcObj->m_data.getCount()); // TODO: Change size_t to Count?
+ setData(
+ gfx::ShaderOffset(),
+ srcObj->m_data.begin(),
+ (size_t)srcObj->m_data.getCount()); // TODO: Change size_t to Count?
for (auto& kv : srcObj->m_objects)
{
ComPtr<IShaderObject> subObject;
@@ -1265,8 +1332,12 @@ Result ShaderTableBase::init(const IShaderTable::Desc& desc)
m_missShaderCount = desc.missShaderCount;
m_hitGroupCount = desc.hitGroupCount;
m_callableShaderCount = desc.callableShaderCount;
- m_shaderGroupNames.reserve(desc.hitGroupCount + desc.missShaderCount + desc.rayGenShaderCount + desc.callableShaderCount);
- m_recordOverwrites.reserve(desc.hitGroupCount + desc.missShaderCount + desc.rayGenShaderCount + desc.callableShaderCount);
+ m_shaderGroupNames.reserve(
+ desc.hitGroupCount + desc.missShaderCount + desc.rayGenShaderCount +
+ desc.callableShaderCount);
+ m_recordOverwrites.reserve(
+ desc.hitGroupCount + desc.missShaderCount + desc.rayGenShaderCount +
+ desc.callableShaderCount);
for (GfxIndex i = 0; i < desc.rayGenShaderCount; i++)
{
m_shaderGroupNames.add(desc.rayGenShaderEntryPointNames[i]);
@@ -1324,10 +1395,8 @@ bool isDepthFormat(Format format)
{
case Format::D16_UNORM:
case Format::D32_FLOAT:
- case Format::D32_FLOAT_S8_UINT:
- return true;
- default:
- return false;
+ case Format::D32_FLOAT_S8_UINT: return true;
+ default: return false;
}
}
@@ -1335,12 +1404,9 @@ bool isStencilFormat(Format format)
{
switch (format)
{
- case Format::D32_FLOAT_S8_UINT:
- return true;
- default:
- return false;
+ case Format::D32_FLOAT_S8_UINT: return true;
+ default: return false;
}
}
} // namespace gfx
-