summaryrefslogtreecommitdiff
path: root/tools/gfx/cpu/cpu-shader-object-layout.h
diff options
context:
space:
mode:
authorlucy96chen <47800040+lucy96chen@users.noreply.github.com>2022-07-27 15:53:36 -0700
committerGitHub <noreply@github.com>2022-07-27 15:53:36 -0700
commited37dcbc175d07134cb0493f5e379a19e97c82f5 (patch)
tree0abd3202401d89e76a979ab7c18569afd63db8a6 /tools/gfx/cpu/cpu-shader-object-layout.h
parentde0f8cf1be0770b87a117b637943db4ad4e1158b (diff)
Split render-cpu into smaller files (#2340)
* render-cpu split, does not compile * split finished, one compile error * added missing include and missing destructor implementation * Rerun TeamCity CI
Diffstat (limited to 'tools/gfx/cpu/cpu-shader-object-layout.h')
-rw-r--r--tools/gfx/cpu/cpu-shader-object-layout.h97
1 files changed, 97 insertions, 0 deletions
diff --git a/tools/gfx/cpu/cpu-shader-object-layout.h b/tools/gfx/cpu/cpu-shader-object-layout.h
new file mode 100644
index 000000000..44c225f83
--- /dev/null
+++ b/tools/gfx/cpu/cpu-shader-object-layout.h
@@ -0,0 +1,97 @@
+// cpu-shader-object-layout.h
+#pragma once
+#include "cpu-base.h"
+
+namespace gfx
+{
+using namespace Slang;
+
+namespace cpu
+{
+
+struct BindingRangeInfo
+{
+ slang::BindingType bindingType;
+ Index count;
+ Index baseIndex; // Flat index for sub-objects
+ Index subObjectIndex;
+
+ // TODO: The `uniformOffset` field should be removed,
+ // since it cannot be supported by the Slang reflection
+ // API once we fix some design issues.
+ //
+ // It is only being used today for pre-allocation of sub-objects
+ // for constant buffers and parameter blocks (which should be
+ // deprecated/removed anyway).
+ //
+ // Note: We would need to bring this field back, plus
+ // a lot of other complexity, if we ever want to support
+ // setting of resources/buffers directly by a binding
+ // range index and array index.
+ //
+ Index uniformOffset; // Uniform offset for a resource typed field.
+};
+
+struct SubObjectRangeInfo
+{
+ RefPtr<ShaderObjectLayoutImpl> layout;
+ Index bindingRangeIndex;
+};
+
+class ShaderObjectLayoutImpl : public ShaderObjectLayoutBase
+{
+public:
+
+ // TODO: Once memory lifetime stuff is handled, there is
+ // no specific need to even track binding or sub-object
+ // ranges for CPU.
+
+ size_t m_size = 0;
+ List<SubObjectRangeInfo> subObjectRanges;
+ List<BindingRangeInfo> m_bindingRanges;
+
+ Index m_subObjectCount = 0;
+ Index m_resourceCount = 0;
+
+ ShaderObjectLayoutImpl(RendererBase* renderer, slang::TypeLayoutReflection* layout);
+
+ size_t getSize();
+ Index getResourceCount() const;
+ Index getSubObjectCount() const;
+ List<SubObjectRangeInfo>& getSubObjectRanges();
+ BindingRangeInfo getBindingRange(Index index);
+ Index getBindingRangeCount() const;
+};
+
+class EntryPointLayoutImpl : public ShaderObjectLayoutImpl
+{
+private:
+ slang::EntryPointLayout* m_entryPointLayout = nullptr;
+
+public:
+ EntryPointLayoutImpl(
+ RendererBase* renderer,
+ slang::EntryPointLayout* entryPointLayout)
+ : ShaderObjectLayoutImpl(renderer, entryPointLayout->getTypeLayout())
+ , m_entryPointLayout(entryPointLayout)
+ {}
+
+ const char* getEntryPointName();
+};
+
+class RootShaderObjectLayoutImpl : public ShaderObjectLayoutImpl
+{
+public:
+ slang::ProgramLayout* m_programLayout = nullptr;
+ List<RefPtr<EntryPointLayoutImpl>> m_entryPointLayouts;
+
+ RootShaderObjectLayoutImpl(RendererBase* renderer, slang::ProgramLayout* programLayout);
+
+ int getKernelIndex(UnownedStringSlice kernelName);
+ void getKernelThreadGroupSize(int kernelIndex, UInt* threadGroupSizes);
+
+ EntryPointLayoutImpl* getEntryPoint(Index index);
+};
+
+} // namespace cpu
+} // namespace gfx