summaryrefslogtreecommitdiffstats
path: root/tools/render-test/render.h
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2018-04-19 17:47:04 -0400
committerTim Foley <tfoleyNV@users.noreply.github.com>2018-04-19 14:47:04 -0700
commit4c751df1680c30fac0369171a9b8dd4bb5bb5b9f (patch)
treeafde05a4cefd2b203add6b6ea8b94722d9734e11 /tools/render-test/render.h
parentcbedf01cc53b848dfcc086f04098ef438121a7c7 (diff)
Separation of Binding/Resource construction on Renderer interface (#508)
* Dx12 rendering works in test framework. * Turn on dx12 render tests. * First pass at Resource and TextureResource/BufferResource types. * Fix bug in Dx11 impl for BufferResource. * Dx12 supports TextureResource and binds using TextureResource type, and all tests pass. * Added TextureBuffer::Size type to make handling mips a little simpler. * Small improvements to Dx12 constant buffer binding Removed k prefix on an enum * First pass impl of dx11 createTextureResource Added setDefaults to TextureResource::Desc and BufferResource::Desc to simplify setup accessFlags -> cpuAccessFlags desc -> srcDesc * Split out generateTextureResource - can produce the texture using createTextureResource on the Renderer. * Added support for read mapping to Dx11 accessFlags -> cpuAccessFlags First pass at using TextureResource/BufferResource on Dx11 Some tests fail with this checkin * TextureResource working on all tests on dx11. * Construct ResourceBuffers on Dx11 and Dx12 using utility function createInputBufferResource. * First pass at OpenGl TextureResource * Small fixes to dx12 and dx11 setup. Gl working working using BufferResource and TextureResource * Tidy up around the compareSampler - looks like the previous test was incorrect. * Small documentation /naming improvements. * Fix some more small documentation issues. * First pass testing out construction of binding resources external to Renderer implementation. * Moved some BindingState::Desc types to BindingState to make easier to use. * First pass of binding using BindingState::Desc for Dx11. * First pass at binding with dx12. * Fixed issues around separating dx12 binding from ShaderInputLayout * First pass at OpenGl state binding. * BindingState::Desc::Binding::Type -> BindingType * Use Buffer to manage life of vk resources. Construction of buffers handled by createBufferResource (BindingState doesn't have specialized logic) * Remove InputLayout types from binding so can create a binding independent of it. * Added upload buffer to BufferResource - could be used for write mapping. * m_samplers -> m_samplerDescs. First pass at Vk binding with BindingState::Desc. Small tidy/doc improvements. * First pass with binding all taking place through BindingState::Desc. All tests pass. * Removed support for creating BindingState from ShaderInputLayout * Remove serializeOutput from Renderer interface and all implementations. Implement map/unmap on vulkan Implement serializeBindingOutput which uses map/unmap and BindingState::Desc to write result. * Make implementation of BindingState use the BindingState::Desc for much of state - only hold api specific in BindingDetail per implementation. * Use Glsl binding on vulkan (was using hlsl). * BindingState::Desc::Binding -> BindingState::Binding. Made possible by impls using 'BindingDetail' for their specific needs. * Fix compile problems on win32. * Fix a typo in name createBindingSetDesc -> createBindingStateDesc
Diffstat (limited to 'tools/render-test/render.h')
-rw-r--r--tools/render-test/render.h156
1 files changed, 139 insertions, 17 deletions
diff --git a/tools/render-test/render.h b/tools/render-test/render.h
index 2800e069b..4a25c2369 100644
--- a/tools/render-test/render.h
+++ b/tools/render-test/render.h
@@ -3,13 +3,16 @@
#include "options.h"
#include "window.h"
-#include "shader-input-layout.h"
+
+//#include "shader-input-layout.h"
#include "../../source/core/slang-result.h"
#include "../../source/core/smart-pointer.h"
+#include "../../source/core/list.h"
namespace renderer_test {
+
// Declare opaque type
class InputLayout: public Slang::RefObject
{
@@ -21,10 +24,7 @@ class ShaderProgram: public Slang::RefObject
public:
};
-class BindingState: public Slang::RefObject
-{
- public:
-};
+
struct ShaderCompileRequest
{
@@ -83,6 +83,7 @@ struct InputElementDesc
enum class MapFlavor
{
+ Unknown, ///< Unknown mapping type
HostRead,
HostWrite,
WriteDiscard,
@@ -155,6 +156,13 @@ class Resource: public Slang::RefObject
};
};
+ /// Base class for Descs
+ struct DescBase
+ {
+ int bindFlags = 0; ///< Combination of Resource::BindFlag or 0 (and will use initialUsage to set)
+ int cpuAccessFlags = 0; ///< Combination of Resource::AccessFlag
+ };
+
/// Get the type
SLANG_FORCE_INLINE Type getType() const { return m_type; }
/// True if it's a texture derived type
@@ -162,6 +170,11 @@ class Resource: public Slang::RefObject
/// True if it's a buffer derived type
SLANG_FORCE_INLINE bool isBuffer() const { return m_type == Type::Buffer; }
+ /// Get the descBase
+ const DescBase& getDescBase() const;
+ /// Returns true if can bind with flag
+ bool canBind(BindFlag::Enum bindFlag) const { return (getDescBase().bindFlags & bindFlag) != 0; }
+
/// For a usage gives the required binding flags
static const BindFlag::Enum s_requiredBinding[int(Usage::CountOf)];
@@ -178,21 +191,16 @@ class BufferResource: public Resource
public:
typedef Resource Parent;
- struct Desc
+ struct Desc: public DescBase
{
void init(size_t sizeInBytesIn)
{
- bindFlags = 0;
- cpuAccessFlags = 0;
sizeInBytes = sizeInBytesIn;
elementSize = 0;
}
/// Set up default parameters based on usage
void setDefaults(Usage initialUsage);
- int bindFlags; ///< Combination of Resource::BindFlag or 0 (and will use initialUsage to set)
- int cpuAccessFlags; ///< Combination of Resource::AccessFlag
-
size_t sizeInBytes; ///< Total size in bytes
int elementSize; ///< Get the element stride. If > 0, this is a structured buffer
};
@@ -249,7 +257,7 @@ class TextureResource: public Resource
int depth; ///< Depth (if 3d)
};
- struct Desc
+ struct Desc: public DescBase
{
/// Initialize with default values
void init();
@@ -274,9 +282,6 @@ class TextureResource: public Resource
/// Set up default parameters based on type and usage
void setDefaults(Type type, Usage initialUsage);
- int bindFlags; ///< Combination of Resource::BindFlag or 0 (and will use initialUsage to set)
- int cpuAccessFlags; ///< Combination of Resource::AccessFlag
-
Size size;
int arraySize; ///< Array size
@@ -318,6 +323,124 @@ class TextureResource: public Resource
Desc m_desc;
};
+enum class BindingType
+{
+ Unknown,
+ Sampler,
+ Buffer,
+ Texture,
+ CombinedTextureSampler,
+ CountOf,
+};
+
+class BindingState : public Slang::RefObject
+{
+public:
+
+ enum class ShaderStyle
+ {
+ Hlsl,
+ Glsl,
+ CountOf,
+ };
+
+ struct RegisterSet
+ {
+ /// Default Ctor makes an empty set
+ SLANG_FORCE_INLINE RegisterSet() :
+ m_numIndices(0),
+ m_indexOrBase(0)
+ {}
+ /// Ctor for one or more. NOTE! Meaning if indexIn changes depending if numIndices > 1.
+ SLANG_FORCE_INLINE RegisterSet(int indexIn, int numIndicesIn) :
+ m_numIndices(uint8_t(numIndicesIn)),
+ m_indexOrBase(uint16_t(indexIn))
+ {
+ }
+ uint8_t m_numIndices;
+ uint16_t m_indexOrBase; ///< Meaning changes depending on numIndices. If 1, it is the index if larger than 1, then is an index into 'indices'
+ };
+
+ struct RegisterDesc
+ {
+ RegisterSet registerSets[int(ShaderStyle::CountOf)];
+ };
+
+ struct RegisterList
+ {
+ const uint16_t* begin() const { return indices; }
+ const uint16_t* end() const { return indices + numIndices; }
+
+ int getSize() const { return int(numIndices); }
+ uint16_t operator[](int i) const { assert(i >= 0 && i < numIndices); return indices[i]; }
+
+ const uint16_t* indices;
+ int numIndices;
+ };
+
+ struct SamplerDesc
+ {
+ bool isCompareSampler;
+ };
+
+ struct Binding
+ {
+ BindingType bindingType; ///< Type of binding
+ int descIndex; ///< The description index associated with type. -1 if not used. For example if bindingType is Sampler, the descIndex is into m_samplerDescs.
+ Slang::RefPtr<Resource> resource; ///< Associated resource. nullptr if not used
+ RegisterDesc registerDesc; ///< Registers associated with binding
+ };
+
+ struct Desc
+ {
+ /// Given a RegisterSet, return as a RegisterList, that can be easily iterated over
+ RegisterList asRegisterList(const RegisterSet& set) const;
+ /// Given a RegisterDesc and a style returns a RegisterList, that can be easily iterated over
+ RegisterList asRegisterList(ShaderStyle style, const RegisterDesc& registerDesc) const;
+
+ /// Returns the first member of the set, or returns -1 if is empty
+ int getFirst(const RegisterSet& set) const;
+ /// Returns the first member of the set, or returns -1 if is empty
+ int getFirst(ShaderStyle style, const RegisterDesc& registerDesc) const;
+
+ /// Add a resource - assumed that the binding will match the Desc of the resource
+ void addResource(BindingType bindingType, Resource* resource, const RegisterDesc& registerDesc);
+ /// Add a sampler
+ void addSampler(const SamplerDesc& desc, const RegisterDesc& registerDesc);
+ /// Add a BufferResource
+ void addBufferResource(BufferResource* resource, const RegisterDesc& registerDesc) { addResource(BindingType::Buffer, resource, registerDesc); }
+ /// Add a texture
+ void addTextureResource(TextureResource* resource, const RegisterDesc& registerDesc) { addResource(BindingType::Texture, resource, registerDesc); }
+ /// Add combined texture a
+ void addCombinedTextureSampler(TextureResource* resource, const SamplerDesc& samplerDesc, const RegisterDesc& registerDesc);
+
+ /// Clear the contents
+ void clear();
+
+ /// Given an index, returns as a register set. If index is < 0, assumes means no indices, and just returns the empty set
+ RegisterSet addRegisterSet(int index);
+ /// Given a list of indices, returns the associated register set. Note does check for indices being unique. The order is maintained.
+ /// Only >= 0 indices are valid
+ RegisterSet addRegisterSet(const int* indices, int numIndices);
+
+ Slang::List<Binding> m_bindings;
+ Slang::List<SamplerDesc> m_samplerDescs;
+ Slang::List<uint16_t> m_indices; ///< Used to store lists of registers
+ int m_numRenderTargets = 1;
+ };
+
+ /// Get the Desc used to create this binding
+ SLANG_FORCE_INLINE const Desc& getDesc() const { return m_desc; }
+
+ protected:
+ BindingState(const Desc& desc):
+ m_desc(desc)
+ {
+ }
+
+ Desc m_desc;
+};
+
class Renderer: public Slang::RefObject
{
public:
@@ -334,10 +457,9 @@ public:
virtual BufferResource* createBufferResource(Resource::Usage initialUsage, const BufferResource::Desc& desc, const void* initData = nullptr) { return nullptr; }
virtual SlangResult captureScreenShot(const char* outputPath) = 0;
- virtual void serializeOutput(BindingState* state, const char* outputPath) = 0;
virtual InputLayout* createInputLayout(const InputElementDesc* inputElements, UInt inputElementCount) = 0;
- virtual BindingState* createBindingState(const ShaderInputLayout& shaderInput) = 0;
+ virtual BindingState* createBindingState(const BindingState::Desc& desc) { return nullptr; }
virtual ShaderCompiler* getShaderCompiler() = 0;
virtual void* map(BufferResource* buffer, MapFlavor flavor) = 0;