Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 29 Mar 2007
Offline Last Active Yesterday, 11:40 PM

#5300056 Blur computer shader, can't figured out warning

Posted by on 10 July 2016 - 06:38 PM

I don't see you setting the PS shader resources anywhere. You basically need to do this:


ID3D11ShaderResourceView* nullSRVs[1] = { nullptr };
context->PSSetShaderResourceViews(0, 1, nullSRVs);

#5299925 Blur computer shader, can't figured out warning

Posted by on 09 July 2016 - 07:26 PM

That means that you have a resource that's bound as an SRV (input) for the pixel shader stage, and you're trying to bind it as a UAV (output) for the compute shader stage. The debug layer always complains about these situations because you're not allowed to have the same resource simultaneously bound as an input and an output. You'll just need to clear out the PS SRV's before you bind your CS UAV's, which you do by binding NULL pointers to the slots.

#5299845 Is it possible “Update” texture in one pass?

Posted by on 08 July 2016 - 10:44 PM

You can't create a UAV for a multisampled texture, so you can't write to one directly from a shader. Even if you could, you can't read from an fp16 UAV texture unless the GPU supports extended formats for UAV reads, and you're running on D3D11.3 or D3D12. 

#5299803 Techniques used for precomputing lightmaps

Posted by on 08 July 2016 - 01:34 PM

I find that path tracers are easy to understand, and can be relatively simple to implement. You can check out Physically Based Rendering if you're looking for a good book on the subject, or you can check out pbrt or Mitsuba if you'd like look at the code for a working implementation. Aside from being straightforward, path tracers have a few nice properties:


  • If they're unbiased, then adding more samples will always converge towards the correct result. So adding more rays means better quality. This is not the case for photon mapping, which is a biased rendering method.
  • You can pretty much handle any shading model, and by using importance sampling techniques you can improve convergence as well
  • Depending on how you integrate, it's possible to write a progressive renderer. This means that you can show low-quality results right away, and continuously update those results as more rays come in.

Probably the biggest downside of path tracing is that a simple implementation can be rather noisy compared to some other techniques, especially for certain scenes where the light transport is particularly complicated. At the very least you'll typically need some form of importance sampling, and more complex scenes may require bidirectional path tracing in order to converge more quickly.

#5299437 ddx, ddy reuse for better performance?

Posted by on 06 July 2016 - 11:44 PM

Historically, tex2Dgrad is slower than a normal tex2D even if they have equivalent results. Explicitly specifying gradients potentially requires that the shader core send quite a bit more per-thread data (6 floats vs 2 floats for the 2D case), and on some older GPU's this caused a performance penalty. I'm not sure if it's still slower on newer GPU's, but personally I would still avoid it in order to avoid unneeded register pressure.

#5299435 [Solved][D3D12] Triangle not rendering, vertex data not given to GPU

Posted by on 06 July 2016 - 11:30 PM

The first thing you should do is enable the debug layer before creating your device. The debug layer will output helpful messages when you use the API incorrectly. You can enable it like this:


ID3D12Debug* d3d12debug = nullptr;
    d3d12debug = nullptr;

#5299265 Per-Pixel eye vectors for fullscreen quad

Posted by on 05 July 2016 - 11:21 PM

You need to undo your projection, not the view transform. To do that you can take your pixel position in normalized device coordinates (bottom left is (-1,-1), top right is (1,1), transform by the inverse of your projection matrix, and then divide by w. Just make sure you normalize the result, since it won't be a unit vector.

#5298166 New Post about Gamma Correction

Posted by on 26 June 2016 - 06:48 PM

I just came across this excellent presentation that anyone should read if they're interested in color spaces and proper terminology.

#5298011 Basic texturing

Posted by on 25 June 2016 - 12:28 PM

When you declare a texture in your HLSL shader code and compile it with the shader compiler, the compiler will assign the texture to a t# register. There are several register types, but the t# registers are always used for shader resource views. By default, the compiler will assign the registers sequentially based on the order in which you declared your textures. So if you TextureA, TextureB, and TextureC all declared in a row, then they'll get assigned to t0, t1, t2 respectively. You can also explicitly tell the compiler which register you'd like to use by using the "register" keyword, like this:


Texture2D ObjTexture : register(t0);


Now the reason that the registers are important is because they exactly correspond to the binding slots used for PSSetShaderResources. So if you call PSSetShaderResources with StartSlot set to 3 and NumViews set to to 2, then you will bind shader resource views to registers t3 and t4. In your case, the texture will get assigned to t0 so you can just pass 0 for StartSlot and 1 for NumViews, and then pass along a single-element array containing your shader resource view pointer. 


Sampler states work exactly the same way, except that they use a different set of registers and binding slots. Samplers will use registers s0 through s15, and they will correspond to the binding slots of PSSetSamplers.


The way that the binding slots work is that they're persistent on your device context even if you change shaders. So if you bind shader A, set 3 textures, and then draw, those same 3 textures will still be bound if you bind shader B. If you want to un-bind those textures, you need to do it by passing an array of NULL pointers to PSSetShaderResources (or by calling ID3D11DeviceContext::ClearState, which will clear all bindings for all shader stages).


Finally, one thing to keep in mind for advanced scenarios is that it's possible to query a shader's reflection data to find out which textures exist and which registers they were assigned to. To do that, you need to use the ID3D11ShaderReflection interface and use GetResourceBindingDesc/GetResourceBindingDescByName

#5297634 Two constant buffers - cant get it to work

Posted by on 22 June 2016 - 03:14 PM

Does that shader not emit any warnings on compile?


The older versions of the shader compiler (pre-Windows 10) didn't warn you at all about this, they would just silently ignore your register assignment and do it automatically. The latest version of d3dcompiler_47 will give you a proper error message.

#5297399 New Post about Gamma Correction

Posted by on 20 June 2016 - 08:35 PM

I would recommend being careful when explaining what sRGB is. A lot of people are under the mistaken impression that it's just the transfer function (AKA the "gamma curve"), but being a RGB color space it also specifies the chromaticities of the primaries. So you can have the situation where perhaps you use the primaries but not the transfer function, which is what people are usually using when they refer to "linear" space. Or you can have other standards (like Rec. 709) that use the same primaries, but have a different transfer function. You generally don't have to worry about that until you need to work in another color space, and then things can get confusing if you don't understand what the color space is actually specifying. 

#5297145 How to get patch id in domain shader.

Posted by on 18 June 2016 - 04:12 PM

SV_PrimitiveID always starts at 0 for every draw call, and then increases for every primitive processed as part of that draw call. So if you only every draw 1 primitive per draw, then it's always going to be 0. If you need some sort of global ID, then you'll need to provide an offset in a constant buffer.

#5297000 gui rendering issue in dx12

Posted by on 17 June 2016 - 12:50 PM

If you'd like, you can tell the debug layer to automatically break into the debugger whenever an error or warning or occurs. I always do this, since it ensures that I notice and fix every issue. You can do it like this during initialization:


ID3D12InfoQueue* infoQueue = nullptr;
infoQueue->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY_WARNING, TRUE);
infoQueue->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY_ERROR, TRUE);

#5296832 DirectXMath - storing transform matrices

Posted by on 16 June 2016 - 11:59 AM

_vectorcall is not the default for x64 (the default is _fastcall). You need to either decorate your function with it or set as the default calling convention if you want that behavior. However you need to be careful if you enable it as the default calling convention, since it will also apply to functions declared in headers from third-party libraries. This can lead to a mismatch where your calling code expects _vectorcall convention, but the pre-compiled third-party lib was compiled with _fastcall.

#5296533 Deferred Context Usage

Posted by on 14 June 2016 - 04:47 PM

Yeah I'm going to piggy-back on what phantom said, and advise you to steer clear of deferred contexts in D3D11. Unfortunately the way that the D3D11 API is setup just doesn't work for multithreading, and so deferred contexts were never able to live up to their promise. The biggest problem comes from the fact that the driver often needs the full pipeline state at draw or dispatch time in order patch shaders and set low-level GPU state. With deferred contexts some of the state might be inherited from a previous context, and so the driver ends up having to serialize at submission time in order to figure out the full set of state bits for a draw. The lack of lower-level memory access is also an issue, since it makes the semantics of thinks like Map/Discard more complicated.