diff --git a/CHANGELOG b/CHANGELOG index b9b89e58..89fb47a8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +- remove SampleDesc and instead add sampleCount and sampleQuality to TextureDesc - rename ISamplerState -> ISampler - rename ISamplerState::Desc -> SamlerDesc - rename BufferDesc::sizeInBytes -> size diff --git a/include/slang-rhi.h b/include/slang-rhi.h index d3b99293..7625b7ce 100644 --- a/include/slang-rhi.h +++ b/include/slang-rhi.h @@ -717,14 +717,6 @@ struct Offset3D } }; -struct SampleDesc -{ - /// Number of samples per pixel. - GfxCount numSamples = 1; - /// The quality measure for the samples. - int quality = 0; -}; - struct Extents { /// Width in pixels. @@ -750,8 +742,11 @@ struct TextureDesc GfxCount numMipLevels = 0; /// The resources format. Format format; - /// How the resource is sampled. - SampleDesc sampleDesc; + /// Number of samples per pixel. + GfxCount sampleCount = 1; + /// The quality measure for the samples. + int sampleQuality = 0; + ClearValue* optimalClearValue = nullptr; }; diff --git a/src/cpu/cpu-resource-views.cpp b/src/cpu/cpu-resource-views.cpp index a158c60c..c315ac30 100644 --- a/src/cpu/cpu-resource-views.cpp +++ b/src/cpu/cpu-resource-views.cpp @@ -133,7 +133,7 @@ void* TextureViewImpl::_getTexelPtr(int32_t const* texelCoords) int32_t baseCoordCount = baseShape->baseCoordCount; bool isArray = (desc.arraySize != 0) || (desc.type == rhi::TextureType::TextureCube); - bool isMultisample = desc.sampleDesc.numSamples > 1; + bool isMultisample = desc.sampleCount > 1; bool hasMipLevels = !isMultisample; int32_t effectiveArrayElementCount = texture->m_effectiveArrayElementCount; diff --git a/src/d3d11/d3d11-device.cpp b/src/d3d11/d3d11-device.cpp index ab3d3487..6f854502 100644 --- a/src/d3d11/d3d11-device.cpp +++ b/src/d3d11/d3d11-device.cpp @@ -434,7 +434,7 @@ Result DeviceImpl::readTexture( auto texture = static_cast(resource); // Don't bother supporting MSAA for right now - if (texture->getDesc()->sampleDesc.numSamples > 1) + if (texture->getDesc()->sampleCount > 1) { fprintf(stderr, "ERROR: cannot capture multi-sample texture\n"); return E_INVALIDARG; @@ -582,8 +582,8 @@ Result DeviceImpl::createTexture(const TextureDesc& descIn, const SubresourceDat desc.Width = srcDesc.size.width; desc.Height = srcDesc.size.height; desc.Usage = D3D11_USAGE_DEFAULT; - desc.SampleDesc.Count = srcDesc.sampleDesc.numSamples; - desc.SampleDesc.Quality = srcDesc.sampleDesc.quality; + desc.SampleDesc.Count = srcDesc.sampleCount; + desc.SampleDesc.Quality = srcDesc.sampleQuality; if (srcDesc.type == TextureType::TextureCube) { diff --git a/src/d3d12/d3d12-device.cpp b/src/d3d12/d3d12-device.cpp index abfc1894..ef765823 100644 --- a/src/d3d12/d3d12-device.cpp +++ b/src/d3d12/d3d12-device.cpp @@ -1342,7 +1342,7 @@ Result DeviceImpl::createTextureView(ITexture* texture, IResourceView::Desc cons viewImpl->m_resource = resourceImpl; viewImpl->m_desc = desc; bool isArray = resourceImpl ? resourceImpl->getDesc()->arraySize > 1 : false; - bool isMultiSample = resourceImpl ? resourceImpl->getDesc()->sampleDesc.numSamples > 1 : false; + bool isMultiSample = resourceImpl ? resourceImpl->getDesc()->sampleCount > 1 : false; switch (desc.type) { default: diff --git a/src/d3d12/d3d12-helper-functions.cpp b/src/d3d12/d3d12-helper-functions.cpp index 95de4fd3..6747bb89 100644 --- a/src/d3d12/d3d12-helper-functions.cpp +++ b/src/d3d12/d3d12-helper-functions.cpp @@ -231,7 +231,7 @@ void initSrvDesc( break; case D3D12_RESOURCE_DIMENSION_TEXTURE2D: descOut.ViewDimension = - textureDesc.sampleDesc.numSamples > 1 ? D3D12_SRV_DIMENSION_TEXTURE2DMS : D3D12_SRV_DIMENSION_TEXTURE2D; + textureDesc.sampleCount > 1 ? D3D12_SRV_DIMENSION_TEXTURE2DMS : D3D12_SRV_DIMENSION_TEXTURE2D; descOut.Texture2D.PlaneSlice = D3DUtil::getPlaneSlice(descOut.Format, subresourceRange.aspectMask); descOut.Texture2D.ResourceMinLODClamp = 0.0f; descOut.Texture2D.MipLevels = subresourceRange.mipLevelCount == 0 @@ -297,8 +297,8 @@ void initSrvDesc( : subresourceRange.mipLevelCount; break; case D3D12_RESOURCE_DIMENSION_TEXTURE2D: - descOut.ViewDimension = textureDesc.sampleDesc.numSamples > 1 ? D3D12_SRV_DIMENSION_TEXTURE2DMSARRAY - : D3D12_SRV_DIMENSION_TEXTURE2DARRAY; + descOut.ViewDimension = + textureDesc.sampleCount > 1 ? D3D12_SRV_DIMENSION_TEXTURE2DMSARRAY : D3D12_SRV_DIMENSION_TEXTURE2DARRAY; if (descOut.ViewDimension == D3D12_SRV_DIMENSION_TEXTURE2DARRAY) { descOut.Texture2DArray.ArraySize = @@ -357,8 +357,8 @@ Result initTextureDesc(D3D12_RESOURCE_DESC& resourceDesc, const TextureDesc& src resourceDesc.DepthOrArraySize = (srcDesc.size.depth > 1) ? srcDesc.size.depth : arraySize; resourceDesc.MipLevels = numMipMaps; - resourceDesc.SampleDesc.Count = srcDesc.sampleDesc.numSamples; - resourceDesc.SampleDesc.Quality = srcDesc.sampleDesc.quality; + resourceDesc.SampleDesc.Count = srcDesc.sampleCount; + resourceDesc.SampleDesc.Quality = srcDesc.sampleQuality; resourceDesc.Flags = D3D12_RESOURCE_FLAG_NONE; resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; diff --git a/src/metal/metal-device.cpp b/src/metal/metal-device.cpp index bbd96f46..5030d1e9 100644 --- a/src/metal/metal-device.cpp +++ b/src/metal/metal-device.cpp @@ -188,7 +188,7 @@ Result DeviceImpl::readTexture( TextureImpl* textureImpl = static_cast(texture); - if (textureImpl->getDesc()->sampleDesc.numSamples > 1) + if (textureImpl->getDesc()->sampleCount > 1) { return SLANG_E_NOT_IMPLEMENTED; } @@ -374,10 +374,10 @@ Result DeviceImpl::createTexture(const TextureDesc& descIn, const SubresourceDat textureDesc->setWidth(desc.size.width); break; case TextureType::Texture2D: - if (desc.sampleDesc.numSamples > 1) + if (desc.sampleCount > 1) { textureDesc->setTextureType(isArray ? MTL::TextureType2DMultisampleArray : MTL::TextureType2DMultisample); - textureDesc->setSampleCount(desc.sampleDesc.numSamples); + textureDesc->setSampleCount(desc.sampleCount); } else { @@ -432,7 +432,7 @@ Result DeviceImpl::createTexture(const TextureDesc& descIn, const SubresourceDat textureDesc->setArrayLength(isArray ? desc.arraySize : 1); textureDesc->setPixelFormat(pixelFormat); textureDesc->setUsage(textureUsage); - textureDesc->setSampleCount(desc.sampleDesc.numSamples); + textureDesc->setSampleCount(desc.sampleCount); textureDesc->setAllowGPUOptimizedContents(desc.memoryType == MemoryType::DeviceLocal); textureImpl->m_texture = NS::TransferPtr(m_device->newTexture(textureDesc.get())); diff --git a/src/metal/metal-framebuffer.cpp b/src/metal/metal-framebuffer.cpp index 355d2883..b46492d3 100644 --- a/src/metal/metal-framebuffer.cpp +++ b/src/metal/metal-framebuffer.cpp @@ -44,7 +44,7 @@ Result FramebufferImpl::init(DeviceImpl* device, const IFramebuffer::Desc& desc) const IResourceView::Desc* viewDesc = view->getViewDesc(); m_width = std::max(1u, uint32_t(textureDesc->size.width >> viewDesc->subresourceRange.mipLevel)); m_height = std::max(1u, uint32_t(textureDesc->size.height >> viewDesc->subresourceRange.mipLevel)); - m_sampleCount = std::max(m_sampleCount, uint32_t(textureDesc->sampleDesc.numSamples)); + m_sampleCount = std::max(m_sampleCount, uint32_t(textureDesc->sampleCount)); return SLANG_OK; }; diff --git a/src/vulkan/vk-device.cpp b/src/vulkan/vk-device.cpp index a1b87db3..3d392305 100644 --- a/src/vulkan/vk-device.cpp +++ b/src/vulkan/vk-device.cpp @@ -1449,7 +1449,7 @@ Result DeviceImpl::getTextureAllocationInfo(const TextureDesc& descIn, Size* out imageInfo.usage = _calcImageUsageFlags(desc.allowedStates, desc.memoryType, nullptr); imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - imageInfo.samples = (VkSampleCountFlagBits)desc.sampleDesc.numSamples; + imageInfo.samples = (VkSampleCountFlagBits)desc.sampleCount; VkImage image; SLANG_VK_RETURN_ON_FAIL(m_api.vkCreateImage(m_device, &imageInfo, nullptr, &image)); @@ -1535,7 +1535,7 @@ Result DeviceImpl::createTexture(const TextureDesc& descIn, const SubresourceDat imageInfo.usage = _calcImageUsageFlags(desc.allowedStates, desc.memoryType, initData); imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - imageInfo.samples = (VkSampleCountFlagBits)desc.sampleDesc.numSamples; + imageInfo.samples = (VkSampleCountFlagBits)desc.sampleCount; VkExternalMemoryImageCreateInfo externalMemoryImageCreateInfo = {VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO }; @@ -1689,7 +1689,7 @@ Result DeviceImpl::createTexture(const TextureDesc& descIn, const SubresourceDat VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL ); - if (desc.sampleDesc.numSamples != 1) + if (desc.sampleCount > 1) { // Handle senario where texture is sampled. We cannot use // a simple buffer copy for sampled textures. ClearColorImage diff --git a/tests/test-resolve-resource-tests.cpp b/tests/test-resolve-resource-tests.cpp index 2348abad..fd37c7cb 100644 --- a/tests/test-resolve-resource-tests.cpp +++ b/tests/test-resolve-resource-tests.cpp @@ -95,7 +95,7 @@ struct BaseResolveResourceTest msaaTexDesc.defaultState = ResourceState::RenderTarget; msaaTexDesc.allowedStates = ResourceStateSet(ResourceState::RenderTarget, ResourceState::ResolveSource); msaaTexDesc.format = format; - msaaTexDesc.sampleDesc.numSamples = 4; + msaaTexDesc.sampleCount = 4; REQUIRE_CALL(device->createTexture(msaaTexDesc, msaaTextureInfo.initData, msaaTexture.writeRef())); diff --git a/tests/test-texture-types.cpp b/tests/test-texture-types.cpp index 6b1b389b..d1eae4b8 100644 --- a/tests/test-texture-types.cpp +++ b/tests/test-texture-types.cpp @@ -375,7 +375,7 @@ struct RenderTargetTests : BaseTextureViewTest sampledTexDesc.allowedStates = ResourceStateSet(sampledTexDesc.defaultState, ResourceState::ResolveSource, ResourceState::CopySource); sampledTexDesc.format = textureInfo->format; - sampledTexDesc.sampleDesc.numSamples = sampleCount; + sampledTexDesc.sampleCount = sampleCount; REQUIRE_CALL( device->createTexture(sampledTexDesc, textureInfo->subresourceDatas.data(), sampledTexture.writeRef())