Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e1499d1a1 | ||
|
|
586c82ef10 | ||
|
|
7ece76a679 | ||
|
|
9959b104f9 | ||
|
|
f024214621 |
@@ -972,24 +972,22 @@ void WebGPUDriver::updateDescriptorSetBuffer(Handle<HwDescriptorSet> dsh,
|
|||||||
|
|
||||||
void WebGPUDriver::updateDescriptorSetTexture(Handle<HwDescriptorSet> dsh,
|
void WebGPUDriver::updateDescriptorSetTexture(Handle<HwDescriptorSet> dsh,
|
||||||
backend::descriptor_binding_t binding, Handle<HwTexture> th, SamplerParams params) {
|
backend::descriptor_binding_t binding, Handle<HwTexture> th, SamplerParams params) {
|
||||||
/*
|
|
||||||
auto bindGroup = handleCast<WebGPUDescriptorSet>(dsh);
|
auto bindGroup = handleCast<WebGPUDescriptorSet>(dsh);
|
||||||
auto texture = handleCast<WGPUTexture>(th);
|
auto texture = handleCast<WGPUTexture>(th);
|
||||||
|
|
||||||
// TODO very high odds badd assumptions are in here about handling HwTexture. Revisit with more
|
|
||||||
// understanding. Right now assuming there is a wgpu::TextureView filled in
|
|
||||||
if (!bindGroup->getIsLocked()) {
|
if (!bindGroup->getIsLocked()) {
|
||||||
|
// Dawn will cache duplicate samplers, so we don't strictly need to maintain a cache.
|
||||||
|
// Making a cache might save us minor perf by reducing param translation
|
||||||
|
auto sampler = makeSampler(params);
|
||||||
// TODO making assumptions that size and offset mean the same thing here.
|
// TODO making assumptions that size and offset mean the same thing here.
|
||||||
wgpu::BindGroupEntry tEntry{ .binding = static_cast<uint32_t>(binding * 2),
|
wgpu::BindGroupEntry tEntry{ .binding = static_cast<uint32_t>(binding * 2),
|
||||||
.textureView = texture->texView };
|
.textureView = texture->getTexView() };
|
||||||
bindGroup->addEntry(tEntry.binding, std::move(tEntry));
|
bindGroup->addEntry(tEntry.binding, std::move(tEntry));
|
||||||
|
|
||||||
wgpu::BindGroupEntry sEntry{ .binding = static_cast<uint32_t>(binding * 2 + 1),
|
wgpu::BindGroupEntry sEntry{ .binding = static_cast<uint32_t>(binding * 2 + 1),
|
||||||
.sampler = texture->sampler };
|
.sampler = sampler };
|
||||||
bindGroup->addEntry(sEntry.binding, std::move(sEntry));
|
bindGroup->addEntry(sEntry.binding, std::move(sEntry));
|
||||||
}
|
}
|
||||||
//TODO Just the setup, this function stilll needs the rest of logic implemented
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGPUDriver::bindDescriptorSet(Handle<HwDescriptorSet> dsh, backend::descriptor_set_t set,
|
void WebGPUDriver::bindDescriptorSet(Handle<HwDescriptorSet> dsh, backend::descriptor_set_t set,
|
||||||
@@ -1001,5 +999,121 @@ void WebGPUDriver::bindDescriptorSet(Handle<HwDescriptorSet> dsh, backend::descr
|
|||||||
|
|
||||||
void WebGPUDriver::setDebugTag(HandleBase::HandleId handleId, utils::CString tag) {
|
void WebGPUDriver::setDebugTag(HandleBase::HandleId handleId, utils::CString tag) {
|
||||||
}
|
}
|
||||||
|
wgpu::Sampler WebGPUDriver::makeSampler(SamplerParams const& params) {
|
||||||
|
wgpu::SamplerDescriptor desc;
|
||||||
|
|
||||||
|
desc.label = "TODO";
|
||||||
|
desc.addressModeU = fWrapModeToWAddressMode(params.wrapS);
|
||||||
|
desc.addressModeV = fWrapModeToWAddressMode(params.wrapR);
|
||||||
|
desc.addressModeW = fWrapModeToWAddressMode(params.wrapT);
|
||||||
|
switch (params.filterMag) {
|
||||||
|
case SamplerMagFilter::NEAREST: {
|
||||||
|
desc.magFilter = wgpu::FilterMode::Nearest;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SamplerMagFilter::LINEAR: {
|
||||||
|
desc.magFilter = wgpu::FilterMode::Linear;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch (params.filterMin) {
|
||||||
|
case SamplerMinFilter::NEAREST: {
|
||||||
|
desc.minFilter = wgpu::FilterMode::Nearest;
|
||||||
|
// Metal Driver uses an explicit not-mipmapped value webgpu lacks. Nearest should
|
||||||
|
// suffice
|
||||||
|
desc.mipmapFilter = wgpu::MipmapFilterMode::Nearest;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SamplerMinFilter::LINEAR: {
|
||||||
|
desc.minFilter = wgpu::FilterMode::Linear;
|
||||||
|
// Metal Driver uses an explicit not-mipmapped value webgpu lacks. Nearest should
|
||||||
|
// suffice
|
||||||
|
|
||||||
|
desc.mipmapFilter = wgpu::MipmapFilterMode::Nearest;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SamplerMinFilter::NEAREST_MIPMAP_NEAREST: {
|
||||||
|
desc.minFilter = wgpu::FilterMode::Nearest;
|
||||||
|
desc.mipmapFilter = wgpu::MipmapFilterMode::Nearest;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SamplerMinFilter::LINEAR_MIPMAP_NEAREST: {
|
||||||
|
desc.minFilter = wgpu::FilterMode::Linear;
|
||||||
|
desc.mipmapFilter = wgpu::MipmapFilterMode::Nearest;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SamplerMinFilter::NEAREST_MIPMAP_LINEAR: {
|
||||||
|
desc.minFilter = wgpu::FilterMode::Nearest;
|
||||||
|
desc.mipmapFilter = wgpu::MipmapFilterMode::Linear;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SamplerMinFilter::LINEAR_MIPMAP_LINEAR: {
|
||||||
|
desc.minFilter = wgpu::FilterMode::Linear;
|
||||||
|
desc.mipmapFilter = wgpu::MipmapFilterMode::Linear;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch (params.compareFunc) {
|
||||||
|
case SamplerCompareFunc::LE: {
|
||||||
|
desc.compare = wgpu::CompareFunction::LessEqual;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SamplerCompareFunc::GE: {
|
||||||
|
desc.compare = wgpu::CompareFunction::GreaterEqual;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SamplerCompareFunc::L: {
|
||||||
|
desc.compare = wgpu::CompareFunction::Less;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SamplerCompareFunc::G: {
|
||||||
|
desc.compare = wgpu::CompareFunction::Greater;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SamplerCompareFunc::E: {
|
||||||
|
desc.compare = wgpu::CompareFunction::Equal;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SamplerCompareFunc::NE: {
|
||||||
|
desc.compare = wgpu::CompareFunction::NotEqual;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SamplerCompareFunc::A: {
|
||||||
|
desc.compare = wgpu::CompareFunction::Always;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SamplerCompareFunc::N: {
|
||||||
|
desc.compare = wgpu::CompareFunction::Never;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
desc.maxAnisotropy = 1u << params.anisotropyLog2;
|
||||||
|
|
||||||
|
|
||||||
|
// Unused: Filament's compareMode, WGPU lodMinClamp/lodMaxClamp
|
||||||
|
|
||||||
|
return mDevice.CreateSampler();
|
||||||
|
}
|
||||||
|
wgpu::AddressMode WebGPUDriver::fWrapModeToWAddressMode(const SamplerWrapMode& fWrapMode) {
|
||||||
|
switch (fWrapMode) {
|
||||||
|
case SamplerWrapMode::CLAMP_TO_EDGE: {
|
||||||
|
return wgpu::AddressMode::ClampToEdge;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SamplerWrapMode::REPEAT: {
|
||||||
|
return wgpu::AddressMode::Repeat;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SamplerWrapMode::MIRRORED_REPEAT: {
|
||||||
|
return wgpu::AddressMode::MirrorRepeat;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return wgpu::AddressMode::Undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace filament
|
} // namespace filament
|
||||||
|
|||||||
@@ -56,7 +56,8 @@ private:
|
|||||||
explicit WebGPUDriver(WebGPUPlatform& platform, const Platform::DriverConfig& driverConfig) noexcept;
|
explicit WebGPUDriver(WebGPUPlatform& platform, const Platform::DriverConfig& driverConfig) noexcept;
|
||||||
[[nodiscard]] ShaderModel getShaderModel() const noexcept final;
|
[[nodiscard]] ShaderModel getShaderModel() const noexcept final;
|
||||||
[[nodiscard]] ShaderLanguage getShaderLanguage() const noexcept final;
|
[[nodiscard]] ShaderLanguage getShaderLanguage() const noexcept final;
|
||||||
|
[[nodiscard]] wgpu::Sampler makeSampler(SamplerParams const& params);
|
||||||
|
[[nodiscard]] static wgpu::AddressMode fWrapModeToWAddressMode(const filament::backend::SamplerWrapMode& fUsage);
|
||||||
template<typename GPUBufferObject>
|
template<typename GPUBufferObject>
|
||||||
void updateGPUBuffer(GPUBufferObject* gpuBufferObject, BufferDescriptor&& bufferDescriptor,
|
void updateGPUBuffer(GPUBufferObject* gpuBufferObject, BufferDescriptor&& bufferDescriptor,
|
||||||
uint32_t byteOffset) {
|
uint32_t byteOffset) {
|
||||||
|
|||||||
@@ -267,10 +267,14 @@ WebGPUDescriptorSetLayout::~WebGPUDescriptorSetLayout() {}
|
|||||||
|
|
||||||
WebGPUDescriptorSet::WebGPUDescriptorSet(const wgpu::BindGroupLayout& layout, uint layoutSize)
|
WebGPUDescriptorSet::WebGPUDescriptorSet(const wgpu::BindGroupLayout& layout, uint layoutSize)
|
||||||
: mLayout(layout),
|
: mLayout(layout),
|
||||||
entries(layoutSize, wgpu::BindGroupEntry{}) {
|
entries(layoutSize, wgpu::BindGroupEntry{.buffer = nullptr, .sampler = nullptr, .textureView = nullptr}) {
|
||||||
// Establish the size of entries based on the layout. This should be reliable and efficient.
|
// Establish the size of entries based on the layout. This should be reliable and efficient.
|
||||||
}
|
}
|
||||||
WebGPUDescriptorSet::~WebGPUDescriptorSet() {}
|
WebGPUDescriptorSet::~WebGPUDescriptorSet() {
|
||||||
|
mBindGroup = nullptr;
|
||||||
|
mLayout = nullptr;
|
||||||
|
entries.clear();
|
||||||
|
}
|
||||||
|
|
||||||
wgpu::BindGroup WebGPUDescriptorSet::lockAndReturn(const wgpu::Device& device) {
|
wgpu::BindGroup WebGPUDescriptorSet::lockAndReturn(const wgpu::Device& device) {
|
||||||
if (mBindGroup) {
|
if (mBindGroup) {
|
||||||
@@ -292,7 +296,7 @@ void WebGPUDescriptorSet::addEntry(uint index, wgpu::BindGroupEntry&& entry) {
|
|||||||
}
|
}
|
||||||
// TODO: Putting some level of trust that Filament is not going to reuse indexes or go past the
|
// TODO: Putting some level of trust that Filament is not going to reuse indexes or go past the
|
||||||
// layout index for efficiency. Add guards if wrong.
|
// layout index for efficiency. Add guards if wrong.
|
||||||
entries[index] = std::move(entry);
|
entries.emplace_back(std::move(entry));
|
||||||
}
|
}
|
||||||
// From createTextureR
|
// From createTextureR
|
||||||
WGPUTexture::WGPUTexture(SamplerType target, uint8_t levels, TextureFormat format, uint8_t samples,
|
WGPUTexture::WGPUTexture(SamplerType target, uint8_t levels, TextureFormat format, uint8_t samples,
|
||||||
|
|||||||
@@ -141,9 +141,9 @@ public:
|
|||||||
WGPUTexture(WGPUTexture* src, uint8_t baseLevel, uint8_t levelCount) noexcept;
|
WGPUTexture(WGPUTexture* src, uint8_t baseLevel, uint8_t levelCount) noexcept;
|
||||||
|
|
||||||
const wgpu::Texture& getTexture() const { return texture; }
|
const wgpu::Texture& getTexture() const { return texture; }
|
||||||
const wgpu::Sampler& getSampler() const { return sampler; }
|
|
||||||
const wgpu::TextureView& getTexView() const { return texView; }
|
const wgpu::TextureView& getTexView() const { return texView; }
|
||||||
|
|
||||||
|
// Public to allow checking for support of a texture format
|
||||||
static wgpu::TextureFormat fToWGPUTextureFormat(const filament::backend::TextureFormat& fUsage);
|
static wgpu::TextureFormat fToWGPUTextureFormat(const filament::backend::TextureFormat& fUsage);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -152,10 +152,6 @@ private:
|
|||||||
// along with a sampler Current plan: Inherit the sampler and Texture to always exist (It is a
|
// along with a sampler Current plan: Inherit the sampler and Texture to always exist (It is a
|
||||||
// ref counted pointer) when making views. View is optional
|
// ref counted pointer) when making views. View is optional
|
||||||
wgpu::Texture texture = nullptr;
|
wgpu::Texture texture = nullptr;
|
||||||
// TODO: Adding this but not yet setting it up. Filament "Textures" are combined image samplers,
|
|
||||||
// rep both.
|
|
||||||
wgpu::Sampler sampler = nullptr;
|
|
||||||
// TODO: Not sure all the ways HwTexture is used. Overloading like this might be entirely wrong.
|
|
||||||
wgpu::TextureView texView = nullptr;
|
wgpu::TextureView texView = nullptr;
|
||||||
wgpu::TextureUsage fToWGPUTextureUsage(const filament::backend::TextureUsage& fUsage);
|
wgpu::TextureUsage fToWGPUTextureUsage(const filament::backend::TextureUsage& fUsage);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -99,10 +99,9 @@ wgpu::Adapter WebGPUPlatform::requestAdapter(wgpu::Surface const& surface) {
|
|||||||
|
|
||||||
wgpu::Device WebGPUPlatform::requestDevice(wgpu::Adapter const& adapter) {
|
wgpu::Device WebGPUPlatform::requestDevice(wgpu::Adapter const& adapter) {
|
||||||
// TODO consider passing limits
|
// TODO consider passing limits
|
||||||
constexpr std::array desiredFeatures = {
|
constexpr std::array desiredFeatures = { wgpu::FeatureName::DepthClipControl,
|
||||||
wgpu::FeatureName::DepthClipControl,
|
wgpu::FeatureName::Depth32FloatStencil8, wgpu::FeatureName::CoreFeaturesAndLimits,
|
||||||
wgpu::FeatureName::Depth32FloatStencil8,
|
wgpu::FeatureName::TransientAttachments };
|
||||||
wgpu::FeatureName::CoreFeaturesAndLimits };
|
|
||||||
std::vector<wgpu::FeatureName> requiredFeatures;
|
std::vector<wgpu::FeatureName> requiredFeatures;
|
||||||
requiredFeatures.reserve(desiredFeatures.size());
|
requiredFeatures.reserve(desiredFeatures.size());
|
||||||
wgpu::SupportedFeatures supportedFeatures;
|
wgpu::SupportedFeatures supportedFeatures;
|
||||||
|
|||||||
Reference in New Issue
Block a user