summaryrefslogtreecommitdiffstats
path: root/prelude/slang-cpp-types.h
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-02-26 21:13:41 +0000
committerGitHub <noreply@github.com>2020-02-26 21:13:41 +0000
commit7bce066cfc51296a538c7a7d325133d60e352494 (patch)
treece54b40315274c3a7daaf5781de3d2504d72cba2 /prelude/slang-cpp-types.h
parent6308a1224672944220a1fee34ae22f70212703a0 (diff)
Support for RWTexture types on CPU and CUDA (#1243)
* Added FloatTextureData as a mechanism to enable CPU based Texture writes. * Add [] RWTexture access for CPU. * Fixed rw-texture-simple.slang.expected.txt * WIP: CUDA stdlib has support for [] surface access. * Made IRWTexture class able to take different locations. Doing a Texture2d access on CUDA works. * Fix bug in outputing UniformState - was missing out padding. Support RWTexture with array. Support RWTexture3D. * Use * for locations for read only textures, so only need a ITexture interface. * Fix problem around application of set/get for CUDA on subscript Texture types.
Diffstat (limited to 'prelude/slang-cpp-types.h')
-rw-r--r--prelude/slang-cpp-types.h140
1 files changed, 68 insertions, 72 deletions
diff --git a/prelude/slang-cpp-types.h b/prelude/slang-cpp-types.h
index 563b4b6e9..c7421bc0b 100644
--- a/prelude/slang-cpp-types.h
+++ b/prelude/slang-cpp-types.h
@@ -228,136 +228,132 @@ struct SamplerComparisonState
// Texture
-struct ITexture1D
+struct ITexture
{
- virtual void Load(const int2& v, void* out) = 0;
- virtual void Sample(SamplerState samplerState, float loc, void* out) = 0;
- virtual void SampleLevel(SamplerState samplerState, float loc, float level, void* out) = 0;
+ virtual void Load(const int* v, void* out) = 0;
+ virtual void Sample(SamplerState samplerState, const float* loc, void* out) = 0;
+ virtual void SampleLevel(SamplerState samplerState, const float* loc, float level, void* out) = 0;
};
template <typename T>
struct Texture1D
{
- T Load(const int2& v) const { T out; texture->Load(v, &out); return out; }
- T Sample(SamplerState samplerState, float v) const { T out; texture->Sample(samplerState, v, &out); return out; }
- T SampleLevel(SamplerState samplerState, float v, float level) { T out; texture->SampleLevel(samplerState, v, level, &out); return out; }
+ T Load(const int2& loc) const { T out; texture->Load(&loc.x, &out); return out; }
+ T Sample(SamplerState samplerState, float loc) const { T out; texture->Sample(samplerState, &loc, &out); return out; }
+ T SampleLevel(SamplerState samplerState, float loc, float level) { T out; texture->SampleLevel(samplerState, &loc, level, &out); return out; }
- ITexture1D* texture;
-};
-
-struct ITexture2D
-{
- virtual void Load(const int3& v, void* out) = 0;
- virtual void Sample(SamplerState samplerState, const float2& loc, void* out) = 0;
- virtual void SampleLevel(SamplerState samplerState, const float2& loc, float level, void* out) = 0;
+ ITexture* texture;
};
template <typename T>
struct Texture2D
{
- T Load(const int3& v) const { T out; texture->Load(v, &out); return out; }
- T Sample(SamplerState samplerState, const float2& v) const { T out; texture->Sample(samplerState, v, &out); return out; }
- T SampleLevel(SamplerState samplerState, const float2& v, float level) { T out; texture->SampleLevel(samplerState, v, level, &out); return out; }
+ T Load(const int3& loc) const { T out; texture->Load(&loc.x, &out); return out; }
+ T Sample(SamplerState samplerState, const float2& loc) const { T out; texture->Sample(samplerState, &loc.x, &out); return out; }
+ T SampleLevel(SamplerState samplerState, const float2& loc, float level) { T out; texture->SampleLevel(samplerState, &loc.x, level, &out); return out; }
- ITexture2D* texture;
-};
-
-struct ITexture3D
-{
- virtual void Load(const int4& v, void* out) = 0;
- virtual void Sample(SamplerState samplerState, const float3& loc, void* out) = 0;
- virtual void SampleLevel(SamplerState samplerState, const float3& loc, float level, void* out) = 0;
+ ITexture* texture;
};
template <typename T>
struct Texture3D
{
- T Load(const int4& v) const { T out; texture->Load(v, &out); return out; }
- T Sample(SamplerState samplerState, const float3& v) const { T out; texture->Sample(samplerState, v, &out); return out; }
- T SampleLevel(SamplerState samplerState, const float3& v, float level) { T out; texture->SampleLevel(samplerState, v, level, &out); return out; }
+ T Load(const int4& loc) const { T out; texture->Load(&loc.x, &out); return out; }
+ T Sample(SamplerState samplerState, const float3& loc) const { T out; texture->Sample(samplerState, &loc.x, &out); return out; }
+ T SampleLevel(SamplerState samplerState, const float3& loc, float level) { T out; texture->SampleLevel(samplerState, &loc.x, level, &out); return out; }
- ITexture3D* texture;
+ ITexture* texture;
};
-struct ITextureCube
+template <typename T>
+struct TextureCube
{
- virtual void Sample(SamplerState samplerState, const float3& loc, void* out) = 0;
- virtual void SampleLevel(SamplerState samplerState, const float3& loc, float level, void* out) = 0;
+ T Sample(SamplerState samplerState, const float3& loc) const { T out; texture->Sample(samplerState, &loc.x, &out); return out; }
+ T SampleLevel(SamplerState samplerState, const float3& loc, float level) { T out; texture->SampleLevel(samplerState, &loc.x, level, &out); return out; }
+
+ ITexture* texture;
};
template <typename T>
-struct TextureCube
+struct Texture1DArray
{
- T Sample(SamplerState samplerState, const float3& v) const { T out; texture->Sample(samplerState, v, &out); return out; }
- T SampleLevel(SamplerState samplerState, const float3& v, float level) { T out; texture->SampleLevel(samplerState, v, level, &out); return out; }
+ T Load(const int3& loc) const { T out; texture->Load(&loc.x, &out); return out; }
+ T Sample(SamplerState samplerState, const float2& loc) const { T out; texture->Sample(samplerState, &loc.x, &out); return out; }
+ T SampleLevel(SamplerState samplerState, const float2& loc, float level) { T out; texture->SampleLevel(samplerState, &loc.x, level, &out); return out; }
- ITextureCube* texture;
+ ITexture* texture;
};
-struct ITexture1DArray
+template <typename T>
+struct Texture2DArray
{
- virtual void Load(const int3& v, void* out) = 0;
- virtual void Sample(SamplerState samplerState, const float2& loc, void* out) = 0;
- virtual void SampleLevel(SamplerState samplerState, const float2& loc, float level, void* out) = 0;
+ T Load(const int4& loc) const { T out; texture->Load(&loc.x, &out); return out; }
+ T Sample(SamplerState samplerState, const float3& loc) const { T out; texture->Sample(samplerState, &loc.x, &out); return out; }
+ T SampleLevel(SamplerState samplerState, const float3& loc, float level) { T out; texture->SampleLevel(samplerState, &loc.x, level, &out); return out; }
+
+ ITexture* texture;
};
template <typename T>
-struct Texture1DArray
+struct TextureCubeArray
{
- T Load(const int3& v) const { T out; texture->Load(v, &out); return out; }
- T Sample(SamplerState samplerState, const float2& v) const { T out; texture->Sample(samplerState, v, &out); return out; }
- T SampleLevel(SamplerState samplerState, const float2& v, float level) { T out; texture->SampleLevel(samplerState, v, level, &out); return out; }
+ T Sample(SamplerState samplerState, const float4& loc) const { T out; texture->Sample(samplerState, &loc.x, &out); return out; }
+ T SampleLevel(SamplerState samplerState, const float4& loc, float level) { T out; texture->SampleLevel(samplerState, &loc.x, level, &out); return out; }
- ITexture1DArray* texture;
+ ITexture* texture;
};
-struct ITexture2DArray
+/* !!!!!!!!!!!!!!!!!!!!!!!!!!! RWTexture !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
+
+struct IRWTexture
{
- virtual void Load(const int4& v, void* out) = 0;
- virtual void Sample(SamplerState samplerState, const float3& loc, void* out) = 0;
- virtual void SampleLevel(SamplerState samplerState, const float3& loc, float level, void* out) = 0;
+ /// Load at specified location.
+ virtual void Load(const int32_t* loc, void* out) = 0;
+ /// Get the reference to the element at loc.
+ virtual void* refAt(const uint32_t* loc) = 0;
};
template <typename T>
-struct Texture2DArray
+struct RWTexture1D
{
- T Load(const int4& v) const { T out; texture->Load(v, &out); return out; }
- T Sample(SamplerState samplerState, const float3& v) const { T out; texture->Sample(samplerState, v, &out); return out; }
- T SampleLevel(SamplerState samplerState, const float3& v, float level) { T out; texture->SampleLevel(samplerState, v, level, &out); return out; }
-
- ITexture2DArray* texture;
+ T Load(int32_t loc) const { T out; texture->Load(&loc, &out); return out; }
+ T& operator[](uint32_t loc) { return *(T*)texture->refAt(&loc); }
+ IRWTexture* texture;
};
-struct ITextureCubeArray
+template <typename T>
+struct RWTexture2D
{
- virtual void Sample(SamplerState samplerState, const float4& loc, void* out) = 0;
- virtual void SampleLevel(SamplerState samplerState, const float4& loc, float level, void* out) = 0;
+ T Load(const int2& loc) const { T out; texture->Load(&loc.x, &out); return out; }
+ T& operator[](const uint2& loc) { return *(T*)texture->refAt(&loc.x); }
+ IRWTexture* texture;
};
template <typename T>
-struct TextureCubeArray
+struct RWTexture3D
{
- T Sample(SamplerState samplerState, const float4& v) const { T out; texture->Sample(samplerState, v, &out); return out; }
- T SampleLevel(SamplerState samplerState, const float4& v, float level) { T out; texture->SampleLevel(samplerState, v, level, &out); return out; }
-
- ITextureCubeArray* texture;
+ T Load(const int3& loc) const { T out; texture->Load(&loc.x, &out); return out; }
+ T& operator[](const uint3& loc) { return *(T*)texture->refAt(&loc.x); }
+ IRWTexture* texture;
};
-/* !!!!!!!!!!!!!!!!!!!!!!!!!!! RWTexture !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
-
-struct IRWTexture1D
+template <typename T>
+struct RWTexture1DArray
{
- virtual void Load(int32_t loc, void* out) = 0;
+ T Load(int2 loc) const { T out; texture->Load(&loc.x, &out); return out; }
+ T& operator[](uint2 loc) { return *(T*)texture->refAt(&loc.x); }
+ IRWTexture* texture;
};
template <typename T>
-struct RWTexture1D
+struct RWTexture2DArray
{
- T Load(int32_t loc) const { T out; texture->Load(loc, &out); return out; }
-
- IRWTexture1D* texture;
+ T Load(const int3& loc) const { T out; texture->Load(&loc.x, &out); return out; }
+ T& operator[](const uint3& loc) { return *(T*)texture->refAt(&loc.x); }
+ IRWTexture* texture;
};
+
/* Varying input for Compute */
/* Used when running a single thread */