From 1f401d04e32c6feaeb35243ea5bfc2b14520344b Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 20 Feb 2020 18:24:00 -0500 Subject: WIP on RWTexture types on CUDA/CPU (#1234) * CUDA support for array of resources. * * Add support for Texture2DArray on CPU * Expand texture-simple.slang to test Texture2DArray * Reorganise CUDAComputeUtil to split out createTextureResource. * Add TextureCubeArray support for CPU/CUDA targets. * Pulled out CUDAResource Renamed derived classes to reflect that change. * Creation of SurfObject type. * Functions to return read/write access for simplifying future additions. * WIP for RWTexture access on CPU/CUDA. * CUsurfObject cannot have mips. * Ability to set number of mips on test data. Preliminary support for CUsurfObj and RWTexture1D on CUDA. CUDA docs improvements. * Fix typo. --- tools/render-test/cpu-compute-util.cpp | 66 +++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 12 deletions(-) (limited to 'tools/render-test/cpu-compute-util.cpp') diff --git a/tools/render-test/cpu-compute-util.cpp b/tools/render-test/cpu-compute-util.cpp index 608da9461..3826ccec1 100644 --- a/tools/render-test/cpu-compute-util.cpp +++ b/tools/render-test/cpu-compute-util.cpp @@ -247,19 +247,61 @@ struct ValueTextureCubeArray : public CPUComputeUtil::Resource, public CPPPrelud float m_value; }; -static CPUComputeUtil::Resource* _newValueTexture(SlangResourceShape shape, int elemCount, float value) + +template +struct ValueRWTexture1D : public CPUComputeUtil::Resource, public CPPPrelude::IRWTexture1D +{ + void set(void* out) + { + float* dst = (float*)out; + for (int i = 0; i < COUNT; ++i) + { + dst[i] = m_value; + } + } + + virtual void Load(int32_t loc, void* out) SLANG_OVERRIDE + { + set(out); + } + + ValueRWTexture1D(float value) : + m_value(value) + { + m_interface = static_cast(this); + } + + float m_value; +}; + + +static CPUComputeUtil::Resource* _newValueTexture(SlangResourceShape shape, SlangResourceAccess access, Index elemCount, float value) { switch (shape) { case SLANG_TEXTURE_1D: { - switch (elemCount) + if (access == SLANG_RESOURCE_ACCESS_READ_WRITE) { - case 1: return new ValueTexture1D<1>(value); - case 2: return new ValueTexture1D<2>(value); - case 3: return new ValueTexture1D<3>(value); - case 4: return new ValueTexture1D<4>(value); - default: break; + switch (elemCount) + { + case 1: return new ValueRWTexture1D<1>(value); + case 2: return new ValueRWTexture1D<2>(value); + case 3: return new ValueRWTexture1D<3>(value); + case 4: return new ValueRWTexture1D<4>(value); + default: break; + } + } + else + { + switch (elemCount) + { + case 1: return new ValueTexture1D<1>(value); + case 2: return new ValueTexture1D<2>(value); + case 3: return new ValueTexture1D<3>(value); + case 4: return new ValueTexture1D<4>(value); + default: break; + } } break; } @@ -388,7 +430,7 @@ static CPUComputeUtil::Resource* _newValueTexture(SlangResourceShape shape, int auto type = typeLayout->getType(); auto shape = type->getResourceShape(); - //auto access = type->getResourceAccess(); + auto access = type->getResourceAccess(); auto baseShape = shape & SLANG_RESOURCE_BASE_SHAPE_MASK; switch (baseShape) @@ -407,22 +449,22 @@ static CPUComputeUtil::Resource* _newValueTexture(SlangResourceShape shape, int slang::TypeReflection* typeReflection = typeLayout->getResourceResultType(); - int count = 1; + Index count = 1; if (typeReflection->getKind() == slang::TypeReflection::Kind::Vector) { - count = int(typeReflection->getElementCount()); + count = Index(typeReflection->getElementCount()); } switch (srcEntry.textureDesc.content) { case InputTextureContent::One: { - value->m_target = _newValueTexture(shape, count, 1.0f); + value->m_target = _newValueTexture(shape, access, count, 1.0f); break; } case InputTextureContent::Zero: { - value->m_target = _newValueTexture(shape, count, 0.0f); + value->m_target = _newValueTexture(shape, access, count, 0.0f); break; } default: break; -- cgit v1.2.3