summaryrefslogtreecommitdiffstats
path: root/tools/render-test
diff options
context:
space:
mode:
Diffstat (limited to 'tools/render-test')
-rw-r--r--tools/render-test/shader-input-layout.cpp26
-rw-r--r--tools/render-test/shader-input-layout.h10
-rw-r--r--tools/render-test/shader-renderer-util.cpp158
-rw-r--r--tools/render-test/shader-renderer-util.h6
4 files changed, 183 insertions, 17 deletions
diff --git a/tools/render-test/shader-input-layout.cpp b/tools/render-test/shader-input-layout.cpp
index ab9ed3c7b..bb213cdaa 100644
--- a/tools/render-test/shader-input-layout.cpp
+++ b/tools/render-test/shader-input-layout.cpp
@@ -171,6 +171,19 @@ struct ShaderInputLayoutParser
{
val->samplerDesc.isCompareSampler = true;
}
+ else if (word == "filteringMode")
+ {
+ parser.Read("=");
+ auto contentWord = parser.ReadWord();
+ if (contentWord == "point")
+ {
+ val->samplerDesc.filteringMode = TextureFilteringMode::Point;
+ }
+ else
+ {
+ val->samplerDesc.filteringMode = TextureFilteringMode::Linear;
+ }
+ }
else
{
return SLANG_FAIL;
@@ -643,14 +656,15 @@ struct ShaderInputLayoutParser
default:
throw ShaderInputLayoutFormatException(
- String("Unexpected '") + parser.NextToken().Content + String("' at line") +
+ String("Unexpected '") + parser.NextToken().Content + String("' at line ") +
String(parser.NextToken().Position.Line));
}
}
RefPtr<ShaderInputLayout::Val> parseVal(Misc::TokenReader& parser)
{
- auto word = parser.NextToken().Content;
+ auto nextToken = parser.NextToken();
+ auto word = nextToken.Content;
if (parser.AdvanceIf("begin_array"))
{
RefPtr<ShaderInputLayout::ArrayVal> val = new ShaderInputLayout::ArrayVal;
@@ -820,8 +834,8 @@ struct ShaderInputLayoutParser
else
{
throw ShaderInputLayoutFormatException(
- String("Unknown shader input type '") + word + String("' at line") +
- String(parser.NextToken().Position.Line));
+ String("Unknown shader input type '") + word + String("' at line: ") +
+ String(nextToken.Position.Line));
}
parser.ReadToken();
return nullptr;
@@ -997,8 +1011,10 @@ struct ShaderInputLayoutParser
parentVal = rootVal;
auto lines = Misc::Split(source, '\n');
+ int lineNum = 0;
for (auto& line : lines)
{
+ lineNum++;
if (line.startsWith("//TEST_INPUT:"))
{
auto lineContent = line.subString(13, line.getLength() - 13);
@@ -1010,7 +1026,7 @@ struct ShaderInputLayoutParser
catch (const Misc::TextFormatException&)
{
StringBuilder msg;
- msg << "Invalid input syntax at line " << parser.NextToken().Position.Line;
+ msg << "Invalid input syntax at line " << lineNum << ": " << line;
throw ShaderInputLayoutFormatException(msg);
}
}
diff --git a/tools/render-test/shader-input-layout.h b/tools/render-test/shader-input-layout.h
index e0a2be886..b5ee99566 100644
--- a/tools/render-test/shader-input-layout.h
+++ b/tools/render-test/shader-input-layout.h
@@ -82,6 +82,7 @@ struct InputBufferDesc
struct InputSamplerDesc
{
bool isCompareSampler = false;
+ TextureFilteringMode filteringMode = TextureFilteringMode::Linear;
};
struct TextureData
@@ -109,7 +110,8 @@ struct TextureData
}
void* addSlice(size_t elemCount)
{
- void* dst = ::malloc(m_formatSize * elemCount);
+ const size_t totalSize = m_formatSize * elemCount;
+ void* dst = ::malloc(totalSize);
m_slices.add(Slice::make(dst, elemCount));
return dst;
}
@@ -153,9 +155,9 @@ struct TextureData
uint8_t m_formatSize = 0;
Slang::List<Slice> m_slices;
- int m_textureSize;
- int m_mipLevels;
- int m_arraySize;
+ int m_textureSize = 0;
+ int m_mipLevels = 1;
+ int m_arraySize = 1;
};
class ShaderInputLayout
diff --git a/tools/render-test/shader-renderer-util.cpp b/tools/render-test/shader-renderer-util.cpp
index 5046a1b10..3ac62f37a 100644
--- a/tools/render-test/shader-renderer-util.cpp
+++ b/tools/render-test/shader-renderer-util.cpp
@@ -76,6 +76,7 @@ inline int calcNumMipLevels(TextureType type, Extent3D size)
const FormatInfo& formatInfo = getFormatInfo(format);
bool isArray = inputDesc.arrayLength > 1;
+ bool isMS = inputDesc.sampleCount > 1;
textureDesc.sampleCount = inputDesc.sampleCount;
textureDesc.format = format;
@@ -113,9 +114,13 @@ inline int calcNumMipLevels(TextureType type, Extent3D size)
case 2:
{
textureDesc.type =
- isArray ? (inputDesc.isCube ? TextureType::TextureCubeArray
- : TextureType::Texture2DArray)
- : (inputDesc.isCube ? TextureType::TextureCube : TextureType::Texture2D);
+ isArray
+ ? (inputDesc.isCube
+ ? TextureType::TextureCubeArray
+ : (isMS ? TextureType::Texture2DMSArray : TextureType::Texture2DArray))
+ : (inputDesc.isCube
+ ? TextureType::TextureCube
+ : (isMS ? TextureType::Texture2DMS : TextureType::Texture2D));
textureDesc.size.width = inputDesc.size;
textureDesc.size.height = inputDesc.size;
textureDesc.size.depth = 1;
@@ -137,9 +142,9 @@ inline int calcNumMipLevels(TextureType type, Extent3D size)
}
// Metal doesn't support mip maps for 1D textures.
- if (device->getDeviceType() == DeviceType::Metal &&
- (textureDesc.type == TextureType::Texture1D ||
- textureDesc.type == TextureType::Texture1DArray))
+ if ((isMS) || (device->getDeviceType() == DeviceType::Metal &&
+ (textureDesc.type == TextureType::Texture1D ||
+ textureDesc.type == TextureType::Texture1DArray)))
{
textureDesc.mipCount = 1;
}
@@ -167,7 +172,16 @@ inline int calcNumMipLevels(TextureType type, Extent3D size)
}
}
- textureOut = device->createTexture(textureDesc, initSubresources.getBuffer());
+ if (isMS)
+ {
+ textureDesc.usage |= TextureUsage::RenderTarget;
+ textureOut = device->createTexture(textureDesc);
+ clearTexture(textureOut.get(), inputDesc.content, device);
+ }
+ else
+ {
+ textureOut = device->createTexture(textureDesc, initSubresources.getBuffer());
+ }
return textureOut ? SLANG_OK : SLANG_FAIL;
}
@@ -177,7 +191,7 @@ inline int calcNumMipLevels(TextureType type, Extent3D size)
size_t bufferSize,
const void* initData,
IDevice* device,
- Slang::ComPtr<IBuffer>& bufferOut)
+ ComPtr<IBuffer>& bufferOut)
{
BufferDesc bufferDesc;
bufferDesc.size = bufferSize;
@@ -197,6 +211,131 @@ inline int calcNumMipLevels(TextureType type, Extent3D size)
return SLANG_OK;
}
+/* static */ Result ShaderRendererUtil::clearTexture(
+ ITexture* texture,
+ InputTextureContent content,
+ IDevice* device)
+{
+ SLANG_ASSERT(texture);
+ ComPtr<ICommandQueue> queue;
+ SLANG_RETURN_ON_FAIL(device->getQueue(QueueType::Graphics, queue.writeRef()));
+
+ ComPtr<ICommandEncoder> commandEncoder;
+ SLANG_RETURN_ON_FAIL(queue->createCommandEncoder(commandEncoder.writeRef()));
+
+ TextureDesc desc = texture->getDesc();
+ SubresourceRange range;
+ range.layer = 0;
+ range.layerCount = texture->getDesc().arrayLength;
+ range.mip = 0;
+ range.mipCount = texture->getDesc().mipCount;
+
+ FormatInfo formatInfo = getFormatInfo(desc.format);
+ switch (formatInfo.kind)
+ {
+ case FormatKind::Float:
+ {
+ float clearValue[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+ switch (content)
+ {
+ case InputTextureContent::Zero:
+ // clearValue is already all zeros
+ break;
+ case InputTextureContent::One:
+ clearValue[0] = clearValue[1] = clearValue[2] = clearValue[3] = 1.0f;
+ break;
+ case InputTextureContent::ChessBoard:
+ case InputTextureContent::Gradient:
+ // For chessboard or gradient, we can't use a single clear value
+ // Instead, we should use a compute shader or multiple draw calls
+ SLANG_ASSERT(!"ChessBoard or Gradient content type is not supported for "
+ "multisampled textures - requires compute shader implementation");
+ return SLANG_FAIL;
+ }
+ commandEncoder->clearTextureFloat(texture, range, clearValue);
+ break;
+ }
+ case FormatKind::Integer:
+ {
+ uint32_t clearValue[4] = {0U, 0U, 0U, 0U};
+ switch (content)
+ {
+ case InputTextureContent::Zero:
+ // clearValue is already all zeros
+ break;
+ case InputTextureContent::One:
+ clearValue[0] = clearValue[1] = clearValue[2] = clearValue[3] = 1U;
+ break;
+ case InputTextureContent::ChessBoard:
+ case InputTextureContent::Gradient:
+ // For chessboard or gradient, we can't use a single clear value
+ // Instead, we should use a compute shader or multiple draw calls
+ SLANG_ASSERT(!"ChessBoard or Gradient content type is not supported for "
+ "multisampled textures - requires compute shader implementation");
+ return SLANG_FAIL;
+ }
+ commandEncoder->clearTextureUint(texture, range, clearValue);
+ break;
+ }
+ case FormatKind::Normalized:
+ {
+ int32_t clearValue[4] = {0, 0, 0, 0};
+ switch (content)
+ {
+ case InputTextureContent::Zero:
+ // clearValue is already all zeros
+ break;
+ case InputTextureContent::One:
+ clearValue[0] = clearValue[1] = clearValue[2] = clearValue[3] = 1;
+ break;
+ case InputTextureContent::ChessBoard:
+ case InputTextureContent::Gradient:
+ // For chessboard or gradient, we can't use a single clear value
+ // Instead, we should use a compute shader or multiple draw calls
+ SLANG_ASSERT(!"ChessBoard or Gradient content type is not supported for "
+ "multisampled textures - requires compute shader implementation");
+ return SLANG_FAIL;
+ }
+ commandEncoder->clearTextureSint(texture, range, clearValue);
+ break;
+ }
+ case FormatKind::DepthStencil:
+ {
+ float depthValue = 0.f;
+ uint8_t stencilValue = 0U;
+ switch (content)
+ {
+ case InputTextureContent::Zero:
+ // clearValue is already all zeros
+ break;
+ case InputTextureContent::One:
+ depthValue = 1;
+ stencilValue = 1U;
+ break;
+ case InputTextureContent::ChessBoard:
+ case InputTextureContent::Gradient:
+ // For chessboard or gradient, we can't use a single clear value
+ // Instead, we should use a compute shader or multiple draw calls
+ SLANG_ASSERT(!"ChessBoard or Gradient content type is not supported for "
+ "multisampled textures - requires compute shader implementation");
+ return SLANG_FAIL;
+ }
+ commandEncoder
+ ->clearTextureDepthStencil(texture, range, true, depthValue, true, stencilValue);
+ break;
+ }
+ default:
+ {
+ SLANG_ASSERT(!"Unsupported FormatKind type");
+ return SLANG_FAIL;
+ }
+ }
+
+ SLANG_RETURN_ON_FAIL(queue->submit(commandEncoder->finish()));
+
+ return SLANG_OK;
+}
+
static SamplerDesc _calcSamplerDesc(const InputSamplerDesc& srcDesc)
{
SamplerDesc samplerDesc;
@@ -205,6 +344,9 @@ static SamplerDesc _calcSamplerDesc(const InputSamplerDesc& srcDesc)
samplerDesc.reductionOp = TextureReductionOp::Comparison;
samplerDesc.comparisonFunc = ComparisonFunc::Less;
}
+ samplerDesc.minFilter = srcDesc.filteringMode;
+ samplerDesc.magFilter = srcDesc.filteringMode;
+ samplerDesc.mipFilter = srcDesc.filteringMode;
return samplerDesc;
}
diff --git a/tools/render-test/shader-renderer-util.h b/tools/render-test/shader-renderer-util.h
index bf0569988..257b41039 100644
--- a/tools/render-test/shader-renderer-util.h
+++ b/tools/render-test/shader-renderer-util.h
@@ -39,6 +39,12 @@ struct ShaderRendererUtil
const void* initData,
IDevice* device,
ComPtr<IBuffer>& bufferOut);
+
+ /// Clear a texture with the specified content
+ static Slang::Result clearTexture(
+ ITexture* texture,
+ InputTextureContent content,
+ IDevice* device);
};
} // namespace renderer_test